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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
890db783560a670afceac2e6c8c5cd30c13ee27b
|
60bf3fa4185ec5075eaea4384181bfbc7e1dc319
|
/src/game/sets/sets_level06.lean
|
750d01c421f0f9d9dcdd7925ae3f18c694637ef6
|
[
"Apache-2.0"
] |
permissive
|
anrddh/real-number-game
|
660f1127d03a78fd35986c771d65c3132c5f4025
|
c708c4e02ec306c657e1ea67862177490db041b0
|
refs/heads/master
| 1,668,214,277,092
| 1,593,105,075,000
| 1,593,105,075,000
| 264,269,218
| 0
| 0
| null | 1,589,567,264,000
| 1,589,567,264,000
| null |
UTF-8
|
Lean
| false
| false
| 1,108
|
lean
|
import game.sets.sets_level05 -- hide
import tactic -- hide
namespace xena -- hide
variable X : Type
open_locale classical -- hide
/-
# Chapter 1 : Sets
## Level 6 : `sdiff` and `neg`
-/
/-
The set-theoretic difference `A \ B` satisfies the following property:
```
lemma mem_sdiff_iff : x ∈ A \ B ↔ x ∈ A ∧ x ∉ B
```
The complement `-A` of a set `A` (often denoted $A^c$ in textbooks)
is all the elements of `X` which are not in `A`:
```
lemma mem_neg_iff : x ∈ -A ↔ x ∉ A
```
In this lemma, you might get a shock. The `rw` tactic is aggressive
in the Real Number Game -- if after a rewrite the goal can be
solved by `refl`, then Lean will close the goal automatically.
-/
/- Axiom : mem_sdiff_iff :
x ∈ A \ B ↔ x ∈ A ∧ x ∉ B
-/
/- Axiom : mem_neg_iff :
x ∈ -A ↔ x ∉ A
-/
/- Lemma
If $A$ and $B$ are sets with elements of type $X$, then
$$(A \setminus B) = A \cap B^{c}.$$
-/
theorem setdiff_eq_intersect_comp (A B : set X) : A \ B = A ∩ -B :=
begin
rw ext_iff,
intro x,
rw mem_sdiff_iff,
rw mem_inter_iff,
rw mem_neg_iff,
end
end xena -- hide
|
ce502e02e72f736350774fad71a2799afccba848
|
6de8ea38e7f58ace8fbf74ba3ad0bf3b3d1d7ab5
|
/solutions2/Problem1/solutions.lean
|
54971da0f396f67738d07a9a739b1aff3ed1e5a2
|
[] |
no_license
|
KinanBab/CS591K1-Labs
|
72f4e2c7d230d4e4f548a343a47bf815272b1f58
|
d4569bf99d20c22cd56721024688cda247d1447f
|
refs/heads/master
| 1,587,016,758,873
| 1,558,148,366,000
| 1,558,148,366,000
| 165,329,114
| 5
| 2
| null | 1,550,689,848,000
| 1,547,252,664,000
|
TeX
|
UTF-8
|
Lean
| false
| false
| 2,862
|
lean
|
-- Problem 1: filtering elements of a list (30 points)
-- Part A: Implement a filter (5 points)
-- only keeps elements that satisfy the condition F
@[simp] def filter{T} : (T -> bool) -> list T -> list T
| F list.nil := list.nil
| F (list.cons h l') :=
if F h
then list.cons h (filter F l')
else filter F l'
-- Part B: filter and boolean and (5 points)
theorem filter_and (T: Type) (F1 F2: T -> bool) (l: list T) :
filter (λ x, F1 x ∧ F2 x) l = filter F1 (filter F2 l) :=
begin
induction l,
simp,
simp,
cases (F2 l_hd),
simp, assumption,
simp,
cases (F1 l_hd),
simp, assumption,
simp, assumption,
end
-- Part C: filter produces an equal or smaller array (5 points)
theorem filter_len (T: Type) (F1: T -> bool) (l: list T) :
list.length (filter F1 l) ≤ list.length l :=
begin
induction l,
simp,
simp,
cases (F1 l_hd),
simp,
rewrite nat.add_comm,
rewrite nat.add_one,
apply nat.le_trans,
assumption,
apply nat.le_succ,
simp,
rewrite nat.add_comm,
rewrite nat.add_one,
rewrite nat.add_comm,
rewrite nat.add_one,
apply nat.succ_le_succ,
assumption,
end
-- Part D: filter is safe (10 points)
-- it does not add any elments that do not satisify the condition
@[simp] def is_safe{T} : (T -> bool) -> list T -> bool
| F list.nil := tt
| F (list.cons h l') := (F h) && (is_safe F l')
theorem filter_safe (T: Type) (F1: T -> bool) (l: list T) :
is_safe F1 (filter F1 l) = tt :=
begin
-- Proof goes here
-- HINT: you will need to use cases (<expression>)
-- instead of cases, so that the case is added as a hypothesis
-- HINT: #check eq_ff_of_not_eq_tt at https://github.com/leanprover/lean/blob/master/library/init/data/bool/lemmas.lean
induction l,
simp,
simp,
cases H: (F1 l_hd),
simp,
assumption,
simp,
apply and.intro; assumption,
end
-- part E: correctness (5 points)
-- are these properties enough to guarantee correctness? can you
-- think of an example that satisfy these properties but is incorrect?
-- You do not have to prove it or write it down, just give an informal arguments in comments
-- ANSWER: No, it does not guarantee correctness: here is a simple counter example
@[simp] def filter_incorrect{T} : (T → bool) → list T → list T
| F l := list.nil
theorem filter_and_incorrect (T: Type) (F1 F2: T → bool) (l: list T) :
filter_incorrect (λ x, F1 x ∧ F2 x) l = filter_incorrect F1 (filter_incorrect F2 l) :=
begin
simp,
end
theorem filter_len_incorrect (T: Type) (F1: T -> bool) (l: list T) :
list.length (filter_incorrect F1 l) ≤ list.length l :=
begin
simp,
apply nat.zero_le,
end
theorem filter_safe_incorrect (T: Type) (F1: T -> bool) (l: list T) :
is_safe F1 (filter_incorrect F1 l) = tt :=
begin
simp,
end
|
81e15807e8ae95c8de64ebbf8eb063be0e5c24cf
|
41ebf3cb010344adfa84907b3304db00e02db0a6
|
/uexp/src/uexp/rules/commonexp.lean
|
051c1fc49f641d2675b12c56f85f387d06ea6ce3
|
[
"BSD-2-Clause"
] |
permissive
|
ReinierKoops/Cosette
|
e061b2ba58b26f4eddf4cd052dcf7abd16dfe8fb
|
eb8dadd06ee05fe7b6b99de431dd7c4faef5cb29
|
refs/heads/master
| 1,686,483,953,198
| 1,624,293,498,000
| 1,624,293,498,000
| 378,997,885
| 0
| 0
|
BSD-2-Clause
| 1,624,293,485,000
| 1,624,293,484,000
| null |
UTF-8
|
Lean
| false
| false
| 1,181
|
lean
|
import ..sql
import ..tactics
import ..u_semiring
import ..extra_constants
import ..meta.ucongr
import ..meta.TDP
import ..meta.cosette_tactics
-- NOTE: this one cannot solved by ucongr, need to be revisited
open Expr
open Proj
open Pred
open SQL
open binary_operators
theorem rule :
forall (Γ s1 : Schema) (a : relation s1)
(x : Column datatypes.int s1) (y : Column datatypes.int s1),
denoteSQL (SELECT1 (e2p (binaryExpr add_ (uvariable (right⋅x)) (uvariable (right⋅x))))
FROM1 (table a WHERE (equal (uvariable (right⋅x)) (uvariable (right⋅y)))) : SQL Γ _) =
denoteSQL (SELECT1 (e2p (binaryExpr add_ (uvariable (right⋅x)) (uvariable (right⋅y))))
FROM1 (table a WHERE (equal (uvariable (right⋅x)) (uvariable (right⋅y)))) : SQL Γ _) :=
begin
intros,
funext,
unfold_all_denotations,
simp,
congr,
funext,
apply congr_arg _,
have eq_subst_l' : ∀ {s: Schema} (t₁ t₂: Tuple s) (R: Tuple s → Tuple s) (e : Tuple s), (t₁ ≃ t₂) * (e ≃ R t₁) = (t₁ ≃ t₂) * (e ≃ R t₂),
{ intros, rw eq_subst_l },
rewrite eq_subst_l',
end
|
8556ed62d5a193dbd3dcbf5fd690bc742203ecff
|
a0a027e4a00cdb315527e8922122f2a4411fd01c
|
/6.8-automatically-generated-constructions.lean
|
806920c8945c95a24ef5b782b469f43b2e25b5d7
|
[] |
no_license
|
spl/lean-tutorial
|
96a1ef321d06b9b28d044eeb6bf1ff9a86761a6e
|
35c0250004d75d8ae58f6192b649744545116022
|
refs/heads/master
| 1,610,250,012,890
| 1,454,259,122,000
| 1,454,259,122,000
| 49,971,362
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 593
|
lean
|
inductive tree (A : Type) : Type :=
| leaf : A → tree A
| node : tree A → tree A → tree A
open tree
variable {A : Type}
theorem leaf_ne_node {a : A} {l r : tree A}
(h : leaf a = node l r) : false :=
tree.no_confusion h
theorem leaf_inj {a b : A} (h : leaf a = leaf b) : a = b :=
tree.no_confusion h id
theorem node_inj_left {l1 r1 l2 r2 : tree A}
(h : node l1 r1 = node l2 r2) : l1 = l2 :=
tree.no_confusion h (λ e₁ e₂, e₁)
theorem node_inj_right {l1 r1 l2 r2 : tree A}
(h : node l1 r1 = node l2 r2) : r1 = r2 :=
tree.no_confusion h (λ e₁ e₂, e₂)
|
8ba84ddeab33d164b0fbbf62b0cd3f1effabdc23
|
618003631150032a5676f229d13a079ac875ff77
|
/src/topology/homeomorph.lean
|
aab3893b1e538b55c128e9662e194c0654e381fb
|
[
"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
| 8,643
|
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, Patrick Massot, Sébastien Gouëzel, Zhouhang Zhou, Reid Barton
-/
import topology.dense_embedding
open set
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- α and β are homeomorph, also called topological isomoph -/
structure homeomorph (α : Type*) (β : Type*) [topological_space α] [topological_space β]
extends α ≃ β :=
(continuous_to_fun : continuous to_fun)
(continuous_inv_fun : continuous inv_fun)
infix ` ≃ₜ `:25 := homeomorph
namespace homeomorph
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
instance : has_coe_to_fun (α ≃ₜ β) := ⟨λ_, α → β, λe, e.to_equiv⟩
lemma coe_eq_to_equiv (h : α ≃ₜ β) (a : α) : h a = h.to_equiv a := rfl
/-- Identity map is a homeomorphism. -/
protected def refl (α : Type*) [topological_space α] : α ≃ₜ α :=
{ continuous_to_fun := continuous_id, continuous_inv_fun := continuous_id, .. equiv.refl α }
/-- Composition of two homeomorphisms. -/
protected def trans (h₁ : α ≃ₜ β) (h₂ : β ≃ₜ γ) : α ≃ₜ γ :=
{ continuous_to_fun := h₂.continuous_to_fun.comp h₁.continuous_to_fun,
continuous_inv_fun := h₁.continuous_inv_fun.comp h₂.continuous_inv_fun,
.. equiv.trans h₁.to_equiv h₂.to_equiv }
/-- Inverse of a homeomorphism. -/
protected def symm (h : α ≃ₜ β) : β ≃ₜ α :=
{ continuous_to_fun := h.continuous_inv_fun,
continuous_inv_fun := h.continuous_to_fun,
.. h.to_equiv.symm }
protected lemma continuous (h : α ≃ₜ β) : continuous h := h.continuous_to_fun
lemma symm_comp_self (h : α ≃ₜ β) : ⇑h.symm ∘ ⇑h = id :=
funext $ assume a, h.to_equiv.left_inv a
lemma self_comp_symm (h : α ≃ₜ β) : ⇑h ∘ ⇑h.symm = id :=
funext $ assume a, h.to_equiv.right_inv a
lemma range_coe (h : α ≃ₜ β) : range h = univ :=
eq_univ_of_forall $ assume b, ⟨h.symm b, congr_fun h.self_comp_symm b⟩
lemma image_symm (h : α ≃ₜ β) : image h.symm = preimage h :=
funext h.symm.to_equiv.image_eq_preimage
lemma preimage_symm (h : α ≃ₜ β) : preimage h.symm = image h :=
(funext h.to_equiv.image_eq_preimage).symm
lemma induced_eq
{α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] (h : α ≃ₜ β) :
tβ.induced h = tα :=
le_antisymm
(calc topological_space.induced ⇑h tβ ≤ _ : induced_mono (coinduced_le_iff_le_induced.1 h.symm.continuous)
... ≤ tα : by rw [induced_compose, symm_comp_self, induced_id] ; exact le_refl _)
(coinduced_le_iff_le_induced.1 h.continuous)
lemma coinduced_eq
{α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] (h : α ≃ₜ β) :
tα.coinduced h = tβ :=
le_antisymm
h.continuous
begin
have : (tβ.coinduced h.symm).coinduced h ≤ tα.coinduced h := coinduced_mono h.symm.continuous,
rwa [coinduced_compose, self_comp_symm, coinduced_id] at this,
end
protected lemma embedding (h : α ≃ₜ β) : embedding h :=
⟨⟨h.induced_eq.symm⟩, h.to_equiv.injective⟩
lemma compact_image {s : set α} (h : α ≃ₜ β) : compact (h '' s) ↔ compact s :=
h.embedding.compact_iff_compact_image.symm
lemma compact_preimage {s : set β} (h : α ≃ₜ β) : compact (h ⁻¹' s) ↔ compact s :=
by rw ← image_symm; exact h.symm.compact_image
protected lemma dense_embedding (h : α ≃ₜ β) : dense_embedding h :=
{ dense := assume a, by rw [h.range_coe, closure_univ]; trivial,
inj := h.to_equiv.injective,
induced := (induced_iff_nhds_eq _).2 (assume a, by rw [← nhds_induced, h.induced_eq]) }
protected lemma is_open_map (h : α ≃ₜ β) : is_open_map h :=
begin
assume s,
rw ← h.preimage_symm,
exact h.symm.continuous s
end
protected lemma is_closed_map (h : α ≃ₜ β) : is_closed_map h :=
begin
assume s,
rw ← h.preimage_symm,
exact continuous_iff_is_closed.1 (h.symm.continuous) _
end
/-- If an bijective map `e : α ≃ β` is continuous and open, then it is a homeomorphism. -/
def homeomorph_of_continuous_open (e : α ≃ β) (h₁ : continuous e) (h₂ : is_open_map e) :
α ≃ₜ β :=
{ continuous_to_fun := h₁,
continuous_inv_fun := begin
intros s hs,
convert ← h₂ s hs using 1,
apply e.image_eq_preimage
end,
.. e }
lemma comp_continuous_on_iff (h : α ≃ₜ β) (f : γ → α) (s : set γ) :
continuous_on (h ∘ f) s ↔ continuous_on f s :=
begin
split,
{ assume H,
have : continuous_on (h.symm ∘ (h ∘ f)) s :=
h.symm.continuous.comp_continuous_on H,
rwa [← function.comp.assoc h.symm h f, symm_comp_self h] at this },
{ exact λ H, h.continuous.comp_continuous_on H }
end
lemma comp_continuous_iff (h : α ≃ₜ β) (f : γ → α) :
continuous (h ∘ f) ↔ continuous f :=
by simp [continuous_iff_continuous_on_univ, comp_continuous_on_iff]
protected lemma quotient_map (h : α ≃ₜ β) : quotient_map h :=
⟨h.to_equiv.surjective, h.coinduced_eq.symm⟩
/-- If two sets are equal, then they are homeomorphic. -/
def set_congr {s t : set α} (h : s = t) : s ≃ₜ t :=
{ continuous_to_fun := continuous_subtype_mk _ continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ continuous_subtype_val,
.. equiv.set_congr h }
/-- Sum of two homeomorphisms. -/
def sum_congr (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) : α ⊕ γ ≃ₜ β ⊕ δ :=
{ continuous_to_fun :=
continuous_sum_rec (continuous_inl.comp h₁.continuous) (continuous_inr.comp h₂.continuous),
continuous_inv_fun :=
continuous_sum_rec (continuous_inl.comp h₁.symm.continuous) (continuous_inr.comp h₂.symm.continuous),
.. h₁.to_equiv.sum_congr h₂.to_equiv }
/-- Product of two homeomorphisms. -/
def prod_congr (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) : α × γ ≃ₜ β × δ :=
{ continuous_to_fun :=
continuous.prod_mk (h₁.continuous.comp continuous_fst) (h₂.continuous.comp continuous_snd),
continuous_inv_fun :=
continuous.prod_mk (h₁.symm.continuous.comp continuous_fst) (h₂.symm.continuous.comp continuous_snd),
.. h₁.to_equiv.prod_congr h₂.to_equiv }
section
variables (α β γ)
/-- `α × β` is homeomorphic to `β × α`. -/
def prod_comm : α × β ≃ₜ β × α :=
{ continuous_to_fun := continuous.prod_mk continuous_snd continuous_fst,
continuous_inv_fun := continuous.prod_mk continuous_snd continuous_fst,
.. equiv.prod_comm α β }
/-- `(α × β) × γ` is homeomorphic to `α × (β × γ)`. -/
def prod_assoc : (α × β) × γ ≃ₜ α × (β × γ) :=
{ continuous_to_fun :=
continuous.prod_mk (continuous_fst.comp continuous_fst)
(continuous.prod_mk (continuous_snd.comp continuous_fst) continuous_snd),
continuous_inv_fun := continuous.prod_mk
(continuous.prod_mk continuous_fst (continuous_fst.comp continuous_snd))
(continuous_snd.comp continuous_snd),
.. equiv.prod_assoc α β γ }
end
/-- `ulift α` is homeomorphic to `α`. -/
def {u v} ulift {α : Type u} [topological_space α] : ulift.{v u} α ≃ₜ α :=
{ continuous_to_fun := continuous_ulift_down,
continuous_inv_fun := continuous_ulift_up,
.. equiv.ulift }
section distrib
/-- `(α ⊕ β) × γ` is homeomorphic to `α × γ ⊕ β × γ`. -/
def sum_prod_distrib : (α ⊕ β) × γ ≃ₜ α × γ ⊕ β × γ :=
homeomorph.symm $
homeomorph.homeomorph_of_continuous_open (equiv.sum_prod_distrib α β γ).symm
(continuous_sum_rec
((continuous_inl.comp continuous_fst).prod_mk continuous_snd)
((continuous_inr.comp continuous_fst).prod_mk continuous_snd))
(is_open_map_sum
(open_embedding_inl.prod open_embedding_id).is_open_map
(open_embedding_inr.prod open_embedding_id).is_open_map)
/-- `α × (β ⊕ γ)` is homeomorphic to `α × β ⊕ α × γ`. -/
def prod_sum_distrib : α × (β ⊕ γ) ≃ₜ α × β ⊕ α × γ :=
(prod_comm _ _).trans $
sum_prod_distrib.trans $
sum_congr (prod_comm _ _) (prod_comm _ _)
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
/-- `(Σ i, σ i) × β` is homeomorphic to `Σ i, (σ i × β)`. -/
def sigma_prod_distrib : ((Σ i, σ i) × β) ≃ₜ (Σ i, (σ i × β)) :=
homeomorph.symm $
homeomorph_of_continuous_open (equiv.sigma_prod_distrib σ β).symm
(continuous_sigma $ λ i,
continuous.prod_mk (continuous_sigma_mk.comp continuous_fst) continuous_snd)
(is_open_map_sigma $ λ i,
(open_embedding.prod open_embedding_sigma_mk open_embedding_id).is_open_map)
end distrib
end homeomorph
|
035e6236084f8b6a6587b4ba1958dd05967163c6
|
4e3bf8e2b29061457a887ac8889e88fa5aa0e34c
|
/lean/love04_functional_programming_exercise_sheet.lean
|
81381a57f7024ce4e6c214ef3e92088dc92fc9e1
|
[] |
no_license
|
mukeshtiwari/logical_verification_2019
|
9f964c067a71f65eb8884743273fbeef99e6503d
|
16f62717f55ed5b7b87e03ae0134791a9bef9b9a
|
refs/heads/master
| 1,619,158,844,208
| 1,585,139,500,000
| 1,585,139,500,000
| 249,906,380
| 0
| 0
| null | 1,585,118,728,000
| 1,585,118,727,000
| null |
UTF-8
|
Lean
| false
| false
| 5,907
|
lean
|
/- LoVe Exercise 4: Functional Programming -/
import .love04_functional_programming_demo
namespace LoVe
/- Question 1: Reverse of a List -/
/- We define a new accumulator-based version of `reverse`. The first argument
serves as the accumulator. This definition is _tail-recursive_, meaning that
compilers and interpreters can easily optimize the recursion away, resulting in
more efficient code. -/
def areverse {α : Type} : list α → list α → list α
| ys [] := ys
| ys (x :: xs) := areverse (x :: ys) xs
/- 1.1. Our intention is that `areverse [] xs` should be equal to `reverse xs`.
But if we start an induction, we quickly see that the induction hypothesis is
not strong enough. Start by proving the following generalization (using pattern
matching or the `induction` tactic): -/
lemma areverse_eq_reverse_append {α : Type} :
∀ys xs : list α, areverse ys xs = reverse xs ++ ys
:= sorry
/- 1.2. Derive the desired equation. -/
lemma areverse_eq_reverse {α : Type} (xs : list α) :
areverse [] xs = reverse xs :=
sorry
/- 1.3. Prove the following property. Hint: A one-line inductionless proof is
possible. -/
lemma areverse_areverse {α : Type} (xs : list α) :
areverse [] (areverse [] xs) = xs :=
sorry
/- Question 2: Drop and Take -/
/- The `drop` function removes the first `n` elements from the front of a
list. -/
def drop {α : Type} : ℕ → list α → list α
| 0 xs := xs
| (_ + 1) [] := []
| (m + 1) (x :: xs) := drop m xs
/- Its relative `take` returns a list consisting of the the first `n` elements
at the front of a list. -/
/- 2.1. Define `take`. -/
/- To avoid unpleasant surprises in the proofs, we recommend that you follow the
same recursion pattern as for `drop` above. -/
def take {α : Type} : ℕ → list α → list α
:= sorry
#reduce take 0 [3, 7, 11] -- expected: []
#reduce take 1 [3, 7, 11] -- expected: [3]
#reduce take 2 [3, 7, 11] -- expected: [3, 7]
#reduce take 3 [3, 7, 11] -- expected: [3, 7, 11]
#reduce take 4 [3, 7, 11] -- expected: [3, 7, 11]
-- when `#reduce` fails for some obscure reason, try `#eval`:
#eval take 2 ["a", "b", "c"] -- expected: ["a", "b"]
/- 2.2. Prove the following lemmas. Notice that they are registered as
simplification rules thanks to the `@[simp]` attribute. -/
@[simp] lemma drop_nil {α : Type} :
∀n : ℕ, drop n ([] : list α) = []
:= sorry
@[simp] lemma take_nil {α : Type} :
∀n : ℕ, take n ([] : list α) = []
:= sorry
/- 2.3. Follow the recursion pattern of `drop` and `take` to prove the following
lemmas. In other words, for each lemma, there should be three cases, and the
third case will need to invoke the induction hypothesis.
The first case is shown for `drop_drop`. Beware of the fact that there are three
variables in the `drop_drop` lemma (but only two arguments to `drop`).
Hint: The `refl` tactic might be useful in the third case of `drop_drop`. -/
lemma drop_drop {α : Type} :
∀(m n : ℕ) (xs : list α), drop n (drop m xs) = drop (n + m) xs
| 0 n xs := by refl
-- supply the two missing cases here
lemma take_take {α : Type} :
∀(m : ℕ) (xs : list α), take m (take m xs) = take m xs
:= sorry
lemma take_drop {α : Type} :
∀(n : ℕ) (xs : list α), take n xs ++ drop n xs = xs
:= sorry
/- Question 3: λ-Terms -/
/- 3.1. Define an inductive type corresponding to the untyled λ-terms, as given
by the following context-free grammar:
<lam> ::= 'var' <string>
| 'abs' <string> <lam>
| 'app' <lam> <lam> -/
-- enter your definition here
/- 3.2. Register a textual representation of the type `lam`. Make sure to supply
enough parentheses to guarantee that the output is unambiguous. -/
def lam.repr : lam → string
-- enter your answer here
instance : has_repr lam :=
⟨lam.repr⟩
/- Question 4 (**optional**): Concatenation -/
/- Consider the following Lean definition of 2–3 trees as an inductive type: -/
inductive tttree (α : Type) : Type
| empty {} : tttree
| bin : α → tttree → tttree → tttree
| ter : α → tttree → tttree → tttree → tttree
export tttree (empty bin ter)
/- 4.1 (**optional**). Complete the following Lean definition. The `map_tree`
function should apply its argument `f` to all values of type α stored in the
tree and otherwise preserve the tree's structure. -/
-- enter your definition here
/- 4.2 (**optional**). Prove the following lemma about your definition of
`map_tree`. -/
lemma map_tttree_id {α : Type} :
∀t : tttree α, map_tttree (λx : α, x) t = t
:= sorry
/- 4.3 (**optional**). Complete the following Lean definition. The `set_tree`
function should return the set of all values of type α stored in the tree. In
your answer, you may use traditional set notations regardless of whether they
are actually supported by Lean. -/
def set_tttree {α : Type} : tttree α → set α
:= sorry
/- A _congruence rule_ is a lemma that can be used to lift an equivalence
relation between terms to the same terms occurring under a common context.
Congruence rules for equality are built into Lean's logic. In the following
example, the equivalence relation is `=`, the terms are `f` and `g`, and the
context is `map_tree … t`: -/
lemma map_tttree_congr_weak {α β : Type} (f g : α → β) (f = g) (t : tttree α) :
map_tttree f t = map_tttree g t :=
by simp *
/- 4.4 (**optional**). The above rule is not as flexible as it could be,
because it requires `f = g`. As long as `f` and `g` are equal for all values
`x : α` stored in `t`, we have `map_tree f t = map_tree g t`, even if `f` and
`g` disagree on other `α` values. Inspired by this observation, prove the
following stronger congruence rule. -/
lemma map_tttree_congr_strong {α β : Type} (f g : α → β) :
∀t : tttree α, (∀x, x ∈ set_tttree t → f x = g x) →
map_tttree f t = map_tttree g t
:= sorry
end LoVe
|
7ba9b611672d93df4c7a3680a10b720fa8303b80
|
a45212b1526d532e6e83c44ddca6a05795113ddc
|
/src/data/dlist/instances.lean
|
b1d2b8576ede9be71021126a49d1f98cf554eddc
|
[
"Apache-2.0"
] |
permissive
|
fpvandoorn/mathlib
|
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
|
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
|
refs/heads/master
| 1,624,791,089,608
| 1,556,715,231,000
| 1,556,715,231,000
| 165,722,980
| 5
| 0
|
Apache-2.0
| 1,552,657,455,000
| 1,547,494,646,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 682
|
lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
Traversable instance for dlists.
-/
import data.dlist category.traversable.equiv category.traversable.instances
namespace dlist
variables (α : Type*)
open function equiv
def list_equiv_dlist : list α ≃ dlist α :=
by refine { to_fun := dlist.of_list, inv_fun := dlist.to_list, .. };
simp [function.right_inverse,left_inverse,to_list_of_list,of_list_to_list]
instance : traversable dlist :=
equiv.traversable list_equiv_dlist
instance : is_lawful_traversable dlist :=
equiv.is_lawful_traversable list_equiv_dlist
end dlist
|
db13c23572020ca1634a63bc1489d3ee7d6bbd2f
|
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
|
/stage0/src/Init/Coe.lean
|
a551c061bcc7a68da94f4381cc1db3989c7e47fa
|
[
"Apache-2.0"
] |
permissive
|
dupuisf/lean4
|
d082d13b01243e1de29ae680eefb476961221eef
|
6a39c65bd28eb0e28c3870188f348c8914502718
|
refs/heads/master
| 1,676,948,755,391
| 1,610,665,114,000
| 1,610,665,114,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,076
|
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
-/
prelude
import Init.Core
universes u v w w'
class Coe (α : Sort u) (β : Sort v) where
coe : α → β
/-- Auxiliary class that contains the transitive closure of `Coe`. -/
class CoeTC (α : Sort u) (β : Sort v) where
coe : α → β
/- Expensive coercion that can only appear at the beggining of a sequence of coercions. -/
class CoeHead (α : Sort u) (β : Sort v) where
coe : α → β
/- Expensive coercion that can only appear at the end of a sequence of coercions. -/
class CoeTail (α : Sort u) (β : Sort v) where
coe : α → β
class CoeDep (α : Sort u) (a : α) (β : Sort v) where
coe : β
/- Combines CoeHead, CoeTC, CoeTail, CoeDep -/
class CoeT (α : Sort u) (a : α) (β : Sort v) where
coe : β
class CoeFun (α : Sort u) (γ : outParam (α → outParam (Sort v))) where
coe : (a : α) → γ a
class CoeSort (α : Sort u) (β : outParam (Sort v)) where
coe : α → β
abbrev coeB {α : Sort u} {β : Sort v} [Coe α β] (a : α) : β :=
Coe.coe a
abbrev coeHead {α : Sort u} {β : Sort v} [CoeHead α β] (a : α) : β :=
CoeHead.coe a
abbrev coeTail {α : Sort u} {β : Sort v} [CoeTail α β] (a : α) : β :=
CoeTail.coe a
abbrev coeD {α : Sort u} {β : Sort v} (a : α) [CoeDep α a β] : β :=
CoeDep.coe a
abbrev coeTC {α : Sort u} {β : Sort v} [CoeTC α β] (a : α) : β :=
CoeTC.coe a
/-- Apply coercion manually. -/
abbrev coe {α : Sort u} {β : Sort v} (a : α) [CoeT α a β] : β :=
CoeT.coe a
prefix:max "↑" => coe
abbrev coeFun {α : Sort u} {γ : α → Sort v} (a : α) [CoeFun α γ] : γ a :=
CoeFun.coe a
abbrev coeSort {α : Sort u} {β : Sort v} (a : α) [CoeSort α β] : β :=
CoeSort.coe a
instance coeTrans {α : Sort u} {β : Sort v} {δ : Sort w} [Coe β δ] [CoeTC α β] : CoeTC α δ where
coe a := coeB (coeTC a : β)
instance coeBase {α : Sort u} {β : Sort v} [Coe α β] : CoeTC α β where
coe a := coeB a
instance coeOfHeafOfTCOfTail {α : Sort u} {β : Sort v} {δ : Sort w} {γ : Sort w'} (a : α) [CoeHead α β] [CoeTail δ γ] [CoeTC β δ] : CoeT α a γ where
coe := coeTail (coeTC (coeHead a : β) : δ)
instance coeOfHeadOfTC {α : Sort u} {β : Sort v} {δ : Sort w} (a : α) [CoeHead α β] [CoeTC β δ] : CoeT α a δ where
coe := coeTC (coeHead a : β)
instance coeOfTCOfTail {α : Sort u} {β : Sort v} {δ : Sort w} (a : α) [CoeTail β δ] [CoeTC α β] : CoeT α a δ where
coe := coeTail (coeTC a : β)
instance coeOfHead {α : Sort u} {β : Sort v} (a : α) [CoeHead α β] : CoeT α a β where
coe := coeHead a
instance coeOfTail {α : Sort u} {β : Sort v} (a : α) [CoeTail α β] : CoeT α a β where
coe := coeTail a
instance coeOfTC {α : Sort u} {β : Sort v} (a : α) [CoeTC α β] : CoeT α a β where
coe := coeTC a
instance coeOfDep {α : Sort u} {β : Sort v} (a : α) [CoeDep α a β] : CoeT α a β where
coe := coeD a
instance coeId {α : Sort u} (a : α) : CoeT α a α where
coe := a
/- Basic instances -/
@[inline] instance boolToProp : Coe Bool Prop where
coe b := b = true
@[inline] instance coeDecidableEq (x : Bool) : Decidable (coe x) :=
inferInstanceAs (Decidable (x = true))
instance decPropToBool (p : Prop) [Decidable p] : CoeDep Prop p Bool where
coe := decide p
instance optionCoe {α : Type u} : CoeTail α (Option α) where
coe := some
instance subtypeCoe {α : Sort u} {p : α → Prop} : CoeHead { x // p x } α where
coe v := v.val
/- Coe & OfNat bridge -/
/-
Remark: one may question why we use `OfNat α` instead of `Coe Nat α`.
Reason: `OfNat` is for implementing polymorphic numeric literals, and we may
want to have numberic literals for a type α and **no** coercion from `Nat` to `α`. -/
instance hasOfNatOfCoe [Coe α β] [OfNat α n] : OfNat β n where
ofNat := coe (OfNat.ofNat n : α)
@[inline] def liftCoeM {m : Type u → Type v} {n : Type u → Type w} {α β : Type u} [MonadLiftT m n] [∀ a, CoeT α a β] [Monad n] (x : m α) : n β := do
let a ← liftM x
pure (coe a)
@[inline] def coeM {m : Type u → Type v} {α β : Type u} [∀ a, CoeT α a β] [Monad m] (x : m α) : m β := do
let a ← x
pure <| coe a
instance [CoeFun α β] (a : α) : CoeDep α a (β a) where
coe := coeFun a
instance [CoeFun α (fun _ => β)] : CoeTail α β where
coe a := coeFun a
instance [CoeSort α β] : CoeTail α β where
coe a := coeSort a
/- Coe and heterogeneous operators, we use `CoeTC` instead of `CoeT` to avoid expensive coercions such as `CoeDep` -/
instance [CoeTC α β] [Add β] : HAdd α β β where
hAdd a b := Add.add a b
instance [CoeTC α β] [Add β] : HAdd β α β where
hAdd a b := Add.add a b
instance [CoeTC α β] [Sub β] : HSub α β β where
hSub a b := Sub.sub a b
instance [CoeTC α β] [Sub β] : HSub β α β where
hSub a b := Sub.sub a b
instance [CoeTC α β] [Mul β] : HMul α β β where
hMul a b := Mul.mul a b
instance [CoeTC α β] [Mul β] : HMul β α β where
hMul a b := Mul.mul a b
instance [CoeTC α β] [Div β] : HDiv α β β where
hDiv a b := Div.div a b
instance [CoeTC α β] [Div β] : HDiv β α β where
hDiv a b := Div.div a b
instance [CoeTC α β] [Mod β] : HMod α β β where
hMod a b := Mod.mod a b
instance [CoeTC α β] [Mod β] : HMod β α β where
hMod a b := Mod.mod a b
instance [CoeTC α β] [Append β] : HAppend α β β where
hAppend a b := Append.append a b
instance [CoeTC α β] [Append β] : HAppend β α β where
hAppend a b := Append.append a b
instance [CoeTC α β] [OrElse β] : HOrElse α β β where
hOrElse a b := OrElse.orElse a b
instance [CoeTC α β] [OrElse β] : HOrElse β α β where
hOrElse a b := OrElse.orElse a b
instance [CoeTC α β] [AndThen β] : HAndThen α β β where
hAndThen a b := AndThen.andThen a b
instance [CoeTC α β] [AndThen β] : HAndThen β α β where
hAndThen a b := AndThen.andThen a b
|
8e4ee915cb342077ff2061863f3dc84e58ac9f53
|
8e2026ac8a0660b5a490dfb895599fb445bb77a0
|
/library/init/data/char/basic.lean
|
2cbf476499991f3e9ea43574ff2c11f38f050322
|
[
"Apache-2.0"
] |
permissive
|
pcmoritz/lean
|
6a8575115a724af933678d829b4f791a0cb55beb
|
35eba0107e4cc8a52778259bb5392300267bfc29
|
refs/heads/master
| 1,607,896,326,092
| 1,490,752,175,000
| 1,490,752,175,000
| 86,612,290
| 0
| 0
| null | 1,490,809,641,000
| 1,490,809,641,000
| null |
UTF-8
|
Lean
| false
| false
| 729
|
lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.data.fin.basic
open nat
def char_sz : nat := succ 255
def char := fin char_sz
namespace char
/- We cannot use tactic dec_trivial here because the tactic framework has not been defined yet. -/
lemma zero_lt_char_sz : 0 < char_sz :=
zero_lt_succ _
@[pattern] def of_nat (n : nat) : char :=
if h : n < char_sz then fin.mk n h else fin.mk 0 zero_lt_char_sz
def to_nat (c : char) : nat :=
fin.val c
end char
instance : decidable_eq char :=
have decidable_eq (fin char_sz), from fin.decidable_eq _,
this
instance : inhabited char :=
⟨#"A"⟩
|
a395fc64694b121209a538d4342cc6ba9f13205f
|
8e6cad62ec62c6c348e5faaa3c3f2079012bdd69
|
/src/data/mv_polynomial/rename.lean
|
2a0b539c5274c4ab716e11d7df602c917826be4b
|
[
"Apache-2.0"
] |
permissive
|
benjamindavidson/mathlib
|
8cc81c865aa8e7cf4462245f58d35ae9a56b150d
|
fad44b9f670670d87c8e25ff9cdf63af87ad731e
|
refs/heads/master
| 1,679,545,578,362
| 1,615,343,014,000
| 1,615,343,014,000
| 312,926,983
| 0
| 0
|
Apache-2.0
| 1,615,360,301,000
| 1,605,399,418,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 9,104
|
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, Johan Commelin, Mario Carneiro
-/
import data.mv_polynomial.basic
/-!
# Renaming variables of polynomials
This file establishes the `rename` operation on multivariate polynomials,
which modifies the set of variables.
## Main declarations
* `mv_polynomial.rename`
* `mv_polynomial.rename_equiv`
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ α : Type*` (indexing the variables)
+ `R S : Type*` `[comm_semiring R]` `[comm_semiring S]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `mv_polynomial σ R` which mathematicians might call `X^s`
+ `r : R` elements of the coefficient ring
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : mv_polynomial σ α`
-/
noncomputable theory
open_locale classical big_operators
open set function finsupp add_monoid_algebra
open_locale big_operators
variables {σ τ α R S : Type*} [comm_semiring R] [comm_semiring S]
namespace mv_polynomial
section rename
/-- Rename all the variables in a multivariable polynomial. -/
def rename (f : σ → τ) : mv_polynomial σ R →ₐ[R] mv_polynomial τ R :=
aeval (X ∘ f)
@[simp] lemma rename_C (f : σ → τ) (r : R) : rename f (C r) = C r :=
eval₂_C _ _ _
@[simp] lemma rename_X (f : σ → τ) (i : σ) : rename f (X i : mv_polynomial σ R) = X (f i) :=
eval₂_X _ _ _
lemma map_rename (f : R →+* S) (g : σ → τ) (p : mv_polynomial σ R) :
map f (rename g p) = rename g (map f p) :=
mv_polynomial.induction_on p
(λ a, by simp only [map_C, rename_C])
(λ p q hp hq, by simp only [hp, hq, alg_hom.map_add, ring_hom.map_add])
(λ p n hp, by simp only [hp, rename_X, map_X, ring_hom.map_mul, alg_hom.map_mul])
@[simp] lemma rename_rename (f : σ → τ) (g : τ → α) (p : mv_polynomial σ R) :
rename g (rename f p) = rename (g ∘ f) p :=
show rename g (eval₂ C (X ∘ f) p) = _,
begin
simp only [rename, aeval_eq_eval₂_hom],
simp [eval₂_comp_left _ C (X ∘ f) p, (∘), eval₂_C, eval_X],
apply eval₂_hom_congr _ rfl rfl,
ext1, simp only [comp_app, ring_hom.coe_comp, eval₂_hom_C],
end
@[simp] lemma rename_id (p : mv_polynomial σ R) : rename id p = p :=
eval₂_eta p
lemma rename_monomial (f : σ → τ) (d : σ →₀ ℕ) (r : R) :
rename f (monomial d r) = monomial (d.map_domain f) r :=
begin
rw [rename, aeval_monomial, monomial_eq, finsupp.prod_map_domain_index],
{ refl },
{ exact assume n, pow_zero _ },
{ exact assume n i₁ i₂, pow_add _ _ _ }
end
lemma rename_eq (f : σ → τ) (p : mv_polynomial σ R) :
rename f p = finsupp.map_domain (finsupp.map_domain f) p :=
begin
simp only [rename, aeval_def, eval₂, finsupp.map_domain, ring_hom.coe_of],
congr' with s a : 2,
rw [← monomial, monomial_eq, finsupp.prod_sum_index],
congr' with n i : 2,
rw [finsupp.prod_single_index],
exact pow_zero _,
exact assume a, pow_zero _,
exact assume a b c, pow_add _ _ _
end
lemma rename_injective (f : σ → τ) (hf : function.injective f) :
function.injective (rename f : mv_polynomial σ R → mv_polynomial τ R) :=
have (rename f : mv_polynomial σ R → mv_polynomial τ R) =
finsupp.map_domain (finsupp.map_domain f) := funext (rename_eq f),
begin
rw this,
exact finsupp.map_domain_injective (finsupp.map_domain_injective hf)
end
section
variables (R)
/-- `mv_polynomial.rename e` is an equivalence when `e` is. -/
@[simps apply]
def rename_equiv (f : σ ≃ τ) : mv_polynomial σ R ≃ₐ[R] mv_polynomial τ R :=
{ to_fun := rename f,
inv_fun := rename f.symm,
left_inv := λ p, by rw [rename_rename, f.symm_comp_self, rename_id],
right_inv := λ p, by rw [rename_rename, f.self_comp_symm, rename_id],
..rename f}
@[simp] lemma rename_equiv_refl :
rename_equiv R (equiv.refl σ) = alg_equiv.refl :=
alg_equiv.ext rename_id
@[simp] lemma rename_equiv_symm (f : σ ≃ τ) :
(rename_equiv R f).symm = rename_equiv R f.symm := rfl
@[simp] lemma rename_equiv_trans (e : σ ≃ τ) (f : τ ≃ α):
(rename_equiv R e).trans (rename_equiv R f) = rename_equiv R (e.trans f) :=
alg_equiv.ext (rename_rename e f)
end
section
variables (f : R →+* S) (k : σ → τ) (g : τ → S) (p : mv_polynomial σ R)
lemma eval₂_rename : (rename k p).eval₂ f g = p.eval₂ f (g ∘ k) :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma eval₂_hom_rename : eval₂_hom f g (rename k p) = eval₂_hom f (g ∘ k) p :=
eval₂_rename _ _ _ _
lemma aeval_rename [algebra R S] : aeval g (rename k p) = aeval (g ∘ k) p :=
eval₂_hom_rename _ _ _ _
lemma rename_eval₂ (g : τ → mv_polynomial σ R) :
rename k (p.eval₂ C (g ∘ k)) = (rename k p).eval₂ C (rename k ∘ g) :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma rename_prodmk_eval₂ (j : τ) (g : σ → mv_polynomial σ R) :
rename (prod.mk j) (p.eval₂ C g) = p.eval₂ C (λ x, rename (prod.mk j) (g x)) :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma eval₂_rename_prodmk (g : σ × τ → S) (i : σ) (p : mv_polynomial τ R) :
(rename (prod.mk i) p).eval₂ f g = eval₂ f (λ j, g (i, j)) p :=
by apply mv_polynomial.induction_on p; { intros, simp [*] }
lemma eval_rename_prodmk (g : σ × τ → R) (i : σ) (p : mv_polynomial τ R) :
eval g (rename (prod.mk i) p) = eval (λ j, g (i, j)) p :=
eval₂_rename_prodmk (ring_hom.id _) _ _ _
end
/-- Every polynomial is a polynomial in finitely many variables. -/
theorem exists_finset_rename (p : mv_polynomial σ R) :
∃ (s : finset σ) (q : mv_polynomial {x // x ∈ s} R), p = rename coe q :=
begin
apply induction_on p,
{ intro r, exact ⟨∅, C r, by rw rename_C⟩ },
{ rintro p q ⟨s, p, rfl⟩ ⟨t, q, rfl⟩,
refine ⟨s ∪ t, ⟨_, _⟩⟩,
{ refine rename (subtype.map id _) p + rename (subtype.map id _) q;
simp only [id.def, true_or, or_true, finset.mem_union, forall_true_iff] {contextual := tt}, },
{ simp only [rename_rename, alg_hom.map_add], refl, }, },
{ rintro p n ⟨s, p, rfl⟩,
refine ⟨insert n s, ⟨_, _⟩⟩,
{ refine rename (subtype.map id _) p * X ⟨n, s.mem_insert_self n⟩,
simp only [id.def, or_true, finset.mem_insert, forall_true_iff] {contextual := tt}, },
{ simp only [rename_rename, rename_X, subtype.coe_mk, alg_hom.map_mul], refl, }, },
end
/-- Every polynomial is a polynomial in finitely many variables. -/
theorem exists_fin_rename (p : mv_polynomial σ R) :
∃ (n : ℕ) (f : fin n → σ) (hf : injective f) (q : mv_polynomial (fin n) R), p = rename f q :=
begin
obtain ⟨s, q, rfl⟩ := exists_finset_rename p,
obtain ⟨n, ⟨e⟩⟩ := fintype.exists_equiv_fin {x // x ∈ s},
refine ⟨n, coe ∘ e.symm, subtype.val_injective.comp e.symm.injective, rename e q, _⟩,
rw [← rename_rename, rename_rename e],
simp only [function.comp, equiv.symm_apply_apply, rename_rename]
end
end rename
lemma eval₂_cast_comp (f : σ → τ) (c : ℤ →+* R) (g : τ → R) (p : mv_polynomial σ ℤ) :
eval₂ c (g ∘ f) p = eval₂ c g (rename f p) :=
mv_polynomial.induction_on p
(λ n, by simp only [eval₂_C, rename_C])
(λ p q hp hq, by simp only [hp, hq, rename, eval₂_add, alg_hom.map_add])
(λ p n hp, by simp only [hp, rename, aeval_def, eval₂_X, eval₂_mul])
section coeff
@[simp]
lemma coeff_rename_map_domain (f : σ → τ) (hf : injective f) (φ : mv_polynomial σ R) (d : σ →₀ ℕ) :
(rename f φ).coeff (d.map_domain f) = φ.coeff d :=
begin
apply induction_on' φ,
{ intros u r,
rw [rename_monomial, coeff_monomial, coeff_monomial],
simp only [(finsupp.map_domain_injective hf).eq_iff],
split_ifs; refl, },
{ intros, simp only [*, alg_hom.map_add, coeff_add], }
end
lemma coeff_rename_eq_zero (f : σ → τ) (φ : mv_polynomial σ R) (d : τ →₀ ℕ)
(h : ∀ u : σ →₀ ℕ, u.map_domain f = d → φ.coeff u = 0) :
(rename f φ).coeff d = 0 :=
begin
rw [rename_eq, coeff, ← not_mem_support_iff],
intro H,
replace H := map_domain_support H,
rw [finset.mem_image] at H,
obtain ⟨u, hu, rfl⟩ := H,
specialize h u rfl,
simp [mem_support_iff, coeff] at h hu,
contradiction
end
lemma coeff_rename_ne_zero (f : σ → τ) (φ : mv_polynomial σ R) (d : τ →₀ ℕ)
(h : (rename f φ).coeff d ≠ 0) :
∃ u : σ →₀ ℕ, u.map_domain f = d ∧ φ.coeff u ≠ 0 :=
by { contrapose! h, apply coeff_rename_eq_zero _ _ _ h }
@[simp] lemma constant_coeff_rename {τ : Type*} (f : σ → τ) (φ : mv_polynomial σ R) :
constant_coeff (rename f φ) = constant_coeff φ :=
begin
apply φ.induction_on,
{ intro a, simp only [constant_coeff_C, rename_C]},
{ intros p q hp hq, simp only [hp, hq, ring_hom.map_add, alg_hom.map_add] },
{ intros p n hp, simp only [hp, rename_X, constant_coeff_X, ring_hom.map_mul, alg_hom.map_mul] }
end
end coeff
end mv_polynomial
|
9e6930cad34e417a64ffce534bab088f46c02af2
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/apply_failure.lean
|
245bcbeb6806b6b0316ed2ab1e8aa75edd87db17
|
[
"Apache-2.0"
] |
permissive
|
soonhokong/lean
|
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
|
38607e3eb57f57f77c0ac114ad169e9e4262e24f
|
refs/heads/master
| 1,611,187,284,081
| 1,450,766,737,000
| 1,476,122,547,000
| 11,513,992
| 2
| 0
| null | 1,401,763,102,000
| 1,374,182,235,000
|
C++
|
UTF-8
|
Lean
| false
| false
| 146
|
lean
|
example (a b c : Prop) : a ∧ b → b ∧ a :=
begin
intro H,
repeat (apply or.elim H | apply and.elim H | intro H | split | assumption)
end
|
9c0f3f61e6f4d186e82ffd374d14cf3b8c9424f1
|
dfbb669f3f58ceb57cb207dcfab5726a07425b03
|
/vscode-lean4/test/test-fixtures/simple/Test/Version.lean
|
dd3a5bb806002e5ef06f6243ae6b569973fb4b7c
|
[
"Apache-2.0"
] |
permissive
|
leanprover/vscode-lean4
|
8bcf7f06867b3c1d42007fe6da863a7a17444dbb
|
6ef0bfa668bdeaad0979e6df10551d42fcc01094
|
refs/heads/master
| 1,692,247,771,767
| 1,691,608,804,000
| 1,691,608,804,000
| 325,845,305
| 64
| 24
|
Apache-2.0
| 1,694,176,429,000
| 1,609,435,614,000
|
TypeScript
|
UTF-8
|
Lean
| false
| false
| 146
|
lean
|
import Lake
def getLeanVersion :=
Lean.versionString
#eval s!"Lean Version: {getLeanVersion}"
#eval s!"Lake Version: {Lake.versionString}"
|
431118ae33e6e2bfdf8874f69b2ec1de5dc16d85
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/algebra/group/defs.lean
|
33ea9b47fb1dee49d679925c328d02db1ae32004
|
[
"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
| 14,416
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
-/
import algebra.group.to_additive
import tactic.basic
/-!
# Typeclasses for (semi)groups and monoid
In this file we define typeclasses for algebraic structures with one binary operation.
The classes are named `(add_)?(comm_)?(semigroup|monoid|group)`, where `add_` means that
the class uses additive notation and `comm_` means that the class assumes that the binary
operation is commutative.
The file does not contain any lemmas except for
* axioms of typeclasses restated in the root namespace;
* lemmas required for instances.
For basic lemmas about these classes see `algebra.group.basic`.
-/
set_option default_priority 100
set_option old_structure_cmd true
universe u
/- Additive "sister" structures.
Example, add_semigroup mirrors semigroup.
These structures exist just to help automation.
In an alternative design, we could have the binary operation as an
extra argument for semigroup, monoid, group, etc. However, the lemmas
would be hard to index since they would not contain any constant.
For example, mul_assoc would be
lemma mul_assoc {α : Type u} {op : α → α → α} [semigroup α op] :
∀ a b c : α, op (op a b) c = op a (op b c) :=
semigroup.mul_assoc
The simplifier cannot effectively use this lemma since the pattern for
the left-hand-side would be
?op (?op ?a ?b) ?c
Remark: we use a tactic for transporting theorems from the multiplicative fragment
to the additive one.
-/
section has_mul
variables {G : Type u} [has_mul G]
/-- `left_mul g` denotes left multiplication by `g` -/
@[to_additive "`left_add g` denotes left addition by `g`"]
def left_mul : G → G → G := λ g : G, λ x : G, g * x
/-- `right_mul g` denotes right multiplication by `g` -/
@[to_additive "`right_add g` denotes right addition by `g`"]
def right_mul : G → G → G := λ g : G, λ x : G, x * g
end has_mul
/-- A semigroup is a type with an associative `(*)`. -/
@[protect_proj, ancestor has_mul] class semigroup (G : Type u) extends has_mul G :=
(mul_assoc : ∀ a b c : G, a * b * c = a * (b * c))
/-- An additive semigroup is a type with an associative `(+)`. -/
@[protect_proj, ancestor has_add] class add_semigroup (G : Type u) extends has_add G :=
(add_assoc : ∀ a b c : G, a + b + c = a + (b + c))
attribute [to_additive] semigroup
section semigroup
variables {G : Type u} [semigroup G]
@[no_rsimp, to_additive]
lemma mul_assoc : ∀ a b c : G, a * b * c = a * (b * c) :=
semigroup.mul_assoc
attribute [no_rsimp] add_assoc -- TODO(Mario): find out why this isn't copying
@[to_additive]
instance semigroup.to_is_associative : is_associative G (*) :=
⟨mul_assoc⟩
end semigroup
/-- A commutative semigroup is a type with an associative commutative `(*)`. -/
@[protect_proj, ancestor semigroup]
class comm_semigroup (G : Type u) extends semigroup G :=
(mul_comm : ∀ a b : G, a * b = b * a)
/-- A commutative additive semigroup is a type with an associative commutative `(+)`. -/
@[protect_proj, ancestor add_semigroup]
class add_comm_semigroup (G : Type u) extends add_semigroup G :=
(add_comm : ∀ a b : G, a + b = b + a)
attribute [to_additive] comm_semigroup
section comm_semigroup
variables {G : Type u} [comm_semigroup G]
@[no_rsimp, to_additive]
lemma mul_comm : ∀ a b : G, a * b = b * a :=
comm_semigroup.mul_comm
attribute [no_rsimp] add_comm
@[to_additive]
instance comm_semigroup.to_is_commutative : is_commutative G (*) :=
⟨mul_comm⟩
end comm_semigroup
/-- A `left_cancel_semigroup` is a semigroup such that `a * b = a * c` implies `b = c`. -/
@[protect_proj, ancestor semigroup]
class left_cancel_semigroup (G : Type u) extends semigroup G :=
(mul_left_cancel : ∀ a b c : G, a * b = a * c → b = c)
/-- An `add_left_cancel_semigroup` is an additive semigroup such that
`a + b = a + c` implies `b = c`. -/
@[protect_proj, ancestor add_semigroup]
class add_left_cancel_semigroup (G : Type u) extends add_semigroup G :=
(add_left_cancel : ∀ a b c : G, a + b = a + c → b = c)
attribute [to_additive add_left_cancel_semigroup] left_cancel_semigroup
section left_cancel_semigroup
variables {G : Type u} [left_cancel_semigroup G] {a b c : G}
@[to_additive]
lemma mul_left_cancel : a * b = a * c → b = c :=
left_cancel_semigroup.mul_left_cancel a b c
@[to_additive]
lemma mul_left_cancel_iff : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congr_arg _⟩
@[to_additive]
theorem mul_right_injective (a : G) : function.injective ((*) a) :=
λ b c, mul_left_cancel
@[simp, to_additive]
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congr_arg _⟩
end left_cancel_semigroup
/-- A `right_cancel_semigroup` is a semigroup such that `a * b = c * b` implies `a = c`. -/
@[protect_proj, ancestor semigroup]
class right_cancel_semigroup (G : Type u) extends semigroup G :=
(mul_right_cancel : ∀ a b c : G, a * b = c * b → a = c)
/-- An `add_right_cancel_semigroup` is an additive semigroup such that
`a + b = c + b` implies `a = c`. -/
@[protect_proj, ancestor add_semigroup]
class add_right_cancel_semigroup (G : Type u) extends add_semigroup G :=
(add_right_cancel : ∀ a b c : G, a + b = c + b → a = c)
attribute [to_additive add_right_cancel_semigroup] right_cancel_semigroup
section right_cancel_semigroup
variables {G : Type u} [right_cancel_semigroup G] {a b c : G}
@[to_additive]
lemma mul_right_cancel : a * b = c * b → a = c :=
right_cancel_semigroup.mul_right_cancel a b c
@[to_additive]
lemma mul_right_cancel_iff : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congr_arg _⟩
@[to_additive]
theorem mul_left_injective (a : G) : function.injective (λ x, x * a) :=
λ b c, mul_right_cancel
@[simp, to_additive]
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congr_arg _⟩
end right_cancel_semigroup
/-- A `monoid` is a `semigroup` with an element `1` such that `1 * a = a * 1 = a`. -/
@[ancestor semigroup has_one]
class monoid (M : Type u) extends semigroup M, has_one M :=
(one_mul : ∀ a : M, 1 * a = a) (mul_one : ∀ a : M, a * 1 = a)
/-- An `add_monoid` is an `add_semigroup` with an element `0` such that `0 + a = a + 0 = a`. -/
@[ancestor add_semigroup has_zero]
class add_monoid (M : Type u) extends add_semigroup M, has_zero M :=
(zero_add : ∀ a : M, 0 + a = a) (add_zero : ∀ a : M, a + 0 = a)
attribute [to_additive] monoid
section monoid
variables {M : Type u} [monoid M]
@[ematch, simp, to_additive]
lemma one_mul : ∀ a : M, 1 * a = a :=
monoid.one_mul
@[ematch, simp, to_additive]
lemma mul_one : ∀ a : M, a * 1 = a :=
monoid.mul_one
attribute [ematch] add_zero zero_add -- TODO(Mario): Make to_additive transfer this
@[to_additive]
instance monoid_to_is_left_id : is_left_id M (*) 1 :=
⟨ monoid.one_mul ⟩
@[to_additive]
instance monoid_to_is_right_id : is_right_id M (*) 1 :=
⟨ monoid.mul_one ⟩
@[to_additive]
lemma left_inv_eq_right_inv {a b c : M} (hba : b * a = 1) (hac : a * c = 1) : b = c :=
by rw [←one_mul c, ←hba, mul_assoc, hac, mul_one b]
end monoid
/-- A commutative monoid is a monoid with commutative `(*)`. -/
@[protect_proj, ancestor monoid comm_semigroup]
class comm_monoid (M : Type u) extends monoid M, comm_semigroup M
/-- An additive commutative monoid is an additive monoid with commutative `(+)`. -/
@[protect_proj, ancestor add_monoid add_comm_semigroup]
class add_comm_monoid (M : Type u) extends add_monoid M, add_comm_semigroup M
attribute [to_additive] comm_monoid
section left_cancel_monoid
/-- An additive monoid in which addition is left-cancellative.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `add_left_cancel_semigroup` is not enough. -/
@[protect_proj, ancestor add_left_cancel_semigroup add_monoid]
class add_left_cancel_monoid (M : Type u) extends add_left_cancel_semigroup M, add_monoid M
-- TODO: I found 1 (one) lemma assuming `[add_left_cancel_monoid]`.
-- Should we port more lemmas to this typeclass?
/-- A monoid in which multiplication is left-cancellative. -/
@[protect_proj, ancestor left_cancel_semigroup monoid, to_additive add_left_cancel_monoid]
class left_cancel_monoid (M : Type u) extends left_cancel_semigroup M, monoid M
/-- Commutative version of add_left_cancel_monoid. -/
@[protect_proj, ancestor add_left_cancel_monoid add_comm_monoid]
class add_left_cancel_comm_monoid (M : Type u) extends add_left_cancel_monoid M, add_comm_monoid M
/-- Commutative version of left_cancel_monoid. -/
@[protect_proj, ancestor left_cancel_monoid comm_monoid, to_additive add_left_cancel_comm_monoid]
class left_cancel_comm_monoid (M : Type u) extends left_cancel_monoid M, comm_monoid M
end left_cancel_monoid
section right_cancel_monoid
/-- An additive monoid in which addition is right-cancellative.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/
@[protect_proj, ancestor add_right_cancel_semigroup add_monoid]
class add_right_cancel_monoid (M : Type u) extends add_right_cancel_semigroup M, add_monoid M
/-- A monoid in which multiplication is right-cancellative. -/
@[protect_proj, ancestor right_cancel_semigroup monoid, to_additive add_right_cancel_monoid]
class right_cancel_monoid (M : Type u) extends right_cancel_semigroup M, monoid M
/-- Commutative version of add_right_cancel_monoid. -/
@[protect_proj, ancestor add_right_cancel_monoid add_comm_monoid]
class add_right_cancel_comm_monoid (M : Type u) extends add_right_cancel_monoid M, add_comm_monoid M
/-- Commutative version of right_cancel_monoid. -/
@[protect_proj, ancestor right_cancel_monoid comm_monoid, to_additive add_right_cancel_comm_monoid]
class right_cancel_comm_monoid (M : Type u) extends right_cancel_monoid M, comm_monoid M
end right_cancel_monoid
section cancel_monoid
/-- An additive monoid in which addition is cancellative on both sides.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `add_right_cancel_semigroup` is not enough. -/
@[protect_proj, ancestor add_left_cancel_monoid add_right_cancel_monoid]
class add_cancel_monoid (M : Type u)
extends add_left_cancel_monoid M, add_right_cancel_monoid M
/-- A monoid in which multiplication is cancellative. -/
@[protect_proj, ancestor left_cancel_monoid right_cancel_monoid, to_additive add_cancel_monoid]
class cancel_monoid (M : Type u) extends left_cancel_monoid M, right_cancel_monoid M
/-- Commutative version of add_cancel_monoid. -/
@[protect_proj, ancestor add_left_cancel_comm_monoid add_right_cancel_comm_monoid]
class add_cancel_comm_monoid (M : Type u)
extends add_left_cancel_comm_monoid M, add_right_cancel_comm_monoid M
/-- Commutative version of cancel_monoid. -/
@[protect_proj, ancestor right_cancel_comm_monoid left_cancel_comm_monoid, to_additive add_cancel_comm_monoid]
class cancel_comm_monoid (M : Type u) extends left_cancel_comm_monoid M, right_cancel_comm_monoid M
end cancel_monoid
/-- A `group` is a `monoid` with an operation `⁻¹` satisfying `a⁻¹ * a = 1`. -/
@[protect_proj, ancestor monoid has_inv]
class group (α : Type u) extends monoid α, has_inv α :=
(mul_left_inv : ∀ a : α, a⁻¹ * a = 1)
/-- An `add_group` is an `add_monoid` with a unary `-` satisfying `-a + a = 0`. -/
@[protect_proj, ancestor add_monoid has_neg]
class add_group (α : Type u) extends add_monoid α, has_neg α :=
(add_left_neg : ∀ a : α, -a + a = 0)
attribute [to_additive] group
section group
variables {G : Type u} [group G] {a b c : G}
@[simp, to_additive]
lemma mul_left_inv : ∀ a : G, a⁻¹ * a = 1 :=
group.mul_left_inv
@[to_additive] lemma inv_mul_self (a : G) : a⁻¹ * a = 1 := mul_left_inv a
@[simp, to_additive]
lemma inv_mul_cancel_left (a b : G) : a⁻¹ * (a * b) = b :=
by rw [← mul_assoc, mul_left_inv, one_mul]
@[simp, to_additive]
lemma inv_eq_of_mul_eq_one (h : a * b = 1) : a⁻¹ = b :=
left_inv_eq_right_inv (inv_mul_self a) h
@[simp, to_additive]
lemma inv_inv (a : G) : (a⁻¹)⁻¹ = a :=
inv_eq_of_mul_eq_one (mul_left_inv a)
@[simp, to_additive]
lemma mul_right_inv (a : G) : a * a⁻¹ = 1 :=
have a⁻¹⁻¹ * a⁻¹ = 1 := mul_left_inv a⁻¹,
by rwa [inv_inv] at this
@[to_additive] lemma mul_inv_self (a : G) : a * a⁻¹ = 1 := mul_right_inv a
@[simp, to_additive]
lemma mul_inv_cancel_right (a b : G) : a * b * b⁻¹ = a :=
by rw [mul_assoc, mul_right_inv, mul_one]
@[to_additive]
instance group.to_left_cancel_semigroup : left_cancel_semigroup G :=
{ mul_left_cancel := λ a b c h, by rw [← inv_mul_cancel_left a b, h, inv_mul_cancel_left],
..‹group G› }
@[to_additive]
instance group.to_right_cancel_semigroup : right_cancel_semigroup G :=
{ mul_right_cancel := λ a b c h, by rw [← mul_inv_cancel_right a b, h, mul_inv_cancel_right],
..‹group G› }
@[to_additive]
instance group.to_cancel_monoid : cancel_monoid G :=
{ ..‹group G›, .. group.to_left_cancel_semigroup,
..group.to_right_cancel_semigroup }
end group
section add_group
variables {G : Type u} [add_group G]
/-- The subtraction operation on an `add_group` -/
@[reducible] protected def algebra.sub (a b : G) : G :=
a + -b
instance add_group_has_sub : has_sub G :=
⟨algebra.sub⟩
lemma sub_eq_add_neg (a b : G) : a - b = a + -b :=
rfl
end add_group
/-- A commutative group is a group with commutative `(*)`. -/
@[protect_proj, ancestor group comm_monoid]
class comm_group (G : Type u) extends group G, comm_monoid G
/-- An additive commutative group is an additive group with commutative `(+)`. -/
@[protect_proj, ancestor add_group add_comm_monoid]
class add_comm_group (G : Type u) extends add_group G, add_comm_monoid G
attribute [to_additive] comm_group
attribute [instance, priority 300] add_comm_group.to_add_comm_monoid
section comm_group
variables {G : Type u} [comm_group G]
@[to_additive]
instance comm_group.to_cancel_comm_monoid : cancel_comm_monoid G :=
{ ..‹comm_group G›,
..group.to_left_cancel_semigroup,
..group.to_right_cancel_semigroup }
end comm_group
|
c48de712b0aa9f4bfa74ecd9ebf1311a21f725f0
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/class6.lean
|
4b1bde26727cf8f754845cbfc75fdaaa2077a34f
|
[
"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
| 308
|
lean
|
open tactic
inductive t1 : Type
| mk1 : t1
inductive t2 : Type
| mk2 : t2
def inhabited_t1 : inhabited t1
:= inhabited.mk t1.mk1
def inhabited_t2 : inhabited t2
:= inhabited.mk t2.mk2
attribute [instance] inhabited_t1
attribute [instance] inhabited_t2
def T : inhabited (t1 × t2)
:= by apply_instance
|
c3106c106bf66d00a277499eb1f5c27272a15cec
|
d1a52c3f208fa42c41df8278c3d280f075eb020c
|
/src/Lean/Widget/InteractiveCode.lean
|
972fa3541f9ba9a095f521dfa7baf8c9ea205418
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
cipher1024/lean4
|
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
|
69114d3b50806264ef35b57394391c3e738a9822
|
refs/heads/master
| 1,642,227,983,603
| 1,642,011,696,000
| 1,642,011,696,000
| 228,607,691
| 0
| 0
|
Apache-2.0
| 1,576,584,269,000
| 1,576,584,268,000
| null |
UTF-8
|
Lean
| false
| false
| 5,009
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki
-/
import Lean.PrettyPrinter.Delaborator.Basic
import Lean.Server.Rpc.Basic
import Lean.Widget.TaggedText
/-! RPC infrastructure for storing and formatting code fragments, in particular `Expr`s,
with environment and subexpression information. -/
namespace Lean.Widget
open Server
-- TODO: Some of the `WithBlah` types exist mostly because we cannot derive multi-argument RPC wrappers.
-- They will be gone eventually.
structure InfoWithCtx where
ctx : Elab.ContextInfo
info : Elab.Info
deriving Inhabited, RpcEncoding with { withRef := true }
structure CodeToken where
info : WithRpcRef InfoWithCtx
-- TODO(WN): add fields for semantic highlighting
-- kind : Lsp.SymbolKind
deriving Inhabited, RpcEncoding
/-- Pretty-printed syntax (usually but not necessarily an `Expr`) with embedded `Info`s. -/
abbrev CodeWithInfos := TaggedText CodeToken
def CodeWithInfos.pretty (tt : CodeWithInfos) :=
tt.stripTags
open Expr in
/-- Find a subexpression of `e` using the pretty-printer address scheme. -/
-- NOTE(WN): not currently in use
partial def traverse (e : Expr) (addr : Nat) : MetaM (LocalContext × Expr):= do
let e ← Meta.instantiateMVars e
go (tritsLE [] addr |>.drop 1) (← getLCtx) e
where
tritsLE (acc : List Nat) (n : Nat) : List Nat :=
if n == 0 then acc
else tritsLE (n % 3 :: acc) (n / 3)
go (addr : List Nat) (lctx : LocalContext) (e : Expr) : MetaM (LocalContext × Expr) := do
match addr with
| [] => (lctx, e)
| a::as => do
let go' (e' : Expr) := do
go as (← getLCtx) e'
let eExpr ← match a, e with
| 0, app e₁ e₂ _ => go' e₁
| 1, app e₁ e₂ _ => go' e₂
| 0, lam _ e₁ e₂ _ => go' e₁
| 1, lam n e₁ e₂ data =>
Meta.withLocalDecl n data.binderInfo e₁ fun fvar =>
go' (e₂.instantiate1 fvar)
| 0, forallE _ e₁ e₂ _ => go' e₁
| 1, forallE n e₁ e₂ data =>
Meta.withLocalDecl n data.binderInfo e₁ fun fvar =>
go' (e₂.instantiate1 fvar)
| 0, letE _ e₁ e₂ e₃ _ => go' e₁
| 1, letE _ e₁ e₂ e₃ _ => go' e₂
| 2, letE n e₁ e₂ e₃ _ =>
Meta.withLetDecl n e₁ e₂ fun fvar => do
go' (e₃.instantiate1 fvar)
| 0, mdata _ e₁ _ => go' e₁
| 0, proj _ _ e₁ _ => go' e₁
| _, _ => (lctx, e) -- panic! s!"cannot descend {a} into {e.expr}"
-- TODO(WN): should the two fns below go in `Lean.PrettyPrinter` ?
open PrettyPrinter in
private def formatWithOpts (e : Expr) (optsPerPos : Delaborator.OptionsPerPos)
: MetaM (Format × Std.RBMap Nat Elab.Info compare) := do
let currNamespace ← getCurrNamespace
let openDecls ← getOpenDecls
let opts ← getOptions
let e ← Meta.instantiateMVars e
let (stx, infos) ← PrettyPrinter.delabCore currNamespace openDecls e optsPerPos
let stx := sanitizeSyntax stx |>.run' { options := opts }
let stx ← PrettyPrinter.parenthesizeTerm stx
let fmt ← PrettyPrinter.formatTerm stx
return (fmt, infos)
/-- Pretty-print the expression and its subexpression information. -/
def formatInfos (e : Expr) : MetaM (Format × Std.RBMap Nat Elab.Info compare) :=
formatWithOpts e {}
/-- Like `formatInfos` but with `pp.all` set at the top-level expression. -/
def formatExplicitInfos (e : Expr) : MetaM (Format × Std.RBMap Nat Elab.Info compare) :=
let optsPerPos := Std.RBMap.ofList [(1, KVMap.empty.setBool `pp.all true)]
formatWithOpts e optsPerPos
/-- Tags a pretty-printed `Expr` with infos from the delaborator. -/
partial def tagExprInfos (ctx : Elab.ContextInfo) (infos : Std.RBMap Nat Elab.Info compare) (tt : TaggedText (Nat × Nat))
: CodeWithInfos :=
go tt
where
go (tt : TaggedText (Nat × Nat)) :=
tt.rewrite fun (n, _) subTt =>
match infos.find? n with
| none => go subTt
| some i => TaggedText.tag ⟨WithRpcRef.mk { ctx, info := i }⟩ (go subTt)
def exprToInteractive (e : Expr) : MetaM CodeWithInfos := do
let (fmt, infos) ← formatInfos e
let tt := TaggedText.prettyTagged fmt
let ctx := {
env := ← getEnv
mctx := ← getMCtx
options := ← getOptions
currNamespace := ← getCurrNamespace
openDecls := ← getOpenDecls
fileMap := arbitrary
}
tagExprInfos ctx infos tt
def exprToInteractiveExplicit (e : Expr) : MetaM CodeWithInfos := do
let (fmt, infos) ← formatExplicitInfos e
let tt := TaggedText.prettyTagged fmt
let ctx := {
env := ← getEnv
mctx := ← getMCtx
options := ← getOptions
currNamespace := ← getCurrNamespace
openDecls := ← getOpenDecls
fileMap := arbitrary
}
let infos := infos.erase 1 -- remove highlight for entire expression in popups
tagExprInfos ctx infos tt
end Lean.Widget
|
79eed9a5454f026c2304a94f5dc2fa8cbbdd4317
|
618003631150032a5676f229d13a079ac875ff77
|
/src/category_theory/monoidal/types.lean
|
82f2ded8dc834dbdb435b7cd3fa0ed30f3aacd28
|
[
"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
| 557
|
lean
|
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Scott Morrison
-/
import category_theory.monoidal.of_has_finite_products
open category_theory
open tactic
universes u v
namespace category_theory.monoidal
local attribute [instance] monoidal_of_has_finite_products
instance types : monoidal_category.{u} (Type u) := by apply_instance
-- TODO Once we add braided/symmetric categories, include the braiding/symmetry.
end category_theory.monoidal
|
cceeb1c139a227d4762928b3fd23b46e8aabadbe
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/src/Lean/Compiler/IR/CtorLayout.lean
|
94c9d2ed6eedc38e0a47a23c0b5edebd502607a3
|
[
"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
| 954
|
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.Environment
import Lean.Compiler.IR.Format
namespace Lean
namespace IR
inductive CtorFieldInfo where
| irrelevant
| object (i : Nat)
| usize (i : Nat)
| scalar (sz : Nat) (offset : Nat) (type : IRType)
namespace CtorFieldInfo
def format : CtorFieldInfo → Format
| irrelevant => "◾"
| object i => f!"obj@{i}"
| usize i => f!"usize@{i}"
| scalar sz offset type => f!"scalar#{sz}@{offset}:{type}"
instance : ToFormat CtorFieldInfo := ⟨format⟩
end CtorFieldInfo
structure CtorLayout where
cidx : Nat
fieldInfo : List CtorFieldInfo
numObjs : Nat
numUSize : Nat
scalarSize : Nat
@[extern "lean_ir_get_ctor_layout"]
opaque getCtorLayout (env : @& Environment) (ctorName : @& Name) : Except String CtorLayout
end IR
end Lean
|
c454997f88844175dd38d910694a774677013576
|
3446e92e64a5de7ed1f2109cfb024f83cd904c34
|
/src/game/world4/level6.lean
|
cd79d2914d679feb1993065f2f218031175a61d3
|
[] |
no_license
|
kckennylau/natural_number_game
|
019f4a5f419c9681e65234ecd124c564f9a0a246
|
ad8c0adaa725975be8a9f978c8494a39311029be
|
refs/heads/master
| 1,598,784,137,722
| 1,571,905,156,000
| 1,571,905,156,000
| 218,354,686
| 0
| 0
| null | 1,572,373,319,000
| 1,572,373,318,000
| null |
UTF-8
|
Lean
| false
| false
| 673
|
lean
|
import game.world4.level5 -- hide
namespace mynat -- hide
/-
# World 4 : Power World
## Level 6 of 7: `mul_pow`
You might find `mul_right_comm` useful in this one. Remember `rw mul_right_comm (m ^ t)` will
rewrite the first occurrence of `(m ^ t) * x * y = (m ^ t) * y * x`.
-/
/- Lemma
For all naturals $m$, $n$, $a$, we have $(m * n) ^ a = m ^ a * n ^ a$.
-/
lemma mul_pow (m n a : mynat) : (m * n) ^ a = m ^ a * n ^ a :=
begin [less_leaky]
induction a with t Ht,
rw [pow_zero, pow_zero, pow_zero, mul_one],
refl,
rw [pow_succ, pow_succ, pow_succ, Ht],
rw ←mul_assoc,
rw mul_right_comm (m ^ t),
rw ←mul_assoc,
refl,
end
end mynat -- hide
|
b11701f18a5de07ad436b8b4ee8aa47fcfacc940
|
1717bcbca047a0d25d687e7e9cd482fba00d058f
|
/src/topology/instances/ennreal.lean
|
67ff29a58fbbbb11cfd03e78eee88a984e8858cf
|
[
"Apache-2.0"
] |
permissive
|
swapnilkapoor22/mathlib
|
51ad5804e6a0635ed5c7611cee73e089ab271060
|
3e7efd4ecd5d379932a89212eebd362beb01309e
|
refs/heads/master
| 1,676,467,741,465
| 1,610,301,556,000
| 1,610,301,556,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 43,947
|
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 : ℝ≥0}
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 : ℝ≥0 → 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 : ℝ≥0 | a < ↑b},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] },
show is_open {b : ℝ≥0 | ↑b < a},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } },
{ rw [@order_topology.topology_eq_generate_intervals ℝ≥0 _],
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 : ℝ≥0 → ennreal) ∈ 𝓝 (r : ennreal) :=
have {a : ennreal | a ≠ ⊤} = range (coe : ℝ≥0 → 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 : α → ℝ≥0} {a : ℝ≥0} :
tendsto (λa, (m a : ennreal)) f (𝓝 ↑a) ↔ tendsto m f (𝓝 a) :=
embedding_coe.tendsto_nhds_iff.symm
lemma continuous_coe : continuous (coe : ℝ≥0 → ennreal) :=
embedding_coe.continuous
lemma continuous_coe_iff {α} [topological_space α] {f : α → ℝ≥0} :
continuous (λa, (f a : ennreal)) ↔ continuous f :=
embedding_coe.continuous_iff.symm
lemma nhds_coe {r : ℝ≥0} : 𝓝 (r : ennreal) = (𝓝 r).map coe :=
by rw [embedding_coe.induced, map_nhds_induced_eq coe_range_mem_nhds]
lemma nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ennreal), (p : ennreal)) =
(𝓝 (r, p)).map (λp:ℝ≥0×ℝ≥0, (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 `ℝ≥0`. -/
def ne_top_homeomorph_nnreal : {a | a ≠ ∞} ≃ₜ ℝ≥0 :=
{ 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 `ℝ≥0`. -/
def lt_top_homeomorph_nnreal : {a | a < ∞} ≃ₜ ℝ≥0 :=
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_iff_nnreal.2 $ assume n, _,
rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩,
replace hε : 0 < ε, from coe_pos.1 hε,
filter_upwards [prod_mem_nhds_sets (lt_mem_nhds $ @coe_lt_top (n / ε)) (lt_mem_nhds hεb)],
rintros ⟨a₁, a₂⟩ ⟨h₁, h₂⟩,
dsimp at h₁ h₂ ⊢,
rw [← div_mul_cancel n hε.ne', coe_mul],
exact mul_lt_mul h₁ 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 le_of_forall_lt_one_mul_le {x y : ennreal} (h : ∀ a < 1, a * x ≤ y) : x ≤ y :=
begin
have : tendsto (* x) (𝓝[Iio 1] 1) (𝓝 (1 * x)) :=
(ennreal.continuous_at_mul_const (or.inr one_ne_zero)).mono_left inf_le_left,
rw one_mul at this,
haveI : (𝓝[Iio 1] (1 : ennreal)).ne_bot := nhds_within_Iio_self_ne_bot' ennreal.zero_lt_one,
exact le_of_tendsto this (eventually_nhds_within_iff.2 $ eventually_of_forall h)
end
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 :=
pos_iff_ne_zero.1 (lt_of_lt_of_le (pos_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 : ℝ≥0} :
has_sum (λa, (f a : ennreal)) ↑r ↔ has_sum f r :=
have (λs:finset α, ∑ a in s, ↑(f a)) = (coe : ℝ≥0 → 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 : α → ℝ≥0} (h : has_sum f r) : (∑'a, (f a : ennreal)) = r :=
(ennreal.has_sum_coe.2 h).tsum_eq
protected lemma coe_tsum {f : α → ℝ≥0} : 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 ℝ≥0 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 : ℝ≥0) : 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 summable_iff_not_tendsto_nat_at_top {f : ℕ → ℝ≥0} :
summable f ↔ ¬ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top]
lemma summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0}
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f :=
begin
apply summable_iff_not_tendsto_nat_at_top.2 (λ H, _),
rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩,
exact lt_irrefl _ (hn.trans_le (h n)),
end
lemma tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0}
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : (∑' n, f n) ≤ c :=
le_of_tendsto' (has_sum_iff_tendsto_nat.1 (summable_of_sum_range_le h).has_sum) h
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
lemma summable_sigma {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ≥0} :
summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) :=
begin
split,
{ simp only [← nnreal.summable_coe, nnreal.coe_tsum],
exact λ h, ⟨h.sigma_factor, h.sigma⟩ },
{ rintro ⟨h₁, h₂⟩,
simpa only [← ennreal.tsum_coe_ne_top_iff_summable, ennreal.tsum_sigma', ennreal.coe_tsum, h₁]
using h₂ }
end
open finset
/-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability
assumption on `f`, as otherwise all sums are zero. -/
lemma tendsto_sum_nat_add (f : ℕ → ℝ≥0) : tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
rw ← tendsto_coe,
convert tendsto_sum_nat_add (λ i, (f i : ℝ)),
norm_cast,
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) : ℝ≥0) : ennreal)) =
(∑' k, (ennreal.to_nnreal ∘ f) (k + i) : ℝ≥0) :=
λ 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 _
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 : α → ℝ≥0 := λ 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 : β) : ℝ≥0 := ⟨f b, le_trans (hg b) (hgf b)⟩ in
let g' (b : β) : ℝ≥0 := ⟨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
lemma summable_iff_not_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 :=
by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top_of_nonneg hf]
lemma summable_sigma_of_nonneg {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ} (hf : ∀ x, 0 ≤ f x) :
summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) :=
by { lift f to (Σ x, β x) → ℝ≥0 using hf, exact_mod_cast nnreal.summable_sigma }
lemma summable_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n)
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f :=
begin
apply (summable_iff_not_tendsto_nat_at_top_of_nonneg hf).2 (λ H, _),
rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩,
exact lt_irrefl _ (hn.trans_le (h n)),
end
lemma tsum_le_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n)
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : (∑' n, f n) ≤ c :=
le_of_tendsto' ((has_sum_iff_tendsto_nat_of_nonneg hf _).1
(summable_of_sum_range_le hf h).has_sum) h
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
|
19af6bd7a38afdbd14faac83cc1f970ceb4186c6
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/linear_algebra/vandermonde.lean
|
5e64aa124f3fe50755a21a3b135e06500716b264
|
[
"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
| 4,281
|
lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import algebra.big_operators.fin
import algebra.geom_sum
import group_theory.perm.fin
import linear_algebra.matrix.determinant
import tactic.ring_exp
/-!
# Vandermonde matrix
This file defines the `vandermonde` matrix and gives its determinant.
## Main definitions
- `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`.
## Main results
- `det_vandermonde`: `det (vandermonde v)` is the product of `v i - v j`, where
`(i, j)` ranges over the unordered pairs.
-/
variables {R : Type*} [comm_ring R]
open_locale big_operators
open_locale matrix
open equiv
namespace matrix
/-- `vandermonde v` is the square matrix with `i`th row equal to `1, v i, v i ^ 2, v i ^ 3, ...`.
-/
def vandermonde {n : ℕ} (v : fin n → R) : matrix (fin n) (fin n) R :=
λ i j, v i ^ (j : ℕ)
@[simp] lemma vandermonde_apply {n : ℕ} (v : fin n → R) (i j) :
vandermonde v i j = v i ^ (j : ℕ) :=
rfl
@[simp] lemma vandermonde_cons {n : ℕ} (v0 : R) (v : fin n → R) :
vandermonde (fin.cons v0 v : fin n.succ → R) =
fin.cons (λ j, v0 ^ (j : ℕ)) (λ i, fin.cons 1 (λ j, v i * vandermonde v i j)) :=
begin
ext i j,
refine fin.cases (by simp) (λ i, _) i,
refine fin.cases (by simp) (λ j, _) j,
simp [pow_succ]
end
lemma vandermonde_succ {n : ℕ} (v : fin n.succ → R) :
vandermonde v =
fin.cons (λ j, v 0 ^ (j : ℕ))
(λ i, fin.cons 1 (λ j, v i.succ * vandermonde (fin.tail v) i j)) :=
begin
conv_lhs { rw [← fin.cons_self_tail v, vandermonde_cons] },
simp only [fin.tail]
end
lemma det_vandermonde {n : ℕ} (v : fin n → R) :
det (vandermonde v) = ∏ i : fin n, ∏ j in finset.univ.filter (λ j, i < j), (v j - v i) :=
begin
unfold vandermonde,
induction n with n ih,
{ exact det_eq_one_of_card_eq_zero (fintype.card_fin 0) },
calc det (λ (i j : fin n.succ), v i ^ (j : ℕ))
= det (λ (i j : fin n.succ), @fin.cons _ (λ _, R)
(v 0 ^ (j : ℕ))
(λ i, v (fin.succ i) ^ (j : ℕ) - v 0 ^ (j : ℕ)) i) :
det_eq_of_forall_row_eq_smul_add_const (fin.cons 0 1) 0 (fin.cons_zero _ _) _
... = det (λ (i j : fin n), @fin.cons _ (λ _, R)
(v 0 ^ (j.succ : ℕ))
(λ (i : fin n), v (fin.succ i) ^ (j.succ : ℕ) - v 0 ^ (j.succ : ℕ))
(fin.succ_above 0 i)) :
by simp_rw [det_succ_column_zero, fin.sum_univ_succ, fin.cons_zero, minor, fin.cons_succ,
fin.coe_zero, pow_zero, one_mul, sub_self, mul_zero, zero_mul,
finset.sum_const_zero, add_zero]
... = det (λ (i j : fin n), (v (fin.succ i) - v 0) *
(∑ k in finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ))) :
by { congr, ext i j, rw [fin.succ_above_zero, fin.cons_succ, fin.coe_succ, mul_comm],
exact (geom_sum₂_mul (v i.succ) (v 0) (j + 1 : ℕ)).symm }
... = (∏ (i : fin n), (v (fin.succ i) - v 0)) * det (λ (i j : fin n),
(∑ k in finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ))) :
det_mul_column (λ i, v (fin.succ i) - v 0) _
... = (∏ (i : fin n), (v (fin.succ i) - v 0)) * det (λ (i j : fin n), v (fin.succ i) ^ (j : ℕ)) :
congr_arg ((*) _) _
... = ∏ i : fin n.succ, ∏ j in finset.univ.filter (λ j, i < j), (v j - v i) :
by { simp_rw [ih (v ∘ fin.succ), fin.prod_univ_succ, fin.prod_filter_zero_lt,
fin.prod_filter_succ_lt] },
{ intros i j,
rw fin.cons_zero,
refine fin.cases _ (λ i, _) i,
{ simp },
rw [fin.cons_succ, fin.cons_succ, pi.one_apply],
ring },
{ cases n,
{ simp only [det_eq_one_of_card_eq_zero (fintype.card_fin 0)] },
apply det_eq_of_forall_col_eq_smul_add_pred (λ i, v 0),
{ intro j,
simp },
{ intros i j,
simp only [smul_eq_mul, pi.add_apply, fin.coe_succ, fin.coe_cast_succ, pi.smul_apply],
rw [finset.sum_range_succ, add_comm, nat.sub_self, pow_zero, mul_one, finset.mul_sum],
congr' 1,
refine finset.sum_congr rfl (λ i' hi', _),
rw [mul_left_comm (v 0), nat.succ_sub, pow_succ],
exact nat.lt_succ_iff.mp (finset.mem_range.mp hi') } }
end
end matrix
|
d51b90e3a0eaf25315fae67920c467ce26279dff
|
d796eac6dc113f68ec6fc0579c13e8eae2bdef6c
|
/Resources/Code/Category+Theory-Github-Topic/monoidal-categories-reboot/src/monoidal_categories_reboot/monoidal_functor.lean
|
29d69726e2788763b33d5ae2a01296e1923122fb
|
[
"Apache-2.0"
] |
permissive
|
paddlelaw/functional-discipline-content-cats
|
5a7e13e8adedd96b94f66b0b3cbf1847bc86d7f6
|
d93b7aa849b343c384cec40c73ee84a9300004e8
|
refs/heads/master
| 1,675,541,859,508
| 1,607,251,766,000
| 1,607,251,766,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,883
|
lean
|
-- Copyright (c) 2018 Michael Jendrusch. All rights reserved.
import category_theory.category
import category_theory.functor
import category_theory.products
import category_theory.natural_isomorphism
import .tensor_product
import .monoidal_category
import tactic.rewrite_search
import tactic.interactive
open category_theory
open tactic
universe u
universes v₁ v₂ v₃ u₁ u₂ u₃
open category_theory.category
open category_theory.functor
open category_theory.prod
open category_theory.functor.category.nat_trans
open category_theory.nat_iso
namespace category_theory.monoidal
section
open monoidal_category
structure monoidal_functor
(C : Sort u₁) [𝒞 : monoidal_category.{v₁} C]
(D : Sort u₂) [𝒟 : monoidal_category.{v₂} D]
extends category_theory.functor C D :=
-- unit morphism
(ε : tensor_unit D ≅ obj (tensor_unit C))
-- natural transformation
(μ : Π X Y : C, (obj X) ⊗ (obj Y) ≅ obj (X ⊗ Y))
(μ_natural' : ∀ (X Y X' Y' : C)
(f : X ⟶ Y) (g : X' ⟶ Y'),
(μ X X').hom ≫ map (f ⊗ g) = ((map f) ⊗ (map g)) ≫ (μ Y Y').hom
. obviously)
-- associativity
(associativity' : ∀ (X Y Z : C),
((μ X Y).hom ⊗ 𝟙 (obj Z)) ≫ (μ (X ⊗ Y) Z).hom ≫ map (associator X Y Z).hom
= (associator (obj X) (obj Y) (obj Z)).hom ≫ (𝟙 (obj X) ⊗ (μ Y Z).hom) ≫ (μ X (Y ⊗ Z)).hom
. obviously)
-- unitality
(left_unitality' : ∀ X : C,
(left_unitor (obj X)).hom
= (ε.hom ⊗ 𝟙 (obj X)) ≫ (μ (tensor_unit C) X).hom ≫ map (left_unitor X).hom
. obviously)
(right_unitality' : ∀ X : C,
(right_unitor (obj X)).hom
= (𝟙 (obj X) ⊗ ε.hom) ≫ (μ X (tensor_unit C)).hom ≫ map (right_unitor X).hom
. obviously)
restate_axiom monoidal_functor.μ_natural'
attribute [simp,search] monoidal_functor.μ_natural
restate_axiom monoidal_functor.left_unitality'
attribute [simp,search] monoidal_functor.left_unitality
restate_axiom monoidal_functor.right_unitality'
attribute [simp,search] monoidal_functor.right_unitality
restate_axiom monoidal_functor.associativity'
attribute [simp,search] monoidal_functor.associativity
end
namespace monoidal_functor
variables {C : Sort u₁} [𝒞 : monoidal_category.{v₁} C]
variables {D : Sort u₂} [𝒟 : monoidal_category.{v₂} D]
include 𝒞 𝒟
-- This is unfortunate; we need all sorts of struts to give
-- monoidal functors the features of functors...
@[reducible] def on_iso (F : monoidal_functor C D) {X Y : C} (f : X ≅ Y) : F.obj X ≅ F.obj Y :=
F.to_functor.map_iso f
@[search] lemma map_id (F : monoidal_functor C D) (X : C) :
F.map (𝟙 X) = 𝟙 (F.obj X) := F.map_id' X
@[search] lemma map_comp (F : monoidal_functor C D) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) :
F.map (f ≫ g) = F.map f ≫ F.map g := F.map_comp' f g
end monoidal_functor
section
variables (C : Sort u₁) [𝒞 : monoidal_category.{v₁} C]
variables (D : Sort u₂) [𝒟 : monoidal_category.{v₂} D]
variables (E : Sort u₃) [ℰ : monoidal_category.{v₃} E]
include 𝒞 𝒟 ℰ
open tactic.rewrite_search.tracer
-- set_option profiler true
def monoidal_functor.comp
(F : monoidal_functor C D) (G : monoidal_functor D E) : monoidal_functor C E :=
{ ε := G.ε ≪≫ (G.on_iso F.ε),
μ := λ X Y, G.μ (F.obj X) (F.obj Y) ≪≫ G.on_iso (F.μ X Y),
μ_natural' :=
begin
tidy,
/- `rewrite_search` says -/ -- FIXME actually, its output is broken
conv_lhs { congr, skip, erw [←map_comp] },
conv_lhs { erw [monoidal_functor.μ_natural] },
conv_lhs { congr, skip, erw [map_comp] },
conv_lhs { erw [←category.assoc] },
conv_lhs { congr, erw [monoidal_functor.μ_natural] },
conv_rhs { erw [←category.assoc] },
end,
associativity' := λ X Y Z,
begin
-- obviously fails here, but it seems like it should be doable!
dsimp,
conv { to_rhs,
rw ←interchange_right_identity,
slice 3 4,
rw ← G.map_id,
rw ← G.μ_natural,
},
-- rewrite_search { view := visualiser, trace_summary := tt, explain := tt, max_iterations := 50 }, -- fails
conv { to_rhs,
slice 1 3,
rw ←G.associativity,
},
-- rewrite_search (saw/visited/used) 137/23/16 expressions during proof of category_theory.monoidal.monoidal_functor.comp
conv { to_lhs,
rw ←interchange_left_identity,
slice 2 3,
rw ← G.map_id,
rw ← G.μ_natural, },
repeat { rw category.assoc },
repeat { rw ←G.map_comp },
rw F.associativity,
end,
left_unitality' := λ X,
begin
-- Don't attempt to read this; it is a Frankenstein effort of Scott + rewrite_search
dsimp,
rw G.left_unitality,
rw ←interchange_left_identity,
repeat {rw category.assoc},
apply congr_arg,
/- `rewrite_search` says -/ -- FIXME actually, its output is broken
rw F.left_unitality,
conv_lhs { congr, skip, erw [map_comp] },
conv_lhs { erw [←category.id_app] },
conv_lhs { erw [←category.assoc] },
conv_lhs { congr, erw [monoidal_functor.μ_natural] },
conv_lhs { congr, congr, congr, skip, erw [map_id] },
conv_rhs { erw [←category.assoc] },
erw map_comp,
end,
right_unitality' := λ X,
begin
dsimp,
rw G.right_unitality,
rw ←interchange_right_identity,
repeat {rw category.assoc},
apply congr_arg,
/- `rewrite_search` says -/ -- FIXME actually, its output is broken
rw F.right_unitality,
conv_lhs { congr, skip, erw [map_comp] },
conv_lhs { erw [←category.id_app] },
conv_lhs { erw [←category.assoc] },
conv_lhs { congr, erw [monoidal_functor.μ_natural] },
conv_lhs { congr, congr, congr, erw [map_id] },
conv_rhs { erw [←category.assoc] },
erw map_comp,
end,
.. (F.to_functor) ⋙ (G.to_functor) }
end
end category_theory.monoidal
|
8e0d84ea8c354a91dc93e6e60886159006d54bc7
|
8b9f17008684d796c8022dab552e42f0cb6fb347
|
/library/init/reserved_notation.lean
|
8867ef0ac167d1186c593d13f5a1f5832b0f4fea
|
[
"Apache-2.0"
] |
permissive
|
chubbymaggie/lean
|
0d06ae25f9dd396306fb02190e89422ea94afd7b
|
d2c7b5c31928c98f545b16420d37842c43b4ae9a
|
refs/heads/master
| 1,611,313,622,901
| 1,430,266,839,000
| 1,430,267,083,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,409
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.reserved_notation
Authors: Leonardo de Moura, Jeremy Avigad
-/
prelude
import init.datatypes
notation `assume` binders `,` r:(scoped f, f) := r
notation `take` binders `,` r:(scoped f, f) := r
/-
Global declarations of right binding strength
If a module reassigns these, it will be incompatible with other modules that adhere to these
conventions.
When hovering over a symbol, use "C-c C-k" to see how to input it.
-/
definition std.prec.max : num := 1024 -- the strength of application, identifiers, (, [, etc.
definition std.prec.arrow : num := 25
/-
The next definition is "max + 10". It can be used e.g. for postfix operations that should
be stronger than application.
-/
definition std.prec.max_plus :=
num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ
(num.succ std.prec.max)))))))))
/- Logical operations and relations -/
reserve prefix `¬`:40
reserve prefix `~`:40
reserve infixr `∧`:35
reserve infixr `/\`:35
reserve infixr `\/`:30
reserve infixr `∨`:30
reserve infix `<->`:20
reserve infix `↔`:20
reserve infix `=`:50
reserve infix `≠`:50
reserve infix `≈`:50
reserve infix `∼`:50
reserve infix `≡`:50
reserve infixr `∘`:60 -- input with \comp
reserve postfix `⁻¹`:std.prec.max_plus -- input with \sy or \-1 or \inv
reserve infixl `⬝`:75
reserve infixr `▸`:75
/- types and type constructors -/
reserve infixl `⊎`:25
reserve infixl `×`:30
/- arithmetic operations -/
reserve infixl `+`:65
reserve infixl `-`:65
reserve infixl `*`:70
reserve infixl `div`:70
reserve infixl `mod`:70
reserve infixl `/`:70
reserve prefix `-`:100
reserve infix `<=`:50
reserve infix `≤`:50
reserve infix `<`:50
reserve infix `>=`:50
reserve infix `≥`:50
reserve infix `>`:50
/- boolean operations -/
reserve infixl `&&`:70
reserve infixl `||`:65
/- set operations -/
reserve infix `∈`:50
reserve infix `∉`:50
reserve infixl `∩`:70
reserve infixl `∪`:65
/- other symbols -/
reserve infix `∣`:50
reserve infixl `++`:65
reserve infixr `::`:65
-- Yet another trick to anotate an expression with a type
abbreviation is_typeof (A : Type) (a : A) : A := a
notation `typeof` t `:` T := is_typeof T t
notation `(` t `:` T `)` := is_typeof T t
|
9f01f132bf0746bac6a0b2a6524c401e708c23ad
|
7a76361040c55ae1eba5856c1a637593117a6556
|
/src/lectures/love01_definitions_and_statements_demo.lean
|
090ab700506340277480c37ce77b98a4f2720c52
|
[] |
no_license
|
rgreenblatt/fpv2021
|
c2cbe7b664b648cef7d240a654d6bdf97a559272
|
c65d72e48c8fa827d2040ed6ea86c2be62db36fa
|
refs/heads/main
| 1,692,245,693,819
| 1,633,364,621,000
| 1,633,364,621,000
| 407,231,487
| 0
| 0
| null | 1,631,808,608,000
| 1,631,808,608,000
| null |
UTF-8
|
Lean
| false
| false
| 7,553
|
lean
|
import ..lovelib
/-!
# LoVe Demo 1: Definitions and Statements
We introduce the basics of Lean and proof assistants, without trying to carry
out actual proofs yet. We focus on specifying objects and statements of their
intended properties. -/
set_option pp.beta true
set_option pp.generalized_field_notation false
namespace LoVe
/-! ## A View of Lean
In a first approximation:
Lean = functional programming + logic
In today's lecture, we cover inductive types, recursive functions, and lemma
statements.
If you are not familiar with typed functional programming (e.g., Haskell, ML,
OCaml, Scala), we recommend that you study a tutorial, such as the first
chapters of the online tutorial __Learn You a Haskell for Great Good!__:
http://learnyouahaskell.com/chapters
Make sure to at least reach the section titled "Lambdas".
## Types and Terms
Similar to simply typed λ-calculus or typed functional programming languages
(ML, OCaml, Haskell).
Types `σ`, `τ`, `υ`:
* type variables `α`;
* basic types `T`;
* complex types `T σ1 … σN`.
Some type constructors `T` are written infix, e.g., `→` (function type).
The function arrow is right-associative:
`σ₁ → σ₂ → σ₃ → τ` = `σ₁ → (σ₂ → (σ₃ → τ))`.
Polymorphic types are also possible. In Lean, the type variables must be bound
using `∀`, e.g., `∀α, α → α`.
Terms `t`, `u`:
* constants `c`;
* variables `x`;
* applications `t u`;
* λ-expressions `λx, t`.
__Currying__: functions can be
* fully applied (e.g., `f x y z` if `f` is ternary);
* partially applied (e.g., `f x y`, `f x`);
* left unapplied (e.g., `f`).
Application is left-associative: `f x y z` = `((f x) y) z`. -/
#check ℕ
#check ℤ
#check empty
#check unit
#check bool
#check ℕ → ℤ
#check ℤ → ℕ
#check bool → ℕ → ℤ
#check (bool → ℕ) → ℤ
#check ℕ → (bool → ℕ) → ℤ
#check prod ℕ bool
#check prod
#check λx : ℕ, x
#check λf : ℕ → ℕ, λg : ℕ → ℕ, λh : ℕ → ℕ, λx : ℕ, h (g (f x))
#check λ(f g h : ℕ → ℕ) (x : ℕ), h (g (f x))
constants a b : ℤ
constant f : ℤ → ℤ
constant g : ℤ → ℤ → ℤ
#check λx : ℤ, g (f (g a x)) (g x b)
#check λx, g (f (g a x)) (g x b)
#check λx, x
constant trool : Type
constants trool.true trool.false trool.maybe : trool
/-! ### Type Checking and Type Inference
Type checking and type inference are decidable problems, but this property is
quickly lost if features such as overloading or subtyping are added.
Type judgment: `C ⊢ t : σ`, meaning `t` has type `σ` in local context `C`.
Typing rules:
—————————— Cst if c is declared with type σ
C ⊢ c : σ
—————————— Var if x : σ occurs in C
C ⊢ x : σ
C ⊢ t : σ → τ C ⊢ u : σ
——————————————————————————— App
C ⊢ t u : τ
C, x : σ ⊢ t : τ
———————————————————————— Lam
C ⊢ (λx : σ, t) : σ → τ
### Type Inhabitation
Given a type `σ`, the __type inhabitation__ problem consists of finding a term
of that type.
Recursive procedure:
1. If `σ` is of the form `τ → υ`, a candidate inhabitant is an anonymous
function of the form `λx, _`.
2. Alternatively, you can use any constant or variable `x : τ₁ → ⋯ → τN → σ` to
build the term `x _ … _`. -/
constants α β γ : Type
def some_fun_of_type : (α → β → γ) → ((β → α) → β) → α → γ :=
λf g a, f a (g (λb, a))
/-! ## Type Definitions
An __inductive type__ (also called __inductive datatype__,
__algebraic datatype__, or just __datatype__) is a type that consists of all the
values that can be built using a finite number of applications of its
__constructors__, and only those.
### Natural Numbers -/
namespace my_nat
/-! Definition of type `nat` (= `ℕ`) of natural numbers, using Peano-style unary
notation: -/
inductive nat : Type
| zero : nat
| succ : nat → nat
#check nat
#check nat.zero
#check nat.succ
end my_nat
#print nat
#print ℕ
/-! ### Arithmetic Expressions -/
inductive aexp : Type
| num : ℤ → aexp
| var : string → aexp
| add : aexp → aexp → aexp
| sub : aexp → aexp → aexp
| mul : aexp → aexp → aexp
| div : aexp → aexp → aexp
/-! ### Lists -/
namespace my_list
inductive list (α : Type) : Type
| nil : list
| cons : α → list → list
#check list.nil
#check list.cons
end my_list
#print list
/-! ## Function Definitions
The syntax for defining a function operating on an inductive type is very
compact: We define a single function and use __pattern matching__ to extract the
arguments to the constructors. -/
def add : ℕ → ℕ → ℕ
| m nat.zero := m
| m (nat.succ n) := nat.succ (add m n)
#eval add 2 7
#reduce add 2 7
def mul : ℕ → ℕ → ℕ
| _ nat.zero := nat.zero
| m (nat.succ n) := add m (mul m n)
#eval mul 2 7
#print mul
#print mul._main
def power : ℕ → ℕ → ℕ
| _ nat.zero := 1
| m (nat.succ n) := m * power m n
#eval power 2 5
def power₂ (m : ℕ) : ℕ → ℕ
| nat.zero := 1
| (nat.succ n) := m * power₂ n
#eval power₂ 2 5
def iter (α : Type) (z : α) (f : α → α) : ℕ → α
| nat.zero := z
| (nat.succ n) := f (iter n)
#check iter
def power₃ (m n : ℕ) : ℕ :=
iter ℕ 1 (λl, m * l) n
#eval power₃ 2 5
def append (α : Type) : list α → list α → list α
| list.nil ys := ys
| (list.cons x xs) ys := list.cons x (append xs ys)
#check append
#eval append _ [3, 1] [4, 1, 5]
/-! Aliases:
`[]` := `nil`
`x :: xs` := `cons x xs`
`[x₁, …, xN]` := `x₁ :: … :: xN :: []` -/
def append₂ {α : Type} : list α → list α → list α
| list.nil ys := ys
| (list.cons x xs) ys := list.cons x (append₂ xs ys)
#check append₂
#eval append₂ [3, 1] [4, 1, 5]
#check @append₂
#eval @append₂ _ [3, 1] [4, 1, 5]
def append₃ {α : Type} : list α → list α → list α
| [] ys := ys
| (x :: xs) ys := x :: append₃ xs ys
def reverse {α : Type} : list α → list α
| [] := []
| (x :: xs) := reverse xs ++ [x]
def eval (env : string → ℤ) : aexp → ℤ
| (aexp.num i) := i
| (aexp.var x) := env x
| (aexp.add e₁ e₂) := eval e₁ + eval e₂
| (aexp.sub e₁ e₂) := eval e₁ - eval e₂
| (aexp.mul e₁ e₂) := eval e₁ * eval e₂
| (aexp.div e₁ e₂) := eval e₁ / eval e₂
#eval eval (λs, 7) (aexp.div (aexp.var "x") (aexp.num 0))
/-! Lean only accepts the function definitions for which it can prove
termination. In particular, it accepts __structurally recursive__ functions,
which peel off exactly one constructor at a time.
## Lemma Statements
Notice the similarity with `def` commands. -/
namespace sorry_lemmas
lemma add_comm (m n : ℕ) :
add m n = add n m :=
sorry
lemma add_assoc (l m n : ℕ) :
add (add l m) n = add l (add m n) :=
sorry
lemma mul_comm (m n : ℕ) :
mul m n = mul n m :=
sorry
lemma mul_assoc (l m n : ℕ) :
mul (mul l m) n = mul l (mul m n) :=
sorry
lemma mul_add (l m n : ℕ) :
mul l (add m n) = add (mul l m) (mul l n) :=
sorry
lemma reverse_reverse {α : Type} (xs : list α) :
reverse (reverse xs) = xs :=
sorry
/-! Axioms are like lemmas but without proofs (`:= …`). Constant declarations
are like definitions but without bodies (`:= …`). -/
constants a b : ℤ
axiom a_less_b :
a < b
end sorry_lemmas
end LoVe
|
28231f7ecb1e534611862b89b118d33924a14dd4
|
737dc4b96c97368cb66b925eeea3ab633ec3d702
|
/src/Lean/Meta/Basic.lean
|
59b42c5d2812179e230f64e7832696c39ea5a4a5
|
[
"Apache-2.0"
] |
permissive
|
Bioye97/lean4
|
1ace34638efd9913dc5991443777b01a08983289
|
bc3900cbb9adda83eed7e6affeaade7cfd07716d
|
refs/heads/master
| 1,690,589,820,211
| 1,631,051,000,000
| 1,631,067,598,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 49,189
|
lean
|
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Data.LOption
import Lean.Environment
import Lean.Class
import Lean.ReducibilityAttrs
import Lean.Util.Trace
import Lean.Util.RecDepth
import Lean.Util.PPExt
import Lean.Util.OccursCheck
import Lean.Util.MonadBacktrack
import Lean.Compiler.InlineAttrs
import Lean.Meta.TransparencyMode
import Lean.Meta.DiscrTreeTypes
import Lean.Eval
import Lean.CoreM
/-
This module provides four (mutually dependent) goodies that are needed for building the elaborator and tactic frameworks.
1- Weak head normal form computation with support for metavariables and transparency modes.
2- Definitionally equality checking with support for metavariables (aka unification modulo definitional equality).
3- Type inference.
4- Type class resolution.
They are packed into the MetaM monad.
-/
namespace Lean.Meta
builtin_initialize isDefEqStuckExceptionId : InternalExceptionId ← registerInternalExceptionId `isDefEqStuck
structure Config where
foApprox : Bool := false
ctxApprox : Bool := false
quasiPatternApprox : Bool := false
/- When `constApprox` is set to true,
we solve `?m t =?= c` using
`?m := fun _ => c`
when `?m t` is not a higher-order pattern and `c` is not an application as -/
constApprox : Bool := false
/-
When the following flag is set,
`isDefEq` throws the exeption `Exeption.isDefEqStuck`
whenever it encounters a constraint `?m ... =?= t` where
`?m` is read only.
This feature is useful for type class resolution where
we may want to notify the caller that the TC problem may be solveable
later after it assigns `?m`. -/
isDefEqStuckEx : Bool := false
transparency : TransparencyMode := TransparencyMode.default
/- If zetaNonDep == false, then non dependent let-decls are not zeta expanded. -/
zetaNonDep : Bool := true
/- When `trackZeta == true`, we store zetaFVarIds all free variables that have been zeta-expanded. -/
trackZeta : Bool := false
unificationHints : Bool := true
/- Enables proof irrelevance at `isDefEq` -/
proofIrrelevance : Bool := true
/- By default synthetic opaque metavariables are not assigned by `isDefEq`. Motivation: we want to make
sure typing constraints resolved during elaboration should not "fill" holes that are supposed to be filled using tactics.
However, this restriction is too restrictive for tactics such as `exact t`. When elaborating `t`, we dot not fill
named holes when solving typing constraints or TC resolution. But, we ignore the restriction when we try to unify
the type of `t` with the goal target type. We claim this is not a hack and is defensible behavior because
this last unification step is not really part of the term elaboration. -/
assignSyntheticOpaque : Bool := false
/- When `ignoreLevelDepth` is `false`, only universe level metavariables with depth == metavariable context depth
can be assigned.
We used to have `ignoreLevelDepth == false` always, but this setting produced counterintuitive behavior in a few
cases. Recall that universe levels are often ignored by users, they may not even be aware they exist.
We still use this restriction for regular metavariables. See discussion at the beginning of `MetavarContext.lean`.
We claim it is reasonable to ignore this restriction for universe metavariables because their values are often
contrained by the terms is instances and simp theorems.
TODO: we should delete this configuration option and the method `isReadOnlyLevelMVar` after we have more tests.
-/
ignoreLevelMVarDepth : Bool := true
structure ParamInfo where
binderInfo : BinderInfo := BinderInfo.default
hasFwdDeps : Bool := false
backDeps : Array Nat := #[]
deriving Inhabited
def ParamInfo.isImplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.implicit
def ParamInfo.isInstImplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.instImplicit
def ParamInfo.isStrictImplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.strictImplicit
def ParamInfo.isExplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.default || p.binderInfo == BinderInfo.auxDecl
structure FunInfo where
paramInfo : Array ParamInfo := #[]
resultDeps : Array Nat := #[]
structure InfoCacheKey where
transparency : TransparencyMode
expr : Expr
nargs? : Option Nat
deriving Inhabited, BEq
namespace InfoCacheKey
instance : Hashable InfoCacheKey :=
⟨fun ⟨transparency, expr, nargs⟩ => mixHash (hash transparency) <| mixHash (hash expr) (hash nargs)⟩
end InfoCacheKey
open Std (PersistentArray PersistentHashMap)
abbrev SynthInstanceCache := PersistentHashMap Expr (Option Expr)
abbrev InferTypeCache := PersistentExprStructMap Expr
abbrev FunInfoCache := PersistentHashMap InfoCacheKey FunInfo
abbrev WhnfCache := PersistentExprStructMap Expr
/- A set of pairs. TODO: consider more efficient representations (e.g., a proper set) and caching policies (e.g., imperfect cache).
We should also investigate the impact on memory consumption. -/
abbrev DefEqCache := PersistentHashMap (Expr × Expr) Unit
structure Cache where
inferType : InferTypeCache := {}
funInfo : FunInfoCache := {}
synthInstance : SynthInstanceCache := {}
whnfDefault : WhnfCache := {} -- cache for closed terms and `TransparencyMode.default`
whnfAll : WhnfCache := {} -- cache for closed terms and `TransparencyMode.all`
defEqDefault : DefEqCache := {}
defEqAll : DefEqCache := {}
deriving Inhabited
/--
"Context" for a postponed universe constraint.
`lhs` and `rhs` are the surrounding `isDefEq` call when the postponed constraint was created.
-/
structure DefEqContext where
lhs : Expr
rhs : Expr
lctx : LocalContext
localInstances : LocalInstances
/--
Auxiliary structure for representing postponed universe constraints.
Remark: the fields `ref` and `rootDefEq?` are used for error message generation only.
Remark: we may consider improving the error message generation in the future.
-/
structure PostponedEntry where
ref : Syntax -- We save the `ref` at entry creation time
lhs : Level
rhs : Level
ctx? : Option DefEqContext -- Context for the surrounding `isDefEq` call when entry was created
deriving Inhabited
structure State where
mctx : MetavarContext := {}
cache : Cache := {}
/- When `trackZeta == true`, then any let-decl free variable that is zeta expansion performed by `MetaM` is stored in `zetaFVarIds`. -/
zetaFVarIds : FVarIdSet := {}
postponed : PersistentArray PostponedEntry := {}
deriving Inhabited
structure SavedState where
core : Core.State
meta : State
deriving Inhabited
structure Context where
config : Config := {}
lctx : LocalContext := {}
localInstances : LocalInstances := #[]
/-- Not `none` when inside of an `isDefEq` test. See `PostponedEntry`. -/
defEqCtx? : Option DefEqContext := none
/--
Track the number of nested `synthPending` invocations. Nested invocations can happen
when the type class resolution invokes `synthPending`.
Remark: in the current implementation, `synthPending` fails if `synthPendingDepth > 0`.
We will add a configuration option if necessary. -/
synthPendingDepth : Nat := 0
abbrev MetaM := ReaderT Context $ StateRefT State CoreM
-- Make the compiler generate specialized `pure`/`bind` so we do not have to optimize through the
-- whole monad stack at every use site. May eventually be covered by `deriving`.
instance : Monad MetaM := let i := inferInstanceAs (Monad MetaM); { pure := i.pure, bind := i.bind }
instance : Inhabited (MetaM α) where
default := fun _ _ => arbitrary
instance : MonadLCtx MetaM where
getLCtx := return (← read).lctx
instance : MonadMCtx MetaM where
getMCtx := return (← get).mctx
modifyMCtx f := modify fun s => { s with mctx := f s.mctx }
instance : AddMessageContext MetaM where
addMessageContext := addMessageContextFull
protected def saveState : MetaM SavedState :=
return { core := (← getThe Core.State), meta := (← get) }
/-- Restore backtrackable parts of the state. -/
def SavedState.restore (b : SavedState) : MetaM Unit := do
Core.restore b.core
modify fun s => { s with mctx := b.meta.mctx, zetaFVarIds := b.meta.zetaFVarIds, postponed := b.meta.postponed }
instance : MonadBacktrack SavedState MetaM where
saveState := Meta.saveState
restoreState s := s.restore
@[inline] def MetaM.run (x : MetaM α) (ctx : Context := {}) (s : State := {}) : CoreM (α × State) :=
x ctx |>.run s
@[inline] def MetaM.run' (x : MetaM α) (ctx : Context := {}) (s : State := {}) : CoreM α :=
Prod.fst <$> x.run ctx s
@[inline] def MetaM.toIO (x : MetaM α) (ctxCore : Core.Context) (sCore : Core.State) (ctx : Context := {}) (s : State := {}) : IO (α × Core.State × State) := do
let ((a, s), sCore) ← (x.run ctx s).toIO ctxCore sCore
pure (a, sCore, s)
instance [MetaEval α] : MetaEval (MetaM α) :=
⟨fun env opts x _ => MetaEval.eval env opts x.run' true⟩
protected def throwIsDefEqStuck : MetaM α :=
throw <| Exception.internal isDefEqStuckExceptionId
builtin_initialize
registerTraceClass `Meta
registerTraceClass `Meta.debug
@[inline] def liftMetaM [MonadLiftT MetaM m] (x : MetaM α) : m α :=
liftM x
@[inline] def mapMetaM [MonadControlT MetaM m] [Monad m] (f : forall {α}, MetaM α → MetaM α) {α} (x : m α) : m α :=
controlAt MetaM fun runInBase => f <| runInBase x
@[inline] def map1MetaM [MonadControlT MetaM m] [Monad m] (f : forall {α}, (β → MetaM α) → MetaM α) {α} (k : β → m α) : m α :=
controlAt MetaM fun runInBase => f fun b => runInBase <| k b
@[inline] def map2MetaM [MonadControlT MetaM m] [Monad m] (f : forall {α}, (β → γ → MetaM α) → MetaM α) {α} (k : β → γ → m α) : m α :=
controlAt MetaM fun runInBase => f fun b c => runInBase <| k b c
section Methods
variable [MonadControlT MetaM n] [Monad n]
@[inline] def modifyCache (f : Cache → Cache) : MetaM Unit :=
modify fun ⟨mctx, cache, zetaFVarIds, postponed⟩ => ⟨mctx, f cache, zetaFVarIds, postponed⟩
@[inline] def modifyInferTypeCache (f : InferTypeCache → InferTypeCache) : MetaM Unit :=
modifyCache fun ⟨ic, c1, c2, c3, c4, c5, c6⟩ => ⟨f ic, c1, c2, c3, c4, c5, c6⟩
def getLocalInstances : MetaM LocalInstances :=
return (← read).localInstances
def getConfig : MetaM Config :=
return (← read).config
def setMCtx (mctx : MetavarContext) : MetaM Unit :=
modify fun s => { s with mctx := mctx }
def resetZetaFVarIds : MetaM Unit :=
modify fun s => { s with zetaFVarIds := {} }
def getZetaFVarIds : MetaM FVarIdSet :=
return (← get).zetaFVarIds
def getPostponed : MetaM (PersistentArray PostponedEntry) :=
return (← get).postponed
def setPostponed (postponed : PersistentArray PostponedEntry) : MetaM Unit :=
modify fun s => { s with postponed := postponed }
@[inline] def modifyPostponed (f : PersistentArray PostponedEntry → PersistentArray PostponedEntry) : MetaM Unit :=
modify fun s => { s with postponed := f s.postponed }
/- WARNING: The following 4 constants are a hack for simulating forward declarations.
They are defined later using the `export` attribute. This is hackish because we
have to hard-code the true arity of these definitions here, and make sure the C names match.
We have used another hack based on `IO.Ref`s in the past, it was safer but less efficient. -/
@[extern 6 "lean_whnf"] constant whnf : Expr → MetaM Expr
@[extern 6 "lean_infer_type"] constant inferType : Expr → MetaM Expr
@[extern 7 "lean_is_expr_def_eq"] constant isExprDefEqAux : Expr → Expr → MetaM Bool
@[extern 6 "lean_synth_pending"] protected constant synthPending : MVarId → MetaM Bool
def whnfForall (e : Expr) : MetaM Expr := do
let e' ← whnf e
if e'.isForall then pure e' else pure e
-- withIncRecDepth for a monad `n` such that `[MonadControlT MetaM n]`
protected def withIncRecDepth (x : n α) : n α :=
mapMetaM (withIncRecDepth (m := MetaM)) x
private def mkFreshExprMVarAtCore
(mvarId : MVarId) (lctx : LocalContext) (localInsts : LocalInstances) (type : Expr) (kind : MetavarKind) (userName : Name) (numScopeArgs : Nat) : MetaM Expr := do
modifyMCtx fun mctx => mctx.addExprMVarDecl mvarId userName lctx localInsts type kind numScopeArgs;
return mkMVar mvarId
def mkFreshExprMVarAt
(lctx : LocalContext) (localInsts : LocalInstances) (type : Expr)
(kind : MetavarKind := MetavarKind.natural) (userName : Name := Name.anonymous) (numScopeArgs : Nat := 0)
: MetaM Expr := do
mkFreshExprMVarAtCore (← mkFreshMVarId) lctx localInsts type kind userName numScopeArgs
def mkFreshLevelMVar : MetaM Level := do
let mvarId ← mkFreshMVarId
modifyMCtx fun mctx => mctx.addLevelMVarDecl mvarId;
return mkLevelMVar mvarId
private def mkFreshExprMVarCore (type : Expr) (kind : MetavarKind) (userName : Name) : MetaM Expr := do
mkFreshExprMVarAt (← getLCtx) (← getLocalInstances) type kind userName
private def mkFreshExprMVarImpl (type? : Option Expr) (kind : MetavarKind) (userName : Name) : MetaM Expr :=
match type? with
| some type => mkFreshExprMVarCore type kind userName
| none => do
let u ← mkFreshLevelMVar
let type ← mkFreshExprMVarCore (mkSort u) MetavarKind.natural Name.anonymous
mkFreshExprMVarCore type kind userName
def mkFreshExprMVar (type? : Option Expr) (kind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Expr :=
mkFreshExprMVarImpl type? kind userName
def mkFreshTypeMVar (kind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Expr := do
let u ← mkFreshLevelMVar
mkFreshExprMVar (mkSort u) kind userName
/- Low-level version of `MkFreshExprMVar` which allows users to create/reserve a `mvarId` using `mkFreshId`, and then later create
the metavar using this method. -/
private def mkFreshExprMVarWithIdCore (mvarId : MVarId) (type : Expr)
(kind : MetavarKind := MetavarKind.natural) (userName : Name := Name.anonymous) (numScopeArgs : Nat := 0)
: MetaM Expr := do
mkFreshExprMVarAtCore mvarId (← getLCtx) (← getLocalInstances) type kind userName numScopeArgs
def mkFreshExprMVarWithId (mvarId : MVarId) (type? : Option Expr := none) (kind : MetavarKind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Expr :=
match type? with
| some type => mkFreshExprMVarWithIdCore mvarId type kind userName
| none => do
let u ← mkFreshLevelMVar
let type ← mkFreshExprMVar (mkSort u)
mkFreshExprMVarWithIdCore mvarId type kind userName
def mkFreshLevelMVars (num : Nat) : MetaM (List Level) :=
num.foldM (init := []) fun _ us =>
return (← mkFreshLevelMVar)::us
def mkFreshLevelMVarsFor (info : ConstantInfo) : MetaM (List Level) :=
mkFreshLevelMVars info.numLevelParams
def mkConstWithFreshMVarLevels (declName : Name) : MetaM Expr := do
let info ← getConstInfo declName
return mkConst declName (← mkFreshLevelMVarsFor info)
def getTransparency : MetaM TransparencyMode :=
return (← getConfig).transparency
def shouldReduceAll : MetaM Bool :=
return (← getTransparency) == TransparencyMode.all
def shouldReduceReducibleOnly : MetaM Bool :=
return (← getTransparency) == TransparencyMode.reducible
def getMVarDecl (mvarId : MVarId) : MetaM MetavarDecl := do
match (← getMCtx).findDecl? mvarId with
| some d => pure d
| none => throwError "unknown metavariable '?{mvarId.name}'"
def setMVarKind (mvarId : MVarId) (kind : MetavarKind) : MetaM Unit :=
modifyMCtx fun mctx => mctx.setMVarKind mvarId kind
/- Update the type of the given metavariable. This function assumes the new type is
definitionally equal to the current one -/
def setMVarType (mvarId : MVarId) (type : Expr) : MetaM Unit := do
modifyMCtx fun mctx => mctx.setMVarType mvarId type
def isReadOnlyExprMVar (mvarId : MVarId) : MetaM Bool := do
return (← getMVarDecl mvarId).depth != (← getMCtx).depth
def isReadOnlyOrSyntheticOpaqueExprMVar (mvarId : MVarId) : MetaM Bool := do
let mvarDecl ← getMVarDecl mvarId
match mvarDecl.kind with
| MetavarKind.syntheticOpaque => return !(← getConfig).assignSyntheticOpaque
| _ => return mvarDecl.depth != (← getMCtx).depth
def getLevelMVarDepth (mvarId : MVarId) : MetaM Nat := do
match (← getMCtx).findLevelDepth? mvarId with
| some depth => return depth
| _ => throwError "unknown universe metavariable '?{mvarId.name}'"
def isReadOnlyLevelMVar (mvarId : MVarId) : MetaM Bool := do
if (← getConfig).ignoreLevelMVarDepth then
return false
else
return (← getLevelMVarDepth mvarId) != (← getMCtx).depth
def renameMVar (mvarId : MVarId) (newUserName : Name) : MetaM Unit :=
modifyMCtx fun mctx => mctx.renameMVar mvarId newUserName
def isExprMVarAssigned (mvarId : MVarId) : MetaM Bool :=
return (← getMCtx).isExprAssigned mvarId
def getExprMVarAssignment? (mvarId : MVarId) : MetaM (Option Expr) :=
return (← getMCtx).getExprAssignment? mvarId
/-- Return true if `e` contains `mvarId` directly or indirectly -/
def occursCheck (mvarId : MVarId) (e : Expr) : MetaM Bool :=
return (← getMCtx).occursCheck mvarId e
def assignExprMVar (mvarId : MVarId) (val : Expr) : MetaM Unit :=
modifyMCtx fun mctx => mctx.assignExpr mvarId val
def isDelayedAssigned (mvarId : MVarId) : MetaM Bool :=
return (← getMCtx).isDelayedAssigned mvarId
def getDelayedAssignment? (mvarId : MVarId) : MetaM (Option DelayedMetavarAssignment) :=
return (← getMCtx).getDelayedAssignment? mvarId
def hasAssignableMVar (e : Expr) : MetaM Bool :=
return (← getMCtx).hasAssignableMVar e
def throwUnknownFVar (fvarId : FVarId) : MetaM α :=
throwError "unknown free variable '{mkFVar fvarId}'"
def findLocalDecl? (fvarId : FVarId) : MetaM (Option LocalDecl) :=
return (← getLCtx).find? fvarId
def getLocalDecl (fvarId : FVarId) : MetaM LocalDecl := do
match (← getLCtx).find? fvarId with
| some d => pure d
| none => throwUnknownFVar fvarId
def getFVarLocalDecl (fvar : Expr) : MetaM LocalDecl :=
getLocalDecl fvar.fvarId!
def getLocalDeclFromUserName (userName : Name) : MetaM LocalDecl := do
match (← getLCtx).findFromUserName? userName with
| some d => pure d
| none => throwError "unknown local declaration '{userName}'"
def instantiateLevelMVars (u : Level) : MetaM Level :=
MetavarContext.instantiateLevelMVars u
def instantiateMVars (e : Expr) : MetaM Expr :=
(MetavarContext.instantiateExprMVars e).run
def instantiateLocalDeclMVars (localDecl : LocalDecl) : MetaM LocalDecl :=
match localDecl with
| LocalDecl.cdecl idx id n type bi =>
return LocalDecl.cdecl idx id n (← instantiateMVars type) bi
| LocalDecl.ldecl idx id n type val nonDep =>
return LocalDecl.ldecl idx id n (← instantiateMVars type) (← instantiateMVars val) nonDep
@[inline] def liftMkBindingM (x : MetavarContext.MkBindingM α) : MetaM α := do
match x (← getLCtx) { mctx := (← getMCtx), ngen := (← getNGen) } with
| EStateM.Result.ok e newS => do
setNGen newS.ngen;
setMCtx newS.mctx;
pure e
| EStateM.Result.error (MetavarContext.MkBinding.Exception.revertFailure mctx lctx toRevert decl) newS => do
setMCtx newS.mctx;
setNGen newS.ngen;
throwError "failed to create binder due to failure when reverting variable dependencies"
def abstractRange (e : Expr) (n : Nat) (xs : Array Expr) : MetaM Expr :=
liftMkBindingM <| MetavarContext.abstractRange e n xs
def abstract (e : Expr) (xs : Array Expr) : MetaM Expr :=
abstractRange e xs.size xs
def mkForallFVars (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) (usedLetOnly : Bool := true) : MetaM Expr :=
if xs.isEmpty then pure e else liftMkBindingM <| MetavarContext.mkForall xs e usedOnly usedLetOnly
def mkLambdaFVars (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) (usedLetOnly : Bool := true) : MetaM Expr :=
if xs.isEmpty then pure e else liftMkBindingM <| MetavarContext.mkLambda xs e usedOnly usedLetOnly
def mkLetFVars (xs : Array Expr) (e : Expr) (usedLetOnly := true) : MetaM Expr :=
mkLambdaFVars xs e (usedLetOnly := usedLetOnly)
def mkArrow (d b : Expr) : MetaM Expr :=
return Lean.mkForall (← mkFreshUserName `x) BinderInfo.default d b
/-- `fun _ : Unit => a` -/
def mkFunUnit (a : Expr) : MetaM Expr :=
return Lean.mkLambda (← mkFreshUserName `x) BinderInfo.default (mkConst ``Unit) a
def elimMVarDeps (xs : Array Expr) (e : Expr) (preserveOrder : Bool := false) : MetaM Expr :=
if xs.isEmpty then pure e else liftMkBindingM <| MetavarContext.elimMVarDeps xs e preserveOrder
@[inline] def withConfig (f : Config → Config) : n α → n α :=
mapMetaM <| withReader (fun ctx => { ctx with config := f ctx.config })
@[inline] def withTrackingZeta (x : n α) : n α :=
withConfig (fun cfg => { cfg with trackZeta := true }) x
@[inline] def withoutProofIrrelevance (x : n α) : n α :=
withConfig (fun cfg => { cfg with proofIrrelevance := false }) x
@[inline] def withTransparency (mode : TransparencyMode) : n α → n α :=
mapMetaM <| withConfig (fun config => { config with transparency := mode })
@[inline] def withDefault (x : n α) : n α :=
withTransparency TransparencyMode.default x
@[inline] def withReducible (x : n α) : n α :=
withTransparency TransparencyMode.reducible x
@[inline] def withReducibleAndInstances (x : n α) : n α :=
withTransparency TransparencyMode.instances x
@[inline] def withAtLeastTransparency (mode : TransparencyMode) (x : n α) : n α :=
withConfig
(fun config =>
let oldMode := config.transparency
let mode := if oldMode.lt mode then mode else oldMode
{ config with transparency := mode })
x
/-- Execute `x` allowing `isDefEq` to assign synthetic opaque metavariables. -/
@[inline] def withAssignableSyntheticOpaque (x : n α) : n α :=
withConfig (fun config => { config with assignSyntheticOpaque := true }) x
/-- Save cache, execute `x`, restore cache -/
@[inline] private def savingCacheImpl (x : MetaM α) : MetaM α := do
let savedCache := (← get).cache
try x finally modify fun s => { s with cache := savedCache }
@[inline] def savingCache : n α → n α :=
mapMetaM savingCacheImpl
def getTheoremInfo (info : ConstantInfo) : MetaM (Option ConstantInfo) := do
if (← shouldReduceAll) then
return some info
else
return none
private def getDefInfoTemp (info : ConstantInfo) : MetaM (Option ConstantInfo) := do
match (← getTransparency) with
| TransparencyMode.all => return some info
| TransparencyMode.default => return some info
| _ =>
if (← isReducible info.name) then
return some info
else
return none
/- Remark: we later define `getConst?` at `GetConst.lean` after we define `Instances.lean`.
This method is only used to implement `isClassQuickConst?`.
It is very similar to `getConst?`, but it returns none when `TransparencyMode.instances` and
`constName` is an instance. This difference should be irrelevant for `isClassQuickConst?`. -/
private def getConstTemp? (constName : Name) : MetaM (Option ConstantInfo) := do
match (← getEnv).find? constName with
| some (info@(ConstantInfo.thmInfo _)) => getTheoremInfo info
| some (info@(ConstantInfo.defnInfo _)) => getDefInfoTemp info
| some info => pure (some info)
| none => throwUnknownConstant constName
private def isClassQuickConst? (constName : Name) : MetaM (LOption Name) := do
if isClass (← getEnv) constName then
pure (LOption.some constName)
else
match (← getConstTemp? constName) with
| some _ => pure LOption.undef
| none => pure LOption.none
private partial def isClassQuick? : Expr → MetaM (LOption Name)
| Expr.bvar .. => pure LOption.none
| Expr.lit .. => pure LOption.none
| Expr.fvar .. => pure LOption.none
| Expr.sort .. => pure LOption.none
| Expr.lam .. => pure LOption.none
| Expr.letE .. => pure LOption.undef
| Expr.proj .. => pure LOption.undef
| Expr.forallE _ _ b _ => isClassQuick? b
| Expr.mdata _ e _ => isClassQuick? e
| Expr.const n _ _ => isClassQuickConst? n
| Expr.mvar mvarId _ => do
match (← getExprMVarAssignment? mvarId) with
| some val => isClassQuick? val
| none => pure LOption.none
| Expr.app f _ _ =>
match f.getAppFn with
| Expr.const n .. => isClassQuickConst? n
| Expr.lam .. => pure LOption.undef
| _ => pure LOption.none
def saveAndResetSynthInstanceCache : MetaM SynthInstanceCache := do
let savedSythInstance := (← get).cache.synthInstance
modifyCache fun c => { c with synthInstance := {} }
pure savedSythInstance
def restoreSynthInstanceCache (cache : SynthInstanceCache) : MetaM Unit :=
modifyCache fun c => { c with synthInstance := cache }
@[inline] private def resettingSynthInstanceCacheImpl (x : MetaM α) : MetaM α := do
let savedSythInstance ← saveAndResetSynthInstanceCache
try x finally restoreSynthInstanceCache savedSythInstance
/-- Reset `synthInstance` cache, execute `x`, and restore cache -/
@[inline] def resettingSynthInstanceCache : n α → n α :=
mapMetaM resettingSynthInstanceCacheImpl
@[inline] def resettingSynthInstanceCacheWhen (b : Bool) (x : n α) : n α :=
if b then resettingSynthInstanceCache x else x
private def withNewLocalInstanceImp (className : Name) (fvar : Expr) (k : MetaM α) : MetaM α := do
let localDecl ← getFVarLocalDecl fvar
/- Recall that we use `auxDecl` binderInfo when compiling recursive declarations. -/
match localDecl.binderInfo with
| BinderInfo.auxDecl => k
| _ =>
resettingSynthInstanceCache <|
withReader
(fun ctx => { ctx with localInstances := ctx.localInstances.push { className := className, fvar := fvar } })
k
/-- Add entry `{ className := className, fvar := fvar }` to localInstances,
and then execute continuation `k`.
It resets the type class cache using `resettingSynthInstanceCache`. -/
def withNewLocalInstance (className : Name) (fvar : Expr) : n α → n α :=
mapMetaM <| withNewLocalInstanceImp className fvar
private def fvarsSizeLtMaxFVars (fvars : Array Expr) (maxFVars? : Option Nat) : Bool :=
match maxFVars? with
| some maxFVars => fvars.size < maxFVars
| none => true
mutual
/--
`withNewLocalInstances isClassExpensive fvars j k` updates the vector or local instances
using free variables `fvars[j] ... fvars.back`, and execute `k`.
- `isClassExpensive` is defined later.
- The type class chache is reset whenever a new local instance is found.
- `isClassExpensive` uses `whnf` which depends (indirectly) on the set of local instances.
Thus, each new local instance requires a new `resettingSynthInstanceCache`. -/
private partial def withNewLocalInstancesImp
(fvars : Array Expr) (i : Nat) (k : MetaM α) : MetaM α := do
if h : i < fvars.size then
let fvar := fvars.get ⟨i, h⟩
let decl ← getFVarLocalDecl fvar
match (← isClassQuick? decl.type) with
| LOption.none => withNewLocalInstancesImp fvars (i+1) k
| LOption.undef =>
match (← isClassExpensive? decl.type) with
| none => withNewLocalInstancesImp fvars (i+1) k
| some c => withNewLocalInstance c fvar <| withNewLocalInstancesImp fvars (i+1) k
| LOption.some c => withNewLocalInstance c fvar <| withNewLocalInstancesImp fvars (i+1) k
else
k
/--
`forallTelescopeAuxAux lctx fvars j type`
Remarks:
- `lctx` is the `MetaM` local context extended with declarations for `fvars`.
- `type` is the type we are computing the telescope for. It contains only
dangling bound variables in the range `[j, fvars.size)`
- if `reducing? == true` and `type` is not `forallE`, we use `whnf`.
- when `type` is not a `forallE` nor it can't be reduced to one, we
excute the continuation `k`.
Here is an example that demonstrates the `reducing?`.
Suppose we have
```
abbrev StateM s a := s -> Prod a s
```
Now, assume we are trying to build the telescope for
```
forall (x : Nat), StateM Int Bool
```
if `reducing == true`, the function executes `k #[(x : Nat) (s : Int)] Bool`.
if `reducing == false`, the function executes `k #[(x : Nat)] (StateM Int Bool)`
if `maxFVars?` is `some max`, then we interrupt the telescope construction
when `fvars.size == max`
-/
private partial def forallTelescopeReducingAuxAux
(reducing : Bool) (maxFVars? : Option Nat)
(type : Expr)
(k : Array Expr → Expr → MetaM α) : MetaM α := do
let rec process (lctx : LocalContext) (fvars : Array Expr) (j : Nat) (type : Expr) : MetaM α := do
match type with
| Expr.forallE n d b c =>
if fvarsSizeLtMaxFVars fvars maxFVars? then
let d := d.instantiateRevRange j fvars.size fvars
let fvarId ← mkFreshFVarId
let lctx := lctx.mkLocalDecl fvarId n d c.binderInfo
let fvar := mkFVar fvarId
let fvars := fvars.push fvar
process lctx fvars j b
else
let type := type.instantiateRevRange j fvars.size fvars;
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
k fvars type
| _ =>
let type := type.instantiateRevRange j fvars.size fvars;
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
if reducing && fvarsSizeLtMaxFVars fvars maxFVars? then
let newType ← whnf type
if newType.isForall then
process lctx fvars fvars.size newType
else
k fvars type
else
k fvars type
process (← getLCtx) #[] 0 type
private partial def forallTelescopeReducingAux (type : Expr) (maxFVars? : Option Nat) (k : Array Expr → Expr → MetaM α) : MetaM α := do
match maxFVars? with
| some 0 => k #[] type
| _ => do
let newType ← whnf type
if newType.isForall then
forallTelescopeReducingAuxAux true maxFVars? newType k
else
k #[] type
private partial def isClassExpensive? : Expr → MetaM (Option Name)
| type => withReducible <| -- when testing whether a type is a type class, we only unfold reducible constants.
forallTelescopeReducingAux type none fun xs type => do
let env ← getEnv
match type.getAppFn with
| Expr.const c _ _ => do
if isClass env c then
return some c
else
-- make sure abbreviations are unfolded
match (← whnf type).getAppFn with
| Expr.const c _ _ => return if isClass env c then some c else none
| _ => return none
| _ => return none
private partial def isClassImp? (type : Expr) : MetaM (Option Name) := do
match (← isClassQuick? type) with
| LOption.none => pure none
| LOption.some c => pure (some c)
| LOption.undef => isClassExpensive? type
end
def isClass? (type : Expr) : MetaM (Option Name) :=
try isClassImp? type catch _ => pure none
private def withNewLocalInstancesImpAux (fvars : Array Expr) (j : Nat) : n α → n α :=
mapMetaM <| withNewLocalInstancesImp fvars j
partial def withNewLocalInstances (fvars : Array Expr) (j : Nat) : n α → n α :=
mapMetaM <| withNewLocalInstancesImpAux fvars j
@[inline] private def forallTelescopeImp (type : Expr) (k : Array Expr → Expr → MetaM α) : MetaM α := do
forallTelescopeReducingAuxAux (reducing := false) (maxFVars? := none) type k
/--
Given `type` of the form `forall xs, A`, execute `k xs A`.
This combinator will declare local declarations, create free variables for them,
execute `k` with updated local context, and make sure the cache is restored after executing `k`. -/
def forallTelescope (type : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => forallTelescopeImp type k) k
private def forallTelescopeReducingImp (type : Expr) (k : Array Expr → Expr → MetaM α) : MetaM α :=
forallTelescopeReducingAux type (maxFVars? := none) k
/--
Similar to `forallTelescope`, but given `type` of the form `forall xs, A`,
it reduces `A` and continues bulding the telescope if it is a `forall`. -/
def forallTelescopeReducing (type : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => forallTelescopeReducingImp type k) k
private def forallBoundedTelescopeImp (type : Expr) (maxFVars? : Option Nat) (k : Array Expr → Expr → MetaM α) : MetaM α :=
forallTelescopeReducingAux type maxFVars? k
/--
Similar to `forallTelescopeReducing`, stops constructing the telescope when
it reaches size `maxFVars`. -/
def forallBoundedTelescope (type : Expr) (maxFVars? : Option Nat) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => forallBoundedTelescopeImp type maxFVars? k) k
private partial def lambdaTelescopeImp (e : Expr) (consumeLet : Bool) (k : Array Expr → Expr → MetaM α) : MetaM α := do
process consumeLet (← getLCtx) #[] 0 e
where
process (consumeLet : Bool) (lctx : LocalContext) (fvars : Array Expr) (j : Nat) (e : Expr) : MetaM α := do
match consumeLet, e with
| _, Expr.lam n d b c =>
let d := d.instantiateRevRange j fvars.size fvars
let fvarId ← mkFreshFVarId
let lctx := lctx.mkLocalDecl fvarId n d c.binderInfo
let fvar := mkFVar fvarId
process consumeLet lctx (fvars.push fvar) j b
| true, Expr.letE n t v b _ => do
let t := t.instantiateRevRange j fvars.size fvars
let v := v.instantiateRevRange j fvars.size fvars
let fvarId ← mkFreshFVarId
let lctx := lctx.mkLetDecl fvarId n t v
let fvar := mkFVar fvarId
process true lctx (fvars.push fvar) j b
| _, e =>
let e := e.instantiateRevRange j fvars.size fvars
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
k fvars e
/-- Similar to `forallTelescope` but for lambda and let expressions. -/
def lambdaLetTelescope (type : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => lambdaTelescopeImp type true k) k
/-- Similar to `forallTelescope` but for lambda expressions. -/
def lambdaTelescope (type : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => lambdaTelescopeImp type false k) k
/-- Return the parameter names for the givel global declaration. -/
def getParamNames (declName : Name) : MetaM (Array Name) := do
forallTelescopeReducing (← getConstInfo declName).type fun xs _ => do
xs.mapM fun x => do
let localDecl ← getLocalDecl x.fvarId!
pure localDecl.userName
-- `kind` specifies the metavariable kind for metavariables not corresponding to instance implicit `[ ... ]` arguments.
private partial def forallMetaTelescopeReducingAux
(e : Expr) (reducing : Bool) (maxMVars? : Option Nat) (kind : MetavarKind) : MetaM (Array Expr × Array BinderInfo × Expr) :=
process #[] #[] 0 e
where
process (mvars : Array Expr) (bis : Array BinderInfo) (j : Nat) (type : Expr) : MetaM (Array Expr × Array BinderInfo × Expr) := do
if maxMVars?.isEqSome mvars.size then
let type := type.instantiateRevRange j mvars.size mvars;
return (mvars, bis, type)
else
match type with
| Expr.forallE n d b c =>
let d := d.instantiateRevRange j mvars.size mvars
let k := if c.binderInfo.isInstImplicit then MetavarKind.synthetic else kind
let mvar ← mkFreshExprMVar d k n
let mvars := mvars.push mvar
let bis := bis.push c.binderInfo
process mvars bis j b
| _ =>
let type := type.instantiateRevRange j mvars.size mvars;
if reducing then do
let newType ← whnf type;
if newType.isForall then
process mvars bis mvars.size newType
else
return (mvars, bis, type)
else
return (mvars, bis, type)
/-- Similar to `forallTelescope`, but creates metavariables instead of free variables. -/
def forallMetaTelescope (e : Expr) (kind := MetavarKind.natural) : MetaM (Array Expr × Array BinderInfo × Expr) :=
forallMetaTelescopeReducingAux e (reducing := false) (maxMVars? := none) kind
/-- Similar to `forallTelescopeReducing`, but creates metavariables instead of free variables. -/
def forallMetaTelescopeReducing (e : Expr) (maxMVars? : Option Nat := none) (kind := MetavarKind.natural) : MetaM (Array Expr × Array BinderInfo × Expr) :=
forallMetaTelescopeReducingAux e (reducing := true) maxMVars? kind
/-- Similar to `forallMetaTelescopeReducing`, stops constructing the telescope when it reaches size `maxMVars`. -/
def forallMetaBoundedTelescope (e : Expr) (maxMVars : Nat) (kind : MetavarKind := MetavarKind.natural) : MetaM (Array Expr × Array BinderInfo × Expr) :=
forallMetaTelescopeReducingAux e (reducing := true) (maxMVars? := some maxMVars) (kind := kind)
/-- Similar to `forallMetaTelescopeReducingAux` but for lambda expressions. -/
partial def lambdaMetaTelescope (e : Expr) (maxMVars? : Option Nat := none) : MetaM (Array Expr × Array BinderInfo × Expr) :=
process #[] #[] 0 e
where
process (mvars : Array Expr) (bis : Array BinderInfo) (j : Nat) (type : Expr) : MetaM (Array Expr × Array BinderInfo × Expr) := do
let finalize : Unit → MetaM (Array Expr × Array BinderInfo × Expr) := fun _ => do
let type := type.instantiateRevRange j mvars.size mvars
pure (mvars, bis, type)
if maxMVars?.isEqSome mvars.size then
finalize ()
else
match type with
| Expr.lam n d b c =>
let d := d.instantiateRevRange j mvars.size mvars
let mvar ← mkFreshExprMVar d
let mvars := mvars.push mvar
let bis := bis.push c.binderInfo
process mvars bis j b
| _ => finalize ()
private def withNewFVar (fvar fvarType : Expr) (k : Expr → MetaM α) : MetaM α := do
match (← isClass? fvarType) with
| none => k fvar
| some c => withNewLocalInstance c fvar <| k fvar
private def withLocalDeclImp (n : Name) (bi : BinderInfo) (type : Expr) (k : Expr → MetaM α) : MetaM α := do
let fvarId ← mkFreshFVarId
let ctx ← read
let lctx := ctx.lctx.mkLocalDecl fvarId n type bi
let fvar := mkFVar fvarId
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewFVar fvar type k
def withLocalDecl (name : Name) (bi : BinderInfo) (type : Expr) (k : Expr → n α) : n α :=
map1MetaM (fun k => withLocalDeclImp name bi type k) k
def withLocalDeclD (name : Name) (type : Expr) (k : Expr → n α) : n α :=
withLocalDecl name BinderInfo.default type k
partial def withLocalDecls
[Inhabited α]
(declInfos : Array (Name × BinderInfo × (Array Expr → n Expr)))
(k : (xs : Array Expr) → n α)
: n α :=
loop #[]
where
loop [Inhabited α] (acc : Array Expr) : n α := do
if acc.size < declInfos.size then
let (name, bi, typeCtor) := declInfos[acc.size]
withLocalDecl name bi (←typeCtor acc) fun x => loop (acc.push x)
else
k acc
def withLocalDeclsD [Inhabited α] (declInfos : Array (Name × (Array Expr → n Expr))) (k : (xs : Array Expr) → n α) : n α :=
withLocalDecls
(declInfos.map (fun (name, typeCtor) => (name, BinderInfo.default, typeCtor))) k
private def withNewBinderInfosImp (bs : Array (FVarId × BinderInfo)) (k : MetaM α) : MetaM α := do
let lctx := bs.foldl (init := (← getLCtx)) fun lctx (fvarId, bi) =>
lctx.setBinderInfo fvarId bi
withReader (fun ctx => { ctx with lctx := lctx }) k
def withNewBinderInfos (bs : Array (FVarId × BinderInfo)) (k : n α) : n α :=
mapMetaM (fun k => withNewBinderInfosImp bs k) k
private def withLetDeclImp (n : Name) (type : Expr) (val : Expr) (k : Expr → MetaM α) : MetaM α := do
let fvarId ← mkFreshFVarId
let ctx ← read
let lctx := ctx.lctx.mkLetDecl fvarId n type val
let fvar := mkFVar fvarId
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewFVar fvar type k
def withLetDecl (name : Name) (type : Expr) (val : Expr) (k : Expr → n α) : n α :=
map1MetaM (fun k => withLetDeclImp name type val k) k
private def withExistingLocalDeclsImp (decls : List LocalDecl) (k : MetaM α) : MetaM α := do
let ctx ← read
let numLocalInstances := ctx.localInstances.size
let lctx := decls.foldl (fun (lctx : LocalContext) decl => lctx.addDecl decl) ctx.lctx
withReader (fun ctx => { ctx with lctx := lctx }) do
let newLocalInsts ← decls.foldlM
(fun (newlocalInsts : Array LocalInstance) (decl : LocalDecl) => (do {
match (← isClass? decl.type) with
| none => pure newlocalInsts
| some c => pure <| newlocalInsts.push { className := c, fvar := decl.toExpr } } : MetaM _))
ctx.localInstances;
if newLocalInsts.size == numLocalInstances then
k
else
resettingSynthInstanceCache <| withReader (fun ctx => { ctx with localInstances := newLocalInsts }) k
def withExistingLocalDecls (decls : List LocalDecl) : n α → n α :=
mapMetaM <| withExistingLocalDeclsImp decls
private def withNewMCtxDepthImp (x : MetaM α) : MetaM α := do
let saved ← get
modify fun s => { s with mctx := s.mctx.incDepth, postponed := {} }
try
x
finally
modify fun s => { s with mctx := saved.mctx, postponed := saved.postponed }
/--
Save cache and `MetavarContext`, bump the `MetavarContext` depth, execute `x`,
and restore saved data. -/
def withNewMCtxDepth : n α → n α :=
mapMetaM withNewMCtxDepthImp
private def withLocalContextImp (lctx : LocalContext) (localInsts : LocalInstances) (x : MetaM α) : MetaM α := do
let localInstsCurr ← getLocalInstances
withReader (fun ctx => { ctx with lctx := lctx, localInstances := localInsts }) do
if localInsts == localInstsCurr then
x
else
resettingSynthInstanceCache x
def withLCtx (lctx : LocalContext) (localInsts : LocalInstances) : n α → n α :=
mapMetaM <| withLocalContextImp lctx localInsts
private def withMVarContextImp (mvarId : MVarId) (x : MetaM α) : MetaM α := do
let mvarDecl ← getMVarDecl mvarId
withLocalContextImp mvarDecl.lctx mvarDecl.localInstances x
/--
Execute `x` using the given metavariable `LocalContext` and `LocalInstances`.
The type class resolution cache is flushed when executing `x` if its `LocalInstances` are
different from the current ones. -/
def withMVarContext (mvarId : MVarId) : n α → n α :=
mapMetaM <| withMVarContextImp mvarId
private def withMCtxImp (mctx : MetavarContext) (x : MetaM α) : MetaM α := do
let mctx' ← getMCtx
setMCtx mctx
try x finally setMCtx mctx'
def withMCtx (mctx : MetavarContext) : n α → n α :=
mapMetaM <| withMCtxImp mctx
@[inline] private def approxDefEqImp (x : MetaM α) : MetaM α :=
withConfig (fun config => { config with foApprox := true, ctxApprox := true, quasiPatternApprox := true}) x
/-- Execute `x` using approximate unification: `foApprox`, `ctxApprox` and `quasiPatternApprox`. -/
@[inline] def approxDefEq : n α → n α :=
mapMetaM approxDefEqImp
@[inline] private def fullApproxDefEqImp (x : MetaM α) : MetaM α :=
withConfig (fun config => { config with foApprox := true, ctxApprox := true, quasiPatternApprox := true, constApprox := true }) x
/--
Similar to `approxDefEq`, but uses all available approximations.
We don't use `constApprox` by default at `approxDefEq` because it often produces undesirable solution for monadic code.
For example, suppose we have `pure (x > 0)` which has type `?m Prop`. We also have the goal `[Pure ?m]`.
Now, assume the expected type is `IO Bool`. Then, the unification constraint `?m Prop =?= IO Bool` could be solved
as `?m := fun _ => IO Bool` using `constApprox`, but this spurious solution would generate a failure when we try to
solve `[Pure (fun _ => IO Bool)]` -/
@[inline] def fullApproxDefEq : n α → n α :=
mapMetaM fullApproxDefEqImp
def normalizeLevel (u : Level) : MetaM Level := do
let u ← instantiateLevelMVars u
pure u.normalize
def assignLevelMVar (mvarId : MVarId) (u : Level) : MetaM Unit := do
modifyMCtx fun mctx => mctx.assignLevel mvarId u
def whnfR (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.reducible <| whnf e
def whnfD (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.default <| whnf e
def whnfI (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.instances <| whnf e
def setInlineAttribute (declName : Name) (kind := Compiler.InlineAttributeKind.inline): MetaM Unit := do
let env ← getEnv
match Compiler.setInlineAttribute env declName kind with
| Except.ok env => setEnv env
| Except.error msg => throwError msg
private partial def instantiateForallAux (ps : Array Expr) (i : Nat) (e : Expr) : MetaM Expr := do
if h : i < ps.size then
let p := ps.get ⟨i, h⟩
match (← whnf e) with
| Expr.forallE _ _ b _ => instantiateForallAux ps (i+1) (b.instantiate1 p)
| _ => throwError "invalid instantiateForall, too many parameters"
else
pure e
/- Given `e` of the form `forall (a_1 : A_1) ... (a_n : A_n), B[a_1, ..., a_n]` and `p_1 : A_1, ... p_n : A_n`, return `B[p_1, ..., p_n]`. -/
def instantiateForall (e : Expr) (ps : Array Expr) : MetaM Expr :=
instantiateForallAux ps 0 e
private partial def instantiateLambdaAux (ps : Array Expr) (i : Nat) (e : Expr) : MetaM Expr := do
if h : i < ps.size then
let p := ps.get ⟨i, h⟩
match (← whnf e) with
| Expr.lam _ _ b _ => instantiateLambdaAux ps (i+1) (b.instantiate1 p)
| _ => throwError "invalid instantiateLambda, too many parameters"
else
pure e
/- Given `e` of the form `fun (a_1 : A_1) ... (a_n : A_n) => t[a_1, ..., a_n]` and `p_1 : A_1, ... p_n : A_n`, return `t[p_1, ..., p_n]`.
It uses `whnf` to reduce `e` if it is not a lambda -/
def instantiateLambda (e : Expr) (ps : Array Expr) : MetaM Expr :=
instantiateLambdaAux ps 0 e
/-- Return true iff `e` depends on the free variable `fvarId` -/
def dependsOn (e : Expr) (fvarId : FVarId) : MetaM Bool :=
return (← getMCtx).exprDependsOn e fvarId
def ppExpr (e : Expr) : MetaM Format := do
let ctxCore ← readThe Core.Context
Lean.ppExpr { env := (← getEnv), mctx := (← getMCtx), lctx := (← getLCtx), opts := (← getOptions), currNamespace := ctxCore.currNamespace, openDecls := ctxCore.openDecls } e
@[inline] protected def orElse (x : MetaM α) (y : Unit → MetaM α) : MetaM α := do
let s ← saveState
try x catch _ => s.restore; y ()
instance : OrElse (MetaM α) := ⟨Meta.orElse⟩
instance : Alternative MetaM where
failure := fun {α} => throwError "failed"
orElse := Meta.orElse
@[inline] private def orelseMergeErrorsImp (x y : MetaM α)
(mergeRef : Syntax → Syntax → Syntax := fun r₁ r₂ => r₁)
(mergeMsg : MessageData → MessageData → MessageData := fun m₁ m₂ => m₁ ++ Format.line ++ m₂) : MetaM α := do
let env ← getEnv
let mctx ← getMCtx
try
x
catch ex =>
setEnv env
setMCtx mctx
match ex with
| Exception.error ref₁ m₁ =>
try
y
catch
| Exception.error ref₂ m₂ => throw <| Exception.error (mergeRef ref₁ ref₂) (mergeMsg m₁ m₂)
| ex => throw ex
| ex => throw ex
/--
Similar to `orelse`, but merge errors. Note that internal errors are not caught.
The default `mergeRef` uses the `ref` (position information) for the first message.
The default `mergeMsg` combines error messages using `Format.line ++ Format.line` as a separator. -/
@[inline] def orelseMergeErrors [MonadControlT MetaM m] [Monad m] (x y : m α)
(mergeRef : Syntax → Syntax → Syntax := fun r₁ r₂ => r₁)
(mergeMsg : MessageData → MessageData → MessageData := fun m₁ m₂ => m₁ ++ Format.line ++ Format.line ++ m₂) : m α := do
controlAt MetaM fun runInBase => orelseMergeErrorsImp (runInBase x) (runInBase y) mergeRef mergeMsg
/-- Execute `x`, and apply `f` to the produced error message -/
def mapErrorImp (x : MetaM α) (f : MessageData → MessageData) : MetaM α := do
try
x
catch
| Exception.error ref msg => throw <| Exception.error ref <| f msg
| ex => throw ex
@[inline] def mapError [MonadControlT MetaM m] [Monad m] (x : m α) (f : MessageData → MessageData) : m α :=
controlAt MetaM fun runInBase => mapErrorImp (runInBase x) f
end Methods
end Meta
export Meta (MetaM)
end Lean
|
f80e103f2a2bd0f2f0201f3846024c749c20cbe3
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/measure_theory/integral/mean_inequalities.lean
|
970d8d1085a2324fd0ddd0c17bdd872601e8773d
|
[
"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
| 20,814
|
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
-/
import measure_theory.integral.lebesgue
import analysis.mean_inequalities
import analysis.mean_inequalities_pow
import measure_theory.function.special_functions.basic
/-!
# Mean value inequalities for integrals
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we prove several inequalities on integrals, notably the Hölder inequality and
the Minkowski inequality. The versions for finite sums are in `analysis.mean_inequalities`.
## Main results
Hölder's inequality for the Lebesgue integral of `ℝ≥0∞` and `ℝ≥0` functions: we prove
`∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents
and `α→(e)nnreal` functions in two cases,
* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions,
* `nnreal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions.
Minkowski's inequality for the Lebesgue integral of measurable functions with `ℝ≥0∞` values:
we prove `(∫ (f + g)^p ∂μ) ^ (1/p) ≤ (∫ f^p ∂μ) ^ (1/p) + (∫ g^p ∂μ) ^ (1/p)` for `1 ≤ p`.
-/
section lintegral
/-!
### Hölder's inequality for the Lebesgue integral of ℝ≥0∞ and nnreal functions
We prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q`
conjugate real exponents and `α→(e)nnreal` functions in several cases, the first two being useful
only to prove the more general results:
* `ennreal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ℝ≥0∞ functions for which the
integrals on the right are equal to 1,
* `ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ℝ≥0∞ functions for which the
integrals on the right are neither ⊤ nor 0,
* `ennreal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions,
* `nnreal.lintegral_mul_le_Lp_mul_Lq` : nnreal functions.
-/
noncomputable theory
open_locale classical big_operators nnreal ennreal
open measure_theory
variables {α : Type*} [measurable_space α] {μ : measure α}
namespace ennreal
lemma lintegral_mul_le_one_of_lintegral_rpow_eq_one {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hf_norm : ∫⁻ a, (f a)^p ∂μ = 1)
(hg_norm : ∫⁻ a, (g a)^q ∂μ = 1) :
∫⁻ a, (f * g) a ∂μ ≤ 1 :=
begin
calc ∫⁻ (a : α), ((f * g) a) ∂μ
≤ ∫⁻ (a : α), ((f a)^p / ennreal.of_real p + (g a)^q / ennreal.of_real q) ∂μ :
lintegral_mono (λ a, young_inequality (f a) (g a) hpq)
... = 1 :
begin
simp only [div_eq_mul_inv],
rw lintegral_add_left',
{ rw [lintegral_mul_const'' _ (hf.pow_const p), lintegral_mul_const', hf_norm, hg_norm,
← div_eq_mul_inv, ← div_eq_mul_inv, hpq.inv_add_inv_conj_ennreal],
simp [hpq.symm.pos], },
{ exact (hf.pow_const _).mul_const _, },
end
end
/-- Function multiplied by the inverse of its p-seminorm `(∫⁻ f^p ∂μ) ^ 1/p`-/
def fun_mul_inv_snorm (f : α → ℝ≥0∞) (p : ℝ) (μ : measure α) : α → ℝ≥0∞ :=
λ a, (f a) * ((∫⁻ c, (f c) ^ p ∂μ) ^ (1 / p))⁻¹
lemma fun_eq_fun_mul_inv_snorm_mul_snorm {p : ℝ} (f : α → ℝ≥0∞)
(hf_nonzero : ∫⁻ a, (f a) ^ p ∂μ ≠ 0) (hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) {a : α} :
f a = (fun_mul_inv_snorm f p μ a) * (∫⁻ c, (f c)^p ∂μ)^(1/p) :=
by simp [fun_mul_inv_snorm, mul_assoc, ennreal.inv_mul_cancel, hf_nonzero, hf_top]
lemma fun_mul_inv_snorm_rpow {p : ℝ} (hp0 : 0 < p) {f : α → ℝ≥0∞} {a : α} :
(fun_mul_inv_snorm f p μ a) ^ p = (f a)^p * (∫⁻ c, (f c) ^ p ∂μ)⁻¹ :=
begin
rw [fun_mul_inv_snorm, mul_rpow_of_nonneg _ _ (le_of_lt hp0)],
suffices h_inv_rpow : ((∫⁻ (c : α), f c ^ p ∂μ) ^ (1 / p))⁻¹ ^ p = (∫⁻ (c : α), f c ^ p ∂μ)⁻¹,
by rw h_inv_rpow,
rw [inv_rpow, ← rpow_mul, one_div_mul_cancel hp0.ne', rpow_one]
end
lemma lintegral_rpow_fun_mul_inv_snorm_eq_one {p : ℝ} (hp0_lt : 0 < p) {f : α → ℝ≥0∞}
(hf_nonzero : ∫⁻ a, (f a)^p ∂μ ≠ 0) (hf_top : ∫⁻ a, (f a)^p ∂μ ≠ ⊤) :
∫⁻ c, (fun_mul_inv_snorm f p μ c)^p ∂μ = 1 :=
begin
simp_rw fun_mul_inv_snorm_rpow hp0_lt,
rw [lintegral_mul_const', ennreal.mul_inv_cancel hf_nonzero hf_top],
rwa inv_ne_top
end
/-- Hölder's inequality in case of finite non-zero integrals -/
lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ)
(hf_nontop : ∫⁻ a, (f a)^p ∂μ ≠ ⊤) (hg_nontop : ∫⁻ a, (g a)^q ∂μ ≠ ⊤)
(hf_nonzero : ∫⁻ a, (f a)^p ∂μ ≠ 0) (hg_nonzero : ∫⁻ a, (g a)^q ∂μ ≠ 0) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ)^(1/p) * (∫⁻ a, (g a)^q ∂μ)^(1/q) :=
begin
let npf := (∫⁻ (c : α), (f c) ^ p ∂μ) ^ (1/p),
let nqg := (∫⁻ (c : α), (g c) ^ q ∂μ) ^ (1/q),
calc ∫⁻ (a : α), (f * g) a ∂μ
= ∫⁻ (a : α), ((fun_mul_inv_snorm f p μ * fun_mul_inv_snorm g q μ) a)
* (npf * nqg) ∂μ :
begin
refine lintegral_congr (λ a, _),
rw [pi.mul_apply, fun_eq_fun_mul_inv_snorm_mul_snorm f hf_nonzero hf_nontop,
fun_eq_fun_mul_inv_snorm_mul_snorm g hg_nonzero hg_nontop, pi.mul_apply],
ring,
end
... ≤ npf * nqg :
begin
rw lintegral_mul_const' (npf * nqg) _
(by simp [hf_nontop, hg_nontop, hf_nonzero, hg_nonzero, ennreal.mul_eq_top]),
refine mul_le_of_le_one_left' _,
have hf1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.pos hf_nonzero hf_nontop,
have hg1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.symm.pos hg_nonzero hg_nontop,
exact lintegral_mul_le_one_of_lintegral_rpow_eq_one hpq (hf.mul_const _) hf1 hg1,
end
end
lemma ae_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hf_zero : ∫⁻ a, (f a)^p ∂μ = 0) :
f =ᵐ[μ] 0 :=
begin
rw lintegral_eq_zero_iff' (hf.pow_const p) at hf_zero,
refine filter.eventually.mp hf_zero (filter.eventually_of_forall (λ x, _)),
dsimp only,
rw [pi.zero_apply, ← not_imp_not],
exact λ hx, (rpow_pos_of_nonneg (pos_iff_ne_zero.2 hx) hp0).ne'
end
lemma lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hf_zero : ∫⁻ a, (f a)^p ∂μ = 0) :
∫⁻ a, (f * g) a ∂μ = 0 :=
begin
rw ←@lintegral_zero_fun α _ μ,
refine lintegral_congr_ae _,
suffices h_mul_zero : f * g =ᵐ[μ] 0 * g , by rwa zero_mul at h_mul_zero,
have hf_eq_zero : f =ᵐ[μ] 0, from ae_eq_zero_of_lintegral_rpow_eq_zero hp0 hf hf_zero,
exact hf_eq_zero.mul (ae_eq_refl g),
end
lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {p q : ℝ} (hp0_lt : 0 < p) (hq0 : 0 ≤ q)
{f g : α → ℝ≥0∞} (hf_top : ∫⁻ a, (f a)^p ∂μ = ⊤) (hg_nonzero : ∫⁻ a, (g a)^q ∂μ ≠ 0) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^q ∂μ) ^ (1/q) :=
begin
refine le_trans le_top (le_of_eq _),
have hp0_inv_lt : 0 < 1/p, by simp [hp0_lt],
rw [hf_top, ennreal.top_rpow_of_pos hp0_inv_lt],
simp [hq0, hg_nonzero],
end
/-- Hölder's inequality for functions `α → ℝ≥0∞`. The integral of the product of two functions
is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem lintegral_mul_le_Lp_mul_Lq (μ : measure α) {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^q ∂μ) ^ (1/q) :=
begin
by_cases hf_zero : ∫⁻ a, (f a) ^ p ∂μ = 0,
{ refine eq.trans_le _ (zero_le _),
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.nonneg hf hf_zero, },
by_cases hg_zero : ∫⁻ a, (g a) ^ q ∂μ = 0,
{ refine eq.trans_le _ (zero_le _),
rw mul_comm,
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.symm.nonneg hg hg_zero, },
by_cases hf_top : ∫⁻ a, (f a) ^ p ∂μ = ⊤,
{ exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.pos hpq.symm.nonneg hf_top hg_zero, },
by_cases hg_top : ∫⁻ a, (g a) ^ q ∂μ = ⊤,
{ rw [mul_comm, mul_comm ((∫⁻ (a : α), (f a) ^ p ∂μ) ^ (1 / p))],
exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.symm.pos hpq.nonneg hg_top hf_zero, },
-- non-⊤ non-zero case
exact ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top hpq hf hf_top hg_top hf_zero hg_zero
end
lemma lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top {p : ℝ}
{f g : α → ℝ≥0∞} (hf : ae_measurable f μ) (hf_top : ∫⁻ a, (f a) ^ p ∂μ < ⊤)
(hg_top : ∫⁻ a, (g a) ^ p ∂μ < ⊤) (hp1 : 1 ≤ p) :
∫⁻ a, ((f + g) a) ^ p ∂μ < ⊤ :=
begin
have hp0_lt : 0 < p, from lt_of_lt_of_le zero_lt_one hp1,
have hp0 : 0 ≤ p, from le_of_lt hp0_lt,
calc ∫⁻ (a : α), (f a + g a) ^ p ∂μ
≤ ∫⁻ a, ((2:ℝ≥0∞)^(p-1) * (f a) ^ p + (2:ℝ≥0∞)^(p-1) * (g a) ^ p) ∂ μ :
begin
refine lintegral_mono (λ a, _),
dsimp only,
have h_zero_lt_half_rpow : (0 : ℝ≥0∞) < (1 / 2) ^ p,
{ rw [←ennreal.zero_rpow_of_pos hp0_lt],
exact ennreal.rpow_lt_rpow (by simp [zero_lt_one]) hp0_lt, },
have h_rw : (1 / 2) ^ p * (2:ℝ≥0∞) ^ (p - 1) = 1 / 2,
{ rw [sub_eq_add_neg, ennreal.rpow_add _ _ two_ne_zero ennreal.coe_ne_top,
←mul_assoc, ←ennreal.mul_rpow_of_nonneg _ _ hp0, one_div,
ennreal.inv_mul_cancel two_ne_zero ennreal.coe_ne_top, ennreal.one_rpow,
one_mul, ennreal.rpow_neg_one], },
rw ←ennreal.mul_le_mul_left (ne_of_lt h_zero_lt_half_rpow).symm _,
{ rw [mul_add, ← mul_assoc, ← mul_assoc, h_rw, ←ennreal.mul_rpow_of_nonneg _ _ hp0, mul_add],
refine ennreal.rpow_arith_mean_le_arith_mean2_rpow (1/2 : ℝ≥0∞) (1/2 : ℝ≥0∞)
(f a) (g a) _ hp1,
rw [ennreal.div_add_div_same, one_add_one_eq_two,
ennreal.div_self two_ne_zero ennreal.coe_ne_top], },
{ rw ← lt_top_iff_ne_top,
refine ennreal.rpow_lt_top_of_nonneg hp0 _,
rw [one_div, ennreal.inv_ne_top],
exact two_ne_zero, },
end
... < ⊤ :
begin
have h_two : (2 : ℝ≥0∞) ^ (p - 1) ≠ ⊤,
from ennreal.rpow_ne_top_of_nonneg (by simp [hp1]) ennreal.coe_ne_top,
rw [lintegral_add_left', lintegral_const_mul'' _ (hf.pow_const p),
lintegral_const_mul' _ _ h_two, ennreal.add_lt_top],
{ exact ⟨ennreal.mul_lt_top h_two hf_top.ne, ennreal.mul_lt_top h_two hg_top.ne⟩ },
{ exact (hf.pow_const p).const_mul _ }
end
end
lemma lintegral_Lp_mul_le_Lq_mul_Lr {α} [measurable_space α] {p q r : ℝ} (hp0_lt : 0 < p)
(hpq : p < q) (hpqr : 1/p = 1/q + 1/r) (μ : measure α) {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) :
(∫⁻ a, ((f * g) a)^p ∂μ) ^ (1/p) ≤ (∫⁻ a, (f a)^q ∂μ) ^ (1/q) * (∫⁻ a, (g a)^r ∂μ) ^ (1/r) :=
begin
have hp0_ne : p ≠ 0, from (ne_of_lt hp0_lt).symm,
have hp0 : 0 ≤ p, from le_of_lt hp0_lt,
have hq0_lt : 0 < q, from lt_of_le_of_lt hp0 hpq,
have hq0_ne : q ≠ 0, from (ne_of_lt hq0_lt).symm,
have h_one_div_r : 1/r = 1/p - 1/q, by simp [hpqr],
have hr0_ne : r ≠ 0,
{ have hr_inv_pos : 0 < 1/r,
by rwa [h_one_div_r, sub_pos, one_div_lt_one_div hq0_lt hp0_lt],
rw [one_div, _root_.inv_pos] at hr_inv_pos,
exact (ne_of_lt hr_inv_pos).symm, },
let p2 := q/p,
let q2 := p2.conjugate_exponent,
have hp2q2 : p2.is_conjugate_exponent q2,
from real.is_conjugate_exponent_conjugate_exponent (by simp [lt_div_iff, hpq, hp0_lt]),
calc (∫⁻ (a : α), ((f * g) a) ^ p ∂μ) ^ (1 / p)
= (∫⁻ (a : α), (f a)^p * (g a)^p ∂μ) ^ (1 / p) :
by simp_rw [pi.mul_apply, ennreal.mul_rpow_of_nonneg _ _ hp0]
... ≤ ((∫⁻ a, (f a)^(p * p2) ∂ μ)^(1/p2) * (∫⁻ a, (g a)^(p * q2) ∂ μ)^(1/q2)) ^ (1/p) :
begin
refine ennreal.rpow_le_rpow _ (by simp [hp0]),
simp_rw ennreal.rpow_mul,
exact ennreal.lintegral_mul_le_Lp_mul_Lq μ hp2q2 (hf.pow_const _) (hg.pow_const _)
end
... = (∫⁻ (a : α), (f a) ^ q ∂μ) ^ (1 / q) * (∫⁻ (a : α), (g a) ^ r ∂μ) ^ (1 / r) :
begin
rw [@ennreal.mul_rpow_of_nonneg _ _ (1/p) (by simp [hp0]), ←ennreal.rpow_mul,
←ennreal.rpow_mul],
have hpp2 : p * p2 = q,
{ symmetry, rw [mul_comm, ←div_eq_iff hp0_ne], },
have hpq2 : p * q2 = r,
{ rw [← inv_inv r, ← one_div, ← one_div, h_one_div_r],
field_simp [q2, real.conjugate_exponent, p2, hp0_ne, hq0_ne] },
simp_rw [div_mul_div_comm, mul_one, mul_comm p2, mul_comm q2, hpp2, hpq2],
end
end
lemma lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow {p q : ℝ}
(hpq : p.is_conjugate_exponent q) {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) (hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) :
∫⁻ a, (f a) * (g a) ^ (p - 1) ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^p ∂μ) ^ (1/q) :=
begin
refine le_trans (ennreal.lintegral_mul_le_Lp_mul_Lq μ hpq hf (hg.pow_const _)) _,
by_cases hf_zero_rpow : (∫⁻ (a : α), (f a) ^ p ∂μ) ^ (1 / p) = 0,
{ rw [hf_zero_rpow, zero_mul],
exact zero_le _, },
have hf_top_rpow : (∫⁻ (a : α), (f a) ^ p ∂μ) ^ (1 / p) ≠ ⊤,
{ by_contra h,
refine hf_top _,
have hp_not_neg : ¬ p < 0, by simp [hpq.nonneg],
simpa [hpq.pos, hp_not_neg] using h, },
refine (ennreal.mul_le_mul_left hf_zero_rpow hf_top_rpow).mpr (le_of_eq _),
congr,
ext1 a,
rw [←ennreal.rpow_mul, hpq.sub_one_mul_conj],
end
lemma lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add {p q : ℝ}
(hpq : p.is_conjugate_exponent q) {f g : α → ℝ≥0∞} (hf : ae_measurable f μ)
(hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) (hg : ae_measurable g μ) (hg_top : ∫⁻ a, (g a) ^ p ∂μ ≠ ⊤) :
∫⁻ a, ((f + g) a)^p ∂ μ
≤ ((∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p))
* (∫⁻ a, (f a + g a)^p ∂μ) ^ (1/q) :=
begin
calc ∫⁻ a, ((f+g) a) ^ p ∂μ ≤ ∫⁻ a, ((f + g) a) * ((f + g) a) ^ (p - 1) ∂μ :
begin
refine lintegral_mono (λ a, _),
dsimp only,
by_cases h_zero : (f + g) a = 0,
{ rw [h_zero, ennreal.zero_rpow_of_pos hpq.pos],
exact zero_le _, },
by_cases h_top : (f + g) a = ⊤,
{ rw [h_top, ennreal.top_rpow_of_pos hpq.sub_one_pos, ennreal.top_mul_top],
exact le_top, },
refine le_of_eq _,
nth_rewrite 1 ←ennreal.rpow_one ((f + g) a),
rw [←ennreal.rpow_add _ _ h_zero h_top, add_sub_cancel'_right],
end
... = ∫⁻ (a : α), f a * (f + g) a ^ (p - 1) ∂μ + ∫⁻ (a : α), g a * (f + g) a ^ (p - 1) ∂μ :
begin
have h_add_m : ae_measurable (λ (a : α), ((f + g) a) ^ (p-1)) μ,
from (hf.add hg).pow_const _,
have h_add_apply : ∫⁻ (a : α), (f + g) a * (f + g) a ^ (p - 1) ∂μ
= ∫⁻ (a : α), (f a + g a) * (f + g) a ^ (p - 1) ∂μ,
from rfl,
simp_rw [h_add_apply, add_mul],
rw lintegral_add_left' (hf.mul h_add_m),
end
... ≤ ((∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p))
* (∫⁻ a, (f a + g a)^p ∂μ) ^ (1/q) :
begin
rw add_mul,
exact add_le_add
(lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hf (hf.add hg) hf_top)
(lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hg (hf.add hg) hg_top),
end
end
private lemma lintegral_Lp_add_le_aux {p q : ℝ}
(hpq : p.is_conjugate_exponent q) {f g : α → ℝ≥0∞} (hf : ae_measurable f μ)
(hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) (hg : ae_measurable g μ) (hg_top : ∫⁻ a, (g a) ^ p ∂μ ≠ ⊤)
(h_add_zero : ∫⁻ a, ((f+g) a) ^ p ∂ μ ≠ 0) (h_add_top : ∫⁻ a, ((f+g) a) ^ p ∂ μ ≠ ⊤) :
(∫⁻ a, ((f + g) a)^p ∂ μ) ^ (1/p) ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p) :=
begin
have hp_not_nonpos : ¬ p ≤ 0, by simp [hpq.pos],
have htop_rpow : (∫⁻ a, ((f+g) a) ^ p ∂μ)^(1/p) ≠ ⊤,
{ by_contra h,
exact h_add_top (@ennreal.rpow_eq_top_of_nonneg _ (1/p) (by simp [hpq.nonneg]) h), },
have h0_rpow : (∫⁻ a, ((f+g) a) ^ p ∂ μ) ^ (1/p) ≠ 0,
by simp [h_add_zero, h_add_top, hpq.nonneg, hp_not_nonpos, -pi.add_apply],
suffices h : 1 ≤ (∫⁻ (a : α), ((f+g) a)^p ∂μ) ^ -(1/p)
* ((∫⁻ (a : α), (f a)^p ∂μ) ^ (1/p) + (∫⁻ (a : α), (g a)^p ∂μ) ^ (1/p)),
by rwa [←mul_le_mul_left h0_rpow htop_rpow, ←mul_assoc, ←rpow_add _ _ h_add_zero h_add_top,
←sub_eq_add_neg, _root_.sub_self, rpow_zero, one_mul, mul_one] at h,
have h : ∫⁻ (a : α), ((f+g) a)^p ∂μ
≤ ((∫⁻ (a : α), (f a)^p ∂μ) ^ (1/p) + (∫⁻ (a : α), (g a)^p ∂μ) ^ (1/p))
* (∫⁻ (a : α), ((f+g) a)^p ∂μ) ^ (1/q),
from lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add hpq hf hf_top hg hg_top,
have h_one_div_q : 1/q = 1 - 1/p, by { nth_rewrite 1 ←hpq.inv_add_inv_conj, ring, },
simp_rw [h_one_div_q, sub_eq_add_neg 1 (1/p), ennreal.rpow_add _ _ h_add_zero h_add_top,
rpow_one] at h,
nth_rewrite 1 mul_comm at h,
nth_rewrite 0 ←one_mul (∫⁻ (a : α), ((f+g) a) ^ p ∂μ) at h,
rwa [←mul_assoc, ennreal.mul_le_mul_right h_add_zero h_add_top, mul_comm] at h,
end
/-- Minkowski's inequality for functions `α → ℝ≥0∞`: the `ℒp` seminorm of the sum of two
functions is bounded by the sum of their `ℒp` seminorms. -/
theorem lintegral_Lp_add_le {p : ℝ} {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) (hp1 : 1 ≤ p) :
(∫⁻ a, ((f + g) a)^p ∂ μ) ^ (1/p) ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p) :=
begin
have hp_pos : 0 < p, from lt_of_lt_of_le zero_lt_one hp1,
by_cases hf_top : ∫⁻ a, (f a) ^ p ∂μ = ⊤,
{ simp [hf_top, hp_pos], },
by_cases hg_top : ∫⁻ a, (g a) ^ p ∂μ = ⊤,
{ simp [hg_top, hp_pos], },
by_cases h1 : p = 1,
{ refine le_of_eq _,
simp_rw [h1, one_div_one, ennreal.rpow_one],
exact lintegral_add_left' hf _, },
have hp1_lt : 1 < p, by { refine lt_of_le_of_ne hp1 _, symmetry, exact h1, },
have hpq := real.is_conjugate_exponent_conjugate_exponent hp1_lt,
by_cases h0 : ∫⁻ a, ((f+g) a) ^ p ∂ μ = 0,
{ rw [h0, @ennreal.zero_rpow_of_pos (1/p) (by simp [lt_of_lt_of_le zero_lt_one hp1])],
exact zero_le _, },
have htop : ∫⁻ a, ((f+g) a) ^ p ∂ μ ≠ ⊤,
{ rw ← ne.def at hf_top hg_top,
rw ← lt_top_iff_ne_top at hf_top hg_top ⊢,
exact lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top hf hf_top hg_top hp1, },
exact lintegral_Lp_add_le_aux hpq hf hf_top hg hg_top h0 htop,
end
/-- Variant of Minkowski's inequality for functions `α → ℝ≥0∞` in `ℒp` with `p ≤ 1`: the `ℒp`
seminorm of the sum of two functions is bounded by a constant multiple of the sum
of their `ℒp` seminorms. -/
theorem lintegral_Lp_add_le_of_le_one {p : ℝ} {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) :
(∫⁻ a, ((f + g) a)^p ∂ μ) ^ (1/p) ≤
2^(1/p-1) * ((∫⁻ a, (f a)^p ∂μ) ^ (1/p) + (∫⁻ a, (g a)^p ∂μ) ^ (1/p)) :=
begin
rcases eq_or_lt_of_le hp0 with rfl|hp,
{ simp only [pi.add_apply, rpow_zero, lintegral_one, _root_.div_zero, zero_sub],
norm_num,
rw [rpow_neg, rpow_one, ennreal.inv_mul_cancel two_ne_zero two_ne_top],
exact le_rfl },
calc (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤ (∫⁻ a, (f a)^p ∂ μ + ∫⁻ a, (g a)^p ∂ μ) ^ (1/p) :
begin
apply rpow_le_rpow _ (div_nonneg zero_le_one hp0),
rw ← lintegral_add_left' (hf.pow_const p),
exact lintegral_mono (λ a, rpow_add_le_add_rpow _ _ hp0 hp1)
end
... ≤ 2 ^ (1/p-1) * ((∫⁻ a, f a ^ p ∂μ) ^ (1/p) + (∫⁻ a, g a ^ p ∂μ) ^ (1/p)) :
rpow_add_le_mul_rpow_add_rpow _ _ ((one_le_div hp).2 hp1)
end
end ennreal
/-- Hölder's inequality for functions `α → ℝ≥0`. The integral of the product of two functions
is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem nnreal.lintegral_mul_le_Lp_mul_Lq {p q : ℝ} (hpq : p.is_conjugate_exponent q)
{f g : α → ℝ≥0} (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ)^(1/p) * (∫⁻ a, (g a)^q ∂μ)^(1/q) :=
begin
simp_rw [pi.mul_apply, ennreal.coe_mul],
exact ennreal.lintegral_mul_le_Lp_mul_Lq μ hpq hf.coe_nnreal_ennreal hg.coe_nnreal_ennreal,
end
end lintegral
|
884a5f0c10a95fdb0a16ceaf822a3684376065ae
|
b9a81ebb9de684db509231c4469a7d2c88915808
|
/test/super_tests.lean
|
ac7c3793d14a7b22b781875a5e50549acf3730eb
|
[] |
no_license
|
leanprover/super
|
3dd81ce8d9ac3cba20bce55e84833fadb2f5716e
|
47b107b4cec8f3b41d72daba9cbda2f9d54025de
|
refs/heads/master
| 1,678,482,996,979
| 1,676,526,367,000
| 1,676,526,367,000
| 92,215,900
| 12
| 6
| null | 1,513,327,539,000
| 1,495,570,640,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,992
|
lean
|
import super
section
open super tactic
example (i : Type) (a b : i) (p : i → Prop) (H : a = b) (Hpa : p a) : true := by do
H ← get_local `H >>= clause.of_classical_proof,
Hpa ← get_local `Hpa >>= clause.of_classical_proof,
a ← get_local `a,
try_sup (λx y, ff) H Hpa 0 0 [0] tt ff ``super.sup_ltr >>= clause.validate,
to_expr ``(trivial) >>= apply
example (i : Type) (a b : i) (p : i → Prop) (H : a = b) (Hpa : p a → false) (Hpb : p b → false) : true := by do
H ← get_local `H >>= clause.of_classical_proof,
Hpa ← get_local `Hpa >>= clause.of_classical_proof,
Hpb ← get_local `Hpb >>= clause.of_classical_proof,
try_sup (λx y, ff) H Hpa 0 0 [0] tt ff ``super.sup_ltr >>= clause.validate,
try_sup (λx y, ff) H Hpb 0 0 [0] ff ff ``super.sup_rtl >>= clause.validate,
to_expr ``(trivial) >>= apply
example (i : Type) (p q : i → Prop) (H : ∀x y, p x → q y → false) : true := by do
h ← get_local `H >>= clause.of_classical_proof,
(op, lcs) ← h^.open_constn h^.num_binders,
guard $ (get_components lcs)^.length = 2,
triv
example (i : Type) (p : i → i → Prop) (H : ∀x y z, p x y → p y z → false) : true := by do
h ← get_local `H >>= clause.of_classical_proof,
(op, lcs) ← h^.open_constn h^.num_binders,
guard $ (get_components lcs)^.length = 1,
triv
example (i : Type) (p : i → i → Type) (c : i) (h : ∀ (x : i), p x c → p x c) : true := by do
h ← get_local `h, hcls ← clause.of_classical_proof h,
taut ← is_taut hcls,
when (¬taut) failed,
to_expr ``(trivial) >>= apply
open tactic
example (m n : ℕ) : true := by do
e₁ ← to_expr ```((0 + (m : ℕ)) + 0),
e₂ ← to_expr ```(0 + (0 + (m : ℕ))),
e₃ ← to_expr ```(0 + (m : ℕ)),
prec ← return (contained_funsyms e₁)^.keys,
prec_gt ← return $ prec_gt_of_name_list prec,
guard $ lpo prec_gt e₁ e₃,
guard $ lpo prec_gt e₂ e₃,
to_expr ``(trivial) >>= apply
/-
open tactic
example (i : Type) (f : i → i) (c d x : i) : true := by do
ef ← get_local `f, ec ← get_local `c, ed ← get_local `d,
syms ← return [ef,ec,ed],
prec_gt ← return $ prec_gt_of_name_list (list.map local_uniq_name [ef, ec, ed]),
sequence' (do s1 ← syms, s2 ← syms, return (do
s1_fmt ← pp s1, s2_fmt ← pp s2,
trace (s1_fmt ++ to_fmt " > " ++ s2_fmt ++ to_fmt ": " ++ to_fmt (prec_gt s1 s2))
)),
exprs ← @mapM tactic _ _ _ to_expr [`(f c), `(f (f c)), `(f d), `(f x), `(f (f x))],
sequence' (do e1 ← exprs, e2 ← exprs, return (do
e1_fmt ← pp e1, e2_fmt ← pp e2,
trace (e1_fmt ++ to_fmt" > " ++ e2_fmt ++ to_fmt": " ++ to_fmt (lpo prec_gt e1 e2))
)),
mk_const ``true.intro >>= apply
-/
open monad
example (x y : ℕ) (h : nat.zero = nat.succ nat.zero) (h2 : nat.succ x = nat.succ y) : true := by do
h ← get_local `h >>= clause.of_classical_proof,
h2 ← get_local `h2 >>= clause.of_classical_proof,
cs ← try_no_confusion_eq_r h 0,
cs.mmap' clause.validate,
cs ← try_no_confusion_eq_r h2 0,
cs.mmap' clause.validate,
to_expr ``(trivial) >>= exact
end
|
57870857fadba4cc469369868a4643938616e279
|
efce24474b28579aba3272fdb77177dc2b11d7aa
|
/src/homotopy_theory/formal/i_category/cofibration_category.lean
|
061f7e533e4bc6da67a6e04a92d043cdcbb322ad
|
[
"Apache-2.0"
] |
permissive
|
rwbarton/lean-homotopy-theory
|
cff499f24268d60e1c546e7c86c33f58c62888ed
|
39e1b4ea1ed1b0eca2f68bc64162dde6a6396dee
|
refs/heads/lean-3.4.2
| 1,622,711,883,224
| 1,598,550,958,000
| 1,598,550,958,000
| 136,023,667
| 12
| 6
|
Apache-2.0
| 1,573,187,573,000
| 1,528,116,262,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 7,600
|
lean
|
import tactic.slice
import category_theory.colimit_lemmas
import category_theory.pushout_fold
import homotopy_theory.formal.cofibrations.cofibration_category
import homotopy_theory.formal.cofibrations.cylinder
import homotopy_theory.formal.cofibrations.factorization_from_cylinder
import homotopy_theory.formal.cofibrations.homotopy
import homotopy_theory.formal.cofibrations.left_proper
import .cylinder_object
import .dold
universes v u
open category_theory
open category_theory.category
local notation f ` ∘ `:80 g:80 := g ≫ f
namespace homotopy_theory.cofibrations
open homotopy_theory.cylinder (renaming homotopic_rel → homotopic_rel_cylinder)
open homotopy_theory.weak_equivalences
open precofibration_category
-- An I-category gives rise to a cofibration category with the same
-- cofibrations in which the weak equivalences are the homotopy
-- equivalences.
variables {C : Type u} [category.{v} C]
[has_initial_object.{v} C] [has_coproducts.{v} C] [I_category.{v} C]
-- Every object is fibrant.
lemma all_objects_fibrant (x : C) : fibrant x :=
assume y j ⟨jc, jw⟩,
let ⟨⟨r, h, H⟩⟩ := (heq_iff_sdr_inclusion jc).mp jw in ⟨r, h⟩
instance I_category.cofibration_category : cofibration_category.{v} C :=
cofibration_category.mk_from_cylinder
(assume a b a' b' f g f' g' po ⟨fc, fw⟩,
⟨precofibration_category.pushout_is_cof po fc, pushout_is_acof po fc fw⟩)
(assume a, ⟨I.obj a, ii @> a, p @> a, cof_ii a, heq_p, pii⟩)
(assume x, ⟨x, 𝟙 x, ⟨cof_id x, weq_id x⟩, all_objects_fibrant x⟩)
-- The functor I produces cylinder objects in the general sense of
-- cofibration categories.
def canonical_cylinder (b : C) :
relative_cylinder (all_objects_cofibrant.cofibrant.{v} b) :=
⟨I.obj b,
(pushout_by_cof (!b) (!b) _).is_pushout.induced (i 0 @> b) (i 1 @> b)
(category_theory.initial.uniqueness _ _),
p @> b,
-- We proved ii : b ⊔ b → Ib is a cofibration; need to massage this
-- into a map from the pushout over the initial object.
let po := pushout_by_cof (!b) (!b) (all_objects_cofibrant.cofibrant.{v} b),
-- The map we need to show is a cofibration
ii' := po.is_pushout.induced (i 0 @> b) (i 1 @> b)
(category_theory.initial.uniqueness _ _),
c : Is_coproduct po.map₀ po.map₁ :=
Is_coproduct_of_Is_pushout_of_Is_initial po.is_pushout
has_initial_object.initial_object.is_initial_object,
j : iso (b ⊔ b) po.ob := isomorphic_coprod_of_Is_coproduct c in
have ii' ∘ j.hom = ii @> b, begin
dsimp [j, isomorphic_coprod_of_Is_coproduct];
apply coprod.uniqueness; rw ←assoc; simp [ii]
end,
have ii' = ii @> b ∘ j.inv, by rw ←this; simp,
show is_cof ii',
by rw this; exact cof_comp (cof_iso j.symm) (cof_ii b),
heq_p,
begin
apply (pushout_by_cof (!b) (!b) _).is_pushout.uniqueness;
{ rw ←assoc, simp }
end⟩
/-
I a → a
↓ po ↓
b ⊔ b → I b → c → b
a
-/
def canonical_relative_cylinder {a b : C} {j : a ⟶ b} (hj : is_cof j) :
relative_cylinder hj :=
let po := pushout_by_cof (I.map j) (p.app a) (I_preserves_cofibrations hj) in
⟨po.ob,
(pushout_by_cof j j _).is_pushout.induced ((i 0).app b ≫ po.map₀) ((i 1).app b ≫ po.map₀)
begin
erw [←assoc, ←assoc, (i 0).naturality, (i 1).naturality],
rw [assoc, assoc, po.is_pushout.commutes, ←assoc, ←assoc],
simp
end,
po.is_pushout.induced (p.app b) j (p.naturality j),
/-
a ⊔ a → I a → a
↓ po₁ ↓ po₂ ↓
b ⊔ b → ⬝ → b ⊔ b
a
↓ po₃ ↓
I b → c → b
-/
begin
let po₀ := pushout_by_cof j j hj,
let abb : a ⟶ po₀.ob := po₀.map₀ ∘ j,
let po₁ := pushout_by_cof _ (ii.app a) (cof_coprod hj hj),
let l := po₁.is_pushout.induced (coprod.induced po₀.map₀ po₀.map₁) (abb ∘ p.app a)
begin
apply coprod.uniqueness,
{ rw [←assoc, coprod_of_maps_commutes₀, assoc, coprod.induced_commutes₀],
rw [iii₀_assoc, ←assoc, pi_components, id_comp] },
{ rw [←assoc, coprod_of_maps_commutes₁, assoc, coprod.induced_commutes₁],
rw [iii₁_assoc, ←assoc, pi_components, id_comp, ←po₀.is_pushout.commutes] }
end,
have po₁₂ : Is_pushout (coprod_of_maps j j) (coprod.fold a) _ _ :=
Is_pushout_fold po₀.is_pushout,
have po₂ : Is_pushout po₁.map₁ (p.app a) l abb,
{ refine Is_pushout_of_Is_pushout_of_Is_pushout' po₁.is_pushout _ _,
{ convert po₁₂,
{ apply pii },
{ simp } },
{ simp } },
have po₂₃ : Is_pushout (I.map j) (p.app a) _ _ := po.is_pushout,
let m := _, -- naming part of the type of a hypothesis
have : is_cof m := I_category.relative_cylinder j hj,
let n := _, -- naming part of the type of the goal
change is_cof n,
have po₃ : Is_pushout m l po.map₀ n,
{ refine Is_pushout_of_Is_pushout_of_Is_pushout_vert' po₂ _ _,
convert po₂₃,
{ simp, refl },
{ have : po.map₀ ∘ (i 0).app b ∘ j = po.map₁,
{ rw ←assoc,
erw (i 0).naturality,
rw [assoc, po.is_pushout.commutes, ←assoc, pi_components, id_comp] },
simpa using this },
{ apply po₁.is_pushout.uniqueness; rw [←assoc, ←assoc],
{ simp only [Is_pushout.induced_commutes₀, Is_pushout.induced_commutes₁],
apply coprod.uniqueness; rw [←assoc, ←assoc]; simp },
{ simp only [assoc, Is_pushout.induced_commutes₀, Is_pushout.induced_commutes₁],
slice_rhs 2 3 { change (i 0).app b ∘ ((functor.id _).map j), rw (i 0).naturality },
simp only [assoc],
erw [po.is_pushout.commutes],
slice_rhs 2 3 { rw pi_components },
dsimp, simp } } },
exact pushout_is_cof po₃ this
end,
begin
have : is_weq po.map₀ :=
left_proper.pushout_weq_by_cof po.is_pushout (I_preserves_cofibrations hj) heq_p,
refine category_with_weak_equivalences.weq_of_comp_weq_left this _,
simpa using heq_p,
end,
begin
symmetry,
apply pushout_induced_eq_iff; rw ←assoc; simp
end⟩
section homotopy
variables {a b x : C} {j : a ⟶ b} (hj : is_cof j) (f₀ f₁ : b ⟶ x)
lemma homotopic_rel_iff_cylinder :
homotopic_rel hj f₀ f₁ ↔ homotopic_rel_cylinder j f₀ f₁ :=
let po := pushout_by_cof (I.map j) (p.app a) (I_preserves_cofibrations hj) in
begin
split; intro H,
{ rcases homotopic_rel' (canonical_relative_cylinder hj) (all_objects_fibrant x) f₀ f₁ H
with ⟨H, Hi₀, Hi₁⟩,
dsimp [canonical_relative_cylinder, relative_cylinder.i₀, relative_cylinder.i₁] at Hi₀ Hi₁,
simp at Hi₀ Hi₁,
refine ⟨⟨po.map₀ ≫ H, _, _⟩, _⟩,
{ rw [←Hi₀, ←assoc, ←assoc], refl },
{ rw [←Hi₁, ←assoc, ←assoc], refl },
{ dsimp [homotopy.is_rel],
rw [←Hi₀],
slice_rhs 2 3 { change (functor.id _).map j ≫ (i 0).app b, rw (i 0).naturality },
slice_lhs 1 2 { rw po.is_pushout.commutes },
slice_rhs 3 4 { change I.map j ≫ po.map₀, rw po.is_pushout.commutes },
slice_rhs 2 3 { rw pi_components },
simp } },
{ rcases H with ⟨⟨H, Hi₀, Hi₁⟩, r⟩,
refine ⟨canonical_relative_cylinder hj, ⟨⟨_, _, _⟩⟩⟩,
refine po.is_pushout.induced H (j ≫ f₀) r,
{ convert Hi₀ using 1,
dsimp [relative_cylinder.i₀, canonical_relative_cylinder], simp },
{ convert Hi₁ using 1,
dsimp [relative_cylinder.i₁, canonical_relative_cylinder], simp } }
end
end homotopy
end homotopy_theory.cofibrations
|
e69166716ea4b448806915cecf50f1f5292de2f5
|
8e6cad62ec62c6c348e5faaa3c3f2079012bdd69
|
/src/data/complex/basic.lean
|
2cbb0bddfd9086037fc107917c7bc80d540884de
|
[
"Apache-2.0"
] |
permissive
|
benjamindavidson/mathlib
|
8cc81c865aa8e7cf4462245f58d35ae9a56b150d
|
fad44b9f670670d87c8e25ff9cdf63af87ad731e
|
refs/heads/master
| 1,679,545,578,362
| 1,615,343,014,000
| 1,615,343,014,000
| 312,926,983
| 0
| 0
|
Apache-2.0
| 1,615,360,301,000
| 1,605,399,418,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 26,676
|
lean
|
/-
Copyright (c) 2017 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Mario Carneiro
-/
import data.real.sqrt
/-!
# The complex numbers
The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field
of characteristic zero. The result that the complex numbers are algebraically closed, see
`field_theory.algebraic_closure`.
-/
open_locale big_operators
/-! ### Definition and basic arithmmetic -/
/-- Complex numbers consist of two `real`s: a real part `re` and an imaginary part `im`. -/
structure complex : Type :=
(re : ℝ) (im : ℝ)
notation `ℂ` := complex
namespace complex
noncomputable instance : decidable_eq ℂ := classical.dec_eq _
/-- The equivalence between the complex numbers and `ℝ × ℝ`. -/
def equiv_real_prod : ℂ ≃ (ℝ × ℝ) :=
{ to_fun := λ z, ⟨z.re, z.im⟩,
inv_fun := λ p, ⟨p.1, p.2⟩,
left_inv := λ ⟨x, y⟩, rfl,
right_inv := λ ⟨x, y⟩, rfl }
@[simp] theorem equiv_real_prod_apply (z : ℂ) : equiv_real_prod z = (z.re, z.im) := rfl
theorem equiv_real_prod_symm_re (x y : ℝ) : (equiv_real_prod.symm (x, y)).re = x := rfl
theorem equiv_real_prod_symm_im (x y : ℝ) : (equiv_real_prod.symm (x, y)).im = y := rfl
@[simp] theorem eta : ∀ z : ℂ, complex.mk z.re z.im = z
| ⟨a, b⟩ := rfl
@[ext]
theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w
| ⟨zr, zi⟩ ⟨_, _⟩ rfl rfl := rfl
theorem ext_iff {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=
⟨λ H, by simp [H], and.rec ext⟩
instance : has_coe ℝ ℂ := ⟨λ r, ⟨r, 0⟩⟩
@[simp, norm_cast] lemma of_real_re (r : ℝ) : (r : ℂ).re = r := rfl
@[simp, norm_cast] lemma of_real_im (r : ℝ) : (r : ℂ).im = 0 := rfl
lemma of_real_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl
@[simp, norm_cast] theorem of_real_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w :=
⟨congr_arg re, congr_arg _⟩
instance : has_zero ℂ := ⟨(0 : ℝ)⟩
instance : inhabited ℂ := ⟨0⟩
@[simp] lemma zero_re : (0 : ℂ).re = 0 := rfl
@[simp] lemma zero_im : (0 : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma of_real_zero : ((0 : ℝ) : ℂ) = 0 := rfl
@[simp] theorem of_real_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := of_real_inj
theorem of_real_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr of_real_eq_zero
instance : has_one ℂ := ⟨(1 : ℝ)⟩
@[simp] lemma one_re : (1 : ℂ).re = 1 := rfl
@[simp] lemma one_im : (1 : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma of_real_one : ((1 : ℝ) : ℂ) = 1 := rfl
instance : has_add ℂ := ⟨λ z w, ⟨z.re + w.re, z.im + w.im⟩⟩
@[simp] lemma add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl
@[simp] lemma add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl
@[simp] lemma bit0_re (z : ℂ) : (bit0 z).re = bit0 z.re := rfl
@[simp] lemma bit1_re (z : ℂ) : (bit1 z).re = bit1 z.re := rfl
@[simp] lemma bit0_im (z : ℂ) : (bit0 z).im = bit0 z.im := eq.refl _
@[simp] lemma bit1_im (z : ℂ) : (bit1 z).im = bit0 z.im := add_zero _
@[simp, norm_cast] lemma of_real_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s :=
ext_iff.2 $ by simp
@[simp, norm_cast] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r :=
ext_iff.2 $ by simp [bit0]
@[simp, norm_cast] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r :=
ext_iff.2 $ by simp [bit1]
instance : has_neg ℂ := ⟨λ z, ⟨-z.re, -z.im⟩⟩
@[simp] lemma neg_re (z : ℂ) : (-z).re = -z.re := rfl
@[simp] lemma neg_im (z : ℂ) : (-z).im = -z.im := rfl
@[simp, norm_cast] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := ext_iff.2 $ by simp
instance : has_sub ℂ := ⟨λ z w, ⟨z.re - w.re, z.im - w.im⟩⟩
instance : has_mul ℂ := ⟨λ z w, ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩
@[simp] lemma mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl
@[simp] lemma mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl
@[simp, norm_cast] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := ext_iff.2 $ by simp
lemma smul_re (r : ℝ) (z : ℂ) : (↑r * z).re = r * z.re := by simp
lemma smul_im (r : ℝ) (z : ℂ) : (↑r * z).im = r * z.im := by simp
lemma of_real_smul (r : ℝ) (z : ℂ) : (↑r * z) = ⟨r * z.re, r * z.im⟩ :=
ext (smul_re _ _) (smul_im _ _)
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
def I : ℂ := ⟨0, 1⟩
@[simp] lemma I_re : I.re = 0 := rfl
@[simp] lemma I_im : I.im = 1 := rfl
@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp
lemma I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ :=
ext_iff.2 $ by simp
lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm
lemma mk_eq_add_mul_I (a b : ℝ) : complex.mk a b = a + b * I :=
ext_iff.2 $ by simp
@[simp] lemma re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z :=
ext_iff.2 $ by simp
/-! ### Commutative ring instance and lemmas -/
instance : comm_ring ℂ :=
by refine { zero := 0, add := (+), neg := has_neg.neg, sub := has_sub.sub, one := 1, mul := (*),
sub_eq_add_neg := _, ..};
{ intros, apply ext_iff.2; split; simp; ring }
instance re.is_add_group_hom : is_add_group_hom complex.re :=
{ map_add := complex.add_re }
instance im.is_add_group_hom : is_add_group_hom complex.im :=
{ map_add := complex.add_im }
@[simp] lemma I_pow_bit0 (n : ℕ) : I ^ (bit0 n) = (-1) ^ n :=
by rw [pow_bit0', I_mul_I]
@[simp] lemma I_pow_bit1 (n : ℕ) : I ^ (bit1 n) = (-1) ^ n * I :=
by rw [pow_bit1', I_mul_I]
/-! ### Complex conjugation -/
/-- The complex conjugate. -/
def conj : ℂ →+* ℂ :=
begin
refine_struct { to_fun := λ z : ℂ, (⟨z.re, -z.im⟩ : ℂ), .. };
{ intros, ext; simp [add_comm], },
end
@[simp] lemma conj_re (z : ℂ) : (conj z).re = z.re := rfl
@[simp] lemma conj_im (z : ℂ) : (conj z).im = -z.im := rfl
@[simp] lemma conj_of_real (r : ℝ) : conj r = r := ext_iff.2 $ by simp [conj]
@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp
@[simp] lemma conj_bit0 (z : ℂ) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]
@[simp] lemma conj_bit1 (z : ℂ) : conj (bit1 z) = bit1 (conj z) := ext_iff.2 $ by simp [bit0]
@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp
@[simp] lemma conj_conj (z : ℂ) : conj (conj z) = z :=
ext_iff.2 $ by simp
lemma conj_involutive : function.involutive conj := conj_conj
lemma conj_bijective : function.bijective conj := conj_involutive.bijective
lemma conj_inj {z w : ℂ} : conj z = conj w ↔ z = w :=
conj_bijective.1.eq_iff
@[simp] lemma conj_eq_zero {z : ℂ} : conj z = 0 ↔ z = 0 :=
by simpa using @conj_inj z 0
lemma eq_conj_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=
⟨λ h, ⟨z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)⟩,
λ ⟨h, e⟩, by rw [e, conj_of_real]⟩
lemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=
eq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩
instance : star_ring ℂ :=
{ star := λ z, conj z,
star_involutive := λ z, by simp,
star_mul := λ r s, by { ext; simp [mul_comm], },
star_add := by simp, }
/-! ### Norm squared -/
/-- The norm squared function. -/
@[pp_nodot] def norm_sq : monoid_with_zero_hom ℂ ℝ :=
{ to_fun := λ z, z.re * z.re + z.im * z.im,
map_zero' := by simp,
map_one' := by simp,
map_mul' := λ z w, by { dsimp, ring } }
lemma norm_sq_apply (z : ℂ) : norm_sq z = z.re * z.re + z.im * z.im := rfl
@[simp] lemma norm_sq_of_real (r : ℝ) : norm_sq r = r * r :=
by simp [norm_sq]
lemma norm_sq_eq_conj_mul_self {z : ℂ} : (norm_sq z : ℂ) = conj z * z :=
by { ext; simp [norm_sq, mul_comm], }
@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := norm_sq.map_zero
@[simp] lemma norm_sq_one : norm_sq 1 = 1 := norm_sq.map_one
@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]
lemma norm_sq_nonneg (z : ℂ) : 0 ≤ norm_sq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
lemma norm_sq_eq_zero {z : ℂ} : norm_sq z = 0 ↔ z = 0 :=
⟨λ h, ext
(eq_zero_of_mul_self_add_mul_self_eq_zero h)
(eq_zero_of_mul_self_add_mul_self_eq_zero $ (add_comm _ _).trans h),
λ h, h.symm ▸ norm_sq_zero⟩
@[simp] lemma norm_sq_pos {z : ℂ} : 0 < norm_sq z ↔ z ≠ 0 :=
(norm_sq_nonneg z).lt_iff_ne.trans $ not_congr (eq_comm.trans norm_sq_eq_zero)
@[simp] lemma norm_sq_neg (z : ℂ) : norm_sq (-z) = norm_sq z :=
by simp [norm_sq]
@[simp] lemma norm_sq_conj (z : ℂ) : norm_sq (conj z) = norm_sq z :=
by simp [norm_sq]
lemma norm_sq_mul (z w : ℂ) : norm_sq (z * w) = norm_sq z * norm_sq w :=
norm_sq.map_mul z w
lemma norm_sq_add (z w : ℂ) : norm_sq (z + w) =
norm_sq z + norm_sq w + 2 * (z * conj w).re :=
by dsimp [norm_sq]; ring
lemma re_sq_le_norm_sq (z : ℂ) : z.re * z.re ≤ norm_sq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
lemma im_sq_le_norm_sq (z : ℂ) : z.im * z.im ≤ norm_sq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : ℂ) : z * conj z = norm_sq z :=
ext_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]
theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=
ext_iff.2 $ by simp [two_mul]
/-- The coercion `ℝ → ℂ` as a `ring_hom`. -/
def of_real : ℝ →+* ℂ := ⟨coe, of_real_one, of_real_mul, of_real_zero, of_real_add⟩
@[simp] lemma of_real_eq_coe (r : ℝ) : of_real r = r := rfl
@[simp] lemma I_sq : I ^ 2 = -1 := by rw [pow_two, I_mul_I]
@[simp] lemma sub_re (z w : ℂ) : (z - w).re = z.re - w.re := rfl
@[simp] lemma sub_im (z w : ℂ) : (z - w).im = z.im - w.im := rfl
@[simp, norm_cast] lemma of_real_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s := ext_iff.2 $ by simp
@[simp, norm_cast] lemma of_real_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : ℂ) = r ^ n :=
by induction n; simp [*, of_real_mul, pow_succ]
theorem sub_conj (z : ℂ) : z - conj z = (2 * z.im : ℝ) * I :=
ext_iff.2 $ by simp [two_mul, sub_eq_add_neg]
lemma norm_sq_sub (z w : ℂ) : norm_sq (z - w) =
norm_sq z + norm_sq w - 2 * (z * conj w).re :=
by rw [sub_eq_add_neg, norm_sq_add]; simp [-mul_re, add_comm, add_left_comm, sub_eq_add_neg]
/-! ### Inversion -/
noncomputable instance : has_inv ℂ := ⟨λ z, conj z * ((norm_sq z)⁻¹:ℝ)⟩
theorem inv_def (z : ℂ) : z⁻¹ = conj z * ((norm_sq z)⁻¹:ℝ) := rfl
@[simp] lemma inv_re (z : ℂ) : (z⁻¹).re = z.re / norm_sq z := by simp [inv_def, division_def]
@[simp] lemma inv_im (z : ℂ) : (z⁻¹).im = -z.im / norm_sq z := by simp [inv_def, division_def]
@[simp, norm_cast] lemma of_real_inv (r : ℝ) : ((r⁻¹ : ℝ) : ℂ) = r⁻¹ :=
ext_iff.2 $ by simp
protected lemma inv_zero : (0⁻¹ : ℂ) = 0 :=
by rw [← of_real_zero, ← of_real_inv, inv_zero]
protected theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 :=
by rw [inv_def, ← mul_assoc, mul_conj, ← of_real_mul,
mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]
/-! ### Field instance and lemmas -/
noncomputable instance : field ℂ :=
{ inv := has_inv.inv,
exists_pair_ne := ⟨0, 1, mt (congr_arg re) zero_ne_one⟩,
mul_inv_cancel := @complex.mul_inv_cancel,
inv_zero := complex.inv_zero,
..complex.comm_ring }
@[simp] lemma I_fpow_bit0 (n : ℤ) : I ^ (bit0 n) = (-1) ^ n :=
by rw [fpow_bit0', I_mul_I]
@[simp] lemma I_fpow_bit1 (n : ℤ) : I ^ (bit1 n) = (-1) ^ n * I :=
by rw [fpow_bit1', I_mul_I]
lemma div_re (z w : ℂ) : (z / w).re = z.re * w.re / norm_sq w + z.im * w.im / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]
lemma div_im (z w : ℂ) : (z / w).im = z.im * w.re / norm_sq w - z.re * w.im / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]
@[simp, norm_cast] lemma of_real_div (r s : ℝ) : ((r / s : ℝ) : ℂ) = r / s :=
of_real.map_div r s
@[simp, norm_cast] lemma of_real_fpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n :=
of_real.map_fpow r n
@[simp] lemma div_I (z : ℂ) : z / I = -(z * I) :=
(div_eq_iff_mul_eq I_ne_zero).2 $ by simp [mul_assoc]
@[simp] lemma inv_I : I⁻¹ = -I :=
by simp [inv_eq_one_div]
@[simp] lemma norm_sq_inv (z : ℂ) : norm_sq z⁻¹ = (norm_sq z)⁻¹ :=
norm_sq.map_inv' z
@[simp] lemma norm_sq_div (z w : ℂ) : norm_sq (z / w) = norm_sq z / norm_sq w :=
norm_sq.map_div z w
/-! ### Cast lemmas -/
@[simp, norm_cast] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : ℂ) = n :=
of_real.map_nat_cast n
@[simp, norm_cast] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n :=
by rw [← of_real_nat_cast, of_real_re]
@[simp, norm_cast] lemma nat_cast_im (n : ℕ) : (n : ℂ).im = 0 :=
by rw [← of_real_nat_cast, of_real_im]
@[simp, norm_cast] theorem of_real_int_cast (n : ℤ) : ((n : ℝ) : ℂ) = n :=
of_real.map_int_cast n
@[simp, norm_cast] lemma int_cast_re (n : ℤ) : (n : ℂ).re = n :=
by rw [← of_real_int_cast, of_real_re]
@[simp, norm_cast] lemma int_cast_im (n : ℤ) : (n : ℂ).im = 0 :=
by rw [← of_real_int_cast, of_real_im]
@[simp, norm_cast] theorem of_real_rat_cast (n : ℚ) : ((n : ℝ) : ℂ) = n :=
of_real.map_rat_cast n
@[simp, norm_cast] lemma rat_cast_re (q : ℚ) : (q : ℂ).re = q :=
by rw [← of_real_rat_cast, of_real_re]
@[simp, norm_cast] lemma rat_cast_im (q : ℚ) : (q : ℂ).im = 0 :=
by rw [← of_real_rat_cast, of_real_im]
/-! ### Characteristic zero -/
instance char_zero_complex : char_zero ℂ :=
char_zero_of_inj_zero $ λ n h,
by rwa [← of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h
/-- A complex number `z` plus its conjugate `conj z` is `2` times its real part. -/
theorem re_eq_add_conj (z : ℂ) : (z.re : ℂ) = (z + conj z) / 2 :=
by simp only [add_conj, of_real_mul, of_real_one, of_real_bit0,
mul_div_cancel_left (z.re:ℂ) two_ne_zero']
/-- A complex number `z` minus its conjugate `conj z` is `2i` times its imaginary part. -/
theorem im_eq_sub_conj (z : ℂ) : (z.im : ℂ) = (z - conj(z))/(2 * I) :=
by simp only [sub_conj, of_real_mul, of_real_one, of_real_bit0, mul_right_comm,
mul_div_cancel_left _ (mul_ne_zero two_ne_zero' I_ne_zero : 2 * I ≠ 0)]
/-! ### Absolute value -/
/-- The complex absolute value function, defined as the square root of the norm squared. -/
@[pp_nodot] noncomputable def abs (z : ℂ) : ℝ := (norm_sq z).sqrt
local notation `abs'` := _root_.abs
@[simp, norm_cast] lemma abs_of_real (r : ℝ) : abs r = abs' r :=
by simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]
lemma abs_of_nonneg {r : ℝ} (h : 0 ≤ r) : abs r = r :=
(abs_of_real _).trans (abs_of_nonneg h)
lemma abs_of_nat (n : ℕ) : complex.abs n = n :=
calc complex.abs n = complex.abs (n:ℝ) : by rw [of_real_nat_cast]
... = _ : abs_of_nonneg (nat.cast_nonneg n)
lemma mul_self_abs (z : ℂ) : abs z * abs z = norm_sq z :=
real.mul_self_sqrt (norm_sq_nonneg _)
@[simp] lemma abs_zero : abs 0 = 0 := by simp [abs]
@[simp] lemma abs_one : abs 1 = 1 := by simp [abs]
@[simp] lemma abs_I : abs I = 1 := by simp [abs]
@[simp] lemma abs_two : abs 2 = 2 :=
calc abs 2 = abs (2 : ℝ) : by rw [of_real_bit0, of_real_one]
... = (2 : ℝ) : abs_of_nonneg (by norm_num)
lemma abs_nonneg (z : ℂ) : 0 ≤ abs z :=
real.sqrt_nonneg _
@[simp] lemma abs_eq_zero {z : ℂ} : abs z = 0 ↔ z = 0 :=
(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero
lemma abs_ne_zero {z : ℂ} : abs z ≠ 0 ↔ z ≠ 0 :=
not_congr abs_eq_zero
@[simp] lemma abs_conj (z : ℂ) : abs (conj z) = abs z :=
by simp [abs]
@[simp] lemma abs_mul (z w : ℂ) : abs (z * w) = abs z * abs w :=
by rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl
lemma abs_re_le_abs (z : ℂ) : abs' z.re ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.re) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply re_sq_le_norm_sq
lemma abs_im_le_abs (z : ℂ) : abs' z.im ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg z.im) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply im_sq_le_norm_sq
lemma re_le_abs (z : ℂ) : z.re ≤ abs z :=
(abs_le.1 (abs_re_le_abs _)).2
lemma im_le_abs (z : ℂ) : z.im ≤ abs z :=
(abs_le.1 (abs_im_le_abs _)).2
lemma abs_add (z w : ℂ) : abs (z + w) ≤ abs z + abs w :=
(mul_self_le_mul_self_iff (abs_nonneg _)
(add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $
begin
rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,
add_right_comm, norm_sq_add, add_le_add_iff_left,
mul_assoc, mul_le_mul_left (@zero_lt_two ℝ _ _)],
simpa [-mul_re] using re_le_abs (z * conj w)
end
instance : is_absolute_value abs :=
{ abv_nonneg := abs_nonneg,
abv_eq_zero := λ _, abs_eq_zero,
abv_add := abs_add,
abv_mul := abs_mul }
open is_absolute_value
@[simp] lemma abs_abs (z : ℂ) : abs' (abs z) = abs z :=
_root_.abs_of_nonneg (abs_nonneg _)
@[simp] lemma abs_pos {z : ℂ} : 0 < abs z ↔ z ≠ 0 := abv_pos abs
@[simp] lemma abs_neg : ∀ z, abs (-z) = abs z := abv_neg abs
lemma abs_sub : ∀ z w, abs (z - w) = abs (w - z) := abv_sub abs
lemma abs_sub_le : ∀ a b c, abs (a - c) ≤ abs (a - b) + abs (b - c) := abv_sub_le abs
@[simp] theorem abs_inv : ∀ z, abs z⁻¹ = (abs z)⁻¹ := abv_inv abs
@[simp] theorem abs_div : ∀ z w, abs (z / w) = abs z / abs w := abv_div abs
lemma abs_abs_sub_le_abs_sub : ∀ z w, abs' (abs z - abs w) ≤ abs (z - w) :=
abs_abv_sub_le_abv_sub abs
lemma abs_le_abs_re_add_abs_im (z : ℂ) : abs z ≤ abs' z.re + abs' z.im :=
by simpa [re_add_im] using abs_add z.re (z.im * I)
lemma abs_re_div_abs_le_one (z : ℂ) : abs' (z.re / z.abs) ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }
lemma abs_im_div_abs_le_one (z : ℂ) : abs' (z.im / z.abs) ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by { simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }
@[simp, norm_cast] lemma abs_cast_nat (n : ℕ) : abs (n : ℂ) = n :=
by rw [← of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]
@[simp, norm_cast] lemma int_cast_abs (n : ℤ) : ↑(abs' n) = abs n :=
by rw [← of_real_int_cast, abs_of_real, int.cast_abs]
lemma norm_sq_eq_abs (x : ℂ) : norm_sq x = abs x ^ 2 :=
by rw [abs, pow_two, real.mul_self_sqrt (norm_sq_nonneg _)]
/--
We put a partial order on ℂ so that `z ≤ w` exactly if `w - z` is real and nonnegative.
Complex numbers with different imaginary parts are incomparable.
-/
def complex_order : partial_order ℂ :=
{ le := λ z w, ∃ x : ℝ, 0 ≤ x ∧ w = z + x,
le_refl := λ x, ⟨0, by simp⟩,
le_trans := λ x y z h₁ h₂,
begin
obtain ⟨w₁, l₁, rfl⟩ := h₁,
obtain ⟨w₂, l₂, rfl⟩ := h₂,
refine ⟨w₁ + w₂, _, _⟩,
{ linarith, },
{ simp [add_assoc], },
end,
le_antisymm := λ z w h₁ h₂,
begin
obtain ⟨w₁, l₁, rfl⟩ := h₁,
obtain ⟨w₂, l₂, e⟩ := h₂,
have h₃ : w₁ + w₂ = 0,
{ symmetry,
rw add_assoc at e,
apply of_real_inj.mp,
apply add_left_cancel,
convert e; simp, },
have h₄ : w₁ = 0, linarith,
simp [h₄],
end, }
localized "attribute [instance] complex_order" in complex_order
section complex_order
open_locale complex_order
lemma le_def {z w : ℂ} : z ≤ w ↔ ∃ x : ℝ, 0 ≤ x ∧ w = z + x := iff.refl _
lemma lt_def {z w : ℂ} : z < w ↔ ∃ x : ℝ, 0 < x ∧ w = z + x :=
begin
rw [lt_iff_le_not_le],
fsplit,
{ rintro ⟨⟨x, l, rfl⟩, h⟩,
by_cases hx : x = 0,
{ simp [hx] at h, exfalso, exact h (le_refl _), },
{ replace l : 0 < x := l.lt_of_ne (ne.symm hx),
exact ⟨x, l, rfl⟩, } },
{ rintro ⟨x, l, rfl⟩,
fsplit,
{ exact ⟨x, l.le, rfl⟩, },
{ rintro ⟨x', l', e⟩,
rw [add_assoc] at e,
replace e := add_left_cancel (by { convert e, simp }),
norm_cast at e,
linarith, } }
end
@[simp, norm_cast] lemma real_le_real {x y : ℝ} : (x : ℂ) ≤ (y : ℂ) ↔ x ≤ y :=
begin
rw [le_def],
fsplit,
{ rintro ⟨r, l, e⟩,
norm_cast at e,
subst e,
exact le_add_of_nonneg_right l, },
{ intro h,
exact ⟨y - x, sub_nonneg.mpr h, (by simp)⟩, },
end
@[simp, norm_cast] lemma real_lt_real {x y : ℝ} : (x : ℂ) < (y : ℂ) ↔ x < y :=
begin
rw [lt_def],
fsplit,
{ rintro ⟨r, l, e⟩,
norm_cast at e,
subst e,
exact lt_add_of_pos_right x l, },
{ intro h,
exact ⟨y - x, sub_pos.mpr h, (by simp)⟩, },
end
@[simp, norm_cast] lemma zero_le_real {x : ℝ} : (0 : ℂ) ≤ (x : ℂ) ↔ 0 ≤ x := real_le_real
@[simp, norm_cast] lemma zero_lt_real {x : ℝ} : (0 : ℂ) < (x : ℂ) ↔ 0 < x := real_lt_real
/--
With `z ≤ w` iff `w - z` is real and nonnegative, `ℂ` is an ordered ring.
-/
def complex_ordered_comm_ring : ordered_comm_ring ℂ :=
{ zero_le_one := ⟨1, zero_le_one, by simp⟩,
add_le_add_left := λ w z h y,
begin
obtain ⟨x, l, rfl⟩ := h,
exact ⟨x, l, by simp [add_assoc]⟩,
end,
mul_pos := λ z w hz hw,
begin
obtain ⟨zx, lz, rfl⟩ := lt_def.mp hz,
obtain ⟨wx, lw, rfl⟩ := lt_def.mp hw,
norm_cast,
simp only [mul_pos, lz, lw, zero_add],
end,
le_of_add_le_add_left := λ u v z h,
begin
obtain ⟨x, l, e⟩ := h,
rw add_assoc at e,
exact ⟨x, l, add_left_cancel e⟩,
end,
mul_lt_mul_of_pos_left := λ u v z h₁ h₂,
begin
obtain ⟨x₁, l₁, rfl⟩ := lt_def.mp h₁,
obtain ⟨x₂, l₂, rfl⟩ := lt_def.mp h₂,
simp only [mul_add, zero_add],
exact lt_def.mpr ⟨x₂ * x₁, mul_pos l₂ l₁, (by norm_cast)⟩,
end,
mul_lt_mul_of_pos_right := λ u v z h₁ h₂,
begin
obtain ⟨x₁, l₁, rfl⟩ := lt_def.mp h₁,
obtain ⟨x₂, l₂, rfl⟩ := lt_def.mp h₂,
simp only [add_mul, zero_add],
exact lt_def.mpr ⟨x₁ * x₂, mul_pos l₁ l₂, (by norm_cast)⟩,
end,
-- we need more instances here because comm_ring doesn't have zero_add et al as fields,
-- they are derived as lemmas
..(by apply_instance : partial_order ℂ),
..(by apply_instance : comm_ring ℂ),
..(by apply_instance : comm_semiring ℂ),
..(by apply_instance : add_cancel_monoid ℂ) }
localized "attribute [instance] complex_ordered_comm_ring" in complex_order
/--
With `z ≤ w` iff `w - z` is real and nonnegative, `ℂ` is a star ordered ring.
(That is, an ordered ring in which every element of the form `star z * z` is nonnegative.)
In fact, the nonnegative elements are precisely those of this form.
This hold in any `C^*`-algebra, e.g. `ℂ`,
but we don't yet have `C^*`-algebras in mathlib.
-/
def complex_star_ordered_ring : star_ordered_ring ℂ :=
{ star_mul_self_nonneg := λ z,
begin
refine ⟨z.abs^2, pow_nonneg (abs_nonneg z) 2, _⟩,
simp only [has_star.star, of_real_pow, zero_add],
norm_cast,
rw [←norm_sq_eq_abs, norm_sq_eq_conj_mul_self],
end, }
localized "attribute [instance] complex_star_ordered_ring" in complex_order
end complex_order
/-! ### Cauchy sequences -/
theorem is_cau_seq_re (f : cau_seq ℂ abs) : is_cau_seq abs' (λ n, (f n).re) :=
λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij,
lt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)
theorem is_cau_seq_im (f : cau_seq ℂ abs) : is_cau_seq abs' (λ n, (f n).im) :=
λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij,
lt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)
/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_re (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_re f⟩
/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_im (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_im f⟩
lemma is_cau_seq_abs {f : ℕ → ℂ} (hf : is_cau_seq abs f) :
is_cau_seq abs' (abs ∘ f) :=
λ ε ε0, let ⟨i, hi⟩ := hf ε ε0 in
⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩
/-- The limit of a Cauchy sequence of complex numbers. -/
noncomputable def lim_aux (f : cau_seq ℂ abs) : ℂ :=
⟨cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)⟩
theorem equiv_lim_aux (f : cau_seq ℂ abs) : f ≈ cau_seq.const abs (lim_aux f) :=
λ ε ε0, (exists_forall_ge_and
(cau_seq.equiv_lim ⟨_, is_cau_seq_re f⟩ _ (half_pos ε0))
(cau_seq.equiv_lim ⟨_, is_cau_seq_im f⟩ _ (half_pos ε0))).imp $
λ i H j ij, begin
cases H _ ij with H₁ H₂,
apply lt_of_le_of_lt (abs_le_abs_re_add_abs_im _),
dsimp [lim_aux] at *,
have := add_lt_add H₁ H₂,
rwa add_halves at this,
end
noncomputable instance : cau_seq.is_complete ℂ abs :=
⟨λ f, ⟨lim_aux f, equiv_lim_aux f⟩⟩
open cau_seq
lemma lim_eq_lim_im_add_lim_re (f : cau_seq ℂ abs) : lim f =
↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I :=
lim_eq_of_equiv_const $
calc f ≈ _ : equiv_lim_aux f
... = cau_seq.const abs (↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I) :
cau_seq.ext (λ _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))
lemma lim_re (f : cau_seq ℂ abs) : lim (cau_seq_re f) = (lim f).re :=
by rw [lim_eq_lim_im_add_lim_re]; simp
lemma lim_im (f : cau_seq ℂ abs) : lim (cau_seq_im f) = (lim f).im :=
by rw [lim_eq_lim_im_add_lim_re]; simp
lemma is_cau_seq_conj (f : cau_seq ℂ abs) : is_cau_seq abs (λ n, conj (f n)) :=
λ ε ε0, let ⟨i, hi⟩ := f.2 ε ε0 in
⟨i, λ j hj, by rw [← conj.map_sub, abs_conj]; exact hi j hj⟩
/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/
noncomputable def cau_seq_conj (f : cau_seq ℂ abs) : cau_seq ℂ abs :=
⟨_, is_cau_seq_conj f⟩
lemma lim_conj (f : cau_seq ℂ abs) : lim (cau_seq_conj f) = conj (lim f) :=
complex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])
(by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)
/-- The absolute value of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_abs (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_abs f.2⟩
lemma lim_abs (f : cau_seq ℂ abs) : lim (cau_seq_abs f) = abs (lim f) :=
lim_eq_of_equiv_const (λ ε ε0,
let ⟨i, hi⟩ := equiv_lim f ε ε0 in
⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩)
@[simp, norm_cast] lemma of_real_prod {α : Type*} (s : finset α) (f : α → ℝ) :
((∏ i in s, f i : ℝ) : ℂ) = ∏ i in s, (f i : ℂ) :=
ring_hom.map_prod of_real _ _
@[simp, norm_cast] lemma of_real_sum {α : Type*} (s : finset α) (f : α → ℝ) :
((∑ i in s, f i : ℝ) : ℂ) = ∑ i in s, (f i : ℂ) :=
ring_hom.map_sum of_real _ _
end complex
|
dbc4b2bf3afdc47909531dee72041a7cd253885a
|
f57749ca63d6416f807b770f67559503fdb21001
|
/library/data/set/basic.lean
|
ab7d1701354df5c203047df1ad9af8f2cf8013e0
|
[
"Apache-2.0"
] |
permissive
|
aliassaf/lean
|
bd54e85bed07b1ff6f01396551867b2677cbc6ac
|
f9b069b6a50756588b309b3d716c447004203152
|
refs/heads/master
| 1,610,982,152,948
| 1,438,916,029,000
| 1,438,916,029,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,287
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Leonardo de Moura
-/
import logic algebra.binary
open eq.ops binary
definition set [reducible] (X : Type) := X → Prop
namespace set
variable {X : Type}
/- membership and subset -/
definition mem [reducible] (x : X) (a : set X) := a x
infix `∈` := mem
notation a ∉ b := ¬ mem a b
theorem setext {a b : set X} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b :=
funext (take x, propext (H x))
definition subset (a b : set X) := ∀⦃x⦄, x ∈ a → x ∈ b
infix `⊆` := subset
theorem subset.refl (a : set X) : a ⊆ a := take x, assume H, H
theorem subset.trans (a b c : set X) (subab : a ⊆ b) (subbc : b ⊆ c) : a ⊆ c :=
take x, assume ax, subbc (subab ax)
theorem subset.antisymm {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
setext (λ x, iff.intro (λ ina, h₁ ina) (λ inb, h₂ inb))
-- an alterantive name
theorem eq_of_subset_of_subset {a b : set X} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
subset.antisymm h₁ h₂
definition strict_subset (a b : set X) := a ⊆ b ∧ a ≠ b
infix `⊂`:50 := strict_subset
theorem strict_subset.irrefl (a : set X) : ¬ a ⊂ a :=
assume h, absurd rfl (and.elim_right h)
/- bounded quantification -/
abbreviation bounded_forall (a : set X) (P : X → Prop) := ∀⦃x⦄, x ∈ a → P x
notation `forallb` binders `∈` a `,` r:(scoped:1 P, P) := bounded_forall a r
notation `∀₀` binders `∈` a `,` r:(scoped:1 P, P) := bounded_forall a r
abbreviation bounded_exists (a : set X) (P : X → Prop) := ∃⦃x⦄, x ∈ a ∧ P x
notation `existsb` binders `∈` a `,` r:(scoped:1 P, P) := bounded_exists a r
notation `∃₀` binders `∈` a `,` r:(scoped:1 P, P) := bounded_exists a r
/- empty set -/
definition empty [reducible] : set X := λx, false
notation `∅` := empty
theorem not_mem_empty (x : X) : ¬ (x ∈ ∅) :=
assume H : x ∈ ∅, H
theorem mem_empty_eq (x : X) : x ∈ ∅ = false := rfl
theorem eq_empty_of_forall_not_mem {s : set X} (H : ∀ x, x ∉ s) : s = ∅ :=
setext (take x, iff.intro
(assume xs, absurd xs (H x))
(assume xe, absurd xe !not_mem_empty))
theorem empty_subset (s : set X) : ∅ ⊆ s :=
take x, assume H, false.elim H
theorem eq_empty_of_subset_empty {s : set X} (H : s ⊆ ∅) : s = ∅ :=
subset.antisymm H (empty_subset s)
theorem subset_empty_iff (s : set X) : s ⊆ ∅ ↔ s = ∅ :=
iff.intro eq_empty_of_subset_empty (take xeq, by rewrite xeq; apply subset.refl ∅)
/- universal set -/
definition univ : set X := λx, true
theorem mem_univ (x : X) : x ∈ univ := trivial
theorem mem_univ_eq (x : X) : x ∈ univ = true := rfl
theorem empty_ne_univ [h : inhabited X] : (empty : set X) ≠ univ :=
assume H : empty = univ,
absurd (mem_univ (inhabited.value h)) (eq.rec_on H (not_mem_empty _))
/- union -/
definition union [reducible] (a b : set X) : set X := λx, x ∈ a ∨ x ∈ b
notation a ∪ b := union a b
theorem mem_union (x : X) (a b : set X) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := !iff.refl
theorem mem_union_eq (x : X) (a b : set X) : x ∈ a ∪ b = (x ∈ a ∨ x ∈ b) := rfl
theorem union_self (a : set X) : a ∪ a = a :=
setext (take x, !or_self)
theorem union_empty (a : set X) : a ∪ ∅ = a :=
setext (take x, !or_false)
theorem empty_union (a : set X) : ∅ ∪ a = a :=
setext (take x, !false_or)
theorem union.comm (a b : set X) : a ∪ b = b ∪ a :=
setext (take x, or.comm)
theorem union.assoc (a b c : set X) : (a ∪ b) ∪ c = a ∪ (b ∪ c) :=
setext (take x, or.assoc)
theorem union.left_comm (s₁ s₂ s₃ : set X) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
!left_comm union.comm union.assoc s₁ s₂ s₃
theorem union.right_comm (s₁ s₂ s₃ : set X) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ :=
!right_comm union.comm union.assoc s₁ s₂ s₃
/- intersection -/
definition inter [reducible] (a b : set X) : set X := λx, x ∈ a ∧ x ∈ b
notation a ∩ b := inter a b
theorem mem_inter (x : X) (a b : set X) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := !iff.refl
theorem mem_inter_eq (x : X) (a b : set X) : x ∈ a ∩ b = (x ∈ a ∧ x ∈ b) := rfl
theorem inter_self (a : set X) : a ∩ a = a :=
setext (take x, !and_self)
theorem inter_empty (a : set X) : a ∩ ∅ = ∅ :=
setext (take x, !and_false)
theorem empty_inter (a : set X) : ∅ ∩ a = ∅ :=
setext (take x, !false_and)
theorem inter.comm (a b : set X) : a ∩ b = b ∩ a :=
setext (take x, !and.comm)
theorem inter.assoc (a b c : set X) : (a ∩ b) ∩ c = a ∩ (b ∩ c) :=
setext (take x, !and.assoc)
theorem inter.left_comm (s₁ s₂ s₃ : set X) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
!left_comm inter.comm inter.assoc s₁ s₂ s₃
theorem inter.right_comm (s₁ s₂ s₃ : set X) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ :=
!right_comm inter.comm inter.assoc s₁ s₂ s₃
theorem inter_univ (a : set X) : a ∩ univ = a :=
setext (take x, !and_true)
theorem univ_inter (a : set X) : univ ∩ a = a :=
setext (take x, !true_and)
/- distributivity laws -/
theorem inter.distrib_left (s t u : set X) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) :=
setext (take x, !and.left_distrib)
theorem inter.distrib_right (s t u : set X) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) :=
setext (take x, !and.right_distrib)
theorem union.distrib_left (s t u : set X) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) :=
setext (take x, !or.left_distrib)
theorem union.distrib_right (s t u : set X) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) :=
setext (take x, !or.right_distrib)
/- set-builder notation -/
-- {x : X | P}
definition set_of (P : X → Prop) : set X := P
notation `{` binder `|` r:(scoped:1 P, set_of P) `}` := r
-- {x ∈ s | P}
definition filter (P : X → Prop) (s : set X) : set X := λx, x ∈ s ∧ P x
notation `{` binder ∈ s `|` r:(scoped:1 p, filter p s) `}` := r
-- '{x, y, z}
definition insert (x : X) (a : set X) : set X := {y : X | y = x ∨ y ∈ a}
notation `'{`:max a:(foldr `,` (x b, insert x b) ∅) `}`:0 := a
/- set difference -/
definition diff (s t : set X) : set X := {x ∈ s | x ∉ t}
infix `\`:70 := diff
theorem mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∈ s :=
and.left H
theorem not_mem_of_mem_diff {s t : set X} {x : X} (H : x ∈ s \ t) : x ∉ t :=
and.right H
theorem mem_diff {s t : set X} {x : X} (H1 : x ∈ s) (H2 : x ∉ t) : x ∈ s \ t :=
and.intro H1 H2
theorem mem_diff_iff (s t : set X) (x : X) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := !iff.refl
theorem mem_diff_eq (s t : set X) (x : X) : x ∈ s \ t = (x ∈ s ∧ x ∉ t) := rfl
/- large unions -/
section
variables {I : Type}
variable a : set I
variable b : I → set X
variable C : set (set X)
definition Inter : set X := {x : X | ∀i, x ∈ b i}
definition bInter : set X := {x : X | ∀₀ i ∈ a, x ∈ b i}
definition sInter : set X := {x : X | ∀₀ c ∈ C, x ∈ c}
definition Union : set X := {x : X | ∃i, x ∈ b i}
definition bUnion : set X := {x : X | ∃₀ i ∈ a, x ∈ b i}
definition sUnion : set X := {x : X | ∃₀ c ∈ C, x ∈ c}
-- TODO: need notation for these
end
end set
|
36163b7aaa00e20910b301bec856e904603ef7db
|
c5b07d17b3c9fb19e4b302465d237fd1d988c14f
|
/src/tmp/zipper.lean
|
44ed22ce6cdc5c1d0f11158e0fe2c62b86638d88
|
[
"MIT"
] |
permissive
|
skaslev/papers
|
acaec61602b28c33d6115e53913b2002136aa29b
|
f15b379f3c43bbd0a37ac7bb75f4278f7e901389
|
refs/heads/master
| 1,665,505,770,318
| 1,660,378,602,000
| 1,660,378,602,000
| 14,101,547
| 0
| 1
|
MIT
| 1,595,414,522,000
| 1,383,542,702,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 1,026
|
lean
|
import data.iso
import category.comonad
def U := Type
def UU := Type → Type
axiom deriv : UU → UU
-- The generating function of `zipper f` is T(x) = x f'(x)
def zipper (f : UU) (A) := A × deriv f A
-- The logarithmic derivative of f(x) is g(x) such that f'(x) = f(x) g(x)
-- that is g(x) = (ln f(x))' = f'(x)/f(x)
def logderiv (f : UU) := Σ g : UU, Π A, iso (deriv f A) (f A × g A)
-- Given f(x) and it's logarithmic derivative g(x) we can construct alternative zipper
def logderiv_zipper (f : UU) (g : logderiv f) (A) := A × f A × g.1 A
-- .. that is isomorphic to the usual one
def logderiv_zipper_iso (f : UU) (g : logderiv f) (A) : iso (zipper f A) (logderiv_zipper f g A) :=
iso.id_iso.mul (g.2 A)
namespace zipper
variables {f : UU} [functor (deriv f)]
def map {A B} (g : A → B) (x : zipper f A) : zipper f B :=
(g x.1, g <$> x.2)
instance : functor (zipper f) :=
{ map := @map _ _ }
def extract {A} (z : zipper f A) : A := z.1
-- def dup {A} (z : zipper f A) : zipper f (zipper f A) :=
end zipper
|
55195b6348ed860599925222e4ccf59d5bd10b5c
|
c31182a012eec69da0a1f6c05f42b0f0717d212d
|
/src/system_of_complexes/truncate.lean
|
dcbac5e4f0007b5f34567f10d582ded8296ee8fb
|
[] |
no_license
|
Ja1941/lean-liquid
|
fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc
|
8e80ed0cbdf5145d6814e833a674eaf05a1495c1
|
refs/heads/master
| 1,689,437,983,362
| 1,628,362,719,000
| 1,628,362,719,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,114
|
lean
|
import category_theory.preadditive.additive_functor
import system_of_complexes.basic
/-!
# Truncation
In this file we define a truncation functors for (systems of) complexes of seminormed groups.
This operation takes a complex `C` indexed by `ℕ`, and creates a new complex whose objects are
* in degree `0`: the cokernel of `d : C 0 ⟶ C 1`
* in degree `n+1`: the object `C (n+2)`
Various lemmas are proved about how this construction preserves or reflects
various notions of bounded exactness.
-/
universes u
noncomputable theory
open_locale nnreal
open category_theory category_theory.limits
namespace SemiNormedGroup
open quotient_add_group
namespace truncate
variables (C : cochain_complex SemiNormedGroup.{u} ℕ)
open category_theory.preadditive
def X : ℕ → SemiNormedGroup.{u}
| 0 := coker (C.d 0 1)
| (n+1) := C.X (n+2)
def d : Π i j, X C i ⟶ X C j
| 0 1 := coker.lift (C.d_comp_d 0 1 2)
| (i+1) (j+1) := C.d (i+2) (j+2)
| _ _ := 0
lemma d_eq_zero : ∀ ⦃i j : ℕ⦄, ¬(complex_shape.up ℕ).rel i j → d C i j = 0
| 0 0 h := rfl
| 0 (j+2) h := rfl
| (i+1) 0 h := rfl
| 0 1 h := (h rfl).elim
| (i+1) (j+1) h := C.shape _ _ $ λ H, h $ nat.succ_injective $ H
lemma d_comp_d : Π i j k, i + 1 = j → j + 1 = k → d C i j ≫ d C j k = 0
| 0 1 2 rfl rfl := coker.lift_comp_eq_zero _ (C.d_comp_d _ _ _)
| (i+1) (j+1) (k+1) rfl rfl := C.d_comp_d _ _ _
@[simps]
def obj : cochain_complex SemiNormedGroup ℕ :=
{ X := X C,
d := d C,
shape' := d_eq_zero C,
d_comp_d' := d_comp_d C }
lemma obj_d_add_one (C : cochain_complex SemiNormedGroup ℕ) (i j : ℕ) :
(obj C).d (i+1) (j+1) = d C (i+1) (j+1) :=
rfl
def map_f {C₁ C₂ : cochain_complex SemiNormedGroup ℕ} (f : C₁ ⟶ C₂) :
Π i:ℕ, X C₁ i ⟶ X C₂ i
| 0 := coker.map (f.comm 0 1).symm
| (i+1) := f.f (i+2)
lemma map_comm {C₁ C₂ : cochain_complex SemiNormedGroup.{u} ℕ} (f : C₁ ⟶ C₂) :
Π i j, i + 1 = j → map_f f i ≫ d C₂ i j = d C₁ i j ≫ map_f f j
| 0 1 rfl := (coker.map_lift_comm (f.comm 1 2).symm).symm
| (i+1) (j+1) rfl := f.comm (i+2) (j+2)
@[simps]
def map {C₁ C₂ : cochain_complex SemiNormedGroup.{u} ℕ} (f : C₁ ⟶ C₂) :
obj C₁ ⟶ obj C₂ :=
{ f := map_f f,
comm' := map_comm f }
end truncate
@[simps]
def truncate : cochain_complex SemiNormedGroup.{u} ℕ ⥤ cochain_complex SemiNormedGroup.{u} ℕ :=
{ obj := λ C, truncate.obj C,
map := λ C₁ C₂ f, truncate.map f,
map_id' := λ C, by ext (n|n) ⟨x⟩; refl,
map_comp' := λ C₁ C₂ C₃ f g, by ext (n|n) ⟨x⟩; refl }
instance truncate.additive : truncate.additive :=
{ map_zero' := by { intros, ext (n|n) ⟨⟩; refl },
map_add' := by { intros, ext (n|n) ⟨⟩; refl } }
end SemiNormedGroup
namespace system_of_complexes
open category_theory
variables (C : system_of_complexes.{u})
@[simps]
def truncate : system_of_complexes ⥤ system_of_complexes :=
(whiskering_right _ _ _).obj $ SemiNormedGroup.truncate
@[simp] lemma truncate_obj_d_zero_one (c : ℝ≥0) (y : C c 1) :
(truncate.obj C).d 0 1 (SemiNormedGroup.coker.π y) = C.d 1 2 y := rfl
@[simp] lemma truncate_obj_d_succ_succ (c : ℝ≥0) (i j : ℕ) (x: truncate.obj C c (i+1)) :
(truncate.obj C).d (i+1) (j+1) x = C.d (i+2) (j+2) x := rfl
lemma truncate_admissible (hC : C.admissible) :
(truncate.obj C).admissible :=
{ d_norm_noninc' :=
begin
rintro c (i|i) j rfl,
{ apply SemiNormedGroup.coker.lift_norm_noninc,
exact hC.d_norm_noninc _ _ 1 2 },
{ exact hC.d_norm_noninc _ _ (i+2) (i+3) }
end,
res_norm_noninc :=
begin
rintro c₁ c₂ (i|i) h x,
{ apply SemiNormedGroup.coker.lift_norm_noninc,
exact SemiNormedGroup.coker.π_norm_noninc.comp (hC.res_norm_noninc _ _ _ _) },
{ exact hC.res_norm_noninc _ _ _ _ x }
end }
variables {k K : ℝ≥0} (m' m : ℕ) [hk : fact (1 ≤ k)] (c₀ : ℝ≥0)
include hk
lemma truncate_is_weak_bounded_exact (hC : C.is_weak_bounded_exact k K (m+1) c₀) :
(truncate.obj C).is_weak_bounded_exact k K m c₀
| c hc 0 hi x ε hε :=
begin
let π := λ c, @SemiNormedGroup.coker.π _ _ (@d C c 0 1),
obtain ⟨x, rfl⟩ : ∃ x', π _ x' = x := SemiNormedGroup.coker.π_surjective x,
obtain ⟨i₀, -, hi₀, rfl, y, hy⟩ := hC c hc _ (nat.succ_le_succ hi) x ε hε,
obtain rfl : i₀ = 0, { rwa nat.sub_self at hi₀ }, clear hi,
refine ⟨0, _, rfl, rfl, 0, _⟩,
simp only [normed_group_hom.map_zero, sub_zero,
normed_group_hom.map_neg, truncate_obj_d_zero_one, norm_neg],
calc _ = ∥π c (res x - C.d 0 1 y)∥ : _
... ≤ ∥res x - C.d 0 1 y∥ : SemiNormedGroup.coker.π_norm_noninc _
... ≤ _ : hy,
have hπy : π c (C.d 0 1 y) = 0,
{ show (C.d 0 1 ≫ π c) y = 0, rw [SemiNormedGroup.coker.comp_pi_eq_zero], refl },
simp only [normed_group_hom.map_sub, hπy, sub_zero], refl
end
| c hc (i+1) hi x ε hε :=
begin
obtain ⟨_, _, rfl, rfl, y, hy⟩ := hC c hc _ (nat.succ_le_succ hi) x ε hε,
refine ⟨i, _, rfl, rfl, _⟩,
cases i; [exact ⟨SemiNormedGroup.coker.π y, hy⟩, exact ⟨y, hy⟩],
end
lemma is_weak_bounded_exact_of_truncate (IH : C.is_weak_bounded_exact k K m c₀)
(hC : (truncate.obj C).is_weak_bounded_exact k K m c₀) :
C.is_weak_bounded_exact k K (m+1) c₀
| c hc 0 hi x ε hε := IH c hc 0 (nat.zero_le _) x ε hε
| c hc 1 hi x ε hε :=
begin
let π := λ c, @SemiNormedGroup.coker.π _ _ (@d C c 0 1),
let δ := ε / 2,
have hδε : δ + δ = ε, { dsimp [δ], rw [← add_div, half_add_self] },
have hδ : 0 < δ := div_pos hε zero_lt_two,
obtain ⟨x', Hxx', Hx'⟩ : ∃ x', π c x' = π c (res x) ∧ ∥x'∥ < ∥π c (res x)∥ + δ :=
SemiNormedGroup.coker.π_is_quotient.norm_lift hδ _,
obtain ⟨y, hy⟩ : ∃ y : C c 0, C.d 0 1 y = res x - x',
{ erw [quotient_add_group.eq, add_comm, ← sub_eq_add_neg, set.mem_range] at Hxx',
exact Hxx' },
obtain ⟨_, _, rfl, rfl, y', H⟩ := hC c hc _ (nat.zero_le m) (π _ x) δ hδ,
refine ⟨0, 2, rfl, rfl, y, _⟩,
simp only [d_self_apply, normed_group_hom.map_zero, sub_zero,
truncate_obj_d_zero_one, norm_neg] at H ⊢,
calc ∥res x - (C.d 0 1) y∥ ≤ ∥x'∥ : by rw [hy, sub_sub_cancel]
... ≤ ∥π c (res x)∥ + δ : Hx'.le
... ≤ ↑K * ∥C.d 1 2 x∥ + δ + δ : add_le_add_right H _
... ≤ ↑K * ∥C.d 1 2 x∥ + ε : by rw [add_assoc, hδε]
end
| c hc (i+2) hi x ε hε :=
begin
obtain ⟨_, _, rfl, rfl, y, hy⟩ := hC c hc (i+1) (nat.pred_le_pred hi) x ε hε,
refine ⟨i+1, _, rfl, rfl, _⟩,
cases i,
{ let π := λ c, @SemiNormedGroup.coker.π _ _ (@d C c 0 1),
obtain ⟨y, rfl⟩ : ∃ y', π _ y' = y := SemiNormedGroup.coker.π_surjective y,
exact ⟨y, hy⟩ },
{ exact ⟨y, hy⟩ },
end
lemma truncate_is_weak_bounded_exact_iff (hC : C.is_weak_bounded_exact k K m c₀) :
(truncate.obj C).is_weak_bounded_exact k K m c₀ ↔ C.is_weak_bounded_exact k K (m+1) c₀ :=
⟨is_weak_bounded_exact_of_truncate C m c₀ hC, truncate_is_weak_bounded_exact C m c₀⟩
omit hk
end system_of_complexes
|
57518249c804cff5798c369151c28552fbf84a0d
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/analysis/normed_space/normed_group_hom.lean
|
344d230bae0d6cd4ff4262406922645212c1cbb6
|
[
"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
| 22,368
|
lean
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import analysis.normed_space.basic
import topology.sequences
/-!
# Normed groups homomorphisms
This file gathers definitions and elementary constructions about bounded group homomorphisms
between normed (abelian) groups (abbreviated to "normed group homs").
The main lemmas relate the boundedness condition to continuity and Lipschitzness.
The main construction is to endow the type of normed group homs between two given normed groups
with a group structure and a norm, giving rise to a normed group structure.
Some easy other constructions are related to subgroups of normed groups.
Since a lot of elementary properties don't require `∥x∥ = 0 → x = 0` we start setting up the
theory of `semi_normed_group_hom` and we specialize to `normed_group_hom` when needed.
-/
noncomputable theory
open_locale nnreal big_operators
/-- A morphism of seminormed abelian groups is a bounded group homomorphism. -/
structure normed_group_hom (V W : Type*) [semi_normed_group V] [semi_normed_group W] :=
(to_fun : V → W)
(map_add' : ∀ v₁ v₂, to_fun (v₁ + v₂) = to_fun v₁ + to_fun v₂)
(bound' : ∃ C, ∀ v, ∥to_fun v∥ ≤ C * ∥v∥)
namespace add_monoid_hom
variables {V W : Type*} [semi_normed_group V] [semi_normed_group W] {f g : normed_group_hom V W}
/-- Associate to a group homomorphism a bounded group homomorphism under a norm control condition.
See `add_monoid_hom.mk_normed_group_hom'` for a version that uses `ℝ≥0` for the bound. -/
def mk_normed_group_hom (f : V →+ W)
(C : ℝ) (h : ∀ v, ∥f v∥ ≤ C * ∥v∥) : normed_group_hom V W :=
{ bound' := ⟨C, h⟩, ..f }
/-- Associate to a group homomorphism a bounded group homomorphism under a norm control condition.
See `add_monoid_hom.mk_normed_group_hom` for a version that uses `ℝ` for the bound. -/
def mk_normed_group_hom' (f : V →+ W) (C : ℝ≥0) (hC : ∀ x, nnnorm (f x) ≤ C * nnnorm x) :
normed_group_hom V W :=
{ bound' := ⟨C, hC⟩ .. f}
end add_monoid_hom
lemma exists_pos_bound_of_bound {V W : Type*} [semi_normed_group V] [semi_normed_group W]
{f : V → W} (M : ℝ) (h : ∀x, ∥f x∥ ≤ M * ∥x∥) :
∃ N, 0 < N ∧ ∀x, ∥f x∥ ≤ N * ∥x∥ :=
⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), λx, calc
∥f x∥ ≤ M * ∥x∥ : h x
... ≤ max M 1 * ∥x∥ : mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _) ⟩
namespace normed_group_hom
variables {V V₁ V₂ V₃ : Type*}
variables [semi_normed_group V] [semi_normed_group V₁] [semi_normed_group V₂] [semi_normed_group V₃]
variables {f g : normed_group_hom V₁ V₂}
instance : has_coe_to_fun (normed_group_hom V₁ V₂) := ⟨_, normed_group_hom.to_fun⟩
initialize_simps_projections normed_group_hom (to_fun → apply)
lemma coe_inj (H : ⇑f = g) : f = g :=
by cases f; cases g; congr'; exact funext H
lemma coe_injective : @function.injective (normed_group_hom V₁ V₂) (V₁ → V₂) coe_fn :=
by apply coe_inj
lemma coe_inj_iff : f = g ↔ ⇑f = g := ⟨congr_arg _, coe_inj⟩
@[ext] lemma ext (H : ∀ x, f x = g x) : f = g := coe_inj $ funext H
lemma ext_iff : f = g ↔ ∀ x, f x = g x := ⟨by rintro rfl x; refl, ext⟩
variables (f g)
@[simp] lemma to_fun_eq_coe : f.to_fun = f := rfl
@[simp] lemma coe_mk (f) (h₁) (h₂) (h₃) : ⇑(⟨f, h₁, h₂, h₃⟩ : normed_group_hom V₁ V₂) = f := rfl
@[simp] lemma coe_mk_normed_group_hom (f : V₁ →+ V₂) (C) (hC) :
⇑(f.mk_normed_group_hom C hC) = f := rfl
@[simp] lemma coe_mk_normed_group_hom' (f : V₁ →+ V₂) (C) (hC) :
⇑(f.mk_normed_group_hom' C hC) = f := rfl
/-- The group homomorphism underlying a bounded group homomorphism. -/
def to_add_monoid_hom (f : normed_group_hom V₁ V₂) : V₁ →+ V₂ :=
add_monoid_hom.mk' f f.map_add'
@[simp] lemma coe_to_add_monoid_hom : ⇑f.to_add_monoid_hom = f := rfl
lemma to_add_monoid_hom_injective :
function.injective (@normed_group_hom.to_add_monoid_hom V₁ V₂ _ _) :=
λ f g h, coe_inj $ show ⇑f.to_add_monoid_hom = g, by { rw h, refl }
@[simp] lemma mk_to_add_monoid_hom (f) (h₁) (h₂) :
(⟨f, h₁, h₂⟩ : normed_group_hom V₁ V₂).to_add_monoid_hom = add_monoid_hom.mk' f h₁ := rfl
@[simp] lemma map_zero : f 0 = 0 := f.to_add_monoid_hom.map_zero
@[simp] lemma map_add (x y) : f (x + y) = f x + f y := f.to_add_monoid_hom.map_add _ _
@[simp] lemma map_sum {ι : Type*} (v : ι → V₁) (s : finset ι) :
f (∑ i in s, v i) = ∑ i in s, f (v i) :=
f.to_add_monoid_hom.map_sum _ _
@[simp] lemma map_sub (x y) : f (x - y) = f x - f y := f.to_add_monoid_hom.map_sub _ _
@[simp] lemma map_neg (x) : f (-x) = -(f x) := f.to_add_monoid_hom.map_neg _
lemma bound : ∃ C, 0 < C ∧ ∀ x, ∥f x∥ ≤ C * ∥x∥ :=
let ⟨C, hC⟩ := f.bound' in exists_pos_bound_of_bound _ hC
theorem antilipschitz_of_norm_ge {K : ℝ≥0} (h : ∀ x, ∥x∥ ≤ K * ∥f x∥) :
antilipschitz_with K f :=
antilipschitz_with.of_le_mul_dist $
λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y)
/-! ### The operator norm -/
/-- The operator norm of a seminormed group homomorphism is the inf of all its bounds. -/
def op_norm (f : normed_group_hom V₁ V₂) := Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥}
instance has_op_norm : has_norm (normed_group_hom V₁ V₂) := ⟨op_norm⟩
lemma norm_def : ∥f∥ = Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} := rfl
-- So that invocations of `real.Inf_le` make sense: we show that the set of
-- bounds is nonempty and bounded below.
lemma bounds_nonempty {f : normed_group_hom V₁ V₂} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } :=
let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩
lemma bounds_bdd_below {f : normed_group_hom V₁ V₂} :
bdd_below {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} :=
⟨0, λ _ ⟨hn, _⟩, hn⟩
lemma op_norm_nonneg : 0 ≤ ∥f∥ :=
real.lb_le_Inf _ bounds_nonempty (λ _ ⟨hx, _⟩, hx)
/-- The fundamental property of the operator norm: `∥f x∥ ≤ ∥f∥ * ∥x∥`. -/
theorem le_op_norm (x : V₁) : ∥f x∥ ≤ ∥f∥ * ∥x∥ :=
begin
obtain ⟨C, Cpos, hC⟩ := f.bound,
replace hC := hC x,
by_cases h : ∥x∥ = 0,
{ rwa [h, mul_zero] at ⊢ hC },
have hlt : 0 < ∥x∥ := lt_of_le_of_ne (norm_nonneg x) (ne.symm h),
exact (div_le_iff hlt).mp ((real.le_Inf _ bounds_nonempty bounds_bdd_below).2 (λ c ⟨_, hc⟩,
(div_le_iff hlt).mpr $ by { apply hc })),
end
theorem le_op_norm_of_le {c : ℝ} {x} (h : ∥x∥ ≤ c) : ∥f x∥ ≤ ∥f∥ * c :=
le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg)
theorem le_of_op_norm_le {c : ℝ} (h : ∥f∥ ≤ c) (x : V₁) : ∥f x∥ ≤ c * ∥x∥ :=
(f.le_op_norm x).trans (mul_le_mul_of_nonneg_right h (norm_nonneg x))
/-- continuous linear maps are Lipschitz continuous. -/
theorem lipschitz : lipschitz_with ⟨∥f∥, op_norm_nonneg f⟩ f :=
lipschitz_with.of_dist_le_mul $ λ x y,
by { rw [dist_eq_norm, dist_eq_norm, ←map_sub], apply le_op_norm }
protected lemma uniform_continuous (f : normed_group_hom V₁ V₂) :
uniform_continuous f := f.lipschitz.uniform_continuous
@[continuity]
protected lemma continuous (f : normed_group_hom V₁ V₂) : continuous f :=
f.uniform_continuous.continuous
lemma ratio_le_op_norm (x : V₁) : ∥f x∥ / ∥x∥ ≤ ∥f∥ :=
div_le_of_nonneg_of_le_mul (norm_nonneg _) f.op_norm_nonneg (le_op_norm _ _)
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ x, ∥f x∥ ≤ M * ∥x∥) :
∥f∥ ≤ M :=
real.Inf_le _ bounds_bdd_below ⟨hMp, hM⟩
theorem op_norm_le_of_lipschitz {f : normed_group_hom V₁ V₂} {K : ℝ≥0} (hf : lipschitz_with K f) :
∥f∥ ≤ K :=
f.op_norm_le_bound K.2 $ λ x, by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0
/-- If a bounded group homomorphism map is constructed from a group homomorphism via the constructor
`mk_normed_group_hom`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
lemma mk_normed_group_hom_norm_le (f : V₁ →+ V₂) {C : ℝ} (hC : 0 ≤ C) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
∥f.mk_normed_group_hom C h∥ ≤ C :=
op_norm_le_bound _ hC h
/-- If a bounded group homomorphism map is constructed from a group homomorphism
via the constructor `mk_normed_group_hom`, then its norm is bounded by the bound
given to the constructor or zero if this bound is negative. -/
lemma mk_normed_group_hom_norm_le' (f : V₁ →+ V₂) {C : ℝ} (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
∥f.mk_normed_group_hom C h∥ ≤ max C 0 :=
op_norm_le_bound _ (le_max_right _ _) $ λ x, (h x).trans $
mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg x)
alias mk_normed_group_hom_norm_le ← add_monoid_hom.mk_normed_group_hom_norm_le
alias mk_normed_group_hom_norm_le' ← add_monoid_hom.mk_normed_group_hom_norm_le'
/-! ### Addition of normed group homs -/
/-- Addition of normed group homs. -/
instance : has_add (normed_group_hom V₁ V₂) :=
⟨λ f g, (f.to_add_monoid_hom + g.to_add_monoid_hom).mk_normed_group_hom (∥f∥ + ∥g∥) $ λ v, calc
∥f v + g v∥
≤ ∥f v∥ + ∥g v∥ : norm_add_le _ _
... ≤ ∥f∥ * ∥v∥ + ∥g∥ * ∥v∥ : add_le_add (le_op_norm f v) (le_op_norm g v)
... = (∥f∥ + ∥g∥) * ∥v∥ : by rw add_mul⟩
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ :=
mk_normed_group_hom_norm_le _ (add_nonneg (op_norm_nonneg _) (op_norm_nonneg _)) _
/--
Terms containing `@has_add.add (has_coe_to_fun.F ...) pi.has_add`
seem to cause leanchecker to [crash due to an out-of-memory
condition](https://github.com/leanprover-community/lean/issues/543).
As a workaround, we add a type annotation: `(f + g : V₁ → V₂)`
-/
library_note "addition on function coercions"
-- see Note [addition on function coercions]
@[simp] lemma coe_add (f g : normed_group_hom V₁ V₂) : ⇑(f + g) = (f + g : V₁ → V₂) := rfl
@[simp] lemma add_apply (f g : normed_group_hom V₁ V₂) (v : V₁) :
(f + g : normed_group_hom V₁ V₂) v = f v + g v := rfl
/-! ### The zero normed group hom -/
instance : has_zero (normed_group_hom V₁ V₂) :=
⟨(0 : V₁ →+ V₂).mk_normed_group_hom 0 (by simp)⟩
instance : inhabited (normed_group_hom V₁ V₂) := ⟨0⟩
/-- The norm of the `0` operator is `0`. -/
theorem op_norm_zero : ∥(0 : normed_group_hom V₁ V₂)∥ = 0 :=
le_antisymm (real.Inf_le _ bounds_bdd_below
⟨ge_of_eq rfl, λ _, le_of_eq (by { rw [zero_mul], exact norm_zero })⟩)
(op_norm_nonneg _)
/-- For normed groups, an operator is zero iff its norm vanishes. -/
theorem op_norm_zero_iff {V₁ V₂ : Type*} [normed_group V₁] [normed_group V₂]
{f : normed_group_hom V₁ V₂} : ∥f∥ = 0 ↔ f = 0 :=
iff.intro
(λ hn, ext (λ x, norm_le_zero_iff.1
(calc _ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _
... = _ : by rw [hn, zero_mul])))
(λ hf, by rw [hf, op_norm_zero] )
-- see Note [addition on function coercions]
@[simp] lemma coe_zero : ⇑(0 : normed_group_hom V₁ V₂) = (0 : V₁ → V₂) := rfl
@[simp] lemma zero_apply (v : V₁) : (0 : normed_group_hom V₁ V₂) v = 0 := rfl
variables {f g}
/-! ### The identity normed group hom -/
variable (V)
/-- The identity as a continuous normed group hom. -/
@[simps]
def id : normed_group_hom V V :=
(add_monoid_hom.id V).mk_normed_group_hom 1 (by simp [le_refl])
/-- The norm of the identity is at most `1`. It is in fact `1`, except when the norm of every
element vanishes, where it is `0`. (Since we are working with seminorms this can happen even if the
space is non-trivial.) It means that one can not do better than an inequality in general. -/
lemma norm_id_le : ∥(id V : normed_group_hom V V)∥ ≤ 1 :=
op_norm_le_bound _ zero_le_one (λx, by simp)
/-- If there is an element with norm different from `0`, then the norm of the identity equals `1`.
(Since we are working with seminorms supposing that the space is non-trivial is not enough.) -/
lemma norm_id_of_nontrivial_seminorm (h : ∃ (x : V), ∥x∥ ≠ 0 ) :
∥(id V)∥ = 1 :=
le_antisymm (norm_id_le V) $ let ⟨x, hx⟩ := h in
have _ := (id V).ratio_le_op_norm x,
by rwa [id_apply, div_self hx] at this
/-- If a normed space is non-trivial, then the norm of the identity equals `1`. -/
lemma norm_id {V : Type*} [normed_group V] [nontrivial V] : ∥(id V)∥ = 1 :=
begin
refine norm_id_of_nontrivial_seminorm V _,
obtain ⟨x, hx⟩ := exists_ne (0 : V),
exact ⟨x, ne_of_gt (norm_pos_iff.2 hx)⟩,
end
lemma coe_id : ((normed_group_hom.id V) : V → V) = (_root_.id : V → V) := rfl
/-! ### The negation of a normed group hom -/
/-- Opposite of a normed group hom. -/
instance : has_neg (normed_group_hom V₁ V₂) :=
⟨λ f, (-f.to_add_monoid_hom).mk_normed_group_hom (∥f∥) (λ v, by simp [le_op_norm f v])⟩
-- see Note [addition on function coercions]
@[simp] lemma coe_neg (f : normed_group_hom V₁ V₂) : ⇑(-f) = (-f : V₁ → V₂) := rfl
@[simp] lemma neg_apply (f : normed_group_hom V₁ V₂) (v : V₁) :
(-f : normed_group_hom V₁ V₂) v = - (f v) := rfl
lemma op_norm_neg (f : normed_group_hom V₁ V₂) : ∥-f∥ = ∥f∥ :=
by simp only [norm_def, coe_neg, norm_neg, pi.neg_apply]
/-! ### Subtraction of normed group homs -/
/-- Subtraction of normed group homs. -/
instance : has_sub (normed_group_hom V₁ V₂) :=
⟨λ f g,
{ bound' :=
begin
simp only [add_monoid_hom.sub_apply, add_monoid_hom.to_fun_eq_coe, sub_eq_add_neg],
exact (f + -g).bound'
end,
.. (f.to_add_monoid_hom - g.to_add_monoid_hom) }⟩
-- see Note [addition on function coercions]
@[simp] lemma coe_sub (f g : normed_group_hom V₁ V₂) : ⇑(f - g) = (f - g : V₁ → V₂) := rfl
@[simp] lemma sub_apply (f g : normed_group_hom V₁ V₂) (v : V₁) :
(f - g : normed_group_hom V₁ V₂) v = f v - g v := rfl
/-! ### Normed group structure on normed group homs -/
/-- Homs between two given normed groups form a commutative additive group. -/
instance : add_comm_group (normed_group_hom V₁ V₂) :=
coe_injective.add_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl)
/-- Normed group homomorphisms themselves form a seminormed group with respect to
the operator norm. -/
instance to_semi_normed_group : semi_normed_group (normed_group_hom V₁ V₂) :=
semi_normed_group.of_core _ ⟨op_norm_zero, op_norm_add_le, op_norm_neg⟩
/-- Normed group homomorphisms themselves form a normed group with respect to
the operator norm. -/
instance to_normed_group {V₁ V₂ : Type*} [normed_group V₁] [normed_group V₂] :
normed_group (normed_group_hom V₁ V₂) :=
normed_group.of_core _ ⟨λ f, op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩
/-- Coercion of a `normed_group_hom` is an `add_monoid_hom`. Similar to `add_monoid_hom.coe_fn` -/
@[simps]
def coe_fn_add_hom : normed_group_hom V₁ V₂ →+ (V₁ → V₂) :=
{ to_fun := coe_fn, map_zero' := coe_zero, map_add' := coe_add}
@[simp] lemma coe_sum {ι : Type*} (s : finset ι) (f : ι → normed_group_hom V₁ V₂) :
⇑(∑ i in s, f i) = ∑ i in s, (f i) :=
(coe_fn_add_hom : _ →+ (V₁ → V₂)).map_sum f s
lemma sum_apply {ι : Type*} (s : finset ι) (f : ι → normed_group_hom V₁ V₂) (v : V₁) :
(∑ i in s, f i) v = ∑ i in s, (f i v) :=
by simp only [coe_sum, finset.sum_apply]
/-! ### Composition of normed group homs -/
/-- The composition of continuous normed group homs. -/
@[simps]
protected def comp (g : normed_group_hom V₂ V₃) (f : normed_group_hom V₁ V₂) :
normed_group_hom V₁ V₃ :=
(g.to_add_monoid_hom.comp f.to_add_monoid_hom).mk_normed_group_hom (∥g∥ * ∥f∥) $ λ v, calc
∥g (f v)∥ ≤ ∥g∥ * ∥f v∥ : le_op_norm _ _
... ≤ ∥g∥ * (∥f∥ * ∥v∥) : mul_le_mul_of_nonneg_left (le_op_norm _ _) (op_norm_nonneg _)
... = ∥g∥ * ∥f∥ * ∥v∥ : by rw mul_assoc
lemma norm_comp_le (g : normed_group_hom V₂ V₃) (f : normed_group_hom V₁ V₂) :
∥g.comp f∥ ≤ ∥g∥ * ∥f∥ :=
mk_normed_group_hom_norm_le _ (mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _)) _
lemma norm_comp_le_of_le {g : normed_group_hom V₂ V₃} {C₁ C₂ : ℝ} (hg : ∥g∥ ≤ C₂) (hf : ∥f∥ ≤ C₁) :
∥g.comp f∥ ≤ C₂ * C₁ :=
le_trans (norm_comp_le g f) $ mul_le_mul hg hf (norm_nonneg _) (le_trans (norm_nonneg _) hg)
lemma norm_comp_le_of_le' {g : normed_group_hom V₂ V₃} (C₁ C₂ C₃ : ℝ) (h : C₃ = C₂ * C₁)
(hg : ∥g∥ ≤ C₂) (hf : ∥f∥ ≤ C₁) : ∥g.comp f∥ ≤ C₃ :=
by { rw h, exact norm_comp_le_of_le hg hf }
/-- Composition of normed groups hom as an additive group morphism. -/
def comp_hom : (normed_group_hom V₂ V₃) →+ (normed_group_hom V₁ V₂) →+ (normed_group_hom V₁ V₃) :=
add_monoid_hom.mk' (λ g, add_monoid_hom.mk' (λ f, g.comp f)
(by { intros, ext, exact g.map_add _ _ }))
(by { intros, ext, simp only [comp_apply, pi.add_apply, function.comp_app,
add_monoid_hom.add_apply, add_monoid_hom.mk'_apply, coe_add] })
@[simp] lemma comp_zero (f : normed_group_hom V₂ V₃) : f.comp (0 : normed_group_hom V₁ V₂) = 0 :=
by { ext, exact f.map_zero }
@[simp] lemma zero_comp (f : normed_group_hom V₁ V₂) : (0 : normed_group_hom V₂ V₃).comp f = 0 :=
by { ext, refl }
lemma comp_assoc {V₄: Type* } [semi_normed_group V₄] (h : normed_group_hom V₃ V₄)
(g : normed_group_hom V₂ V₃) (f : normed_group_hom V₁ V₂) :
(h.comp g).comp f = h.comp (g.comp f) :=
by { ext, refl }
lemma coe_comp (f : normed_group_hom V₁ V₂) (g : normed_group_hom V₂ V₃) :
(g.comp f : V₁ → V₃) = (g : V₂ → V₃) ∘ (f : V₁ → V₂) := rfl
end normed_group_hom
namespace normed_group_hom
variables {V W V₁ V₂ V₃ : Type*}
variables [semi_normed_group V] [semi_normed_group W] [semi_normed_group V₁] [semi_normed_group V₂]
[semi_normed_group V₃]
/-- The inclusion of an `add_subgroup`, as bounded group homomorphism. -/
@[simps] def incl (s : add_subgroup V) : normed_group_hom s V :=
{ to_fun := (coe : s → V),
map_add' := λ v w, add_subgroup.coe_add _ _ _,
bound' := ⟨1, λ v, by { rw [one_mul], refl }⟩ }
lemma norm_incl {V' : add_subgroup V} (x : V') : ∥incl _ x∥ = ∥x∥ :=
rfl
/-!### Kernel -/
section kernels
variables (f : normed_group_hom V₁ V₂) (g : normed_group_hom V₂ V₃)
/-- The kernel of a bounded group homomorphism. Naturally endowed with a
`semi_normed_group` instance. -/
def ker : add_subgroup V₁ := f.to_add_monoid_hom.ker
lemma mem_ker (v : V₁) : v ∈ f.ker ↔ f v = 0 :=
by { erw f.to_add_monoid_hom.mem_ker, refl }
/-- Given a normed group hom `f : V₁ → V₂` satisfying `g.comp f = 0` for some `g : V₂ → V₃`,
the corestriction of `f` to the kernel of `g`. -/
@[simps] def ker.lift (h : g.comp f = 0) :
normed_group_hom V₁ g.ker :=
{ to_fun := λ v, ⟨f v, by { erw g.mem_ker, show (g.comp f) v = 0, rw h, refl }⟩,
map_add' := λ v w, by { simp only [map_add], refl },
bound' := f.bound' }
@[simp] lemma ker.incl_comp_lift (h : g.comp f = 0) :
(incl g.ker).comp (ker.lift f g h) = f :=
by { ext, refl }
@[simp]
lemma ker_zero : (0 : normed_group_hom V₁ V₂).ker = ⊤ :=
by { ext, simp [mem_ker] }
lemma coe_ker : (f.ker : set V₁) = (f : V₁ → V₂) ⁻¹' {0} := rfl
lemma is_closed_ker {V₂ : Type*} [normed_group V₂] (f : normed_group_hom V₁ V₂) :
is_closed (f.ker : set V₁) :=
f.coe_ker ▸ is_closed.preimage f.continuous (t1_space.t1 0)
end kernels
/-! ### Range -/
section range
variables (f : normed_group_hom V₁ V₂) (g : normed_group_hom V₂ V₃)
/-- The image of a bounded group homomorphism. Naturally endowed with a
`semi_normed_group` instance. -/
def range : add_subgroup V₂ := f.to_add_monoid_hom.range
lemma mem_range (v : V₂) : v ∈ f.range ↔ ∃ w, f w = v :=
by { rw [range, add_monoid_hom.mem_range], refl }
lemma comp_range : (g.comp f).range = add_subgroup.map g.to_add_monoid_hom f.range :=
by { erw add_monoid_hom.map_range, refl }
lemma incl_range (s : add_subgroup V₁) : (incl s).range = s :=
by { ext x, exact ⟨λ ⟨y, hy⟩, by { rw ← hy; simp }, λ hx, ⟨⟨x, hx⟩, by simp⟩⟩ }
@[simp]
lemma range_comp_incl_top : (f.comp (incl (⊤ : add_subgroup V₁))).range = f.range :=
by simpa [comp_range, incl_range, ← add_monoid_hom.range_eq_map]
end range
variables {f : normed_group_hom V W}
/-- A `normed_group_hom` is *norm-nonincreasing* if `∥f v∥ ≤ ∥v∥` for all `v`. -/
def norm_noninc (f : normed_group_hom V W) : Prop :=
∀ v, ∥f v∥ ≤ ∥v∥
namespace norm_noninc
lemma norm_noninc_iff_norm_le_one : f.norm_noninc ↔ ∥f∥ ≤ 1 :=
begin
refine ⟨λ h, _, λ h, λ v, _⟩,
{ refine op_norm_le_bound _ (zero_le_one) (λ v, _),
simpa [one_mul] using h v },
{ simpa using le_of_op_norm_le f h v }
end
lemma zero : (0 : normed_group_hom V₁ V₂).norm_noninc :=
λ v, by simp
lemma id : (id V).norm_noninc :=
λ v, le_rfl
lemma comp {g : normed_group_hom V₂ V₃} {f : normed_group_hom V₁ V₂}
(hg : g.norm_noninc) (hf : f.norm_noninc) :
(g.comp f).norm_noninc :=
λ v, (hg (f v)).trans (hf v)
end norm_noninc
section isometry
lemma isometry_iff_norm (f : normed_group_hom V W) :
isometry f ↔ ∀ v, ∥f v∥ = ∥v∥ :=
add_monoid_hom.isometry_iff_norm f.to_add_monoid_hom
lemma isometry_of_norm (f : normed_group_hom V W) (hf : ∀ v, ∥f v∥ = ∥v∥) :
isometry f :=
f.isometry_iff_norm.mpr hf
lemma norm_eq_of_isometry {f : normed_group_hom V W} (hf : isometry f) (v : V) :
∥f v∥ = ∥v∥ :=
f.isometry_iff_norm.mp hf v
lemma isometry_id : @isometry V V _ _ (id V) :=
isometry_id
lemma isometry_comp {g : normed_group_hom V₂ V₃} {f : normed_group_hom V₁ V₂}
(hg : isometry g) (hf : isometry f) :
isometry (g.comp f) :=
hg.comp hf
lemma norm_noninc_of_isometry (hf : isometry f) : f.norm_noninc :=
λ v, le_of_eq $ norm_eq_of_isometry hf v
end isometry
end normed_group_hom
|
4dca7da2a15339c7e66cfbcbc23fab9e5d178535
|
649957717d58c43b5d8d200da34bf374293fe739
|
/src/category_theory/discrete_category.lean
|
0635033c17caaec5bc7d1f42dc540c4a873e0b7e
|
[
"Apache-2.0"
] |
permissive
|
Vtec234/mathlib
|
b50c7b21edea438df7497e5ed6a45f61527f0370
|
fb1848bbbfce46152f58e219dc0712f3289d2b20
|
refs/heads/master
| 1,592,463,095,113
| 1,562,737,749,000
| 1,562,737,749,000
| 196,202,858
| 0
| 0
|
Apache-2.0
| 1,562,762,338,000
| 1,562,762,337,000
| null |
UTF-8
|
Lean
| false
| false
| 2,423
|
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, Floris van Doorn
import data.ulift
import category_theory.opposites category_theory.equivalence
namespace category_theory
universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
-- We only work in `Type`, rather than `Sort`, as we need to use `ulift`.
def discrete (α : Type u₁) := α
instance discrete_category (α : Type u₁) : small_category (discrete α) :=
{ hom := λ X Y, ulift (plift (X = Y)),
id := λ X, ulift.up (plift.up rfl),
comp := λ X Y Z g f, by { rcases f with ⟨⟨rfl⟩⟩, exact g } }
namespace discrete
variables {α : Type u₁}
@[simp] lemma id_def (X : discrete α) : ulift.up (plift.up (eq.refl X)) = 𝟙 X := rfl
end discrete
variables {C : Type u₂} [𝒞 : category.{v₂} C]
include 𝒞
namespace functor
@[simp] def of_function {I : Type u₁} (F : I → C) : (discrete I) ⥤ C :=
{ obj := F,
map := λ X Y f, begin cases f, cases f, cases f, exact 𝟙 (F X) end }
end functor
namespace nat_trans
@[simp] def of_homs {I : Type u₁} {F G : discrete I ⥤ C}
(f : Π i : discrete I, F.obj i ⟶ G.obj i) : F ⟶ G :=
{ app := f }
@[simp] def of_function {I : Type u₁} {F G : I → C} (f : Π i : I, F i ⟶ G i) :
(functor.of_function F) ⟶ (functor.of_function G) :=
of_homs f
end nat_trans
namespace nat_iso
@[simp] def of_isos {I : Type u₁} {F G : discrete I ⥤ C}
(f : Π i : discrete I, F.obj i ≅ G.obj i) : F ≅ G :=
of_components f (by tidy)
end nat_iso
namespace discrete
variables {J : Type v₁}
omit 𝒞
def lift {α : Type u₁} {β : Type u₂} (f : α → β) : (discrete α) ⥤ (discrete β) :=
functor.of_function f
open opposite
protected def opposite (α : Type u₁) : (discrete α)ᵒᵖ ≌ discrete α :=
let F : discrete α ⥤ (discrete α)ᵒᵖ := functor.of_function (λ x, op x) in
begin
refine equivalence.mk (functor.left_op F) F _ (nat_iso.of_isos $ λ X, by simp [F]),
refine nat_iso.of_components (λ X, by simp [F]) _,
tidy
end
include 𝒞
@[simp] lemma functor_map_id
(F : discrete J ⥤ C) {j : discrete J} (f : j ⟶ j) : F.map f = 𝟙 (F.obj j) :=
begin
have h : f = 𝟙 j, cases f, cases f, ext,
rw h,
simp,
end
end discrete
end category_theory
|
f7b8e41ae022858522ce244422f9febb2cdea272
|
43390109ab88557e6090f3245c47479c123ee500
|
/src/M1F/problem_bank/0504/Q0504.lean
|
9a4c410d4e8b6ea57bb7aae58cf412128c9a03a0
|
[
"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
| 211
|
lean
|
import algebra.group_power tactic.norm_num algebra.big_operators
def factorial : ℕ → ℕ
| 0 := 1
| (n+1) := (factorial n) * (n+1)
theorem Q4 (n : ℕ) (H : n > 0) : factorial n < 3^n ↔ n ≤ 6 := sorry
|
07d77268afb9809c9268126d9ad996404e93064a
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/geometry/manifold/vector_bundle/fiberwise_linear.lean
|
d2253f00b568dd2cace2d8d5b88c3ea3f2ffbcf2
|
[
"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
| 15,128
|
lean
|
/-
Copyright (c) 2022 Floris van Doorn, Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Heather Macbeth
-/
import geometry.manifold.cont_mdiff
/-! # The groupoid of smooth, fiberwise-linear maps
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file contains preliminaries for the definition of a smooth vector bundle: an associated
`structure_groupoid`, the groupoid of `smooth_fiberwise_linear` functions.
-/
noncomputable theory
open set topological_space
open_locale manifold topology
/-! ### The groupoid of smooth, fiberwise-linear maps -/
variables {𝕜 B F : Type*} [topological_space B]
variables [nontrivially_normed_field 𝕜] [normed_add_comm_group F] [normed_space 𝕜 F]
namespace fiberwise_linear
variables {φ φ' : B → F ≃L[𝕜] F} {U U' : set B}
/-- For `B` a topological space and `F` a `𝕜`-normed space, a map from `U : set B` to `F ≃L[𝕜] F`
determines a local homeomorphism from `B × F` to itself by its action fiberwise. -/
def local_homeomorph (φ : B → F ≃L[𝕜] F) (hU : is_open U)
(hφ : continuous_on (λ x, φ x : B → F →L[𝕜] F) U)
(h2φ : continuous_on (λ x, (φ x).symm : B → F →L[𝕜] F) U) :
local_homeomorph (B × F) (B × F) :=
{ to_fun := λ x, (x.1, φ x.1 x.2),
inv_fun := λ x, (x.1, (φ x.1).symm x.2),
source := U ×ˢ univ,
target := U ×ˢ univ,
map_source' := λ x hx, mk_mem_prod hx.1 (mem_univ _),
map_target' := λ x hx, mk_mem_prod hx.1 (mem_univ _),
left_inv' := λ x _, prod.ext rfl (continuous_linear_equiv.symm_apply_apply _ _),
right_inv' := λ x _, prod.ext rfl (continuous_linear_equiv.apply_symm_apply _ _),
open_source := hU.prod is_open_univ,
open_target := hU.prod is_open_univ,
continuous_to_fun := begin
have : continuous_on (λ p : B × F, ((φ p.1 : F →L[𝕜] F), p.2)) (U ×ˢ univ),
{ exact hφ.prod_map continuous_on_id },
exact continuous_on_fst.prod (is_bounded_bilinear_map_apply.continuous.comp_continuous_on this),
end,
continuous_inv_fun := begin
have : continuous_on (λ p : B × F, (((φ p.1).symm : F →L[𝕜] F), p.2)) (U ×ˢ univ),
{ exact h2φ.prod_map continuous_on_id },
exact continuous_on_fst.prod (is_bounded_bilinear_map_apply.continuous.comp_continuous_on this),
end, }
/-- Compute the composition of two local homeomorphisms induced by fiberwise linear
equivalences. -/
lemma trans_local_homeomorph_apply
(hU : is_open U)
(hφ : continuous_on (λ x, φ x : B → F →L[𝕜] F) U)
(h2φ : continuous_on (λ x, (φ x).symm : B → F →L[𝕜] F) U)
(hU' : is_open U')
(hφ' : continuous_on (λ x, φ' x : B → F →L[𝕜] F) U')
(h2φ' : continuous_on (λ x, (φ' x).symm : B → F →L[𝕜] F) U')
(b : B) (v : F) :
(fiberwise_linear.local_homeomorph φ hU hφ h2φ ≫ₕ
fiberwise_linear.local_homeomorph φ' hU' hφ' h2φ') ⟨b, v⟩ = ⟨b, φ' b (φ b v)⟩ :=
rfl
/-- Compute the source of the composition of two local homeomorphisms induced by fiberwise linear
equivalences. -/
lemma source_trans_local_homeomorph
(hU : is_open U)
(hφ : continuous_on (λ x, φ x : B → F →L[𝕜] F) U)
(h2φ : continuous_on (λ x, (φ x).symm : B → F →L[𝕜] F) U)
(hU' : is_open U')
(hφ' : continuous_on (λ x, φ' x : B → F →L[𝕜] F) U')
(h2φ' : continuous_on (λ x, (φ' x).symm : B → F →L[𝕜] F) U') :
(fiberwise_linear.local_homeomorph φ hU hφ h2φ ≫ₕ
fiberwise_linear.local_homeomorph φ' hU' hφ' h2φ').source = (U ∩ U') ×ˢ univ :=
by { dsimp only [fiberwise_linear.local_homeomorph], mfld_set_tac }
/-- Compute the target of the composition of two local homeomorphisms induced by fiberwise linear
equivalences. -/
lemma target_trans_local_homeomorph
(hU : is_open U)
(hφ : continuous_on (λ x, φ x : B → F →L[𝕜] F) U)
(h2φ : continuous_on (λ x, (φ x).symm : B → F →L[𝕜] F) U)
(hU' : is_open U')
(hφ' : continuous_on (λ x, φ' x : B → F →L[𝕜] F) U')
(h2φ' : continuous_on (λ x, (φ' x).symm : B → F →L[𝕜] F) U') :
(fiberwise_linear.local_homeomorph φ hU hφ h2φ ≫ₕ
fiberwise_linear.local_homeomorph φ' hU' hφ' h2φ').target = (U ∩ U') ×ˢ univ :=
by { dsimp only [fiberwise_linear.local_homeomorph], mfld_set_tac }
end fiberwise_linear
variables {EB : Type*} [normed_add_comm_group EB] [normed_space 𝕜 EB]
{HB : Type*} [topological_space HB] [charted_space HB B] {IB : model_with_corners 𝕜 EB HB}
/-- Let `e` be a local homeomorphism of `B × F`. Suppose that at every point `p` in the source of
`e`, there is some neighbourhood `s` of `p` on which `e` is equal to a bi-smooth fiberwise linear
local homeomorphism.
Then the source of `e` is of the form `U ×ˢ univ`, for some set `U` in `B`, and, at any point `x` in
`U`, admits a neighbourhood `u` of `x` such that `e` is equal on `u ×ˢ univ` to some bi-smooth
fiberwise linear local homeomorphism. -/
lemma smooth_fiberwise_linear.locality_aux₁ (e : local_homeomorph (B × F) (B × F))
(h : ∀ p ∈ e.source, ∃ s : set (B × F), is_open s ∧ p ∈ s ∧
∃ (φ : B → (F ≃L[𝕜] F)) (u : set B) (hu : is_open u)
(hφ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, (φ x : F →L[𝕜] F)) u)
(h2φ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, ((φ x).symm : F →L[𝕜] F)) u),
(e.restr s).eq_on_source
(fiberwise_linear.local_homeomorph φ hu hφ.continuous_on h2φ.continuous_on)) :
∃ (U : set B) (hU : e.source = U ×ˢ univ),
∀ x ∈ U, ∃ (φ : B → (F ≃L[𝕜] F)) (u : set B) (hu : is_open u) (huU : u ⊆ U) (hux : x ∈ u)
(hφ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, (φ x : F →L[𝕜] F)) u)
(h2φ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, ((φ x).symm : F →L[𝕜] F)) u),
(e.restr (u ×ˢ univ)).eq_on_source
(fiberwise_linear.local_homeomorph φ hu hφ.continuous_on h2φ.continuous_on) :=
begin
rw [set_coe.forall'] at h,
-- choose s hs hsp φ u hu hφ h2φ heφ using h,
-- the following 2 lines should be `choose s hs hsp φ u hu hφ h2φ heφ using h,`
-- `choose` produces a proof term that takes a long time to type-check by the kernel (it seems)
-- porting note: todo: try using `choose` again in Lean 4
simp only [classical.skolem, ← exists_prop] at h,
rcases h with ⟨s, hs, hsp, φ, u, hu, hφ, h2φ, heφ⟩,
have hesu : ∀ p : e.source, e.source ∩ s p = u p ×ˢ univ,
{ intros p,
rw ← e.restr_source' (s _) (hs _),
exact (heφ p).1 },
have hu' : ∀ p : e.source, (p : B × F).fst ∈ u p,
{ intros p,
have : (p : B × F) ∈ e.source ∩ s p := ⟨p.prop, hsp p⟩,
simpa only [hesu, mem_prod, mem_univ, and_true] using this },
have heu : ∀ p : e.source, ∀ q : B × F, q.fst ∈ u p → q ∈ e.source,
{ intros p q hq,
have : q ∈ u p ×ˢ (univ : set F) := ⟨hq, trivial⟩,
rw ← hesu p at this,
exact this.1 },
have he : e.source = (prod.fst '' e.source) ×ˢ (univ : set F),
{ apply has_subset.subset.antisymm,
{ intros p hp,
exact ⟨⟨p, hp, rfl⟩, trivial⟩ },
{ rintros ⟨x, v⟩ ⟨⟨p, hp, rfl : p.fst = x⟩, -⟩,
exact heu ⟨p, hp⟩ (p.fst, v) (hu' ⟨p, hp⟩) } },
refine ⟨prod.fst '' e.source, he, _⟩,
rintros x ⟨p, hp, rfl⟩,
refine ⟨φ ⟨p, hp⟩, u ⟨p, hp⟩, hu ⟨p, hp⟩, _, hu' _, hφ ⟨p, hp⟩, h2φ ⟨p, hp⟩, _⟩,
{ intros y hy, refine ⟨(y, 0), heu ⟨p, hp⟩ ⟨_, _⟩ hy, rfl⟩ },
{ rw [← hesu, e.restr_source_inter], exact heφ ⟨p, hp⟩ },
end
/-- Let `e` be a local homeomorphism of `B × F` whose source is `U ×ˢ univ`, for some set `U` in
`B`, and which, at any point `x` in `U`, admits a neighbourhood `u` of `x` such that `e` is equal on
`u ×ˢ univ` to some bi-smooth fiberwise linear local homeomorphism. Then `e` itself is equal to
some bi-smooth fiberwise linear local homeomorphism.
This is the key mathematical point of the `locality` condition in the construction of the
`structure_groupoid` of bi-smooth fiberwise linear local homeomorphisms. The proof is by gluing
together the various bi-smooth fiberwise linear local homeomorphism which exist locally.
The `U` in the conclusion is the same `U` as in the hypothesis. We state it like this, because this
is exactly what we need for `smooth_fiberwise_linear`. -/
lemma smooth_fiberwise_linear.locality_aux₂ (e : local_homeomorph (B × F) (B × F))
(U : set B) (hU : e.source = U ×ˢ univ)
(h : ∀ x ∈ U, ∃ (φ : B → (F ≃L[𝕜] F)) (u : set B) (hu : is_open u) (hUu : u ⊆ U) (hux : x ∈ u)
(hφ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, (φ x : F →L[𝕜] F)) u)
(h2φ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, ((φ x).symm : F →L[𝕜] F)) u),
(e.restr (u ×ˢ univ)).eq_on_source
(fiberwise_linear.local_homeomorph φ hu hφ.continuous_on h2φ.continuous_on)) :
∃ (Φ : B → (F ≃L[𝕜] F)) (U : set B) (hU₀ : is_open U)
(hΦ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, (Φ x : F →L[𝕜] F)) U)
(h2Φ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, ((Φ x).symm : F →L[𝕜] F)) U),
e.eq_on_source (fiberwise_linear.local_homeomorph Φ hU₀ hΦ.continuous_on h2Φ.continuous_on) :=
begin
classical,
rw set_coe.forall' at h,
choose! φ u hu hUu hux hφ h2φ heφ using h,
have heuφ : ∀ x : U, eq_on e (λ q, (q.1, φ x q.1 q.2)) (u x ×ˢ univ),
{ intros x p hp,
refine (heφ x).2 _,
rw (heφ x).1,
exact hp },
have huφ : ∀ (x x' : U) (y : B) (hyx : y ∈ u x) (hyx' : y ∈ u x'), φ x y = φ x' y,
{ intros p p' y hyp hyp',
ext v,
have h1 : e (y, v) = (y, φ p y v) := heuφ _ ⟨(id hyp : (y, v).fst ∈ u p), trivial⟩,
have h2 : e (y, v) = (y, φ p' y v) := heuφ _ ⟨(id hyp' : (y, v).fst ∈ u p'), trivial⟩,
exact congr_arg prod.snd (h1.symm.trans h2) },
have hUu' : U = ⋃ i, u i,
{ ext x,
rw mem_Union,
refine ⟨λ h, ⟨⟨x, h⟩, hux _⟩, _⟩,
rintros ⟨x, hx⟩,
exact hUu x hx },
have hU' : is_open U,
{ rw hUu',
apply is_open_Union hu },
let Φ₀ : U → F ≃L[𝕜] F := Union_lift u (λ x, (φ x) ∘ coe) huφ U hUu'.le,
let Φ : B → F ≃L[𝕜] F := λ y, if hy : y ∈ U then Φ₀ ⟨y, hy⟩ else continuous_linear_equiv.refl 𝕜 F,
have hΦ : ∀ (y) (hy : y ∈ U), Φ y = Φ₀ ⟨y, hy⟩ := λ y hy, dif_pos hy,
have hΦφ : ∀ x : U, ∀ y ∈ u x, Φ y = φ x y,
{ intros x y hyu,
refine (hΦ y (hUu x hyu)).trans _,
exact Union_lift_mk ⟨y, hyu⟩ _ },
have hΦ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ y, (Φ y : F →L[𝕜] F)) U,
{ apply cont_mdiff_on_of_locally_cont_mdiff_on,
intros x hx,
refine ⟨u ⟨x, hx⟩, hu ⟨x, hx⟩, hux _, _⟩,
refine (cont_mdiff_on.congr (hφ ⟨x, hx⟩) _).mono (inter_subset_right _ _),
intros y hy,
rw hΦφ ⟨x, hx⟩ y hy },
have h2Φ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ y, ((Φ y).symm : F →L[𝕜] F)) U,
{ apply cont_mdiff_on_of_locally_cont_mdiff_on,
intros x hx,
refine ⟨u ⟨x, hx⟩, hu ⟨x, hx⟩, hux _, _⟩,
refine (cont_mdiff_on.congr (h2φ ⟨x, hx⟩) _).mono (inter_subset_right _ _),
intros y hy,
rw hΦφ ⟨x, hx⟩ y hy },
refine ⟨Φ, U, hU', hΦ, h2Φ, hU, λ p hp, _⟩,
rw [hU] at hp,
-- using rw on the next line seems to cause a timeout in kernel type-checking
refine (heuφ ⟨p.fst, hp.1⟩ ⟨hux _, hp.2⟩).trans _,
congrm (_, _),
rw hΦφ,
apply hux
end
variables (F B IB)
/-- For `B` a manifold and `F` a normed space, the groupoid on `B × F` consisting of local
homeomorphisms which are bi-smooth and fiberwise linear, and induce the identity on `B`.
When a (topological) vector bundle is smooth, then the composition of charts associated
to the vector bundle belong to this groupoid. -/
def smooth_fiberwise_linear : structure_groupoid (B × F) :=
{ members := ⋃ (φ : B → F ≃L[𝕜] F) (U : set B) (hU : is_open U)
(hφ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, φ x : B → F →L[𝕜] F) U)
(h2φ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, (φ x).symm : B → F →L[𝕜] F) U),
{e | e.eq_on_source (fiberwise_linear.local_homeomorph φ hU hφ.continuous_on h2φ.continuous_on)},
trans' := begin
simp_rw [mem_Union],
rintros e e' ⟨φ, U, hU, hφ, h2φ, heφ⟩ ⟨φ', U', hU', hφ', h2φ', heφ'⟩,
refine ⟨λ b, (φ b).trans (φ' b), _, hU.inter hU', _, _, setoid.trans (heφ.trans' heφ') ⟨_, _⟩⟩,
{ show smooth_on IB 𝓘(𝕜, F →L[𝕜] F)
(λ (x : B), (φ' x).to_continuous_linear_map ∘L (φ x).to_continuous_linear_map) (U ∩ U'),
exact (hφ'.mono $ inter_subset_right _ _).clm_comp (hφ.mono $ inter_subset_left _ _) },
{ show smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ (x : B),
(φ x).symm.to_continuous_linear_map ∘L (φ' x).symm.to_continuous_linear_map) (U ∩ U'),
exact (h2φ.mono $ inter_subset_left _ _).clm_comp (h2φ'.mono $ inter_subset_right _ _) },
{ apply fiberwise_linear.source_trans_local_homeomorph },
{ rintros ⟨b, v⟩ hb, apply fiberwise_linear.trans_local_homeomorph_apply }
end,
symm' := begin
simp_rw [mem_Union],
rintros e ⟨φ, U, hU, hφ, h2φ, heφ⟩,
refine ⟨λ b, (φ b).symm, U, hU, h2φ, _, heφ.symm'⟩,
simp_rw continuous_linear_equiv.symm_symm,
exact hφ
end,
id_mem' := begin
simp_rw [mem_Union],
refine ⟨λ b, continuous_linear_equiv.refl 𝕜 F, univ, is_open_univ, _, _, ⟨_, λ b hb, _⟩⟩,
{ apply cont_mdiff_on_const },
{ apply cont_mdiff_on_const },
{ simp only [fiberwise_linear.local_homeomorph, local_homeomorph.refl_local_equiv,
local_equiv.refl_source, univ_prod_univ] },
{ simp only [fiberwise_linear.local_homeomorph, local_homeomorph.refl_apply, prod.mk.eta,
id.def, continuous_linear_equiv.coe_refl', local_homeomorph.mk_coe, local_equiv.coe_mk] },
end,
locality' := begin -- the hard work has been extracted to `locality_aux₁` and `locality_aux₂`
simp_rw [mem_Union],
intros e he,
obtain ⟨U, hU, h⟩ := smooth_fiberwise_linear.locality_aux₁ e he,
exact smooth_fiberwise_linear.locality_aux₂ e U hU h,
end,
eq_on_source' := begin
simp_rw [mem_Union],
rintros e e' ⟨φ, U, hU, hφ, h2φ, heφ⟩ hee',
exact ⟨φ, U, hU, hφ, h2φ, setoid.trans hee' heφ⟩,
end }
@[simp] lemma mem_smooth_fiberwise_linear_iff (e : local_homeomorph (B × F) (B × F)) :
e ∈ smooth_fiberwise_linear B F IB ↔
∃ (φ : B → F ≃L[𝕜] F) (U : set B) (hU : is_open U)
(hφ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, φ x : B → F →L[𝕜] F) U)
(h2φ : smooth_on IB 𝓘(𝕜, F →L[𝕜] F) (λ x, (φ x).symm : B → F →L[𝕜] F) U),
e.eq_on_source (fiberwise_linear.local_homeomorph φ hU hφ.continuous_on h2φ.continuous_on) :=
show e ∈ set.Union _ ↔ _, by { simp only [mem_Union], refl }
|
1c9db72effbe9a3e9254d81d26fb55b1b0acb62d
|
7cef822f3b952965621309e88eadf618da0c8ae9
|
/src/topology/topological_fiber_bundle.lean
|
9997aceba5bcc23662f9c5c4b22d782e7fd1edd4
|
[
"Apache-2.0"
] |
permissive
|
rmitta/mathlib
|
8d90aee30b4db2b013e01f62c33f297d7e64a43d
|
883d974b608845bad30ae19e27e33c285200bf84
|
refs/heads/master
| 1,585,776,832,544
| 1,576,874,096,000
| 1,576,874,096,000
| 153,663,165
| 0
| 2
|
Apache-2.0
| 1,544,806,490,000
| 1,539,884,365,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 23,772
|
lean
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import topology.local_homeomorph
/-!
# Fiber bundles
A topological fiber bundle with fiber F over a base B is a space projecting on B for which the
fibers are all homeomorphic to F, such that the local situation around each point is a direct
product. We define a predicate `is_topological_fiber_bundle F p` saying that `p : Z → B` is a
topological fiber bundle with fiber `F`.
It is in general nontrivial to construct a fiber bundle. A way is to start from the knowledge of
how changes of local trivializations act on the fiber. From this, one can construct the total space
of the bundle and its topology by a suitable gluing construction. The main content of this file is
an implementation of this construction: starting from an object of type
`topological_fiber_bundle_core` registering the trivialization changes, one gets the corresponding
fiber bundle and projection.
## Main definitions
`bundle_trivialization F p` : structure extending local homeomorphisms, defining a local
trivialization of a topological space `Z` with projection `p` and fiber `F`.
`is_topological_fiber_bundle F p` : Prop saying that the map `p` between topological spaces is a
fiber bundle with fiber `F`.
`topological_fiber_bundle_core ι B F` : structure registering how changes of coordinates act on the
fiber `F` above open subsets of `B`, where local trivializations are indexed by ι.
Let `Z : topological_fiber_bundle_core ι B F`. Then we define
`Z.total_space` : the total space of `Z`, defined as a Type as `B × F`, but with a twisted topology
coming from the fiber bundle structure
`Z.proj` : projection from `Z.total_space` to `B`. It is continuous.
`Z.fiber x` : the fiber above `x`, homeomorphic to `F` (and defeq to `F` as a type).
`Z.local_triv i`: for `i : ι`, a local homeomorphism from `Z.total_space` to `B × F`, that realizes
a trivialization above the set `Z.base_set i`, which is an open set in `B`.
## Implementation notes
A topological fiber bundle with fiber F over a base B is a family of spaces isomorphic to F,
indexed by B, which is locally trivial in the following sense: there is a covering of B by open
sets such that, on each such open set `s`, the bundle is isomorphic to `s × F`.
To construct a fiber bundle formally, the main data is what happens when one changes trivializations
from `s × F` to `s' × F` on `s ∩ s'`: one should get a family of homeomorphisms of `F`, depending
continuously on the base point, satisfying basic compatibility conditions (cocycle property).
Useful classes of bundles can then be specified by requiring that these homeomorphisms of `F`
belong to some subgroup, preserving some structure (the "structure group of the bundle"): then
these structures are inherited by the fibers of the bundle.
Given such trivialization change data (encoded below in a structure called
`topological_fiber_bundle_core`), one can construct the fiber bundle. The intrinsic canonical
mathematical construction is the following.
The fiber above x is the disjoint union of F over all trivializations, modulo the gluing
identifications: one gets a fiber which is isomorphic to F, but non-canonically
(each choice of one of the trivializations around x gives such an isomorphism). Given a
trivialization over a set `s`, one gets an isomorphism between `s × F` and `proj^{-1} s`, by using
the identification corresponding to this trivialization. One chooses the topology on the bundle that
makes all of these into homeomorphisms.
For the practical implementation, it turns out to be more convenient to avoid completely the
gluing and quotienting construction above, and to declare above each `x` that the fiber is `F`,
but thinking that it corresponds to the `F` coming from the choice of one trivialization around `x`.
This has several practical advantages:
* without any work, one gets a topological space structure on the fiber. And if `F` has more
structure it is inherited for free by the fiber.
* In the trivial situation of the trivial bundle where there is only one chart and one
trivialization, this construction gives the product space B × F with the product topology. In the
case of the tangent bundle of manifolds, this also implies that on vector spaces the derivative and
the manifold derivative are equal.
A drawback is that some silly constructions will typecheck: in the case of the tangent bundle, one
can add two vectors in different tangent spaces (as they both are elements of F from the point of
view of Lean). To solve this, one could mark the tangent space as irreducible, but then one would
lose the identification of the tangent space to F with F. There is however a big advantage of this
situation: even if Lean can not check that two basepoints are defeq, it will accept the fact that
the tangent spaces are the same. For instance, if two maps f and g are locally inverse to each
other, one can express that the composition of their derivatives is the identity of
`tangent_space I x`. One could fear issues as this composition goes from `tangent_space I x` to
`tangent_space I (g (f x))` (which should be the same, but should not be obvious to Lean
as it does not know that `g (f x) = x`). As these types are the same to Lean (equal to `F`), there
are in fact no dependent type difficulties here!
For this construction of a fiber bundle from a `topological_fiber_bundle_core`, we should thus
choose for each `x` one specific trivialization around it. We include this choice in the definition
of the `topological_fiber_bundle_core`, as it makes some constructions more
functorial and it is a nice way to say that the trivializations cover the whole space B.
With this definition, the type of the fiber bundle space constructed from the core data is just
`B × F`, but the topology is not the product one.
We also take the indexing type (indexing all the trivializations) as a parameter to the fiber bundle
core: it could always be taken as a subtype of all the maps from open subsets of B to continuous
maps of F, but in practice it will sometimes be something else. For instance, on a manifold, one
will use the set of charts as a good parameterization for the trivializations of the tangent bundle.
Or for the pullback of a `topological_fiber_bundle_core`, the indexing type will be the same as
for the initial bundle.
## Tags
Fiber bundle, topological bundle, vector bundle, local trivialization, structure group
-/
variables {ι : Type*} {B : Type*} {F : Type*}
open topological_space set
open_locale topological_space
section topological_fiber_bundle
variables {Z : Type*} [topological_space B] [topological_space Z]
[topological_space F] (proj : Z → B)
variable (F)
/--
A structure extending local homeomorphisms, defining a local trivialization of a projection
`proj : Z → B` with fiber `F`, as a local homeomorphism between `Z` and `B × F` defined between two
sets of the form `proj ⁻¹' base_set` and `base_set × F`, acting trivially on the first coordinate.
-/
structure bundle_trivialization extends local_homeomorph Z (B × F) :=
(base_set : set B)
(open_base_set : is_open base_set)
(source_eq : source = proj ⁻¹' base_set)
(target_eq : target = set.prod base_set univ)
(proj_to_fun : ∀ p ∈ source, (to_fun p).1 = proj p)
/-- A topological fiber bundle with fiber F over a base B is a space projecting on B for which the
fibers are all homeomorphic to F, such that the local situation around each point is a direct
product. -/
def is_topological_fiber_bundle : Prop :=
∀ x : Z, ∃e : bundle_trivialization F proj, x ∈ e.source
variables {F} {proj}
/-- In the domain of a bundle trivialization, the projection is continuous-/
lemma bundle_trivialization.continuous_at_proj (e : bundle_trivialization F proj) {x : Z}
(ex : x ∈ e.source) : continuous_at proj x :=
begin
assume s hs,
obtain ⟨t, st, t_open, xt⟩ : ∃ t ⊆ s, is_open t ∧ proj x ∈ t,
from mem_nhds_sets_iff.1 hs,
rw e.source_eq at ex,
let u := e.base_set ∩ t,
have u_open : is_open u := is_open_inter e.open_base_set t_open,
have xu : proj x ∈ u := ⟨ex, xt⟩,
/- Take a small enough open neighborhood u of `proj x`, contained in a trivialization domain o.
One should show that its preimage is open. -/
suffices : is_open (proj ⁻¹' u),
{ have : proj ⁻¹' u ∈ 𝓝 x := mem_nhds_sets this xu,
apply filter.mem_sets_of_superset this,
exact preimage_mono (subset.trans (inter_subset_right _ _) st) },
-- to do this, rewrite `proj ⁻¹' u` in terms of the trivialization, and use its continuity.
have : proj ⁻¹' u = e.to_fun ⁻¹' (set.prod u univ) ∩ e.source,
{ ext p,
split,
{ assume h,
have : p ∈ e.source,
{ rw e.source_eq,
have : u ⊆ e.base_set := inter_subset_left _ _,
exact preimage_mono this h },
simp [this, e.proj_to_fun, h.1, h.2] },
{ rintros ⟨h, h_source⟩,
simpa [e.proj_to_fun, h_source] using h } },
rw [this, inter_comm],
exact continuous_on.preimage_open_of_open e.continuous_to_fun e.open_source
(is_open_prod u_open is_open_univ)
end
/-- The projection from a topological fiber bundle to its base is continuous. -/
lemma is_topological_fiber_bundle.continuous_proj (h : is_topological_fiber_bundle F proj) :
continuous proj :=
begin
rw continuous_iff_continuous_at,
assume x,
rcases h x with ⟨e, ex⟩,
exact e.continuous_at_proj ex
end
/-- The projection from a topological fiber bundle to its base is an open map. -/
lemma is_topological_fiber_bundle.is_open_map_proj (h : is_topological_fiber_bundle F proj) :
is_open_map proj :=
begin
assume s hs,
rw is_open_iff_forall_mem_open,
assume x xs,
obtain ⟨y, ys, yx⟩ : ∃ y, y ∈ s ∧ proj y = x, from (mem_image _ _ _).1 xs,
obtain ⟨e, he⟩ : ∃ (e : bundle_trivialization F proj), y ∈ e.source, from h y,
refine ⟨proj '' (s ∩ e.source), image_subset _ (inter_subset_left _ _), _, ⟨y, ⟨ys, he⟩, yx⟩⟩,
have : ∀z ∈ s ∩ e.source, prod.fst (e.to_fun z) = proj z := λz hz, e.proj_to_fun z hz.2,
rw [← image_congr this, image_comp],
have : is_open (e.to_fun '' (s ∩ e.source)) :=
e.to_local_homeomorph.image_open_of_open (is_open_inter hs e.to_local_homeomorph.open_source)
(inter_subset_right _ _),
exact is_open_map_fst _ this
end
/-- The first projection in a product is a topological fiber bundle. -/
lemma is_topological_fiber_bundle_fst : is_topological_fiber_bundle F (prod.fst : B × F → B) :=
begin
let F : bundle_trivialization F (prod.fst : B × F → B) :=
{ base_set := univ,
open_base_set := is_open_univ,
source_eq := rfl,
target_eq := by simp,
proj_to_fun := by simp,
..local_homeomorph.refl _ },
exact λx, ⟨F, by simp⟩
end
/-- The second projection in a product is a topological fiber bundle. -/
lemma is_topological_fiber_bundle_snd : is_topological_fiber_bundle F (prod.snd : F × B → B) :=
begin
let F : bundle_trivialization F (prod.snd : F × B → B) :=
{ base_set := univ,
open_base_set := is_open_univ,
source_eq := rfl,
target_eq := by simp,
proj_to_fun := λp, by { simp, refl },
..(homeomorph.prod_comm F B).to_local_homeomorph },
exact λx, ⟨F, by simp⟩
end
end topological_fiber_bundle
/-- Core data defining a locally trivial topological bundle with fiber `F` over a topological
space `B`. Note that "bundle" is used in its mathematical sense. This is the (computer science)
bundled version, i.e., all the relevant data is contained in the following structure. A family of
local trivializations is indexed by a type ι, on open subsets `base_set i` for each `i : ι`.
Trivialization changes from `i` to `j` are given by continuous maps `coord_change i j` from
`base_set i ∩ base_set j` to the set of homeomorphisms of `F`, but we express them as maps
`B → F → F` and require continuity on `(base_set i ∩ base_set j) × F` to avoid the topology on the
space of continuous maps on `F`. -/
structure topological_fiber_bundle_core (ι : Type*) (B : Type*) [topological_space B]
(F : Type*) [topological_space F] :=
(base_set : ι → set B)
(is_open_base_set : ∀i, is_open (base_set i))
(index_at : B → ι)
(mem_base_set_at : ∀x, x ∈ base_set (index_at x))
(coord_change : ι → ι → B → F → F)
(coord_change_self : ∀i, ∀ x ∈ base_set i, ∀v, coord_change i i x v = v)
(coord_change_continuous : ∀i j, continuous_on (λp : B × F, coord_change i j p.1 p.2)
(set.prod ((base_set i) ∩ (base_set j)) univ))
(coord_change_comp : ∀i j k, ∀x ∈ (base_set i) ∩ (base_set j) ∩ (base_set k), ∀v,
(coord_change j k x) (coord_change i j x v) = coord_change i k x v)
attribute [simp] topological_fiber_bundle_core.mem_base_set_at
namespace topological_fiber_bundle_core
variables [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F)
include Z
/-- The index set of a topological fiber bundle core, as a convenience function for dot notation -/
@[nolint] def index := ι
/-- The base space of a topological fiber bundle core, as a convenience function for dot notation -/
@[nolint] def base := B
/-- The fiber of a topological fiber bundle core, as a convenience function for dot notation and
typeclass inference -/
@[nolint] def fiber (x : B) := F
instance topological_space_fiber (x : B) : topological_space (Z.fiber x) :=
by { dsimp [fiber], apply_instance }
/-- Total space of a topological bundle created from core. It is equal to `B × F`, but as it is
not marked as reducible, typeclass inference will not infer the wrong topology, and will use the
instance `topological_fiber_bundle_core.to_topological_space` with the right topology. -/
@[nolint] def total_space := B × F
/-- The projection from the total space of a topological fiber bundle core, on its base. -/
@[simp] def proj : Z.total_space → B := λp, p.1
/-- Local homeomorphism version of the trivialization change. -/
def triv_change (i j : ι) : local_homeomorph (B × F) (B × F) :=
{ source := set.prod (Z.base_set i ∩ Z.base_set j) univ,
target := set.prod (Z.base_set i ∩ Z.base_set j) univ,
to_fun := λp, ⟨p.1, Z.coord_change i j p.1 p.2⟩,
inv_fun := λp, ⟨p.1, Z.coord_change j i p.1 p.2⟩,
map_source := λp hp, by simpa using hp,
map_target := λp hp, by simpa using hp,
left_inv := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, mem_inter_eq, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx.1 },
{ simp [hx] }
end,
right_inv := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, mem_inter_eq, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx.2 },
{ simp [hx] },
end,
open_source :=
is_open_prod (is_open_inter (Z.is_open_base_set i) (Z.is_open_base_set j)) is_open_univ,
open_target :=
is_open_prod (is_open_inter (Z.is_open_base_set i) (Z.is_open_base_set j)) is_open_univ,
continuous_to_fun :=
continuous_on.prod continuous_fst.continuous_on (Z.coord_change_continuous i j),
continuous_inv_fun := by simpa [inter_comm]
using continuous_on.prod continuous_fst.continuous_on (Z.coord_change_continuous j i) }
@[simp] lemma mem_triv_change_source (i j : ι) (p : B × F) :
p ∈ (Z.triv_change i j).source ↔ p.1 ∈ Z.base_set i ∩ Z.base_set j :=
by { erw [mem_prod], simp }
/-- Associate to a trivialization index `i : ι` the corresponding trivialization, i.e., a bijection
between `proj ⁻¹ (base_set i)` and `base_set i × F`. As the fiber above `x` is `F` but read in the
chart with index `index_at x`, the trivialization in the fiber above x is by definition the
coordinate change from i to `index_at x`, so it depends on `x`.
The local trivialization will ultimately be a local homeomorphism. For now, we only introduce the
local equiv version, denoted with a prime. In further developments, avoid this auxiliary version,
and use Z.local_triv instead.
-/
def local_triv' (i : ι) : local_equiv Z.total_space (B × F) :=
{ source := Z.proj ⁻¹' (Z.base_set i),
target := set.prod (Z.base_set i) univ,
inv_fun := λp, ⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩,
to_fun := λp, ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩,
map_source := λp hp,
by simpa only [set.mem_preimage, and_true, set.mem_univ, set.prod_mk_mem_set_prod_eq] using hp,
map_target := λp hp,
by simpa only [set.mem_preimage, and_true, set.mem_univ, set.mem_prod] using hp,
left_inv := begin
rintros ⟨x, v⟩ hx,
change x ∈ Z.base_set i at hx,
dsimp,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact Z.mem_base_set_at _ },
{ simp [hx] }
end,
right_inv := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx },
{ simp [hx] }
end }
@[simp] lemma mem_local_triv'_source (i : ι) (p : Z.total_space) :
p ∈ (Z.local_triv' i).source ↔ p.1 ∈ Z.base_set i :=
by refl
@[simp] lemma mem_local_triv'_target (i : ι) (p : B × F) :
p ∈ (Z.local_triv' i).target ↔ p.1 ∈ Z.base_set i :=
by { erw [mem_prod], simp }
@[simp] lemma local_triv'_fst (i : ι) (p : Z.total_space) :
((Z.local_triv' i).to_fun p).1 = p.1 := rfl
@[simp] lemma local_triv'_inv_fst (i : ι) (p : B × F) :
((Z.local_triv' i).inv_fun p).1 = p.1 := rfl
/-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/
lemma local_triv'_trans (i j : ι) :
(Z.local_triv' i).symm.trans (Z.local_triv' j) ≈ (Z.triv_change i j).to_local_equiv :=
begin
split,
{ ext x, erw [mem_prod], simp [local_equiv.trans_source] },
{ rintros ⟨x, v⟩ hx,
simp only [triv_change, local_triv', local_equiv.symm, true_and, local_equiv.right_inv,
prod_mk_mem_set_prod_eq, local_equiv.trans_source, mem_inter_eq, and_true,
mem_univ, prod.mk.inj_iff, local_equiv.trans_apply, mem_preimage, proj,
local_equiv.left_inv] at hx ⊢,
simp [Z.coord_change_comp, hx] }
end
/-- Topological structure on the total space of a topological bundle created from core, designed so
that all the local trivialization are continuous. -/
instance to_topological_space : topological_space Z.total_space :=
topological_space.generate_from $ ⋃ (i : ι) (s : set (B × F)) (s_open : is_open s),
{(Z.local_triv' i).source ∩ (Z.local_triv' i).to_fun ⁻¹' s }
lemma open_source' (i : ι) : is_open (Z.local_triv' i).source :=
begin
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
refine ⟨i, set.prod (Z.base_set i) univ, is_open_prod (Z.is_open_base_set i) (is_open_univ), _⟩,
ext p,
simp [topological_fiber_bundle_core.local_triv'_fst,
topological_fiber_bundle_core.mem_local_triv'_source]
end
lemma open_target' (i : ι) : is_open (Z.local_triv' i).target :=
is_open_prod (Z.is_open_base_set i) (is_open_univ)
/-- Local trivialization of a topological bundle created from core, as a local homeomorphism. -/
def local_triv (i : ι) : local_homeomorph Z.total_space (B × F) :=
{ open_source := Z.open_source' i,
open_target := Z.open_target' i,
continuous_to_fun := begin
rw continuous_on_open_iff (Z.open_source' i),
assume s s_open,
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
exact ⟨i, s, s_open, rfl⟩
end,
continuous_inv_fun := begin
apply continuous_on_open_of_generate_from (Z.open_target' i),
assume t ht,
simp only [exists_prop, mem_Union, mem_singleton_iff] at ht,
obtain ⟨j, s, s_open, ts⟩ : ∃ j s,
is_open s ∧ t = (local_triv' Z j).source ∩ (local_triv' Z j).to_fun ⁻¹' s := ht,
rw ts,
simp only [local_equiv.right_inv, preimage_inter, local_equiv.left_inv],
let e := Z.local_triv' i,
let e' := Z.local_triv' j,
let f := e.symm.trans e',
have : is_open (f.source ∩ f.to_fun ⁻¹' s),
{ rw [local_equiv.eq_on_source_preimage (Z.local_triv'_trans i j)],
exact (continuous_on_open_iff (Z.triv_change i j).open_source).1
((Z.triv_change i j).continuous_to_fun) _ s_open },
convert this using 1,
dsimp [local_equiv.trans_source],
rw [← preimage_comp, inter_assoc]
end,
..Z.local_triv' i }
/- We will now state again the basic properties of the local trivializations, but without primes,
i.e., for the local homeomorphism instead of the local equiv. -/
@[simp] lemma mem_local_triv_source (i : ι) (p : Z.total_space) :
p ∈ (Z.local_triv i).source ↔ p.1 ∈ Z.base_set i :=
by refl
@[simp] lemma mem_local_triv_target (i : ι) (p : B × F) :
p ∈ (Z.local_triv i).target ↔ p.1 ∈ Z.base_set i :=
by { erw [mem_prod], simp }
@[simp] lemma local_triv_fst (i : ι) (p : Z.total_space) :
((Z.local_triv i).to_fun p).1 = p.1 := rfl
@[simp] lemma local_triv_symm_fst (i : ι) (p : B × F) :
((Z.local_triv i).inv_fun p).1 = p.1 := rfl
/-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/
lemma local_triv_trans (i j : ι) :
(Z.local_triv i).symm.trans (Z.local_triv j) ≈ Z.triv_change i j :=
Z.local_triv'_trans i j
/-- Extended version of the local trivialization of a fiber bundle constructed from core,
registering additionally in its type that it is a local bundle trivialization. -/
def local_triv_ext (i : ι) : bundle_trivialization F Z.proj :=
{ base_set := Z.base_set i,
open_base_set := Z.is_open_base_set i,
source_eq := rfl,
target_eq := rfl,
proj_to_fun := λp hp, by simp,
..Z.local_triv i }
/-- A topological fiber bundle constructed from core is indeed a topological fiber bundle. -/
theorem is_topological_fiber_bundle : is_topological_fiber_bundle F Z.proj :=
λx, ⟨Z.local_triv_ext (Z.index_at (Z.proj x)), by simp [local_triv_ext]⟩
/-- The projection on the base of a topological bundle created from core is continuous -/
lemma continuous_proj : continuous Z.proj :=
Z.is_topological_fiber_bundle.continuous_proj
/-- The projection on the base of a topological bundle created from core is an open map -/
lemma is_open_map_proj : is_open_map Z.proj :=
Z.is_topological_fiber_bundle.is_open_map_proj
/-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as
a local homeomorphism -/
def local_triv_at (p : Z.total_space) : local_homeomorph Z.total_space (B × F) :=
Z.local_triv (Z.index_at (Z.proj p))
@[simp] lemma mem_local_triv_at_source (p : Z.total_space) : p ∈ (Z.local_triv_at p).source :=
by simp [local_triv_at]
@[simp] lemma local_triv_at_fst (p q : Z.total_space) :
((Z.local_triv_at p).to_fun q).1 = q.1 := rfl
@[simp] lemma local_triv_at_symm_fst (p : Z.total_space) (q : B × F) :
((Z.local_triv_at p).inv_fun q).1 = q.1 := rfl
/-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as
a bundle trivialization -/
def local_triv_at_ext (p : Z.total_space) : bundle_trivialization F Z.proj :=
Z.local_triv_ext (Z.index_at (Z.proj p))
@[simp] lemma local_triv_at_ext_to_local_homeomorph (p : Z.total_space) :
(Z.local_triv_at_ext p).to_local_homeomorph = Z.local_triv_at p := rfl
end topological_fiber_bundle_core
|
e8f5a8f851772f45f83ece23d3a4d9d676c29aec
|
8b9f17008684d796c8022dab552e42f0cb6fb347
|
/library/algebra/ordered_group.lean
|
d64ababbfa39f126447bb1bccea8471285325b0b
|
[
"Apache-2.0"
] |
permissive
|
chubbymaggie/lean
|
0d06ae25f9dd396306fb02190e89422ea94afd7b
|
d2c7b5c31928c98f545b16420d37842c43b4ae9a
|
refs/heads/master
| 1,611,313,622,901
| 1,430,266,839,000
| 1,430,267,083,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 21,329
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: algebra.ordered_group
Authors: Jeremy Avigad
Partially ordered additive groups, modeled on Isabelle's library. We could refine the structures,
but we would have to declare more inheritance paths.
-/
import logic.eq data.unit data.sigma data.prod
import algebra.function algebra.binary
import algebra.group algebra.order
open eq eq.ops -- note: ⁻¹ will be overloaded
namespace algebra
variable {A : Type}
/- partially ordered monoids, such as the natural numbers -/
structure ordered_cancel_comm_monoid [class] (A : Type) extends add_comm_monoid A,
add_left_cancel_semigroup A, add_right_cancel_semigroup A, order_pair A :=
(add_le_add_left : ∀a b, le a b → ∀c, le (add c a) (add c b))
(le_of_add_le_add_left : ∀a b c, le (add a b) (add a c) → le b c)
section
variables [s : ordered_cancel_comm_monoid A]
variables {a b c d e : A}
include s
theorem add_le_add_left (H : a ≤ b) (c : A) : c + a ≤ c + b :=
!ordered_cancel_comm_monoid.add_le_add_left H c
theorem add_le_add_right (H : a ≤ b) (c : A) : a + c ≤ b + c :=
(add.comm c a) ▸ (add.comm c b) ▸ (add_le_add_left H c)
theorem add_le_add (Hab : a ≤ b) (Hcd : c ≤ d) : a + c ≤ b + d :=
le.trans (add_le_add_right Hab c) (add_le_add_left Hcd b)
theorem add_lt_add_left (H : a < b) (c : A) : c + a < c + b :=
have H1 : c + a ≤ c + b, from add_le_add_left (le_of_lt H) c,
have H2 : c + a ≠ c + b, from
take H3 : c + a = c + b,
have H4 : a = b, from add.left_cancel H3,
ne_of_lt H H4,
lt_of_le_of_ne H1 H2
theorem add_lt_add_right (H : a < b) (c : A) : a + c < b + c :=
begin
rewrite [add.comm, {b + _}add.comm],
exact (add_lt_add_left H c)
end
theorem le_add_of_nonneg_right (H : b ≥ 0) : a ≤ a + b :=
begin
have H1 : a + b ≥ a + 0, from add_le_add_left H a,
rewrite add_zero at H1,
exact H1
end
theorem le_add_of_nonneg_left (H : b ≥ 0) : a ≤ b + a :=
begin
have H1 : 0 + a ≤ b + a, from add_le_add_right H a,
rewrite zero_add at H1,
exact H1
end
theorem add_lt_add (Hab : a < b) (Hcd : c < d) : a + c < b + d :=
lt.trans (add_lt_add_right Hab c) (add_lt_add_left Hcd b)
theorem add_lt_add_of_le_of_lt (Hab : a ≤ b) (Hcd : c < d) : a + c < b + d :=
lt_of_le_of_lt (add_le_add_right Hab c) (add_lt_add_left Hcd b)
theorem add_lt_add_of_lt_of_le (Hab : a < b) (Hcd : c ≤ d) : a + c < b + d :=
lt_of_lt_of_le (add_lt_add_right Hab c) (add_le_add_left Hcd b)
theorem lt_add_of_pos_right (H : b > 0) : a < a + b := !add_zero ▸ add_lt_add_left H a
theorem lt_add_of_pos_left (H : b > 0) : a < b + a := !zero_add ▸ add_lt_add_right H a
-- here we start using le_of_add_le_add_left.
theorem le_of_add_le_add_left (H : a + b ≤ a + c) : b ≤ c :=
!ordered_cancel_comm_monoid.le_of_add_le_add_left H
theorem le_of_add_le_add_right (H : a + b ≤ c + b) : a ≤ c :=
le_of_add_le_add_left (show b + a ≤ b + c, begin rewrite [add.comm, {b + _}add.comm], exact H end)
theorem lt_of_add_lt_add_left (H : a + b < a + c) : b < c :=
have H1 : b ≤ c, from le_of_add_le_add_left (le_of_lt H),
have H2 : b ≠ c, from
assume H3 : b = c, lt.irrefl _ (H3 ▸ H),
lt_of_le_of_ne H1 H2
theorem lt_of_add_lt_add_right (H : a + b < c + b) : a < c :=
lt_of_add_lt_add_left ((add.comm a b) ▸ (add.comm c b) ▸ H)
theorem add_le_add_left_iff (a b c : A) : a + b ≤ a + c ↔ b ≤ c :=
iff.intro le_of_add_le_add_left (assume H, add_le_add_left H _)
theorem add_le_add_right_iff (a b c : A) : a + b ≤ c + b ↔ a ≤ c :=
iff.intro le_of_add_le_add_right (assume H, add_le_add_right H _)
theorem add_lt_add_left_iff (a b c : A) : a + b < a + c ↔ b < c :=
iff.intro lt_of_add_lt_add_left (assume H, add_lt_add_left H _)
theorem add_lt_add_right_iff (a b c : A) : a + b < c + b ↔ a < c :=
iff.intro lt_of_add_lt_add_right (assume H, add_lt_add_right H _)
-- here we start using properties of zero.
theorem add_nonneg (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a + b :=
!zero_add ▸ (add_le_add Ha Hb)
theorem add_pos (Ha : 0 < a) (Hb : 0 < b) : 0 < a + b :=
!zero_add ▸ (add_lt_add Ha Hb)
theorem add_pos_of_pos_of_nonneg (Ha : 0 < a) (Hb : 0 ≤ b) : 0 < a + b :=
!zero_add ▸ (add_lt_add_of_lt_of_le Ha Hb)
theorem add_pos_of_nonneg_of_pos (Ha : 0 ≤ a) (Hb : 0 < b) : 0 < a + b :=
!zero_add ▸ (add_lt_add_of_le_of_lt Ha Hb)
theorem add_nonpos (Ha : a ≤ 0) (Hb : b ≤ 0) : a + b ≤ 0 :=
!zero_add ▸ (add_le_add Ha Hb)
theorem add_neg (Ha : a < 0) (Hb : b < 0) : a + b < 0 :=
!zero_add ▸ (add_lt_add Ha Hb)
theorem add_neg_of_neg_of_nonpos (Ha : a < 0) (Hb : b ≤ 0) : a + b < 0 :=
!zero_add ▸ (add_lt_add_of_lt_of_le Ha Hb)
theorem add_neg_of_nonpos_of_neg (Ha : a ≤ 0) (Hb : b < 0) : a + b < 0 :=
!zero_add ▸ (add_lt_add_of_le_of_lt Ha Hb)
-- TODO: add nonpos version (will be easier with simplifier)
theorem add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg
(Ha : 0 ≤ a) (Hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 :=
iff.intro
(assume Hab : a + b = 0,
have Ha' : a ≤ 0, from
calc
a = a + 0 : by rewrite add_zero
... ≤ a + b : add_le_add_left Hb
... = 0 : Hab,
have Haz : a = 0, from le.antisymm Ha' Ha,
have Hb' : b ≤ 0, from
calc
b = 0 + b : by rewrite zero_add
... ≤ a + b : add_le_add_right Ha
... = 0 : Hab,
have Hbz : b = 0, from le.antisymm Hb' Hb,
and.intro Haz Hbz)
(assume Hab : a = 0 ∧ b = 0,
match Hab with
| and.intro Ha' Hb' := by rewrite [Ha', Hb', add_zero]
end)
theorem le_add_of_nonneg_of_le (Ha : 0 ≤ a) (Hbc : b ≤ c) : b ≤ a + c :=
!zero_add ▸ add_le_add Ha Hbc
theorem le_add_of_le_of_nonneg (Hbc : b ≤ c) (Ha : 0 ≤ a) : b ≤ c + a :=
!add_zero ▸ add_le_add Hbc Ha
theorem lt_add_of_pos_of_le (Ha : 0 < a) (Hbc : b ≤ c) : b < a + c :=
!zero_add ▸ add_lt_add_of_lt_of_le Ha Hbc
theorem lt_add_of_le_of_pos (Hbc : b ≤ c) (Ha : 0 < a) : b < c + a :=
!add_zero ▸ add_lt_add_of_le_of_lt Hbc Ha
theorem add_le_of_nonpos_of_le (Ha : a ≤ 0) (Hbc : b ≤ c) : a + b ≤ c :=
!zero_add ▸ add_le_add Ha Hbc
theorem add_le_of_le_of_nonpos (Hbc : b ≤ c) (Ha : a ≤ 0) : b + a ≤ c :=
!add_zero ▸ add_le_add Hbc Ha
theorem add_lt_of_neg_of_le (Ha : a < 0) (Hbc : b ≤ c) : a + b < c :=
!zero_add ▸ add_lt_add_of_lt_of_le Ha Hbc
theorem add_lt_of_le_of_neg (Hbc : b ≤ c) (Ha : a < 0) : b + a < c :=
!add_zero ▸ add_lt_add_of_le_of_lt Hbc Ha
theorem lt_add_of_nonneg_of_lt (Ha : 0 ≤ a) (Hbc : b < c) : b < a + c :=
!zero_add ▸ add_lt_add_of_le_of_lt Ha Hbc
theorem lt_add_of_lt_of_nonneg (Hbc : b < c) (Ha : 0 ≤ a) : b < c + a :=
!add_zero ▸ add_lt_add_of_lt_of_le Hbc Ha
theorem lt_add_of_pos_of_lt (Ha : 0 < a) (Hbc : b < c) : b < a + c :=
!zero_add ▸ add_lt_add Ha Hbc
theorem lt_add_of_lt_of_pos (Hbc : b < c) (Ha : 0 < a) : b < c + a :=
!add_zero ▸ add_lt_add Hbc Ha
theorem add_lt_of_nonpos_of_lt (Ha : a ≤ 0) (Hbc : b < c) : a + b < c :=
!zero_add ▸ add_lt_add_of_le_of_lt Ha Hbc
theorem add_lt_of_lt_of_nonpos (Hbc : b < c) (Ha : a ≤ 0) : b + a < c :=
!add_zero ▸ add_lt_add_of_lt_of_le Hbc Ha
theorem add_lt_of_neg_of_lt (Ha : a < 0) (Hbc : b < c) : a + b < c :=
!zero_add ▸ add_lt_add Ha Hbc
theorem add_lt_of_lt_of_neg (Hbc : b < c) (Ha : a < 0) : b + a < c :=
!add_zero ▸ add_lt_add Hbc Ha
end
-- TODO: add properties of max and min
/- partially ordered groups -/
structure ordered_comm_group [class] (A : Type) extends add_comm_group A, order_pair A :=
(add_le_add_left : ∀a b, le a b → ∀c, le (add c a) (add c b))
theorem ordered_comm_group.le_of_add_le_add_left [s : ordered_comm_group A] {a b c : A} (H : a + b ≤ a + c) : b ≤ c :=
assert H' : -a + (a + b) ≤ -a + (a + c), from ordered_comm_group.add_le_add_left _ _ H _,
by rewrite *neg_add_cancel_left at H'; exact H'
definition ordered_comm_group.to_ordered_cancel_comm_monoid [instance] [coercion] [reducible]
[s : ordered_comm_group A] : ordered_cancel_comm_monoid A :=
⦃ ordered_cancel_comm_monoid, s,
add_left_cancel := @add.left_cancel A s,
add_right_cancel := @add.right_cancel A s,
le_of_add_le_add_left := @ordered_comm_group.le_of_add_le_add_left A s ⦄
section
variables [s : ordered_comm_group A] (a b c d e : A)
include s
theorem neg_le_neg {a b : A} (H : a ≤ b) : -b ≤ -a :=
have H1 : 0 ≤ -a + b, from !add.left_inv ▸ !(add_le_add_left H),
!add_neg_cancel_right ▸ !zero_add ▸ add_le_add_right H1 (-b)
theorem le_of_neg_le_neg {a b : A} (H : -b ≤ -a) : a ≤ b :=
neg_neg a ▸ neg_neg b ▸ neg_le_neg H
theorem neg_le_neg_iff_le : -a ≤ -b ↔ b ≤ a :=
iff.intro le_of_neg_le_neg neg_le_neg
theorem nonneg_of_neg_nonpos {a : A} (H : -a ≤ 0) : 0 ≤ a :=
le_of_neg_le_neg (neg_zero⁻¹ ▸ H)
theorem neg_nonpos_of_nonneg {a : A} (H : 0 ≤ a) : -a ≤ 0 :=
neg_zero ▸ neg_le_neg H
theorem neg_nonpos_iff_nonneg : -a ≤ 0 ↔ 0 ≤ a :=
iff.intro nonneg_of_neg_nonpos neg_nonpos_of_nonneg
theorem nonpos_of_neg_nonneg {a : A} (H : 0 ≤ -a) : a ≤ 0 :=
le_of_neg_le_neg (neg_zero⁻¹ ▸ H)
theorem neg_nonneg_of_nonpos {a : A} (H : a ≤ 0) : 0 ≤ -a :=
neg_zero ▸ neg_le_neg H
theorem neg_nonneg_iff_nonpos : 0 ≤ -a ↔ a ≤ 0 :=
iff.intro nonpos_of_neg_nonneg neg_nonneg_of_nonpos
theorem neg_lt_neg {a b : A} (H : a < b) : -b < -a :=
have H1 : 0 < -a + b, from !add.left_inv ▸ !(add_lt_add_left H),
!add_neg_cancel_right ▸ !zero_add ▸ add_lt_add_right H1 (-b)
theorem lt_of_neg_lt_neg {a b : A} (H : -b < -a) : a < b :=
neg_neg a ▸ neg_neg b ▸ neg_lt_neg H
theorem neg_lt_neg_iff_lt : -a < -b ↔ b < a :=
iff.intro lt_of_neg_lt_neg neg_lt_neg
theorem pos_of_neg_neg {a : A} (H : -a < 0) : 0 < a :=
lt_of_neg_lt_neg (neg_zero⁻¹ ▸ H)
theorem neg_neg_of_pos {a : A} (H : 0 < a) : -a < 0 :=
neg_zero ▸ neg_lt_neg H
theorem neg_neg_iff_pos : -a < 0 ↔ 0 < a :=
iff.intro pos_of_neg_neg neg_neg_of_pos
theorem neg_of_neg_pos {a : A} (H : 0 < -a) : a < 0 :=
lt_of_neg_lt_neg (neg_zero⁻¹ ▸ H)
theorem neg_pos_of_neg {a : A} (H : a < 0) : 0 < -a :=
neg_zero ▸ neg_lt_neg H
theorem neg_pos_iff_neg : 0 < -a ↔ a < 0 :=
iff.intro neg_of_neg_pos neg_pos_of_neg
theorem le_neg_iff_le_neg : a ≤ -b ↔ b ≤ -a := !neg_neg ▸ !neg_le_neg_iff_le
theorem neg_le_iff_neg_le : -a ≤ b ↔ -b ≤ a := !neg_neg ▸ !neg_le_neg_iff_le
theorem lt_neg_iff_lt_neg : a < -b ↔ b < -a := !neg_neg ▸ !neg_lt_neg_iff_lt
theorem neg_lt_iff_neg_lt : -a < b ↔ -b < a := !neg_neg ▸ !neg_lt_neg_iff_lt
theorem sub_nonneg_iff_le : 0 ≤ a - b ↔ b ≤ a := !sub_self ▸ !add_le_add_right_iff
theorem sub_nonpos_iff_le : a - b ≤ 0 ↔ a ≤ b := !sub_self ▸ !add_le_add_right_iff
theorem sub_pos_iff_lt : 0 < a - b ↔ b < a := !sub_self ▸ !add_lt_add_right_iff
theorem sub_neg_iff_lt : a - b < 0 ↔ a < b := !sub_self ▸ !add_lt_add_right_iff
theorem add_le_iff_le_neg_add : a + b ≤ c ↔ b ≤ -a + c :=
have H: a + b ≤ c ↔ -a + (a + b) ≤ -a + c, from iff.symm (!add_le_add_left_iff),
!neg_add_cancel_left ▸ H
theorem add_le_iff_le_sub_left : a + b ≤ c ↔ b ≤ c - a :=
by rewrite [sub_eq_add_neg, {c+_}add.comm]; apply add_le_iff_le_neg_add
theorem add_le_iff_le_sub_right : a + b ≤ c ↔ a ≤ c - b :=
have H: a + b ≤ c ↔ a + b - b ≤ c - b, from iff.symm (!add_le_add_right_iff),
!add_neg_cancel_right ▸ H
theorem le_add_iff_neg_add_le : a ≤ b + c ↔ -b + a ≤ c :=
assert H: a ≤ b + c ↔ -b + a ≤ -b + (b + c), from iff.symm (!add_le_add_left_iff),
by rewrite neg_add_cancel_left at H; exact H
theorem le_add_iff_sub_left_le : a ≤ b + c ↔ a - b ≤ c :=
by rewrite [sub_eq_add_neg, {a+_}add.comm]; apply le_add_iff_neg_add_le
theorem le_add_iff_sub_right_le : a ≤ b + c ↔ a - c ≤ b :=
assert H: a ≤ b + c ↔ a - c ≤ b + c - c, from iff.symm (!add_le_add_right_iff),
by rewrite add_neg_cancel_right at H; exact H
theorem add_lt_iff_lt_neg_add_left : a + b < c ↔ b < -a + c :=
assert H: a + b < c ↔ -a + (a + b) < -a + c, from iff.symm (!add_lt_add_left_iff),
begin rewrite neg_add_cancel_left at H, exact H end
theorem add_lt_iff_lt_neg_add_right : a + b < c ↔ a < -b + c :=
by rewrite add.comm; apply add_lt_iff_lt_neg_add_left
theorem add_lt_iff_lt_sub_left : a + b < c ↔ b < c - a :=
begin
rewrite [sub_eq_add_neg, {c+_}add.comm],
apply add_lt_iff_lt_neg_add_left
end
theorem add_lt_add_iff_lt_sub_right : a + b < c ↔ a < c - b :=
assert H: a + b < c ↔ a + b - b < c - b, from iff.symm (!add_lt_add_right_iff),
by rewrite add_neg_cancel_right at H; exact H
theorem lt_add_iff_neg_add_lt_left : a < b + c ↔ -b + a < c :=
assert H: a < b + c ↔ -b + a < -b + (b + c), from iff.symm (!add_lt_add_left_iff),
by rewrite neg_add_cancel_left at H; exact H
theorem lt_add_iff_neg_add_lt_right : a < b + c ↔ -c + a < b :=
by rewrite add.comm; apply lt_add_iff_neg_add_lt_left
theorem lt_add_iff_sub_lt_left : a < b + c ↔ a - b < c :=
by rewrite [sub_eq_add_neg, {a + _}add.comm]; apply lt_add_iff_neg_add_lt_left
theorem lt_add_iff_sub_lt_right : a < b + c ↔ a - c < b :=
by rewrite add.comm; apply lt_add_iff_sub_lt_left
-- TODO: the Isabelle library has varations on a + b ≤ b ↔ a ≤ 0
theorem le_iff_le_of_sub_eq_sub {a b c d : A} (H : a - b = c - d) : a ≤ b ↔ c ≤ d :=
calc
a ≤ b ↔ a - b ≤ 0 : iff.symm (sub_nonpos_iff_le a b)
... = (c - d ≤ 0) : by rewrite H
... ↔ c ≤ d : sub_nonpos_iff_le c d
theorem lt_iff_lt_of_sub_eq_sub {a b c d : A} (H : a - b = c - d) : a < b ↔ c < d :=
calc
a < b ↔ a - b < 0 : iff.symm (sub_neg_iff_lt a b)
... = (c - d < 0) : by rewrite H
... ↔ c < d : sub_neg_iff_lt c d
theorem sub_le_sub_left {a b : A} (H : a ≤ b) (c : A) : c - b ≤ c - a :=
add_le_add_left (neg_le_neg H) c
theorem sub_le_sub_right {a b : A} (H : a ≤ b) (c : A) : a - c ≤ b - c := add_le_add_right H (-c)
theorem sub_le_sub {a b c d : A} (Hab : a ≤ b) (Hcd : c ≤ d) : a - d ≤ b - c :=
add_le_add Hab (neg_le_neg Hcd)
theorem sub_lt_sub_left {a b : A} (H : a < b) (c : A) : c - b < c - a :=
add_lt_add_left (neg_lt_neg H) c
theorem sub_lt_sub_right {a b : A} (H : a < b) (c : A) : a - c < b - c := add_lt_add_right H (-c)
theorem sub_lt_sub {a b c d : A} (Hab : a < b) (Hcd : c < d) : a - d < b - c :=
add_lt_add Hab (neg_lt_neg Hcd)
theorem sub_lt_sub_of_le_of_lt {a b c d : A} (Hab : a ≤ b) (Hcd : c < d) : a - d < b - c :=
add_lt_add_of_le_of_lt Hab (neg_lt_neg Hcd)
theorem sub_lt_sub_of_lt_of_le {a b c d : A} (Hab : a < b) (Hcd : c ≤ d) : a - d < b - c :=
add_lt_add_of_lt_of_le Hab (neg_le_neg Hcd)
theorem sub_le_self (a : A) {b : A} (H : b ≥ 0) : a - b ≤ a :=
calc
a - b = a + -b : rfl
... ≤ a + 0 : add_le_add_left (neg_nonpos_of_nonneg H)
... = a : by rewrite add_zero
theorem sub_lt_self (a : A) {b : A} (H : b > 0) : a - b < a :=
calc
a - b = a + -b : rfl
... < a + 0 : add_lt_add_left (neg_neg_of_pos H)
... = a : by rewrite add_zero
end
structure decidable_linear_ordered_comm_group [class] (A : Type)
extends ordered_comm_group A, decidable_linear_order A
section
variables [s : decidable_linear_ordered_comm_group A]
variables {a b c d e : A}
include s
theorem eq_zero_of_neg_eq (H : -a = a) : a = 0 :=
lt.by_cases
(assume H1 : a < 0,
have H2: a > 0, from H ▸ neg_pos_of_neg H1,
absurd H1 (lt.asymm H2))
(assume H1 : a = 0, H1)
(assume H1 : a > 0,
have H2: a < 0, from H ▸ neg_neg_of_pos H1,
absurd H1 (lt.asymm H2))
definition abs (a : A) : A := if 0 ≤ a then a else -a
theorem abs_of_nonneg (H : a ≥ 0) : abs a = a := if_pos H
theorem abs_of_pos (H : a > 0) : abs a = a := if_pos (le_of_lt H)
theorem abs_of_neg (H : a < 0) : abs a = -a := if_neg (not_le_of_lt H)
theorem abs_zero : abs 0 = 0 := abs_of_nonneg (le.refl _)
theorem abs_of_nonpos (H : a ≤ 0) : abs a = -a :=
decidable.by_cases
(assume H1 : a = 0, by rewrite [H1, abs_zero, neg_zero])
(assume H1 : a ≠ 0,
have H2 : a < 0, from lt_of_le_of_ne H H1,
abs_of_neg H2)
theorem abs_neg (a : A) : abs (-a) = abs a :=
or.elim (le.total 0 a)
(assume H1 : 0 ≤ a, by rewrite [abs_of_nonpos (neg_nonpos_of_nonneg H1), neg_neg, abs_of_nonneg H1])
(assume H1 : a ≤ 0, by rewrite [abs_of_nonneg (neg_nonneg_of_nonpos H1), abs_of_nonpos H1])
theorem abs_nonneg (a : A) : abs a ≥ 0 :=
or.elim (le.total 0 a)
(assume H : 0 ≤ a, by rewrite (abs_of_nonneg H); exact H)
(assume H : a ≤ 0,
calc
0 ≤ -a : neg_nonneg_of_nonpos H
... = abs a : abs_of_nonpos H)
theorem abs_abs (a : A) : abs (abs a) = abs a := abs_of_nonneg !abs_nonneg
theorem le_abs_self (a : A) : a ≤ abs a :=
or.elim (le.total 0 a)
(assume H : 0 ≤ a, abs_of_nonneg H ▸ !le.refl)
(assume H : a ≤ 0, le.trans H !abs_nonneg)
theorem neg_le_abs_self (a : A) : -a ≤ abs a :=
!abs_neg ▸ !le_abs_self
theorem eq_zero_of_abs_eq_zero (H : abs a = 0) : a = 0 :=
have H1 : a ≤ 0, from H ▸ le_abs_self a,
have H2 : -a ≤ 0, from H ▸ abs_neg a ▸ le_abs_self (-a),
le.antisymm H1 (nonneg_of_neg_nonpos H2)
theorem abs_eq_zero_iff_eq_zero (a : A) : abs a = 0 ↔ a = 0 :=
iff.intro eq_zero_of_abs_eq_zero (assume H, congr_arg abs H ⬝ !abs_zero)
theorem abs_pos_of_pos (H : a > 0) : abs a > 0 :=
by rewrite (abs_of_pos H); exact H
theorem abs_pos_of_neg (H : a < 0) : abs a > 0 :=
!abs_neg ▸ abs_pos_of_pos (neg_pos_of_neg H)
theorem abs_pos_of_ne_zero (H : a ≠ 0) : abs a > 0 :=
or.elim (lt_or_gt_of_ne H) abs_pos_of_neg abs_pos_of_pos
theorem abs_sub (a b : A) : abs (a - b) = abs (b - a) :=
by rewrite [-neg_sub, abs_neg]
theorem abs.by_cases {P : A → Prop} {a : A} (H1 : P a) (H2 : P (-a)) : P (abs a) :=
or.elim (le.total 0 a)
(assume H : 0 ≤ a, (abs_of_nonneg H)⁻¹ ▸ H1)
(assume H : a ≤ 0, (abs_of_nonpos H)⁻¹ ▸ H2)
theorem abs_le_of_le_of_neg_le (H1 : a ≤ b) (H2 : -a ≤ b) : abs a ≤ b :=
abs.by_cases H1 H2
theorem abs_lt_of_lt_of_neg_lt (H1 : a < b) (H2 : -a < b) : abs a < b :=
abs.by_cases H1 H2
-- the triangle inequality
section
private lemma aux1 {a b : A} (H1 : a + b ≥ 0) (H2 : a ≥ 0) : abs (a + b) ≤ abs a + abs b :=
decidable.by_cases
(assume H3 : b ≥ 0,
calc
abs (a + b) ≤ abs (a + b) : le.refl
... = a + b : by rewrite (abs_of_nonneg H1)
... = abs a + b : by rewrite (abs_of_nonneg H2)
... = abs a + abs b : by rewrite (abs_of_nonneg H3))
(assume H3 : ¬ b ≥ 0,
assert H4 : b ≤ 0, from le_of_lt (lt_of_not_le H3),
calc
abs (a + b) = a + b : by rewrite (abs_of_nonneg H1)
... = abs a + b : by rewrite (abs_of_nonneg H2)
... ≤ abs a + 0 : add_le_add_left H4
... ≤ abs a + -b : add_le_add_left (neg_nonneg_of_nonpos H4)
... = abs a + abs b : by rewrite (abs_of_nonpos H4))
private lemma aux2 {a b : A} (H1 : a + b ≥ 0) : abs (a + b) ≤ abs a + abs b :=
or.elim (le.total b 0)
(assume H2 : b ≤ 0,
have H3 : ¬ a < 0, from
assume H4 : a < 0,
have H5 : a + b < 0, from !add_zero ▸ add_lt_add_of_lt_of_le H4 H2,
not_lt_of_le H1 H5,
aux1 H1 (le_of_not_lt H3))
(assume H2 : 0 ≤ b,
begin
have H3 : abs (b + a) ≤ abs b + abs a,
begin
rewrite add.comm at H1,
exact (aux1 H1 H2)
end,
rewrite [add.comm, {abs a + _}add.comm],
exact H3
end)
theorem abs_add_le_abs_add_abs (a b : A) : abs (a + b) ≤ abs a + abs b :=
or.elim (le.total 0 (a + b))
(assume H2 : 0 ≤ a + b, aux2 H2)
(assume H2 : a + b ≤ 0,
assert H3 : -a + -b = -(a + b), by rewrite neg_add,
assert H4 : -(a + b) ≥ 0, from iff.mp' (neg_nonneg_iff_nonpos (a+b)) H2,
have H5 : -a + -b ≥ 0, begin rewrite -H3 at H4, exact H4 end,
calc
abs (a + b) = abs (-a + -b) : by rewrite [-abs_neg, neg_add]
... ≤ abs (-a) + abs (-b) : aux2 H5
... = abs a + abs b : by rewrite *abs_neg)
end
theorem abs_sub_abs_le_abs_sub (a b : A) : abs a - abs b ≤ abs (a - b) :=
have H1 : abs a - abs b + abs b ≤ abs (a - b) + abs b, from
calc
abs a - abs b + abs b = abs a : by rewrite sub_add_cancel
... = abs (a - b + b) : by rewrite sub_add_cancel
... ≤ abs (a - b) + abs b : abs_add_le_abs_add_abs,
algebra.le_of_add_le_add_right H1
end
end algebra
|
a408f45d8c15e19118950f397fcfe07cee8d5c90
|
87d5955e1100ba73f6b56149b659e85116fa215b
|
/group_theory/action.lean
|
bafeb082cd91d633c1bc57d39f435376036875d9
|
[
"Apache-2.0"
] |
permissive
|
avigad/leanproved
|
4d15a05f8544a67b9f589c5e656358e1485aef3c
|
3cf0f5dda3ace82f6b7cdc159528ce3ebaef159f
|
refs/heads/master
| 1,611,368,103,158
| 1,433,589,072,000
| 1,433,589,072,000
| 36,843,899
| 0
| 0
| null | 1,433,385,918,000
| 1,433,385,918,000
| null |
UTF-8
|
Lean
| false
| false
| 8,188
|
lean
|
/-
Copyright (c) 2015 Haitao Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Haitao Zhang
-/
import algebra.group data .extra .hom .perm .finsubg
namespace group
open finset algebra function
local attribute perm.f [coercion]
section def
variables {G S : Type}
variable [ambientG : group G]
include ambientG
variable [finS : fintype S]
include finS
variable [deceqS : decidable_eq S]
include deceqS
definition orbit (hom : G → perm S) (H : finset G) (a : S) : finset S :=
image (move_by a) (image hom H)
variable [deceqG : decidable_eq G]
include deceqG -- required by {x ∈ H |p x} filtering
definition moverset (hom : G → perm S) (H : finset G) (a b : S) : finset G :=
{f ∈ H | hom f a = b}
definition stab (hom : G → perm S) (H : finset G) (a : S) : finset G :=
{f ∈ H | hom f a = a}
end def
section orbit_stabilizer
variables {G S : Type}
variable [ambientG : group G]
include ambientG
variable [finS : fintype S]
include finS
variable [deceqS : decidable_eq S]
include deceqS
variable [deceqG : decidable_eq G]
include deceqG
-- these are already specified by stab hom H a
variables {hom : G → perm S} {H : finset G} {a : S}
variable [Hom : is_hom_class hom]
include Hom
lemma exists_of_orbit {b : S} : b ∈ orbit hom H a → ∃ h, h ∈ H ∧ hom h a = b :=
assume Pb,
obtain p (Pp₁ : p ∈ image hom H) (Pp₂ : move_by a p = b), from exists_of_mem_image Pb,
obtain h (Ph₁ : h ∈ H) (Ph₂ : hom h = p), from exists_of_mem_image Pp₁,
assert Phab : hom h a = b, from calc
hom h a = p a : Ph₂
... = b : Pp₂,
exists.intro h (and.intro Ph₁ Phab)
lemma stab_lmul {f g : G} : g ∈ stab hom H a → hom (f*g) a = hom f a :=
assume Pgstab,
assert Pg : hom g a = a, from of_mem_filter Pgstab, calc
hom (f*g) a = perm.f ((hom f) * (hom g)) a : is_hom hom
... = ((hom f) ∘ (hom g)) a : rfl
... = (hom f) a : Pg
lemma stab_subset : stab hom H a ⊆ H :=
begin
apply subset_of_forall, intro f Pfstab, apply mem_of_mem_filter Pfstab
end
lemma reverse_move {h g : G} : g ∈ moverset hom H a (hom h a) → hom (h⁻¹*g) a = a :=
assume Pg,
assert Pga : hom g a = hom h a, from of_mem_filter Pg, calc
hom (h⁻¹*g) a = perm.f ((hom h⁻¹) * (hom g)) a : is_hom hom
... = ((hom h⁻¹) ∘ hom g) a : rfl
... = ((hom h⁻¹) ∘ hom h) a : {Pga}
... = perm.f ((hom h⁻¹) * hom h) a : rfl
... = perm.f ((hom h)⁻¹ * hom h) a : hom_map_inv hom h
... = (1 : perm S) a : mul.left_inv (hom h)
... = a : rfl
lemma moverset_inj_on_orbit : set.inj_on (moverset hom H a) (ts (orbit hom H a)) :=
take b1 b2,
assume Pb1, obtain h1 Ph1₁ Ph1₂, from exists_of_orbit Pb1,
assert Ph1b1 : h1 ∈ moverset hom H a b1,
from mem_filter_of_mem Ph1₁ Ph1₂,
assume Psetb2 Pmeq, begin
subst b1,
rewrite Pmeq at Ph1b1,
apply of_mem_filter Ph1b1
end
variable [subgH : is_finsubg H]
include subgH
lemma subg_stab_of_move {h g : G} :
h ∈ H → g ∈ moverset hom H a (hom h a) → h⁻¹*g ∈ stab hom H a :=
assume Ph Pg,
assert Phinvg : h⁻¹*g ∈ H, from begin
apply finsubg_mul_closed H,
apply finsubg_has_inv H, assumption,
apply mem_of_mem_filter Pg
end,
mem_filter_of_mem Phinvg (reverse_move Pg)
lemma subg_stab_closed : finset_mul_closed_on (stab hom H a) :=
take f g, assume Pfstab, assert Pf : hom f a = a, from of_mem_filter Pfstab,
assume Pgstab,
assert Pfg : hom (f*g) a = a, from calc
hom (f*g) a = (hom f) a : stab_lmul Pgstab
... = a : Pf,
assert PfginH : (f*g) ∈ H,
from finsubg_mul_closed H f g (mem_of_mem_filter Pfstab) (mem_of_mem_filter Pgstab),
mem_filter_of_mem PfginH Pfg
lemma subg_stab_has_one : 1 ∈ stab hom H a :=
assert P : hom 1 a = a, from calc
hom 1 a = (1 : perm S) a : {hom_map_one hom}
... = a : rfl,
assert PoneinH : 1 ∈ H, from finsubg_has_one H,
mem_filter_of_mem PoneinH P
lemma subg_stab_has_inv : finset_has_inv (stab hom H a) :=
take f, assume Pfstab, assert Pf : hom f a = a, from of_mem_filter Pfstab,
assert Pfinv : hom f⁻¹ a = a, from calc
hom f⁻¹ a = hom f⁻¹ ((hom f) a) : Pf
... = perm.f ((hom f⁻¹) * (hom f)) a : rfl
... = hom (f⁻¹ * f) a : is_hom hom
... = hom 1 a : mul.left_inv
... = (1 : perm S) a : hom_map_one hom,
assert PfinvinH : f⁻¹ ∈ H, from finsubg_has_inv H f (mem_of_mem_filter Pfstab),
mem_filter_of_mem PfinvinH Pfinv
definition subg_stab_is_finsubg [instance] :
is_finsubg (stab hom H a) :=
is_finsubg.mk subg_stab_has_one subg_stab_closed subg_stab_has_inv
lemma subg_lcoset_eq_moverset {h : G} :
h ∈ H → fin_lcoset (stab hom H a) h = moverset hom H a (hom h a) :=
assume Ph, ext (take g, iff.intro
(assume Pl, obtain f (Pf₁ : f ∈ stab hom H a) (Pf₂ : h*f = g), from exists_of_mem_image Pl,
assert Pfstab : hom f a = a, from of_mem_filter Pf₁,
assert PginH : g ∈ H, begin
subst Pf₂,
apply finsubg_mul_closed H,
assumption,
apply mem_of_mem_filter Pf₁
end,
assert Pga : hom g a = hom h a, from calc
hom g a = hom (h*f) a : by subst g
... = hom h a : stab_lmul Pf₁,
mem_filter_of_mem PginH Pga)
(assume Pr, begin
rewrite [↑fin_lcoset, mem_image_iff],
existsi h⁻¹*g,
split,
exact subg_stab_of_move Ph Pr,
apply mul_inv_cancel_left
end))
lemma subg_moverset_of_orbit_is_lcoset_of_stab (b : S) :
b ∈ orbit hom H a → ∃ h, h ∈ H ∧ fin_lcoset (stab hom H a) h = moverset hom H a b :=
assume Porb,
obtain p (Pp₁ : p ∈ image hom H) (Pp₂ : move_by a p = b), from exists_of_mem_image Porb,
obtain h (Ph₁ : h ∈ H) (Ph₂ : hom h = p), from exists_of_mem_image Pp₁,
assert Phab : hom h a = b, from by subst p; assumption,
exists.intro h (and.intro Ph₁ (Phab ▸ subg_lcoset_eq_moverset Ph₁))
lemma subg_lcoset_of_stab_is_moverset_of_orbit (h : G) :
h ∈ H → ∃ b, b ∈ orbit hom H a ∧ moverset hom H a b = fin_lcoset (stab hom H a) h :=
assume Ph,
have Pha : (hom h a) ∈ orbit hom H a, by
apply mem_image_of_mem; apply mem_image_of_mem; exact Ph,
exists.intro (hom h a) (and.intro Pha (eq.symm (subg_lcoset_eq_moverset Ph)))
lemma subg_moversets_of_orbit_eq_stab_lcosets :
image (moverset hom H a) (orbit hom H a) = fin_lcosets (stab hom H a) H :=
ext (take s, iff.intro
(assume Pl, obtain b Pb₁ Pb₂, from exists_of_mem_image Pl,
obtain h Ph, from subg_moverset_of_orbit_is_lcoset_of_stab b Pb₁, begin
rewrite [↑fin_lcosets, mem_image_eq],
existsi h, subst Pb₂, assumption
end)
(assume Pr, obtain h Ph₁ Ph₂, from exists_of_mem_image Pr,
obtain b Pb, from @subg_lcoset_of_stab_is_moverset_of_orbit G S ambientG finS deceqS deceqG hom H a Hom subgH h Ph₁, begin
rewrite [mem_image_eq],
existsi b, subst Ph₂, assumption
end))
open nat
theorem orbit_stabilizer_theorem : card H = card (orbit hom H a) * card (stab hom H a) :=
calc card H = card (fin_lcosets (stab hom H a) H) * card (stab hom H a) : lagrange_theorem stab_subset
... = card (image (moverset hom H a) (orbit hom H a)) * card (stab hom H a) : subg_moversets_of_orbit_eq_stab_lcosets
... = card (orbit hom H a) * card (stab hom H a) : card_image_eq_of_inj_on moverset_inj_on_orbit
end orbit_stabilizer
end group
|
33bd6ec98c260af97bd8e67e7f62fd2189d95e75
|
1dd482be3f611941db7801003235dc84147ec60a
|
/src/data/equiv/algebra.lean
|
1d1475318407e31df148d81376ac761a99685be8
|
[
"Apache-2.0"
] |
permissive
|
sanderdahmen/mathlib
|
479039302bd66434bb5672c2a4cecf8d69981458
|
8f0eae75cd2d8b7a083cf935666fcce4565df076
|
refs/heads/master
| 1,587,491,322,775
| 1,549,672,060,000
| 1,549,672,060,000
| 169,748,224
| 0
| 0
|
Apache-2.0
| 1,549,636,694,000
| 1,549,636,694,000
| null |
UTF-8
|
Lean
| false
| false
| 14,441
|
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
-/
import data.equiv.basic data.polynomial linear_algebra.multivariate_polynomial
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
namespace equiv
section group
variables [group α]
protected def mul_left (a : α) : α ≃ α :=
{ to_fun := λx, a * x,
inv_fun := λx, a⁻¹ * x,
left_inv := assume x, show a⁻¹ * (a * x) = x, from inv_mul_cancel_left a x,
right_inv := assume x, show a * (a⁻¹ * x) = x, from mul_inv_cancel_left a x }
attribute [to_additive equiv.add_left._proof_1] equiv.mul_left._proof_1
attribute [to_additive equiv.add_left._proof_2] equiv.mul_left._proof_2
attribute [to_additive equiv.add_left] equiv.mul_left
protected def mul_right (a : α) : α ≃ α :=
{ to_fun := λx, x * a,
inv_fun := λx, x * a⁻¹,
left_inv := assume x, show (x * a) * a⁻¹ = x, from mul_inv_cancel_right x a,
right_inv := assume x, show (x * a⁻¹) * a = x, from inv_mul_cancel_right x a }
attribute [to_additive equiv.add_right._proof_1] equiv.mul_right._proof_1
attribute [to_additive equiv.add_right._proof_2] equiv.mul_right._proof_2
attribute [to_additive equiv.add_right] equiv.mul_right
protected def inv (α) [group α] : α ≃ α :=
{ to_fun := λa, a⁻¹,
inv_fun := λa, a⁻¹,
left_inv := assume a, inv_inv a,
right_inv := assume a, inv_inv a }
attribute [to_additive equiv.neg._proof_1] equiv.inv._proof_1
attribute [to_additive equiv.neg._proof_2] equiv.inv._proof_2
attribute [to_additive equiv.neg] equiv.inv
def units_equiv_ne_zero (α : Type*) [field α] : units α ≃ {a : α | a ≠ 0} :=
⟨λ a, ⟨a.1, units.ne_zero _⟩, λ a, units.mk0 _ a.2, λ ⟨_, _, _, _⟩, units.ext rfl, λ ⟨_, _⟩, rfl⟩
@[simp] lemma coe_units_equiv_ne_zero [field α] (a : units α) :
((units_equiv_ne_zero α a) : α) = a := rfl
end group
section instances
variables (e : α ≃ β)
protected def has_zero [has_zero β] : has_zero α := ⟨e.symm 0⟩
lemma zero_def [has_zero β] : @has_zero.zero _ (equiv.has_zero e) = e.symm 0 := rfl
protected def has_one [has_one β] : has_one α := ⟨e.symm 1⟩
lemma one_def [has_one β] : @has_one.one _ (equiv.has_one e) = e.symm 1 := rfl
protected def has_mul [has_mul β] : has_mul α := ⟨λ x y, e.symm (e x * e y)⟩
lemma mul_def [has_mul β] (x y : α) :
@has_mul.mul _ (equiv.has_mul e) x y = e.symm (e x * e y) := rfl
protected def has_add [has_add β] : has_add α := ⟨λ x y, e.symm (e x + e y)⟩
lemma add_def [has_add β] (x y : α) :
@has_add.add _ (equiv.has_add e) x y = e.symm (e x + e y) := rfl
protected def has_inv [has_inv β] : has_inv α := ⟨λ x, e.symm (e x)⁻¹⟩
lemma inv_def [has_inv β] (x : α) : @has_inv.inv _ (equiv.has_inv e) x = e.symm (e x)⁻¹ := rfl
protected def has_neg [has_neg β] : has_neg α := ⟨λ x, e.symm (-e x)⟩
lemma neg_def [has_neg β] (x : α) : @has_neg.neg _ (equiv.has_neg e) x = e.symm (-e x) := rfl
protected def semigroup [semigroup β] : semigroup α :=
{ mul_assoc := by simp [mul_def, mul_assoc],
..equiv.has_mul e }
protected def comm_semigroup [comm_semigroup β] : comm_semigroup α :=
{ mul_comm := by simp [mul_def, mul_comm],
..equiv.semigroup e }
protected def monoid [monoid β] : monoid α :=
{ one_mul := by simp [mul_def, one_def],
mul_one := by simp [mul_def, one_def],
..equiv.semigroup e,
..equiv.has_one e }
protected def comm_monoid [comm_monoid β] : comm_monoid α :=
{ ..equiv.comm_semigroup e,
..equiv.monoid e }
protected def group [group β] : group α :=
{ mul_left_inv := by simp [mul_def, inv_def, one_def],
..equiv.monoid e,
..equiv.has_inv e }
protected def comm_group [comm_group β] : comm_group α :=
{ ..equiv.group e,
..equiv.comm_semigroup e }
protected def add_semigroup [add_semigroup β] : add_semigroup α :=
@additive.add_semigroup _ (@equiv.semigroup _ _ e multiplicative.semigroup)
protected def add_comm_semigroup [add_comm_semigroup β] : add_comm_semigroup α :=
@additive.add_comm_semigroup _ (@equiv.comm_semigroup _ _ e multiplicative.comm_semigroup)
protected def add_monoid [add_monoid β] : add_monoid α :=
@additive.add_monoid _ (@equiv.monoid _ _ e multiplicative.monoid)
protected def add_comm_monoid [add_comm_monoid β] : add_comm_monoid α :=
@additive.add_comm_monoid _ (@equiv.comm_monoid _ _ e multiplicative.comm_monoid)
protected def add_group [add_group β] : add_group α :=
@additive.add_group _ (@equiv.group _ _ e multiplicative.group)
protected def add_comm_group [add_comm_group β] : add_comm_group α :=
@additive.add_comm_group _ (@equiv.comm_group _ _ e multiplicative.comm_group)
protected def semiring [semiring β] : semiring α :=
{ right_distrib := by simp [mul_def, add_def, add_mul],
left_distrib := by simp [mul_def, add_def, mul_add],
zero_mul := by simp [mul_def, zero_def],
mul_zero := by simp [mul_def, zero_def],
..equiv.has_zero e,
..equiv.has_mul e,
..equiv.has_add e,
..equiv.monoid e,
..equiv.add_comm_monoid e }
protected def comm_semiring [comm_semiring β] : comm_semiring α :=
{ ..equiv.semiring e,
..equiv.comm_monoid e }
protected def ring [ring β] : ring α :=
{ ..equiv.semiring e,
..equiv.add_comm_group e }
protected def comm_ring [comm_ring β] : comm_ring α :=
{ ..equiv.comm_monoid e,
..equiv.ring e }
protected def zero_ne_one_class [zero_ne_one_class β] : zero_ne_one_class α :=
{ zero_ne_one := by simp [zero_def, one_def],
..equiv.has_zero e,
..equiv.has_one e }
protected def nonzero_comm_ring [nonzero_comm_ring β] : nonzero_comm_ring α :=
{ ..equiv.zero_ne_one_class e,
..equiv.comm_ring e }
protected def domain [domain β] : domain α :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := by simp [mul_def, zero_def, equiv.eq_symm_apply],
..equiv.has_zero e,
..equiv.zero_ne_one_class e,
..equiv.has_mul e,
..equiv.ring e }
protected def integral_domain [integral_domain β] : integral_domain α :=
{ ..equiv.domain e,
..equiv.nonzero_comm_ring e }
protected def division_ring [division_ring β] : division_ring α :=
{ inv_mul_cancel := λ _,
by simp [mul_def, inv_def, zero_def, one_def, (equiv.symm_apply_eq _).symm];
exact inv_mul_cancel,
mul_inv_cancel := λ _,
by simp [mul_def, inv_def, zero_def, one_def, (equiv.symm_apply_eq _).symm];
exact mul_inv_cancel,
..equiv.has_zero e,
..equiv.has_one e,
..equiv.domain e,
..equiv.has_inv e }
protected def field [field β] : field α :=
{ ..equiv.integral_domain e,
..equiv.division_ring e }
protected def discrete_field [discrete_field β] : discrete_field α :=
{ has_decidable_eq := equiv.decidable_eq e,
inv_zero := by simp [mul_def, inv_def, zero_def],
..equiv.has_mul e,
..equiv.has_inv e,
..equiv.has_zero e,
..equiv.field e }
end instances
end equiv
structure ring_equiv (α β : Type*) [ring α] [ring β] extends α ≃ β :=
(hom : is_ring_hom to_fun)
infix ` ≃r `:50 := ring_equiv
namespace ring_equiv
variables [ring α] [ring β] [ring γ]
instance {e : α ≃r β} : is_ring_hom e.to_equiv := hom _
protected def refl (α : Type*) [ring α] : α ≃r α :=
{ hom := is_ring_hom.id, .. equiv.refl α }
protected def symm {α β : Type*} [ring α] [ring β] (e : α ≃r β) : β ≃r α :=
{ hom := ⟨(equiv.symm_apply_eq _).2 e.hom.1.symm,
λ x y, (equiv.symm_apply_eq _).2 $ show _ = e.to_equiv.to_fun _, by rw [e.2.2, e.1.4, e.1.4],
λ x y, (equiv.symm_apply_eq _).2 $ show _ = e.to_equiv.to_fun _, by rw [e.2.3, e.1.4, e.1.4]⟩,
.. e.to_equiv.symm }
protected def trans {α β γ : Type*} [ring α] [ring β] [ring γ]
(e₁ : α ≃r β) (e₂ : β ≃r γ) : α ≃r γ :=
{ hom := is_ring_hom.comp _ _, .. e₁.1.trans e₂.1 }
end ring_equiv
namespace mv_polynomial
variables (α) [comm_ring α]
variables [decidable_eq α] [decidable_eq β] [decidable_eq γ] [decidable_eq δ]
def pempty_ring_equiv : mv_polynomial pempty α ≃r α :=
{ to_fun := mv_polynomial.eval₂ id $ pempty.elim,
inv_fun := C,
left_inv := is_id _ (by apply_instance) (assume a, by rw [eval₂_C]; refl) (assume a, a.elim),
right_inv := λ r, eval₂_C _ _ _,
hom := eval₂.is_ring_hom _ _ }
def punit_ring_equiv : mv_polynomial punit α ≃r polynomial α :=
{ to_fun := eval₂ polynomial.C (λu:punit, polynomial.X),
inv_fun := polynomial.eval₂ mv_polynomial.C (X punit.star),
left_inv :=
begin
refine is_id _ _ _ _,
apply is_semiring_hom.comp (eval₂ polynomial.C (λu:punit, polynomial.X)) _; apply_instance,
{ assume a, rw [eval₂_C, polynomial.eval₂_C] },
{ rintros ⟨⟩, rw [eval₂_X, polynomial.eval₂_X] }
end,
right_inv := assume p, polynomial.induction_on p
(assume a, by rw [polynomial.eval₂_C, mv_polynomial.eval₂_C])
(assume p q hp hq, by rw [polynomial.eval₂_add, mv_polynomial.eval₂_add, hp, hq])
(assume p n hp,
by rw [polynomial.eval₂_mul, polynomial.eval₂_pow, polynomial.eval₂_X, polynomial.eval₂_C,
eval₂_mul, eval₂_C, eval₂_pow, eval₂_X]),
hom := eval₂.is_ring_hom _ _ }
def ring_equiv_of_equiv (e : β ≃ γ) : mv_polynomial β α ≃r mv_polynomial γ α :=
{ to_fun := rename e,
inv_fun := rename e.symm,
left_inv := λ p, by simp only [rename_rename, (∘), e.inverse_apply_apply]; exact rename_id p,
right_inv := λ p, by simp only [rename_rename, (∘), e.apply_inverse_apply]; exact rename_id p,
hom := rename.is_ring_hom e }
def ring_equiv_congr [comm_ring γ] (e : α ≃r γ) : mv_polynomial β α ≃r mv_polynomial β γ :=
{ to_fun := map e.to_fun,
inv_fun := map e.symm.to_fun,
left_inv := assume p,
have (e.symm.to_equiv.to_fun ∘ e.to_equiv.to_fun) = id,
{ ext a, exact e.to_equiv.inverse_apply_apply a },
by simp only [map_map, this, map_id],
right_inv := assume p,
have (e.to_equiv.to_fun ∘ e.symm.to_equiv.to_fun) = id,
{ ext a, exact e.to_equiv.apply_inverse_apply a },
by simp only [map_map, this, map_id],
hom := map.is_ring_hom e.to_fun }
section
variables (β γ δ)
instance ring_on_sum : ring (mv_polynomial (β ⊕ γ) α) := by apply_instance
instance ring_on_iter : ring (mv_polynomial β (mv_polynomial γ α)) := by apply_instance
def sum_to_iter : mv_polynomial (β ⊕ γ) α → mv_polynomial β (mv_polynomial γ α) :=
eval₂ (C ∘ C) (λbc, sum.rec_on bc X (C ∘ X))
instance is_semiring_hom_C_C :
is_semiring_hom (C ∘ C : α → mv_polynomial β (mv_polynomial γ α)) :=
@is_semiring_hom.comp _ _ _ _ C mv_polynomial.is_semiring_hom _ _ C mv_polynomial.is_semiring_hom
instance is_semiring_hom_sum_to_iter : is_semiring_hom (sum_to_iter α β γ) :=
eval₂.is_semiring_hom _ _
lemma sum_to_iter_C (a : α) : sum_to_iter α β γ (C a) = C (C a) :=
eval₂_C _ _ a
lemma sum_to_iter_Xl (b : β) : sum_to_iter α β γ (X (sum.inl b)) = X b :=
eval₂_X _ _ (sum.inl b)
lemma sum_to_iter_Xr (c : γ) : sum_to_iter α β γ (X (sum.inr c)) = C (X c) :=
eval₂_X _ _ (sum.inr c)
def iter_to_sum : mv_polynomial β (mv_polynomial γ α) → mv_polynomial (β ⊕ γ) α :=
eval₂ (eval₂ C (X ∘ sum.inr)) (X ∘ sum.inl)
section
instance is_semiring_hom_iter_to_sum : is_semiring_hom (iter_to_sum α β γ) :=
eval₂.is_semiring_hom _ _
end
lemma iter_to_sum_C_C (a : α) : iter_to_sum α β γ (C (C a)) = C a :=
eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _)
lemma iter_to_sum_X (b : β) : iter_to_sum α β γ (X b) = X (sum.inl b) :=
eval₂_X _ _ _
lemma iter_to_sum_C_X (c : γ) : iter_to_sum α β γ (C (X c)) = X (sum.inr c) :=
eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _)
def mv_polynomial_equiv_mv_polynomial [comm_ring δ]
(f : mv_polynomial β α → mv_polynomial γ δ) (hf : is_semiring_hom f)
(g : mv_polynomial γ δ → mv_polynomial β α) (hg : is_semiring_hom g)
(hfgC : ∀a, f (g (C a)) = C a)
(hfgX : ∀n, f (g (X n)) = X n)
(hgfC : ∀a, g (f (C a)) = C a)
(hgfX : ∀n, g (f (X n)) = X n) :
mv_polynomial β α ≃r mv_polynomial γ δ :=
{ to_fun := f, inv_fun := g,
left_inv := is_id _ (is_semiring_hom.comp _ _) hgfC hgfX,
right_inv := is_id _ (is_semiring_hom.comp _ _) hfgC hfgX,
hom := is_ring_hom.of_semiring f }
def sum_ring_equiv : mv_polynomial (β ⊕ γ) α ≃r mv_polynomial β (mv_polynomial γ α) :=
begin
apply @mv_polynomial_equiv_mv_polynomial α (β ⊕ γ) _ _ _ _ _ _ _ _
(sum_to_iter α β γ) _ (iter_to_sum α β γ) _,
{ assume p,
apply @hom_eq_hom _ _ _ _ _ _ _ _ _ _ _ _ _ p,
apply_instance,
{ apply @is_semiring_hom.comp _ _ _ _ _ _ _ _ _ _,
apply_instance,
apply @is_semiring_hom.comp _ _ _ _ _ _ _ _ _ _,
apply_instance,
{ apply @mv_polynomial.is_semiring_hom },
{ apply mv_polynomial.is_semiring_hom_iter_to_sum α β γ },
{ apply mv_polynomial.is_semiring_hom_sum_to_iter α β γ } },
{ apply mv_polynomial.is_semiring_hom },
{ assume a, rw [iter_to_sum_C_C α β γ, sum_to_iter_C α β γ] },
{ assume c, rw [iter_to_sum_C_X α β γ, sum_to_iter_Xr α β γ] } },
{ assume b, rw [iter_to_sum_X α β γ, sum_to_iter_Xl α β γ] },
{ assume a, rw [sum_to_iter_C α β γ, iter_to_sum_C_C α β γ] },
{ assume n, cases n with b c,
{ rw [sum_to_iter_Xl, iter_to_sum_X] },
{ rw [sum_to_iter_Xr, iter_to_sum_C_X] } },
{ apply mv_polynomial.is_semiring_hom_sum_to_iter α β γ },
{ apply mv_polynomial.is_semiring_hom_iter_to_sum α β γ }
end
instance option_ring : ring (mv_polynomial (option β) α) :=
mv_polynomial.ring
instance polynomial_ring : ring (polynomial (mv_polynomial β α)) :=
@comm_ring.to_ring _ polynomial.comm_ring
instance polynomial_ring2 : ring (mv_polynomial β (polynomial α)) :=
by apply_instance
def option_equiv_left : mv_polynomial (option β) α ≃r polynomial (mv_polynomial β α) :=
(ring_equiv_of_equiv α $ (equiv.option_equiv_sum_punit β).trans (equiv.sum_comm _ _)).trans $
(sum_ring_equiv α _ _).trans $
punit_ring_equiv _
def option_equiv_right : mv_polynomial (option β) α ≃r mv_polynomial β (polynomial α) :=
(ring_equiv_of_equiv α $ equiv.option_equiv_sum_punit.{0} β).trans $
(sum_ring_equiv α β unit).trans $
ring_equiv_congr (mv_polynomial unit α) (punit_ring_equiv α)
end
end mv_polynomial
|
92dfe4c46a0874b35e594c92a9999faca840f4d2
|
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
|
/src/category_theory/limits/cones.lean
|
0e6d9972821198e64f791857c3f5ca260f47becb
|
[
"Apache-2.0"
] |
permissive
|
johoelzl/mathlib
|
253f46daa30b644d011e8e119025b01ad69735c4
|
592e3c7a2dfbd5826919b4605559d35d4d75938f
|
refs/heads/master
| 1,625,657,216,488
| 1,551,374,946,000
| 1,551,374,946,000
| 98,915,829
| 0
| 0
|
Apache-2.0
| 1,522,917,267,000
| 1,501,524,499,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 10,550
|
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
import category_theory.natural_isomorphism
import category_theory.whiskering
import category_theory.const
import category_theory.opposites
import category_theory.yoneda
universes v u u' -- declare the `v`'s first; see `category_theory.category` for an explanation
open category_theory
variables {J : Type v} [small_category J]
variables {C : Type u} [𝒞 : category.{v} C]
include 𝒞
open category_theory
open category_theory.category
open category_theory.functor
namespace category_theory
namespace functor
variables {J C} (F : J ⥤ C)
/--
`F.cones` is the functor assigning to an object `X` the type of
natural transformations from the constant functor with value `X` to `F`.
An object representing this functor is a limit of `F`.
-/
def cones : Cᵒᵖ ⥤ Type v := (const J).op ⋙ (yoneda.obj F)
lemma cones_obj (X : Cᵒᵖ) : F.cones.obj X = ((const J).obj (unop X) ⟶ F) := rfl
@[simp] lemma cones_map_app {X₁ X₂ : Cᵒᵖ} (f : X₁ ⟶ X₂) (t : F.cones.obj X₁) (j : J) :
(F.cones.map f t).app j = f.unop ≫ t.app j := rfl
/--
`F.cocones` is the functor assigning to an object `X` the type of
natural transformations from `F` to the constant functor with value `X`.
An object corepresenting this functor is a colimit of `F`.
-/
def cocones : C ⥤ Type v := const J ⋙ coyoneda.obj (op F)
lemma cocones_obj (X : C) : F.cocones.obj X = (F ⟹ (const J).obj X) := rfl
@[simp] lemma cocones_map_app {X₁ X₂ : C} (f : X₁ ⟶ X₂) (t : F.cocones.obj X₁) (j : J) :
(F.cocones.map f t).app j = t.app j ≫ f := rfl
end functor
section
variables (J C)
def cones : (J ⥤ C) ⥤ (Cᵒᵖ ⥤ Type v) :=
{ obj := functor.cones,
map := λ F G f, whisker_left (const J).op (yoneda.map f) }
def cocones : (J ⥤ C)ᵒᵖ ⥤ (C ⥤ Type v) :=
{ obj := λ F, functor.cocones (unop F),
map := λ F G f, whisker_left (const J) (coyoneda.map f) }
variables {J C}
@[simp] lemma cones_obj (F : J ⥤ C) : (cones J C).obj F = F.cones := rfl
@[simp] lemma cones_map {F G : J ⥤ C} {f : F ⟶ G} :
(cones J C).map f = (whisker_left (const J).op (yoneda.map f)) := rfl
@[simp] lemma cocones_obj (F : (J ⥤ C)ᵒᵖ) : (cocones J C).obj F = (unop F).cocones := rfl
@[simp] lemma cocones_map {F G : (J ⥤ C)ᵒᵖ} {f : F ⟶ G} :
(cocones J C).map f = (whisker_left (const J) (coyoneda.map f)) := rfl
end
namespace limits
/--
A `c : cone F` is:
* an object `c.X` and
* a natural transformation `c.π : c.X ⟹ F` from the constant `c.X` functor to `F`.
`cone F` is equivalent, in the obvious way, to `Σ X, F.cones.obj X`.
-/
structure cone (F : J ⥤ C) :=
(X : C)
(π : (const J).obj X ⟹ F)
@[simp] lemma cone.w {F : J ⥤ C} (c : cone F) {j j' : J} (f : j ⟶ j') :
c.π.app j ≫ F.map f = c.π.app j' :=
by convert ←(c.π.naturality f).symm; apply id_comp
/--
A `c : cocone F` is
* an object `c.X` and
* a natural transformation `c.ι : F ⟹ c.X` from `F` to the constant `c.X` functor.
`cocone F` is equivalent, in the obvious way, to `Σ X, F.cocones.obj X`.
-/
structure cocone (F : J ⥤ C) :=
(X : C)
(ι : F ⟹ (const J).obj X)
@[simp] lemma cocone.w {F : J ⥤ C} (c : cocone F) {j j' : J} (f : j ⟶ j') :
F.map f ≫ c.ι.app j' = c.ι.app j :=
by convert ←(c.ι.naturality f); apply comp_id
variables {F : J ⥤ C}
namespace cone
@[simp] def extensions (c : cone F) : yoneda.obj c.X ⟶ F.cones :=
{ app := λ X f, ((const J).map f) ≫ c.π }
/-- A map to the vertex of a cone induces a cone by composition. -/
@[simp] def extend (c : cone F) {X : C} (f : X ⟶ c.X) : cone F :=
{ X := X,
π := c.extensions.app (op X) f }
def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cone F) : cone (E ⋙ F) :=
{ X := c.X,
π := whisker_left E c.π }
@[simp] lemma whisker_π_app (c : cone F) {K : Type v} [small_category K] (E : K ⥤ J) (k : K) :
(c.whisker E).π.app k = (c.π).app (E.obj k) := rfl
end cone
namespace cocone
@[simp] def extensions (c : cocone F) : coyoneda.obj (op c.X) ⟶ F.cocones :=
{ app := λ X f, c.ι ≫ ((const J).map f) }
/-- A map from the vertex of a cocone induces a cocone by composition. -/
@[simp] def extend (c : cocone F) {X : C} (f : c.X ⟶ X) : cocone F :=
{ X := X,
ι := c.extensions.app X f }
def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cocone F) : cocone (E ⋙ F) :=
{ X := c.X,
ι := whisker_left E c.ι }
@[simp] lemma whisker_ι_app (c : cocone F) {K : Type v} [small_category K] (E : K ⥤ J) (k : K) :
(c.whisker E).ι.app k = (c.ι).app (E.obj k) := rfl
end cocone
structure cone_morphism (A B : cone F) :=
(hom : A.X ⟶ B.X)
(w' : ∀ j : J, hom ≫ B.π.app j = A.π.app j . obviously)
restate_axiom cone_morphism.w'
attribute [simp] cone_morphism.w
@[extensionality] lemma cone_morphism.ext {A B : cone F} {f g : cone_morphism A B}
(w : f.hom = g.hom) : f = g :=
by cases f; cases g; simpa using w
instance cone.category : category.{v} (cone F) :=
{ hom := λ A B, cone_morphism A B,
comp := λ X Y Z f g,
{ hom := f.hom ≫ g.hom,
w' := by intro j; rw [assoc, g.w, f.w] },
id := λ B, { hom := 𝟙 B.X } }
namespace cones
@[simp] lemma id.hom (c : cone F) : (𝟙 c : cone_morphism c c).hom = 𝟙 (c.X) := rfl
@[simp] lemma comp.hom {c d e : cone F} (f : c ⟶ d) (g : d ⟶ e) :
(f ≫ g).hom = f.hom ≫ g.hom := rfl
/-- To give an isomorphism between cones, it suffices to give an
isomorphism between their vertices which commutes with the cone
maps. -/
@[extensionality] def ext {c c' : cone F}
(φ : c.X ≅ c'.X) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j) : c ≅ c' :=
{ hom := { hom := φ.hom },
inv := { hom := φ.inv, w' := λ j, φ.inv_comp_eq.mpr (w j) } }
def postcompose {G : J ⥤ C} (α : F ⟶ G) : cone F ⥤ cone G :=
{ obj := λ c, { X := c.X, π := c.π ⊟ α },
map := λ c₁ c₂ f, { hom := f.hom, w' :=
by intro; erw ← category.assoc; simp [-category.assoc] } }
@[simp] lemma postcompose_obj_X {G : J ⥤ C} (α : F ⟶ G) (c : cone F) :
((postcompose α).obj c).X = c.X := rfl
@[simp] lemma postcompose_obj_π {G : J ⥤ C} (α : F ⟶ G) (c : cone F) :
((postcompose α).obj c).π = c.π ⊟ α := rfl
@[simp] lemma postcompose_map_hom {G : J ⥤ C} (α : F ⟶ G) {c₁ c₂ : cone F} (f : c₁ ⟶ c₂):
((postcompose α).map f).hom = f.hom := rfl
def forget : cone F ⥤ C :=
{ obj := λ t, t.X, map := λ s t f, f.hom }
@[simp] lemma forget_obj {t : cone F} : forget.obj t = t.X := rfl
@[simp] lemma forget_map {s t : cone F} {f : s ⟶ t} : forget.map f = f.hom := rfl
section
variables {D : Type u'} [𝒟 : category.{v} D]
include 𝒟
@[simp] def functoriality (G : C ⥤ D) : cone F ⥤ cone (F ⋙ G) :=
{ obj := λ A,
{ X := G.obj A.X,
π := { app := λ j, G.map (A.π.app j), naturality' := by intros; erw ←G.map_comp; tidy } },
map := λ X Y f,
{ hom := G.map f.hom,
w' := by intros; rw [←functor.map_comp, f.w] } }
end
end cones
structure cocone_morphism (A B : cocone F) :=
(hom : A.X ⟶ B.X)
(w' : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j . obviously)
restate_axiom cocone_morphism.w'
attribute [simp] cocone_morphism.w
@[extensionality] lemma cocone_morphism.ext
{A B : cocone F} {f g : cocone_morphism A B} (w : f.hom = g.hom) : f = g :=
by cases f; cases g; simpa using w
instance cocone.category : category.{v} (cocone F) :=
{ hom := λ A B, cocone_morphism A B,
comp := λ _ _ _ f g,
{ hom := f.hom ≫ g.hom,
w' := by intro j; rw [←assoc, f.w, g.w] },
id := λ B, { hom := 𝟙 B.X } }
namespace cocones
@[simp] lemma id.hom (c : cocone F) : (𝟙 c : cocone_morphism c c).hom = 𝟙 (c.X) := rfl
@[simp] lemma comp.hom {c d e : cocone F} (f : c ⟶ d) (g : d ⟶ e) :
(f ≫ g).hom = f.hom ≫ g.hom := rfl
/-- To give an isomorphism between cocones, it suffices to give an
isomorphism between their vertices which commutes with the cocone
maps. -/
@[extensionality] def ext {c c' : cocone F}
(φ : c.X ≅ c'.X) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j) : c ≅ c' :=
{ hom := { hom := φ.hom },
inv := { hom := φ.inv, w' := λ j, φ.comp_inv_eq.mpr (w j).symm } }
def precompose {G : J ⥤ C} (α : G ⟶ F) : cocone F ⥤ cocone G :=
{ obj := λ c, { X := c.X, ι := α ⊟ c.ι },
map := λ c₁ c₂ f, { hom := f.hom } }
@[simp] lemma precompose_obj_X {G : J ⥤ C} (α : G ⟶ F) (c : cocone F) :
((precompose α).obj c).X = c.X := rfl
@[simp] lemma precompose_obj_ι {G : J ⥤ C} (α : G ⟶ F) (c : cocone F) :
((precompose α).obj c).ι = α ⊟ c.ι := rfl
@[simp] lemma precompose_map_hom {G : J ⥤ C} (α : G ⟶ F) {c₁ c₂ : cocone F} (f : c₁ ⟶ c₂) :
((precompose α).map f).hom = f.hom := rfl
def forget : cocone F ⥤ C :=
{ obj := λ t, t.X, map := λ s t f, f.hom }
@[simp] lemma forget_obj {t : cocone F} : forget.obj t = t.X := rfl
@[simp] lemma forget_map {s t : cocone F} {f : s ⟶ t} : forget.map f = f.hom := rfl
section
variables {D : Type u'} [𝒟 : category.{v} D]
include 𝒟
@[simp] def functoriality (G : C ⥤ D) : cocone F ⥤ cocone (F ⋙ G) :=
{ obj := λ A,
{ X := G.obj A.X,
ι := { app := λ j, G.map (A.ι.app j), naturality' := by intros; erw ←G.map_comp; tidy } },
map := λ _ _ f,
{ hom := G.map f.hom,
w' := by intros; rw [←functor.map_comp, cocone_morphism.w] } }
end
end cocones
end limits
namespace functor
variables {D : Type u'} [category.{v} D]
variables {F : J ⥤ C} {G : J ⥤ C} (H : C ⥤ D)
open category_theory.limits
/-- The image of a cone in C under a functor G : C ⥤ D is a cone in D. -/
def map_cone (c : cone F) : cone (F ⋙ H) := (cones.functoriality H).obj c
/-- The image of a cocone in C under a functor G : C ⥤ D is a cocone in D. -/
def map_cocone (c : cocone F) : cocone (F ⋙ H) := (cocones.functoriality H).obj c
def map_cone_morphism {c c' : cone F} (f : cone_morphism c c') :
cone_morphism (H.map_cone c) (H.map_cone c') := (cones.functoriality H).map f
def map_cocone_morphism {c c' : cocone F} (f : cocone_morphism c c') :
cocone_morphism (H.map_cocone c) (H.map_cocone c') := (cocones.functoriality H).map f
@[simp] lemma map_cone_π (c : cone F) (j : J) :
(map_cone H c).π.app j = H.map (c.π.app j) := rfl
@[simp] lemma map_cocone_ι (c : cocone F) (j : J) :
(map_cocone H c).ι.app j = H.map (c.ι.app j) := rfl
end functor
end category_theory
|
e675b6828c537b89f08962a78d1d30fff1beedce
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/stage0/src/Lean/Meta/IndPredBelow.lean
|
f88ce50193c0bd8624f817f328ee7b868923a819
|
[
"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
| 25,714
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dany Fabian
-/
import Lean.Meta.Constructions
import Lean.Meta.Transform
import Lean.Meta.Tactic
import Lean.Meta.Match.Match
import Lean.Meta.Reduce
namespace Lean.Meta.IndPredBelow
open Match
register_builtin_option maxBackwardChainingDepth : Nat := {
defValue := 10
descr := "The maximum search depth used in the backwards chaining part of the proof of `brecOn` for inductive predicates."
}
/--
The context used in the creation of the `below` scheme for inductive predicates.
-/
structure Context where
motives : Array (Name × Expr)
typeInfos : Array InductiveVal
belowNames : Array Name
headers : Array Expr
numParams : Nat
/--
Collection of variables used to keep track of the positions of binders in the construction
of `below` motives and constructors.
-/
structure Variables where
target : Array Expr
indVal : Array Expr
params : Array Expr
args : Array Expr
motives : Array Expr
innerType : Expr
deriving Inhabited
/--
Collection of variables used to keep track of the local context used in the `brecOn` proof.
-/
structure BrecOnVariables where
params : Array FVarId
motives : Array FVarId
indices : Array FVarId
witness : FVarId
indHyps : Array FVarId
def mkContext (declName : Name) : MetaM Context := do
let indVal ← getConstInfoInduct declName
let typeInfos ← indVal.all.toArray.mapM getConstInfoInduct
let motiveTypes ← typeInfos.mapM motiveType
let motives ← motiveTypes.mapIdxM fun j motive =>
return (← motiveName motiveTypes j.val, motive)
let headers ← typeInfos.mapM $ mkHeader motives indVal.numParams
return {
motives := motives
typeInfos := typeInfos
numParams := indVal.numParams
headers := headers
belowNames := indVal.all.toArray.map (· ++ `below)
}
where
motiveName (motiveTypes : Array Expr) (i : Nat) : MetaM Name :=
if motiveTypes.size > 1
then mkFreshUserName s!"motive_{i.succ}"
else mkFreshUserName "motive"
mkHeader
(motives : Array (Name × Expr))
(numParams : Nat)
(indVal : InductiveVal) : MetaM Expr := do
let header ← forallTelescopeReducing indVal.type fun xs t => do
withNewBinderInfos (xs.map fun x => (x.fvarId!, BinderInfo.implicit)) $
mkForallFVars xs (← mkArrow (mkAppN (mkIndValConst indVal) xs) t)
addMotives motives numParams header
addMotives (motives : Array (Name × Expr)) (numParams : Nat) : Expr → MetaM Expr :=
motives.foldrM (fun (motiveName, motive) t =>
forallTelescopeReducing t fun xs s => do
let motiveType ← instantiateForall motive xs[:numParams]
withLocalDecl motiveName BinderInfo.implicit motiveType fun motive => do
mkForallFVars (xs.insertAt numParams motive) s)
motiveType (indVal : InductiveVal) : MetaM Expr :=
forallTelescopeReducing indVal.type fun xs _ => do
mkForallFVars xs (← mkArrow (mkAppN (mkIndValConst indVal) xs) (mkSort levelZero))
mkIndValConst (indVal : InductiveVal) : Expr :=
mkConst indVal.name $ indVal.levelParams.map mkLevelParam
partial def mkCtorType
(ctx : Context)
(belowIdx : Nat)
(originalCtor : ConstructorVal) : MetaM Expr :=
forallTelescopeReducing originalCtor.type fun xs t => addHeaderVars
{ innerType := t
indVal := #[]
motives := #[]
params := xs[:ctx.numParams]
args := xs[ctx.numParams:]
target := xs[:ctx.numParams] }
where
addHeaderVars (vars : Variables) := do
let headersWithNames ← ctx.headers.mapIdxM fun idx header =>
return (ctx.belowNames[idx]!, fun _ : Array Expr => pure header)
withLocalDeclsD headersWithNames fun xs =>
addMotives { vars with indVal := xs }
addMotives (vars : Variables) := do
let motiveBuilders ← ctx.motives.mapM fun (motiveName, motiveType) =>
return (motiveName, BinderInfo.implicit, fun _ : Array Expr =>
instantiateForall motiveType vars.params)
withLocalDecls motiveBuilders fun xs =>
modifyBinders { vars with target := vars.target ++ xs, motives := xs } 0
modifyBinders (vars : Variables) (i : Nat) := do
if i < vars.args.size then
let binder := vars.args[i]!
let binderType ← inferType binder
if (← checkCount binderType) then
mkBelowBinder vars binder binderType fun indValIdx x =>
mkMotiveBinder vars indValIdx binder binderType fun y =>
withNewBinderInfos #[(binder.fvarId!, BinderInfo.implicit)] do
modifyBinders { vars with target := vars.target ++ #[binder, x, y]} i.succ
else modifyBinders { vars with target := vars.target.push binder } i.succ
else rebuild vars
rebuild (vars : Variables) :=
vars.innerType.withApp fun _ args => do
let hApp :=
mkAppN
(mkConst originalCtor.name $ ctx.typeInfos[0]!.levelParams.map mkLevelParam)
(vars.params ++ vars.args)
let innerType := mkAppN vars.indVal[belowIdx]! $
vars.params ++ vars.motives ++ args[ctx.numParams:] ++ #[hApp]
let x ← mkForallFVars vars.target innerType
return replaceTempVars vars x
replaceTempVars (vars : Variables) (ctor : Expr) :=
let levelParams :=
ctx.typeInfos[0]!.levelParams.map mkLevelParam
ctor.replaceFVars vars.indVal $ ctx.belowNames.map fun indVal =>
mkConst indVal levelParams
checkCount (domain : Expr) : MetaM Bool := do
let run (x : StateRefT Nat MetaM Expr) : MetaM (Expr × Nat) := StateRefT'.run x 0
let (_, cnt) ← run <| transform domain fun e => do
if let some name := e.constName? then
if let some _ := ctx.typeInfos.findIdx? fun indVal => indVal.name == name then
modify (· + 1)
return TransformStep.visit e
if cnt > 1 then
throwError "only arrows are allowed as premises. Multiple recursive occurrences detected:{indentExpr domain}"
return cnt == 1
mkBelowBinder
(vars : Variables)
(binder : Expr)
(domain : Expr)
{α : Type} (k : Nat → Expr → MetaM α) : MetaM α := do
forallTelescopeReducing domain fun xs t => do
let fail _ := do
throwError "only trivial inductive applications supported in premises:{indentExpr t}"
t.withApp fun f args => do
if let some name := f.constName? then
if let some idx := ctx.typeInfos.findIdx?
fun indVal => indVal.name == name then
let hApp := mkAppN binder xs
let t :=
mkAppN vars.indVal[idx]! $
vars.params ++ vars.motives ++ args[ctx.numParams:] ++ #[hApp]
let newDomain ← mkForallFVars xs t
withLocalDecl (←copyVarName binder.fvarId!) binder.binderInfo newDomain (k idx)
else fail ()
else fail ()
mkMotiveBinder
(vars : Variables)
(indValIdx : Nat)
(binder : Expr)
(domain : Expr)
{α : Type} (k : Expr → MetaM α) : MetaM α := do
forallTelescopeReducing domain fun xs t => do
t.withApp fun _ args => do
let hApp := mkAppN binder xs
let t := mkAppN vars.motives[indValIdx]! $ args[ctx.numParams:] ++ #[hApp]
let newDomain ← mkForallFVars xs t
withLocalDecl (←copyVarName binder.fvarId!) binder.binderInfo newDomain k
copyVarName (oldName : FVarId) : MetaM Name := do
let binderDecl ← oldName.getDecl
mkFreshUserName binderDecl.userName
def mkConstructor (ctx : Context) (i : Nat) (ctor : Name) : MetaM Constructor := do
let ctorInfo ← getConstInfoCtor ctor
let name := ctor.updatePrefix ctx.belowNames[i]!
let type ← mkCtorType ctx i ctorInfo
return {
name := name
type := type }
def mkInductiveType
(ctx : Context)
(i : Fin ctx.typeInfos.size)
(indVal : InductiveVal) : MetaM InductiveType := do
return {
name := ctx.belowNames[i]!
type := ctx.headers[i]!
ctors := (← indVal.ctors.mapM (mkConstructor ctx i))
}
def mkBelowDecl (ctx : Context) : MetaM Declaration := do
let lparams := ctx.typeInfos[0]!.levelParams
return Declaration.inductDecl
lparams
(ctx.numParams + ctx.motives.size)
(←ctx.typeInfos.mapIdxM $ mkInductiveType ctx).toList
ctx.typeInfos[0]!.isUnsafe
partial def backwardsChaining (m : MVarId) (depth : Nat) : MetaM Bool := do
if depth = 0 then return false
else
m.withContext do
let lctx ← getLCtx
let mTy ← m.getType
lctx.anyM fun localDecl =>
if localDecl.isAuxDecl then
return false
else
commitWhen do
let (mvars, _, t) ← forallMetaTelescope localDecl.type
if ←isDefEq mTy t then
m.assign (mkAppN localDecl.toExpr mvars)
mvars.allM fun v =>
v.mvarId!.isAssigned <||> backwardsChaining v.mvarId! (depth - 1)
else return false
partial def proveBrecOn (ctx : Context) (indVal : InductiveVal) (type : Expr) : MetaM Expr := do
let main ← mkFreshExprSyntheticOpaqueMVar type
let (m, vars) ← intros main.mvarId!
let [m] ← applyIH m vars |
throwError "applying the induction hypothesis should only return one goal"
let ms ← induction m vars
let ms ← applyCtors ms
let maxDepth := maxBackwardChainingDepth.get $ ←getOptions
ms.forM (closeGoal maxDepth)
instantiateMVars main
where
intros (m : MVarId) : MetaM (MVarId × BrecOnVariables) := do
let (params, m) ← m.introNP indVal.numParams
let (motives, m) ← m.introNP ctx.motives.size
let (indices, m) ← m.introNP indVal.numIndices
let (witness, m) ← m.intro1P
let (indHyps, m) ← m.introNP ctx.motives.size
return (m, ⟨params, motives, indices, witness, indHyps⟩)
applyIH (m : MVarId) (vars : BrecOnVariables) : MetaM (List MVarId) := do
match (← vars.indHyps.findSomeM?
fun ih => do try pure <| some <| (← m.apply <| mkFVar ih) catch _ => pure none) with
| some goals => pure goals
| none => throwError "cannot apply induction hypothesis: {MessageData.ofGoal m}"
induction (m : MVarId) (vars : BrecOnVariables) : MetaM (List MVarId) := do
let params := vars.params.map mkFVar
let motives := vars.motives.map mkFVar
let levelParams := indVal.levelParams.map mkLevelParam
let motives ← ctx.motives.mapIdxM fun idx (_, motive) => do
let motive ← instantiateForall motive params
forallTelescopeReducing motive fun xs _ => do
mkLambdaFVars xs <| mkAppN (mkConst ctx.belowNames[idx]! levelParams) $ (params ++ motives ++ xs)
let recursorInfo ← getConstInfo $ mkRecName indVal.name
let recLevels :=
if recursorInfo.numLevelParams > levelParams.length
then levelZero::levelParams
else levelParams
let recursor := mkAppN (mkConst recursorInfo.name $ recLevels) $ params ++ motives
m.apply recursor
applyCtors (ms : List MVarId) : MetaM $ List MVarId := do
let mss ← ms.toArray.mapIdxM fun _ m => do
let m ← introNPRec m
(← m.getType).withApp fun below args =>
m.withContext do
args.back.withApp fun ctor _ => do
let ctorName := ctor.constName!.updatePrefix below.constName!
let ctor := mkConst ctorName below.constLevels!
let ctorInfo ← getConstInfoCtor ctorName
let (mvars, _, _) ← forallMetaTelescope ctorInfo.type
let ctor := mkAppN ctor mvars
m.apply ctor
return mss.foldr List.append []
introNPRec (m : MVarId) : MetaM MVarId := do
if (← m.getType).isForall then introNPRec (← m.intro1P).2 else return m
closeGoal (maxDepth : Nat) (m : MVarId) : MetaM Unit := do
unless (← m.isAssigned) do
let m ← introNPRec m
unless (← backwardsChaining m maxDepth) do
m.withContext do
throwError "couldn't solve by backwards chaining ({``maxBackwardChainingDepth} = {maxDepth}): {MessageData.ofGoal m}"
def mkBrecOnDecl (ctx : Context) (idx : Nat) : MetaM Declaration := do
let type ← mkType
let indVal := ctx.typeInfos[idx]!
let name := indVal.name ++ brecOnSuffix
return Declaration.thmDecl {
name := name
levelParams := indVal.levelParams
type := type
value := ←proveBrecOn ctx indVal type }
where
mkType : MetaM Expr :=
forallTelescopeReducing ctx.headers[idx]! fun xs _ => do
let params := xs[:ctx.numParams]
let motives := xs[ctx.numParams:ctx.numParams + ctx.motives.size].toArray
let indices := xs[ctx.numParams + ctx.motives.size:]
let motiveBinders ← ctx.motives.mapIdxM $ mkIH params motives
withLocalDeclsD motiveBinders fun ys => do
mkForallFVars (xs ++ ys) (mkAppN motives[idx]! indices)
mkIH
(params : Array Expr)
(motives : Array Expr)
(idx : Fin ctx.motives.size)
(motive : Name × Expr) : MetaM $ Name × (Array Expr → MetaM Expr) := do
let name :=
if ctx.motives.size > 1
then mkFreshUserName s!"ih_{idx.val.succ}"
else mkFreshUserName "ih"
let ih ← instantiateForall motive.2 params
let mkDomain (_ : Array Expr) : MetaM Expr :=
forallTelescopeReducing ih fun ys _ => do
let levels := ctx.typeInfos[idx]!.levelParams.map mkLevelParam
let args := params ++ motives ++ ys
let premise :=
mkAppN
(mkConst ctx.belowNames[idx.val]! levels) args
let conclusion :=
mkAppN motives[idx]! ys
mkForallFVars ys (←mkArrow premise conclusion)
return (←name, mkDomain)
/-- Given a constructor name, find the indices of the corresponding `below` version thereof. -/
partial def getBelowIndices (ctorName : Name) : MetaM $ Array Nat := do
let ctorInfo ← getConstInfoCtor ctorName
let belowCtorInfo ← getConstInfoCtor (ctorName.updatePrefix $ ctorInfo.induct ++ `below)
forallTelescopeReducing ctorInfo.type fun xs _ => do
loop xs belowCtorInfo.type #[] 0 0
where
loop
(xs : Array Expr)
(rest : Expr)
(belowIndices : Array Nat)
(xIdx yIdx : Nat) : MetaM $ Array Nat := do
if xIdx ≥ xs.size then return belowIndices else
let x := xs[xIdx]!
let xTy ← inferType x
let yTy := rest.bindingDomain!
if (← isDefEq xTy yTy) then
let rest ← instantiateForall rest #[x]
loop xs rest (belowIndices.push yIdx) (xIdx + 1) (yIdx + 1)
else
forallBoundedTelescope rest (some 1) fun _ rest =>
loop xs rest belowIndices xIdx (yIdx + 1)
private def belowType (motive : Expr) (xs : Array Expr) (idx : Nat) : MetaM $ Name × Expr := do
(← inferType xs[idx]!).withApp fun type args => do
let indName := type.constName!
let indInfo ← getConstInfoInduct indName
let belowArgs := args[:indInfo.numParams] ++ #[motive] ++ args[indInfo.numParams:] ++ #[xs[idx]!]
let belowType := mkAppN (mkConst (indName ++ `below) type.constLevels!) belowArgs
return (indName, belowType)
/-- This function adds an additional `below` discriminant to a matcher application.
It is used for modifying the patterns, such that the structural recursion can use the new
`below` predicate instead of the original one and thus be used prove structural recursion.
It takes as parameters:
- matcherApp: a matcher application
- belowMotive: the motive, that the `below` type should carry
- below: an expression from the local context that is the `below` version of a predicate
and can be used for structural recursion
- idx: the index of the original predicate discriminant.
It returns:
- A matcher application as an expression
- A side-effect for adding the matcher to the environment -/
partial def mkBelowMatcher
(matcherApp : MatcherApp)
(belowMotive : Expr)
(below : Expr)
(idx : Nat) : MetaM $ Expr × MetaM Unit := do
let mkMatcherInput ← getMkMatcherInputInContext matcherApp
let (indName, _, motive, matchType) ←
forallBoundedTelescope mkMatcherInput.matchType mkMatcherInput.numDiscrs fun xs t => do
let (indName, belowType) ← belowType belowMotive xs idx
let matchType ←
withLocalDeclD (←mkFreshUserName `h_below) belowType fun h_below => do
mkForallFVars (xs.push h_below) t
let motive ← newMotive belowType xs
pure (indName, belowType.replaceFVars xs matcherApp.discrs, motive, matchType)
let lhss ← mkMatcherInput.lhss.mapM <| addBelowPattern indName
let alts ← mkMatcherInput.lhss.zip lhss |>.toArray.zip matcherApp.alts |>.mapIdxM fun idx ((oldLhs, lhs), alt) => do
withExistingLocalDecls (oldLhs.fvarDecls ++ lhs.fvarDecls) do
lambdaTelescope alt fun xs t => do
let oldFVars := oldLhs.fvarDecls.toArray
let fvars := lhs.fvarDecls.toArray.map (·.toExpr)
let xs :=
-- special case: if we had no free vars, i.e. there was a unit added and no we do have free vars, we get rid of the unit.
match oldFVars.size, fvars.size with
| 0, _+1 => xs[1:]
| _, _ => xs
let t := t.replaceFVars xs[:oldFVars.size] fvars[:oldFVars.size]
trace[Meta.IndPredBelow.match] "xs = {xs}; oldFVars = {oldFVars.map (·.toExpr)}; fvars = {fvars}; new = {fvars[:oldFVars.size] ++ xs[oldFVars.size:] ++ fvars[oldFVars.size:]}"
let newAlt ← mkLambdaFVars (fvars[:oldFVars.size] ++ xs[oldFVars.size:] ++ fvars[oldFVars.size:]) t
trace[Meta.IndPredBelow.match] "alt {idx}:\n{alt} ↦ {newAlt}"
pure newAlt
let matcherName ← mkFreshUserName mkMatcherInput.matcherName
withExistingLocalDecls (lhss.foldl (init := []) fun s v => s ++ v.fvarDecls) do
for lhs in lhss do
trace[Meta.IndPredBelow.match] "{lhs.patterns.map (·.toMessageData)}"
let res ← Match.mkMatcher { matcherName, matchType, discrInfos := mkArray (mkMatcherInput.numDiscrs + 1) {}, lhss }
res.addMatcher
-- if a wrong index is picked, the resulting matcher can be type-incorrect.
-- we check here, so that errors can propagate higher up the call stack.
check res.matcher
let newApp := mkApp res.matcher motive
let newApp := mkAppN newApp <| matcherApp.discrs.push below
let newApp := mkAppN newApp alts
return (newApp, res.addMatcher)
where
addBelowPattern (indName : Name) (lhs : AltLHS) : MetaM AltLHS := do
withExistingLocalDecls lhs.fvarDecls do
let patterns := lhs.patterns.toArray
let originalPattern := patterns[idx]!
let (fVars, belowPattern) ← convertToBelow indName patterns[idx]!
withExistingLocalDecls fVars.toList do
let patterns := patterns.push belowPattern
let patterns := patterns.set! idx (←toInaccessible originalPattern)
return { lhs with patterns := patterns.toList, fvarDecls := lhs.fvarDecls ++ fVars.toList }
/--
this function changes the type of the pattern from the original type to the `below` version thereof.
Most of the cases don't apply. In order to change the type and the pattern to be type correct, we don't
simply recursively change all occurrences, but rather, we recursively change occurences of the constructor.
As such there are only a few cases:
- the pattern is a constructor from the original type. Here we need to:
- replace the constructor
- copy original recursive patterns and convert them to below and reintroduce them in the correct position
- turn original recursive patterns inaccessible
- introduce free variables as needed.
- it is an `as` pattern. Here the contstructor could be hidden inside of it.
- it is a variable. Here you we need to introduce a fresh variable of a different type.
-/
convertToBelow (indName : Name)
(originalPattern : Pattern) : MetaM $ Array LocalDecl × Pattern := do
match originalPattern with
| Pattern.ctor ctorName us params fields =>
let ctorInfo ← getConstInfoCtor ctorName
let belowCtor ← getConstInfoCtor $ ctorName.updatePrefix $ ctorInfo.induct ++ `below
let belowIndices ← IndPredBelow.getBelowIndices ctorName
let belowIndices := belowIndices[ctorInfo.numParams:].toArray.map (· - belowCtor.numParams)
-- belowFieldOpts starts off with an array of empty fields.
-- We then go over pattern's fields and set the appropriate fields to values.
-- In general, there are fewer `fields` than `belowFieldOpts`, because the
-- `belowCtor` carries a `below`, a non-`below` and a `motive` version of each
-- field that occurs in a recursive application of the inductive predicate.
-- `belowIndices` is a mapping from non-`below` to the `below` version of each field.
let mut belowFieldOpts := mkArray belowCtor.numFields none
let fields := fields.toArray
for fieldIdx in [:fields.size] do
belowFieldOpts := belowFieldOpts.set! belowIndices[fieldIdx]! (some fields[fieldIdx]!)
let belowParams := params.toArray.push belowMotive
let belowCtorExpr := mkAppN (mkConst belowCtor.name us) belowParams
let (additionalFVars, belowFields) ← transformFields belowCtorExpr indName belowFieldOpts
withExistingLocalDecls additionalFVars.toList do
let ctor := Pattern.ctor belowCtor.name us belowParams.toList belowFields.toList
trace[Meta.IndPredBelow.match] "{originalPattern.toMessageData} ↦ {ctor.toMessageData}"
return (additionalFVars, ctor)
| Pattern.as varId p hId =>
let (additionalFVars, p) ← convertToBelow indName p
return (additionalFVars, Pattern.as varId p hId)
| Pattern.var varId =>
let var := mkFVar varId
let (_, tgtType) ← belowType belowMotive #[var] 0
withLocalDeclD (←mkFreshUserName `h) tgtType fun h => do
let localDecl ← getFVarLocalDecl h
return (#[localDecl], Pattern.var h.fvarId!)
| p => return (#[], p)
transformFields belowCtor indName belowFieldOpts :=
let rec loop
(belowCtor : Expr)
(belowFieldOpts : Array $ Option Pattern)
(belowFields : Array Pattern)
(additionalFVars : Array LocalDecl) : MetaM (Array LocalDecl × Array Pattern) := do
if belowFields.size ≥ belowFieldOpts.size then pure (additionalFVars, belowFields) else
if let some belowField := belowFieldOpts[belowFields.size]! then
let belowFieldExpr ← belowField.toExpr
let belowCtor := mkApp belowCtor belowFieldExpr
let patTy ← inferType belowFieldExpr
patTy.withApp fun f _ => do
let constName := f.constName?
if constName == indName then
let (fvars, transformedField) ← convertToBelow indName belowField
withExistingLocalDecls fvars.toList do
let belowFieldOpts := belowFieldOpts.set! (belowFields.size + 1) transformedField
let belowField :=
match belowField with
| Pattern.ctor .. => Pattern.inaccessible belowFieldExpr
| _ => belowField
loop belowCtor belowFieldOpts (belowFields.push belowField) (additionalFVars ++ fvars)
else
loop belowCtor belowFieldOpts (belowFields.push belowField) additionalFVars
else
let ctorType ← inferType belowCtor
withLocalDeclD (←mkFreshUserName `a) ctorType.bindingDomain! fun a => do
let localDecl ← getFVarLocalDecl a
loop (mkApp belowCtor a) belowFieldOpts (belowFields.push $ Pattern.var a.fvarId!) (additionalFVars.push localDecl)
loop belowCtor belowFieldOpts #[] #[]
toInaccessible : Pattern → MetaM Pattern
| Pattern.inaccessible p => return Pattern.inaccessible p
| Pattern.var v => return Pattern.var v
| p => return Pattern.inaccessible $ ←p.toExpr
newMotive (belowType : Expr) (ys : Array Expr) : MetaM Expr :=
lambdaTelescope matcherApp.motive fun xs t => do
let numDiscrs := matcherApp.discrs.size
withLocalDeclD (←mkFreshUserName `h_below) (belowType.replaceFVars ys xs) fun h_below => do
let motive ← mkLambdaFVars (xs[:numDiscrs] ++ #[h_below] ++ xs[numDiscrs:]) t
trace[Meta.IndPredBelow.match] "motive := {motive}"
return motive
def findBelowIdx (xs : Array Expr) (motive : Expr) : MetaM $ Option (Expr × Nat) := do
xs.findSomeM? fun x => do
let xTy ← inferType x
xTy.withApp fun f _ =>
match f.constName?, xs.indexOf? x with
| some name, some idx => do
if (← isInductivePredicate name) then
let (_, belowTy) ← belowType motive xs idx
let below ← mkFreshExprSyntheticOpaqueMVar belowTy
try
trace[Meta.IndPredBelow.match] "{←Meta.ppGoal below.mvarId!}"
if (← backwardsChaining below.mvarId! 10) then
trace[Meta.IndPredBelow.match] "Found below term in the local context: {below}"
if (← xs.anyM (isDefEq below)) then pure none else pure (below, idx.val)
else
trace[Meta.IndPredBelow.match] "could not find below term in the local context"
pure none
catch _ => pure none
else pure none
| _, _ => pure none
def mkBelow (declName : Name) : MetaM Unit := do
if (← isInductivePredicate declName) then
let x ← getConstInfoInduct declName
if x.isRec then
let ctx ← IndPredBelow.mkContext declName
let decl ← IndPredBelow.mkBelowDecl ctx
addDecl decl
trace[Meta.IndPredBelow] "added {ctx.belowNames}"
ctx.belowNames.forM Lean.mkCasesOn
for i in [:ctx.typeInfos.size] do
try
let decl ← IndPredBelow.mkBrecOnDecl ctx i
addDecl decl
catch e => trace[Meta.IndPredBelow] "failed to prove brecOn for {ctx.belowNames[i]!}\n{e.toMessageData}"
else trace[Meta.IndPredBelow] "Not recursive"
else trace[Meta.IndPredBelow] "Not inductive predicate"
builtin_initialize
registerTraceClass `Meta.IndPredBelow
registerTraceClass `Meta.IndPredBelow.match
end Lean.Meta.IndPredBelow
|
7a3cbbd2fa3fe57657acad15f90dbc932265a7cb
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/geometry/manifold/local_invariant_properties.lean
|
8e07981ff9550fbfc32236b04a1911169311c246
|
[
"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
| 33,826
|
lean
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris van Doorn
-/
import geometry.manifold.charted_space
/-!
# Local properties invariant under a groupoid
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We study properties of a triple `(g, s, x)` where `g` is a function between two spaces `H` and `H'`,
`s` is a subset of `H` and `x` is a point of `H`. Our goal is to register how such a property
should behave to make sense in charted spaces modelled on `H` and `H'`.
The main examples we have in mind are the properties "`g` is differentiable at `x` within `s`", or
"`g` is smooth at `x` within `s`". We want to develop general results that, when applied in these
specific situations, say that the notion of smooth function in a manifold behaves well under
restriction, intersection, is local, and so on.
## Main definitions
* `local_invariant_prop G G' P` says that a property `P` of a triple `(g, s, x)` is local, and
invariant under composition by elements of the groupoids `G` and `G'` of `H` and `H'`
respectively.
* `charted_space.lift_prop_within_at` (resp. `lift_prop_at`, `lift_prop_on` and `lift_prop`):
given a property `P` of `(g, s, x)` where `g : H → H'`, define the corresponding property
for functions `M → M'` where `M` and `M'` are charted spaces modelled respectively on `H` and
`H'`. We define these properties within a set at a point, or at a point, or on a set, or in the
whole space. This lifting process (obtained by restricting to suitable chart domains) can always
be done, but it only behaves well under locality and invariance assumptions.
Given `hG : local_invariant_prop G G' P`, we deduce many properties of the lifted property on the
charted spaces. For instance, `hG.lift_prop_within_at_inter` says that `P g s x` is equivalent to
`P g (s ∩ t) x` whenever `t` is a neighborhood of `x`.
## Implementation notes
We do not use dot notation for properties of the lifted property. For instance, we have
`hG.lift_prop_within_at_congr` saying that if `lift_prop_within_at P g s x` holds, and `g` and `g'`
coincide on `s`, then `lift_prop_within_at P g' s x` holds. We can't call it
`lift_prop_within_at.congr` as it is in the namespace associated to `local_invariant_prop`, not
in the one for `lift_prop_within_at`.
-/
noncomputable theory
open_locale classical manifold topology
open set filter
variables {H M H' M' X : Type*}
variables [topological_space H] [topological_space M] [charted_space H M]
variables [topological_space H'] [topological_space M'] [charted_space H' M']
variables [topological_space X]
namespace structure_groupoid
variables (G : structure_groupoid H) (G' : structure_groupoid H')
/-- Structure recording good behavior of a property of a triple `(f, s, x)` where `f` is a function,
`s` a set and `x` a point. Good behavior here means locality and invariance under given groupoids
(both in the source and in the target). Given such a good behavior, the lift of this property
to charted spaces admitting these groupoids will inherit the good behavior. -/
structure local_invariant_prop (P : (H → H') → (set H) → H → Prop) : Prop :=
(is_local : ∀ {s x u} {f : H → H'}, is_open u → x ∈ u → (P f s x ↔ P f (s ∩ u) x))
(right_invariance' : ∀ {s x f} {e : local_homeomorph H H}, e ∈ G → x ∈ e.source → P f s x →
P (f ∘ e.symm) (e.symm ⁻¹' s) (e x))
(congr_of_forall : ∀ {s x} {f g : H → H'}, (∀ y ∈ s, f y = g y) → f x = g x → P f s x → P g s x)
(left_invariance' : ∀ {s x f} {e' : local_homeomorph H' H'}, e' ∈ G' → s ⊆ f ⁻¹' e'.source →
f x ∈ e'.source → P f s x → P (e' ∘ f) s x)
variables {G G'} {P : (H → H') → (set H) → H → Prop} {s t u : set H} {x : H}
variable (hG : G.local_invariant_prop G' P)
include hG
namespace local_invariant_prop
lemma congr_set {s t : set H} {x : H} {f : H → H'} (hu : s =ᶠ[𝓝 x] t) :
P f s x ↔ P f t x :=
begin
obtain ⟨o, host, ho, hxo⟩ := mem_nhds_iff.mp hu.mem_iff,
simp_rw [subset_def, mem_set_of, ← and.congr_left_iff, ← mem_inter_iff, ← set.ext_iff] at host,
rw [hG.is_local ho hxo, host, ← hG.is_local ho hxo]
end
lemma is_local_nhds {s u : set H} {x : H} {f : H → H'} (hu : u ∈ 𝓝[s] x) :
P f s x ↔ P f (s ∩ u) x :=
hG.congr_set $ mem_nhds_within_iff_eventually_eq.mp hu
lemma congr_iff_nhds_within {s : set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g)
(h2 : f x = g x) : P f s x ↔ P g s x :=
by { simp_rw [hG.is_local_nhds h1],
exact ⟨hG.congr_of_forall (λ y hy, hy.2) h2, hG.congr_of_forall (λ y hy, hy.2.symm) h2.symm⟩ }
lemma congr_nhds_within {s : set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x)
(hP : P f s x) : P g s x :=
(hG.congr_iff_nhds_within h1 h2).mp hP
lemma congr_nhds_within' {s : set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x)
(hP : P g s x) : P f s x :=
(hG.congr_iff_nhds_within h1 h2).mpr hP
lemma congr_iff {s : set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) : P f s x ↔ P g s x :=
hG.congr_iff_nhds_within (mem_nhds_within_of_mem_nhds h) (mem_of_mem_nhds h : _)
lemma congr {s : set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P f s x) : P g s x :=
(hG.congr_iff h).mp hP
lemma congr' {s : set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P g s x) : P f s x :=
hG.congr h.symm hP
lemma left_invariance {s : set H} {x : H} {f : H → H'} {e' : local_homeomorph H' H'}
(he' : e' ∈ G') (hfs : continuous_within_at f s x) (hxe' : f x ∈ e'.source) :
P (e' ∘ f) s x ↔ P f s x :=
begin
have h2f := hfs.preimage_mem_nhds_within (e'.open_source.mem_nhds hxe'),
have h3f := (((e'.continuous_at hxe').comp_continuous_within_at hfs).preimage_mem_nhds_within $
e'.symm.open_source.mem_nhds $ e'.maps_to hxe'),
split,
{ intro h,
rw [hG.is_local_nhds h3f] at h,
have h2 := hG.left_invariance' (G'.symm he') (inter_subset_right _ _)
(by exact e'.maps_to hxe') h,
rw [← hG.is_local_nhds h3f] at h2,
refine hG.congr_nhds_within _ (e'.left_inv hxe') h2,
exact eventually_of_mem h2f (λ x', e'.left_inv) },
{ simp_rw [hG.is_local_nhds h2f],
exact hG.left_invariance' he' (inter_subset_right _ _) hxe' }
end
lemma right_invariance {s : set H} {x : H} {f : H → H'} {e : local_homeomorph H H}
(he : e ∈ G) (hxe : x ∈ e.source) : P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P f s x :=
begin
refine ⟨λ h, _, hG.right_invariance' he hxe⟩,
have := hG.right_invariance' (G.symm he) (e.maps_to hxe) h,
rw [e.symm_symm, e.left_inv hxe] at this,
refine hG.congr _ ((hG.congr_set _).mp this),
{ refine eventually_of_mem (e.open_source.mem_nhds hxe) (λ x' hx', _),
simp_rw [function.comp_apply, e.left_inv hx'] },
{ rw [eventually_eq_set],
refine eventually_of_mem (e.open_source.mem_nhds hxe) (λ x' hx', _),
simp_rw [mem_preimage, e.left_inv hx'] },
end
end local_invariant_prop
end structure_groupoid
namespace charted_space
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property in a charted space, by requiring that it holds at the preferred chart at
this point. (When the property is local and invariant, it will in fact hold using any chart, see
`lift_prop_within_at_indep_chart`). We require continuity in the lifted property, as otherwise one
single chart might fail to capture the behavior of the function.
-/
def lift_prop_within_at (P : (H → H') → set H → H → Prop)
(f : M → M') (s : set M) (x : M) : Prop :=
continuous_within_at f s x ∧
P (chart_at H' (f x) ∘ f ∘ (chart_at H x).symm) ((chart_at H x).symm ⁻¹' s) (chart_at H x x)
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of functions on sets in a charted space, by requiring that it holds
around each point of the set, in the preferred charts. -/
def lift_prop_on (P : (H → H') → set H → H → Prop) (f : M → M') (s : set M) :=
∀ x ∈ s, lift_prop_within_at P f s x
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of a function at a point in a charted space, by requiring that it holds
in the preferred chart. -/
def lift_prop_at (P : (H → H') → set H → H → Prop) (f : M → M') (x : M) :=
lift_prop_within_at P f univ x
lemma lift_prop_at_iff {P : (H → H') → set H → H → Prop} {f : M → M'} {x : M} :
lift_prop_at P f x ↔ continuous_at f x ∧
P (chart_at H' (f x) ∘ f ∘ (chart_at H x).symm) univ (chart_at H x x) :=
by rw [lift_prop_at, lift_prop_within_at, continuous_within_at_univ, preimage_univ]
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of a function in a charted space, by requiring that it holds
in the preferred chart around every point. -/
def lift_prop (P : (H → H') → set H → H → Prop) (f : M → M') :=
∀ x, lift_prop_at P f x
lemma lift_prop_iff {P : (H → H') → set H → H → Prop} {f : M → M'} :
lift_prop P f ↔ continuous f ∧
∀ x, P (chart_at H' (f x) ∘ f ∘ (chart_at H x).symm) univ (chart_at H x x) :=
by simp_rw [lift_prop, lift_prop_at_iff, forall_and_distrib, continuous_iff_continuous_at]
end charted_space
open charted_space
namespace structure_groupoid
variables {G : structure_groupoid H} {G' : structure_groupoid H'}
{e e' : local_homeomorph M H} {f f' : local_homeomorph M' H'}
{P : (H → H') → set H → H → Prop} {g g' : M → M'} {s t : set M} {x : M}
{Q : (H → H) → set H → H → Prop}
lemma lift_prop_within_at_univ : lift_prop_within_at P g univ x ↔ lift_prop_at P g x :=
iff.rfl
lemma lift_prop_on_univ : lift_prop_on P g univ ↔ lift_prop P g :=
by simp [lift_prop_on, lift_prop, lift_prop_at]
lemma lift_prop_within_at_self {f : H → H'} {s : set H} {x : H} :
lift_prop_within_at P f s x ↔ continuous_within_at f s x ∧ P f s x :=
iff.rfl
lemma lift_prop_within_at_self_source {f : H → M'} {s : set H} {x : H} :
lift_prop_within_at P f s x ↔ continuous_within_at f s x ∧ P (chart_at H' (f x) ∘ f) s x :=
iff.rfl
lemma lift_prop_within_at_self_target {f : M → H'} :
lift_prop_within_at P f s x ↔
continuous_within_at f s x ∧
P (f ∘ (chart_at H x).symm) ((chart_at H x).symm ⁻¹' s) (chart_at H x x) :=
iff.rfl
namespace local_invariant_prop
variable (hG : G.local_invariant_prop G' P)
include hG
/-- `lift_prop_within_at P f s x` is equivalent to a definition where we restrict the set we are
considering to the domain of the charts at `x` and `f x`. -/
lemma lift_prop_within_at_iff {f : M → M'} :
lift_prop_within_at P f s x ↔
continuous_within_at f s x ∧ P ((chart_at H' (f x)) ∘ f ∘ (chart_at H x).symm)
((chart_at H x).target ∩ (chart_at H x).symm ⁻¹' (s ∩ f ⁻¹' (chart_at H' (f x)).source))
(chart_at H x x) :=
begin
refine and_congr_right (λ hf, hG.congr_set _),
exact local_homeomorph.preimage_eventually_eq_target_inter_preimage_inter hf
(mem_chart_source H x) (chart_source_mem_nhds H' (f x))
end
lemma lift_prop_within_at_indep_chart_source_aux (g : M → H')
(he : e ∈ G.maximal_atlas M) (xe : x ∈ e.source)
(he' : e' ∈ G.maximal_atlas M) (xe' : x ∈ e'.source) :
P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) :=
begin
rw [← hG.right_invariance (compatible_of_mem_maximal_atlas he he')],
swap, { simp only [xe, xe'] with mfld_simps },
simp_rw [local_homeomorph.trans_apply, e.left_inv xe],
rw [hG.congr_iff],
{ refine hG.congr_set _,
refine (eventually_of_mem _ $ λ y (hy : y ∈ e'.symm ⁻¹' e.source), _).set_eq,
{ refine (e'.symm.continuous_at $ e'.maps_to xe').preimage_mem_nhds (e.open_source.mem_nhds _),
simp_rw [e'.left_inv xe', xe] },
simp_rw [mem_preimage, local_homeomorph.coe_trans_symm, local_homeomorph.symm_symm,
function.comp_apply, e.left_inv hy] },
{ refine ((e'.eventually_nhds' _ xe').mpr $ e.eventually_left_inverse xe).mono (λ y hy, _),
simp only with mfld_simps,
rw [hy] },
end
lemma lift_prop_within_at_indep_chart_target_aux2 (g : H → M') {x : H} {s : set H}
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source)
(hf' : f' ∈ G'.maximal_atlas M') (xf' : g x ∈ f'.source)
(hgs : continuous_within_at g s x) :
P (f ∘ g) s x ↔ P (f' ∘ g) s x :=
begin
have hcont : continuous_within_at (f ∘ g) s x :=
(f.continuous_at xf).comp_continuous_within_at hgs,
rw [← hG.left_invariance (compatible_of_mem_maximal_atlas hf hf') hcont
(by simp only [xf, xf'] with mfld_simps)],
refine hG.congr_iff_nhds_within _ (by simp only [xf] with mfld_simps),
exact (hgs.eventually $ f.eventually_left_inverse xf).mono (λ y, congr_arg f')
end
lemma lift_prop_within_at_indep_chart_target_aux {g : X → M'} {e : local_homeomorph X H} {x : X}
{s : set X} (xe : x ∈ e.source)
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source)
(hf' : f' ∈ G'.maximal_atlas M') (xf' : g x ∈ f'.source)
(hgs : continuous_within_at g s x) :
P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) :=
begin
rw [← e.left_inv xe] at xf xf' hgs,
refine hG.lift_prop_within_at_indep_chart_target_aux2 (g ∘ e.symm) hf xf hf' xf' _,
exact hgs.comp (e.symm.continuous_at $ e.maps_to xe).continuous_within_at subset.rfl
end
/-- If a property of a germ of function `g` on a pointed set `(s, x)` is invariant under the
structure groupoid (by composition in the source space and in the target space), then
expressing it in charted spaces does not depend on the element of the maximal atlas one uses
both in the source and in the target manifolds, provided they are defined around `x` and `g x`
respectively, and provided `g` is continuous within `s` at `x` (otherwise, the local behavior
of `g` at `x` can not be captured with a chart in the target). -/
lemma lift_prop_within_at_indep_chart_aux
(he : e ∈ G.maximal_atlas M) (xe : x ∈ e.source)
(he' : e' ∈ G.maximal_atlas M) (xe' : x ∈ e'.source)
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source)
(hf' : f' ∈ G'.maximal_atlas M') (xf' : g x ∈ f'.source)
(hgs : continuous_within_at g s x) :
P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) :=
by rw [hG.lift_prop_within_at_indep_chart_source_aux (f ∘ g) he xe he' xe',
hG.lift_prop_within_at_indep_chart_target_aux xe' hf xf hf' xf' hgs]
lemma lift_prop_within_at_indep_chart [has_groupoid M G] [has_groupoid M' G']
(he : e ∈ G.maximal_atlas M) (xe : x ∈ e.source)
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source) :
lift_prop_within_at P g s x ↔
continuous_within_at g s x ∧ P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) :=
and_congr_right $ hG.lift_prop_within_at_indep_chart_aux (chart_mem_maximal_atlas _ _)
(mem_chart_source _ _) he xe (chart_mem_maximal_atlas _ _) (mem_chart_source _ _) hf xf
/-- A version of `lift_prop_within_at_indep_chart`, only for the source. -/
lemma lift_prop_within_at_indep_chart_source [has_groupoid M G]
(he : e ∈ G.maximal_atlas M) (xe : x ∈ e.source) :
lift_prop_within_at P g s x ↔ lift_prop_within_at P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) :=
begin
have := e.symm.continuous_within_at_iff_continuous_within_at_comp_right xe,
rw [e.symm_symm] at this,
rw [lift_prop_within_at_self_source, lift_prop_within_at, ← this],
simp_rw [function.comp_app, e.left_inv xe],
refine and_congr iff.rfl _,
rw hG.lift_prop_within_at_indep_chart_source_aux (chart_at H' (g x) ∘ g)
(chart_mem_maximal_atlas G x) (mem_chart_source H x) he xe,
end
/-- A version of `lift_prop_within_at_indep_chart`, only for the target. -/
lemma lift_prop_within_at_indep_chart_target [has_groupoid M' G']
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source) :
lift_prop_within_at P g s x ↔ continuous_within_at g s x ∧ lift_prop_within_at P (f ∘ g) s x :=
begin
rw [lift_prop_within_at_self_target, lift_prop_within_at, and.congr_right_iff],
intro hg,
simp_rw [(f.continuous_at xf).comp_continuous_within_at hg, true_and],
exact hG.lift_prop_within_at_indep_chart_target_aux (mem_chart_source _ _)
(chart_mem_maximal_atlas _ _) (mem_chart_source _ _) hf xf hg
end
/-- A version of `lift_prop_within_at_indep_chart`, that uses `lift_prop_within_at` on both sides.
-/
lemma lift_prop_within_at_indep_chart' [has_groupoid M G] [has_groupoid M' G']
(he : e ∈ G.maximal_atlas M) (xe : x ∈ e.source)
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source) :
lift_prop_within_at P g s x ↔
continuous_within_at g s x ∧ lift_prop_within_at P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) :=
begin
rw [hG.lift_prop_within_at_indep_chart he xe hf xf, lift_prop_within_at_self, and.left_comm,
iff.comm, and_iff_right_iff_imp],
intro h,
have h1 := (e.symm.continuous_within_at_iff_continuous_within_at_comp_right xe).mp h.1,
have : continuous_at f ((g ∘ e.symm) (e x)),
{ simp_rw [function.comp, e.left_inv xe, f.continuous_at xf] },
exact this.comp_continuous_within_at h1,
end
lemma lift_prop_on_indep_chart [has_groupoid M G] [has_groupoid M' G']
(he : e ∈ G.maximal_atlas M) (hf : f ∈ G'.maximal_atlas M') (h : lift_prop_on P g s)
{y : H} (hy : y ∈ e.target ∩ e.symm ⁻¹' (s ∩ g ⁻¹' f.source)) :
P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) y :=
begin
convert ((hG.lift_prop_within_at_indep_chart he (e.symm_maps_to hy.1) hf hy.2.2).1
(h _ hy.2.1)).2,
rw [e.right_inv hy.1],
end
lemma lift_prop_within_at_inter' (ht : t ∈ 𝓝[s] x) :
lift_prop_within_at P g (s ∩ t) x ↔ lift_prop_within_at P g s x :=
begin
rw [lift_prop_within_at, lift_prop_within_at, continuous_within_at_inter' ht, hG.congr_set],
simp_rw [eventually_eq_set, mem_preimage,
(chart_at H x).eventually_nhds' (λ x, x ∈ s ∩ t ↔ x ∈ s) (mem_chart_source H x)],
exact (mem_nhds_within_iff_eventually_eq.mp ht).symm.mem_iff
end
lemma lift_prop_within_at_inter (ht : t ∈ 𝓝 x) :
lift_prop_within_at P g (s ∩ t) x ↔ lift_prop_within_at P g s x :=
hG.lift_prop_within_at_inter' (mem_nhds_within_of_mem_nhds ht)
lemma lift_prop_at_of_lift_prop_within_at (h : lift_prop_within_at P g s x) (hs : s ∈ 𝓝 x) :
lift_prop_at P g x :=
by rwa [← univ_inter s, hG.lift_prop_within_at_inter hs] at h
lemma lift_prop_within_at_of_lift_prop_at_of_mem_nhds (h : lift_prop_at P g x) (hs : s ∈ 𝓝 x) :
lift_prop_within_at P g s x :=
by rwa [← univ_inter s, hG.lift_prop_within_at_inter hs]
lemma lift_prop_on_of_locally_lift_prop_on
(h : ∀ x ∈ s, ∃ u, is_open u ∧ x ∈ u ∧ lift_prop_on P g (s ∩ u)) :
lift_prop_on P g s :=
begin
assume x hx,
rcases h x hx with ⟨u, u_open, xu, hu⟩,
have := hu x ⟨hx, xu⟩,
rwa hG.lift_prop_within_at_inter at this,
exact is_open.mem_nhds u_open xu,
end
lemma lift_prop_of_locally_lift_prop_on (h : ∀ x, ∃ u, is_open u ∧ x ∈ u ∧ lift_prop_on P g u) :
lift_prop P g :=
begin
rw ← lift_prop_on_univ,
apply hG.lift_prop_on_of_locally_lift_prop_on (λ x hx, _),
simp [h x],
end
lemma lift_prop_within_at_congr_of_eventually_eq
(h : lift_prop_within_at P g s x) (h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) :
lift_prop_within_at P g' s x :=
begin
refine ⟨h.1.congr_of_eventually_eq h₁ hx, _⟩,
refine hG.congr_nhds_within' _ (by simp_rw [function.comp_apply,
(chart_at H x).left_inv (mem_chart_source H x), hx]) h.2,
simp_rw [eventually_eq, function.comp_app, (chart_at H x).eventually_nhds_within'
(λ y, chart_at H' (g' x) (g' y) = chart_at H' (g x) (g y))
(mem_chart_source H x)],
exact h₁.mono (λ y hy, by rw [hx, hy])
end
lemma lift_prop_within_at_congr_iff_of_eventually_eq (h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) :
lift_prop_within_at P g' s x ↔ lift_prop_within_at P g s x :=
⟨λ h, hG.lift_prop_within_at_congr_of_eventually_eq h h₁.symm hx.symm,
λ h, hG.lift_prop_within_at_congr_of_eventually_eq h h₁ hx⟩
lemma lift_prop_within_at_congr_iff
(h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) :
lift_prop_within_at P g' s x ↔ lift_prop_within_at P g s x :=
hG.lift_prop_within_at_congr_iff_of_eventually_eq (eventually_nhds_within_of_forall h₁) hx
lemma lift_prop_within_at_congr
(h : lift_prop_within_at P g s x) (h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) :
lift_prop_within_at P g' s x :=
(hG.lift_prop_within_at_congr_iff h₁ hx).mpr h
lemma lift_prop_at_congr_iff_of_eventually_eq
(h₁ : g' =ᶠ[𝓝 x] g) : lift_prop_at P g' x ↔ lift_prop_at P g x :=
hG.lift_prop_within_at_congr_iff_of_eventually_eq (by simp_rw [nhds_within_univ, h₁]) h₁.eq_of_nhds
lemma lift_prop_at_congr_of_eventually_eq (h : lift_prop_at P g x) (h₁ : g' =ᶠ[𝓝 x] g) :
lift_prop_at P g' x :=
(hG.lift_prop_at_congr_iff_of_eventually_eq h₁).mpr h
lemma lift_prop_on_congr (h : lift_prop_on P g s) (h₁ : ∀ y ∈ s, g' y = g y) :
lift_prop_on P g' s :=
λ x hx, hG.lift_prop_within_at_congr (h x hx) h₁ (h₁ x hx)
lemma lift_prop_on_congr_iff (h₁ : ∀ y ∈ s, g' y = g y) :
lift_prop_on P g' s ↔ lift_prop_on P g s :=
⟨λ h, hG.lift_prop_on_congr h (λ y hy, (h₁ y hy).symm), λ h, hG.lift_prop_on_congr h h₁⟩
omit hG
lemma lift_prop_within_at_mono_of_mem
(mono_of_mem : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, s ∈ 𝓝[t] x → P f s x → P f t x)
(h : lift_prop_within_at P g s x) (hst : s ∈ 𝓝[t] x) :
lift_prop_within_at P g t x :=
begin
refine ⟨h.1.mono_of_mem hst, mono_of_mem _ h.2⟩,
simp_rw [← mem_map, (chart_at H x).symm.map_nhds_within_preimage_eq (mem_chart_target H x),
(chart_at H x).left_inv (mem_chart_source H x), hst]
end
lemma lift_prop_within_at_mono
(mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x)
(h : lift_prop_within_at P g s x) (hts : t ⊆ s) :
lift_prop_within_at P g t x :=
begin
refine ⟨h.1.mono hts, _⟩,
apply mono (λ y hy, _) h.2,
simp only with mfld_simps at hy,
simp only [hy, hts _] with mfld_simps,
end
lemma lift_prop_within_at_of_lift_prop_at
(mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : lift_prop_at P g x) :
lift_prop_within_at P g s x :=
begin
rw ← lift_prop_within_at_univ at h,
exact lift_prop_within_at_mono mono h (subset_univ _),
end
lemma lift_prop_on_mono (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x)
(h : lift_prop_on P g t) (hst : s ⊆ t) :
lift_prop_on P g s :=
λ x hx, lift_prop_within_at_mono mono (h x (hst hx)) hst
lemma lift_prop_on_of_lift_prop
(mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : lift_prop P g) :
lift_prop_on P g s :=
begin
rw ← lift_prop_on_univ at h,
exact lift_prop_on_mono mono h (subset_univ _)
end
lemma lift_prop_at_of_mem_maximal_atlas [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y)
(he : e ∈ maximal_atlas M G) (hx : x ∈ e.source) : lift_prop_at Q e x :=
begin
simp_rw [lift_prop_at,
hG.lift_prop_within_at_indep_chart he hx G.id_mem_maximal_atlas (mem_univ _),
(e.continuous_at hx).continuous_within_at, true_and],
exact hG.congr' (e.eventually_right_inverse' hx) (hQ _)
end
lemma lift_prop_on_of_mem_maximal_atlas [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximal_atlas M G) :
lift_prop_on Q e e.source :=
begin
assume x hx,
apply hG.lift_prop_within_at_of_lift_prop_at_of_mem_nhds
(hG.lift_prop_at_of_mem_maximal_atlas hQ he hx),
exact is_open.mem_nhds e.open_source hx,
end
lemma lift_prop_at_symm_of_mem_maximal_atlas [has_groupoid M G] {x : H}
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y)
(he : e ∈ maximal_atlas M G) (hx : x ∈ e.target) : lift_prop_at Q e.symm x :=
begin
suffices h : Q (e ∘ e.symm) univ x,
{ have A : e.symm ⁻¹' e.source ∩ e.target = e.target,
by mfld_set_tac,
have : e.symm x ∈ e.source, by simp only [hx] with mfld_simps,
rw [lift_prop_at,
hG.lift_prop_within_at_indep_chart G.id_mem_maximal_atlas (mem_univ _) he this],
refine ⟨(e.symm.continuous_at hx).continuous_within_at, _⟩,
simp only [h] with mfld_simps },
exact hG.congr' (e.eventually_right_inverse hx) (hQ x)
end
lemma lift_prop_on_symm_of_mem_maximal_atlas [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximal_atlas M G) :
lift_prop_on Q e.symm e.target :=
begin
assume x hx,
apply hG.lift_prop_within_at_of_lift_prop_at_of_mem_nhds
(hG.lift_prop_at_symm_of_mem_maximal_atlas hQ he hx),
exact is_open.mem_nhds e.open_target hx,
end
lemma lift_prop_at_chart [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) : lift_prop_at Q (chart_at H x) x :=
hG.lift_prop_at_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x) (mem_chart_source H x)
lemma lift_prop_on_chart [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop_on Q (chart_at H x) (chart_at H x).source :=
hG.lift_prop_on_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x)
lemma lift_prop_at_chart_symm [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop_at Q (chart_at H x).symm ((chart_at H x) x) :=
hG.lift_prop_at_symm_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x) (by simp)
lemma lift_prop_on_chart_symm [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop_on Q (chart_at H x).symm (chart_at H x).target :=
hG.lift_prop_on_symm_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x)
lemma lift_prop_at_of_mem_groupoid (hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y)
{f : local_homeomorph H H} (hf : f ∈ G) {x : H} (hx : x ∈ f.source) :
lift_prop_at Q f x :=
lift_prop_at_of_mem_maximal_atlas hG hQ (G.mem_maximal_atlas_of_mem_groupoid hf) hx
lemma lift_prop_on_of_mem_groupoid (hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y)
{f : local_homeomorph H H} (hf : f ∈ G) :
lift_prop_on Q f f.source :=
lift_prop_on_of_mem_maximal_atlas hG hQ (G.mem_maximal_atlas_of_mem_groupoid hf)
lemma lift_prop_id (hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop Q (id : M → M) :=
begin
simp_rw [lift_prop_iff, continuous_id, true_and],
exact λ x, hG.congr' ((chart_at H x).eventually_right_inverse $ mem_chart_target H x) (hQ _)
end
end local_invariant_prop
section local_structomorph
variables (G)
open local_homeomorph
/-- A function from a model space `H` to itself is a local structomorphism, with respect to a
structure groupoid `G` for `H`, relative to a set `s` in `H`, if for all points `x` in the set, the
function agrees with a `G`-structomorphism on `s` in a neighbourhood of `x`. -/
def is_local_structomorph_within_at (f : H → H) (s : set H) (x : H) : Prop :=
x ∈ s → ∃ (e : local_homeomorph H H), e ∈ G ∧ eq_on f e.to_fun (s ∩ e.source) ∧ x ∈ e.source
/-- For a groupoid `G` which is `closed_under_restriction`, being a local structomorphism is a local
invariant property. -/
lemma is_local_structomorph_within_at_local_invariant_prop [closed_under_restriction G] :
local_invariant_prop G G (is_local_structomorph_within_at G) :=
{ is_local := begin
intros s x u f hu hux,
split,
{ rintros h hx,
rcases h hx.1 with ⟨e, heG, hef, hex⟩,
have : s ∩ u ∩ e.source ⊆ s ∩ e.source := by mfld_set_tac,
exact ⟨e, heG, hef.mono this, hex⟩ },
{ rintros h hx,
rcases h ⟨hx, hux⟩ with ⟨e, heG, hef, hex⟩,
refine ⟨e.restr (interior u), _, _, _⟩,
{ exact closed_under_restriction' heG (is_open_interior) },
{ have : s ∩ u ∩ e.source = s ∩ (e.source ∩ u) := by mfld_set_tac,
simpa only [this, interior_interior, hu.interior_eq] with mfld_simps using hef },
{ simp only [*, interior_interior, hu.interior_eq] with mfld_simps } }
end,
right_invariance' := begin
intros s x f e' he'G he'x h hx,
have hxs : x ∈ s := by simpa only [e'.left_inv he'x] with mfld_simps using hx,
rcases h hxs with ⟨e, heG, hef, hex⟩,
refine ⟨e'.symm.trans e, G.trans (G.symm he'G) heG, _, _⟩,
{ intros y hy,
simp only with mfld_simps at hy,
simp only [hef ⟨hy.1, hy.2.2⟩] with mfld_simps },
{ simp only [hex, he'x] with mfld_simps }
end,
congr_of_forall := begin
intros s x f g hfgs hfg' h hx,
rcases h hx with ⟨e, heG, hef, hex⟩,
refine ⟨e, heG, _, hex⟩,
intros y hy,
rw [← hef hy, hfgs y hy.1]
end,
left_invariance' := begin
intros s x f e' he'G he' hfx h hx,
rcases h hx with ⟨e, heG, hef, hex⟩,
refine ⟨e.trans e', G.trans heG he'G, _, _⟩,
{ intros y hy,
simp only with mfld_simps at hy,
simp only [hef ⟨hy.1, hy.2.1⟩] with mfld_simps },
{ simpa only [hex, hef ⟨hx, hex⟩] with mfld_simps using hfx }
end }
/-- A slight reformulation of `is_local_structomorph_within_at` when `f` is a local homeomorph.
This gives us an `e` that is defined on a subset of `f.source`. -/
lemma _root_.local_homeomorph.is_local_structomorph_within_at_iff {G : structure_groupoid H}
[closed_under_restriction G]
(f : local_homeomorph H H) {s : set H} {x : H} (hx : x ∈ f.source ∪ sᶜ) :
G.is_local_structomorph_within_at ⇑f s x ↔
x ∈ s → ∃ (e : local_homeomorph H H), e ∈ G ∧ e.source ⊆ f.source ∧
eq_on f ⇑e (s ∩ e.source) ∧ x ∈ e.source :=
begin
split,
{ intros hf h2x,
obtain ⟨e, he, hfe, hxe⟩ := hf h2x,
refine ⟨e.restr f.source, closed_under_restriction' he f.open_source, _, _, hxe, _⟩,
{ simp_rw [local_homeomorph.restr_source],
refine (inter_subset_right _ _).trans interior_subset },
{ intros x' hx', exact hfe ⟨hx'.1, hx'.2.1⟩ },
{ rw [f.open_source.interior_eq], exact or.resolve_right hx (not_not.mpr h2x) } },
{ intros hf hx, obtain ⟨e, he, h2e, hfe, hxe⟩ := hf hx, exact ⟨e, he, hfe, hxe⟩ }
end
/-- A slight reformulation of `is_local_structomorph_within_at` when `f` is a local homeomorph and
the set we're considering is a superset of `f.source`. -/
lemma _root_.local_homeomorph.is_local_structomorph_within_at_iff' {G : structure_groupoid H}
[closed_under_restriction G]
(f : local_homeomorph H H) {s : set H} {x : H} (hs : f.source ⊆ s) (hx : x ∈ f.source ∪ sᶜ) :
G.is_local_structomorph_within_at ⇑f s x ↔
x ∈ s → ∃ (e : local_homeomorph H H), e ∈ G ∧ e.source ⊆ f.source ∧
eq_on f ⇑e e.source ∧ x ∈ e.source :=
begin
simp_rw [f.is_local_structomorph_within_at_iff hx],
refine imp_congr_right (λ hx, exists_congr $ λ e, and_congr_right $ λ he, _),
refine and_congr_right (λ h2e, _),
rw [inter_eq_right_iff_subset.mpr (h2e.trans hs)],
end
/-- A slight reformulation of `is_local_structomorph_within_at` when `f` is a local homeomorph and
the set we're considering is `f.source`. -/
lemma _root_.local_homeomorph.is_local_structomorph_within_at_source_iff {G : structure_groupoid H}
[closed_under_restriction G]
(f : local_homeomorph H H) {x : H} :
G.is_local_structomorph_within_at ⇑f f.source x ↔
x ∈ f.source → ∃ (e : local_homeomorph H H), e ∈ G ∧ e.source ⊆ f.source ∧
eq_on f ⇑e e.source ∧ x ∈ e.source :=
begin
have : x ∈ f.source ∪ f.sourceᶜ, { simp_rw [union_compl_self] },
exact f.is_local_structomorph_within_at_iff' subset.rfl this,
end
variables {H₁ : Type*} [topological_space H₁] {H₂ : Type*} [topological_space H₂]
{H₃ : Type*} [topological_space H₃] [charted_space H₁ H₂] [charted_space H₂ H₃]
{G₁ : structure_groupoid H₁} [has_groupoid H₂ G₁] [closed_under_restriction G₁]
(G₂ : structure_groupoid H₂) [has_groupoid H₃ G₂]
variables (G₂)
lemma has_groupoid.comp
(H : ∀ e ∈ G₂, lift_prop_on (is_local_structomorph_within_at G₁) (e : H₂ → H₂) e.source) :
@has_groupoid H₁ _ H₃ _ (charted_space.comp H₁ H₂ H₃) G₁ :=
{ compatible := begin
rintros _ _ ⟨e, f, he, hf, rfl⟩ ⟨e', f', he', hf', rfl⟩,
apply G₁.locality,
intros x hx,
simp only with mfld_simps at hx,
have hxs : x ∈ f.symm ⁻¹' (e.symm ≫ₕ e').source,
{ simp only [hx] with mfld_simps },
have hxs' : x ∈ f.target ∩ (f.symm) ⁻¹' ((e.symm ≫ₕ e').source ∩ (e.symm ≫ₕ e') ⁻¹' f'.source),
{ simp only [hx] with mfld_simps },
obtain ⟨φ, hφG₁, hφ, hφ_dom⟩ := local_invariant_prop.lift_prop_on_indep_chart
(is_local_structomorph_within_at_local_invariant_prop G₁) (G₁.subset_maximal_atlas hf)
(G₁.subset_maximal_atlas hf') (H _ (G₂.compatible he he')) hxs' hxs,
simp_rw [← local_homeomorph.coe_trans, local_homeomorph.trans_assoc] at hφ,
simp_rw [local_homeomorph.trans_symm_eq_symm_trans_symm, local_homeomorph.trans_assoc],
have hs : is_open (f.symm ≫ₕ e.symm ≫ₕ e' ≫ₕ f').source :=
(f.symm ≫ₕ e.symm ≫ₕ e' ≫ₕ f').open_source,
refine ⟨_, hs.inter φ.open_source, _, _⟩,
{ simp only [hx, hφ_dom] with mfld_simps, },
{ refine G₁.eq_on_source (closed_under_restriction' hφG₁ hs) _,
rw local_homeomorph.restr_source_inter,
refine (hφ.mono _).restr_eq_on_source,
mfld_set_tac },
end }
end local_structomorph
end structure_groupoid
|
3c6458db33088f76f64015e62955ecc1252df9d1
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/tests/lean/diamond5.lean
|
c08e3189880428b8b082ce61e50765e8e5efdc0c
|
[
"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
| 305
|
lean
|
class A (α : Type) where
one : α
zero : α
class B (α : Type) extends A α where
add : α → α → α
class C (α : Type) extends A α where
mul : α → α → α
set_option structureDiamondWarning false
def D.toC (x : Nat) := x
class D (α : Type) extends B α, C α
#check @D.toC_1
|
f58c673c50d7ed01610334b37096de1ef92a4422
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/explicit2.lean
|
35b10020d2ffa792899b160d1bcc966b9ab8ee1f
|
[
"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
| 54
|
lean
|
variable f {A : Type} : A → A
eval (@f Bool)
eval @f
|
2b8a553480d81a64860a9ac1ba516b63f45418d8
|
07f5f86b00fed90a419ccda4298d8b795a68f657
|
/library/init/meta/name.lean
|
e86e57ffe361157db527074c3c5289aa54cdb91f
|
[
"Apache-2.0"
] |
permissive
|
VBaratham/lean
|
8ec5c3167b4835cfbcd7f25e2173d61ad9416b3a
|
450ca5834c1c35318e4b47d553bb9820c1b3eee7
|
refs/heads/master
| 1,629,649,471,814
| 1,512,060,373,000
| 1,512,060,469,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,731
|
lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.ordering.basic init.coe init.data.to_string
/-- Reflect a C++ name object. The VM replaces it with the C++ implementation. -/
inductive name
| anonymous : name
| mk_string : string → name → name
| mk_numeral : unsigned → name → name
/-- Gadget for automatic parameter support. This is similar to the opt_param gadget, but it uses
the tactic declaration names tac_name to synthesize the argument.
Like opt_param, this gadget only affects elaboration.
For example, the tactic will *not* be invoked during type class resolution. -/
@[reducible] def {u} auto_param (α : Sort u) (tac_name : name) : Sort u :=
α
instance : inhabited name :=
⟨name.anonymous⟩
def mk_str_name (n : name) (s : string) : name :=
name.mk_string s n
def mk_num_name (n : name) (v : nat) : name :=
name.mk_numeral (unsigned.of_nat' v) n
def mk_simple_name (s : string) : name :=
mk_str_name name.anonymous s
instance string_to_name : has_coe string name :=
⟨mk_simple_name⟩
infix ` <.> `:65 := mk_str_name
open name
def name.get_prefix : name → name
| anonymous := anonymous
| (mk_string s p) := p
| (mk_numeral s p) := p
def name.update_prefix : name → name → name
| anonymous new_p := anonymous
| (mk_string s p) new_p := mk_string s new_p
| (mk_numeral s p) new_p := mk_numeral s new_p
/- The (decidable_eq string) has not been defined yet.
So, we disable the use of if-then-else when compiling the following definitions. -/
set_option eqn_compiler.ite false
def name.to_string_with_sep (sep : string) : name → string
| anonymous := "[anonymous]"
| (mk_string s anonymous) := s
| (mk_numeral v anonymous) := repr v
| (mk_string s n) := name.to_string_with_sep n ++ sep ++ s
| (mk_numeral v n) := name.to_string_with_sep n ++ sep ++ repr v
private def name.components' : name -> list name
| anonymous := []
| (mk_string s n) := mk_string s anonymous :: name.components' n
| (mk_numeral v n) := mk_numeral v anonymous :: name.components' n
def name.components (n : name) : list name :=
(name.components' n).reverse
protected def name.to_string : name → string :=
name.to_string_with_sep "."
instance : has_to_string name :=
⟨name.to_string⟩
/- TODO(Leo): provide a definition in Lean. -/
meta constant name.has_decidable_eq : decidable_eq name
/- Both cmp and lex_cmp are total orders, but lex_cmp implements a lexicographical order. -/
meta constant name.cmp : name → name → ordering
meta constant name.lex_cmp : name → name → ordering
meta constant name.append : name → name → name
meta constant name.is_internal : name → bool
protected meta def name.lt (a b : name) : Prop :=
name.cmp a b = ordering.lt
meta instance : decidable_rel name.lt :=
λ a b, ordering.decidable_eq _ _
meta instance : has_lt name :=
⟨name.lt⟩
attribute [instance] name.has_decidable_eq
meta instance : has_append name :=
⟨name.append⟩
/-- `name.append_after n i` return a name of the form n_i -/
meta constant name.append_after : name → nat → name
meta def name.is_prefix_of : name → name → bool
| p name.anonymous := ff
| p n :=
if p = n then tt else name.is_prefix_of p n.get_prefix
meta def name.replace_prefix : name → name → name → name
| anonymous p p' := anonymous
| (mk_string s c) p p' := if c = p then mk_string s p' else mk_string s (name.replace_prefix c p p')
| (mk_numeral v c) p p' := if c = p then mk_numeral v p' else mk_numeral v (name.replace_prefix c p p')
|
91de9e8220457fce35fda5c898e292fbf12f5e89
|
02fbe05a45fda5abde7583464416db4366eedfbf
|
/library/init/data/nat/basic.lean
|
1dd96225de7224dd4dd391c7c95f5ebeca08b7a8
|
[
"Apache-2.0"
] |
permissive
|
jasonrute/lean
|
cc12807e11f9ac6b01b8951a8bfb9c2eb35a0154
|
4be962c167ca442a0ec5e84472d7ff9f5302788f
|
refs/heads/master
| 1,672,036,664,637
| 1,601,642,826,000
| 1,601,642,826,000
| 260,777,966
| 0
| 0
|
Apache-2.0
| 1,588,454,819,000
| 1,588,454,818,000
| null |
UTF-8
|
Lean
| false
| false
| 5,920
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura
-/
prelude
import init.logic
notation `ℕ` := nat
namespace nat
inductive less_than_or_equal (a : ℕ) : ℕ → Prop
| refl : less_than_or_equal a
| step : Π {b}, less_than_or_equal b → less_than_or_equal (succ b)
instance : has_le ℕ :=
⟨nat.less_than_or_equal⟩
@[reducible] protected def le (n m : ℕ) := nat.less_than_or_equal n m
@[reducible] protected def lt (n m : ℕ) := nat.less_than_or_equal (succ n) m
instance : has_lt ℕ :=
⟨nat.lt⟩
def pred : ℕ → ℕ
| 0 := 0
| (a+1) := a
protected def sub : ℕ → ℕ → ℕ
| a 0 := a
| a (b+1) := pred (sub a b)
protected def mul : nat → nat → nat
| a 0 := 0
| a (b+1) := (mul a b) + a
instance : has_sub ℕ :=
⟨nat.sub⟩
instance : has_mul ℕ :=
⟨nat.mul⟩
-- defeq to the instance provided by comm_semiring
instance : has_dvd ℕ :=
has_dvd.mk (λ a b, ∃ c, b = a * c)
instance : decidable_eq ℕ
| zero zero := is_true rfl
| (succ x) zero := is_false (λ h, nat.no_confusion h)
| zero (succ y) := is_false (λ h, nat.no_confusion h)
| (succ x) (succ y) :=
match decidable_eq x y with
| is_true xeqy := is_true (xeqy ▸ eq.refl (succ x))
| is_false xney := is_false (λ h, nat.no_confusion h (λ xeqy, absurd xeqy xney))
end
def {u} repeat {α : Type u} (f : ℕ → α → α) : ℕ → α → α
| 0 a := a
| (succ n) a := f n (repeat n a)
instance : inhabited ℕ :=
⟨nat.zero⟩
@[simp] lemma nat_zero_eq_zero : nat.zero = 0 :=
rfl
/- properties of inequality -/
@[refl] protected def le_refl (a : ℕ) : a ≤ a :=
less_than_or_equal.refl
lemma le_succ (n : ℕ) : n ≤ succ n :=
less_than_or_equal.step (nat.le_refl n)
lemma succ_le_succ {n m : ℕ} : n ≤ m → succ n ≤ succ m :=
λ h, less_than_or_equal.rec (nat.le_refl (succ n)) (λ a b, less_than_or_equal.step) h
lemma zero_le : ∀ (n : ℕ), 0 ≤ n
| 0 := nat.le_refl 0
| (n+1) := less_than_or_equal.step (zero_le n)
lemma zero_lt_succ (n : ℕ) : 0 < succ n :=
succ_le_succ (zero_le n)
def succ_pos := zero_lt_succ
lemma not_succ_le_zero : ∀ (n : ℕ), succ n ≤ 0 → false
.
lemma not_lt_zero (a : ℕ) : ¬ a < 0 := not_succ_le_zero a
lemma pred_le_pred {n m : ℕ} : n ≤ m → pred n ≤ pred m :=
λ h, less_than_or_equal.rec_on h
(nat.le_refl (pred n))
(λ n, nat.rec (λ a b, b) (λ a b c, less_than_or_equal.step) n)
lemma le_of_succ_le_succ {n m : ℕ} : succ n ≤ succ m → n ≤ m :=
pred_le_pred
instance decidable_le : ∀ a b : ℕ, decidable (a ≤ b)
| 0 b := is_true (zero_le b)
| (a+1) 0 := is_false (not_succ_le_zero a)
| (a+1) (b+1) :=
match decidable_le a b with
| is_true h := is_true (succ_le_succ h)
| is_false h := is_false (λ a, h (le_of_succ_le_succ a))
end
instance decidable_lt : ∀ a b : ℕ, decidable (a < b) :=
λ a b, nat.decidable_le (succ a) b
protected lemma eq_or_lt_of_le {a b : ℕ} (h : a ≤ b) : a = b ∨ a < b :=
less_than_or_equal.cases_on h (or.inl rfl) (λ n h, or.inr (succ_le_succ h))
lemma lt_succ_of_le {a b : ℕ} : a ≤ b → a < succ b :=
succ_le_succ
@[simp] lemma succ_sub_succ_eq_sub (a b : ℕ) : succ a - succ b = a - b :=
nat.rec_on b
(show succ a - succ zero = a - zero, from (eq.refl (succ a - succ zero)))
(λ b, congr_arg pred)
lemma not_succ_le_self : ∀ n : ℕ, ¬succ n ≤ n :=
λ n, nat.rec (not_succ_le_zero 0) (λ a b c, b (le_of_succ_le_succ c)) n
protected lemma lt_irrefl (n : ℕ) : ¬n < n :=
not_succ_le_self n
protected lemma le_trans {n m k : ℕ} (h1 : n ≤ m) : m ≤ k → n ≤ k :=
less_than_or_equal.rec h1 (λ p h2, less_than_or_equal.step)
lemma pred_le : ∀ (n : ℕ), pred n ≤ n
| 0 := less_than_or_equal.refl
| (succ a) := less_than_or_equal.step less_than_or_equal.refl
lemma pred_lt : ∀ {n : ℕ}, n ≠ 0 → pred n < n
| 0 h := absurd rfl h
| (succ a) h := lt_succ_of_le less_than_or_equal.refl
lemma sub_le (a b : ℕ) : a - b ≤ a :=
nat.rec_on b (nat.le_refl (a - 0)) (λ b₁, nat.le_trans (pred_le (a - b₁)))
lemma sub_lt : ∀ {a b : ℕ}, 0 < a → 0 < b → a - b < a
| 0 b h1 h2 := absurd h1 (nat.lt_irrefl 0)
| (a+1) 0 h1 h2 := absurd h2 (nat.lt_irrefl 0)
| (a+1) (b+1) h1 h2 :=
eq.symm (succ_sub_succ_eq_sub a b) ▸
show a - b < succ a, from
lt_succ_of_le (sub_le a b)
protected lemma lt_of_lt_of_le {n m k : ℕ} : n < m → m ≤ k → n < k :=
nat.le_trans
/- Basic nat.add lemmas -/
protected lemma zero_add : ∀ n : ℕ, 0 + n = n
| 0 := rfl
| (n+1) := congr_arg succ (zero_add n)
lemma succ_add : ∀ n m : ℕ, (succ n) + m = succ (n + m)
| n 0 := rfl
| n (m+1) := congr_arg succ (succ_add n m)
lemma add_succ (n m : ℕ) : n + succ m = succ (n + m) :=
rfl
protected lemma add_zero (n : ℕ) : n + 0 = n :=
rfl
lemma add_one (n : ℕ) : n + 1 = succ n :=
rfl
lemma succ_eq_add_one (n : ℕ) : succ n = n + 1 :=
rfl
/- Basic lemmas for comparing numerals -/
protected lemma bit0_succ_eq (n : ℕ) : bit0 (succ n) = succ (succ (bit0 n)) :=
show succ (succ n + n) = succ (succ (n + n)), from
congr_arg succ (succ_add n n)
protected lemma zero_lt_bit0 : ∀ {n : nat}, n ≠ 0 → 0 < bit0 n
| 0 h := absurd rfl h
| (succ n) h :=
calc 0 < succ (succ (bit0 n)) : zero_lt_succ _
... = bit0 (succ n) : (nat.bit0_succ_eq n).symm
protected lemma zero_lt_bit1 (n : nat) : 0 < bit1 n :=
zero_lt_succ _
protected lemma bit0_ne_zero : ∀ {n : ℕ}, n ≠ 0 → bit0 n ≠ 0
| 0 h := absurd rfl h
| (n+1) h :=
suffices (n+1) + (n+1) ≠ 0, from this,
suffices succ ((n+1) + n) ≠ 0, from this,
λ h, nat.no_confusion h
protected lemma bit1_ne_zero (n : ℕ) : bit1 n ≠ 0 :=
show succ (n + n) ≠ 0, from
λ h, nat.no_confusion h
end nat
|
c53bb823d74c2e2a250cd88a2041b37f48db8a82
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/topology/uniform_space/separation.lean
|
3f217a1320fd86283c000db98cb0237fad257d4c
|
[
"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
| 23,260
|
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, Patrick Massot
-/
import tactic.apply_fun
import data.set.pairwise
import topology.uniform_space.basic
import topology.separation
/-!
# Hausdorff properties of uniform spaces. Separation quotient.
This file studies uniform spaces whose underlying topological spaces are separated
(also known as Hausdorff or T₂).
This turns out to be equivalent to asking that the intersection of all entourages
is the diagonal only. This condition actually implies the stronger separation property
that the space is regular (T₃), hence those conditions are equivalent for topologies coming from
a uniform structure.
More generally, the intersection `𝓢 X` of all entourages of `X`, which has type `set (X × X)` is an
equivalence relation on `X`. Points which are equivalent under the relation are basically
undistinguishable from the point of view of the uniform structure. For instance any uniformly
continuous function will send equivalent points to the same value.
The quotient `separation_quotient X` of `X` by `𝓢 X` has a natural uniform structure which is
separated, and satisfies a universal property: every uniformly continuous function
from `X` to a separated uniform space uniquely factors through `separation_quotient X`.
As usual, this allows to turn `separation_quotient` into a functor (but we don't use the
category theory library in this file).
These notions admit relative versions, one can ask that `s : set X` is separated, this
is equivalent to asking that the uniform structure induced on `s` is separated.
## Main definitions
* `separation_relation X : set (X × X)`: the separation relation
* `separated_space X`: a predicate class asserting that `X` is separated
* `is_separated s`: a predicate asserting that `s : set X` is separated
* `separation_quotient X`: the maximal separated quotient of `X`.
* `separation_quotient.lift f`: factors a map `f : X → Y` through the separation quotient of `X`.
* `separation_quotient.map f`: turns a map `f : X → Y` into a map between the separation quotients
of `X` and `Y`.
## Main results
* `separated_iff_t2`: the equivalence between being separated and being Hausdorff for uniform
spaces.
* `separation_quotient.uniform_continuous_lift`: factoring a uniformly continuous map through the
separation quotient gives a uniformly continuous map.
* `separation_quotient.uniform_continuous_map`: maps induced between separation quotients are
uniformly continuous.
## Notations
Localized in `uniformity`, we have the notation `𝓢 X` for the separation relation
on a uniform space `X`,
## Implementation notes
The separation setoid `separation_setoid` is not declared as a global instance.
It is made a local instance while building the theory of `separation_quotient`.
The factored map `separation_quotient.lift f` is defined without imposing any condition on
`f`, but returns junk if `f` is not uniformly continuous (constant junk hence it is always
uniformly continuous).
-/
open filter topological_space set classical function uniform_space
open_locale classical topological_space uniformity filter
noncomputable theory
set_option eqn_compiler.zeta true
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
variables [uniform_space α] [uniform_space β] [uniform_space γ]
/-!
### Separated uniform spaces
-/
/-- The separation relation is the intersection of all entourages.
Two points which are related by the separation relation are "indistinguishable"
according to the uniform structure. -/
protected def separation_rel (α : Type u) [u : uniform_space α] :=
⋂₀ (𝓤 α).sets
localized "notation `𝓢` := separation_rel" in uniformity
lemma separated_equiv : equivalence (λx y, (x, y) ∈ 𝓢 α) :=
⟨assume x, assume s, refl_mem_uniformity,
assume x y, assume h (s : set (α×α)) hs,
have preimage prod.swap s ∈ 𝓤 α,
from symm_le_uniformity hs,
h _ this,
assume x y z (hxy : (x, y) ∈ 𝓢 α) (hyz : (y, z) ∈ 𝓢 α)
s (hs : s ∈ 𝓤 α),
let ⟨t, ht, (h_ts : comp_rel t t ⊆ s)⟩ := comp_mem_uniformity_sets hs in
h_ts $ show (x, z) ∈ comp_rel t t,
from ⟨y, hxy t ht, hyz t ht⟩⟩
/-- A uniform space is separated if its separation relation is trivial (each point
is related only to itself). -/
class separated_space (α : Type u) [uniform_space α] : Prop := (out : 𝓢 α = id_rel)
theorem separated_space_iff {α : Type u} [uniform_space α] :
separated_space α ↔ 𝓢 α = id_rel :=
⟨λ h, h.1, λ h, ⟨h⟩⟩
theorem separated_def {α : Type u} [uniform_space α] :
separated_space α ↔ ∀ x y, (∀ r ∈ 𝓤 α, (x, y) ∈ r) → x = y :=
by simp [separated_space_iff, id_rel_subset.2 separated_equiv.1, subset.antisymm_iff];
simp [subset_def, separation_rel]
theorem separated_def' {α : Type u} [uniform_space α] :
separated_space α ↔ ∀ x y, x ≠ y → ∃ r ∈ 𝓤 α, (x, y) ∉ r :=
separated_def.trans $ forall₂_congr $ λ x y, by rw ← not_imp_not; simp [not_forall]
lemma eq_of_uniformity {α : Type*} [uniform_space α] [separated_space α] {x y : α}
(h : ∀ {V}, V ∈ 𝓤 α → (x, y) ∈ V) : x = y :=
separated_def.mp ‹separated_space α› x y (λ _, h)
lemma eq_of_uniformity_basis {α : Type*} [uniform_space α] [separated_space α] {ι : Type*}
{p : ι → Prop} {s : ι → set (α × α)} (hs : (𝓤 α).has_basis p s) {x y : α}
(h : ∀ {i}, p i → (x, y) ∈ s i) : x = y :=
eq_of_uniformity (λ V V_in, let ⟨i, hi, H⟩ := hs.mem_iff.mp V_in in H (h hi))
lemma eq_of_forall_symmetric {α : Type*} [uniform_space α] [separated_space α] {x y : α}
(h : ∀ {V}, V ∈ 𝓤 α → symmetric_rel V → (x, y) ∈ V) : x = y :=
eq_of_uniformity_basis has_basis_symmetric (by simpa [and_imp] using λ _, h)
lemma id_rel_sub_separation_relation (α : Type*) [uniform_space α] : id_rel ⊆ 𝓢 α :=
begin
unfold separation_rel,
rw id_rel_subset,
intros x,
suffices : ∀ t ∈ 𝓤 α, (x, x) ∈ t, by simpa only [refl_mem_uniformity],
exact λ t, refl_mem_uniformity,
end
lemma separation_rel_comap {f : α → β}
(h : ‹uniform_space α› = uniform_space.comap f ‹uniform_space β›) :
𝓢 α = (prod.map f f) ⁻¹' 𝓢 β :=
begin
dsimp [separation_rel],
simp_rw [uniformity_comap h, (filter.comap_has_basis (prod.map f f) (𝓤 β)).sInter_sets,
← preimage_Inter, sInter_eq_bInter],
refl,
end
protected lemma filter.has_basis.separation_rel {ι : Sort*} {p : ι → Prop} {s : ι → set (α × α)}
(h : has_basis (𝓤 α) p s) :
𝓢 α = ⋂ i (hi : p i), s i :=
by { unfold separation_rel, rw h.sInter_sets }
lemma separation_rel_eq_inter_closure : 𝓢 α = ⋂₀ (closure '' (𝓤 α).sets) :=
by simp [uniformity_has_basis_closure.separation_rel]
lemma is_closed_separation_rel : is_closed (𝓢 α) :=
begin
rw separation_rel_eq_inter_closure,
apply is_closed_sInter,
rintros _ ⟨t, t_in, rfl⟩,
exact is_closed_closure,
end
lemma separated_iff_t2 : separated_space α ↔ t2_space α :=
begin
classical,
split ; introI h,
{ rw [t2_iff_is_closed_diagonal, ← show 𝓢 α = diagonal α, from h.1],
exact is_closed_separation_rel },
{ rw separated_def',
intros x y hxy,
rcases t2_separation hxy with ⟨u, v, uo, vo, hx, hy, h⟩,
rcases is_open_iff_ball_subset.1 uo x hx with ⟨r, hrU, hr⟩,
exact ⟨r, hrU, λ H, disjoint_iff.2 h ⟨hr H, hy⟩⟩ }
end
@[priority 100] -- see Note [lower instance priority]
instance separated_regular [separated_space α] : regular_space α :=
{ t0 := by { haveI := separated_iff_t2.mp ‹_›, exact t1_space.t0_space.t0 },
regular := λs a hs ha,
have sᶜ ∈ 𝓝 a,
from is_open.mem_nhds hs.is_open_compl ha,
have {p : α × α | p.1 = a → p.2 ∈ sᶜ} ∈ 𝓤 α,
from mem_nhds_uniformity_iff_right.mp this,
let ⟨d, hd, h⟩ := comp_mem_uniformity_sets this in
let e := {y:α| (a, y) ∈ d} in
have hae : a ∈ closure e, from subset_closure $ refl_mem_uniformity hd,
have closure e ×ˢ closure e ⊆ comp_rel d (comp_rel (e ×ˢ e) d),
begin
rw [←closure_prod_eq, closure_eq_inter_uniformity],
change (⨅d' ∈ 𝓤 α, _) ≤ comp_rel d (comp_rel _ d),
exact (infi_le_of_le d $ infi_le_of_le hd $ le_rfl)
end,
have e_subset : closure e ⊆ sᶜ,
from assume a' ha',
let ⟨x, (hx : (a, x) ∈ d), y, ⟨hx₁, hx₂⟩, (hy : (y, _) ∈ d)⟩ := @this ⟨a, a'⟩ ⟨hae, ha'⟩ in
have (a, a') ∈ comp_rel d d, from ⟨y, hx₂, hy⟩,
h this rfl,
have closure e ∈ 𝓝 a, from (𝓝 a).sets_of_superset (mem_nhds_left a hd) subset_closure,
have 𝓝 a ⊓ 𝓟 (closure e)ᶜ = ⊥,
from (is_compl_principal (closure e)).inf_right_eq_bot_iff.2 (le_principal_iff.2 this),
⟨(closure e)ᶜ, is_closed_closure.is_open_compl, assume x h₁ h₂, @e_subset x h₂ h₁, this⟩,
..@t2_space.t1_space _ _ (separated_iff_t2.mp ‹_›) }
lemma is_closed_of_spaced_out [separated_space α] {V₀ : set (α × α)} (V₀_in : V₀ ∈ 𝓤 α)
{s : set α} (hs : s.pairwise (λ x y, (x, y) ∉ V₀)) : is_closed s :=
begin
rcases comp_symm_mem_uniformity_sets V₀_in with ⟨V₁, V₁_in, V₁_symm, h_comp⟩,
apply is_closed_of_closure_subset,
intros x hx,
rw mem_closure_iff_ball at hx,
rcases hx V₁_in with ⟨y, hy, hy'⟩,
suffices : x = y, by rwa this,
apply eq_of_forall_symmetric,
intros V V_in V_symm,
rcases hx (inter_mem V₁_in V_in) with ⟨z, hz, hz'⟩,
obtain rfl : z = y,
{ by_contra hzy,
exact hs hz' hy' hzy (h_comp $ mem_comp_of_mem_ball V₁_symm (ball_inter_left x _ _ hz) hy) },
exact ball_inter_right x _ _ hz
end
lemma is_closed_range_of_spaced_out {ι} [separated_space α] {V₀ : set (α × α)} (V₀_in : V₀ ∈ 𝓤 α)
{f : ι → α} (hf : pairwise (λ x y, (f x, f y) ∉ V₀)) : is_closed (range f) :=
is_closed_of_spaced_out V₀_in $
by { rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ h, exact hf x y (ne_of_apply_ne f h) }
/-!
### Separated sets
-/
/-- A set `s` in a uniform space `α` is separated if the separation relation `𝓢 α`
induces the trivial relation on `s`. -/
def is_separated (s : set α) : Prop := ∀ x y ∈ s, (x, y) ∈ 𝓢 α → x = y
lemma is_separated_def (s : set α) : is_separated s ↔ ∀ x y ∈ s, (x, y) ∈ 𝓢 α → x = y :=
iff.rfl
lemma is_separated_def' (s : set α) : is_separated s ↔ (s ×ˢ s) ∩ 𝓢 α ⊆ id_rel :=
begin
rw is_separated_def,
split,
{ rintros h ⟨x, y⟩ ⟨⟨x_in, y_in⟩, H⟩,
simp [h x x_in y y_in H] },
{ intros h x x_in y y_in xy_in,
rw ← mem_id_rel,
exact h ⟨mk_mem_prod x_in y_in, xy_in⟩ }
end
lemma is_separated.mono {s t : set α} (hs : is_separated s) (hts : t ⊆ s) : is_separated t :=
λ x hx y hy, hs x (hts hx) y (hts hy)
lemma univ_separated_iff : is_separated (univ : set α) ↔ separated_space α :=
begin
simp only [is_separated, mem_univ, true_implies_iff, separated_space_iff],
split,
{ intro h,
exact subset.antisymm (λ ⟨x, y⟩ xy_in, h x y xy_in) (id_rel_sub_separation_relation α), },
{ intros h x y xy_in,
rwa h at xy_in },
end
lemma is_separated_of_separated_space [separated_space α] (s : set α) : is_separated s :=
begin
rw [is_separated, separated_space.out],
tauto,
end
lemma is_separated_iff_induced {s : set α} : is_separated s ↔ separated_space s :=
begin
rw separated_space_iff,
change _ ↔ 𝓢 {x // x ∈ s} = _,
rw [separation_rel_comap rfl, is_separated_def'],
split; intro h,
{ ext ⟨⟨x, x_in⟩, ⟨y, y_in⟩⟩,
suffices : (x, y) ∈ 𝓢 α ↔ x = y, by simpa only [mem_id_rel],
refine ⟨λ H, h ⟨mk_mem_prod x_in y_in, H⟩, _⟩,
rintro rfl,
exact id_rel_sub_separation_relation α rfl },
{ rintros ⟨x, y⟩ ⟨⟨x_in, y_in⟩, hS⟩,
have A : (⟨⟨x, x_in⟩, ⟨y, y_in⟩⟩ : ↥s × ↥s) ∈ prod.map (coe : s → α) (coe : s → α) ⁻¹' 𝓢 α,
from hS,
simpa using h.subset A }
end
lemma eq_of_uniformity_inf_nhds_of_is_separated {s : set α} (hs : is_separated s) :
∀ {x y : α}, x ∈ s → y ∈ s → cluster_pt (x, y) (𝓤 α) → x = y :=
begin
intros x y x_in y_in H,
have : ∀ V ∈ 𝓤 α, (x, y) ∈ closure V,
{ intros V V_in,
rw mem_closure_iff_cluster_pt,
have : 𝓤 α ≤ 𝓟 V, by rwa le_principal_iff,
exact H.mono this },
apply hs x x_in y y_in,
simpa [separation_rel_eq_inter_closure],
end
lemma eq_of_uniformity_inf_nhds [separated_space α] :
∀ {x y : α}, cluster_pt (x, y) (𝓤 α) → x = y :=
begin
have : is_separated (univ : set α),
{ rw univ_separated_iff,
assumption },
introv,
simpa using eq_of_uniformity_inf_nhds_of_is_separated this,
end
/-!
### Separation quotient
-/
namespace uniform_space
/-- The separation relation of a uniform space seen as a setoid. -/
def separation_setoid (α : Type u) [uniform_space α] : setoid α :=
⟨λx y, (x, y) ∈ 𝓢 α, separated_equiv⟩
local attribute [instance] separation_setoid
instance separation_setoid.uniform_space {α : Type u} [u : uniform_space α] :
uniform_space (quotient (separation_setoid α)) :=
{ to_topological_space := u.to_topological_space.coinduced (λx, ⟦x⟧),
uniformity := map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) u.uniformity,
refl := le_trans (by simp [quotient.exists_rep]) (filter.map_mono refl_le_uniformity),
symm := tendsto_map' $
by simp [prod.swap, (∘)]; exact tendsto_map.comp tendsto_swap_uniformity,
comp := calc (map (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) u.uniformity).lift' (λs, comp_rel s s) =
u.uniformity.lift' ((λs, comp_rel s s) ∘ image (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧))) :
map_lift'_eq2 $ monotone_comp_rel monotone_id monotone_id
... ≤ u.uniformity.lift' (image (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) ∘
(λs:set (α×α), comp_rel s (comp_rel s s))) :
lift'_mono' $ assume s hs ⟨a, b⟩ ⟨c, ⟨⟨a₁, a₂⟩, ha, a_eq⟩, ⟨⟨b₁, b₂⟩, hb, b_eq⟩⟩,
begin
simp at a_eq,
simp at b_eq,
have h : ⟦a₂⟧ = ⟦b₁⟧, { rw [a_eq.right, b_eq.left] },
have h : (a₂, b₁) ∈ 𝓢 α := quotient.exact h,
simp [function.comp, set.image, comp_rel, and.comm, and.left_comm, and.assoc],
exact ⟨a₁, a_eq.left, b₂, b_eq.right, a₂, ha, b₁, h s hs, hb⟩
end
... = map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧))
(u.uniformity.lift' (λs:set (α×α), comp_rel s (comp_rel s s))) :
by rw [map_lift'_eq];
exact monotone_comp_rel monotone_id (monotone_comp_rel monotone_id monotone_id)
... ≤ map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) u.uniformity :
map_mono comp_le_uniformity3,
is_open_uniformity := assume s,
have ∀a, ⟦a⟧ ∈ s →
({p:α×α | p.1 = a → ⟦p.2⟧ ∈ s} ∈ 𝓤 α ↔
{p:α×α | p.1 ≈ a → ⟦p.2⟧ ∈ s} ∈ 𝓤 α),
from assume a ha,
⟨assume h,
let ⟨t, ht, hts⟩ := comp_mem_uniformity_sets h in
have hts : ∀{a₁ a₂}, (a, a₁) ∈ t → (a₁, a₂) ∈ t → ⟦a₂⟧ ∈ s,
from assume a₁ a₂ ha₁ ha₂, @hts (a, a₂) ⟨a₁, ha₁, ha₂⟩ rfl,
have ht' : ∀{a₁ a₂}, a₁ ≈ a₂ → (a₁, a₂) ∈ t,
from assume a₁ a₂ h, sInter_subset_of_mem ht h,
u.uniformity.sets_of_superset ht $ assume ⟨a₁, a₂⟩ h₁ h₂, hts (ht' $ setoid.symm h₂) h₁,
assume h, u.uniformity.sets_of_superset h $ by simp {contextual := tt}⟩,
begin
simp [topological_space.coinduced, u.is_open_uniformity, uniformity, forall_quotient_iff],
exact ⟨λh a ha, (this a ha).mp $ h a ha, λh a ha, (this a ha).mpr $ h a ha⟩
end }
lemma uniformity_quotient :
𝓤 (quotient (separation_setoid α)) = (𝓤 α).map (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)) :=
rfl
lemma uniform_continuous_quotient_mk :
uniform_continuous (quotient.mk : α → quotient (separation_setoid α)) :=
le_rfl
lemma uniform_continuous_quotient {f : quotient (separation_setoid α) → β}
(hf : uniform_continuous (λx, f ⟦x⟧)) : uniform_continuous f :=
hf
lemma uniform_continuous_quotient_lift
{f : α → β} {h : ∀a b, (a, b) ∈ 𝓢 α → f a = f b}
(hf : uniform_continuous f) : uniform_continuous (λa, quotient.lift f h a) :=
uniform_continuous_quotient hf
lemma uniform_continuous_quotient_lift₂
{f : α → β → γ} {h : ∀a c b d, (a, b) ∈ 𝓢 α → (c, d) ∈ 𝓢 β → f a c = f b d}
(hf : uniform_continuous (λp:α×β, f p.1 p.2)) :
uniform_continuous (λp:_×_, quotient.lift₂ f h p.1 p.2) :=
begin
rw [uniform_continuous, uniformity_prod_eq_prod, uniformity_quotient, uniformity_quotient,
filter.prod_map_map_eq, filter.tendsto_map'_iff, filter.tendsto_map'_iff],
rwa [uniform_continuous, uniformity_prod_eq_prod, filter.tendsto_map'_iff] at hf
end
lemma comap_quotient_le_uniformity :
(𝓤 $ quotient $ separation_setoid α).comap (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) ≤ (𝓤 α) :=
assume t' ht',
let ⟨t, ht, tt_t'⟩ := comp_mem_uniformity_sets ht' in
let ⟨s, hs, ss_t⟩ := comp_mem_uniformity_sets ht in
⟨(λp:α×α, (⟦p.1⟧, ⟦p.2⟧)) '' s,
(𝓤 α).sets_of_superset hs $ assume x hx, ⟨x, hx, rfl⟩,
assume ⟨a₁, a₂⟩ ⟨⟨b₁, b₂⟩, hb, ab_eq⟩,
have ⟦b₁⟧ = ⟦a₁⟧ ∧ ⟦b₂⟧ = ⟦a₂⟧, from prod.mk.inj ab_eq,
have b₁ ≈ a₁ ∧ b₂ ≈ a₂, from and.imp quotient.exact quotient.exact this,
have ab₁ : (a₁, b₁) ∈ t, from (setoid.symm this.left) t ht,
have ba₂ : (b₂, a₂) ∈ s, from this.right s hs,
tt_t' ⟨b₁, show ((a₁, a₂).1, b₁) ∈ t, from ab₁,
ss_t ⟨b₂, show ((b₁, a₂).1, b₂) ∈ s, from hb, ba₂⟩⟩⟩
lemma comap_quotient_eq_uniformity :
(𝓤 $ quotient $ separation_setoid α).comap (λ (p : α × α), (⟦p.fst⟧, ⟦p.snd⟧)) = 𝓤 α :=
le_antisymm comap_quotient_le_uniformity le_comap_map
instance separated_separation : separated_space (quotient (separation_setoid α)) :=
⟨set.ext $ assume ⟨a, b⟩, quotient.induction_on₂ a b $ assume a b,
⟨assume h,
have a ≈ b, from assume s hs,
have s ∈ (𝓤 $ quotient $ separation_setoid α).comap (λp:(α×α), (⟦p.1⟧, ⟦p.2⟧)),
from comap_quotient_le_uniformity hs,
let ⟨t, ht, hts⟩ := this in
hts begin dsimp [preimage], exact h t ht end,
show ⟦a⟧ = ⟦b⟧, from quotient.sound this,
assume heq : ⟦a⟧ = ⟦b⟧, assume h hs,
heq ▸ refl_mem_uniformity hs⟩⟩
lemma separated_of_uniform_continuous {f : α → β} {x y : α}
(H : uniform_continuous f) (h : x ≈ y) : f x ≈ f y :=
assume _ h', h _ (H h')
lemma eq_of_separated_of_uniform_continuous [separated_space β] {f : α → β} {x y : α}
(H : uniform_continuous f) (h : x ≈ y) : f x = f y :=
separated_def.1 (by apply_instance) _ _ $ separated_of_uniform_continuous H h
lemma _root_.is_separated.eq_of_uniform_continuous {f : α → β} {x y : α} {s : set β}
(hs : is_separated s) (hxs : f x ∈ s) (hys : f y ∈ s) (H : uniform_continuous f) (h : x ≈ y) :
f x = f y :=
(is_separated_def _).mp hs _ hxs _ hys $ λ _ h', h _ (H h')
/-- The maximal separated quotient of a uniform space `α`. -/
def separation_quotient (α : Type*) [uniform_space α] := quotient (separation_setoid α)
namespace separation_quotient
instance : uniform_space (separation_quotient α) := separation_setoid.uniform_space
instance : separated_space (separation_quotient α) := uniform_space.separated_separation
instance [inhabited α] : inhabited (separation_quotient α) :=
quotient.inhabited (separation_setoid α)
/-- Factoring functions to a separated space through the separation quotient. -/
def lift [separated_space β] (f : α → β) : (separation_quotient α → β) :=
if h : uniform_continuous f then
quotient.lift f (λ x y, eq_of_separated_of_uniform_continuous h)
else
λ x, f (nonempty.some ⟨x.out⟩)
lemma lift_mk [separated_space β] {f : α → β} (h : uniform_continuous f) (a : α) :
lift f ⟦a⟧ = f a :=
by rw [lift, dif_pos h]; refl
lemma uniform_continuous_lift [separated_space β] (f : α → β) : uniform_continuous (lift f) :=
begin
by_cases hf : uniform_continuous f,
{ rw [lift, dif_pos hf], exact uniform_continuous_quotient_lift hf },
{ rw [lift, dif_neg hf], exact uniform_continuous_of_const (assume a b, rfl) }
end
/-- The separation quotient functor acting on functions. -/
def map (f : α → β) : separation_quotient α → separation_quotient β :=
lift (quotient.mk ∘ f)
lemma map_mk {f : α → β} (h : uniform_continuous f) (a : α) : map f ⟦a⟧ = ⟦f a⟧ :=
by rw [map, lift_mk (uniform_continuous_quotient_mk.comp h)]
lemma uniform_continuous_map (f : α → β) : uniform_continuous (map f) :=
uniform_continuous_lift (quotient.mk ∘ f)
lemma map_unique {f : α → β} (hf : uniform_continuous f)
{g : separation_quotient α → separation_quotient β}
(comm : quotient.mk ∘ f = g ∘ quotient.mk) : map f = g :=
by ext ⟨a⟩;
calc map f ⟦a⟧ = ⟦f a⟧ : map_mk hf a
... = g ⟦a⟧ : congr_fun comm a
lemma map_id : map (@id α) = id :=
map_unique uniform_continuous_id rfl
lemma map_comp {f : α → β} {g : β → γ} (hf : uniform_continuous f) (hg : uniform_continuous g) :
map g ∘ map f = map (g ∘ f) :=
(map_unique (hg.comp hf) $ by simp only [(∘), map_mk, hf, hg]).symm
end separation_quotient
lemma separation_prod {a₁ a₂ : α} {b₁ b₂ : β} : (a₁, b₁) ≈ (a₂, b₂) ↔ a₁ ≈ a₂ ∧ b₁ ≈ b₂ :=
begin
split,
{ assume h,
exact ⟨separated_of_uniform_continuous uniform_continuous_fst h,
separated_of_uniform_continuous uniform_continuous_snd h⟩ },
{ rintros ⟨eqv_α, eqv_β⟩ r r_in,
rw uniformity_prod at r_in,
rcases r_in with ⟨t_α, ⟨r_α, r_α_in, h_α⟩, t_β, ⟨r_β, r_β_in, h_β⟩, rfl⟩,
let p_α := λ(p : (α × β) × (α × β)), (p.1.1, p.2.1),
let p_β := λ(p : (α × β) × (α × β)), (p.1.2, p.2.2),
have key_α : p_α ((a₁, b₁), (a₂, b₂)) ∈ r_α, { simp [p_α, eqv_α r_α r_α_in] },
have key_β : p_β ((a₁, b₁), (a₂, b₂)) ∈ r_β, { simp [p_β, eqv_β r_β r_β_in] },
exact ⟨h_α key_α, h_β key_β⟩ },
end
instance separated.prod [separated_space α] [separated_space β] : separated_space (α × β) :=
separated_def.2 $ assume x y H, prod.ext
(eq_of_separated_of_uniform_continuous uniform_continuous_fst H)
(eq_of_separated_of_uniform_continuous uniform_continuous_snd H)
lemma _root_.is_separated.prod {s : set α} {t : set β} (hs : is_separated s) (ht : is_separated t) :
is_separated (s ×ˢ t) :=
(is_separated_def _).mpr $ λ x hx y hy H, prod.ext
(hs.eq_of_uniform_continuous hx.1 hy.1 uniform_continuous_fst H)
(ht.eq_of_uniform_continuous hx.2 hy.2 uniform_continuous_snd H)
end uniform_space
|
8f45ef3201d4363fd67e56d670b99fd223a777c2
|
77c5b91fae1b966ddd1db969ba37b6f0e4901e88
|
/src/data/fin/interval.lean
|
95d8fb0c2b96a010c6e49d6e6621ded1eaea94ae
|
[
"Apache-2.0"
] |
permissive
|
dexmagic/mathlib
|
ff48eefc56e2412429b31d4fddd41a976eb287ce
|
7a5d15a955a92a90e1d398b2281916b9c41270b2
|
refs/heads/master
| 1,693,481,322,046
| 1,633,360,193,000
| 1,633,360,193,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,062
|
lean
|
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.nat.interval
/-!
# Finite intervals in `fin n`
This file proves that `fin n` is a `locally_finite_order` and calculates the cardinality of its
intervals as finsets and fintypes.
## TODO
@Yaël: Add `finset.Ico`. Coming very soon.
-/
open finset fin
variables (n : ℕ)
instance : locally_finite_order (fin n) := subtype.locally_finite_order _
namespace fin
variables {n} (a b : fin n)
lemma Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).subtype (λ x, x < n) := rfl
lemma Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).subtype (λ x, x < n) := rfl
lemma Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).subtype (λ x, x < n) := rfl
@[simp] lemma map_subtype_embedding_Icc :
(Icc a b).map (function.embedding.subtype _) = Icc (a : ℕ) b :=
map_subtype_embedding_Icc _ _ _ (λ _ c x _ hx _, hx.trans_lt)
@[simp] lemma map_subtype_embedding_Ioc :
(Ioc a b).map (function.embedding.subtype _) = Ioc (a : ℕ) b :=
map_subtype_embedding_Ioc _ _ _ (λ _ c x _ hx _, hx.trans_lt)
@[simp] lemma map_subtype_embedding_Ioo :
(Ioo a b).map (function.embedding.subtype _) = Ioo (a : ℕ) b :=
map_subtype_embedding_Ioo _ _ _ (λ _ c x _ hx _, hx.trans_lt)
@[simp] lemma card_Icc : (Icc a b).card = b + 1 - a :=
by rw [←nat.card_Icc, ←map_subtype_embedding_Icc, card_map]
@[simp] lemma card_Ioc : (Ioc a b).card = b - a :=
by rw [←nat.card_Ioc, ←map_subtype_embedding_Ioc, card_map]
@[simp] lemma card_Ioo : (Ioo a b).card = b - a - 1 :=
by rw [←nat.card_Ioo, ←map_subtype_embedding_Ioo, card_map]
@[simp] lemma card_fintype_Icc : fintype.card (set.Icc a b) = b + 1 - a :=
by rw [←card_Icc, fintype.card_of_finset]
@[simp] lemma card_fintype_Ioc : fintype.card (set.Ioc a b) = b - a :=
by rw [←card_Ioc, fintype.card_of_finset]
@[simp] lemma card_fintype_Ioo : fintype.card (set.Ioo a b) = b - a - 1 :=
by rw [←card_Ioo, fintype.card_of_finset]
end fin
|
b6a36b7c30f4f0b4d83446d821e404c2580434e9
|
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
|
/tests/lean/run/e2.lean
|
0d0f059fc519dd0cf5c4f3031efde57e213774dc
|
[
"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
| 39
|
lean
|
definition Prop := Type.{0}
check Prop
|
0981be48510bf414f1cfaca4c501154563b76250
|
3f7026ea8bef0825ca0339a275c03b911baef64d
|
/src/order/filter/basic.lean
|
2d0d5237591116fe03d1a2f32e33a3c55911a0e6
|
[
"Apache-2.0"
] |
permissive
|
rspencer01/mathlib
|
b1e3afa5c121362ef0881012cc116513ab09f18c
|
c7d36292c6b9234dc40143c16288932ae38fdc12
|
refs/heads/master
| 1,595,010,346,708
| 1,567,511,503,000
| 1,567,511,503,000
| 206,071,681
| 0
| 0
|
Apache-2.0
| 1,567,513,643,000
| 1,567,513,643,000
| null |
UTF-8
|
Lean
| false
| false
| 82,021
|
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, Jeremy Avigad
Theory of filters on sets.
-/
import order.galois_connection order.zorn
import data.set.finite
open lattice set
universes u v w x y
local attribute [instance] classical.prop_decidable
namespace lattice
variables {α : Type u} {ι : Sort v}
def complete_lattice.copy (c : complete_lattice α)
(le : α → α → Prop) (eq_le : le = @complete_lattice.le α c)
(top : α) (eq_top : top = @complete_lattice.top α c)
(bot : α) (eq_bot : bot = @complete_lattice.bot α c)
(sup : α → α → α) (eq_sup : sup = @complete_lattice.sup α c)
(inf : α → α → α) (eq_inf : inf = @complete_lattice.inf α c)
(Sup : set α → α) (eq_Sup : Sup = @complete_lattice.Sup α c)
(Inf : set α → α) (eq_Inf : Inf = @complete_lattice.Inf α c) :
complete_lattice α :=
begin
refine { le := le, top := top, bot := bot, sup := sup, inf := inf, Sup := Sup, Inf := Inf, ..};
subst_vars,
exact @complete_lattice.le_refl α c,
exact @complete_lattice.le_trans α c,
exact @complete_lattice.le_antisymm α c,
exact @complete_lattice.le_sup_left α c,
exact @complete_lattice.le_sup_right α c,
exact @complete_lattice.sup_le α c,
exact @complete_lattice.inf_le_left α c,
exact @complete_lattice.inf_le_right α c,
exact @complete_lattice.le_inf α c,
exact @complete_lattice.le_top α c,
exact @complete_lattice.bot_le α c,
exact @complete_lattice.le_Sup α c,
exact @complete_lattice.Sup_le α c,
exact @complete_lattice.Inf_le α c,
exact @complete_lattice.le_Inf α c
end
end lattice
open set lattice
section order
variables {α : Type u} (r : α → α → Prop)
local infix ` ≼ ` : 50 := r
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 only [directed_on, exists_prop, mem_Union, exists_imp_distrib]; 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, ⟨z, xf⟩, xa₁, xa₂⟩
end order
theorem directed_of_chain {α β r} [is_refl β r] {f : α → β} {c : set α}
(h : zorn.chain (f ⁻¹'o r) c) :
directed r (λx:{a:α // a ∈ c}, f (x.val)) :=
assume ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases
(assume : a = b, by simp only [this, exists_prop, and_self, subtype.exists];
exact ⟨b, hb, refl _⟩)
(assume : a ≠ b, (h a ha b hb this).elim
(λ h : r (f a) (f b), ⟨⟨b, hb⟩, h, refl _⟩)
(λ h : r (f b) (f a), ⟨⟨a, ha⟩, refl _, h⟩))
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)
/-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/
@[reducible]
instance {α : Type*}: has_mem (set α) (filter α) := ⟨λ U F, U ∈ F.sets⟩
namespace filter
variables {α : Type u} {f g : filter α} {s t : set α}
lemma filter_eq : ∀{f g : filter α}, f.sets = g.sets → f = g
| ⟨a, _, _, _⟩ ⟨._, _, _, _⟩ rfl := rfl
lemma filter_eq_iff : f = g ↔ f.sets = g.sets :=
⟨congr_arg _, filter_eq⟩
protected lemma ext_iff : f = g ↔ ∀ s, s ∈ f ↔ s ∈ g :=
by rw [filter_eq_iff, ext_iff]
@[extensionality]
protected lemma ext : (∀ s, s ∈ f ↔ s ∈ g) → f = g :=
filter.ext_iff.2
lemma univ_mem_sets : univ ∈ f :=
f.univ_sets
lemma mem_sets_of_superset : ∀{x y : set α}, x ∈ f → x ⊆ y → y ∈ f :=
f.sets_of_superset
lemma inter_mem_sets : ∀{s t}, s ∈ f → t ∈ f → s ∩ t ∈ f :=
f.inter_sets
lemma univ_mem_sets' (h : ∀ a, a ∈ s) : s ∈ f :=
mem_sets_of_superset univ_mem_sets (assume x _, h x)
lemma mp_sets (hs : s ∈ f) (h : {x | x ∈ s → x ∈ t} ∈ f) : t ∈ f :=
mem_sets_of_superset (inter_mem_sets hs h) $ assume x ⟨h₁, h₂⟩, h₂ h₁
lemma congr_sets (h : {x | x ∈ s ↔ x ∈ t} ∈ f) : s ∈ f ↔ t ∈ f :=
⟨λ hs, mp_sets hs (mem_sets_of_superset h (λ x, iff.mp)),
λ hs, mp_sets hs (mem_sets_of_superset h (λ x, iff.mpr))⟩
lemma Inter_mem_sets {β : Type v} {s : β → set α} {is : set β} (hf : finite is) :
(∀i∈is, s i ∈ f) → (⋂i∈is, s i) ∈ f :=
finite.induction_on hf
(assume hs, by simp only [univ_mem_sets, mem_empty_eq, Inter_neg, Inter_univ, not_false_iff])
(assume i is _ hf hi hs,
have h₁ : s i ∈ f, from hs i (by simp),
have h₂ : (⋂x∈is, s x) ∈ f, from hi $ assume a ha, hs _ $ by simp only [ha, mem_insert_iff, or_true],
by simp [inter_mem_sets h₁ h₂])
lemma exists_sets_subset_iff : (∃t ∈ f, t ⊆ s) ↔ s ∈ f :=
⟨assume ⟨t, ht, ts⟩, mem_sets_of_superset ht ts, assume hs, ⟨s, hs, subset.refl _⟩⟩
lemma monotone_mem_sets {f : filter α} : monotone (λs, s ∈ f) :=
assume s t hst h, mem_sets_of_superset h hst
end filter
namespace tactic.interactive
open tactic interactive
/-- `filter_upwards [h1, ⋯, hn]` replaces a goal of the form `s ∈ f`
and terms `h1 : t1 ∈ f, ⋯, hn : tn ∈ f` with `∀x, x ∈ t1 → ⋯ → x ∈ tn → x ∈ s`.
`filter_upwards [h1, ⋯, hn] e` is a short form for `{ filter_upwards [h1, ⋯, hn], exact e }`.
-/
meta def filter_upwards
(s : parse types.pexpr_list)
(e' : parse $ optional types.texpr) : tactic unit :=
do
s.reverse.mmap (λ e, eapplyc `filter.mp_sets >> eapply e),
eapplyc `filter.univ_mem_sets',
match e' with
| some e := interactive.exact e
| none := skip
end
end tactic.interactive
namespace filter
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
section principal
/-- The principal filter of `s` is the collection of all supersets of `s`. -/
def principal (s : set α) : filter α :=
{ sets := {t | s ⊆ t},
univ_sets := subset_univ s,
sets_of_superset := assume x y hx hy, subset.trans hx hy,
inter_sets := assume x y, subset_inter }
instance : inhabited (filter α) :=
⟨principal ∅⟩
@[simp] lemma mem_principal_sets {s t : set α} : s ∈ principal t ↔ t ⊆ s := iff.rfl
lemma mem_principal_self (s : set α) : s ∈ principal s := subset.refl _
end principal
section join
/-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/
def join (f : filter (filter α)) : filter α :=
{ sets := {s | {t : filter α | s ∈ t} ∈ f},
univ_sets := by simp only [univ_mem_sets, mem_set_of_eq]; exact univ_mem_sets,
sets_of_superset := assume x y hx xy,
mem_sets_of_superset hx $ assume f h, mem_sets_of_superset h xy,
inter_sets := assume x y hx hy,
mem_sets_of_superset (inter_mem_sets hx hy) $ assume f ⟨h₁, h₂⟩, inter_mem_sets h₁ h₂ }
@[simp] lemma mem_join_sets {s : set α} {f : filter (filter α)} :
s ∈ join f ↔ {t | s ∈ filter.sets t} ∈ f := iff.rfl
end join
section lattice
instance : partial_order (filter α) :=
{ 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₁ }
theorem le_def {f g : filter α} : f ≤ g ↔ ∀ x ∈ g, x ∈ f := iff.rfl
/-- `generate_sets g s`: `s` is in the filter closure of `g`. -/
inductive generate_sets (g : set (set α)) : set α → Prop
| basic {s : set α} : s ∈ g → generate_sets s
| univ {} : generate_sets univ
| superset {s t : set α} : generate_sets s → s ⊆ t → generate_sets t
| inter {s t : set α} : generate_sets s → generate_sets t → generate_sets (s ∩ t)
/-- `generate g` is the smallest filter containing the sets `g`. -/
def generate (g : set (set α)) : filter α :=
{ sets := {s | generate_sets g s},
univ_sets := generate_sets.univ,
sets_of_superset := assume x y, generate_sets.superset,
inter_sets := assume s t, generate_sets.inter }
lemma sets_iff_generate {s : set (set α)} {f : filter α} : f ≤ filter.generate s ↔ s ⊆ f.sets :=
iff.intro
(assume h u hu, h $ generate_sets.basic $ hu)
(assume h u hu, hu.rec_on h univ_mem_sets
(assume x y _ hxy hx, mem_sets_of_superset hx hxy)
(assume x y _ _ hx hy, inter_mem_sets hx hy))
protected def mk_of_closure (s : set (set α)) (hs : (generate s).sets = s) : filter α :=
{ sets := s,
univ_sets := hs ▸ (univ_mem_sets : univ ∈ generate s),
sets_of_superset := assume x y, hs ▸ (mem_sets_of_superset : x ∈ generate s → x ⊆ y → y ∈ generate s),
inter_sets := assume x y, hs ▸ (inter_mem_sets : x ∈ generate s → y ∈ generate s → x ∩ y ∈ generate s) }
lemma mk_of_closure_sets {s : set (set α)} {hs : (generate s).sets = s} :
filter.mk_of_closure s hs = generate s :=
filter.ext $ assume u,
show u ∈ (filter.mk_of_closure s hs).sets ↔ u ∈ (generate s).sets, from hs.symm ▸ iff.refl _
/- Galois insertion from sets of sets into a filters. -/
def gi_generate (α : Type*) :
@galois_insertion (set (set α)) (order_dual (filter α)) _ _ filter.generate filter.sets :=
{ gc := assume s f, sets_iff_generate,
le_l_u := assume f u, generate_sets.basic,
choice := λs hs, filter.mk_of_closure s (le_antisymm hs $ sets_iff_generate.1 $ le_refl _),
choice_eq := assume s hs, mk_of_closure_sets }
/-- The infimum of filters is the filter generated by intersections
of elements of the two filters. -/
instance : has_inf (filter α) := ⟨λf g : filter α,
{ sets := {s | ∃ (a ∈ f) (b ∈ g), a ∩ b ⊆ s },
univ_sets := ⟨_, univ_mem_sets, _, univ_mem_sets, inter_subset_left _ _⟩,
sets_of_superset := assume x y ⟨a, ha, b, hb, h⟩ xy, ⟨a, ha, b, hb, subset.trans h xy⟩,
inter_sets := assume x y ⟨a, ha, b, hb, hx⟩ ⟨c, hc, d, hd, hy⟩,
⟨_, inter_mem_sets ha hc, _, inter_mem_sets hb hd,
calc a ∩ c ∩ (b ∩ d) = (a ∩ b) ∩ (c ∩ d) : by ac_refl
... ⊆ x ∩ y : inter_subset_inter hx hy⟩ }⟩
@[simp] lemma mem_inf_sets {f g : filter α} {s : set α} :
s ∈ f ⊓ g ↔ ∃t₁∈f.sets, ∃t₂∈g.sets, t₁ ∩ t₂ ⊆ s := iff.rfl
lemma mem_inf_sets_of_left {f g : filter α} {s : set α} (h : s ∈ f) : s ∈ f ⊓ g :=
⟨s, h, univ, univ_mem_sets, inter_subset_left _ _⟩
lemma mem_inf_sets_of_right {f g : filter α} {s : set α} (h : s ∈ g) : s ∈ f ⊓ g :=
⟨univ, univ_mem_sets, s, h, inter_subset_right _ _⟩
lemma inter_mem_inf_sets {α : Type u} {f g : filter α} {s t : set α}
(hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g :=
inter_mem_sets (mem_inf_sets_of_left hs) (mem_inf_sets_of_right ht)
instance : has_top (filter α) :=
⟨{ sets := {s | ∀x, x ∈ s},
univ_sets := assume x, mem_univ x,
sets_of_superset := assume x y hx hxy a, hxy (hx a),
inter_sets := assume x y hx hy a, mem_inter (hx _) (hy _) }⟩
lemma mem_top_sets_iff_forall {s : set α} : s ∈ (⊤ : filter α) ↔ (∀x, x ∈ s) :=
iff.refl _
@[simp] lemma mem_top_sets {s : set α} : s ∈ (⊤ : filter α) ↔ s = univ :=
by rw [mem_top_sets_iff_forall, eq_univ_iff_forall]
section complete_lattice
/- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately,
we want to have different definitional equalities for the lattice operations. So we define them
upfront and change the lattice operations for the complete lattice instance. -/
private def original_complete_lattice : complete_lattice (filter α) :=
@order_dual.lattice.complete_lattice _ (gi_generate α).lift_complete_lattice
local attribute [instance] original_complete_lattice
instance : complete_lattice (filter α) := original_complete_lattice.copy
/- le -/ filter.partial_order.le rfl
/- top -/ (filter.lattice.has_top).1
(top_unique $ assume s hs, by have := univ_mem_sets ; finish)
/- bot -/ _ rfl
/- sup -/ _ rfl
/- inf -/ (filter.lattice.has_inf).1
begin
ext f g : 2,
exact le_antisymm
(le_inf (assume s, mem_inf_sets_of_left) (assume s, mem_inf_sets_of_right))
(assume s ⟨a, ha, b, hb, hs⟩, show s ∈ complete_lattice.inf f g, from
mem_sets_of_superset (inter_mem_sets
(@inf_le_left (filter α) _ _ _ _ ha)
(@inf_le_right (filter α) _ _ _ _ hb)) hs)
end
/- Sup -/ (join ∘ principal) (by ext s x; exact (@mem_bInter_iff _ _ s filter.sets x).symm)
/- Inf -/ _ rfl
end complete_lattice
lemma bot_sets_eq : (⊥ : filter α).sets = univ := rfl
lemma sup_sets_eq {f g : filter α} : (f ⊔ g).sets = f.sets ∩ g.sets :=
(gi_generate α).gc.u_inf
lemma Sup_sets_eq {s : set (filter α)} : (Sup s).sets = (⋂f∈s, (f:filter α).sets) :=
(gi_generate α).gc.u_Inf
lemma supr_sets_eq {f : ι → filter α} : (supr f).sets = (⋂i, (f i).sets) :=
(gi_generate α).gc.u_infi
lemma generate_empty : filter.generate ∅ = (⊤ : filter α) :=
(gi_generate α).gc.l_bot
lemma generate_univ : filter.generate univ = (⊥ : filter α) :=
mk_of_closure_sets.symm
lemma generate_union {s t : set (set α)} :
filter.generate (s ∪ t) = filter.generate s ⊓ filter.generate t :=
(gi_generate α).gc.l_sup
lemma generate_Union {s : ι → set (set α)} :
filter.generate (⋃ i, s i) = (⨅ i, filter.generate (s i)) :=
(gi_generate α).gc.l_supr
@[simp] lemma mem_bot_sets {s : set α} : s ∈ (⊥ : filter α) :=
trivial
@[simp] lemma mem_sup_sets {f g : filter α} {s : set α} :
s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g :=
iff.rfl
@[simp] lemma mem_Sup_sets {x : set α} {s : set (filter α)} :
x ∈ Sup s ↔ (∀f∈s, x ∈ (f:filter α)) :=
iff.rfl
@[simp] lemma mem_supr_sets {x : set α} {f : ι → filter α} :
x ∈ supr f ↔ (∀i, x ∈ f i) :=
by simp only [supr_sets_eq, iff_self, mem_Inter]
@[simp] lemma le_principal_iff {s : set α} {f : filter α} : f ≤ principal s ↔ s ∈ f :=
show (∀{t}, s ⊆ t → t ∈ f) ↔ s ∈ f,
from ⟨assume h, h (subset.refl s), assume hs t ht, mem_sets_of_superset hs ht⟩
lemma principal_mono {s t : set α} : principal s ≤ principal t ↔ s ⊆ t :=
by simp only [le_principal_iff, iff_self, mem_principal_sets]
lemma monotone_principal : monotone (principal : set α → filter α) :=
by simp only [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 only [le_antisymm_iff, le_principal_iff, mem_principal_sets]; refl
@[simp] lemma join_principal_eq_Sup {s : set (filter α)} : join (principal s) = Sup s := rfl
/- lattice equations -/
lemma empty_in_sets_eq_bot {f : filter α} : ∅ ∈ f ↔ f = ⊥ :=
⟨assume h, bot_unique $ assume s _, mem_sets_of_superset 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) :
∃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 $ univ_mem_sets' $ assume x, false.elim (ne ⟨x⟩)
lemma forall_sets_neq_empty_iff_neq_bot {f : filter α} :
(∀ (s : set α), s ∈ f → s ≠ ∅) ↔ f ≠ ⊥ :=
by
simp only [(@empty_in_sets_eq_bot α f).symm, ne.def];
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 :=
have ∅ ∈ f ⊓ principal (- s), from h.symm ▸ mem_bot_sets,
let ⟨s₁, hs₁, s₂, (hs₂ : -s ⊆ s₂), (hs : s₁ ∩ s₂ ⊆ ∅)⟩ := this in
by filter_upwards [hs₁] assume a ha, classical.by_contradiction $ assume ha', hs ⟨ha, hs₂ ha'⟩
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),
univ_sets := by simp only [mem_Union]; exact ⟨i, univ_mem_sets⟩,
sets_of_superset := by simp only [mem_Union, exists_imp_distrib];
intros x y i hx hxy; exact ⟨i, mem_sets_of_superset hx hxy⟩,
inter_sets :=
begin
simp only [mem_Union, exists_imp_distrib],
assume x y a hx b hy,
rcases h a b with ⟨c, ha, hb⟩,
exact ⟨c, inter_mem_sets (ha hx) (hb hy)⟩
end } 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 mem_infi {f : ι → filter α} (h : directed (≥) f) (ne : nonempty ι) (s) :
s ∈ infi f ↔ s ∈ ⋃ i, (f i).sets :=
show s ∈ (infi f).sets ↔ s ∈ ⋃ i, (f i).sets, by rw infi_sets_eq h ne
lemma infi_sets_eq' {f : β → filter α} {s : set β}
(h : directed_on (f ⁻¹'o (≥)) 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 rw [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 rw [supr_subtype]; refl
lemma infi_sets_eq_finite (f : ι → filter α) :
(⨅i, f i).sets = (⋃t:finset (plift ι), (⨅i∈t, f (plift.down i)).sets) :=
begin
rw [infi_eq_infi_finset, infi_sets_eq],
exact (directed_of_sup $ λs₁ s₂ hs, infi_le_infi $ λi, infi_le_infi_const $ λh, hs h),
apply_instance
end
lemma mem_infi_finite {f : ι → filter α} (s) :
s ∈ infi f ↔ s ∈ ⋃t:finset (plift ι), (⨅i∈t, f (plift.down i)).sets :=
show s ∈ (infi f).sets ↔ s ∈ ⋃t:finset (plift ι), (⨅i∈t, f (plift.down i)).sets,
by rw infi_sets_eq_finite
@[simp] lemma sup_join {f₁ f₂ : filter (filter α)} : (join f₁ ⊔ join f₂) = join (f₁ ⊔ f₂) :=
filter_eq $ set.ext $ assume x,
by simp only [supr_sets_eq, join, mem_sup_sets, iff_self, mem_set_of_eq]
@[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 only [supr_sets_eq, join, iff_self, mem_Inter, mem_set_of_eq]
instance : bounded_distrib_lattice (filter α) :=
{ le_sup_inf :=
begin
assume x y z s,
simp only [and_assoc, mem_inf_sets, mem_sup_sets, exists_prop, exists_imp_distrib, and_imp],
intros hs t₁ ht₁ t₂ ht₂ hts,
exact ⟨s ∪ t₁,
x.sets_of_superset hs $ subset_union_left _ _,
y.sets_of_superset ht₁ $ subset_union_right _ _,
s ∪ t₂,
x.sets_of_superset hs $ subset_union_left _ _,
z.sets_of_superset ht₂ $ subset_union_right _ _,
subset.trans (@le_sup_inf (set α) _ _ _ _) (union_subset (subset.refl _) hts)⟩
end,
..filter.lattice.complete_lattice }
/- the complementary version with ⨆i, f ⊓ g i does not hold! -/
lemma infi_sup_eq {f : filter α} {g : ι → filter α} : (⨅ x, f ⊔ g x) = f ⊔ infi g :=
begin
refine le_antisymm _ (le_infi $ assume i, sup_le_sup (le_refl f) $ infi_le _ _),
rintros t ⟨h₁, h₂⟩,
rw [infi_sets_eq_finite] at h₂,
simp only [mem_Union, (finset.inf_eq_infi _ _).symm] at h₂,
rcases h₂ with ⟨s, hs⟩,
suffices : (⨅i, f ⊔ g i) ≤ f ⊔ s.inf (λi, g i.down), { exact this ⟨h₁, hs⟩ },
refine finset.induction_on s _ _,
{ exact le_sup_right_of_le le_top },
{ rintros ⟨i⟩ s his ih,
rw [finset.inf_insert, sup_inf_left],
exact le_inf (infi_le _ _) ih }
end
lemma mem_infi_sets_finset {s : finset α} {f : α → filter β} :
∀t, t ∈ (⨅a∈s, f a) ↔ (∃p:α → set β, (∀a∈s, p a ∈ f a) ∧ (⋂a∈s, p a) ⊆ t) :=
show ∀t, t ∈ (⨅a∈s, f a) ↔ (∃p:α → set β, (∀a∈s, p a ∈ f a) ∧ (⨅a∈s, p a) ≤ t),
begin
simp only [(finset.inf_eq_infi _ _).symm],
refine finset.induction_on s _ _,
{ simp only [finset.not_mem_empty, false_implies_iff, finset.inf_empty, top_le_iff,
imp_true_iff, mem_top_sets, true_and, exists_const],
intros; refl },
{ intros a s has ih t,
simp only [ih, finset.forall_mem_insert, finset.inf_insert, mem_inf_sets,
exists_prop, iff_iff_implies_and_implies, exists_imp_distrib, and_imp, and_assoc] {contextual := tt},
split,
{ intros t₁ ht₁ t₂ p hp ht₂ ht,
existsi function.update p a t₁,
have : ∀a'∈s, function.update p a t₁ a' = p a',
from assume a' ha',
have a' ≠ a, from assume h, has $ h ▸ ha',
function.update_noteq this,
have eq : s.inf (λj, function.update p a t₁ j) = s.inf (λj, p j) :=
finset.inf_congr rfl this,
simp only [this, ht₁, hp, function.update_same, true_and, imp_true_iff, eq] {contextual := tt},
exact subset.trans (inter_subset_inter (subset.refl _) ht₂) ht },
assume p hpa hp ht,
exact ⟨p a, hpa, (s.inf p), ⟨⟨p, hp, le_refl _⟩, ht⟩⟩ }
end
/- 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, by simp⟩)
(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 only [union_subset_iff, union_subset_iff, mem_sup_sets, forall_const, iff_self, mem_principal_sets]
@[simp] lemma supr_principal {ι : Sort w} {s : ι → set α} : (⨆x, principal (s x)) = principal (⋃i, s i) :=
filter_eq $ set.ext $ assume x, by simp only [supr_sets_eq, mem_principal_sets, mem_Inter];
exact (@supr_le_iff (set α) _ _ _ _).symm
lemma principal_univ : principal (univ : set α) = ⊤ :=
top_unique $ by simp only [le_principal_iff, mem_top_sets, eq_self_iff_true]
lemma principal_empty : principal (∅ : set α) = ⊥ :=
bot_unique $ assume s _, empty_subset _
@[simp] lemma principal_eq_bot_iff {s : set α} : principal s = ⊥ ↔ s = ∅ :=
⟨assume h, principal_eq_iff_eq.mp $ by simp only [principal_empty, h, eq_self_iff_true],
assume h, by simp only [h, principal_empty, eq_self_iff_true]⟩
lemma inf_principal_eq_bot {f : filter α} {s : set α} (hs : -s ∈ f) : f ⊓ principal s = ⊥ :=
empty_in_sets_eq_bot.mp ⟨_, hs, s, mem_principal_self s, assume x ⟨h₁, h₂⟩, h₁ h₂⟩
theorem mem_inf_principal (f : filter α) (s t : set α) :
s ∈ f ⊓ principal t ↔ { x | x ∈ t → x ∈ s } ∈ f :=
begin
simp only [mem_inf_sets, mem_principal_sets, exists_prop], split,
{ rintros ⟨u, ul, v, tsubv, uvinter⟩,
apply filter.mem_sets_of_superset ul,
intros x xu xt, exact uvinter ⟨xu, tsubv xt⟩ },
intro h, refine ⟨_, h, t, set.subset.refl t, _⟩,
rintros x ⟨hx, xt⟩,
exact hx xt
end
end lattice
section map
/-- The forward map of a filter -/
def map (m : α → β) (f : filter α) : filter β :=
{ sets := preimage m ⁻¹' f.sets,
univ_sets := univ_mem_sets,
sets_of_superset := assume s t hs st, mem_sets_of_superset hs $ preimage_mono st,
inter_sets := assume s t hs ht, inter_mem_sets hs ht }
@[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.symm
variables {f : filter α} {m : α → β} {m' : β → γ} {s : set α} {t : set β}
@[simp] lemma mem_map : t ∈ map m f ↔ {x | m x ∈ t} ∈ f := iff.rfl
lemma image_mem_map (hs : s ∈ f) : m '' s ∈ map m f :=
f.sets_of_superset hs $ subset_preimage_image m s
lemma range_mem_map : range m ∈ map m f :=
by rw ←image_univ; exact image_mem_map univ_mem_sets
lemma mem_map_sets_iff : t ∈ map m f ↔ (∃s∈f, m '' s ⊆ t) :=
iff.intro
(assume ht, ⟨set.preimage m t, ht, image_preimage_subset _ _⟩)
(assume ⟨s, hs, ht⟩, mem_sets_of_superset (image_mem_map hs) ht)
@[simp] lemma map_id : filter.map id f = f :=
filter_eq $ rfl
@[simp] lemma map_compose : filter.map m' ∘ filter.map m = filter.map (m' ∘ m) :=
funext $ assume _, filter_eq $ rfl
@[simp] lemma map_map : filter.map m' (filter.map m f) = filter.map (m' ∘ m) f :=
congr_fun (@@filter.map_compose m m') f
end map
section comap
/-- The inverse map of a filter -/
def comap (m : α → β) (f : filter β) : filter α :=
{ sets := { s | ∃t∈ f, m ⁻¹' t ⊆ s },
univ_sets := ⟨univ, univ_mem_sets, by simp only [subset_univ, preimage_univ]⟩,
sets_of_superset := assume a b ⟨a', ha', ma'a⟩ ab,
⟨a', ha', subset.trans ma'a ab⟩,
inter_sets := assume a b ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩,
⟨a' ∩ b', inter_mem_sets ha₁ hb₁, inter_subset_inter ha₂ hb₂⟩ }
end comap
/-- The cofinite filter is the filter of subsets whose complements are finite. -/
def cofinite : filter α :=
{ sets := {s | finite (- s)},
univ_sets := by simp only [compl_univ, finite_empty, mem_set_of_eq],
sets_of_superset := assume s t (hs : finite (-s)) (st: s ⊆ t),
finite_subset hs $ @lattice.neg_le_neg (set α) _ _ _ st,
inter_sets := assume s t (hs : finite (-s)) (ht : finite (-t)),
by simp only [compl_inter, finite_union, ht, hs, mem_set_of_eq] }
lemma cofinite_ne_bot (hi : set.infinite (@set.univ α)) : @cofinite α ≠ ⊥ :=
forall_sets_neq_empty_iff_neq_bot.mp
$ λ s hs hn, by change set.finite _ at hs;
rw [hn, set.compl_empty] at hs; exact hi hs
/-- The monadic bind operation on filter is defined the usual way in terms of `map` and `join`.
Unfortunately, this `bind` does not result in the expected applicative. See `filter.seq` for the
applicative instance. -/
def bind (f : filter α) (m : α → filter β) : filter β := join (map m f)
/-- The applicative sequentiation operation. This is not induced by the bind operation. -/
def seq (f : filter (α → β)) (g : filter α) : filter β :=
⟨{ s | ∃u∈ f, ∃t∈ g, (∀m∈u, ∀x∈t, (m : α → β) x ∈ s) },
⟨univ, univ_mem_sets, univ, univ_mem_sets, by simp only [forall_prop_of_true, mem_univ, forall_true_iff]⟩,
assume s₀ s₁ ⟨t₀, t₁, h₀, h₁, h⟩ hst, ⟨t₀, t₁, h₀, h₁, assume x hx y hy, hst $ h _ hx _ hy⟩,
assume s₀ s₁ ⟨t₀, ht₀, t₁, ht₁, ht⟩ ⟨u₀, hu₀, u₁, hu₁, hu⟩,
⟨t₀ ∩ u₀, inter_mem_sets ht₀ hu₀, t₁ ∩ u₁, inter_mem_sets ht₁ hu₁,
assume x ⟨hx₀, hx₁⟩ x ⟨hy₀, hy₁⟩, ⟨ht _ hx₀ _ hy₀, hu _ hx₁ _ hy₁⟩⟩⟩
instance : has_pure filter := ⟨λ(α : Type u) x, principal {x}⟩
instance : has_bind filter := ⟨@filter.bind⟩
instance : has_seq filter := ⟨@filter.seq⟩
instance : functor filter := { map := @filter.map }
section
-- this section needs to be before applicative, otherwise the wrong instance will be chosen
protected def monad : monad filter := { map := @filter.map }
local attribute [instance] filter.monad
protected def is_lawful_monad : is_lawful_monad filter :=
{ id_map := assume α f, filter_eq rfl,
pure_bind := assume α β a f, by simp only [bind, Sup_image, image_singleton,
join_principal_eq_Sup, lattice.Sup_singleton, map_principal, eq_self_iff_true],
bind_assoc := assume α β γ f m₁ m₂, filter_eq rfl,
bind_pure_comp_eq_map := assume α β f x, filter_eq $
by simp only [bind, join, map, preimage, principal, set.subset_univ, eq_self_iff_true,
function.comp_app, mem_set_of_eq, singleton_subset_iff] }
end
instance : applicative filter := { map := @filter.map, seq := @filter.seq }
instance : alternative filter :=
{ failure := λα, ⊥,
orelse := λα x y, x ⊔ y }
@[simp] lemma pure_def (x : α) : pure x = principal {x} := rfl
@[simp] lemma mem_pure {a : α} {s : set α} : a ∈ s → s ∈ (pure a : filter α) :=
by simp only [imp_self, pure_def, mem_principal_sets, singleton_subset_iff]; exact id
@[simp] lemma mem_pure_iff {a : α} {s : set α} : s ∈ (pure a : filter α) ↔ a ∈ s :=
by rw [pure_def, mem_principal_sets, set.singleton_subset_iff]
@[simp] lemma map_def {α β} (m : α → β) (f : filter α) : m <$> f = map m f := rfl
@[simp] lemma bind_def {α β} (f : filter α) (m : α → filter β) : f >>= m = bind f m := rfl
/- map and comap equations -/
section map
variables {f f₁ f₂ : filter α} {g g₁ g₂ : filter β} {m : α → β} {m' : β → γ} {s : set α} {t : set β}
@[simp] theorem mem_comap_sets : s ∈ comap m g ↔ ∃t∈ g, m ⁻¹' t ⊆ s := iff.rfl
theorem preimage_mem_comap (ht : t ∈ g) : m ⁻¹' t ∈ comap m g :=
⟨t, ht, subset.refl _⟩
lemma comap_id : comap id f = f :=
le_antisymm (assume s, preimage_mem_comap) (assume s ⟨t, ht, hst⟩, mem_sets_of_superset ht hst)
lemma comap_comap_comp {m : γ → β} {n : β → α} : comap m (comap n f) = comap (n ∘ m) f :=
le_antisymm
(assume c ⟨b, hb, (h : preimage (n ∘ m) b ⊆ c)⟩, ⟨preimage n b, preimage_mem_comap hb, h⟩)
(assume c ⟨b, ⟨a, ha, (h₁ : preimage n a ⊆ b)⟩, (h₂ : preimage m b ⊆ c)⟩,
⟨a, ha, show preimage m (preimage n a) ⊆ c, from subset.trans (preimage_mono h₁) h₂⟩)
@[simp] theorem comap_principal {t : set β} : comap m (principal t) = principal (m ⁻¹' t) :=
filter_eq $ set.ext $ assume s,
⟨assume ⟨u, (hu : t ⊆ u), (b : preimage m u ⊆ s)⟩, subset.trans (preimage_mono hu) b,
assume : preimage m t ⊆ s, ⟨t, subset.refl t, this⟩⟩
lemma map_le_iff_le_comap : map m f ≤ g ↔ f ≤ comap m g :=
⟨assume h s ⟨t, ht, hts⟩, mem_sets_of_superset (h ht) hts, assume h s ht, h ⟨_, ht, subset.refl _⟩⟩
lemma gc_map_comap (m : α → β) : galois_connection (map m) (comap m) :=
assume f g, map_le_iff_le_comap
lemma map_mono (h : f₁ ≤ f₂) : map m f₁ ≤ map m f₂ := (gc_map_comap m).monotone_l h
lemma monotone_map : monotone (map m) | a b := map_mono
lemma comap_mono (h : g₁ ≤ g₂) : comap m g₁ ≤ comap m g₂ := (gc_map_comap m).monotone_u h
lemma monotone_comap : monotone (comap m) | a b := comap_mono
@[simp] lemma map_bot : map m ⊥ = ⊥ := (gc_map_comap m).l_bot
@[simp] lemma map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_comap m).l_sup
@[simp] lemma map_supr {f : ι → filter α} : map m (⨆i, f i) = (⨆i, map m (f i)) :=
(gc_map_comap m).l_supr
@[simp] lemma comap_top : comap m ⊤ = ⊤ := (gc_map_comap m).u_top
@[simp] lemma comap_inf : comap m (g₁ ⊓ g₂) = comap m g₁ ⊓ comap m g₂ := (gc_map_comap m).u_inf
@[simp] lemma comap_infi {f : ι → filter β} : comap m (⨅i, f i) = (⨅i, comap m (f i)) :=
(gc_map_comap m).u_infi
lemma le_comap_top (f : α → β) (l : filter α) : l ≤ comap f ⊤ :=
by rw [comap_top]; exact le_top
lemma map_comap_le : map m (comap m g) ≤ g := (gc_map_comap m).l_u_le _
lemma le_comap_map : f ≤ comap m (map m f) := (gc_map_comap m).le_u_l _
@[simp] lemma comap_bot : comap m ⊥ = ⊥ :=
bot_unique $ assume s _, ⟨∅, by simp only [mem_bot_sets], by simp only [empty_subset, preimage_empty]⟩
lemma comap_supr {ι} {f : ι → filter β} {m : α → β} :
comap m (supr f) = (⨆i, comap m (f i)) :=
le_antisymm
(assume s hs,
have ∀i, ∃t, t ∈ f i ∧ m ⁻¹' t ⊆ s, by simpa only [mem_comap_sets, exists_prop, mem_supr_sets] using mem_supr_sets.1 hs,
let ⟨t, ht⟩ := classical.axiom_of_choice this in
⟨⋃i, t i, mem_supr_sets.2 $ assume i, (f i).sets_of_superset (ht i).1 (subset_Union _ _),
begin
rw [preimage_Union, Union_subset_iff],
assume i,
exact (ht i).2
end⟩)
(supr_le $ assume i, monotone_comap $ le_supr _ _)
lemma comap_Sup {s : set (filter β)} {m : α → β} : comap m (Sup s) = (⨆f∈s, comap m f) :=
by simp only [Sup_eq_supr, comap_supr, eq_self_iff_true]
lemma comap_sup : comap m (g₁ ⊔ g₂) = comap m g₁ ⊔ comap m g₂ :=
le_antisymm
(assume s ⟨⟨t₁, ht₁, hs₁⟩, ⟨t₂, ht₂, hs₂⟩⟩,
⟨t₁ ∪ t₂,
⟨g₁.sets_of_superset ht₁ (subset_union_left _ _), g₂.sets_of_superset ht₂ (subset_union_right _ _)⟩,
union_subset hs₁ hs₂⟩)
(sup_le (comap_mono le_sup_left) (comap_mono le_sup_right))
lemma map_comap {f : filter β} {m : α → β} (hf : range m ∈ f) : (f.comap m).map m = f :=
le_antisymm
map_comap_le
(assume t' ⟨t, ht, sub⟩, by filter_upwards [ht, hf]; rintros x hxt ⟨y, rfl⟩; exact sub hxt)
lemma comap_map {f : filter α} {m : α → β} (h : ∀ x y, m x = m y → x = y) :
comap m (map m f) = f :=
have ∀s, preimage m (image m s) = s,
from assume s, preimage_image_eq s h,
le_antisymm
(assume s hs, ⟨
image m s,
f.sets_of_superset hs $ by simp only [this, subset.refl],
by simp only [this, subset.refl]⟩)
le_comap_map
lemma le_of_map_le_map_inj' {f g : filter α} {m : α → β} {s : set α}
(hsf : s ∈ f) (hsg : s ∈ g) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y)
(h : map m f ≤ map m g) : f ≤ g :=
assume t ht, by filter_upwards [hsf, h $ image_mem_map (inter_mem_sets hsg ht)]
assume a has ⟨b, ⟨hbs, hb⟩, h⟩,
have b = a, from hm _ hbs _ has h,
this ▸ hb
lemma le_of_map_le_map_inj_iff {f g : filter α} {m : α → β} {s : set α}
(hsf : s ∈ f) (hsg : s ∈ g) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y) :
map m f ≤ map m g ↔ f ≤ g :=
iff.intro (le_of_map_le_map_inj' hsf hsg hm) map_mono
lemma eq_of_map_eq_map_inj' {f g : filter α} {m : α → β} {s : set α}
(hsf : s ∈ f) (hsg : s ∈ g) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y)
(h : map m f = map m g) : f = g :=
le_antisymm
(le_of_map_le_map_inj' hsf hsg hm $ le_of_eq h)
(le_of_map_le_map_inj' hsg hsf hm $ le_of_eq h.symm)
lemma map_inj {f g : filter α} {m : α → β} (hm : ∀ x y, m x = m y → x = y) (h : map m f = map m g) :
f = g :=
have comap m (map m f) = comap m (map m g), by rw h,
by rwa [comap_map hm, comap_map hm] at this
theorem le_map_comap_of_surjective' {f : α → β} {l : filter β} {u : set β} (ul : u ∈ l)
(hf : ∀ y ∈ u, ∃ x, f x = y) :
l ≤ map f (comap f l) :=
assume s ⟨t, tl, ht⟩,
have t ∩ u ⊆ s, from
assume x ⟨xt, xu⟩,
exists.elim (hf x xu) $ λ a faeq,
by { rw ←faeq, apply ht, change f a ∈ t, rw faeq, exact xt },
mem_sets_of_superset (inter_mem_sets tl ul) this
theorem map_comap_of_surjective' {f : α → β} {l : filter β} {u : set β} (ul : u ∈ l)
(hf : ∀ y ∈ u, ∃ x, f x = y) :
map f (comap f l) = l :=
le_antisymm map_comap_le (le_map_comap_of_surjective' ul hf)
theorem le_map_comap_of_surjective {f : α → β} (hf : function.surjective f) (l : filter β) :
l ≤ map f (comap f l) :=
le_map_comap_of_surjective' univ_mem_sets (λ y _, hf y)
theorem map_comap_of_surjective {f : α → β} (hf : function.surjective f) (l : filter β) :
map f (comap f l) = l :=
le_antisymm map_comap_le (le_map_comap_of_surjective hf l)
lemma comap_neq_bot {f : filter β} {m : α → β}
(hm : ∀t∈ f, ∃a, m a ∈ t) : comap m f ≠ ⊥ :=
forall_sets_neq_empty_iff_neq_bot.mp $ assume s ⟨t, ht, t_s⟩,
let ⟨a, (ha : a ∈ preimage m t)⟩ := hm t ht in
neq_bot_of_le_neq_bot (ne_empty_of_mem ha) t_s
lemma comap_neq_bot_of_surj {f : filter β} {m : α → β}
(hf : f ≠ ⊥) (hm : ∀b, ∃a, m a = b) : comap m f ≠ ⊥ :=
comap_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⟩
@[simp] lemma map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ :=
⟨by rw [←empty_in_sets_eq_bot, ←empty_in_sets_eq_bot]; exact id,
assume h, by simp only [h, eq_self_iff_true, map_bot]⟩
lemma map_ne_bot (hf : f ≠ ⊥) : map m f ≠ ⊥ :=
assume h, hf $ by rwa [map_eq_bot_iff] at h
lemma sInter_comap_sets (f : α → β) (F : filter β) :
⋂₀(comap f F).sets = ⋂ U ∈ F, f ⁻¹' U :=
begin
ext x,
suffices : (∀ (A : set α) (B : set β), B ∈ F → f ⁻¹' B ⊆ A → x ∈ A) ↔
∀ (B : set β), B ∈ F → f x ∈ B,
by simp only [mem_sInter, mem_Inter, mem_comap_sets, this, and_imp, mem_comap_sets, exists_prop, mem_sInter,
iff_self, mem_Inter, mem_preimage, exists_imp_distrib],
split,
{ intros h U U_in,
simpa only [set.subset.refl, forall_prop_of_true, mem_preimage] using h (f ⁻¹' U) U U_in },
{ intros h V U U_in f_U_V,
exact f_U_V (h U U_in) },
end
end map
lemma map_cong {m₁ m₂ : α → β} {f : filter α} (h : {x | m₁ x = m₂ x} ∈ f) :
map m₁ f = map m₂ f :=
have ∀(m₁ m₂ : α → β) (h : {x | m₁ x = m₂ x} ∈ f), map m₁ f ≤ map m₂ f,
begin
intros m₁ m₂ h s hs,
show {x | m₁ x ∈ s} ∈ f,
filter_upwards [h, hs],
simp only [subset_def, mem_preimage, mem_set_of_eq, forall_true_iff] {contextual := tt}
end,
le_antisymm (this m₁ m₂ h) (this m₂ m₁ $ mem_sets_of_superset h $ assume x, eq.symm)
-- 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 : preimage m s ∈ infi f),
have ∃i, preimage m s ∈ f i,
by simp only [infi_sets_eq hf hι, mem_Union] at hs; assumption,
let ⟨i, hi⟩ := this in
have (⨅ i, map m (f i)) ≤ principal s, from
infi_le_of_le i $ by simp only [le_principal_iff, mem_map]; assumption,
by simp only [filter.le_principal_iff] at this; assumption)
lemma map_binfi_eq {ι : Type w} {f : ι → filter α} {m : α → β} {p : ι → Prop}
(h : directed_on (f ⁻¹'o (≥)) {x | p x}) (ne : ∃i, p i) :
map m (⨅i (h : p i), f i) = (⨅i (h: p i), map m (f i)) :=
let ⟨i, hi⟩ := ne in
calc map m (⨅i (h : p i), f i) = map m (⨅i:subtype p, f i.val) : by simp only [infi_subtype, eq_self_iff_true]
... = (⨅i:subtype p, 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 (h : p i), map m (f i)) : by simp only [infi_subtype, eq_self_iff_true]
lemma map_inf' {f g : filter α} {m : α → β} {t : set α} (htf : t ∈ f) (htg : t ∈ g)
(h : ∀x∈t, ∀y∈t, m x = m y → x = y) : map m (f ⊓ g) = map m f ⊓ map m g :=
begin
refine le_antisymm
(le_inf (map_mono inf_le_left) (map_mono inf_le_right))
(assume s hs, _),
simp only [map, mem_inf_sets, exists_prop, mem_map, mem_preimage, mem_inf_sets] at hs ⊢,
rcases hs with ⟨t₁, h₁, t₂, h₂, hs⟩,
refine ⟨m '' (t₁ ∩ t), _, m '' (t₂ ∩ t), _, _⟩,
{ filter_upwards [h₁, htf] assume a h₁ h₂, mem_image_of_mem _ ⟨h₁, h₂⟩ },
{ filter_upwards [h₂, htg] assume a h₁ h₂, mem_image_of_mem _ ⟨h₁, h₂⟩ },
{ rw [image_inter_on],
{ refine image_subset_iff.2 _,
exact λ x ⟨⟨h₁, _⟩, h₂, _⟩, hs ⟨h₁, h₂⟩ },
{ exact λ x ⟨_, hx⟩ y ⟨_, hy⟩, h x hx y hy } }
end
lemma map_inf {f g : filter α} {m : α → β} (h : ∀ x y, m x = m y → x = y) :
map m (f ⊓ g) = map m f ⊓ map m g :=
map_inf' univ_mem_sets univ_mem_sets (assume x _ y _, h x y)
lemma map_eq_comap_of_inverse {f : filter α} {m : α → β} {n : β → α}
(h₁ : m ∘ n = id) (h₂ : n ∘ m = id) : map m f = comap n f :=
le_antisymm
(assume b ⟨a, ha, (h : preimage n a ⊆ b)⟩, f.sets_of_superset ha $
calc a = preimage (n ∘ m) a : by simp only [h₂, preimage_id, eq_self_iff_true]
... ⊆ preimage m b : preimage_mono h)
(assume b (hb : preimage m b ∈ f),
⟨preimage m b, hb, show preimage (m ∘ n) b ⊆ b, by simp only [h₁]; apply subset.refl⟩)
lemma map_swap_eq_comap_swap {f : filter (α × β)} : prod.swap <$> f = comap prod.swap f :=
map_eq_comap_of_inverse prod.swap_swap_eq prod.swap_swap_eq
lemma le_map {f : filter α} {m : α → β} {g : filter β} (h : ∀s∈ f, m '' s ∈ g) :
g ≤ f.map m :=
assume s hs, mem_sets_of_superset (h _ hs) $ image_preimage_subset _ _
section applicative
@[simp] lemma mem_pure_sets {a : α} {s : set α} :
s ∈ (pure a : filter α) ↔ a ∈ s :=
by simp only [iff_self, pure_def, mem_principal_sets, singleton_subset_iff]
lemma singleton_mem_pure_sets {a : α} : {a} ∈ (pure a : filter α) :=
by simp only [mem_singleton, pure_def, mem_principal_sets, singleton_subset_iff]
@[simp] lemma pure_neq_bot {α : Type u} {a : α} : pure a ≠ (⊥ : filter α) :=
by simp only [pure, has_pure.pure, ne.def, not_false_iff, singleton_ne_empty, principal_eq_bot_iff]
lemma mem_seq_sets_def {f : filter (α → β)} {g : filter α} {s : set β} :
s ∈ f.seq g ↔ (∃u ∈ f, ∃t ∈ g, ∀x∈u, ∀y∈t, (x : α → β) y ∈ s) :=
iff.refl _
lemma mem_seq_sets_iff {f : filter (α → β)} {g : filter α} {s : set β} :
s ∈ f.seq g ↔ (∃u ∈ f, ∃t ∈ g, set.seq u t ⊆ s) :=
by simp only [mem_seq_sets_def, seq_subset, exists_prop, iff_self]
lemma mem_map_seq_iff {f : filter α} {g : filter β} {m : α → β → γ} {s : set γ} :
s ∈ (f.map m).seq g ↔ (∃t u, t ∈ g ∧ u ∈ f ∧ ∀x∈u, ∀y∈t, m x y ∈ s) :=
iff.intro
(assume ⟨t, ht, s, hs, hts⟩, ⟨s, m ⁻¹' t, hs, ht, assume a, hts _⟩)
(assume ⟨t, s, ht, hs, hts⟩, ⟨m '' s, image_mem_map hs, t, ht, assume f ⟨a, has, eq⟩, eq ▸ hts _ has⟩)
lemma seq_mem_seq_sets {f : filter (α → β)} {g : filter α} {s : set (α → β)} {t : set α}
(hs : s ∈ f) (ht : t ∈ g) : s.seq t ∈ f.seq g :=
⟨s, hs, t, ht, assume f hf a ha, ⟨f, hf, a, ha, rfl⟩⟩
lemma le_seq {f : filter (α → β)} {g : filter α} {h : filter β}
(hh : ∀t ∈ f, ∀u ∈ g, set.seq t u ∈ h) : h ≤ seq f g :=
assume s ⟨t, ht, u, hu, hs⟩, mem_sets_of_superset (hh _ ht _ hu) $
assume b ⟨m, hm, a, ha, eq⟩, eq ▸ hs _ hm _ ha
lemma seq_mono {f₁ f₂ : filter (α → β)} {g₁ g₂ : filter α}
(hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.seq g₁ ≤ f₂.seq g₂ :=
le_seq $ assume s hs t ht, seq_mem_seq_sets (hf hs) (hg ht)
@[simp] lemma pure_seq_eq_map (g : α → β) (f : filter α) : seq (pure g) f = f.map g :=
begin
refine le_antisymm (le_map $ assume s hs, _) (le_seq $ assume s hs t ht, _),
{ rw ← singleton_seq, apply seq_mem_seq_sets _ hs,
simp only [mem_singleton, pure_def, mem_principal_sets, singleton_subset_iff] },
{ rw mem_pure_sets at hs,
refine sets_of_superset (map g f) (image_mem_map ht) _,
rintros b ⟨a, ha, rfl⟩, exact ⟨g, hs, a, ha, rfl⟩ }
end
@[simp] lemma map_pure (f : α → β) (a : α) : map f (pure a) = pure (f a) :=
le_antisymm
(le_principal_iff.2 $ sets_of_superset (map f (pure a)) (image_mem_map singleton_mem_pure_sets) $
by simp only [image_singleton, mem_singleton, singleton_subset_iff])
(le_map $ assume s, begin
simp only [mem_image, pure_def, mem_principal_sets, singleton_subset_iff],
exact assume has, ⟨a, has, rfl⟩
end)
@[simp] lemma seq_pure (f : filter (α → β)) (a : α) : seq f (pure a) = map (λg:α → β, g a) f :=
begin
refine le_antisymm (le_map $ assume s hs, _) (le_seq $ assume s hs t ht, _),
{ rw ← seq_singleton, exact seq_mem_seq_sets hs
(by simp only [mem_singleton, pure_def, mem_principal_sets, singleton_subset_iff]) },
{ rw mem_pure_sets at ht,
refine sets_of_superset (map (λg:α→β, g a) f) (image_mem_map hs) _,
rintros b ⟨g, hg, rfl⟩, exact ⟨g, hg, a, ht, rfl⟩ }
end
@[simp] lemma seq_assoc (x : filter α) (g : filter (α → β)) (h : filter (β → γ)) :
seq h (seq g x) = seq (seq (map (∘) h) g) x :=
begin
refine le_antisymm (le_seq $ assume s hs t ht, _) (le_seq $ assume s hs t ht, _),
{ rcases mem_seq_sets_iff.1 hs with ⟨u, hu, v, hv, hs⟩,
rcases mem_map_sets_iff.1 hu with ⟨w, hw, hu⟩,
refine mem_sets_of_superset _
(set.seq_mono (subset.trans (set.seq_mono hu (subset.refl _)) hs) (subset.refl _)),
rw ← set.seq_seq,
exact seq_mem_seq_sets hw (seq_mem_seq_sets hv ht) },
{ rcases mem_seq_sets_iff.1 ht with ⟨u, hu, v, hv, ht⟩,
refine mem_sets_of_superset _ (set.seq_mono (subset.refl _) ht),
rw set.seq_seq,
exact seq_mem_seq_sets (seq_mem_seq_sets (image_mem_map hs) hu) hv }
end
lemma prod_map_seq_comm (f : filter α) (g : filter β) :
(map prod.mk f).seq g = seq (map (λb a, (a, b)) g) f :=
begin
refine le_antisymm (le_seq $ assume s hs t ht, _) (le_seq $ assume s hs t ht, _),
{ rcases mem_map_sets_iff.1 hs with ⟨u, hu, hs⟩,
refine mem_sets_of_superset _ (set.seq_mono hs (subset.refl _)),
rw ← set.prod_image_seq_comm,
exact seq_mem_seq_sets (image_mem_map ht) hu },
{ rcases mem_map_sets_iff.1 hs with ⟨u, hu, hs⟩,
refine mem_sets_of_superset _ (set.seq_mono hs (subset.refl _)),
rw set.prod_image_seq_comm,
exact seq_mem_seq_sets (image_mem_map ht) hu }
end
instance : is_lawful_functor (filter : Type u → Type u) :=
{ id_map := assume α f, map_id,
comp_map := assume α β γ f g a, map_map.symm }
instance : is_lawful_applicative (filter : Type u → Type u) :=
{ pure_seq_eq_map := assume α β, pure_seq_eq_map,
map_pure := assume α β, map_pure,
seq_pure := assume α β, seq_pure,
seq_assoc := assume α β γ, seq_assoc }
instance : is_comm_applicative (filter : Type u → Type u) :=
⟨assume α β f g, prod_map_seq_comm f g⟩
lemma {l} seq_eq_filter_seq {α β : Type l} (f : filter (α → β)) (g : filter α) :
f <*> g = seq f g := rfl
end applicative
/- bind equations -/
section bind
@[simp] lemma mem_bind_sets {s : set β} {f : filter α} {m : α → filter β} :
s ∈ bind f m ↔ ∃t ∈ f, ∀x ∈ t, s ∈ m x :=
calc s ∈ bind f m ↔ {a | s ∈ m a} ∈ f : by simp only [bind, mem_map, iff_self, mem_join_sets, mem_set_of_eq]
... ↔ (∃t ∈ f, t ⊆ {a | s ∈ m a}) : exists_sets_subset_iff.symm
... ↔ (∃t ∈ f, ∀x ∈ t, s ∈ m x) : iff.refl _
lemma bind_mono {f : filter α} {g h : α → filter β} (h₁ : {a | g a ≤ h a} ∈ f) :
bind f g ≤ bind f h :=
assume x h₂, show (_ ∈ f), by filter_upwards [h₁, h₂] assume s gh' h', gh' h'
lemma bind_sup {f g : filter α} {h : α → filter β} :
bind (f ⊔ g) h = bind f h ⊔ bind g h :=
by simp only [bind, sup_join, map_sup, eq_self_iff_true]
lemma bind_mono2 {f g : filter α} {h : α → filter β} (h₁ : f ≤ g) :
bind f h ≤ bind g h :=
assume s h', h₁ h'
lemma principal_bind {s : set α} {f : α → filter β} :
(bind (principal s) f) = (⨆x ∈ s, f x) :=
show join (map f (principal s)) = (⨆x ∈ s, f x),
by simp only [Sup_image, join_principal_eq_Sup, map_principal, eq_self_iff_true]
end bind
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), from h.symm ▸ (mem_bot_sets : ∅ ∈ (⊥ : filter α)),
classical.by_cases
(assume : nonempty ι,
have ∃i, ∅ ∈ f i,
by rw [mem_infi hd this] at he; simp only [mem_Union] at he; assumption,
let ⟨i, hi⟩ := this in
hb i $ bot_unique $
assume s _, (f i).sets_of_superset 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⟩
lemma mem_infi_sets {f : ι → filter α} (i : ι) : ∀{s}, s ∈ f i → s ∈ ⨅i, f i :=
show (⨅i, f i) ≤ f i, from infi_le _ _
@[elab_as_eliminator]
lemma infi_sets_induct {f : ι → filter α} {s : set α} (hs : s ∈ infi f) {p : set α → Prop}
(uni : p univ)
(ins : ∀{i s₁ s₂}, s₁ ∈ f i → p s₂ → p (s₁ ∩ s₂))
(upw : ∀{s₁ s₂}, s₁ ⊆ s₂ → p s₁ → p s₂) : p s :=
begin
rw [mem_infi_finite] at hs,
simp only [mem_Union, (finset.inf_eq_infi _ _).symm] at hs,
rcases hs with ⟨is, his⟩,
revert s,
refine finset.induction_on is _ _,
{ assume s hs, rwa [mem_top_sets.1 hs] },
{ rintros ⟨i⟩ js his ih s hs,
rw [finset.inf_insert, mem_inf_sets] at hs,
rcases hs with ⟨s₁, hs₁, s₂, hs₂, hs⟩,
exact upw hs (ins hs₁ (ih hs₂)) }
end
/- tendsto -/
/-- `tendsto` is the generic "limit of a function" predicate.
`tendsto f l₁ l₂` asserts that for every `l₂` neighborhood `a`,
the `f`-preimage of `a` is an `l₁` neighborhood. -/
def tendsto (f : α → β) (l₁ : filter α) (l₂ : filter β) := l₁.map f ≤ l₂
lemma tendsto_def {f : α → β} {l₁ : filter α} {l₂ : filter β} :
tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f ⁻¹' s ∈ l₁ := iff.rfl
lemma tendsto_iff_comap {f : α → β} {l₁ : filter α} {l₂ : filter β} :
tendsto f l₁ l₂ ↔ l₁ ≤ l₂.comap f :=
map_le_iff_le_comap
lemma tendsto.congr' {f₁ f₂ : α → β} {l₁ : filter α} {l₂ : filter β}
(hl : {x | f₁ x = f₂ x} ∈ l₁) (h : tendsto f₁ l₁ l₂) : tendsto f₂ l₁ l₂ :=
by rwa [tendsto, ←map_cong hl]
theorem tendsto.congr'r {f₁ f₂ : α → β} {l₁ : filter α} {l₂ : filter β}
(h : ∀ x, f₁ x = f₂ x) : tendsto f₁ l₁ l₂ ↔ tendsto f₂ l₁ l₂ :=
iff_of_eq (by congr'; exact funext h)
theorem tendsto.congr {f₁ f₂ : α → β} {l₁ : filter α} {l₂ : filter β}
(h : ∀ x, f₁ x = f₂ x) : tendsto f₁ l₁ l₂ → tendsto f₂ l₁ l₂ :=
(tendsto.congr'r h).1
lemma tendsto_id' {x y : filter α} : x ≤ y → tendsto id x y :=
by simp only [tendsto, map_id, forall_true_iff] {contextual := tt}
lemma tendsto_id {x : filter α} : tendsto id x x := tendsto_id' $ le_refl x
lemma tendsto.comp {f : α → β} {g : β → γ} {x : filter α} {y : filter β} {z : filter γ}
(hg : tendsto g y z) (hf : tendsto f x y) : tendsto (g ∘ f) x z :=
calc map (g ∘ f) x = map g (map f x) : by rw [map_map]
... ≤ map g y : map_mono hf
... ≤ z : hg
lemma tendsto_le_left {f : α → β} {x y : filter α} {z : filter β}
(h : y ≤ x) : tendsto f x z → tendsto f y z :=
le_trans (map_mono h)
lemma tendsto_le_right {f : α → β} {x : filter α} {y z : filter β}
(h₁ : y ≤ z) (h₂ : tendsto f x y) : tendsto f x z :=
le_trans h₂ h₁
lemma tendsto_map {f : α → β} {x : filter α} : tendsto f x (map f x) := le_refl (map f x)
lemma tendsto_map' {f : β → γ} {g : α → β} {x : filter α} {y : filter γ}
(h : tendsto (f ∘ g) x y) : tendsto f (map g x) y :=
by rwa [tendsto, map_map]
lemma tendsto_map'_iff {f : β → γ} {g : α → β} {x : filter α} {y : filter γ} :
tendsto f (map g x) y ↔ tendsto (f ∘ g) x y :=
by rw [tendsto, map_map]; refl
lemma tendsto_comap {f : α → β} {x : filter β} : tendsto f (comap f x) x :=
map_comap_le
lemma tendsto_comap_iff {f : α → β} {g : β → γ} {a : filter α} {c : filter γ} :
tendsto f a (c.comap g) ↔ tendsto (g ∘ f) a c :=
⟨assume h, tendsto_comap.comp h, assume h, map_le_iff_le_comap.mp $ by rwa [map_map]⟩
lemma tendsto_comap'_iff {m : α → β} {f : filter α} {g : filter β} {i : γ → α}
(h : range i ∈ f) : tendsto (m ∘ i) (comap i f) g ↔ tendsto m f g :=
by rw [tendsto, ← map_compose]; simp only [(∘), map_comap h, tendsto]
lemma comap_eq_of_inverse {f : filter α} {g : filter β} {φ : α → β} (ψ : β → α)
(eq : ψ ∘ φ = id) (hφ : tendsto φ f g) (hψ : tendsto ψ g f) : comap φ g = f :=
begin
refine le_antisymm (le_trans (comap_mono $ map_le_iff_le_comap.1 hψ) _) (map_le_iff_le_comap.1 hφ),
rw [comap_comap_comp, eq, comap_id],
exact le_refl _
end
lemma map_eq_of_inverse {f : filter α} {g : filter β} {φ : α → β} (ψ : β → α)
(eq : φ ∘ ψ = id) (hφ : tendsto φ f g) (hψ : tendsto ψ g f) : map φ f = g :=
begin
refine le_antisymm hφ (le_trans _ (map_mono hψ)),
rw [map_map, eq, map_id],
exact le_refl _
end
lemma tendsto_inf {f : α → β} {x : filter α} {y₁ y₂ : filter β} :
tendsto f x (y₁ ⊓ y₂) ↔ tendsto f x y₁ ∧ tendsto f x y₂ :=
by simp only [tendsto, lattice.le_inf_iff, iff_self]
lemma tendsto_inf_left {f : α → β} {x₁ x₂ : filter α} {y : filter β}
(h : tendsto f x₁ y) : tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_left) h
lemma tendsto_inf_right {f : α → β} {x₁ x₂ : filter α} {y : filter β}
(h : tendsto f x₂ y) : tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_right) h
lemma tendsto_infi {f : α → β} {x : filter α} {y : ι → filter β} :
tendsto f x (⨅i, y i) ↔ ∀i, tendsto f x (y i) :=
by simp only [tendsto, iff_self, lattice.le_infi_iff]
lemma tendsto_infi' {f : α → β} {x : ι → filter α} {y : filter β} (i : ι) :
tendsto f (x i) y → tendsto f (⨅i, x i) y :=
tendsto_le_left (infi_le _ _)
lemma tendsto_principal {f : α → β} {a : filter α} {s : set β} :
tendsto f a (principal s) ↔ {a | f a ∈ s} ∈ a :=
by simp only [tendsto, le_principal_iff, mem_map, iff_self]
lemma tendsto_principal_principal {f : α → β} {s : set α} {t : set β} :
tendsto f (principal s) (principal t) ↔ ∀a∈s, f a ∈ t :=
by simp only [tendsto, image_subset_iff, le_principal_iff, map_principal, mem_principal_sets]; refl
lemma tendsto_pure_pure (f : α → β) (a : α) :
tendsto f (pure a) (pure (f a)) :=
show filter.map f (pure a) ≤ pure (f a),
by rw [filter.map_pure]; exact le_refl _
lemma tendsto_const_pure {a : filter α} {b : β} : tendsto (λa, b) a (pure b) :=
by simp [tendsto]; exact univ_mem_sets
lemma tendsto_if {l₁ : filter α} {l₂ : filter β}
{f g : α → β} {p : α → Prop} [decidable_pred p]
(h₀ : tendsto f (l₁ ⊓ principal p) l₂)
(h₁ : tendsto g (l₁ ⊓ principal { x | ¬ p x }) l₂) :
tendsto (λ x, if p x then f x else g x) l₁ l₂ :=
begin
revert h₀ h₁, simp only [tendsto_def, mem_inf_principal],
intros h₀ h₁ s hs,
apply mem_sets_of_superset (inter_mem_sets (h₀ s hs) (h₁ s hs)),
rintros x ⟨hp₀, hp₁⟩, simp only [mem_preimage],
by_cases h : p x,
{ rw if_pos h, exact hp₀ h },
rw if_neg h, exact hp₁ h
end
section prod
variables {s : set α} {t : set β} {f : filter α} {g : 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.
-/
/-- Product of filters. This is the filter generated by cartesian products
of elements of the component filters. -/
protected def prod (f : filter α) (g : filter β) : filter (α × β) :=
f.comap prod.fst ⊓ g.comap prod.snd
lemma prod_mem_prod {s : set α} {t : set β} {f : filter α} {g : filter β}
(hs : s ∈ f) (ht : t ∈ g) : set.prod s t ∈ filter.prod f g :=
inter_mem_inf_sets (preimage_mem_comap hs) (preimage_mem_comap ht)
lemma mem_prod_iff {s : set (α×β)} {f : filter α} {g : filter β} :
s ∈ filter.prod f g ↔ (∃ t₁ ∈ f, ∃ t₂ ∈ g, set.prod t₁ t₂ ⊆ s) :=
begin
simp only [filter.prod],
split,
exact assume ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, h⟩,
⟨s₁, hs₁, s₂, hs₂, subset.trans (inter_subset_inter hts₁ hts₂) h⟩,
exact assume ⟨t₁, ht₁, t₂, ht₂, h⟩,
⟨prod.fst ⁻¹' t₁, ⟨t₁, ht₁, subset.refl _⟩, prod.snd ⁻¹' t₂, ⟨t₂, ht₂, subset.refl _⟩, h⟩
end
lemma tendsto_fst {f : filter α} {g : filter β} : tendsto prod.fst (filter.prod f g) f :=
tendsto_inf_left tendsto_comap
lemma tendsto_snd {f : filter α} {g : filter β} : tendsto prod.snd (filter.prod f g) g :=
tendsto_inf_right tendsto_comap
lemma tendsto.prod_mk {f : filter α} {g : filter β} {h : filter γ} {m₁ : α → β} {m₂ : α → γ}
(h₁ : tendsto m₁ f g) (h₂ : tendsto m₂ f h) : tendsto (λx, (m₁ x, m₂ x)) f (filter.prod g h) :=
tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
lemma prod_infi_left {f : ι → filter α} {g : filter β} (i : ι) :
filter.prod (⨅i, f i) g = (⨅i, filter.prod (f i) g) :=
by rw [filter.prod, comap_infi, infi_inf i]; simp only [filter.prod, eq_self_iff_true]
lemma prod_infi_right {f : filter α} {g : ι → filter β} (i : ι) :
filter.prod f (⨅i, g i) = (⨅i, filter.prod f (g i)) :=
by rw [filter.prod, comap_infi, inf_infi i]; simp only [filter.prod, eq_self_iff_true]
lemma prod_mono {f₁ f₂ : filter α} {g₁ g₂ : filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
filter.prod f₁ g₁ ≤ filter.prod f₂ g₂ :=
inf_le_inf (comap_mono hf) (comap_mono hg)
lemma prod_comap_comap_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} :
filter.prod (comap m₁ f₁) (comap m₂ f₂) = comap (λp:β₁×β₂, (m₁ p.1, m₂ p.2)) (filter.prod f₁ f₂) :=
by simp only [filter.prod, comap_comap_comp, eq_self_iff_true, comap_inf]
lemma prod_comm' : filter.prod f g = comap (prod.swap) (filter.prod g f) :=
by simp only [filter.prod, comap_comap_comp, (∘), inf_comm, prod.fst_swap,
eq_self_iff_true, prod.snd_swap, comap_inf]
lemma prod_comm : filter.prod f g = map (λp:β×α, (p.2, p.1)) (filter.prod g f) :=
by rw [prod_comm', ← map_swap_eq_comap_swap]; refl
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₂) :=
le_antisymm
(assume s hs,
let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs in
filter.sets_of_superset _ (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) $
calc set.prod (m₁ '' s₁) (m₂ '' s₂) = (λp:α₁×α₂, (m₁ p.1, m₂ p.2)) '' set.prod s₁ s₂ :
set.prod_image_image_eq
... ⊆ _ : by rwa [image_subset_iff])
((tendsto.comp (le_refl _) tendsto_fst).prod_mk (tendsto.comp (le_refl _) tendsto_snd))
lemma map_prod (m : α × β → γ) (f : filter α) (g : filter β) :
map m (f.prod g) = (f.map (λa b, m (a, b))).seq g :=
begin
simp [filter.ext_iff, mem_prod_iff, mem_map_seq_iff],
assume s,
split,
exact assume ⟨t, ht, s, hs, h⟩, ⟨s, hs, t, ht, assume x hx y hy, @h ⟨x, y⟩ ⟨hx, hy⟩⟩,
exact assume ⟨s, hs, t, ht, h⟩, ⟨t, ht, s, hs, assume ⟨x, y⟩ ⟨hx, hy⟩, h x hx y hy⟩
end
lemma prod_eq {f : filter α} {g : filter β} : f.prod g = (f.map prod.mk).seq g :=
have h : _ := map_prod id f g, by rwa [map_id] at h
lemma prod_inf_prod {f₁ f₂ : filter α} {g₁ g₂ : filter β} :
filter.prod f₁ g₁ ⊓ filter.prod f₂ g₂ = filter.prod (f₁ ⊓ f₂) (g₁ ⊓ g₂) :=
by simp only [filter.prod, comap_inf, inf_comm, inf_assoc, lattice.inf_left_comm]
@[simp] lemma prod_bot {f : filter α} : filter.prod f (⊥ : filter β) = ⊥ := by simp [filter.prod]
@[simp] lemma bot_prod {g : filter β} : filter.prod (⊥ : filter α) g = ⊥ := by simp [filter.prod]
@[simp] lemma prod_principal_principal {s : set α} {t : set β} :
filter.prod (principal s) (principal t) = principal (set.prod s t) :=
by simp only [filter.prod, comap_principal, principal_eq_iff_eq, comap_principal, inf_principal]; refl
@[simp] lemma prod_pure_pure {a : α} {b : β} : filter.prod (pure a) (pure b) = pure (a, b) :=
by simp
lemma prod_eq_bot {f : filter α} {g : filter β} : filter.prod f g = ⊥ ↔ (f = ⊥ ∨ g = ⊥) :=
begin
split,
{ assume h,
rcases mem_prod_iff.1 (empty_in_sets_eq_bot.2 h) with ⟨s, hs, t, ht, hst⟩,
rw [subset_empty_iff, set.prod_eq_empty_iff] at hst,
cases hst with s_eq t_eq,
{ left, exact empty_in_sets_eq_bot.1 (s_eq ▸ hs) },
{ right, exact empty_in_sets_eq_bot.1 (t_eq ▸ ht) } },
{ rintros (rfl | rfl),
exact bot_prod,
exact prod_bot }
end
lemma prod_neq_bot {f : filter α} {g : filter β} : filter.prod f g ≠ ⊥ ↔ (f ≠ ⊥ ∧ g ≠ ⊥) :=
by rw [(≠), prod_eq_bot, not_or_distrib]
lemma tendsto_prod_iff {f : α × β → γ} {x : filter α} {y : filter β} {z : filter γ} :
filter.tendsto f (filter.prod x y) z ↔
∀ W ∈ z, ∃ U ∈ x, ∃ V ∈ y, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W :=
by simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff, exists_prop, iff_self]
end prod
/- at_top and at_bot -/
/-- `at_top` is the filter representing the limit `→ ∞` on an ordered set.
It is generated by the collection of up-sets `{b | a ≤ b}`.
(The preorder need not have a top element for this to be well defined,
and indeed is trivial when a top element exists.) -/
def at_top [preorder α] : filter α := ⨅ a, principal {b | a ≤ b}
/-- `at_bot` is the filter representing the limit `→ -∞` on an ordered set.
It is generated by the collection of down-sets `{b | b ≤ a}`.
(The preorder need not have a bottom element for this to be well defined,
and indeed is trivial when a bottom element exists.) -/
def at_bot [preorder α] : filter α := ⨅ a, principal {b | b ≤ a}
lemma mem_at_top [preorder α] (a : α) : {b : α | a ≤ b} ∈ @at_top α _ :=
mem_infi_sets a $ subset.refl _
@[simp] lemma at_top_ne_bot [nonempty α] [semilattice_sup α] : (at_top : filter α) ≠ ⊥ :=
infi_neq_bot_of_directed (by apply_instance)
(assume a b, ⟨a ⊔ b, by simp only [ge, le_principal_iff, forall_const, set_of_subset_set_of,
mem_principal_sets, and_self, sup_le_iff, forall_true_iff] {contextual := tt}⟩)
(assume a, by simp only [principal_eq_bot_iff, ne.def, principal_eq_bot_iff]; exact ne_empty_of_mem (le_refl a))
@[simp] lemma mem_at_top_sets [nonempty α] [semilattice_sup α] {s : set α} :
s ∈ (at_top : filter α) ↔ ∃a:α, ∀b≥a, b ∈ s :=
let ⟨a⟩ := ‹nonempty α› in
iff.intro
(assume h, infi_sets_induct h ⟨a, by simp only [forall_const, mem_univ, forall_true_iff]⟩
(assume a s₁ s₂ ha ⟨b, hb⟩, ⟨a ⊔ b,
assume c hc, ⟨ha $ le_trans le_sup_left hc, hb _ $ le_trans le_sup_right hc⟩⟩)
(assume s₁ s₂ h ⟨a, ha⟩, ⟨a, assume b hb, h $ ha _ hb⟩))
(assume ⟨a, h⟩, mem_infi_sets a $ assume x, h x)
lemma map_at_top_eq [nonempty α] [semilattice_sup α] {f : α → β} :
at_top.map f = (⨅a, principal $ f '' {a' | a ≤ a'}) :=
calc map f (⨅a, principal {a' | a ≤ a'}) = (⨅a, map f $ principal {a' | a ≤ a'}) :
map_infi_eq (assume a b, ⟨a ⊔ b, by simp only [ge, le_principal_iff, forall_const, set_of_subset_set_of,
mem_principal_sets, and_self, sup_le_iff, forall_true_iff] {contextual := tt}⟩)
(by apply_instance)
... = (⨅a, principal $ f '' {a' | a ≤ a'}) : by simp only [map_principal, eq_self_iff_true]
lemma tendsto_at_top [preorder β] (m : α → β) (f : filter α) :
tendsto m f at_top ↔ (∀b, {a | b ≤ m a} ∈ f) :=
by simp only [at_top, tendsto_infi, tendsto_principal]; refl
lemma tendsto_at_top' [nonempty α] [semilattice_sup α] (f : α → β) (l : filter β) :
tendsto f at_top l ↔ (∀s ∈ l, ∃a, ∀b≥a, f b ∈ s) :=
by simp only [tendsto_def, mem_at_top_sets]; refl
theorem tendsto_at_top_principal [nonempty β] [semilattice_sup β] {f : β → α} {s : set α} :
tendsto f at_top (principal s) ↔ ∃N, ∀n≥N, f n ∈ s :=
by rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl
/-- A function `f` grows to infinity independent of an order-preserving embedding `e`. -/
lemma tendsto_at_top_embedding {α β γ : Type*} [preorder β] [preorder γ]
{f : α → β} {e : β → γ} {l : filter α}
(hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, c ≤ e b) :
tendsto (e ∘ f) l at_top ↔ tendsto f l at_top :=
begin
rw [tendsto_at_top, tendsto_at_top],
split,
{ assume hc b,
filter_upwards [hc (e b)] assume a, (hm b (f a)).1 },
{ assume hb c,
rcases hu c with ⟨b, hc⟩,
filter_upwards [hb b] assume a ha, le_trans hc ((hm b (f a)).2 ha) }
end
lemma tendsto_at_top_at_top [nonempty α] [semilattice_sup α] [preorder β] (f : α → β) :
tendsto f at_top at_top ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a :=
iff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal
lemma tendsto_at_top_at_bot [nonempty α] [decidable_linear_order α] [preorder β] (f : α → β) :
tendsto f at_top at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), i ≤ a → b ≥ f a :=
@tendsto_at_top_at_top α (order_dual β) _ _ _ f
lemma tendsto_finset_image_at_top_at_top {i : β → γ} {j : γ → β} (h : ∀x, j (i x) = x) :
tendsto (λs:finset γ, s.image j) at_top at_top :=
tendsto_infi.2 $ assume s, tendsto_infi' (s.image i) $ tendsto_principal_principal.2 $
assume t (ht : s.image i ⊆ t),
calc s = (s.image i).image j :
by simp only [finset.image_image, (∘), h]; exact finset.image_id.symm
... ⊆ t.image j : finset.image_subset_image ht
lemma prod_at_top_at_top_eq {β₁ β₂ : Type*} [inhabited β₁] [inhabited β₂] [semilattice_sup β₁]
[semilattice_sup β₂] : filter.prod (@at_top β₁ _) (@at_top β₂ _) = @at_top (β₁ × β₂) _ :=
by simp [at_top, prod_infi_left (default β₁), prod_infi_right (default β₂), infi_prod];
exact infi_comm
lemma prod_map_at_top_eq {α₁ α₂ β₁ β₂ : Type*} [inhabited β₁] [inhabited β₂]
[semilattice_sup β₁] [semilattice_sup β₂] (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) :
filter.prod (map u₁ at_top) (map u₂ at_top) = map (prod.map u₁ u₂) at_top :=
by rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def]
/-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a
Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an
insertion and a connetion above `b'`. -/
lemma map_at_top_eq_of_gc [semilattice_sup α] [semilattice_sup β] {f : α → β} (g : β → α) (b' : β)(hf : monotone f) (gc : ∀a, ∀b≥b', f a ≤ b ↔ a ≤ g b) (hgi : ∀b≥b', b ≤ f (g b)) :
map f at_top = at_top :=
begin
rw [@map_at_top_eq α _ ⟨g b'⟩],
refine le_antisymm
(le_infi $ assume b, infi_le_of_le (g (b ⊔ b')) $ principal_mono.2 $ image_subset_iff.2 _)
(le_infi $ assume a, infi_le_of_le (f a ⊔ b') $ principal_mono.2 _),
{ assume a ha, exact (le_trans le_sup_left $ le_trans (hgi _ le_sup_right) $ hf ha) },
{ assume b hb,
have hb' : b' ≤ b := le_trans le_sup_right hb,
exact ⟨g b, (gc _ _ hb').1 (le_trans le_sup_left hb),
le_antisymm ((gc _ _ hb').2 (le_refl _)) (hgi _ hb')⟩ }
end
lemma map_add_at_top_eq_nat (k : ℕ) : map (λa, a + k) at_top = at_top :=
map_at_top_eq_of_gc (λa, a - k) k
(assume a b h, add_le_add_right h k)
(assume a b h, (nat.le_sub_right_iff_add_le h).symm)
(assume a h, by rw [nat.sub_add_cancel h])
lemma map_sub_at_top_eq_nat (k : ℕ) : map (λa, a - k) at_top = at_top :=
map_at_top_eq_of_gc (λa, a + k) 0
(assume a b h, nat.sub_le_sub_right h _)
(assume a b _, nat.sub_le_right_iff_le_add)
(assume b _, by rw [nat.add_sub_cancel])
lemma tendso_add_at_top_nat (k : ℕ) : tendsto (λa, a + k) at_top at_top :=
le_of_eq (map_add_at_top_eq_nat k)
lemma tendso_sub_at_top_nat (k : ℕ) : tendsto (λa, a - k) at_top at_top :=
le_of_eq (map_sub_at_top_eq_nat k)
lemma tendsto_add_at_top_iff_nat {f : ℕ → α} {l : filter α} (k : ℕ) :
tendsto (λn, f (n + k)) at_top l ↔ tendsto f at_top l :=
show tendsto (f ∘ (λn, n + k)) at_top l ↔ tendsto f at_top l,
by rw [← tendsto_map'_iff, map_add_at_top_eq_nat]
lemma map_div_at_top_eq_nat (k : ℕ) (hk : k > 0) : map (λa, a / k) at_top = at_top :=
map_at_top_eq_of_gc (λb, b * k + (k - 1)) 1
(assume a b h, nat.div_le_div_right h)
(assume a b _,
calc a / k ≤ b ↔ a / k < b + 1 : by rw [← nat.succ_eq_add_one, nat.lt_succ_iff]
... ↔ a < (b + 1) * k : nat.div_lt_iff_lt_mul _ _ hk
... ↔ _ :
begin
cases k,
exact (lt_irrefl _ hk).elim,
simp [mul_add, add_mul, nat.succ_add, nat.lt_succ_iff]
end)
(assume b _,
calc b = (b * k) / k : by rw [nat.mul_div_cancel b hk]
... ≤ (b * k + (k - 1)) / k : nat.div_le_div_right $ nat.le_add_right _ _)
/- ultrafilter -/
section ultrafilter
open zorn
variables {f g : filter α}
/-- An ultrafilter is a minimal (maximal in the set order) proper filter. -/
def is_ultrafilter (f : filter α) := f ≠ ⊥ ∧ ∀g, g ≠ ⊥ → g ≤ f → f ≤ g
lemma ultrafilter_unique (hg : is_ultrafilter g) (hf : f ≠ ⊥) (h : f ≤ g) : f = g :=
le_antisymm h (hg.right _ hf h)
lemma le_of_ultrafilter {g : filter α} (hf : is_ultrafilter f) (h : f ⊓ g ≠ ⊥) :
f ≤ g :=
le_of_inf_eq $ ultrafilter_unique hf h inf_le_left
/-- Equivalent characterization of ultrafilters:
A filter f is an ultrafilter if and only if for each set s,
-s belongs to f if and only if s does not belong to f. -/
lemma ultrafilter_iff_compl_mem_iff_not_mem :
is_ultrafilter f ↔ (∀ s, -s ∈ f ↔ s ∉ f) :=
⟨assume hf s,
⟨assume hns hs,
hf.1 $ empty_in_sets_eq_bot.mp $ by convert f.inter_sets hs hns; rw [inter_compl_self],
assume hs,
have f ≤ principal (-s), from
le_of_ultrafilter hf $ assume h, hs $ mem_sets_of_neq_bot $
by simp only [h, eq_self_iff_true, lattice.neg_neg],
by simp only [le_principal_iff] at this; assumption⟩,
assume hf,
⟨mt empty_in_sets_eq_bot.mpr ((hf ∅).mp (by convert f.univ_sets; rw [compl_empty])),
assume g hg g_le s hs, classical.by_contradiction $ mt (hf s).mpr $
assume : - s ∈ f,
have s ∩ -s ∈ g, from inter_mem_sets hs (g_le this),
by simp only [empty_in_sets_eq_bot, hg, inter_compl_self] at this; contradiction⟩⟩
lemma mem_or_compl_mem_of_ultrafilter (hf : is_ultrafilter f) (s : set α) :
s ∈ f ∨ - s ∈ f :=
classical.or_iff_not_imp_left.2 (ultrafilter_iff_compl_mem_iff_not_mem.mp hf s).mpr
lemma mem_or_mem_of_ultrafilter {s t : set α} (hf : is_ultrafilter f) (h : s ∪ t ∈ f) :
s ∈ f ∨ t ∈ f :=
(mem_or_compl_mem_of_ultrafilter hf s).imp_right
(assume : -s ∈ f, by filter_upwards [this, h] assume x hnx hx, hx.resolve_left hnx)
lemma mem_of_finite_sUnion_ultrafilter {s : set (set α)} (hf : is_ultrafilter f) (hs : finite s)
: ⋃₀ s ∈ f → ∃t∈s, t ∈ f :=
finite.induction_on hs (by simp only [empty_in_sets_eq_bot, hf.left, mem_empty_eq, sUnion_empty,
forall_prop_of_false, exists_false, not_false_iff, exists_prop_of_false]) $
λ t s' ht' hs' ih, by simp only [exists_prop, mem_insert_iff, set.sUnion_insert]; exact
assume h, (mem_or_mem_of_ultrafilter hf h).elim
(assume : t ∈ f, ⟨t, or.inl rfl, this⟩)
(assume h, let ⟨t, hts', ht⟩ := ih h in ⟨t, or.inr hts', ht⟩)
lemma mem_of_finite_Union_ultrafilter {is : set β} {s : β → set α}
(hf : is_ultrafilter f) (his : finite is) (h : (⋃i∈is, s i) ∈ f) : ∃i∈is, s i ∈ f :=
have his : finite (image s is), from finite_image s his,
have h : (⋃₀ image s is) ∈ f, from by simp only [sUnion_image, set.sUnion_image]; assumption,
let ⟨t, ⟨i, hi, h_eq⟩, (ht : t ∈ f)⟩ := mem_of_finite_sUnion_ultrafilter hf his h in
⟨i, hi, h_eq.symm ▸ ht⟩
lemma ultrafilter_map {f : filter α} {m : α → β} (h : is_ultrafilter f) : is_ultrafilter (map m f) :=
by rw ultrafilter_iff_compl_mem_iff_not_mem at ⊢ h; exact assume s, h (m ⁻¹' s)
lemma ultrafilter_pure {a : α} : is_ultrafilter (pure a) :=
begin
rw ultrafilter_iff_compl_mem_iff_not_mem, intro s,
rw [mem_pure_sets, mem_pure_sets], exact iff.rfl
end
lemma ultrafilter_bind {f : filter α} (hf : is_ultrafilter f) {m : α → filter β}
(hm : ∀ a, is_ultrafilter (m a)) : is_ultrafilter (f.bind m) :=
begin
simp only [ultrafilter_iff_compl_mem_iff_not_mem] at ⊢ hf hm, intro s,
dsimp [bind, join, map, preimage],
simp only [hm], apply hf
end
/-- The ultrafilter lemma: Any proper filter is contained in an ultrafilter. -/
lemma exists_ultrafilter (h : f ≠ ⊥) : ∃u, u ≤ f ∧ is_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 r 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 r 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₂⟩
/-- Construct an ultrafilter extending a given filter.
The ultrafilter lemma is the assertion that such a filter exists;
we use the axiom of choice to pick one. -/
noncomputable def ultrafilter_of (f : filter α) : filter α :=
if h : f = ⊥ then ⊥ else classical.epsilon (λu, u ≤ f ∧ is_ultrafilter u)
lemma ultrafilter_of_spec (h : f ≠ ⊥) : ultrafilter_of f ≤ f ∧ is_ultrafilter (ultrafilter_of f) :=
begin
have h' := classical.epsilon_spec (exists_ultrafilter h),
simp only [ultrafilter_of, dif_neg, h, dif_neg, not_false_iff],
simp only at h',
assumption
end
lemma ultrafilter_of_le : ultrafilter_of f ≤ f :=
if h : f = ⊥ then by simp only [ultrafilter_of, dif_pos, h, dif_pos, eq_self_iff_true, le_bot_iff]; exact le_refl _
else (ultrafilter_of_spec h).left
lemma ultrafilter_ultrafilter_of (h : f ≠ ⊥) : is_ultrafilter (ultrafilter_of f) :=
(ultrafilter_of_spec h).right
lemma ultrafilter_of_ultrafilter (h : is_ultrafilter f) : ultrafilter_of f = f :=
ultrafilter_unique h (ultrafilter_ultrafilter_of h.left).left ultrafilter_of_le
/-- A filter equals the intersection of all the ultrafilters which contain it. -/
lemma sup_of_ultrafilters (f : filter α) : f = ⨆ (g) (u : is_ultrafilter g) (H : g ≤ f), g :=
begin
refine le_antisymm _ (supr_le $ λ g, supr_le $ λ u, supr_le $ λ H, H),
intros s hs,
-- If s ∉ f.sets, we'll apply the ultrafilter lemma to the restriction of f to -s.
by_contradiction hs',
let j : (-s) → α := subtype.val,
have j_inv_s : j ⁻¹' s = ∅, by
erw [←preimage_inter_range, subtype.val_range, inter_compl_self, preimage_empty],
let f' := comap j f,
have : f' ≠ ⊥,
{ apply mt empty_in_sets_eq_bot.mpr,
rintro ⟨t, htf, ht⟩,
suffices : t ⊆ s, from absurd (f.sets_of_superset htf this) hs',
rw [subset_empty_iff] at ht,
have : j '' (j ⁻¹' t) = ∅, by rw [ht, image_empty],
erw [image_preimage_eq_inter_range, subtype.val_range, ←subset_compl_iff_disjoint,
set.compl_compl] at this,
exact this },
rcases exists_ultrafilter this with ⟨g', g'f', u'⟩,
simp only [supr_sets_eq, mem_Inter] at hs,
have := hs (g'.map subtype.val) (ultrafilter_map u') (map_le_iff_le_comap.mpr g'f'),
rw [←le_principal_iff, map_le_iff_le_comap, comap_principal, j_inv_s, principal_empty,
le_bot_iff] at this,
exact absurd this u'.1
end
/-- The `tendsto` relation can be checked on ultrafilters. -/
lemma tendsto_iff_ultrafilter (f : α → β) (l₁ : filter α) (l₂ : filter β) :
tendsto f l₁ l₂ ↔ ∀ g, is_ultrafilter g → g ≤ l₁ → g.map f ≤ l₂ :=
⟨assume h g u gx, le_trans (map_mono gx) h,
assume h, by rw [sup_of_ultrafilters l₁]; simpa only [tendsto, map_supr, supr_le_iff]⟩
/- The ultrafilter monad. The monad structure on ultrafilters is the
restriction of the one on filters. -/
def ultrafilter (α : Type u) : Type u := {f : filter α // is_ultrafilter f}
def ultrafilter.map (m : α → β) (u : ultrafilter α) : ultrafilter β :=
⟨u.val.map m, ultrafilter_map u.property⟩
def ultrafilter.pure (x : α) : ultrafilter α := ⟨pure x, ultrafilter_pure⟩
def ultrafilter.bind (u : ultrafilter α) (m : α → ultrafilter β) : ultrafilter β :=
⟨u.val.bind (λ a, (m a).val), ultrafilter_bind u.property (λ a, (m a).property)⟩
instance ultrafilter.has_pure : has_pure ultrafilter := ⟨@ultrafilter.pure⟩
instance ultrafilter.has_bind : has_bind ultrafilter := ⟨@ultrafilter.bind⟩
instance ultrafilter.functor : functor ultrafilter := { map := @ultrafilter.map }
instance ultrafilter.monad : monad ultrafilter := { map := @ultrafilter.map }
noncomputable def hyperfilter : filter α := ultrafilter_of cofinite
lemma hyperfilter_le_cofinite (hi : set.infinite (@set.univ α)) : @hyperfilter α ≤ cofinite :=
(ultrafilter_of_spec (cofinite_ne_bot hi)).1
lemma is_ultrafilter_hyperfilter (hi : set.infinite (@set.univ α)) : is_ultrafilter (@hyperfilter α) :=
(ultrafilter_of_spec (cofinite_ne_bot hi)).2
theorem nmem_hyperfilter_of_finite (hi : set.infinite (@set.univ α)) {s : set α} (hf : set.finite s) :
s ∉ @hyperfilter α :=
λ hy,
have hx : -s ∉ hyperfilter :=
λ hs, (ultrafilter_iff_compl_mem_iff_not_mem.mp (is_ultrafilter_hyperfilter hi) s).mp hs hy,
have ht : -s ∈ cofinite.sets := by show -s ∈ {s | _}; rwa [set.mem_set_of_eq, lattice.neg_neg],
hx $ hyperfilter_le_cofinite hi ht
theorem compl_mem_hyperfilter_of_finite (hi : set.infinite (@set.univ α)) {s : set α} (hf : set.finite s) :
-s ∈ @hyperfilter α :=
(ultrafilter_iff_compl_mem_iff_not_mem.mp (is_ultrafilter_hyperfilter hi) s).mpr $
nmem_hyperfilter_of_finite hi hf
theorem mem_hyperfilter_of_finite_compl (hi : set.infinite (@set.univ α)) {s : set α} (hf : set.finite (-s)) :
s ∈ @hyperfilter α :=
have h : _ := compl_mem_hyperfilter_of_finite hi hf,
by rwa [lattice.neg_neg] at h
section
local attribute [instance] filter.monad filter.is_lawful_monad
instance ultrafilter.is_lawful_monad : is_lawful_monad ultrafilter :=
{ id_map := assume α f, subtype.eq (id_map f.val),
pure_bind := assume α β a f, subtype.eq (pure_bind a (subtype.val ∘ f)),
bind_assoc := assume α β γ f m₁ m₂, subtype.eq (filter_eq rfl),
bind_pure_comp_eq_map := assume α β f x, subtype.eq (bind_pure_comp_eq_map _ f x.val) }
end
lemma ultrafilter.eq_iff_val_le_val {u v : ultrafilter α} : u = v ↔ u.val ≤ v.val :=
⟨assume h, by rw h; exact le_refl _,
assume h, by rw subtype.ext; apply ultrafilter_unique v.property u.property.1 h⟩
lemma exists_ultrafilter_iff (f : filter α) : (∃ (u : ultrafilter α), u.val ≤ f) ↔ f ≠ ⊥ :=
⟨assume ⟨u, uf⟩, lattice.neq_bot_of_le_neq_bot u.property.1 uf,
assume h, let ⟨u, uf, hu⟩ := exists_ultrafilter h in ⟨⟨u, hu⟩, uf⟩⟩
end ultrafilter
end filter
namespace filter
variables {α β γ : Type u} {f : β → filter α} {s : γ → set α}
open list
lemma mem_traverse_sets :
∀(fs : list β) (us : list γ),
forall₂ (λb c, s c ∈ f b) fs us → traverse s us ∈ traverse f fs
| [] [] forall₂.nil := mem_pure_sets.2 $ mem_singleton _
| (f::fs) (u::us) (forall₂.cons h hs) := seq_mem_seq_sets (image_mem_map h) (mem_traverse_sets fs us hs)
lemma mem_traverse_sets_iff (fs : list β) (t : set (list α)) :
t ∈ traverse f fs ↔
(∃us:list (set α), forall₂ (λb (s : set α), s ∈ f b) fs us ∧ sequence us ⊆ t) :=
begin
split,
{ induction fs generalizing t,
case nil { simp only [sequence, pure_def, imp_self, forall₂_nil_left_iff, pure_def,
exists_eq_left, mem_principal_sets, set.pure_def, singleton_subset_iff, traverse_nil] },
case cons : b fs ih t {
assume ht,
rcases mem_seq_sets_iff.1 ht with ⟨u, hu, v, hv, ht⟩,
rcases mem_map_sets_iff.1 hu with ⟨w, hw, hwu⟩,
rcases ih v hv with ⟨us, hus, hu⟩,
exact ⟨w :: us, forall₂.cons hw hus, subset.trans (set.seq_mono hwu hu) ht⟩ } },
{ rintros ⟨us, hus, hs⟩,
exact mem_sets_of_superset (mem_traverse_sets _ _ hus) hs }
end
lemma sequence_mono :
∀(as bs : list (filter α)), forall₂ (≤) as bs → sequence as ≤ sequence bs
| [] [] forall₂.nil := le_refl _
| (a::as) (b::bs) (forall₂.cons h hs) := seq_mono (map_mono h) (sequence_mono as bs hs)
end filter
|
5bb44aac7a696771d465cd5cb8aef91064e6b885
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/algebra/category/Module/adjunctions.lean
|
2392e6e9b8352e11f224e43148ffd89a45893799
|
[
"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,122
|
lean
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johan Commelin
-/
import algebra.category.Module.monoidal
import category_theory.monoidal.functorial
import category_theory.monoidal.types
import linear_algebra.direct_sum.finsupp
import category_theory.linear.linear_functor
/-!
The functor of forming finitely supported functions on a type with values in a `[ring R]`
is the left adjoint of
the forgetful functor from `R`-modules to types.
-/
noncomputable theory
open category_theory
namespace Module
universe u
open_locale classical
variables (R : Type u)
section
variables [ring R]
/--
The free functor `Type u ⥤ Module R` sending a type `X` to the
free `R`-module with generators `x : X`, implemented as the type `X →₀ R`.
-/
@[simps]
def free : Type u ⥤ Module R :=
{ obj := λ X, Module.of R (X →₀ R),
map := λ X Y f, finsupp.lmap_domain _ _ f,
map_id' := by { intros, exact finsupp.lmap_domain_id _ _ },
map_comp' := by { intros, exact finsupp.lmap_domain_comp _ _ _ _, } }
/--
The free-forgetful adjunction for R-modules.
-/
def adj : free R ⊣ forget (Module.{u} R) :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X M, (finsupp.lift M R X).to_equiv.symm,
hom_equiv_naturality_left_symm' := λ _ _ M f g,
finsupp.lhom_ext' (λ x, linear_map.ext_ring
(finsupp.sum_map_domain_index_add_monoid_hom (λ y, ((smul_add_hom R ↥M).flip) (g y))).symm) }
end
namespace free
variables [comm_ring R]
/-- The free R-module functor is lax monoidal. -/
-- In fact, it's strong monoidal, but we don't yet have a typeclass for that.
instance : lax_monoidal.{u} (free R).obj :=
{ -- Send `R` to `punit →₀ R`
ε := finsupp.lsingle punit.star,
-- Send `(α →₀ R) ⊗ (β →₀ R)` to `α × β →₀ R`
μ := λ α β, (finsupp_tensor_finsupp' R α β).to_linear_map,
μ_natural' := begin
intros,
ext x x' ⟨y, y'⟩,
-- This is rather tedious: it's a terminal simp, with no arguments,
-- but between the four of them it is too slow.
simp only [tensor_product.mk_apply, mul_one, tensor_apply, monoidal_category.hom_apply,
Module.free_map, Module.coe_comp, map_functorial_obj,
linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply,
function.comp_app,
finsupp.lmap_domain_apply, finsupp.map_domain_single,
finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply],
end,
left_unitality' := begin
intros,
ext,
simp only [tensor_product.mk_apply, mul_one,
Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj,
Module.monoidal_category.hom_apply, left_unitor_hom_apply,
Module.monoidal_category.left_unitor_hom_apply,
linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply,
function.comp_app,
finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single,
finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply],
end,
right_unitality' := begin
intros,
ext,
simp only [tensor_product.mk_apply, mul_one,
Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj,
Module.monoidal_category.hom_apply, right_unitor_hom_apply,
Module.monoidal_category.right_unitor_hom_apply,
linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply,
function.comp_app,
finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single,
finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply],
end,
associativity' := begin
intros,
ext,
simp only [tensor_product.mk_apply, mul_one,
Module.id_apply, Module.free_map, Module.coe_comp, map_functorial_obj,
Module.monoidal_category.hom_apply, associator_hom_apply,
Module.monoidal_category.associator_hom_apply,
linear_map.compr₂_apply, linear_equiv.coe_to_linear_map, linear_map.comp_apply,
function.comp_app,
finsupp.lmap_domain_apply, finsupp.smul_single', finsupp.map_domain_single,
finsupp_tensor_finsupp'_single_tmul_single, finsupp.lsingle_apply],
end, }
end free
end Module
namespace category_theory
universes v u
/--
`Free R C` is a type synonym for `C`, which, given `[comm_ring R]` and `[category C]`,
we will equip with a category structure where the morphisms are formal `R`-linear combinations
of the morphisms in `C`.
-/
@[nolint unused_arguments has_inhabited_instance]
def Free (R : Type*) (C : Type u) := C
/--
Consider an object of `C` as an object of the `R`-linear completion.
-/
def Free.of (R : Type*) {C : Type u} (X : C) : Free R C := X
variables (R : Type*) [comm_ring R] (C : Type u) [category.{v} C]
open finsupp
-- Conceptually, it would be nice to construct this via "transport of enrichment",
-- using the fact that `Module.free R : Type ⥤ Module R` and `Module.forget` are both lax monoidal.
-- This still seems difficult, so we just do it by hand.
instance category_Free : category (Free R C) :=
{ hom := λ (X Y : C), (X ⟶ Y) →₀ R,
id := λ (X : C), finsupp.single (𝟙 X) 1,
comp := λ (X Y Z : C) f g, f.sum (λ f' s, g.sum (λ g' t, finsupp.single (f' ≫ g') (s * t))),
assoc' := λ W X Y Z f g h,
begin
dsimp,
-- This imitates the proof of associativity for `monoid_algebra`.
simp only [sum_sum_index, sum_single_index,
single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff,
add_mul, mul_add, category.assoc, mul_assoc, zero_mul, mul_zero, sum_zero, sum_add],
end }.
namespace Free
section
local attribute [simp] category_theory.category_Free
@[simp]
lemma single_comp_single {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (r s : R) :
(single f r ≫ single g s : (Free.of R X) ⟶ (Free.of R Z)) = single (f ≫ g) (r * s) :=
by { dsimp, simp, }
instance : preadditive (Free R C) :=
{ hom_group := λ X Y, finsupp.add_comm_group,
add_comp' := λ X Y Z f f' g, begin
dsimp,
rw [finsupp.sum_add_index];
{ simp [add_mul], }
end,
comp_add' := λ X Y Z f g g', begin
dsimp,
rw ← finsupp.sum_add,
congr, ext r h,
rw [finsupp.sum_add_index];
{ simp [mul_add], },
end, }
instance : linear R (Free R C) :=
{ hom_module := λ X Y, finsupp.module (X ⟶ Y) R,
smul_comp' := λ X Y Z r f g, begin
dsimp,
rw [finsupp.sum_smul_index];
simp [finsupp.smul_sum, mul_assoc],
end,
comp_smul' := λ X Y Z f r g, begin
dsimp,
simp_rw [finsupp.smul_sum],
congr, ext h s,
rw [finsupp.sum_smul_index];
simp [finsupp.smul_sum, mul_left_comm],
end, }
end
/--
A category embeds into its `R`-linear completion.
-/
@[simps]
def embedding : C ⥤ Free R C :=
{ obj := λ X, X,
map := λ X Y f, finsupp.single f 1,
map_id' := λ X, rfl,
map_comp' := λ X Y Z f g, by simp, }
variables (R) {C} {D : Type u} [category.{v} D] [preadditive D] [linear R D]
open preadditive linear
/--
A functor to a preadditive category lifts to a functor from its `R`-linear completion.
-/
@[simps]
def lift (F : C ⥤ D) : Free R C ⥤ D :=
{ obj := λ X, F.obj X,
map := λ X Y f, f.sum (λ f' r, r • (F.map f')),
map_id' := by { dsimp [category_theory.category_Free], simp },
map_comp' := λ X Y Z f g, begin
apply finsupp.induction_linear f,
{ simp, },
{ intros f₁ f₂ w₁ w₂,
rw add_comp,
rw [finsupp.sum_add_index, finsupp.sum_add_index],
{ simp [w₁, w₂, add_comp], },
{ simp, },
{ intros, simp only [add_smul], },
{ simp, },
{ intros, simp only [add_smul], }, },
{ intros f' r,
apply finsupp.induction_linear g,
{ simp, },
{ intros f₁ f₂ w₁ w₂,
rw comp_add,
rw [finsupp.sum_add_index, finsupp.sum_add_index],
{ simp [w₁, w₂, add_comp], },
{ simp, },
{ intros, simp only [add_smul], },
{ simp, },
{ intros, simp only [add_smul], }, },
{ intros g' s,
erw single_comp_single,
simp [mul_comm r s, mul_smul], } }
end, }
@[simp]
lemma lift_map_single (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (r : R) :
(lift R F).map (single f r) = r • F.map f :=
by simp
instance lift_additive (F : C ⥤ D) : (lift R F).additive :=
{ map_zero' := by simp,
map_add' := λ X Y f g, begin
dsimp,
rw finsupp.sum_add_index; simp [add_smul]
end, }
instance lift_linear (F : C ⥤ D) : (lift R F).linear R :=
{ map_smul' := λ X Y f r, begin
dsimp,
rw finsupp.sum_smul_index;
simp [finsupp.smul_sum, mul_smul],
end, }
/--
The embedding into the `R`-linear completion, followed by the lift,
is isomorphic to the original functor.
-/
def embedding_lift_iso (F : C ⥤ D) : embedding R C ⋙ lift R F ≅ F :=
nat_iso.of_components
(λ X, iso.refl _)
(by tidy)
/--
Two `R`-linear functors out of the `R`-linear completion are isomorphic iff their
compositions with the embedding functor are isomorphic.
-/
@[ext]
def ext {F G : Free R C ⥤ D} [F.additive] [F.linear R] [G.additive] [G.linear R]
(α : embedding R C ⋙ F ≅ embedding R C ⋙ G) : F ≅ G :=
nat_iso.of_components
(λ X, α.app X)
begin
intros X Y f,
apply finsupp.induction_linear f,
{ simp, },
{ intros f₁ f₂ w₁ w₂,
simp only [F.map_add, G.map_add, add_comp, comp_add, w₁, w₂], },
{ intros f' r,
rw [iso.app_hom, iso.app_hom, ←smul_single_one, F.map_smul, G.map_smul, smul_comp, comp_smul],
change r • (embedding R C ⋙ F).map f' ≫ _ = r • _ ≫ (embedding R C ⋙ G).map f',
rw α.hom.naturality f',
apply_instance, -- Why are these not picked up automatically when we rewrite?
apply_instance, }
end
/--
`Free.lift` is unique amongst `R`-linear functors `Free R C ⥤ D`
which compose with `embedding ℤ C` to give the original functor.
-/
def lift_unique (F : C ⥤ D) (L : Free R C ⥤ D) [L.additive] [L.linear R]
(α : embedding R C ⋙ L ≅ F) :
L ≅ lift R F :=
ext R (α.trans (embedding_lift_iso R F).symm)
end Free
end category_theory
|
ebec6e462b0b7be2542241a741707f24b0d9aed1
|
367134ba5a65885e863bdc4507601606690974c1
|
/src/category_theory/limits/preserves/shapes/binary_products.lean
|
ff3f562bf77266c52a0e8a69a25aeac167a4e07b
|
[
"Apache-2.0"
] |
permissive
|
kodyvajjha/mathlib
|
9bead00e90f68269a313f45f5561766cfd8d5cad
|
b98af5dd79e13a38d84438b850a2e8858ec21284
|
refs/heads/master
| 1,624,350,366,310
| 1,615,563,062,000
| 1,615,563,062,000
| 162,666,963
| 0
| 0
|
Apache-2.0
| 1,545,367,651,000
| 1,545,367,651,000
| null |
UTF-8
|
Lean
| false
| false
| 3,462
|
lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.shapes.binary_products
import category_theory.limits.preserves.basic
/-!
# Preserving binary products
Constructions to relate the notions of preserving binary products and reflecting binary products
to concrete binary fans.
In particular, we show that `prod_comparison G X Y` is an isomorphism iff `G` preserves
the product of `X` and `Y`.
-/
noncomputable theory
universes v u₁ u₂
open category_theory category_theory.category category_theory.limits
variables {C : Type u₁} [category.{v} C]
variables {D : Type u₂} [category.{v} D]
variables (G : C ⥤ D)
namespace category_theory.limits
variables {P X Y Z : C} (f : P ⟶ X) (g : P ⟶ Y)
/--
The map of a binary fan is a limit iff the fork consisting of the mapped morphisms is a limit. This
essentially lets us commute `binary_fan.mk` with `functor.map_cone`.
-/
def is_limit_map_cone_binary_fan_equiv :
is_limit (G.map_cone (binary_fan.mk f g)) ≃ is_limit (binary_fan.mk (G.map f) (G.map g)) :=
(is_limit.postcompose_hom_equiv (diagram_iso_pair _) _).symm.trans
(is_limit.equiv_iso_limit (cones.ext (iso.refl _) (by { rintro (_ | _), tidy })))
/-- The property of preserving products expressed in terms of binary fans. -/
def map_is_limit_of_preserves_of_is_limit [preserves_limit (pair X Y) G]
(l : is_limit (binary_fan.mk f g)) :
is_limit (binary_fan.mk (G.map f) (G.map g)) :=
is_limit_map_cone_binary_fan_equiv G f g (preserves_limit.preserves l)
/-- The property of reflecting products expressed in terms of binary fans. -/
def is_limit_of_reflects_of_map_is_limit [reflects_limit (pair X Y) G]
(l : is_limit (binary_fan.mk (G.map f) (G.map g))) :
is_limit (binary_fan.mk f g) :=
reflects_limit.reflects ((is_limit_map_cone_binary_fan_equiv G f g).symm l)
variables (X Y) [has_binary_product X Y]
/--
If `G` preserves binary products and `C` has them, then the binary fan constructed of the mapped
morphisms of the binary product cone is a limit.
-/
def is_limit_of_has_binary_product_of_preserves_limit
[preserves_limit (pair X Y) G] :
is_limit (binary_fan.mk (G.map (limits.prod.fst : X ⨯ Y ⟶ X)) (G.map (limits.prod.snd))) :=
map_is_limit_of_preserves_of_is_limit G _ _ (prod_is_prod X Y)
variables [has_binary_product (G.obj X) (G.obj Y)]
/--
If the product comparison map for `G` at `(X,Y)` is an isomorphism, then `G` preserves the
pair of `(X,Y)`.
-/
def preserves_pair.of_iso_comparison [i : is_iso (prod_comparison G X Y)] :
preserves_limit (pair X Y) G :=
begin
apply preserves_limit_of_preserves_limit_cone (prod_is_prod X Y),
apply (is_limit_map_cone_binary_fan_equiv _ _ _).symm _,
apply is_limit.of_point_iso (limit.is_limit (pair (G.obj X) (G.obj Y))),
apply i,
end
variables [preserves_limit (pair X Y) G]
/--
If `G` preserves the product of `(X,Y)`, then the product comparison map for `G` at `(X,Y)` is
an isomorphism.
-/
def preserves_pair.iso :
G.obj (X ⨯ Y) ≅ G.obj X ⨯ G.obj Y :=
is_limit.cone_point_unique_up_to_iso
(is_limit_of_has_binary_product_of_preserves_limit G X Y)
(limit.is_limit _)
@[simp]
lemma preserves_pair.iso_hom : (preserves_pair.iso G X Y).hom = prod_comparison G X Y := rfl
instance : is_iso (prod_comparison G X Y) :=
begin
rw ← preserves_pair.iso_hom,
apply_instance
end
end category_theory.limits
|
e9746df5e9a77b51246cfc7e3f974f57c55a3eab
|
4e3bf8e2b29061457a887ac8889e88fa5aa0e34c
|
/lean/love09_hoare_logic_homework_sheet.lean
|
6a82c2640e066820f476109e5e180f9eabd2076f
|
[] |
no_license
|
mukeshtiwari/logical_verification_2019
|
9f964c067a71f65eb8884743273fbeef99e6503d
|
16f62717f55ed5b7b87e03ae0134791a9bef9b9a
|
refs/heads/master
| 1,619,158,844,208
| 1,585,139,500,000
| 1,585,139,500,000
| 249,906,380
| 0
| 0
| null | 1,585,118,728,000
| 1,585,118,727,000
| null |
UTF-8
|
Lean
| false
| false
| 2,539
|
lean
|
/- LoVe Homework 9: Hoare Logic -/
import .love08_operational_semantics_exercise_sheet
import .love09_hoare_logic_demo
namespace LoVe
/- Question 1: Hoare Logic for Dijkstra's Guarded Command Language -/
/- Recall the definition of GCL from exercise 8: -/
#check gcl
namespace gcl
#check big_step
/- The definition of Hoare triples for partial correctness is unsurprising: -/
def partial_hoare (P : state → Prop) (S : gcl state) (Q : state → Prop) :
Prop :=
∀s t, P s → (S, s) ~~> t → Q t
local notation `{* ` P : 1 ` *} ` S : 1 ` {* ` Q : 1 ` *}` :=
partial_hoare P S Q
namespace partial_hoare
variables {P P' P₁ P₂ P₃ Q Q' : state → Prop} {x : string} {a : state → ℕ}
variables {S S₀ S₁ S₂ : gcl state} {Ss : list (gcl state)}
/- 1.1. Prove the consequence rule. -/
lemma consequence (h : {* P *} S {* Q *}) (hp : ∀s, P' s → P s)
(hq : ∀s, Q s → Q' s) :
{* P' *} S {* Q' *} :=
sorry
/- 1.2. Prove the rule for `assign`. -/
lemma assign_intro (P : state → Prop) :
{* λs : state, P (s{x ↦ a s}) *} assign x a {* P *} :=
sorry
/- 1.3. Prove the rule for `assert`. -/
lemma assert_intro :
{* λs, Q s → P s *} assert Q {* P *} :=
sorry
/- 1.4. Prove the rule for `seq`. -/
lemma seq_intro (h₁ : {* P₁ *} S₁ {* P₂ *}) (h₂ : {* P₂ *} S₂ {* P₃ *}) :
{* P₁ *} seq S₁ S₂ {* P₃ *} :=
sorry
/- 1.5. Prove the rule for `choice`. -/
lemma choice_intro
(h : ∀i (hi : i < list.length Ss),
{* λs, P s *} list.nth_le Ss i hi {* Q *}) :
{* P *} choice Ss {* Q *} :=
sorry
/- 1.6. State the rule for `loop`.
lemma loop_intro … :
{* … *} loop p {* … *} :=
… -/
/- 1.7 **optional**. Prove the rule you stated for `loop`.
Hint: This one is difficult and requires some generalization, as explained in
Section 5.8 ("Induction Pitfalls") of the lecture notes. -/
-- enter your answer to question 1.6 here
-- enter your answer to question 1.7 here
end partial_hoare
end gcl
/- Question 2: Factorial -/
section FACT
/- The following WHILE program is intended to compute the factorial of `n`,
leaving the result in `r`. -/
def FACT : program :=
assign "r" (λs, 1) ;;
while (λs, s "n" ≠ 0)
(assign "r" (λs, s "r" * s "n") ;;
assign "n" (λs, s "n" - 1))
/- 2.1. Define the factorial function. -/
def fact : ℕ → ℕ
:= sorry
/- 2.2. Prove the correctness of `FACT` using `vcg`. -/
lemma FACT_correct (n : ℕ) :
{* λs, s "n" = n *} FACT {* λs, s "r" = fact n *} :=
sorry
end FACT
end LoVe
|
f2c8b331e4cd43699dd3e9f861e0f5875f0aba9f
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/algebra/big_operators/finprod.lean
|
6ab0a5ecbcbf0d6c68d5266834a9c285856b2c4b
|
[
"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
| 43,629
|
lean
|
/-
Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov
-/
import algebra.big_operators.order
import algebra.indicator_function
/-!
# Finite products and sums over types and sets
We define products and sums over types and subsets of types, with no finiteness hypotheses.
All infinite products and sums are defined to be junk values (i.e. one or zero).
This approach is sometimes easier to use than `finset.sum`,
when issues arise with `finset` and `fintype` being data.
## Main definitions
We use the following variables:
* `α`, `β` - types with no structure;
* `s`, `t` - sets
* `M`, `N` - additive or multiplicative commutative monoids
* `f`, `g` - functions
Definitions in this file:
* `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite.
Zero otherwise.
* `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if
it's finite. One otherwise.
## Notation
* `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f`
* `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f`
This notation works for functions `f : p → M`, where `p : Prop`, so the following works:
* `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : set α` : sum over the set `s`;
* `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`;
* `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`.
## Implementation notes
`finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However
experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings
where the user is not interested in computability and wants to do reasoning without running into
typeclass diamonds caused by the constructive finiteness used in definitions such as `finset` and
`fintype`. By sticking solely to `set.finite` we avoid these problems. We are aware that there are
other solutions but for beginner mathematicians this approach is easier in practice.
Another application is the construction of a partition of unity from a collection of “bump”
function. In this case the finite set depends on the point and it's convenient to have a definition
that does not mention the set explicitly.
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
We did not add `is_finite (X : Type) : Prop`, because it is simply `nonempty (fintype X)`.
## Tags
finsum, finprod, finite sum, finite product
-/
open function set
/-!
### Definition and relation to `finset.sum` and `finset.prod`
-/
section sort
variables {M N : Type*} {α β ι : Sort*} [comm_monoid M] [comm_monoid N]
open_locale big_operators
section
/- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas
with `classical.dec` in their statement. -/
open_locale classical
/-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero
otherwise. -/
@[irreducible] noncomputable def finsum {M α} [add_comm_monoid M] (f : α → M) : M :=
if h : finite (support (f ∘ plift.down)) then ∑ i in h.to_finset, f i.down else 0
/-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's
finite. One otherwise. -/
@[irreducible, to_additive]
noncomputable def finprod (f : α → M) : M :=
if h : finite (mul_support (f ∘ plift.down)) then ∏ i in h.to_finset, f i.down else 1
end
localized "notation `∑ᶠ` binders `, ` r:(scoped:67 f, finsum f) := r" in big_operators
localized "notation `∏ᶠ` binders `, ` r:(scoped:67 f, finprod f) := r" in big_operators
@[to_additive] lemma finprod_eq_prod_plift_of_mul_support_to_finset_subset
{f : α → M} (hf : finite (mul_support (f ∘ plift.down))) {s : finset (plift α)}
(hs : hf.to_finset ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i.down :=
begin
rw [finprod, dif_pos],
refine finset.prod_subset hs (λ x hx hxf, _),
rwa [hf.mem_to_finset, nmem_mul_support] at hxf
end
@[to_additive] lemma finprod_eq_prod_plift_of_mul_support_subset
{f : α → M} {s : finset (plift α)} (hs : mul_support (f ∘ plift.down) ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i.down :=
finprod_eq_prod_plift_of_mul_support_to_finset_subset
(s.finite_to_set.subset hs) $ λ x hx, by { rw finite.mem_to_finset at hx, exact hs hx }
@[simp, to_additive] lemma finprod_one : ∏ᶠ i : α, (1 : M) = 1 :=
begin
have : mul_support (λ x : plift α, (λ _, 1 : α → M) x.down) ⊆ (∅ : finset (plift α)),
from λ x h, h rfl,
rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_empty]
end
@[to_additive] lemma finprod_of_is_empty [is_empty α] (f : α → M) : ∏ᶠ i, f i = 1 :=
by { rw ← finprod_one, congr }
@[simp, to_additive] lemma finprod_false (f : false → M) : ∏ᶠ i, f i = 1 :=
finprod_of_is_empty _
@[to_additive] lemma finprod_eq_single (f : α → M) (a : α) (ha : ∀ x ≠ a, f x = 1) :
∏ᶠ x, f x = f a :=
begin
have : mul_support (f ∘ plift.down) ⊆ ({plift.up a} : finset (plift α)),
{ intro x, contrapose,
simpa [plift.eq_up_iff_down_eq] using ha x.down },
rw [finprod_eq_prod_plift_of_mul_support_subset this, finset.prod_singleton],
end
@[to_additive] lemma finprod_unique [unique α] (f : α → M) : ∏ᶠ i, f i = f default :=
finprod_eq_single f default $ λ x hx, (hx $ unique.eq_default _).elim
@[simp, to_additive] lemma finprod_true (f : true → M) : ∏ᶠ i, f i = f trivial :=
@finprod_unique M true _ ⟨⟨trivial⟩, λ _, rfl⟩ f
@[to_additive] lemma finprod_eq_dif {p : Prop} [decidable p] (f : p → M) :
∏ᶠ i, f i = if h : p then f h else 1 :=
begin
split_ifs,
{ haveI : unique p := ⟨⟨h⟩, λ _, rfl⟩, exact finprod_unique f },
{ haveI : is_empty p := ⟨h⟩, exact finprod_of_is_empty f }
end
@[to_additive] lemma finprod_eq_if {p : Prop} [decidable p] {x : M} :
∏ᶠ i : p, x = if p then x else 1 :=
finprod_eq_dif (λ _, x)
@[to_additive] lemma finprod_congr {f g : α → M} (h : ∀ x, f x = g x) :
finprod f = finprod g :=
congr_arg _ $ funext h
@[congr, to_additive] lemma finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q)
(hfg : ∀ h : q, f (hpq.mpr h) = g h) :
finprod f = finprod g :=
by { subst q, exact finprod_congr hfg }
attribute [congr] finsum_congr_Prop
/-- To prove a property of a finite product, it suffices to prove that the property is
multiplicative and holds on multipliers. -/
@[to_additive] lemma finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1)
(hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) :
p (∏ᶠ i, f i) :=
begin
rw finprod,
split_ifs,
exacts [finset.prod_induction _ _ hp₁ hp₀ (λ i hi, hp₂ _), hp₀]
end
/-- To prove a property of a finite sum, it suffices to prove that the property is
additive and holds on summands. -/
add_decl_doc finsum_induction
lemma finprod_nonneg {R : Type*} [ordered_comm_semiring R] {f : α → R} (hf : ∀ x, 0 ≤ f x) :
0 ≤ ∏ᶠ x, f x :=
finprod_induction (λ x, 0 ≤ x) zero_le_one (λ x y, mul_nonneg) hf
@[to_additive finsum_nonneg]
lemma one_le_finprod' {M : Type*} [ordered_comm_monoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) :
1 ≤ ∏ᶠ i, f i :=
finprod_induction _ le_rfl (λ _ _, one_le_mul) hf
@[to_additive] lemma monoid_hom.map_finprod_plift (f : M →* N) (g : α → M)
(h : finite (mul_support $ g ∘ plift.down)) :
f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) :=
begin
rw [finprod_eq_prod_plift_of_mul_support_subset h.coe_to_finset.ge,
finprod_eq_prod_plift_of_mul_support_subset, f.map_prod],
rw [h.coe_to_finset],
exact mul_support_comp_subset f.map_one (g ∘ plift.down)
end
@[to_additive] lemma monoid_hom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) :
f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) :=
f.map_finprod_plift g (finite.of_fintype _)
@[to_additive] lemma monoid_hom.map_finprod_of_preimage_one (f : M →* N)
(hf : ∀ x, f x = 1 → x = 1) (g : α → M) :
f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) :=
begin
by_cases hg : (mul_support $ g ∘ plift.down).finite, { exact f.map_finprod_plift g hg },
rw [finprod, dif_neg, f.map_one, finprod, dif_neg],
exacts [infinite.mono (λ x hx, mt (hf (g x.down)) hx) hg, hg]
end
@[to_additive] lemma monoid_hom.map_finprod_of_injective (g : M →* N) (hg : injective g)
(f : α → M) :
g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.map_finprod_of_preimage_one (λ x, (hg.eq_iff' g.map_one).mp) f
@[to_additive] lemma mul_equiv.map_finprod (g : M ≃* N) (f : α → M) :
g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.to_monoid_hom.map_finprod_of_injective g.injective f
lemma finsum_smul {R M : Type*} [ring R] [add_comm_group M] [module R M]
[no_zero_smul_divisors R M] (f : ι → R) (x : M) :
(∑ᶠ i, f i) • x = (∑ᶠ i, (f i) • x) :=
begin
rcases eq_or_ne x 0 with rfl|hx, { simp },
exact ((smul_add_hom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _
end
lemma smul_finsum {R M : Type*} [ring R] [add_comm_group M] [module R M]
[no_zero_smul_divisors R M] (c : R) (f : ι → M) :
c • (∑ᶠ i, f i) = (∑ᶠ i, c • f i) :=
begin
rcases eq_or_ne c 0 with rfl|hc, { simp },
exact (smul_add_hom R M c).map_finsum_of_injective (smul_right_injective M hc) _
end
@[to_additive] lemma finprod_inv_distrib {G : Type*} [comm_group G] (f : α → G) :
∏ᶠ x, (f x)⁻¹ = (∏ᶠ x, f x)⁻¹ :=
((mul_equiv.inv G).map_finprod f).symm
lemma finprod_inv_distrib₀ {G : Type*} [comm_group_with_zero G] (f : α → G) :
∏ᶠ x, (f x)⁻¹ = (∏ᶠ x, f x)⁻¹ :=
((mul_equiv.inv₀ G).map_finprod f).symm
end sort
section type
variables {α β ι M N : Type*} [comm_monoid M] [comm_monoid N]
open_locale big_operators
@[to_additive] lemma finprod_eq_mul_indicator_apply (s : set α)
(f : α → M) (a : α) :
∏ᶠ (h : a ∈ s), f a = mul_indicator s f a :=
by convert finprod_eq_if
@[simp, to_additive] lemma finprod_mem_mul_support (f : α → M) (a : α) :
∏ᶠ (h : f a ≠ 1), f a = f a :=
by rw [← mem_mul_support, finprod_eq_mul_indicator_apply, mul_indicator_mul_support]
@[to_additive] lemma finprod_mem_def (s : set α) (f : α → M) :
∏ᶠ a ∈ s, f a = ∏ᶠ a, mul_indicator s f a :=
finprod_congr $ finprod_eq_mul_indicator_apply s f
@[to_additive] lemma finprod_eq_prod_of_mul_support_subset (f : α → M) {s : finset α}
(h : mul_support f ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i :=
begin
have A : mul_support (f ∘ plift.down) = equiv.plift.symm '' mul_support f,
{ rw mul_support_comp_eq_preimage,
exact (equiv.plift.symm.image_eq_preimage _).symm },
have : mul_support (f ∘ plift.down) ⊆ s.map equiv.plift.symm.to_embedding,
{ rw [A, finset.coe_map], exact image_subset _ h },
rw [finprod_eq_prod_plift_of_mul_support_subset this],
simp
end
@[to_additive] lemma finprod_eq_prod_of_mul_support_to_finset_subset (f : α → M)
(hf : finite (mul_support f)) {s : finset α} (h : hf.to_finset ⊆ s) :
∏ᶠ i, f i = ∏ i in s, f i :=
finprod_eq_prod_of_mul_support_subset _ $ λ x hx, h $ hf.mem_to_finset.2 hx
@[to_additive] lemma finprod_def (f : α → M) [decidable (mul_support f).finite] :
∏ᶠ i : α, f i = if h : (mul_support f).finite then ∏ i in h.to_finset, f i else 1 :=
begin
split_ifs,
{ exact finprod_eq_prod_of_mul_support_to_finset_subset _ h (finset.subset.refl _) },
{ rw [finprod, dif_neg],
rw [mul_support_comp_eq_preimage],
exact mt (λ hf, hf.of_preimage equiv.plift.surjective) h}
end
@[to_additive] lemma finprod_of_infinite_mul_support {f : α → M} (hf : (mul_support f).infinite) :
∏ᶠ i, f i = 1 :=
by { classical, rw [finprod_def, dif_neg hf] }
@[to_additive] lemma finprod_eq_prod (f : α → M) (hf : (mul_support f).finite) :
∏ᶠ i : α, f i = ∏ i in hf.to_finset, f i :=
by { classical, rw [finprod_def, dif_pos hf] }
@[to_additive] lemma finprod_eq_prod_of_fintype [fintype α] (f : α → M) :
∏ᶠ i : α, f i = ∏ i, f i :=
finprod_eq_prod_of_mul_support_to_finset_subset _ (finite.of_fintype _) $ finset.subset_univ _
@[to_additive] lemma finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : finset α}
(h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) :
∏ᶠ i (hi : p i), f i = ∏ i in t, f i :=
begin
set s := {x | p x},
have : mul_support (s.mul_indicator f) ⊆ t,
{ rw [set.mul_support_mul_indicator], intros x hx, exact (h hx.2).1 hx.1 },
erw [finprod_mem_def, finprod_eq_prod_of_mul_support_subset _ this],
refine finset.prod_congr rfl (λ x hx, mul_indicator_apply_eq_self.2 $ λ hxs, _),
contrapose! hxs,
exact (h hxs).2 hx
end
@[to_additive] lemma finprod_cond_ne (f : α → M) (a : α) [decidable_eq α]
(hf : finite (mul_support f)) : (∏ᶠ i ≠ a, f i) = ∏ i in hf.to_finset.erase a, f i :=
begin
apply finprod_cond_eq_prod_of_cond_iff,
intros x hx,
rw [finset.mem_erase, finite.mem_to_finset, mem_mul_support],
exact ⟨λ h, and.intro h hx, λ h, h.1⟩
end
@[to_additive] lemma finprod_mem_eq_prod_of_inter_mul_support_eq (f : α → M) {s : set α}
{t : finset α} (h : s ∩ mul_support f = t ∩ mul_support f) :
∏ᶠ i ∈ s, f i = ∏ i in t, f i :=
finprod_cond_eq_prod_of_cond_iff _ $ by simpa [set.ext_iff] using h
@[to_additive] lemma finprod_mem_eq_prod_of_subset (f : α → M) {s : set α} {t : finset α}
(h₁ : s ∩ mul_support f ⊆ t) (h₂ : ↑t ⊆ s) :
∏ᶠ i ∈ s, f i = ∏ i in t, f i :=
finprod_cond_eq_prod_of_cond_iff _ $ λ x hx, ⟨λ h, h₁ ⟨h, hx⟩, λ h, h₂ h⟩
@[to_additive] lemma finprod_mem_eq_prod (f : α → M) {s : set α}
(hf : (s ∩ mul_support f).finite) :
∏ᶠ i ∈ s, f i = ∏ i in hf.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_assoc]
@[to_additive] lemma finprod_mem_eq_prod_filter (f : α → M) (s : set α) [decidable_pred (∈ s)]
(hf : (mul_support f).finite) :
∏ᶠ i ∈ s, f i = ∏ i in finset.filter (∈ s) hf.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by simp [inter_comm, inter_left_comm]
@[to_additive] lemma finprod_mem_eq_to_finset_prod (f : α → M) (s : set α) [fintype s] :
∏ᶠ i ∈ s, f i = ∏ i in s.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [coe_to_finset]
@[to_additive] lemma finprod_mem_eq_finite_to_finset_prod (f : α → M) {s : set α} (hs : s.finite) :
∏ᶠ i ∈ s, f i = ∏ i in hs.to_finset, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ $ by rw [hs.coe_to_finset]
@[to_additive] lemma finprod_mem_finset_eq_prod (f : α → M) (s : finset α) :
∏ᶠ i ∈ s, f i = ∏ i in s, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl
@[to_additive] lemma finprod_mem_coe_finset (f : α → M) (s : finset α) :
∏ᶠ i ∈ (s : set α), f i = ∏ i in s, f i :=
finprod_mem_eq_prod_of_inter_mul_support_eq _ rfl
@[to_additive] lemma finprod_mem_eq_one_of_infinite {f : α → M} {s : set α}
(hs : (s ∩ mul_support f).infinite) : ∏ᶠ i ∈ s, f i = 1 :=
begin
rw finprod_mem_def,
apply finprod_of_infinite_mul_support,
rwa [← mul_support_mul_indicator] at hs
end
@[to_additive]
lemma finprod_mem_eq_one_of_forall_eq_one {f : α → M} {s : set α} (h : ∀ x ∈ s, f x = 1) :
∏ᶠ i ∈ s, f i = 1 :=
by simp [h] {contextual := tt}
@[to_additive] lemma finprod_mem_inter_mul_support (f : α → M) (s : set α) :
∏ᶠ i ∈ (s ∩ mul_support f), f i = ∏ᶠ i ∈ s, f i :=
by rw [finprod_mem_def, finprod_mem_def, mul_indicator_inter_mul_support]
@[to_additive] lemma finprod_mem_inter_mul_support_eq (f : α → M) (s t : set α)
(h : s ∩ mul_support f = t ∩ mul_support f) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_inter_mul_support, h, finprod_mem_inter_mul_support]
@[to_additive] lemma finprod_mem_inter_mul_support_eq' (f : α → M) (s t : set α)
(h : ∀ x ∈ mul_support f, x ∈ s ↔ x ∈ t) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i :=
begin
apply finprod_mem_inter_mul_support_eq,
ext x,
exact and_congr_left (h x)
end
@[to_additive] lemma finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @set.univ α, f i = ∏ᶠ i : α, f i :=
finprod_congr $ λ i, finprod_true _
variables {f g : α → M} {a b : α} {s t : set α}
@[to_additive] lemma finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i :=
h₀.symm ▸ (finprod_congr $ λ i, finprod_congr_Prop rfl (h₁ i))
@[to_additive]
lemma finprod_eq_one_of_forall_eq_one {f : α → M} (h : ∀ x, f x = 1) :
∏ᶠ i, f i = 1 :=
by simp [h] {contextual := tt}
/-!
### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication
-/
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals
the product of `f i` multiplied by the product over `g i`. -/
@[to_additive] lemma finprod_mul_distrib (hf : (mul_support f).finite)
(hg : (mul_support g).finite) :
∏ᶠ i, (f i * g i) = (∏ᶠ i, f i) * ∏ᶠ i, g i :=
begin
classical,
rw [finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_union_left _ _),
finprod_eq_prod_of_mul_support_to_finset_subset _ hg (finset.subset_union_right _ _),
← finset.prod_mul_distrib],
refine finprod_eq_prod_of_mul_support_subset _ _,
simp [mul_support_mul]
end
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i`
equals the product of `f i` divided by the product over `g i`. -/
@[to_additive] lemma finprod_div_distrib {G : Type*} [comm_group G] {f g : α → G}
(hf : (mul_support f).finite) (hg : (mul_support g).finite) :
∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i :=
by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mul_support_inv g).symm.rec hg),
finprod_inv_distrib]
lemma finprod_div_distrib₀ {G : Type*} [comm_group_with_zero G] {f g : α → G}
(hf : (mul_support f).finite) (hg : (mul_support g).finite) :
∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i :=
by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mul_support_inv₀ g).symm.rec hg),
finprod_inv_distrib₀]
/-- A more general version of `finprod_mem_mul_distrib` that requires `s ∩ mul_support f` and
`s ∩ mul_support g` instead of `s` to be finite. -/
@[to_additive] lemma finprod_mem_mul_distrib' (hf : (s ∩ mul_support f).finite)
(hg : (s ∩ mul_support g).finite) :
∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i :=
begin
rw [← mul_support_mul_indicator] at hf hg,
simp only [finprod_mem_def, mul_indicator_mul, finprod_mul_distrib hf hg]
end
/-- The product of constant one over any set equals one. -/
@[to_additive] lemma finprod_mem_one (s : set α) : ∏ᶠ i ∈ s, (1 : M) = 1 := by simp
/-- If a function `f` equals one on a set `s`, then the product of `f i` over `i ∈ s` equals one. -/
@[to_additive] lemma finprod_mem_of_eq_on_one (hf : eq_on f 1 s) : ∏ᶠ i ∈ s, f i = 1 :=
by { rw ← finprod_mem_one s, exact finprod_mem_congr rfl hf }
/-- If the product of `f i` over `i ∈ s` is not equal to one, then there is some `x ∈ s`
such that `f x ≠ 1`. -/
@[to_additive] lemma exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) :
∃ x ∈ s, f x ≠ 1 :=
begin
by_contra' h',
exact h (finprod_mem_of_eq_on_one h')
end
/-- Given a finite set `s`, the product of `f i * g i` over `i ∈ s` equals the product of `f i`
over `i ∈ s` times the product of `g i` over `i ∈ s`. -/
@[to_additive] lemma finprod_mem_mul_distrib (hs : s.finite) :
∏ᶠ i ∈ s, (f i * g i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i :=
finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _)
@[to_additive] lemma monoid_hom.map_finprod {f : α → M} (g : M →* N) (hf : (mul_support f).finite) :
g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.map_finprod_plift f $ hf.preimage $ equiv.plift.injective.inj_on _
/-- A more general version of `monoid_hom.map_finprod_mem` that requires `s ∩ mul_support f` and
instead of `s` to be finite. -/
@[to_additive] lemma monoid_hom.map_finprod_mem' {f : α → M} (g : M →* N)
(h₀ : (s ∩ mul_support f).finite) :
g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, (g (f i)) :=
begin
rw [g.map_finprod],
{ simp only [g.map_finprod_Prop] },
{ simpa only [finprod_eq_mul_indicator_apply, mul_support_mul_indicator] }
end
/-- Given a monoid homomorphism `g : M →* N`, and a function `f : α → M`, the value of `g` at the
product of `f i` over `i ∈ s` equals the product of `(g ∘ f) i` over `s`. -/
@[to_additive] lemma monoid_hom.map_finprod_mem (f : α → M) (g : M →* N) (hs : s.finite) :
g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) :=
g.map_finprod_mem' (hs.inter_of_left _)
@[to_additive] lemma mul_equiv.map_finprod_mem (g : M ≃* N) (f : α → M) {s : set α}
(hs : s.finite) : g (∏ᶠ i ∈ s, f i) = ∏ᶠ i ∈ s, g (f i) :=
g.to_monoid_hom.map_finprod_mem f hs
@[to_additive] lemma finprod_mem_inv_distrib {G : Type*} [comm_group G] (f : α → G)
(hs : s.finite) : ∏ᶠ x ∈ s, (f x)⁻¹ = (∏ᶠ x ∈ s, f x)⁻¹ :=
((mul_equiv.inv G).map_finprod_mem f hs).symm
lemma finprod_mem_inv_distrib₀ {G : Type*} [comm_group_with_zero G] (f : α → G)
(hs : s.finite) : ∏ᶠ x ∈ s, (f x)⁻¹ = (∏ᶠ x ∈ s, f x)⁻¹ :=
((mul_equiv.inv₀ G).map_finprod_mem f hs).symm
/-- Given a finite set `s`, the product of `f i / g i` over `i ∈ s` equals the product of `f i`
over `i ∈ s` divided by the product of `g i` over `i ∈ s`. -/
@[to_additive] lemma finprod_mem_div_distrib {G : Type*} [comm_group G] (f g : α → G)
(hs : s.finite) : ∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i :=
by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib g hs]
lemma finprod_mem_div_distrib₀ {G : Type*} [comm_group_with_zero G] (f g : α → G)
(hs : s.finite) : ∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i :=
by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib₀ g hs]
/-!
### `∏ᶠ x ∈ s, f x` and set operations
-/
/-- The product of any function over an empty set is one. -/
@[to_additive] lemma finprod_mem_empty : ∏ᶠ i ∈ (∅ : set α), f i = 1 := by simp
/-- A set `s` is not empty if the product of some function over `s` is not equal to one. -/
@[to_additive] lemma nonempty_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : s.nonempty :=
ne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ finprod_mem_empty
/-- Given finite sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` times the product of
`f i` over `i ∈ s ∩ t` equals the product of `f i` over `i ∈ s` times the product of `f i`
over `i ∈ t`. -/
@[to_additive] lemma finprod_mem_union_inter (hs : s.finite) (ht : t.finite) :
(∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
begin
lift s to finset α using hs, lift t to finset α using ht,
classical,
rw [← finset.coe_union, ← finset.coe_inter],
simp only [finprod_mem_coe_finset, finset.prod_union_inter]
end
/-- A more general version of `finprod_mem_union_inter` that requires `s ∩ mul_support f` and
`t ∩ mul_support f` instead of `s` and `t` to be finite. -/
@[to_additive] lemma finprod_mem_union_inter'
(hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) :
(∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
begin
rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t,
← finprod_mem_union_inter hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support,
← finprod_mem_inter_mul_support f (s ∩ t)],
congr' 2,
rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm]
end
/-- A more general version of `finprod_mem_union` that requires `s ∩ mul_support f` and
`t ∩ mul_support f` instead of `s` and `t` to be finite. -/
@[to_additive] lemma finprod_mem_union' (hst : disjoint s t) (hs : (s ∩ mul_support f).finite)
(ht : (t ∩ mul_support f).finite) :
∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty,
mul_one]
/-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` equals the
product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/
@[to_additive] lemma finprod_mem_union (hst : disjoint s t) (hs : s.finite) (ht : t.finite) :
∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _)
/-- A more general version of `finprod_mem_union'` that requires `s ∩ mul_support f` and
`t ∩ mul_support f` instead of `s` and `t` to be disjoint -/
@[to_additive] lemma finprod_mem_union'' (hst : disjoint (s ∩ mul_support f) (t ∩ mul_support f))
(hs : (s ∩ mul_support f).finite) (ht : (t ∩ mul_support f).finite) :
∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_inter_mul_support f s, ← finprod_mem_inter_mul_support f t,
← finprod_mem_union hst hs ht, ← union_inter_distrib_right, finprod_mem_inter_mul_support]
/-- The product of `f i` over `i ∈ {a}` equals `f a`. -/
@[to_additive] lemma finprod_mem_singleton : ∏ᶠ i ∈ ({a} : set α), f i = f a :=
by rw [← finset.coe_singleton, finprod_mem_coe_finset, finset.prod_singleton]
@[simp, to_additive] lemma finprod_cond_eq_left : ∏ᶠ i = a, f i = f a :=
finprod_mem_singleton
@[simp, to_additive] lemma finprod_cond_eq_right : ∏ᶠ i (hi : a = i), f i = f a :=
by simp [@eq_comm _ a]
/-- A more general version of `finprod_mem_insert` that requires `s ∩ mul_support f` instead of
`s` to be finite. -/
@[to_additive] lemma finprod_mem_insert' (f : α → M) (h : a ∉ s)
(hs : (s ∩ mul_support f).finite) :
∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i :=
begin
rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton],
{ rwa disjoint_singleton_left },
{ exact (finite_singleton a).inter_of_left _ }
end
/-- Given a finite set `s` and an element `a ∉ s`, the product of `f i` over `i ∈ insert a s` equals
`f a` times the product of `f i` over `i ∈ s`. -/
@[to_additive] lemma finprod_mem_insert (f : α → M) (h : a ∉ s) (hs : s.finite) :
∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i :=
finprod_mem_insert' f h $ hs.inter_of_left _
/-- If `f a = 1` for all `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the
product of `f i` over `i ∈ s`. -/
@[to_additive] lemma finprod_mem_insert_of_eq_one_if_not_mem (h : a ∉ s → f a = 1) :
∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i :=
begin
refine finprod_mem_inter_mul_support_eq' _ _ _ (λ x hx, ⟨_, or.inr⟩),
rintro (rfl|hxs),
exacts [not_imp_comm.1 h hx, hxs]
end
/-- If `f a = 1`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over
`i ∈ s`. -/
@[to_additive] lemma finprod_mem_insert_one (h : f a = 1) :
∏ᶠ i ∈ (insert a s), f i = ∏ᶠ i ∈ s, f i :=
finprod_mem_insert_of_eq_one_if_not_mem (λ _, h)
/-- If the multiplicative support of `f` is finite, then for every `x` in the domain of `f`,
`f x` divides `finprod f`. -/
lemma finprod_mem_dvd {f : α → N} (a : α) (hf : finite (mul_support f)) :
f a ∣ finprod f :=
begin
by_cases ha : a ∈ mul_support f,
{ rw finprod_eq_prod_of_mul_support_to_finset_subset f hf (set.subset.refl _),
exact finset.dvd_prod_of_mem f ((finite.mem_to_finset hf).mpr ha) },
{ rw nmem_mul_support.mp ha,
exact one_dvd (finprod f) }
end
/-- The product of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a * f b`. -/
@[to_additive] lemma finprod_mem_pair (h : a ≠ b) : ∏ᶠ i ∈ ({a, b} : set α), f i = f a * f b :=
by { rw [finprod_mem_insert, finprod_mem_singleton], exacts [h, finite_singleton b] }
/-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s`
provided that `g` is injective on `s ∩ mul_support (f ∘ g)`. -/
@[to_additive] lemma finprod_mem_image' {s : set β} {g : β → α}
(hg : set.inj_on g (s ∩ mul_support (f ∘ g))) :
∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) :=
begin
classical,
by_cases hs : finite (s ∩ mul_support (f ∘ g)),
{ have hg : ∀ (x ∈ hs.to_finset) (y ∈ hs.to_finset), g x = g y → x = y,
by simpa only [hs.mem_to_finset],
rw [finprod_mem_eq_prod _ hs, ← finset.prod_image hg],
refine finprod_mem_eq_prod_of_inter_mul_support_eq f _,
rw [finset.coe_image, hs.coe_to_finset, ← image_inter_mul_support_eq, inter_assoc,
inter_self] },
{ rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite],
rwa [image_inter_mul_support_eq, infinite_image_iff hg] }
end
/-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s`
provided that `g` is injective on `s`. -/
@[to_additive] lemma finprod_mem_image {β} {s : set β} {g : β → α} (hg : set.inj_on g s) :
∏ᶠ i ∈ (g '' s), f i = ∏ᶠ j ∈ s, f (g j) :=
finprod_mem_image' $ hg.mono $ inter_subset_left _ _
/-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i`
provided that `g` is injective on `mul_support (f ∘ g)`. -/
@[to_additive] lemma finprod_mem_range' {g : β → α} (hg : set.inj_on g (mul_support (f ∘ g))) :
∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) :=
begin
rw [← image_univ, finprod_mem_image', finprod_mem_univ],
rwa univ_inter
end
/-- The product of `f y` over `y ∈ set.range g` equals the product of `f (g i)` over all `i`
provided that `g` is injective. -/
@[to_additive] lemma finprod_mem_range {g : β → α} (hg : injective g) :
∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) :=
finprod_mem_range' (hg.inj_on _)
/-- The product of `f i` over `s : set α` is equal to the product of `g j` over `t : set β`
if there exists a function `e : α → β` such that `e` is bijective from `s` to `t` and for all
`x` in `s` we have `f x = g (e x)`.
See also `finset.prod_bij`. -/
@[to_additive] lemma finprod_mem_eq_of_bij_on {s : set α} {t : set β} {f : α → M} {g : β → M}
(e : α → β) (he₀ : set.bij_on e s t) (he₁ : ∀ x ∈ s, f x = g (e x)) :
∏ᶠ i ∈ s, f i = ∏ᶠ j ∈ t, g j :=
begin
rw [← set.bij_on.image_eq he₀, finprod_mem_image he₀.2.1],
exact finprod_mem_congr rfl he₁
end
/-- The product of `f i` is equal to the product of `g j` if there exists a bijective function
`e : α → β` such that for all `x` we have `f x = g (e x)`.
See `finprod_comp`, `fintype.prod_bijective` and `finset.prod_bij` -/
@[to_additive] lemma finprod_eq_of_bijective {f : α → M} {g : β → M}
(e : α → β) (he₀ : function.bijective e) (he₁ : ∀ x, f x = g (e x)) :
∏ᶠ i, f i = ∏ᶠ j, g j :=
begin
rw [← finprod_mem_univ f, ← finprod_mem_univ g],
exact finprod_mem_eq_of_bij_on _ (bijective_iff_bij_on_univ.mp he₀) (λ x _, he₁ x),
end
/-- Given a bijective function `e` the product of `g i` is equal to the product of `g (e i)`.
See also `finprod_eq_of_bijective`, `fintype.prod_bijective` and `finset.prod_bij` -/
@[to_additive] lemma finprod_comp {g : β → M} (e : α → β) (he₀ : function.bijective e) :
∏ᶠ i, g (e i) = ∏ᶠ j, g j := finprod_eq_of_bijective e he₀ (λ x, rfl)
@[to_additive] lemma finprod_set_coe_eq_finprod_mem (s : set α) : ∏ᶠ j : s, f j = ∏ᶠ i ∈ s, f i :=
begin
rw [← finprod_mem_range, subtype.range_coe],
exact subtype.coe_injective
end
@[to_additive] lemma finprod_subtype_eq_finprod_cond (p : α → Prop) :
∏ᶠ j : subtype p, f j = ∏ᶠ i (hi : p i), f i :=
finprod_set_coe_eq_finprod_mem {i | p i}
@[to_additive] lemma finprod_mem_inter_mul_diff' (t : set α) (h : (s ∩ mul_support f).finite) :
(∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i :=
begin
rw [← finprod_mem_union', inter_union_diff],
exacts [λ x hx, hx.2.2 hx.1.2, h.subset (λ x hx, ⟨hx.1.1, hx.2⟩),
h.subset (λ x hx, ⟨hx.1.1, hx.2⟩)],
end
@[to_additive] lemma finprod_mem_inter_mul_diff (t : set α) (h : s.finite) :
(∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i = ∏ᶠ i ∈ s, f i :=
finprod_mem_inter_mul_diff' _ $ h.inter_of_left _
/-- A more general version of `finprod_mem_mul_diff` that requires `t ∩ mul_support f` instead of
`t` to be finite. -/
@[to_additive] lemma finprod_mem_mul_diff' (hst : s ⊆ t) (ht : (t ∩ mul_support f).finite) :
(∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i :=
by rw [← finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst]
/-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i ∈ s`
times the product of `f i` over `t \ s` equals the product of `f i` over `i ∈ t`. -/
@[to_additive] lemma finprod_mem_mul_diff (hst : s ⊆ t) (ht : t.finite) :
(∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i = ∏ᶠ i ∈ t, f i :=
finprod_mem_mul_diff' hst (ht.inter_of_left _)
/-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type,
the product of `f a` over the union `⋃ i, t i` is equal to the product over all indexes `i`
of the products of `f a` over `a ∈ t i`. -/
@[to_additive] lemma finprod_mem_Union [fintype ι] {t : ι → set α}
(h : pairwise (disjoint on t)) (ht : ∀ i, (t i).finite) :
∏ᶠ a ∈ (⋃ i : ι, t i), f a = ∏ᶠ i, (∏ᶠ a ∈ t i, f a) :=
begin
lift t to ι → finset α using ht,
classical,
rw [← bUnion_univ, ← finset.coe_univ, ← finset.coe_bUnion,
finprod_mem_coe_finset, finset.prod_bUnion],
{ simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype] },
{ exact λ x _ y _ hxy, finset.disjoint_iff_disjoint_coe.2 (h x y hxy) }
end
/-- Given a family of sets `t : ι → set α`, a finite set `I` in the index type such that all
sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then
the product of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the product over `i ∈ I`
of the products of `f a` over `a ∈ t i`. -/
@[to_additive] lemma finprod_mem_bUnion {I : set ι} {t : ι → set α}
(h : I.pairwise_disjoint t) (hI : I.finite) (ht : ∀ i ∈ I, (t i).finite) :
∏ᶠ a ∈ ⋃ x ∈ I, t x, f a = ∏ᶠ i ∈ I, ∏ᶠ j ∈ t i, f j :=
begin
haveI := hI.fintype,
rw [bUnion_eq_Union, finprod_mem_Union, ← finprod_set_coe_eq_finprod_mem],
exacts [λ x y hxy, h x.2 y.2 (subtype.coe_injective.ne hxy), λ b, ht b b.2]
end
/-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a`
over `a ∈ ⋃₀ t` is the product over `s ∈ t` of the products of `f a` over `a ∈ s`. -/
@[to_additive] lemma finprod_mem_sUnion {t : set (set α)} (h : t.pairwise_disjoint id)
(ht₀ : t.finite) (ht₁ : ∀ x ∈ t, set.finite x) :
∏ᶠ a ∈ ⋃₀ t, f a = ∏ᶠ s ∈ t, ∏ᶠ a ∈ s, f a :=
by { rw set.sUnion_eq_bUnion, exact finprod_mem_bUnion h ht₀ ht₁ }
@[to_additive] lemma mul_finprod_cond_ne (a : α) (hf : finite (mul_support f)) :
f a * (∏ᶠ i ≠ a, f i) = ∏ᶠ i, f i :=
begin
classical,
rw [finprod_eq_prod _ hf],
have h : ∀ x : α, f x ≠ 1 → (x ≠ a ↔ x ∈ hf.to_finset \ {a}),
{ intros x hx,
rw [finset.mem_sdiff, finset.mem_singleton, finite.mem_to_finset, mem_mul_support],
exact ⟨λ h, and.intro hx h, λ h, h.2⟩,},
rw [finprod_cond_eq_prod_of_cond_iff f h, finset.sdiff_singleton_eq_erase],
by_cases ha : a ∈ mul_support f,
{ apply finset.mul_prod_erase _ _ ((finite.mem_to_finset _ ).mpr ha), },
{ rw [mem_mul_support, not_not] at ha,
rw [ha, one_mul],
apply finset.prod_erase _ ha, }
end
/-- If `s : set α` and `t : set β` are finite sets, then the product over `s` commutes
with the product over `t`. -/
@[to_additive] lemma finprod_mem_comm {s : set α} {t : set β}
(f : α → β → M) (hs : s.finite) (ht : t.finite) :
∏ᶠ i ∈ s, ∏ᶠ j ∈ t, f i j = ∏ᶠ j ∈ t, ∏ᶠ i ∈ s, f i j :=
begin
lift s to finset α using hs, lift t to finset β using ht,
simp only [finprod_mem_coe_finset],
exact finset.prod_comm
end
/-- To prove a property of a finite product, it suffices to prove that the property is
multiplicative and holds on multipliers. -/
@[to_additive] lemma finprod_mem_induction (p : M → Prop) (hp₀ : p 1)
(hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ x ∈ s, p $ f x) :
p (∏ᶠ i ∈ s, f i) :=
finprod_induction _ hp₀ hp₁ $ λ x, finprod_induction _ hp₀ hp₁ $ hp₂ x
lemma finprod_cond_nonneg {R : Type*} [ordered_comm_semiring R] {p : α → Prop} {f : α → R}
(hf : ∀ x, p x → 0 ≤ f x) :
0 ≤ ∏ᶠ x (h : p x), f x :=
finprod_nonneg $ λ x, finprod_nonneg $ hf x
@[to_additive]
lemma single_le_finprod {M : Type*} [ordered_comm_monoid M] (i : α) {f : α → M}
(hf : finite (mul_support f)) (h : ∀ j, 1 ≤ f j) :
f i ≤ ∏ᶠ j, f j :=
by classical;
calc f i ≤ ∏ j in insert i hf.to_finset, f j :
finset.single_le_prod' (λ j hj, h j) (finset.mem_insert_self _ _)
... = ∏ᶠ j, f j :
(finprod_eq_prod_of_mul_support_to_finset_subset _ hf (finset.subset_insert _ _)).symm
lemma finprod_eq_zero {M₀ : Type*} [comm_monoid_with_zero M₀] (f : α → M₀) (x : α)
(hx : f x = 0) (hf : finite (mul_support f)) :
∏ᶠ x, f x = 0 :=
begin
nontriviality,
rw [finprod_eq_prod f hf],
refine finset.prod_eq_zero (hf.mem_to_finset.2 _) hx,
simp [hx]
end
@[to_additive] lemma finprod_prod_comm (s : finset β) (f : α → β → M)
(h : ∀ b ∈ s, (mul_support (λ a, f a b)).finite) :
∏ᶠ a : α, ∏ b in s, f a b = ∏ b in s, ∏ᶠ a : α, f a b :=
begin
have hU : mul_support (λ a, ∏ b in s, f a b) ⊆
(s.finite_to_set.bUnion (λ b hb, h b (finset.mem_coe.1 hb))).to_finset,
{ rw finite.coe_to_finset,
intros x hx,
simp only [exists_prop, mem_Union, ne.def, mem_mul_support, finset.mem_coe],
contrapose! hx,
rw [mem_mul_support, not_not, finset.prod_congr rfl hx, finset.prod_const_one] },
rw [finprod_eq_prod_of_mul_support_subset _ hU, finset.prod_comm],
refine finset.prod_congr rfl (λ b hb, (finprod_eq_prod_of_mul_support_subset _ _).symm),
intros a ha,
simp only [finite.coe_to_finset, mem_Union],
exact ⟨b, hb, ha⟩
end
@[to_additive] lemma prod_finprod_comm (s : finset α) (f : α → β → M)
(h : ∀ a ∈ s, (mul_support (f a)).finite) :
∏ a in s, ∏ᶠ b : β, f a b = ∏ᶠ b : β, ∏ a in s, f a b :=
(finprod_prod_comm s (λ b a, f a b) h).symm
lemma mul_finsum {R : Type*} [semiring R] (f : α → R) (r : R)
(h : (function.support f).finite) :
r * ∑ᶠ a : α, f a = ∑ᶠ a : α, r * f a :=
(add_monoid_hom.mul_left r).map_finsum h
lemma finsum_mul {R : Type*} [semiring R] (f : α → R) (r : R)
(h : (function.support f).finite) :
(∑ᶠ a : α, f a) * r = ∑ᶠ a : α, f a * r :=
(add_monoid_hom.mul_right r).map_finsum h
@[to_additive] lemma finset.mul_support_of_fiberwise_prod_subset_image [decidable_eq β]
(s : finset α) (f : α → M) (g : α → β) :
mul_support (λ b, (s.filter (λ a, g a = b)).prod f) ⊆ s.image g :=
begin
simp only [finset.coe_image, set.mem_image, finset.mem_coe, function.support_subset_iff],
intros b h,
suffices : (s.filter (λ (a : α), g a = b)).nonempty,
{ simpa only [s.fiber_nonempty_iff_mem_image g b, finset.mem_image, exists_prop], },
exact finset.nonempty_of_prod_ne_one h,
end
/-- Note that `b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd` iff `(a, b) ∈ s` so we can
simplify the right hand side of this lemma. However the form stated here is more useful for
iterating this lemma, e.g., if we have `f : α × β × γ → M`. -/
@[to_additive] lemma finprod_mem_finset_product' [decidable_eq α] [decidable_eq β]
(s : finset (α × β)) (f : α × β → M) :
∏ᶠ ab (h : ab ∈ s), f ab =
∏ᶠ a b (h : b ∈ (s.filter (λ ab, prod.fst ab = a)).image prod.snd), f (a, b) :=
begin
have : ∀ a, ∏ (i : β) in (s.filter (λ ab, prod.fst ab = a)).image prod.snd, f (a, i) =
(finset.filter (λ ab, prod.fst ab = a) s).prod f,
{ refine (λ a, finset.prod_bij (λ b _, (a, b)) _ _ _ _); -- `finish` closes these goals
try { simp, done },
suffices : ∀ a' b, (a', b) ∈ s → a' = a → (a, b) ∈ s ∧ a' = a, by simpa,
rintros a' b hp rfl,
exact ⟨hp, rfl⟩ },
rw finprod_mem_finset_eq_prod,
simp_rw [finprod_mem_finset_eq_prod, this],
rw [finprod_eq_prod_of_mul_support_subset _
(s.mul_support_of_fiberwise_prod_subset_image f prod.fst),
← finset.prod_fiberwise_of_maps_to _ f], -- `finish` could close the goal here
simp only [finset.mem_image, prod.mk.eta],
exact λ x hx, ⟨x, hx, rfl⟩,
end
/-- See also `finprod_mem_finset_product'`. -/
@[to_additive] lemma finprod_mem_finset_product (s : finset (α × β)) (f : α × β → M) :
∏ᶠ ab (h : ab ∈ s), f ab = ∏ᶠ a b (h : (a, b) ∈ s), f (a, b) :=
by { classical, rw finprod_mem_finset_product', simp, }
@[to_additive] lemma finprod_mem_finset_product₃ {γ : Type*}
(s : finset (α × β × γ)) (f : α × β × γ → M) :
∏ᶠ abc (h : abc ∈ s), f abc = ∏ᶠ a b c (h : (a, b, c) ∈ s), f (a, b, c) :=
by { classical, rw finprod_mem_finset_product', simp_rw finprod_mem_finset_product', simp, }
@[to_additive] lemma finprod_curry (f : α × β → M) (hf : (mul_support f).finite) :
∏ᶠ ab, f ab = ∏ᶠ a b, f (a, b) :=
begin
have h₁ : ∀ a, ∏ᶠ (h : a ∈ hf.to_finset), f a = f a, { simp, },
have h₂ : ∏ᶠ a, f a = ∏ᶠ a (h : a ∈ hf.to_finset), f a, { simp, },
simp_rw [h₂, finprod_mem_finset_product, h₁],
end
@[to_additive] lemma finprod_curry₃ {γ : Type*} (f : α × β × γ → M) (h : (mul_support f).finite) :
∏ᶠ abc, f abc = ∏ᶠ a b c, f (a, b, c) :=
by { rw finprod_curry f h, congr, ext a, rw finprod_curry, simp [h], }
@[to_additive]
lemma finprod_dmem {s : set α} [decidable_pred (∈ s)] (f : (Π (a : α), a ∈ s → M)) :
∏ᶠ (a : α) (h : a ∈ s), f a h = ∏ᶠ (a : α) (h : a ∈ s), if h' : a ∈ s then f a h' else 1 :=
finprod_congr (λ a, finprod_congr (λ ha, (dif_pos ha).symm))
@[to_additive]
lemma finprod_emb_domain' {f : α → β} (hf : function.injective f)
[decidable_pred (∈ set.range f)] (g : α → M) :
∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a :=
begin
simp_rw [← finprod_eq_dif],
rw [finprod_dmem, finprod_mem_range hf, finprod_congr (λ a, _)],
rw [dif_pos (set.mem_range_self a), hf (classical.some_spec (set.mem_range_self a))]
end
@[to_additive]
lemma finprod_emb_domain (f : α ↪ β) [decidable_pred (∈ set.range f)] (g : α → M) :
∏ᶠ (b : β), (if h : b ∈ set.range f then g (classical.some h) else 1) = ∏ᶠ (a : α), g a :=
finprod_emb_domain' f.injective g
end type
|
7fbf931f1884424abe8a4be37b3ae58b5b4a8bd1
|
69d4931b605e11ca61881fc4f66db50a0a875e39
|
/src/topology/category/Top/basic.lean
|
61377c5d6be8f237587d04fd103f189587732e14
|
[
"Apache-2.0"
] |
permissive
|
abentkamp/mathlib
|
d9a75d291ec09f4637b0f30cc3880ffb07549ee5
|
5360e476391508e092b5a1e5210bd0ed22dc0755
|
refs/heads/master
| 1,682,382,954,948
| 1,622,106,077,000
| 1,622,106,077,000
| 149,285,665
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,102
|
lean
|
/-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Scott Morrison, Mario Carneiro
-/
import category_theory.concrete_category.unbundled_hom
import topology.continuous_function.basic
import topology.opens
/-!
# Category instance for topological spaces
We introduce the bundled category `Top` of topological spaces together with the functors `discrete`
and `trivial` from the category of types to `Top` which equip a type with the corresponding
discrete, resp. trivial, topology. For a proof that these functors are left, resp. right adjoint
to the forgetful functor, see `topology.category.Top.adjunctions`.
-/
open category_theory
open topological_space
universe u
/-- The category of topological spaces and continuous maps. -/
def Top : Type (u+1) := bundled topological_space
namespace Top
instance bundled_hom : bundled_hom @continuous_map :=
⟨@continuous_map.to_fun, @continuous_map.id, @continuous_map.comp, @continuous_map.coe_inj⟩
attribute [derive [has_coe_to_sort, large_category, concrete_category]] Top
instance topological_space_unbundled (x : Top) : topological_space x := x.str
@[simp] lemma id_app (X : Top.{u}) (x : X) :
(𝟙 X : X → X) x = x := rfl
@[simp] lemma comp_app {X Y Z : Top.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) :
(f ≫ g : X → Z) x = g (f x) := rfl
/-- Construct a bundled `Top` from the underlying type and the typeclass. -/
def of (X : Type u) [topological_space X] : Top := ⟨X⟩
instance (X : Top) : topological_space X := X.str
@[simp] lemma coe_of (X : Type u) [topological_space X] : (of X : Type u) = X := rfl
instance : inhabited Top := ⟨Top.of empty⟩
/-- The discrete topology on any type. -/
def discrete : Type u ⥤ Top.{u} :=
{ obj := λ X, ⟨X, ⊥⟩,
map := λ X Y f, { to_fun := f, continuous_to_fun := continuous_bot } }
/-- The trivial topology on any type. -/
def trivial : Type u ⥤ Top.{u} :=
{ obj := λ X, ⟨X, ⊤⟩,
map := λ X Y f, { to_fun := f, continuous_to_fun := continuous_top } }
end Top
|
027547b5a94b648d1e3cc27790f2b843af9fde21
|
75bd9c50a345718d735a7533c007cf45f9da9a83
|
/src/measure_theory/l1_space.lean
|
42294ebe32b9a5e5112b13273b660a6ca13aaa6b
|
[
"Apache-2.0"
] |
permissive
|
jtbarker/mathlib
|
a1a3b1ddc16179826260578410746756ef18032c
|
392d3e376b44265ef2dedbd92231d3177acc1fd0
|
refs/heads/master
| 1,671,246,411,096
| 1,600,801,712,000
| 1,600,801,712,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 36,794
|
lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import measure_theory.ae_eq_fun
/-!
# Integrable functions and `L¹` space
In the first part of this file, the predicate `integrable` is defined and basic properties of
integrable functions are proved.
In the second part, the space `L¹` of equivalence classes of integrable functions under the relation
of being almost everywhere equal is defined as a subspace of the space `L⁰`. See the file
`src/measure_theory/ae_eq_fun.lean` for information on `L⁰` space.
## Notation
* `α →₁ β` is the type of `L¹` space, where `α` is a `measure_space` and `β` is a `normed_group`
with a `second_countable_topology`. `f : α →ₘ β` is a "function" in `L¹`. In comments, `[f]` is
also used to denote an `L¹` function.
`₁` can be typed as `\1`.
## Main definitions
* Let `f : α → β` be a function, where `α` is a `measure_space` and `β` a `normed_group`.
Then `has_finite_integral f` means `(∫⁻ a, nnnorm (f a)) < ⊤`.
* If `β` is moreover a `measurable_space` then `f` is called `integrable` if
`f` is `measurable` and `has_finite_integral f` holds.
* The space `L¹` is defined as a subspace of `L⁰` :
An `ae_eq_fun` `[f] : α →ₘ β` is in the space `L¹` if `edist [f] 0 < ⊤`, which means
`(∫⁻ a, edist (f a) 0) < ⊤` if we expand the definition of `edist` in `L⁰`.
## Main statements
`L¹`, as a subspace, inherits most of the structures of `L⁰`.
## Implementation notes
Maybe `integrable f` should be mean `(∫⁻ a, edist (f a) 0) < ⊤`, so that `integrable` and
`ae_eq_fun.integrable` are more aligned. But in the end one can use the lemma
`lintegral_nnnorm_eq_lintegral_edist : (∫⁻ a, nnnorm (f a)) = (∫⁻ a, edist (f a) 0)` to switch the
two forms.
To prove something for an arbitrary integrable + measurable function, a useful theorem is
`integrable.induction` in the file `set_integral`.
## Tags
integrable, function space, l1
-/
noncomputable theory
open_locale classical topological_space big_operators
open set filter topological_space ennreal emetric measure_theory
variables {α β γ δ : Type*} [measurable_space α] {μ ν : measure α}
variables [normed_group β]
variables [normed_group γ]
namespace measure_theory
/-! ### Some results about the Lebesgue integral involving a normed group -/
lemma lintegral_nnnorm_eq_lintegral_edist (f : α → β) :
∫⁻ a, nnnorm (f a) ∂μ = ∫⁻ a, edist (f a) 0 ∂μ :=
by simp only [edist_eq_coe_nnnorm]
lemma lintegral_norm_eq_lintegral_edist (f : α → β) :
∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ = ∫⁻ a, edist (f a) 0 ∂μ :=
by simp only [of_real_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm]
lemma lintegral_edist_triangle [second_countable_topology β] [measurable_space β]
[opens_measurable_space β] {f g h : α → β}
(hf : measurable f) (hg : measurable g) (hh : measurable h) :
∫⁻ a, edist (f a) (g a) ∂μ ≤ ∫⁻ a, edist (f a) (h a) ∂μ + ∫⁻ a, edist (g a) (h a) ∂μ :=
begin
rw ← lintegral_add (hf.edist hh) (hg.edist hh),
refine lintegral_mono (λ a, _),
apply edist_triangle_right
end
lemma lintegral_nnnorm_zero : ∫⁻ a : α, nnnorm (0 : β) ∂μ = 0 := by simp
lemma lintegral_nnnorm_add [measurable_space β] [opens_measurable_space β]
[measurable_space γ] [opens_measurable_space γ]
{f : α → β} {g : α → γ} (hf : measurable f) (hg : measurable g) :
∫⁻ a, nnnorm (f a) + nnnorm (g a) ∂μ = ∫⁻ a, nnnorm (f a) ∂μ + ∫⁻ a, nnnorm (g a) ∂μ :=
lintegral_add hf.ennnorm hg.ennnorm
lemma lintegral_nnnorm_neg {f : α → β} :
∫⁻ a, nnnorm ((-f) a) ∂μ = ∫⁻ a, nnnorm (f a) ∂μ :=
by simp only [pi.neg_apply, nnnorm_neg]
/-! ### The predicate `has_finite_integral` -/
/-- `has_finite_integral f μ` means that the integral `∫⁻ a, ∥f a∥ ∂μ` is finite.
`has_finite_integral f` means `has_finite_integral f volume`. -/
def has_finite_integral (f : α → β) (μ : measure α . volume_tac) : Prop :=
∫⁻ a, nnnorm (f a) ∂μ < ⊤
lemma has_finite_integral_iff_norm (f : α → β) :
has_finite_integral f μ ↔ ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ < ⊤ :=
by simp only [has_finite_integral, of_real_norm_eq_coe_nnnorm]
lemma has_finite_integral_iff_edist (f : α → β) :
has_finite_integral f μ ↔ ∫⁻ a, edist (f a) 0 ∂μ < ⊤ :=
by simp only [has_finite_integral_iff_norm, edist_dist, dist_zero_right]
lemma has_finite_integral_iff_of_real {f : α → ℝ} (h : 0 ≤ᵐ[μ] f) :
has_finite_integral f μ ↔ ∫⁻ a, ennreal.of_real (f a) ∂μ < ⊤ :=
have lintegral_eq : ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ = ∫⁻ a, ennreal.of_real (f a) ∂μ :=
begin
refine lintegral_congr_ae (h.mono $ λ a h, _),
rwa [real.norm_eq_abs, abs_of_nonneg]
end,
by rw [has_finite_integral_iff_norm, lintegral_eq]
lemma has_finite_integral.mono {f : α → β} {g : α → γ} (hg : has_finite_integral g μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ ∥g a∥) : has_finite_integral f μ :=
begin
simp only [has_finite_integral_iff_norm] at *,
calc ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ ≤ ∫⁻ (a : α), (ennreal.of_real ∥g a∥) ∂μ :
lintegral_mono_ae (h.mono $ assume a h, of_real_le_of_real h)
... < ⊤ : hg
end
lemma has_finite_integral.mono' {f : α → β} {g : α → ℝ} (hg : has_finite_integral g μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ g a) : has_finite_integral f μ :=
hg.mono $ h.mono $ λ x hx, le_trans hx (le_abs_self _)
lemma has_finite_integral.congr' {f : α → β} {g : α → γ} (hf : has_finite_integral f μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
has_finite_integral g μ :=
hf.mono $ eventually_eq.le $ eventually_eq.symm h
lemma has_finite_integral_congr' {f : α → β} {g : α → γ} (h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
has_finite_integral f μ ↔ has_finite_integral g μ :=
⟨λ hf, hf.congr' h, λ hg, hg.congr' $ eventually_eq.symm h⟩
lemma has_finite_integral.congr {f g : α → β} (hf : has_finite_integral f μ) (h : f =ᵐ[μ] g) :
has_finite_integral g μ :=
hf.congr' $ h.fun_comp norm
lemma has_finite_integral_congr {f g : α → β} (h : f =ᵐ[μ] g) :
has_finite_integral f μ ↔ has_finite_integral g μ :=
has_finite_integral_congr' $ h.fun_comp norm
lemma has_finite_integral_const_iff {c : β} :
has_finite_integral (λ x : α, c) μ ↔ c = 0 ∨ μ univ < ⊤ :=
begin
simp only [has_finite_integral, lintegral_const],
by_cases hc : c = 0,
{ simp [hc] },
{ simp only [hc, false_or],
refine ⟨λ h, _, λ h, mul_lt_top coe_lt_top h⟩,
replace h := mul_lt_top (@coe_lt_top $ (nnnorm c)⁻¹) h,
rwa [← mul_assoc, ← coe_mul, _root_.inv_mul_cancel, coe_one, one_mul] at h,
rwa [ne.def, nnnorm_eq_zero] }
end
lemma has_finite_integral_const [finite_measure μ] (c : β) : has_finite_integral (λ x : α, c) μ :=
has_finite_integral_const_iff.2 (or.inr $ measure_lt_top _ _)
lemma has_finite_integral_of_bounded [finite_measure μ] {f : α → β} {C : ℝ}
(hC : ∀ᵐ a ∂μ, ∥f a∥ ≤ C) : has_finite_integral f μ :=
(has_finite_integral_const C).mono' hC
lemma has_finite_integral.mono_measure {f : α → β} (h : has_finite_integral f ν) (hμ : μ ≤ ν) :
has_finite_integral f μ :=
lt_of_le_of_lt (lintegral_mono' hμ (le_refl _)) h
lemma has_finite_integral.add_measure {f : α → β} (hμ : has_finite_integral f μ)
(hν : has_finite_integral f ν) : has_finite_integral f (μ + ν) :=
begin
simp only [has_finite_integral, lintegral_add_measure] at *,
exact add_lt_top.2 ⟨hμ, hν⟩
end
lemma has_finite_integral.left_of_add_measure {f : α → β} (h : has_finite_integral f (μ + ν)) :
has_finite_integral f μ :=
h.mono_measure $ measure.le_add_right $ le_refl _
lemma has_finite_integral.right_of_add_measure {f : α → β} (h : has_finite_integral f (μ + ν)) :
has_finite_integral f ν :=
h.mono_measure $ measure.le_add_left $ le_refl _
@[simp] lemma has_finite_integral_add_measure {f : α → β} :
has_finite_integral f (μ + ν) ↔ has_finite_integral f μ ∧ has_finite_integral f ν :=
⟨λ h, ⟨h.left_of_add_measure, h.right_of_add_measure⟩, λ h, h.1.add_measure h.2⟩
lemma has_finite_integral.smul_measure {f : α → β} (h : has_finite_integral f μ) {c : ennreal}
(hc : c < ⊤) : has_finite_integral f (c • μ) :=
begin
simp only [has_finite_integral, lintegral_smul_measure] at *,
exact mul_lt_top hc h
end
@[simp] lemma has_finite_integral_zero_measure (f : α → β) : has_finite_integral f 0 :=
by simp only [has_finite_integral, lintegral_zero_measure, with_top.zero_lt_top]
variables (α β μ)
@[simp] lemma has_finite_integral_zero : has_finite_integral (λa:α, (0:β)) μ :=
by simp [has_finite_integral]
variables {α β μ}
lemma has_finite_integral.neg {f : α → β} (hfi : has_finite_integral f μ) :
has_finite_integral (-f) μ :=
by simpa [has_finite_integral] using hfi
@[simp] lemma has_finite_integral_neg_iff {f : α → β} :
has_finite_integral (-f) μ ↔ has_finite_integral f μ :=
⟨λ h, neg_neg f ▸ h.neg, has_finite_integral.neg⟩
lemma has_finite_integral.norm {f : α → β} (hfi : has_finite_integral f μ) :
has_finite_integral (λa, ∥f a∥) μ :=
have eq : (λa, (nnnorm ∥f a∥ : ennreal)) = λa, (nnnorm (f a) : ennreal),
by { funext, rw nnnorm_norm },
by { rwa [has_finite_integral, eq] }
lemma has_finite_integral_norm_iff (f : α → β) :
has_finite_integral (λa, ∥f a∥) μ ↔ has_finite_integral f μ :=
has_finite_integral_congr' $ eventually_of_forall $ λ x, norm_norm (f x)
section dominated_convergence
variables {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
lemma all_ae_of_real_F_le_bound (h : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a) :
∀ n, ∀ᵐ a ∂μ, ennreal.of_real ∥F n a∥ ≤ ennreal.of_real (bound a) :=
λn, (h n).mono $ λ a h, ennreal.of_real_le_of_real h
lemma all_ae_tendsto_of_real_norm (h : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top $ 𝓝 $ f a) :
∀ᵐ a ∂μ, tendsto (λn, ennreal.of_real ∥F n a∥) at_top $ 𝓝 $ ennreal.of_real ∥f a∥ :=
h.mono $
λ a h, tendsto_of_real $ tendsto.comp (continuous.tendsto continuous_norm _) h
lemma all_ae_of_real_f_le_bound (h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
∀ᵐ a ∂μ, ennreal.of_real ∥f a∥ ≤ ennreal.of_real (bound a) :=
begin
have F_le_bound := all_ae_of_real_F_le_bound h_bound,
rw ← ae_all_iff at F_le_bound,
apply F_le_bound.mp ((all_ae_tendsto_of_real_norm h_lim).mono _),
assume a tendsto_norm F_le_bound,
exact le_of_tendsto' tendsto_norm (F_le_bound)
end
lemma has_finite_integral_of_dominated_convergence {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(bound_has_finite_integral : has_finite_integral bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
has_finite_integral f μ :=
/- `∥F n a∥ ≤ bound a` and `∥F n a∥ --> ∥f a∥` implies `∥f a∥ ≤ bound a`,
and so `∫ ∥f∥ ≤ ∫ bound < ⊤` since `bound` is has_finite_integral -/
begin
rw has_finite_integral_iff_norm,
calc ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ ≤ ∫⁻ a, ennreal.of_real (bound a) ∂μ :
lintegral_mono_ae $ all_ae_of_real_f_le_bound h_bound h_lim
... < ⊤ :
begin
rw ← has_finite_integral_iff_of_real,
{ exact bound_has_finite_integral },
exact (h_bound 0).mono (λ a h, le_trans (norm_nonneg _) h)
end
end
lemma tendsto_lintegral_norm_of_dominated_convergence [measurable_space β]
[borel_space β] [second_countable_topology β]
{F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(F_measurable : ∀ n, measurable (F n))
(f_measurable : measurable f)
(bound_has_finite_integral : has_finite_integral bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
tendsto (λn, ∫⁻ a, (ennreal.of_real ∥F n a - f a∥) ∂μ) at_top (𝓝 0) :=
let b := λa, 2 * ennreal.of_real (bound a) in
/- `∥F n a∥ ≤ bound a` and `F n a --> f a` implies `∥f a∥ ≤ bound a`, and thus by the
triangle inequality, have `∥F n a - f a∥ ≤ 2 * (bound a). -/
have hb : ∀ n, ∀ᵐ a ∂μ, ennreal.of_real ∥F n a - f a∥ ≤ b a,
begin
assume n,
filter_upwards [all_ae_of_real_F_le_bound h_bound n, all_ae_of_real_f_le_bound h_bound h_lim],
assume a h₁ h₂,
calc ennreal.of_real ∥F n a - f a∥ ≤ (ennreal.of_real ∥F n a∥) + (ennreal.of_real ∥f a∥) :
begin
rw [← ennreal.of_real_add],
apply of_real_le_of_real,
{ apply norm_sub_le }, { exact norm_nonneg _ }, { exact norm_nonneg _ }
end
... ≤ (ennreal.of_real (bound a)) + (ennreal.of_real (bound a)) : add_le_add h₁ h₂
... = b a : by rw ← two_mul
end,
/- On the other hand, `F n a --> f a` implies that `∥F n a - f a∥ --> 0` -/
have h : ∀ᵐ a ∂μ, tendsto (λ n, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 0),
begin
rw ← ennreal.of_real_zero,
refine h_lim.mono (λ a h, (continuous_of_real.tendsto _).comp _),
rwa ← tendsto_iff_norm_tendsto_zero
end,
/- Therefore, by the dominated convergence theorem for nonnegative integration, have
` ∫ ∥f a - F n a∥ --> 0 ` -/
begin
suffices h : tendsto (λn, ∫⁻ a, (ennreal.of_real ∥F n a - f a∥) ∂μ) at_top (𝓝 (∫⁻ (a:α), 0 ∂μ)),
{ rwa lintegral_zero at h },
-- Using the dominated convergence theorem.
refine tendsto_lintegral_of_dominated_convergence _ _ hb _ _,
-- Show `λa, ∥f a - F n a∥` is measurable for all `n`
{ exact λn, measurable_of_real.comp ((F_measurable n).sub f_measurable).norm },
-- Show `2 * bound` is has_finite_integral
{ rw has_finite_integral_iff_of_real at bound_has_finite_integral,
{ calc ∫⁻ a, b a ∂μ = 2 * ∫⁻ a, ennreal.of_real (bound a) ∂μ :
by { rw lintegral_const_mul', exact coe_ne_top }
... < ⊤ : mul_lt_top (coe_lt_top) bound_has_finite_integral },
filter_upwards [h_bound 0] λ a h, le_trans (norm_nonneg _) h },
-- Show `∥f a - F n a∥ --> 0`
{ exact h }
end
end dominated_convergence
section pos_part
/-! Lemmas used for defining the positive part of a `L¹` function -/
lemma has_finite_integral.max_zero {f : α → ℝ} (hf : has_finite_integral f μ) :
has_finite_integral (λa, max (f a) 0) μ :=
hf.mono $ eventually_of_forall $ λ x, by simp [real.norm_eq_abs, abs_le, abs_nonneg, le_abs_self]
lemma has_finite_integral.min_zero {f : α → ℝ} (hf : has_finite_integral f μ) :
has_finite_integral (λa, min (f a) 0) μ :=
hf.mono $ eventually_of_forall $ λ x,
by simp [real.norm_eq_abs, abs_le, abs_nonneg, neg_le, neg_le_abs_self]
end pos_part
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma has_finite_integral.smul (c : 𝕜) {f : α → β} : has_finite_integral f μ →
has_finite_integral (c • f) μ :=
begin
simp only [has_finite_integral], assume hfi,
calc
∫⁻ (a : α), nnnorm (c • f a) ∂μ = ∫⁻ (a : α), (nnnorm c) * nnnorm (f a) ∂μ :
by simp only [nnnorm_smul, ennreal.coe_mul]
... < ⊤ :
begin
rw lintegral_const_mul',
exacts [mul_lt_top coe_lt_top hfi, coe_ne_top]
end
end
lemma has_finite_integral_smul_iff {c : 𝕜} (hc : c ≠ 0) (f : α → β) :
has_finite_integral (c • f) μ ↔ has_finite_integral f μ :=
begin
split,
{ assume h,
simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.smul c⁻¹ },
exact has_finite_integral.smul _
end
lemma has_finite_integral.const_mul {f : α → ℝ} (h : has_finite_integral f μ) (c : ℝ) :
has_finite_integral (λ x, c * f x) μ :=
(has_finite_integral.smul c h : _)
lemma has_finite_integral.mul_const {f : α → ℝ} (h : has_finite_integral f μ) (c : ℝ) :
has_finite_integral (λ x, f x * c) μ :=
by simp_rw [mul_comm, h.const_mul _]
end normed_space
/-! ### The predicate `integrable` -/
variables [measurable_space β] [measurable_space γ] [measurable_space δ]
/-- `integrable f μ` means that `f` is measurable and that the integral `∫⁻ a, ∥f a∥ ∂μ` is finite.
`integrable f` means `integrable f volume`. -/
def integrable (f : α → β) (μ : measure α . volume_tac) : Prop :=
measurable f ∧ has_finite_integral f μ
lemma integrable.measurable {f : α → β} (hf : integrable f μ) : measurable f := hf.1
lemma integrable.has_finite_integral {f : α → β} (hf : integrable f μ) : has_finite_integral f μ :=
hf.2
lemma integrable.mono {f : α → β} {g : α → γ} (hg : integrable g μ) (hf : measurable f)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ ∥g a∥) : integrable f μ :=
⟨hf, hg.has_finite_integral.mono h⟩
lemma integrable.mono' {f : α → β} {g : α → ℝ} (hg : integrable g μ) (hf : measurable f)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ g a) : integrable f μ :=
⟨hf, hg.has_finite_integral.mono' h⟩
lemma integrable.congr' {f : α → β} {g : α → γ} (hf : integrable f μ) (hg : measurable g)
(h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) : integrable g μ :=
⟨hg, hf.has_finite_integral.congr' h⟩
lemma integrable_congr' {f : α → β} {g : α → γ} (hf : measurable f) (hg : measurable g)
(h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) : integrable f μ ↔ integrable g μ :=
⟨λ h2f, h2f.congr' hg h, λ h2g, h2g.congr' hf $ eventually_eq.symm h⟩
lemma integrable.congr {f g : α → β} (hf : integrable f μ) (hg : measurable g) (h : f =ᵐ[μ] g) :
integrable g μ :=
hf.congr' hg $ h.fun_comp norm
lemma integrable_congr {f g : α → β} (hf : measurable f) (hg : measurable g) (h : f =ᵐ[μ] g) :
integrable f μ ↔ integrable g μ :=
integrable_congr' hf hg $ h.fun_comp norm
lemma integrable_const_iff {c : β} : integrable (λ x : α, c) μ ↔ c = 0 ∨ μ univ < ⊤ :=
by rw [integrable, and_iff_right measurable_const, has_finite_integral_const_iff]
lemma integrable_const [finite_measure μ] (c : β) : integrable (λ x : α, c) μ :=
integrable_const_iff.2 $ or.inr $ measure_lt_top _ _
lemma integrable.mono_measure {f : α → β} (h : integrable f ν) (hμ : μ ≤ ν) : integrable f μ :=
⟨h.measurable, h.has_finite_integral.mono_measure hμ⟩
lemma integrable.add_measure {f : α → β} (hμ : integrable f μ) (hν : integrable f ν) :
integrable f (μ + ν) :=
⟨hμ.measurable, hμ.has_finite_integral.add_measure hν.has_finite_integral⟩
lemma integrable.left_of_add_measure {f : α → β} (h : integrable f (μ + ν)) : integrable f μ :=
h.mono_measure $ measure.le_add_right $ le_refl _
lemma integrable.right_of_add_measure {f : α → β} (h : integrable f (μ + ν)) : integrable f ν :=
h.mono_measure $ measure.le_add_left $ le_refl _
@[simp] lemma integrable_add_measure {f : α → β} :
integrable f (μ + ν) ↔ integrable f μ ∧ integrable f ν :=
⟨λ h, ⟨h.left_of_add_measure, h.right_of_add_measure⟩, λ h, h.1.add_measure h.2⟩
lemma integrable.smul_measure {f : α → β} (h : integrable f μ) {c : ennreal} (hc : c < ⊤) :
integrable f (c • μ) :=
⟨h.measurable, h.has_finite_integral.smul_measure hc⟩
lemma integrable_map_measure [opens_measurable_space β] {f : α → δ} {g : δ → β}
(hf : measurable f) (hg : measurable g) :
integrable g (measure.map f μ) ↔ integrable (g ∘ f) μ :=
by { simp only [integrable, has_finite_integral, lintegral_map hg.ennnorm hf, hf, hg, hg.comp hf] }
lemma lintegral_edist_lt_top [second_countable_topology β] [opens_measurable_space β] {f g : α → β}
(hf : integrable f μ) (hg : integrable g μ) :
∫⁻ a, edist (f a) (g a) ∂μ < ⊤ :=
lt_of_le_of_lt
(lintegral_edist_triangle hf.measurable hg.measurable
(measurable_const : measurable (λa, (0 : β))))
(ennreal.add_lt_top.2 $ by { simp_rw ← has_finite_integral_iff_edist,
exact ⟨hf.has_finite_integral, hg.has_finite_integral⟩ })
variables (α β μ)
@[simp] lemma integrable_zero : integrable (λ _, (0 : β)) μ :=
by simp [integrable, measurable_const]
variables {α β μ}
lemma integrable.add [borel_space β] [second_countable_topology β]
{f g : α → β} (hf : integrable f μ) (hg : integrable g μ) : integrable (f + g) μ :=
⟨hf.measurable.add hg.measurable, calc
∫⁻ a, nnnorm (f a + g a) ∂μ ≤ ∫⁻ a, nnnorm (f a) + nnnorm (g a) ∂μ :
lintegral_mono
(assume a, by { simp only [← coe_add, coe_le_coe], exact nnnorm_add_le _ _ })
... = _ :
lintegral_nnnorm_add hf.measurable hg.measurable
... < ⊤ : add_lt_top.2 ⟨hf.has_finite_integral, hg.has_finite_integral⟩⟩
lemma integrable_finset_sum {ι} [borel_space β] [second_countable_topology β] (s : finset ι)
{f : ι → α → β} (hf : ∀ i, integrable (f i) μ) : integrable (λ a, ∑ i in s, f i a) μ :=
begin
refine finset.induction_on s _ _,
{ simp only [finset.sum_empty, integrable_zero] },
{ assume i s his ih, simp only [his, finset.sum_insert, not_false_iff],
exact (hf _).add ih }
end
lemma integrable.neg [borel_space β] {f : α → β} (hf : integrable f μ) : integrable (-f) μ :=
⟨hf.measurable.neg, hf.has_finite_integral.neg⟩
@[simp] lemma integrable_neg_iff [borel_space β] {f : α → β} : integrable (-f) μ ↔ integrable f μ :=
⟨λ h, neg_neg f ▸ h.neg, integrable.neg⟩
lemma integrable.sub [borel_space β] [second_countable_topology β] {f g : α → β}
(hf : integrable f μ) (hg : integrable g μ) : integrable (f - g) μ :=
⟨hf.measurable.sub hg.measurable,
calc
∫⁻ a, nnnorm (f a - g a) ∂μ ≤ ∫⁻ a, nnnorm (f a) + nnnorm (-g a) ∂μ :
lintegral_mono (assume a, by exact_mod_cast nnnorm_add_le _ _ )
... = _ :
by { simp only [nnnorm_neg], exact lintegral_nnnorm_add hf.measurable hg.measurable }
... < ⊤ : add_lt_top.2 ⟨hf.has_finite_integral, hg.has_finite_integral⟩⟩
lemma integrable.norm [opens_measurable_space β] {f : α → β} (hf : integrable f μ) :
integrable (λa, ∥f a∥) μ :=
⟨hf.measurable.norm, hf.has_finite_integral.norm⟩
lemma integrable_norm_iff [opens_measurable_space β] {f : α → β} (hf : measurable f) :
integrable (λa, ∥f a∥) μ ↔ integrable f μ :=
by simp_rw [integrable, and_iff_right hf, and_iff_right hf.norm, has_finite_integral_norm_iff]
section pos_part
/-! Lemmas used for defining the positive part of a `L¹` function -/
lemma integrable.max_zero {f : α → ℝ} (hf : integrable f μ) : integrable (λa, max (f a) 0) μ :=
⟨hf.measurable.max measurable_const, hf.has_finite_integral.max_zero⟩
lemma integrable.min_zero {f : α → ℝ} (hf : integrable f μ) : integrable (λa, min (f a) 0) μ :=
⟨hf.measurable.min measurable_const, hf.has_finite_integral.min_zero⟩
end pos_part
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul [borel_space β] (c : 𝕜) {f : α → β}
(hf : integrable f μ) : integrable (c • f) μ :=
⟨hf.measurable.const_smul c, hf.has_finite_integral.smul c⟩
lemma integrable_smul_iff [borel_space β] {c : 𝕜} (hc : c ≠ 0) (f : α → β) :
integrable (c • f) μ ↔ integrable f μ :=
and_congr (measurable_const_smul_iff hc) (has_finite_integral_smul_iff hc f)
lemma integrable.const_mul {f : α → ℝ} (h : integrable f μ) (c : ℝ) : integrable (λ x, c * f x) μ :=
integrable.smul c h
lemma integrable.mul_const {f : α → ℝ} (h : integrable f μ) (c : ℝ) : integrable (λ x, f x * c) μ :=
by simp_rw [mul_comm, h.const_mul _]
end normed_space
variables [second_countable_topology β]
/-! ### The predicate `integrable` on measurable functions modulo a.e.-equality -/
namespace ae_eq_fun
section
variable [opens_measurable_space β]
/-- A class of almost everywhere equal functions is `integrable` if it has a finite distance to
the origin. It means the same thing as the predicate `integrable` over functions. -/
def integrable (f : α →ₘ[μ] β) : Prop := f ∈ ball (0 : α →ₘ[μ] β) ⊤
lemma integrable_mk {f : α → β} (hf : measurable f) :
(integrable (mk f hf : α →ₘ[μ] β)) ↔ measure_theory.integrable f μ :=
by simp [integrable, zero_def, edist_mk_mk', measure_theory.integrable, nndist_eq_nnnorm,
has_finite_integral, hf]
lemma integrable_coe_fn {f : α →ₘ[μ] β} : (measure_theory.integrable f μ) ↔ integrable f :=
by rw [← integrable_mk, mk_coe_fn]
lemma integrable_zero : integrable (0 : α →ₘ[μ] β) := mem_ball_self coe_lt_top
end
section
variable [borel_space β]
lemma integrable.add {f g : α →ₘ[μ] β} : integrable f → integrable g → integrable (f + g) :=
begin
refine induction_on₂ f g (λ f hf g hg hfi hgi, _),
simp only [integrable_mk, mk_add_mk] at hfi hgi ⊢,
exact hfi.add hgi
end
lemma integrable.neg {f : α →ₘ[μ] β} : integrable f → integrable (-f) :=
induction_on f $ λ f hfm hfi, (integrable_mk _).2 ((integrable_mk hfm).1 hfi).neg
lemma integrable.sub {f g : α →ₘ[μ] β} (hf : integrable f) (hg : integrable g) :
integrable (f - g) :=
hf.add hg.neg
protected lemma is_add_subgroup : is_add_subgroup (ball (0 : α →ₘ[μ] β) ⊤) :=
{ zero_mem := integrable_zero,
add_mem := λ _ _, integrable.add,
neg_mem := λ _, integrable.neg }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul {c : 𝕜} {f : α →ₘ[μ] β} : integrable f → integrable (c • f) :=
induction_on f $ λ f hfm hfi, (integrable_mk _).2 $ ((integrable_mk hfm).1 hfi).smul _
end normed_space
end
end ae_eq_fun
/-! ### The `L¹` space of functions -/
variables (α β)
/-- The space of equivalence classes of integrable (and measurable) functions, where two integrable
functions are equivalent if they agree almost everywhere, i.e., they differ on a set of measure
`0`. -/
def l1 [opens_measurable_space β] (μ : measure α) : Type* :=
{f : α →ₘ[μ] β // f.integrable}
notation α ` →₁[`:25 μ `] ` β := l1 α β μ
variables {α β}
namespace l1
open ae_eq_fun
local attribute [instance] ae_eq_fun.is_add_subgroup
section
variable [opens_measurable_space β]
instance : has_coe (α →₁[μ] β) (α →ₘ[μ] β) := coe_subtype
instance : has_coe_to_fun (α →₁[μ] β) := ⟨λ f, α → β, λ f, ⇑(f : α →ₘ[μ] β)⟩
@[simp, norm_cast] lemma coe_coe (f : α →₁[μ] β) : ⇑(f : α →ₘ[μ] β) = f := rfl
protected lemma eq {f g : α →₁[μ] β} : (f : α →ₘ[μ] β) = (g : α →ₘ[μ] β) → f = g := subtype.eq
@[norm_cast] protected lemma eq_iff {f g : α →₁[μ] β} : (f : α →ₘ[μ] β) = (g : α →ₘ[μ] β) ↔ f = g :=
iff.intro (l1.eq) (congr_arg coe)
/- TODO : order structure of l1-/
/-- `L¹` space forms a `emetric_space`, with the emetric being inherited from almost everywhere
functions, i.e., `edist f g = ∫⁻ a, edist (f a) (g a)`. -/
instance : emetric_space (α →₁[μ] β) := subtype.emetric_space
/-- `L¹` space forms a `metric_space`, with the metric being inherited from almost everywhere
functions, i.e., `edist f g = ennreal.to_real (∫⁻ a, edist (f a) (g a))`. -/
instance : metric_space (α →₁[μ] β) := metric_space_emetric_ball 0 ⊤
end
variable [borel_space β]
instance : add_comm_group (α →₁[μ] β) := subtype.add_comm_group
instance : inhabited (α →₁[μ] β) := ⟨0⟩
@[simp, norm_cast] lemma coe_zero : ((0 : α →₁[μ] β) : α →ₘ[μ] β) = 0 := rfl
@[simp, norm_cast]
lemma coe_add (f g : α →₁[μ] β) : ((f + g : α →₁[μ] β) : α →ₘ[μ] β) = f + g := rfl
@[simp, norm_cast] lemma coe_neg (f : α →₁[μ] β) : ((-f : α →₁[μ] β) : α →ₘ[μ] β) = -f := rfl
@[simp, norm_cast]
lemma coe_sub (f g : α →₁[μ] β) : ((f - g : α →₁[μ] β) : α →ₘ[μ] β) = f - g := rfl
@[simp] lemma edist_eq (f g : α →₁[μ] β) : edist f g = edist (f : α →ₘ[μ] β) (g : α →ₘ[μ] β) := rfl
lemma dist_eq (f g : α →₁[μ] β) :
dist f g = ennreal.to_real (edist (f : α →ₘ[μ] β) (g : α →ₘ[μ] β)) :=
rfl
/-- The norm on `L¹` space is defined to be `∥f∥ = ∫⁻ a, edist (f a) 0`. -/
instance : has_norm (α →₁[μ] β) := ⟨λ f, dist f 0⟩
lemma norm_eq (f : α →₁[μ] β) : ∥f∥ = ennreal.to_real (edist (f : α →ₘ[μ] β) 0) := rfl
instance : normed_group (α →₁[μ] β) := normed_group.of_add_dist (λ x, rfl) $ by
{ intros, simp only [dist_eq, coe_add], rw edist_add_right }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
instance : has_scalar 𝕜 (α →₁[μ] β) := ⟨λ x f, ⟨x • (f : α →ₘ[μ] β), ae_eq_fun.integrable.smul f.2⟩⟩
@[simp, norm_cast] lemma coe_smul (c : 𝕜) (f : α →₁[μ] β) :
((c • f : α →₁[μ] β) : α →ₘ[μ] β) = c • (f : α →ₘ[μ] β) := rfl
instance : semimodule 𝕜 (α →₁[μ] β) :=
{ one_smul := λf, l1.eq (by { simp only [coe_smul], exact one_smul _ _ }),
mul_smul := λx y f, l1.eq (by { simp only [coe_smul], exact mul_smul _ _ _ }),
smul_add := λx f g, l1.eq (by { simp only [coe_smul, coe_add], exact smul_add _ _ _ }),
smul_zero := λx, l1.eq (by { simp only [coe_zero, coe_smul], exact smul_zero _ }),
add_smul := λx y f, l1.eq (by { simp only [coe_smul], exact add_smul _ _ _ }),
zero_smul := λf, l1.eq (by { simp only [coe_smul], exact zero_smul _ _ }) }
instance : normed_space 𝕜 (α →₁[μ] β) :=
⟨ begin
rintros x ⟨f, hf⟩,
show ennreal.to_real (edist (x • f) 0) ≤ ∥x∥ * ennreal.to_real (edist f 0),
rw [edist_smul, to_real_of_real_mul],
exact norm_nonneg _
end ⟩
end normed_space
section of_fun
/-- Construct the equivalence class `[f]` of a measurable and integrable function `f`. -/
def of_fun (f : α → β) (hf : integrable f μ) : (α →₁[μ] β) :=
⟨mk f hf.measurable, by { rw integrable_mk, exact hf }⟩
@[simp] lemma of_fun_eq_mk (f : α → β) (hf : integrable f μ) :
(of_fun f hf : α →ₘ[μ] β) = mk f hf.measurable :=
rfl
lemma of_fun_eq_of_fun (f g : α → β) (hf : integrable f μ) (hg : integrable g μ) :
of_fun f hf = of_fun g hg ↔ f =ᵐ[μ] g :=
by { rw ← l1.eq_iff, simp only [of_fun_eq_mk, mk_eq_mk] }
lemma of_fun_zero : of_fun (λ _, (0 : β)) (integrable_zero α β μ) = 0 := rfl
lemma of_fun_add (f g : α → β) (hf : integrable f μ) (hg : integrable g μ) :
of_fun (f + g) (hf.add hg) = of_fun f hf + of_fun g hg :=
rfl
lemma of_fun_neg (f : α → β) (hf : integrable f μ) :
of_fun (- f) (integrable.neg hf) = - of_fun f hf := rfl
lemma of_fun_sub (f g : α → β) (hf : integrable f μ) (hg : integrable g μ) :
of_fun (f - g) (hf.sub hg) = of_fun f hf - of_fun g hg :=
rfl
lemma norm_of_fun (f : α → β) (hf : integrable f μ) :
∥ of_fun f hf ∥ = ennreal.to_real (∫⁻ a, edist (f a) 0 ∂μ) :=
rfl
lemma norm_of_fun_eq_lintegral_norm (f : α → β) (hf : integrable f μ) :
∥ of_fun f hf ∥ = ennreal.to_real (∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ) :=
by { rw [norm_of_fun, lintegral_norm_eq_lintegral_edist] }
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma of_fun_smul (f : α → β) (hf : integrable f μ) (k : 𝕜) :
of_fun (λa, k • f a) (hf.smul k) = k • of_fun f hf := rfl
end of_fun
section to_fun
protected lemma measurable (f : α →₁[μ] β) : measurable f := f.1.measurable
lemma measurable_norm (f : α →₁[μ] β) : measurable (λ a, ∥f a∥) :=
f.measurable.norm
protected lemma integrable (f : α →₁[μ] β) : integrable ⇑f μ :=
integrable_coe_fn.2 f.2
protected lemma has_finite_integral (f : α →₁[μ] β) : has_finite_integral ⇑f μ :=
f.integrable.has_finite_integral
lemma integrable_norm (f : α →₁[μ] β) : integrable (λ a, ∥f a∥) μ :=
(integrable_norm_iff f.measurable).mpr f.integrable
lemma of_fun_to_fun (f : α →₁[μ] β) : of_fun f f.integrable = f :=
subtype.ext (f : α →ₘ[μ] β).mk_coe_fn
lemma mk_to_fun (f : α →₁[μ] β) : (mk f f.measurable : α →ₘ[μ] β) = f :=
by { rw ← of_fun_eq_mk, rw l1.eq_iff, exact of_fun_to_fun f }
lemma to_fun_of_fun (f : α → β) (hf : integrable f μ) : ⇑(of_fun f hf : α →₁[μ] β) =ᵐ[μ] f :=
coe_fn_mk f hf.measurable
variables (α β)
lemma zero_to_fun : ⇑(0 : α →₁[μ] β) =ᵐ[μ] 0 := ae_eq_fun.coe_fn_zero
variables {α β}
lemma add_to_fun (f g : α →₁[μ] β) : ⇑(f + g) =ᵐ[μ] f + g :=
ae_eq_fun.coe_fn_add _ _
lemma neg_to_fun (f : α →₁[μ] β) : ⇑(-f) =ᵐ[μ] -⇑f := ae_eq_fun.coe_fn_neg _
lemma sub_to_fun (f g : α →₁[μ] β) : ⇑(f - g) =ᵐ[μ] ⇑f - ⇑g :=
ae_eq_fun.coe_fn_sub _ _
lemma dist_to_fun (f g : α →₁[μ] β) : dist f g = ennreal.to_real (∫⁻ x, edist (f x) (g x) ∂μ) :=
by { simp only [← coe_coe, dist_eq, edist_eq_coe] }
lemma norm_eq_nnnorm_to_fun (f : α →₁[μ] β) : ∥f∥ = ennreal.to_real (∫⁻ a, nnnorm (f a) ∂μ) :=
by { rw [← coe_coe, lintegral_nnnorm_eq_lintegral_edist, ← edist_zero_eq_coe], refl }
lemma norm_eq_norm_to_fun (f : α →₁[μ] β) :
∥f∥ = ennreal.to_real (∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ) :=
by { rw norm_eq_nnnorm_to_fun, congr, funext, rw of_real_norm_eq_coe_nnnorm }
lemma lintegral_edist_to_fun_lt_top (f g : α →₁[μ] β) : (∫⁻ a, edist (f a) (g a) ∂μ) < ⊤ :=
lintegral_edist_lt_top f.integrable g.integrable
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma smul_to_fun (c : 𝕜) (f : α →₁[μ] β) : ⇑(c • f) =ᵐ[μ] c • f :=
ae_eq_fun.coe_fn_smul _ _
end to_fun
section pos_part
/-- Positive part of a function in `L¹` space. -/
def pos_part (f : α →₁[μ] ℝ) : α →₁[μ] ℝ :=
⟨ae_eq_fun.pos_part f,
begin
rw [← ae_eq_fun.integrable_coe_fn,
integrable_congr (ae_eq_fun.measurable _) (f.measurable.max measurable_const) (coe_fn_pos_part _)],
exact f.integrable.max_zero
end ⟩
/-- Negative part of a function in `L¹` space. -/
def neg_part (f : α →₁[μ] ℝ) : α →₁[μ] ℝ := pos_part (-f)
@[norm_cast]
lemma coe_pos_part (f : α →₁[μ] ℝ) : (f.pos_part : α →ₘ[μ] ℝ) = (f : α →ₘ[μ] ℝ).pos_part := rfl
lemma pos_part_to_fun (f : α →₁[μ] ℝ) : ⇑(pos_part f) =ᵐ[μ] λ a, max (f a) 0 :=
ae_eq_fun.coe_fn_pos_part _
lemma neg_part_to_fun_eq_max (f : α →₁[μ] ℝ) : ∀ᵐ a ∂μ, neg_part f a = max (- f a) 0 :=
begin
rw neg_part,
filter_upwards [pos_part_to_fun (-f), neg_to_fun f],
simp only [mem_set_of_eq],
assume a h₁ h₂,
rw [h₁, h₂, pi.neg_apply]
end
lemma neg_part_to_fun_eq_min (f : α →₁[μ] ℝ) : ∀ᵐ a ∂μ, neg_part f a = - min (f a) 0 :=
(neg_part_to_fun_eq_max f).mono $ assume a h,
by rw [h, min_eq_neg_max_neg_neg, _root_.neg_neg, neg_zero]
lemma norm_le_norm_of_ae_le {f g : α →₁[μ] β} (h : ∀ᵐ a ∂μ, ∥f a∥ ≤ ∥g a∥) : ∥f∥ ≤ ∥g∥ :=
begin
simp only [l1.norm_eq_norm_to_fun],
rw to_real_le_to_real,
{ apply lintegral_mono_ae,
exact h.mono (λ a h, of_real_le_of_real h) },
{ rw [← lt_top_iff_ne_top, ← has_finite_integral_iff_norm], exact f.has_finite_integral },
{ rw [← lt_top_iff_ne_top, ← has_finite_integral_iff_norm], exact g.has_finite_integral }
end
lemma continuous_pos_part : continuous $ λf : α →₁[μ] ℝ, pos_part f :=
begin
simp only [metric.continuous_iff],
assume g ε hε,
use ε, use hε,
simp only [dist_eq_norm],
assume f hfg,
refine lt_of_le_of_lt (norm_le_norm_of_ae_le _) hfg,
filter_upwards [l1.sub_to_fun f g, l1.sub_to_fun (pos_part f) (pos_part g),
pos_part_to_fun f, pos_part_to_fun g],
simp only [mem_set_of_eq],
assume a h₁ h₂ h₃ h₄,
simp only [real.norm_eq_abs, h₁, h₂, h₃, h₄, pi.sub_apply],
exact abs_max_sub_max_le_abs _ _ _
end
lemma continuous_neg_part : continuous $ λf : α →₁[μ] ℝ, neg_part f :=
have eq : (λf : α →₁[μ] ℝ, neg_part f) = (λf : α →₁[μ] ℝ, pos_part (-f)) := rfl,
by { rw eq, exact continuous_pos_part.comp continuous_neg }
end pos_part
/- TODO: l1 is a complete space -/
end l1
end measure_theory
open measure_theory
lemma measurable.integrable_zero [measurable_space β] {f : α → β} (hf : measurable f) :
integrable f 0 :=
⟨hf, has_finite_integral_zero_measure f⟩
|
7c37bbf67976e876834418857b14330ebb35f511
|
5d166a16ae129621cb54ca9dde86c275d7d2b483
|
/tests/lean/run/aexp.lean
|
b4dfa099a1d66d6887a164bcee34af32458af879
|
[
"Apache-2.0"
] |
permissive
|
jcarlson23/lean
|
b00098763291397e0ac76b37a2dd96bc013bd247
|
8de88701247f54d325edd46c0eed57aeacb64baf
|
refs/heads/master
| 1,611,571,813,719
| 1,497,020,963,000
| 1,497,021,515,000
| 93,882,536
| 1
| 0
| null | 1,497,029,896,000
| 1,497,029,896,000
| null |
UTF-8
|
Lean
| false
| false
| 1,712
|
lean
|
namespace imp
open tactic
@[reducible]
def uname := string
inductive aexp
| val : nat → aexp
| var : uname → aexp
| plus : aexp → aexp → aexp
| times : aexp → aexp → aexp
instance : decidable_eq aexp :=
by mk_dec_eq_instance
@[reducible]
def value := nat
def state := uname → value
open aexp
def aval : aexp → state → value
| (val n) s := n
| (var x) s := s x
| (plus a₁ a₂) s := aval a₁ s + aval a₂ s
| (times a₁ a₂) s := aval a₁ s * aval a₂ s
example : aval (plus (val 3) (var "x")) (λ x, 0) = 3 :=
rfl
def updt (s : state) (x : uname) (v : value) : state :=
λ y, if x = y then v else s y
def asimp_const : aexp → aexp
| (val n) := val n
| (var x) := var x
| (plus a₁ a₂) :=
match asimp_const a₁, asimp_const a₂ with
| val n₁, val n₂ := val (n₁ + n₂)
| b₁, b₂ := plus b₁ b₂
end
| (times a₁ a₂) :=
match asimp_const a₁, asimp_const a₂ with
| val n₁, val n₂ := val (n₁ * n₂)
| b₁, b₂ := times b₁ b₂
end
example : asimp_const (plus (plus (val 2) (val 3)) (var "x")) = plus (val 5) (var "x") :=
rfl
attribute [ematch] asimp_const aval
-- set_option trace.smt.ematch true
meta def not_done : tactic unit := fail_if_success done
lemma aval_asimp_const (a : aexp) (s : state) : aval (asimp_const a) s = aval a s :=
begin [smt]
induction a,
all_goals {destruct (asimp_const a_1), all_goals {destruct (asimp_const a_2), eblast}}
end
lemma ex2 (a : aexp) (s : state) : aval (asimp_const a) s = aval a s :=
begin [smt]
induction a,
all_goals {destruct (asimp_const a_1), all_goals {destruct (asimp_const a_2), eblast_using [asimp_const, aval]}}
end
end imp
|
99064523c91b0a9f82fb82eb029ab4b05aed983d
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/stream/init.lean
|
30c26cbdcd95bbbab4b6acc4f55e88de6fa5f51f
|
[
"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
| 20,306
|
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
-/
import data.stream.defs
import tactic.ext
import logic.function.basic
/-!
# Streams a.k.a. infinite lists a.k.a. infinite sequences
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file used to be in the core library. It was moved to `mathlib` and renamed to `init` to avoid
name clashes. -/
open nat function option
universes u v w
namespace stream
variables {α : Type u} {β : Type v} {δ : Type w}
instance {α} [inhabited α] : inhabited (stream α) :=
⟨stream.const default⟩
protected theorem eta (s : stream α) : head s :: tail s = s :=
funext (λ i, begin cases i; refl end)
@[simp] theorem nth_zero_cons (a : α) (s : stream α) : nth (a :: s) 0 = a := rfl
theorem head_cons (a : α) (s : stream α) : head (a :: s) = a := rfl
theorem tail_cons (a : α) (s : stream α) : tail (a :: s) = s := rfl
theorem tail_drop (n : nat) (s : stream α) : tail (drop n s) = drop n (tail s) :=
funext (λ i, begin unfold tail drop, simp [nth, nat.add_comm, nat.add_left_comm] end)
theorem nth_drop (n m : nat) (s : stream α) : nth (drop m s) n = nth s (n + m) := rfl
theorem tail_eq_drop (s : stream α) : tail s = drop 1 s := rfl
theorem drop_drop (n m : nat) (s : stream α) : drop n (drop m s) = drop (n+m) s :=
funext (λ i, begin unfold drop, rw nat.add_assoc end)
theorem nth_succ (n : nat) (s : stream α) : nth s (succ n) = nth (tail s) n := rfl
@[simp] lemma nth_succ_cons (n : nat) (s : stream α) (x : α) : nth (x :: s) n.succ = nth s n := rfl
theorem drop_succ (n : nat) (s : stream α) : drop (succ n) s = drop n (tail s) := rfl
@[simp] lemma head_drop {α} (a : stream α) (n : ℕ) : (a.drop n).head = a.nth n :=
by simp only [drop, head, nat.zero_add, stream.nth]
@[ext] protected theorem ext {s₁ s₂ : stream α} : (∀ n, nth s₁ n = nth s₂ n) → s₁ = s₂ :=
assume h, funext h
lemma cons_injective2 : function.injective2 (cons : α → stream α → stream α) :=
λ x y s t h, ⟨by rw [←nth_zero_cons x s, h, nth_zero_cons],
stream.ext (λ n, by rw [←nth_succ_cons n _ x, h, nth_succ_cons])⟩
lemma cons_injective_left (s : stream α) : function.injective (λ x, cons x s) :=
cons_injective2.left _
lemma cons_injective_right (x : α) : function.injective (cons x) :=
cons_injective2.right _
theorem all_def (p : α → Prop) (s : stream α) : all p s = ∀ n, p (nth s n) := rfl
theorem any_def (p : α → Prop) (s : stream α) : any p s = ∃ n, p (nth s n) := rfl
theorem mem_cons (a : α) (s : stream α) : a ∈ (a::s) :=
exists.intro 0 rfl
theorem mem_cons_of_mem {a : α} {s : stream α} (b : α) : a ∈ s → a ∈ b :: s :=
assume ⟨n, h⟩,
exists.intro (succ n) (by rw [nth_succ, tail_cons, h])
theorem eq_or_mem_of_mem_cons {a b : α} {s : stream α} : a ∈ b::s → a = b ∨ a ∈ s :=
assume ⟨n, h⟩,
begin
cases n with n',
{ left, exact h },
{ right, rw [nth_succ, tail_cons] at h, exact ⟨n', h⟩ }
end
theorem mem_of_nth_eq {n : nat} {s : stream α} {a : α} : a = nth s n → a ∈ s :=
assume h, exists.intro n h
section map
variable (f : α → β)
theorem drop_map (n : nat) (s : stream α) : drop n (map f s) = map f (drop n s) :=
stream.ext (λ i, rfl)
theorem nth_map (n : nat) (s : stream α) : nth (map f s) n = f (nth s n) := rfl
theorem tail_map (s : stream α) : tail (map f s) = map f (tail s) :=
begin rw tail_eq_drop, refl end
theorem head_map (s : stream α) : head (map f s) = f (head s) := rfl
theorem map_eq (s : stream α) : map f s = f (head s) :: map f (tail s) :=
by rw [← stream.eta (map f s), tail_map, head_map]
theorem map_cons (a : α) (s : stream α) : map f (a :: s) = f a :: map f s :=
begin rw [← stream.eta (map f (a :: s)), map_eq], refl end
theorem map_id (s : stream α) : map id s = s := rfl
theorem map_map (g : β → δ) (f : α → β) (s : stream α) : map g (map f s) = map (g ∘ f) s := rfl
theorem map_tail (s : stream α) : map f (tail s) = tail (map f s) := rfl
theorem mem_map {a : α} {s : stream α} : a ∈ s → f a ∈ map f s :=
assume ⟨n, h⟩,
exists.intro n (by rw [nth_map, h])
theorem exists_of_mem_map {f} {b : β} {s : stream α} : b ∈ map f s → ∃ a, a ∈ s ∧ f a = b :=
assume ⟨n, h⟩, ⟨nth s n, ⟨n, rfl⟩, h.symm⟩
end map
section zip
variable (f : α → β → δ)
theorem drop_zip (n : nat) (s₁ : stream α) (s₂ : stream β) :
drop n (zip f s₁ s₂) = zip f (drop n s₁) (drop n s₂) :=
stream.ext (λ i, rfl)
theorem nth_zip (n : nat) (s₁ : stream α) (s₂ : stream β) :
nth (zip f s₁ s₂) n = f (nth s₁ n) (nth s₂ n) := rfl
theorem head_zip (s₁ : stream α) (s₂ : stream β) : head (zip f s₁ s₂) = f (head s₁) (head s₂) := rfl
theorem tail_zip (s₁ : stream α) (s₂ : stream β) :
tail (zip f s₁ s₂) = zip f (tail s₁) (tail s₂) := rfl
theorem zip_eq (s₁ : stream α) (s₂ : stream β) :
zip f s₁ s₂ = f (head s₁) (head s₂) :: zip f (tail s₁) (tail s₂) :=
begin rw [← stream.eta (zip f s₁ s₂)], refl end
@[simp] lemma nth_enum (s : stream α) (n : ℕ) : nth (enum s) n = (n, s.nth n) := rfl
lemma enum_eq_zip (s : stream α) : enum s = zip prod.mk nats s := rfl
end zip
theorem mem_const (a : α) : a ∈ const a :=
exists.intro 0 rfl
theorem const_eq (a : α) : const a = a :: const a :=
begin
apply stream.ext, intro n,
cases n; refl
end
theorem tail_const (a : α) : tail (const a) = const a :=
suffices tail (a :: const a) = const a, by rwa [← const_eq] at this, rfl
theorem map_const (f : α → β) (a : α) : map f (const a) = const (f a) := rfl
theorem nth_const (n : nat) (a : α) : nth (const a) n = a := rfl
theorem drop_const (n : nat) (a : α) : drop n (const a) = const a :=
stream.ext (λ i, rfl)
theorem head_iterate (f : α → α) (a : α) : head (iterate f a) = a := rfl
theorem tail_iterate (f : α → α) (a : α) : tail (iterate f a) = iterate f (f a) :=
begin
funext n,
induction n with n' ih,
{ refl },
{ unfold tail iterate,
unfold tail iterate at ih,
rw add_one at ih, dsimp at ih,
rw add_one, dsimp, rw ih }
end
theorem iterate_eq (f : α → α) (a : α) : iterate f a = a :: iterate f (f a) :=
begin
rw [← stream.eta (iterate f a)],
rw tail_iterate, refl
end
theorem nth_zero_iterate (f : α → α) (a : α) : nth (iterate f a) 0 = a := rfl
theorem nth_succ_iterate (n : nat) (f : α → α) (a : α) :
nth (iterate f a) (succ n) = nth (iterate f (f a)) n :=
by rw [nth_succ, tail_iterate]
section bisim
variable (R : stream α → stream α → Prop)
local infix ` ~ `:50 := R
def is_bisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → head s₁ = head s₂ ∧ tail s₁ ~ tail s₂
theorem nth_of_bisim (bisim : is_bisimulation R) :
∀ {s₁ s₂} n, s₁ ~ s₂ → nth s₁ n = nth s₂ n ∧ drop (n+1) s₁ ~ drop (n+1) s₂
| s₁ s₂ 0 h := bisim h
| s₁ s₂ (n+1) h :=
match bisim h with
| ⟨h₁, trel⟩ := nth_of_bisim n trel
end
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : is_bisimulation R) : ∀ {s₁ s₂}, s₁ ~ s₂ → s₁ = s₂ :=
λ s₁ s₂ r, stream.ext (λ n, and.elim_left (nth_of_bisim R bisim n r))
end bisim
theorem bisim_simple (s₁ s₂ : stream α) :
head s₁ = head s₂ → s₁ = tail s₁ → s₂ = tail s₂ → s₁ = s₂ :=
assume hh ht₁ ht₂, eq_of_bisim
(λ s₁ s₂, head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂)
(λ s₁ s₂ ⟨h₁, h₂, h₃⟩,
begin
constructor, exact h₁, rw [← h₂, ← h₃], repeat { constructor }; assumption
end)
(and.intro hh (and.intro ht₁ ht₂))
theorem coinduction {s₁ s₂ : stream α} :
head s₁ = head s₂ → (∀ (β : Type u) (fr : stream α → β), fr s₁ = fr s₂ →
fr (tail s₁) = fr (tail s₂)) → s₁ = s₂ :=
assume hh ht,
eq_of_bisim
(λ s₁ s₂, head s₁ = head s₂ ∧ ∀ (β : Type u) (fr : stream α → β), fr s₁ = fr s₂ →
fr (tail s₁) = fr (tail s₂))
(λ s₁ s₂ h,
have h₁ : head s₁ = head s₂, from and.elim_left h,
have h₂ : head (tail s₁) = head (tail s₂), from and.elim_right h α (@head α) h₁,
have h₃ : ∀ (β : Type u) (fr : stream α → β),
fr (tail s₁) = fr (tail s₂) → fr (tail (tail s₁)) = fr (tail (tail s₂)),
from λ β fr, and.elim_right h β (λ s, fr (tail s)),
and.intro h₁ (and.intro h₂ h₃))
(and.intro hh ht)
theorem iterate_id (a : α) : iterate id a = const a :=
coinduction
rfl
(λ β fr ch, begin rw [tail_iterate, tail_const], exact ch end)
local attribute [reducible] stream
theorem map_iterate (f : α → α) (a : α) : iterate f (f a) = map f (iterate f a) :=
begin
funext n,
induction n with n' ih,
{ refl },
{ unfold map iterate nth, dsimp,
unfold map iterate nth at ih, dsimp at ih,
rw ih }
end
section corec
theorem corec_def (f : α → β) (g : α → α) (a : α) : corec f g a = map f (iterate g a) := rfl
theorem corec_eq (f : α → β) (g : α → α) (a : α) : corec f g a = f a :: corec f g (g a) :=
begin rw [corec_def, map_eq, head_iterate, tail_iterate], refl end
theorem corec_id_id_eq_const (a : α) : corec id id a = const a :=
by rw [corec_def, map_id, iterate_id]
theorem corec_id_f_eq_iterate (f : α → α) (a : α) : corec id f a = iterate f a := rfl
end corec
section corec'
theorem corec'_eq (f : α → β × α) (a : α) : corec' f a = (f a).1 :: corec' f (f a).2 :=
corec_eq _ _ _
end corec'
theorem unfolds_eq (g : α → β) (f : α → α) (a : α) : unfolds g f a = g a :: unfolds g f (f a) :=
begin unfold unfolds, rw [corec_eq] end
theorem nth_unfolds_head_tail : ∀ (n : nat) (s : stream α), nth (unfolds head tail s) n = nth s n :=
begin
intro n, induction n with n' ih,
{ intro s, refl },
{ intro s, rw [nth_succ, nth_succ, unfolds_eq, tail_cons, ih] }
end
theorem unfolds_head_eq : ∀ (s : stream α), unfolds head tail s = s :=
λ s, stream.ext (λ n, nth_unfolds_head_tail n s)
theorem interleave_eq (s₁ s₂ : stream α) : s₁ ⋈ s₂ = head s₁ :: head s₂ :: (tail s₁ ⋈ tail s₂) :=
begin
unfold interleave corec_on, rw corec_eq, dsimp, rw corec_eq, refl
end
theorem tail_interleave (s₁ s₂ : stream α) : tail (s₁ ⋈ s₂) = s₂ ⋈ (tail s₁) :=
begin unfold interleave corec_on, rw corec_eq, refl end
theorem interleave_tail_tail (s₁ s₂ : stream α) : tail s₁ ⋈ tail s₂ = tail (tail (s₁ ⋈ s₂)) :=
begin rw [interleave_eq s₁ s₂], refl end
theorem nth_interleave_left : ∀ (n : nat) (s₁ s₂ : stream α), nth (s₁ ⋈ s₂) (2 * n) = nth s₁ n
| 0 s₁ s₂ := rfl
| (succ n) s₁ s₂ :=
begin
change nth (s₁ ⋈ s₂) (succ (succ (2*n))) = nth s₁ (succ n),
rw [nth_succ, nth_succ, interleave_eq, tail_cons, tail_cons, nth_interleave_left],
refl
end
theorem nth_interleave_right : ∀ (n : nat) (s₁ s₂ : stream α), nth (s₁ ⋈ s₂) (2*n+1) = nth s₂ n
| 0 s₁ s₂ := rfl
| (succ n) s₁ s₂ :=
begin
change nth (s₁ ⋈ s₂) (succ (succ (2*n+1))) = nth s₂ (succ n),
rw [nth_succ, nth_succ, interleave_eq, tail_cons, tail_cons, nth_interleave_right],
refl
end
theorem mem_interleave_left {a : α} {s₁ : stream α} (s₂ : stream α) : a ∈ s₁ → a ∈ s₁ ⋈ s₂ :=
assume ⟨n, h⟩,
exists.intro (2*n) (by rw [h, nth_interleave_left])
theorem mem_interleave_right {a : α} {s₁ : stream α} (s₂ : stream α) : a ∈ s₂ → a ∈ s₁ ⋈ s₂ :=
assume ⟨n, h⟩,
exists.intro (2*n+1) (by rw [h, nth_interleave_right])
theorem odd_eq (s : stream α) : odd s = even (tail s) := rfl
theorem head_even (s : stream α) : head (even s) = head s := rfl
theorem tail_even (s : stream α) : tail (even s) = even (tail (tail s)) :=
begin unfold even, rw corec_eq, refl end
theorem even_cons_cons (a₁ a₂ : α) (s : stream α) : even (a₁ :: a₂ :: s) = a₁ :: even s :=
begin unfold even, rw corec_eq, refl end
theorem even_tail (s : stream α) : even (tail s) = odd s := rfl
theorem even_interleave (s₁ s₂ : stream α) : even (s₁ ⋈ s₂) = s₁ :=
eq_of_bisim
(λ s₁' s₁, ∃ s₂, s₁' = even (s₁ ⋈ s₂))
(λ s₁' s₁ ⟨s₂, h₁⟩,
begin
rw h₁,
constructor,
{refl},
{exact ⟨tail s₂, by rw [interleave_eq, even_cons_cons, tail_cons]⟩}
end)
(exists.intro s₂ rfl)
theorem interleave_even_odd (s₁ : stream α) : even s₁ ⋈ odd s₁ = s₁ :=
eq_of_bisim
(λ s' s, s' = even s ⋈ odd s)
(λ s' s (h : s' = even s ⋈ odd s),
begin
rw h, constructor,
{refl},
{simp [odd_eq, odd_eq, tail_interleave, tail_even]}
end)
rfl
theorem nth_even : ∀ (n : nat) (s : stream α), nth (even s) n = nth s (2*n)
| 0 s := rfl
| (succ n) s :=
begin
change nth (even s) (succ n) = nth s (succ (succ (2 * n))),
rw [nth_succ, nth_succ, tail_even, nth_even], refl
end
theorem nth_odd : ∀ (n : nat) (s : stream α), nth (odd s) n = nth s (2 * n + 1) :=
λ n s, begin rw [odd_eq, nth_even], refl end
theorem mem_of_mem_even (a : α) (s : stream α) : a ∈ even s → a ∈ s :=
assume ⟨n, h⟩,
exists.intro (2*n) (by rw [h, nth_even])
theorem mem_of_mem_odd (a : α) (s : stream α) : a ∈ odd s → a ∈ s :=
assume ⟨n, h⟩,
exists.intro (2*n+1) (by rw [h, nth_odd])
theorem nil_append_stream (s : stream α) : append_stream [] s = s := rfl
theorem cons_append_stream (a : α) (l : list α) (s : stream α) :
append_stream (a::l) s = a :: append_stream l s := rfl
theorem append_append_stream :
∀ (l₁ l₂ : list α) (s : stream α), (l₁ ++ l₂) ++ₛ s = l₁ ++ₛ (l₂ ++ₛ s)
| [] l₂ s := rfl
| (list.cons a l₁) l₂ s := by rw [list.cons_append, cons_append_stream, cons_append_stream,
append_append_stream]
theorem map_append_stream (f : α → β) :
∀ (l : list α) (s : stream α), map f (l ++ₛ s) = list.map f l ++ₛ map f s
| [] s := rfl
| (list.cons a l) s := by rw [cons_append_stream, list.map_cons, map_cons, cons_append_stream,
map_append_stream]
theorem drop_append_stream : ∀ (l : list α) (s : stream α), drop l.length (l ++ₛ s) = s
| [] s := by refl
| (list.cons a l) s := by rw [list.length_cons, add_one, drop_succ, cons_append_stream, tail_cons,
drop_append_stream]
theorem append_stream_head_tail (s : stream α) : [head s] ++ₛ tail s = s :=
by rw [cons_append_stream, nil_append_stream, stream.eta]
theorem mem_append_stream_right : ∀ {a : α} (l : list α) {s : stream α}, a ∈ s → a ∈ l ++ₛ s
| a [] s h := h
| a (list.cons b l) s h :=
have ih : a ∈ l ++ₛ s, from mem_append_stream_right l h,
mem_cons_of_mem _ ih
theorem mem_append_stream_left : ∀ {a : α} {l : list α} (s : stream α), a ∈ l → a ∈ l ++ₛ s
| a [] s h := absurd h (list.not_mem_nil _)
| a (list.cons b l) s h :=
or.elim (list.eq_or_mem_of_mem_cons h)
(λ (aeqb : a = b), exists.intro 0 aeqb)
(λ (ainl : a ∈ l), mem_cons_of_mem b (mem_append_stream_left s ainl))
@[simp] theorem take_zero (s : stream α) : take 0 s = [] := rfl
@[simp] theorem take_succ (n : nat) (s : stream α) :
take (succ n) s = head s :: take n (tail s) := rfl
@[simp] theorem length_take (n : ℕ) (s : stream α) : (take n s).length = n :=
by induction n generalizing s; simp *
theorem nth_take_succ : ∀ (n : nat) (s : stream α), list.nth (take (succ n) s) n = some (nth s n)
| 0 s := rfl
| (n+1) s := begin rw [take_succ, add_one, list.nth, nth_take_succ], refl end
theorem append_take_drop :
∀ (n : nat) (s : stream α), append_stream (take n s) (drop n s) = s :=
begin
intro n,
induction n with n' ih,
{ intro s, refl },
{ intro s, rw [take_succ, drop_succ, cons_append_stream, ih (tail s), stream.eta] }
end
-- Take theorem reduces a proof of equality of infinite streams to an
-- induction over all their finite approximations.
theorem take_theorem (s₁ s₂ : stream α) : (∀ (n : nat), take n s₁ = take n s₂) → s₁ = s₂ :=
begin
intro h, apply stream.ext, intro n,
induction n with n ih,
{ have aux := h 1, simp [take] at aux, exact aux },
{ have h₁ : some (nth s₁ (succ n)) = some (nth s₂ (succ n)),
{ rw [← nth_take_succ, ← nth_take_succ, h (succ (succ n))] },
injection h₁ }
end
protected lemma cycle_g_cons (a : α) (a₁ : α) (l₁ : list α) (a₀ : α) (l₀ : list α) :
stream.cycle_g (a, a₁::l₁, a₀, l₀) = (a₁, l₁, a₀, l₀) := rfl
theorem cycle_eq : ∀ (l : list α) (h : l ≠ []), cycle l h = l ++ₛ cycle l h
| [] h := absurd rfl h
| (list.cons a l) h :=
have gen : ∀ l' a', corec stream.cycle_f stream.cycle_g (a', l', a, l) =
(a' :: l') ++ₛ corec stream.cycle_f stream.cycle_g (a, l, a, l),
begin
intro l',
induction l' with a₁ l₁ ih,
{intros, rw [corec_eq], refl},
{intros, rw [corec_eq, stream.cycle_g_cons, ih a₁], refl}
end,
gen l a
theorem mem_cycle {a : α} {l : list α} : ∀ (h : l ≠ []), a ∈ l → a ∈ cycle l h :=
assume h ainl, begin rw [cycle_eq], exact mem_append_stream_left _ ainl end
theorem cycle_singleton (a : α) (h : [a] ≠ []) : cycle [a] h = const a :=
coinduction
rfl
(λ β fr ch, by rwa [cycle_eq, const_eq])
theorem tails_eq (s : stream α) : tails s = tail s :: tails (tail s) :=
by unfold tails; rw [corec_eq]; refl
theorem nth_tails : ∀ (n : nat) (s : stream α), nth (tails s) n = drop n (tail s) :=
begin
intro n, induction n with n' ih,
{ intros, refl },
{ intro s, rw [nth_succ, drop_succ, tails_eq, tail_cons, ih] }
end
theorem tails_eq_iterate (s : stream α) : tails s = iterate tail (tail s) := rfl
theorem inits_core_eq (l : list α) (s : stream α) :
inits_core l s = l :: inits_core (l ++ [head s]) (tail s) :=
begin unfold inits_core corec_on, rw [corec_eq], refl end
theorem tail_inits (s : stream α) :
tail (inits s) = inits_core [head s, head (tail s)] (tail (tail s)) :=
begin unfold inits, rw inits_core_eq, refl end
theorem inits_tail (s : stream α) :
inits (tail s) = inits_core [head (tail s)] (tail (tail s)) := rfl
theorem cons_nth_inits_core : ∀ (a : α) (n : nat) (l : list α) (s : stream α),
a :: nth (inits_core l s) n = nth (inits_core (a::l) s) n :=
begin
intros a n,
induction n with n' ih,
{ intros, refl },
{ intros l s, rw [nth_succ, inits_core_eq, tail_cons, ih, inits_core_eq (a::l) s], refl }
end
theorem nth_inits : ∀ (n : nat) (s : stream α), nth (inits s) n = take (succ n) s :=
begin
intro n, induction n with n' ih,
{ intros, refl },
{ intros, rw [nth_succ, take_succ, ← ih, tail_inits, inits_tail, cons_nth_inits_core] }
end
theorem inits_eq (s : stream α) : inits s = [head s] :: map (list.cons (head s)) (inits (tail s)) :=
begin
apply stream.ext, intro n,
cases n,
{ refl },
{ rw [nth_inits, nth_succ, tail_cons, nth_map, nth_inits], refl }
end
theorem zip_inits_tails (s : stream α) : zip append_stream (inits s) (tails s) = const s :=
begin
apply stream.ext, intro n,
rw [nth_zip, nth_inits, nth_tails, nth_const, take_succ,
cons_append_stream, append_take_drop, stream.eta]
end
theorem identity (s : stream α) : pure id ⊛ s = s := rfl
theorem composition (g : stream (β → δ)) (f : stream (α → β)) (s : stream α) :
pure comp ⊛ g ⊛ f ⊛ s = g ⊛ (f ⊛ s) := rfl
theorem homomorphism (f : α → β) (a : α) : pure f ⊛ pure a = pure (f a) := rfl
theorem interchange (fs : stream (α → β)) (a : α) :
fs ⊛ pure a = pure (λ f : α → β, f a) ⊛ fs := rfl
theorem map_eq_apply (f : α → β) (s : stream α) : map f s = pure f ⊛ s := rfl
theorem nth_nats (n : nat) : nth nats n = n := rfl
theorem nats_eq : nats = 0 :: map succ nats :=
begin
apply stream.ext, intro n,
cases n, refl, rw [nth_succ], refl
end
end stream
|
0887c042249cd063cc4818833f322e11f7a7b9f7
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/topology/algebra/polynomial.lean
|
aacfc3ea4b05f7441ab848398f18b8f305cefbc5
|
[
"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
| 2,069
|
lean
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
Analytic facts about polynomials.
-/
import topology.algebra.ring
import data.polynomial.div
import data.real.cau_seq
open polynomial is_absolute_value
lemma polynomial.tendsto_infinity {α β : Type*} [comm_ring α] [linear_ordered_field β]
(abv : α → β) [is_absolute_value abv] {p : polynomial α} (h : 0 < degree p) :
∀ x : β, ∃ r > 0, ∀ z : α, r < abv z → x < abv (p.eval z) :=
degree_pos_induction_on p h
(λ a ha x, ⟨max (x / abv a) 1, (lt_max_iff.2 (or.inr zero_lt_one)), λ z hz,
by simp [max_lt_iff, div_lt_iff' ((abv_pos abv).2 ha), abv_mul abv] at *; tauto⟩)
(λ p hp ih x, let ⟨r, hr0, hr⟩ := ih x in
⟨max r 1, lt_max_iff.2 (or.inr zero_lt_one), λ z hz, by rw [eval_mul, eval_X, abv_mul abv];
calc x < abv (p.eval z) : hr _ (max_lt_iff.1 hz).1
... ≤ abv (eval z p) * abv z : le_mul_of_one_le_right
(abv_nonneg _ _) (max_le_iff.1 (le_of_lt hz)).2⟩)
(λ p a hp ih x, let ⟨r, hr0, hr⟩ := ih (x + abv a) in
⟨r, hr0, λ z hz, by rw [eval_add, eval_C, ← sub_neg_eq_add];
exact lt_of_lt_of_le (lt_sub_iff_add_lt.2
(by rw abv_neg abv; exact (hr z hz)))
(le_trans (le_abs_self _) (abs_abv_sub_le_abv_sub _ _ _))⟩)
@[continuity]
lemma polynomial.continuous_eval {α} [comm_semiring α] [topological_space α]
[topological_semiring α] (p : polynomial α) : continuous (λ x, p.eval x) :=
begin
apply p.induction,
{ convert continuous_const,
ext, exact eval_zero, },
{ intros a b f haf hb hcts,
simp only [polynomial.eval_add],
refine continuous.add _ hcts,
have : ∀ x, finsupp.sum (finsupp.single a b) (λ (e : ℕ) (a : α), a * x ^ e) = b * x ^a,
from λ x, finsupp.sum_single_index (by simp),
convert continuous.mul _ _,
{ ext, dsimp only [eval_eq_sum], apply this },
{ apply_instance },
{ apply continuous_const },
{ apply continuous_pow }}
end
|
5e5cdd93657bf104d82c5a512b3b63871cb673b8
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/check_monad_mk.lean
|
e17c1aaaf87dbb1cd2850f07c30ece43a1aa207a
|
[
"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
| 59
|
lean
|
#check @monad.mk
#check @functor.mk
#check @applicative.mk
|
1a3d186e5bfae685c55df6e77bed12307a3baffa
|
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
|
/src/topology/list.lean
|
dddaca3c1f0b574d0777a71eb822dc2cbb0339a1
|
[
"Apache-2.0"
] |
permissive
|
lacker/mathlib
|
f2439c743c4f8eb413ec589430c82d0f73b2d539
|
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
|
refs/heads/master
| 1,671,948,326,773
| 1,601,479,268,000
| 1,601,479,268,000
| 298,686,743
| 0
| 0
|
Apache-2.0
| 1,601,070,794,000
| 1,601,070,794,000
| null |
UTF-8
|
Lean
| false
| false
| 8,387
|
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
Topology on lists and vectors.
-/
import topology.constructions
open topological_space set filter
open_locale topological_space filter
variables {α : Type*} {β : Type*}
instance [topological_space α] : topological_space (list α) :=
topological_space.mk_of_nhds (traverse nhds)
lemma nhds_list [topological_space α] (as : list α) : 𝓝 as = traverse 𝓝 as :=
begin
refine nhds_mk_of_nhds _ _ _ _,
{ assume l, induction l,
case list.nil { exact le_refl _ },
case list.cons : a l ih {
suffices : list.cons <$> pure a <*> pure l ≤ list.cons <$> 𝓝 a <*> traverse 𝓝 l,
{ simpa only [] with functor_norm using this },
exact filter.seq_mono (filter.map_mono $ pure_le_nhds a) ih } },
{ assume l s hs,
rcases (mem_traverse_sets_iff _ _).1 hs with ⟨u, hu, hus⟩, clear as hs,
have : ∃v:list (set α), l.forall₂ (λa s, is_open s ∧ a ∈ s) v ∧ sequence v ⊆ s,
{ induction hu generalizing s,
case list.forall₂.nil : hs this { existsi [], simpa only [list.forall₂_nil_left_iff, exists_eq_left] },
case list.forall₂.cons : a s as ss ht h ih t hts {
rcases mem_nhds_sets_iff.1 ht with ⟨u, hut, hu⟩,
rcases ih (subset.refl _) with ⟨v, hv, hvss⟩,
exact ⟨u::v, list.forall₂.cons hu hv,
subset.trans (set.seq_mono (set.image_subset _ hut) hvss) hts⟩ } },
rcases this with ⟨v, hv, hvs⟩,
refine ⟨sequence v, mem_traverse_sets _ _ _, hvs, _⟩,
{ exact hv.imp (assume a s ⟨hs, ha⟩, mem_nhds_sets hs ha) },
{ assume u hu,
have hu := (list.mem_traverse _ _).1 hu,
have : list.forall₂ (λa s, is_open s ∧ a ∈ s) u v,
{ refine list.forall₂.flip _,
replace hv := hv.flip,
simp only [list.forall₂_and_left, flip] at ⊢ hv,
exact ⟨hv.1, hu.flip⟩ },
refine mem_sets_of_superset _ hvs,
exact mem_traverse_sets _ _ (this.imp $ assume a s ⟨hs, ha⟩, mem_nhds_sets hs ha) } }
end
lemma nhds_nil [topological_space α] : 𝓝 ([] : list α) = pure [] :=
by rw [nhds_list, list.traverse_nil _]; apply_instance
lemma nhds_cons [topological_space α] (a : α) (l : list α) :
𝓝 (a :: l) = list.cons <$> 𝓝 a <*> 𝓝 l :=
by rw [nhds_list, list.traverse_cons _, ← nhds_list]; apply_instance
namespace list
variables [topological_space α] [topological_space β]
lemma tendsto_cons' {a : α} {l : list α} :
tendsto (λp:α×list α, list.cons p.1 p.2) (𝓝 a ×ᶠ 𝓝 l) (𝓝 (a :: l)) :=
by rw [nhds_cons, tendsto, map_prod]; exact le_refl _
lemma tendsto_cons {α : Type*} {f : α → β} {g : α → list β}
{a : _root_.filter α} {b : β} {l : list β} (hf : tendsto f a (𝓝 b)) (hg : tendsto g a (𝓝 l)) :
tendsto (λa, list.cons (f a) (g a)) a (𝓝 (b :: l)) :=
tendsto_cons'.comp (tendsto.prod_mk hf hg)
lemma tendsto_cons_iff {β : Type*} {f : list α → β} {b : _root_.filter β} {a : α} {l : list α} :
tendsto f (𝓝 (a :: l)) b ↔ tendsto (λp:α×list α, f (p.1 :: p.2)) (𝓝 a ×ᶠ 𝓝 l) b :=
have 𝓝 (a :: l) = (𝓝 a ×ᶠ 𝓝 l).map (λp:α×list α, (p.1 :: p.2)),
begin
simp only
[nhds_cons, filter.prod_eq, (filter.map_def _ _).symm, (filter.seq_eq_filter_seq _ _).symm],
simp [-filter.seq_eq_filter_seq, -filter.map_def, (∘)] with functor_norm,
end,
by rw [this, filter.tendsto_map'_iff]
lemma tendsto_nhds {β : Type*} {f : list α → β} {r : list α → _root_.filter β}
(h_nil : tendsto f (pure []) (r []))
(h_cons : ∀l a, tendsto f (𝓝 l) (r l) → tendsto (λp:α×list α, f (p.1 :: p.2)) (𝓝 a ×ᶠ 𝓝 l) (r (a::l))) :
∀l, tendsto f (𝓝 l) (r l)
| [] := by rwa [nhds_nil]
| (a::l) := by rw [tendsto_cons_iff]; exact h_cons l a (tendsto_nhds l)
lemma continuous_at_length :
∀(l : list α), continuous_at list.length l :=
begin
simp only [continuous_at, nhds_discrete],
refine tendsto_nhds _ _,
{ exact tendsto_pure_pure _ _ },
{ assume l a ih,
dsimp only [list.length],
refine tendsto.comp (tendsto_pure_pure (λx, x + 1) _) _,
refine tendsto.comp ih tendsto_snd }
end
lemma tendsto_insert_nth' {a : α} : ∀{n : ℕ} {l : list α},
tendsto (λp:α×list α, insert_nth n p.1 p.2) (𝓝 a ×ᶠ 𝓝 l) (𝓝 (insert_nth n a l))
| 0 l := tendsto_cons'
| (n+1) [] :=
suffices tendsto (λa, []) (𝓝 a) (𝓝 ([] : list α)),
by simpa [nhds_nil, tendsto, map_prod, (∘), insert_nth],
tendsto_const_nhds
| (n+1) (a'::l) :=
have 𝓝 a ×ᶠ 𝓝 (a' :: l) =
(𝓝 a ×ᶠ (𝓝 a' ×ᶠ 𝓝 l)).map (λp:α×α×list α, (p.1, p.2.1 :: p.2.2)),
begin
simp only
[nhds_cons, filter.prod_eq, (filter.map_def _ _).symm, (filter.seq_eq_filter_seq _ _).symm],
simp [-filter.seq_eq_filter_seq, -filter.map_def, (∘)] with functor_norm
end,
begin
rw [this, tendsto_map'_iff],
exact tendsto_cons
(tendsto_fst.comp tendsto_snd)
((@tendsto_insert_nth' n l).comp (tendsto.prod_mk tendsto_fst (tendsto_snd.comp tendsto_snd)))
end
lemma tendsto_insert_nth {β : Type*} {n : ℕ} {a : α} {l : list α} {f : β → α} {g : β → list α}
{b : _root_.filter β} (hf : tendsto f b (𝓝 a)) (hg : tendsto g b (𝓝 l)) :
tendsto (λb:β, insert_nth n (f b) (g b)) b (𝓝 (insert_nth n a l)) :=
tendsto_insert_nth'.comp (tendsto.prod_mk hf hg)
lemma continuous_insert_nth {n : ℕ} : continuous (λp:α×list α, insert_nth n p.1 p.2) :=
continuous_iff_continuous_at.mpr $
assume ⟨a, l⟩, by rw [continuous_at, nhds_prod_eq]; exact tendsto_insert_nth'
lemma tendsto_remove_nth : ∀{n : ℕ} {l : list α},
tendsto (λl, remove_nth l n) (𝓝 l) (𝓝 (remove_nth l n))
| _ [] := by rw [nhds_nil]; exact tendsto_pure_nhds _ _
| 0 (a::l) := by rw [tendsto_cons_iff]; exact tendsto_snd
| (n+1) (a::l) :=
begin
rw [tendsto_cons_iff],
dsimp [remove_nth],
exact tendsto_cons tendsto_fst ((@tendsto_remove_nth n l).comp tendsto_snd)
end
lemma continuous_remove_nth {n : ℕ} : continuous (λl : list α, remove_nth l n) :=
continuous_iff_continuous_at.mpr $ assume a, tendsto_remove_nth
end list
namespace vector
open list
instance (n : ℕ) [topological_space α] : topological_space (vector α n) :=
by unfold vector; apply_instance
lemma tendsto_cons [topological_space α] {n : ℕ} {a : α} {l : vector α n}:
tendsto (λp:α×vector α n, vector.cons p.1 p.2) (𝓝 a ×ᶠ 𝓝 l) (𝓝 (a :: l)) :=
by { simp [tendsto_subtype_rng, ←subtype.val_eq_coe, cons_val],
exact tendsto_cons tendsto_fst (tendsto.comp continuous_at_subtype_coe tendsto_snd) }
lemma tendsto_insert_nth
[topological_space α] {n : ℕ} {i : fin (n+1)} {a:α} :
∀{l:vector α n}, tendsto (λp:α×vector α n, insert_nth p.1 i p.2)
(𝓝 a ×ᶠ 𝓝 l) (𝓝 (insert_nth a i l))
| ⟨l, hl⟩ :=
begin
rw [insert_nth, tendsto_subtype_rng],
simp [insert_nth_val],
exact list.tendsto_insert_nth tendsto_fst (tendsto.comp continuous_at_subtype_coe tendsto_snd : _)
end
lemma continuous_insert_nth' [topological_space α] {n : ℕ} {i : fin (n+1)} :
continuous (λp:α×vector α n, insert_nth p.1 i p.2) :=
continuous_iff_continuous_at.mpr $ assume ⟨a, l⟩,
by rw [continuous_at, nhds_prod_eq]; exact tendsto_insert_nth
lemma continuous_insert_nth [topological_space α] [topological_space β] {n : ℕ} {i : fin (n+1)}
{f : β → α} {g : β → vector α n} (hf : continuous f) (hg : continuous g) :
continuous (λb, insert_nth (f b) i (g b)) :=
continuous_insert_nth'.comp (continuous.prod_mk hf hg)
lemma continuous_at_remove_nth [topological_space α] {n : ℕ} {i : fin (n+1)} :
∀{l:vector α (n+1)}, continuous_at (remove_nth i) l
| ⟨l, hl⟩ :=
-- ∀{l:vector α (n+1)}, tendsto (remove_nth i) (𝓝 l) (𝓝 (remove_nth i l))
--| ⟨l, hl⟩ :=
begin
rw [continuous_at, remove_nth, tendsto_subtype_rng],
simp only [← subtype.val_eq_coe, vector.remove_nth_val],
exact tendsto.comp list.tendsto_remove_nth continuous_at_subtype_coe,
end
lemma continuous_remove_nth [topological_space α] {n : ℕ} {i : fin (n+1)} :
continuous (remove_nth i : vector α (n+1) → vector α n) :=
continuous_iff_continuous_at.mpr $ assume ⟨a, l⟩, continuous_at_remove_nth
end vector
|
f008237c78e4caf3aafaa644638c998da7e2f7fd
|
d642a6b1261b2cbe691e53561ac777b924751b63
|
/src/topology/metric_space/cau_seq_filter.lean
|
b8236f2351412734b97984c4bf97c0298ee5dbfa
|
[
"Apache-2.0"
] |
permissive
|
cipher1024/mathlib
|
fee56b9954e969721715e45fea8bcb95f9dc03fe
|
d077887141000fefa5a264e30fa57520e9f03522
|
refs/heads/master
| 1,651,806,490,504
| 1,573,508,694,000
| 1,573,508,694,000
| 107,216,176
| 0
| 0
|
Apache-2.0
| 1,647,363,136,000
| 1,508,213,014,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 19,628
|
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, Sébastien Gouëzel
Characterize completeness of metric spaces in terms of Cauchy sequences.
In particular, reconcile the filter notion of Cauchy-ness with the cau_seq notion on normed spaces.
-/
import topology.uniform_space.basic analysis.normed_space.basic data.real.cau_seq analysis.specific_limits
import tactic.linarith
universes u v
open set filter classical emetric
variable {β : Type v}
/- We show that a metric space in which all Cauchy sequences converge is complete, i.e., all
Cauchy filters converge. For this, we approximate any Cauchy filter by a Cauchy sequence,
taking advantage of the fact that there is a sequence tending to `0` in ℝ. The proof also gives
a more precise result, that to get completeness it is enough to have the convergence
of all sequence that are Cauchy in a fixed quantitative sense, for instance satisfying
`dist (u n) (u m) < 2^{- min m n}`. The classical argument to obtain this criterion is to start
from a Cauchy sequence, extract a subsequence that satisfies this property, deduce the convergence
of the subsequence, and then the convergence of the original sequence. All this argument is
completely bypassed by the following proof, which avoids any use of subsequences and is written
partly in terms of filters. -/
namespace ennreal
/-In this paragraph, we prove useful properties of the sequence `half_pow n := 2^{-n}` in ennreal.
Some of them are instrumental in this file to get Cauchy sequences, but others are proved
here only for use in further applications of the completeness criterion
`emetric.complete_of_convergent_controlled_sequences` below. -/
/-- An auxiliary positive sequence that tends to `0` in `ennreal`, with good behavior. -/
noncomputable def half_pow (n : ℕ) : ennreal := ennreal.of_real ((1 / 2) ^ n)
lemma half_pow_pos (n : ℕ) : 0 < half_pow n :=
begin
have : (0 : real) < (1/2)^n := pow_pos (by norm_num) _,
simpa [half_pow] using this
end
lemma half_pow_tendsto_zero : tendsto (λn, half_pow n) at_top (nhds 0) :=
begin
unfold half_pow,
rw ← ennreal.of_real_zero,
apply ennreal.tendsto_of_real,
exact tendsto_pow_at_top_nhds_0_of_lt_1 (by norm_num) (by norm_num)
end
lemma half_pow_add_succ (n : ℕ) : half_pow (n+1) + half_pow (n+1) = half_pow n :=
begin
have : (0 : real) ≤ (1/2)^(n+1) := (le_of_lt (pow_pos (by norm_num) _)),
simp only [half_pow, eq.symm (ennreal.of_real_add this this)],
apply congr_arg,
simp only [pow_add, one_div_eq_inv, pow_one],
ring,
end
lemma half_pow_mono (m k : ℕ) (h : m ≤ k) : half_pow k ≤ half_pow m :=
ennreal.of_real_le_of_real (pow_le_pow_of_le_one (by norm_num) (by norm_num) h)
lemma edist_le_two_mul_half_pow [emetric_space β] {k l N : ℕ} (hk : N ≤ k) (hl : N ≤ l)
{u : ℕ → β} (h : ∀n, edist (u n) (u (n+1)) ≤ half_pow n) :
edist (u k) (u l) ≤ 2 * half_pow N :=
begin
have ineq_rec : ∀m, ∀k≥m, half_pow k + edist (u m) (u (k+1)) ≤ 2 * half_pow m,
{ assume m,
refine nat.le_induction _ (λk km hk, _),
{ calc half_pow m + edist (u m) (u (m+1)) ≤ half_pow m + half_pow m : add_le_add_left' (h m)
... = 2 * half_pow m : by simp [(mul_two _).symm, mul_comm] },
{ calc half_pow (k + 1) + edist (u m) (u (k + 1 + 1))
≤ half_pow (k+1) + (edist (u m) (u (k+1)) + edist (u (k+1)) (u (k+2))) :
add_le_add_left' (edist_triangle _ _ _)
... ≤ half_pow (k+1) + (edist (u m) (u (k+1)) + half_pow (k+1)) :
add_le_add_left' (add_le_add_left' (h (k+1)))
... = (half_pow(k+1) + half_pow(k+1)) + edist (u m) (u (k+1)) : by simp [add_comm]
... = half_pow k + edist (u m) (u (k+1)) : by rw half_pow_add_succ
... ≤ 2 * half_pow m : hk }},
have Imk : ∀m, ∀k≥m, edist (u m) (u k) ≤ 2 * half_pow m,
{ assume m k hk,
by_cases h : m = k,
{ simp [h, le_of_lt (half_pow_pos k)] },
{ have I : m < k := lt_of_le_of_ne hk h,
have : 0 < k := lt_of_le_of_lt (nat.zero_le _) ‹m < k›,
let l := nat.pred k,
have : k = l+1 := (nat.succ_pred_eq_of_pos ‹0 < k›).symm,
rw this,
have : m ≤ l := begin rw this at I, apply nat.le_of_lt_succ I end,
calc edist (u m) (u (l+1)) ≤ half_pow l + edist (u m) (u (l+1)) : le_add_left (le_refl _)
... ≤ 2 * half_pow m : ineq_rec m l ‹m ≤ l› }},
by_cases h : k ≤ l,
{ calc edist (u k) (u l) ≤ 2 * half_pow k : Imk k l h
... ≤ 2 * half_pow N :
canonically_ordered_semiring.mul_le_mul (le_refl _) (half_pow_mono N k hk) },
{ simp at h,
calc edist (u k) (u l) = edist (u l) (u k) : edist_comm _ _
... ≤ 2 * half_pow l : Imk l k (le_of_lt h)
... ≤ 2 * half_pow N :
canonically_ordered_semiring.mul_le_mul (le_refl _) (half_pow_mono N l hl) }
end
lemma cauchy_seq_of_edist_le_half_pow [emetric_space β]
{u : ℕ → β} (h : ∀n, edist (u n) (u (n+1)) ≤ half_pow n) : cauchy_seq u :=
begin
refine emetric.cauchy_seq_iff_le_tendsto_0.2 ⟨λn:ℕ, 2 * half_pow n, ⟨_, _⟩⟩,
{ exact λk l N hk hl, edist_le_two_mul_half_pow hk hl h },
{ have : tendsto (λn, 2 * half_pow n) at_top (nhds (2 * 0)) :=
ennreal.tendsto_mul_right half_pow_tendsto_zero (by simp),
simpa using this }
end
end ennreal
namespace sequentially_complete
section
/- We fix a cauchy filter `f`, and a bounding sequence `B` made of positive numbers. We will
prove that, if all sequences satisfying `dist (u n) (u m) < B (min n m)` converge, then
the cauchy filter `f` is converging. The idea is to construct from `f` a Cauchy sequence
that satisfies this property, therefore converges, and then to deduce the convergence of
`f` from this.
We give the argument in the more general setting of emetric spaces, and specialize it to
metric spaces at the end.
-/
variables [emetric_space β] {f : filter β} (hf : cauchy f) (B : ℕ → ennreal) (hB : ∀n, 0 < B n)
open ennreal
/--Auxiliary sequence, which is bounded by `B`, positive, and tends to `0`.-/
noncomputable def B2 (B : ℕ → ennreal) (n : ℕ) :=
(half_pow n) ⊓ (B n)
lemma B2_pos (hB : ∀n, 0 < B n) (n : ℕ) : 0 < B2 B n :=
by unfold B2; simp [half_pow_pos n, hB n]
lemma B2_lim : tendsto (λn, B2 B n) at_top (nhds 0) :=
begin
have : ∀n, B2 B n ≤ half_pow n := λn, lattice.inf_le_left,
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds half_pow_tendsto_zero
(by simp) (by simp [this])
end
/-- Define a decreasing sequence of sets in the filter `f`, of diameter bounded by `B2 n`. -/
def set_seq_of_cau_filter : ℕ → set β
| 0 := some ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB 0))
| (n+1) := (set_seq_of_cau_filter n) ∩ some ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB (n + 1)))
/-- These sets are in the filter. -/
lemma set_seq_of_cau_filter_mem_sets : ∀ n, set_seq_of_cau_filter hf B hB n ∈ f
| 0 := some (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB 0)))
| (n+1) := inter_mem_sets (set_seq_of_cau_filter_mem_sets n)
(some (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB (n + 1)))))
/-- These sets are nonempty. -/
lemma set_seq_of_cau_filter_inhabited (n : ℕ) : ∃ x, x ∈ set_seq_of_cau_filter hf B hB n :=
inhabited_of_mem_sets (emetric.cauchy_iff.1 hf).1 (set_seq_of_cau_filter_mem_sets hf B hB n)
/-- By construction, their diameter is controlled by `B2 n`. -/
lemma set_seq_of_cau_filter_spec : ∀ n, ∀ {x y},
x ∈ set_seq_of_cau_filter hf B hB n → y ∈ set_seq_of_cau_filter hf B hB n → edist x y < B2 B n
| 0 := some_spec (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB 0)))
| (n+1) := λ x y hx hy,
some_spec (some_spec ((emetric.cauchy_iff.1 hf).2 _ (B2_pos B hB (n+1)))) x y
(mem_of_mem_inter_right hx) (mem_of_mem_inter_right hy)
-- this must exist somewhere, no?
private lemma mono_of_mono_succ_aux {α} [partial_order α] (f : ℕ → α) (h : ∀ n, f (n+1) ≤ f n) (m : ℕ) :
∀ n, f (m + n) ≤ f m
| 0 := le_refl _
| (k+1) := le_trans (h _) (mono_of_mono_succ_aux _)
lemma mono_of_mono_succ {α} [partial_order α] (f : ℕ → α) (h : ∀ n, f (n+1) ≤ f n) {m n : ℕ}
(hmn : m ≤ n) : f n ≤ f m :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_le hmn in
by simpa [hk] using mono_of_mono_succ_aux f h m k
lemma set_seq_of_cau_filter_monotone' (n : ℕ) :
set_seq_of_cau_filter hf B hB (n+1) ⊆ set_seq_of_cau_filter hf B hB n :=
inter_subset_left _ _
/-- These sets are nested. -/
lemma set_seq_of_cau_filter_monotone {n k : ℕ} (hle : n ≤ k) :
set_seq_of_cau_filter hf B hB k ⊆ set_seq_of_cau_filter hf B hB n :=
mono_of_mono_succ (set_seq_of_cau_filter hf B hB) (set_seq_of_cau_filter_monotone' hf B hB) hle
/-- Define the approximating Cauchy sequence for the Cauchy filter `f`,
obtained by taking a point in each set. -/
noncomputable def seq_of_cau_filter (n : ℕ) : β :=
some (set_seq_of_cau_filter_inhabited hf B hB n)
/-- The approximating sequence indeed belong to our good sets. -/
lemma seq_of_cau_filter_mem_set_seq (n : ℕ) : seq_of_cau_filter hf B hB n ∈ set_seq_of_cau_filter hf B hB n :=
some_spec (set_seq_of_cau_filter_inhabited hf B hB n)
/-- The distance between points in the sequence is bounded by `B2 N`. -/
lemma seq_of_cau_filter_bound {N n k : ℕ} (hn : N ≤ n) (hk : N ≤ k) :
edist (seq_of_cau_filter hf B hB n) (seq_of_cau_filter hf B hB k) < B2 B N :=
set_seq_of_cau_filter_spec hf B hB N
(set_seq_of_cau_filter_monotone hf B hB hn (seq_of_cau_filter_mem_set_seq hf B hB n))
(set_seq_of_cau_filter_monotone hf B hB hk (seq_of_cau_filter_mem_set_seq hf B hB k))
/-- The approximating sequence is indeed Cauchy as `B2 n` tends to `0` with `n`. -/
lemma seq_of_cau_filter_is_cauchy :
cauchy_seq (seq_of_cau_filter hf B hB) :=
emetric.cauchy_seq_iff_le_tendsto_0.2 ⟨B2 B,
λ n m N hn hm, le_of_lt (seq_of_cau_filter_bound hf B hB hn hm), B2_lim B⟩
/-- If the approximating Cauchy sequence is converging, to a limit `y`, then the
original Cauchy filter `f` is also converging, to the same limit.
Given `t1` in the filter `f` and `t2` a neighborhood of `y`, it suffices to show that `t1 ∩ t2` is
nonempty.
Pick `ε` so that the ε-eball around `y` is contained in `t2`.
Pick `n` with `B2 n < ε/2`, and `n2` such that `dist(seq n2, y) < ε/2`. Let `N = max(n, n2)`.
We defined `seq` by looking at a decreasing sequence of sets of `f` with shrinking radius.
The Nth one has radius `< B2 N < ε/2`. This set is in `f`, so we can find an element `x` that's
also in `t1`.
`dist(x, seq N) < ε/2` since `seq N` is in this set, and `dist (seq N, y) < ε/2`,
so `x` is in the ε-ball around `y`, and thus in `t2`. -/
lemma le_nhds_cau_filter_lim {y : β} (H : tendsto (seq_of_cau_filter hf B hB) at_top (nhds y)) :
f ≤ nhds y :=
begin
refine (le_nhds_iff_adhp_of_cauchy hf).2 _,
refine forall_sets_neq_empty_iff_neq_bot.1 (λs hs, _),
rcases filter.mem_inf_sets.2 hs with ⟨t1, ht1, t2, ht2, ht1t2⟩,
rcases emetric.mem_nhds_iff.1 ht2 with ⟨ε, hε, ht2'⟩,
cases emetric.cauchy_iff.1 hf with hfb _,
have : ε / 2 > 0 := ennreal.half_pos hε,
rcases inhabited_of_mem_sets (by simp) ((tendsto_orderable.1 (B2_lim B)).2 _ this)
with ⟨n, hnε⟩,
simp only [set.mem_set_of_eq] at hnε, -- hnε : ε / 2 > B2 B hB n
cases (emetric.tendsto_at_top _).1 H _ this with n2 hn2,
let N := max n n2,
have ht1sn : t1 ∩ set_seq_of_cau_filter hf B hB N ∈ f,
from inter_mem_sets ht1 (set_seq_of_cau_filter_mem_sets hf B hB _),
have hts1n_ne : t1 ∩ set_seq_of_cau_filter hf B hB N ≠ ∅,
from forall_sets_neq_empty_iff_neq_bot.2 hfb _ ht1sn,
cases exists_mem_of_ne_empty hts1n_ne with x hx,
-- x : β, hx : x ∈ t1 ∩ set_seq_of_cau_filter hf B hB N
-- we still have to show that x ∈ t2, i.e., edist x y < ε
have I1 : seq_of_cau_filter hf B hB N ∈ set_seq_of_cau_filter hf B hB n :=
(set_seq_of_cau_filter_monotone hf B hB (le_max_left n n2)) (seq_of_cau_filter_mem_set_seq hf B hB N),
have I2 : x ∈ set_seq_of_cau_filter hf B hB n :=
(set_seq_of_cau_filter_monotone hf B hB (le_max_left n n2)) hx.2,
have hdist1 : edist x (seq_of_cau_filter hf B hB N) < B2 B n :=
set_seq_of_cau_filter_spec hf B hB _ I2 I1,
have hdist2 : edist (seq_of_cau_filter hf B hB N) y < ε / 2 :=
hn2 N (le_max_right _ _),
have hdist : edist x y < ε := calc
edist x y ≤ edist x (seq_of_cau_filter hf B hB N) + edist (seq_of_cau_filter hf B hB N) y : edist_triangle _ _ _
... < B2 B n + ε/2 : ennreal.add_lt_add hdist1 hdist2
... ≤ ε/2 + ε/2 : add_le_add_right' (le_of_lt hnε)
... = ε : ennreal.add_halves _,
have hxt2 : x ∈ t2, from ht2' hdist,
exact ne_empty_iff_exists_mem.2 ⟨x, ht1t2 (mem_inter hx.left hxt2)⟩
end
end
end sequentially_complete
/-- An emetric space in which every Cauchy sequence converges is complete. -/
theorem complete_of_cauchy_seq_tendsto {α : Type u} [emetric_space α]
(H : ∀u : ℕ → α, cauchy_seq u → ∃x, tendsto u at_top (nhds x)) :
complete_space α :=
⟨begin
-- Consider a Cauchy filter `f`
intros f hf,
-- Introduce a sequence `u` approximating the filter `f`. We don't need the bound `B`,
-- so take for instance `B n = 1` for all `n`.
let u := sequentially_complete.seq_of_cau_filter hf (λn, 1) (λn, ennreal.zero_lt_one),
-- It is Cauchy.
have : cauchy_seq u := sequentially_complete.seq_of_cau_filter_is_cauchy hf (λn, 1) (λn, ennreal.zero_lt_one),
-- Therefore, it converges by assumption. Let `x` be its limit.
rcases H u this with ⟨x, hx⟩,
-- The original filter also converges to `x`.
exact ⟨x, sequentially_complete.le_nhds_cau_filter_lim hf (λn, 1) (λn, ennreal.zero_lt_one) hx⟩
end⟩
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem emetric.complete_of_convergent_controlled_sequences {α : Type u} [emetric_space α]
(B : ℕ → ennreal) (hB : ∀n, 0 < B n)
(H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) → ∃x, tendsto u at_top (nhds x)) :
complete_space α :=
⟨begin
-- Consider a Cauchy filter `f`.
intros f hf,
-- Introduce a sequence `u` approximating the filter `f`.
let u := sequentially_complete.seq_of_cau_filter hf B hB,
-- It satisfies the required bound.
have : ∀N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N := λN n m hn hm, calc
edist (u n) (u m) < sequentially_complete.B2 B N :
sequentially_complete.seq_of_cau_filter_bound hf B hB hn hm
... ≤ B N : lattice.inf_le_right,
-- Therefore, it converges by assumption. Let `x` be its limit.
rcases H u this with ⟨x, hx⟩,
-- The original filter also converges to `x`.
exact ⟨x, sequentially_complete.le_nhds_cau_filter_lim hf B hB hx⟩
end⟩
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem metric.complete_of_convergent_controlled_sequences {α : Type u} [metric_space α]
(B : ℕ → real) (hB : ∀n, 0 < B n)
(H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) → ∃x, tendsto u at_top (nhds x)) :
complete_space α :=
begin
-- this follows from the same criterion in emetric spaces. We just need to translate
-- the convergence assumption from `dist` to `edist`
apply emetric.complete_of_convergent_controlled_sequences (λn, ennreal.of_real (B n)),
{ simp [hB] },
{ assume u Hu,
apply H,
assume N n m hn hm,
have Z := Hu N n m hn hm,
rw [edist_dist, ennreal.of_real_lt_of_real_iff] at Z,
exact Z,
exact hB N }
end
section
/- Now, we will apply these results to `cau_seq`, i.e., "Cauchy sequences" defined by a
multiplicative absolute value on normed fields. -/
lemma tendsto_limit [normed_ring β] [hn : is_absolute_value (norm : β → ℝ)]
(f : cau_seq β norm) [cau_seq.is_complete β norm] :
tendsto f at_top (nhds f.lim) :=
_root_.tendsto_nhds.mpr
begin
intros s os lfs,
suffices : ∃ (a : ℕ), ∀ (b : ℕ), b ≥ a → f b ∈ s, by simpa using this,
rcases metric.is_open_iff.1 os _ lfs with ⟨ε, ⟨hε, hεs⟩⟩,
cases setoid.symm (cau_seq.equiv_lim f) _ hε with N hN,
existsi N,
intros b hb,
apply hεs,
dsimp [metric.ball], rw [dist_comm, dist_eq_norm],
solve_by_elim
end
variables [normed_field β]
/-
This section shows that if we have a uniform space generated by an absolute value, topological
completeness and Cauchy sequence completeness coincide. The problem is that there isn't
a good notion of "uniform space generated by an absolute value", so right now this is
specific to norm. Furthermore, norm only instantiates is_absolute_value on normed_field.
This needs to be fixed, since it prevents showing that ℤ_[hp] is complete
-/
instance normed_field.is_absolute_value : is_absolute_value (norm : β → ℝ) :=
{ abv_nonneg := norm_nonneg,
abv_eq_zero := norm_eq_zero,
abv_add := norm_triangle,
abv_mul := normed_field.norm_mul }
open metric
lemma cauchy_of_filter_cauchy (f : ℕ → β) (hf : cauchy_seq f) :
is_cau_seq norm f :=
begin
cases cauchy_iff.1 hf with hf1 hf2,
intros ε hε,
rcases hf2 {x | dist x.1 x.2 < ε} (dist_mem_uniformity hε) with ⟨t, ⟨ht, htsub⟩⟩,
simp at ht, cases ht with N hN,
existsi N,
intros j hj,
rw ←dist_eq_norm,
apply @htsub (f j, f N),
apply set.mk_mem_prod; solve_by_elim [le_refl]
end
lemma filter_cauchy_of_cauchy (f : cau_seq β norm) : cauchy_seq f :=
begin
apply cauchy_iff.2,
split,
{ exact map_ne_bot at_top_ne_bot },
{ intros s hs,
rcases mem_uniformity_dist.1 hs with ⟨ε, ⟨hε, hεs⟩⟩,
cases cau_seq.cauchy₂ f hε with N hN,
existsi {n | n ≥ N}.image f,
simp, split,
{ existsi N, intros b hb, existsi b, simp [hb] },
{ rintros ⟨a, b⟩ ⟨⟨a', ⟨ha'1, ha'2⟩⟩, ⟨b', ⟨hb'1, hb'2⟩⟩⟩,
dsimp at ha'1 ha'2 hb'1 hb'2,
rw [←ha'2, ←hb'2],
apply hεs,
rw dist_eq_norm,
apply hN; assumption }},
end
/-- In a normed field, `cau_seq` coincides with the usual notion of Cauchy sequences. -/
lemma cau_seq_iff_cauchy_seq {α : Type u} [normed_field α] {u : ℕ → α} :
is_cau_seq norm u ↔ cauchy_seq u :=
⟨λh, filter_cauchy_of_cauchy ⟨u, h⟩,
λh, cauchy_of_filter_cauchy u h⟩
/-- A complete normed field is complete as a metric space, as Cauchy sequences converge by
assumption and this suffices to characterize completeness. -/
instance complete_space_of_cau_seq_complete [cau_seq.is_complete β norm] : complete_space β :=
begin
apply complete_of_cauchy_seq_tendsto,
assume u hu,
have C : is_cau_seq norm u := cau_seq_iff_cauchy_seq.2 hu,
existsi cau_seq.lim ⟨u, C⟩,
rw metric.tendsto_at_top,
assume ε εpos,
cases (cau_seq.equiv_lim ⟨u, C⟩) _ εpos with N hN,
existsi N,
simpa [dist_eq_norm] using hN
end
end
|
01c341b6389c6dc0711083b119eaf37aebdfa064
|
ec5a7ae10c533e1b1f4b0bc7713e91ecf829a3eb
|
/ijcar16/examples/cc3.lean
|
5e2ab496a47481dabd9cfbf8774a66a53fb5bb31
|
[
"MIT"
] |
permissive
|
leanprover/leanprover.github.io
|
cf248934af7c7e9aeff17cf8df3c12c5e7e73f1a
|
071a20d2e059a2c3733e004c681d3949cac3c07a
|
refs/heads/master
| 1,692,621,047,417
| 1,691,396,994,000
| 1,691,396,994,000
| 19,366,263
| 18
| 27
|
MIT
| 1,693,989,071,000
| 1,399,006,345,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 684
|
lean
|
/-
Example/test file for the congruence closure procedure described in the paper:
"Congruence Closure for Intensional Type Theory"
Daniel Selsam and Leonardo de Moura
The tactic `by blast` has been configured in this file to use just
the congruence closure procedure using the command
set_option blast.strategy "cc"
-/
open nat
set_option blast.strategy "cc"
constant f (a b : nat) : a > b → nat
constant g : nat → nat
example
(a₁ a₂ b₁ b₂ c d : nat)
(H₁ : a₁ > b₁)
(H₂ : a₂ > b₂) :
a₁ = c → a₂ = c →
b₁ = d → d = b₂ →
g (g (f a₁ b₁ H₁)) = g (g (f a₂ b₂ H₂)) :=
by blast
|
a042f868c06d67e6c9bc4d147ebfb24543cc98e2
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/implicit3.lean
|
6270f578bbf4cf981c598b561e9e467a1db90b30
|
[
"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
| 238
|
lean
|
import Int.
print 10 = 20
variable f : Int -> Int -> Int
variable g : Int -> Int -> Int -> Int
notation 10 _ ++ _ : f
notation 10 _ ++ _ : g
set_option pp::implicit true
set_option pp::notation false
print (10 ++ 20)
print (10 ++ 20) 10
|
f9a076258249cdfd3d2119c92604fe3091fd8641
|
f618aea02cb4104ad34ecf3b9713065cc0d06103
|
/src/field_theory/mv_polynomial.lean
|
1107fe1f94df75925c3b0f12f2b417e20a8b8a3d
|
[
"Apache-2.0"
] |
permissive
|
joehendrix/mathlib
|
84b6603f6be88a7e4d62f5b1b0cbb523bb82b9a5
|
c15eab34ad754f9ecd738525cb8b5a870e834ddc
|
refs/heads/master
| 1,589,606,591,630
| 1,555,946,393,000
| 1,555,946,393,000
| 182,813,854
| 0
| 0
| null | 1,555,946,309,000
| 1,555,946,308,000
| null |
UTF-8
|
Lean
| false
| false
| 6,816
|
lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
Multivariate functions of the form `α^n → α` are isomorphic to multivariate polynomials in
`n` variables.
-/
import linear_algebra.finsupp field_theory.finite
noncomputable theory
local attribute [instance, priority 0] classical.prop_decidable
local attribute [instance, priority 0] nat.cast_coe
open lattice set linear_map submodule
namespace mv_polynomial
variables {α : Type*} {σ : Type*}
variables [discrete_field α] [fintype α] [fintype σ] [decidable_eq σ]
def indicator (a : σ → α) : mv_polynomial σ α :=
finset.univ.prod (λn, 1 - (X n - C (a n))^(fintype.card α - 1))
lemma eval_indicator_apply_eq_one (a : σ → α) :
eval a (indicator a) = 1 :=
have 0 < fintype.card α - 1,
begin
rw [← finite_field.card_units, fintype.card_pos_iff],
exact ⟨1⟩
end,
by simp only [indicator, (finset.prod_hom (eval a)).symm, eval_sub,
is_ring_hom.map_one (eval a), is_semiring_hom.map_pow (eval a), eval_X, eval_C,
sub_self, zero_pow this, sub_zero, finset.prod_const_one]
lemma eval_indicator_apply_eq_zero (a b : σ → α) (h : a ≠ b) :
eval a (indicator b) = 0 :=
have ∃i, a i ≠ b i, by rwa [(≠), function.funext_iff, not_forall] at h,
begin
rcases this with ⟨i, hi⟩,
simp only [indicator, (finset.prod_hom (eval a)).symm, eval_sub,
is_ring_hom.map_one (eval a), is_semiring_hom.map_pow (eval a), eval_X, eval_C,
sub_self, finset.prod_eq_zero_iff],
refine ⟨i, finset.mem_univ _, _⟩,
rw [finite_field.pow_card_sub_one_eq_one, sub_self],
rwa [(≠), sub_eq_zero],
end
lemma degrees_indicator (c : σ → α) :
degrees (indicator c) ≤ finset.univ.sum (λs:σ, add_monoid.smul (fintype.card α - 1) {s}) :=
begin
rw [indicator],
refine le_trans (degrees_prod _ _) (finset.sum_le_sum $ assume s hs, _),
refine le_trans (degrees_sub _ _) _,
rw [degrees_one, ← bot_eq_zero, bot_sup_eq],
refine le_trans (degrees_pow _ _) (add_monoid.smul_le_smul_of_le_right _ _),
refine le_trans (degrees_sub _ _) _,
rw [degrees_C, ← bot_eq_zero, sup_bot_eq],
exact degrees_X _
end
set_option class.instance_max_depth 50
lemma indicator_mem_restrict_degree (c : σ → α) :
indicator c ∈ restrict_degree σ α (fintype.card α - 1) :=
begin
rw [mem_restrict_degree_iff_sup, indicator],
assume n,
refine le_trans (multiset.count_le_of_le _ $ degrees_indicator _) (le_of_eq _),
rw [← finset.sum_hom (multiset.count n)],
simp only [is_add_monoid_hom.map_smul (multiset.count n), multiset.singleton_eq_singleton,
add_monoid.smul_eq_mul, nat.cast_id],
transitivity,
refine finset.sum_eq_single n _ _,
{ assume b hb ne, rw [multiset.count_cons_of_ne ne.symm, multiset.count_zero, mul_zero] },
{ assume h, exact (h $ finset.mem_univ _).elim },
{ rw [multiset.count_cons_self, multiset.count_zero, mul_one] }
end
section
variables (α σ)
def evalₗ : mv_polynomial σ α →ₗ[α] (σ → α) → α :=
⟨ λp e, p.eval e,
assume p q, funext $ assume e, eval_add,
assume a p, funext $ assume e, by rw [smul_eq_C_mul, eval_mul, eval_C]; refl ⟩
end
section
set_option class.instance_max_depth 50
lemma evalₗ_apply (p : mv_polynomial σ α) (e : σ → α) : evalₗ α σ p e = p.eval e :=
rfl
end
lemma map_restrict_dom_evalₗ : (restrict_degree σ α (fintype.card α - 1)).map (evalₗ α σ) = ⊤ :=
begin
refine top_unique (submodule.le_def'.2 $ assume e _, mem_map.2 _),
refine ⟨finset.univ.sum (λn:σ → α, e n • indicator n), _, _⟩,
{ exact sum_mem _ (assume c _, smul_mem _ _ (indicator_mem_restrict_degree _)) },
{ ext n,
simp only [linear_map.map_sum, @pi.finset_sum_apply (σ → α) (λ_, α) _ _ _ _ _,
pi.smul_apply, linear_map.map_smul],
simp only [evalₗ_apply],
transitivity,
refine finset.sum_eq_single n _ _,
{ assume b _ h,
rw [eval_indicator_apply_eq_zero _ _ h.symm, smul_zero] },
{ assume h, exact (h $ finset.mem_univ n).elim },
{ rw [eval_indicator_apply_eq_one, smul_eq_mul, mul_one] } }
end
end mv_polynomial
namespace mv_polynomial
universe u
variables (σ : Type u) (α : Type u) [decidable_eq σ] [fintype σ] [discrete_field α] [fintype α]
def R : Type u := restrict_degree σ α (fintype.card α - 1)
instance R.add_comm_group : add_comm_group (R σ α) := by dunfold R; apply_instance
instance R.vector_space : vector_space α (R σ α) := by dunfold R; apply_instance
set_option class.instance_max_depth 50
lemma dim_R : vector_space.dim α (R σ α) = fintype.card (σ → α) :=
calc vector_space.dim α (R σ α) =
vector_space.dim α (↥{s : σ →₀ ℕ | ∀ (n : σ), s n ≤ fintype.card α - 1} →₀ α) :
linear_equiv.dim_eq
(finsupp.restrict_dom_equiv_finsupp α α {s : σ →₀ ℕ | ∀n:σ, s n ≤ fintype.card α - 1 })
... = cardinal.mk {s : σ →₀ ℕ | ∀ (n : σ), s n ≤ fintype.card α - 1} :
by rw [finsupp.dim_eq, dim_of_field, mul_one]
... = cardinal.mk {s : σ → ℕ | ∀ (n : σ), s n < fintype.card α } :
begin
refine quotient.sound ⟨equiv.subtype_congr finsupp.equiv_fun_on_fintype $ assume f, _⟩,
refine forall_congr (assume n, nat.le_sub_right_iff_add_le _),
exact fintype.card_pos_iff.2 ⟨0⟩
end
... = cardinal.mk (σ → {n // n < fintype.card α}) :
quotient.sound ⟨@equiv.subtype_pi_equiv_pi σ (λ_, ℕ) (λs n, n < fintype.card α)⟩
... = cardinal.mk (σ → fin (fintype.card α)) :
quotient.sound ⟨equiv.arrow_congr (equiv.refl σ) (equiv.fin_equiv_subtype _).symm⟩
... = cardinal.mk (σ → α) :
begin
refine (trunc.induction_on (fintype.equiv_fin α) $ assume (e : α ≃ fin (fintype.card α)), _),
refine quotient.sound ⟨equiv.arrow_congr (equiv.refl σ) e.symm⟩
end
... = fintype.card (σ → α) : cardinal.fintype_card _
def evalᵢ : R σ α →ₗ[α] (σ → α) → α :=
((evalₗ α σ).comp (restrict_degree σ α (fintype.card α - 1)).subtype)
lemma range_evalᵢ : (evalᵢ σ α).range = ⊤ :=
begin
rw [evalᵢ, linear_map.range_comp, range_subtype],
exact map_restrict_dom_evalₗ
end
lemma ker_evalₗ : (evalᵢ σ α).ker = ⊥ :=
begin
refine injective_of_surjective _ _ _ (range_evalᵢ _ _),
{ rw [dim_R], exact cardinal.nat_lt_omega _ },
{ rw [dim_R, dim_fun, dim_of_field, mul_one] }
end
lemma eq_zero_of_eval_eq_zero (p : mv_polynomial σ α)
(h : ∀v:σ → α, p.eval v = 0) (hp : p ∈ restrict_degree σ α (fintype.card α - 1)) :
p = 0 :=
let p' : R σ α := ⟨p, hp⟩ in
have p' ∈ (evalᵢ σ α).ker := by rw [mem_ker]; ext v; exact h v,
show p'.1 = (0 : R σ α).1,
begin
rw [ker_evalₗ, mem_bot] at this,
rw [this]
end
end mv_polynomial
|
7bd49f88521df9b3873ef6e5e1e61586068881f2
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/src/analysis/convex/basic.lean
|
afa93ca3e9711a03c00db8ad95b07332e1f6a9a1
|
[
"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
| 42,036
|
lean
|
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudriashov, Yaël Dillies
-/
import algebra.order.invertible
import algebra.order.module
import linear_algebra.affine_space.midpoint
import linear_algebra.affine_space.affine_subspace
import linear_algebra.ray
import tactic.positivity
/-!
# Convex sets and functions in vector spaces
In a 𝕜-vector space, we define the following objects and properties.
* `segment 𝕜 x y`: Closed segment joining `x` and `y`.
* `open_segment 𝕜 x y`: Open segment joining `x` and `y`.
* `convex 𝕜 s`: A set `s` is convex if for any two points `x y ∈ s` it includes `segment 𝕜 x y`.
* `std_simplex 𝕜 ι`: The standard simplex in `ι → 𝕜` (currently requires `fintype ι`). It is the
intersection of the positive quadrant with the hyperplane `s.sum = 1`.
We also provide various equivalent versions of the definitions above, prove that some specific sets
are convex.
## Notations
We provide the following notation:
* `[x -[𝕜] y] = segment 𝕜 x y` in locale `convex`
## TODO
Generalize all this file to affine spaces.
Should we rename `segment` and `open_segment` to `convex.Icc` and `convex.Ioo`? Should we also
define `clopen_segment`/`convex.Ico`/`convex.Ioc`?
-/
variables {𝕜 E F β : Type*}
open linear_map set
open_locale big_operators classical pointwise
/-! ### Segment -/
section ordered_semiring
variables [ordered_semiring 𝕜] [add_comm_monoid E]
section has_smul
variables (𝕜) [has_smul 𝕜 E]
/-- Segments in a vector space. -/
def segment (x y : E) : set E :=
{z : E | ∃ (a b : 𝕜) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1), a • x + b • y = z}
/-- Open segment in a vector space. Note that `open_segment 𝕜 x x = {x}` instead of being `∅` when
the base semiring has some element between `0` and `1`. -/
def open_segment (x y : E) : set E :=
{z : E | ∃ (a b : 𝕜) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1), a • x + b • y = z}
localized "notation `[` x ` -[` 𝕜 `] ` y `]` := segment 𝕜 x y" in convex
lemma segment_eq_image₂ (x y : E) :
[x -[𝕜] y] = (λ p : 𝕜 × 𝕜, p.1 • x + p.2 • y) '' {p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1} :=
by simp only [segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc]
lemma open_segment_eq_image₂ (x y : E) :
open_segment 𝕜 x y =
(λ p : 𝕜 × 𝕜, p.1 • x + p.2 • y) '' {p | 0 < p.1 ∧ 0 < p.2 ∧ p.1 + p.2 = 1} :=
by simp only [open_segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc]
lemma segment_symm (x y : E) : [x -[𝕜] y] = [y -[𝕜] x] :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩,
λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩
lemma open_segment_symm (x y : E) :
open_segment 𝕜 x y = open_segment 𝕜 y x :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩,
λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩
lemma open_segment_subset_segment (x y : E) :
open_segment 𝕜 x y ⊆ [x -[𝕜] y] :=
λ z ⟨a, b, ha, hb, hab, hz⟩, ⟨a, b, ha.le, hb.le, hab, hz⟩
lemma segment_subset_iff {x y : E} {s : set E} :
[x -[𝕜] y] ⊆ s ↔ ∀ a b : 𝕜, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s :=
⟨λ H a b ha hb hab, H ⟨a, b, ha, hb, hab, rfl⟩,
λ H z ⟨a, b, ha, hb, hab, hz⟩, hz ▸ H a b ha hb hab⟩
lemma open_segment_subset_iff {x y : E} {s : set E} :
open_segment 𝕜 x y ⊆ s ↔ ∀ a b : 𝕜, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s :=
⟨λ H a b ha hb hab, H ⟨a, b, ha, hb, hab, rfl⟩,
λ H z ⟨a, b, ha, hb, hab, hz⟩, hz ▸ H a b ha hb hab⟩
end has_smul
open_locale convex
section mul_action_with_zero
variables (𝕜) [mul_action_with_zero 𝕜 E]
lemma left_mem_segment (x y : E) : x ∈ [x -[𝕜] y] :=
⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩
lemma right_mem_segment (x y : E) : y ∈ [x -[𝕜] y] :=
segment_symm 𝕜 y x ▸ left_mem_segment 𝕜 y x
end mul_action_with_zero
section module
variables (𝕜) [module 𝕜 E] {x y z : E} {s : set E}
@[simp] lemma segment_same (x : E) : [x -[𝕜] x] = {x} :=
set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩,
by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
λ h, mem_singleton_iff.1 h ▸ left_mem_segment 𝕜 z z⟩
lemma insert_endpoints_open_segment (x y : E) :
insert x (insert y (open_segment 𝕜 x y)) = [x -[𝕜] y] :=
begin
simp only [subset_antisymm_iff, insert_subset, left_mem_segment, right_mem_segment,
open_segment_subset_segment, true_and],
rintro z ⟨a, b, ha, hb, hab, rfl⟩,
refine hb.eq_or_gt.imp _ (λ hb', ha.eq_or_gt.imp _ _),
{ rintro rfl,
rw add_zero at hab,
rw [hab, one_smul, zero_smul, add_zero] },
{ rintro rfl,
rw zero_add at hab,
rw [hab, one_smul, zero_smul, zero_add] },
{ exact λ ha', ⟨a, b, ha', hb', hab, rfl⟩ }
end
variables {𝕜}
lemma mem_open_segment_of_ne_left_right (hx : x ≠ z) (hy : y ≠ z) (hz : z ∈ [x -[𝕜] y]) :
z ∈ open_segment 𝕜 x y :=
begin
rw [← insert_endpoints_open_segment] at hz,
exact ((hz.resolve_left hx.symm).resolve_left hy.symm)
end
lemma open_segment_subset_iff_segment_subset (hx : x ∈ s) (hy : y ∈ s) :
open_segment 𝕜 x y ⊆ s ↔ [x -[𝕜] y] ⊆ s :=
by simp only [← insert_endpoints_open_segment, insert_subset, *, true_and]
end module
end ordered_semiring
open_locale convex
section ordered_ring
variables [ordered_ring 𝕜]
section add_comm_group
variables (𝕜) [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F]
section densely_ordered
variables [nontrivial 𝕜] [densely_ordered 𝕜]
@[simp] lemma open_segment_same (x : E) :
open_segment 𝕜 x x = {x} :=
set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩,
by simpa only [← add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
λ (h : z = x), begin
obtain ⟨a, ha₀, ha₁⟩ := densely_ordered.dense (0 : 𝕜) 1 zero_lt_one,
refine ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel'_right _ _, _⟩,
rw [←add_smul, add_sub_cancel'_right, one_smul, h],
end⟩
end densely_ordered
lemma segment_eq_image (x y : E) : [x -[𝕜] y] = (λ θ : 𝕜, (1 - θ) • x + θ • y) '' Icc (0 : 𝕜) 1 :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, hz⟩,
⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩,
λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1-θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩
lemma open_segment_eq_image (x y : E) :
open_segment 𝕜 x y = (λ (θ : 𝕜), (1 - θ) • x + θ • y) '' Ioo (0 : 𝕜) 1 :=
set.ext $ λ z,
⟨λ ⟨a, b, ha, hb, hab, hz⟩,
⟨b, ⟨hb, hab ▸ lt_add_of_pos_left _ ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩,
λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1 - θ, θ, sub_pos.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩
lemma segment_eq_image' (x y : E) :
[x -[𝕜] y] = (λ (θ : 𝕜), x + θ • (y - x)) '' Icc (0 : 𝕜) 1 :=
by { convert segment_eq_image 𝕜 x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel }
lemma open_segment_eq_image' (x y : E) :
open_segment 𝕜 x y = (λ (θ : 𝕜), x + θ • (y - x)) '' Ioo (0 : 𝕜) 1 :=
by { convert open_segment_eq_image 𝕜 x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel }
lemma segment_eq_image_line_map (x y : E) :
[x -[𝕜] y] = affine_map.line_map x y '' Icc (0 : 𝕜) 1 :=
by { convert segment_eq_image 𝕜 x y, ext, exact affine_map.line_map_apply_module _ _ _ }
lemma open_segment_eq_image_line_map (x y : E) :
open_segment 𝕜 x y = affine_map.line_map x y '' Ioo (0 : 𝕜) 1 :=
by { convert open_segment_eq_image 𝕜 x y, ext, exact affine_map.line_map_apply_module _ _ _ }
lemma segment_image (f : E →ₗ[𝕜] F) (a b : E) : f '' [a -[𝕜] b] = [f a -[𝕜] f b] :=
set.ext (λ x, by simp_rw [segment_eq_image, mem_image, exists_exists_and_eq_and, map_add, map_smul])
@[simp] lemma open_segment_image (f : E →ₗ[𝕜] F) (a b : E) :
f '' open_segment 𝕜 a b = open_segment 𝕜 (f a) (f b) :=
set.ext (λ x, by simp_rw [open_segment_eq_image, mem_image, exists_exists_and_eq_and, map_add,
map_smul])
lemma mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b -[𝕜] a + c] ↔ x ∈ [b -[𝕜] c] :=
begin
rw [segment_eq_image', segment_eq_image'],
refine exists_congr (λ θ, and_congr iff.rfl _),
simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj],
end
@[simp] lemma mem_open_segment_translate (a : E) {x b c : E} :
a + x ∈ open_segment 𝕜 (a + b) (a + c) ↔ x ∈ open_segment 𝕜 b c :=
begin
rw [open_segment_eq_image', open_segment_eq_image'],
refine exists_congr (λ θ, and_congr iff.rfl _),
simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj],
end
lemma segment_translate_preimage (a b c : E) : (λ x, a + x) ⁻¹' [a + b -[𝕜] a + c] = [b -[𝕜] c] :=
set.ext $ λ x, mem_segment_translate 𝕜 a
lemma open_segment_translate_preimage (a b c : E) :
(λ x, a + x) ⁻¹' open_segment 𝕜 (a + b) (a + c) = open_segment 𝕜 b c :=
set.ext $ λ x, mem_open_segment_translate 𝕜 a
lemma segment_translate_image (a b c : E) : (λ x, a + x) '' [b -[𝕜] c] = [a + b -[𝕜] a + c] :=
segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ $ add_left_surjective a
lemma open_segment_translate_image (a b c : E) :
(λ x, a + x) '' open_segment 𝕜 b c = open_segment 𝕜 (a + b) (a + c) :=
open_segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ $ add_left_surjective a
end add_comm_group
end ordered_ring
lemma same_ray_of_mem_segment [ordered_comm_ring 𝕜] [add_comm_group E] [module 𝕜 E]
{x y z : E} (h : x ∈ [y -[𝕜] z]) : same_ray 𝕜 (x - y) (z - x) :=
begin
rw segment_eq_image' at h,
rcases h with ⟨θ, ⟨hθ₀, hθ₁⟩, rfl⟩,
simpa only [add_sub_cancel', ← sub_sub, sub_smul, one_smul]
using (same_ray_nonneg_smul_left (z - y) hθ₀).nonneg_smul_right (sub_nonneg.2 hθ₁)
end
section linear_ordered_ring
variables [linear_ordered_ring 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F]
lemma midpoint_mem_segment [invertible (2 : 𝕜)] (x y : E) :
midpoint 𝕜 x y ∈ [x -[𝕜] y] :=
begin
rw segment_eq_image_line_map,
exact ⟨⅟2, ⟨inv_of_nonneg.mpr zero_le_two, inv_of_le_one one_le_two⟩, rfl⟩,
end
lemma mem_segment_sub_add [invertible (2 : 𝕜)] (x y : E) :
x ∈ [x-y -[𝕜] x+y] :=
begin
convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _,
rw midpoint_sub_add
end
lemma mem_segment_add_sub [invertible (2 : 𝕜)] (x y : E) :
x ∈ [x+y -[𝕜] x-y] :=
begin
convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _,
rw midpoint_add_sub
end
@[simp] lemma left_mem_open_segment_iff [densely_ordered 𝕜] [no_zero_smul_divisors 𝕜 E] {x y : E} :
x ∈ open_segment 𝕜 x y ↔ x = y :=
begin
split,
{ rintro ⟨a, b, ha, hb, hab, hx⟩,
refine smul_right_injective _ hb.ne' ((add_right_inj (a • x)).1 _),
rw [hx, ←add_smul, hab, one_smul] },
{ rintro rfl,
rw open_segment_same,
exact mem_singleton _ }
end
@[simp] lemma right_mem_open_segment_iff [densely_ordered 𝕜] [no_zero_smul_divisors 𝕜 E] {x y : E} :
y ∈ open_segment 𝕜 x y ↔ x = y :=
by rw [open_segment_symm, left_mem_open_segment_iff, eq_comm]
end add_comm_group
end linear_ordered_ring
section linear_ordered_field
variables [linear_ordered_field 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F] {x y z : E}
lemma mem_segment_iff_same_ray : x ∈ [y -[𝕜] z] ↔ same_ray 𝕜 (x - y) (z - x) :=
begin
refine ⟨same_ray_of_mem_segment, λ h, _⟩,
rcases h.exists_eq_smul_add with ⟨a, b, ha, hb, hab, hxy, hzx⟩,
rw [add_comm, sub_add_sub_cancel] at hxy hzx,
rw [← mem_segment_translate _ (-x), neg_add_self],
refine ⟨b, a, hb, ha, add_comm a b ▸ hab, _⟩,
rw [← sub_eq_neg_add, ← neg_sub, hxy, ← sub_eq_neg_add, hzx, smul_neg, smul_comm, neg_add_self]
end
lemma mem_segment_iff_div : x ∈ [y -[𝕜] z] ↔
∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x :=
begin
split,
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
use [a, b, ha, hb],
simp * },
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
refine ⟨a / (a + b), b / (a + b), div_nonneg ha hab.le, div_nonneg hb hab.le, _, rfl⟩,
rw [← add_div, div_self hab.ne'] }
end
lemma mem_open_segment_iff_div : x ∈ open_segment 𝕜 y z ↔
∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x :=
begin
split,
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
use [a, b, ha, hb],
rw [hab, div_one, div_one] },
{ rintro ⟨a, b, ha, hb, rfl⟩,
have hab : 0 < a + b := by positivity,
refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, _, rfl⟩,
rw [← add_div, div_self hab.ne'] }
end
end add_comm_group
end linear_ordered_field
/-!
#### Segments in an ordered space
Relates `segment`, `open_segment` and `set.Icc`, `set.Ico`, `set.Ioc`, `set.Ioo`
-/
section ordered_semiring
variables [ordered_semiring 𝕜]
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E]
lemma segment_subset_Icc {x y : E} (h : x ≤ y) : [x -[𝕜] y] ⊆ Icc x y :=
begin
rintro z ⟨a, b, ha, hb, hab, rfl⟩,
split,
calc
x = a • x + b • x :(convex.combo_self hab _).symm
... ≤ a • x + b • y : add_le_add_left (smul_le_smul_of_nonneg h hb) _,
calc
a • x + b • y
≤ a • y + b • y : add_le_add_right (smul_le_smul_of_nonneg h ha) _
... = y : convex.combo_self hab _,
end
end ordered_add_comm_monoid
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E]
lemma open_segment_subset_Ioo {x y : E} (h : x < y) : open_segment 𝕜 x y ⊆ Ioo x y :=
begin
rintro z ⟨a, b, ha, hb, hab, rfl⟩,
split,
calc
x = a • x + b • x : (convex.combo_self hab _).symm
... < a • x + b • y : add_lt_add_left (smul_lt_smul_of_pos h hb) _,
calc
a • x + b • y
< a • y + b • y : add_lt_add_right (smul_lt_smul_of_pos h ha) _
... = y : convex.combo_self hab _,
end
end ordered_cancel_add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E] {𝕜}
lemma segment_subset_interval (x y : E) : [x -[𝕜] y] ⊆ interval x y :=
begin
cases le_total x y,
{ rw interval_of_le h,
exact segment_subset_Icc h },
{ rw [interval_of_ge h, segment_symm],
exact segment_subset_Icc h }
end
lemma convex.min_le_combo (x y : E) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
min x y ≤ a • x + b • y :=
(segment_subset_interval x y ⟨_, _, ha, hb, hab, rfl⟩).1
lemma convex.combo_le_max (x y : E) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
a • x + b • y ≤ max x y :=
(segment_subset_interval x y ⟨_, _, ha, hb, hab, rfl⟩).2
end linear_ordered_add_comm_monoid
end ordered_semiring
section linear_ordered_field
variables [linear_ordered_field 𝕜]
lemma Icc_subset_segment {x y : 𝕜} : Icc x y ⊆ [x -[𝕜] y] :=
begin
rintro z ⟨hxz, hyz⟩,
obtain rfl | h := (hxz.trans hyz).eq_or_lt,
{ rw segment_same,
exact hyz.antisymm hxz },
rw ←sub_nonneg at hxz hyz,
rw ←sub_pos at h,
refine ⟨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, _, _⟩,
{ rw [←add_div, sub_add_sub_cancel, div_self h.ne'] },
{ rw [smul_eq_mul, smul_eq_mul, ←mul_div_right_comm, ←mul_div_right_comm, ←add_div,
div_eq_iff h.ne', add_comm, sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub] }
end
@[simp] lemma segment_eq_Icc {x y : 𝕜} (h : x ≤ y) : [x -[𝕜] y] = Icc x y :=
(segment_subset_Icc h).antisymm Icc_subset_segment
lemma Ioo_subset_open_segment {x y : 𝕜} : Ioo x y ⊆ open_segment 𝕜 x y :=
λ z hz, mem_open_segment_of_ne_left_right hz.1.ne hz.2.ne'
(Icc_subset_segment $ Ioo_subset_Icc_self hz)
@[simp] lemma open_segment_eq_Ioo {x y : 𝕜} (h : x < y) : open_segment 𝕜 x y = Ioo x y :=
(open_segment_subset_Ioo h).antisymm Ioo_subset_open_segment
lemma segment_eq_Icc' (x y : 𝕜) : [x -[𝕜] y] = Icc (min x y) (max x y) :=
begin
cases le_total x y,
{ rw [segment_eq_Icc h, max_eq_right h, min_eq_left h] },
{ rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h] }
end
lemma open_segment_eq_Ioo' {x y : 𝕜} (hxy : x ≠ y) :
open_segment 𝕜 x y = Ioo (min x y) (max x y) :=
begin
cases hxy.lt_or_lt,
{ rw [open_segment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le] },
{ rw [open_segment_symm, open_segment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le] }
end
lemma segment_eq_interval (x y : 𝕜) : [x -[𝕜] y] = interval x y :=
segment_eq_Icc' _ _
/-- A point is in an `Icc` iff it can be expressed as a convex combination of the endpoints. -/
lemma convex.mem_Icc {x y : 𝕜} (h : x ≤ y) {z : 𝕜} :
z ∈ Icc x y ↔ ∃ (a b : 𝕜), 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
rw ←segment_eq_Icc h,
simp_rw [←exists_prop],
refl,
end
/-- A point is in an `Ioo` iff it can be expressed as a strict convex combination of the endpoints.
-/
lemma convex.mem_Ioo {x y : 𝕜} (h : x < y) {z : 𝕜} :
z ∈ Ioo x y ↔ ∃ (a b : 𝕜), 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
rw ←open_segment_eq_Ioo h,
simp_rw [←exists_prop],
refl,
end
/-- A point is in an `Ioc` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
lemma convex.mem_Ioc {x y : 𝕜} (h : x < y) {z : 𝕜} :
z ∈ Ioc x y ↔ ∃ (a b : 𝕜), 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
split,
{ rintro hz,
obtain ⟨a, b, ha, hb, hab, rfl⟩ := (convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz),
obtain rfl | hb' := hb.eq_or_lt,
{ rw add_zero at hab,
rw [hab, one_mul, zero_mul, add_zero] at hz,
exact (hz.1.ne rfl).elim },
{ exact ⟨a, b, ha, hb', hab, rfl⟩ } },
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc] },
{ exact Ioo_subset_Ioc_self ((convex.mem_Ioo h).2 ⟨a, b, ha', hb, hab, rfl⟩) } }
end
/-- A point is in an `Ico` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
lemma convex.mem_Ico {x y : 𝕜} (h : x < y) {z : 𝕜} :
z ∈ Ico x y ↔ ∃ (a b : 𝕜), 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z :=
begin
split,
{ rintro hz,
obtain ⟨a, b, ha, hb, hab, rfl⟩ := (convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz),
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rw [hab, one_mul, zero_mul, zero_add] at hz,
exact (hz.2.ne rfl).elim },
{ exact ⟨a, b, ha', hb, hab, rfl⟩ } },
{ rintro ⟨a, b, ha, hb, hab, rfl⟩,
obtain rfl | hb' := hb.eq_or_lt,
{ rw add_zero at hab,
rwa [hab, one_mul, zero_mul, add_zero, left_mem_Ico] },
{ exact Ioo_subset_Ico_self ((convex.mem_Ioo h).2 ⟨a, b, ha, hb', hab, rfl⟩) } }
end
end linear_ordered_field
/-! ### Convexity of sets -/
section ordered_semiring
variables [ordered_semiring 𝕜]
section add_comm_monoid
variables [add_comm_monoid E] [add_comm_monoid F]
section has_smul
variables (𝕜) [has_smul 𝕜 E] [has_smul 𝕜 F] (s : set E)
/-- Convexity of sets. -/
def convex : Prop :=
∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
a • x + b • y ∈ s
variables {𝕜 s}
lemma convex_iff_segment_subset :
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → [x -[𝕜] y] ⊆ s :=
forall₄_congr $ λ x y hx hy, (segment_subset_iff _).symm
lemma convex.segment_subset (h : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
[x -[𝕜] y] ⊆ s :=
convex_iff_segment_subset.1 h hx hy
lemma convex.open_segment_subset (h : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
open_segment 𝕜 x y ⊆ s :=
(open_segment_subset_segment 𝕜 x y).trans (h.segment_subset hx hy)
/-- Alternative definition of set convexity, in terms of pointwise set operations. -/
lemma convex_iff_pointwise_add_subset :
convex 𝕜 s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s :=
iff.intro
begin
rintro hA a b ha hb hab w ⟨au, bv, ⟨u, hu, rfl⟩, ⟨v, hv, rfl⟩, rfl⟩,
exact hA hu hv ha hb hab
end
(λ h x y hx hy a b ha hb hab,
(h ha hb hab) (set.add_mem_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩))
alias convex_iff_pointwise_add_subset ↔ convex.set_combo_subset _
lemma convex_empty : convex 𝕜 (∅ : set E) :=
λ x y, false.elim
lemma convex_univ : convex 𝕜 (set.univ : set E) := λ _ _ _ _ _ _ _ _ _, trivial
lemma convex.inter {t : set E} (hs : convex 𝕜 s) (ht : convex 𝕜 t) : convex 𝕜 (s ∩ t) :=
λ x y (hx : x ∈ s ∩ t) (hy : y ∈ s ∩ t) a b (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1),
⟨hs hx.left hy.left ha hb hab, ht hx.right hy.right ha hb hab⟩
lemma convex_sInter {S : set (set E)} (h : ∀ s ∈ S, convex 𝕜 s) : convex 𝕜 (⋂₀ S) :=
assume x y hx hy a b ha hb hab s hs,
h s hs (hx s hs) (hy s hs) ha hb hab
lemma convex_Inter {ι : Sort*} {s : ι → set E} (h : ∀ i, convex 𝕜 (s i)) : convex 𝕜 (⋂ i, s i) :=
(sInter_range s) ▸ convex_sInter $ forall_range_iff.2 h
lemma convex_Inter₂ {ι : Sort*} {κ : ι → Sort*} {s : Π i, κ i → set E}
(h : ∀ i j, convex 𝕜 (s i j)) :
convex 𝕜 (⋂ i j, s i j) :=
convex_Inter $ λ i, convex_Inter $ h i
lemma convex.prod {s : set E} {t : set F} (hs : convex 𝕜 s) (ht : convex 𝕜 t) :
convex 𝕜 (s ×ˢ t) :=
begin
intros x y hx hy a b ha hb hab,
apply mem_prod.2,
exact ⟨hs (mem_prod.1 hx).1 (mem_prod.1 hy).1 ha hb hab,
ht (mem_prod.1 hx).2 (mem_prod.1 hy).2 ha hb hab⟩
end
lemma convex_pi {ι : Type*} {E : ι → Type*} [Π i, add_comm_monoid (E i)]
[Π i, has_smul 𝕜 (E i)] {s : set ι} {t : Π i, set (E i)} (ht : ∀ i, convex 𝕜 (t i)) :
convex 𝕜 (s.pi t) :=
λ x y hx hy a b ha hb hab i hi, ht i (hx i hi) (hy i hi) ha hb hab
lemma directed.convex_Union {ι : Sort*} {s : ι → set E} (hdir : directed (⊆) s)
(hc : ∀ ⦃i : ι⦄, convex 𝕜 (s i)) :
convex 𝕜 (⋃ i, s i) :=
begin
rintro x y hx hy a b ha hb hab,
rw mem_Union at ⊢ hx hy,
obtain ⟨i, hx⟩ := hx,
obtain ⟨j, hy⟩ := hy,
obtain ⟨k, hik, hjk⟩ := hdir i j,
exact ⟨k, hc (hik hx) (hjk hy) ha hb hab⟩,
end
lemma directed_on.convex_sUnion {c : set (set E)} (hdir : directed_on (⊆) c)
(hc : ∀ ⦃A : set E⦄, A ∈ c → convex 𝕜 A) :
convex 𝕜 (⋃₀c) :=
begin
rw sUnion_eq_Union,
exact (directed_on_iff_directed.1 hdir).convex_Union (λ A, hc A.2),
end
end has_smul
section module
variables [module 𝕜 E] [module 𝕜 F] {s : set E}
lemma convex_iff_open_segment_subset :
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → open_segment 𝕜 x y ⊆ s :=
convex_iff_segment_subset.trans $ forall₄_congr $ λ x y hx hy,
(open_segment_subset_iff_segment_subset hx hy).symm
lemma convex_iff_forall_pos :
convex 𝕜 s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1
→ a • x + b • y ∈ s :=
convex_iff_open_segment_subset.trans $ forall₄_congr $ λ x y hx hy,
open_segment_subset_iff 𝕜
lemma convex_iff_pairwise_pos :
convex 𝕜 s ↔ s.pairwise (λ x y, ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s) :=
begin
refine convex_iff_forall_pos.trans ⟨λ h x hx y hy _, h hx hy, _⟩,
intros h x y hx hy a b ha hb hab,
obtain rfl | hxy := eq_or_ne x y,
{ rwa convex.combo_self hab },
{ exact h hx hy hxy ha hb hab },
end
protected lemma set.subsingleton.convex {s : set E} (h : s.subsingleton) : convex 𝕜 s :=
convex_iff_pairwise_pos.mpr (h.pairwise _)
lemma convex_singleton (c : E) : convex 𝕜 ({c} : set E) :=
subsingleton_singleton.convex
lemma convex_segment (x y : E) : convex 𝕜 [x -[𝕜] y] :=
begin
rintro p q ⟨ap, bp, hap, hbp, habp, rfl⟩ ⟨aq, bq, haq, hbq, habq, rfl⟩ a b ha hb hab,
refine ⟨a * ap + b * aq, a * bp + b * bq,
add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq),
add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), _, _⟩,
{ rw [add_add_add_comm, ←mul_add, ←mul_add, habp, habq, mul_one, mul_one, hab] },
{ simp_rw [add_smul, mul_smul, smul_add],
exact add_add_add_comm _ _ _ _ }
end
lemma convex_open_segment (a b : E) : convex 𝕜 (open_segment 𝕜 a b) :=
begin
rw convex_iff_open_segment_subset,
rintro p q ⟨ap, bp, hap, hbp, habp, rfl⟩ ⟨aq, bq, haq, hbq, habq, rfl⟩ z ⟨a, b, ha, hb, hab, rfl⟩,
refine ⟨a * ap + b * aq, a * bp + b * bq,
add_pos (mul_pos ha hap) (mul_pos hb haq),
add_pos (mul_pos ha hbp) (mul_pos hb hbq), _, _⟩,
{ rw [add_add_add_comm, ←mul_add, ←mul_add, habp, habq, mul_one, mul_one, hab] },
{ simp_rw [add_smul, mul_smul, smul_add],
exact add_add_add_comm _ _ _ _ }
end
lemma convex.linear_image (hs : convex 𝕜 s) (f : E →ₗ[𝕜] F) : convex 𝕜 (f '' s) :=
begin
intros x y hx hy a b ha hb hab,
obtain ⟨x', hx', rfl⟩ := mem_image_iff_bex.1 hx,
obtain ⟨y', hy', rfl⟩ := mem_image_iff_bex.1 hy,
exact ⟨a • x' + b • y', hs hx' hy' ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩,
end
lemma convex.is_linear_image (hs : convex 𝕜 s) {f : E → F} (hf : is_linear_map 𝕜 f) :
convex 𝕜 (f '' s) :=
hs.linear_image $ hf.mk' f
lemma convex.linear_preimage {s : set F} (hs : convex 𝕜 s) (f : E →ₗ[𝕜] F) :
convex 𝕜 (f ⁻¹' s) :=
begin
intros x y hx hy a b ha hb hab,
rw [mem_preimage, f.map_add, f.map_smul, f.map_smul],
exact hs hx hy ha hb hab,
end
lemma convex.is_linear_preimage {s : set F} (hs : convex 𝕜 s) {f : E → F} (hf : is_linear_map 𝕜 f) :
convex 𝕜 (f ⁻¹' s) :=
hs.linear_preimage $ hf.mk' f
lemma convex.add {t : set E} (hs : convex 𝕜 s) (ht : convex 𝕜 t) : convex 𝕜 (s + t) :=
by { rw ← add_image_prod, exact (hs.prod ht).is_linear_image is_linear_map.is_linear_map_add }
lemma convex.vadd (hs : convex 𝕜 s) (z : E) : convex 𝕜 (z +ᵥ s) :=
by { simp_rw [←image_vadd, vadd_eq_add, ←singleton_add], exact (convex_singleton _).add hs }
lemma convex.translate (hs : convex 𝕜 s) (z : E) : convex 𝕜 ((λ x, z + x) '' s) := hs.vadd _
/-- The translation of a convex set is also convex. -/
lemma convex.translate_preimage_right (hs : convex 𝕜 s) (z : E) : convex 𝕜 ((λ x, z + x) ⁻¹' s) :=
begin
intros x y hx hy a b ha hb hab,
have h := hs hx hy ha hb hab,
rwa [smul_add, smul_add, add_add_add_comm, ←add_smul, hab, one_smul] at h,
end
/-- The translation of a convex set is also convex. -/
lemma convex.translate_preimage_left (hs : convex 𝕜 s) (z : E) : convex 𝕜 ((λ x, x + z) ⁻¹' s) :=
by simpa only [add_comm] using hs.translate_preimage_right z
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid β] [module 𝕜 β] [ordered_smul 𝕜 β]
lemma convex_Iic (r : β) : convex 𝕜 (Iic r) :=
λ x y hx hy a b ha hb hab,
calc
a • x + b • y
≤ a • r + b • r
: add_le_add (smul_le_smul_of_nonneg hx ha) (smul_le_smul_of_nonneg hy hb)
... = r : convex.combo_self hab _
lemma convex_Ici (r : β) : convex 𝕜 (Ici r) := @convex_Iic 𝕜 βᵒᵈ _ _ _ _ r
lemma convex_Icc (r s : β) : convex 𝕜 (Icc r s) :=
Ici_inter_Iic.subst ((convex_Ici r).inter $ convex_Iic s)
lemma convex_halfspace_le {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | f w ≤ r} :=
(convex_Iic r).is_linear_preimage h
lemma convex_halfspace_ge {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | r ≤ f w} :=
(convex_Ici r).is_linear_preimage h
lemma convex_hyperplane {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | f w = r} :=
begin
simp_rw le_antisymm_iff,
exact (convex_halfspace_le h r).inter (convex_halfspace_ge h r),
end
end ordered_add_comm_monoid
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid β] [module 𝕜 β] [ordered_smul 𝕜 β]
lemma convex_Iio (r : β) : convex 𝕜 (Iio r) :=
begin
intros x y hx hy a b ha hb hab,
obtain rfl | ha' := ha.eq_or_lt,
{ rw zero_add at hab,
rwa [zero_smul, zero_add, hab, one_smul] },
rw mem_Iio at hx hy,
calc
a • x + b • y
< a • r + b • r
: add_lt_add_of_lt_of_le (smul_lt_smul_of_pos hx ha') (smul_le_smul_of_nonneg hy.le hb)
... = r : convex.combo_self hab _
end
lemma convex_Ioi (r : β) : convex 𝕜 (Ioi r) := @convex_Iio 𝕜 βᵒᵈ _ _ _ _ r
lemma convex_Ioo (r s : β) : convex 𝕜 (Ioo r s) :=
Ioi_inter_Iio.subst ((convex_Ioi r).inter $ convex_Iio s)
lemma convex_Ico (r s : β) : convex 𝕜 (Ico r s) :=
Ici_inter_Iio.subst ((convex_Ici r).inter $ convex_Iio s)
lemma convex_Ioc (r s : β) : convex 𝕜 (Ioc r s) :=
Ioi_inter_Iic.subst ((convex_Ioi r).inter $ convex_Iic s)
lemma convex_halfspace_lt {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | f w < r} :=
(convex_Iio r).is_linear_preimage h
lemma convex_halfspace_gt {f : E → β} (h : is_linear_map 𝕜 f) (r : β) :
convex 𝕜 {w | r < f w} :=
(convex_Ioi r).is_linear_preimage h
end ordered_cancel_add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid β] [module 𝕜 β] [ordered_smul 𝕜 β]
lemma convex_interval (r s : β) : convex 𝕜 (interval r s) :=
convex_Icc _ _
end linear_ordered_add_comm_monoid
end module
end add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid E] [ordered_add_comm_monoid β] [module 𝕜 E]
[ordered_smul 𝕜 E] {s : set E} {f : E → β}
lemma monotone_on.convex_le (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x ≤ r} :=
λ x y hx hy a b ha hb hab, ⟨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (convex.combo_le_max x y ha hb hab)).trans
(max_rec' _ hx.2 hy.2)⟩
lemma monotone_on.convex_lt (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x < r} :=
λ x y hx hy a b ha hb hab, ⟨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (convex.combo_le_max x y ha hb hab)).trans_lt
(max_rec' _ hx.2 hy.2)⟩
lemma monotone_on.convex_ge (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r ≤ f x} :=
@monotone_on.convex_le 𝕜 Eᵒᵈ βᵒᵈ _ _ _ _ _ _ _ hf.dual hs r
lemma monotone_on.convex_gt (hf : monotone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r < f x} :=
@monotone_on.convex_lt 𝕜 Eᵒᵈ βᵒᵈ _ _ _ _ _ _ _ hf.dual hs r
lemma antitone_on.convex_le (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x ≤ r} :=
@monotone_on.convex_ge 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_lt (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | f x < r} :=
@monotone_on.convex_gt 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_ge (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r ≤ f x} :=
@monotone_on.convex_le 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r
lemma antitone_on.convex_gt (hf : antitone_on f s) (hs : convex 𝕜 s) (r : β) :
convex 𝕜 {x ∈ s | r < f x} :=
@monotone_on.convex_lt 𝕜 E βᵒᵈ _ _ _ _ _ _ _ hf hs r
lemma monotone.convex_le (hf : monotone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma monotone.convex_lt (hf : monotone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma monotone.convex_ge (hf : monotone f ) (r : β) :
convex 𝕜 {x | r ≤ f x} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_ge convex_univ r)
lemma monotone.convex_gt (hf : monotone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.monotone_on univ).convex_le convex_univ r)
lemma antitone.convex_le (hf : antitone f) (r : β) :
convex 𝕜 {x | f x ≤ r} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_le convex_univ r)
lemma antitone.convex_lt (hf : antitone f) (r : β) :
convex 𝕜 {x | f x < r} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_lt convex_univ r)
lemma antitone.convex_ge (hf : antitone f) (r : β) :
convex 𝕜 {x | r ≤ f x} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_ge convex_univ r)
lemma antitone.convex_gt (hf : antitone f) (r : β) :
convex 𝕜 {x | r < f x} :=
set.sep_univ.subst ((hf.antitone_on univ).convex_gt convex_univ r)
end linear_ordered_add_comm_monoid
section add_comm_group
variables [add_comm_group E] [module 𝕜 E] {s t : set E}
lemma convex.combo_eq_vadd {a b : 𝕜} {x y : E} (h : a + b = 1) :
a • x + b • y = b • (y - x) + x :=
calc
a • x + b • y = (b • y - b • x) + (a • x + b • x) : by abel
... = b • (y - x) + x : by rw [smul_sub, convex.combo_self h]
end add_comm_group
end ordered_semiring
section ordered_comm_semiring
variables [ordered_comm_semiring 𝕜]
section add_comm_monoid
variables [add_comm_monoid E] [add_comm_monoid F] [module 𝕜 E] [module 𝕜 F] {s : set E}
lemma convex.smul (hs : convex 𝕜 s) (c : 𝕜) : convex 𝕜 (c • s) :=
hs.linear_image (linear_map.lsmul _ _ c)
lemma convex.smul_preimage (hs : convex 𝕜 s) (c : 𝕜) : convex 𝕜 ((λ z, c • z) ⁻¹' s) :=
hs.linear_preimage (linear_map.lsmul _ _ c)
lemma convex.affinity (hs : convex 𝕜 s) (z : E) (c : 𝕜) : convex 𝕜 ((λ x, z + c • x) '' s) :=
by simpa only [←image_smul, ←image_vadd, image_image] using (hs.smul c).vadd z
end add_comm_monoid
end ordered_comm_semiring
section ordered_ring
variables [ordered_ring 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F] {s t : set E}
lemma convex.add_smul_mem (hs : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ s)
{t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • y ∈ s :=
begin
have h : x + t • y = (1 - t) • x + t • (x + y),
{ rw [smul_add, ←add_assoc, ←add_smul, sub_add_cancel, one_smul] },
rw h,
exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _),
end
lemma convex.smul_mem_of_zero_mem (hs : convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s)
{t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : t • x ∈ s :=
by simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht
lemma convex.add_smul_sub_mem (h : convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s)
{t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • (y - x) ∈ s :=
begin
apply h.segment_subset hx hy,
rw segment_eq_image',
exact mem_image_of_mem _ ht,
end
/-- Affine subspaces are convex. -/
lemma affine_subspace.convex (Q : affine_subspace 𝕜 E) : convex 𝕜 (Q : set E) :=
begin
intros x y hx hy a b ha hb hab,
rw [eq_sub_of_add_eq hab, ← affine_map.line_map_apply_module],
exact affine_map.line_map_mem b hx hy,
end
/--
Applying an affine map to an affine combination of two points yields
an affine combination of the images.
-/
lemma convex.combo_affine_apply {a b : 𝕜} {x y : E} {f : E →ᵃ[𝕜] F} (h : a + b = 1) :
f (a • x + b • y) = a • f x + b • f y :=
begin
simp only [convex.combo_eq_vadd h, ← vsub_eq_sub],
exact f.apply_line_map _ _ _,
end
/-- The preimage of a convex set under an affine map is convex. -/
lemma convex.affine_preimage (f : E →ᵃ[𝕜] F) {s : set F} (hs : convex 𝕜 s) :
convex 𝕜 (f ⁻¹' s) :=
begin
intros x y xs ys a b ha hb hab,
rw [mem_preimage, convex.combo_affine_apply hab],
exact hs xs ys ha hb hab,
end
/-- The image of a convex set under an affine map is convex. -/
lemma convex.affine_image (f : E →ᵃ[𝕜] F) (hs : convex 𝕜 s) : convex 𝕜 (f '' s) :=
begin
rintro x y ⟨x', ⟨hx', hx'f⟩⟩ ⟨y', ⟨hy', hy'f⟩⟩ a b ha hb hab,
refine ⟨a • x' + b • y', ⟨hs hx' hy' ha hb hab, _⟩⟩,
rw [convex.combo_affine_apply hab, hx'f, hy'f]
end
lemma convex.neg (hs : convex 𝕜 s) : convex 𝕜 (-s) :=
hs.is_linear_preimage is_linear_map.is_linear_map_neg
lemma convex.sub (hs : convex 𝕜 s) (ht : convex 𝕜 t) : convex 𝕜 (s - t) :=
by { rw sub_eq_add_neg, exact hs.add ht.neg }
end add_comm_group
end ordered_ring
section linear_ordered_field
variables [linear_ordered_field 𝕜]
section add_comm_group
variables [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F] {s : set E}
/-- Alternative definition of set convexity, using division. -/
lemma convex_iff_div :
convex 𝕜 s ↔ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄,
0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s :=
begin
simp only [convex_iff_segment_subset, subset_def, mem_segment_iff_div],
refine forall₄_congr (λ x y hx hy, ⟨λ H a b ha hb hab, H _ ⟨a, b, ha, hb, hab, rfl⟩, _⟩),
rintro H _ ⟨a, b, ha, hb, hab, rfl⟩,
exact H ha hb hab
end
lemma convex.mem_smul_of_zero_mem (h : convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s)
(hx : x ∈ s) {t : 𝕜} (ht : 1 ≤ t) :
x ∈ t • s :=
begin
rw mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne',
exact h.smul_mem_of_zero_mem zero_mem hx ⟨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one ht⟩,
end
lemma convex.add_smul (h_conv : convex 𝕜 s) {p q : 𝕜} (hp : 0 ≤ p) (hq : 0 ≤ q) :
(p + q) • s = p • s + q • s :=
begin
obtain rfl | hs := s.eq_empty_or_nonempty,
{ simp_rw [smul_set_empty, add_empty] },
obtain rfl | hp' := hp.eq_or_lt,
{ rw [zero_add, zero_smul_set hs, zero_add] },
obtain rfl | hq' := hq.eq_or_lt,
{ rw [add_zero, zero_smul_set hs, add_zero] },
ext,
split,
{ rintro ⟨v, hv, rfl⟩,
exact ⟨p • v, q • v, smul_mem_smul_set hv, smul_mem_smul_set hv, (add_smul _ _ _).symm⟩ },
{ rintro ⟨v₁, v₂, ⟨v₁₁, h₁₂, rfl⟩, ⟨v₂₁, h₂₂, rfl⟩, rfl⟩,
have hpq := add_pos hp' hq',
refine mem_smul_set.2 ⟨_, h_conv h₁₂ h₂₂ _ _
(by rw [←div_self hpq.ne', add_div] : p / (p + q) + q / (p + q) = 1),
by simp only [← mul_smul, smul_add, mul_div_cancel' _ hpq.ne']⟩; positivity }
end
end add_comm_group
end linear_ordered_field
/-!
#### Convex sets in an ordered space
Relates `convex` and `ord_connected`.
-/
section
lemma set.ord_connected.convex_of_chain [ordered_semiring 𝕜] [ordered_add_comm_monoid E]
[module 𝕜 E] [ordered_smul 𝕜 E] {s : set E} (hs : s.ord_connected) (h : is_chain (≤) s) :
convex 𝕜 s :=
begin
refine convex_iff_segment_subset.mpr (λ x y hx hy, _),
obtain hxy | hyx := h.total hx hy,
{ exact (segment_subset_Icc hxy).trans (hs.out hx hy) },
{ rw segment_symm,
exact (segment_subset_Icc hyx).trans (hs.out hy hx) }
end
lemma set.ord_connected.convex [ordered_semiring 𝕜] [linear_ordered_add_comm_monoid E] [module 𝕜 E]
[ordered_smul 𝕜 E] {s : set E} (hs : s.ord_connected) :
convex 𝕜 s :=
hs.convex_of_chain $ is_chain_of_trichotomous s
lemma convex_iff_ord_connected [linear_ordered_field 𝕜] {s : set 𝕜} :
convex 𝕜 s ↔ s.ord_connected :=
begin
simp_rw [convex_iff_segment_subset, segment_eq_interval, ord_connected_iff_interval_subset],
exact forall_congr (λ x, forall_swap)
end
alias convex_iff_ord_connected ↔ convex.ord_connected _
end
/-! #### Convexity of submodules/subspaces -/
section submodule
open submodule
lemma submodule.convex [ordered_semiring 𝕜] [add_comm_monoid E] [module 𝕜 E] (K : submodule 𝕜 E) :
convex 𝕜 (↑K : set E) :=
by { repeat {intro}, refine add_mem (smul_mem _ _ _) (smul_mem _ _ _); assumption }
lemma subspace.convex [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 E] (K : subspace 𝕜 E) :
convex 𝕜 (↑K : set E) :=
K.convex
end submodule
/-! ### Simplex -/
section simplex
variables (𝕜) (ι : Type*) [ordered_semiring 𝕜] [fintype ι]
/-- The standard simplex in the space of functions `ι → 𝕜` is the set of vectors with non-negative
coordinates with total sum `1`. This is the free object in the category of convex spaces. -/
def std_simplex : set (ι → 𝕜) :=
{f | (∀ x, 0 ≤ f x) ∧ ∑ x, f x = 1}
lemma std_simplex_eq_inter :
std_simplex 𝕜 ι = (⋂ x, {f | 0 ≤ f x}) ∩ {f | ∑ x, f x = 1} :=
by { ext f, simp only [std_simplex, set.mem_inter_eq, set.mem_Inter, set.mem_set_of_eq] }
lemma convex_std_simplex : convex 𝕜 (std_simplex 𝕜 ι) :=
begin
refine λ f g hf hg a b ha hb hab, ⟨λ x, _, _⟩,
{ apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1] },
{ erw [finset.sum_add_distrib, ← finset.smul_sum, ← finset.smul_sum, hf.2, hg.2,
smul_eq_mul, smul_eq_mul, mul_one, mul_one],
exact hab }
end
variable {ι}
lemma ite_eq_mem_std_simplex (i : ι) : (λ j, ite (i = j) (1:𝕜) 0) ∈ std_simplex 𝕜 ι :=
⟨λ j, by simp only; split_ifs; norm_num, by rw [finset.sum_ite_eq, if_pos (finset.mem_univ _)]⟩
end simplex
|
2987cc1b98133176f81ee7695b294e68e7bda386
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/1018unknowMVarIssue.lean
|
3b36c85e1ac253e73a55b7de5050c8bd6fce8304
|
[
"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
| 260
|
lean
|
inductive Fam2 : Type → Type → Type 1 where
| any : Fam2 α α
| nat : Nat → Fam2 Nat Nat
set_option pp.rawOnError true
set_option trace.Elab.info true
example (a : α) (x : Fam2 α β) : β :=
match x with
| Fam2.any => _
| Fam2.nat n => n
|
c42194bd2a9bd7f3784be4c590e0731f4e2d3d70
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/omega/int/form_auto.lean
|
2b66c40a87780ecfc1e82ef7028afe03b28bae7d
|
[] |
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,450
|
lean
|
/-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.omega.int.preterm
import Mathlib.PostPort
universes l
namespace Mathlib
/-
Linear integer arithmetic formulas in pre-normalized form.
-/
namespace omega
namespace int
/-- Intermediate shadow syntax for LNA formulas that includes unreified exprs -/
/-- Intermediate shadow syntax for LIA formulas that includes non-canonical terms -/
inductive preform where
| eq : preterm → preterm → preform
| le : preterm → preterm → preform
| not : preform → preform
| or : preform → preform → preform
| and : preform → preform → preform
namespace preform
/-- Evaluate a preform into prop using the valuation v. -/
@[simp] def holds (v : ℕ → ℤ) : preform → Prop := sorry
end preform
/-- univ_close p n := p closed by prepending n universal quantifiers -/
@[simp] def univ_close (p : preform) : (ℕ → ℤ) → ℕ → Prop := sorry
namespace preform
/-- Fresh de Brujin index not used by any variable in argument -/
def fresh_index : preform → ℕ := sorry
/-- All valuations satisfy argument -/
def valid (p : preform) := ∀ (v : ℕ → ℤ), holds v p
/-- There exists some valuation that satisfies argument -/
def sat (p : preform) := ∃ (v : ℕ → ℤ), holds v p
/-- implies p q := under any valuation, q holds if p holds -/
def implies (p : preform) (q : preform) := ∀ (v : ℕ → ℤ), holds v p → holds v q
/-- equiv p q := under any valuation, p holds iff q holds -/
def equiv (p : preform) (q : preform) := ∀ (v : ℕ → ℤ), holds v p ↔ holds v q
theorem sat_of_implies_of_sat {p : preform} {q : preform} : implies p q → sat p → sat q :=
fun (h1 : implies p q) (h2 : sat p) => exists_imp_exists h1 h2
theorem sat_or {p : preform} {q : preform} : sat (or p q) ↔ sat p ∨ sat q := sorry
/-- There does not exist any valuation that satisfies argument -/
def unsat (p : preform) := ¬sat p
def repr : preform → string := sorry
protected instance has_repr : has_repr preform := has_repr.mk repr
end preform
theorem univ_close_of_valid {p : preform} {m : ℕ} {v : ℕ → ℤ} :
preform.valid p → univ_close p v m :=
sorry
theorem valid_of_unsat_not {p : preform} : preform.unsat (preform.not p) → preform.valid p := sorry
end Mathlib
|
a07bee8094dd412969fc8ad1901047945a710209
|
8cb37a089cdb4af3af9d8bf1002b417e407a8e9e
|
/library/init/algebra/order.lean
|
201f6574479278a48a0d4cd24105b90f35a7f188
|
[
"Apache-2.0"
] |
permissive
|
kbuzzard/lean
|
ae3c3db4bb462d750dbf7419b28bafb3ec983ef7
|
ed1788fd674bb8991acffc8fca585ec746711928
|
refs/heads/master
| 1,620,983,366,617
| 1,618,937,600,000
| 1,618,937,600,000
| 359,886,396
| 1
| 0
|
Apache-2.0
| 1,618,936,987,000
| 1,618,936,987,000
| null |
UTF-8
|
Lean
| false
| false
| 9,920
|
lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic init.classical init.meta.name init.algebra.classes
/- Make sure instances defined in this file have lower priority than the ones
defined for concrete structures -/
set_option default_priority 100
set_option old_structure_cmd true
universe u
variables {α : Type u}
set_option auto_param.check_exists false
section preorder
/-!
### Definition of `preorder` and lemmas about types with a `preorder`
-/
/-- A preorder is a reflexive, transitive relation `≤` with `a < b` defined in the obvious way. -/
class preorder (α : Type u) extends has_le α, has_lt α :=
(le_refl : ∀ a : α, a ≤ a)
(le_trans : ∀ a b c : α, a ≤ b → b ≤ c → a ≤ c)
(lt := λ a b, a ≤ b ∧ ¬ b ≤ a)
(lt_iff_le_not_le : ∀ a b : α, a < b ↔ (a ≤ b ∧ ¬ b ≤ a) . order_laws_tac)
variables [preorder α]
/-- The relation `≤` on a preorder is reflexive. -/
@[refl] lemma le_refl : ∀ a : α, a ≤ a :=
preorder.le_refl
/-- The relation `≤` on a preorder is transitive. -/
@[trans] lemma le_trans : ∀ {a b c : α}, a ≤ b → b ≤ c → a ≤ c :=
preorder.le_trans
lemma lt_iff_le_not_le : ∀ {a b : α}, a < b ↔ (a ≤ b ∧ ¬ b ≤ a) :=
preorder.lt_iff_le_not_le
lemma lt_of_le_not_le : ∀ {a b : α}, a ≤ b → ¬ b ≤ a → a < b
| a b hab hba := lt_iff_le_not_le.mpr ⟨hab, hba⟩
lemma le_not_le_of_lt : ∀ {a b : α}, a < b → a ≤ b ∧ ¬ b ≤ a
| a b hab := lt_iff_le_not_le.mp hab
lemma le_of_eq {a b : α} : a = b → a ≤ b :=
λ h, h ▸ le_refl a
@[trans] lemma ge_trans : ∀ {a b c : α}, a ≥ b → b ≥ c → a ≥ c :=
λ a b c h₁ h₂, le_trans h₂ h₁
lemma lt_irrefl : ∀ a : α, ¬ a < a
| a haa := match le_not_le_of_lt haa with
| ⟨h1, h2⟩ := false.rec _ (h2 h1)
end
lemma gt_irrefl : ∀ a : α, ¬ a > a :=
lt_irrefl
@[trans] lemma lt_trans : ∀ {a b c : α}, a < b → b < c → a < c
| a b c hab hbc :=
match le_not_le_of_lt hab, le_not_le_of_lt hbc with
| ⟨hab, hba⟩, ⟨hbc, hcb⟩ := lt_of_le_not_le (le_trans hab hbc) (λ hca, hcb (le_trans hca hab))
end
@[trans] lemma gt_trans : ∀ {a b c : α}, a > b → b > c → a > c :=
λ a b c h₁ h₂, lt_trans h₂ h₁
lemma ne_of_lt {a b : α} (h : a < b) : a ≠ b :=
λ he, absurd h (he ▸ lt_irrefl a)
lemma ne_of_gt {a b : α} (h : b < a) : a ≠ b :=
λ he, absurd h (he ▸ lt_irrefl a)
lemma lt_asymm {a b : α} (h : a < b) : ¬ b < a :=
λ h1 : b < a, lt_irrefl a (lt_trans h h1)
lemma le_of_lt : ∀ {a b : α}, a < b → a ≤ b
| a b hab := (le_not_le_of_lt hab).left
@[trans] lemma lt_of_lt_of_le : ∀ {a b c : α}, a < b → b ≤ c → a < c
| a b c hab hbc :=
let ⟨hab, hba⟩ := le_not_le_of_lt hab in
lt_of_le_not_le (le_trans hab hbc) $ λ hca, hba (le_trans hbc hca)
@[trans] lemma lt_of_le_of_lt : ∀ {a b c : α}, a ≤ b → b < c → a < c
| a b c hab hbc :=
let ⟨hbc, hcb⟩ := le_not_le_of_lt hbc in
lt_of_le_not_le (le_trans hab hbc) $ λ hca, hcb (le_trans hca hab)
@[trans] lemma gt_of_gt_of_ge {a b c : α} (h₁ : a > b) (h₂ : b ≥ c) : a > c :=
lt_of_le_of_lt h₂ h₁
@[trans] lemma gt_of_ge_of_gt {a b c : α} (h₁ : a ≥ b) (h₂ : b > c) : a > c :=
lt_of_lt_of_le h₂ h₁
lemma not_le_of_gt {a b : α} (h : a > b) : ¬ a ≤ b :=
(le_not_le_of_lt h).right
lemma not_lt_of_ge {a b : α} (h : a ≥ b) : ¬ a < b :=
λ hab, not_le_of_gt hab h
lemma le_of_lt_or_eq : ∀ {a b : α}, (a < b ∨ a = b) → a ≤ b
| a b (or.inl hab) := le_of_lt hab
| a b (or.inr hab) := hab ▸ le_refl _
lemma le_of_eq_or_lt {a b : α} (h : a = b ∨ a < b) : a ≤ b :=
or.elim h le_of_eq le_of_lt
instance decidable_lt_of_decidable_le [decidable_rel ((≤) : α → α → Prop)] :
decidable_rel ((<) : α → α → Prop)
| a b :=
if hab : a ≤ b then
if hba : b ≤ a then
is_false $ λ hab', not_le_of_gt hab' hba
else
is_true $ lt_of_le_not_le hab hba
else
is_false $ λ hab', hab (le_of_lt hab')
end preorder
section partial_order
/-!
### Definition of `partial_order` and lemmas about types with a partial order
-/
/-- A partial order is a reflexive, transitive, antisymmetric relation `≤`. -/
class partial_order (α : Type u) extends preorder α :=
(le_antisymm : ∀ a b : α, a ≤ b → b ≤ a → a = b)
variables [partial_order α]
lemma le_antisymm : ∀ {a b : α}, a ≤ b → b ≤ a → a = b :=
partial_order.le_antisymm
lemma le_antisymm_iff {a b : α} : a = b ↔ a ≤ b ∧ b ≤ a :=
⟨λe, ⟨le_of_eq e, le_of_eq e.symm⟩, λ⟨h1, h2⟩, le_antisymm h1 h2⟩
lemma lt_of_le_of_ne {a b : α} : a ≤ b → a ≠ b → a < b :=
λ h₁ h₂, lt_of_le_not_le h₁ $ mt (le_antisymm h₁) h₂
instance decidable_eq_of_decidable_le [decidable_rel ((≤) : α → α → Prop)] :
decidable_eq α
| a b :=
if hab : a ≤ b then
if hba : b ≤ a then
is_true (le_antisymm hab hba)
else
is_false (λ heq, hba (heq ▸ le_refl _))
else
is_false (λ heq, hab (heq ▸ le_refl _))
namespace decidable
variables [@decidable_rel α (≤)]
lemma lt_or_eq_of_le {a b : α} (hab : a ≤ b) : a < b ∨ a = b :=
if hba : b ≤ a then or.inr (le_antisymm hab hba)
else or.inl (lt_of_le_not_le hab hba)
lemma eq_or_lt_of_le {a b : α} (hab : a ≤ b) : a = b ∨ a < b :=
(lt_or_eq_of_le hab).swap
lemma le_iff_lt_or_eq {a b : α} : a ≤ b ↔ a < b ∨ a = b :=
⟨lt_or_eq_of_le, le_of_lt_or_eq⟩
end decidable
local attribute [instance] classical.prop_decidable
lemma lt_or_eq_of_le {a b : α} : a ≤ b → a < b ∨ a = b := decidable.lt_or_eq_of_le
lemma le_iff_lt_or_eq {a b : α} : a ≤ b ↔ a < b ∨ a = b := decidable.le_iff_lt_or_eq
end partial_order
section linear_order
/-!
### Definition of `linear_order` and lemmas about types with a linear order
-/
/-- A linear order is reflexive, transitive, antisymmetric and total relation `≤`.
We assume that every linear ordered type has decidable `(≤)`, `(<)`, and `(=)`. -/
class linear_order (α : Type u) extends partial_order α :=
(le_total : ∀ a b : α, a ≤ b ∨ b ≤ a)
(decidable_le : decidable_rel (≤))
(decidable_eq : decidable_eq α := @decidable_eq_of_decidable_le _ _ decidable_le)
(decidable_lt : decidable_rel ((<) : α → α → Prop) :=
@decidable_lt_of_decidable_le _ _ decidable_le)
variables [linear_order α]
local attribute [instance] linear_order.decidable_le
lemma le_total : ∀ a b : α, a ≤ b ∨ b ≤ a :=
linear_order.le_total
lemma le_of_not_ge {a b : α} : ¬ a ≥ b → a ≤ b :=
or.resolve_left (le_total b a)
lemma le_of_not_le {a b : α} : ¬ a ≤ b → b ≤ a :=
or.resolve_left (le_total a b)
lemma not_lt_of_gt {a b : α} (h : a > b) : ¬ a < b :=
lt_asymm h
lemma lt_trichotomy (a b : α) : a < b ∨ a = b ∨ b < a :=
or.elim (le_total a b)
(λ h : a ≤ b, or.elim (decidable.lt_or_eq_of_le h)
(λ h : a < b, or.inl h)
(λ h : a = b, or.inr (or.inl h)))
(λ h : b ≤ a, or.elim (decidable.lt_or_eq_of_le h)
(λ h : b < a, or.inr (or.inr h))
(λ h : b = a, or.inr (or.inl h.symm)))
lemma le_of_not_lt {a b : α} (h : ¬ b < a) : a ≤ b :=
match lt_trichotomy a b with
| or.inl hlt := le_of_lt hlt
| or.inr (or.inl heq) := heq ▸ le_refl a
| or.inr (or.inr hgt) := absurd hgt h
end
lemma le_of_not_gt {a b : α} : ¬ a > b → a ≤ b := le_of_not_lt
lemma lt_of_not_ge {a b : α} (h : ¬ a ≥ b) : a < b :=
lt_of_le_not_le ((le_total _ _).resolve_right h) h
lemma lt_or_le (a b : α) : a < b ∨ b ≤ a :=
if hba : b ≤ a then or.inr hba else or.inl $ lt_of_not_ge hba
lemma le_or_lt (a b : α) : a ≤ b ∨ b < a :=
(lt_or_le b a).swap
lemma lt_or_ge : ∀ (a b : α), a < b ∨ a ≥ b := lt_or_le
lemma le_or_gt : ∀ (a b : α), a ≤ b ∨ a > b := le_or_lt
lemma lt_or_gt_of_ne {a b : α} (h : a ≠ b) : a < b ∨ a > b :=
match lt_trichotomy a b with
| or.inl hlt := or.inl hlt
| or.inr (or.inl heq) := absurd heq h
| or.inr (or.inr hgt) := or.inr hgt
end
lemma ne_iff_lt_or_gt {a b : α} : a ≠ b ↔ a < b ∨ a > b :=
⟨lt_or_gt_of_ne, λo, or.elim o ne_of_lt ne_of_gt⟩
lemma lt_iff_not_ge (x y : α) : x < y ↔ ¬ x ≥ y :=
⟨not_le_of_gt, lt_of_not_ge⟩
@[simp] lemma not_lt {a b : α} : ¬ a < b ↔ b ≤ a := ⟨le_of_not_gt, not_lt_of_ge⟩
@[simp] lemma not_le {a b : α} : ¬ a ≤ b ↔ b < a := (lt_iff_not_ge _ _).symm
instance (a b : α) : decidable (a < b) :=
linear_order.decidable_lt a b
instance (a b : α) : decidable (a ≤ b) :=
linear_order.decidable_le a b
instance (a b : α) : decidable (a = b) :=
linear_order.decidable_eq a b
lemma eq_or_lt_of_not_lt {a b : α} (h : ¬ a < b) : a = b ∨ b < a :=
if h₁ : a = b then or.inl h₁
else or.inr (lt_of_not_ge (λ hge, h (lt_of_le_of_ne hge h₁)))
instance : is_total_preorder α (≤) :=
{trans := @le_trans _ _, total := le_total}
/- TODO(Leo): decide whether we should keep this instance or not -/
instance is_strict_weak_order_of_linear_order : is_strict_weak_order α (<) :=
is_strict_weak_order_of_is_total_preorder lt_iff_not_ge
/- TODO(Leo): decide whether we should keep this instance or not -/
instance is_strict_total_order_of_linear_order : is_strict_total_order α (<) :=
{ trichotomous := lt_trichotomy }
/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order. -/
def lt_by_cases (x y : α) {P : Sort*}
(h₁ : x < y → P) (h₂ : x = y → P) (h₃ : y < x → P) : P :=
if h : x < y then h₁ h else
if h' : y < x then h₃ h' else
h₂ (le_antisymm (le_of_not_gt h') (le_of_not_gt h))
lemma le_imp_le_of_lt_imp_lt {β} [preorder α] [linear_order β]
{a b : α} {c d : β} (H : d < c → b < a) (h : a ≤ b) : c ≤ d :=
le_of_not_lt $ λ h', not_le_of_gt (H h') h
end linear_order
|
0441dee1c20707e0c652e51db81cd054be4b8d69
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/topology/algebra/ordered/monotone_convergence.lean
|
7a9beeb36bb25df0fc3923572a04a00433fc0201
|
[
"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
| 12,916
|
lean
|
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, Yury Kudryashov
-/
import topology.algebra.ordered.basic
/-!
# Bounded monotone sequences converge
In this file we prove a few theorems of the form “if the range of a monotone function `f : ι → α`
admits a least upper bound `a`, then `f x` tends to `a` as `x → ∞`”, as well as version of this
statement for (conditionally) complete lattices that use `⨆ x, f x` instead of `is_lub`.
These theorems work for linear orders with order topologies as well as their products (both in terms
of `prod` and in terms of function types). In order to reduce code duplication, we introduce two
typeclasses (one for the property formulated above and one for the dual property), prove theorems
assuming one of these typeclasses, and provide instances for linear orders and their products.
We also prove some "inverse" results: if `f n` is a monotone sequence and `a` is its limit,
then `f n ≤ a` for all `n`.
## Tags
monotone convergence
-/
open filter set function
open_locale filter topological_space classical
variables {α β : Type*}
/-- We say that `α` is a `Sup_convergence_class` if the following holds. Let `f : ι → α` be a
monotone function, let `a : α` be a least upper bound of `set.range f`. Then `f x` tends to `𝓝 a` as
`x → ∞` (formally, at the filter `filter.at_top`). We require this for `ι = (s : set α)`, `f = coe`
in the definition, then prove it for any `f` in `tendsto_at_top_is_lub`.
This property holds for linear orders with order topology as well as their products. -/
class Sup_convergence_class (α : Type*) [preorder α] [topological_space α] : Prop :=
(tendsto_coe_at_top_is_lub : ∀ (a : α) (s : set α), is_lub s a → tendsto (coe : s → α) at_top (𝓝 a))
/-- We say that `α` is an `Inf_convergence_class` if the following holds. Let `f : ι → α` be a
monotone function, let `a : α` be a greatest lower bound of `set.range f`. Then `f x` tends to `𝓝 a`
as `x → -∞` (formally, at the filter `filter.at_bot`). We require this for `ι = (s : set α)`,
`f = coe` in the definition, then prove it for any `f` in `tendsto_at_bot_is_glb`.
This property holds for linear orders with order topology as well as their products. -/
class Inf_convergence_class (α : Type*) [preorder α] [topological_space α] : Prop :=
(tendsto_coe_at_bot_is_glb : ∀ (a : α) (s : set α), is_glb s a → tendsto (coe : s → α) at_bot (𝓝 a))
instance order_dual.Sup_convergence_class [preorder α] [topological_space α]
[Inf_convergence_class α] : Sup_convergence_class (order_dual α) :=
⟨‹Inf_convergence_class α›.1⟩
instance order_dual.Inf_convergence_class [preorder α] [topological_space α]
[Sup_convergence_class α] : Inf_convergence_class (order_dual α) :=
⟨‹Sup_convergence_class α›.1⟩
@[priority 100] -- see Note [lower instance priority]
instance linear_order.Sup_convergence_class [topological_space α] [linear_order α]
[order_topology α] : Sup_convergence_class α :=
begin
refine ⟨λ a s ha, tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩⟩,
{ rcases ha.exists_between hb with ⟨c, hcs, bc, bca⟩,
lift c to s using hcs,
refine (eventually_ge_at_top c).mono (λ x hx, bc.trans_le hx) },
{ exact eventually_of_forall (λ x, (ha.1 x.2).trans_lt hb) }
end
@[priority 100] -- see Note [lower instance priority]
instance linear_order.Inf_convergence_class [topological_space α] [linear_order α]
[order_topology α] : Inf_convergence_class α :=
show Inf_convergence_class (order_dual $ order_dual α), from order_dual.Inf_convergence_class
section
variables {ι : Type*} [preorder ι] [topological_space α]
section is_lub
variables [preorder α] [Sup_convergence_class α] {f : ι → α} {a : α}
lemma tendsto_at_top_is_lub (h_mono : monotone f) (ha : is_lub (set.range f) a) :
tendsto f at_top (𝓝 a) :=
begin
suffices : tendsto (range_factorization f) at_top at_top,
from (Sup_convergence_class.tendsto_coe_at_top_is_lub _ _ ha).comp this,
exact h_mono.range_factorization.tendsto_at_top_at_top (λ b, b.2.imp $ λ a ha, ha.ge)
end
lemma tendsto_at_bot_is_lub (h_anti : antitone f)
(ha : is_lub (set.range f) a) : tendsto f at_bot (𝓝 a) :=
@tendsto_at_top_is_lub α (order_dual ι) _ _ _ _ f a h_anti.dual ha
end is_lub
section is_glb
variables [preorder α] [Inf_convergence_class α] {f : ι → α} {a : α}
lemma tendsto_at_bot_is_glb (h_mono : monotone f) (ha : is_glb (set.range f) a) :
tendsto f at_bot (𝓝 a) :=
@tendsto_at_top_is_lub (order_dual α) (order_dual ι) _ _ _ _ f a h_mono.dual ha
lemma tendsto_at_top_is_glb (h_anti : antitone f)
(ha : is_glb (set.range f) a) :
tendsto f at_top (𝓝 a) :=
@tendsto_at_top_is_lub (order_dual α) ι _ _ _ _ f a h_anti ha
end is_glb
section csupr
variables [conditionally_complete_lattice α] [Sup_convergence_class α] {f : ι → α} {a : α}
lemma tendsto_at_top_csupr (h_mono : monotone f) (hbdd : bdd_above $ range f) :
tendsto f at_top (𝓝 (⨆i, f i)) :=
begin
casesI is_empty_or_nonempty ι,
exacts [tendsto_of_is_empty, tendsto_at_top_is_lub h_mono (is_lub_csupr hbdd)]
end
lemma tendsto_at_bot_csupr (h_anti : antitone f)
(hbdd : bdd_above $ range f) :
tendsto f at_bot (𝓝 (⨆i, f i)) :=
@tendsto_at_top_csupr α (order_dual ι) _ _ _ _ _ h_anti.dual hbdd
end csupr
section cinfi
variables [conditionally_complete_lattice α] [Inf_convergence_class α] {f : ι → α} {a : α}
lemma tendsto_at_bot_cinfi (h_mono : monotone f) (hbdd : bdd_below $ range f) :
tendsto f at_bot (𝓝 (⨅i, f i)) :=
@tendsto_at_top_csupr (order_dual α) (order_dual ι) _ _ _ _ _ h_mono.dual hbdd
lemma tendsto_at_top_cinfi (h_anti : antitone f)
(hbdd : bdd_below $ range f) :
tendsto f at_top (𝓝 (⨅i, f i)) :=
@tendsto_at_top_csupr (order_dual α) ι _ _ _ _ _ h_anti hbdd
end cinfi
section supr
variables [complete_lattice α] [Sup_convergence_class α] {f : ι → α} {a : α}
lemma tendsto_at_top_supr (h_mono : monotone f) : tendsto f at_top (𝓝 (⨆i, f i)) :=
tendsto_at_top_csupr h_mono (order_top.bdd_above _)
lemma tendsto_at_bot_supr (h_anti : antitone f) :
tendsto f at_bot (𝓝 (⨆i, f i)) :=
tendsto_at_bot_csupr h_anti (order_top.bdd_above _)
end supr
section infi
variables [complete_lattice α] [Inf_convergence_class α] {f : ι → α} {a : α}
lemma tendsto_at_bot_infi (h_mono : monotone f) : tendsto f at_bot (𝓝 (⨅i, f i)) :=
tendsto_at_bot_cinfi h_mono (order_bot.bdd_below _)
lemma tendsto_at_top_infi (h_anti : antitone f) :
tendsto f at_top (𝓝 (⨅i, f i)) :=
tendsto_at_top_cinfi h_anti (order_bot.bdd_below _)
end infi
end
instance [preorder α] [preorder β] [topological_space α] [topological_space β]
[Sup_convergence_class α] [Sup_convergence_class β] : Sup_convergence_class (α × β) :=
begin
constructor,
rintro ⟨a, b⟩ s h,
rw [is_lub_prod, ← range_restrict, ← range_restrict] at h,
have A : tendsto (λ x : s, (x : α × β).1) at_top (𝓝 a),
from tendsto_at_top_is_lub (monotone_fst.restrict s) h.1,
have B : tendsto (λ x : s, (x : α × β).2) at_top (𝓝 b),
from tendsto_at_top_is_lub (monotone_snd.restrict s) h.2,
convert A.prod_mk_nhds B,
ext1 ⟨⟨x, y⟩, h⟩, refl
end
instance [preorder α] [preorder β] [topological_space α] [topological_space β]
[Inf_convergence_class α] [Inf_convergence_class β] : Inf_convergence_class (α × β) :=
show Inf_convergence_class (order_dual $ (order_dual α × order_dual β)),
from order_dual.Inf_convergence_class
instance {ι : Type*} {α : ι → Type*} [Π i, preorder (α i)] [Π i, topological_space (α i)]
[Π i, Sup_convergence_class (α i)] : Sup_convergence_class (Π i, α i) :=
begin
refine ⟨λ f s h, _⟩,
simp only [is_lub_pi, ← range_restrict] at h,
exact tendsto_pi.2 (λ i, tendsto_at_top_is_lub ((monotone_eval _).restrict _) (h i))
end
instance {ι : Type*} {α : ι → Type*} [Π i, preorder (α i)] [Π i, topological_space (α i)]
[Π i, Inf_convergence_class (α i)] : Inf_convergence_class (Π i, α i) :=
show Inf_convergence_class (order_dual $ Π i, order_dual (α i)),
from order_dual.Inf_convergence_class
instance pi.Sup_convergence_class' {ι : Type*} [preorder α] [topological_space α]
[Sup_convergence_class α] : Sup_convergence_class (ι → α) :=
pi.Sup_convergence_class
instance pi.Inf_convergence_class' {ι : Type*} [preorder α] [topological_space α]
[Inf_convergence_class α] : Inf_convergence_class (ι → α) :=
pi.Inf_convergence_class
lemma tendsto_of_monotone {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) :
tendsto f at_top at_top ∨ (∃ l, tendsto f at_top (𝓝 l)) :=
if H : bdd_above (range f) then or.inr ⟨_, tendsto_at_top_csupr h_mono H⟩
else or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H
lemma tendsto_iff_tendsto_subseq_of_monotone {ι₁ ι₂ α : Type*} [semilattice_sup ι₁] [preorder ι₂]
[nonempty ι₁] [topological_space α] [conditionally_complete_linear_order α] [order_topology α]
[no_top_order α] {f : ι₂ → α} {φ : ι₁ → ι₂} {l : α} (hf : monotone f)
(hg : tendsto φ at_top at_top) :
tendsto f at_top (𝓝 l) ↔ tendsto (f ∘ φ) at_top (𝓝 l) :=
begin
split; intro h,
{ exact h.comp hg },
{ rcases tendsto_of_monotone hf with h' | ⟨l', hl'⟩,
{ exact (not_tendsto_at_top_of_tendsto_nhds h (h'.comp hg)).elim },
{ rwa tendsto_nhds_unique h (hl'.comp hg) } }
end
/-! The next family of results, such as `is_lub_of_tendsto` and `supr_eq_of_tendsto`, are converses
to the standard fact that bounded monotone functions converge. They state, that if a monotone
function `f` tends to `a` along `at_top`, then that value `a` is a least upper bound for the range
of `f`.
Related theorems above (`is_lub.is_lub_of_tendsto`, `is_glb.is_glb_of_tendsto` etc) cover the case
when `f x` tends to `a` as `x` tends to some point `b` in the domain. -/
lemma monotone.ge_of_tendsto {α β : Type*} [topological_space α] [preorder α]
[order_closed_topology α] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f)
(ha : tendsto f at_top (𝓝 a)) (b : β) :
f b ≤ a :=
begin
haveI : nonempty β := nonempty.intro b,
exact ge_of_tendsto ha ((eventually_ge_at_top b).mono (λ _ hxy, hf hxy))
end
lemma monotone.le_of_tendsto {α β : Type*} [topological_space α] [preorder α]
[order_closed_topology α] [semilattice_inf β] {f : β → α} {a : α} (hf : monotone f)
(ha : tendsto f at_bot (𝓝 a)) (b : β) :
a ≤ f b :=
@monotone.ge_of_tendsto (order_dual α) (order_dual β) _ _ _ _ f _ hf.dual ha b
lemma is_lub_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α]
[nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f)
(ha : tendsto f at_top (𝓝 a)) :
is_lub (set.range f) a :=
begin
split,
{ rintros _ ⟨b, rfl⟩,
exact hf.ge_of_tendsto ha b },
{ exact λ _ hb, le_of_tendsto' ha (λ x, hb (set.mem_range_self x)) }
end
lemma is_glb_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α]
[nonempty β] [semilattice_inf β] {f : β → α} {a : α} (hf : monotone f)
(ha : tendsto f at_bot (𝓝 a)) :
is_glb (set.range f) a :=
@is_lub_of_tendsto (order_dual α) (order_dual β) _ _ _ _ _ _ _ hf.dual ha
lemma supr_eq_of_tendsto {α β} [topological_space α] [complete_linear_order α] [order_topology α]
[nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) :
tendsto f at_top (𝓝 a) → supr f = a :=
tendsto_nhds_unique (tendsto_at_top_supr hf)
lemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [order_topology α]
[nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : antitone f) :
tendsto f at_top (𝓝 a) → infi f = a :=
tendsto_nhds_unique (tendsto_at_top_infi hf)
lemma supr_eq_supr_subseq_of_monotone {ι₁ ι₂ α : Type*} [preorder ι₂] [complete_lattice α]
{l : filter ι₁} [l.ne_bot] {f : ι₂ → α} {φ : ι₁ → ι₂} (hf : monotone f)
(hφ : tendsto φ l at_top) :
(⨆ i, f i) = (⨆ i, f (φ i)) :=
le_antisymm
(supr_le_supr2 $ λ i, exists_imp_exists (λ j (hj : i ≤ φ j), hf hj)
(hφ.eventually $ eventually_ge_at_top i).exists)
(supr_le_supr2 $ λ i, ⟨φ i, le_refl _⟩)
lemma infi_eq_infi_subseq_of_monotone {ι₁ ι₂ α : Type*} [preorder ι₂] [complete_lattice α]
{l : filter ι₁} [l.ne_bot] {f : ι₂ → α} {φ : ι₁ → ι₂} (hf : monotone f)
(hφ : tendsto φ l at_bot) :
(⨅ i, f i) = (⨅ i, f (φ i)) :=
supr_eq_supr_subseq_of_monotone hf.dual hφ
|
f36c4aa4e33797c682350fccd9253309c0f2c105
|
969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb
|
/src/data/polynomial/coeff.lean
|
019a9be24390c5a48efad632ed3a70d13936419f
|
[
"Apache-2.0"
] |
permissive
|
SAAluthwela/mathlib
|
62044349d72dd63983a8500214736aa7779634d3
|
83a4b8b990907291421de54a78988c024dc8a552
|
refs/heads/master
| 1,679,433,873,417
| 1,615,998,031,000
| 1,615,998,031,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,550
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.monomial
import data.finset.nat_antidiagonal
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
noncomputable theory
open finsupp finset add_monoid_algebra
open_locale big_operators
namespace polynomial
universes u v
variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
variables [semiring R] {p q r : polynomial R}
section coeff
lemma coeff_one (n : ℕ) : coeff (1 : polynomial R) n = if 0 = n then 1 else 0 :=
coeff_monomial
@[simp]
lemma coeff_add (p q : polynomial R) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := rfl
lemma coeff_sum [semiring S] (n : ℕ) (f : ℕ → R → polynomial S) :
coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) := finsupp.sum_apply
lemma sum_def [add_comm_monoid S] (f : ℕ → R → S) :
p.sum f = ∑ n in p.support, f n (p.coeff n) :=
rfl
@[simp] lemma coeff_smul (p : polynomial R) (r : R) (n : ℕ) :
coeff (r • p) n = r * coeff p n := finsupp.smul_apply _ _ _
@[simp] lemma mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 :=
by simp [support, coeff]
lemma not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 :=
by simp
variable (R)
/-- The nth coefficient, as a linear map. -/
def lcoeff (n : ℕ) : polynomial R →ₗ[R] R :=
finsupp.lapply n
variable {R}
@[simp] lemma lcoeff_apply (n : ℕ) (f : polynomial R) : lcoeff R n f = coeff f n := rfl
@[simp] lemma finset_sum_coeff {ι : Type*} (s : finset ι) (f : ι → polynomial R) (n : ℕ) :
coeff (∑ b in s, f b) n = ∑ b in s, coeff (f b) n :=
(s.sum_hom (λ q : polynomial R, lcoeff R n q)).symm
/-- Decomposes the coefficient of the product `p * q` as a sum
over `nat.antidiagonal`. A version which sums over `range (n + 1)` can be obtained
by using `finset.nat.sum_antidiagonal_eq_sum_range_succ`. -/
lemma coeff_mul (p q : polynomial R) (n : ℕ) :
coeff (p * q) n = ∑ x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 :=
add_monoid_algebra.mul_apply_antidiagonal p q n _ (λ x, nat.mem_antidiagonal)
@[simp] lemma mul_coeff_zero (p q : polynomial R) : coeff (p * q) 0 = coeff p 0 * coeff q 0 :=
by simp [coeff_mul]
lemma coeff_mul_X_zero (p : polynomial R) : coeff (p * X) 0 = 0 :=
by simp
lemma coeff_X_mul_zero (p : polynomial R) : coeff (X * p) 0 = 0 :=
by simp
lemma coeff_C_mul_X (x : R) (k n : ℕ) :
coeff (C x * X^k : polynomial R) n = if n = k then x else 0 :=
by rw [← single_eq_C_mul_X]; simp [monomial, single, eq_comm, coeff]; congr
@[simp] lemma coeff_C_mul (p : polynomial R) : coeff (C a * p) n = a * coeff p n :=
add_monoid_algebra.single_zero_mul_apply p a n
lemma C_mul' (a : R) (f : polynomial R) : C a * f = a • f :=
ext $ λ n, coeff_C_mul f
@[simp] lemma coeff_mul_C (p : polynomial R) (n : ℕ) (a : R) :
coeff (p * C a) n = coeff p n * a :=
add_monoid_algebra.mul_single_zero_apply p a n
lemma coeff_X_pow (k n : ℕ) :
coeff (X^k : polynomial R) n = if n = k then 1 else 0 :=
by { simp only [X_pow_eq_monomial, monomial, single, eq_comm], congr }
@[simp]
lemma coeff_X_pow_self (n : ℕ) :
coeff (X^n : polynomial R) n = 1 :=
by simp [coeff_X_pow]
theorem coeff_mul_X_pow (p : polynomial R) (n d : ℕ) :
coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=
begin
rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one],
{ rintros ⟨i,j⟩ h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,
rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },
{ exact λ h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }
end
lemma coeff_mul_X_pow' (p : polynomial R) (n d : ℕ) :
(p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 :=
begin
split_ifs,
{ rw [←@nat.sub_add_cancel d n h, coeff_mul_X_pow, nat.add_sub_cancel] },
{ refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (λ x hx, _)),
rw [coeff_X_pow, if_neg, mul_zero],
exact ne_of_lt (lt_of_le_of_lt (nat.le_of_add_le_right
(le_of_eq (finset.nat.mem_antidiagonal.mp hx))) (not_le.mp h)) },
end
@[simp] theorem coeff_mul_X (p : polynomial R) (n : ℕ) :
coeff (p * X) (n + 1) = coeff p n :=
by simpa only [pow_one] using coeff_mul_X_pow p 1 n
theorem mul_X_pow_eq_zero {p : polynomial R} {n : ℕ}
(H : p * X ^ n = 0) : p = 0 :=
ext $ λ k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n)
lemma C_mul_X_pow_eq_monomial (c : R) (n : ℕ) : C c * X^n = monomial n c :=
by { ext1, rw [monomial_eq_smul_X, coeff_smul, coeff_C_mul] }
lemma support_mul_X_pow (c : R) (n : ℕ) (H : c ≠ 0) : (C c * X^n).support = singleton n :=
by rw [C_mul_X_pow_eq_monomial, support_monomial n c H]
lemma support_C_mul_X_pow' {c : R} {n : ℕ} : (C c * X^n).support ⊆ singleton n :=
by { rw [C_mul_X_pow_eq_monomial], exact support_monomial' n c }
lemma C_dvd_iff_dvd_coeff (r : R) (φ : polynomial R) :
C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i :=
begin
split,
{ rintros ⟨φ, rfl⟩ c, rw coeff_C_mul, apply dvd_mul_right },
{ intro h,
choose c hc using h,
classical,
let c' : ℕ → R := λ i, if i ∈ φ.support then c i else 0,
let ψ : polynomial R := ∑ i in φ.support, monomial i (c' i),
use ψ,
ext i,
simp only [ψ, c', coeff_C_mul, mem_support_iff, coeff_monomial,
finset_sum_coeff, finset.sum_ite_eq'],
split_ifs with hi hi,
{ rw hc },
{ rw [not_not] at hi, rwa mul_zero } },
end
end coeff
open submodule polynomial set
variables {f : polynomial R} {I : submodule (polynomial R) (polynomial R)}
/-- If the coefficients of a polynomial belong to n ideal contains the submodule span of the
coefficients of a polynomial. -/
lemma span_le_of_coeff_mem_C_inverse (cf : ∀ (i : ℕ), f.coeff i ∈ (C ⁻¹' I.carrier)) :
(span (polynomial R) {g | ∃ i, g = C (f.coeff i)}) ≤ I :=
begin
refine bInter_subset_of_mem _,
rintros _ ⟨i, rfl⟩,
exact (mem_coe _).mpr (cf i),
end
lemma mem_span_C_coeff :
f ∈ span (polynomial R) {g : polynomial R | ∃ i : ℕ, g = (C (coeff f i))} :=
begin
rw [← f.sum_single] {occs := occurrences.pos [1]},
refine sum_mem _ (λ i hi, _),
change monomial i _ ∈ span _ _,
rw [← C_mul_X_pow_eq_monomial, ← X_pow_mul, ← smul_eq_mul],
exact smul_mem _ _ (subset_span ⟨i, rfl⟩),
end
lemma exists_coeff_not_mem_C_inverse :
f ∉ I → ∃ i : ℕ , coeff f i ∉ (C ⁻¹' I.carrier) :=
imp_of_not_imp_not _ _
(λ cf, not_not.mpr ((span_le_of_coeff_mem_C_inverse (not_exists_not.mp cf)) mem_span_C_coeff))
section cast
@[simp] lemma nat_cast_coeff_zero {n : ℕ} {R : Type*} [semiring R] :
(n : polynomial R).coeff 0 = n :=
begin
induction n with n ih,
{ simp, },
{ simp [ih], },
end
@[simp, norm_cast] theorem nat_cast_inj
{m n : ℕ} {R : Type*} [semiring R] [char_zero R] : (↑m : polynomial R) = ↑n ↔ m = n :=
begin
fsplit,
{ intro h,
apply_fun (λ p, p.coeff 0) at h,
simpa using h, },
{ rintro rfl, refl, },
end
@[simp] lemma int_cast_coeff_zero {i : ℤ} {R : Type*} [ring R] :
(i : polynomial R).coeff 0 = i :=
by cases i; simp
@[simp, norm_cast] theorem int_cast_inj
{m n : ℤ} {R : Type*} [ring R] [char_zero R] : (↑m : polynomial R) = ↑n ↔ m = n :=
begin
fsplit,
{ intro h,
apply_fun (λ p, p.coeff 0) at h,
simpa using h, },
{ rintro rfl, refl, },
end
end cast
end polynomial
|
85551a416fddfb4fe90ad249c0901b7a272254d6
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/univ2.lean
|
710088e283c255c2d19ed556ee08cb3dad92e7bc
|
[
"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
| 216
|
lean
|
universe M1 >= 1
universe M2 >= 1
universe Z >= max M1+1 M2+1
print environment
(*
local env = get_environment()
assert(env:get_universe_distance("Z", "M1") == 1)
assert(env:get_universe_distance("Z", "M2") == 1)
*)
|
7f47fdac78001bfc671d4f6a32a531335a67e9d4
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/topology/sheaves/forget.lean
|
60e8e07ec58f390ec68f39d69c0cc709ea840d1d
|
[
"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
| 8,144
|
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 category_theory.limits.preserves.shapes.products
import topology.sheaves.sheaf
/-!
# Checking the sheaf condition on the underlying presheaf of types.
If `G : C ⥤ D` is a functor which reflects isomorphisms and preserves limits
(we assume all limits exist in both `C` and `D`),
then checking the sheaf condition for a presheaf `F : presheaf C X`
is equivalent to checking the sheaf condition for `F ⋙ G`.
The important special case is when
`C` is a concrete category with a forgetful functor
that preserves limits and reflects isomorphisms.
Then to check the sheaf condition it suffices
to check it on the underlying sheaf of types.
## References
* https://stacks.math.columbia.edu/tag/0073
-/
noncomputable theory
open category_theory
open category_theory.limits
open topological_space
open opposite
namespace Top
namespace presheaf
namespace sheaf_condition
open sheaf_condition_equalizer_products
universes v u₁ u₂
variables {C : Type u₁} [category.{v} C] [has_limits C]
variables {D : Type u₂} [category.{v} D] [has_limits D]
variables (G : C ⥤ D) [preserves_limits G]
variables {X : Top.{v}} (F : presheaf C X)
variables {ι : Type v} (U : ι → opens X)
local attribute [reducible] diagram left_res right_res
/--
When `G` preserves limits, the sheaf condition diagram for `F` composed with `G` is
naturally isomorphic to the sheaf condition diagram for `F ⋙ G`.
-/
def diagram_comp_preserves_limits :
diagram F U ⋙ G ≅ diagram (F ⋙ G) U :=
begin
fapply nat_iso.of_components,
rintro ⟨j⟩,
exact (preserves_product.iso _ _),
exact (preserves_product.iso _ _),
rintros ⟨⟩ ⟨⟩ ⟨⟩,
{ ext, simp, dsimp, simp, }, -- non-terminal `simp`, but `squeeze_simp` fails
{ ext,
simp only [limit.lift_π, functor.comp_map, map_lift_pi_comparison, fan.mk_π_app,
preserves_product.iso_hom, parallel_pair_map_left, functor.map_comp,
category.assoc],
dsimp, simp, },
{ ext,
simp only [limit.lift_π, functor.comp_map, parallel_pair_map_right, fan.mk_π_app,
preserves_product.iso_hom, map_lift_pi_comparison, functor.map_comp,
category.assoc],
dsimp, simp, },
{ ext, simp, dsimp, simp, },
end
local attribute [reducible] res
/--
When `G` preserves limits, the image under `G` of the sheaf condition fork for `F`
is the sheaf condition fork for `F ⋙ G`,
postcomposed with the inverse of the natural isomorphism `diagram_comp_preserves_limits`.
-/
def map_cone_fork : G.map_cone (fork F U) ≅
(cones.postcompose (diagram_comp_preserves_limits G F U).inv).obj (fork (F ⋙ G) U) :=
cones.ext (iso.refl _) (λ j,
begin
dsimp, simp [diagram_comp_preserves_limits], cases j; dsimp,
{ rw iso.eq_comp_inv,
ext,
simp, dsimp, simp, },
{ rw iso.eq_comp_inv,
ext,
simp, -- non-terminal `simp`, but `squeeze_simp` fails
dsimp,
simp only [limit.lift_π, fan.mk_π_app, ←G.map_comp, limit.lift_π_assoc, fan.mk_π_app] }
end)
end sheaf_condition
universes v u₁ u₂
open sheaf_condition sheaf_condition_equalizer_products
variables {C : Type u₁} [category.{v} C] {D : Type u₂} [category.{v} D]
variables (G : C ⥤ D)
variables [reflects_isomorphisms G]
variables [has_limits C] [has_limits D] [preserves_limits G]
variables {X : Top.{v}} (F : presheaf C X)
/--
If `G : C ⥤ D` is a functor which reflects isomorphisms and preserves limits
(we assume all limits exist in both `C` and `D`),
then checking the sheaf condition for a presheaf `F : presheaf C X`
is equivalent to checking the sheaf condition for `F ⋙ G`.
The important special case is when
`C` is a concrete category with a forgetful functor
that preserves limits and reflects isomorphisms.
Then to check the sheaf condition it suffices to check it on the underlying sheaf of types.
Another useful example is the forgetful functor `TopCommRing ⥤ Top`.
See <https://stacks.math.columbia.edu/tag/0073>.
In fact we prove a stronger version with arbitrary complete target category.
-/
lemma is_sheaf_iff_is_sheaf_comp :
presheaf.is_sheaf F ↔ presheaf.is_sheaf (F ⋙ G) :=
begin
split,
{ intros S ι U,
-- We have that the sheaf condition fork for `F` is a limit fork,
obtain ⟨t₁⟩ := S U,
-- and since `G` preserves limits, the image under `G` of this fork is a limit fork too.
letI := preserves_smallest_limits_of_preserves_limits G,
have t₂ := @preserves_limit.preserves _ _ _ _ _ _ _ G _ _ t₁,
-- As we established above, that image is just the sheaf condition fork
-- for `F ⋙ G` postcomposed with some natural isomorphism,
have t₃ := is_limit.of_iso_limit t₂ (map_cone_fork G F U),
-- and as postcomposing by a natural isomorphism preserves limit cones,
have t₄ := is_limit.postcompose_inv_equiv _ _ t₃,
-- we have our desired conclusion.
exact ⟨t₄⟩, },
{ intros S ι U,
refine ⟨_⟩,
-- Let `f` be the universal morphism from `F.obj U` to the equalizer
-- of the sheaf condition fork, whatever it is.
-- Our goal is to show that this is an isomorphism.
let f := equalizer.lift _ (w F U),
-- If we can do that,
suffices : is_iso (G.map f),
{ resetI,
-- we have that `f` itself is an isomorphism, since `G` reflects isomorphisms
haveI : is_iso f := is_iso_of_reflects_iso f G,
-- TODO package this up as a result elsewhere:
apply is_limit.of_iso_limit (limit.is_limit _),
apply iso.symm,
fapply cones.ext,
exact (as_iso f),
rintro ⟨_|_⟩; { dsimp [f], simp, }, },
{ -- Returning to the task of shwoing that `G.map f` is an isomorphism,
-- we note that `G.map f` is almost but not quite (see below) a morphism
-- from the sheaf condition cone for `F ⋙ G` to the
-- image under `G` of the equalizer cone for the sheaf condition diagram.
let c := fork (F ⋙ G) U,
obtain ⟨hc⟩ := S U,
let d := G.map_cone (equalizer.fork (left_res F U) (right_res F U)),
letI := preserves_smallest_limits_of_preserves_limits G,
have hd : is_limit d := preserves_limit.preserves (limit.is_limit _),
-- Since both of these are limit cones
-- (`c` by our hypothesis `S`, and `d` because `G` preserves limits),
-- we hope to be able to conclude that `f` is an isomorphism.
-- We say "not quite" above because `c` and `d` don't quite have the same shape:
-- we need to postcompose by the natural isomorphism `diagram_comp_preserves_limits`
-- introduced above.
let d' := (cones.postcompose (diagram_comp_preserves_limits G F U).hom).obj d,
have hd' : is_limit d' :=
(is_limit.postcompose_hom_equiv (diagram_comp_preserves_limits G F U : _) d).symm hd,
-- Now everything works: we verify that `f` really is a morphism between these cones:
let f' : c ⟶ d' :=
fork.mk_hom (G.map f)
begin
dsimp only [c, d, d', f, diagram_comp_preserves_limits, res],
dunfold fork.ι,
ext1 j,
dsimp,
simp only [category.assoc, ←functor.map_comp_assoc, equalizer.lift_ι,
map_lift_pi_comparison_assoc],
dsimp [res], simp,
end,
-- conclude that it is an isomorphism,
-- just because it's a morphism between two limit cones.
haveI : is_iso f' := is_limit.hom_is_iso hc hd' f',
-- A cone morphism is an isomorphism exactly if the morphism between the cone points is,
-- so we're done!
exact is_iso.of_iso ((cones.forget _).map_iso (as_iso f')) }, },
end
/-!
As an example, we now have everything we need to check the sheaf condition
for a presheaf of commutative rings, merely by checking the sheaf condition
for the underlying sheaf of types.
```
import algebra.category.Ring.limits
example (X : Top) (F : presheaf CommRing X) (h : presheaf.is_sheaf (F ⋙ (forget CommRing))) :
F.is_sheaf :=
(is_sheaf_iff_is_sheaf_comp (forget CommRing) F).mpr h
```
-/
end presheaf
end Top
|
6e08df23617f9b9b3b1ece9188d213be715a4da2
|
437dc96105f48409c3981d46fb48e57c9ac3a3e4
|
/src/algebra/big_operators.lean
|
7e9483523ae4e46f61c7249a080a78f4ae73357e
|
[
"Apache-2.0"
] |
permissive
|
dan-c-k/mathlib
|
08efec79bd7481ee6da9cc44c24a653bff4fbe0d
|
96efc220f6225bc7a5ed8349900391a33a38cc56
|
refs/heads/master
| 1,658,082,847,093
| 1,589,013,201,000
| 1,589,013,201,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 52,133
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import data.finset
import data.nat.enat
import tactic.omega
/-!
# Big operators
In this file we define products and sums indexed by finite sets (specifically, `finset`).
## Notation
We introduce the following notation, localized in `big_operators`.
To enable the notation, use `open_locale big_operators`.
Let `s` be a `finset α`, and `f : α → β` a function.
* `∏ x in s, f x` is notation for `finset.prod s f` (assuming `β` is a `comm_monoid`)
* `∑ x in s, f x` is notation for `finset.sum s f` (assuming `β` is an `add_comm_monoid`)
* `∏ x, f x` is notation for `finset.prod finset.univ f`
(assuming `α` is a `fintype` and `β` is a `comm_monoid`)
* `∑ x in s, f x` is notation for `finset.prod finset.univ f`
(assuming `α` is a `fintype` and `β` is an `add_comm_monoid`)
-/
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
theorem directed.finset_le {r : α → α → Prop} [is_trans α r]
{ι} (hι : nonempty ι) {f : ι → α} (D : directed r f) (s : finset ι) :
∃ z, ∀ i ∈ s, r (f i) (f z) :=
show ∃ z, ∀ i ∈ s.1, r (f i) (f z), from
multiset.induction_on s.1 (let ⟨z⟩ := hι in ⟨z, λ _, false.elim⟩) $
λ i s ⟨j, H⟩, let ⟨k, h₁, h₂⟩ := D i j in
⟨k, λ a h, or.cases_on (multiset.mem_cons.1 h)
(λ h, h.symm ▸ h₁)
(λ h, trans (H _ h) h₂)⟩
theorem finset.exists_le {α : Type u} [nonempty α] [directed_order α] (s : finset α) :
∃ M, ∀ i ∈ s, i ≤ M :=
directed.finset_le (by apply_instance) directed_order.directed s
namespace finset
/-- `∏ x in s, f x` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/
@[to_additive "`∑ x in s, f` is the sum of `f x` as `x` ranges over the elements
of the finite set `s`."]
protected def prod [comm_monoid β] (s : finset α) (f : α → β) : β := (s.1.map f).prod
end finset
/-
## Operator precedence of `∏` and `∑`
There is no established mathematical convention
for the operator precedence of big operators like `∏` and `∑`.
We will have to make a choice.
Online discussions, such as https://math.stackexchange.com/q/185538/30839
seem to suggest that `∏` and `∑` should have the same precedence,
and that this should be somewhere between `*` and `+`.
The latter have precedence levels `70` and `65` respectively,
and we therefore choose the level `67`.
In practice, this means that parentheses should be placed as follows:
```lean
∑ k in K, (a k + b k) = ∑ k in K, a k + ∑ k in K, b k →
∏ k in K, a k * b k = (∏ k in K, a k) * (∏ k in K, b k)
```
(Example taken from page 490 of Knuth's *Concrete Mathematics*.)
-/
localized "notation `∑` binders `, ` r:(scoped:67 f, finset.sum finset.univ f) := r" in big_operators
localized "notation `∏` binders `, ` r:(scoped:67 f, finset.prod finset.univ f) := r" in big_operators
localized "notation `∑` binders ` in ` s `, ` r:(scoped:67 f, finset.sum s f) := r" in big_operators
localized "notation `∏` binders ` in ` s `, ` r:(scoped:67 f, finset.prod s f) := r" in big_operators
open_locale big_operators
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
@[to_additive] lemma prod_eq_multiset_prod [comm_monoid β] (s : finset α) (f : α → β) :
∏ x in s, f x = (s.1.map f).prod := rfl
@[to_additive]
theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) : (∏ x in s, f x) = s.fold (*) 1 f := rfl
end finset
@[to_additive]
lemma monoid_hom.map_prod [comm_monoid β] [comm_monoid γ] (g : β →* γ) (f : α → β) (s : finset α) :
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
by simp only [finset.prod_eq_multiset_prod, g.map_multiset_prod, multiset.map_map]
lemma ring_hom.map_list_prod [semiring β] [semiring γ] (f : β →+* γ) (l : list β) :
f l.prod = (l.map f).prod :=
f.to_monoid_hom.map_list_prod l
lemma ring_hom.map_list_sum [semiring β] [semiring γ] (f : β →+* γ) (l : list β) :
f l.sum = (l.map f).sum :=
f.to_add_monoid_hom.map_list_sum l
lemma ring_hom.map_multiset_prod [comm_semiring β] [comm_semiring γ] (f : β →+* γ)
(s : multiset β) :
f s.prod = (s.map f).prod :=
f.to_monoid_hom.map_multiset_prod s
lemma ring_hom.map_multiset_sum [semiring β] [semiring γ] (f : β →+* γ) (s : multiset β) :
f s.sum = (s.map f).sum :=
f.to_add_monoid_hom.map_multiset_sum s
lemma ring_hom.map_prod [comm_semiring β] [comm_semiring γ]
(g : β →+* γ) (f : α → β) (s : finset α) :
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
g.to_monoid_hom.map_prod f s
lemma ring_hom.map_sum [semiring β] [semiring γ]
(g : β →+* γ) (f : α → β) (s : finset α) :
g (∑ x in s, f x) = ∑ x in s, g (f x) :=
g.to_add_monoid_hom.map_sum f s
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
section comm_monoid
variables [comm_monoid β]
@[simp, to_additive]
lemma prod_empty {α : Type u} {f : α → β} : (∏ x in (∅:finset α), f x) = 1 := rfl
@[simp, to_additive]
lemma prod_insert [decidable_eq α] :
a ∉ s → (∏ x in (insert a s), f x) = f a * ∏ x in s, f x := fold_insert
@[simp, to_additive]
lemma prod_singleton : (∏ x in (singleton a), f x) = f a :=
eq.trans fold_singleton $ mul_one _
@[to_additive]
lemma prod_pair [decidable_eq α] {a b : α} (h : a ≠ b) :
(∏ x in ({a, b} : finset α), f x) = f a * f b :=
by simp [prod_insert (not_mem_singleton.2 h.symm), mul_comm]
@[simp, priority 1100] lemma prod_const_one : (∏ x in s, (1 : β)) = 1 :=
by simp only [finset.prod, multiset.map_const, multiset.prod_repeat, one_pow]
@[simp, priority 1100] lemma sum_const_zero {β} {s : finset α} [add_comm_monoid β] :
(∑ x in s, (0 : β)) = 0 :=
@prod_const_one _ (multiplicative β) _ _
attribute [to_additive] prod_const_one
@[simp, to_additive]
lemma prod_image [decidable_eq α] {s : finset γ} {g : γ → α} :
(∀x∈s, ∀y∈s, g x = g y → x = y) → (∏ x in (s.image g), f x) = ∏ x in s, f (g x) :=
fold_image
@[simp, to_additive]
lemma prod_map (s : finset α) (e : α ↪ γ) (f : γ → β) :
(∏ x in (s.map e), f x) = ∏ x in s, f (e x) :=
by rw [finset.prod, finset.map_val, multiset.map_map]; refl
@[congr, to_additive]
lemma prod_congr (h : s₁ = s₂) : (∀x∈s₂, f x = g x) → s₁.prod f = s₂.prod g :=
by rw [h]; exact fold_congr
attribute [congr] finset.sum_congr
@[to_additive]
lemma prod_union_inter [decidable_eq α] :
(∏ x in (s₁ ∪ s₂), f x) * (∏ x in (s₁ ∩ s₂), f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=
fold_union_inter
@[to_additive]
lemma prod_union [decidable_eq α] (h : disjoint s₁ s₂) :
(∏ x in (s₁ ∪ s₂), f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=
by rw [←prod_union_inter, (disjoint_iff_inter_eq_empty.mp h)]; exact (mul_one _).symm
@[to_additive]
lemma prod_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) :
(∏ x in (s₂ \ s₁), f x) * (∏ x in s₁, f x) = (∏ x in s₂, f x) :=
by rw [←prod_union sdiff_disjoint, sdiff_union_of_subset h]
@[simp, to_additive]
lemma prod_sum_elim [decidable_eq (α ⊕ γ)]
(s : finset α) (t : finset γ) (f : α → β) (g : γ → β) :
(s.image sum.inl ∪ t.image sum.inr).prod (sum.elim f g) = (∏ x in s, f x) * (∏ x in t, g x) :=
begin
rw [prod_union, prod_image, prod_image],
{ simp only [sum.elim_inl, sum.elim_inr] },
{ exact λ _ _ _ _, sum.inr.inj },
{ exact λ _ _ _ _, sum.inl.inj },
{ rintros i hi,
erw [finset.mem_inter, finset.mem_image, finset.mem_image] at hi,
rcases hi with ⟨⟨i, hi, rfl⟩, ⟨j, hj, H⟩⟩,
cases H }
end
@[to_additive]
lemma prod_bind [decidable_eq α] {s : finset γ} {t : γ → finset α} :
(∀x∈s, ∀y∈s, x ≠ y → disjoint (t x) (t y)) → (∏ x in (s.bind t), f x) = ∏ x in s, (t x).prod f :=
by haveI := classical.dec_eq γ; exact
finset.induction_on s (λ _, by simp only [bind_empty, prod_empty])
(assume x s hxs ih hd,
have hd' : ∀x∈s, ∀y∈s, x ≠ y → disjoint (t x) (t y),
from assume _ hx _ hy, hd _ (mem_insert_of_mem hx) _ (mem_insert_of_mem hy),
have ∀y∈s, x ≠ y,
from assume _ hy h, by rw [←h] at hy; contradiction,
have ∀y∈s, disjoint (t x) (t y),
from assume _ hy, hd _ (mem_insert_self _ _) _ (mem_insert_of_mem hy) (this _ hy),
have disjoint (t x) (finset.bind s t),
from (disjoint_bind_right _ _ _).mpr this,
by simp only [bind_insert, prod_insert hxs, prod_union this, ih hd'])
@[to_additive]
lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
(∏ x in s.product t, f x) = ∏ x in s, ∏ y in t, f (x, y) :=
begin
haveI := classical.dec_eq α, haveI := classical.dec_eq γ,
rw [product_eq_bind, prod_bind],
{ congr, funext, exact prod_image (λ _ _ _ _ H, (prod.mk.inj H).2) },
simp only [disjoint_iff_ne, mem_image],
rintros _ _ _ _ h ⟨_, _⟩ ⟨_, _, ⟨_, _⟩⟩ ⟨_, _⟩ ⟨_, _, ⟨_, _⟩⟩ _,
apply h, cc
end
@[to_additive]
lemma prod_sigma {σ : α → Type*}
{s : finset α} {t : Πa, finset (σ a)} {f : sigma σ → β} :
(∏ x in s.sigma t, f x) = ∏ a in s, ∏ s in (t a), f ⟨a, s⟩ :=
by haveI := classical.dec_eq α; haveI := (λ a, classical.dec_eq (σ a)); exact
calc (s.sigma t).prod f =
(s.bind (λa, (t a).image (λs, sigma.mk a s))).prod f : by rw sigma_eq_bind
... = s.prod (λa, ((t a).image (λs, sigma.mk a s)).prod f) :
prod_bind $ assume a₁ ha a₂ ha₂ h,
by simp only [disjoint_iff_ne, mem_image];
rintro ⟨_, _⟩ ⟨_, _, _⟩ ⟨_, _⟩ ⟨_, _, _⟩ ⟨_, _⟩; apply h; cc
... = (s.prod $ λa, (t a).prod $ λs, f ⟨a, s⟩) :
prod_congr rfl $ λ _ _, prod_image $ λ _ _ _ _ _, by cc
@[to_additive]
lemma prod_image' [decidable_eq α] {s : finset γ} {g : γ → α} (h : γ → β)
(eq : ∀c∈s, f (g c) = (s.filter (λc', g c' = g c)).prod h) :
(∏ x in s.image g, f x) = ∏ x in s, h x :=
begin
letI := classical.dec_eq γ,
rw [← image_bind_filter_eq s g] {occs := occurrences.pos [2]},
rw [finset.prod_bind],
{ refine finset.prod_congr rfl (assume a ha, _),
rcases finset.mem_image.1 ha with ⟨b, hb, rfl⟩,
exact eq b hb },
assume a₀ _ a₁ _ ne,
refine (disjoint_iff_ne.2 _),
assume c₀ h₀ c₁ h₁,
rcases mem_filter.1 h₀ with ⟨h₀, rfl⟩,
rcases mem_filter.1 h₁ with ⟨h₁, rfl⟩,
exact mt (congr_arg g) ne
end
@[to_additive]
lemma prod_mul_distrib : s.prod (λx, f x * g x) = (∏ x in s, f x) * (∏ x in s, g x) :=
eq.trans (by rw one_mul; refl) fold_op_distrib
@[to_additive]
lemma prod_comm {s : finset γ} {t : finset α} {f : γ → α → β} :
(∏ x in s, ∏ y in t, f x y) = (∏ y in t, ∏ x in s, f x y) :=
begin
classical,
apply finset.induction_on s,
{ simp only [prod_empty, prod_const_one] },
{ intros _ _ H ih,
simp only [prod_insert H, prod_mul_distrib, ih] }
end
@[to_additive]
lemma prod_hom [comm_monoid γ] (s : finset α) {f : α → β} (g : β → γ) [is_monoid_hom g] :
(∏ x in s, g (f x)) = g (∏ x in s, f x) :=
((monoid_hom.of g).map_prod f s).symm
@[to_additive]
lemma prod_hom_rel [comm_monoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : finset α}
(h₁ : r 1 1) (h₂ : ∀a b c, r b c → r (f a * b) (g a * c)) : r (∏ x in s, f x) (∏ x in s, g x) :=
by { delta finset.prod, apply multiset.prod_hom_rel; assumption }
@[to_additive]
lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → f x = 1) : (∏ x in s₁, f x) = ∏ x in s₂, f x :=
by haveI := classical.dec_eq α; exact
have (s₂ \ s₁).prod f = (s₂ \ s₁).prod (λx, 1),
from prod_congr rfl $ by simpa only [mem_sdiff, and_imp],
by rw [←prod_sdiff h]; simp only [this, prod_const_one, one_mul]
-- If we use `[decidable_eq β]` here, some rewrites fail because they find a wrong `decidable`
-- instance first; `{∀x, decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one`
@[to_additive]
lemma prod_filter_ne_one [∀ x, decidable (f x ≠ 1)] :
(∏ x in (s.filter $ λx, f x ≠ 1), f x) = (∏ x in s, f x) :=
prod_subset (filter_subset _) $ λ x,
by { classical, rw [not_imp_comm, mem_filter], exact and.intro }
@[to_additive]
lemma prod_filter (p : α → Prop) [decidable_pred p] (f : α → β) :
(∏ a in s.filter p, f a) = (∏ a in s, if p a then f a else 1) :=
calc (s.filter p).prod f = (s.filter p).prod (λa, if p a then f a else 1) :
prod_congr rfl (assume a h, by rw [if_pos (mem_filter.1 h).2])
... = s.prod (λa, if p a then f a else 1) :
begin
refine prod_subset (filter_subset s) (assume x hs h, _),
rw [mem_filter, not_and] at h,
exact if_neg (h hs)
end
@[to_additive]
lemma prod_eq_single {s : finset α} {f : α → β} (a : α)
(h₀ : ∀b∈s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : (∏ x in s, f x) = f a :=
by haveI := classical.dec_eq α;
from classical.by_cases
(assume : a ∈ s,
calc (∏ x in s, f x) = ({a} : finset α).prod f :
begin
refine (prod_subset _ _).symm,
{ intros _ H, rwa mem_singleton.1 H },
{ simpa only [mem_singleton] }
end
... = f a : prod_singleton)
(assume : a ∉ s,
(prod_congr rfl $ λ b hb, h₀ b hb $ by rintro rfl; cc).trans $
prod_const_one.trans (h₁ this).symm)
@[to_additive] lemma prod_apply_ite {s : finset α}
{p : α → Prop} {hp : decidable_pred p} (f g : α → γ) (h : γ → β) :
(∏ x in s, h (if p x then f x else g x)) =
(∏ x in s.filter p, h (f x)) * (∏ x in s.filter (λ x, ¬ p x), h (g x)) :=
by letI := classical.dec_eq α; exact
calc s.prod (λ x, h (if p x then f x else g x))
= (s.filter p ∪ s.filter (λ x, ¬ p x)).prod (λ x, h (if p x then f x else g x)) :
by rw [filter_union_filter_neg_eq]
... = (s.filter p).prod (λ x, h (if p x then f x else g x)) *
(s.filter (λ x, ¬ p x)).prod (λ x, h (if p x then f x else g x)) :
prod_union (by simp [disjoint_right] {contextual := tt})
... = (s.filter p).prod (λ x, h (f x)) * (s.filter (λ x, ¬ p x)).prod (λ x, h (g x)) :
congr_arg2 _
(prod_congr rfl (by simp {contextual := tt}))
(prod_congr rfl (by simp {contextual := tt}))
@[to_additive] lemma prod_ite {s : finset α}
{p : α → Prop} {hp : decidable_pred p} (f g : α → β) :
(∏ x in s, if p x then f x else g x) =
(s.filter p).prod (λ x, f x) * (s.filter (λ x, ¬ p x)).prod (λ x, g x) :=
by simp [prod_apply_ite _ _ (λ x, x)]
@[simp, to_additive] lemma prod_ite_eq [decidable_eq α] (s : finset α) (a : α) (b : α → β) :
(∏ x in s, (ite (a = x) (b x) 1)) = ite (a ∈ s) (b a) 1 :=
begin
rw ←finset.prod_filter,
split_ifs;
simp only [filter_eq, if_true, if_false, h, prod_empty, prod_singleton, insert_empty_eq_singleton],
end
/--
When a product is taken over a conditional whose condition is an equality test on the index
and whose alternative is 1, then the product's value is either the term at that index or `1`.
The difference with `prod_ite_eq` is that the arguments to `eq` are swapped.
-/
@[simp, to_additive] lemma prod_ite_eq' [decidable_eq α] (s : finset α) (a : α) (b : α → β) :
(∏ x in s, (ite (x = a) (b x) 1)) = ite (a ∈ s) (b a) 1 :=
begin
rw ←prod_ite_eq,
congr, ext x,
by_cases x = a; finish
end
@[to_additive]
lemma prod_attach {f : α → β} : (∏ x in s.attach, f x.val) = (∏ x in s, f x) :=
by haveI := classical.dec_eq α; exact
calc s.attach.prod (λx, f x.val) = ((s.attach).image subtype.val).prod f :
by rw [prod_image]; exact assume x _ y _, subtype.eq
... = _ : by rw [attach_image_val]
@[to_additive]
lemma prod_bij {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Πa∈s, γ) (hi : ∀a ha, i a ha ∈ t) (h : ∀a ha, f a = g (i a ha))
(i_inj : ∀a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀b∈t, ∃a ha, b = i a ha) :
(∏ x in s, f x) = (∏ x in t, g x) :=
congr_arg multiset.prod
(multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi h i_inj i_surj)
@[to_additive]
lemma prod_bij_ne_one {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Πa∈s, f a ≠ 1 → γ) (hi₁ : ∀a h₁ h₂, i a h₁ h₂ ∈ t)
(hi₂ : ∀a₁ a₂ h₁₁ h₁₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(hi₃ : ∀b∈t, g b ≠ 1 → ∃a h₁ h₂, b = i a h₁ h₂)
(h : ∀a h₁ h₂, f a = g (i a h₁ h₂)) :
(∏ x in s, f x) = (∏ x in t, g x) :=
by classical; exact
calc (∏ x in s, f x) = (s.filter $ λx, f x ≠ 1).prod f : prod_filter_ne_one.symm
... = (t.filter $ λx, g x ≠ 1).prod g :
prod_bij (assume a ha, i a (mem_filter.mp ha).1 (mem_filter.mp ha).2)
(assume a ha, (mem_filter.mp ha).elim $ λh₁ h₂, mem_filter.mpr
⟨hi₁ a h₁ h₂, λ hg, h₂ (hg ▸ h a h₁ h₂)⟩)
(assume a ha, (mem_filter.mp ha).elim $ h a)
(assume a₁ a₂ ha₁ ha₂,
(mem_filter.mp ha₁).elim $ λha₁₁ ha₁₂, (mem_filter.mp ha₂).elim $ λha₂₁ ha₂₂, hi₂ a₁ a₂ _ _ _ _)
(assume b hb, (mem_filter.mp hb).elim $ λh₁ h₂,
let ⟨a, ha₁, ha₂, eq⟩ := hi₃ b h₁ h₂ in ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩)
... = (∏ x in t, g x) : prod_filter_ne_one
@[to_additive]
lemma nonempty_of_prod_ne_one (h : (∏ x in s, f x) ≠ 1) : s.nonempty :=
s.eq_empty_or_nonempty.elim (λ H, false.elim $ h $ H.symm ▸ prod_empty) id
@[to_additive]
lemma exists_ne_one_of_prod_ne_one (h : (∏ x in s, f x) ≠ 1) : ∃a∈s, f a ≠ 1 :=
begin
classical,
rw ← prod_filter_ne_one at h,
rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩,
exact ⟨x, (mem_filter.1 hx).1, (mem_filter.1 hx).2⟩
end
lemma sum_range_succ {β} [add_comm_monoid β] (f : ℕ → β) (n : ℕ) :
(∑ x in range (n + 1), f x) = f n + (∑ x in range n, f x) :=
by rw [range_succ, sum_insert not_mem_range_self]
@[to_additive]
lemma prod_range_succ (f : ℕ → β) (n : ℕ) :
(∏ x in range (n + 1), f x) = f n * (∏ x in range n, f x) :=
by rw [range_succ, prod_insert not_mem_range_self]
lemma prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (∏ k in range (n + 1), f k) = (∏ k in range n, f (k+1)) * f 0
| 0 := (prod_range_succ _ _).trans $ mul_comm _ _
| (n + 1) := by rw [prod_range_succ (λ m, f (nat.succ m)), mul_assoc, ← prod_range_succ'];
exact prod_range_succ _ _
/-- A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function reduces to the difference of
the last and first terms when the function we are summing is monotone. -/
lemma sum_range_sub_of_monotone {f : ℕ → ℕ} (h : monotone f) (n : ℕ) :
∑ i in range n, (f (i+1) - f i) = f n - f 0 :=
begin
induction n with n IH, { simp },
rw [finset.sum_range_succ, IH, nat.succ_eq_add_one],
have : f n ≤ f (n+1) := h (nat.le_succ _),
have : f 0 ≤ f n := h (nat.zero_le _),
omega
end
lemma sum_Ico_add {δ : Type*} [add_comm_monoid δ] (f : ℕ → δ) (m n k : ℕ) :
(∑ l in Ico m n, f (k + l)) = (∑ l in Ico (m + k) (n + k), f l) :=
Ico.image_add m n k ▸ eq.symm $ sum_image $ λ x hx y hy h, nat.add_left_cancel h
@[to_additive]
lemma prod_Ico_add (f : ℕ → β) (m n k : ℕ) :
(∏ l in Ico m n, f (k + l)) = (∏ l in Ico (m + k) (n + k), f l) :=
Ico.image_add m n k ▸ eq.symm $ prod_image $ λ x hx y hy h, nat.add_left_cancel h
lemma sum_Ico_succ_top {δ : Type*} [add_comm_monoid δ] {a b : ℕ}
(hab : a ≤ b) (f : ℕ → δ) : (∑ k in Ico a (b + 1), f k) = (∑ k in Ico a b, f k) + f b :=
by rw [Ico.succ_top hab, sum_insert Ico.not_mem_top, add_comm]
@[to_additive]
lemma prod_Ico_succ_top {a b : ℕ} (hab : a ≤ b) (f : ℕ → β) :
(∏ k in Ico a (b + 1), f k) = (∏ k in Ico a b, f k) * f b :=
@sum_Ico_succ_top (additive β) _ _ _ hab _
lemma sum_eq_sum_Ico_succ_bot {δ : Type*} [add_comm_monoid δ] {a b : ℕ}
(hab : a < b) (f : ℕ → δ) : (∑ k in Ico a b, f k) = f a + (∑ k in Ico (a + 1) b, f k) :=
have ha : a ∉ Ico (a + 1) b, by simp,
by rw [← sum_insert ha, Ico.insert_succ_bot hab]
@[to_additive]
lemma prod_eq_prod_Ico_succ_bot {a b : ℕ} (hab : a < b) (f : ℕ → β) :
(∏ k in Ico a b, f k) = f a * (∏ k in Ico (a + 1) b, f k) :=
@sum_eq_sum_Ico_succ_bot (additive β) _ _ _ hab _
@[to_additive]
lemma prod_Ico_consecutive (f : ℕ → β) {m n k : ℕ} (hmn : m ≤ n) (hnk : n ≤ k) :
(∏ i in Ico m n, f i) * (∏ i in Ico n k, f i) = (∏ i in Ico m k, f i) :=
Ico.union_consecutive hmn hnk ▸ eq.symm $ prod_union $ Ico.disjoint_consecutive m n k
@[to_additive]
lemma prod_range_mul_prod_Ico (f : ℕ → β) {m n : ℕ} (h : m ≤ n) :
(∏ k in range m, f k) * (∏ k in Ico m n, f k) = (∏ k in range n, f k) :=
Ico.zero_bot m ▸ Ico.zero_bot n ▸ prod_Ico_consecutive f (nat.zero_le m) h
@[to_additive]
lemma prod_Ico_eq_mul_inv {δ : Type*} [comm_group δ] (f : ℕ → δ) {m n : ℕ} (h : m ≤ n) :
(∏ k in Ico m n, f k) = (∏ k in range n, f k) * (∏ k in range m, f k)⁻¹ :=
eq_mul_inv_iff_mul_eq.2 $ by rw [mul_comm]; exact prod_range_mul_prod_Ico f h
lemma sum_Ico_eq_sub {δ : Type*} [add_comm_group δ] (f : ℕ → δ) {m n : ℕ} (h : m ≤ n) :
(∑ k in Ico m n, f k) = (∑ k in range n, f k) - (∑ k in range m, f k) :=
sum_Ico_eq_add_neg f h
@[to_additive]
lemma prod_Ico_eq_prod_range (f : ℕ → β) (m n : ℕ) :
(∏ k in Ico m n, f k) = (∏ k in range (n - m), f (m + k)) :=
begin
by_cases h : m ≤ n,
{ rw [← Ico.zero_bot, prod_Ico_add, zero_add, nat.sub_add_cancel h] },
{ replace h : n ≤ m := le_of_not_ge h,
rw [Ico.eq_empty_of_le h, nat.sub_eq_zero_of_le h, range_zero, prod_empty, prod_empty] }
end
@[to_additive]
lemma prod_range_zero (f : ℕ → β) :
(∏ k in range 0, f k) = 1 :=
by rw [range_zero, prod_empty]
lemma prod_range_one (f : ℕ → β) :
(∏ k in range 1, f k) = f 0 :=
by { rw [range_one], apply @prod_singleton ℕ β 0 f }
lemma sum_range_one {δ : Type*} [add_comm_monoid δ] (f : ℕ → δ) :
(∑ k in range 1, f k) = f 0 :=
by { rw [range_one], apply @sum_singleton ℕ δ 0 f }
attribute [to_additive finset.sum_range_one] prod_range_one
@[simp] lemma prod_const (b : β) : (∏ x in s, b) = b ^ s.card :=
by haveI := classical.dec_eq α; exact
finset.induction_on s rfl (λ a s has ih,
by rw [prod_insert has, card_insert_of_not_mem has, pow_succ, ih])
lemma prod_pow (s : finset α) (n : ℕ) (f : α → β) :
(∏ x in s, f x ^ n) = (∏ x in s, f x) ^ n :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (by simp [_root_.mul_pow] {contextual := tt})
lemma prod_nat_pow (s : finset α) (n : ℕ) (f : α → ℕ) :
(∏ x in s, f x ^ n) = (∏ x in s, f x) ^ n :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (by simp [nat.mul_pow] {contextual := tt})
-- `to_additive` fails on this lemma, so we prove it manually below
lemma prod_flip {n : ℕ} (f : ℕ → β) :
(∏ r in range (n + 1), f (n - r)) = (∏ k in range (n + 1), f k) :=
begin
induction n with n ih,
{ rw [prod_range_one, prod_range_one] },
{ rw [prod_range_succ', prod_range_succ _ (nat.succ n), mul_comm],
simp [← ih] }
end
@[to_additive]
lemma prod_involution {s : finset α} {f : α → β} :
∀ (g : Π a ∈ s, α)
(h₁ : ∀ a ha, f a * f (g a ha) = 1)
(h₂ : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(h₃ : ∀ a ha, g a ha ∈ s)
(h₄ : ∀ a ha, g (g a ha) (h₃ a ha) = a),
(∏ x in s, f x) = 1 :=
by haveI := classical.dec_eq α;
haveI := classical.dec_eq β; exact
finset.strong_induction_on s
(λ s ih g h₁ h₂ h₃ h₄,
s.eq_empty_or_nonempty.elim (λ hs, hs.symm ▸ rfl)
(λ ⟨x, hx⟩,
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s,
from λ y hy, (mem_of_mem_erase (mem_of_mem_erase hy)),
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y,
from λ x hx y hy h, by rw [← h₄ x hx, ← h₄ y hy]; simp [h],
have ih': (erase (erase s x) (g x hx)).prod f = (1 : β) :=
ih ((s.erase x).erase (g x hx))
⟨subset.trans (erase_subset _ _) (erase_subset _ _),
λ h, not_mem_erase (g x hx) (s.erase x) (h (h₃ x hx))⟩
(λ y hy, g y (hmem y hy))
(λ y hy, h₁ y (hmem y hy))
(λ y hy, h₂ y (hmem y hy))
(λ y hy, mem_erase.2 ⟨λ (h : g y _ = g x hx), by simpa [g_inj h] using hy,
mem_erase.2 ⟨λ (h : g y _ = x),
have y = g x hx, from h₄ y (hmem y hy) ▸ by simp [h],
by simpa [this] using hy, h₃ y (hmem y hy)⟩⟩)
(λ y hy, h₄ y (hmem y hy)),
if hx1 : f x = 1
then ih' ▸ eq.symm (prod_subset hmem
(λ y hy hy₁,
have y = x ∨ y = g x hx, by simp [hy] at hy₁; tauto,
this.elim (λ h, h.symm ▸ hx1)
(λ h, h₁ x hx ▸ h ▸ hx1.symm ▸ (one_mul _).symm)))
else by rw [← insert_erase hx, prod_insert (not_mem_erase _ _),
← insert_erase (mem_erase.2 ⟨h₂ x hx hx1, h₃ x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h₁ x hx]))
/-- The product of the composition of functions `f` and `g`, is the product
over `b ∈ s.image g` of `f b` to the power of the cardinality of the fibre of `b` -/
lemma prod_comp [decidable_eq γ] {s : finset α} (f : γ → β) (g : α → γ) :
∏ a in s, f (g a) = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :=
calc ∏ a in s, f (g a)
= ∏ x in (s.image g).sigma (λ b : γ, s.filter (λ a, g a = b)), f (g x.2) :
prod_bij (λ a ha, ⟨g a, a⟩) (by simp; tauto) (λ _ _, rfl) (by simp) (by finish)
... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f (g a) : prod_sigma
... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f b :
prod_congr rfl (λ b hb, prod_congr rfl (by simp {contextual := tt}))
... = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :
prod_congr rfl (λ _ _, prod_const _)
@[to_additive]
lemma prod_eq_one {f : α → β} {s : finset α} (h : ∀x∈s, f x = 1) : (∏ x in s, f x) = 1 :=
calc (∏ x in s, f x) = s.prod (λx, 1) : finset.prod_congr rfl h
... = 1 : finset.prod_const_one
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive]
lemma prod_powerset_insert [decidable_eq α] {s : finset α} {x : α} (h : x ∉ s) (f : finset α → β) :
(∏ a in (insert x s).powerset, f a) =
(∏ a in s.powerset, f a) * (∏ t in s.powerset, f (insert x t)) :=
begin
rw [powerset_insert, finset.prod_union, finset.prod_image],
{ assume t₁ h₁ t₂ h₂ heq,
rw [← finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₁ h),
← finset.erase_insert (not_mem_of_mem_powerset_of_not_mem h₂ h), heq] },
{ rw finset.disjoint_iff_ne,
assume t₁ h₁ t₂ h₂,
rcases finset.mem_image.1 h₂ with ⟨t₃, h₃, H₃₂⟩,
rw ← H₃₂,
exact ne_insert_of_not_mem _ _ (not_mem_of_mem_powerset_of_not_mem h₁ h) }
end
@[to_additive]
lemma prod_piecewise [decidable_eq α] (s t : finset α) (f g : α → β) :
(∏ x in s, (t.piecewise f g) x) = (∏ x in s ∩ t, f x) * (∏ x in s \ t, g x) :=
by { rw [piecewise, prod_ite, filter_mem_eq_inter, ← sdiff_eq_filter], }
/-- If we can partition a product into subsets that cancel out, then the whole product cancels. -/
@[to_additive]
lemma prod_cancels_of_partition_cancels (R : setoid α) [decidable_rel R.r]
(h : ∀ x ∈ s, (∏ a in s.filter (λy, y ≈ x), f a) = 1) : (∏ x in s, f x) = 1 :=
begin
suffices : (s.image quotient.mk).prod (λ xbar, (s.filter (λ y, ⟦y⟧ = xbar)).prod f) = (∏ x in s, f x),
{ rw [←this, ←finset.prod_eq_one],
intros xbar xbar_in_s,
rcases (mem_image).mp xbar_in_s with ⟨x, x_in_s, xbar_eq_x⟩,
rw [←xbar_eq_x, filter_congr (λ y _, @quotient.eq _ R y x)],
apply h x x_in_s },
apply finset.prod_image' f,
intros,
refl
end
@[to_additive]
lemma prod_update_of_not_mem [decidable_eq α] {s : finset α} {i : α}
(h : i ∉ s) (f : α → β) (b : β) : (∏ x in s, function.update f i b x) = (∏ x in s, f x) :=
begin
apply prod_congr rfl (λj hj, _),
have : j ≠ i, by { assume eq, rw eq at hj, exact h hj },
simp [this]
end
lemma prod_update_of_mem [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s) (f : α → β) (b : β) :
(∏ x in s, function.update f i b x) = b * (∏ x in s \ (singleton i), f x) :=
by { rw [update_eq_piecewise, prod_piecewise], simp [h] }
end comm_monoid
lemma sum_update_of_mem [add_comm_monoid β] [decidable_eq α] {s : finset α} {i : α}
(h : i ∈ s) (f : α → β) (b : β) :
(∑ x in s, function.update f i b x) = b + (∑ x in s \ (singleton i), f x) :=
by { rw [update_eq_piecewise, sum_piecewise], simp [h] }
attribute [to_additive] prod_update_of_mem
lemma sum_smul' [add_comm_monoid β] (s : finset α) (n : ℕ) (f : α → β) :
(∑ x in s, add_monoid.smul n (f x)) = add_monoid.smul n ((∑ x in s, f x)) :=
@prod_pow _ (multiplicative β) _ _ _ _
attribute [to_additive sum_smul'] prod_pow
@[simp] lemma sum_const [add_comm_monoid β] (b : β) :
(∑ x in s, b) = add_monoid.smul s.card b :=
@prod_const _ (multiplicative β) _ _ _
attribute [to_additive] prod_const
lemma sum_comp [add_comm_monoid β] [decidable_eq γ] {s : finset α} (f : γ → β) (g : α → γ) :
∑ a in s, f (g a) = ∑ b in s.image g, add_monoid.smul (s.filter (λ a, g a = b)).card (f b) :=
@prod_comp _ (multiplicative β) _ _ _ _ _ _
attribute [to_additive "The sum of the composition of functions `f` and `g`, is the sum
over `b ∈ s.image g` of `f b` times of the cardinality of the fibre of `b`"] prod_comp
lemma sum_const_nat {m : ℕ} {f : α → ℕ} (h₁ : ∀x ∈ s, f x = m) :
(∑ x in s, f x) = card s * m :=
begin
rw [← nat.smul_eq_mul, ← sum_const],
apply sum_congr rfl h₁
end
@[simp]
lemma sum_boole {s : finset α} {p : α → Prop} [semiring β] {hp : decidable_pred p} :
(∑ x in s, if p x then (1 : β) else (0 : β)) = (s.filter p).card :=
by simp [sum_ite]
lemma sum_range_succ' [add_comm_monoid β] (f : ℕ → β) :
∀ n : ℕ, (∑ i in range (n + 1), f i) = (∑ i in range n, f (i + 1)) + f 0 :=
@prod_range_succ' (multiplicative β) _ _
attribute [to_additive] prod_range_succ'
lemma sum_flip [add_comm_monoid β] {n : ℕ} (f : ℕ → β) :
(∑ i in range (n + 1), f (n - i)) = (∑ i in range (n + 1), f i) :=
@prod_flip (multiplicative β) _ _ _
attribute [to_additive] prod_flip
@[norm_cast]
lemma sum_nat_cast [add_comm_monoid β] [has_one β] (s : finset α) (f : α → ℕ) :
↑(∑ x in s, f x : ℕ) = (∑ x in s, (f x : β)) :=
(nat.cast_add_monoid_hom β).map_sum f s
@[norm_cast]
lemma prod_nat_cast [comm_semiring β] (s : finset α) (f : α → ℕ) :
↑(∏ x in s, f x : ℕ) = (∏ x in s, (f x : β)) :=
(nat.cast_ring_hom β).map_prod f s
protected lemma sum_nat_coe_enat (s : finset α) (f : α → ℕ) :
(∑ x in s, (f x : enat)) = (∑ x in s, f x : ℕ) :=
begin
classical,
induction s using finset.induction with a s has ih h,
{ simp },
{ simp [has, ih] }
end
theorem dvd_sum [comm_semiring α] {a : α} {s : finset β} {f : β → α}
(h : ∀ x ∈ s, a ∣ f x) : a ∣ ∑ x in s, f x :=
multiset.dvd_sum (λ y hy, by rcases multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx)
lemma le_sum_of_subadditive [add_comm_monoid α] [ordered_add_comm_monoid β]
(f : α → β) (h_zero : f 0 = 0) (h_add : ∀x y, f (x + y) ≤ f x + f y) (s : finset γ) (g : γ → α) :
f (∑ x in s, g x) ≤ ∑ x in s, f (g x) :=
begin
refine le_trans (multiset.le_sum_of_subadditive f h_zero h_add _) _,
rw [multiset.map_map],
refl
end
lemma abs_sum_le_sum_abs [discrete_linear_ordered_field α] {f : β → α} {s : finset β} :
abs (∑ x in s, f x) ≤ ∑ x in s, abs (f x) :=
le_sum_of_subadditive _ abs_zero abs_add s f
section comm_group
variables [comm_group β]
@[simp, to_additive]
lemma prod_inv_distrib : (∏ x in s, (f x)⁻¹) = (∏ x in s, f x)⁻¹ :=
s.prod_hom has_inv.inv
end comm_group
@[simp] theorem card_sigma {σ : α → Type*} (s : finset α) (t : Π a, finset (σ a)) :
card (s.sigma t) = ∑ a in s, card (t a) :=
multiset.card_sigma _ _
lemma card_bind [decidable_eq β] {s : finset α} {t : α → finset β}
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → disjoint (t x) (t y)) :
(s.bind t).card = ∑ u in s, card (t u) :=
calc (s.bind t).card = (s.bind t).sum (λ _, 1) : by simp
... = s.sum (λ a, (t a).sum (λ _, 1)) : finset.sum_bind h
... = s.sum (λ u, card (t u)) : by simp
lemma card_bind_le [decidable_eq β] {s : finset α} {t : α → finset β} :
(s.bind t).card ≤ ∑ a in s, (t a).card :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp)
(λ a s has ih,
calc ((insert a s).bind t).card ≤ (t a).card + (s.bind t).card :
by rw bind_insert; exact finset.card_union_le _ _
... ≤ (insert a s).sum (λ a, card (t a)) :
by rw sum_insert has; exact add_le_add_left ih _)
theorem card_eq_sum_card_image [decidable_eq β] (f : α → β) (s : finset α) :
s.card = ∑ a in s.image f, (s.filter (λ x, f x = a)).card :=
by letI := classical.dec_eq α; exact
calc s.card = ((s.image f).bind (λ a, s.filter (λ x, f x = a))).card :
congr_arg _ (finset.ext.2 $ λ x,
⟨λ hs, mem_bind.2 ⟨f x, mem_image_of_mem _ hs,
mem_filter.2 ⟨hs, rfl⟩⟩,
λ h, let ⟨a, ha₁, ha₂⟩ := mem_bind.1 h in by convert filter_subset s ha₂⟩)
... = (s.image f).sum (λ a, (s.filter (λ x, f x = a)).card) :
card_bind (by simp [disjoint_left, finset.ext] {contextual := tt})
lemma gsmul_sum [add_comm_group β] {f : α → β} {s : finset α} (z : ℤ) :
gsmul z (∑ a in s, f a) = ∑ a in s, gsmul z (f a) :=
(s.sum_hom (gsmul z)).symm
end finset
namespace finset
variables {s s₁ s₂ : finset α} {f g : α → β} {b : β} {a : α}
@[simp] lemma sum_sub_distrib [add_comm_group β] :
∑ x in s, (f x - g x) = (∑ x in s, f x) - (∑ x in s, g x) :=
sum_add_distrib.trans $ congr_arg _ sum_neg_distrib
section comm_monoid
variables [comm_monoid β]
lemma prod_pow_boole [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∏ x in s, (f x)^(ite (a = x) 1 0)) = ite (a ∈ s) (f a) 1 :=
by simp
end comm_monoid
section semiring
variables [semiring β]
lemma sum_mul : (∑ x in s, f x) * b = ∑ x in s, f x * b :=
(s.sum_hom (λ x, x * b)).symm
lemma mul_sum : b * (∑ x in s, f x) = ∑ x in s, b * f x :=
(s.sum_hom _).symm
lemma sum_mul_boole [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∑ x in s, (f x * ite (a = x) 1 0)) = ite (a ∈ s) (f a) 0 :=
by simp
lemma sum_boole_mul [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∑ x in s, (ite (a = x) 1 0) * f x) = ite (a ∈ s) (f a) 0 :=
by simp
end semiring
lemma sum_div [division_ring β] {s : finset α} {f : α → β} {b : β} :
(∑ x in s, f x) / b = ∑ x in s, f x / b :=
calc (∑ x in s, f x) / b = ∑ x in s, f x * (1 / b) : by rw [div_eq_mul_one_div, sum_mul]
... = ∑ x in s, f x / b : by { congr, ext, rw ← div_eq_mul_one_div (f x) b }
section comm_semiring
variables [comm_semiring β]
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : (∏ x in s, f x) = 0 :=
by haveI := classical.dec_eq α;
calc (∏ x in s, f x) = ∏ x in insert a (erase s a), f x : by rw insert_erase ha
... = 0 : by rw [prod_insert (not_mem_erase _ _), h, zero_mul]
/-- The product over a sum can be written as a sum over the product of sets, `finset.pi`.
`finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/
lemma prod_sum {δ : α → Type*} [decidable_eq α] [∀a, decidable_eq (δ a)]
{s : finset α} {t : Πa, finset (δ a)} {f : Πa, δ a → β} :
(∏ a in s, ∑ b in (t a), f a b) =
∑ p in (s.pi t), ∏ x in s.attach, f x.1 (p x.1 x.2) :=
begin
induction s using finset.induction with a s ha ih,
{ rw [pi_empty, sum_singleton], refl },
{ have h₁ : ∀x ∈ t a, ∀y ∈ t a, ∀h : x ≠ y,
disjoint (image (pi.cons s a x) (pi s t)) (image (pi.cons s a y) (pi s t)),
{ assume x hx y hy h,
simp only [disjoint_iff_ne, mem_image],
rintros _ ⟨p₂, hp, eq₂⟩ _ ⟨p₃, hp₃, eq₃⟩ eq,
have : pi.cons s a x p₂ a (mem_insert_self _ _) = pi.cons s a y p₃ a (mem_insert_self _ _),
{ rw [eq₂, eq₃, eq] },
rw [pi.cons_same, pi.cons_same] at this,
exact h this },
rw [prod_insert ha, pi_insert ha, ih, sum_mul, sum_bind h₁],
refine sum_congr rfl (λ b _, _),
have h₂ : ∀p₁∈pi s t, ∀p₂∈pi s t, pi.cons s a b p₁ = pi.cons s a b p₂ → p₁ = p₂, from
assume p₁ h₁ p₂ h₂ eq, injective_pi_cons ha eq,
rw [sum_image h₂, mul_sum],
refine sum_congr rfl (λ g _, _),
rw [attach_insert, prod_insert, prod_image],
{ simp only [pi.cons_same],
congr', ext ⟨v, hv⟩, congr',
exact (pi.cons_ne (by rintro rfl; exact ha hv)).symm },
{ exact λ _ _ _ _, subtype.eq ∘ subtype.mk.inj },
{ simp only [mem_image], rintro ⟨⟨_, hm⟩, _, rfl⟩, exact ha hm } }
end
lemma sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : finset ι₁) (s₂ : finset ι₂)
(f₁ : ι₁ → β) (f₂ : ι₂ → β) :
(∑ x₁ in s₁, f₁ x₁) * (∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁.product s₂, f₁ p.1 * f₂ p.2 :=
by { rw [sum_product, sum_mul, sum_congr rfl], intros, rw mul_sum }
open_locale classical
/-- The product of `f a + g a` over all of `s` is the sum
over the powerset of `s` of the product of `f` over a subset `t` times
the product of `g` over the complement of `t` -/
lemma prod_add (f g : α → β) (s : finset α) :
∏ a in s, (f a + g a) = ∑ t in s.powerset, ((∏ a in t, f a) * (∏ a in (s \ t), g a)) :=
calc ∏ a in s, (f a + g a)
= ∏ a in s, ∑ p in ({false, true} : finset Prop), if p then f a else g a : by simp
... = ∑ p in (s.pi (λ _, {false, true}) : finset (Π a ∈ s, Prop)),
∏ a in s.attach, if p a.1 a.2 then f a.1 else g a.1 : prod_sum
... = ∑ t in s.powerset, (∏ a in t, f a) * (∏ a in (s \ t), g a) : begin
refine eq.symm (sum_bij (λ t _ a _, a ∈ t) _ _ _ _),
{ simp [subset_iff]; tauto },
{ intros t ht,
erw [prod_ite (λ a : {a // a ∈ s}, f a.1) (λ a : {a // a ∈ s}, g a.1)],
refine congr_arg2 _
(prod_bij (λ (a : α) (ha : a ∈ t), ⟨a, mem_powerset.1 ht ha⟩)
_ _ _
(λ b hb, ⟨b, by cases b; finish⟩))
(prod_bij (λ (a : α) (ha : a ∈ s \ t), ⟨a, by simp * at *⟩)
_ _ _
(λ b hb, ⟨b, by cases b; finish⟩));
intros; simp * at *; simp * at * },
{ finish [function.funext_iff, finset.ext, subset_iff] },
{ assume f hf,
exact ⟨s.filter (λ a : α, ∃ h : a ∈ s, f a h),
by simp, by funext; intros; simp *⟩ }
end
/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `finset`
gives `(a + b)^s.card`.-/
lemma sum_pow_mul_eq_add_pow
{α R : Type*} [comm_semiring R] (a b : R) (s : finset α) :
(∑ t in s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card :=
begin
rw [← prod_const, prod_add],
refine finset.sum_congr rfl (λ t ht, _),
rw [prod_const, prod_const, ← card_sdiff (mem_powerset.1 ht)]
end
lemma prod_pow_eq_pow_sum {x : β} {f : α → ℕ} :
∀ {s : finset α}, (∏ i in s, x ^ (f i)) = x ^ (∑ x in s, f x) :=
begin
apply finset.induction,
{ simp },
{ assume a s has H,
rw [finset.prod_insert has, finset.sum_insert has, pow_add, H] }
end
end comm_semiring
section integral_domain /- add integral_semi_domain to support nat and ennreal -/
variables [integral_domain β]
lemma prod_eq_zero_iff : (∏ x in s, f x) = 0 ↔ (∃a∈s, f a = 0) :=
begin
classical,
apply finset.induction_on s,
exact ⟨not.elim one_ne_zero, λ ⟨_, H, _⟩, H.elim⟩,
assume a s ha ih,
rw [prod_insert ha, mul_eq_zero_iff_eq_zero_or_eq_zero, bex_def, exists_mem_insert, ih, ← bex_def]
end
end integral_domain
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid β]
lemma sum_le_sum : (∀x∈s, f x ≤ g x) → (∑ x in s, f x) ≤ (∑ x in s, g x) :=
begin
classical,
apply finset.induction_on s,
exact (λ _, le_refl _),
assume a s ha ih h,
have : f a + (∑ x in s, f x) ≤ g a + (∑ x in s, g x),
from add_le_add' (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simpa only [sum_insert ha]
end
lemma sum_nonneg (h : ∀x∈s, 0 ≤ f x) : 0 ≤ (∑ x in s, f x) :=
le_trans (by rw [sum_const_zero]) (sum_le_sum h)
lemma sum_nonpos (h : ∀x∈s, f x ≤ 0) : (∑ x in s, f x) ≤ 0 :=
le_trans (sum_le_sum h) (by rw [sum_const_zero])
lemma sum_le_sum_of_subset_of_nonneg
(h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → 0 ≤ f x) : (∑ x in s₁, f x) ≤ (∑ x in s₂, f x) :=
by classical;
calc (∑ x in s₁, f x) ≤ (∑ x in s₂ \ s₁, f x) + (∑ x in s₁, f x) :
le_add_of_nonneg_left' $ sum_nonneg $ by simpa only [mem_sdiff, and_imp]
... = ∑ x in s₂ \ s₁ ∪ s₁, f x : (sum_union sdiff_disjoint).symm
... = (∑ x in s₂, f x) : by rw [sdiff_union_of_subset h]
lemma sum_eq_zero_iff_of_nonneg : (∀x∈s, 0 ≤ f x) → ((∑ x in s, f x) = 0 ↔ ∀x∈s, f x = 0) :=
begin
classical,
apply finset.induction_on s,
exact λ _, ⟨λ _ _, false.elim, λ _, rfl⟩,
assume a s ha ih H,
have : ∀ x ∈ s, 0 ≤ f x, from λ _, H _ ∘ mem_insert_of_mem,
rw [sum_insert ha, add_eq_zero_iff' (H _ $ mem_insert_self _ _) (sum_nonneg this),
forall_mem_insert, ih this]
end
lemma sum_eq_zero_iff_of_nonpos : (∀x∈s, f x ≤ 0) → ((∑ x in s, f x) = 0 ↔ ∀x∈s, f x = 0) :=
@sum_eq_zero_iff_of_nonneg _ (order_dual β) _ _ _
lemma single_le_sum (hf : ∀x∈s, 0 ≤ f x) {a} (h : a ∈ s) : f a ≤ (∑ x in s, f x) :=
have (singleton a).sum f ≤ (∑ x in s, f x),
from sum_le_sum_of_subset_of_nonneg
(λ x e, (mem_singleton.1 e).symm ▸ h) (λ x h _, hf x h),
by rwa sum_singleton at this
end ordered_add_comm_monoid
section canonically_ordered_add_monoid
variables [canonically_ordered_add_monoid β]
lemma sum_le_sum_of_subset (h : s₁ ⊆ s₂) : (∑ x in s₁, f x) ≤ (∑ x in s₂, f x) :=
sum_le_sum_of_subset_of_nonneg h $ assume x h₁ h₂, zero_le _
lemma sum_le_sum_of_ne_zero (h : ∀x∈s₁, f x ≠ 0 → x ∈ s₂) :
(∑ x in s₁, f x) ≤ (∑ x in s₂, f x) :=
by classical;
calc (∑ x in s₁, f x) = (s₁.filter (λx, f x = 0)).sum f + (s₁.filter (λx, f x ≠ 0)).sum f :
by rw [←sum_union, filter_union_filter_neg_eq];
exact disjoint_filter.2 (assume _ _ h n_h, n_h h)
... ≤ (∑ x in s₂, f x) : add_le_of_nonpos_of_le'
(sum_nonpos $ by simp only [mem_filter, and_imp]; exact λ _ _, le_of_eq)
(sum_le_sum_of_subset $ by simpa only [subset_iff, mem_filter, and_imp])
end canonically_ordered_add_monoid
section ordered_cancel_comm_monoid
variables [ordered_cancel_add_comm_monoid β]
theorem sum_lt_sum (Hle : ∀ i ∈ s, f i ≤ g i) (Hlt : ∃ i ∈ s, f i < g i) :
(∑ x in s, f x) < (∑ x in s, g x) :=
begin
classical,
rcases Hlt with ⟨i, hi, hlt⟩,
rw [← insert_erase hi, sum_insert (not_mem_erase _ _), sum_insert (not_mem_erase _ _)],
exact add_lt_add_of_lt_of_le hlt (sum_le_sum $ λ j hj, Hle j $ mem_of_mem_erase hj)
end
lemma sum_lt_sum_of_nonempty (hs : s.nonempty) (Hlt : ∀ x ∈ s, f x < g x) :
(∑ x in s, f x) < (∑ x in s, g x) :=
begin
apply sum_lt_sum,
{ intros i hi, apply le_of_lt (Hlt i hi) },
cases hs with i hi,
exact ⟨i, hi, Hlt i hi⟩,
end
lemma sum_lt_sum_of_subset [decidable_eq α]
(h : s₁ ⊆ s₂) {i : α} (hi : i ∈ s₂ \ s₁) (hpos : 0 < f i) (hnonneg : ∀ j ∈ s₂ \ s₁, 0 ≤ f j) :
(∑ x in s₁, f x) < (∑ x in s₂, f x) :=
calc (∑ x in s₁, f x) < (∑ x in insert i s₁, f x) :
begin
simp only [mem_sdiff] at hi,
rw sum_insert hi.2,
exact lt_add_of_pos_left (finset.sum s₁ f) hpos,
end
... ≤ (∑ x in s₂, f x) :
begin
simp only [mem_sdiff] at hi,
apply sum_le_sum_of_subset_of_nonneg,
{ simp [finset.insert_subset, h, hi.1] },
{ assume x hx h'x,
apply hnonneg x,
simp [mem_insert, not_or_distrib] at h'x,
rw mem_sdiff,
simp [hx, h'x] }
end
end ordered_cancel_comm_monoid
section decidable_linear_ordered_cancel_comm_monoid
variables [decidable_linear_ordered_cancel_add_comm_monoid β]
theorem exists_le_of_sum_le (hs : s.nonempty) (Hle : (∑ x in s, f x) ≤ s.sum g) :
∃ i ∈ s, f i ≤ g i :=
begin
classical,
contrapose! Hle with Hlt,
rcases hs with ⟨i, hi⟩,
exact sum_lt_sum (λ i hi, le_of_lt (Hlt i hi)) ⟨i, hi, Hlt i hi⟩
end
end decidable_linear_ordered_cancel_comm_monoid
section linear_ordered_comm_ring
variables [linear_ordered_comm_ring β]
open_locale classical
/- this is also true for a ordered commutative multiplicative monoid -/
lemma prod_nonneg {s : finset α} {f : α → β}
(h0 : ∀(x ∈ s), 0 ≤ f x) : 0 ≤ (∏ x in s, f x) :=
begin
induction s using finset.induction with a s has ih h,
{ simp [zero_le_one] },
{ simp [has], apply mul_nonneg, apply h0 a (mem_insert_self a s),
exact ih (λ x H, h0 x (mem_insert_of_mem H)) }
end
/- this is also true for a ordered commutative multiplicative monoid -/
lemma prod_pos {s : finset α} {f : α → β} (h0 : ∀(x ∈ s), 0 < f x) : 0 < (∏ x in s, f x) :=
begin
induction s using finset.induction with a s has ih h,
{ simp [zero_lt_one] },
{ simp [has], apply mul_pos, apply h0 a (mem_insert_self a s),
exact ih (λ x H, h0 x (mem_insert_of_mem H)) }
end
/- this is also true for a ordered commutative multiplicative monoid -/
lemma prod_le_prod {s : finset α} {f g : α → β} (h0 : ∀(x ∈ s), 0 ≤ f x)
(h1 : ∀(x ∈ s), f x ≤ g x) : (∏ x in s, f x) ≤ (∏ x in s, g x) :=
begin
induction s using finset.induction with a s has ih h,
{ simp },
{ simp [has], apply mul_le_mul,
exact h1 a (mem_insert_self a s),
apply ih (λ x H, h0 _ _) (λ x H, h1 _ _); exact (mem_insert_of_mem H),
apply prod_nonneg (λ x H, h0 x (mem_insert_of_mem H)),
apply le_trans (h0 a (mem_insert_self a s)) (h1 a (mem_insert_self a s)) }
end
end linear_ordered_comm_ring
section canonically_ordered_comm_semiring
variables [canonically_ordered_comm_semiring β]
lemma prod_le_prod' {s : finset α} {f g : α → β} (h : ∀ i ∈ s, f i ≤ g i) :
(∏ x in s, f x) ≤ (∏ x in s, g x) :=
begin
classical,
induction s using finset.induction with a s has ih h,
{ simp },
{ rw [finset.prod_insert has, finset.prod_insert has],
apply canonically_ordered_semiring.mul_le_mul,
{ exact h _ (finset.mem_insert_self a s) },
{ exact ih (λ i hi, h _ (finset.mem_insert_of_mem hi)) } }
end
end canonically_ordered_comm_semiring
@[simp] lemma card_pi [decidable_eq α] {δ : α → Type*}
(s : finset α) (t : Π a, finset (δ a)) :
(s.pi t).card = s.prod (λ a, card (t a)) :=
multiset.card_pi _ _
theorem card_le_mul_card_image [decidable_eq β] {f : α → β} (s : finset α)
(n : ℕ) (hn : ∀ a ∈ s.image f, (s.filter (λ x, f x = a)).card ≤ n) :
s.card ≤ n * (s.image f).card :=
calc s.card = (∑ a in s.image f, (s.filter (λ x, f x = a)).card) :
card_eq_sum_card_image _ _
... ≤ (∑ _ in s.image f, n) : sum_le_sum hn
... = _ : by simp [mul_comm]
@[simp] lemma prod_Ico_id_eq_fact : ∀ n : ℕ, (Ico 1 (n + 1)).prod (λ x, x) = nat.fact n
| 0 := rfl
| (n+1) := by rw [prod_Ico_succ_top $ nat.succ_le_succ $ zero_le n,
nat.fact_succ, prod_Ico_id_eq_fact n, nat.succ_eq_add_one, mul_comm]
end finset
namespace finset
section gauss_sum
/-- Gauss' summation formula -/
lemma sum_range_id_mul_two :
∀(n : ℕ), (∑ i in range n, i) * 2 = n * (n - 1)
| 0 := rfl
| 1 := rfl
| ((n + 1) + 1) :=
begin
rw [sum_range_succ, add_mul, sum_range_id_mul_two (n + 1), mul_comm, two_mul,
nat.add_sub_cancel, nat.add_sub_cancel, mul_comm _ n],
simp only [add_mul, one_mul, add_comm, add_assoc, add_left_comm]
end
/-- Gauss' summation formula -/
lemma sum_range_id (n : ℕ) : (∑ i in range n, i) = (n * (n - 1)) / 2 :=
by rw [← sum_range_id_mul_two n, nat.mul_div_cancel]; exact dec_trivial
end gauss_sum
lemma card_eq_sum_ones (s : finset α) : s.card = ∑ _ in s, 1 :=
by simp
end finset
section group
open list
variables [group α] [group β]
theorem is_group_anti_hom.map_prod (f : α → β) [is_group_anti_hom f] (l : list α) :
f (prod l) = prod (map f (reverse l)) :=
by induction l with hd tl ih; [exact is_group_anti_hom.map_one f,
simp only [prod_cons, is_group_anti_hom.map_mul f, ih, reverse_cons, map_append, prod_append, map_singleton, prod_cons, prod_nil, mul_one]]
theorem inv_prod : ∀ l : list α, (prod l)⁻¹ = prod (map (λ x, x⁻¹) (reverse l)) :=
λ l, @is_group_anti_hom.map_prod _ _ _ _ _ inv_is_group_anti_hom l -- TODO there is probably a cleaner proof of this
end group
@[to_additive is_add_group_hom_finset_sum]
lemma is_group_hom_finset_prod {α β γ} [group α] [comm_group β] (s : finset γ)
(f : γ → α → β) [∀c, is_group_hom (f c)] : is_group_hom (λa, ∏ c in s, f c a) :=
{ map_mul := assume a b, by simp only [λc, is_mul_hom.map_mul (f c), finset.prod_mul_distrib] }
attribute [instance] is_group_hom_finset_prod is_add_group_hom_finset_sum
namespace multiset
variables [decidable_eq α]
@[simp] lemma to_finset_sum_count_eq (s : multiset α) :
(∑ a in s.to_finset, s.count a) = s.card :=
multiset.induction_on s rfl
(assume a s ih,
calc (∑ x in to_finset (a :: s), count x (a :: s)) =
(to_finset (a :: s)).sum (λx, (if x = a then 1 else 0) + count x s) :
finset.sum_congr rfl $ λ _ _, by split_ifs;
[simp only [h, count_cons_self, nat.one_add], simp only [count_cons_of_ne h, zero_add]]
... = card (a :: s) :
begin
by_cases a ∈ s.to_finset,
{ have : (to_finset s).sum (λx, ite (x = a) 1 0) = (finset.singleton a).sum (λx, ite (x = a) 1 0),
{ apply (finset.sum_subset _ _).symm,
{ intros _ H, rwa mem_singleton.1 H },
{ exact λ _ _ H, if_neg (mt finset.mem_singleton.2 H) } },
rw [to_finset_cons, finset.insert_eq_of_mem h, finset.sum_add_distrib, ih, this, finset.sum_singleton, if_pos rfl, add_comm, card_cons] },
{ have ha : a ∉ s, by rwa mem_to_finset at h,
have : (to_finset s).sum (λx, ite (x = a) 1 0) = (to_finset s).sum (λx, 0), from
finset.sum_congr rfl (λ x hx, if_neg $ by rintro rfl; cc),
rw [to_finset_cons, finset.sum_insert h, if_pos rfl, finset.sum_add_distrib, this, finset.sum_const_zero, ih, count_eq_zero_of_not_mem ha, zero_add, add_comm, card_cons] }
end)
end multiset
namespace with_top
open finset
open_locale classical
/-- sum of finite numbers is still finite -/
lemma sum_lt_top [ordered_add_comm_monoid β] {s : finset α} {f : α → with_top β} :
(∀a∈s, f a < ⊤) → (∑ x in s, f x) < ⊤ :=
finset.induction_on s (by { intro h, rw sum_empty, exact coe_lt_top _ })
(λa s ha ih h,
begin
rw [sum_insert ha, add_lt_top], split,
{ apply h, apply mem_insert_self },
{ apply ih, intros a ha, apply h, apply mem_insert_of_mem ha }
end)
/-- sum of finite numbers is still finite -/
lemma sum_lt_top_iff [canonically_ordered_add_monoid β] {s : finset α} {f : α → with_top β} :
(∑ x in s, f x) < ⊤ ↔ (∀a∈s, f a < ⊤) :=
iff.intro (λh a ha, lt_of_le_of_lt (single_le_sum (λa ha, zero_le _) ha) h) sum_lt_top
end with_top
|
70f2b285836f29ddf8babd317dddeb7303c2da59
|
78630e908e9624a892e24ebdd21260720d29cf55
|
/src/logic_first_order/fol_03.lean
|
6a06b2837a6ae611caae744794faafe43aa397b4
|
[
"CC0-1.0"
] |
permissive
|
tomasz-lisowski/lean-logic-examples
|
84e612466776be0a16c23a0439ff8ef6114ddbe1
|
2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d
|
refs/heads/master
| 1,683,334,199,431
| 1,621,938,305,000
| 1,621,938,305,000
| 365,041,573
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 355
|
lean
|
namespace fol_03
variable A : Type
variables P Q : A → Prop
theorem fol_03 : ((∃ x, P x) → (∀ x, Q x)) → ∀ y, P y → Q y :=
assume h1: (∃ x, P x) → (∀ x, Q x),
assume y: A,
show P y → Q y, from
(assume h2: P y,
have h3: ∃ x, P x, from exists.intro y h2,
have h4: ∀ x, Q x, from h1 h3,
show Q y, from h4 y)
end fol_03
|
24336bb34261dbe43b3fda571acb0051ad60b86e
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/hott/init/path.hlean
|
8680026961a29effe938960e2fbff4a49b6ceead
|
[
"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
| 27,972
|
hlean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
prelude
import .function .tactic
open function eq
/- Path equality -/
namespace eq
variables {A B C : Type} {P : A → Type} {a a' x y z t : A} {b b' : B}
--notation a = b := eq a b
notation x = y `:>`:50 A:49 := @eq A x y
definition idp [reducible] [constructor] {a : A} := refl a
definition idpath [reducible] [constructor] (a : A) := refl a
-- unbased path induction
definition rec' [reducible] [unfold 6] {P : Π (a b : A), (a = b) → Type}
(H : Π (a : A), P a a idp) {a b : A} (p : a = b) : P a b p :=
eq.rec (H a) p
definition rec_on' [reducible] [unfold 5] {P : Π (a b : A), (a = b) → Type}
{a b : A} (p : a = b) (H : Π (a : A), P a a idp) : P a b p :=
eq.rec (H a) p
/- Concatenation and inverse -/
definition concat [trans] [unfold 6] (p : x = y) (q : y = z) : x = z :=
by induction q; exact p
definition inverse [symm] [unfold 4] (p : x = y) : y = x :=
by induction p; reflexivity
infix ⬝ := concat
postfix ⁻¹ := inverse
--a second notation for the inverse, which is not overloaded
postfix [parsing_only] `⁻¹ᵖ`:std.prec.max_plus := inverse
/- The 1-dimensional groupoid structure -/
-- The identity path is a right unit.
definition con_idp [unfold_full] (p : x = y) : p ⬝ idp = p :=
idp
-- The identity path is a right unit.
definition idp_con [unfold 4] (p : x = y) : idp ⬝ p = p :=
by induction p; reflexivity
-- Concatenation is associative.
definition con.assoc' (p : x = y) (q : y = z) (r : z = t) :
p ⬝ (q ⬝ r) = (p ⬝ q) ⬝ r :=
by induction r; reflexivity
definition con.assoc (p : x = y) (q : y = z) (r : z = t) :
(p ⬝ q) ⬝ r = p ⬝ (q ⬝ r) :=
by induction r; reflexivity
-- The left inverse law.
definition con.right_inv [unfold 4] (p : x = y) : p ⬝ p⁻¹ = idp :=
by induction p; reflexivity
-- The right inverse law.
definition con.left_inv [unfold 4] (p : x = y) : p⁻¹ ⬝ p = idp :=
by induction p; reflexivity
/- Several auxiliary theorems about canceling inverses across associativity. These are somewhat
redundant, following from earlier theorems. -/
definition inv_con_cancel_left (p : x = y) (q : y = z) : p⁻¹ ⬝ (p ⬝ q) = q :=
by induction q; induction p; reflexivity
definition con_inv_cancel_left (p : x = y) (q : x = z) : p ⬝ (p⁻¹ ⬝ q) = q :=
by induction q; induction p; reflexivity
definition con_inv_cancel_right (p : x = y) (q : y = z) : (p ⬝ q) ⬝ q⁻¹ = p :=
by induction q; reflexivity
definition inv_con_cancel_right (p : x = z) (q : y = z) : (p ⬝ q⁻¹) ⬝ q = p :=
by induction q; reflexivity
-- Inverse distributes over concatenation
definition con_inv (p : x = y) (q : y = z) : (p ⬝ q)⁻¹ = q⁻¹ ⬝ p⁻¹ :=
by induction q; induction p; reflexivity
definition inv_con_inv_left (p : y = x) (q : y = z) : (p⁻¹ ⬝ q)⁻¹ = q⁻¹ ⬝ p :=
by induction q; induction p; reflexivity
-- universe metavariables
definition inv_con_inv_right (p : x = y) (q : z = y) : (p ⬝ q⁻¹)⁻¹ = q ⬝ p⁻¹ :=
by induction q; induction p; reflexivity
definition inv_con_inv_inv (p : y = x) (q : z = y) : (p⁻¹ ⬝ q⁻¹)⁻¹ = q ⬝ p :=
by induction q; induction p; reflexivity
-- Inverse is an involution.
definition inv_inv (p : x = y) : p⁻¹⁻¹ = p :=
by induction p; reflexivity
-- auxiliary definition used by 'cases' tactic
definition elim_inv_inv {A : Type} {a b : A} {C : a = b → Type} (H₁ : a = b) (H₂ : C (H₁⁻¹⁻¹)) : C H₁ :=
eq.rec_on (inv_inv H₁) H₂
/- Theorems for moving things around in equations -/
definition con_eq_of_eq_inv_con {p : x = z} {q : y = z} {r : y = x} :
p = r⁻¹ ⬝ q → r ⬝ p = q :=
begin
induction r, intro h, exact !idp_con ⬝ h ⬝ !idp_con
end
definition con_eq_of_eq_con_inv [unfold 5] {p : x = z} {q : y = z} {r : y = x} :
r = q ⬝ p⁻¹ → r ⬝ p = q :=
by induction p; exact id
definition inv_con_eq_of_eq_con {p : x = z} {q : y = z} {r : x = y} :
p = r ⬝ q → r⁻¹ ⬝ p = q :=
by induction r; intro h; exact !idp_con ⬝ h ⬝ !idp_con
definition con_inv_eq_of_eq_con [unfold 5] {p : z = x} {q : y = z} {r : y = x} :
r = q ⬝ p → r ⬝ p⁻¹ = q :=
by induction p; exact id
definition eq_con_of_inv_con_eq {p : x = z} {q : y = z} {r : y = x} :
r⁻¹ ⬝ q = p → q = r ⬝ p :=
by induction r; intro h; exact !idp_con⁻¹ ⬝ h ⬝ !idp_con⁻¹
definition eq_con_of_con_inv_eq [unfold 5] {p : x = z} {q : y = z} {r : y = x} :
q ⬝ p⁻¹ = r → q = r ⬝ p :=
by induction p; exact id
definition eq_inv_con_of_con_eq {p : x = z} {q : y = z} {r : x = y} :
r ⬝ q = p → q = r⁻¹ ⬝ p :=
by induction r; intro h; exact !idp_con⁻¹ ⬝ h ⬝ !idp_con⁻¹
definition eq_con_inv_of_con_eq [unfold 5] {p : z = x} {q : y = z} {r : y = x} :
q ⬝ p = r → q = r ⬝ p⁻¹ :=
by induction p; exact id
definition eq_of_con_inv_eq_idp [unfold 5] {p q : x = y} : p ⬝ q⁻¹ = idp → p = q :=
by induction q; exact id
definition eq_of_inv_con_eq_idp {p q : x = y} : q⁻¹ ⬝ p = idp → p = q :=
by induction q; intro h; exact !idp_con⁻¹ ⬝ h
definition eq_inv_of_con_eq_idp' [unfold 5] {p : x = y} {q : y = x} : p ⬝ q = idp → p = q⁻¹ :=
by induction q; exact id
definition eq_inv_of_con_eq_idp {p : x = y} {q : y = x} : q ⬝ p = idp → p = q⁻¹ :=
by induction q; intro h; exact !idp_con⁻¹ ⬝ h
definition eq_of_idp_eq_inv_con {p q : x = y} : idp = p⁻¹ ⬝ q → p = q :=
by induction p; intro h; exact h ⬝ !idp_con
definition eq_of_idp_eq_con_inv [unfold 4] {p q : x = y} : idp = q ⬝ p⁻¹ → p = q :=
by induction p; exact id
definition inv_eq_of_idp_eq_con [unfold 4] {p : x = y} {q : y = x} : idp = q ⬝ p → p⁻¹ = q :=
by induction p; exact id
definition inv_eq_of_idp_eq_con' {p : x = y} {q : y = x} : idp = p ⬝ q → p⁻¹ = q :=
by induction p; intro h; exact h ⬝ !idp_con
definition con_inv_eq_idp [unfold 6] {p q : x = y} (r : p = q) : p ⬝ q⁻¹ = idp :=
by cases r; apply con.right_inv
definition inv_con_eq_idp [unfold 6] {p q : x = y} (r : p = q) : q⁻¹ ⬝ p = idp :=
by cases r; apply con.left_inv
definition con_eq_idp {p : x = y} {q : y = x} (r : p = q⁻¹) : p ⬝ q = idp :=
by cases q; exact r
definition idp_eq_inv_con {p q : x = y} (r : p = q) : idp = p⁻¹ ⬝ q :=
by cases r; exact !con.left_inv⁻¹
definition idp_eq_con_inv {p q : x = y} (r : p = q) : idp = q ⬝ p⁻¹ :=
by cases r; exact !con.right_inv⁻¹
definition idp_eq_con {p : x = y} {q : y = x} (r : p⁻¹ = q) : idp = q ⬝ p :=
by cases p; exact r
/- Transport -/
definition transport [subst] [reducible] [unfold 5] (P : A → Type) {x y : A} (p : x = y)
(u : P x) : P y :=
by induction p; exact u
-- This idiom makes the operation right associative.
infixr ` ▸ ` := transport _
definition cast [reducible] [unfold 3] {A B : Type} (p : A = B) (a : A) : B :=
p ▸ a
definition cast_def [reducible] [unfold_full] {A B : Type} (p : A = B) (a : A)
: cast p a = p ▸ a :=
idp
definition tr_rev [reducible] [unfold 6] (P : A → Type) {x y : A} (p : x = y) (u : P y) : P x :=
p⁻¹ ▸ u
definition ap [unfold 6] ⦃A B : Type⦄ (f : A → B) {x y:A} (p : x = y) : f x = f y :=
by induction p; reflexivity
abbreviation ap01 [parsing_only] := ap
definition homotopy [reducible] (f g : Πx, P x) : Type :=
Πx : A, f x = g x
infix ~ := homotopy
protected definition homotopy.refl [refl] [reducible] [unfold_full] (f : Πx, P x) : f ~ f :=
λ x, idp
protected definition homotopy.symm [symm] [reducible] [unfold_full] {f g : Πx, P x} (H : f ~ g)
: g ~ f :=
λ x, (H x)⁻¹
protected definition homotopy.trans [trans] [reducible] [unfold_full] {f g h : Πx, P x}
(H1 : f ~ g) (H2 : g ~ h) : f ~ h :=
λ x, H1 x ⬝ H2 x
definition homotopy_of_eq {f g : Πx, P x} (H1 : f = g) : f ~ g :=
H1 ▸ homotopy.refl f
definition apd10 [unfold 5] {f g : Πx, P x} (H : f = g) : f ~ g :=
λx, by induction H; reflexivity
--the next theorem is useful if you want to write "apply (apd10' a)"
definition apd10' [unfold 6] {f g : Πx, P x} (a : A) (H : f = g) : f a = g a :=
by induction H; reflexivity
--apd10 is also ap evaluation
definition apd10_eq_ap_eval {f g : Πx, P x} (H : f = g) (a : A)
: apd10 H a = ap (λs : Πx, P x, s a) H :=
by induction H; reflexivity
definition ap10 [reducible] [unfold 5] {f g : A → B} (H : f = g) : f ~ g := apd10 H
definition ap11 {f g : A → B} (H : f = g) {x y : A} (p : x = y) : f x = g y :=
by induction H; exact ap f p
definition apd [unfold 6] (f : Πa, P a) {x y : A} (p : x = y) : p ▸ f x = f y :=
by induction p; reflexivity
definition ap011 [unfold 9] (f : A → B → C) (Ha : a = a') (Hb : b = b') : f a b = f a' b' :=
by cases Ha; exact ap (f a) Hb
/- More theorems for moving things around in equations -/
definition tr_eq_of_eq_inv_tr {P : A → Type} {x y : A} {p : x = y} {u : P x} {v : P y} :
u = p⁻¹ ▸ v → p ▸ u = v :=
by induction p; exact id
definition inv_tr_eq_of_eq_tr {P : A → Type} {x y : A} {p : y = x} {u : P x} {v : P y} :
u = p ▸ v → p⁻¹ ▸ u = v :=
by induction p; exact id
definition eq_inv_tr_of_tr_eq {P : A → Type} {x y : A} {p : x = y} {u : P x} {v : P y} :
p ▸ u = v → u = p⁻¹ ▸ v :=
by induction p; exact id
definition eq_tr_of_inv_tr_eq {P : A → Type} {x y : A} {p : y = x} {u : P x} {v : P y} :
p⁻¹ ▸ u = v → u = p ▸ v :=
by induction p; exact id
/- Functoriality of functions -/
-- Here we prove that functions behave like functors between groupoids, and that [ap] itself is
-- functorial.
-- Functions take identity paths to identity paths
definition ap_idp [unfold_full] (x : A) (f : A → B) : ap f idp = idp :> (f x = f x) := idp
-- Functions commute with concatenation.
definition ap_con [unfold 8] (f : A → B) {x y z : A} (p : x = y) (q : y = z) :
ap f (p ⬝ q) = ap f p ⬝ ap f q :=
by induction q; reflexivity
definition con_ap_con_eq_con_ap_con_ap (f : A → B) {w x y z : A} (r : f w = f x)
(p : x = y) (q : y = z) : r ⬝ ap f (p ⬝ q) = (r ⬝ ap f p) ⬝ ap f q :=
by induction q; induction p; reflexivity
definition ap_con_con_eq_ap_con_ap_con (f : A → B) {w x y z : A} (p : x = y) (q : y = z)
(r : f z = f w) : ap f (p ⬝ q) ⬝ r = ap f p ⬝ (ap f q ⬝ r) :=
by induction q; induction p; apply con.assoc
-- Functions commute with path inverses.
definition ap_inv' [unfold 6] (f : A → B) {x y : A} (p : x = y) : (ap f p)⁻¹ = ap f p⁻¹ :=
by induction p; reflexivity
definition ap_inv [unfold 6] (f : A → B) {x y : A} (p : x = y) : ap f p⁻¹ = (ap f p)⁻¹ :=
by induction p; reflexivity
-- [ap] itself is functorial in the first argument.
definition ap_id [unfold 4] (p : x = y) : ap id p = p :=
by induction p; reflexivity
definition ap_compose [unfold 8] (g : B → C) (f : A → B) {x y : A} (p : x = y) :
ap (g ∘ f) p = ap g (ap f p) :=
by induction p; reflexivity
-- Sometimes we don't have the actual function [compose].
definition ap_compose' [unfold 8] (g : B → C) (f : A → B) {x y : A} (p : x = y) :
ap (λa, g (f a)) p = ap g (ap f p) :=
by induction p; reflexivity
-- The action of constant maps.
definition ap_constant [unfold 5] (p : x = y) (z : B) : ap (λu, z) p = idp :=
by induction p; reflexivity
-- Naturality of [ap].
-- see also natural_square in cubical.square
definition ap_con_eq_con_ap {f g : A → B} (p : f ~ g) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x ⬝ ap g q :=
by induction q; apply idp_con
-- Naturality of [ap] at identity.
definition ap_con_eq_con {f : A → A} (p : Πx, f x = x) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x ⬝ q :=
by induction q; apply idp_con
definition con_ap_eq_con {f : A → A} (p : Πx, x = f x) {x y : A} (q : x = y) :
p x ⬝ ap f q = q ⬝ p y :=
by induction q; exact !idp_con⁻¹
-- Naturality of [ap] with constant function
definition ap_con_eq {f : A → B} {b : B} (p : Πx, f x = b) {x y : A} (q : x = y) :
ap f q ⬝ p y = p x :=
by induction q; apply idp_con
-- Naturality with other paths hanging around.
definition con_ap_con_con_eq_con_con_ap_con {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{w z : B} (r : w = f x) (s : g y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (ap g q ⬝ s) :=
by induction s; induction q; reflexivity
definition con_ap_con_eq_con_con_ap {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{w : B} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ ap g q :=
by induction q; reflexivity
-- TODO: try this using the simplifier, and compare proofs
definition ap_con_con_eq_con_ap_con {f g : A → B} (p : f ~ g) {x y : A} (q : x = y)
{z : B} (s : g y = z) :
ap f q ⬝ (p y ⬝ s) = p x ⬝ (ap g q ⬝ s) :=
begin
induction s,
induction q,
apply idp_con
end
definition con_ap_con_con_eq_con_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{w z : A} (r : w = f x) (s : y = z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) = (r ⬝ p x) ⬝ (q ⬝ s) :=
by induction s; induction q; reflexivity
definition con_con_ap_con_eq_con_con_con {g : A → A} (p : id ~ g) {x y : A} (q : x = y)
{w z : A} (r : w = x) (s : g y = z) :
(r ⬝ p x) ⬝ (ap g q ⬝ s) = (r ⬝ q) ⬝ (p y ⬝ s) :=
by induction s; induction q; reflexivity
definition con_ap_con_eq_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{w : A} (r : w = f x) :
(r ⬝ ap f q) ⬝ p y = (r ⬝ p x) ⬝ q :=
by induction q; reflexivity
definition ap_con_con_eq_con_con {f : A → A} (p : f ~ id) {x y : A} (q : x = y)
{z : A} (s : y = z) :
ap f q ⬝ (p y ⬝ s) = p x ⬝ (q ⬝ s) :=
by induction s; induction q; apply idp_con
definition con_con_ap_eq_con_con {g : A → A} (p : id ~ g) {x y : A} (q : x = y)
{w : A} (r : w = x) :
(r ⬝ p x) ⬝ ap g q = (r ⬝ q) ⬝ p y :=
begin cases q, exact idp end
definition con_ap_con_eq_con_con' {g : A → A} (p : id ~ g) {x y : A} (q : x = y)
{z : A} (s : g y = z) :
p x ⬝ (ap g q ⬝ s) = q ⬝ (p y ⬝ s) :=
by induction s; induction q; exact !idp_con⁻¹
/- Action of [apd10] and [ap10] on paths -/
-- Application of paths between functions preserves the groupoid structure
definition apd10_idp (f : Πx, P x) (x : A) : apd10 (refl f) x = idp := idp
definition apd10_con {f f' f'' : Πx, P x} (h : f = f') (h' : f' = f'') (x : A) :
apd10 (h ⬝ h') x = apd10 h x ⬝ apd10 h' x :=
by induction h; induction h'; reflexivity
definition apd10_inv {f g : Πx : A, P x} (h : f = g) (x : A) :
apd10 h⁻¹ x = (apd10 h x)⁻¹ :=
by induction h; reflexivity
definition ap10_idp {f : A → B} (x : A) : ap10 (refl f) x = idp := idp
definition ap10_con {f f' f'' : A → B} (h : f = f') (h' : f' = f'') (x : A) :
ap10 (h ⬝ h') x = ap10 h x ⬝ ap10 h' x := apd10_con h h' x
definition ap10_inv {f g : A → B} (h : f = g) (x : A) : ap10 h⁻¹ x = (ap10 h x)⁻¹ :=
apd10_inv h x
-- [ap10] also behaves nicely on paths produced by [ap]
definition ap_ap10 (f g : A → B) (h : B → C) (p : f = g) (a : A) :
ap h (ap10 p a) = ap10 (ap (λ f', h ∘ f') p) a:=
by induction p; reflexivity
/- Transport and the groupoid structure of paths -/
definition idp_tr {P : A → Type} {x : A} (u : P x) : idp ▸ u = u := idp
definition con_tr [unfold 7] {P : A → Type} {x y z : A} (p : x = y) (q : y = z) (u : P x) :
p ⬝ q ▸ u = q ▸ p ▸ u :=
by induction q; reflexivity
definition tr_inv_tr {P : A → Type} {x y : A} (p : x = y) (z : P y) :
p ▸ p⁻¹ ▸ z = z :=
(con_tr p⁻¹ p z)⁻¹ ⬝ ap (λr, transport P r z) (con.left_inv p)
definition inv_tr_tr {P : A → Type} {x y : A} (p : x = y) (z : P x) :
p⁻¹ ▸ p ▸ z = z :=
(con_tr p p⁻¹ z)⁻¹ ⬝ ap (λr, transport P r z) (con.right_inv p)
definition con_tr_lemma {P : A → Type}
{x y z w : A} (p : x = y) (q : y = z) (r : z = w) (u : P x) :
ap (λe, e ▸ u) (con.assoc' p q r) ⬝ (con_tr (p ⬝ q) r u) ⬝
ap (transport P r) (con_tr p q u)
= (con_tr p (q ⬝ r) u) ⬝ (con_tr q r (p ▸ u))
:> ((p ⬝ (q ⬝ r)) ▸ u = r ▸ q ▸ p ▸ u) :=
by induction r; induction q; induction p; reflexivity
-- Here is another coherence lemma for transport.
definition tr_inv_tr_lemma {P : A → Type} {x y : A} (p : x = y) (z : P x) :
tr_inv_tr p (transport P p z) = ap (transport P p) (inv_tr_tr p z) :=
by induction p; reflexivity
/- some properties for apd -/
definition apd_idp (x : A) (f : Πx, P x) : apd f idp = idp :> (f x = f x) := idp
definition apd_con (f : Πx, P x) {x y z : A} (p : x = y) (q : y = z)
: apd f (p ⬝ q) = con_tr p q (f x) ⬝ ap (transport P q) (apd f p) ⬝ apd f q :=
by cases p; cases q; apply idp
definition apd_inv (f : Πx, P x) {x y : A} (p : x = y)
: apd f p⁻¹ = (eq_inv_tr_of_tr_eq (apd f p))⁻¹ :=
by cases p; apply idp
-- Dependent transport in a doubly dependent type.
definition transportD [unfold 6] {P : A → Type} (Q : Πa, P a → Type)
{a a' : A} (p : a = a') (b : P a) (z : Q a b) : Q a' (p ▸ b) :=
by induction p; exact z
-- In Coq the variables P, Q and b are explicit, but in Lean we can probably have them implicit
-- using the following notation
notation p ` ▸D `:65 x:64 := transportD _ p _ x
-- Transporting along higher-dimensional paths
definition transport2 [unfold 7] (P : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : P x) :
p ▸ z = q ▸ z :=
ap (λp', p' ▸ z) r
notation p ` ▸2 `:65 x:64 := transport2 _ p _ x
-- An alternative definition.
definition tr2_eq_ap10 (Q : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : Q x) :
transport2 Q r z = ap10 (ap (transport Q) r) z :=
by induction r; reflexivity
definition tr2_con {P : A → Type} {x y : A} {p1 p2 p3 : x = y}
(r1 : p1 = p2) (r2 : p2 = p3) (z : P x) :
transport2 P (r1 ⬝ r2) z = transport2 P r1 z ⬝ transport2 P r2 z :=
by induction r1; induction r2; reflexivity
definition tr2_inv (Q : A → Type) {x y : A} {p q : x = y} (r : p = q) (z : Q x) :
transport2 Q r⁻¹ z = (transport2 Q r z)⁻¹ :=
by induction r; reflexivity
definition transportD2 [unfold 7] {B C : A → Type} (D : Π(a:A), B a → C a → Type)
{x1 x2 : A} (p : x1 = x2) (y : B x1) (z : C x1) (w : D x1 y z) : D x2 (p ▸ y) (p ▸ z) :=
by induction p; exact w
notation p ` ▸D2 `:65 x:64 := transportD2 _ p _ _ x
definition ap_tr_con_tr2 (P : A → Type) {x y : A} {p q : x = y} {z w : P x} (r : p = q)
(s : z = w) :
ap (transport P p) s ⬝ transport2 P r w = transport2 P r z ⬝ ap (transport P q) s :=
by induction r; exact !idp_con⁻¹
definition fn_tr_eq_tr_fn {P Q : A → Type} {x y : A} (p : x = y) (f : Πx, P x → Q x) (z : P x) :
f y (p ▸ z) = p ▸ f x z :=
by induction p; reflexivity
/- Transporting in particular fibrations -/
/-
From the Coq HoTT library:
One frequently needs lemmas showing that transport in a certain dependent type is equal to some
more explicitly defined operation, defined according to the structure of that dependent type.
For most dependent types, we prove these lemmas in the appropriate file in the types/
subdirectory. Here we consider only the most basic cases.
-/
-- Transporting in a constant fibration.
definition tr_constant (p : x = y) (z : B) : transport (λx, B) p z = z :=
by induction p; reflexivity
definition tr2_constant {p q : x = y} (r : p = q) (z : B) :
tr_constant p z = transport2 (λu, B) r z ⬝ tr_constant q z :=
by induction r; exact !idp_con⁻¹
-- Transporting in a pulled back fibration.
definition tr_compose (P : B → Type) (f : A → B) (p : x = y) (z : P (f x)) :
transport (P ∘ f) p z = transport P (ap f p) z :=
by induction p; reflexivity
definition ap_precompose (f : A → B) (g g' : B → C) (p : g = g') :
ap (λh, h ∘ f) p = transport (λh : B → C, g ∘ f = h ∘ f) p idp :=
by induction p; reflexivity
definition apd10_ap_precompose (f : A → B) (g g' : B → C) (p : g = g') :
apd10 (ap (λh : B → C, h ∘ f) p) = λa, apd10 p (f a) :=
by induction p; reflexivity
definition apd10_ap_precompose_dependent {C : B → Type}
(f : A → B) {g g' : Πb : B, C b} (p : g = g')
: apd10 (ap (λ(h : (Πb : B, C b))(a : A), h (f a)) p) = λa, apd10 p (f a) :=
by induction p; reflexivity
definition apd10_ap_postcompose (f : B → C) (g g' : A → B) (p : g = g') :
apd10 (ap (λh : A → B, f ∘ h) p) = λa, ap f (apd10 p a) :=
by induction p; reflexivity
-- A special case of [tr_compose] which seems to come up a lot.
definition tr_eq_cast_ap {P : A → Type} {x y} (p : x = y) (u : P x) : p ▸ u = cast (ap P p) u :=
by induction p; reflexivity
definition tr_eq_cast_ap_fn {P : A → Type} {x y} (p : x = y) : transport P p = cast (ap P p) :=
by induction p; reflexivity
/- The behavior of [ap] and [apd] -/
-- In a constant fibration, [apd] reduces to [ap], modulo [transport_const].
definition apd_eq_tr_constant_con_ap (f : A → B) (p : x = y) :
apd f p = tr_constant p (f x) ⬝ ap f p :=
by induction p; reflexivity
/- The 2-dimensional groupoid structure -/
-- Horizontal composition of 2-dimensional paths.
definition concat2 [unfold 9 10] {p p' : x = y} {q q' : y = z} (h : p = p') (h' : q = q')
: p ⬝ q = p' ⬝ q' :=
ap011 concat h h'
-- 2-dimensional path inversion
definition inverse2 [unfold 6] {p q : x = y} (h : p = q) : p⁻¹ = q⁻¹ :=
ap inverse h
infixl ` ◾ `:75 := concat2
postfix [parsing_only] `⁻²`:(max+10) := inverse2 --this notation is abusive, should we use it?
/- Whiskering -/
definition whisker_left [unfold 8] (p : x = y) {q r : y = z} (h : q = r) : p ⬝ q = p ⬝ r :=
idp ◾ h
definition whisker_right [unfold 7] {p q : x = y} (h : p = q) (r : y = z) : p ⬝ r = q ⬝ r :=
h ◾ idp
-- Unwhiskering, a.k.a. cancelling
definition cancel_left {x y z : A} (p : x = y) {q r : y = z} : (p ⬝ q = p ⬝ r) → (q = r) :=
λs, !inv_con_cancel_left⁻¹ ⬝ whisker_left p⁻¹ s ⬝ !inv_con_cancel_left
definition cancel_right {x y z : A} {p q : x = y} (r : y = z) : (p ⬝ r = q ⬝ r) → (p = q) :=
λs, !con_inv_cancel_right⁻¹ ⬝ whisker_right s r⁻¹ ⬝ !con_inv_cancel_right
-- Whiskering and identity paths.
definition whisker_right_idp {p q : x = y} (h : p = q) :
whisker_right h idp = h :=
by induction h; induction p; reflexivity
definition whisker_right_idp_left [unfold_full] (p : x = y) (q : y = z) :
whisker_right idp q = idp :> (p ⬝ q = p ⬝ q) :=
idp
definition whisker_left_idp_right [unfold_full] (p : x = y) (q : y = z) :
whisker_left p idp = idp :> (p ⬝ q = p ⬝ q) :=
idp
definition whisker_left_idp {p q : x = y} (h : p = q) :
(idp_con p)⁻¹ ⬝ whisker_left idp h ⬝ idp_con q = h :=
by induction h; induction p; reflexivity
definition whisker_left_idp2 {A : Type} {a : A} (p : idp = idp :> a = a) :
whisker_left idp p = p :=
begin
refine _ ⬝ whisker_left_idp p,
exact !idp_con⁻¹
end
definition con2_idp [unfold_full] {p q : x = y} (h : p = q) :
h ◾ idp = whisker_right h idp :> (p ⬝ idp = q ⬝ idp) :=
idp
definition idp_con2 [unfold_full] {p q : x = y} (h : p = q) :
idp ◾ h = whisker_left idp h :> (idp ⬝ p = idp ⬝ q) :=
idp
definition inverse2_concat2 {p p' : x = y} (h : p = p')
: h⁻² ◾ h = con.left_inv p ⬝ (con.left_inv p')⁻¹ :=
by induction h; induction p; reflexivity
-- The interchange law for concatenation.
definition con2_con_con2 {p p' p'' : x = y} {q q' q'' : y = z}
(a : p = p') (b : p' = p'') (c : q = q') (d : q' = q'') :
(a ◾ c) ⬝ (b ◾ d) = (a ⬝ b) ◾ (c ⬝ d) :=
by induction d; induction c; induction b;induction a; reflexivity
definition concat2_eq_rl {A : Type} {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') : a ◾ b = whisker_right a q ⬝ whisker_left p' b :=
by induction b; induction a; reflexivity
definition concat2_eq_lf {A : Type} {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') : a ◾ b = whisker_left p b ⬝ whisker_right a q' :=
by induction b; induction a; reflexivity
definition whisker_right_con_whisker_left {x y z : A} {p p' : x = y} {q q' : y = z}
(a : p = p') (b : q = q') :
(whisker_right a q) ⬝ (whisker_left p' b) = (whisker_left p b) ⬝ (whisker_right a q') :=
by induction b; induction a; reflexivity
-- Structure corresponding to the coherence equations of a bicategory.
-- The "pentagonator": the 3-cell witnessing the associativity pentagon.
definition pentagon {v w x y z : A} (p : v = w) (q : w = x) (r : x = y) (s : y = z) :
whisker_left p (con.assoc' q r s)
⬝ con.assoc' p (q ⬝ r) s
⬝ whisker_right (con.assoc' p q r) s
= con.assoc' p q (r ⬝ s) ⬝ con.assoc' (p ⬝ q) r s :=
by induction s;induction r;induction q;induction p;reflexivity
-- The 3-cell witnessing the left unit triangle.
definition triangulator (p : x = y) (q : y = z) :
con.assoc' p idp q ⬝ whisker_right (con_idp p) q = whisker_left p (idp_con q) :=
by induction q; induction p; reflexivity
definition eckmann_hilton {x:A} (p q : idp = idp :> x = x) : p ⬝ q = q ⬝ p :=
begin
refine (whisker_right_idp p ◾ whisker_left_idp2 q)⁻¹ ⬝ _,
refine !whisker_right_con_whisker_left ⬝ _,
refine !whisker_left_idp2 ◾ !whisker_right_idp
end
definition concat_eq_concat2 {A : Type} {a : A} (p q : idp = idp :> a = a) : p ⬝ q = p ◾ q :=
begin
refine (whisker_right_idp p ◾ whisker_left_idp2 q)⁻¹ ⬝ _,
exact !concat2_eq_rl⁻¹
end
definition inverse_eq_inverse2 {A : Type} {a : A} (p : idp = idp :> a = a) : p⁻¹ = p⁻² :=
begin
apply eq.cancel_right p,
refine !con.left_inv ⬝ _,
refine _ ⬝ !concat_eq_concat2⁻¹,
exact !inverse2_concat2⁻¹,
end
-- The action of functions on 2-dimensional paths
definition ap02 [unfold 8] [reducible] (f : A → B) {x y : A} {p q : x = y} (r : p = q)
: ap f p = ap f q :=
ap (ap f) r
definition ap02_con (f : A → B) {x y : A} {p p' p'' : x = y} (r : p = p') (r' : p' = p'') :
ap02 f (r ⬝ r') = ap02 f r ⬝ ap02 f r' :=
by induction r; induction r'; reflexivity
definition ap02_con2 (f : A → B) {x y z : A} {p p' : x = y} {q q' :y = z} (r : p = p')
(s : q = q') :
ap02 f (r ◾ s) = ap_con f p q
⬝ (ap02 f r ◾ ap02 f s)
⬝ (ap_con f p' q')⁻¹ :=
by induction r; induction s; induction q; induction p; reflexivity
definition apd02 [unfold 8] {p q : x = y} (f : Π x, P x) (r : p = q) :
apd f p = transport2 P r (f x) ⬝ apd f q :=
by induction r; exact !idp_con⁻¹
-- And now for a lemma whose statement is much longer than its proof.
definition apd02_con {P : A → Type} (f : Π x:A, P x) {x y : A}
{p1 p2 p3 : x = y} (r1 : p1 = p2) (r2 : p2 = p3) :
apd02 f (r1 ⬝ r2) = apd02 f r1
⬝ whisker_left (transport2 P r1 (f x)) (apd02 f r2)
⬝ con.assoc' _ _ _
⬝ (whisker_right (tr2_con r1 r2 (f x))⁻¹ (apd f p3)) :=
by induction r2; induction r1; induction p1; reflexivity
end eq
|
15c3a6697a4c975f75e6dcee0fb331151e3d97a2
|
92b50235facfbc08dfe7f334827d47281471333b
|
/library/data/real/default.lean
|
1940618c48462395f53e30524e6a6e56fcd8d447
|
[
"Apache-2.0"
] |
permissive
|
htzh/lean
|
24f6ed7510ab637379ec31af406d12584d31792c
|
d70c79f4e30aafecdfc4a60b5d3512199200ab6e
|
refs/heads/master
| 1,607,677,731,270
| 1,437,089,952,000
| 1,437,089,952,000
| 37,078,816
| 0
| 0
| null | 1,433,780,956,000
| 1,433,780,955,000
| null |
UTF-8
|
Lean
| false
| false
| 182
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
-/
import .basic .order
|
3c3519e2b60e13b0f755957efee596e3aba87a6c
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/blast_simp_subsingleton2.lean
|
f8fd199462c800a7cd0c0a46f1bb875fb08c25ef
|
[
"Apache-2.0"
] |
permissive
|
soonhokong/lean
|
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
|
38607e3eb57f57f77c0ac114ad169e9e4262e24f
|
refs/heads/master
| 1,611,187,284,081
| 1,450,766,737,000
| 1,476,122,547,000
| 11,513,992
| 2
| 0
| null | 1,401,763,102,000
| 1,374,182,235,000
|
C++
|
UTF-8
|
Lean
| false
| false
| 312
|
lean
|
import data.unit
open nat unit
constant r {A B : Type} : A → B → A
example (a b c d : unit) : r a b = r c d :=
by simp
example (a b : unit) : a = b :=
by simp
example (a b : unit) : (λ x : nat, a) = (λ y : nat, b) :=
by simp
example (a b : unit) : (λ x : nat, r a b) = (λ y : nat, r b b) :=
by simp
|
b3f35ac18e65734764e6b54e0d9b4650cfe1609f
|
206422fb9edabf63def0ed2aa3f489150fb09ccb
|
/src/category_theory/eq_to_hom.lean
|
cff79fe70c90b9de0dd7e818e39a9a98c9dae7b3
|
[
"Apache-2.0"
] |
permissive
|
hamdysalah1/mathlib
|
b915f86b2503feeae268de369f1b16932321f097
|
95454452f6b3569bf967d35aab8d852b1ddf8017
|
refs/heads/master
| 1,677,154,116,545
| 1,611,797,994,000
| 1,611,797,994,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,971
|
lean
|
/-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Scott Morrison
-/
import category_theory.opposites
universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
namespace category_theory
open opposite
variables {C : Type u₁} [category.{v₁} C]
/--
An equality `X = Y` gives us a morphism `X ⟶ Y`.
It is typically better to use this, rather than rewriting by the equality then using `𝟙 _`
which usually leads to dependent type theory hell.
-/
def eq_to_hom {X Y : C} (p : X = Y) : X ⟶ Y := by rw p; exact 𝟙 _
@[simp] lemma eq_to_hom_refl (X : C) (p : X = X) : eq_to_hom p = 𝟙 X := rfl
@[simp, reassoc] lemma eq_to_hom_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eq_to_hom p ≫ eq_to_hom q = eq_to_hom (p.trans q) :=
by cases p; cases q; simp
/--
An equality `X = Y` gives us a morphism `X ⟶ Y`.
It is typically better to use this, rather than rewriting by the equality then using `iso.refl _`
which usually leads to dependent type theory hell.
-/
def eq_to_iso {X Y : C} (p : X = Y) : X ≅ Y :=
⟨eq_to_hom p, eq_to_hom p.symm, by simp, by simp⟩
@[simp] lemma eq_to_iso.hom {X Y : C} (p : X = Y) : (eq_to_iso p).hom = eq_to_hom p :=
rfl
@[simp] lemma eq_to_iso.inv {X Y : C} (p : X = Y) : (eq_to_iso p).inv = eq_to_hom p.symm :=
rfl
@[simp] lemma eq_to_iso_refl {X : C} (p : X = X) : eq_to_iso p = iso.refl X := rfl
@[simp] lemma eq_to_iso_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eq_to_iso p ≪≫ eq_to_iso q = eq_to_iso (p.trans q) :=
by ext; simp
@[simp] lemma eq_to_hom_op {X Y : C} (h : X = Y) :
(eq_to_hom h).op = eq_to_hom (congr_arg op h.symm) :=
by { cases h, refl, }
@[simp] lemma eq_to_hom_unop {X Y : Cᵒᵖ} (h : X = Y) :
(eq_to_hom h).unop = eq_to_hom (congr_arg unop h.symm) :=
by { cases h, refl, }
instance {X Y : C} (h : X = Y) : is_iso (eq_to_hom h) := { .. eq_to_iso h }
@[simp] lemma inv_eq_to_hom {X Y : C} (h : X = Y) : inv (eq_to_hom h) = eq_to_hom h.symm := rfl
variables {D : Type u₂} [category.{v₂} D]
namespace functor
/-- Proving equality between functors. This isn't an extensionality lemma,
because usually you don't really want to do this. -/
lemma ext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ X Y f, F.map f = eq_to_hom (h_obj X) ≫ G.map f ≫ eq_to_hom (h_obj Y).symm) :
F = G :=
begin
cases F with F_obj _ _ _, cases G with G_obj _ _ _,
have : F_obj = G_obj, by ext X; apply h_obj,
subst this,
congr,
funext X Y f,
simpa using h_map X Y f
end
/-- Proving equality between functors using heterogeneous equality. -/
lemma hext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ X Y (f : X ⟶ Y), F.map f == G.map f) : F = G :=
begin
cases F with F_obj _ _ _, cases G with G_obj _ _ _,
have : F_obj = G_obj, by ext X; apply h_obj,
subst this,
congr,
funext X Y f,
exact eq_of_heq (h_map X Y f)
end
-- Using equalities between functors.
lemma congr_obj {F G : C ⥤ D} (h : F = G) (X) : F.obj X = G.obj X :=
by subst h
lemma congr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) :
F.map f = eq_to_hom (congr_obj h X) ≫ G.map f ≫ eq_to_hom (congr_obj h Y).symm :=
by subst h; simp
end functor
@[simp] lemma eq_to_hom_map (F : C ⥤ D) {X Y : C} (p : X = Y) :
F.map (eq_to_hom p) = eq_to_hom (congr_arg F.obj p) :=
by cases p; simp
@[simp] lemma eq_to_iso_map (F : C ⥤ D) {X Y : C} (p : X = Y) :
F.map_iso (eq_to_iso p) = eq_to_iso (congr_arg F.obj p) :=
by ext; cases p; simp
@[simp] lemma eq_to_hom_app {F G : C ⥤ D} (h : F = G) (X : C) :
(eq_to_hom h : F ⟶ G).app X = eq_to_hom (functor.congr_obj h X) :=
by subst h; refl
lemma nat_trans.congr {F G : C ⥤ D} (α : F ⟶ G) {X Y : C} (h : X = Y) :
α.app X = F.map (eq_to_hom h) ≫ α.app Y ≫ G.map (eq_to_hom h.symm) :=
by { rw [α.naturality_assoc], simp }
end category_theory
|
acef14fefc70bc15313a40d3be3386758b1e8445
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/src/model_theory/fraisse.lean
|
4b8b79d05201fb9d215b7dffdb81c57a6f740b53
|
[
"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
| 13,586
|
lean
|
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import model_theory.finitely_generated
import model_theory.direct_limit
import model_theory.bundled
/-!
# Fraïssé Classes and Fraïssé Limits
This file pertains to the ages of countable first-order structures. The age of a structure is the
class of all finitely-generated structures that embed into it.
Of particular interest are Fraïssé classes, which are exactly the ages of countable
ultrahomogeneous structures. To each is associated a unique (up to nonunique isomorphism)
Fraïssé limit - the countable ultrahomogeneous structure with that age.
## Main Definitions
* `first_order.language.age` is the class of finitely-generated structures that embed into a
particular structure.
* A class `K` has the `first_order.language.hereditary` when all finitely-generated
structures that embed into structures in `K` are also in `K`.
* A class `K` has the `first_order.language.joint_embedding` when for every `M`, `N` in
`K`, there is another structure in `K` into which both `M` and `N` embed.
* A class `K` has the `first_order.language.amalgamation` when for any pair of embeddings
of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a
fourth structure in `K` such that the resulting square of embeddings commutes.
* `first_order.language.is_fraisse` indicates that a class is nonempty, isomorphism-invariant,
essentially countable, and satisfies the hereditary, joint embedding, and amalgamation properties.
* `first_order.language.is_fraisse_limit` indicates that a structure is a Fraïssé limit for a given
class.
## Main Results
* We show that the age of any structure is isomorphism-invariant and satisfies the hereditary and
joint-embedding properties.
* `first_order.language.age.countable_quotient` shows that the age of any countable structure is
essentially countable.
* `first_order.language.exists_countable_is_age_of_iff` gives necessary and sufficient conditions
for a class to be the age of a countable structure in a language with countably many functions.
## Implementation Notes
* Classes of structures are formalized with `set (bundled L.Structure)`.
* Some results pertain to countable limit structures, others to countably-generated limit
structures. In the case of a language with countably many function symbols, these are equivalent.
## References
- [W. Hodges, *A Shorter Model Theory*][Hodges97]
- [K. Tent, M. Ziegler, *A Course in Model Theory*][Tent_Ziegler]
## TODO
* Show existence and uniqueness of Fraïssé limits
-/
universes u v w w'
open_locale first_order
open set category_theory
namespace first_order
namespace language
open Structure substructure
variables (L : language.{u v})
/-! ### The Age of a Structure and Fraïssé Classes-/
/-- The age of a structure `M` is the class of finitely-generated structures that embed into it. -/
def age (M : Type w) [L.Structure M] : set (bundled.{w} L.Structure) :=
{ N | Structure.fg L N ∧ nonempty (N ↪[L] M) }
variables {L} (K : set (bundled.{w} L.Structure))
/-- A class `K` has the hereditary property when all finitely-generated structures that embed into
structures in `K` are also in `K`. -/
def hereditary : Prop :=
∀ (M : bundled.{w} L.Structure), M ∈ K → L.age M ⊆ K
/-- A class `K` has the joint embedding property when for every `M`, `N` in `K`, there is another
structure in `K` into which both `M` and `N` embed. -/
def joint_embedding : Prop :=
directed_on (λ M N : bundled.{w} L.Structure, nonempty (M ↪[L] N)) K
/-- A class `K` has the amalgamation property when for any pair of embeddings of a structure `M` in
`K` into other structures in `K`, those two structures can be embedded into a fourth structure in
`K` such that the resulting square of embeddings commutes. -/
def amalgamation : Prop :=
∀ (M N P : bundled.{w} L.Structure) (MN : M ↪[L] N) (MP : M ↪[L] P), M ∈ K → N ∈ K → P ∈ K →
∃ (Q : bundled.{w} L.Structure) (NQ : N ↪[L] Q) (PQ : P ↪[L] Q), Q ∈ K ∧ NQ.comp MN = PQ.comp MP
/-- A Fraïssé class is a nonempty, isomorphism-invariant, essentially countable class of structures
satisfying the hereditary, joint embedding, and amalgamation properties. -/
class is_fraisse : Prop :=
(is_nonempty : K.nonempty)
(fg : ∀ M : bundled.{w} L.Structure, M ∈ K → Structure.fg L M)
(is_equiv_invariant : ∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K))
(is_essentially_countable : (quotient.mk '' K).countable)
(hereditary : hereditary K)
(joint_embedding : joint_embedding K)
(amalgamation : amalgamation K)
variables {K} (L) (M : Type w) [L.Structure M]
lemma age.is_equiv_invariant (N P : bundled.{w} L.Structure) (h : nonempty (N ≃[L] P)) :
N ∈ L.age M ↔ P ∈ L.age M :=
and_congr h.some.fg_iff
⟨nonempty.map (λ x, embedding.comp x h.some.symm.to_embedding),
nonempty.map (λ x, embedding.comp x h.some.to_embedding)⟩
variables {L} {M} {N : Type w} [L.Structure N]
lemma embedding.age_subset_age (MN : M ↪[L] N) : L.age M ⊆ L.age N :=
λ _, and.imp_right (nonempty.map MN.comp)
lemma equiv.age_eq_age (MN : M ≃[L] N) : L.age M = L.age N :=
le_antisymm MN.to_embedding.age_subset_age MN.symm.to_embedding.age_subset_age
lemma Structure.fg.mem_age_of_equiv {M N : bundled L.Structure} (h : Structure.fg L M)
(MN : nonempty (M ≃[L] N)) : N ∈ L.age M :=
⟨MN.some.fg_iff.1 h, ⟨MN.some.symm.to_embedding⟩⟩
lemma hereditary.is_equiv_invariant_of_fg (h : hereditary K)
(fg : ∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M)
(M N : bundled.{w} L.Structure) (hn : nonempty (M ≃[L] N)) : M ∈ K ↔ N ∈ K :=
⟨λ MK, h M MK ((fg M MK).mem_age_of_equiv hn),
λ NK, h N NK ((fg N NK).mem_age_of_equiv ⟨hn.some.symm⟩)⟩
variable (M)
lemma age.nonempty : (L.age M).nonempty :=
⟨bundled.of (substructure.closure L (∅ : set M)),
(fg_iff_Structure_fg _).1 (fg_closure set.finite_empty), ⟨substructure.subtype _⟩⟩
lemma age.hereditary : hereditary (L.age M) :=
λ N hN P hP, hN.2.some.age_subset_age hP
lemma age.joint_embedding : joint_embedding (L.age M) :=
λ N hN P hP, ⟨bundled.of ↥(hN.2.some.to_hom.range ⊔ hP.2.some.to_hom.range),
⟨(fg_iff_Structure_fg _).1 ((hN.1.range hN.2.some.to_hom).sup (hP.1.range hP.2.some.to_hom)),
⟨subtype _⟩⟩,
⟨embedding.comp (inclusion le_sup_left) hN.2.some.equiv_range.to_embedding⟩,
⟨embedding.comp (inclusion le_sup_right) hP.2.some.equiv_range.to_embedding⟩⟩
/-- The age of a countable structure is essentially countable (has countably many isomorphism
classes). -/
lemma age.countable_quotient (h : (univ : set M).countable) :
(quotient.mk '' (L.age M)).countable :=
begin
refine eq.mp (congr rfl (set.ext _)) ((countable_set_of_finite_subset h).image
(λ s, ⟦⟨closure L s, infer_instance⟩⟧)),
rw forall_quotient_iff,
intro N,
simp only [subset_univ, and_true, mem_image, mem_set_of_eq, quotient.eq],
split,
{ rintro ⟨s, hs1, hs2⟩,
use bundled.of ↥(closure L s),
exact ⟨⟨(fg_iff_Structure_fg _).1 (fg_closure hs1), ⟨subtype _⟩⟩, hs2⟩ },
{ rintro ⟨P, ⟨⟨s, hs⟩, ⟨PM⟩⟩, hP2⟩,
refine ⟨PM '' s, set.finite.image PM s.finite_to_set, setoid.trans _ hP2⟩,
rw [← embedding.coe_to_hom, closure_image PM.to_hom, hs, ← hom.range_eq_map],
exact ⟨PM.equiv_range.symm⟩ }
end
/-- The age of a direct limit of structures is the union of the ages of the structures. -/
@[simp] theorem age_direct_limit {ι : Type w} [preorder ι] [is_directed ι (≤)] [nonempty ι]
(G : ι → Type (max w w')) [Π i, L.Structure (G i)]
(f : Π i j, i ≤ j → G i ↪[L] G j) [directed_system G (λ i j h, f i j h)] :
L.age (direct_limit G f) = ⋃ (i : ι), L.age (G i) :=
begin
classical,
ext M,
simp only [mem_Union],
split,
{ rintro ⟨Mfg, ⟨e⟩⟩,
obtain ⟨s, hs⟩ := Mfg.range e.to_hom,
let out := @quotient.out _ (direct_limit.setoid G f),
obtain ⟨i, hi⟩ := finset.exists_le (s.image (sigma.fst ∘ out)),
have e' := ((direct_limit.of L ι G f i).equiv_range.symm.to_embedding),
refine ⟨i, Mfg, ⟨e'.comp ((substructure.inclusion _).comp e.equiv_range.to_embedding)⟩⟩,
rw [← hs, closure_le],
intros x hx,
refine ⟨f (out x).1 i (hi (out x).1 (finset.mem_image_of_mem _ hx)) (out x).2, _⟩,
rw [embedding.coe_to_hom, direct_limit.of_apply, quotient.mk_eq_iff_out,
direct_limit.equiv_iff G f _
(hi (out x).1 (finset.mem_image_of_mem _ hx)), directed_system.map_self],
refl },
{ rintro ⟨i, Mfg, ⟨e⟩⟩,
exact ⟨Mfg, ⟨embedding.comp (direct_limit.of L ι G f i) e⟩⟩ }
end
/-- Sufficient conditions for a class to be the age of a countably-generated structure. -/
theorem exists_cg_is_age_of (hn : K.nonempty)
(h : ∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K))
(hc : (quotient.mk '' K).countable)
(fg : ∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M)
(hp : hereditary K)
(jep : joint_embedding K) :
∃ (M : bundled.{w} L.Structure), Structure.cg L M ∧ L.age M = K :=
begin
obtain ⟨F, hF⟩ := hc.exists_eq_range (hn.image _),
simp only [set.ext_iff, forall_quotient_iff, mem_image, mem_range, quotient.eq] at hF,
simp_rw [quotient.eq_mk_iff_out] at hF,
have hF' : ∀ n : ℕ, (F n).out ∈ K,
{ intro n,
obtain ⟨P, hP1, hP2⟩ := (hF (F n).out).2 ⟨n, setoid.refl _⟩,
exact (h _ _ hP2).1 hP1 },
choose P hPK hP hFP using (λ (N : K) (n : ℕ), jep N N.2 (F (n + 1)).out (hF' _)),
let G : ℕ → K := @nat.rec (λ _, K) (⟨(F 0).out, hF' 0⟩) (λ n N, ⟨P N n, hPK N n⟩),
let f : Π (i j), i ≤ j → G i ↪[L] G j :=
directed_system.nat_le_rec (λ n, (hP _ n).some),
refine ⟨bundled.of (direct_limit (λ n, G n) f), direct_limit.cg _ (λ n, (fg _ (G n).2).cg),
(age_direct_limit _ _).trans (subset_antisymm
(Union_subset (λ n N hN, hp (G n) (G n).2 hN)) (λ N KN, _))⟩,
obtain ⟨n, ⟨e⟩⟩ := (hF N).1 ⟨N, KN, setoid.refl _⟩,
refine mem_Union_of_mem n ⟨fg _ KN, ⟨embedding.comp _ e.symm.to_embedding⟩⟩,
cases n,
{ exact embedding.refl _ _ },
{ exact (hFP _ n).some }
end
theorem exists_countable_is_age_of_iff [L.countable_functions] :
(∃ (M : bundled.{w} L.Structure), (univ : set M).countable ∧ L.age M = K) ↔
K.nonempty ∧
(∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) ∧
(quotient.mk '' K).countable ∧
(∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M) ∧
hereditary K ∧
joint_embedding K :=
begin
split,
{ rintros ⟨M, h1, h2, rfl⟩,
resetI,
refine ⟨age.nonempty M, age.is_equiv_invariant L M, age.countable_quotient M h1, λ N hN, hN.1,
age.hereditary M, age.joint_embedding M⟩, },
{ rintros ⟨Kn, eqinv, cq, hfg, hp, jep⟩,
obtain ⟨M, hM, rfl⟩ := exists_cg_is_age_of Kn eqinv cq hfg hp jep,
haveI := ((Structure.cg_iff_countable).1 hM).some,
refine ⟨M, to_countable _, rfl⟩, }
end
variables {K} (L) (M)
/-- A structure `M` is ultrahomogeneous if every embedding of a finitely generated substructure
into `M` extends to an automorphism of `M`. -/
def is_ultrahomogeneous : Prop :=
∀ (S : L.substructure M) (hs : S.fg) (f : S ↪[L] M),
∃ (g : M ≃[L] M), f = g.to_embedding.comp S.subtype
variables {L} (K)
/-- A structure `M` is a Fraïssé limit for a class `K` if it is countably generated,
ultrahomogeneous, and has age `K`. -/
structure is_fraisse_limit [countable_functions L] : Prop :=
(ultrahomogeneous : is_ultrahomogeneous L M)
(countable : (univ : set M).countable)
(age : L.age M = K)
variables {L} {M}
lemma is_ultrahomogeneous.amalgamation_age (h : L.is_ultrahomogeneous M) :
amalgamation (L.age M) :=
begin
rintros N P Q NP NQ ⟨Nfg, ⟨NM⟩⟩ ⟨Pfg, ⟨PM⟩⟩ ⟨Qfg, ⟨QM⟩⟩,
obtain ⟨g, hg⟩ := h ((PM.comp NP).to_hom.range) (Nfg.range _)
((QM.comp NQ).comp (PM.comp NP).equiv_range.symm.to_embedding),
let s := (g.to_hom.comp PM.to_hom).range ⊔ QM.to_hom.range,
refine ⟨bundled.of s, embedding.comp (substructure.inclusion le_sup_left)
((g.to_embedding.comp PM).equiv_range).to_embedding,
embedding.comp (substructure.inclusion le_sup_right) QM.equiv_range.to_embedding,
⟨(fg_iff_Structure_fg _).1 (fg.sup (Pfg.range _) (Qfg.range _)), ⟨substructure.subtype _⟩⟩, _⟩,
ext n,
have hgn := (embedding.ext_iff.1 hg) ((PM.comp NP).equiv_range n),
simp only [embedding.comp_apply, equiv.coe_to_embedding, equiv.symm_apply_apply,
substructure.coe_subtype, embedding.equiv_range_apply] at hgn,
simp only [embedding.comp_apply, equiv.coe_to_embedding, substructure.coe_inclusion,
set.coe_inclusion, embedding.equiv_range_apply, hgn],
end
lemma is_ultrahomogeneous.age_is_fraisse (hc : (univ : set M).countable)
(h : L.is_ultrahomogeneous M) :
is_fraisse (L.age M) :=
⟨age.nonempty M, λ _ hN, hN.1, age.is_equiv_invariant L M, age.countable_quotient M hc,
age.hereditary M, age.joint_embedding M, h.amalgamation_age⟩
namespace is_fraisse_limit
/-- If a class has a Fraïssé limit, it must be Fraïssé. -/
theorem is_fraisse [countable_functions L] (h : is_fraisse_limit K M) : is_fraisse K :=
(congr rfl h.age).mp (h.ultrahomogeneous.age_is_fraisse h.countable)
end is_fraisse_limit
end language
end first_order
|
5f6a7413af017571ee6a4a435efad470f810f25d
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/634b.lean
|
097699ca2832392b6b9112617c9e6e12bc3749ca
|
[
"Apache-2.0"
] |
permissive
|
soonhokong/lean
|
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
|
38607e3eb57f57f77c0ac114ad169e9e4262e24f
|
refs/heads/master
| 1,611,187,284,081
| 1,450,766,737,000
| 1,476,122,547,000
| 11,513,992
| 2
| 0
| null | 1,401,763,102,000
| 1,374,182,235,000
|
C++
|
UTF-8
|
Lean
| false
| false
| 903
|
lean
|
open nat
namespace foo
section
parameter (X : Type₁)
definition A {n : ℕ} : Type₁ := X
definition B : Type₁ := X
variable {n : ℕ}
check @A n
check foo.A nat
check foo.A (X × B)
check @foo.A (X × B) 10
check @foo.A (@foo.B (@A n)) n
check @foo.A (@foo.B (@foo.A X n)) n
check @foo.A (@foo.B (@foo.A nat n)) n
set_option pp.full_names true
check A
check foo.A nat
check @foo.A (X × B) 10
check @foo.A (@foo.B (@foo.A X n)) n
check @foo.A (@foo.B (@foo.A nat n)) n
set_option pp.full_names false
set_option pp.implicit true
check @A n
check @foo.A nat 10
check @foo.A X n
set_option pp.full_names true
check @foo.A X n
check @A n
set_option pp.full_names false
check @foo.A X n
check @foo.A B n
check @foo.A (@foo.B (@A n)) n
check @foo.A (@foo.B (@foo.A X n)) n
check @foo.A (@foo.B (@foo.A nat n)) n
check @A n
end
end foo
|
072329bdff89c9d60c0eaa1ead7532c9b9bdee22
|
367134ba5a65885e863bdc4507601606690974c1
|
/src/data/finset/gcd.lean
|
d8d0ddc7e39ed72a39cf0b5bad0791e659374ce2
|
[
"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
| 7,008
|
lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Aaron Anderson
-/
import data.finset.fold
import data.multiset.gcd
/-!
# GCD and LCM operations on finsets
## Main definitions
- `finset.gcd` - the greatest common denominator of a `finset` of elements of a `gcd_monoid`
- `finset.lcm` - the least common multiple of a `finset` of elements of a `gcd_monoid`
## Implementation notes
Many of the proofs use the lemmas `gcd.def` and `lcm.def`, which relate `finset.gcd`
and `finset.lcm` to `multiset.gcd` and `multiset.lcm`.
TODO: simplify with a tactic and `data.finset.lattice`
## Tags
finset, gcd
-/
variables {α β γ : Type*}
namespace finset
open multiset
variables [comm_cancel_monoid_with_zero α] [nontrivial α] [gcd_monoid α]
/-! ### lcm -/
section lcm
/-- Least common multiple of a finite set -/
def lcm (s : finset β) (f : β → α) : α := s.fold gcd_monoid.lcm 1 f
variables {s s₁ s₂ : finset β} {f : β → α}
lemma lcm_def : s.lcm f = (s.1.map f).lcm := rfl
@[simp] lemma lcm_empty : (∅ : finset β).lcm f = 1 :=
fold_empty
@[simp] lemma lcm_dvd_iff {a : α} : s.lcm f ∣ a ↔ (∀b ∈ s, f b ∣ a) :=
begin
apply iff.trans multiset.lcm_dvd,
simp only [multiset.mem_map, and_imp, exists_imp_distrib],
exact ⟨λ k b hb, k _ _ hb rfl, λ k a' b hb h, h ▸ k _ hb⟩,
end
lemma lcm_dvd {a : α} : (∀b ∈ s, f b ∣ a) → s.lcm f ∣ a :=
lcm_dvd_iff.2
lemma dvd_lcm {b : β} (hb : b ∈ s) : f b ∣ s.lcm f :=
lcm_dvd_iff.1 (dvd_refl _) _ hb
@[simp] lemma lcm_insert [decidable_eq β] {b : β} :
(insert b s : finset β).lcm f = gcd_monoid.lcm (f b) (s.lcm f) :=
begin
by_cases h : b ∈ s,
{ rw [insert_eq_of_mem h,
(lcm_eq_right_iff (f b) (s.lcm f) (multiset.normalize_lcm (s.1.map f))).2 (dvd_lcm h)] },
apply fold_insert h,
end
@[simp] lemma lcm_singleton {b : β} : ({b} : finset β).lcm f = normalize (f b) :=
multiset.lcm_singleton
@[simp] lemma normalize_lcm : normalize (s.lcm f) = s.lcm f := by simp [lcm_def]
lemma lcm_union [decidable_eq β] : (s₁ ∪ s₂).lcm f = gcd_monoid.lcm (s₁.lcm f) (s₂.lcm f) :=
finset.induction_on s₁ (by rw [empty_union, lcm_empty, lcm_one_left, normalize_lcm]) $ λ a s has ih,
by rw [insert_union, lcm_insert, lcm_insert, ih, lcm_assoc]
theorem lcm_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a ∈ s₂, f a = g a) :
s₁.lcm f = s₂.lcm g :=
by { subst hs, exact finset.fold_congr hfg }
lemma lcm_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.lcm f ∣ s.lcm g :=
lcm_dvd (λ b hb, dvd_trans (h b hb) (dvd_lcm hb))
lemma lcm_mono (h : s₁ ⊆ s₂) : s₁.lcm f ∣ s₂.lcm f :=
lcm_dvd $ assume b hb, dvd_lcm (h hb)
end lcm
/-! ### gcd -/
section gcd
/-- Greatest common divisor of a finite set -/
def gcd (s : finset β) (f : β → α) : α := s.fold gcd_monoid.gcd 0 f
variables {s s₁ s₂ : finset β} {f : β → α}
lemma gcd_def : s.gcd f = (s.1.map f).gcd := rfl
@[simp] lemma gcd_empty : (∅ : finset β).gcd f = 0 :=
fold_empty
lemma dvd_gcd_iff {a : α} : a ∣ s.gcd f ↔ ∀b ∈ s, a ∣ f b :=
begin
apply iff.trans multiset.dvd_gcd,
simp only [multiset.mem_map, and_imp, exists_imp_distrib],
exact ⟨λ k b hb, k _ _ hb rfl, λ k a' b hb h, h ▸ k _ hb⟩,
end
lemma gcd_dvd {b : β} (hb : b ∈ s) : s.gcd f ∣ f b :=
dvd_gcd_iff.1 (dvd_refl _) _ hb
lemma dvd_gcd {a : α} : (∀b ∈ s, a ∣ f b) → a ∣ s.gcd f :=
dvd_gcd_iff.2
@[simp] lemma gcd_insert [decidable_eq β] {b : β} :
(insert b s : finset β).gcd f = gcd_monoid.gcd (f b) (s.gcd f) :=
begin
by_cases h : b ∈ s,
{ rw [insert_eq_of_mem h,
(gcd_eq_right_iff (f b) (s.gcd f) (multiset.normalize_gcd (s.1.map f))).2 (gcd_dvd h)] ,},
apply fold_insert h,
end
@[simp] lemma gcd_singleton {b : β} : ({b} : finset β).gcd f = normalize (f b) :=
multiset.gcd_singleton
@[simp] lemma normalize_gcd : normalize (s.gcd f) = s.gcd f := by simp [gcd_def]
lemma gcd_union [decidable_eq β] : (s₁ ∪ s₂).gcd f = gcd_monoid.gcd (s₁.gcd f) (s₂.gcd f) :=
finset.induction_on s₁ (by rw [empty_union, gcd_empty, gcd_zero_left, normalize_gcd]) $
λ a s has ih, by rw [insert_union, gcd_insert, gcd_insert, ih, gcd_assoc]
theorem gcd_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a ∈ s₂, f a = g a) :
s₁.gcd f = s₂.gcd g :=
by { subst hs, exact finset.fold_congr hfg }
lemma gcd_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.gcd f ∣ s.gcd g :=
dvd_gcd (λ b hb, dvd_trans (gcd_dvd hb) (h b hb))
lemma gcd_mono (h : s₁ ⊆ s₂) : s₂.gcd f ∣ s₁.gcd f :=
dvd_gcd $ assume b hb, gcd_dvd (h hb)
theorem gcd_eq_zero_iff : s.gcd f = 0 ↔ ∀ (x : β), x ∈ s → f x = 0 :=
begin
rw [gcd_def, multiset.gcd_eq_zero_iff],
split; intro h,
{ intros b bs,
apply h (f b),
simp only [multiset.mem_map, mem_def.1 bs],
use b,
simp [mem_def.1 bs] },
{ intros a as,
rw multiset.mem_map at as,
rcases as with ⟨b, ⟨bs, rfl⟩⟩,
apply h b (mem_def.1 bs) }
end
lemma gcd_eq_gcd_filter_ne_zero [decidable_pred (λ (x : β), f x = 0)] :
s.gcd f = (s.filter (λ x, f x ≠ 0)).gcd f :=
begin
classical,
transitivity ((s.filter (λ x, f x = 0)) ∪ (s.filter (λ x, f x ≠ 0))).gcd f,
{ rw filter_union_filter_neg_eq },
rw gcd_union,
transitivity gcd_monoid.gcd (0 : α) _,
{ refine congr (congr rfl _) rfl,
apply s.induction_on, { simp },
intros a s has h,
rw filter_insert,
split_ifs with h1; simp [h, h1], },
simp [gcd_zero_left, normalize_gcd],
end
lemma gcd_mul_left {a : α} : s.gcd (λ x, a * f x) = normalize a * s.gcd f :=
begin
classical,
apply s.induction_on,
{ simp },
intros b t hbt h,
rw [gcd_insert, gcd_insert, h, ← gcd_mul_left],
apply gcd_eq_of_associated_right,
apply associated_mul_mul _ (associated.refl _),
apply normalize_associated,
end
lemma gcd_mul_right {a : α} : s.gcd (λ x, f x * a) = s.gcd f * normalize a :=
begin
classical,
apply s.induction_on,
{ simp },
intros b t hbt h,
rw [gcd_insert, gcd_insert, h, ← gcd_mul_right],
apply gcd_eq_of_associated_right,
apply associated_mul_mul (associated.refl _),
apply normalize_associated,
end
end gcd
end finset
namespace finset
section integral_domain
variables [nontrivial β] [integral_domain α] [gcd_monoid α]
lemma gcd_eq_of_dvd_sub {s : finset β} {f g : β → α} {a : α}
(h : ∀ x : β, x ∈ s → a ∣ f x - g x) :
gcd_monoid.gcd a (s.gcd f) = gcd_monoid.gcd a (s.gcd g) :=
begin
classical,
revert h,
apply s.induction_on,
{ simp },
intros b s bs hi h,
rw [gcd_insert, gcd_insert, gcd_comm (f b), ← gcd_assoc, hi (λ x hx, h _ (mem_insert_of_mem hx)),
gcd_comm a, gcd_assoc, gcd_comm a (gcd_monoid.gcd _ _),
gcd_comm (g b), gcd_assoc _ _ a, gcd_comm _ a],
refine congr rfl _,
apply gcd_eq_of_dvd_sub_right (h _ (mem_insert_self _ _)),
end
end integral_domain
end finset
|
0c54829261a844f304e5f037252c71be6461bc83
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/number_theory/cyclotomic/primitive_roots.lean
|
d7d1218e4a224d0e233686ce388eea4dd3d68a25
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 25,520
|
lean
|
/-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Best, Riccardo Brasca, Eric Rodriguez
-/
import data.pnat.prime
import algebra.is_prime_pow
import number_theory.cyclotomic.basic
import ring_theory.adjoin.power_basis
import ring_theory.polynomial.cyclotomic.eval
import ring_theory.norm
/-!
# Primitive roots in cyclotomic fields
If `is_cyclotomic_extension {n} A B`, we define an element `zeta n A B : B` that is (under certain
assumptions) a primitive `n`-root of unity in `B` and we study its properties. We also prove related
theorems under the more general assumption of just being a primitive root, for reasons described
in the implementation details section.
## Main definitions
* `is_cyclotomic_extension.zeta n A B`: if `is_cyclotomic_extension {n} A B`, than `zeta n A B`
is an element of `B` that plays the role of a primitive `n`-th root of unity.
* `is_primitive_root.power_basis`: if `K` and `L` are fields such that
`is_cyclotomic_extension {n} K L`, then `is_primitive_root.power_basis`
gives a K-power basis for L given a primitive root `ζ`.
* `is_primitive_root.embeddings_equiv_primitive_roots`: the equivalence between `L →ₐ[K] A`
and `primitive_roots n A` given by the choice of `ζ`.
## Main results
* `is_cyclotomic_extension.zeta_primitive_root`: `zeta n A B` is a primitive `n`-th root of unity.
* `is_cyclotomic_extension.finrank`: if `irreducible (cyclotomic n K)` (in particular for
`K = ℚ`), then the `finrank` of a cyclotomic extension is `n.totient`.
* `is_primitive_root.norm_eq_one`: if `irreducible (cyclotomic n K)` (in particular for `K = ℚ`),
the norm of a primitive root is `1` if `n ≠ 2`.
* `is_primitive_root.sub_one_norm_eq_eval_cyclotomic`: if `irreducible (cyclotomic n K)`
(in particular for `K = ℚ`), then the norm of `ζ - 1` is `eval 1 (cyclotomic n ℤ)`, for a
primitive root ζ. We also prove the analogous of this result for `zeta`.
* `is_primitive_root.pow_sub_one_norm_prime_pow_ne_two` : if
`irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` `p ^ (k - s + 1) ≠ 2`. See the following
lemmas for similar results. We also prove the analogous of this result for `zeta`.
* `is_primitive_root.sub_one_norm_prime_ne_two` : if `irreducible (cyclotomic (p ^ (k + 1)) K)`
(in particular for `K = ℚ`) and `p` is an odd prime, then the norm of `ζ - 1` is `p`. We also
prove the analogous of this result for `zeta`.
* `is_primitive_root.embeddings_equiv_primitive_roots`: the equivalence between `L →ₐ[K] A`
and `primitive_roots n A` given by the choice of `ζ`.
## Implementation details
`zeta n A B` is defined as any primitive root of unity in `B`, that exists by definition. It is not
true in general that it is a root of `cyclotomic n B`, but this holds if `is_domain B` and
`ne_zero (↑n : B)`.
`zeta n A B` is defined using `exists.some`, which means we cannot control it.
For example, in normal mathematics, we can demand that `(zeta p ℤ ℤ[ζₚ] : ℚ(ζₚ))` is equal to
`zeta p ℚ ℚ(ζₚ)`, as we are just choosing "an arbitrary primitive root" and we can internally
specify that our choices agree. This is not the case here, and it is indeed impossible to prove that
these two are equal. Therefore, whenever possible, we prove our results for any primitive root,
and only at the "final step", when we need to provide an "explicit" primitive root, we use `zeta`.
-/
open polynomial algebra finset finite_dimensional is_cyclotomic_extension nat pnat set
universes u v w z
variables {p n : ℕ+} (A : Type w) (B : Type z) (K : Type u) {L : Type v} (C : Type w)
variables [comm_ring A] [comm_ring B] [algebra A B] [is_cyclotomic_extension {n} A B]
section zeta
namespace is_cyclotomic_extension
variables (n)
/-- If `B` is a `n`-th cyclotomic extension of `A`, then `zeta n A B` is a primitive root of
unity in `B`. -/
noncomputable def zeta : B :=
(exists_prim_root A $ set.mem_singleton n : ∃ r : B, is_primitive_root r n).some
/-- `zeta n A B` is a primitive `n`-th root of unity. -/
@[simp] lemma zeta_spec : is_primitive_root (zeta n A B) n :=
classical.some_spec (exists_prim_root A (set.mem_singleton n) : ∃ r : B, is_primitive_root r n)
lemma aeval_zeta [is_domain B] [ne_zero ((n : ℕ) : B)] :
aeval (zeta n A B) (cyclotomic n A) = 0 :=
begin
rw [aeval_def, ← eval_map, ← is_root.def, map_cyclotomic, is_root_cyclotomic_iff],
exact zeta_spec n A B
end
lemma zeta_is_root [is_domain B] [ne_zero ((n : ℕ) : B)] :
is_root (cyclotomic n B) (zeta n A B) :=
by { convert aeval_zeta n A B, rw [is_root.def, aeval_def, eval₂_eq_eval_map, map_cyclotomic] }
lemma zeta_pow : (zeta n A B) ^ (n : ℕ) = 1 :=
(zeta_spec n A B).pow_eq_one
end is_cyclotomic_extension
end zeta
section no_order
variables [field K] [comm_ring L] [is_domain L] [algebra K L] [is_cyclotomic_extension {n} K L]
{ζ : L} (hζ : is_primitive_root ζ n)
namespace is_primitive_root
variable {C}
/-- The `power_basis` given by a primitive root `η`. -/
@[simps] protected noncomputable def power_basis : power_basis K L :=
power_basis.map (algebra.adjoin.power_basis $ integral {n} K L ζ) $
(subalgebra.equiv_of_eq _ _ (is_cyclotomic_extension.adjoin_primitive_root_eq_top hζ)).trans
subalgebra.top_equiv
lemma power_basis_gen_mem_adjoin_zeta_sub_one :
(hζ.power_basis K).gen ∈ adjoin K ({ζ - 1} : set L) :=
begin
rw [power_basis_gen, adjoin_singleton_eq_range_aeval, alg_hom.mem_range],
exact ⟨X + 1, by simp⟩
end
/-- The `power_basis` given by `η - 1`. -/
@[simps] noncomputable def sub_one_power_basis : power_basis K L :=
(hζ.power_basis K).of_gen_mem_adjoin
(is_integral_sub (is_cyclotomic_extension.integral {n} K L ζ) is_integral_one)
(hζ.power_basis_gen_mem_adjoin_zeta_sub_one _)
variables {K} (C)
-- We are not using @[simps] to avoid a timeout.
/-- The equivalence between `L →ₐ[K] C` and `primitive_roots n C` given by a primitive root `ζ`. -/
noncomputable def embeddings_equiv_primitive_roots (C : Type*) [comm_ring C] [is_domain C]
[algebra K C] (hirr : irreducible (cyclotomic n K)) : (L →ₐ[K] C) ≃ primitive_roots n C :=
((hζ.power_basis K).lift_equiv).trans
{ to_fun := λ x,
begin
haveI := is_cyclotomic_extension.ne_zero' n K L,
haveI hn := ne_zero.of_no_zero_smul_divisors K C n,
refine ⟨x.1, _⟩,
cases x,
rwa [mem_primitive_roots n.pos, ←is_root_cyclotomic_iff, is_root.def,
←map_cyclotomic _ (algebra_map K C), hζ.minpoly_eq_cyclotomic_of_irreducible hirr,
←eval₂_eq_eval_map, ←aeval_def]
end,
inv_fun := λ x,
begin
haveI := is_cyclotomic_extension.ne_zero' n K L,
haveI hn := ne_zero.of_no_zero_smul_divisors K C n,
refine ⟨x.1, _⟩,
cases x,
rwa [aeval_def, eval₂_eq_eval_map, hζ.power_basis_gen K,
←hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_cyclotomic, ←is_root.def,
is_root_cyclotomic_iff, ← mem_primitive_roots n.pos]
end,
left_inv := λ x, subtype.ext rfl,
right_inv := λ x, subtype.ext rfl }
@[simp]
lemma embeddings_equiv_primitive_roots_apply_coe (C : Type*) [comm_ring C] [is_domain C]
[algebra K C] (hirr : irreducible (cyclotomic n K)) (φ : L →ₐ[K] C) :
(hζ.embeddings_equiv_primitive_roots C hirr φ : C) = φ ζ := rfl
end is_primitive_root
namespace is_cyclotomic_extension
variables {K} (L)
/-- If `irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the `finrank` of a
cyclotomic extension is `n.totient`. -/
lemma finrank (hirr : irreducible (cyclotomic n K)) :
finrank K L = (n : ℕ).totient :=
begin
haveI := is_cyclotomic_extension.ne_zero' n K L,
rw [((zeta_spec n K L).power_basis K).finrank, is_primitive_root.power_basis_dim,
←(zeta_spec n K L).minpoly_eq_cyclotomic_of_irreducible hirr, nat_degree_cyclotomic]
end
end is_cyclotomic_extension
end no_order
section norm
namespace is_primitive_root
section comm_ring
variables [comm_ring L] {ζ : L} (hζ : is_primitive_root ζ n)
variables {K} [field K] [algebra K L]
/-- This mathematically trivial result is complementary to `norm_eq_one` below. -/
lemma norm_eq_neg_one_pow (hζ : is_primitive_root ζ 2) [is_domain L] :
norm K ζ = (-1) ^ finrank K L :=
by rw [hζ.eq_neg_one_of_two_right, show -1 = algebra_map K L (-1), by simp,
algebra.norm_algebra_map]
include hζ
/-- If `irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of a primitive root is
`1` if `n ≠ 2`. -/
lemma norm_eq_one [is_domain L] [is_cyclotomic_extension {n} K L] (hn : n ≠ 2)
(hirr : irreducible (cyclotomic n K)) : norm K ζ = 1 :=
begin
haveI := is_cyclotomic_extension.ne_zero' n K L,
by_cases h1 : n = 1,
{ rw [h1, one_coe, one_right_iff] at hζ,
rw [hζ, show 1 = algebra_map K L 1, by simp, algebra.norm_algebra_map, one_pow] },
{ replace h1 : 2 ≤ n,
{ by_contra' h,
exact h1 (pnat.eq_one_of_lt_two h) },
rw [← hζ.power_basis_gen K, power_basis.norm_gen_eq_coeff_zero_minpoly, hζ.power_basis_gen K,
← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, cyclotomic_coeff_zero _ h1, mul_one,
hζ.power_basis_dim K, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, nat_degree_cyclotomic],
exact (totient_even $ h1.lt_of_ne hn.symm).neg_one_pow }
end
/-- If `K` is linearly ordered, the norm of a primitive root is `1` if `n` is odd. -/
lemma norm_eq_one_of_linearly_ordered {K : Type*} [linear_ordered_field K] [algebra K L]
(hodd : odd (n : ℕ)) : norm K ζ = 1 :=
begin
have hz := congr_arg (norm K) ((is_primitive_root.iff_def _ n).1 hζ).1,
rw [←(algebra_map K L).map_one , algebra.norm_algebra_map, one_pow, map_pow, ←one_pow ↑n] at hz,
exact strict_mono.injective hodd.strict_mono_pow hz
end
lemma norm_of_cyclotomic_irreducible [is_domain L] [is_cyclotomic_extension {n} K L]
(hirr : irreducible (cyclotomic n K)) : norm K ζ = ite (n = 2) (-1) 1 :=
begin
split_ifs with hn,
{ unfreezingI {subst hn},
convert norm_eq_neg_one_pow hζ,
erw [is_cyclotomic_extension.finrank _ hirr, totient_two, pow_one],
all_goals { apply_instance } },
{ exact hζ.norm_eq_one hn hirr }
end
end comm_ring
section field
variables [field L] {ζ : L} (hζ : is_primitive_root ζ n)
variables {K} [field K] [algebra K L]
include hζ
/-- If `irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the norm of
`ζ - 1` is `eval 1 (cyclotomic n ℤ)`. -/
lemma sub_one_norm_eq_eval_cyclotomic [is_cyclotomic_extension {n} K L]
(h : 2 < (n : ℕ)) (hirr : irreducible (cyclotomic n K)) :
norm K (ζ - 1) = ↑(eval 1 (cyclotomic n ℤ)) :=
begin
haveI := is_cyclotomic_extension.ne_zero' n K L,
let E := algebraic_closure L,
obtain ⟨z, hz⟩ := is_alg_closed.exists_root _ (degree_cyclotomic_pos n E n.pos).ne.symm,
apply (algebra_map K E).injective,
letI := finite_dimensional {n} K L,
letI := is_galois n K L,
rw [norm_eq_prod_embeddings],
conv_lhs { congr, skip, funext,
rw [← neg_sub, alg_hom.map_neg, alg_hom.map_sub, alg_hom.map_one, neg_eq_neg_one_mul] },
rw [prod_mul_distrib, prod_const, card_univ, alg_hom.card, is_cyclotomic_extension.finrank L hirr,
(totient_even h).neg_one_pow, one_mul],
have : finset.univ.prod (λ (σ : L →ₐ[K] E), 1 - σ ζ) = eval 1 (cyclotomic' n E),
{ rw [cyclotomic', eval_prod, ← @finset.prod_attach E E, ← univ_eq_attach],
refine fintype.prod_equiv (hζ.embeddings_equiv_primitive_roots E hirr) _ _ (λ σ, _),
simp },
haveI : ne_zero ((n : ℕ) : E) := (ne_zero.of_no_zero_smul_divisors K _ (n : ℕ)),
rw [this, cyclotomic', ← cyclotomic_eq_prod_X_sub_primitive_roots (is_root_cyclotomic_iff.1 hz),
← map_cyclotomic_int, _root_.map_int_cast, ←int.cast_one, eval_int_cast_map, eq_int_cast,
int.cast_id]
end
/-- If `is_prime_pow (n : ℕ)`, `n ≠ 2` and `irreducible (cyclotomic n K)` (in particular for
`K = ℚ`), then the norm of `ζ - 1` is `(n : ℕ).min_fac`. -/
lemma sub_one_norm_is_prime_pow (hn : is_prime_pow (n : ℕ)) [is_cyclotomic_extension {n} K L]
(hirr : irreducible (cyclotomic (n : ℕ) K)) (h : n ≠ 2) :
norm K (ζ - 1) = (n : ℕ).min_fac :=
begin
have := (coe_lt_coe 2 _).1 (lt_of_le_of_ne (succ_le_of_lt (is_prime_pow.one_lt hn))
(function.injective.ne pnat.coe_injective h).symm),
letI hprime : fact ((n : ℕ).min_fac.prime) := ⟨min_fac_prime (is_prime_pow.ne_one hn)⟩,
rw [sub_one_norm_eq_eval_cyclotomic hζ this hirr],
nth_rewrite 0 [← is_prime_pow.min_fac_pow_factorization_eq hn],
obtain ⟨k, hk⟩ : ∃ k, ((n : ℕ).factorization) (n : ℕ).min_fac = k + 1 :=
exists_eq_succ_of_ne_zero (((n : ℕ).factorization.mem_support_to_fun (n : ℕ).min_fac).1 $
factor_iff_mem_factorization.2 $ (mem_factors (is_prime_pow.ne_zero hn)).2
⟨hprime.out, min_fac_dvd _⟩),
simp [hk, sub_one_norm_eq_eval_cyclotomic hζ this hirr],
end
omit hζ
variable {A}
lemma minpoly_sub_one_eq_cyclotomic_comp [algebra K A] [is_domain A] {ζ : A}
[is_cyclotomic_extension {n} K A] (hζ : is_primitive_root ζ n)
(h : irreducible (polynomial.cyclotomic n K)) :
minpoly K (ζ - 1) = (cyclotomic n K).comp (X + 1) :=
begin
haveI := is_cyclotomic_extension.ne_zero' n K A,
rw [show ζ - 1 = ζ + (algebra_map K A (-1)), by simp [sub_eq_add_neg], minpoly.add_algebra_map
(is_cyclotomic_extension.integral {n} K A ζ), hζ.minpoly_eq_cyclotomic_of_irreducible h],
simp
end
local attribute [instance] is_cyclotomic_extension.finite_dimensional
local attribute [instance] is_cyclotomic_extension.is_galois
/-- If `irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ^ (k - s + 1) ≠ 2`. See the next lemmas
for similar results. -/
lemma pow_sub_one_norm_prime_pow_ne_two {k s : ℕ} (hζ : is_primitive_root ζ ↑(p ^ (k + 1)))
[hpri : fact (p : ℕ).prime] [is_cyclotomic_extension {p ^ (k + 1)} K L]
(hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (hs : s ≤ k)
(htwo : p ^ (k - s + 1) ≠ 2) : norm K (ζ ^ ((p : ℕ) ^ s) - 1) = p ^ ((p : ℕ) ^ s) :=
begin
have hirr₁ : irreducible (cyclotomic (p ^ (k - s + 1)) K) :=
cyclotomic_irreducible_pow_of_irreducible_pow hpri.1 (by linarith) hirr,
rw ←pnat.pow_coe at hirr₁,
let η := ζ ^ ((p : ℕ) ^ s) - 1,
let η₁ : K⟮η⟯ := intermediate_field.adjoin_simple.gen K η,
have hη : is_primitive_root (η + 1) (p ^ (k + 1 - s)),
{ rw [sub_add_cancel],
refine is_primitive_root.pow (p ^ (k + 1)).pos hζ _,
rw [pnat.pow_coe, ← pow_add, add_comm s, nat.sub_add_cancel (le_trans hs (nat.le_succ k))] },
haveI : is_cyclotomic_extension {p ^ (k - s + 1)} K K⟮η⟯,
{ suffices : is_cyclotomic_extension {p ^ (k - s + 1)} K K⟮η + 1⟯.to_subalgebra,
{ have H : K⟮η + 1⟯.to_subalgebra = K⟮η⟯.to_subalgebra,
{ simp only [intermediate_field.adjoin_simple_to_subalgebra_of_integral
(is_cyclotomic_extension.integral {p ^ (k + 1)} K L _)],
refine subalgebra.ext (λ x, ⟨λ hx, adjoin_le _ hx, λ hx, adjoin_le _ hx⟩),
{ simp only [set.singleton_subset_iff, set_like.mem_coe],
exact subalgebra.add_mem _ (subset_adjoin (mem_singleton η)) (subalgebra.one_mem _) },
{ simp only [set.singleton_subset_iff, set_like.mem_coe],
nth_rewrite 0 [← add_sub_cancel η 1],
refine subalgebra.sub_mem _ (subset_adjoin (mem_singleton _)) (subalgebra.one_mem _) } },
rw [H] at this,
exact this },
rw [intermediate_field.adjoin_simple_to_subalgebra_of_integral
(is_cyclotomic_extension.integral {p ^ (k + 1)} K L _)],
have hη' : is_primitive_root (η + 1) ↑(p ^ (k + 1 - s)) := by simpa using hη,
convert hη'.adjoin_is_cyclotomic_extension K,
rw [nat.sub_add_comm hs] },
replace hη : is_primitive_root (η₁ + 1) ↑(p ^ (k - s + 1)),
{ apply coe_submonoid_class_iff.1,
convert hη,
rw [nat.sub_add_comm hs, pow_coe] },
rw [norm_eq_norm_adjoin K],
{ have H := hη.sub_one_norm_is_prime_pow _ hirr₁ htwo,
swap, { rw [pnat.pow_coe], exact hpri.1.is_prime_pow.pow (nat.succ_ne_zero _) },
rw [add_sub_cancel] at H,
rw [H, coe_coe],
congr,
{ rw [pnat.pow_coe, nat.pow_min_fac, hpri.1.min_fac_eq], exact nat.succ_ne_zero _ },
have := finite_dimensional.finrank_mul_finrank K K⟮η⟯ L,
rw [is_cyclotomic_extension.finrank L hirr, is_cyclotomic_extension.finrank K⟮η⟯ hirr₁,
pnat.pow_coe, pnat.pow_coe, nat.totient_prime_pow hpri.out (k - s).succ_pos,
nat.totient_prime_pow hpri.out k.succ_pos, mul_comm _ (↑p - 1), mul_assoc,
mul_comm (↑p ^ (k.succ - 1))] at this,
replace this := nat.eq_of_mul_eq_mul_left (tsub_pos_iff_lt.2 (nat.prime.one_lt hpri.out)) this,
have Hex : k.succ - 1 = (k - s).succ - 1 + s,
{ simp only [nat.succ_sub_succ_eq_sub, tsub_zero],
exact (nat.sub_add_cancel hs).symm },
rw [Hex, pow_add] at this,
exact nat.eq_of_mul_eq_mul_left (pow_pos hpri.out.pos _) this },
all_goals { apply_instance }
end
/-- If `irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ≠ 2`. -/
lemma pow_sub_one_norm_prime_ne_two {k : ℕ} (hζ : is_primitive_root ζ ↑(p ^ (k + 1)))
[hpri : fact (p : ℕ).prime] [is_cyclotomic_extension {p ^ (k + 1)} K L]
(hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) {s : ℕ} (hs : s ≤ k)
(hodd : p ≠ 2) : norm K (ζ ^ ((p : ℕ) ^ s) - 1) = p ^ ((p : ℕ) ^ s) :=
begin
refine hζ.pow_sub_one_norm_prime_pow_ne_two hirr hs (λ h, _),
rw [← pnat.coe_inj, pnat.coe_bit0, pnat.one_coe, pnat.pow_coe, ← pow_one 2] at h,
replace h := eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 nat.prime_two)
((k - s).succ_pos) h,
rw [← pnat.one_coe, ← pnat.coe_bit0, pnat.coe_inj] at h,
exact hodd h
end
/-- If `irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd
prime, then the norm of `ζ - 1` is `p`. -/
lemma sub_one_norm_prime_ne_two {k : ℕ} (hζ : is_primitive_root ζ ↑(p ^ (k + 1)))
[hpri : fact (p : ℕ).prime] [is_cyclotomic_extension {p ^ (k + 1)} K L]
(hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (h : p ≠ 2) :
norm K (ζ - 1) = p :=
by simpa using hζ.pow_sub_one_norm_prime_ne_two hirr k.zero_le h
/-- If `irreducible (cyclotomic p K)` (in particular for `K = ℚ`) and `p` is an odd prime,
then the norm of `ζ - 1` is `p`. -/
lemma sub_one_norm_prime [hpri : fact (p : ℕ).prime] [hcyc : is_cyclotomic_extension {p} K L]
(hζ: is_primitive_root ζ p) (hirr : irreducible (cyclotomic p K)) (h : p ≠ 2) :
norm K (ζ - 1) = p :=
begin
replace hirr : irreducible (cyclotomic (↑(p ^ (0 + 1)) : ℕ) K) := by simp [hirr],
replace hζ : is_primitive_root ζ (↑(p ^ (0 + 1)) : ℕ) := by simp [hζ],
haveI : is_cyclotomic_extension {p ^ (0 + 1)} K L := by simp [hcyc],
simpa using sub_one_norm_prime_ne_two hζ hirr h
end
/-- If `irreducible (cyclotomic (2 ^ (k + 1)) K)` (in particular for `K = ℚ`), then the norm of
`ζ ^ (2 ^ k) - 1` is `(-2) ^ (2 ^ k)`. -/
lemma pow_sub_one_norm_two {k : ℕ} (hζ : is_primitive_root ζ (2 ^ (k + 1)))
[is_cyclotomic_extension {2 ^ (k + 1)} K L]
(hirr : irreducible (cyclotomic (2 ^ (k + 1)) K)) :
norm K (ζ ^ (2 ^ k) - 1) = (-2) ^ (2 ^ k) :=
begin
have := hζ.pow_of_dvd (λ h, two_ne_zero (pow_eq_zero h)) (pow_dvd_pow 2 (le_succ k)),
rw [nat.pow_div (le_succ k) zero_lt_two, nat.succ_sub (le_refl k), nat.sub_self, pow_one] at this,
have H : (-1 : L) - (1 : L) = algebra_map K L (-2),
{ simp only [_root_.map_neg, map_bit0, _root_.map_one],
ring },
replace hirr : irreducible (cyclotomic (2 ^ (k + 1) : ℕ+) K) := by simp [hirr],
rw [this.eq_neg_one_of_two_right, H, algebra.norm_algebra_map,
is_cyclotomic_extension.finrank L hirr,
pow_coe, pnat.coe_bit0, one_coe, totient_prime_pow nat.prime_two (zero_lt_succ k),
succ_sub_succ_eq_sub, tsub_zero, mul_one]
end
/-- If `irreducible (cyclotomic (2 ^ k) K)` (in particular for `K = ℚ`) and `k` is at least `2`,
then the norm of `ζ - 1` is `2`. -/
lemma sub_one_norm_two {k : ℕ} (hζ : is_primitive_root ζ (2 ^ k)) (hk : 2 ≤ k)
[H : is_cyclotomic_extension {2 ^ k} K L] (hirr : irreducible (cyclotomic (2 ^ k) K)) :
norm K (ζ - 1) = 2 :=
begin
have : 2 < (2 ^ k : ℕ+),
{ simp only [← coe_lt_coe, pnat.coe_bit0, one_coe, pow_coe],
nth_rewrite 0 [← pow_one 2],
exact pow_lt_pow one_lt_two (lt_of_lt_of_le one_lt_two hk) },
replace hirr : irreducible (cyclotomic (2 ^ k : ℕ+) K) := by simp [hirr],
replace hζ : is_primitive_root ζ (2 ^ k : ℕ+) := by simp [hζ],
obtain ⟨k₁, hk₁⟩ := exists_eq_succ_of_ne_zero ((lt_of_lt_of_le zero_lt_two hk).ne.symm),
simpa [hk₁] using sub_one_norm_eq_eval_cyclotomic hζ this hirr,
end
/-- If `irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `1 ≤ k`. -/
lemma pow_sub_one_norm_prime_pow_of_one_le {k s : ℕ} (hζ : is_primitive_root ζ ↑(p ^ (k + 1)))
[hpri : fact (p : ℕ).prime] [hcycl : is_cyclotomic_extension {p ^ (k + 1)} K L]
(hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (hs : s ≤ k)
(hk : 1 ≤ k) : norm K (ζ ^ ((p : ℕ) ^ s) - 1) = p ^ ((p : ℕ) ^ s) :=
begin
by_cases htwo : p ^ (k - s + 1) = 2,
{ have hp : p = 2,
{ rw [← pnat.coe_inj, pnat.coe_bit0, pnat.one_coe, pnat.pow_coe, ← pow_one 2] at htwo,
replace htwo := eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 nat.prime_two)
(succ_pos _) htwo,
rwa [show 2 = ((2 : ℕ+) : ℕ), by simp, pnat.coe_inj] at htwo },
replace hs : s = k,
{ rw [hp, ← pnat.coe_inj, pnat.pow_coe, pnat.coe_bit0, pnat.one_coe] at htwo,
nth_rewrite 1 [← pow_one 2] at htwo,
replace htwo := nat.pow_right_injective rfl.le htwo,
rw [add_left_eq_self, nat.sub_eq_zero_iff_le] at htwo,
refine le_antisymm hs htwo },
simp only [hs, hp, pnat.coe_bit0, one_coe, coe_coe, cast_bit0, cast_one,
pow_coe] at ⊢ hζ hirr hcycl,
haveI := hcycl,
obtain ⟨k₁, hk₁⟩ := nat.exists_eq_succ_of_ne_zero (one_le_iff_ne_zero.1 hk),
rw [hζ.pow_sub_one_norm_two hirr],
rw [hk₁, pow_succ, pow_mul, neg_eq_neg_one_mul, mul_pow, neg_one_sq, one_mul, ← pow_mul,
← pow_succ] },
{ exact hζ.pow_sub_one_norm_prime_pow_ne_two hirr hs htwo }
end
end field
end is_primitive_root
namespace is_cyclotomic_extension
open is_primitive_root
variables {K} (L) [field K] [field L] [algebra K L]
/-- If `irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of `zeta n K L` is `1`
if `n` is odd. -/
lemma norm_zeta_eq_one [is_cyclotomic_extension {n} K L] (hn : n ≠ 2)
(hirr : irreducible (cyclotomic n K)) : norm K (zeta n K L) = 1 :=
(zeta_spec n K L).norm_eq_one hn hirr
/-- If `is_prime_pow (n : ℕ)`, `n ≠ 2` and `irreducible (cyclotomic n K)` (in particular for
`K = ℚ`), then the norm of `zeta n K L - 1` is `(n : ℕ).min_fac`. -/
lemma is_prime_pow_norm_zeta_sub_one (hn : is_prime_pow (n : ℕ))
[is_cyclotomic_extension {n} K L]
(hirr : irreducible (cyclotomic (n : ℕ) K)) (h : n ≠ 2) :
norm K (zeta n K L - 1) = (n : ℕ).min_fac :=
(zeta_spec n K L).sub_one_norm_is_prime_pow hn hirr h
/-- If `irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `(zeta (p ^ (k + 1)) K L) ^ (p ^ s) - 1` is `p ^ (p ^ s)`
if `p ^ (k - s + 1) ≠ 2`. -/
lemma prime_ne_two_pow_norm_zeta_pow_sub_one {k : ℕ} [hpri : fact (p : ℕ).prime]
[is_cyclotomic_extension {p ^ (k + 1)} K L]
(hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) {s : ℕ} (hs : s ≤ k)
(htwo : p ^ (k - s + 1) ≠ 2) :
norm K ((zeta (p ^ (k + 1)) K L) ^ ((p : ℕ) ^ s) - 1) = p ^ ((p : ℕ) ^ s) :=
(zeta_spec _ K L).pow_sub_one_norm_prime_pow_ne_two hirr hs htwo
/-- If `irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd
prime, then the norm of `zeta (p ^ (k + 1)) K L - 1` is `p`. -/
lemma prime_ne_two_pow_norm_zeta_sub_one {k : ℕ} [hpri : fact (p : ℕ).prime]
[is_cyclotomic_extension {p ^ (k + 1)} K L]
(hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (h : p ≠ 2) :
norm K (zeta (p ^ (k + 1)) K L - 1) = p :=
(zeta_spec _ K L).sub_one_norm_prime_ne_two hirr h
/-- If `irreducible (cyclotomic p K)` (in particular for `K = ℚ`) and `p` is an odd prime,
then the norm of `zeta p K L - 1` is `p`. -/
lemma prime_ne_two_norm_zeta_sub_one [hpri : fact (p : ℕ).prime]
[hcyc : is_cyclotomic_extension {p} K L] (hirr : irreducible (cyclotomic p K)) (h : p ≠ 2) :
norm K (zeta p K L - 1) = p :=
(zeta_spec _ K L).sub_one_norm_prime hirr h
/-- If `irreducible (cyclotomic (2 ^ k) K)` (in particular for `K = ℚ`) and `k` is at least `2`,
then the norm of `zeta (2 ^ k) K L - 1` is `2`. -/
lemma two_pow_norm_zeta_sub_one {k : ℕ} (hk : 2 ≤ k)
[is_cyclotomic_extension {2 ^ k} K L] (hirr : irreducible (cyclotomic (2 ^ k) K)) :
norm K (zeta (2 ^ k) K L - 1) = 2 :=
sub_one_norm_two (zeta_spec (2 ^ k) K L) hk hirr
end is_cyclotomic_extension
end norm
|
110851201d377e3f5ae908eeaef448bb91a88afb
|
853df553b1d6ca524e3f0a79aedd32dde5d27ec3
|
/src/order/zorn.lean
|
61c638281a3f0156e3824d41bcc4de21bd61079e
|
[
"Apache-2.0"
] |
permissive
|
DanielFabian/mathlib
|
efc3a50b5dde303c59eeb6353ef4c35a345d7112
|
f520d07eba0c852e96fe26da71d85bf6d40fcc2a
|
refs/heads/master
| 1,668,739,922,971
| 1,595,201,756,000
| 1,595,201,756,000
| 279,469,476
| 0
| 0
| null | 1,594,696,604,000
| 1,594,696,604,000
| null |
UTF-8
|
Lean
| false
| false
| 12,899
|
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
Zorn's lemmas.
Ported from Isabelle/HOL (written by Jacques D. Fleuriot, Tobias Nipkow, and Christian Sternagel).
-/
import data.set.lattice
noncomputable theory
universes u
open set classical
open_locale classical
namespace zorn
section chain
parameters {α : Type u} (r : α → α → Prop)
local infix ` ≺ `:50 := r
/-- A chain is a subset `c` satisfying
`x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ c`. -/
def chain (c : set α) := pairwise_on c (λx y, x ≺ y ∨ y ≺ x)
parameters {r}
theorem chain.total_of_refl [is_refl α r]
{c} (H : chain c) {x y} (hx : x ∈ c) (hy : y ∈ c) :
x ≺ y ∨ y ≺ x :=
if e : x = y then or.inl (e ▸ refl _) else H _ hx _ hy e
theorem chain.mono {c c'} : c' ⊆ c → chain c → chain c' :=
pairwise_on.mono
theorem chain.directed_on [is_refl α r] {c} (H : chain c) : directed_on (≺) c :=
assume x hx y hy,
match H.total_of_refl hx hy with
| or.inl h := ⟨y, hy, h, refl _⟩
| or.inr h := ⟨x, hx, refl _, h⟩
end
theorem chain_insert {c : set α} {a : α} (hc : chain c) (ha : ∀b∈c, b ≠ a → a ≺ b ∨ b ≺ a) :
chain (insert a c) :=
forall_insert_of_forall
(assume x hx, forall_insert_of_forall (hc x hx) (assume hneq, (ha x hx hneq).symm))
(forall_insert_of_forall (assume x hx hneq, ha x hx $ assume h', hneq h'.symm) (assume h, (h rfl).rec _))
/-- `super_chain c₁ c₂` means that `c₂ is a chain that strictly includes `c₁`. -/
def super_chain (c₁ c₂ : set α) : Prop := chain c₂ ∧ c₁ ⊂ c₂
/-- A chain `c` is a maximal chain if there does not exists a chain strictly including `c`. -/
def is_max_chain (c : set α) := chain c ∧ ¬ (∃c', super_chain c c')
/-- Given a set `c`, if there exists a chain `c'` strictly including `c`, then `succ_chain c`
is one of these chains. Otherwise it is `c`. -/
def succ_chain (c : set α) : set α :=
if h : ∃c', chain c ∧ super_chain c c' then some h else c
theorem succ_spec {c : set α} (h : ∃c', chain c ∧ super_chain c c') :
super_chain c (succ_chain c) :=
let ⟨c', hc'⟩ := h in
have chain c ∧ super_chain c (some h),
from @some_spec _ (λc', chain c ∧ super_chain c c') _,
by simp [succ_chain, dif_pos, h, this.right]
theorem chain_succ {c : set α} (hc : chain c) : chain (succ_chain c) :=
if h : ∃c', chain c ∧ super_chain c c' then
(succ_spec h).left
else
by simp [succ_chain, dif_neg, h]; exact hc
theorem super_of_not_max {c : set α} (hc₁ : chain c) (hc₂ : ¬ is_max_chain c) :
super_chain c (succ_chain c) :=
begin
simp [is_max_chain, not_and_distrib, not_forall_not] at hc₂,
cases hc₂.neg_resolve_left hc₁ with c' hc',
exact succ_spec ⟨c', hc₁, hc'⟩
end
theorem succ_increasing {c : set α} : c ⊆ succ_chain c :=
if h : ∃c', chain c ∧ super_chain c c' then
have super_chain c (succ_chain c), from succ_spec h,
this.right.left
else by simp [succ_chain, dif_neg, h, subset.refl]
/-- Set of sets reachable from `∅` using `succ_chain` and `⋃₀`. -/
inductive chain_closure : set α → Prop
| succ : ∀{s}, chain_closure s → chain_closure (succ_chain s)
| union : ∀{s}, (∀a∈s, chain_closure a) → chain_closure (⋃₀ s)
theorem chain_closure_empty : chain_closure ∅ :=
have chain_closure (⋃₀ ∅),
from chain_closure.union $ assume a h, h.rec _,
by simp at this; assumption
theorem chain_closure_closure : chain_closure (⋃₀ chain_closure) :=
chain_closure.union $ assume s hs, hs
variables {c c₁ c₂ c₃ : set α}
private lemma chain_closure_succ_total_aux (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
(h : ∀{c₃}, chain_closure c₃ → c₃ ⊆ c₂ → c₂ = c₃ ∨ succ_chain c₃ ⊆ c₂) :
c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁ :=
begin
induction hc₁,
case succ : c₃ hc₃ ih {
cases ih with ih ih,
{ have h := h hc₃ ih,
cases h with h h,
{ exact or.inr (h ▸ subset.refl _) },
{ exact or.inl h } },
{ exact or.inr (subset.trans ih succ_increasing) } },
case union : s hs ih {
refine (classical.or_iff_not_imp_right.2 $ λ hn, sUnion_subset $ λ a ha, _),
apply (ih a ha).resolve_right,
apply mt (λ h, _) hn,
exact subset.trans h (subset_sUnion_of_mem ha) }
end
private lemma chain_closure_succ_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂) (h : c₁ ⊆ c₂) :
c₂ = c₁ ∨ succ_chain c₁ ⊆ c₂ :=
begin
induction hc₂ generalizing c₁ hc₁ h,
case succ : c₂ hc₂ ih {
have h₁ : c₁ ⊆ c₂ ∨ @succ_chain α r c₂ ⊆ c₁ :=
(chain_closure_succ_total_aux hc₁ hc₂ $ assume c₁, ih),
cases h₁ with h₁ h₁,
{ have h₂ := ih hc₁ h₁,
cases h₂ with h₂ h₂,
{ exact (or.inr $ h₂ ▸ subset.refl _) },
{ exact (or.inr $ subset.trans h₂ succ_increasing) } },
{ exact (or.inl $ subset.antisymm h₁ h) } },
case union : s hs ih {
apply or.imp_left (assume h', subset.antisymm h' h),
apply classical.by_contradiction,
simp [not_or_distrib, sUnion_subset_iff, classical.not_forall],
intros c₃ hc₃ h₁ h₂,
have h := chain_closure_succ_total_aux hc₁ (hs c₃ hc₃) (assume c₄, ih _ hc₃),
cases h with h h,
{ have h' := ih c₃ hc₃ hc₁ h,
cases h' with h' h',
{ exact (h₁ $ h' ▸ subset.refl _) },
{ exact (h₂ $ subset.trans h' $ subset_sUnion_of_mem hc₃) } },
{ exact (h₁ $ subset.trans succ_increasing h) } }
end
theorem chain_closure_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂) : c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ :=
have c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁,
from chain_closure_succ_total_aux hc₁ hc₂ $ assume c₃ hc₃, chain_closure_succ_total hc₃ hc₂,
or.imp_right (assume : succ_chain c₂ ⊆ c₁, subset.trans succ_increasing this) this
theorem chain_closure_succ_fixpoint (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
(h_eq : succ_chain c₂ = c₂) : c₁ ⊆ c₂ :=
begin
induction hc₁,
case succ : c₁ hc₁ h {
exact or.elim (chain_closure_succ_total hc₁ hc₂ h)
(assume h, h ▸ h_eq.symm ▸ subset.refl c₂) id },
case union : s hs ih {
exact (sUnion_subset $ assume c₁ hc₁, ih c₁ hc₁) }
end
theorem chain_closure_succ_fixpoint_iff (hc : chain_closure c) :
succ_chain c = c ↔ c = ⋃₀ chain_closure :=
⟨assume h, subset.antisymm
(subset_sUnion_of_mem hc)
(chain_closure_succ_fixpoint chain_closure_closure hc h),
assume : c = ⋃₀{c : set α | chain_closure c},
subset.antisymm
(calc succ_chain c ⊆ ⋃₀{c : set α | chain_closure c} :
subset_sUnion_of_mem $ chain_closure.succ hc
... = c : this.symm)
succ_increasing⟩
theorem chain_chain_closure (hc : chain_closure c) : chain c :=
begin
induction hc,
case succ : c hc h {
exact chain_succ h },
case union : s hs h {
have h : ∀c∈s, zorn.chain c := h,
exact assume c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq,
have t₁ ⊆ t₂ ∨ t₂ ⊆ t₁, from chain_closure_total (hs _ ht₁) (hs _ ht₂),
or.elim this
(assume : t₁ ⊆ t₂, h t₂ ht₂ c₁ (this hc₁) c₂ hc₂ hneq)
(assume : t₂ ⊆ t₁, h t₁ ht₁ c₁ hc₁ c₂ (this hc₂) hneq) }
end
/-- `max_chain` is the union of all sets in the chain closure. -/
def max_chain := ⋃₀ chain_closure
/-- Hausdorff's maximality principle
There exists a maximal totally ordered subset of `α`.
Note that we do not require `α` to be partially ordered by `r`. -/
theorem max_chain_spec : is_max_chain max_chain :=
classical.by_contradiction $
assume : ¬ is_max_chain (⋃₀ chain_closure),
have super_chain (⋃₀ chain_closure) (succ_chain (⋃₀ chain_closure)),
from super_of_not_max (chain_chain_closure chain_closure_closure) this,
let ⟨h₁, H⟩ := this,
⟨h₂, (h₃ : (⋃₀ chain_closure) ≠ succ_chain (⋃₀ chain_closure))⟩ := ssubset_iff_subset_ne.1 H in
have succ_chain (⋃₀ chain_closure) = (⋃₀ chain_closure),
from (chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl,
h₃ this.symm
/-- Zorn's lemma
If every chain has an upper bound, then there is a maximal element -/
theorem exists_maximal_of_chains_bounded
(h : ∀c, chain c → ∃ub, ∀a∈c, a ≺ ub) (trans : ∀{a b c}, a ≺ b → b ≺ c → a ≺ c) :
∃m, ∀a, m ≺ a → a ≺ m :=
have ∃ub, ∀a∈max_chain, a ≺ ub,
from h _ $ max_chain_spec.left,
let ⟨ub, (hub : ∀a∈max_chain, a ≺ ub)⟩ := this in
⟨ub, assume a ha,
have chain (insert a max_chain),
from chain_insert max_chain_spec.left $ assume b hb _, or.inr $ trans (hub b hb) ha,
have a ∈ max_chain, from
classical.by_contradiction $ assume h : a ∉ max_chain,
max_chain_spec.right $ ⟨insert a max_chain, this, ssubset_insert h⟩,
hub a this⟩
end chain
theorem zorn_partial_order {α : Type u} [partial_order α]
(h : ∀c:set α, chain (≤) c → ∃ub, ∀a∈c, a ≤ ub) : ∃m:α, ∀a, m ≤ a → a = m :=
let ⟨m, hm⟩ := @exists_maximal_of_chains_bounded α (≤) h (assume a b c, le_trans) in
⟨m, assume a ha, le_antisymm (hm a ha) ha⟩
theorem zorn_partial_order₀ {α : Type u} [partial_order α] (s : set α)
(ih : ∀ c ⊆ s, chain (≤) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub)
(x : α) (hxs : x ∈ s) : ∃ m ∈ s, x ≤ m ∧ ∀ z ∈ s, m ≤ z → z = m :=
let ⟨⟨m, hms, hxm⟩, h⟩ := @zorn_partial_order {m // m ∈ s ∧ x ≤ m} _ (λ c hc, c.eq_empty_or_nonempty.elim
(assume hce, hce.symm ▸ ⟨⟨x, hxs, le_refl _⟩, λ _, false.elim⟩)
(assume ⟨m, hmc⟩,
let ⟨ub, hubs, hub⟩ := ih (subtype.val '' c) (image_subset_iff.2 $ λ z hzc, z.2.1)
(by rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq;
exact hc p hpc q hqc (mt (by rintro rfl; refl) hpq)) m.1 (mem_image_of_mem _ hmc) in
⟨⟨ub, hubs, le_trans m.2.2 $ hub m.1 $ mem_image_of_mem _ hmc⟩, λ a hac, hub a.1 ⟨a, hac, rfl⟩⟩)) in
⟨m, hms, hxm, λ z hzs hmz, congr_arg subtype.val $ h ⟨z, hzs, le_trans hxm hmz⟩ hmz⟩
theorem zorn_subset {α : Type u} (S : set (set α))
(h : ∀c ⊆ S, chain (⊆) c → ∃ub ∈ S, ∀ s ∈ c, s ⊆ ub) :
∃ m ∈ S, ∀a ∈ S, m ⊆ a → a = m :=
begin
letI : partial_order S := partial_order.lift subtype.val (λ _ _, subtype.ext_val),
have : ∀c:set S, @chain S (≤) c → ∃ub, ∀a∈c, a ≤ ub,
{ intros c hc,
rcases h (subtype.val '' c) (image_subset_iff.2 _) _ with ⟨s, sS, hs⟩,
{ exact ⟨⟨s, sS⟩, λ ⟨x, hx⟩ H, hs _ (mem_image_of_mem _ H)⟩ },
{ rintro ⟨x, hx⟩ _, exact hx },
{ rintro _ ⟨x, cx, rfl⟩ _ ⟨y, cy, rfl⟩ xy,
exact hc x cx y cy (mt (congr_arg _) xy) } },
rcases zorn_partial_order this with ⟨⟨m, mS⟩, hm⟩,
exact ⟨m, mS, λ a aS ha, congr_arg subtype.val (hm ⟨a, aS⟩ ha)⟩
end
theorem zorn_subset₀ {α : Type u} (S : set (set α))
(H : ∀c ⊆ S, chain (⊆) c → c.nonempty → ∃ub ∈ S, ∀ s ∈ c, s ⊆ ub) (x) (hx : x ∈ S) :
∃ m ∈ S, x ⊆ m ∧ ∀a ∈ S, m ⊆ a → a = m :=
begin
let T := {s ∈ S | x ⊆ s},
rcases zorn_subset T _ with ⟨m, ⟨mS, mx⟩, hm⟩,
{ exact ⟨m, mS, mx, λ a ha ha', hm a ⟨ha, subset.trans mx ha'⟩ ha'⟩ },
{ intros c cT hc,
cases c.eq_empty_or_nonempty with c0 c0,
{ rw c0, exact ⟨x, ⟨hx, subset.refl _⟩, λ _, false.elim⟩ },
{ rcases H _ (subset.trans cT (sep_subset _ _)) hc c0 with ⟨ub, us, h⟩,
refine ⟨ub, ⟨us, _⟩, h⟩,
rcases c0 with ⟨s, hs⟩,
exact subset.trans (cT hs).2 (h _ hs) } }
end
theorem chain.total {α : Type u} [preorder α]
{c : set α} (H : chain (≤) c) :
∀ {x y}, x ∈ c → y ∈ c → x ≤ y ∨ y ≤ x :=
λ x y, H.total_of_refl
theorem chain.image {α β : Type*} (r : α → α → Prop)
(s : β → β → Prop) (f : α → β)
(h : ∀ x y, r x y → s (f x) (f y))
{c : set α} (hrc : chain r c) : chain s (f '' c) :=
λ x ⟨a, ha₁, ha₂⟩ y ⟨b, hb₁, hb₂⟩, ha₂ ▸ hb₂ ▸ λ hxy,
(hrc a ha₁ b hb₁ (mt (congr_arg f) $ hxy)).elim
(or.inl ∘ h _ _) (or.inr ∘ h _ _)
end zorn
theorem directed_of_chain {α β r} [is_refl β r] {f : α → β} {c : set α}
(h : zorn.chain (f ⁻¹'o r) c) :
directed r (λx:{a:α // a ∈ c}, f (x.val)) :=
assume ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases
(assume : a = b, by simp only [this, exists_prop, and_self, subtype.exists];
exact ⟨b, hb, refl _⟩)
(assume : a ≠ b, (h a ha b hb this).elim
(λ h : r (f a) (f b), ⟨⟨b, hb⟩, h, refl _⟩)
(λ h : r (f b) (f a), ⟨⟨a, ha⟩, refl _, h⟩))
|
27c9e6aca050f33964de5418d97c3ff729520ec8
|
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
|
/stage0/src/Lean/Server/Snapshots.lean
|
208f650721020fd8c638f75219e436ba9ce8e532
|
[
"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
| 5,411
|
lean
|
/-
Copyright (c) 2020 Wojciech Nawrocki. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki
-/
import Init.System.IO
import Lean.Elab.Import
import Lean.Elab.Command
/-! One can think of this module as being a partial reimplementation
of Lean.Elab.Frontend which also stores a snapshot of the world after
each command. Importantly, we allow (re)starting compilation from any
snapshot/position in the file for interactive editing purposes. -/
namespace Lean.Server.Snapshots
open Elab
/-- What Lean knows about the world after the header and each command. -/
structure Snapshot where
/- Where the command which produced this snapshot begins. Note that
neighbouring snapshots are *not* necessarily attached beginning-to-end,
since inputs outside the grammar advance the parser but do not produce
snapshots. -/
beginPos : String.Pos
stx : Syntax
mpState : Parser.ModuleParserState
cmdState : Command.State
deriving Inhabited
namespace Snapshot
def endPos (s : Snapshot) : String.Pos := s.mpState.pos
def env (s : Snapshot) : Environment :=
s.cmdState.env
def msgLog (s : Snapshot) : MessageLog :=
s.cmdState.messages
end Snapshot
def reparseHeader (contents : String) (header : Snapshot) (opts : Options := {}) : IO Snapshot := do
let inputCtx := Parser.mkInputContext contents "<input>"
let (_, newHeaderParserState, _) ← Parser.parseHeader inputCtx
pure { header with mpState := newHeaderParserState }
private def ioErrorFromEmpty (ex : Empty) : IO.Error :=
nomatch ex
/-- Parses the next command occurring after the given snapshot
without elaborating it. -/
def parseNextCmd (contents : String) (snap : Snapshot) : IO Syntax := do
let inputCtx := Parser.mkInputContext contents "<input>"
let cmdState := snap.cmdState
let scope := cmdState.scopes.head!
let pmctx := { env := cmdState.env, options := scope.opts, currNamespace := scope.currNamespace, openDecls := scope.openDecls }
let (cmdStx, _, _) :=
Parser.parseCommand inputCtx pmctx snap.mpState snap.msgLog
cmdStx
/--
Parse remaining file without elaboration. NOTE that doing so can lead to parse errors or even wrong syntax objects,
so it should only be done for reporting preliminary results! -/
partial def parseAhead (contents : String) (snap : Snapshot) : IO (Array Syntax) := do
let inputCtx := Parser.mkInputContext contents "<input>"
let cmdState := snap.cmdState
let scope := cmdState.scopes.head!
let pmctx := { env := cmdState.env, options := scope.opts, currNamespace := scope.currNamespace, openDecls := scope.openDecls }
go inputCtx pmctx snap.mpState #[]
where
go inputCtx pmctx cmdParserState stxs := do
let (cmdStx, cmdParserState, _) := Parser.parseCommand inputCtx pmctx cmdParserState snap.msgLog
if Parser.isEOI cmdStx || Parser.isExitCommand cmdStx then
stxs.push cmdStx
else
go inputCtx pmctx cmdParserState (stxs.push cmdStx)
/-- Compiles the next command occurring after the given snapshot.
If there is no next command (file ended), returns messages produced
through the file. -/
-- NOTE: This code is really very similar to Elab.Frontend. But generalizing it
-- over "store snapshots"/"don't store snapshots" would likely result in confusing
-- isServer? conditionals and not be worth it due to how short it is.
def compileNextCmd (contents : String) (snap : Snapshot) : IO (Sum Snapshot MessageLog) := do
let inputCtx := Parser.mkInputContext contents "<input>"
let cmdState := snap.cmdState
let scope := cmdState.scopes.head!
let pmctx := { env := cmdState.env, options := scope.opts, currNamespace := scope.currNamespace, openDecls := scope.openDecls }
let (cmdStx, cmdParserState, msgLog) :=
Parser.parseCommand inputCtx pmctx snap.mpState snap.msgLog
let cmdPos := cmdStx.getPos?.get!
if Parser.isEOI cmdStx || Parser.isExitCommand cmdStx then
Sum.inr msgLog
else
let cmdStateRef ← IO.mkRef { snap.cmdState with messages := msgLog }
let cmdCtx : Elab.Command.Context := {
cmdPos := snap.endPos
fileName := inputCtx.fileName
fileMap := inputCtx.fileMap
}
let (output, _) ← IO.FS.withIsolatedStreams do
EIO.toIO ioErrorFromEmpty do
Elab.Command.catchExceptions
(Elab.Command.elabCommandTopLevel cmdStx)
cmdCtx cmdStateRef
let mut postCmdState ← cmdStateRef.get
if !output.isEmpty then
postCmdState := {
postCmdState with
messages := postCmdState.messages.add {
fileName := inputCtx.fileName
severity := MessageSeverity.information
pos := inputCtx.fileMap.toPosition snap.endPos
data := output
}
}
let postCmdSnap : Snapshot := {
beginPos := cmdPos
stx := cmdStx
mpState := cmdParserState
cmdState := postCmdState
}
Sum.inl postCmdSnap
/-- Compiles all commands after the given snapshot. Returns them as a list, together with
the final message log. -/
partial def compileCmdsAfter (contents : String) (snap : Snapshot) : IO (List Snapshot × MessageLog) := do
let cmdOut ← compileNextCmd contents snap
match cmdOut with
| Sum.inl snap =>
let (snaps, msgLog) ← compileCmdsAfter contents snap
(snap :: snaps, msgLog)
| Sum.inr msgLog => ([], msgLog)
end Lean.Server.Snapshots
|
cd5a85dee841f826e424fe590cde7bfe95fb2acb
|
d5ecf6c46a2f605470a4a7724909dc4b9e7350e0
|
/tests/norm_num.lean
|
24039a36afe75a118058570b354a111a5b29f9ea
|
[
"Apache-2.0"
] |
permissive
|
MonoidMusician/mathlib
|
41f79df478987a636b735c338396813d2e8e44c4
|
72234ef1a050eea3a2197c23aeb345fc13c08ff3
|
refs/heads/master
| 1,583,672,205,771
| 1,522,892,143,000
| 1,522,892,143,000
| 128,144,032
| 0
| 0
|
Apache-2.0
| 1,522,892,144,000
| 1,522,890,892,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 1,598
|
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
Tests for norm_num
-/
import analysis.real tactic.norm_num
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 : (5 / 2:ℕ) = 2 := by norm_num
example : (5 / -2:ℤ) < -1 := by norm_num
example : (0 + 1) / 2 < 0 + 1 := by norm_num
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 (x : ℕ) : ℕ := begin
let n : ℕ, {apply_normed (2^32 - 71)},
exact n
end
|
32bfedeb3379fcd5c7378bc03c84a569165d1a75
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/category_theory/limits/bicones.lean
|
741c3576f30965c959e870e2e63726ddec9bb4a8
|
[
"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,794
|
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.structured_arrow
import category_theory.fin_category
/-!
# Bicones
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₁
open category_theory.limits
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] [decidable_eq 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] [∀ (j k : J), decidable_eq (j ⟶ k)]
/-- 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 [∀ (j k : J), decidable_eq (j ⟶ k)] {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 [∀ (j k : J), decidable_eq (j ⟶ k)] :
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
|
e4b1204cc84e1a94a1fcbcce366ab3e3fbadeb9e
|
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
|
/06_Inductive_Types.org.49.lean
|
f9a91dcc41349bf4cd3acdd8912816f7e260787a
|
[] |
no_license
|
cjmazey/lean-tutorial
|
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
|
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
|
refs/heads/master
| 1,610,286,098,832
| 1,447,124,923,000
| 1,447,124,923,000
| 43,082,433
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 422
|
lean
|
/- page 94 -/
import standard
open nat
variable C : nat → Type
variable fz : C zero
variable fs : Π (n : nat), C n → C (succ n)
eval nat.rec fz fs zero
-- nat.rec_on is defined from nat.rec
eval nat.rec_on zero fz fs
example : nat.rec fz fs zero = fz :=
rfl
variable a : nat
eval nat.rec fz fs (succ a)
eval nat.rec_on (succ a) fz fs
example (a : nat) : nat.rec fz fs (succ a) = fs a (nat.rec fz fs a) :=
rfl
|
79d36099cdbb26cfac27317be2652879c33f1369
|
4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d
|
/src/Lean/PrettyPrinter/Formatter.lean
|
e67cc5a877e17378161c9103aaf93d125d567215
|
[
"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
| 21,586
|
lean
|
/-
Copyright (c) 2020 Sebastian Ullrich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
-/
import Lean.CoreM
import Lean.Parser.Extension
import Lean.KeyedDeclsAttribute
import Lean.ParserCompiler.Attribute
import Lean.PrettyPrinter.Basic
/-!
The formatter turns a `Syntax` tree into a `Format` object, inserting both mandatory whitespace (to separate adjacent
tokens) as well as "pretty" optional whitespace.
The basic approach works much like the parenthesizer: A right-to-left traversal over the syntax tree, driven by
parser-specific handlers registered via attributes. The traversal is right-to-left so that when emitting a token, we
already know the text following it and can decide whether or not whitespace between the two is necessary.
-/
namespace Lean
namespace PrettyPrinter
namespace Formatter
structure Context where
options : Options
table : Parser.TokenTable
structure State where
stxTrav : Syntax.Traverser
-- Textual content of `stack` up to the first whitespace (not enclosed in an escaped ident). We assume that the textual
-- content of `stack` is modified only by `pushText` and `pushLine`, so `leadWord` is adjusted there accordingly.
leadWord : String := ""
-- Stack of generated Format objects, analogous to the Syntax stack in the parser.
-- Note, however, that the stack is reversed because of the right-to-left traversal.
stack : Array Format := #[]
end Formatter
abbrev FormatterM := ReaderT Formatter.Context $ StateRefT Formatter.State CoreM
@[inline] def FormatterM.orElse {α} (p₁ : FormatterM α) (p₂ : Unit → FormatterM α) : FormatterM α := do
let s ← get
catchInternalId backtrackExceptionId
p₁
(fun _ => do set s; p₂ ())
instance {α} : OrElse (FormatterM α) := ⟨FormatterM.orElse⟩
abbrev Formatter := FormatterM Unit
unsafe def mkFormatterAttribute : IO (KeyedDeclsAttribute Formatter) :=
KeyedDeclsAttribute.init {
builtinName := `builtinFormatter,
name := `formatter,
descr := "Register a formatter for a parser.
[formatter k] registers a declaration of type `Lean.PrettyPrinter.Formatter` for the `SyntaxNodeKind` `k`.",
valueTypeName := `Lean.PrettyPrinter.Formatter,
evalKey := fun builtin stx => do
let env ← getEnv
let id ← Attribute.Builtin.getId stx
-- `isValidSyntaxNodeKind` is updated only in the next stage for new `[builtin*Parser]`s, but we try to
-- synthesize a formatter for it immediately, so we just check for a declaration in this case
if (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id then pure id
else throwError "invalid [formatter] argument, unknown syntax kind '{id}'"
} `Lean.PrettyPrinter.formatterAttribute
@[builtinInit mkFormatterAttribute] constant formatterAttribute : KeyedDeclsAttribute Formatter
unsafe def mkCombinatorFormatterAttribute : IO ParserCompiler.CombinatorAttribute :=
ParserCompiler.registerCombinatorAttribute
`combinatorFormatter
"Register a formatter for a parser combinator.
[combinatorFormatter c] registers a declaration of type `Lean.PrettyPrinter.Formatter` for the `Parser` declaration `c`.
Note that, unlike with [formatter], this is not a node kind since combinators usually do not introduce their own node kinds.
The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced
with `Formatter` in the parameter types."
@[builtinInit mkCombinatorFormatterAttribute] constant combinatorFormatterAttribute : ParserCompiler.CombinatorAttribute
namespace Formatter
open Lean.Core
open Lean.Parser
def throwBacktrack {α} : FormatterM α :=
throw $ Exception.internal backtrackExceptionId
instance : Syntax.MonadTraverser FormatterM := ⟨{
get := State.stxTrav <$> get,
set := fun t => modify (fun st => { st with stxTrav := t }),
modifyGet := fun f => modifyGet (fun st => let (a, t) := f st.stxTrav; (a, { st with stxTrav := t }))
}⟩
open Syntax.MonadTraverser
def getStack : FormatterM (Array Format) := do
let st ← get
pure st.stack
def getStackSize : FormatterM Nat := do
let stack ← getStack;
pure stack.size
def setStack (stack : Array Format) : FormatterM Unit :=
modify fun st => { st with stack := stack }
def push (f : Format) : FormatterM Unit :=
modify fun st => { st with stack := st.stack.push f }
def pushLine : FormatterM Unit := do
push Format.line;
modify fun st => { st with leadWord := "" }
/-- Execute `x` at the right-most child of the current node, if any, then advance to the left. -/
def visitArgs (x : FormatterM Unit) : FormatterM Unit := do
let stx ← getCur
if stx.getArgs.size > 0 then
goDown (stx.getArgs.size - 1) *> x <* goUp
goLeft
/-- Execute `x`, pass array of generated Format objects to `fn`, and push result. -/
def fold (fn : Array Format → Format) (x : FormatterM Unit) : FormatterM Unit := do
let sp ← getStackSize
x
let stack ← getStack
let f := fn $ stack.extract sp stack.size
setStack $ (stack.shrink sp).push f
/-- Execute `x` and concatenate generated Format objects. -/
def concat (x : FormatterM Unit) : FormatterM Unit := do
fold (Array.foldl (fun acc f => if acc.isNil then f else f ++ acc) Format.nil) x
def indent (x : Formatter) (indent : Option Int := none) : Formatter := do
concat x
let ctx ← read
let indent := indent.getD $ Std.Format.getIndent ctx.options
modify fun st => { st with stack := st.stack.modify (st.stack.size - 1) (Format.nest indent) }
def group (x : Formatter) : Formatter := do
concat x
modify fun st => { st with stack := st.stack.modify (st.stack.size - 1) Format.fill }
/-- If `pos?` has a position, run `x` and tag its results with that position. Otherwise just run `x`. -/
def withMaybeTag (pos? : Option String.Pos) (x : FormatterM Unit) : Formatter := do
if let some p := pos? then
concat x
modify fun st => { st with stack := st.stack.modify (st.stack.size - 1) (Format.tag p) }
else
x
@[combinatorFormatter Lean.Parser.orelse] def orelse.formatter (p1 p2 : Formatter) : Formatter :=
-- HACK: We have no (immediate) information on which side of the orelse could have produced the current node, so try
-- them in turn. Uses the syntax traverser non-linearly!
p1 <|> p2
-- `mkAntiquot` is quite complex, so we'd rather have its formatter synthesized below the actual parser definition.
-- Note that there is a mutual recursion
-- `categoryParser -> mkAntiquot -> termParser -> categoryParser`, so we need to introduce an indirection somewhere
-- anyway.
@[extern "lean_mk_antiquot_formatter"]
constant mkAntiquot.formatter' (name : String) (kind : Option SyntaxNodeKind) (anonymous := true) : Formatter
-- break up big mutual recursion
@[extern "lean_pretty_printer_formatter_interpret_parser_descr"]
constant interpretParserDescr' : ParserDescr → CoreM Formatter
unsafe def formatterForKindUnsafe (k : SyntaxNodeKind) : Formatter := do
if k == `missing then
push "<missing>"
goLeft
else
let stx ← getCur
let f ← runForNodeKind formatterAttribute k interpretParserDescr'
withMaybeTag stx.getPos? f
@[implementedBy formatterForKindUnsafe]
constant formatterForKind (k : SyntaxNodeKind) : Formatter
@[combinatorFormatter Lean.Parser.withAntiquot]
def withAntiquot.formatter (antiP p : Formatter) : Formatter :=
-- TODO: could be optimized using `isAntiquot` (which would have to be moved), but I'd rather
-- fix the backtracking hack outright.
orelse.formatter antiP p
@[combinatorFormatter Lean.Parser.withAntiquotSuffixSplice]
def withAntiquotSuffixSplice.formatter (k : SyntaxNodeKind) (p suffix : Formatter) : Formatter := do
if (← getCur).isAntiquotSuffixSplice then
visitArgs <| suffix *> p
else
p
@[combinatorFormatter Lean.Parser.tokenWithAntiquot]
def tokenWithAntiquot.formatter (p : Formatter) : Formatter := do
if (← getCur).isTokenAntiquot then
visitArgs p
else
p
@[combinatorFormatter Lean.Parser.categoryParser]
def categoryParser.formatter (cat : Name) : Formatter := group $ indent do
let stx ← getCur
trace[PrettyPrinter.format] "formatting {indentD (format stx)}"
if stx.getKind == `choice then
visitArgs do
-- format only last choice
-- TODO: We could use elaborator data here to format the chosen child when available
formatterForKind (← getCur).getKind
else
withAntiquot.formatter (mkAntiquot.formatter' cat.toString none) (formatterForKind stx.getKind)
@[combinatorFormatter Lean.Parser.categoryParserOfStack]
def categoryParserOfStack.formatter (offset : Nat) : Formatter := do
let st ← get
let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset)
categoryParser.formatter stx.getId
@[combinatorFormatter Lean.Parser.parserOfStack]
def parserOfStack.formatter (offset : Nat) (prec : Nat := 0) : Formatter := do
let st ← get
let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset)
formatterForKind stx.getKind
@[combinatorFormatter Lean.Parser.error]
def error.formatter (msg : String) : Formatter := pure ()
@[combinatorFormatter Lean.Parser.errorAtSavedPos]
def errorAtSavedPos.formatter (msg : String) (delta : Bool) : Formatter := pure ()
@[combinatorFormatter Lean.Parser.atomic]
def atomic.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.lookahead]
def lookahead.formatter (p : Formatter) : Formatter := pure ()
@[combinatorFormatter Lean.Parser.notFollowedBy]
def notFollowedBy.formatter (p : Formatter) : Formatter := pure ()
@[combinatorFormatter Lean.Parser.andthen]
def andthen.formatter (p1 p2 : Formatter) : Formatter := p2 *> p1
def checkKind (k : SyntaxNodeKind) : FormatterM Unit := do
let stx ← getCur
if k != stx.getKind then
trace[PrettyPrinter.format.backtrack] "unexpected node kind '{stx.getKind}', expected '{k}'"
throwBacktrack
@[combinatorFormatter Lean.Parser.node]
def node.formatter (k : SyntaxNodeKind) (p : Formatter) : Formatter := do
checkKind k;
visitArgs p
@[combinatorFormatter Lean.Parser.trailingNode]
def trailingNode.formatter (k : SyntaxNodeKind) (_ _ : Nat) (p : Formatter) : Formatter := do
checkKind k
visitArgs do
p;
-- leading term, not actually produced by `p`
categoryParser.formatter `foo
def parseToken (s : String) : FormatterM ParserState := do
-- include comment tokens, e.g. when formatting `- -0`
(Parser.andthenFn Parser.whitespace (Parser.tokenFn [])) {
input := s,
fileName := "",
fileMap := FileMap.ofString "",
prec := 0,
env := ← getEnv,
options := ← getOptions,
tokens := (← read).table } (Parser.mkParserState s)
def pushTokenCore (tk : String) : FormatterM Unit := do
if tk.toSubstring.dropRightWhile (fun s => s == ' ') == tk.toSubstring then
push tk
else
pushLine
push tk.trimRight
def pushToken (info : SourceInfo) (tk : String) : FormatterM Unit := do
match info with
| SourceInfo.original _ _ ss _ =>
-- preserve non-whitespace content (i.e. comments)
let ss' := ss.trim
if !ss'.isEmpty then
let ws := { ss with startPos := ss'.stopPos }
if ws.contains '\n' then
push s!"\n{ss'}"
else
push s!" {ss'}"
modify fun st => { st with leadWord := "" }
| _ => pure ()
let st ← get
-- If there is no space between `tk` and the next word, see if we would parse more than `tk` as a single token
if st.leadWord != "" && tk.trimRight == tk then
let tk' := tk.trimLeft
let t ← parseToken $ tk' ++ st.leadWord
if t.pos <= tk'.bsize then
-- stopped within `tk` => use it as is, extend `leadWord` if not prefixed by whitespace
pushTokenCore tk
modify fun st => { st with leadWord := if tk.trimLeft == tk then tk ++ st.leadWord else "" }
else
-- stopped after `tk` => add space
pushTokenCore $ tk ++ " "
modify fun st => { st with leadWord := if tk.trimLeft == tk then tk else "" }
else
-- already separated => use `tk` as is
pushTokenCore tk
modify fun st => { st with leadWord := if tk.trimLeft == tk then tk else "" }
match info with
| SourceInfo.original ss _ _ _ =>
-- preserve non-whitespace content (i.e. comments)
let ss' := ss.trim
if !ss'.isEmpty then
let ws := { ss with startPos := ss'.stopPos }
if ws.contains '\n' then do
-- Indentation is automatically increased when entering a category, but comments should be aligned
-- with the actual token, so dedent
indent (push s!"{ss'}\n") (some ((0:Int) - Std.Format.getIndent (← getOptions)))
else
push s!"{ss'} "
modify fun st => { st with leadWord := "" }
| _ => pure ()
@[combinatorFormatter Lean.Parser.symbolNoAntiquot]
def symbolNoAntiquot.formatter (sym : String) : Formatter := do
let stx ← getCur
if stx.isToken sym then do
let (Syntax.atom info _) ← pure stx | unreachable!
pushToken info sym
goLeft
else do
trace[PrettyPrinter.format.backtrack] "unexpected syntax '{format stx}', expected symbol '{sym}'"
throwBacktrack
@[combinatorFormatter Lean.Parser.nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.formatter := symbolNoAntiquot.formatter
@[combinatorFormatter Lean.Parser.rawCh] def rawCh.formatter (ch : Char) := symbolNoAntiquot.formatter ch.toString
@[combinatorFormatter Lean.Parser.unicodeSymbolNoAntiquot]
def unicodeSymbolNoAntiquot.formatter (sym asciiSym : String) : Formatter := do
let Syntax.atom info val ← getCur
| throwError m!"not an atom: {← getCur}"
if val == sym.trim then
pushToken info sym
else
pushToken info asciiSym;
goLeft
@[combinatorFormatter Lean.Parser.identNoAntiquot]
def identNoAntiquot.formatter : Formatter := do
checkKind identKind
let Syntax.ident info _ id _ ← getCur
| throwError m!"not an ident: {← getCur}"
let id := id.simpMacroScopes
pushToken info id.toString
goLeft
@[combinatorFormatter Lean.Parser.rawIdentNoAntiquot] def rawIdentNoAntiquot.formatter : Formatter := do
checkKind identKind
let Syntax.ident info _ id _ ← getCur
| throwError m!"not an ident: {← getCur}"
pushToken info id.toString
goLeft
@[combinatorFormatter Lean.Parser.identEq] def identEq.formatter (id : Name) := rawIdentNoAntiquot.formatter
def visitAtom (k : SyntaxNodeKind) : Formatter := do
let stx ← getCur
if k != Name.anonymous then
checkKind k
let Syntax.atom info val ← pure $ stx.ifNode (fun n => n.getArg 0) (fun _ => stx)
| throwError m!"not an atom: {stx}"
pushToken info val
goLeft
@[combinatorFormatter Lean.Parser.charLitNoAntiquot] def charLitNoAntiquot.formatter := visitAtom charLitKind
@[combinatorFormatter Lean.Parser.strLitNoAntiquot] def strLitNoAntiquot.formatter := visitAtom strLitKind
@[combinatorFormatter Lean.Parser.nameLitNoAntiquot] def nameLitNoAntiquot.formatter := visitAtom nameLitKind
@[combinatorFormatter Lean.Parser.numLitNoAntiquot] def numLitNoAntiquot.formatter := visitAtom numLitKind
@[combinatorFormatter Lean.Parser.scientificLitNoAntiquot] def scientificLitNoAntiquot.formatter := visitAtom scientificLitKind
@[combinatorFormatter Lean.Parser.fieldIdx] def fieldIdx.formatter := visitAtom fieldIdxKind
@[combinatorFormatter Lean.Parser.manyNoAntiquot]
def manyNoAntiquot.formatter (p : Formatter) : Formatter := do
let stx ← getCur
visitArgs $ stx.getArgs.size.forM fun _ => p
@[combinatorFormatter Lean.Parser.many1NoAntiquot] def many1NoAntiquot.formatter (p : Formatter) : Formatter := manyNoAntiquot.formatter p
@[combinatorFormatter Lean.Parser.optionalNoAntiquot]
def optionalNoAntiquot.formatter (p : Formatter) : Formatter := visitArgs p
@[combinatorFormatter Lean.Parser.many1Unbox]
def many1Unbox.formatter (p : Formatter) : Formatter := do
let stx ← getCur
if stx.getKind == nullKind then do
manyNoAntiquot.formatter p
else
p
@[combinatorFormatter Lean.Parser.sepByNoAntiquot]
def sepByNoAntiquot.formatter (p pSep : Formatter) : Formatter := do
let stx ← getCur
visitArgs $ (List.range stx.getArgs.size).reverse.forM $ fun i => if i % 2 == 0 then p else pSep
@[combinatorFormatter Lean.Parser.sepBy1NoAntiquot] def sepBy1NoAntiquot.formatter := sepByNoAntiquot.formatter
@[combinatorFormatter Lean.Parser.withPosition] def withPosition.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.withoutPosition] def withoutPosition.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.withForbidden] def withForbidden.formatter (tk : Token) (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.withoutForbidden] def withoutForbidden.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.withoutInfo] def withoutInfo.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.setExpected]
def setExpected.formatter (expected : List String) (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.incQuotDepth] def incQuotDepth.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.decQuotDepth] def decQuotDepth.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.suppressInsideQuot] def suppressInsideQuot.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.evalInsideQuot] def evalInsideQuot.formatter (declName : Name) (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.checkWsBefore] def checkWsBefore.formatter : Formatter := do
let st ← get
if st.leadWord != "" then
pushLine
@[combinatorFormatter Lean.Parser.checkPrec] def checkPrec.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkLhsPrec] def checkLhsPrec.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.setLhsPrec] def setLhsPrec.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkStackTop] def checkStackTop.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkNoWsBefore] def checkNoWsBefore.formatter : Formatter :=
-- prevent automatic whitespace insertion
modify fun st => { st with leadWord := "" }
@[combinatorFormatter Lean.Parser.checkLinebreakBefore] def checkLinebreakBefore.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkTailWs] def checkTailWs.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkColGe] def checkColGe.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkColGt] def checkColGt.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkLineEq] def checkLineEq.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.eoi] def eoi.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.notFollowedByCategoryToken] def notFollowedByCategoryToken.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkNoImmediateColon] def checkNoImmediateColon.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkInsideQuot] def checkInsideQuot.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.checkOutsideQuot] def checkOutsideQuot.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.skip] def skip.formatter : Formatter := pure ()
@[combinatorFormatter Lean.Parser.pushNone] def pushNone.formatter : Formatter := goLeft
@[combinatorFormatter Lean.Parser.withOpenDecl] def withOpenDecl.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.withOpen] def withOpen.formatter (p : Formatter) : Formatter := p
@[combinatorFormatter Lean.Parser.interpolatedStr]
def interpolatedStr.formatter (p : Formatter) : Formatter := do
visitArgs $ (← getCur).getArgs.reverse.forM fun chunk =>
match chunk.isLit? interpolatedStrLitKind with
| some str => push str *> goLeft
| none => p
@[combinatorFormatter Lean.Parser.dbgTraceState] def dbgTraceState.formatter (label : String) (p : Formatter) : Formatter := p
@[combinatorFormatter ite, macroInline] def ite {α : Type} (c : Prop) [h : Decidable c] (t e : Formatter) : Formatter :=
if c then t else e
abbrev FormatterAliasValue := AliasValue Formatter
builtin_initialize formatterAliasesRef : IO.Ref (NameMap FormatterAliasValue) ← IO.mkRef {}
def registerAlias (aliasName : Name) (v : FormatterAliasValue) : IO Unit := do
Parser.registerAliasCore formatterAliasesRef aliasName v
instance : Coe Formatter FormatterAliasValue := { coe := AliasValue.const }
instance : Coe (Formatter → Formatter) FormatterAliasValue := { coe := AliasValue.unary }
instance : Coe (Formatter → Formatter → Formatter) FormatterAliasValue := { coe := AliasValue.binary }
end Formatter
open Formatter
def format (formatter : Formatter) (stx : Syntax) : CoreM Format := do
trace[PrettyPrinter.format.input] "{Std.format stx}"
let options ← getOptions
let table ← Parser.builtinTokenTable.get
catchInternalId backtrackExceptionId
(do
let (_, st) ← (concat formatter { table := table, options := options }).run { stxTrav := Syntax.Traverser.fromSyntax stx };
pure $ Format.fill $ st.stack.get! 0)
(fun _ => throwError "format: uncaught backtrack exception")
def formatTerm := format $ categoryParser.formatter `term
def formatTactic := format $ categoryParser.formatter `tactic
def formatCommand := format $ categoryParser.formatter `command
builtin_initialize registerTraceClass `PrettyPrinter.format;
end PrettyPrinter
end Lean
|
0fd89cc9459ee16c702b5fcba02b06c631174d48
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/structInst3.lean
|
136a250408cf8ba69b606a8a1f5b37b72495b5b5
|
[
"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
| 639
|
lean
|
universe u
namespace Ex1
structure A (α : Type u) :=
(x : α) (f : α → α := λ x => x)
structure B (α : Type u) extends A α :=
(y : α := f (f x)) (g : α → α → α := λ x y => f x)
structure C (α : Type u) extends B α :=
(z : α := g x y) (x := f z)
end Ex1
open Ex1
def c1 : C Nat := { x := 1 }
#check { c1 with z := 2 }
#check { c1 with z := 2 }
theorem ex1 : { c1 with z := 2 }.z = 2 :=
rfl
#check ex1
theorem ex2 : { c1 with z := 2 }.x = c1.x :=
rfl
#check ex2
def c2 : C (Nat × Nat) := { z := (1, 1) }
#check { c2 with x.fst := 2 }
#check { c2 with x.1 := 3 }
#check show C _ from { c2.toB with .. }
|
c7ed5d5a223e983318a03a1e028e16dc9fdc10a8
|
432d948a4d3d242fdfb44b81c9e1b1baacd58617
|
/src/algebra/module/linear_map.lean
|
572797f1c032f1338277979a0eea93a2c4f69031
|
[
"Apache-2.0"
] |
permissive
|
JLimperg/aesop3
|
306cc6570c556568897ed2e508c8869667252e8a
|
a4a116f650cc7403428e72bd2e2c4cda300fe03f
|
refs/heads/master
| 1,682,884,916,368
| 1,620,320,033,000
| 1,620,320,033,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 18,637
|
lean
|
/-
Copyright (c) 2020 Anne Baanen. 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, Anne Baanen
-/
import algebra.group.hom
import algebra.module.basic
import algebra.group_action_hom
/-!
# Linear maps and linear equivalences
In this file we define
* `linear_map R M M₂`, `M →ₗ[R] M₂` : a linear map between two R-`module`s.
* `is_linear_map R f` : predicate saying that `f : M → M₂` is a linear map.
* `linear_equiv R M ₂`, `M ≃ₗ[R] M₂`: an invertible linear map
## Tags
linear map, linear equiv, linear equivalences, linear isomorphism, linear isomorphic
-/
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}
/-- A map `f` between modules 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₂] [module R M] [module 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)
section
set_option old_structure_cmd true
/-- A map `f` between modules 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₂] [module R M] [module R M₂]
extends add_hom M M₂, M →[R] M₂
end
/-- The `add_hom` underlying a `linear_map`. -/
add_decl_doc linear_map.to_add_hom
/-- The `mul_action_hom` underlying a `linear_map`. -/
add_decl_doc linear_map.to_mul_action_hom
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 [module R M] [module R M₂]
/-- The `distrib_mul_action_hom` underlying a `linear_map`. -/
def to_distrib_mul_action_hom (f : M →ₗ[R] M₂) : distrib_mul_action_hom R M M₂ :=
{ map_zero' := zero_smul R (0 : M) ▸ zero_smul R (f.to_fun 0) ▸ f.map_smul' 0 0, ..f }
instance : has_coe_to_fun (M →ₗ[R] M₂) := ⟨_, to_fun⟩
initialize_simps_projections linear_map (to_fun → apply)
@[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
variables [module R M] [module 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_injective : injective (λ f : M →ₗ[R] M₂, show M → M₂, from f) :=
by rintro ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩; congr
@[ext] theorem ext (H : ∀ x, f x = g x) : f = g :=
coe_injective $ funext H
protected lemma congr_arg : Π {x x' : M}, x = x' → f x = f x'
| _ _ rfl := rfl
/-- If two linear maps are equal, they are equal at each point. -/
protected lemma congr_fun (h : f = g) (x : M) : f x = g x := h ▸ rfl
theorem ext_iff : f = g ↔ ∀ x, f x = g x :=
⟨by { rintro rfl x, refl }, ext⟩
@[simp] lemma mk_coe (f : M →ₗ[R] M₂) (h₁ h₂) :
(linear_map.mk f h₁ h₂ : M →ₗ[R] M₂) = f := ext $ λ _, rfl
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 :=
f.to_distrib_mul_action_hom.map_zero
variables (M M₂)
/--
A typeclass for `has_scalar` structures which can be moved through a `linear_map`.
This typeclass is generated automatically from a `is_scalar_tower` instance, but exists so that
we can also add an instance for `add_comm_group.int_module`, allowing `z •` to be moved even if
`R` does not support negation.
-/
class compatible_smul (R S : Type*) [semiring S] [has_scalar R M]
[module S M] [has_scalar R M₂] [module S M₂] :=
(map_smul : ∀ (f : M →ₗ[S] M₂) (c : R) (x : M), f (c • x) = c • f x)
variables {M M₂}
@[priority 100]
instance is_scalar_tower.compatible_smul
{R S : Type*} [semiring S] [has_scalar R S]
[has_scalar R M] [module S M] [is_scalar_tower R S M]
[has_scalar R M₂] [module S M₂] [is_scalar_tower R S M₂] : compatible_smul M M₂ R S :=
⟨λ f c x, by rw [← smul_one_smul S c x, ← smul_one_smul S c (f x), map_smul]⟩
@[simp, priority 900]
lemma map_smul_of_tower {R S : Type*} [semiring S] [has_scalar R M]
[module S M] [has_scalar R M₂] [module S M₂]
[compatible_smul M M₂ R S] (f : M →ₗ[S] M₂) (c : R) (x : M) :
f (c • x) = c • f x :=
compatible_smul.map_smul f c x
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 = f := rfl
variable (R)
/-- If `M` and `M₂` are both `R`-modules and `S`-modules and `R`-module structures
are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear
map from `M` to `M₂` is `R`-linear.
See also `linear_map.map_smul_of_tower`. -/
def restrict_scalars {S : Type*} [semiring S] [module S M] [module S M₂]
[compatible_smul M M₂ R S] (f : M →ₗ[S] M₂) : M →ₗ[R] M₂ :=
{ to_fun := f,
map_add' := f.map_add,
map_smul' := f.map_smul_of_tower }
variable {R}
@[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 _ _
theorem to_add_monoid_hom_injective :
function.injective (to_add_monoid_hom : (M →ₗ[R] M₂) → (M →+ M₂)) :=
λ f g h, ext $ add_monoid_hom.congr_fun h
/-- If two `R`-linear maps from `R` are equal on `1`, then they are equal. -/
@[ext] theorem ext_ring {f g : R →ₗ[R] M} (h : f 1 = g 1) : f = g :=
ext $ λ x, by rw [← mul_one x, ← smul_eq_mul, f.map_smul, g.map_smul, h]
theorem ext_ring_iff {f g : R →ₗ[R] M} : f = g ↔ f 1 = g 1 :=
⟨λ h, h ▸ rfl, ext_ring⟩
end
section
variables {module_M : module R M} {module_M₂ : module R M₂}
{module_M₃ : module 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⟩
lemma comp_apply (x : M) : f.comp g x = f (g x) := rfl
@[simp, norm_cast] lemma coe_comp : (f.comp g : M → M₃) = f ∘ g := rfl
@[simp] theorem comp_id : f.comp id = f :=
linear_map.ext $ λ x, rfl
@[simp] theorem id_comp : id.comp f = f :=
linear_map.ext $ λ x, rfl
end
/-- If a function `g` is a left and right inverse of a linear map `f`, then `g` is linear itself. -/
def inverse [module R M] [module R M₂]
(f : M →ₗ[R] M₂) (g : M₂ → M) (h₁ : left_inverse g f) (h₂ : right_inverse g f) :
M₂ →ₗ[R] M :=
by dsimp [left_inverse, function.right_inverse] at h₁ h₂; exact
⟨g, λ x y, by { rw [← h₁ (g (x + y)), ← h₁ (g x + g y)]; simp [h₂] },
λ a b, by { rw [← h₁ (g (a • b)), ← h₁ (a • g b)]; simp [h₂] }⟩
end add_comm_monoid
section add_comm_group
variables [semiring R] [add_comm_group M] [add_comm_group M₂]
variables {module_M : module R M} {module_M₂ : module 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 }
instance compatible_smul.int_module
{S : Type*} [semiring S] [module S M] [module S M₂] : compatible_smul M M₂ ℤ S :=
⟨λ f c x, begin
induction c using int.induction_on,
case hz : { simp },
case hp : n ih { simp [add_smul, ih] },
case hn : n ih { simp [sub_smul, ih] }
end⟩
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 [module R M] [module 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] [module 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
lemma is_linear_map_smul' {R M : Type*} [semiring R] [add_comm_monoid M] [module 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 [module R M] [module 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
/-- Linear endomorphisms of a module, with associated ring structure
`linear_map.endomorphism_semiring` and algebra structure `module.endomorphism_algebra`. -/
abbreviation module.End (R : Type u) (M : Type v)
[semiring R] [add_comm_monoid M] [module R M] := M →ₗ[R] M
/-- 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] [module ℚ M]
[add_comm_group M₂] [module ℚ M₂] (f : M →+ M₂) :
M →ₗ[ℚ] M₂ :=
{ map_smul' := f.map_rat_module_smul, ..f }
/-! ### Linear equivalences -/
section
set_option old_structure_cmd true
/-- A linear equivalence is an invertible linear map. -/
@[nolint has_inhabited_instance]
structure linear_equiv (R : Type u) (M : Type v) (M₂ : Type w)
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module R M₂]
extends M →ₗ[R] M₂, M ≃+ M₂
end
attribute [nolint doc_blame] linear_equiv.to_linear_map
attribute [nolint doc_blame] linear_equiv.to_add_equiv
infix ` ≃ₗ ` := linear_equiv _
notation M ` ≃ₗ[`:50 R `] ` M₂ := linear_equiv R M M₂
namespace linear_equiv
section add_comm_monoid
variables {M₄ : Type*}
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
section
variables [module R M] [module R M₂] [module R M₃]
include R
instance : has_coe (M ≃ₗ[R] M₂) (M →ₗ[R] M₂) := ⟨to_linear_map⟩
-- see Note [function coercion]
instance : has_coe_to_fun (M ≃ₗ[R] M₂) := ⟨_, λ f, f.to_fun⟩
@[simp] lemma coe_mk {to_fun inv_fun map_add map_smul left_inv right_inv } :
⇑(⟨to_fun, map_add, map_smul, inv_fun, left_inv, right_inv⟩ : M ≃ₗ[R] M₂) = to_fun :=
rfl
-- This exists for compatibility, previously `≃ₗ[R]` extended `≃` instead of `≃+`.
@[nolint doc_blame]
def to_equiv : (M ≃ₗ[R] M₂) → M ≃ M₂ := λ f, f.to_add_equiv.to_equiv
lemma to_equiv_injective : function.injective (to_equiv : (M ≃ₗ[R] M₂) → M ≃ M₂) :=
λ ⟨_, _, _, _, _, _⟩ ⟨_, _, _, _, _, _⟩ h, linear_equiv.mk.inj_eq.mpr (equiv.mk.inj h)
@[simp] lemma to_equiv_inj {e₁ e₂ : M ≃ₗ[R] M₂} : e₁.to_equiv = e₂.to_equiv ↔ e₁ = e₂ :=
to_equiv_injective.eq_iff
lemma to_linear_map_injective : function.injective (coe : (M ≃ₗ[R] M₂) → (M →ₗ[R] M₂)) :=
λ e₁ e₂ H, to_equiv_injective $ equiv.ext $ linear_map.congr_fun H
@[simp, norm_cast] lemma to_linear_map_inj {e₁ e₂ : M ≃ₗ[R] M₂} :
(e₁ : M →ₗ[R] M₂) = e₂ ↔ e₁ = e₂ :=
to_linear_map_injective.eq_iff
end
section
variables {module_M : module R M} {module_M₂ : module R M₂}
variables (e e' : M ≃ₗ[R] M₂)
lemma to_linear_map_eq_coe : e.to_linear_map = ↑e := rfl
@[simp, norm_cast] theorem coe_coe : ⇑(e : M →ₗ[R] M₂) = e := rfl
@[simp] lemma coe_to_equiv : ⇑e.to_equiv = e := rfl
@[simp] lemma coe_to_linear_map : ⇑e.to_linear_map = e := rfl
@[simp] lemma to_fun_eq_coe : e.to_fun = e := rfl
section
variables {e e'}
@[ext] lemma ext (h : ∀ x, e x = e' x) : e = e' :=
to_equiv_injective (equiv.ext h)
protected lemma congr_arg : Π {x x' : M}, x = x' → e x = e x'
| _ _ rfl := rfl
protected lemma congr_fun (h : e = e') (x : M) : e x = e' x := h ▸ rfl
lemma ext_iff : e = e' ↔ ∀ x, e x = e' x :=
⟨λ h x, h ▸ rfl, ext⟩
end
section
variables (M R)
/-- The identity map is a linear equivalence. -/
@[refl]
def refl [module R M] : M ≃ₗ[R] M := { .. linear_map.id, .. equiv.refl M }
end
@[simp] lemma refl_apply [module R M] (x : M) : refl R M x = x := rfl
/-- Linear equivalences are symmetric. -/
@[symm]
def symm : M₂ ≃ₗ[R] M :=
{ .. e.to_linear_map.inverse e.inv_fun e.left_inv e.right_inv,
.. e.to_equiv.symm }
/-- See Note [custom simps projection] -/
def simps.symm_apply [module R M] [module R M₂] (e : M ≃ₗ[R] M₂) : M₂ → M := e.symm
initialize_simps_projections linear_equiv (to_fun → apply, inv_fun → symm_apply)
@[simp] lemma inv_fun_eq_symm : e.inv_fun = e.symm := rfl
variables {module_M₃ : module R M₃} (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃)
/-- Linear equivalences are transitive. -/
@[trans]
def trans : M ≃ₗ[R] M₃ :=
{ .. e₂.to_linear_map.comp e₁.to_linear_map,
.. e₁.to_equiv.trans e₂.to_equiv }
@[simp] lemma coe_to_add_equiv : ⇑(e.to_add_equiv) = e := rfl
/-- The two paths coercion can take to an `add_monoid_hom` are equivalent -/
lemma to_add_monoid_hom_commutes :
e.to_linear_map.to_add_monoid_hom = e.to_add_equiv.to_add_monoid_hom :=
rfl
@[simp] theorem trans_apply (c : M) :
(e₁.trans e₂) c = e₂ (e₁ c) := rfl
@[simp] theorem apply_symm_apply (c : M₂) : e (e.symm c) = c := e.6 c
@[simp] theorem symm_apply_apply (b : M) : e.symm (e b) = b := e.5 b
@[simp] lemma symm_trans_apply (c : M₃) : (e₁.trans e₂).symm c = e₁.symm (e₂.symm c) := rfl
@[simp] lemma trans_refl : e.trans (refl R M₂) = e := to_equiv_injective e.to_equiv.trans_refl
@[simp] lemma refl_trans : (refl R M).trans e = e := to_equiv_injective e.to_equiv.refl_trans
lemma symm_apply_eq {x y} : e.symm x = y ↔ x = e y := e.to_equiv.symm_apply_eq
lemma eq_symm_apply {x y} : y = e.symm x ↔ e y = x := e.to_equiv.eq_symm_apply
@[simp] lemma trans_symm [module R M] [module R M₂] (f : M ≃ₗ[R] M₂) :
f.trans f.symm = linear_equiv.refl R M :=
by { ext x, simp }
@[simp] lemma symm_trans [module R M] [module R M₂] (f : M ≃ₗ[R] M₂) :
f.symm.trans f = linear_equiv.refl R M₂ :=
by { ext x, simp }
@[simp, norm_cast] lemma refl_to_linear_map [module R M] :
(linear_equiv.refl R M : M →ₗ[R] M) = linear_map.id :=
rfl
@[simp, norm_cast]
lemma comp_coe [module R M] [module R M₂] [module R M₃] (f : M ≃ₗ[R] M₂)
(f' : M₂ ≃ₗ[R] M₃) : (f' : M₂ →ₗ[R] M₃).comp (f : M →ₗ[R] M₂) = (f.trans f' : M →ₗ[R] M₃) :=
rfl
@[simp] lemma mk_coe (h₁ h₂ f h₃ h₄) :
(linear_equiv.mk e h₁ h₂ f h₃ h₄ : M ≃ₗ[R] M₂) = e := ext $ λ _, rfl
@[simp] theorem map_add (a b : M) : e (a + b) = e a + e b := e.map_add' a b
@[simp] theorem map_zero : e 0 = 0 := e.to_linear_map.map_zero
@[simp] theorem map_smul (c : R) (x : M) : e (c • x) = c • e x := e.map_smul' c x
@[simp] lemma map_sum {s : finset ι} (u : ι → M) : e (∑ i in s, u i) = ∑ i in s, e (u i) :=
e.to_linear_map.map_sum
@[simp] theorem map_eq_zero_iff {x : M} : e x = 0 ↔ x = 0 :=
e.to_add_equiv.map_eq_zero_iff
theorem map_ne_zero_iff {x : M} : e x ≠ 0 ↔ x ≠ 0 :=
e.to_add_equiv.map_ne_zero_iff
@[simp] theorem symm_symm : e.symm.symm = e := by { cases e, refl }
lemma symm_bijective [module R M] [module R M₂] :
function.bijective (symm : (M ≃ₗ[R] M₂) → (M₂ ≃ₗ[R] M)) :=
equiv.bijective ⟨symm, symm, symm_symm, symm_symm⟩
@[simp] lemma mk_coe' (f h₁ h₂ h₃ h₄) :
(linear_equiv.mk f h₁ h₂ ⇑e h₃ h₄ : M₂ ≃ₗ[R] M) = e.symm :=
symm_bijective.injective $ ext $ λ x, rfl
@[simp] theorem symm_mk (f h₁ h₂ h₃ h₄) :
(⟨e, h₁, h₂, f, h₃, h₄⟩ : M ≃ₗ[R] M₂).symm =
{ to_fun := f, inv_fun := e,
..(⟨e, h₁, h₂, f, h₃, h₄⟩ : M ≃ₗ[R] M₂).symm } := rfl
protected lemma bijective : function.bijective e := e.to_equiv.bijective
protected lemma injective : function.injective e := e.to_equiv.injective
protected lemma surjective : function.surjective e := e.to_equiv.surjective
protected lemma image_eq_preimage (s : set M) : e '' s = e.symm ⁻¹' s :=
e.to_equiv.image_eq_preimage s
end
/-- An involutive linear map is a linear equivalence. -/
def of_involutive [module R M] (f : M →ₗ[R] M) (hf : involutive f) : M ≃ₗ[R] M :=
{ .. f, .. hf.to_equiv f }
@[simp] lemma coe_of_involutive [module R M] (f : M →ₗ[R] M) (hf : involutive f) :
⇑(of_involutive f hf) = f :=
rfl
end add_comm_monoid
end linear_equiv
|
264fd74ae3fd626b1b52caf600d58d6077ee80de
|
b00eb947a9c4141624aa8919e94ce6dcd249ed70
|
/stage0/src/Init/Data/Int/Basic.lean
|
a40b134884b02bad8ad72221a86a998a0ce05891
|
[
"Apache-2.0"
] |
permissive
|
gebner/lean4-old
|
a4129a041af2d4d12afb3a8d4deedabde727719b
|
ee51cdfaf63ee313c914d83264f91f414a0e3b6e
|
refs/heads/master
| 1,683,628,606,745
| 1,622,651,300,000
| 1,622,654,405,000
| 142,608,821
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,545
|
lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
The integers, with addition, multiplication, and subtraction.
-/
prelude
import Init.Coe
import Init.Data.Nat.Div
import Init.Data.List.Basic
open Nat
/- the Type, coercions, and notation -/
inductive Int : Type where
| ofNat : Nat → Int
| negSucc : Nat → Int
attribute [extern "lean_nat_to_int"] Int.ofNat
attribute [extern "lean_int_neg_succ_of_nat"] Int.negSucc
instance : Coe Nat Int := ⟨Int.ofNat⟩
namespace Int
instance : Inhabited Int := ⟨ofNat 0⟩
def negOfNat : Nat → Int
| 0 => 0
| succ m => negSucc m
set_option bootstrap.genMatcherCode false in
@[extern "lean_int_neg"]
protected def neg (n : @& Int) : Int :=
match n with
| ofNat n => negOfNat n
| negSucc n => succ n
def subNatNat (m n : Nat) : Int :=
match (n - m : Nat) with
| 0 => ofNat (m - n) -- m ≥ n
| (succ k) => negSucc k
set_option bootstrap.genMatcherCode false in
@[extern "lean_int_add"]
protected def add (m n : @& Int) : Int :=
match m, n with
| ofNat m, ofNat n => ofNat (m + n)
| ofNat m, negSucc n => subNatNat m (succ n)
| negSucc m, ofNat n => subNatNat n (succ m)
| negSucc m, negSucc n => negSucc (succ (m + n))
set_option bootstrap.genMatcherCode false in
@[extern "lean_int_mul"]
protected def mul (m n : @& Int) : Int :=
match m, n with
| ofNat m, ofNat n => ofNat (m * n)
| ofNat m, negSucc n => negOfNat (m * succ n)
| negSucc m, ofNat n => negOfNat (succ m * n)
| negSucc m, negSucc n => ofNat (succ m * succ n)
/-
The `Neg Int` default instance must have priority higher than `low` since
the default instance `OfNat Nat n` has `low` priority.
```
#check -42
```
-/
@[defaultInstance mid]
instance : Neg Int where
neg := Int.neg
instance : Add Int where
add := Int.add
instance : Mul Int where
mul := Int.mul
@[extern "lean_int_sub"]
protected def sub (m n : @& Int) : Int :=
m + (- n)
instance : Sub Int where
sub := Int.sub
inductive NonNeg : Int → Prop where
| mk (n : Nat) : NonNeg (ofNat n)
protected def le (a b : Int) : Prop := NonNeg (b - a)
instance : LE Int where
le := Int.le
protected def lt (a b : Int) : Prop := (a + 1) ≤ b
instance : LT Int where
lt := Int.lt
set_option bootstrap.genMatcherCode false in
@[extern "lean_int_dec_eq"]
protected def decEq (a b : @& Int) : Decidable (a = b) :=
match a, b with
| ofNat a, ofNat b => match decEq a b with
| isTrue h => isTrue <| h ▸ rfl
| isFalse h => isFalse <| fun h' => Int.noConfusion h' (fun h' => absurd h' h)
| negSucc a, negSucc b => match decEq a b with
| isTrue h => isTrue <| h ▸ rfl
| isFalse h => isFalse <| fun h' => Int.noConfusion h' (fun h' => absurd h' h)
| ofNat a, negSucc b => isFalse <| fun h => Int.noConfusion h
| negSucc a, ofNat b => isFalse <| fun h => Int.noConfusion h
instance : DecidableEq Int := Int.decEq
set_option bootstrap.genMatcherCode false in
@[extern "lean_int_dec_nonneg"]
private def decNonneg (m : @& Int) : Decidable (NonNeg m) :=
match m with
| ofNat m => isTrue <| NonNeg.mk m
| negSucc m => isFalse <| fun h => nomatch h
@[extern "lean_int_dec_le"]
instance decLe (a b : @& Int) : Decidable (a ≤ b) :=
decNonneg _
@[extern "lean_int_dec_lt"]
instance decLt (a b : @& Int) : Decidable (a < b) :=
decNonneg _
set_option bootstrap.genMatcherCode false in
@[extern "lean_nat_abs"]
def natAbs (m : @& Int) : Nat :=
match m with
| ofNat m => m
| negSucc m => m.succ
instance : OfNat Int n where
ofNat := Int.ofNat n
@[extern "lean_int_div"]
def div : (@& Int) → (@& Int) → Int
| ofNat m, ofNat n => ofNat (m / n)
| ofNat m, negSucc n => -ofNat (m / succ n)
| negSucc m, ofNat n => -ofNat (succ m / n)
| negSucc m, negSucc n => ofNat (succ m / succ n)
@[extern "lean_int_mod"]
def mod : (@& Int) → (@& Int) → Int
| ofNat m, ofNat n => ofNat (m % n)
| ofNat m, negSucc n => ofNat (m % succ n)
| negSucc m, ofNat n => -ofNat (succ m % n)
| negSucc m, negSucc n => -ofNat (succ m % succ n)
instance : Div Int where
div := Int.div
instance : Mod Int where
mod := Int.mod
def toNat : Int → Nat
| ofNat n => n
| negSucc n => 0
def natMod (m n : Int) : Nat := (m % n).toNat
protected def Int.pow (m : Int) : Nat → Int
| 0 => 1
| succ n => Int.pow m n * m
instance : HPow Int Nat Int where
hPow := Int.pow
end Int
|
f1be3a800d25d171ff2cd2ab8435408049b6d4e3
|
d9d511f37a523cd7659d6f573f990e2a0af93c6f
|
/archive/imo/imo2006_q3.lean
|
b9b2f0f3062c9f993f65184dc9413e61ddd0c81b
|
[
"Apache-2.0"
] |
permissive
|
hikari0108/mathlib
|
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
|
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
|
refs/heads/master
| 1,690,483,608,260
| 1,631,541,580,000
| 1,631,541,580,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,418
|
lean
|
/-
Copyright (c) 2021 Tian Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tian Chen
-/
import analysis.special_functions.sqrt
/-!
# IMO 2006 Q3
Determine the least real number $M$ such that
$$
\left| ab(a^2 - b^2) + bc(b^2 - c^2) + ca(c^2 - a^2) \right|
≤ M (a^2 + b^2 + c^2)^2
$$
for all real numbers $a$, $b$, $c$.
## Solution
The answer is $M = \frac{9 \sqrt 2}{32}$.
This is essentially a translation of the solution in
https://web.evanchen.cc/exams/IMO-2006-notes.pdf.
It involves making the substitution
`x = a - b`, `y = b - c`, `z = c - a`, `s = a + b + c`.
-/
open real
/-- Replacing `x` and `y` with their average increases the left side. -/
lemma lhs_ineq {x y : ℝ} (hxy : 0 ≤ x * y) :
16 * x ^ 2 * y ^ 2 * (x + y) ^ 2 ≤ ((x + y) ^ 2) ^ 3 :=
begin
conv_rhs { rw pow_succ' },
refine mul_le_mul_of_nonneg_right _ (sq_nonneg _),
apply le_of_sub_nonneg,
calc ((x + y) ^ 2) ^ 2 - 16 * x ^ 2 * y ^ 2
= (x - y) ^ 2 * ((x + y) ^ 2 + 4 * (x * y))
: by ring
... ≥ 0 : mul_nonneg (sq_nonneg _) $ add_nonneg (sq_nonneg _) $
mul_nonneg zero_lt_four.le hxy
end
lemma four_pow_four_pos : (0 : ℝ) < 4 ^ 4 := pow_pos zero_lt_four _
lemma mid_ineq {s t : ℝ} :
s * t ^ 3 ≤ (3 * t + s) ^ 4 / 4 ^ 4 :=
(le_div_iff four_pow_four_pos).mpr $ le_of_sub_nonneg $
calc (3 * t + s) ^ 4 - s * t ^ 3 * 4 ^ 4
= (s - t) ^ 2 * ((s + 7 * t) ^ 2 + 2 * (4 * t) ^ 2)
: by ring
... ≥ 0 : mul_nonneg (sq_nonneg _) $ add_nonneg (sq_nonneg _) $
mul_nonneg zero_le_two (sq_nonneg _)
/-- Replacing `x` and `y` with their average decreases the right side. -/
lemma rhs_ineq {x y : ℝ} :
3 * (x + y) ^ 2 ≤ 2 * (x ^ 2 + y ^ 2 + (x + y) ^ 2) :=
le_of_sub_nonneg $
calc _ = (x - y) ^ 2 : by ring
... ≥ 0 : sq_nonneg _
lemma zero_lt_32 : (0 : ℝ) < 32 := by norm_num
theorem subst_wlog {x y z s : ℝ} (hxy : 0 ≤ x * y) (hxyz : x + y + z = 0) :
32 * abs (x * y * z * s) ≤ sqrt 2 * (x^2 + y^2 + z^2 + s^2)^2 :=
have hz : (x + y)^2 = z^2 := neg_eq_of_add_eq_zero hxyz ▸ (neg_sq _).symm,
have hs : 0 ≤ 2 * s ^ 2 := mul_nonneg zero_le_two (sq_nonneg s),
have this : _ :=
calc (2 * s^2) * (16 * x^2 * y^2 * (x + y)^2)
≤ (3 * (x + y)^2 + 2 * s^2)^4 / 4^4 :
le_trans (mul_le_mul_of_nonneg_left (lhs_ineq hxy) hs) mid_ineq
... ≤ (2 * (x^2 + y^2 + (x + y)^2) + 2 * s^2)^4 / 4^4 :
div_le_div_of_le four_pow_four_pos.le $ pow_le_pow_of_le_left
(add_nonneg (mul_nonneg zero_lt_three.le (sq_nonneg _)) hs)
(add_le_add_right rhs_ineq _) _,
le_of_pow_le_pow _ (mul_nonneg (sqrt_nonneg _) (sq_nonneg _)) nat.succ_pos' $
calc (32 * abs (x * y * z * s)) ^ 2
= 32 * ((2 * s^2) * (16 * x^2 * y^2 * (x + y)^2)) :
by rw [mul_pow, sq_abs, hz]; ring
... ≤ 32 * ((2 * (x^2 + y^2 + (x + y)^2) + 2 * s^2)^4 / 4^4) :
mul_le_mul_of_nonneg_left this zero_lt_32.le
... = (sqrt 2 * (x^2 + y^2 + z^2 + s^2)^2)^2 :
by rw [← div_mul_eq_mul_div_comm, mul_pow, sq_sqrt zero_le_two,
hz, ← pow_mul, ← mul_add, mul_pow, ← mul_assoc];
exact congr (congr_arg _ $ by norm_num) rfl
/-- Proof that `M = 9 * sqrt 2 / 32` works with the substitution. -/
theorem subst_proof₁ (x y z s : ℝ) (hxyz : x + y + z = 0) :
abs (x * y * z * s) ≤ sqrt 2 / 32 * (x^2 + y^2 + z^2 + s^2)^2 :=
begin
wlog h' := mul_nonneg_of_three x y z using [x y z, y z x, z x y] tactic.skip,
{ rw [div_mul_eq_mul_div, le_div_iff' zero_lt_32],
exact subst_wlog h' hxyz },
{ intro h,
rw [add_assoc, add_comm] at h,
rw [mul_assoc x, mul_comm x, add_assoc (x^2), add_comm (x^2)],
exact this h },
{ intro h,
rw [add_comm, ← add_assoc] at h,
rw [mul_comm _ z, ← mul_assoc, add_comm _ (z^2), ← add_assoc],
exact this h }
end
lemma lhs_identity (a b c : ℝ) :
a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)
= (a - b) * (b - c) * (c - a) * -(a + b + c) :=
by ring
theorem proof₁ {a b c : ℝ} :
abs (a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)) ≤
9 * sqrt 2 / 32 * (a^2 + b^2 + c^2)^2 :=
calc _ = _ : congr_arg _ $ lhs_identity a b c
... ≤ _ : subst_proof₁ (a - b) (b - c) (c - a) (-(a + b + c)) (by ring)
... = _ : by ring
theorem proof₂ (M : ℝ)
(h : ∀ a b c : ℝ,
abs (a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)) ≤
M * (a^2 + b^2 + c^2)^2) :
9 * sqrt 2 / 32 ≤ M :=
begin
have h₁ : ∀ x : ℝ,
(2 - 3 * x - 2) * (2 - (2 + 3 * x)) * (2 + 3 * x - (2 - 3 * x)) *
-(2 - 3 * x + 2 + (2 + 3 * x)) = -(18 ^ 2 * x ^ 2 * x),
{ intro, ring },
have h₂ : ∀ x : ℝ, (2 - 3 * x) ^ 2 + 2 ^ 2 + (2 + 3 * x) ^ 2 = 18 * x ^ 2 + 12,
{ intro, ring },
have := h (2 - 3 * sqrt 2) 2 (2 + 3 * sqrt 2),
rw [lhs_identity, h₁, h₂, sq_sqrt zero_le_two,
abs_neg, abs_eq_self.mpr, ← div_le_iff] at this,
{ convert this using 1, ring },
{ apply pow_pos, norm_num },
{ exact mul_nonneg (mul_nonneg (sq_nonneg _) zero_le_two) (sqrt_nonneg _) }
end
theorem imo2006_q3 (M : ℝ) :
(∀ a b c : ℝ,
abs (a * b * (a^2 - b^2) + b * c * (b^2 - c^2) + c * a * (c^2 - a^2)) ≤
M * (a^2 + b^2 + c^2)^2) ↔
9 * sqrt 2 / 32 ≤ M :=
⟨proof₂ M, λ h _ _ _, le_trans proof₁ $ mul_le_mul_of_nonneg_right h $ sq_nonneg _⟩
|
66a0ee58a6e490a1f43e79b4cab0effe417ba705
|
07c6143268cfb72beccd1cc35735d424ebcb187b
|
/src/algebra/ring.lean
|
67b8f006bcf47327dcfcd677d361a6469d7d5110
|
[
"Apache-2.0"
] |
permissive
|
khoek/mathlib
|
bc49a842910af13a3c372748310e86467d1dc766
|
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
|
refs/heads/master
| 1,588,232,063,837
| 1,587,304,803,000
| 1,587,304,803,000
| 176,688,517
| 0
| 0
|
Apache-2.0
| 1,553,070,585,000
| 1,553,070,585,000
| null |
UTF-8
|
Lean
| false
| false
| 29,195
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston
-/
import algebra.group.with_one
import deprecated.group
import tactic.norm_cast
/-!
# Properties and homomorphisms of semirings and rings
This file proves simple properties of semirings, rings and domains and their unit groups. It also
defines homomorphisms of semirings and rings, both unbundled (e.g. `is_semiring_hom f`)
and bundled (e.g. `ring_hom a β`, a.k.a. `α →+* β`). The unbundled ones are deprecated
and the plan is to slowly remove them from mathlib.
## Main definitions
is_semiring_hom (deprecated), is_ring_hom (deprecated), ring_hom, nonzero_comm_semiring,
nonzero_comm_ring, domain
## Notations
→+* for bundled ring homs (also use for semiring homs)
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `semiring_hom` -- the idea is that `ring_hom` is used.
The constructor for a `ring_hom` between semirings needs a proof of `map_zero`, `map_one` and
`map_add` as well as `map_mul`; a separate constructor `ring_hom.mk'` will construct ring homs
between rings from monoid homs given only a proof that addition is preserved.
Throughout the section on `ring_hom` implicit `{}` brackets are often used instead of type class `[]` brackets.
This is done when the instances can be inferred because they are implicit arguments to the type `ring_hom`.
When they can be inferred from the type it is faster to use this method than to use type class inference.
## Tags
is_ring_hom, is_semiring_hom, ring_hom, semiring_hom, semiring, comm_semiring, ring, comm_ring,
domain, integral_domain, nonzero_comm_semiring, nonzero_comm_ring, units
-/
universes u v w
variable {α : Type u}
section
variable [semiring α]
theorem mul_two (n : α) : n * 2 = n + n :=
(left_distrib n 1 1).trans (by simp)
theorem bit0_eq_two_mul (n : α) : bit0 n = 2 * n :=
(two_mul _).symm
@[to_additive] lemma mul_ite {α} [has_mul α] (P : Prop) [decidable P] (a b c : α) :
a * (if P then b else c) = if P then a * b else a * c :=
by split_ifs; refl
@[to_additive] lemma ite_mul {α} [has_mul α] (P : Prop) [decidable P] (a b c : α) :
(if P then a else b) * c = if P then a * c else b * c :=
by split_ifs; refl
-- We make `mul_ite` and `ite_mul` simp lemmas,
-- but not `add_ite` or `ite_add`.
-- The problem we're trying to avoid is dealing with
-- summations of the form `s.sum (λ x, f x + ite P 1 0)`,
-- in which `add_ite` followed by `sum_ite` would needlessly slice up
-- the `f x` terms according to whether `P` holds at `x`.
-- There doesn't appear to be a corresponding difficulty so far with
-- `mul_ite` and `ite_mul`.
attribute [simp] mul_ite ite_mul
@[simp] lemma mul_boole {α} [semiring α] (P : Prop) [decidable P] (a : α) :
a * (if P then 1 else 0) = if P then a else 0 :=
by simp
@[simp] lemma boole_mul {α} [semiring α] (P : Prop) [decidable P] (a : α) :
(if P then 1 else 0) * a = if P then a else 0 :=
by simp
variable (α)
/-- Either zero and one are nonequal in a semiring, or the semiring is the zero ring. -/
lemma zero_ne_one_or_forall_eq_0 : (0 : α) ≠ 1 ∨ (∀a:α, a = 0) :=
by haveI := classical.dec;
refine not_or_of_imp (λ h a, _); simpa using congr_arg ((*) a) h.symm
/-- If zero equals one in a semiring, the semiring is the zero ring. -/
lemma eq_zero_of_zero_eq_one (h : (0 : α) = 1) : (∀a:α, a = 0) :=
(zero_ne_one_or_forall_eq_0 α).neg_resolve_left h
/-- If zero equals one in a semiring, all elements of that semiring are equal. -/
theorem subsingleton_of_zero_eq_one (h : (0 : α) = 1) : subsingleton α :=
⟨λa b, by rw [eq_zero_of_zero_eq_one α h a, eq_zero_of_zero_eq_one α h b]⟩
end
namespace units
variables [ring α] {a b : α}
/-- Each element of the group of units of a ring has an additive inverse. -/
instance : has_neg (units α) := ⟨λu, ⟨-↑u, -↑u⁻¹, by simp, by simp⟩ ⟩
/-- Representing an element of a ring's unit group as an element of the ring commutes with
mapping this element to its additive inverse. -/
@[simp] protected theorem coe_neg (u : units α) : (↑-u : α) = -u := rfl
/-- Mapping an element of a ring's unit group to its inverse commutes with mapping this element
to its additive inverse. -/
@[simp] protected theorem neg_inv (u : units α) : (-u)⁻¹ = -u⁻¹ := rfl
/-- An element of a ring's unit group equals the additive inverse of its additive inverse. -/
@[simp] protected theorem neg_neg (u : units α) : - -u = u :=
units.ext $ neg_neg _
/-- Multiplication of elements of a ring's unit group commutes with mapping the first
argument to its additive inverse. -/
@[simp] protected theorem neg_mul (u₁ u₂ : units α) : -u₁ * u₂ = -(u₁ * u₂) :=
units.ext $ neg_mul_eq_neg_mul_symm _ _
/-- Multiplication of elements of a ring's unit group commutes with mapping the second argument
to its additive inverse. -/
@[simp] protected theorem mul_neg (u₁ u₂ : units α) : u₁ * -u₂ = -(u₁ * u₂) :=
units.ext $ (neg_mul_eq_mul_neg _ _).symm
/-- Multiplication of the additive inverses of two elements of a ring's unit group equals
multiplication of the two original elements. -/
@[simp] protected theorem neg_mul_neg (u₁ u₂ : units α) : -u₁ * -u₂ = u₁ * u₂ := by simp
/-- The additive inverse of an element of a ring's unit group equals the additive inverse of
one times the original element. -/
protected theorem neg_eq_neg_one_mul (u : units α) : -u = -1 * u := by simp
end units
instance [semiring α] : semiring (with_zero α) :=
{ left_distrib := λ a b c, begin
cases a with a, {refl},
cases b with b; cases c with c; try {refl},
exact congr_arg some (left_distrib _ _ _)
end,
right_distrib := λ a b c, begin
cases c with c,
{ change (a + b) * 0 = a * 0 + b * 0, simp },
cases a with a; cases b with b; try {refl},
exact congr_arg some (right_distrib _ _ _)
end,
..with_zero.add_comm_monoid,
..with_zero.mul_zero_class,
..with_zero.monoid }
attribute [refl] dvd_refl
attribute [trans] dvd.trans
/-- Predicate for semiring homomorphisms (deprecated -- use the bundled `ring_hom` version). -/
class is_semiring_hom {α : Type u} {β : Type v} [semiring α] [semiring β] (f : α → β) : Prop :=
(map_zero [] : f 0 = 0)
(map_one [] : f 1 = 1)
(map_add [] : ∀ {x y}, f (x + y) = f x + f y)
(map_mul [] : ∀ {x y}, f (x * y) = f x * f y)
namespace is_semiring_hom
variables {β : Type v} [semiring α] [semiring β]
variables (f : α → β) [is_semiring_hom f] {x y : α}
/-- The identity map is a semiring homomorphism. -/
instance id : is_semiring_hom (@id α) := by refine {..}; intros; refl
/-- The composition of two semiring homomorphisms is a semiring homomorphism. -/
-- see Note [no instance on morphisms]
lemma comp {γ} [semiring γ] (g : β → γ) [is_semiring_hom g] :
is_semiring_hom (g ∘ f) :=
{ map_zero := by simp [map_zero f]; exact map_zero g,
map_one := by simp [map_one f]; exact map_one g,
map_add := λ x y, by simp [map_add f]; rw map_add g; refl,
map_mul := λ x y, by simp [map_mul f]; rw map_mul g; refl }
/-- A semiring homomorphism is an additive monoid homomorphism. -/
@[priority 100] -- see Note [lower instance priority]
instance : is_add_monoid_hom f :=
{ ..‹is_semiring_hom f› }
/-- A semiring homomorphism is a monoid homomorphism. -/
@[priority 100] -- see Note [lower instance priority]
instance : is_monoid_hom f :=
{ ..‹is_semiring_hom f› }
end is_semiring_hom
section
variables [ring α] (a b c d e : α)
/-- An element of a ring multiplied by the additive inverse of one is the element's additive
inverse. -/
lemma mul_neg_one (a : α) : a * -1 = -a := by simp
/-- The additive inverse of one multiplied by an element of a ring is the element's additive
inverse. -/
lemma neg_one_mul (a : α) : -1 * a = -a := by simp
/-- An iff statement following from right distributivity in rings and the definition
of subtraction. -/
theorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d ↔ (a - b) * e + c = d :=
calc
a * e + c = b * e + d ↔ a * e + c = d + b * e : by simp [add_comm]
... ↔ a * e + c - b * e = d : iff.intro (λ h, begin rw h, simp end) (λ h,
begin rw ← h, simp end)
... ↔ (a - b) * e + c = d : begin simp [sub_mul, sub_add_eq_add_sub] end
/-- A simplification of one side of an equation exploiting right distributivity in rings
and the definition of subtraction. -/
theorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d → (a - b) * e + c = d :=
assume h,
calc
(a - b) * e + c = (a * e + c) - b * e : begin simp [sub_mul, sub_add_eq_add_sub] end
... = d : begin rw h, simp [@add_sub_cancel α] end
/-- If the product of two elements of a ring is nonzero, both elements are nonzero. -/
theorem ne_zero_and_ne_zero_of_mul_ne_zero {a b : α} (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 :=
begin
split,
{ intro ha, apply h, simp [ha] },
{ intro hb, apply h, simp [hb] }
end
end
/-- Given an element a of a commutative semiring, there exists another element whose product
with zero equals a iff a equals zero. -/
@[simp] lemma zero_dvd_iff [comm_semiring α] {a : α} : 0 ∣ a ↔ a = 0 :=
⟨eq_zero_of_zero_dvd, λ h, by rw h⟩
section comm_ring
variable [comm_ring α]
/-- Representation of a difference of two squares in a commutative ring as a product. -/
theorem mul_self_sub_mul_self (a b : α) : a * a - b * b = (a + b) * (a - b) :=
by rw [add_mul, mul_sub, mul_sub, mul_comm a b, sub_add_sub_cancel]
/-- An element a of a commutative ring divides the additive inverse of an element b iff a
divides b. -/
@[simp] lemma dvd_neg (a b : α) : (a ∣ -b) ↔ (a ∣ b) :=
⟨dvd_of_dvd_neg, dvd_neg_of_dvd⟩
/-- The additive inverse of an element a of a commutative ring divides another element b iff a
divides b. -/
@[simp] lemma neg_dvd (a b : α) : (-a ∣ b) ↔ (a ∣ b) :=
⟨dvd_of_neg_dvd, neg_dvd_of_dvd⟩
/-- If an element a divides another element c in a commutative ring, a divides the sum of another
element b with c iff a divides b. -/
theorem dvd_add_left {a b c : α} (h : a ∣ c) : a ∣ b + c ↔ a ∣ b :=
(dvd_add_iff_left h).symm
/-- If an element a divides another element b in a commutative ring, a divides the sum of b and
another element c iff a divides c. -/
theorem dvd_add_right {a b c : α} (h : a ∣ b) : a ∣ b + c ↔ a ∣ c :=
(dvd_add_iff_right h).symm
/-- An element a divides the sum a + b if and only if a divides b.-/
@[simp] lemma dvd_add_self_left {a b : α} :
a ∣ a + b ↔ a ∣ b :=
dvd_add_right (dvd_refl a)
/-- An element a divides the sum b + a if and only if a divides b.-/
@[simp] lemma dvd_add_self_right {a b : α} :
a ∣ b + a ↔ a ∣ b :=
dvd_add_left (dvd_refl a)
/-- Vieta's formula for a quadratic equation, relating the coefficients of the polynomial with
its roots. This particular version states that if we have a root `x` of a monic quadratic
polynomial, then there is another root `y` such that `x + y` is negative the `a_1` coefficient
and `x * y` is the `a_0` coefficient. -/
lemma Vieta_formula_quadratic {b c x : α} (h : x * x - b * x + c = 0) :
∃ y : α, y * y - b * y + c = 0 ∧ x + y = b ∧ x * y = c :=
begin
have : c = -(x * x - b * x) := (neg_eq_of_add_eq_zero h).symm,
have : c = x * (b - x), by subst this; simp [mul_sub, mul_comm],
refine ⟨b - x, _, by simp, by rw this⟩,
rw [this, sub_add, ← sub_mul, sub_self]
end
end comm_ring
/-- Predicate for ring homomorphisms (deprecated -- use the bundled `ring_hom` version). -/
class is_ring_hom {α : Type u} {β : Type v} [ring α] [ring β] (f : α → β) : Prop :=
(map_one [] : f 1 = 1)
(map_mul [] : ∀ {x y}, f (x * y) = f x * f y)
(map_add [] : ∀ {x y}, f (x + y) = f x + f y)
namespace is_ring_hom
variables {β : Type v} [ring α] [ring β]
/-- A map of rings that is a semiring homomorphism is also a ring homomorphism. -/
lemma of_semiring (f : α → β) [H : is_semiring_hom f] : is_ring_hom f := {..H}
variables (f : α → β) [is_ring_hom f] {x y : α}
/-- Ring homomorphisms map zero to zero. -/
lemma map_zero : f 0 = 0 :=
calc f 0 = f (0 + 0) - f 0 : by rw [map_add f]; simp
... = 0 : by simp
/-- Ring homomorphisms preserve additive inverses. -/
lemma map_neg : f (-x) = -f x :=
calc f (-x) = f (-x + x) - f x : by rw [map_add f]; simp
... = -f x : by simp [map_zero f]
/-- Ring homomorphisms preserve subtraction. -/
lemma map_sub : f (x - y) = f x - f y :=
by simp [sub_eq_add_neg, map_add f, map_neg f]
/-- The identity map is a ring homomorphism. -/
instance id : is_ring_hom (@id α) := by refine {..}; intros; refl
/-- The composition of two ring homomorphisms is a ring homomorphism. -/
-- see Note [no instance on morphisms]
lemma comp {γ} [ring γ] (g : β → γ) [is_ring_hom g] :
is_ring_hom (g ∘ f) :=
{ map_add := λ x y, by simp [map_add f]; rw map_add g; refl,
map_mul := λ x y, by simp [map_mul f]; rw map_mul g; refl,
map_one := by simp [map_one f]; exact map_one g }
/-- A ring homomorphism is also a semiring homomorphism. -/
@[priority 100] -- see Note [lower instance priority]
instance : is_semiring_hom f :=
{ map_zero := map_zero f, ..‹is_ring_hom f› }
@[priority 100] -- see Note [lower instance priority]
instance : is_add_group_hom f := { }
end is_ring_hom
set_option old_structure_cmd true
section prio
set_option default_priority 100 -- see Note [default priority]
/-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too. -/
structure ring_hom (α : Type*) (β : Type*) [semiring α] [semiring β]
extends monoid_hom α β, add_monoid_hom α β
end prio
infixr ` →+* `:25 := ring_hom
instance {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} : has_coe_to_fun (α →+* β) :=
⟨_, ring_hom.to_fun⟩
instance {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} : has_coe (α →+* β) (α →* β) :=
⟨ring_hom.to_monoid_hom⟩
instance {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} : has_coe (α →+* β) (α →+ β) :=
⟨ring_hom.to_add_monoid_hom⟩
lemma coe_monoid_hom {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} (f : α →+* β) (a : α) :
((f : α →* β) : α → β) a = (f : α → β) a := rfl
lemma coe_add_monoid_hom {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} (f : α →+* β) (a : α) :
((f : α →+ β) : α → β) a = (f : α → β) a := rfl
@[norm_cast] lemma coe_monoid_hom' {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} (f : α →+* β) :
((f : α →* β) : α → β) = (f : α → β) := by { apply funext, intro, apply coe_monoid_hom }
@[norm_cast] lemma coe_add_monoid_hom' {α : Type*} {β : Type*} {rα : semiring α} {rβ : semiring β} (f : α →+* β) :
((f : α →+ β) : α → β) = (f : α → β) := by { apply funext, intro, apply coe_add_monoid_hom }
namespace ring_hom
variables {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β]
include rα rβ
/-- Interpret `f : α → β` with `is_semiring_hom f` as a ring homomorphism. -/
def of (f : α → β) [is_semiring_hom f] : α →+* β :=
{ to_fun := f,
.. monoid_hom.of f,
.. add_monoid_hom.of f }
@[simp] lemma coe_of (f : α → β) [is_semiring_hom f] : ⇑(of f) = f := rfl
@[simp] lemma coe_mk (f : α → β) (h₁ h₂ h₃ h₄) : ⇑(⟨f, h₁, h₂, h₃, h₄⟩ : α →+* β) = f := rfl
variables (f : α →+* β) {x y : α} {rα rβ}
theorem coe_inj ⦃f g : α →+* β⦄ (h : (f : α → β) = g) : f = g :=
by cases f; cases g; cases h; refl
@[ext] theorem ext ⦃f g : α →+* β⦄ (h : ∀ x, f x = g x) : f = g :=
coe_inj (funext h)
theorem ext_iff {f g : α →+* β} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, λ h, ext h⟩
/-- Ring homomorphisms map zero to zero. -/
@[simp] lemma map_zero (f : α →+* β) : f 0 = 0 := f.map_zero'
/-- Ring homomorphisms map one to one. -/
@[simp] lemma map_one (f : α →+* β) : f 1 = 1 := f.map_one'
/-- Ring homomorphisms preserve addition. -/
@[simp] lemma map_add (f : α →+* β) (a b : α) : f (a + b) = f a + f b := f.map_add' a b
/-- Ring homomorphisms preserve multiplication. -/
@[simp] lemma map_mul (f : α →+* β) (a b : α) : f (a * b) = f a * f b := f.map_mul' a b
instance (f : α →+* β) : is_semiring_hom f :=
{ map_zero := f.map_zero,
map_one := f.map_one,
map_add := f.map_add,
map_mul := f.map_mul }
omit rα rβ
instance {α γ} [ring α] [ring γ] (g : α →+* γ) : is_ring_hom g :=
is_ring_hom.of_semiring g
/-- The identity ring homomorphism from a semiring to itself. -/
def id (α : Type*) [semiring α] : α →+* α :=
by refine {to_fun := id, ..}; intros; refl
include rα
@[simp] lemma id_apply : ring_hom.id α x = x := rfl
variable {rγ : semiring γ}
include rβ rγ
/-- Composition of ring homomorphisms is a ring homomorphism. -/
def comp (hnp : β →+* γ) (hmn : α →+* β) : α →+* γ :=
{ to_fun := hnp ∘ hmn,
map_zero' := by simp,
map_one' := by simp,
map_add' := λ x y, by simp,
map_mul' := λ x y, by simp}
/-- Composition of semiring homomorphisms is associative. -/
lemma comp_assoc {δ} {rδ: semiring δ} (f : α →+* β) (g : β →+* γ) (h : γ →+* δ) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[simp] lemma coe_comp (hnp : β →+* γ) (hmn : α →+* β) : (hnp.comp hmn : α → γ) = hnp ∘ hmn := rfl
lemma comp_apply (hnp : β →+* γ) (hmn : α →+* β) (x : α) : (hnp.comp hmn : α → γ) x =
(hnp (hmn x)) := rfl
lemma cancel_right {g₁ g₂ : β →+* γ} {f : α →+* β} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, ring_hom.ext $ (forall_iff_forall_surj hf).1 (ext_iff.1 h), λ h, h ▸ rfl⟩
lemma cancel_left {g : β →+* γ} {f₁ f₂ : α →+* β} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, ring_hom.ext $ λ x, hg $ by rw [← comp_apply, h, comp_apply], λ h, h ▸ rfl⟩
omit rα rβ rγ
/-- Ring homomorphisms preserve additive inverse. -/
@[simp] theorem map_neg {α β} [ring α] [ring β] (f : α →+* β) (x : α) : f (-x) = -(f x) :=
eq_neg_of_add_eq_zero $ by rw [←f.map_add, neg_add_self, f.map_zero]
/-- Ring homomorphisms preserve subtraction. -/
@[simp] theorem map_sub {α β} [ring α] [ring β] (f : α →+* β) (x y : α) :
f (x - y) = (f x) - (f y) := by simp [sub_eq_add_neg]
/-- A ring homomorphism is injective iff its kernel is trivial. -/
theorem injective_iff {α β} [ring α] [ring β] (f : α →+* β) :
function.injective f ↔ (∀ a, f a = 0 → a = 0) :=
add_monoid_hom.injective_iff f.to_add_monoid_hom
include rα
/-- Makes a ring homomorphism from a monoid homomorphism of rings which preserves addition. -/
def mk' {γ} [ring γ] (f : α →* γ) (map_add : ∀ a b : α, f (a + b) = f a + f b) : α →+* γ :=
{ to_fun := f,
map_zero' := add_self_iff_eq_zero.1 $ by rw [←map_add, add_zero],
map_one' := f.map_one,
map_mul' := f.map_mul,
map_add' := map_add }
end ring_hom
section prio
set_option default_priority 100 -- see Note [default priority]
/-- Predicate for commutative semirings in which zero does not equal one. -/
class nonzero_comm_semiring (α : Type*) extends comm_semiring α, zero_ne_one_class α
/-- Predicate for commutative rings in which zero does not equal one. -/
class nonzero_comm_ring (α : Type*) extends comm_ring α, zero_ne_one_class α
end prio
-- This could be generalized, for example if we added `nonzero_ring` into the hierarchy,
-- but it doesn't seem worth doing just for these lemmas.
lemma succ_ne_self [nonzero_comm_ring α] (a : α) : a + 1 ≠ a :=
λ h, one_ne_zero ((add_left_inj a).mp (by simp [h]))
-- As with succ_ne_self.
lemma pred_ne_self [nonzero_comm_ring α] (a : α) : a - 1 ≠ a :=
λ h, one_ne_zero (neg_inj ((add_left_inj a).mp (by { convert h, simp })))
/-- A nonzero commutative ring is a nonzero commutative semiring. -/
@[priority 100] -- see Note [lower instance priority]
instance nonzero_comm_ring.to_nonzero_comm_semiring {α : Type*} [I : nonzero_comm_ring α] :
nonzero_comm_semiring α :=
{ zero_ne_one := by convert zero_ne_one,
..show comm_semiring α, by apply_instance }
/-- An integral domain is a nonzero commutative ring. -/
@[priority 100] -- see Note [lower instance priority]
instance integral_domain.to_nonzero_comm_ring (α : Type*) [id : integral_domain α] :
nonzero_comm_ring α :=
{ ..id }
/-- An element of the unit group of a nonzero commutative semiring represented as an element
of the semiring is nonzero. -/
lemma units.coe_ne_zero [nonzero_comm_semiring α] (u : units α) : (u : α) ≠ 0 :=
λ h : u.1 = 0, by simpa [h, zero_ne_one] using u.3
/-- Makes a nonzero commutative ring from a commutative ring containing at least two distinct
elements. -/
def nonzero_comm_ring.of_ne [comm_ring α] {x y : α} (h : x ≠ y) : nonzero_comm_ring α :=
{ one := 1,
zero := 0,
zero_ne_one := λ h01, h $ by rw [← one_mul x, ← one_mul y, ← h01, zero_mul, zero_mul],
..show comm_ring α, by apply_instance }
/-- Makes a nonzero commutative semiring from a commutative semiring containing at least two
distinct elements. -/
def nonzero_comm_semiring.of_ne [comm_semiring α] {x y : α} (h : x ≠ y) : nonzero_comm_semiring α :=
{ one := 1,
zero := 0,
zero_ne_one := λ h01, h $ by rw [← one_mul x, ← one_mul y, ← h01, zero_mul, zero_mul],
..show comm_semiring α, by apply_instance }
/-- this is needed for compatibility between Lean 3.4.2 and Lean 3.5.1c -/
def has_div_of_division_ring [division_ring α] : has_div α := division_ring_has_div
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A domain is a ring with no zero divisors, i.e. satisfying
the condition `a * b = 0 ↔ a = 0 ∨ b = 0`. Alternatively, a domain
is an integral domain without assuming commutativity of multiplication. -/
class domain (α : Type u) extends ring α, no_zero_divisors α, zero_ne_one_class α
end prio
section domain
variable [domain α]
/-- Simplification theorems for the definition of a domain. -/
@[simp] theorem mul_eq_zero {a b : α} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
⟨eq_zero_or_eq_zero_of_mul_eq_zero, λo,
or.elim o (λh, by rw h; apply zero_mul) (λh, by rw h; apply mul_zero)⟩
@[simp] theorem zero_eq_mul {a b : α} : 0 = a * b ↔ a = 0 ∨ b = 0 :=
by rw [eq_comm, mul_eq_zero]
lemma mul_self_eq_zero {α} [domain α] {x : α} : x * x = 0 ↔ x = 0 := by simp
lemma zero_eq_mul_self {α} [domain α] {x : α} : 0 = x * x ↔ x = 0 := by simp
/-- The product of two nonzero elements of a domain is nonzero. -/
theorem mul_ne_zero' {a b : α} (h₁ : a ≠ 0) (h₂ : b ≠ 0) : a * b ≠ 0 :=
λ h, or.elim (eq_zero_or_eq_zero_of_mul_eq_zero h) h₁ h₂
/-- Right multiplication by a nonzero element in a domain is injective. -/
theorem domain.mul_right_inj {a b c : α} (ha : a ≠ 0) : b * a = c * a ↔ b = c :=
by rw [← sub_eq_zero, ← mul_sub_right_distrib, mul_eq_zero];
simp [ha]; exact sub_eq_zero
/-- Left multiplication by a nonzero element in a domain is injective. -/
theorem domain.mul_left_inj {a b c : α} (ha : a ≠ 0) : a * b = a * c ↔ b = c :=
by rw [← sub_eq_zero, ← mul_sub_left_distrib, mul_eq_zero];
simp [ha]; exact sub_eq_zero
/-- An element of a domain fixed by right multiplication by an element other than one must
be zero. -/
theorem eq_zero_of_mul_eq_self_right' {a b : α} (h₁ : b ≠ 1) (h₂ : a * b = a) : a = 0 :=
by apply (mul_eq_zero.1 _).resolve_right (sub_ne_zero.2 h₁);
rw [mul_sub_left_distrib, mul_one, sub_eq_zero, h₂]
/-- An element of a domain fixed by left multiplication by an element other than one must
be zero. -/
theorem eq_zero_of_mul_eq_self_left' {a b : α} (h₁ : b ≠ 1) (h₂ : b * a = a) : a = 0 :=
by apply (mul_eq_zero.1 _).resolve_left (sub_ne_zero.2 h₁);
rw [mul_sub_right_distrib, one_mul, sub_eq_zero, h₂]
/-- For elements a, b of a domain, if a*b is nonzero, so is b*a. -/
theorem mul_ne_zero_comm' {a b : α} (h : a * b ≠ 0) : b * a ≠ 0 :=
mul_ne_zero' (ne_zero_of_mul_ne_zero_left h) (ne_zero_of_mul_ne_zero_right h)
end domain
/- integral domains -/
section
variables [s : integral_domain α] (a b c d e : α)
include s
/-- An integral domain is a domain. -/
@[priority 100] -- see Note [lower instance priority]
instance integral_domain.to_domain : domain α := {..s, ..(by apply_instance : semiring α)}
/-- Right multiplcation by a nonzero element of an integral domain is injective. -/
theorem eq_of_mul_eq_mul_right_of_ne_zero {a b c : α} (ha : a ≠ 0) (h : b * a = c * a) : b = c :=
have b * a - c * a = 0, by simp [h],
have (b - c) * a = 0, by rw [mul_sub_right_distrib, this],
have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right ha,
eq_of_sub_eq_zero this
/-- Left multiplication by a nonzero element of an integral domain is injective. -/
theorem eq_of_mul_eq_mul_left_of_ne_zero {a b c : α} (ha : a ≠ 0) (h : a * b = a * c) : b = c :=
have a * b - a * c = 0, by simp [h],
have a * (b - c) = 0, by rw [mul_sub_left_distrib, this],
have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_left ha,
eq_of_sub_eq_zero this
/-- Given two elements b, c of an integral domain and a nonzero element a, a*b divides a*c iff
b divides c. -/
theorem mul_dvd_mul_iff_left {a b c : α} (ha : a ≠ 0) : a * b ∣ a * c ↔ b ∣ c :=
exists_congr $ λ d, by rw [mul_assoc, domain.mul_left_inj ha]
/-- Given two elements a, b of an integral domain and a nonzero element c, a*c divides b*c iff
a divides b. -/
theorem mul_dvd_mul_iff_right {a b c : α} (hc : c ≠ 0) : a * c ∣ b * c ↔ a ∣ b :=
exists_congr $ λ d, by rw [mul_right_comm, domain.mul_right_inj hc]
/-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or
one's additive inverse. -/
lemma units.inv_eq_self_iff (u : units α) : u⁻¹ = u ↔ u = 1 ∨ u = -1 :=
by conv {to_lhs, rw [inv_eq_iff_mul_eq_one, ← mul_one (1 : units α), units.ext_iff, units.coe_mul,
units.coe_mul, mul_self_eq_mul_self_iff, ← units.ext_iff, ← units.coe_neg, ← units.ext_iff] }
end
/- units in various rings -/
namespace units
section comm_semiring
variables [comm_semiring α] (a b : α) (u : units α)
/-- Elements of the unit group of a commutative semiring represented as elements of the semiring
divide any element of the semiring. -/
@[simp] lemma coe_dvd : ↑u ∣ a := ⟨↑u⁻¹ * a, by simp⟩
/-- In a commutative semiring, an element a divides an element b iff a divides all
associates of b. -/
@[simp] lemma dvd_coe_mul : a ∣ b * u ↔ a ∣ b :=
iff.intro
(assume ⟨c, eq⟩, ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← eq, units.mul_inv_cancel_right]⟩)
(assume ⟨c, eq⟩, eq.symm ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _)
/-- An element of a commutative semiring divides a unit iff the element divides one. -/
@[simp] lemma dvd_coe : a ∣ ↑u ↔ a ∣ 1 :=
suffices a ∣ 1 * ↑u ↔ a ∣ 1, by simpa,
dvd_coe_mul _ _ _
/-- In a commutative semiring, an element a divides an element b iff all associates of a divide b.-/
@[simp] lemma coe_mul_dvd : a * u ∣ b ↔ a ∣ b :=
iff.intro
(assume ⟨c, eq⟩, ⟨c * ↑u, eq.symm ▸ by ac_refl⟩)
(assume h, suffices a * ↑u ∣ b * 1, by simpa, mul_dvd_mul h (coe_dvd _ _))
end comm_semiring
section domain
variables [domain α]
/-- Every unit in a domain is nonzero. -/
@[simp] theorem ne_zero : ∀(u : units α), (↑u : α) ≠ 0
| ⟨u, v, (huv : 0 * v = 1), hvu⟩ rfl := by simpa using huv
end domain
end units
/-- A predicate to express that a ring is an integral domain.
This is mainly useful because such a predicate does not contain data,
and can therefore be easily transported along ring isomorphisms. -/
structure is_integral_domain (R : Type u) [ring R] : Prop :=
(mul_comm : ∀ (x y : R), x * y = y * x)
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ x y : R, x * y = 0 → x = 0 ∨ y = 0)
(zero_ne_one : (0 : R) ≠ 1)
/-- Every integral domain satisfies the predicate for integral domains. -/
lemma integral_domain.to_is_integral_domain (R : Type u) [integral_domain R] :
is_integral_domain R :=
{ .. (‹_› : integral_domain R) }
/-- If a ring satisfies the predicate for integral domains,
then it can be endowed with an `integral_domain` instance
whose data is definitionally equal to the existing data. -/
def is_integral_domain.to_integral_domain (R : Type u) [ring R] (h : is_integral_domain R) :
integral_domain R :=
{ .. (‹_› : ring R), .. (‹_› : is_integral_domain R) }
|
9108d0052d0156978e5dfca46fabb12e9ab413ac
|
df7bb3acd9623e489e95e85d0bc55590ab0bc393
|
/lean/love02_backward_proofs_exercise_solution.lean
|
f5e1bb25bbdbcda680078a0a4afc59429fdf75eb
|
[] |
no_license
|
MaschavanderMarel/logical_verification_2020
|
a41c210b9237c56cb35f6cd399e3ac2fe42e775d
|
7d562ef174cc6578ca6013f74db336480470b708
|
refs/heads/master
| 1,692,144,223,196
| 1,634,661,675,000
| 1,634,661,675,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,082
|
lean
|
import .love02_backward_proofs_demo
/- # LoVe Exercise 2: Backward Proofs -/
set_option pp.beta true
set_option pp.generalized_field_notation false
namespace LoVe
namespace backward_proofs
/- ## Question 1: Connectives and Quantifiers
1.1. Carry out the following proofs using basic tactics.
Hint: Some strategies for carrying out such proofs are described at the end of
Section 2.3 in the Hitchhiker's Guide. -/
lemma I (a : Prop) :
a → a :=
begin
intro ha,
exact ha
end
lemma K (a b : Prop) :
a → b → b :=
begin
intros ha hb,
exact hb
end
lemma C (a b c : Prop) :
(a → b → c) → b → a → c :=
begin
intros hg hb ha,
apply hg,
exact ha,
exact hb
end
lemma proj_1st (a : Prop) :
a → a → a :=
begin
intros ha ha',
exact ha
end
/- Please give a different answer than for `proj_1st`: -/
lemma proj_2nd (a : Prop) :
a → a → a :=
begin
intros ha ha',
exact ha'
end
lemma some_nonsense (a b c : Prop) :
(a → b → c) → a → (a → c) → b → c :=
begin
intros hg ha hf hb,
apply hg,
exact ha,
exact hb
end
/- 1.2. Prove the contraposition rule using basic tactics. -/
lemma contrapositive (a b : Prop) :
(a → b) → ¬ b → ¬ a :=
begin
intros hab hnb ha,
apply hnb,
apply hab,
apply ha
end
/- 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.
Hint: This exercise is tricky, especially the right-to-left direction. Some
forward reasoning, like in the proof of `and_swap₂` in the lecture, might be
necessary. -/
lemma forall_and {α : Type} (p q : α → Prop) :
(∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=
begin
apply iff.intro,
{ intro h,
apply and.intro,
{ intro x,
apply and.elim_left,
apply h },
{ intro x,
apply and.elim_right,
apply h } },
{ intros h x,
apply and.intro,
{ apply and.elim_left h },
{ apply and.elim_right h } }
end
/- ## Question 2: Natural Numbers
2.1. Prove the following recursive equations on the first argument of the
`mul` operator defined in lecture 1. -/
set_option trace.simplify.rewrite true
#check mul
lemma mul_zero (n : ℕ) :
mul 0 n = 0 :=
begin
induction' n,
{ refl },
{ simp [add, mul, ih] }
end
lemma mul_zero' (n : ℕ) :
mul 0 n = 0 :=
begin
induction' n,
{ refl },
{ rewrite mul,
rewrite ih,
rewrite add }
end
lemma mul_succ (m n : ℕ) :
mul (nat.succ m) n = add (mul m n) n :=
begin
induction' n,
{ refl },
{ simp [add, add_succ, add_assoc, mul, ih] }
end
lemma mul_succ' (m n : ℕ) :
mul (nat.succ m) n = add (mul m n) n :=
begin
induction' n,
{ refl },
{ rewrite mul,
rewrite ih,
rewrite add_succ,
rewrite mul,
rewrite add_assoc,
rewrite add,
rewrite add }
end
/- 2.2. Prove commutativity and associativity of multiplication using the
`induction'` tactic. Choose the induction variable carefully. -/
lemma mul_comm (m n : ℕ) :
mul m n = mul n m :=
begin
induction' m,
{ simp [mul, mul_zero] },
{ simp [mul, mul_succ, ih],
cc }
end
lemma mul_assoc (l m n : ℕ) :
mul (mul l m) n = mul l (mul m n) :=
begin
induction' n,
{ refl },
{ simp [mul, mul_add, ih] }
end
/- 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply
commutativity at a specific position, instantiate the rule by passing some
arguments (e.g., `mul_comm _ l`). -/
lemma add_mul (l m n : ℕ) :
mul (add l m) n = add (mul n l) (mul n m) :=
begin
rw mul_comm _ n,
rw mul_add
end
/- ## Question 3 (**optional**): Intuitionistic Logic
Intuitionistic logic is extended to classical logic by assuming a classical
axiom. There are several possibilities for the choice of axiom. In this
question, we are concerned with the logical equivalence of three different
axioms: -/
def excluded_middle :=
∀a : Prop, a ∨ ¬ a
def peirce :=
∀a b : Prop, ((a → b) → a) → a
def double_negation :=
∀a : Prop, (¬¬ a) → a
/- For the proofs below, please avoid using lemmas from Lean's `classical`
namespace, because this would defeat the purpose of the exercise.
3.1 (**optional**). Prove the following implication using tactics.
Hint: You will need `or.elim` and `false.elim`. You can use
`rw excluded_middle` to unfold the definition of `excluded_middle`,
and similarly for `peirce`. -/
lemma peirce_of_em :
excluded_middle → peirce :=
begin
rw excluded_middle,
rw peirce,
intro hem,
intros a b haba,
apply or.elim (hem a),
{ intro,
assumption },
{ intro hna,
apply haba,
intro ha,
apply false.elim,
apply hna,
assumption }
end
/- 3.2 (**optional**). Prove the following implication using tactics. -/
lemma dn_of_peirce :
peirce → double_negation :=
begin
rw peirce,
rw double_negation,
intros hpeirce a hnna,
apply hpeirce a false,
intro hna,
apply false.elim,
apply hnna,
exact hna
end
/- We leave the missing implication for the homework: -/
namespace sorry_lemmas
lemma em_of_dn :
double_negation → excluded_middle :=
sorry
end sorry_lemmas
end backward_proofs
end LoVe
|
b2b3e6e34a652a28c92f6d45beff5d25c6b54717
|
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
|
/stage0/src/Lean/Data/Lsp/Basic.lean
|
c18758738561caf50933d1e55cfab98ed897ea4f
|
[
"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
| 4,642
|
lean
|
/-
Copyright (c) 2020 Marc Huisinga. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Marc Huisinga, Wojciech Nawrocki
-/
import Lean.Data.Json
import Lean.Data.JsonRpc
/-! Defines most of the 'Basic Structures' in the LSP specification
(https://microsoft.github.io/language-server-protocol/specifications/specification-current/),
as well as some utilities.
Since LSP is Json-based, Ints/Nats are represented by Floats on the wire. -/
namespace Lean
namespace Lsp
open Json
structure CancelParams where
id : JsonRpc.RequestID
deriving Inhabited, BEq, ToJson, FromJson
abbrev DocumentUri := String
/-- We adopt the convention that zero-based UTF-16 positions as sent by LSP clients
are represented by `Lsp.Position` while internally we mostly use `String.Pos` UTF-8
offsets. For diagnostics, one-based `Lean.Position`s are used internally.
`character` is accepted liberally: actual character := min(line length, character) -/
structure Position where
line : Nat
character : Nat
deriving Inhabited, BEq, ToJson, FromJson
instance : ToString Position := ⟨fun p =>
"(" ++ toString p.line ++ ", " ++ toString p.character ++ ")"⟩
structure Range where
start : Position
«end» : Position
deriving Inhabited, BEq, ToJson, FromJson
structure Location where
uri : DocumentUri
range : Range
deriving Inhabited, BEq, ToJson, FromJson
structure LocationLink where
originSelectionRange? : Option Range
targetUri : DocumentUri
targetRange : Range
targetSelectionRange : Range
deriving ToJson, FromJson
-- NOTE: Diagnostic defined in Diagnostics.lean
/- NOTE: No specific commands are specified by LSP, hence
possible commands need to be announced as capabilities. -/
structure Command where
title : String
command : String
arguments? : Option (Array Json) := none
deriving ToJson, FromJson
structure TextEdit where
range : Range
newText : String
deriving ToJson, FromJson
def TextEditBatch := Array TextEdit
instance : FromJson TextEditBatch :=
⟨@fromJson? (Array TextEdit) _⟩
instance : ToJson TextEditBatch :=
⟨@toJson (Array TextEdit) _⟩
structure TextDocumentIdentifier where
uri : DocumentUri
deriving ToJson, FromJson
structure VersionedTextDocumentIdentifier where
uri : DocumentUri
version? : Option Nat := none
deriving ToJson, FromJson
structure TextDocumentEdit where
textDocument : VersionedTextDocumentIdentifier
edits : TextEditBatch
deriving ToJson, FromJson
-- TODO(Marc): missing:
-- File Resource Changes, WorkspaceEdit
-- both of these are pretty global, we can look at their
-- uses when single file behaviour works.
structure TextDocumentItem where
uri : DocumentUri
languageId : String
version : Nat
text : String
deriving ToJson, FromJson
structure TextDocumentPositionParams where
textDocument : TextDocumentIdentifier
position : Position
deriving ToJson, FromJson
structure DocumentFilter where
language? : Option String := none
scheme? : Option String := none
pattern? : Option String := none
deriving ToJson, FromJson
def DocumentSelector := Array DocumentFilter
instance : FromJson DocumentSelector :=
⟨@fromJson? (Array DocumentFilter) _⟩
instance : ToJson DocumentSelector :=
⟨@toJson (Array DocumentFilter) _⟩
structure StaticRegistrationOptions where
id? : Option String := none
deriving ToJson, FromJson
structure TextDocumentRegistrationOptions where
documentSelector? : Option DocumentSelector := none
deriving ToJson, FromJson
inductive MarkupKind where
| plaintext | markdown
instance : FromJson MarkupKind := ⟨fun
| str "plaintext" => Except.ok MarkupKind.plaintext
| str "markdown" => Except.ok MarkupKind.markdown
| _ => throw "unknown MarkupKind"⟩
instance : ToJson MarkupKind := ⟨fun
| MarkupKind.plaintext => str "plaintext"
| MarkupKind.markdown => str "markdown"⟩
structure MarkupContent where
kind : MarkupKind
value : String
deriving ToJson, FromJson
structure ProgressParams (α : Type) where
token : String -- do we need `integer`?
value : α
deriving ToJson
structure WorkDoneProgressReport where
kind := "report"
message? : Option String := none
cancellable := false
percentage? : Option Nat := none
deriving ToJson
structure WorkDoneProgressBegin extends WorkDoneProgressReport where
kind := "begin"
title : String
deriving ToJson
structure WorkDoneProgressEnd where
kind := "end"
message? : Option String := none
deriving ToJson
-- TODO(Marc): missing:
-- WorkDoneProgressOptions, PartialResultParams
end Lsp
end Lean
|
eae8ecdd6189ebb89fbfe8cb27d2f1a185e58653
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tmp/debugger_example.lean
|
b18b57871f4a23360aa4649f9652281dd5fec1db
|
[
"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
| 235
|
lean
|
import tools.debugger
set_option debugger true
set_option debugger.autorun true
open tactic
local attribute [breakpoint] tactic.constructor
example (p q : Prop) : p → q → p ∧ q :=
by do intros, constructor, repeat assumption
|
0336e79b3e26afa872db76c2c4d4d17dd97fed54
|
a45212b1526d532e6e83c44ddca6a05795113ddc
|
/test/omega.lean
|
18dc49c54f41b59d3645f401770f9a1b2a9555b7
|
[
"Apache-2.0"
] |
permissive
|
fpvandoorn/mathlib
|
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
|
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
|
refs/heads/master
| 1,624,791,089,608
| 1,556,715,231,000
| 1,556,715,231,000
| 165,722,980
| 5
| 0
|
Apache-2.0
| 1,552,657,455,000
| 1,547,494,646,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,454
|
lean
|
/-
Test cases for omega. Most of the examples are from John Harrison's
Handbook of Practical Logic and Automated Reasoning.
-/
import tactic.omega
example (x : int) : (x = 5 ∨ x = 7) → 2 < x := by omega
example (x : int) : x ≤ -x → x ≤ 0 := by omega
example : ∀ x y : int, (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega
example : ∀ (x y z : int), x < y → y < z → x < z := by omega
example (x y z : int) : x - y ≤ x - z → z ≤ y:= by omega
example (x : int) (h1 : x = -5 ∨ x = 7) (h2 : x = 0) : false := by omega
example : ∀ x : int, 31 * x > 0 → x > 0 := by omega
example (x y : int) : (-x - y < x - y) → (x - y < x + y) → (x > 0 ∧ y > 0) := by omega
example : ∀ (x : int), (x ≥ -1 ∧ x ≤ 1) → (x = -1 ∨ x = 0 ∨ x = 1):= by omega
example : ∀ (x : int), 5 * x = 5 → x = 1 := by omega
example (x y : int) : ∀ z w v : int, x = y → y = z → x = z := by omega
example : ∀ x : int, x < 349 ∨ x > 123 := by omega
example : ∀ x y : int, x ≤ 3 * y → 3 * x ≤ 9 * y := by omega
example (x : int) (h1 : x < 43 ∧ x > 513) : false := by omega
example (x y z w : int) : x ≤ y → y ≤ z → z ≤ w → x ≤ w:= by omega
example (x y z : int) : ∀ w v : int, 100 = x → x = y → y = z → z = w → w = v → v = 100 := by omega
example (x : nat) : 31 * x > 0 → x > 0 := by omega
example (x y : nat) : (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega
example : ∀ (x y z y : nat), ¬(2 * x + 1 = 2 * y) := by omega
example : ∀ (x y : nat), x > 0 → x + y > 0 := by omega
example : ∀ (x : nat), x < 349 ∨ x > 123 := by omega
example : ∀ (x y : nat), (x = 2 ∨ x = 10) → (x = 3 * y) → false := by omega
example (x y : nat) : x ≤ 3 * y → 3 * x ≤ 9 * y := by omega
example (x y z : nat) : (x ≤ y) → (z > y) → (x - z = 0) := by omega
example (x y z : nat) : x - 5 > 122 → y ≤ 127 → y < x := by omega
example : ∀ (x y : nat), x ≤ y ↔ x - y = 0 := by omega
/-
Use `omega manual` to disable automatic reverts,
and `omega int` or `omega nat` to specify the domain.
-/
example (i : int) (n : nat) (h1 : n = 0) (h2 : i < i) : false := by omega int
example (i : int) (n : nat) (h1 : i = 0) (h2 : n < n) : false := by omega nat
example (x y z w : int) (h1 : 3 * y ≥ x) (h2 : z > 19 * w) : 3 * x ≤ 9 * y :=
by {revert h1 x y, omega manual}
example (n : nat) (h1 : n < 34) (i : int) (h2 : i * 9 = -72) : i = -8 :=
by {revert h2 i, omega manual int}
|
472e21d4ba8c05c164860cbdfb7b4305c62e3f93
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/algebra/category/CommRing/basic_auto.lean
|
b2cc9e06e727c6f18b524b5b8203c7ee7b529449
|
[] |
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
| 10,944
|
lean
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.category.Group.basic
import Mathlib.data.equiv.ring
import Mathlib.PostPort
universes u u_1
namespace Mathlib
/-!
# Category instances for semiring, ring, comm_semiring, and comm_ring.
We introduce the bundled categories:
* `SemiRing`
* `Ring`
* `CommSemiRing`
* `CommRing`
along with the relevant forgetful functors between them.
-/
/-- The category of semirings. -/
def SemiRing := category_theory.bundled semiring
namespace SemiRing
protected instance bundled_hom : category_theory.bundled_hom ring_hom :=
category_theory.bundled_hom.mk ring_hom.to_fun ring_hom.id ring_hom.comp
protected instance large_category : category_theory.large_category SemiRing :=
category_theory.bundled_hom.category ring_hom
/-- Construct a bundled SemiRing from the underlying type and typeclass. -/
def of (R : Type u) [semiring R] : SemiRing := category_theory.bundled.of R
protected instance inhabited : Inhabited SemiRing := { default := of PUnit }
protected instance semiring (R : SemiRing) : semiring ↥R := category_theory.bundled.str R
@[simp] theorem coe_of (R : Type u) [semiring R] : ↥(of R) = R := rfl
protected instance has_forget_to_Mon : category_theory.has_forget₂ SemiRing Mon :=
category_theory.bundled_hom.mk_has_forget₂
(fun (R : Type u_1) (hR : semiring R) => monoid_with_zero.to_monoid R)
(fun (R₁ R₂ : category_theory.bundled semiring) => ring_hom.to_monoid_hom) sorry
-- can't use bundled_hom.mk_has_forget₂, since AddCommMon is an induced category
protected instance has_forget_to_AddCommMon : category_theory.has_forget₂ SemiRing AddCommMon :=
category_theory.has_forget₂.mk
(category_theory.functor.mk (fun (R : SemiRing) => AddCommMon.of ↥R)
fun (R₁ R₂ : SemiRing) (f : R₁ ⟶ R₂) => ring_hom.to_add_monoid_hom f)
end SemiRing
/-- The category of rings. -/
def Ring := category_theory.bundled ring
namespace Ring
protected instance ring.to_semiring.category_theory.bundled_hom.parent_projection :
category_theory.bundled_hom.parent_projection ring.to_semiring :=
category_theory.bundled_hom.parent_projection.mk
protected instance concrete_category : category_theory.concrete_category Ring :=
category_theory.bundled_hom.category_theory.bundled.category_theory.concrete_category
(category_theory.bundled_hom.map_hom ring_hom ring.to_semiring)
/-- Construct a bundled Ring from the underlying type and typeclass. -/
def of (R : Type u) [ring R] : Ring := category_theory.bundled.of R
protected instance inhabited : Inhabited Ring := { default := of PUnit }
protected instance ring (R : Ring) : ring ↥R := category_theory.bundled.str R
@[simp] theorem coe_of (R : Type u) [ring R] : ↥(of R) = R := rfl
protected instance has_forget_to_SemiRing : category_theory.has_forget₂ Ring SemiRing :=
category_theory.bundled_hom.forget₂ ring_hom ring.to_semiring
-- can't use bundled_hom.mk_has_forget₂, since AddCommGroup is an induced category
protected instance has_forget_to_AddCommGroup : category_theory.has_forget₂ Ring AddCommGroup :=
category_theory.has_forget₂.mk
(category_theory.functor.mk (fun (R : Ring) => AddCommGroup.of ↥R)
fun (R₁ R₂ : Ring) (f : R₁ ⟶ R₂) => ring_hom.to_add_monoid_hom f)
end Ring
/-- The category of commutative semirings. -/
def CommSemiRing := category_theory.bundled comm_semiring
namespace CommSemiRing
protected instance comm_semiring.to_semiring.category_theory.bundled_hom.parent_projection :
category_theory.bundled_hom.parent_projection comm_semiring.to_semiring :=
category_theory.bundled_hom.parent_projection.mk
protected instance large_category : category_theory.large_category CommSemiRing :=
category_theory.bundled_hom.category
(category_theory.bundled_hom.map_hom ring_hom comm_semiring.to_semiring)
/-- Construct a bundled CommSemiRing from the underlying type and typeclass. -/
def of (R : Type u) [comm_semiring R] : CommSemiRing := category_theory.bundled.of R
protected instance inhabited : Inhabited CommSemiRing := { default := of PUnit }
protected instance comm_semiring (R : CommSemiRing) : comm_semiring ↥R :=
category_theory.bundled.str R
@[simp] theorem coe_of (R : Type u) [comm_semiring R] : ↥(of R) = R := rfl
protected instance has_forget_to_SemiRing : category_theory.has_forget₂ CommSemiRing SemiRing :=
category_theory.bundled_hom.forget₂ ring_hom comm_semiring.to_semiring
/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
protected instance has_forget_to_CommMon : category_theory.has_forget₂ CommSemiRing CommMon :=
category_theory.has_forget₂.mk' (fun (R : CommSemiRing) => CommMon.of ↥R) sorry
(fun (R₁ R₂ : CommSemiRing) (f : R₁ ⟶ R₂) => ring_hom.to_monoid_hom f) sorry
end CommSemiRing
/-- The category of commutative rings. -/
def CommRing := category_theory.bundled comm_ring
namespace CommRing
protected instance comm_ring.to_ring.category_theory.bundled_hom.parent_projection :
category_theory.bundled_hom.parent_projection comm_ring.to_ring :=
category_theory.bundled_hom.parent_projection.mk
protected instance concrete_category : category_theory.concrete_category CommRing :=
category_theory.bundled_hom.category_theory.bundled.category_theory.concrete_category
(category_theory.bundled_hom.map_hom
(category_theory.bundled_hom.map_hom ring_hom ring.to_semiring) comm_ring.to_ring)
/-- Construct a bundled CommRing from the underlying type and typeclass. -/
def of (R : Type u) [comm_ring R] : CommRing := category_theory.bundled.of R
protected instance inhabited : Inhabited CommRing := { default := of PUnit }
protected instance comm_ring (R : CommRing) : comm_ring ↥R := category_theory.bundled.str R
@[simp] theorem coe_of (R : Type u) [comm_ring R] : ↥(of R) = R := rfl
protected instance has_forget_to_Ring : category_theory.has_forget₂ CommRing Ring :=
category_theory.bundled_hom.forget₂
(category_theory.bundled_hom.map_hom ring_hom ring.to_semiring) comm_ring.to_ring
/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
protected instance has_forget_to_CommSemiRing : category_theory.has_forget₂ CommRing CommSemiRing :=
category_theory.has_forget₂.mk' (fun (R : CommRing) => CommSemiRing.of ↥R) sorry
(fun (R₁ R₂ : CommRing) (f : R₁ ⟶ R₂) => f) sorry
protected instance category_theory.forget₂.category_theory.full :
category_theory.full (category_theory.forget₂ CommRing CommSemiRing) :=
category_theory.full.mk
fun (X Y : CommRing)
(f :
category_theory.functor.obj (category_theory.forget₂ CommRing CommSemiRing) X ⟶
category_theory.functor.obj (category_theory.forget₂ CommRing CommSemiRing) Y) =>
f
end CommRing
-- This example verifies an improvement possible in Lean 3.8.
-- Before that, to have `add_ring_hom.map_zero` usable by `simp` here,
-- we had to mark all the concrete category `has_coe_to_sort` instances reducible.
-- Now, it just works.
namespace ring_equiv
/-- Build an isomorphism in the category `Ring` from a `ring_equiv` between `ring`s. -/
@[simp] theorem to_Ring_iso_inv {X : Type u} {Y : Type u} [ring X] [ring Y] (e : X ≃+* Y) :
category_theory.iso.inv (to_Ring_iso e) = to_ring_hom (ring_equiv.symm e) :=
Eq.refl (category_theory.iso.inv (to_Ring_iso e))
/-- Build an isomorphism in the category `CommRing` from a `ring_equiv` between `comm_ring`s. -/
def to_CommRing_iso {X : Type u} {Y : Type u} [comm_ring X] [comm_ring Y] (e : X ≃+* Y) :
CommRing.of X ≅ CommRing.of Y :=
category_theory.iso.mk (to_ring_hom e) (to_ring_hom (ring_equiv.symm e))
end ring_equiv
namespace category_theory.iso
/-- Build a `ring_equiv` from an isomorphism in the category `Ring`. -/
def Ring_iso_to_ring_equiv {X : Ring} {Y : Ring} (i : X ≅ Y) : ↥X ≃+* ↥Y :=
ring_equiv.mk ⇑(hom i) ⇑(inv i) sorry sorry sorry sorry
/-- Build a `ring_equiv` from an isomorphism in the category `CommRing`. -/
def CommRing_iso_to_ring_equiv {X : CommRing} {Y : CommRing} (i : X ≅ Y) : ↥X ≃+* ↥Y :=
ring_equiv.mk ⇑(hom i) ⇑(inv i) sorry sorry sorry sorry
end category_theory.iso
/-- Ring equivalences between `ring`s are the same as (isomorphic to) isomorphisms in `Ring`. -/
def ring_equiv_iso_Ring_iso {X : Type u} {Y : Type u} [ring X] [ring Y] :
X ≃+* Y ≅ Ring.of X ≅ Ring.of Y :=
category_theory.iso.mk (fun (e : X ≃+* Y) => ring_equiv.to_Ring_iso e)
fun (i : Ring.of X ≅ Ring.of Y) => category_theory.iso.Ring_iso_to_ring_equiv i
/-- Ring equivalences between `comm_ring`s are the same as (isomorphic to) isomorphisms
in `CommRing`. -/
def ring_equiv_iso_CommRing_iso {X : Type u} {Y : Type u} [comm_ring X] [comm_ring Y] :
X ≃+* Y ≅ CommRing.of X ≅ CommRing.of Y :=
category_theory.iso.mk (fun (e : X ≃+* Y) => ring_equiv.to_CommRing_iso e)
fun (i : CommRing.of X ≅ CommRing.of Y) => category_theory.iso.CommRing_iso_to_ring_equiv i
protected instance Ring.forget_reflects_isos :
category_theory.reflects_isomorphisms (category_theory.forget Ring) :=
category_theory.reflects_isomorphisms.mk
fun (X Y : Ring) (f : X ⟶ Y)
(_x : category_theory.is_iso (category_theory.functor.map (category_theory.forget Ring) f)) =>
let i :
category_theory.functor.obj (category_theory.forget Ring) X ≅
category_theory.functor.obj (category_theory.forget Ring) Y :=
category_theory.as_iso (category_theory.functor.map (category_theory.forget Ring) f);
let e : ↥X ≃+* ↥Y :=
ring_equiv.mk (ring_hom.to_fun f) (equiv.inv_fun (category_theory.iso.to_equiv i)) sorry
sorry sorry sorry;
category_theory.is_iso.mk (category_theory.iso.inv (ring_equiv.to_Ring_iso e))
protected instance CommRing.forget_reflects_isos :
category_theory.reflects_isomorphisms (category_theory.forget CommRing) :=
category_theory.reflects_isomorphisms.mk
fun (X Y : CommRing) (f : X ⟶ Y)
(_x :
category_theory.is_iso (category_theory.functor.map (category_theory.forget CommRing) f)) =>
let i :
category_theory.functor.obj (category_theory.forget CommRing) X ≅
category_theory.functor.obj (category_theory.forget CommRing) Y :=
category_theory.as_iso (category_theory.functor.map (category_theory.forget CommRing) f);
let e : ↥X ≃+* ↥Y :=
ring_equiv.mk (ring_hom.to_fun f) (equiv.inv_fun (category_theory.iso.to_equiv i)) sorry
sorry sorry sorry;
category_theory.is_iso.mk (category_theory.iso.inv (ring_equiv.to_CommRing_iso e))
end Mathlib
|
c3127b283807860069d3e6491d9592e6427a622a
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/algebraic_geometry/prime_spectrum/basic.lean
|
543338325925b48320c8ea58a1f91252f7fc51b8
|
[
"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
| 30,846
|
lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import topology.opens
import ring_theory.ideal.prod
import ring_theory.ideal.over
import linear_algebra.finsupp
import algebra.punit_instances
import ring_theory.nilpotent
import topology.sober
/-!
# Prime spectrum of a commutative ring
The prime spectrum of a commutative ring is the type of all prime ideals.
It is naturally endowed with a topology: the Zariski topology.
(It is also naturally endowed with a sheaf of rings,
which is constructed in `algebraic_geometry.structure_sheaf`.)
## Main definitions
* `prime_spectrum R`: The prime spectrum of a commutative ring `R`,
i.e., the set of all prime ideals of `R`.
* `zero_locus s`: The zero locus of a subset `s` of `R`
is the subset of `prime_spectrum R` consisting of all prime ideals that contain `s`.
* `vanishing_ideal t`: The vanishing ideal of a subset `t` of `prime_spectrum R`
is the intersection of points in `t` (viewed as prime ideals).
## Conventions
We denote subsets of rings with `s`, `s'`, etc...
whereas we denote subsets of prime spectra with `t`, `t'`, etc...
## Inspiration/contributors
The contents of this file draw inspiration from
<https://github.com/ramonfmir/lean-scheme>
which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau,
and Chris Hughes (on an earlier repository).
-/
noncomputable theory
open_locale classical
universes u v
variables (R : Type u) [comm_ring R]
/-- The prime spectrum of a commutative ring `R`
is the type of all prime ideals of `R`.
It is naturally endowed with a topology (the Zariski topology),
and a sheaf of commutative rings (see `algebraic_geometry.structure_sheaf`).
It is a fundamental building block in algebraic geometry. -/
@[nolint has_inhabited_instance]
def prime_spectrum := {I : ideal R // I.is_prime}
variable {R}
namespace prime_spectrum
/-- A method to view a point in the prime spectrum of a commutative ring
as an ideal of that ring. -/
abbreviation as_ideal (x : prime_spectrum R) : ideal R := x.val
instance is_prime (x : prime_spectrum R) :
x.as_ideal.is_prime := x.2
/--
The prime spectrum of the zero ring is empty.
-/
lemma punit (x : prime_spectrum punit) : false :=
x.1.ne_top_iff_one.1 x.2.1 $ subsingleton.elim (0 : punit) 1 ▸ x.1.zero_mem
section
variables (R) (S : Type v) [comm_ring S]
/-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of
`R` and the prime spectrum of `S`. -/
noncomputable def prime_spectrum_prod :
prime_spectrum (R × S) ≃ prime_spectrum R ⊕ prime_spectrum S :=
ideal.prime_ideals_equiv R S
variables {R S}
@[simp] lemma prime_spectrum_prod_symm_inl_as_ideal (x : prime_spectrum R) :
((prime_spectrum_prod R S).symm (sum.inl x)).as_ideal = ideal.prod x.as_ideal ⊤ :=
by { cases x, refl }
@[simp] lemma prime_spectrum_prod_symm_inr_as_ideal (x : prime_spectrum S) :
((prime_spectrum_prod R S).symm (sum.inr x)).as_ideal = ideal.prod ⊤ x.as_ideal :=
by { cases x, refl }
end
@[ext] lemma ext {x y : prime_spectrum R} :
x = y ↔ x.as_ideal = y.as_ideal :=
subtype.ext_iff_val
/-- The zero locus of a set `s` of elements of a commutative ring `R`
is the set of all prime ideals of the ring that contain the set `s`.
An element `f` of `R` can be thought of as a dependent function
on the prime spectrum of `R`.
At a point `x` (a prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`.
In this manner, `zero_locus s` is exactly the subset of `prime_spectrum R`
where all "functions" in `s` vanish simultaneously.
-/
def zero_locus (s : set R) : set (prime_spectrum R) :=
{x | s ⊆ x.as_ideal}
@[simp] lemma mem_zero_locus (x : prime_spectrum R) (s : set R) :
x ∈ zero_locus s ↔ s ⊆ x.as_ideal := iff.rfl
@[simp] lemma zero_locus_span (s : set R) :
zero_locus (ideal.span s : set R) = zero_locus s :=
by { ext x, exact (submodule.gi R R).gc s x.as_ideal }
/-- The vanishing ideal of a set `t` of points
of the prime spectrum of a commutative ring `R`
is the intersection of all the prime ideals in the set `t`.
An element `f` of `R` can be thought of as a dependent function
on the prime spectrum of `R`.
At a point `x` (a prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`.
In this manner, `vanishing_ideal t` is exactly the ideal of `R`
consisting of all "functions" that vanish on all of `t`.
-/
def vanishing_ideal (t : set (prime_spectrum R)) : ideal R :=
⨅ (x : prime_spectrum R) (h : x ∈ t), x.as_ideal
lemma coe_vanishing_ideal (t : set (prime_spectrum R)) :
(vanishing_ideal t : set R) = {f : R | ∀ x : prime_spectrum R, x ∈ t → f ∈ x.as_ideal} :=
begin
ext f,
rw [vanishing_ideal, set_like.mem_coe, submodule.mem_infi],
apply forall_congr, intro x,
rw [submodule.mem_infi],
end
lemma mem_vanishing_ideal (t : set (prime_spectrum R)) (f : R) :
f ∈ vanishing_ideal t ↔ ∀ x : prime_spectrum R, x ∈ t → f ∈ x.as_ideal :=
by rw [← set_like.mem_coe, coe_vanishing_ideal, set.mem_set_of_eq]
@[simp] lemma vanishing_ideal_singleton (x : prime_spectrum R) :
vanishing_ideal ({x} : set (prime_spectrum R)) = x.as_ideal :=
by simp [vanishing_ideal]
lemma subset_zero_locus_iff_le_vanishing_ideal (t : set (prime_spectrum R)) (I : ideal R) :
t ⊆ zero_locus I ↔ I ≤ vanishing_ideal t :=
⟨λ h f k, (mem_vanishing_ideal _ _).mpr (λ x j, (mem_zero_locus _ _).mpr (h j) k), λ h,
λ x j, (mem_zero_locus _ _).mpr (le_trans h (λ f h, ((mem_vanishing_ideal _ _).mp h) x j))⟩
section gc
variable (R)
/-- `zero_locus` and `vanishing_ideal` form a galois connection. -/
lemma gc : @galois_connection
(ideal R) (order_dual (set (prime_spectrum R))) _ _
(λ I, zero_locus I) (λ t, vanishing_ideal t) :=
λ I t, subset_zero_locus_iff_le_vanishing_ideal t I
/-- `zero_locus` and `vanishing_ideal` form a galois connection. -/
lemma gc_set : @galois_connection
(set R) (order_dual (set (prime_spectrum R))) _ _
(λ s, zero_locus s) (λ t, vanishing_ideal t) :=
have ideal_gc : galois_connection (ideal.span) coe := (submodule.gi R R).gc,
by simpa [zero_locus_span, function.comp] using ideal_gc.compose (gc R)
lemma subset_zero_locus_iff_subset_vanishing_ideal (t : set (prime_spectrum R)) (s : set R) :
t ⊆ zero_locus s ↔ s ⊆ vanishing_ideal t :=
(gc_set R) s t
end gc
lemma subset_vanishing_ideal_zero_locus (s : set R) :
s ⊆ vanishing_ideal (zero_locus s) :=
(gc_set R).le_u_l s
lemma le_vanishing_ideal_zero_locus (I : ideal R) :
I ≤ vanishing_ideal (zero_locus I) :=
(gc R).le_u_l I
@[simp] lemma vanishing_ideal_zero_locus_eq_radical (I : ideal R) :
vanishing_ideal (zero_locus (I : set R)) = I.radical := ideal.ext $ λ f,
begin
rw [mem_vanishing_ideal, ideal.radical_eq_Inf, submodule.mem_Inf],
exact ⟨(λ h x hx, h ⟨x, hx.2⟩ hx.1), (λ h x hx, h x.1 ⟨hx, x.2⟩)⟩
end
@[simp] lemma zero_locus_radical (I : ideal R) : zero_locus (I.radical : set R) = zero_locus I :=
vanishing_ideal_zero_locus_eq_radical I ▸ (gc R).l_u_l_eq_l I
lemma subset_zero_locus_vanishing_ideal (t : set (prime_spectrum R)) :
t ⊆ zero_locus (vanishing_ideal t) :=
(gc R).l_u_le t
lemma zero_locus_anti_mono {s t : set R} (h : s ⊆ t) : zero_locus t ⊆ zero_locus s :=
(gc_set R).monotone_l h
lemma zero_locus_anti_mono_ideal {s t : ideal R} (h : s ≤ t) :
zero_locus (t : set R) ⊆ zero_locus (s : set R) :=
(gc R).monotone_l h
lemma vanishing_ideal_anti_mono {s t : set (prime_spectrum R)} (h : s ⊆ t) :
vanishing_ideal t ≤ vanishing_ideal s :=
(gc R).monotone_u h
lemma zero_locus_subset_zero_locus_iff (I J : ideal R) :
zero_locus (I : set R) ⊆ zero_locus (J : set R) ↔ J ≤ I.radical :=
⟨λ h, ideal.radical_le_radical_iff.mp (vanishing_ideal_zero_locus_eq_radical I ▸
vanishing_ideal_zero_locus_eq_radical J ▸ vanishing_ideal_anti_mono h),
λ h, zero_locus_radical I ▸ zero_locus_anti_mono_ideal h⟩
lemma zero_locus_subset_zero_locus_singleton_iff (f g : R) :
zero_locus ({f} : set R) ⊆ zero_locus {g} ↔ g ∈ (ideal.span ({f} : set R)).radical :=
by rw [← zero_locus_span {f}, ← zero_locus_span {g}, zero_locus_subset_zero_locus_iff,
ideal.span_le, set.singleton_subset_iff, set_like.mem_coe]
lemma zero_locus_bot :
zero_locus ((⊥ : ideal R) : set R) = set.univ :=
(gc R).l_bot
@[simp] lemma zero_locus_singleton_zero :
zero_locus ({0} : set R) = set.univ :=
zero_locus_bot
@[simp] lemma zero_locus_empty :
zero_locus (∅ : set R) = set.univ :=
(gc_set R).l_bot
@[simp] lemma vanishing_ideal_univ :
vanishing_ideal (∅ : set (prime_spectrum R)) = ⊤ :=
by simpa using (gc R).u_top
lemma zero_locus_empty_of_one_mem {s : set R} (h : (1:R) ∈ s) :
zero_locus s = ∅ :=
begin
rw set.eq_empty_iff_forall_not_mem,
intros x hx,
rw mem_zero_locus at hx,
have x_prime : x.as_ideal.is_prime := by apply_instance,
have eq_top : x.as_ideal = ⊤, { rw ideal.eq_top_iff_one, exact hx h },
apply x_prime.ne_top eq_top,
end
@[simp] lemma zero_locus_singleton_one :
zero_locus ({1} : set R) = ∅ :=
zero_locus_empty_of_one_mem (set.mem_singleton (1 : R))
lemma zero_locus_empty_iff_eq_top {I : ideal R} :
zero_locus (I : set R) = ∅ ↔ I = ⊤ :=
begin
split,
{ contrapose!,
intro h,
apply set.ne_empty_iff_nonempty.mpr,
rcases ideal.exists_le_maximal I h with ⟨M, hM, hIM⟩,
exact ⟨⟨M, hM.is_prime⟩, hIM⟩ },
{ rintro rfl, apply zero_locus_empty_of_one_mem, trivial }
end
@[simp] lemma zero_locus_univ :
zero_locus (set.univ : set R) = ∅ :=
zero_locus_empty_of_one_mem (set.mem_univ 1)
lemma zero_locus_sup (I J : ideal R) :
zero_locus ((I ⊔ J : ideal R) : set R) = zero_locus I ∩ zero_locus J :=
(gc R).l_sup
lemma zero_locus_union (s s' : set R) :
zero_locus (s ∪ s') = zero_locus s ∩ zero_locus s' :=
(gc_set R).l_sup
lemma vanishing_ideal_union (t t' : set (prime_spectrum R)) :
vanishing_ideal (t ∪ t') = vanishing_ideal t ⊓ vanishing_ideal t' :=
(gc R).u_inf
lemma zero_locus_supr {ι : Sort*} (I : ι → ideal R) :
zero_locus ((⨆ i, I i : ideal R) : set R) = (⋂ i, zero_locus (I i)) :=
(gc R).l_supr
lemma zero_locus_Union {ι : Sort*} (s : ι → set R) :
zero_locus (⋃ i, s i) = (⋂ i, zero_locus (s i)) :=
(gc_set R).l_supr
lemma zero_locus_bUnion (s : set (set R)) :
zero_locus (⋃ s' ∈ s, s' : set R) = ⋂ s' ∈ s, zero_locus s' :=
by simp only [zero_locus_Union]
lemma vanishing_ideal_Union {ι : Sort*} (t : ι → set (prime_spectrum R)) :
vanishing_ideal (⋃ i, t i) = (⨅ i, vanishing_ideal (t i)) :=
(gc R).u_infi
lemma zero_locus_inf (I J : ideal R) :
zero_locus ((I ⊓ J : ideal R) : set R) = zero_locus I ∪ zero_locus J :=
set.ext $ λ x, by simpa using x.2.inf_le
lemma union_zero_locus (s s' : set R) :
zero_locus s ∪ zero_locus s' = zero_locus ((ideal.span s) ⊓ (ideal.span s') : ideal R) :=
by { rw zero_locus_inf, simp }
lemma zero_locus_mul (I J : ideal R) :
zero_locus ((I * J : ideal R) : set R) = zero_locus I ∪ zero_locus J :=
set.ext $ λ x, by simpa using x.2.mul_le
lemma zero_locus_singleton_mul (f g : R) :
zero_locus ({f * g} : set R) = zero_locus {f} ∪ zero_locus {g} :=
set.ext $ λ x, by simpa using x.2.mul_mem_iff_mem_or_mem
@[simp] lemma zero_locus_pow (I : ideal R) {n : ℕ} (hn : 0 < n) :
zero_locus ((I ^ n : ideal R) : set R) = zero_locus I :=
zero_locus_radical (I ^ n) ▸ (I.radical_pow n hn).symm ▸ zero_locus_radical I
@[simp] lemma zero_locus_singleton_pow (f : R) (n : ℕ) (hn : 0 < n) :
zero_locus ({f ^ n} : set R) = zero_locus {f} :=
set.ext $ λ x, by simpa using x.2.pow_mem_iff_mem n hn
lemma sup_vanishing_ideal_le (t t' : set (prime_spectrum R)) :
vanishing_ideal t ⊔ vanishing_ideal t' ≤ vanishing_ideal (t ∩ t') :=
begin
intros r,
rw [submodule.mem_sup, mem_vanishing_ideal],
rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩,
rw mem_vanishing_ideal at hf hg,
apply submodule.add_mem; solve_by_elim
end
lemma mem_compl_zero_locus_iff_not_mem {f : R} {I : prime_spectrum R} :
I ∈ (zero_locus {f} : set (prime_spectrum R))ᶜ ↔ f ∉ I.as_ideal :=
by rw [set.mem_compl_eq, mem_zero_locus, set.singleton_subset_iff]; refl
/-- The Zariski topology on the prime spectrum of a commutative ring
is defined via the closed sets of the topology:
they are exactly those sets that are the zero locus of a subset of the ring. -/
instance zariski_topology : topological_space (prime_spectrum R) :=
topological_space.of_closed (set.range prime_spectrum.zero_locus)
(⟨set.univ, by simp⟩)
begin
intros Zs h,
rw set.sInter_eq_Inter,
let f : Zs → set R := λ i, classical.some (h i.2),
have hf : ∀ i : Zs, ↑i = zero_locus (f i) := λ i, (classical.some_spec (h i.2)).symm,
simp only [hf],
exact ⟨_, zero_locus_Union _⟩
end
(by { rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩, exact ⟨_, (union_zero_locus s t).symm⟩ })
lemma is_open_iff (U : set (prime_spectrum R)) :
is_open U ↔ ∃ s, Uᶜ = zero_locus s :=
by simp only [@eq_comm _ Uᶜ]; refl
lemma is_closed_iff_zero_locus (Z : set (prime_spectrum R)) :
is_closed Z ↔ ∃ s, Z = zero_locus s :=
by rw [← is_open_compl_iff, is_open_iff, compl_compl]
lemma is_closed_iff_zero_locus_ideal (Z : set (prime_spectrum R)) :
is_closed Z ↔ ∃ (s : ideal R), Z = zero_locus s :=
(is_closed_iff_zero_locus _).trans
⟨λ x, ⟨_, x.some_spec.trans (zero_locus_span _).symm⟩, λ x, ⟨_, x.some_spec⟩⟩
lemma is_closed_iff_zero_locus_radical_ideal (Z : set (prime_spectrum R)) :
is_closed Z ↔ ∃ (s : ideal R), s.radical = s ∧ Z = zero_locus s :=
(is_closed_iff_zero_locus_ideal _).trans
⟨λ x, ⟨_, ideal.radical_idem _, x.some_spec.trans (zero_locus_radical _).symm⟩,
λ x, ⟨_, x.some_spec.2⟩⟩
lemma is_closed_zero_locus (s : set R) :
is_closed (zero_locus s) :=
by { rw [is_closed_iff_zero_locus], exact ⟨s, rfl⟩ }
lemma is_closed_singleton_iff_is_maximal (x : prime_spectrum R) :
is_closed ({x} : set (prime_spectrum R)) ↔ x.as_ideal.is_maximal :=
begin
refine (is_closed_iff_zero_locus _).trans ⟨λ h, _, λ h, _⟩,
{ obtain ⟨s, hs⟩ := h,
rw [eq_comm, set.eq_singleton_iff_unique_mem] at hs,
refine ⟨⟨x.2.1, λ I hI, not_not.1 (mt (ideal.exists_le_maximal I) $
not_exists.2 (λ J, not_and.2 $ λ hJ hIJ,_))⟩⟩,
exact ne_of_lt (lt_of_lt_of_le hI hIJ) (symm $ congr_arg prime_spectrum.as_ideal
(hs.2 ⟨J, hJ.is_prime⟩ (λ r hr, hIJ (le_of_lt hI $ hs.1 hr)))) },
{ refine ⟨x.as_ideal.1, _⟩,
rw [eq_comm, set.eq_singleton_iff_unique_mem],
refine ⟨λ _ h, h, λ y hy, prime_spectrum.ext.2 (h.eq_of_le y.2.ne_top hy).symm⟩ }
end
lemma zero_locus_vanishing_ideal_eq_closure (t : set (prime_spectrum R)) :
zero_locus (vanishing_ideal t : set R) = closure t :=
begin
apply set.subset.antisymm,
{ rintro x hx t' ⟨ht', ht⟩,
obtain ⟨fs, rfl⟩ : ∃ s, t' = zero_locus s,
by rwa [is_closed_iff_zero_locus] at ht',
rw [subset_zero_locus_iff_subset_vanishing_ideal] at ht,
exact set.subset.trans ht hx },
{ rw (is_closed_zero_locus _).closure_subset_iff,
exact subset_zero_locus_vanishing_ideal t }
end
lemma vanishing_ideal_closure (t : set (prime_spectrum R)) :
vanishing_ideal (closure t) = vanishing_ideal t :=
zero_locus_vanishing_ideal_eq_closure t ▸ (gc R).u_l_u_eq_u t
lemma t1_space_iff_is_field [is_domain R] :
t1_space (prime_spectrum R) ↔ is_field R :=
begin
refine ⟨_, λ h, _⟩,
{ introI h,
have hbot : ideal.is_prime (⊥ : ideal R) := ideal.bot_prime,
exact not_not.1 (mt (ring.ne_bot_of_is_maximal_of_not_is_field $
(is_closed_singleton_iff_is_maximal _).1 (t1_space.t1 ⟨⊥, hbot⟩)) (not_not.2 rfl)) },
{ refine ⟨λ x, (is_closed_singleton_iff_is_maximal x).2 _⟩,
by_cases hx : x.as_ideal = ⊥,
{ exact hx.symm ▸ @ideal.bot_is_maximal R (@field.to_division_ring _ $ is_field.to_field R h) },
{ exact absurd h (ring.not_is_field_iff_exists_prime.2 ⟨x.as_ideal, ⟨hx, x.2⟩⟩) } }
end
local notation `Z(` a `)` := zero_locus (a : set R)
lemma is_irreducible_zero_locus_iff_of_radical (I : ideal R) (hI : I.radical = I) :
is_irreducible (zero_locus (I : set R)) ↔ I.is_prime :=
begin
rw [ideal.is_prime_iff, is_irreducible],
apply and_congr,
{ rw [← set.ne_empty_iff_nonempty, ne.def, zero_locus_empty_iff_eq_top] },
{ transitivity ∀ (x y : ideal R), Z(I) ⊆ Z(x) ∪ Z(y) → Z(I) ⊆ Z(x) ∨ Z(I) ⊆ Z(y),
{ simp_rw [is_preirreducible_iff_closed_union_closed, is_closed_iff_zero_locus_ideal],
split,
{ rintros h x y, exact h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ },
{ rintros h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩, exact h x y } },
{ simp_rw [← zero_locus_inf, subset_zero_locus_iff_le_vanishing_ideal,
vanishing_ideal_zero_locus_eq_radical, hI],
split,
{ intros h x y h',
simp_rw [← set_like.mem_coe, ← set.singleton_subset_iff, ← ideal.span_le],
apply h,
rw [← hI, ← ideal.radical_le_radical_iff, ideal.radical_inf, ← ideal.radical_mul,
ideal.radical_le_radical_iff, hI, ideal.span_mul_span],
simpa [ideal.span_le] using h' },
{ simp_rw [or_iff_not_imp_left, set_like.not_le_iff_exists],
rintros h s t h' ⟨x, hx, hx'⟩ y hy,
exact h (h' ⟨ideal.mul_mem_right _ _ hx, ideal.mul_mem_left _ _ hy⟩) hx' } } }
end
lemma is_irreducible_zero_locus_iff (I : ideal R) :
is_irreducible (zero_locus (I : set R)) ↔ I.radical.is_prime :=
(zero_locus_radical I) ▸ is_irreducible_zero_locus_iff_of_radical _ I.radical_idem
instance [is_domain R] : irreducible_space (prime_spectrum R) :=
begin
rw [irreducible_space_def, set.top_eq_univ, ← zero_locus_bot, is_irreducible_zero_locus_iff],
simpa using ideal.bot_prime
end
instance : quasi_sober (prime_spectrum R) :=
begin
constructor,
intros S h₁ h₂,
rw [← h₂.closure_eq, ← zero_locus_vanishing_ideal_eq_closure,
is_irreducible_zero_locus_iff] at h₁,
use ⟨_, h₁⟩,
obtain ⟨s, hs, rfl⟩ := (is_closed_iff_zero_locus_radical_ideal _).mp h₂,
rw is_generic_point_iff_forall_closed h₂,
intros Z hZ hxZ,
obtain ⟨t, rfl⟩ := (is_closed_iff_zero_locus_ideal _).mp hZ,
exact zero_locus_anti_mono (by simpa [hs] using hxZ),
simp [hs]
end
section comap
variables {S : Type v} [comm_ring S] {S' : Type*} [comm_ring S']
lemma preimage_comap_zero_locus_aux (f : R →+* S) (s : set R) :
(λ y, ⟨ideal.comap f y.as_ideal, infer_instance⟩ :
prime_spectrum S → prime_spectrum R) ⁻¹' (zero_locus s) = zero_locus (f '' s) :=
begin
ext x,
simp only [mem_zero_locus, set.image_subset_iff],
refl
end
/-- The function between prime spectra of commutative rings induced by a ring homomorphism.
This function is continuous. -/
def comap (f : R →+* S) : C(prime_spectrum S, prime_spectrum R) :=
{ to_fun := λ y, ⟨ideal.comap f y.as_ideal, infer_instance⟩,
continuous_to_fun :=
begin
simp only [continuous_iff_is_closed, is_closed_iff_zero_locus],
rintro _ ⟨s, rfl⟩,
exact ⟨_, preimage_comap_zero_locus_aux f s⟩
end }
variables (f : R →+* S)
@[simp] lemma comap_as_ideal (y : prime_spectrum S) :
(comap f y).as_ideal = ideal.comap f y.as_ideal :=
rfl
@[simp] lemma comap_id : comap (ring_hom.id R) = continuous_map.id := by { ext, refl }
@[simp] lemma comap_comp (f : R →+* S) (g : S →+* S') :
comap (g.comp f) = (comap f).comp (comap g) :=
rfl
lemma comap_comp_apply (f : R →+* S) (g : S →+* S') (x : prime_spectrum S') :
prime_spectrum.comap (g.comp f) x = (prime_spectrum.comap f) (prime_spectrum.comap g x) :=
rfl
@[simp] lemma preimage_comap_zero_locus (s : set R) :
(comap f) ⁻¹' (zero_locus s) = zero_locus (f '' s) :=
preimage_comap_zero_locus_aux f s
lemma comap_injective_of_surjective (f : R →+* S) (hf : function.surjective f) :
function.injective (comap f) :=
λ x y h, prime_spectrum.ext.2 (ideal.comap_injective_of_surjective f hf
(congr_arg prime_spectrum.as_ideal h : (comap f x).as_ideal = (comap f y).as_ideal))
lemma comap_singleton_is_closed_of_surjective (f : R →+* S) (hf : function.surjective f)
(x : prime_spectrum S) (hx : is_closed ({x} : set (prime_spectrum S))) :
is_closed ({comap f x} : set (prime_spectrum R)) :=
begin
haveI : x.as_ideal.is_maximal := (is_closed_singleton_iff_is_maximal x).1 hx,
exact (is_closed_singleton_iff_is_maximal _).2 (ideal.comap_is_maximal_of_surjective f hf)
end
lemma comap_singleton_is_closed_of_is_integral (f : R →+* S) (hf : f.is_integral)
(x : prime_spectrum S) (hx : is_closed ({x} : set (prime_spectrum S))) :
is_closed ({comap f x} : set (prime_spectrum R)) :=
(is_closed_singleton_iff_is_maximal _).2 (ideal.is_maximal_comap_of_is_integral_of_is_maximal'
f hf x.as_ideal $ (is_closed_singleton_iff_is_maximal x).1 hx)
variable S
lemma localization_comap_inducing [algebra R S] (M : submonoid R)
[is_localization M S] : inducing (comap (algebra_map R S)) :=
begin
constructor,
rw topological_space_eq_iff,
intro U,
simp_rw ← is_closed_compl_iff,
generalize : Uᶜ = Z,
simp_rw [is_closed_induced_iff, is_closed_iff_zero_locus],
split,
{ rintro ⟨s, rfl⟩,
refine ⟨_,⟨(algebra_map R S) ⁻¹' (ideal.span s),rfl⟩,_⟩,
rw [preimage_comap_zero_locus, ← zero_locus_span, ← zero_locus_span s],
congr' 1,
exact congr_arg submodule.carrier (is_localization.map_comap M S (ideal.span s)) },
{ rintro ⟨_, ⟨t, rfl⟩, rfl⟩, simp }
end
lemma localization_comap_injective [algebra R S] (M : submonoid R)
[is_localization M S] : function.injective (comap (algebra_map R S)) :=
begin
intros p q h,
replace h := congr_arg (λ (x : prime_spectrum R), ideal.map (algebra_map R S) x.as_ideal) h,
dsimp only at h,
erw [is_localization.map_comap M S, is_localization.map_comap M S] at h,
ext1,
exact h
end
lemma localization_comap_embedding [algebra R S] (M : submonoid R)
[is_localization M S] : embedding (comap (algebra_map R S)) :=
⟨localization_comap_inducing S M, localization_comap_injective S M⟩
lemma localization_comap_range [algebra R S] (M : submonoid R)
[is_localization M S] :
set.range (comap (algebra_map R S)) = { p | disjoint (M : set R) p.as_ideal } :=
begin
ext x,
split,
{ rintro ⟨p, rfl⟩ x ⟨hx₁, hx₂⟩,
exact (p.2.1 : ¬ _)
(p.as_ideal.eq_top_of_is_unit_mem hx₂ (is_localization.map_units S ⟨x, hx₁⟩)) },
{ intro h,
use ⟨x.as_ideal.map (algebra_map R S),
is_localization.is_prime_of_is_prime_disjoint M S _ x.2 h⟩,
ext1,
exact is_localization.comap_map_of_is_prime_disjoint M S _ x.2 h }
end
end comap
section basic_open
/-- `basic_open r` is the open subset containing all prime ideals not containing `r`. -/
def basic_open (r : R) : topological_space.opens (prime_spectrum R) :=
{ val := { x | r ∉ x.as_ideal },
property := ⟨{r}, set.ext $ λ x, set.singleton_subset_iff.trans $ not_not.symm⟩ }
@[simp] lemma mem_basic_open (f : R) (x : prime_spectrum R) :
x ∈ basic_open f ↔ f ∉ x.as_ideal := iff.rfl
lemma is_open_basic_open {a : R} : is_open ((basic_open a) : set (prime_spectrum R)) :=
(basic_open a).property
@[simp] lemma basic_open_eq_zero_locus_compl (r : R) :
(basic_open r : set (prime_spectrum R)) = (zero_locus {r})ᶜ :=
set.ext $ λ x, by simpa only [set.mem_compl_eq, mem_zero_locus, set.singleton_subset_iff]
@[simp] lemma basic_open_one : basic_open (1 : R) = ⊤ :=
topological_space.opens.ext $ by simp
@[simp] lemma basic_open_zero : basic_open (0 : R) = ⊥ :=
topological_space.opens.ext $ by simp
lemma basic_open_le_basic_open_iff (f g : R) :
basic_open f ≤ basic_open g ↔ f ∈ (ideal.span ({g} : set R)).radical :=
by rw [topological_space.opens.le_def, basic_open_eq_zero_locus_compl,
basic_open_eq_zero_locus_compl, set.le_eq_subset, set.compl_subset_compl,
zero_locus_subset_zero_locus_singleton_iff]
lemma basic_open_mul (f g : R) : basic_open (f * g) = basic_open f ⊓ basic_open g :=
topological_space.opens.ext $ by {simp [zero_locus_singleton_mul]}
lemma basic_open_mul_le_left (f g : R) : basic_open (f * g) ≤ basic_open f :=
by { rw basic_open_mul f g, exact inf_le_left }
lemma basic_open_mul_le_right (f g : R) : basic_open (f * g) ≤ basic_open g :=
by { rw basic_open_mul f g, exact inf_le_right }
@[simp] lemma basic_open_pow (f : R) (n : ℕ) (hn : 0 < n) : basic_open (f ^ n) = basic_open f :=
topological_space.opens.ext $ by simpa using zero_locus_singleton_pow f n hn
lemma is_topological_basis_basic_opens : topological_space.is_topological_basis
(set.range (λ (r : R), (basic_open r : set (prime_spectrum R)))) :=
begin
apply topological_space.is_topological_basis_of_open_of_nhds,
{ rintros _ ⟨r, rfl⟩,
exact is_open_basic_open },
{ rintros p U hp ⟨s, hs⟩,
rw [← compl_compl U, set.mem_compl_eq, ← hs, mem_zero_locus, set.not_subset] at hp,
obtain ⟨f, hfs, hfp⟩ := hp,
refine ⟨basic_open f, ⟨f, rfl⟩, hfp, _⟩,
rw [← set.compl_subset_compl, ← hs, basic_open_eq_zero_locus_compl, compl_compl],
exact zero_locus_anti_mono (set.singleton_subset_iff.mpr hfs) }
end
lemma is_basis_basic_opens :
topological_space.opens.is_basis (set.range (@basic_open R _)) :=
begin
unfold topological_space.opens.is_basis,
convert is_topological_basis_basic_opens,
rw ← set.range_comp,
end
lemma is_compact_basic_open (f : R) : is_compact (basic_open f : set (prime_spectrum R)) :=
is_compact_of_finite_subfamily_closed $ λ ι Z hZc hZ,
begin
let I : ι → ideal R := λ i, vanishing_ideal (Z i),
have hI : ∀ i, Z i = zero_locus (I i) := λ i,
by simpa only [zero_locus_vanishing_ideal_eq_closure] using (hZc i).closure_eq.symm,
rw [basic_open_eq_zero_locus_compl f, set.inter_comm, ← set.diff_eq,
set.diff_eq_empty, funext hI, ← zero_locus_supr] at hZ,
obtain ⟨n, hn⟩ : f ∈ (⨆ (i : ι), I i).radical,
{ rw ← vanishing_ideal_zero_locus_eq_radical,
apply vanishing_ideal_anti_mono hZ,
exact (subset_vanishing_ideal_zero_locus {f} (set.mem_singleton f)) },
rcases submodule.exists_finset_of_mem_supr I hn with ⟨s, hs⟩,
use s,
-- Using simp_rw here, because `hI` and `zero_locus_supr` need to be applied underneath binders
simp_rw [basic_open_eq_zero_locus_compl f, set.inter_comm, ← set.diff_eq,
set.diff_eq_empty, hI, ← zero_locus_supr],
rw ← zero_locus_radical, -- this one can't be in `simp_rw` because it would loop
apply zero_locus_anti_mono,
rw set.singleton_subset_iff,
exact ⟨n, hs⟩
end
@[simp]
lemma basic_open_eq_bot_iff (f : R) :
basic_open f = ⊥ ↔ is_nilpotent f :=
begin
rw [← subtype.coe_injective.eq_iff, basic_open_eq_zero_locus_compl],
simp only [set.eq_univ_iff_forall, topological_space.opens.empty_eq, set.singleton_subset_iff,
topological_space.opens.coe_bot, nilpotent_iff_mem_prime, set.compl_empty_iff, mem_zero_locus,
set_like.mem_coe],
exact subtype.forall,
end
lemma localization_away_comap_range (S : Type v) [comm_ring S] [algebra R S] (r : R)
[is_localization.away r S] : set.range (comap (algebra_map R S)) = basic_open r :=
begin
rw localization_comap_range S (submonoid.powers r),
ext,
simp only [mem_zero_locus, basic_open_eq_zero_locus_compl, set_like.mem_coe, set.mem_set_of_eq,
set.singleton_subset_iff, set.mem_compl_eq],
split,
{ intros h₁ h₂,
exact h₁ ⟨submonoid.mem_powers r, h₂⟩ },
{ rintros h₁ _ ⟨⟨n, rfl⟩, h₃⟩,
exact h₁ (x.2.mem_of_pow_mem _ h₃) },
end
lemma localization_away_open_embedding (S : Type v) [comm_ring S] [algebra R S] (r : R)
[is_localization.away r S] : open_embedding (comap (algebra_map R S)) :=
{ to_embedding := localization_comap_embedding S (submonoid.powers r),
open_range := by { rw localization_away_comap_range S r, exact is_open_basic_open } }
end basic_open
/-- The prime spectrum of a commutative ring is a compact topological space. -/
instance : compact_space (prime_spectrum R) :=
{ compact_univ := by { convert is_compact_basic_open (1 : R), rw basic_open_one, refl } }
section order
/-!
## The specialization order
We endow `prime_spectrum R` with a partial order,
where `x ≤ y` if and only if `y ∈ closure {x}`.
TODO: maybe define sober topological spaces, and generalise this instance to those
-/
instance : partial_order (prime_spectrum R) :=
subtype.partial_order _
@[simp] lemma as_ideal_le_as_ideal (x y : prime_spectrum R) :
x.as_ideal ≤ y.as_ideal ↔ x ≤ y :=
subtype.coe_le_coe
@[simp] lemma as_ideal_lt_as_ideal (x y : prime_spectrum R) :
x.as_ideal < y.as_ideal ↔ x < y :=
subtype.coe_lt_coe
lemma le_iff_mem_closure (x y : prime_spectrum R) :
x ≤ y ↔ y ∈ closure ({x} : set (prime_spectrum R)) :=
by rw [← as_ideal_le_as_ideal, ← zero_locus_vanishing_ideal_eq_closure,
mem_zero_locus, vanishing_ideal_singleton, set_like.coe_subset_coe]
lemma le_iff_specializes (x y : prime_spectrum R) :
x ≤ y ↔ x ⤳ y :=
le_iff_mem_closure x y
instance : t0_space (prime_spectrum R) :=
by { simp [t0_space_iff_or_not_mem_closure, ← le_iff_mem_closure,
← not_and_distrib, ← le_antisymm_iff, eq_comm] }
end order
/-- If `x` specializes to `y`, then there is a natural map from the localization of `y` to
the localization of `x`. -/
def localization_map_of_specializes {x y : prime_spectrum R} (h : x ⤳ y) :
localization.at_prime y.as_ideal →+* localization.at_prime x.as_ideal :=
@is_localization.lift _ _ _ _ _ _ _ _ localization.is_localization (algebra_map R _)
begin
rintro ⟨a, ha⟩,
rw [← prime_spectrum.le_iff_specializes, ← as_ideal_le_as_ideal, ← set_like.coe_subset_coe,
← set.compl_subset_compl] at h,
exact (is_localization.map_units _ ⟨a, (show a ∈ x.as_ideal.prime_compl, from h ha)⟩ : _)
end
end prime_spectrum
namespace local_ring
variables (R) [local_ring R]
/--
The closed point in the prime spectrum of a local ring.
-/
def closed_point : prime_spectrum R :=
⟨maximal_ideal R, (maximal_ideal.is_maximal R).is_prime⟩
variable {R}
lemma is_local_ring_hom_iff_comap_closed_point {S : Type v} [comm_ring S] [local_ring S]
(f : R →+* S) : is_local_ring_hom f ↔ prime_spectrum.comap f (closed_point S) = closed_point R :=
by { rw [(local_hom_tfae f).out 0 4, subtype.ext_iff], refl }
@[simp] lemma comap_closed_point {S : Type v} [comm_ring S] [local_ring S] (f : R →+* S)
[is_local_ring_hom f] : prime_spectrum.comap f (closed_point S) = closed_point R :=
(is_local_ring_hom_iff_comap_closed_point f).mp infer_instance
end local_ring
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.