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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dc326eba568b2fc3799f14ed6b9b40d908081f20 | 2d2554d724f667419148b06acf724e2702ada7c9 | /src/definitions.lean | fa08d66deb41afc09e6e030531781d954bb8eab9 | [] | no_license | hediet/lean-linear-integer-equation-solver | 64591803a01d38dba8599c5bde3e88446a2dca28 | 1a83fa7935b4411618c4edcdee7edb5c4a6678a7 | refs/heads/master | 1,677,680,410,160 | 1,612,962,170,000 | 1,612,962,170,000 | 337,718,062 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,045 | lean | import data.bool
import data.int.gcd
def rdiv (as: list ℤ) (f: ℤ): list ℤ := as.map (λ a, a / f)
def rmul (as: list ℤ) (f: ℤ): list ℤ := as.map (λ a, a * f)
def smul (as bs: list ℤ): ℤ := ((as.zip bs).map (λ (t: ℤ × ℤ), t.1 * t.2)).foldr (+) 0
def gcd_list: list ℤ → ℕ
| [] := 0
| [x] := x.nat_abs
| (x :: xs) := nat.gcd x.nat_abs (gcd_list xs)
def xgcd_list: list ℤ → list ℤ
| [] := []
| [x] := [if x < 0 then -1 else 1]
| (x :: xs) :=
(if x < 0 then -1 else 1) * nat.gcd_a x.nat_abs (gcd_list xs)
:: rmul (xgcd_list xs) (nat.gcd_b x.nat_abs (gcd_list xs))
def to_subscript : char → char
| '0' := '₀'
| '1' := '₁'
| '2' := '₂'
| '3' := '₃'
| '4' := '₄'
| '5' := '₅'
| '6' := '₆'
| '7' := '₇'
| '8' := '₈'
| '9' := '₉'
| c := c
def repr_subscript : ℕ → string
| n := ((repr n).to_list.map to_subscript).as_string
structure Eq := mk :: (as : list ℤ) (c: ℤ)
instance : has_repr Eq :=
⟨ λ eq, (string.join ((eq.as.map_with_index (λ i a, repr a ++ "x" ++ repr_subscript i)).intersperse " + ")) ++ " = " ++ (repr eq.c) ⟩
instance : inhabited Eq :=
⟨ Eq.mk [] 0 ⟩
def Eq.is_solution (eq: Eq) (xs: list ℤ): bool :=
(xs.length = eq.as.length) && (smul eq.as xs = eq.c)
instance : has_mem (list ℤ) Eq := ⟨ λ s eq, eq.is_solution s ⟩
def Eq.has_solution (eq: Eq): bool := (gcd_list eq.as) ∣ eq.c.nat_abs
def Eq.get_solution (eq: Eq) : option (list ℤ) :=
if eq.has_solution
then some (rmul (xgcd_list eq.as) (if eq.c = 0 then 0 else (eq.c / gcd_list eq.as)))
else none
def Eq.mul (e: Eq) (f: ℤ) := Eq.mk (rmul e.as f) (e.c * f)
def Eq.div (e: Eq) (f: ℤ) := Eq.mk (rdiv e.as f) (e.c / f)
def Eq.add (e e2: Eq) := Eq.mk ((e.as.zip e2.as).map (λ ⟨ a, b ⟩, a + b )) (e.c + e2.c)
def Eq.remove_column (eq: Eq) (col: ℕ): Eq := Eq.mk (eq.as.remove_nth col) eq.c
def Eq.insert_column (eq: Eq): Eq := Eq.mk (0::eq.as) eq.c
def Eq.is_zero (e: Eq): bool := (e.as.all (=0)) && (e.c = 0)
def Eq.equiv (eq1 eq2: Eq): Prop := ∀ xs: list ℤ, xs ∈ eq1 ↔ xs ∈ eq2
structure Eqs := (dim: ℕ) (eqs : list Eq)
instance : has_repr Eqs :=
⟨ λ eqs, string.join ((eqs.eqs.map repr).intersperse "\n") ⟩
def Eqs.is_solution (e: Eqs) (xs: list ℤ): bool := (xs.length = e.dim) && e.eqs.all (λ eq, eq.is_solution xs)
def Eqs.from (eqs: list Eq): Eqs := ⟨ (eqs.head'.map (λ (h: Eq), h.as.length)).get_or_else 0, eqs ⟩
instance : has_mem (list ℤ) Eqs := ⟨ λ s eq, eq.is_solution s ⟩
def Eqs.equiv (e1 e2: Eqs): Prop := ∀ xs: list ℤ, xs ∈ e1 ↔ xs ∈ e2
def Eqs.indexed_coefficients (e: Eqs): list (ℤ × ℕ × ℕ) :=
(e.eqs.map_with_index (λ idx1 (eq: Eq),
eq.as.map_with_index (λ idx2 v, (v, idx1, idx2))
)).join
def Eqs.remove_column (eqs: Eqs) (col: ℕ): Eqs := Eqs.mk (eqs.dim - 1) (eqs.eqs.map (λ eq, eq.remove_column col))
def Eqs.insert_column (eqs: Eqs): Eqs := Eqs.mk (eqs.dim + 1) (eqs.eqs.map (λ eq, eq.insert_column))
def Eqs.cons_eq (e: Eqs) (eq: Eq): Eqs := Eqs.mk e.dim (eq::e.eqs)
|
b6cc79120f7bedfdbb0577105445aa0a54938ebb | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/topology/dense_embedding.lean | 4d7810b16d339f64b694f6ab864ef9d7d5dafa7a | [
"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 | 14,884 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import topology.separation
/-!
# Dense embeddings
This file defines three properties of functions:
`dense_range f` means `f` has dense image;
`dense_inducing i` means `i` is also `inducing`;
`dense_embedding e` means `e` is also an `embedding`.
The main theorem `continuous_extend` gives a criterion for a function
`f : X → Z` to a regular (T₃) space Z to extend along a dense embedding
`i : X → Y` to a continuous function `g : Y → Z`. Actually `i` only
has to be `dense_inducing` (not necessarily injective).
-/
noncomputable theory
open set filter lattice
open_locale classical topological_space
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
section dense_range
variables [topological_space β] [topological_space γ] (f : α → β) (g : β → γ)
/-- `f : α → β` has dense range if its range (image) is a dense subset of β. -/
def dense_range := ∀ x, x ∈ closure (range f)
variables {f}
lemma dense_range_iff_closure_range : dense_range f ↔ closure (range f) = univ :=
eq_univ_iff_forall.symm
lemma dense_range.closure_range (h : dense_range f) : closure (range f) = univ :=
eq_univ_iff_forall.mpr h
lemma dense_range.comp (hg : dense_range g) (hf : dense_range f) (cg : continuous g) :
dense_range (g ∘ f) :=
begin
have : g '' (closure $ range f) ⊆ closure (g '' range f),
from image_closure_subset_closure_image cg,
have : closure (g '' closure (range f)) ⊆ closure (g '' range f),
by simpa [closure_closure] using (closure_mono this),
intro c,
rw range_comp,
apply this,
rw [hf.closure_range, image_univ],
exact hg c
end
/-- If `f : α → β` has dense range and `β` contains some element, then `α` must too. -/
def dense_range.inhabited (df : dense_range f) (b : β) : inhabited α :=
⟨begin
have := exists_mem_of_ne_empty (mem_closure_iff.1 (df b) _ is_open_univ trivial),
simp only [mem_range, univ_inter] at this,
exact classical.some (classical.some_spec this),
end⟩
lemma dense_range.nonempty (hf : dense_range f) : nonempty α ↔ nonempty β :=
⟨nonempty.map f, λ ⟨b⟩, @nonempty_of_inhabited _ (hf.inhabited b)⟩
lemma dense_range.prod {ι : Type*} {κ : Type*} {f : ι → β} {g : κ → γ}
(hf : dense_range f) (hg : dense_range g) : dense_range (λ p : ι × κ, (f p.1, g p.2)) :=
have closure (range $ λ p : ι×κ, (f p.1, g p.2)) = set.prod (closure $ range f) (closure $ range g),
by rw [←closure_prod_eq, prod_range_range_eq],
assume ⟨b, d⟩, this.symm ▸ mem_prod.2 ⟨hf _, hg _⟩
end dense_range
/-- `i : α → β` is "dense inducing" if it has dense range and the topology on `α`
is the one induced by `i` from the topology on `β`. -/
structure dense_inducing [topological_space α] [topological_space β] (i : α → β)
extends inducing i : Prop :=
(dense : dense_range i)
namespace dense_inducing
variables [topological_space α] [topological_space β]
variables {i : α → β} (di : dense_inducing i)
lemma nhds_eq_comap (di : dense_inducing i) :
∀ a : α, 𝓝 a = comap i (𝓝 $ i a) :=
di.to_inducing.nhds_eq_comap
protected lemma continuous (di : dense_inducing i) : continuous i :=
di.to_inducing.continuous
lemma closure_range : closure (range i) = univ :=
di.dense.closure_range
lemma self_sub_closure_image_preimage_of_open {s : set β} (di : dense_inducing i) :
is_open s → s ⊆ closure (i '' (i ⁻¹' s)) :=
begin
intros s_op b b_in_s,
rw [image_preimage_eq_inter_range, mem_closure_iff],
intros U U_op b_in,
rw ←inter_assoc,
have ne_e : U ∩ s ≠ ∅ := ne_empty_of_mem ⟨b_in, b_in_s⟩,
exact (dense_iff_inter_open.1 di.closure_range) _ (is_open_inter U_op s_op) ne_e
end
lemma closure_image_nhds_of_nhds {s : set α} {a : α} (di : dense_inducing i) :
s ∈ 𝓝 a → closure (i '' s) ∈ 𝓝 (i a) :=
begin
rw [di.nhds_eq_comap a, mem_comap_sets],
intro h,
rcases h with ⟨t, t_nhd, sub⟩,
rw mem_nhds_sets_iff at t_nhd,
rcases t_nhd with ⟨U, U_sub, ⟨U_op, e_a_in_U⟩⟩,
have := calc i ⁻¹' U ⊆ i⁻¹' t : preimage_mono U_sub
... ⊆ s : sub,
have := calc U ⊆ closure (i '' (i ⁻¹' U)) : self_sub_closure_image_preimage_of_open di U_op
... ⊆ closure (i '' s) : closure_mono (image_subset i this),
have U_nhd : U ∈ 𝓝 (i a) := mem_nhds_sets U_op e_a_in_U,
exact (𝓝 (i a)).sets_of_superset U_nhd this
end
/-- The product of two dense inducings is a dense inducing -/
protected lemma prod [topological_space γ] [topological_space δ]
{e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_inducing e₁) (de₂ : dense_inducing e₂) :
dense_inducing (λ(p : α × γ), (e₁ p.1, e₂ p.2)) :=
{ induced := (de₁.to_inducing.prod_mk de₂.to_inducing).induced,
dense := de₁.dense.prod de₂.dense }
variables [topological_space δ] {f : γ → α} {g : γ → δ} {h : δ → β}
/--
γ -f→ α
g↓ ↓e
δ -h→ β
-/
lemma tendsto_comap_nhds_nhds {d : δ} {a : α} (di : dense_inducing i) (H : tendsto h (𝓝 d) (𝓝 (i a)))
(comm : h ∘ g = i ∘ f) : tendsto f (comap g (𝓝 d)) (𝓝 a) :=
begin
have lim1 : map g (comap g (𝓝 d)) ≤ 𝓝 d := map_comap_le,
replace lim1 : map h (map g (comap g (𝓝 d))) ≤ map h (𝓝 d) := map_mono lim1,
rw [filter.map_map, comm, ← filter.map_map, map_le_iff_le_comap] at lim1,
have lim2 : comap i (map h (𝓝 d)) ≤ comap i (𝓝 (i a)) := comap_mono H,
rw ← di.nhds_eq_comap at lim2,
exact le_trans lim1 lim2,
end
protected lemma nhds_inf_neq_bot (di : dense_inducing i) {b : β} : 𝓝 b ⊓ principal (range i) ≠ ⊥ :=
begin
convert di.dense b,
simp [closure_eq_nhds]
end
lemma comap_nhds_neq_bot (di : dense_inducing i) {b : β} : comap i (𝓝 b) ≠ ⊥ :=
forall_sets_neq_empty_iff_neq_bot.mp $
assume s ⟨t, ht, (hs : i ⁻¹' t ⊆ s)⟩,
have t ∩ range i ∈ 𝓝 b ⊓ principal (range i),
from inter_mem_inf_sets ht (subset.refl _),
let ⟨_, ⟨hx₁, y, rfl⟩⟩ := inhabited_of_mem_sets di.nhds_inf_neq_bot this in
subset_ne_empty hs $ ne_empty_of_mem hx₁
variables [topological_space γ]
/-- If `i : α → β` is a dense inducing, then any function `f : α → γ` "extends"
to a function `g = extend di f : β → γ`. If `γ` is Hausdorff and `f` has a
continuous extension, then `g` is the unique such extension. In general,
`g` might not be continuous or even extend `f`. -/
def extend (di : dense_inducing i) (f : α → γ) (b : β) : γ :=
@lim _ _ ⟨f (dense_range.inhabited di.dense b).default⟩ (map f (comap i (𝓝 b)))
lemma extend_eq [t2_space γ] {b : β} {c : γ} {f : α → γ} (hf : map f (comap i (𝓝 b)) ≤ 𝓝 c) :
di.extend f b = c :=
@lim_eq _ _ (id _) _ _ _ (by simp; exact comap_nhds_neq_bot di) hf
lemma extend_e_eq [t2_space γ] {f : α → γ} (a : α) (hf : continuous_at f a) :
di.extend f (i a) = f a :=
extend_eq _ $ di.nhds_eq_comap a ▸ hf
lemma extend_eq_of_cont [t2_space γ] {f : α → γ} (hf : continuous f) (a : α) :
di.extend f (i a) = f a :=
di.extend_e_eq a (continuous_iff_continuous_at.1 hf a)
lemma tendsto_extend [regular_space γ] {b : β} {f : α → γ} (di : dense_inducing i)
(hf : {b | ∃c, tendsto f (comap i $ 𝓝 b) (𝓝 c)} ∈ 𝓝 b) :
tendsto (di.extend f) (𝓝 b) (𝓝 (di.extend f b)) :=
let φ := {b | tendsto f (comap i $ 𝓝 b) (𝓝 $ di.extend f b)} in
have hφ : φ ∈ 𝓝 b,
from (𝓝 b).sets_of_superset hf $ assume b ⟨c, hc⟩,
show tendsto f (comap i (𝓝 b)) (𝓝 (di.extend f b)), from (di.extend_eq hc).symm ▸ hc,
assume s hs,
let ⟨s'', hs''₁, hs''₂, hs''₃⟩ := nhds_is_closed hs in
let ⟨s', hs'₁, (hs'₂ : i ⁻¹' s' ⊆ f ⁻¹' s'')⟩ := mem_of_nhds hφ hs''₁ in
let ⟨t, (ht₁ : t ⊆ φ ∩ s'), ht₂, ht₃⟩ := mem_nhds_sets_iff.mp $ inter_mem_sets hφ hs'₁ in
have h₁ : closure (f '' (i ⁻¹' s')) ⊆ s'',
by rw [closure_subset_iff_subset_of_is_closed hs''₃, image_subset_iff]; exact hs'₂,
have h₂ : t ⊆ di.extend f ⁻¹' closure (f '' (i ⁻¹' t)), from
assume b' hb',
have 𝓝 b' ≤ principal t, by simp; exact mem_nhds_sets ht₂ hb',
have map f (comap i (𝓝 b')) ≤ 𝓝 (di.extend f b') ⊓ principal (f '' (i ⁻¹' t)),
from calc _ ≤ map f (comap i (𝓝 b' ⊓ principal t)) : map_mono $ comap_mono $ le_inf (le_refl _) this
... ≤ map f (comap i (𝓝 b')) ⊓ map f (comap i (principal t)) :
le_inf (map_mono $ comap_mono $ inf_le_left) (map_mono $ comap_mono $ inf_le_right)
... ≤ map f (comap i (𝓝 b')) ⊓ principal (f '' (i ⁻¹' t)) : by simp [le_refl]
... ≤ _ : inf_le_inf ((ht₁ hb').left) (le_refl _),
show di.extend f b' ∈ closure (f '' (i ⁻¹' t)),
begin
rw [closure_eq_nhds],
apply neq_bot_of_le_neq_bot _ this,
simp,
exact di.comap_nhds_neq_bot
end,
(𝓝 b).sets_of_superset
(show t ∈ 𝓝 b, from mem_nhds_sets ht₂ ht₃)
(calc t ⊆ di.extend f ⁻¹' closure (f '' (i ⁻¹' t)) : h₂
... ⊆ di.extend f ⁻¹' closure (f '' (i ⁻¹' s')) :
preimage_mono $ closure_mono $ image_subset f $ preimage_mono $ subset.trans ht₁ $ inter_subset_right _ _
... ⊆ di.extend f ⁻¹' s'' : preimage_mono h₁
... ⊆ di.extend f ⁻¹' s : preimage_mono hs''₂)
lemma continuous_extend [regular_space γ] {f : α → γ} (di : dense_inducing i)
(hf : ∀b, ∃c, tendsto f (comap i (𝓝 b)) (𝓝 c)) : continuous (di.extend f) :=
continuous_iff_continuous_at.mpr $ assume b, di.tendsto_extend $ univ_mem_sets' hf
lemma mk'
(i : α → β)
(c : continuous i)
(dense : ∀x, x ∈ closure (range i))
(H : ∀ (a:α) s ∈ 𝓝 a,
∃t ∈ 𝓝 (i a), ∀ b, i b ∈ t → b ∈ s) :
dense_inducing i :=
{ induced := (induced_iff_nhds_eq i).2 $
λ a, le_antisymm (tendsto_iff_comap.1 $ c.tendsto _) (by simpa [le_def] using H a),
dense := dense }
end dense_inducing
/-- A dense embedding is an embedding with dense image. -/
structure dense_embedding [topological_space α] [topological_space β] (e : α → β)
extends dense_inducing e : Prop :=
(inj : function.injective e)
theorem dense_embedding.mk'
[topological_space α] [topological_space β] (e : α → β)
(c : continuous e)
(dense : ∀x, x ∈ closure (range e))
(inj : function.injective e)
(H : ∀ (a:α) s ∈ 𝓝 a,
∃t ∈ 𝓝 (e a), ∀ b, e b ∈ t → b ∈ s) :
dense_embedding e :=
{ inj := inj,
..dense_inducing.mk' e c dense H}
namespace dense_embedding
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
variables {e : α → β} (de : dense_embedding e)
lemma inj_iff {x y} : e x = e y ↔ x = y := de.inj.eq_iff
lemma to_embedding : embedding e :=
{ induced := de.induced,
inj := de.inj }
/-- The product of two dense embeddings is a dense embedding -/
protected lemma prod {e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_embedding e₁) (de₂ : dense_embedding e₂) :
dense_embedding (λ(p : α × γ), (e₁ p.1, e₂ p.2)) :=
{ inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩,
by simp; exact assume h₁ h₂, ⟨de₁.inj h₁, de₂.inj h₂⟩,
..dense_inducing.prod de₁.to_dense_inducing de₂.to_dense_inducing }
/-- The dense embedding of a subtype inside its closure. -/
def subtype_emb {α : Type*} (p : α → Prop) (e : α → β) (x : {x // p x}) :
{x // x ∈ closure (e '' {x | p x})} :=
⟨e x.1, subset_closure $ mem_image_of_mem e x.2⟩
protected lemma subtype (p : α → Prop) : dense_embedding (subtype_emb p e) :=
{ dense_embedding .
dense := assume ⟨x, hx⟩, closure_subtype.mpr $
have (λ (x : {x // p x}), e (x.val)) = e ∘ subtype.val, from rfl,
begin
rw ← image_univ,
simp [(image_comp _ _ _).symm, (∘), subtype_emb, -image_univ],
rw [this, image_comp, subtype.val_image],
simp,
assumption
end,
inj := assume ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq $ de.inj $ @@congr_arg subtype.val h,
induced := (induced_iff_nhds_eq _).2 (assume ⟨x, hx⟩,
by simp [subtype_emb, nhds_subtype_eq_comap, de.to_inducing.nhds_eq_comap, comap_comap_comp, (∘)]) }
end dense_embedding
lemma is_closed_property [topological_space β] {e : α → β} {p : β → Prop}
(he : dense_range e) (hp : is_closed {x | p x}) (h : ∀a, p (e a)) :
∀b, p b :=
have univ ⊆ {b | p b},
from calc univ = closure (range e) : he.closure_range.symm
... ⊆ closure {b | p b} : closure_mono $ range_subset_iff.mpr h
... = _ : closure_eq_of_is_closed hp,
assume b, this trivial
lemma is_closed_property2 [topological_space β] {e : α → β} {p : β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂)) :
∀b₁ b₂, p b₁ b₂ :=
have ∀q:β×β, p q.1 q.2,
from is_closed_property (he.prod he) hp $ λ _, h _ _,
assume b₁ b₂, this ⟨b₁, b₂⟩
lemma is_closed_property3 [topological_space β] {e : α → β} {p : β → β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) :
∀b₁ b₂ b₃, p b₁ b₂ b₃ :=
have ∀q:β×β×β, p q.1 q.2.1 q.2.2,
from is_closed_property (he.prod $ he.prod he) hp $ λ _, h _ _ _,
assume b₁ b₂ b₃, this ⟨b₁, b₂, b₃⟩
@[elab_as_eliminator]
lemma dense_range.induction_on [topological_space β] {e : α → β} (he : dense_range e) {p : β → Prop}
(b₀ : β) (hp : is_closed {b | p b}) (ih : ∀a:α, p $ e a) : p b₀ :=
is_closed_property he hp ih b₀
@[elab_as_eliminator]
lemma dense_range.induction_on₂ [topological_space β] {e : α → β} {p : β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂))
(b₁ b₂ : β) : p b₁ b₂ := is_closed_property2 he hp h _ _
@[elab_as_eliminator]
lemma dense_range.induction_on₃ [topological_space β] {e : α → β} {p : β → β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃))
(b₁ b₂ b₃ : β) : p b₁ b₂ b₃ := is_closed_property3 he hp h _ _ _
section
variables [topological_space β] [topological_space γ] [t2_space γ]
variables {f : α → β}
/-- Two continuous functions to a t2-space that agree on the dense range of a function are equal. -/
lemma dense_range.equalizer (hfd : dense_range f)
{g h : β → γ} (hg : continuous g) (hh : continuous h) (H : g ∘ f = h ∘ f) :
g = h :=
funext $ λ y, hfd.induction_on y (is_closed_eq hg hh) $ congr_fun H
end
|
6861a58f60ce98568875d93eed6f730a8af04b86 | e39f04f6ff425fe3b3f5e26a8998b817d1dba80f | /algebra/big_operators.lean | b8502595611471d0b5519ec022f6d4e2cc5491df | [
"Apache-2.0"
] | permissive | kristychoi/mathlib | c504b5e8f84e272ea1d8966693c42de7523bf0ec | 257fd84fe98927ff4a5ffe044f68c4e9d235cc75 | refs/heads/master | 1,586,520,722,896 | 1,544,030,145,000 | 1,544,031,933,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 27,659 | 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
Some big operators for lists and finite sets.
-/
import data.list.basic data.list.perm data.finset
import algebra.group algebra.ordered_group algebra.group_power
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₂)⟩
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
/-- `prod s f` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/
@[to_additive finset.sum]
protected def prod [comm_monoid β] (s : finset α) (f : α → β) : β := (s.1.map f).prod
attribute [to_additive finset.sum.equations._eqn_1] finset.prod.equations._eqn_1
@[to_additive finset.sum_eq_fold]
theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) : s.prod f = s.fold (*) 1 f := rfl
section comm_monoid
variables [comm_monoid β]
@[simp, to_additive finset.sum_empty]
lemma prod_empty {α : Type u} {f : α → β} : (∅:finset α).prod f = 1 := rfl
@[simp, to_additive finset.sum_insert]
lemma prod_insert [decidable_eq α] : a ∉ s → (insert a s).prod f = f a * s.prod f := fold_insert
@[simp, to_additive finset.sum_singleton]
lemma prod_singleton : (singleton a).prod f = f a :=
eq.trans fold_singleton $ mul_one _
@[simp] lemma prod_const_one : s.prod (λx, (1 : β)) = 1 :=
by simp only [finset.prod, multiset.map_const, multiset.prod_repeat, one_pow]
@[simp] lemma sum_const_zero {β} {s : finset α} [add_comm_monoid β] : s.sum (λx, (0 : β)) = 0 :=
@prod_const_one _ (multiplicative β) _ _
attribute [to_additive finset.sum_const_zero] prod_const_one
@[simp, to_additive finset.sum_image]
lemma prod_image [decidable_eq α] {s : finset γ} {g : γ → α} :
(∀x∈s, ∀y∈s, g x = g y → x = y) → (s.image g).prod f = s.prod (λx, f (g x)) :=
fold_image
@[congr, to_additive finset.sum_congr]
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 finset.sum_union_inter]
lemma prod_union_inter [decidable_eq α] : (s₁ ∪ s₂).prod f * (s₁ ∩ s₂).prod f = s₁.prod f * s₂.prod f :=
fold_union_inter
@[to_additive finset.sum_union]
lemma prod_union [decidable_eq α] (h : s₁ ∩ s₂ = ∅) : (s₁ ∪ s₂).prod f = s₁.prod f * s₂.prod f :=
by rw [←prod_union_inter, h]; exact (mul_one _).symm
@[to_additive finset.sum_sdiff]
lemma prod_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) : (s₂ \ s₁).prod f * s₁.prod f = s₂.prod f :=
by rw [←prod_union (sdiff_inter_self _ _), sdiff_union_of_subset h]
@[to_additive finset.sum_bind]
lemma prod_bind [decidable_eq α] {s : finset γ} {t : γ → finset α} :
(∀x∈s, ∀y∈s, x ≠ y → t x ∩ t y = ∅) → (s.bind t).prod f = s.prod (λx, (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 → t x ∩ t y = ∅,
from assume _ hx _ hy, hd _ (mem_insert_of_mem hx) _ (mem_insert_of_mem hy),
have t x ∩ finset.bind s t = ∅,
from eq_empty_of_forall_not_mem $ assume a,
by rw [mem_inter, mem_bind];
rintro ⟨h₁, y, hys, hy₂⟩;
exact eq_empty_iff_forall_not_mem.1
(hd _ (mem_insert_self _ _) _ (mem_insert_of_mem hys) (assume h, hxs (h.symm ▸ hys)))
_ (mem_inter_of_mem h₁ hy₂),
by simp only [bind_insert, prod_insert hxs, prod_union this, ih hd'])
@[to_additive finset.sum_product]
lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
(s.product t).prod f = s.prod (λx, t.prod $ λy, f (x, y)) :=
begin
haveI := classical.dec_eq α, haveI := classical.dec_eq γ,
rw [product_eq_bind, prod_bind (λ x hx y hy h, eq_empty_of_forall_not_mem _)],
{ congr, funext, exact prod_image (λ _ _ _ _ H, (prod.mk.inj H).2) },
simp only [mem_inter, mem_image], rintro ⟨_, _⟩ ⟨⟨_, _, _⟩, ⟨_, _, _⟩⟩, apply h, cc
end
@[to_additive finset.sum_sigma]
lemma prod_sigma {σ : α → Type*}
{s : finset α} {t : Πa, finset (σ a)} {f : sigma σ → β} :
(s.sigma t).prod f = s.prod (λa, (t a).prod $ λs, 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, eq_empty_of_forall_not_mem $
by simp only [mem_inter, 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 finset.sum_image']
lemma prod_image' [decidable_eq α] {s : finset γ} {g : γ → α} (h : γ → β)
(eq : ∀c∈s, f (g c) = (s.filter (λc', g c' = g c)).prod h) :
(s.image g).prod f = s.prod h :=
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_inter_eq_empty.1 (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 finset.sum_add_distrib]
lemma prod_mul_distrib : s.prod (λx, f x * g x) = s.prod f * s.prod g :=
eq.trans (by rw one_mul; refl) fold_op_distrib
@[to_additive finset.sum_comm]
lemma prod_comm [decidable_eq γ] {s : finset γ} {t : finset α} {f : γ → α → β} :
s.prod (λx, t.prod $ f x) = t.prod (λy, s.prod $ λx, f x y) :=
finset.induction_on s (by simp only [prod_empty, prod_const_one]) $
λ _ _ H ih, by simp only [prod_insert H, prod_mul_distrib, ih]
@[to_additive finset.sum_hom]
lemma prod_hom [comm_monoid γ] (g : β → γ)
(h₁ : g 1 = 1) (h₂ : ∀x y, g (x * y) = g x * g y) : s.prod (λx, g (f x)) = g (s.prod f) :=
eq.trans (by rw [h₁]; refl) (fold_hom h₂)
@[to_additive finset.sum_hom_rel]
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 (s.prod f) (s.prod g) :=
begin
letI := classical.dec_eq α,
refine finset.induction_on s h₁ (assume a s has ih, _),
rw [prod_insert has, prod_insert has],
exact h₂ a (s.prod f) (s.prod g) ih,
end
@[to_additive finset.sum_subset]
lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → f x = 1) : s₁.prod f = s₂.prod f :=
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]
@[to_additive finset.sum_eq_single]
lemma prod_eq_single {s : finset α} {f : α → β} (a : α)
(h₀ : ∀b∈s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : s.prod f = f a :=
by haveI := classical.dec_eq α;
from classical.by_cases
(assume : a ∈ s,
calc s.prod f = ({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 finset.sum_attach]
lemma prod_attach {f : α → β} : s.attach.prod (λx, f x.val) = s.prod f :=
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 finset.sum_bij]
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) :
s.prod f = t.prod g :=
by haveI := classical.prop_decidable; exact
calc s.prod f = s.attach.prod (λx, f x.val) : prod_attach.symm
... = s.attach.prod (λx, g (i x.1 x.2)) : prod_congr rfl $ assume x hx, h _ _
... = (s.attach.image $ λx:{x // x ∈ s}, i x.1 x.2).prod g :
(prod_image $ assume (a₁:{x // x ∈ s}) _ a₂ _ eq, subtype.eq $ i_inj a₁.1 a₂.1 a₁.2 a₂.2 eq).symm
... = t.prod g :
prod_subset
(by simp only [subset_iff, mem_image, mem_attach]; rintro _ ⟨⟨_, _⟩, _, rfl⟩; solve_by_elim)
(assume b hb hb1, false.elim $ hb1 $ by rcases i_surj b hb with ⟨a, ha, rfl⟩;
exact mem_image.2 ⟨⟨_, _⟩, mem_attach _ _, rfl⟩)
@[to_additive finset.sum_bij_ne_zero]
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₂)) :
s.prod f = t.prod g :=
by haveI := classical.prop_decidable; exact
calc s.prod f = (s.filter $ λx, f x ≠ 1).prod f :
(prod_subset (filter_subset _) $ by simp only [not_imp_comm, mem_filter]; exact λ _, and.intro).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⟩)
... = t.prod g :
(prod_subset (filter_subset _) $ by simp only [not_imp_comm, mem_filter]; exact λ _, and.intro)
@[to_additive finset.exists_ne_zero_of_sum_ne_zero]
lemma exists_ne_one_of_prod_ne_one : s.prod f ≠ 1 → ∃a∈s, f a ≠ 1 :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (λ H, (H rfl).elim) (assume a s has ih h,
classical.by_cases
(assume ha : f a = 1,
let ⟨a, ha, hfa⟩ := ih (by rwa [prod_insert has, ha, one_mul] at h) in
⟨a, mem_insert_of_mem ha, hfa⟩)
(assume hna : f a ≠ 1,
⟨a, mem_insert_self _ _, hna⟩))
@[to_additive finset.sum_range_succ]
lemma prod_range_succ (f : ℕ → β) (n : ℕ) :
(range (nat.succ n)).prod f = f n * (range n).prod f :=
by rw [range_succ, prod_insert not_mem_range_self]
lemma prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (range (nat.succ n)).prod f = (range n).prod (f ∘ nat.succ) * 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 _ _
@[simp] lemma prod_const (b : β) : s.prod (λ a, 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 : α → β) :
s.prod (λ x, f x ^ n) = s.prod f ^ 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 : α → ℕ) :
s.prod (λ x, f x ^ n) = s.prod f ^ n :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (by simp [nat.mul_pow] {contextual := tt})
@[to_additive finset.sum_involution]
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),
s.prod f = 1 :=
by haveI := classical.dec_eq α;
haveI := classical.dec_eq β; exact
finset.strong_induction_on s
(λ s ih g h₁ h₂ h₃ h₄,
if hs : s = ∅ then hs.symm ▸ rfl
else let ⟨x, hx⟩ := exists_mem_of_ne_empty hs in
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])
@[to_additive finset.sum_eq_zero]
lemma prod_eq_one [comm_monoid β] {f : α → β} {s : finset α} (h : ∀x∈s, f x = 1) : s.prod f = 1 :=
calc s.prod f = s.prod (λx, 1) : finset.prod_congr rfl h
... = 1 : finset.prod_const_one
end comm_monoid
lemma sum_smul [add_comm_monoid β] (s : finset α) (n : ℕ) (f : α → β) :
s.sum (λ x, add_monoid.smul n (f x)) = add_monoid.smul n (s.sum f) :=
@prod_pow _ (multiplicative β) _ _ _ _
attribute [to_additive finset.sum_smul] prod_pow
@[simp] lemma sum_const [add_comm_monoid β] (b : β) :
s.sum (λ a, b) = add_monoid.smul s.card b :=
@prod_const _ (multiplicative β) _ _ _
attribute [to_additive finset.sum_const] prod_const
lemma sum_range_succ' [add_comm_monoid β] (f : ℕ → β) :
∀ n : ℕ, (range (nat.succ n)).sum f = (range n).sum (f ∘ nat.succ) + f 0 :=
@prod_range_succ' (multiplicative β) _ _
attribute [to_additive finset.sum_range_succ'] prod_range_succ'
lemma sum_nat_cast [add_comm_monoid β] [has_one β] (s : finset α) (f : α → ℕ) :
↑(s.sum f) = s.sum (λa, f a : α → β) :=
(sum_hom _ nat.cast_zero nat.cast_add).symm
section comm_group
variables [comm_group β]
@[simp, to_additive finset.sum_neg_distrib]
lemma prod_inv_distrib : s.prod (λx, (f x)⁻¹) = (s.prod f)⁻¹ :=
prod_hom has_inv.inv one_inv mul_inv
end comm_group
@[simp] theorem card_sigma {σ : α → Type*} (s : finset α) (t : Π a, finset (σ a)) :
card (s.sigma t) = s.sum (λ a, card (t a)) :=
multiset.card_sigma _ _
lemma card_bind [decidable_eq β] {s : finset α} {t : α → finset β}
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → t x ∩ t y = ∅) :
(s.bind t).card = s.sum (λ u, 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 ≤ s.sum (λ a, (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 _)
lemma gsmul_sum [add_comm_group β] {f : α → β} {s : finset α} (z : ℤ) :
gsmul z (s.sum f) = s.sum (λa, gsmul z (f a)) :=
begin
refine (finset.sum_hom (gsmul z) _ _).symm,
exact gsmul_zero _,
assume x y, exact gsmul_add _ _ _
end
end finset
namespace finset
variables {s s₁ s₂ : finset α} {f g : α → β} {b : β} {a : α}
@[simp] lemma sum_sub_distrib [add_comm_group β] : s.sum (λx, f x - g x) = s.sum f - s.sum g :=
sum_add_distrib.trans $ congr_arg _ sum_neg_distrib
section ordered_cancel_comm_monoid
variables [decidable_eq α] [ordered_cancel_comm_monoid β]
lemma sum_le_sum : (∀x∈s, f x ≤ g x) → s.sum f ≤ s.sum g :=
finset.induction_on s (λ _, le_refl _) $ assume a s ha ih h,
have f a + s.sum f ≤ g a + s.sum g,
from add_le_add (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simpa only [sum_insert ha]
lemma zero_le_sum (h : ∀x∈s, 0 ≤ f x) : 0 ≤ s.sum f := le_trans (by rw [sum_const_zero]) (sum_le_sum h)
lemma sum_le_zero (h : ∀x∈s, f x ≤ 0) : s.sum f ≤ 0 := le_trans (sum_le_sum h) (by rw [sum_const_zero])
end ordered_cancel_comm_monoid
section semiring
variables [semiring β]
lemma sum_mul : s.sum f * b = s.sum (λx, f x * b) :=
(sum_hom (λx, x * b) (zero_mul b) (assume a c, add_mul a c b)).symm
lemma mul_sum : b * s.sum f = s.sum (λx, b * f x) :=
(sum_hom (λx, b * x) (mul_zero b) (assume a c, mul_add b a c)).symm
end semiring
section comm_semiring
variables [decidable_eq α] [comm_semiring β]
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : s.prod f = 0 :=
calc s.prod f = (insert a (erase s a)).prod f : by rw insert_erase ha
... = 0 : by rw [prod_insert (not_mem_erase _ _), h, zero_mul]
lemma prod_sum {δ : α → Type*} [∀a, decidable_eq (δ a)]
{s : finset α} {t : Πa, finset (δ a)} {f : Πa, δ a → β} :
s.prod (λa, (t a).sum (λb, f a b)) =
(s.pi t).sum (λp, s.attach.prod (λx, 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,
image (pi.cons s a x) (pi s t) ∩ image (pi.cons s a y) (pi s t) = ∅,
{ assume x hx y hy h,
apply eq_empty_of_forall_not_mem,
simp only [mem_inter, mem_image],
rintro p₁ ⟨⟨p₂, hp, eq⟩, ⟨p₃, hp₃, rfl⟩⟩,
have : pi.cons s a x p₂ a (mem_insert_self _ _) = pi.cons s a y p₃ a (mem_insert_self _ _),
{ rw [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
end comm_semiring
section integral_domain /- add integral_semi_domain to support nat and ennreal -/
variables [decidable_eq α] [integral_domain β]
lemma prod_eq_zero_iff : s.prod f = 0 ↔ (∃a∈s, f a = 0) :=
finset.induction_on s ⟨not.elim one_ne_zero, λ ⟨_, H, _⟩, H.elim⟩ $ λ a s ha ih,
by rw [prod_insert ha, mul_eq_zero_iff_eq_zero_or_eq_zero,
bex_def, exists_mem_insert, ih, ← bex_def]
end integral_domain
section ordered_comm_monoid
variables [decidable_eq α] [ordered_comm_monoid β]
lemma sum_le_sum' : (∀x∈s, f x ≤ g x) → s.sum f ≤ s.sum g :=
finset.induction_on s (λ _, le_refl _) $ assume a s ha ih h,
have f a + s.sum f ≤ g a + s.sum g,
from add_le_add' (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simpa only [sum_insert ha]
lemma zero_le_sum' (h : ∀x∈s, 0 ≤ f x) : 0 ≤ s.sum f := le_trans (by rw [sum_const_zero]) (sum_le_sum' h)
lemma sum_le_zero' (h : ∀x∈s, f x ≤ 0) : s.sum f ≤ 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) : s₁.sum f ≤ s₂.sum f :=
calc s₁.sum f ≤ (s₂ \ s₁).sum f + s₁.sum f :
le_add_of_nonneg_left' $ zero_le_sum' $ by simpa only [mem_sdiff, and_imp]
... = (s₂ \ s₁ ∪ s₁).sum f : (sum_union (sdiff_inter_self _ _)).symm
... = s₂.sum f : by rw [sdiff_union_of_subset h]
lemma sum_eq_zero_iff_of_nonneg : (∀x∈s, 0 ≤ f x) → (s.sum f = 0 ↔ ∀x∈s, f x = 0) :=
finset.induction_on s (λ _, ⟨λ _ _, false.elim, λ _, rfl⟩) $ λ a s ha ih H,
have ∀ x ∈ s, 0 ≤ f x, from λ _, H _ ∘ mem_insert_of_mem,
by rw [sum_insert ha,
add_eq_zero_iff' (H _ $ mem_insert_self _ _) (zero_le_sum' this),
forall_mem_insert, ih this]
lemma single_le_sum (hf : ∀x∈s, 0 ≤ f x) {a} (h : a ∈ s) : f a ≤ s.sum f :=
have (singleton a).sum f ≤ s.sum f,
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_comm_monoid
section canonically_ordered_monoid
variables [decidable_eq α] [canonically_ordered_monoid β] [@decidable_rel β (≤)]
lemma sum_le_sum_of_subset (h : s₁ ⊆ s₂) : s₁.sum f ≤ s₂.sum f :=
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₂) : s₁.sum f ≤ s₂.sum f :=
calc s₁.sum f = (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]; apply filter_inter_filter_neg_eq
... ≤ s₂.sum f : add_le_of_nonpos_of_le'
(sum_le_zero' $ 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_monoid
section discrete_linear_ordered_field
variables [discrete_linear_ordered_field α] [decidable_eq β]
lemma abs_sum_le_sum_abs {f : β → α} {s : finset β} : abs (s.sum f) ≤ s.sum (λa, abs (f a)) :=
finset.induction_on s (le_of_eq abs_zero) $
assume a s has ih,
calc abs (sum (insert a s) f) ≤ abs (f a) + abs (sum s f) :
by rw sum_insert has; exact abs_add_le_abs_add_abs _ _
... ≤ abs (f a) + s.sum (λa, abs (f a)) : add_le_add (le_refl _) ih
... ≤ sum (insert a s) (λ (a : β), abs (f a)) : by rw sum_insert has
end discrete_linear_ordered_field
@[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 _ _
@[simp] lemma prod_range_id_eq_fact (n : ℕ) : ((range n.succ).erase 0).prod (λ x, x) = nat.fact n :=
calc ((range n.succ).erase 0).prod (λ x, x) = (range n).prod nat.succ :
eq.symm (prod_bij (λ x _, nat.succ x)
(λ a h₁, mem_erase.2 ⟨nat.succ_ne_zero _, mem_range.2 $ nat.succ_lt_succ $ by simpa using h₁⟩)
(by simp) (λ _ _ _ _, nat.succ_inj)
(λ b h,
have b.pred.succ = b, from nat.succ_pred_eq_of_pos $
by simp [nat.pos_iff_ne_zero] at *; tauto,
⟨nat.pred b, mem_range.2 $ nat.lt_of_succ_lt_succ (by simp [*] at *), this.symm⟩))
... = nat.fact n : by induction n; simp [*, range_succ]
end finset
section group
open list
variables [group α] [group β]
@[to_additive is_add_group_hom.sum]
theorem is_group_hom.prod (f : α → β) [is_group_hom f] (l : list α) :
f (prod l) = prod (map f l) :=
by induction l; simp only [*, is_group_hom.mul f, is_group_hom.one f, prod_nil, prod_cons, map]
theorem is_group_anti_hom.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.one f,
simp only [prod_cons, is_group_anti_hom.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.prod _ _ _ _ _ inv_is_group_anti_hom l -- TODO there is probably a cleaner proof of this
end group
section comm_group
variables [comm_group α] [comm_group β] (f : α → β) [is_group_hom f]
@[to_additive is_add_group_hom.multiset_sum]
lemma is_group_hom.multiset_prod (m : multiset α) : f m.prod = (m.map f).prod :=
quotient.induction_on m $ assume l, by simp [is_group_hom.prod f l]
@[to_additive is_add_group_hom.finset_sum]
lemma is_group_hom.finset_prod (g : γ → α) (s : finset γ) : f (s.prod g) = s.prod (f ∘ g) :=
show f (s.val.map g).prod = (s.val.map (f ∘ g)).prod, by rw [is_group_hom.multiset_prod f]; simp
end comm_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, s.prod (λc, f c a)) :=
⟨assume a b, by simp only [λc, is_group_hom.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 α) :
s.to_finset.sum (λa, s.count a) = s.card :=
multiset.induction_on s rfl
(assume a s ih,
calc (to_finset (a :: s)).sum (λx, 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
|
1e3725ea288c4deb7efb3040d23626886eca1342 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/tactic/linarith.lean | 643b53d07472ab5bdc954557c7944055436a99f8 | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 35,581 | 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
-/
import tactic.ring data.nat.gcd data.list.defs meta.rb_map data.tree
/-!
# `linarith`
A tactic for discharging linear arithmetic goals using Fourier-Motzkin elimination.
`linarith` is (in principle) complete for ℚ and ℝ. It is not complete for non-dense orders, i.e. ℤ.
- @TODO: investigate storing comparisons in a list instead of a set, for possible efficiency gains
- @TODO: delay proofs of denominator normalization and nat casting until after contradiction is
found
-/
meta def nat.to_pexpr : ℕ → pexpr
| 0 := ``(0)
| 1 := ``(1)
| n := if n % 2 = 0 then ``(bit0 %%(nat.to_pexpr (n/2))) else ``(bit1 %%(nat.to_pexpr (n/2)))
open native
namespace linarith
section lemmas
lemma int.coe_nat_bit0 (n : ℕ) : (↑(bit0 n : ℕ) : ℤ) = bit0 (↑n : ℤ) := by simp [bit0]
lemma int.coe_nat_bit1 (n : ℕ) : (↑(bit1 n : ℕ) : ℤ) = bit1 (↑n : ℤ) := by simp [bit1, bit0]
lemma int.coe_nat_bit0_mul (n : ℕ) (x : ℕ) : (↑(bit0 n * x) : ℤ) = (↑(bit0 n) : ℤ) * (↑x : ℤ) := by simp
lemma int.coe_nat_bit1_mul (n : ℕ) (x : ℕ) : (↑(bit1 n * x) : ℤ) = (↑(bit1 n) : ℤ) * (↑x : ℤ) := by simp
lemma int.coe_nat_one_mul (x : ℕ) : (↑(1 * x) : ℤ) = 1 * (↑x : ℤ) := by simp
lemma int.coe_nat_zero_mul (x : ℕ) : (↑(0 * x) : ℤ) = 0 * (↑x : ℤ) := by simp
lemma int.coe_nat_mul_bit0 (n : ℕ) (x : ℕ) : (↑(x * bit0 n) : ℤ) = (↑x : ℤ) * (↑(bit0 n) : ℤ) := by simp
lemma int.coe_nat_mul_bit1 (n : ℕ) (x : ℕ) : (↑(x * bit1 n) : ℤ) = (↑x : ℤ) * (↑(bit1 n) : ℤ) := by simp
lemma int.coe_nat_mul_one (x : ℕ) : (↑(x * 1) : ℤ) = (↑x : ℤ) * 1 := by simp
lemma int.coe_nat_mul_zero (x : ℕ) : (↑(x * 0) : ℤ) = (↑x : ℤ) * 0 := by simp
lemma nat_eq_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 = n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 = z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_eq_coe_nat_iff]
lemma nat_le_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 ≤ n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 ≤ z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_le]
lemma nat_lt_subst {n1 n2 : ℕ} {z1 z2 : ℤ} (hn : n1 < n2) (h1 : ↑n1 = z1) (h2 : ↑n2 = z2) : z1 < z2 :=
by simpa [eq.symm h1, eq.symm h2, int.coe_nat_lt]
lemma eq_of_eq_of_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b = 0) : a + b = 0 :=
by simp *
lemma le_of_eq_of_le {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b ≤ 0) : a + b ≤ 0 :=
by simp *
lemma lt_of_eq_of_lt {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b < 0) : a + b < 0 :=
by simp *
lemma le_of_le_of_eq {α} [ordered_semiring α] {a b : α} (ha : a ≤ 0) (hb : b = 0) : a + b ≤ 0 :=
by simp *
lemma lt_of_lt_of_eq {α} [ordered_semiring α] {a b : α} (ha : a < 0) (hb : b = 0) : a + b < 0 :=
by simp *
lemma mul_neg {α} [ordered_ring α] {a b : α} (ha : a < 0) (hb : b > 0) : b * a < 0 :=
have (-b)*a > 0, from mul_pos_of_neg_of_neg (neg_neg_of_pos hb) ha,
neg_of_neg_pos (by simpa)
lemma mul_nonpos {α} [ordered_ring α] {a b : α} (ha : a ≤ 0) (hb : b > 0) : b * a ≤ 0 :=
have (-b)*a ≥ 0, from mul_nonneg_of_nonpos_of_nonpos (le_of_lt (neg_neg_of_pos hb)) ha,
(by simpa)
lemma mul_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b > 0) : b * a = 0 :=
by simp *
lemma eq_of_not_lt_of_not_gt {α} [linear_order α] (a b : α) (h1 : ¬ a < b) (h2 : ¬ b < a) : a = b :=
le_antisymm (le_of_not_gt h2) (le_of_not_gt h1)
lemma add_subst {α} [ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 + e2) = t1 + t2 := by simp [left_distrib, *]
lemma sub_subst {α} [ring α] {n e1 e2 t1 t2 : α} (h1 : n * e1 = t1) (h2 : n * e2 = t2) :
n * (e1 - e2) = t1 - t2 := by simp [left_distrib, *, sub_eq_add_neg]
lemma neg_subst {α} [ring α] {n e t : α} (h1 : n * e = t) : n * (-e) = -t := by simp *
private meta def apnn : tactic unit := `[norm_num]
lemma mul_subst {α} [comm_ring α] {n1 n2 k e1 e2 t1 t2 : α} (h1 : n1 * e1 = t1) (h2 : n2 * e2 = t2)
(h3 : n1*n2 = k . apnn) : k * (e1 * e2) = t1 * t2 :=
have h3 : n1 * n2 = k, from h3,
by rw [←h3, mul_comm n1, mul_assoc n2, ←mul_assoc n1, h1, ←mul_assoc n2, mul_comm n2, mul_assoc, h2] -- OUCH
lemma div_subst {α} [field α] {n1 n2 k e1 e2 t1 : α} (h1 : n1 * e1 = t1) (h2 : n2 / e2 = 1) (h3 : n1*n2 = k) :
k * (e1 / e2) = t1 :=
by rw [←h3, mul_assoc, mul_div_comm, h2, ←mul_assoc, h1, mul_comm, one_mul]
end lemmas
section datatypes
@[derive decidable_eq, derive inhabited]
inductive ineq
| eq | le | lt
open ineq
def ineq.max : ineq → ineq → ineq
| eq a := a
| le a := a
| lt a := lt
def ineq.is_lt : ineq → ineq → bool
| eq le := tt
| eq lt := tt
| le lt := tt
| _ _ := ff
def ineq.to_string : ineq → string
| eq := "="
| le := "≤"
| lt := "<"
instance : has_to_string ineq := ⟨ineq.to_string⟩
/--
The main datatype for FM elimination.
Variables are represented by natural numbers, each of which has an integer coefficient.
Index 0 is reserved for constants, i.e. `coeffs.find 0` is the coefficient of 1.
The represented term is `coeffs.keys.sum (λ i, coeffs.find i * Var[i])`.
str determines the direction of the comparison -- is it < 0, ≤ 0, or = 0?
-/
@[derive _root_.inhabited]
meta structure comp :=
(str : ineq)
(coeffs : rb_map ℕ int)
meta inductive comp_source
| assump : ℕ → comp_source
| add : comp_source → comp_source → comp_source
| scale : ℕ → comp_source → comp_source
meta def comp_source.flatten : comp_source → rb_map ℕ ℕ
| (comp_source.assump n) := mk_rb_map.insert n 1
| (comp_source.add c1 c2) := (comp_source.flatten c1).add (comp_source.flatten c2)
| (comp_source.scale n c) := (comp_source.flatten c).map (λ v, v * n)
meta def comp_source.to_string : comp_source → string
| (comp_source.assump e) := to_string e
| (comp_source.add c1 c2) := comp_source.to_string c1 ++ " + " ++ comp_source.to_string c2
| (comp_source.scale n c) := to_string n ++ " * " ++ comp_source.to_string c
meta instance comp_source.has_to_format : has_to_format comp_source :=
⟨λ a, comp_source.to_string a⟩
meta structure pcomp :=
(c : comp)
(src : comp_source)
meta def map_lt (m1 m2 : rb_map ℕ int) : bool :=
list.lex (prod.lex (<) (<)) m1.to_list m2.to_list
-- make more efficient
meta def comp.lt (c1 c2 : comp) : bool :=
(c1.str.is_lt c2.str) || (c1.str = c2.str) && map_lt c1.coeffs c2.coeffs
meta instance comp.has_lt : has_lt comp := ⟨λ a b, comp.lt a b⟩
meta instance pcomp.has_lt : has_lt pcomp := ⟨λ p1 p2, p1.c < p2.c⟩
-- short-circuit type class inference
meta instance pcomp.has_lt_dec : decidable_rel ((<) : pcomp → pcomp → Prop) := by apply_instance
meta def comp.coeff_of (c : comp) (a : ℕ) : ℤ :=
c.coeffs.zfind a
meta def comp.scale (c : comp) (n : ℕ) : comp :=
{ c with coeffs := c.coeffs.map ((*) (n : ℤ)) }
meta def comp.add (c1 c2 : comp) : comp :=
⟨c1.str.max c2.str, c1.coeffs.add c2.coeffs⟩
meta def pcomp.scale (c : pcomp) (n : ℕ) : pcomp :=
⟨c.c.scale n, comp_source.scale n c.src⟩
meta def pcomp.add (c1 c2 : pcomp) : pcomp :=
⟨c1.c.add c2.c, comp_source.add c1.src c2.src⟩
meta instance pcomp.to_format : has_to_format pcomp :=
⟨λ p, to_fmt p.c.coeffs ++ to_string p.c.str ++ "0"⟩
meta instance comp.to_format : has_to_format comp :=
⟨λ p, to_fmt p.coeffs⟩
end datatypes
section fm_elim
/-- If `c1` and `c2` both contain variable `a` with opposite coefficients,
produces `v1`, `v2`, and `c` such that `a` has been cancelled in `c := v1*c1 + v2*c2`. -/
meta def elim_var (c1 c2 : comp) (a : ℕ) : option (ℕ × ℕ × comp) :=
let v1 := c1.coeff_of a,
v2 := c2.coeff_of a in
if v1 * v2 < 0 then
let vlcm := nat.lcm v1.nat_abs v2.nat_abs,
v1' := vlcm / v1.nat_abs,
v2' := vlcm / v2.nat_abs in
some ⟨v1', v2', comp.add (c1.scale v1') (c2.scale v2')⟩
else none
meta def pelim_var (p1 p2 : pcomp) (a : ℕ) : option pcomp :=
do (n1, n2, c) ← elim_var p1.c p2.c a,
return ⟨c, comp_source.add (p1.src.scale n1) (p2.src.scale n2)⟩
meta def comp.is_contr (c : comp) : bool := c.coeffs.empty ∧ c.str = ineq.lt
meta def pcomp.is_contr (p : pcomp) : bool := p.c.is_contr
meta def elim_with_set (a : ℕ) (p : pcomp) (comps : rb_set pcomp) : rb_set pcomp :=
if ¬ p.c.coeffs.contains a then mk_rb_set.insert p else
comps.fold mk_rb_set $ λ pc s,
match pelim_var p pc a with
| some pc := s.insert pc
| none := s
end
/--
The state for the elimination monad.
* `vars`: the set of variables present in `comps`
* `comps`: a set of comparisons
* `inputs`: a set of pairs of exprs `(t, pf)`, where `t` is a term and `pf` is a proof that
`t {<, ≤, =} 0`, indexed by `ℕ`.
* `has_false`: stores a `pcomp` of `0 < 0` if one has been found
TODO: is it more efficient to store comps as a list, to avoid comparisons?
-/
meta structure linarith_structure :=
(vars : rb_set ℕ)
(comps : rb_set pcomp)
@[reducible] meta def linarith_monad :=
state_t linarith_structure (except_t pcomp id)
meta instance : monad linarith_monad := state_t.monad
meta instance : monad_except pcomp linarith_monad :=
state_t.monad_except pcomp
meta def get_vars : linarith_monad (rb_set ℕ) :=
linarith_structure.vars <$> get
meta def get_var_list : linarith_monad (list ℕ) :=
rb_set.to_list <$> get_vars
meta def get_comps : linarith_monad (rb_set pcomp) :=
linarith_structure.comps <$> get
meta def validate : linarith_monad unit :=
do ⟨_, comps⟩ ← get,
match comps.to_list.find (λ p : pcomp, p.is_contr) with
| none := return ()
| some c := throw c
end
meta def update (vars : rb_set ℕ) (comps : rb_set pcomp) : linarith_monad unit :=
state_t.put ⟨vars, comps⟩ >> validate
meta def monad.elim_var (a : ℕ) : linarith_monad unit :=
do vs ← get_vars,
when (vs.contains a) $
do comps ← get_comps,
let cs' := comps.fold mk_rb_set (λ p s, s.union (elim_with_set a p comps)),
update (vs.erase a) cs'
meta def elim_all_vars : linarith_monad unit :=
get_var_list >>= list.mmap' monad.elim_var
end fm_elim
section parse
open ineq tactic
meta def map_of_expr_mul_aux (c1 c2 : rb_map ℕ ℤ) : option (rb_map ℕ ℤ) :=
match c1.keys, c2.keys with
| [0], _ := some $ c2.scale (c1.zfind 0)
| _, [0] := some $ c1.scale (c2.zfind 0)
| [], _ := some mk_rb_map
| _, [] := some mk_rb_map
| _, _ := none
end
meta def list.mfind {α} (tac : α → tactic unit) : list α → tactic α
| [] := failed
| (h::t) := tac h >> return h <|> list.mfind t
meta def rb_map.find_defeq (red : transparency) {v} (m : expr_map v) (e : expr) : tactic v :=
prod.snd <$> list.mfind (λ p, is_def_eq e p.1 red) m.to_list
/--
Turns an expression into a map from `ℕ` to `ℤ`, for use in a `comp` object.
The `expr_map` `ℕ` argument identifies which expressions have already been assigned numbers.
Returns a new map.
-/
meta def map_of_expr (red : transparency) : expr_map ℕ → expr → tactic (expr_map ℕ × rb_map ℕ ℤ)
| m e@`(%%e1 * %%e2) :=
(do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
mp ← map_of_expr_mul_aux comp1 comp2,
return (m', mp)) <|>
(do k ← rb_map.find_defeq red m e, return (m, mk_rb_map.insert k 1)) <|>
(let n := m.size + 1 in return (m.insert e n, mk_rb_map.insert n 1))
| m `(%%e1 + %%e2) :=
do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
return (m', comp1.add comp2)
| m `(%%e1 - %%e2) :=
do (m', comp1) ← map_of_expr m e1,
(m', comp2) ← map_of_expr m' e2,
return (m', comp1.add (comp2.scale (-1)))
| m `(-%%e) := do (m', comp) ← map_of_expr m e, return (m', comp.scale (-1))
| m e :=
match e.to_int with
| some 0 := return ⟨m, mk_rb_map⟩
| some z := return ⟨m, mk_rb_map.insert 0 z⟩
| none :=
(do k ← rb_map.find_defeq red m e, return (m, mk_rb_map.insert k 1)) <|>
(let n := m.size + 1 in return (m.insert e n, mk_rb_map.insert n 1))
end
meta def parse_into_comp_and_expr : expr → option (ineq × expr)
| `(%%e < 0) := (ineq.lt, e)
| `(%%e ≤ 0) := (ineq.le, e)
| `(%%e = 0) := (ineq.eq, e)
| _ := none
meta def to_comp (red : transparency) (e : expr) (m : expr_map ℕ) : tactic (comp × expr_map ℕ) :=
do (iq, e) ← parse_into_comp_and_expr e,
(m', comp') ← map_of_expr red m e,
return ⟨⟨iq, comp'⟩, m'⟩
meta def to_comp_fold (red : transparency) : expr_map ℕ → list expr →
tactic (list (option comp) × expr_map ℕ)
| m [] := return ([], m)
| m (h::t) :=
(do (c, m') ← to_comp red h m,
(l, mp) ← to_comp_fold m' t,
return (c::l, mp)) <|>
(do (l, mp) ← to_comp_fold m t,
return (none::l, mp))
/--
Takes a list of proofs of props of the form `t {<, ≤, =} 0`, and creates a
`linarith_structure`.
-/
meta def mk_linarith_structure (red : transparency) (l : list expr) :
tactic (linarith_structure × rb_map ℕ (expr × expr)) :=
do pftps ← l.mmap infer_type,
(l', map) ← to_comp_fold red mk_rb_map pftps,
let lz := list.enum $ ((l.zip pftps).zip l').filter_map (λ ⟨a, b⟩, prod.mk a <$> b),
let prmap := rb_map.of_list $ lz.map (λ ⟨n, x⟩, (n, x.1)),
let vars : rb_set ℕ := rb_map.set_of_list $ list.range map.size.succ,
let pc : rb_set pcomp := rb_map.set_of_list $
lz.map (λ ⟨n, x⟩, ⟨x.2, comp_source.assump n⟩),
return (⟨vars, pc⟩, prmap)
meta def linarith_monad.run (red : transparency) {α} (tac : linarith_monad α) (l : list expr) :
tactic ((pcomp ⊕ α) × rb_map ℕ (expr × expr)) :=
do (struct, inputs) ← mk_linarith_structure red l,
match (state_t.run (validate >> tac) struct).run with
| (except.ok (a, _)) := return (sum.inr a, inputs)
| (except.error contr) := return (sum.inl contr, inputs)
end
end parse
section prove
open ineq tactic
meta def get_rel_sides : expr → tactic (expr × expr)
| `(%%a < %%b) := return (a, b)
| `(%%a ≤ %%b) := return (a, b)
| `(%%a = %%b) := return (a, b)
| `(%%a ≥ %%b) := return (a, b)
| `(%%a > %%b) := return (a, b)
| _ := failed
meta def mul_expr (n : ℕ) (e : expr) : pexpr :=
if n = 1 then ``(%%e) else
``(%%(nat.to_pexpr n) * %%e)
meta def add_exprs_aux : pexpr → list pexpr → pexpr
| p [] := p
| p [a] := ``(%%p + %%a)
| p (h::t) := add_exprs_aux ``(%%p + %%h) t
meta def add_exprs : list pexpr → pexpr
| [] := ``(0)
| (h::t) := add_exprs_aux h t
meta def find_contr (m : rb_set pcomp) : option pcomp :=
m.keys.find (λ p, p.c.is_contr)
meta def ineq_const_mul_nm : ineq → name
| lt := ``mul_neg
| le := ``mul_nonpos
| eq := ``mul_eq
meta def ineq_const_nm : ineq → ineq → (name × ineq)
| eq eq := (``eq_of_eq_of_eq, eq)
| eq le := (``le_of_eq_of_le, le)
| eq lt := (``lt_of_eq_of_lt, lt)
| le eq := (``le_of_le_of_eq, le)
| le le := (`add_nonpos, le)
| le lt := (`add_neg_of_nonpos_of_neg, lt)
| lt eq := (``lt_of_lt_of_eq, lt)
| lt le := (`add_neg_of_neg_of_nonpos, lt)
| lt lt := (`add_neg, lt)
meta def mk_single_comp_zero_pf (c : ℕ) (h : expr) : tactic (ineq × expr) :=
do tp ← infer_type h,
some (iq, e) ← return $ parse_into_comp_and_expr tp,
if c = 0 then
do e' ← mk_app ``zero_mul [e], return (eq, e')
else if c = 1 then return (iq, h)
else
do nm ← resolve_name (ineq_const_mul_nm iq),
tp ← (prod.snd <$> (infer_type h >>= get_rel_sides)) >>= infer_type,
cpos ← to_expr ``((%%c.to_pexpr : %%tp) > 0),
(_, ex) ← solve_aux cpos `[norm_num, done],
-- e' ← mk_app (ineq_const_mul_nm iq) [h, ex], -- this takes many seconds longer in some examples! why?
e' ← to_expr ``(%%nm %%h %%ex) ff,
return (iq, e')
meta def mk_lt_zero_pf_aux (c : ineq) (pf npf : expr) (coeff : ℕ) : tactic (ineq × expr) :=
do (iq, h') ← mk_single_comp_zero_pf coeff npf,
let (nm, niq) := ineq_const_nm c iq,
n ← resolve_name nm,
e' ← to_expr ``(%%n %%pf %%h'),
return (niq, e')
/--
Takes a list of coefficients `[c]` and list of expressions, of equal length.
Each expression is a proof of a prop of the form `t {<, ≤, =} 0`.
Produces a proof that the sum of `(c*t) {<, ≤, =} 0`,
where the `comp` is as strong as possible.
-/
meta def mk_lt_zero_pf : list ℕ → list expr → tactic expr
| _ [] := fail "no linear hypotheses found"
| [c] [h] := prod.snd <$> mk_single_comp_zero_pf c h
| (c::ct) (h::t) :=
do (iq, h') ← mk_single_comp_zero_pf c h,
prod.snd <$> (ct.zip t).mfoldl (λ pr ce, mk_lt_zero_pf_aux pr.1 pr.2 ce.2 ce.1) (iq, h')
| _ _ := fail "not enough args to mk_lt_zero_pf"
meta def term_of_ineq_prf (prf : expr) : tactic expr :=
do (lhs, _) ← infer_type prf >>= get_rel_sides,
return lhs
meta structure linarith_config :=
(discharger : tactic unit := `[ring])
(restrict_type : option Type := none)
(restrict_type_reflect : reflected restrict_type . apply_instance)
(exfalso : bool := tt)
(transparency : transparency := reducible)
(split_hypotheses : bool := tt)
meta def ineq_pf_tp (pf : expr) : tactic expr :=
do (_, z) ← infer_type pf >>= get_rel_sides,
infer_type z
meta def mk_neg_one_lt_zero_pf (tp : expr) : tactic expr :=
to_expr ``((neg_neg_of_pos zero_lt_one : -1 < (0 : %%tp)))
/--
Assumes `e` is a proof that `t = 0`. Creates a proof that `-t = 0`.
-/
meta def mk_neg_eq_zero_pf (e : expr) : tactic expr :=
to_expr ``(neg_eq_zero.mpr %%e)
meta def add_neg_eq_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
do some (iq, tp) ← parse_into_comp_and_expr <$> infer_type h,
match iq with
| ineq.eq := do nep ← mk_neg_eq_zero_pf h, tl ← add_neg_eq_pfs t, return $ h::nep::tl
| _ := list.cons h <$> add_neg_eq_pfs t
end
/--
Takes a list of proofs of propositions of the form `t {<, ≤, =} 0`,
and tries to prove the goal `false`.
-/
meta def prove_false_by_linarith1 (cfg : linarith_config) : list expr → tactic unit
| [] := fail "no args to linarith"
| l@(h::t) :=
do l' ← add_neg_eq_pfs l,
hz ← ineq_pf_tp h >>= mk_neg_one_lt_zero_pf,
(sum.inl contr, inputs) ← elim_all_vars.run cfg.transparency (hz::l')
| fail "linarith failed to find a contradiction",
let coeffs := inputs.keys.map (λ k, (contr.src.flatten.ifind k)),
let pfs : list expr := inputs.keys.map (λ k, (inputs.ifind k).1),
let zip := (coeffs.zip pfs).filter (λ pr, pr.1 ≠ 0),
let (coeffs, pfs) := zip.unzip,
mls ← zip.mmap (λ pr, do e ← term_of_ineq_prf pr.2, return (mul_expr pr.1 e)),
sm ← to_expr $ add_exprs mls,
tgt ← to_expr ``(%%sm = 0),
(a, b) ← solve_aux tgt (cfg.discharger >> done),
pf ← mk_lt_zero_pf coeffs pfs,
pftp ← infer_type pf,
(_, nep, _) ← rewrite_core b pftp,
pf' ← mk_eq_mp nep pf,
mk_app `lt_irrefl [pf'] >>= exact
end prove
section normalize
open tactic
set_option eqn_compiler.max_steps 50000
meta def rem_neg (prf : expr) : expr → tactic expr
| `(_ ≤ _) := to_expr ``(lt_of_not_ge %%prf)
| `(_ < _) := to_expr ``(le_of_not_gt %%prf)
| `(_ > _) := to_expr ``(le_of_not_gt %%prf)
| `(_ ≥ _) := to_expr ``(lt_of_not_ge %%prf)
| e := failed
meta def rearr_comp : expr → expr → tactic expr
| prf `(%%a ≤ 0) := return prf
| prf `(%%a < 0) := return prf
| prf `(%%a = 0) := return prf
| prf `(%%a ≥ 0) := to_expr ``(neg_nonpos.mpr %%prf)
| prf `(%%a > 0) := to_expr ``(neg_neg_of_pos %%prf)
| prf `(0 ≥ %%a) := to_expr ``(show %%a ≤ 0, from %%prf)
| prf `(0 > %%a) := to_expr ``(show %%a < 0, from %%prf)
| prf `(0 = %%a) := to_expr ``(eq.symm %%prf)
| prf `(0 ≤ %%a) := to_expr ``(neg_nonpos.mpr %%prf)
| prf `(0 < %%a) := to_expr ``(neg_neg_of_pos %%prf)
| prf `(%%a ≤ %%b) := to_expr ``(sub_nonpos.mpr %%prf)
| prf `(%%a < %%b) := to_expr ``(sub_neg_of_lt %%prf)
| prf `(%%a = %%b) := to_expr ``(sub_eq_zero.mpr %%prf)
| prf `(%%a > %%b) := to_expr ``(sub_neg_of_lt %%prf)
| prf `(%%a ≥ %%b) := to_expr ``(sub_nonpos.mpr %%prf)
| prf `(¬ %%t) := do nprf ← rem_neg prf t, tp ← infer_type nprf, rearr_comp nprf tp
| prf _ := fail "couldn't rearrange comp"
meta def is_numeric : expr → option ℚ
| `(%%e1 + %%e2) := (+) <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 - %%e2) := has_sub.sub <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 * %%e2) := (*) <$> is_numeric e1 <*> is_numeric e2
| `(%%e1 / %%e2) := (/) <$> is_numeric e1 <*> is_numeric e2
| `(-%%e) := rat.neg <$> is_numeric e
| e := e.to_rat
meta def find_cancel_factor : expr → ℕ × tree ℕ
| `(%%e1 + %%e2) :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, lcm := v1.lcm v2 in
(lcm, tree.node lcm t1 t2)
| `(%%e1 - %%e2) :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, lcm := v1.lcm v2 in
(lcm, tree.node lcm t1 t2)
| `(%%e1 * %%e2) :=
match is_numeric e1, is_numeric e2 with
| none, none := (1, tree.node 1 tree.nil tree.nil)
| _, _ :=
let (v1, t1) := find_cancel_factor e1, (v2, t2) := find_cancel_factor e2, pd := v1*v2 in
(pd, tree.node pd t1 t2)
end
| `(%%e1 / %%e2) :=
match is_numeric e2 with
| some q := let (v1, t1) := find_cancel_factor e1, n := v1.lcm q.num.nat_abs in
(n, tree.node n t1 (tree.node q.num.nat_abs tree.nil tree.nil))
| none := (1, tree.node 1 tree.nil tree.nil)
end
| `(-%%e) := find_cancel_factor e
| _ := (1, tree.node 1 tree.nil tree.nil)
open tree
meta def mk_prod_prf : ℕ → tree ℕ → expr → tactic expr
| v (node _ lhs rhs) `(%%e1 + %%e2) :=
do v1 ← mk_prod_prf v lhs e1, v2 ← mk_prod_prf v rhs e2, mk_app ``add_subst [v1, v2]
| v (node _ lhs rhs) `(%%e1 - %%e2) :=
do v1 ← mk_prod_prf v lhs e1, v2 ← mk_prod_prf v rhs e2, mk_app ``sub_subst [v1, v2]
| v (node n lhs@(node ln _ _) rhs) `(%%e1 * %%e2) :=
do tp ← infer_type e1, v1 ← mk_prod_prf ln lhs e1, v2 ← mk_prod_prf (v/ln) rhs e2,
ln' ← tp.of_nat ln, vln' ← tp.of_nat (v/ln), v' ← tp.of_nat v,
ntp ← to_expr ``(%%ln' * %%vln' = %%v'),
(_, npf) ← solve_aux ntp `[norm_num, done],
mk_app ``mul_subst [v1, v2, npf]
| v (node n lhs rhs@(node rn _ _)) `(%%e1 / %%e2) :=
do tp ← infer_type e1, v1 ← mk_prod_prf (v/rn) lhs e1,
rn' ← tp.of_nat rn, vrn' ← tp.of_nat (v/rn), n' ← tp.of_nat n, v' ← tp.of_nat v,
ntp ← to_expr ``(%%rn' / %%e2 = 1),
(_, npf) ← solve_aux ntp `[norm_num, done],
ntp2 ← to_expr ``(%%vrn' * %%n' = %%v'),
(_, npf2) ← solve_aux ntp2 `[norm_num, done],
mk_app ``div_subst [v1, npf, npf2]
| v t `(-%%e) := do v' ← mk_prod_prf v t e, mk_app ``neg_subst [v']
| v _ e :=
do tp ← infer_type e,
v' ← tp.of_nat v,
e' ← to_expr ``(%%v' * %%e),
mk_app `eq.refl [e']
/--
Given `e`, a term with rational division, produces a natural number `n` and a proof of `n*e = e'`,
where `e'` has no division.
-/
meta def kill_factors (e : expr) : tactic (ℕ × expr) :=
let (n, t) := find_cancel_factor e in
do e' ← mk_prod_prf n t e, return (n, e')
open expr
meta def expr_contains (n : name) : expr → bool
| (const nm _) := nm = n
| (lam _ _ _ bd) := expr_contains bd
| (pi _ _ _ bd) := expr_contains bd
| (app e1 e2) := expr_contains e1 || expr_contains e2
| _ := ff
lemma sub_into_lt {α} [ordered_semiring α] {a b : α} (he : a = b) (hl : a ≤ 0) : b ≤ 0 :=
by rwa he at hl
meta def norm_hyp_aux (h' lhs : expr) : tactic expr :=
do (v, lhs') ← kill_factors lhs,
if v = 1 then return h' else do
(ih, h'') ← mk_single_comp_zero_pf v h',
(_, nep, _) ← infer_type h'' >>= rewrite_core lhs',
mk_eq_mp nep h''
meta def norm_hyp (h : expr) : tactic expr :=
do htp ← infer_type h,
h' ← rearr_comp h htp,
some (c, lhs) ← parse_into_comp_and_expr <$> infer_type h',
if expr_contains `has_div.div lhs then
norm_hyp_aux h' lhs
else return h'
meta def get_contr_lemma_name : expr → option name
| `(%%a < %%b) := return `lt_of_not_ge
| `(%%a ≤ %%b) := return `le_of_not_gt
| `(%%a = %%b) := return ``eq_of_not_lt_of_not_gt
| `(%%a ≠ %%b) := return `not.intro
| `(%%a ≥ %%b) := return `le_of_not_gt
| `(%%a > %%b) := return `lt_of_not_ge
| `(¬ %%a < %%b) := return `not.intro
| `(¬ %%a ≤ %%b) := return `not.intro
| `(¬ %%a = %%b) := return `not.intro
| `(¬ %%a ≥ %%b) := return `not.intro
| `(¬ %%a > %%b) := return `not.intro
| _ := none
/-- Assumes the input `t` is of type `ℕ`. Produces `t'` of type `ℤ` such that `↑t = t'` and
a proof of equality. -/
meta def cast_expr (e : expr) : tactic (expr × expr) :=
do s ← [`int.coe_nat_add, `int.coe_nat_zero, `int.coe_nat_one,
``int.coe_nat_bit0_mul, ``int.coe_nat_bit1_mul, ``int.coe_nat_zero_mul, ``int.coe_nat_one_mul,
``int.coe_nat_mul_bit0, ``int.coe_nat_mul_bit1, ``int.coe_nat_mul_zero, ``int.coe_nat_mul_one,
``int.coe_nat_bit0, ``int.coe_nat_bit1].mfoldl simp_lemmas.add_simp simp_lemmas.mk,
ce ← to_expr ``(↑%%e : ℤ),
simplify s [] ce {fail_if_unchanged := ff}
meta def is_nat_int_coe : expr → option expr
| `((↑(%%n : ℕ) : ℤ)) := some n
| _ := none
meta def mk_coe_nat_nonneg_prf (e : expr) : tactic expr :=
mk_app `int.coe_nat_nonneg [e]
meta def get_nat_comps : expr → list expr
| `(%%a + %%b) := (get_nat_comps a).append (get_nat_comps b)
| `(%%a * %%b) := (get_nat_comps a).append (get_nat_comps b)
| e := match is_nat_int_coe e with
| some e' := [e']
| none := []
end
meta def mk_coe_nat_nonneg_prfs (e : expr) : tactic (list expr) :=
(get_nat_comps e).mmap mk_coe_nat_nonneg_prf
meta def mk_cast_eq_and_nonneg_prfs (pf a b : expr) (ln : name) : tactic (list expr) :=
do (a', prfa) ← cast_expr a,
(b', prfb) ← cast_expr b,
la ← mk_coe_nat_nonneg_prfs a',
lb ← mk_coe_nat_nonneg_prfs b',
pf' ← mk_app ln [pf, prfa, prfb],
return $ pf'::(la.append lb)
meta def mk_int_pfs_of_nat_pf (pf : expr) : tactic (list expr) :=
do tp ← infer_type pf,
match tp with
| `(%%a = %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_eq_subst
| `(%%a ≤ %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_le_subst
| `(%%a < %%b) := mk_cast_eq_and_nonneg_prfs pf a b ``nat_lt_subst
| `(%%a ≥ %%b) := mk_cast_eq_and_nonneg_prfs pf b a ``nat_le_subst
| `(%%a > %%b) := mk_cast_eq_and_nonneg_prfs pf b a ``nat_lt_subst
| `(¬ %%a ≤ %%b) := do pf' ← mk_app ``lt_of_not_ge [pf], mk_cast_eq_and_nonneg_prfs pf' b a ``nat_lt_subst
| `(¬ %%a < %%b) := do pf' ← mk_app ``le_of_not_gt [pf], mk_cast_eq_and_nonneg_prfs pf' b a ``nat_le_subst
| `(¬ %%a ≥ %%b) := do pf' ← mk_app ``lt_of_not_ge [pf], mk_cast_eq_and_nonneg_prfs pf' a b ``nat_lt_subst
| `(¬ %%a > %%b) := do pf' ← mk_app ``le_of_not_gt [pf], mk_cast_eq_and_nonneg_prfs pf' a b ``nat_le_subst
| _ := fail "mk_int_pfs_of_nat_pf failed: proof is not an inequality"
end
meta def mk_non_strict_int_pf_of_strict_int_pf (pf : expr) : tactic expr :=
do tp ← infer_type pf,
match tp with
| `(%%a < %%b) := to_expr ``(@cast (%%a < %%b) (%%a + 1 ≤ %%b) (by refl) %%pf)
| `(%%a > %%b) := to_expr ``(@cast (%%a > %%b) (%%a ≥ %%b + 1) (by refl) %%pf)
| `(¬ %%a ≤ %%b) := to_expr ``(@cast (%%a > %%b) (%%a ≥ %%b + 1) (by refl) (lt_of_not_ge %%pf))
| `(¬ %%a ≥ %%b) := to_expr ``(@cast (%%a < %%b) (%%a + 1 ≤ %%b) (by refl) (lt_of_not_ge %%pf))
| _ := fail "mk_non_strict_int_pf_of_strict_int_pf failed: proof is not an inequality"
end
meta def guard_is_nat_prop : expr → tactic unit
| `(%%a = _) := infer_type a >>= unify `(ℕ)
| `(%%a ≤ _) := infer_type a >>= unify `(ℕ)
| `(%%a < _) := infer_type a >>= unify `(ℕ)
| `(%%a ≥ _) := infer_type a >>= unify `(ℕ)
| `(%%a > _) := infer_type a >>= unify `(ℕ)
| `(¬ %%p) := guard_is_nat_prop p
| _ := failed
meta def guard_is_strict_int_prop : expr → tactic unit
| `(%%a < _) := infer_type a >>= unify `(ℤ)
| `(%%a > _) := infer_type a >>= unify `(ℤ)
| `(¬ %%a ≤ _) := infer_type a >>= unify `(ℤ)
| `(¬ %%a ≥ _) := infer_type a >>= unify `(ℤ)
| _ := failed
meta def replace_nat_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
(do infer_type h >>= guard_is_nat_prop,
ls ← mk_int_pfs_of_nat_pf h,
list.append ls <$> replace_nat_pfs t) <|> list.cons h <$> replace_nat_pfs t
meta def replace_strict_int_pfs : list expr → tactic (list expr)
| [] := return []
| (h::t) :=
(do infer_type h >>= guard_is_strict_int_prop,
l ← mk_non_strict_int_pf_of_strict_int_pf h,
list.cons l <$> replace_strict_int_pfs t) <|> list.cons h <$> replace_strict_int_pfs t
meta def partition_by_type_aux : rb_lmap expr expr → list expr → tactic (rb_lmap expr expr)
| m [] := return m
| m (h::t) := do tp ← ineq_pf_tp h, partition_by_type_aux (m.insert tp h) t
meta def partition_by_type (l : list expr) : tactic (rb_lmap expr expr) :=
partition_by_type_aux mk_rb_map l
private meta def try_linarith_on_lists (cfg : linarith_config) (ls : list (list expr)) : tactic unit :=
(first $ ls.map $ prove_false_by_linarith1 cfg) <|> fail "linarith failed"
/--
Takes a list of proofs of propositions.
Filters out the proofs of linear (in)equalities,
and tries to use them to prove `false`.
If `pref_type` is given, starts by working over this type.
-/
meta def prove_false_by_linarith (cfg : linarith_config) (pref_type : option expr) (l : list expr) : tactic unit :=
do l' ← replace_nat_pfs l,
l'' ← replace_strict_int_pfs l',
ls ← list.reduce_option <$> l''.mmap (λ h, (do s ← norm_hyp h, return (some s)) <|> return none)
>>= partition_by_type,
pref_type ← (unify pref_type.iget `(ℕ) >> return (some `(ℤ) : option expr)) <|> return pref_type,
match cfg.restrict_type, rb_map.values ls, pref_type with
| some rtp, _, _ :=
do m ← mk_mvar, unify `(some %%m : option Type) cfg.restrict_type_reflect, m ← instantiate_mvars m,
prove_false_by_linarith1 cfg (ls.ifind m)
| none, [ls'], _ := prove_false_by_linarith1 cfg ls'
| none, ls', none := try_linarith_on_lists cfg ls'
| none, _, (some t) := prove_false_by_linarith1 cfg (ls.ifind t) <|>
try_linarith_on_lists cfg (rb_map.values (ls.erase t))
end
end normalize
end linarith
section
open tactic linarith
open lean lean.parser interactive tactic interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many
meta def linarith.elab_arg_list : option (list pexpr) → tactic (list expr)
| none := return []
| (some l) := l.mmap i_to_expr
meta def linarith.preferred_type_of_goal : option expr → tactic (option expr)
| none := return none
| (some e) := some <$> ineq_pf_tp e
/--
`linarith.interactive_aux cfg o_goal restrict_hyps args`:
* `cfg` is a `linarith_config` object
* `o_goal : option expr` is the local constant corresponding to the former goal, if there was one
* `restrict_hyps : bool` is `tt` if `linarith only [...]` was used
* `args : option (list pexpr)` is the optional list of arguments in `linarith [...]`
-/
meta def linarith.interactive_aux (cfg : linarith_config) :
option expr → bool → option (list pexpr) → tactic unit
| none tt none := fail "linarith only called with no arguments"
| none tt (some l) := l.mmap i_to_expr >>= prove_false_by_linarith cfg none
| (some e) tt l :=
do tp ← ineq_pf_tp e,
list.cons e <$> linarith.elab_arg_list l >>= prove_false_by_linarith cfg (some tp)
| oe ff l :=
do otp ← linarith.preferred_type_of_goal oe,
list.append <$> local_context <*>
(list.filter (λ a, bnot $ expr.is_local_constant a) <$> linarith.elab_arg_list l) >>=
prove_false_by_linarith cfg otp
/--
Tries to prove a goal of `false` by linear arithmetic on hypotheses.
If the goal is a linear (in)equality, tries to prove it by contradiction.
If the goal is not `false` or an inequality, applies `exfalso` and tries linarith on the
hypotheses.
* `linarith` will use all relevant hypotheses in the local context.
* `linarith [t1, t2, t3]` will add proof terms t1, t2, t3 to the local context.
* `linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses
`h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.
* `linarith!` will use a stronger reducibility setting to identify atoms.
Config options:
* `linarith {exfalso := ff}` will fail on a goal that is neither an inequality nor `false`
* `linarith {restrict_type := T}` will run only on hypotheses that are inequalities over `T`
* `linarith {discharger := tac}` will use `tac` instead of `ring` for normalization.
Options: `ring2`, `ring SOP`, `simp`
-/
meta def tactic.interactive.linarith (red : parse ((tk "!")?))
(restr : parse ((tk "only")?)) (hyps : parse pexpr_list?)
(cfg : linarith_config := {}) : tactic unit :=
let cfg :=
if red.is_some then {cfg with transparency := semireducible, discharger := `[ring!]}
else cfg in
do t ← target,
when cfg.split_hypotheses (try auto.split_hyps),
match get_contr_lemma_name t with
| some nm := seq (applyc nm) $
do t ← intro1, linarith.interactive_aux cfg (some t) restr.is_some hyps
| none := if cfg.exfalso then exfalso >> linarith.interactive_aux cfg none restr.is_some hyps
else fail "linarith failed: target type is not an inequality."
end
add_hint_tactic "linarith"
/--
`linarith` attempts to find a contradiction between hypotheses that are linear (in)equalities.
Equivalently, it can prove a linear inequality by assuming its negation and proving `false`.
In theory, `linarith` should prove any goal that is true in the theory of linear arithmetic over
the rationals. While there is some special handling for non-dense orders like `nat` and `int`,
this tactic is not complete for these theories and will not prove every true goal.
An example:
```lean
example (x y z : ℚ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0)
(h3 : 12*y - 4* z < 0) : false :=
by linarith
```
`linarith` will use all appropriate hypotheses and the negation of the goal, if applicable.
`linarith [t1, t2, t3]` will additionally use proof terms `t1, t2, t3`.
`linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses
`h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.
`linarith!` will use a stronger reducibility setting to try to identify atoms. For example,
```lean
example (x : ℚ) : id x ≥ x :=
by linarith
```
will fail, because `linarith` will not identify `x` and `id x`. `linarith!` will.
This can sometimes be expensive.
`linarith {discharger := tac, restrict_type := tp, exfalso := ff}` takes a config object with five
optional arguments:
* `discharger` specifies a tactic to be used for reducing an algebraic equation in the
proof stage. The default is `ring`. Other options currently include `ring SOP` or `simp` for basic
problems.
* `restrict_type` will only use hypotheses that are inequalities over `tp`. This is useful
if you have e.g. both integer and rational valued inequalities in the local context, which can
sometimes confuse the tactic.
* `transparency` controls how hard `linarith` will try to match atoms to each other. By default
it will only unfold `reducible` definitions.
* If `split_hypotheses` is true, `linarith` will split conjunctions in the context into separate
hypotheses.
* If `exfalso` is false, `linarith` will fail when the goal is neither an inequality nor `false`.
(True by default.)
-/
add_tactic_doc
{ name := "linarith",
category := doc_category.tactic,
decl_names := [`tactic.interactive.linarith],
tags := ["arithmetic", "decision procedure", "finishing"] }
end
|
f4d0b47d5d51a39dae385236fc7f5a9497cebda6 | d7189ea2ef694124821b033e533f18905b5e87ef | /galois/order.lean | 5e92efb4cfcd8a4c6b58bba56fd409fd9547461a | [
"Apache-2.0"
] | permissive | digama0/lean-protocol-support | eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59 | cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda | refs/heads/master | 1,625,421,450,627 | 1,506,035,462,000 | 1,506,035,462,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 296 | lean | /-
Defines an additional theorem over orders.
-/
/-- Show that for linear orders le is equivalent to not_gt.
N.B. This is the inverse of lt_iff_not_ge.
-/
protected lemma le_iff_not_gt {α : Type} [linear_order α] (x y : α)
: (x ≤ y) ↔ ¬(x > y) :=
iff.intro not_lt_of_ge le_of_not_gt
|
5f8ec9e3c6293d3339a1b92a7690f085a0618c9d | 36938939954e91f23dec66a02728db08a7acfcf9 | /lean/tactic.lean | e837c776a76521e9c323884528def77827c49d0f | [
"Apache-2.0"
] | permissive | pnwamk/reopt-vcg | f8b56dd0279392a5e1c6aee721be8138e6b558d3 | c9f9f185fbefc25c36c4b506bbc85fd1a03c3b6d | refs/heads/master | 1,631,145,017,772 | 1,593,549,019,000 | 1,593,549,143,000 | 254,191,418 | 0 | 0 | null | 1,586,377,077,000 | 1,586,377,077,000 | null | UTF-8 | Lean | false | false | 195 | lean | -- This tries to prove a property by just running the evaluator.
meta def dec_trivial_tac : tactic unit := do
tgt ← tactic.target,
tactic.apply $ (`(@of_as_true) : expr) tgt,
tactic.triv
|
a23432a80949f265c725d1d7db9cab8cc4281bfc | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /stage0/src/Init/Control/EState.lean | fa416d618ea45ce5a863aabe7d6cc2e0c8b6cfbd | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 1,992 | 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
-/
prelude
import Init.Control.State
import Init.Control.Except
import Init.Data.ToString.Basic
universe u v
namespace EStateM
variable {ε σ α : Type u}
instance [ToString ε] [ToString α] : ToString (Result ε σ α) where
toString
| Result.ok a _ => "ok: " ++ toString a
| Result.error e _ => "error: " ++ toString e
instance [Repr ε] [Repr α] : Repr (Result ε σ α) where
reprPrec
| Result.error e _, prec => Repr.addAppParen ("EStateM.Result.error " ++ reprArg e) prec
| Result.ok a _, prec => Repr.addAppParen ("EStateM.Result.ok " ++ reprArg a) prec
end EStateM
namespace EStateM
variable {ε σ α β : Type u}
/-- Alternative orElse operator that allows to select which exception should be used.
The default is to use the first exception since the standard `orElse` uses the second. -/
@[inline] protected def orElse' {δ} [Backtrackable δ σ] (x₁ x₂ : EStateM ε σ α) (useFirstEx := true) : EStateM ε σ α := fun s =>
let d := Backtrackable.save s;
match x₁ s with
| Result.error e₁ s₁ =>
match x₂ (Backtrackable.restore s₁ d) with
| Result.error e₂ s₂ => Result.error (if useFirstEx then e₁ else e₂) s₂
| ok => ok
| ok => ok
instance : MonadFinally (EStateM ε σ) := {
tryFinally' := fun x h s =>
let r := x s
match r with
| Result.ok a s => match h (some a) s with
| Result.ok b s => Result.ok (a, b) s
| Result.error e s => Result.error e s
| Result.error e₁ s => match h none s with
| Result.ok _ s => Result.error e₁ s
| Result.error e₂ s => Result.error e₂ s
}
@[inline] def fromStateM {ε σ α : Type} (x : StateM σ α) : EStateM ε σ α := fun s =>
match x.run s with
| (a, s') => EStateM.Result.ok a s'
end EStateM
|
9792f6772628a26918f4724ce96a317c7233b4d8 | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/elab1.lean | 762407cfeff46cf38a4096eeac64555ac90402b5 | [
"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 | 618 | lean | variable f {A : Type} (a b : A) : A.
check f 10 true
variable g {A B : Type} (a : A) : A.
check g 10
variable h : forall (A : Type), A -> A.
check fun x, fun A : Type, h A x
variable my_eq : forall A : Type, A -> A -> Bool.
check fun (A B : Type) (a : _) (b : _) (C : Type), my_eq C a b.
variable a : Bool
variable b : Bool
variable H : a /\ b
theorem t1 : b := (fun H1, and_intro H1 (and_eliml H)).
theorem t2 : a = b := trans (refl a) (refl b).
check f Bool Bool.
theorem pierce (a b : Bool) : ((a -> b) -> a) -> a :=
λ H, or_elim (EM a)
(λ H_a, H)
(λ H_na, NotImp1 (MT H H_na))
|
1e88c9a04cc3e11a2d6c283ea6307cc2a32e6bc6 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/record5.lean | 6811a2232552c13e5ac02704eea1d9bfb5c640c7 | [
"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 | 352 | lean | import logic data.unit
structure point (A : Type) (B : Type) :=
mk :: (x : A) (y : B)
structure point2 (A : Type) (B : Type) extends point A B :=
make
check point2.make
structure point3 extends point num num, point2 num num renaming x→y y→z
check point3.mk
set_option pp.coercions true
theorem tst : point3.mk 1 2 3 = point2.make 2 3 :=
rfl
|
9a04f57255c5e6cb78ea44ac61e9f15f264a3eaa | b522075d31b564daeb3347a10eb9bb777ee93943 | /manifold/manifold.lean | 8ec27dabc1fa9b31e2c74d999bc5af8d1c7bb66f | [] | no_license | truonghoangle/manifolds | e6c2534dd46579f56ba99a48e2eb7ce51640e7c0 | 9c0d731a480e88758180b31ce7c3b371771d426b | refs/heads/master | 1,638,501,090,139 | 1,557,991,948,000 | 1,557,991,948,000 | 185,779,631 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,722 | lean | /-
Copyright (c) 2019 Joe Cool. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Hoang Le Truong.
-/
import manifold.basis
open topological_space
noncomputable theory
universes u v w
variables {α : Type} {β : Type} {γ : Type w} {n : ℕ}
variable [nondiscrete_normed_field α]
variables {E : cartesian α }
variables {F : cartesian α }
structure chart (X : Top) (E : cartesian α ) :=
(iso : X ≃ₜ. E.to_Top)
(h1 : is_open iso.to_fun.dom)
(h2 : is_open iso.inv_fun.dom)
namespace chart
variable {X : Top}
def to_fun (c : chart X E) : X →. E := c.iso.to_fun
def inv_fun (c :chart X E) : E →. X := c.iso.inv_fun
def domain (c : chart X E) : set X := c.to_fun.dom
def codomain (c : chart X E) : set E := c.inv_fun.dom
end chart
def lift_fun (E : cartesian α) (F : cartesian α) (h:(E→. α) → Prop)
: ( E →. F )→ Prop := λ f, ∀ i: fin (F.dim), h (pfun.lift (cartesian.proj F i).to_fun ∘. f )
def compatible_charts {X : Top} (h:(E→. α) → Prop) (c₁ c₂ : chart X E) : Prop :=
lift_fun E E h (c₂.to_fun ∘. c₁.inv_fun) ∧
lift_fun E E h (c₁.to_fun ∘. c₂.inv_fun)
class manifold {α:Type} [nondiscrete_normed_field α] (E : cartesian α ) (X:Top) :=
(struct1 : t2_space X)
(struct2 : second_countable_topology X)
(charts : set (chart X E))
(cover : ⋃₀ (chart.domain '' charts) = set.univ)
class manifold_prop {α:Type} [nondiscrete_normed_field α] (E : cartesian α ) (X:Top) extends manifold E X :=
(property: (E→. α) → Prop)
(compatible : ∀{{c₁ c₂}}, c₁ ∈ charts → c₂∈ charts → compatible_charts property c₁ c₂ )
|
46c14d2110283c51a1f4791914c79b08559efef4 | 958488bc7f3c2044206e0358e56d7690b6ae696c | /lean/while/Swap.lean | d7196e02c2878858a4c4ad0694cbc98219e08aec | [] | no_license | possientis/Prog | a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4 | d4b3debc37610a88e0dac3ac5914903604fd1d1f | refs/heads/master | 1,692,263,717,723 | 1,691,757,179,000 | 1,691,757,179,000 | 40,361,602 | 3 | 0 | null | 1,679,896,438,000 | 1,438,953,859,000 | Coq | UTF-8 | Lean | false | false | 2,520 | lean | import Stmt
import Subst
import Hoare
def Swap : Stmt :=
"t" :== x ;;
"x" :== y ;;
"y" :== aVar "t"
def p₁(n m:ℕ) : Pred := λ s, s "x" = n ∧ s "y" = m
def p₂(n m:ℕ) : Pred := λ s, s "x" = m ∧ s "y" = n
def p₃(n m:ℕ) : Pred := λ s, s "t" = n ∧ s "y" = m
def p₄(n m:ℕ) : Pred := λ s, s "x" = m ∧ s "t" = n
lemma L0 : "y" = "t" = false :=
begin
apply propext, split,
{ from dec_trivial },
{ intros H1, contradiction }
end
lemma L1 : ∀ (n m:ℕ), subst "t" x (p₃ n m) = p₁ n m :=
begin
intros n m,
unfold subst, unfold bindVar, unfold p₁, unfold p₃,
unfold x, unfold aVar,
apply funext, intros s, apply propext, split; intros H1; cases H1 with H1 H2,
{ simp at H1, cases decidable.em ("y" = "t") with H3 H3,
{ exfalso, revert H3, from dec_trivial},
{ simp [H3] at H2, split; assumption }},
{ split,
{ simp, assumption },
{ cases decidable.em ("y" = "t") with H3 H3,
{ exfalso, revert H3, from dec_trivial },
{ simp [H3], assumption }}}
end
lemma L2 : ∀ (n m:ℕ), subst "x" y (p₄ n m) = p₃ n m :=
begin
intros n m,
unfold subst, unfold bindVar, unfold p₃, unfold p₄, unfold y, unfold aVar,
apply funext, intros s, apply propext, split; intros H1; cases H1 with H1 H2,
{ simp at H1, cases decidable.em ("t" = "x") with H3 H3,
{ exfalso, revert H3, from dec_trivial },
{ simp [H3] at H2, split; assumption }},
{split,
{ simp, assumption },
{ cases decidable.em ("t" = "x") with H3 H3,
{ exfalso, revert H3, from dec_trivial },
{ simp [H3], assumption }}}
end
lemma L3 : ∀ (n m:ℕ), subst "y" (aVar "t") (p₂ n m) = p₄ n m :=
begin
intros n m,
unfold subst, unfold bindVar, unfold p₂, unfold p₄, unfold aVar,
apply funext, intros s, apply propext, split; intros H1; cases H1 with H1 H2,
{ simp at H2, cases decidable.em ("x" = "y") with H3 H3,
{ exfalso, revert H3, from dec_trivial },
{ simp [H3] at H1, split; assumption }},
{ simp, split,
{ cases decidable.em ("x" = "y") with H3 H3,
{ exfalso, revert H3, from dec_trivial },
{ simp [H3], assumption }},
{ assumption }}
end
lemma Swap_Correct : ∀ (n m:ℕ), Hoare (p₁ n m) Swap (p₂ n m) :=
begin
intros n m, unfold Swap, apply (seq_intro _ (p₃ n m)),
{ rw ← L1, apply assign_intro },
{ apply (seq_intro _ (p₄ n m)),
{ rw ← L2, apply assign_intro },
{ rw ← L3, apply assign_intro }}
end
|
b80c52b28b58d4e99b823edcd7ba54e5211777af | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/pequiv_auto.lean | 95848882e9e4bb888a65e9bf54f11029ce59949f | [] | 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 | 12,110 | lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.set.lattice
import Mathlib.PostPort
universes u v l u_1 w x u_2 u_3
namespace Mathlib
/-- A `pequiv` is a partial equivalence, a representation of a bijection between a subset
of `α` and a subset of `β` -/
structure pequiv (α : Type u) (β : Type v) where
to_fun : α → Option β
inv_fun : β → Option α
inv : ∀ (a : α) (b : β), a ∈ inv_fun b ↔ b ∈ to_fun a
infixr:25 " ≃. " => Mathlib.pequiv
namespace pequiv
protected instance has_coe_to_fun {α : Type u} {β : Type v} : has_coe_to_fun (α ≃. β) :=
has_coe_to_fun.mk (fun (x : α ≃. β) => α → Option β) to_fun
@[simp] theorem coe_mk_apply {α : Type u} {β : Type v} (f₁ : α → Option β) (f₂ : β → Option α)
(h : ∀ (a : α) (b : β), a ∈ f₂ b ↔ b ∈ f₁ a) (x : α) : coe_fn (mk f₁ f₂ h) x = f₁ x :=
rfl
theorem ext {α : Type u} {β : Type v} {f : α ≃. β} {g : α ≃. β}
(h : ∀ (x : α), coe_fn f x = coe_fn g x) : f = g :=
sorry
theorem ext_iff {α : Type u} {β : Type v} {f : α ≃. β} {g : α ≃. β} :
f = g ↔ ∀ (x : α), coe_fn f x = coe_fn g x :=
{ mp := congr_fun ∘ congr_arg fun {f : α ≃. β} (x : α) => coe_fn f x, mpr := ext }
protected def refl (α : Type u_1) : α ≃. α := mk some some sorry
protected def symm {α : Type u} {β : Type v} (f : α ≃. β) : β ≃. α :=
mk (inv_fun f) (to_fun f) sorry
theorem mem_iff_mem {α : Type u} {β : Type v} (f : α ≃. β) {a : α} {b : β} :
a ∈ coe_fn (pequiv.symm f) b ↔ b ∈ coe_fn f a :=
inv f
theorem eq_some_iff {α : Type u} {β : Type v} (f : α ≃. β) {a : α} {b : β} :
coe_fn (pequiv.symm f) b = some a ↔ coe_fn f a = some b :=
inv f
protected def trans {α : Type u} {β : Type v} {γ : Type w} (f : α ≃. β) (g : β ≃. γ) : α ≃. γ :=
mk (fun (a : α) => option.bind (coe_fn f a) ⇑g)
(fun (a : γ) => option.bind (coe_fn (pequiv.symm g) a) ⇑(pequiv.symm f)) sorry
@[simp] theorem refl_apply {α : Type u} (a : α) : coe_fn (pequiv.refl α) a = some a := rfl
@[simp] theorem symm_refl {α : Type u} : pequiv.symm (pequiv.refl α) = pequiv.refl α := rfl
@[simp] theorem symm_symm {α : Type u} {β : Type v} (f : α ≃. β) :
pequiv.symm (pequiv.symm f) = f :=
sorry
theorem symm_injective {α : Type u} {β : Type v} : function.injective pequiv.symm :=
function.left_inverse.injective symm_symm
theorem trans_assoc {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} (f : α ≃. β) (g : β ≃. γ)
(h : γ ≃. δ) : pequiv.trans (pequiv.trans f g) h = pequiv.trans f (pequiv.trans g h) :=
ext fun (_x : α) => option.bind_assoc (coe_fn f _x) ⇑g ⇑h
theorem mem_trans {α : Type u} {β : Type v} {γ : Type w} (f : α ≃. β) (g : β ≃. γ) (a : α) (c : γ) :
c ∈ coe_fn (pequiv.trans f g) a ↔ ∃ (b : β), b ∈ coe_fn f a ∧ c ∈ coe_fn g b :=
option.bind_eq_some'
theorem trans_eq_some {α : Type u} {β : Type v} {γ : Type w} (f : α ≃. β) (g : β ≃. γ) (a : α)
(c : γ) :
coe_fn (pequiv.trans f g) a = some c ↔ ∃ (b : β), coe_fn f a = some b ∧ coe_fn g b = some c :=
option.bind_eq_some'
theorem trans_eq_none {α : Type u} {β : Type v} {γ : Type w} (f : α ≃. β) (g : β ≃. γ) (a : α) :
coe_fn (pequiv.trans f g) a = none ↔ ∀ (b : β) (c : γ), ¬b ∈ coe_fn f a ∨ ¬c ∈ coe_fn g b :=
sorry
@[simp] theorem refl_trans {α : Type u} {β : Type v} (f : α ≃. β) :
pequiv.trans (pequiv.refl α) f = f :=
ext fun (x : α) => option.ext fun (a : β) => id (iff.refl (a ∈ coe_fn f x))
@[simp] theorem trans_refl {α : Type u} {β : Type v} (f : α ≃. β) :
pequiv.trans f (pequiv.refl β) = f :=
sorry
protected theorem inj {α : Type u} {β : Type v} (f : α ≃. β) {a₁ : α} {a₂ : α} {b : β}
(h₁ : b ∈ coe_fn f a₁) (h₂ : b ∈ coe_fn f a₂) : a₁ = a₂ :=
sorry
theorem injective_of_forall_ne_is_some {α : Type u} {β : Type v} (f : α ≃. β) (a₂ : α)
(h : ∀ (a₁ : α), a₁ ≠ a₂ → ↥(option.is_some (coe_fn f a₁))) : function.injective ⇑f :=
sorry
theorem injective_of_forall_is_some {α : Type u} {β : Type v} {f : α ≃. β}
(h : ∀ (a : α), ↥(option.is_some (coe_fn f a))) : function.injective ⇑f :=
sorry
def of_set {α : Type u} (s : set α) [decidable_pred s] : α ≃. α :=
mk (fun (a : α) => ite (a ∈ s) (some a) none) (fun (a : α) => ite (a ∈ s) (some a) none) sorry
theorem mem_of_set_self_iff {α : Type u} {s : set α} [decidable_pred s] {a : α} :
a ∈ coe_fn (of_set s) a ↔ a ∈ s :=
sorry
theorem mem_of_set_iff {α : Type u} {s : set α} [decidable_pred s] {a : α} {b : α} :
a ∈ coe_fn (of_set s) b ↔ a = b ∧ a ∈ s :=
sorry
@[simp] theorem of_set_eq_some_iff {α : Type u} {s : set α} {h : decidable_pred s} {a : α} {b : α} :
coe_fn (of_set s) b = some a ↔ a = b ∧ a ∈ s :=
mem_of_set_iff
@[simp] theorem of_set_eq_some_self_iff {α : Type u} {s : set α} {h : decidable_pred s} {a : α} :
coe_fn (of_set s) a = some a ↔ a ∈ s :=
mem_of_set_self_iff
@[simp] theorem of_set_symm {α : Type u} (s : set α) [decidable_pred s] :
pequiv.symm (of_set s) = of_set s :=
rfl
@[simp] theorem of_set_univ {α : Type u} : of_set set.univ = pequiv.refl α := rfl
@[simp] theorem of_set_eq_refl {α : Type u} {s : set α} [decidable_pred s] :
of_set s = pequiv.refl α ↔ s = set.univ :=
sorry
theorem symm_trans_rev {α : Type u} {β : Type v} {γ : Type w} (f : α ≃. β) (g : β ≃. γ) :
pequiv.symm (pequiv.trans f g) = pequiv.trans (pequiv.symm g) (pequiv.symm f) :=
rfl
theorem trans_symm {α : Type u} {β : Type v} (f : α ≃. β) :
pequiv.trans f (pequiv.symm f) =
of_set (set_of fun (a : α) => ↥(option.is_some (coe_fn f a))) :=
sorry
theorem symm_trans {α : Type u} {β : Type v} (f : α ≃. β) :
pequiv.trans (pequiv.symm f) f =
of_set (set_of fun (b : β) => ↥(option.is_some (coe_fn (pequiv.symm f) b))) :=
sorry
theorem trans_symm_eq_iff_forall_is_some {α : Type u} {β : Type v} {f : α ≃. β} :
pequiv.trans f (pequiv.symm f) = pequiv.refl α ↔ ∀ (a : α), ↥(option.is_some (coe_fn f a)) :=
sorry
protected instance has_bot {α : Type u} {β : Type v} : has_bot (α ≃. β) :=
has_bot.mk (mk (fun (_x : α) => none) (fun (_x : β) => none) sorry)
@[simp] theorem bot_apply {α : Type u} {β : Type v} (a : α) : coe_fn ⊥ a = none := rfl
@[simp] theorem symm_bot {α : Type u} {β : Type v} : pequiv.symm ⊥ = ⊥ := rfl
@[simp] theorem trans_bot {α : Type u} {β : Type v} {γ : Type w} (f : α ≃. β) :
pequiv.trans f ⊥ = ⊥ :=
sorry
@[simp] theorem bot_trans {α : Type u} {β : Type v} {γ : Type w} (f : β ≃. γ) :
pequiv.trans ⊥ f = ⊥ :=
sorry
theorem is_some_symm_get {α : Type u} {β : Type v} (f : α ≃. β) {a : α}
(h : ↥(option.is_some (coe_fn f a))) :
↥(option.is_some (coe_fn (pequiv.symm f) (option.get h))) :=
sorry
def single {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] (a : α) (b : β) : α ≃. β :=
mk (fun (x : α) => ite (x = a) (some b) none) (fun (x : β) => ite (x = b) (some a) none) sorry
theorem mem_single {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] (a : α) (b : β) :
b ∈ coe_fn (single a b) a :=
if_pos rfl
theorem mem_single_iff {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] (a₁ : α) (a₂ : α)
(b₁ : β) (b₂ : β) : b₁ ∈ coe_fn (single a₂ b₂) a₁ ↔ a₁ = a₂ ∧ b₁ = b₂ :=
sorry
@[simp] theorem symm_single {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] (a : α)
(b : β) : pequiv.symm (single a b) = single b a :=
rfl
@[simp] theorem single_apply {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] (a : α)
(b : β) : coe_fn (single a b) a = some b :=
if_pos rfl
theorem single_apply_of_ne {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] {a₁ : α}
{a₂ : α} (h : a₁ ≠ a₂) (b : β) : coe_fn (single a₁ b) a₂ = none :=
if_neg (ne.symm h)
theorem single_trans_of_mem {α : Type u} {β : Type v} {γ : Type w} [DecidableEq α] [DecidableEq β]
[DecidableEq γ] (a : α) {b : β} {c : γ} {f : β ≃. γ} (h : c ∈ coe_fn f b) :
pequiv.trans (single a b) f = single a c :=
sorry
theorem trans_single_of_mem {α : Type u} {β : Type v} {γ : Type w} [DecidableEq α] [DecidableEq β]
[DecidableEq γ] {a : α} {b : β} (c : γ) {f : α ≃. β} (h : b ∈ coe_fn f a) :
pequiv.trans f (single b c) = single a c :=
symm_injective (single_trans_of_mem c (iff.mpr (mem_iff_mem f) h))
@[simp] theorem single_trans_single {α : Type u} {β : Type v} {γ : Type w} [DecidableEq α]
[DecidableEq β] [DecidableEq γ] (a : α) (b : β) (c : γ) :
pequiv.trans (single a b) (single b c) = single a c :=
single_trans_of_mem a (mem_single b c)
@[simp] theorem single_subsingleton_eq_refl {α : Type u} [DecidableEq α] [subsingleton α] (a : α)
(b : α) : single a b = pequiv.refl α :=
sorry
theorem trans_single_of_eq_none {β : Type v} {γ : Type w} {δ : Type x} [DecidableEq β]
[DecidableEq γ] {b : β} (c : γ) {f : δ ≃. β} (h : coe_fn (pequiv.symm f) b = none) :
pequiv.trans f (single b c) = ⊥ :=
sorry
theorem single_trans_of_eq_none {α : Type u} {β : Type v} {δ : Type x} [DecidableEq α]
[DecidableEq β] (a : α) {b : β} {f : β ≃. δ} (h : coe_fn f b = none) :
pequiv.trans (single a b) f = ⊥ :=
symm_injective (trans_single_of_eq_none a h)
theorem single_trans_single_of_ne {α : Type u} {β : Type v} {γ : Type w} [DecidableEq α]
[DecidableEq β] [DecidableEq γ] {b₁ : β} {b₂ : β} (h : b₁ ≠ b₂) (a : α) (c : γ) :
pequiv.trans (single a b₁) (single b₂ c) = ⊥ :=
single_trans_of_eq_none a (single_apply_of_ne (ne.symm h) c)
protected instance partial_order {α : Type u} {β : Type v} : partial_order (α ≃. β) :=
partial_order.mk (fun (f g : α ≃. β) => ∀ (a : α) (b : β), b ∈ coe_fn f a → b ∈ coe_fn g a)
(preorder.lt._default fun (f g : α ≃. β) => ∀ (a : α) (b : β), b ∈ coe_fn f a → b ∈ coe_fn g a)
sorry sorry sorry
theorem le_def {α : Type u} {β : Type v} {f : α ≃. β} {g : α ≃. β} :
f ≤ g ↔ ∀ (a : α) (b : β), b ∈ coe_fn f a → b ∈ coe_fn g a :=
iff.rfl
protected instance order_bot {α : Type u} {β : Type v} : order_bot (α ≃. β) :=
order_bot.mk ⊥ partial_order.le partial_order.lt sorry sorry sorry sorry
protected instance semilattice_inf_bot {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] :
semilattice_inf_bot (α ≃. β) :=
semilattice_inf_bot.mk order_bot.bot order_bot.le order_bot.lt sorry sorry sorry sorry
(fun (f g : α ≃. β) =>
mk (fun (a : α) => ite (coe_fn f a = coe_fn g a) (coe_fn f a) none)
(fun (b : β) =>
ite (coe_fn (pequiv.symm f) b = coe_fn (pequiv.symm g) b) (coe_fn (pequiv.symm f) b) none)
sorry)
sorry sorry sorry
end pequiv
namespace equiv
def to_pequiv {α : Type u_1} {β : Type u_2} (f : α ≃ β) : α ≃. β :=
pequiv.mk (some ∘ ⇑f) (some ∘ ⇑(equiv.symm f)) sorry
@[simp] theorem to_pequiv_refl {α : Type u_1} : to_pequiv (equiv.refl α) = pequiv.refl α := rfl
theorem to_pequiv_trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α ≃ β) (g : β ≃ γ) :
to_pequiv (equiv.trans f g) = pequiv.trans (to_pequiv f) (to_pequiv g) :=
rfl
theorem to_pequiv_symm {α : Type u_1} {β : Type u_2} (f : α ≃ β) :
to_pequiv (equiv.symm f) = pequiv.symm (to_pequiv f) :=
rfl
theorem to_pequiv_apply {α : Type u_1} {β : Type u_2} (f : α ≃ β) (x : α) :
coe_fn (to_pequiv f) x = some (coe_fn f x) :=
rfl
end Mathlib |
66a776e4ba823f92cf694c7412d732e6d222f48d | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/elab_failure.lean | 01aa3f986d69dab51e2bf9f0a7c1f9820522a8c0 | [
"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 | 404 | lean | open bool nat
attribute [reducible] nat.rec_on
definition is_eq (a b : nat) : bool :=
nat.rec_on a
(λ b, nat.cases_on b tt (λb₁, ff))
(λ a₁ r₁ b, nat.cases_on b ff (λb₁, r₁ b₁))
b
example (a₁ : nat) (b : nat) : true :=
@nat.cases_on (λ (n : nat), true) b
true.intro
(λ (b₁ : _),
have aux : is_eq a₁ b₁ = is_eq (succ a₁) (succ b₁), from rfl,
true.intro)
|
7884f72f43892bb7898d9f8072ce203885b85536 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/normed_space/pointwise.lean | 36dfb61d618c4ff5daf024c2c85d751fea3fb942 | [
"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 | 5,588 | lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.normed.group.pointwise
import analysis.normed_space.basic
import topology.metric_space.hausdorff_distance
/-!
# Properties of pointwise scalar multiplication of sets in normed spaces.
We explore the relationships between scalar multiplication of sets in vector spaces, and the norm.
Notably, we express arbitrary balls as rescaling of other balls, and we show that the
multiplication of bounded sets remain bounded.
-/
open metric set
open_locale pointwise topological_space
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] {E : Type*} [semi_normed_group E] [normed_space 𝕜 E]
theorem smul_ball {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :
c • ball x r = ball (c • x) (∥c∥ * r) :=
begin
ext y,
rw mem_smul_set_iff_inv_smul_mem₀ hc,
conv_lhs { rw ←inv_smul_smul₀ hc x },
simp [← div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hc), mul_comm _ r, dist_smul],
end
theorem smul_sphere' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :
c • sphere x r = sphere (c • x) (∥c∥ * r) :=
begin
ext y,
rw mem_smul_set_iff_inv_smul_mem₀ hc,
conv_lhs { rw ←inv_smul_smul₀ hc x },
simp only [mem_sphere, dist_smul, normed_field.norm_inv, ← div_eq_inv_mul,
div_eq_iff (norm_pos_iff.2 hc).ne', mul_comm r],
end
/-- In a nontrivial real normed space, a sphere is nonempty if and only if its radius is
nonnegative. -/
@[simp] theorem normed_space.sphere_nonempty {E : Type*} [normed_group E]
[normed_space ℝ E] [nontrivial E] {x : E} {r : ℝ} :
(sphere x r).nonempty ↔ 0 ≤ r :=
begin
refine ⟨λ h, nonempty_closed_ball.1 (h.mono sphere_subset_closed_ball), λ hr, _⟩,
rcases exists_ne x with ⟨y, hy⟩,
have : ∥y - x∥ ≠ 0, by simpa [sub_eq_zero],
use r • ∥y - x∥⁻¹ • (y - x) + x,
simp [norm_smul, this, real.norm_of_nonneg hr]
end
theorem smul_sphere {E : Type*} [normed_group E] [normed_space 𝕜 E] [normed_space ℝ E]
[nontrivial E] (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) :
c • sphere x r = sphere (c • x) (∥c∥ * r) :=
begin
rcases eq_or_ne c 0 with rfl|hc,
{ simp [zero_smul_set, set.singleton_zero, hr] },
{ exact smul_sphere' hc x r }
end
theorem smul_closed_ball' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :
c • closed_ball x r = closed_ball (c • x) (∥c∥ * r) :=
by simp only [← ball_union_sphere, set.smul_set_union, smul_ball hc, smul_sphere' hc]
lemma metric.bounded.smul {s : set E} (hs : bounded s) (c : 𝕜) :
bounded (c • s) :=
begin
obtain ⟨R, hR⟩ : ∃ (R : ℝ), ∀ x ∈ s, ∥x∥ ≤ R := hs.exists_norm_le,
refine (bounded_iff_exists_norm_le).2 ⟨∥c∥ * R, _⟩,
assume z hz,
obtain ⟨y, ys, rfl⟩ : ∃ (y : E), y ∈ s ∧ c • y = z := mem_smul_set.1 hz,
calc ∥c • y∥ = ∥c∥ * ∥y∥ : norm_smul _ _
... ≤ ∥c∥ * R : mul_le_mul_of_nonneg_left (hR y ys) (norm_nonneg _)
end
/-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r • s` is contained in any
fixed neighborhood of `x`. -/
lemma eventually_singleton_add_smul_subset
{x : E} {s : set E} (hs : bounded s) {u : set E} (hu : u ∈ 𝓝 x) :
∀ᶠ r in 𝓝 (0 : 𝕜), {x} + r • s ⊆ u :=
begin
obtain ⟨ε, εpos, hε⟩ : ∃ ε (hε : 0 < ε), closed_ball x ε ⊆ u :=
nhds_basis_closed_ball.mem_iff.1 hu,
obtain ⟨R, Rpos, hR⟩ : ∃ (R : ℝ), 0 < R ∧ s ⊆ closed_ball 0 R := hs.subset_ball_lt 0 0,
have : metric.closed_ball (0 : 𝕜) (ε / R) ∈ 𝓝 (0 : 𝕜) :=
closed_ball_mem_nhds _ (div_pos εpos Rpos),
filter_upwards [this] with r hr,
simp only [image_add_left, singleton_add],
assume y hy,
obtain ⟨z, zs, hz⟩ : ∃ (z : E), z ∈ s ∧ r • z = -x + y, by simpa [mem_smul_set] using hy,
have I : ∥r • z∥ ≤ ε := calc
∥r • z∥ = ∥r∥ * ∥z∥ : norm_smul _ _
... ≤ (ε / R) * R :
mul_le_mul (mem_closed_ball_zero_iff.1 hr)
(mem_closed_ball_zero_iff.1 (hR zs)) (norm_nonneg _) (div_pos εpos Rpos).le
... = ε : by field_simp [Rpos.ne'],
have : y = x + r • z, by simp only [hz, add_neg_cancel_left],
apply hε,
simpa only [this, dist_eq_norm, add_sub_cancel', mem_closed_ball] using I,
end
lemma set_smul_mem_nhds_zero {s : set E} (hs : s ∈ 𝓝 (0 : E)) {c : 𝕜} (hc : c ≠ 0) :
c • s ∈ 𝓝 (0 : E) :=
begin
obtain ⟨ε, εpos, hε⟩ : ∃ (ε : ℝ) (H : 0 < ε), ball 0 ε ⊆ s := metric.mem_nhds_iff.1 hs,
have : c • ball (0 : E) ε ∈ 𝓝 (0 : E),
{ rw [smul_ball hc, smul_zero],
exact ball_mem_nhds _ (mul_pos (by simpa using hc) εpos) },
exact filter.mem_of_superset this ((set_smul_subset_set_smul_iff₀ hc).2 hε)
end
lemma set_smul_mem_nhds_zero_iff (s : set E) {c : 𝕜} (hc : c ≠ 0) :
c • s ∈ 𝓝 (0 : E) ↔ s ∈ 𝓝(0 : E) :=
begin
refine ⟨λ h, _, λ h, set_smul_mem_nhds_zero h hc⟩,
convert set_smul_mem_nhds_zero h (inv_ne_zero hc),
rw [smul_smul, inv_mul_cancel hc, one_smul],
end
end normed_space
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E]
theorem smul_closed_ball (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) :
c • closed_ball x r = closed_ball (c • x) (∥c∥ * r) :=
begin
rcases eq_or_ne c 0 with rfl|hc,
{ simp [hr, zero_smul_set, set.singleton_zero, ← nonempty_closed_ball] },
{ exact smul_closed_ball' hc x r }
end
end normed_space
|
d739cd16edc541b5a8c42a1571130691c8953b2c | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/ring_theory/principal_ideal_domain.lean | 21127a7c34004d8c3dfefde2d0b5ba2258b149c5 | [
"Apache-2.0"
] | permissive | kmill/mathlib | ea5a007b67ae4e9e18dd50d31d8aa60f650425ee | 1a419a9fea7b959317eddd556e1bb9639f4dcc05 | refs/heads/master | 1,668,578,197,719 | 1,593,629,163,000 | 1,593,629,163,000 | 276,482,939 | 0 | 0 | null | 1,593,637,960,000 | 1,593,637,959,000 | null | UTF-8 | Lean | false | false | 8,161 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Chris Hughes, Morenikeji Neri
-/
import ring_theory.noetherian
import ring_theory.unique_factorization_domain
/-!
# Principal ideal rings and principal ideal domains
A principal ideal ring (PIR) is a commutative ring in which all ideals are principal. A
principal ideal domain (PID) is an integral domain which is a principal ideal ring.
# Main definitions
Note that for principal ideal domains, one should use
`[integral domain R] [is_principal_ideal_ring R]`. There is no explicit definition of a PID.
Theorems about PID's are in the `principal_ideal_ring` namespace.
- `is_principal_ideal_ring`: a predicate on commutative rings, saying that every
ideal is principal.
- `generator`: a generator of a principal ideal (or more generally submodule)
- `to_unique_factorization_domain`: a noncomputable definition, putting a UFD structure on a PID.
Note that the definition of a UFD is currently not a predicate, as it contains data
of factorizations of non-zero elements.
# Main results
- `to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.
- `euclidean_domain.to_principal_ideal_domain` : a Euclidean domain is a PID.
-/
universes u v
variables {R : Type u} {M : Type v}
open set function
open submodule
open_locale classical
/-- An `R`-submodule of `M` is principal if it is generated by one element. -/
class submodule.is_principal [ring R] [add_comm_group M] [module R M] (S : submodule R M) : Prop :=
(principal [] : ∃ a, S = span R {a})
/-- A commutative ring is a principal ideal ring if all ideals are principal. -/
class is_principal_ideal_ring (R : Type u) [comm_ring R] : Prop :=
(principal : ∀ (S : ideal R), S.is_principal)
attribute [instance] is_principal_ideal_ring.principal
namespace submodule.is_principal
variables [comm_ring R] [add_comm_group M] [module R M]
/-- `generator I`, if `I` is a principal submodule, is the `x ∈ M` such that `span R {x} = I` -/
noncomputable def generator (S : submodule R M) [S.is_principal] : M :=
classical.some (principal S)
lemma span_singleton_generator (S : submodule R M) [S.is_principal] : span R {generator S} = S :=
eq.symm (classical.some_spec (principal S))
@[simp] lemma generator_mem (S : submodule R M) [S.is_principal] : generator S ∈ S :=
by { conv_rhs { rw ← span_singleton_generator S }, exact subset_span (mem_singleton _) }
lemma mem_iff_eq_smul_generator (S : submodule R M) [S.is_principal] {x : M} :
x ∈ S ↔ ∃ s : R, x = s • generator S :=
by simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator]
lemma mem_iff_generator_dvd (S : ideal R) [S.is_principal] {x : R} : x ∈ S ↔ generator S ∣ x :=
(mem_iff_eq_smul_generator S).trans (exists_congr (λ a, by simp only [mul_comm, smul_eq_mul]))
lemma eq_bot_iff_generator_eq_zero (S : submodule R M) [S.is_principal] :
S = ⊥ ↔ generator S = 0 :=
by rw [← @span_singleton_eq_bot R M, span_singleton_generator]
end submodule.is_principal
namespace is_prime
open submodule.is_principal ideal
-- TODO -- for a non-ID should prove that if p < q then q maximal; 0 isn't prime in a non-ID
lemma to_maximal_ideal [integral_domain R] [is_principal_ideal_ring R] {S : ideal R}
[hpi : is_prime S] (hS : S ≠ ⊥) : is_maximal S :=
is_maximal_iff.2 ⟨(ne_top_iff_one S).1 hpi.1, begin
assume T x hST hxS hxT,
cases (mem_iff_generator_dvd _).1 (hST $ generator_mem S) with z hz,
cases hpi.2 (show generator T * z ∈ S, from hz ▸ generator_mem S),
{ have hTS : T ≤ S, rwa [← span_singleton_generator T, submodule.span_le, singleton_subset_iff],
exact (hxS $ hTS hxT).elim },
cases (mem_iff_generator_dvd _).1 h with y hy,
have : generator S ≠ 0 := mt (eq_bot_iff_generator_eq_zero _).2 hS,
rw [← mul_one (generator S), hy, mul_left_comm, domain.mul_right_inj this] at hz,
exact hz.symm ▸ ideal.mul_mem_right _ (generator_mem T)
end⟩
end is_prime
section
open euclidean_domain
variable [euclidean_domain R]
lemma mod_mem_iff {S : ideal R} {x y : R} (hy : y ∈ S) : x % y ∈ S ↔ x ∈ S :=
⟨λ hxy, div_add_mod x y ▸ ideal.add_mem S (ideal.mul_mem_right S hy) hxy,
λ hx, (mod_eq_sub_mul_div x y).symm ▸ ideal.sub_mem S hx (ideal.mul_mem_right S hy)⟩
@[priority 100] -- see Note [lower instance priority]
instance euclidean_domain.to_principal_ideal_domain : is_principal_ideal_ring R :=
{ principal := λ S, by exactI
⟨if h : {x : R | x ∈ S ∧ x ≠ 0}.nonempty
then
have wf : well_founded (euclidean_domain.r : R → R → Prop) := euclidean_domain.r_well_founded,
have hmin : well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h ∈ S ∧
well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h ≠ 0,
from well_founded.min_mem wf {x : R | x ∈ S ∧ x ≠ 0} h,
⟨well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h,
submodule.ext $ λ x,
⟨λ hx, div_add_mod x (well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h) ▸
(ideal.mem_span_singleton.2 $ dvd_add (dvd_mul_right _ _) $
have (x % (well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h) ∉ {x : R | x ∈ S ∧ x ≠ 0}),
from λ h₁, well_founded.not_lt_min wf _ h h₁ (mod_lt x hmin.2),
have x % well_founded.min wf {x : R | x ∈ S ∧ x ≠ 0} h = 0, by finish [(mod_mem_iff hmin.1).2 hx],
by simp *),
λ hx, let ⟨y, hy⟩ := ideal.mem_span_singleton.1 hx in hy.symm ▸ ideal.mul_mem_right _ hmin.1⟩⟩
else ⟨0, submodule.ext $ λ a, by rw [← @submodule.bot_coe R R _ _ _, span_eq, submodule.mem_bot]; exact
⟨λ haS, by_contradiction $ λ ha0, h ⟨a, ⟨haS, ha0⟩⟩,
λ h₁, h₁.symm ▸ S.zero_mem⟩⟩⟩ }
end
namespace principal_ideal_ring
open is_principal_ideal_ring
variables [integral_domain R] [is_principal_ideal_ring R]
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian_ring : is_noetherian_ring R :=
⟨assume s : ideal R,
begin
rcases (is_principal_ideal_ring.principal s).principal with ⟨a, rfl⟩,
rw [← finset.coe_singleton],
exact ⟨{a}, submodule.coe_injective rfl⟩
end⟩
lemma is_maximal_of_irreducible {p : R} (hp : irreducible p) :
ideal.is_maximal (span R ({p} : set R)) :=
⟨mt ideal.span_singleton_eq_top.1 hp.1, λ I hI, begin
rcases principal I with ⟨a, rfl⟩,
erw ideal.span_singleton_eq_top,
unfreezingI { rcases ideal.span_singleton_le_span_singleton.1 (le_of_lt hI) with ⟨b, rfl⟩ },
refine (of_irreducible_mul hp).resolve_right (mt (λ hb, _) (not_le_of_lt hI)),
erw [ideal.span_singleton_le_span_singleton, mul_dvd_of_is_unit_right hb]
end⟩
lemma irreducible_iff_prime {p : R} : irreducible p ↔ prime p :=
⟨λ hp, (ideal.span_singleton_prime hp.ne_zero).1 $
(is_maximal_of_irreducible hp).is_prime,
irreducible_of_prime⟩
lemma associates_irreducible_iff_prime : ∀{p : associates R}, irreducible p ↔ p.prime :=
associates.forall_associated.2 $ assume a,
by rw [associates.irreducible_mk_iff, associates.prime_mk, irreducible_iff_prime]
section
open_locale classical
/-- `factors a` is a multiset of irreducible elements whose product is `a`, up to units -/
noncomputable def factors (a : R) : multiset R :=
if h : a = 0 then ∅ else classical.some
(is_noetherian_ring.exists_factors a h)
lemma factors_spec (a : R) (h : a ≠ 0) :
(∀b∈factors a, irreducible b) ∧ associated a (factors a).prod :=
begin
unfold factors, rw [dif_neg h],
exact classical.some_spec
(is_noetherian_ring.exists_factors a h)
end
/-- The unique factorization domain structure given by the principal ideal domain.
This is not added as type class instance, since the `factors` might be computed in a different way.
E.g. factors could return normalized values.
-/
noncomputable def to_unique_factorization_domain : unique_factorization_domain R :=
{ factors := factors,
factors_prod := assume a ha, associated.symm (factors_spec a ha).2,
prime_factors := assume a ha, by simpa [irreducible_iff_prime] using (factors_spec a ha).1 }
end
end principal_ideal_ring
|
9ed46632898ef0dfb3b7f314ca880400fa5c2309 | b2fe74b11b57d362c13326bc5651244f111fa6f4 | /src/data/complex/is_R_or_C.lean | d80dcb4da37b099ee88b0df34d389a327dcd1e91 | [
"Apache-2.0"
] | permissive | midfield/mathlib | c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7 | 775edc615ecec631d65b6180dbcc7bc26c3abc26 | refs/heads/master | 1,675,330,551,921 | 1,608,304,514,000 | 1,608,304,514,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,981 | lean | /-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import analysis.normed_space.basic
import analysis.complex.basic
/-!
# `is_R_or_C`: a typeclass for ℝ or ℂ
This file defines the typeclass `is_R_or_C` intended to have only two instances:
ℝ and ℂ. It is meant for definitions and theorems which hold for both the real and the complex case,
and in particular when the real case follows directly from the complex case by setting `re` to `id`,
`im` to zero and so on. Its API follows closely that of ℂ.
Possible applications include defining inner products and Hilbert spaces for both the real and
complex case. One would produce the definitions and proof for an arbitrary field of this
typeclass, which basically amounts to doing the complex case, and the two cases then fall out
immediately from the two instances of the class.
## Implementation notes
The coercion from reals into an `is_R_or_C` field is done by registering `algebra_map ℝ K` as
a `has_coe_t`. For this to work, we must proceed carefully to avoid problems involving circular
coercions in the case `K=ℝ`; in particular, we cannot use the plain `has_coe` and must set
priorities carefully. This problem was already solved for `ℕ`, and we copy the solution detailed
in `data/nat/cast`. See also Note [coercion into rings] for more details.
In addition, several lemmas need to be set at priority 900 to make sure that they do not override
their counterparts in `complex.lean` (which causes linter errors).
-/
open_locale big_operators
section
local notation `𝓚` := algebra_map ℝ _
/--
This typeclass captures properties shared by ℝ and ℂ, with an API that closely matches that of ℂ.
-/
class is_R_or_C (K : Type*) extends nondiscrete_normed_field K, normed_algebra ℝ K, complete_space K :=
(re : K →+ ℝ)
(im : K →+ ℝ)
(conj : K →+* K)
(I : K) -- Meant to be set to 0 for K=ℝ
(I_re_ax : re I = 0)
(I_mul_I_ax : I = 0 ∨ I * I = -1)
(re_add_im_ax : ∀ (z : K), 𝓚 (re z) + 𝓚 (im z) * I = z)
(of_real_re_ax : ∀ r : ℝ, re (𝓚 r) = r)
(of_real_im_ax : ∀ r : ℝ, im (𝓚 r) = 0)
(mul_re_ax : ∀ z w : K, re (z * w) = re z * re w - im z * im w)
(mul_im_ax : ∀ z w : K, im (z * w) = re z * im w + im z * re w)
(conj_re_ax : ∀ z : K, re (conj z) = re z)
(conj_im_ax : ∀ z : K, im (conj z) = -(im z))
(conj_I_ax : conj I = -I)
(norm_sq_eq_def_ax : ∀ (z : K), ∥z∥^2 = (re z) * (re z) + (im z) * (im z))
(mul_im_I_ax : ∀ (z : K), (im z) * im I = im z)
(inv_def_ax : ∀ (z : K), z⁻¹ = conj z * 𝓚 ((∥z∥^2)⁻¹))
(div_I_ax : ∀ (z : K), z / I = -(z * I))
end
namespace is_R_or_C
variables {K : Type*} [is_R_or_C K]
local postfix `†`:100 := @is_R_or_C.conj K _
/- The priority must be set at 900 to ensure that coercions are tried in the right order.
See Note [coercion into rings], or `data/nat/cast.lean` for more details. -/
@[priority 900] noncomputable instance algebra_map_coe : has_coe_t ℝ K := ⟨algebra_map ℝ K⟩
lemma of_real_alg (x : ℝ) : (x : K) = x • (1 : K) :=
algebra.algebra_map_eq_smul_one x
lemma algebra_map_eq_of_real : ⇑(algebra_map ℝ K) = coe := rfl
@[simp] lemma re_add_im (z : K) : ((re z) : K) + (im z) * I = z := is_R_or_C.re_add_im_ax z
@[simp, norm_cast] lemma of_real_re : ∀ r : ℝ, re (r : K) = r := is_R_or_C.of_real_re_ax
@[simp, norm_cast] lemma of_real_im : ∀ r : ℝ, im (r : K) = 0 := is_R_or_C.of_real_im_ax
@[simp] lemma mul_re : ∀ z w : K, re (z * w) = re z * re w - im z * im w :=
is_R_or_C.mul_re_ax
@[simp] lemma mul_im : ∀ z w : K, im (z * w) = re z * im w + im z * re w :=
is_R_or_C.mul_im_ax
theorem inv_def (z : K) : z⁻¹ = conj z * ((∥z∥^2)⁻¹:ℝ) :=
is_R_or_C.inv_def_ax z
theorem ext_iff : ∀ {z w : K}, z = w ↔ re z = re w ∧ im z = im w :=
λ z w, { mp := by { rintro rfl, cc },
mpr := by { rintro ⟨h₁,h₂⟩, rw [←re_add_im z, ←re_add_im w, h₁, h₂] } }
theorem ext : ∀ {z w : K}, re z = re w → im z = im w → z = w :=
by { simp_rw ext_iff, cc }
@[simp, norm_cast, priority 900] lemma of_real_zero : ((0 : ℝ) : K) = 0 :=
by rw [of_real_alg, zero_smul]
@[simp] lemma zero_re' : re (0 : K) = (0 : ℝ) := re.map_zero
@[simp, norm_cast, priority 900] lemma of_real_one : ((1 : ℝ) : K) = 1 :=
by rw [of_real_alg, one_smul]
@[simp] lemma one_re : re (1 : K) = 1 := by rw [←of_real_one, of_real_re]
@[simp] lemma one_im : im (1 : K) = 0 := by rw [←of_real_one, of_real_im]
@[simp, norm_cast, priority 900] theorem of_real_inj {z w : ℝ} : (z : K) = (w : K) ↔ z = w :=
{ mp := λ h, by { convert congr_arg re h; simp only [of_real_re] },
mpr := λ h, by rw h }
@[simp] lemma bit0_re (z : K) : re (bit0 z) = bit0 (re z) := by simp [bit0]
@[simp] lemma bit1_re (z : K) : re (bit1 z) = bit1 (re z) :=
by simp only [bit1, add_monoid_hom.map_add, bit0_re, add_right_inj, one_re]
@[simp] lemma bit0_im (z : K) : im (bit0 z) = bit0 (im z) := by simp [bit0]
@[simp] lemma bit1_im (z : K) : im (bit1 z) = bit0 (im z) :=
by simp only [bit1, add_right_eq_self, add_monoid_hom.map_add, bit0_im, one_im]
@[simp, priority 900] theorem of_real_eq_zero {z : ℝ} : (z : K) = 0 ↔ z = 0 :=
by rw [←of_real_zero]; exact of_real_inj
@[simp, norm_cast, priority 900] lemma of_real_add ⦃r s : ℝ⦄ : ((r + s : ℝ) : K) = r + s :=
by { apply (@is_R_or_C.ext_iff K _ ((r + s : ℝ) : K) (r + s)).mpr, simp }
@[simp, norm_cast, priority 900] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : K) = bit0 (r : K) :=
ext_iff.2 $ by simp [bit0]
@[simp, norm_cast, priority 900] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : K) = bit1 (r : K) :=
ext_iff.2 $ by simp [bit1]
/- Note: This can be proven by `norm_num` once K is proven to be of characteristic zero below. -/
lemma two_ne_zero : (2 : K) ≠ 0 :=
begin
intro h, rw [(show (2 : K) = ((2 : ℝ) : K), by norm_num), ←of_real_zero, of_real_inj] at h,
linarith,
end
@[simp, norm_cast, priority 900] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : K) = -r :=
ext_iff.2 $ by simp
@[simp, norm_cast, priority 900] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : K) = r * s :=
ext_iff.2 $ by simp
lemma of_real_mul_re (r : ℝ) (z : K) : re (↑r * z) = r * re z :=
by simp only [mul_re, of_real_im, zero_mul, of_real_re, sub_zero]
lemma smul_re (r : ℝ) (z : K) : re (↑r * z) = r * (re z) :=
by simp only [of_real_im, zero_mul, of_real_re, sub_zero, mul_re]
lemma smul_im (r : ℝ) (z : K) : im (↑r * z) = r * (im z) :=
by simp only [add_zero, of_real_im, zero_mul, of_real_re, mul_im]
lemma smul_re' : ∀ (r : ℝ) (z : K), re (r • z) = r * (re z) :=
λ r z, by { rw algebra.smul_def, apply smul_re }
lemma smul_im' : ∀ (r : ℝ) (z : K), im (r • z) = r * (im z) :=
λ r z, by { rw algebra.smul_def, apply smul_im }
/-- The real part in a `is_R_or_C` field, as a linear map. -/
noncomputable def re_lm : K →ₗ[ℝ] ℝ :=
{ map_smul' := smul_re', .. re }
@[simp] lemma re_lm_coe : (re_lm : K → ℝ) = re := rfl
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
@[simp] lemma I_re : re (I : K) = 0 := I_re_ax
@[simp] lemma I_im (z : K) : im z * im (I : K) = im z := mul_im_I_ax z
@[simp] lemma I_im' (z : K) : im (I : K) * im z = im z :=
by rw [mul_comm, I_im _]
lemma I_mul_I : (I : K) = 0 ∨ (I : K) * I = -1 := I_mul_I_ax
@[simp] lemma conj_re (z : K) : re (conj z) = re z := is_R_or_C.conj_re_ax z
@[simp] lemma conj_im (z : K) : im (conj z) = -(im z) := is_R_or_C.conj_im_ax z
@[simp] lemma conj_of_real (r : ℝ) : conj (r : K) = (r : K) :=
by { rw ext_iff, simp only [of_real_im, conj_im, eq_self_iff_true, conj_re, and_self, neg_zero] }
@[simp] lemma conj_bit0 (z : K) : conj (bit0 z) = bit0 (conj z) := by simp [bit0, ext_iff]
@[simp] lemma conj_bit1 (z : K) : conj (bit1 z) = bit1 (conj z) := by simp [bit0, ext_iff]
@[simp] lemma conj_neg_I : conj (-I) = (I : K) := by simp [ext_iff]
@[simp] lemma conj_conj (z : K) : conj (conj z) = z := by simp [ext_iff]
lemma conj_involutive : @function.involutive K is_R_or_C.conj := conj_conj
lemma conj_bijective : @function.bijective K K is_R_or_C.conj := conj_involutive.bijective
lemma conj_inj (z w : K) : conj z = conj w ↔ z = w := conj_bijective.1.eq_iff
@[simp] lemma conj_eq_zero {z : K} : conj z = 0 ↔ z = 0 :=
by simpa using @conj_inj K _ z 0
lemma eq_conj_iff_real {z : K} : conj z = z ↔ ∃ r : ℝ, z = (r : K) :=
begin
split,
{ intro h,
suffices : im z = 0,
{ use (re z),
rw ← add_zero (coe _),
convert (re_add_im z).symm, simp [this] },
contrapose! h,
rw ← re_add_im z,
simp only [conj_of_real, ring_hom.map_add, ring_hom.map_mul, conj_I_ax],
rw [add_left_cancel_iff, ext_iff],
simpa [neg_eq_iff_add_eq_zero, add_self_eq_zero] },
{ rintros ⟨r, rfl⟩, apply conj_of_real }
end
variables (K)
/-- Conjugation as a ring equivalence. This is used to convert the inner product into a
sesquilinear product. -/
def conj_to_ring_equiv : K ≃+* Kᵒᵖ :=
{ to_fun := opposite.op ∘ conj,
inv_fun := conj ∘ opposite.unop,
left_inv := λ x, by simp only [conj_conj, function.comp_app, opposite.unop_op],
right_inv := λ x, by simp only [conj_conj, opposite.op_unop, function.comp_app],
map_mul' := λ x y, by simp [mul_comm],
map_add' := λ x y, by simp }
variables {K}
@[simp] lemma ring_equiv_apply {x : K} : (conj_to_ring_equiv K x).unop = x† := rfl
lemma eq_conj_iff_re {z : K} : conj z = z ↔ ((re z) : K) = z :=
eq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩
/-- The norm squared function. -/
def norm_sq (z : K) : ℝ := re z * re z + im z * im z
lemma norm_sq_eq_def {z : K} : ∥z∥^2 = (re z) * (re z) + (im z) * (im z) := norm_sq_eq_def_ax z
lemma norm_sq_eq_def' (z : K) : norm_sq z = ∥z∥^2 := by rw [norm_sq_eq_def, norm_sq]
@[simp] lemma norm_sq_of_real (r : ℝ) : ∥(r : K)∥^2 = r * r :=
by simp [norm_sq_eq_def]
@[simp] lemma norm_sq_zero : norm_sq (0 : K) = 0 := by simp [norm_sq, pow_two]
@[simp] lemma norm_sq_one : norm_sq (1 : K) = 1 := by simp [norm_sq]
lemma norm_sq_nonneg (z : K) : 0 ≤ norm_sq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
@[simp] lemma norm_sq_eq_zero {z : K} : norm_sq z = 0 ↔ z = 0 :=
by { rw [norm_sq, ←norm_sq_eq_def], simp [pow_two] }
@[simp] lemma norm_sq_pos {z : K} : 0 < norm_sq z ↔ z ≠ 0 :=
by rw [lt_iff_le_and_ne, ne, eq_comm]; simp [norm_sq_nonneg]
@[simp] lemma norm_sq_neg (z : K) : norm_sq (-z) = norm_sq z :=
by simp [norm_sq]
@[simp] lemma norm_sq_conj (z : K) : norm_sq (conj z) = norm_sq z := by simp [norm_sq]
@[simp] lemma norm_sq_mul (z w : K) : norm_sq (z * w) = norm_sq z * norm_sq w :=
by simp [norm_sq, pow_two]; ring
lemma norm_sq_add (z w : K) :
norm_sq (z + w) = norm_sq z + norm_sq w + 2 * (re (z * conj w)) :=
by simp [norm_sq, pow_two]; ring
lemma re_sq_le_norm_sq (z : K) : re z * re z ≤ norm_sq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
lemma im_sq_le_norm_sq (z : K) : im z * im z ≤ norm_sq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : K) : z * conj z = ((norm_sq z) : K) :=
by simp [ext_iff, norm_sq, mul_comm, sub_eq_neg_add, add_comm]
theorem add_conj (z : K) : z + conj z = 2 * (re z) :=
by simp [ext_iff, two_mul]
/-- The pseudo-coercion `of_real` as a `ring_hom`. -/
noncomputable def of_real_hom : ℝ →+* K := algebra_map ℝ K
/-- The coercion from reals as a `ring_hom`. -/
noncomputable def coe_hom : ℝ →+* K := ⟨coe, of_real_one, of_real_mul, of_real_zero, of_real_add⟩
@[simp, norm_cast, priority 900] lemma of_real_sub (r s : ℝ) : ((r - s : ℝ) : K) = r - s :=
ext_iff.2 $ by simp
@[simp, norm_cast, priority 900] lemma of_real_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : K) = r ^ n :=
by induction n; simp [*, of_real_mul, pow_succ]
theorem sub_conj (z : K) : z - conj z = (2 * im z) * I :=
by simp [ext_iff, two_mul, sub_eq_add_neg, add_mul, mul_im_I_ax]
lemma norm_sq_sub (z w : K) : norm_sq (z - w) =
norm_sq z + norm_sq w - 2 * re (z * conj w) :=
by simp [-mul_re, norm_sq_add, add_comm, add_left_comm, sub_eq_add_neg]
lemma sqrt_norm_sq_eq_norm {z : K} : real.sqrt (norm_sq z) = ∥z∥ :=
begin
have h₁ : (norm_sq z) = ∥z∥^2 := by rw [norm_sq_eq_def, norm_sq],
have h₂ : ∥z∥ = real.sqrt (∥z∥^2) := eq_comm.mp (real.sqrt_sqr (norm_nonneg z)),
rw [h₂],
exact congr_arg real.sqrt h₁
end
/-! ### Inversion -/
@[simp] lemma inv_re (z : K) : re (z⁻¹) = re z / norm_sq z :=
by simp [inv_def, norm_sq_eq_def, norm_sq, division_def]
@[simp] lemma inv_im (z : K) : im (z⁻¹) = im (-z) / norm_sq z :=
by simp [inv_def, norm_sq_eq_def, norm_sq, division_def]
@[simp, norm_cast, priority 900] lemma of_real_inv (r : ℝ) : ((r⁻¹ : ℝ) : K) = r⁻¹ :=
begin
rw ext_iff, by_cases r = 0, { simp [h] },
{ simp; field_simp [h, norm_sq] },
end
protected lemma inv_zero : (0⁻¹ : K) = 0 :=
by rw [← of_real_zero, ← of_real_inv, inv_zero]
protected theorem mul_inv_cancel {z : K} (h : z ≠ 0) : z * z⁻¹ = 1 :=
by rw [inv_def, ←mul_assoc, mul_conj, ←of_real_mul, ←norm_sq_eq_def',
mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]
lemma div_re (z w : K) : re (z / w) = re z * re w / norm_sq w + im z * im w / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]
lemma div_im (z w : K) : im (z / w) = im z * re w / norm_sq w - re z * im w / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]
@[simp, norm_cast, priority 900] lemma of_real_div (r s : ℝ) : ((r / s : ℝ) : K) = r / s :=
(@is_R_or_C.coe_hom K _).map_div r s
lemma div_re_of_real {z : K} {r : ℝ} : re (z / r) = re z / r :=
begin
by_cases h : r = 0,
{ simp [h, of_real_zero] },
{ change r ≠ 0 at h,
rw [div_eq_mul_inv, ←of_real_inv, div_eq_mul_inv],
simp [norm_sq, div_mul_eq_div_mul_one_div, div_self h] }
end
@[simp, norm_cast, priority 900] lemma of_real_fpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : K) = r ^ n :=
(@is_R_or_C.coe_hom K _).map_fpow r n
lemma I_mul_I_of_nonzero : (I : K) ≠ 0 → (I : K) * I = -1 :=
by { have := I_mul_I_ax, tauto }
@[simp] lemma div_I (z : K) : z / I = -(z * I) :=
begin
by_cases h : (I : K) = 0,
{ simp [h] },
{ field_simp [h], simp [mul_assoc, I_mul_I_of_nonzero h] }
end
@[simp] lemma inv_I : (I : K)⁻¹ = -I :=
by { by_cases h : (I : K) = 0; field_simp [h] }
@[simp] lemma norm_sq_inv (z : K) : norm_sq z⁻¹ = (norm_sq z)⁻¹ :=
begin
by_cases z = 0,
{ simp [h] },
{ refine mul_right_cancel' (mt norm_sq_eq_zero.1 h) _,
simp [h, ←norm_sq_mul], }
end
@[simp] lemma norm_sq_div (z w : K) : norm_sq (z / w) = norm_sq z / norm_sq w :=
by { rw [division_def, norm_sq_mul, norm_sq_inv], refl }
lemma norm_conj {z : K} : ∥conj z∥ = ∥z∥ :=
by simp only [←sqrt_norm_sq_eq_norm, norm_sq_conj]
lemma conj_inv {z : K} : conj (z⁻¹) = (conj z)⁻¹ :=
by simp only [inv_def, norm_conj, ring_hom.map_mul, conj_of_real]
lemma conj_div {z w : K} : conj (z / w) = (conj z) / (conj w) :=
by rw [div_eq_inv_mul, div_eq_inv_mul, ring_hom.map_mul]; simp only [conj_inv]
/-! ### Cast lemmas -/
@[simp, norm_cast, priority 900] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : K) = n :=
of_real_hom.map_nat_cast n
@[simp, norm_cast] lemma nat_cast_re (n : ℕ) : re (n : K) = n :=
by rw [← of_real_nat_cast, of_real_re]
@[simp, norm_cast] lemma nat_cast_im (n : ℕ) : im (n : K) = 0 :=
by rw [← of_real_nat_cast, of_real_im]
@[simp, norm_cast, priority 900] theorem of_real_int_cast (n : ℤ) : ((n : ℝ) : K) = n :=
of_real_hom.map_int_cast n
@[simp, norm_cast] lemma int_cast_re (n : ℤ) : re (n : K) = n :=
by rw [← of_real_int_cast, of_real_re]
@[simp, norm_cast] lemma int_cast_im (n : ℤ) : im (n : K) = 0 :=
by rw [← of_real_int_cast, of_real_im]
@[simp, norm_cast, priority 900] theorem of_real_rat_cast (n : ℚ) : ((n : ℝ) : K) = n :=
(@is_R_or_C.of_real_hom K _).map_rat_cast n
@[simp, norm_cast] lemma rat_cast_re (q : ℚ) : re (q : K) = q :=
by rw [← of_real_rat_cast, of_real_re]
@[simp, norm_cast] lemma rat_cast_im (q : ℚ) : im (q : K) = 0 :=
by rw [← of_real_rat_cast, of_real_im]
/-! ### Characteristic zero -/
-- TODO: I think this can be instance, because it is a `Prop`
/--
ℝ and ℂ are both of characteristic zero.
Note: This is not registered as an instance to avoid having multiple instances on ℝ and ℂ.
-/
lemma char_zero_R_or_C : char_zero K :=
char_zero_of_inj_zero $ λ n h,
by rwa [← of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h
theorem re_eq_add_conj (z : K) : ↑(re z) = (z + conj z) / 2 :=
begin
haveI : char_zero K := char_zero_R_or_C,
rw [add_conj, mul_div_cancel_left ((re z):K) two_ne_zero'],
end
/-! ### Absolute value -/
/-- The complex absolute value function, defined as the square root of the norm squared. -/
@[pp_nodot] noncomputable def abs (z : K) : ℝ := (norm_sq z).sqrt
local notation `abs'` := _root_.abs
local notation `absK` := @abs K _
@[simp, norm_cast] lemma abs_of_real (r : ℝ) : absK r = abs' r :=
by simp [abs, norm_sq, norm_sq_of_real, real.sqrt_mul_self_eq_abs]
lemma norm_eq_abs (z : K) : ∥z∥ = absK z := by simp [abs, norm_sq_eq_def']
lemma abs_of_nonneg {r : ℝ} (h : 0 ≤ r) : absK r = r :=
(abs_of_real _).trans (abs_of_nonneg h)
lemma abs_of_nat (n : ℕ) : absK n = n :=
by { rw [← of_real_nat_cast], exact abs_of_nonneg (nat.cast_nonneg n) }
lemma mul_self_abs (z : K) : abs z * abs z = norm_sq z :=
real.mul_self_sqrt (norm_sq_nonneg _)
@[simp] lemma abs_zero : absK 0 = 0 := by simp [abs]
@[simp] lemma abs_one : absK 1 = 1 := by simp [abs]
@[simp] lemma abs_two : absK 2 = 2 :=
calc absK 2 = absK (2 : ℝ) : by rw [of_real_bit0, of_real_one]
... = (2 : ℝ) : abs_of_nonneg (by norm_num)
lemma abs_nonneg (z : K) : 0 ≤ absK z :=
real.sqrt_nonneg _
@[simp] lemma abs_eq_zero {z : K} : absK z = 0 ↔ z = 0 :=
(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero
lemma abs_ne_zero {z : K} : abs z ≠ 0 ↔ z ≠ 0 :=
not_congr abs_eq_zero
@[simp] lemma abs_conj (z : K) : abs (conj z) = abs z :=
by simp [abs]
@[simp] lemma abs_mul (z w : K) : 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 : K) : abs' (re z) ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg (re z)) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply re_sq_le_norm_sq
lemma abs_im_le_abs (z : K) : abs' (im z) ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg (im z)) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply im_sq_le_norm_sq
lemma re_le_abs (z : K) : re z ≤ abs z :=
(abs_le.1 (abs_re_le_abs _)).2
lemma im_le_abs (z : K) : im z ≤ abs z :=
(abs_le.1 (abs_im_le_abs _)).2
lemma abs_add (z w : K) : 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 absK :=
{ 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 : K) : abs' (abs z) = abs z :=
_root_.abs_of_nonneg (abs_nonneg _)
@[simp] lemma abs_pos {z : K} : 0 < abs z ↔ z ≠ 0 := abv_pos abs
@[simp] lemma abs_neg : ∀ z : K, abs (-z) = abs z := abv_neg abs
lemma abs_sub : ∀ z w : K, abs (z - w) = abs (w - z) := abv_sub abs
lemma abs_sub_le : ∀ a b c : K, abs (a - c) ≤ abs (a - b) + abs (b - c) := abv_sub_le abs
@[simp] theorem abs_inv : ∀ z : K, abs z⁻¹ = (abs z)⁻¹ := abv_inv abs
@[simp] theorem abs_div : ∀ z w : K, abs (z / w) = abs z / abs w := abv_div abs
lemma abs_abs_sub_le_abs_sub : ∀ z w : K, abs' (abs z - abs w) ≤ abs (z - w) :=
abs_abv_sub_le_abv_sub abs
lemma abs_re_div_abs_le_one (z : K) : abs' (re z / abs z) ≤ 1 :=
begin
by_cases hz : z = 0,
{ simp [hz, zero_le_one] },
{ simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }
end
lemma abs_im_div_abs_le_one (z : K) : abs' (im z / abs z) ≤ 1 :=
begin
by_cases hz : z = 0,
{ simp [hz, zero_le_one] },
{ simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }
end
@[simp, norm_cast] lemma abs_cast_nat (n : ℕ) : abs (n : K) = n :=
by rw [← of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]
lemma norm_sq_eq_abs (x : K) : norm_sq x = abs x ^ 2 :=
by rw [abs, pow_two, real.mul_self_sqrt (norm_sq_nonneg _)]
lemma re_eq_abs_of_mul_conj (x : K) : re (x * (conj x)) = abs (x * (conj x)) :=
by rw [mul_conj, of_real_re, abs_of_real, norm_sq_eq_abs, pow_two, _root_.abs_mul, abs_abs]
lemma abs_sqr_re_add_conj (x : K) : (abs (x + x†))^2 = (re (x + x†))^2 :=
by simp [pow_two, ←norm_sq_eq_abs, norm_sq]
lemma abs_sqr_re_add_conj' (x : K) : (abs (x† + x))^2 = (re (x† + x))^2 :=
by simp [pow_two, ←norm_sq_eq_abs, norm_sq]
lemma conj_mul_eq_norm_sq_left (x : K) : x† * x = ((norm_sq x) : K) :=
begin
rw ext_iff,
refine ⟨by simp [of_real_re, mul_re, conj_re, conj_im, norm_sq],_⟩,
simp [of_real_im, mul_im, conj_im, conj_re, mul_comm],
end
/-- The real part in a `is_R_or_C` field, as a continuous linear map. -/
noncomputable def re_clm : K →L[ℝ] ℝ :=
re_lm.mk_continuous 1 $ by { simp only [norm_eq_abs, re_lm_coe, one_mul], exact abs_re_le_abs }
@[simp] lemma norm_re_clm : ∥(re_clm : K →L[ℝ] ℝ)∥ = 1 :=
begin
apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _),
convert continuous_linear_map.ratio_le_op_norm _ (1 : K),
simp,
end
@[simp, norm_cast] lemma re_clm_coe : ((re_clm : K →L[ℝ] ℝ) : K →ₗ[ℝ] ℝ) = re_lm := rfl
@[simp] lemma re_clm_apply : ((re_clm : K →L[ℝ] ℝ) : K → ℝ) = re := rfl
/-! ### Cauchy sequences -/
theorem is_cau_seq_re (f : cau_seq K abs) : is_cau_seq abs' (λ n, re (f n)) :=
λ ε ε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 K abs) : is_cau_seq abs' (λ n, im (f n)) :=
λ ε ε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 K Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_re (f : cau_seq K abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_re f⟩
/-- The imaginary part of a K Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_im (f : cau_seq K abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_im f⟩
lemma is_cau_seq_abs {f : ℕ → K} (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)⟩
@[simp, norm_cast, priority 900] lemma of_real_prod {α : Type*} (s : finset α) (f : α → ℝ) :
((∏ i in s, f i : ℝ) : K) = ∏ i in s, (f i : K) :=
ring_hom.map_prod _ _ _
@[simp, norm_cast, priority 900] lemma of_real_sum {α : Type*} (s : finset α) (f : α → ℝ) :
((∑ i in s, f i : ℝ) : K) = ∑ i in s, (f i : K) :=
ring_hom.map_sum _ _ _
@[simp, norm_cast] lemma of_real_finsupp_sum
{α M : Type*} [has_zero M] (f : α →₀ M) (g : α → M → ℝ) :
((f.sum (λ a b, g a b) : ℝ) : K) = f.sum (λ a b, ((g a b) : K)) :=
ring_hom.map_finsupp_sum _ f g
@[simp, norm_cast] lemma of_real_finsupp_prod
{α M : Type*} [has_zero M] (f : α →₀ M) (g : α → M → ℝ) :
((f.prod (λ a b, g a b) : ℝ) : K) = f.prod (λ a b, ((g a b) : K)) :=
ring_hom.map_finsupp_prod _ f g
end is_R_or_C
section instances
noncomputable instance real.is_R_or_C : is_R_or_C ℝ :=
{ re := add_monoid_hom.id ℝ,
im := 0,
conj := ring_hom.id ℝ,
I := 0,
I_re_ax := by simp only [add_monoid_hom.map_zero],
I_mul_I_ax := or.intro_left _ rfl,
re_add_im_ax := λ z, by unfold_coes; simp [add_zero, id.def, mul_zero],
of_real_re_ax := λ r, by simp only [add_monoid_hom.id_apply, algebra.id.map_eq_self],
of_real_im_ax := λ r, by simp only [add_monoid_hom.zero_apply],
mul_re_ax := λ z w, by simp only [sub_zero, mul_zero, add_monoid_hom.zero_apply, add_monoid_hom.id_apply],
mul_im_ax := λ z w, by simp only [add_zero, zero_mul, mul_zero, add_monoid_hom.zero_apply],
conj_re_ax := λ z, by simp only [ring_hom.id_apply],
conj_im_ax := λ z, by simp only [neg_zero, add_monoid_hom.zero_apply],
conj_I_ax := by simp only [ring_hom.map_zero, neg_zero],
norm_sq_eq_def_ax := λ z, by simp only [pow_two, norm, ←abs_mul, abs_mul_self z, add_zero, mul_zero, add_monoid_hom.zero_apply, add_monoid_hom.id_apply],
mul_im_I_ax := λ z, by simp only [mul_zero, add_monoid_hom.zero_apply],
inv_def_ax :=
begin
intro z,
unfold_coes,
have H : z ≠ 0 → 1 / z = z / (z * z) := λ h,
calc
1 / z = 1 * (1 / z) : (one_mul (1 / z)).symm
... = (z / z) * (1 / z) : congr_arg (λ x, x * (1 / z)) (div_self h).symm
... = z / (z * z) : by field_simp,
rcases lt_trichotomy z 0 with hlt|heq|hgt,
{ field_simp [norm, abs, max_eq_right_of_lt (show z < -z, by linarith), pow_two, mul_inv', ←H (ne_of_lt hlt)] },
{ simp [heq] },
{ field_simp [norm, abs, max_eq_left_of_lt (show -z < z, by linarith), pow_two, mul_inv', ←H (ne_of_gt hgt)] },
end,
div_I_ax := λ z, by simp only [div_zero, mul_zero, neg_zero]}
noncomputable instance complex.is_R_or_C : is_R_or_C ℂ :=
{ re := ⟨complex.re, complex.zero_re, complex.add_re⟩,
im := ⟨complex.im, complex.zero_im, complex.add_im⟩,
conj := complex.conj,
I := complex.I,
I_re_ax := by simp only [add_monoid_hom.coe_mk, complex.I_re],
I_mul_I_ax := by simp only [complex.I_mul_I, eq_self_iff_true, or_true],
re_add_im_ax := λ z, by simp only [add_monoid_hom.coe_mk, complex.re_add_im,
complex.coe_algebra_map, complex.of_real_eq_coe],
of_real_re_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_re,
complex.coe_algebra_map, complex.of_real_eq_coe],
of_real_im_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_im,
complex.coe_algebra_map, complex.of_real_eq_coe],
mul_re_ax := λ z w, by simp only [complex.mul_re, add_monoid_hom.coe_mk],
mul_im_ax := λ z w, by simp only [add_monoid_hom.coe_mk, complex.mul_im],
conj_re_ax := λ z, by simp only [ring_hom.coe_mk, add_monoid_hom.coe_mk, complex.conj_re],
conj_im_ax := λ z, by simp only [ring_hom.coe_mk, complex.conj_im, add_monoid_hom.coe_mk],
conj_I_ax := by simp only [complex.conj_I, ring_hom.coe_mk],
norm_sq_eq_def_ax := λ z, by simp only [←complex.norm_sq_eq_abs, ←complex.norm_sq, add_monoid_hom.coe_mk, complex.norm_eq_abs],
mul_im_I_ax := λ z, by simp only [mul_one, add_monoid_hom.coe_mk, complex.I_im],
inv_def_ax := λ z, by {
simp only [complex.inv_def, complex.norm_sq_eq_abs, complex.coe_algebra_map,
complex.of_real_eq_coe, complex.norm_eq_abs],
},
div_I_ax := complex.div_I }
end instances
namespace is_R_or_C
section cleanup_lemmas
local notation `reR` := @is_R_or_C.re ℝ _
local notation `imR` := @is_R_or_C.im ℝ _
local notation `conjR` := @is_R_or_C.conj ℝ _
local notation `IR` := @is_R_or_C.I ℝ _
local notation `absR` := @is_R_or_C.abs ℝ _
local notation `norm_sqR` := @is_R_or_C.norm_sq ℝ _
local notation `reC` := @is_R_or_C.re ℂ _
local notation `imC` := @is_R_or_C.im ℂ _
local notation `conjC` := @is_R_or_C.conj ℂ _
local notation `IC` := @is_R_or_C.I ℂ _
local notation `absC` := @is_R_or_C.abs ℂ _
local notation `norm_sqC` := @is_R_or_C.norm_sq ℂ _
@[simp] lemma re_to_real {x : ℝ} : reR x = x := rfl
@[simp] lemma im_to_real {x : ℝ} : imR x = 0 := rfl
@[simp] lemma conj_to_real {x : ℝ} : conjR x = x := rfl
@[simp] lemma I_to_real : IR = 0 := rfl
@[simp] lemma norm_sq_to_real {x : ℝ} : norm_sqR x = x*x := by simp [is_R_or_C.norm_sq]
@[simp] lemma abs_to_real {x : ℝ} : absR x = _root_.abs x :=
by simp [is_R_or_C.abs, abs, real.sqrt_mul_self_eq_abs]
@[simp] lemma coe_real_eq_id : @coe ℝ ℝ _ = id := rfl
@[simp] lemma re_to_complex {x : ℂ} : reC x = x.re := rfl
@[simp] lemma im_to_complex {x : ℂ} : imC x = x.im := rfl
@[simp] lemma conj_to_complex {x : ℂ} : conjC x = x.conj := rfl
@[simp] lemma I_to_complex : IC = complex.I := rfl
@[simp] lemma norm_sq_to_complex {x : ℂ} : norm_sqC x = complex.norm_sq x :=
by simp [is_R_or_C.norm_sq, complex.norm_sq]
@[simp] lemma abs_to_complex {x : ℂ} : absC x = complex.abs x :=
by simp [is_R_or_C.abs, complex.abs]
end cleanup_lemmas
end is_R_or_C
|
ecbd8384ae66e764575763f4c77982459f50def5 | 38193807b9085b93599c814229d2b0dacb64ba22 | /benchmarks/add-commute/AddCommute.lean | 9c6f8b000da4a158b0929fa833059852fc183d59 | [] | no_license | zgrannan/rest-old | d650363e403a9d5322fb44ee892b743aec558e1b | 6a6974641b25259cb8701af4302169db22b33b6b | refs/heads/master | 1,670,816,037,466 | 1,599,571,928,000 | 1,599,571,928,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 337 | lean | inductive N : Type
| z : N
| s : N → N
def add : N → N → N
| m N.z := m
| m (N.s n) := N.s (add m n)
theorem comm : ∀ (p q : N), add p q = add q p := sorry
theorem assoc : ∀ (p q r : N), add (add p q) r = add p (add q r) := sorry
theorem simple (p q r : N) : add (add p q) r = add (add r q) p := by simp [comm,assoc]
|
ad9ee74fb2224b0d572772edac32d7e903c0fe55 | 78630e908e9624a892e24ebdd21260720d29cf55 | /src/logic_propositional/prop_17.lean | 4cfa1013a346f36f17412659ac5222713b22327f | [
"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 | 444 | lean | namespace prop_17
variables A B : Prop
theorem prop_17 : ¬ (¬ A ∧ ¬ B) → (A ∨ B) :=
assume h1: ¬ (¬ A ∧ ¬ B),
show A ∨ B, from or.elim (classical.em A)
(assume h2: A, or.inl h2)
(assume h3: ¬ A,
show A ∨ B, from or.inr
(show B, from (classical.by_contradiction
(assume h4: ¬ B,
have h5: ¬ A ∧ ¬ B, from and.intro h3 h4,
h1 h5))))
-- end namespace
end prop_17 |
d9f611c782dfb6eb2c1a7b5081c06d481ae9338f | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/topology/subset_properties.lean | c8a2345f12f47b45ff3d0b7db6bbedbde3e61320 | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 67,805 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import topology.continuous_on
import data.finset.order
/-!
# Properties of subsets of topological spaces
In this file we define various properties of subsets of a topological space, and some classes on
topological spaces.
## Main definitions
We define the following properties for sets in a topological space:
* `is_compact`: each open cover has a finite subcover. This is defined in mathlib using filters.
The main property of a compact set is `is_compact.elim_finite_subcover`.
* `is_clopen`: a set that is both open and closed.
* `is_irreducible`: a nonempty set that has contains no non-trivial pair of disjoint opens.
See also the section below in the module doc.
* `is_connected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
`connected_component` is the connected component of an element in the space.
* `is_totally_disconnected`: all of its connected components are singletons.
* `is_totally_separated`: any two points can be separated by two disjoint opens that cover the set.
For each of these definitions (except for `is_clopen`), we also have a class stating that the whole
space satisfies that property:
`compact_space`, `irreducible_space`, `connected_space`, `totally_disconnected_space`, `totally_separated_space`.
Furthermore, we have two more classes:
* `locally_compact_space`: for every point `x`, every open neighborhood of `x` contains a compact
neighborhood of `x`. The definition is formulated in terms of the neighborhood filter.
* `sigma_compact_space`: a space that is the union of a countably many compact subspaces.
## On the definition of irreducible and connected sets/spaces
In informal mathematics, irreducible and connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption
as `is_preirreducible` and `is_preconnected` respectively.
In other words, the only difference is whether the empty space
counts as irreducible and/or connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open set filter classical
open_locale classical topological_space filter
universes u v
variables {α : Type u} {β : Type v} [topological_space α] {s t : set α}
/- compact sets -/
section compact
/-- A set `s` is compact if for every filter `f` that contains `s`,
every set of `f` also meets every neighborhood of some `a ∈ s`. -/
def is_compact (s : set α) := ∀ ⦃f⦄ [ne_bot f], f ≤ 𝓟 s → ∃a∈s, cluster_pt a f
/-- The complement to a compact set belongs to a filter `f` if it belongs to each filter
`𝓝 a ⊓ f`, `a ∈ s`. -/
lemma is_compact.compl_mem_sets (hs : is_compact s) {f : filter α} (hf : ∀ a ∈ s, sᶜ ∈ 𝓝 a ⊓ f) :
sᶜ ∈ f :=
begin
contrapose! hf,
simp only [mem_iff_inf_principal_compl, compl_compl, inf_assoc, ← exists_prop] at hf ⊢,
exact @hs _ hf inf_le_right
end
/-- The complement to a compact set belongs to a filter `f` if each `a ∈ s` has a neighborhood `t`
within `s` such that `tᶜ` belongs to `f`. -/
lemma is_compact.compl_mem_sets_of_nhds_within (hs : is_compact s) {f : filter α}
(hf : ∀ a ∈ s, ∃ t ∈ 𝓝[s] a, tᶜ ∈ f) :
sᶜ ∈ f :=
begin
refine hs.compl_mem_sets (λ a ha, _),
rcases hf a ha with ⟨t, ht, hst⟩,
replace ht := mem_inf_principal.1 ht,
refine mem_inf_sets.2 ⟨_, ht, _, hst, _⟩,
rintros x ⟨h₁, h₂⟩ hs,
exact h₂ (h₁ hs)
end
/-- If `p : set α → Prop` is stable under restriction and union, and each point `x`
of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/
@[elab_as_eliminator]
lemma is_compact.induction_on {s : set α} (hs : is_compact s) {p : set α → Prop} (he : p ∅)
(hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t))
(hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) :
p s :=
let f : filter α :=
{ sets := {t | p tᶜ},
univ_sets := by simpa,
sets_of_superset := λ t₁ t₂ ht₁ ht, hmono (compl_subset_compl.2 ht) ht₁,
inter_sets := λ t₁ t₂ ht₁ ht₂, by simp [compl_inter, hunion ht₁ ht₂] } in
have sᶜ ∈ f, from hs.compl_mem_sets_of_nhds_within (by simpa using hnhds),
by simpa
/-- The intersection of a compact set and a closed set is a compact set. -/
lemma is_compact.inter_right (hs : is_compact s) (ht : is_closed t) :
is_compact (s ∩ t) :=
begin
introsI f hnf hstf,
obtain ⟨a, hsa, ha⟩ : ∃ a ∈ s, cluster_pt a f :=
hs (le_trans hstf (le_principal_iff.2 (inter_subset_left _ _))),
have : a ∈ t :=
(ht.mem_of_nhds_within_ne_bot $ ha.mono $
le_trans hstf (le_principal_iff.2 (inter_subset_right _ _))),
exact ⟨a, ⟨hsa, this⟩, ha⟩
end
/-- The intersection of a closed set and a compact set is a compact set. -/
lemma is_compact.inter_left (ht : is_compact t) (hs : is_closed s) : is_compact (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
/-- The set difference of a compact set and an open set is a compact set. -/
lemma compact_diff (hs : is_compact s) (ht : is_open t) : is_compact (s \ t) :=
hs.inter_right (is_closed_compl_iff.mpr ht)
/-- A closed subset of a compact set is a compact set. -/
lemma compact_of_is_closed_subset (hs : is_compact s) (ht : is_closed t) (h : t ⊆ s) :
is_compact t :=
inter_eq_self_of_subset_right h ▸ hs.inter_right ht
lemma is_compact.adherence_nhdset {f : filter α}
(hs : is_compact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : is_open t) (ht₂ : ∀a∈s, cluster_pt a f → a ∈ t) :
t ∈ f :=
classical.by_cases mem_sets_of_eq_bot $
assume : f ⊓ 𝓟 tᶜ ≠ ⊥,
let ⟨a, ha, (hfa : cluster_pt a $ f ⊓ 𝓟 tᶜ)⟩ := @@hs this $ inf_le_left_of_le hf₂ in
have a ∈ t,
from ht₂ a ha (hfa.of_inf_left),
have tᶜ ∩ t ∈ 𝓝[tᶜ] a,
from inter_mem_nhds_within _ (mem_nhds_sets ht₁ this),
have A : 𝓝[tᶜ] a = ⊥,
from empty_in_sets_eq_bot.1 $ compl_inter_self t ▸ this,
have 𝓝[tᶜ] a ≠ ⊥,
from hfa.of_inf_right,
absurd A this
lemma compact_iff_ultrafilter_le_nhds :
is_compact s ↔ (∀f : ultrafilter α, ↑f ≤ 𝓟 s → ∃a∈s, ↑f ≤ 𝓝 a) :=
begin
refine (forall_ne_bot_le_iff _).trans _,
{ rintro f g hle ⟨a, has, haf⟩,
exact ⟨a, has, haf.mono hle⟩ },
{ simp only [ultrafilter.cluster_pt_iff] }
end
alias compact_iff_ultrafilter_le_nhds ↔ is_compact.ultrafilter_le_nhds _
/-- For every open cover of a compact set, there exists a finite subcover. -/
lemma is_compact.elim_finite_subcover {ι : Type v} (hs : is_compact s)
(U : ι → set α) (hUo : ∀i, is_open (U i)) (hsU : s ⊆ ⋃ i, U i) :
∃ t : finset ι, s ⊆ ⋃ i ∈ t, U i :=
is_compact.induction_on hs ⟨∅, empty_subset _⟩ (λ s₁ s₂ hs ⟨t, hs₂⟩, ⟨t, subset.trans hs hs₂⟩)
(λ s₁ s₂ ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩,
⟨t₁ ∪ t₂, by { rw [finset.bUnion_union], exact union_subset_union ht₁ ht₂ }⟩)
(λ x hx, let ⟨i, hi⟩ := mem_Union.1 (hsU hx) in
⟨U i, mem_nhds_within.2 ⟨U i, hUo i, hi, inter_subset_left _ _⟩, {i}, by simp⟩)
/-- For every family of closed sets whose intersection avoids a compact set,
there exists a finite subfamily whose intersection avoids this compact set. -/
lemma is_compact.elim_finite_subfamily_closed {s : set α} {ι : Type v} (hs : is_compact s)
(Z : ι → set α) (hZc : ∀i, is_closed (Z i)) (hsZ : s ∩ (⋂ i, Z i) = ∅) :
∃ t : finset ι, s ∩ (⋂ i ∈ t, Z i) = ∅ :=
let ⟨t, ht⟩ := hs.elim_finite_subcover (λ i, (Z i)ᶜ) hZc
(by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,
exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using hsZ)
in
⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,
exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using ht⟩
/-- To show that a compact set intersects the intersection of a family of closed sets,
it is sufficient to show that it intersects every finite subfamily. -/
lemma is_compact.inter_Inter_nonempty {s : set α} {ι : Type v} (hs : is_compact s)
(Z : ι → set α) (hZc : ∀i, is_closed (Z i)) (hsZ : ∀ t : finset ι, (s ∩ ⋂ i ∈ t, Z i).nonempty) :
(s ∩ ⋂ i, Z i).nonempty :=
begin
simp only [← ne_empty_iff_nonempty] at hsZ ⊢,
apply mt (hs.elim_finite_subfamily_closed Z hZc), push_neg, exact hsZ
end
/-- Cantor's intersection theorem:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
lemma is_compact.nonempty_Inter_of_directed_nonempty_compact_closed
{ι : Type v} [hι : nonempty ι] (Z : ι → set α) (hZd : directed (⊇) Z)
(hZn : ∀ i, (Z i).nonempty) (hZc : ∀ i, is_compact (Z i)) (hZcl : ∀ i, is_closed (Z i)) :
(⋂ i, Z i).nonempty :=
begin
apply hι.elim,
intro i₀,
let Z' := λ i, Z i ∩ Z i₀,
suffices : (⋂ i, Z' i).nonempty,
{ exact nonempty.mono (Inter_subset_Inter $ assume i, inter_subset_left (Z i) (Z i₀)) this },
rw ← ne_empty_iff_nonempty,
intro H,
obtain ⟨t, ht⟩ : ∃ (t : finset ι), ((Z i₀) ∩ ⋂ (i ∈ t), Z' i) = ∅,
from (hZc i₀).elim_finite_subfamily_closed Z'
(assume i, is_closed_inter (hZcl i) (hZcl i₀)) (by rw [H, inter_empty]),
obtain ⟨i₁, hi₁⟩ : ∃ i₁ : ι, Z i₁ ⊆ Z i₀ ∧ ∀ i ∈ t, Z i₁ ⊆ Z' i,
{ rcases directed.finset_le hZd t with ⟨i, hi⟩,
rcases hZd i i₀ with ⟨i₁, hi₁, hi₁₀⟩,
use [i₁, hi₁₀],
intros j hj,
exact subset_inter (subset.trans hi₁ (hi j hj)) hi₁₀ },
suffices : ((Z i₀) ∩ ⋂ (i ∈ t), Z' i).nonempty,
{ rw ← ne_empty_iff_nonempty at this, contradiction },
refine nonempty.mono _ (hZn i₁),
exact subset_inter hi₁.left (subset_bInter hi₁.right)
end
/-- Cantor's intersection theorem for sequences indexed by `ℕ`:
the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/
lemma is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed
(Z : ℕ → set α) (hZd : ∀ i, Z (i+1) ⊆ Z i)
(hZn : ∀ i, (Z i).nonempty) (hZ0 : is_compact (Z 0)) (hZcl : ∀ i, is_closed (Z i)) :
(⋂ i, Z i).nonempty :=
have Zmono : _, from @monotone_of_monotone_nat (order_dual _) _ Z hZd,
have hZd : directed (⊇) Z, from directed_of_sup Zmono,
have ∀ i, Z i ⊆ Z 0, from assume i, Zmono $ zero_le i,
have hZc : ∀ i, is_compact (Z i), from assume i, compact_of_is_closed_subset hZ0 (hZcl i) (this i),
is_compact.nonempty_Inter_of_directed_nonempty_compact_closed Z hZd hZn hZc hZcl
/-- For every open cover of a compact set, there exists a finite subcover. -/
lemma is_compact.elim_finite_subcover_image {b : set β} {c : β → set α}
(hs : is_compact s) (hc₁ : ∀i∈b, is_open (c i)) (hc₂ : s ⊆ ⋃i∈b, c i) :
∃b'⊆b, finite b' ∧ s ⊆ ⋃i∈b', c i :=
begin
rcases hs.elim_finite_subcover (λ i, c i.1 : b → set α) _ _ with ⟨d, hd⟩,
refine ⟨↑(d.image subtype.val), _, finset.finite_to_set _, _⟩,
{ intros i hi,
erw finset.mem_image at hi,
rcases hi with ⟨s, hsd, rfl⟩,
exact s.property },
{ refine subset.trans hd _,
rintros x ⟨_, ⟨s, rfl⟩, ⟨_, ⟨hsd, rfl⟩, H⟩⟩,
refine ⟨c s.val, ⟨s.val, _⟩, H⟩,
simp [finset.mem_image_of_mem subtype.val hsd] },
{ rintro ⟨i, hi⟩, exact hc₁ i hi },
{ refine subset.trans hc₂ _,
rintros x ⟨_, ⟨i, rfl⟩, ⟨_, ⟨hib, rfl⟩, H⟩⟩,
exact ⟨_, ⟨⟨i, hib⟩, rfl⟩, H⟩ },
end
/-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem compact_of_finite_subfamily_closed
(h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →
s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) :
is_compact s :=
assume f hfn hfs, classical.by_contradiction $ assume : ¬ (∃x∈s, cluster_pt x f),
have hf : ∀x∈s, 𝓝 x ⊓ f = ⊥,
by simpa only [cluster_pt, not_exists, not_not, ne_bot],
have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t,
from assume ⟨x, hxs, hx⟩,
have ∅ ∈ 𝓝 x ⊓ f, by rw [empty_in_sets_eq_bot, hf x hxs],
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := by rw [mem_inf_sets] at this; exact this in
have ∅ ∈ 𝓝[t₂] x,
from (𝓝[t₂] x).sets_of_superset (inter_mem_inf_sets ht₁ (subset.refl t₂)) ht,
have 𝓝[t₂] x = ⊥,
by rwa [empty_in_sets_eq_bot] at this,
by simp only [closure_eq_cluster_pts] at hx; exact hx t₂ ht₂ this,
let ⟨t, ht⟩ := h (λ i : f.sets, closure i.1) (λ i, is_closed_closure)
(by simpa [eq_empty_iff_forall_not_mem, not_exists]) in
have (⋂i∈t, subtype.val i) ∈ f,
from t.Inter_mem_sets.2 $ assume i hi, i.2,
have s ∩ (⋂i∈t, subtype.val i) ∈ f,
from inter_mem_sets (le_principal_iff.1 hfs) this,
have ∅ ∈ f,
from mem_sets_of_superset this $ assume x ⟨hxs, hx⟩,
let ⟨i, hit, hxi⟩ := (show ∃i ∈ t, x ∉ closure (subtype.val i),
by { rw [eq_empty_iff_forall_not_mem] at ht, simpa [hxs, not_forall] using ht x }) in
have x ∈ closure i.val, from subset_closure (mem_bInter_iff.mp hx i hit),
show false, from hxi this,
hfn $ by rwa [empty_in_sets_eq_bot] at this
/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/
lemma compact_of_finite_subcover
(h : Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) →
s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) :
is_compact s :=
compact_of_finite_subfamily_closed $
assume ι Z hZc hsZ,
let ⟨t, ht⟩ := h (λ i, (Z i)ᶜ) (assume i, is_open_compl_iff.mpr $ hZc i)
(by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,
exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using hsZ)
in
⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_Union,
exists_prop, mem_inter_eq, not_and, iff_self, mem_Inter, mem_compl_eq] using ht⟩
/-- A set `s` is compact if and only if
for every open cover of `s`, there exists a finite subcover. -/
lemma compact_iff_finite_subcover :
is_compact s ↔ (Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) →
s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) :=
⟨assume hs ι, hs.elim_finite_subcover, compact_of_finite_subcover⟩
/-- A set `s` is compact if and only if
for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem compact_iff_finite_subfamily_closed :
is_compact s ↔ (Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →
s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) :=
⟨assume hs ι, hs.elim_finite_subfamily_closed, compact_of_finite_subfamily_closed⟩
@[simp]
lemma compact_empty : is_compact (∅ : set α) :=
assume f hnf hsf, not.elim hnf $
empty_in_sets_eq_bot.1 $ le_principal_iff.1 hsf
@[simp]
lemma compact_singleton {a : α} : is_compact ({a} : set α) :=
λ f hf hfa, ⟨a, rfl, cluster_pt.of_le_nhds'
(hfa.trans $ by simpa only [principal_singleton] using pure_le_nhds a) hf⟩
lemma set.finite.compact_bUnion {s : set β} {f : β → set α} (hs : finite s)
(hf : ∀i ∈ s, is_compact (f i)) :
is_compact (⋃i ∈ s, f i) :=
compact_of_finite_subcover $ assume ι U hUo hsU,
have ∀i : subtype s, ∃t : finset ι, f i ⊆ (⋃ j ∈ t, U j), from
assume ⟨i, hi⟩, (hf i hi).elim_finite_subcover _ hUo
(calc f i ⊆ ⋃i ∈ s, f i : subset_bUnion_of_mem hi
... ⊆ ⋃j, U j : hsU),
let ⟨finite_subcovers, h⟩ := axiom_of_choice this in
by haveI : fintype (subtype s) := hs.fintype; exact
let t := finset.bind finset.univ finite_subcovers in
have (⋃i ∈ s, f i) ⊆ (⋃ i ∈ t, U i), from bUnion_subset $
assume i hi, calc
f i ⊆ (⋃ j ∈ finite_subcovers ⟨i, hi⟩, U j) : (h ⟨i, hi⟩)
... ⊆ (⋃ j ∈ t, U j) : bUnion_subset_bUnion_left $
assume j hj, finset.mem_bind.mpr ⟨_, finset.mem_univ _, hj⟩,
⟨t, this⟩
lemma compact_Union {f : β → set α} [fintype β]
(h : ∀i, is_compact (f i)) : is_compact (⋃i, f i) :=
by rw ← bUnion_univ; exact finite_univ.compact_bUnion (λ i _, h i)
lemma set.finite.is_compact (hs : finite s) : is_compact s :=
bUnion_of_singleton s ▸ hs.compact_bUnion (λ _ _, compact_singleton)
lemma is_compact.union (hs : is_compact s) (ht : is_compact t) : is_compact (s ∪ t) :=
by rw union_eq_Union; exact compact_Union (λ b, by cases b; assumption)
lemma is_compact.insert (hs : is_compact s) (a) : is_compact (insert a s) :=
compact_singleton.union hs
/-- `filter.cocompact` is the filter generated by complements to compact sets. -/
def filter.cocompact (α : Type*) [topological_space α] : filter α :=
⨅ (s : set α) (hs : is_compact s), 𝓟 (sᶜ)
lemma filter.has_basis_cocompact : (filter.cocompact α).has_basis is_compact compl :=
has_basis_binfi_principal'
(λ s hs t ht, ⟨s ∪ t, hs.union ht, compl_subset_compl.2 (subset_union_left s t),
compl_subset_compl.2 (subset_union_right s t)⟩)
⟨∅, compact_empty⟩
lemma filter.mem_cocompact : s ∈ filter.cocompact α ↔ ∃ t, is_compact t ∧ tᶜ ⊆ s :=
filter.has_basis_cocompact.mem_iff.trans $ exists_congr $ λ t, exists_prop
lemma filter.mem_cocompact' : s ∈ filter.cocompact α ↔ ∃ t, is_compact t ∧ sᶜ ⊆ t :=
filter.mem_cocompact.trans $ exists_congr $ λ t, and_congr_right $ λ ht, compl_subset_comm
lemma is_compact.compl_mem_cocompact (hs : is_compact s) : sᶜ ∈ filter.cocompact α :=
filter.has_basis_cocompact.mem_of_mem hs
section tube_lemma
variables [topological_space β]
/-- `nhds_contain_boxes s t` means that any open neighborhood of `s × t` in `α × β` includes
a product of an open neighborhood of `s` by an open neighborhood of `t`. -/
def nhds_contain_boxes (s : set α) (t : set β) : Prop :=
∀ (n : set (α × β)) (hn : is_open n) (hp : set.prod s t ⊆ n),
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n
lemma nhds_contain_boxes.symm {s : set α} {t : set β} :
nhds_contain_boxes s t → nhds_contain_boxes t s :=
assume H n hn hp,
let ⟨u, v, uo, vo, su, tv, p⟩ :=
H (prod.swap ⁻¹' n)
(hn.preimage continuous_swap)
(by rwa [←image_subset_iff, image_swap_prod]) in
⟨v, u, vo, uo, tv, su,
by rwa [←image_subset_iff, image_swap_prod] at p⟩
lemma nhds_contain_boxes.comm {s : set α} {t : set β} :
nhds_contain_boxes s t ↔ nhds_contain_boxes t s :=
iff.intro nhds_contain_boxes.symm nhds_contain_boxes.symm
lemma nhds_contain_boxes_of_singleton {x : α} {y : β} :
nhds_contain_boxes ({x} : set α) ({y} : set β) :=
assume n hn hp,
let ⟨u, v, uo, vo, xu, yv, hp'⟩ :=
is_open_prod_iff.mp hn x y (hp $ by simp) in
⟨u, v, uo, vo, by simpa, by simpa, hp'⟩
lemma nhds_contain_boxes_of_compact {s : set α} (hs : is_compact s) (t : set β)
(H : ∀ x ∈ s, nhds_contain_boxes ({x} : set α) t) : nhds_contain_boxes s t :=
assume n hn hp,
have ∀x : subtype s, ∃uv : set α × set β,
is_open uv.1 ∧ is_open uv.2 ∧ {↑x} ⊆ uv.1 ∧ t ⊆ uv.2 ∧ set.prod uv.1 uv.2 ⊆ n,
from assume ⟨x, hx⟩,
have set.prod {x} t ⊆ n, from
subset.trans (prod_mono (by simpa) (subset.refl _)) hp,
let ⟨ux,vx,H1⟩ := H x hx n hn this in ⟨⟨ux,vx⟩,H1⟩,
let ⟨uvs, h⟩ := classical.axiom_of_choice this in
have us_cover : s ⊆ ⋃i, (uvs i).1, from
assume x hx, subset_Union _ ⟨x,hx⟩ (by simpa using (h ⟨x,hx⟩).2.2.1),
let ⟨s0, s0_cover⟩ :=
hs.elim_finite_subcover _ (λi, (h i).1) us_cover in
let u := ⋃(i ∈ s0), (uvs i).1 in
let v := ⋂(i ∈ s0), (uvs i).2 in
have is_open u, from is_open_bUnion (λi _, (h i).1),
have is_open v, from is_open_bInter s0.finite_to_set (λi _, (h i).2.1),
have t ⊆ v, from subset_bInter (λi _, (h i).2.2.2.1),
have set.prod u v ⊆ n, from assume ⟨x',y'⟩ ⟨hx',hy'⟩,
have ∃i ∈ s0, x' ∈ (uvs i).1, by simpa using hx',
let ⟨i,is0,hi⟩ := this in
(h i).2.2.2.2 ⟨hi, (bInter_subset_of_mem is0 : v ⊆ (uvs i).2) hy'⟩,
⟨u, v, ‹is_open u›, ‹is_open v›, s0_cover, ‹t ⊆ v›, ‹set.prod u v ⊆ n›⟩
/-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist
open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`. -/
lemma generalized_tube_lemma {s : set α} (hs : is_compact s) {t : set β} (ht : is_compact t)
{n : set (α × β)} (hn : is_open n) (hp : set.prod s t ⊆ n) :
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n :=
have _, from
nhds_contain_boxes_of_compact hs t $ assume x _, nhds_contain_boxes.symm $
nhds_contain_boxes_of_compact ht {x} $ assume y _, nhds_contain_boxes_of_singleton,
this n hn hp
end tube_lemma
/-- Type class for compact spaces. Separation is sometimes included in the definition, especially
in the French literature, but we do not include it here. -/
class compact_space (α : Type*) [topological_space α] : Prop :=
(compact_univ : is_compact (univ : set α))
lemma compact_univ [h : compact_space α] : is_compact (univ : set α) := h.compact_univ
lemma cluster_point_of_compact [compact_space α] (f : filter α) [ne_bot f] :
∃ x, cluster_pt x f :=
by simpa using compact_univ (show f ≤ 𝓟 univ, by simp)
theorem compact_space_of_finite_subfamily_closed {α : Type u} [topological_space α]
(h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →
(⋂ i, Z i) = ∅ → (∃ (t : finset ι), (⋂ i ∈ t, Z i) = ∅)) :
compact_space α :=
{ compact_univ :=
begin
apply compact_of_finite_subfamily_closed,
intros ι Z, specialize h Z,
simpa using h
end }
lemma is_closed.compact [compact_space α] {s : set α} (h : is_closed s) :
is_compact s :=
compact_of_is_closed_subset compact_univ h (subset_univ _)
variables [topological_space β]
lemma is_compact.image_of_continuous_on {f : α → β} (hs : is_compact s) (hf : continuous_on f s) :
is_compact (f '' s) :=
begin
intros l lne ls,
have : ne_bot (l.comap f ⊓ 𝓟 s) :=
comap_inf_principal_ne_bot_of_image_mem lne (le_principal_iff.1 ls),
obtain ⟨a, has, ha⟩ : ∃ a ∈ s, cluster_pt a (l.comap f ⊓ 𝓟 s) := @@hs this inf_le_right,
use [f a, mem_image_of_mem f has],
have : tendsto f (𝓝 a ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f a) ⊓ l),
{ convert (hf a has).inf (@tendsto_comap _ _ f l) using 1,
rw nhds_within,
ac_refl },
exact @@tendsto.ne_bot _ this ha,
end
lemma is_compact.image {f : α → β} (hs : is_compact s) (hf : continuous f) :
is_compact (f '' s) :=
hs.image_of_continuous_on hf.continuous_on
lemma compact_range [compact_space α] {f : α → β} (hf : continuous f) :
is_compact (range f) :=
by rw ← image_univ; exact compact_univ.image hf
/-- If X is is_compact then pr₂ : X × Y → Y is a closed map -/
theorem is_closed_proj_of_compact
{X : Type*} [topological_space X] [compact_space X]
{Y : Type*} [topological_space Y] :
is_closed_map (prod.snd : X × Y → Y) :=
begin
set πX := (prod.fst : X × Y → X),
set πY := (prod.snd : X × Y → Y),
assume C (hC : is_closed C),
rw is_closed_iff_cluster_pt at hC ⊢,
assume y (y_closure : cluster_pt y $ 𝓟 (πY '' C)),
have : ne_bot (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)),
{ suffices : ne_bot (map πY (comap πY (𝓝 y) ⊓ 𝓟 C)),
by simpa only [map_ne_bot_iff],
calc map πY (comap πY (𝓝 y) ⊓ 𝓟 C) =
𝓝 y ⊓ map πY (𝓟 C) : filter.push_pull' _ _ _
... = 𝓝 y ⊓ 𝓟 (πY '' C) : by rw map_principal
... ≠ ⊥ : y_closure },
resetI,
obtain ⟨x, hx⟩ : ∃ x, cluster_pt x (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)),
from cluster_point_of_compact _,
refine ⟨⟨x, y⟩, _, by simp [πY]⟩,
apply hC,
rw [cluster_pt, ← filter.map_ne_bot_iff πX],
calc map πX (𝓝 (x, y) ⊓ 𝓟 C)
= map πX (comap πX (𝓝 x) ⊓ comap πY (𝓝 y) ⊓ 𝓟 C) : by rw [nhds_prod_eq, filter.prod]
... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C ⊓ comap πX (𝓝 x)) : by ac_refl
... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C) ⊓ 𝓝 x : by rw filter.push_pull
... = 𝓝 x ⊓ map πX (comap πY (𝓝 y) ⊓ 𝓟 C) : by rw inf_comm
... ≠ ⊥ : hx,
end
lemma embedding.compact_iff_compact_image {f : α → β} (hf : embedding f) :
is_compact s ↔ is_compact (f '' s) :=
iff.intro (assume h, h.image hf.continuous) $ assume h, begin
rw compact_iff_ultrafilter_le_nhds at ⊢ h,
intros u us',
have : ↑(u.map f) ≤ 𝓟 (f '' s), begin
rw [ultrafilter.coe_map, map_le_iff_le_comap, comap_principal], convert us',
exact preimage_image_eq _ hf.inj
end,
rcases h (u.map f) this with ⟨_, ⟨a, ha, ⟨⟩⟩, _⟩,
refine ⟨a, ha, _⟩,
rwa [hf.induced, nhds_induced, ←map_le_iff_le_comap]
end
lemma compact_iff_compact_in_subtype {p : α → Prop} {s : set {a // p a}} :
is_compact s ↔ is_compact ((coe : _ → α) '' s) :=
embedding_subtype_coe.compact_iff_compact_image
lemma compact_iff_compact_univ {s : set α} : is_compact s ↔ is_compact (univ : set s) :=
by rw [compact_iff_compact_in_subtype, image_univ, subtype.range_coe]; refl
lemma compact_iff_compact_space {s : set α} : is_compact s ↔ compact_space s :=
compact_iff_compact_univ.trans ⟨λ h, ⟨h⟩, @compact_space.compact_univ _ _⟩
lemma is_compact.prod {s : set α} {t : set β} (hs : is_compact s) (ht : is_compact t) :
is_compact (set.prod s t) :=
begin
rw compact_iff_ultrafilter_le_nhds at hs ht ⊢,
intros f hfs,
rw le_principal_iff at hfs,
obtain ⟨a : α, sa : a ∈ s, ha : map prod.fst ↑f ≤ 𝓝 a⟩ :=
hs (f.map prod.fst) (le_principal_iff.2 $ mem_map.2 $ mem_sets_of_superset hfs (λ x, and.left)),
obtain ⟨b : β, tb : b ∈ t, hb : map prod.snd ↑f ≤ 𝓝 b⟩ :=
ht (f.map prod.snd) (le_principal_iff.2 $ mem_map.2 $
mem_sets_of_superset hfs (λ x, and.right)),
rw map_le_iff_le_comap at ha hb,
refine ⟨⟨a, b⟩, ⟨sa, tb⟩, _⟩,
rw nhds_prod_eq, exact le_inf ha hb
end
/-- Finite topological spaces are compact. -/
@[priority 100] instance fintype.compact_space [fintype α] : compact_space α :=
{ compact_univ := finite_univ.is_compact }
/-- The product of two compact spaces is compact. -/
instance [compact_space α] [compact_space β] : compact_space (α × β) :=
⟨by { rw ← univ_prod_univ, exact compact_univ.prod compact_univ }⟩
/-- The disjoint union of two compact spaces is compact. -/
instance [compact_space α] [compact_space β] : compact_space (α ⊕ β) :=
⟨begin
rw ← range_inl_union_range_inr,
exact (compact_range continuous_inl).union (compact_range continuous_inr)
end⟩
section tychonoff
variables {ι : Type*} {π : ι → Type*} [∀i, topological_space (π i)]
/-- Tychonoff's theorem -/
lemma compact_pi_infinite {s : Πi:ι, set (π i)} :
(∀i, is_compact (s i)) → is_compact {x : Πi:ι, π i | ∀i, x i ∈ s i} :=
begin
simp only [compact_iff_ultrafilter_le_nhds, nhds_pi, exists_prop, mem_set_of_eq, le_infi_iff,
le_principal_iff],
intros h f hfs,
have : ∀i:ι, ∃a, a∈s i ∧ tendsto (λx:Πi:ι, π i, x i) f (𝓝 a),
{ refine λ i, h i (f.map _) (mem_map.2 _),
exact mem_sets_of_superset hfs (λ x hx, hx i) },
choose a ha,
exact ⟨a, assume i, (ha i).left, assume i, (ha i).right.le_comap⟩
end
/-- A version of Tychonoff's theorem that uses `set.pi`. -/
lemma compact_univ_pi {s : Πi:ι, set (π i)} (h : ∀i, is_compact (s i)) :
is_compact (pi univ s) :=
by { convert compact_pi_infinite h, simp only [pi, forall_prop_of_true, mem_univ] }
instance pi.compact [∀i:ι, compact_space (π i)] : compact_space (Πi, π i) :=
⟨begin
have A : is_compact {x : Πi:ι, π i | ∀i, x i ∈ (univ : set (π i))} :=
compact_pi_infinite (λi, compact_univ),
have : {x : Πi:ι, π i | ∀i, x i ∈ (univ : set (π i))} = univ := by ext; simp,
rwa this at A,
end⟩
end tychonoff
instance quot.compact_space {r : α → α → Prop} [compact_space α] :
compact_space (quot r) :=
⟨by { rw ← range_quot_mk, exact compact_range continuous_quot_mk }⟩
instance quotient.compact_space {s : setoid α} [compact_space α] :
compact_space (quotient s) :=
quot.compact_space
/-- There are various definitions of "locally compact space" in the literature, which agree for
Hausdorff spaces but not in general. This one is the precise condition on X needed for the
evaluation `map C(X, Y) × X → Y` to be continuous for all `Y` when `C(X, Y)` is given the
compact-open topology. -/
class locally_compact_space (α : Type*) [topological_space α] : Prop :=
(local_compact_nhds : ∀ (x : α) (n ∈ 𝓝 x), ∃ s ∈ 𝓝 x, s ⊆ n ∧ is_compact s)
/-- A reformulation of the definition of locally compact space: In a locally compact space,
every open set containing `x` has a compact subset containing `x` in its interior. -/
lemma exists_compact_subset [locally_compact_space α] {x : α} {U : set α}
(hU : is_open U) (hx : x ∈ U) : ∃ (K : set α), is_compact K ∧ x ∈ interior K ∧ K ⊆ U :=
begin
rcases locally_compact_space.local_compact_nhds x U _ with ⟨K, h1K, h2K, h3K⟩,
{ refine ⟨K, h3K, _, h2K⟩, rwa [ mem_interior_iff_mem_nhds] },
rwa [← mem_interior_iff_mem_nhds, hU.interior_eq]
end
lemma ultrafilter.le_nhds_Lim [compact_space α] (F : ultrafilter α) :
↑F ≤ 𝓝 (@Lim _ _ (F : filter α).nonempty_of_ne_bot F) :=
begin
rcases compact_univ.ultrafilter_le_nhds F (by simp) with ⟨x, -, h⟩,
exact le_nhds_Lim ⟨x,h⟩,
end
variables (α)
/-- A σ-compact space is a space that is the union of a countable collection of compact subspaces.
Note that a locally compact separable T₂ space need not be σ-compact.
The sequence can be extracted using `topological_space.compact_covering`. -/
class sigma_compact_space (α : Type*) [topological_space α] : Prop :=
(exists_compact_covering : ∃ K : ℕ → set α, (∀ n, is_compact (K n)) ∧ (⋃ n, K n) = univ)
variables [sigma_compact_space α]
open sigma_compact_space
/-- An arbitrary compact covering of a σ-compact space. -/
def compact_covering : ℕ → set α :=
classical.some exists_compact_covering
lemma is_compact_compact_covering (n : ℕ) : is_compact (compact_covering α n) :=
(classical.some_spec sigma_compact_space.exists_compact_covering).1 n
lemma Union_compact_covering : (⋃ n, compact_covering α n) = univ :=
(classical.some_spec sigma_compact_space.exists_compact_covering).2
end compact
section clopen
/-- A set is clopen if it is both open and closed. -/
def is_clopen (s : set α) : Prop :=
is_open s ∧ is_closed s
theorem is_clopen_union {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∪ t) :=
⟨is_open_union hs.1 ht.1, is_closed_union hs.2 ht.2⟩
theorem is_clopen_inter {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ t) :=
⟨is_open_inter hs.1 ht.1, is_closed_inter hs.2 ht.2⟩
@[simp] theorem is_clopen_empty : is_clopen (∅ : set α) :=
⟨is_open_empty, is_closed_empty⟩
@[simp] theorem is_clopen_univ : is_clopen (univ : set α) :=
⟨is_open_univ, is_closed_univ⟩
theorem is_clopen_compl {s : set α} (hs : is_clopen s) : is_clopen sᶜ :=
⟨hs.2, is_closed_compl_iff.2 hs.1⟩
@[simp] theorem is_clopen_compl_iff {s : set α} : is_clopen sᶜ ↔ is_clopen s :=
⟨λ h, compl_compl s ▸ is_clopen_compl h, is_clopen_compl⟩
theorem is_clopen_diff {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s \ t) :=
is_clopen_inter hs (is_clopen_compl ht)
lemma is_clopen_Inter {β : Type*} [fintype β] {s : β → set α}
(h : ∀ i, is_clopen (s i)) : is_clopen (⋂ i, s i) :=
⟨(is_open_Inter (forall_and_distrib.1 h).1), (is_closed_Inter (forall_and_distrib.1 h).2)⟩
lemma is_clopen_bInter {β : Type*} {s : finset β} {f : β → set α} (h : ∀i∈s, is_clopen (f i)) :
is_clopen (⋂i∈s, f i) :=
⟨ is_open_bInter ⟨finset_coe.fintype s⟩ (λ i hi, (h i hi).1),
by {show is_closed (⋂ (i : β) (H : i ∈ (↑s : set β)), f i), rw bInter_eq_Inter,
apply is_closed_Inter, rintro ⟨i, hi⟩, exact (h i hi).2}⟩
lemma continuous_on.preimage_clopen_of_clopen {β: Type*} [topological_space β]
{f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_clopen s)
(ht : is_clopen t) : is_clopen (s ∩ f⁻¹' t) :=
⟨continuous_on.preimage_open_of_open hf hs.1 ht.1, continuous_on.preimage_closed_of_closed hf hs.2 ht.2⟩
/-- The intersection of a disjoint covering by two open sets of a clopen set will be clopen. -/
theorem is_clopen_inter_of_disjoint_cover_clopen {Z a b : set α} (h : is_clopen Z)
(cover : Z ⊆ a ∪ b) (ha : is_open a) (hb : is_open b) (hab : a ∩ b = ∅) : is_clopen (Z ∩ a) :=
begin
refine ⟨is_open_inter h.1 ha, _⟩,
have : is_closed (Z ∩ bᶜ) := is_closed_inter h.2 (is_closed_compl_iff.2 hb),
convert this using 1,
apply subset.antisymm,
{ exact inter_subset_inter_right Z (subset_compl_iff_disjoint.2 hab) },
{ rintros x ⟨hx₁, hx₂⟩,
exact ⟨hx₁, by simpa [not_mem_of_mem_compl hx₂] using cover hx₁⟩ }
end
end clopen
section preirreducible
/-- A preirreducible set `s` is one where there is no non-trivial pair of disjoint opens on `s`. -/
def is_preirreducible (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- An irreducible set `s` is one that is nonempty and
where there is no non-trivial pair of disjoint opens on `s`. -/
def is_irreducible (s : set α) : Prop :=
s.nonempty ∧ is_preirreducible s
lemma is_irreducible.nonempty {s : set α} (h : is_irreducible s) :
s.nonempty := h.1
lemma is_irreducible.is_preirreducible {s : set α} (h : is_irreducible s) :
is_preirreducible s := h.2
theorem is_preirreducible_empty : is_preirreducible (∅ : set α) :=
λ _ _ _ _ _ ⟨x, h1, h2⟩, h1.elim
theorem is_irreducible_singleton {x} : is_irreducible ({x} : set α) :=
⟨singleton_nonempty x,
λ u v _ _ ⟨y, h1, h2⟩ ⟨z, h3, h4⟩, by rw mem_singleton_iff at h1 h3;
substs y z; exact ⟨x, rfl, h2, h4⟩⟩
theorem is_preirreducible.closure {s : set α} (H : is_preirreducible s) :
is_preirreducible (closure s) :=
λ u v hu hv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in
let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in
let ⟨r, hrs, hruv⟩ := H u v hu hv ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
lemma is_irreducible.closure {s : set α} (h : is_irreducible s) :
is_irreducible (closure s) :=
⟨h.nonempty.closure, h.is_preirreducible.closure⟩
theorem exists_preirreducible (s : set α) (H : is_preirreducible s) :
∃ t : set α, is_preirreducible t ∧ s ⊆ t ∧ ∀ u, is_preirreducible u → t ⊆ u → u = t :=
let ⟨m, hm, hsm, hmm⟩ := zorn.zorn_subset₀ {t : set α | is_preirreducible t}
(λ c hc hcc hcn, let ⟨t, htc⟩ := hcn in
⟨⋃₀ c, λ u v hu hv ⟨y, hy, hyu⟩ ⟨z, hz, hzv⟩,
let ⟨p, hpc, hyp⟩ := mem_sUnion.1 hy,
⟨q, hqc, hzq⟩ := mem_sUnion.1 hz in
or.cases_on (zorn.chain.total hcc hpc hqc)
(assume hpq : p ⊆ q, let ⟨x, hxp, hxuv⟩ := hc hqc u v hu hv
⟨y, hpq hyp, hyu⟩ ⟨z, hzq, hzv⟩ in
⟨x, mem_sUnion_of_mem hxp hqc, hxuv⟩)
(assume hqp : q ⊆ p, let ⟨x, hxp, hxuv⟩ := hc hpc u v hu hv
⟨y, hyp, hyu⟩ ⟨z, hqp hzq, hzv⟩ in
⟨x, mem_sUnion_of_mem hxp hpc, hxuv⟩),
λ x hxc, subset_sUnion_of_mem hxc⟩) s H in
⟨m, hm, hsm, λ u hu hmu, hmm _ hu hmu⟩
/-- A maximal irreducible set that contains a given point. -/
def irreducible_component (x : α) : set α :=
classical.some (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)
lemma irreducible_component_property (x : α) :
is_preirreducible (irreducible_component x) ∧ {x} ⊆ (irreducible_component x) ∧
∀ u, is_preirreducible u → (irreducible_component x) ⊆ u → u = (irreducible_component x) :=
classical.some_spec (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)
theorem mem_irreducible_component {x : α} : x ∈ irreducible_component x :=
singleton_subset_iff.1 (irreducible_component_property x).2.1
theorem is_irreducible_irreducible_component {x : α} : is_irreducible (irreducible_component x) :=
⟨⟨x, mem_irreducible_component⟩, (irreducible_component_property x).1⟩
theorem eq_irreducible_component {x : α} :
∀ {s : set α}, is_preirreducible s → irreducible_component x ⊆ s → s = irreducible_component x :=
(irreducible_component_property x).2.2
theorem is_closed_irreducible_component {x : α} :
is_closed (irreducible_component x) :=
closure_eq_iff_is_closed.1 $ eq_irreducible_component
is_irreducible_irreducible_component.is_preirreducible.closure
subset_closure
/-- A preirreducible space is one where there is no non-trivial pair of disjoint opens. -/
class preirreducible_space (α : Type u) [topological_space α] : Prop :=
(is_preirreducible_univ [] : is_preirreducible (univ : set α))
/-- An irreducible space is one that is nonempty
and where there is no non-trivial pair of disjoint opens. -/
class irreducible_space (α : Type u) [topological_space α] extends preirreducible_space α : Prop :=
(to_nonempty [] : nonempty α)
attribute [instance, priority 50] irreducible_space.to_nonempty -- see Note [lower instance priority]
theorem nonempty_preirreducible_inter [preirreducible_space α] {s t : set α} :
is_open s → is_open t → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preirreducible_space.is_preirreducible_univ α _ _ s t
theorem is_preirreducible.image [topological_space β] {s : set α} (H : is_preirreducible s)
(f : α → β) (hf : continuous_on f s) : is_preirreducible (f '' s) :=
begin
rintros u v hu hv ⟨_, ⟨⟨x, hx, rfl⟩, hxu⟩⟩ ⟨_, ⟨⟨y, hy, rfl⟩, hyv⟩⟩,
rw ← mem_preimage at hxu hyv,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
have := H u' v' hu' hv',
rw [inter_comm s u', ← u'_eq] at this,
rw [inter_comm s v', ← v'_eq] at this,
rcases this ⟨x, hxu, hx⟩ ⟨y, hyv, hy⟩ with ⟨z, hzs, hzu', hzv'⟩,
refine ⟨f z, mem_image_of_mem f hzs, _, _⟩,
all_goals
{ rw ← mem_preimage,
apply mem_of_mem_inter_left,
show z ∈ _ ∩ s,
simp [*] }
end
theorem is_irreducible.image [topological_space β] {s : set α} (H : is_irreducible s)
(f : α → β) (hf : continuous_on f s) : is_irreducible (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preirreducible.image f hf⟩
lemma subtype.preirreducible_space {s : set α} (h : is_preirreducible s) :
preirreducible_space s :=
{ is_preirreducible_univ :=
begin
intros u v hu hv hsu hsv,
rw is_open_induced_iff at hu hv,
rcases hu with ⟨u, hu, rfl⟩,
rcases hv with ⟨v, hv, rfl⟩,
rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩,
rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩,
rcases h u v hu hv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩,
exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩
end }
lemma subtype.irreducible_space {s : set α} (h : is_irreducible s) :
irreducible_space s :=
{ is_preirreducible_univ :=
(subtype.preirreducible_space h.is_preirreducible).is_preirreducible_univ,
to_nonempty := h.nonempty.to_subtype }
/-- A set `s` is irreducible if and only if
for every finite collection of open sets all of whose members intersect `s`,
`s` also intersects the intersection of the entire collection
(i.e., there is an element of `s` contained in every member of the collection). -/
lemma is_irreducible_iff_sInter {s : set α} :
is_irreducible s ↔
∀ (U : finset (set α)) (hU : ∀ u ∈ U, is_open u) (H : ∀ u ∈ U, (s ∩ u).nonempty),
(s ∩ ⋂₀ ↑U).nonempty :=
begin
split; intro h,
{ intro U, apply finset.induction_on U,
{ intros, simpa using h.nonempty },
{ intros u U hu IH hU H,
rw [finset.coe_insert, sInter_insert],
apply h.2,
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sInter (finset.finite_to_set U),
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ solve_by_elim [finset.mem_insert_self] },
{ apply IH,
all_goals { intros, solve_by_elim [finset.mem_insert_of_mem] } } } },
{ split,
{ simpa using h ∅ _ _; intro u; simp },
intros u v hu hv hu' hv',
simpa using h {u,v} _ _,
all_goals
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption } }
end
/-- A set is preirreducible if and only if
for every cover by two closed sets, it is contained in one of the two covering sets. -/
lemma is_preirreducible_iff_closed_union_closed {s : set α} :
is_preirreducible s ↔
∀ (z₁ z₂ : set α), is_closed z₁ → is_closed z₂ → s ⊆ z₁ ∪ z₂ → s ⊆ z₁ ∨ s ⊆ z₂ :=
begin
split,
all_goals
{ intros h t₁ t₂ ht₁ ht₂,
specialize h t₁ᶜ t₂ᶜ,
simp only [is_open_compl_iff, is_closed_compl_iff] at h,
specialize h ht₁ ht₂ },
{ contrapose!, simp only [not_subset],
rintro ⟨⟨x, hx, hx'⟩, ⟨y, hy, hy'⟩⟩,
rcases h ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩ with ⟨z, hz, hz'⟩,
rw ← compl_union at hz',
exact ⟨z, hz, hz'⟩ },
{ rintro ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩,
rw ← compl_inter at h,
delta set.nonempty,
rw imp_iff_not_or at h,
contrapose! h,
split,
{ intros z hz hz', exact h z ⟨hz, hz'⟩ },
{ split; intro H; refine H _ ‹_›; assumption } }
end
/-- A set is irreducible if and only if
for every cover by a finite collection of closed sets,
it is contained in one of the members of the collection. -/
lemma is_irreducible_iff_sUnion_closed {s : set α} :
is_irreducible s ↔
∀ (Z : finset (set α)) (hZ : ∀ z ∈ Z, is_closed z) (H : s ⊆ ⋃₀ ↑Z),
∃ z ∈ Z, s ⊆ z :=
begin
rw [is_irreducible, is_preirreducible_iff_closed_union_closed],
split; intro h,
{ intro Z, apply finset.induction_on Z,
{ intros, rw [finset.coe_empty, sUnion_empty] at H,
rcases h.1 with ⟨x, hx⟩,
exfalso, tauto },
{ intros z Z hz IH hZ H,
cases h.2 z (⋃₀ ↑Z) _ _ _
with h' h',
{ exact ⟨z, finset.mem_insert_self _ _, h'⟩ },
{ rcases IH _ h' with ⟨z', hz', hsz'⟩,
{ exact ⟨z', finset.mem_insert_of_mem hz', hsz'⟩ },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ rw sUnion_eq_bUnion,
apply is_closed_bUnion (finset.finite_to_set Z),
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ simpa using H } } },
{ split,
{ by_contradiction hs,
simpa using h ∅ _ _,
{ intro z, simp },
{ simpa [set.nonempty] using hs } },
intros z₁ z₂ hz₁ hz₂ H,
have := h {z₁, z₂} _ _,
simp only [exists_prop, finset.mem_insert, finset.mem_singleton] at this,
{ rcases this with ⟨z, rfl|rfl, hz⟩; tauto },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using H } }
end
end preirreducible
section preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def is_preconnected (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def is_connected (s : set α) : Prop :=
s.nonempty ∧ is_preconnected s
lemma is_connected.nonempty {s : set α} (h : is_connected s) :
s.nonempty := h.1
lemma is_connected.is_preconnected {s : set α} (h : is_connected s) :
is_preconnected s := h.2
theorem is_preirreducible.is_preconnected {s : set α} (H : is_preirreducible s) :
is_preconnected s :=
λ _ _ hu hv _, H _ _ hu hv
theorem is_irreducible.is_connected {s : set α} (H : is_irreducible s) : is_connected s :=
⟨H.nonempty, H.is_preirreducible.is_preconnected⟩
theorem is_preconnected_empty : is_preconnected (∅ : set α) :=
is_preirreducible_empty.is_preconnected
theorem is_connected_singleton {x} : is_connected ({x} : set α) :=
is_irreducible_singleton.is_connected
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall {s : set α} (x : α)
(H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩,
have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt },
wlog xu : x ∈ u := hs xs using [u v y z, v u z y],
rcases H y ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall_pair {s : set α}
(H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
rcases H x y xs ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem is_preconnected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, is_preconnected s) : is_preconnected (⋃₀ c) :=
begin
apply is_preconnected_of_forall x,
rintros y ⟨s, sc, ys⟩,
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
end
theorem is_preconnected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t)
(H3 : is_preconnected s) (H4 : is_preconnected t) : is_preconnected (s ∪ t) :=
sUnion_pair s t ▸ is_preconnected_sUnion x {s, t}
(by rintro r (rfl | rfl | h); assumption)
(by rintro r (rfl | rfl | h); assumption)
theorem is_connected.union {s t : set α} (H : (s ∩ t).nonempty)
(Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) :=
begin
rcases H with ⟨x, hx⟩,
refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, _⟩,
exact is_preconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx)
Hs.is_preconnected Ht.is_preconnected
end
theorem is_preconnected.closure {s : set α} (H : is_preconnected s) :
is_preconnected (closure s) :=
λ u v hu hv hcsuv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in
let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in
let ⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans subset_closure hcsuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
theorem is_connected.closure {s : set α} (H : is_connected s) :
is_connected (closure s) :=
⟨H.nonempty.closure, H.is_preconnected.closure⟩
theorem is_preconnected.image [topological_space β] {s : set α} (H : is_preconnected s)
(f : α → β) (hf : continuous_on f s) : is_preconnected (f '' s) :=
begin
-- Unfold/destruct definitions in hypotheses
rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
-- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'`
replace huv : s ⊆ u' ∪ v',
{ rw [image_subset_iff, preimage_union] at huv,
replace huv := subset_inter huv (subset.refl _),
rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv,
exact (subset_inter_iff.1 huv).1 },
-- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_preconnected s›`
obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty,
{ refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm,
exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] },
rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc,
inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz,
exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩
end
theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s)
(f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preconnected.image f hf⟩
theorem is_preconnected_closed_iff {s : set α} :
is_preconnected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' →
(s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty :=
⟨begin
rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h',
have xt' : x ∉ t', from (h' xs).elim (absurd xt) id,
have yt : y ∉ t, from (h' ys).elim id (absurd yt'),
have := ne_empty_iff_nonempty.2 (h tᶜ t'ᶜ (is_open_compl_iff.2 ht)
(is_open_compl_iff.2 ht') h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end,
begin
rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not,
← subset_compl_iff_disjoint, compl_inter] at h',
have xv : x ∉ v, from (h' xs).elim (absurd xu) id,
have yu : y ∉ u, from (h' ys).elim id (absurd yv),
have := ne_empty_iff_nonempty.2 (h uᶜ vᶜ (is_closed_compl_iff.2 hu)
(is_closed_compl_iff.2 hv) h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end⟩
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component (x : α) : set α :=
⋃₀ { s : set α | is_preconnected s ∧ x ∈ s }
/-- The connected component of a point inside a set. -/
def connected_component_in (F : set α) (x : F) : set α := coe '' (connected_component x)
theorem mem_connected_component {x : α} : x ∈ connected_component x :=
mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton.is_preconnected, mem_singleton x⟩
theorem is_connected_connected_component {x : α} : is_connected (connected_component x) :=
⟨⟨x, mem_connected_component⟩, is_preconnected_sUnion x _ (λ _, and.right) (λ _, and.left)⟩
theorem subset_connected_component {x : α} {s : set α} (H1 : is_preconnected s) (H2 : x ∈ s) :
s ⊆ connected_component x :=
λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩
theorem is_closed_connected_component {x : α} :
is_closed (connected_component x) :=
closure_eq_iff_is_closed.1 $ subset.antisymm
(subset_connected_component
is_connected_connected_component.closure.is_preconnected
(subset_closure mem_connected_component))
subset_closure
theorem irreducible_component_subset_connected_component {x : α} :
irreducible_component x ⊆ connected_component x :=
subset_connected_component
is_irreducible_irreducible_component.is_connected.is_preconnected
mem_irreducible_component
/-- A preconnected space is one where there is no non-trivial open partition. -/
class preconnected_space (α : Type u) [topological_space α] : Prop :=
(is_preconnected_univ : is_preconnected (univ : set α))
export preconnected_space (is_preconnected_univ)
/-- A connected space is a nonempty one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] extends preconnected_space α : Prop :=
(to_nonempty : nonempty α)
attribute [instance, priority 50] connected_space.to_nonempty -- see Note [lower instance priority]
lemma is_connected_range [topological_space β] [connected_space α] {f : α → β} (h : continuous f) :
is_connected (range f) :=
begin
inhabit α,
rw ← image_univ,
exact ⟨⟨f (default α), mem_image_of_mem _ (mem_univ _)⟩,
is_preconnected.image is_preconnected_univ _ h.continuous_on⟩
end
lemma connected_space_iff_connected_component :
connected_space α ↔ ∃ x : α, connected_component x = univ :=
begin
split,
{ rintros ⟨h, ⟨x⟩⟩,
exactI ⟨x, eq_univ_of_univ_subset $ subset_connected_component is_preconnected_univ (mem_univ x)⟩ },
{ rintros ⟨x, h⟩,
haveI : preconnected_space α := ⟨by {rw ← h, exact is_connected_connected_component.2 }⟩,
exact ⟨⟨x⟩⟩ }
end
@[priority 100] -- see Note [lower instance priority]
instance preirreducible_space.preconnected_space (α : Type u) [topological_space α]
[preirreducible_space α] : preconnected_space α :=
⟨(preirreducible_space.is_preirreducible_univ α).is_preconnected⟩
@[priority 100] -- see Note [lower instance priority]
instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
{ to_nonempty := irreducible_space.to_nonempty α }
theorem nonempty_inter [preconnected_space α] {s t : set α} :
is_open s → is_open t → s ∪ t = univ → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preconnected_space.is_preconnected_univ α _ _ s t
theorem is_clopen_iff [preconnected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ :=
⟨λ hs, classical.by_contradiction $ λ h,
have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅, from ⟨mt or.inl h,
mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩,
let ⟨_, h2, h3⟩ := nonempty_inter hs.1 hs.2 (union_compl_self s)
(ne_empty_iff_nonempty.1 h1.1) (ne_empty_iff_nonempty.1 h1.2) in
h3 h2,
by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩
lemma eq_univ_of_nonempty_clopen [preconnected_space α] {s : set α}
(h : s.nonempty) (h' : is_clopen s) : s = univ :=
by { rw is_clopen_iff at h', finish [h.ne_empty] }
lemma subtype.preconnected_space {s : set α} (h : is_preconnected s) :
preconnected_space s :=
{ is_preconnected_univ :=
begin
intros u v hu hv hs hsu hsv,
rw is_open_induced_iff at hu hv,
rcases hu with ⟨u, hu, rfl⟩,
rcases hv with ⟨v, hv, rfl⟩,
rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩,
rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩,
rcases h u v hu hv _ ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩,
exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩,
intros z hz,
rcases hs (mem_univ ⟨z, hz⟩) with hzu|hzv,
{ left, assumption },
{ right, assumption }
end }
lemma subtype.connected_space {s : set α} (h : is_connected s) :
connected_space s :=
{ is_preconnected_univ :=
(subtype.preconnected_space h.is_preconnected).is_preconnected_univ,
to_nonempty := h.nonempty.to_subtype }
lemma is_preconnected_iff_preconnected_space {s : set α} :
is_preconnected s ↔ preconnected_space s :=
⟨subtype.preconnected_space,
begin
introI,
simpa using is_preconnected_univ.image (coe : s → α) continuous_subtype_coe.continuous_on
end⟩
lemma is_connected_iff_connected_space {s : set α} : is_connected s ↔ connected_space s :=
⟨subtype.connected_space,
λ h, ⟨nonempty_subtype.mp h.2, is_preconnected_iff_preconnected_space.mpr h.1⟩⟩
/-- A set `s` is preconnected if and only if
for every cover by two open sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
lemma is_preconnected_iff_subset_of_disjoint {s : set α} :
is_preconnected s ↔
∀ (u v : set α) (hu : is_open u) (hv : is_open v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A set `s` is connected if and only if
for every cover by a finite collection of open sets that are pairwise disjoint on `s`,
it is contained in one of the members of the collection. -/
lemma is_connected_iff_sUnion_disjoint_open {s : set α} :
is_connected s ↔
∀ (U : finset (set α)) (H : ∀ (u v : set α), u ∈ U → v ∈ U → (s ∩ (u ∩ v)).nonempty → u = v)
(hU : ∀ u ∈ U, is_open u) (hs : s ⊆ ⋃₀ ↑U),
∃ u ∈ U, s ⊆ u :=
begin
rw [is_connected, is_preconnected_iff_subset_of_disjoint],
split; intro h,
{ intro U, apply finset.induction_on U,
{ rcases h.left,
suffices : s ⊆ ∅ → false, { simpa },
intro, solve_by_elim },
{ intros u U hu IH hs hU H,
rw [finset.coe_insert, sUnion_insert] at H,
cases h.2 u (⋃₀ ↑U) _ _ H _ with hsu hsU,
{ exact ⟨u, finset.mem_insert_self _ _, hsu⟩ },
{ rcases IH _ _ hsU with ⟨v, hvU, hsv⟩,
{ exact ⟨v, finset.mem_insert_of_mem hvU, hsv⟩ },
{ intros, apply hs; solve_by_elim [finset.mem_insert_of_mem] },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sUnion,
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ apply eq_empty_of_subset_empty,
rintro x ⟨hxs, hxu, hxU⟩,
rw mem_sUnion at hxU,
rcases hxU with ⟨v, hvU, hxv⟩,
rcases hs u v (finset.mem_insert_self _ _) (finset.mem_insert_of_mem hvU) _ with rfl,
{ contradiction },
{ exact ⟨x, hxs, hxu, hxv⟩ } } } },
{ split,
{ rw ← ne_empty_iff_nonempty,
by_contradiction hs, push_neg at hs, subst hs,
simpa using h ∅ _ _ _; simp },
intros u v hu hv hs hsuv,
rcases h {u, v} _ _ _ with ⟨t, ht, ht'⟩,
{ rw [finset.mem_insert, finset.mem_singleton] at ht,
rcases ht with rfl|rfl; tauto },
{ intros t₁ t₂ ht₁ ht₂ hst,
rw ← ne_empty_iff_nonempty at hst,
rw [finset.mem_insert, finset.mem_singleton] at ht₁ ht₂,
rcases ht₁ with rfl|rfl; rcases ht₂ with rfl|rfl,
all_goals { refl <|> contradiction <|> skip },
rw inter_comm t₁ at hst, contradiction },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using hs } }
end
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem subset_or_disjoint_of_clopen {α : Type*} [topological_space α] {s t : set α}
(h : is_preconnected t) (h1 : is_clopen s) : s ∩ t = ∅ ∨ t ⊆ s :=
begin
by_contradiction h2,
have h3 : (s ∩ t).nonempty := ne_empty_iff_nonempty.mp (mt or.inl h2),
have h4 : (t ∩ sᶜ).nonempty,
{ apply inter_compl_nonempty_iff.2,
push_neg at h2,
exact h2.2 },
rw [inter_comm] at h3,
apply ne_empty_iff_nonempty.2 (h s sᶜ h1.1 (is_open_compl_iff.2 h1.2) _ h3 h4),
{ rw [inter_compl_self, inter_empty] },
{ rw [union_compl_self],
exact subset_univ t },
end
/-- A set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_disjoint_closed {α : Type*} {s : set α} [topological_space α] :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
rw is_preconnected_closed_iff at h,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ rw is_preconnected_closed_iff,
intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A closed set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_fully_disjoint_closed {s : set α} (hs : is_closed s) :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hss : s ⊆ u ∪ v) (huv : u ∩ v = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split,
{ intros h u v hu hv hss huv,
apply is_preconnected_iff_subset_of_disjoint_closed.1 h u v hu hv hss,
rw huv,
exact inter_empty s },
intro H,
rw is_preconnected_iff_subset_of_disjoint_closed,
intros u v hu hv hss huv,
have H1 := H (u ∩ s) (v ∩ s),
rw [subset_inter_iff, subset_inter_iff] at H1,
simp only [subset.refl, and_true] at H1,
apply H1 (is_closed_inter hu hs) (is_closed_inter hv hs),
{ rw ←inter_distrib_right,
apply subset_inter_iff.2,
exact ⟨hss, subset.refl s⟩ },
{ rw [inter_comm v s, inter_assoc, ←inter_assoc s, inter_self s,
inter_comm, inter_assoc, inter_comm v u, huv] }
end
/-- The connected component of a point is always a subset of the intersection of all its clopen
neighbourhoods. -/
lemma connected_component_subset_Inter_clopen {x : α} :
connected_component x ⊆ ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z :=
begin
apply subset_Inter (λ Z, _),
cases (subset_or_disjoint_of_clopen (@is_connected_connected_component _ _ x).2 Z.2.1),
{ exfalso,
apply nonempty.ne_empty
(nonempty_of_mem (mem_inter (@mem_connected_component _ _ x) Z.2.2)),
rw inter_comm,
exact h },
exact h,
end
end preconnected
section totally_disconnected
/-- A set is called totally disconnected if all of its connected components are singletons. -/
def is_totally_disconnected (s : set α) : Prop :=
∀ t, t ⊆ s → is_preconnected t → subsingleton t
theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) :=
λ t ht _, ⟨λ ⟨_, h⟩, (ht h).elim⟩
theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) :=
λ t ht _, ⟨λ ⟨p, hp⟩ ⟨q, hq⟩, subtype.eq $ show p = q,
from (eq_of_mem_singleton (ht hp)).symm ▸ (eq_of_mem_singleton (ht hq)).symm⟩
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] : Prop :=
(is_totally_disconnected_univ : is_totally_disconnected (univ : set α))
instance pi.totally_disconnected_space {α : Type*} {β : α → Type*} [t₂ : Πa, topological_space (β a)]
[∀a, totally_disconnected_space (β a)] : totally_disconnected_space (Π (a : α), β a) :=
⟨λ t h1 h2, ⟨λ a b, subtype.ext $ funext $ λ x, subtype.mk_eq_mk.1 $
(totally_disconnected_space.is_totally_disconnected_univ
((λ (c : Π (a : α), β a), c x) '' t) (set.subset_univ _)
(is_preconnected.image h2 _ (continuous.continuous_on (continuous_apply _)))).cases_on
(λ h3, h3
⟨(a.1 x), by {simp only [set.mem_image, subtype.val_eq_coe], use a, split,
simp only [subtype.coe_prop]}⟩
⟨(b.1 x), by {simp only [set.mem_image, subtype.val_eq_coe], use b, split,
simp only [subtype.coe_prop]}⟩)⟩⟩
instance subtype.totally_disconnected_space {α : Type*} {p : α → Prop} [topological_space α]
[totally_disconnected_space α] : totally_disconnected_space (subtype p) :=
⟨λ s h1 h2,
set.subsingleton_of_image subtype.val_injective s (
totally_disconnected_space.is_totally_disconnected_univ (subtype.val '' s) (set.subset_univ _)
((is_preconnected.image h2 _) (continuous.continuous_on (@continuous_subtype_val _ _ p))))⟩
end totally_disconnected
section totally_separated
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated (s : set α) : Prop :=
∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧
x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ u ∩ v = ∅
theorem is_totally_separated_empty : is_totally_separated (∅ : set α) :=
λ x, false.elim
theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) :=
λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim
theorem is_totally_disconnected_of_is_totally_separated {s : set α}
(H : is_totally_separated s) : is_totally_disconnected s :=
λ t hts ht, ⟨λ ⟨x, hxt⟩ ⟨y, hyt⟩, subtype.eq $ classical.by_contradiction $
assume hxy : x ≠ y, let ⟨u, v, hu, hv, hxu, hyv, hsuv, huv⟩ := H x (hts hxt) y (hts hyt) hxy in
let ⟨r, hrt, hruv⟩ := ht u v hu hv (subset.trans hts hsuv) ⟨x, hxt, hxu⟩ ⟨y, hyt, hyv⟩ in
(ext_iff.1 huv r).1 hruv⟩
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] : Prop :=
(is_totally_separated_univ [] : is_totally_separated (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α]
[totally_separated_space α] : totally_disconnected_space α :=
⟨is_totally_disconnected_of_is_totally_separated $
totally_separated_space.is_totally_separated_univ α⟩
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.of_discrete
(α : Type*) [topological_space α] [discrete_topology α] : totally_separated_space α :=
⟨λ a _ b _ h, ⟨{b}ᶜ, {b}, is_open_discrete _, is_open_discrete _, by simpa⟩⟩
end totally_separated
|
af11beb9073cad1911622b92b8ebb8b94718282f | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/topology/uniform_space/uniform_embedding.lean | dbbf501d9f58032cb4946bcde14580d0578b9443 | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 20,063 | 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, Sébastien Gouëzel, Patrick Massot
-/
import topology.uniform_space.cauchy
import topology.uniform_space.separation
import topology.dense_embedding
/-!
# Uniform embeddings of uniform spaces.
Extension of uniform continuous functions.
-/
open filter topological_space set classical
open_locale classical uniformity topological_space filter
section
variables {α : Type*} {β : Type*} {γ : Type*}
[uniform_space α] [uniform_space β] [uniform_space γ]
universe u
structure uniform_inducing (f : α → β) : Prop :=
(comap_uniformity : comap (λx:α×α, (f x.1, f x.2)) (𝓤 β) = 𝓤 α)
lemma uniform_inducing.mk' {f : α → β} (h : ∀ s, s ∈ 𝓤 α ↔
∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : uniform_inducing f :=
⟨by simp [eq_comm, filter.ext_iff, subset_def, h]⟩
lemma uniform_inducing.comp {g : β → γ} (hg : uniform_inducing g)
{f : α → β} (hf : uniform_inducing f) : uniform_inducing (g ∘ f) :=
⟨ by rw [show (λ (x : α × α), ((g ∘ f) x.1, (g ∘ f) x.2)) =
(λ y : β × β, (g y.1, g y.2)) ∘ (λ x : α × α, (f x.1, f x.2)), by ext ; simp,
← filter.comap_comap, hg.1, hf.1]⟩
structure uniform_embedding (f : α → β) extends uniform_inducing f : Prop :=
(inj : function.injective f)
lemma uniform_embedding_subtype_val {p : α → Prop} :
uniform_embedding (subtype.val : subtype p → α) :=
{ comap_uniformity := rfl,
inj := subtype.val_injective }
lemma uniform_embedding_subtype_coe {p : α → Prop} :
uniform_embedding (coe : subtype p → α) :=
uniform_embedding_subtype_val
lemma uniform_embedding_set_inclusion {s t : set α} (hst : s ⊆ t) :
uniform_embedding (inclusion hst) :=
{ comap_uniformity :=
by { erw [uniformity_subtype, uniformity_subtype, comap_comap], congr },
inj := inclusion_injective hst }
lemma uniform_embedding.comp {g : β → γ} (hg : uniform_embedding g)
{f : α → β} (hf : uniform_embedding f) : uniform_embedding (g ∘ f) :=
{ inj := hg.inj.comp hf.inj,
..hg.to_uniform_inducing.comp hf.to_uniform_inducing }
theorem uniform_embedding_def {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ ∀ s, s ∈ 𝓤 α ↔
∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s :=
begin
split,
{ rintro ⟨⟨h⟩, h'⟩,
rw [eq_comm, filter.ext_iff] at h,
simp [*, subset_def] },
{ rintro ⟨h, h'⟩,
refine uniform_embedding.mk ⟨_⟩ h,
rw [eq_comm, filter.ext_iff],
simp [*, subset_def] }
end
theorem uniform_embedding_def' {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
∀ s, s ∈ 𝓤 α →
∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s :=
by simp [uniform_embedding_def, uniform_continuous_def]; exact
⟨λ ⟨I, H⟩, ⟨I, λ s su, (H _).2 ⟨s, su, λ x y, id⟩, λ s, (H s).1⟩,
λ ⟨I, H₁, H₂⟩, ⟨I, λ s, ⟨H₂ s,
λ ⟨t, tu, h⟩, sets_of_superset _ (H₁ t tu) (λ ⟨a, b⟩, h a b)⟩⟩⟩
lemma uniform_inducing.uniform_continuous {f : α → β}
(hf : uniform_inducing f) : uniform_continuous f :=
by simp [uniform_continuous, hf.comap_uniformity.symm, tendsto_comap]
lemma uniform_inducing.uniform_continuous_iff {f : α → β} {g : β → γ} (hg : uniform_inducing g) :
uniform_continuous f ↔ uniform_continuous (g ∘ f) :=
by simp [uniform_continuous, tendsto]; rw [← hg.comap_uniformity, ← map_le_iff_le_comap, filter.map_map]
lemma uniform_inducing.inducing {f : α → β} (h : uniform_inducing f) : inducing f :=
begin
refine ⟨eq_of_nhds_eq_nhds $ assume a, _ ⟩,
rw [nhds_induced, nhds_eq_uniformity, nhds_eq_uniformity, ← h.comap_uniformity,
comap_lift'_eq, comap_lift'_eq2];
{ refl <|> exact monotone_preimage }
end
lemma uniform_inducing.prod {α' : Type*} {β' : Type*} [uniform_space α'] [uniform_space β']
{e₁ : α → α'} {e₂ : β → β'} (h₁ : uniform_inducing e₁) (h₂ : uniform_inducing e₂) :
uniform_inducing (λp:α×β, (e₁ p.1, e₂ p.2)) :=
⟨by simp [(∘), uniformity_prod, h₁.comap_uniformity.symm, h₂.comap_uniformity.symm,
comap_inf, comap_comap]⟩
lemma uniform_inducing.dense_inducing {f : α → β} (h : uniform_inducing f) (hd : dense_range f) :
dense_inducing f :=
{ dense := hd,
induced := h.inducing.induced }
lemma uniform_embedding.embedding {f : α → β} (h : uniform_embedding f) : embedding f :=
{ induced := h.to_uniform_inducing.inducing.induced,
inj := h.inj }
lemma uniform_embedding.dense_embedding {f : α → β} (h : uniform_embedding f) (hd : dense_range f) :
dense_embedding f :=
{ dense := hd,
inj := h.inj,
induced := h.embedding.induced }
lemma closure_image_mem_nhds_of_uniform_inducing
{s : set (α×α)} {e : α → β} (b : β)
(he₁ : uniform_inducing e) (he₂ : dense_inducing e) (hs : s ∈ 𝓤 α) :
∃a, closure (e '' {a' | (a, a') ∈ s}) ∈ 𝓝 b :=
have s ∈ comap (λp:α×α, (e p.1, e p.2)) (𝓤 β),
from he₁.comap_uniformity.symm ▸ hs,
let ⟨t₁, ht₁u, ht₁⟩ := this in
have ht₁ : ∀p:α×α, (e p.1, e p.2) ∈ t₁ → p ∈ s, from ht₁,
let ⟨t₂, ht₂u, ht₂s, ht₂c⟩ := comp_symm_of_uniformity ht₁u in
let ⟨t, htu, hts, htc⟩ := comp_symm_of_uniformity ht₂u in
have preimage e {b' | (b, b') ∈ t₂} ∈ comap e (𝓝 b),
from preimage_mem_comap $ mem_nhds_left b ht₂u,
let ⟨a, (ha : (b, e a) ∈ t₂)⟩ := (he₂.comap_nhds_ne_bot _).nonempty_of_mem this in
have ∀b' (s' : set (β × β)), (b, b') ∈ t → s' ∈ 𝓤 β →
({y : β | (b', y) ∈ s'} ∩ e '' {a' : α | (a, a') ∈ s}).nonempty,
from assume b' s' hb' hs',
have preimage e {b'' | (b', b'') ∈ s' ∩ t} ∈ comap e (𝓝 b'),
from preimage_mem_comap $ mem_nhds_left b' $ inter_mem_sets hs' htu,
let ⟨a₂, ha₂s', ha₂t⟩ := (he₂.comap_nhds_ne_bot _).nonempty_of_mem this in
have (e a, e a₂) ∈ t₁,
from ht₂c $ prod_mk_mem_comp_rel (ht₂s ha) $ htc $ prod_mk_mem_comp_rel hb' ha₂t,
have e a₂ ∈ {b'':β | (b', b'') ∈ s'} ∩ e '' {a' | (a, a') ∈ s},
from ⟨ha₂s', mem_image_of_mem _ $ ht₁ (a, a₂) this⟩,
⟨_, this⟩,
have ∀b', (b, b') ∈ t → ne_bot (𝓝 b' ⊓ 𝓟 (e '' {a' | (a, a') ∈ s})),
begin
intros b' hb',
rw [nhds_eq_uniformity, lift'_inf_principal_eq, lift'_ne_bot_iff],
exact assume s, this b' s hb',
exact monotone_inter monotone_preimage monotone_const
end,
have ∀b', (b, b') ∈ t → b' ∈ closure (e '' {a' | (a, a') ∈ s}),
from assume b' hb', by rw [closure_eq_cluster_pts]; exact this b' hb',
⟨a, (𝓝 b).sets_of_superset (mem_nhds_left b htu) this⟩
lemma uniform_embedding_subtype_emb (p : α → Prop) {e : α → β} (ue : uniform_embedding e)
(de : dense_embedding e) : uniform_embedding (dense_embedding.subtype_emb p e) :=
{ comap_uniformity := by simp [comap_comap, (∘), dense_embedding.subtype_emb,
uniformity_subtype, ue.comap_uniformity.symm],
inj := (de.subtype p).inj }
lemma uniform_embedding.prod {α' : Type*} {β' : Type*} [uniform_space α'] [uniform_space β']
{e₁ : α → α'} {e₂ : β → β'} (h₁ : uniform_embedding e₁) (h₂ : uniform_embedding e₂) :
uniform_embedding (λp:α×β, (e₁ p.1, e₂ p.2)) :=
{ inj := h₁.inj.prod_map h₂.inj,
..h₁.to_uniform_inducing.prod h₂.to_uniform_inducing }
lemma is_complete_of_complete_image {m : α → β} {s : set α} (hm : uniform_inducing m)
(hs : is_complete (m '' s)) : is_complete s :=
begin
intros f hf hfs,
rw le_principal_iff at hfs,
obtain ⟨_, ⟨x, hx, rfl⟩, hyf⟩ : ∃ y ∈ m '' s, map m f ≤ 𝓝 y,
from hs (f.map m) (hf.map hm.uniform_continuous)
(le_principal_iff.2 (image_mem_map hfs)),
rw [map_le_iff_le_comap, ← nhds_induced, ← hm.inducing.induced] at hyf,
exact ⟨x, hx, hyf⟩
end
/-- A set is complete iff its image under a uniform embedding is complete. -/
lemma is_complete_image_iff {m : α → β} {s : set α} (hm : uniform_embedding m) :
is_complete (m '' s) ↔ is_complete s :=
begin
refine ⟨is_complete_of_complete_image hm.to_uniform_inducing, λ c f hf fs, _⟩,
rw filter.le_principal_iff at fs,
let f' := comap m f,
have cf' : cauchy f',
{ haveI : ne_bot (comap m f) := by
{ refine comap_ne_bot (λt ht, _),
have A : t ∩ m '' s ∈ f := filter.inter_mem_sets ht fs,
obtain ⟨x, ⟨xt, ⟨y, ys, rfl⟩⟩⟩ : (t ∩ m '' s).nonempty,
from hf.1.nonempty_of_mem A,
exact ⟨y, xt⟩ },
exact hf.comap (le_of_eq hm.comap_uniformity) },
have : f' ≤ 𝓟 s := by simp [f']; exact
⟨m '' s, by simpa using fs, by simp [preimage_image_eq s hm.inj]⟩,
rcases c f' cf' this with ⟨x, xs, hx⟩,
existsi [m x, mem_image_of_mem m xs],
rw [(uniform_embedding.embedding hm).induced, nhds_induced] at hx,
calc f = map m f' : (map_comap $ filter.mem_sets_of_superset fs $ image_subset_range _ _).symm
... ≤ map m (comap m (𝓝 (m x))) : map_mono hx
... ≤ 𝓝 (m x) : map_comap_le
end
lemma complete_space_iff_is_complete_range {f : α → β} (hf : uniform_embedding f) :
complete_space α ↔ is_complete (range f) :=
by rw [complete_space_iff_is_complete_univ, ← is_complete_image_iff hf, image_univ]
lemma complete_space_congr {e : α ≃ β} (he : uniform_embedding e) :
complete_space α ↔ complete_space β :=
by rw [complete_space_iff_is_complete_range he, e.range_eq_univ,
complete_space_iff_is_complete_univ]
lemma complete_space_coe_iff_is_complete {s : set α} :
complete_space s ↔ is_complete s :=
(complete_space_iff_is_complete_range uniform_embedding_subtype_coe).trans $
by rw [subtype.range_coe]
lemma is_complete.complete_space_coe {s : set α} (hs : is_complete s) :
complete_space s :=
complete_space_coe_iff_is_complete.2 hs
lemma is_closed.complete_space_coe [complete_space α] {s : set α} (hs : is_closed s) :
complete_space s :=
hs.is_complete.complete_space_coe
lemma complete_space_extension {m : β → α} (hm : uniform_inducing m) (dense : dense_range m)
(h : ∀f:filter β, cauchy f → ∃x:α, map m f ≤ 𝓝 x) : complete_space α :=
⟨assume (f : filter α), assume hf : cauchy f,
let
p : set (α × α) → set α → set α := λs t, {y : α| ∃x:α, x ∈ t ∧ (x, y) ∈ s},
g := (𝓤 α).lift (λs, f.lift' (p s))
in
have mp₀ : monotone p,
from assume a b h t s ⟨x, xs, xa⟩, ⟨x, xs, h xa⟩,
have mp₁ : ∀{s}, monotone (p s),
from assume s a b h x ⟨y, ya, yxs⟩, ⟨y, h ya, yxs⟩,
have f ≤ g, from
le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht,
le_principal_iff.mpr $
mem_sets_of_superset ht $ assume x hx, ⟨x, hx, refl_mem_uniformity hs⟩,
have ne_bot g, from hf.left.mono this,
have ne_bot (comap m g), from comap_ne_bot $ assume t ht,
let ⟨t', ht', ht_mem⟩ := (mem_lift_sets $ monotone_lift' monotone_const mp₀).mp ht in
let ⟨t'', ht'', ht'_sub⟩ := (mem_lift'_sets mp₁).mp ht_mem in
let ⟨x, (hx : x ∈ t'')⟩ := hf.left.nonempty_of_mem ht'' in
have h₀ : ne_bot (nhds_within x (range m)),
from dense.nhds_within_ne_bot x,
have h₁ : {y | (x, y) ∈ t'} ∈ 𝓝 x ⊓ 𝓟 (range m),
from @mem_inf_sets_of_left α (𝓝 x) (𝓟 (range m)) _ $ mem_nhds_left x ht',
have h₂ : range m ∈ 𝓝 x ⊓ 𝓟 (range m),
from @mem_inf_sets_of_right α (𝓝 x) (𝓟 (range m)) _ $ subset.refl _,
have {y | (x, y) ∈ t'} ∩ range m ∈ 𝓝 x ⊓ 𝓟 (range m),
from @inter_mem_sets α (𝓝 x ⊓ 𝓟 (range m)) _ _ h₁ h₂,
let ⟨y, xyt', b, b_eq⟩ := h₀.nonempty_of_mem this in
⟨b, b_eq.symm ▸ ht'_sub ⟨x, hx, xyt'⟩⟩,
have cauchy g, from
⟨‹ne_bot g›, assume s hs,
let
⟨s₁, hs₁, (comp_s₁ : comp_rel s₁ s₁ ⊆ s)⟩ := comp_mem_uniformity_sets hs,
⟨s₂, hs₂, (comp_s₂ : comp_rel s₂ s₂ ⊆ s₁)⟩ := comp_mem_uniformity_sets hs₁,
⟨t, ht, (prod_t : set.prod t t ⊆ s₂)⟩ := mem_prod_same_iff.mp (hf.right hs₂)
in
have hg₁ : p (preimage prod.swap s₁) t ∈ g,
from mem_lift (symm_le_uniformity hs₁) $ @mem_lift' α α f _ t ht,
have hg₂ : p s₂ t ∈ g,
from mem_lift hs₂ $ @mem_lift' α α f _ t ht,
have hg : set.prod (p (preimage prod.swap s₁) t) (p s₂ t) ∈ filter.prod g g,
from @prod_mem_prod α α _ _ g g hg₁ hg₂,
(filter.prod g g).sets_of_superset hg
(assume ⟨a, b⟩ ⟨⟨c₁, c₁t, hc₁⟩, ⟨c₂, c₂t, hc₂⟩⟩,
have (c₁, c₂) ∈ set.prod t t, from ⟨c₁t, c₂t⟩,
comp_s₁ $ prod_mk_mem_comp_rel hc₁ $
comp_s₂ $ prod_mk_mem_comp_rel (prod_t this) hc₂)⟩,
have cauchy (filter.comap m g),
from ‹cauchy g›.comap' (le_of_eq hm.comap_uniformity) ‹_›,
let ⟨x, (hx : map m (filter.comap m g) ≤ 𝓝 x)⟩ := h _ this in
have cluster_pt x (map m (filter.comap m g)),
from (le_nhds_iff_adhp_of_cauchy (this.map hm.uniform_continuous)).mp hx,
have cluster_pt x g,
from this.mono map_comap_le,
⟨x, calc f ≤ g : by assumption
... ≤ 𝓝 x : le_nhds_of_cauchy_adhp ‹cauchy g› this⟩⟩
lemma totally_bounded_preimage {f : α → β} {s : set β} (hf : uniform_embedding f)
(hs : totally_bounded s) : totally_bounded (f ⁻¹' s) :=
λ t ht, begin
rw ← hf.comap_uniformity at ht,
rcases mem_comap_sets.2 ht with ⟨t', ht', ts⟩,
rcases totally_bounded_iff_subset.1
(totally_bounded_subset (image_preimage_subset f s) hs) _ ht' with ⟨c, cs, hfc, hct⟩,
refine ⟨f ⁻¹' c, hfc.preimage (hf.inj.inj_on _), λ x h, _⟩,
have := hct (mem_image_of_mem f h), simp at this ⊢,
rcases this with ⟨z, zc, zt⟩,
rcases cs zc with ⟨y, yc, rfl⟩,
exact ⟨y, zc, ts (by exact zt)⟩
end
end
lemma uniform_embedding_comap {α : Type*} {β : Type*} {f : α → β} [u : uniform_space β]
(hf : function.injective f) : @uniform_embedding α β (uniform_space.comap f u) u f :=
@uniform_embedding.mk _ _ (uniform_space.comap f u) _ _
(@uniform_inducing.mk _ _ (uniform_space.comap f u) _ _ rfl) hf
section uniform_extension
variables {α : Type*} {β : Type*} {γ : Type*}
[uniform_space α] [uniform_space β] [uniform_space γ]
{e : β → α}
(h_e : uniform_inducing e)
(h_dense : dense_range e)
{f : β → γ}
(h_f : uniform_continuous f)
local notation `ψ` := (h_e.dense_inducing h_dense).extend f
lemma uniformly_extend_exists [complete_space γ] (a : α) :
∃c, tendsto f (comap e (𝓝 a)) (𝓝 c) :=
let de := (h_e.dense_inducing h_dense) in
have cauchy (𝓝 a), from cauchy_nhds,
have cauchy (comap e (𝓝 a)), from
this.comap' (le_of_eq h_e.comap_uniformity) (de.comap_nhds_ne_bot _),
have cauchy (map f (comap e (𝓝 a))), from this.map h_f,
complete_space.complete this
lemma uniform_extend_subtype [complete_space γ]
{p : α → Prop} {e : α → β} {f : α → γ} {b : β} {s : set α}
(hf : uniform_continuous (λx:subtype p, f x.val))
(he : uniform_embedding e) (hd : ∀x:β, x ∈ closure (range e))
(hb : closure (e '' s) ∈ 𝓝 b) (hs : is_closed s) (hp : ∀x∈s, p x) :
∃c, tendsto f (comap e (𝓝 b)) (𝓝 c) :=
have de : dense_embedding e,
from he.dense_embedding hd,
have de' : dense_embedding (dense_embedding.subtype_emb p e),
by exact de.subtype p,
have ue' : uniform_embedding (dense_embedding.subtype_emb p e),
from uniform_embedding_subtype_emb _ he de,
have b ∈ closure (e '' {x | p x}),
from (closure_mono $ monotone_image $ hp) (mem_of_nhds hb),
let ⟨c, (hc : tendsto (f ∘ subtype.val) (comap (dense_embedding.subtype_emb p e) (𝓝 ⟨b, this⟩)) (𝓝 c))⟩ :=
uniformly_extend_exists ue'.to_uniform_inducing de'.dense hf _ in
begin
rw [nhds_subtype_eq_comap] at hc,
simp [comap_comap] at hc,
change (tendsto (f ∘ @subtype.val α p) (comap (e ∘ @subtype.val α p) (𝓝 b)) (𝓝 c)) at hc,
rw [←comap_comap, tendsto_comap'_iff] at hc,
exact ⟨c, hc⟩,
exact ⟨_, hb, assume x,
begin
change e x ∈ (closure (e '' s)) → x ∈ range subtype.val,
rw [←closure_induced, mem_closure_iff_cluster_pt, cluster_pt, ne_bot,
(≠), nhds_induced, ← de.to_dense_inducing.nhds_eq_comap],
change x ∈ {y | cluster_pt y (𝓟 s)} → x ∈ range subtype.val,
rw [←closure_eq_cluster_pts, hs.closure_eq],
exact assume hxs, ⟨⟨x, hp x hxs⟩, rfl⟩,
exact de.inj
end⟩
end
variables [separated_space γ]
lemma uniformly_extend_of_ind (b : β) : ψ (e b) = f b :=
dense_inducing.extend_eq_at _ b h_f.continuous.continuous_at
lemma uniformly_extend_unique {g : α → γ} (hg : ∀ b, g (e b) = f b)
(hc : continuous g) :
ψ = g :=
dense_inducing.extend_unique _ hg hc
include h_f
lemma uniformly_extend_spec [complete_space γ] (a : α) :
tendsto f (comap e (𝓝 a)) (𝓝 (ψ a)) :=
let de := (h_e.dense_inducing h_dense) in
begin
by_cases ha : a ∈ range e,
{ rcases ha with ⟨b, rfl⟩,
rw [uniformly_extend_of_ind _ _ h_f, ← de.nhds_eq_comap],
exact h_f.continuous.tendsto _ },
{ simp only [dense_inducing.extend, dif_neg ha],
exact lim_spec (uniformly_extend_exists h_e h_dense h_f _) }
end
lemma uniform_continuous_uniformly_extend [cγ : complete_space γ] : uniform_continuous ψ :=
assume d hd,
let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $
monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp (comp_le_uniformity3 hd) in
have h_pnt : ∀{a m}, m ∈ 𝓝 a → ∃c, c ∈ f '' preimage e m ∧ (c, ψ a) ∈ s ∧ (ψ a, c) ∈ s,
from assume a m hm,
have nb : ne_bot (map f (comap e (𝓝 a))),
from ((h_e.dense_inducing h_dense).comap_nhds_ne_bot _).map _,
have (f '' preimage e m) ∩ ({c | (c, ψ a) ∈ s } ∩ {c | (ψ a, c) ∈ s }) ∈ map f (comap e (𝓝 a)),
from inter_mem_sets (image_mem_map $ preimage_mem_comap $ hm)
(uniformly_extend_spec h_e h_dense h_f _ (inter_mem_sets (mem_nhds_right _ hs) (mem_nhds_left _ hs))),
nb.nonempty_of_mem this,
have preimage (λp:β×β, (f p.1, f p.2)) s ∈ 𝓤 β,
from h_f hs,
have preimage (λp:β×β, (f p.1, f p.2)) s ∈ comap (λx:β×β, (e x.1, e x.2)) (𝓤 α),
by rwa [h_e.comap_uniformity.symm] at this,
let ⟨t, ht, ts⟩ := this in
show preimage (λp:(α×α), (ψ p.1, ψ p.2)) d ∈ 𝓤 α,
from (𝓤 α).sets_of_superset (interior_mem_uniformity ht) $
assume ⟨x₁, x₂⟩ hx_t,
have 𝓝 (x₁, x₂) ≤ 𝓟 (interior t),
from is_open_iff_nhds.mp is_open_interior (x₁, x₂) hx_t,
have interior t ∈ filter.prod (𝓝 x₁) (𝓝 x₂),
by rwa [nhds_prod_eq, le_principal_iff] at this,
let ⟨m₁, hm₁, m₂, hm₂, (hm : set.prod m₁ m₂ ⊆ interior t)⟩ := mem_prod_iff.mp this in
let ⟨a, ha₁, _, ha₂⟩ := h_pnt hm₁ in
let ⟨b, hb₁, hb₂, _⟩ := h_pnt hm₂ in
have set.prod (preimage e m₁) (preimage e m₂) ⊆ preimage (λp:(β×β), (f p.1, f p.2)) s,
from calc _ ⊆ preimage (λp:(β×β), (e p.1, e p.2)) (interior t) : preimage_mono hm
... ⊆ preimage (λp:(β×β), (e p.1, e p.2)) t : preimage_mono interior_subset
... ⊆ preimage (λp:(β×β), (f p.1, f p.2)) s : ts,
have set.prod (f '' preimage e m₁) (f '' preimage e m₂) ⊆ s,
from calc set.prod (f '' preimage e m₁) (f '' preimage e m₂) =
(λp:(β×β), (f p.1, f p.2)) '' (set.prod (preimage e m₁) (preimage e m₂)) : prod_image_image_eq
... ⊆ (λp:(β×β), (f p.1, f p.2)) '' preimage (λp:(β×β), (f p.1, f p.2)) s : monotone_image this
... ⊆ s : image_subset_iff.mpr $ subset.refl _,
have (a, b) ∈ s, from @this (a, b) ⟨ha₁, hb₁⟩,
hs_comp $ show (ψ x₁, ψ x₂) ∈ comp_rel s (comp_rel s s),
from ⟨a, ha₂, ⟨b, this, hb₂⟩⟩
end uniform_extension
|
f715bd9ec015ff271c4d3c8aca13f29c54638069 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/field_theory/fixed.lean | a240704dcdfc723145236896f3c267b3ab5ad096 | [
"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 | 14,456 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.polynomial.group_ring_action
import field_theory.normal
import field_theory.separable
import field_theory.tower
import ring_theory.polynomial
/-!
# Fixed field under a group action.
This is the basis of the Fundamental Theorem of Galois Theory.
Given a (finite) group `G` that acts on a field `F`, we define `fixed_points G F`,
the subfield consisting of elements of `F` fixed_points by every element of `G`.
This subfield is then normal and separable, and in addition (TODO) if `G` acts faithfully on `F`
then `finrank (fixed_points G F) F = fintype.card G`.
## Main Definitions
- `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of
`G`, where `G` is a group that acts on `F`.
-/
noncomputable theory
open_locale classical big_operators
open mul_action finset finite_dimensional
universes u v w
variables {M : Type u} [monoid M]
variables (G : Type u) [group G]
variables (F : Type v) [field F] [mul_semiring_action M F] [mul_semiring_action G F] (m : M)
/-- The subfield of F fixed by the field endomorphism `m`. -/
def fixed_by.subfield : subfield F :=
{ carrier := fixed_by M F m,
zero_mem' := smul_zero m,
add_mem' := λ x y hx hy, (smul_add m x y).trans $ congr_arg2 _ hx hy,
neg_mem' := λ x hx, (smul_neg m x).trans $ congr_arg _ hx,
one_mem' := smul_one m,
mul_mem' := λ x y hx hy, (smul_mul' m x y).trans $ congr_arg2 _ hx hy,
inv_mem' := λ x hx, (smul_inv'' m x).trans $ congr_arg _ hx }
section invariant_subfields
variables (M) {F}
/-- A typeclass for subrings invariant under a `mul_semiring_action`. -/
class is_invariant_subfield (S : subfield F) : Prop :=
(smul_mem : ∀ (m : M) {x : F}, x ∈ S → m • x ∈ S)
variable (S : subfield F)
instance is_invariant_subfield.to_mul_semiring_action [is_invariant_subfield M S] :
mul_semiring_action M S :=
{ smul := λ m x, ⟨m • x, is_invariant_subfield.smul_mem m x.2⟩,
one_smul := λ s, subtype.eq $ one_smul M s,
mul_smul := λ m₁ m₂ s, subtype.eq $ mul_smul m₁ m₂ s,
smul_add := λ m s₁ s₂, subtype.eq $ smul_add m s₁ s₂,
smul_zero := λ m, subtype.eq $ smul_zero m,
smul_one := λ m, subtype.eq $ smul_one m,
smul_mul := λ m s₁ s₂, subtype.eq $ smul_mul' m s₁ s₂ }
instance [is_invariant_subfield M S] : is_invariant_subring M (S.to_subring) :=
{ smul_mem := is_invariant_subfield.smul_mem }
end invariant_subfields
namespace fixed_points
variable (M)
-- we use `subfield.copy` so that the underlying set is `fixed_points M F`
/-- The subfield of fixed points by a monoid action. -/
def subfield : subfield F :=
subfield.copy (⨅ (m : M), fixed_by.subfield F m) (fixed_points M F)
(by { ext z, simp [fixed_points, fixed_by.subfield, infi, subfield.mem_Inf] })
instance : is_invariant_subfield M (fixed_points.subfield M F) :=
{ smul_mem := λ g x hx g', by rw [hx, hx] }
instance : smul_comm_class M (fixed_points.subfield M F) F :=
{ smul_comm := λ m f f', show m • (↑f * f') = f * (m • f'), by rw [smul_mul', f.prop m] }
instance smul_comm_class' : smul_comm_class (fixed_points.subfield M F) M F :=
smul_comm_class.symm _ _ _
@[simp] theorem smul (m : M) (x : fixed_points.subfield M F) : m • x = x :=
subtype.eq $ x.2 m
-- Why is this so slow?
@[simp] theorem smul_polynomial (m : M) (p : polynomial (fixed_points.subfield M F)) : m • p = p :=
polynomial.induction_on p
(λ x, by rw [polynomial.smul_C, smul])
(λ p q ihp ihq, by rw [smul_add, ihp, ihq])
(λ n x ih, by rw [smul_mul', polynomial.smul_C, smul, smul_pow', polynomial.smul_X])
instance : algebra (fixed_points.subfield M F) F :=
algebra.of_subring (fixed_points.subfield M F).to_subring
theorem coe_algebra_map :
algebra_map (fixed_points.subfield M F) F = subfield.subtype (fixed_points.subfield M F) :=
rfl
lemma linear_independent_smul_of_linear_independent {s : finset F} :
linear_independent (fixed_points.subfield G F) (λ i : (s : set F), (i : F)) →
linear_independent F (λ i : (s : set F), mul_action.to_fun G F i) :=
begin
haveI : is_empty ((∅ : finset F) : set F) := ⟨subtype.prop⟩,
refine finset.induction_on s (λ _, linear_independent_empty_type)
(λ a s has ih hs, _),
rw coe_insert at hs ⊢,
rw linear_independent_insert (mt mem_coe.1 has) at hs,
rw linear_independent_insert' (mt mem_coe.1 has), refine ⟨ih hs.1, λ ha, _⟩,
rw finsupp.mem_span_image_iff_total at ha, rcases ha with ⟨l, hl, hla⟩,
rw [finsupp.total_apply_of_mem_supported F hl] at hla,
suffices : ∀ i ∈ s, l i ∈ fixed_points.subfield G F,
{ replace hla := (sum_apply _ _ (λ i, l i • to_fun G F i)).symm.trans (congr_fun hla 1),
simp_rw [pi.smul_apply, to_fun_apply, one_smul] at hla,
refine hs.2 (hla ▸ submodule.sum_mem _ (λ c hcs, _)),
change (⟨l c, this c hcs⟩ : fixed_points.subfield G F) • c ∈ _,
exact submodule.smul_mem _ _ (submodule.subset_span $ mem_coe.2 hcs) },
intros i his g,
refine eq_of_sub_eq_zero (linear_independent_iff'.1 (ih hs.1) s.attach (λ i, g • l i - l i) _
⟨i, his⟩ (mem_attach _ _) : _),
refine (@sum_attach _ _ s _ (λ i, (g • l i - l i) • (to_fun G F) i)).trans _, ext g', dsimp only,
conv_lhs { rw sum_apply, congr, skip, funext, rw [pi.smul_apply, sub_smul, smul_eq_mul] },
rw [sum_sub_distrib, pi.zero_apply, sub_eq_zero],
conv_lhs { congr, skip, funext,
rw [to_fun_apply, ← mul_inv_cancel_left g g', mul_smul, ← smul_mul', ← to_fun_apply _ x] },
show ∑ x in s, g • (λ y, l y • to_fun G F y) x (g⁻¹ * g') =
∑ x in s, (λ y, l y • to_fun G F y) x g',
rw [← smul_sum, ← sum_apply _ _ (λ y, l y • to_fun G F y),
← sum_apply _ _ (λ y, l y • to_fun G F y)], dsimp only,
rw [hla, to_fun_apply, to_fun_apply, smul_smul, mul_inv_cancel_left]
end
variables [fintype G] (x : F)
/-- `minpoly G F x` is the minimal polynomial of `(x : F)` over `fixed_points G F`. -/
def minpoly : polynomial (fixed_points.subfield G F) :=
(prod_X_sub_smul G F x).to_subring (fixed_points.subfield G F).to_subring $ λ c hc g,
let ⟨n, hc0, hn⟩ := polynomial.mem_frange_iff.1 hc in hn.symm ▸ prod_X_sub_smul.coeff G F x g n
namespace minpoly
theorem monic : (minpoly G F x).monic :=
by { simp only [minpoly, polynomial.monic_to_subring], exact prod_X_sub_smul.monic G F x }
theorem eval₂ : polynomial.eval₂ (subring.subtype $ (fixed_points.subfield G F).to_subring) x
(minpoly G F x) = 0 :=
begin
rw [← prod_X_sub_smul.eval G F x, polynomial.eval₂_eq_eval_map],
simp only [minpoly, polynomial.map_to_subring],
end
theorem eval₂' :
polynomial.eval₂ (subfield.subtype $ (fixed_points.subfield G F)) x (minpoly G F x) = 0 :=
eval₂ G F x
theorem ne_one :
minpoly G F x ≠ (1 : polynomial (fixed_points.subfield G F)) :=
λ H, have _ := eval₂ G F x,
(one_ne_zero : (1 : F) ≠ 0) $ by rwa [H, polynomial.eval₂_one] at this
theorem of_eval₂ (f : polynomial (fixed_points.subfield G F))
(hf : polynomial.eval₂ (subfield.subtype $ fixed_points.subfield G F) x f = 0) :
minpoly G F x ∣ f :=
begin
erw [← polynomial.map_dvd_map' (subfield.subtype $ fixed_points.subfield G F),
minpoly, polynomial.map_to_subring _ (subfield G F).to_subring, prod_X_sub_smul],
refine fintype.prod_dvd_of_coprime
(polynomial.pairwise_coprime_X_sub $ mul_action.injective_of_quotient_stabilizer G x)
(λ y, quotient_group.induction_on y $ λ g, _),
rw [polynomial.dvd_iff_is_root, polynomial.is_root.def, mul_action.of_quotient_stabilizer_mk,
polynomial.eval_smul',
← subfield.to_subring.subtype_eq_subtype,
← is_invariant_subring.coe_subtype_hom' G (fixed_points.subfield G F).to_subring,
← mul_semiring_action_hom.coe_polynomial, ← mul_semiring_action_hom.map_smul,
smul_polynomial, mul_semiring_action_hom.coe_polynomial,
is_invariant_subring.coe_subtype_hom', polynomial.eval_map,
subfield.to_subring.subtype_eq_subtype, hf, smul_zero]
end
/- Why is this so slow? -/
theorem irreducible_aux (f g : polynomial (fixed_points.subfield G F))
(hf : f.monic) (hg : g.monic) (hfg : f * g = minpoly G F x) :
f = 1 ∨ g = 1 :=
begin
have hf2 : f ∣ minpoly G F x,
{ rw ← hfg, exact dvd_mul_right _ _ },
have hg2 : g ∣ minpoly G F x,
{ rw ← hfg, exact dvd_mul_left _ _ },
have := eval₂ G F x,
rw [← hfg, polynomial.eval₂_mul, mul_eq_zero] at this,
cases this,
{ right,
have hf3 : f = minpoly G F x,
{ exact polynomial.eq_of_monic_of_associated hf (monic G F x)
(associated_of_dvd_dvd hf2 $ @of_eval₂ G _ F _ _ _ x f this) },
rwa [← mul_one (minpoly G F x), hf3,
mul_right_inj' (monic G F x).ne_zero] at hfg },
{ left,
have hg3 : g = minpoly G F x,
{ exact polynomial.eq_of_monic_of_associated hg (monic G F x)
(associated_of_dvd_dvd hg2 $ @of_eval₂ G _ F _ _ _ x g this) },
rwa [← one_mul (minpoly G F x), hg3,
mul_left_inj' (monic G F x).ne_zero] at hfg }
end
theorem irreducible : irreducible (minpoly G F x) :=
(polynomial.irreducible_of_monic (monic G F x) (ne_one G F x)).2 (irreducible_aux G F x)
end minpoly
theorem is_integral : is_integral (fixed_points.subfield G F) x :=
⟨minpoly G F x, minpoly.monic G F x, minpoly.eval₂ G F x⟩
theorem minpoly_eq_minpoly :
minpoly G F x = _root_.minpoly (fixed_points.subfield G F) x :=
minpoly.eq_of_irreducible_of_monic (minpoly.irreducible G F x)
(minpoly.eval₂ G F x) (minpoly.monic G F x)
instance normal : normal (fixed_points.subfield G F) F :=
⟨λ x, is_integral G F x, λ x, (polynomial.splits_id_iff_splits _).1 $
by { rw [← minpoly_eq_minpoly, minpoly,
coe_algebra_map, ← subfield.to_subring.subtype_eq_subtype,
polynomial.map_to_subring _ (fixed_points.subfield G F).to_subring, prod_X_sub_smul],
exact polynomial.splits_prod _ (λ _ _, polynomial.splits_X_sub_C _) }⟩
instance separable : is_separable (fixed_points.subfield G F) F :=
⟨λ x, is_integral G F x,
λ x, by {
-- this was a plain rw when we were using unbundled subrings
erw [← minpoly_eq_minpoly,
← polynomial.separable_map (fixed_points.subfield G F).subtype,
minpoly, polynomial.map_to_subring _ ((subfield G F).to_subring) ],
exact polynomial.separable_prod_X_sub_C_iff.2 (injective_of_quotient_stabilizer G x) }⟩
lemma dim_le_card : module.rank (fixed_points.subfield G F) F ≤ fintype.card G :=
dim_le $ λ s hs, by simpa only [dim_fun', cardinal.mk_finset, finset.coe_sort_coe,
cardinal.lift_nat_cast, cardinal.nat_cast_le]
using cardinal_lift_le_dim_of_linear_independent'
(linear_independent_smul_of_linear_independent G F hs)
instance : finite_dimensional (fixed_points.subfield G F) F :=
is_noetherian.iff_fg.1 $ is_noetherian.iff_dim_lt_omega.2 $
lt_of_le_of_lt (dim_le_card G F) (cardinal.nat_lt_omega _)
lemma finrank_le_card : finrank (fixed_points.subfield G F) F ≤ fintype.card G :=
begin
rw [← cardinal.nat_cast_le, finrank_eq_dim],
apply dim_le_card,
end
end fixed_points
lemma linear_independent_to_linear_map (R : Type u) (A : Type v) (B : Type w)
[comm_semiring R] [ring A] [algebra R A]
[comm_ring B] [is_domain B] [algebra R B] :
linear_independent B (alg_hom.to_linear_map : (A →ₐ[R] B) → (A →ₗ[R] B)) :=
have linear_independent B (linear_map.lto_fun R A B ∘ alg_hom.to_linear_map),
from ((linear_independent_monoid_hom A B).comp
(coe : (A →ₐ[R] B) → (A →* B))
(λ f g hfg, alg_hom.ext $ monoid_hom.ext_iff.1 hfg) : _),
this.of_comp _
lemma cardinal_mk_alg_hom (K : Type u) (V : Type v) (W : Type w)
[field K] [field V] [algebra K V] [finite_dimensional K V]
[field W] [algebra K W] [finite_dimensional K W] :
cardinal.mk (V →ₐ[K] W) ≤ finrank W (V →ₗ[K] W) :=
cardinal_mk_le_finrank_of_linear_independent $ linear_independent_to_linear_map K V W
noncomputable instance alg_hom.fintype (K : Type u) (V : Type v) (W : Type w)
[field K] [field V] [algebra K V] [finite_dimensional K V]
[field W] [algebra K W] [finite_dimensional K W] :
fintype (V →ₐ[K] W) :=
classical.choice $ cardinal.lt_omega_iff_fintype.1 $
lt_of_le_of_lt (cardinal_mk_alg_hom K V W) (cardinal.nat_lt_omega _)
noncomputable instance alg_equiv.fintype (K : Type u) (V : Type v)
[field K] [field V] [algebra K V] [finite_dimensional K V] :
fintype (V ≃ₐ[K] V) :=
fintype.of_equiv (V →ₐ[K] V) (alg_equiv_equiv_alg_hom K V).symm
lemma finrank_alg_hom (K : Type u) (V : Type v)
[field K] [field V] [algebra K V] [finite_dimensional K V] :
fintype.card (V →ₐ[K] V) ≤ finrank V (V →ₗ[K] V) :=
fintype_card_le_finrank_of_linear_independent $ linear_independent_to_linear_map K V V
namespace fixed_points
theorem finrank_eq_card (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [mul_semiring_action G F] [has_faithful_scalar G F] :
finrank (fixed_points.subfield G F) F = fintype.card G :=
le_antisymm (fixed_points.finrank_le_card G F) $
calc fintype.card G
≤ fintype.card (F →ₐ[fixed_points.subfield G F] F) :
fintype.card_le_of_injective _ (mul_semiring_action.to_alg_hom_injective _ F)
... ≤ finrank F (F →ₗ[fixed_points.subfield G F] F) : finrank_alg_hom (fixed_points G F) F
... = finrank (fixed_points.subfield G F) F : finrank_linear_map' _ _ _
/-- `mul_semiring_action.to_alg_hom` is bijective. -/
theorem to_alg_hom_bijective (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [mul_semiring_action G F] [has_faithful_scalar G F] :
function.bijective (mul_semiring_action.to_alg_hom _ _ : G → F →ₐ[subfield G F] F) :=
begin
rw fintype.bijective_iff_injective_and_card,
split,
{ exact mul_semiring_action.to_alg_hom_injective _ F },
{ apply le_antisymm,
{ exact fintype.card_le_of_injective _ (mul_semiring_action.to_alg_hom_injective _ F) },
{ rw ← finrank_eq_card G F,
exact has_le.le.trans_eq (finrank_alg_hom _ F) (finrank_linear_map' _ _ _) } },
end
/-- Bijection between G and algebra homomorphisms that fix the fixed points -/
def to_alg_hom_equiv (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [mul_semiring_action G F] [has_faithful_scalar G F] :
G ≃ (F →ₐ[fixed_points.subfield G F] F) :=
equiv.of_bijective _ (to_alg_hom_bijective G F)
end fixed_points
|
dcdca2b9235408bf0ad812655c1d739dad60c182 | b70447c014d9e71cf619ebc9f539b262c19c2e0b | /hott/init/pathover.hlean | 95c1a22c0c2ad9d1feb1deaa1a50be8ea1e21be6 | [
"Apache-2.0"
] | permissive | ia0/lean2 | c20d8da69657f94b1d161f9590a4c635f8dc87f3 | d86284da630acb78fa5dc3b0b106153c50ffccd0 | refs/heads/master | 1,611,399,322,751 | 1,495,751,007,000 | 1,495,751,007,000 | 93,104,167 | 0 | 0 | null | 1,496,355,488,000 | 1,496,355,487,000 | null | UTF-8 | Lean | false | false | 18,621 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Basic theorems about pathovers
-/
prelude
import .path .equiv
open equiv is_equiv function
variables {A A' : Type} {B B' : A → Type} {B'' : A' → Type} {C : Π⦃a⦄, B a → Type}
{a a₂ a₃ a₄ : A} {p p' : a = a₂} {p₂ : a₂ = a₃} {p₃ : a₃ = a₄} {p₁₃ : a = a₃}
{b b' : B a} {b₂ b₂' : B a₂} {b₃ : B a₃} {b₄ : B a₄}
{c : C b} {c₂ : C b₂}
namespace eq
inductive pathover.{l} (B : A → Type.{l}) (b : B a) : Π{a₂ : A}, a = a₂ → B a₂ → Type.{l} :=
idpatho : pathover B b (refl a) b
notation b ` =[`:50 p:0 `] `:0 b₂:50 := pathover _ b p b₂
definition idpo [reducible] [constructor] : b =[refl a] b :=
pathover.idpatho b
definition idpatho [reducible] [constructor] (b : B a) : b =[refl a] b :=
pathover.idpatho b
/- equivalences with equality using transport -/
definition pathover_of_tr_eq [unfold 5 8] (r : p ▸ b = b₂) : b =[p] b₂ :=
by cases p; cases r; constructor
definition pathover_of_eq_tr [unfold 5 8] (r : b = p⁻¹ ▸ b₂) : b =[p] b₂ :=
by cases p; cases r; constructor
definition tr_eq_of_pathover [unfold 8] (r : b =[p] b₂) : p ▸ b = b₂ :=
by cases r; reflexivity
definition eq_tr_of_pathover [unfold 8] (r : b =[p] b₂) : b = p⁻¹ ▸ b₂ :=
by cases r; reflexivity
definition pathover_equiv_tr_eq [constructor] (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (p ▸ b = b₂) :=
begin
fapply equiv.MK,
{ exact tr_eq_of_pathover},
{ exact pathover_of_tr_eq},
{ intro r, cases p, cases r, apply idp},
{ intro r, cases r, apply idp},
end
definition pathover_equiv_eq_tr [constructor] (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (b = p⁻¹ ▸ b₂) :=
begin
fapply equiv.MK,
{ exact eq_tr_of_pathover},
{ exact pathover_of_eq_tr},
{ intro r, cases p, cases r, apply idp},
{ intro r, cases r, apply idp},
end
definition pathover_tr [unfold 5] (p : a = a₂) (b : B a) : b =[p] p ▸ b :=
by cases p; constructor
definition tr_pathover [unfold 5] (p : a = a₂) (b : B a₂) : p⁻¹ ▸ b =[p] b :=
by cases p; constructor
definition concato [unfold 12] (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) : b =[p ⬝ p₂] b₃ :=
by induction r₂; exact r
definition inverseo [unfold 8] (r : b =[p] b₂) : b₂ =[p⁻¹] b :=
by induction r; constructor
definition concato_eq [unfold 10] (r : b =[p] b₂) (q : b₂ = b₂') : b =[p] b₂' :=
by induction q; exact r
definition eq_concato [unfold 9] (q : b = b') (r : b' =[p] b₂) : b =[p] b₂ :=
by induction q; exact r
definition change_path [unfold 9] (q : p = p') (r : b =[p] b₂) : b =[p'] b₂ :=
q ▸ r
-- infix ` ⬝ ` := concato
infix ` ⬝o `:72 := concato
infix ` ⬝op `:73 := concato_eq
infix ` ⬝po `:74 := eq_concato
-- postfix `⁻¹` := inverseo
postfix `⁻¹ᵒ`:(max+10) := inverseo
definition pathover_cancel_right (q : b =[p ⬝ p₂] b₃) (r : b₃ =[p₂⁻¹] b₂) : b =[p] b₂ :=
change_path !con_inv_cancel_right (q ⬝o r)
definition pathover_cancel_right' (q : b =[p₁₃ ⬝ p₂⁻¹] b₂) (r : b₂ =[p₂] b₃) : b =[p₁₃] b₃ :=
change_path !inv_con_cancel_right (q ⬝o r)
definition pathover_cancel_left (q : b₂ =[p⁻¹] b) (r : b =[p ⬝ p₂] b₃) : b₂ =[p₂] b₃ :=
change_path !inv_con_cancel_left (q ⬝o r)
definition pathover_cancel_left' (q : b =[p] b₂) (r : b₂ =[p⁻¹ ⬝ p₁₃] b₃) : b =[p₁₃] b₃ :=
change_path !con_inv_cancel_left (q ⬝o r)
/- Some of the theorems analogous to theorems for = in init.path -/
definition cono_idpo (r : b =[p] b₂) : r ⬝o idpo =[con_idp p] r :=
pathover.rec_on r idpo
definition idpo_cono (r : b =[p] b₂) : idpo ⬝o r =[idp_con p] r :=
pathover.rec_on r idpo
definition cono.assoc' (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
r ⬝o (r₂ ⬝o r₃) =[!con.assoc'] (r ⬝o r₂) ⬝o r₃ :=
pathover.rec_on r₃ (pathover.rec_on r₂ (pathover.rec_on r idpo))
definition cono.assoc (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
(r ⬝o r₂) ⬝o r₃ =[!con.assoc] r ⬝o (r₂ ⬝o r₃) :=
pathover.rec_on r₃ (pathover.rec_on r₂ (pathover.rec_on r idpo))
definition cono.right_inv (r : b =[p] b₂) : r ⬝o r⁻¹ᵒ =[!con.right_inv] idpo :=
pathover.rec_on r idpo
definition cono.left_inv (r : b =[p] b₂) : r⁻¹ᵒ ⬝o r =[!con.left_inv] idpo :=
pathover.rec_on r idpo
definition eq_of_pathover {a' a₂' : A'} (q : a' =[p] a₂') : a' = a₂' :=
by cases q;reflexivity
definition pathover_of_eq [unfold 5 8] (p : a = a₂) {a' a₂' : A'} (q : a' = a₂') : a' =[p] a₂' :=
by cases p;cases q;constructor
definition pathover_constant [constructor] (p : a = a₂) (a' a₂' : A') : a' =[p] a₂' ≃ a' = a₂' :=
begin
fapply equiv.MK,
{ exact eq_of_pathover},
{ exact pathover_of_eq p},
{ intro r, cases p, cases r, reflexivity},
{ intro r, cases r, reflexivity},
end
definition pathover_of_eq_tr_constant_inv (p : a = a₂) (a' : A')
: pathover_of_eq p (tr_constant p a')⁻¹ = pathover_tr p a' :=
by cases p; constructor
definition eq_of_pathover_idp [unfold 6] {b' : B a} (q : b =[idpath a] b') : b = b' :=
tr_eq_of_pathover q
--should B be explicit in the next two definitions?
definition pathover_idp_of_eq [unfold 6] {b' : B a} (q : b = b') : b =[idpath a] b' :=
pathover_of_tr_eq q
definition pathover_idp [constructor] (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
equiv.MK eq_of_pathover_idp
(pathover_idp_of_eq)
(to_right_inv !pathover_equiv_tr_eq)
(to_left_inv !pathover_equiv_tr_eq)
definition eq_of_pathover_idp_pathover_of_eq {A X : Type} (x : X) {a a' : A} (p : a = a') :
eq_of_pathover_idp (pathover_of_eq (idpath x) p) = p :=
by induction p; reflexivity
-- definition pathover_idp (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
-- pathover_equiv_tr_eq idp b b'
-- definition eq_of_pathover_idp [reducible] {b' : B a} (q : b =[idpath a] b') : b = b' :=
-- to_fun !pathover_idp q
-- definition pathover_idp_of_eq [reducible] {b' : B a} (q : b = b') : b =[idpath a] b' :=
-- to_inv !pathover_idp q
definition idp_rec_on [recursor] [unfold 7] {P : Π⦃b₂ : B a⦄, b =[idpath a] b₂ → Type}
{b₂ : B a} (r : b =[idpath a] b₂) (H : P idpo) : P r :=
have H2 : P (pathover_idp_of_eq (eq_of_pathover_idp r)), from
eq.rec_on (eq_of_pathover_idp r) H,
proof left_inv !pathover_idp r ▸ H2 qed
definition rec_on_right [recursor] {P : Π⦃b₂ : B a₂⦄, b =[p] b₂ → Type}
{b₂ : B a₂} (r : b =[p] b₂) (H : P !pathover_tr) : P r :=
by cases r; exact H
definition rec_on_left [recursor] {P : Π⦃b : B a⦄, b =[p] b₂ → Type}
{b : B a} (r : b =[p] b₂) (H : P !tr_pathover) : P r :=
by cases r; exact H
--pathover with fibration B' ∘ f
definition pathover_ap [unfold 10] (B' : A' → Type) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p] b₂) : b =[ap f p] b₂ :=
by cases q; constructor
definition pathover_of_pathover_ap (B' : A' → Type) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[ap f p] b₂) : b =[p] b₂ :=
by cases p; apply (idp_rec_on q); apply idpo
definition pathover_compose [constructor] (B' : A' → Type) (f : A → A') (p : a = a₂)
(b : B' (f a)) (b₂ : B' (f a₂)) : b =[p] b₂ ≃ b =[ap f p] b₂ :=
begin
fapply equiv.MK,
{ exact pathover_ap B' f},
{ exact pathover_of_pathover_ap B' f},
{ intro q, cases p, esimp, apply (idp_rec_on q), apply idp},
{ intro q, cases q, reflexivity},
end
definition pathover_of_pathover_tr (q : b =[p ⬝ p₂] p₂ ▸ b₂) : b =[p] b₂ :=
pathover_cancel_right q !pathover_tr⁻¹ᵒ
definition pathover_tr_of_pathover (q : b =[p₁₃ ⬝ p₂⁻¹] b₂) : b =[p₁₃] p₂ ▸ b₂ :=
pathover_cancel_right' q !pathover_tr
definition pathover_of_tr_pathover (q : p ▸ b =[p⁻¹ ⬝ p₁₃] b₃) : b =[p₁₃] b₃ :=
pathover_cancel_left' !pathover_tr q
definition tr_pathover_of_pathover (q : b =[p ⬝ p₂] b₃) : p ▸ b =[p₂] b₃ :=
pathover_cancel_left !pathover_tr⁻¹ᵒ q
definition pathover_tr_of_eq (q : b = b') : b =[p] p ▸ b' :=
by cases q;apply pathover_tr
definition tr_pathover_of_eq (q : b₂ = b₂') : p⁻¹ ▸ b₂ =[p] b₂' :=
by cases q;apply tr_pathover
definition eq_of_parallel_po_right (q : b =[p] b₂) (q' : b =[p] b₂') : b₂ = b₂' :=
begin
apply @eq_of_pathover_idp A B, apply change_path (con.left_inv p),
exact q⁻¹ᵒ ⬝o q'
end
definition eq_of_parallel_po_left (q : b =[p] b₂) (q' : b' =[p] b₂) : b = b' :=
begin
apply @eq_of_pathover_idp A B, apply change_path (con.right_inv p),
exact q ⬝o q'⁻¹ᵒ
end
variable (C)
definition transporto (r : b =[p] b₂) (c : C b) : C b₂ :=
by induction r;exact c
infix ` ▸o `:75 := transporto _
definition fn_tro_eq_tro_fn {C' : Π ⦃a : A⦄, B a → Type} (q : b =[p] b₂)
(f : Π⦃a : A⦄ (b : B a), C b → C' b) (c : C b) : f b₂ (q ▸o c) = q ▸o (f b c) :=
by induction q; reflexivity
variable {C}
/- various variants of ap for pathovers -/
definition apd [unfold 6] (f : Πa, B a) (p : a = a₂) : f a =[p] f a₂ :=
by induction p; constructor
definition apo [unfold 12] {f : A → A'} (g : Πa, B a → B'' (f a)) (q : b =[p] b₂) :
g a b =[p] g a₂ b₂ :=
by induction q; constructor
definition apd011 [unfold 10] (f : Πa, B a → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
: f a b = f a₂ b₂ :=
by cases Hb; reflexivity
definition apd0111 [unfold 13 14] (f : Πa b, C b → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
(Hc : c =[apd011 C Ha Hb] c₂) : f a b c = f a₂ b₂ c₂ :=
by cases Hb; apply (idp_rec_on Hc); apply idp
definition apod11 {f : Πb, C b} {g : Πb₂, C b₂} (r : f =[p] g)
{b : B a} {b₂ : B a₂} (q : b =[p] b₂) : f b =[apd011 C p q] g b₂ :=
by cases r; apply (idp_rec_on q); constructor
definition apdo10 {f : Πb, C b} {g : Πb₂, C b₂} (r : f =[p] g)
(b : B a) : f b =[apd011 C p !pathover_tr] g (p ▸ b) :=
by cases r; constructor
definition apo10 [unfold 9] {f : B a → B' a} {g : B a₂ → B' a₂} (r : f =[p] g)
(b : B a) : f b =[p] g (p ▸ b) :=
by cases r; constructor
definition apo10_constant_right [unfold 9] {f : B a → A'} {g : B a₂ → A'} (r : f =[p] g)
(b : B a) : f b = g (p ▸ b) :=
by cases r; constructor
definition apo10_constant_left [unfold 9] {f : A' → B a} {g : A' → B a₂} (r : f =[p] g)
(a' : A') : f a' =[p] g a' :=
by cases r; constructor
definition apo11 {f : B a → B' a} {g : B a₂ → B' a₂} (r : f =[p] g)
(q : b =[p] b₂) : f b =[p] g b₂ :=
by induction q; exact apo10 r b
definition apdo011 {A : Type} {B : A → Type} {C : Π⦃a⦄, B a → Type}
(f : Π⦃a⦄ (b : B a), C b) {a a' : A} (p : a = a') {b : B a} {b' : B a'} (q : b =[p] b')
: f b =[apd011 C p q] f b' :=
by cases q; constructor
definition apdo0111 {A : Type} {B : A → Type} {C C' : Π⦃a⦄, B a → Type}
(f : Π⦃a⦄ {b : B a}, C b → C' b) {a a' : A} (p : a = a') {b : B a} {b' : B a'} (q : b =[p] b')
{c : C b} {c' : C b'} (r : c =[apd011 C p q] c')
: f c =[apd011 C' p q] f c' :=
begin
induction q, esimp at r, induction r using idp_rec_on, constructor
end
definition apo11_constant_right [unfold 12] {f : B a → A'} {g : B a₂ → A'}
(q : f =[p] g) (r : b =[p] b₂) : f b = g b₂ :=
eq_of_pathover (apo11 q r)
/- properties about these "ap"s, transporto and pathover_ap -/
definition apd_con (f : Πa, B a) (p : a = a₂) (q : a₂ = a₃)
: apd f (p ⬝ q) = apd f p ⬝o apd f q :=
by cases p; cases q; reflexivity
definition apd_inv (f : Πa, B a) (p : a = a₂) : apd f p⁻¹ = (apd f p)⁻¹ᵒ :=
by cases p; reflexivity
definition apd_eq_pathover_of_eq_ap (f : A → A') (p : a = a₂) :
apd f p = pathover_of_eq p (ap f p) :=
eq.rec_on p idp
definition apo_invo (f : Πa, B a → B' a) {Ha : a = a₂} (Hb : b =[Ha] b₂)
: (apo f Hb)⁻¹ᵒ = apo f Hb⁻¹ᵒ :=
by induction Hb; reflexivity
definition apd011_inv (f : Πa, B a → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
: (apd011 f Ha Hb)⁻¹ = (apd011 f Ha⁻¹ Hb⁻¹ᵒ) :=
by induction Hb; reflexivity
definition cast_apd011 (q : b =[p] b₂) (c : C b) : cast (apd011 C p q) c = q ▸o c :=
by induction q; reflexivity
definition apd_compose1 (g : Πa, B a → B' a) (f : Πa, B a) (p : a = a₂)
: apd (g ∘' f) p = apo g (apd f p) :=
by induction p; reflexivity
definition apd_compose2 (g : Πa', B'' a') (f : A → A') (p : a = a₂)
: apd (λa, g (f a)) p = pathover_of_pathover_ap B'' f (apd g (ap f p)) :=
by induction p; reflexivity
definition apo_tro (C : Π⦃a⦄, B' a → Type) (f : Π⦃a⦄, B a → B' a) (q : b =[p] b₂)
(c : C (f b)) : apo f q ▸o c = q ▸o c :=
by induction q; reflexivity
definition pathover_ap_tro {B' : A' → Type} (C : Π⦃a'⦄, B' a' → Type) (f : A → A')
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p] b₂) (c : C b) : pathover_ap B' f q ▸o c = q ▸o c :=
by induction q; reflexivity
definition pathover_ap_invo_tro {B' : A' → Type} (C : Π⦃a'⦄, B' a' → Type) (f : A → A')
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p] b₂) (c : C b₂)
: (pathover_ap B' f q)⁻¹ᵒ ▸o c = q⁻¹ᵒ ▸o c :=
by induction q; reflexivity
definition pathover_tro (q : b =[p] b₂) (c : C b) : c =[apd011 C p q] q ▸o c :=
by induction q; constructor
definition pathover_ap_invo {B' : A' → Type} (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p] b₂)
: pathover_ap B' f q⁻¹ᵒ =[ap_inv f p] (pathover_ap B' f q)⁻¹ᵒ :=
by induction q; exact idpo
definition tro_invo_tro {A : Type} {B : A → Type} (C : Π⦃a⦄, B a → Type)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') (c : C b') :
q ▸o (q⁻¹ᵒ ▸o c) = c :=
by induction q; reflexivity
definition invo_tro_tro {A : Type} {B : A → Type} (C : Π⦃a⦄, B a → Type)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') (c : C b) :
q⁻¹ᵒ ▸o (q ▸o c) = c :=
by induction q; reflexivity
definition cono_tro {A : Type} {B : A → Type} (C : Π⦃a⦄, B a → Type)
{a₁ a₂ a₃ : A} {p₁ : a₁ = a₂} {p₂ : a₂ = a₃} {b₁ : B a₁} {b₂ : B a₂} {b₃ : B a₃}
(q₁ : b₁ =[p₁] b₂) (q₂ : b₂ =[p₂] b₃) (c : C b₁) :
transporto C (q₁ ⬝o q₂) c = transporto C q₂ (transporto C q₁ c) :=
by induction q₂; reflexivity
definition is_equiv_transporto [constructor] {A : Type} {B : A → Type} (C : Π⦃a⦄, B a → Type)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') : is_equiv (transporto C q) :=
begin
fapply adjointify,
{ exact transporto C q⁻¹ᵒ},
{ exact tro_invo_tro C q},
{ exact invo_tro_tro C q}
end
definition equiv_apd011 [constructor] {A : Type} {B : A → Type} (C : Π⦃a⦄, B a → Type)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') : C b ≃ C b' :=
equiv.mk (transporto C q) !is_equiv_transporto
/- some cancellation laws for concato_eq an variants -/
definition cono.right_inv_eq (q : b = b') :
pathover_idp_of_eq q ⬝op q⁻¹ = (idpo : b =[refl a] b) :=
by induction q;constructor
definition cono.right_inv_eq' (q : b = b') :
q ⬝po (pathover_idp_of_eq q⁻¹) = (idpo : b =[refl a] b) :=
by induction q;constructor
definition cono.left_inv_eq (q : b = b') :
pathover_idp_of_eq q⁻¹ ⬝op q = (idpo : b' =[refl a] b') :=
by induction q;constructor
definition cono.left_inv_eq' (q : b = b') :
q⁻¹ ⬝po pathover_idp_of_eq q = (idpo : b' =[refl a] b') :=
by induction q;constructor
definition pathover_of_fn_pathover_fn (f : Π{a}, B a ≃ B' a) (r : f b =[p] f b₂) : b =[p] b₂ :=
(left_inv f b)⁻¹ ⬝po apo (λa, f⁻¹ᵉ) r ⬝op left_inv f b₂
/- a pathover in a pathover type where the only thing which varies is the path is the same as
an equality with a change_path -/
definition change_path_of_pathover (s : p = p') (r : b =[p] b₂) (r' : b =[p'] b₂)
(q : r =[s] r') : change_path s r = r' :=
by induction s; eapply idp_rec_on q; reflexivity
definition pathover_of_change_path (s : p = p') (r : b =[p] b₂) (r' : b =[p'] b₂)
(q : change_path s r = r') : r =[s] r' :=
by induction s; induction q; constructor
definition pathover_pathover_path [constructor] (s : p = p') (r : b =[p] b₂) (r' : b =[p'] b₂) :
(r =[s] r') ≃ change_path s r = r' :=
begin
fapply equiv.MK,
{ apply change_path_of_pathover},
{ apply pathover_of_change_path},
{ intro q, induction s, induction q, reflexivity},
{ intro q, induction s, eapply idp_rec_on q, reflexivity},
end
/- variants of inverse2 and concat2 -/
definition inverseo2 [unfold 10] {r r' : b =[p] b₂} (s : r = r') : r⁻¹ᵒ = r'⁻¹ᵒ :=
by induction s; reflexivity
definition concato2 [unfold 15 16] {r r' : b =[p] b₂} {r₂ r₂' : b₂ =[p₂] b₃}
(s : r = r') (s₂ : r₂ = r₂') : r ⬝o r₂ = r' ⬝o r₂' :=
by induction s; induction s₂; reflexivity
infixl ` ◾o `:75 := concato2
postfix [parsing_only] `⁻²ᵒ`:(max+10) := inverseo2 --this notation is abusive, should we use it?
-- find a better name for this
definition fn_tro_eq_tro_fn2 (q : b =[p] b₂)
{k : A → A} {l : Π⦃a⦄, B a → B (k a)} (m : Π⦃a⦄ {b : B a}, C b → C (l b))
(c : C b) :
m (q ▸o c) = (pathover_ap B k (apo l q)) ▸o (m c) :=
by induction q; reflexivity
definition apd0111_precompose (f : Π⦃a⦄ {b : B a}, C b → A')
{k : A → A} {l : Π⦃a⦄, B a → B (k a)} (m : Π⦃a⦄ {b : B a}, C b → C (l b))
{q : b =[p] b₂} (c : C b)
: apd0111 (λa b c, f (m c)) p q (pathover_tro q c) ⬝ ap (@f _ _) (fn_tro_eq_tro_fn2 q m c) =
apd0111 f (ap k p) (pathover_ap B k (apo l q)) (pathover_tro _ (m c)) :=
by induction q; reflexivity
end eq
|
4ea3e29cd7329e97112d85bd0daa3d3b7543680d | d1a52c3f208fa42c41df8278c3d280f075eb020c | /tmp/eqns/elim1.lean | 996c23f5de9b8cc22625dc0e0df42bd1ce94df36 | [
"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,317 | lean | universes u v
inductive Foo (α : Type u)
| leaf (a : α) : Foo
| node (left : Foo) (right : Foo) : Foo
| cons (head : α) (tail : Foo) : Foo
def Foo.elim {α : Type u} (C : Foo α → Foo α → Sort v) (x y : Foo α)
(h₁ : forall (a₁ a₂ : α), C (Foo.leaf a₁) (Foo.leaf a₂))
(h₂ : forall (l₁ r₁ l₂ r₂ : Foo α), C (Foo.node l₁ r₁) (Foo.node l₂ r₂))
(h₃ : forall (h₁ t₁ h₂ t₂), C (Foo.cons h₁ t₁) (Foo.cons h₂ t₂))
(h₄ : forall (x y), C x y)
: C x y :=
Foo.casesOn x
(fun a₁ => Foo.casesOn y
(fun a₂ => h₁ a₁ a₂)
(fun l₂ r₂ => h₄ (Foo.leaf a₁) (Foo.node l₂ r₂))
(fun h₂ t₂ => h₄ (Foo.leaf a₁) (Foo.cons h₂ t₂)))
(fun l₁ r₁ => Foo.casesOn y
(fun a₂ => h₄ (Foo.node l₁ r₁) (Foo.leaf a₂))
(fun l₂ r₂ => h₂ l₁ r₁ l₂ r₂)
(fun h₂ t₂ => h₄ (Foo.node l₁ r₁) (Foo.cons h₂ t₂)))
(fun h₁ t₁ => Foo.casesOn y
(fun a₂ => h₄ (Foo.cons h₁ t₁) (Foo.leaf a₂))
(fun l₂ r₂ => h₄ (Foo.cons h₁ t₁) (Foo.node l₂ r₂))
(fun h₂ t₂ => h₃ h₁ t₁ h₂ t₂))
def f : List Nat → List Nat → List Nat
| x::xs, _ => []
| _, [] => []
| xs, ys => xs ++ ys
def List.elim (C : List Nat → List Nat → Sort v) (xs ys : List Nat)
(h₁ : forall x xs ys, C (x::xs) ys)
(h₂ : forall xs, C xs [])
(h₃ : forall xs ys, C xs ys)
: C xs ys :=
List.casesOn xs
(List.casesOn ys
(h₂ [])
(fun y ys => h₃ [] (y::ys)))
(fun x xs => h₁ x xs ys)
theorem List.elim.eq1 (C : List Nat → List Nat → Sort v)
(h₁ : forall x xs ys, C (x::xs) ys)
(h₂ : forall xs, C xs [])
(h₃ : forall xs ys, C xs ys)
(x : Nat) (xs ys : List Nat)
: List.elim C (x::xs) ys h₁ h₂ h₃ = h₁ x xs ys :=
rfl
theorem List.elim.eq2 (C : List Nat → List Nat → Sort v)
(h₁ : forall x xs ys, C (x::xs) ys)
(h₂ : forall xs, C xs [])
(h₃ : forall xs ys, C xs ys)
(xs : List Nat)
: (forall x' xs', xs = x'::xs' → False) → List.elim C xs [] h₁ h₂ h₃ = h₂ xs :=
List.casesOn xs
(fun _ => rfl)
(fun x xs h => False.elim (h x xs rfl))
theorem List.elim.eq3 (C : List Nat → List Nat → Sort v)
(h₁ : forall x xs ys, C (x::xs) ys)
(h₂ : forall xs, C xs [])
(h₃ : forall xs ys, C xs ys)
(xs : List Nat) (ys : List Nat)
: (forall x' xs', xs = x'::xs' → False) → (ys = [] → False) → List.elim C xs ys h₁ h₂ h₃ = h₃ xs ys :=
List.casesOn xs
(List.casesOn ys
(fun _ h => False.elim (h rfl))
(fun y ys _ _ => rfl))
(fun x xs h _ => False.elim (h x xs rfl))
theorem List.elim.eq3.a (C : List Nat → List Nat → Sort v)
(h₁ : forall x xs ys, C (x::xs) ys)
(h₂ : forall xs, C xs [])
(h₃ : forall xs ys, C xs ys)
(y : Nat) (ys : List Nat)
: List.elim C [] (y::ys) h₁ h₂ h₃ = h₃ [] (y::ys) :=
rfl
def List.elim2 (C : List Nat → List Nat → Sort v) (xs ys : List Nat)
(h₁ : forall x xs ys, C (x::xs) ys)
(h₂ : forall xs, (forall (x' : Nat) (xs' : List Nat), xs = x' :: xs' → False) → C xs [])
(h₃ : forall xs ys, (forall (x' : Nat) (xs' : List Nat), xs = x' :: xs' → False) → (ys = [] → False) → C xs ys)
: C xs ys :=
List.casesOn xs
(List.casesOn ys
(h₂ [] (fun _ _ h => List.noConfusion h))
(fun y ys => h₃ [] (y::ys) (fun _ _ h => List.noConfusion h) (fun h => List.noConfusion h)))
(fun x xs => h₁ x xs ys)
def List.elim3 (C : List Nat → List Nat → List Nat → Sort v) (xs ys zs : List Nat)
(h₁ : forall zs, C [] [] zs)
(h₂ : forall xs ys, C xs ys [])
(h₃ : forall xs ys zs, C xs ys zs)
: C xs ys zs :=
List.casesOn xs
(List.casesOn ys
(h₁ zs)
(fun y ys => List.casesOn zs
(h₃ [] (y::ys) [])
(fun z zs => h₃ [] (y::ys) (z::zs))))
(fun x xs =>
(List.casesOn zs
(h₂ (x::xs) ys)
(fun z zs => h₃ (x::xs) ys (z::zs))))
theorem List.elim3.eq (C : List Nat → List Nat → List Nat → Sort v)
(h₁ : forall zs, C [] [] zs)
(h₂ : forall xs ys, C xs ys [])
(h₃ : forall xs ys zs, C xs ys zs)
(xs ys zs : List Nat)
: (xs = [] → ys = [] → False) → (zs = [] → False) → List.elim3 C xs ys zs h₁ h₂ h₃ = h₃ xs ys zs :=
List.casesOn xs
(List.casesOn ys
(fun h _ => False.elim (h rfl rfl))
(fun y ys => List.casesOn zs
(fun _ h => False.elim (h rfl))
(fun z zs _ _ => rfl)))
(fun x xs =>
List.casesOn zs
(fun _ h => False.elim (h rfl))
(fun z zs _ _ => rfl))
theorem List.elim3.eq.a (C : List Nat → List Nat → List Nat → Sort v)
(h₁ : forall zs, C [] [] zs)
(h₂ : forall xs ys, C xs ys [])
(h₃ : forall xs ys zs, C xs ys zs)
(y : Nat) (ys : List Nat) (z : Nat) (zs : List Nat)
: List.elim3 C [] (y::ys) (z::zs) h₁ h₂ h₃ = h₃ [] (y::ys) (z::zs) :=
rfl
theorem List.elim3.eq.b (C : List Nat → List Nat → List Nat → Sort v)
(h₁ : forall zs, C [] [] zs)
(h₂ : forall xs ys, C xs ys [])
(h₃ : forall xs ys zs, C xs ys zs)
(x : Nat) (xs : List Nat) (y : Nat) (ys : List Nat) (z : Nat) (zs : List Nat)
: List.elim3 C (x::xs) (y::ys) (z::zs) h₁ h₂ h₃ = h₃ (x::xs) (y::ys) (z::zs) :=
rfl
|
62bee5a02c431aa0159ee28306a0eed9219d0ca7 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/geometry/manifold/basic_smooth_bundle.lean | 0ac297aa7a7d9e3b6ef203c382c9e0c9babb458a | [
"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 | 33,243 | 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.topological_fiber_bundle geometry.manifold.smooth_manifold_with_corners
/-!
# Basic smooth bundles
In general, a smooth bundle is a bundle over a smooth manifold, whose fiber is a manifold, and
for which the coordinate changes are smooth. In this definition, there are charts involved at
several places: in the manifold structure of the base, in the manifold structure of the fibers, and
in the local trivializations. This makes it a complicated object in general. There is however a
specific situation where things are much simpler: when the fiber is a vector space (no need for
charts for the fibers), and when the local trivializations of the bundle and the charts of the base
coincide. Then everything is expressed in terms of the charts of the base, making for a much
simpler overall structure, which is easier to manipulate formally.
Most vector bundles that naturally occur in differential geometry are of this form:
the tangent bundle, the cotangent bundle, differential forms (used to define de Rham cohomology)
and the bundle of Riemannian metrics. Therefore, it is worth defining a specific constructor for
this kind of bundle, that we call basic smooth bundles.
A basic smooth bundle is thus a smooth bundle over a smooth manifold whose fiber is a vector space,
and which is trivial in the coordinate charts of the base. (We recall that in our notion of manifold
there is a distinguished atlas, which does not need to be maximal: we require the triviality above
this specific atlas). It can be constructed from a basic smooth bundled core, defined below,
specifying the changes in the fiber when one goes from one coordinate chart to another one. We do
not require that this changes in fiber are linear, but only diffeomorphisms.
## Main definitions
* `basic_smooth_bundle_core I M F`: assuming that `M` is a smooth manifold over the model with
corners `I` on `(𝕜, E, H)`, and `F` is a normed vector space over `𝕜`, this structure registers,
for each pair of charts of `M`, a smooth change of coordinates on `F`. This is the core structure
from which one will build a smooth bundle with fiber `F` over `M`.
Let `Z` be a basic smooth bundle core over `M` with fiber `F`. We define
`Z.to_topological_fiber_bundle_core`, the (topological) fiber bundle core associated to `Z`. From it,
we get a space `Z.to_topological_fiber_bundle_core.total_space` (which as a Type is just `M × F`),
with the fiber bundle topology. It inherits a manifold structure (where the charts are in bijection
with the charts of the basis). We show that this manifold is smooth.
Then we use this machinery to construct the tangent bundle of a smooth manifold.
* `tangent_bundle_core I M`: the basic smooth bundle core associated to a smooth manifold `M` over a
model with corners `I`.
* `tangent_bundle I M` : the total space of `tangent_bundle_core I M`. It is itself a
smooth manifold over the model with corners `I.tangent`, the product of `I` and the trivial model
with corners on `E`.
* `tangent_space I x` : the tangent space to `M` at `x`
* `tangent_bundle.proj I M`: the projection from the tangent bundle to the base manifold
## Implementation notes
In the definition of a basic smooth bundle core, we do not require that the coordinate changes of
the fibers are linear map, only that they are diffeomorphisms. Therefore, the fibers of the
resulting fiber bundle do not inherit a vector space structure (as an algebraic object) in general.
As the fiber, as a type, is just `F`, one can still always register the vector space structure, but
it does not make sense to do so (i.e., it will not lead to any useful theorem) unless this structure
is canonical, i.e., the coordinate changes are linear maps.
For instance, we register the vector space structure on the fibers of the tangent bundle. However,
we do not register the normed space structure coming from that of `F` (as it is not canonical, and
we also want to keep the possibility to add a Riemannian structure on the manifold later on without
having two competing normed space instances on the tangent spaces).
We require `F` to be a normed space, and not just a topological vector space, as we want to talk
about smooth functions on `F`. The notion of derivative requires a norm to be defined.
## TODO
construct the cotangent bundle, and the bundles of differential forms. They should follow
functorially from the description of the tangent bundle as a basic smooth bundle.
## Tags
Smooth fiber bundle, vector bundle, tangent space, tangent bundle
-/
noncomputable theory
universe u
open topological_space set
/-- Core structure used to create a smooth bundle above `M` (a manifold over the model with
corner I) with fiber the normed vector space `F` over `𝕜`, which is trivial in the chart domains of
`M`. This structure registers the changes in the fibers when one changes coordinate charts in the
base. We do not require the change of coordinates of the fibers to be linear, only smooth.
Therefore, the fibers of the resulting bundle will not inherit a canonical vector space structure
in general. -/
structure basic_smooth_bundle_core {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type u} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
(F : Type u) [normed_group F] [normed_space 𝕜 F] :=
(coord_change : atlas H M → atlas H M → H → F → F)
(coord_change_self :
∀ i : atlas H M, ∀ x ∈ i.1.target, ∀ v, coord_change i i x v = v)
(coord_change_comp : ∀ i j k : atlas H M,
∀ x ∈ ((i.1.symm.trans j.1).trans (j.1.symm.trans k.1)).source, ∀ v,
(coord_change j k ((i.1.symm.trans j.1).to_fun x)) (coord_change i j x v) = coord_change i k x v)
(coord_change_smooth : ∀ i j : atlas H M,
times_cont_diff_on 𝕜 ⊤ (λp : E × F, coord_change i j (I.inv_fun p.1) p.2)
((I.to_fun '' (i.1.symm.trans j.1).source).prod (univ : set F)))
namespace basic_smooth_bundle_core
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type u} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
{M : Type*} [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
{F : Type u} [normed_group F] [normed_space 𝕜 F]
(Z : basic_smooth_bundle_core I M F)
/-- Fiber bundle core associated to a basic smooth bundle core -/
def to_topological_fiber_bundle_core : topological_fiber_bundle_core (atlas H M) M F :=
{ base_set := λi, i.1.source,
is_open_base_set := λi, i.1.open_source,
index_at := λx, ⟨chart_at H x, chart_mem_atlas H x⟩,
mem_base_set_at := λx, mem_chart_source H x,
coord_change := λi j x v, Z.coord_change i j (i.1.to_fun x) v,
coord_change_self := λi x hx v, Z.coord_change_self i (i.1.to_fun x) (i.1.map_source hx) v,
coord_change_comp := λi j k x ⟨⟨hx1, hx2⟩, hx3⟩ v, begin
have := Z.coord_change_comp i j k (i.1.to_fun x) _ v,
convert this using 2,
{ simp [hx1] },
{ simp [local_equiv.trans_source, hx1, hx2, hx3, i.1.map_source, j.1.map_source] }
end,
coord_change_continuous := λi j, begin
have A : continuous_on (λp : E × F, Z.coord_change i j (I.inv_fun p.1) p.2)
((I.to_fun '' (i.1.symm.trans j.1).source).prod (univ : set F)) :=
(Z.coord_change_smooth i j).continuous_on,
have B : continuous_on (λx : M, I.to_fun (i.1.to_fun x)) i.1.source :=
I.continuous_to_fun.comp_continuous_on i.1.continuous_to_fun,
have C : continuous_on (λp : M × F, (⟨I.to_fun (i.1.to_fun p.1), p.2⟩ : E × F))
(i.1.source.prod univ),
{ apply continuous_on.prod _ continuous_snd.continuous_on,
exact B.comp continuous_fst.continuous_on (prod_subset_preimage_fst _ _) },
have C' : continuous_on (λp : M × F, (⟨I.to_fun (i.1.to_fun p.1), p.2⟩ : E × F))
((i.1.source ∩ j.1.source).prod univ) :=
continuous_on.mono C (prod_mono (inter_subset_left _ _) (subset.refl _)),
have D : (i.1.source ∩ j.1.source).prod univ ⊆ (λ (p : M × F),
(I.to_fun (i.1.to_fun p.1), p.2)) ⁻¹' ((I.to_fun '' (i.1.symm.trans j.1).source).prod univ),
{ rintros ⟨x, v⟩ hx,
simp at hx,
simp [mem_image_of_mem, local_equiv.trans_source, hx] },
convert continuous_on.comp A C' D,
ext p,
simp
end }
@[simp] lemma base_set (i : atlas H M) :
Z.to_topological_fiber_bundle_core.base_set i = i.1.source := rfl
/-- Local chart for the total space of a basic smooth bundle -/
def chart {e : local_homeomorph M H} (he : e ∈ atlas H M) :
local_homeomorph (Z.to_topological_fiber_bundle_core.total_space) (H × F) :=
(Z.to_topological_fiber_bundle_core.local_triv ⟨e, he⟩).trans
(local_homeomorph.prod e (local_homeomorph.refl F))
@[simp] lemma chart_source (e : local_homeomorph M H) (he : e ∈ atlas H M) :
(Z.chart he).source = Z.to_topological_fiber_bundle_core.proj ⁻¹' e.source :=
by { ext p, simp [chart, local_equiv.trans_source] }
@[simp] lemma chart_target (e : local_homeomorph M H) (he : e ∈ atlas H M) :
(Z.chart he).target = e.target.prod univ :=
begin
simp only [chart, local_equiv.trans_target, local_homeomorph.prod_to_local_equiv, id.def,
local_equiv.refl_inv_fun, local_homeomorph.trans_to_local_equiv, local_equiv.refl_target,
local_homeomorph.refl_local_equiv, local_equiv.prod_target, local_homeomorph.prod_inv_fun],
ext p,
split;
simp [e.map_target] {contextual := tt}
end
/-- The total space of a basic smooth bundle is endowed with a manifold structure, where the charts
are in bijection with the charts of the basis. -/
instance to_manifold : manifold (H × F) Z.to_topological_fiber_bundle_core.total_space :=
{ atlas := ⋃(e : local_homeomorph M H) (he : e ∈ atlas H M), {Z.chart he},
chart_at := λp, Z.chart (chart_mem_atlas H p.1),
mem_chart_source := λp, by simp [mem_chart_source],
chart_mem_atlas := λp, begin
simp only [mem_Union, mem_singleton_iff, chart_mem_atlas],
exact ⟨chart_at H p.1, chart_mem_atlas H p.1, rfl⟩
end }
lemma mem_atlas_iff (f : local_homeomorph Z.to_topological_fiber_bundle_core.total_space (H × F)) :
f ∈ atlas (H × F) Z.to_topological_fiber_bundle_core.total_space ↔
∃(e : local_homeomorph M H) (he : e ∈ atlas H M), f = Z.chart he :=
by simp [atlas, manifold.atlas]
@[simp] lemma mem_chart_source_iff (p q : Z.to_topological_fiber_bundle_core.total_space) :
p ∈ (chart_at (H × F) q).source ↔ p.1 ∈ (chart_at H q.1).source :=
by simp [chart_at, manifold.chart_at]
@[simp] lemma mem_chart_target_iff (p : H × F) (q : Z.to_topological_fiber_bundle_core.total_space) :
p ∈ (chart_at (H × F) q).target ↔ p.1 ∈ (chart_at H q.1).target :=
by simp [chart_at, manifold.chart_at]
@[simp] lemma chart_at_to_fun_fst (p q : Z.to_topological_fiber_bundle_core.total_space) :
((chart_at (H × F) q).to_fun p).1 = (chart_at H q.1).to_fun p.1 := rfl
@[simp] lemma chart_at_inv_fun_fst (p : H × F) (q : Z.to_topological_fiber_bundle_core.total_space) :
((chart_at (H × F) q).inv_fun p).1 = (chart_at H q.1).inv_fun p.1 := rfl
/-- Smooth manifold structure on the total space of a basic smooth bundle -/
instance to_smooth_manifold :
smooth_manifold_with_corners (I.prod (model_with_corners_self 𝕜 F))
Z.to_topological_fiber_bundle_core.total_space :=
begin
/- We have to check that the charts belong to the smooth groupoid, i.e., they are smooth on their
source, and their inverses are smooth on the target. Since both objects are of the same type, it
suffices to prove the first statement in A below, and then glue back the pieces at the end. -/
let J := model_with_corners.to_local_equiv (I.prod (model_with_corners_self 𝕜 F)),
have A : ∀ (e e' : local_homeomorph M H) (he : e ∈ atlas H M) (he' : e' ∈ atlas H M),
times_cont_diff_on 𝕜 ⊤
(J.to_fun ∘ ((Z.chart he).symm.trans (Z.chart he')).to_fun ∘ J.inv_fun)
(J.inv_fun ⁻¹' ((Z.chart he).symm.trans (Z.chart he')).source ∩ range J.to_fun),
{ assume e e' he he',
have U : unique_diff_on 𝕜
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod (univ : set F)),
{ apply unique_diff_on.prod _ unique_diff_on_univ,
rw inter_comm,
exact I.unique_diff.inter (I.continuous_inv_fun _ (local_homeomorph.open_source _)) },
have : J.inv_fun ⁻¹' ((chart Z he).symm.trans (chart Z he')).source ∩ range J.to_fun =
(I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod univ,
{ have : range (λ (p : H × F), (I.to_fun (p.fst), id p.snd)) =
(range I.to_fun).prod (range (id : F → F)) := prod_range_range_eq.symm,
simp at this,
ext p,
simp [-mem_range, J, local_equiv.trans_source, chart, model_with_corners.prod,
local_equiv.trans_target, this],
split,
{ tauto },
{ exact λ⟨⟨hx1, hx2⟩, hx3⟩, ⟨⟨⟨hx1, e.map_target hx1⟩, hx2⟩, hx3⟩ } },
rw this,
-- check separately that the two components of the coordinate change are smooth
apply times_cont_diff_on.prod _ _ U,
show times_cont_diff_on 𝕜 ⊤ (λ (p : E × F), (I.to_fun ∘ e'.to_fun ∘ e.inv_fun ∘ I.inv_fun) p.1)
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod (univ : set F)),
{ -- the coordinate change on the base is just a coordinate change for `M`, smooth since
-- `M` is smooth
have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (e.symm.trans e').to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) he he').1,
have B : times_cont_diff_on 𝕜 ⊤ (λp : E × F, p.1)
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod univ) :=
times_cont_diff_fst.times_cont_diff_on U,
exact times_cont_diff_on.comp A B U (prod_subset_preimage_fst _ _) },
show times_cont_diff_on 𝕜 ⊤ (λ (p : E × F),
Z.coord_change ⟨chart_at H (e.inv_fun (I.inv_fun p.1)), _⟩ ⟨e', he'⟩
((chart_at H (e.inv_fun (I.inv_fun p.1))).to_fun (e.inv_fun (I.inv_fun p.1)))
(Z.coord_change ⟨e, he⟩ ⟨chart_at H (e.inv_fun (I.inv_fun p.1)), _⟩
(e.to_fun (e.inv_fun (I.inv_fun p.1))) p.2))
((I.inv_fun ⁻¹' (e.symm.trans e').source ∩ range I.to_fun).prod (univ : set F)),
{ /- The coordinate change in the fiber is more complicated as its definition involves the
reference chart chosen at each point. However, it appears with its inverse, so using the
cocycle property one can get rid of it, and then conclude using the smoothness of the
cocycle as given in the definition of basic smooth bundles. -/
have := Z.coord_change_smooth ⟨e, he⟩ ⟨e', he'⟩,
rw model_with_corners.image at this,
apply times_cont_diff_on.congr this U,
rintros ⟨x, v⟩ hx,
simp [local_equiv.trans_source] at hx,
let f := chart_at H (e.inv_fun (I.inv_fun x)),
have A : I.inv_fun x ∈ ((e.symm.trans f).trans (f.symm.trans e')).source,
by simp [local_equiv.trans_source, hx.1.1, hx.1.2, mem_chart_source, f.map_source],
rw e.right_inv hx.1.1,
have := Z.coord_change_comp ⟨e, he⟩ ⟨f, chart_mem_atlas _ _⟩ ⟨e', he'⟩ (I.inv_fun x) A v,
simpa using this } },
haveI : has_groupoid Z.to_topological_fiber_bundle_core.total_space
(times_cont_diff_groupoid ⊤ (I.prod (model_with_corners_self 𝕜 F))) :=
begin
split,
assume e₀ e₀' he₀ he₀',
rcases (Z.mem_atlas_iff _).1 he₀ with ⟨e, he, rfl⟩,
rcases (Z.mem_atlas_iff _).1 he₀' with ⟨e', he', rfl⟩,
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
exact ⟨A e e' he he', A e' e he' he⟩
end,
constructor
end
end basic_smooth_bundle_core
section tangent_bundle
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type u} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
set_option class.instance_max_depth 50
/-- Basic smooth bundle core version of the tangent bundle of a smooth manifold `M` modelled over a
model with corners `I` on `(E, H)`. The fibers are equal to `E`, and the coordinate change in the
fiber corresponds to the derivative of the coordinate change in `M`. -/
def tangent_bundle_core : basic_smooth_bundle_core I M E :=
{ coord_change := λi j x v, (fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) (I.to_fun x) : E → E) v,
coord_change_smooth := λi j, begin
/- To check that the coordinate change of the bundle is smooth, one should just use the
smoothness of the charts, and thus the smoothness of their derivatives. -/
rw model_with_corners.image,
have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (i.1.symm.trans j.1).to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) i.2 j.2).1,
have B : unique_diff_on 𝕜 (I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun),
{ rw inter_comm,
apply I.unique_diff.inter (I.continuous_inv_fun _ (local_homeomorph.open_source _)) },
have C : times_cont_diff_on 𝕜 ⊤
(λ (p : E × E), (fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) p.1 : E → E) p.2)
((I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun).prod univ) :=
times_cont_diff_on_fderiv_within_apply A B lattice.le_top,
have D : ∀ x ∈ (I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun),
fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) x =
fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) x,
{ assume x hx,
have N : I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∈ nhds x :=
I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) hx.1),
symmetry,
rw inter_comm,
exact fderiv_within_inter N (I.unique_diff _ hx.2) },
apply times_cont_diff_on.congr C (unique_diff_on.prod B unique_diff_on_univ),
rintros ⟨x, v⟩ hx,
have E : x ∈ I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun,
by simpa using hx,
have : I.to_fun (I.inv_fun x) = x, by simp [E.2],
dsimp,
rw [this, D x E],
refl
end,
coord_change_self := λi x hx v, begin
/- Locally, a self-change of coordinate is just the identity, thus its derivative is the
identity. One just needs to write this carefully, paying attention to the sets where the
functions are defined. -/
have A : I.inv_fun ⁻¹' (i.1.symm.trans i.1).source ∩ range I.to_fun ∈
nhds_within (I.to_fun x) (range I.to_fun),
{ rw inter_comm,
apply inter_mem_nhds_within,
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
simp [hx, local_equiv.trans_source, i.1.map_target] },
have B : {y : E | (I.to_fun ∘ i.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) y = (id : E → E) y} ∈
nhds_within (I.to_fun x) (range I.to_fun),
{ apply filter.mem_sets_of_superset A,
assume y hy,
rw ← model_with_corners.image at hy,
rcases hy with ⟨z, hz⟩,
simp [local_equiv.trans_source] at hz,
simp [hz.2.symm, hz.1] },
have C : fderiv_within 𝕜 (I.to_fun ∘ i.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) (I.to_fun x) =
fderiv_within 𝕜 (id : E → E) (range I.to_fun) (I.to_fun x) :=
fderiv_within_congr_of_mem_nhds_within (I.unique_diff _ (mem_range_self _)) B (by simp [hx]),
rw fderiv_within_id (I.unique_diff _ (mem_range_self _)) at C,
rw C,
refl
end,
coord_change_comp := λi j u x hx, begin
/- The cocycle property is just the fact that the derivative of a composition is the product of
the derivatives. One needs however to check that all the functions one considers are smooth, and
to pay attention to the domains where these functions are defined, making this proof a little
bit cumbersome although there is nothing complicated here. -/
have M : I.to_fun x ∈
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun) :=
⟨by simpa using hx, mem_range_self _⟩,
have U : unique_diff_within_at 𝕜
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x),
{ have : unique_diff_on 𝕜
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun),
{ rw inter_comm,
exact I.unique_diff.inter (I.continuous_inv_fun _ (local_homeomorph.open_source _)) },
exact this _ M },
have A : fderiv_within 𝕜 ((I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
∘ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun))
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x)
= (fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x))).comp
(fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x)),
{ apply fderiv_within.comp _ _ _ _ U,
show differentiable_within_at 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x),
{ have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (i.1.symm.trans j.1).to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (i.1.symm.trans j.1).source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) i.2 j.2).1,
have B : differentiable_on 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun),
{ apply (A.differentiable_on (lattice.le_top)).mono,
have : ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ⊆ (i.1.symm.trans j.1).source :=
inter_subset_left _ _,
exact inter_subset_inter (preimage_mono this) (subset.refl (range I.to_fun)) },
apply B,
simpa [mem_inter_iff, -mem_image, -mem_range, mem_range_self] using hx },
show differentiable_within_at 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x)),
{ have A : times_cont_diff_on 𝕜 ⊤
(I.to_fun ∘ (j.1.symm.trans u.1).to_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun) :=
(has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) j.2 u.2).1,
apply A.differentiable_on (lattice.le_top),
rw [local_homeomorph.trans_source] at hx,
simp [mem_inter_iff, -mem_image, -mem_range, mem_range_self],
exact hx.2 },
show (I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
⊆ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) ⁻¹'
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun),
{ assume y hy,
simp [-mem_range, local_equiv.trans_source] at hy,
rw [local_equiv.left_inv] at hy,
{ simp [-mem_range, mem_range_self, hy, local_equiv.trans_source] },
{ exact hy.1.1.2 } } },
have B : fderiv_within 𝕜 ((I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
∘ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun))
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x)
= fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x),
{ have E : ∀ y ∈ (I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun),
((I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
∘ (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)) y =
(I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) y,
{ assume y hy,
simp only [function.comp_app, model_with_corners_left_inv],
rw [j.1.left_inv],
exact hy.1.1.2 },
exact fderiv_within_congr U E (E _ M) },
have C : fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x) =
fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun) (I.to_fun x),
{ rw inter_comm,
apply fderiv_within_inter _ (I.unique_diff _ (mem_range_self _)),
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
simpa using hx },
have D : fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' (j.1.symm.trans u.1).source ∩ range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x)) =
fderiv_within 𝕜 (I.to_fun ∘ u.1.to_fun ∘ j.1.inv_fun ∘ I.inv_fun)
(range I.to_fun)
((I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun) (I.to_fun x)),
{ rw inter_comm,
apply fderiv_within_inter _ (I.unique_diff _ (mem_range_self _)),
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
rw [local_homeomorph.trans_source] at hx,
simp [mem_inter_iff, -mem_image, -mem_range, mem_range_self],
exact hx.2 },
have E : fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(I.inv_fun ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I.to_fun)
(I.to_fun x) =
(fderiv_within 𝕜 (I.to_fun ∘ j.1.to_fun ∘ i.1.inv_fun ∘ I.inv_fun)
(range I.to_fun)
(I.to_fun x)),
{ rw inter_comm,
apply fderiv_within_inter _ (I.unique_diff _ (mem_range_self _)),
apply I.continuous_inv_fun.continuous_at.preimage_mem_nhds
(mem_nhds_sets (local_homeomorph.open_source _) _),
simpa using hx },
rw [B, C, D, E] at A,
rw A,
assume v,
simp,
unfold_coes,
simp
end }
/-- The tangent bundle to a smooth manifold, as a plain type. -/
def tangent_bundle := (tangent_bundle_core I M).to_topological_fiber_bundle_core.total_space
/-- The projection from the tangent bundle of a smooth manifold to the manifold. As the tangent
bundle is represented internally as a product type, the notation `p.1` also works for the projection
of the point `p`. -/
def tangent_bundle.proj : tangent_bundle I M → M :=
(tangent_bundle_core I M).to_topological_fiber_bundle_core.proj
variable {M}
/-- The tangent space at a point of the manifold `M`. It is just `E`. -/
def tangent_space (x : M) : Type* :=
(tangent_bundle_core I M).to_topological_fiber_bundle_core.fiber x
section tangent_bundle_instances
/- In general, the definition of tangent_bundle and tangent_space are not reducible, so that type
class inference does not pick wrong instances. In this section, we record the right instances for
them, noting in particular that the tangent bundle is a smooth manifold. -/
variable (M)
local attribute [reducible] tangent_bundle
instance : topological_space (tangent_bundle I M) := by apply_instance
instance : manifold (H × E) (tangent_bundle I M) := by apply_instance
instance : smooth_manifold_with_corners I.tangent (tangent_bundle I M) := by apply_instance
local attribute [reducible] tangent_space topological_fiber_bundle_core.fiber
/- When `topological_fiber_bundle_core.fiber` is reducible, then
`topological_fiber_bundle_core.topological_space_fiber` can be applied to prove that any space is
a topological space, with several unknown metavariables. This is a bad instance, that we disable.-/
local attribute [instance, priority 0] topological_fiber_bundle_core.topological_space_fiber
variables {M} (x : M)
instance : topological_module 𝕜 (tangent_space I x) := by apply_instance
instance : topological_space (tangent_space I x) := by apply_instance
instance : add_comm_group (tangent_space I x) := by apply_instance
instance : topological_add_group (tangent_space I x) := by apply_instance
instance : vector_space 𝕜 (tangent_space I x) := by apply_instance
end tangent_bundle_instances
variable (M)
/-- The tangent bundle projection on the basis is a continuous map. -/
lemma tangent_bundle_proj_continuous : continuous (tangent_bundle.proj I M) :=
topological_fiber_bundle_core.continuous_proj _
/-- The tangent bundle projection on the basis is an open map. -/
lemma tangent_bundle_proj_open : is_open_map (tangent_bundle.proj I M) :=
topological_fiber_bundle_core.is_open_map_proj _
/-- In the tangent bundle to the model space, the charts are just the identity-/
@[simp] lemma tangent_bundle_model_space_chart_at (p : tangent_bundle I H) :
(chart_at (H × E) p).to_local_equiv = local_equiv.refl (H × E) :=
begin
have A : ∀ x_fst, fderiv_within 𝕜 (I.to_fun ∘ I.inv_fun) (range I.to_fun) (I.to_fun x_fst)
= continuous_linear_map.id,
{ assume x_fst,
have : fderiv_within 𝕜 (I.to_fun ∘ I.inv_fun) (range I.to_fun) (I.to_fun x_fst)
= fderiv_within 𝕜 id (range I.to_fun) (I.to_fun x_fst),
{ refine fderiv_within_congr (I.unique_diff _ (mem_range_self _)) (λy hy, _) (by simp),
exact model_with_corners_right_inv _ hy },
rwa fderiv_within_id (I.unique_diff _ (mem_range_self _)) at this },
ext x : 1,
show (chart_at (H × E) p).to_fun x = (local_equiv.refl (H × E)).to_fun x,
{ cases x,
simp [chart_at, manifold.chart_at, basic_smooth_bundle_core.chart,
topological_fiber_bundle_core.local_triv, topological_fiber_bundle_core.local_triv',
basic_smooth_bundle_core.to_topological_fiber_bundle_core, tangent_bundle_core],
erw [local_equiv.refl_to_fun, local_equiv.refl_inv_fun, A],
refl },
show ∀ x, ((chart_at (H × E) p).to_local_equiv).inv_fun x = (local_equiv.refl (H × E)).inv_fun x,
{ rintros ⟨x_fst, x_snd⟩,
simp [chart_at, manifold.chart_at, basic_smooth_bundle_core.chart,
topological_fiber_bundle_core.local_triv, topological_fiber_bundle_core.local_triv',
basic_smooth_bundle_core.to_topological_fiber_bundle_core, tangent_bundle_core],
erw [local_equiv.refl_to_fun, local_equiv.refl_inv_fun, A],
refl },
show ((chart_at (H × E) p).to_local_equiv).source = (local_equiv.refl (H × E)).source,
by simp [chart_at, manifold.chart_at, basic_smooth_bundle_core.chart,
topological_fiber_bundle_core.local_triv, topological_fiber_bundle_core.local_triv',
basic_smooth_bundle_core.to_topological_fiber_bundle_core, tangent_bundle_core,
local_equiv.trans_source]
end
variable (H)
/-- In the tangent bundle to the model space, the topology is the product topology, i.e., the bundle
is trivial -/
lemma tangent_bundle_model_space_topology_eq_prod :
tangent_bundle.topological_space I H = prod.topological_space :=
begin
ext o,
let x : tangent_bundle I H := (I.inv_fun (0 : E), (0 : E)),
let e := chart_at (H × E) x,
have e_source : e.source = univ, by { simp [e], refl },
have e_target : e.target = univ, by { simp [e], refl },
let e' := e.to_homeomorph_of_source_eq_univ_target_eq_univ e_source e_target,
split,
{ assume ho,
have := e'.continuous_inv_fun o ho,
simpa [e', tangent_bundle_model_space_chart_at] },
{ assume ho,
have := e'.continuous_to_fun o ho,
simpa [e', tangent_bundle_model_space_chart_at] }
end
end tangent_bundle
|
884e7bcfb829a6b62176c7481a7cb83887e2d225 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/box_integral/partition/split.lean | 7a3dd3c13e81ef03a138cf4b48587ffa1b67e089 | [
"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 | 15,658 | lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.box_integral.partition.basic
/-!
# Split a box along one or more hyperplanes
## Main definitions
A hyperplane `{x : ι → ℝ | x i = a}` splits a rectangular box `I : box_integral.box ι` into two
smaller boxes. If `a ∉ Ioo (I.lower i, I.upper i)`, then one of these boxes is empty, so it is not a
box in the sense of `box_integral.box`.
We introduce the following definitions.
* `box_integral.box.split_lower I i a` and `box_integral.box.split_upper I i a` are these boxes (as
`with_bot (box_integral.box ι)`);
* `box_integral.prepartition.split I i a` is the partition of `I` made of these two boxes (or of one
box `I` if one of these boxes is empty);
* `box_integral.prepartition.split_many I s`, where `s : finset (ι × ℝ)` is a finite set of
hyperplanes `{x : ι → ℝ | x i = a}` encoded as pairs `(i, a)`, is the partition of `I` made by
cutting it along all the hyperplanes in `s`.
## Main results
The main result `box_integral.prepartition.exists_Union_eq_diff` says that any prepartition `π` of
`I` admits a prepartition `π'` of `I` that covers exactly `I \ π.Union`. One of these prepartitions
is available as `box_integral.prepartition.compl`.
## Tags
rectangular box, partition, hyperplane
-/
noncomputable theory
open_locale classical big_operators filter
open function set filter
namespace box_integral
variables {ι M : Type*} {n : ℕ}
namespace box
variables {I : box ι} {i : ι} {x : ℝ} {y : ι → ℝ}
/-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ι → ℝ | y i = x}` splits
`I` into two boxes. `box_integral.box.split_lower I i x` is the box `I ∩ {y | y i ≤ x}`
(if it is nonempty). As usual, we represent a box that may be empty as
`with_bot (box_integral.box ι)`. -/
def split_lower (I : box ι) (i : ι) (x : ℝ) : with_bot (box ι) :=
mk' I.lower (update I.upper i (min x (I.upper i)))
@[simp] lemma coe_split_lower : (split_lower I i x : set (ι → ℝ)) = I ∩ {y | y i ≤ x} :=
begin
rw [split_lower, coe_mk'],
ext y,
simp only [mem_univ_pi, mem_Ioc, mem_inter_eq, mem_coe, mem_set_of_eq, forall_and_distrib,
← pi.le_def, le_update_iff, le_min_iff, and_assoc, and_forall_ne i, mem_def],
rw [and_comm (y i ≤ x), pi.le_def]
end
lemma split_lower_le : I.split_lower i x ≤ I := with_bot_coe_subset_iff.1 $ by simp
@[simp] lemma split_lower_eq_bot {i x} : I.split_lower i x = ⊥ ↔ x ≤ I.lower i :=
begin
rw [split_lower, mk'_eq_bot, exists_update_iff I.upper (λ j y, y ≤ I.lower j)],
simp [(I.lower_lt_upper _).not_le]
end
@[simp] lemma split_lower_eq_self : I.split_lower i x = I ↔ I.upper i ≤ x :=
by simp [split_lower, update_eq_iff]
lemma split_lower_def [decidable_eq ι] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i))
(h' : ∀ j, I.lower j < update I.upper i x j :=
(forall_update_iff I.upper (λ j y, I.lower j < y)).2 ⟨h.1, λ j hne, I.lower_lt_upper _⟩) :
I.split_lower i x = (⟨I.lower, update I.upper i x, h'⟩ : box ι) :=
by { simp only [split_lower, mk'_eq_coe, min_eq_left h.2.le], use rfl, congr }
/-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ι → ℝ | y i = x}` splits
`I` into two boxes. `box_integral.box.split_upper I i x` is the box `I ∩ {y | x < y i}`
(if it is nonempty). As usual, we represent a box that may be empty as
`with_bot (box_integral.box ι)`. -/
def split_upper (I : box ι) (i : ι) (x : ℝ) : with_bot (box ι) :=
mk' (update I.lower i (max x (I.lower i))) I.upper
@[simp] lemma coe_split_upper : (split_upper I i x : set (ι → ℝ)) = I ∩ {y | x < y i} :=
begin
rw [split_upper, coe_mk'],
ext y,
simp only [mem_univ_pi, mem_Ioc, mem_inter_eq, mem_coe, mem_set_of_eq, forall_and_distrib,
forall_update_iff I.lower (λ j z, z < y j), max_lt_iff, and_assoc (x < y i),
and_forall_ne i, mem_def],
exact and_comm _ _
end
lemma split_upper_le : I.split_upper i x ≤ I := with_bot_coe_subset_iff.1 $ by simp
@[simp] lemma split_upper_eq_bot {i x} : I.split_upper i x = ⊥ ↔ I.upper i ≤ x :=
begin
rw [split_upper, mk'_eq_bot, exists_update_iff I.lower (λ j y, I.upper j ≤ y)],
simp [(I.lower_lt_upper _).not_le]
end
@[simp] lemma split_upper_eq_self : I.split_upper i x = I ↔ x ≤ I.lower i :=
by simp [split_upper, update_eq_iff]
lemma split_upper_def [decidable_eq ι] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i))
(h' : ∀ j, update I.lower i x j < I.upper j :=
(forall_update_iff I.lower (λ j y, y < I.upper j)).2 ⟨h.2, λ j hne, I.lower_lt_upper _⟩) :
I.split_upper i x = (⟨update I.lower i x, I.upper, h'⟩ : box ι) :=
by { simp only [split_upper, mk'_eq_coe, max_eq_left h.1.le], refine ⟨_, rfl⟩, congr }
lemma disjoint_split_lower_split_upper (I : box ι) (i : ι) (x : ℝ) :
disjoint (I.split_lower i x) (I.split_upper i x) :=
begin
rw [← disjoint_with_bot_coe, coe_split_lower, coe_split_upper],
refine (disjoint.inf_left' _ _).inf_right' _,
exact λ y (hy : y i ≤ x ∧ x < y i), not_lt_of_le hy.1 hy.2
end
lemma split_lower_ne_split_upper (I : box ι) (i : ι) (x : ℝ) :
I.split_lower i x ≠ I.split_upper i x :=
begin
cases le_or_lt x (I.lower i),
{ rw [split_upper_eq_self.2 h, split_lower_eq_bot.2 h], exact with_bot.bot_ne_coe },
{ refine (disjoint_split_lower_split_upper I i x).ne _,
rwa [ne.def, split_lower_eq_bot, not_le] }
end
end box
namespace prepartition
variables {I J : box ι} {i : ι} {x : ℝ}
/-- The partition of `I : box ι` into the boxes `I ∩ {y | y ≤ x i}` and `I ∩ {y | x i < y}`.
One of these boxes can be empty, then this partition is just the single-box partition `⊤`. -/
def split (I : box ι) (i : ι) (x : ℝ) : prepartition I :=
of_with_bot {I.split_lower i x, I.split_upper i x}
begin
simp only [finset.mem_insert, finset.mem_singleton],
rintro J (rfl|rfl),
exacts [box.split_lower_le, box.split_upper_le]
end
begin
simp only [finset.coe_insert, finset.coe_singleton, true_and, set.mem_singleton_iff,
pairwise_insert_of_symmetric symmetric_disjoint, pairwise_singleton],
rintro J rfl -,
exact I.disjoint_split_lower_split_upper i x
end
@[simp] lemma mem_split_iff : J ∈ split I i x ↔ ↑J = I.split_lower i x ∨ ↑J = I.split_upper i x :=
by simp [split]
lemma mem_split_iff' : J ∈ split I i x ↔
(J : set (ι → ℝ)) = I ∩ {y | y i ≤ x} ∨ (J : set (ι → ℝ)) = I ∩ {y | x < y i} :=
by simp [mem_split_iff, ← box.with_bot_coe_inj]
@[simp] lemma Union_split (I : box ι) (i : ι) (x : ℝ) : (split I i x).Union = I :=
by simp [split, ← inter_union_distrib_left, ← set_of_or, le_or_lt]
lemma is_partition_split (I : box ι) (i : ι) (x : ℝ) : is_partition (split I i x) :=
is_partition_iff_Union_eq.2 $ Union_split I i x
lemma sum_split_boxes {M : Type*} [add_comm_monoid M] (I : box ι) (i : ι) (x : ℝ) (f : box ι → M) :
∑ J in (split I i x).boxes, f J = (I.split_lower i x).elim 0 f + (I.split_upper i x).elim 0 f :=
by rw [split, sum_of_with_bot, finset.sum_pair (I.split_lower_ne_split_upper i x)]
/-- If `x ∉ (I.lower i, I.upper i)`, then the hyperplane `{y | y i = x}` does not split `I`. -/
lemma split_of_not_mem_Ioo (h : x ∉ Ioo (I.lower i) (I.upper i)) : split I i x = ⊤ :=
begin
refine ((is_partition_top I).eq_of_boxes_subset (λ J hJ, _)).symm,
rcases mem_top.1 hJ with rfl, clear hJ,
rw [mem_boxes, mem_split_iff],
rw [mem_Ioo, not_and_distrib, not_lt, not_lt] at h,
cases h; [right, left],
{ rwa [eq_comm, box.split_upper_eq_self] },
{ rwa [eq_comm, box.split_lower_eq_self] }
end
lemma coe_eq_of_mem_split_of_mem_le {y : ι → ℝ} (h₁ : J ∈ split I i x) (h₂ : y ∈ J) (h₃ : y i ≤ x) :
(J : set (ι → ℝ)) = I ∩ {y | y i ≤ x} :=
(mem_split_iff'.1 h₁).resolve_right $ λ H,
by { rw [← box.mem_coe, H] at h₂, exact h₃.not_lt h₂.2 }
lemma coe_eq_of_mem_split_of_lt_mem {y : ι → ℝ} (h₁ : J ∈ split I i x) (h₂ : y ∈ J) (h₃ : x < y i) :
(J : set (ι → ℝ)) = I ∩ {y | x < y i} :=
(mem_split_iff'.1 h₁).resolve_left $ λ H,
by { rw [← box.mem_coe, H] at h₂, exact h₃.not_le h₂.2 }
@[simp] lemma restrict_split (h : I ≤ J) (i : ι) (x : ℝ) : (split J i x).restrict I = split I i x :=
begin
refine ((is_partition_split J i x).restrict h).eq_of_boxes_subset _,
simp only [finset.subset_iff, mem_boxes, mem_restrict', exists_prop, mem_split_iff'],
have : ∀ s, (I ∩ s : set (ι → ℝ)) ⊆ J, from λ s, (inter_subset_left _ _).trans h,
rintro J₁ ⟨J₂, (H₂|H₂), H₁⟩; [left, right]; simp [H₁, H₂, inter_left_comm ↑I, this],
end
lemma inf_split (π : prepartition I) (i : ι) (x : ℝ) :
π ⊓ split I i x = π.bUnion (λ J, split J i x) :=
bUnion_congr_of_le rfl $ λ J hJ, restrict_split hJ i x
/-- Split a box along many hyperplanes `{y | y i = x}`; each hyperplane is given by the pair
`(i x)`. -/
def split_many (I : box ι) (s : finset (ι × ℝ)) : prepartition I :=
s.inf (λ p, split I p.1 p.2)
@[simp] lemma split_many_empty (I : box ι) : split_many I ∅ = ⊤ := finset.inf_empty
@[simp] lemma split_many_insert (I : box ι) (s : finset (ι × ℝ)) (p : ι × ℝ) :
split_many I (insert p s) = split_many I s ⊓ split I p.1 p.2 :=
by rw [split_many, finset.inf_insert, inf_comm, split_many]
lemma split_many_le_split (I : box ι) {s : finset (ι × ℝ)} {p : ι × ℝ} (hp : p ∈ s) :
split_many I s ≤ split I p.1 p.2 :=
finset.inf_le hp
lemma is_partition_split_many (I : box ι) (s : finset (ι × ℝ)) :
is_partition (split_many I s) :=
finset.induction_on s (by simp only [split_many_empty, is_partition_top]) $
λ a s ha hs, by simpa only [split_many_insert, inf_split]
using hs.bUnion (λ J hJ, is_partition_split _ _ _)
@[simp] lemma Union_split_many (I : box ι) (s : finset (ι × ℝ)) : (split_many I s).Union = I :=
(is_partition_split_many I s).Union_eq
lemma inf_split_many {I : box ι} (π : prepartition I) (s : finset (ι × ℝ)) :
π ⊓ split_many I s = π.bUnion (λ J, split_many J s) :=
begin
induction s using finset.induction_on with p s hp ihp,
{ simp },
{ simp_rw [split_many_insert, ← inf_assoc, ihp, inf_split, bUnion_assoc] }
end
/-- Let `s : finset (ι × ℝ)` be a set of hyperplanes `{x : ι → ℝ | x i = r}` in `ι → ℝ` encoded as
pairs `(i, r)`. Suppose that this set contains all faces of a box `J`. The hyperplanes of `s` split
a box `I` into subboxes. Let `Js` be one of them. If `J` and `Js` have nonempty intersection, then
`Js` is a subbox of `J`. -/
lemma not_disjoint_imp_le_of_subset_of_mem_split_many {I J Js : box ι} {s : finset (ι × ℝ)}
(H : ∀ i, {(i, J.lower i), (i, J.upper i)} ⊆ s) (HJs : Js ∈ split_many I s)
(Hn : ¬disjoint (J : with_bot (box ι)) Js) : Js ≤ J :=
begin
simp only [finset.insert_subset, finset.singleton_subset_iff] at H,
rcases box.not_disjoint_coe_iff_nonempty_inter.mp Hn with ⟨x, hx, hxs⟩,
refine λ y hy i, ⟨_, _⟩,
{ rcases split_many_le_split I (H i).1 HJs with ⟨Jl, Hmem : Jl ∈ split I i (J.lower i), Hle⟩,
have := Hle hxs,
rw [← box.coe_subset_coe, coe_eq_of_mem_split_of_lt_mem Hmem this (hx i).1] at Hle,
exact (Hle hy).2 },
{ rcases split_many_le_split I (H i).2 HJs with ⟨Jl, Hmem : Jl ∈ split I i (J.upper i), Hle⟩,
have := Hle hxs,
rw [← box.coe_subset_coe, coe_eq_of_mem_split_of_mem_le Hmem this (hx i).2] at Hle,
exact (Hle hy).2 }
end
section fintype
variable [finite ι]
/-- Let `s` be a finite set of boxes in `ℝⁿ = ι → ℝ`. Then there exists a finite set `t₀` of
hyperplanes (namely, the set of all hyperfaces of boxes in `s`) such that for any `t ⊇ t₀`
and any box `I` in `ℝⁿ` the following holds. The hyperplanes from `t` split `I` into subboxes.
Let `J'` be one of them, and let `J` be one of the boxes in `s`. If these boxes have a nonempty
intersection, then `J' ≤ J`. -/
lemma eventually_not_disjoint_imp_le_of_mem_split_many (s : finset (box ι)) :
∀ᶠ t : finset (ι × ℝ) in at_top, ∀ (I : box ι) (J ∈ s) (J' ∈ split_many I t),
¬disjoint (J : with_bot (box ι)) J' → J' ≤ J :=
begin
casesI nonempty_fintype ι,
refine eventually_at_top.2
⟨s.bUnion (λ J, finset.univ.bUnion (λ i, {(i, J.lower i), (i, J.upper i)})),
λ t ht I J hJ J' hJ', not_disjoint_imp_le_of_subset_of_mem_split_many (λ i, _) hJ'⟩,
exact λ p hp, ht (finset.mem_bUnion.2 ⟨J, hJ, finset.mem_bUnion.2 ⟨i, finset.mem_univ _, hp⟩⟩)
end
lemma eventually_split_many_inf_eq_filter (π : prepartition I) :
∀ᶠ t : finset (ι × ℝ) in at_top,
π ⊓ (split_many I t) = (split_many I t).filter (λ J, ↑J ⊆ π.Union) :=
begin
refine (eventually_not_disjoint_imp_le_of_mem_split_many π.boxes).mono (λ t ht, _),
refine le_antisymm ((bUnion_le_iff _).2 $ λ J hJ, _) (le_inf (λ J hJ, _) (filter_le _ _)),
{ refine of_with_bot_mono _,
simp only [finset.mem_image, exists_prop, mem_boxes, mem_filter],
rintro _ ⟨J₁, h₁, rfl⟩ hne,
refine ⟨_, ⟨J₁, ⟨h₁, subset.trans _ (π.subset_Union hJ)⟩, rfl⟩, le_rfl⟩,
exact ht I J hJ J₁ h₁ (mt disjoint_iff.1 hne) },
{ rw mem_filter at hJ,
rcases set.mem_Union₂.1 (hJ.2 J.upper_mem) with ⟨J', hJ', hmem⟩,
refine ⟨J', hJ', ht I _ hJ' _ hJ.1 $ box.not_disjoint_coe_iff_nonempty_inter.2 _⟩,
exact ⟨J.upper, hmem, J.upper_mem⟩ }
end
lemma exists_split_many_inf_eq_filter_of_finite (s : set (prepartition I)) (hs : s.finite) :
∃ t : finset (ι × ℝ), ∀ π ∈ s,
π ⊓ (split_many I t) = (split_many I t).filter (λ J, ↑J ⊆ π.Union) :=
begin
have := λ π (hπ : π ∈ s), eventually_split_many_inf_eq_filter π,
exact (hs.eventually_all.2 this).exists
end
/-- If `π` is a partition of `I`, then there exists a finite set `s` of hyperplanes such that
`split_many I s ≤ π`. -/
lemma is_partition.exists_split_many_le {I : box ι} {π : prepartition I}
(h : is_partition π) : ∃ s, split_many I s ≤ π :=
(eventually_split_many_inf_eq_filter π).exists.imp $ λ s hs,
by { rwa [h.Union_eq, filter_of_true, inf_eq_right] at hs, exact λ J hJ, le_of_mem _ hJ }
/-- For every prepartition `π` of `I` there exists a prepartition that covers exactly
`I \ π.Union`. -/
lemma exists_Union_eq_diff (π : prepartition I) :
∃ π' : prepartition I, π'.Union = I \ π.Union :=
begin
rcases π.eventually_split_many_inf_eq_filter.exists with ⟨s, hs⟩,
use (split_many I s).filter (λ J, ¬(J : set (ι → ℝ)) ⊆ π.Union),
simp [← hs]
end
/-- If `π` is a prepartition of `I`, then `π.compl` is a prepartition of `I`
such that `π.compl.Union = I \ π.Union`. -/
def compl (π : prepartition I) : prepartition I := π.exists_Union_eq_diff.some
@[simp] lemma Union_compl (π : prepartition I) : π.compl.Union = I \ π.Union :=
π.exists_Union_eq_diff.some_spec
/-- Since the definition of `box_integral.prepartition.compl` uses `Exists.some`,
the result depends only on `π.Union`. -/
lemma compl_congr {π₁ π₂ : prepartition I} (h : π₁.Union = π₂.Union) :
π₁.compl = π₂.compl :=
by { dunfold compl, congr' 1, rw h }
lemma is_partition.compl_eq_bot {π : prepartition I} (h : is_partition π) : π.compl = ⊥ :=
by rw [← Union_eq_empty, Union_compl, h.Union_eq, diff_self]
@[simp] lemma compl_top : (⊤ : prepartition I).compl = ⊥ := (is_partition_top I).compl_eq_bot
end fintype
end prepartition
end box_integral
|
9b514616d038744b7b231184f6f28148593cc346 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/algebra/module/submodule.lean | 962d4a368872c9be652c52521162a1923bebf55c | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,464 | lean | /-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
-/
import algebra.module.linear_map
import group_theory.group_action.sub_mul_action
/-!
# Submodules of a module
In this file we define
* `submodule R M` : a subset of a `module` `M` that contains zero and is closed with respect to
addition and scalar multiplication.
* `subspace k M` : an abbreviation for `submodule` assuming that `k` is a `field`.
## Tags
submodule, subspace, linear map
-/
open function
open_locale big_operators
universes u' u v w
variables {S : Type u'} {R : Type u} {M : Type v} {ι : Type w}
set_option old_structure_cmd true
/-- A submodule of a module is one which is closed under vector operations.
This is a sufficient condition for the subset of vectors in the submodule
to themselves form a module. -/
structure submodule (R : Type u) (M : Type v) [semiring R]
[add_comm_monoid M] [semimodule R M] extends add_submonoid M, sub_mul_action R M : Type v.
/-- Reinterpret a `submodule` as an `add_submonoid`. -/
add_decl_doc submodule.to_add_submonoid
/-- Reinterpret a `submodule` as an `sub_mul_action`. -/
add_decl_doc submodule.to_sub_mul_action
namespace submodule
variables [semiring R] [add_comm_monoid M] [semimodule R M]
instance : set_like (submodule R M) M :=
⟨submodule.carrier, λ p q h, by cases p; cases q; congr'⟩
variables {p q : submodule R M}
@[simp] lemma mk_coe (S : set M) (h₁ h₂ h₃) :
((⟨S, h₁, h₂, h₃⟩ : submodule R M) : set M) = S := rfl
@[ext] theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := set_like.ext h
theorem to_add_submonoid_injective :
injective (to_add_submonoid : submodule R M → add_submonoid M) :=
λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h)
@[simp] theorem to_add_submonoid_eq : p.to_add_submonoid = q.to_add_submonoid ↔ p = q :=
to_add_submonoid_injective.eq_iff
theorem to_sub_mul_action_injective :
injective (to_sub_mul_action : submodule R M → sub_mul_action R M) :=
λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h)
@[simp] theorem to_sub_mul_action_eq : p.to_sub_mul_action = q.to_sub_mul_action ↔ p = q :=
to_sub_mul_action_injective.eq_iff
end submodule
namespace submodule
section add_comm_monoid
variables [semiring S] [semiring R] [add_comm_monoid M]
-- We can infer the module structure implicitly from the bundled submodule,
-- rather than via typeclass resolution.
variables {semimodule_M : semimodule R M}
variables {p q : submodule R M}
variables {r : R} {x y : M}
variables [has_scalar S R] [semimodule S M] [is_scalar_tower S R M]
variables (p)
@[simp] lemma mem_carrier : x ∈ p.carrier ↔ x ∈ (p : set M) := iff.rfl
@[simp] lemma zero_mem : (0 : M) ∈ p := p.zero_mem'
lemma add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := p.add_mem' h₁ h₂
lemma smul_mem (r : R) (h : x ∈ p) : r • x ∈ p := p.smul_mem' r h
lemma smul_of_tower_mem (r : S) (h : x ∈ p) : r • x ∈ p :=
p.to_sub_mul_action.smul_of_tower_mem r h
lemma sum_mem {t : finset ι} {f : ι → M} : (∀c∈t, f c ∈ p) → (∑ i in t, f i) ∈ p :=
p.to_add_submonoid.sum_mem
lemma sum_smul_mem {t : finset ι} {f : ι → M} (r : ι → R)
(hyp : ∀ c ∈ t, f c ∈ p) : (∑ i in t, r i • f i) ∈ p :=
submodule.sum_mem _ (λ i hi, submodule.smul_mem _ _ (hyp i hi))
@[simp] lemma smul_mem_iff' (u : units S) : (u:S) • x ∈ p ↔ x ∈ p :=
p.to_sub_mul_action.smul_mem_iff' u
instance : has_add p := ⟨λx y, ⟨x.1 + y.1, add_mem _ x.2 y.2⟩⟩
instance : has_zero p := ⟨⟨0, zero_mem _⟩⟩
instance : inhabited p := ⟨0⟩
instance : has_scalar S p := ⟨λ c x, ⟨c • x.1, smul_of_tower_mem _ c x.2⟩⟩
protected lemma nonempty : (p : set M).nonempty := ⟨0, p.zero_mem⟩
@[simp] lemma mk_eq_zero {x} (h : x ∈ p) : (⟨x, h⟩ : p) = 0 ↔ x = 0 := subtype.ext_iff_val
variables {p}
@[simp, norm_cast] lemma coe_eq_zero {x : p} : (x : M) = 0 ↔ x = 0 :=
(set_like.coe_eq_coe : (x : M) = (0 : p) ↔ x = 0)
@[simp, norm_cast] lemma coe_add (x y : p) : (↑(x + y) : M) = ↑x + ↑y := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : p) : M) = 0 := rfl
@[norm_cast] lemma coe_smul (r : R) (x : p) : ((r • x : p) : M) = r • ↑x := rfl
@[simp, norm_cast] lemma coe_smul_of_tower (r : S) (x : p) : ((r • x : p) : M) = r • ↑x := rfl
@[simp, norm_cast] lemma coe_mk (x : M) (hx : x ∈ p) : ((⟨x, hx⟩ : p) : M) = x := rfl
@[simp] lemma coe_mem (x : p) : (x : M) ∈ p := x.2
variables (p)
instance : add_comm_monoid p :=
{ add := (+), zero := 0, .. p.to_add_submonoid.to_add_comm_monoid }
instance semimodule' : semimodule S p :=
by refine {smul := (•), ..p.to_sub_mul_action.mul_action', ..};
{ intros, apply set_coe.ext, simp [smul_add, add_smul, mul_smul] }
instance : semimodule R p := p.semimodule'
instance : is_scalar_tower S R p :=
p.to_sub_mul_action.is_scalar_tower
instance no_zero_smul_divisors [no_zero_smul_divisors R M] : no_zero_smul_divisors R p :=
⟨λ c x h,
have c = 0 ∨ (x : M) = 0,
from eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg coe h),
this.imp_right (@subtype.ext_iff _ _ x 0).mpr⟩
/-- Embedding of a submodule `p` to the ambient space `M`. -/
protected def subtype : p →ₗ[R] M :=
by refine {to_fun := coe, ..}; simp [coe_smul]
@[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl
lemma subtype_eq_val : ((submodule.subtype p) : p → M) = subtype.val := rfl
end add_comm_monoid
section add_comm_group
variables [ring R] [add_comm_group M]
variables {semimodule_M : semimodule R M}
variables (p p' : submodule R M)
variables {r : R} {x y : M}
lemma neg_mem (hx : x ∈ p) : -x ∈ p := p.to_sub_mul_action.neg_mem hx
/-- Reinterpret a submodule as an additive subgroup. -/
def to_add_subgroup : add_subgroup M :=
{ neg_mem' := λ _, p.neg_mem , .. p.to_add_submonoid }
@[simp] lemma coe_to_add_subgroup : (p.to_add_subgroup : set M) = p := rfl
lemma sub_mem : x ∈ p → y ∈ p → x - y ∈ p := p.to_add_subgroup.sub_mem
@[simp] lemma neg_mem_iff : -x ∈ p ↔ x ∈ p := p.to_add_subgroup.neg_mem_iff
lemma add_mem_iff_left : y ∈ p → (x + y ∈ p ↔ x ∈ p) := p.to_add_subgroup.add_mem_cancel_right
lemma add_mem_iff_right : x ∈ p → (x + y ∈ p ↔ y ∈ p) := p.to_add_subgroup.add_mem_cancel_left
instance : has_neg p := ⟨λx, ⟨-x.1, neg_mem _ x.2⟩⟩
@[simp, norm_cast] lemma coe_neg (x : p) : ((-x : p) : M) = -x := rfl
instance : add_comm_group p :=
{ add := (+), zero := 0, neg := has_neg.neg, ..p.to_add_subgroup.to_add_comm_group }
@[simp, norm_cast] lemma coe_sub (x y : p) : (↑(x - y) : M) = ↑x - ↑y := rfl
end add_comm_group
section ordered_monoid
variables [semiring R]
/-- A submodule of an `ordered_add_comm_monoid` is an `ordered_add_comm_monoid`. -/
instance to_ordered_add_comm_monoid
{M} [ordered_add_comm_monoid M] [semimodule R M] (S : submodule R M) :
ordered_add_comm_monoid S :=
subtype.coe_injective.ordered_add_comm_monoid coe rfl (λ _ _, rfl)
/-- A submodule of a `linear_ordered_add_comm_monoid` is a `linear_ordered_add_comm_monoid`. -/
instance to_linear_ordered_add_comm_monoid
{M} [linear_ordered_add_comm_monoid M] [semimodule R M] (S : submodule R M) :
linear_ordered_add_comm_monoid S :=
subtype.coe_injective.linear_ordered_add_comm_monoid coe rfl (λ _ _, rfl)
/-- A submodule of an `ordered_cancel_add_comm_monoid` is an `ordered_cancel_add_comm_monoid`. -/
instance to_ordered_cancel_add_comm_monoid
{M} [ordered_cancel_add_comm_monoid M] [semimodule R M] (S : submodule R M) :
ordered_cancel_add_comm_monoid S :=
subtype.coe_injective.ordered_cancel_add_comm_monoid coe rfl (λ _ _, rfl)
/-- A submodule of a `linear_ordered_cancel_add_comm_monoid` is a
`linear_ordered_cancel_add_comm_monoid`. -/
instance to_linear_ordered_cancel_add_comm_monoid
{M} [linear_ordered_cancel_add_comm_monoid M] [semimodule R M] (S : submodule R M) :
linear_ordered_cancel_add_comm_monoid S :=
subtype.coe_injective.linear_ordered_cancel_add_comm_monoid coe rfl (λ _ _, rfl)
end ordered_monoid
section ordered_group
variables [ring R]
/-- A submodule of an `ordered_add_comm_group` is an `ordered_add_comm_group`. -/
instance to_ordered_add_comm_group
{M} [ordered_add_comm_group M] [semimodule R M] (S : submodule R M) :
ordered_add_comm_group S :=
subtype.coe_injective.ordered_add_comm_group coe rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl)
/-- A submodule of a `linear_ordered_add_comm_group` is a
`linear_ordered_add_comm_group`. -/
instance to_linear_ordered_add_comm_group
{M} [linear_ordered_add_comm_group M] [semimodule R M] (S : submodule R M) :
linear_ordered_add_comm_group S :=
subtype.coe_injective.linear_ordered_add_comm_group coe rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl)
end ordered_group
end submodule
namespace submodule
variables [division_ring S] [semiring R] [add_comm_monoid M] [semimodule R M]
variables [has_scalar S R] [semimodule S M] [is_scalar_tower S R M]
variables (p : submodule R M) {s : S} {x y : M}
theorem smul_mem_iff (s0 : s ≠ 0) : s • x ∈ p ↔ x ∈ p :=
p.to_sub_mul_action.smul_mem_iff s0
end submodule
/-- Subspace of a vector space. Defined to equal `submodule`. -/
abbreviation subspace (R : Type u) (M : Type v)
[field R] [add_comm_group M] [vector_space R M] :=
submodule R M
|
25d693a45a0d41156df1bb1270ac5715e2b40f6b | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/ring_theory/ideal/basic.lean | 9606078e05f10c66e847dcdc01560c672f673d5f | [
"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 | 31,765 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Mario Carneiro
-/
import algebra.associated
import linear_algebra.basic
import order.zorn
/-!
# Ideals over a ring
This file defines `ideal R`, the type of ideals over a commutative ring `R`.
## Implementation notes
`ideal R` is implemented using `submodule R R`, where `•` is interpreted as `*`.
## TODO
Support one-sided ideals, and ideals over non-commutative rings.
See `algebra.ring_quot` for quotients of non-commutative rings.
-/
universes u v w
variables {α : Type u} {β : Type v}
open set function
open_locale classical big_operators
/-- Ideal in a commutative ring is an additive subgroup `s` such that
`a * b ∈ s` whenever `b ∈ s`. -/
@[reducible] def ideal (R : Type u) [comm_ring R] := submodule R R
namespace ideal
variables [comm_ring α] (I : ideal α) {a b : α}
protected lemma zero_mem : (0 : α) ∈ I := I.zero_mem
protected lemma add_mem : a ∈ I → b ∈ I → a + b ∈ I := I.add_mem
lemma neg_mem_iff : -a ∈ I ↔ a ∈ I := I.neg_mem_iff
lemma add_mem_iff_left : b ∈ I → (a + b ∈ I ↔ a ∈ I) := I.add_mem_iff_left
lemma add_mem_iff_right : a ∈ I → (a + b ∈ I ↔ b ∈ I) := I.add_mem_iff_right
protected lemma sub_mem : a ∈ I → b ∈ I → a - b ∈ I := I.sub_mem
lemma mul_mem_left : b ∈ I → a * b ∈ I := I.smul_mem _
lemma mul_mem_right (h : a ∈ I) : a * b ∈ I := mul_comm b a ▸ I.mul_mem_left h
end ideal
variables {a b : α}
-- A separate namespace definition is needed because the variables were historically in a different order
namespace ideal
variables [comm_ring α] (I : ideal α)
@[ext] lemma ext {I J : ideal α} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J :=
submodule.ext h
theorem eq_top_of_unit_mem
(x y : α) (hx : x ∈ I) (h : y * x = 1) : I = ⊤ :=
eq_top_iff.2 $ λ z _, calc
z = z * (y * x) : by simp [h]
... = (z * y) * x : eq.symm $ mul_assoc z y x
... ∈ I : I.mul_mem_left hx
theorem eq_top_of_is_unit_mem {x} (hx : x ∈ I) (h : is_unit x) : I = ⊤ :=
let ⟨y, hy⟩ := is_unit_iff_exists_inv'.1 h in eq_top_of_unit_mem I x y hx hy
theorem eq_top_iff_one : I = ⊤ ↔ (1:α) ∈ I :=
⟨by rintro rfl; trivial,
λ h, eq_top_of_unit_mem _ _ 1 h (by simp)⟩
theorem ne_top_iff_one : I ≠ ⊤ ↔ (1:α) ∉ I :=
not_congr I.eq_top_iff_one
@[simp]
theorem unit_mul_mem_iff_mem {x y : α} (hy : is_unit y) : y * x ∈ I ↔ x ∈ I :=
begin
refine ⟨λ h, _, λ h, I.smul_mem y h⟩,
obtain ⟨y', hy'⟩ := is_unit_iff_exists_inv.1 hy,
have := I.smul_mem y' h,
rwa [smul_eq_mul, ← mul_assoc, mul_comm y' y, hy', one_mul] at this,
end
@[simp]
theorem mul_unit_mem_iff_mem {x y : α} (hy : is_unit y) : x * y ∈ I ↔ x ∈ I :=
mul_comm y x ▸ unit_mul_mem_iff_mem I hy
/-- The ideal generated by a subset of a ring -/
def span (s : set α) : ideal α := submodule.span α s
lemma subset_span {s : set α} : s ⊆ span s := submodule.subset_span
lemma span_le {s : set α} {I} : span s ≤ I ↔ s ⊆ I := submodule.span_le
lemma span_mono {s t : set α} : s ⊆ t → span s ≤ span t := submodule.span_mono
@[simp] lemma span_eq : span (I : set α) = I := submodule.span_eq _
@[simp] lemma span_singleton_one : span (1 : set α) = ⊤ :=
(eq_top_iff_one _).2 $ subset_span $ mem_singleton _
lemma mem_span_insert {s : set α} {x y} :
x ∈ span (insert y s) ↔ ∃ a (z ∈ span s), x = a * y + z := submodule.mem_span_insert
lemma mem_span_insert' {s : set α} {x y} :
x ∈ span (insert y s) ↔ ∃a, x + a * y ∈ span s := submodule.mem_span_insert'
lemma mem_span_singleton' {x y : α} :
x ∈ span ({y} : set α) ↔ ∃ a, a * y = x := submodule.mem_span_singleton
lemma mem_span_singleton {x y : α} :
x ∈ span ({y} : set α) ↔ y ∣ x :=
mem_span_singleton'.trans $ exists_congr $ λ _, by rw [eq_comm, mul_comm]
lemma span_singleton_le_span_singleton {x y : α} :
span ({x} : set α) ≤ span ({y} : set α) ↔ y ∣ x :=
span_le.trans $ singleton_subset_iff.trans mem_span_singleton
lemma span_singleton_eq_span_singleton {α : Type u} [integral_domain α] {x y : α} :
span ({x} : set α) = span ({y} : set α) ↔ associated x y :=
begin
rw [←dvd_dvd_iff_associated, le_antisymm_iff, and_comm],
apply and_congr;
rw span_singleton_le_span_singleton,
end
lemma span_eq_bot {s : set α} : span s = ⊥ ↔ ∀ x ∈ s, (x:α) = 0 := submodule.span_eq_bot
@[simp] lemma span_singleton_eq_bot {x} : span ({x} : set α) = ⊥ ↔ x = 0 :=
submodule.span_singleton_eq_bot
@[simp] lemma span_zero : span (0 : set α) = ⊥ := by rw [←set.singleton_zero, span_singleton_eq_bot]
lemma span_singleton_eq_top {x} : span ({x} : set α) = ⊤ ↔ is_unit x :=
by rw [is_unit_iff_dvd_one, ← span_singleton_le_span_singleton, singleton_one, span_singleton_one,
eq_top_iff]
lemma span_singleton_mul_right_unit {a : α} (h2 : is_unit a) (x : α) :
span ({x * a} : set α) = span {x} :=
begin
apply le_antisymm,
{ rw span_singleton_le_span_singleton, use a},
{ rw span_singleton_le_span_singleton, rw is_unit.mul_right_dvd h2}
end
lemma span_singleton_mul_left_unit {a : α} (h2 : is_unit a) (x : α) :
span ({a * x} : set α) = span {x} := by rw [mul_comm, span_singleton_mul_right_unit h2]
/--
The ideal generated by an arbitrary binary relation.
-/
def of_rel (r : α → α → Prop) : ideal α :=
submodule.span α { x | ∃ (a b) (h : r a b), x = a - b }
/-- An ideal `P` of a ring `R` is prime if `P ≠ R` and `xy ∈ P → x ∈ P ∨ y ∈ P` -/
@[class] def is_prime (I : ideal α) : Prop :=
I ≠ ⊤ ∧ ∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I
theorem is_prime.mem_or_mem {I : ideal α} (hI : I.is_prime) :
∀ {x y : α}, x * y ∈ I → x ∈ I ∨ y ∈ I := hI.2
theorem is_prime.mem_or_mem_of_mul_eq_zero {I : ideal α} (hI : I.is_prime)
{x y : α} (h : x * y = 0) : x ∈ I ∨ y ∈ I :=
hI.2 (h.symm ▸ I.zero_mem)
theorem is_prime.mem_of_pow_mem {I : ideal α} (hI : I.is_prime)
{r : α} (n : ℕ) (H : r^n ∈ I) : r ∈ I :=
begin
induction n with n ih,
{ exact (mt (eq_top_iff_one _).2 hI.1).elim H },
exact or.cases_on (hI.mem_or_mem H) id ih
end
theorem zero_ne_one_of_proper {I : ideal α} (h : I ≠ ⊤) : (0:α) ≠ 1 :=
λ hz, I.ne_top_iff_one.1 h $ hz ▸ I.zero_mem
theorem span_singleton_prime {p : α} (hp : p ≠ 0) :
is_prime (span ({p} : set α)) ↔ prime p :=
by simp [is_prime, prime, span_singleton_eq_top, hp, mem_span_singleton]
lemma bot_prime {R : Type*} [integral_domain R] : (⊥ : ideal R).is_prime :=
⟨λ h, one_ne_zero (by rwa [ideal.eq_top_iff_one, submodule.mem_bot] at h),
λ x y h, mul_eq_zero.mp (by simpa only [submodule.mem_bot] using h)⟩
/-- An ideal is maximal if it is maximal in the collection of proper ideals. -/
@[class] def is_maximal (I : ideal α) : Prop :=
I ≠ ⊤ ∧ ∀ J, I < J → J = ⊤
theorem is_maximal_iff {I : ideal α} : I.is_maximal ↔
(1:α) ∉ I ∧ ∀ (J : ideal α) x, I ≤ J → x ∉ I → x ∈ J → (1:α) ∈ J :=
and_congr I.ne_top_iff_one $ forall_congr $ λ J,
by rw [lt_iff_le_not_le]; exact
⟨λ H x h hx₁ hx₂, J.eq_top_iff_one.1 $
H ⟨h, not_subset.2 ⟨_, hx₂, hx₁⟩⟩,
λ H ⟨h₁, h₂⟩, let ⟨x, xJ, xI⟩ := not_subset.1 h₂ in
J.eq_top_iff_one.2 $ H x h₁ xI xJ⟩
theorem is_maximal.eq_of_le {I J : ideal α}
(hI : I.is_maximal) (hJ : J ≠ ⊤) (IJ : I ≤ J) : I = J :=
eq_iff_le_not_lt.2 ⟨IJ, λ h, hJ (hI.2 _ h)⟩
theorem is_maximal.exists_inv {I : ideal α}
(hI : I.is_maximal) {x} (hx : x ∉ I) : ∃ y, y * x - 1 ∈ I :=
begin
cases is_maximal_iff.1 hI with H₁ H₂,
rcases mem_span_insert'.1 (H₂ (span (insert x I)) x
(set.subset.trans (subset_insert _ _) subset_span)
hx (subset_span (mem_insert _ _))) with ⟨y, hy⟩,
rw [span_eq, ← neg_mem_iff, add_comm, neg_add', neg_mul_eq_neg_mul] at hy,
exact ⟨-y, hy⟩
end
theorem is_maximal.is_prime {I : ideal α} (H : I.is_maximal) : I.is_prime :=
⟨H.1, λ x y hxy, or_iff_not_imp_left.2 $ λ hx, begin
cases H.exists_inv hx with z hz,
have := I.mul_mem_left hz,
rw [mul_sub, mul_one, mul_comm, mul_assoc] at this,
exact I.neg_mem_iff.1 ((I.add_mem_iff_right $ I.mul_mem_left hxy).1 this)
end⟩
@[priority 100] -- see Note [lower instance priority]
instance is_maximal.is_prime' (I : ideal α) : ∀ [H : I.is_maximal], I.is_prime :=
is_maximal.is_prime
/-- Krull's theorem: if `I` is an ideal that is not the whole ring, then it is included in some
maximal ideal. -/
theorem exists_le_maximal (I : ideal α) (hI : I ≠ ⊤) :
∃ M : ideal α, M.is_maximal ∧ I ≤ M :=
begin
rcases zorn.zorn_partial_order₀ { J : ideal α | J ≠ ⊤ } _ I hI with ⟨M, M0, IM, h⟩,
{ refine ⟨M, ⟨M0, λ J hJ, by_contradiction $ λ J0, _⟩, IM⟩,
cases h J J0 (le_of_lt hJ), exact lt_irrefl _ hJ },
{ intros S SC cC I IS,
refine ⟨Sup S, λ H, _, λ _, le_Sup⟩,
obtain ⟨J, JS, J0⟩ : ∃ J ∈ S, (1 : α) ∈ J,
from (submodule.mem_Sup_of_directed ⟨I, IS⟩ cC.directed_on).1 ((eq_top_iff_one _).1 H),
exact SC JS ((eq_top_iff_one _).2 J0) }
end
/-- Krull's theorem: a nontrivial ring has a maximal ideal. -/
theorem exists_maximal [nontrivial α] : ∃ M : ideal α, M.is_maximal :=
let ⟨I, ⟨hI, _⟩⟩ := exists_le_maximal (⊥ : ideal α) submodule.bot_ne_top in ⟨I, hI⟩
/-- If P is not properly contained in any maximal ideal then it is not properly contained
in any proper ideal -/
lemma maximal_of_no_maximal {R : Type u} [comm_ring R] {P : ideal R}
(hmax : ∀ m : ideal R, P < m → ¬is_maximal m) (J : ideal R) (hPJ : P < J) : J = ⊤ :=
begin
by_contradiction hnonmax,
rcases exists_le_maximal J hnonmax with ⟨M, hM1, hM2⟩,
exact hmax M (lt_of_lt_of_le hPJ hM2) hM1,
end
theorem mem_span_pair {x y z : α} :
z ∈ span ({x, y} : set α) ↔ ∃ a b, a * x + b * y = z :=
by simp [mem_span_insert, mem_span_singleton', @eq_comm _ _ z]
lemma span_singleton_lt_span_singleton [integral_domain β] {x y : β} :
span ({x} : set β) < span ({y} : set β) ↔ dvd_not_unit y x :=
by rw [lt_iff_le_not_le, span_singleton_le_span_singleton, span_singleton_le_span_singleton,
dvd_and_not_dvd_iff]
lemma factors_decreasing [integral_domain β] (b₁ b₂ : β) (h₁ : b₁ ≠ 0) (h₂ : ¬ is_unit b₂) :
span ({b₁ * b₂} : set β) < span {b₁} :=
lt_of_le_not_le (ideal.span_le.2 $ singleton_subset_iff.2 $
ideal.mem_span_singleton.2 ⟨b₂, rfl⟩) $ λ h,
h₂ $ is_unit_of_dvd_one _ $ (mul_dvd_mul_iff_left h₁).1 $
by rwa [mul_one, ← ideal.span_singleton_le_span_singleton]
/-- The quotient `R/I` of a ring `R` by an ideal `I`. -/
def quotient (I : ideal α) := I.quotient
namespace quotient
variables {I} {x y : α}
instance (I : ideal α) : has_one I.quotient := ⟨submodule.quotient.mk 1⟩
instance (I : ideal α) : has_mul I.quotient :=
⟨λ a b, quotient.lift_on₂' a b (λ a b, submodule.quotient.mk (a * b)) $
λ a₁ a₂ b₁ b₂ h₁ h₂, quot.sound $ begin
refine calc a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ : _
... ∈ I : I.add_mem (I.mul_mem_left h₁) (I.mul_mem_right h₂),
rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁]
end⟩
instance (I : ideal α) : comm_ring I.quotient :=
{ mul := (*),
one := 1,
mul_assoc := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg submodule.quotient.mk (mul_assoc a b c),
mul_comm := λ a b, quotient.induction_on₂' a b $
λ a b, congr_arg submodule.quotient.mk (mul_comm a b),
one_mul := λ a, quotient.induction_on' a $
λ a, congr_arg submodule.quotient.mk (one_mul a),
mul_one := λ a, quotient.induction_on' a $
λ a, congr_arg submodule.quotient.mk (mul_one a),
left_distrib := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg submodule.quotient.mk (left_distrib a b c),
right_distrib := λ a b c, quotient.induction_on₃' a b c $
λ a b c, congr_arg submodule.quotient.mk (right_distrib a b c),
..submodule.quotient.add_comm_group I }
/-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/
def mk (I : ideal α) : α →+* I.quotient :=
⟨λ a, submodule.quotient.mk a, rfl, λ _ _, rfl, rfl, λ _ _, rfl⟩
instance : inhabited (quotient I) := ⟨mk I 37⟩
protected theorem eq : mk I x = mk I y ↔ x - y ∈ I := submodule.quotient.eq I
@[simp] theorem mk_eq_mk (x : α) : (submodule.quotient.mk x : quotient I) = mk I x := rfl
lemma eq_zero_iff_mem {I : ideal α} : mk I a = 0 ↔ a ∈ I :=
by conv {to_rhs, rw ← sub_zero a }; exact quotient.eq'
theorem zero_eq_one_iff {I : ideal α} : (0 : I.quotient) = 1 ↔ I = ⊤ :=
eq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm
theorem zero_ne_one_iff {I : ideal α} : (0 : I.quotient) ≠ 1 ↔ I ≠ ⊤ :=
not_congr zero_eq_one_iff
protected theorem nontrivial {I : ideal α} (hI : I ≠ ⊤) : nontrivial I.quotient :=
⟨⟨0, 1, zero_ne_one_iff.2 hI⟩⟩
lemma mk_surjective : function.surjective (mk I) :=
λ y, quotient.induction_on' y (λ x, exists.intro x rfl)
instance (I : ideal α) [hI : I.is_prime] : integral_domain I.quotient :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b,
quotient.induction_on₂' a b $ λ a b hab,
(hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim
(or.inl ∘ eq_zero_iff_mem.2)
(or.inr ∘ eq_zero_iff_mem.2),
.. quotient.comm_ring I,
.. quotient.nontrivial hI.1 }
lemma is_integral_domain_iff_prime (I : ideal α) : is_integral_domain I.quotient ↔ I.is_prime :=
⟨ λ ⟨h1, h2, h3⟩, ⟨zero_ne_one_iff.1 $ @zero_ne_one _ _ ⟨h1⟩, λ x y h,
by { simp only [←eq_zero_iff_mem, (mk I).map_mul] at ⊢ h, exact h3 _ _ h}⟩,
λ h, by exactI integral_domain.to_is_integral_domain I.quotient⟩
lemma exists_inv {I : ideal α} [hI : I.is_maximal] :
∀ {a : I.quotient}, a ≠ 0 → ∃ b : I.quotient, a * b = 1 :=
begin
rintro ⟨a⟩ h,
cases hI.exists_inv (mt eq_zero_iff_mem.2 h) with b hb,
rw [mul_comm] at hb,
exact ⟨mk _ b, quot.sound hb⟩
end
/-- quotient by maximal ideal is a field. def rather than instance, since users will have
computable inverses in some applications -/
protected noncomputable def field (I : ideal α) [hI : I.is_maximal] : field I.quotient :=
{ inv := λ a, if ha : a = 0 then 0 else classical.some (exists_inv ha),
mul_inv_cancel := λ a (ha : a ≠ 0), show a * dite _ _ _ = _,
by rw dif_neg ha;
exact classical.some_spec (exists_inv ha),
inv_zero := dif_pos rfl,
..quotient.integral_domain I }
/-- If the quotient by an ideal is a field, then the ideal is maximal. -/
theorem maximal_of_is_field (I : ideal α)
(hqf : is_field I.quotient) : I.is_maximal :=
begin
apply ideal.is_maximal_iff.2,
split,
{ intro h,
rcases hqf.exists_pair_ne with ⟨⟨x⟩, ⟨y⟩, hxy⟩,
exact hxy (ideal.quotient.eq.2 (mul_one (x - y) ▸ I.mul_mem_left h)) },
{ intros J x hIJ hxnI hxJ,
rcases hqf.mul_inv_cancel (mt ideal.quotient.eq_zero_iff_mem.1 hxnI) with ⟨⟨y⟩, hy⟩,
rw [← zero_add (1 : α), ← sub_self (x * y), sub_add],
refine J.sub_mem (J.mul_mem_right hxJ) (hIJ (ideal.quotient.eq.1 hy)) }
end
/-- The quotient of a ring by an ideal is a field iff the ideal is maximal. -/
theorem maximal_ideal_iff_is_field_quotient (I : ideal α) :
I.is_maximal ↔ is_field I.quotient :=
⟨λ h, @field.to_is_field I.quotient (@ideal.quotient.field _ _ I h),
λ h, maximal_of_is_field I h⟩
variable [comm_ring β]
/-- Given a ring homomorphism `f : α →+* β` sending all elements of an ideal to zero,
lift it to the quotient by this ideal. -/
def lift (S : ideal α) (f : α →+* β) (H : ∀ (a : α), a ∈ S → f a = 0) :
quotient S →+* β :=
{ to_fun := λ x, quotient.lift_on' x f $ λ (a b) (h : _ ∈ _),
eq_of_sub_eq_zero $ by rw [← f.map_sub, H _ h],
map_one' := f.map_one,
map_zero' := f.map_zero,
map_add' := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ f.map_add,
map_mul' := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ f.map_mul }
@[simp] lemma lift_mk (S : ideal α) (f : α →+* β) (H : ∀ (a : α), a ∈ S → f a = 0) :
lift S f H (mk S a) = f a := rfl
end quotient
section lattice
variables {R : Type u} [comm_ring R]
lemma mem_sup_left {S T : ideal R} : ∀ {x : R}, x ∈ S → x ∈ S ⊔ T :=
show S ≤ S ⊔ T, from le_sup_left
lemma mem_sup_right {S T : ideal R} : ∀ {x : R}, x ∈ T → x ∈ S ⊔ T :=
show T ≤ S ⊔ T, from le_sup_right
lemma mem_supr_of_mem {ι : Type*} {S : ι → ideal R} (i : ι) :
∀ {x : R}, x ∈ S i → x ∈ supr S :=
show S i ≤ supr S, from le_supr _ _
lemma mem_Sup_of_mem {S : set (ideal R)} {s : ideal R}
(hs : s ∈ S) : ∀ {x : R}, x ∈ s → x ∈ Sup S :=
show s ≤ Sup S, from le_Sup hs
theorem mem_Inf {s : set (ideal R)} {x : R} :
x ∈ Inf s ↔ ∀ ⦃I⦄, I ∈ s → x ∈ I :=
⟨λ hx I his, hx I ⟨I, infi_pos his⟩, λ H I ⟨J, hij⟩, hij ▸ λ S ⟨hj, hS⟩, hS ▸ H hj⟩
@[simp] lemma mem_inf {I J : ideal R} {x : R} : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J := iff.rfl
@[simp] lemma mem_infi {ι : Type*} {I : ι → ideal R} {x : R} : x ∈ infi I ↔ ∀ i, x ∈ I i :=
submodule.mem_infi _
@[simp] lemma mem_bot {x : R} : x ∈ (⊥ : ideal R) ↔ x = 0 :=
submodule.mem_bot _
end lattice
/-- All ideals in a field are trivial. -/
lemma eq_bot_or_top {K : Type u} [field K] (I : ideal K) :
I = ⊥ ∨ I = ⊤ :=
begin
rw or_iff_not_imp_right,
change _ ≠ _ → _,
rw ideal.ne_top_iff_one,
intro h1,
rw eq_bot_iff,
intros r hr,
by_cases H : r = 0, {simpa},
simpa [H, h1] using submodule.smul_mem I r⁻¹ hr,
end
lemma eq_bot_of_prime {K : Type u} [field K] (I : ideal K) [h : I.is_prime] :
I = ⊥ :=
or_iff_not_imp_right.mp I.eq_bot_or_top h.1
lemma bot_is_maximal {K : Type u} [field K] : is_maximal (⊥ : ideal K) :=
⟨λ h, absurd ((eq_top_iff_one (⊤ : ideal K)).mp rfl) (by rw ← h; simp),
λ I hI, or_iff_not_imp_left.mp (eq_bot_or_top I) (ne_of_gt hI)⟩
section pi
variables (ι : Type v)
/-- `I^n` as an ideal of `R^n`. -/
def pi : ideal (ι → α) :=
{ carrier := { x | ∀ i, x i ∈ I },
zero_mem' := λ i, submodule.zero_mem _,
add_mem' := λ a b ha hb i, submodule.add_mem _ (ha i) (hb i),
smul_mem' := λ a b hb i, ideal.mul_mem_left _ (hb i) }
lemma mem_pi (x : ι → α) : x ∈ I.pi ι ↔ ∀ i, x i ∈ I := iff.rfl
/-- `R^n/I^n` is a `R/I`-module. -/
instance module_pi : module (I.quotient) (I.pi ι).quotient :=
begin
refine { smul := λ c m, quotient.lift_on₂' c m (λ r m, submodule.quotient.mk $ r • m) _, .. },
{ intros c₁ m₁ c₂ m₂ hc hm,
change c₁ - c₂ ∈ I at hc,
change m₁ - m₂ ∈ (I.pi ι) at hm,
apply ideal.quotient.eq.2,
have : c₁ • (m₂ - m₁) ∈ I.pi ι,
{ rw ideal.mem_pi,
intro i,
simp only [smul_eq_mul, pi.smul_apply, pi.sub_apply],
apply ideal.mul_mem_left,
rw ←ideal.neg_mem_iff,
simpa only [neg_sub] using hm i },
rw [←ideal.add_mem_iff_left (I.pi ι) this, sub_eq_add_neg, add_comm, ←add_assoc, ←smul_add,
sub_add_cancel, ←sub_eq_add_neg, ←sub_smul, ideal.mem_pi],
exact λ i, ideal.mul_mem_right _ hc },
all_goals { rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ <|> rintro ⟨a⟩,
simp only [(•), submodule.quotient.quot_mk_eq_mk, ideal.quotient.mk_eq_mk],
change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,
congr' with i, simp [mul_assoc, mul_add, add_mul] }
end
/-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/
noncomputable def pi_quot_equiv : (I.pi ι).quotient ≃ₗ[I.quotient] (ι → I.quotient) :=
{ to_fun := λ x, quotient.lift_on' x (λ f i, ideal.quotient.mk I (f i)) $
λ a b hab, funext (λ i, ideal.quotient.eq.2 (hab i)),
map_add' := by { rintros ⟨_⟩ ⟨_⟩, refl },
map_smul' := by { rintros ⟨_⟩ ⟨_⟩, refl },
inv_fun := λ x, ideal.quotient.mk (I.pi ι) $ λ i, quotient.out' (x i),
left_inv :=
begin
rintro ⟨x⟩,
exact ideal.quotient.eq.2 (λ i, ideal.quotient.eq.1 (quotient.out_eq' _))
end,
right_inv :=
begin
intro x,
ext i,
obtain ⟨r, hr⟩ := @quot.exists_rep _ _ (x i),
simp_rw ←hr,
convert quotient.out_eq' _
end }
/-- If `f : R^n → R^m` is an `R`-linear map and `I ⊆ R` is an ideal, then the image of `I^n` is
contained in `I^m`. -/
lemma map_pi {ι} [fintype ι] {ι' : Type w} (x : ι → α) (hi : ∀ i, x i ∈ I)
(f : (ι → α) →ₗ[α] (ι' → α)) (i : ι') : f x i ∈ I :=
begin
rw pi_eq_sum_univ x,
simp only [finset.sum_apply, smul_eq_mul, linear_map.map_sum, pi.smul_apply, linear_map.map_smul],
exact submodule.sum_mem _ (λ j hj, ideal.mul_mem_right _ (hi j))
end
end pi
end ideal
namespace ring
variables {R : Type*} [comm_ring R]
lemma not_is_field_of_subsingleton {R : Type*} [ring R] [subsingleton R] : ¬ is_field R :=
λ ⟨⟨x, y, hxy⟩, _, _⟩, hxy (subsingleton.elim x y)
lemma exists_not_is_unit_of_not_is_field [nontrivial R] (hf : ¬ is_field R) :
∃ x ≠ (0 : R), ¬ is_unit x :=
begin
have : ¬ _ := λ h, hf ⟨exists_pair_ne R, mul_comm, h⟩,
simp_rw is_unit_iff_exists_inv,
push_neg at ⊢ this,
obtain ⟨x, hx, not_unit⟩ := this,
exact ⟨x, hx, not_unit⟩
end
lemma not_is_field_iff_exists_ideal_bot_lt_and_lt_top [nontrivial R] :
¬ is_field R ↔ ∃ I : ideal R, ⊥ < I ∧ I < ⊤ :=
begin
split,
{ intro h,
obtain ⟨x, nz, nu⟩ := exists_not_is_unit_of_not_is_field h,
use ideal.span {x},
rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top],
exact ⟨mt ideal.span_singleton_eq_bot.mp nz, mt ideal.span_singleton_eq_top.mp nu⟩ },
{ rintros ⟨I, bot_lt, lt_top⟩ hf,
obtain ⟨x, mem, ne_zero⟩ := submodule.exists_of_lt bot_lt,
rw submodule.mem_bot at ne_zero,
obtain ⟨y, hy⟩ := hf.mul_inv_cancel ne_zero,
rw [lt_top_iff_ne_top, ne.def, ideal.eq_top_iff_one, ← hy] at lt_top,
exact lt_top (ideal.mul_mem_right _ mem), }
end
lemma not_is_field_iff_exists_prime [nontrivial R] :
¬ is_field R ↔ ∃ p : ideal R, p ≠ ⊥ ∧ p.is_prime :=
not_is_field_iff_exists_ideal_bot_lt_and_lt_top.trans
⟨λ ⟨I, bot_lt, lt_top⟩, let ⟨p, hp, le_p⟩ := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top) in
⟨p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.is_prime⟩,
λ ⟨p, ne_bot, prime⟩, ⟨p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr prime.1⟩⟩
end ring
namespace ideal
/-- Maximal ideals in a non-field are nontrivial. -/
variables {R : Type u} [comm_ring R] [nontrivial R]
lemma bot_lt_of_maximal (M : ideal R) [hm : M.is_maximal] (non_field : ¬ is_field R) : ⊥ < M :=
begin
rcases (ring.not_is_field_iff_exists_ideal_bot_lt_and_lt_top.1 non_field)
with ⟨I, Ibot, Itop⟩,
split, finish,
intro mle,
apply @irrefl _ (<) _ (⊤ : ideal R),
have : M = ⊥ := eq_bot_iff.mpr mle,
rw this at *,
rwa hm.2 I Ibot at Itop,
end
end ideal
/-- The set of non-invertible elements of a monoid. -/
def nonunits (α : Type u) [monoid α] : set α := { a | ¬is_unit a }
@[simp] theorem mem_nonunits_iff [comm_monoid α] : a ∈ nonunits α ↔ ¬ is_unit a := iff.rfl
theorem mul_mem_nonunits_right [comm_monoid α] :
b ∈ nonunits α → a * b ∈ nonunits α :=
mt is_unit_of_mul_is_unit_right
theorem mul_mem_nonunits_left [comm_monoid α] :
a ∈ nonunits α → a * b ∈ nonunits α :=
mt is_unit_of_mul_is_unit_left
theorem zero_mem_nonunits [semiring α] : 0 ∈ nonunits α ↔ (0:α) ≠ 1 :=
not_congr is_unit_zero_iff
@[simp] theorem one_not_mem_nonunits [monoid α] : (1:α) ∉ nonunits α :=
not_not_intro is_unit_one
theorem coe_subset_nonunits [comm_ring α] {I : ideal α} (h : I ≠ ⊤) :
(I : set α) ⊆ nonunits α :=
λ x hx hu, h $ I.eq_top_of_is_unit_mem hx hu
lemma exists_max_ideal_of_mem_nonunits [comm_ring α] (h : a ∈ nonunits α) :
∃ I : ideal α, I.is_maximal ∧ a ∈ I :=
begin
have : ideal.span ({a} : set α) ≠ ⊤,
{ intro H, rw ideal.span_singleton_eq_top at H, contradiction },
rcases ideal.exists_le_maximal _ this with ⟨I, Imax, H⟩,
use [I, Imax], apply H, apply ideal.subset_span, exact set.mem_singleton a
end
/-- A commutative ring is local if it has a unique maximal ideal. Note that
`local_ring` is a predicate. -/
class local_ring (α : Type u) [comm_ring α] extends nontrivial α : Prop :=
(is_local : ∀ (a : α), (is_unit a) ∨ (is_unit (1 - a)))
namespace local_ring
variables [comm_ring α] [local_ring α]
lemma is_unit_or_is_unit_one_sub_self (a : α) :
(is_unit a) ∨ (is_unit (1 - a)) :=
is_local a
lemma is_unit_of_mem_nonunits_one_sub_self (a : α) (h : (1 - a) ∈ nonunits α) :
is_unit a :=
or_iff_not_imp_right.1 (is_local a) h
lemma is_unit_one_sub_self_of_mem_nonunits (a : α) (h : a ∈ nonunits α) :
is_unit (1 - a) :=
or_iff_not_imp_left.1 (is_local a) h
lemma nonunits_add {x y} (hx : x ∈ nonunits α) (hy : y ∈ nonunits α) :
x + y ∈ nonunits α :=
begin
rintros ⟨u, hu⟩,
apply hy,
suffices : is_unit ((↑u⁻¹ : α) * y),
{ rcases this with ⟨s, hs⟩,
use u * s,
convert congr_arg (λ z, (u : α) * z) hs,
rw ← mul_assoc, simp },
rw show (↑u⁻¹ * y) = (1 - ↑u⁻¹ * x),
{ rw eq_sub_iff_add_eq,
replace hu := congr_arg (λ z, (↑u⁻¹ : α) * z) hu.symm,
simpa [mul_add, add_comm] using hu },
apply is_unit_one_sub_self_of_mem_nonunits,
exact mul_mem_nonunits_right hx
end
variable (α)
/-- The ideal of elements that are not units. -/
def maximal_ideal : ideal α :=
{ carrier := nonunits α,
zero_mem' := zero_mem_nonunits.2 $ zero_ne_one,
add_mem' := λ x y hx hy, nonunits_add hx hy,
smul_mem' := λ a x, mul_mem_nonunits_right }
instance maximal_ideal.is_maximal : (maximal_ideal α).is_maximal :=
begin
rw ideal.is_maximal_iff,
split,
{ intro h, apply h, exact is_unit_one },
{ intros I x hI hx H,
erw not_not at hx,
rcases hx with ⟨u,rfl⟩,
simpa using I.smul_mem ↑u⁻¹ H }
end
lemma maximal_ideal_unique :
∃! I : ideal α, I.is_maximal :=
⟨maximal_ideal α, maximal_ideal.is_maximal α,
λ I hI, hI.eq_of_le (maximal_ideal.is_maximal α).1 $
λ x hx, hI.1 ∘ I.eq_top_of_is_unit_mem hx⟩
variable {α}
lemma eq_maximal_ideal {I : ideal α} (hI : I.is_maximal) : I = maximal_ideal α :=
unique_of_exists_unique (maximal_ideal_unique α) hI $ maximal_ideal.is_maximal α
lemma le_maximal_ideal {J : ideal α} (hJ : J ≠ ⊤) : J ≤ maximal_ideal α :=
begin
rcases ideal.exists_le_maximal J hJ with ⟨M, hM1, hM2⟩,
rwa ←eq_maximal_ideal hM1
end
@[simp] lemma mem_maximal_ideal (x) :
x ∈ maximal_ideal α ↔ x ∈ nonunits α := iff.rfl
end local_ring
lemma local_of_nonunits_ideal [comm_ring α] (hnze : (0:α) ≠ 1)
(h : ∀ x y ∈ nonunits α, x + y ∈ nonunits α) : local_ring α :=
{ exists_pair_ne := ⟨0, 1, hnze⟩,
is_local := λ x, or_iff_not_imp_left.mpr $ λ hx,
begin
by_contra H,
apply h _ _ hx H,
simp [-sub_eq_add_neg, add_sub_cancel'_right]
end }
lemma local_of_unique_max_ideal [comm_ring α] (h : ∃! I : ideal α, I.is_maximal) :
local_ring α :=
local_of_nonunits_ideal
(let ⟨I, Imax, _⟩ := h in (λ (H : 0 = 1), Imax.1 $ I.eq_top_iff_one.2 $ H ▸ I.zero_mem))
$ λ x y hx hy H,
let ⟨I, Imax, Iuniq⟩ := h in
let ⟨Ix, Ixmax, Hx⟩ := exists_max_ideal_of_mem_nonunits hx in
let ⟨Iy, Iymax, Hy⟩ := exists_max_ideal_of_mem_nonunits hy in
have xmemI : x ∈ I, from ((Iuniq Ix Ixmax) ▸ Hx),
have ymemI : y ∈ I, from ((Iuniq Iy Iymax) ▸ Hy),
Imax.1 $ I.eq_top_of_is_unit_mem (I.add_mem xmemI ymemI) H
lemma local_of_unique_nonzero_prime (R : Type u) [comm_ring R]
(h : ∃! P : ideal R, P ≠ ⊥ ∧ ideal.is_prime P) : local_ring R :=
local_of_unique_max_ideal begin
rcases h with ⟨P, ⟨hPnonzero, hPnot_top, _⟩, hPunique⟩,
refine ⟨P, ⟨hPnot_top, _⟩, λ M hM, hPunique _ ⟨_, ideal.is_maximal.is_prime hM⟩⟩,
{ refine ideal.maximal_of_no_maximal (λ M hPM hM, ne_of_lt hPM _),
exact (hPunique _ ⟨ne_bot_of_gt hPM, ideal.is_maximal.is_prime hM⟩).symm },
{ rintro rfl,
exact hPnot_top (hM.2 P (bot_lt_iff_ne_bot.2 hPnonzero)) },
end
lemma local_of_surjective {A B : Type*} [comm_ring A] [local_ring A] [comm_ring B] [nontrivial B]
(f : A →+* B) (hf : function.surjective f) :
local_ring B :=
{ is_local :=
begin
intros b,
obtain ⟨a, rfl⟩ := hf b,
apply (local_ring.is_unit_or_is_unit_one_sub_self a).imp f.is_unit_map _,
rw [← f.map_one, ← f.map_sub],
apply f.is_unit_map,
end,
.. ‹nontrivial B› }
/-- A local ring homomorphism is a homomorphism between local rings
such that the image of the maximal ideal of the source is contained within
the maximal ideal of the target. -/
class is_local_ring_hom [semiring α] [semiring β] (f : α →+* β) : Prop :=
(map_nonunit : ∀ a, is_unit (f a) → is_unit a)
instance is_local_ring_hom_id (A : Type*) [semiring A] : is_local_ring_hom (ring_hom.id A) :=
{ map_nonunit := λ a, id }
@[simp] lemma is_unit_map_iff {A B : Type*} [semiring A] [semiring B] (f : A →+* B)
[is_local_ring_hom f] (a) :
is_unit (f a) ↔ is_unit a :=
⟨is_local_ring_hom.map_nonunit a, f.is_unit_map⟩
instance is_local_ring_hom_comp {A B C : Type*} [semiring A] [semiring B] [semiring C]
(g : B →+* C) (f : A →+* B) [is_local_ring_hom g] [is_local_ring_hom f] :
is_local_ring_hom (g.comp f) :=
{ map_nonunit := λ a, is_local_ring_hom.map_nonunit a ∘ is_local_ring_hom.map_nonunit (f a) }
@[simp] lemma is_unit_of_map_unit [semiring α] [semiring β] (f : α →+* β) [is_local_ring_hom f]
(a) (h : is_unit (f a)) : is_unit a :=
is_local_ring_hom.map_nonunit a h
theorem of_irreducible_map [semiring α] [semiring β] (f : α →+* β) [h : is_local_ring_hom f] {x : α}
(hfx : irreducible (f x)) : irreducible x :=
⟨λ h, hfx.1 $ is_unit.map f.to_monoid_hom h, λ p q hx, let ⟨H⟩ := h in
or.imp (H p) (H q) $ hfx.2 _ _ $ f.map_mul p q ▸ congr_arg f hx⟩
section
open local_ring
variables [comm_ring α] [local_ring α] [comm_ring β] [local_ring β]
variables (f : α →+* β) [is_local_ring_hom f]
lemma map_nonunit (a) (h : a ∈ maximal_ideal α) : f a ∈ maximal_ideal β :=
λ H, h $ is_unit_of_map_unit f a H
end
namespace local_ring
variables [comm_ring α] [local_ring α] [comm_ring β] [local_ring β]
variable (α)
/-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/
def residue_field := (maximal_ideal α).quotient
noncomputable instance residue_field.field : field (residue_field α) :=
ideal.quotient.field (maximal_ideal α)
noncomputable instance : inhabited (residue_field α) := ⟨37⟩
/-- The quotient map from a local ring to its residue field. -/
def residue : α →+* (residue_field α) :=
ideal.quotient.mk _
namespace residue_field
variables {α β}
/-- The map on residue fields induced by a local homomorphism between local rings -/
noncomputable def map (f : α →+* β) [is_local_ring_hom f] :
residue_field α →+* residue_field β :=
ideal.quotient.lift (maximal_ideal α) ((ideal.quotient.mk _).comp f) $
λ a ha,
begin
erw ideal.quotient.eq_zero_iff_mem,
exact map_nonunit f a ha
end
end residue_field
end local_ring
namespace field
variables [field α]
@[priority 100] -- see Note [lower instance priority]
instance : local_ring α :=
{ is_local := λ a,
if h : a = 0
then or.inr (by rw [h, sub_zero]; exact is_unit_one)
else or.inl $ is_unit_of_mul_eq_one a a⁻¹ $ div_self h }
end field
|
eb81e0f5e71fed2e6a6ed256a76d234b1acc753f | 6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf | /src/game/world10/level1.lean | bb7c9ff34dcd1fc2819d3636a63aadc3e6ce39fd | [
"Apache-2.0"
] | permissive | arolihas/natural_number_game | 4f0c93feefec93b8824b2b96adff8b702b8b43ce | 8e4f7b4b42888a3b77429f90cce16292bd288138 | refs/heads/master | 1,621,872,426,808 | 1,586,270,467,000 | 1,586,270,467,000 | 253,648,466 | 0 | 0 | null | 1,586,219,694,000 | 1,586,219,694,000 | null | UTF-8 | Lean | false | false | 3,508 | lean | import mynat.le -- import definition of ≤
import game.world9.level4 -- hide
import game.world4.level8 -- hide
namespace mynat -- hide
/- Axiom : le_iff_exists_add (a b : mynat)
a ≤ b ↔ ∃ (c : mynat), b = a + c
-/
/- Tactic : use
## Summary
`use` works on the goal. If your goal is `⊢ ∃ c : mynat, 1 + x = x + c`
then `use 1` will turn the goal into `⊢ 1 + x = x + 1`, and the rather
more unwise `use 0` will turn it into the impossible-to-prove
`⊢ 1 + x = x + 0`.
## Details
`use` is a tactic which works on goals of the form `⊢ ∃ c, P(c)` where
`P(c)` is some proposition which depends on `c`. With a goal of this
form, `use 0` will turn the goal into `⊢ P(0)`, `use x + y` (assuming
`x` and `y` are natural numbers in your local context) will turn
the goal into `P(x + y)` and so on.
-/
-- World name : Inequality world
/-
# Inequality world.
A new import, giving us a new definition. If `a` and `b` are naturals,
`a ≤ b` is *defined* to mean
`∃ (c : mynat), b = a + c`
The upside-down E means "there exists". So in words, $a\le b$
if and only if there exists a natural $c$ such that $b=a+c$.
If you really want to change an `a ≤ b` to `∃ c, b = a + c` then
you can do so with `rw le_iff_exists_add`:
```
le_iff_exists_add (a b : mynat) :
a ≤ b ↔ ∃ (c : mynat), b = a + c
```
But because `a ≤ b` is *defined as* `∃ (c : mynat), b = a + c`, you
do not need to `rw le_iff_exists_add`, you can just pretend when you see `a ≤ b`
that it says `∃ (c : mynat), b = a + c`. You will see a concrete
example of this below.
A new construction like `∃` means that we need to learn how to manipulate it.
There are two situations. Firstly we need to know how to solve a goal
of the form `⊢ ∃ c, ...`, and secondly we need to know how to use a hypothesis
of the form `∃ c, ...`.
## Level 1: the `use` tactic.
The goal below is to prove $x\le 1+x$ for any natural number $x$.
First let's turn the goal explicitly into an existence problem with
`rw le_iff_exists_add,`
and now the goal has become `∃ c : mynat, 1 + x = x + c`. Clearly
this statement is true, and the proof is that $c=1$ will work (we also
need the fact that addition is commutative, but we proved that a long
time ago). How do we make progress with this goal?
The `use` tactic can be used on goals of the form `∃ c, ...`. The idea
is that we choose which natural number we want to use, and then we use it.
So try
`use 1,`
and now the goal becomes `⊢ 1 + x = x + 1`. You can solve this by
`exact add_comm 1 x`, or if you are lazy you can just use the `ring` tactic,
which is a powerful AI which will solve any equality in algebra which can
be proved using the standard rules of addition and multiplication. Now
look at your proof. We're going to remove a line.
## Important
An important time-saver here is to note that because `a ≤ b` is *defined*
as `∃ c : mynat, b = a + c`, you *do not need to write* `rw le_iff_exists_add`.
The `use` tactic will work directly on a goal of the form `a ≤ b`. Just
use the difference `b - a` (note that we have not defined subtraction so
this does not formally make sense, but you can do the calculation in your head).
If you have written `rw le_iff_exists_add` below, then just put two minus signs `--`
before it and comment it out. See that the proof still compiles.
-/
/- Lemma : no-side-bar
If $x$ is a natural number, then $x\le 1+x$.
-/
lemma one_add_le_self (x : mynat) : x ≤ 1 + x :=
begin
end
end mynat -- hide
|
486510c054c0898ab0a9a66b464897048655b804 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/data/zmod/basic.lean | c881069fd70fd8470ebe9a44ea6de3bcd0a9b62e | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 32,598 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import algebra.char_p.basic
import ring_theory.ideal.operations
import tactic.fin_cases
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `zmod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
* `val_min_abs` returns the integer closest to zero in the equivalence class.
* A coercion `cast` is defined from `zmod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
namespace fin
/-!
## Ring structure on `fin n`
We define a commutative ring structure on `fin n`, but we do not register it as instance.
Afterwords, when we define `zmod n` in terms of `fin n`, we use these definitions
to register the ring structure on `zmod n` as type class instance.
-/
open nat.modeq int
/-- Multiplicative commutative semigroup structure on `fin (n+1)`. -/
instance (n : ℕ) : comm_semigroup (fin (n+1)) :=
{ mul_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc ((a * b) % (n+1) * c) ≡ a * b * c [MOD (n+1)] : (nat.mod_modeq _ _).mul_right _
... ≡ a * (b * c) [MOD (n+1)] : by rw mul_assoc
... ≡ a * (b * c % (n+1)) [MOD (n+1)] : (nat.mod_modeq _ _).symm.mul_left _),
mul_comm := λ ⟨a, _⟩ ⟨b, _⟩,
fin.eq_of_veq (show (a * b) % (n+1) = (b * a) % (n+1), by rw mul_comm),
..fin.has_mul }
private lemma left_distrib_aux (n : ℕ) : ∀ a b c : fin (n+1), a * (b + c) = a * b + a * c :=
λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc a * ((b + c) % (n+1)) ≡ a * (b + c) [MOD (n+1)] : (nat.mod_modeq _ _).mul_left _
... ≡ a * b + a * c [MOD (n+1)] : by rw mul_add
... ≡ (a * b) % (n+1) + (a * c) % (n+1) [MOD (n+1)] :
(nat.mod_modeq _ _).symm.add (nat.mod_modeq _ _).symm)
/-- Commutative ring structure on `fin (n+1)`. -/
instance (n : ℕ) : comm_ring (fin (n+1)) :=
{ one_mul := fin.one_mul,
mul_one := fin.mul_one,
left_distrib := left_distrib_aux n,
right_distrib := λ a b c, by rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm]; refl,
..fin.has_one,
..fin.add_comm_group n,
..fin.comm_semigroup n }
end fin
/-- The integers modulo `n : ℕ`. -/
def zmod : ℕ → Type
| 0 := ℤ
| (n+1) := fin (n+1)
namespace zmod
instance fintype : Π (n : ℕ) [fact (0 < n)], fintype (zmod n)
| 0 h := false.elim $ nat.not_lt_zero 0 h.1
| (n+1) _ := fin.fintype (n+1)
@[simp] lemma card (n : ℕ) [fact (0 < n)] : fintype.card (zmod n) = n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 (fact.out _) },
{ exact fintype.card_fin (n+1) }
end
instance decidable_eq : Π (n : ℕ), decidable_eq (zmod n)
| 0 := int.decidable_eq
| (n+1) := fin.decidable_eq _
instance has_repr : Π (n : ℕ), has_repr (zmod n)
| 0 := int.has_repr
| (n+1) := fin.has_repr _
instance comm_ring : Π (n : ℕ), comm_ring (zmod n)
| 0 := int.comm_ring
| (n+1) := fin.comm_ring n
instance inhabited (n : ℕ) : inhabited (zmod n) := ⟨0⟩
/-- `val a` is a natural number defined as:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
See `zmod.val_min_abs` for a variant that takes values in the integers.
-/
def val : Π {n : ℕ}, zmod n → ℕ
| 0 := int.nat_abs
| (n+1) := (coe : fin (n + 1) → ℕ)
lemma val_lt {n : ℕ} [fact (0 < n)] (a : zmod n) : a.val < n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 (fact.out _) },
exact fin.is_lt a
end
lemma val_le {n : ℕ} [fact (0 < n)] (a : zmod n) : a.val ≤ n :=
a.val_lt.le
@[simp] lemma val_zero : ∀ {n}, (0 : zmod n).val = 0
| 0 := rfl
| (n+1) := rfl
@[simp] lemma val_one' : (1 : zmod 0).val = 1 := rfl
@[simp] lemma val_neg' {n : zmod 0} : (-n).val = n.val := by simp [val]
@[simp] lemma val_mul' {m n : zmod 0} : (m * n).val = m.val * n.val :=
by simp [val, int.nat_abs_mul]
lemma val_nat_cast {n : ℕ} (a : ℕ) : (a : zmod n).val = a % n :=
begin
casesI n,
{ rw [nat.mod_zero, int.nat_cast_eq_coe_nat],
exact int.nat_abs_of_nat a, },
rw ← fin.of_nat_eq_coe,
refl
end
instance (n : ℕ) : char_p (zmod n) n :=
{ cast_eq_zero_iff :=
begin
intro k,
cases n,
{ simp only [int.nat_cast_eq_coe_nat, zero_dvd_iff, int.coe_nat_eq_zero], },
rw [fin.eq_iff_veq],
show (k : zmod (n+1)).val = (0 : zmod (n+1)).val ↔ _,
rw [val_nat_cast, val_zero, nat.dvd_iff_mod_eq_zero],
end }
@[simp] lemma nat_cast_self (n : ℕ) : (n : zmod n) = 0 :=
char_p.cast_eq_zero (zmod n) n
@[simp] lemma nat_cast_self' (n : ℕ) : (n + 1 : zmod (n + 1)) = 0 :=
by rw [← nat.cast_add_one, nat_cast_self (n + 1)]
section universal_property
variables {n : ℕ} {R : Type*}
section
variables [has_zero R] [has_one R] [has_add R] [has_neg R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `zmod.cast_hom` for a bundled version. -/
def cast : Π {n : ℕ}, zmod n → R
| 0 := int.cast
| (n+1) := λ i, i.val
-- see Note [coercion into rings]
@[priority 900] instance (n : ℕ) : has_coe_t (zmod n) R := ⟨cast⟩
@[simp] lemma cast_zero : ((0 : zmod n) : R) = 0 :=
by { cases n; refl }
variables {S : Type*} [has_zero S] [has_one S] [has_add S] [has_neg S]
@[simp] lemma _root_.prod.fst_zmod_cast (a : zmod n) : (a : R × S).fst = a :=
by cases n; simp
@[simp] lemma _root_.prod.snd_zmod_cast (a : zmod n) : (a : R × S).snd = a :=
by cases n; simp
end
/-- So-named because the coercion is `nat.cast` into `zmod`. For `nat.cast` into an arbitrary ring,
see `zmod.nat_cast_val`. -/
lemma nat_cast_zmod_val {n : ℕ} [fact (0 < n)] (a : zmod n) : (a.val : zmod n) = a :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 (fact.out _) },
{ apply fin.coe_coe_eq_self }
end
lemma nat_cast_right_inverse [fact (0 < n)] : function.right_inverse val (coe : ℕ → zmod n) :=
nat_cast_zmod_val
lemma nat_cast_zmod_surjective [fact (0 < n)] : function.surjective (coe : ℕ → zmod n) :=
nat_cast_right_inverse.surjective
/-- So-named because the outer coercion is `int.cast` into `zmod`. For `int.cast` into an arbitrary
ring, see `zmod.int_cast_cast`. -/
lemma int_cast_zmod_cast (a : zmod n) : ((a : ℤ) : zmod n) = a :=
begin
cases n,
{ rw [int.cast_id a, int.cast_id a], },
{ rw [coe_coe, int.nat_cast_eq_coe_nat, int.cast_coe_nat, fin.coe_coe_eq_self] }
end
lemma int_cast_right_inverse : function.right_inverse (coe : zmod n → ℤ) (coe : ℤ → zmod n) :=
int_cast_zmod_cast
lemma int_cast_surjective : function.surjective (coe : ℤ → zmod n) :=
int_cast_right_inverse.surjective
@[norm_cast]
lemma cast_id : ∀ n (i : zmod n), ↑i = i
| 0 i := int.cast_id i
| (n+1) i := nat_cast_zmod_val i
@[simp]
lemma cast_id' : (coe : zmod n → zmod n) = id := funext (cast_id n)
variables (R) [ring R]
/-- The coercions are respectively `nat.cast` and `zmod.cast`. -/
@[simp] lemma nat_cast_comp_val [fact (0 < n)] :
(coe : ℕ → R) ∘ (val : zmod n → ℕ) = coe :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 (fact.out _) },
refl
end
/-- The coercions are respectively `int.cast`, `zmod.cast`, and `zmod.cast`. -/
@[simp] lemma int_cast_comp_cast : (coe : ℤ → R) ∘ (coe : zmod n → ℤ) = coe :=
begin
cases n,
{ exact congr_arg ((∘) int.cast) zmod.cast_id', },
{ ext, simp }
end
variables {R}
@[simp] lemma nat_cast_val [fact (0 < n)] (i : zmod n) : (i.val : R) = i :=
congr_fun (nat_cast_comp_val R) i
@[simp] lemma int_cast_cast (i : zmod n) : ((i : ℤ) : R) = i :=
congr_fun (int_cast_comp_cast R) i
lemma coe_add_eq_ite {n : ℕ} (a b : zmod n) :
(↑(a + b) : ℤ) = if (n : ℤ) ≤ a + b then a + b - n else a + b :=
begin
cases n,
{ simp },
simp only [coe_coe, fin.coe_add_eq_ite, int.nat_cast_eq_coe_nat,
← int.coe_nat_add, ← int.coe_nat_succ, int.coe_nat_le],
split_ifs with h,
{ exact int.coe_nat_sub h },
{ refl }
end
section char_dvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variables {n} {m : ℕ} [char_p R m]
@[simp] lemma cast_one (h : m ∣ n) : ((1 : zmod n) : R) = 1 :=
begin
casesI n,
{ exact int.cast_one },
show ((1 % (n+1) : ℕ) : R) = 1,
cases n, { rw [nat.dvd_one] at h, substI m, apply subsingleton.elim },
rw nat.mod_eq_of_lt,
{ exact nat.cast_one },
exact nat.lt_of_sub_eq_succ rfl
end
lemma cast_add (h : m ∣ n) (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
begin
casesI n,
{ apply int.cast_add },
simp only [coe_coe],
symmetry,
erw [fin.coe_add, ← nat.cast_add, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ _ m],
exact h.trans (nat.dvd_sub_mod _),
end
lemma cast_mul (h : m ∣ n) (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
begin
casesI n,
{ apply int.cast_mul },
simp only [coe_coe],
symmetry,
erw [fin.coe_mul, ← nat.cast_mul, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ _ m],
exact h.trans (nat.dvd_sub_mod _),
end
/-- The canonical ring homomorphism from `zmod n` to a ring of characteristic `n`.
See also `zmod.lift` (in `data.zmod.quotient`) for a generalized version working in `add_group`s.
-/
def cast_hom (h : m ∣ n) (R : Type*) [ring R] [char_p R m] : zmod n →+* R :=
{ to_fun := coe,
map_zero' := cast_zero,
map_one' := cast_one h,
map_add' := cast_add h,
map_mul' := cast_mul h }
@[simp] lemma cast_hom_apply {h : m ∣ n} (i : zmod n) : cast_hom h R i = i := rfl
@[simp, norm_cast]
lemma cast_sub (h : m ∣ n) (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
(cast_hom h R).map_sub a b
@[simp, norm_cast]
lemma cast_neg (h : m ∣ n) (a : zmod n) : ((-a : zmod n) : R) = -a :=
(cast_hom h R).map_neg a
@[simp, norm_cast]
lemma cast_pow (h : m ∣ n) (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
(cast_hom h R).map_pow a k
@[simp, norm_cast]
lemma cast_nat_cast (h : m ∣ n) (k : ℕ) : ((k : zmod n) : R) = k :=
(cast_hom h R).map_nat_cast k
@[simp, norm_cast]
lemma cast_int_cast (h : m ∣ n) (k : ℤ) : ((k : zmod n) : R) = k :=
(cast_hom h R).map_int_cast k
end char_dvd
section char_eq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [char_p R n]
@[simp] lemma cast_one' : ((1 : zmod n) : R) = 1 :=
cast_one dvd_rfl
@[simp] lemma cast_add' (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
cast_add dvd_rfl a b
@[simp] lemma cast_mul' (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
cast_mul dvd_rfl a b
@[simp] lemma cast_sub' (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
cast_sub dvd_rfl a b
@[simp] lemma cast_pow' (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
lemma cast_nat_cast' (k : ℕ) : ((k : zmod n) : R) = k :=
cast_nat_cast dvd_rfl k
@[simp, norm_cast]
lemma cast_int_cast' (k : ℤ) : ((k : zmod n) : R) = k :=
cast_int_cast dvd_rfl k
variables (R)
lemma cast_hom_injective : function.injective (zmod.cast_hom (dvd_refl n) R) :=
begin
rw ring_hom.injective_iff,
intro x,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective x,
rw [ring_hom.map_int_cast, char_p.int_cast_eq_zero_iff R n,
char_p.int_cast_eq_zero_iff (zmod n) n],
exact id
end
lemma cast_hom_bijective [fintype R] (h : fintype.card R = n) :
function.bijective (zmod.cast_hom (dvd_refl n) R) :=
begin
haveI : fact (0 < n) :=
⟨begin
rw [pos_iff_ne_zero],
intro hn,
rw hn at h,
exact (fintype.card_eq_zero_iff.mp h).elim' 0
end⟩,
rw [fintype.bijective_iff_injective_and_card, zmod.card, h, eq_self_iff_true, and_true],
apply zmod.cast_hom_injective
end
/-- The unique ring isomorphism between `zmod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ring_equiv [fintype R] (h : fintype.card R = n) : zmod n ≃+* R :=
ring_equiv.of_bijective _ (zmod.cast_hom_bijective R h)
end char_eq
end universal_property
lemma int_coe_eq_int_coe_iff (a b : ℤ) (c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [ZMOD c] :=
char_p.int_coe_eq_int_coe_iff (zmod c) c a b
lemma int_coe_eq_int_coe_iff' (a b : ℤ) (c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a % c = b % c :=
zmod.int_coe_eq_int_coe_iff a b c
lemma nat_coe_eq_nat_coe_iff (a b c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [MOD c] :=
begin
convert zmod.int_coe_eq_int_coe_iff a b c,
simp [nat.modeq_iff_dvd, int.modeq_iff_dvd],
end
lemma int_coe_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : zmod b) = 0 ↔ (b : ℤ) ∣ a :=
begin
change (a : zmod b) = ((0 : ℤ) : zmod b) ↔ (b : ℤ) ∣ a,
rw [zmod.int_coe_eq_int_coe_iff, int.modeq_zero_iff_dvd],
end
lemma nat_coe_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : zmod b) = 0 ↔ b ∣ a :=
begin
change (a : zmod b) = ((0 : ℕ) : zmod b) ↔ b ∣ a,
rw [zmod.nat_coe_eq_nat_coe_iff, nat.modeq_zero_iff_dvd],
end
@[push_cast, simp]
lemma int_cast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : zmod b) = (a : zmod b) :=
begin
rw zmod.int_coe_eq_int_coe_iff,
apply int.mod_modeq,
end
lemma ker_int_cast_add_hom (n : ℕ) :
(int.cast_add_hom (zmod n)).ker = add_subgroup.gmultiples n :=
by { ext, rw [int.mem_gmultiples_iff, add_monoid_hom.mem_ker,
int.coe_cast_add_hom, int_coe_zmod_eq_zero_iff_dvd] }
lemma ker_int_cast_ring_hom (n : ℕ) :
(int.cast_ring_hom (zmod n)).ker = ideal.span ({n} : set ℤ) :=
by { ext, rw [ideal.mem_span_singleton, ring_hom.mem_ker,
int.coe_cast_ring_hom, int_coe_zmod_eq_zero_iff_dvd] }
local attribute [semireducible] int.nonneg
@[simp] lemma nat_cast_to_nat (p : ℕ) :
∀ {z : ℤ} (h : 0 ≤ z), (z.to_nat : zmod p) = z
| (n : ℕ) h := by simp only [int.cast_coe_nat, int.to_nat_coe_nat]
| -[1+n] h := false.elim h
lemma val_injective (n : ℕ) [fact (0 < n)] :
function.injective (zmod.val : zmod n → ℕ) :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 (fact.out _) },
assume a b h,
ext,
exact h
end
lemma val_one_eq_one_mod (n : ℕ) : (1 : zmod n).val = 1 % n :=
by rw [← nat.cast_one, val_nat_cast]
lemma val_one (n : ℕ) [fact (1 < n)] : (1 : zmod n).val = 1 :=
by { rw val_one_eq_one_mod, exact nat.mod_eq_of_lt (fact.out _) }
lemma val_add {n : ℕ} [fact (0 < n)] (a b : zmod n) : (a + b).val = (a.val + b.val) % n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 (fact.out _) },
{ apply fin.val_add }
end
lemma val_mul {n : ℕ} (a b : zmod n) : (a * b).val = (a.val * b.val) % n :=
begin
cases n,
{ rw nat.mod_zero, apply int.nat_abs_mul },
{ apply fin.val_mul }
end
instance nontrivial (n : ℕ) [fact (1 < n)] : nontrivial (zmod n) :=
⟨⟨0, 1, assume h, zero_ne_one $
calc 0 = (0 : zmod n).val : by rw val_zero
... = (1 : zmod n).val : congr_arg zmod.val h
... = 1 : val_one n ⟩⟩
/-- The inversion on `zmod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : Π (n : ℕ), zmod n → zmod n
| 0 i := int.sign i
| (n+1) i := nat.gcd_a i.val (n+1)
instance (n : ℕ) : has_inv (zmod n) := ⟨inv n⟩
lemma inv_zero : ∀ (n : ℕ), (0 : zmod n)⁻¹ = 0
| 0 := int.sign_zero
| (n+1) := show (nat.gcd_a _ (n+1) : zmod (n+1)) = 0,
by { rw val_zero, unfold nat.gcd_a nat.xgcd nat.xgcd_aux, refl }
lemma mul_inv_eq_gcd {n : ℕ} (a : zmod n) :
a * a⁻¹ = nat.gcd a.val n :=
begin
cases n,
{ calc a * a⁻¹ = a * int.sign a : rfl
... = a.nat_abs : by rw [int.mul_sign, int.nat_cast_eq_coe_nat]
... = a.val.gcd 0 : by rw nat.gcd_zero_right; refl },
{ set k := n.succ,
calc a * a⁻¹ = a * a⁻¹ + k * nat.gcd_b (val a) k : by rw [nat_cast_self, zero_mul, add_zero]
... = ↑(↑a.val * nat.gcd_a (val a) k + k * nat.gcd_b (val a) k) :
by { push_cast, rw nat_cast_zmod_val, refl }
... = nat.gcd a.val k : (congr_arg coe (nat.gcd_eq_gcd_ab a.val k)).symm, }
end
@[simp] lemma nat_cast_mod (n : ℕ) (a : ℕ) : ((a % n : ℕ) : zmod n) = a :=
by conv {to_rhs, rw ← nat.mod_add_div a n}; simp
lemma eq_iff_modeq_nat (n : ℕ) {a b : ℕ} : (a : zmod n) = b ↔ a ≡ b [MOD n] :=
begin
cases n,
{ simp only [nat.modeq, int.coe_nat_inj', nat.mod_zero, int.nat_cast_eq_coe_nat], },
{ rw [fin.ext_iff, nat.modeq, ← val_nat_cast, ← val_nat_cast], exact iff.rfl, }
end
lemma coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(x * x⁻¹ : zmod n) = 1 :=
begin
rw [nat.coprime, nat.gcd_comm, nat.gcd_rec] at h,
rw [mul_inv_eq_gcd, val_nat_cast, h, nat.cast_one],
end
/-- `unit_of_coprime` makes an element of `units (zmod n)` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) : units (zmod n) :=
⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩
@[simp] lemma coe_unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(unit_of_coprime x h : zmod n) = x := rfl
lemma val_coe_unit_coprime {n : ℕ} (u : units (zmod n)) :
nat.coprime (u : zmod n).val n :=
begin
cases n,
{ rcases int.units_eq_one_or u with rfl|rfl; simp },
apply nat.coprime_of_mul_modeq_one ((u⁻¹ : units (zmod (n+1))) : zmod (n+1)).val,
have := units.ext_iff.1 (mul_right_inv u),
rw [units.coe_one] at this,
rw [← eq_iff_modeq_nat, nat.cast_one, ← this], clear this,
rw [← nat_cast_zmod_val ((u * u⁻¹ : units (zmod (n+1))) : zmod (n+1))],
rw [units.coe_mul, val_mul, nat_cast_mod],
end
@[simp] lemma inv_coe_unit {n : ℕ} (u : units (zmod n)) :
(u : zmod n)⁻¹ = (u⁻¹ : units (zmod n)) :=
begin
have := congr_arg (coe : ℕ → zmod n) (val_coe_unit_coprime u),
rw [← mul_inv_eq_gcd, nat.cast_one] at this,
let u' : units (zmod n) := ⟨u, (u : zmod n)⁻¹, this, by rwa mul_comm⟩,
have h : u = u', { apply units.ext, refl },
rw h,
refl
end
lemma mul_inv_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a * a⁻¹ = 1 :=
begin
rcases h with ⟨u, rfl⟩,
rw [inv_coe_unit, u.mul_inv],
end
lemma inv_mul_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a⁻¹ * a = 1 :=
by rw [mul_comm, mul_inv_of_unit a h]
/-- Equivalence between the units of `zmod n` and
the subtype of terms `x : zmod n` for which `x.val` is comprime to `n` -/
def units_equiv_coprime {n : ℕ} [fact (0 < n)] :
units (zmod n) ≃ {x : zmod n // nat.coprime x.val n} :=
{ to_fun := λ x, ⟨x, val_coe_unit_coprime x⟩,
inv_fun := λ x, unit_of_coprime x.1.val x.2,
left_inv := λ ⟨_, _, _, _⟩, units.ext (nat_cast_zmod_val _),
right_inv := λ ⟨_, _⟩, by simp }
/-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`,
the rings `zmod (m * n)` and `zmod m × zmod n` are isomorphic.
See `ideal.quotient_inf_ring_equiv_pi_quotient` for the Chinese remainder theorem for ideals in any
ring.
-/
def chinese_remainder {m n : ℕ} (h : m.coprime n) :
zmod (m * n) ≃+* zmod m × zmod n :=
let to_fun : zmod (m * n) → zmod m × zmod n :=
zmod.cast_hom (show m.lcm n ∣ m * n, by simp [nat.lcm_dvd_iff]) (zmod m × zmod n) in
let inv_fun : zmod m × zmod n → zmod (m * n) :=
λ x, if m * n = 0
then if m = 1
then ring_hom.snd _ _ x
else ring_hom.fst _ _ x
else nat.chinese_remainder h x.1.val x.2.val in
have inv : function.left_inverse inv_fun to_fun ∧ function.right_inverse inv_fun to_fun :=
if hmn0 : m * n = 0
then begin
rcases h.eq_of_mul_eq_zero hmn0 with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩;
simp [inv_fun, to_fun, function.left_inverse, function.right_inverse,
ring_hom.eq_int_cast, prod.ext_iff]
end
else
begin
haveI : fact (0 < (m * n)) := ⟨nat.pos_of_ne_zero hmn0⟩,
haveI : fact (0 < m) := ⟨nat.pos_of_ne_zero $ left_ne_zero_of_mul hmn0⟩,
haveI : fact (0 < n) := ⟨nat.pos_of_ne_zero $ right_ne_zero_of_mul hmn0⟩,
have left_inv : function.left_inverse inv_fun to_fun,
{ intro x,
dsimp only [dvd_mul_left, dvd_mul_right, zmod.cast_hom_apply, coe_coe, inv_fun, to_fun],
conv_rhs { rw ← zmod.nat_cast_zmod_val x },
rw [if_neg hmn0, zmod.eq_iff_modeq_nat, ← nat.modeq_and_modeq_iff_modeq_mul h,
prod.fst_zmod_cast, prod.snd_zmod_cast],
refine
⟨(nat.chinese_remainder h (x : zmod m).val (x : zmod n).val).2.left.trans _,
(nat.chinese_remainder h (x : zmod m).val (x : zmod n).val).2.right.trans _⟩,
{ rw [← zmod.eq_iff_modeq_nat, zmod.nat_cast_zmod_val, zmod.nat_cast_val] },
{ rw [← zmod.eq_iff_modeq_nat, zmod.nat_cast_zmod_val, zmod.nat_cast_val] } },
exact ⟨left_inv, fintype.right_inverse_of_left_inverse_of_card_le left_inv (by simp)⟩,
end,
{ to_fun := to_fun,
inv_fun := inv_fun,
map_mul' := ring_hom.map_mul _,
map_add' := ring_hom.map_add _,
left_inv := inv.1,
right_inv := inv.2 }
instance subsingleton_units : subsingleton (units (zmod 2)) :=
⟨λ x y, begin
ext1,
cases x with x xi hx1 hx2,
cases y with y yi hy1 hy2,
revert hx1 hx2 hy1 hy2,
fin_cases x; fin_cases y; simp
end⟩
lemma le_div_two_iff_lt_neg (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)]
{x : zmod n} (hx0 : x ≠ 0) : x.val ≤ (n / 2 : ℕ) ↔ (n / 2 : ℕ) < (-x).val :=
begin
haveI npos : fact (0 < n) := ⟨by
{ apply (nat.eq_zero_or_pos n).resolve_left,
unfreezingI { rintro rfl },
simpa [fact_iff] using hn, }⟩,
have hn2 : (n : ℕ) / 2 < n := nat.div_lt_of_lt_mul
((lt_mul_iff_one_lt_left npos.1).2 dec_trivial),
have hn2' : (n : ℕ) - n / 2 = n / 2 + 1,
{ conv {to_lhs, congr, rw [← nat.succ_sub_one n, nat.succ_sub npos.1]},
rw [← nat.two_mul_odd_div_two hn.1, two_mul, ← nat.succ_add, nat.add_sub_cancel], },
have hxn : (n : ℕ) - x.val < n,
{ rw [sub_lt_iff_sub_lt x.val_le le_rfl, nat.sub_self],
rw ← zmod.nat_cast_zmod_val x at hx0,
exact nat.pos_of_ne_zero (λ h, by simpa [h] using hx0) },
by conv {to_rhs, rw [← nat.succ_le_iff, nat.succ_eq_add_one, ← hn2', ← zero_add (- x),
← zmod.nat_cast_self, ← sub_eq_add_neg, ← zmod.nat_cast_zmod_val x,
← nat.cast_sub x.val_le,
zmod.val_nat_cast, nat.mod_eq_of_lt hxn, sub_le_sub_iff_left' x.val_le] }
end
lemma ne_neg_self (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)] {a : zmod n} (ha : a ≠ 0) : a ≠ -a :=
λ h, have a.val ≤ n / 2 ↔ (n : ℕ) / 2 < (-a).val := le_div_two_iff_lt_neg n ha,
by rwa [← h, ← not_lt, not_iff_self] at this
lemma neg_one_ne_one {n : ℕ} [fact (2 < n)] :
(-1 : zmod n) ≠ 1 :=
char_p.neg_one_ne_one (zmod n) n
@[simp] lemma neg_eq_self_mod_two (a : zmod 2) : -a = a :=
by fin_cases a; ext; simp [fin.coe_neg, int.nat_mod]; norm_num
@[simp] lemma nat_abs_mod_two (a : ℤ) : (a.nat_abs : zmod 2) = a :=
begin
cases a,
{ simp only [int.nat_abs_of_nat, int.cast_coe_nat, int.of_nat_eq_coe] },
{ simp only [neg_eq_self_mod_two, nat.cast_succ, int.nat_abs, int.cast_neg_succ_of_nat] }
end
@[simp] lemma val_eq_zero : ∀ {n : ℕ} (a : zmod n), a.val = 0 ↔ a = 0
| 0 a := int.nat_abs_eq_zero
| (n+1) a := by { rw fin.ext_iff, exact iff.rfl }
lemma val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : zmod n).val = a :=
by rw [val_nat_cast, nat.mod_eq_of_lt h]
lemma neg_val' {n : ℕ} [fact (0 < n)] (a : zmod n) : (-a).val = (n - a.val) % n :=
calc (-a).val = val (-a) % n : by rw nat.mod_eq_of_lt ((-a).val_lt)
... = (n - val a) % n : nat.modeq.add_right_cancel' _ (by rw [nat.modeq, ←val_add,
add_left_neg, nat.sub_add_cancel a.val_le, nat.mod_self, val_zero])
lemma neg_val {n : ℕ} [fact (0 < n)] (a : zmod n) : (-a).val = if a = 0 then 0 else n - a.val :=
begin
rw neg_val',
by_cases h : a = 0, { rw [if_pos h, h, val_zero, nat.sub_zero, nat.mod_self] },
rw if_neg h,
apply nat.mod_eq_of_lt,
apply nat.sub_lt (fact.out (0 < n)),
contrapose! h,
rwa [nat.le_zero_iff, val_eq_zero] at h,
end
/-- `val_min_abs x` returns the integer in the same equivalence class as `x` that is closest to `0`,
The result will be in the interval `(-n/2, n/2]`. -/
def val_min_abs : Π {n : ℕ}, zmod n → ℤ
| 0 x := x
| n@(_+1) x := if x.val ≤ n / 2 then x.val else (x.val : ℤ) - n
@[simp] lemma val_min_abs_def_zero (x : zmod 0) : val_min_abs x = x := rfl
lemma val_min_abs_def_pos {n : ℕ} [fact (0 < n)] (x : zmod n) :
val_min_abs x = if x.val ≤ n / 2 then x.val else x.val - n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 (fact.out (0 < 0)) },
{ refl }
end
@[simp] lemma coe_val_min_abs : ∀ {n : ℕ} (x : zmod n), (x.val_min_abs : zmod n) = x
| 0 x := int.cast_id x
| k@(n+1) x :=
begin
rw val_min_abs_def_pos,
split_ifs,
{ rw [int.cast_coe_nat, nat_cast_zmod_val] },
{ rw [int.cast_sub, int.cast_coe_nat, nat_cast_zmod_val, int.cast_coe_nat, nat_cast_self,
sub_zero] }
end
lemma nat_abs_val_min_abs_le {n : ℕ} [fact (0 < n)] (x : zmod n) : x.val_min_abs.nat_abs ≤ n / 2 :=
begin
rw zmod.val_min_abs_def_pos,
split_ifs with h, { exact h },
have : (x.val - n : ℤ) ≤ 0,
{ rw [sub_nonpos, int.coe_nat_le], exact x.val_le, },
rw [← int.coe_nat_le, int.of_nat_nat_abs_of_nonpos this, neg_sub],
conv_lhs { congr, rw [← nat.mod_add_div n 2, int.coe_nat_add, int.coe_nat_mul,
int.coe_nat_bit0, int.coe_nat_one] },
suffices : ((n % 2 : ℕ) + (n / 2) : ℤ) ≤ (val x),
{ rw ← sub_nonneg at this ⊢, apply le_trans this (le_of_eq _), ring_nf, ring },
norm_cast,
calc (n : ℕ) % 2 + n / 2 ≤ 1 + n / 2 :
nat.add_le_add_right (nat.le_of_lt_succ (nat.mod_lt _ dec_trivial)) _
... ≤ x.val :
by { rw add_comm, exact nat.succ_le_of_lt (lt_of_not_ge h) }
end
@[simp] lemma val_min_abs_zero : ∀ n, (0 : zmod n).val_min_abs = 0
| 0 := by simp only [val_min_abs_def_zero]
| (n+1) := by simp only [val_min_abs_def_pos, if_true, int.coe_nat_zero, zero_le, val_zero]
@[simp] lemma val_min_abs_eq_zero {n : ℕ} (x : zmod n) :
x.val_min_abs = 0 ↔ x = 0 :=
begin
cases n, { simp },
split,
{ simp only [val_min_abs_def_pos, int.coe_nat_succ],
split_ifs with h h; assume h0,
{ apply val_injective, rwa [int.coe_nat_eq_zero] at h0, },
{ apply absurd h0, rw sub_eq_zero, apply ne_of_lt, exact_mod_cast x.val_lt } },
{ rintro rfl, rw val_min_abs_zero }
end
lemma nat_cast_nat_abs_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val_min_abs.nat_abs : zmod n) = if a.val ≤ (n : ℕ) / 2 then a else -a :=
begin
have : (a.val : ℤ) - n ≤ 0,
by { erw [sub_nonpos, int.coe_nat_le], exact a.val_le, },
rw [zmod.val_min_abs_def_pos],
split_ifs,
{ rw [int.nat_abs_of_nat, nat_cast_zmod_val] },
{ rw [← int.cast_coe_nat, int.of_nat_nat_abs_of_nonpos this, int.cast_neg, int.cast_sub],
rw [int.cast_coe_nat, int.cast_coe_nat, nat_cast_self, sub_zero, nat_cast_zmod_val], }
end
@[simp] lemma nat_abs_val_min_abs_neg {n : ℕ} (a : zmod n) :
(-a).val_min_abs.nat_abs = a.val_min_abs.nat_abs :=
begin
cases n, { simp only [int.nat_abs_neg, val_min_abs_def_zero], },
by_cases ha0 : a = 0, { rw [ha0, neg_zero] },
by_cases haa : -a = a, { rw [haa] },
suffices hpa : (n+1 : ℕ) - a.val ≤ (n+1) / 2 ↔ (n+1 : ℕ) / 2 < a.val,
{ rw [val_min_abs_def_pos, val_min_abs_def_pos],
rw ← not_le at hpa,
simp only [if_neg ha0, neg_val, hpa, int.coe_nat_sub a.val_le],
split_ifs,
all_goals { rw [← int.nat_abs_neg], congr' 1, ring } },
suffices : (((n+1 : ℕ) % 2) + 2 * ((n + 1) / 2)) - a.val ≤ (n+1) / 2 ↔ (n+1 : ℕ) / 2 < a.val,
by rwa [nat.mod_add_div] at this,
suffices : (n + 1) % 2 + (n + 1) / 2 ≤ val a ↔ (n + 1) / 2 < val a,
by rw [sub_le_iff_sub_le, two_mul, ← add_assoc, nat.add_sub_cancel, this],
cases (n + 1 : ℕ).mod_two_eq_zero_or_one with hn0 hn1,
{ split,
{ assume h,
apply lt_of_le_of_ne (le_trans (nat.le_add_left _ _) h),
contrapose! haa,
rw [← zmod.nat_cast_zmod_val a, ← haa, neg_eq_iff_add_eq_zero, ← nat.cast_add],
rw [char_p.cast_eq_zero_iff (zmod (n+1)) (n+1)],
rw [← two_mul, ← zero_add (2 * _), ← hn0, nat.mod_add_div] },
{ rw [hn0, zero_add], exact le_of_lt } },
{ rw [hn1, add_comm, nat.succ_le_iff] }
end
lemma val_eq_ite_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val : ℤ) = a.val_min_abs + if a.val ≤ n / 2 then 0 else n :=
by { rw [zmod.val_min_abs_def_pos], split_ifs; simp only [add_zero, sub_add_cancel] }
lemma prime_ne_zero (p q : ℕ) [hp : fact p.prime] [hq : fact q.prime] (hpq : p ≠ q) :
(q : zmod p) ≠ 0 :=
by rwa [← nat.cast_zero, ne.def, eq_iff_modeq_nat, nat.modeq_zero_iff_dvd,
← hp.1.coprime_iff_not_dvd, nat.coprime_primes hp.1 hq.1]
end zmod
namespace zmod
variables (p : ℕ) [fact p.prime]
private lemma mul_inv_cancel_aux (a : zmod p) (h : a ≠ 0) : a * a⁻¹ = 1 :=
begin
obtain ⟨k, rfl⟩ := nat_cast_zmod_surjective a,
apply coe_mul_inv_eq_one,
apply nat.coprime.symm,
rwa [nat.prime.coprime_iff_not_dvd (fact.out p.prime), ← char_p.cast_eq_zero_iff (zmod p)]
end
/-- Field structure on `zmod p` if `p` is prime. -/
instance : field (zmod p) :=
{ mul_inv_cancel := mul_inv_cancel_aux p,
inv_zero := inv_zero p,
.. zmod.comm_ring p,
.. zmod.has_inv p,
.. zmod.nontrivial p }
/-- `zmod p` is an integral domain when `p` is prime. -/
instance (p : ℕ) [hp : fact p.prime] : integral_domain (zmod p) :=
begin
-- We need `cases p` here in order to resolve which `comm_ring` instance is being used.
unfreezingI { cases p, { exfalso, rcases hp with ⟨⟨⟨⟩⟩⟩, }, },
exact @field.to_integral_domain (zmod _) (zmod.field _)
end
end zmod
lemma ring_hom.ext_zmod {n : ℕ} {R : Type*} [semiring R] (f g : (zmod n) →+* R) : f = g :=
begin
ext a,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective a,
let φ : ℤ →+* R := f.comp (int.cast_ring_hom (zmod n)),
let ψ : ℤ →+* R := g.comp (int.cast_ring_hom (zmod n)),
show φ k = ψ k,
rw φ.ext_int ψ,
end
namespace zmod
variables {n : ℕ} {R : Type*}
instance subsingleton_ring_hom [semiring R] : subsingleton ((zmod n) →+* R) :=
⟨ring_hom.ext_zmod⟩
instance subsingleton_ring_equiv [semiring R] : subsingleton (zmod n ≃+* R) :=
⟨λ f g, by { rw ring_equiv.coe_ring_hom_inj_iff, apply ring_hom.ext_zmod _ _ }⟩
@[simp] lemma ring_hom_map_cast [ring R] (f : R →+* (zmod n)) (k : zmod n) :
f k = k :=
by { cases n; simp }
lemma ring_hom_right_inverse [ring R] (f : R →+* (zmod n)) :
function.right_inverse (coe : zmod n → R) f :=
ring_hom_map_cast f
lemma ring_hom_surjective [ring R] (f : R →+* (zmod n)) : function.surjective f :=
(ring_hom_right_inverse f).surjective
lemma ring_hom_eq_of_ker_eq [comm_ring R] (f g : R →+* (zmod n))
(h : f.ker = g.ker) : f = g :=
begin
have := f.lift_of_right_inverse_comp _ (zmod.ring_hom_right_inverse f) ⟨g, le_of_eq h⟩,
rw subtype.coe_mk at this,
rw [←this, ring_hom.ext_zmod (f.lift_of_right_inverse _ _ _) (ring_hom.id _), ring_hom.id_comp],
end
section lift
variables (n) {A : Type*} [add_group A]
/-- The map from `zmod n` induced by `f : ℤ →+ A` that maps `n` to `0`. -/
@[simps]
def lift : {f : ℤ →+ A // f n = 0} ≃ (zmod n →+ A) :=
(equiv.subtype_equiv_right $ begin
intro f,
rw ker_int_cast_add_hom,
split,
{ rintro hf _ ⟨x, rfl⟩,
simp only [f.map_gsmul, gsmul_zero, f.mem_ker, hf] },
{ intro h,
refine h (add_subgroup.mem_gmultiples _) }
end).trans $ ((int.cast_add_hom (zmod n)).lift_of_right_inverse coe int_cast_zmod_cast)
variables (f : {f : ℤ →+ A // f n = 0})
@[simp] lemma lift_coe (x : ℤ) :
lift n f (x : zmod n) = f x :=
add_monoid_hom.lift_of_right_inverse_comp_apply _ _ _ _ _
lemma lift_cast_add_hom (x : ℤ) :
lift n f (int.cast_add_hom (zmod n) x) = f x :=
add_monoid_hom.lift_of_right_inverse_comp_apply _ _ _ _ _
@[simp] lemma lift_comp_coe : zmod.lift n f ∘ coe = f :=
funext $ lift_coe _ _
@[simp] lemma lift_comp_cast_add_hom :
(zmod.lift n f).comp (int.cast_add_hom (zmod n)) = f :=
add_monoid_hom.ext $ lift_cast_add_hom _ _
end lift
end zmod
|
ff5d8f7b2e883916eddb0937167b19f7e474025e | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/number_theory/bernoulli.lean | e1f1ef8505d239d0ed792a4ffba3e4a3b1fd29de | [
"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 | 2,898 | 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 data.rat
import data.fintype.card
/-!
# Bernoulli numbers
The Bernoulli numbers are a sequence of numbers that frequently show up in number theory.
For example, they show up in the Taylor series of many trigonometric and hyperbolic functions,
and also as (integral multiples of products of powers of `π` and)
special values of the Riemann zeta function.
(Note: these facts are not yet available in mathlib)
In this file, we provide the definition,
and the basic fact (`sum_bernoulli`) that
$$ \sum_{k < n} \binom{n}{k} * B_k = n, $$
where $B_k$ denotes the the $k$-th Bernoulli number.
-/
open_locale big_operators
/-- The Bernoulli numbers:
the $n$-th Bernoulli number $B_n$ is defined recursively via
$$B_n = \sum_{k < n} \binom{n}{k} * \frac{B_k}{n+1-k}$$ -/
def bernoulli : ℕ → ℚ :=
well_founded.fix nat.lt_wf
(λ n bernoulli, 1 - ∑ k : fin n, (n.choose k) * bernoulli k k.2 / (n + 1 - k))
lemma bernoulli_def' (n : ℕ) :
bernoulli n = 1 - ∑ k : fin n, (n.choose k) * (bernoulli k) / (n + 1 - k) :=
well_founded.fix_eq _ _ _
lemma bernoulli_def (n : ℕ) :
bernoulli n = 1 - ∑ k in finset.range n, (n.choose k) * (bernoulli k) / (n + 1 - k) :=
by { rw [bernoulli_def', finset.sum_range_eq_sum_fin], refl }
@[simp] lemma bernoulli_zero : bernoulli 0 = 1 := rfl
@[simp] lemma bernoulli_one : bernoulli 1 = 1/2 :=
begin
rw [bernoulli_def],
repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 }
end
@[simp] lemma bernoulli_two : bernoulli 2 = 1/6 :=
begin
rw [bernoulli_def],
repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 }
end
@[simp] lemma bernoulli_three : bernoulli 3 = 0 :=
begin
rw [bernoulli_def],
repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 }
end
@[simp] lemma bernoulli_four : bernoulli 4 = -1/30 :=
begin
rw [bernoulli_def],
repeat { try { rw [finset.sum_range_succ] }, try { rw [nat.choose_succ_succ] }, simp, norm_num1 }
end
@[simp] lemma sum_bernoulli (n : ℕ) :
∑ k in finset.range n, (n.choose k : ℚ) * bernoulli k = n :=
begin
induction n with n ih, { simp },
rw [finset.sum_range_succ],
rw [nat.choose_succ_self_right],
rw [bernoulli_def, mul_sub, mul_one, sub_add_eq_add_sub, sub_eq_iff_eq_add],
rw [add_left_cancel_iff, finset.mul_sum, finset.sum_congr rfl],
intros k hk, rw finset.mem_range at hk,
rw [mul_div_right_comm, ← mul_assoc],
congr' 1,
rw [← mul_div_assoc, eq_div_iff],
{ rw [mul_comm ((n+1 : ℕ) : ℚ)],
have hk' : k ≤ n + 1, by linarith,
rw_mod_cast nat.choose_mul_succ_eq n k },
{ contrapose! hk with H, rw sub_eq_zero at H, norm_cast at H, linarith }
end
|
b8e7e12c170d6b7ee57f3b48c97d63dc5ec6133c | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/category_theory/products/basic.lean | c72806f39b76b0e3125e24bf1a6388302c2f23be | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 5,694 | 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.equivalence
import category_theory.eq_to_hom
import tactic.interactive
namespace category_theory
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ -- declare the `v`'s first; see `category_theory.category` for an explanation
section
variables (C : Type u₁) [𝒞 : category.{v₁} C] (D : Type u₂) [𝒟 : category.{v₂} D]
include 𝒞 𝒟
/--
`prod C D` gives the cartesian product of two categories.
-/
instance prod : category.{max v₁ v₂} (C × D) :=
{ hom := λ X Y, ((X.1) ⟶ (Y.1)) × ((X.2) ⟶ (Y.2)),
id := λ X, ⟨ 𝟙 (X.1), 𝟙 (X.2) ⟩,
comp := λ _ _ _ f g, (f.1 ≫ g.1, f.2 ≫ g.2) }
-- rfl lemmas for category.prod
@[simp] lemma prod_id (X : C) (Y : D) : 𝟙 (X, Y) = (𝟙 X, 𝟙 Y) := rfl
@[simp] lemma prod_comp {P Q R : C} {S T U : D} (f : (P, S) ⟶ (Q, T)) (g : (Q, T) ⟶ (R, U)) :
f ≫ g = (f.1 ≫ g.1, f.2 ≫ g.2) := rfl
@[simp] lemma prod_id_fst (X : prod C D) : prod.fst (𝟙 X) = 𝟙 X.fst := rfl
@[simp] lemma prod_id_snd (X : prod C D) : prod.snd (𝟙 X) = 𝟙 X.snd := rfl
@[simp] lemma prod_comp_fst {X Y Z : prod C D} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).1 = f.1 ≫ g.1 := rfl
@[simp] lemma prod_comp_snd {X Y Z : prod C D} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).2 = f.2 ≫ g.2 := rfl
end
section
variables (C : Type u₁) [𝒞 : category.{v₁} C] (D : Type u₁) [𝒟 : category.{v₁} D]
include 𝒞 𝒟
/--
`prod.category.uniform C D` is an additional instance specialised so both factors have the same universe levels. This helps typeclass resolution.
-/
instance uniform_prod : category (C × D) := category_theory.prod C D
end
-- Next we define the natural functors into and out of product categories. For now this doesn't address the universal properties.
namespace prod
/-- `sectl C Z` is the functor `C ⥤ C × D` given by `X ↦ (X, Z)`. -/
-- Here and below we specify explicitly the projections to generate `@[simp]` lemmas for,
-- as the default behaviour of `@[simps]` will generate projections all the way down to components of pairs.
@[simps obj map] def sectl
(C : Type u₁) [category.{v₁} C] {D : Type u₂} [category.{v₂} D] (Z : D) : C ⥤ C × D :=
{ obj := λ X, (X, Z),
map := λ X Y f, (f, 𝟙 Z) }
/-- `sectr Z D` is the functor `D ⥤ C × D` given by `Y ↦ (Z, Y)` . -/
@[simps obj map] def sectr
{C : Type u₁} [category.{v₁} C] (Z : C) (D : Type u₂) [category.{v₂} D] : D ⥤ C × D :=
{ obj := λ X, (Z, X),
map := λ X Y f, (𝟙 Z, f) }
variables (C : Type u₁) [𝒞 : category.{v₁} C] (D : Type u₂) [𝒟 : category.{v₂} D]
include 𝒞 𝒟
/-- `fst` is the functor `(X, Y) ↦ X`. -/
@[simps obj map] def fst : C × D ⥤ C :=
{ obj := λ X, X.1,
map := λ X Y f, f.1 }
/-- `snd` is the functor `(X, Y) ↦ Y`. -/
@[simps obj map] def snd : C × D ⥤ D :=
{ obj := λ X, X.2,
map := λ X Y f, f.2 }
@[simps obj map] def swap : C × D ⥤ D × C :=
{ obj := λ X, (X.2, X.1),
map := λ _ _ f, (f.2, f.1) }
@[simps hom_app inv_app] def symmetry : swap C D ⋙ swap D C ≅ 𝟭 (C × D) :=
{ hom := { app := λ X, 𝟙 X },
inv := { app := λ X, 𝟙 X } }
def braiding : C × D ≌ D × C :=
equivalence.mk (swap C D) (swap D C)
(nat_iso.of_components (λ X, eq_to_iso (by simp)) (by tidy))
(nat_iso.of_components (λ X, eq_to_iso (by simp)) (by tidy))
instance swap_is_equivalence : is_equivalence (swap C D) :=
(by apply_instance : is_equivalence (braiding C D).functor)
end prod
section
variables (C : Type u₁) [𝒞 : category.{v₁} C] (D : Type u₂) [𝒟 : category.{v₂} D]
include 𝒞 𝒟
@[simps] def evaluation : C ⥤ (C ⥤ D) ⥤ D :=
{ obj := λ X,
{ obj := λ F, F.obj X,
map := λ F G α, α.app X, },
map := λ X Y f,
{ app := λ F, F.map f,
naturality' := λ F G α, eq.symm (α.naturality f) } }
@[simps obj map] def evaluation_uncurried : C × (C ⥤ D) ⥤ D :=
{ obj := λ p, p.2.obj p.1,
map := λ x y f, (x.2.map f.1) ≫ (f.2.app y.1),
map_comp' := λ X Y Z f g,
begin
cases g, cases f, cases Z, cases Y, cases X,
simp only [prod_comp, nat_trans.comp_app, functor.map_comp, category.assoc],
rw [←nat_trans.comp_app, nat_trans.naturality, nat_trans.comp_app,
category.assoc, nat_trans.naturality],
end }
end
variables {A : Type u₁} [𝒜 : category.{v₁} A]
{B : Type u₂} [ℬ : category.{v₂} B]
{C : Type u₃} [𝒞 : category.{v₃} C]
{D : Type u₄} [𝒟 : category.{v₄} D]
include 𝒜 ℬ 𝒞 𝒟
namespace functor
/-- The cartesian product of two functors. -/
@[simps obj map] def prod (F : A ⥤ B) (G : C ⥤ D) : A × C ⥤ B × D :=
{ obj := λ X, (F.obj X.1, G.obj X.2),
map := λ _ _ f, (F.map f.1, G.map f.2) }
/- Because of limitations in Lean 3's handling of notations, we do not setup a notation `F × G`.
You can use `F.prod G` as a "poor man's infix", or just write `functor.prod F G`. -/
end functor
namespace nat_trans
/-- The cartesian product of two natural transformations. -/
@[simps app] def prod {F G : A ⥤ B} {H I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) :
F.prod H ⟶ G.prod I :=
{ app := λ X, (α.app X.1, β.app X.2),
naturality' := λ X Y f,
begin
cases X, cases Y,
simp only [functor.prod_map, prod.mk.inj_iff, prod_comp],
split; rw naturality
end }
/- Again, it is inadvisable in Lean 3 to setup a notation `α × β`;
use instead `α.prod β` or `nat_trans.prod α β`. -/
end nat_trans
end category_theory
|
1c4ad7341a5393ab890b439358705921d1b79806 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /archive/imo/imo2019_q4.lean | 64c4a49dbcde31d8fc3e2fc663b5bf71690ba66b | [
"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,192 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import tactic.interval_cases
import algebra.big_operators.order
import algebra.big_operators.enat
import data.nat.multiplicity
/-!
# IMO 2019 Q4
Find all pairs `(k, n)` of positive integers such that
```
k! = (2 ^ n − 1)(2 ^ n − 2)(2 ^ n − 4)···(2 ^ n − 2 ^ (n − 1))
```
We show in this file that this property holds iff `(k, n) = (1, 1) ∨ (k, n) = (3, 2)`.
Proof sketch:
The idea of the proof is to count the factors of 2 on both sides. The LHS has less than `k` factors
of 2, and the RHS has exactly `n * (n - 1) / 2` factors of 2. So we know that `n * (n - 1) / 2 < k`.
Now for `n ≥ 6` we have `RHS < 2 ^ (n ^ 2) < (n(n-1)/2)! < k!`. We then treat the cases `n < 6`
individually.
-/
open_locale nat big_operators
open finset multiplicity nat (hiding zero_le prime)
theorem imo2019_q4_upper_bound {k n : ℕ} (hk : k > 0)
(h : (k! : ℤ) = ∏ i in range n, (2 ^ n - 2 ^ i)) : n < 6 :=
begin
have prime_2 : prime (2 : ℤ),
{ exact prime_iff_prime_int.mp prime_two },
have h2 : n * (n - 1) / 2 < k,
{ suffices : multiplicity 2 (k! : ℤ) = (n * (n - 1) / 2 : ℕ),
{ rw [← enat.coe_lt_coe, ← this], change multiplicity ((2 : ℕ) : ℤ) _ < _,
simp_rw [int.coe_nat_multiplicity, multiplicity_two_factorial_lt hk.lt.ne.symm] },
rw [h, multiplicity.finset.prod prime_2, ← sum_range_id, ← sum_nat_coe_enat],
apply sum_congr rfl, intros i hi,
rw [multiplicity_sub_of_gt, multiplicity_pow_self_of_prime prime_2],
rwa [multiplicity_pow_self_of_prime prime_2, multiplicity_pow_self_of_prime prime_2,
enat.coe_lt_coe, ←mem_range] },
rw [←not_le], intro hn,
apply ne_of_lt _ h.symm,
suffices : (∏ i in range n, 2 ^ n : ℤ) < ↑k!,
{ apply lt_of_le_of_lt _ this, apply prod_le_prod,
{ intros, rw [sub_nonneg], apply pow_le_pow, norm_num, apply le_of_lt, rwa [← mem_range] },
{ intros, apply sub_le_self, apply pow_nonneg, norm_num } },
suffices : 2 ^ (n * n) < (n * (n - 1) / 2)!,
{ rw [prod_const, card_range, ← pow_mul], rw [← int.coe_nat_lt_coe_nat_iff] at this,
clear h, convert this.trans _, norm_cast, rwa [int.coe_nat_lt_coe_nat_iff, factorial_lt],
refine nat.div_pos _ (by norm_num),
refine le_trans _ (mul_le_mul hn (pred_le_pred hn) (zero_le _) (zero_le _)),
norm_num },
refine le_induction _ _ n hn, { norm_num },
intros n' hn' ih,
have h5 : 1 ≤ 2 * n', { linarith },
have : 2 ^ (2 + 2) ≤ (n' * (n' - 1) / 2).succ,
{ change succ (6 * (6 - 1) / 2) ≤ _,
apply succ_le_succ, apply nat.div_le_div_right,
exact mul_le_mul hn' (pred_le_pred hn') (zero_le _) (zero_le _) },
rw [triangle_succ], apply lt_of_lt_of_le _ factorial_mul_pow_le_factorial,
refine lt_of_le_of_lt _ (mul_lt_mul ih (nat.pow_le_pow_of_le_left this _)
(pow_pos (by norm_num) _) (zero_le _)),
rw [← pow_mul, ← pow_add], apply pow_le_pow_of_le_right, norm_num,
rw [add_mul 2 2],
convert add_le_add_left (add_le_add_left h5 (2 * n')) (n' * n') using 1, ring
end
theorem imo2019_q4 {k n : ℕ} (hk : k > 0) (hn : n > 0) :
(k! : ℤ) = (∏ i in range n, (2 ^ n - 2 ^ i)) ↔ (k, n) = (1, 1) ∨ (k, n) = (3, 2) :=
begin
/- The implication `←` holds. -/
split, swap,
{ rintro (h|h); simp [prod.ext_iff] at h; rcases h with ⟨rfl, rfl⟩;
norm_num [prod_range_succ, succ_mul] },
intro h,
/- We know that n < 6. -/
have := imo2019_q4_upper_bound hk h,
interval_cases n,
/- n = 1 -/
{ left, congr, norm_num at h, norm_cast at h, rw [factorial_eq_one] at h, apply antisymm h,
apply succ_le_of_lt hk },
/- n = 2 -/
{ right, congr, norm_num [prod_range_succ] at h, norm_cast at h, rw [← factorial_inj],
exact h, rw [h], norm_num },
all_goals { exfalso, norm_num [prod_range_succ] at h, norm_cast at h, },
/- n = 3 -/
{ refine monotone_factorial.ne_of_lt_of_lt_nat 5 _ _ _ h; norm_num },
/- n = 4 -/
{ refine monotone_factorial.ne_of_lt_of_lt_nat 7 _ _ _ h; norm_num },
/- n = 5 -/
{ refine monotone_factorial.ne_of_lt_of_lt_nat 10 _ _ _ h; norm_num },
end
|
54d929e513f3e164a13cf3ef4b8c3a8330f8aca3 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/special_functions/non_integrable.lean | 0310351d805ad855a4b74adadcb02ceffedaf87c | [
"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 | 9,700 | lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.special_functions.integrals
import analysis.calculus.fderiv_measurable
/-!
# Non integrable functions
In this file we prove that the derivative of a function that tends to infinity is not interval
integrable, see `interval_integral.not_integrable_has_deriv_at_of_tendsto_norm_at_top_filter` and
`interval_integral.not_integrable_has_deriv_at_of_tendsto_norm_at_top_punctured`. Then we apply the
latter lemma to prove that the function `λ x, x⁻¹` is integrable on `a..b` if and only if `a = b` or
`0 ∉ [a, b]`.
## Main results
* `not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured`: if `f` tends to infinity
along `𝓝[≠] c` and `f' = O(g)` along the same filter, then `g` is not interval integrable on any
nontrivial integral `a..b`, `c ∈ [a, b]`.
* `not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_filter`: a version of
`not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured` that works for one-sided
neighborhoods;
* `not_interval_integrable_of_sub_inv_is_O_punctured`: if `1 / (x - c) = O(f)` as `x → c`, `x ≠ c`,
then `f` is not interval integrable on any nontrivial interval `a..b`, `c ∈ [a, b]`;
* `interval_integrable_sub_inv_iff`, `interval_integrable_inv_iff`: integrability conditions for
`(x - c)⁻¹` and `x⁻¹`.
## Tags
integrable function
-/
open_locale measure_theory topological_space interval nnreal ennreal
open measure_theory topological_space set filter asymptotics interval_integral
variables {E F : Type*} [normed_group E] [normed_space ℝ E] [measurable_space E] [borel_space E]
[second_countable_topology E] [complete_space E] [normed_group F]
[measurable_space F] [borel_space F]
/-- If `f` is eventually differentiable along a nontrivial filter `l : filter ℝ` that is generated
by convex sets, the norm of `f` tends to infinity along `l`, and `f' = O(g)` along `l`, where `f'`
is the derivative of `f`, then `g` is not integrable on any interval `a..b` such that
`[a, b] ∈ l`. -/
lemma not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_filter {f : ℝ → E} {g : ℝ → F}
{a b : ℝ} (l : filter ℝ) [ne_bot l] [tendsto_Ixx_class Icc l l] (hl : [a, b] ∈ l)
(hd : ∀ᶠ x in l, differentiable_at ℝ f x) (hf : tendsto (λ x, ∥f x∥) l at_top)
(hfg : is_O (deriv f) g l) :
¬interval_integrable g volume a b :=
begin
intro hgi,
obtain ⟨C, hC₀, s, hsl, hsub, hfd, hg⟩ : ∃ (C : ℝ) (hC₀ : 0 ≤ C) (s ∈ l),
(∀ (x ∈ s) (y ∈ s), [x, y] ⊆ [a, b]) ∧
(∀ (x ∈ s) (y ∈ s) (z ∈ [x, y]), differentiable_at ℝ f z) ∧
(∀ (x ∈ s) (y ∈ s) (z ∈ [x, y]), ∥deriv f z∥ ≤ C * ∥g z∥),
{ rcases hfg.exists_nonneg with ⟨C, C₀, hC⟩,
have h : ∀ᶠ x : ℝ × ℝ in l.prod l, ∀ y ∈ [x.1, x.2], (differentiable_at ℝ f y ∧
∥deriv f y∥ ≤ C * ∥g y∥) ∧ y ∈ [a, b],
from (tendsto_fst.interval tendsto_snd).eventually ((hd.and hC.bound).and hl).lift'_powerset,
rcases mem_prod_self_iff.1 h with ⟨s, hsl, hs⟩,
simp only [prod_subset_iff, mem_set_of_eq] at hs,
exact ⟨C, C₀, s, hsl, λ x hx y hy z hz, (hs x hx y hy z hz).2,
λ x hx y hy z hz, (hs x hx y hy z hz).1.1, λ x hx y hy z hz, (hs x hx y hy z hz).1.2⟩ },
replace hgi : interval_integrable (λ x, C * ∥g x∥) volume a b, by convert hgi.norm.smul C,
obtain ⟨c, hc, d, hd, hlt⟩ : ∃ (c ∈ s) (d ∈ s), ∥f c∥ + ∫ y in Ι a b, C * ∥g y∥ < ∥f d∥,
{ rcases filter.nonempty_of_mem hsl with ⟨c, hc⟩,
have : ∀ᶠ x in l, ∥f c∥ + ∫ y in Ι a b, C * ∥g y∥ < ∥f x∥,
from hf.eventually (eventually_gt_at_top _),
exact ⟨c, hc, (this.and hsl).exists.imp (λ d hd, ⟨hd.2, hd.1⟩)⟩ },
specialize hsub c hc d hd, specialize hfd c hc d hd,
replace hg : ∀ x ∈ Ι c d, ∥deriv f x∥ ≤ C * ∥g x∥, from λ z hz, hg c hc d hd z ⟨hz.1.le, hz.2⟩,
have hg_ae : ∀ᵐ x ∂(volume.restrict (Ι c d)), ∥deriv f x∥ ≤ C * ∥g x∥,
from (ae_restrict_mem measurable_set_interval_oc).mono hg,
have hsub' : Ι c d ⊆ Ι a b,
from interval_oc_subset_interval_oc_of_interval_subset_interval hsub,
have hfi : interval_integrable (deriv f) volume c d,
from (hgi.mono_set hsub).mono_fun' (ae_measurable_deriv _ _) hg_ae,
refine hlt.not_le (sub_le_iff_le_add'.1 _),
calc ∥f d∥ - ∥f c∥ ≤ ∥f d - f c∥ : norm_sub_norm_le _ _
... = ∥∫ x in c..d, deriv f x∥ : congr_arg _ (integral_deriv_eq_sub hfd hfi).symm
... = ∥∫ x in Ι c d, deriv f x∥ : norm_integral_eq_norm_integral_Ioc _
... ≤ ∫ x in Ι c d, ∥deriv f x∥ : norm_integral_le_integral_norm _
... ≤ ∫ x in Ι c d, C * ∥g x∥ :
set_integral_mono_on hfi.norm.def (hgi.def.mono_set hsub') measurable_set_interval_oc hg
... ≤ ∫ x in Ι a b, C * ∥g x∥ :
set_integral_mono_set hgi.def (ae_of_all _ $ λ x, mul_nonneg hC₀ (norm_nonneg _))
hsub'.eventually_le
end
/-- If `a ≠ b`, `c ∈ [a, b]`, `f` is differentiable in the neighborhood of `c` within
`[a, b] \ {c}`, `∥f x∥ → ∞` as `x → c` within `[a, b] \ {c}`, and `f' = O(g)` along
`𝓝[[a, b] \ {c}] c`, where `f'` is the derivative of `f`, then `g` is not interval integrable on
`a..b`. -/
lemma not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_within_diff_singleton
{f : ℝ → E} {g : ℝ → F} {a b c : ℝ} (hne : a ≠ b) (hc : c ∈ [a, b])
(h_deriv : ∀ᶠ x in 𝓝[[a, b] \ {c}] c, differentiable_at ℝ f x)
(h_infty : tendsto (λ x, ∥f x∥) (𝓝[[a, b] \ {c}] c) at_top)
(hg : is_O (deriv f) g (𝓝[[a, b] \ {c}] c)) :
¬interval_integrable g volume a b :=
begin
obtain ⟨l, hl, hl', hle, hmem⟩ : ∃ l : filter ℝ, tendsto_Ixx_class Icc l l ∧ l.ne_bot ∧
l ≤ 𝓝 c ∧ [a, b] \ {c} ∈ l,
{ cases (min_lt_max.2 hne).lt_or_lt c with hlt hlt,
{ refine ⟨𝓝[<] c, infer_instance, infer_instance, inf_le_left, _⟩,
rw ← Iic_diff_right,
exact diff_mem_nhds_within_diff (Icc_mem_nhds_within_Iic ⟨hlt, hc.2⟩) _ },
{ refine ⟨𝓝[>] c, infer_instance, infer_instance, inf_le_left, _⟩,
rw ← Ici_diff_left,
exact diff_mem_nhds_within_diff (Icc_mem_nhds_within_Ici ⟨hc.1, hlt⟩) _ } },
resetI,
have : l ≤ 𝓝[[a, b] \ {c}] c, from le_inf hle (le_principal_iff.2 hmem),
exact not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_filter l
(mem_of_superset hmem (diff_subset _ _))
(h_deriv.filter_mono this) (h_infty.mono_left this) (hg.mono this),
end
/-- If `f` is differentiable in a punctured neighborhood of `c`, `∥f x∥ → ∞` as `x → c` (more
formally, along the filter `𝓝[≠] c`), and `f' = O(g)` along `𝓝[≠] c`, where `f'` is the derivative
of `f`, then `g` is not interval integrable on any nontrivial interval `a..b` such that
`c ∈ [a, b]`. -/
lemma not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured {f : ℝ → E} {g : ℝ → F}
{a b c : ℝ} (h_deriv : ∀ᶠ x in 𝓝[≠] c, differentiable_at ℝ f x)
(h_infty : tendsto (λ x, ∥f x∥) (𝓝[≠] c) at_top) (hg : is_O (deriv f) g (𝓝[≠] c))
(hne : a ≠ b) (hc : c ∈ [a, b]) :
¬interval_integrable g volume a b :=
have 𝓝[[a, b] \ {c}] c ≤ 𝓝[≠] c, from nhds_within_mono _ (inter_subset_right _ _),
not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_within_diff_singleton hne hc
(h_deriv.filter_mono this) (h_infty.mono_left this) (hg.mono this)
/-- If `f` grows in the punctured neighborhood of `c : ℝ` at least as fast as `1 / (x - c)`,
then it is not interval integrable on any nontrivial interval `a..b`, `c ∈ [a, b]`. -/
lemma not_interval_integrable_of_sub_inv_is_O_punctured {f : ℝ → F} {a b c : ℝ}
(hf : is_O (λ x, (x - c)⁻¹) f (𝓝[≠] c)) (hne : a ≠ b) (hc : c ∈ [a, b]) :
¬interval_integrable f volume a b :=
begin
have A : ∀ᶠ x in 𝓝[≠] c, has_deriv_at (λ x, real.log (x - c)) (x - c)⁻¹ x,
{ filter_upwards [self_mem_nhds_within] with x hx,
simpa using ((has_deriv_at_id x).sub_const c).log (sub_ne_zero.2 hx) },
have B : tendsto (λ x, ∥real.log (x - c)∥) (𝓝[≠] c) at_top,
{ refine tendsto_abs_at_bot_at_top.comp (real.tendsto_log_nhds_within_zero.comp _),
rw ← sub_self c,
exact ((has_deriv_at_id c).sub_const c).tendsto_punctured_nhds one_ne_zero },
exact not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured
(A.mono (λ x hx, hx.differentiable_at)) B
(hf.congr' (A.mono $ λ x hx, hx.deriv.symm) eventually_eq.rfl) hne hc
end
/-- The function `λ x, (x - c)⁻¹` is integrable on `a..b` if and only if `a = b` or `c ∉ [a, b]`. -/
@[simp] lemma interval_integrable_sub_inv_iff {a b c : ℝ} :
interval_integrable (λ x, (x - c)⁻¹) volume a b ↔ a = b ∨ c ∉ [a, b] :=
begin
split,
{ refine λ h, or_iff_not_imp_left.2 (λ hne hc, _),
exact not_interval_integrable_of_sub_inv_is_O_punctured (is_O_refl _ _) hne hc h },
{ rintro (rfl|h₀),
exacts [interval_integrable.refl,
interval_integrable_inv (λ x hx, sub_ne_zero.2 $ ne_of_mem_of_not_mem hx h₀)
(continuous_on_id.sub continuous_on_const)] }
end
/-- The function `λ x, x⁻¹` is integrable on `a..b` if and only if `a = b` or `0 ∉ [a, b]`. -/
@[simp] lemma interval_integrable_inv_iff {a b : ℝ} :
interval_integrable (λ x, x⁻¹) volume a b ↔ a = b ∨ (0 : ℝ) ∉ [a, b] :=
by simp only [← interval_integrable_sub_inv_iff, sub_zero]
|
74daf73fe702d709e4c348fb986cd3615b773a8e | 947b78d97130d56365ae2ec264df196ce769371a | /tests/compiler/rbmap_library.lean | a79b14e79c0b5aa9d3486ce6fc14a2752cf3b0b8 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,295 | lean | import Std
open Std
def check (b : Bool) : IO Unit :=
unless b $ IO.println "ERROR"
def sz {α β : Type} {lt : α → α → Bool} (m : RBMap α β lt) : Nat :=
m.fold (fun sz _ _ => sz+1) 0
def depth {α β : Type} {lt : α → α → Bool} (m : RBMap α β lt) : Nat :=
m.depth Nat.max
def tst1 : IO Unit :=
do let Map := RBMap String Nat (fun a b => a < b);
let m : Map := {};
let m := m.insert "hello" 0;
let m := m.insert "world" 1;
check (m.find? "hello" == some 0);
check (m.find? "world" == some 1);
let m := m.erase "hello";
check (m.find? "hello" == none);
check (m.find? "world" == some 1);
pure ()
def tst2 : IO Unit :=
do let Map := RBMap Nat Nat (fun a b => a < b);
let m : Map := {};
let n : Nat := 10000;
let m := n.fold (fun i (m : Map) => m.insert i (i*10)) m;
check (m.all (fun k v => v == k*10));
check (sz m == n);
IO.println (">> " ++ toString (depth m) ++ ", " ++ toString (sz m));
let m := (n/2).fold (fun i (m : Map) => m.erase (2*i)) m;
check (m.all (fun k v => v == k*10));
check (sz m == n / 2);
IO.println (">> " ++ toString (depth m) ++ ", " ++ toString (sz m));
pure ()
abbrev Map := RBMap Nat Nat (fun a b => a < b)
def mkRandMap (max : Nat) : Nat → Map → Array (Nat × Nat) → IO (Map × Array (Nat × Nat))
| 0, m, a => pure (m, a)
| n+1, m, a => do
k ← IO.rand 0 max;
v ← IO.rand 0 max;
if m.find? k == none then do
let m := m.insert k v;
let a := a.push (k, v);
mkRandMap n m a
else
mkRandMap n m a
def tst3 (seed : Nat) (n : Nat) (max : Nat) : IO Unit :=
do IO.setRandSeed seed;
(m, a) ← mkRandMap max n {} Array.empty;
check (sz m == a.size);
check (a.all (fun ⟨k, v⟩ => m.find? k == some v));
IO.println ("tst3 size: " ++ toString a.size);
let m := a.iterate m (fun i ⟨k, v⟩ m => if i.val % 2 == 0 then m.erase k else m);
check (sz m == a.size / 2);
a.iterateM () (fun i ⟨k, v⟩ _ => when (i.val % 2 == 1) (check (m.find? k == some v)));
IO.println ("tst3 after, depth: " ++ toString (depth m) ++ ", size: " ++ toString (sz m));
pure ()
def main (xs : List String) : IO Unit :=
tst1 *> tst2 *>
tst3 1 1000 20000 *>
tst3 2 1000 40000 *>
tst3 3 100 4000 *>
tst3 4 5000 100000 *>
tst3 5 1000 40000 *>
pure ()
|
5b307bcd9ec395510245da442ac494b0b63b1a9e | 367134ba5a65885e863bdc4507601606690974c1 | /src/algebra/big_operators/ring.lean | e29ff4bccbf93a82cc5ed350920915039ae2227c | [
"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,925 | 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 algebra.big_operators.basic
import data.finset.pi
import data.finset.powerset
/-!
# Results about big operators with values in a (semi)ring
We prove results about big operators that involve some interaction between
multiplicative and additive structures on the values being combined.
-/
universes u v w
open_locale big_operators
variables {α : Type u} {β : Type v} {γ : Type w}
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {b : β} {f g : α → β}
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 :=
by simp only [div_eq_mul_inv, sum_mul]
section comm_semiring
variables [comm_semiring β]
/-- 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_bUnion 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, pi_cons_injective 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' with ⟨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 ({true, false} : finset Prop), if p then f a else g a : by simp
... = ∑ p in (s.pi (λ _, {true, false}) : 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_iff, 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
theorem dvd_sum {b : β} {s : finset α} {f : α → β}
(h : ∀ x ∈ s, b ∣ f x) : b ∣ ∑ 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)
@[norm_cast]
lemma prod_nat_cast (s : finset α) (f : α → ℕ) :
↑(∏ x in s, f x : ℕ) = (∏ x in s, (f x : β)) :=
(nat.cast_ring_hom β).map_prod f s
end comm_semiring
/-- 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 α] [comm_monoid β] {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
/-- A product over `powerset s` is equal to the double product over
sets of subsets of `s` with `card s = k`, for `k = 1, ... , card s`. -/
lemma prod_powerset [comm_monoid β] (s : finset α) (f : finset α → β) :
∏ t in powerset s, f t = ∏ j in range (card s + 1), ∏ t in powerset_len j s, f t :=
begin
classical,
rw [powerset_card_bUnion, prod_bUnion],
intros i hi j hj hij,
rw [powerset_len_eq_filter, powerset_len_eq_filter, disjoint_filter],
intros x hx hc hnc,
apply hij,
rwa ← hc,
end
/-- A sum over `powerset s` is equal to the double sum over
sets of subsets of `s` with `card s = k`, for `k = 1, ... , card s`. -/
lemma sum_powerset [add_comm_monoid β] (s : finset α) (f : finset α → β) :
∑ t in powerset s, f t = ∑ j in range (card s + 1), ∑ t in powerset_len j s, f t :=
begin
classical,
rw [powerset_card_bUnion, sum_bUnion],
intros i hi j hj hij,
rw [powerset_len_eq_filter, powerset_len_eq_filter, disjoint_filter],
intros x hx hc hnc,
apply hij,
rwa ← hc,
end
end finset
|
192bd49e6cc5930d60bb928219877df859ca706a | a726f88081e44db9edfd14d32cfe9c4393ee56a4 | /world_experiments/world9/level4.lean | dcc858985e98e71c5d7d84a71068f177eb984776 | [] | no_license | b-mehta/natural_number_game | 80451bf10277adc89a55dbe8581692c36d822462 | 9faf799d0ab48ecbc89b3d70babb65ba64beee3b | refs/heads/master | 1,598,525,389,186 | 1,573,516,674,000 | 1,573,516,674,000 | 217,339,684 | 0 | 0 | null | 1,571,933,100,000 | 1,571,933,099,000 | null | UTF-8 | Lean | false | false | 795 | lean | import game.world5.level3 -- hide
namespace mynat -- hide
/-
# World 5 : Inequality world
## Level 4 : `le_trans`
-/
/- Lemma
≤ is transitive. In other words, if $a\leq b$ and $b\leq c$ then $a\leq c$.
-/
theorem le_trans (a b c : mynat) (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
begin [less_leaky]
cases hab with d hd,
cases hbc with e he,
use (d + e),
rw ←add_assoc,
rw ←hd,
assumption,
end
/-
Congratulations -- you just proved that the natural numbers are a preorder.
-/
instance : preorder mynat := by structure_helper -- hide
end mynat -- hide
/-
I think that to go further, I (Kevin) have to teach you that implication is a function,
and Mohammad has to make the worlds in this game depend on each other in a non-linear
manner. This is all to come in V1.1.
-/ |
5c7eb8cf0a441798a61d83e8188600fea7ade3d0 | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /library/theories/group_theory/hom.lean | 4eba4563eee0dfe5f0f0756760a0b05dd41a523f | [
"Apache-2.0"
] | permissive | YHVHvx/lean | 732bf0fb7a298cd7fe0f15d82f8e248c11db49e9 | 038369533e0136dd395dc252084d3c1853accbf2 | refs/heads/master | 1,610,701,080,210 | 1,449,128,595,000 | 1,449,128,595,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,075 | 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.set .subgroup
namespace group
open algebra
-- ⁻¹ in eq.ops conflicts with group ⁻¹
-- open eq.ops
notation H1 ▸ H2 := eq.subst H1 H2
open set
open function
open group.ops
open quot
local attribute set [reducible]
section defs
variables {A B : Type}
variable [s1 : group A]
variable [s2 : group B]
include s1
include s2
-- the Prop of being hom
definition homomorphic [reducible] (f : A → B) : Prop := ∀ a b, f (a*b) = (f a)*(f b)
-- type class for inference
structure is_hom_class [class] (f : A → B) : Type :=
(is_hom : homomorphic f)
-- the proof of hom_prop if the class can be inferred
definition is_hom (f : A → B) [h : is_hom_class f] : homomorphic f :=
@is_hom_class.is_hom A B s1 s2 f h
definition ker (f : A → B) [h : is_hom_class f] : set A := {a : A | f a = 1}
definition isomorphic (f : A → B) := injective f ∧ homomorphic f
structure is_iso_class [class] (f : A → B) extends is_hom_class f : Type :=
(inj : injective f)
lemma iso_is_inj (f : A → B) [h : is_iso_class f] : injective f:=
@is_iso_class.inj A B s1 s2 f h
lemma iso_is_iso (f : A → B) [h : is_iso_class f] : isomorphic f:=
and.intro (iso_is_inj f) (is_hom f)
end defs
section
variables {A B : Type}
variable [s1 : group A]
definition id_is_iso [instance] : @is_hom_class A A s1 s1 (@id A) :=
is_hom_class.mk (take a b, rfl)
variable [s2 : group B]
include s1
include s2
variable f : A → B
variable [h : is_hom_class f]
include h
theorem hom_map_one : f 1 = 1 :=
have P : f 1 = (f 1) * (f 1), from
calc f 1 = f (1*1) : mul_one
... = (f 1) * (f 1) : is_hom f,
eq.symm (mul.right_inv (f 1) ▸ (mul_inv_eq_of_eq_mul P))
theorem hom_map_inv (a : A) : f a⁻¹ = (f a)⁻¹ :=
assert P : f 1 = 1, from hom_map_one f,
assert P1 : f (a⁻¹ * a) = 1, from (eq.symm (mul.left_inv a)) ▸ P,
assert P2 : (f a⁻¹) * (f a) = 1, from (is_hom f a⁻¹ a) ▸ P1,
assert P3 : (f a⁻¹) * (f a) = (f a)⁻¹ * (f a), from eq.symm (mul.left_inv (f a)) ▸ P2,
mul_right_cancel P3
theorem hom_map_mul_closed (H : set A) : mul_closed_on H → mul_closed_on (f '[H]) :=
assume Pclosed, assume b1, assume b2,
assume Pb1 : b1 ∈ f '[ H], assume Pb2 : b2 ∈ f '[ H],
obtain a1 (Pa1 : a1 ∈ H ∧ f a1 = b1), from Pb1,
obtain a2 (Pa2 : a2 ∈ H ∧ f a2 = b2), from Pb2,
assert Pa1a2 : a1 * a2 ∈ H, from Pclosed a1 a2 (and.left Pa1) (and.left Pa2),
assert Pb1b2 : f (a1 * a2) = b1 * b2, from calc
f (a1 * a2) = f a1 * f a2 : is_hom f a1 a2
... = b1 * f a2 : {and.right Pa1}
... = b1 * b2 : {and.right Pa2},
mem_image Pa1a2 Pb1b2
lemma ker.has_one : 1 ∈ ker f := hom_map_one f
lemma ker.has_inv : subgroup.has_inv (ker f) :=
take a, assume Pa : f a = 1, calc
f a⁻¹ = (f a)⁻¹ : by rewrite (hom_map_inv f)
... = 1⁻¹ : by rewrite Pa
... = 1 : by rewrite one_inv
lemma ker.mul_closed : mul_closed_on (ker f) :=
take x y, assume (Px : f x = 1) (Py : f y = 1), calc
f (x*y) = (f x) * (f y) : by rewrite [is_hom f]
... = 1 : by rewrite [Px, Py, mul_one]
lemma ker.normal : same_left_right_coset (ker f) :=
take a, funext (assume x, begin
esimp [ker, set_of, glcoset, grcoset],
rewrite [*(is_hom f), mul_eq_one_iff_mul_eq_one (f a⁻¹) (f x)]
end)
definition ker_is_normal_subgroup : is_normal_subgroup (ker f) :=
is_normal_subgroup.mk (ker.has_one f) (ker.mul_closed f) (ker.has_inv f)
(ker.normal f)
-- additional subgroup variable
variable {H : set A}
variable [is_subgH : is_subgroup H]
include is_subgH
theorem hom_map_subgroup : is_subgroup (f '[H]) :=
have Pone : 1 ∈ f '[H], from mem_image (@subg_has_one _ _ H _) (hom_map_one f),
have Pclosed : mul_closed_on (f '[H]), from hom_map_mul_closed f H subg_mul_closed,
assert Pinv : ∀ b, b ∈ f '[H] → b⁻¹ ∈ f '[H], from
assume b, assume Pimg,
obtain a (Pa : a ∈ H ∧ f a = b), from Pimg,
assert Painv : a⁻¹ ∈ H, from subg_has_inv a (and.left Pa),
assert Pfainv : (f a)⁻¹ ∈ f '[H], from mem_image Painv (hom_map_inv f a),
and.right Pa ▸ Pfainv,
is_subgroup.mk Pone Pclosed Pinv
end
section hom_theorem
variables {A B : Type}
variable [s1 : group A]
variable [s2 : group B]
include s1
include s2
variable {f : A → B}
variable [h : is_hom_class f]
include h
definition ker_nsubg [instance] : is_normal_subgroup (ker f) :=
is_normal_subgroup.mk (ker.has_one f) (ker.mul_closed f)
(ker.has_inv f) (ker.normal f)
definition quot_over_ker [instance] : group (coset_of (ker f)) := mk_quotient_group (ker f)
-- under the wrap the tower of concepts collapse to a simple condition
example (a x : A) : (x ∈ a ∘> ker f) = (f (a⁻¹*x) = 1) := rfl
lemma ker_coset_same_val (a b : A): same_lcoset (ker f) a b → f a = f b :=
assume Psame,
assert Pin : f (b⁻¹*a) = 1, from subg_same_lcoset_in_lcoset a b Psame,
assert P : (f b)⁻¹ * (f a) = 1, from calc
(f b)⁻¹ * (f a) = (f b⁻¹) * (f a) : (hom_map_inv f)
... = f (b⁻¹*a) : by rewrite [is_hom f]
... = 1 : by rewrite Pin,
eq.symm (inv_inv (f b) ▸ inv_eq_of_mul_eq_one P)
definition ker_natural_map : (coset_of (ker f)) → B :=
quot.lift f ker_coset_same_val
example (a : A) : ker_natural_map ⟦a⟧ = f a := rfl
lemma ker_coset_hom (a b : A) :
ker_natural_map (⟦a⟧*⟦b⟧) = (ker_natural_map ⟦a⟧) * (ker_natural_map ⟦b⟧) := calc
ker_natural_map (⟦a⟧*⟦b⟧) = ker_natural_map ⟦a*b⟧ : rfl
... = f (a*b) : rfl
... = (f a) * (f b) : by rewrite [is_hom f]
... = (ker_natural_map ⟦a⟧) * (ker_natural_map ⟦b⟧) : rfl
lemma ker_map_is_hom : homomorphic (ker_natural_map : coset_of (ker f) → B) :=
take aK bK,
quot.ind (λ a, quot.ind (λ b, ker_coset_hom a b) bK) aK
lemma ker_coset_inj (a b : A) : (ker_natural_map ⟦a⟧ = ker_natural_map ⟦b⟧) → ⟦a⟧ = ⟦b⟧ :=
assume Pfeq : f a = f b,
assert Painb : a ∈ b ∘> ker f, from calc
f (b⁻¹*a) = (f b⁻¹) * (f a) : by rewrite [is_hom f]
... = (f b)⁻¹ * (f a) : by rewrite (hom_map_inv f)
... = (f a)⁻¹ * (f a) : by rewrite Pfeq
... = 1 : by rewrite (mul.left_inv (f a)),
quot.sound (@subg_in_lcoset_same_lcoset _ _ (ker f) _ a b Painb)
lemma ker_map_is_inj : injective (ker_natural_map : coset_of (ker f) → B) :=
take aK bK,
quot.ind (λ a, quot.ind (λ b, ker_coset_inj a b) bK) aK
-- a special case of the fundamental homomorphism theorem or the first isomorphism theorem
theorem first_isomorphism_theorem : isomorphic (ker_natural_map : coset_of (ker f) → B) :=
and.intro ker_map_is_inj ker_map_is_hom
end hom_theorem
end group
|
01114003025e8d2d7ed8303dd9d0d4b7d794d5ad | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/zmod/basic.lean | 807cd3aff05e854e8796b608fd0180c75c21ac43 | [
"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 | 38,265 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import algebra.char_p.basic
import data.fintype.units
import data.nat.parity
import tactic.fin_cases
/-!
# Integers mod `n`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `zmod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
* `val_min_abs` returns the integer closest to zero in the equivalence class.
* A coercion `cast` is defined from `zmod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
open function
namespace zmod
instance : char_zero (zmod 0) := (by apply_instance : char_zero ℤ)
/-- `val a` is a natural number defined as:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
See `zmod.val_min_abs` for a variant that takes values in the integers.
-/
def val : Π {n : ℕ}, zmod n → ℕ
| 0 := int.nat_abs
| (n+1) := (coe : fin (n + 1) → ℕ)
lemma val_lt {n : ℕ} [ne_zero n] (a : zmod n) : a.val < n :=
begin
casesI n,
{ cases ne_zero.ne 0 rfl },
exact fin.is_lt a
end
lemma val_le {n : ℕ} [ne_zero n] (a : zmod n) : a.val ≤ n :=
a.val_lt.le
@[simp] lemma val_zero : ∀ {n}, (0 : zmod n).val = 0
| 0 := rfl
| (n+1) := rfl
@[simp] lemma val_one' : (1 : zmod 0).val = 1 := rfl
@[simp] lemma val_neg' {n : zmod 0} : (-n).val = n.val := by simp [val]
@[simp] lemma val_mul' {m n : zmod 0} : (m * n).val = m.val * n.val :=
by simp [val, int.nat_abs_mul]
lemma val_nat_cast {n : ℕ} (a : ℕ) : (a : zmod n).val = a % n :=
begin
casesI n,
{ rw [nat.mod_zero],
exact int.nat_abs_of_nat a, },
rw ← fin.of_nat_eq_coe,
refl
end
instance (n : ℕ) : char_p (zmod n) n :=
{ cast_eq_zero_iff :=
begin
intro k,
cases n,
{ simp only [zero_dvd_iff, int.coe_nat_eq_zero], },
rw [fin.eq_iff_veq],
show (k : zmod (n+1)).val = (0 : zmod (n+1)).val ↔ _,
rw [val_nat_cast, val_zero, nat.dvd_iff_mod_eq_zero],
end }
@[simp] lemma add_order_of_one (n : ℕ) : add_order_of (1 : zmod n) = n :=
char_p.eq _ (char_p.add_order_of_one _) (zmod.char_p n)
/-- This lemma works in the case in which `zmod n` is not infinite, i.e. `n ≠ 0`. The version
where `a ≠ 0` is `add_order_of_coe'`. -/
@[simp] lemma add_order_of_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) :
add_order_of (a : zmod n) = n / n.gcd a :=
begin
cases a,
simp [nat.pos_of_ne_zero n0],
rw [← nat.smul_one_eq_coe, add_order_of_nsmul' _ a.succ_ne_zero, zmod.add_order_of_one],
end
/-- This lemma works in the case in which `a ≠ 0`. The version where
`zmod n` is not infinite, i.e. `n ≠ 0`, is `add_order_of_coe`. -/
@[simp] lemma add_order_of_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) :
add_order_of (a : zmod n) = n / n.gcd a :=
by rw [← nat.smul_one_eq_coe, add_order_of_nsmul' _ a0, zmod.add_order_of_one]
/-- We have that `ring_char (zmod n) = n`. -/
lemma ring_char_zmod_n (n : ℕ) : ring_char (zmod n) = n :=
by { rw ring_char.eq_iff, exact zmod.char_p n, }
@[simp] lemma nat_cast_self (n : ℕ) : (n : zmod n) = 0 :=
char_p.cast_eq_zero (zmod n) n
@[simp] lemma nat_cast_self' (n : ℕ) : (n + 1 : zmod (n + 1)) = 0 :=
by rw [← nat.cast_add_one, nat_cast_self (n + 1)]
section universal_property
variables {n : ℕ} {R : Type*}
section
variables [add_group_with_one R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `zmod.cast_hom` for a bundled version. -/
def cast : Π {n : ℕ}, zmod n → R
| 0 := int.cast
| (n+1) := λ i, i.val
-- see Note [coercion into rings]
@[priority 900] instance (n : ℕ) : has_coe_t (zmod n) R := ⟨cast⟩
@[simp] lemma cast_zero : ((0 : zmod n) : R) = 0 :=
by cases n; simp
lemma cast_eq_val [ne_zero n] (a : zmod n) : (a : R) = a.val :=
begin
casesI n,
{ cases ne_zero.ne 0 rfl },
refl,
end
variables {S : Type*} [add_group_with_one S]
@[simp] lemma _root_.prod.fst_zmod_cast (a : zmod n) : (a : R × S).fst = a :=
by cases n; simp
@[simp] lemma _root_.prod.snd_zmod_cast (a : zmod n) : (a : R × S).snd = a :=
by cases n; simp
end
/-- So-named because the coercion is `nat.cast` into `zmod`. For `nat.cast` into an arbitrary ring,
see `zmod.nat_cast_val`. -/
lemma nat_cast_zmod_val {n : ℕ} [ne_zero n] (a : zmod n) : (a.val : zmod n) = a :=
begin
casesI n,
{ cases ne_zero.ne 0 rfl },
{ apply fin.coe_coe_eq_self }
end
lemma nat_cast_right_inverse [ne_zero n] : function.right_inverse val (coe : ℕ → zmod n) :=
nat_cast_zmod_val
lemma nat_cast_zmod_surjective [ne_zero n] : function.surjective (coe : ℕ → zmod n) :=
nat_cast_right_inverse.surjective
/-- So-named because the outer coercion is `int.cast` into `zmod`. For `int.cast` into an arbitrary
ring, see `zmod.int_cast_cast`. -/
@[norm_cast] lemma int_cast_zmod_cast (a : zmod n) : ((a : ℤ) : zmod n) = a :=
begin
cases n,
{ rw [int.cast_id a, int.cast_id a], },
{ rw [coe_coe, int.cast_coe_nat, fin.coe_coe_eq_self] }
end
lemma int_cast_right_inverse : function.right_inverse (coe : zmod n → ℤ) (coe : ℤ → zmod n) :=
int_cast_zmod_cast
lemma int_cast_surjective : function.surjective (coe : ℤ → zmod n) :=
int_cast_right_inverse.surjective
@[norm_cast]
lemma cast_id : ∀ n (i : zmod n), ↑i = i
| 0 i := int.cast_id i
| (n+1) i := nat_cast_zmod_val i
@[simp]
lemma cast_id' : (coe : zmod n → zmod n) = id := funext (cast_id n)
variables (R) [ring R]
/-- The coercions are respectively `nat.cast` and `zmod.cast`. -/
@[simp] lemma nat_cast_comp_val [ne_zero n] :
(coe : ℕ → R) ∘ (val : zmod n → ℕ) = coe :=
begin
casesI n,
{ cases ne_zero.ne 0 rfl },
refl
end
/-- The coercions are respectively `int.cast`, `zmod.cast`, and `zmod.cast`. -/
@[simp] lemma int_cast_comp_cast : (coe : ℤ → R) ∘ (coe : zmod n → ℤ) = coe :=
begin
cases n,
{ exact congr_arg ((∘) int.cast) zmod.cast_id', },
{ ext, simp }
end
variables {R}
@[simp] lemma nat_cast_val [ne_zero n] (i : zmod n) : (i.val : R) = i :=
congr_fun (nat_cast_comp_val R) i
@[simp] lemma int_cast_cast (i : zmod n) : ((i : ℤ) : R) = i :=
congr_fun (int_cast_comp_cast R) i
lemma coe_add_eq_ite {n : ℕ} (a b : zmod n) :
(↑(a + b) : ℤ) = if (n : ℤ) ≤ a + b then a + b - n else a + b :=
begin
cases n,
{ simp },
simp only [coe_coe, fin.coe_add_eq_ite,
← int.coe_nat_add, ← int.coe_nat_succ, int.coe_nat_le],
split_ifs with h,
{ exact int.coe_nat_sub h },
{ refl }
end
section char_dvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variables {n} {m : ℕ} [char_p R m]
@[simp] lemma cast_one (h : m ∣ n) : ((1 : zmod n) : R) = 1 :=
begin
casesI n,
{ exact int.cast_one },
show ((1 % (n+1) : ℕ) : R) = 1,
cases n, { rw [nat.dvd_one] at h, substI m, apply subsingleton.elim },
rw nat.mod_eq_of_lt,
{ exact nat.cast_one },
exact nat.lt_of_sub_eq_succ rfl
end
lemma cast_add (h : m ∣ n) (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
begin
casesI n,
{ apply int.cast_add },
simp only [coe_coe],
symmetry,
erw [fin.coe_add, ← nat.cast_add, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ m],
exact h.trans (nat.dvd_sub_mod _),
end
lemma cast_mul (h : m ∣ n) (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
begin
casesI n,
{ apply int.cast_mul },
simp only [coe_coe],
symmetry,
erw [fin.coe_mul, ← nat.cast_mul, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ m],
exact h.trans (nat.dvd_sub_mod _),
end
/-- The canonical ring homomorphism from `zmod n` to a ring of characteristic `n`.
See also `zmod.lift` (in `data.zmod.quotient`) for a generalized version working in `add_group`s.
-/
def cast_hom (h : m ∣ n) (R : Type*) [ring R] [char_p R m] : zmod n →+* R :=
{ to_fun := coe,
map_zero' := cast_zero,
map_one' := cast_one h,
map_add' := cast_add h,
map_mul' := cast_mul h }
@[simp] lemma cast_hom_apply {h : m ∣ n} (i : zmod n) : cast_hom h R i = i := rfl
@[simp, norm_cast]
lemma cast_sub (h : m ∣ n) (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
(cast_hom h R).map_sub a b
@[simp, norm_cast]
lemma cast_neg (h : m ∣ n) (a : zmod n) : ((-a : zmod n) : R) = -a :=
(cast_hom h R).map_neg a
@[simp, norm_cast]
lemma cast_pow (h : m ∣ n) (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
(cast_hom h R).map_pow a k
@[simp, norm_cast]
lemma cast_nat_cast (h : m ∣ n) (k : ℕ) : ((k : zmod n) : R) = k :=
map_nat_cast (cast_hom h R) k
@[simp, norm_cast]
lemma cast_int_cast (h : m ∣ n) (k : ℤ) : ((k : zmod n) : R) = k := map_int_cast (cast_hom h R) k
end char_dvd
section char_eq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [char_p R n]
@[simp] lemma cast_one' : ((1 : zmod n) : R) = 1 :=
cast_one dvd_rfl
@[simp] lemma cast_add' (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
cast_add dvd_rfl a b
@[simp] lemma cast_mul' (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
cast_mul dvd_rfl a b
@[simp] lemma cast_sub' (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
cast_sub dvd_rfl a b
@[simp] lemma cast_pow' (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
lemma cast_nat_cast' (k : ℕ) : ((k : zmod n) : R) = k :=
cast_nat_cast dvd_rfl k
@[simp, norm_cast]
lemma cast_int_cast' (k : ℤ) : ((k : zmod n) : R) = k :=
cast_int_cast dvd_rfl k
variables (R)
lemma cast_hom_injective : function.injective (zmod.cast_hom (dvd_refl n) R) :=
begin
rw injective_iff_map_eq_zero,
intro x,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective x,
rw [map_int_cast, char_p.int_cast_eq_zero_iff R n,
char_p.int_cast_eq_zero_iff (zmod n) n],
exact id
end
lemma cast_hom_bijective [fintype R] (h : fintype.card R = n) :
function.bijective (zmod.cast_hom (dvd_refl n) R) :=
begin
haveI : ne_zero n :=
⟨begin
intro hn,
rw hn at h,
exact (fintype.card_eq_zero_iff.mp h).elim' 0
end⟩,
rw [fintype.bijective_iff_injective_and_card, zmod.card, h, eq_self_iff_true, and_true],
apply zmod.cast_hom_injective
end
/-- The unique ring isomorphism between `zmod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ring_equiv [fintype R] (h : fintype.card R = n) : zmod n ≃+* R :=
ring_equiv.of_bijective _ (zmod.cast_hom_bijective R h)
/-- The identity between `zmod m` and `zmod n` when `m = n`, as a ring isomorphism. -/
def ring_equiv_congr {m n : ℕ} (h : m = n) : zmod m ≃+* zmod n :=
begin
cases m; cases n,
{ exact ring_equiv.refl _ },
{ exfalso, exact n.succ_ne_zero h.symm },
{ exfalso, exact m.succ_ne_zero h },
{ exact
{ map_mul' := λ a b, begin
rw [order_iso.to_fun_eq_coe], ext,
rw [fin.coe_cast, fin.coe_mul, fin.coe_mul, fin.coe_cast, fin.coe_cast, ← h] end,
map_add' := λ a b, begin
rw [order_iso.to_fun_eq_coe], ext,
rw [fin.coe_cast, fin.coe_add, fin.coe_add, fin.coe_cast, fin.coe_cast, ← h] end,
..fin.cast h } }
end
end char_eq
end universal_property
lemma int_coe_eq_int_coe_iff (a b : ℤ) (c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [ZMOD c] :=
char_p.int_cast_eq_int_cast (zmod c) c
lemma int_coe_eq_int_coe_iff' (a b : ℤ) (c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a % c = b % c :=
zmod.int_coe_eq_int_coe_iff a b c
lemma nat_coe_eq_nat_coe_iff (a b c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [MOD c] :=
by simpa [int.coe_nat_modeq_iff] using zmod.int_coe_eq_int_coe_iff a b c
lemma nat_coe_eq_nat_coe_iff' (a b c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a % c = b % c :=
zmod.nat_coe_eq_nat_coe_iff a b c
lemma int_coe_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : zmod b) = 0 ↔ (b : ℤ) ∣ a :=
by rw [← int.cast_zero, zmod.int_coe_eq_int_coe_iff, int.modeq_zero_iff_dvd]
lemma int_coe_eq_int_coe_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : zmod c) = ↑b ↔ ↑c ∣ b-a :=
begin
rw [zmod.int_coe_eq_int_coe_iff, int.modeq_iff_dvd],
end
lemma nat_coe_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : zmod b) = 0 ↔ b ∣ a :=
by rw [← nat.cast_zero, zmod.nat_coe_eq_nat_coe_iff, nat.modeq_zero_iff_dvd]
lemma val_int_cast {n : ℕ} (a : ℤ) [ne_zero n] : ↑(a : zmod n).val = a % n :=
begin
have hle : (0 : ℤ) ≤ ↑(a : zmod n).val := int.coe_nat_nonneg _,
have hlt : ↑(a : zmod n).val < (n : ℤ) := int.coe_nat_lt.mpr (zmod.val_lt a),
refine (int.mod_eq_of_lt hle hlt).symm.trans _,
rw [←zmod.int_coe_eq_int_coe_iff', int.cast_coe_nat, zmod.nat_cast_val, zmod.cast_id],
end
lemma coe_int_cast {n : ℕ} (a : ℤ) : ↑(a : zmod n) = a % n :=
begin
cases n,
{ rw [int.coe_nat_zero, int.mod_zero, int.cast_id, int.cast_id] },
{ rw [←val_int_cast, val, coe_coe] },
end
@[simp] lemma val_neg_one (n : ℕ) : (-1 : zmod n.succ).val = n :=
begin
rw [val, fin.coe_neg],
cases n,
{ rw [nat.mod_one] },
{ rw [fin.coe_one, nat.succ_add_sub_one, nat.mod_eq_of_lt (nat.lt.base _)] },
end
/-- `-1 : zmod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/
lemma cast_neg_one {R : Type*} [ring R] (n : ℕ) : ↑(-1 : zmod n) = (n - 1 : R) :=
begin
cases n,
{ rw [int.cast_neg, int.cast_one, nat.cast_zero, zero_sub] },
{ rw [←nat_cast_val, val_neg_one, nat.cast_succ, add_sub_cancel] },
end
lemma cast_sub_one {R : Type*} [ring R] {n : ℕ} (k : zmod n) :
((k - 1 : zmod n) : R) = (if k = 0 then n else k) - 1 :=
begin
split_ifs with hk,
{ rw [hk, zero_sub, zmod.cast_neg_one] },
{ cases n,
{ rw [int.cast_sub, int.cast_one] },
{ rw [←zmod.nat_cast_val, zmod.val, fin.coe_sub_one, if_neg],
{ rw [nat.cast_sub, nat.cast_one, coe_coe],
rwa [fin.ext_iff, fin.coe_zero, ←ne, ←nat.one_le_iff_ne_zero] at hk },
{ exact hk } } },
end
lemma nat_coe_zmod_eq_iff (p : ℕ) (n : ℕ) (z : zmod p) [ne_zero p] :
↑n = z ↔ ∃ k, n = z.val + p * k :=
begin
split,
{ rintro rfl,
refine ⟨n / p, _⟩,
rw [val_nat_cast, nat.mod_add_div] },
{ rintro ⟨k, rfl⟩,
rw [nat.cast_add, nat_cast_zmod_val, nat.cast_mul, nat_cast_self, zero_mul, add_zero] }
end
lemma int_coe_zmod_eq_iff (p : ℕ) (n : ℤ) (z : zmod p) [ne_zero p] :
↑n = z ↔ ∃ k, n = z.val + p * k :=
begin
split,
{ rintro rfl,
refine ⟨n / p, _⟩,
rw [val_int_cast, int.mod_add_div] },
{ rintro ⟨k, rfl⟩,
rw [int.cast_add, int.cast_mul, int.cast_coe_nat, int.cast_coe_nat, nat_cast_val,
zmod.nat_cast_self, zero_mul, add_zero, cast_id] }
end
@[push_cast, simp]
lemma int_cast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : zmod b) = (a : zmod b) :=
begin
rw zmod.int_coe_eq_int_coe_iff,
apply int.mod_modeq,
end
lemma ker_int_cast_add_hom (n : ℕ) :
(int.cast_add_hom (zmod n)).ker = add_subgroup.zmultiples n :=
by { ext, rw [int.mem_zmultiples_iff, add_monoid_hom.mem_ker,
int.coe_cast_add_hom, int_coe_zmod_eq_zero_iff_dvd] }
lemma ker_int_cast_ring_hom (n : ℕ) :
(int.cast_ring_hom (zmod n)).ker = ideal.span ({n} : set ℤ) :=
by { ext, rw [ideal.mem_span_singleton, ring_hom.mem_ker,
int.coe_cast_ring_hom, int_coe_zmod_eq_zero_iff_dvd] }
local attribute [semireducible] int.nonneg
@[simp] lemma nat_cast_to_nat (p : ℕ) :
∀ {z : ℤ} (h : 0 ≤ z), (z.to_nat : zmod p) = z
| (n : ℕ) h := by simp only [int.cast_coe_nat, int.to_nat_coe_nat]
| -[1+n] h := false.elim h
lemma val_injective (n : ℕ) [ne_zero n] :
function.injective (zmod.val : zmod n → ℕ) :=
begin
casesI n,
{ cases ne_zero.ne 0 rfl },
assume a b h,
ext,
exact h
end
lemma val_one_eq_one_mod (n : ℕ) : (1 : zmod n).val = 1 % n :=
by rw [← nat.cast_one, val_nat_cast]
lemma val_one (n : ℕ) [fact (1 < n)] : (1 : zmod n).val = 1 :=
by { rw val_one_eq_one_mod, exact nat.mod_eq_of_lt (fact.out _) }
lemma val_add {n : ℕ} [ne_zero n] (a b : zmod n) : (a + b).val = (a.val + b.val) % n :=
begin
casesI n,
{ cases ne_zero.ne 0 rfl },
{ apply fin.val_add }
end
lemma val_mul {n : ℕ} (a b : zmod n) : (a * b).val = (a.val * b.val) % n :=
begin
cases n,
{ rw nat.mod_zero, apply int.nat_abs_mul },
{ apply fin.val_mul }
end
instance nontrivial (n : ℕ) [fact (1 < n)] : nontrivial (zmod n) :=
⟨⟨0, 1, assume h, zero_ne_one $
calc 0 = (0 : zmod n).val : by rw val_zero
... = (1 : zmod n).val : congr_arg zmod.val h
... = 1 : val_one n ⟩⟩
instance nontrivial' : nontrivial (zmod 0) := int.nontrivial
/-- The inversion on `zmod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : Π (n : ℕ), zmod n → zmod n
| 0 i := int.sign i
| (n+1) i := nat.gcd_a i.val (n+1)
instance (n : ℕ) : has_inv (zmod n) := ⟨inv n⟩
lemma inv_zero : ∀ (n : ℕ), (0 : zmod n)⁻¹ = 0
| 0 := int.sign_zero
| (n+1) := show (nat.gcd_a _ (n+1) : zmod (n+1)) = 0,
by { rw val_zero, unfold nat.gcd_a nat.xgcd nat.xgcd_aux, refl }
lemma mul_inv_eq_gcd {n : ℕ} (a : zmod n) :
a * a⁻¹ = nat.gcd a.val n :=
begin
cases n,
{ calc a * a⁻¹ = a * int.sign a : rfl
... = a.nat_abs : by rw int.mul_sign
... = a.val.gcd 0 : by rw nat.gcd_zero_right; refl },
{ set k := n.succ,
calc a * a⁻¹ = a * a⁻¹ + k * nat.gcd_b (val a) k : by rw [nat_cast_self, zero_mul, add_zero]
... = ↑(↑a.val * nat.gcd_a (val a) k + k * nat.gcd_b (val a) k) :
by { push_cast, rw nat_cast_zmod_val, refl }
... = nat.gcd a.val k : (congr_arg coe (nat.gcd_eq_gcd_ab a.val k)).symm, }
end
@[simp] lemma nat_cast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : zmod n) = a :=
by conv {to_rhs, rw ← nat.mod_add_div a n}; simp
lemma eq_iff_modeq_nat (n : ℕ) {a b : ℕ} : (a : zmod n) = b ↔ a ≡ b [MOD n] :=
begin
cases n,
{ simp only [nat.modeq, int.coe_nat_inj', nat.mod_zero], },
{ rw [fin.ext_iff, nat.modeq, ← val_nat_cast, ← val_nat_cast], exact iff.rfl, }
end
lemma coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(x * x⁻¹ : zmod n) = 1 :=
begin
rw [nat.coprime, nat.gcd_comm, nat.gcd_rec] at h,
rw [mul_inv_eq_gcd, val_nat_cast, h, nat.cast_one],
end
/-- `unit_of_coprime` makes an element of `(zmod n)ˣ` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) : (zmod n)ˣ :=
⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩
@[simp] lemma coe_unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(unit_of_coprime x h : zmod n) = x := rfl
lemma val_coe_unit_coprime {n : ℕ} (u : (zmod n)ˣ) :
nat.coprime (u : zmod n).val n :=
begin
cases n,
{ rcases int.units_eq_one_or u with rfl|rfl; simp },
apply nat.coprime_of_mul_modeq_one ((u⁻¹ : units (zmod (n+1))) : zmod (n+1)).val,
have := units.ext_iff.1 (mul_right_inv u),
rw [units.coe_one] at this,
rw [← eq_iff_modeq_nat, nat.cast_one, ← this], clear this,
rw [← nat_cast_zmod_val ((u * u⁻¹ : units (zmod (n+1))) : zmod (n+1))],
rw [units.coe_mul, val_mul, nat_cast_mod],
end
@[simp] lemma inv_coe_unit {n : ℕ} (u : (zmod n)ˣ) :
(u : zmod n)⁻¹ = (u⁻¹ : (zmod n)ˣ) :=
begin
have := congr_arg (coe : ℕ → zmod n) (val_coe_unit_coprime u),
rw [← mul_inv_eq_gcd, nat.cast_one] at this,
let u' : (zmod n)ˣ := ⟨u, (u : zmod n)⁻¹, this, by rwa mul_comm⟩,
have h : u = u', { apply units.ext, refl },
rw h,
refl
end
lemma mul_inv_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a * a⁻¹ = 1 :=
begin
rcases h with ⟨u, rfl⟩,
rw [inv_coe_unit, u.mul_inv],
end
lemma inv_mul_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a⁻¹ * a = 1 :=
by rw [mul_comm, mul_inv_of_unit a h]
-- TODO: this equivalence is true for `zmod 0 = ℤ`, but needs to use different functions.
/-- Equivalence between the units of `zmod n` and
the subtype of terms `x : zmod n` for which `x.val` is comprime to `n` -/
def units_equiv_coprime {n : ℕ} [ne_zero n] : (zmod n)ˣ ≃ {x : zmod n // nat.coprime x.val n} :=
{ to_fun := λ x, ⟨x, val_coe_unit_coprime x⟩,
inv_fun := λ x, unit_of_coprime x.1.val x.2,
left_inv := λ ⟨_, _, _, _⟩, units.ext (nat_cast_zmod_val _),
right_inv := λ ⟨_, _⟩, by simp }
/-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`,
the rings `zmod (m * n)` and `zmod m × zmod n` are isomorphic.
See `ideal.quotient_inf_ring_equiv_pi_quotient` for the Chinese remainder theorem for ideals in any
ring.
-/
def chinese_remainder {m n : ℕ} (h : m.coprime n) :
zmod (m * n) ≃+* zmod m × zmod n :=
let to_fun : zmod (m * n) → zmod m × zmod n :=
zmod.cast_hom (show m.lcm n ∣ m * n, by simp [nat.lcm_dvd_iff]) (zmod m × zmod n) in
let inv_fun : zmod m × zmod n → zmod (m * n) :=
λ x, if m * n = 0
then if m = 1
then ring_hom.snd _ _ x
else ring_hom.fst _ _ x
else nat.chinese_remainder h x.1.val x.2.val in
have inv : function.left_inverse inv_fun to_fun ∧ function.right_inverse inv_fun to_fun :=
if hmn0 : m * n = 0
then begin
rcases h.eq_of_mul_eq_zero hmn0 with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩;
simp [inv_fun, to_fun, function.left_inverse, function.right_inverse,
eq_int_cast, prod.ext_iff]
end
else
begin
haveI : ne_zero (m * n) := ⟨hmn0⟩,
haveI : ne_zero m := ⟨left_ne_zero_of_mul hmn0⟩,
haveI : ne_zero n := ⟨right_ne_zero_of_mul hmn0⟩,
have left_inv : function.left_inverse inv_fun to_fun,
{ intro x,
dsimp only [dvd_mul_left, dvd_mul_right, zmod.cast_hom_apply, coe_coe, inv_fun, to_fun],
conv_rhs { rw ← zmod.nat_cast_zmod_val x },
rw [if_neg hmn0, zmod.eq_iff_modeq_nat, ← nat.modeq_and_modeq_iff_modeq_mul h,
prod.fst_zmod_cast, prod.snd_zmod_cast],
refine
⟨(nat.chinese_remainder h (x : zmod m).val (x : zmod n).val).2.left.trans _,
(nat.chinese_remainder h (x : zmod m).val (x : zmod n).val).2.right.trans _⟩,
{ rw [← zmod.eq_iff_modeq_nat, zmod.nat_cast_zmod_val, zmod.nat_cast_val] },
{ rw [← zmod.eq_iff_modeq_nat, zmod.nat_cast_zmod_val, zmod.nat_cast_val] } },
exact ⟨left_inv, left_inv.right_inverse_of_card_le (by simp)⟩,
end,
{ to_fun := to_fun,
inv_fun := inv_fun,
map_mul' := ring_hom.map_mul _,
map_add' := ring_hom.map_add _,
left_inv := inv.1,
right_inv := inv.2 }
-- todo: this can be made a `unique` instance.
instance subsingleton_units : subsingleton ((zmod 2)ˣ) :=
⟨dec_trivial⟩
lemma le_div_two_iff_lt_neg (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)]
{x : zmod n} (hx0 : x ≠ 0) : x.val ≤ (n / 2 : ℕ) ↔ (n / 2 : ℕ) < (-x).val :=
begin
haveI npos : ne_zero n := ⟨by
{ unfreezingI { rintro rfl },
simpa [fact_iff] using hn, }⟩,
have hn2 : (n : ℕ) / 2 < n := nat.div_lt_of_lt_mul
((lt_mul_iff_one_lt_left $ ne_zero.pos n).2 dec_trivial),
have hn2' : (n : ℕ) - n / 2 = n / 2 + 1,
{ conv {to_lhs, congr, rw [← nat.succ_sub_one n, nat.succ_sub $ ne_zero.pos n]},
rw [← nat.two_mul_odd_div_two hn.1, two_mul, ← nat.succ_add, add_tsub_cancel_right], },
have hxn : (n : ℕ) - x.val < n,
{ rw [tsub_lt_iff_tsub_lt x.val_le le_rfl, tsub_self],
rw ← zmod.nat_cast_zmod_val x at hx0,
exact nat.pos_of_ne_zero (λ h, by simpa [h] using hx0) },
by conv {to_rhs, rw [← nat.succ_le_iff, nat.succ_eq_add_one, ← hn2', ← zero_add (- x),
← zmod.nat_cast_self, ← sub_eq_add_neg, ← zmod.nat_cast_zmod_val x,
← nat.cast_sub x.val_le,
zmod.val_nat_cast, nat.mod_eq_of_lt hxn, tsub_le_tsub_iff_left x.val_le] }
end
lemma ne_neg_self (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)] {a : zmod n} (ha : a ≠ 0) : a ≠ -a :=
λ h, have a.val ≤ n / 2 ↔ (n : ℕ) / 2 < (-a).val := le_div_two_iff_lt_neg n ha,
by rwa [← h, ← not_lt, not_iff_self] at this
lemma neg_one_ne_one {n : ℕ} [fact (2 < n)] :
(-1 : zmod n) ≠ 1 :=
char_p.neg_one_ne_one (zmod n) n
lemma neg_eq_self_mod_two (a : zmod 2) : -a = a :=
by fin_cases a; ext; simp [fin.coe_neg, int.nat_mod]; norm_num
@[simp] lemma nat_abs_mod_two (a : ℤ) : (a.nat_abs : zmod 2) = a :=
begin
cases a,
{ simp only [int.nat_abs_of_nat, int.cast_coe_nat, int.of_nat_eq_coe] },
{ simp only [neg_eq_self_mod_two, nat.cast_succ, int.nat_abs, int.cast_neg_succ_of_nat] }
end
@[simp] lemma val_eq_zero : ∀ {n : ℕ} (a : zmod n), a.val = 0 ↔ a = 0
| 0 a := int.nat_abs_eq_zero
| (n+1) a := by { rw fin.ext_iff, exact iff.rfl }
lemma neg_eq_self_iff {n : ℕ} (a : zmod n) : -a = a ↔ a = 0 ∨ 2 * a.val = n :=
begin
rw [neg_eq_iff_add_eq_zero, ← two_mul],
cases n,
{ rw [@mul_eq_zero ℤ, @mul_eq_zero ℕ, val_eq_zero],
exact ⟨λ h, h.elim dec_trivial or.inl, λ h, or.inr (h.elim id $ λ h, h.elim dec_trivial id)⟩ },
conv_lhs
{ rw [← a.nat_cast_zmod_val, ← nat.cast_two, ← nat.cast_mul, nat_coe_zmod_eq_zero_iff_dvd] },
split,
{ rintro ⟨m, he⟩, cases m,
{ rw [mul_zero, mul_eq_zero] at he,
rcases he with ⟨⟨⟩⟩|he,
exact or.inl (a.val_eq_zero.1 he) },
cases m, { right, rwa mul_one at he },
refine (a.val_lt.not_le $ nat.le_of_mul_le_mul_left _ zero_lt_two).elim,
rw [he, mul_comm], apply nat.mul_le_mul_left, dec_trivial },
{ rintro (rfl|h), { rw [val_zero, mul_zero], apply dvd_zero }, { rw h } },
end
lemma val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : zmod n).val = a :=
by rw [val_nat_cast, nat.mod_eq_of_lt h]
lemma neg_val' {n : ℕ} [ne_zero n] (a : zmod n) : (-a).val = (n - a.val) % n :=
calc (-a).val = val (-a) % n : by rw nat.mod_eq_of_lt ((-a).val_lt)
... = (n - val a) % n : nat.modeq.add_right_cancel' _ (by rw [nat.modeq, ←val_add,
add_left_neg, tsub_add_cancel_of_le a.val_le, nat.mod_self, val_zero])
lemma neg_val {n : ℕ} [ne_zero n] (a : zmod n) : (-a).val = if a = 0 then 0 else n - a.val :=
begin
rw neg_val',
by_cases h : a = 0, { rw [if_pos h, h, val_zero, tsub_zero, nat.mod_self] },
rw if_neg h,
apply nat.mod_eq_of_lt,
apply nat.sub_lt (ne_zero.pos n),
contrapose! h,
rwa [le_zero_iff, val_eq_zero] at h,
end
/-- `val_min_abs x` returns the integer in the same equivalence class as `x` that is closest to `0`,
The result will be in the interval `(-n/2, n/2]`. -/
def val_min_abs : Π {n : ℕ}, zmod n → ℤ
| 0 x := x
| n@(_+1) x := if x.val ≤ n / 2 then x.val else (x.val : ℤ) - n
@[simp] lemma val_min_abs_def_zero (x : zmod 0) : val_min_abs x = x := rfl
lemma val_min_abs_def_pos {n : ℕ} [ne_zero n] (x : zmod n) :
val_min_abs x = if x.val ≤ n / 2 then x.val else x.val - n :=
begin
casesI n,
{ cases ne_zero.ne 0 rfl },
{ refl }
end
@[simp, norm_cast] lemma coe_val_min_abs : ∀ {n : ℕ} (x : zmod n), (x.val_min_abs : zmod n) = x
| 0 x := int.cast_id x
| k@(n+1) x :=
begin
rw val_min_abs_def_pos,
split_ifs,
{ rw [int.cast_coe_nat, nat_cast_zmod_val] },
{ rw [int.cast_sub, int.cast_coe_nat, nat_cast_zmod_val, int.cast_coe_nat, nat_cast_self,
sub_zero] }
end
lemma injective_val_min_abs {n : ℕ} : (val_min_abs : zmod n → ℤ).injective :=
function.injective_iff_has_left_inverse.2 ⟨_, coe_val_min_abs⟩
lemma _root_.nat.le_div_two_iff_mul_two_le {n m : ℕ} : m ≤ n / 2 ↔ (m : ℤ) * 2 ≤ n :=
by rw [nat.le_div_iff_mul_le zero_lt_two, ← int.coe_nat_le, int.coe_nat_mul, nat.cast_two]
lemma val_min_abs_nonneg_iff {n : ℕ} [ne_zero n] (x : zmod n) :
0 ≤ x.val_min_abs ↔ x.val ≤ n / 2 :=
begin
rw [val_min_abs_def_pos], split_ifs,
{ exact iff_of_true (nat.cast_nonneg _) h },
{ exact iff_of_false (sub_lt_zero.2 $ int.coe_nat_lt.2 x.val_lt).not_le h },
end
lemma val_min_abs_mul_two_eq_iff {n : ℕ} (a : zmod n) : a.val_min_abs * 2 = n ↔ 2 * a.val = n :=
begin
cases n, { simp },
by_cases a.val ≤ n.succ / 2,
{ rw [val_min_abs, if_pos h, ← int.coe_nat_inj', nat.cast_mul, nat.cast_two, mul_comm] },
apply iff_of_false (λ he, _) (mt _ h),
{ rw [← a.val_min_abs_nonneg_iff, ← mul_nonneg_iff_left_nonneg_of_pos, he] at h,
exacts [h (nat.cast_nonneg _), zero_lt_two] },
{ rw [mul_comm], exact λ h, (nat.le_div_iff_mul_le zero_lt_two).2 h.le },
end
lemma val_min_abs_mem_Ioc {n : ℕ} [ne_zero n] (x : zmod n) :
x.val_min_abs * 2 ∈ set.Ioc (-n : ℤ) n :=
begin
simp_rw [val_min_abs_def_pos, nat.le_div_two_iff_mul_two_le], split_ifs,
{ refine ⟨(neg_lt_zero.2 $ by exact_mod_cast ne_zero.pos n).trans_le (mul_nonneg _ _), h⟩,
exacts [nat.cast_nonneg _, zero_le_two] },
{ refine ⟨_, trans (mul_nonpos_of_nonpos_of_nonneg _ zero_le_two) $ nat.cast_nonneg _⟩,
{ linarith only [h] },
{ rw [sub_nonpos, int.coe_nat_le], exact x.val_lt.le } },
end
lemma val_min_abs_spec {n : ℕ} [ne_zero n] (x : zmod n) (y : ℤ) :
x.val_min_abs = y ↔ x = y ∧ y * 2 ∈ set.Ioc (-n : ℤ) n :=
⟨by { rintro rfl, exact ⟨x.coe_val_min_abs.symm, x.val_min_abs_mem_Ioc⟩ }, λ h, begin
rw ← sub_eq_zero,
apply @int.eq_zero_of_abs_lt_dvd n,
{ rw [← int_coe_zmod_eq_zero_iff_dvd, int.cast_sub, coe_val_min_abs, h.1, sub_self] },
rw [← mul_lt_mul_right (@zero_lt_two ℤ _ _ _ _ _)],
nth_rewrite 0 ← abs_eq_self.2 (@zero_le_two ℤ _ _ _ _),
rw [← abs_mul, sub_mul, abs_lt], split;
linarith only [x.val_min_abs_mem_Ioc.1, x.val_min_abs_mem_Ioc.2, h.2.1, h.2.2],
end⟩
lemma nat_abs_val_min_abs_le {n : ℕ} [ne_zero n] (x : zmod n) : x.val_min_abs.nat_abs ≤ n / 2 :=
begin
rw [nat.le_div_two_iff_mul_two_le],
cases x.val_min_abs.nat_abs_eq,
{ rw ← h, exact x.val_min_abs_mem_Ioc.2 },
{ rw [← neg_le_neg_iff, ← neg_mul, ← h], exact x.val_min_abs_mem_Ioc.1.le },
end
@[simp] lemma val_min_abs_zero : ∀ n, (0 : zmod n).val_min_abs = 0
| 0 := by simp only [val_min_abs_def_zero]
| (n+1) := by simp only [val_min_abs_def_pos, if_true, int.coe_nat_zero, zero_le, val_zero]
@[simp] lemma val_min_abs_eq_zero {n : ℕ} (x : zmod n) :
x.val_min_abs = 0 ↔ x = 0 :=
begin
cases n, { simp },
rw ← val_min_abs_zero n.succ,
apply injective_val_min_abs.eq_iff,
end
lemma nat_cast_nat_abs_val_min_abs {n : ℕ} [ne_zero n] (a : zmod n) :
(a.val_min_abs.nat_abs : zmod n) = if a.val ≤ (n : ℕ) / 2 then a else -a :=
begin
have : (a.val : ℤ) - n ≤ 0,
by { erw [sub_nonpos, int.coe_nat_le], exact a.val_le, },
rw [val_min_abs_def_pos],
split_ifs,
{ rw [int.nat_abs_of_nat, nat_cast_zmod_val] },
{ rw [← int.cast_coe_nat, int.of_nat_nat_abs_of_nonpos this, int.cast_neg, int.cast_sub,
int.cast_coe_nat, int.cast_coe_nat, nat_cast_self, sub_zero, nat_cast_zmod_val], }
end
lemma val_min_abs_neg_of_ne_half {n : ℕ} {a : zmod n} (ha : 2 * a.val ≠ n) :
(-a).val_min_abs = -a.val_min_abs :=
begin
casesI eq_zero_or_ne_zero n, { subst h, refl },
refine (val_min_abs_spec _ _).2 ⟨_, _, _⟩,
{ rw [int.cast_neg, coe_val_min_abs] },
{ rw [neg_mul, neg_lt_neg_iff],
exact a.val_min_abs_mem_Ioc.2.lt_of_ne (mt a.val_min_abs_mul_two_eq_iff.1 ha) },
{ linarith only [a.val_min_abs_mem_Ioc.1] },
end
@[simp] lemma nat_abs_val_min_abs_neg {n : ℕ} (a : zmod n) :
(-a).val_min_abs.nat_abs = a.val_min_abs.nat_abs :=
begin
by_cases h2a : 2 * a.val = n,
{ rw a.neg_eq_self_iff.2 (or.inr h2a) },
{ rw [val_min_abs_neg_of_ne_half h2a, int.nat_abs_neg] }
end
lemma val_eq_ite_val_min_abs {n : ℕ} [ne_zero n] (a : zmod n) :
(a.val : ℤ) = a.val_min_abs + if a.val ≤ n / 2 then 0 else n :=
by { rw val_min_abs_def_pos, split_ifs; simp only [add_zero, sub_add_cancel] }
lemma prime_ne_zero (p q : ℕ) [hp : fact p.prime] [hq : fact q.prime] (hpq : p ≠ q) :
(q : zmod p) ≠ 0 :=
by rwa [← nat.cast_zero, ne.def, eq_iff_modeq_nat, nat.modeq_zero_iff_dvd,
← hp.1.coprime_iff_not_dvd, nat.coprime_primes hp.1 hq.1]
variables {n a : ℕ}
lemma val_min_abs_nat_abs_eq_min {n : ℕ} [hpos : ne_zero n] (a : zmod n) :
a.val_min_abs.nat_abs = min a.val (n - a.val) :=
begin
rw val_min_abs_def_pos,
split_ifs with h h,
{ rw int.nat_abs_of_nat, symmetry,
apply min_eq_left (le_trans h (le_trans
(nat.half_le_of_sub_le_half _) (nat.sub_le_sub_left n h))),
rw nat.sub_sub_self (nat.div_le_self _ _) },
{ rw [←int.nat_abs_neg, neg_sub, ←nat.cast_sub a.val_le], symmetry,
apply min_eq_right (le_trans (le_trans (nat.sub_le_sub_left n (lt_of_not_ge h))
(nat.le_half_of_half_lt_sub _)) (le_of_not_ge h)),
rw nat.sub_sub_self (nat.div_lt_self (lt_of_le_of_ne' (nat.zero_le _) hpos.1) one_lt_two),
apply nat.lt_succ_self }
end
lemma val_min_abs_nat_cast_of_le_half (ha : a ≤ n / 2) : (a : zmod n).val_min_abs = a :=
begin
cases n,
{ simp },
{ simp [val_min_abs_def_pos, val_nat_cast,
nat.mod_eq_of_lt (ha.trans_lt $ nat.div_lt_self' _ 0), ha] }
end
lemma val_min_abs_nat_cast_of_half_lt (ha : n / 2 < a) (ha' : a < n) :
(a : zmod n).val_min_abs = a - n :=
begin
cases n,
{ cases not_lt_bot ha' },
{ simp [val_min_abs_def_pos, val_nat_cast, nat.mod_eq_of_lt ha', ha.not_le] }
end
@[simp] lemma val_min_nat_abs_nat_cast_eq_self [ne_zero n] :
(a : zmod n).val_min_abs = a ↔ a ≤ n / 2 :=
begin
refine ⟨λ ha, _, val_min_abs_nat_cast_of_le_half⟩,
rw [←int.nat_abs_of_nat a, ←ha],
exact nat_abs_val_min_abs_le a,
end
lemma nat_abs_min_of_le_div_two (n : ℕ) (x y : ℤ)
(he : (x : zmod n) = y) (hl : x.nat_abs ≤ n / 2) : x.nat_abs ≤ y.nat_abs :=
begin
rw int_coe_eq_int_coe_iff_dvd_sub at he,
obtain ⟨m, he⟩ := he,
rw sub_eq_iff_eq_add at he,
subst he,
obtain rfl|hm := eq_or_ne m 0,
{ rw [mul_zero, zero_add] },
apply hl.trans,
rw ← add_le_add_iff_right x.nat_abs,
refine trans (trans ((add_le_add_iff_left _).2 hl) _) (int.nat_abs_sub_le _ _),
rw [add_sub_cancel, int.nat_abs_mul, int.nat_abs_of_nat],
refine trans _ (nat.le_mul_of_pos_right $ int.nat_abs_pos_of_ne_zero hm),
rw ← mul_two, apply nat.div_mul_le_self,
end
lemma nat_abs_val_min_abs_add_le {n : ℕ} (a b : zmod n) :
(a + b).val_min_abs.nat_abs ≤ (a.val_min_abs + b.val_min_abs).nat_abs :=
begin
cases n, { refl },
apply nat_abs_min_of_le_div_two n.succ,
{ simp_rw [int.cast_add, coe_val_min_abs] },
{ apply nat_abs_val_min_abs_le },
end
variables (p : ℕ) [fact p.prime]
private lemma mul_inv_cancel_aux (a : zmod p) (h : a ≠ 0) : a * a⁻¹ = 1 :=
begin
obtain ⟨k, rfl⟩ := nat_cast_zmod_surjective a,
apply coe_mul_inv_eq_one,
apply nat.coprime.symm,
rwa [nat.prime.coprime_iff_not_dvd (fact.out p.prime), ← char_p.cast_eq_zero_iff (zmod p)]
end
/-- Field structure on `zmod p` if `p` is prime. -/
instance : field (zmod p) :=
{ mul_inv_cancel := mul_inv_cancel_aux p,
inv_zero := inv_zero p,
.. zmod.comm_ring p,
.. zmod.has_inv p,
.. zmod.nontrivial p }
/-- `zmod p` is an integral domain when `p` is prime. -/
instance (p : ℕ) [hp : fact p.prime] : is_domain (zmod p) :=
begin
-- We need `cases p` here in order to resolve which `comm_ring` instance is being used.
unfreezingI { cases p, { exact (nat.not_prime_zero hp.out).elim }, },
exact @field.is_domain (zmod _) (zmod.field _)
end
end zmod
lemma ring_hom.ext_zmod {n : ℕ} {R : Type*} [semiring R] (f g : (zmod n) →+* R) : f = g :=
begin
ext a,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective a,
let φ : ℤ →+* R := f.comp (int.cast_ring_hom (zmod n)),
let ψ : ℤ →+* R := g.comp (int.cast_ring_hom (zmod n)),
show φ k = ψ k,
rw φ.ext_int ψ,
end
namespace zmod
variables {n : ℕ} {R : Type*}
instance subsingleton_ring_hom [semiring R] : subsingleton ((zmod n) →+* R) :=
⟨ring_hom.ext_zmod⟩
instance subsingleton_ring_equiv [semiring R] : subsingleton (zmod n ≃+* R) :=
⟨λ f g, by { rw ring_equiv.coe_ring_hom_inj_iff, apply ring_hom.ext_zmod _ _ }⟩
@[simp] lemma ring_hom_map_cast [ring R] (f : R →+* (zmod n)) (k : zmod n) :
f k = k :=
by { cases n; simp }
lemma ring_hom_right_inverse [ring R] (f : R →+* (zmod n)) :
function.right_inverse (coe : zmod n → R) f :=
ring_hom_map_cast f
lemma ring_hom_surjective [ring R] (f : R →+* (zmod n)) : function.surjective f :=
(ring_hom_right_inverse f).surjective
lemma ring_hom_eq_of_ker_eq [comm_ring R] (f g : R →+* (zmod n))
(h : f.ker = g.ker) : f = g :=
begin
have := f.lift_of_right_inverse_comp _ (zmod.ring_hom_right_inverse f) ⟨g, le_of_eq h⟩,
rw subtype.coe_mk at this,
rw [←this, ring_hom.ext_zmod (f.lift_of_right_inverse _ _ ⟨g, _⟩) _, ring_hom.id_comp],
end
section lift
variables (n) {A : Type*} [add_group A]
/-- The map from `zmod n` induced by `f : ℤ →+ A` that maps `n` to `0`. -/
@[simps]
def lift : {f : ℤ →+ A // f n = 0} ≃ (zmod n →+ A) :=
(equiv.subtype_equiv_right $ begin
intro f,
rw ker_int_cast_add_hom,
split,
{ rintro hf _ ⟨x, rfl⟩,
simp only [f.map_zsmul, zsmul_zero, f.mem_ker, hf] },
{ intro h,
refine h (add_subgroup.mem_zmultiples _) }
end).trans $ ((int.cast_add_hom (zmod n)).lift_of_right_inverse coe int_cast_zmod_cast)
variables (f : {f : ℤ →+ A // f n = 0})
@[simp] lemma lift_coe (x : ℤ) :
lift n f (x : zmod n) = f x :=
add_monoid_hom.lift_of_right_inverse_comp_apply _ _ _ _ _
lemma lift_cast_add_hom (x : ℤ) :
lift n f (int.cast_add_hom (zmod n) x) = f x :=
add_monoid_hom.lift_of_right_inverse_comp_apply _ _ _ _ _
@[simp] lemma lift_comp_coe : zmod.lift n f ∘ coe = f :=
funext $ lift_coe _ _
@[simp] lemma lift_comp_cast_add_hom :
(zmod.lift n f).comp (int.cast_add_hom (zmod n)) = f :=
add_monoid_hom.ext $ lift_cast_add_hom _ _
end lift
end zmod
|
cdb6c63920956a8687321764023b4abf14086150 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/normed_space/add_torsor_bases.lean | 6da2223d0983980d6365e71ebd5d23e5a3a9eeef | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 7,057 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import analysis.normed_space.finite_dimension
import analysis.calculus.affine_map
import analysis.convex.combination
import linear_algebra.affine_space.finite_dimensional
/-!
# Bases in normed affine spaces.
This file contains results about bases in normed affine spaces.
## Main definitions:
* `continuous_barycentric_coord`
* `is_open_map_barycentric_coord`
* `affine_basis.interior_convex_hull`
* `exists_subset_affine_independent_span_eq_top_of_open`
* `interior_convex_hull_nonempty_iff_affine_span_eq_top`
-/
section barycentric
variables {ι 𝕜 E P : Type*} [nontrivially_normed_field 𝕜] [complete_space 𝕜]
variables [normed_add_comm_group E] [normed_space 𝕜 E]
variables [metric_space P] [normed_add_torsor E P]
include E
lemma is_open_map_barycentric_coord [nontrivial ι] (b : affine_basis ι 𝕜 P) (i : ι) :
is_open_map (b.coord i) :=
affine_map.is_open_map_linear_iff.mp $ (b.coord i).linear.is_open_map_of_finite_dimensional $
(b.coord i).linear_surjective_iff.mpr (b.surjective_coord i)
variables [finite_dimensional 𝕜 E] (b : affine_basis ι 𝕜 P)
@[continuity]
lemma continuous_barycentric_coord (i : ι) : continuous (b.coord i) :=
(b.coord i).continuous_of_finite_dimensional
lemma smooth_barycentric_coord (b : affine_basis ι 𝕜 E) (i : ι) : cont_diff 𝕜 ⊤ (b.coord i) :=
(⟨b.coord i, continuous_barycentric_coord b i⟩ : E →A[𝕜] 𝕜).cont_diff
end barycentric
open set
/-- Given a finite-dimensional normed real vector space, the interior of the convex hull of an
affine basis is the set of points whose barycentric coordinates are strictly positive with respect
to this basis.
TODO Restate this result for affine spaces (instead of vector spaces) once the definition of
convexity is generalised to this setting. -/
lemma affine_basis.interior_convex_hull {ι E : Type*} [finite ι] [normed_add_comm_group E]
[normed_space ℝ E] (b : affine_basis ι ℝ E) :
interior (convex_hull ℝ (range b)) = {x | ∀ i, 0 < b.coord i x} :=
begin
casesI subsingleton_or_nontrivial ι,
{ -- The zero-dimensional case.
have : range b = univ,
from affine_subspace.eq_univ_of_subsingleton_span_eq_top (subsingleton_range _) b.tot,
simp [this] },
{ -- The positive-dimensional case.
haveI : finite_dimensional ℝ E := b.finite_dimensional,
have : convex_hull ℝ (range b) = ⋂ i, (b.coord i)⁻¹' Ici 0,
{ rw [b.convex_hull_eq_nonneg_coord, set_of_forall], refl },
ext,
simp only [this, interior_Inter, ← is_open_map.preimage_interior_eq_interior_preimage
(is_open_map_barycentric_coord b _) (continuous_barycentric_coord b _),
interior_Ici, mem_Inter, mem_set_of_eq, mem_Ioi, mem_preimage], },
end
variables {V P : Type*} [normed_add_comm_group V] [normed_space ℝ V] [metric_space P]
[normed_add_torsor V P]
include V
open affine_map
/-- Given a set `s` of affine-independent points belonging to an open set `u`, we may extend `s` to
an affine basis, all of whose elements belong to `u`. -/
lemma is_open.exists_between_affine_independent_span_eq_top {s u : set P} (hu : is_open u)
(hsu : s ⊆ u) (hne : s.nonempty) (h : affine_independent ℝ (coe : s → P)) :
∃ t : set P, s ⊆ t ∧ t ⊆ u ∧ affine_independent ℝ (coe : t → P) ∧ affine_span ℝ t = ⊤ :=
begin
obtain ⟨q, hq⟩ := hne,
obtain ⟨ε, ε0, hεu⟩ := metric.nhds_basis_closed_ball.mem_iff.1 (hu.mem_nhds $ hsu hq),
obtain ⟨t, ht₁, ht₂, ht₃⟩ := exists_subset_affine_independent_affine_span_eq_top h,
let f : P → P := λ y, line_map q y (ε / dist y q),
have hf : ∀ y, f y ∈ u,
{ refine λ y, hεu _,
simp only [f],
rw [metric.mem_closed_ball, line_map_apply, dist_vadd_left, norm_smul, real.norm_eq_abs,
dist_eq_norm_vsub V y q, abs_div, abs_of_pos ε0, abs_of_nonneg (norm_nonneg _), div_mul_comm],
exact mul_le_of_le_one_left ε0.le (div_self_le_one _) },
have hεyq : ∀ y ∉ s, ε / dist y q ≠ 0,
from λ y hy, div_ne_zero ε0.ne' (dist_ne_zero.2 (ne_of_mem_of_not_mem hq hy).symm),
classical,
let w : t → ℝˣ := λ p, if hp : (p : P) ∈ s then 1 else units.mk0 _ (hεyq ↑p hp),
refine ⟨set.range (λ (p : t), line_map q p (w p : ℝ)), _, _, _, _⟩,
{ intros p hp, use ⟨p, ht₁ hp⟩, simp [w, hp], },
{ rintros y ⟨⟨p, hp⟩, rfl⟩,
by_cases hps : p ∈ s; simp only [w, hps, line_map_apply_one, units.coe_mk0, dif_neg, dif_pos,
not_false_iff, units.coe_one, subtype.coe_mk];
[exact hsu hps, exact hf p], },
{ exact (ht₂.units_line_map ⟨q, ht₁ hq⟩ w).range, },
{ rw [affine_span_eq_affine_span_line_map_units (ht₁ hq) w, ht₃], },
end
lemma is_open.exists_subset_affine_independent_span_eq_top {u : set P} (hu : is_open u)
(hne : u.nonempty) :
∃ s ⊆ u, affine_independent ℝ (coe : s → P) ∧ affine_span ℝ s = ⊤ :=
begin
rcases hne with ⟨x, hx⟩,
rcases hu.exists_between_affine_independent_span_eq_top (singleton_subset_iff.mpr hx)
(singleton_nonempty _) (affine_independent_of_subsingleton _ _) with ⟨s, -, hsu, hs⟩,
exact ⟨s, hsu, hs⟩
end
/-- The affine span of a nonempty open set is `⊤`. -/
lemma is_open.affine_span_eq_top {u : set P} (hu : is_open u) (hne : u.nonempty) :
affine_span ℝ u = ⊤ :=
let ⟨s, hsu, hs, hs'⟩ := hu.exists_subset_affine_independent_span_eq_top hne
in top_unique $ hs' ▸ affine_span_mono _ hsu
lemma affine_span_eq_top_of_nonempty_interior {s : set V}
(hs : (interior $ convex_hull ℝ s).nonempty) :
affine_span ℝ s = ⊤ :=
top_unique $ is_open_interior.affine_span_eq_top hs ▸
(affine_span_mono _ interior_subset).trans_eq (affine_span_convex_hull _)
lemma affine_basis.centroid_mem_interior_convex_hull {ι} [fintype ι] (b : affine_basis ι ℝ V) :
finset.univ.centroid ℝ b ∈ interior (convex_hull ℝ (range b)) :=
begin
haveI := b.nonempty,
simp only [b.interior_convex_hull, mem_set_of_eq, b.coord_apply_centroid (finset.mem_univ _),
inv_pos, nat.cast_pos, finset.card_pos, finset.univ_nonempty, forall_true_iff]
end
lemma interior_convex_hull_nonempty_iff_affine_span_eq_top [finite_dimensional ℝ V] {s : set V} :
(interior (convex_hull ℝ s)).nonempty ↔ affine_span ℝ s = ⊤ :=
begin
refine ⟨affine_span_eq_top_of_nonempty_interior, λ h, _⟩,
obtain ⟨t, hts, b, hb⟩ := affine_basis.exists_affine_subbasis h,
suffices : (interior (convex_hull ℝ (range b))).nonempty,
{ rw [hb, subtype.range_coe_subtype, set_of_mem_eq] at this,
refine this.mono _,
mono* },
lift t to finset V using b.finite_set,
exact ⟨_, b.centroid_mem_interior_convex_hull⟩
end
lemma convex.interior_nonempty_iff_affine_span_eq_top [finite_dimensional ℝ V] {s : set V}
(hs : convex ℝ s) : (interior s).nonempty ↔ affine_span ℝ s = ⊤ :=
by rw [← interior_convex_hull_nonempty_iff_affine_span_eq_top, hs.convex_hull_eq]
|
78bb69fd8adb31c4d5cb16cb1469205153b10fb0 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/measure_theory/integral/bochner.lean | 84076d698e9b8e69026a8b881a4458c20cc41451 | [
"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 | 84,695 | lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import measure_theory.integral.set_to_l1
/-!
# Bochner integral
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined through the extension process described in the file `set_to_L1`,
which follows these steps:
1. Define the integral of the indicator of a set. This is `weighted_smul μ s x = (μ s).to_real * x`.
`weighted_smul μ` is shown to be linear in the value `x` and `dominated_fin_meas_additive`
(defined in the file `set_to_L1`) with respect to the set `s`.
2. Define the integral on simple functions of the type `simple_func α E` (notation : `α →ₛ E`)
where `E` is a real normed space. (See `simple_func.integral` for details.)
3. Transfer this definition to define the integral on `L1.simple_func α E` (notation :
`α →₁ₛ[μ] E`), see `L1.simple_func.integral`. Show that this integral is a continuous linear
map from `α →₁ₛ[μ] E` to `E`.
4. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `α →₁ₛ[μ] E` using `continuous_linear_map.extend` and the fact that the embedding of
`α →₁ₛ[μ] E` into `α →₁[μ] E` is dense.
5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1
space, if it is in L1, and 0 otherwise.
The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to
`set_to_fun (dominated_fin_meas_additive_weighted_smul μ) f`. Some basic properties of the integral
(like linearity) are particular cases of the properties of `set_to_fun` (which are described in the
file `set_to_L1`).
## Main statements
1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure
space and `E` is a real normed space.
* `integral_zero` : `∫ 0 ∂μ = 0`
* `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ`
* `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ`
* `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ`
* `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ`
* `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ`
* `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ`
2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure
space.
* `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
* `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions,
which is called `lintegral` and has the notation `∫⁻`.
* `integral_eq_lintegral_max_sub_lintegral_min` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`,
where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ`
4. `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
5. (In the file `set_integral`) integration commutes with continuous linear maps.
* `continuous_linear_map.integral_comp_comm`
* `linear_isometry.integral_comp_comm`
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `integrable.induction` in the file `simple_func_dense_lp` (or one
of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove
something for an arbitrary integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_max_sub_lintegral_min` for a complicated example, which proves that
`∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued
function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_max_sub_lintegral_min` is
scattered in sections with the name `pos_part`.
Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all
functions :
1. First go to the `L¹` space.
For example, if you see `ennreal.to_real (∫⁻ a, ennreal.of_real $ ‖f a‖)`, that is the norm of
`f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `is_closed_eq`.
3. Show that the property holds for all simple functions `s` in `L¹` space.
Typically, you need to convert various notions to their `simple_func` counterpart, using lemmas
like `L1.integral_coe_eq_integral`.
4. Since simple functions are dense in `L¹`,
```
univ = closure {s simple}
= closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions
⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}
= {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself
```
Use `is_closed_property` or `dense_range.induction_on` for this argument.
## Notations
* `α →ₛ E` : simple functions (defined in `measure_theory/integration`)
* `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`measure_theory/lp_space`)
* `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple
functions (defined in `measure_theory/simple_func_dense`)
* `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ`
* `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type
We also define notations for integral on a set, which are described in the file
`measure_theory/set_integral`.
Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
assert_not_exists differentiable
noncomputable theory
open_locale topology big_operators nnreal ennreal measure_theory
open set filter topological_space ennreal emetric
namespace measure_theory
variables {α E F 𝕜 : Type*}
section weighted_smul
open continuous_linear_map
variables [normed_add_comm_group F] [normed_space ℝ F] {m : measurable_space α} {μ : measure α}
/-- Given a set `s`, return the continuous linear map `λ x, (μ s).to_real • x`. The extension of
that set function through `set_to_L1` gives the Bochner integral of L1 functions. -/
def weighted_smul {m : measurable_space α} (μ : measure α) (s : set α) : F →L[ℝ] F :=
(μ s).to_real • (continuous_linear_map.id ℝ F)
lemma weighted_smul_apply {m : measurable_space α} (μ : measure α) (s : set α) (x : F) :
weighted_smul μ s x = (μ s).to_real • x :=
by simp [weighted_smul]
@[simp] lemma weighted_smul_zero_measure {m : measurable_space α} :
weighted_smul (0 : measure α) = (0 : set α → F →L[ℝ] F) :=
by { ext1, simp [weighted_smul], }
@[simp] lemma weighted_smul_empty {m : measurable_space α} (μ : measure α) :
weighted_smul μ ∅ = (0 : F →L[ℝ] F) :=
by { ext1 x, rw [weighted_smul_apply], simp, }
lemma weighted_smul_add_measure {m : measurable_space α} (μ ν : measure α) {s : set α}
(hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) :
(weighted_smul (μ + ν) s : F →L[ℝ] F) = weighted_smul μ s + weighted_smul ν s :=
begin
ext1 x,
push_cast,
simp_rw [pi.add_apply, weighted_smul_apply],
push_cast,
rw [pi.add_apply, ennreal.to_real_add hμs hνs, add_smul],
end
lemma weighted_smul_smul_measure {m : measurable_space α} (μ : measure α) (c : ℝ≥0∞) {s : set α} :
(weighted_smul (c • μ) s : F →L[ℝ] F) = c.to_real • weighted_smul μ s :=
begin
ext1 x,
push_cast,
simp_rw [pi.smul_apply, weighted_smul_apply],
push_cast,
simp_rw [pi.smul_apply, smul_eq_mul, to_real_mul, smul_smul],
end
lemma weighted_smul_congr (s t : set α) (hst : μ s = μ t) :
(weighted_smul μ s : F →L[ℝ] F) = weighted_smul μ t :=
by { ext1 x, simp_rw weighted_smul_apply, congr' 2, }
lemma weighted_smul_null {s : set α} (h_zero : μ s = 0) : (weighted_smul μ s : F →L[ℝ] F) = 0 :=
by { ext1 x, rw [weighted_smul_apply, h_zero], simp, }
lemma weighted_smul_union' (s t : set α) (ht : measurable_set t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weighted_smul μ (s ∪ t) : F →L[ℝ] F) = weighted_smul μ s + weighted_smul μ t :=
begin
ext1 x,
simp_rw [add_apply, weighted_smul_apply,
measure_union (set.disjoint_iff_inter_eq_empty.mpr h_inter) ht,
ennreal.to_real_add hs_finite ht_finite, add_smul],
end
@[nolint unused_arguments]
lemma weighted_smul_union (s t : set α) (hs : measurable_set s) (ht : measurable_set t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weighted_smul μ (s ∪ t) : F →L[ℝ] F) = weighted_smul μ s + weighted_smul μ t :=
weighted_smul_union' s t ht hs_finite ht_finite h_inter
lemma weighted_smul_smul [normed_field 𝕜] [normed_space 𝕜 F] [smul_comm_class ℝ 𝕜 F]
(c : 𝕜) (s : set α) (x : F) :
weighted_smul μ s (c • x) = c • weighted_smul μ s x :=
by { simp_rw [weighted_smul_apply, smul_comm], }
lemma norm_weighted_smul_le (s : set α) : ‖(weighted_smul μ s : F →L[ℝ] F)‖ ≤ (μ s).to_real :=
calc ‖(weighted_smul μ s : F →L[ℝ] F)‖ = ‖(μ s).to_real‖ * ‖continuous_linear_map.id ℝ F‖ :
norm_smul _ _
... ≤ ‖(μ s).to_real‖ : (mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le
... = abs (μ s).to_real : real.norm_eq_abs _
... = (μ s).to_real : abs_eq_self.mpr ennreal.to_real_nonneg
lemma dominated_fin_meas_additive_weighted_smul {m : measurable_space α} (μ : measure α) :
dominated_fin_meas_additive μ (weighted_smul μ : set α → F →L[ℝ] F) 1 :=
⟨weighted_smul_union, λ s _ _, (norm_weighted_smul_le s).trans (one_mul _).symm.le⟩
lemma weighted_smul_nonneg (s : set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weighted_smul μ s x :=
begin
simp only [weighted_smul, algebra.id.smul_eq_mul, coe_smul', id.def, coe_id', pi.smul_apply],
exact mul_nonneg to_real_nonneg hx,
end
end weighted_smul
local infixr ` →ₛ `:25 := simple_func
namespace simple_func
section pos_part
variables [linear_order E] [has_zero E] [measurable_space α]
/-- Positive part of a simple function. -/
def pos_part (f : α →ₛ E) : α →ₛ E := f.map (λ b, max b 0)
/-- Negative part of a simple function. -/
def neg_part [has_neg E] (f : α →ₛ E) : α →ₛ E := pos_part (-f)
lemma pos_part_map_norm (f : α →ₛ ℝ) : (pos_part f).map norm = pos_part f :=
by { ext, rw [map_apply, real.norm_eq_abs, abs_of_nonneg], exact le_max_right _ _ }
lemma neg_part_map_norm (f : α →ₛ ℝ) : (neg_part f).map norm = neg_part f :=
by { rw neg_part, exact pos_part_map_norm _ }
lemma pos_part_sub_neg_part (f : α →ₛ ℝ) : f.pos_part - f.neg_part = f :=
begin
simp only [pos_part, neg_part],
ext a,
rw coe_sub,
exact max_zero_sub_eq_self (f a)
end
end pos_part
section integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group,
and prove basic property of this integral.
-/
open finset
variables [normed_add_comm_group E] [normed_add_comm_group F] [normed_space ℝ F] {p : ℝ≥0∞}
{G F' : Type*} [normed_add_comm_group G] [normed_add_comm_group F'] [normed_space ℝ F']
{m : measurable_space α} {μ : measure α}
/-- Bochner integral of simple functions whose codomain is a real `normed_space`.
This is equal to `∑ x in f.range, (μ (f ⁻¹' {x})).to_real • x` (see `integral_eq`). -/
def integral {m : measurable_space α} (μ : measure α) (f : α →ₛ F) : F :=
f.set_to_simple_func (weighted_smul μ)
lemma integral_def {m : measurable_space α} (μ : measure α) (f : α →ₛ F) :
f.integral μ = f.set_to_simple_func (weighted_smul μ) := rfl
lemma integral_eq {m : measurable_space α} (μ : measure α) (f : α →ₛ F) :
f.integral μ = ∑ x in f.range, (μ (f ⁻¹' {x})).to_real • x :=
by simp [integral, set_to_simple_func, weighted_smul_apply]
lemma integral_eq_sum_filter [decidable_pred (λ x : F, x ≠ 0)] {m : measurable_space α} (f : α →ₛ F)
(μ : measure α) :
f.integral μ = ∑ x in f.range.filter (λ x, x ≠ 0), (μ (f ⁻¹' {x})).to_real • x :=
by { rw [integral_def, set_to_simple_func_eq_sum_filter], simp_rw weighted_smul_apply, congr }
/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/
lemma integral_eq_sum_of_subset [decidable_pred (λ x : F, x ≠ 0)] {f : α →ₛ F} {s : finset F}
(hs : f.range.filter (λ x, x ≠ 0) ⊆ s) : f.integral μ = ∑ x in s, (μ (f ⁻¹' {x})).to_real • x :=
begin
rw [simple_func.integral_eq_sum_filter, finset.sum_subset hs],
rintro x - hx, rw [finset.mem_filter, not_and_distrib, ne.def, not_not] at hx,
rcases hx with hx|rfl; [skip, simp],
rw [simple_func.mem_range] at hx, rw [preimage_eq_empty]; simp [set.disjoint_singleton_left, hx]
end
@[simp] lemma integral_const {m : measurable_space α} (μ : measure α) (y : F) :
(const α y).integral μ = (μ univ).to_real • y :=
by classical; calc (const α y).integral μ = ∑ z in {y}, (μ ((const α y) ⁻¹' {z})).to_real • z :
integral_eq_sum_of_subset $ (filter_subset _ _).trans (range_const_subset _ _)
... = (μ univ).to_real • y : by simp
@[simp] lemma integral_piecewise_zero {m : measurable_space α} (f : α →ₛ F) (μ : measure α)
{s : set α} (hs : measurable_set s) :
(piecewise s hs f 0).integral μ = f.integral (μ.restrict s) :=
begin
classical,
refine (integral_eq_sum_of_subset _).trans
((sum_congr rfl $ λ y hy, _).trans (integral_eq_sum_filter _ _).symm),
{ intros y hy,
simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,
mem_range_indicator] at *,
rcases hy with ⟨⟨rfl, -⟩|⟨x, hxs, rfl⟩, h₀⟩,
exacts [(h₀ rfl).elim, ⟨set.mem_range_self _, h₀⟩] },
{ dsimp,
rw [set.piecewise_eq_indicator, indicator_preimage_of_not_mem,
measure.restrict_apply (f.measurable_set_preimage _)],
exact λ h₀, (mem_filter.1 hy).2 (eq.symm h₀) }
end
/-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/
lemma map_integral (f : α →ₛ E) (g : E → F) (hf : integrable f μ) (hg : g 0 = 0) :
(f.map g).integral μ = ∑ x in f.range, (ennreal.to_real (μ (f ⁻¹' {x}))) • (g x) :=
map_set_to_simple_func _ weighted_smul_union hf hg
/-- `simple_func.integral` and `simple_func.lintegral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `normed_space`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
lemma integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : integrable f μ) (hg0 : g 0 = 0)
(ht : ∀ b, g b ≠ ∞) :
(f.map (ennreal.to_real ∘ g)).integral μ = ennreal.to_real (∫⁻ a, g (f a) ∂μ) :=
begin
have hf' : f.fin_meas_supp μ := integrable_iff_fin_meas_supp.1 hf,
simp only [← map_apply g f, lintegral_eq_lintegral],
rw [map_integral f _ hf, map_lintegral, ennreal.to_real_sum],
{ refine finset.sum_congr rfl (λb hb, _),
rw [smul_eq_mul, to_real_mul, mul_comm] },
{ assume a ha,
by_cases a0 : a = 0,
{ rw [a0, hg0, zero_mul], exact with_top.zero_ne_top },
{ apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne } },
{ simp [hg0] }
end
variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space ℝ E] [smul_comm_class ℝ 𝕜 E]
lemma integral_congr {f g : α →ₛ E} (hf : integrable f μ) (h : f =ᵐ[μ] g) :
f.integral μ = g.integral μ :=
set_to_simple_func_congr (weighted_smul μ) (λ s hs, weighted_smul_null) weighted_smul_union hf h
/-- `simple_func.bintegral` and `simple_func.integral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `normed_space`, we need some form of coercion. -/
lemma integral_eq_lintegral {f : α →ₛ ℝ} (hf : integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) :
f.integral μ = ennreal.to_real (∫⁻ a, ennreal.of_real (f a) ∂μ) :=
begin
have : f =ᵐ[μ] f.map (ennreal.to_real ∘ ennreal.of_real) :=
h_pos.mono (λ a h, (ennreal.to_real_of_real h).symm),
rw [← integral_eq_lintegral' hf],
exacts [integral_congr hf this, ennreal.of_real_zero, λ b, ennreal.of_real_ne_top]
end
lemma integral_add {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) :
integral μ (f + g) = integral μ f + integral μ g :=
set_to_simple_func_add _ weighted_smul_union hf hg
lemma integral_neg {f : α →ₛ E} (hf : integrable f μ) : integral μ (-f) = - integral μ f :=
set_to_simple_func_neg _ weighted_smul_union hf
lemma integral_sub {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) :
integral μ (f - g) = integral μ f - integral μ g :=
set_to_simple_func_sub _ weighted_smul_union hf hg
lemma integral_smul (c : 𝕜) {f : α →ₛ E} (hf : integrable f μ) :
integral μ (c • f) = c • integral μ f :=
set_to_simple_func_smul _ weighted_smul_union weighted_smul_smul c hf
lemma norm_set_to_simple_func_le_integral_norm (T : set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real) {f : α →ₛ E}
(hf : integrable f μ) :
‖f.set_to_simple_func T‖ ≤ C * (f.map norm).integral μ :=
calc ‖f.set_to_simple_func T‖
≤ C * ∑ x in f.range, ennreal.to_real (μ (f ⁻¹' {x})) * ‖x‖ :
norm_set_to_simple_func_le_sum_mul_norm_of_integrable T hT_norm f hf
... = C * (f.map norm).integral μ : by { rw map_integral f norm hf norm_zero, simp_rw smul_eq_mul, }
lemma norm_integral_le_integral_norm (f : α →ₛ E) (hf : integrable f μ) :
‖f.integral μ‖ ≤ (f.map norm).integral μ :=
begin
refine (norm_set_to_simple_func_le_integral_norm _ (λ s _ _, _) hf).trans (one_mul _).le,
exact (norm_weighted_smul_le s).trans (one_mul _).symm.le,
end
lemma integral_add_measure {ν} (f : α →ₛ E) (hf : integrable f (μ + ν)) :
f.integral (μ + ν) = f.integral μ + f.integral ν :=
begin
simp_rw [integral_def],
refine set_to_simple_func_add_left' (weighted_smul μ) (weighted_smul ν) (weighted_smul (μ + ν))
(λ s hs hμνs, _) hf,
rw [lt_top_iff_ne_top, measure.coe_add, pi.add_apply, ennreal.add_ne_top] at hμνs,
rw weighted_smul_add_measure _ _ hμνs.1 hμνs.2,
end
end integral
end simple_func
namespace L1
open ae_eq_fun Lp.simple_func Lp
variables [normed_add_comm_group E] [normed_add_comm_group F] {m : measurable_space α}
{μ : measure α}
variables {α E μ}
namespace simple_func
lemma norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((to_simple_func f).map norm).integral μ :=
begin
rw [norm_eq_sum_mul f, (to_simple_func f).map_integral norm (simple_func.integrable f) norm_zero],
simp_rw smul_eq_mul,
end
section pos_part
/-- Positive part of a simple function in L1 space. -/
def pos_part (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.pos_part (f : α →₁[μ] ℝ),
begin
rcases f with ⟨f, s, hsf⟩,
use s.pos_part,
simp only [subtype.coe_mk, Lp.coe_pos_part, ← hsf, ae_eq_fun.pos_part_mk, simple_func.pos_part,
simple_func.coe_map, mk_eq_mk],
end ⟩
/-- Negative part of a simple function in L1 space. -/
def neg_part (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := pos_part (-f)
@[norm_cast]
lemma coe_pos_part (f : α →₁ₛ[μ] ℝ) : (pos_part f : α →₁[μ] ℝ) = Lp.pos_part (f : α →₁[μ] ℝ) := rfl
@[norm_cast]
lemma coe_neg_part (f : α →₁ₛ[μ] ℝ) : (neg_part f : α →₁[μ] ℝ) = Lp.neg_part (f : α →₁[μ] ℝ) := rfl
end pos_part
section simple_func_integral
/-!
### The Bochner integral of `L1`
Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`,
and prove basic properties of this integral. -/
variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space ℝ E] [smul_comm_class ℝ 𝕜 E]
{F' : Type*} [normed_add_comm_group F'] [normed_space ℝ F']
local attribute [instance] simple_func.normed_space
/-- The Bochner integral over simple functions in L1 space. -/
def integral (f : α →₁ₛ[μ] E) : E := ((to_simple_func f)).integral μ
lemma integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = ((to_simple_func f)).integral μ := rfl
lemma integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] (to_simple_func f)) :
integral f = ennreal.to_real (∫⁻ a, ennreal.of_real ((to_simple_func f) a) ∂μ) :=
by rw [integral, simple_func.integral_eq_lintegral (simple_func.integrable f) h_pos]
lemma integral_eq_set_to_L1s (f : α →₁ₛ[μ] E) : integral f = set_to_L1s (weighted_smul μ) f := rfl
lemma integral_congr {f g : α →₁ₛ[μ] E} (h : to_simple_func f =ᵐ[μ] to_simple_func g) :
integral f = integral g :=
simple_func.integral_congr (simple_func.integrable f) h
lemma integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g :=
set_to_L1s_add _ (λ _ _, weighted_smul_null) weighted_smul_union _ _
lemma integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) :
integral (c • f) = c • integral f :=
set_to_L1s_smul _ (λ _ _, weighted_smul_null) weighted_smul_union weighted_smul_smul c f
lemma norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ :=
begin
rw [integral, norm_eq_integral],
exact (to_simple_func f).norm_integral_le_integral_norm (simple_func.integrable f)
end
variables {E' : Type*} [normed_add_comm_group E'] [normed_space ℝ E'] [normed_space 𝕜 E']
variables (α E μ 𝕜)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/
def integral_clm' : (α →₁ₛ[μ] E) →L[𝕜] E :=
linear_map.mk_continuous ⟨integral, integral_add, integral_smul⟩
1 (λf, le_trans (norm_integral_le_norm _) $ by rw one_mul)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/
def integral_clm : (α →₁ₛ[μ] E) →L[ℝ] E := integral_clm' α E ℝ μ
variables {α E μ 𝕜}
local notation (name := simple_func.integral_clm) `Integral` := integral_clm α E μ
open continuous_linear_map
lemma norm_Integral_le_one : ‖Integral‖ ≤ 1 :=
linear_map.mk_continuous_norm_le _ (zero_le_one) _
section pos_part
lemma pos_part_to_simple_func (f : α →₁ₛ[μ] ℝ) :
to_simple_func (pos_part f) =ᵐ[μ] (to_simple_func f).pos_part :=
begin
have eq : ∀ a, (to_simple_func f).pos_part a = max ((to_simple_func f) a) 0 := λa, rfl,
have ae_eq : ∀ᵐ a ∂μ, to_simple_func (pos_part f) a = max ((to_simple_func f) a) 0,
{ filter_upwards [to_simple_func_eq_to_fun (pos_part f), Lp.coe_fn_pos_part (f : α →₁[μ] ℝ),
to_simple_func_eq_to_fun f] with _ _ h₂ _,
convert h₂, },
refine ae_eq.mono (assume a h, _),
rw [h, eq],
end
lemma neg_part_to_simple_func (f : α →₁ₛ[μ] ℝ) :
to_simple_func (neg_part f) =ᵐ[μ] (to_simple_func f).neg_part :=
begin
rw [simple_func.neg_part, measure_theory.simple_func.neg_part],
filter_upwards [pos_part_to_simple_func (-f), neg_to_simple_func f],
assume a h₁ h₂,
rw h₁,
show max _ _ = max _ _,
rw h₂,
refl
end
lemma integral_eq_norm_pos_part_sub (f : α →₁ₛ[μ] ℝ) :
integral f = ‖pos_part f‖ - ‖neg_part f‖ :=
begin
-- Convert things in `L¹` to their `simple_func` counterpart
have ae_eq₁ : (to_simple_func f).pos_part =ᵐ[μ] (to_simple_func (pos_part f)).map norm,
{ filter_upwards [pos_part_to_simple_func f] with _ h,
rw [simple_func.map_apply, h],
conv_lhs { rw [← simple_func.pos_part_map_norm, simple_func.map_apply] } },
-- Convert things in `L¹` to their `simple_func` counterpart
have ae_eq₂ : (to_simple_func f).neg_part =ᵐ[μ] (to_simple_func (neg_part f)).map norm,
{ filter_upwards [neg_part_to_simple_func f] with _ h,
rw [simple_func.map_apply, h],
conv_lhs { rw [← simple_func.neg_part_map_norm, simple_func.map_apply], }, },
-- Convert things in `L¹` to their `simple_func` counterpart
have ae_eq : ∀ᵐ a ∂μ, (to_simple_func f).pos_part a - (to_simple_func f).neg_part a =
(to_simple_func (pos_part f)).map norm a - (to_simple_func (neg_part f)).map norm a,
{ filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂,
rw [h₁, h₂], },
rw [integral, norm_eq_integral, norm_eq_integral, ← simple_func.integral_sub],
{ show (to_simple_func f).integral μ =
((to_simple_func (pos_part f)).map norm - (to_simple_func (neg_part f)).map norm).integral μ,
apply measure_theory.simple_func.integral_congr (simple_func.integrable f),
filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂,
show _ = _ - _,
rw [← h₁, ← h₂],
have := (to_simple_func f).pos_part_sub_neg_part,
conv_lhs {rw ← this},
refl, },
{ exact (simple_func.integrable f).pos_part.congr ae_eq₁ },
{ exact (simple_func.integrable f).neg_part.congr ae_eq₂ }
end
end pos_part
end simple_func_integral
end simple_func
open simple_func
local notation (name := simple_func.integral_clm) `Integral` := @integral_clm α E _ _ _ _ _ μ _
variables [normed_space ℝ E] [nontrivially_normed_field 𝕜] [normed_space 𝕜 E]
[smul_comm_class ℝ 𝕜 E] [normed_space ℝ F] [complete_space E]
section integration_in_L1
local attribute [instance] simple_func.normed_space
open continuous_linear_map
variables (𝕜)
/-- The Bochner integral in L1 space as a continuous linear map. -/
def integral_clm' : (α →₁[μ] E) →L[𝕜] E :=
(integral_clm' α E 𝕜 μ).extend
(coe_to_Lp α E 𝕜) (simple_func.dense_range one_ne_top) simple_func.uniform_inducing
variables {𝕜}
/-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/
def integral_clm : (α →₁[μ] E) →L[ℝ] E := integral_clm' ℝ
/-- The Bochner integral in L1 space -/
@[irreducible] def integral (f : α →₁[μ] E) : E := integral_clm f
lemma integral_eq (f : α →₁[μ] E) : integral f = integral_clm f :=
by simp only [integral]
lemma integral_eq_set_to_L1 (f : α →₁[μ] E) :
integral f = set_to_L1 (dominated_fin_meas_additive_weighted_smul μ) f :=
by { simp only [integral], refl }
@[norm_cast] lemma simple_func.integral_L1_eq_integral (f : α →₁ₛ[μ] E) :
integral (f : α →₁[μ] E) = (simple_func.integral f) :=
begin
simp only [integral],
exact set_to_L1_eq_set_to_L1s_clm (dominated_fin_meas_additive_weighted_smul μ) f
end
variables (α E)
@[simp] lemma integral_zero : integral (0 : α →₁[μ] E) = 0 :=
begin
simp only [integral],
exact map_zero integral_clm
end
variables {α E}
@[integral_simps]
lemma integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g :=
begin
simp only [integral],
exact map_add integral_clm f g
end
@[integral_simps]
lemma integral_neg (f : α →₁[μ] E) : integral (-f) = - integral f :=
begin
simp only [integral],
exact map_neg integral_clm f
end
@[integral_simps]
lemma integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g :=
begin
simp only [integral],
exact map_sub integral_clm f g
end
@[integral_simps]
lemma integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f :=
begin
simp only [integral],
show (integral_clm' 𝕜) (c • f) = c • (integral_clm' 𝕜) f, from map_smul (integral_clm' 𝕜) c f
end
local notation (name := integral_clm) `Integral` := @integral_clm α E _ _ μ _ _
local notation (name := simple_func.integral_clm') `sIntegral` :=
@simple_func.integral_clm α E _ _ μ _
lemma norm_Integral_le_one : ‖Integral‖ ≤ 1 :=
norm_set_to_L1_le (dominated_fin_meas_additive_weighted_smul μ) zero_le_one
lemma norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ :=
calc ‖integral f‖ = ‖Integral f‖ : by simp only [integral]
... ≤ ‖Integral‖ * ‖f‖ : le_op_norm _ _
... ≤ 1 * ‖f‖ : mul_le_mul_of_nonneg_right norm_Integral_le_one $ norm_nonneg _
... = ‖f‖ : one_mul _
@[continuity]
lemma continuous_integral : continuous (λ (f : α →₁[μ] E), integral f) :=
begin
simp only [integral],
exact L1.integral_clm.continuous
end
section pos_part
lemma integral_eq_norm_pos_part_sub (f : α →₁[μ] ℝ) :
integral f = ‖Lp.pos_part f‖ - ‖Lp.neg_part f‖ :=
begin
-- Use `is_closed_property` and `is_closed_eq`
refine @is_closed_property _ _ _ (coe : (α →₁ₛ[μ] ℝ) → (α →₁[μ] ℝ))
(λ f : α →₁[μ] ℝ, integral f = ‖Lp.pos_part f‖ - ‖Lp.neg_part f‖)
(simple_func.dense_range one_ne_top) (is_closed_eq _ _) _ f,
{ simp only [integral],
exact cont _ },
{ refine continuous.sub (continuous_norm.comp Lp.continuous_pos_part)
(continuous_norm.comp Lp.continuous_neg_part) },
-- Show that the property holds for all simple functions in the `L¹` space.
{ assume s,
norm_cast,
exact simple_func.integral_eq_norm_pos_part_sub _ }
end
end pos_part
end integration_in_L1
end L1
/-!
## The Bochner integral on functions
Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable
functions, and 0 otherwise; prove its basic properties.
-/
variables [normed_add_comm_group E] [normed_space ℝ E] [complete_space E]
[nontrivially_normed_field 𝕜] [normed_space 𝕜 E] [smul_comm_class ℝ 𝕜 E]
[normed_add_comm_group F] [normed_space ℝ F] [complete_space F]
section
open_locale classical
/-- The Bochner integral -/
@[irreducible] def integral {m : measurable_space α} (μ : measure α) (f : α → E) : E :=
if hf : integrable f μ then L1.integral (hf.to_L1 f) else 0
end
/-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly,
and needs parentheses. We do not set the binding power of `r` to `0`, because then
`∫ x, f x = 0` will be parsed incorrectly. -/
notation `∫` binders `, ` r:(scoped:60 f, f) ` ∂` μ:70 := integral μ r
notation `∫` binders `, ` r:(scoped:60 f, integral volume f) := r
notation `∫` binders ` in ` s `, ` r:(scoped:60 f, f) ` ∂` μ:70 := integral (measure.restrict μ s) r
notation `∫` binders ` in ` s `, ` r:(scoped:60 f, integral (measure.restrict volume s) f) := r
section properties
open continuous_linear_map measure_theory.simple_func
variables {f g : α → E} {m : measurable_space α} {μ : measure α}
lemma integral_eq (f : α → E) (hf : integrable f μ) :
∫ a, f a ∂μ = L1.integral (hf.to_L1 f) :=
by { rw [integral], exact @dif_pos _ (id _) hf _ _ _ }
lemma integral_eq_set_to_fun (f : α → E) :
∫ a, f a ∂μ = set_to_fun μ (weighted_smul μ) (dominated_fin_meas_additive_weighted_smul μ) f :=
by { simp only [integral, L1.integral], refl }
lemma L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ :=
begin
simp only [integral, L1.integral],
exact (L1.set_to_fun_eq_set_to_L1 (dominated_fin_meas_additive_weighted_smul μ) f).symm
end
lemma integral_undef (h : ¬ integrable f μ) : ∫ a, f a ∂μ = 0 :=
by { rw [integral], exact @dif_neg _ (id _) h _ _ _ }
lemma integral_non_ae_strongly_measurable (h : ¬ ae_strongly_measurable f μ) : ∫ a, f a ∂μ = 0 :=
integral_undef $ not_and_of_not_left _ h
variables (α E)
lemma integral_zero : ∫ a : α, (0:E) ∂μ = 0 :=
begin
simp only [integral, L1.integral],
exact set_to_fun_zero (dominated_fin_meas_additive_weighted_smul μ)
end
@[simp] lemma integral_zero' : integral μ (0 : α → E) = 0 :=
integral_zero α E
variables {α E}
lemma integrable_of_integral_eq_one {f : α → ℝ} (h : ∫ x, f x ∂μ = 1) :
integrable f μ :=
by { contrapose h, rw integral_undef h, exact zero_ne_one }
lemma integral_add (hf : integrable f μ) (hg : integrable g μ) :
∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_add (dominated_fin_meas_additive_weighted_smul μ) hf hg
end
lemma integral_add' (hf : integrable f μ) (hg : integrable g μ) :
∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
integral_add hf hg
lemma integral_finset_sum {ι} (s : finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, integrable (f i) μ) :
∫ a, ∑ i in s, f i a ∂μ = ∑ i in s, ∫ a, f i a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_finset_sum (dominated_fin_meas_additive_weighted_smul _) s hf
end
@[integral_simps]
lemma integral_neg (f : α → E) : ∫ a, -f a ∂μ = - ∫ a, f a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_neg (dominated_fin_meas_additive_weighted_smul μ) f
end
lemma integral_neg' (f : α → E) : ∫ a, (-f) a ∂μ = - ∫ a, f a ∂μ :=
integral_neg f
lemma integral_sub (hf : integrable f μ) (hg : integrable g μ) :
∫ a, f a - g a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_sub (dominated_fin_meas_additive_weighted_smul μ) hf hg
end
lemma integral_sub' (hf : integrable f μ) (hg : integrable g μ) :
∫ a, (f - g) a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ :=
integral_sub hf hg
@[integral_simps]
lemma integral_smul (c : 𝕜) (f : α → E) :
∫ a, c • (f a) ∂μ = c • ∫ a, f a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_smul (dominated_fin_meas_additive_weighted_smul μ) weighted_smul_smul c f
end
lemma integral_mul_left {L : Type*} [is_R_or_C L] (r : L) (f : α → L) :
∫ a, r * (f a) ∂μ = r * ∫ a, f a ∂μ :=
integral_smul r f
lemma integral_mul_right {L : Type*} [is_R_or_C L] (r : L) (f : α → L) :
∫ a, (f a) * r ∂μ = ∫ a, f a ∂μ * r :=
by { simp only [mul_comm], exact integral_mul_left r f }
lemma integral_div {L : Type*} [is_R_or_C L] (r : L) (f : α → L) :
∫ a, (f a) / r ∂μ = ∫ a, f a ∂μ / r :=
by simpa only [←div_eq_mul_inv] using integral_mul_right r⁻¹ f
lemma integral_congr_ae (h : f =ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_congr_ae (dominated_fin_meas_additive_weighted_smul μ) h
end
@[simp] lemma L1.integral_of_fun_eq_integral {f : α → E} (hf : integrable f μ) :
∫ a, (hf.to_L1 f) a ∂μ = ∫ a, f a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_to_L1 (dominated_fin_meas_additive_weighted_smul μ) hf
end
@[continuity]
lemma continuous_integral : continuous (λ (f : α →₁[μ] E), ∫ a, f a ∂μ) :=
begin
simp only [integral, L1.integral],
exact continuous_set_to_fun (dominated_fin_meas_additive_weighted_smul μ)
end
lemma norm_integral_le_lintegral_norm (f : α → E) :
‖∫ a, f a ∂μ‖ ≤ ennreal.to_real (∫⁻ a, (ennreal.of_real ‖f a‖) ∂μ) :=
begin
by_cases hf : integrable f μ,
{ rw [integral_eq f hf, ← integrable.norm_to_L1_eq_lintegral_norm f hf],
exact L1.norm_integral_le _ },
{ rw [integral_undef hf, norm_zero], exact to_real_nonneg }
end
lemma ennnorm_integral_le_lintegral_ennnorm (f : α → E) :
(‖∫ a, f a ∂μ‖₊ : ℝ≥0∞) ≤ ∫⁻ a, ‖f a‖₊ ∂μ :=
by { simp_rw [← of_real_norm_eq_coe_nnnorm], apply ennreal.of_real_le_of_le_to_real,
exact norm_integral_le_lintegral_norm f }
lemma integral_eq_zero_of_ae {f : α → E} (hf : f =ᵐ[μ] 0) : ∫ a, f a ∂μ = 0 :=
by simp [integral_congr_ae hf, integral_zero]
/-- If `f` has finite integral, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
lemma has_finite_integral.tendsto_set_integral_nhds_zero {ι} {f : α → E}
(hf : has_finite_integral f μ) {l : filter ι} {s : ι → set α} (hs : tendsto (μ ∘ s) l (𝓝 0)) :
tendsto (λ i, ∫ x in s i, f x ∂μ) l (𝓝 0) :=
begin
rw [tendsto_zero_iff_norm_tendsto_zero],
simp_rw [← coe_nnnorm, ← nnreal.coe_zero, nnreal.tendsto_coe, ← ennreal.tendsto_coe,
ennreal.coe_zero],
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
(tendsto_set_lintegral_zero (ne_of_lt hf) hs) (λ i, zero_le _)
(λ i, ennnorm_integral_le_lintegral_ennnorm _)
end
/-- If `f` is integrable, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
lemma integrable.tendsto_set_integral_nhds_zero {ι} {f : α → E}
(hf : integrable f μ) {l : filter ι} {s : ι → set α} (hs : tendsto (μ ∘ s) l (𝓝 0)) :
tendsto (λ i, ∫ x in s i, f x ∂μ) l (𝓝 0) :=
hf.2.tendsto_set_integral_nhds_zero hs
/-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/
lemma tendsto_integral_of_L1 {ι} (f : α → E) (hfi : integrable f μ)
{F : ι → α → E} {l : filter ι} (hFi : ∀ᶠ i in l, integrable (F i) μ)
(hF : tendsto (λ i, ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0)) :
tendsto (λ i, ∫ x, F i x ∂μ) l (𝓝 $ ∫ x, f x ∂μ) :=
begin
simp only [integral, L1.integral],
exact tendsto_set_to_fun_of_L1 (dominated_fin_meas_additive_weighted_smul μ) f hfi hFi hF
end
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their integrals.
We could weaken the condition `bound_integrable` to require `has_finite_integral bound μ` instead
(i.e. not requiring that `bound` is measurable), but in all applications proving integrability
is easier. -/
theorem tendsto_integral_of_dominated_convergence {F : ℕ → α → E} {f : α → E} (bound : α → ℝ)
(F_measurable : ∀ n, ae_strongly_measurable (F n) μ)
(bound_integrable : integrable bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
tendsto (λn, ∫ a, F n a ∂μ) at_top (𝓝 $ ∫ a, f a ∂μ) :=
begin
simp only [integral, L1.integral],
exact tendsto_set_to_fun_of_dominated_convergence (dominated_fin_meas_additive_weighted_smul μ)
bound F_measurable bound_integrable h_bound h_lim
end
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
lemma tendsto_integral_filter_of_dominated_convergence {ι} {l : filter ι}
[l.is_countably_generated]
{F : ι → α → E} {f : α → E} (bound : α → ℝ)
(hF_meas : ∀ᶠ n in l, ae_strongly_measurable (F n) μ)
(h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) l (𝓝 (f a))) :
tendsto (λn, ∫ a, F n a ∂μ) l (𝓝 $ ∫ a, f a ∂μ) :=
begin
simp only [integral, L1.integral],
exact tendsto_set_to_fun_filter_of_dominated_convergence
(dominated_fin_meas_additive_weighted_smul μ) bound hF_meas h_bound bound_integrable h_lim
end
/-- Lebesgue dominated convergence theorem for series. -/
lemma has_sum_integral_of_dominated_convergence {ι} [countable ι]
{F : ι → α → E} {f : α → E} (bound : ι → α → ℝ)
(hF_meas : ∀ n, ae_strongly_measurable (F n) μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound n a)
(bound_summable : ∀ᵐ a ∂μ, summable (λ n, bound n a))
(bound_integrable : integrable (λ a, ∑' n, bound n a) μ)
(h_lim : ∀ᵐ a ∂μ, has_sum (λ n, F n a) (f a)) :
has_sum (λn, ∫ a, F n a ∂μ) (∫ a, f a ∂μ) :=
begin
have hb_nonneg : ∀ᵐ a ∂μ, ∀ n, 0 ≤ bound n a :=
eventually_countable_forall.2 (λ n, (h_bound n).mono $ λ a, (norm_nonneg _).trans),
have hb_le_tsum : ∀ n, bound n ≤ᵐ[μ] (λ a, ∑' n, bound n a),
{ intro n,
filter_upwards [hb_nonneg, bound_summable] with _ ha0 ha_sum
using le_tsum ha_sum _ (λ i _, ha0 i) },
have hF_integrable : ∀ n, integrable (F n) μ,
{ refine λ n, bound_integrable.mono' (hF_meas n) _,
exact eventually_le.trans (h_bound n) (hb_le_tsum n) },
simp only [has_sum, ← integral_finset_sum _ (λ n _, hF_integrable n)],
refine tendsto_integral_filter_of_dominated_convergence (λ a, ∑' n, bound n a) _ _
bound_integrable h_lim,
{ exact eventually_of_forall (λ s, s.ae_strongly_measurable_sum $ λ n hn, hF_meas n) },
{ refine eventually_of_forall (λ s, _),
filter_upwards [eventually_countable_forall.2 h_bound, hb_nonneg, bound_summable]
with a hFa ha0 has,
calc ‖∑ n in s, F n a‖ ≤ ∑ n in s, bound n a : norm_sum_le_of_le _ (λ n hn, hFa n)
... ≤ ∑' n, bound n a : sum_le_tsum _ (λ n hn, ha0 n) has },
end
variables {X : Type*} [topological_space X] [first_countable_topology X]
lemma continuous_within_at_of_dominated {F : X → α → E} {x₀ : X} {bound : α → ℝ} {s : set X}
(hF_meas : ∀ᶠ x in 𝓝[s] x₀, ae_strongly_measurable (F x) μ)
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, continuous_within_at (λ x, F x a) s x₀) :
continuous_within_at (λ x, ∫ a, F x a ∂μ) s x₀ :=
begin
simp only [integral, L1.integral],
exact continuous_within_at_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ)
hF_meas h_bound bound_integrable h_cont
end
lemma continuous_at_of_dominated {F : X → α → E} {x₀ : X} {bound : α → ℝ}
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_strongly_measurable (F x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a)
(bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_at (λ x, F x a) x₀) :
continuous_at (λ x, ∫ a, F x a ∂μ) x₀ :=
begin
simp only [integral, L1.integral],
exact continuous_at_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ) hF_meas
h_bound bound_integrable h_cont
end
lemma continuous_on_of_dominated {F : X → α → E} {bound : α → ℝ} {s : set X}
(hF_meas : ∀ x ∈ s, ae_strongly_measurable (F x) μ)
(h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, continuous_on (λ x, F x a) s) :
continuous_on (λ x, ∫ a, F x a ∂μ) s :=
begin
simp only [integral, L1.integral],
exact continuous_on_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ) hF_meas
h_bound bound_integrable h_cont
end
lemma continuous_of_dominated {F : X → α → E} {bound : α → ℝ}
(hF_meas : ∀ x, ae_strongly_measurable (F x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a)
(bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous (λ x, F x a)) :
continuous (λ x, ∫ a, F x a ∂μ) :=
begin
simp only [integral, L1.integral],
exact continuous_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ) hF_meas
h_bound bound_integrable h_cont
end
/-- The Bochner integral of a real-valued function `f : α → ℝ` is the difference between the
integral of the positive part of `f` and the integral of the negative part of `f`. -/
lemma integral_eq_lintegral_pos_part_sub_lintegral_neg_part {f : α → ℝ} (hf : integrable f μ) :
∫ a, f a ∂μ =
ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) -
ennreal.to_real (∫⁻ a, (ennreal.of_real $ - f a) ∂μ) :=
let f₁ := hf.to_L1 f in
-- Go to the `L¹` space
have eq₁ : ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) = ‖Lp.pos_part f₁‖ :=
begin
rw L1.norm_def,
congr' 1,
apply lintegral_congr_ae,
filter_upwards [Lp.coe_fn_pos_part f₁, hf.coe_fn_to_L1] with _ h₁ h₂,
rw [h₁, h₂, ennreal.of_real],
congr' 1,
apply nnreal.eq,
rw real.nnnorm_of_nonneg (le_max_right _ _),
simp only [real.coe_to_nnreal', subtype.coe_mk],
end,
-- Go to the `L¹` space
have eq₂ : ennreal.to_real (∫⁻ a, (ennreal.of_real $ - f a) ∂μ) = ‖Lp.neg_part f₁‖ :=
begin
rw L1.norm_def,
congr' 1,
apply lintegral_congr_ae,
filter_upwards [Lp.coe_fn_neg_part f₁, hf.coe_fn_to_L1] with _ h₁ h₂,
rw [h₁, h₂, ennreal.of_real],
congr' 1,
apply nnreal.eq,
simp only [real.coe_to_nnreal', coe_nnnorm, nnnorm_neg],
rw [real.norm_of_nonpos (min_le_right _ _), ← max_neg_neg, neg_zero],
end,
begin
rw [eq₁, eq₂, integral, dif_pos],
exact L1.integral_eq_norm_pos_part_sub _
end
lemma integral_eq_lintegral_of_nonneg_ae
{f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfm : ae_strongly_measurable f μ) :
∫ a, f a ∂μ = ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) :=
begin
by_cases hfi : integrable f μ,
{ rw integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi,
have h_min : ∫⁻ a, ennreal.of_real (-f a) ∂μ = 0,
{ rw lintegral_eq_zero_iff',
{ refine hf.mono _,
simp only [pi.zero_apply],
assume a h,
simp only [h, neg_nonpos, of_real_eq_zero], },
{ exact measurable_of_real.comp_ae_measurable hfm.ae_measurable.neg } },
rw [h_min, zero_to_real, _root_.sub_zero] },
{ rw integral_undef hfi,
simp_rw [integrable, hfm, has_finite_integral_iff_norm, lt_top_iff_ne_top, ne.def, true_and,
not_not] at hfi,
have : ∫⁻ (a : α), ennreal.of_real (f a) ∂μ = ∫⁻ a, (ennreal.of_real ‖f a‖) ∂μ,
{ refine lintegral_congr_ae (hf.mono $ assume a h, _),
rw [real.norm_eq_abs, abs_of_nonneg h] },
rw [this, hfi], refl }
end
lemma integral_norm_eq_lintegral_nnnorm {G} [normed_add_comm_group G]
{f : α → G} (hf : ae_strongly_measurable f μ) :
∫ x, ‖f x‖ ∂μ = ennreal.to_real ∫⁻ x, ‖f x‖₊ ∂μ :=
begin
rw integral_eq_lintegral_of_nonneg_ae _ hf.norm,
{ simp_rw [of_real_norm_eq_coe_nnnorm], },
{ refine ae_of_all _ _, simp_rw [pi.zero_apply, norm_nonneg, imp_true_iff] },
end
lemma of_real_integral_norm_eq_lintegral_nnnorm {G} [normed_add_comm_group G] {f : α → G}
(hf : integrable f μ) :
ennreal.of_real ∫ x, ‖f x‖ ∂μ = ∫⁻ x, ‖f x‖₊ ∂μ :=
by rw [integral_norm_eq_lintegral_nnnorm hf.ae_strongly_measurable,
ennreal.of_real_to_real (lt_top_iff_ne_top.mp hf.2)]
lemma integral_eq_integral_pos_part_sub_integral_neg_part {f : α → ℝ} (hf : integrable f μ) :
∫ a, f a ∂μ = (∫ a, real.to_nnreal (f a) ∂μ) - (∫ a, real.to_nnreal (-f a) ∂μ) :=
begin
rw [← integral_sub hf.real_to_nnreal],
{ simp },
{ exact hf.neg.real_to_nnreal }
end
lemma integral_nonneg_of_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ a, f a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_nonneg (dominated_fin_meas_additive_weighted_smul μ)
(λ s _ _, weighted_smul_nonneg s) hf
end
lemma lintegral_coe_eq_integral (f : α → ℝ≥0) (hfi : integrable (λ x, (f x : ℝ)) μ) :
∫⁻ a, f a ∂μ = ennreal.of_real ∫ a, f a ∂μ :=
begin
simp_rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (λ x, (f x).coe_nonneg))
hfi.ae_strongly_measurable, ← ennreal.coe_nnreal_eq], rw [ennreal.of_real_to_real],
rw [← lt_top_iff_ne_top], convert hfi.has_finite_integral, ext1 x, rw [nnreal.nnnorm_eq]
end
lemma of_real_integral_eq_lintegral_of_real {f : α → ℝ} (hfi : integrable f μ) (f_nn : 0 ≤ᵐ[μ] f) :
ennreal.of_real (∫ x, f x ∂μ) = ∫⁻ x, ennreal.of_real (f x) ∂μ :=
begin
simp_rw [integral_congr_ae (show f =ᵐ[μ] λ x, ‖f x‖,
by { filter_upwards [f_nn] with x hx,
rw [real.norm_eq_abs, abs_eq_self.mpr hx], }),
of_real_integral_norm_eq_lintegral_nnnorm hfi, ←of_real_norm_eq_coe_nnnorm],
apply lintegral_congr_ae,
filter_upwards [f_nn] with x hx,
exact congr_arg ennreal.of_real (by rw [real.norm_eq_abs, abs_eq_self.mpr hx]),
end
lemma integral_to_real {f : α → ℝ≥0∞} (hfm : ae_measurable f μ) (hf : ∀ᵐ x ∂μ, f x < ∞) :
∫ a, (f a).to_real ∂μ = (∫⁻ a, f a ∂μ).to_real :=
begin
rw [integral_eq_lintegral_of_nonneg_ae _ hfm.ennreal_to_real.ae_strongly_measurable],
{ rw lintegral_congr_ae, refine hf.mp (eventually_of_forall _),
intros x hx, rw [lt_top_iff_ne_top] at hx, simp [hx] },
{ exact (eventually_of_forall $ λ x, ennreal.to_real_nonneg) }
end
lemma lintegral_coe_le_coe_iff_integral_le {f : α → ℝ≥0} (hfi : integrable (λ x, (f x : ℝ)) μ)
{b : ℝ≥0} :
∫⁻ a, f a ∂μ ≤ b ↔ ∫ a, (f a : ℝ) ∂μ ≤ b :=
by rw [lintegral_coe_eq_integral f hfi, ennreal.of_real, ennreal.coe_le_coe,
real.to_nnreal_le_iff_le_coe]
lemma integral_coe_le_of_lintegral_coe_le {f : α → ℝ≥0} {b : ℝ≥0} (h : ∫⁻ a, f a ∂μ ≤ b) :
∫ a, (f a : ℝ) ∂μ ≤ b :=
begin
by_cases hf : integrable (λ a, (f a : ℝ)) μ,
{ exact (lintegral_coe_le_coe_iff_integral_le hf).1 h },
{ rw integral_undef hf, exact b.2 }
end
lemma integral_nonneg {f : α → ℝ} (hf : 0 ≤ f) : 0 ≤ ∫ a, f a ∂μ :=
integral_nonneg_of_ae $ eventually_of_forall hf
lemma integral_nonpos_of_ae {f : α → ℝ} (hf : f ≤ᵐ[μ] 0) : ∫ a, f a ∂μ ≤ 0 :=
begin
have hf : 0 ≤ᵐ[μ] (-f) := hf.mono (assume a h, by rwa [pi.neg_apply, pi.zero_apply, neg_nonneg]),
have : 0 ≤ ∫ a, -f a ∂μ := integral_nonneg_of_ae hf,
rwa [integral_neg, neg_nonneg] at this,
end
lemma integral_nonpos {f : α → ℝ} (hf : f ≤ 0) : ∫ a, f a ∂μ ≤ 0 :=
integral_nonpos_of_ae $ eventually_of_forall hf
lemma integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 :=
by simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ennreal.to_real_eq_zero_iff,
lintegral_eq_zero_iff' (ennreal.measurable_of_real.comp_ae_measurable hfi.1.ae_measurable),
← ennreal.not_lt_top, ← has_finite_integral_iff_of_real hf, hfi.2, not_true, or_false,
← hf.le_iff_eq, filter.eventually_eq, filter.eventually_le, (∘), pi.zero_apply,
ennreal.of_real_eq_zero]
lemma integral_eq_zero_iff_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 :=
integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi
lemma integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (function.support f) :=
by simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, pos_iff_ne_zero, ne.def, @eq_comm ℝ 0,
integral_eq_zero_iff_of_nonneg_ae hf hfi, filter.eventually_eq, ae_iff, pi.zero_apply,
function.support]
lemma integral_pos_iff_support_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (function.support f) :=
integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi
section normed_add_comm_group
variables {H : Type*} [normed_add_comm_group H]
lemma L1.norm_eq_integral_norm (f : α →₁[μ] H) : ‖f‖ = ∫ a, ‖f a‖ ∂μ :=
begin
simp only [snorm, snorm', ennreal.one_to_real, ennreal.rpow_one, Lp.norm_def,
if_false, ennreal.one_ne_top, one_ne_zero, _root_.div_one],
rw integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (by simp [norm_nonneg]))
(Lp.ae_strongly_measurable f).norm,
simp [of_real_norm_eq_coe_nnnorm]
end
lemma L1.norm_of_fun_eq_integral_norm {f : α → H} (hf : integrable f μ) :
‖hf.to_L1 f‖ = ∫ a, ‖f a‖ ∂μ :=
begin
rw L1.norm_eq_integral_norm,
refine integral_congr_ae _,
apply hf.coe_fn_to_L1.mono,
intros a ha,
simp [ha]
end
lemma mem_ℒp.snorm_eq_integral_rpow_norm {f : α → H} {p : ℝ≥0∞} (hp1 : p ≠ 0) (hp2 : p ≠ ∞)
(hf : mem_ℒp f p μ) :
snorm f p μ = ennreal.of_real ((∫ a, ‖f a‖ ^ p.to_real ∂μ) ^ (p.to_real ⁻¹)) :=
begin
have A : ∫⁻ (a : α), ennreal.of_real (‖f a‖ ^ p.to_real) ∂μ = ∫⁻ (a : α), ‖f a‖₊ ^ p.to_real ∂μ,
{ apply lintegral_congr (λ x, _),
rw [← of_real_rpow_of_nonneg (norm_nonneg _) to_real_nonneg, of_real_norm_eq_coe_nnnorm] },
simp only [snorm_eq_lintegral_rpow_nnnorm hp1 hp2, one_div],
rw integral_eq_lintegral_of_nonneg_ae, rotate,
{ exact eventually_of_forall (λ x, real.rpow_nonneg_of_nonneg (norm_nonneg _) _) },
{ exact (hf.ae_strongly_measurable.norm.ae_measurable.pow_const _).ae_strongly_measurable },
rw [A, ← of_real_rpow_of_nonneg to_real_nonneg (inv_nonneg.2 to_real_nonneg), of_real_to_real],
exact (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp1 hp2 hf.2).ne
end
end normed_add_comm_group
lemma integral_mono_ae {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ) (h : f ≤ᵐ[μ] g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
begin
simp only [integral, L1.integral],
exact set_to_fun_mono (dominated_fin_meas_additive_weighted_smul μ)
(λ s _ _, weighted_smul_nonneg s) hf hg h
end
@[mono] lemma integral_mono {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ) (h : f ≤ g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
integral_mono_ae hf hg $ eventually_of_forall h
lemma integral_mono_of_nonneg {f g : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hgi : integrable g μ)
(h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
begin
by_cases hfm : ae_strongly_measurable f μ,
{ refine integral_mono_ae ⟨hfm, _⟩ hgi h,
refine (hgi.has_finite_integral.mono $ h.mp $ hf.mono $ λ x hf hfg, _),
simpa [abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)] },
{ rw [integral_non_ae_strongly_measurable hfm],
exact integral_nonneg_of_ae (hf.trans h) }
end
lemma integral_mono_measure {f : α → ℝ} {ν} (hle : μ ≤ ν) (hf : 0 ≤ᵐ[ν] f) (hfi : integrable f ν) :
∫ a, f a ∂μ ≤ ∫ a, f a ∂ν :=
begin
have hfi' : integrable f μ := hfi.mono_measure hle,
have hf' : 0 ≤ᵐ[μ] f := hle.absolutely_continuous hf,
rw [integral_eq_lintegral_of_nonneg_ae hf' hfi'.1, integral_eq_lintegral_of_nonneg_ae hf hfi.1,
ennreal.to_real_le_to_real],
exacts [lintegral_mono' hle le_rfl, ((has_finite_integral_iff_of_real hf').1 hfi'.2).ne,
((has_finite_integral_iff_of_real hf).1 hfi.2).ne]
end
lemma norm_integral_le_integral_norm (f : α → E) : ‖(∫ a, f a ∂μ)‖ ≤ ∫ a, ‖f a‖ ∂μ :=
have le_ae : ∀ᵐ a ∂μ, 0 ≤ ‖f a‖ := eventually_of_forall (λa, norm_nonneg _),
classical.by_cases
( λh : ae_strongly_measurable f μ,
calc ‖∫ a, f a ∂μ‖ ≤ ennreal.to_real (∫⁻ a, (ennreal.of_real ‖f a‖) ∂μ) :
norm_integral_le_lintegral_norm _
... = ∫ a, ‖f a‖ ∂μ : (integral_eq_lintegral_of_nonneg_ae le_ae $ h.norm).symm )
( λh : ¬ae_strongly_measurable f μ,
begin
rw [integral_non_ae_strongly_measurable h, norm_zero],
exact integral_nonneg_of_ae le_ae
end )
lemma norm_integral_le_of_norm_le {f : α → E} {g : α → ℝ} (hg : integrable g μ)
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : ‖∫ x, f x ∂μ‖ ≤ ∫ x, g x ∂μ :=
calc ‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ : norm_integral_le_integral_norm f
... ≤ ∫ x, g x ∂μ :
integral_mono_of_nonneg (eventually_of_forall $ λ x, norm_nonneg _) hg h
lemma simple_func.integral_eq_integral (f : α →ₛ E) (hfi : integrable f μ) :
f.integral μ = ∫ x, f x ∂μ :=
begin
rw [integral_eq f hfi, ← L1.simple_func.to_Lp_one_eq_to_L1,
L1.simple_func.integral_L1_eq_integral, L1.simple_func.integral_eq_integral],
exact simple_func.integral_congr hfi (Lp.simple_func.to_simple_func_to_Lp _ _).symm
end
lemma simple_func.integral_eq_sum (f : α →ₛ E) (hfi : integrable f μ) :
∫ x, f x ∂μ = ∑ x in f.range, (ennreal.to_real (μ (f ⁻¹' {x}))) • x :=
by { rw [← f.integral_eq_integral hfi, simple_func.integral, ← simple_func.integral_eq], refl, }
@[simp] lemma integral_const (c : E) : ∫ x : α, c ∂μ = (μ univ).to_real • c :=
begin
cases (@le_top _ _ _ (μ univ)).lt_or_eq with hμ hμ,
{ haveI : is_finite_measure μ := ⟨hμ⟩,
simp only [integral, L1.integral],
exact set_to_fun_const (dominated_fin_meas_additive_weighted_smul _) _, },
{ by_cases hc : c = 0,
{ simp [hc, integral_zero] },
{ have : ¬integrable (λ x : α, c) μ,
{ simp only [integrable_const_iff, not_or_distrib],
exact ⟨hc, hμ.not_lt⟩ },
simp [integral_undef, *] } }
end
lemma norm_integral_le_of_norm_le_const [is_finite_measure μ] {f : α → E} {C : ℝ}
(h : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) :
‖∫ x, f x ∂μ‖ ≤ C * (μ univ).to_real :=
calc ‖∫ x, f x ∂μ‖ ≤ ∫ x, C ∂μ : norm_integral_le_of_norm_le (integrable_const C) h
... = C * (μ univ).to_real : by rw [integral_const, smul_eq_mul, mul_comm]
lemma tendsto_integral_approx_on_of_measurable
[measurable_space E] [borel_space E]
{f : α → E} {s : set E} [separable_space s] (hfi : integrable f μ)
(hfm : measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s)
(h₀i : integrable (λ x, y₀) μ) :
tendsto (λ n, (simple_func.approx_on f hfm s y₀ h₀ n).integral μ) at_top (𝓝 $ ∫ x, f x ∂μ) :=
begin
have hfi' := simple_func.integrable_approx_on hfm hfi h₀ h₀i,
simp only [simple_func.integral_eq_integral _ (hfi' _), integral, L1.integral],
exact tendsto_set_to_fun_approx_on_of_measurable (dominated_fin_meas_additive_weighted_smul μ)
hfi hfm hs h₀ h₀i,
end
lemma tendsto_integral_approx_on_of_measurable_of_range_subset
[measurable_space E] [borel_space E] {f : α → E}
(fmeas : measurable f) (hf : integrable f μ) (s : set E) [separable_space s]
(hs : range f ∪ {0} ⊆ s) :
tendsto (λ n, (simple_func.approx_on f fmeas s 0 (hs $ by simp) n).integral μ) at_top
(𝓝 $ ∫ x, f x ∂μ) :=
begin
apply tendsto_integral_approx_on_of_measurable hf fmeas _ _ (integrable_zero _ _ _),
exact eventually_of_forall (λ x, subset_closure (hs (set.mem_union_left _ (mem_range_self _)))),
end
variable {ν : measure α}
lemma integral_add_measure {f : α → E} (hμ : integrable f μ) (hν : integrable f ν) :
∫ x, f x ∂(μ + ν) = ∫ x, f x ∂μ + ∫ x, f x ∂ν :=
begin
have hfi := hμ.add_measure hν,
simp_rw [integral_eq_set_to_fun],
have hμ_dfma : dominated_fin_meas_additive (μ + ν) (weighted_smul μ : set α → E →L[ℝ] E) 1,
from dominated_fin_meas_additive.add_measure_right μ ν
(dominated_fin_meas_additive_weighted_smul μ) zero_le_one,
have hν_dfma : dominated_fin_meas_additive (μ + ν) (weighted_smul ν : set α → E →L[ℝ] E) 1,
from dominated_fin_meas_additive.add_measure_left μ ν
(dominated_fin_meas_additive_weighted_smul ν) zero_le_one,
rw [← set_to_fun_congr_measure_of_add_right hμ_dfma (dominated_fin_meas_additive_weighted_smul μ)
f hfi,
← set_to_fun_congr_measure_of_add_left hν_dfma (dominated_fin_meas_additive_weighted_smul ν)
f hfi],
refine set_to_fun_add_left' _ _ _ (λ s hs hμνs, _) f,
rw [measure.coe_add, pi.add_apply, add_lt_top] at hμνs,
rw [weighted_smul, weighted_smul, weighted_smul, ← add_smul, measure.coe_add, pi.add_apply,
to_real_add hμνs.1.ne hμνs.2.ne],
end
@[simp] lemma integral_zero_measure {m : measurable_space α} (f : α → E) :
∫ x, f x ∂(0 : measure α) = 0 :=
begin
simp only [integral, L1.integral],
exact set_to_fun_measure_zero (dominated_fin_meas_additive_weighted_smul _) rfl
end
theorem integral_finset_sum_measure {ι} {m : measurable_space α} {f : α → E}
{μ : ι → measure α} {s : finset ι} (hf : ∀ i ∈ s, integrable f (μ i)) :
∫ a, f a ∂(∑ i in s, μ i) = ∑ i in s, ∫ a, f a ∂μ i :=
begin
classical,
refine finset.induction_on' s _ _, -- `induction s using finset.induction_on'` fails
{ simp },
{ intros i t hi ht hit iht,
simp only [finset.sum_insert hit, ← iht],
exact integral_add_measure (hf _ hi) (integrable_finset_sum_measure.2 $ λ j hj, hf j (ht hj)) }
end
lemma nndist_integral_add_measure_le_lintegral (h₁ : integrable f μ) (h₂ : integrable f ν) :
(nndist (∫ x, f x ∂μ) (∫ x, f x ∂(μ + ν)) : ℝ≥0∞) ≤ ∫⁻ x, ‖f x‖₊ ∂ν :=
begin
rw [integral_add_measure h₁ h₂, nndist_comm, nndist_eq_nnnorm, add_sub_cancel'],
exact ennnorm_integral_le_lintegral_ennnorm _
end
theorem has_sum_integral_measure {ι} {m : measurable_space α} {f : α → E} {μ : ι → measure α}
(hf : integrable f (measure.sum μ)) :
has_sum (λ i, ∫ a, f a ∂μ i) (∫ a, f a ∂measure.sum μ) :=
begin
have hfi : ∀ i, integrable f (μ i) := λ i, hf.mono_measure (measure.le_sum _ _),
simp only [has_sum, ← integral_finset_sum_measure (λ i _, hfi i)],
refine metric.nhds_basis_ball.tendsto_right_iff.mpr (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.le,
have hf_lt : ∫⁻ x, ‖f x‖₊ ∂(measure.sum μ) < ∞ := hf.2,
have hmem : ∀ᶠ y in 𝓝 ∫⁻ x, ‖f x‖₊ ∂(measure.sum μ), ∫⁻ x, ‖f x‖₊ ∂(measure.sum μ) < y + ε,
{ refine tendsto_id.add tendsto_const_nhds (lt_mem_nhds $ ennreal.lt_add_right _ _),
exacts [hf_lt.ne, ennreal.coe_ne_zero.2 (nnreal.coe_ne_zero.1 ε0.ne')] },
refine ((has_sum_lintegral_measure (λ x, ‖f x‖₊) μ).eventually hmem).mono (λ s hs, _),
obtain ⟨ν, hν⟩ : ∃ ν, (∑ i in s, μ i) + ν = measure.sum μ,
{ refine ⟨measure.sum (λ i : ↥(sᶜ : set ι), μ i), _⟩,
simpa only [← measure.sum_coe_finset] using measure.sum_add_sum_compl (s : set ι) μ },
rw [metric.mem_ball, ← coe_nndist, nnreal.coe_lt_coe, ← ennreal.coe_lt_coe, ← hν],
rw [← hν, integrable_add_measure] at hf,
refine (nndist_integral_add_measure_le_lintegral hf.1 hf.2).trans_lt _,
rw [← hν, lintegral_add_measure, lintegral_finset_sum_measure] at hs,
exact lt_of_add_lt_add_left hs
end
theorem integral_sum_measure {ι} {m : measurable_space α} {f : α → E} {μ : ι → measure α}
(hf : integrable f (measure.sum μ)) :
∫ a, f a ∂measure.sum μ = ∑' i, ∫ a, f a ∂μ i :=
(has_sum_integral_measure hf).tsum_eq.symm
lemma integral_tsum {ι} [countable ι] {f : ι → α → E} (hf : ∀ i, ae_strongly_measurable (f i) μ)
(hf' : ∑' i, ∫⁻ (a : α), ‖f i a‖₊ ∂μ ≠ ∞) :
∫ (a : α), (∑' i, f i a) ∂μ = ∑' i, ∫ (a : α), f i a ∂μ :=
begin
have hf'' : ∀ i, ae_measurable (λ x, (‖f i x‖₊ : ℝ≥0∞)) μ, from λ i, (hf i).ennnorm,
have hhh : ∀ᵐ (a : α) ∂μ, summable (λ n, (‖f n a‖₊ : ℝ)),
{ rw ← lintegral_tsum hf'' at hf',
refine (ae_lt_top' (ae_measurable.ennreal_tsum hf'') hf').mono _,
intros x hx,
rw ← ennreal.tsum_coe_ne_top_iff_summable_coe,
exact hx.ne, },
convert (measure_theory.has_sum_integral_of_dominated_convergence (λ i a, ‖f i a‖₊) hf _
hhh ⟨_, _⟩ _).tsum_eq.symm,
{ intros n,
filter_upwards with x,
refl, },
{ simp_rw [← coe_nnnorm, ← nnreal.coe_tsum],
rw ae_strongly_measurable_iff_ae_measurable,
apply ae_measurable.coe_nnreal_real,
apply ae_measurable.nnreal_tsum,
exact λ i, (hf i).nnnorm.ae_measurable, },
{ dsimp [has_finite_integral],
have : ∫⁻ a, ∑' n, ‖f n a‖₊ ∂μ < ⊤ := by rwa [lintegral_tsum hf'', lt_top_iff_ne_top],
convert this using 1,
apply lintegral_congr_ae,
simp_rw [← coe_nnnorm, ← nnreal.coe_tsum, nnreal.nnnorm_eq],
filter_upwards [hhh] with a ha,
exact ennreal.coe_tsum (nnreal.summable_coe.mp ha), },
{ filter_upwards [hhh] with x hx,
exact (summable_of_summable_norm hx).has_sum, },
end
@[simp] lemma integral_smul_measure (f : α → E) (c : ℝ≥0∞) :
∫ x, f x ∂(c • μ) = c.to_real • ∫ x, f x ∂μ :=
begin
-- First we consider the “degenerate” case `c = ∞`
rcases eq_or_ne c ∞ with rfl|hc,
{ rw [ennreal.top_to_real, zero_smul, integral_eq_set_to_fun, set_to_fun_top_smul_measure], },
-- Main case: `c ≠ ∞`
simp_rw [integral_eq_set_to_fun, ← set_to_fun_smul_left],
have hdfma :
dominated_fin_meas_additive μ (weighted_smul (c • μ) : set α → E →L[ℝ] E) c.to_real,
from mul_one c.to_real
▸ (dominated_fin_meas_additive_weighted_smul (c • μ)).of_smul_measure c hc,
have hdfma_smul := (dominated_fin_meas_additive_weighted_smul (c • μ)),
rw ← set_to_fun_congr_smul_measure c hc hdfma hdfma_smul f,
exact set_to_fun_congr_left' _ _ (λ s hs hμs, weighted_smul_smul_measure μ c) f,
end
lemma integral_map_of_strongly_measurable {β} [measurable_space β] {φ : α → β} (hφ : measurable φ)
{f : β → E} (hfm : strongly_measurable f) :
∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ :=
begin
by_cases hfi : integrable f (measure.map φ μ), swap,
{ rw [integral_undef hfi, integral_undef],
rwa [← integrable_map_measure hfm.ae_strongly_measurable hφ.ae_measurable] },
borelize E,
haveI : separable_space (range f ∪ {0} : set E) := hfm.separable_space_range_union_singleton,
refine tendsto_nhds_unique
(tendsto_integral_approx_on_of_measurable_of_range_subset hfm.measurable hfi _ subset.rfl) _,
convert tendsto_integral_approx_on_of_measurable_of_range_subset (hfm.measurable.comp hφ)
((integrable_map_measure hfm.ae_strongly_measurable hφ.ae_measurable).1 hfi) (range f ∪ {0})
(by simp [insert_subset_insert, set.range_comp_subset_range]) using 1,
ext1 i,
simp only [simple_func.approx_on_comp, simple_func.integral_eq, measure.map_apply, hφ,
simple_func.measurable_set_preimage, ← preimage_comp, simple_func.coe_comp],
refine (finset.sum_subset (simple_func.range_comp_subset_range _ hφ) (λ y _ hy, _)).symm,
rw [simple_func.mem_range, ← set.preimage_singleton_eq_empty, simple_func.coe_comp] at hy,
rw [hy],
simp,
end
lemma integral_map {β} [measurable_space β] {φ : α → β} (hφ : ae_measurable φ μ)
{f : β → E} (hfm : ae_strongly_measurable f (measure.map φ μ)) :
∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ :=
let g := hfm.mk f in calc
∫ y, f y ∂(measure.map φ μ) = ∫ y, g y ∂(measure.map φ μ) : integral_congr_ae hfm.ae_eq_mk
... = ∫ y, g y ∂(measure.map (hφ.mk φ) μ) :
by { congr' 1, exact measure.map_congr hφ.ae_eq_mk }
... = ∫ x, g (hφ.mk φ x) ∂μ :
integral_map_of_strongly_measurable hφ.measurable_mk hfm.strongly_measurable_mk
... = ∫ x, g (φ x) ∂μ : integral_congr_ae (hφ.ae_eq_mk.symm.fun_comp _)
... = ∫ x, f (φ x) ∂μ : integral_congr_ae $ ae_eq_comp hφ (hfm.ae_eq_mk).symm
lemma _root_.measurable_embedding.integral_map {β} {_ : measurable_space β} {f : α → β}
(hf : measurable_embedding f) (g : β → E) :
∫ y, g y ∂(measure.map f μ) = ∫ x, g (f x) ∂μ :=
begin
by_cases hgm : ae_strongly_measurable g (measure.map f μ),
{ exact integral_map hf.measurable.ae_measurable hgm },
{ rw [integral_non_ae_strongly_measurable hgm, integral_non_ae_strongly_measurable],
rwa ← hf.ae_strongly_measurable_map_iff }
end
lemma _root_.closed_embedding.integral_map {β} [topological_space α] [borel_space α]
[topological_space β] [measurable_space β] [borel_space β]
{φ : α → β} (hφ : closed_embedding φ) (f : β → E) :
∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ :=
hφ.measurable_embedding.integral_map _
lemma integral_map_equiv {β} [measurable_space β] (e : α ≃ᵐ β) (f : β → E) :
∫ y, f y ∂(measure.map e μ) = ∫ x, f (e x) ∂μ :=
e.measurable_embedding.integral_map f
lemma measure_preserving.integral_comp {β} {_ : measurable_space β} {f : α → β} {ν}
(h₁ : measure_preserving f μ ν) (h₂ : measurable_embedding f) (g : β → E) :
∫ x, g (f x) ∂μ = ∫ y, g y ∂ν :=
h₁.map_eq ▸ (h₂.integral_map g).symm
lemma set_integral_eq_subtype {α} [measure_space α] {s : set α} (hs : measurable_set s)
(f : α → E) :
∫ x in s, f x = ∫ x : s, f x :=
by { rw ← map_comap_subtype_coe hs, exact (measurable_embedding.subtype_coe hs).integral_map _ }
@[simp] lemma integral_dirac' [measurable_space α] (f : α → E) (a : α)
(hfm : strongly_measurable f) :
∫ x, f x ∂(measure.dirac a) = f a :=
begin
borelize E,
calc ∫ x, f x ∂(measure.dirac a) = ∫ x, f a ∂(measure.dirac a) :
integral_congr_ae $ ae_eq_dirac' hfm.measurable
... = f a : by simp [measure.dirac_apply_of_mem]
end
@[simp] lemma integral_dirac [measurable_space α] [measurable_singleton_class α]
(f : α → E) (a : α) : ∫ x, f x ∂(measure.dirac a) = f a :=
calc ∫ x, f x ∂(measure.dirac a) = ∫ x, f a ∂(measure.dirac a) :
integral_congr_ae $ ae_eq_dirac f
... = f a : by simp [measure.dirac_apply_of_mem]
lemma set_integral_dirac' {mα : measurable_space α} {f : α → E} (hf : strongly_measurable f)
(a : α) {s : set α} (hs : measurable_set s) [decidable (a ∈ s)] :
∫ x in s, f x ∂(measure.dirac a) = if a ∈ s then f a else 0 :=
begin
rw [restrict_dirac' hs],
swap, { apply_instance, },
split_ifs,
{ exact integral_dirac' _ _ hf, },
{ exact integral_zero_measure _, },
end
lemma set_integral_dirac [measurable_space α] [measurable_singleton_class α] (f : α → E)
(a : α) (s : set α) [decidable (a ∈ s)] :
∫ x in s, f x ∂(measure.dirac a) = if a ∈ s then f a else 0 :=
begin
rw [restrict_dirac],
split_ifs,
{ exact integral_dirac _ _, },
{ exact integral_zero_measure _, },
end
lemma mul_meas_ge_le_integral_of_nonneg [is_finite_measure μ] {f : α → ℝ} (hf_nonneg : 0 ≤ f)
(hf_int : integrable f μ) (ε : ℝ) :
ε * (μ {x | ε ≤ f x}).to_real ≤ ∫ x, f x ∂μ :=
begin
cases lt_or_le ε 0 with hε hε,
{ exact (mul_nonpos_of_nonpos_of_nonneg hε.le ennreal.to_real_nonneg).trans
(integral_nonneg hf_nonneg), },
rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (λ x, hf_nonneg x))
hf_int.ae_strongly_measurable, ← ennreal.to_real_of_real hε, ← ennreal.to_real_mul],
have : {x : α | (ennreal.of_real ε).to_real ≤ f x}
= {x : α | ennreal.of_real ε ≤ (λ x, ennreal.of_real (f x)) x},
{ ext1 x,
rw [set.mem_set_of_eq, set.mem_set_of_eq, ← ennreal.to_real_of_real (hf_nonneg x)],
exact ennreal.to_real_le_to_real ennreal.of_real_ne_top ennreal.of_real_ne_top, },
rw this,
have h_meas : ae_measurable (λ x, ennreal.of_real (f x)) μ,
from measurable_id'.ennreal_of_real.comp_ae_measurable hf_int.ae_measurable,
have h_mul_meas_le := @mul_meas_ge_le_lintegral₀ _ _ μ _ h_meas (ennreal.of_real ε),
rw ennreal.to_real_le_to_real _ _,
{ exact h_mul_meas_le, },
{ simp only [ne.def, with_top.mul_eq_top_iff, ennreal.of_real_eq_zero, not_le,
ennreal.of_real_ne_top, false_and, or_false, not_and],
exact λ _, measure_ne_top _ _, },
{ have h_lt_top : ∫⁻ a, ‖f a‖₊ ∂μ < ∞ := hf_int.has_finite_integral,
simp_rw [← of_real_norm_eq_coe_nnnorm, real.norm_eq_abs] at h_lt_top,
convert h_lt_top.ne,
ext1 x,
rw abs_of_nonneg (hf_nonneg x), },
end
/-- Hölder's inequality for the integral of a product of norms. The integral of the product of two
norms of functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are
conjugate exponents. -/
theorem integral_mul_norm_le_Lp_mul_Lq {E} [normed_add_comm_group E] {f g : α → E}
{p q : ℝ} (hpq : p.is_conjugate_exponent q)
(hf : mem_ℒp f (ennreal.of_real p) μ) (hg : mem_ℒp g (ennreal.of_real q) μ) :
∫ a, ‖f a‖ * ‖g a‖ ∂μ ≤ (∫ a, ‖f a‖ ^ p ∂μ) ^ (1/p) * (∫ a, ‖g a‖ ^ q ∂μ) ^ (1/q) :=
begin
-- translate the Bochner integrals into Lebesgue integrals.
rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae,
integral_eq_lintegral_of_nonneg_ae],
rotate 1,
{ exact eventually_of_forall (λ x, real.rpow_nonneg_of_nonneg (norm_nonneg _) _), },
{ exact (hg.1.norm.ae_measurable.pow ae_measurable_const).ae_strongly_measurable, },
{ exact eventually_of_forall (λ x, real.rpow_nonneg_of_nonneg (norm_nonneg _) _),},
{ exact (hf.1.norm.ae_measurable.pow ae_measurable_const).ae_strongly_measurable, },
{ exact eventually_of_forall (λ x, mul_nonneg (norm_nonneg _) (norm_nonneg _)), },
{ exact hf.1.norm.mul hg.1.norm, },
rw [ennreal.to_real_rpow, ennreal.to_real_rpow, ← ennreal.to_real_mul],
-- replace norms by nnnorm
have h_left : ∫⁻ a, ennreal.of_real (‖f a‖ * ‖g a‖) ∂μ
= ∫⁻ a, ((λ x, (‖f x‖₊ : ℝ≥0∞)) * (λ x, ‖g x‖₊)) a ∂μ,
{ simp_rw [pi.mul_apply, ← of_real_norm_eq_coe_nnnorm, ennreal.of_real_mul (norm_nonneg _)], },
have h_right_f : ∫⁻ a, ennreal.of_real (‖f a‖ ^ p) ∂μ = ∫⁻ a, ‖f a‖₊ ^ p ∂μ,
{ refine lintegral_congr (λ x, _),
rw [← of_real_norm_eq_coe_nnnorm, ennreal.of_real_rpow_of_nonneg (norm_nonneg _) hpq.nonneg], },
have h_right_g : ∫⁻ a, ennreal.of_real (‖g a‖ ^ q) ∂μ = ∫⁻ a, ‖g a‖₊ ^ q ∂μ,
{ refine lintegral_congr (λ x, _),
rw [← of_real_norm_eq_coe_nnnorm,
ennreal.of_real_rpow_of_nonneg (norm_nonneg _) hpq.symm.nonneg], },
rw [h_left, h_right_f, h_right_g],
-- we can now apply `ennreal.lintegral_mul_le_Lp_mul_Lq` (up to the `to_real` application)
refine ennreal.to_real_mono _ _,
{ refine ennreal.mul_ne_top _ _,
{ convert hf.snorm_ne_top,
rw snorm_eq_lintegral_rpow_nnnorm,
{ rw ennreal.to_real_of_real hpq.nonneg, },
{ rw [ne.def, ennreal.of_real_eq_zero, not_le],
exact hpq.pos, },
{ exact ennreal.coe_ne_top, }, },
{ convert hg.snorm_ne_top,
rw snorm_eq_lintegral_rpow_nnnorm,
{ rw ennreal.to_real_of_real hpq.symm.nonneg, },
{ rw [ne.def, ennreal.of_real_eq_zero, not_le],
exact hpq.symm.pos, },
{ exact ennreal.coe_ne_top, }, }, },
{ exact ennreal.lintegral_mul_le_Lp_mul_Lq μ hpq hf.1.nnnorm.ae_measurable.coe_nnreal_ennreal
hg.1.nnnorm.ae_measurable.coe_nnreal_ennreal, },
end
/-- Hölder's inequality for functions `α → ℝ`. The integral of the product of two nonnegative
functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem integral_mul_le_Lp_mul_Lq_of_nonneg {p q : ℝ}
(hpq : p.is_conjugate_exponent q) {f g : α → ℝ} (hf_nonneg : 0 ≤ᵐ[μ] f) (hg_nonneg : 0 ≤ᵐ[μ] g)
(hf : mem_ℒp f (ennreal.of_real p) μ) (hg : mem_ℒp g (ennreal.of_real q) μ) :
∫ a, f a * g a ∂μ ≤ (∫ a, (f a) ^ p ∂μ) ^ (1/p) * (∫ a, (g a) ^ q ∂μ) ^ (1/q) :=
begin
have h_left : ∫ a, f a * g a ∂μ = ∫ a, ‖f a‖ * ‖g a‖ ∂μ,
{ refine integral_congr_ae _,
filter_upwards [hf_nonneg, hg_nonneg] with x hxf hxg,
rw [real.norm_of_nonneg hxf, real.norm_of_nonneg hxg], },
have h_right_f : ∫ a, (f a) ^ p ∂μ = ∫ a, ‖f a‖ ^ p ∂μ,
{ refine integral_congr_ae _,
filter_upwards [hf_nonneg] with x hxf,
rw real.norm_of_nonneg hxf, },
have h_right_g : ∫ a, (g a) ^ q ∂μ = ∫ a, ‖g a‖ ^ q ∂μ,
{ refine integral_congr_ae _,
filter_upwards [hg_nonneg] with x hxg,
rw real.norm_of_nonneg hxg, },
rw [h_left, h_right_f, h_right_g],
exact integral_mul_norm_le_Lp_mul_Lq hpq hf hg,
end
end properties
section integral_trim
variables {H β γ : Type*} [normed_add_comm_group H]
{m m0 : measurable_space β} {μ : measure β}
/-- Simple function seen as simple function of a larger `measurable_space`. -/
def simple_func.to_larger_space (hm : m ≤ m0) (f : @simple_func β m γ) : simple_func β γ :=
⟨@simple_func.to_fun β m γ f, λ x, hm _ (@simple_func.measurable_set_fiber β γ m f x),
@simple_func.finite_range β γ m f⟩
lemma simple_func.coe_to_larger_space_eq (hm : m ≤ m0) (f : @simple_func β m γ) :
⇑(f.to_larger_space hm) = f :=
rfl
lemma integral_simple_func_larger_space (hm : m ≤ m0) (f : @simple_func β m F)
(hf_int : integrable f μ) :
∫ x, f x ∂μ = ∑ x in (@simple_func.range β F m f), (ennreal.to_real (μ (f ⁻¹' {x}))) • x :=
begin
simp_rw ← f.coe_to_larger_space_eq hm,
have hf_int : integrable (f.to_larger_space hm) μ, by rwa simple_func.coe_to_larger_space_eq,
rw simple_func.integral_eq_sum _ hf_int,
congr,
end
lemma integral_trim_simple_func (hm : m ≤ m0) (f : @simple_func β m F) (hf_int : integrable f μ) :
∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) :=
begin
have hf : strongly_measurable[m] f, from @simple_func.strongly_measurable β F m _ f,
have hf_int_m := hf_int.trim hm hf,
rw [integral_simple_func_larger_space (le_refl m) f hf_int_m,
integral_simple_func_larger_space hm f hf_int],
congr' with x,
congr,
exact (trim_measurable_set_eq hm (@simple_func.measurable_set_fiber β F m f x)).symm,
end
lemma integral_trim (hm : m ≤ m0) {f : β → F} (hf : strongly_measurable[m] f) :
∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) :=
begin
borelize F,
by_cases hf_int : integrable f μ,
swap,
{ have hf_int_m : ¬ integrable f (μ.trim hm),
from λ hf_int_m, hf_int (integrable_of_integrable_trim hm hf_int_m),
rw [integral_undef hf_int, integral_undef hf_int_m], },
haveI : separable_space (range f ∪ {0} : set F) := hf.separable_space_range_union_singleton,
let f_seq := @simple_func.approx_on F β _ _ _ m _ hf.measurable (range f ∪ {0}) 0 (by simp) _,
have hf_seq_meas : ∀ n, strongly_measurable[m] (f_seq n),
from λ n, @simple_func.strongly_measurable β F m _ (f_seq n),
have hf_seq_int : ∀ n, integrable (f_seq n) μ,
from simple_func.integrable_approx_on_range (hf.mono hm).measurable hf_int,
have hf_seq_int_m : ∀ n, integrable (f_seq n) (μ.trim hm),
from λ n, (hf_seq_int n).trim hm (hf_seq_meas n) ,
have hf_seq_eq : ∀ n, ∫ x, f_seq n x ∂μ = ∫ x, f_seq n x ∂(μ.trim hm),
from λ n, integral_trim_simple_func hm (f_seq n) (hf_seq_int n),
have h_lim_1 : at_top.tendsto (λ n, ∫ x, f_seq n x ∂μ) (𝓝 (∫ x, f x ∂μ)),
{ refine tendsto_integral_of_L1 f hf_int (eventually_of_forall hf_seq_int) _,
exact simple_func.tendsto_approx_on_range_L1_nnnorm (hf.mono hm).measurable hf_int, },
have h_lim_2 : at_top.tendsto (λ n, ∫ x, f_seq n x ∂μ) (𝓝 (∫ x, f x ∂(μ.trim hm))),
{ simp_rw hf_seq_eq,
refine @tendsto_integral_of_L1 β F _ _ _ m (μ.trim hm) _ f
(hf_int.trim hm hf) _ _ (eventually_of_forall hf_seq_int_m) _,
exact @simple_func.tendsto_approx_on_range_L1_nnnorm β F m _ _ _ f _ _
hf.measurable (hf_int.trim hm hf), },
exact tendsto_nhds_unique h_lim_1 h_lim_2,
end
lemma integral_trim_ae (hm : m ≤ m0) {f : β → F} (hf : ae_strongly_measurable f (μ.trim hm)) :
∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) :=
begin
rw [integral_congr_ae (ae_eq_of_ae_eq_trim hf.ae_eq_mk), integral_congr_ae hf.ae_eq_mk],
exact integral_trim hm hf.strongly_measurable_mk,
end
lemma ae_eq_trim_of_strongly_measurable
[topological_space γ] [metrizable_space γ] (hm : m ≤ m0) {f g : β → γ}
(hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) (hfg : f =ᵐ[μ] g) :
f =ᵐ[μ.trim hm] g :=
begin
rwa [eventually_eq, ae_iff, trim_measurable_set_eq hm _],
exact (hf.measurable_set_eq_fun hg).compl
end
lemma ae_eq_trim_iff [topological_space γ] [metrizable_space γ]
(hm : m ≤ m0) {f g : β → γ} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) :
f =ᵐ[μ.trim hm] g ↔ f =ᵐ[μ] g :=
⟨ae_eq_of_ae_eq_trim, ae_eq_trim_of_strongly_measurable hm hf hg⟩
lemma ae_le_trim_of_strongly_measurable
[linear_order γ] [topological_space γ] [order_closed_topology γ] [pseudo_metrizable_space γ]
(hm : m ≤ m0) {f g : β → γ} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g)
(hfg : f ≤ᵐ[μ] g) :
f ≤ᵐ[μ.trim hm] g :=
begin
rwa [eventually_le, ae_iff, trim_measurable_set_eq hm _],
exact (hf.measurable_set_le hg).compl,
end
lemma ae_le_trim_iff
[linear_order γ] [topological_space γ] [order_closed_topology γ] [pseudo_metrizable_space γ]
(hm : m ≤ m0) {f g : β → γ} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) :
f ≤ᵐ[μ.trim hm] g ↔ f ≤ᵐ[μ] g :=
⟨ae_le_of_ae_le_trim, ae_le_trim_of_strongly_measurable hm hf hg⟩
end integral_trim
section snorm_bound
variables {m0 : measurable_space α} {μ : measure α}
lemma snorm_one_le_of_le {r : ℝ≥0} {f : α → ℝ}
(hfint : integrable f μ) (hfint' : 0 ≤ ∫ x, f x ∂μ) (hf : ∀ᵐ ω ∂μ, f ω ≤ r) :
snorm f 1 μ ≤ 2 * μ set.univ * r :=
begin
by_cases hr : r = 0,
{ suffices : f =ᵐ[μ] 0,
{ rw [snorm_congr_ae this, snorm_zero, hr, ennreal.coe_zero, mul_zero],
exact le_rfl },
rw [hr, nonneg.coe_zero] at hf,
have hnegf : ∫ x, -f x ∂μ = 0,
{ rw [integral_neg, neg_eq_zero],
exact le_antisymm (integral_nonpos_of_ae hf) hfint' },
have := (integral_eq_zero_iff_of_nonneg_ae _ hfint.neg).1 hnegf,
{ filter_upwards [this] with ω hω,
rwa [pi.neg_apply, pi.zero_apply, neg_eq_zero] at hω },
{ filter_upwards [hf] with ω hω,
rwa [pi.zero_apply, pi.neg_apply, right.nonneg_neg_iff] } },
by_cases hμ : is_finite_measure μ,
swap,
{ have : μ set.univ = ∞,
{ by_contra hμ',
exact hμ (is_finite_measure.mk $ lt_top_iff_ne_top.2 hμ') },
rw [this, ennreal.mul_top, if_neg, ennreal.top_mul, if_neg],
{ exact le_top },
{ simp [hr] },
{ norm_num } },
haveI := hμ,
rw [integral_eq_integral_pos_part_sub_integral_neg_part hfint, sub_nonneg] at hfint',
have hposbdd : ∫ ω, max (f ω) 0 ∂μ ≤ (μ set.univ).to_real • r,
{ rw ← integral_const,
refine integral_mono_ae hfint.real_to_nnreal (integrable_const r) _,
filter_upwards [hf] with ω hω using real.to_nnreal_le_iff_le_coe.2 hω },
rw [mem_ℒp.snorm_eq_integral_rpow_norm one_ne_zero ennreal.one_ne_top
(mem_ℒp_one_iff_integrable.2 hfint),
ennreal.of_real_le_iff_le_to_real (ennreal.mul_ne_top
(ennreal.mul_ne_top ennreal.two_ne_top $ @measure_ne_top _ _ _ hμ _) ennreal.coe_ne_top)],
simp_rw [ennreal.one_to_real, _root_.inv_one, real.rpow_one, real.norm_eq_abs,
← max_zero_add_max_neg_zero_eq_abs_self, ← real.coe_to_nnreal'],
rw integral_add hfint.real_to_nnreal,
{ simp only [real.coe_to_nnreal', ennreal.to_real_mul, ennreal.to_real_bit0,
ennreal.one_to_real, ennreal.coe_to_real] at hfint' ⊢,
refine (add_le_add_left hfint' _).trans _,
rwa [← two_mul, mul_assoc, mul_le_mul_left (two_pos : (0 : ℝ) < 2)] },
{ exact hfint.neg.sup (integrable_zero _ _ μ) }
end
lemma snorm_one_le_of_le' {r : ℝ} {f : α → ℝ}
(hfint : integrable f μ) (hfint' : 0 ≤ ∫ x, f x ∂μ) (hf : ∀ᵐ ω ∂μ, f ω ≤ r) :
snorm f 1 μ ≤ 2 * μ set.univ * ennreal.of_real r :=
begin
refine snorm_one_le_of_le hfint hfint' _,
simp only [real.coe_to_nnreal', le_max_iff],
filter_upwards [hf] with ω hω using or.inl hω,
end
end snorm_bound
end measure_theory
|
a642078d624e9da306d51e706a70ae53f371e957 | 49bd2218ae088932d847f9030c8dbff1c5607bb7 | /src/data/set/function.lean | e2ab53bed1158dcda6900bdadf16ff2fb020dd74 | [
"Apache-2.0"
] | permissive | FredericLeRoux/mathlib | e8f696421dd3e4edc8c7edb3369421c8463d7bac | 3645bf8fb426757e0a20af110d1fdded281d286e | refs/heads/master | 1,607,062,870,732 | 1,578,513,186,000 | 1,578,513,186,000 | 231,653,181 | 0 | 0 | Apache-2.0 | 1,578,080,327,000 | 1,578,080,326,000 | null | UTF-8 | Lean | false | false | 12,551 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu
Functions over sets.
-/
import data.set.basic logic.function
open function
namespace set
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
/- maps to -/
/-- `maps_to f a b` means that the image of `a` is contained in `b`. -/
@[reducible] def maps_to (f : α → β) (a : set α) (b : set β) : Prop := a ⊆ f ⁻¹' b
theorem maps_to' (f : α → β) (a : set α) (b : set β) : maps_to f a b ↔ f '' a ⊆ b :=
image_subset_iff.symm
theorem maps_to_of_eq_on {f1 f2 : α → β} {a : set α} {b : set β} (h₁ : eq_on f1 f2 a)
(h₂ : maps_to f1 a b) :
maps_to f2 a b :=
λ x h, by rw [mem_preimage, ← h₁ _ h]; exact h₂ h
theorem maps_to_comp {g : β → γ} {f : α → β} {a : set α} {b : set β} {c : set γ}
(h₁ : maps_to g b c) (h₂ : maps_to f a b) : maps_to (g ∘ f) a c :=
λ x h, h₁ (h₂ h)
theorem maps_to_univ (f : α → β) (a) : maps_to f a univ :=
λ x h, trivial
theorem maps_to_image (f : α → β) (a : set α) : maps_to f a (f '' a) :=
by rw maps_to'
theorem maps_to_range (f : α → β) (a : set α) : maps_to f a (range f) :=
by rw [← image_univ, maps_to']; exact image_subset _ (subset_univ _)
theorem image_subset_of_maps_to_of_subset {f : α → β} {a c : set α} {b : set β} (h₁ : maps_to f a b)
(h₂ : c ⊆ a) :
f '' c ⊆ b :=
λ y hy, let ⟨x, hx, heq⟩ := hy in
by rw [←heq]; apply h₁; apply h₂; assumption
theorem image_subset_of_maps_to {f : α → β} {a : set α} {b : set β} (h : maps_to f a b) :
f '' a ⊆ b :=
image_subset_of_maps_to_of_subset h (subset.refl _)
/- injectivity -/
/-- `f` is injective on `a` if the restriction of `f` to `a` is injective. -/
@[reducible] def inj_on (f : α → β) (a : set α) : Prop :=
∀⦃x1 x2 : α⦄, x1 ∈ a → x2 ∈ a → f x1 = f x2 → x1 = x2
theorem inj_on_empty (f : α → β) : inj_on f ∅ :=
λ _ _ h₁ _ _, false.elim h₁
theorem inj_on_of_eq_on {f1 f2 : α → β} {a : set α} (h₁ : eq_on f1 f2 a)
(h₂ : inj_on f1 a) :
inj_on f2 a :=
λ _ _ h₁' h₂' heq, by apply h₂ h₁' h₂'; rw [h₁, heq, ←h₁]; repeat {assumption}
theorem inj_on_of_inj_on_of_subset {f : α → β} {a b : set α} (h₁ : inj_on f b) (h₂ : a ⊆ b) :
inj_on f a :=
λ _ _ h₁' h₂' heq, h₁ (h₂ h₁') (h₂ h₂') heq
lemma injective_iff_inj_on_univ {f : α → β} : injective f ↔ inj_on f univ :=
iff.intro (λ h _ _ _ _ heq, h heq) (λ h _ _ heq, h trivial trivial heq)
lemma inj_on_of_injective {α β : Type*} {f : α → β} (s : set α) (h : injective f) :
inj_on f s :=
inj_on_of_inj_on_of_subset (injective_iff_inj_on_univ.1 h) (subset_univ s)
theorem inj_on_comp {g : β → γ} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : inj_on g b) (h₃: inj_on f a) :
inj_on (g ∘ f) a :=
λ _ _ h₁' h₂' heq,
by apply h₃ h₁' h₂'; apply h₂; repeat {apply h₁, assumption}; assumption
lemma inj_on_comp_of_injective_left {g : β → γ} {f : α → β} {a : set α} (hg : injective g)
(hf : inj_on f a) : inj_on (g ∘ f) a :=
inj_on_comp (maps_to_univ _ _) (injective_iff_inj_on_univ.mp hg) hf
lemma inj_on_iff_injective {f : α → β} {s : set α} : inj_on f s ↔ injective (λ x:s, f x.1) :=
⟨λ H a b h, subtype.eq $ H a.2 b.2 h,
λ H a b as bs h, congr_arg subtype.val $ @H ⟨a, as⟩ ⟨b, bs⟩ h⟩
lemma inv_fun_on_image [inhabited α] {β : Type v} {s t : set α} {f : α → β}
(h : inj_on f s) (ht : t ⊆ s) : (inv_fun_on f s) '' (f '' t) = t :=
begin
have A : ∀z, z ∈ t → ((inv_fun_on f s) ∘ f) z = z := λz hz, inv_fun_on_eq' h (ht hz),
rw ← image_comp,
ext,
simp [A] {contextual := tt}
end
lemma inj_on_preimage {f : α → β} {B : set (set β)} (hB : B ⊆ powerset (range f)) :
inj_on (preimage f) B :=
begin
intros s t hs ht hst,
rw [←image_preimage_eq_of_subset (hB hs), ←image_preimage_eq_of_subset (hB ht), hst]
end
lemma subset_image_iff {s : set α} {t : set β} (f : α → β) :
t ⊆ f '' s ↔ ∃u⊆s, t = f '' u ∧ inj_on f u :=
begin
split,
{ assume h, choose g hg using h,
refine ⟨ {a | ∃ b (h : b ∈ t), g h = a }, _, set.ext $ assume b, ⟨_, _⟩, _⟩,
{ rintros a ⟨b, hb, rfl⟩,
exact (hg hb).1 },
{ rintros hb,
exact ⟨g hb, ⟨b, hb, rfl⟩, (hg hb).2⟩ },
{ rintros ⟨c, ⟨b, hb, rfl⟩, rfl⟩,
rwa (hg hb).2 },
{ rintros a₁ a₂ ⟨b₁, h₁, rfl⟩ ⟨b₂, h₂, rfl⟩ eq,
rw [(hg h₁).2, (hg h₂).2] at eq,
subst eq } },
{ rintros ⟨u, hu, rfl, _⟩,
exact image_subset _ hu }
end
lemma subset_range_iff {s : set β} (f : α → β) :
s ⊆ set.range f ↔ ∃u, s = f '' u ∧ inj_on f u :=
by rw [← image_univ, subset_image_iff]; simp
/- surjectivity -/
/-- `f` is surjective from `a` to `b` if `b` is contained in the image of `a`. -/
@[reducible] def surj_on (f : α → β) (a : set α) (b : set β) : Prop := b ⊆ f '' a
theorem surj_on_of_eq_on {f1 f2 : α → β} {a : set α} {b : set β} (h₁ : eq_on f1 f2 a)
(h₂ : surj_on f1 a b) :
surj_on f2 a b :=
λ _ h, let ⟨x, hx⟩ := h₂ h in
⟨x, hx.left, by rw [←h₁ _ hx.left]; exact hx.right⟩
theorem surj_on_comp {g : β → γ} {f : α → β} {a : set α} {b : set β} {c : set γ}
(h₁ : surj_on g b c) (h₂ : surj_on f a b) :
surj_on (g ∘ f) a c :=
λ z h, let ⟨y, hy⟩ := h₁ h, ⟨x, hx⟩ := h₂ hy.left in
⟨x, hx.left, calc g (f x) = g y : by rw [hx.right]
... = z : hy.right⟩
lemma surjective_iff_surj_on_univ {f : α → β} : surjective f ↔ surj_on f univ univ :=
by simp [surjective, surj_on, subset_def]
lemma surj_on_iff_surjective {f : α → β} {s : set α} : surj_on f s univ ↔ surjective (λ x:s, f x.1) :=
⟨λ H b, let ⟨a, as, e⟩ := @H b trivial in ⟨⟨a, as⟩, e⟩,
λ H b _, let ⟨⟨a, as⟩, e⟩ := H b in ⟨a, as, e⟩⟩
lemma image_eq_of_maps_to_of_surj_on {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : surj_on f a b) :
f '' a = b :=
eq_of_subset_of_subset (image_subset_of_maps_to h₁) h₂
/- bijectivity -/
/-- `f` is bijective from `a` to `b` if `f` is injective on `a` and `f '' a = b`. -/
@[reducible] def bij_on (f : α → β) (a : set α) (b : set β) : Prop :=
maps_to f a b ∧ inj_on f a ∧ surj_on f a b
lemma maps_to_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
maps_to f a b :=
h.left
lemma inj_on_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
inj_on f a :=
h.right.left
lemma surj_on_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
surj_on f a b :=
h.right.right
lemma bij_on.mk {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : inj_on f a) (h₃ : surj_on f a b) :
bij_on f a b :=
⟨h₁, h₂, h₃⟩
lemma inj_on.to_bij_on {f : α → β} {a : set α} (h : inj_on f a) : bij_on f a (f '' a) :=
bij_on.mk (maps_to_image f a) h (subset.refl _)
theorem bij_on_of_eq_on {f1 f2 : α → β} {a : set α} {b : set β} (h₁ : eq_on f1 f2 a)
(h₂ : bij_on f1 a b) : bij_on f2 a b :=
let ⟨map, inj, surj⟩ := h₂ in
⟨maps_to_of_eq_on h₁ map, inj_on_of_eq_on h₁ inj, surj_on_of_eq_on h₁ surj⟩
lemma image_eq_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
f '' a = b :=
image_eq_of_maps_to_of_surj_on h.left h.right.right
theorem bij_on_comp {g : β → γ} {f : α → β} {a : set α} {b : set β} {c : set γ}
(h₁ : bij_on g b c) (h₂: bij_on f a b) :
bij_on (g ∘ f) a c :=
let ⟨gmap, ginj, gsurj⟩ := h₁, ⟨fmap, finj, fsurj⟩ := h₂ in
⟨maps_to_comp gmap fmap, inj_on_comp fmap ginj finj, surj_on_comp gsurj fsurj⟩
lemma bijective_iff_bij_on_univ {f : α → β} : bijective f ↔ bij_on f univ univ :=
iff.intro
(λ h, let ⟨inj, surj⟩ := h in
⟨maps_to_univ f _, iff.mp injective_iff_inj_on_univ inj, iff.mp surjective_iff_surj_on_univ surj⟩)
(λ h, let ⟨map, inj, surj⟩ := h in
⟨iff.mpr injective_iff_inj_on_univ inj, iff.mpr surjective_iff_surj_on_univ surj⟩)
/- left inverse -/
/-- `g` is a left inverse to `f` on `a` means that `g (f x) = x` for all `x ∈ a`. -/
@[reducible] def left_inv_on (g : β → α) (f : α → β) (a : set α) : Prop :=
∀ x ∈ a, g (f x) = x
theorem left_inv_on_of_eq_on_left {g1 g2 : β → α} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : eq_on g1 g2 b) (h₃ : left_inv_on g1 f a) : left_inv_on g2 f a :=
λ x h,
calc
g2 (f x) = g1 (f x) : eq.symm $ h₂ _ (h₁ h)
... = x : h₃ _ h
theorem left_inv_on_of_eq_on_right {g : β → α} {f1 f2 : α → β} {a : set α}
(h₁ : eq_on f1 f2 a) (h₂ : left_inv_on g f1 a) : left_inv_on g f2 a :=
λ x h,
calc
g (f2 x) = g (f1 x) : congr_arg g (h₁ _ h).symm
... = x : h₂ _ h
theorem inj_on_of_left_inv_on {g : β → α} {f : α → β} {a : set α} (h : left_inv_on g f a) :
inj_on f a :=
λ x₁ x₂ h₁ h₂ heq,
calc
x₁ = g (f x₁) : eq.symm $ h _ h₁
... = g (f x₂) : congr_arg g heq
... = x₂ : h _ h₂
theorem left_inv_on_comp {f' : β → α} {g' : γ → β} {g : β → γ} {f : α → β}
{a : set α} {b : set β} (h₁ : maps_to f a b)
(h₂ : left_inv_on f' f a) (h₃ : left_inv_on g' g b) : left_inv_on (f' ∘ g') (g ∘ f) a :=
λ x h,
calc
(f' ∘ g') ((g ∘ f) x) = f' (f x) : congr_arg f' (h₃ _ (h₁ h))
... = x : h₂ _ h
/- right inverse -/
/-- `g` is a right inverse to `f` on `b` if `f (g x) = x` for all `x ∈ b`. -/
@[reducible] def right_inv_on (g : β → α) (f : α → β) (b : set β) : Prop :=
left_inv_on f g b
theorem right_inv_on_of_eq_on_left {g1 g2 : β → α} {f : α → β} {b : set β}
(h₁ : eq_on g1 g2 b) (h₂ : right_inv_on g1 f b) : right_inv_on g2 f b :=
left_inv_on_of_eq_on_right h₁ h₂
theorem right_inv_on_of_eq_on_right {g : β → α} {f1 f2 : α → β} {a : set α} {b : set β}
(h₁ : maps_to g b a) (h₂ : eq_on f1 f2 a) (h₃ : right_inv_on g f1 b) : right_inv_on g f2 b :=
left_inv_on_of_eq_on_left h₁ h₂ h₃
theorem surj_on_of_right_inv_on {g : β → α} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to g b a) (h₂ : right_inv_on g f b) :
surj_on f a b :=
λ y h, ⟨g y, h₁ h, h₂ _ h⟩
theorem right_inv_on_comp {f' : β → α} {g' : γ → β} {g : β → γ} {f : α → β}
{c : set γ} {b : set β} (g'cb : maps_to g' c b)
(h₁ : right_inv_on f' f b) (h₂ : right_inv_on g' g c) : right_inv_on (f' ∘ g') (g ∘ f) c :=
left_inv_on_comp g'cb h₂ h₁
theorem right_inv_on_of_inj_on_of_left_inv_on {f : α → β} {g : β → α} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : maps_to g b a) (h₃ : inj_on f a) (h₄ : left_inv_on f g b) :
right_inv_on f g a :=
λ x h, h₃ (h₂ $ h₁ h) h (h₄ _ (h₁ h))
theorem eq_on_of_left_inv_of_right_inv {g₁ g₂ : β → α} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to g₂ b a) (h₂ : left_inv_on g₁ f a) (h₃ : right_inv_on g₂ f b) : eq_on g₁ g₂ b :=
λ y h,
calc
g₁ y = (g₁ ∘ f ∘ g₂) y : congr_arg g₁ (h₃ _ h).symm
... = g₂ y : h₂ _ (h₁ h)
theorem left_inv_on_of_surj_on_right_inv_on {f : α → β} {g : β → α} {a : set α} {b : set β}
(h₁ : surj_on f a b) (h₂ : right_inv_on f g a) :
left_inv_on f g b :=
λ y h, let ⟨x, hx, heq⟩ := h₁ h in
calc
(f ∘ g) y = (f ∘ g ∘ f) x : congr_arg (f ∘ g) heq.symm
... = f x : congr_arg f (h₂ _ hx)
... = y : heq
/- inverses -/
/-- `g` is an inverse to `f` viewed as a map from `a` to `b` -/
@[reducible] def inv_on (g : β → α) (f : α → β) (a : set α) (b : set β) : Prop :=
left_inv_on g f a ∧ right_inv_on g f b
theorem bij_on_of_inv_on {g : β → α} {f : α → β} {a : set α} {b : set β} (h₁ : maps_to f a b)
(h₂ : maps_to g b a) (h₃ : inv_on g f a b) : bij_on f a b :=
⟨h₁, inj_on_of_left_inv_on h₃.left, surj_on_of_right_inv_on h₂ h₃.right⟩
lemma range_restrict {α : Type*} {β : Type*} (f : α → β) (p : set α) :
range (restrict f p) = f '' (p : set α) :=
by { ext x, simp [restrict], refl }
end set
|
dd62dbe60a83f7f39c9e876591c8f47d6c851a10 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/readerThe.lean | 60d4ca7062252af0dd8e8828f31bab429363af0d | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 345 | lean | new_frontend
abbrev M := ReaderT String $ StateT Nat $ ReaderT Bool $ IO
def f : M Nat := do
let s ← read
IO.println s
let b ← readThe Bool
IO.println b
let s ← get
pure s
#eval (f "hello").run' 10 true
def g : M Nat :=
let a : M Nat := adaptTheReader Bool not f
adaptReader (fun s => s ++ " world") a
#eval (g "hello").run' 10 true
|
ff3eb62b79cf8b207e45ee19734a4c4616656e24 | cf39355caa609c0f33405126beee2739aa3cb77e | /tmp/even_odd.lean | 0bba9914d2f39ace46fe35d90b53d8c62bce0e19 | [
"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 | 949 | lean | import data.vector
open nat
universes u v
-- set_option trace.eqn_compiler.wf_rec true
set_option trace.debug.eqn_compiler.wf_rec true
-- set_option trace.debug.eqn_compiler.mutual true
mutual def even, odd
with even : nat → bool
| 0 := tt
| (a+1) := odd a
with odd : nat → bool
| 0 := ff
| (a+1) := even a
#print even
#print even._main
#print _mutual.even.odd
#eval even 3
#eval even 4
#eval odd 3
#eval odd 4
#check even.equations._eqn_1
#check even.equations._eqn_2
#check odd.equations._eqn_1
#check odd.equations._eqn_2
mutual def f, g {α β : Type u} (p : α × β)
with f : Π n : nat, vector (α × β) n
| 0 := vector.nil
| (succ n) := vector.cons p $ (g n p.1).map (λ b, (p.1, b))
with g : Π n : nat, α → vector β n
| 0 a := vector.nil
| (succ n) a := vector.cons p.2 $ (f n).map (λ p, p.2)
#check @f.equations._eqn_1
#check @f.equations._eqn_2
#check @g.equations._eqn_1
#check @g.equations._eqn_2
|
da35cfd0f8f703aa95adcbfe39c868f19903fdc3 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/measure_theory/haar_measure.lean | 9356d8a218ae2e0c789b12c8f805080534f485ed | [
"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 | 31,470 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.content
import measure_theory.prod_group
/-!
# Haar measure
In this file we prove the existence of Haar measure for a locally compact Hausdorff topological
group.
For the construction, we follow the write-up by Jonathan Gleason,
*Existence and Uniqueness of Haar Measure*.
This is essentially the same argument as in
https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets.
We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest)
number of left-translates of `U` are needed to cover `K` (`index` in the formalization).
Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`,
where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set
with nonempty interior. This function is `chaar` in the formalization, and we define the limit
formally using Tychonoff's theorem.
This function `h` forms a content, which we can extend to an outer measure `μ`
(`haar_outer_measure`), and obtain the Haar measure from that (`haar_measure`).
We normalize the Haar measure so that the measure of `K₀` is `1`.
We show that for second countable spaces any left invariant Borel measure is a scalar multiple of
the Haar measure.
Note that `μ` need not coincide with `h` on compact sets, according to
[halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`,
where `ᵒ` denotes the interior.
## Main Declarations
* `haar_measure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant
regular measure. It takes as argument a compact set of the group (with non-empty interior),
and is normalized so that the measure of the given set is 1.
* `haar_measure_self`: the Haar measure is normalized.
* `is_left_invariant_haar_measure`: the Haar measure is left invariant.
* `regular_haar_measure`: the Haar measure is a regular measure.
## References
* Paul Halmos (1950), Measure Theory, §53
* Jonathan Gleason, Existence and Uniqueness of Haar Measure
- Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact
sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11)
invalid.
* https://en.wikipedia.org/wiki/Haar_measure
-/
noncomputable theory
open set has_inv function topological_space measurable_space
open_locale nnreal classical ennreal
variables {G : Type*} [group G]
namespace measure_theory
namespace measure
/-! We put the internal functions in the construction of the Haar measure in a namespace,
so that the chosen names don't clash with other declarations.
We first define a couple of the functions before proving the properties (that require that `G`
is a topological group). -/
namespace haar
/-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`:
it is the smallest number of (left) translates of `V` that is necessary to cover `K`.
It is defined to be 0 if no finite number of translates cover `K`. -/
def index (K V : set G) : ℕ :=
Inf $ finset.card '' {t : finset G | K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V }
lemma index_empty {V : set G} : index ∅ V = 0 :=
begin
simp only [index, nat.Inf_eq_zero], left, use ∅,
simp only [finset.card_empty, empty_subset, mem_set_of_eq, eq_self_iff_true, and_self],
end
variables [topological_space G]
/-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`.
In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`,
and `K` is any compact set.
The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an
element of `haar_product` (below). -/
def prehaar (K₀ U : set G) (K : compacts G) : ℝ := (index K.1 U : ℝ) / index K₀ U
lemma prehaar_empty (K₀ : positive_compacts G) {U : set G} : prehaar K₀.1 U ⊥ = 0 :=
by { simp only [prehaar, compacts.bot_val, index_empty, nat.cast_zero, zero_div] }
lemma prehaar_nonneg (K₀ : positive_compacts G) {U : set G} (K : compacts G) :
0 ≤ prehaar K₀.1 U K :=
by apply div_nonneg; norm_cast; apply zero_le
/-- `haar_product K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`.
For all `U`, we can show that `prehaar K₀ U ∈ haar_product K₀`. -/
def haar_product (K₀ : set G) : set (compacts G → ℝ) :=
pi univ (λ K, Icc 0 $ index K.1 K₀)
@[simp] lemma mem_prehaar_empty {K₀ : set G} {f : compacts G → ℝ} :
f ∈ haar_product K₀ ↔ ∀ K : compacts G, f K ∈ Icc (0 : ℝ) (index K.1 K₀) :=
by simp only [haar_product, pi, forall_prop_of_true, mem_univ, mem_set_of_eq]
/-- The closure of the collection of elements of the form `prehaar K₀ U`,
for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space
`compacts G → ℝ`, with the topology of pointwise convergence.
We show that the intersection of all these sets is nonempty, and the Haar measure
on compact sets is defined to be an element in the closure of this intersection. -/
def cl_prehaar (K₀ : set G) (V : open_nhds_of (1 : G)) : set (compacts G → ℝ) :=
closure $ prehaar K₀ '' { U : set G | U ⊆ V.1 ∧ is_open U ∧ (1 : G) ∈ U }
variables [topological_group G]
/-!
### Lemmas about `index`
-/
/-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined,
there is a finite set `t` satisfying the desired properties. -/
lemma index_defined {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) :
∃ n : ℕ, n ∈ finset.card '' {t : finset G | K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V } :=
by { rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩, exact ⟨t.card, t, ht, rfl⟩ }
lemma index_elim {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) :
∃ (t : finset G), K ⊆ (⋃ g ∈ t, (λ h, g * h) ⁻¹' V) ∧ finset.card t = index K V :=
by { have := nat.Inf_mem (index_defined hK hV), rwa [mem_image] at this }
lemma le_index_mul (K₀ : positive_compacts G) (K : compacts G) {V : set G}
(hV : (interior V).nonempty) : index K.1 V ≤ index K.1 K₀.1 * index K₀.1 V :=
begin
rcases index_elim K.2 K₀.2.2 with ⟨s, h1s, h2s⟩,
rcases index_elim K₀.2.1 hV with ⟨t, h1t, h2t⟩,
rw [← h2s, ← h2t, mul_comm],
refine le_trans _ finset.mul_card_le,
apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], refine subset.trans h1s _,
apply bUnion_subset, intros g₁ hg₁, rw preimage_subset_iff, intros g₂ hg₂,
have := h1t hg₂,
rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩, rw [mem_preimage, ← mul_assoc] at h2V,
exact mem_bUnion (finset.mul_mem_mul hg₃ hg₁) h2V
end
lemma index_pos (K : positive_compacts G) {V : set G} (hV : (interior V).nonempty) :
0 < index K.1 V :=
begin
unfold index, rw [nat.Inf_def, nat.find_pos, mem_image],
{ rintro ⟨t, h1t, h2t⟩, rw [finset.card_eq_zero] at h2t, subst h2t,
cases K.2.2 with g hg,
show g ∈ (∅ : set G), convert h1t (interior_subset hg), symmetry, apply bUnion_empty },
{ exact index_defined K.2.1 hV }
end
lemma index_mono {K K' V : set G} (hK' : is_compact K') (h : K ⊆ K')
(hV : (interior V).nonempty) : index K V ≤ index K' V :=
begin
rcases index_elim hK' hV with ⟨s, h1s, h2s⟩,
apply nat.Inf_le, rw [mem_image], refine ⟨s, subset.trans h h1s, h2s⟩
end
lemma index_union_le (K₁ K₂ : compacts G) {V : set G} (hV : (interior V).nonempty) :
index (K₁.1 ∪ K₂.1) V ≤ index K₁.1 V + index K₂.1 V :=
begin
rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩,
rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩,
rw [← h2s, ← h2t],
refine le_trans _ (finset.card_union_le _ _),
apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq],
apply union_subset; refine subset.trans (by assumption) _; apply bUnion_subset_bUnion_left;
intros g hg; simp only [mem_def] at hg;
simp only [mem_def, multiset.mem_union, finset.union_val, hg, or_true, true_or]
end
lemma index_union_eq (K₁ K₂ : compacts G) {V : set G} (hV : (interior V).nonempty)
(h : disjoint (K₁.1 * V⁻¹) (K₂.1 * V⁻¹)) :
index (K₁.1 ∪ K₂.1) V = index K₁.1 V + index K₂.1 V :=
begin
apply le_antisymm (index_union_le K₁ K₂ hV),
rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩, rw [← h2s],
have : ∀ (K : set G) , K ⊆ (⋃ g ∈ s, (λ h, g * h) ⁻¹' V) →
index K V ≤ (s.filter (λ g, ((λ (h : G), g * h) ⁻¹' V ∩ K).nonempty)).card,
{ intros K hK, apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq],
intros g hg, rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩,
simp only [mem_preimage] at h2g₀,
simp only [mem_Union], use g₀, split,
{ simp only [finset.mem_filter, h1g₀, true_and], use g,
simp only [hg, h2g₀, mem_inter_eq, mem_preimage, and_self] },
exact h2g₀ },
refine le_trans (add_le_add (this K₁.1 $ subset.trans (subset_union_left _ _) h1s)
(this K₂.1 $ subset.trans (subset_union_right _ _) h1s)) _,
rw [← finset.card_union_eq, finset.filter_union_right],
exact s.card_filter_le _,
apply finset.disjoint_filter.mpr,
rintro g₁ h1g₁ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩,
simp only [mem_preimage] at h1g₃ h1g₂,
apply @h g₁⁻¹,
split; simp only [set.mem_inv, set.mem_mul, exists_exists_and_eq_and, exists_and_distrib_left],
{ refine ⟨_, h2g₂, (g₁ * g₂)⁻¹, _, _⟩, simp only [inv_inv, h1g₂],
simp only [mul_inv_rev, mul_inv_cancel_left] },
{ refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, _, _⟩, simp only [inv_inv, h1g₃],
simp only [mul_inv_rev, mul_inv_cancel_left] }
end
lemma mul_left_index_le {K : set G} (hK : is_compact K) {V : set G} (hV : (interior V).nonempty)
(g : G) : index ((λ h, g * h) '' K) V ≤ index K V :=
begin
rcases index_elim hK hV with ⟨s, h1s, h2s⟩, rw [← h2s],
apply nat.Inf_le, rw [mem_image],
refine ⟨s.map (equiv.mul_right g⁻¹).to_embedding, _, finset.card_map _⟩,
{ simp only [mem_set_of_eq], refine subset.trans (image_subset _ h1s) _,
rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩,
simp only [mem_preimage] at hg₁, simp only [exists_prop, mem_Union, finset.mem_map,
equiv.coe_mul_right, exists_exists_and_eq_and, mem_preimage, equiv.to_embedding_apply],
refine ⟨_, hg₂, _⟩, simp only [mul_assoc, hg₁, inv_mul_cancel_left] }
end
lemma is_left_invariant_index {K : set G} (hK : is_compact K) (g : G) {V : set G}
(hV : (interior V).nonempty) : index ((λ h, g * h) '' K) V = index K V :=
begin
refine le_antisymm (mul_left_index_le hK hV g) _,
convert mul_left_index_le (hK.image $ continuous_mul_left g) hV g⁻¹,
rw [image_image], symmetry, convert image_id' _, ext h, apply inv_mul_cancel_left
end
/-!
### Lemmas about `prehaar`
-/
lemma prehaar_le_index (K₀ : positive_compacts G) {U : set G} (K : compacts G)
(hU : (interior U).nonempty) : prehaar K₀.1 U K ≤ index K.1 K₀.1 :=
begin
unfold prehaar, rw [div_le_iff]; norm_cast,
{ apply le_index_mul K₀ K hU },
{ exact index_pos K₀ hU }
end
lemma prehaar_pos (K₀ : positive_compacts G) {U : set G} (hU : (interior U).nonempty)
{K : set G} (h1K : is_compact K) (h2K : (interior K).nonempty) : 0 < prehaar K₀.1 U ⟨K, h1K⟩ :=
by { apply div_pos; norm_cast, apply index_pos ⟨K, h1K, h2K⟩ hU, exact index_pos K₀ hU }
lemma prehaar_mono {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty)
{K₁ K₂ : compacts G} (h : K₁.1 ⊆ K₂.1) : prehaar K₀.1 U K₁ ≤ prehaar K₀.1 U K₂ :=
begin
simp only [prehaar], rw [div_le_div_right], exact_mod_cast index_mono K₂.2 h hU,
exact_mod_cast index_pos K₀ hU
end
lemma prehaar_self {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) :
prehaar K₀.1 U ⟨K₀.1, K₀.2.1⟩ = 1 :=
by { simp only [prehaar], rw [div_self], apply ne_of_gt, exact_mod_cast index_pos K₀ hU }
lemma prehaar_sup_le {K₀ : positive_compacts G} {U : set G} (K₁ K₂ : compacts G)
(hU : (interior U).nonempty) : prehaar K₀.1 U (K₁ ⊔ K₂) ≤ prehaar K₀.1 U K₁ + prehaar K₀.1 U K₂ :=
begin
simp only [prehaar], rw [div_add_div_same, div_le_div_right],
exact_mod_cast index_union_le K₁ K₂ hU, exact_mod_cast index_pos K₀ hU
end
lemma prehaar_sup_eq {K₀ : positive_compacts G} {U : set G} {K₁ K₂ : compacts G}
(hU : (interior U).nonempty) (h : disjoint (K₁.1 * U⁻¹) (K₂.1 * U⁻¹)) :
prehaar K₀.1 U (K₁ ⊔ K₂) = prehaar K₀.1 U K₁ + prehaar K₀.1 U K₂ :=
by { simp only [prehaar], rw [div_add_div_same], congr', exact_mod_cast index_union_eq K₁ K₂ hU h }
lemma is_left_invariant_prehaar {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty)
(g : G) (K : compacts G) : prehaar K₀.1 U (K.map _ $ continuous_mul_left g) = prehaar K₀.1 U K :=
by simp only [prehaar, compacts.map_val, is_left_invariant_index K.2 _ hU]
/-!
### Lemmas about `haar_product`
-/
lemma prehaar_mem_haar_product (K₀ : positive_compacts G) {U : set G}
(hU : (interior U).nonempty) : prehaar K₀.1 U ∈ haar_product K₀.1 :=
by { rintro ⟨K, hK⟩ h2K, rw [mem_Icc], exact ⟨prehaar_nonneg K₀ _, prehaar_le_index K₀ _ hU⟩ }
lemma nonempty_Inter_cl_prehaar (K₀ : positive_compacts G) :
(haar_product K₀.1 ∩ ⋂ (V : open_nhds_of (1 : G)), cl_prehaar K₀.1 V).nonempty :=
begin
have : is_compact (haar_product K₀.1), { apply compact_univ_pi, intro K, apply compact_Icc },
refine this.inter_Inter_nonempty (cl_prehaar K₀.1) (λ s, is_closed_closure) (λ t, _),
let V₀ := ⋂ (V ∈ t), (V : open_nhds_of 1).1,
have h1V₀ : is_open V₀,
{ apply is_open_bInter, apply finite_mem_finset, rintro ⟨V, hV⟩ h2V, exact hV.1 },
have h2V₀ : (1 : G) ∈ V₀, { simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, exact hV.2 },
refine ⟨prehaar K₀.1 V₀, _⟩,
split,
{ apply prehaar_mem_haar_product K₀, use 1, rwa h1V₀.interior_eq },
{ simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, apply subset_closure,
apply mem_image_of_mem, rw [mem_set_of_eq],
exact ⟨subset.trans (Inter_subset _ ⟨V, hV⟩) (Inter_subset _ h2V), h1V₀, h2V₀⟩ },
end
/-!
### Lemmas about `chaar`
-/
/-- This is the "limit" of `prehaar K₀.1 U K` as `U` becomes a smaller and smaller open
neighborhood of `(1 : G)`. More precisely, it is defined to be an arbitrary element
in the intersection of all the sets `cl_prehaar K₀ V` in `haar_product K₀`.
This is roughly equal to the Haar measure on compact sets,
but it can differ slightly. We do know that
`haar_measure K₀ (interior K.1) ≤ chaar K₀ K ≤ haar_measure K₀ K.1`.
These inequalities are given by `measure_theory.measure.haar_outer_measure_le_echaar` and
`measure_theory.measure.echaar_le_haar_outer_measure`. -/
def chaar (K₀ : positive_compacts G) (K : compacts G) : ℝ :=
classical.some (nonempty_Inter_cl_prehaar K₀) K
lemma chaar_mem_haar_product (K₀ : positive_compacts G) : chaar K₀ ∈ haar_product K₀.1 :=
(classical.some_spec (nonempty_Inter_cl_prehaar K₀)).1
lemma chaar_mem_cl_prehaar (K₀ : positive_compacts G) (V : open_nhds_of (1 : G)) :
chaar K₀ ∈ cl_prehaar K₀.1 V :=
by { have := (classical.some_spec (nonempty_Inter_cl_prehaar K₀)).2, rw [mem_Inter] at this,
exact this V }
lemma chaar_nonneg (K₀ : positive_compacts G) (K : compacts G) : 0 ≤ chaar K₀ K :=
by { have := chaar_mem_haar_product K₀ K (mem_univ _), rw mem_Icc at this, exact this.1 }
lemma chaar_empty (K₀ : positive_compacts G) : chaar K₀ ⊥ = 0 :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f ⊥,
have : continuous eval := continuous_apply ⊥,
show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)},
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_empty },
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton },
end
lemma chaar_self (K₀ : positive_compacts G) : chaar K₀ ⟨K₀.1, K₀.2.1⟩ = 1 :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f ⟨K₀.1, K₀.2.1⟩,
have : continuous eval := continuous_apply _,
show chaar K₀ ∈ eval ⁻¹' {(1 : ℝ)},
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_self,
rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton }
end
lemma chaar_mono {K₀ : positive_compacts G} {K₁ K₂ : compacts G} (h : K₁.1 ⊆ K₂.1) :
chaar K₀ K₁ ≤ chaar K₀ K₂ :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f K₂ - f K₁,
have : continuous eval := (continuous_apply K₂).sub (continuous_apply K₁),
rw [← sub_nonneg], show chaar K₀ ∈ eval ⁻¹' (Ici (0 : ℝ)),
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg],
apply prehaar_mono _ h, rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_Ici },
end
lemma chaar_sup_le {K₀ : positive_compacts G} (K₁ K₂ : compacts G) :
chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂ :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f K₁ + f K₂ - f (K₁ ⊔ K₂),
have : continuous eval :=
((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply K₂))).sub
(continuous_apply (K₁ ⊔ K₂)),
rw [← sub_nonneg], show chaar K₀ ∈ eval ⁻¹' (Ici (0 : ℝ)),
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg],
apply prehaar_sup_le, rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_Ici },
end
lemma chaar_sup_eq [t2_space G] {K₀ : positive_compacts G} {K₁ K₂ : compacts G}
(h : disjoint K₁.1 K₂.1) : chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂ :=
begin
rcases compact_compact_separated K₁.2 K₂.2 (disjoint_iff.mp h) with
⟨U₁, U₂, h1U₁, h1U₂, h2U₁, h2U₂, hU⟩,
rw [← disjoint_iff_inter_eq_empty] at hU,
rcases compact_open_separated_mul K₁.2 h1U₁ h2U₁ with ⟨V₁, h1V₁, h2V₁, h3V₁⟩,
rcases compact_open_separated_mul K₂.2 h1U₂ h2U₂ with ⟨V₂, h1V₂, h2V₂, h3V₂⟩,
let eval : (compacts G → ℝ) → ℝ := λ f, f K₁ + f K₂ - f (K₁ ⊔ K₂),
have : continuous eval :=
((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply K₂))).sub
(continuous_apply (K₁ ⊔ K₂)),
rw [eq_comm, ← sub_eq_zero], show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)},
let V := V₁ ∩ V₂,
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀
⟨V⁻¹, (is_open_inter h1V₁ h1V₂).preimage continuous_inv,
by simp only [mem_inv, one_inv, h2V₁, h2V₂, V, mem_inter_eq, true_and]⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩,
simp only [mem_preimage, eval, sub_eq_zero, mem_singleton_iff], rw [eq_comm],
apply prehaar_sup_eq,
{ rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ refine disjoint_of_subset _ _ hU,
{ refine subset.trans (mul_subset_mul subset.rfl _) h3V₁,
exact subset.trans (inv_subset.mpr h1U) (inter_subset_left _ _) },
{ refine subset.trans (mul_subset_mul subset.rfl _) h3V₂,
exact subset.trans (inv_subset.mpr h1U) (inter_subset_right _ _) }}},
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton },
end
lemma is_left_invariant_chaar {K₀ : positive_compacts G} (g : G) (K : compacts G) :
chaar K₀ (K.map _ $ continuous_mul_left g) = chaar K₀ K :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f (K.map _ $ continuous_mul_left g) - f K,
have : continuous eval := (continuous_apply (K.map _ _)).sub (continuous_apply K),
rw [← sub_eq_zero], show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)},
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩,
simp only [mem_singleton_iff, mem_preimage, eval, sub_eq_zero],
apply is_left_invariant_prehaar, rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton },
end
/-- The function `chaar` interpreted in `ℝ≥0∞` -/
@[reducible] def echaar (K₀ : positive_compacts G) (K : compacts G) : ℝ≥0∞ :=
show nnreal, from ⟨chaar K₀ K, chaar_nonneg _ _⟩
/-! We only prove the properties for `echaar` that we use at least twice below. -/
/-- The variant of `chaar_sup_le` for `echaar` -/
lemma echaar_sup_le {K₀ : positive_compacts G} (K₁ K₂ : compacts G) :
echaar K₀ (K₁ ⊔ K₂) ≤ echaar K₀ K₁ + echaar K₀ K₂ :=
by { norm_cast, simp only [←nnreal.coe_le_coe, nnreal.coe_add, subtype.coe_mk, chaar_sup_le]}
/-- The variant of `chaar_mono` for `echaar` -/
lemma echaar_mono {K₀ : positive_compacts G} ⦃K₁ K₂ : compacts G⦄ (h : K₁.1 ⊆ K₂.1) :
echaar K₀ K₁ ≤ echaar K₀ K₂ :=
by { norm_cast, simp only [←nnreal.coe_le_coe, subtype.coe_mk, chaar_mono, h] }
/-- The variant of `chaar_self` for `echaar` -/
lemma echaar_self {K₀ : positive_compacts G} : echaar K₀ ⟨K₀.1, K₀.2.1⟩ = 1 :=
by { simp_rw [← ennreal.coe_one, echaar, ennreal.coe_eq_coe, chaar_self], refl }
/-- The variant of `is_left_invariant_chaar` for `echaar` -/
lemma is_left_invariant_echaar {K₀ : positive_compacts G} (g : G) (K : compacts G) :
echaar K₀ (K.map _ $ continuous_mul_left g) = echaar K₀ K :=
by simpa only [ennreal.coe_eq_coe, ←nnreal.coe_eq] using is_left_invariant_chaar g K
end haar
open haar
/-!
### The Haar outer measure
-/
variables [topological_space G] [t2_space G] [topological_group G]
/-- The Haar outer measure on `G`. It is not normalized, and is mainly used to construct
`haar_measure`, which is a normalized measure. -/
def haar_outer_measure (K₀ : positive_compacts G) : outer_measure G :=
outer_measure.of_content (echaar K₀) $
by { rw echaar, norm_cast, rw [←nnreal.coe_eq, nnreal.coe_zero, subtype.coe_mk, chaar_empty] }
lemma haar_outer_measure_eq_infi (K₀ : positive_compacts G) (A : set G) :
haar_outer_measure K₀ A = ⨅ (U : set G) (hU : is_open U) (h : A ⊆ U),
inner_content (echaar K₀) ⟨U, hU⟩ :=
outer_measure.of_content_eq_infi echaar_sup_le A
lemma echaar_le_haar_outer_measure {K₀ : positive_compacts G} (K : compacts G) :
echaar K₀ K ≤ haar_outer_measure K₀ K.1 :=
outer_measure.le_of_content_compacts echaar_sup_le K
lemma haar_outer_measure_of_is_open {K₀ : positive_compacts G} (U : set G) (hU : is_open U) :
haar_outer_measure K₀ U = inner_content (echaar K₀) ⟨U, hU⟩ :=
outer_measure.of_content_opens echaar_sup_le ⟨U, hU⟩
lemma haar_outer_measure_le_echaar {K₀ : positive_compacts G} {U : set G} (hU : is_open U)
(K : compacts G) (h : U ⊆ K.1) : haar_outer_measure K₀ U ≤ echaar K₀ K :=
(outer_measure.of_content_le echaar_sup_le echaar_mono ⟨U, hU⟩ K h : _)
lemma haar_outer_measure_exists_open {K₀ : positive_compacts G} {A : set G}
(hA : haar_outer_measure K₀ A < ∞) {ε : ℝ≥0} (hε : 0 < ε) :
∃ U : opens G, A ⊆ U ∧ haar_outer_measure K₀ U ≤ haar_outer_measure K₀ A + ε :=
outer_measure.of_content_exists_open echaar_sup_le hA hε
lemma haar_outer_measure_exists_compact {K₀ : positive_compacts G} {U : opens G}
(hU : haar_outer_measure K₀ U < ∞) {ε : ℝ≥0} (hε : 0 < ε) :
∃ K : compacts G, K.1 ⊆ U ∧ haar_outer_measure K₀ U ≤ haar_outer_measure K₀ K.1 + ε :=
outer_measure.of_content_exists_compact echaar_sup_le hU hε
lemma haar_outer_measure_caratheodory {K₀ : positive_compacts G} (A : set G) :
(haar_outer_measure K₀).caratheodory.measurable_set' A ↔ ∀ (U : opens G),
haar_outer_measure K₀ (U ∩ A) + haar_outer_measure K₀ (U \ A) ≤ haar_outer_measure K₀ U :=
outer_measure.of_content_caratheodory echaar_sup_le A
lemma one_le_haar_outer_measure_self {K₀ : positive_compacts G} : 1 ≤ haar_outer_measure K₀ K₀.1 :=
begin
rw [haar_outer_measure_eq_infi],
refine le_binfi _, intros U hU, refine le_infi _, intros h2U,
refine le_trans _ (le_bsupr ⟨K₀.1, K₀.2.1⟩ h2U), simp_rw [echaar_self, le_rfl]
end
lemma haar_outer_measure_pos_of_is_open {K₀ : positive_compacts G}
{U : set G} (hU : is_open U) (h2U : U.nonempty) : 0 < haar_outer_measure K₀ U :=
outer_measure.of_content_pos_of_is_mul_left_invariant echaar_sup_le is_left_invariant_echaar
⟨K₀.1, K₀.2.1⟩ (by simp only [echaar_self, ennreal.zero_lt_one]) hU h2U
lemma haar_outer_measure_self_pos {K₀ : positive_compacts G} :
0 < haar_outer_measure K₀ K₀.1 :=
(haar_outer_measure_pos_of_is_open is_open_interior K₀.2.2).trans_le
((haar_outer_measure K₀).mono interior_subset)
lemma haar_outer_measure_lt_top_of_is_compact [locally_compact_space G] {K₀ : positive_compacts G}
{K : set G} (hK : is_compact K) : haar_outer_measure K₀ K < ∞ :=
begin
rcases exists_compact_superset hK with ⟨F, h1F, h2F⟩,
refine ((haar_outer_measure K₀).mono h2F).trans_lt _,
refine (haar_outer_measure_le_echaar is_open_interior ⟨F, h1F⟩ interior_subset).trans_lt
ennreal.coe_lt_top
end
variables [S : measurable_space G] [borel_space G]
include S
lemma haar_caratheodory_measurable (K₀ : positive_compacts G) :
S ≤ (haar_outer_measure K₀).caratheodory :=
begin
rw [@borel_space.measurable_eq G _ _], refine generate_from_le _,
intros U hU, rw haar_outer_measure_caratheodory, intro U',
rw haar_outer_measure_of_is_open ((U' : set G) ∩ U) (is_open_inter U'.prop hU),
simp only [inner_content, supr_subtype'], rw [opens.coe_mk],
haveI : nonempty {L : compacts G // L.1 ⊆ U' ∩ U} := ⟨⟨⊥, empty_subset _⟩⟩,
rw [ennreal.supr_add],
refine supr_le _, rintro ⟨L, hL⟩, simp only [subset_inter_iff] at hL,
have : ↑U' \ U ⊆ U' \ L.1 := diff_subset_diff_right hL.2,
refine le_trans (add_le_add_left ((haar_outer_measure K₀).mono' this) _) _,
rw haar_outer_measure_of_is_open (↑U' \ L.1) (is_open_diff U'.2 L.2.is_closed),
simp only [inner_content, supr_subtype'], rw [opens.coe_mk],
haveI : nonempty {M : compacts G // M.1 ⊆ ↑U' \ L.1} := ⟨⟨⊥, empty_subset _⟩⟩,
rw [ennreal.add_supr], refine supr_le _, rintro ⟨M, hM⟩, simp only [subset_diff] at hM,
have : (L ⊔ M).1 ⊆ U',
{ simp only [union_subset_iff, compacts.sup_val, hM, hL, and_self] },
rw haar_outer_measure_of_is_open ↑U' U'.2,
refine le_trans (ge_of_eq _) (le_inner_content _ _ this), norm_cast,
simp only [←nnreal.coe_eq, nnreal.coe_add, subtype.coe_mk], exact chaar_sup_eq hM.2.symm
end
/-!
### The Haar measure
-/
/-- the Haar measure on `G`, scaled so that `haar_measure K₀ K₀ = 1`. -/
def haar_measure (K₀ : positive_compacts G) : measure G :=
(haar_outer_measure K₀ K₀.1)⁻¹ •
(haar_outer_measure K₀).to_measure (haar_caratheodory_measurable K₀)
lemma haar_measure_apply {K₀ : positive_compacts G} {s : set G} (hs : measurable_set s) :
haar_measure K₀ s = haar_outer_measure K₀ s / haar_outer_measure K₀ K₀.1 :=
by { simp only [haar_measure, hs, div_eq_mul_inv, mul_comm, to_measure_apply,
algebra.id.smul_eq_mul, pi.smul_apply, measure.coe_smul] }
lemma is_mul_left_invariant_haar_measure (K₀ : positive_compacts G) :
is_mul_left_invariant (haar_measure K₀) :=
begin
intros g A hA,
rw [haar_measure_apply hA, haar_measure_apply (measurable_const_mul g hA)],
congr' 1,
exact outer_measure.is_mul_left_invariant_of_content echaar_sup_le is_left_invariant_echaar g A
end
lemma haar_measure_self [locally_compact_space G] {K₀ : positive_compacts G} :
haar_measure K₀ K₀.1 = 1 :=
begin
rw [haar_measure_apply K₀.2.1.measurable_set, ennreal.div_self],
{ rw [← pos_iff_ne_zero], exact haar_outer_measure_self_pos },
{ exact ne_of_lt (haar_outer_measure_lt_top_of_is_compact K₀.2.1) }
end
lemma haar_measure_pos_of_is_open [locally_compact_space G] {K₀ : positive_compacts G}
{U : set G} (hU : is_open U) (h2U : U.nonempty) : 0 < haar_measure K₀ U :=
begin
rw [haar_measure_apply hU.measurable_set, ennreal.div_pos_iff],
refine ⟨_, ne_of_lt $ haar_outer_measure_lt_top_of_is_compact K₀.2.1⟩,
rw [← pos_iff_ne_zero], apply haar_outer_measure_pos_of_is_open hU h2U
end
lemma regular_haar_measure [locally_compact_space G] {K₀ : positive_compacts G} :
(haar_measure K₀).regular :=
begin
apply measure.regular.smul, split,
{ intros K hK, rw [to_measure_apply _ _ hK.measurable_set],
apply haar_outer_measure_lt_top_of_is_compact hK },
{ intros A hA, rw [to_measure_apply _ _ hA, haar_outer_measure_eq_infi],
refine binfi_le_binfi _, intros U hU, refine infi_le_infi _, intro h2U,
rw [to_measure_apply _ _ hU.measurable_set, haar_outer_measure_of_is_open U hU], refl' },
{ intros U hU, rw [to_measure_apply _ _ hU.measurable_set, haar_outer_measure_of_is_open U hU],
dsimp only [inner_content], refine bsupr_le (λ K hK, _),
refine le_supr_of_le K.1 _, refine le_supr_of_le K.2 _, refine le_supr_of_le hK _,
rw [to_measure_apply _ _ K.2.measurable_set], apply echaar_le_haar_outer_measure },
{ rw ennreal.inv_lt_top, apply haar_outer_measure_self_pos }
end
instance [locally_compact_space G] [separable_space G] (K₀ : positive_compacts G) :
sigma_finite (haar_measure K₀) :=
regular_haar_measure.sigma_finite
section unique
variables [locally_compact_space G] [second_countable_topology G] {μ : measure G} [sigma_finite μ]
/-- The Haar measure is unique up to scaling. More precisely: every σ-finite left invariant measure
is a scalar multiple of the Haar measure. -/
theorem haar_measure_unique (hμ : is_mul_left_invariant μ)
(K₀ : positive_compacts G) : μ = μ K₀.1 • haar_measure K₀ :=
begin
ext1 s hs,
have := measure_mul_measure_eq hμ (is_mul_left_invariant_haar_measure K₀)
regular_haar_measure K₀.2.1 hs,
rw [haar_measure_self, one_mul] at this,
rw [← this (by norm_num), smul_apply],
end
theorem regular_of_left_invariant (hμ : is_mul_left_invariant μ) {K} (hK : is_compact K)
(h2K : (interior K).nonempty) (hμK : μ K < ∞) : regular μ :=
begin
rw [haar_measure_unique hμ ⟨K, hK, h2K⟩],
exact regular.smul regular_haar_measure hμK
end
end unique
end measure
end measure_theory
|
a5f26b5fc898180fc2921d0385081966ef038dea | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/set_theory/cardinal.lean | 2f1c8456e447fa9bb3636f2e87719625562f2512 | [
"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 | 46,761 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl, Mario Carneiro
-/
import data.set.countable
import set_theory.schroeder_bernstein
import data.fintype.card
/-!
# Cardinal Numbers
We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity.
We define the order on cardinal numbers, define omega, and do basic cardinal arithmetic:
addition, multiplication, power, cardinal successor, minimum, supremum,
infinitary sums and products
The fact that the cardinality of `α × α` coincides with that of `α` when `α` is infinite is not
proved in this file, as it relies on facts on well-orders. Instead, it is in
`cardinal_ordinal.lean` (together with many other facts on cardinals, for instance the
cardinality of `list α`).
## Implementation notes
* There is a type of cardinal numbers in every universe level: `cardinal.{u} : Type (u + 1)`
is the quotient of types in `Type u`.
There is a lift operation lifting cardinal numbers to a higher level.
* Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file
`set_theory/ordinal.lean`, because concepts from that file are used in the proof.
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, omega
-/
open function set
open_locale classical
universes u v w x
variables {α β : Type u}
/-- The equivalence relation on types given by equivalence (bijective correspondence) of types.
Quotienting by this equivalence relation gives the cardinal numbers.
-/
instance cardinal.is_equivalent : setoid (Type u) :=
{ r := λα β, nonempty (α ≃ β),
iseqv := ⟨λα,
⟨equiv.refl α⟩,
λα β ⟨e⟩, ⟨e.symm⟩,
λα β γ ⟨e₁⟩ ⟨e₂⟩, ⟨e₁.trans e₂⟩⟩ }
/-- `cardinal.{u}` is the type of cardinal numbers in `Type u`,
defined as the quotient of `Type u` by existence of an equivalence
(a bijection with explicit inverse). -/
def cardinal : Type (u + 1) := quotient cardinal.is_equivalent
namespace cardinal
/-- The cardinal number of a type -/
def mk : Type u → cardinal := quotient.mk
localized "notation `#` := cardinal.mk" in cardinal
protected lemma eq : mk α = mk β ↔ nonempty (α ≃ β) := quotient.eq
@[simp] theorem mk_def (α : Type u) : @eq cardinal ⟦α⟧ (mk α) := rfl
@[simp] theorem mk_out (c : cardinal) : mk (c.out) = c := quotient.out_eq _
/-- We define the order on cardinal numbers by `mk α ≤ mk β` if and only if
there exists an embedding (injective function) from α to β. -/
instance : has_le cardinal.{u} :=
⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, nonempty $ α ↪ β) $
assume α β γ δ ⟨e₁⟩ ⟨e₂⟩,
propext ⟨assume ⟨e⟩, ⟨e.congr e₁ e₂⟩, assume ⟨e⟩, ⟨e.congr e₁.symm e₂.symm⟩⟩⟩
theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : injective f) : mk α ≤ mk β :=
⟨⟨f, hf⟩⟩
theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : surjective f) : mk β ≤ mk α :=
⟨embedding.of_surjective f hf⟩
theorem le_mk_iff_exists_set {c : cardinal} {α : Type u} :
c ≤ mk α ↔ ∃ p : set α, mk p = c :=
⟨quotient.induction_on c $ λ β ⟨⟨f, hf⟩⟩,
⟨set.range f, eq.symm $ quot.sound ⟨equiv.set.range f hf⟩⟩,
λ ⟨p, e⟩, e ▸ ⟨⟨subtype.val, λ a b, subtype.eq⟩⟩⟩
theorem out_embedding {c c' : cardinal} : c ≤ c' ↔ nonempty (c.out ↪ c'.out) :=
by { transitivity _, rw [←quotient.out_eq c, ←quotient.out_eq c'], refl }
noncomputable instance : linear_order cardinal.{u} :=
{ le := (≤),
le_refl := by rintros ⟨α⟩; exact ⟨embedding.refl _⟩,
le_trans := by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.trans e₂⟩,
le_antisymm := by rintros ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩; exact quotient.sound (e₁.antisymm e₂),
le_total := by rintros ⟨α⟩ ⟨β⟩; exact embedding.total,
decidable_le := classical.dec_rel _ }
noncomputable instance : distrib_lattice cardinal.{u} := by apply_instance -- short-circuit type class inference
instance : has_zero cardinal.{u} := ⟨⟦pempty⟧⟩
instance : inhabited cardinal.{u} := ⟨0⟩
theorem ne_zero_iff_nonempty {α : Type u} : mk α ≠ 0 ↔ nonempty α :=
not_iff_comm.1
⟨λ h, quotient.sound ⟨(equiv.empty_of_not_nonempty h).trans equiv.empty_equiv_pempty⟩,
λ e, let ⟨h⟩ := quotient.exact e in λ ⟨a⟩, (h a).elim⟩
instance : has_one cardinal.{u} := ⟨⟦punit⟧⟩
instance : nontrivial cardinal.{u} :=
⟨⟨1, 0, ne_zero_iff_nonempty.2 ⟨punit.star⟩⟩⟩
theorem le_one_iff_subsingleton {α : Type u} : mk α ≤ 1 ↔ subsingleton α :=
⟨λ ⟨f⟩, ⟨λ a b, f.injective (subsingleton.elim _ _)⟩,
λ ⟨h⟩, ⟨⟨λ a, punit.star, λ a b _, h _ _⟩⟩⟩
theorem one_lt_iff_nontrivial {α : Type u} : 1 < mk α ↔ nontrivial α :=
by { rw [← not_iff_not, not_nontrivial_iff_subsingleton, ← le_one_iff_subsingleton], simp }
instance : has_add cardinal.{u} :=
⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, mk (α ⊕ β)) $ assume α β γ δ ⟨e₁⟩ ⟨e₂⟩,
quotient.sound ⟨equiv.sum_congr e₁ e₂⟩⟩
@[simp] theorem add_def (α β) : mk α + mk β = mk (α ⊕ β) := rfl
instance : has_mul cardinal.{u} :=
⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, mk (α × β)) $ assume α β γ δ ⟨e₁⟩ ⟨e₂⟩,
quotient.sound ⟨equiv.prod_congr e₁ e₂⟩⟩
@[simp] theorem mul_def (α β : Type u) : mk α * mk β = mk (α × β) := rfl
private theorem add_comm (a b : cardinal.{u}) : a + b = b + a :=
quotient.induction_on₂ a b $ assume α β, quotient.sound ⟨equiv.sum_comm α β⟩
private theorem mul_comm (a b : cardinal.{u}) : a * b = b * a :=
quotient.induction_on₂ a b $ assume α β, quotient.sound ⟨equiv.prod_comm α β⟩
private theorem zero_add (a : cardinal.{u}) : 0 + a = a :=
quotient.induction_on a $ assume α, quotient.sound ⟨equiv.pempty_sum α⟩
private theorem zero_mul (a : cardinal.{u}) : 0 * a = 0 :=
quotient.induction_on a $ assume α, quotient.sound ⟨equiv.pempty_prod α⟩
private theorem one_mul (a : cardinal.{u}) : 1 * a = a :=
quotient.induction_on a $ assume α, quotient.sound ⟨equiv.punit_prod α⟩
private theorem left_distrib (a b c : cardinal.{u}) : a * (b + c) = a * b + a * c :=
quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.prod_sum_distrib α β γ⟩
instance : comm_semiring cardinal.{u} :=
{ zero := 0,
one := 1,
add := (+),
mul := (*),
zero_add := zero_add,
add_zero := assume a, by rw [add_comm a 0, zero_add a],
add_assoc := λa b c, quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.sum_assoc α β γ⟩,
add_comm := add_comm,
zero_mul := zero_mul,
mul_zero := assume a, by rw [mul_comm a 0, zero_mul a],
one_mul := one_mul,
mul_one := assume a, by rw [mul_comm a 1, one_mul a],
mul_assoc := λa b c, quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.prod_assoc α β γ⟩,
mul_comm := mul_comm,
left_distrib := left_distrib,
right_distrib := assume a b c,
by rw [mul_comm (a + b) c, left_distrib c a b, mul_comm c a, mul_comm c b] }
/-- The cardinal exponential. `mk α ^ mk β` is the cardinal of `β → α`. -/
protected def power (a b : cardinal.{u}) : cardinal.{u} :=
quotient.lift_on₂ a b (λα β, mk (β → α)) $ assume α₁ α₂ β₁ β₂ ⟨e₁⟩ ⟨e₂⟩,
quotient.sound ⟨equiv.arrow_congr e₂ e₁⟩
instance : has_pow cardinal cardinal := ⟨cardinal.power⟩
local infixr ^ := @has_pow.pow cardinal cardinal cardinal.has_pow
@[simp] theorem power_def (α β) : mk α ^ mk β = mk (β → α) := rfl
@[simp] theorem power_zero {a : cardinal} : a ^ 0 = 1 :=
quotient.induction_on a $ assume α, quotient.sound
⟨equiv.pempty_arrow_equiv_punit α⟩
@[simp] theorem power_one {a : cardinal} : a ^ 1 = a :=
quotient.induction_on a $ assume α, quotient.sound
⟨equiv.punit_arrow_equiv α⟩
@[simp] theorem one_power {a : cardinal} : 1 ^ a = 1 :=
quotient.induction_on a $ assume α, quotient.sound
⟨equiv.arrow_punit_equiv_punit α⟩
@[simp] theorem prop_eq_two : mk (ulift Prop) = 2 :=
quot.sound ⟨equiv.ulift.trans $ equiv.Prop_equiv_bool.trans equiv.bool_equiv_punit_sum_punit⟩
@[simp] theorem zero_power {a : cardinal} : a ≠ 0 → 0 ^ a = 0 :=
quotient.induction_on a $ assume α heq,
nonempty.rec_on (ne_zero_iff_nonempty.1 heq) $ assume a,
quotient.sound ⟨equiv.equiv_pempty $ assume f, pempty.rec (λ _, false) (f a)⟩
theorem power_ne_zero {a : cardinal} (b) : a ≠ 0 → a ^ b ≠ 0 :=
quotient.induction_on₂ a b $ λ α β h,
let ⟨a⟩ := ne_zero_iff_nonempty.1 h in
ne_zero_iff_nonempty.2 ⟨λ _, a⟩
theorem mul_power {a b c : cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.arrow_prod_equiv_prod_arrow α β γ⟩
theorem power_add {a b c : cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.sum_arrow_equiv_prod_arrow β γ α⟩
theorem power_mul {a b c : cardinal} : (a ^ b) ^ c = a ^ (b * c) :=
by rw [_root_.mul_comm b c];
from (quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.arrow_arrow_equiv_prod_arrow γ β α⟩)
@[simp] lemma pow_cast_right (κ : cardinal.{u}) :
∀ n : ℕ, (κ ^ (↑n : cardinal.{u})) = @has_pow.pow _ _ monoid.has_pow κ n
| 0 := by simp
| (_+1) := by rw [nat.cast_succ, power_add, power_one, _root_.mul_comm, pow_succ, pow_cast_right]
section order_properties
open sum
theorem zero_le : ∀(a : cardinal), 0 ≤ a :=
by rintro ⟨α⟩; exact ⟨embedding.of_not_nonempty $ λ ⟨a⟩, a.elim⟩
theorem le_zero (a : cardinal) : a ≤ 0 ↔ a = 0 :=
by simp [le_antisymm_iff, zero_le]
theorem pos_iff_ne_zero {o : cardinal} : 0 < o ↔ o ≠ 0 :=
by simp [lt_iff_le_and_ne, eq_comm, zero_le]
@[simp] theorem zero_lt_one : (0 : cardinal) < 1 :=
lt_of_le_of_ne (zero_le _) zero_ne_one
lemma zero_power_le (c : cardinal.{u}) : (0 : cardinal.{u}) ^ c ≤ 1 :=
by { by_cases h : c = 0, rw [h, power_zero], rw [zero_power h], apply zero_le }
theorem add_le_add : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sum_map e₂⟩
theorem add_le_add_left (a) {b c : cardinal} : b ≤ c → a + b ≤ a + c :=
add_le_add (le_refl _)
theorem add_le_add_right {a b : cardinal} (c) (h : a ≤ b) : a + c ≤ b + c :=
add_le_add h (le_refl _)
theorem le_add_right (a b : cardinal) : a ≤ a + b :=
by simpa using add_le_add_left a (zero_le b)
theorem le_add_left (a b : cardinal) : a ≤ b + a :=
by simpa using add_le_add_right a (zero_le b)
theorem mul_le_mul : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a * c ≤ b * d :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.prod_map e₂⟩
theorem mul_le_mul_left (a) {b c : cardinal} : b ≤ c → a * b ≤ a * c :=
mul_le_mul (le_refl _)
theorem mul_le_mul_right {a b : cardinal} (c) (h : a ≤ b) : a * c ≤ b * c :=
mul_le_mul h (le_refl _)
theorem power_le_power_left : ∀{a b c : cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩; exact
let ⟨a⟩ := ne_zero_iff_nonempty.1 hα in
⟨@embedding.arrow_congr_right _ _ _ ⟨a⟩ e⟩
theorem power_le_max_power_one {a b c : cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 :=
begin
by_cases ha : a = 0,
simp [ha, zero_power_le],
exact le_trans (power_le_power_left ha h) (le_max_left _ _)
end
theorem power_le_power_right {a b c : cardinal} : a ≤ b → a ^ c ≤ b ^ c :=
quotient.induction_on₃ a b c $ assume α β γ ⟨e⟩, ⟨embedding.arrow_congr_left e⟩
theorem le_iff_exists_add {a b : cardinal} : a ≤ b ↔ ∃ c, b = a + c :=
⟨quotient.induction_on₂ a b $ λ α β ⟨⟨f, hf⟩⟩,
have (α ⊕ ((range f)ᶜ : set β)) ≃ β, from
(equiv.sum_congr (equiv.set.range f hf) (equiv.refl _)).trans $
(equiv.set.sum_compl (range f)),
⟨⟦↥(range f)ᶜ⟧, quotient.sound ⟨this.symm⟩⟩,
λ ⟨c, e⟩, add_zero a ▸ e.symm ▸ add_le_add_left _ (zero_le _)⟩
end order_properties
instance : order_bot cardinal.{u} :=
{ bot := 0, bot_le := zero_le, ..cardinal.linear_order }
instance : canonically_ordered_add_monoid cardinal.{u} :=
{ add_le_add_left := λ a b h c, add_le_add_left _ h,
lt_of_add_lt_add_left := λ a b c, lt_imp_lt_of_le_imp_le (add_le_add_left _),
le_iff_exists_add := @le_iff_exists_add,
..cardinal.order_bot,
..cardinal.comm_semiring, ..cardinal.linear_order }
theorem cantor : ∀(a : cardinal.{u}), a < 2 ^ a :=
by rw ← prop_eq_two; rintros ⟨a⟩; exact ⟨
⟨⟨λ a b, ⟨a = b⟩, λ a b h, cast (ulift.up.inj (@congr_fun _ _ _ _ h b)).symm rfl⟩⟩,
λ ⟨⟨f, hf⟩⟩, cantor_injective (λ s, f (λ a, ⟨s a⟩)) $
λ s t h, by funext a; injection congr_fun (hf h) a⟩
instance : no_top_order cardinal.{u} :=
{ no_top := λ a, ⟨_, cantor a⟩, ..cardinal.linear_order }
/-- The minimum cardinal in a family of cardinals (the existence
of which is provided by `injective_min`). -/
noncomputable def min {ι} (I : nonempty ι) (f : ι → cardinal) : cardinal :=
f $ classical.some $
@embedding.min_injective _ (λ i, (f i).out) I
theorem min_eq {ι} (I) (f : ι → cardinal) : ∃ i, min I f = f i :=
⟨_, rfl⟩
theorem min_le {ι I} (f : ι → cardinal) (i) : min I f ≤ f i :=
by rw [← mk_out (min I f), ← mk_out (f i)]; exact
let ⟨g⟩ := classical.some_spec
(@embedding.min_injective _ (λ i, (f i).out) I) in
⟨g i⟩
theorem le_min {ι I} {f : ι → cardinal} {a} : a ≤ min I f ↔ ∀ i, a ≤ f i :=
⟨λ h i, le_trans h (min_le _ _),
λ h, let ⟨i, e⟩ := min_eq I f in e.symm ▸ h i⟩
protected theorem wf : @well_founded cardinal.{u} (<) :=
⟨λ a, classical.by_contradiction $ λ h,
let ι := {c :cardinal // ¬ acc (<) c},
f : ι → cardinal := subtype.val,
⟨⟨c, hc⟩, hi⟩ := @min_eq ι ⟨⟨_, h⟩⟩ f in
hc (acc.intro _ (λ j ⟨_, h'⟩,
classical.by_contradiction $ λ hj, h' $
by have := min_le f ⟨j, hj⟩; rwa hi at this))⟩
instance has_wf : @has_well_founded cardinal.{u} := ⟨(<), cardinal.wf⟩
instance wo : @is_well_order cardinal.{u} (<) := ⟨cardinal.wf⟩
/-- The successor cardinal - the smallest cardinal greater than
`c`. This is not the same as `c + 1` except in the case of finite `c`. -/
noncomputable def succ (c : cardinal) : cardinal :=
@min {c' // c < c'} ⟨⟨_, cantor _⟩⟩ subtype.val
theorem lt_succ_self (c : cardinal) : c < succ c :=
by cases min_eq _ _ with s e; rw [succ, e]; exact s.2
theorem succ_le {a b : cardinal} : succ a ≤ b ↔ a < b :=
⟨lt_of_lt_of_le (lt_succ_self _), λ h,
by exact min_le _ (subtype.mk b h)⟩
theorem lt_succ {a b : cardinal} : a < succ b ↔ a ≤ b :=
by rw [← not_le, succ_le, not_lt]
theorem add_one_le_succ (c : cardinal) : c + 1 ≤ succ c :=
begin
refine quot.induction_on c (λ α, _) (lt_succ_self c),
refine quot.induction_on (succ (quot.mk setoid.r α)) (λ β h, _),
cases h.left with f,
have : ¬ surjective f := λ hn,
ne_of_lt h (quotient.sound ⟨equiv.of_bijective f ⟨f.injective, hn⟩⟩),
cases not_forall.1 this with b nex,
refine ⟨⟨sum.rec (by exact f) _, _⟩⟩,
{ exact λ _, b },
{ intros a b h, rcases a with a|⟨⟨⟨⟩⟩⟩; rcases b with b|⟨⟨⟨⟩⟩⟩,
{ rw f.injective h },
{ exact nex.elim ⟨_, h⟩ },
{ exact nex.elim ⟨_, h.symm⟩ },
{ refl } }
end
lemma succ_ne_zero (c : cardinal) : succ c ≠ 0 :=
by { rw [←pos_iff_ne_zero, lt_succ], apply zero_le }
/-- The indexed sum of cardinals is the cardinality of the
indexed disjoint union, i.e. sigma type. -/
def sum {ι} (f : ι → cardinal) : cardinal := mk Σ i, (f i).out
theorem le_sum {ι} (f : ι → cardinal) (i) : f i ≤ sum f :=
by rw ← quotient.out_eq (f i); exact
⟨⟨λ a, ⟨i, a⟩, λ a b h, eq_of_heq $ by injection h⟩⟩
@[simp] theorem sum_mk {ι} (f : ι → Type*) : sum (λ i, mk (f i)) = mk (Σ i, f i) :=
quot.sound ⟨equiv.sigma_congr_right $ λ i,
classical.choice $ quotient.exact $ quot.out_eq $ mk (f i)⟩
theorem sum_const (ι : Type u) (a : cardinal.{u}) : sum (λ _:ι, a) = mk ι * a :=
quotient.induction_on a $ λ α, by simp; exact
quotient.sound ⟨equiv.sigma_equiv_prod _ _⟩
theorem sum_le_sum {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g :=
⟨(embedding.refl _).sigma_map $ λ i, classical.choice $
by have := H i; rwa [← quot.out_eq (f i), ← quot.out_eq (g i)] at this⟩
/-- The indexed supremum of cardinals is the smallest cardinal above
everything in the family. -/
noncomputable def sup {ι} (f : ι → cardinal) : cardinal :=
@min {c // ∀ i, f i ≤ c} ⟨⟨sum f, le_sum f⟩⟩ (λ a, a.1)
theorem le_sup {ι} (f : ι → cardinal) (i) : f i ≤ sup f :=
by dsimp [sup]; cases min_eq _ _ with c hc; rw hc; exact c.2 i
theorem sup_le {ι} {f : ι → cardinal} {a} : sup f ≤ a ↔ ∀ i, f i ≤ a :=
⟨λ h i, le_trans (le_sup _ _) h,
λ h, by dsimp [sup]; change a with (⟨a, h⟩:subtype _).1; apply min_le⟩
theorem sup_le_sup {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sup f ≤ sup g :=
sup_le.2 $ λ i, le_trans (H i) (le_sup _ _)
theorem sup_le_sum {ι} (f : ι → cardinal) : sup f ≤ sum f :=
sup_le.2 $ le_sum _
theorem sum_le_sup {ι : Type u} (f : ι → cardinal.{u}) : sum f ≤ mk ι * sup.{u u} f :=
by rw ← sum_const; exact sum_le_sum _ _ (le_sup _)
theorem sup_eq_zero {ι} {f : ι → cardinal} (h : ι → false) : sup f = 0 :=
by { rw [←le_zero, sup_le], intro x, exfalso, exact h x }
/-- The indexed product of cardinals is the cardinality of the Pi type
(dependent product). -/
def prod {ι : Type u} (f : ι → cardinal) : cardinal := mk (Π i, (f i).out)
@[simp] theorem prod_mk {ι} (f : ι → Type*) : prod (λ i, mk (f i)) = mk (Π i, f i) :=
quot.sound ⟨equiv.Pi_congr_right $ λ i,
classical.choice $ quotient.exact $ mk_out $ mk (f i)⟩
theorem prod_const (ι : Type u) (a : cardinal.{u}) : prod (λ _:ι, a) = a ^ mk ι :=
quotient.induction_on a $ by simp
theorem prod_le_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g :=
⟨embedding.Pi_congr_right $ λ i, classical.choice $
by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩
theorem prod_ne_zero {ι} (f : ι → cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 :=
begin
suffices : nonempty (Π i, (f i).out) ↔ ∀ i, nonempty (f i).out,
by simpa [← ne_zero_iff_nonempty, prod],
exact classical.nonempty_pi
end
theorem prod_eq_zero {ι} (f : ι → cardinal) : prod f = 0 ↔ ∃ i, f i = 0 :=
not_iff_not.1 $ by simpa using prod_ne_zero f
/-- The universe lift operation on cardinals. You can specify the universes explicitly with
`lift.{u v} : cardinal.{u} → cardinal.{max u v}` -/
def lift (c : cardinal.{u}) : cardinal.{max u v} :=
quotient.lift_on c (λ α, ⟦ulift α⟧) $ λ α β ⟨e⟩,
quotient.sound ⟨equiv.ulift.trans $ e.trans equiv.ulift.symm⟩
theorem lift_mk (α) : lift.{u v} (mk α) = mk (ulift.{v u} α) := rfl
theorem lift_umax : lift.{u (max u v)} = lift.{u v} :=
funext $ λ a, quot.induction_on a $ λ α,
quotient.sound ⟨equiv.ulift.trans equiv.ulift.symm⟩
theorem lift_id' (a : cardinal) : lift a = a :=
quot.induction_on a $ λ α, quot.sound ⟨equiv.ulift⟩
@[simp] theorem lift_id : ∀ a, lift.{u u} a = a := lift_id'.{u u}
@[simp] theorem lift_lift (a : cardinal) : lift.{(max u v) w} (lift.{u v} a) = lift.{u (max v w)} a :=
quot.induction_on a $ λ α,
quotient.sound ⟨equiv.ulift.trans $ equiv.ulift.trans equiv.ulift.symm⟩
theorem lift_mk_le {α : Type u} {β : Type v} :
lift.{u (max v w)} (mk α) ≤ lift.{v (max u w)} (mk β) ↔ nonempty (α ↪ β) :=
⟨λ ⟨f⟩, ⟨embedding.congr equiv.ulift equiv.ulift f⟩,
λ ⟨f⟩, ⟨embedding.congr equiv.ulift.symm equiv.ulift.symm f⟩⟩
theorem lift_mk_eq {α : Type u} {β : Type v} :
lift.{u (max v w)} (mk α) = lift.{v (max u w)} (mk β) ↔ nonempty (α ≃ β) :=
quotient.eq.trans
⟨λ ⟨f⟩, ⟨equiv.ulift.symm.trans $ f.trans equiv.ulift⟩,
λ ⟨f⟩, ⟨equiv.ulift.trans $ f.trans equiv.ulift.symm⟩⟩
@[simp] theorem lift_le {a b : cardinal} : lift a ≤ lift b ↔ a ≤ b :=
quotient.induction_on₂ a b $ λ α β,
by rw ← lift_umax; exact lift_mk_le
@[simp] theorem lift_inj {a b : cardinal} : lift a = lift b ↔ a = b :=
by simp [le_antisymm_iff]
@[simp] theorem lift_lt {a b : cardinal} : lift a < lift b ↔ a < b :=
by simp [lt_iff_le_not_le, -not_le]
@[simp] theorem lift_zero : lift 0 = 0 :=
quotient.sound ⟨equiv.ulift.trans equiv.pempty_equiv_pempty⟩
@[simp] theorem lift_one : lift 1 = 1 :=
quotient.sound ⟨equiv.ulift.trans equiv.punit_equiv_punit⟩
@[simp] theorem lift_add (a b) : lift (a + b) = lift a + lift b :=
quotient.induction_on₂ a b $ λ α β,
quotient.sound ⟨equiv.ulift.trans (equiv.sum_congr equiv.ulift equiv.ulift).symm⟩
@[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b :=
quotient.induction_on₂ a b $ λ α β,
quotient.sound ⟨equiv.ulift.trans (equiv.prod_congr equiv.ulift equiv.ulift).symm⟩
@[simp] theorem lift_power (a b) : lift (a ^ b) = lift a ^ lift b :=
quotient.induction_on₂ a b $ λ α β,
quotient.sound ⟨equiv.ulift.trans (equiv.arrow_congr equiv.ulift equiv.ulift).symm⟩
@[simp] theorem lift_two_power (a) : lift (2 ^ a) = 2 ^ lift a :=
by simp [bit0]
@[simp] theorem lift_min {ι I} (f : ι → cardinal) : lift (min I f) = min I (lift ∘ f) :=
le_antisymm (le_min.2 $ λ a, lift_le.2 $ min_le _ a) $
let ⟨i, e⟩ := min_eq I (lift ∘ f) in
by rw e; exact lift_le.2 (le_min.2 $ λ j, lift_le.1 $
by have := min_le (lift ∘ f) j; rwa e at this)
theorem lift_down {a : cardinal.{u}} {b : cardinal.{max u v}} :
b ≤ lift a → ∃ a', lift a' = b :=
quotient.induction_on₂ a b $ λ α β,
by dsimp; rw [← lift_id (mk β), ← lift_umax, ← lift_umax.{u v}, lift_mk_le]; exact
λ ⟨f⟩, ⟨mk (set.range f), eq.symm $ lift_mk_eq.2
⟨embedding.equiv_of_surjective
(embedding.cod_restrict _ f set.mem_range_self)
$ λ ⟨a, ⟨b, e⟩⟩, ⟨b, subtype.eq e⟩⟩⟩
theorem le_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :
b ≤ lift a ↔ ∃ a', lift a' = b ∧ a' ≤ a :=
⟨λ h, let ⟨a', e⟩ := lift_down h in ⟨a', e, lift_le.1 $ e.symm ▸ h⟩,
λ ⟨a', e, h⟩, e ▸ lift_le.2 h⟩
theorem lt_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :
b < lift a ↔ ∃ a', lift a' = b ∧ a' < a :=
⟨λ h, let ⟨a', e⟩ := lift_down (le_of_lt h) in
⟨a', e, lift_lt.1 $ e.symm ▸ h⟩,
λ ⟨a', e, h⟩, e ▸ lift_lt.2 h⟩
@[simp] theorem lift_succ (a) : lift (succ a) = succ (lift a) :=
le_antisymm
(le_of_not_gt $ λ h, begin
rcases lt_lift_iff.1 h with ⟨b, e, h⟩,
rw [lt_succ, ← lift_le, e] at h,
exact not_lt_of_le h (lt_succ_self _)
end)
(succ_le.2 $ lift_lt.2 $ lt_succ_self _)
@[simp] theorem lift_max {a : cardinal.{u}} {b : cardinal.{v}} :
lift.{u (max v w)} a = lift.{v (max u w)} b ↔ lift.{u v} a = lift.{v u} b :=
calc lift.{u (max v w)} a = lift.{v (max u w)} b
↔ lift.{(max u v) w} (lift.{u v} a)
= lift.{(max u v) w} (lift.{v u} b) : by simp
... ↔ lift.{u v} a = lift.{v u} b : lift_inj
theorem mk_prod {α : Type u} {β : Type v} :
mk (α × β) = lift.{u v} (mk α) * lift.{v u} (mk β) :=
quotient.sound ⟨equiv.prod_congr (equiv.ulift).symm (equiv.ulift).symm⟩
theorem sum_const_eq_lift_mul (ι : Type u) (a : cardinal.{v}) :
sum (λ _:ι, a) = lift.{u v} (mk ι) * lift.{v u} a :=
begin
apply quotient.induction_on a,
intro α,
simp only [cardinal.mk_def, cardinal.sum_mk, cardinal.lift_id],
convert mk_prod using 1,
exact quotient.sound ⟨equiv.sigma_equiv_prod ι α⟩,
end
/-- `ω` is the smallest infinite cardinal, also known as ℵ₀. -/
def omega : cardinal.{u} := lift (mk ℕ)
lemma mk_nat : mk nat = omega := (lift_id _).symm
theorem omega_ne_zero : omega ≠ 0 :=
ne_zero_iff_nonempty.2 ⟨⟨0⟩⟩
theorem omega_pos : 0 < omega :=
pos_iff_ne_zero.2 omega_ne_zero
@[simp] theorem lift_omega : lift omega = omega := lift_lift _
/- properties about the cast from nat -/
@[simp] theorem mk_fin : ∀ (n : ℕ), mk (fin n) = n
| 0 := quotient.sound ⟨(equiv.pempty_of_not_nonempty $ λ ⟨h⟩, h.elim0)⟩
| (n+1) := by rw [nat.cast_succ, ← mk_fin]; exact
quotient.sound (fintype.card_eq.1 $ by simp)
@[simp] theorem lift_nat_cast (n : ℕ) : lift n = n :=
by induction n; simp *
lemma lift_eq_nat_iff {a : cardinal.{u}} {n : ℕ} : lift.{u v} a = n ↔ a = n :=
by rw [← lift_nat_cast.{u v} n, lift_inj]
lemma nat_eq_lift_eq_iff {n : ℕ} {a : cardinal.{u}} :
(n : cardinal) = lift.{u v} a ↔ (n : cardinal) = a :=
by rw [← lift_nat_cast.{u v} n, lift_inj]
theorem lift_mk_fin (n : ℕ) : lift (mk (fin n)) = n := by simp
theorem fintype_card (α : Type u) [fintype α] : mk α = fintype.card α :=
by rw [← lift_mk_fin.{u}, ← lift_id (mk α), lift_mk_eq.{u 0 u}];
exact fintype.card_eq.1 (by simp)
theorem card_le_of_finset {α} (s : finset α) :
(s.card : cardinal) ≤ cardinal.mk α :=
begin
rw (_ : (s.card : cardinal) = cardinal.mk (↑s : set α)),
{ exact ⟨function.embedding.subtype _⟩ },
rw [cardinal.fintype_card, fintype.card_coe]
end
@[simp, norm_cast] theorem nat_cast_pow {m n : ℕ} : (↑(pow m n) : cardinal) = m ^ n :=
by induction n; simp [pow_succ', -_root_.add_comm, power_add, *]
@[simp, norm_cast] theorem nat_cast_le {m n : ℕ} : (m : cardinal) ≤ n ↔ m ≤ n :=
by rw [← lift_mk_fin, ← lift_mk_fin, lift_le]; exact
⟨λ ⟨⟨f, hf⟩⟩, begin
have : _ = fintype.card _ := finset.card_image_of_injective finset.univ hf,
simp at this,
rw [← fintype.card_fin n, ← this],
exact finset.card_le_of_subset (finset.subset_univ _)
end,
λ h, ⟨⟨λ i, ⟨i.1, lt_of_lt_of_le i.2 h⟩, λ a b h,
have _, from fin.veq_of_eq h, fin.eq_of_veq this⟩⟩⟩
@[simp, norm_cast] theorem nat_cast_lt {m n : ℕ} : (m : cardinal) < n ↔ m < n :=
by simp [lt_iff_le_not_le, -not_le]
@[simp, norm_cast] theorem nat_cast_inj {m n : ℕ} : (m : cardinal) = n ↔ m = n :=
by simp [le_antisymm_iff]
@[simp, norm_cast, priority 900] theorem nat_succ (n : ℕ) : (n.succ : cardinal) = succ n :=
le_antisymm (add_one_le_succ _) (succ_le.2 $ nat_cast_lt.2 $ nat.lt_succ_self _)
@[simp] theorem succ_zero : succ 0 = 1 :=
by norm_cast
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : finset α, s.card ≤ n) :
# α ≤ n :=
begin
refine lt_succ.1 (lt_of_not_ge $ λ hn, _),
rw [← cardinal.nat_succ, ← cardinal.lift_mk_fin n.succ] at hn,
cases hn with f,
refine not_lt_of_le (H $ finset.univ.map f) _,
rw [finset.card_map, ← fintype.card, fintype.card_ulift, fintype.card_fin],
exact n.lt_succ_self
end
theorem cantor' (a) {b : cardinal} (hb : 1 < b) : a < b ^ a :=
by rw [← succ_le, (by norm_cast : succ 1 = 2)] at hb;
exact lt_of_lt_of_le (cantor _) (power_le_power_right hb)
theorem one_le_iff_pos {c : cardinal} : 1 ≤ c ↔ 0 < c :=
by rw [← succ_zero, succ_le]
theorem one_le_iff_ne_zero {c : cardinal} : 1 ≤ c ↔ c ≠ 0 :=
by rw [one_le_iff_pos, pos_iff_ne_zero]
theorem nat_lt_omega (n : ℕ) : (n : cardinal.{u}) < omega :=
succ_le.1 $ by rw [← nat_succ, ← lift_mk_fin, omega, lift_mk_le.{0 0 u}]; exact
⟨⟨coe, λ a b, fin.ext⟩⟩
@[simp] theorem one_lt_omega : 1 < omega :=
by simpa using nat_lt_omega 1
theorem lt_omega {c : cardinal.{u}} : c < omega ↔ ∃ n : ℕ, c = n :=
⟨λ h, begin
rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩,
rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩,
suffices : finite S,
{ cases this, resetI,
existsi fintype.card S,
rw [← lift_nat_cast.{0 u}, lift_inj, fintype_card S] },
by_contra nf,
have P : ∀ (n : ℕ) (IH : ∀ i<n, S), ∃ a : S, ¬ ∃ y h, IH y h = a :=
λ n IH,
let g : {i | i < n} → S := λ ⟨i, h⟩, IH i h in
not_forall.1 (λ h, nf
⟨fintype.of_surjective g (λ a, subtype.exists.2 (h a))⟩),
let F : ℕ → S := nat.lt_wf.fix (λ n IH, classical.some (P n IH)),
refine not_le_of_lt h' ⟨⟨F, _⟩⟩,
suffices : ∀ (n : ℕ) (m < n), F m ≠ F n,
{ refine λ m n, not_imp_not.1 (λ ne, _),
rcases lt_trichotomy m n with h|h|h,
{ exact this n m h },
{ contradiction },
{ exact (this m n h).symm } },
intros n m h,
have := classical.some_spec (P n (λ y _, F y)),
rw [← show F n = classical.some (P n (λ y _, F y)),
from nat.lt_wf.fix_eq (λ n IH, classical.some (P n IH)) n] at this,
exact λ e, this ⟨m, h, e⟩,
end, λ ⟨n, e⟩, e.symm ▸ nat_lt_omega _⟩
theorem omega_le {c : cardinal.{u}} : omega ≤ c ↔ ∀ n : ℕ, (n:cardinal) ≤ c :=
⟨λ h n, le_trans (le_of_lt (nat_lt_omega _)) h,
λ h, le_of_not_lt $ λ hn, begin
rcases lt_omega.1 hn with ⟨n, rfl⟩,
exact not_le_of_lt (nat.lt_succ_self _) (nat_cast_le.1 (h (n+1)))
end⟩
theorem lt_omega_iff_fintype {α : Type u} : mk α < omega ↔ nonempty (fintype α) :=
lt_omega.trans ⟨λ ⟨n, e⟩, begin
rw [← lift_mk_fin n] at e,
cases quotient.exact e with f,
exact ⟨fintype.of_equiv _ f.symm⟩
end, λ ⟨_⟩, by exactI ⟨_, fintype_card _⟩⟩
theorem lt_omega_iff_finite {α} {S : set α} : mk S < omega ↔ finite S :=
lt_omega_iff_fintype
instance can_lift_cardinal_nat : can_lift cardinal ℕ :=
⟨ coe, λ x, x < omega, λ x hx, let ⟨n, hn⟩ := lt_omega.mp hx in ⟨n, hn.symm⟩⟩
theorem add_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a + b < omega :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_add]; apply nat_lt_omega
end
lemma add_lt_omega_iff {a b : cardinal} : a + b < omega ↔ a < omega ∧ b < omega :=
⟨λ h, ⟨lt_of_le_of_lt (le_add_right _ _) h, lt_of_le_of_lt (le_add_left _ _) h⟩,
λ⟨h1, h2⟩, add_lt_omega h1 h2⟩
theorem mul_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a * b < omega :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_mul]; apply nat_lt_omega
end
lemma mul_lt_omega_iff {a b : cardinal} : a * b < omega ↔ a = 0 ∨ b = 0 ∨ a < omega ∧ b < omega :=
begin
split,
{ intro h, by_cases ha : a = 0, { left, exact ha },
right, by_cases hb : b = 0, { left, exact hb },
right, rw [← ne, ← one_le_iff_ne_zero] at ha hb, split,
{ rw [← mul_one a], refine lt_of_le_of_lt (mul_le_mul (le_refl a) hb) h },
{ rw [← _root_.one_mul b], refine lt_of_le_of_lt (mul_le_mul ha (le_refl b)) h }},
rintro (rfl|rfl|⟨ha,hb⟩); simp only [*, mul_lt_omega, omega_pos, _root_.zero_mul, mul_zero]
end
lemma mul_lt_omega_iff_of_ne_zero {a b : cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < omega ↔ a < omega ∧ b < omega :=
by simp [mul_lt_omega_iff, ha, hb]
theorem power_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a ^ b < omega :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat_cast_pow]; apply nat_lt_omega
end
lemma eq_one_iff_subsingleton_and_nonempty {α : Type*} :
mk α = 1 ↔ (subsingleton α ∧ nonempty α) :=
calc mk α = 1 ↔ mk α ≤ 1 ∧ ¬mk α < 1 : eq_iff_le_not_lt
... ↔ subsingleton α ∧ nonempty α :
begin
apply and_congr le_one_iff_subsingleton,
push_neg,
rw [one_le_iff_ne_zero, ne_zero_iff_nonempty]
end
theorem infinite_iff {α : Type u} : infinite α ↔ omega ≤ mk α :=
by rw [←not_lt, lt_omega_iff_fintype, not_nonempty_fintype]
lemma countable_iff (s : set α) : countable s ↔ mk s ≤ omega :=
begin
rw [countable_iff_exists_injective], split,
rintro ⟨f, hf⟩, exact ⟨embedding.trans ⟨f, hf⟩ equiv.ulift.symm.to_embedding⟩,
rintro ⟨f'⟩, cases embedding.trans f' equiv.ulift.to_embedding with f hf, exact ⟨f, hf⟩
end
lemma denumerable_iff {α : Type u} : nonempty (denumerable α) ↔ mk α = omega :=
⟨λ⟨h⟩, quotient.sound $ by exactI ⟨ (denumerable.eqv α).trans equiv.ulift.symm ⟩,
λ h, by { cases quotient.exact h with f, exact ⟨denumerable.mk' $ f.trans equiv.ulift⟩ }⟩
lemma mk_int : mk ℤ = omega :=
denumerable_iff.mp ⟨by apply_instance⟩
lemma mk_pnat : mk ℕ+ = omega :=
denumerable_iff.mp ⟨by apply_instance⟩
lemma two_le_iff : (2 : cardinal) ≤ mk α ↔ ∃x y : α, x ≠ y :=
begin
split,
{ rintro ⟨f⟩, refine ⟨f $ sum.inl ⟨⟩, f $ sum.inr ⟨⟩, _⟩, intro h, cases f.2 h },
{ rintro ⟨x, y, h⟩, by_contra h',
rw [not_le, ←nat.cast_two, nat_succ, lt_succ, nat.cast_one, le_one_iff_subsingleton] at h',
apply h, exactI subsingleton.elim _ _ }
end
lemma two_le_iff' (x : α) : (2 : cardinal) ≤ mk α ↔ ∃y : α, x ≠ y :=
begin
rw [two_le_iff],
split,
{ rintro ⟨y, z, h⟩, refine classical.by_cases (λ(h' : x = y), _) (λ h', ⟨y, h'⟩),
rw [←h'] at h, exact ⟨z, h⟩ },
{ rintro ⟨y, h⟩, exact ⟨x, y, h⟩ }
end
/-- König's theorem -/
theorem sum_lt_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i < g i) : sum f < prod g :=
lt_of_not_ge $ λ ⟨F⟩, begin
have : inhabited (Π (i : ι), (g i).out),
{ refine ⟨λ i, classical.choice $ ne_zero_iff_nonempty.1 _⟩,
rw mk_out,
exact ne_of_gt (lt_of_le_of_lt (zero_le _) (H i)) }, resetI,
let G := inv_fun F,
have sG : surjective G := inv_fun_surjective F.2,
choose C hc using show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b,
{ assume i,
simp only [- not_exists, not_exists.symm, not_forall.symm],
refine λ h, not_le_of_lt (H i) _,
rw [← mk_out (f i), ← mk_out (g i)],
exact ⟨embedding.of_surjective _ h⟩ },
exact (let ⟨⟨i, a⟩, h⟩ := sG C in hc i a (congr_fun h _))
end
@[simp] theorem mk_empty : mk empty = 0 :=
fintype_card empty
@[simp] theorem mk_pempty : mk pempty = 0 :=
fintype_card pempty
@[simp] theorem mk_plift_of_false {p : Prop} (h : ¬ p) : mk (plift p) = 0 :=
quotient.sound ⟨equiv.plift.trans $ equiv.equiv_pempty h⟩
theorem mk_unit : mk unit = 1 :=
(fintype_card unit).trans nat.cast_one
@[simp] theorem mk_punit : mk punit = 1 :=
(fintype_card punit).trans nat.cast_one
@[simp] theorem mk_singleton {α : Type u} (x : α) : mk ({x} : set α) = 1 :=
quotient.sound ⟨equiv.set.singleton x⟩
@[simp] theorem mk_plift_of_true {p : Prop} (h : p) : mk (plift p) = 1 :=
quotient.sound ⟨equiv.plift.trans $ equiv.prop_equiv_punit h⟩
@[simp] theorem mk_bool : mk bool = 2 :=
quotient.sound ⟨equiv.bool_equiv_punit_sum_punit⟩
@[simp] theorem mk_Prop : mk Prop = 2 :=
(quotient.sound ⟨equiv.Prop_equiv_bool⟩ : mk Prop = mk bool).trans mk_bool
@[simp] theorem mk_set {α : Type u} : mk (set α) = 2 ^ mk α :=
begin
rw [← prop_eq_two, cardinal.power_def (ulift Prop) α, cardinal.eq],
exact ⟨equiv.arrow_congr (equiv.refl _) equiv.ulift.symm⟩,
end
@[simp] theorem mk_option {α : Type u} : mk (option α) = mk α + 1 :=
quotient.sound ⟨equiv.option_equiv_sum_punit α⟩
theorem mk_list_eq_sum_pow (α : Type u) : mk (list α) = sum (λ n : ℕ, (mk α)^(n:cardinal.{u})) :=
calc mk (list α)
= mk (Σ n, vector α n) : quotient.sound ⟨(equiv.sigma_preimage_equiv list.length).symm⟩
... = mk (Σ n, fin n → α) : quotient.sound ⟨equiv.sigma_congr_right $ λ n,
⟨vector.nth, vector.of_fn, vector.of_fn_nth, λ f, funext $ vector.nth_of_fn f⟩⟩
... = mk (Σ n : ℕ, ulift.{u} (fin n) → α) : quotient.sound ⟨equiv.sigma_congr_right $ λ n,
equiv.arrow_congr equiv.ulift.symm (equiv.refl α)⟩
... = sum (λ n : ℕ, (mk α)^(n:cardinal.{u})) : by simp only [(lift_mk_fin _).symm, lift_mk, power_def, sum_mk]
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : mk (quot r) ≤ mk α :=
mk_le_of_surjective quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : setoid α} : mk (quotient s) ≤ mk α :=
mk_quot_le
theorem mk_subtype_le {α : Type u} (p : α → Prop) : mk (subtype p) ≤ mk α :=
⟨embedding.subtype p⟩
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
mk (subtype p) ≤ mk (subtype q) :=
⟨embedding.subtype_map (embedding.refl α) h⟩
@[simp] theorem mk_emptyc (α : Type u) : mk (∅ : set α) = 0 :=
quotient.sound ⟨equiv.set.pempty α⟩
lemma mk_emptyc_iff {α : Type u} {s : set α} : mk s = 0 ↔ s = ∅ :=
begin
split,
{ intro h,
have h2 : cardinal.mk s = cardinal.mk pempty, by simp [h],
refine set.eq_empty_iff_forall_not_mem.mpr (λ _ hx, _),
rcases cardinal.eq.mp h2 with ⟨f, _⟩,
cases f ⟨_, hx⟩ },
{ intro, convert mk_emptyc _ }
end
theorem mk_univ {α : Type u} : mk (@univ α) = mk α :=
quotient.sound ⟨equiv.set.univ α⟩
theorem mk_image_le {α β : Type u} {f : α → β} {s : set α} : mk (f '' s) ≤ mk s :=
mk_le_of_surjective surjective_onto_image
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : set α} :
lift.{v u} (mk (f '' s)) ≤ lift.{u v} (mk s) :=
lift_mk_le.{v u 0}.mpr ⟨embedding.of_surjective _ surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : mk (range f) ≤ mk α :=
mk_le_of_surjective surjective_onto_range
lemma mk_range_eq (f : α → β) (h : injective f) : mk (range f) = mk α :=
quotient.sound ⟨(equiv.set.range f h).symm⟩
lemma mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{v u} (mk (range f)) = lift.{u v} (mk α) :=
begin
have := (@lift_mk_eq.{v u max u v} (range f) α).2 ⟨(equiv.set.range f hf).symm⟩,
simp only [lift_umax.{u v}, lift_umax.{v u}] at this,
exact this
end
lemma mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{v (max u w)} (# (range f)) = lift.{u (max v w)} (# α) :=
lift_mk_eq.mpr ⟨(equiv.set.range f hf).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : set α} (hf : injective f) :
mk (f '' s) = mk s :=
quotient.sound ⟨(equiv.set.image f s hf).symm⟩
theorem mk_Union_le_sum_mk {α ι : Type u} {f : ι → set α} : mk (⋃ i, f i) ≤ sum (λ i, mk (f i)) :=
calc mk (⋃ i, f i) ≤ mk (Σ i, f i) : mk_le_of_surjective (set.sigma_to_Union_surjective f)
... = sum (λ i, mk (f i)) : (sum_mk _).symm
theorem mk_Union_eq_sum_mk {α ι : Type u} {f : ι → set α} (h : ∀i j, i ≠ j → disjoint (f i) (f j)) :
mk (⋃ i, f i) = sum (λ i, mk (f i)) :=
calc mk (⋃ i, f i) = mk (Σi, f i) : quot.sound ⟨set.Union_eq_sigma_of_disjoint h⟩
... = sum (λi, mk (f i)) : (sum_mk _).symm
lemma mk_Union_le {α ι : Type u} (f : ι → set α) :
mk (⋃ i, f i) ≤ mk ι * cardinal.sup.{u u} (λ i, mk (f i)) :=
le_trans mk_Union_le_sum_mk (sum_le_sup _)
lemma mk_sUnion_le {α : Type u} (A : set (set α)) :
mk (⋃₀ A) ≤ mk A * cardinal.sup.{u u} (λ s : A, mk s) :=
by { rw [sUnion_eq_Union], apply mk_Union_le }
lemma mk_bUnion_le {ι α : Type u} (A : ι → set α) (s : set ι) :
mk (⋃(x ∈ s), A x) ≤ mk s * cardinal.sup.{u u} (λ x : s, mk (A x.1)) :=
by { rw [bUnion_eq_Union], apply mk_Union_le }
@[simp] lemma finset_card {α : Type u} {s : finset α} : ↑(finset.card s) = mk (↑s : set α) :=
by rw [fintype_card, nat_cast_inj, fintype.card_coe]
lemma finset_card_lt_omega (s : finset α) : mk (↑s : set α) < omega :=
by { rw [lt_omega_iff_fintype], exact ⟨finset.subtype.fintype s⟩ }
theorem mk_union_add_mk_inter {α : Type u} {S T : set α} :
mk (S ∪ T : set α) + mk (S ∩ T : set α) = mk S + mk T :=
quot.sound ⟨equiv.set.union_sum_inter S T⟩
/-- The cardinality of a union is at most the sum of the cardinalities
of the two sets. -/
lemma mk_union_le {α : Type u} (S T : set α) : mk (S ∪ T : set α) ≤ mk S + mk T :=
@mk_union_add_mk_inter α S T ▸ le_add_right (mk (S ∪ T : set α)) (mk (S ∩ T : set α))
theorem mk_union_of_disjoint {α : Type u} {S T : set α} (H : disjoint S T) :
mk (S ∪ T : set α) = mk S + mk T :=
quot.sound ⟨equiv.set.union H⟩
lemma mk_sum_compl {α} (s : set α) : #s + #(sᶜ : set α) = #α :=
quotient.sound ⟨equiv.set.sum_compl s⟩
lemma mk_le_mk_of_subset {α} {s t : set α} (h : s ⊆ t) : mk s ≤ mk t :=
⟨set.embedding_of_subset s t h⟩
lemma mk_subtype_mono {p q : α → Prop} (h : ∀x, p x → q x) : mk {x // p x} ≤ mk {x // q x} :=
⟨embedding_of_subset _ _ h⟩
lemma mk_set_le (s : set α) : mk s ≤ mk α :=
mk_subtype_le s
lemma mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : set α) (h : injective f) :
lift.{v u} (mk (f '' s)) = lift.{u v} (mk s) :=
lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image f s h).symm⟩
lemma mk_image_eq_of_inj_on_lift {α : Type u} {β : Type v} (f : α → β) (s : set α)
(h : inj_on f s) : lift.{v u} (mk (f '' s)) = lift.{u v} (mk s) :=
lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image_of_inj_on f s h).symm⟩
lemma mk_image_eq_of_inj_on {α β : Type u} (f : α → β) (s : set α) (h : inj_on f s) :
mk (f '' s) = mk s :=
quotient.sound ⟨(equiv.set.image_of_inj_on f s h).symm⟩
lemma mk_subtype_of_equiv {α β : Type u} (p : β → Prop) (e : α ≃ β) :
mk {a : α // p (e a)} = mk {b : β // p b} :=
quotient.sound ⟨equiv.subtype_equiv_of_subtype e⟩
lemma mk_sep (s : set α) (t : α → Prop) : mk ({ x ∈ s | t x } : set α) = mk { x : s | t x.1 } :=
quotient.sound ⟨equiv.set.sep s t⟩
lemma mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : set β)
(h : injective f) : lift.{u v} (mk (f ⁻¹' s)) ≤ lift.{v u} (mk s) :=
begin
rw lift_mk_le.{u v 0}, use subtype.coind (λ x, f x.1) (λ x, x.2),
apply subtype.coind_injective, exact h.comp subtype.val_injective
end
lemma mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : set β)
(h : s ⊆ range f) : lift.{v u} (mk s) ≤ lift.{u v} (mk (f ⁻¹' s)) :=
begin
rw lift_mk_le.{v u 0},
refine ⟨⟨_, _⟩⟩,
{ rintro ⟨y, hy⟩, rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩, exact ⟨x, hy⟩ },
rintro ⟨y, hy⟩ ⟨y', hy'⟩, dsimp,
rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩,
rcases classical.subtype_of_exists (h hy') with ⟨x', rfl⟩,
simp, intro hxx', rw hxx'
end
lemma mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : set β)
(h : injective f) (h2 : s ⊆ range f) : lift.{u v} (mk (f ⁻¹' s)) = lift.{v u} (mk s) :=
le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2)
lemma mk_preimage_of_injective (f : α → β) (s : set β) (h : injective f) :
mk (f ⁻¹' s) ≤ mk s :=
by { convert mk_preimage_of_injective_lift.{u u} f s h using 1; rw [lift_id] }
lemma mk_preimage_of_subset_range (f : α → β) (s : set β)
(h : s ⊆ range f) : mk s ≤ mk (f ⁻¹' s) :=
by { convert mk_preimage_of_subset_range_lift.{u u} f s h using 1; rw [lift_id] }
lemma mk_preimage_of_injective_of_subset_range (f : α → β) (s : set β)
(h : injective f) (h2 : s ⊆ range f) : mk (f ⁻¹' s) = mk s :=
by { convert mk_preimage_of_injective_of_subset_range_lift.{u u} f s h h2 using 1; rw [lift_id] }
lemma mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : set α}
{t : set β} (h : t ⊆ f '' s) :
lift.{v u} (mk t) ≤ lift.{u v} (mk ({ x ∈ s | f x ∈ t } : set α)) :=
by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range_lift _ _ h using 1, rw [mk_sep], refl }
lemma mk_subset_ge_of_subset_image (f : α → β) {s : set α} {t : set β} (h : t ⊆ f '' s) :
mk t ≤ mk ({ x ∈ s | f x ∈ t } : set α) :=
by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range _ _ h using 1, rw [mk_sep], refl }
theorem le_mk_iff_exists_subset {c : cardinal} {α : Type u} {s : set α} :
c ≤ mk s ↔ ∃ p : set α, p ⊆ s ∧ mk p = c :=
begin
rw [le_mk_iff_exists_set, ←subtype.exists_set_subtype],
apply exists_congr, intro t, rw [mk_image_eq], apply subtype.val_injective
end
/-- The function α^{<β}, defined to be sup_{γ < β} α^γ.
We index over {s : set β.out // mk s < β } instead of {γ // γ < β}, because the latter lives in a
higher universe -/
noncomputable def powerlt (α β : cardinal.{u}) : cardinal.{u} :=
sup.{u u} (λ(s : {s : set β.out // mk s < β}), α ^ mk.{u} s)
infix ` ^< `:80 := powerlt
theorem powerlt_aux {c c' : cardinal} (h : c < c') :
∃(s : {s : set c'.out // mk s < c'}), mk s = c :=
begin
cases out_embedding.mp (le_of_lt h) with f,
have : mk ↥(range ⇑f) = c, { rwa [mk_range_eq, mk, quotient.out_eq c], exact f.2 },
exact ⟨⟨range f, by convert h⟩, this⟩
end
lemma le_powerlt {c₁ c₂ c₃ : cardinal} (h : c₂ < c₃) : c₁ ^ c₂ ≤ c₁ ^< c₃ :=
by { rcases powerlt_aux h with ⟨s, rfl⟩, apply le_sup _ s }
lemma powerlt_le {c₁ c₂ c₃ : cardinal} : c₁ ^< c₂ ≤ c₃ ↔ ∀(c₄ < c₂), c₁ ^ c₄ ≤ c₃ :=
begin
rw [powerlt, sup_le],
split,
{ intros h c₄ hc₄, rcases powerlt_aux hc₄ with ⟨s, rfl⟩, exact h s },
intros h s, exact h _ s.2
end
lemma powerlt_le_powerlt_left {a b c : cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
by { rw [powerlt, sup_le], rintro ⟨s, hs⟩, apply le_powerlt, exact lt_of_lt_of_le hs h }
lemma powerlt_succ {c₁ c₂ : cardinal} (h : c₁ ≠ 0) : c₁ ^< c₂.succ = c₁ ^ c₂ :=
begin
apply le_antisymm,
{ rw powerlt_le, intros c₃ h2, apply power_le_power_left h, rwa [←lt_succ] },
{ apply le_powerlt, apply lt_succ_self }
end
lemma powerlt_max {c₁ c₂ c₃ : cardinal} : c₁ ^< max c₂ c₃ = max (c₁ ^< c₂) (c₁ ^< c₃) :=
by { cases le_total c₂ c₃; simp only [max_eq_left, max_eq_right, h, powerlt_le_powerlt_left] }
lemma zero_powerlt {a : cardinal} (h : a ≠ 0) : 0 ^< a = 1 :=
begin
apply le_antisymm,
{ rw [powerlt_le], intros c hc, apply zero_power_le },
convert le_powerlt (pos_iff_ne_zero.2 h), rw [power_zero]
end
lemma powerlt_zero {a : cardinal} : a ^< 0 = 0 :=
by { apply sup_eq_zero, rintro ⟨x, hx⟩, rw [←not_le] at hx, apply hx, apply zero_le }
end cardinal
|
23ffbed1b2abd976ece724498a6c49d01c0d261d | 4727251e0cd73359b15b664c3170e5d754078599 | /src/measure_theory/measure/giry_monad.lean | 11b2f7ff2f0242985988d63f26bc03055c7c0d19 | [
"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 | 8,542 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import measure_theory.integral.lebesgue
/-!
# The Giry monad
Let X be a measurable space. The collection of all measures on X again
forms a measurable space. This construction forms a monad on
measurable spaces and measurable functions, called the Giry monad.
Note that most sources use the term "Giry monad" for the restriction
to *probability* measures. Here we include all measures on X.
See also `measure_theory/category/Meas.lean`, containing an upgrade of the type-level
monad to an honest monad of the functor `Measure : Meas ⥤ Meas`.
## References
* <https://ncatlab.org/nlab/show/Giry+monad>
## Tags
giry monad
-/
noncomputable theory
open_locale classical big_operators ennreal
open classical set filter
variables {α β γ δ ε : Type*}
namespace measure_theory
namespace measure
variables [measurable_space α] [measurable_space β]
/-- Measurability structure on `measure`: Measures are measurable w.r.t. all projections -/
instance : measurable_space (measure α) :=
⨆ (s : set α) (hs : measurable_set s), (borel ℝ≥0∞).comap (λμ, μ s)
lemma measurable_coe {s : set α} (hs : measurable_set s) : measurable (λμ : measure α, μ s) :=
measurable.of_comap_le $ le_supr_of_le s $ le_supr_of_le hs $ le_rfl
lemma measurable_of_measurable_coe (f : β → measure α)
(h : ∀(s : set α) (hs : measurable_set s), measurable (λb, f b s)) :
measurable f :=
measurable.of_le_map $ supr₂_le $ assume s hs, measurable_space.comap_le_iff_le_map.2 $
by rw [measurable_space.map_comp]; exact h s hs
lemma measurable_measure {μ : α → measure β} :
measurable μ ↔ ∀(s : set β) (hs : measurable_set s), measurable (λb, μ b s) :=
⟨λ hμ s hs, (measurable_coe hs).comp hμ, measurable_of_measurable_coe μ⟩
lemma measurable_map (f : α → β) (hf : measurable f) :
measurable (λμ : measure α, map f μ) :=
measurable_of_measurable_coe _ $ assume s hs,
suffices measurable (λ (μ : measure α), μ (f ⁻¹' s)),
by simpa [map_apply, hs, hf],
measurable_coe (hf hs)
lemma measurable_dirac :
measurable (measure.dirac : α → measure α) :=
measurable_of_measurable_coe _ $ assume s hs,
begin
simp only [dirac_apply', hs],
exact measurable_one.indicator hs
end
lemma measurable_lintegral {f : α → ℝ≥0∞} (hf : measurable f) :
measurable (λμ : measure α, ∫⁻ x, f x ∂μ) :=
begin
simp only [lintegral_eq_supr_eapprox_lintegral, hf, simple_func.lintegral],
refine measurable_supr (λ n, finset.measurable_sum _ (λ i _, _)),
refine measurable.const_mul _ _,
exact measurable_coe ((simple_func.eapprox f n).measurable_set_preimage _)
end
/-- Monadic join on `measure` in the category of measurable spaces and measurable
functions. -/
def join (m : measure (measure α)) : measure α :=
measure.of_measurable
(λs hs, ∫⁻ μ, μ s ∂m)
(by simp)
begin
assume f hf h,
simp [measure_Union h hf],
apply lintegral_tsum,
assume i, exact measurable_coe (hf i)
end
@[simp] lemma join_apply {m : measure (measure α)} :
∀{s : set α}, measurable_set s → join m s = ∫⁻ μ, μ s ∂m :=
measure.of_measurable_apply
@[simp] lemma join_zero : (0 : measure (measure α)).join = 0 :=
by { ext1 s hs, simp [hs] }
lemma measurable_join : measurable (join : measure (measure α) → measure α) :=
measurable_of_measurable_coe _ $ assume s hs,
by simp only [join_apply hs]; exact measurable_lintegral (measurable_coe hs)
lemma lintegral_join {m : measure (measure α)} {f : α → ℝ≥0∞} (hf : measurable f) :
∫⁻ x, f x ∂(join m) = ∫⁻ μ, ∫⁻ x, f x ∂μ ∂m :=
begin
rw [lintegral_eq_supr_eapprox_lintegral hf],
have : ∀n x,
join m (⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {x}) =
∫⁻ μ, μ ((⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {x})) ∂m :=
assume n x, join_apply (simple_func.measurable_set_preimage _ _),
simp only [simple_func.lintegral, this],
transitivity,
have : ∀(s : ℕ → finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → measure α → ℝ≥0∞)
(hf : ∀n r, measurable (f n r)) (hm : monotone (λn μ, ∑ r in s n, r * f n r μ)),
(⨆n:ℕ, ∑ r in s n, r * ∫⁻ μ, f n r μ ∂m) =
∫⁻ μ, ⨆n:ℕ, ∑ r in s n, r * f n r μ ∂m,
{ assume s f hf hm,
symmetry,
transitivity,
apply lintegral_supr,
{ assume n,
exact finset.measurable_sum _ (assume r _, (hf _ _).const_mul _) },
{ exact hm },
congr, funext n,
transitivity,
apply lintegral_finset_sum,
{ assume r _, exact (hf _ _).const_mul _ },
congr, funext r,
apply lintegral_const_mul,
exact hf _ _ },
specialize this (λn, simple_func.range (simple_func.eapprox f n)),
specialize this
(λn r μ, μ (⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {r})),
refine this _ _; clear this,
{ assume n r,
apply measurable_coe,
exact simple_func.measurable_set_preimage _ _ },
{ change monotone (λn μ, (simple_func.eapprox f n).lintegral μ),
assume n m h μ,
refine simple_func.lintegral_mono _ le_rfl,
apply simple_func.monotone_eapprox,
assumption },
congr, funext μ,
symmetry,
apply lintegral_eq_supr_eapprox_lintegral,
exact hf
end
/-- Monadic bind on `measure`, only works in the category of measurable spaces and measurable
functions. When the function `f` is not measurable the result is not well defined. -/
def bind (m : measure α) (f : α → measure β) : measure β := join (map f m)
@[simp] lemma bind_zero_left (f : α → measure β) : bind 0 f = 0 :=
by simp [bind]
@[simp] lemma bind_zero_right (m : measure α) :
bind m (0 : α → measure β) = 0 :=
begin
ext1 s hs,
simp only [bind, hs, join_apply, coe_zero, pi.zero_apply],
rw [lintegral_map (measurable_coe hs) measurable_zero],
simp
end
@[simp] lemma bind_zero_right' (m : measure α) :
bind m (λ _, 0 : α → measure β) = 0 :=
bind_zero_right m
@[simp] lemma bind_apply {m : measure α} {f : α → measure β} {s : set β}
(hs : measurable_set s) (hf : measurable f) :
bind m f s = ∫⁻ a, f a s ∂m :=
by rw [bind, join_apply hs, lintegral_map (measurable_coe hs) hf]
lemma measurable_bind' {g : α → measure β} (hg : measurable g) : measurable (λm, bind m g) :=
measurable_join.comp (measurable_map _ hg)
lemma lintegral_bind {m : measure α} {μ : α → measure β} {f : β → ℝ≥0∞}
(hμ : measurable μ) (hf : measurable f) :
∫⁻ x, f x ∂ (bind m μ) = ∫⁻ a, ∫⁻ x, f x ∂(μ a) ∂m:=
(lintegral_join hf).trans (lintegral_map (measurable_lintegral hf) hμ)
lemma bind_bind {γ} [measurable_space γ] {m : measure α} {f : α → measure β} {g : β → measure γ}
(hf : measurable f) (hg : measurable g) :
bind (bind m f) g = bind m (λa, bind (f a) g) :=
measure.ext $ assume s hs,
begin
rw [bind_apply hs hg, bind_apply hs ((measurable_bind' hg).comp hf), lintegral_bind hf],
{ congr, funext a,
exact (bind_apply hs hg).symm },
exact (measurable_coe hs).comp hg
end
lemma bind_dirac {f : α → measure β} (hf : measurable f) (a : α) : bind (dirac a) f = f a :=
measure.ext $ λ s hs, by rw [bind_apply hs hf, lintegral_dirac' a ((measurable_coe hs).comp hf)]
lemma dirac_bind {m : measure α} : bind m dirac = m :=
measure.ext $ assume s hs,
by simp [bind_apply hs measurable_dirac, dirac_apply' _ hs, lintegral_indicator 1 hs]
lemma join_eq_bind (μ : measure (measure α)) : join μ = bind μ id :=
by rw [bind, map_id]
lemma join_map_map {f : α → β} (hf : measurable f) (μ : measure (measure α)) :
join (map (map f) μ) = map f (join μ) :=
measure.ext $ assume s hs,
begin
rw [join_apply hs, map_apply hf hs, join_apply,
lintegral_map (measurable_coe hs) (measurable_map f hf)],
{ congr, funext ν, exact map_apply hf hs },
exact hf hs
end
lemma join_map_join (μ : measure (measure (measure α))) :
join (map join μ) = join (join μ) :=
begin
show bind μ join = join (join μ),
rw [join_eq_bind, join_eq_bind, bind_bind measurable_id measurable_id],
apply congr_arg (bind μ),
funext ν,
exact join_eq_bind ν
end
lemma join_map_dirac (μ : measure α) : join (map dirac μ) = μ :=
dirac_bind
lemma join_dirac (μ : measure α) : join (dirac μ) = μ :=
eq.trans (join_eq_bind (dirac μ)) (bind_dirac measurable_id _)
end measure
end measure_theory
|
162f657add6b1aa3e6b7f35ac6c0ce06994f49d2 | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/j2.lean | a506dcb993fd44e8a6d433d682292339ff941f69 | [
"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 | 1,229 | lean | import macros
import tactic
using Nat
definition dvd (a b : Nat) : Bool := ∃ c, a * c = b
infix 50 | : dvd
theorem dvd_trans {a b c} (H1 : a | b) (H2 : b | c) : a | c
:= obtain (w1 : Nat) (Hw1 : a * w1 = b), from H1,
obtain (w2 : Nat) (Hw2 : b * w2 = c), from H2,
exists_intro (w1 * w2)
(calc a * (w1 * w2) = a * w1 * w2 : symm (mul_assoc a w1 w2)
... = b * w2 : { Hw1 }
... = c : Hw2)
definition prime p := p ≥ 2 ∧ forall m, m | p → m = 1 ∨ m = p
theorem not_prime_eq (n : Nat) (H1 : n ≥ 2) (H2 : ¬ prime n) : ∃ m, m | n ∧ m ≠ 1 ∧ m ≠ n
:= have H3 : ¬ n ≥ 2 ∨ ¬ (∀ m : Nat, m | n → m = 1 ∨ m = n),
from (not_and _ _ ◂ H2),
have H4 : ¬ ¬ n ≥ 2,
from ((symm (not_not_eq _)) ◂ H1),
obtain (m : Nat) (H5 : ¬ (m | n → m = 1 ∨ m = n)),
from (not_forall_elim (resolve1 H3 H4)),
have H6 : m | n ∧ ¬ (m = 1 ∨ m = n),
from ((not_implies _ _) ◂ H5),
have H7 : ¬ (m = 1 ∨ m = n) ↔ (m ≠ 1 ∧ m ≠ n),
from (not_or (m = 1) (m = n)),
have H8 : m | n ∧ m ≠ 1 ∧ m ≠ n,
from subst H6 H7,
show ∃ m, m | n ∧ m ≠ 1 ∧ m ≠ n,
from exists_intro m H8
|
15a44ca8e383175267e207f207d7e029aa5b0827 | 1dd482be3f611941db7801003235dc84147ec60a | /src/data/polynomial.lean | 02eeda2beda01d1db15fae9fe37f5dbdd1cf52b8 | [
"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 | 85,813 | 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, Jens Wagemaker
Theory of univariate polynomials, represented as `ℕ →₀ α`, where α is a commutative semiring.
-/
import data.finsupp algebra.euclidean_domain tactic.ring ring_theory.associated ring_theory.multiplicity
/-- `polynomial α` is the type of univariate polynomials over `α`.
Polynomials should be seen as (semi-)rings with the additional constructor `X`.
The embedding from α is called `C`. -/
def polynomial (α : Type*) [comm_semiring α] := ℕ →₀ α
open finsupp finset lattice
namespace polynomial
universes u v
variables {α : Type u} {β : Type v} {a b : α} {m n : ℕ}
section comm_semiring
variables [comm_semiring α] [decidable_eq α] {p q r : polynomial α}
instance : has_zero (polynomial α) := finsupp.has_zero
instance : has_one (polynomial α) := finsupp.has_one
instance : has_add (polynomial α) := finsupp.has_add
instance : has_mul (polynomial α) := finsupp.has_mul
instance : comm_semiring (polynomial α) := finsupp.to_comm_semiring
instance : decidable_eq (polynomial α) := finsupp.decidable_eq
def polynomial.has_coe_to_fun : has_coe_to_fun (polynomial α) :=
finsupp.has_coe_to_fun
local attribute [instance] finsupp.to_comm_semiring polynomial.has_coe_to_fun
@[simp] lemma support_zero : (0 : polynomial α).support = ∅ := rfl
/-- `C a` is the constant polynomial `a`. -/
def C (a : α) : polynomial α := single 0 a
/-- `X` is the polynomial variable (aka indeterminant). -/
def X : polynomial α := single 1 1
/-- coeff p n is the coefficient of X^n in p -/
def coeff (p : polynomial α) := p.to_fun
instance [has_repr α] : has_repr (polynomial α) :=
⟨λ p, if p = 0 then "0"
else (p.support.sort (≤)).foldr
(λ n a, a ++ (if a = "" then "" else " + ") ++
if n = 0
then "C (" ++ repr (coeff p n) ++ ")"
else if n = 1
then if (coeff p n) = 1 then "X" else "C (" ++ repr (coeff p n) ++ ") * X"
else if (coeff p n) = 1 then "X ^ " ++ repr n
else "C (" ++ repr (coeff p n) ++ ") * X ^ " ++ repr n) ""⟩
theorem ext {p q : polynomial α} : p = q ↔ ∀ n, coeff p n = coeff q n :=
⟨λ h n, h ▸ rfl, finsupp.ext⟩
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : polynomial α) : with_bot ℕ := p.support.sup some
def degree_lt_wf : well_founded (λp q : polynomial α, degree p < degree q) :=
inv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)
/-- `nat_degree p` forces `degree p` to ℕ, by defining nat_degree 0 = 0. -/
def nat_degree (p : polynomial α) : ℕ := (degree p).get_or_else 0
lemma single_eq_C_mul_X : ∀{n}, single n a = C a * X^n
| 0 := (mul_one _).symm
| (n+1) :=
calc single (n + 1) a = single n a * X : by rw [X, single_mul_single, mul_one]
... = (C a * X^n) * X : by rw [single_eq_C_mul_X]
... = C a * X^(n+1) : by simp only [pow_add, mul_assoc, pow_one]
lemma sum_C_mul_X_eq (p : polynomial α) : p.sum (λn a, C a * X^n) = p :=
eq.trans (sum_congr rfl $ assume n hn, single_eq_C_mul_X.symm) (finsupp.sum_single _)
@[elab_as_eliminator] protected lemma induction_on {M : polynomial α → Prop} (p : polynomial α)
(h_C : ∀a, M (C a))
(h_add : ∀p q, M p → M q → M (p + q))
(h_monomial : ∀(n : ℕ) (a : α), M (C a * X^n) → M (C a * X^(n+1))) :
M p :=
have ∀{n:ℕ} {a}, M (C a * X^n),
begin
assume n a,
induction n with n ih,
{ simp only [pow_zero, mul_one, h_C] },
{ exact h_monomial _ _ ih }
end,
finsupp.induction p
(suffices M (C 0), by simpa only [C, single_zero],
h_C 0)
(assume n a p _ _ hp, suffices M (C a * X^n + p), by rwa [single_eq_C_mul_X],
h_add _ _ this hp)
@[simp] lemma C_0 : C (0 : α) = 0 := single_zero
@[simp] lemma C_1 : C (1 : α) = 1 := rfl
@[simp] lemma C_mul : C (a * b) = C a * C b :=
(@single_mul_single _ _ _ _ _ _ 0 0 a b).symm
@[simp] lemma C_add : C (a + b) = C a + C b := finsupp.single_add
instance C.is_semiring_hom : is_semiring_hom (C : α → polynomial α) :=
⟨C_0, C_1, λ _ _, C_add, λ _ _, C_mul⟩
@[simp] lemma C_pow : C (a ^ n) = C a ^ n := is_semiring_hom.map_pow _ _ _
section coeff
lemma apply_eq_coeff : p n = coeff p n := rfl
@[simp] lemma coeff_zero (n : ℕ) : coeff (0 : polynomial α) n = 0 := rfl
@[simp] lemma coeff_one_zero (n : ℕ) : coeff (1 : polynomial α) 0 = 1 := rfl
@[simp] lemma coeff_add (p q : polynomial α) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := rfl
lemma coeff_C : coeff (C a) n = ite (n = 0) a 0 :=
by simp [coeff, eq_comm, C, single]; congr
@[simp] lemma coeff_C_zero : coeff (C a) 0 = a := rfl
@[simp] lemma coeff_X_one : coeff (X : polynomial α) 1 = 1 := rfl
@[simp] lemma coeff_X_zero : coeff (X : polynomial α) 0 = 0 := rfl
lemma coeff_X : coeff (X : polynomial α) n = if 1 = n then 1 else 0 := rfl
@[simp] lemma coeff_C_mul_X (x : α) (k n : ℕ) :
coeff (C x * X^k : polynomial α) n = if n = k then x else 0 :=
by rw [← single_eq_C_mul_X]; simp [single, eq_comm, coeff]; congr
lemma coeff_sum [comm_semiring β] [decidable_eq β] (n : ℕ) (f : ℕ → α → polynomial β) :
coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) := finsupp.sum_apply
lemma coeff_single : coeff (single n a) m = if n = m then a else 0 := rfl
@[simp] lemma coeff_C_mul (p : polynomial α) : coeff (C a * p) n = a * coeff p n :=
begin
conv in (a * _) { rw [← @sum_single _ _ _ _ _ p, coeff_sum] },
rw [mul_def, C, sum_single_index],
{ simp [coeff_single, finsupp.mul_sum, coeff_sum],
apply sum_congr rfl,
assume i hi, by_cases i = n; simp [h] },
simp
end
@[simp] lemma coeff_one (n : ℕ) :
coeff (1 : polynomial α) n = if 0 = n then 1 else 0 := rfl
@[simp] lemma coeff_X_pow (k n : ℕ) :
coeff (X^k : polynomial α) n = if n = k then 1 else 0 :=
by simpa only [C_1, one_mul] using coeff_C_mul_X (1:α) k n
lemma coeff_mul_left (p q : polynomial α) (n : ℕ) :
coeff (p * q) n = (range (n+1)).sum (λ k, coeff p k * coeff q (n-k)) :=
have hite : ∀ a : ℕ × ℕ, ite (a.1 + a.2 = n) (coeff p (a.fst) * coeff q (a.snd)) 0 ≠ 0
→ a.1 + a.2 = n, from λ a ha, by_contradiction
(λ h, absurd (eq.refl (0 : α)) (by rwa if_neg h at ha)),
calc coeff (p * q) n = sum (p.support) (λ a, sum (q.support)
(λ b, ite (a + b = n) (coeff p a * coeff q b) 0)) :
by simp only [finsupp.mul_def, coeff_sum, coeff_single]; refl
... = (p.support.product q.support).sum
(λ v : ℕ × ℕ, ite (v.1 + v.2 = n) (coeff p v.1 * coeff q v.2) 0) :
by rw sum_product
... = (range (n+1)).sum (λ k, coeff p k * coeff q (n-k)) :
sum_bij_ne_zero (λ a _ _, a.1)
(λ a _ ha, mem_range.2 (nat.lt_succ_of_le (hite a ha ▸ le_add_right (le_refl _))))
(λ a₁ a₂ _ h₁ _ h₂ h, prod.ext h
((add_left_inj a₁.1).1 (by rw [hite a₁ h₁, h, hite a₂ h₂])))
(λ a h₁ h₂, ⟨(a, n - a), mem_product.2
⟨mem_support_iff.2 (ne_zero_of_mul_ne_zero_right h₂),
mem_support_iff.2 (ne_zero_of_mul_ne_zero_left h₂)⟩,
by simpa [nat.add_sub_cancel' (nat.le_of_lt_succ (mem_range.1 h₁))],
rfl⟩)
(λ a _ ha, by rw [← hite a ha, if_pos rfl, nat.add_sub_cancel_left])
lemma coeff_mul_right (p q : polynomial α) (n : ℕ) :
coeff (p * q) n = (range (n+1)).sum (λ k, coeff p (n-k) * coeff q k) :=
by rw [mul_comm, coeff_mul_left]; simp only [mul_comm]
theorem coeff_mul_X_pow (p : polynomial α) (n d : ℕ) :
coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=
begin
rw [coeff_mul_right, sum_eq_single n, coeff_X_pow, if_pos rfl, mul_one, nat.add_sub_cancel],
{ intros b h1 h2, rw [coeff_X_pow, if_neg h2, mul_zero] },
{ exact λ h1, (h1 (mem_range.2 (nat.le_add_left _ _))).elim }
end
theorem coeff_mul_X (p : polynomial α) (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 α} {n : ℕ}
(H : p * X ^ n = 0) : p = 0 :=
ext.2 $ λ k, (coeff_mul_X_pow p n k).symm.trans $ ext.1 H (k+n)
end coeff
lemma C_inj : C a = C b ↔ a = b :=
⟨λ h, coeff_C_zero.symm.trans (h.symm ▸ coeff_C_zero), congr_arg C⟩
section eval₂
variables [semiring β]
variables (f : α → β) (x : β)
open is_semiring_hom
/-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring
to the target and a value `x` for the variable in the target -/
def eval₂ (p : polynomial α) : β :=
p.sum (λ e a, f a * x ^ e)
variables [is_semiring_hom f]
@[simp] lemma eval₂_C : (C a).eval₂ f x = f a :=
(sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [pow_zero, mul_one]
@[simp] lemma eval₂_X : X.eval₂ f x = x :=
(sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [map_one f, one_mul, pow_one]
@[simp] lemma eval₂_zero : (0 : polynomial α).eval₂ f x = 0 :=
finsupp.sum_zero_index
@[simp] lemma eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x :=
finsupp.sum_add_index
(λ _, by rw [map_zero f, zero_mul])
(λ _ _ _, by rw [map_add f, add_mul])
@[simp] lemma eval₂_one : (1 : polynomial α).eval₂ f x = 1 :=
by rw [← C_1, eval₂_C, map_one f]
instance eval₂.is_add_monoid_hom : is_add_monoid_hom (eval₂ f x) :=
⟨eval₂_zero _ _, λ _ _, eval₂_add _ _⟩
end eval₂
section eval₂
variables [comm_semiring β]
variables (f : α → β) [is_semiring_hom f] (x : β)
open is_semiring_hom
@[simp] lemma eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x :=
begin
dunfold eval₂,
rw [mul_def, finsupp.sum_mul _ p], simp only [finsupp.mul_sum _ q], rw [sum_sum_index],
{ apply sum_congr rfl, assume i hi, dsimp only, rw [sum_sum_index],
{ apply sum_congr rfl, assume j hj, dsimp only,
rw [sum_single_index, map_mul f, pow_add],
{ simp only [mul_assoc, mul_left_comm] },
{ rw [map_zero f, zero_mul] } },
{ intro, rw [map_zero f, zero_mul] },
{ intros, rw [map_add f, add_mul] } },
{ intro, rw [map_zero f, zero_mul] },
{ intros, rw [map_add f, add_mul] }
end
instance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f x) :=
⟨eval₂_zero _ _, eval₂_one _ _, λ _ _, eval₂_add _ _, λ _ _, eval₂_mul _ _⟩
lemma eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n := map_pow _ _ _
lemma eval₂_sum (p : polynomial α) (g : ℕ → α → polynomial α) (x : β) :
(p.sum g).eval₂ f x = p.sum (λ n a, (g n a).eval₂ f x) :=
finsupp.sum_sum_index (by simp [is_add_monoid_hom.map_zero f])
(by intros; simp [right_distrib, is_add_monoid_hom.map_add f])
end eval₂
section eval
variable {x : α}
/-- `eval x p` is the evaluation of the polynomial `p` at `x` -/
def eval : α → polynomial α → α := eval₂ id
@[simp] lemma eval_C : (C a).eval x = a := eval₂_C _ _
@[simp] lemma eval_X : X.eval x = x := eval₂_X _ _
@[simp] lemma eval_zero : (0 : polynomial α).eval x = 0 := eval₂_zero _ _
@[simp] lemma eval_add : (p + q).eval x = p.eval x + q.eval x := eval₂_add _ _
@[simp] lemma eval_one : (1 : polynomial α).eval x = 1 := eval₂_one _ _
@[simp] lemma eval_mul : (p * q).eval x = p.eval x * q.eval x := eval₂_mul _ _
instance eval.is_semiring_hom : is_semiring_hom (eval x) := eval₂.is_semiring_hom _ _
@[simp] lemma eval_pow (n : ℕ) : (p ^ n).eval x = p.eval x ^ n := eval₂_pow _ _ _
lemma eval_sum (p : polynomial α) (f : ℕ → α → polynomial α) (x : α) :
(p.sum f).eval x = p.sum (λ n a, (f n a).eval x) :=
eval₂_sum _ _ _ _
lemma eval₂_hom [comm_semiring β] (f : α → β) [is_semiring_hom f] (x : α) :
p.eval₂ f (f x) = f (p.eval x) :=
polynomial.induction_on p
(by simp)
(by simp [is_semiring_hom.map_add f] {contextual := tt})
(by simp [is_semiring_hom.map_mul f, eval_pow,
is_semiring_hom.map_pow f, pow_succ', (mul_assoc _ _ _).symm] {contextual := tt})
/-- `is_root p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/
def is_root (p : polynomial α) (a : α) : Prop := p.eval a = 0
instance : decidable (is_root p a) := by unfold is_root; apply_instance
@[simp] lemma is_root.def : is_root p a ↔ p.eval a = 0 := iff.rfl
lemma root_mul_left_of_is_root (p : polynomial α) {q : polynomial α} :
is_root q a → is_root (p * q) a :=
λ H, by rw [is_root, eval_mul, is_root.def.1 H, mul_zero]
lemma root_mul_right_of_is_root {p : polynomial α} (q : polynomial α) :
is_root p a → is_root (p * q) a :=
λ H, by rw [is_root, eval_mul, is_root.def.1 H, zero_mul]
lemma coeff_zero_eq_eval_zero (p : polynomial α) :
coeff p 0 = p.eval 0 :=
calc coeff p 0 = coeff p 0 * 0 ^ 0 : by simp
... = p.eval 0 : eq.symm $
finset.sum_eq_single _ (λ b _ hb, by simp [zero_pow (nat.pos_of_ne_zero hb)]) (by simp)
end eval
section comp
def comp (p q : polynomial α) : polynomial α := p.eval₂ C q
lemma eval₂_comp [comm_semiring β] (f : α → β) [is_semiring_hom f] {x : β} :
(p.comp q).eval₂ f x = p.eval₂ f (q.eval₂ f x) :=
show (p.sum (λ e a, C a * q ^ e)).eval₂ f x = p.eval₂ f (eval₂ f x q),
by simp only [eval₂_mul, eval₂_C, eval₂_pow, eval₂_sum]; refl
lemma eval_comp : (p.comp q).eval a = p.eval (q.eval a) := eval₂_comp _
@[simp] lemma comp_X : p.comp X = p :=
begin
refine polynomial.ext.2 (λ n, _),
rw [comp, eval₂],
conv in (C _ * _) { rw ← single_eq_C_mul_X },
rw finsupp.sum_single
end
@[simp] lemma X_comp : X.comp p = p := eval₂_X _ _
@[simp] lemma comp_C : p.comp (C a) = C (p.eval a) :=
begin
dsimp [comp, eval₂, eval, finsupp.sum],
rw [← sum_hom (@C α _ _)],
apply finset.sum_congr rfl; simp
end
@[simp] lemma C_comp : (C a).comp p = C a := eval₂_C _ _
@[simp] lemma comp_zero : p.comp (0 : polynomial α) = C (p.eval 0) :=
by rw [← C_0, comp_C]
@[simp] lemma zero_comp : comp (0 : polynomial α) p = 0 :=
by rw [← C_0, C_comp]
@[simp] lemma comp_one : p.comp 1 = C (p.eval 1) :=
by rw [← C_1, comp_C]
@[simp] lemma one_comp : comp (1 : polynomial α) p = 1 :=
by rw [← C_1, C_comp]
instance : is_semiring_hom (λ q : polynomial α, q.comp p) :=
by unfold comp; apply_instance
@[simp] lemma add_comp : (p + q).comp r = p.comp r + q.comp r := eval₂_add _ _
@[simp] lemma mul_comp : (p * q).comp r = p.comp r * q.comp r := eval₂_mul _ _
end comp
section map
variables [comm_semiring β] [decidable_eq β]
variables (f : α → β)
/-- `map f p` maps a polynomial `p` across a ring hom `f` -/
def map : polynomial α → polynomial β := eval₂ (C ∘ f) X
variables [is_semiring_hom f]
@[simp] lemma map_C : (C a).map f = C (f a) := eval₂_C _ _
@[simp] lemma map_X : X.map f = X := eval₂_X _ _
@[simp] lemma map_zero : (0 : polynomial α).map f = 0 := eval₂_zero _ _
@[simp] lemma map_add : (p + q).map f = p.map f + q.map f := eval₂_add _ _
@[simp] lemma map_one : (1 : polynomial α).map f = 1 := eval₂_one _ _
@[simp] lemma map_mul : (p * q).map f = p.map f * q.map f := eval₂_mul _ _
instance map.is_semiring_hom : is_semiring_hom (map f) := eval₂.is_semiring_hom _ _
lemma map_pow (n : ℕ) : (p ^ n).map f = p.map f ^ n := eval₂_pow _ _ _
lemma coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) :=
begin
rw [map, eval₂, coeff_sum],
conv_rhs { rw [← sum_C_mul_X_eq p, coeff_sum, finsupp.sum,
← finset.sum_hom f], },
refine finset.sum_congr rfl (λ x hx, _),
simp [function.comp, coeff_C_mul_X, is_semiring_hom.map_mul f],
split_ifs; simp [is_semiring_hom.map_zero f],
end
lemma map_map {γ : Type*} [comm_semiring γ] [decidable_eq γ] (g : β → γ) [is_semiring_hom g]
(p : polynomial α) : (p.map f).map g = p.map (λ x, g (f x)) :=
polynomial.ext.2 (by simp [coeff_map])
lemma eval₂_map {γ : Type*} [comm_semiring γ] (g : β → γ) [is_semiring_hom g] (x : γ) :
(p.map f).eval₂ g x = p.eval₂ (λ y, g (f y)) x :=
polynomial.induction_on p
(by simp)
(by simp [is_semiring_hom.map_add f] {contextual := tt})
(by simp [is_semiring_hom.map_mul f,
is_semiring_hom.map_pow f, pow_succ', (mul_assoc _ _ _).symm] {contextual := tt})
lemma eval_map (x : β) : (p.map f).eval x = p.eval₂ f x := eval₂_map _ _ _
@[simp] lemma map_id : p.map id = p := by simp [id, polynomial.ext, coeff_map]
end map
/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/
def leading_coeff (p : polynomial α) : α := coeff p (nat_degree p)
/-- a polynomial is `monic` if its leading coefficient is 1 -/
def monic (p : polynomial α) := leading_coeff p = (1 : α)
lemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl
instance monic.decidable : decidable (monic p) :=
by unfold monic; apply_instance
@[simp] lemma degree_zero : degree (0 : polynomial α) = ⊥ := rfl
@[simp] lemma nat_degree_zero : nat_degree (0 : polynomial α) = 0 := rfl
@[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) :=
show sup (ite (a = 0) ∅ {0}) some = 0, by rw if_neg ha; refl
lemma degree_C_le : degree (C a) ≤ (0 : with_bot ℕ) :=
by by_cases h : a = 0; [rw [h, C_0], rw [degree_C h]]; [exact bot_le, exact le_refl _]
lemma degree_one_le : degree (1 : polynomial α) ≤ (0 : with_bot ℕ) :=
by rw [← C_1]; exact degree_C_le
lemma degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h;
exact support_eq_empty.1 (max_eq_none.1 h),
λ h, h.symm ▸ rfl⟩
lemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) :=
let ⟨n, hn⟩ :=
classical.not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in
have hn : degree p = some n := not_not.1 hn,
by rw [nat_degree, hn]; refl
lemma nat_degree_eq_of_degree_eq_some {p : polynomial α} {n : ℕ}
(h : degree p = n) : nat_degree p = n :=
have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,
option.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n,
by rwa [← degree_eq_nat_degree hp0]
@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=
begin
by_cases hp : p = 0, { rw hp, exact bot_le },
rw [degree_eq_nat_degree hp],
exact le_refl _
end
lemma nat_degree_eq_of_degree_eq [comm_semiring β] [decidable_eq β] {q : polynomial β}
(h : degree p = degree q) : nat_degree p = nat_degree q :=
by unfold nat_degree; rw h
lemma le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : with_bot ℕ) ≤ degree p :=
show @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ),
from finset.le_sup (finsupp.mem_support_iff.2 h)
lemma le_nat_degree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ nat_degree p :=
begin
rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],
exact le_degree_of_ne_zero h,
{ assume h, subst h, exact h rfl }
end
lemma degree_le_degree (h : coeff q (nat_degree p) ≠ 0) : degree p ≤ degree q :=
begin
by_cases hp : p = 0,
{ rw hp, exact bot_le },
{ rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h }
end
@[simp] lemma nat_degree_C (a : α) : nat_degree (C a) = 0 :=
begin
by_cases ha : a = 0,
{ have : C a = 0, { rw [ha, C_0] },
rw [nat_degree, degree_eq_bot.2 this],
refl },
{ rw [nat_degree, degree_C ha], refl }
end
@[simp] lemma nat_degree_one : nat_degree (1 : polynomial α) = 0 := nat_degree_C 1
@[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n :=
by rw [← single_eq_C_mul_X, degree, support_single_ne_zero ha]; refl
lemma degree_monomial_le (n : ℕ) (a : α) : degree (C a * X ^ n) ≤ n :=
if h : a = 0 then by rw [h, C_0, zero_mul]; exact bot_le else le_of_eq (degree_monomial n h)
lemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=
not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))
lemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) : coeff p (nat_degree q) = 0 :=
coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)
lemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 :=
mt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))
lemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) :=
begin
refine polynomial.ext.2 (λ n, _),
cases n,
{ refl },
{ have : degree p < ↑(nat.succ n) := lt_of_le_of_lt h (with_bot.some_lt_some.2 (nat.succ_pos _)),
rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt this] }
end
lemma eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero (h ▸ le_refl _)
lemma degree_add_le (p q : polynomial α) : degree (p + q) ≤ max (degree p) (degree q) :=
calc degree (p + q) = ((p + q).support).sup some : rfl
... ≤ (p.support ∪ q.support).sup some : sup_mono support_add
... = p.support.sup some ⊔ q.support.sup some : sup_union
... = _ : with_bot.sup_eq_max _ _
@[simp] lemma leading_coeff_zero : leading_coeff (0 : polynomial α) = 0 := rfl
@[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 :=
⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1
(not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)),
λ h, h.symm ▸ leading_coeff_zero⟩
lemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = ⊥ :=
by rw [leading_coeff_eq_zero, degree_eq_bot]
lemma degree_add_eq_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q :=
le_antisymm (max_eq_right_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $
begin
rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, zero_add],
exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h)
end
lemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) :
degree (p + q) = max p.degree q.degree :=
le_antisymm (degree_add_le _ _) $
match lt_trichotomy (degree p) (degree q) with
| or.inl hlt :=
by rw [degree_add_eq_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_refl _
| or.inr (or.inl heq) :=
le_of_not_gt $
assume hlt : max (degree p) (degree q) > degree (p + q),
h $ show leading_coeff p + leading_coeff q = 0,
begin
rw [heq, max_self] at hlt,
rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add],
exact coeff_nat_degree_eq_zero_of_degree_lt hlt
end
| or.inr (or.inr hlt) :=
by rw [add_comm, degree_add_eq_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_refl _
end
lemma degree_erase_le (p : polynomial α) (n : ℕ) : degree (p.erase n) ≤ degree p :=
sup_mono (erase_subset _ _)
lemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p :=
lt_of_le_of_ne (degree_erase_le _ _) $
(degree_eq_nat_degree hp).symm ▸ λ h, not_mem_erase _ _ (mem_of_max h)
lemma degree_sum_le [decidable_eq β] (s : finset β) (f : β → polynomial α) :
degree (s.sum f) ≤ s.sup (λ b, degree (f b)) :=
finset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $
assume a s has ih,
calc degree (sum (insert a s) f) ≤ max (degree (f a)) (degree (s.sum f)) :
by rw sum_insert has; exact degree_add_le _ _
... ≤ _ : by rw [sup_insert, with_bot.sup_eq_max]; exact max_le_max (le_refl _) ih
lemma degree_mul_le (p q : polynomial α) : degree (p * q) ≤ degree p + degree q :=
calc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (coeff p i * a) * X ^ (i + j)))) :
by simp only [single_eq_C_mul_X.symm]; exact degree_sum_le _ _
... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) :
finset.sup_mono_fun (assume i hi, degree_sum_le _ _)
... ≤ degree p + degree q :
begin
refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_monomial_le _ _) _)),
rw [with_bot.coe_add],
rw mem_support_iff at ha hb,
exact add_le_add' (le_degree_of_ne_zero ha) (le_degree_of_ne_zero hb)
end
lemma degree_pow_le (p : polynomial α) : ∀ n, degree (p ^ n) ≤ add_monoid.smul n (degree p)
| 0 := by rw [pow_zero, add_monoid.zero_smul]; exact degree_one_le
| (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) :
by rw pow_succ; exact degree_mul_le _ _
... ≤ _ : by rw succ_smul; exact add_le_add' (le_refl _) (degree_pow_le _)
@[simp] lemma leading_coeff_monomial (a : α) (n : ℕ) : leading_coeff (C a * X ^ n) = a :=
begin
by_cases ha : a = 0,
{ simp only [ha, C_0, zero_mul, leading_coeff_zero] },
{ rw [leading_coeff, nat_degree, degree_monomial _ ha, ← single_eq_C_mul_X],
exact @finsupp.single_eq_same _ _ _ _ _ n a }
end
@[simp] lemma leading_coeff_C (a : α) : leading_coeff (C a) = a :=
suffices leading_coeff (C a * X^0) = a, by rwa [pow_zero, mul_one] at this,
leading_coeff_monomial a 0
@[simp] lemma leading_coeff_X : leading_coeff (X : polynomial α) = 1 :=
suffices leading_coeff (C (1:α) * X^1) = 1, by rwa [C_1, pow_one, one_mul] at this,
leading_coeff_monomial 1 1
@[simp] lemma monic_X : monic (X : polynomial α) := leading_coeff_X
@[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial α) = 1 :=
suffices leading_coeff (C (1:α) * X^0) = 1, by rwa [C_1, pow_zero, mul_one] at this,
leading_coeff_monomial 1 0
@[simp] lemma monic_one : monic (1 : polynomial α) := leading_coeff_C _
lemma leading_coeff_add_of_degree_lt (h : degree p < degree q) :
leading_coeff (p + q) = leading_coeff q :=
have coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h,
by simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_of_degree_lt h),
this, coeff_add, zero_add]
lemma leading_coeff_add_of_degree_eq (h : degree p = degree q)
(hlc : leading_coeff p + leading_coeff q ≠ 0) :
leading_coeff (p + q) = leading_coeff p + leading_coeff q :=
have nat_degree (p + q) = nat_degree p,
by apply nat_degree_eq_of_degree_eq; rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self],
by simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add]
@[simp] lemma coeff_mul_degree_add_degree (p q : polynomial α) :
coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q :=
calc coeff (p * q) (nat_degree p + nat_degree q) =
(range (nat_degree p + nat_degree q + 1)).sum
(λ k, coeff p k * coeff q (nat_degree p + nat_degree q - k)) : coeff_mul_left _ _ _
... = coeff p (nat_degree p) * coeff q (nat_degree p + nat_degree q - nat_degree p) :
finset.sum_eq_single _ (λ n hn₁ hn₂, (le_total n (nat_degree p)).elim
(λ h, have degree q < (nat_degree p + nat_degree q - n : ℕ),
from lt_of_le_of_lt degree_le_nat_degree
(with_bot.coe_lt_coe.2 (nat.lt_sub_left_iff_add_lt.2
(add_lt_add_right (lt_of_le_of_ne h hn₂) _))),
by simp [coeff_eq_zero_of_degree_lt this])
(λ h, have degree p < n, from lt_of_le_of_lt degree_le_nat_degree
(with_bot.coe_lt_coe.2 (lt_of_le_of_ne h hn₂.symm)),
by simp [coeff_eq_zero_of_degree_lt this]))
(λ h, false.elim (h (mem_range.2 (lt_of_le_of_lt (nat.le_add_right _ _) (nat.lt_succ_self _)))))
... = _ : by simp [leading_coeff, nat.add_sub_cancel_left]
lemma degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) :
degree (p * q) = degree p + degree q :=
have hp : p ≠ 0 := by refine mt _ h; exact λ hp, by rw [hp, leading_coeff_zero, zero_mul],
have hq : q ≠ 0 := by refine mt _ h; exact λ hq, by rw [hq, leading_coeff_zero, mul_zero],
le_antisymm (degree_mul_le _ _)
begin
rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq],
refine le_degree_of_ne_zero _,
rwa coeff_mul_degree_add_degree
end
lemma nat_degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) :
nat_degree (p * q) = nat_degree p + nat_degree q :=
have hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, zero_mul]),
have hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, mul_zero]),
have hpq : p * q ≠ 0 := λ hpq, by rw [← coeff_mul_degree_add_degree, hpq, coeff_zero] at h;
exact h rfl,
option.some_inj.1 (show (nat_degree (p * q) : with_bot ℕ) = nat_degree p + nat_degree q,
by rw [← degree_eq_nat_degree hpq, degree_mul_eq' h, degree_eq_nat_degree hp, degree_eq_nat_degree hq])
lemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
leading_coeff (p * q) = leading_coeff p * leading_coeff q :=
begin
unfold leading_coeff,
rw [nat_degree_mul_eq' h, coeff_mul_degree_add_degree],
refl
end
lemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 →
leading_coeff (p ^ n) = leading_coeff p ^ n :=
nat.rec_on n (by simp) $
λ n ih h,
have h₁ : leading_coeff p ^ n ≠ 0 :=
λ h₁, h $ by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← ih h₁] at h,
by rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁]
lemma degree_pow_eq' : ∀ {n}, leading_coeff p ^ n ≠ 0 →
degree (p ^ n) = add_monoid.smul n (degree p)
| 0 := λ h, by rw [pow_zero, ← C_1] at *;
rw [degree_C h, add_monoid.zero_smul]
| (n+1) := λ h,
have h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $
by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← leading_coeff_pow' h₁] at h,
by rw [pow_succ, degree_mul_eq' h₂, succ_smul, degree_pow_eq' h₁]
lemma nat_degree_pow_eq' {n : ℕ} (h : leading_coeff p ^ n ≠ 0) :
nat_degree (p ^ n) = n * nat_degree p :=
if hp0 : p = 0 then
if hn0 : n = 0 then by simp *
else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp
else
have hpn : p ^ n ≠ 0, from λ hpn0, have h1 : _ := h,
by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h;
exact h rfl,
option.some_inj.1 $ show (nat_degree (p ^ n) : with_bot ℕ) = (n * nat_degree p : ℕ),
by rw [← degree_eq_nat_degree hpn, degree_pow_eq' h, degree_eq_nat_degree hp0,
← with_bot.coe_smul]; simp
@[simp] lemma leading_coeff_X_pow : ∀ n : ℕ, leading_coeff ((X : polynomial α) ^ n) = 1
| 0 := by simp
| (n+1) :=
if h10 : (1 : α) = 0
then by rw [pow_succ, ← one_mul X, ← C_1, h10]; simp
else
have h : leading_coeff (X : polynomial α) * leading_coeff (X ^ n) ≠ 0,
by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul];
exact h10,
by rw [pow_succ, leading_coeff_mul' h, leading_coeff_X, leading_coeff_X_pow, one_mul]
lemma nat_degree_comp_le : nat_degree (p.comp q) ≤ nat_degree p * nat_degree q :=
if h0 : p.comp q = 0 then by rw [h0, nat_degree_zero]; exact nat.zero_le _
else with_bot.coe_le_coe.1 $
calc ↑(nat_degree (p.comp q)) = degree (p.comp q) : (degree_eq_nat_degree h0).symm
... ≤ _ : degree_sum_le _ _
... ≤ _ : sup_le (λ n hn,
calc degree (C (coeff p n) * q ^ n)
≤ degree (C (coeff p n)) + degree (q ^ n) : degree_mul_le _ _
... ≤ nat_degree (C (coeff p n)) + add_monoid.smul n (degree q) :
add_le_add' degree_le_nat_degree (degree_pow_le _ _)
... ≤ nat_degree (C (coeff p n)) + add_monoid.smul n (nat_degree q) :
add_le_add_left' (add_monoid.smul_le_smul_of_le_right
(@degree_le_nat_degree _ _ _ q) n)
... = (n * nat_degree q : ℕ) :
by rw [nat_degree_C, with_bot.coe_zero, zero_add, ← with_bot.coe_smul,
add_monoid.smul_eq_mul]; simp
... ≤ (nat_degree p * nat_degree q : ℕ) : with_bot.coe_le_coe.2 $
mul_le_mul_of_nonneg_right
(le_nat_degree_of_ne_zero (finsupp.mem_support_iff.1 hn))
(nat.zero_le _))
lemma degree_map_le [comm_semiring β] [decidable_eq β] (f : α → β) [is_semiring_hom f] :
degree (p.map f) ≤ degree p :=
if h : p.map f = 0 then by simp [h]
else begin
rw [degree_eq_nat_degree h],
refine le_degree_of_ne_zero (mt (congr_arg f) _),
rw [← coeff_map f, is_semiring_hom.map_zero f],
exact mt leading_coeff_eq_zero.1 h
end
lemma subsingleton_of_monic_zero (h : monic (0 : polynomial α)) :
(∀ p q : polynomial α, p = q) ∧ (∀ a b : α, a = b) :=
by rw [monic.def, leading_coeff_zero] at h;
exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero],
λ a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩
lemma degree_map_eq_of_leading_coeff_ne_zero [comm_semiring β] [decidable_eq β] (f : α → β)
[is_semiring_hom f] (hf : f (leading_coeff p) ≠ 0) : degree (p.map f) = degree p :=
le_antisymm (degree_map_le f) $
have hp0 : p ≠ 0, from λ hp0, by simpa [hp0, is_semiring_hom.map_zero f] using hf,
begin
rw [degree_eq_nat_degree hp0],
refine le_degree_of_ne_zero _,
rw [coeff_map], exact hf
end
lemma degree_map_eq_of_injective [comm_semiring β] [decidable_eq β] (f : α → β) [is_semiring_hom f]
(hf : function.injective f) : degree (p.map f) = degree p :=
if h : p = 0 then by simp [h]
else degree_map_eq_of_leading_coeff_ne_zero _
(by rw [← is_semiring_hom.map_zero f]; exact mt hf.eq_iff.1
(mt leading_coeff_eq_zero.1 h))
lemma monic_map [comm_semiring β] [decidable_eq β] (f : α → β)
[is_semiring_hom f] (hp : monic p) : monic (p.map f) :=
if h : (0 : β) = 1 then
by haveI := subsingleton_of_zero_eq_one β h;
exact subsingleton.elim _ _
else
have f (leading_coeff p) ≠ 0,
by rwa [show _ = _, from hp, is_semiring_hom.map_one f, ne.def, eq_comm],
by erw [monic, leading_coeff, nat_degree_eq_of_degree_eq
(degree_map_eq_of_leading_coeff_ne_zero f this), coeff_map,
← leading_coeff, show _ = _, from hp, is_semiring_hom.map_one f]
lemma zero_le_degree_iff {p : polynomial α} : 0 ≤ degree p ↔ p ≠ 0 :=
by rw [ne.def, ← degree_eq_bot];
cases degree p; exact dec_trivial
@[simp] lemma coeff_mul_X_zero (p : polynomial α) : coeff (p * X) 0 = 0 :=
by rw [coeff_mul_left, sum_range_succ]; simp
instance [subsingleton α] : subsingleton (polynomial α) :=
⟨λ _ _, polynomial.ext.2 (λ _, subsingleton.elim _ _)⟩
lemma ne_zero_of_monic_of_zero_ne_one (hp : monic p) (h : (0 : α) ≠ 1) :
p ≠ 0 := mt (congr_arg leading_coeff) $ by rw [monic.def.1 hp, leading_coeff_zero]; cc
lemma eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) :
p = C (p.coeff 1) * X + C (p.coeff 0) :=
polynomial.ext.2 (λ n, nat.cases_on n (by simp)
(λ n, nat.cases_on n (by simp [coeff_C])
(λ m, have degree p < m.succ.succ, from lt_of_le_of_lt h dec_trivial,
by simp [coeff_eq_zero_of_degree_lt this, coeff_C, nat.succ_ne_zero, coeff_X,
nat.succ_inj', @eq_comm ℕ 0])))
lemma eq_X_add_C_of_degree_eq_one (h : degree p = 1) :
p = C (p.leading_coeff) * X + C (p.coeff 0) :=
(eq_X_add_C_of_degree_le_one (show degree p ≤ 1, from h ▸ le_refl _)).trans
(by simp [leading_coeff, nat_degree_eq_of_degree_eq_some h])
theorem degree_C_mul_X_pow_le (r : α) (n : ℕ) : degree (C r * X^n) ≤ n :=
begin
rw [← single_eq_C_mul_X],
refine finset.sup_le (λ b hb, _),
rw list.eq_of_mem_singleton (finsupp.support_single_subset hb),
exact le_refl _
end
theorem degree_X_pow_le (n : ℕ) : degree (X^n : polynomial α) ≤ n :=
by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le (1:α) n
theorem degree_X_le : degree (X : polynomial α) ≤ 1 :=
by simpa only [C_1, one_mul, pow_one] using degree_C_mul_X_pow_le (1:α) 1
theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : monic p :=
decidable.by_cases
(assume H : degree p < n, @subsingleton.elim _ (subsingleton_of_zero_eq_one α $
H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _)
(assume H : ¬degree p < n, by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H])
theorem monic_X_pow_add {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) + p) :=
have H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)),
monic_of_degree_le (n+1)
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero])
theorem monic_X_add_C (x : α) : monic (X + C x) :=
pow_one (X : polynomial α) ▸ monic_X_pow_add degree_C_le
theorem degree_le_iff_coeff_zero (f : polynomial α) (n : with_bot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 :=
⟨λ (H : finset.sup (f.support) some ≤ n) m (Hm : n < (m : with_bot ℕ)), decidable.of_not_not $ λ H4,
have H1 : m ∉ f.support,
from λ H2, not_lt_of_ge ((finset.sup_le_iff.1 H) m H2 : ((m : with_bot ℕ) ≤ n)) Hm,
H1 $ (finsupp.mem_support_to_fun f m).2 H4,
λ H, finset.sup_le $ λ b Hb, decidable.of_not_not $ λ Hn,
(finsupp.mem_support_to_fun f b).1 Hb $ H b $ lt_of_not_ge Hn⟩
theorem nat_degree_le_of_degree_le {p : polynomial α} {n : ℕ}
(H : degree p ≤ n) : nat_degree p ≤ n :=
show option.get_or_else (degree p) 0 ≤ n, from match degree p, H with
| none, H := zero_le _
| (some d), H := with_bot.coe_le_coe.1 H
end
theorem leading_coeff_mul_X_pow {p : polynomial α} {n : ℕ} :
leading_coeff (p * X ^ n) = leading_coeff p :=
decidable.by_cases
(assume H : leading_coeff p = 0, by rw [H, leading_coeff_eq_zero.1 H, zero_mul, leading_coeff_zero])
(assume H : leading_coeff p ≠ 0,
by rw [leading_coeff_mul', leading_coeff_X_pow, mul_one];
rwa [leading_coeff_X_pow, mul_one])
end comm_semiring
section comm_ring
variables [comm_ring α] [decidable_eq α] {p q : polynomial α}
instance : comm_ring (polynomial α) := finsupp.to_comm_ring
instance : has_scalar α (polynomial α) := finsupp.to_has_scalar
-- TODO if this becomes a semimodule then the below lemma could be proved for semimodules
instance : module α (polynomial α) := finsupp.to_module ℕ α
-- TODO -- this is OK for semimodules
@[simp] lemma coeff_smul (p : polynomial α) (r : α) (n : ℕ) :
coeff (r • p) n = r * coeff p n := finsupp.smul_apply
-- TODO -- this is OK for semimodules
lemma C_mul' (a : α) (f : polynomial α) : C a * f = a • f :=
ext.2 $ λ n, coeff_C_mul f
variable (α)
def lcoeff (n : ℕ) : polynomial α →ₗ α :=
{ to_fun := λ f, coeff f n,
add := λ f g, coeff_add f g n,
smul := λ r p, coeff_smul p r n }
variable {α}
@[simp] lemma lcoeff_apply (n : ℕ) (f : polynomial α) : lcoeff α n f = coeff f n := rfl
instance C.is_ring_hom : is_ring_hom (@C α _ _) := by apply is_ring_hom.of_semiring
@[simp] lemma C_neg : C (-a) = -C a := is_ring_hom.map_neg C
@[simp] lemma C_sub : C (a - b) = C a - C b := is_ring_hom.map_sub C
instance eval₂.is_ring_hom {β} [comm_ring β]
(f : α → β) [is_ring_hom f] {x : β} : is_ring_hom (eval₂ f x) :=
by apply is_ring_hom.of_semiring
instance eval.is_ring_hom {x : α} : is_ring_hom (eval x) := eval₂.is_ring_hom _
instance map.is_ring_hom {β} [comm_ring β] [decidable_eq β]
(f : α → β) [is_ring_hom f] : is_ring_hom (map f) :=
eval₂.is_ring_hom (C ∘ f)
@[simp] lemma map_sub {β} [comm_ring β] [decidable_eq β]
(f : α → β) [is_ring_hom f] : (p - q).map f = p.map f - q.map f := is_ring_hom.map_sub _
@[simp] lemma map_neg {β} [comm_ring β] [decidable_eq β]
(f : α → β) [is_ring_hom f] : (-p).map f = -(p.map f) := is_ring_hom.map_neg _
@[simp] lemma degree_neg (p : polynomial α) : degree (-p) = degree p :=
by unfold degree; rw support_neg
@[simp] lemma coeff_neg (p : polynomial α) (n : ℕ) : coeff (-p) n = -coeff p n := rfl
@[simp] lemma coeff_sub (p q : polynomial α) (n : ℕ) : coeff (p - q) n = coeff p n - coeff q n := rfl
@[simp] lemma eval_neg (p : polynomial α) (x : α) : (-p).eval x = -p.eval x :=
is_ring_hom.map_neg _
@[simp] lemma eval_sub (p q : polynomial α) (x : α) : (p - q).eval x = p.eval x - q.eval x :=
is_ring_hom.map_sub _
lemma degree_sub_lt (hd : degree p = degree q)
(hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) :
degree (p - q) < degree p :=
have hp : single (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p :=
finsupp.single_add_erase,
have hq : single (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q :=
finsupp.single_add_erase,
have hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd,
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0),
calc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) :
by conv {to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]}
... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q))
: degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _
... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
instance : has_well_founded (polynomial α) := ⟨_, degree_lt_wf⟩
lemma ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : monic q) : q ≠ 0
| h := begin
rw [h, monic.def, leading_coeff_zero] at hq,
rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp,
exact hp rfl
end
lemma div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : monic q) :
degree (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) < degree p :=
have hp : leading_coeff p ≠ 0 := mt leading_coeff_eq_zero.1 h.2,
have hpq : leading_coeff (C (leading_coeff p) * X ^ (nat_degree p - nat_degree q)) *
leading_coeff q ≠ 0,
by rwa [leading_coeff_monomial, monic.def.1 hq, mul_one],
if h0 : p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q = 0
then h0.symm ▸ (lt_of_not_ge $ mt le_bot_iff.1 (mt degree_eq_bot.1 h.2))
else
have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic h.2 hq,
have hlt : nat_degree q ≤ nat_degree p := with_bot.coe_le_coe.1
(by rw [← degree_eq_nat_degree h.2, ← degree_eq_nat_degree hq0];
exact h.1),
degree_sub_lt
(by rw [degree_mul_eq' hpq, degree_monomial _ hp, degree_eq_nat_degree h.2,
degree_eq_nat_degree hq0, ← with_bot.coe_add, nat.sub_add_cancel hlt])
h.2
(by rw [leading_coeff_mul' hpq, leading_coeff_monomial, monic.def.1 hq, mul_one])
def div_mod_by_monic_aux : Π (p : polynomial α) {q : polynomial α},
monic q → polynomial α × polynomial α
| p := λ q hq, if h : degree q ≤ degree p ∧ p ≠ 0 then
let z := C (leading_coeff p) * X^(nat_degree p - nat_degree q) in
have wf : _ := div_wf_lemma h hq,
let dm := div_mod_by_monic_aux (p - z * q) hq in
⟨z + dm.1, dm.2⟩
else ⟨0, p⟩
using_well_founded {dec_tac := tactic.assumption}
/-- `div_by_monic` gives the quotient of `p` by a monic polynomial `q`. -/
def div_by_monic (p q : polynomial α) : polynomial α :=
if hq : monic q then (div_mod_by_monic_aux p hq).1 else 0
/-- `mod_by_monic` gives the remainder of `p` by a monic polynomial `q`. -/
def mod_by_monic (p q : polynomial α) : polynomial α :=
if hq : monic q then (div_mod_by_monic_aux p hq).2 else p
infixl ` /ₘ ` : 70 := div_by_monic
infixl ` %ₘ ` : 70 := mod_by_monic
lemma degree_mod_by_monic_lt : ∀ (p : polynomial α) {q : polynomial α} (hq : monic q)
(hq0 : q ≠ 0), degree (p %ₘ q) < degree q
| p := λ q hq hq0,
if h : degree q ≤ degree p ∧ p ≠ 0 then
have wf : _ := div_wf_lemma ⟨h.1, h.2⟩ hq,
have degree ((p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) %ₘ q) < degree q :=
degree_mod_by_monic_lt (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q)
hq hq0,
begin
unfold mod_by_monic at this ⊢,
unfold div_mod_by_monic_aux,
rw dif_pos hq at this ⊢,
rw if_pos h,
exact this
end
else
or.cases_on (not_and_distrib.1 h) begin
unfold mod_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_neg h],
exact lt_of_not_ge,
end
begin
assume hp,
unfold mod_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_neg h, not_not.1 hp],
exact lt_of_le_of_ne bot_le
(ne.symm (mt degree_eq_bot.1 hq0)),
end
using_well_founded {dec_tac := tactic.assumption}
lemma mod_by_monic_eq_sub_mul_div : ∀ (p : polynomial α) {q : polynomial α} (hq : monic q),
p %ₘ q = p - q * (p /ₘ q)
| p := λ q hq,
if h : degree q ≤ degree p ∧ p ≠ 0 then
have wf : _ := div_wf_lemma h hq,
have ih : _ := mod_by_monic_eq_sub_mul_div
(p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) hq,
begin
unfold mod_by_monic div_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_pos h],
rw [mod_by_monic, dif_pos hq] at ih,
refine ih.trans _,
unfold div_by_monic,
rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub, mul_comm]
end
else
begin
unfold mod_by_monic div_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero]
end
using_well_founded {dec_tac := tactic.assumption}
lemma mod_by_monic_add_div (p : polynomial α) {q : polynomial α} (hq : monic q) :
p %ₘ q + q * (p /ₘ q) = p := eq_sub_iff_add_eq.1 (mod_by_monic_eq_sub_mul_div p hq)
@[simp] lemma zero_mod_by_monic (p : polynomial α) : 0 %ₘ p = 0 :=
begin
unfold mod_by_monic div_mod_by_monic_aux,
by_cases hp : monic p,
{ rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] },
{ rw [dif_neg hp] }
end
@[simp] lemma zero_div_by_monic (p : polynomial α) : 0 /ₘ p = 0 :=
begin
unfold div_by_monic div_mod_by_monic_aux,
by_cases hp : monic p,
{ rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] },
{ rw [dif_neg hp] }
end
@[simp] lemma mod_by_monic_zero (p : polynomial α) : p %ₘ 0 = p :=
if h : monic (0 : polynomial α) then (subsingleton_of_monic_zero h).1 _ _ else
by unfold mod_by_monic div_mod_by_monic_aux; rw dif_neg h
@[simp] lemma div_by_monic_zero (p : polynomial α) : p /ₘ 0 = 0 :=
if h : monic (0 : polynomial α) then (subsingleton_of_monic_zero h).1 _ _ else
by unfold div_by_monic div_mod_by_monic_aux; rw dif_neg h
lemma div_by_monic_eq_of_not_monic (p : polynomial α) (hq : ¬monic q) : p /ₘ q = 0 := dif_neg hq
lemma mod_by_monic_eq_of_not_monic (p : polynomial α) (hq : ¬monic q) : p %ₘ q = p := dif_neg hq
lemma mod_by_monic_eq_self_iff (hq : monic q) (hq0 : q ≠ 0) : p %ₘ q = p ↔ degree p < degree q :=
⟨λ h, h ▸ degree_mod_by_monic_lt _ hq hq0,
λ h, have ¬ degree q ≤ degree p := not_le_of_gt h,
by unfold mod_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩
lemma div_by_monic_eq_zero_iff (hq : monic q) (hq0 : q ≠ 0) : p /ₘ q = 0 ↔ degree p < degree q :=
⟨λ h, by have := mod_by_monic_add_div p hq;
rwa [h, mul_zero, add_zero, mod_by_monic_eq_self_iff hq hq0] at this,
λ h, have ¬ degree q ≤ degree p := not_le_of_gt h,
by unfold div_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩
lemma degree_add_div_by_monic (hq : monic q) (h : degree q ≤ degree p) :
degree q + degree (p /ₘ q) = degree p :=
if hq0 : q = 0 then
have ∀ (p : polynomial α), p = 0,
from λ p, (@subsingleton_of_monic_zero α _ _ (hq0 ▸ hq)).1 _ _,
by rw [this (p /ₘ q), this p, this q]; refl
else
have hdiv0 : p /ₘ q ≠ 0 := by rwa [(≠), div_by_monic_eq_zero_iff hq hq0, not_lt],
have hlc : leading_coeff q * leading_coeff (p /ₘ q) ≠ 0 :=
by rwa [monic.def.1 hq, one_mul, (≠), leading_coeff_eq_zero],
have hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) :=
calc degree (p %ₘ q) < degree q : degree_mod_by_monic_lt _ hq hq0
... ≤ _ : by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0,
degree_eq_nat_degree hdiv0, ← with_bot.coe_add, with_bot.coe_le_coe];
exact nat.le_add_right _ _,
calc degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) : eq.symm (degree_mul_eq' hlc)
... = degree (p %ₘ q + q * (p /ₘ q)) : (degree_add_eq_of_degree_lt hmod).symm
... = _ : congr_arg _ (mod_by_monic_add_div _ hq)
lemma degree_div_by_monic_le (p q : polynomial α) : degree (p /ₘ q) ≤ degree p :=
if hp0 : p = 0 then by simp only [hp0, zero_div_by_monic, le_refl]
else if hq : monic q then
have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq,
if h : degree q ≤ degree p
then by rw [← degree_add_div_by_monic hq h, degree_eq_nat_degree hq0,
degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 (not_lt.2 h))];
exact with_bot.coe_le_coe.2 (nat.le_add_left _ _)
else
by unfold div_by_monic div_mod_by_monic_aux;
simp only [dif_pos hq, h, false_and, if_false, degree_zero, bot_le]
else (div_by_monic_eq_of_not_monic p hq).symm ▸ bot_le
lemma degree_div_by_monic_lt (p : polynomial α) {q : polynomial α} (hq : monic q)
(hp0 : p ≠ 0) (h0q : 0 < degree q) : degree (p /ₘ q) < degree p :=
have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq,
if hpq : degree p < degree q
then begin
rw [(div_by_monic_eq_zero_iff hq hq0).2 hpq, degree_eq_nat_degree hp0],
exact with_bot.bot_lt_some _
end
else begin
rw [← degree_add_div_by_monic hq (not_lt.1 hpq), degree_eq_nat_degree hq0,
degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 hpq)],
exact with_bot.coe_lt_coe.2 (nat.lt_add_of_pos_left
(with_bot.coe_lt_coe.1 $ (degree_eq_nat_degree hq0) ▸ h0q))
end
lemma div_mod_by_monic_unique {f g} (q r : polynomial α) (hg : monic g)
(h : r + g * q = f ∧ degree r < degree g) : f /ₘ g = q ∧ f %ₘ g = r :=
if hg0 : g = 0 then by split; exact (subsingleton_of_monic_zero
(hg0 ▸ hg : monic (0 : polynomial α))).1 _ _
else
have h₁ : r - f %ₘ g = -g * (q - f /ₘ g),
from eq_of_sub_eq_zero
(by rw [← sub_eq_zero_of_eq (h.1.trans (mod_by_monic_add_div f hg).symm)];
simp [mul_add, mul_comm]),
have h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g)),
by simp [h₁],
have h₄ : degree (r - f %ₘ g) < degree g,
from calc degree (r - f %ₘ g) ≤ max (degree r) (degree (-(f %ₘ g))) :
degree_add_le _ _
... < degree g : max_lt_iff.2 ⟨h.2, by rw degree_neg; exact degree_mod_by_monic_lt _ hg hg0⟩,
have h₅ : q - (f /ₘ g) = 0,
from by_contradiction
(λ hqf, not_le_of_gt h₄ $
calc degree g ≤ degree g + degree (q - f /ₘ g) :
by erw [degree_eq_nat_degree hg0, degree_eq_nat_degree hqf,
with_bot.coe_le_coe];
exact nat.le_add_right _ _
... = degree (r - f %ₘ g) :
by rw [h₂, degree_mul_eq']; simpa [monic.def.1 hg]),
⟨eq.symm $ eq_of_sub_eq_zero h₅,
eq.symm $ eq_of_sub_eq_zero $ by simpa [h₅] using h₁⟩
lemma map_mod_div_by_monic [comm_ring β] [decidable_eq β] (f : α → β) [is_semiring_hom f] (hq : monic q) :
(p /ₘ q).map f = p.map f /ₘ q.map f ∧ (p %ₘ q).map f = p.map f %ₘ q.map f :=
if h01 : (0 : β) = 1 then by haveI := subsingleton_of_zero_eq_one β h01;
exact ⟨subsingleton.elim _ _, subsingleton.elim _ _⟩
else
have h01α : (0 : α) ≠ 1, from mt (congr_arg f)
(by rwa [is_semiring_hom.map_one f, is_semiring_hom.map_zero f]),
have map f p /ₘ map f q = map f (p /ₘ q) ∧ map f p %ₘ map f q = map f (p %ₘ q),
from (div_mod_by_monic_unique ((p /ₘ q).map f) _ (monic_map f hq)
⟨eq.symm $ by rw [← map_mul, ← map_add, mod_by_monic_add_div _ hq],
calc _ ≤ degree (p %ₘ q) : degree_map_le _
... < degree q : degree_mod_by_monic_lt _ hq
$ (ne_zero_of_monic_of_zero_ne_one hq h01α)
... = _ : eq.symm $ degree_map_eq_of_leading_coeff_ne_zero _
(by rw [monic.def.1 hq, is_semiring_hom.map_one f]; exact ne.symm h01)⟩),
⟨this.1.symm, this.2.symm⟩
lemma map_div_by_monic [comm_ring β] [decidable_eq β] (f : α → β) [is_semiring_hom f] (hq : monic q) :
(p /ₘ q).map f = p.map f /ₘ q.map f :=
(map_mod_div_by_monic f hq).1
lemma map_mod_by_monic [comm_ring β] [decidable_eq β] (f : α → β) [is_semiring_hom f] (hq : monic q) :
(p %ₘ q).map f = p.map f %ₘ q.map f :=
(map_mod_div_by_monic f hq).2
lemma dvd_iff_mod_by_monic_eq_zero (hq : monic q) : p %ₘ q = 0 ↔ q ∣ p :=
⟨λ h, by rw [← mod_by_monic_add_div p hq, h, zero_add];
exact dvd_mul_right _ _,
λ h, if hq0 : q = 0 then by rw hq0 at hq;
exact (subsingleton_of_monic_zero hq).1 _ _
else
let ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h in
by_contradiction (λ hpq0,
have hmod : p %ₘ q = q * (r - p /ₘ q) :=
by rw [mod_by_monic_eq_sub_mul_div _ hq, mul_sub, ← hr],
have degree (q * (r - p /ₘ q)) < degree q :=
hmod ▸ degree_mod_by_monic_lt _ hq hq0,
have hrpq0 : leading_coeff (r - p /ₘ q) ≠ 0 :=
λ h, hpq0 $ leading_coeff_eq_zero.1
(by rw [hmod, leading_coeff_eq_zero.1 h, mul_zero, leading_coeff_zero]),
have hlc : leading_coeff q * leading_coeff (r - p /ₘ q) ≠ 0 :=
by rwa [monic.def.1 hq, one_mul],
by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0,
degree_eq_nat_degree (mt leading_coeff_eq_zero.2 hrpq0)] at this;
exact not_lt_of_ge (nat.le_add_right _ _) (with_bot.some_lt_some.1 this))⟩
@[simp] lemma mod_by_monic_one (p : polynomial α) : p %ₘ 1 = 0 :=
(dvd_iff_mod_by_monic_eq_zero monic_one).2 (one_dvd _)
@[simp] lemma div_by_monic_one (p : polynomial α) : p /ₘ 1 = p :=
by conv_rhs { rw [← mod_by_monic_add_div p monic_one] }; simp
lemma degree_pos_of_root (hp : p ≠ 0) (h : is_root p a) : 0 < degree p :=
lt_of_not_ge $ λ hlt, begin
have := eq_C_of_degree_le_zero hlt,
rw [is_root, this, eval_C] at h,
exact hp (finsupp.ext (λ n, show coeff p n = 0, from
nat.cases_on n h (λ _, coeff_eq_zero_of_degree_lt (lt_of_le_of_lt hlt
(with_bot.coe_lt_coe.2 (nat.succ_pos _)))))),
end
theorem monic_X_sub_C (x : α) : monic (X - C x) :=
by simpa only [C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) - p) :=
monic_X_pow_add ((degree_neg p).symm ▸ H)
theorem degree_mod_by_monic_le (p : polynomial α) {q : polynomial α}
(hq : monic q) : degree (p %ₘ q) ≤ degree q :=
decidable.by_cases
(assume H : q = 0, by rw [monic, H, leading_coeff_zero] at hq;
have : (0:polynomial α) = 1 := (by rw [← C_0, ← C_1, hq]);
rw [eq_zero_of_zero_eq_one _ this (p %ₘ q), eq_zero_of_zero_eq_one _ this q]; exact le_refl _)
(assume H : q ≠ 0, le_of_lt $ degree_mod_by_monic_lt _ hq H)
lemma root_X_sub_C : is_root (X - C a) b ↔ a = b :=
by rw [is_root.def, eval_sub, eval_X, eval_C, sub_eq_zero_iff_eq, eq_comm]
end comm_ring
section nonzero_comm_ring
variables [nonzero_comm_ring α] [decidable_eq α] {p q : polynomial α}
instance : nonzero_comm_ring (polynomial α) :=
{ zero_ne_one := λ (h : (0 : polynomial α) = 1),
@zero_ne_one α _ $
calc (0 : α) = eval 0 0 : eval_zero.symm
... = eval 0 1 : congr_arg _ h
... = 1 : eval_C,
..polynomial.comm_ring }
@[simp] lemma degree_one : degree (1 : polynomial α) = (0 : with_bot ℕ) :=
degree_C (show (1 : α) ≠ 0, from zero_ne_one.symm)
@[simp] lemma degree_X : degree (X : polynomial α) = 1 :=
begin
unfold X degree single finsupp.support,
rw if_neg (zero_ne_one).symm,
refl
end
lemma X_ne_zero : (X : polynomial α) ≠ 0 :=
mt (congr_arg (λ p, coeff p 1)) (by simp)
@[simp] lemma degree_X_sub_C (a : α) : degree (X - C a) = 1 :=
begin
rw [sub_eq_add_neg, add_comm, ← @degree_X α],
by_cases ha : a = 0,
{ simp only [ha, C_0, neg_zero, zero_add] },
exact degree_add_eq_of_degree_lt (by rw [degree_X, degree_neg, degree_C ha]; exact dec_trivial)
end
@[simp] lemma degree_X_pow : ∀ (n : ℕ), degree ((X : polynomial α) ^ n) = n
| 0 := by simp only [pow_zero, degree_one]; refl
| (n+1) :=
have h : leading_coeff (X : polynomial α) * leading_coeff (X ^ n) ≠ 0,
by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul];
exact zero_ne_one.symm,
by rw [pow_succ, degree_mul_eq' h, degree_X, degree_X_pow, add_comm]; refl
lemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : α) :
degree ((X : polynomial α) ^ n - C a) = n :=
have degree (-C a) < degree ((X : polynomial α) ^ n),
from calc degree (-C a) ≤ 0 : by rw degree_neg; exact degree_C_le
... < degree ((X : polynomial α) ^ n) : by rwa [degree_X_pow];
exact with_bot.coe_lt_coe.2 hn,
by rw [sub_eq_add_neg, add_comm, degree_add_eq_of_degree_lt this, degree_X_pow]
lemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : α) :
(X : polynomial α) ^ n - C a ≠ 0 :=
mt degree_eq_bot.2 (show degree ((X : polynomial α) ^ n - C a) ≠ ⊥,
by rw degree_X_pow_sub_C hn; exact dec_trivial)
@[simp] lemma not_monic_zero : ¬monic (0 : polynomial α) :=
by simpa only [monic, leading_coeff_zero] using zero_ne_one
lemma ne_zero_of_monic (h : monic p) : p ≠ 0 :=
λ h₁, @not_monic_zero α _ _ (h₁ ▸ h)
end nonzero_comm_ring
section comm_ring
variables [comm_ring α] [decidable_eq α] {p q : polynomial α}
@[simp] lemma mod_by_monic_X_sub_C_eq_C_eval (p : polynomial α) (a : α) : p %ₘ (X - C a) = C (p.eval a) :=
if h0 : (0 : α) = 1 then by letI := subsingleton_of_zero_eq_one α h0; exact subsingleton.elim _ _
else
by letI : nonzero_comm_ring α := {zero_ne_one := h0, ..show comm_ring α, from infer_instance}; exact
have h : (p %ₘ (X - C a)).eval a = p.eval a :=
by rw [mod_by_monic_eq_sub_mul_div _ (monic_X_sub_C a), eval_sub, eval_mul,
eval_sub, eval_X, eval_C, sub_self, zero_mul, sub_zero],
have degree (p %ₘ (X - C a)) < 1 :=
degree_X_sub_C a ▸ degree_mod_by_monic_lt p (monic_X_sub_C a) ((degree_X_sub_C a).symm ▸
ne_zero_of_monic (monic_X_sub_C _)),
have degree (p %ₘ (X - C a)) ≤ 0 :=
begin
cases (degree (p %ₘ (X - C a))),
{ exact bot_le },
{ exact with_bot.some_le_some.2 (nat.le_of_lt_succ (with_bot.some_lt_some.1 this)) }
end,
begin
rw [eq_C_of_degree_le_zero this, eval_C] at h,
rw [eq_C_of_degree_le_zero this, h]
end
lemma mul_div_by_monic_eq_iff_is_root : (X - C a) * (p /ₘ (X - C a)) = p ↔ is_root p a :=
⟨λ h, by rw [← h, is_root.def, eval_mul, eval_sub, eval_X, eval_C, sub_self, zero_mul],
λ h : p.eval a = 0,
by conv {to_rhs, rw ← mod_by_monic_add_div p (monic_X_sub_C a)};
rw [mod_by_monic_X_sub_C_eq_C_eval, h, C_0, zero_add]⟩
lemma dvd_iff_is_root : (X - C a) ∣ p ↔ is_root p a :=
⟨λ h, by rwa [← dvd_iff_mod_by_monic_eq_zero (monic_X_sub_C _),
mod_by_monic_X_sub_C_eq_C_eval, ← C_0, C_inj] at h,
λ h, ⟨(p /ₘ (X - C a)), by rw mul_div_by_monic_eq_iff_is_root.2 h⟩⟩
lemma mod_by_monic_X (p : polynomial α) : p %ₘ X = C (p.eval 0) :=
by rw [← mod_by_monic_X_sub_C_eq_C_eval, C_0, sub_zero]
end comm_ring
section integral_domain
variables [integral_domain α] [decidable_eq α] {p q : polynomial α}
@[simp] lemma degree_mul_eq : degree (p * q) = degree p + degree q :=
if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add]
else if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot]
else degree_mul_eq' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)
(mt leading_coeff_eq_zero.1 hq0)
@[simp] lemma degree_pow_eq (p : polynomial α) (n : ℕ) :
degree (p ^ n) = add_monoid.smul n (degree p) :=
by induction n; [simp only [pow_zero, degree_one, add_monoid.zero_smul],
simp only [*, pow_succ, succ_smul, degree_mul_eq]]
@[simp] lemma leading_coeff_mul (p q : polynomial α) : leading_coeff (p * q) =
leading_coeff p * leading_coeff q :=
begin
by_cases hp : p = 0,
{ simp only [hp, zero_mul, leading_coeff_zero] },
{ by_cases hq : q = 0,
{ simp only [hq, mul_zero, leading_coeff_zero] },
{ rw [leading_coeff_mul'],
exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } }
end
@[simp] lemma leading_coeff_pow (p : polynomial α) (n : ℕ) :
leading_coeff (p ^ n) = leading_coeff p ^ n :=
by induction n; [simp only [pow_zero, leading_coeff_one],
simp only [*, pow_succ, leading_coeff_mul]]
instance : integral_domain (polynomial α) :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h, begin
have : leading_coeff 0 = leading_coeff a * leading_coeff b := h ▸ leading_coeff_mul a b,
rw [leading_coeff_zero, eq_comm] at this,
rw [← leading_coeff_eq_zero, ← leading_coeff_eq_zero],
exact eq_zero_or_eq_zero_of_mul_eq_zero this
end,
..polynomial.nonzero_comm_ring }
lemma nat_degree_mul_eq (hp : p ≠ 0) (hq : q ≠ 0) : nat_degree (p * q) =
nat_degree p + nat_degree q :=
by rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree (mul_ne_zero hp hq),
with_bot.coe_add, ← degree_eq_nat_degree hp,
← degree_eq_nat_degree hq, degree_mul_eq]
@[simp] lemma nat_degree_pow_eq (p : polynomial α) (n : ℕ) :
nat_degree (p ^ n) = n * nat_degree p :=
if hp0 : p = 0
then if hn0 : n = 0 then by simp [hp0, hn0]
else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp
else nat_degree_pow_eq'
(by rw [← leading_coeff_pow, ne.def, leading_coeff_eq_zero]; exact pow_ne_zero _ hp0)
lemma root_or_root_of_root_mul (h : is_root (p * q) a) : is_root p a ∨ is_root q a :=
by rw [is_root, eval_mul] at h;
exact eq_zero_or_eq_zero_of_mul_eq_zero h
lemma degree_le_mul_left (p : polynomial α) (hq : q ≠ 0) : degree p ≤ degree (p * q) :=
if hp : p = 0 then by simp only [hp, zero_mul, le_refl]
else by rw [degree_mul_eq, degree_eq_nat_degree hp,
degree_eq_nat_degree hq];
exact with_bot.coe_le_coe.2 (nat.le_add_right _ _)
lemma exists_finset_roots : ∀ {p : polynomial α} (hp : p ≠ 0),
∃ s : finset α, (s.card : with_bot ℕ) ≤ degree p ∧ ∀ x, x ∈ s ↔ is_root p x
| p := λ hp, by haveI := classical.prop_decidable (∃ x, is_root p x); exact
if h : ∃ x, is_root p x
then
let ⟨x, hx⟩ := h in
have hpd : 0 < degree p := degree_pos_of_root hp hx,
have hd0 : p /ₘ (X - C x) ≠ 0 :=
λ h, by rw [← mul_div_by_monic_eq_iff_is_root.2 hx, h, mul_zero] at hp; exact hp rfl,
have wf : degree (p /ₘ _) < degree p :=
degree_div_by_monic_lt _ (monic_X_sub_C x) hp
((degree_X_sub_C x).symm ▸ dec_trivial),
let ⟨t, htd, htr⟩ := @exists_finset_roots (p /ₘ (X - C x)) hd0 in
have hdeg : degree (X - C x) ≤ degree p := begin
rw [degree_X_sub_C, degree_eq_nat_degree hp],
rw degree_eq_nat_degree hp at hpd,
exact with_bot.coe_le_coe.2 (with_bot.coe_lt_coe.1 hpd)
end,
have hdiv0 : p /ₘ (X - C x) ≠ 0 := mt (div_by_monic_eq_zero_iff (monic_X_sub_C x)
(ne_zero_of_monic (monic_X_sub_C x))).1 $ not_lt.2 hdeg,
⟨insert x t, calc (card (insert x t) : with_bot ℕ) ≤ card t + 1 :
with_bot.coe_le_coe.2 $ finset.card_insert_le _ _
... ≤ degree p :
by rw [← degree_add_div_by_monic (monic_X_sub_C x) hdeg,
degree_X_sub_C, add_comm];
exact add_le_add' (le_refl (1 : with_bot ℕ)) htd,
begin
assume y,
rw [mem_insert, htr, eq_comm, ← root_X_sub_C],
conv {to_rhs, rw ← mul_div_by_monic_eq_iff_is_root.2 hx},
exact ⟨λ h, or.cases_on h (root_mul_right_of_is_root _) (root_mul_left_of_is_root _),
root_or_root_of_root_mul⟩
end⟩
else
⟨∅, (degree_eq_nat_degree hp).symm ▸ with_bot.coe_le_coe.2 (nat.zero_le _),
by simpa only [not_mem_empty, false_iff, not_exists] using h⟩
using_well_founded {dec_tac := tactic.assumption}
/-- `roots p` noncomputably gives a finset containing all the roots of `p` -/
noncomputable def roots (p : polynomial α) : finset α :=
if h : p = 0 then ∅ else classical.some (exists_finset_roots h)
lemma card_roots (hp0 : p ≠ 0) : ((roots p).card : with_bot ℕ) ≤ degree p :=
begin
unfold roots,
rw dif_neg hp0,
exact (classical.some_spec (exists_finset_roots hp0)).1
end
@[simp] lemma mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ is_root p a :=
by unfold roots; rw dif_neg hp; exact (classical.some_spec (exists_finset_roots hp)).2 _
lemma card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : α) :
(roots ((X : polynomial α) ^ n - C a)).card ≤ n :=
with_bot.coe_le_coe.1 $
calc ((roots ((X : polynomial α) ^ n - C a)).card : with_bot ℕ)
≤ degree ((X : polynomial α) ^ n - C a) : card_roots (X_pow_sub_C_ne_zero hn a)
... = n : degree_X_pow_sub_C hn a
/-- `nth_roots n a` noncomputably returns the solutions to `x ^ n = a`-/
noncomputable def nth_roots {α : Type*} [integral_domain α] (n : ℕ) (a : α) : finset α :=
by letI := classical.prop_decidable; exact
roots ((X : polynomial α) ^ n - C a)
@[simp] lemma mem_nth_roots {α : Type*} [integral_domain α] {n : ℕ} (hn : 0 < n) {a x : α} :
x ∈ nth_roots n a ↔ x ^ n = a :=
by letI := classical.prop_decidable;
rw [nth_roots, mem_roots (X_pow_sub_C_ne_zero hn a),
is_root.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero_iff_eq]
lemma card_nth_roots {α : Type*} [integral_domain α] (n : ℕ) (a : α) :
(nth_roots n a).card ≤ n :=
by letI := classical.prop_decidable; exact
if hn : n = 0
then if h : (X : polynomial α) ^ n - C a = 0
then by simp only [nat.zero_le, nth_roots, roots, h, dif_pos rfl, card_empty]
else with_bot.coe_le_coe.1 (le_trans (card_roots h)
(by rw [hn, pow_zero, ← @C_1 α _ _, ← is_ring_hom.map_sub (@C α _ _)];
exact degree_C_le))
else by rw [← with_bot.coe_le_coe, ← degree_X_pow_sub_C (nat.pos_of_ne_zero hn) a];
exact card_roots (X_pow_sub_C_ne_zero (nat.pos_of_ne_zero hn) a)
lemma coeff_comp_degree_mul_degree (hqd0 : nat_degree q ≠ 0) :
coeff (p.comp q) (nat_degree p * nat_degree q) =
leading_coeff p * leading_coeff q ^ nat_degree p :=
if hp0 : p = 0 then by simp [hp0] else
calc coeff (p.comp q) (nat_degree p * nat_degree q)
= p.sum (λ n a, coeff (C a * q ^ n) (nat_degree p * nat_degree q)) :
by rw [comp, eval₂, coeff_sum]
... = coeff (C (leading_coeff p) * q ^ nat_degree p) (nat_degree p * nat_degree q) :
finset.sum_eq_single _
begin
assume b hbs hbp,
have hq0 : q ≠ 0, from λ hq0, hqd0 (by rw [hq0, nat_degree_zero]),
have : coeff p b ≠ 0, rwa [← apply_eq_coeff, ← finsupp.mem_support_iff],
dsimp [apply_eq_coeff],
refine coeff_eq_zero_of_degree_lt _,
rw [degree_mul_eq, degree_C this, degree_pow_eq, zero_add, degree_eq_nat_degree hq0,
← with_bot.coe_smul, add_monoid.smul_eq_mul, with_bot.coe_lt_coe, nat.cast_id],
exact (mul_lt_mul_right (nat.pos_of_ne_zero hqd0)).2
(lt_of_le_of_ne (with_bot.coe_le_coe.1 (by rw ← degree_eq_nat_degree hp0; exact le_sup hbs)) hbp)
end
(by rw [finsupp.mem_support_iff, apply_eq_coeff, ← leading_coeff, ne.def, leading_coeff_eq_zero,
classical.not_not]; simp {contextual := tt})
... = _ :
have coeff (q ^ nat_degree p) (nat_degree p * nat_degree q) = leading_coeff (q ^ nat_degree p),
by rw [leading_coeff, nat_degree_pow_eq],
by rw [coeff_C_mul, this, leading_coeff_pow]
lemma nat_degree_comp : nat_degree (p.comp q) = nat_degree p * nat_degree q :=
le_antisymm nat_degree_comp_le
(if hp0 : p = 0 then by rw [hp0, zero_comp, nat_degree_zero, zero_mul]
else if hqd0 : nat_degree q = 0
then have degree q ≤ 0, by rw [← with_bot.coe_zero, ← hqd0]; exact degree_le_nat_degree,
by rw [eq_C_of_degree_le_zero this]; simp
else le_nat_degree_of_ne_zero $
have hq0 : q ≠ 0, from λ hq0, hqd0 $ by rw [hq0, nat_degree_zero],
calc coeff (p.comp q) (nat_degree p * nat_degree q)
= leading_coeff p * leading_coeff q ^ nat_degree p :
coeff_comp_degree_mul_degree hqd0
... ≠ 0 : mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)
(pow_ne_zero _ (mt leading_coeff_eq_zero.1 hq0)))
lemma leading_coeff_comp (hq : nat_degree q ≠ 0): leading_coeff (p.comp q) =
leading_coeff p * leading_coeff q ^ nat_degree p :=
by rw [← coeff_comp_degree_mul_degree hq, ← nat_degree_comp]; refl
lemma degree_eq_zero_of_is_unit (h : is_unit p) : degree p = 0 :=
let ⟨q, hq⟩ := is_unit_iff_dvd_one.1 h in
have hp0 : p ≠ 0, from λ hp0, by simpa [hp0] using hq,
have hq0 : q ≠ 0, from λ hp0, by simpa [hp0] using hq,
have nat_degree (1 : polynomial α) = nat_degree (p * q),
from congr_arg _ hq,
by rw [nat_degree_one, nat_degree_mul_eq hp0 hq0, eq_comm,
add_eq_zero_iff, ← with_bot.coe_eq_coe,
← degree_eq_nat_degree hp0] at this;
exact this.1
@[simp] lemma degree_coe_units (u : units (polynomial α)) :
degree (u : polynomial α) = 0 :=
degree_eq_zero_of_is_unit ⟨u, rfl⟩
@[simp] lemma nat_degree_coe_units (u : units (polynomial α)) :
nat_degree (u : polynomial α) = 0 :=
nat_degree_eq_of_degree_eq_some (degree_coe_units u)
lemma coeff_coe_units_zero_ne_zero (u : units (polynomial α)) :
coeff (u : polynomial α) 0 ≠ 0 :=
begin
conv in (0) {rw [← nat_degree_coe_units u]},
rw [← leading_coeff, ne.def, leading_coeff_eq_zero],
exact units.coe_ne_zero _
end
lemma degree_eq_degree_of_associated (h : associated p q) : degree p = degree q :=
let ⟨u, hu⟩ := h in by simp [hu.symm]
end integral_domain
section field
variables [discrete_field α] {p q : polynomial α}
instance : vector_space α (polynomial α) :=
{ ..finsupp.to_module ℕ α }
lemma is_unit_iff_degree_eq_zero : is_unit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_is_unit,
λ h, have degree p ≤ 0, by simp [*, le_refl],
have hc : coeff p 0 ≠ 0, from λ hc,
by rw [eq_C_of_degree_le_zero this, hc] at h;
simpa using h,
is_unit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, begin
conv in p { rw eq_C_of_degree_le_zero this },
rw [← C_mul, _root_.mul_inv_cancel hc, C_1]
end⟩⟩
lemma degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬is_unit p) :
0 < degree p :=
lt_of_not_ge (λ h, by rw [eq_C_of_degree_le_zero h] at hp0 hp;
exact hp ⟨units.map C (units.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))), rfl⟩)
lemma irreducible_of_degree_eq_one (hp1 : degree p = 1) : irreducible p :=
⟨mt is_unit_iff_dvd_one.1 (λ ⟨q, hq⟩,
absurd (congr_arg degree hq) (λ h,
have degree q = 0, by rw [degree_one, degree_mul_eq, hp1, eq_comm,
nat.with_bot.add_eq_zero_iff] at h; exact h.2,
by simp [degree_mul_eq, this, degree_one, hp1] at h;
exact absurd h dec_trivial)),
λ q r hpqr, begin
have := congr_arg degree hpqr,
rw [hp1, degree_mul_eq, eq_comm, nat.with_bot.add_eq_one_iff] at this,
rw [is_unit_iff_degree_eq_zero, is_unit_iff_degree_eq_zero]; tautology
end⟩
lemma monic_mul_leading_coeff_inv (h : p ≠ 0) :
monic (p * C (leading_coeff p)⁻¹) :=
by rw [monic, leading_coeff_mul, leading_coeff_C,
mul_inv_cancel (show leading_coeff p ≠ 0, from mt leading_coeff_eq_zero.1 h)]
lemma degree_mul_leading_coeff_inv (p : polynomial α) (h : q ≠ 0) :
degree (p * C (leading_coeff q)⁻¹) = degree p :=
have h₁ : (leading_coeff q)⁻¹ ≠ 0 :=
inv_ne_zero (mt leading_coeff_eq_zero.1 h),
by rw [degree_mul_eq, degree_C h₁, add_zero]
def div (p q : polynomial α) :=
C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹))
def mod (p q : polynomial α) :=
p %ₘ (q * C (leading_coeff q)⁻¹)
private lemma quotient_mul_add_remainder_eq_aux (p q : polynomial α) :
q * div p q + mod p q = p :=
if h : q = 0 then by simp only [h, zero_mul, mod, mod_by_monic_zero, zero_add]
else begin
conv {to_rhs, rw ← mod_by_monic_add_div p (monic_mul_leading_coeff_inv h)},
rw [div, mod, add_comm, mul_assoc]
end
private lemma remainder_lt_aux (p : polynomial α) (hq : q ≠ 0) :
degree (mod p q) < degree q :=
by rw ← degree_mul_leading_coeff_inv q hq; exact
degree_mod_by_monic_lt p (monic_mul_leading_coeff_inv hq)
(mul_ne_zero hq (mt leading_coeff_eq_zero.2 (by rw leading_coeff_C;
exact inv_ne_zero (mt leading_coeff_eq_zero.1 hq))))
instance : has_div (polynomial α) := ⟨div⟩
instance : has_mod (polynomial α) := ⟨mod⟩
lemma div_def : p / q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)) := rfl
lemma mod_def : p % q = p %ₘ (q * C (leading_coeff q)⁻¹) := rfl
lemma mod_by_monic_eq_mod (p : polynomial α) (hq : monic q) : p %ₘ q = p % q :=
show p %ₘ q = p %ₘ (q * C (leading_coeff q)⁻¹), by simp only [monic.def.1 hq, inv_one, mul_one, C_1]
lemma div_by_monic_eq_div (p : polynomial α) (hq : monic q) : p /ₘ q = p / q :=
show p /ₘ q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)),
by simp only [monic.def.1 hq, inv_one, C_1, one_mul, mul_one]
lemma mod_X_sub_C_eq_C_eval (p : polynomial α) (a : α) : p % (X - C a) = C (p.eval a) :=
mod_by_monic_eq_mod p (monic_X_sub_C a) ▸ mod_by_monic_X_sub_C_eq_C_eval _ _
lemma mul_div_eq_iff_is_root : (X - C a) * (p / (X - C a)) = p ↔ is_root p a :=
div_by_monic_eq_div p (monic_X_sub_C a) ▸ mul_div_by_monic_eq_iff_is_root
instance : euclidean_domain (polynomial α) :=
{ quotient := (/),
quotient_zero := by simp [div_def],
remainder := (%),
r := _,
r_well_founded := degree_lt_wf,
quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux,
remainder_lt := λ p q hq, remainder_lt_aux _ hq,
mul_left_not_lt := λ p q hq, not_lt_of_ge (degree_le_mul_left _ hq) }
lemma mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=
⟨λ h, h ▸ euclidean_domain.mod_lt _ hq0,
λ h, have ¬degree (q * C (leading_coeff q)⁻¹) ≤ degree p :=
not_le_of_gt $ by rwa degree_mul_leading_coeff_inv q hq0,
begin
rw [mod_def, mod_by_monic, dif_pos (monic_mul_leading_coeff_inv hq0)],
unfold div_mod_by_monic_aux,
simp only [this, false_and, if_false]
end⟩
lemma div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=
⟨λ h, by have := euclidean_domain.div_add_mod p q;
rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,
λ h, have hlt : degree p < degree (q * C (leading_coeff q)⁻¹),
by rwa degree_mul_leading_coeff_inv q hq0,
have hm : monic (q * C (leading_coeff q)⁻¹) := monic_mul_leading_coeff_inv hq0,
by rw [div_def, (div_by_monic_eq_zero_iff hm (ne_zero_of_monic hm)).2 hlt, mul_zero]⟩
lemma degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :
degree q + degree (p / q) = degree p :=
have degree (p % q) < degree (q * (p / q)) :=
calc degree (p % q) < degree q : euclidean_domain.mod_lt _ hq0
... ≤ _ : degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)),
by conv {to_rhs, rw [← euclidean_domain.div_add_mod p q, add_comm,
degree_add_eq_of_degree_lt this, degree_mul_eq]}
lemma degree_div_le (p q : polynomial α) : degree (p / q) ≤ degree p :=
if hq : q = 0 then by simp [hq]
else by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq];
exact degree_div_by_monic_le _ _
lemma degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p :=
have hq0 : q ≠ 0, from λ hq0, by simpa [hq0] using hq,
by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq0];
exact degree_div_by_monic_lt _ (monic_mul_leading_coeff_inv hq0) hp
(by rw degree_mul_leading_coeff_inv _ hq0; exact hq)
@[simp] lemma degree_map [discrete_field β] (p : polynomial α) (f : α → β) [is_field_hom f] :
degree (p.map f) = degree p :=
degree_map_eq_of_injective _ (is_field_hom.injective f)
@[simp] lemma nat_degree_map [discrete_field β] (f : α → β) [is_field_hom f] :
nat_degree (p.map f) = nat_degree p :=
nat_degree_eq_of_degree_eq (degree_map _ f)
@[simp] lemma leading_coeff_map [discrete_field β] (f : α → β) [is_field_hom f] :
leading_coeff (p.map f) = f (leading_coeff p) :=
by simp [leading_coeff, coeff_map f]
lemma map_div [discrete_field β] (f : α → β) [is_field_hom f] :
(p / q).map f = p.map f / q.map f :=
if hq0 : q = 0 then by simp [hq0]
else
by rw [div_def, div_def, map_mul, map_div_by_monic f (monic_mul_leading_coeff_inv hq0)];
simp [is_field_hom.map_inv f, leading_coeff, coeff_map f]
lemma map_mod [discrete_field β] (f : α → β) [is_field_hom f] :
(p % q).map f = p.map f % q.map f :=
if hq0 : q = 0 then by simp [hq0]
else by rw [mod_def, mod_def, leading_coeff_map f, ← is_field_hom.map_inv f, ← map_C f,
← map_mul f, map_mod_by_monic f (monic_mul_leading_coeff_inv hq0)]
@[simp] lemma map_eq_zero [discrete_field β] (f : α → β) [is_field_hom f] :
p.map f = 0 ↔ p = 0 :=
by simp [polynomial.ext, is_field_hom.map_eq_zero f, coeff_map]
lemma exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, is_root p x :=
⟨-(p.coeff 0 / p.coeff 1),
have p.coeff 1 ≠ 0,
by rw ← nat_degree_eq_of_degree_eq_some h;
exact mt leading_coeff_eq_zero.1 (λ h0, by simpa [h0] using h),
by conv in p { rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1, by rw h; exact le_refl _)] };
simp [is_root, mul_div_cancel' _ this]⟩
lemma coeff_inv_units (u : units (polynomial α)) (n : ℕ) :
((↑u : polynomial α).coeff n)⁻¹ = ((↑u⁻¹ : polynomial α).coeff n) :=
begin
rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹),
coeff_C, coeff_C, inv_eq_one_div],
split_ifs,
{ rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero,
coeff_zero_eq_eval_zero, ← eval_mul, ← units.coe_mul, inv_mul_self];
simp },
{ simp }
end
instance : normalization_domain (polynomial α) :=
{ norm_unit := λ p, if hp0 : p = 0 then 1
else ⟨C p.leading_coeff⁻¹, C p.leading_coeff,
by rw [← C_mul, inv_mul_cancel, C_1];
exact mt leading_coeff_eq_zero.1 hp0,
by rw [← C_mul, mul_inv_cancel, C_1];
exact mt leading_coeff_eq_zero.1 hp0,⟩,
norm_unit_zero := dif_pos rfl,
norm_unit_mul := λ p q hp0 hq0, begin
rw [dif_neg hp0, dif_neg hq0, dif_neg (mul_ne_zero hp0 hq0)],
apply units.ext,
show C (leading_coeff (p * q))⁻¹ = C (leading_coeff p)⁻¹ * C (leading_coeff q)⁻¹,
rw [leading_coeff_mul, mul_inv', C_mul, mul_comm]
end,
norm_unit_coe_units := λ u,
have hu : degree ↑u⁻¹ = 0, from degree_eq_zero_of_is_unit ⟨u⁻¹, rfl⟩,
begin
apply units.ext,
rw [dif_neg (units.coe_ne_zero u)],
conv_rhs {rw eq_C_of_degree_eq_zero hu},
refine C_inj.2 _,
rw [← nat_degree_eq_of_degree_eq_some hu, leading_coeff,
coeff_inv_units],
simp
end,
..polynomial.integral_domain }
lemma monic_mul_norm_unit (hp0 : p ≠ 0) : monic (p * norm_unit p) :=
show leading_coeff (p * ↑(dite _ _ _)) = 1,
by rw dif_neg hp0; exact monic_mul_leading_coeff_inv hp0
lemma coe_norm_unit (hp : p ≠ 0) : (norm_unit p : polynomial α) = C p.leading_coeff⁻¹ :=
show ↑(dite _ _ _) = C p.leading_coeff⁻¹, by rw dif_neg hp; refl
end field
section derivative
variables [comm_semiring α] [decidable_eq α]
/-- `derivative p` formal derivative of the polynomial `p` -/
def derivative (p : polynomial α) : polynomial α := p.sum (λn a, C (a * n) * X^(n - 1))
lemma coeff_derivative (p : polynomial α) (n : ℕ) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) :=
begin
rw [derivative],
simp only [coeff_X_pow, coeff_sum, coeff_C_mul],
rw [finsupp.sum, finset.sum_eq_single (n + 1), apply_eq_coeff],
{ rw [if_pos (nat.add_sub_cancel _ _).symm, mul_one, nat.cast_add, nat.cast_one] },
{ assume b, cases b,
{ intros, rw [nat.cast_zero, mul_zero, zero_mul] },
{ intros _ H, rw [nat.succ_sub_one b, if_neg (mt (congr_arg nat.succ) H.symm), mul_zero] } },
{ intro H, rw [not_mem_support_iff.1 H, zero_mul, zero_mul] }
end
@[simp] lemma derivative_zero : derivative (0 : polynomial α) = 0 :=
finsupp.sum_zero_index
lemma derivative_monomial (a : α) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) :=
by rw [← single_eq_C_mul_X, ← single_eq_C_mul_X, derivative, sum_single_index, single_eq_C_mul_X];
simp only [zero_mul, C_0]; refl
@[simp] lemma derivative_C {a : α} : derivative (C a) = 0 :=
suffices derivative (C a * X^0) = C (a * 0:α) * X ^ 0,
by simpa only [mul_one, zero_mul, C_0, mul_zero, pow_zero],
derivative_monomial a 0
@[simp] lemma derivative_X : derivative (X : polynomial α) = 1 :=
suffices derivative (C (1:α) * X^1) = C (1 * (1:ℕ)) * X ^ 0,
by simpa only [mul_one, one_mul, C_1, pow_one, nat.cast_one, pow_zero],
derivative_monomial 1 1
@[simp] lemma derivative_one : derivative (1 : polynomial α) = 0 :=
derivative_C
@[simp] lemma derivative_add {f g : polynomial α} :
derivative (f + g) = derivative f + derivative g :=
by refine finsupp.sum_add_index _ _; intros;
simp only [add_mul, zero_mul, C_0, C_add, C_mul]
instance : is_add_monoid_hom (derivative : polynomial α → polynomial α) :=
by refine_struct {..}; simp
@[simp] lemma derivative_sum {s : finset β} {f : β → polynomial α} :
derivative (s.sum f) = s.sum (λb, derivative (f b)) :=
(finset.sum_hom derivative).symm
@[simp] lemma derivative_mul {f g : polynomial α} :
derivative (f * g) = derivative f * g + f * derivative g :=
calc derivative (f * g) = f.sum (λn a, g.sum (λm b, C ((a * b) * (n + m : ℕ)) * X^((n + m) - 1))) :
begin
transitivity, exact derivative_sum,
transitivity, { apply finset.sum_congr rfl, assume x hx, exact derivative_sum },
apply finset.sum_congr rfl, assume n hn, apply finset.sum_congr rfl, assume m hm,
transitivity,
{ apply congr_arg, exact single_eq_C_mul_X },
exact derivative_monomial _ _
end
... = f.sum (λn a, g.sum (λm b,
(C (a * n) * X^(n - 1)) * (C b * X^m) + (C a * X^n) * (C (b * m) * X^(m - 1)))) :
sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm,
by simp only [nat.cast_add, mul_add, add_mul, C_add, C_mul];
cases n; simp only [nat.succ_sub_succ, pow_zero];
cases m; simp only [nat.cast_zero, C_0, nat.succ_sub_succ, zero_mul, mul_zero,
nat.sub_zero, pow_zero, pow_add, one_mul, pow_succ, mul_comm, mul_left_comm]
... = derivative f * g + f * derivative g :
begin
conv { to_rhs, congr,
{ rw [← sum_C_mul_X_eq g] },
{ rw [← sum_C_mul_X_eq f] } },
unfold derivative finsupp.sum,
simp only [sum_add_distrib, finset.mul_sum, finset.sum_mul]
end
lemma derivative_eval (p : polynomial α) (x : α) : p.derivative.eval x = p.sum (λ n a, (a * n)*x^(n-1)) :=
by simp [derivative, eval_sum, eval_pow]
end derivative
section domain
variables [integral_domain α] [decidable_eq α]
lemma mem_support_derivative [char_zero α] (p : polynomial α) (n : ℕ) :
n ∈ (derivative p).support ↔ n + 1 ∈ p.support :=
suffices (¬(coeff p (n + 1) = 0 ∨ ((n + 1:ℕ) : α) = 0)) ↔ coeff p (n + 1) ≠ 0,
by simpa only [coeff_derivative, apply_eq_coeff, mem_support_iff, ne.def, mul_eq_zero],
by rw [nat.cast_eq_zero]; simp only [nat.succ_ne_zero, or_false]
@[simp] lemma degree_derivative_eq [char_zero α] (p : polynomial α) (hp : 0 < nat_degree p) :
degree (derivative p) = (nat_degree p - 1 : ℕ) :=
le_antisymm
(le_trans (degree_sum_le _ _) $ sup_le $ assume n hn,
have n ≤ nat_degree p, begin
rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],
{ refine le_degree_of_ne_zero _, simpa only [mem_support_iff] using hn },
{ assume h, simpa only [h, support_zero] using hn }
end,
le_trans (degree_monomial_le _ _) $ with_bot.coe_le_coe.2 $ nat.sub_le_sub_right this _)
begin
refine le_sup _,
rw [mem_support_derivative, nat.sub_add_cancel, mem_support_iff],
{ show ¬ leading_coeff p = 0,
rw [leading_coeff_eq_zero],
assume h, rw [h, nat_degree_zero] at hp,
exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp), },
exact hp
end
end domain
section identities
/- @TODO: pow_add_expansion and pow_sub_pow_factor are not specific to polynomials.
These belong somewhere else. But not in group_power because they depend on tactic.ring
Maybe use data.nat.choose to prove it.
-/
def pow_add_expansion {α : Type*} [comm_semiring α] (x y : α) : ∀ (n : ℕ),
{k // (x + y)^n = x^n + n*x^(n-1)*y + k * y^2}
| 0 := ⟨0, by simp⟩
| 1 := ⟨0, by simp⟩
| (n+2) :=
begin
cases pow_add_expansion (n+1) with z hz,
rw [_root_.pow_succ, hz],
existsi (x*z + (n+1)*x^n+z*y),
simp [_root_.pow_succ],
ring -- expensive!
end
variables [comm_ring α] [decidable_eq α]
private def poly_binom_aux1 (x y : α) (e : ℕ) (a : α) :
{k : α // a * (x + y)^e = a * (x^e + e*x^(e-1)*y + k*y^2)} :=
begin
existsi (pow_add_expansion x y e).val,
congr,
apply (pow_add_expansion _ _ _).property
end
private lemma poly_binom_aux2 (f : polynomial α) (x y : α) :
f.eval (x + y) = f.sum (λ e a, a * (x^e + e*x^(e-1)*y + (poly_binom_aux1 x y e a).val*y^2)) :=
begin
unfold eval eval₂, congr, ext,
apply (poly_binom_aux1 x y _ _).property
end
private lemma poly_binom_aux3 (f : polynomial α) (x y : α) : f.eval (x + y) =
f.sum (λ e a, a * x^e) +
f.sum (λ e a, (a * e * x^(e-1)) * y) +
f.sum (λ e a, (a *(poly_binom_aux1 x y e a).val)*y^2) :=
by rw poly_binom_aux2; simp [left_distrib, finsupp.sum_add, mul_assoc]
def binom_expansion (f : polynomial α) (x y : α) :
{k : α // f.eval (x + y) = f.eval x + (f.derivative.eval x) * y + k * y^2} :=
begin
existsi f.sum (λ e a, a *((poly_binom_aux1 x y e a).val)),
rw poly_binom_aux3,
congr,
{ rw derivative_eval, symmetry,
apply finsupp.sum_mul },
{ symmetry, apply finsupp.sum_mul }
end
def pow_sub_pow_factor (x y : α) : Π {i : ℕ},{z : α // x^i - y^i = z*(x - y)}
| 0 := ⟨0, by simp⟩ --sorry --false.elim $ not_lt_of_ge h zero_lt_one
| 1 := ⟨1, by simp⟩
| (k+2) :=
begin
cases pow_sub_pow_factor with z hz,
existsi z*x + y^(k+1),
rw [_root_.pow_succ x, _root_.pow_succ y, ←sub_add_sub_cancel (x*x^(k+1)) (x*y^(k+1)),
←mul_sub x, hz],
simp only [_root_.pow_succ],
ring
end
def eval_sub_factor (f : polynomial α) (x y : α) :
{z : α // f.eval x - f.eval y = z*(x - y)} :=
begin
existsi f.sum (λ a b, b * (pow_sub_pow_factor x y).val),
unfold eval eval₂,
rw [←finsupp.sum_sub],
have : finsupp.sum f (λ (a : ℕ) (b : α), b * (pow_sub_pow_factor x y).val) * (x - y) =
finsupp.sum f (λ (a : ℕ) (b : α), b * (pow_sub_pow_factor x y).val * (x - y)),
{ apply finsupp.sum_mul },
rw this,
congr, ext e a,
rw [mul_assoc, ←(pow_sub_pow_factor x y).property],
simp [left_distrib]
end
end identities
end polynomial
|
9be3c9af33dd01856d103ea341119548ebd8fa8a | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /13_More_Tactics.org.9.lean | a6515b5a1cc1da00ac4a892bcd28dd3d3d705fce | [] | 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 | 92 | lean | import standard
variables p q : Prop
example (Hp : p) (Hnp : ¬ p) : q :=
by contradiction
|
a9b5f49f31f87ccf86ca3fab5bdf73dc90fc6a03 | c86b74188c4b7a462728b1abd659ab4e5828dd61 | /src/Init/Control/Option.lean | 7cde967b1c99b39c990a212df064815f58834578 | [
"Apache-2.0"
] | permissive | cwb96/lean4 | 75e1f92f1ba98bbaa6b34da644b3dfab2ce7bf89 | b48831cda76e64f13dd1c0edde7ba5fb172ed57a | refs/heads/master | 1,686,347,881,407 | 1,624,483,842,000 | 1,624,483,842,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,159 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
prelude
import Init.Data.Option.Basic
import Init.Control.Basic
import Init.Control.Except
universes u v
instance {α} : ToBool (Option α) := ⟨Option.toBool⟩
def OptionT (m : Type u → Type v) (α : Type u) : Type v :=
m (Option α)
@[inline] def OptionT.run {m : Type u → Type v} {α : Type u} (x : OptionT m α) : m (Option α) :=
x
namespace OptionT
variable {m : Type u → Type v} [Monad m] {α β : Type u}
protected def mk (x : m (Option α)) : OptionT m α :=
x
@[inline] protected def bind (x : OptionT m α) (f : α → OptionT m β) : OptionT m β := OptionT.mk do
match (← x) with
| some a => f a
| none => pure none
@[inline] protected def pure (a : α) : OptionT m α := OptionT.mk do
pure (some a)
instance : Monad (OptionT m) where
pure := OptionT.pure
bind := OptionT.bind
@[inline] protected def orElse (x : OptionT m α) (y : OptionT m α) : OptionT m α := OptionT.mk do
match (← x) with
| some a => pure (some a)
| _ => y
@[inline] protected def fail : OptionT m α := OptionT.mk do
pure none
instance : Alternative (OptionT m) where
failure := OptionT.fail
orElse := OptionT.orElse
@[inline] protected def lift (x : m α) : OptionT m α := OptionT.mk do
return some (← x)
instance : MonadLift m (OptionT m) := ⟨OptionT.lift⟩
instance : MonadFunctor m (OptionT m) := ⟨fun f x => f x⟩
@[inline] protected def tryCatch (x : OptionT m α) (handle : Unit → OptionT m α) : OptionT m α := OptionT.mk do
let some a ← x | handle ()
pure a
instance : MonadExceptOf Unit (OptionT m) where
throw := fun _ => OptionT.fail
tryCatch := OptionT.tryCatch
instance (ε : Type u) [Monad m] [MonadExceptOf ε m] : MonadExceptOf ε (OptionT m) where
throw e := OptionT.mk <| throwThe ε e
tryCatch x handle := OptionT.mk <| tryCatchThe ε x handle
end OptionT
abbrev OptionM (α : Type u) := OptionT Id α
abbrev OptionM.run (x : OptionM α) : Option α :=
x
|
7733bd089054ddf69a30ea7d93d11bd4cee3baf0 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/ftree.lean | e4fb30acb9fcc829b2a9cfd67d04d3d2cfe27e97 | [
"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 | 682 | lean | import data.list
namespace explicit
inductive ftree.{l₁ l₂} (A : Type.{l₁}) (B : Type.{l₂}) : Type.{max 1 l₁ l₂} :=
leafa : A → ftree A B,
leafb : B → ftree A B,
node : (A → ftree A B) → (B → ftree A B) → ftree A B
end explicit
namespace implicit
inductive ftree (A : Type) (B : Type) : Type :=
leafa : ftree A B,
node : (A → B → ftree A B) → (B → ftree A B) → ftree A B
set_option pp.universes true
check ftree
end implicit
namespace implicit2
inductive ftree (A : Type) (B : Type) : Type :=
leafa : A → ftree A B,
leafb : B → ftree A B,
node : (list A → ftree A B) → (B → ftree A B) → ftree A B
check ftree
end implicit2
|
38d59b798d7a570cd8a9e4af6f65018edfeaabb7 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/1315b.lean | fbde76806ce60bb0af0dfecb59b7361f196864c6 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 1,059 | lean | open nat
def k : ℕ := 0
def fails : Π (n : ℕ) (m : ℕ), ℕ
| 0 m := 0
| (succ n) m :=
match k with
| 0 := 0
| (succ i) :=
let val := m+1 in
match fails n val with
| 0 := 0
| (succ l) := 0
end
end
def test (k : ℕ) : Π (n : ℕ) (m : ℕ), ℕ
| 0 m := 0
| (succ n) m :=
match k with
| 0 := 1
| (succ i) :=
let val := m+1 in
match test n val with
| 0 := 2
| (succ l) := 3
end
end
example (k m : ℕ) : test k 0 m = 0 :=
rfl
example (m n : ℕ) : test 0 (succ n) m = 1 :=
rfl
example (k m : ℕ) : test (succ k) 1 m = 2 :=
rfl
example (k m : ℕ) : test (succ k) 2 m = 3 :=
rfl
example (k m : ℕ) : test (succ k) 3 m = 3 :=
rfl
open tactic
run_cmd do
t ← infer_type `(test._match_2),
trace t,
tactic.interactive.guard_expr_eq t ```(nat → nat)
example (k m n : ℕ) : test (succ k) (succ (succ n)) m = 3 :=
begin
revert m,
induction n with n',
{intro, reflexivity},
{intro,
simp [test] {zeta := ff}, dsimp, simp [ih_1],
simp [nat.bit1_eq_succ_bit0, test]}
end
|
be7c0794cd37398f571c95dbd76d86f64bf90ddd | cf39355caa609c0f33405126beee2739aa3cb77e | /leanpkg/leanpkg/toml.lean | 341183b71453bdd7d77735b1b605140dbd80d397 | [
"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 | 3,814 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Gabriel Ebner
-/
import data.buffer.parser
-- I'd like to contribute a new naming convention:
-- CamelCase for non-terminals.
def join (sep : string) : list string → string
| [x] := x
| [] := ""
| (x::xs) := x ++ sep ++ join xs
namespace toml
inductive value : Type
| str : string → value
| nat : ℕ → value
| bool : bool → value
| table : list (string × value) → value
namespace value
private def escapec : char → string
| '\"' := "\\\""
| '\t' := "\\t"
| '\n' := "\\n"
| '\\' := "\\\\"
| c := string.singleton c
private def escape (s : string) : string :=
s.fold "" (λ s c, s ++ escapec c)
/- TODO(Leo): has_to_string -/
private mutual def repr_core, repr_pairs
with repr_core : value → string
| (value.str s) := "\"" ++ escape s ++ "\""
| (value.nat n) := repr n
| (value.bool tt) := "true"
| (value.bool ff) := "false"
| (value.table cs) := "{" ++ repr_pairs cs ++ "}"
with repr_pairs : list (string × value) → string
| [] := ""
| [(k, v)] := k ++ " = " ++ repr_core v
| ((k, v)::kvs) := k ++ " = " ++ repr_core v ++ ", " ++ repr_pairs kvs
protected def repr : ∀ (v : value), string
| (table cs) := join "\n" $ do (h, c) ← cs,
match c with
| table ds :=
["[" ++ h ++ "]\n" ++
join "" (do (k, v) ← ds,
[k ++ " = " ++ repr_core v ++ "\n"])]
| _ := ["<error> " ++ repr_core c]
end
| v := repr_core v
/- TODO(Leo): has_to_string -/
instance : has_repr value :=
⟨value.repr⟩
def lookup : value → string → option value
| (value.table cs) k :=
match cs.filter (λ c : string × value, c.fst = k) with
| [] := none
| (k,v) ::_ := some v
end
| _ _ := none
end value
open parser
def Comment : parser unit :=
ch '#' >> many' (sat (≠ '#')) >> optional (ch '\n') >> eps
def Ws : parser unit :=
decorate_error "<whitespace>" $
many' $ one_of' " \t\x0d\n".to_list <|> Comment
def tok (s : string) := str s >> Ws
def StringChar : parser char :=
sat (λc, c ≠ '\"' ∧ c ≠ '\\' ∧ c.val > 0x1f)
<|> (do str "\\",
(str "t" >> return '\t') <|>
(str "n" >> return '\n') <|>
(str "\\" >> return '\\') <|>
(str "\"" >> return '\"'))
def BasicString : parser string :=
str "\"" *> (many_char StringChar) <* str "\"" <* Ws
def String := BasicString
def Nat : parser nat :=
do s ← many_char1 (one_of "0123456789".to_list),
Ws,
return s.to_nat
def Boolean : parser bool :=
(tok "true" >> return tt) <|>
(tok "false" >> return ff)
def BareKey : parser string := do
cs ← many_char1 $ sat $ λ c, c.is_alpha ∨ c.is_digit ∨ c = '_' ∨ c = '-',
Ws,
return cs
def Key := BareKey <|> BasicString
section
parameter Val : parser value
def KeyVal : parser (string × value) := do
k ← Key, tok "=", v ← Val,
return (k, v)
def StdTable : parser (string × value) := do
tok "[", n ← Key, tok "]",
cs ← many KeyVal,
return (n, value.table cs)
def Table : parser (string × value) := StdTable
def StrVal : parser value :=
value.str <$> String
def NatVal : parser value :=
value.nat <$> Nat
def BoolVal : parser value :=
value.bool <$> Boolean
def InlineTable : parser value :=
tok "{" *> (value.table <$> sep_by (tok ",") KeyVal) <* tok "}"
end
def Val : parser value :=
fix $ λ Val, StrVal <|> NatVal <|> BoolVal <|> InlineTable Val
def Expression := Table Val
def File : parser value :=
Ws *> (value.table <$> many Expression)
/-
#eval run_string File $
"[package]\n" ++
"name = \"sss\"\n" ++
"version = \"0.1\"\n" ++
"timeout = 10\n" ++
"\n" ++
"[dependencies]\n" ++
"library_dev = { git = \"https://github.com/leanprover/library_dev\", rev = \"master\" }"
-/
end toml
|
bed9e0d1fa1c846db6e6103ef3df6d9999c51b81 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/topology/fiber_bundle/basic.lean | f9271f889986140e801714fa550257f29dd036cd | [
"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 | 44,570 | 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, Floris van Doorn, Heather Macbeth
-/
import topology.fiber_bundle.trivialization
/-!
# Fiber bundles
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Mathematically, 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.
In our formalism, a fiber bundle is by definition the type
`bundle.total_space E` where `E : B → Type*` is a function associating to
`x : B` the fiber over `x`. This type `bundle.total_space E` is just a type synonym for
`Σ (x : B), E x`, with the interest that one can put another topology than on `Σ (x : B), E x`
which has the disjoint union topology.
To have a fiber bundle structure on `bundle.total_space E`, one should
additionally have the following data:
* `F` should be a topological space;
* There should be a topology on `bundle.total_space E`, for which the projection to `B` is
a fiber bundle with fiber `F` (in particular, each fiber `E x` is homeomorphic to `F`);
* For each `x`, the fiber `E x` should be a topological space, and the injection
from `E x` to `bundle.total_space F E` should be an embedding;
* There should be a distinguished set of bundle trivializations, the "trivialization atlas"
* There should be a choice of bundle trivialization at each point, which belongs to this atlas.
If all these conditions are satisfied, we register the typeclass `fiber_bundle F E`.
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
`fiber_bundle_core` registering the trivialization changes, one gets the corresponding
fiber bundle and projection.
Similarly we implement the object `fiber_prebundle` which allows to define a topological
fiber bundle from trivializations given as local equivalences with minimum additional properties.
## Main definitions
### Basic definitions
* `fiber_bundle F E` : Structure saying that `E : B → Type*` is a fiber bundle with fiber `F`.
### Construction of a bundle from trivializations
* `bundle.total_space E` is a type synonym for `Σ (x : B), E x`, that we can endow with a suitable
topology.
* `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 : fiber_bundle_core ι B F`. Then we define
* `Z.fiber x` : the fiber above `x`, homeomorphic to `F` (and defeq to `F` as a type).
* `Z.total_space` : the total space of `Z`, defined as a `Type` as `Σ (b : B), F`, but with a
twisted topology coming from the fiber bundle structure. It is (reducibly) the same as
`bundle.total_space Z.fiber`.
* `Z.proj` : projection from `Z.total_space` to `B`. It is continuous.
* `Z.local_triv i`: for `i : ι`, bundle trivialization above the set `Z.base_set i`, which is an
open set in `B`.
* `fiber_prebundle F E` : structure registering a cover of prebundle trivializations
and requiring that the relative transition maps are local homeomorphisms.
* `fiber_prebundle.total_space_topology a` : natural topology of the total space, making
the prebundle into a bundle.
## Implementation notes
### Data vs mixins
For both fiber and vector bundles, one faces a choice: should the definition state the *existence*
of local trivializations (a propositional typeclass), or specify a fixed atlas of trivializations (a
typeclass containing data)?
In their initial mathlib implementations, both fiber and vector bundles were defined
propositionally. For vector bundles, this turns out to be mathematically wrong: in infinite
dimension, the transition function between two trivializations is not automatically continuous as a
map from the base `B` to the endomorphisms `F →L[R] F` of the fiber (considered with the
operator-norm topology), and so the definition needs to be modified by restricting consideration to
a family of trivializations (constituting the data) which are all mutually-compatible in this sense.
The PRs #13052 and #13175 implemented this change.
There is still the choice about whether to hold this data at the level of fiber bundles or of vector
bundles. As of PR #17505, the data is all held in `fiber_bundle`, with `vector_bundle` a
(propositional) mixin stating fiberwise-linearity.
This allows bundles to carry instances of typeclasses in which the scalar field, `R`, does not
appear as a parameter. Notably, we would like a vector bundle over `R` with fiber `F` over base `B`
to be a `charted_space (B × F)`, with the trivializations providing the charts. This would be a
dangerous instance for typeclass inference, because `R` does not appear as a parameter in
`charted_space (B × F)`. But if the data of the trivializations is held in `fiber_bundle`, then a
fiber bundle with fiber `F` over base `B` can be a `charted_space (B × F)`, and this is safe for
typeclass inference.
We expect that this choice of definition will also streamline constructions of fiber bundles with
similar underlying structure (e.g., the same bundle being both a real and complex vector bundle).
### Core construction
A 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
`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 case of the tangent bundle of manifolds, this implies that on vector spaces the derivative
(from `F` to `F`) and the manifold derivative (from `tangent_space I x` to `tangent_space I' (f x)`)
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 `fiber_bundle_core`, we should thus
choose for each `x` one specific trivialization around it. We include this choice in the definition
of the `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 : B), F `, but the topology is not the product one, in general.
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 `fiber_bundle_core`, the indexing type will be the same as
for the initial bundle.
## Tags
Fiber bundle, topological bundle, structure group
-/
variables {ι B F X : Type*} [topological_space X]
open topological_space filter set bundle
open_locale topology classical bundle
attribute [mfld_simps] total_space_mk coe_fst coe_snd coe_snd_map_apply
coe_snd_map_smul total_space.mk_cast
/-! ### General definition of fiber bundles -/
section fiber_bundle
variables (F) [topological_space B] [topological_space F] (E : B → Type*)
[topological_space (total_space E)] [∀ b, topological_space (E b)]
/-- 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. -/
class fiber_bundle :=
(total_space_mk_inducing [] : ∀ (b : B), inducing (@total_space_mk B E b))
(trivialization_atlas [] : set (trivialization F (π E)))
(trivialization_at [] : B → trivialization F (π E))
(mem_base_set_trivialization_at [] : ∀ b : B, b ∈ (trivialization_at b).base_set)
(trivialization_mem_atlas [] : ∀ b : B, trivialization_at b ∈ trivialization_atlas)
export fiber_bundle
variables {F E}
/-- Given a type `E` equipped with a fiber bundle structure, this is a `Prop` typeclass
for trivializations of `E`, expressing that a trivialization is in the designated atlas for the
bundle. This is needed because lemmas about the linearity of trivializations or the continuity (as
functions to `F →L[R] F`, where `F` is the model fiber) of the transition functions are only
expected to hold for trivializations in the designated atlas. -/
@[mk_iff]
class mem_trivialization_atlas [fiber_bundle F E] (e : trivialization F (π E)) : Prop :=
(out : e ∈ trivialization_atlas F E)
instance [fiber_bundle F E] (b : B) : mem_trivialization_atlas (trivialization_at F E b) :=
{ out := trivialization_mem_atlas F E b }
namespace fiber_bundle
variables (F) {E} [fiber_bundle F E]
lemma map_proj_nhds (x : total_space E) :
map (π E) (𝓝 x) = 𝓝 x.proj :=
(trivialization_at F E x.proj).map_proj_nhds $
(trivialization_at F E x.proj).mem_source.2 $ mem_base_set_trivialization_at F E x.proj
variables (E)
/-- The projection from a fiber bundle to its base is continuous. -/
@[continuity] lemma continuous_proj : continuous (π E) :=
continuous_iff_continuous_at.2 $ λ x, (map_proj_nhds F x).le
/-- The projection from a fiber bundle to its base is an open map. -/
lemma is_open_map_proj : is_open_map (π E) :=
is_open_map.of_nhds_le $ λ x, (map_proj_nhds F x).ge
/-- The projection from a fiber bundle with a nonempty fiber to its base is a surjective
map. -/
lemma surjective_proj [nonempty F] : function.surjective (π E) :=
λ b, let ⟨p, _, hpb⟩ :=
(trivialization_at F E b).proj_surj_on_base_set (mem_base_set_trivialization_at F E b) in ⟨p, hpb⟩
/-- The projection from a fiber bundle with a nonempty fiber to its base is a quotient
map. -/
lemma quotient_map_proj [nonempty F] : quotient_map (π E) :=
(is_open_map_proj F E).to_quotient_map (continuous_proj F E) (surjective_proj F E)
lemma continuous_total_space_mk (x : B) : continuous (@total_space_mk B E x) :=
(total_space_mk_inducing F E x).continuous
variables {E F}
@[simp, mfld_simps]
lemma mem_trivialization_at_proj_source {x : total_space E} :
x ∈ (trivialization_at F E x.proj).source :=
(trivialization.mem_source _).mpr $ mem_base_set_trivialization_at F E x.proj
@[simp, mfld_simps]
lemma trivialization_at_proj_fst {x : total_space E} :
((trivialization_at F E x.proj) x).1 = x.proj :=
trivialization.coe_fst' _ $ mem_base_set_trivialization_at F E x.proj
variable (F)
open trivialization
/-- Characterization of continuous functions (at a point, within a set) into a fiber bundle. -/
lemma continuous_within_at_total_space (f : X → total_space E) {s : set X} {x₀ : X} :
continuous_within_at f s x₀ ↔
continuous_within_at (λ x, (f x).proj) s x₀ ∧
continuous_within_at (λ x, ((trivialization_at F E (f x₀).proj) (f x)).2) s x₀ :=
begin
refine (and_iff_right_iff_imp.2 $ λ hf, _).symm.trans (and_congr_right $ λ hf, _),
{ refine (continuous_proj F E).continuous_within_at.comp hf (maps_to_image f s) },
have h1 : (λ x, (f x).proj) ⁻¹' (trivialization_at F E (f x₀).proj).base_set ∈ 𝓝[s] x₀ :=
hf.preimage_mem_nhds_within ((open_base_set _).mem_nhds (mem_base_set_trivialization_at F E _)),
have h2 : continuous_within_at (λ x, (trivialization_at F E (f x₀).proj (f x)).1) s x₀,
{ refine hf.congr_of_eventually_eq (eventually_of_mem h1 $ λ x hx, _) trivialization_at_proj_fst,
rw [coe_fst'],
exact hx },
rw [(trivialization_at F E (f x₀).proj).continuous_within_at_iff_continuous_within_at_comp_left],
{ simp_rw [continuous_within_at_prod_iff, function.comp, trivialization.coe_coe, h2, true_and] },
{ apply mem_trivialization_at_proj_source },
{ rwa [source_eq, preimage_preimage] }
end
/-- Characterization of continuous functions (at a point) into a fiber bundle. -/
lemma continuous_at_total_space (f : X → total_space E) {x₀ : X} :
continuous_at f x₀ ↔ continuous_at (λ x, (f x).proj) x₀ ∧
continuous_at (λ x, ((trivialization_at F E (f x₀).proj) (f x)).2) x₀ :=
by { simp_rw [← continuous_within_at_univ], exact continuous_within_at_total_space F f }
end fiber_bundle
variables (F E)
/-- If `E` is a fiber bundle over a conditionally complete linear order,
then it is trivial over any closed interval. -/
lemma fiber_bundle.exists_trivialization_Icc_subset
[conditionally_complete_linear_order B] [order_topology B] [fiber_bundle F E] (a b : B) :
∃ e : trivialization F (π E), Icc a b ⊆ e.base_set :=
begin
classical,
obtain ⟨ea, hea⟩ : ∃ ea : trivialization F (π E), a ∈ ea.base_set :=
⟨trivialization_at F E a, mem_base_set_trivialization_at F E a⟩,
-- If `a < b`, then `[a, b] = ∅`, and the statement is trivial
cases le_or_lt a b with hab hab; [skip, exact ⟨ea, by simp *⟩],
/- Let `s` be the set of points `x ∈ [a, b]` such that `E` is trivializable over `[a, x]`.
We need to show that `b ∈ s`. Let `c = Sup s`. We will show that `c ∈ s` and `c = b`. -/
set s : set B := {x ∈ Icc a b | ∃ e : trivialization F (π E), Icc a x ⊆ e.base_set},
have ha : a ∈ s, from ⟨left_mem_Icc.2 hab, ea, by simp [hea]⟩,
have sne : s.nonempty := ⟨a, ha⟩,
have hsb : b ∈ upper_bounds s, from λ x hx, hx.1.2,
have sbd : bdd_above s := ⟨b, hsb⟩,
set c := Sup s,
have hsc : is_lub s c, from is_lub_cSup sne sbd,
have hc : c ∈ Icc a b, from ⟨hsc.1 ha, hsc.2 hsb⟩,
obtain ⟨-, ec : trivialization F (π E), hec : Icc a c ⊆ ec.base_set⟩ : c ∈ s,
{ cases hc.1.eq_or_lt with heq hlt, { rwa ← heq },
refine ⟨hc, _⟩,
/- In order to show that `c ∈ s`, consider a trivialization `ec` of `proj` over a neighborhood
of `c`. Its base set includes `(c', c]` for some `c' ∈ [a, c)`. -/
obtain ⟨ec, hc⟩ : ∃ ec : trivialization F (π E), c ∈ ec.base_set :=
⟨trivialization_at F E c, mem_base_set_trivialization_at F E c⟩,
obtain ⟨c', hc', hc'e⟩ : ∃ c' ∈ Ico a c, Ioc c' c ⊆ ec.base_set :=
(mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset hlt).1
(mem_nhds_within_of_mem_nhds $ is_open.mem_nhds ec.open_base_set hc),
/- Since `c' < c = Sup s`, there exists `d ∈ s ∩ (c', c]`. Let `ead` be a trivialization of
`proj` over `[a, d]`. Then we can glue `ead` and `ec` into a trivialization over `[a, c]`. -/
obtain ⟨d, ⟨hdab, ead, had⟩, hd⟩ : ∃ d ∈ s, d ∈ Ioc c' c := hsc.exists_between hc'.2,
refine ⟨ead.piecewise_le ec d (had ⟨hdab.1, le_rfl⟩) (hc'e hd), subset_ite.2 _⟩,
refine ⟨λ x hx, had ⟨hx.1.1, hx.2⟩, λ x hx, hc'e ⟨hd.1.trans (not_le.1 hx.2), hx.1.2⟩⟩ },
/- So, `c ∈ s`. Let `ec` be a trivialization of `proj` over `[a, c]`. If `c = b`, then we are
done. Otherwise we show that `proj` can be trivialized over a larger interval `[a, d]`,
`d ∈ (c, b]`, hence `c` is not an upper bound of `s`. -/
cases hc.2.eq_or_lt with heq hlt, { exact ⟨ec, heq ▸ hec⟩ },
rsuffices ⟨d, hdcb, hd⟩ : ∃ (d ∈ Ioc c b) (e : trivialization F (π E)), Icc a d ⊆ e.base_set,
{ exact ((hsc.1 ⟨⟨hc.1.trans hdcb.1.le, hdcb.2⟩, hd⟩).not_lt hdcb.1).elim },
/- Since the base set of `ec` is open, it includes `[c, d)` (hence, `[a, d)`) for some
`d ∈ (c, b]`. -/
obtain ⟨d, hdcb, hd⟩ : ∃ d ∈ Ioc c b, Ico c d ⊆ ec.base_set :=
(mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hlt).1
(mem_nhds_within_of_mem_nhds $ is_open.mem_nhds ec.open_base_set (hec ⟨hc.1, le_rfl⟩)),
have had : Ico a d ⊆ ec.base_set,
from Ico_subset_Icc_union_Ico.trans (union_subset hec hd),
by_cases he : disjoint (Iio d) (Ioi c),
{ /- If `(c, d) = ∅`, then let `ed` be a trivialization of `proj` over a neighborhood of `d`.
Then the disjoint union of `ec` restricted to `(-∞, d)` and `ed` restricted to `(c, ∞)` is
a trivialization over `[a, d]`. -/
obtain ⟨ed, hed⟩ : ∃ ed : trivialization F (π E), d ∈ ed.base_set :=
⟨trivialization_at F E d, mem_base_set_trivialization_at F E d⟩,
refine ⟨d, hdcb, (ec.restr_open (Iio d) is_open_Iio).disjoint_union
(ed.restr_open (Ioi c) is_open_Ioi) (he.mono (inter_subset_right _ _)
(inter_subset_right _ _)), λ x hx, _⟩,
rcases hx.2.eq_or_lt with rfl|hxd,
exacts [or.inr ⟨hed, hdcb.1⟩, or.inl ⟨had ⟨hx.1, hxd⟩, hxd⟩] },
{ /- If `(c, d)` is nonempty, then take `d' ∈ (c, d)`. Since the base set of `ec` includes
`[a, d)`, it includes `[a, d'] ⊆ [a, d)` as well. -/
rw [disjoint_left] at he, push_neg at he, rcases he with ⟨d', hdd' : d' < d, hd'c⟩,
exact ⟨d', ⟨hd'c, hdd'.le.trans hdcb.2⟩, ec, (Icc_subset_Ico_right hdd').trans had⟩ }
end
end fiber_bundle
/-! ### Core construction for constructing fiber bundles -/
/-- Core data defining a locally trivial 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`. -/
@[nolint has_nonempty_instance]
structure 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)
(continuous_on_coord_change : ∀ i j, continuous_on (λp : B × F, coord_change i j p.1 p.2)
(((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)
namespace fiber_bundle_core
variables [topological_space B] [topological_space F] (Z : fiber_bundle_core ι B F)
include Z
/-- The index set of a fiber bundle core, as a convenience function for dot notation -/
@[nolint unused_arguments has_nonempty_instance]
def index := ι
/-- The base space of a fiber bundle core, as a convenience function for dot notation -/
@[nolint unused_arguments, reducible]
def base := B
/-- The fiber of a fiber bundle core, as a convenience function for dot notation and
typeclass inference -/
@[nolint unused_arguments has_nonempty_instance]
def fiber (x : B) := F
section fiber_instances
local attribute [reducible] fiber
instance topological_space_fiber (x : B) : topological_space (Z.fiber x) := by apply_instance
end fiber_instances
/-- The total space of the fiber bundle, as a convenience function for dot notation.
It is by definition equal to `bundle.total_space Z.fiber`, a.k.a. `Σ x, Z.fiber x` but with a
different name for typeclass inference. -/
@[nolint unused_arguments, reducible]
def total_space := bundle.total_space Z.fiber
/-- The projection from the total space of a fiber bundle core, on its base. -/
@[reducible, simp, mfld_simps] def proj : Z.total_space → B := bundle.total_space.proj
/-- Local homeomorphism version of the trivialization change. -/
def triv_change (i j : ι) : local_homeomorph (B × F) (B × F) :=
{ source := (Z.base_set i ∩ Z.base_set j) ×ˢ univ,
target := (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_iff, 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_iff, 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.inter (Z.is_open_base_set i) (Z.is_open_base_set j)).prod is_open_univ,
open_target :=
(is_open.inter (Z.is_open_base_set i) (Z.is_open_base_set j)).prod is_open_univ,
continuous_to_fun :=
continuous_on.prod continuous_fst.continuous_on (Z.continuous_on_coord_change i j),
continuous_inv_fun := by simpa [inter_comm]
using continuous_on.prod continuous_fst.continuous_on (Z.continuous_on_coord_change j i) }
@[simp, mfld_simps] 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_as_local_equiv (i : ι) : local_equiv Z.total_space (B × F) :=
{ source := Z.proj ⁻¹' (Z.base_set i),
target := 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 only,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact Z.mem_base_set_at _ },
{ simp only [hx, mem_inter_iff, and_self, mem_base_set_at] }
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 only [hx, mem_inter_iff, and_self, mem_base_set_at] }
end }
variable (i : ι)
lemma mem_local_triv_as_local_equiv_source (p : Z.total_space) :
p ∈ (Z.local_triv_as_local_equiv i).source ↔ p.1 ∈ Z.base_set i :=
iff.rfl
lemma mem_local_triv_as_local_equiv_target (p : B × F) :
p ∈ (Z.local_triv_as_local_equiv i).target ↔ p.1 ∈ Z.base_set i :=
by { erw [mem_prod], simp only [and_true, mem_univ] }
lemma local_triv_as_local_equiv_apply (p : Z.total_space) :
(Z.local_triv_as_local_equiv i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl
/-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/
lemma local_triv_as_local_equiv_trans (i j : ι) :
(Z.local_triv_as_local_equiv i).symm.trans
(Z.local_triv_as_local_equiv j) ≈ (Z.triv_change i j).to_local_equiv :=
begin
split,
{ ext x, simp only [mem_local_triv_as_local_equiv_target] with mfld_simps, refl, },
{ rintros ⟨x, v⟩ hx,
simp only [triv_change, local_triv_as_local_equiv, local_equiv.symm, true_and, prod.mk.inj_iff,
prod_mk_mem_set_prod_eq, local_equiv.trans_source, mem_inter_iff, and_true, mem_preimage,
proj, mem_univ, local_equiv.coe_mk, eq_self_iff_true, local_equiv.coe_trans,
total_space.proj] at hx ⊢,
simp only [Z.coord_change_comp, hx, mem_inter_iff, and_self, mem_base_set_at], }
end
/-- Topological structure on the total space of a fiber bundle created from core, designed so
that all the local trivialization are continuous. -/
instance to_topological_space : topological_space (bundle.total_space Z.fiber) :=
topological_space.generate_from $ ⋃ (i : ι) (s : set (B × F)) (s_open : is_open s),
{(Z.local_triv_as_local_equiv i).source ∩ (Z.local_triv_as_local_equiv i) ⁻¹' s}
variables (b : B) (a : F)
lemma open_source' (i : ι) : is_open (Z.local_triv_as_local_equiv i).source :=
begin
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
refine ⟨i, Z.base_set i ×ˢ univ, (Z.is_open_base_set i).prod is_open_univ, _⟩,
ext p,
simp only [local_triv_as_local_equiv_apply, prod_mk_mem_set_prod_eq, mem_inter_iff, and_self,
mem_local_triv_as_local_equiv_source, and_true, mem_univ, mem_preimage],
end
/-- 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 (i : ι) : 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 only with mfld_simps, refl },
open_source := Z.open_source' i,
open_target := (Z.is_open_base_set i).prod is_open_univ,
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.is_open_base_set i).prod is_open_univ),
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_as_local_equiv Z j).source ∩ (local_triv_as_local_equiv Z j) ⁻¹' s := ht,
rw ts,
simp only [local_equiv.right_inv, preimage_inter, local_equiv.left_inv],
let e := Z.local_triv_as_local_equiv i,
let e' := Z.local_triv_as_local_equiv j,
let f := e.symm.trans e',
have : is_open (f.source ∩ f ⁻¹' s),
{ rw [(Z.local_triv_as_local_equiv_trans i j).source_inter_preimage_eq],
exact (continuous_on_open_iff (Z.triv_change i j).open_source).1
((Z.triv_change i j).continuous_on) _ s_open },
convert this using 1,
dsimp [local_equiv.trans_source],
rw [← preimage_comp, inter_assoc],
refl,
end,
to_local_equiv := Z.local_triv_as_local_equiv i }
/-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as
a bundle trivialization -/
def local_triv_at (b : B) : trivialization F (π Z.fiber) :=
Z.local_triv (Z.index_at b)
@[simp, mfld_simps] lemma local_triv_at_def (b : B) :
Z.local_triv (Z.index_at b) = Z.local_triv_at b := rfl
/-- If an element of `F` is invariant under all coordinate changes, then one can define a
corresponding section of the fiber bundle, which is continuous. This applies in particular to the
zero section of a vector bundle. Another example (not yet defined) would be the identity
section of the endomorphism bundle of a vector bundle. -/
lemma continuous_const_section (v : F)
(h : ∀ i j, ∀ x ∈ (Z.base_set i) ∩ (Z.base_set j), Z.coord_change i j x v = v) :
continuous (show B → Z.total_space, from λ x, ⟨x, v⟩) :=
begin
apply continuous_iff_continuous_at.2 (λ x, _),
have A : Z.base_set (Z.index_at x) ∈ 𝓝 x :=
is_open.mem_nhds (Z.is_open_base_set (Z.index_at x)) (Z.mem_base_set_at x),
apply ((Z.local_triv_at x).to_local_homeomorph.continuous_at_iff_continuous_at_comp_left _).2,
{ simp only [(∘)] with mfld_simps,
apply continuous_at_id.prod,
have : continuous_on (λ (y : B), v) (Z.base_set (Z.index_at x)) := continuous_on_const,
apply (this.congr _).continuous_at A,
assume y hy,
simp only [h, hy, mem_base_set_at] with mfld_simps },
{ exact A }
end
@[simp, mfld_simps] lemma local_triv_as_local_equiv_coe :
⇑(Z.local_triv_as_local_equiv i) = Z.local_triv i := rfl
@[simp, mfld_simps] lemma local_triv_as_local_equiv_source :
(Z.local_triv_as_local_equiv i).source = (Z.local_triv i).source := rfl
@[simp, mfld_simps] lemma local_triv_as_local_equiv_target :
(Z.local_triv_as_local_equiv i).target = (Z.local_triv i).target := rfl
@[simp, mfld_simps] lemma local_triv_as_local_equiv_symm :
(Z.local_triv_as_local_equiv i).symm = (Z.local_triv i).to_local_equiv.symm := rfl
@[simp, mfld_simps] lemma base_set_at : Z.base_set i = (Z.local_triv i).base_set := rfl
@[simp, mfld_simps] lemma local_triv_apply (p : Z.total_space) :
(Z.local_triv i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl
@[simp, mfld_simps] lemma local_triv_at_apply (p : Z.total_space) :
((Z.local_triv_at p.1) p) = ⟨p.1, p.2⟩ :=
by { rw [local_triv_at, local_triv_apply, coord_change_self], exact Z.mem_base_set_at p.1 }
@[simp, mfld_simps] lemma local_triv_at_apply_mk (b : B) (a : F) :
((Z.local_triv_at b) ⟨b, a⟩) = ⟨b, a⟩ :=
Z.local_triv_at_apply _
@[simp, mfld_simps] lemma mem_local_triv_source (p : Z.total_space) :
p ∈ (Z.local_triv i).source ↔ p.1 ∈ (Z.local_triv i).base_set := iff.rfl
@[simp, mfld_simps] lemma mem_local_triv_at_source (p : Z.total_space) (b : B) :
p ∈ (Z.local_triv_at b).source ↔ p.1 ∈ (Z.local_triv_at b).base_set := iff.rfl
@[simp, mfld_simps] lemma mem_source_at : (⟨b, a⟩ : Z.total_space) ∈ (Z.local_triv_at b).source :=
by { rw [local_triv_at, mem_local_triv_source], exact Z.mem_base_set_at b }
@[simp, mfld_simps] lemma mem_local_triv_target (p : B × F) :
p ∈ (Z.local_triv i).target ↔ p.1 ∈ (Z.local_triv i).base_set :=
trivialization.mem_target _
@[simp, mfld_simps] lemma mem_local_triv_at_target (p : B × F) (b : B) :
p ∈ (Z.local_triv_at b).target ↔ p.1 ∈ (Z.local_triv_at b).base_set :=
trivialization.mem_target _
@[simp, mfld_simps] lemma local_triv_symm_apply (p : B × F) :
(Z.local_triv i).to_local_homeomorph.symm p =
⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩ := rfl
@[simp, mfld_simps] lemma mem_local_triv_at_base_set (b : B) :
b ∈ (Z.local_triv_at b).base_set :=
by { rw [local_triv_at, ←base_set_at], exact Z.mem_base_set_at b, }
/-- The inclusion of a fiber into the total space is a continuous map. -/
@[continuity]
lemma continuous_total_space_mk (b : B) :
continuous (total_space_mk b : Z.fiber b → bundle.total_space Z.fiber) :=
begin
rw [continuous_iff_le_induced, fiber_bundle_core.to_topological_space],
apply le_induced_generate_from,
simp only [total_space_mk, mem_Union, mem_singleton_iff, local_triv_as_local_equiv_source,
local_triv_as_local_equiv_coe],
rintros s ⟨i, t, ht, rfl⟩,
rw [←((Z.local_triv i).source_inter_preimage_target_inter t), preimage_inter, ←preimage_comp,
trivialization.source_eq],
apply is_open.inter,
{ simp only [total_space.proj, proj, ←preimage_comp],
by_cases (b ∈ (Z.local_triv i).base_set),
{ rw preimage_const_of_mem h, exact is_open_univ, },
{ rw preimage_const_of_not_mem h, exact is_open_empty, }},
{ simp only [function.comp, local_triv_apply],
rw [preimage_inter, preimage_comp],
by_cases (b ∈ Z.base_set i),
{ have hc : continuous (λ (x : Z.fiber b), (Z.coord_change (Z.index_at b) i b) x),
from (Z.continuous_on_coord_change (Z.index_at b) i).comp_continuous
(continuous_const.prod_mk continuous_id) (λ x, ⟨⟨Z.mem_base_set_at b, h⟩, mem_univ x⟩),
exact (((Z.local_triv i).open_target.inter ht).preimage (continuous.prod.mk b)).preimage hc },
{ rw [(Z.local_triv i).target_eq, ←base_set_at, mk_preimage_prod_right_eq_empty h,
preimage_empty, empty_inter],
exact is_open_empty, }}
end
/-- A fiber bundle constructed from core is indeed a fiber bundle. -/
instance fiber_bundle : fiber_bundle F Z.fiber :=
{ total_space_mk_inducing := λ b, ⟨ begin refine le_antisymm _ (λ s h, _),
{ rw ←continuous_iff_le_induced,
exact continuous_total_space_mk Z b, },
{ refine is_open_induced_iff.mpr ⟨(Z.local_triv_at b).source ∩ (Z.local_triv_at b) ⁻¹'
((Z.local_triv_at b).base_set ×ˢ s), (continuous_on_open_iff
(Z.local_triv_at b).open_source).mp (Z.local_triv_at b).continuous_to_fun _
((Z.local_triv_at b).open_base_set.prod h), _⟩,
rw [preimage_inter, ←preimage_comp, function.comp],
simp only [total_space_mk],
refine ext_iff.mpr (λ a, ⟨λ ha, _, λ ha, ⟨Z.mem_base_set_at b, _⟩⟩),
{ simp only [mem_prod, mem_preimage, mem_inter_iff, local_triv_at_apply_mk] at ha,
exact ha.2.2, },
{ simp only [mem_prod, mem_preimage, mem_inter_iff, local_triv_at_apply_mk],
exact ⟨Z.mem_base_set_at b, ha⟩, } } end⟩,
trivialization_atlas := set.range Z.local_triv,
trivialization_at := Z.local_triv_at,
mem_base_set_trivialization_at := Z.mem_base_set_at,
trivialization_mem_atlas := λ b, ⟨Z.index_at b, rfl⟩ }
/-- The projection on the base of a fiber bundle created from core is continuous -/
lemma continuous_proj : continuous Z.proj := continuous_proj F Z.fiber
/-- The projection on the base of a fiber bundle created from core is an open map -/
lemma is_open_map_proj : is_open_map Z.proj := is_open_map_proj F Z.fiber
end fiber_bundle_core
/-! ### Prebundle construction for constructing fiber bundles -/
variables (F) (E : B → Type*) [topological_space B] [topological_space F]
/-- This structure permits to define a fiber bundle when trivializations are given as local
equivalences but there is not yet a topology on the total space. The total space is hence given a
topology in such a way that there is a fiber bundle structure for which the local equivalences
are also local homeomorphism and hence local trivializations. -/
@[nolint has_nonempty_instance]
structure fiber_prebundle :=
(pretrivialization_atlas : set (pretrivialization F (π E)))
(pretrivialization_at : B → pretrivialization F (π E))
(mem_base_pretrivialization_at : ∀ x : B, x ∈ (pretrivialization_at x).base_set)
(pretrivialization_mem_atlas : ∀ x : B, pretrivialization_at x ∈ pretrivialization_atlas)
(continuous_triv_change : ∀ e e' ∈ pretrivialization_atlas,
continuous_on (e ∘ e'.to_local_equiv.symm) (e'.target ∩ (e'.to_local_equiv.symm ⁻¹' e.source)))
namespace fiber_prebundle
variables {F E} (a : fiber_prebundle F E) {e : pretrivialization F (π E)}
/-- Topology on the total space that will make the prebundle into a bundle. -/
def total_space_topology (a : fiber_prebundle F E) : topological_space (total_space E) :=
⨆ (e : pretrivialization F (π E)) (he : e ∈ a.pretrivialization_atlas),
coinduced e.set_symm (subtype.topological_space)
lemma continuous_symm_of_mem_pretrivialization_atlas (he : e ∈ a.pretrivialization_atlas) :
@continuous_on _ _ _ a.total_space_topology
e.to_local_equiv.symm e.target :=
begin
refine id (λ z H, id (λ U h, preimage_nhds_within_coinduced' H
e.open_target (le_def.1 (nhds_mono _) U h))),
exact le_supr₂ e he,
end
lemma is_open_source (e : pretrivialization F (π E)) : is_open[a.total_space_topology] e.source :=
begin
letI := a.total_space_topology,
refine is_open_supr_iff.mpr (λ e', _),
refine is_open_supr_iff.mpr (λ he', _),
refine is_open_coinduced.mpr (is_open_induced_iff.mpr ⟨e.target, e.open_target, _⟩),
rw [pretrivialization.set_symm, restrict, e.target_eq,
e.source_eq, preimage_comp, subtype.preimage_coe_eq_preimage_coe_iff,
e'.target_eq, prod_inter_prod, inter_univ,
pretrivialization.preimage_symm_proj_inter],
end
lemma is_open_target_of_mem_pretrivialization_atlas_inter (e e' : pretrivialization F (π E))
(he' : e' ∈ a.pretrivialization_atlas) :
is_open (e'.to_local_equiv.target ∩ e'.to_local_equiv.symm ⁻¹' e.source) :=
begin
letI := a.total_space_topology,
obtain ⟨u, hu1, hu2⟩ := continuous_on_iff'.mp (a.continuous_symm_of_mem_pretrivialization_atlas
he') e.source (a.is_open_source e),
rw [inter_comm, hu2],
exact hu1.inter e'.open_target,
end
/-- Promotion from a `pretrivialization` to a `trivialization`. -/
def trivialization_of_mem_pretrivialization_atlas (he : e ∈ a.pretrivialization_atlas) :
@trivialization B F _ _ _ a.total_space_topology (π E) :=
{ open_source := a.is_open_source e,
continuous_to_fun := begin
letI := a.total_space_topology,
refine continuous_on_iff'.mpr (λ s hs, ⟨e ⁻¹' s ∩ e.source, (is_open_supr_iff.mpr (λ e', _)),
by { rw [inter_assoc, inter_self], refl }⟩),
refine (is_open_supr_iff.mpr (λ he', _)),
rw [is_open_coinduced, is_open_induced_iff],
obtain ⟨u, hu1, hu2⟩ := continuous_on_iff'.mp (a.continuous_triv_change _ he _ he') s hs,
have hu3 := congr_arg (λ s, (λ x : e'.target, (x : B × F)) ⁻¹' s) hu2,
simp only [subtype.coe_preimage_self, preimage_inter, univ_inter] at hu3,
refine ⟨u ∩ e'.to_local_equiv.target ∩
(e'.to_local_equiv.symm ⁻¹' e.source), _, by
{ simp only [preimage_inter, inter_univ, subtype.coe_preimage_self, hu3.symm], refl }⟩,
rw inter_assoc,
exact hu1.inter (a.is_open_target_of_mem_pretrivialization_atlas_inter e e' he'),
end,
continuous_inv_fun := a.continuous_symm_of_mem_pretrivialization_atlas he,
.. e }
lemma mem_trivialization_at_source (b : B) (x : E b) :
total_space_mk b x ∈ (a.pretrivialization_at b).source :=
begin
simp only [(a.pretrivialization_at b).source_eq, mem_preimage, total_space.proj],
exact a.mem_base_pretrivialization_at b,
end
@[simp] lemma total_space_mk_preimage_source (b : B) :
(total_space_mk b) ⁻¹' (a.pretrivialization_at b).source = univ :=
begin
apply eq_univ_of_univ_subset,
rw [(a.pretrivialization_at b).source_eq, ←preimage_comp, function.comp],
simp only [total_space.proj],
rw preimage_const_of_mem _,
exact a.mem_base_pretrivialization_at b,
end
/-- Topology on the fibers `E b` induced by the map `E b → E.total_space`. -/
def fiber_topology (b : B) : topological_space (E b) :=
topological_space.induced (total_space_mk b) a.total_space_topology
@[continuity] lemma inducing_total_space_mk (b : B) :
@inducing _ _ (a.fiber_topology b) a.total_space_topology (total_space_mk b) :=
by { letI := a.total_space_topology, letI := a.fiber_topology b, exact ⟨rfl⟩ }
@[continuity] lemma continuous_total_space_mk (b : B) :
@continuous _ _ (a.fiber_topology b) a.total_space_topology (total_space_mk b) :=
begin
letI := a.total_space_topology, letI := a.fiber_topology b,
exact (a.inducing_total_space_mk b).continuous
end
/-- Make a `fiber_bundle` from a `fiber_prebundle`. Concretely this means
that, given a `fiber_prebundle` structure for a sigma-type `E` -- which consists of a
number of "pretrivializations" identifying parts of `E` with product spaces `U × F` -- one
establishes that for the topology constructed on the sigma-type using
`fiber_prebundle.total_space_topology`, these "pretrivializations" are actually
"trivializations" (i.e., homeomorphisms with respect to the constructed topology). -/
def to_fiber_bundle :
@fiber_bundle B F _ _ E a.total_space_topology a.fiber_topology :=
{ total_space_mk_inducing := a.inducing_total_space_mk,
trivialization_atlas := {e | ∃ e₀ (he₀ : e₀ ∈ a.pretrivialization_atlas),
e = a.trivialization_of_mem_pretrivialization_atlas he₀},
trivialization_at := λ x, a.trivialization_of_mem_pretrivialization_atlas
(a.pretrivialization_mem_atlas x),
mem_base_set_trivialization_at := a.mem_base_pretrivialization_at,
trivialization_mem_atlas := λ x, ⟨_, a.pretrivialization_mem_atlas x, rfl⟩ }
lemma continuous_proj : @continuous _ _ a.total_space_topology _ (π E) :=
begin
letI := a.total_space_topology,
letI := a.fiber_topology,
letI := a.to_fiber_bundle,
exact continuous_proj F E,
end
/-- For a fiber bundle `E` over `B` constructed using the `fiber_prebundle` mechanism,
continuity of a function `total_space E → X` on an open set `s` can be checked by precomposing at
each point with the pretrivialization used for the construction at that point. -/
lemma continuous_on_of_comp_right {X : Type*} [topological_space X] {f : total_space E → X}
{s : set B} (hs : is_open s)
(hf : ∀ b ∈ s, continuous_on (f ∘ (a.pretrivialization_at b).to_local_equiv.symm)
((s ∩ (a.pretrivialization_at b).base_set) ×ˢ (set.univ : set F))) :
@continuous_on _ _ a.total_space_topology _ f ((π E) ⁻¹' s) :=
begin
letI := a.total_space_topology,
intros z hz,
let e : trivialization F (π E) :=
a.trivialization_of_mem_pretrivialization_atlas (a.pretrivialization_mem_atlas z.proj),
refine (e.continuous_at_of_comp_right _
((hf z.proj hz).continuous_at (is_open.mem_nhds _ _))).continuous_within_at,
{ exact a.mem_base_pretrivialization_at z.proj },
{ exact ((hs.inter (a.pretrivialization_at z.proj).open_base_set).prod is_open_univ) },
refine ⟨_, mem_univ _⟩,
rw e.coe_fst,
{ exact ⟨hz, a.mem_base_pretrivialization_at z.proj⟩ },
{ rw e.mem_source,
exact a.mem_base_pretrivialization_at z.proj },
end
end fiber_prebundle
|
f58ec86bbdd917b178300e6baa877ee76c4828db | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /library/algebra/field.lean | ff2fe0ba90bf2672ff31fdba4e7f3452427358dc | [
"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 | 18,933 | lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: algebra.field
Authors: Robert Lewis
Structures with multiplicative and additive components, including division rings and fields.
The development is modeled after Isabelle's library.
-/
----------------------------------------------------------------------------------------------------
import logic.eq logic.connectives data.unit data.sigma data.prod
import algebra.function algebra.binary algebra.group algebra.ring
open eq eq.ops
namespace algebra
variable {A : Type}
-- in division rings, 1 / 0 = 0
structure division_ring [class] (A : Type) extends ring A, has_inv A, zero_ne_one_class A :=
(mul_inv_cancel : ∀{a}, a ≠ zero → mul a (inv a) = one)
(inv_mul_cancel : ∀{a}, a ≠ zero → mul (inv a) a = one)
--(inv_zero : inv zero = zero)
section division_ring
variables [s : division_ring A] {a b c : A}
include s
definition divide (a b : A) : A := a * b⁻¹
infix `/` := divide
-- only in this file
local attribute divide [reducible]
theorem mul_inv_cancel (H : a ≠ 0) : a * a⁻¹ = 1 :=
division_ring.mul_inv_cancel H
theorem inv_mul_cancel (H : a ≠ 0) : a⁻¹ * a = 1 :=
division_ring.inv_mul_cancel H
theorem inv_eq_one_div : a⁻¹ = 1 / a := !one_mul⁻¹
-- the following are only theorems if we assume inv_zero here
/- theorem inv_zero : 0⁻¹ = 0 := !division_ring.inv_zero
theorem one_div_zero : 1 / 0 = 0 :=
calc
1 / 0 = 1 * 0⁻¹ : refl
... = 1 * 0 : division_ring.inv_zero A
... = 0 : mul_zero
-/
theorem div_eq_mul_one_div : a / b = a * (1 / b) :=
by rewrite [↑divide, one_mul]
-- theorem div_zero : a / 0 = 0 := by rewrite [div_eq_mul_one_div, one_div_zero, mul_zero]
theorem mul_one_div_cancel (H : a ≠ 0) : a * (1 / a) = 1 :=
by rewrite [-inv_eq_one_div, (mul_inv_cancel H)]
theorem one_div_mul_cancel (H : a ≠ 0) : (1 / a) * a = 1 :=
by rewrite [-inv_eq_one_div, (inv_mul_cancel H)]
theorem div_self (H : a ≠ 0) : a / a = 1 := mul_inv_cancel H
theorem one_div_one : 1 / 1 = 1 := div_self (ne.symm zero_ne_one)
theorem mul_div_assoc : (a * b) / c = a * (b / c) := !mul.assoc
theorem one_div_ne_zero (H : a ≠ 0) : 1 / a ≠ 0 :=
assume H2 : 1 / a = 0,
have C1 : 0 = 1, from symm (by rewrite [-(mul_one_div_cancel H), H2, mul_zero]),
absurd C1 zero_ne_one
-- theorem ne_zero_of_one_div_ne_zero (H : 1 / a ≠ 0) : a ≠ 0 :=
-- assume Ha : a = 0, absurd (Ha⁻¹ ▸ one_div_zero) H
-- the analogue in group is called inv_one
theorem inv_one_is_one : 1⁻¹ = 1 :=
by rewrite [-mul_one, (inv_mul_cancel (ne.symm zero_ne_one))]
theorem div_one : a / 1 = a :=
by rewrite [↑divide, inv_one_is_one, mul_one]
theorem zero_div : 0 / a = 0 := !zero_mul
-- note: integral domain has a "mul_ne_zero". Discrete fields are int domains.
theorem mul_ne_zero' (Ha : a ≠ 0) (Hb : b ≠ 0) : a * b ≠ 0 :=
assume H : a * b = 0,
have C1 : a = 0, by rewrite [-mul_one, -(mul_one_div_cancel Hb), -mul.assoc, H, zero_mul],
absurd C1 Ha
theorem mul_ne_zero_comm (H : a * b ≠ 0) : b * a ≠ 0 :=
have H2 : a ≠ 0 ∧ b ≠ 0, from mul_ne_zero_imp_ne_zero H,
mul_ne_zero' (and.right H2) (and.left H2)
-- make "left" and "right" versions?
theorem eq_one_div_of_mul_eq_one (H : a * b = 1) : b = 1 / a :=
have H2 : a ≠ 0, from
(assume A : a = 0,
have B : 0 = 1, by rewrite [-(zero_mul b), -A, H],
absurd B zero_ne_one),
show b = 1 / a, from symm (calc
1 / a = (1 / a) * 1 : mul_one
... = (1 / a) * (a * b) : H
... = (1 / a) * a * b : mul.assoc
... = 1 * b : one_div_mul_cancel H2
... = b : one_mul)
-- which one is left and which is right?
theorem eq_one_div_of_mul_eq_one_left (H : b * a = 1) : b = 1 / a :=
have H2 : a ≠ 0, from
(assume A : a = 0,
have B : 0 = 1, from symm (calc
1 = b * a : symm H
... = b * 0 : A
... = 0 : mul_zero),
absurd B zero_ne_one),
show b = 1 / a, from symm (calc
1 / a = 1 * (1 / a) : one_mul
... = b * a * (1 / a) : H
... = b * (a * (1 / a)) : mul.assoc
... = b * 1 : mul_one_div_cancel H2
... = b : mul_one)
theorem one_div_mul_one_div (Ha : a ≠ 0) (Hb : b ≠ 0) : (1 / a) * (1 / b) = 1 / (b * a) :=
have H : (b * a) * ((1 / a) * (1 / b)) = 1, by
rewrite [mul.assoc, -(mul.assoc a), (mul_one_div_cancel Ha), one_mul, (mul_one_div_cancel Hb)],
eq_one_div_of_mul_eq_one H
theorem one_div_neg_one_eq_neg_one : 1 / (-1) = -1 :=
have H : (-1) * (-1) = 1, by rewrite [-neg_eq_neg_one_mul, neg_neg],
symm (eq_one_div_of_mul_eq_one H)
theorem one_div_neg_eq_neg_one_div (H : a ≠ 0) : 1 / (- a) = - (1 / a) :=
have H1 : -1 ≠ 0, from
(assume H2 : -1 = 0, absurd (symm (calc
1 = -(-1) : neg_neg
... = -0 : H2
... = 0 : neg_zero)) zero_ne_one),
calc
1 / (- a) = 1 / ((-1) * a) : neg_eq_neg_one_mul
... = (1 / a) * (1 / (- 1)) : one_div_mul_one_div H H1
... = (1 / a) * (-1) : one_div_neg_one_eq_neg_one
... = - (1 / a) : mul_neg_one_eq_neg
theorem div_neg_eq_neg_div (Ha : a ≠ 0) : b / (- a) = - (b / a) :=
calc
b / (- a) = b * (1 / (- a)) : inv_eq_one_div
... = b * -(1 / a) : one_div_neg_eq_neg_one_div Ha
... = -(b * (1 / a)) : neg_mul_eq_mul_neg
... = - (b * a⁻¹) : inv_eq_one_div
theorem neg_div (Ha : a ≠ 0) : (-b) / a = - (b / a) :=
by rewrite [neg_eq_neg_one_mul, mul_div_assoc, -neg_eq_neg_one_mul]
theorem neg_div_neg_eq_div (Hb : b ≠ 0) : (-a) / (-b) = a / b :=
by rewrite [(div_neg_eq_neg_div Hb), (neg_div Hb), neg_neg]
theorem div_div (H : a ≠ 0) : 1 / (1 / a) = a :=
symm (eq_one_div_of_mul_eq_one_left (mul_one_div_cancel H))
theorem eq_of_invs_eq (Ha : a ≠ 0) (Hb : b ≠ 0) (H : 1 / a = 1 / b) : a = b :=
by rewrite [-(div_div Ha), H, (div_div Hb)]
-- oops, the analogous theorem in group is called inv_mul, but it *should* be called
-- mul_inv, in which case, we will have to rename this one
theorem mul_inv (Ha : a ≠ 0) (Hb : b ≠ 0) : (b * a)⁻¹ = a⁻¹ * b⁻¹ :=
have H1 : b * a ≠ 0, from mul_ne_zero' Hb Ha,
eq.symm (calc
a⁻¹ * b⁻¹ = (1 / a) * b⁻¹ : inv_eq_one_div
... = (1 / a) * (1 / b) : inv_eq_one_div
... = (1 / (b * a)) : one_div_mul_one_div Ha Hb
... = (b * a)⁻¹ : inv_eq_one_div)
theorem mul_div_cancel (Hb : b ≠ 0) : a * b / b = a :=
by rewrite [↑divide, mul.assoc, (mul_inv_cancel Hb), mul_one]
theorem div_mul_cancel (Hb : b ≠ 0) : a / b * b = a :=
by rewrite [↑divide, mul.assoc, (inv_mul_cancel Hb), mul_one]
theorem div_add_div_same : a / c + b / c = (a + b) / c := !right_distrib⁻¹
theorem inv_mul_add_mul_inv_eq_inv_add_inv (Ha : a ≠ 0) (Hb : b ≠ 0) :
(1 / a) * (a + b) * (1 / b) = 1 / a + 1 / b :=
by rewrite [(left_distrib (1 / a)), (one_div_mul_cancel Ha), right_distrib, one_mul,
mul.assoc, (mul_one_div_cancel Hb), mul_one, add.comm]
theorem inv_mul_sub_mul_inv_eq_inv_add_inv (Ha : a ≠ 0) (Hb : b ≠ 0) :
(1 / a) * (b - a) * (1 / b) = 1 / a - 1 / b :=
by rewrite [(mul_sub_left_distrib (1 / a)), (one_div_mul_cancel Ha), mul_sub_right_distrib,
one_mul, mul.assoc, (mul_one_div_cancel Hb), mul_one, one_mul]
theorem div_eq_one_iff_eq (Hb : b ≠ 0) : a / b = 1 ↔ a = b :=
iff.intro
(assume H1 : a / b = 1, symm (calc
b = 1 * b : one_mul
... = a / b * b : H1
... = a : div_mul_cancel Hb))
(assume H2 : a = b, calc
a / b = b / b : H2
... = 1 : div_self Hb)
theorem eq_div_iff_mul_eq (Hc : c ≠ 0) : a = b / c ↔ a * c = b :=
iff.intro
(assume H : a = b / c, by rewrite [H, (div_mul_cancel Hc)])
(assume H : a * c = b, by rewrite [-(mul_div_cancel Hc), H])
theorem add_div_eq_mul_add_div (Hc : c ≠ 0) : a + b / c = (a * c + b) / c :=
have H : (a + b / c) * c = a * c + b, by rewrite [right_distrib, (div_mul_cancel Hc)],
(iff.elim_right (eq_div_iff_mul_eq Hc)) H
theorem mul_mul_div (Hc : c ≠ 0) : a = a * c * (1 / c) :=
calc
a = a * 1 : mul_one
... = a * (c * (1 / c)) : mul_one_div_cancel Hc
... = a * c * (1 / c) : mul.assoc
-- There are many similar rules to these last two in the Isabelle library
-- that haven't been ported yet. Do as necessary.
end division_ring
structure field [class] (A : Type) extends division_ring A, comm_ring A
section field
variables [s : field A] {a b c d: A}
include s
local attribute divide [reducible]
theorem one_div_mul_one_div' (Ha : a ≠ 0) (Hb : b ≠ 0) : (1 / a) * (1 / b) = 1 / (a * b) :=
by rewrite [(one_div_mul_one_div Ha Hb), mul.comm b]
theorem div_mul_right (Hb : b ≠ 0) (H : a * b ≠ 0) : a / (a * b) = 1 / b :=
let Ha : a ≠ 0 := and.left (mul_ne_zero_imp_ne_zero H) in
symm (calc
1 / b = 1 * (1 / b) : one_mul
... = (a * a⁻¹) * (1 / b) : mul_inv_cancel Ha
... = a * (a⁻¹ * (1 / b)) : mul.assoc
... = a * ((1 / a) * (1 / b)) :inv_eq_one_div
... = a * (1 / (b * a)) : one_div_mul_one_div Ha Hb
... = a * (1 / (a * b)) : mul.comm
... = a * (a * b)⁻¹ : inv_eq_one_div)
theorem div_mul_left (Ha : a ≠ 0) (H : a * b ≠ 0) : b / (a * b) = 1 / a :=
let H1 : b * a ≠ 0 := mul_ne_zero_comm H in
by rewrite [mul.comm a, (div_mul_right Ha H1)]
theorem mul_div_cancel_left (Ha : a ≠ 0) : a * b / a = b :=
by rewrite [mul.comm a, (mul_div_cancel Ha)]
theorem mul_div_cancel' (Hb : b ≠ 0) : b * (a / b) = a :=
by rewrite [mul.comm, (div_mul_cancel Hb)]
theorem one_div_add_one_div (Ha : a ≠ 0) (Hb : b ≠ 0) : 1 / a + 1 / b = (a + b) / (a * b) :=
have H [visible] : a * b ≠ 0, from (mul_ne_zero' Ha Hb),
by rewrite [add.comm, -(div_mul_left Ha H), -(div_mul_right Hb H), ↑divide, -right_distrib]
theorem div_mul_div (Hb : b ≠ 0) (Hd : d ≠ 0) : (a / b) * (c / d) = (a * c) / (b * d) :=
by rewrite [↑divide, 2 mul.assoc, (mul.comm b⁻¹), mul.assoc, (mul_inv Hd Hb)]
theorem mul_div_mul_left (Hb : b ≠ 0) (Hc : c ≠ 0) : (c * a) / (c * b) = a / b :=
have H [visible] : c * b ≠ 0, from mul_ne_zero' Hc Hb,
by rewrite [-(div_mul_div Hc Hb), (div_self Hc), one_mul]
theorem mul_div_mul_right (Hb : b ≠ 0) (Hc : c ≠ 0) : (a * c) / (b * c) = a / b :=
by rewrite [(mul.comm a), (mul.comm b), (mul_div_mul_left Hb Hc)]
theorem div_mul_eq_mul_div : (b / c) * a = (b * a) / c :=
by rewrite [↑divide, mul.assoc, (mul.comm c⁻¹), -mul.assoc]
-- this one is odd -- I am not sure what to call it, but again, the prefix is right
theorem div_mul_eq_mul_div_comm (Hc : c ≠ 0) : (b / c) * a = b * (a / c) :=
by rewrite [(div_mul_eq_mul_div), -(one_mul c), -(div_mul_div (ne.symm zero_ne_one) Hc), div_one, one_mul]
theorem div_add_div (Hb : b ≠ 0) (Hd : d ≠ 0) :
(a / b) + (c / d) = ((a * d) + (b * c)) / (b * d) :=
have H [visible] : b * d ≠ 0, from mul_ne_zero' Hb Hd,
by rewrite [-(mul_div_mul_right Hb Hd), -(mul_div_mul_left Hd Hb), div_add_div_same]
theorem div_sub_div (Hb : b ≠ 0) (Hd : d ≠ 0) :
(a / b) - (c / d) = ((a * d) - (b * c)) / (b * d) :=
by rewrite [↑sub, neg_eq_neg_one_mul, -mul_div_assoc, (div_add_div Hb Hd),
-mul.assoc, (mul.comm b), mul.assoc, -neg_eq_neg_one_mul]
theorem mul_eq_mul_of_div_eq_div (Hb : b ≠ 0) (Hd : d ≠ 0) (H : a / b = c / d) : a * d = c * b :=
by rewrite [-mul_one, mul.assoc, (mul.comm d), -mul.assoc, -(div_self Hb),
-(div_mul_eq_mul_div_comm Hb), H, (div_mul_eq_mul_div), (div_mul_cancel Hd)]
theorem one_div_div (Ha : a ≠ 0) (Hb : b ≠ 0) : 1 / (a / b) = b / a :=
have H : (a / b) * (b / a) = 1, from calc
(a / b) * (b / a) = (a * b) / (b * a) : div_mul_div Hb Ha
... = (a * b) / (a * b) : mul.comm
... = 1 : div_self (mul_ne_zero' Ha Hb),
symm (eq_one_div_of_mul_eq_one H)
theorem div_div_eq_mul_div (Hb : b ≠ 0) (Hc : c ≠ 0) : a / (b / c) = (a * c) / b :=
by rewrite [div_eq_mul_one_div, (one_div_div Hb Hc), -mul_div_assoc]
theorem div_div_eq_div_mul (Hb : b ≠ 0) (Hc : c ≠ 0) : (a / b) / c = a / (b * c) :=
by rewrite [div_eq_mul_one_div, (div_mul_div Hb Hc), mul_one]
theorem div_div_div_div (Hb : b ≠ 0) (Hc : c ≠ 0) (Hd : d ≠ 0) : (a / b) / (c / d) = (a * d) / (b * c) :=
by rewrite [(div_div_eq_mul_div Hc Hd), (div_mul_eq_mul_div), (div_div_eq_div_mul Hb Hc)]
-- remaining to transfer from Isabelle fields: ordered fields
end field
structure discrete_field [class] (A : Type) extends field A :=
(has_decidable_eq : decidable_eq A)
(inv_zero : inv zero = zero)
attribute discrete_field.has_decidable_eq [instance]
section discrete_field
variable [s : discrete_field A]
include s
variables {a b c d : A}
-- many of the theorems in discrete_field are the same as theorems in field or division ring,
-- but with fewer hypotheses since 0⁻¹ = 0 and equality is decidable.
-- they are named with '. Is there a better convention?
theorem discrete_field.eq_zero_or_eq_zero_of_mul_eq_zero
(x y : A) (H : x * y = 0) : x = 0 ∨ y = 0 :=
decidable.by_cases
(assume H : x = 0, or.inl H)
(assume H1 : x ≠ 0,
or.inr (by rewrite [-one_mul, -(inv_mul_cancel H1), mul.assoc, H, mul_zero]))
definition discrete_field.to_integral_domain [instance] [reducible] [coercion] :
integral_domain A :=
⦃ integral_domain, s,
eq_zero_or_eq_zero_of_mul_eq_zero := discrete_field.eq_zero_or_eq_zero_of_mul_eq_zero⦄
theorem inv_zero : 0⁻¹ = 0 := !discrete_field.inv_zero
theorem one_div_zero : 1 / 0 = 0 :=
calc
1 / 0 = 1 * 0⁻¹ : refl
... = 1 * 0 : discrete_field.inv_zero A
... = 0 : mul_zero
theorem div_zero : a / 0 = 0 := by rewrite [div_eq_mul_one_div, one_div_zero, mul_zero]
theorem ne_zero_of_one_div_ne_zero (H : 1 / a ≠ 0) : a ≠ 0 :=
assume Ha : a = 0, absurd (Ha⁻¹ ▸ one_div_zero) H
theorem inv_zero_imp_zero (H : 1 / a = 0) : a = 0 :=
decidable.by_cases
(assume Ha, Ha)
(assume Ha, false.elim ((one_div_ne_zero Ha) H))
-- the following could all go in "discrete_division_ring"
theorem one_div_mul_one_div'' : (1 / a) * (1 / b) = 1 / (b * a) :=
decidable.by_cases
(assume Ha : a = 0,
by rewrite [Ha, div_zero, zero_mul, -(@div_zero A s 1), mul_zero b])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0,
by rewrite [Hb, div_zero, mul_zero, -(@div_zero A s 1), zero_mul a])
(assume Hb : b ≠ 0, one_div_mul_one_div Ha Hb))
theorem one_div_neg_eq_neg_one_div' : 1 / (- a) = - (1 / a) :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, neg_zero, 2 div_zero, neg_zero])
(assume Ha : a ≠ 0, one_div_neg_eq_neg_one_div Ha)
theorem neg_div' : (-b) / a = - (b / a) :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, 2 div_zero, neg_zero])
(assume Ha : a ≠ 0, neg_div Ha)
theorem neg_div_neg_eq_div' : (-a) / (-b) = a / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, neg_zero, 2 div_zero])
(assume Hb : b ≠ 0, neg_div_neg_eq_div Hb)
theorem div_div' : 1 / (1 / a) = a :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, 2 div_zero])
(assume Ha : a ≠ 0, div_div Ha)
theorem eq_of_invs_eq' (H : 1 / a = 1 / b) : a = b :=
decidable.by_cases
(assume Ha : a = 0,
have Hb : b = 0, from inv_zero_imp_zero (by rewrite [-H, Ha, div_zero]),
Hb⁻¹ ▸ Ha)
(assume Ha : a ≠ 0,
have Hb : b ≠ 0, from ne_zero_of_one_div_ne_zero (H ▸ (one_div_ne_zero Ha)),
eq_of_invs_eq Ha Hb H)
theorem mul_inv' : (b * a)⁻¹ = a⁻¹ * b⁻¹ :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, mul_zero, 2 inv_zero, zero_mul])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, zero_mul, 2 inv_zero, mul_zero])
(assume Hb : b ≠ 0, mul_inv Ha Hb))
-- the following are specifically for fields
theorem one_div_mul_one_div''' : (1 / a) * (1 / b) = 1 / (a * b) :=
by rewrite [(one_div_mul_one_div''), mul.comm b]
theorem div_mul_right' (Ha : a ≠ 0) : a / (a * b) = 1 / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, mul_zero, 2 div_zero])
(assume Hb : b ≠ 0, div_mul_right Hb (mul_ne_zero Ha Hb))
theorem div_mul_left' (Hb : b ≠ 0) : b / (a * b) = 1 / a :=
by rewrite [mul.comm a, div_mul_right' Hb]
theorem div_mul_div' : (a / b) * (c / d) = (a * c) / (b * d) :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, div_zero, zero_mul, -(@div_zero A s (a * c)), zero_mul])
(assume Hb : b ≠ 0,
decidable.by_cases
(assume Hd : d = 0, by rewrite [Hd, div_zero, mul_zero, -(@div_zero A s (a * c)), mul_zero])
(assume Hd : d ≠ 0, div_mul_div Hb Hd))
theorem mul_div_mul_left' (Hc : c ≠ 0) : (c * a) / (c * b) = a / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, mul_zero, 2 div_zero])
(assume Hb : b ≠ 0, mul_div_mul_left Hb Hc)
theorem mul_div_mul_right' (Hc : c ≠ 0) : (a * c) / (b * c) = a / b :=
by rewrite [(mul.comm a), (mul.comm b), (mul_div_mul_left' Hc)]
-- this one is odd -- I am not sure what to call it, but again, the prefix is right
theorem div_mul_eq_mul_div_comm' : (b / c) * a = b * (a / c) :=
decidable.by_cases
(assume Hc : c = 0, by rewrite [Hc, div_zero, zero_mul, -(mul_zero b), -(@div_zero A s a)])
(assume Hc : c ≠ 0, div_mul_eq_mul_div_comm Hc)
theorem one_div_div' : 1 / (a / b) = b / a :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, zero_div, 2 div_zero])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, 2 div_zero, zero_div])
(assume Hb : b ≠ 0, one_div_div Ha Hb))
theorem div_div_eq_mul_div' : a / (b / c) = (a * c) / b :=
by rewrite [div_eq_mul_one_div, one_div_div', -mul_div_assoc]
theorem div_div_eq_div_mul' : (a / b) / c = a / (b * c) :=
by rewrite [div_eq_mul_one_div, div_mul_div', mul_one]
theorem div_div_div_div' : (a / b) / (c / d) = (a * d) / (b * c) :=
by rewrite [div_div_eq_mul_div', div_mul_eq_mul_div, div_div_eq_div_mul']
end discrete_field
end algebra
/-
decidable.by_cases
(assume Ha : a = 0, sorry)
(assume Ha : a ≠ 0, sorry)
-/
|
aa4e6d81022f0f95f3517142742424a424cc5be8 | 82e44445c70db0f03e30d7be725775f122d72f3e | /archive/100-theorems-list/73_ascending_descending_sequences.lean | 340cf538289c55d78204a4ba044eddc3f0ba8efb | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 8,176 | 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 tactic.basic
import data.fintype.basic
/-!
# Erdős–Szekeres theorem
This file proves Theorem 73 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/), also
known as the Erdős–Szekeres theorem: given a sequence of more than `r * s` distinct
values, there is an increasing sequence of length longer than `r` or a decreasing sequence of length
longer than `s`.
We use the proof outlined at
https://en.wikipedia.org/wiki/Erdos-Szekeres_theorem#Pigeonhole_principle.
## Tags
sequences, increasing, decreasing, Ramsey, Erdos-Szekeres, Erdős–Szekeres, Erdős-Szekeres
-/
variables {α : Type*} [linear_order α] {β : Type*}
open function finset
open_locale classical
/--
**Erdős–Szekeres Theorem**: Given a sequence of more than `r * s` distinct values, there is an
increasing sequence of length longer than `r` or a decreasing sequence of length longer than `s`.
Proof idea:
We label each value in the sequence with two numbers specifying the longest increasing
subsequence ending there, and the longest decreasing subsequence ending there.
We then show the pair of labels must be unique. Now if there is no increasing sequence longer than
`r` and no decreasing sequence longer than `s`, then there are at most `r * s` possible labels,
which is a contradiction if there are more than `r * s` elements.
-/
theorem erdos_szekeres {r s n : ℕ} {f : fin n → α} (hn : r * s < n) (hf : injective f) :
(∃ (t : finset (fin n)), r < t.card ∧ strict_mono_incr_on f ↑t) ∨
(∃ (t : finset (fin n)), s < t.card ∧ strict_mono_decr_on f ↑t) :=
begin
-- Given an index `i`, produce the set of increasing (resp., decreasing) subsequences which ends
-- at `i`.
let inc_sequences_ending_in : fin n → finset (finset (fin n)) :=
λ i, univ.powerset.filter (λ t, finset.max t = some i ∧ strict_mono_incr_on f ↑t),
let dec_sequences_ending_in : fin n → finset (finset (fin n)) :=
λ i, univ.powerset.filter (λ t, finset.max t = some i ∧ strict_mono_decr_on f ↑t),
-- The singleton sequence is in both of the above collections.
-- (This is useful to show that the maximum length subsequence is at least 1, and that the set
-- of subsequences is nonempty.)
have inc_i : ∀ i, {i} ∈ inc_sequences_ending_in i := λ i, by simp [strict_mono_incr_on],
have dec_i : ∀ i, {i} ∈ dec_sequences_ending_in i := λ i, by simp [strict_mono_decr_on],
-- Define the pair of labels: at index `i`, the pair is the maximum length of an increasing
-- subsequence ending at `i`, paired with the maximum length of a decreasing subsequence ending
-- at `i`.
-- We call these labels `(a_i, b_i)`.
let ab : fin n → ℕ × ℕ,
{ intro i,
apply (max' ((inc_sequences_ending_in i).image card) (nonempty.image ⟨{i}, inc_i i⟩ _),
max' ((dec_sequences_ending_in i).image card) (nonempty.image ⟨{i}, dec_i i⟩ _)) },
-- It now suffices to show that one of the labels is 'big' somewhere. In particular, if the
-- first in the pair is more than `r` somewhere, then we have an increasing subsequence in our
-- set, and if the second is more than `s` somewhere, then we have a decreasing subsequence.
suffices : ∃ i, r < (ab i).1 ∨ s < (ab i).2,
{ obtain ⟨i, hi⟩ := this,
apply or.imp _ _ hi,
work_on_goal 0 { have : (ab i).1 ∈ _ := max'_mem _ _ },
work_on_goal 1 { have : (ab i).2 ∈ _ := max'_mem _ _ },
all_goals
{ intro hi,
rw mem_image at this,
obtain ⟨t, ht₁, ht₂⟩ := this,
refine ⟨t, by rwa ht₂, _⟩,
rw mem_filter at ht₁,
apply ht₁.2.2 } },
-- Show first that the pair of labels is unique.
have : injective ab,
{ apply injective_of_lt_imp_ne,
intros i j k q,
injection q with q₁ q₂,
-- We have two cases: `f i < f j` or `f j < f i`.
-- In the former we'll show `a_i < a_j`, and in the latter we'll show `b_i < b_j`.
cases lt_or_gt_of_ne (λ _, ne_of_lt ‹i < j› (hf ‹f i = f j›)),
work_on_goal 0 { apply ne_of_lt _ q₁, have : (ab i).1 ∈ _ := max'_mem _ _ },
work_on_goal 1 { apply ne_of_lt _ q₂, have : (ab i).2 ∈ _ := max'_mem _ _ },
all_goals
{ -- Reduce to showing there is a subsequence of length `a_i + 1` which ends at `j`.
rw nat.lt_iff_add_one_le,
apply le_max',
rw mem_image at this ⊢,
-- In particular we take the subsequence `t` of length `a_i` which ends at `i`, by definition
-- of `a_i`
rcases this with ⟨t, ht₁, ht₂⟩,
rw mem_filter at ht₁,
-- Ensure `t` ends at `i`.
have : i ∈ t.max,
simp [ht₁.2.1],
-- Now our new subsequence is given by adding `j` at the end of `t`.
refine ⟨insert j t, _, _⟩,
-- First make sure it's valid, i.e., that this subsequence ends at `j` and is increasing
{ rw mem_filter,
refine ⟨_, _, _⟩,
{ rw mem_powerset, apply subset_univ },
-- It ends at `j` since `i < j`.
{ convert max_insert,
rw [ht₁.2.1, option.lift_or_get_some_some, max_eq_left, with_top.some_eq_coe],
apply le_of_lt ‹i < j› },
-- To show it's increasing (i.e., `f` is monotone increasing on `t.insert j`), we do cases
-- on what the possibilities could be - either in `t` or equals `j`.
simp only [strict_mono_incr_on, strict_mono_decr_on, coe_insert, set.mem_insert_iff,
mem_coe],
-- Most of the cases are just bashes.
rintros x ⟨rfl | _⟩ y ⟨rfl | _⟩ _,
{ apply (irrefl _ ‹j < j›).elim },
{ exfalso,
apply not_le_of_lt (trans ‹i < j› ‹j < y›) (le_max_of_mem ‹y ∈ t› ‹i ∈ t.max›) },
{ apply lt_of_le_of_lt _ ‹f i < f j› <|> apply lt_of_lt_of_le ‹f j < f i› _,
rcases lt_or_eq_of_le (le_max_of_mem ‹x ∈ t› ‹i ∈ t.max›) with _ | rfl,
{ apply le_of_lt (ht₁.2.2 ‹x ∈ t› (mem_of_max ‹i ∈ t.max›) ‹x < i›) },
{ refl } },
{ apply ht₁.2.2 ‹x ∈ t› ‹y ∈ t› ‹x < y› } },
-- Finally show that this new subsequence is one longer than the old one.
{ rw [card_insert_of_not_mem, ht₂],
intro _,
apply not_le_of_lt ‹i < j› (le_max_of_mem ‹j ∈ t› ‹i ∈ t.max›) } } },
-- Finished both goals!
-- Now that we have uniqueness of each label, it remains to do some counting to finish off.
-- Suppose all the labels are small.
by_contra q,
push_neg at q,
-- Then the labels `(a_i, b_i)` all fit in the following set: `{ (x,y) | 1 ≤ x ≤ r, 1 ≤ y ≤ s }`
let ran : finset (ℕ × ℕ) := ((range r).image nat.succ).product ((range s).image nat.succ),
-- which we prove here.
have : image ab univ ⊆ ran,
-- First some logical shuffling
{ rintro ⟨x₁, x₂⟩,
simp only [mem_image, exists_prop, mem_range, mem_univ, mem_product, true_and, prod.mk.inj_iff],
rintros ⟨i, rfl, rfl⟩,
specialize q i,
-- Show `1 ≤ a_i` and `1 ≤ b_i`, which is easy from the fact that `{i}` is a increasing and
-- decreasing subsequence which we did right near the top.
have z : 1 ≤ (ab i).1 ∧ 1 ≤ (ab i).2,
{ split;
{ apply le_max',
rw mem_image,
refine ⟨{i}, by solve_by_elim, card_singleton i⟩ } },
refine ⟨_, _⟩,
-- Need to get `a_i ≤ r`, here phrased as: there is some `a < r` with `a+1 = a_i`.
{ refine ⟨(ab i).1 - 1, _, nat.succ_pred_eq_of_pos z.1⟩,
rw nat.sub_lt_right_iff_lt_add z.1,
apply nat.lt_succ_of_le q.1 },
{ refine ⟨(ab i).2 - 1, _, nat.succ_pred_eq_of_pos z.2⟩,
rw nat.sub_lt_right_iff_lt_add z.2,
apply nat.lt_succ_of_le q.2 } },
-- To get our contradiction, it suffices to prove `n ≤ r * s`
apply not_le_of_lt hn,
-- Which follows from considering the cardinalities of the subset above, since `ab` is injective.
simpa [nat.succ_injective, card_image_of_injective, ‹injective ab›] using card_le_of_subset this,
end
|
c4574f4298eb2e56ca8339fa3e1fb13e0f0314fb | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /stage0/src/Lean/Elab/Tactic.lean | ee1081c5a8ce5575c8b715eb2c0451e4a464e4e5 | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 495 | 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, Sebastian Ullrich
-/
import Lean.Elab.Term
import Lean.Elab.Tactic.Basic
import Lean.Elab.Tactic.ElabTerm
import Lean.Elab.Tactic.Induction
import Lean.Elab.Tactic.Generalize
import Lean.Elab.Tactic.Injection
import Lean.Elab.Tactic.Match
import Lean.Elab.Tactic.Rewrite
import Lean.Elab.Tactic.Location
import Lean.Elab.Tactic.Simp
|
3a812729926f611f0c2a7c5c006ecd896ce8ac5e | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/topology/sheaves/sheaf_condition/opens_le_cover.lean | e9ce631adaf3af77181df5b98a0c4a940631545f | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,473 | 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 topology.sheaves.presheaf
import category_theory.limits.final
import topology.sheaves.sheaf_condition.pairwise_intersections
/-!
# Another version of the sheaf condition.
Given a family of open sets `U : ι → opens X` we can form the subcategory
`{ V : opens X // ∃ i, V ≤ U i }`, which has `supr U` as a cocone.
The sheaf condition on a presheaf `F` is equivalent to
`F` sending the opposite of this cocone to a limit cone in `C`, for every `U`.
This condition is particularly nice when checking the sheaf condition
because we don't need to do any case bashing
(depending on whether we're looking at single or double intersections,
or equivalently whether we're looking at the first or second object in an equalizer diagram).
## References
* This is the definition Lurie uses in [Spectral Algebraic Geometry][LurieSAG].
-/
universes v u
noncomputable theory
open category_theory
open category_theory.limits
open topological_space
open opposite
open topological_space.opens
namespace Top
variables {C : Type u} [category.{v} C]
variables {X : Top.{v}} (F : presheaf C X) {ι : Type v} (U : ι → opens X)
namespace presheaf
namespace sheaf_condition
/--
The category of open sets contained in some element of the cover.
-/
def opens_le_cover : Type v := { V : opens X // ∃ i, V ≤ U i }
instance [inhabited ι] : inhabited (opens_le_cover U) :=
⟨⟨⊥, default ι, bot_le⟩⟩
instance : category (opens_le_cover U) := category_theory.full_subcategory _
namespace opens_le_cover
variables {U}
/--
An arbitrarily chosen index such that `V ≤ U i`.
-/
def index (V : opens_le_cover U) : ι := V.property.some
/--
The morphism from `V` to `U i` for some `i`.
-/
def hom_to_index (V : opens_le_cover U) : V.val ⟶ U (index V) :=
(V.property.some_spec).hom
end opens_le_cover
/--
`supr U` as a cocone over the opens sets contained in some element of the cover.
(In fact this is a colimit cocone.)
-/
def opens_le_cover_cocone : cocone (full_subcategory_inclusion _ : opens_le_cover U ⥤ opens X) :=
{ X := supr U,
ι := { app := λ V : opens_le_cover U, V.hom_to_index ≫ opens.le_supr U _, } }
end sheaf_condition
open sheaf_condition
/--
An equivalent formulation of the sheaf condition
(which we prove equivalent to the usual one below as
`sheaf_condition_equiv_sheaf_condition_opens_le_cover`).
A presheaf is a sheaf if `F` sends the cone `(opens_le_cover_cocone U).op` to a limit cone.
(Recall `opens_le_cover_cocone U`, has cone point `supr U`,
mapping down to any `V` which is contained in some `U i`.)
-/
def is_sheaf_opens_le_cover : Prop :=
∀ ⦃ι : Type v⦄ (U : ι → opens X), nonempty (is_limit (F.map_cone (opens_le_cover_cocone U).op))
namespace sheaf_condition
open category_theory.pairwise
/--
Implementation detail:
the object level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U`
-/
@[simp]
def pairwise_to_opens_le_cover_obj : pairwise ι → opens_le_cover U
| (single i) := ⟨U i, ⟨i, le_refl _⟩⟩
| (pair i j) := ⟨U i ⊓ U j, ⟨i, inf_le_left⟩⟩
open category_theory.pairwise.hom
/--
Implementation detail:
the morphism level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U`
-/
def pairwise_to_opens_le_cover_map :
Π {V W : pairwise ι},
(V ⟶ W) → (pairwise_to_opens_le_cover_obj U V ⟶ pairwise_to_opens_le_cover_obj U W)
| _ _ (id_single i) := 𝟙 _
| _ _ (id_pair i j) := 𝟙 _
| _ _ (left i j) := hom_of_le inf_le_left
| _ _ (right i j) := hom_of_le inf_le_right
/--
The category of single and double intersections of the `U i` maps into the category
of open sets below some `U i`.
-/
@[simps]
def pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U :=
{ obj := pairwise_to_opens_le_cover_obj U,
map := λ V W i, pairwise_to_opens_le_cover_map U i, }
instance (V : opens_le_cover U) :
nonempty (structured_arrow V (pairwise_to_opens_le_cover U)) :=
⟨{ right := single (V.index), hom := V.hom_to_index }⟩
/--
The diagram consisting of the `U i` and `U i ⊓ U j` is cofinal in the diagram
of all opens contained in some `U i`.
-/
-- This is a case bash: for each pair of types of objects in `pairwise ι`,
-- we have to explicitly construct a zigzag.
instance : functor.final (pairwise_to_opens_le_cover U) :=
⟨λ V, is_connected_of_zigzag $ λ A B, begin
rcases A with ⟨⟨⟩, ⟨i⟩|⟨i,j⟩, a⟩;
rcases B with ⟨⟨⟩, ⟨i'⟩|⟨i',j'⟩, b⟩;
dsimp at *,
{ refine ⟨[
{ left := punit.star, right := pair i i',
hom := (le_inf a.le b.le).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil) },
{ refine ⟨[
{ left := punit.star, right := pair i' i,
hom := (le_inf (b.le.trans inf_le_left) a.le).hom, },
{ left := punit.star, right := single i',
hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := right i' i, }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i' i, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil)) },
{ refine ⟨[
{ left := punit.star, right := single i,
hom := (a.le.trans inf_le_left).hom, },
{ left := punit.star, right := pair i i', hom :=
(le_inf (a.le.trans inf_le_left) b.le).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil)) },
{ refine ⟨[
{ left := punit.star, right := single i,
hom := (a.le.trans inf_le_left).hom, },
{ left := punit.star, right := pair i i',
hom := (le_inf (a.le.trans inf_le_left) (b.le.trans inf_le_left)).hom, },
{ left := punit.star, right := single i',
hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil))), },
end⟩
/--
The diagram in `opens X` indexed by pairwise intersections from `U` is isomorphic
(in fact, equal) to the diagram factored through `opens_le_cover U`.
-/
def pairwise_diagram_iso :
pairwise.diagram U ≅
pairwise_to_opens_le_cover U ⋙ full_subcategory_inclusion _ :=
{ hom := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, },
inv := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, }, }
/--
The cocone `pairwise.cocone U` with cocone point `supr U` over `pairwise.diagram U` is isomorphic
to the cocone `opens_le_cover_cocone U` (with the same cocone point)
after appropriate whiskering and postcomposition.
-/
def pairwise_cocone_iso :
(pairwise.cocone U).op ≅
(cones.postcompose_equivalence (nat_iso.op (pairwise_diagram_iso U : _) : _)).functor.obj
((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op) :=
cones.ext (iso.refl _) (by tidy)
end sheaf_condition
open sheaf_condition
/--
The sheaf condition
in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }`
is equivalent to the reformulation
in terms of a limit diagram over `U i` and `U i ⊓ U j`.
-/
lemma is_sheaf_opens_le_cover_iff_is_sheaf_pairwise_intersections (F : presheaf C X) :
F.is_sheaf_opens_le_cover ↔ F.is_sheaf_pairwise_intersections :=
forall_congr (λ ι, forall_congr (λ U, equiv.nonempty_congr $
calc is_limit (F.map_cone (opens_le_cover_cocone U).op)
≃ is_limit ((F.map_cone (opens_le_cover_cocone U).op).whisker (pairwise_to_opens_le_cover U).op)
: (functor.initial.is_limit_whisker_equiv (pairwise_to_opens_le_cover U).op _).symm
... ≃ is_limit (F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op))
: is_limit.equiv_iso_limit F.map_cone_whisker.symm
... ≃ is_limit ((cones.postcompose_equivalence _).functor.obj
(F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op)))
: (is_limit.postcompose_hom_equiv _ _).symm
... ≃ is_limit (F.map_cone ((cones.postcompose_equivalence _).functor.obj
((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op)))
: is_limit.equiv_iso_limit (functor.map_cone_postcompose_equivalence_functor _).symm
... ≃ is_limit (F.map_cone (pairwise.cocone U).op)
: is_limit.equiv_iso_limit
((cones.functoriality _ _).map_iso (pairwise_cocone_iso U : _).symm)))
variables [has_products C]
/--
The sheaf condition in terms of an equalizer diagram is equivalent
to the reformulation in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }`.
-/
lemma is_sheaf_iff_is_sheaf_opens_le_cover (F : presheaf C X) :
F.is_sheaf ↔ F.is_sheaf_opens_le_cover :=
iff.trans
(is_sheaf_iff_is_sheaf_pairwise_intersections F)
(is_sheaf_opens_le_cover_iff_is_sheaf_pairwise_intersections F).symm
end presheaf
end Top
|
b00d87e9d5c416532465bca34832392cead122f2 | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /doc/demo/add_assoc.lean | 736e70c25a875843dde96ce10d3760a1876a2910 | [
"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 | 432 | lean | import tactic
using Nat
rewrite_set basic
add_rewrite add_zerol add_succl eq_id : basic
theorem add_assoc (a b c : Nat) : a + (b + c) = (a + b) + c
:= induction_on a
(have 0 + (b + c) = (0 + b) + c :
by simp basic)
(λ (n : Nat) (iH : n + (b + c) = (n + b) + c),
have (n + 1) + (b + c) = ((n + 1) + b) + c :
by simp basic)
exit
check add_zerol
check add_succl
check @eq_id
print environment 1 |
c2b254156ac0a734826c9ce8500a96e39b2fa73e | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/multiset/locally_finite.lean | 988094e14a91715543cbe4e557875eb30f137ffd | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 8,515 | 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.finset.locally_finite
/-!
# Intervals as multisets
This file provides basic results about all the `multiset.Ixx`, which are defined in
`order.locally_finite`.
Note that intervals of multisets themselves (`multiset.locally_finite_order`) are defined elsewhere.
-/
variables {α : Type*}
namespace multiset
section preorder
variables [preorder α] [locally_finite_order α] {a b c : α}
lemma nodup_Icc : (Icc a b).nodup := finset.nodup _
lemma nodup_Ico : (Ico a b).nodup := finset.nodup _
lemma nodup_Ioc : (Ioc a b).nodup := finset.nodup _
lemma nodup_Ioo : (Ioo a b).nodup := finset.nodup _
@[simp] lemma Icc_eq_zero_iff : Icc a b = 0 ↔ ¬a ≤ b :=
by rw [Icc, finset.val_eq_zero, finset.Icc_eq_empty_iff]
@[simp] lemma Ico_eq_zero_iff : Ico a b = 0 ↔ ¬a < b :=
by rw [Ico, finset.val_eq_zero, finset.Ico_eq_empty_iff]
@[simp] lemma Ioc_eq_zero_iff : Ioc a b = 0 ↔ ¬a < b :=
by rw [Ioc, finset.val_eq_zero, finset.Ioc_eq_empty_iff]
@[simp] lemma Ioo_eq_zero_iff [densely_ordered α] : Ioo a b = 0 ↔ ¬a < b :=
by rw [Ioo, finset.val_eq_zero, finset.Ioo_eq_empty_iff]
alias Icc_eq_zero_iff ↔ _ Icc_eq_zero
alias Ico_eq_zero_iff ↔ _ Ico_eq_zero
alias Ioc_eq_zero_iff ↔ _ Ioc_eq_zero
@[simp] lemma Ioo_eq_zero (h : ¬a < b) : Ioo a b = 0 :=
eq_zero_iff_forall_not_mem.2 $ λ x hx, h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2)
@[simp] lemma Icc_eq_zero_of_lt (h : b < a) : Icc a b = 0 := Icc_eq_zero h.not_le
@[simp] lemma Ico_eq_zero_of_le (h : b ≤ a) : Ico a b = 0 := Ico_eq_zero h.not_lt
@[simp] lemma Ioc_eq_zero_of_le (h : b ≤ a) : Ioc a b = 0 := Ioc_eq_zero h.not_lt
@[simp] lemma Ioo_eq_zero_of_le (h : b ≤ a) : Ioo a b = 0 := Ioo_eq_zero h.not_lt
variables (a)
@[simp] lemma Ico_self : Ico a a = 0 := by rw [Ico, finset.Ico_self, finset.empty_val]
@[simp] lemma Ioc_self : Ioc a a = 0 := by rw [Ioc, finset.Ioc_self, finset.empty_val]
@[simp] lemma Ioo_self : Ioo a a = 0 := by rw [Ioo, finset.Ioo_self, finset.empty_val]
variables {a b c}
lemma left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := finset.left_mem_Icc
lemma left_mem_Ico : a ∈ Ico a b ↔ a < b := finset.left_mem_Ico
lemma right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := finset.right_mem_Icc
lemma right_mem_Ioc : b ∈ Ioc a b ↔ a < b := finset.right_mem_Ioc
@[simp] lemma left_not_mem_Ioc : a ∉ Ioc a b := finset.left_not_mem_Ioc
@[simp] lemma left_not_mem_Ioo : a ∉ Ioo a b := finset.left_not_mem_Ioo
@[simp] lemma right_not_mem_Ico : b ∉ Ico a b := finset.right_not_mem_Ico
@[simp] lemma right_not_mem_Ioo : b ∉ Ioo a b := finset.right_not_mem_Ioo
lemma Ico_filter_lt_of_le_left [decidable_pred (< c)] (hca : c ≤ a) :
(Ico a b).filter (λ x, x < c) = ∅ :=
by { rw [Ico, ←finset.filter_val, finset.Ico_filter_lt_of_le_left hca], refl }
lemma Ico_filter_lt_of_right_le [decidable_pred (< c)] (hbc : b ≤ c) :
(Ico a b).filter (λ x, x < c) = Ico a b :=
by rw [Ico, ←finset.filter_val, finset.Ico_filter_lt_of_right_le hbc]
lemma Ico_filter_lt_of_le_right [decidable_pred (< c)] (hcb : c ≤ b) :
(Ico a b).filter (λ x, x < c) = Ico a c :=
by { rw [Ico, ←finset.filter_val, finset.Ico_filter_lt_of_le_right hcb], refl }
lemma Ico_filter_le_of_le_left [decidable_pred ((≤) c)] (hca : c ≤ a) :
(Ico a b).filter (λ x, c ≤ x) = Ico a b :=
by rw [Ico, ←finset.filter_val, finset.Ico_filter_le_of_le_left hca]
lemma Ico_filter_le_of_right_le [decidable_pred ((≤) b)] :
(Ico a b).filter (λ x, b ≤ x) = ∅ :=
by { rw [Ico, ←finset.filter_val, finset.Ico_filter_le_of_right_le], refl }
lemma Ico_filter_le_of_left_le [decidable_pred ((≤) c)] (hac : a ≤ c) :
(Ico a b).filter (λ x, c ≤ x) = Ico c b :=
by { rw [Ico, ←finset.filter_val, finset.Ico_filter_le_of_left_le hac], refl }
end preorder
section partial_order
variables [partial_order α] [locally_finite_order α] {a b : α}
@[simp] lemma Icc_self (a : α) : Icc a a = {a} := by rw [Icc, finset.Icc_self, finset.singleton_val]
lemma Ico_cons_right (h : a ≤ b) : b ::ₘ (Ico a b) = Icc a b :=
by { classical,
rw [Ico, ←finset.insert_val_of_not_mem right_not_mem_Ico, finset.Ico_insert_right h], refl }
lemma Ioo_cons_left (h : a < b) : a ::ₘ (Ioo a b) = Ico a b :=
by { classical,
rw [Ioo, ←finset.insert_val_of_not_mem left_not_mem_Ioo, finset.Ioo_insert_left h], refl }
lemma Ico_disjoint_Ico {a b c d : α} (h : b ≤ c) : (Ico a b).disjoint (Ico c d) :=
λ x hab hbc, by { rw mem_Ico at hab hbc, exact hab.2.not_le (h.trans hbc.1) }
@[simp] lemma Ico_inter_Ico_of_le [decidable_eq α] {a b c d : α} (h : b ≤ c) :
Ico a b ∩ Ico c d = 0 :=
multiset.inter_eq_zero_iff_disjoint.2 $ Ico_disjoint_Ico h
lemma Ico_filter_le_left {a b : α} [decidable_pred (≤ a)] (hab : a < b) :
(Ico a b).filter (λ x, x ≤ a) = {a} :=
by { rw [Ico, ←finset.filter_val, finset.Ico_filter_le_left hab], refl }
lemma card_Ico_eq_card_Icc_sub_one (a b : α) : (Ico a b).card = (Icc a b).card - 1 :=
finset.card_Ico_eq_card_Icc_sub_one _ _
lemma card_Ioc_eq_card_Icc_sub_one (a b : α) : (Ioc a b).card = (Icc a b).card - 1 :=
finset.card_Ioc_eq_card_Icc_sub_one _ _
lemma card_Ioo_eq_card_Ico_sub_one (a b : α) : (Ioo a b).card = (Ico a b).card - 1 :=
finset.card_Ioo_eq_card_Ico_sub_one _ _
lemma card_Ioo_eq_card_Icc_sub_two (a b : α) : (Ioo a b).card = (Icc a b).card - 2 :=
finset.card_Ioo_eq_card_Icc_sub_two _ _
end partial_order
section linear_order
variables [linear_order α] [locally_finite_order α] {a b c d : α}
lemma Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) :
Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
finset.Ico_subset_Ico_iff h
lemma Ico_add_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) :
Ico a b + Ico b c = Ico a c :=
by rw [add_eq_union_iff_disjoint.2 (Ico_disjoint_Ico le_rfl), Ico, Ico, Ico, ←finset.union_val,
finset.Ico_union_Ico_eq_Ico hab hbc]
lemma Ico_inter_Ico : Ico a b ∩ Ico c d = Ico (max a c) (min b d) :=
by rw [Ico, Ico, Ico, ←finset.inter_val, finset.Ico_inter_Ico]
@[simp] lemma Ico_filter_lt (a b c : α) : (Ico a b).filter (λ x, x < c) = Ico a (min b c) :=
by rw [Ico, Ico, ←finset.filter_val, finset.Ico_filter_lt]
@[simp] lemma Ico_filter_le (a b c : α) : (Ico a b).filter (λ x, c ≤ x) = Ico (max a c) b :=
by rw [Ico, Ico, ←finset.filter_val, finset.Ico_filter_le]
@[simp] lemma Ico_sub_Ico_left (a b c : α) : Ico a b - Ico a c = Ico (max a c) b :=
by rw [Ico, Ico, Ico, ←finset.sdiff_val, finset.Ico_diff_Ico_left]
@[simp] lemma Ico_sub_Ico_right (a b c : α) : Ico a b - Ico c b = Ico a (min b c) :=
by rw [Ico, Ico, Ico, ←finset.sdiff_val, finset.Ico_diff_Ico_right]
end linear_order
section ordered_cancel_add_comm_monoid
variables [ordered_cancel_add_comm_monoid α] [has_exists_add_of_le α] [locally_finite_order α]
lemma map_add_left_Icc (a b c : α) : (Icc a b).map ((+) c) = Icc (c + a) (c + b) :=
by { classical, rw [Icc, Icc, ←finset.image_add_left_Icc, finset.image_val,
((finset.nodup _).map $ add_right_injective c).dedup] }
lemma map_add_left_Ico (a b c : α) : (Ico a b).map ((+) c) = Ico (c + a) (c + b) :=
by { classical, rw [Ico, Ico, ←finset.image_add_left_Ico, finset.image_val,
((finset.nodup _).map $ add_right_injective c).dedup] }
lemma map_add_left_Ioc (a b c : α) : (Ioc a b).map ((+) c) = Ioc (c + a) (c + b) :=
by { classical, rw [Ioc, Ioc, ←finset.image_add_left_Ioc, finset.image_val,
((finset.nodup _).map $ add_right_injective c).dedup] }
lemma map_add_left_Ioo (a b c : α) : (Ioo a b).map ((+) c) = Ioo (c + a) (c + b) :=
by { classical, rw [Ioo, Ioo, ←finset.image_add_left_Ioo, finset.image_val,
((finset.nodup _).map $ add_right_injective c).dedup] }
lemma map_add_right_Icc (a b c : α) : (Icc a b).map (λ x, x + c) = Icc (a + c) (b + c) :=
by { simp_rw add_comm _ c, exact map_add_left_Icc _ _ _ }
lemma map_add_right_Ico (a b c : α) : (Ico a b).map (λ x, x + c) = Ico (a + c) (b + c) :=
by { simp_rw add_comm _ c, exact map_add_left_Ico _ _ _ }
lemma map_add_right_Ioc (a b c : α) : (Ioc a b).map (λ x, x + c) = Ioc (a + c) (b + c) :=
by { simp_rw add_comm _ c, exact map_add_left_Ioc _ _ _ }
lemma map_add_right_Ioo (a b c : α) : (Ioo a b).map (λ x, x + c) = Ioo (a + c) (b + c) :=
by { simp_rw add_comm _ c, exact map_add_left_Ioo _ _ _ }
end ordered_cancel_add_comm_monoid
end multiset
|
a8bbbbf1d52c89c10c7792e975997d74e72f5eb8 | 49bd2218ae088932d847f9030c8dbff1c5607bb7 | /src/algebra/module.lean | 45ad58e3d610082252cd8a6221b1a202fbe4c15f | [
"Apache-2.0"
] | permissive | FredericLeRoux/mathlib | e8f696421dd3e4edc8c7edb3369421c8463d7bac | 3645bf8fb426757e0a20af110d1fdded281d286e | refs/heads/master | 1,607,062,870,732 | 1,578,513,186,000 | 1,578,513,186,000 | 231,653,181 | 0 | 0 | Apache-2.0 | 1,578,080,327,000 | 1,578,080,326,000 | null | UTF-8 | Lean | false | false | 17,275 | lean | /-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
Modules over a ring.
## Implementation notes
Throughout the `linear_map` section 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 `linear_map`.
When they can be inferred from the type it is faster to use this method than to use type class inference
-/
import algebra.ring algebra.big_operators group_theory.subgroup group_theory.group_action
open function
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
-- /-- Typeclass for types with a scalar multiplication operation, denoted `•` (`\bu`) -/
-- class has_scalar (α : Type u) (γ : Type v) := (smul : α → γ → γ)
-- infixr ` • `:73 := has_scalar.smul
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A semimodule is a generalization of vector spaces to a scalar semiring.
It consists of a scalar semiring `α` and an additive monoid of "vectors" `β`,
connected by a "scalar multiplication" operation `r • x : β`
(where `r : α` and `x : β`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
class semimodule (α : Type u) (β : Type v) [semiring α]
[add_comm_monoid β] extends distrib_mul_action α β :=
(add_smul : ∀(r s : α) (x : β), (r + s) • x = r • x + s • x)
(zero_smul : ∀x : β, (0 : α) • x = 0)
end prio
section semimodule
variables [R:semiring α] [add_comm_monoid β] [semimodule α β] (r s : α) (x y : β)
include R
theorem add_smul : (r + s) • x = r • x + s • x := semimodule.add_smul r s x
variables (α)
@[simp] theorem zero_smul : (0 : α) • x = 0 := semimodule.zero_smul α x
lemma smul_smul : r • s • x = (r * s) • x := (mul_smul _ _ _).symm
instance smul.is_add_monoid_hom {r : α} : is_add_monoid_hom (λ x : β, r • x) :=
{ map_add := smul_add _, map_zero := smul_zero _ }
lemma semimodule.eq_zero_of_zero_eq_one (zero_eq_one : (0 : α) = 1) : x = 0 :=
by rw [←one_smul α x, ←zero_eq_one, zero_smul]
/-- R-linearity of finite sums of elements of an R-semimodule. -/
lemma finset.sum_smul {α : Type*} {R : Type*} [semiring R] {M : Type*} [add_comm_monoid M]
[semimodule R M] (s : finset α) (r : R) (f : α → M) :
s.sum (λ (x : α), (r • (f x))) = r • (s.sum f) :=
s.sum_hom _
end semimodule
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A module is a generalization of vector spaces to a scalar ring.
It consists of a scalar ring `α` and an additive group of "vectors" `β`,
connected by a "scalar multiplication" operation `r • x : β`
(where `r : α` and `x : β`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
class module (α : Type u) (β : Type v) [ring α] [add_comm_group β] extends semimodule α β
end prio
structure module.core (α β) [ring α] [add_comm_group β] extends has_scalar α β :=
(smul_add : ∀(r : α) (x y : β), r • (x + y) = r • x + r • y)
(add_smul : ∀(r s : α) (x : β), (r + s) • x = r • x + s • x)
(mul_smul : ∀(r s : α) (x : β), (r * s) • x = r • s • x)
(one_smul : ∀x : β, (1 : α) • x = x)
def module.of_core {α β} [ring α] [add_comm_group β] (M : module.core α β) : module α β :=
by letI := M.to_has_scalar; exact
{ zero_smul := λ x,
have (0 : α) • x + (0 : α) • x = (0 : α) • x + 0, by rw ← M.add_smul; simp,
add_left_cancel this,
smul_zero := λ r,
have r • (0:β) + r • 0 = r • 0 + 0, by rw ← M.smul_add; simp,
add_left_cancel this,
..M }
section module
variables [ring α] [add_comm_group β] [module α β] (r s : α) (x y : β)
@[simp] theorem neg_smul : -r • x = - (r • x) :=
eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul])
variables (α)
theorem neg_one_smul (x : β) : (-1 : α) • x = -x := by simp
variables {α}
@[simp] theorem smul_neg : r • (-x) = -(r • x) :=
by rw [← neg_one_smul α, ← mul_smul, mul_neg_one, neg_smul]
theorem smul_sub (r : α) (x y : β) : r • (x - y) = r • x - r • y :=
by simp [smul_add]; rw smul_neg
theorem sub_smul (r s : α) (y : β) : (r - s) • y = r • y - s • y :=
by simp [add_smul]
end module
instance semiring.to_semimodule [r : semiring α] : semimodule α α :=
{ smul := (*),
smul_add := mul_add,
add_smul := add_mul,
mul_smul := mul_assoc,
one_smul := one_mul,
zero_smul := zero_mul,
smul_zero := mul_zero, ..r }
@[simp] lemma smul_eq_mul [semiring α] {a a' : α} : a • a' = a * a' := rfl
instance ring.to_module [r : ring α] : module α α :=
{ ..semiring.to_semimodule }
def is_ring_hom.to_module [ring α] [ring β] (f : α → β) [h : is_ring_hom f] : module α β :=
module.of_core
{ smul := λ r x, f r * x,
smul_add := λ r x y, by unfold has_scalar.smul; rw [mul_add],
add_smul := λ r s x, by unfold has_scalar.smul; rw [h.map_add, add_mul],
mul_smul := λ r s x, by unfold has_scalar.smul; rw [h.map_mul, mul_assoc],
one_smul := λ x, show f 1 * x = _, by rw [h.map_one, one_mul] }
class is_linear_map (α : Type u) {β : Type v} {γ : Type w}
[ring α] [add_comm_group β] [add_comm_group γ] [module α β] [module α γ]
(f : β → γ) : Prop :=
(add : ∀x y, f (x + y) = f x + f y)
(smul : ∀(c : α) x, f (c • x) = c • f x)
structure linear_map (α : Type u) (β : Type v) (γ : Type w)
[ring α] [add_comm_group β] [add_comm_group γ] [module α β] [module α γ] :=
(to_fun : β → γ)
(add : ∀x y, to_fun (x + y) = to_fun x + to_fun y)
(smul : ∀(c : α) x, to_fun (c • x) = c • to_fun x)
infixr ` →ₗ `:25 := linear_map _
notation β ` →ₗ[`:25 α:25 `] `:0 γ:0 := linear_map α β γ
namespace linear_map
variables {rα : ring α} {gβ : add_comm_group β} {gγ : add_comm_group γ} {gδ : add_comm_group δ}
variables {mβ : module α β} {mγ : module α γ} {mδ : module α δ}
variables (f g : β →ₗ[α] γ)
include α mβ mγ
instance : has_coe_to_fun (β →ₗ[α] γ) := ⟨_, to_fun⟩
@[simp] lemma coe_mk (f : β → γ) (h₁ h₂) :
((linear_map.mk f h₁ h₂ : β →ₗ[α] γ) : β → γ) = f := rfl
theorem is_linear : is_linear_map α f := {..f}
@[ext] theorem ext {f g : β →ₗ[α] γ} (H : ∀ x, f x = g x) : f = g :=
by cases f; cases g; congr'; exact funext H
theorem ext_iff {f g : β →ₗ[α] γ} : f = g ↔ ∀ x, f x = g x :=
⟨by rintro rfl; simp, ext⟩
@[simp] lemma map_add (x y : β) : f (x + y) = f x + f y := f.add x y
@[simp] lemma map_smul (c : α) (x : β) : f (c • x) = c • f x := f.smul c x
@[simp] lemma map_zero : f 0 = 0 :=
by rw [← zero_smul α, map_smul f 0 0, zero_smul]
instance : is_add_group_hom f := { map_add := map_add f }
@[simp] lemma map_neg (x : β) : f (- x) = - f x :=
by rw [← neg_one_smul α, map_smul, neg_one_smul]
@[simp] lemma map_sub (x y : β) : f (x - y) = f x - f y :=
by simp [map_neg, map_add]
@[simp] lemma map_sum {ι} {t : finset ι} {g : ι → β} :
f (t.sum g) = t.sum (λi, f (g i)) :=
(t.sum_hom f).symm
include mδ
def comp (f : γ →ₗ[α] δ) (g : β →ₗ[α] γ) : β →ₗ[α] δ := ⟨f ∘ g, by simp, by simp⟩
@[simp] lemma comp_apply (f : γ →ₗ[α] δ) (g : β →ₗ[α] γ) (x : β) : f.comp g x = f (g x) := rfl
omit mγ mδ
variables [rα] [gβ] [mβ]
def id : β →ₗ[α] β := ⟨id, by simp, by simp⟩
@[simp] lemma id_apply (x : β) : @id α β _ _ _ x = x := rfl
end linear_map
namespace is_linear_map
variables [ring α] [add_comm_group β] [add_comm_group γ]
variables [module α β] [module α γ]
include α
def mk' (f : β → γ) (H : is_linear_map α f) : β →ₗ γ := {to_fun := f, ..H}
@[simp] theorem mk'_apply {f : β → γ} (H : is_linear_map α f) (x : β) :
mk' f H x = f x := rfl
lemma is_linear_map_neg :
is_linear_map α (λ (z : β), -z) :=
is_linear_map.mk neg_add (λ x y, (smul_neg x y).symm)
lemma is_linear_map_smul {α R : Type*} [add_comm_group α] [comm_ring R] [module R α] (c : R) :
is_linear_map R (λ (z : α), c • z) :=
begin
refine is_linear_map.mk (smul_add c) _,
intros _ _,
simp [smul_smul],
ac_refl
end
--TODO: move
lemma is_linear_map_smul' {α R : Type*} [add_comm_group α] [ring R] [module R α] (a : α) :
is_linear_map R (λ (c : R), c • a) :=
begin
refine is_linear_map.mk (λ x y, add_smul x y a) _,
intros _ _,
simp [smul_smul]
end
variables {f : β → γ} (lin : is_linear_map α f)
include β γ lin
@[simp] lemma map_zero : f (0 : β) = (0 : γ) :=
by rw [← zero_smul α (0 : β), lin.smul, zero_smul]
@[simp] lemma map_add (x y : β) : f (x + y) = f x + f y :=
by rw [lin.add]
@[simp] lemma map_neg (x : β) : f (- x) = - f x :=
by rw [← neg_one_smul α, lin.smul, neg_one_smul]
@[simp] lemma map_sub (x y : β) : f (x - y) = f x - f y :=
by simp [lin.map_neg, lin.map_add]
end is_linear_map
abbreviation module.End (R : Type u) (M : Type v)
[comm_ring R] [add_comm_group M] [module R M] := M →ₗ[R] M
/-- A submodule of a module is one which is closed under vector operations.
This is a sufficient condition for the subset of vectors in the submodule
to themselves form a module. -/
structure submodule (α : Type u) (β : Type v) [ring α]
[add_comm_group β] [module α β] : Type v :=
(carrier : set β)
(zero : (0:β) ∈ carrier)
(add : ∀ {x y}, x ∈ carrier → y ∈ carrier → x + y ∈ carrier)
(smul : ∀ (c:α) {x}, x ∈ carrier → c • x ∈ carrier)
namespace submodule
variables [ring α] [add_comm_group β] [add_comm_group γ]
variables [module α β] [module α γ]
variables (p p' : submodule α β)
variables {r : α} {x y : β}
instance : has_coe (submodule α β) (set β) := ⟨submodule.carrier⟩
instance : has_mem β (submodule α β) := ⟨λ x p, x ∈ (p : set β)⟩
@[simp] theorem mem_coe : x ∈ (p : set β) ↔ x ∈ p := iff.rfl
theorem ext' {s t : submodule α β} (h : (s : set β) = t) : s = t :=
by cases s; cases t; congr'
protected theorem ext'_iff {s t : submodule α β} : (s : set β) = t ↔ s = t :=
⟨ext', λ h, h ▸ rfl⟩
@[ext] theorem ext {s t : submodule α β}
(h : ∀ x, x ∈ s ↔ x ∈ t) : s = t := ext' $ set.ext h
@[simp] lemma zero_mem : (0 : β) ∈ p := p.zero
lemma add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := p.add h₁ h₂
lemma smul_mem (r : α) (h : x ∈ p) : r • x ∈ p := p.smul r h
lemma neg_mem (hx : x ∈ p) : -x ∈ p := by rw ← neg_one_smul α; exact p.smul_mem _ hx
lemma sub_mem (hx : x ∈ p) (hy : y ∈ p) : x - y ∈ p := p.add_mem hx (p.neg_mem hy)
lemma neg_mem_iff : -x ∈ p ↔ x ∈ p :=
⟨λ h, by simpa using neg_mem p h, neg_mem p⟩
lemma add_mem_iff_left (h₁ : y ∈ p) : x + y ∈ p ↔ x ∈ p :=
⟨λ h₂, by simpa using sub_mem _ h₂ h₁, λ h₂, add_mem _ h₂ h₁⟩
lemma add_mem_iff_right (h₁ : x ∈ p) : x + y ∈ p ↔ y ∈ p :=
⟨λ h₂, by simpa using sub_mem _ h₂ h₁, add_mem _ h₁⟩
lemma sum_mem {ι : Type w} [decidable_eq ι] {t : finset ι} {f : ι → β} :
(∀c∈t, f c ∈ p) → t.sum f ∈ p :=
finset.induction_on t (by simp [p.zero_mem]) (by simp [p.add_mem] {contextual := tt})
instance : has_add p := ⟨λx y, ⟨x.1 + y.1, add_mem _ x.2 y.2⟩⟩
instance : has_zero p := ⟨⟨0, zero_mem _⟩⟩
instance : has_neg p := ⟨λx, ⟨-x.1, neg_mem _ x.2⟩⟩
instance : has_scalar α p := ⟨λ c x, ⟨c • x.1, smul_mem _ c x.2⟩⟩
@[simp] lemma coe_add (x y : p) : (↑(x + y) : β) = ↑x + ↑y := rfl
@[simp] lemma coe_zero : ((0 : p) : β) = 0 := rfl
@[simp] lemma coe_neg (x : p) : ((-x : p) : β) = -x := rfl
@[simp] lemma coe_smul (r : α) (x : p) : ((r • x : p) : β) = r • ↑x := rfl
instance : add_comm_group p :=
by refine {add := (+), zero := 0, neg := has_neg.neg, ..};
{ intros, apply set_coe.ext, simp }
instance submodule_is_add_subgroup : is_add_subgroup (p : set β) :=
{ zero_mem := p.zero,
add_mem := p.add,
neg_mem := λ _, p.neg_mem }
lemma coe_sub (x y : p) : (↑(x - y) : β) = ↑x - ↑y := by simp
instance : module α p :=
by refine {smul := (•), ..};
{ intros, apply set_coe.ext, simp [smul_add, add_smul, mul_smul] }
protected def subtype : p →ₗ[α] β :=
by refine {to_fun := coe, ..}; simp [coe_smul]
@[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl
lemma subtype_eq_val (p : submodule α β) :
((submodule.subtype p) : p → β) = subtype.val := rfl
end submodule
@[reducible] def ideal (α : Type u) [comm_ring α] := submodule α α
namespace ideal
variables [comm_ring α] (I : ideal α) {a b : α}
protected lemma zero_mem : (0 : α) ∈ I := I.zero_mem
protected lemma add_mem : a ∈ I → b ∈ I → a + b ∈ I := I.add_mem
lemma neg_mem_iff : -a ∈ I ↔ a ∈ I := I.neg_mem_iff
lemma add_mem_iff_left : b ∈ I → (a + b ∈ I ↔ a ∈ I) := I.add_mem_iff_left
lemma add_mem_iff_right : a ∈ I → (a + b ∈ I ↔ b ∈ I) := I.add_mem_iff_right
protected lemma sub_mem : a ∈ I → b ∈ I → a - b ∈ I := I.sub_mem
lemma mul_mem_left : b ∈ I → a * b ∈ I := I.smul_mem _
lemma mul_mem_right (h : a ∈ I) : a * b ∈ I := mul_comm b a ▸ I.mul_mem_left h
end ideal
library_note "vector space definition"
"Vector spaces are defined as an `abbreviation` for modules,
if the base ring is a field.
(A previous definition made `vector_space` a structure
defined to be `module`.)
This has as advantage that vector spaces are completely transparant
for type class inference, which means that all instances for modules
are immediately picked up for vector spaces as well.
A cosmetic disadvantage is that one can not extend vector spaces an sich,
in definitions such as `normed_space`.
The solution is to extend `module` instead."
/-- A vector space is the same as a module, except the scalar ring is actually
a field. (This adds commutativity of the multiplication and existence of inverses.)
This is the traditional generalization of spaces like `ℝ^n`, which have a natural
addition operation and a way to multiply them by real numbers, but no multiplication
operation between vectors. -/
abbreviation vector_space (α : Type u) (β : Type v) [discrete_field α] [add_comm_group β] :=
module α β
instance discrete_field.to_vector_space {α : Type*} [discrete_field α] : vector_space α α :=
{ .. ring.to_module }
/-- Subspace of a vector space. Defined to equal `submodule`. -/
@[reducible] def subspace (α : Type u) (β : Type v)
[discrete_field α] [add_comm_group β] [vector_space α β] : Type v :=
submodule α β
instance subspace.vector_space {α β}
{f : discrete_field α} [add_comm_group β] [vector_space α β]
(p : subspace α β) : vector_space α p := {..submodule.module p}
namespace submodule
variables {R:discrete_field α} [add_comm_group β] [add_comm_group γ]
variables [vector_space α β] [vector_space α γ]
variables (p p' : submodule α β)
variables {r : α} {x y : β}
include R
set_option class.instance_max_depth 36
theorem smul_mem_iff (r0 : r ≠ 0) : r • x ∈ p ↔ x ∈ p :=
⟨λ h, by simpa [smul_smul, inv_mul_cancel r0] using p.smul_mem (r⁻¹) h,
p.smul_mem r⟩
end submodule
namespace add_comm_monoid
open add_monoid
variables {M : Type*} [add_comm_monoid M]
instance : semimodule ℕ M :=
{ smul := smul,
smul_add := λ _ _ _, smul_add _ _ _,
add_smul := λ _ _ _, add_smul _ _ _,
mul_smul := λ _ _ _, mul_smul _ _ _,
one_smul := one_smul,
zero_smul := zero_smul,
smul_zero := smul_zero }
end add_comm_monoid
namespace add_comm_group
variables {M : Type*} [add_comm_group M]
instance : module ℤ M :=
{ smul := gsmul,
smul_add := λ _ _ _, gsmul_add _ _ _,
add_smul := λ _ _ _, add_gsmul _ _ _,
mul_smul := λ _ _ _, gsmul_mul _ _ _,
one_smul := one_gsmul,
zero_smul := zero_gsmul,
smul_zero := gsmul_zero }
end add_comm_group
lemma gsmul_eq_smul {M : Type*} [add_comm_group M] (n : ℤ) (x : M) : gsmul n x = n • x := rfl
def is_add_group_hom.to_linear_map [add_comm_group α] [add_comm_group β]
(f : α → β) [is_add_group_hom f] : α →ₗ[ℤ] β :=
{ to_fun := f,
add := is_add_hom.map_add f,
smul := λ i x, int.induction_on i (by rw [zero_smul, zero_smul, is_add_group_hom.map_zero f])
(λ i ih, by rw [add_smul, add_smul, is_add_hom.map_add f, ih, one_smul, one_smul])
(λ i ih, by rw [sub_smul, sub_smul, is_add_group_hom.map_sub f, ih, one_smul, one_smul]) }
lemma module.smul_eq_smul {R : Type*} [ring R] {β : Type*} [add_comm_group β] [module R β]
(n : ℕ) (b : β) : n • b = (n : R) • b :=
begin
induction n with n ih,
{ rw [nat.cast_zero, zero_smul, zero_smul] },
{ change (n + 1) • b = (n + 1 : R) • b,
rw [add_smul, add_smul, one_smul, ih, one_smul] }
end
lemma finset.sum_const' {α : Type*} (R : Type*) [ring R] {β : Type*}
[add_comm_group β] [module R β] {s : finset α} (b : β) :
finset.sum s (λ (a : α), b) = (finset.card s : R) • b :=
by rw [finset.sum_const, ← module.smul_eq_smul]; refl
|
3b516eaefa25d2facfea623b50aa886f5b8440a7 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/compiler/phashmap.lean | a429f110128d205e5ee5486805139c68929c92c7 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 2,144 | lean | import Init.Data.PersistentHashMap
import Init.Lean.Data.Format
open Lean PersistentHashMap
abbrev Map := PersistentHashMap Nat Nat
partial def formatMap : Node Nat Nat → Format
| Node.collision keys vals _ => Format.sbracket $
keys.size.fold
(fun i fmt =>
let k := keys.get! i;
let v := vals.get! i;
let p := if i > 0 then fmt ++ format "," ++ Format.line else fmt;
p ++ "c@" ++ Format.paren (format k ++ " => " ++ format v))
Format.nil
| Node.entries entries => Format.sbracket $
entries.size.fold
(fun i fmt =>
let entry := entries.get! i;
let p := if i > 0 then fmt ++ format "," ++ Format.line else fmt;
p ++
match entry with
| Entry.null => "<null>"
| Entry.ref node => formatMap node
| Entry.entry k v => Format.paren (format k ++ " => " ++ format v))
Format.nil
def mkMap (n : Nat) : Map :=
n.fold (fun i m => m.insert i (i*10)) PersistentHashMap.empty
def check (n : Nat) (m : Map) : IO Unit :=
n.forM $ fun i =>
match m.find? i with
| none => IO.println ("failed to find " ++ toString i)
| some v => unless (v == i*10) (IO.println ("unexpected value " ++ toString i ++ " => " ++ toString v))
def delOdd (n : Nat) (m : Map) : Map :=
n.fold (fun i m => if i % 2 == 0 then m else m.erase i) m
def check2 (n : Nat) (bot : Nat) (m : Map) : IO Unit :=
n.forM $ fun i =>
if i % 2 == 0 && i >= bot then
match m.find? i with
| none => IO.println ("failed to find " ++ toString i)
| some v => unless (v == i*10) (IO.println ("unexpected value " ++ toString i ++ " => " ++ toString v))
else
unless (m.find? i == none) (IO.println ("mapping still contains " ++ toString i))
def delLess (n : Nat) (m : Map) : Map :=
n.fold (fun i m => m.erase i) m
def main (xs : List String) : IO Unit :=
do
let n := 5000;
let m := mkMap n;
-- IO.println (formatMap m.root);
IO.println m.stats;
check n m;
let m := delOdd n m;
IO.println m.stats;
check2 n 0 m;
let m := delLess 4900 m;
check2 n 4900 m;
IO.println m.size;
IO.println m.stats;
let m := delLess 4990 m;
check2 n 4990 m;
IO.println m.size;
IO.println m.stats
|
d8de81ab2b64f6975f0628580e9da434ce9e09f3 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/number_theory/bertrand.lean | 73927a0e9b79c7514299553fd1af1f096e6749ae | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 11,461 | lean | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import data.nat.choose.factorization
import data.nat.prime_norm_num
import number_theory.primorial
import analysis.convex.specific_functions.basic
import analysis.convex.specific_functions.deriv
/-!
# Bertrand's Postulate
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the Erdős proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `nat.four_pow_lt_mul_central_binom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of “There is a Prime between n and 2n”_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open_locale big_operators
section real
open real
namespace bertrand
/--
A reified version of the `bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 ≤ x.
-/
lemma real_main_inequality {x : ℝ} (n_large : (512 : ℝ) ≤ x) :
x * (2 * x) ^ (sqrt (2 * x)) * 4 ^ (2 * x / 3) ≤ 4 ^ x :=
begin
let f : ℝ → ℝ := λ x, log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x,
have hf' : ∀ x, 0 < x → 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) :=
λ x h, div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _),
have hf : ∀ x, 0 < x → f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)),
{ intros x h5,
have h6 := mul_pos (zero_lt_two' ℝ) h5,
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x)),
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, ← mul_div_right_comm, ← mul_div, mul_comm x] },
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large,
rw [← div_le_one (rpow_pos_of_pos four_pos x), ← div_div_eq_mul_div, ← rpow_sub four_pos,
← mul_div 2 x, mul_div_left_comm, ← mul_one_sub, (by norm_num1 : (1 : ℝ) - 2 / 3 = 1 / 3),
mul_one_div, ← log_nonpos_iff (hf' x h5), ← hf x h5],
have h : concave_on ℝ (set.Ioi 0.5) f,
{ refine ((strict_concave_on_log_Ioi.concave_on.subset (set.Ioi_subset_Ioi _)
(convex_Ioi 0.5)).add ((strict_concave_on_sqrt_mul_log_Ioi.concave_on.comp_linear_map
((2 : ℝ) • linear_map.id)).subset
(λ a ha, lt_of_eq_of_lt _ ((mul_lt_mul_left two_pos).mpr ha)) (convex_Ioi 0.5))).sub
((convex_on_id (convex_Ioi (0.5 : ℝ))).smul (div_nonneg (log_nonneg _) _)); norm_num1 },
suffices : ∃ x1 x2, 0.5 < x1 ∧ x1 < x2 ∧ x2 ≤ x ∧ 0 ≤ f x1 ∧ f x2 ≤ 0,
{ obtain ⟨x1, x2, h1, h2, h0, h3, h4⟩ := this,
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4 },
refine ⟨18, 512, by norm_num1, by norm_num1, le_trans (by norm_num1) n_large, _, _⟩,
{ have : sqrt (2 * 18) = 6 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1),
rw [hf, log_nonneg_iff (hf' 18 _), this]; norm_num1 },
{ have : sqrt (2 * 512) = 32,
{ exact (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1) },
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one (rpow_pos_of_pos four_pos _),
← rpow_le_rpow_iff _ (rpow_pos_of_pos four_pos _).le three_pos, ← rpow_mul]; norm_num1 },
end
end bertrand
end real
section nat
open nat
/--
The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
lemma bertrand_main_inequality {n : ℕ} (n_large : 512 ≤ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) ≤ 4 ^ n :=
begin
rw ← @cast_le ℝ,
simp only [cast_bit0, cast_add, cast_one, cast_mul, cast_pow, ← real.rpow_nat_cast],
have n_pos : 0 < n := (dec_trivial : 0 < 512).trans_le n_large,
have n2_pos : 1 ≤ 2 * n := mul_pos dec_trivial n_pos,
refine trans (mul_le_mul _ _ _ _) (bertrand.real_main_inequality (by exact_mod_cast n_large)),
{ refine mul_le_mul_of_nonneg_left _ (nat.cast_nonneg _),
refine real.rpow_le_rpow_of_exponent_le (by exact_mod_cast n2_pos) _,
exact_mod_cast real.nat_sqrt_le_real_sqrt },
{ exact real.rpow_le_rpow_of_exponent_le (by norm_num1) (cast_div_le.trans (by norm_cast)) },
{ exact real.rpow_nonneg_of_nonneg (by norm_num1) _ },
{ refine mul_nonneg (nat.cast_nonneg _) _,
exact real.rpow_nonneg_of_nonneg (mul_nonneg zero_le_two (nat.cast_nonneg _)) _, },
end
/--
A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
lemma central_binom_factorization_small (n : ℕ) (n_large : 2 < n)
(no_prime: ¬∃ (p : ℕ), p.prime ∧ n < p ∧ p ≤ 2 * n) :
central_binom n = ∏ p in finset.range (2 * n / 3 + 1), p ^ ((central_binom n).factorization p) :=
begin
refine (eq.trans _ n.prod_pow_factorization_central_binom).symm,
apply finset.prod_subset,
{ exact finset.range_subset.2 (add_le_add_right (nat.div_le_self _ _) _) },
intros x hx h2x,
rw [finset.mem_range, lt_succ_iff] at hx h2x,
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x,
replace no_prime := not_exists.mp no_prime x,
rw [←and_assoc, not_and', not_and_distrib, not_lt] at no_prime,
cases no_prime hx with h h,
{ rw [factorization_eq_zero_of_non_prime n.central_binom h, pow_zero] },
{ rw [factorization_central_binom_of_two_mul_self_lt_three_mul n_large h h2x, pow_zero] },
end
/--
An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `central_binom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
lemma central_binom_le_of_no_bertrand_prime (n : ℕ) (n_big : 2 < n)
(no_prime : ¬∃ (p : ℕ), nat.prime p ∧ n < p ∧ p ≤ 2 * n) :
central_binom n ≤ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) :=
begin
have n_pos : 0 < n := (nat.zero_le _).trans_lt n_big,
have n2_pos : 1 ≤ 2 * n := mul_pos (zero_lt_two' ℕ) n_pos,
let S := (finset.range (2 * n / 3 + 1)).filter nat.prime,
let f := λ x, x ^ n.central_binom.factorization x,
have : ∏ (x : ℕ) in S, f x = ∏ (x : ℕ) in finset.range (2 * n / 3 + 1), f x,
{ refine finset.prod_filter_of_ne (λ p hp h, _),
contrapose! h, dsimp only [f],
rw [factorization_eq_zero_of_non_prime n.central_binom h, pow_zero] },
rw [central_binom_factorization_small n n_big no_prime, ← this,
← finset.prod_filter_mul_prod_filter_not S (≤ sqrt (2 * n))],
apply mul_le_mul',
{ refine (finset.prod_le_prod' (λ p hp, (_ : f p ≤ 2 * n))).trans _,
{ exact pow_factorization_choose_le (mul_pos two_pos n_pos) },
have : (finset.Icc 1 (sqrt (2 * n))).card = sqrt (2 * n),
{ rw [card_Icc, nat.add_sub_cancel] },
rw finset.prod_const,
refine pow_le_pow n2_pos ((finset.card_le_of_subset (λ x hx, _)).trans this.le),
obtain ⟨h1, h2⟩ := finset.mem_filter.1 hx,
exact finset.mem_Icc.mpr ⟨(finset.mem_filter.1 h1).2.one_lt.le, h2⟩ },
{ refine le_trans _ (primorial_le_4_pow (2 * n / 3)),
refine (finset.prod_le_prod' (λ p hp, (_ : f p ≤ p))).trans _,
{ obtain ⟨h1, h2⟩ := finset.mem_filter.1 hp,
refine (pow_le_pow (finset.mem_filter.1 h1).2.one_lt.le _).trans (pow_one p).le,
exact nat.factorization_choose_le_one (sqrt_lt'.mp $ not_le.1 h2) },
refine finset.prod_le_prod_of_subset_of_one_le' (finset.filter_subset _ _) _,
exact λ p hp _, (finset.mem_filter.1 hp).2.one_lt.le }
end
namespace nat
/--
Proves that Bertrand's postulate holds for all sufficiently large `n`.
-/
lemma exists_prime_lt_and_le_two_mul_eventually (n : ℕ) (n_big : 512 ≤ n) :
∃ (p : ℕ), p.prime ∧ n < p ∧ p ≤ 2 * n :=
begin
-- Assume there is no prime in the range.
by_contradiction no_prime,
-- Then we have the above sub-exponential bound on the size of this central binomial coefficient.
-- We now couple this bound with an exponential lower bound on the central binomial coefficient,
-- yielding an inequality which we have seen is false for large enough n.
have H1 : n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) ≤ 4 ^ n := bertrand_main_inequality n_big,
have H2 : 4 ^ n < n * n.central_binom :=
nat.four_pow_lt_mul_central_binom n (le_trans (by norm_num1) n_big),
have H3 : n.central_binom ≤ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) :=
central_binom_le_of_no_bertrand_prime n (lt_of_lt_of_le (by norm_num1) n_big) no_prime,
rw mul_assoc at H1, exact not_le.2 H2 ((mul_le_mul_left' H3 n).trans H1),
end
/--
Proves that Bertrand's postulate holds over all positive naturals less than n by identifying a
descending list of primes, each no more than twice the next, such that the list contains a witness
for each number ≤ n.
-/
lemma exists_prime_lt_and_le_two_mul_succ {n} (q)
{p : ℕ} (prime_p : nat.prime p) (covering : p ≤ 2 * q)
(H : n < q → ∃ (p : ℕ), p.prime ∧ n < p ∧ p ≤ 2 * n)
(hn : n < p) : ∃ (p : ℕ), p.prime ∧ n < p ∧ p ≤ 2 * n :=
begin
by_cases p ≤ 2 * n, { exact ⟨p, prime_p, hn, h⟩ },
exact H (lt_of_mul_lt_mul_left' (lt_of_lt_of_le (not_le.1 h) covering))
end
/--
**Bertrand's Postulate**: For any positive natural number, there is a prime which is greater than
it, but no more than twice as large.
-/
theorem exists_prime_lt_and_le_two_mul (n : ℕ) (hn0 : n ≠ 0) :
∃ p, nat.prime p ∧ n < p ∧ p ≤ 2 * n :=
begin
-- Split into cases whether `n` is large or small
cases lt_or_le 511 n,
-- If `n` is large, apply the lemma derived from the inequalities on the central binomial
-- coefficient.
{ exact exists_prime_lt_and_le_two_mul_eventually n h, },
replace h : n < 521 := h.trans_lt (by norm_num1),
revert h,
-- For small `n`, supply a list of primes to cover the initial cases.
([317, 163, 83, 43, 23, 13, 7, 5, 3, 2].mmap' $ λ n,
`[refine exists_prime_lt_and_le_two_mul_succ %%(reflect n) (by norm_num1) (by norm_num1) _]),
exact λ h2, ⟨2, prime_two, h2, nat.mul_le_mul_left 2 (nat.pos_of_ne_zero hn0)⟩,
end
alias nat.exists_prime_lt_and_le_two_mul ← bertrand
end nat
end nat
|
3ce8363bef7cc4ad7ae3b3d0672dcfdb276948e8 | f0f12a5b81106a798deda31dca238c11997a605e | /Playlean4/Basic.lean | d71589b7d33bcc9114d1140bd66508b8c353ccd6 | [
"MIT"
] | permissive | thejohncrafter/playlean4 | fe7119d492aab07048f78333eeda9862f6471740 | 81df180a71b8d84d0f45bc98db367aad203cf5df | refs/heads/master | 1,683,152,783,765 | 1,621,879,382,000 | 1,621,879,382,000 | 366,563,501 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,136 | lean |
universes u
def id' {α : Sort u} (a : α) : α := a
def Set (X : Type) := X → Prop
namespace Set
def mem {X : Type} (x : X) (s : Set X) := s x
infix:50 " ∈ " => mem
theorem ext {X : Type} (s₁ s₂ : Set X) (h : ∀ x : X, x ∈ s₁ ↔ x ∈ s₂) : s₁ = s₂ :=
by
funext x
exact propext <| h x
@[inline]
def asSubtype {X : Type} (Y : Set X) := Subtype (λ x => x ∈ Y)
instance {X : Type} : CoeSort (Set X) Type where
coe Y := Subtype (λ x => x ∈ Y)
def img {X Y : Type} (f : X → Y) (P : Set X) : Set Y :=
λ y => ∃ x, x ∈ P ∧ y = f x
def imgComp {X Y Z : Type} {f : X → Y} {g : Y → Z} {P : Set X} :
img g (img f P) = img (g ∘ f) P :=
by
funext z
apply propext
simp [img, Function.comp]
exact ⟨ λ h => match h with
| ⟨ y, ⟨ ⟨ x, ⟨ xIn, xImg ⟩ ⟩, yImg ⟩ ⟩ =>
⟨ x, ⟨ xIn, xImg ▸ yImg ▸ rfl ⟩ ⟩,
λ h => match h with
| ⟨ x, ⟨ xIn, xImg ⟩ ⟩ =>
⟨ (f x), ⟨ ⟨ x, ⟨ xIn, rfl ⟩ ⟩, xImg ⟩ ⟩ ⟩
def imgCongrFun {X Y : Type} {f g : X → Y} {P : Set X} (h : f = g) :
img f P = img g P := by rw [h]
end Set
|
6700fd1f67a846f79346b1339fff4db3c31d3514 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/366.lean | ceecdbaf69d30857a64ad52aa207e3b55eb96929 | [
"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 | 184 | lean | def foo : Inhabited Nat :=
set_option trace.Meta.synthInstance true in by { exact inferInstance }
namespace Foo
def bla := 20
end Foo
def boo : Nat :=
open Foo in by exact bla
|
1a15adb5f5011b4e08f32861981e477f37c3253c | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/algebraic_geometry/projective_spectrum/topology.lean | a0e04d1a1027790281eb09c396cb54f54545cd8a | [
"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 | 18,867 | lean | /-
Copyright (c) 2020 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Johan Commelin
-/
import topology.category.Top
import ring_theory.graded_algebra.homogeneous_ideal
/-!
# Projective spectrum of a graded ring
The projective spectrum of a graded commutative ring is the subtype of all homogenous ideals that
are prime and do not contain the irrelevant ideal.
It is naturally endowed with a topology: the Zariski topology.
## Notation
- `R` is a commutative semiring;
- `A` is a commutative ring and an `R`-algebra;
- `𝒜 : ℕ → submodule R A` is the grading of `A`;
## Main definitions
* `projective_spectrum 𝒜`: The projective spectrum of a graded ring `A`, or equivalently, the set of
all homogeneous ideals of `A` that is both prime and relevant i.e. not containing irrelevant
ideal. Henceforth, we call elements of projective spectrum *relevant homogeneous prime ideals*.
* `projective_spectrum.zero_locus 𝒜 s`: The zero locus of a subset `s` of `A`
is the subset of `projective_spectrum 𝒜` consisting of all relevant homogeneous prime ideals that
contain `s`.
* `projective_spectrum.vanishing_ideal t`: The vanishing ideal of a subset `t` of
`projective_spectrum 𝒜` is the intersection of points in `t` (viewed as relevant homogeneous prime
ideals).
* `projective_spectrum.Top`: the topological space of `projective_spectrum 𝒜` endowed with the
Zariski topology
-/
noncomputable theory
open_locale direct_sum big_operators pointwise
open direct_sum set_like Top topological_space category_theory opposite
variables {R A: Type*}
variables [comm_semiring R] [comm_ring A] [algebra R A]
variables (𝒜 : ℕ → submodule R A) [graded_algebra 𝒜]
/--
The projective spectrum of a graded commutative ring is the subtype of all homogenous ideals that
are prime and do not contain the irrelevant ideal.
-/
@[nolint has_nonempty_instance]
def projective_spectrum :=
{I : homogeneous_ideal 𝒜 // I.to_ideal.is_prime ∧ ¬(homogeneous_ideal.irrelevant 𝒜 ≤ I)}
namespace projective_spectrum
variable {𝒜}
/-- A method to view a point in the projective spectrum of a graded ring
as a homogeneous ideal of that ring. -/
abbreviation as_homogeneous_ideal (x : projective_spectrum 𝒜) : homogeneous_ideal 𝒜 := x.1
lemma as_homogeneous_ideal_def (x : projective_spectrum 𝒜) :
x.as_homogeneous_ideal = x.1 := rfl
instance is_prime (x : projective_spectrum 𝒜) :
x.as_homogeneous_ideal.to_ideal.is_prime := x.2.1
@[ext] lemma ext {x y : projective_spectrum 𝒜} :
x = y ↔ x.as_homogeneous_ideal = y.as_homogeneous_ideal :=
subtype.ext_iff_val
variable (𝒜)
/-- The zero locus of a set `s` of elements of a commutative ring `A`
is the set of all relevant homogeneous prime ideals of the ring that contain the set `s`.
An element `f` of `A` can be thought of as a dependent function on the projective spectrum of `𝒜`.
At a point `x` (a homogeneous prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `A` modulo the prime ideal `x`.
In this manner, `zero_locus s` is exactly the subset of `projective_spectrum 𝒜`
where all "functions" in `s` vanish simultaneously. -/
def zero_locus (s : set A) : set (projective_spectrum 𝒜) :=
{x | s ⊆ x.as_homogeneous_ideal}
@[simp] lemma mem_zero_locus (x : projective_spectrum 𝒜) (s : set A) :
x ∈ zero_locus 𝒜 s ↔ s ⊆ x.as_homogeneous_ideal := iff.rfl
@[simp] lemma zero_locus_span (s : set A) :
zero_locus 𝒜 (ideal.span s) = zero_locus 𝒜 s :=
by { ext x, exact (submodule.gi _ _).gc s x.as_homogeneous_ideal.to_ideal }
variable {𝒜}
/-- 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 `A` can be thought of as a dependent function on the projective spectrum of `𝒜`.
At a point `x` (a homogeneous prime ideal)
the function (i.e., element) `f` takes values in the quotient ring `A` modulo the prime ideal `x`.
In this manner, `vanishing_ideal t` is exactly the ideal of `A`
consisting of all "functions" that vanish on all of `t`. -/
def vanishing_ideal (t : set (projective_spectrum 𝒜)) : homogeneous_ideal 𝒜 :=
⨅ (x : projective_spectrum 𝒜) (h : x ∈ t), x.as_homogeneous_ideal
lemma coe_vanishing_ideal (t : set (projective_spectrum 𝒜)) :
(vanishing_ideal t : set A) =
{f | ∀ x : projective_spectrum 𝒜, x ∈ t → f ∈ x.as_homogeneous_ideal} :=
begin
ext f,
rw [vanishing_ideal, set_like.mem_coe, ← homogeneous_ideal.mem_iff,
homogeneous_ideal.to_ideal_infi, submodule.mem_infi],
apply forall_congr (λ x, _),
rw [homogeneous_ideal.to_ideal_infi, submodule.mem_infi, homogeneous_ideal.mem_iff],
end
lemma mem_vanishing_ideal (t : set (projective_spectrum 𝒜)) (f : A) :
f ∈ vanishing_ideal t ↔
∀ x : projective_spectrum 𝒜, x ∈ t → f ∈ x.as_homogeneous_ideal :=
by rw [← set_like.mem_coe, coe_vanishing_ideal, set.mem_set_of_eq]
@[simp] lemma vanishing_ideal_singleton (x : projective_spectrum 𝒜) :
vanishing_ideal ({x} : set (projective_spectrum 𝒜)) = x.as_homogeneous_ideal :=
by simp [vanishing_ideal]
lemma subset_zero_locus_iff_le_vanishing_ideal (t : set (projective_spectrum 𝒜))
(I : ideal A) :
t ⊆ zero_locus 𝒜 I ↔ I ≤ (vanishing_ideal t).to_ideal :=
⟨λ 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))⟩
variable (𝒜)
/-- `zero_locus` and `vanishing_ideal` form a galois connection. -/
lemma gc_ideal : @galois_connection
(ideal A) (set (projective_spectrum 𝒜))ᵒᵈ _ _
(λ I, zero_locus 𝒜 I) (λ t, (vanishing_ideal t).to_ideal) :=
λ 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 A) (set (projective_spectrum 𝒜))ᵒᵈ _ _
(λ s, zero_locus 𝒜 s) (λ t, vanishing_ideal t) :=
have ideal_gc : galois_connection (ideal.span) coe := (submodule.gi A _).gc,
by simpa [zero_locus_span, function.comp] using galois_connection.compose ideal_gc (gc_ideal 𝒜)
lemma gc_homogeneous_ideal : @galois_connection
(homogeneous_ideal 𝒜) (set (projective_spectrum 𝒜))ᵒᵈ _ _
(λ I, zero_locus 𝒜 I) (λ t, (vanishing_ideal t)) :=
λ I t, by simpa [show I.to_ideal ≤ (vanishing_ideal t).to_ideal ↔ I ≤ (vanishing_ideal t),
from iff.rfl] using subset_zero_locus_iff_le_vanishing_ideal t I.to_ideal
lemma subset_zero_locus_iff_subset_vanishing_ideal (t : set (projective_spectrum 𝒜))
(s : set A) :
t ⊆ zero_locus 𝒜 s ↔ s ⊆ vanishing_ideal t :=
(gc_set _) s t
lemma subset_vanishing_ideal_zero_locus (s : set A) :
s ⊆ vanishing_ideal (zero_locus 𝒜 s) :=
(gc_set _).le_u_l s
lemma ideal_le_vanishing_ideal_zero_locus (I : ideal A) :
I ≤ (vanishing_ideal (zero_locus 𝒜 I)).to_ideal :=
(gc_ideal _).le_u_l I
lemma homogeneous_ideal_le_vanishing_ideal_zero_locus (I : homogeneous_ideal 𝒜) :
I ≤ vanishing_ideal (zero_locus 𝒜 I) :=
(gc_homogeneous_ideal _).le_u_l I
lemma subset_zero_locus_vanishing_ideal (t : set (projective_spectrum 𝒜)) :
t ⊆ zero_locus 𝒜 (vanishing_ideal t) :=
(gc_ideal _).l_u_le t
lemma zero_locus_anti_mono {s t : set A} (h : s ⊆ t) : zero_locus 𝒜 t ⊆ zero_locus 𝒜 s :=
(gc_set _).monotone_l h
lemma zero_locus_anti_mono_ideal {s t : ideal A} (h : s ≤ t) :
zero_locus 𝒜 (t : set A) ⊆ zero_locus 𝒜 (s : set A) :=
(gc_ideal _).monotone_l h
lemma zero_locus_anti_mono_homogeneous_ideal {s t : homogeneous_ideal 𝒜} (h : s ≤ t) :
zero_locus 𝒜 (t : set A) ⊆ zero_locus 𝒜 (s : set A) :=
(gc_homogeneous_ideal _).monotone_l h
lemma vanishing_ideal_anti_mono {s t : set (projective_spectrum 𝒜)} (h : s ⊆ t) :
vanishing_ideal t ≤ vanishing_ideal s :=
(gc_ideal _).monotone_u h
lemma zero_locus_bot :
zero_locus 𝒜 ((⊥ : ideal A) : set A) = set.univ :=
(gc_ideal 𝒜).l_bot
@[simp] lemma zero_locus_singleton_zero :
zero_locus 𝒜 ({0} : set A) = set.univ :=
zero_locus_bot _
@[simp] lemma zero_locus_empty :
zero_locus 𝒜 (∅ : set A) = set.univ :=
(gc_set 𝒜).l_bot
@[simp] lemma vanishing_ideal_univ :
vanishing_ideal (∅ : set (projective_spectrum 𝒜)) = ⊤ :=
by simpa using (gc_ideal _).u_top
lemma zero_locus_empty_of_one_mem {s : set A} (h : (1:A) ∈ s) :
zero_locus 𝒜 s = ∅ :=
set.eq_empty_iff_forall_not_mem.mpr $ λ x hx,
(infer_instance : x.as_homogeneous_ideal.to_ideal.is_prime).ne_top $
x.as_homogeneous_ideal.to_ideal.eq_top_iff_one.mpr $ hx h
@[simp] lemma zero_locus_singleton_one :
zero_locus 𝒜 ({1} : set A) = ∅ :=
zero_locus_empty_of_one_mem 𝒜 (set.mem_singleton (1 : A))
@[simp] lemma zero_locus_univ :
zero_locus 𝒜 (set.univ : set A) = ∅ :=
zero_locus_empty_of_one_mem _ (set.mem_univ 1)
lemma zero_locus_sup_ideal (I J : ideal A) :
zero_locus 𝒜 ((I ⊔ J : ideal A) : set A) = zero_locus _ I ∩ zero_locus _ J :=
(gc_ideal 𝒜).l_sup
lemma zero_locus_sup_homogeneous_ideal (I J : homogeneous_ideal 𝒜) :
zero_locus 𝒜 ((I ⊔ J : homogeneous_ideal 𝒜) : set A) = zero_locus _ I ∩ zero_locus _ J :=
(gc_homogeneous_ideal 𝒜).l_sup
lemma zero_locus_union (s s' : set A) :
zero_locus 𝒜 (s ∪ s') = zero_locus _ s ∩ zero_locus _ s' :=
(gc_set 𝒜).l_sup
lemma vanishing_ideal_union (t t' : set (projective_spectrum 𝒜)) :
vanishing_ideal (t ∪ t') = vanishing_ideal t ⊓ vanishing_ideal t' :=
by ext1; convert (gc_ideal 𝒜).u_inf
lemma zero_locus_supr_ideal {γ : Sort*} (I : γ → ideal A) :
zero_locus _ ((⨆ i, I i : ideal A) : set A) = (⋂ i, zero_locus 𝒜 (I i)) :=
(gc_ideal 𝒜).l_supr
lemma zero_locus_supr_homogeneous_ideal {γ : Sort*} (I : γ → homogeneous_ideal 𝒜) :
zero_locus _ ((⨆ i, I i : homogeneous_ideal 𝒜) : set A) = (⋂ i, zero_locus 𝒜 (I i)) :=
(gc_homogeneous_ideal 𝒜).l_supr
lemma zero_locus_Union {γ : Sort*} (s : γ → set A) :
zero_locus 𝒜 (⋃ i, s i) = (⋂ i, zero_locus 𝒜 (s i)) :=
(gc_set 𝒜).l_supr
lemma zero_locus_bUnion (s : set (set A)) :
zero_locus 𝒜 (⋃ s' ∈ s, s' : set A) = ⋂ s' ∈ s, zero_locus 𝒜 s' :=
by simp only [zero_locus_Union]
lemma vanishing_ideal_Union {γ : Sort*} (t : γ → set (projective_spectrum 𝒜)) :
vanishing_ideal (⋃ i, t i) = (⨅ i, vanishing_ideal (t i)) :=
homogeneous_ideal.to_ideal_injective $
by convert (gc_ideal 𝒜).u_infi; exact homogeneous_ideal.to_ideal_infi _
lemma zero_locus_inf (I J : ideal A) :
zero_locus 𝒜 ((I ⊓ J : ideal A) : set A) = zero_locus 𝒜 I ∪ zero_locus 𝒜 J :=
set.ext $ λ x, by simpa using x.2.1.inf_le
lemma union_zero_locus (s s' : set A) :
zero_locus 𝒜 s ∪ zero_locus 𝒜 s' = zero_locus 𝒜 ((ideal.span s) ⊓ (ideal.span s'): ideal A) :=
by { rw zero_locus_inf, simp }
lemma zero_locus_mul_ideal (I J : ideal A) :
zero_locus 𝒜 ((I * J : ideal A) : set A) = zero_locus 𝒜 I ∪ zero_locus 𝒜 J :=
set.ext $ λ x, by simpa using x.2.1.mul_le
lemma zero_locus_mul_homogeneous_ideal (I J : homogeneous_ideal 𝒜) :
zero_locus 𝒜 ((I * J : homogeneous_ideal 𝒜) : set A) = zero_locus 𝒜 I ∪ zero_locus 𝒜 J :=
set.ext $ λ x, by simpa using x.2.1.mul_le
lemma zero_locus_singleton_mul (f g : A) :
zero_locus 𝒜 ({f * g} : set A) = zero_locus 𝒜 {f} ∪ zero_locus 𝒜 {g} :=
set.ext $ λ x, by simpa using x.2.1.mul_mem_iff_mem_or_mem
@[simp] lemma zero_locus_singleton_pow (f : A) (n : ℕ) (hn : 0 < n) :
zero_locus 𝒜 ({f ^ n} : set A) = zero_locus 𝒜 {f} :=
set.ext $ λ x, by simpa using x.2.1.pow_mem_iff_mem n hn
lemma sup_vanishing_ideal_le (t t' : set (projective_spectrum 𝒜)) :
vanishing_ideal t ⊔ vanishing_ideal t' ≤ vanishing_ideal (t ∩ t') :=
begin
intros r,
rw [← homogeneous_ideal.mem_iff, homogeneous_ideal.to_ideal_sup, mem_vanishing_ideal,
submodule.mem_sup],
rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩,
erw mem_vanishing_ideal at hf hg,
apply submodule.add_mem; solve_by_elim
end
lemma mem_compl_zero_locus_iff_not_mem {f : A} {I : projective_spectrum 𝒜} :
I ∈ (zero_locus 𝒜 {f} : set (projective_spectrum 𝒜))ᶜ ↔ f ∉ I.as_homogeneous_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 (projective_spectrum 𝒜) :=
topological_space.of_closed (set.range (projective_spectrum.zero_locus 𝒜))
(⟨set.univ, by simp⟩)
begin
intros Zs h,
rw set.sInter_eq_Inter,
let f : Zs → set _ := λ 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 { rintros _ ⟨s, rfl⟩ _ ⟨t, rfl⟩, exact ⟨_, (union_zero_locus 𝒜 s t).symm⟩ })
/--
The underlying topology of `Proj` is the projective spectrum of graded ring `A`.
-/
def Top : Top := Top.of (projective_spectrum 𝒜)
lemma is_open_iff (U : set (projective_spectrum 𝒜)) :
is_open U ↔ ∃ s, Uᶜ = zero_locus 𝒜 s :=
by simp only [@eq_comm _ Uᶜ]; refl
lemma is_closed_iff_zero_locus (Z : set (projective_spectrum 𝒜)) :
is_closed Z ↔ ∃ s, Z = zero_locus 𝒜 s :=
by rw [← is_open_compl_iff, is_open_iff, compl_compl]
lemma is_closed_zero_locus (s : set A) :
is_closed (zero_locus 𝒜 s) :=
by { rw [is_closed_iff_zero_locus], exact ⟨s, rfl⟩ }
lemma zero_locus_vanishing_ideal_eq_closure (t : set (projective_spectrum 𝒜)) :
zero_locus 𝒜 (vanishing_ideal t : set A) = 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 (projective_spectrum 𝒜)) :
vanishing_ideal (closure t) = vanishing_ideal t :=
begin
have := (gc_ideal 𝒜).u_l_u_eq_u t,
dsimp only at this,
ext1,
erw zero_locus_vanishing_ideal_eq_closure 𝒜 t at this,
exact this,
end
section basic_open
/-- `basic_open r` is the open subset containing all prime ideals not containing `r`. -/
def basic_open (r : A) : topological_space.opens (projective_spectrum 𝒜) :=
{ val := { x | r ∉ x.as_homogeneous_ideal },
property := ⟨{r}, set.ext $ λ x, set.singleton_subset_iff.trans $ not_not.symm⟩ }
@[simp] lemma mem_basic_open (f : A) (x : projective_spectrum 𝒜) :
x ∈ basic_open 𝒜 f ↔ f ∉ x.as_homogeneous_ideal := iff.rfl
lemma mem_coe_basic_open (f : A) (x : projective_spectrum 𝒜) :
x ∈ (↑(basic_open 𝒜 f): set (projective_spectrum 𝒜)) ↔ f ∉ x.as_homogeneous_ideal := iff.rfl
lemma is_open_basic_open {a : A} : is_open ((basic_open 𝒜 a) :
set (projective_spectrum 𝒜)) :=
(basic_open 𝒜 a).property
@[simp] lemma basic_open_eq_zero_locus_compl (r : A) :
(basic_open 𝒜 r : set (projective_spectrum 𝒜)) = (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 : A) = ⊤ :=
topological_space.opens.ext $ by simp
@[simp] lemma basic_open_zero : basic_open 𝒜 (0 : A) = ⊥ :=
topological_space.opens.ext $ by simp
lemma basic_open_mul (f g : A) : 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 : A) : 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 : A) : basic_open 𝒜 (f * g) ≤ basic_open 𝒜 g :=
by { rw basic_open_mul 𝒜 f g, exact inf_le_right }
@[simp] lemma basic_open_pow (f : A) (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 basic_open_eq_union_of_projection (f : A) :
basic_open 𝒜 f = ⨆ (i : ℕ), basic_open 𝒜 (graded_algebra.proj 𝒜 i f) :=
topological_space.opens.ext $ set.ext $ λ z, begin
erw [mem_coe_basic_open, topological_space.opens.mem_Sup],
split; intros hz,
{ rcases show ∃ i, graded_algebra.proj 𝒜 i f ∉ z.as_homogeneous_ideal, begin
contrapose! hz with H,
classical,
rw ←direct_sum.sum_support_decompose 𝒜 f,
apply ideal.sum_mem _ (λ i hi, H i)
end with ⟨i, hi⟩,
exact ⟨basic_open 𝒜 (graded_algebra.proj 𝒜 i f), ⟨i, rfl⟩, by rwa mem_basic_open⟩ },
{ obtain ⟨_, ⟨i, rfl⟩, hz⟩ := hz,
exact λ rid, hz (z.1.2 i rid) },
end
lemma is_topological_basis_basic_opens : topological_space.is_topological_basis
(set.range (λ (r : A), (basic_open 𝒜 r : set (projective_spectrum 𝒜)))) :=
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
end basic_open
section order
/-!
## The specialization order
We endow `projective_spectrum 𝒜` with a partial order,
where `x ≤ y` if and only if `y ∈ closure {x}`.
-/
instance : partial_order (projective_spectrum 𝒜) :=
subtype.partial_order _
@[simp] lemma as_ideal_le_as_ideal (x y : projective_spectrum 𝒜) :
x.as_homogeneous_ideal ≤ y.as_homogeneous_ideal ↔ x ≤ y :=
subtype.coe_le_coe
@[simp] lemma as_ideal_lt_as_ideal (x y : projective_spectrum 𝒜) :
x.as_homogeneous_ideal < y.as_homogeneous_ideal ↔ x < y :=
subtype.coe_lt_coe
lemma le_iff_mem_closure (x y : projective_spectrum 𝒜) :
x ≤ y ↔ y ∈ closure ({x} : set (projective_spectrum 𝒜)) :=
begin
rw [← as_ideal_le_as_ideal, ← zero_locus_vanishing_ideal_eq_closure,
mem_zero_locus, vanishing_ideal_singleton],
simp only [coe_subset_coe, subtype.coe_le_coe, coe_coe],
end
end order
end projective_spectrum
|
1991fef1d20ef2ad9894af3de0da809bff55d51e | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/ordered_monoid_auto.lean | 9fc3f4881b831fa4fc13975ae5d63932426e979a | [] | 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 | 40,860 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.group.with_one
import Mathlib.algebra.group.type_tags
import Mathlib.algebra.group.prod
import Mathlib.algebra.order_functions
import Mathlib.order.bounded_lattice
import Mathlib.PostPort
universes u_1 l u u_2
namespace Mathlib
/-!
# Ordered monoids
This file develops the basics of ordered monoids.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
/-- An ordered commutative monoid is a commutative monoid
with a partial order such that
* `a ≤ b → c * a ≤ c * b` (multiplication is monotone)
* `a * b < a * c → b < c`.
-/
class ordered_comm_monoid (α : Type u_1) extends partial_order α, comm_monoid α where
mul_le_mul_left : ∀ (a b : α), a ≤ b → ∀ (c : α), c * a ≤ c * b
lt_of_mul_lt_mul_left : ∀ (a b c : α), a * b < a * c → b < c
/-- An ordered (additive) commutative monoid is a commutative monoid
with a partial order such that
* `a ≤ b → c + a ≤ c + b` (addition is monotone)
* `a + b < a + c → b < c`.
-/
class ordered_add_comm_monoid (α : Type u_1) extends partial_order α, add_comm_monoid α where
add_le_add_left : ∀ (a b : α), a ≤ b → ∀ (c : α), c + a ≤ c + b
lt_of_add_lt_add_left : ∀ (a b c : α), a + b < a + c → b < c
/-- A linearly ordered commutative monoid with a zero element. -/
class linear_ordered_comm_monoid_with_zero (α : Type u_1)
extends ordered_comm_monoid α, comm_monoid_with_zero α, linear_order α where
zero_le_one : 0 ≤ 1
theorem mul_le_mul_left' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (h : a ≤ b) (c : α) :
c * a ≤ c * b :=
ordered_comm_monoid.mul_le_mul_left a b h c
theorem add_le_add_right {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} (h : a ≤ b)
(c : α) : a + c ≤ b + c :=
sorry
theorem lt_of_add_lt_add_left {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} {c : α} :
a + b < a + c → b < c :=
ordered_add_comm_monoid.lt_of_add_lt_add_left a b c
theorem mul_le_mul' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α} {d : α}
(h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d :=
has_le.le.trans (mul_le_mul_right' h₁ c) (mul_le_mul_left' h₂ b)
theorem mul_le_mul_three {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α} {d : α}
{e : α} {f : α} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a * b * c ≤ d * e * f :=
mul_le_mul' (mul_le_mul' h₁ h₂) h₃
theorem le_mul_of_one_le_right' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (h : 1 ≤ b) :
a ≤ a * b :=
(fun (this : a * 1 ≤ a * b) => eq.mp (Eq._oldrec (Eq.refl (a * 1 ≤ a * b)) (mul_one a)) this)
(mul_le_mul_left' h a)
theorem le_mul_of_one_le_left' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (h : 1 ≤ b) :
a ≤ b * a :=
(fun (this : 1 * a ≤ b * a) => eq.mp (Eq._oldrec (Eq.refl (1 * a ≤ b * a)) (one_mul a)) this)
(mul_le_mul_right' h a)
theorem lt_of_mul_lt_mul_right' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α}
(h : a * b < c * b) : a < c :=
sorry
-- here we start using properties of one.
theorem le_add_of_nonneg_of_le {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} {c : α}
(ha : 0 ≤ a) (hbc : b ≤ c) : b ≤ a + c :=
zero_add b ▸ add_le_add ha hbc
theorem le_add_of_le_of_nonneg {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b ≤ c) (ha : 0 ≤ a) : b ≤ c + a :=
add_zero b ▸ add_le_add hbc ha
theorem add_nonneg {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} (ha : 0 ≤ a)
(hb : 0 ≤ b) : 0 ≤ a + b :=
le_add_of_nonneg_of_le ha hb
theorem one_lt_mul_of_lt_of_le' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (ha : 1 < a)
(hb : 1 ≤ b) : 1 < a * b :=
lt_of_lt_of_le ha (le_mul_of_one_le_right' hb)
theorem add_pos_of_nonneg_of_pos {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α}
(ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b :=
lt_of_lt_of_le hb (le_add_of_nonneg_left ha)
theorem one_lt_mul' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (ha : 1 < a) (hb : 1 < b) :
1 < a * b :=
one_lt_mul_of_lt_of_le' ha (has_lt.lt.le hb)
theorem mul_le_one' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (ha : a ≤ 1) (hb : b ≤ 1) :
a * b ≤ 1 :=
one_mul 1 ▸ mul_le_mul' ha hb
theorem mul_le_of_le_one_of_le' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α}
(ha : a ≤ 1) (hbc : b ≤ c) : a * b ≤ c :=
one_mul c ▸ mul_le_mul' ha hbc
theorem mul_le_of_le_of_le_one' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b ≤ c) (ha : a ≤ 1) : b * a ≤ c :=
mul_one c ▸ mul_le_mul' hbc ha
theorem mul_lt_one_of_lt_one_of_le_one' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α}
(ha : a < 1) (hb : b ≤ 1) : a * b < 1 :=
has_le.le.trans_lt (mul_le_of_le_of_le_one' le_rfl hb) ha
theorem mul_lt_one_of_le_one_of_lt_one' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α}
(ha : a ≤ 1) (hb : b < 1) : a * b < 1 :=
has_le.le.trans_lt (mul_le_of_le_one_of_le' ha le_rfl) hb
theorem mul_lt_one' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (ha : a < 1) (hb : b < 1) :
a * b < 1 :=
mul_lt_one_of_le_one_of_lt_one' (has_lt.lt.le ha) hb
theorem lt_add_of_nonneg_of_lt' {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} {c : α}
(ha : 0 ≤ a) (hbc : b < c) : b < a + c :=
has_lt.lt.trans_le hbc (le_add_of_nonneg_left ha)
theorem lt_mul_of_lt_of_one_le' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b < c) (ha : 1 ≤ a) : b < c * a :=
has_lt.lt.trans_le hbc (le_mul_of_one_le_right' ha)
theorem lt_add_of_pos_of_lt' {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} {c : α}
(ha : 0 < a) (hbc : b < c) : b < a + c :=
lt_add_of_nonneg_of_lt' (has_lt.lt.le ha) hbc
theorem lt_add_of_lt_of_pos' {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b < c) (ha : 0 < a) : b < c + a :=
lt_add_of_lt_of_nonneg' hbc (has_lt.lt.le ha)
theorem mul_lt_of_le_one_of_lt' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α}
(ha : a ≤ 1) (hbc : b < c) : a * b < c :=
lt_of_le_of_lt (mul_le_of_le_one_of_le' ha le_rfl) hbc
theorem mul_lt_of_lt_of_le_one' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b < c) (ha : a ≤ 1) : b * a < c :=
lt_of_le_of_lt (mul_le_of_le_of_le_one' le_rfl ha) hbc
theorem mul_lt_of_lt_one_of_lt' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} {c : α}
(ha : a < 1) (hbc : b < c) : a * b < c :=
mul_lt_of_le_one_of_lt' (has_lt.lt.le ha) hbc
theorem add_lt_of_lt_of_neg' {α : Type u} [ordered_add_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b < c) (ha : a < 0) : b + a < c :=
add_lt_of_lt_of_nonpos' hbc (has_lt.lt.le ha)
theorem mul_eq_one_iff' {α : Type u} [ordered_comm_monoid α] {a : α} {b : α} (ha : 1 ≤ a)
(hb : 1 ≤ b) : a * b = 1 ↔ a = 1 ∧ b = 1 :=
sorry
theorem monotone.mul' {α : Type u} [ordered_comm_monoid α] {β : Type u_1} [preorder β] {f : β → α}
{g : β → α} (hf : monotone f) (hg : monotone g) : monotone fun (x : β) => f x * g x :=
fun (x y : β) (h : x ≤ y) => mul_le_mul' (hf h) (hg h)
theorem monotone.mul_const' {α : Type u} [ordered_comm_monoid α] {β : Type u_1} [preorder β]
{f : β → α} (hf : monotone f) (a : α) : monotone fun (x : β) => f x * a :=
monotone.mul' hf monotone_const
theorem monotone.const_mul' {α : Type u} [ordered_comm_monoid α] {β : Type u_1} [preorder β]
{f : β → α} (hf : monotone f) (a : α) : monotone fun (x : β) => a * f x :=
monotone.mul' monotone_const hf
theorem bit0_pos {α : Type u} [ordered_add_comm_monoid α] {a : α} (h : 0 < a) : 0 < bit0 a :=
add_pos h h
namespace units
protected instance Mathlib.add_units.preorder {α : Type u} [add_monoid α] [preorder α] :
preorder (add_units α) :=
preorder.lift coe
@[simp] theorem Mathlib.add_units.coe_le_coe {α : Type u} [add_monoid α] [preorder α]
{a : add_units α} {b : add_units α} : ↑a ≤ ↑b ↔ a ≤ b :=
iff.rfl
-- should `to_additive` do this?
@[simp] theorem Mathlib.add_units.coe_lt_coe {α : Type u} [add_monoid α] [preorder α]
{a : add_units α} {b : add_units α} : ↑a < ↑b ↔ a < b :=
iff.rfl
protected instance partial_order {α : Type u} [monoid α] [partial_order α] :
partial_order (units α) :=
partial_order.lift coe ext
protected instance linear_order {α : Type u} [monoid α] [linear_order α] : linear_order (units α) :=
linear_order.lift coe ext
@[simp] theorem Mathlib.add_units.max_coe {α : Type u} [add_monoid α] [linear_order α]
{a : add_units α} {b : add_units α} : ↑(max a b) = max ↑a ↑b :=
sorry
@[simp] theorem Mathlib.add_units.min_coe {α : Type u} [add_monoid α] [linear_order α]
{a : add_units α} {b : add_units α} : ↑(min a b) = min ↑a ↑b :=
sorry
end units
namespace with_zero
protected instance preorder {α : Type u} [preorder α] : preorder (with_zero α) := with_bot.preorder
protected instance partial_order {α : Type u} [partial_order α] : partial_order (with_zero α) :=
with_bot.partial_order
protected instance order_bot {α : Type u} [partial_order α] : order_bot (with_zero α) :=
with_bot.order_bot
theorem zero_le {α : Type u} [partial_order α] (a : with_zero α) : 0 ≤ a := order_bot.bot_le a
theorem zero_lt_coe {α : Type u} [partial_order α] (a : α) : 0 < ↑a := with_bot.bot_lt_coe a
@[simp] theorem coe_lt_coe {α : Type u} [partial_order α] {a : α} {b : α} : ↑a < ↑b ↔ a < b :=
with_bot.coe_lt_coe
@[simp] theorem coe_le_coe {α : Type u} [partial_order α] {a : α} {b : α} : ↑a ≤ ↑b ↔ a ≤ b :=
with_bot.coe_le_coe
protected instance lattice {α : Type u} [lattice α] : lattice (with_zero α) := with_bot.lattice
protected instance linear_order {α : Type u} [linear_order α] : linear_order (with_zero α) :=
with_bot.linear_order
theorem mul_le_mul_left {α : Type u} [ordered_comm_monoid α] (a : with_zero α) (b : with_zero α) :
a ≤ b → ∀ (c : with_zero α), c * a ≤ c * b :=
sorry
theorem lt_of_mul_lt_mul_left {α : Type u} [ordered_comm_monoid α] (a : with_zero α)
(b : with_zero α) (c : with_zero α) : a * b < a * c → b < c :=
sorry
protected instance ordered_comm_monoid {α : Type u} [ordered_comm_monoid α] :
ordered_comm_monoid (with_zero α) :=
ordered_comm_monoid.mk comm_monoid_with_zero.mul sorry comm_monoid_with_zero.one sorry sorry sorry
partial_order.le partial_order.lt sorry sorry sorry mul_le_mul_left lt_of_mul_lt_mul_left
/-
Note 1 : the below is not an instance because it requires `zero_le`. It seems
like a rather pathological definition because α already has a zero.
Note 2 : there is no multiplicative analogue because it does not seem necessary.
Mathematicians might be more likely to use the order-dual version, where all
elements are ≤ 1 and then 1 is the top element.
-/
/--
If `0` is the least element in `α`, then `with_zero α` is an `ordered_add_comm_monoid`.
-/
def ordered_add_comm_monoid {α : Type u} [ordered_add_comm_monoid α] (zero_le : ∀ (a : α), 0 ≤ a) :
ordered_add_comm_monoid (with_zero α) :=
ordered_add_comm_monoid.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry
partial_order.le partial_order.lt sorry sorry sorry sorry sorry
end with_zero
namespace with_top
protected instance has_zero {α : Type u} [HasZero α] : HasZero (with_top α) := { zero := ↑0 }
@[simp] theorem coe_one {α : Type u} [HasOne α] : ↑1 = 1 := rfl
@[simp] theorem coe_eq_one {α : Type u} [HasOne α] {a : α} : ↑a = 1 ↔ a = 1 := coe_eq_coe
@[simp] theorem one_eq_coe {α : Type u} [HasOne α] {a : α} : 1 = ↑a ↔ a = 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl (1 = ↑a ↔ a = 1)) (propext eq_comm)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑a = 1 ↔ a = 1)) (propext coe_eq_one))) (iff.refl (a = 1)))
@[simp] theorem top_ne_one {α : Type u} [HasOne α] : ⊤ ≠ 1 :=
fun (ᾰ : ⊤ = 1) =>
eq.dcases_on ᾰ (fun (a : some 1 = none) => option.no_confusion a) (Eq.refl 1) (HEq.refl ᾰ)
@[simp] theorem one_ne_top {α : Type u} [HasOne α] : 1 ≠ ⊤ :=
fun (ᾰ : 1 = ⊤) =>
eq.dcases_on ᾰ (fun (a : none = some 1) => option.no_confusion a) (Eq.refl ⊤) (HEq.refl ᾰ)
protected instance has_add {α : Type u} [Add α] : Add (with_top α) :=
{ add :=
fun (o₁ o₂ : with_top α) =>
option.bind o₁ fun (a : α) => option.map (fun (b : α) => a + b) o₂ }
protected instance add_semigroup {α : Type u} [add_semigroup α] : add_semigroup (with_top α) :=
add_semigroup.mk Add.add sorry
theorem coe_add {α : Type u} [Add α] {a : α} {b : α} : ↑(a + b) = ↑a + ↑b := rfl
theorem coe_bit0 {α : Type u} [Add α] {a : α} : ↑(bit0 a) = bit0 ↑a := rfl
theorem coe_bit1 {α : Type u} [Add α] [HasOne α] {a : α} : ↑(bit1 a) = bit1 ↑a := rfl
@[simp] theorem add_top {α : Type u} [Add α] {a : with_top α} : a + ⊤ = ⊤ :=
option.cases_on a (idRhs (none + ⊤ = none + ⊤) rfl)
fun (a : α) => idRhs (some a + ⊤ = some a + ⊤) rfl
@[simp] theorem top_add {α : Type u} [Add α] {a : with_top α} : ⊤ + a = ⊤ := rfl
theorem add_eq_top {α : Type u} [Add α] {a : with_top α} {b : with_top α} :
a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ :=
sorry
theorem add_lt_top {α : Type u} [Add α] [partial_order α] {a : with_top α} {b : with_top α} :
a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ :=
sorry
theorem add_eq_coe {α : Type u} [Add α] {a : with_top α} {b : with_top α} {c : α} :
a + b = ↑c ↔ ∃ (a' : α), ∃ (b' : α), ↑a' = a ∧ ↑b' = b ∧ a' + b' = c :=
sorry
protected instance add_comm_semigroup {α : Type u} [add_comm_semigroup α] :
add_comm_semigroup (with_top α) :=
add_comm_semigroup.mk add_comm_semigroup.add sorry sorry
protected instance add_monoid {α : Type u} [add_monoid α] : add_monoid (with_top α) :=
add_monoid.mk Add.add sorry (some 0) sorry sorry
protected instance add_comm_monoid {α : Type u} [add_comm_monoid α] :
add_comm_monoid (with_top α) :=
add_comm_monoid.mk Add.add sorry 0 sorry sorry sorry
protected instance ordered_add_comm_monoid {α : Type u} [ordered_add_comm_monoid α] :
ordered_add_comm_monoid (with_top α) :=
ordered_add_comm_monoid.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry
partial_order.le partial_order.lt sorry sorry sorry sorry sorry
/-- Coercion from `α` to `with_top α` as an `add_monoid_hom`. -/
def coe_add_hom {α : Type u} [add_monoid α] : α →+ with_top α := add_monoid_hom.mk coe sorry sorry
@[simp] theorem coe_coe_add_hom {α : Type u} [add_monoid α] : ⇑coe_add_hom = coe := rfl
@[simp] theorem zero_lt_top {α : Type u} [ordered_add_comm_monoid α] : 0 < ⊤ := coe_lt_top 0
@[simp] theorem zero_lt_coe {α : Type u} [ordered_add_comm_monoid α] (a : α) : 0 < ↑a ↔ 0 < a :=
coe_lt_coe
end with_top
namespace with_bot
protected instance has_zero {α : Type u} [HasZero α] : HasZero (with_bot α) := with_top.has_zero
protected instance has_one {α : Type u} [HasOne α] : HasOne (with_bot α) := with_top.has_one
protected instance add_semigroup {α : Type u} [add_semigroup α] : add_semigroup (with_bot α) :=
with_top.add_semigroup
protected instance add_comm_semigroup {α : Type u} [add_comm_semigroup α] :
add_comm_semigroup (with_bot α) :=
with_top.add_comm_semigroup
protected instance add_monoid {α : Type u} [add_monoid α] : add_monoid (with_bot α) :=
with_top.add_monoid
protected instance add_comm_monoid {α : Type u} [add_comm_monoid α] :
add_comm_monoid (with_bot α) :=
with_top.add_comm_monoid
protected instance ordered_add_comm_monoid {α : Type u} [ordered_add_comm_monoid α] :
ordered_add_comm_monoid (with_bot α) :=
ordered_add_comm_monoid.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry
partial_order.le partial_order.lt sorry sorry sorry sorry sorry
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
theorem coe_zero {α : Type u} [HasZero α] : ↑0 = 0 := rfl
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
theorem coe_one {α : Type u} [HasOne α] : ↑1 = 1 := rfl
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
theorem coe_eq_zero {α : Type u_1} [add_monoid α] {a : α} : ↑a = 0 ↔ a = 0 := sorry
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
theorem coe_add {α : Type u} [add_semigroup α] (a : α) (b : α) : ↑(a + b) = ↑a + ↑b := sorry
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
theorem coe_bit0 {α : Type u} [add_semigroup α] {a : α} : ↑(bit0 a) = bit0 ↑a := sorry
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
theorem coe_bit1 {α : Type u} [add_semigroup α] [HasOne α] {a : α} : ↑(bit1 a) = bit1 ↑a := sorry
@[simp] theorem bot_add {α : Type u} [ordered_add_comm_monoid α] (a : with_bot α) : ⊥ + a = ⊥ := rfl
@[simp] theorem add_bot {α : Type u} [ordered_add_comm_monoid α] (a : with_bot α) : a + ⊥ = ⊥ :=
option.cases_on a (Eq.refl (none + ⊥)) fun (a : α) => Eq.refl (some a + ⊥)
end with_bot
/-- A canonically ordered additive monoid is an ordered commutative additive monoid
in which the ordering coincides with the subtractibility relation,
which is to say, `a ≤ b` iff there exists `c` with `b = a + c`.
This is satisfied by the natural numbers, for example, but not
the integers or other nontrivial `ordered_add_comm_group`s. -/
class canonically_ordered_add_monoid (α : Type u_1) extends ordered_add_comm_monoid α, order_bot α
where
le_iff_exists_add : ∀ (a b : α), a ≤ b ↔ ∃ (c : α), b = a + c
/-- A canonically ordered monoid is an ordered commutative monoid
in which the ordering coincides with the divisibility relation,
which is to say, `a ≤ b` iff there exists `c` with `b = a * c`.
Example seem rare; it seems more likely that the `order_dual`
of a naturally-occurring lattice satisfies this than the lattice
itself (for example, dual of the lattice of ideals of a PID or
Dedekind domain satisfy this; collections of all things ≤ 1 seem to
be more natural that collections of all things ≥ 1).
-/
class canonically_ordered_monoid (α : Type u_1) extends ordered_comm_monoid α, order_bot α where
le_iff_exists_mul : ∀ (a b : α), a ≤ b ↔ ∃ (c : α), b = a * c
theorem le_iff_exists_mul {α : Type u} [canonically_ordered_monoid α] {a : α} {b : α} :
a ≤ b ↔ ∃ (c : α), b = a * c :=
canonically_ordered_monoid.le_iff_exists_mul a b
theorem self_le_mul_right {α : Type u} [canonically_ordered_monoid α] (a : α) (b : α) : a ≤ a * b :=
iff.mpr le_iff_exists_mul (Exists.intro b rfl)
theorem self_le_add_left {α : Type u} [canonically_ordered_add_monoid α] (a : α) (b : α) :
a ≤ b + a :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ≤ b + a)) (add_comm b a))) (self_le_add_right a b)
@[simp] theorem one_le {α : Type u} [canonically_ordered_monoid α] (a : α) : 1 ≤ a := sorry
@[simp] theorem bot_eq_one {α : Type u} [canonically_ordered_monoid α] : ⊥ = 1 :=
le_antisymm bot_le (one_le ⊥)
@[simp] theorem add_eq_zero_iff {α : Type u} [canonically_ordered_add_monoid α] {a : α} {b : α} :
a + b = 0 ↔ a = 0 ∧ b = 0 :=
add_eq_zero_iff' (zero_le a) (zero_le b)
@[simp] theorem le_one_iff_eq_one {α : Type u} [canonically_ordered_monoid α] {a : α} :
a ≤ 1 ↔ a = 1 :=
{ mp := fun (h : a ≤ 1) => le_antisymm h (one_le a), mpr := fun (h : a = 1) => h ▸ le_refl a }
theorem pos_iff_ne_zero {α : Type u} [canonically_ordered_add_monoid α] {a : α} : 0 < a ↔ a ≠ 0 :=
{ mp := ne_of_gt, mpr := fun (hne : a ≠ 0) => lt_of_le_of_ne (zero_le a) (ne.symm hne) }
theorem exists_pos_mul_of_lt {α : Type u} [canonically_ordered_monoid α] {a : α} {b : α}
(h : a < b) : ∃ (c : α), ∃ (H : c > 1), a * c = b :=
sorry
theorem le_mul_left {α : Type u} [canonically_ordered_monoid α] {a : α} {b : α} {c : α}
(h : a ≤ c) : a ≤ b * c :=
sorry
theorem le_mul_right {α : Type u} [canonically_ordered_monoid α] {a : α} {b : α} {c : α}
(h : a ≤ b) : a ≤ b * c :=
sorry
-- This instance looks absurd: a monoid already has a zero
/-- Adding a new zero to a canonically ordered additive monoid produces another one. -/
protected instance with_zero.canonically_ordered_add_monoid {α : Type u}
[canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_zero α) :=
canonically_ordered_add_monoid.mk ordered_add_comm_monoid.add sorry ordered_add_comm_monoid.zero
sorry sorry sorry ordered_add_comm_monoid.le ordered_add_comm_monoid.lt sorry sorry sorry sorry
sorry 0 sorry sorry
protected instance with_top.canonically_ordered_add_monoid {α : Type u}
[canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_top α) :=
canonically_ordered_add_monoid.mk ordered_add_comm_monoid.add sorry ordered_add_comm_monoid.zero
sorry sorry sorry order_bot.le order_bot.lt sorry sorry sorry sorry sorry order_bot.bot sorry
sorry
/-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid
whose ordering is a linear order. -/
class canonically_linear_ordered_add_monoid (α : Type u_1)
extends canonically_ordered_add_monoid α, linear_order α where
/-- A canonically linear-ordered monoid is a canonically ordered monoid
whose ordering is a linear order. -/
class canonically_linear_ordered_monoid (α : Type u_1)
extends canonically_ordered_monoid α, linear_order α where
protected instance canonically_linear_ordered_add_monoid.semilattice_sup_bot {α : Type u}
[canonically_linear_ordered_add_monoid α] : semilattice_sup_bot α :=
semilattice_sup_bot.mk order_bot.bot lattice.le lattice.lt sorry sorry sorry sorry lattice.sup
sorry sorry sorry
/-- An ordered cancellative additive commutative monoid
is an additive commutative monoid with a partial order,
in which addition is cancellative and monotone. -/
class ordered_cancel_add_comm_monoid (α : Type u) extends add_cancel_comm_monoid α, partial_order α
where
add_le_add_left : ∀ (a b : α), a ≤ b → ∀ (c : α), c + a ≤ c + b
le_of_add_le_add_left : ∀ (a b c : α), a + b ≤ a + c → b ≤ c
/-- An ordered cancellative commutative monoid
is a commutative monoid with a partial order,
in which multiplication is cancellative and monotone. -/
class ordered_cancel_comm_monoid (α : Type u) extends partial_order α, cancel_comm_monoid α where
mul_le_mul_left : ∀ (a b : α), a ≤ b → ∀ (c : α), c * a ≤ c * b
le_of_mul_le_mul_left : ∀ (a b c : α), a * b ≤ a * c → b ≤ c
theorem le_of_mul_le_mul_left' {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α} :
a * b ≤ a * c → b ≤ c :=
ordered_cancel_comm_monoid.le_of_mul_le_mul_left
protected instance ordered_cancel_add_comm_monoid.to_ordered_add_comm_monoid {α : Type u}
[ordered_cancel_add_comm_monoid α] : ordered_add_comm_monoid α :=
ordered_add_comm_monoid.mk ordered_cancel_add_comm_monoid.add
ordered_cancel_add_comm_monoid.add_assoc ordered_cancel_add_comm_monoid.zero
ordered_cancel_add_comm_monoid.zero_add ordered_cancel_add_comm_monoid.add_zero
ordered_cancel_add_comm_monoid.add_comm ordered_cancel_add_comm_monoid.le
ordered_cancel_add_comm_monoid.lt ordered_cancel_add_comm_monoid.le_refl
ordered_cancel_add_comm_monoid.le_trans ordered_cancel_add_comm_monoid.le_antisymm
ordered_cancel_add_comm_monoid.add_le_add_left sorry
theorem mul_lt_mul_left' {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} (h : a < b)
(c : α) : c * a < c * b :=
lt_of_le_not_le (mul_le_mul_left' (has_lt.lt.le h) c) (mt le_of_mul_le_mul_left' (not_le_of_gt h))
theorem add_lt_add_right {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α} (h : a < b)
(c : α) : a + c < b + c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + c < b + c)) (add_comm a c)))
(eq.mpr (id (Eq._oldrec (Eq.refl (c + a < b + c)) (add_comm b c))) (add_lt_add_left h c))
theorem mul_lt_mul''' {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α} {d : α}
(h₁ : a < b) (h₂ : c < d) : a * c < b * d :=
lt_trans (mul_lt_mul_right' h₁ c) (mul_lt_mul_left' h₂ b)
theorem mul_lt_mul_of_le_of_lt {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
{d : α} (h₁ : a ≤ b) (h₂ : c < d) : a * c < b * d :=
lt_of_le_of_lt (mul_le_mul_right' h₁ c) (mul_lt_mul_left' h₂ b)
theorem mul_lt_mul_of_lt_of_le {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
{d : α} (h₁ : a < b) (h₂ : c ≤ d) : a * c < b * d :=
lt_of_lt_of_le (mul_lt_mul_right' h₁ c) (mul_le_mul_left' h₂ b)
theorem lt_add_of_pos_right {α : Type u} [ordered_cancel_add_comm_monoid α] (a : α) {b : α}
(h : 0 < b) : a < a + b :=
(fun (this : a + 0 < a + b) => eq.mp (Eq._oldrec (Eq.refl (a + 0 < a + b)) (add_zero a)) this)
(add_lt_add_left h a)
theorem lt_mul_of_one_lt_left' {α : Type u} [ordered_cancel_comm_monoid α] (a : α) {b : α}
(h : 1 < b) : a < b * a :=
(fun (this : 1 * a < b * a) => eq.mp (Eq._oldrec (Eq.refl (1 * a < b * a)) (one_mul a)) this)
(mul_lt_mul_right' h a)
theorem le_of_add_le_add_right {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α}
{c : α} (h : a + b ≤ c + b) : a ≤ c :=
sorry
theorem mul_lt_one {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} (ha : a < 1)
(hb : b < 1) : a * b < 1 :=
one_mul 1 ▸ mul_lt_mul''' ha hb
theorem add_neg_of_neg_of_nonpos {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α}
(ha : a < 0) (hb : b ≤ 0) : a + b < 0 :=
zero_add 0 ▸ add_lt_add_of_lt_of_le ha hb
theorem add_neg_of_nonpos_of_neg {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α}
(ha : a ≤ 0) (hb : b < 0) : a + b < 0 :=
zero_add 0 ▸ add_lt_add_of_le_of_lt ha hb
theorem lt_add_of_pos_of_le {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α} {c : α}
(ha : 0 < a) (hbc : b ≤ c) : b < a + c :=
zero_add b ▸ add_lt_add_of_lt_of_le ha hbc
theorem lt_add_of_le_of_pos {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b ≤ c) (ha : 0 < a) : b < c + a :=
add_zero b ▸ add_lt_add_of_le_of_lt hbc ha
theorem mul_le_of_le_one_of_le {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(ha : a ≤ 1) (hbc : b ≤ c) : a * b ≤ c :=
one_mul c ▸ mul_le_mul' ha hbc
theorem mul_le_of_le_of_le_one {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b ≤ c) (ha : a ≤ 1) : b * a ≤ c :=
mul_one c ▸ mul_le_mul' hbc ha
theorem add_lt_of_neg_of_le {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α} {c : α}
(ha : a < 0) (hbc : b ≤ c) : a + b < c :=
zero_add c ▸ add_lt_add_of_lt_of_le ha hbc
theorem mul_lt_of_le_of_lt_one {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b ≤ c) (ha : a < 1) : b * a < c :=
mul_one c ▸ mul_lt_mul_of_le_of_lt hbc ha
theorem lt_mul_of_one_le_of_lt {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(ha : 1 ≤ a) (hbc : b < c) : b < a * c :=
one_mul b ▸ mul_lt_mul_of_le_of_lt ha hbc
theorem lt_mul_of_lt_of_one_le {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b < c) (ha : 1 ≤ a) : b < c * a :=
mul_one b ▸ mul_lt_mul_of_lt_of_le hbc ha
theorem lt_add_of_pos_of_lt {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α} {c : α}
(ha : 0 < a) (hbc : b < c) : b < a + c :=
zero_add b ▸ add_lt_add ha hbc
theorem lt_mul_of_lt_of_one_lt {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b < c) (ha : 1 < a) : b < c * a :=
mul_one b ▸ mul_lt_mul''' hbc ha
theorem mul_lt_of_le_one_of_lt {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(ha : a ≤ 1) (hbc : b < c) : a * b < c :=
one_mul c ▸ mul_lt_mul_of_le_of_lt ha hbc
theorem add_lt_of_lt_of_nonpos {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α}
{c : α} (hbc : b < c) (ha : a ≤ 0) : b + a < c :=
add_zero c ▸ add_lt_add_of_lt_of_le hbc ha
theorem mul_lt_of_lt_one_of_lt {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α} {c : α}
(ha : a < 1) (hbc : b < c) : a * b < c :=
one_mul c ▸ mul_lt_mul''' ha hbc
theorem add_lt_of_lt_of_neg {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α} {c : α}
(hbc : b < c) (ha : a < 0) : b + a < c :=
add_zero c ▸ add_lt_add hbc ha
@[simp] theorem add_le_add_iff_left {α : Type u} [ordered_cancel_add_comm_monoid α] (a : α) {b : α}
{c : α} : a + b ≤ a + c ↔ b ≤ c :=
{ mp := le_of_add_le_add_left, mpr := fun (h : b ≤ c) => add_le_add_left h a }
@[simp] theorem add_le_add_iff_right {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α} {b : α}
(c : α) : a + c ≤ b + c ↔ a ≤ b :=
add_comm c a ▸ add_comm c b ▸ add_le_add_iff_left c
@[simp] theorem mul_lt_mul_iff_left {α : Type u} [ordered_cancel_comm_monoid α] (a : α) {b : α}
{c : α} : a * b < a * c ↔ b < c :=
{ mp := lt_of_mul_lt_mul_left', mpr := fun (h : b < c) => mul_lt_mul_left' h a }
@[simp] theorem mul_lt_mul_iff_right {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α}
(c : α) : a * c < b * c ↔ a < b :=
mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_iff_left c
@[simp] theorem le_add_iff_nonneg_right {α : Type u} [ordered_cancel_add_comm_monoid α] (a : α)
{b : α} : a ≤ a + b ↔ 0 ≤ b :=
(fun (this : a + 0 ≤ a + b ↔ 0 ≤ b) =>
eq.mp (Eq._oldrec (Eq.refl (a + 0 ≤ a + b ↔ 0 ≤ b)) (add_zero a)) this)
(add_le_add_iff_left a)
@[simp] theorem le_add_iff_nonneg_left {α : Type u} [ordered_cancel_add_comm_monoid α] (a : α)
{b : α} : a ≤ b + a ↔ 0 ≤ b :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ≤ b + a ↔ 0 ≤ b)) (add_comm b a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a ≤ a + b ↔ 0 ≤ b)) (propext (le_add_iff_nonneg_right a))))
(iff.refl (0 ≤ b)))
@[simp] theorem lt_mul_iff_one_lt_right' {α : Type u} [ordered_cancel_comm_monoid α] (a : α)
{b : α} : a < a * b ↔ 1 < b :=
(fun (this : a * 1 < a * b ↔ 1 < b) =>
eq.mp (Eq._oldrec (Eq.refl (a * 1 < a * b ↔ 1 < b)) (mul_one a)) this)
(mul_lt_mul_iff_left a)
@[simp] theorem lt_mul_iff_one_lt_left' {α : Type u} [ordered_cancel_comm_monoid α] (a : α)
{b : α} : a < b * a ↔ 1 < b :=
eq.mpr (id (Eq._oldrec (Eq.refl (a < b * a ↔ 1 < b)) (mul_comm b a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a < a * b ↔ 1 < b)) (propext (lt_mul_iff_one_lt_right' a))))
(iff.refl (1 < b)))
@[simp] theorem mul_le_iff_le_one_left' {α : Type u} [ordered_cancel_comm_monoid α] {a : α}
{b : α} : a * b ≤ b ↔ a ≤ 1 :=
sorry
@[simp] theorem add_le_iff_nonpos_right {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α}
{b : α} : a + b ≤ a ↔ b ≤ 0 :=
sorry
@[simp] theorem add_lt_iff_neg_right {α : Type u} [ordered_cancel_add_comm_monoid α] {a : α}
{b : α} : a + b < b ↔ a < 0 :=
sorry
@[simp] theorem mul_lt_iff_lt_one_left' {α : Type u} [ordered_cancel_comm_monoid α] {a : α}
{b : α} : a * b < a ↔ b < 1 :=
sorry
theorem mul_eq_one_iff_eq_one_of_one_le {α : Type u} [ordered_cancel_comm_monoid α] {a : α} {b : α}
(ha : 1 ≤ a) (hb : 1 ≤ b) : a * b = 1 ↔ a = 1 ∧ b = 1 :=
sorry
theorem monotone.add_strict_mono {α : Type u} [ordered_cancel_add_comm_monoid α] {β : Type u_1}
[preorder β] {f : β → α} {g : β → α} (hf : monotone f) (hg : strict_mono g) :
strict_mono fun (x : β) => f x + g x :=
fun (x y : β) (h : x < y) => add_lt_add_of_le_of_lt (hf (le_of_lt h)) (hg h)
theorem strict_mono.mul_monotone' {α : Type u} [ordered_cancel_comm_monoid α] {β : Type u_1}
[preorder β] {f : β → α} {g : β → α} (hf : strict_mono f) (hg : monotone g) :
strict_mono fun (x : β) => f x * g x :=
fun (x y : β) (h : x < y) => mul_lt_mul_of_lt_of_le (hf h) (hg (le_of_lt h))
theorem strict_mono.add_const {α : Type u} [ordered_cancel_add_comm_monoid α] {β : Type u_1}
[preorder β] {f : β → α} (hf : strict_mono f) (c : α) : strict_mono fun (x : β) => f x + c :=
strict_mono.add_monotone hf monotone_const
theorem strict_mono.const_add {α : Type u} [ordered_cancel_add_comm_monoid α] {β : Type u_1}
[preorder β] {f : β → α} (hf : strict_mono f) (c : α) : strict_mono fun (x : β) => c + f x :=
monotone.add_strict_mono monotone_const hf
theorem with_top.add_lt_add_iff_left {α : Type u} [ordered_cancel_add_comm_monoid α]
{a : with_top α} {b : with_top α} {c : with_top α} : a < ⊤ → (a + c < a + b ↔ c < b) :=
sorry
theorem with_bot.add_lt_add_iff_left {α : Type u} [ordered_cancel_add_comm_monoid α]
{a : with_bot α} {b : with_bot α} {c : with_bot α} : ⊥ < a → (a + c < a + b ↔ c < b) :=
sorry
theorem with_top.add_lt_add_iff_right {α : Type u} [ordered_cancel_add_comm_monoid α]
{a : with_top α} {b : with_top α} {c : with_top α} : a < ⊤ → (c + a < b + a ↔ c < b) :=
sorry
theorem with_bot.add_lt_add_iff_right {α : Type u} [ordered_cancel_add_comm_monoid α]
{a : with_bot α} {b : with_bot α} {c : with_bot α} : ⊥ < a → (c + a < b + a ↔ c < b) :=
sorry
/-! Some lemmas about types that have an ordering and a binary operation, with no
rules relating them. -/
theorem fn_min_add_fn_max {α : Type u} {β : Type u_1} [linear_order α] [add_comm_semigroup β]
(f : α → β) (n : α) (m : α) : f (min n m) + f (max n m) = f n + f m :=
sorry
theorem min_mul_max {α : Type u} [linear_order α] [comm_semigroup α] (n : α) (m : α) :
min n m * max n m = n * m :=
fn_min_mul_fn_max id n m
/-- A linearly ordered cancellative additive commutative monoid
is an additive commutative monoid with a decidable linear order
in which addition is cancellative and monotone. -/
class linear_ordered_cancel_add_comm_monoid (α : Type u)
extends ordered_cancel_add_comm_monoid α, linear_order α where
/-- A linearly ordered cancellative commutative monoid
is a commutative monoid with a linear order
in which multiplication is cancellative and monotone. -/
class linear_ordered_cancel_comm_monoid (α : Type u)
extends linear_order α, ordered_cancel_comm_monoid α where
theorem min_add_add_left {α : Type u} [linear_ordered_cancel_add_comm_monoid α] (a : α) (b : α)
(c : α) : min (a + b) (a + c) = a + min b c :=
Eq.symm (monotone.map_min (monotone.const_add monotone_id a))
theorem min_mul_mul_right {α : Type u} [linear_ordered_cancel_comm_monoid α] (a : α) (b : α)
(c : α) : min (a * c) (b * c) = min a b * c :=
Eq.symm (monotone.map_min (monotone.mul_const' monotone_id c))
theorem max_add_add_left {α : Type u} [linear_ordered_cancel_add_comm_monoid α] (a : α) (b : α)
(c : α) : max (a + b) (a + c) = a + max b c :=
Eq.symm (monotone.map_max (monotone.const_add monotone_id a))
theorem max_mul_mul_right {α : Type u} [linear_ordered_cancel_comm_monoid α] (a : α) (b : α)
(c : α) : max (a * c) (b * c) = max a b * c :=
Eq.symm (monotone.map_max (monotone.mul_const' monotone_id c))
theorem min_le_add_of_nonneg_right {α : Type u} [linear_ordered_cancel_add_comm_monoid α] {a : α}
{b : α} (hb : 0 ≤ b) : min a b ≤ a + b :=
iff.mpr min_le_iff (Or.inl (le_add_of_nonneg_right hb))
theorem min_le_add_of_nonneg_left {α : Type u} [linear_ordered_cancel_add_comm_monoid α] {a : α}
{b : α} (ha : 0 ≤ a) : min a b ≤ a + b :=
iff.mpr min_le_iff (Or.inr (le_add_of_nonneg_left ha))
theorem max_le_mul_of_one_le {α : Type u} [linear_ordered_cancel_comm_monoid α] {a : α} {b : α}
(ha : 1 ≤ a) (hb : 1 ≤ b) : max a b ≤ a * b :=
iff.mpr max_le_iff { left := le_mul_of_one_le_right' hb, right := le_mul_of_one_le_left' ha }
namespace order_dual
protected instance ordered_comm_monoid {α : Type u} [ordered_comm_monoid α] :
ordered_comm_monoid (order_dual α) :=
ordered_comm_monoid.mk comm_monoid.mul sorry comm_monoid.one sorry sorry sorry partial_order.le
partial_order.lt sorry sorry sorry sorry sorry
protected instance ordered_cancel_add_comm_monoid {α : Type u} [ordered_cancel_add_comm_monoid α] :
ordered_cancel_add_comm_monoid (order_dual α) :=
ordered_cancel_add_comm_monoid.mk ordered_add_comm_monoid.add sorry sorry
ordered_add_comm_monoid.zero sorry sorry sorry sorry ordered_add_comm_monoid.le
ordered_add_comm_monoid.lt sorry sorry sorry sorry sorry
protected instance linear_ordered_cancel_add_comm_monoid {α : Type u}
[linear_ordered_cancel_add_comm_monoid α] :
linear_ordered_cancel_add_comm_monoid (order_dual α) :=
linear_ordered_cancel_add_comm_monoid.mk ordered_cancel_add_comm_monoid.add sorry sorry
ordered_cancel_add_comm_monoid.zero sorry sorry sorry sorry linear_order.le linear_order.lt
sorry sorry sorry sorry sorry sorry linear_order.decidable_le linear_order.decidable_eq
linear_order.decidable_lt
end order_dual
namespace prod
protected instance ordered_cancel_comm_monoid {M : Type u_1} {N : Type u_2}
[ordered_cancel_comm_monoid M] [ordered_cancel_comm_monoid N] :
ordered_cancel_comm_monoid (M × N) :=
ordered_cancel_comm_monoid.mk comm_monoid.mul sorry sorry comm_monoid.one sorry sorry sorry sorry
partial_order.le partial_order.lt sorry sorry sorry sorry sorry
end prod
protected instance multiplicative.preorder {α : Type u} [preorder α] :
preorder (multiplicative α) :=
id
protected instance additive.preorder {α : Type u} [preorder α] : preorder (additive α) := id
protected instance multiplicative.partial_order {α : Type u} [partial_order α] :
partial_order (multiplicative α) :=
id
protected instance additive.partial_order {α : Type u} [partial_order α] :
partial_order (additive α) :=
id
protected instance multiplicative.linear_order {α : Type u} [linear_order α] :
linear_order (multiplicative α) :=
id
protected instance additive.linear_order {α : Type u} [linear_order α] :
linear_order (additive α) :=
id
protected instance multiplicative.ordered_comm_monoid {α : Type u} [ordered_add_comm_monoid α] :
ordered_comm_monoid (multiplicative α) :=
ordered_comm_monoid.mk comm_monoid.mul sorry comm_monoid.one sorry sorry sorry partial_order.le
partial_order.lt sorry sorry sorry ordered_add_comm_monoid.add_le_add_left
ordered_add_comm_monoid.lt_of_add_lt_add_left
protected instance additive.ordered_add_comm_monoid {α : Type u} [ordered_comm_monoid α] :
ordered_add_comm_monoid (additive α) :=
ordered_add_comm_monoid.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry
partial_order.le partial_order.lt sorry sorry sorry ordered_comm_monoid.mul_le_mul_left
ordered_comm_monoid.lt_of_mul_lt_mul_left
protected instance multiplicative.ordered_cancel_comm_monoid {α : Type u}
[ordered_cancel_add_comm_monoid α] : ordered_cancel_comm_monoid (multiplicative α) :=
ordered_cancel_comm_monoid.mk right_cancel_semigroup.mul sorry sorry ordered_comm_monoid.one sorry
sorry sorry sorry ordered_comm_monoid.le ordered_comm_monoid.lt sorry sorry sorry sorry
ordered_cancel_add_comm_monoid.le_of_add_le_add_left
protected instance additive.ordered_cancel_add_comm_monoid {α : Type u}
[ordered_cancel_comm_monoid α] : ordered_cancel_add_comm_monoid (additive α) :=
ordered_cancel_add_comm_monoid.mk add_right_cancel_semigroup.add sorry sorry
ordered_add_comm_monoid.zero sorry sorry sorry sorry ordered_add_comm_monoid.le
ordered_add_comm_monoid.lt sorry sorry sorry sorry
ordered_cancel_comm_monoid.le_of_mul_le_mul_left
end Mathlib |
7d191e0daabee6c0f6da407df6dd1b6017af53d4 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/analysis/analytic/inverse.lean | 58786d8a47fe9c097816bc773353090b9062f222 | [
"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 | 27,116 | lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.analytic.composition
/-!
# Inverse of analytic functions
We construct the left and right inverse of a formal multilinear series with invertible linear term,
we prove that they coincide and study their properties (notably convergence).
## Main statements
* `p.left_inv i`: the formal left inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.right_inv i`: the formal right inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.left_inv_comp` says that `p.left_inv i` is indeed a left inverse to `p` when `p₁ = i`.
* `p.right_inv_comp` says that `p.right_inv i` is indeed a right inverse to `p` when `p₁ = i`.
* `p.left_inv_eq_right_inv`: the two inverses coincide.
* `p.radius_right_inv_pos_of_radius_pos`: if a power series has a positive radius of convergence,
then so does its inverse.
-/
open_locale big_operators classical topological_space
open finset filter
namespace formal_multilinear_series
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{F : Type*} [normed_group F] [normed_space 𝕜 F]
/-! ### The left inverse of a formal multilinear series -/
/-- The left inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `(left_inv p i) ∘ p = id`. For this, the linear term
`p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `q ∘ p` is `∑ qₖ (p_{j₁}, ..., p_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `qₙ (p₁, ..., p₁)`. We adjust the definition so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def left_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
formal_multilinear_series 𝕜 F E
| 0 := 0
| 1 := (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm
| (n+2) := - ∑ c : {c : composition (n+2) // c.length < n + 2},
have (c : composition (n+2)).length < n+2 := c.2,
(left_inv (c : composition (n+2)).length).comp_along_composition
(p.comp_continuous_linear_map i.symm) c
@[simp] lemma left_inv_coeff_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.left_inv i 0 = 0 := by rw left_inv
@[simp] lemma left_inv_coeff_one (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.left_inv i 1 = (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm := by rw left_inv
/-- The left inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
lemma left_inv_remove_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.remove_zero.left_inv i = p.left_inv i :=
begin
ext1 n,
induction n using nat.strong_rec' with n IH,
cases n, { simp }, -- if one replaces `simp` with `refl`, the proof times out in the kernel.
cases n, { simp }, -- TODO: why?
simp only [left_inv, neg_inj],
refine finset.sum_congr rfl (λ c cuniv, _),
rcases c with ⟨c, hc⟩,
ext v,
dsimp,
simp [IH _ hc],
end
/-- The left inverse to a formal multilinear series is indeed a left inverse, provided its linear
term is invertible. -/
lemma left_inv_comp (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) :
(left_inv p i).comp p = id 𝕜 E :=
begin
ext n v,
cases n,
{ simp only [left_inv, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def,
not_false_iff, zero_ne_one, comp_coeff_zero']},
cases n,
{ simp only [left_inv, comp_coeff_one, h, id_apply_one, continuous_linear_equiv.coe_apply,
continuous_linear_equiv.symm_apply_apply, continuous_multilinear_curry_fin1_symm_apply] },
have A : (finset.univ : finset (composition (n+2)))
= {c | composition.length c < n + 2}.to_finset ∪ {composition.ones (n+2)},
{ refine subset.antisymm (λ c hc, _) (subset_univ _),
by_cases h : c.length < n + 2,
{ simp [h] },
{ simp [composition.eq_ones_iff_le_length.2 (not_lt.1 h)] } },
have B : disjoint ({c | composition.length c < n + 2} : set (composition (n + 2))).to_finset
{composition.ones (n+2)}, by simp,
have C : (p.left_inv i (composition.ones (n + 2)).length)
(λ (j : fin (composition.ones n.succ.succ).length), p 1 (λ k,
v ((fin.cast_le (composition.length_le _)) j)))
= p.left_inv i (n+2) (λ (j : fin (n+2)), p 1 (λ k, v j)),
{ apply formal_multilinear_series.congr _ (composition.ones_length _) (λ j hj1 hj2, _),
exact formal_multilinear_series.congr _ rfl (λ k hk1 hk2, by congr) },
have D : p.left_inv i (n+2) (λ (j : fin (n+2)), p 1 (λ k, v j)) =
- ∑ (c : composition (n + 2)) in {c : composition (n + 2) | c.length < n + 2}.to_finset,
(p.left_inv i c.length) (p.apply_composition c v),
{ simp only [left_inv, continuous_multilinear_map.neg_apply, neg_inj,
continuous_multilinear_map.sum_apply],
convert (sum_to_finset_eq_subtype (λ (c : composition (n+2)), c.length < n+2)
(λ (c : composition (n+2)), (continuous_multilinear_map.comp_along_composition
(p.comp_continuous_linear_map ↑(i.symm)) c (p.left_inv i c.length))
(λ (j : fin (n + 2)), p 1 (λ (k : fin 1), v j)))).symm.trans _,
simp only [comp_continuous_linear_map_apply_composition,
continuous_multilinear_map.comp_along_composition_apply],
congr,
ext c,
congr,
ext k,
simp [h] },
simp [formal_multilinear_series.comp, show n + 2 ≠ 1, by dec_trivial, A, finset.sum_union B,
apply_composition_ones, C, D],
end
/-! ### The right inverse of a formal multilinear series -/
/-- The right inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `p ∘ (right_inv p i) = id`. For this, the linear
term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `p ∘ q` is `∑ pₖ (q_{j₁}, ..., q_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `p₁ (qₙ)`. We adjust the definition of `qₙ` so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
formal_multilinear_series 𝕜 F E
| 0 := 0
| 1 := (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm
| (n+2) :=
let q : formal_multilinear_series 𝕜 F E := λ k, if h : k < n + 2 then right_inv k else 0 in
- (i.symm : F →L[𝕜] E).comp_continuous_multilinear_map ((p.comp q) (n+2))
@[simp] lemma right_inv_coeff_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.right_inv i 0 = 0 := by rw right_inv
@[simp] lemma right_inv_coeff_one (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.right_inv i 1 = (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm := by rw right_inv
/-- The right inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
lemma right_inv_remove_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.remove_zero.right_inv i = p.right_inv i :=
begin
ext1 n,
induction n using nat.strong_rec' with n IH,
cases n, { simp },
cases n, { simp },
simp only [right_inv, neg_inj],
unfold_coes,
congr' 1,
rw remove_zero_comp_of_pos _ _ (show 0 < n+2, by dec_trivial),
congr' 1,
ext k,
by_cases hk : k < n+2; simp [hk, IH]
end
lemma comp_right_inv_aux1 {n : ℕ} (hn : 0 < n)
(p : formal_multilinear_series 𝕜 E F) (q : formal_multilinear_series 𝕜 F E) (v : fin n → F) :
p.comp q n v =
(∑ (c : composition n) in {c : composition n | 1 < c.length}.to_finset,
p c.length (q.apply_composition c v)) + p 1 (λ i, q n v) :=
begin
have A : (finset.univ : finset (composition n))
= {c | 1 < composition.length c}.to_finset ∪ {composition.single n hn},
{ refine subset.antisymm (λ c hc, _) (subset_univ _),
by_cases h : 1 < c.length,
{ simp [h] },
{ have : c.length = 1,
by { refine (eq_iff_le_not_lt.2 ⟨ _, h⟩).symm, exact c.length_pos_of_pos hn },
rw ← composition.eq_single_iff_length hn at this,
simp [this] } },
have B : disjoint ({c | 1 < composition.length c} : set (composition n)).to_finset
{composition.single n hn}, by simp,
have C : p (composition.single n hn).length
(q.apply_composition (composition.single n hn) v)
= p 1 (λ (i : fin 1), q n v),
{ apply p.congr (composition.single_length hn) (λ j hj1 hj2, _),
simp [apply_composition_single] },
simp [formal_multilinear_series.comp, A, finset.sum_union B, C],
end
lemma comp_right_inv_aux2
(p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (v : fin (n + 2) → F) :
∑ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset,
p c.length (apply_composition (λ (k : ℕ), ite (k < n + 2) (p.right_inv i k) 0) c v) =
∑ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset,
p c.length ((p.right_inv i).apply_composition c v) :=
begin
have N : 0 < n + 2, by dec_trivial,
refine sum_congr rfl (λ c hc, p.congr rfl (λ j hj1 hj2, _)),
have : ∀ k, c.blocks_fun k < n + 2,
{ simp only [set.mem_to_finset, set.mem_set_of_eq] at hc,
simp [← composition.ne_single_iff N, composition.eq_single_iff_length, ne_of_gt hc] },
simp [apply_composition, this],
end
/-- The right inverse to a formal multilinear series is indeed a right inverse, provided its linear
term is invertible and its constant term vanishes. -/
lemma comp_right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) (h0 : p 0 = 0) :
p.comp (right_inv p i) = id 𝕜 F :=
begin
ext n v,
cases n,
{ simp only [h0, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def, not_false_iff,
zero_ne_one, comp_coeff_zero']},
cases n,
{ simp only [comp_coeff_one, h, right_inv, continuous_linear_equiv.apply_symm_apply, id_apply_one,
continuous_linear_equiv.coe_apply, continuous_multilinear_curry_fin1_symm_apply] },
have N : 0 < n+2, by dec_trivial,
simp [comp_right_inv_aux1 N, h, right_inv, lt_irrefl n, show n + 2 ≠ 1, by dec_trivial,
← sub_eq_add_neg, sub_eq_zero, comp_right_inv_aux2],
end
lemma right_inv_coeff (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (hn : 2 ≤ n) :
p.right_inv i n = - (i.symm : F →L[𝕜] E).comp_continuous_multilinear_map
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition n)),
p.comp_along_composition (p.right_inv i) c) :=
begin
cases n, { exact false.elim (zero_lt_two.not_le hn) },
cases n, { exact false.elim (one_lt_two.not_le hn) },
simp only [right_inv, neg_inj],
congr' 1,
ext v,
have N : 0 < n + 2, by dec_trivial,
have : (p 1) (λ (i : fin 1), 0) = 0 := continuous_multilinear_map.map_zero _,
simp [comp_right_inv_aux1 N, lt_irrefl n, this, comp_right_inv_aux2]
end
/-! ### Coincidence of the left and the right inverse -/
private lemma left_inv_eq_right_inv_aux (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) (h0 : p 0 = 0) :
left_inv p i = right_inv p i := calc
left_inv p i = (left_inv p i).comp (id 𝕜 F) : by simp
... = (left_inv p i).comp (p.comp (right_inv p i)) : by rw comp_right_inv p i h h0
... = ((left_inv p i).comp p).comp (right_inv p i) : by rw comp_assoc
... = (id 𝕜 E).comp (right_inv p i) : by rw left_inv_comp p i h
... = right_inv p i : by simp
/-- The left inverse and the right inverse of a formal multilinear series coincide. This is not at
all obvious from their definition, but it follows from uniqueness of inverses (which comes from the
fact that composition is associative on formal multilinear series). -/
theorem left_inv_eq_right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) :
left_inv p i = right_inv p i := calc
left_inv p i = left_inv p.remove_zero i : by rw left_inv_remove_zero
... = right_inv p.remove_zero i : by { apply left_inv_eq_right_inv_aux; simp [h] }
... = right_inv p i : by rw right_inv_remove_zero
/-!
### Convergence of the inverse of a power series
Assume that `p` is a convergent multilinear series, and let `q` be its (left or right) inverse.
Using the left-inverse formula gives
$$
q_n = - (p_1)^{-n} \sum_{k=0}^{n-1} \sum_{i_1 + \dotsc + i_k = n} q_k (p_{i_1}, \dotsc, p_{i_k}).
$$
Assume for simplicity that we are in dimension `1` and `p₁ = 1`. In the formula for `qₙ`, the term
`q_{n-1}` appears with a multiplicity of `n-1` (choosing the index `i_j` for which `i_j = 2` while
all the other indices are equal to `1`), which indicates that `qₙ` might grow like `n!`. This is
bad for summability properties.
It turns out that the right-inverse formula is better behaved, and should instead be used for this
kind of estimate. It reads
$$
q_n = - (p_1)^{-1} \sum_{k=2}^n \sum_{i_1 + \dotsc + i_k = n} p_k (q_{i_1}, \dotsc, q_{i_k}).
$$
Here, `q_{n-1}` can only appear in the term with `k = 2`, and it only appears twice, so there is
hope this formula can lead to an at most geometric behavior.
Let `Qₙ = ∥qₙ∥`. Bounding `∥pₖ∥` with `C r^k` gives an inequality
$$
Q_n ≤ C' \sum_{k=2}^n r^k \sum_{i_1 + \dotsc + i_k = n} Q_{i_1} \dotsm Q_{i_k}.
$$
This formula is not enough to prove by naive induction on `n` a bound of the form `Qₙ ≤ D R^n`.
However, assuming that the inequality above were an equality, one could get a formula for the
generating series of the `Qₙ`:
$$
\begin{align}
Q(z) & := \sum Q_n z^n = Q_1 z + C' \sum_{2 \leq k \leq n} \sum_{i_1 + \dotsc + i_k = n}
(r z^{i_1} Q_{i_1}) \dotsm (r z^{i_k} Q_{i_k})
\\ & = Q_1 z + C' \sum_{k = 2}^\infty (\sum_{i_1 \geq 1} r z^{i_1} Q_{i_1})
\dotsm (\sum_{i_k \geq 1} r z^{i_k} Q_{i_k})
\\ & = Q_1 z + C' \sum_{k = 2}^\infty (r Q(z))^k
= Q_1 z + C' (r Q(z))^2 / (1 - r Q(z)).
\end{align}
$$
One can solve this formula explicitly. The solution is analytic in a neighborhood of `0` in `ℂ`,
hence its coefficients grow at most geometrically (by a contour integral argument), and therefore
the original `Qₙ`, which are bounded by these ones, are also at most geometric.
This classical argument is not really satisfactory, as it requires an a priori bound on a complex
analytic function. Another option would be to compute explicitly its terms (with binomial
coefficients) to obtain an explicit geometric bound, but this would be very painful.
Instead, we will use the above intuition, but in a slightly different form, with finite sums and an
induction. I learnt this trick in [pöschel2017siegelsternberg]. Let
$S_n = \sum_{k=1}^n Q_k a^k$ (where `a` is a positive real parameter to be chosen suitably small).
The above computation but with finite sums shows that
$$
S_n \leq Q_1 a + C' \sum_{k=2}^n (r S_{n-1})^k.
$$
In particular, $S_n \leq Q_1 a + C' (r S_{n-1})^2 / (1- r S_{n-1})$.
Assume that $S_{n-1} \leq K a$, where `K > Q₁` is fixed and `a` is small enough so that
`r K a ≤ 1/2` (to control the denominator). Then this equation gives a bound
$S_n \leq Q_1 a + 2 C' r^2 K^2 a^2$.
If `a` is small enough, this is bounded by `K a` as the second term is quadratic in `a`, and
therefore negligible.
By induction, we deduce `Sₙ ≤ K a` for all `n`, which gives in particular the fact that `aⁿ Qₙ`
remains bounded.
-/
/-- First technical lemma to control the growth of coefficients of the inverse. Bound the explicit
expression for `∑_{k<n+1} aᵏ Qₖ` in terms of a sum of powers of the same sum one step before,
in a general abstract setup. -/
lemma radius_right_inv_pos_of_radius_pos_aux1
(n : ℕ) (p : ℕ → ℝ) (hp : ∀ k, 0 ≤ p k) {r a : ℝ} (hr : 0 ≤ r) (ha : 0 ≤ a) :
∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, p (c.blocks_fun j))
≤ ∑ j in Ico 2 (n + 1), r ^ j * (∑ k in Ico 1 n, a ^ k * p k) ^ j :=
calc
∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, p (c.blocks_fun j))
= ∑ k in Ico 2 (n + 1),
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
∏ j, r * (a ^ (c.blocks_fun j) * p (c.blocks_fun j))) :
begin
simp_rw [mul_sum],
apply sum_congr rfl (λ k hk, _),
apply sum_congr rfl (λ c hc, _),
rw [prod_mul_distrib, prod_mul_distrib, prod_pow_eq_pow_sum, composition.sum_blocks_fun,
prod_const, card_fin],
ring,
end
... ≤ ∑ d in comp_partial_sum_target 2 (n + 1) n,
∏ (j : fin d.2.length), r * (a ^ d.2.blocks_fun j * p (d.2.blocks_fun j)) :
begin
rw sum_sigma',
refine sum_le_sum_of_subset_of_nonneg _ (λ x hx1 hx2,
prod_nonneg (λ j hj, mul_nonneg hr (mul_nonneg (pow_nonneg ha _) (hp _)))),
rintros ⟨k, c⟩ hd,
simp only [set.mem_to_finset, Ico.mem, mem_sigma, set.mem_set_of_eq] at hd,
simp only [mem_comp_partial_sum_target_iff],
refine ⟨hd.2, c.length_le.trans_lt hd.1.2, λ j, _⟩,
have : c ≠ composition.single k (zero_lt_two.trans_le hd.1.1),
by simp [composition.eq_single_iff_length, ne_of_gt hd.2],
rw composition.ne_single_iff at this,
exact (this j).trans_le (nat.lt_succ_iff.mp hd.1.2)
end
... = ∑ e in comp_partial_sum_source 2 (n+1) n, ∏ (j : fin e.1), r * (a ^ e.2 j * p (e.2 j)) :
begin
symmetry,
apply comp_change_of_variables_sum,
rintros ⟨k, blocks_fun⟩ H,
have K : (comp_change_of_variables 2 (n + 1) n ⟨k, blocks_fun⟩ H).snd.length = k, by simp,
congr' 2; try { rw K },
rw fin.heq_fun_iff K.symm,
assume j,
rw comp_change_of_variables_blocks_fun,
end
... = ∑ j in Ico 2 (n+1), r ^ j * (∑ k in Ico 1 n, a ^ k * p k) ^ j :
begin
rw [comp_partial_sum_source, ← sum_sigma' (Ico 2 (n + 1))
(λ (k : ℕ), (fintype.pi_finset (λ (i : fin k), Ico 1 n) : finset (fin k → ℕ)))
(λ n e, ∏ (j : fin n), r * (a ^ e j * p (e j)))],
apply sum_congr rfl (λ j hj, _),
simp only [← @multilinear_map.mk_pi_algebra_apply ℝ (fin j) _ _ ℝ],
simp only [← multilinear_map.map_sum_finset (multilinear_map.mk_pi_algebra ℝ (fin j) ℝ)
(λ k (m : ℕ), r * (a ^ m * p m))],
simp only [multilinear_map.mk_pi_algebra_apply],
dsimp,
simp [prod_const, ← mul_sum, mul_pow],
end
/-- Second technical lemma to control the growth of coefficients of the inverse. Bound the explicit
expression for `∑_{k<n+1} aᵏ Qₖ` in terms of a sum of powers of the same sum one step before,
in the specific setup we are interesting in, by reducing to the general bound in
`radius_right_inv_pos_of_radius_pos_aux1`. -/
lemma radius_right_inv_pos_of_radius_pos_aux2
{n : ℕ} (hn : 2 ≤ n + 1) (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
{r a C : ℝ} (hr : 0 ≤ r) (ha : 0 ≤ a) (hC : 0 ≤ C) (hp : ∀ n, ∥p n∥ ≤ C * r ^ n) :
(∑ k in Ico 1 (n + 1), a ^ k * ∥p.right_inv i k∥) ≤
∥(i.symm : F →L[𝕜] E)∥ * a + ∥(i.symm : F →L[𝕜] E)∥ * C * ∑ k in Ico 2 (n + 1),
(r * ((∑ j in Ico 1 n, a ^ j * ∥p.right_inv i j∥))) ^ k :=
let I := ∥(i.symm : F →L[𝕜] E)∥ in calc
∑ k in Ico 1 (n + 1), a ^ k * ∥p.right_inv i k∥
= a * I + ∑ k in Ico 2 (n + 1), a ^ k * ∥p.right_inv i k∥ :
by simp only [linear_isometry_equiv.norm_map, pow_one, right_inv_coeff_one,
Ico.succ_singleton, sum_singleton, ← sum_Ico_consecutive _ one_le_two hn]
... = a * I + ∑ k in Ico 2 (n + 1), a ^ k *
∥(i.symm : F →L[𝕜] E).comp_continuous_multilinear_map
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
p.comp_along_composition (p.right_inv i) c)∥ :
begin
congr' 1,
apply sum_congr rfl (λ j hj, _),
rw [right_inv_coeff _ _ _ (Ico.mem.1 hj).1, norm_neg],
end
... ≤ a * ∥(i.symm : F →L[𝕜] E)∥ + ∑ k in Ico 2 (n + 1), a ^ k * (I *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
C * r ^ c.length * ∏ j, ∥p.right_inv i (c.blocks_fun j)∥)) :
begin
apply_rules [add_le_add, le_refl, sum_le_sum (λ j hj, _), mul_le_mul_of_nonneg_left,
pow_nonneg, ha],
apply (continuous_linear_map.norm_comp_continuous_multilinear_map_le _ _).trans,
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _),
apply (norm_sum_le _ _).trans,
apply sum_le_sum (λ c hc, _),
apply (comp_along_composition_norm _ _ _).trans,
apply mul_le_mul_of_nonneg_right (hp _),
exact prod_nonneg (λ j hj, norm_nonneg _),
end
... = I * a + I * C * ∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, ∥p.right_inv i (c.blocks_fun j)∥) :
begin
simp_rw [mul_assoc C, ← mul_sum, ← mul_assoc, mul_comm _ (∥↑i.symm∥), mul_assoc, ← mul_sum,
← mul_assoc, mul_comm _ C, mul_assoc, ← mul_sum],
ring,
end
... ≤ I * a + I * C * ∑ k in Ico 2 (n+1), (r * ((∑ j in Ico 1 n, a ^ j * ∥p.right_inv i j∥))) ^ k :
begin
apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, norm_nonneg, hC, mul_nonneg],
simp_rw [mul_pow],
apply radius_right_inv_pos_of_radius_pos_aux1 n (λ k, ∥p.right_inv i k∥)
(λ k, norm_nonneg _) hr ha,
end
/-- If a a formal multilinear series has a positive radius of convergence, then its right inverse
also has a positive radius of convergence. -/
theorem radius_right_inv_pos_of_radius_pos (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(hp : 0 < p.radius) : 0 < (p.right_inv i).radius :=
begin
obtain ⟨C, r, Cpos, rpos, ple⟩ : ∃ C r (hC : 0 < C) (hr : 0 < r), ∀ (n : ℕ), ∥p n∥ ≤ C * r ^ n :=
le_mul_pow_of_radius_pos p hp,
let I := ∥(i.symm : F →L[𝕜] E)∥,
-- choose `a` small enough to make sure that `∑_{k ≤ n} aᵏ Qₖ` will be controllable by
-- induction
obtain ⟨a, apos, ha1, ha2⟩ : ∃ a (apos : 0 < a),
(2 * I * C * r^2 * (I + 1) ^ 2 * a ≤ 1) ∧ (r * (I + 1) * a ≤ 1/2),
{ have : tendsto (λ a, 2 * I * C * r^2 * (I + 1) ^ 2 * a) (𝓝 0)
(𝓝 (2 * I * C * r^2 * (I + 1) ^ 2 * 0)) := tendsto_const_nhds.mul tendsto_id,
have A : ∀ᶠ a in 𝓝 0, 2 * I * C * r^2 * (I + 1) ^ 2 * a < 1,
by { apply (tendsto_order.1 this).2, simp [zero_lt_one] },
have : tendsto (λ a, r * (I + 1) * a) (𝓝 0)
(𝓝 (r * (I + 1) * 0)) := tendsto_const_nhds.mul tendsto_id,
have B : ∀ᶠ a in 𝓝 0, r * (I + 1) * a < 1/2,
by { apply (tendsto_order.1 this).2, simp [zero_lt_one] },
have C : ∀ᶠ a in 𝓝[set.Ioi (0 : ℝ)] (0 : ℝ), (0 : ℝ) < a,
by { filter_upwards [self_mem_nhds_within], exact λ a ha, ha },
rcases (C.and ((A.and B).filter_mono inf_le_left)).exists with ⟨a, ha⟩,
exact ⟨a, ha.1, ha.2.1.le, ha.2.2.le⟩ },
-- check by induction that the partial sums are suitably bounded, using the choice of `a` and the
-- inductive control from Lemma `radius_right_inv_pos_of_radius_pos_aux2`.
let S := λ n, ∑ k in Ico 1 n, a ^ k * ∥p.right_inv i k∥,
have IRec : ∀ n, 1 ≤ n → S n ≤ (I + 1) * a,
{ apply nat.le_induction,
{ simp only [S],
rw [Ico.eq_empty_of_le (le_refl 1), sum_empty],
exact mul_nonneg (add_nonneg (norm_nonneg _) zero_le_one) apos.le },
{ assume n one_le_n hn,
have In : 2 ≤ n + 1, by linarith,
have Snonneg : 0 ≤ S n :=
sum_nonneg (λ x hx, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _)),
have rSn : r * S n ≤ 1/2 := calc
r * S n ≤ r * ((I+1) * a) : mul_le_mul_of_nonneg_left hn rpos.le
... ≤ 1/2 : by rwa [← mul_assoc],
calc S (n + 1) ≤ I * a + I * C * ∑ k in Ico 2 (n + 1), (r * S n)^k :
radius_right_inv_pos_of_radius_pos_aux2 In p i rpos.le apos.le Cpos.le ple
... = I * a + I * C * (((r * S n) ^ 2 - (r * S n) ^ (n + 1)) / (1 - r * S n)) :
by { rw geom_sum_Ico' _ In, exact ne_of_lt (rSn.trans_lt (by norm_num)) }
... ≤ I * a + I * C * ((r * S n) ^ 2 / (1/2)) :
begin
apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg,
Cpos.le],
refine div_le_div (sq_nonneg _) _ (by norm_num) (by linarith),
simp only [sub_le_self_iff],
apply pow_nonneg (mul_nonneg rpos.le Snonneg),
end
... = I * a + 2 * I * C * (r * S n) ^ 2 : by ring
... ≤ I * a + 2 * I * C * (r * ((I + 1) * a)) ^ 2 :
by apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg,
Cpos.le, zero_le_two, pow_le_pow_of_le_left, rpos.le]
... = (I + 2 * I * C * r^2 * (I + 1) ^ 2 * a) * a : by ring
... ≤ (I + 1) * a :
by apply_rules [mul_le_mul_of_nonneg_right, apos.le, add_le_add, le_refl] } },
-- conclude that all coefficients satisfy `aⁿ Qₙ ≤ (I + 1) a`.
let a' : nnreal := ⟨a, apos.le⟩,
suffices H : (a' : ennreal) ≤ (p.right_inv i).radius,
by { apply lt_of_lt_of_le _ H, exact_mod_cast apos },
apply le_radius_of_bound _ ((I + 1) * a) (λ n, _),
by_cases hn : n = 0,
{ have : ∥p.right_inv i n∥ = ∥p.right_inv i 0∥, by congr; try { rw hn },
simp only [this, norm_zero, zero_mul, right_inv_coeff_zero],
apply_rules [mul_nonneg, add_nonneg, norm_nonneg, zero_le_one, apos.le] },
{ have one_le_n : 1 ≤ n := bot_lt_iff_ne_bot.2 hn,
calc ∥p.right_inv i n∥ * ↑a' ^ n = a ^ n * ∥p.right_inv i n∥ : mul_comm _ _
... ≤ ∑ k in Ico 1 (n + 1), a ^ k * ∥p.right_inv i k∥ :
begin
have : ∀ k ∈ Ico 1 (n + 1), 0 ≤ a ^ k * ∥p.right_inv i k∥ :=
λ k hk, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _),
exact single_le_sum this (by simp [one_le_n]),
end
... ≤ (I + 1) * a : IRec (n + 1) (by dec_trivial) }
end
end formal_multilinear_series
|
d0963e1f8e3555181b76ad15f1c6529947ca02e9 | 6f510b1ed724f95a55b7d26a8dcd13e1264123dd | /src/page00.lean | 16a63bc5027261730a7a52ee3cc057319f0a166c | [] | no_license | jcommelin/oberharmersbach2019 | adaf2e54ba4eff7c178c933978055ff4d6b0593b | d2cdf780a10baa8502a9b0cae01c7efa318649a6 | refs/heads/master | 1,587,558,516,731 | 1,550,558,213,000 | 1,550,558,213,000 | 170,372,753 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 361 | lean | /- 2019-02-19, Oberharmersbach
Interactive theorem proving with a computer — my experience
-- _
-- | | ___ __ _ _ __
-- | |/ _ \/ _` | '_ \
-- | | __| (_| | | | |
-- |_|\___|\__,_|_| |_|
--
A rose-colored introduction
by Johan Commelin -/
|
6e8354c1b075e06985936f79ae22935cb603c8b7 | ff5230333a701471f46c57e8c115a073ebaaa448 | /tests/lean/run/smt_ematch2.lean | a1e2de83cb949259324102c130d839bc84a75d6f | [
"Apache-2.0"
] | permissive | stanford-cs242/lean | f81721d2b5d00bc175f2e58c57b710d465e6c858 | 7bd861261f4a37326dcf8d7a17f1f1f330e4548c | refs/heads/master | 1,600,957,431,849 | 1,576,465,093,000 | 1,576,465,093,000 | 225,779,423 | 0 | 3 | Apache-2.0 | 1,575,433,936,000 | 1,575,433,935,000 | null | UTF-8 | Lean | false | false | 2,729 | lean | universe variables u
namespace foo
variables {α : Type u}
open smt_tactic
meta def no_ac : smt_config :=
{ cc_cfg := { ac := ff }}
meta def blast : tactic unit :=
using_smt_with no_ac $ intros >> iterate (ematch >> try close)
section add_comm_monoid
variables [add_comm_monoid α]
attribute [ematch] add_comm add_assoc
theorem add_comm_three (a b c : α) : a + b + c = c + b + a :=
by blast
theorem add.comm4 : ∀ (n m k l : α), n + m + (k + l) = n + k + (m + l) :=
by blast
end add_comm_monoid
section group
variable [group α]
attribute [ematch] mul_assoc mul_left_inv one_mul
theorem inv_mul_cancel_left (a b : α) : a⁻¹ * (a * b) = b :=
by blast
end group
namespace subt
constant subt : nat → nat → Prop
axiom subt_trans {a b c : nat} : subt a b → subt b c → subt a c
attribute [ematch] subt_trans
lemma ex (a b c d : nat) : subt a b → subt b c → subt c d → subt a d :=
by blast
end subt
section ring
variables [ring α] (a b : α)
attribute [ematch] zero_mul
lemma ex2 : a = 0 → a * b = 0 :=
by blast
definition ex1 (a b : int) : a = 0 → a * b = 0 :=
by blast
end ring
namespace cast1
constant C : nat → Type
constant f : ∀ n, C n → C n
axiom fax (n : nat) (a : C (2*n)) : (: f (2*n) a :) = a
attribute [ematch] fax
lemma ex3 (n m : nat) (a : C n) : n = 2*m → f n a = a :=
by blast
end cast1
namespace cast2
constant C : nat → Type
constant f : ∀ n, C n → C n
constant g : ∀ n, C n → C n → C n
axiom gffax (n : nat) (a b : C n) : (: g n (f n a) (f n b) :) = a
attribute [ematch] gffax
lemma ex4 (n m : nat) (a c : C n) (b : C m) : n = m → a == f m b → g n a (f n c) == b :=
by blast
end cast2
namespace cast3
constant C : nat → Type
constant f : ∀ n, C n → C n
constant g : ∀ n, C n → C n → C n
axiom gffax (n : nat) (a b : C n) : (: g n a b :) = a
attribute [ematch] gffax
lemma ex5 (n m : nat) (a c : C n) (b : C m) (e : m = n) : a == b → g n a a == b :=
by blast
end cast3
namespace tuple
constant {α} tuple: Type α → nat → Type α
constant nil {α : Type u} : tuple α 0
constant append {α : Type u} {n m : nat} : tuple α n → tuple α m → tuple α (n + m)
infix ` ++ ` := append
axiom append_assoc {α : Type u} {n₁ n₂ n₃ : nat} (v₁ : tuple α n₁) (v₂ : tuple α n₂) (v₃ : tuple α n₃) :
(v₁ ++ v₂) ++ v₃ == v₁ ++ (v₂ ++ v₃)
attribute [ematch] append_assoc
variables {p m n q : nat}
variables {xs : tuple α m}
variables {ys : tuple α n}
variables {zs : tuple α p}
variables {ws : tuple α q}
lemma ex6 : p = m + n → zs == xs ++ ys → zs ++ ws == xs ++ (ys ++ ws) :=
by blast
def ex : p = n + m → zs == xs ++ ys → zs ++ ws == xs ++ (ys ++ ws) :=
by blast
end tuple
end foo
|
7d3914f3c5d339f97f500e4832ae1ca216ee6154 | 968efffb675bc4487e76008d6cb8e2f1120fb63c | /src/ltest/default.lean | eafa5d81787d0a0fe209c21546c6c8ac836fcddf | [] | no_license | jroesch/ltest | 5435329a69f791d14309dc76e104ccd2a9e04cc6 | 2bf75f5fe46129c7ddd5e34dcc710735daa458bf | refs/heads/master | 1,611,260,605,891 | 1,495,607,848,000 | 1,495,607,848,000 | 92,227,695 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,829 | lean | structure test_result :=
(test_name : name)
(success : bool)
-- @Kha? can we just build a procedure which auto derives this?
meta instance : has_reflect test_result
| ⟨ n , succ ⟩ := unchecked_cast `(test_result.mk %%(reflect n) %%(reflect succ))
meta instance : has_to_string test_result :=
⟨ fun res, "{ test_name := " ++ to_string res.test_name ++ ", " ++ to_string res.success ++ "}" ⟩
@[user_attribute] def test_result_attr : user_attribute :=
{ name := `test_result, descr := "the result of running a test" }
meta def mk_test_res_decl (res : test_result) : tactic (name × declaration) := do
decl_name ← name.mk_string "_test_result" <$> tactic.mk_fresh_name,
let decl := declaration.defn decl_name [] `(test_result) (reflect res) reducibility_hints.abbrev false,
return (decl_name, decl)
meta def create_test_result (res : test_result) : tactic unit := do
(decl_name, decl) ← mk_test_res_decl res,
tactic.add_decl decl,
tactic.set_basic_attribute `test_result decl_name
meta def mk_list_expr (ty : expr) : list name → tactic expr
| [] := tactic.to_expr ``(@list.nil %%ty)
| (n :: ns) := do
n' ← tactic.mk_const n,
tl ← mk_list_expr ns,
tactic.to_expr ``(%%n' :: %%tl)
meta def collect_test_results : tactic (list test_result) := do
ns ← attribute.get_instances `test_result,
ty ← tactic.to_expr ``(test_result),
ls_expr ← mk_list_expr ty ns,
tactic.eval_expr (list test_result) ls_expr
meta def must_fail (tac : tactic unit) :=
(do tactic.fail_if_success tac,
create_test_result { test_name := `foo, success := bool.tt },
tactic.admit) <|> create_test_result { test_name := `foo, success := bool.ff }
def foo : 1 = 1 :=
begin
create_test_result { test_name := `foo, success := bool.ff },
reflexivity
end
run_cmd (do rs ← collect_test_results, tactic.trace (to_string rs))
|
fbd7b21792c9e10c885a724df3f464c7c0c63a38 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/theories/group_theory/pgroup.lean | ada18aca1021146781f93d8e5a1f3649859a25cf | [
"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 | 15,510 | 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 theories.number_theory.primes data algebra.group algebra.group_power algebra.group_bigops
import .cyclic .finsubg .hom .perm .action
open nat fin list function subtype
namespace group_theory
section pgroup
open finset fintype
variables {G S : Type} [ambientG : group G] [deceqG : decidable_eq G] [finS : fintype S] [deceqS : decidable_eq S]
include ambientG
definition psubg (H : finset G) (p m : nat) : Prop := prime p ∧ card H = p^m
include deceqG finS deceqS
variables {H : finset G} [subgH : is_finsubg H]
include subgH
variables {hom : G → perm S} [Hom : is_hom_class hom]
include Hom
open finset.partition
lemma card_mod_eq_of_action_by_psubg {p : nat} :
∀ {m : nat}, psubg H p m → (card S) % p = (card (fixed_points hom H)) % p
| 0 := by rewrite [↑psubg, pow_zero]; intro Psubg;
rewrite [finsubg_eq_singleton_one_of_card_one (and.right Psubg), fixed_points_of_one]
| (succ m) := take Ppsubg, begin
rewrite [@orbit_class_equation' G S ambientG _ finS deceqS hom Hom H subgH],
apply add_mod_eq_of_dvd, apply dvd_Sum_of_dvd,
intro s Psin,
rewrite mem_sep_iff at Psin,
cases Psin with Psinorbs Pcardne,
esimp [orbits, equiv_classes, orbit_partition] at Psinorbs,
rewrite mem_image_iff at Psinorbs,
cases Psinorbs with a Pa,
cases Pa with Pain Porb,
substvars,
cases Ppsubg with Pprime PcardH,
have Pdvd : card (orbit hom H a) ∣ p ^ (succ m),
begin
rewrite -PcardH,
apply dvd_of_eq_mul (finset.card (stab hom H a)),
apply orbit_stabilizer_theorem
end,
apply or.elim (eq_one_or_dvd_of_dvd_prime_pow Pprime Pdvd),
intro Pcardeq, contradiction,
intro Ppdvd, exact Ppdvd
end
end pgroup
section psubg_cosets
open finset fintype
variables {G : Type} [ambientG : group G] [finG : fintype G] [deceqG : decidable_eq G]
include ambientG deceqG finG
variables {H : finset G} [finsubgH : is_finsubg H]
include finsubgH
lemma card_psubg_cosets_mod_eq {p : nat} {m : nat} :
psubg H p m → (card (lcoset_type univ H)) % p = card (lcoset_type (normalizer H) H) % p :=
assume Psubg, by rewrite [-card_aol_fixed_points_eq_card_cosets]; exact card_mod_eq_of_action_by_psubg Psubg
end psubg_cosets
section cauchy
lemma prodl_rotl_eq_one_of_prodl_eq_one {A B : Type} [gB : group B] {f : A → B} :
∀ {l : list A}, Prodl l f = 1 → Prodl (list.rotl l) f = 1
| nil := assume Peq, rfl
| (a::l) := begin
rewrite [rotl_cons, Prodl_cons f, Prodl_append _ _ f, Prodl_singleton],
exact mul_eq_one_of_mul_eq_one
end
section rotl_peo
variables {A : Type} [ambA : group A]
include ambA
variable [finA : fintype A]
include finA
variable (A)
definition all_prodl_eq_one (n : nat) : list (list A) :=
map (λ l, cons (Prodl l id)⁻¹ l) (all_lists_of_len n)
variable {A}
lemma prodl_eq_one_of_mem_all_prodl_eq_one {n : nat} {l : list A} : l ∈ all_prodl_eq_one A n → Prodl l id = 1 :=
assume Plin, obtain l' Pl' Pl, from exists_of_mem_map Plin,
by substvars; rewrite [Prodl_cons id _ l', mul.left_inv]
lemma length_of_mem_all_prodl_eq_one {n : nat} {l : list A} : l ∈ all_prodl_eq_one A n → length l = succ n :=
assume Plin, obtain l' Pl' Pl, from exists_of_mem_map Plin,
begin substvars, rewrite [length_cons, length_mem_all_lists Pl'] end
lemma nodup_all_prodl_eq_one {n : nat} : nodup (all_prodl_eq_one A n) :=
nodup_map (take l₁ l₂ Peq, tail_eq_of_cons_eq Peq) nodup_all_lists
lemma all_prodl_eq_one_complete {n : nat} : ∀ {l : list A}, length l = succ n → Prodl l id = 1 → l ∈ all_prodl_eq_one A n
| nil := assume Pleq, by contradiction
| (a::l) := assume Pleq Pprod,
begin
rewrite length_cons at Pleq,
rewrite (Prodl_cons id a l) at Pprod,
rewrite [eq_inv_of_mul_eq_one Pprod],
apply mem_map, apply mem_all_lists, apply succ.inj Pleq
end
open fintype
lemma length_all_prodl_eq_one {n : nat} : length (@all_prodl_eq_one A _ _ n) = (card A)^n :=
eq.trans !length_map length_all_lists
open fin
definition prodseq {n : nat} (s : seq A n) : A := Prodl (upto n) s
attribute [reducible]
definition peo {n : nat} (s : seq A n) := prodseq s = 1
definition constseq {n : nat} (s : seq A (succ n)) := ∀ i, s i = s !zero
lemma prodseq_eq {n :nat} {s : seq A n} : prodseq s = Prodl (fun_to_list s) id :=
Prodl_map
lemma prodseq_eq_pow_of_constseq {n : nat} (s : seq A (succ n)) :
constseq s → prodseq s = (s !zero) ^ succ n :=
assume Pc, have Pcl : ∀ i, i ∈ upto (succ n) → s i = s !zero,
from take i, assume Pin, Pc i,
by rewrite [↑prodseq, Prodl_eq_pow_of_const _ Pcl, fin.length_upto]
lemma seq_eq_of_constseq_of_eq {n : nat} {s₁ s₂ : seq A (succ n)} :
constseq s₁ → constseq s₂ → s₁ !zero = s₂ !zero → s₁ = s₂ :=
assume Pc₁ Pc₂ Peq, funext take i, by rewrite [Pc₁ i, Pc₂ i, Peq]
lemma peo_const_one : ∀ {n : nat}, peo (λ i : fin n, (1 : A))
| 0 := rfl
| (succ n) := let s := λ i : fin (succ n), (1 : A) in
have Pconst : constseq s, from take i, rfl,
calc prodseq s = (s !zero) ^ succ n : prodseq_eq_pow_of_constseq s Pconst
... = (1 : A) ^ succ n : rfl
... = 1 : one_pow
variable [deceqA : decidable_eq A]
include deceqA
variable (A)
attribute [reducible]
definition peo_seq (n : nat) := {s : seq A (succ n) | peo s}
definition peo_seq_one (n : nat) : peo_seq A n :=
tag (λ i : fin (succ n), (1 : A)) peo_const_one
definition all_prodseq_eq_one (n : nat) : list (seq A (succ n)) :=
dmap (λ l, length l = card (fin (succ n))) list_to_fun (all_prodl_eq_one A n)
definition all_peo_seqs (n : nat) : list (peo_seq A n) :=
dmap peo tag (all_prodseq_eq_one A n)
variable {A}
lemma prodseq_eq_one_of_mem_all_prodseq_eq_one {n : nat} {s : seq A (succ n)} :
s ∈ all_prodseq_eq_one A n → prodseq s = 1 :=
assume Psin, obtain l Pex, from exists_of_mem_dmap Psin,
obtain leq Pin Peq, from Pex,
by rewrite [prodseq_eq, Peq, list_to_fun_to_list, prodl_eq_one_of_mem_all_prodl_eq_one Pin]
lemma all_prodseq_eq_one_complete {n : nat} {s : seq A (succ n)} :
prodseq s = 1 → s ∈ all_prodseq_eq_one A n :=
assume Peq,
have Plin : map s (elems (fin (succ n))) ∈ all_prodl_eq_one A n,
from begin
apply all_prodl_eq_one_complete,
rewrite [length_map], exact length_upto (succ n),
rewrite prodseq_eq at Peq, exact Peq
end,
have Psin : list_to_fun (map s (elems (fin (succ n)))) (length_map_of_fintype s) ∈ all_prodseq_eq_one A n,
from mem_dmap _ Plin,
by rewrite [fun_eq_list_to_fun_map s (length_map_of_fintype s)]; apply Psin
lemma nodup_all_prodseq_eq_one {n : nat} : nodup (all_prodseq_eq_one A n) :=
dmap_nodup_of_dinj dinj_list_to_fun nodup_all_prodl_eq_one
lemma rotl1_peo_of_peo {n : nat} {s : seq A n} : peo s → peo (rotl_fun 1 s) :=
begin rewrite [↑peo, *prodseq_eq, seq_rotl_eq_list_rotl], apply prodl_rotl_eq_one_of_prodl_eq_one end
section
-- local attribute perm.f [coercion]
lemma rotl_perm_peo_of_peo {n : nat} : ∀ {m} {s : seq A n}, peo s → peo (rotl_perm A n m s)
| 0 := begin rewrite [↑rotl_perm, rotl_seq_zero], intros, assumption end
| (succ m) := take s,
have Pmul : rotl_perm A n (m + 1) s = rotl_fun 1 (rotl_perm A n m s), from
calc s ∘ (rotl (m + 1)) = s ∘ ((rotl m) ∘ (rotl 1)) : rotl_compose
... = s ∘ (rotl m) ∘ (rotl 1) : comp.assoc,
begin
rewrite [-add_one, Pmul], intro P,
exact rotl1_peo_of_peo (rotl_perm_peo_of_peo P)
end
end
lemma nodup_all_peo_seqs {n : nat} : nodup (all_peo_seqs A n) :=
dmap_nodup_of_dinj (dinj_tag peo) nodup_all_prodseq_eq_one
lemma all_peo_seqs_complete {n : nat} : ∀ s : peo_seq A n, s ∈ all_peo_seqs A n :=
take ps, subtype.destruct ps (take s, assume Ps,
have Pin : s ∈ all_prodseq_eq_one A n, from all_prodseq_eq_one_complete Ps,
mem_dmap Ps Pin)
lemma length_all_peo_seqs {n : nat} : length (all_peo_seqs A n) = (card A)^n :=
eq.trans (eq.trans
(show length (all_peo_seqs A n) = length (all_prodseq_eq_one A n), from
have Pmap : map elt_of (all_peo_seqs A n) = all_prodseq_eq_one A n,
from map_dmap_of_inv_of_pos (λ s P, rfl)
(λ s, prodseq_eq_one_of_mem_all_prodseq_eq_one),
by rewrite [-Pmap, length_map])
(show length (all_prodseq_eq_one A n) = length (all_prodl_eq_one A n), from
have Pmap : map fun_to_list (all_prodseq_eq_one A n) = all_prodl_eq_one A n,
from map_dmap_of_inv_of_pos list_to_fun_to_list
(λ l Pin, by rewrite [length_of_mem_all_prodl_eq_one Pin, card_fin]),
by rewrite [-Pmap, length_map]))
length_all_prodl_eq_one
attribute [instance]
definition peo_seq_is_fintype {n : nat} : fintype (peo_seq A n) :=
fintype.mk (all_peo_seqs A n) nodup_all_peo_seqs all_peo_seqs_complete
lemma card_peo_seq {n : nat} : card (peo_seq A n) = (card A)^n :=
length_all_peo_seqs
section
variable (A)
-- local attribute perm.f [coercion]
definition rotl_peo_seq (n : nat) (m : nat) (s : peo_seq A n) : peo_seq A n :=
tag (rotl_perm A (succ n) m (elt_of s)) (rotl_perm_peo_of_peo (has_property s))
variable {A}
end
lemma rotl_peo_seq_zero {n : nat} : rotl_peo_seq A n 0 = id :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, ↑rotl_perm, rotl_seq_zero] end
lemma rotl_peo_seq_id {n : nat} : rotl_peo_seq A n (succ n) = id :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, -rotl_perm_pow_eq, rotl_perm_pow_eq_one] end
lemma rotl_peo_seq_compose {n i j : nat} :
(rotl_peo_seq A n i) ∘ (rotl_peo_seq A n j) = rotl_peo_seq A n (j + i) :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, ↑rotl_perm, ↑rotl_fun, comp.assoc, rotl_compose] end
lemma rotl_peo_seq_mod {n i : nat} : rotl_peo_seq A n i = rotl_peo_seq A n (i % succ n) :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, rotl_perm_mod] end
lemma rotl_peo_seq_inj {n m : nat} : injective (rotl_peo_seq A n m) :=
take ps₁ ps₂, subtype.destruct ps₁ (λ s₁ P₁, subtype.destruct ps₂ (λ s₂ P₂,
assume Peq, tag_eq (rotl_fun_inj (dinj_tag peo _ _ Peq))))
variable (A)
attribute [reducible]
definition rotl_perm_ps (n : nat) (m : fin (succ n)) : perm (peo_seq A n) :=
perm.mk (rotl_peo_seq A n m) rotl_peo_seq_inj
variable {A}
variable {n : nat}
lemma rotl_perm_ps_eq {m : fin (succ n)} {s : peo_seq A n} : elt_of (perm.f (rotl_perm_ps A n m) s) = perm.f (rotl_perm A (succ n) m) (elt_of s) := rfl
lemma rotl_perm_ps_eq_of_rotl_perm_eq {i j : fin (succ n)} :
(rotl_perm A (succ n) i) = (rotl_perm A (succ n) j) → (rotl_perm_ps A n i) = (rotl_perm_ps A n j) :=
assume Peq, eq_of_feq (funext take s, subtype.eq (by rewrite [*rotl_perm_ps_eq, Peq]))
lemma rotl_perm_ps_hom (i j : fin (succ n)) :
rotl_perm_ps A n (i+j) = (rotl_perm_ps A n i) * (rotl_perm_ps A n j) :=
eq_of_feq (begin rewrite [↑rotl_perm_ps, {val (i+j)}val_madd, add.comm, -rotl_peo_seq_mod, -rotl_peo_seq_compose] end)
section
local attribute group_of_add_group [instance]
attribute [instance]
definition rotl_perm_ps_is_hom : is_hom_class (rotl_perm_ps A n) :=
is_hom_class.mk rotl_perm_ps_hom
open finset
lemma const_of_is_fixed_point {s : peo_seq A n} :
is_fixed_point (rotl_perm_ps A n) univ s → constseq (elt_of s) :=
assume Pfp, take i, begin
rewrite [-(Pfp i !mem_univ) at {1}, rotl_perm_ps_eq, ↑rotl_perm, ↑rotl_fun, {i}mk_mod_eq at {2}, rotl_to_zero]
end
lemma const_of_rotl_fixed_point {s : peo_seq A n} :
s ∈ fixed_points (rotl_perm_ps A n) univ → constseq (elt_of s) :=
assume Psin, take i, begin
apply const_of_is_fixed_point, exact is_fixed_point_of_mem_fixed_points Psin
end
lemma pow_eq_one_of_mem_fixed_points {s : peo_seq A n} :
s ∈ fixed_points (rotl_perm_ps A n) univ → (elt_of s !zero)^(succ n) = 1 :=
assume Psin, eq.trans
(eq.symm (prodseq_eq_pow_of_constseq (elt_of s) (const_of_rotl_fixed_point Psin)))
(has_property s)
lemma peo_seq_one_is_fixed_point : is_fixed_point (rotl_perm_ps A n) univ (peo_seq_one A n) :=
take h, assume Pin, by esimp [rotl_perm_ps]
lemma peo_seq_one_mem_fixed_points : peo_seq_one A n ∈ fixed_points (rotl_perm_ps A n) univ :=
mem_fixed_points_of_exists_of_is_fixed_point (exists.intro !zero !mem_univ) peo_seq_one_is_fixed_point
lemma generator_of_prime_of_dvd_order {p : nat}
: prime p → p ∣ card A → ∃ g : A, g ≠ 1 ∧ g^p = 1 :=
assume Pprime Pdvd,
let pp := nat.pred p, spp := nat.succ pp in
have Peq : spp = p, from succ_pred_prime Pprime,
have Ppsubg : psubg (@univ (fin spp) _) spp 1,
from and.intro (eq.symm Peq ▸ Pprime) (by rewrite [Peq, card_fin, pow_one]),
have (pow_nat (card A) pp) % spp = (card (fixed_points (rotl_perm_ps A pp) univ)) % spp,
by rewrite -card_peo_seq; apply card_mod_eq_of_action_by_psubg Ppsubg,
have Pcardmod : (pow_nat (card A) pp) % p = (card (fixed_points (rotl_perm_ps A pp) univ)) % p,
from Peq ▸ this,
have Pfpcardmod : (card (fixed_points (rotl_perm_ps A pp) univ)) % p = 0,
from eq.trans (eq.symm Pcardmod) (mod_eq_zero_of_dvd (dvd_pow_of_dvd_of_pos Pdvd (pred_prime_pos Pprime))),
have Pfpcardpos : card (fixed_points (rotl_perm_ps A pp) univ) > 0,
from card_pos_of_mem peo_seq_one_mem_fixed_points,
have Pfpcardgt1 : card (fixed_points (rotl_perm_ps A pp) univ) > 1,
from gt_one_of_pos_of_prime_dvd Pprime Pfpcardpos Pfpcardmod,
obtain s₁ s₂ Pin₁ Pin₂ Psnes, from exists_two_of_card_gt_one Pfpcardgt1,
decidable.by_cases
(λ Pe₁ : elt_of s₁ !zero = 1,
have Pne₂ : elt_of s₂ !zero ≠ 1,
from assume Pe₂,
absurd
(subtype.eq (seq_eq_of_constseq_of_eq
(const_of_rotl_fixed_point Pin₁)
(const_of_rotl_fixed_point Pin₂)
(eq.trans Pe₁ (eq.symm Pe₂))))
Psnes,
exists.intro (elt_of s₂ !zero)
(and.intro Pne₂ (Peq ▸ pow_eq_one_of_mem_fixed_points Pin₂)))
(λ Pne, exists.intro (elt_of s₁ !zero)
(and.intro Pne (Peq ▸ pow_eq_one_of_mem_fixed_points Pin₁)))
end
theorem cauchy_theorem {p : nat} : prime p → p ∣ card A → ∃ g : A, order g = p :=
assume Pprime Pdvd,
obtain g Pne Pgpow, from generator_of_prime_of_dvd_order Pprime Pdvd,
have Porder : order g ∣ p, from order_dvd_of_pow_eq_one Pgpow,
or.elim (eq_one_or_eq_self_of_prime_of_dvd Pprime Porder)
(λ Pe, absurd (eq_one_of_order_eq_one Pe) Pne)
(λ Porderp, exists.intro g Porderp)
end rotl_peo
end cauchy
section sylow
open finset fintype
variables {G : Type} [ambientG : group G] [finG : fintype G] [deceqG : decidable_eq G]
include ambientG deceqG finG
theorem first_sylow_theorem {p : nat} (Pp : prime p) :
∀ n, p^n ∣ card G → ∃ (H : finset G) (finsubgH : is_finsubg H), card H = p^n
| 0 := assume Pdvd, exists.intro ('{1})
(exists.intro one_is_finsubg
(by rewrite [pow_zero]))
| (succ n) := assume Pdvd,
obtain H PfinsubgH PcardH, from first_sylow_theorem n (pow_dvd_of_pow_succ_dvd Pdvd),
have Ppsubg : psubg H p n, from and.intro Pp PcardH,
have Ppowsucc : p^(succ n) ∣ (card (lcoset_type univ H) * p^n),
by rewrite [-PcardH, -(lagrange_theorem' !subset_univ)]; exact Pdvd,
have Ppdvd : p ∣ card (lcoset_type (normalizer H) H), from
dvd_of_mod_eq_zero
(by rewrite [-(card_psubg_cosets_mod_eq Ppsubg), -dvd_iff_mod_eq_zero];
exact dvd_of_pow_succ_dvd_mul_pow (pos_of_prime Pp) Ppowsucc),
obtain J PJ, from cauchy_theorem Pp Ppdvd,
exists.intro (fin_coset_Union (cyc J))
(exists.intro _
(by rewrite [pow_succ, -PcardH, -PJ]; apply card_Union_lcosets))
end sylow
end group_theory
|
23ba6f4fc4f075451c1d7a436bd4f92d18877fce | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /tests/compiler/uint_fold.lean | e8326fc7bb9fbd62816bd831cc33b788a746d2d1 | [
"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 | 571 | lean | #lang lean4
@[noinline] def h (x : Nat) : UInt32 :=
UInt32.ofNat x
def f (x y : UInt32) : UInt32 :=
let a1 : UInt32 := 128 * 100 - 100;
let v : Nat := 10 + x.toNat;
let a2 : UInt32 := x + a1;
let a3 : UInt32 := 10;
y + a2 + h v + a3
partial def g (x : UInt32) (y : UInt32) : UInt32 :=
if x = 0 then y else g (x-1) (y+2)
def foo : UInt8 :=
let x : UInt8 := 100;
x + x + x
def main : IO UInt32 :=
IO.println (toString (f 10 20)) *>
IO.println (toString (f 0 0)) *>
IO.println (toString (g 3 5)) *>
IO.println (toString (g 0 6)) *>
IO.println (toString foo) *>
pure 0
|
2f311ff49a7d7b1ed2b1e67224179e02307e738a | f3849be5d845a1cb97680f0bbbe03b85518312f0 | /library/init/relator.lean | f9789536393267b87d98272154ea0d716dfb7b0a | [
"Apache-2.0"
] | permissive | bjoeris/lean | 0ed95125d762b17bfcb54dad1f9721f953f92eeb | 4e496b78d5e73545fa4f9a807155113d8e6b0561 | refs/heads/master | 1,611,251,218,281 | 1,495,337,658,000 | 1,495,337,658,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,143 | 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
Relator for functions, pairs, sums, and lists.
-/
prelude
import init.core init.data.basic
namespace relator
universe variables u₁ u₂ v₁ v₂
reserve infixr ` ⇒ `:40
/- TODO(johoelzl):
* should we introduce relators of datatypes as recursive function or as inductive
predicate? For now we stick to the recursor approach.
* relation lift for datatypes, Π, Σ, set, and subtype types
* proof composition and identity laws
* implement method to derive relators from datatype
-/
section
variables {α : Type u₁} {β : Type u₂} {γ : Type v₁} {δ : Type v₂}
variables (R : α → β → Prop) (S : γ → δ → Prop)
def lift_fun (f : α → γ) (g : β → δ) : Prop :=
∀{a b}, R a b → S (f a) (g b)
infixr ⇒ := lift_fun
end
section
variables {α : Type u₁} {β : inout Type u₂} (R : inout α → β → Prop)
@[class] def right_total := ∀b, ∃a, R a b
@[class] def left_total := ∀a, ∃b, R a b
@[class] def bi_total := left_total R ∧ right_total R
end
section
variables {α : Type u₁} {β : Type u₂} (R : α → β → Prop)
@[class] def left_unique := ∀{a b c}, R a b → R c b → a = c
@[class] def right_unique := ∀{a b c}, R a b → R a c → b = c
lemma rel_forall_of_total [t : bi_total R] : ((R ⇒ iff) ⇒ iff) (λp, ∀i, p i) (λq, ∀i, q i) :=
take p q Hrel,
⟨take H b, exists.elim (t.right b) (take a Rab, (Hrel Rab).mp (H _)),
take H a, exists.elim (t.left a) (take b Rab, (Hrel Rab).mpr (H _))⟩
lemma left_unique_of_rel_eq {eq' : β → β → Prop} (he : (R ⇒ (R ⇒ iff)) eq eq') : left_unique R
| a b c (ab : R a b) (cb : R c b) :=
have eq' b b,
from iff.mp (he ab ab) rfl,
iff.mpr (he ab cb) this
end
lemma rel_imp : (iff ⇒ (iff ⇒ iff)) implies implies :=
take p q h r s l, imp_congr h l
lemma rel_not : (iff ⇒ iff) not not :=
take p q h, not_congr h
instance bi_total_eq {α : Type u₁} : relator.bi_total (@eq α) :=
⟨take a, ⟨a, rfl⟩, take a, ⟨a, rfl⟩⟩
end relator
|
7f61f8d24cf2365a1e20e6c60695c86ed157146e | 3446e92e64a5de7ed1f2109cfb024f83cd904c34 | /src/game/world3/level4.lean | 187f857a9f4b0512e3959ccd6774ffb8e066c9b5 | [] | 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 | 1,608 | lean | import game.world3.level3 -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 4: `mul_add`
Currently our tools for multiplication include the
following:
* `mul_zero : ∀ m, m * 0 = 0`
* `zero_mul : ∀ m, 0 * m = m`
* `mul_succ : ∀ a b, a * succ b = a * b + b`
but for addition we have `add_comm` and `add_assoc`
and are in much better shape.
Where are we going? Well we want to prove `mul_comm`
and `mul_assoc`, i.e. that `a * b = b * a` and
`(a * b) * c = a * (b * c)`. But we *also* want to
establish the way multiplication interacts with addition,
i.e. we want to prove that we can "expand out the brackets"
and show `a * (b + c) = (a * b) + (a * c)`.
The technical term for this is "distributivity of multiplication over addition".
Note the name of this lemma -- "mul_add". And note the left
hand side -- `a * (b + c)`, a multiplication and an addition.
I think "mul_add" is much easier to remember than "distributivity".
-/
/- Lemma
Multiplication is distributive over addition.
In other words, for all natural numbers $a$, $b$ and $c$, we have
$$ a * (b + c) = a * b + a * c. $$
-/
lemma mul_add (t a b : mynat) : t * (a + b) = t * a + t * b :=
begin [less_leaky]
induction b with d hd,
{ rewrite [add_zero, mul_zero, add_zero],
},
{
rw add_succ,
-- or show a * succ (b + d) = _,
rw mul_succ,
-- or show a * (b + d) + _ = _,
rw hd,
rw mul_succ,
rw add_assoc, -- ;-)
refl,
}
end
def left_distrib := mul_add -- stupid field name, -- hide
-- I just don't instinctively know what left_distrib means -- hide
end mynat -- hide
|
914c1c6bc1957e71bcd3b466a5cae52c965ed464 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/mv_polynomial/monad.lean | ca12e69353d1509215204cbd9f3bcc2b93836f14 | [
"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,124 | lean | /-
Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import data.mv_polynomial.rename
import data.mv_polynomial.variables
/-!
# Monad operations on `mv_polynomial`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines two monadic operations on `mv_polynomial`. Given `p : mv_polynomial σ R`,
* `mv_polynomial.bind₁` and `mv_polynomial.join₁` operate on the variable type `σ`.
* `mv_polynomial.bind₂` and `mv_polynomial.join₂` operate on the coefficient type `R`.
- `mv_polynomial.bind₁ f φ` with `f : σ → mv_polynomial τ R` and `φ : mv_polynomial σ R`,
is the polynomial `φ(f 1, ..., f i, ...) : mv_polynomial τ R`.
- `mv_polynomial.join₁ φ` with `φ : mv_polynomial (mv_polynomial σ R) R` collapses `φ` to
a `mv_polynomial σ R`, by evaluating `φ` under the map `X f ↦ f` for `f : mv_polynomial σ R`.
In other words, if you have a polynomial `φ` in a set of variables indexed by a polynomial ring,
you evaluate the polynomial in these indexing polynomials.
- `mv_polynomial.bind₂ f φ` with `f : R →+* mv_polynomial σ S` and `φ : mv_polynomial σ R`
is the `mv_polynomial σ S` obtained from `φ` by mapping the coefficients of `φ` through `f`
and considering the resulting polynomial as polynomial expression in `mv_polynomial σ R`.
- `mv_polynomial.join₂ φ` with `φ : mv_polynomial σ (mv_polynomial σ R)` collapses `φ` to
a `mv_polynomial σ R`, by considering `φ` as polynomial expression in `mv_polynomial σ R`.
These operations themselves have algebraic structure: `mv_polynomial.bind₁`
and `mv_polynomial.join₁` are algebra homs and
`mv_polynomial.bind₂` and `mv_polynomial.join₂` are ring homs.
They interact in convenient ways with `mv_polynomial.rename`, `mv_polynomial.map`,
`mv_polynomial.vars`, and other polynomial operations.
Indeed, `mv_polynomial.rename` is the "map" operation for the (`bind₁`, `join₁`) pair,
whereas `mv_polynomial.map` is the "map" operation for the other pair.
## Implementation notes
We add an `is_lawful_monad` instance for the (`bind₁`, `join₁`) pair.
The second pair cannot be instantiated as a `monad`,
since it is not a monad in `Type` but in `CommRing` (or rather `CommSemiRing`).
-/
open_locale big_operators
noncomputable theory
namespace mv_polynomial
open finsupp
variables {σ : Type*} {τ : Type*}
variables {R S T : Type*} [comm_semiring R] [comm_semiring S] [comm_semiring T]
/--
`bind₁` is the "left hand side" bind operation on `mv_polynomial`, operating on the variable type.
Given a polynomial `p : mv_polynomial σ R` and a map `f : σ → mv_polynomial τ R` taking variables
in `p` to polynomials in the variable type `τ`, `bind₁ f p` replaces each variable in `p` with
its value under `f`, producing a new polynomial in `τ`. The coefficient type remains the same.
This operation is an algebra hom.
-/
def bind₁ (f : σ → mv_polynomial τ R) : mv_polynomial σ R →ₐ[R] mv_polynomial τ R :=
aeval f
/--
`bind₂` is the "right hand side" bind operation on `mv_polynomial`,
operating on the coefficient type.
Given a polynomial `p : mv_polynomial σ R` and
a map `f : R → mv_polynomial σ S` taking coefficients in `p` to polynomials over a new ring `S`,
`bind₂ f p` replaces each coefficient in `p` with its value under `f`,
producing a new polynomial over `S`.
The variable type remains the same. This operation is a ring hom.
-/
def bind₂ (f : R →+* mv_polynomial σ S) : mv_polynomial σ R →+* mv_polynomial σ S :=
eval₂_hom f X
/--
`join₁` is the monadic join operation corresponding to `mv_polynomial.bind₁`. Given a polynomial `p`
with coefficients in `R` whose variables are polynomials in `σ` with coefficients in `R`,
`join₁ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`.
This operation is an algebra hom.
-/
def join₁ : mv_polynomial (mv_polynomial σ R) R →ₐ[R] mv_polynomial σ R :=
aeval id
/--
`join₂` is the monadic join operation corresponding to `mv_polynomial.bind₂`. Given a polynomial `p`
with variables in `σ` whose coefficients are polynomials in `σ` with coefficients in `R`,
`join₂ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`.
This operation is a ring hom.
-/
def join₂ : mv_polynomial σ (mv_polynomial σ R) →+* mv_polynomial σ R :=
eval₂_hom (ring_hom.id _) X
@[simp] lemma aeval_eq_bind₁ (f : σ → mv_polynomial τ R) :
aeval f = bind₁ f := rfl
@[simp] lemma eval₂_hom_C_eq_bind₁ (f : σ → mv_polynomial τ R) :
eval₂_hom C f = bind₁ f := rfl
@[simp] lemma eval₂_hom_eq_bind₂ (f : R →+* mv_polynomial σ S) :
eval₂_hom f X = bind₂ f := rfl
section
variables (σ R)
@[simp] lemma aeval_id_eq_join₁ :
aeval id = @join₁ σ R _ := rfl
lemma eval₂_hom_C_id_eq_join₁ (φ : mv_polynomial (mv_polynomial σ R) R) :
eval₂_hom C id φ = join₁ φ := rfl
@[simp] lemma eval₂_hom_id_X_eq_join₂ :
eval₂_hom (ring_hom.id _) X = @join₂ σ R _ := rfl
end
-- In this file, we don't want to use these simp lemmas,
-- because we first need to show how these new definitions interact
-- and the proofs fall back on unfolding the definitions and call simp afterwards
local attribute [-simp] aeval_eq_bind₁ eval₂_hom_C_eq_bind₁ eval₂_hom_eq_bind₂
aeval_id_eq_join₁ eval₂_hom_id_X_eq_join₂
@[simp]
lemma bind₁_X_right (f : σ → mv_polynomial τ R) (i : σ) : bind₁ f (X i) = f i :=
aeval_X f i
@[simp]
lemma bind₂_X_right (f : R →+* mv_polynomial σ S) (i : σ) : bind₂ f (X i) = X i :=
eval₂_hom_X' f X i
@[simp]
lemma bind₁_X_left : bind₁ (X : σ → mv_polynomial σ R) = alg_hom.id R _ :=
by { ext1 i, simp }
variable (f : σ → mv_polynomial τ R)
@[simp]
lemma bind₁_C_right (f : σ → mv_polynomial τ R) (x) : bind₁ f (C x) = C x :=
by simp [bind₁, algebra_map_eq]
@[simp]
lemma bind₂_C_right (f : R →+* mv_polynomial σ S) (r : R) : bind₂ f (C r) = f r :=
eval₂_hom_C f X r
@[simp]
lemma bind₂_C_left : bind₂ (C : R →+* mv_polynomial σ R) = ring_hom.id _ :=
by { ext : 2; simp }
@[simp]
lemma bind₂_comp_C (f : R →+* mv_polynomial σ S) :
(bind₂ f).comp C = f :=
ring_hom.ext $ bind₂_C_right _
@[simp]
lemma join₂_map (f : R →+* mv_polynomial σ S) (φ : mv_polynomial σ R) :
join₂ (map f φ) = bind₂ f φ :=
by simp only [join₂, bind₂, eval₂_hom_map_hom, ring_hom.id_comp]
@[simp]
lemma join₂_comp_map (f : R →+* mv_polynomial σ S) :
join₂.comp (map f) = bind₂ f :=
ring_hom.ext $ join₂_map _
lemma aeval_id_rename (f : σ → mv_polynomial τ R) (p : mv_polynomial σ R) :
aeval id (rename f p) = aeval f p :=
by rw [aeval_rename, function.comp.left_id]
@[simp]
lemma join₁_rename (f : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) :
join₁ (rename f φ) = bind₁ f φ :=
aeval_id_rename _ _
@[simp]
lemma bind₁_id : bind₁ (@id (mv_polynomial σ R)) = join₁ := rfl
@[simp]
lemma bind₂_id : bind₂ (ring_hom.id (mv_polynomial σ R)) = join₂ := rfl
lemma bind₁_bind₁ {υ : Type*} (f : σ → mv_polynomial τ R) (g : τ → mv_polynomial υ R)
(φ : mv_polynomial σ R) :
(bind₁ g) (bind₁ f φ) = bind₁ (λ i, bind₁ g (f i)) φ :=
by simp [bind₁, ← comp_aeval]
lemma bind₁_comp_bind₁ {υ : Type*} (f : σ → mv_polynomial τ R) (g : τ → mv_polynomial υ R) :
(bind₁ g).comp (bind₁ f) = bind₁ (λ i, bind₁ g (f i)) :=
by { ext1, apply bind₁_bind₁ }
lemma bind₂_comp_bind₂ (f : R →+* mv_polynomial σ S) (g : S →+* mv_polynomial σ T) :
(bind₂ g).comp (bind₂ f) = bind₂ ((bind₂ g).comp f) :=
by { ext : 2; simp }
lemma bind₂_bind₂ (f : R →+* mv_polynomial σ S) (g : S →+* mv_polynomial σ T)
(φ : mv_polynomial σ R) :
(bind₂ g) (bind₂ f φ) = bind₂ ((bind₂ g).comp f) φ :=
ring_hom.congr_fun (bind₂_comp_bind₂ f g) φ
lemma rename_comp_bind₁ {υ : Type*} (f : σ → mv_polynomial τ R) (g : τ → υ) :
(rename g).comp (bind₁ f) = bind₁ (λ i, rename g $ f i) :=
by { ext1 i, simp }
lemma rename_bind₁ {υ : Type*} (f : σ → mv_polynomial τ R) (g : τ → υ) (φ : mv_polynomial σ R) :
rename g (bind₁ f φ) = bind₁ (λ i, rename g $ f i) φ :=
alg_hom.congr_fun (rename_comp_bind₁ f g) φ
lemma map_bind₂ (f : R →+* mv_polynomial σ S) (g : S →+* T) (φ : mv_polynomial σ R) :
map g (bind₂ f φ) = bind₂ ((map g).comp f) φ :=
begin
simp only [bind₂, eval₂_comp_right, coe_eval₂_hom, eval₂_map],
congr' 1 with : 1,
simp only [function.comp_app, map_X]
end
lemma bind₁_comp_rename {υ : Type*} (f : τ → mv_polynomial υ R) (g : σ → τ) :
(bind₁ f).comp (rename g) = bind₁ (f ∘ g) :=
by { ext1 i, simp }
lemma bind₁_rename {υ : Type*} (f : τ → mv_polynomial υ R) (g : σ → τ) (φ : mv_polynomial σ R) :
bind₁ f (rename g φ) = bind₁ (f ∘ g) φ :=
alg_hom.congr_fun (bind₁_comp_rename f g) φ
lemma bind₂_map (f : S →+* mv_polynomial σ T) (g : R →+* S) (φ : mv_polynomial σ R) :
bind₂ f (map g φ) = bind₂ (f.comp g) φ :=
by simp [bind₂]
@[simp]
lemma map_comp_C (f : R →+* S) : (map f).comp (C : R →+* mv_polynomial σ R) = C.comp f :=
by { ext1, apply map_C }
-- mixing the two monad structures
lemma hom_bind₁ (f : mv_polynomial τ R →+* S) (g : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) :
f (bind₁ g φ) = eval₂_hom (f.comp C) (λ i, f (g i)) φ :=
by rw [bind₁, map_aeval, algebra_map_eq]
lemma map_bind₁ (f : R →+* S) (g : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) :
map f (bind₁ g φ) = bind₁ (λ (i : σ), (map f) (g i)) (map f φ) :=
by { rw [hom_bind₁, map_comp_C, ← eval₂_hom_map_hom], refl }
@[simp]
lemma eval₂_hom_comp_C (f : R →+* S) (g : σ → S) :
(eval₂_hom f g).comp C = f :=
by { ext1 r, exact eval₂_C f g r }
lemma eval₂_hom_bind₁ (f : R →+* S) (g : τ → S) (h : σ → mv_polynomial τ R)
(φ : mv_polynomial σ R) :
eval₂_hom f g (bind₁ h φ) = eval₂_hom f (λ i, eval₂_hom f g (h i)) φ :=
by rw [hom_bind₁, eval₂_hom_comp_C]
lemma aeval_bind₁ [algebra R S] (f : τ → S) (g : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) :
aeval f (bind₁ g φ) = aeval (λ i, aeval f (g i)) φ :=
eval₂_hom_bind₁ _ _ _ _
lemma aeval_comp_bind₁ [algebra R S] (f : τ → S) (g : σ → mv_polynomial τ R) :
(aeval f).comp (bind₁ g) = aeval (λ i, aeval f (g i)) :=
by { ext1, apply aeval_bind₁ }
lemma eval₂_hom_comp_bind₂ (f : S →+* T) (g : σ → T) (h : R →+* mv_polynomial σ S) :
(eval₂_hom f g).comp (bind₂ h) = eval₂_hom ((eval₂_hom f g).comp h) g :=
by { ext : 2; simp }
lemma eval₂_hom_bind₂ (f : S →+* T) (g : σ → T) (h : R →+* mv_polynomial σ S)
(φ : mv_polynomial σ R) :
eval₂_hom f g (bind₂ h φ) = eval₂_hom ((eval₂_hom f g).comp h) g φ :=
ring_hom.congr_fun (eval₂_hom_comp_bind₂ f g h) φ
lemma aeval_bind₂ [algebra S T] (f : σ → T) (g : R →+* mv_polynomial σ S) (φ : mv_polynomial σ R) :
aeval f (bind₂ g φ) = eval₂_hom ((↑(aeval f : _ →ₐ[S] _) : _ →+* _).comp g) f φ :=
eval₂_hom_bind₂ _ _ _ _
lemma eval₂_hom_C_left (f : σ → mv_polynomial τ R) : eval₂_hom C f = bind₁ f := rfl
lemma bind₁_monomial (f : σ → mv_polynomial τ R) (d : σ →₀ ℕ) (r : R) :
bind₁ f (monomial d r) = C r * ∏ i in d.support, f i ^ d i :=
by simp only [monomial_eq, alg_hom.map_mul, bind₁_C_right, finsupp.prod,
alg_hom.map_prod, alg_hom.map_pow, bind₁_X_right]
lemma bind₂_monomial (f : R →+* mv_polynomial σ S) (d : σ →₀ ℕ) (r : R) :
bind₂ f (monomial d r) = f r * monomial d 1 :=
by simp only [monomial_eq, ring_hom.map_mul, bind₂_C_right, finsupp.prod,
ring_hom.map_prod, ring_hom.map_pow, bind₂_X_right, C_1, one_mul]
@[simp]
lemma bind₂_monomial_one (f : R →+* mv_polynomial σ S) (d : σ →₀ ℕ) :
bind₂ f (monomial d 1) = monomial d 1 :=
by rw [bind₂_monomial, f.map_one, one_mul]
section
lemma vars_bind₁ [decidable_eq τ] (f : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) :
(bind₁ f φ).vars ⊆ φ.vars.bUnion (λ i, (f i).vars) :=
begin
calc (bind₁ f φ).vars
= (φ.support.sum (λ (x : σ →₀ ℕ), (bind₁ f) (monomial x (coeff x φ)))).vars :
by { rw [← alg_hom.map_sum, ← φ.as_sum], }
... ≤ φ.support.bUnion (λ (i : σ →₀ ℕ), ((bind₁ f) (monomial i (coeff i φ))).vars) :
vars_sum_subset _ _
... = φ.support.bUnion (λ (d : σ →₀ ℕ), (C (coeff d φ) * ∏ i in d.support, f i ^ d i).vars) :
by simp only [bind₁_monomial]
... ≤ φ.support.bUnion (λ (d : σ →₀ ℕ), d.support.bUnion (λ i, (f i).vars)) : _ -- proof below
... ≤ φ.vars.bUnion (λ (i : σ), (f i).vars) : _, -- proof below
{ apply finset.bUnion_mono,
intros d hd,
calc (C (coeff d φ) * ∏ (i : σ) in d.support, f i ^ d i).vars
≤ (C (coeff d φ)).vars ∪ (∏ (i : σ) in d.support, f i ^ d i).vars : vars_mul _ _
... ≤ (∏ (i : σ) in d.support, f i ^ d i).vars :
by simp only [finset.empty_union, vars_C, finset.le_iff_subset, finset.subset.refl]
... ≤ d.support.bUnion (λ (i : σ), (f i ^ d i).vars) : vars_prod _
... ≤ d.support.bUnion (λ (i : σ), (f i).vars) : _,
apply finset.bUnion_mono,
intros i hi,
apply vars_pow, },
{ intro j,
simp_rw finset.mem_bUnion,
rintro ⟨d, hd, ⟨i, hi, hj⟩⟩,
exact ⟨i, (mem_vars _).mpr ⟨d, hd, hi⟩, hj⟩ }
end
end
lemma mem_vars_bind₁ (f : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) {j : τ}
(h : j ∈ (bind₁ f φ).vars) :
∃ (i : σ), i ∈ φ.vars ∧ j ∈ (f i).vars :=
by classical; simpa only [exists_prop, finset.mem_bUnion, mem_support_iff, ne.def]
using vars_bind₁ f φ h
instance monad : monad (λ σ, mv_polynomial σ R) :=
{ map := λ α β f p, rename f p,
pure := λ _, X,
bind := λ _ _ p f, bind₁ f p }
instance is_lawful_functor : is_lawful_functor (λ σ, mv_polynomial σ R) :=
{ id_map := by intros; simp [(<$>)],
comp_map := by intros; simp [(<$>)] }
instance is_lawful_monad : is_lawful_monad (λ σ, mv_polynomial σ R) :=
{ pure_bind := by intros; simp [pure, bind],
bind_assoc := by intros; simp [bind, ← bind₁_comp_bind₁] }
/-
Possible TODO for the future:
Enable the following definitions, and write a lot of supporting lemmas.
def bind (f : R →+* mv_polynomial τ S) (g : σ → mv_polynomial τ S) :
mv_polynomial σ R →+* mv_polynomial τ S :=
eval₂_hom f g
def join (f : R →+* S) : mv_polynomial (mv_polynomial σ R) S →ₐ[S] mv_polynomial σ S :=
aeval (map f)
def ajoin [algebra R S] : mv_polynomial (mv_polynomial σ R) S →ₐ[S] mv_polynomial σ S :=
join (algebra_map R S)
-/
end mv_polynomial
|
30756463fa0a7661804f7237c86bfc8c1161b2cf | f3ab5c6b849dd89e43f1fe3572fbed3fc1baaf0f | /lean/types.lean | 71eb98d320cf86d06f41274105cabf2f9868e32c | [
"Apache-2.0",
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | ekmett/coda | 69fa7ac66924ea2cee12f7005b192c22baf9e03e | 3309ea70c31b58a3915b0ecc9140985c3a1ac565 | refs/heads/master | 1,670,616,044,398 | 1,619,020,702,000 | 1,619,020,702,000 | 100,850,826 | 170 | 15 | NOASSERTION | 1,670,434,088,000 | 1,503,220,814,000 | Haskell | UTF-8 | Lean | false | false | 540 | lean | inductive ty : Type
| i : ty
| arr : ty -> ty -> ty
inductive ctx : Type
| n : ctx
| s : ctx -> ty -> ctx
notation Γ >> σ := ctx.s Γ σ
inductive var : ctx -> ty -> Type
| z : ∀ (Γ : ctx) (σ : ty), var (Γ >> σ) σ
| s : ∀ (Γ : ctx) (σ : ty), var Γ σ → var (Γ >> σ) σ
inductive tm : ctx -> ty -> Type
| vr : ∀ (Γ : ctx) (σ : ty), var Γ σ → tm Γ σ
| ap : ∀ (Γ : ctx) (σ τ : ty), tm Γ (ty.arr σ τ) -> tm Γ σ -> tm Γ τ
| lm : ∀ (Γ : ctx) (σ τ : ty), tm (Γ >> σ) τ -> tm Γ (ty.arr σ τ)
|
f73440f36ff888f99d5eb93c499180ef3babe6ba | 54d7e71c3616d331b2ec3845d31deb08f3ff1dea | /library/init/meta/simp_tactic.lean | 02f5fe101f1ac586db0815691711157557e96c53 | [
"Apache-2.0"
] | permissive | pachugupta/lean | 6f3305c4292288311cc4ab4550060b17d49ffb1d | 0d02136a09ac4cf27b5c88361750e38e1f485a1a | refs/heads/master | 1,611,110,653,606 | 1,493,130,117,000 | 1,493,167,649,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,327 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.tactic init.meta.attribute init.meta.constructor_tactic
import init.meta.relation_tactics init.meta.occurrences init.meta.quote
import init.data.option.instances
open tactic
meta constant simp_lemmas : Type
meta constant simp_lemmas.mk : simp_lemmas
meta constant simp_lemmas.join : simp_lemmas → simp_lemmas → simp_lemmas
meta constant simp_lemmas.erase : simp_lemmas → list name → simp_lemmas
meta constant simp_lemmas.mk_default_core : transparency → tactic simp_lemmas
meta constant simp_lemmas.add_core : transparency → simp_lemmas → expr → tactic simp_lemmas
meta constant simp_lemmas.add_simp_core : transparency → simp_lemmas → name → tactic simp_lemmas
meta constant simp_lemmas.add_congr_core : transparency → simp_lemmas → name → tactic simp_lemmas
meta def simp_lemmas.mk_default : tactic simp_lemmas :=
simp_lemmas.mk_default_core reducible
meta def simp_lemmas.add : simp_lemmas → expr → tactic simp_lemmas :=
simp_lemmas.add_core reducible
meta def simp_lemmas.add_simp : simp_lemmas → name → tactic simp_lemmas :=
simp_lemmas.add_simp_core reducible
meta def simp_lemmas.add_congr : simp_lemmas → name → tactic simp_lemmas :=
simp_lemmas.add_congr_core reducible
meta def simp_lemmas.append : simp_lemmas → list expr → tactic simp_lemmas
| sls [] := return sls
| sls (l::ls) := do
new_sls ← simp_lemmas.add sls l,
simp_lemmas.append new_sls ls
/- (simp_lemmas.rewrite_core m s prove R e) apply a simplification lemma from 's'
- 'prove' is used to discharge proof obligations.
- 'R' is the equivalence relation being used (e.g., 'eq', 'iff')
- 'e' is the expression to be "simplified"
Result (new_e, pr) is the new expression 'new_e' and a proof (pr : e R new_e) -/
meta constant simp_lemmas.rewrite_core : transparency → simp_lemmas → tactic unit → name → expr → tactic (expr × expr)
meta def simp_lemmas.rewrite : simp_lemmas → tactic unit → name → expr → tactic (expr × expr) :=
simp_lemmas.rewrite_core reducible
/- (simp_lemmas.drewrite s e) tries to rewrite 'e' using only refl lemmas in 's' -/
meta constant simp_lemmas.drewrite_core : transparency → simp_lemmas → expr → tactic expr
meta def simp_lemmas.drewrite : simp_lemmas → expr → tactic expr :=
simp_lemmas.drewrite_core reducible
/- (Definitional) Simplify the given expression using *only* reflexivity equality lemmas from the given set of lemmas.
The resulting expression is definitionally equal to the input. -/
meta constant simp_lemmas.dsimplify_core (max_steps : nat) (visit_instances : bool) : simp_lemmas → expr → tactic expr
meta constant is_valid_simp_lemma_cnst : transparency → name → tactic bool
meta constant is_valid_simp_lemma : transparency → expr → tactic bool
def default_max_steps := 10000000
meta def simp_lemmas.dsimplify : simp_lemmas → expr → tactic expr :=
simp_lemmas.dsimplify_core default_max_steps ff
meta constant simp_lemmas.pp : simp_lemmas → tactic format
namespace tactic
/- (get_eqn_lemmas_for deps d) returns the automatically generated equational lemmas for definition d.
If deps is tt, then lemmas for automatically generated auxiliary declarations used to define d are also included. -/
meta constant get_eqn_lemmas_for : bool → name → tactic (list name)
meta constant dsimplify_core
/- The user state type. -/
{α : Type}
/- Initial user data -/
(a : α)
(max_steps : nat)
/- If visit_instances = ff, then instance implicit arguments are not visited, but
tactic will canonize them. -/
(visit_instances : bool)
/- (pre a e) is invoked before visiting the children of subterm 'e',
if it succeeds the result (new_a, new_e, flag) where
- 'new_a' is the new value for the user data
- 'new_e' is a new expression that must be definitionally equal to 'e',
- 'flag' if tt 'new_e' children should be visited, and 'post' invoked. -/
(pre : α → expr → tactic (α × expr × bool))
/- (post a e) is invoked after visiting the children of subterm 'e',
The output is similar to (pre a e), but the 'flag' indicates whether
the new expression should be revisited or not. -/
(post : α → expr → tactic (α × expr × bool))
: expr → tactic (α × expr)
meta def dsimplify
(pre : expr → tactic (expr × bool))
(post : expr → tactic (expr × bool))
: expr → tactic expr :=
λ e, do (a, new_e) ← dsimplify_core () default_max_steps ff
(λ u e, do r ← pre e, return (u, r))
(λ u e, do r ← post e, return (u, r)) e,
return new_e
meta constant dunfold_expr_core : transparency → expr → tactic expr
meta def dunfold_expr : expr → tactic expr :=
dunfold_expr_core reducible
meta constant unfold_projection_core : transparency → expr → tactic expr
meta def unfold_projection : expr → tactic expr :=
unfold_projection_core reducible
meta def dunfold_occs_core (m : transparency) (max_steps : nat) (occs : occurrences) (cs : list name) (e : expr) : tactic expr :=
let unfold (c : nat) (e : expr) : tactic (nat × expr × bool) := do
guard (cs.any e.is_app_of),
new_e ← dunfold_expr_core m e,
if occs.contains c
then return (c+1, new_e, tt)
else return (c+1, e, tt)
in do (c, new_e) ← dsimplify_core 1 max_steps tt unfold (λ c e, failed) e,
return new_e
meta def dunfold_core (m : transparency) (max_steps : nat) (cs : list name) (e : expr) : tactic expr :=
let unfold (u : unit) (e : expr) : tactic (unit × expr × bool) := do
guard (cs.any e.is_app_of),
new_e ← dunfold_expr_core m e,
return (u, new_e, tt)
in do (c, new_e) ← dsimplify_core () max_steps tt (λ c e, failed) unfold e,
return new_e
meta def dunfold : list name → tactic unit :=
λ cs, target >>= dunfold_core reducible default_max_steps cs >>= change
meta def dunfold_occs_of (occs : list nat) (c : name) : tactic unit :=
target >>= dunfold_occs_core reducible default_max_steps (occurrences.pos occs) [c] >>= change
meta def dunfold_core_at (occs : occurrences) (cs : list name) (h : expr) : tactic unit :=
do num_reverted ← revert h,
(expr.pi n bi d b : expr) ← target,
new_d ← dunfold_occs_core reducible default_max_steps occs cs d,
change $ expr.pi n bi new_d b,
intron num_reverted
meta def dunfold_at (cs : list name) (h : expr) : tactic unit :=
do num_reverted ← revert h,
(expr.pi n bi d b : expr) ← target,
new_d ← dunfold_core reducible default_max_steps cs d,
change $ expr.pi n bi new_d b,
intron num_reverted
structure delta_config :=
(max_steps := default_max_steps)
(visit_instances := tt)
private meta def is_delta_target (e : expr) (cs : list name) : bool :=
cs.any (λ c,
if e.is_app_of c then tt /- Exact match -/
else let f := e.get_app_fn in
/- f is an auxiliary constant generated when compiling c -/
f.is_constant && f.const_name.is_internal && (f.const_name.get_prefix = c))
/- Delta reduce the given constant names -/
meta def delta_core (cfg : delta_config) (cs : list name) (e : expr) : tactic expr :=
let unfold (u : unit) (e : expr) : tactic (unit × expr × bool) := do
guard (is_delta_target e cs),
(expr.const f_name f_lvls) ← return e.get_app_fn,
env ← get_env,
decl ← env.get f_name,
new_f ← decl.instantiate_value_univ_params f_lvls,
new_e ← head_beta (expr.mk_app new_f e.get_app_args),
return (u, new_e, tt)
in do (c, new_e) ← dsimplify_core () cfg.max_steps cfg.visit_instances (λ c e, failed) unfold e,
return new_e
meta def delta (cs : list name) : tactic unit :=
target >>= delta_core {} cs >>= change
meta def delta_at (cs : list name) (h : expr) : tactic unit :=
do num_reverted ← revert h,
(expr.pi n bi d b : expr) ← target,
new_d ← delta_core {} cs d,
change $ expr.pi n bi new_d b,
intron num_reverted
structure simp_config :=
(max_steps : nat := default_max_steps)
(contextual : bool := ff)
(lift_eq : bool := tt)
(canonize_instances : bool := tt)
(canonize_proofs : bool := ff)
(use_axioms : bool := tt)
(zeta : bool := tt)
(beta : bool := tt)
(eta : bool := tt)
(proj : bool := tt) -- reduce projections
meta constant simplify_core
(c : simp_config)
(s : simp_lemmas)
(r : name) :
expr → tactic (expr × expr)
meta constant ext_simplify_core
/- The user state type. -/
{α : Type}
/- Initial user data -/
(a : α)
(c : simp_config)
/- Congruence and simplification lemmas.
Remark: the simplification lemmas at not applied automatically like in the simplify_core tactic.
the caller must use them at pre/post. -/
(s : simp_lemmas)
/- Tactic for dischaging hypothesis in conditional rewriting rules.
The argument 'α' is the current user state. -/
(prove : α → tactic α)
/- (pre a S r s p e) is invoked before visiting the children of subterm 'e',
'r' is the simplification relation being used, 's' is the updated set of lemmas if 'contextual' is tt,
'p' is the "parent" expression (if there is one).
if it succeeds the result is (new_a, new_e, new_pr, flag) where
- 'new_a' is the new value for the user data
- 'new_e' is a new expression s.t. 'e r new_e'
- 'new_pr' is a proof for 'e r new_e', If it is none, the proof is assumed to be by reflexivity
- 'flag' if tt 'new_e' children should be visited, and 'post' invoked. -/
(pre : α → simp_lemmas → name → option expr → expr → tactic (α × expr × option expr × bool))
/- (post a r s p e) is invoked after visiting the children of subterm 'e',
The output is similar to (pre a r s p e), but the 'flag' indicates whether
the new expression should be revisited or not. -/
(post : α → simp_lemmas → name → option expr → expr → tactic (α × expr × option expr × bool))
/- simplification relation -/
(r : name) :
expr → tactic (α × expr × expr)
meta def simplify (S : simp_lemmas) (e : expr) (cfg : simp_config := {}) : tactic (expr × expr) :=
do e_type ← infer_type e >>= whnf,
simplify_core cfg S `eq e
meta def replace_target (new_target : expr) (pr : expr) : tactic unit :=
do assert `htarget new_target, swap,
ht ← get_local `htarget,
mk_eq_mpr pr ht >>= exact
meta def simplify_goal (S : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
do t ← target,
(new_t, pr) ← simplify S t cfg,
replace_target new_t pr
meta def simp (cfg : simp_config := {}) : tactic unit :=
do S ← simp_lemmas.mk_default,
simplify_goal S cfg >> try triv >> try (reflexivity reducible)
meta def simp_using (hs : list expr) (cfg : simp_config := {}) : tactic unit :=
do S ← simp_lemmas.mk_default,
S ← S.append hs,
simplify_goal S cfg >> try triv
meta def dsimp_core (s : simp_lemmas) : tactic unit :=
target >>= s.dsimplify >>= change
meta def dsimp : tactic unit :=
simp_lemmas.mk_default >>= dsimp_core
meta def dsimp_at_core (s : simp_lemmas) (h : expr) : tactic unit :=
do num_reverted : ℕ ← revert h,
expr.pi n bi d b ← target,
h_simp ← s.dsimplify d,
change $ expr.pi n bi h_simp b,
intron num_reverted
meta def dsimp_at (h : expr) : tactic unit :=
do s ← simp_lemmas.mk_default, dsimp_at_core s h
private meta def is_equation : expr → bool
| (expr.pi n bi d b) := is_equation b
| e := match (expr.is_eq e) with (some a) := tt | none := ff end
private meta def collect_simps : list expr → tactic (list expr)
| [] := return []
| (h :: hs) := do
result ← collect_simps hs,
htype ← infer_type h >>= whnf,
if is_equation htype
then return (h :: result)
else do
pr ← is_prop htype,
return $ if pr then (h :: result) else result
meta def collect_ctx_simps : tactic (list expr) :=
local_context >>= collect_simps
/-- Simplify target using all hypotheses in the local context. -/
meta def simp_using_hs (cfg : simp_config := {}) : tactic unit :=
do es ← collect_ctx_simps, simp_using es cfg
meta def simph (cfg : simp_config := {}) :=
simp_using_hs cfg
meta def intro1_aux : bool → list name → tactic expr
| ff _ := intro1
| tt (n::ns) := intro n
| _ _ := failed
meta def simp_intro_aux (cfg : simp_config) (updt : bool) : simp_lemmas → bool → list name → tactic simp_lemmas
| S tt [] := try (simplify_goal S cfg) >> return S
| S use_ns ns := do
t ← target,
if t.is_napp_of `not 1 then
intro1_aux use_ns ns >> simp_intro_aux S use_ns ns.tail
else if t.is_arrow then
do {
d ← return t.binding_domain,
(new_d, h_d_eq_new_d) ← simplify S d cfg,
h_d ← intro1_aux use_ns ns,
h_new_d ← mk_eq_mp h_d_eq_new_d h_d,
assertv_core h_d.local_pp_name new_d h_new_d,
h_new ← intro1,
new_S ← if updt && is_equation new_d then S.add h_new else return S,
clear h_d,
simp_intro_aux new_S use_ns ns
}
<|>
-- failed to simplify... we just introduce and continue
(intro1_aux use_ns ns >> simp_intro_aux S use_ns ns.tail)
else if t.is_pi || t.is_let then
intro1_aux use_ns ns >> simp_intro_aux S use_ns ns.tail
else do
new_t ← whnf t reducible,
if new_t.is_pi then change new_t >> simp_intro_aux S use_ns ns
else
try (simplify_goal S cfg) >>
mcond (expr.is_pi <$> target)
(simp_intro_aux S use_ns ns)
(if use_ns ∧ ¬ns.empty then failed else return S)
meta def simp_intros_using (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
step $ simp_intro_aux cfg ff s ff []
meta def simph_intros_using (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
step $
do s ← collect_ctx_simps >>= s.append,
simp_intro_aux cfg tt s ff []
meta def simp_intro_lst_using (ns : list name) (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
step $ simp_intro_aux cfg ff s tt ns
meta def simph_intro_lst_using (ns : list name) (s : simp_lemmas) (cfg : simp_config := {}) : tactic unit :=
step $
do s ← collect_ctx_simps >>= s.append,
simp_intro_aux cfg tt s tt ns
meta def simp_at (h : expr) (extra_lemmas : list expr := []) (cfg : simp_config := {}) : tactic unit :=
do when (expr.is_local_constant h = ff) (fail "tactic simp_at failed, the given expression is not a hypothesis"),
htype ← infer_type h,
S ← simp_lemmas.mk_default,
S ← S.append extra_lemmas,
(new_htype, heq) ← simplify S htype cfg,
assert (expr.local_pp_name h) new_htype,
mk_eq_mp heq h >>= exact,
try $ clear h
meta def simp_at_using_hs (h : expr) (extra_lemmas : list expr := []) (cfg : simp_config := {}) : tactic unit :=
do hs ← collect_ctx_simps,
simp_at h (list.filter (≠ h) hs ++ extra_lemmas) cfg
meta def simph_at (h : expr) (extra_lemmas : list expr := []) (cfg : simp_config := {}) : tactic unit :=
simp_at_using_hs h extra_lemmas cfg
meta def mk_eq_simp_ext (simp_ext : expr → tactic (expr × expr)) : tactic unit :=
do (lhs, rhs) ← target >>= match_eq,
(new_rhs, heq) ← simp_ext lhs,
unify rhs new_rhs,
exact heq
/- Simp attribute support -/
meta def to_simp_lemmas : simp_lemmas → list name → tactic simp_lemmas
| S [] := return S
| S (n::ns) := do S' ← S.add_simp n, to_simp_lemmas S' ns
meta def mk_simp_attr (attr_name : name) : command :=
do let t := ```(caching_user_attribute simp_lemmas),
v ← to_expr ``({name := %%(quote attr_name),
descr := "simplifier attribute",
mk_cache := λ ns, do {tactic.to_simp_lemmas simp_lemmas.mk ns},
dependencies := [`reducibility] } : caching_user_attribute simp_lemmas),
add_decl (declaration.defn attr_name [] t v reducibility_hints.abbrev ff),
attribute.register attr_name
meta def get_user_simp_lemmas (attr_name : name) : tactic simp_lemmas :=
if attr_name = `default then simp_lemmas.mk_default
else do
cnst ← return (expr.const attr_name []),
attr ← eval_expr (caching_user_attribute simp_lemmas) cnst,
caching_user_attribute.get_cache attr
meta def join_user_simp_lemmas_core : simp_lemmas → list name → tactic simp_lemmas
| S [] := return S
| S (attr_name::R) := do S' ← get_user_simp_lemmas attr_name, join_user_simp_lemmas_core (S.join S') R
meta def join_user_simp_lemmas : list name → tactic simp_lemmas
| [] := simp_lemmas.mk_default
| attr_names := join_user_simp_lemmas_core simp_lemmas.mk attr_names
/- Normalize numerical expression, returns a pair (n, pr) where n is the resultant numeral,
and pr is a proof that the input argument is equal to n. -/
meta constant norm_num : expr → tactic (expr × expr)
meta def simplify_top_down {α} (a : α) (pre : α → expr → tactic (α × expr × expr)) (e : expr) (cfg : simp_config := {}) : tactic (α × expr × expr) :=
ext_simplify_core a cfg simp_lemmas.mk (λ _, failed)
(λ a _ _ _ e, do (new_a, new_e, pr) ← pre a e, guard (¬ new_e =ₐ e), return (new_a, new_e, some pr, tt))
(λ _ _ _ _ _, failed)
`eq e
meta def simp_top_down (pre : expr → tactic (expr × expr)) (cfg : simp_config := {}) : tactic unit :=
do t ← target,
(_, new_target, pr) ← simplify_top_down () (λ _ e, do (new_e, pr) ← pre e, return ((), new_e, pr)) t cfg,
replace_target new_target pr
meta def simplify_bottom_up {α} (a : α) (post : α → expr → tactic (α × expr × expr)) (e : expr) (cfg : simp_config := {}) : tactic (α × expr × expr) :=
ext_simplify_core a cfg simp_lemmas.mk (λ _, failed)
(λ _ _ _ _ _, failed)
(λ a _ _ _ e, do (new_a, new_e, pr) ← post a e, guard (¬ new_e =ₐ e), return (new_a, new_e, some pr, tt))
`eq e
meta def simp_bottom_up (post : expr → tactic (expr × expr)) (cfg : simp_config := {}) : tactic unit :=
do t ← target,
(_, new_target, pr) ← simplify_bottom_up () (λ _ e, do (new_e, pr) ← post e, return ((), new_e, pr)) t cfg,
replace_target new_target pr
end tactic
export tactic (mk_simp_attr)
|
1cf70f9bc7cbae9f5ab69ef37ba3c087543b798b | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/analysis/calculus/fderiv.lean | bbdc72e5b0a8c634778cfd02022d8737357454cf | [
"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 | 128,049 | lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import analysis.analytic.basic
import analysis.asymptotics.asymptotic_equivalent
import analysis.calculus.tangent_cone
import analysis.normed_space.bounded_linear_maps
import analysis.normed_space.units
/-!
# The Fréchet derivative
Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a
continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then
`has_fderiv_within_at f f' s x`
says that `f` has derivative `f'` at `x`, where the domain of interest
is restricted to `s`. We also have
`has_fderiv_at f f' x := has_fderiv_within_at f f' x univ`
Finally,
`has_strict_fderiv_at f f' x`
means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability,
i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse
function theorem, and is defined here only to avoid proving theorems like
`is_bounded_bilinear_map.has_fderiv_at` twice: first for `has_fderiv_at`, then for
`has_strict_fderiv_at`.
## Main results
In addition to the definition and basic properties of the derivative, this file contains the
usual formulas (and existence assertions) for the derivative of
* constants
* the identity
* bounded linear maps
* bounded bilinear maps
* sum of two functions
* sum of finitely many functions
* multiplication of a function by a scalar constant
* negative of a function
* subtraction of two functions
* multiplication of a function by a scalar function
* multiplication of two scalar functions
* composition of functions (the chain rule)
* inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,
and they more frequently lead to the desired result.
One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying
a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are
translated to this more elementary point of view on the derivative in the file `deriv.lean`. The
derivative of polynomials is handled there, as it is naturally one-dimensional.
The simplifier is set up to prove automatically that some functions are differentiable, or
differentiable at a point (but not differentiable on a set or within a set at a point, as checking
automatically that the good domains are mapped one to the other when using composition is not
something the simplifier can easily do). This means that one can write
`example (x : ℝ) : differentiable ℝ (λ x, sin (exp (3 + x^2)) - 5 * cos x) := by simp`.
If there are divisions, one needs to supply to the simplifier proofs that the denominators do
not vanish, as in
```lean
example (x : ℝ) (h : 1 + sin x ≠ 0) : differentiable_at ℝ (λ x, exp x / (1 + sin x)) x :=
by simp [h]
```
Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be
differentiable, in `analysis.special_functions.trigonometric`.
The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general
complicated multidimensional linear maps), but it will compute one-dimensional derivatives,
see `deriv.lean`.
## Implementation details
The derivative is defined in terms of the `is_o` relation, but also
characterized in terms of the `tendsto` relation.
We also introduce predicates `differentiable_within_at 𝕜 f s x` (where `𝕜` is the base field,
`f` the function to be differentiated, `x` the point at which the derivative is asserted to exist,
and `s` the set along which the derivative is defined), as well as `differentiable_at 𝕜 f x`,
`differentiable_on 𝕜 f s` and `differentiable 𝕜 f` to express the existence of a derivative.
To be able to compute with derivatives, we write `fderiv_within 𝕜 f s x` and `fderiv 𝕜 f x`
for some choice of a derivative if it exists, and the zero function otherwise. This choice only
behaves well along sets for which the derivative is unique, i.e., those for which the tangent
directions span a dense subset of the whole space. The predicates `unique_diff_within_at s x` and
`unique_diff_on s`, defined in `tangent_cone.lean` express this property. We prove that indeed
they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular
for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very
beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever.
To make sure that the simplifier can prove automatically that functions are differentiable, we tag
many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable
functions is differentiable, as well as their product, their cartesian product, and so on. A notable
exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are
differentiable, then their composition also is: `simp` would always be able to match this lemma,
by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`),
we add a lemma that if `f` is differentiable then so is `(λ x, exp (f x))`. This means adding
some boilerplate lemmas, but these can also be useful in their own right.
Tests for this ability of the simplifier (with more examples) are provided in
`tests/differentiable.lean`.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open filter asymptotics continuous_linear_map set metric
open_locale topological_space classical nnreal asymptotics filter ennreal
noncomputable theory
section
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
variables {E : Type*} [normed_group E] [normed_space 𝕜 E]
variables {F : Type*} [normed_group F] [normed_space 𝕜 F]
variables {G : Type*} [normed_group G] [normed_space 𝕜 G]
variables {G' : Type*} [normed_group G'] [normed_space 𝕜 G']
/-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition
is designed to be specialized for `L = 𝓝 x` (in `has_fderiv_at`), giving rise to the usual notion
of Fréchet derivative, and for `L = 𝓝[s] x` (in `has_fderiv_within_at`), giving rise to
the notion of Fréchet derivative along the set `s`. -/
def has_fderiv_at_filter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : filter E) :=
is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L
/-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/
def has_fderiv_within_at (f : E → F) (f' : E →L[𝕜] F) (s : set E) (x : E) :=
has_fderiv_at_filter f f' x (𝓝[s] x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/
def has_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
has_fderiv_at_filter f f' x (𝓝 x)
/-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability*
if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required,
e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly
differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/
def has_strict_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
is_o (λ p : E × E, f p.1 - f p.2 - f' (p.1 - p.2)) (λ p : E × E, p.1 - p.2) (𝓝 (x, x))
variables (𝕜)
/-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative
there (possibly non-unique). -/
def differentiable_within_at (f : E → F) (s : set E) (x : E) :=
∃f' : E →L[𝕜] F, has_fderiv_within_at f f' s x
/-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly
non-unique). -/
def differentiable_at (f : E → F) (x : E) :=
∃f' : E →L[𝕜] F, has_fderiv_at f f' x
/-- If `f` has a derivative at `x` within `s`, then `fderiv_within 𝕜 f s x` is such a derivative.
Otherwise, it is set to `0`. -/
def fderiv_within (f : E → F) (s : set E) (x : E) : E →L[𝕜] F :=
if h : ∃f', has_fderiv_within_at f f' s x then classical.some h else 0
/-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is
set to `0`. -/
def fderiv (f : E → F) (x : E) : E →L[𝕜] F :=
if h : ∃f', has_fderiv_at f f' x then classical.some h else 0
/-- `differentiable_on 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/
def differentiable_on (f : E → F) (s : set E) :=
∀x ∈ s, differentiable_within_at 𝕜 f s x
/-- `differentiable 𝕜 f` means that `f` is differentiable at any point. -/
def differentiable (f : E → F) :=
∀x, differentiable_at 𝕜 f x
variables {𝕜}
variables {f f₀ f₁ g : E → F}
variables {f' f₀' f₁' g' : E →L[𝕜] F}
variables (e : E →L[𝕜] F)
variables {x : E}
variables {s t : set E}
variables {L L₁ L₂ : filter E}
lemma fderiv_within_zero_of_not_differentiable_within_at
(h : ¬ differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 f s x = 0 :=
have ¬ ∃ f', has_fderiv_within_at f f' s x, from h,
by simp [fderiv_within, this]
lemma fderiv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : fderiv 𝕜 f x = 0 :=
have ¬ ∃ f', has_fderiv_at f f' x, from h,
by simp [fderiv, this]
section derivative_uniqueness
/- In this section, we discuss the uniqueness of the derivative.
We prove that the definitions `unique_diff_within_at` and `unique_diff_on` indeed imply the
uniqueness of the derivative. -/
/-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f',
i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity
and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses
this fact, for functions having a derivative within a set. Its specific formulation is useful for
tangent cone related discussions. -/
theorem has_fderiv_within_at.lim (h : has_fderiv_within_at f f' s x) {α : Type*} (l : filter α)
{c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s)
(clim : tendsto (λ n, ∥c n∥) l at_top)
(cdlim : tendsto (λ n, c n • d n) l (𝓝 v)) :
tendsto (λn, c n • (f (x + d n) - f x)) l (𝓝 (f' v)) :=
begin
have tendsto_arg : tendsto (λ n, x + d n) l (𝓝[s] x),
{ conv in (𝓝[s] x) { rw ← add_zero x },
rw [nhds_within, tendsto_inf],
split,
{ apply tendsto_const_nhds.add (tangent_cone_at.lim_zero l clim cdlim) },
{ rwa tendsto_principal } },
have : is_o (λ y, f y - f x - f' (y - x)) (λ y, y - x) (𝓝[s] x) := h,
have : is_o (λ n, f (x + d n) - f x - f' ((x + d n) - x)) (λ n, (x + d n) - x) l :=
this.comp_tendsto tendsto_arg,
have : is_o (λ n, f (x + d n) - f x - f' (d n)) d l := by simpa only [add_sub_cancel'],
have : is_o (λn, c n • (f (x + d n) - f x - f' (d n))) (λn, c n • d n) l :=
(is_O_refl c l).smul_is_o this,
have : is_o (λn, c n • (f (x + d n) - f x - f' (d n))) (λn, (1:ℝ)) l :=
this.trans_is_O (is_O_one_of_tendsto ℝ cdlim),
have L1 : tendsto (λn, c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) :=
(is_o_one_iff ℝ).1 this,
have L2 : tendsto (λn, f' (c n • d n)) l (𝓝 (f' v)) :=
tendsto.comp f'.cont.continuous_at cdlim,
have L3 : tendsto (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)))
l (𝓝 (0 + f' v)) :=
L1.add L2,
have : (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)))
= (λn, c n • (f (x + d n) - f x)),
by { ext n, simp [smul_add, smul_sub] },
rwa [this, zero_add] at L3
end
/-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the
tangent cone to `s` at `x` -/
theorem has_fderiv_within_at.unique_on (hf : has_fderiv_within_at f f' s x)
(hg : has_fderiv_within_at f f₁' s x) :
eq_on f' f₁' (tangent_cone_at 𝕜 s x) :=
λ y ⟨c, d, dtop, clim, cdlim⟩,
tendsto_nhds_unique (hf.lim at_top dtop clim cdlim) (hg.lim at_top dtop clim cdlim)
/-- `unique_diff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/
theorem unique_diff_within_at.eq (H : unique_diff_within_at 𝕜 s x)
(hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f₁' s x) : f' = f₁' :=
continuous_linear_map.ext_on H.1 (hf.unique_on hg)
theorem unique_diff_on.eq (H : unique_diff_on 𝕜 s) (hx : x ∈ s)
(h : has_fderiv_within_at f f' s x) (h₁ : has_fderiv_within_at f f₁' s x) : f' = f₁' :=
(H x hx).eq h h₁
end derivative_uniqueness
section fderiv_properties
/-! ### Basic properties of the derivative -/
theorem has_fderiv_at_filter_iff_tendsto :
has_fderiv_at_filter f f' x L ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) :=
have h : ∀ x', ∥x' - x∥ = 0 → ∥f x' - f x - f' (x' - x)∥ = 0, from λ x' hx',
by { rw [sub_eq_zero.1 (norm_eq_zero.1 hx')], simp },
begin
unfold has_fderiv_at_filter,
rw [←is_o_norm_left, ←is_o_norm_right, is_o_iff_tendsto h],
exact tendsto_congr (λ _, div_eq_inv_mul),
end
theorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝[s] x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝 x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_fderiv_at_iff_is_o_nhds_zero : has_fderiv_at f f' x ↔
is_o (λh, f (x + h) - f x - f' h) (λh, h) (𝓝 0) :=
begin
rw [has_fderiv_at, has_fderiv_at_filter, ← map_add_left_nhds_zero x, is_o_map],
simp [(∘)]
end
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. -/
lemma has_fderiv_at.le_of_lip {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀)
{s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥f'∥ ≤ C :=
begin
refine le_of_forall_pos_le_add (λ ε ε0, op_norm_le_of_nhds_zero _ _),
exact add_nonneg C.coe_nonneg ε0.le,
have hs' := hs, rw [← map_add_left_nhds_zero x₀, mem_map] at hs',
filter_upwards [is_o_iff.1 (has_fderiv_at_iff_is_o_nhds_zero.1 hf) ε0, hs'], intros y hy hys,
have := hlip.norm_sub_le hys (mem_of_mem_nhds hs), rw add_sub_cancel' at this,
calc ∥f' y∥ ≤ ∥f (x₀ + y) - f x₀∥ + ∥f (x₀ + y) - f x₀ - f' y∥ : norm_le_insert _ _
... ≤ C * ∥y∥ + ε * ∥y∥ : add_le_add this hy
... = (C + ε) * ∥y∥ : (add_mul _ _ _).symm
end
theorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) :
has_fderiv_at_filter f f' x L₁ :=
h.mono hst
theorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s ⊆ t) :
has_fderiv_within_at f f' s x :=
h.mono (nhds_within_mono _ hst)
theorem has_fderiv_at.has_fderiv_at_filter (h : has_fderiv_at f f' x) (hL : L ≤ 𝓝 x) :
has_fderiv_at_filter f f' x L :=
h.mono hL
theorem has_fderiv_at.has_fderiv_within_at
(h : has_fderiv_at f f' x) : has_fderiv_within_at f f' s x :=
h.has_fderiv_at_filter inf_le_left
lemma has_fderiv_within_at.differentiable_within_at (h : has_fderiv_within_at f f' s x) :
differentiable_within_at 𝕜 f s x :=
⟨f', h⟩
lemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at 𝕜 f x :=
⟨f', h⟩
@[simp] lemma has_fderiv_within_at_univ :
has_fderiv_within_at f f' univ x ↔ has_fderiv_at f f' x :=
by { simp only [has_fderiv_within_at, nhds_within_univ], refl }
lemma has_strict_fderiv_at.is_O_sub (hf : has_strict_fderiv_at f f' x) :
is_O (λ p : E × E, f p.1 - f p.2) (λ p : E × E, p.1 - p.2) (𝓝 (x, x)) :=
hf.is_O.congr_of_sub.2 (f'.is_O_comp _ _)
lemma has_fderiv_at_filter.is_O_sub (h : has_fderiv_at_filter f f' x L) :
is_O (λ x', f x' - f x) (λ x', x' - x) L :=
h.is_O.congr_of_sub.2 (f'.is_O_sub _ _)
protected lemma has_strict_fderiv_at.has_fderiv_at (hf : has_strict_fderiv_at f f' x) :
has_fderiv_at f f' x :=
begin
rw [has_fderiv_at, has_fderiv_at_filter, is_o_iff],
exact (λ c hc, tendsto_id.prod_mk_nhds tendsto_const_nhds (is_o_iff.1 hf hc))
end
protected lemma has_strict_fderiv_at.differentiable_at (hf : has_strict_fderiv_at f f' x) :
differentiable_at 𝕜 f x :=
hf.has_fderiv_at.differentiable_at
/-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ∥f'∥₊`, then `f` is
`K`-Lipschitz in a neighborhood of `x`. -/
lemma has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt (hf : has_strict_fderiv_at f f' x)
(K : ℝ≥0) (hK : ∥f'∥₊ < K) : ∃ s ∈ 𝓝 x, lipschitz_on_with K f s :=
begin
have := hf.add_is_O_with (f'.is_O_with_comp _ _) hK,
simp only [sub_add_cancel, is_O_with] at this,
rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩,
exact ⟨U, Uo.mem_nhds xU, lipschitz_on_with_iff_norm_sub_le.2 $
λ x hx y hy, hU (mk_mem_prod hx hy)⟩
end
/-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a
neighborhood of `x`. See also `has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt` for a
more precise statement. -/
lemma has_strict_fderiv_at.exists_lipschitz_on_with (hf : has_strict_fderiv_at f f' x) :
∃ K (s ∈ 𝓝 x), lipschitz_on_with K f s :=
(no_top _).imp hf.exists_lipschitz_on_with_of_nnnorm_lt
/-- Directional derivative agrees with `has_fderiv`. -/
lemma has_fderiv_at.lim (hf : has_fderiv_at f f' x) (v : E) {α : Type*} {c : α → 𝕜}
{l : filter α} (hc : tendsto (λ n, ∥c n∥) l at_top) :
tendsto (λ n, (c n) • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) :=
begin
refine (has_fderiv_within_at_univ.2 hf).lim _ (univ_mem' (λ _, trivial)) hc _,
assume U hU,
refine (eventually_ne_of_tendsto_norm_at_top hc (0:𝕜)).mono (λ y hy, _),
convert mem_of_mem_nhds hU,
dsimp only,
rw [← mul_smul, mul_inv_cancel hy, one_smul]
end
theorem has_fderiv_at.unique
(h₀ : has_fderiv_at f f₀' x) (h₁ : has_fderiv_at f f₁' x) : f₀' = f₁' :=
begin
rw ← has_fderiv_within_at_univ at h₀ h₁,
exact unique_diff_within_at_univ.eq h₀ h₁
end
lemma has_fderiv_within_at_inter' (h : t ∈ 𝓝[s] x) :
has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x :=
by simp [has_fderiv_within_at, nhds_within_restrict'' s h]
lemma has_fderiv_within_at_inter (h : t ∈ 𝓝 x) :
has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x :=
by simp [has_fderiv_within_at, nhds_within_restrict' s h]
lemma has_fderiv_within_at.union (hs : has_fderiv_within_at f f' s x)
(ht : has_fderiv_within_at f f' t x) :
has_fderiv_within_at f f' (s ∪ t) x :=
begin
simp only [has_fderiv_within_at, nhds_within_union],
exact hs.join ht,
end
lemma has_fderiv_within_at.nhds_within (h : has_fderiv_within_at f f' s x)
(ht : s ∈ 𝓝[t] x) : has_fderiv_within_at f f' t x :=
(has_fderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
lemma has_fderiv_within_at.has_fderiv_at (h : has_fderiv_within_at f f' s x) (hs : s ∈ 𝓝 x) :
has_fderiv_at f f' x :=
by rwa [← univ_inter s, has_fderiv_within_at_inter hs, has_fderiv_within_at_univ] at h
lemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at 𝕜 f s x) :
has_fderiv_within_at f (fderiv_within 𝕜 f s x) s x :=
begin
dunfold fderiv_within,
dunfold differentiable_within_at at h,
rw dif_pos h,
exact classical.some_spec h
end
lemma differentiable_at.has_fderiv_at (h : differentiable_at 𝕜 f x) :
has_fderiv_at f (fderiv 𝕜 f x) x :=
begin
dunfold fderiv,
dunfold differentiable_at at h,
rw dif_pos h,
exact classical.some_spec h
end
lemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv 𝕜 f x = f' :=
by { ext, rw h.unique h.differentiable_at.has_fderiv_at }
/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz
on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`.
Version using `fderiv`. -/
lemma fderiv_at.le_of_lip {f : E → F} {x₀ : E} (hf : differentiable_at 𝕜 f x₀)
{s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥fderiv 𝕜 f x₀∥ ≤ C :=
hf.has_fderiv_at.le_of_lip hs hlip
lemma has_fderiv_within_at.fderiv_within
(h : has_fderiv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 f s x = f' :=
(hxs.eq h h.differentiable_within_at.has_fderiv_within_at).symm
/-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
lemma has_fderiv_within_at_of_not_mem_closure (h : x ∉ closure s) :
has_fderiv_within_at f f' s x :=
begin
simp only [mem_closure_iff_nhds_within_ne_bot, ne_bot_iff, ne.def, not_not] at h,
simp [has_fderiv_within_at, has_fderiv_at_filter, h, is_o, is_O_with],
end
lemma differentiable_within_at.mono (h : differentiable_within_at 𝕜 f t x) (st : s ⊆ t) :
differentiable_within_at 𝕜 f s x :=
begin
rcases h with ⟨f', hf'⟩,
exact ⟨f', hf'.mono st⟩
end
lemma differentiable_within_at_univ :
differentiable_within_at 𝕜 f univ x ↔ differentiable_at 𝕜 f x :=
by simp only [differentiable_within_at, has_fderiv_within_at_univ, differentiable_at]
lemma differentiable_within_at_inter (ht : t ∈ 𝓝 x) :
differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x :=
by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter,
nhds_within_restrict' s ht]
lemma differentiable_within_at_inter' (ht : t ∈ 𝓝[s] x) :
differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x :=
by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter,
nhds_within_restrict'' s ht]
lemma differentiable_at.differentiable_within_at
(h : differentiable_at 𝕜 f x) : differentiable_within_at 𝕜 f s x :=
(differentiable_within_at_univ.2 h).mono (subset_univ _)
lemma differentiable.differentiable_at (h : differentiable 𝕜 f) :
differentiable_at 𝕜 f x :=
h x
lemma differentiable_within_at.differentiable_at
(h : differentiable_within_at 𝕜 f s x) (hs : s ∈ 𝓝 x) : differentiable_at 𝕜 f x :=
h.imp (λ f' hf', hf'.has_fderiv_at hs)
lemma differentiable_at.fderiv_within
(h : differentiable_at 𝕜 f x) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
begin
apply has_fderiv_within_at.fderiv_within _ hxs,
exact h.has_fderiv_at.has_fderiv_within_at
end
lemma differentiable_on.mono (h : differentiable_on 𝕜 f t) (st : s ⊆ t) :
differentiable_on 𝕜 f s :=
λx hx, (h x (st hx)).mono st
lemma differentiable_on_univ :
differentiable_on 𝕜 f univ ↔ differentiable 𝕜 f :=
by { simp [differentiable_on, differentiable_within_at_univ], refl }
lemma differentiable.differentiable_on (h : differentiable 𝕜 f) : differentiable_on 𝕜 f s :=
(differentiable_on_univ.2 h).mono (subset_univ _)
lemma differentiable_on_of_locally_differentiable_on
(h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ differentiable_on 𝕜 f (s ∩ u)) : differentiable_on 𝕜 f s :=
begin
assume x xs,
rcases h x xs with ⟨t, t_open, xt, ht⟩,
exact (differentiable_within_at_inter (is_open.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩)
end
lemma fderiv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f t x) :
fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x :=
((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht
@[simp] lemma fderiv_within_univ : fderiv_within 𝕜 f univ = fderiv 𝕜 f :=
begin
ext x : 1,
by_cases h : differentiable_at 𝕜 f x,
{ apply has_fderiv_within_at.fderiv_within _ unique_diff_within_at_univ,
rw has_fderiv_within_at_univ,
apply h.has_fderiv_at },
{ have : ¬ differentiable_within_at 𝕜 f univ x,
by contrapose! h; rwa ← differentiable_within_at_univ,
rw [fderiv_zero_of_not_differentiable_at h,
fderiv_within_zero_of_not_differentiable_within_at this] }
end
lemma fderiv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 f (s ∩ t) x = fderiv_within 𝕜 f s x :=
begin
by_cases h : differentiable_within_at 𝕜 f (s ∩ t) x,
{ apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h),
apply hs.inter ht },
{ have : ¬ differentiable_within_at 𝕜 f s x,
by contrapose! h; rw differentiable_within_at_inter; assumption,
rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at this] }
end
lemma fderiv_within_of_mem_nhds (h : s ∈ 𝓝 x) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
begin
have : s = univ ∩ s, by simp only [univ_inter],
rw [this, ← fderiv_within_univ],
exact fderiv_within_inter h (unique_diff_on_univ _ (mem_univ _))
end
lemma fderiv_within_of_open (hs : is_open s) (hx : x ∈ s) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
fderiv_within_of_mem_nhds (is_open.mem_nhds hs hx)
lemma fderiv_within_eq_fderiv (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_at 𝕜 f x) :
fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=
begin
rw ← fderiv_within_univ,
exact fderiv_within_subset (subset_univ _) hs h.differentiable_within_at
end
lemma fderiv_mem_iff {f : E → F} {s : set (E →L[𝕜] F)} {x : E} :
fderiv 𝕜 f x ∈ s ↔ (differentiable_at 𝕜 f x ∧ fderiv 𝕜 f x ∈ s) ∨
(0 : E →L[𝕜] F) ∈ s ∧ ¬differentiable_at 𝕜 f x :=
begin
split,
{ intro hfx,
by_cases hx : differentiable_at 𝕜 f x,
{ exact or.inl ⟨hx, hfx⟩ },
{ rw [fderiv_zero_of_not_differentiable_at hx] at hfx,
exact or.inr ⟨hfx, hx⟩ } },
{ rintro (⟨hf, hf'⟩|⟨h₀, hx⟩),
{ exact hf' },
{ rwa [fderiv_zero_of_not_differentiable_at hx] } }
end
end fderiv_properties
section continuous
/-! ### Deducing continuity from differentiability -/
theorem has_fderiv_at_filter.tendsto_nhds
(hL : L ≤ 𝓝 x) (h : has_fderiv_at_filter f f' x L) :
tendsto f L (𝓝 (f x)) :=
begin
have : tendsto (λ x', f x' - f x) L (𝓝 0),
{ refine h.is_O_sub.trans_tendsto (tendsto.mono_left _ hL),
rw ← sub_self x, exact tendsto_id.sub tendsto_const_nhds },
have := tendsto.add this tendsto_const_nhds,
rw zero_add (f x) at this,
exact this.congr (by simp)
end
theorem has_fderiv_within_at.continuous_within_at
(h : has_fderiv_within_at f f' s x) : continuous_within_at f s x :=
has_fderiv_at_filter.tendsto_nhds inf_le_left h
theorem has_fderiv_at.continuous_at (h : has_fderiv_at f f' x) :
continuous_at f x :=
has_fderiv_at_filter.tendsto_nhds (le_refl _) h
lemma differentiable_within_at.continuous_within_at (h : differentiable_within_at 𝕜 f s x) :
continuous_within_at f s x :=
let ⟨f', hf'⟩ := h in hf'.continuous_within_at
lemma differentiable_at.continuous_at (h : differentiable_at 𝕜 f x) : continuous_at f x :=
let ⟨f', hf'⟩ := h in hf'.continuous_at
lemma differentiable_on.continuous_on (h : differentiable_on 𝕜 f s) : continuous_on f s :=
λx hx, (h x hx).continuous_within_at
lemma differentiable.continuous (h : differentiable 𝕜 f) : continuous f :=
continuous_iff_continuous_at.2 $ λx, (h x).continuous_at
protected lemma has_strict_fderiv_at.continuous_at (hf : has_strict_fderiv_at f f' x) :
continuous_at f x :=
hf.has_fderiv_at.continuous_at
lemma has_strict_fderiv_at.is_O_sub_rev {f' : E ≃L[𝕜] F}
(hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) x) :
is_O (λ p : E × E, p.1 - p.2) (λ p : E × E, f p.1 - f p.2) (𝓝 (x, x)) :=
((f'.is_O_comp_rev _ _).trans (hf.trans_is_O (f'.is_O_comp_rev _ _)).right_is_O_add).congr
(λ _, rfl) (λ _, sub_add_cancel _ _)
lemma has_fderiv_at_filter.is_O_sub_rev {f' : E ≃L[𝕜] F}
(hf : has_fderiv_at_filter f (f' : E →L[𝕜] F) x L) :
is_O (λ x', x' - x) (λ x', f x' - f x) L :=
((f'.is_O_sub_rev _ _).trans (hf.trans_is_O (f'.is_O_sub_rev _ _)).right_is_O_add).congr
(λ _, rfl) (λ _, sub_add_cancel _ _)
end continuous
section congr
/-! ### congr properties of the derivative -/
theorem filter.eventually_eq.has_strict_fderiv_at_iff
(h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) :
has_strict_fderiv_at f₀ f₀' x ↔ has_strict_fderiv_at f₁ f₁' x :=
begin
refine is_o_congr ((h.prod_mk_nhds h).mono _) (eventually_of_forall $ λ _, rfl),
rintros p ⟨hp₁, hp₂⟩,
simp only [*]
end
theorem has_strict_fderiv_at.congr_of_eventually_eq (h : has_strict_fderiv_at f f' x)
(h₁ : f =ᶠ[𝓝 x] f₁) : has_strict_fderiv_at f₁ f' x :=
(h₁.has_strict_fderiv_at_iff (λ _, rfl)).1 h
theorem filter.eventually_eq.has_fderiv_at_filter_iff
(h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at_filter f₀ f₀' x L ↔ has_fderiv_at_filter f₁ f₁' x L :=
is_o_congr (h₀.mono $ λ y hy, by simp only [hy, h₁, hx]) (eventually_of_forall $ λ _, rfl)
lemma has_fderiv_at_filter.congr_of_eventually_eq (h : has_fderiv_at_filter f f' x L)
(hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_fderiv_at_filter f₁ f' x L :=
(hL.has_fderiv_at_filter_iff hx $ λ _, rfl).2 h
lemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : has_fderiv_within_at f₁ f' t x :=
has_fderiv_at_filter.congr_of_eventually_eq (h.mono h₁) (filter.mem_inf_of_right ht) hx
lemma has_fderiv_within_at.congr (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x :=
h.congr_mono hs hx (subset.refl _)
lemma has_fderiv_within_at.congr' (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : x ∈ s) : has_fderiv_within_at f₁ f' s x :=
h.congr hs (hs x hx)
lemma has_fderiv_within_at.congr_of_eventually_eq (h : has_fderiv_within_at f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x :=
has_fderiv_at_filter.congr_of_eventually_eq h h₁ hx
lemma has_fderiv_at.congr_of_eventually_eq (h : has_fderiv_at f f' x)
(h₁ : f₁ =ᶠ[𝓝 x] f) : has_fderiv_at f₁ f' x :=
has_fderiv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _)
lemma differentiable_within_at.congr_mono (h : differentiable_within_at 𝕜 f s x)
(ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : differentiable_within_at 𝕜 f₁ t x :=
(has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx h₁).differentiable_within_at
lemma differentiable_within_at.congr (h : differentiable_within_at 𝕜 f s x)
(ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x :=
differentiable_within_at.congr_mono h ht hx (subset.refl _)
lemma differentiable_within_at.congr_of_eventually_eq
(h : differentiable_within_at 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f)
(hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x :=
(h.has_fderiv_within_at.congr_of_eventually_eq h₁ hx).differentiable_within_at
lemma differentiable_on.congr_mono (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ t, f₁ x = f x)
(h₁ : t ⊆ s) : differentiable_on 𝕜 f₁ t :=
λ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁
lemma differentiable_on.congr (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ s, f₁ x = f x) :
differentiable_on 𝕜 f₁ s :=
λ x hx, (h x hx).congr h' (h' x hx)
lemma differentiable_on_congr (h' : ∀x ∈ s, f₁ x = f x) :
differentiable_on 𝕜 f₁ s ↔ differentiable_on 𝕜 f s :=
⟨λ h, differentiable_on.congr h (λy hy, (h' y hy).symm),
λ h, differentiable_on.congr h h'⟩
lemma differentiable_at.congr_of_eventually_eq (h : differentiable_at 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) :
differentiable_at 𝕜 f₁ x :=
has_fderiv_at.differentiable_at
(has_fderiv_at_filter.congr_of_eventually_eq h.has_fderiv_at hL (mem_of_mem_nhds hL : _))
lemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at 𝕜 f s x)
(hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_diff_within_at 𝕜 t x) (h₁ : t ⊆ s) :
fderiv_within 𝕜 f₁ t x = fderiv_within 𝕜 f s x :=
(has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx h₁).fderiv_within hxt
lemma filter.eventually_eq.fderiv_within_eq (hs : unique_diff_within_at 𝕜 s x)
(hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=
if h : differentiable_within_at 𝕜 f s x
then has_fderiv_within_at.fderiv_within (h.has_fderiv_within_at.congr_of_eventually_eq hL hx) hs
else
have h' : ¬ differentiable_within_at 𝕜 f₁ s x,
from mt (λ h, h.congr_of_eventually_eq (hL.mono $ λ x, eq.symm) hx.symm) h,
by rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at h']
lemma fderiv_within_congr (hs : unique_diff_within_at 𝕜 s x)
(hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) :
fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=
begin
apply filter.eventually_eq.fderiv_within_eq hs _ hx,
apply mem_of_superset self_mem_nhds_within,
exact hL
end
lemma filter.eventually_eq.fderiv_eq (hL : f₁ =ᶠ[𝓝 x] f) :
fderiv 𝕜 f₁ x = fderiv 𝕜 f x :=
begin
have A : f₁ x = f x := hL.eq_of_nhds,
rw [← fderiv_within_univ, ← fderiv_within_univ],
rw ← nhds_within_univ at hL,
exact hL.fderiv_within_eq unique_diff_within_at_univ A
end
protected lemma filter.eventually_eq.fderiv (h : f₁ =ᶠ[𝓝 x] f) :
fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f :=
h.eventually_eq_nhds.mono $ λ x h, h.fderiv_eq
end congr
section id
/-! ### Derivative of the identity -/
theorem has_strict_fderiv_at_id (x : E) :
has_strict_fderiv_at id (id 𝕜 E) x :=
(is_o_zero _ _).congr_left $ by simp
theorem has_fderiv_at_filter_id (x : E) (L : filter E) :
has_fderiv_at_filter id (id 𝕜 E) x L :=
(is_o_zero _ _).congr_left $ by simp
theorem has_fderiv_within_at_id (x : E) (s : set E) :
has_fderiv_within_at id (id 𝕜 E) s x :=
has_fderiv_at_filter_id _ _
theorem has_fderiv_at_id (x : E) : has_fderiv_at id (id 𝕜 E) x :=
has_fderiv_at_filter_id _ _
@[simp] lemma differentiable_at_id : differentiable_at 𝕜 id x :=
(has_fderiv_at_id x).differentiable_at
@[simp] lemma differentiable_at_id' : differentiable_at 𝕜 (λ x, x) x :=
(has_fderiv_at_id x).differentiable_at
lemma differentiable_within_at_id : differentiable_within_at 𝕜 id s x :=
differentiable_at_id.differentiable_within_at
@[simp] lemma differentiable_id : differentiable 𝕜 (id : E → E) :=
λx, differentiable_at_id
@[simp] lemma differentiable_id' : differentiable 𝕜 (λ (x : E), x) :=
λx, differentiable_at_id
lemma differentiable_on_id : differentiable_on 𝕜 id s :=
differentiable_id.differentiable_on
lemma fderiv_id : fderiv 𝕜 id x = id 𝕜 E :=
has_fderiv_at.fderiv (has_fderiv_at_id x)
@[simp] lemma fderiv_id' : fderiv 𝕜 (λ (x : E), x) x = continuous_linear_map.id 𝕜 E :=
fderiv_id
lemma fderiv_within_id (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 id s x = id 𝕜 E :=
begin
rw differentiable_at.fderiv_within (differentiable_at_id) hxs,
exact fderiv_id
end
lemma fderiv_within_id' (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λ (x : E), x) s x = continuous_linear_map.id 𝕜 E :=
fderiv_within_id hxs
end id
section const
/-! ### derivative of a constant function -/
theorem has_strict_fderiv_at_const (c : F) (x : E) :
has_strict_fderiv_at (λ _, c) (0 : E →L[𝕜] F) x :=
(is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self]
theorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) :
has_fderiv_at_filter (λ x, c) (0 : E →L[𝕜] F) x L :=
(is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self]
theorem has_fderiv_within_at_const (c : F) (x : E) (s : set E) :
has_fderiv_within_at (λ x, c) (0 : E →L[𝕜] F) s x :=
has_fderiv_at_filter_const _ _ _
theorem has_fderiv_at_const (c : F) (x : E) :
has_fderiv_at (λ x, c) (0 : E →L[𝕜] F) x :=
has_fderiv_at_filter_const _ _ _
@[simp] lemma differentiable_at_const (c : F) : differentiable_at 𝕜 (λx, c) x :=
⟨0, has_fderiv_at_const c x⟩
lemma differentiable_within_at_const (c : F) : differentiable_within_at 𝕜 (λx, c) s x :=
differentiable_at.differentiable_within_at (differentiable_at_const _)
lemma fderiv_const_apply (c : F) : fderiv 𝕜 (λy, c) x = 0 :=
has_fderiv_at.fderiv (has_fderiv_at_const c x)
@[simp] lemma fderiv_const (c : F) : fderiv 𝕜 (λ (y : E), c) = 0 :=
by { ext m, rw fderiv_const_apply, refl }
lemma fderiv_within_const_apply (c : F) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λy, c) s x = 0 :=
begin
rw differentiable_at.fderiv_within (differentiable_at_const _) hxs,
exact fderiv_const_apply _
end
@[simp] lemma differentiable_const (c : F) : differentiable 𝕜 (λx : E, c) :=
λx, differentiable_at_const _
lemma differentiable_on_const (c : F) : differentiable_on 𝕜 (λx, c) s :=
(differentiable_const _).differentiable_on
lemma has_fderiv_at_of_subsingleton {R X Y : Type*} [nondiscrete_normed_field R]
[normed_group X] [normed_group Y] [normed_space R X] [normed_space R Y] [h : subsingleton X]
(f : X → Y) (x : X) :
has_fderiv_at f (0 : X →L[R] Y) x :=
begin
rw subsingleton_iff at h,
have key : function.const X (f 0) = f := by ext x'; rw h x' 0,
exact key ▸ (has_fderiv_at_const (f 0) _),
end
end const
section continuous_linear_map
/-!
### Continuous linear maps
There are currently two variants of these in mathlib, the bundled version
(named `continuous_linear_map`, and denoted `E →L[𝕜] F`), and the unbundled version (with a
predicate `is_bounded_linear_map`). We give statements for both versions. -/
protected theorem continuous_linear_map.has_strict_fderiv_at {x : E} :
has_strict_fderiv_at e e x :=
(is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self]
protected lemma continuous_linear_map.has_fderiv_at_filter :
has_fderiv_at_filter e e x L :=
(is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self]
protected lemma continuous_linear_map.has_fderiv_within_at : has_fderiv_within_at e e s x :=
e.has_fderiv_at_filter
protected lemma continuous_linear_map.has_fderiv_at : has_fderiv_at e e x :=
e.has_fderiv_at_filter
@[simp] protected lemma continuous_linear_map.differentiable_at : differentiable_at 𝕜 e x :=
e.has_fderiv_at.differentiable_at
protected lemma continuous_linear_map.differentiable_within_at : differentiable_within_at 𝕜 e s x :=
e.differentiable_at.differentiable_within_at
@[simp] protected lemma continuous_linear_map.fderiv : fderiv 𝕜 e x = e :=
e.has_fderiv_at.fderiv
protected lemma continuous_linear_map.fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 e s x = e :=
begin
rw differentiable_at.fderiv_within e.differentiable_at hxs,
exact e.fderiv
end
@[simp] protected lemma continuous_linear_map.differentiable : differentiable 𝕜 e :=
λx, e.differentiable_at
protected lemma continuous_linear_map.differentiable_on : differentiable_on 𝕜 e s :=
e.differentiable.differentiable_on
lemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map 𝕜 f) :
has_fderiv_at_filter f h.to_continuous_linear_map x L :=
h.to_continuous_linear_map.has_fderiv_at_filter
lemma is_bounded_linear_map.has_fderiv_within_at (h : is_bounded_linear_map 𝕜 f) :
has_fderiv_within_at f h.to_continuous_linear_map s x :=
h.has_fderiv_at_filter
lemma is_bounded_linear_map.has_fderiv_at (h : is_bounded_linear_map 𝕜 f) :
has_fderiv_at f h.to_continuous_linear_map x :=
h.has_fderiv_at_filter
lemma is_bounded_linear_map.differentiable_at (h : is_bounded_linear_map 𝕜 f) :
differentiable_at 𝕜 f x :=
h.has_fderiv_at.differentiable_at
lemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map 𝕜 f) :
differentiable_within_at 𝕜 f s x :=
h.differentiable_at.differentiable_within_at
lemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map 𝕜 f) :
fderiv 𝕜 f x = h.to_continuous_linear_map :=
has_fderiv_at.fderiv (h.has_fderiv_at)
lemma is_bounded_linear_map.fderiv_within (h : is_bounded_linear_map 𝕜 f)
(hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = h.to_continuous_linear_map :=
begin
rw differentiable_at.fderiv_within h.differentiable_at hxs,
exact h.fderiv
end
lemma is_bounded_linear_map.differentiable (h : is_bounded_linear_map 𝕜 f) :
differentiable 𝕜 f :=
λx, h.differentiable_at
lemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map 𝕜 f) :
differentiable_on 𝕜 f s :=
h.differentiable.differentiable_on
end continuous_linear_map
section analytic
variables {p : formal_multilinear_series 𝕜 E F} {r : ℝ≥0∞}
lemma has_fpower_series_at.has_strict_fderiv_at (h : has_fpower_series_at f p x) :
has_strict_fderiv_at f (continuous_multilinear_curry_fin1 𝕜 E F (p 1)) x :=
begin
refine h.is_O_image_sub_norm_mul_norm_sub.trans_is_o (is_o.of_norm_right _),
refine is_o_iff_exists_eq_mul.2 ⟨λ y, ∥y - (x, x)∥, _, eventually_eq.rfl⟩,
refine (continuous_id.sub continuous_const).norm.tendsto' _ _ _,
rw [_root_.id, sub_self, norm_zero]
end
lemma has_fpower_series_at.has_fderiv_at (h : has_fpower_series_at f p x) :
has_fderiv_at f (continuous_multilinear_curry_fin1 𝕜 E F (p 1)) x :=
h.has_strict_fderiv_at.has_fderiv_at
lemma has_fpower_series_at.differentiable_at (h : has_fpower_series_at f p x) :
differentiable_at 𝕜 f x :=
h.has_fderiv_at.differentiable_at
lemma analytic_at.differentiable_at : analytic_at 𝕜 f x → differentiable_at 𝕜 f x
| ⟨p, hp⟩ := hp.differentiable_at
lemma analytic_at.differentiable_within_at (h : analytic_at 𝕜 f x) :
differentiable_within_at 𝕜 f s x :=
h.differentiable_at.differentiable_within_at
lemma has_fpower_series_at.fderiv (h : has_fpower_series_at f p x) :
fderiv 𝕜 f x = continuous_multilinear_curry_fin1 𝕜 E F (p 1) :=
h.has_fderiv_at.fderiv
lemma has_fpower_series_on_ball.differentiable_on [complete_space F]
(h : has_fpower_series_on_ball f p x r) :
differentiable_on 𝕜 f (emetric.ball x r) :=
λ y hy, (h.analytic_at_of_mem hy).differentiable_within_at
end analytic
section composition
/-!
### Derivative of the composition of two functions
For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable (x)
theorem has_fderiv_at_filter.comp {g : F → G} {g' : F →L[𝕜] G}
(hg : has_fderiv_at_filter g g' (f x) (L.map f))
(hf : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (g ∘ f) (g'.comp f') x L :=
let eq₁ := (g'.is_O_comp _ _).trans_is_o hf in
let eq₂ := (hg.comp_tendsto tendsto_map).trans_is_O hf.is_O_sub in
by { refine eq₂.triangle (eq₁.congr_left (λ x', _)), simp }
/- A readable version of the previous theorem,
a general form of the chain rule. -/
example {g : F → G} {g' : F →L[𝕜] G}
(hg : has_fderiv_at_filter g g' (f x) (L.map f))
(hf : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (g ∘ f) (g'.comp f') x L :=
begin
unfold has_fderiv_at_filter at hg,
have : is_o (λ x', g (f x') - g (f x) - g' (f x' - f x)) (λ x', f x' - f x) L,
from hg.comp_tendsto (le_refl _),
have eq₁ : is_o (λ x', g (f x') - g (f x) - g' (f x' - f x)) (λ x', x' - x) L,
from this.trans_is_O hf.is_O_sub,
have eq₂ : is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L,
from hf,
have : is_O
(λ x', g' (f x' - f x - f' (x' - x))) (λ x', f x' - f x - f' (x' - x)) L,
from g'.is_O_comp _ _,
have : is_o (λ x', g' (f x' - f x - f' (x' - x))) (λ x', x' - x) L,
from this.trans_is_o eq₂,
have eq₃ : is_o (λ x', g' (f x' - f x) - (g' (f' (x' - x)))) (λ x', x' - x) L,
by { refine this.congr_left _, simp},
exact eq₁.triangle eq₃
end
theorem has_fderiv_within_at.comp {g : F → G} {g' : F →L[𝕜] G} {t : set F}
(hg : has_fderiv_within_at g g' t (f x)) (hf : has_fderiv_within_at f f' s x)
(hst : s ⊆ f ⁻¹' t) :
has_fderiv_within_at (g ∘ f) (g'.comp f') s x :=
begin
apply has_fderiv_at_filter.comp _ (has_fderiv_at_filter.mono hg _) hf,
calc map f (𝓝[s] x)
≤ 𝓝[f '' s] (f x) : hf.continuous_within_at.tendsto_nhds_within_image
... ≤ 𝓝[t] (f x) : nhds_within_mono _ (image_subset_iff.mpr hst)
end
/-- The chain rule. -/
theorem has_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G}
(hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) :
has_fderiv_at (g ∘ f) (g'.comp f') x :=
(hg.mono hf.continuous_at).comp x hf
theorem has_fderiv_at.comp_has_fderiv_within_at {g : F → G} {g' : F →L[𝕜] G}
(hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (g ∘ f) (g'.comp f') s x :=
begin
rw ← has_fderiv_within_at_univ at hg,
exact has_fderiv_within_at.comp x hg hf subset_preimage_univ
end
lemma differentiable_within_at.comp {g : F → G} {t : set F}
(hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(h : s ⊆ f ⁻¹' t) : differentiable_within_at 𝕜 (g ∘ f) s x :=
begin
rcases hf with ⟨f', hf'⟩,
rcases hg with ⟨g', hg'⟩,
exact ⟨continuous_linear_map.comp g' f', hg'.comp x hf' h⟩
end
lemma differentiable_within_at.comp' {g : F → G} {t : set F}
(hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (g ∘ f) (s ∩ f⁻¹' t) x :=
hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
lemma differentiable_at.comp {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) :
differentiable_at 𝕜 (g ∘ f) x :=
(hg.has_fderiv_at.comp x hf.has_fderiv_at).differentiable_at
lemma differentiable_at.comp_differentiable_within_at {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (g ∘ f) s x :=
(differentiable_within_at_univ.2 hg).comp x hf (by simp)
lemma fderiv_within.comp {g : F → G} {t : set F}
(hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(h : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (g ∘ f) s x = (fderiv_within 𝕜 g t (f x)).comp (fderiv_within 𝕜 f s x) :=
begin
apply has_fderiv_within_at.fderiv_within _ hxs,
exact has_fderiv_within_at.comp x (hg.has_fderiv_within_at) (hf.has_fderiv_within_at) h
end
lemma fderiv.comp {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) :
fderiv 𝕜 (g ∘ f) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) :=
begin
apply has_fderiv_at.fderiv,
exact has_fderiv_at.comp x hg.has_fderiv_at hf.has_fderiv_at
end
lemma fderiv.comp_fderiv_within {g : F → G}
(hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x)
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (g ∘ f) s x = (fderiv 𝕜 g (f x)).comp (fderiv_within 𝕜 f s x) :=
begin
apply has_fderiv_within_at.fderiv_within _ hxs,
exact has_fderiv_at.comp_has_fderiv_within_at x (hg.has_fderiv_at) (hf.has_fderiv_within_at)
end
lemma differentiable_on.comp {g : F → G} {t : set F}
(hg : differentiable_on 𝕜 g t) (hf : differentiable_on 𝕜 f s) (st : s ⊆ f ⁻¹' t) :
differentiable_on 𝕜 (g ∘ f) s :=
λx hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st
lemma differentiable.comp {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable 𝕜 f) :
differentiable 𝕜 (g ∘ f) :=
λx, differentiable_at.comp x (hg (f x)) (hf x)
lemma differentiable.comp_differentiable_on {g : F → G} (hg : differentiable 𝕜 g)
(hf : differentiable_on 𝕜 f s) :
differentiable_on 𝕜 (g ∘ f) s :=
(differentiable_on_univ.2 hg).comp hf (by simp)
/-- The chain rule for derivatives in the sense of strict differentiability. -/
protected lemma has_strict_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G}
(hg : has_strict_fderiv_at g g' (f x)) (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, g (f x)) (g'.comp f') x :=
((hg.comp_tendsto (hf.continuous_at.prod_map' hf.continuous_at)).trans_is_O hf.is_O_sub).triangle $
by simpa only [g'.map_sub, f'.coe_comp'] using (g'.is_O_comp _ _).trans_is_o hf
protected lemma differentiable.iterate {f : E → E} (hf : differentiable 𝕜 f) (n : ℕ) :
differentiable 𝕜 (f^[n]) :=
nat.rec_on n differentiable_id (λ n ihn, ihn.comp hf)
protected lemma differentiable_on.iterate {f : E → E} (hf : differentiable_on 𝕜 f s)
(hs : maps_to f s s) (n : ℕ) :
differentiable_on 𝕜 (f^[n]) s :=
nat.rec_on n differentiable_on_id (λ n ihn, ihn.comp hf hs)
variable {x}
protected lemma has_fderiv_at_filter.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) :
has_fderiv_at_filter (f^[n]) (f'^n) x L :=
begin
induction n with n ihn,
{ exact has_fderiv_at_filter_id x L },
{ change has_fderiv_at_filter (f^[n] ∘ f) (f'^(n+1)) x L,
rw [pow_succ'],
refine has_fderiv_at_filter.comp x _ hf,
rw hx,
exact ihn.mono hL }
end
protected lemma has_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_fderiv_at f f' x) (hx : f x = x) (n : ℕ) :
has_fderiv_at (f^[n]) (f'^n) x :=
begin
refine hf.iterate _ hx n,
convert hf.continuous_at,
exact hx.symm
end
protected lemma has_fderiv_within_at.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_fderiv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) :
has_fderiv_within_at (f^[n]) (f'^n) s x :=
begin
refine hf.iterate _ hx n,
convert tendsto_inf.2 ⟨hf.continuous_within_at, _⟩,
exacts [hx.symm, (tendsto_principal_principal.2 hs).mono_left inf_le_right]
end
protected lemma has_strict_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E}
(hf : has_strict_fderiv_at f f' x) (hx : f x = x) (n : ℕ) :
has_strict_fderiv_at (f^[n]) (f'^n) x :=
begin
induction n with n ihn,
{ exact has_strict_fderiv_at_id x },
{ change has_strict_fderiv_at (f^[n] ∘ f) (f'^(n+1)) x,
rw [pow_succ'],
refine has_strict_fderiv_at.comp x _ hf,
rwa hx }
end
protected lemma differentiable_at.iterate {f : E → E} (hf : differentiable_at 𝕜 f x)
(hx : f x = x) (n : ℕ) :
differentiable_at 𝕜 (f^[n]) x :=
exists.elim hf $ λ f' hf, (hf.iterate hx n).differentiable_at
protected lemma differentiable_within_at.iterate {f : E → E} (hf : differentiable_within_at 𝕜 f s x)
(hx : f x = x) (hs : maps_to f s s) (n : ℕ) :
differentiable_within_at 𝕜 (f^[n]) s x :=
exists.elim hf $ λ f' hf, (hf.iterate hx hs n).differentiable_within_at
end composition
section cartesian_product
/-! ### Derivative of the cartesian product of two functions -/
section prod
variables {f₂ : E → G} {f₂' : E →L[𝕜] G}
protected lemma has_strict_fderiv_at.prod
(hf₁ : has_strict_fderiv_at f₁ f₁' x) (hf₂ : has_strict_fderiv_at f₂ f₂' x) :
has_strict_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x :=
hf₁.prod_left hf₂
lemma has_fderiv_at_filter.prod
(hf₁ : has_fderiv_at_filter f₁ f₁' x L) (hf₂ : has_fderiv_at_filter f₂ f₂' x L) :
has_fderiv_at_filter (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x L :=
hf₁.prod_left hf₂
lemma has_fderiv_within_at.prod
(hf₁ : has_fderiv_within_at f₁ f₁' s x) (hf₂ : has_fderiv_within_at f₂ f₂' s x) :
has_fderiv_within_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') s x :=
hf₁.prod hf₂
lemma has_fderiv_at.prod (hf₁ : has_fderiv_at f₁ f₁' x) (hf₂ : has_fderiv_at f₂ f₂' x) :
has_fderiv_at (λx, (f₁ x, f₂ x)) (continuous_linear_map.prod f₁' f₂') x :=
hf₁.prod hf₂
lemma differentiable_within_at.prod
(hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) :
differentiable_within_at 𝕜 (λx:E, (f₁ x, f₂ x)) s x :=
(hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).differentiable_within_at
@[simp]
lemma differentiable_at.prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) :
differentiable_at 𝕜 (λx:E, (f₁ x, f₂ x)) x :=
(hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).differentiable_at
lemma differentiable_on.prod (hf₁ : differentiable_on 𝕜 f₁ s) (hf₂ : differentiable_on 𝕜 f₂ s) :
differentiable_on 𝕜 (λx:E, (f₁ x, f₂ x)) s :=
λx hx, differentiable_within_at.prod (hf₁ x hx) (hf₂ x hx)
@[simp]
lemma differentiable.prod (hf₁ : differentiable 𝕜 f₁) (hf₂ : differentiable 𝕜 f₂) :
differentiable 𝕜 (λx:E, (f₁ x, f₂ x)) :=
λ x, differentiable_at.prod (hf₁ x) (hf₂ x)
lemma differentiable_at.fderiv_prod
(hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) :
fderiv 𝕜 (λx:E, (f₁ x, f₂ x)) x = (fderiv 𝕜 f₁ x).prod (fderiv 𝕜 f₂ x) :=
(hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).fderiv
lemma differentiable_at.fderiv_within_prod
(hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x)
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx:E, (f₁ x, f₂ x)) s x =
(fderiv_within 𝕜 f₁ s x).prod (fderiv_within 𝕜 f₂ s x) :=
begin
apply has_fderiv_within_at.fderiv_within _ hxs,
exact has_fderiv_within_at.prod hf₁.has_fderiv_within_at hf₂.has_fderiv_within_at
end
end prod
section fst
variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}
lemma has_strict_fderiv_at_fst : has_strict_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p :=
(fst 𝕜 E F).has_strict_fderiv_at
protected lemma has_strict_fderiv_at.fst (h : has_strict_fderiv_at f₂ f₂' x) :
has_strict_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=
has_strict_fderiv_at_fst.comp x h
lemma has_fderiv_at_filter_fst {L : filter (E × F)} :
has_fderiv_at_filter (@prod.fst E F) (fst 𝕜 E F) p L :=
(fst 𝕜 E F).has_fderiv_at_filter
protected lemma has_fderiv_at_filter.fst (h : has_fderiv_at_filter f₂ f₂' x L) :
has_fderiv_at_filter (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x L :=
has_fderiv_at_filter_fst.comp x h
lemma has_fderiv_at_fst : has_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p :=
has_fderiv_at_filter_fst
protected lemma has_fderiv_at.fst (h : has_fderiv_at f₂ f₂' x) :
has_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=
h.fst
lemma has_fderiv_within_at_fst {s : set (E × F)} :
has_fderiv_within_at (@prod.fst E F) (fst 𝕜 E F) s p :=
has_fderiv_at_filter_fst
protected lemma has_fderiv_within_at.fst (h : has_fderiv_within_at f₂ f₂' s x) :
has_fderiv_within_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') s x :=
h.fst
lemma differentiable_at_fst : differentiable_at 𝕜 prod.fst p :=
has_fderiv_at_fst.differentiable_at
@[simp] protected lemma differentiable_at.fst (h : differentiable_at 𝕜 f₂ x) :
differentiable_at 𝕜 (λ x, (f₂ x).1) x :=
differentiable_at_fst.comp x h
lemma differentiable_fst : differentiable 𝕜 (prod.fst : E × F → E) :=
λ x, differentiable_at_fst
@[simp] protected lemma differentiable.fst (h : differentiable 𝕜 f₂) :
differentiable 𝕜 (λ x, (f₂ x).1) :=
differentiable_fst.comp h
lemma differentiable_within_at_fst {s : set (E × F)} : differentiable_within_at 𝕜 prod.fst s p :=
differentiable_at_fst.differentiable_within_at
protected lemma differentiable_within_at.fst (h : differentiable_within_at 𝕜 f₂ s x) :
differentiable_within_at 𝕜 (λ x, (f₂ x).1) s x :=
differentiable_at_fst.comp_differentiable_within_at x h
lemma differentiable_on_fst {s : set (E × F)} : differentiable_on 𝕜 prod.fst s :=
differentiable_fst.differentiable_on
protected lemma differentiable_on.fst (h : differentiable_on 𝕜 f₂ s) :
differentiable_on 𝕜 (λ x, (f₂ x).1) s :=
differentiable_fst.comp_differentiable_on h
lemma fderiv_fst : fderiv 𝕜 prod.fst p = fst 𝕜 E F := has_fderiv_at_fst.fderiv
lemma fderiv.fst (h : differentiable_at 𝕜 f₂ x) :
fderiv 𝕜 (λ x, (f₂ x).1) x = (fst 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=
h.has_fderiv_at.fst.fderiv
lemma fderiv_within_fst {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) :
fderiv_within 𝕜 prod.fst s p = fst 𝕜 E F :=
has_fderiv_within_at_fst.fderiv_within hs
lemma fderiv_within.fst (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) :
fderiv_within 𝕜 (λ x, (f₂ x).1) s x = (fst 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) :=
h.has_fderiv_within_at.fst.fderiv_within hs
end fst
section snd
variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}
lemma has_strict_fderiv_at_snd : has_strict_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p :=
(snd 𝕜 E F).has_strict_fderiv_at
protected lemma has_strict_fderiv_at.snd (h : has_strict_fderiv_at f₂ f₂' x) :
has_strict_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=
has_strict_fderiv_at_snd.comp x h
lemma has_fderiv_at_filter_snd {L : filter (E × F)} :
has_fderiv_at_filter (@prod.snd E F) (snd 𝕜 E F) p L :=
(snd 𝕜 E F).has_fderiv_at_filter
protected lemma has_fderiv_at_filter.snd (h : has_fderiv_at_filter f₂ f₂' x L) :
has_fderiv_at_filter (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x L :=
has_fderiv_at_filter_snd.comp x h
lemma has_fderiv_at_snd : has_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p :=
has_fderiv_at_filter_snd
protected lemma has_fderiv_at.snd (h : has_fderiv_at f₂ f₂' x) :
has_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=
h.snd
lemma has_fderiv_within_at_snd {s : set (E × F)} :
has_fderiv_within_at (@prod.snd E F) (snd 𝕜 E F) s p :=
has_fderiv_at_filter_snd
protected lemma has_fderiv_within_at.snd (h : has_fderiv_within_at f₂ f₂' s x) :
has_fderiv_within_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') s x :=
h.snd
lemma differentiable_at_snd : differentiable_at 𝕜 prod.snd p :=
has_fderiv_at_snd.differentiable_at
@[simp] protected lemma differentiable_at.snd (h : differentiable_at 𝕜 f₂ x) :
differentiable_at 𝕜 (λ x, (f₂ x).2) x :=
differentiable_at_snd.comp x h
lemma differentiable_snd : differentiable 𝕜 (prod.snd : E × F → F) :=
λ x, differentiable_at_snd
@[simp] protected lemma differentiable.snd (h : differentiable 𝕜 f₂) :
differentiable 𝕜 (λ x, (f₂ x).2) :=
differentiable_snd.comp h
lemma differentiable_within_at_snd {s : set (E × F)} : differentiable_within_at 𝕜 prod.snd s p :=
differentiable_at_snd.differentiable_within_at
protected lemma differentiable_within_at.snd (h : differentiable_within_at 𝕜 f₂ s x) :
differentiable_within_at 𝕜 (λ x, (f₂ x).2) s x :=
differentiable_at_snd.comp_differentiable_within_at x h
lemma differentiable_on_snd {s : set (E × F)} : differentiable_on 𝕜 prod.snd s :=
differentiable_snd.differentiable_on
protected lemma differentiable_on.snd (h : differentiable_on 𝕜 f₂ s) :
differentiable_on 𝕜 (λ x, (f₂ x).2) s :=
differentiable_snd.comp_differentiable_on h
lemma fderiv_snd : fderiv 𝕜 prod.snd p = snd 𝕜 E F := has_fderiv_at_snd.fderiv
lemma fderiv.snd (h : differentiable_at 𝕜 f₂ x) :
fderiv 𝕜 (λ x, (f₂ x).2) x = (snd 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=
h.has_fderiv_at.snd.fderiv
lemma fderiv_within_snd {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) :
fderiv_within 𝕜 prod.snd s p = snd 𝕜 E F :=
has_fderiv_within_at_snd.fderiv_within hs
lemma fderiv_within.snd (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) :
fderiv_within 𝕜 (λ x, (f₂ x).2) s x = (snd 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) :=
h.has_fderiv_within_at.snd.fderiv_within hs
end snd
section prod_map
variables {f₂ : G → G'} {f₂' : G →L[𝕜] G'} {y : G} (p : E × G)
protected theorem has_strict_fderiv_at.prod_map (hf : has_strict_fderiv_at f f' p.1)
(hf₂ : has_strict_fderiv_at f₂ f₂' p.2) :
has_strict_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p :=
(hf.comp p has_strict_fderiv_at_fst).prod (hf₂.comp p has_strict_fderiv_at_snd)
protected theorem has_fderiv_at.prod_map (hf : has_fderiv_at f f' p.1)
(hf₂ : has_fderiv_at f₂ f₂' p.2) :
has_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p :=
(hf.comp p has_fderiv_at_fst).prod (hf₂.comp p has_fderiv_at_snd)
@[simp] protected theorem differentiable_at.prod_map (hf : differentiable_at 𝕜 f p.1)
(hf₂ : differentiable_at 𝕜 f₂ p.2) :
differentiable_at 𝕜 (λ p : E × G, (f p.1, f₂ p.2)) p :=
(hf.comp p differentiable_at_fst).prod (hf₂.comp p differentiable_at_snd)
end prod_map
end cartesian_product
section const_smul
/-! ### Derivative of a function multiplied by a constant -/
theorem has_strict_fderiv_at.const_smul (h : has_strict_fderiv_at f f' x) (c : 𝕜) :
has_strict_fderiv_at (λ x, c • f x) (c • f') x :=
(c • (1 : F →L[𝕜] F)).has_strict_fderiv_at.comp x h
theorem has_fderiv_at_filter.const_smul (h : has_fderiv_at_filter f f' x L) (c : 𝕜) :
has_fderiv_at_filter (λ x, c • f x) (c • f') x L :=
(c • (1 : F →L[𝕜] F)).has_fderiv_at_filter.comp x h
theorem has_fderiv_within_at.const_smul (h : has_fderiv_within_at f f' s x) (c : 𝕜) :
has_fderiv_within_at (λ x, c • f x) (c • f') s x :=
h.const_smul c
theorem has_fderiv_at.const_smul (h : has_fderiv_at f f' x) (c : 𝕜) :
has_fderiv_at (λ x, c • f x) (c • f') x :=
h.const_smul c
lemma differentiable_within_at.const_smul (h : differentiable_within_at 𝕜 f s x) (c : 𝕜) :
differentiable_within_at 𝕜 (λy, c • f y) s x :=
(h.has_fderiv_within_at.const_smul c).differentiable_within_at
lemma differentiable_at.const_smul (h : differentiable_at 𝕜 f x) (c : 𝕜) :
differentiable_at 𝕜 (λy, c • f y) x :=
(h.has_fderiv_at.const_smul c).differentiable_at
lemma differentiable_on.const_smul (h : differentiable_on 𝕜 f s) (c : 𝕜) :
differentiable_on 𝕜 (λy, c • f y) s :=
λx hx, (h x hx).const_smul c
lemma differentiable.const_smul (h : differentiable 𝕜 f) (c : 𝕜) :
differentiable 𝕜 (λy, c • f y) :=
λx, (h x).const_smul c
lemma fderiv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f s x) (c : 𝕜) :
fderiv_within 𝕜 (λy, c • f y) s x = c • fderiv_within 𝕜 f s x :=
(h.has_fderiv_within_at.const_smul c).fderiv_within hxs
lemma fderiv_const_smul (h : differentiable_at 𝕜 f x) (c : 𝕜) :
fderiv 𝕜 (λy, c • f y) x = c • fderiv 𝕜 f x :=
(h.has_fderiv_at.const_smul c).fderiv
end const_smul
section add
/-! ### Derivative of the sum of two functions -/
theorem has_strict_fderiv_at.add (hf : has_strict_fderiv_at f f' x)
(hg : has_strict_fderiv_at g g' x) :
has_strict_fderiv_at (λ y, f y + g y) (f' + g') x :=
(hf.add hg).congr_left $ λ y, by simp; abel
theorem has_fderiv_at_filter.add
(hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) :
has_fderiv_at_filter (λ y, f y + g y) (f' + g') x L :=
(hf.add hg).congr_left $ λ _, by simp; abel
theorem has_fderiv_within_at.add
(hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) :
has_fderiv_within_at (λ y, f y + g y) (f' + g') s x :=
hf.add hg
theorem has_fderiv_at.add
(hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :
has_fderiv_at (λ x, f x + g x) (f' + g') x :=
hf.add hg
lemma differentiable_within_at.add
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
differentiable_within_at 𝕜 (λ y, f y + g y) s x :=
(hf.has_fderiv_within_at.add hg.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
differentiable_at 𝕜 (λ y, f y + g y) x :=
(hf.has_fderiv_at.add hg.has_fderiv_at).differentiable_at
lemma differentiable_on.add
(hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) :
differentiable_on 𝕜 (λy, f y + g y) s :=
λx hx, (hf x hx).add (hg x hx)
@[simp] lemma differentiable.add
(hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) :
differentiable 𝕜 (λy, f y + g y) :=
λx, (hf x).add (hg x)
lemma fderiv_within_add (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
fderiv_within 𝕜 (λy, f y + g y) s x = fderiv_within 𝕜 f s x + fderiv_within 𝕜 g s x :=
(hf.has_fderiv_within_at.add hg.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
fderiv 𝕜 (λy, f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x :=
(hf.has_fderiv_at.add hg.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.add_const (hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ y, f y + c) f' x :=
add_zero f' ▸ hf.add (has_strict_fderiv_at_const _ _)
theorem has_fderiv_at_filter.add_const
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ y, f y + c) f' x L :=
add_zero f' ▸ hf.add (has_fderiv_at_filter_const _ _ _)
theorem has_fderiv_within_at.add_const
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ y, f y + c) f' s x :=
hf.add_const c
theorem has_fderiv_at.add_const (hf : has_fderiv_at f f' x) (c : F):
has_fderiv_at (λ x, f x + c) f' x :=
hf.add_const c
lemma differentiable_within_at.add_const
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, f y + c) s x :=
(hf.has_fderiv_within_at.add_const c).differentiable_within_at
@[simp] lemma differentiable_within_at_add_const_iff (c : F) :
differentiable_within_at 𝕜 (λ y, f y + c) s x ↔ differentiable_within_at 𝕜 f s x :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma differentiable_at.add_const
(hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, f y + c) x :=
(hf.has_fderiv_at.add_const c).differentiable_at
@[simp] lemma differentiable_at_add_const_iff (c : F) :
differentiable_at 𝕜 (λ y, f y + c) x ↔ differentiable_at 𝕜 f x :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma differentiable_on.add_const
(hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, f y + c) s :=
λx hx, (hf x hx).add_const c
@[simp] lemma differentiable_on_add_const_iff (c : F) :
differentiable_on 𝕜 (λ y, f y + c) s ↔ differentiable_on 𝕜 f s :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma differentiable.add_const
(hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, f y + c) :=
λx, (hf x).add_const c
@[simp] lemma differentiable_add_const_iff (c : F) :
differentiable 𝕜 (λ y, f y + c) ↔ differentiable 𝕜 f :=
⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩
lemma fderiv_within_add_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, f y + c) s x = fderiv_within 𝕜 f s x :=
if hf : differentiable_within_at 𝕜 f s x
then (hf.has_fderiv_within_at.add_const c).fderiv_within hxs
else by { rw [fderiv_within_zero_of_not_differentiable_within_at hf,
fderiv_within_zero_of_not_differentiable_within_at], simpa }
lemma fderiv_add_const (c : F) : fderiv 𝕜 (λy, f y + c) x = fderiv 𝕜 f x :=
by simp only [← fderiv_within_univ, fderiv_within_add_const unique_diff_within_at_univ]
theorem has_strict_fderiv_at.const_add (hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ y, c + f y) f' x :=
zero_add f' ▸ (has_strict_fderiv_at_const _ _).add hf
theorem has_fderiv_at_filter.const_add
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ y, c + f y) f' x L :=
zero_add f' ▸ (has_fderiv_at_filter_const _ _ _).add hf
theorem has_fderiv_within_at.const_add
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ y, c + f y) f' s x :=
hf.const_add c
theorem has_fderiv_at.const_add
(hf : has_fderiv_at f f' x) (c : F):
has_fderiv_at (λ x, c + f x) f' x :=
hf.const_add c
lemma differentiable_within_at.const_add
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, c + f y) s x :=
(hf.has_fderiv_within_at.const_add c).differentiable_within_at
@[simp] lemma differentiable_within_at_const_add_iff (c : F) :
differentiable_within_at 𝕜 (λ y, c + f y) s x ↔ differentiable_within_at 𝕜 f s x :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma differentiable_at.const_add
(hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, c + f y) x :=
(hf.has_fderiv_at.const_add c).differentiable_at
@[simp] lemma differentiable_at_const_add_iff (c : F) :
differentiable_at 𝕜 (λ y, c + f y) x ↔ differentiable_at 𝕜 f x :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma differentiable_on.const_add (hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, c + f y) s :=
λx hx, (hf x hx).const_add c
@[simp] lemma differentiable_on_const_add_iff (c : F) :
differentiable_on 𝕜 (λ y, c + f y) s ↔ differentiable_on 𝕜 f s :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma differentiable.const_add (hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, c + f y) :=
λx, (hf x).const_add c
@[simp] lemma differentiable_const_add_iff (c : F) :
differentiable 𝕜 (λ y, c + f y) ↔ differentiable 𝕜 f :=
⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩
lemma fderiv_within_const_add (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, c + f y) s x = fderiv_within 𝕜 f s x :=
by simpa only [add_comm] using fderiv_within_add_const hxs c
lemma fderiv_const_add (c : F) : fderiv 𝕜 (λy, c + f y) x = fderiv 𝕜 f x :=
by simp only [add_comm c, fderiv_add_const]
end add
section sum
/-! ### Derivative of a finite sum of functions -/
open_locale big_operators
variables {ι : Type*} {u : finset ι} {A : ι → (E → F)} {A' : ι → (E →L[𝕜] F)}
theorem has_strict_fderiv_at.sum (h : ∀ i ∈ u, has_strict_fderiv_at (A i) (A' i) x) :
has_strict_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
begin
dsimp [has_strict_fderiv_at] at *,
convert is_o.sum h,
simp [finset.sum_sub_distrib, continuous_linear_map.sum_apply]
end
theorem has_fderiv_at_filter.sum (h : ∀ i ∈ u, has_fderiv_at_filter (A i) (A' i) x L) :
has_fderiv_at_filter (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x L :=
begin
dsimp [has_fderiv_at_filter] at *,
convert is_o.sum h,
simp [continuous_linear_map.sum_apply]
end
theorem has_fderiv_within_at.sum (h : ∀ i ∈ u, has_fderiv_within_at (A i) (A' i) s x) :
has_fderiv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x :=
has_fderiv_at_filter.sum h
theorem has_fderiv_at.sum (h : ∀ i ∈ u, has_fderiv_at (A i) (A' i) x) :
has_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
has_fderiv_at_filter.sum h
theorem differentiable_within_at.sum (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :
differentiable_within_at 𝕜 (λ y, ∑ i in u, A i y) s x :=
has_fderiv_within_at.differentiable_within_at $ has_fderiv_within_at.sum $
λ i hi, (h i hi).has_fderiv_within_at
@[simp] theorem differentiable_at.sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :
differentiable_at 𝕜 (λ y, ∑ i in u, A i y) x :=
has_fderiv_at.differentiable_at $ has_fderiv_at.sum $ λ i hi, (h i hi).has_fderiv_at
theorem differentiable_on.sum (h : ∀ i ∈ u, differentiable_on 𝕜 (A i) s) :
differentiable_on 𝕜 (λ y, ∑ i in u, A i y) s :=
λ x hx, differentiable_within_at.sum $ λ i hi, h i hi x hx
@[simp] theorem differentiable.sum (h : ∀ i ∈ u, differentiable 𝕜 (A i)) :
differentiable 𝕜 (λ y, ∑ i in u, A i y) :=
λ x, differentiable_at.sum $ λ i hi, h i hi x
theorem fderiv_within_sum (hxs : unique_diff_within_at 𝕜 s x)
(h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :
fderiv_within 𝕜 (λ y, ∑ i in u, A i y) s x = (∑ i in u, fderiv_within 𝕜 (A i) s x) :=
(has_fderiv_within_at.sum (λ i hi, (h i hi).has_fderiv_within_at)).fderiv_within hxs
theorem fderiv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :
fderiv 𝕜 (λ y, ∑ i in u, A i y) x = (∑ i in u, fderiv 𝕜 (A i) x) :=
(has_fderiv_at.sum (λ i hi, (h i hi).has_fderiv_at)).fderiv
end sum
section pi
/-!
### Derivatives of functions `f : E → Π i, F' i`
In this section we formulate `has_*fderiv*_pi` theorems as `iff`s, and provide two versions of each
theorem:
* the version without `'` deals with `φ : Π i, E → F' i` and `φ' : Π i, E →L[𝕜] F' i`
and is designed to deduce differentiability of `λ x i, φ i x` from differentiability
of each `φ i`;
* the version with `'` deals with `Φ : E → Π i, F' i` and `Φ' : E →L[𝕜] Π i, F' i`
and is designed to deduce differentiability of the components `λ x, Φ x i` from
differentiability of `Φ`.
-/
variables {ι : Type*} [fintype ι] {F' : ι → Type*} [Π i, normed_group (F' i)]
[Π i, normed_space 𝕜 (F' i)] {φ : Π i, E → F' i} {φ' : Π i, E →L[𝕜] F' i}
{Φ : E → Π i, F' i} {Φ' : E →L[𝕜] Π i, F' i}
@[simp] lemma has_strict_fderiv_at_pi' :
has_strict_fderiv_at Φ Φ' x ↔
∀ i, has_strict_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x :=
begin
simp only [has_strict_fderiv_at, continuous_linear_map.coe_pi],
exact is_o_pi
end
@[simp] lemma has_strict_fderiv_at_pi :
has_strict_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔
∀ i, has_strict_fderiv_at (φ i) (φ' i) x :=
has_strict_fderiv_at_pi'
@[simp] lemma has_fderiv_at_filter_pi' :
has_fderiv_at_filter Φ Φ' x L ↔
∀ i, has_fderiv_at_filter (λ x, Φ x i) ((proj i).comp Φ') x L :=
begin
simp only [has_fderiv_at_filter, continuous_linear_map.coe_pi],
exact is_o_pi
end
lemma has_fderiv_at_filter_pi :
has_fderiv_at_filter (λ x i, φ i x) (continuous_linear_map.pi φ') x L ↔
∀ i, has_fderiv_at_filter (φ i) (φ' i) x L :=
has_fderiv_at_filter_pi'
@[simp] lemma has_fderiv_at_pi' :
has_fderiv_at Φ Φ' x ↔
∀ i, has_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x :=
has_fderiv_at_filter_pi'
lemma has_fderiv_at_pi :
has_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔
∀ i, has_fderiv_at (φ i) (φ' i) x :=
has_fderiv_at_filter_pi
@[simp] lemma has_fderiv_within_at_pi' :
has_fderiv_within_at Φ Φ' s x ↔
∀ i, has_fderiv_within_at (λ x, Φ x i) ((proj i).comp Φ') s x :=
has_fderiv_at_filter_pi'
lemma has_fderiv_within_at_pi :
has_fderiv_within_at (λ x i, φ i x) (continuous_linear_map.pi φ') s x ↔
∀ i, has_fderiv_within_at (φ i) (φ' i) s x :=
has_fderiv_at_filter_pi
@[simp] lemma differentiable_within_at_pi :
differentiable_within_at 𝕜 Φ s x ↔
∀ i, differentiable_within_at 𝕜 (λ x, Φ x i) s x :=
⟨λ h i, (has_fderiv_within_at_pi'.1 h.has_fderiv_within_at i).differentiable_within_at,
λ h, (has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).differentiable_within_at⟩
@[simp] lemma differentiable_at_pi :
differentiable_at 𝕜 Φ x ↔ ∀ i, differentiable_at 𝕜 (λ x, Φ x i) x :=
⟨λ h i, (has_fderiv_at_pi'.1 h.has_fderiv_at i).differentiable_at,
λ h, (has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).differentiable_at⟩
lemma differentiable_on_pi :
differentiable_on 𝕜 Φ s ↔ ∀ i, differentiable_on 𝕜 (λ x, Φ x i) s :=
⟨λ h i x hx, differentiable_within_at_pi.1 (h x hx) i,
λ h x hx, differentiable_within_at_pi.2 (λ i, h i x hx)⟩
lemma differentiable_pi :
differentiable 𝕜 Φ ↔ ∀ i, differentiable 𝕜 (λ x, Φ x i) :=
⟨λ h i x, differentiable_at_pi.1 (h x) i, λ h x, differentiable_at_pi.2 (λ i, h i x)⟩
-- TODO: find out which version (`φ` or `Φ`) works better with `rw`/`simp`
lemma fderiv_within_pi (h : ∀ i, differentiable_within_at 𝕜 (φ i) s x)
(hs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λ x i, φ i x) s x = pi (λ i, fderiv_within 𝕜 (φ i) s x) :=
(has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).fderiv_within hs
lemma fderiv_pi (h : ∀ i, differentiable_at 𝕜 (φ i) x) :
fderiv 𝕜 (λ x i, φ i x) x = pi (λ i, fderiv 𝕜 (φ i) x) :=
(has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).fderiv
end pi
section neg
/-! ### Derivative of the negative of a function -/
theorem has_strict_fderiv_at.neg (h : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ x, -f x) (-f') x :=
(-1 : F →L[𝕜] F).has_strict_fderiv_at.comp x h
theorem has_fderiv_at_filter.neg (h : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (λ x, -f x) (-f') x L :=
(-1 : F →L[𝕜] F).has_fderiv_at_filter.comp x h
theorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, -f x) (-f') s x :=
h.neg
theorem has_fderiv_at.neg (h : has_fderiv_at f f' x) :
has_fderiv_at (λ x, -f x) (-f') x :=
h.neg
lemma differentiable_within_at.neg (h : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (λy, -f y) s x :=
h.has_fderiv_within_at.neg.differentiable_within_at
@[simp] lemma differentiable_within_at_neg_iff :
differentiable_within_at 𝕜 (λy, -f y) s x ↔ differentiable_within_at 𝕜 f s x :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma differentiable_at.neg (h : differentiable_at 𝕜 f x) :
differentiable_at 𝕜 (λy, -f y) x :=
h.has_fderiv_at.neg.differentiable_at
@[simp] lemma differentiable_at_neg_iff :
differentiable_at 𝕜 (λy, -f y) x ↔ differentiable_at 𝕜 f x :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma differentiable_on.neg (h : differentiable_on 𝕜 f s) :
differentiable_on 𝕜 (λy, -f y) s :=
λx hx, (h x hx).neg
@[simp] lemma differentiable_on_neg_iff :
differentiable_on 𝕜 (λy, -f y) s ↔ differentiable_on 𝕜 f s :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma differentiable.neg (h : differentiable 𝕜 f) :
differentiable 𝕜 (λy, -f y) :=
λx, (h x).neg
@[simp] lemma differentiable_neg_iff : differentiable 𝕜 (λy, -f y) ↔ differentiable 𝕜 f :=
⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩
lemma fderiv_within_neg (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λy, -f y) s x = - fderiv_within 𝕜 f s x :=
if h : differentiable_within_at 𝕜 f s x
then h.has_fderiv_within_at.neg.fderiv_within hxs
else by { rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at, neg_zero], simpa }
@[simp] lemma fderiv_neg : fderiv 𝕜 (λy, -f y) x = - fderiv 𝕜 f x :=
by simp only [← fderiv_within_univ, fderiv_within_neg unique_diff_within_at_univ]
end neg
section sub
/-! ### Derivative of the difference of two functions -/
theorem has_strict_fderiv_at.sub
(hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) :
has_strict_fderiv_at (λ x, f x - g x) (f' - g') x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem has_fderiv_at_filter.sub
(hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) :
has_fderiv_at_filter (λ x, f x - g x) (f' - g') x L :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem has_fderiv_within_at.sub
(hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) :
has_fderiv_within_at (λ x, f x - g x) (f' - g') s x :=
hf.sub hg
theorem has_fderiv_at.sub
(hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :
has_fderiv_at (λ x, f x - g x) (f' - g') x :=
hf.sub hg
lemma differentiable_within_at.sub
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
differentiable_within_at 𝕜 (λ y, f y - g y) s x :=
(hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
differentiable_at 𝕜 (λ y, f y - g y) x :=
(hf.has_fderiv_at.sub hg.has_fderiv_at).differentiable_at
lemma differentiable_on.sub
(hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) :
differentiable_on 𝕜 (λy, f y - g y) s :=
λx hx, (hf x hx).sub (hg x hx)
@[simp] lemma differentiable.sub
(hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) :
differentiable 𝕜 (λy, f y - g y) :=
λx, (hf x).sub (hg x)
lemma fderiv_within_sub (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
fderiv_within 𝕜 (λy, f y - g y) s x = fderiv_within 𝕜 f s x - fderiv_within 𝕜 g s x :=
(hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
fderiv 𝕜 (λy, f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x :=
(hf.has_fderiv_at.sub hg.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.sub_const
(hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ x, f x - c) f' x :=
by simpa only [sub_eq_add_neg] using hf.add_const (-c)
theorem has_fderiv_at_filter.sub_const
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ x, f x - c) f' x L :=
by simpa only [sub_eq_add_neg] using hf.add_const (-c)
theorem has_fderiv_within_at.sub_const
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ x, f x - c) f' s x :=
hf.sub_const c
theorem has_fderiv_at.sub_const
(hf : has_fderiv_at f f' x) (c : F) :
has_fderiv_at (λ x, f x - c) f' x :=
hf.sub_const c
lemma differentiable_within_at.sub_const
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, f y - c) s x :=
(hf.has_fderiv_within_at.sub_const c).differentiable_within_at
@[simp] lemma differentiable_within_at_sub_const_iff (c : F) :
differentiable_within_at 𝕜 (λ y, f y - c) s x ↔ differentiable_within_at 𝕜 f s x :=
by simp only [sub_eq_add_neg, differentiable_within_at_add_const_iff]
lemma differentiable_at.sub_const (hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, f y - c) x :=
(hf.has_fderiv_at.sub_const c).differentiable_at
@[simp] lemma differentiable_at_sub_const_iff (c : F) :
differentiable_at 𝕜 (λ y, f y - c) x ↔ differentiable_at 𝕜 f x :=
by simp only [sub_eq_add_neg, differentiable_at_add_const_iff]
lemma differentiable_on.sub_const (hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, f y - c) s :=
λx hx, (hf x hx).sub_const c
@[simp] lemma differentiable_on_sub_const_iff (c : F) :
differentiable_on 𝕜 (λ y, f y - c) s ↔ differentiable_on 𝕜 f s :=
by simp only [sub_eq_add_neg, differentiable_on_add_const_iff]
lemma differentiable.sub_const (hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, f y - c) :=
λx, (hf x).sub_const c
@[simp] lemma differentiable_sub_const_iff (c : F) :
differentiable 𝕜 (λ y, f y - c) ↔ differentiable 𝕜 f :=
by simp only [sub_eq_add_neg, differentiable_add_const_iff]
lemma fderiv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, f y - c) s x = fderiv_within 𝕜 f s x :=
by simp only [sub_eq_add_neg, fderiv_within_add_const hxs]
lemma fderiv_sub_const (c : F) : fderiv 𝕜 (λy, f y - c) x = fderiv 𝕜 f x :=
by simp only [sub_eq_add_neg, fderiv_add_const]
theorem has_strict_fderiv_at.const_sub
(hf : has_strict_fderiv_at f f' x) (c : F) :
has_strict_fderiv_at (λ x, c - f x) (-f') x :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_fderiv_at_filter.const_sub
(hf : has_fderiv_at_filter f f' x L) (c : F) :
has_fderiv_at_filter (λ x, c - f x) (-f') x L :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_fderiv_within_at.const_sub
(hf : has_fderiv_within_at f f' s x) (c : F) :
has_fderiv_within_at (λ x, c - f x) (-f') s x :=
hf.const_sub c
theorem has_fderiv_at.const_sub
(hf : has_fderiv_at f f' x) (c : F) :
has_fderiv_at (λ x, c - f x) (-f') x :=
hf.const_sub c
lemma differentiable_within_at.const_sub
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
differentiable_within_at 𝕜 (λ y, c - f y) s x :=
(hf.has_fderiv_within_at.const_sub c).differentiable_within_at
@[simp] lemma differentiable_within_at_const_sub_iff (c : F) :
differentiable_within_at 𝕜 (λ y, c - f y) s x ↔ differentiable_within_at 𝕜 f s x :=
by simp [sub_eq_add_neg]
lemma differentiable_at.const_sub
(hf : differentiable_at 𝕜 f x) (c : F) :
differentiable_at 𝕜 (λ y, c - f y) x :=
(hf.has_fderiv_at.const_sub c).differentiable_at
@[simp] lemma differentiable_at_const_sub_iff (c : F) :
differentiable_at 𝕜 (λ y, c - f y) x ↔ differentiable_at 𝕜 f x :=
by simp [sub_eq_add_neg]
lemma differentiable_on.const_sub (hf : differentiable_on 𝕜 f s) (c : F) :
differentiable_on 𝕜 (λy, c - f y) s :=
λx hx, (hf x hx).const_sub c
@[simp] lemma differentiable_on_const_sub_iff (c : F) :
differentiable_on 𝕜 (λ y, c - f y) s ↔ differentiable_on 𝕜 f s :=
by simp [sub_eq_add_neg]
lemma differentiable.const_sub (hf : differentiable 𝕜 f) (c : F) :
differentiable 𝕜 (λy, c - f y) :=
λx, (hf x).const_sub c
@[simp] lemma differentiable_const_sub_iff (c : F) :
differentiable 𝕜 (λ y, c - f y) ↔ differentiable 𝕜 f :=
by simp [sub_eq_add_neg]
lemma fderiv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
fderiv_within 𝕜 (λy, c - f y) s x = -fderiv_within 𝕜 f s x :=
by simp only [sub_eq_add_neg, fderiv_within_const_add, fderiv_within_neg, hxs]
lemma fderiv_const_sub (c : F) : fderiv 𝕜 (λy, c - f y) x = -fderiv 𝕜 f x :=
by simp only [← fderiv_within_univ, fderiv_within_const_sub unique_diff_within_at_univ]
end sub
section bilinear_map
/-! ### Derivative of a bounded bilinear map -/
variables {b : E × F → G} {u : set (E × F) }
open normed_field
lemma is_bounded_bilinear_map.has_strict_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
has_strict_fderiv_at b (h.deriv p) p :=
begin
rw has_strict_fderiv_at,
set T := (E × F) × (E × F),
have : is_o (λ q : T, b (q.1 - q.2)) (λ q : T, ∥q.1 - q.2∥ * 1) (𝓝 (p, p)),
{ refine (h.is_O'.comp_tendsto le_top).trans_is_o _,
simp only [(∘)],
refine (is_O_refl (λ q : T, ∥q.1 - q.2∥) _).mul_is_o (is_o.norm_left $ (is_o_one_iff _).2 _),
rw [← sub_self p],
exact continuous_at_fst.sub continuous_at_snd },
simp only [mul_one, is_o_norm_right] at this,
refine (is_o.congr_of_sub _).1 this, clear this,
convert_to is_o (λ q : T, h.deriv (p - q.2) (q.1 - q.2)) (λ q : T, q.1 - q.2) (𝓝 (p, p)),
{ ext ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩⟩, rcases p with ⟨x, y⟩,
simp only [is_bounded_bilinear_map_deriv_coe, prod.mk_sub_mk, h.map_sub_left, h.map_sub_right],
abel },
have : is_o (λ q : T, p - q.2) (λ q, (1:ℝ)) (𝓝 (p, p)),
from (is_o_one_iff _).2 (sub_self p ▸ tendsto_const_nhds.sub continuous_at_snd),
apply is_bounded_bilinear_map_apply.is_O_comp.trans_is_o,
refine is_o.trans_is_O _ (is_O_const_mul_self 1 _ _).of_norm_right,
refine is_o.mul_is_O _ (is_O_refl _ _),
exact (((h.is_bounded_linear_map_deriv.is_O_id ⊤).comp_tendsto le_top : _).trans_is_o
this).norm_left
end
lemma is_bounded_bilinear_map.has_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
has_fderiv_at b (h.deriv p) p :=
(h.has_strict_fderiv_at p).has_fderiv_at
lemma is_bounded_bilinear_map.has_fderiv_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
has_fderiv_within_at b (h.deriv p) u p :=
(h.has_fderiv_at p).has_fderiv_within_at
lemma is_bounded_bilinear_map.differentiable_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
differentiable_at 𝕜 b p :=
(h.has_fderiv_at p).differentiable_at
lemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map 𝕜 b)
(p : E × F) :
differentiable_within_at 𝕜 b u p :=
(h.differentiable_at p).differentiable_within_at
lemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :
fderiv 𝕜 b p = h.deriv p :=
has_fderiv_at.fderiv (h.has_fderiv_at p)
lemma is_bounded_bilinear_map.fderiv_within (h : is_bounded_bilinear_map 𝕜 b) (p : E × F)
(hxs : unique_diff_within_at 𝕜 u p) : fderiv_within 𝕜 b u p = h.deriv p :=
begin
rw differentiable_at.fderiv_within (h.differentiable_at p) hxs,
exact h.fderiv p
end
lemma is_bounded_bilinear_map.differentiable (h : is_bounded_bilinear_map 𝕜 b) :
differentiable 𝕜 b :=
λx, h.differentiable_at x
lemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map 𝕜 b) :
differentiable_on 𝕜 b u :=
h.differentiable.differentiable_on
lemma is_bounded_bilinear_map.continuous (h : is_bounded_bilinear_map 𝕜 b) :
continuous b :=
h.differentiable.continuous
lemma is_bounded_bilinear_map.continuous_left (h : is_bounded_bilinear_map 𝕜 b) {f : F} :
continuous (λe, b (e, f)) :=
h.continuous.comp (continuous_id.prod_mk continuous_const)
lemma is_bounded_bilinear_map.continuous_right (h : is_bounded_bilinear_map 𝕜 b) {e : E} :
continuous (λf, b (e, f)) :=
h.continuous.comp (continuous_const.prod_mk continuous_id)
end bilinear_map
namespace continuous_linear_equiv
/-!
### The set of continuous linear equivalences between two Banach spaces is open
In this section we establish that the set of continuous linear equivalences between two Banach
spaces is an open subset of the space of linear maps between them. These facts are placed here
because the proof uses `is_bounded_bilinear_map.continuous_left`, proved just above as a consequence
of its differentiability.
-/
protected lemma is_open [complete_space E] : is_open (range (coe : (E ≃L[𝕜] F) → (E →L[𝕜] F))) :=
begin
nontriviality E,
rw [is_open_iff_mem_nhds, forall_range_iff],
refine λ e, is_open.mem_nhds _ (mem_range_self _),
let O : (E →L[𝕜] F) → (E →L[𝕜] E) := λ f, (e.symm : F →L[𝕜] E).comp f,
have h_O : continuous O := is_bounded_bilinear_map_comp.continuous_left,
convert units.is_open.preimage h_O using 1,
ext f',
split,
{ rintros ⟨e', rfl⟩,
exact ⟨(e'.trans e.symm).to_unit, rfl⟩ },
{ rintros ⟨w, hw⟩,
use (units_equiv 𝕜 E w).trans e,
ext x,
simp [hw] }
end
protected lemma nhds [complete_space E] (e : E ≃L[𝕜] F) :
(range (coe : (E ≃L[𝕜] F) → (E →L[𝕜] F))) ∈ 𝓝 (e : E →L[𝕜] F) :=
is_open.mem_nhds continuous_linear_equiv.is_open (by simp)
end continuous_linear_equiv
section smul
/-! ### Derivative of the product of a scalar-valued function and a vector-valued function
If `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued
function, then `λ x, c x • f x` is differentiable as well. Lemmas in this section works for
function `c` taking values in the base field, as well as in a normed algebra over the base
field: e.g., they work for `c : E → ℂ` and `f : E → F` provided that `F` is a complex
normed vector space.
-/
variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
[normed_space 𝕜' F] [is_scalar_tower 𝕜 𝕜' F]
variables {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'}
theorem has_strict_fderiv_at.smul (hc : has_strict_fderiv_at c c' x)
(hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x :=
(is_bounded_bilinear_map_smul.has_strict_fderiv_at (c x, f x)).comp x $
hc.prod hf
theorem has_fderiv_within_at.smul
(hc : has_fderiv_within_at c c' s x) (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) s x :=
(is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp_has_fderiv_within_at x $
hc.prod hf
theorem has_fderiv_at.smul (hc : has_fderiv_at c c' x) (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x :=
(is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp x $
hc.prod hf
lemma differentiable_within_at.smul
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
differentiable_within_at 𝕜 (λ y, c y • f y) s x :=
(hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
differentiable_at 𝕜 (λ y, c y • f y) x :=
(hc.has_fderiv_at.smul hf.has_fderiv_at).differentiable_at
lemma differentiable_on.smul (hc : differentiable_on 𝕜 c s) (hf : differentiable_on 𝕜 f s) :
differentiable_on 𝕜 (λ y, c y • f y) s :=
λx hx, (hc x hx).smul (hf x hx)
@[simp] lemma differentiable.smul (hc : differentiable 𝕜 c) (hf : differentiable 𝕜 f) :
differentiable 𝕜 (λ y, c y • f y) :=
λx, (hc x).smul (hf x)
lemma fderiv_within_smul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
fderiv_within 𝕜 (λ y, c y • f y) s x =
c x • fderiv_within 𝕜 f s x + (fderiv_within 𝕜 c s x).smul_right (f x) :=
(hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
fderiv 𝕜 (λ y, c y • f y) x =
c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smul_right (f x) :=
(hc.has_fderiv_at.smul hf.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.smul_const (hc : has_strict_fderiv_at c c' x) (f : F) :
has_strict_fderiv_at (λ y, c y • f) (c'.smul_right f) x :=
by simpa only [smul_zero, zero_add] using hc.smul (has_strict_fderiv_at_const f x)
theorem has_fderiv_within_at.smul_const (hc : has_fderiv_within_at c c' s x) (f : F) :
has_fderiv_within_at (λ y, c y • f) (c'.smul_right f) s x :=
by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_within_at_const f x s)
theorem has_fderiv_at.smul_const (hc : has_fderiv_at c c' x) (f : F) :
has_fderiv_at (λ y, c y • f) (c'.smul_right f) x :=
by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_at_const f x)
lemma differentiable_within_at.smul_const
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
differentiable_within_at 𝕜 (λ y, c y • f) s x :=
(hc.has_fderiv_within_at.smul_const f).differentiable_within_at
lemma differentiable_at.smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
differentiable_at 𝕜 (λ y, c y • f) x :=
(hc.has_fderiv_at.smul_const f).differentiable_at
lemma differentiable_on.smul_const (hc : differentiable_on 𝕜 c s) (f : F) :
differentiable_on 𝕜 (λ y, c y • f) s :=
λx hx, (hc x hx).smul_const f
lemma differentiable.smul_const (hc : differentiable 𝕜 c) (f : F) :
differentiable 𝕜 (λ y, c y • f) :=
λx, (hc x).smul_const f
lemma fderiv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
fderiv_within 𝕜 (λ y, c y • f) s x =
(fderiv_within 𝕜 c s x).smul_right f :=
(hc.has_fderiv_within_at.smul_const f).fderiv_within hxs
lemma fderiv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
fderiv 𝕜 (λ y, c y • f) x = (fderiv 𝕜 c x).smul_right f :=
(hc.has_fderiv_at.smul_const f).fderiv
end smul
section mul
/-! ### Derivative of the product of two functions -/
variables {𝔸 𝔸' : Type*} [normed_ring 𝔸] [normed_comm_ring 𝔸'] [normed_algebra 𝕜 𝔸]
[normed_algebra 𝕜 𝔸'] {a b : E → 𝔸} {a' b' : E →L[𝕜] 𝔸} {c d : E → 𝔸'} {c' d' : E →L[𝕜] 𝔸'}
theorem has_strict_fderiv_at.mul' {x : E} (ha : has_strict_fderiv_at a a' x)
(hb : has_strict_fderiv_at b b' x) :
has_strict_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x :=
((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_strict_fderiv_at (a x, b x)).comp x
(ha.prod hb)
theorem has_strict_fderiv_at.mul
(hc : has_strict_fderiv_at c c' x) (hd : has_strict_fderiv_at d d' x) :
has_strict_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x :=
by { convert hc.mul' hd, ext z, apply mul_comm }
theorem has_fderiv_within_at.mul'
(ha : has_fderiv_within_at a a' s x) (hb : has_fderiv_within_at b b' s x) :
has_fderiv_within_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) s x :=
((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at
(a x, b x)).comp_has_fderiv_within_at x (ha.prod hb)
theorem has_fderiv_within_at.mul
(hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) :
has_fderiv_within_at (λ y, c y * d y) (c x • d' + d x • c') s x :=
by { convert hc.mul' hd, ext z, apply mul_comm }
theorem has_fderiv_at.mul'
(ha : has_fderiv_at a a' x) (hb : has_fderiv_at b b' x) :
has_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x :=
((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at (a x, b x)).comp x
(ha.prod hb)
theorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) :
has_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x :=
by { convert hc.mul' hd, ext z, apply mul_comm }
lemma differentiable_within_at.mul
(ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) :
differentiable_within_at 𝕜 (λ y, a y * b y) s x :=
(ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).differentiable_within_at
@[simp] lemma differentiable_at.mul (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) :
differentiable_at 𝕜 (λ y, a y * b y) x :=
(ha.has_fderiv_at.mul' hb.has_fderiv_at).differentiable_at
lemma differentiable_on.mul (ha : differentiable_on 𝕜 a s) (hb : differentiable_on 𝕜 b s) :
differentiable_on 𝕜 (λ y, a y * b y) s :=
λx hx, (ha x hx).mul (hb x hx)
@[simp] lemma differentiable.mul (ha : differentiable 𝕜 a) (hb : differentiable 𝕜 b) :
differentiable 𝕜 (λ y, a y * b y) :=
λx, (ha x).mul (hb x)
lemma fderiv_within_mul' (hxs : unique_diff_within_at 𝕜 s x)
(ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) :
fderiv_within 𝕜 (λ y, a y * b y) s x =
a x • fderiv_within 𝕜 b s x + (fderiv_within 𝕜 a s x).smul_right (b x) :=
(ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_within_mul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
fderiv_within 𝕜 (λ y, c y * d y) s x =
c x • fderiv_within 𝕜 d s x + d x • fderiv_within 𝕜 c s x :=
(hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs
lemma fderiv_mul' (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) :
fderiv 𝕜 (λ y, a y * b y) x =
a x • fderiv 𝕜 b x + (fderiv 𝕜 a x).smul_right (b x) :=
(ha.has_fderiv_at.mul' hb.has_fderiv_at).fderiv
lemma fderiv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
fderiv 𝕜 (λ y, c y * d y) x =
c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x :=
(hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv
theorem has_strict_fderiv_at.mul_const' (ha : has_strict_fderiv_at a a' x) (b : 𝔸) :
has_strict_fderiv_at (λ y, a y * b) (a'.smul_right b) x :=
(((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_strict_fderiv_at).comp x ha
theorem has_strict_fderiv_at.mul_const (hc : has_strict_fderiv_at c c' x) (d : 𝔸') :
has_strict_fderiv_at (λ y, c y * d) (d • c') x :=
by { convert hc.mul_const' d, ext z, apply mul_comm }
theorem has_fderiv_within_at.mul_const' (ha : has_fderiv_within_at a a' s x) (b : 𝔸) :
has_fderiv_within_at (λ y, a y * b) (a'.smul_right b) s x :=
(((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp_has_fderiv_within_at x ha
theorem has_fderiv_within_at.mul_const (hc : has_fderiv_within_at c c' s x) (d : 𝔸') :
has_fderiv_within_at (λ y, c y * d) (d • c') s x :=
by { convert hc.mul_const' d, ext z, apply mul_comm }
theorem has_fderiv_at.mul_const' (ha : has_fderiv_at a a' x) (b : 𝔸) :
has_fderiv_at (λ y, a y * b) (a'.smul_right b) x :=
(((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp x ha
theorem has_fderiv_at.mul_const (hc : has_fderiv_at c c' x) (d : 𝔸') :
has_fderiv_at (λ y, c y * d) (d • c') x :=
by { convert hc.mul_const' d, ext z, apply mul_comm }
lemma differentiable_within_at.mul_const
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
differentiable_within_at 𝕜 (λ y, a y * b) s x :=
(ha.has_fderiv_within_at.mul_const' b).differentiable_within_at
lemma differentiable_at.mul_const (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
differentiable_at 𝕜 (λ y, a y * b) x :=
(ha.has_fderiv_at.mul_const' b).differentiable_at
lemma differentiable_on.mul_const (ha : differentiable_on 𝕜 a s) (b : 𝔸) :
differentiable_on 𝕜 (λ y, a y * b) s :=
λx hx, (ha x hx).mul_const b
lemma differentiable.mul_const (ha : differentiable 𝕜 a) (b : 𝔸) :
differentiable 𝕜 (λ y, a y * b) :=
λx, (ha x).mul_const b
lemma fderiv_within_mul_const' (hxs : unique_diff_within_at 𝕜 s x)
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
fderiv_within 𝕜 (λ y, a y * b) s x = (fderiv_within 𝕜 a s x).smul_right b :=
(ha.has_fderiv_within_at.mul_const' b).fderiv_within hxs
lemma fderiv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (d : 𝔸') :
fderiv_within 𝕜 (λ y, c y * d) s x = d • fderiv_within 𝕜 c s x :=
(hc.has_fderiv_within_at.mul_const d).fderiv_within hxs
lemma fderiv_mul_const' (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
fderiv 𝕜 (λ y, a y * b) x = (fderiv 𝕜 a x).smul_right b :=
(ha.has_fderiv_at.mul_const' b).fderiv
lemma fderiv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝔸') :
fderiv 𝕜 (λ y, c y * d) x = d • fderiv 𝕜 c x :=
(hc.has_fderiv_at.mul_const d).fderiv
theorem has_strict_fderiv_at.const_mul (ha : has_strict_fderiv_at a a' x) (b : 𝔸) :
has_strict_fderiv_at (λ y, b * a y) (b • a') x :=
(((continuous_linear_map.lmul 𝕜 𝔸) b).has_strict_fderiv_at).comp x ha
theorem has_fderiv_within_at.const_mul
(ha : has_fderiv_within_at a a' s x) (b : 𝔸) :
has_fderiv_within_at (λ y, b * a y) (b • a') s x :=
(((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp_has_fderiv_within_at x ha
theorem has_fderiv_at.const_mul (ha : has_fderiv_at a a' x) (b : 𝔸) :
has_fderiv_at (λ y, b * a y) (b • a') x :=
(((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp x ha
lemma differentiable_within_at.const_mul
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
differentiable_within_at 𝕜 (λ y, b * a y) s x :=
(ha.has_fderiv_within_at.const_mul b).differentiable_within_at
lemma differentiable_at.const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
differentiable_at 𝕜 (λ y, b * a y) x :=
(ha.has_fderiv_at.const_mul b).differentiable_at
lemma differentiable_on.const_mul (ha : differentiable_on 𝕜 a s) (b : 𝔸) :
differentiable_on 𝕜 (λ y, b * a y) s :=
λx hx, (ha x hx).const_mul b
lemma differentiable.const_mul (ha : differentiable 𝕜 a) (b : 𝔸) :
differentiable 𝕜 (λ y, b * a y) :=
λx, (ha x).const_mul b
lemma fderiv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x)
(ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :
fderiv_within 𝕜 (λ y, b * a y) s x = b • fderiv_within 𝕜 a s x :=
(ha.has_fderiv_within_at.const_mul b).fderiv_within hxs
lemma fderiv_const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) :
fderiv 𝕜 (λ y, b * a y) x = b • fderiv 𝕜 a x :=
(ha.has_fderiv_at.const_mul b).fderiv
end mul
section algebra_inverse
variables {R : Type*} [normed_ring R] [normed_algebra 𝕜 R] [complete_space R]
open normed_ring continuous_linear_map ring
/-- At an invertible element `x` of a normed algebra `R`, the Fréchet derivative of the inversion
operation is the linear map `λ t, - x⁻¹ * t * x⁻¹`. -/
lemma has_fderiv_at_ring_inverse (x : units R) :
has_fderiv_at ring.inverse (-lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹) x :=
begin
have h_is_o : is_o (λ (t : R), inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹)
(λ (t : R), t) (𝓝 0),
{ refine (inverse_add_norm_diff_second_order x).trans_is_o ((is_o_norm_norm).mp _),
simp only [normed_field.norm_pow, norm_norm],
have h12 : 1 < 2 := by norm_num,
convert (asymptotics.is_o_pow_pow h12).comp_tendsto tendsto_norm_zero,
ext, simp },
have h_lim : tendsto (λ (y:R), y - x) (𝓝 x) (𝓝 0),
{ refine tendsto_zero_iff_norm_tendsto_zero.mpr _,
exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },
simp only [has_fderiv_at, has_fderiv_at_filter],
convert h_is_o.comp_tendsto h_lim,
ext y,
simp only [coe_comp', function.comp_app, lmul_left_right_apply, neg_apply, inverse_unit x,
units.inv_mul, add_sub_cancel'_right, mul_sub, sub_mul, one_mul, sub_neg_eq_add]
end
lemma differentiable_at_inverse (x : units R) : differentiable_at 𝕜 (@ring.inverse R _) x :=
(has_fderiv_at_ring_inverse x).differentiable_at
lemma fderiv_inverse (x : units R) :
fderiv 𝕜 (@ring.inverse R _) x = - lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹ :=
(has_fderiv_at_ring_inverse x).fderiv
end algebra_inverse
namespace continuous_linear_equiv
/-! ### Differentiability of linear equivs, and invariance of differentiability -/
variable (iso : E ≃L[𝕜] F)
protected lemma has_strict_fderiv_at :
has_strict_fderiv_at iso (iso : E →L[𝕜] F) x :=
iso.to_continuous_linear_map.has_strict_fderiv_at
protected lemma has_fderiv_within_at :
has_fderiv_within_at iso (iso : E →L[𝕜] F) s x :=
iso.to_continuous_linear_map.has_fderiv_within_at
protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x :=
iso.to_continuous_linear_map.has_fderiv_at_filter
protected lemma differentiable_at : differentiable_at 𝕜 iso x :=
iso.has_fderiv_at.differentiable_at
protected lemma differentiable_within_at :
differentiable_within_at 𝕜 iso s x :=
iso.differentiable_at.differentiable_within_at
protected lemma fderiv : fderiv 𝕜 iso x = iso :=
iso.has_fderiv_at.fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 iso s x = iso :=
iso.to_continuous_linear_map.fderiv_within hxs
protected lemma differentiable : differentiable 𝕜 iso :=
λx, iso.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 iso s :=
iso.differentiable.differentiable_on
lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} :
differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x :=
begin
refine ⟨λ H, _, λ H, iso.differentiable.differentiable_at.comp_differentiable_within_at x H⟩,
have : differentiable_within_at 𝕜 (iso.symm ∘ (iso ∘ f)) s x :=
iso.symm.differentiable.differentiable_at.comp_differentiable_within_at x H,
rwa [← function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this,
end
lemma comp_differentiable_at_iff {f : G → E} {x : G} :
differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x :=
by rw [← differentiable_within_at_univ, ← differentiable_within_at_univ,
iso.comp_differentiable_within_at_iff]
lemma comp_differentiable_on_iff {f : G → E} {s : set G} :
differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s :=
begin
rw [differentiable_on, differentiable_on],
simp only [iso.comp_differentiable_within_at_iff],
end
lemma comp_differentiable_iff {f : G → E} :
differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f :=
begin
rw [← differentiable_on_univ, ← differentiable_on_univ],
exact iso.comp_differentiable_on_iff
end
lemma comp_has_fderiv_within_at_iff
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x :=
begin
refine ⟨λ H, _, λ H, iso.has_fderiv_at.comp_has_fderiv_within_at x H⟩,
have A : f = iso.symm ∘ (iso ∘ f), by { rw [← function.comp.assoc, iso.symm_comp_self], refl },
have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f'),
by rw [← continuous_linear_map.comp_assoc, iso.coe_symm_comp_coe,
continuous_linear_map.id_comp],
rw [A, B],
exact iso.symm.has_fderiv_at.comp_has_fderiv_within_at x H
end
lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x :=
begin
refine ⟨λ H, _, λ H, iso.has_strict_fderiv_at.comp x H⟩,
convert iso.symm.has_strict_fderiv_at.comp x H; ext z; apply (iso.symm_apply_apply _).symm
end
lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x :=
by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff]
lemma comp_has_fderiv_within_at_iff'
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_within_at (iso ∘ f) f' s x ↔
has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x :=
by rw [← iso.comp_has_fderiv_within_at_iff, ← continuous_linear_map.comp_assoc,
iso.coe_comp_coe_symm, continuous_linear_map.id_comp]
lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x :=
by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff']
lemma comp_fderiv_within {f : G → E} {s : set G} {x : G}
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) :=
begin
by_cases h : differentiable_within_at 𝕜 f s x,
{ rw [fderiv.comp_fderiv_within x iso.differentiable_at h hxs, iso.fderiv] },
{ have : ¬differentiable_within_at 𝕜 (iso ∘ f) s x,
from mt iso.comp_differentiable_within_at_iff.1 h,
rw [fderiv_within_zero_of_not_differentiable_within_at h,
fderiv_within_zero_of_not_differentiable_within_at this,
continuous_linear_map.comp_zero] }
end
lemma comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) :=
begin
rw [← fderiv_within_univ, ← fderiv_within_univ],
exact iso.comp_fderiv_within unique_diff_within_at_univ,
end
end continuous_linear_equiv
namespace linear_isometry_equiv
/-! ### Differentiability of linear isometry equivs, and invariance of differentiability -/
variable (iso : E ≃ₗᵢ[𝕜] F)
protected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E →L[𝕜] F) x :=
(iso : E ≃L[𝕜] F).has_strict_fderiv_at
protected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E →L[𝕜] F) s x :=
(iso : E ≃L[𝕜] F).has_fderiv_within_at
protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x :=
(iso : E ≃L[𝕜] F).has_fderiv_at
protected lemma differentiable_at : differentiable_at 𝕜 iso x :=
iso.has_fderiv_at.differentiable_at
protected lemma differentiable_within_at :
differentiable_within_at 𝕜 iso s x :=
iso.differentiable_at.differentiable_within_at
protected lemma fderiv : fderiv 𝕜 iso x = iso := iso.has_fderiv_at.fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 iso s x = iso :=
(iso : E ≃L[𝕜] F).fderiv_within hxs
protected lemma differentiable : differentiable 𝕜 iso :=
λx, iso.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 iso s :=
iso.differentiable.differentiable_on
lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} :
differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x :=
(iso : E ≃L[𝕜] F).comp_differentiable_within_at_iff
lemma comp_differentiable_at_iff {f : G → E} {x : G} :
differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x :=
(iso : E ≃L[𝕜] F).comp_differentiable_at_iff
lemma comp_differentiable_on_iff {f : G → E} {s : set G} :
differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s :=
(iso : E ≃L[𝕜] F).comp_differentiable_on_iff
lemma comp_differentiable_iff {f : G → E} :
differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f :=
(iso : E ≃L[𝕜] F).comp_differentiable_iff
lemma comp_has_fderiv_within_at_iff
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff
lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x :=
(iso : E ≃L[𝕜] F).comp_has_strict_fderiv_at_iff
lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff
lemma comp_has_fderiv_within_at_iff'
{f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_within_at (iso ∘ f) f' s x ↔
has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff'
lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x :=
(iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff'
lemma comp_fderiv_within {f : G → E} {s : set G} {x : G}
(hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) :=
(iso : E ≃L[𝕜] F).comp_fderiv_within hxs
lemma comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) :=
(iso : E ≃L[𝕜] F).comp_fderiv
end linear_isometry_equiv
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a`
in the strict sense.
This is one of the easy parts of the inverse function theorem: it assumes that we already have an
inverse function. -/
theorem has_strict_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}
(hg : continuous_at g a) (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) (g a))
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_strict_fderiv_at g (f'.symm : F →L[𝕜] E) a :=
begin
replace hg := hg.prod_map' hg,
replace hfg := hfg.prod_mk_nhds hfg,
have : is_O (λ p : F × F, g p.1 - g p.2 - f'.symm (p.1 - p.2))
(λ p : F × F, f' (g p.1 - g p.2) - (p.1 - p.2)) (𝓝 (a, a)),
{ refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl),
simp },
refine this.trans_is_o _, clear this,
refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _)
(eventually_of_forall $ λ _, rfl)).trans_is_O _,
{ rintros p ⟨hp1, hp2⟩,
simp [hp1, hp2] },
{ refine (hf.is_O_sub_rev.comp_tendsto hg).congr'
(eventually_of_forall $ λ _, rfl) (hfg.mono _),
rintros p ⟨hp1, hp2⟩,
simp only [(∘), hp1, hp2] }
end
/-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an
invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
theorem has_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}
(hg : continuous_at g a) (hf : has_fderiv_at f (f' : E →L[𝕜] F) (g a))
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_fderiv_at g (f'.symm : F →L[𝕜] E) a :=
begin
have : is_O (λ x : F, g x - g a - f'.symm (x - a)) (λ x : F, f' (g x - g a) - (x - a)) (𝓝 a),
{ refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl),
simp },
refine this.trans_is_o _, clear this,
refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _)
(eventually_of_forall $ λ _, rfl)).trans_is_O _,
{ rintros p hp,
simp [hp, hfg.self_of_nhds] },
{ refine (hf.is_O_sub_rev.comp_tendsto hg).congr'
(eventually_of_forall $ λ _, rfl) (hfg.mono _),
rintros p hp,
simp only [(∘), hp, hfg.self_of_nhds] }
end
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
invertible derivative `f'` in the sense of strict differentiability at `f.symm a`, then `f.symm` has
the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
lemma local_homeomorph.has_strict_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F}
(ha : a ∈ f.target) (htff' : has_strict_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) :
has_strict_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha)
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
invertible derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`.
This is one of the easy parts of the inverse function theorem: it assumes that we already have
an inverse function. -/
lemma local_homeomorph.has_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F}
(ha : a ∈ f.target) (htff' : has_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) :
has_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha)
lemma has_fderiv_within_at.eventually_ne (h : has_fderiv_within_at f f' s x)
(hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) :
∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ f x :=
begin
rw [nhds_within, diff_eq, ← inf_principal, ← inf_assoc, eventually_inf_principal],
have A : is_O (λ z, z - x) (λ z, f' (z - x)) (𝓝[s] x) :=
(is_O_iff.2 $ hf'.imp $ λ C hC, eventually_of_forall $ λ z, hC _),
have : (λ z, f z - f x) ~[𝓝[s] x] (λ z, f' (z - x)) := h.trans_is_O A,
simpa [not_imp_not, sub_eq_zero] using (A.trans this.is_O_symm).eq_zero_imp
end
lemma has_fderiv_at.eventually_ne (h : has_fderiv_at f f' x) (hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) :
∀ᶠ z in 𝓝[{x}ᶜ] x, f z ≠ f x :=
by simpa only [compl_eq_univ_diff] using (has_fderiv_within_at_univ.2 h).eventually_ne hf'
end
section
/-
In the special case of a normed space over the reals,
we can use scalar multiplication in the `tendsto` characterization
of the Fréchet derivative.
-/
variables {E : Type*} [normed_group E] [normed_space ℝ E]
variables {F : Type*} [normed_group F] [normed_space ℝ F]
variables {f : E → F} {f' : E →L[ℝ] F} {x : E}
theorem has_fderiv_at_filter_real_equiv {L : filter E} :
tendsto (λ x' : E, ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) ↔
tendsto (λ x' : E, ∥x' - x∥⁻¹ • (f x' - f x - f' (x' - x))) L (𝓝 0) :=
begin
symmetry,
rw [tendsto_iff_norm_tendsto_zero], refine tendsto_congr (λ x', _),
have : ∥x' - x∥⁻¹ ≥ 0, from inv_nonneg.mpr (norm_nonneg _),
simp [norm_smul, real.norm_eq_abs, abs_of_nonneg this]
end
lemma has_fderiv_at.lim_real (hf : has_fderiv_at f f' x) (v : E) :
tendsto (λ (c:ℝ), c • (f (x + c⁻¹ • v) - f x)) at_top (𝓝 (f' v)) :=
begin
apply hf.lim v,
rw tendsto_at_top_at_top,
exact λ b, ⟨b, λ a ha, le_trans ha (le_abs_self _)⟩
end
end
section tangent_cone
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{F : Type*} [normed_group F] [normed_space 𝕜 F]
{f : E → F} {s : set E} {f' : E →L[𝕜] F}
/-- The image of a tangent cone under the differential of a map is included in the tangent cone to
the image. -/
lemma has_fderiv_within_at.maps_to_tangent_cone {x : E} (h : has_fderiv_within_at f f' s x) :
maps_to f' (tangent_cone_at 𝕜 s x) (tangent_cone_at 𝕜 (f '' s) (f x)) :=
begin
rintros v ⟨c, d, dtop, clim, cdlim⟩,
refine ⟨c, (λn, f (x + d n) - f x), mem_of_superset dtop _, clim,
h.lim at_top dtop clim cdlim⟩,
simp [-mem_image, mem_image_of_mem] {contextual := tt}
end
/-- If a set has the unique differentiability property at a point x, then the image of this set
under a map with onto derivative has also the unique differentiability property at the image point.
-/
lemma has_fderiv_within_at.unique_diff_within_at {x : E} (h : has_fderiv_within_at f f' s x)
(hs : unique_diff_within_at 𝕜 s x) (h' : dense_range f') :
unique_diff_within_at 𝕜 (f '' s) (f x) :=
begin
refine ⟨h'.dense_of_maps_to f'.continuous hs.1 _,
h.continuous_within_at.mem_closure_image hs.2⟩,
show submodule.span 𝕜 (tangent_cone_at 𝕜 s x) ≤
(submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x))).comap f',
rw [submodule.span_le],
exact h.maps_to_tangent_cone.mono (subset.refl _) submodule.subset_span
end
lemma unique_diff_on.image {f' : E → E →L[𝕜] F} (hs : unique_diff_on 𝕜 s)
(hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hd : ∀ x ∈ s, dense_range (f' x)) :
unique_diff_on 𝕜 (f '' s) :=
ball_image_iff.2 $ λ x hx, (hf' x hx).unique_diff_within_at (hs x hx) (hd x hx)
lemma has_fderiv_within_at.unique_diff_within_at_of_continuous_linear_equiv
{x : E} (e' : E ≃L[𝕜] F) (h : has_fderiv_within_at f (e' : E →L[𝕜] F) s x)
(hs : unique_diff_within_at 𝕜 s x) :
unique_diff_within_at 𝕜 (f '' s) (f x) :=
h.unique_diff_within_at hs e'.surjective.dense_range
lemma continuous_linear_equiv.unique_diff_on_image (e : E ≃L[𝕜] F) (h : unique_diff_on 𝕜 s) :
unique_diff_on 𝕜 (e '' s) :=
h.image (λ x _, e.has_fderiv_within_at) (λ x hx, e.surjective.dense_range)
@[simp] lemma continuous_linear_equiv.unique_diff_on_image_iff (e : E ≃L[𝕜] F) :
unique_diff_on 𝕜 (e '' s) ↔ unique_diff_on 𝕜 s :=
⟨λ h, e.symm_image_image s ▸ e.symm.unique_diff_on_image h, e.unique_diff_on_image⟩
@[simp] lemma continuous_linear_equiv.unique_diff_on_preimage_iff (e : F ≃L[𝕜] E) :
unique_diff_on 𝕜 (e ⁻¹' s) ↔ unique_diff_on 𝕜 s :=
by rw [← e.image_symm_eq_preimage, e.symm.unique_diff_on_image_iff]
end tangent_cone
section restrict_scalars
/-!
### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜`
If a function is differentiable over `ℂ`, then it is differentiable over `ℝ`. In this paragraph,
we give variants of this statement, in the general situation where `ℂ` and `ℝ` are replaced
respectively by `𝕜'` and `𝕜` where `𝕜'` is a normed algebra over `𝕜`.
-/
variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
variables {E : Type*} [normed_group E] [normed_space 𝕜 E] [normed_space 𝕜' E]
variables [is_scalar_tower 𝕜 𝕜' E]
variables {F : Type*} [normed_group F] [normed_space 𝕜 F] [normed_space 𝕜' F]
variables [is_scalar_tower 𝕜 𝕜' F]
variables {f : E → F} {f' : E →L[𝕜'] F} {s : set E} {x : E}
lemma has_strict_fderiv_at.restrict_scalars (h : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at f (f'.restrict_scalars 𝕜) x := h
lemma has_fderiv_at.restrict_scalars (h : has_fderiv_at f f' x) :
has_fderiv_at f (f'.restrict_scalars 𝕜) x := h
lemma has_fderiv_within_at.restrict_scalars (h : has_fderiv_within_at f f' s x) :
has_fderiv_within_at f (f'.restrict_scalars 𝕜) s x := h
lemma differentiable_at.restrict_scalars (h : differentiable_at 𝕜' f x) :
differentiable_at 𝕜 f x :=
(h.has_fderiv_at.restrict_scalars 𝕜).differentiable_at
lemma differentiable_within_at.restrict_scalars (h : differentiable_within_at 𝕜' f s x) :
differentiable_within_at 𝕜 f s x :=
(h.has_fderiv_within_at.restrict_scalars 𝕜).differentiable_within_at
lemma differentiable_on.restrict_scalars (h : differentiable_on 𝕜' f s) :
differentiable_on 𝕜 f s :=
λx hx, (h x hx).restrict_scalars 𝕜
lemma differentiable.restrict_scalars (h : differentiable 𝕜' f) :
differentiable 𝕜 f :=
λx, (h x).restrict_scalars 𝕜
lemma has_fderiv_within_at_of_restrict_scalars
{g' : E →L[𝕜] F} (h : has_fderiv_within_at f g' s x)
(H : f'.restrict_scalars 𝕜 = g') : has_fderiv_within_at f f' s x :=
by { rw ← H at h, exact h }
lemma has_fderiv_at_of_restrict_scalars {g' : E →L[𝕜] F} (h : has_fderiv_at f g' x)
(H : f'.restrict_scalars 𝕜 = g') : has_fderiv_at f f' x :=
by { rw ← H at h, exact h }
lemma differentiable_at.fderiv_restrict_scalars (h : differentiable_at 𝕜' f x) :
fderiv 𝕜 f x = (fderiv 𝕜' f x).restrict_scalars 𝕜 :=
(h.has_fderiv_at.restrict_scalars 𝕜).fderiv
lemma differentiable_within_at_iff_restrict_scalars
(hf : differentiable_within_at 𝕜 f s x) (hs : unique_diff_within_at 𝕜 s x) :
differentiable_within_at 𝕜' f s x ↔
∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv_within 𝕜 f s x :=
begin
split,
{ rintros ⟨g', hg'⟩,
exact ⟨g', hs.eq (hg'.restrict_scalars 𝕜) hf.has_fderiv_within_at⟩, },
{ rintros ⟨f', hf'⟩,
exact ⟨f', has_fderiv_within_at_of_restrict_scalars 𝕜 hf.has_fderiv_within_at hf'⟩, },
end
lemma differentiable_at_iff_restrict_scalars (hf : differentiable_at 𝕜 f x) :
differentiable_at 𝕜' f x ↔ ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv 𝕜 f x :=
begin
rw [← differentiable_within_at_univ, ← fderiv_within_univ],
exact differentiable_within_at_iff_restrict_scalars 𝕜
hf.differentiable_within_at unique_diff_within_at_univ,
end
end restrict_scalars
|
2ea4dc2aeb2be6b8b190a8173a8b178f382a47f4 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/group_theory/eckmann_hilton.lean | 52244f77ad55183439a9b8cdb0784909cad3f78d | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,322 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau, Robert Y. Lewis
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.group.basic
import Mathlib.PostPort
universes u l
namespace Mathlib
/-!
# Eckmann-Hilton argument
The Eckmann-Hilton argument says that if a type carries two monoid structures that distribute
over one another, then they are equal, and in addition commutative.
The main application lies in proving that higher homotopy groups (`πₙ` for `n ≥ 2`) are commutative.
## Main declarations
* `eckmann_hilton.comm_monoid`: If a type carries two unital binary operations that distribute
over each other, then these operations are equal, and form a commutative monoid structure.
* `eckmann_hilton.comm_group`: If a type carries a group structure that distributes
over a unital binary operation, then the group is commutative.
-/
namespace eckmann_hilton
/-- `is_unital m e` expresses that `e : X` is a left and right unit
for the binary operation `m : X → X → X`. -/
class is_unital {X : Type u} (m : X → X → X) (e : X)
where
one_mul : ∀ (x : X), m e x = x
mul_one : ∀ (x : X), m x e = x
theorem Mathlib.add_group.is_unital {X : Type u} [G : add_group X] : is_unital Add.add 0 :=
is_unital.mk add_group.zero_add add_group.add_zero
/-- If a type carries two unital binary operations that distribute over each other,
then they have the same unit elements.
In fact, the two operations are the same, and give a commutative monoid structure,
see `eckmann_hilton.comm_monoid`. -/
theorem one {X : Type u} {m₁ : X → X → X} {m₂ : X → X → X} {e₁ : X} {e₂ : X} (h₁ : is_unital m₁ e₁) (h₂ : is_unital m₂ e₂) (distrib : ∀ (a b c d : X), m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) : e₁ = e₂ := sorry
/-- If a type carries two unital binary operations that distribute over each other,
then these operations are equal.
In fact, they give a commutative monoid structure, see `eckmann_hilton.comm_monoid`. -/
theorem mul {X : Type u} {m₁ : X → X → X} {m₂ : X → X → X} {e₁ : X} {e₂ : X} (h₁ : is_unital m₁ e₁) (h₂ : is_unital m₂ e₂) (distrib : ∀ (a b c d : X), m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) : m₁ = m₂ := sorry
/-- If a type carries two unital binary operations that distribute over each other,
then these operations are commutative.
In fact, they give a commutative monoid structure, see `eckmann_hilton.comm_monoid`. -/
theorem mul_comm {X : Type u} {m₁ : X → X → X} {m₂ : X → X → X} {e₁ : X} {e₂ : X} (h₁ : is_unital m₁ e₁) (h₂ : is_unital m₂ e₂) (distrib : ∀ (a b c d : X), m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) : is_commutative X m₂ := sorry
/-- If a type carries two unital binary operations that distribute over each other,
then these operations are associative.
In fact, they give a commutative monoid structure, see `eckmann_hilton.comm_monoid`. -/
theorem mul_assoc {X : Type u} {m₁ : X → X → X} {m₂ : X → X → X} {e₁ : X} {e₂ : X} (h₁ : is_unital m₁ e₁) (h₂ : is_unital m₂ e₂) (distrib : ∀ (a b c d : X), m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) : is_associative X m₂ := sorry
/-- If a type carries two unital binary operations that distribute over each other,
then these operations are equal, and form a commutative monoid structure. -/
def comm_monoid {X : Type u} {m₁ : X → X → X} {m₂ : X → X → X} {e₁ : X} {e₂ : X} (h₁ : is_unital m₁ e₁) (h₂ : is_unital m₂ e₂) (distrib : ∀ (a b c d : X), m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) : comm_monoid X :=
comm_monoid.mk m₂ sorry e₂ is_unital.one_mul is_unital.mul_one sorry
/-- If a type carries a group structure that distributes over a unital binary operation,
then the group is commutative. -/
def comm_group {X : Type u} {m₁ : X → X → X} {e₁ : X} (h₁ : is_unital m₁ e₁) [G : group X] (distrib : ∀ (a b c d : X), m₁ (a * b) (c * d) = m₁ a c * m₁ b d) : comm_group X :=
comm_group.mk group.mul group.mul_assoc group.one group.one_mul group.mul_one group.inv group.div group.mul_left_inv
sorry
|
231780f5a3f3e21bc821251af3d4a0bbf53faf57 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/analysis/complex/real_deriv.lean | 9f40a3dcf68f635a1988c9eef914552b7a0642b4 | [
"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 | 7,352 | lean | /-
Copyright (c) Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yourong Zang
-/
import analysis.calculus.cont_diff
import analysis.complex.conformal
import analysis.calculus.conformal.normed_space
/-! # Real differentiability of complex-differentiable functions
`has_deriv_at.real_of_complex` expresses that, if a function on `ℂ` is differentiable (over `ℂ`),
then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the
complex derivative.
`differentiable_at.conformal_at` states that a real-differentiable function with a nonvanishing
differential from the complex plane into an arbitrary complex-normed space is conformal at a point
if it's holomorphic at that point. This is a version of Cauchy-Riemann equations.
`conformal_at_iff_differentiable_at_or_differentiable_at_comp_conj` proves that a real-differential
function with a nonvanishing differential between the complex plane is conformal at a point if and
only if it's holomorphic or antiholomorphic at that point.
## TODO
* The classical form of Cauchy-Riemann equations
* On a connected open set `u`, a function which is `conformal_at` each point is either holomorphic
throughout or antiholomorphic throughout.
## Warning
We do NOT require conformal functions to be orientation-preserving in this file.
-/
section real_deriv_of_complex
/-! ### Differentiability of the restriction to `ℝ` of complex functions -/
open complex
variables {e : ℂ → ℂ} {e' : ℂ} {z : ℝ}
/-- If a complex function is differentiable at a real point, then the induced real function is also
differentiable at this point, with a derivative equal to the real part of the complex derivative. -/
theorem has_strict_deriv_at.real_of_complex (h : has_strict_deriv_at e e' z) :
has_strict_deriv_at (λx:ℝ, (e x).re) e'.re z :=
begin
have A : has_strict_fderiv_at (coe : ℝ → ℂ) of_real_clm z := of_real_clm.has_strict_fderiv_at,
have B : has_strict_fderiv_at e
((continuous_linear_map.smul_right 1 e' : ℂ →L[ℂ] ℂ).restrict_scalars ℝ)
(of_real_clm z) :=
h.has_strict_fderiv_at.restrict_scalars ℝ,
have C : has_strict_fderiv_at re re_clm (e (of_real_clm z)) := re_clm.has_strict_fderiv_at,
simpa using (C.comp z (B.comp z A)).has_strict_deriv_at
end
/-- If a complex function is differentiable at a real point, then the induced real function is also
differentiable at this point, with a derivative equal to the real part of the complex derivative. -/
theorem has_deriv_at.real_of_complex (h : has_deriv_at e e' z) :
has_deriv_at (λx:ℝ, (e x).re) e'.re z :=
begin
have A : has_fderiv_at (coe : ℝ → ℂ) of_real_clm z := of_real_clm.has_fderiv_at,
have B : has_fderiv_at e ((continuous_linear_map.smul_right 1 e' : ℂ →L[ℂ] ℂ).restrict_scalars ℝ)
(of_real_clm z) :=
h.has_fderiv_at.restrict_scalars ℝ,
have C : has_fderiv_at re re_clm (e (of_real_clm z)) := re_clm.has_fderiv_at,
simpa using (C.comp z (B.comp z A)).has_deriv_at
end
theorem cont_diff_at.real_of_complex {n : with_top ℕ} (h : cont_diff_at ℂ n e z) :
cont_diff_at ℝ n (λ x : ℝ, (e x).re) z :=
begin
have A : cont_diff_at ℝ n (coe : ℝ → ℂ) z,
from of_real_clm.cont_diff.cont_diff_at,
have B : cont_diff_at ℝ n e z := h.restrict_scalars ℝ,
have C : cont_diff_at ℝ n re (e z), from re_clm.cont_diff.cont_diff_at,
exact C.comp z (B.comp z A)
end
theorem cont_diff.real_of_complex {n : with_top ℕ} (h : cont_diff ℂ n e) :
cont_diff ℝ n (λ x : ℝ, (e x).re) :=
cont_diff_iff_cont_diff_at.2 $ λ x,
h.cont_diff_at.real_of_complex
variables {E : Type*} [normed_add_comm_group E] [normed_space ℂ E]
lemma has_strict_deriv_at.complex_to_real_fderiv' {f : ℂ → E} {x : ℂ} {f' : E}
(h : has_strict_deriv_at f f' x) :
has_strict_fderiv_at f (re_clm.smul_right f' + I • im_clm.smul_right f') x :=
by simpa only [complex.restrict_scalars_one_smul_right']
using h.has_strict_fderiv_at.restrict_scalars ℝ
lemma has_deriv_at.complex_to_real_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : has_deriv_at f f' x) :
has_fderiv_at f (re_clm.smul_right f' + I • im_clm.smul_right f') x :=
by simpa only [complex.restrict_scalars_one_smul_right']
using h.has_fderiv_at.restrict_scalars ℝ
lemma has_deriv_within_at.complex_to_real_fderiv' {f : ℂ → E} {s : set ℂ} {x : ℂ} {f' : E}
(h : has_deriv_within_at f f' s x) :
has_fderiv_within_at f (re_clm.smul_right f' + I • im_clm.smul_right f') s x :=
by simpa only [complex.restrict_scalars_one_smul_right']
using h.has_fderiv_within_at.restrict_scalars ℝ
lemma has_strict_deriv_at.complex_to_real_fderiv {f : ℂ → ℂ} {f' x : ℂ}
(h : has_strict_deriv_at f f' x) :
has_strict_fderiv_at f (f' • (1 : ℂ →L[ℝ] ℂ)) x :=
by simpa only [complex.restrict_scalars_one_smul_right]
using h.has_strict_fderiv_at.restrict_scalars ℝ
lemma has_deriv_at.complex_to_real_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : has_deriv_at f f' x) :
has_fderiv_at f (f' • (1 : ℂ →L[ℝ] ℂ)) x :=
by simpa only [complex.restrict_scalars_one_smul_right]
using h.has_fderiv_at.restrict_scalars ℝ
lemma has_deriv_within_at.complex_to_real_fderiv {f : ℂ → ℂ} {s : set ℂ} {f' x : ℂ}
(h : has_deriv_within_at f f' s x) :
has_fderiv_within_at f (f' • (1 : ℂ →L[ℝ] ℂ)) s x :=
by simpa only [complex.restrict_scalars_one_smul_right]
using h.has_fderiv_within_at.restrict_scalars ℝ
end real_deriv_of_complex
section conformality
/-! ### Conformality of real-differentiable complex maps -/
open complex continuous_linear_map
open_locale complex_conjugate
variables {E : Type*} [normed_add_comm_group E] [normed_space ℂ E] {z : ℂ} {f : ℂ → E}
/-- A real differentiable function of the complex plane into some complex normed space `E` is
conformal at a point `z` if it is holomorphic at that point with a nonvanishing differential.
This is a version of the Cauchy-Riemann equations. -/
lemma differentiable_at.conformal_at (h : differentiable_at ℂ f z) (hf' : deriv f z ≠ 0) :
conformal_at f z :=
begin
rw [conformal_at_iff_is_conformal_map_fderiv, (h.has_fderiv_at.restrict_scalars ℝ).fderiv],
apply is_conformal_map_complex_linear,
simpa only [ne.def, ext_ring_iff]
end
/-- A complex function is conformal if and only if the function is holomorphic or antiholomorphic
with a nonvanishing differential. -/
lemma conformal_at_iff_differentiable_at_or_differentiable_at_comp_conj {f : ℂ → ℂ} {z : ℂ} :
conformal_at f z ↔
(differentiable_at ℂ f z ∨ differentiable_at ℂ (f ∘ conj) (conj z)) ∧ fderiv ℝ f z ≠ 0 :=
begin
rw conformal_at_iff_is_conformal_map_fderiv,
rw is_conformal_map_iff_is_complex_or_conj_linear,
apply and_congr_left,
intros h,
have h_diff := h.imp_symm fderiv_zero_of_not_differentiable_at,
apply or_congr,
{ rw differentiable_at_iff_restrict_scalars ℝ h_diff },
rw ← conj_conj z at h_diff,
rw differentiable_at_iff_restrict_scalars ℝ (h_diff.comp _ conj_cle.differentiable_at),
refine exists_congr (λ g, rfl.congr _),
have : fderiv ℝ conj (conj z) = _ := conj_cle.fderiv,
simp [fderiv.comp _ h_diff conj_cle.differentiable_at, this, conj_conj],
end
end conformality
|
453db54e9272fef42aa0401f74aaa2a010746199 | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/linear_algebra/matrix/reindex.lean | 8810099d1eb552d2f5ca9ff85dc71f37533e0aa8 | [
"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 | 3,968 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import linear_algebra.matrix.determinant
/-!
# Changing the index type of a matrix
This file concerns the map `matrix.reindex`, mapping a `m` by `n` matrix
to an `m'` by `n'` matrix, as long as `m ≃ m'` and `n ≃ n'`.
## Main definitions
* `matrix.reindex_linear_equiv`: `matrix.reindex` is a linear equivalence
* `matrix.reindex_alg_equiv`: `matrix.reindex` is a algebra equivalence
## Tags
matrix, reindex
-/
namespace matrix
open_locale matrix
variables {l m n : Type*} [fintype l] [fintype m] [fintype n]
variables {l' m' n' : Type*} [fintype l'] [fintype m'] [fintype n']
variables {R : Type*}
/-- The natural map that reindexes a matrix's rows and columns with equivalent types,
`matrix.reindex`, is a linear equivalence. -/
def reindex_linear_equiv [semiring R] (eₘ : m ≃ m') (eₙ : n ≃ n') :
matrix m n R ≃ₗ[R] matrix m' n' R :=
{ map_add' := λ M N, rfl,
map_smul' := λ M N, rfl,
..(reindex eₘ eₙ)}
@[simp] lemma reindex_linear_equiv_apply [semiring R]
(eₘ : m ≃ m') (eₙ : n ≃ n') (M : matrix m n R) :
reindex_linear_equiv eₘ eₙ M = reindex eₘ eₙ M :=
rfl
@[simp] lemma reindex_linear_equiv_symm [semiring R] (eₘ : m ≃ m') (eₙ : n ≃ n') :
(reindex_linear_equiv eₘ eₙ : _ ≃ₗ[R] _).symm = reindex_linear_equiv eₘ.symm eₙ.symm :=
rfl
@[simp] lemma reindex_linear_equiv_refl_refl [semiring R] :
reindex_linear_equiv (equiv.refl m) (equiv.refl n) = linear_equiv.refl R _ :=
linear_equiv.ext $ λ _, rfl
lemma reindex_linear_equiv_mul {o o' : Type*} [fintype o] [fintype o'] [semiring R]
(eₘ : m ≃ m') (eₙ : n ≃ n') (eₒ : o ≃ o') (M : matrix m n R) (N : matrix n o R) :
reindex_linear_equiv eₘ eₒ (M ⬝ N) =
reindex_linear_equiv eₘ eₙ M ⬝ reindex_linear_equiv eₙ eₒ N :=
minor_mul_equiv M N _ _ _
/-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent
types, `matrix.reindex`, is an equivalence of algebras. -/
def reindex_alg_equiv [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) : matrix m m R ≃ₐ[R] matrix n n R :=
{ to_fun := reindex e e,
map_mul' := reindex_linear_equiv_mul e e e,
commutes' := λ r, by simp [algebra_map, algebra.to_ring_hom, minor_smul],
..(reindex_linear_equiv e e) }
@[simp] lemma reindex_alg_equiv_apply [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) (M : matrix m m R) :
reindex_alg_equiv e M = reindex e e M :=
rfl
@[simp] lemma reindex_alg_equiv_symm [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) :
(reindex_alg_equiv e : _ ≃ₐ[R] _).symm = reindex_alg_equiv e.symm :=
rfl
@[simp] lemma reindex_alg_equiv_refl [comm_semiring R] [decidable_eq m] :
reindex_alg_equiv (equiv.refl m) = (alg_equiv.refl : _ ≃ₐ[R] _) :=
alg_equiv.ext $ λ _, rfl
lemma reindex_alg_equiv_mul [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) (M : matrix m m R) (N : matrix m m R) :
reindex_alg_equiv e (M ⬝ N) = reindex_alg_equiv e M ⬝ reindex_alg_equiv e N :=
(reindex_alg_equiv e).map_mul M N
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_minor_equiv_self`.
-/
lemma det_reindex_linear_equiv_self [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m ≃ n) (A : matrix m m R) :
det (reindex_linear_equiv e e A) = det A :=
det_reindex_self e A
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_minor_equiv_self`.
-/
lemma det_reindex_alg_equiv [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m ≃ n) (A : matrix m m R) :
det (reindex_alg_equiv e A) = det A :=
det_reindex_self e A
end matrix
|
a6385fd42f6c473a6fcd4db53654cc7294a4e0bb | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/linear_algebra/exterior_algebra/basic.lean | 38a0b71a4e7ae5548ab66a1e3583d8e60f9d9be3 | [
"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 | 10,490 | lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhangir Azerbayev, Adam Topaz, Eric Wieser
-/
import algebra.ring_quot
import linear_algebra.clifford_algebra.basic
import linear_algebra.alternating
import group_theory.perm.sign
/-!
# Exterior Algebras
We construct the exterior algebra of a module `M` over a commutative semiring `R`.
## Notation
The exterior algebra of the `R`-module `M` is denoted as `exterior_algebra R M`.
It is endowed with the structure of an `R`-algebra.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m : M, f m * f m = 0`, there is a (unique) lift of `f` to an `R`-algebra morphism,
which is denoted `exterior_algebra.lift R f cond`.
The canonical linear map `M → exterior_algebra R M` is denoted `exterior_algebra.ι R`.
## Theorems
The main theorems proved ensure that `exterior_algebra R M` satisfies the universal property
of the exterior algebra.
1. `ι_comp_lift` is fact that the composition of `ι R` with `lift R f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift R f cond` with respect to 1.
## Definitions
* `ι_multi` is the `alternating_map` corresponding to the wedge product of `ι R m` terms.
## Implementation details
The exterior algebra of `M` is constructed as simply `clifford_algebra (0 : quadratic_form R M)`,
as this avoids us having to duplicate API.
-/
universes u1 u2 u3
variables (R : Type u1) [comm_ring R]
variables (M : Type u2) [add_comm_group M] [module R M]
/--
The exterior algebra of an `R`-module `M`.
-/
@[reducible]
def exterior_algebra := clifford_algebra (0 : quadratic_form R M)
namespace exterior_algebra
variables {M}
/--
The canonical linear map `M →ₗ[R] exterior_algebra R M`.
-/
@[reducible] def ι : M →ₗ[R] exterior_algebra R M := by exact clifford_algebra.ι _
variables {R}
/-- As well as being linear, `ι m` squares to zero -/
@[simp]
theorem ι_sq_zero (m : M) : (ι R m) * (ι R m) = 0 :=
(clifford_algebra.ι_sq_scalar _ m).trans $ map_zero _
variables {A : Type*} [semiring A] [algebra R A]
@[simp]
theorem comp_ι_sq_zero (g : exterior_algebra R M →ₐ[R] A)
(m : M) : g (ι R m) * g (ι R m) = 0 :=
by rw [←alg_hom.map_mul, ι_sq_zero, alg_hom.map_zero]
variables (R)
/--
Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = 0`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `exterior_algebra R M` to `A`.
-/
@[simps symm_apply]
def lift : {f : M →ₗ[R] A // ∀ m, f m * f m = 0} ≃ (exterior_algebra R M →ₐ[R] A) :=
equiv.trans (equiv.subtype_equiv (equiv.refl _) $ by simp) $ clifford_algebra.lift _
@[simp]
theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) :
(lift R ⟨f, cond⟩).to_linear_map.comp (ι R) = f :=
clifford_algebra.ι_comp_lift f _
@[simp]
theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (x) :
lift R ⟨f, cond⟩ (ι R x) = f x :=
clifford_algebra.lift_ι_apply f _ x
@[simp]
theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0)
(g : exterior_algebra R M →ₐ[R] A) : g.to_linear_map.comp (ι R) = f ↔ g = lift R ⟨f, cond⟩ :=
clifford_algebra.lift_unique f _ _
variables {R M}
@[simp]
theorem lift_comp_ι (g : exterior_algebra R M →ₐ[R] A) :
lift R ⟨g.to_linear_map.comp (ι R), comp_ι_sq_zero _⟩ = g :=
clifford_algebra.lift_comp_ι g
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {f g : exterior_algebra R M →ₐ[R] A}
(h : f.to_linear_map.comp (ι R) = g.to_linear_map.comp (ι R)) : f = g :=
clifford_algebra.hom_ext h
/-- If `C` holds for the `algebra_map` of `r : R` into `exterior_algebra R M`, the `ι` of `x : M`,
and is preserved under addition and muliplication, then it holds for all of `exterior_algebra R M`.
-/
@[elab_as_eliminator]
lemma induction {C : exterior_algebra R M → Prop}
(h_grade0 : ∀ r, C (algebra_map R (exterior_algebra R M) r))
(h_grade1 : ∀ x, C (ι R x))
(h_mul : ∀ a b, C a → C b → C (a * b))
(h_add : ∀ a b, C a → C b → C (a + b))
(a : exterior_algebra R M) :
C a :=
clifford_algebra.induction h_grade0 h_grade1 h_mul h_add a
/-- The left-inverse of `algebra_map`. -/
def algebra_map_inv : exterior_algebra R M →ₐ[R] R :=
exterior_algebra.lift R ⟨(0 : M →ₗ[R] R), λ m, by simp⟩
variables (M)
lemma algebra_map_left_inverse :
function.left_inverse algebra_map_inv (algebra_map R $ exterior_algebra R M) :=
λ x, by simp [algebra_map_inv]
@[simp] lemma algebra_map_inj (x y : R) :
algebra_map R (exterior_algebra R M) x = algebra_map R (exterior_algebra R M) y ↔ x = y :=
(algebra_map_left_inverse M).injective.eq_iff
@[simp] lemma algebra_map_eq_zero_iff (x : R) :
algebra_map R (exterior_algebra R M) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebra_map _ _) (algebra_map_left_inverse _).injective
@[simp] lemma algebra_map_eq_one_iff (x : R) : algebra_map R (exterior_algebra R M) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebra_map _ _) (algebra_map_left_inverse _).injective
variables {M}
/-- The canonical map from `exterior_algebra R M` into `triv_sq_zero_ext R M` that sends
`exterior_algebra.ι` to `triv_sq_zero_ext.inr`. -/
def to_triv_sq_zero_ext : exterior_algebra R M →ₐ[R] triv_sq_zero_ext R M :=
lift R ⟨triv_sq_zero_ext.inr_hom R M, λ m, triv_sq_zero_ext.inr_mul_inr R m m⟩
@[simp] lemma to_triv_sq_zero_ext_ι (x : M) :
to_triv_sq_zero_ext (ι R x) = triv_sq_zero_ext.inr x :=
lift_ι_apply _ _ _ _
/-- The left-inverse of `ι`.
As an implementation detail, we implement this using `triv_sq_zero_ext` which has a suitable
algebra structure. -/
def ι_inv : exterior_algebra R M →ₗ[R] M :=
(triv_sq_zero_ext.snd_hom R M).comp to_triv_sq_zero_ext.to_linear_map
lemma ι_left_inverse : function.left_inverse ι_inv (ι R : M → exterior_algebra R M) :=
λ x, by simp [ι_inv]
variables (R)
@[simp] lemma ι_inj (x y : M) : ι R x = ι R y ↔ x = y :=
ι_left_inverse.injective.eq_iff
variables {R}
@[simp] lemma ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 :=
by rw [←ι_inj R x 0, linear_map.map_zero]
@[simp] lemma ι_eq_algebra_map_iff (x : M) (r : R) : ι R x = algebra_map R _ r ↔ x = 0 ∧ r = 0 :=
begin
refine ⟨λ h, _, _⟩,
{ have hf0 : to_triv_sq_zero_ext (ι R x) = (0, x), from to_triv_sq_zero_ext_ι _,
rw [h, alg_hom.commutes] at hf0,
have : r = 0 ∧ 0 = x := prod.ext_iff.1 hf0,
exact this.symm.imp_left eq.symm, },
{ rintro ⟨rfl, rfl⟩,
rw [linear_map.map_zero, ring_hom.map_zero] }
end
@[simp] lemma ι_ne_one [nontrivial R] (x : M) : ι R x ≠ 1 :=
begin
rw [←(algebra_map R (exterior_algebra R M)).map_one, ne.def, ι_eq_algebra_map_iff],
exact one_ne_zero ∘ and.right,
end
/-- The generators of the exterior algebra are disjoint from its scalars. -/
lemma ι_range_disjoint_one : disjoint (ι R).range (1 : submodule R (exterior_algebra R M)) :=
begin
rw submodule.disjoint_def,
rintros _ ⟨x, hx⟩ ⟨r, (rfl : algebra_map _ _ _ = _)⟩,
rw ι_eq_algebra_map_iff x at hx,
rw [hx.2, ring_hom.map_zero]
end
@[simp]
lemma ι_add_mul_swap (x y : M) : ι R x * ι R y + ι R y * ι R x = 0 :=
calc _ = ι R (x + y) * ι R (x + y) : by simp [mul_add, add_mul]
... = _ : ι_sq_zero _
lemma ι_mul_prod_list {n : ℕ} (f : fin n → M) (i : fin n) :
(ι R $ f i) * (list.of_fn $ λ i, ι R $ f i).prod = 0 :=
begin
induction n with n hn,
{ exact i.elim0, },
{ rw [list.of_fn_succ, list.prod_cons, ←mul_assoc],
by_cases h : i = 0,
{ rw [h, ι_sq_zero, zero_mul], },
{ replace hn := congr_arg ((*) $ ι R $ f 0) (hn (λ i, f $ fin.succ i) (i.pred h)),
simp only at hn,
rw [fin.succ_pred, ←mul_assoc, mul_zero] at hn,
refine (eq_zero_iff_eq_zero_of_add_eq_zero _).mp hn,
rw [← add_mul, ι_add_mul_swap, zero_mul], } }
end
variables (R)
/-- The product of `n` terms of the form `ι R m` is an alternating map.
This is a special case of `multilinear_map.mk_pi_algebra_fin`, and the exterior algebra version of
`tensor_algebra.tprod`. -/
def ι_multi (n : ℕ) : alternating_map R M (exterior_algebra R M) (fin n) :=
let F := (multilinear_map.mk_pi_algebra_fin R n (exterior_algebra R M)).comp_linear_map (λ i, ι R)
in
{ map_eq_zero_of_eq' := λ f x y hfxy hxy, begin
rw [multilinear_map.comp_linear_map_apply, multilinear_map.mk_pi_algebra_fin_apply],
wlog h : x < y := lt_or_gt_of_ne hxy using x y,
clear hxy,
induction n with n hn generalizing x y,
{ exact x.elim0, },
{ rw [list.of_fn_succ, list.prod_cons],
by_cases hx : x = 0,
-- one of the repeated terms is on the left
{ rw hx at hfxy h,
rw [hfxy, ←fin.succ_pred y (ne_of_lt h).symm],
exact ι_mul_prod_list (f ∘ fin.succ) _, },
-- ignore the left-most term and induct on the remaining ones, decrementing indices
{ convert mul_zero _,
refine hn (λ i, f $ fin.succ i)
(x.pred hx) (y.pred (ne_of_lt $ lt_of_le_of_lt x.zero_le h).symm)
(fin.pred_lt_pred_iff.mpr h) _,
simp only [fin.succ_pred],
exact hfxy, } }
end,
to_fun := F, ..F}
variables {R}
lemma ι_multi_apply {n : ℕ} (v : fin n → M) :
ι_multi R n v = (list.of_fn $ λ i, ι R (v i)).prod := rfl
@[simp] lemma ι_multi_zero_apply (v : fin 0 → M) : ι_multi R 0 v = 1 := rfl
@[simp] lemma ι_multi_succ_apply {n : ℕ} (v : fin n.succ → M) :
ι_multi R _ v = ι R (v 0) * ι_multi R _ (matrix.vec_tail v):=
(congr_arg list.prod (list.of_fn_succ _)).trans list.prod_cons
lemma ι_multi_succ_curry_left {n : ℕ} (m : M) :
(ι_multi R n.succ).curry_left m =
(linear_map.mul_left R (ι R m)).comp_alternating_map (ι_multi R n) :=
alternating_map.ext $ λ v, (ι_multi_succ_apply _).trans $ begin
simp_rw matrix.tail_cons,
refl,
end
end exterior_algebra
namespace tensor_algebra
variables {R M}
/-- The canonical image of the `tensor_algebra` in the `exterior_algebra`, which maps
`tensor_algebra.ι R x` to `exterior_algebra.ι R x`. -/
def to_exterior : tensor_algebra R M →ₐ[R] exterior_algebra R M :=
tensor_algebra.lift R (exterior_algebra.ι R : M →ₗ[R] exterior_algebra R M)
@[simp] lemma to_exterior_ι (m : M) : (tensor_algebra.ι R m).to_exterior = exterior_algebra.ι R m :=
by simp [to_exterior]
end tensor_algebra
|
3d9f562f6d1436b2e6c1e8d28cb1706a8b5c43db | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/analysis/special_functions/exp_log.lean | ee3a73507233255a803a721e63d17fa679c1d9d9 | [] | 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 | 30,484 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.complex.exponential
import Mathlib.analysis.calculus.mean_value
import Mathlib.measure_theory.borel_space
import Mathlib.analysis.complex.real_deriv
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# Complex and real exponential, real logarithm
## Main statements
This file establishes the basic analytical properties of the complex and real exponential functions
(continuity, differentiability, computation of the derivative).
It also contains the definition of the real logarithm function (as the inverse of the
exponential on `(0, +∞)`, extended to `ℝ` by setting `log (-x) = log x`) and its basic
properties (continuity, differentiability, formula for the derivative).
The complex logarithm is *not* defined in this file as it relies on trigonometric functions. See
instead `trigonometric.lean`.
## Tags
exp, log
-/
namespace complex
/-- The complex exponential is everywhere differentiable, with the derivative `exp x`. -/
theorem has_deriv_at_exp (x : ℂ) : has_deriv_at exp (exp x) x := sorry
theorem differentiable_exp : differentiable ℂ exp :=
fun (x : ℂ) => has_deriv_at.differentiable_at (has_deriv_at_exp x)
theorem differentiable_at_exp {x : ℂ} : differentiable_at ℂ exp x :=
differentiable_exp x
@[simp] theorem deriv_exp : deriv exp = exp :=
funext fun (x : ℂ) => has_deriv_at.deriv (has_deriv_at_exp x)
@[simp] theorem iter_deriv_exp (n : ℕ) : nat.iterate deriv n exp = exp := sorry
theorem continuous_exp : continuous exp :=
differentiable.continuous differentiable_exp
theorem times_cont_diff_exp {n : with_top ℕ} : times_cont_diff ℂ n exp := sorry
theorem measurable_exp : measurable exp :=
continuous.measurable continuous_exp
end complex
theorem has_deriv_at.cexp {f : ℂ → ℂ} {f' : ℂ} {x : ℂ} (hf : has_deriv_at f f' x) : has_deriv_at (fun (x : ℂ) => complex.exp (f x)) (complex.exp (f x) * f') x :=
has_deriv_at.comp x (complex.has_deriv_at_exp (f x)) hf
theorem has_deriv_within_at.cexp {f : ℂ → ℂ} {f' : ℂ} {x : ℂ} {s : set ℂ} (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (fun (x : ℂ) => complex.exp (f x)) (complex.exp (f x) * f') s x :=
has_deriv_at.comp_has_deriv_within_at x (complex.has_deriv_at_exp (f x)) hf
theorem deriv_within_cexp {f : ℂ → ℂ} {x : ℂ} {s : set ℂ} (hf : differentiable_within_at ℂ f s x) (hxs : unique_diff_within_at ℂ s x) : deriv_within (fun (x : ℂ) => complex.exp (f x)) s x = complex.exp (f x) * deriv_within f s x :=
has_deriv_within_at.deriv_within (has_deriv_within_at.cexp (differentiable_within_at.has_deriv_within_at hf)) hxs
@[simp] theorem deriv_cexp {f : ℂ → ℂ} {x : ℂ} (hc : differentiable_at ℂ f x) : deriv (fun (x : ℂ) => complex.exp (f x)) x = complex.exp (f x) * deriv f x :=
has_deriv_at.deriv (has_deriv_at.cexp (differentiable_at.has_deriv_at hc))
theorem measurable.cexp {α : Type u_1} [measurable_space α] {f : α → ℂ} (hf : measurable f) : measurable fun (x : α) => complex.exp (f x) :=
measurable.comp complex.measurable_exp hf
theorem has_fderiv_within_at.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : continuous_linear_map ℂ E ℂ} {x : E} {s : set E} (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (fun (x : E) => complex.exp (f x)) (complex.exp (f x) • f') s x :=
has_deriv_at.comp_has_fderiv_within_at x (complex.has_deriv_at_exp (f x)) hf
theorem has_fderiv_at.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : continuous_linear_map ℂ E ℂ} {x : E} (hf : has_fderiv_at f f' x) : has_fderiv_at (fun (x : E) => complex.exp (f x)) (complex.exp (f x) • f') x :=
iff.mp has_fderiv_within_at_univ (has_fderiv_within_at.cexp (has_fderiv_at.has_fderiv_within_at hf))
theorem differentiable_within_at.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {x : E} {s : set E} (hf : differentiable_within_at ℂ f s x) : differentiable_within_at ℂ (fun (x : E) => complex.exp (f x)) s x :=
has_fderiv_within_at.differentiable_within_at
(has_fderiv_within_at.cexp (differentiable_within_at.has_fderiv_within_at hf))
@[simp] theorem differentiable_at.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {x : E} (hc : differentiable_at ℂ f x) : differentiable_at ℂ (fun (x : E) => complex.exp (f x)) x :=
has_fderiv_at.differentiable_at (has_fderiv_at.cexp (differentiable_at.has_fderiv_at hc))
theorem differentiable_on.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {s : set E} (hc : differentiable_on ℂ f s) : differentiable_on ℂ (fun (x : E) => complex.exp (f x)) s :=
fun (x : E) (h : x ∈ s) => differentiable_within_at.cexp (hc x h)
@[simp] theorem differentiable.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} (hc : differentiable ℂ f) : differentiable ℂ fun (x : E) => complex.exp (f x) :=
fun (x : E) => differentiable_at.cexp (hc x)
theorem times_cont_diff.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {n : with_top ℕ} (h : times_cont_diff ℂ n f) : times_cont_diff ℂ n fun (x : E) => complex.exp (f x) :=
times_cont_diff.comp complex.times_cont_diff_exp h
theorem times_cont_diff_at.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {x : E} {n : with_top ℕ} (hf : times_cont_diff_at ℂ n f x) : times_cont_diff_at ℂ n (fun (x : E) => complex.exp (f x)) x :=
times_cont_diff_at.comp x (times_cont_diff.times_cont_diff_at complex.times_cont_diff_exp) hf
theorem times_cont_diff_on.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {s : set E} {n : with_top ℕ} (hf : times_cont_diff_on ℂ n f s) : times_cont_diff_on ℂ n (fun (x : E) => complex.exp (f x)) s :=
times_cont_diff.comp_times_cont_diff_on complex.times_cont_diff_exp hf
theorem times_cont_diff_within_at.cexp {E : Type u_1} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {x : E} {s : set E} {n : with_top ℕ} (hf : times_cont_diff_within_at ℂ n f s x) : times_cont_diff_within_at ℂ n (fun (x : E) => complex.exp (f x)) s x :=
times_cont_diff_at.comp_times_cont_diff_within_at x (times_cont_diff.times_cont_diff_at complex.times_cont_diff_exp) hf
namespace real
theorem has_deriv_at_exp (x : ℝ) : has_deriv_at exp (exp x) x :=
has_deriv_at.real_of_complex (complex.has_deriv_at_exp ↑x)
theorem times_cont_diff_exp {n : with_top ℕ} : times_cont_diff ℝ n exp :=
times_cont_diff.real_of_complex complex.times_cont_diff_exp
theorem differentiable_exp : differentiable ℝ exp :=
fun (x : ℝ) => has_deriv_at.differentiable_at (has_deriv_at_exp x)
theorem differentiable_at_exp {x : ℝ} : differentiable_at ℝ exp x :=
differentiable_exp x
@[simp] theorem deriv_exp : deriv exp = exp :=
funext fun (x : ℝ) => has_deriv_at.deriv (has_deriv_at_exp x)
@[simp] theorem iter_deriv_exp (n : ℕ) : nat.iterate deriv n exp = exp := sorry
theorem continuous_exp : continuous exp :=
differentiable.continuous differentiable_exp
theorem measurable_exp : measurable exp :=
continuous.measurable continuous_exp
end real
/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
theorem has_deriv_at.exp {f : ℝ → ℝ} {f' : ℝ} {x : ℝ} (hf : has_deriv_at f f' x) : has_deriv_at (fun (x : ℝ) => real.exp (f x)) (real.exp (f x) * f') x :=
has_deriv_at.comp x (real.has_deriv_at_exp (f x)) hf
theorem has_deriv_within_at.exp {f : ℝ → ℝ} {f' : ℝ} {x : ℝ} {s : set ℝ} (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (fun (x : ℝ) => real.exp (f x)) (real.exp (f x) * f') s x :=
has_deriv_at.comp_has_deriv_within_at x (real.has_deriv_at_exp (f x)) hf
theorem deriv_within_exp {f : ℝ → ℝ} {x : ℝ} {s : set ℝ} (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : deriv_within (fun (x : ℝ) => real.exp (f x)) s x = real.exp (f x) * deriv_within f s x :=
has_deriv_within_at.deriv_within (has_deriv_within_at.exp (differentiable_within_at.has_deriv_within_at hf)) hxs
@[simp] theorem deriv_exp {f : ℝ → ℝ} {x : ℝ} (hc : differentiable_at ℝ f x) : deriv (fun (x : ℝ) => real.exp (f x)) x = real.exp (f x) * deriv f x :=
has_deriv_at.deriv (has_deriv_at.exp (differentiable_at.has_deriv_at hc))
/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
theorem measurable.exp {α : Type u_1} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable fun (x : α) => real.exp (f x) :=
measurable.comp real.measurable_exp hf
theorem times_cont_diff.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {n : with_top ℕ} (hf : times_cont_diff ℝ n f) : times_cont_diff ℝ n fun (x : E) => real.exp (f x) :=
times_cont_diff.comp real.times_cont_diff_exp hf
theorem times_cont_diff_at.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {n : with_top ℕ} (hf : times_cont_diff_at ℝ n f x) : times_cont_diff_at ℝ n (fun (x : E) => real.exp (f x)) x :=
times_cont_diff_at.comp x (times_cont_diff.times_cont_diff_at real.times_cont_diff_exp) hf
theorem times_cont_diff_on.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {s : set E} {n : with_top ℕ} (hf : times_cont_diff_on ℝ n f s) : times_cont_diff_on ℝ n (fun (x : E) => real.exp (f x)) s :=
times_cont_diff.comp_times_cont_diff_on real.times_cont_diff_exp hf
theorem times_cont_diff_within_at.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {s : set E} {n : with_top ℕ} (hf : times_cont_diff_within_at ℝ n f s x) : times_cont_diff_within_at ℝ n (fun (x : E) => real.exp (f x)) s x :=
times_cont_diff_at.comp_times_cont_diff_within_at x (times_cont_diff.times_cont_diff_at real.times_cont_diff_exp) hf
theorem has_fderiv_within_at.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : continuous_linear_map ℝ E ℝ} {x : E} {s : set E} (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (fun (x : E) => real.exp (f x)) (real.exp (f x) • f') s x := sorry
theorem has_fderiv_at.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : continuous_linear_map ℝ E ℝ} {x : E} (hf : has_fderiv_at f f' x) : has_fderiv_at (fun (x : E) => real.exp (f x)) (real.exp (f x) • f') x :=
iff.mp has_fderiv_within_at_univ (has_fderiv_within_at.exp (has_fderiv_at.has_fderiv_within_at hf))
theorem differentiable_within_at.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {s : set E} (hf : differentiable_within_at ℝ f s x) : differentiable_within_at ℝ (fun (x : E) => real.exp (f x)) s x :=
has_fderiv_within_at.differentiable_within_at
(has_fderiv_within_at.exp (differentiable_within_at.has_fderiv_within_at hf))
@[simp] theorem differentiable_at.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} (hc : differentiable_at ℝ f x) : differentiable_at ℝ (fun (x : E) => real.exp (f x)) x :=
has_fderiv_at.differentiable_at (has_fderiv_at.exp (differentiable_at.has_fderiv_at hc))
theorem differentiable_on.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {s : set E} (hc : differentiable_on ℝ f s) : differentiable_on ℝ (fun (x : E) => real.exp (f x)) s :=
fun (x : E) (h : x ∈ s) => differentiable_within_at.exp (hc x h)
@[simp] theorem differentiable.exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} (hc : differentiable ℝ f) : differentiable ℝ fun (x : E) => real.exp (f x) :=
fun (x : E) => differentiable_at.exp (hc x)
theorem fderiv_within_exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {s : set E} (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (fun (x : E) => real.exp (f x)) s x = real.exp (f x) • fderiv_within ℝ f s x :=
has_fderiv_within_at.fderiv_within (has_fderiv_within_at.exp (differentiable_within_at.has_fderiv_within_at hf)) hxs
@[simp] theorem fderiv_exp {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} (hc : differentiable_at ℝ f x) : fderiv ℝ (fun (x : E) => real.exp (f x)) x = real.exp (f x) • fderiv ℝ f x :=
has_fderiv_at.fderiv (has_fderiv_at.exp (differentiable_at.has_fderiv_at hc))
namespace real
/-- The real exponential function tends to `+∞` at `+∞`. -/
theorem tendsto_exp_at_top : filter.tendsto exp filter.at_top filter.at_top :=
filter.tendsto_at_top_mono' filter.at_top
(iff.mpr filter.eventually_at_top (Exists.intro 0 fun (x : ℝ) (hx : x ≥ 0) => add_one_le_exp_of_nonneg hx))
(filter.tendsto_at_top_add_const_right filter.at_top 1 filter.tendsto_id)
/-- The real exponential function tends to `0` at `-∞` or, equivalently, `exp(-x)` tends to `0`
at `+∞` -/
theorem tendsto_exp_neg_at_top_nhds_0 : filter.tendsto (fun (x : ℝ) => exp (-x)) filter.at_top (nhds 0) :=
filter.tendsto.congr (fun (x : ℝ) => Eq.symm (exp_neg x))
(filter.tendsto.comp tendsto_inv_at_top_zero tendsto_exp_at_top)
/-- The real exponential function tends to `1` at `0`. -/
theorem tendsto_exp_nhds_0_nhds_1 : filter.tendsto exp (nhds 0) (nhds 1) := sorry
theorem tendsto_exp_at_bot : filter.tendsto exp filter.at_bot (nhds 0) :=
filter.tendsto.congr (fun (x : ℝ) => congr_arg exp (neg_neg x))
(filter.tendsto.comp tendsto_exp_neg_at_top_nhds_0 filter.tendsto_neg_at_bot_at_top)
theorem tendsto_exp_at_bot_nhds_within : filter.tendsto exp filter.at_bot (nhds_within 0 (set.Ioi 0)) :=
iff.mpr filter.tendsto_inf
{ left := tendsto_exp_at_bot, right := iff.mpr filter.tendsto_principal (filter.eventually_of_forall exp_pos) }
/-- `real.exp` as an order isomorphism between `ℝ` and `(0, +∞)`. -/
def exp_order_iso : ℝ ≃o ↥(set.Ioi 0) :=
strict_mono.order_iso_of_surjective (set.cod_restrict exp (set.Ioi 0) exp_pos) sorry sorry
@[simp] theorem coe_exp_order_iso_apply (x : ℝ) : ↑(coe_fn exp_order_iso x) = exp x :=
rfl
@[simp] theorem coe_comp_exp_order_iso : coe ∘ ⇑exp_order_iso = exp :=
rfl
@[simp] theorem range_exp : set.range exp = set.Ioi 0 := sorry
@[simp] theorem map_exp_at_top : filter.map exp filter.at_top = filter.at_top := sorry
@[simp] theorem comap_exp_at_top : filter.comap exp filter.at_top = filter.at_top := sorry
@[simp] theorem tendsto_exp_comp_at_top {α : Type u_1} {l : filter α} {f : α → ℝ} : filter.tendsto (fun (x : α) => exp (f x)) l filter.at_top ↔ filter.tendsto f l filter.at_top := sorry
theorem tendsto_comp_exp_at_top {α : Type u_1} {l : filter α} {f : ℝ → α} : filter.tendsto (fun (x : ℝ) => f (exp x)) filter.at_top l ↔ filter.tendsto f filter.at_top l := sorry
@[simp] theorem map_exp_at_bot : filter.map exp filter.at_bot = nhds_within 0 (set.Ioi 0) := sorry
theorem comap_exp_nhds_within_Ioi_zero : filter.comap exp (nhds_within 0 (set.Ioi 0)) = filter.at_bot := sorry
theorem tendsto_comp_exp_at_bot {α : Type u_1} {l : filter α} {f : ℝ → α} : filter.tendsto (fun (x : ℝ) => f (exp x)) filter.at_bot l ↔ filter.tendsto f (nhds_within 0 (set.Ioi 0)) l := sorry
/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,
to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to
`(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and
the derivative of `log` is `1/x` away from `0`. -/
def log (x : ℝ) : ℝ :=
dite (x = 0) (fun (hx : x = 0) => 0)
fun (hx : ¬x = 0) => coe_fn (order_iso.symm exp_order_iso) { val := abs x, property := sorry }
theorem log_of_ne_zero {x : ℝ} (hx : x ≠ 0) : log x = coe_fn (order_iso.symm exp_order_iso) { val := abs x, property := iff.mpr abs_pos hx } :=
dif_neg hx
theorem log_of_pos {x : ℝ} (hx : 0 < x) : log x = coe_fn (order_iso.symm exp_order_iso) { val := x, property := hx } := sorry
theorem exp_log_eq_abs {x : ℝ} (hx : x ≠ 0) : exp (log x) = abs x := sorry
theorem exp_log {x : ℝ} (hx : 0 < x) : exp (log x) = x :=
eq.mpr (id (Eq._oldrec (Eq.refl (exp (log x) = x)) (exp_log_eq_abs (has_lt.lt.ne' hx)))) (abs_of_pos hx)
theorem exp_log_of_neg {x : ℝ} (hx : x < 0) : exp (log x) = -x :=
eq.mpr (id (Eq._oldrec (Eq.refl (exp (log x) = -x)) (exp_log_eq_abs (ne_of_lt hx)))) (abs_of_neg hx)
@[simp] theorem log_exp (x : ℝ) : log (exp x) = x :=
exp_injective (exp_log (exp_pos x))
theorem surj_on_log : set.surj_on log (set.Ioi 0) set.univ :=
fun (x : ℝ) (_x : x ∈ set.univ) => Exists.intro (exp x) { left := exp_pos x, right := log_exp x }
theorem log_surjective : function.surjective log :=
fun (x : ℝ) => Exists.intro (exp x) (log_exp x)
@[simp] theorem range_log : set.range log = set.univ :=
function.surjective.range_eq log_surjective
@[simp] theorem log_zero : log 0 = 0 :=
dif_pos rfl
@[simp] theorem log_one : log 1 = 0 :=
exp_injective
(eq.mpr (id (Eq._oldrec (Eq.refl (exp (log 1) = exp 0)) (exp_log zero_lt_one)))
(eq.mpr (id (Eq._oldrec (Eq.refl (1 = exp 0)) exp_zero)) (Eq.refl 1)))
@[simp] theorem log_abs (x : ℝ) : log (abs x) = log x := sorry
@[simp] theorem log_neg_eq_log (x : ℝ) : log (-x) = log x :=
eq.mpr (id (Eq._oldrec (Eq.refl (log (-x) = log x)) (Eq.symm (log_abs x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (log (-x) = log (abs x))) (Eq.symm (log_abs (-x)))))
(eq.mpr (id (Eq._oldrec (Eq.refl (log (abs (-x)) = log (abs x))) (abs_neg x))) (Eq.refl (log (abs x)))))
theorem surj_on_log' : set.surj_on log (set.Iio 0) set.univ := sorry
theorem log_mul {x : ℝ} {y : ℝ} (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y := sorry
@[simp] theorem log_inv (x : ℝ) : log (x⁻¹) = -log x := sorry
theorem log_le_log {x : ℝ} {y : ℝ} (h : 0 < x) (h₁ : 0 < y) : log x ≤ log y ↔ x ≤ y :=
eq.mpr (id (Eq._oldrec (Eq.refl (log x ≤ log y ↔ x ≤ y)) (Eq.symm (propext exp_le_exp))))
(eq.mpr (id (Eq._oldrec (Eq.refl (exp (log x) ≤ exp (log y) ↔ x ≤ y)) (exp_log h)))
(eq.mpr (id (Eq._oldrec (Eq.refl (x ≤ exp (log y) ↔ x ≤ y)) (exp_log h₁))) (iff.refl (x ≤ y))))
theorem log_lt_log {x : ℝ} {y : ℝ} (hx : 0 < x) : x < y → log x < log y := sorry
theorem log_lt_log_iff {x : ℝ} {y : ℝ} (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y :=
eq.mpr (id (Eq._oldrec (Eq.refl (log x < log y ↔ x < y)) (Eq.symm (propext exp_lt_exp))))
(eq.mpr (id (Eq._oldrec (Eq.refl (exp (log x) < exp (log y) ↔ x < y)) (exp_log hx)))
(eq.mpr (id (Eq._oldrec (Eq.refl (x < exp (log y) ↔ x < y)) (exp_log hy))) (iff.refl (x < y))))
theorem log_pos_iff {x : ℝ} (hx : 0 < x) : 0 < log x ↔ 1 < x :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 < log x ↔ 1 < x)) (Eq.symm log_one))) (log_lt_log_iff zero_lt_one hx)
theorem log_pos {x : ℝ} (hx : 1 < x) : 0 < log x :=
iff.mpr (log_pos_iff (lt_trans zero_lt_one hx)) hx
theorem log_neg_iff {x : ℝ} (h : 0 < x) : log x < 0 ↔ x < 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl (log x < 0 ↔ x < 1)) (Eq.symm log_one))) (log_lt_log_iff h zero_lt_one)
theorem log_neg {x : ℝ} (h0 : 0 < x) (h1 : x < 1) : log x < 0 :=
iff.mpr (log_neg_iff h0) h1
theorem log_nonneg_iff {x : ℝ} (hx : 0 < x) : 0 ≤ log x ↔ 1 ≤ x :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 ≤ log x ↔ 1 ≤ x)) (Eq.symm (propext not_lt))))
(eq.mpr (id (Eq._oldrec (Eq.refl (¬log x < 0 ↔ 1 ≤ x)) (propext (log_neg_iff hx))))
(eq.mpr (id (Eq._oldrec (Eq.refl (¬x < 1 ↔ 1 ≤ x)) (propext not_lt))) (iff.refl (1 ≤ x))))
theorem log_nonneg {x : ℝ} (hx : 1 ≤ x) : 0 ≤ log x :=
iff.mpr (log_nonneg_iff (has_lt.lt.trans_le zero_lt_one hx)) hx
theorem log_nonpos_iff {x : ℝ} (hx : 0 < x) : log x ≤ 0 ↔ x ≤ 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl (log x ≤ 0 ↔ x ≤ 1)) (Eq.symm (propext not_lt))))
(eq.mpr (id (Eq._oldrec (Eq.refl (¬0 < log x ↔ x ≤ 1)) (propext (log_pos_iff hx))))
(eq.mpr (id (Eq._oldrec (Eq.refl (¬1 < x ↔ x ≤ 1)) (propext not_lt))) (iff.refl (x ≤ 1))))
theorem log_nonpos_iff' {x : ℝ} (hx : 0 ≤ x) : log x ≤ 0 ↔ x ≤ 1 := sorry
theorem log_nonpos {x : ℝ} (hx : 0 ≤ x) (h'x : x ≤ 1) : log x ≤ 0 :=
iff.mpr (log_nonpos_iff' hx) h'x
theorem strict_mono_incr_on_log : strict_mono_incr_on log (set.Ioi 0) :=
fun (x : ℝ) (hx : x ∈ set.Ioi 0) (y : ℝ) (hy : y ∈ set.Ioi 0) (hxy : x < y) => log_lt_log hx hxy
theorem strict_mono_decr_on_log : strict_mono_decr_on log (set.Iio 0) := sorry
/-- The real logarithm function tends to `+∞` at `+∞`. -/
theorem tendsto_log_at_top : filter.tendsto log filter.at_top filter.at_top := sorry
theorem tendsto_log_nhds_within_zero : filter.tendsto log (nhds_within 0 (singleton 0ᶜ)) filter.at_bot := sorry
theorem continuous_on_log : continuous_on log (singleton 0ᶜ) := sorry
theorem continuous_log' : continuous fun (x : Subtype fun (x : ℝ) => 0 < x) => log ↑x := sorry
theorem continuous_at_log {x : ℝ} (hx : x ≠ 0) : continuous_at log x :=
continuous_within_at.continuous_at (continuous_on_log x hx) (mem_nhds_sets is_open_compl_singleton hx)
@[simp] theorem continuous_at_log_iff {x : ℝ} : continuous_at log x ↔ x ≠ 0 := sorry
theorem has_deriv_at_log_of_pos {x : ℝ} (hx : 0 < x) : has_deriv_at log (x⁻¹) x := sorry
theorem has_deriv_at_log {x : ℝ} (hx : x ≠ 0) : has_deriv_at log (x⁻¹) x := sorry
theorem differentiable_at_log {x : ℝ} (hx : x ≠ 0) : differentiable_at ℝ log x :=
has_deriv_at.differentiable_at (has_deriv_at_log hx)
theorem differentiable_on_log : differentiable_on ℝ log (singleton 0ᶜ) :=
fun (x : ℝ) (hx : x ∈ (singleton 0ᶜ)) => differentiable_at.differentiable_within_at (differentiable_at_log hx)
@[simp] theorem differentiable_at_log_iff {x : ℝ} : differentiable_at ℝ log x ↔ x ≠ 0 :=
{ mp := fun (h : differentiable_at ℝ log x) => iff.mp continuous_at_log_iff (differentiable_at.continuous_at h),
mpr := differentiable_at_log }
theorem deriv_log (x : ℝ) : deriv log x = (x⁻¹) := sorry
@[simp] theorem deriv_log' : deriv log = has_inv.inv :=
funext deriv_log
theorem measurable_log : measurable log :=
measurable_of_measurable_on_compl_singleton 0
(continuous.measurable (iff.mp continuous_on_iff_continuous_restrict continuous_on_log))
theorem times_cont_diff_on_log {n : with_top ℕ} : times_cont_diff_on ℝ n log (singleton 0ᶜ) := sorry
theorem times_cont_diff_at_log {x : ℝ} (hx : x ≠ 0) {n : with_top ℕ} : times_cont_diff_at ℝ n log x :=
times_cont_diff_within_at.times_cont_diff_at (times_cont_diff_on_log x hx) (mem_nhds_sets is_open_compl_singleton hx)
end real
theorem filter.tendsto.log {α : Type u_1} {f : α → ℝ} {l : filter α} {x : ℝ} (h : filter.tendsto f l (nhds x)) (hx : x ≠ 0) : filter.tendsto (fun (x : α) => real.log (f x)) l (nhds (real.log x)) :=
filter.tendsto.comp (continuous_at.tendsto (real.continuous_at_log hx)) h
theorem continuous.log {α : Type u_1} [topological_space α] {f : α → ℝ} (hf : continuous f) (h₀ : ∀ (x : α), f x ≠ 0) : continuous fun (x : α) => real.log (f x) :=
continuous_on.comp_continuous real.continuous_on_log hf h₀
theorem continuous_at.log {α : Type u_1} [topological_space α] {f : α → ℝ} {a : α} (hf : continuous_at f a) (h₀ : f a ≠ 0) : continuous_at (fun (x : α) => real.log (f x)) a :=
filter.tendsto.log hf h₀
theorem continuous_within_at.log {α : Type u_1} [topological_space α] {f : α → ℝ} {s : set α} {a : α} (hf : continuous_within_at f s a) (h₀ : f a ≠ 0) : continuous_within_at (fun (x : α) => real.log (f x)) s a :=
filter.tendsto.log hf h₀
theorem continuous_on.log {α : Type u_1} [topological_space α] {f : α → ℝ} {s : set α} (hf : continuous_on f s) (h₀ : ∀ (x : α), x ∈ s → f x ≠ 0) : continuous_on (fun (x : α) => real.log (f x)) s :=
fun (x : α) (hx : x ∈ s) => continuous_within_at.log (hf x hx) (h₀ x hx)
theorem measurable.log {α : Type u_1} [measurable_space α] {f : α → ℝ} (hf : measurable f) : measurable fun (x : α) => real.log (f x) :=
measurable.comp real.measurable_log hf
theorem has_deriv_within_at.log {f : ℝ → ℝ} {x : ℝ} {f' : ℝ} {s : set ℝ} (hf : has_deriv_within_at f f' s x) (hx : f x ≠ 0) : has_deriv_within_at (fun (y : ℝ) => real.log (f y)) (f' / f x) s x :=
eq.mpr (id (Eq._oldrec (Eq.refl (has_deriv_within_at (fun (y : ℝ) => real.log (f y)) (f' / f x) s x)) div_eq_inv_mul))
(has_deriv_at.comp_has_deriv_within_at x (real.has_deriv_at_log hx) hf)
theorem has_deriv_at.log {f : ℝ → ℝ} {x : ℝ} {f' : ℝ} (hf : has_deriv_at f f' x) (hx : f x ≠ 0) : has_deriv_at (fun (y : ℝ) => real.log (f y)) (f' / f x) x := sorry
theorem deriv_within.log {f : ℝ → ℝ} {x : ℝ} {s : set ℝ} (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0) (hxs : unique_diff_within_at ℝ s x) : deriv_within (fun (x : ℝ) => real.log (f x)) s x = deriv_within f s x / f x :=
has_deriv_within_at.deriv_within (has_deriv_within_at.log (differentiable_within_at.has_deriv_within_at hf) hx) hxs
@[simp] theorem deriv.log {f : ℝ → ℝ} {x : ℝ} (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) : deriv (fun (x : ℝ) => real.log (f x)) x = deriv f x / f x :=
has_deriv_at.deriv (has_deriv_at.log (differentiable_at.has_deriv_at hf) hx)
theorem has_fderiv_within_at.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {f' : continuous_linear_map ℝ E ℝ} {s : set E} (hf : has_fderiv_within_at f f' s x) (hx : f x ≠ 0) : has_fderiv_within_at (fun (x : E) => real.log (f x)) (f x⁻¹ • f') s x :=
has_deriv_at.comp_has_fderiv_within_at x (real.has_deriv_at_log hx) hf
theorem has_fderiv_at.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {f' : continuous_linear_map ℝ E ℝ} (hf : has_fderiv_at f f' x) (hx : f x ≠ 0) : has_fderiv_at (fun (x : E) => real.log (f x)) (f x⁻¹ • f') x :=
has_deriv_at.comp_has_fderiv_at x (real.has_deriv_at_log hx) hf
theorem differentiable_within_at.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {s : set E} (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0) : differentiable_within_at ℝ (fun (x : E) => real.log (f x)) s x :=
has_fderiv_within_at.differentiable_within_at
(has_fderiv_within_at.log (differentiable_within_at.has_fderiv_within_at hf) hx)
@[simp] theorem differentiable_at.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) : differentiable_at ℝ (fun (x : E) => real.log (f x)) x :=
has_fderiv_at.differentiable_at (has_fderiv_at.log (differentiable_at.has_fderiv_at hf) hx)
theorem differentiable_on.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {s : set E} (hf : differentiable_on ℝ f s) (hx : ∀ (x : E), x ∈ s → f x ≠ 0) : differentiable_on ℝ (fun (x : E) => real.log (f x)) s :=
fun (x : E) (h : x ∈ s) => differentiable_within_at.log (hf x h) (hx x h)
@[simp] theorem differentiable.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} (hf : differentiable ℝ f) (hx : ∀ (x : E), f x ≠ 0) : differentiable ℝ fun (x : E) => real.log (f x) :=
fun (x : E) => differentiable_at.log (hf x) (hx x)
theorem fderiv_within.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {s : set E} (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0) (hxs : unique_diff_within_at ℝ s x) : fderiv_within ℝ (fun (x : E) => real.log (f x)) s x = f x⁻¹ • fderiv_within ℝ f s x :=
has_fderiv_within_at.fderiv_within (has_fderiv_within_at.log (differentiable_within_at.has_fderiv_within_at hf) hx) hxs
@[simp] theorem fderiv.log {E : Type u_1} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) : fderiv ℝ (fun (x : E) => real.log (f x)) x = f x⁻¹ • fderiv ℝ f x :=
has_fderiv_at.fderiv (has_fderiv_at.log (differentiable_at.has_fderiv_at hf) hx)
namespace real
/-- The function `exp(x)/x^n` tends to `+∞` at `+∞`, for any natural number `n` -/
theorem tendsto_exp_div_pow_at_top (n : ℕ) : filter.tendsto (fun (x : ℝ) => exp x / x ^ n) filter.at_top filter.at_top := sorry
/-- The function `x^n * exp(-x)` tends to `0` at `+∞`, for any natural number `n`. -/
theorem tendsto_pow_mul_exp_neg_at_top_nhds_0 (n : ℕ) : filter.tendsto (fun (x : ℝ) => x ^ n * exp (-x)) filter.at_top (nhds 0) := sorry
/-- The function `(b * exp x + c) / (x ^ n)` tends to `+∞` at `+∞`, for any positive natural number
`n` and any real numbers `b` and `c` such that `b` is positive. -/
theorem tendsto_mul_exp_add_div_pow_at_top (b : ℝ) (c : ℝ) (n : ℕ) (hb : 0 < b) (hn : 1 ≤ n) : filter.tendsto (fun (x : ℝ) => (b * exp x + c) / x ^ n) filter.at_top filter.at_top := sorry
/-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+∞`, for any positive natural number
`n` and any real numbers `b` and `c` such that `b` is nonzero. -/
theorem tendsto_div_pow_mul_exp_add_at_top (b : ℝ) (c : ℝ) (n : ℕ) (hb : 0 ≠ b) (hn : 1 ≤ n) : filter.tendsto (fun (x : ℝ) => x ^ n / (b * exp x + c)) filter.at_top (nhds 0) := sorry
/-- A crude lemma estimating the difference between `log (1-x)` and its Taylor series at `0`,
where the main point of the bound is that it tends to `0`. The goal is to deduce the series
expansion of the logarithm, in `has_sum_pow_div_log_of_abs_lt_1`.
-/
theorem abs_log_sub_add_sum_range_le {x : ℝ} (h : abs x < 1) (n : ℕ) : abs ((finset.sum (finset.range n) fun (i : ℕ) => x ^ (i + 1) / (↑i + 1)) + log (1 - x)) ≤ abs x ^ (n + 1) / (1 - abs x) := sorry
/-- Power series expansion of the logarithm around `1`. -/
theorem has_sum_pow_div_log_of_abs_lt_1 {x : ℝ} (h : abs x < 1) : has_sum (fun (n : ℕ) => x ^ (n + 1) / (↑n + 1)) (-log (1 - x)) := sorry
|
14a10eace8d6da38333954365dc3d4715151b16c | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /library/data/set/basic.lean | 96ebc0af74eb0c4ccfbb07916a68af61994025f8 | [
"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 | 3,634 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: data.set.basic
Author: Jeremy Avigad, Leonardo de Moura
-/
import logic
open eq.ops
definition set (T : Type) := T → Prop
namespace set
variable {T : Type}
/- membership and subset -/
definition mem [reducible] (x : T) (a : set T) := a x
notation e ∈ a := mem e a
theorem setext {a b : set T} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b :=
funext (take x, propext (H x))
definition subset (a b : set T) := ∀⦃x⦄, x ∈ a → x ∈ b
infix `⊆`:50 := subset
/- bounded quantification -/
abbreviation bounded_forall (a : set T) (P : T → 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 T) (P : T → 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 T := λx, false
notation `∅` := empty
theorem mem_empty (x : T) : ¬ (x ∈ ∅) :=
assume H : x ∈ ∅, H
/- universal set -/
definition univ : set T := λx, true
theorem mem_univ (x : T) : x ∈ univ := trivial
/- intersection -/
definition inter [reducible] (a b : set T) : set T := λx, x ∈ a ∧ x ∈ b
notation a ∩ b := inter a b
theorem mem_inter (x : T) (a b : set T) : x ∈ a ∩ b ↔ (x ∈ a ∧ x ∈ b) := !iff.refl
theorem inter_self (a : set T) : a ∩ a = a :=
setext (take x, !and_self)
theorem inter_empty (a : set T) : a ∩ ∅ = ∅ :=
setext (take x, !and_false)
theorem empty_inter (a : set T) : ∅ ∩ a = ∅ :=
setext (take x, !false_and)
theorem inter.comm (a b : set T) : a ∩ b = b ∩ a :=
setext (take x, !and.comm)
theorem inter.assoc (a b c : set T) : (a ∩ b) ∩ c = a ∩ (b ∩ c) :=
setext (take x, !and.assoc)
/- union -/
definition union [reducible] (a b : set T) : set T := λx, x ∈ a ∨ x ∈ b
notation a ∪ b := union a b
theorem mem_union (x : T) (a b : set T) : x ∈ a ∪ b ↔ (x ∈ a ∨ x ∈ b) := !iff.refl
theorem union_self (a : set T) : a ∪ a = a :=
setext (take x, !or_self)
theorem union_empty (a : set T) : a ∪ ∅ = a :=
setext (take x, !or_false)
theorem empty_union (a : set T) : ∅ ∪ a = a :=
setext (take x, !false_or)
theorem union.comm (a b : set T) : a ∪ b = b ∪ a :=
setext (take x, or.comm)
theorem union_assoc (a b c : set T) : (a ∪ b) ∪ c = a ∪ (b ∪ c) :=
setext (take x, or.assoc)
/- set-builder notation -/
-- {x : T | P}
definition set_of (P : T → Prop) : set T := P
notation `{` binders `|` r:(scoped:1 P, set_of P) `}` := r
-- {[x, y, z]} or ⦃x, y, z⦄
definition insert (x : T) (a : set T) : set T := {y : T | y = x ∨ y ∈ a}
notation `{[`:max a:(foldr `,` (x b, insert x b) ∅) `]}`:0 := a
notation `⦃` a:(foldr `,` (x b, insert x b) ∅) `⦄` := a
/- large unions -/
section
variables {I : Type}
variable a : set I
variable b : I → set T
variable C : set (set T)
definition Inter : set T := {x : T | ∀i, x ∈ b i}
definition bInter : set T := {x : T | ∀₀ i ∈ a, x ∈ b i}
definition sInter : set T := {x : T | ∀₀ c ∈ C, x ∈ c}
definition Union : set T := {x : T | ∃i, x ∈ b i}
definition bUnion : set T := {x : T | ∃₀ i ∈ a, x ∈ b i}
definition sUnion : set T := {x : T | ∃₀ c ∈ C, x ∈ c}
-- TODO: need notation for these
end
end set
|
f603d6172175df7e087dea3d4e668f4e743f0db5 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/algebra/ring.lean | 8a25328ed0a97cc99f881bf5c4c8f8ebe813ac47 | [
"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 | 18,338 | 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
Structures with multiplicative and additive components, including semirings, rings, and fields.
The development is modeled after Isabelle's library.
-/
import algebra.group
open eq
variable {A : Type}
/- auxiliary classes -/
structure distrib [class] (A : Type) extends has_mul A, has_add A :=
(left_distrib : ∀a b c, mul a (add b c) = add (mul a b) (mul a c))
(right_distrib : ∀a b c, mul (add a b) c = add (mul a c) (mul b c))
theorem left_distrib [distrib A] (a b c : A) : a * (b + c) = a * b + a * c :=
distrib.left_distrib a b c
theorem right_distrib [distrib A] (a b c : A) : (a + b) * c = a * c + b * c :=
distrib.right_distrib a b c
structure mul_zero_class [class] (A : Type) extends has_mul A, has_zero A :=
(zero_mul : ∀a, mul zero a = zero)
(mul_zero : ∀a, mul a zero = zero)
attribute [simp]
theorem zero_mul [mul_zero_class A] (a : A) : 0 * a = 0 := mul_zero_class.zero_mul a
attribute [simp]
theorem mul_zero [mul_zero_class A] (a : A) : a * 0 = 0 := mul_zero_class.mul_zero a
structure zero_ne_one_class [class] (A : Type) extends has_zero A, has_one A :=
(zero_ne_one : zero ≠ one)
theorem zero_ne_one [s: zero_ne_one_class A] : 0 ≠ (1:A) := @zero_ne_one_class.zero_ne_one A s
/- semiring -/
structure semiring [class] (A : Type) extends add_comm_monoid A, monoid A, distrib A,
mul_zero_class A
section semiring
variables [s : semiring A] (a b c : A)
include s
theorem one_add_one_eq_two : 1 + 1 = (2:A) :=
sorry -- by unfold bit0
theorem ne_zero_of_mul_ne_zero_right {a b : A} (H : a * b ≠ 0) : a ≠ 0 :=
sorry
/-
suppose a = 0,
have a * b = 0, by rewrite [this, zero_mul],
H this
-/
theorem ne_zero_of_mul_ne_zero_left {a b : A} (H : a * b ≠ 0) : b ≠ 0 :=
sorry
/-
suppose b = 0,
have a * b = 0, by rewrite [this, mul_zero],
H this
-/
local attribute right_distrib [simp]
theorem distrib_three_right (a b c d : A) : (a + b + c) * d = a * d + b * d + c * d :=
sorry -- by simp
end semiring
/- comm semiring -/
structure comm_semiring [class] (A : Type) extends semiring A, comm_monoid A
-- TODO: we could also define a cancelative comm_semiring, i.e. satisfying
-- c ≠ 0 → c * a = c * b → a = b.
section comm_semiring
variables [s : comm_semiring A] (a b c : A)
include s
protected definition algebra.dvd (a b : A) : Prop := ∃c, b = a * c
attribute [instance, priority algebra.prio]
definition comm_semiring_has_dvd : has_dvd A :=
has_dvd.mk algebra.dvd
theorem dvd.intro {a b c : A} (H : a * c = b) : a ∣ b :=
exists.intro _ (eq.symm H)
theorem dvd_of_mul_right_eq {a b c : A} (H : a * c = b) : a ∣ b := dvd.intro H
theorem dvd.intro_left {a b c : A} (H : c * a = b) : a ∣ b :=
sorry -- dvd.intro (by rewrite mul.comm at H; exact H)
theorem dvd_of_mul_left_eq {a b c : A} (H : c * a = b) : a ∣ b := dvd.intro_left H
theorem exists_eq_mul_right_of_dvd {a b : A} (H : a ∣ b) : ∃c, b = a * c := H
theorem dvd.elim {P : Prop} {a b : A} (H₁ : a ∣ b) (H₂ : ∀c, b = a * c → P) : P :=
exists.elim H₁ H₂
theorem exists_eq_mul_left_of_dvd {a b : A} (H : a ∣ b) : ∃c, b = c * a :=
dvd.elim H (take c, assume H1 : b = a * c, exists.intro c (eq.trans H1 (mul.comm a c)))
theorem dvd.elim_left {P : Prop} {a b : A} (H₁ : a ∣ b) (H₂ : ∀c, b = c * a → P) : P :=
exists.elim (exists_eq_mul_left_of_dvd H₁) (take c, assume H₃ : b = c * a, H₂ c H₃)
attribute [simp]
theorem dvd.refl : a ∣ a :=
dvd.intro (mul_one a)
theorem dvd.trans {a b c : A} (H₁ : a ∣ b) (H₂ : b ∣ c) : a ∣ c :=
sorry
/-
dvd.elim H₁
(take d, assume H₃ : b = a * d,
dvd.elim H₂
(take e, assume H₄ : c = b * e,
dvd.intro
(show a * (d * e) = c, by rewrite [-mul.assoc, -H₃, H₄])))
-/
theorem eq_zero_of_zero_dvd {a : A} (H : 0 ∣ a) : a = 0 :=
dvd.elim H (take c, assume H' : a = 0 * c, eq.trans H' (zero_mul c))
attribute [simp]
theorem dvd_zero : a ∣ 0 := dvd.intro (mul_zero a)
attribute [simp]
theorem one_dvd : 1 ∣ a := dvd.intro (one_mul a)
attribute [simp]
theorem dvd_mul_right : a ∣ a * b := dvd.intro rfl
attribute [simp]
theorem dvd_mul_left : a ∣ b * a :=
sorry -- by simp
theorem dvd_mul_of_dvd_left {a b : A} (H : a ∣ b) (c : A) : a ∣ b * c :=
sorry
/-
dvd.elim H
(take d,
suppose b = a * d,
dvd.intro
(show a * (d * c) = b * c, by simp))
-/
theorem dvd_mul_of_dvd_right {a b : A} (H : a ∣ b) (c : A) : a ∣ c * b :=
sorry -- begin rewrite mul.comm, exact dvd_mul_of_dvd_left H _ end
theorem mul_dvd_mul {a b c d : A} (dvd_ab : a ∣ b) (dvd_cd : c ∣ d) : a * c ∣ b * d :=
sorry
/-
dvd.elim dvd_ab
(take e, suppose b = a * e,
dvd.elim dvd_cd
(take f, suppose d = c * f,
dvd.intro
(show a * c * (e * f) = b * d,
by simp)))
-/
theorem dvd_of_mul_right_dvd {a b c : A} (H : a * b ∣ c) : a ∣ c :=
dvd.elim H (take d, assume Habdc : c = a * b * d, dvd.intro (eq.symm (eq.trans Habdc (mul.assoc a b d))))
theorem dvd_of_mul_left_dvd {a b c : A} (H : a * b ∣ c) : b ∣ c :=
sorry -- dvd_of_mul_right_dvd begin rewrite mul.comm at H, apply H end
theorem dvd_add {a b c : A} (Hab : a ∣ b) (Hac : a ∣ c) : a ∣ b + c :=
sorry
/-
dvd.elim Hab
(take d, suppose b = a * d,
dvd.elim Hac
(take e, suppose c = a * e,
dvd.intro (show a * (d + e) = b + c,
by rewrite [left_distrib]; substvars)))
-/
end comm_semiring
/- ring -/
structure ring [class] (A : Type) extends add_comm_group A, monoid A, distrib A
attribute [simp]
theorem ring.mul_zero [ring A] (a : A) : a * 0 = 0 :=
sorry
/-
have a * 0 + 0 = a * 0 + a * 0, from calc
a * 0 + 0 = a * (0 + 0) : by simp
... = a * 0 + a * 0 : by rewrite left_distrib,
show a * 0 = 0, from (add.left_cancel this)⁻¹
-/
attribute [simp]
theorem ring.zero_mul [ring A] (a : A) : 0 * a = 0 :=
sorry
/-
have 0 * a + 0 = 0 * a + 0 * a, from calc
0 * a + 0 = (0 + 0) * a : by simp
... = 0 * a + 0 * a : by rewrite right_distrib,
show 0 * a = 0, from (add.left_cancel this)⁻¹
-/
attribute [instance]
definition ring.to_semiring [s : ring A] : semiring A :=
⦃ semiring, s,
mul_zero := ring.mul_zero,
zero_mul := ring.zero_mul ⦄
section
variables [s : ring A] (a b c d e : A)
include s
theorem neg_mul_eq_neg_mul : -(a * b) = -a * b :=
sorry
/-
neg_eq_of_add_eq_zero
begin
rewrite [-right_distrib, add.right_inv, zero_mul]
end
-/
theorem neg_mul_eq_mul_neg : -(a * b) = a * -b :=
sorry
/-
neg_eq_of_add_eq_zero
begin
rewrite [-left_distrib, add.right_inv, mul_zero]
end
-/
attribute [simp]
theorem neg_mul_eq_neg_mul_symm : - a * b = - (a * b) := eq.symm (neg_mul_eq_neg_mul a b)
attribute [simp]
theorem mul_neg_eq_neg_mul_symm : a * - b = - (a * b) := eq.symm (neg_mul_eq_mul_neg a b)
theorem neg_mul_neg : -a * -b = a * b :=
sorry -- by simp
theorem neg_mul_comm : -a * b = a * -b :=
sorry -- by simp
theorem neg_eq_neg_one_mul : -a = -1 * a :=
sorry -- by simp
theorem mul_sub_left_distrib : a * (b - c) = a * b - a * c :=
calc
a * (b - c) = a * b + a * -c : left_distrib a b (-c)
... = a * b - a * c : sorry -- by simp
theorem mul_sub_right_distrib : (a - b) * c = a * c - b * c :=
calc
(a - b) * c = a * c + -b * c : right_distrib a (-b) c
... = a * c - b * c : sorry -- by simp
-- TODO: can calc mode be improved to make this easier?
-- TODO: there is also the other direction. It will be easier when we
-- have the simplifier.
theorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d ↔ (a - b) * e + c = d :=
sorry
/-
calc
a * e + c = b * e + d ↔ a * e + c = d + b * e : by rewrite {b*e+_}add.comm
... ↔ a * e + c - b * e = d : iff.symm !sub_eq_iff_eq_add
... ↔ a * e - b * e + c = d : by rewrite sub_add_eq_add_sub
... ↔ (a - b) * e + c = d : by rewrite mul_sub_right_distrib
-/
theorem mul_add_eq_mul_add_of_sub_mul_add_eq : (a - b) * e + c = d → a * e + c = b * e + d :=
iff.mpr (mul_add_eq_mul_add_iff_sub_mul_add_eq a b c d e)
theorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d → (a - b) * e + c = d :=
iff.mp (mul_add_eq_mul_add_iff_sub_mul_add_eq a b c d e)
theorem mul_neg_one_eq_neg : a * (-1) = -a :=
have a + a * -1 = 0, from calc
a + a * -1 = a * 1 + a * -1 : sorry -- by simp
... = a * (1 + -1) : eq.symm (left_distrib a 1 (-1))
... = 0 : sorry, -- by simp,
symm (neg_eq_of_add_eq_zero this)
theorem ne_zero_and_ne_zero_of_mul_ne_zero {a b : A} (H : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 :=
sorry
/-
have a ≠ 0, from
(suppose a = 0,
have a * b = 0, by rewrite [this, zero_mul],
absurd this H),
have b ≠ 0, from
(suppose b = 0,
have a * b = 0, by rewrite [this, mul_zero],
absurd this H),
and.intro `a ≠ 0` `b ≠ 0`
-/
end
structure comm_ring [class] (A : Type) extends ring A, comm_semigroup A
attribute [instance]
definition comm_ring.to_comm_semiring [s : comm_ring A] : comm_semiring A :=
⦃ comm_semiring, s,
mul_zero := mul_zero,
zero_mul := zero_mul ⦄
section
variables [s : comm_ring A] (a b c d e : A)
include s
local attribute left_distrib right_distrib [simp]
theorem mul_self_sub_mul_self_eq : a * a - b * b = (a + b) * (a - b) :=
sorry -- by simp
theorem mul_self_sub_one_eq : a * a - 1 = (a + 1) * (a - 1) :=
sorry -- by simp
theorem add_mul_self_eq : (a + b) * (a + b) = a*a + 2*a*b + b*b :=
calc (a + b)*(a + b) = a*a + (1+1)*a*b + b*b : sorry -- by simp
... = a*a + 2*a*b + b*b : sorry -- by rewrite one_add_one_eq_two
theorem dvd_neg_iff_dvd : (a ∣ -b) ↔ (a ∣ b) :=
sorry
/-
iff.intro
(suppose a ∣ -b,
dvd.elim this
(take c, suppose -b = a * c,
dvd.intro
(show a * -c = b,
by rewrite [-neg_mul_eq_mul_neg, -this, neg_neg])))
(suppose a ∣ b,
dvd.elim this
(take c, suppose b = a * c,
dvd.intro
(show a * -c = -b,
by rewrite [-neg_mul_eq_mul_neg, -this])))
-/
theorem dvd_neg_of_dvd : (a ∣ b) → (a ∣ -b) :=
iff.mpr (dvd_neg_iff_dvd a b)
theorem dvd_of_dvd_neg : (a ∣ -b) → (a ∣ b) :=
iff.mp (dvd_neg_iff_dvd a b)
theorem neg_dvd_iff_dvd : (-a ∣ b) ↔ (a ∣ b) :=
sorry
/-
iff.intro
(suppose -a ∣ b,
dvd.elim this
(take c, suppose b = -a * c,
dvd.intro
(show a * -c = b, by rewrite [-neg_mul_comm, this])))
(suppose a ∣ b,
dvd.elim this
(take c, suppose b = a * c,
dvd.intro
(show -a * -c = b, by rewrite [neg_mul_neg, this])))
-/
theorem neg_dvd_of_dvd : (a ∣ b) → (-a ∣ b) :=
iff.mpr (neg_dvd_iff_dvd a b)
theorem dvd_of_neg_dvd : (-a ∣ b) → (a ∣ b) :=
iff.mp (neg_dvd_iff_dvd a b)
theorem dvd_sub (H₁ : (a ∣ b)) (H₂ : (a ∣ c)) : (a ∣ b - c) :=
dvd_add H₁ (dvd_neg_of_dvd a c H₂)
end
/- integral domains -/
structure no_zero_divisors [class] (A : Type) extends has_mul A, has_zero A :=
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀a b, mul a b = zero → a = zero ∨ b = zero)
theorem eq_zero_or_eq_zero_of_mul_eq_zero {A : Type} [no_zero_divisors A] {a b : A}
(H : a * b = 0) :
a = 0 ∨ b = 0 :=
no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero a b H
theorem eq_zero_of_mul_self_eq_zero {A : Type} [no_zero_divisors A] {a : A} (H : a * a = 0) :
a = 0 :=
or.elim (eq_zero_or_eq_zero_of_mul_eq_zero H) (assume H', H') (assume H', H')
structure integral_domain [class] (A : Type) extends comm_ring A, no_zero_divisors A,
zero_ne_one_class A
section
variables [s : integral_domain A] (a b c d e : A)
include s
theorem mul_ne_zero {a b : A} (H1 : a ≠ 0) (H2 : b ≠ 0) : a * b ≠ 0 :=
suppose a * b = 0,
or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this) (assume H3, H1 H3) (assume H4, H2 H4)
theorem eq_of_mul_eq_mul_right {a b c : A} (Ha : a ≠ 0) (H : b * a = c * a) : b = c :=
sorry
/-
have b * a - c * a = 0, from iff.mp !eq_iff_sub_eq_zero H,
have (b - c) * a = 0, by rewrite [mul_sub_right_distrib, this],
have b - c = 0, from or_resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero this) Ha,
iff.elim_right !eq_iff_sub_eq_zero this
-/
theorem eq_of_mul_eq_mul_left {a b c : A} (Ha : a ≠ 0) (H : a * b = a * c) : b = c :=
sorry
/-
have a * b - a * c = 0, from iff.mp !eq_iff_sub_eq_zero H,
have a * (b - c) = 0, by rewrite [mul_sub_left_distrib, this],
have b - c = 0, from or_resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero this) Ha,
iff.elim_right !eq_iff_sub_eq_zero this
-/
-- TODO: do we want the iff versions?
theorem eq_zero_of_mul_eq_self_right {a b : A} (H₁ : b ≠ 1) (H₂ : a * b = a) : a = 0 :=
sorry
/-
have b - 1 ≠ 0, from
suppose b - 1 = 0,
have b = 0 + 1, from eq_add_of_sub_eq this,
have b = 1, by rewrite zero_add at this; exact this,
H₁ this,
have a * b - a = 0, by simp,
have a * (b - 1) = 0, by rewrite [mul_sub_left_distrib, mul_one]; apply this,
show a = 0, from or_resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero this) `b - 1 ≠ 0`
-/
theorem eq_zero_of_mul_eq_self_left {a b : A} (H₁ : b ≠ 1) (H₂ : b * a = a) : a = 0 :=
sorry -- eq_zero_of_mul_eq_self_right H₁ (begin rewrite mul.comm at H₂, exact H₂ end)
theorem mul_self_eq_mul_self_iff (a b : A) : a * a = b * b ↔ a = b ∨ a = -b :=
sorry
/-
iff.intro
(suppose a * a = b * b,
have (a - b) * (a + b) = 0,
by rewrite [mul.comm, -mul_self_sub_mul_self_eq, this, sub_self],
have a - b = 0 ∨ a + b = 0, from !eq_zero_or_eq_zero_of_mul_eq_zero this,
or.elim this
(suppose a - b = 0, or.inl (eq_of_sub_eq_zero this))
(suppose a + b = 0, or.inr (eq_neg_of_add_eq_zero this)))
(suppose a = b ∨ a = -b, or.elim this
(suppose a = b, by rewrite this)
(suppose a = -b, by rewrite [this, neg_mul_neg]))
-/
theorem mul_self_eq_one_iff (a : A) : a * a = 1 ↔ a = 1 ∨ a = -1 :=
sorry
/-
have a * a = 1 * 1 ↔ a = 1 ∨ a = -1, from mul_self_eq_mul_self_iff a 1,
by rewrite mul_one at this; exact this
-/
-- TODO: c - b * c → c = 0 ∨ b = 1 and variants
theorem dvd_of_mul_dvd_mul_left {a b c : A} (Ha : a ≠ 0) (Hdvd : (a * b ∣ a * c)) : (b ∣ c) :=
sorry
/-
dvd.elim Hdvd
(take d,
suppose a * c = a * b * d,
have b * d = c, from eq_of_mul_eq_mul_left Ha begin rewrite -mul.assoc, symmetry, exact this end,
dvd.intro this)
-/
theorem dvd_of_mul_dvd_mul_right {a b c : A} (Ha : a ≠ 0) (Hdvd : (b * a ∣ c * a)) : (b ∣ c) :=
sorry
/-
dvd.elim Hdvd
(take d,
suppose c * a = b * a * d,
have b * d * a = c * a, from by rewrite [mul.right_comm, -this],
have b * d = c, from eq_of_mul_eq_mul_right Ha this,
dvd.intro this)
-/
end
namespace norm_num
local attribute bit0 bit1 add1 [reducible]
local attribute right_distrib left_distrib [simp]
theorem mul_zero [mul_zero_class A] (a : A) : a * zero = zero :=
sorry -- by simp
theorem zero_mul [mul_zero_class A] (a : A) : zero * a = zero :=
sorry -- by simp
theorem mul_one [monoid A] (a : A) : a * one = a :=
sorry -- by simp
theorem mul_bit0 [distrib A] (a b : A) : a * (bit0 b) = bit0 (a * b) :=
sorry -- by simp
theorem mul_bit0_helper [distrib A] (a b t : A) (H : a * b = t) : a * (bit0 b) = bit0 t :=
sorry -- by rewrite -H; simp
theorem mul_bit1 [semiring A] (a b : A) : a * (bit1 b) = bit0 (a * b) + a :=
sorry -- by simp
theorem mul_bit1_helper [semiring A] (a b s t : A) (Hs : a * b = s) (Ht : bit0 s + a = t) :
a * (bit1 b) = t :=
sorry -- by simp
theorem subst_into_prod [has_mul A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)
(prt : tl * tr = t) :
l * r = t :=
sorry -- by simp
theorem mk_cong (op : A → A) (a b : A) (H : a = b) : op a = op b :=
sorry -- by simp
theorem neg_add_neg_eq_of_add_add_eq_zero [add_comm_group A] (a b c : A) (H : c + a + b = 0) :
-a + -b = c :=
sorry
/-
begin
apply add_neg_eq_of_eq_add,
apply neg_eq_of_add_eq_zero,
simp
end
-/
theorem neg_add_neg_helper [add_comm_group A] (a b c : A) (H : a + b = c) : -a + -b = -c :=
sorry -- begin apply iff.mp !neg_eq_neg_iff_eq, simp end
theorem neg_add_pos_eq_of_eq_add [add_comm_group A] (a b c : A) (H : b = c + a) : -a + b = c :=
sorry -- begin apply neg_add_eq_of_eq_add, simp end
theorem neg_add_pos_helper1 [add_comm_group A] (a b c : A) (H : b + c = a) : -a + b = -c :=
sorry -- begin apply neg_add_eq_of_eq_add, apply eq_add_neg_of_add_eq H end
theorem neg_add_pos_helper2 [add_comm_group A] (a b c : A) (H : a + c = b) : -a + b = c :=
sorry -- begin apply neg_add_eq_of_eq_add, rewrite H end
theorem pos_add_neg_helper [add_comm_group A] (a b c : A) (H : b + a = c) : a + b = c :=
sorry -- by simp
theorem sub_eq_add_neg_helper [add_comm_group A] (t₁ t₂ e w₁ w₂: A) (H₁ : t₁ = w₁)
(H₂ : t₂ = w₂) (H : w₁ + -w₂ = e) : t₁ - t₂ = e :=
sorry -- by simp
theorem pos_add_pos_helper [add_comm_group A] (a b c h₁ h₂ : A) (H₁ : a = h₁) (H₂ : b = h₂)
(H : h₁ + h₂ = c) : a + b = c :=
sorry -- by simp
theorem subst_into_subtr [add_group A] (l r t : A) (prt : l + -r = t) : l - r = t :=
sorry -- by simp
theorem neg_neg_helper [add_group A] (a b : A) (H : a = -b) : -a = b :=
sorry -- by simp
theorem neg_mul_neg_helper [ring A] (a b c : A) (H : a * b = c) : (-a) * (-b) = c :=
sorry -- by simp
theorem neg_mul_pos_helper [ring A] (a b c : A) (H : a * b = c) : (-a) * b = -c :=
sorry -- by simp
theorem pos_mul_neg_helper [ring A] (a b c : A) (H : a * b = c) : a * (-b) = -c :=
sorry -- by simp
end norm_num
attribute [simp]
zero_mul mul_zero
attribute [simp]
neg_mul_eq_neg_mul_symm mul_neg_eq_neg_mul_symm
attribute [simp]
left_distrib right_distrib
|
dfb74efc1a5c3192d74c34015577754337064247 | e030b0259b777fedcdf73dd966f3f1556d392178 | /library/tools/super/prover_state.lean | de82a08a8951bee852726ce57e987b020673a060 | [
"Apache-2.0"
] | permissive | fgdorais/lean | 17b46a095b70b21fa0790ce74876658dc5faca06 | c3b7c54d7cca7aaa25328f0a5660b6b75fe26055 | refs/heads/master | 1,611,523,590,686 | 1,484,412,902,000 | 1,484,412,902,000 | 38,489,734 | 0 | 0 | null | 1,435,923,380,000 | 1,435,923,379,000 | null | UTF-8 | Lean | false | false | 15,635 | lean | /-
Copyright (c) 2016 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .clause .lpo .cdcl_solver
open tactic monad expr
namespace super
structure score :=
(priority : ℕ)
(in_sos : bool)
(cost : ℕ)
(age : ℕ)
namespace score
def prio.immediate : ℕ := 0
def prio.default : ℕ := 1
def prio.never : ℕ := 2
def sched_default (sc : score) : score := { sc with priority := prio.default }
def sched_now (sc : score) : score := { sc with priority := prio.immediate }
def inc_cost (sc : score) (n : ℕ) : score := { sc with cost := sc^.cost + n }
def min (a b : score) : score :=
{ priority := nat.min a^.priority b^.priority,
in_sos := a^.in_sos && b^.in_sos,
cost := nat.min a^.cost b^.cost,
age := nat.min a^.age b^.age }
def combine (a b : score) : score :=
{ priority := nat.max a^.priority b^.priority,
in_sos := a^.in_sos && b^.in_sos,
cost := a^.cost + b^.cost,
age := nat.max a^.age b^.age }
end score
namespace score
meta instance : has_to_string score :=
⟨λe, "[" ++ to_string e^.priority ++
"," ++ to_string e^.cost ++
"," ++ to_string e^.age ++
",sos=" ++ to_string e^.in_sos ++ "]"⟩
end score
def clause_id := ℕ
namespace clause_id
def to_nat (id : clause_id) : ℕ := id
instance : decidable_eq clause_id := nat.decidable_eq
instance : has_ordering clause_id := nat.has_ordering
end clause_id
meta structure derived_clause :=
(id : clause_id)
(c : clause)
(selected : list ℕ)
(assertions : list expr)
(sc : score)
namespace derived_clause
meta instance : has_to_tactic_format derived_clause :=
⟨λc, do
prf_fmt ← pp c^.c^.proof,
c_fmt ← pp c^.c,
ass_fmt ← pp (c^.assertions^.for (λa, a^.local_type)),
return $
to_string c^.sc ++ " " ++
prf_fmt ++ " " ++
c_fmt ++ " <- " ++ ass_fmt ++
" (selected: " ++ to_fmt c^.selected ++
")"
⟩
meta def clause_with_assertions (ac : derived_clause) : clause :=
ac^.c^.close_constn ac^.assertions
end derived_clause
meta structure locked_clause :=
(dc : derived_clause)
(reasons : list (list expr))
namespace locked_clause
meta instance : has_to_tactic_format locked_clause :=
⟨λc, do
c_fmt ← pp c^.dc,
reasons_fmt ← pp (c^.reasons^.for (λr, r^.for (λa, a^.local_type))),
return $ c_fmt ++ " (locked in case of: " ++ reasons_fmt ++ ")"
⟩
end locked_clause
meta structure prover_state :=
(active : rb_map clause_id derived_clause)
(passive : rb_map clause_id derived_clause)
(newly_derived : list derived_clause)
(prec : list expr)
(locked : list locked_clause)
(local_false : expr)
(sat_solver : cdcl.state)
(current_model : rb_map expr bool)
(sat_hyps : rb_map expr (expr × expr))
(needs_sat_run : bool)
(clause_counter : nat)
open prover_state
private meta def join_with_nl : list format → format :=
list.foldl (λx y, x ++ format.line ++ y) format.nil
private meta def prover_state_tactic_fmt (s : prover_state) : tactic format := do
active_fmts ← mapm pp $ rb_map.values s^.active,
passive_fmts ← mapm pp $ rb_map.values s^.passive,
new_fmts ← mapm pp s^.newly_derived,
locked_fmts ← mapm pp s^.locked,
sat_fmts ← mapm pp s^.sat_solver^.clauses,
sat_model_fmts ← for s^.current_model^.to_list (λx, if x.2 = tt then pp x.1 else pp (not_ x.1)),
prec_fmts ← mapm pp s^.prec,
return (join_with_nl
([to_fmt "active:"] ++ map (append (to_fmt " ")) active_fmts ++
[to_fmt "passive:"] ++ map (append (to_fmt " ")) passive_fmts ++
[to_fmt "new:"] ++ map (append (to_fmt " ")) new_fmts ++
[to_fmt "locked:"] ++ map (append (to_fmt " ")) locked_fmts ++
[to_fmt "sat formulas:"] ++ map (append (to_fmt " ")) sat_fmts ++
[to_fmt "sat model:"] ++ map (append (to_fmt " ")) sat_model_fmts ++
[to_fmt "precedence order: " ++ to_fmt prec_fmts]))
meta instance : has_to_tactic_format prover_state :=
⟨prover_state_tactic_fmt⟩
meta def prover := state_t prover_state tactic
namespace prover
meta instance : monad prover := state_t.monad _ _
meta instance : has_monad_lift tactic prover :=
monad.monad_transformer_lift (state_t prover_state) tactic
meta instance (α : Type) : has_coe (tactic α) (prover α) :=
⟨monad.monad_lift⟩
meta def fail {α β : Type} [has_to_format β] (msg : β) : prover α :=
fail msg
meta def orelse (A : Type) (p1 p2 : prover A) : prover A :=
take state, p1 state <|> p2 state
meta instance : alternative prover :=
{ monad_is_applicative prover with
failure := λα, fail "failed",
orelse := orelse }
end prover
meta def selection_strategy := derived_clause → prover derived_clause
meta def get_active : prover (rb_map clause_id derived_clause) :=
do state ← state_t.read, return state^.active
meta def add_active (a : derived_clause) : prover unit :=
do state ← state_t.read,
state_t.write { state with active := state^.active^.insert a^.id a }
meta def get_passive : prover (rb_map clause_id derived_clause) :=
lift passive state_t.read
meta def get_precedence : prover (list expr) :=
do state ← state_t.read, return state^.prec
meta def get_term_order : prover (expr → expr → bool) := do
state ← state_t.read,
return $ mk_lpo (map name_of_funsym state^.prec)
private meta def set_precedence (new_prec : list expr) : prover unit :=
do state ← state_t.read, state_t.write { state with prec := new_prec }
meta def register_consts_in_precedence (consts : list expr) := do
p ← get_precedence,
p_set ← return (rb_map.set_of_list (map name_of_funsym p)),
new_syms ← return $ list.filter (λc, ¬p_set^.contains (name_of_funsym c)) consts,
set_precedence (new_syms ++ p)
meta def in_sat_solver {A} (cmd : cdcl.solver A) : prover A := do
state ← state_t.read,
result ← cmd state^.sat_solver,
state_t.write { state with sat_solver := result.2 },
return result.1
meta def collect_ass_hyps (c : clause) : prover (list expr) :=
let lcs := contained_lconsts c^.proof in
do st ← state_t.read,
return (do
hs ← st^.sat_hyps^.values,
h ← [hs.1, hs.2],
guard $ lcs^.contains h^.local_uniq_name,
[h])
meta def get_clause_count : prover ℕ :=
do s ← state_t.read, return s^.clause_counter
meta def get_new_cls_id : prover clause_id := do
state ← state_t.read,
state_t.write { state with clause_counter := state^.clause_counter + 1 },
return state^.clause_counter
meta def mk_derived (c : clause) (sc : score) : prover derived_clause := do
ass ← collect_ass_hyps c,
id ← get_new_cls_id,
return { id := id, c := c, selected := [], assertions := ass, sc := sc }
meta def add_inferred (c : derived_clause) : prover unit := do
c' ← c^.c^.normalize, c' ← return { c with c := c' },
register_consts_in_precedence (contained_funsyms c'^.c^.type)^.values,
state ← state_t.read,
state_t.write { state with newly_derived := c' :: state^.newly_derived }
-- FIXME: what if we've seen the variable before, but with a weaker score?
meta def mk_sat_var (v : expr) (suggested_ph : bool) (suggested_ev : score) : prover unit :=
do st ← state_t.read, if st^.sat_hyps^.contains v then return () else do
hpv ← mk_local_def `h v,
hnv ← mk_local_def `hn $ imp v st^.local_false,
state_t.modify $ λst, { st with sat_hyps := st^.sat_hyps^.insert v (hpv, hnv) },
in_sat_solver $ cdcl.mk_var_core v suggested_ph,
match v with
| (pi _ _ _ _) := do
c ← clause.of_proof st^.local_false hpv,
mk_derived c suggested_ev >>= add_inferred
| _ := do cp ← clause.of_proof st^.local_false hpv, mk_derived cp suggested_ev >>= add_inferred,
cn ← clause.of_proof st^.local_false hnv, mk_derived cn suggested_ev >>= add_inferred
end
meta def get_sat_hyp_core (v : expr) (ph : bool) : prover (option expr) :=
flip monad.lift state_t.read $ λst,
match st^.sat_hyps^.find v with
| some (hp, hn) := some $ if ph then hp else hn
| none := none
end
meta def get_sat_hyp (v : expr) (ph : bool) : prover expr :=
do hyp_opt ← get_sat_hyp_core v ph,
match hyp_opt with
| some hyp := return hyp
| none := fail $ "unknown sat variable: " ++ v^.to_string
end
meta def add_sat_clause (c : clause) (suggested_ev : score) : prover unit := do
c ← c^.distinct,
already_added ← flip monad.lift state_t.read $ λst, decidable.to_bool $
c^.type ∈ st^.sat_solver^.clauses^.for (λd, d^.type),
if already_added then return () else do
for c^.get_lits $ λl, mk_sat_var l^.formula l^.is_neg suggested_ev,
in_sat_solver $ cdcl.mk_clause c,
state_t.modify $ λst, { st with needs_sat_run := tt }
meta def sat_eval_lit (v : expr) (pol : bool) : prover bool :=
do v_st ← flip monad.lift state_t.read $ λst, st^.current_model^.find v,
match v_st with
| some ph := return $ if pol then ph else bnot ph
| none := return tt
end
meta def sat_eval_assertion (assertion : expr) : prover bool :=
do lf ← flip monad.lift state_t.read $ λst, st^.local_false,
match is_local_not lf assertion^.local_type with
| some v := sat_eval_lit v ff
| none := sat_eval_lit assertion^.local_type tt
end
meta def sat_eval_assertions : list expr → prover bool
| (a::ass) := do v_a ← sat_eval_assertion a,
if v_a then
sat_eval_assertions ass
else
return ff
| [] := return tt
private meta def intern_clause (c : derived_clause) : prover derived_clause := do
hyp_name ← get_unused_name (mk_simple_name $ "clause_" ++ to_string c^.id^.to_nat) none,
c' ← return $ c^.c^.close_constn c^.assertions,
assertv hyp_name c'^.type c'^.proof,
proof' ← get_local hyp_name,
type ← infer_type proof', -- FIXME: otherwise ""
return { c with c := { (c^.c : clause) with proof := app_of_list proof' c^.assertions } }
meta def register_as_passive (c : derived_clause) : prover unit := do
c ← intern_clause c,
ass_v ← sat_eval_assertions c^.assertions,
if c^.c^.num_quants = 0 ∧ c^.c^.num_lits = 0 then
add_sat_clause c^.clause_with_assertions c^.sc
else if ¬ass_v then do
state_t.modify $ λst, { st with locked := ⟨c, []⟩ :: st^.locked }
else do
state_t.modify $ λst, { st with passive := st^.passive^.insert c^.id c }
meta def remove_passive (id : clause_id) : prover unit :=
do state ← state_t.read, state_t.write { state with passive := state^.passive^.erase id }
meta def move_locked_to_passive : prover unit := do
locked ← flip monad.lift state_t.read (λst, st^.locked),
new_locked ← flip filter locked (λlc, do
reason_vals ← mapm sat_eval_assertions lc^.reasons,
c_val ← sat_eval_assertions lc^.dc^.assertions,
if reason_vals^.for_all (λr, r = ff) ∧ c_val then do
state_t.modify $ λst, { st with passive := st^.passive^.insert lc^.dc^.id lc^.dc },
return ff
else
return tt
),
state_t.modify $ λst, { st with locked := new_locked }
meta def move_active_to_locked : prover unit :=
do active ← get_active, for' active^.values $ λac, do
c_val ← sat_eval_assertions ac^.assertions,
if ¬c_val then do
state_t.modify $ λst, { st with
active := st^.active^.erase ac^.id,
locked := ⟨ac, []⟩ :: st^.locked
}
else
return ()
meta def move_passive_to_locked : prover unit :=
do passive ← flip monad.lift state_t.read $ λst, st^.passive, for' passive^.to_list $ λpc, do
c_val ← sat_eval_assertions pc.2^.assertions,
if ¬c_val then do
state_t.modify $ λst, { st with
passive := st^.passive^.erase pc.1,
locked := ⟨pc.2, []⟩ :: st^.locked
}
else
return ()
def super_cc_config : cc_config :=
{ default_cc_config with em := ff }
meta def do_sat_run : prover (option expr) :=
do sat_result ← in_sat_solver $ cdcl.run (cdcl.theory_solver_of_tactic $ using_smt $ return ()),
state_t.modify $ λst, { st with needs_sat_run := ff },
old_model ← lift prover_state.current_model state_t.read,
match sat_result with
| (cdcl.result.unsat proof) := return (some proof)
| (cdcl.result.sat new_model) := do
state_t.modify $ λst, { st with current_model := new_model },
move_locked_to_passive,
move_active_to_locked,
move_passive_to_locked,
return none
end
meta def take_newly_derived : prover (list derived_clause) := do
state ← state_t.read,
state_t.write { state with newly_derived := [] },
return state^.newly_derived
meta def remove_redundant (id : clause_id) (parents : list derived_clause) : prover unit := do
when (not $ parents^.for_all $ λp, p^.id ≠ id) (fail "clause is redundant because of itself"),
red ← flip monad.lift state_t.read (λst, st^.active^.find id),
match red with
| none := return ()
| some red := do
let reasons := parents^.for (λp, p^.assertions),
assertion := red^.assertions in
if reasons^.for_all $ λr, r^.subset_of assertion then do
state_t.modify $ λst, { st with active := st^.active^.erase id }
else do
state_t.modify $ λst, { st with active := st^.active^.erase id,
locked := ⟨red, reasons⟩ :: st^.locked }
end
meta def inference := derived_clause → prover unit
meta structure inf_decl := (prio : ℕ) (inf : inference)
meta def inf_attr : user_attribute :=
⟨ `super.inf, "inference for the super prover" ⟩
run_command attribute.register `super.inf_attr
meta def seq_inferences : list inference → inference
| [] := λgiven, return ()
| (inf::infs) := λgiven, do
inf given,
now_active ← get_active,
if rb_map.contains now_active given^.id then
seq_inferences infs given
else
return ()
meta def simp_inference (simpl : derived_clause → prover (option clause)) : inference :=
λgiven, do maybe_simpld ← simpl given,
match maybe_simpld with
| some simpld := do
derived_simpld ← mk_derived simpld given^.sc^.sched_now,
add_inferred derived_simpld,
remove_redundant given^.id []
| none := return ()
end
meta def preprocessing_rule (f : list derived_clause → prover (list derived_clause)) : prover unit := do
state ← state_t.read,
newly_derived' ← f state^.newly_derived,
state' ← state_t.read,
state_t.write { state' with newly_derived := newly_derived' }
meta def clause_selection_strategy := ℕ → prover clause_id
namespace prover_state
meta def empty (local_false : expr) : prover_state :=
{ active := rb_map.mk _ _, passive := rb_map.mk _ _,
newly_derived := [], prec := [], clause_counter := 0,
local_false := local_false,
locked := [], sat_solver := cdcl.state.initial local_false,
current_model := rb_map.mk _ _, sat_hyps := rb_map.mk _ _, needs_sat_run := ff }
meta def initial (local_false : expr) (clauses : list clause) : tactic prover_state := do
after_setup ← for' clauses (λc,
let in_sos := decidable.to_bool $ ((contained_lconsts c^.proof)^.erase local_false^.local_uniq_name)^.size = 0 in
do mk_derived c { priority := score.prio.immediate, in_sos := in_sos,
age := 0, cost := 0 } >>= add_inferred
) $ empty local_false,
return after_setup.2
end prover_state
meta def inf_score (add_cost : ℕ) (scores : list score) : prover score := do
age ← get_clause_count,
return $ list.foldl score.combine { priority := score.prio.default,
in_sos := tt,
age := age,
cost := add_cost
} scores
meta def inf_if_successful (add_cost : ℕ) (parent : derived_clause) (tac : tactic (list clause)) : prover unit :=
(do inferred ← tac,
for' inferred $ λc,
inf_score add_cost [parent^.sc] >>= mk_derived c >>= add_inferred)
<|> return ()
meta def simp_if_successful (parent : derived_clause) (tac : tactic (list clause)) : prover unit :=
(do inferred ← tac,
for' inferred $ λc,
mk_derived c parent^.sc^.sched_now >>= add_inferred,
remove_redundant parent^.id [])
<|> return ()
end super
|
cd8f5d0e48a267f353a2229277be19e30f10b806 | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/mv_polynomial/pderiv.lean | fa6324264cc948e5249c2ae3c691da9696ef11b4 | [
"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 | 4,210 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
-/
import data.mv_polynomial.variables
import algebra.module.basic
import tactic.ring
/-!
# Partial derivatives of polynomials
This file defines the notion of the formal *partial derivative* of a polynomial,
the derivative with respect to a single variable.
This derivative is not connected to the notion of derivative from analysis.
It is based purely on the polynomial exponents and coefficients.
## Main declarations
* `mv_polynomial.pderiv i p` : the partial derivative of `p` with respect to `i`.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[comm_ring R]` (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`
+ `a : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : mv_polynomial σ R`
-/
noncomputable theory
open_locale classical big_operators
open set function finsupp add_monoid_algebra
open_locale big_operators
universes u
variables {R : Type u}
namespace mv_polynomial
variables {σ : Type*} {a a' a₁ a₂ : R} {s : σ →₀ ℕ}
section pderiv
variables {R} [comm_semiring R]
/-- `pderiv i p` is the partial derivative of `p` with respect to `i` -/
def pderiv (i : σ) : mv_polynomial σ R →ₗ[R] mv_polynomial σ R :=
{ to_fun := λ p, p.sum (λ A B, monomial (A - single i 1) (B * (A i))),
map_smul' := begin
intros c x,
rw [sum_smul_index', smul_sum],
{ simp_rw [monomial, smul_single, smul_eq_mul, mul_assoc] },
{ intros s,
simp only [monomial_zero, zero_mul] }
end,
map_add' := λ f g, sum_add_index (by simp only [monomial_zero, forall_const, zero_mul])
(by simp only [add_mul, forall_const, eq_self_iff_true, monomial_add]), }
@[simp]
lemma pderiv_monomial {i : σ} :
pderiv i (monomial s a) = monomial (s - single i 1) (a * (s i)) :=
by simp only [pderiv, monomial_zero, sum_monomial, zero_mul, linear_map.coe_mk]
@[simp]
lemma pderiv_C {i : σ} : pderiv i (C a) = 0 :=
suffices pderiv i (monomial 0 a) = 0, by simpa,
by simp only [monomial_zero, pderiv_monomial, nat.cast_zero, mul_zero, zero_apply]
lemma pderiv_eq_zero_of_not_mem_vars {i : σ} {f : mv_polynomial σ R} (h : i ∉ f.vars) :
pderiv i f = 0 :=
begin
change (pderiv i) f = 0,
rw [f.as_sum, linear_map.map_sum],
apply finset.sum_eq_zero,
intros x H,
simp [mem_support_not_mem_vars_zero H h],
end
lemma pderiv_monomial_single {i : σ} {n : ℕ} :
pderiv i (monomial (single i n) a) = monomial (single i (n-1)) (a * n) :=
by simp
private lemma monomial_sub_single_one_add {i : σ} {s' : σ →₀ ℕ} :
monomial (s - single i 1 + s') (a * (s i) * a') =
monomial (s + s' - single i 1) (a * (s i) * a') :=
by by_cases h : s i = 0; simp [h, sub_single_one_add]
private lemma monomial_add_sub_single_one {i : σ} {s' : σ →₀ ℕ} :
monomial (s + (s' - single i 1)) (a * (a' * (s' i))) =
monomial (s + s' - single i 1) (a * (a' * (s' i))) :=
by by_cases h : s' i = 0; simp [h, add_sub_single_one]
lemma pderiv_monomial_mul {i : σ} {s' : σ →₀ ℕ} :
pderiv i (monomial s a * monomial s' a') =
pderiv i (monomial s a) * monomial s' a' + monomial s a * pderiv i (monomial s' a') :=
begin
simp [monomial_sub_single_one_add, monomial_add_sub_single_one],
congr,
ring,
end
@[simp]
lemma pderiv_mul {i : σ} {f g : mv_polynomial σ R} :
pderiv i (f * g) = pderiv i f * g + f * pderiv i g :=
begin
apply induction_on' f,
{ apply induction_on' g,
{ intros u r u' r', exact pderiv_monomial_mul },
{ intros p q hp hq u r,
rw [mul_add, linear_map.map_add, hp, hq, mul_add, linear_map.map_add],
ring } },
{ intros p q hp hq,
simp [add_mul, hp, hq],
ring, }
end
@[simp]
lemma pderiv_C_mul {f : mv_polynomial σ R} {i : σ} :
pderiv i (C a * f) = C a * pderiv i f :=
by convert linear_map.map_smul (pderiv i) a f; rw C_mul'
end pderiv
end mv_polynomial
|
0d316b239199b2c12fbcabced459439153a0bd95 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/convex/specific_functions.lean | 2a613269fe90a770e85fb7d3dff44953fc58b1c4 | [
"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 | 10,303 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Sébastien Gouëzel
-/
import analysis.calculus.mean_value
import analysis.special_functions.pow_deriv
/-!
# Collection of convex functions
In this file we prove that the following functions are convex:
* `strict_convex_on_exp` : The exponential function is strictly convex.
* `even.convex_on_pow`, `even.strict_convex_on_pow` : For an even `n : ℕ`, `λ x, x ^ n` is convex
and strictly convex when `2 ≤ n`.
* `convex_on_pow`, `strict_convex_on_pow` : For `n : ℕ`, `λ x, x ^ n` is convex on $[0, +∞)$ and
strictly convex when `2 ≤ n`.
* `convex_on_zpow`, `strict_convex_on_zpow` : For `m : ℤ`, `λ x, x ^ m` is convex on $[0, +∞)$ and
strictly convex when `m ≠ 0, 1`.
* `convex_on_rpow`, `strict_convex_on_rpow` : For `p : ℝ`, `λ x, x ^ p` is convex on $[0, +∞)$ when
`1 ≤ p` and strictly convex when `1 < p`.
* `strict_concave_on_log_Ioi`, `strict_concave_on_log_Iio`: `real.log` is strictly concave on
$(0, +∞)$ and $(-∞, 0)$ respectively.
## TODO
For `p : ℝ`, prove that `λ x, x ^ p` is concave when `0 ≤ p ≤ 1` and strictly concave when
`0 < p < 1`.
-/
open real set
open_locale big_operators
/-- The norm of a real normed space is convex. Also see `seminorm.convex_on`. -/
lemma convex_on_norm {E : Type*} [normed_group E] [normed_space ℝ E] :
convex_on ℝ univ (norm : E → ℝ) :=
⟨convex_univ, λ x y hx hy a b ha hb hab,
calc ∥a • x + b • y∥ ≤ ∥a • x∥ + ∥b • y∥ : norm_add_le _ _
... = a * ∥x∥ + b * ∥y∥
: by rw [norm_smul, norm_smul, real.norm_of_nonneg ha, real.norm_of_nonneg hb]⟩
/-- `exp` is strictly convex on the whole real line. -/
lemma strict_convex_on_exp : strict_convex_on ℝ univ exp :=
strict_convex_on_univ_of_deriv2_pos differentiable_exp (λ x, (iter_deriv_exp 2).symm ▸ exp_pos x)
/-- `exp` is convex on the whole real line. -/
lemma convex_on_exp : convex_on ℝ univ exp := strict_convex_on_exp.convex_on
/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even -/
lemma even.convex_on_pow {n : ℕ} (hn : even n) : convex_on ℝ set.univ (λ x : ℝ, x^n) :=
begin
apply convex_on_univ_of_deriv2_nonneg differentiable_pow,
{ simp only [deriv_pow', differentiable.mul, differentiable_const, differentiable_pow] },
{ intro x,
rcases nat.even.sub_even hn (nat.even_bit0 1) with ⟨k, hk⟩,
rw [iter_deriv_pow, finset.prod_range_cast_nat_sub, hk, pow_mul'],
exact mul_nonneg (nat.cast_nonneg _) (pow_two_nonneg _) }
end
/-- `x^n`, `n : ℕ` is strictly convex on the whole real line whenever `n ≠ 0` is even. -/
lemma even.strict_convex_on_pow {n : ℕ} (hn : even n) (h : n ≠ 0) :
strict_convex_on ℝ set.univ (λ x : ℝ, x^n) :=
begin
apply strict_mono.strict_convex_on_univ_of_deriv differentiable_pow,
rw deriv_pow',
replace h := nat.pos_of_ne_zero h,
exact strict_mono.const_mul (odd.strict_mono_pow $ nat.even.sub_odd h hn $ nat.odd_iff.2 rfl)
(nat.cast_pos.2 h),
end
/-- `x^n`, `n : ℕ` is convex on `[0, +∞)` for all `n` -/
lemma convex_on_pow (n : ℕ) : convex_on ℝ (Ici 0) (λ x : ℝ, x^n) :=
begin
apply convex_on_of_deriv2_nonneg (convex_Ici _) (continuous_pow n).continuous_on
differentiable_on_pow,
{ simp only [deriv_pow'], exact (@differentiable_on_pow ℝ _ _ _).const_mul (n : ℝ) },
{ intros x hx,
rw [iter_deriv_pow, finset.prod_range_cast_nat_sub],
exact mul_nonneg (nat.cast_nonneg _) (pow_nonneg (interior_subset hx) _) }
end
/-- `x^n`, `n : ℕ` is strictly convex on `[0, +∞)` for all `n` greater than `2`. -/
lemma strict_convex_on_pow {n : ℕ} (hn : 2 ≤ n) : strict_convex_on ℝ (Ici 0) (λ x : ℝ, x^n) :=
begin
apply strict_mono_on.strict_convex_on_of_deriv (convex_Ici _) (continuous_on_pow _)
differentiable_on_pow,
rw [deriv_pow', interior_Ici],
exact λ x (hx : 0 < x) y hy hxy, mul_lt_mul_of_pos_left (pow_lt_pow_of_lt_left hxy hx.le $
nat.sub_pos_of_lt hn) (nat.cast_pos.2 $ zero_lt_two.trans_le hn),
end
lemma finset.prod_nonneg_of_card_nonpos_even
{α β : Type*} [linear_ordered_comm_ring β]
{f : α → β} [decidable_pred (λ x, f x ≤ 0)]
{s : finset α} (h0 : even (s.filter (λ x, f x ≤ 0)).card) :
0 ≤ ∏ x in s, f x :=
calc 0 ≤ (∏ x in s, ((if f x ≤ 0 then (-1:β) else 1) * f x)) :
finset.prod_nonneg (λ x _, by
{ split_ifs with hx hx, by simp [hx], simp at hx ⊢, exact le_of_lt hx })
... = _ : by rw [finset.prod_mul_distrib, finset.prod_ite, finset.prod_const_one,
mul_one, finset.prod_const, neg_one_pow_eq_pow_mod_two, nat.even_iff.1 h0, pow_zero, one_mul]
lemma int_prod_range_nonneg (m : ℤ) (n : ℕ) (hn : even n) :
0 ≤ ∏ k in finset.range n, (m - k) :=
begin
rcases hn with ⟨n, rfl⟩,
induction n with n ihn, { simp },
rw [nat.succ_eq_add_one, mul_add, mul_one, bit0, ← add_assoc, finset.prod_range_succ,
finset.prod_range_succ, mul_assoc],
refine mul_nonneg ihn _, generalize : (1 + 1) * n = k,
cases le_or_lt m k with hmk hmk,
{ have : m ≤ k + 1, from hmk.trans (lt_add_one ↑k).le,
exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) (sub_nonpos_of_le this) },
{ exact mul_nonneg (sub_nonneg_of_le hmk.le) (sub_nonneg_of_le hmk) }
end
lemma int_prod_range_pos {m : ℤ} {n : ℕ} (hn : even n) (hm : m ∉ Ico (0 : ℤ) n) :
0 < ∏ k in finset.range n, (m - k) :=
begin
refine (int_prod_range_nonneg m n hn).lt_of_ne (λ h, hm _),
rw [eq_comm, finset.prod_eq_zero_iff] at h,
obtain ⟨a, ha, h⟩ := h,
rw sub_eq_zero.1 h,
exact ⟨int.coe_zero_le _, int.coe_nat_lt.2 $ finset.mem_range.1 ha⟩,
end
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` -/
lemma convex_on_zpow (m : ℤ) : convex_on ℝ (Ioi 0) (λ x : ℝ, x^m) :=
begin
have : ∀ n : ℤ, differentiable_on ℝ (λ x, x ^ n) (Ioi (0 : ℝ)),
from λ n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),
apply convex_on_of_deriv2_nonneg (convex_Ioi 0);
try { simp only [interior_Ioi, deriv_zpow'] },
{ exact (this _).continuous_on },
{ exact this _ },
{ exact (this _).const_mul _ },
{ intros x hx,
simp only [iter_deriv_zpow, ← int.cast_coe_nat, ← int.cast_sub, ← int.cast_prod],
refine mul_nonneg (int.cast_nonneg.2 _) (zpow_nonneg (le_of_lt hx) _),
exact int_prod_range_nonneg _ _ (nat.even_bit0 1) }
end
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` except `0` and `1`. -/
lemma strict_convex_on_zpow {m : ℤ} (hm₀ : m ≠ 0) (hm₁ : m ≠ 1) :
strict_convex_on ℝ (Ioi 0) (λ x : ℝ, x^m) :=
begin
have : ∀ n : ℤ, differentiable_on ℝ (λ x, x ^ n) (Ioi (0 : ℝ)),
from λ n, differentiable_on_zpow _ _ (or.inl $ lt_irrefl _),
apply strict_convex_on_of_deriv2_pos (convex_Ioi 0),
{ exact (this _).continuous_on },
all_goals { rw interior_Ioi },
{ exact this _ },
intros x hx,
simp only [iter_deriv_zpow, ← int.cast_coe_nat, ← int.cast_sub, ← int.cast_prod],
refine mul_pos (int.cast_pos.2 _) (zpow_pos_of_pos hx _),
refine int_prod_range_pos (nat.even_bit0 1) (λ hm, _),
norm_cast at hm,
rw ←finset.coe_Ico at hm,
fin_cases hm,
{ exact hm₀ rfl },
{ exact hm₁ rfl }
end
lemma convex_on_rpow {p : ℝ} (hp : 1 ≤ p) : convex_on ℝ (Ici 0) (λ x : ℝ, x^p) :=
begin
have A : deriv (λ (x : ℝ), x ^ p) = λ x, p * x^(p-1), by { ext x, simp [hp] },
apply convex_on_of_deriv2_nonneg (convex_Ici 0),
{ exact continuous_on_id.rpow_const (λ x _, or.inr (zero_le_one.trans hp)) },
{ exact (differentiable_rpow_const hp).differentiable_on },
{ rw A,
assume x hx,
replace hx : x ≠ 0, by { simp at hx, exact ne_of_gt hx },
simp [differentiable_at.differentiable_within_at, hx] },
{ assume x hx,
replace hx : 0 < x, by simpa using hx,
suffices : 0 ≤ p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],
apply mul_nonneg (le_trans zero_le_one hp),
exact mul_nonneg (sub_nonneg_of_le hp) (rpow_nonneg_of_nonneg hx.le _) }
end
lemma strict_convex_on_rpow {p : ℝ} (hp : 1 < p) : strict_convex_on ℝ (Ici 0) (λ x : ℝ, x^p) :=
begin
have A : deriv (λ (x : ℝ), x ^ p) = λ x, p * x^(p-1), by { ext x, simp [hp.le] },
apply strict_convex_on_of_deriv2_pos (convex_Ici 0),
{ exact continuous_on_id.rpow_const (λ x _, or.inr (zero_le_one.trans hp.le)) },
{ exact (differentiable_rpow_const hp.le).differentiable_on },
rw interior_Ici,
rintro x (hx : 0 < x),
suffices : 0 < p * ((p - 1) * x ^ (p - 1 - 1)), by simpa [ne_of_gt hx, A],
exact mul_pos (zero_lt_one.trans hp) (mul_pos (sub_pos_of_lt hp) (rpow_pos_of_pos hx _)),
end
lemma strict_concave_on_log_Ioi : strict_concave_on ℝ (Ioi 0) log :=
begin
have h₁ : Ioi 0 ⊆ ({0} : set ℝ)ᶜ,
{ exact λ x (hx : 0 < x) (hx' : x = 0), hx.ne' hx' },
refine strict_concave_on_open_of_deriv2_neg (convex_Ioi 0) is_open_Ioi
(differentiable_on_log.mono h₁) (λ x (hx : 0 < x), _),
rw [function.iterate_succ, function.iterate_one],
change (deriv (deriv log)) x < 0,
rw [deriv_log', deriv_inv],
exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne'),
end
lemma strict_concave_on_log_Iio : strict_concave_on ℝ (Iio 0) log :=
begin
have h₁ : Iio 0 ⊆ ({0} : set ℝ)ᶜ,
{ exact λ x (hx : x < 0) (hx' : x = 0), hx.ne hx' },
refine strict_concave_on_open_of_deriv2_neg (convex_Iio 0) is_open_Iio
(differentiable_on_log.mono h₁) (λ x (hx : x < 0), _),
rw [function.iterate_succ, function.iterate_one],
change (deriv (deriv log)) x < 0,
rw [deriv_log', deriv_inv],
exact neg_neg_of_pos (inv_pos.2 $ sq_pos_of_ne_zero _ hx.ne),
end
open_locale real
lemma strict_concave_on_sin_Icc : strict_concave_on ℝ (Icc 0 π) sin :=
begin
apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_sin
differentiable_sin.differentiable_on (λ x hx, _),
rw interior_Icc at hx,
simp [sin_pos_of_mem_Ioo hx],
end
lemma strict_concave_on_cos_Icc : strict_concave_on ℝ (Icc (-(π/2)) (π/2)) cos :=
begin
apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_cos
differentiable_cos.differentiable_on (λ x hx, _),
rw interior_Icc at hx,
simp [cos_pos_of_mem_Ioo hx],
end
|
c141299ab37075a6dee72172e5aed8f81e2688d9 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/analysis/normed_space/complemented.lean | 6c7acac69e9e287656735dde637c0561b0790497 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,732 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.analysis.normed_space.banach
import Mathlib.analysis.normed_space.finite_dimension
import Mathlib.PostPort
universes u_1 u_2 u_3 u_4
namespace Mathlib
/-!
# Complemented subspaces of normed vector spaces
A submodule `p` of a topological module `E` over `R` is called *complemented* if there exists
a continuous linear projection `f : E →ₗ[R] p`, `∀ x : p, f x = x`. We prove that for
a closed subspace of a normed space this condition is equivalent to existence of a closed
subspace `q` such that `p ⊓ q = ⊥`, `p ⊔ q = ⊤`. We also prove that a subspace of finite codimension
is always a complemented subspace.
## Tags
complemented subspace, normed vector space
-/
namespace continuous_linear_map
theorem ker_closed_complemented_of_finite_dimensional_range {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {F : Type u_3} [normed_group F] [normed_space 𝕜 F] [complete_space 𝕜] (f : continuous_linear_map 𝕜 E F) [finite_dimensional 𝕜 ↥(range f)] : submodule.closed_complemented (ker f) := sorry
/-- If `f : E →L[R] F` and `g : E →L[R] G` are two surjective linear maps and
their kernels are complement of each other, then `x ↦ (f x, g x)` defines
a linear equivalence `E ≃L[R] F × G`. -/
def equiv_prod_of_surjective_of_is_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {F : Type u_3} [normed_group F] [normed_space 𝕜 F] {G : Type u_4} [normed_group G] [normed_space 𝕜 G] [complete_space E] [complete_space (F × G)] (f : continuous_linear_map 𝕜 E F) (g : continuous_linear_map 𝕜 E G) (hf : range f = ⊤) (hg : range g = ⊤) (hfg : is_compl (ker f) (ker g)) : continuous_linear_equiv 𝕜 E (F × G) :=
linear_equiv.to_continuous_linear_equiv_of_continuous
(linear_map.equiv_prod_of_surjective_of_is_compl (↑f) (↑g) hf hg hfg) sorry
@[simp] theorem coe_equiv_prod_of_surjective_of_is_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {F : Type u_3} [normed_group F] [normed_space 𝕜 F] {G : Type u_4} [normed_group G] [normed_space 𝕜 G] [complete_space E] [complete_space (F × G)] {f : continuous_linear_map 𝕜 E F} {g : continuous_linear_map 𝕜 E G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : is_compl (ker f) (ker g)) : ↑(equiv_prod_of_surjective_of_is_compl f g hf hg hfg) = ↑(continuous_linear_map.prod f g) :=
rfl
@[simp] theorem equiv_prod_of_surjective_of_is_compl_to_linear_equiv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {F : Type u_3} [normed_group F] [normed_space 𝕜 F] {G : Type u_4} [normed_group G] [normed_space 𝕜 G] [complete_space E] [complete_space (F × G)] {f : continuous_linear_map 𝕜 E F} {g : continuous_linear_map 𝕜 E G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : is_compl (ker f) (ker g)) : continuous_linear_equiv.to_linear_equiv (equiv_prod_of_surjective_of_is_compl f g hf hg hfg) =
linear_map.equiv_prod_of_surjective_of_is_compl (↑f) (↑g) hf hg hfg :=
rfl
@[simp] theorem equiv_prod_of_surjective_of_is_compl_apply {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] {F : Type u_3} [normed_group F] [normed_space 𝕜 F] {G : Type u_4} [normed_group G] [normed_space 𝕜 G] [complete_space E] [complete_space (F × G)] {f : continuous_linear_map 𝕜 E F} {g : continuous_linear_map 𝕜 E G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : is_compl (ker f) (ker g)) (x : E) : coe_fn (equiv_prod_of_surjective_of_is_compl f g hf hg hfg) x = (coe_fn f x, coe_fn g x) :=
rfl
end continuous_linear_map
namespace subspace
/-- If `q` is a closed complement of a closed subspace `p`, then `p × q` is continuously
isomorphic to `E`. -/
def prod_equiv_of_closed_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] (p : subspace 𝕜 E) (q : subspace 𝕜 E) (h : is_compl p q) (hp : is_closed ↑p) (hq : is_closed ↑q) : continuous_linear_equiv 𝕜 (↥p × ↥q) E :=
linear_equiv.to_continuous_linear_equiv_of_continuous (submodule.prod_equiv_of_is_compl p q h) sorry
/-- Projection to a closed submodule along a closed complement. -/
def linear_proj_of_closed_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] (p : subspace 𝕜 E) (q : subspace 𝕜 E) (h : is_compl p q) (hp : is_closed ↑p) (hq : is_closed ↑q) : continuous_linear_map 𝕜 E ↥p :=
continuous_linear_map.comp (continuous_linear_map.fst 𝕜 ↥p ↥q)
↑(continuous_linear_equiv.symm (prod_equiv_of_closed_compl p q h hp hq))
@[simp] theorem coe_prod_equiv_of_closed_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] {p : subspace 𝕜 E} {q : subspace 𝕜 E} (h : is_compl p q) (hp : is_closed ↑p) (hq : is_closed ↑q) : ⇑(prod_equiv_of_closed_compl p q h hp hq) = ⇑(submodule.prod_equiv_of_is_compl p q h) :=
rfl
@[simp] theorem coe_prod_equiv_of_closed_compl_symm {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] {p : subspace 𝕜 E} {q : subspace 𝕜 E} (h : is_compl p q) (hp : is_closed ↑p) (hq : is_closed ↑q) : ⇑(continuous_linear_equiv.symm (prod_equiv_of_closed_compl p q h hp hq)) =
⇑(linear_equiv.symm (submodule.prod_equiv_of_is_compl p q h)) :=
rfl
@[simp] theorem coe_continuous_linear_proj_of_closed_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] {p : subspace 𝕜 E} {q : subspace 𝕜 E} (h : is_compl p q) (hp : is_closed ↑p) (hq : is_closed ↑q) : ↑(linear_proj_of_closed_compl p q h hp hq) = submodule.linear_proj_of_is_compl p q h :=
rfl
@[simp] theorem coe_continuous_linear_proj_of_closed_compl' {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] {p : subspace 𝕜 E} {q : subspace 𝕜 E} (h : is_compl p q) (hp : is_closed ↑p) (hq : is_closed ↑q) : ⇑(linear_proj_of_closed_compl p q h hp hq) = ⇑(submodule.linear_proj_of_is_compl p q h) :=
rfl
theorem closed_complemented_of_closed_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] {p : subspace 𝕜 E} {q : subspace 𝕜 E} (h : is_compl p q) (hp : is_closed ↑p) (hq : is_closed ↑q) : submodule.closed_complemented p :=
Exists.intro (linear_proj_of_closed_compl p q h hp hq) (submodule.linear_proj_of_is_compl_apply_left h)
theorem closed_complemented_iff_has_closed_compl {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] {p : subspace 𝕜 E} : submodule.closed_complemented p ↔ is_closed ↑p ∧ ∃ (q : subspace 𝕜 E), ∃ (hq : is_closed ↑q), is_compl p q := sorry
theorem closed_complemented_of_quotient_finite_dimensional {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E] [normed_space 𝕜 E] [complete_space E] {p : subspace 𝕜 E} [complete_space 𝕜] [finite_dimensional 𝕜 (submodule.quotient p)] (hp : is_closed ↑p) : submodule.closed_complemented p := sorry
|
7ba96449acfaf63d144524d2f5b5701ed5baba75 | 54d7e71c3616d331b2ec3845d31deb08f3ff1dea | /library/init/algebra/functions.lean | 4bff4c63cc307f152fcb3a0baf55e8df11d326c7 | [
"Apache-2.0"
] | permissive | pachugupta/lean | 6f3305c4292288311cc4ab4550060b17d49ffb1d | 0d02136a09ac4cf27b5c88361750e38e1f485a1a | refs/heads/master | 1,611,110,653,606 | 1,493,130,117,000 | 1,493,167,649,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,299 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
prelude
import init.algebra.ordered_field
universe u
definition min {α : Type u} [decidable_linear_order α] (a b : α) : α := if a ≤ b then a else b
definition max {α : Type u} [decidable_linear_order α] (a b : α) : α := if a ≤ b then b else a
definition abs {α : Type u} [decidable_linear_ordered_comm_group α] (a : α) : α := max a (-a)
section
open decidable tactic
variables {α : Type u} [decidable_linear_order α]
private meta def min_tac_step : tactic unit :=
solve1 $ intros
>> `[unfold min max]
>> try `[simp_using_hs [if_pos, if_neg]]
>> try `[apply le_refl]
>> try `[apply le_of_not_le, assumption]
meta def tactic.interactive.min_tac (a b : interactive.parse lean.parser.qexpr) : tactic unit :=
`[apply @by_cases (%%a ≤ %%b), repeat {min_tac_step}]
lemma min_le_left (a b : α) : min a b ≤ a :=
by min_tac a b
lemma min_le_right (a b : α) : min a b ≤ b :=
by min_tac a b
lemma le_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) : c ≤ min a b :=
by min_tac a b
lemma le_max_left (a b : α) : a ≤ max a b :=
by min_tac a b
lemma le_max_right (a b : α) : b ≤ max a b :=
by min_tac a b
lemma max_le {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) : max a b ≤ c :=
by min_tac a b
lemma eq_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) (h₃ : ∀{d}, d ≤ a → d ≤ b → d ≤ c) : c = min a b :=
le_antisymm (le_min h₁ h₂) (h₃ (min_le_left a b) (min_le_right a b))
lemma min_comm (a b : α) : min a b = min b a :=
eq_min (min_le_right a b) (min_le_left a b) (λ c h₁ h₂, le_min h₂ h₁)
lemma min_assoc (a b c : α) : min (min a b) c = min a (min b c) :=
begin
apply eq_min,
{ apply le_trans, apply min_le_left, apply min_le_left },
{ apply le_min, apply le_trans, apply min_le_left, apply min_le_right, apply min_le_right },
{ intros d h₁ h₂, apply le_min, apply le_min h₁, apply le_trans h₂, apply min_le_left,
apply le_trans h₂, apply min_le_right }
end
lemma min_left_comm : ∀ (a b c : α), min a (min b c) = min b (min a c) :=
left_comm (@min α _) (@min_comm α _) (@min_assoc α _)
@[simp]
lemma min_self (a : α) : min a a = a :=
by min_tac a a
@[ematch]
lemma min_eq_left {a b : α} (h : a ≤ b) : min a b = a :=
begin apply eq.symm, apply eq_min (le_refl _) h, intros, assumption end
@[ematch]
lemma min_eq_right {a b : α} (h : b ≤ a) : min a b = b :=
eq.subst (min_comm b a) (min_eq_left h)
lemma eq_max {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) (h₃ : ∀{d}, a ≤ d → b ≤ d → c ≤ d) : c = max a b :=
le_antisymm (h₃ (le_max_left a b) (le_max_right a b)) (max_le h₁ h₂)
lemma max_comm (a b : α) : max a b = max b a :=
eq_max (le_max_right a b) (le_max_left a b) (λ c h₁ h₂, max_le h₂ h₁)
lemma max_assoc (a b c : α) : max (max a b) c = max a (max b c) :=
begin
apply eq_max,
{ apply le_trans, apply le_max_left a b, apply le_max_left },
{ apply max_le, apply le_trans, apply le_max_right a b, apply le_max_left, apply le_max_right },
{ intros d h₁ h₂, apply max_le, apply max_le h₁, apply le_trans (le_max_left _ _) h₂,
apply le_trans (le_max_right _ _) h₂}
end
lemma max_left_comm : ∀ (a b c : α), max a (max b c) = max b (max a c) :=
left_comm (@max α _) (@max_comm α _) (@max_assoc α _)
@[simp]
lemma max_self (a : α) : max a a = a :=
by min_tac a a
lemma max_eq_left {a b : α} (h : b ≤ a) : max a b = a :=
begin apply eq.symm, apply eq_max (le_refl _) h, intros, assumption end
lemma max_eq_right {a b : α} (h : a ≤ b) : max a b = b :=
eq.subst (max_comm b a) (max_eq_left h)
/- these rely on lt_of_lt -/
lemma min_eq_left_of_lt {a b : α} (h : a < b) : min a b = a :=
min_eq_left (le_of_lt h)
lemma min_eq_right_of_lt {a b : α} (h : b < a) : min a b = b :=
min_eq_right (le_of_lt h)
lemma max_eq_left_of_lt {a b : α} (h : b < a) : max a b = a :=
max_eq_left (le_of_lt h)
lemma max_eq_right_of_lt {a b : α} (h : a < b) : max a b = b :=
max_eq_right (le_of_lt h)
/- these use the fact that it is a linear ordering -/
lemma lt_min {a b c : α} (h₁ : a < b) (h₂ : a < c) : a < min b c :=
or.elim (le_or_gt b c)
(assume h : b ≤ c, by min_tac b c)
(assume h : b > c, by min_tac b c)
lemma max_lt {a b c : α} (h₁ : a < c) (h₂ : b < c) : max a b < c :=
or.elim (le_or_gt a b)
(assume h : a ≤ b, by min_tac a b)
(assume h : a > b, by min_tac a b)
end
section
variables {α : Type u} [decidable_linear_ordered_cancel_comm_monoid α]
lemma min_add_add_left (a b c : α) : min (a + b) (a + c) = a + min b c :=
eq.symm (eq_min
(show a + min b c ≤ a + b, from add_le_add_left (min_le_left _ _) _)
(show a + min b c ≤ a + c, from add_le_add_left (min_le_right _ _) _)
(take d,
suppose d ≤ a + b,
suppose d ≤ a + c,
decidable.by_cases
(suppose b ≤ c, by rwa [min_eq_left this])
(suppose ¬ b ≤ c, by rwa [min_eq_right (le_of_lt (lt_of_not_ge this))])))
lemma min_add_add_right (a b c : α) : min (a + c) (b + c) = min a b + c :=
begin rw [add_comm a c, add_comm b c, add_comm _ c], apply min_add_add_left end
lemma max_add_add_left (a b c : α) : max (a + b) (a + c) = a + max b c :=
eq.symm (eq_max
(add_le_add_left (le_max_left _ _) _)
(add_le_add_left (le_max_right _ _) _)
(take d,
suppose a + b ≤ d,
suppose a + c ≤ d,
decidable.by_cases
(suppose b ≤ c, by rwa [max_eq_right this])
(suppose ¬ b ≤ c, by rwa [max_eq_left (le_of_lt (lt_of_not_ge this))])))
lemma max_add_add_right (a b c : α) : max (a + c) (b + c) = max a b + c :=
begin rw [add_comm a c, add_comm b c, add_comm _ c], apply max_add_add_left end
end
section
variables {α : Type u} [decidable_linear_ordered_comm_group α]
lemma max_neg_neg (a b : α) : max (-a) (-b) = - min a b :=
eq.symm (eq_max
(show -a ≤ -(min a b), from neg_le_neg $ min_le_left a b)
(show -b ≤ -(min a b), from neg_le_neg $ min_le_right a b)
(take d,
assume H₁ : -a ≤ d,
assume H₂ : -b ≤ d,
have H : -d ≤ min a b,
from le_min (neg_le_of_neg_le H₁) (neg_le_of_neg_le H₂),
show -(min a b) ≤ d, from neg_le_of_neg_le H))
lemma min_eq_neg_max_neg_neg (a b : α) : min a b = - max (-a) (-b) :=
by rw [max_neg_neg, neg_neg]
lemma min_neg_neg (a b : α) : min (-a) (-b) = - max a b :=
by rw [min_eq_neg_max_neg_neg, neg_neg, neg_neg]
lemma max_eq_neg_min_neg_neg (a b : α) : max a b = - min (-a) (-b) :=
by rw [min_neg_neg, neg_neg]
end
section decidable_linear_ordered_comm_group
variables {α : Type u} [decidable_linear_ordered_comm_group α]
lemma abs_of_nonneg {a : α} (h : a ≥ 0) : abs a = a :=
have h' : -a ≤ a, from le_trans (neg_nonpos_of_nonneg h) h,
max_eq_left h'
lemma abs_of_pos {a : α} (h : a > 0) : abs a = a :=
abs_of_nonneg (le_of_lt h)
lemma abs_of_nonpos {a : α} (h : a ≤ 0) : abs a = -a :=
have h' : a ≤ -a, from le_trans h (neg_nonneg_of_nonpos h),
max_eq_right h'
lemma abs_of_neg {a : α} (h : a < 0) : abs a = -a :=
abs_of_nonpos (le_of_lt h)
lemma abs_zero : abs 0 = (0:α) :=
abs_of_nonneg (le_refl _)
lemma abs_neg (a : α) : abs (-a) = abs a :=
begin unfold abs, rw [max_comm, neg_neg] end
lemma abs_pos_of_pos {a : α} (h : a > 0) : abs a > 0 :=
by rwa (abs_of_pos h)
lemma abs_pos_of_neg {a : α} (h : a < 0) : abs a > 0 :=
abs_neg a ▸ abs_pos_of_pos (neg_pos_of_neg h)
lemma abs_sub (a b : α) : abs (a - b) = abs (b - a) :=
by rw [-neg_sub, abs_neg]
lemma ne_zero_of_abs_ne_zero {a : α} (h : abs a ≠ 0) : a ≠ 0 :=
assume ha, h (eq.symm ha ▸ abs_zero)
/- these assume a linear order -/
lemma eq_zero_of_neg_eq {a : α} (h : -a = a) : a = 0 :=
match lt_trichotomy a 0 with
| or.inl h₁ :=
have a > 0, from h ▸ neg_pos_of_neg h₁,
absurd h₁ (lt_asymm this)
| or.inr (or.inl h₁) := h₁
| or.inr (or.inr h₁) :=
have a < 0, from h ▸ neg_neg_of_pos h₁,
absurd h₁ (lt_asymm this)
end
lemma abs_nonneg (a : α) : abs a ≥ 0 :=
or.elim (le_total 0 a)
(assume h : 0 ≤ a, by rwa (abs_of_nonneg h))
(assume h : a ≤ 0, calc
0 ≤ -a : neg_nonneg_of_nonpos h
... = abs a : eq.symm (abs_of_nonpos h))
lemma abs_abs (a : α) : abs (abs a) = abs a :=
abs_of_nonneg $ abs_nonneg a
lemma le_abs_self (a : α) : a ≤ abs a :=
or.elim (le_total 0 a)
(assume h : 0 ≤ a,
begin rw [abs_of_nonneg h], apply le_refl end)
(assume h : a ≤ 0, le_trans h $ abs_nonneg a)
lemma neg_le_abs_self (a : α) : -a ≤ abs a :=
abs_neg a ▸ le_abs_self (-a)
lemma eq_zero_of_abs_eq_zero {a : α} (h : abs a = 0) : a = 0 :=
have h₁ : a ≤ 0, from h ▸ le_abs_self a,
have h₂ : -a ≤ 0, from h ▸ abs_neg a ▸ le_abs_self (-a),
le_antisymm h₁ (nonneg_of_neg_nonpos h₂)
lemma eq_of_abs_sub_eq_zero {a b : α} (h : abs (a - b) = 0) : a = b :=
have a - b = 0, from eq_zero_of_abs_eq_zero h,
show a = b, from eq_of_sub_eq_zero this
lemma abs_pos_of_ne_zero {a : α} (h : a ≠ 0) : abs a > 0 :=
or.elim (lt_or_gt_of_ne h) abs_pos_of_neg abs_pos_of_pos
lemma abs_by_cases (P : α → Prop) {a : α} (h1 : P a) (h2 : P (-a)) : P (abs a) :=
or.elim (le_total 0 a)
(assume h : 0 ≤ a, eq.symm (abs_of_nonneg h) ▸ h1)
(assume h : a ≤ 0, eq.symm (abs_of_nonpos h) ▸ h2)
lemma abs_le_of_le_of_neg_le {a b : α} (h1 : a ≤ b) (h2 : -a ≤ b) : abs a ≤ b :=
abs_by_cases (λ x : α, x ≤ b) h1 h2
lemma abs_lt_of_lt_of_neg_lt {a b : α} (h1 : a < b) (h2 : -a < b) : abs a < b :=
abs_by_cases (λ x : α, x < b) h1 h2
private lemma aux1 {a b : α} (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) : by apply le_refl
... = a + b : by rw (abs_of_nonneg h1)
... = abs a + b : by rw (abs_of_nonneg h2)
... = abs a + abs b : by rw (abs_of_nonneg h3))
(assume h3 : ¬ b ≥ 0,
have h4 : b ≤ 0, from le_of_lt (lt_of_not_ge h3),
calc
abs (a + b) = a + b : by rw (abs_of_nonneg h1)
... = abs a + b : by rw (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 rw (abs_of_nonpos h4))
private lemma aux2 {a b : α} (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,
begin
note aux := add_lt_add_of_lt_of_le h4 h2,
rwa [add_zero] at aux
end,
not_lt_of_ge h1 h5,
aux1 h1 (le_of_not_gt h3))
(assume h2 : 0 ≤ b,
begin
assert h3 : abs (b + a) ≤ abs b + abs a,
begin
rw add_comm at h1,
exact aux1 h1 h2
end,
rw [add_comm, add_comm (abs a)],
exact h3
end)
lemma abs_add_le_abs_add_abs (a b : α) : 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,
have h3 : -a + -b = -(a + b), by rw neg_add,
have h4 : -(a + b) ≥ 0, from neg_nonneg_of_nonpos h2,
have h5 : -a + -b ≥ 0, begin rw -h3 at h4, exact h4 end,
calc
abs (a + b) = abs (-a + -b) : by rw [-abs_neg, neg_add]
... ≤ abs (-a) + abs (-b) : aux2 h5
... = abs a + abs b : by rw [abs_neg, abs_neg])
lemma abs_sub_abs_le_abs_sub (a b : α) : 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 rw sub_add_cancel
... = abs (a - b + b) : by rw sub_add_cancel
... ≤ abs (a - b) + abs b : by apply abs_add_le_abs_add_abs,
le_of_add_le_add_right h1
lemma abs_sub_le (a b c : α) : abs (a - c) ≤ abs (a - b) + abs (b - c) :=
calc
abs (a - c) = abs (a - b + (b - c)) : by rw [sub_eq_add_neg, sub_eq_add_neg, sub_eq_add_neg,
add_assoc, neg_add_cancel_left]
... ≤ abs (a - b) + abs (b - c) : by apply abs_add_le_abs_add_abs
lemma abs_add_three (a b c : α) : abs (a + b + c) ≤ abs a + abs b + abs c :=
begin
apply le_trans,
apply abs_add_le_abs_add_abs,
apply le_trans,
apply add_le_add_right,
apply abs_add_le_abs_add_abs,
apply le_refl
end
lemma dist_bdd_within_interval {a b lb ub : α} (h : lb < ub) (hal : lb ≤ a) (hau : a ≤ ub)
(hbl : lb ≤ b) (hbu : b ≤ ub) : abs (a - b) ≤ ub - lb :=
begin
cases (decidable.em (b ≤ a)) with hba hba,
rw (abs_of_nonneg (sub_nonneg_of_le hba)),
apply sub_le_sub,
apply hau,
apply hbl,
rw [abs_of_neg (sub_neg_of_lt (lt_of_not_ge hba)), neg_sub],
apply sub_le_sub,
apply hbu,
apply hal
end
end decidable_linear_ordered_comm_group
section decidable_linear_ordered_comm_ring
variables {α : Type u} [decidable_linear_ordered_comm_ring α]
lemma abs_mul (a b : α) : abs (a * b) = abs a * abs b :=
or.elim (le_total 0 a)
(assume h1 : 0 ≤ a,
or.elim (le_total 0 b)
(assume h2 : 0 ≤ b,
calc
abs (a * b) = a * b : abs_of_nonneg (mul_nonneg h1 h2)
... = abs a * b : by rw (abs_of_nonneg h1)
... = abs a * abs b : by rw (abs_of_nonneg h2))
(assume h2 : b ≤ 0,
calc
abs (a * b) = -(a * b) : abs_of_nonpos (mul_nonpos_of_nonneg_of_nonpos h1 h2)
... = a * -b : by rw neg_mul_eq_mul_neg
... = abs a * -b : by rw (abs_of_nonneg h1)
... = abs a * abs b : by rw (abs_of_nonpos h2)))
(assume h1 : a ≤ 0,
or.elim (le_total 0 b)
(assume h2 : 0 ≤ b,
calc
abs (a * b) = -(a * b) : abs_of_nonpos (mul_nonpos_of_nonpos_of_nonneg h1 h2)
... = -a * b : by rw neg_mul_eq_neg_mul
... = abs a * b : by rw (abs_of_nonpos h1)
... = abs a * abs b : by rw (abs_of_nonneg h2))
(assume h2 : b ≤ 0,
calc
abs (a * b) = a * b : abs_of_nonneg (mul_nonneg_of_nonpos_of_nonpos h1 h2)
... = -a * -b : by rw neg_mul_neg
... = abs a * -b : by rw (abs_of_nonpos h1)
... = abs a * abs b : by rw (abs_of_nonpos h2)))
lemma abs_mul_abs_self (a : α) : abs a * abs a = a * a :=
abs_by_cases (λ x, x * x = a * a) rfl (neg_mul_neg a a)
lemma abs_mul_self (a : α) : abs (a * a) = a * a :=
by rw [abs_mul, abs_mul_abs_self]
lemma sub_le_of_abs_sub_le_left {a b c : α} (h : abs (a - b) ≤ c) : b - c ≤ a :=
if hz : 0 ≤ a - b then
(calc
a ≥ b : le_of_sub_nonneg hz
... ≥ b - c : sub_le_self _ (le_trans (abs_nonneg _) h))
else
have habs : b - a ≤ c, by rwa [abs_of_neg (lt_of_not_ge hz), neg_sub] at h,
have habs' : b ≤ c + a, from le_add_of_sub_right_le habs,
sub_left_le_of_le_add habs'
lemma sub_le_of_abs_sub_le_right {a b c : α} (h : abs (a - b) ≤ c) : a - c ≤ b :=
sub_le_of_abs_sub_le_left (abs_sub a b ▸ h)
lemma sub_lt_of_abs_sub_lt_left {a b c : α} (h : abs (a - b) < c) : b - c < a :=
if hz : 0 ≤ a - b then
(calc
a ≥ b : le_of_sub_nonneg hz
... > b - c : sub_lt_self _ (lt_of_le_of_lt (abs_nonneg _) h))
else
have habs : b - a < c, by rwa [abs_of_neg (lt_of_not_ge hz), neg_sub] at h,
have habs' : b < c + a, from lt_add_of_sub_right_lt habs,
sub_left_lt_of_lt_add habs'
lemma sub_lt_of_abs_sub_lt_right {a b c : α} (h : abs (a - b) < c) : a - c < b :=
sub_lt_of_abs_sub_lt_left (abs_sub a b ▸ h)
lemma abs_sub_square (a b : α) : abs (a - b) * abs (a - b) = a * a + b * b - (1 + 1) * a * b :=
begin
rw abs_mul_abs_self,
simp [left_distrib, right_distrib]
end
lemma eq_zero_of_mul_self_add_mul_self_eq_zero {x y : α} (h : x * x + y * y = 0) : x = 0 :=
have x * x ≤ (0 : α), from calc
x * x ≤ x * x + y * y : le_add_of_nonneg_right (mul_self_nonneg y)
... = 0 : h,
eq_zero_of_mul_self_eq_zero (le_antisymm this (mul_self_nonneg x))
lemma abs_abs_sub_abs_le_abs_sub (a b : α) : abs (abs a - abs b) ≤ abs (a - b) :=
begin
apply nonneg_le_nonneg_of_squares_le,
repeat {apply abs_nonneg},
repeat {rw abs_sub_square},
repeat {rw abs_abs},
repeat {rw abs_mul_abs_self},
apply sub_le_sub_left,
repeat {rw mul_assoc},
apply mul_le_mul_of_nonneg_left,
rw -abs_mul,
apply le_abs_self,
apply le_of_lt,
apply add_pos,
apply zero_lt_one,
apply zero_lt_one
end
end decidable_linear_ordered_comm_ring
section discrete_linear_ordered_field
variables {α : Type u} [discrete_linear_ordered_field α]
lemma abs_div (a b : α) : abs (a / b) = abs a / abs b :=
decidable.by_cases
(suppose h : b = 0, by rw [h, abs_zero, div_zero, div_zero, abs_zero])
(suppose h : b ≠ 0,
have h₁ : abs b ≠ 0, from
assume h₂, h (eq_zero_of_abs_eq_zero h₂),
eq_div_of_mul_eq _ _ h₁
(show abs (a / b) * abs b = abs a, by rw [-abs_mul, div_mul_cancel _ h]))
lemma abs_one_div (a : α) : abs (1 / a) = 1 / abs a :=
by rw [abs_div, abs_of_nonneg (zero_le_one : 1 ≥ (0 : α))]
end discrete_linear_ordered_field
|
327cdcb24b9222041b976039a4fadd7559a8dedb | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /09_Type_Classes.org.8.lean | f5cfac706fc218cf47713210fc4163ab31f04a3a | [] | 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 | 697 | lean | import standard
namespace hide
inductive inhabited [class] (A : Type) : Type :=
mk : A → inhabited A
definition Prop.is_inhabited [instance] : inhabited Prop :=
inhabited.mk true
definition bool.is_inhabited [instance] : inhabited bool :=
inhabited.mk bool.tt
definition nat.is_inhabited [instance] : inhabited nat :=
inhabited.mk nat.zero
definition unit.is_inhabited [instance] : inhabited unit :=
inhabited.mk unit.star
definition default (A : Type) [H : inhabited A] : A :=
inhabited.rec (λ a, a) H
-- BEGIN
example : default Prop = true := rfl
example : default nat = nat.zero := rfl
example : default bool = bool.tt := rfl
example : default unit = unit.star := rfl
-- END
end hide
|
28e67c5be04ae8a73442f2ef7c34f2f778abe14d | d534932ed7c1eba03b537c377a4f8961acd41e99 | /examples/http-server/lakefile.lean | 14b02caefd5eac92e226c2264c37029c6519ecfc | [
"Apache-2.0"
] | permissive | Adminixtrator/lean4-socket | d7e321d547df6545d0c085d310be8f2c41c44ddb | b313041f2e75f4ad8320ab66d7e2afafd2202318 | refs/heads/main | 1,692,582,696,753 | 1,633,439,398,000 | 1,633,439,523,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 135 | lean | import Lake
open Lake DSL
package http_server where
dependencies := #[{
name := `socket
src := Source.path "../../lake"
}] |
f519a67fa421967bf693422c953ae35e2cab426f | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/list/pairwise.lean | 484f2fa4dee070dadd1b3f5386c053581c6e0157 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 17,422 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.list.count
import data.list.lex
import logic.pairwise
import logic.relation
/-!
# Pairwise relations on a list
This file provides basic results about `list.pairwise` and `list.pw_filter` (definitions are in
`data.list.defs`).
`pairwise r [a 0, ..., a (n - 1)]` means `∀ i j, i < j → r (a i) (a j)`. For example,
`pairwise (≠) l` means that all elements of `l` are distinct, and `pairwise (<) l` means that `l`
is strictly increasing.
`pw_filter r l` is the list obtained by iteratively adding each element of `l` that doesn't break
the pairwiseness of the list we have so far. It thus yields `l'` a maximal sublist of `l` such that
`pairwise r l'`.
## Tags
sorted, nodup
-/
open nat function
namespace list
variables {α β : Type*} {R S T: α → α → Prop} {a : α} {l : list α}
mk_iff_of_inductive_prop list.pairwise list.pairwise_iff
/-! ### Pairwise -/
lemma rel_of_pairwise_cons (p : (a :: l).pairwise R) : ∀ {a'}, a' ∈ l → R a a' :=
(pairwise_cons.1 p).1
lemma pairwise.of_cons (p : (a :: l).pairwise R) : pairwise R l := (pairwise_cons.1 p).2
theorem pairwise.tail : ∀ {l : list α} (p : pairwise R l), pairwise R l.tail
| [] h := h
| (a :: l) h := h.of_cons
theorem pairwise.drop : ∀ {l : list α} {n : ℕ}, list.pairwise R l → list.pairwise R (l.drop n)
| _ 0 h := h
| [] (n + 1) h := list.pairwise.nil
| (a :: l) (n + 1) h := pairwise.drop (pairwise_cons.mp h).right
theorem pairwise.imp_of_mem {S : α → α → Prop} {l : list α}
(H : ∀ {a b}, a ∈ l → b ∈ l → R a b → S a b) (p : pairwise R l) : pairwise S l :=
begin
induction p with a l r p IH generalizing H; constructor,
{ exact ball.imp_right
(λ x h, H (mem_cons_self _ _) (mem_cons_of_mem _ h)) r },
{ exact IH (λ a b m m', H
(mem_cons_of_mem _ m) (mem_cons_of_mem _ m')) }
end
lemma pairwise.imp (H : ∀ a b, R a b → S a b) : pairwise R l → pairwise S l :=
pairwise.imp_of_mem (λ a b _ _, H a b)
lemma pairwise_and_iff : l.pairwise (λ a b, R a b ∧ S a b) ↔ l.pairwise R ∧ l.pairwise S :=
⟨λ h, ⟨h.imp (λ a b h, h.1), h.imp (λ a b h, h.2)⟩,
λ ⟨hR, hS⟩, begin
clear_, induction hR with a l R1 R2 IH;
simp only [pairwise.nil, pairwise_cons] at *,
exact ⟨λ b bl, ⟨R1 b bl, hS.1 b bl⟩, IH hS.2⟩
end⟩
lemma pairwise.and (hR : l.pairwise R) (hS : l.pairwise S) : l.pairwise (λ a b, R a b ∧ S a b) :=
pairwise_and_iff.2 ⟨hR, hS⟩
lemma pairwise.imp₂ (H : ∀ a b, R a b → S a b → T a b) (hR : l.pairwise R) (hS : l.pairwise S) :
l.pairwise T :=
(hR.and hS).imp $ λ a b, and.rec (H a b)
theorem pairwise.iff_of_mem {S : α → α → Prop} {l : list α}
(H : ∀ {a b}, a ∈ l → b ∈ l → (R a b ↔ S a b)) : pairwise R l ↔ pairwise S l :=
⟨pairwise.imp_of_mem (λ a b m m', (H m m').1),
pairwise.imp_of_mem (λ a b m m', (H m m').2)⟩
theorem pairwise.iff {S : α → α → Prop}
(H : ∀ a b, R a b ↔ S a b) {l : list α} : pairwise R l ↔ pairwise S l :=
pairwise.iff_of_mem (λ a b _ _, H a b)
theorem pairwise_of_forall {l : list α} (H : ∀ x y, R x y) : pairwise R l :=
by induction l; [exact pairwise.nil,
simp only [*, pairwise_cons, forall_2_true_iff, and_true]]
theorem pairwise.and_mem {l : list α} :
pairwise R l ↔ pairwise (λ x y, x ∈ l ∧ y ∈ l ∧ R x y) l :=
pairwise.iff_of_mem (by simp only [true_and, iff_self, forall_2_true_iff] {contextual := tt})
theorem pairwise.imp_mem {l : list α} :
pairwise R l ↔ pairwise (λ x y, x ∈ l → y ∈ l → R x y) l :=
pairwise.iff_of_mem
(by simp only [forall_prop_of_true, iff_self, forall_2_true_iff] {contextual := tt})
protected lemma pairwise.sublist : Π {l₁ l₂ : list α}, l₁ <+ l₂ → pairwise R l₂ → pairwise R l₁
| ._ ._ sublist.slnil h := h
| ._ ._ (sublist.cons l₁ l₂ a s) (pairwise.cons i h) := h.sublist s
| ._ ._ (sublist.cons2 l₁ l₂ a s) (pairwise.cons i h) :=
(h.sublist s).cons (ball.imp_left s.subset i)
lemma pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : l.pairwise R)
(h₃ : l.pairwise (flip R)) :
∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y :=
begin
induction l with a l ih,
{ exact forall_mem_nil _ },
rw pairwise_cons at h₂ h₃,
rintro x (rfl | hx) y (rfl | hy),
{ exact h₁ _ (l.mem_cons_self _) },
{ exact h₂.1 _ hy },
{ exact h₃.1 _ hx },
{ exact ih (λ x hx, h₁ _ $ mem_cons_of_mem _ hx) h₂.2 h₃.2 hx hy }
end
lemma pairwise.forall_of_forall (H : symmetric R) (H₁ : ∀ x ∈ l, R x x) (H₂ : l.pairwise R) :
∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y :=
H₂.forall_of_forall_of_flip H₁ $ by rwa H.flip_eq
lemma pairwise.forall (hR : symmetric R) (hl : l.pairwise R) :
∀ ⦃a⦄, a ∈ l → ∀ ⦃b⦄, b ∈ l → a ≠ b → R a b :=
pairwise.forall_of_forall
(λ a b h hne, hR (h hne.symm))
(λ _ _ h, (h rfl).elim)
(hl.imp $ λ _ _ h _, h)
lemma pairwise.set_pairwise (hl : pairwise R l) (hr : symmetric R) : {x | x ∈ l}.pairwise R :=
hl.forall hr
theorem pairwise_singleton (R) (a : α) : pairwise R [a] :=
by simp only [pairwise_cons, mem_singleton, forall_prop_of_false (not_mem_nil _), forall_true_iff,
pairwise.nil, and_true]
theorem pairwise_pair {a b : α} : pairwise R [a, b] ↔ R a b :=
by simp only [pairwise_cons, mem_singleton, forall_eq, forall_prop_of_false (not_mem_nil _),
forall_true_iff, pairwise.nil, and_true]
theorem pairwise_append {l₁ l₂ : list α} : pairwise R (l₁++l₂) ↔
pairwise R l₁ ∧ pairwise R l₂ ∧ ∀ x ∈ l₁, ∀ y ∈ l₂, R x y :=
by induction l₁ with x l₁ IH; [simp only [list.pairwise.nil, forall_prop_of_false (not_mem_nil _),
forall_true_iff, and_true, true_and, nil_append],
simp only [cons_append, pairwise_cons, forall_mem_append, IH, forall_mem_cons, forall_and_distrib,
and_assoc, and.left_comm]]
theorem pairwise_append_comm (s : symmetric R) {l₁ l₂ : list α} :
pairwise R (l₁++l₂) ↔ pairwise R (l₂++l₁) :=
have ∀ l₁ l₂ : list α,
(∀ (x : α), x ∈ l₁ → ∀ (y : α), y ∈ l₂ → R x y) →
(∀ (x : α), x ∈ l₂ → ∀ (y : α), y ∈ l₁ → R x y),
from λ l₁ l₂ a x xm y ym, s (a y ym x xm),
by simp only [pairwise_append, and.left_comm]; rw iff.intro (this l₁ l₂) (this l₂ l₁)
theorem pairwise_middle (s : symmetric R) {a : α} {l₁ l₂ : list α} :
pairwise R (l₁ ++ a :: l₂) ↔ pairwise R (a :: (l₁++l₂)) :=
show pairwise R (l₁ ++ ([a] ++ l₂)) ↔ pairwise R ([a] ++ l₁ ++ l₂),
by rw [← append_assoc, pairwise_append, @pairwise_append _ _ ([a] ++ l₁), pairwise_append_comm s];
simp only [mem_append, or_comm]
theorem pairwise_map (f : β → α) :
∀ {l : list β}, pairwise R (map f l) ↔ pairwise (λ a b : β, R (f a) (f b)) l
| [] := by simp only [map, pairwise.nil]
| (b :: l) :=
have (∀ a b', b' ∈ l → f b' = a → R (f b) a) ↔ ∀ (b' : β), b' ∈ l → R (f b) (f b'), from
forall_swap.trans $ forall_congr $ λ a, forall_swap.trans $ by simp only [forall_eq'],
by simp only [map, pairwise_cons, mem_map, exists_imp_distrib, and_imp, this, pairwise_map]
lemma pairwise.of_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b)
(p : pairwise S (map f l)) : pairwise R l :=
((pairwise_map f).1 p).imp H
lemma pairwise.map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b))
(p : pairwise R l) : pairwise S (map f l) :=
(pairwise_map f).2 $ p.imp H
theorem pairwise_filter_map (f : β → option α) {l : list β} :
pairwise R (filter_map f l) ↔ pairwise (λ a a' : β, ∀ (b ∈ f a) (b' ∈ f a'), R b b') l :=
let S (a a' : β) := ∀ (b ∈ f a) (b' ∈ f a'), R b b' in
begin
simp only [option.mem_def], induction l with a l IH,
{ simp only [filter_map, pairwise.nil] },
cases e : f a with b,
{ rw [filter_map_cons_none _ _ e, IH, pairwise_cons],
simp only [e, forall_prop_of_false not_false, forall_3_true_iff, true_and] },
rw [filter_map_cons_some _ _ _ e],
simp only [pairwise_cons, mem_filter_map, exists_imp_distrib, and_imp, IH, e, forall_eq'],
show (∀ (a' : α) (x : β), x ∈ l → f x = some a' → R b a') ∧ pairwise S l ↔
(∀ (a' : β), a' ∈ l → ∀ (b' : α), f a' = some b' → R b b') ∧ pairwise S l,
from and_congr ⟨λ h b mb a ma, h a b mb ma, λ h a b mb ma, h b mb a ma⟩ iff.rfl
end
theorem pairwise.filter_map {S : β → β → Prop} (f : α → option β)
(H : ∀ (a a' : α), R a a' → ∀ (b ∈ f a) (b' ∈ f a'), S b b') {l : list α}
(p : pairwise R l) : pairwise S (filter_map f l) :=
(pairwise_filter_map _).2 $ p.imp H
theorem pairwise_filter (p : α → Prop) [decidable_pred p] {l : list α} :
pairwise R (filter p l) ↔ pairwise (λ x y, p x → p y → R x y) l :=
begin
rw [← filter_map_eq_filter, pairwise_filter_map],
apply pairwise.iff, intros, simp only [option.mem_def, option.guard_eq_some, and_imp, forall_eq'],
end
lemma pairwise.filter (p : α → Prop) [decidable_pred p] : pairwise R l → pairwise R (filter p l) :=
pairwise.sublist (filter_sublist _)
theorem pairwise_pmap {p : β → Prop} {f : Π b, p b → α} {l : list β} (h : ∀ x ∈ l, p x) :
pairwise R (l.pmap f h) ↔
pairwise (λ b₁ b₂, ∀ (h₁ : p b₁) (h₂ : p b₂), R (f b₁ h₁) (f b₂ h₂)) l :=
begin
induction l with a l ihl, { simp },
obtain ⟨ha, hl⟩ : p a ∧ ∀ b, b ∈ l → p b, by simpa using h,
simp only [ihl hl, pairwise_cons, bex_imp_distrib, pmap, and.congr_left_iff, mem_pmap],
refine λ _, ⟨λ H b hb hpa hpb, H _ _ hb rfl, _⟩,
rintro H _ b hb rfl,
exact H b hb _ _
end
theorem pairwise.pmap {l : list α} (hl : pairwise R l)
{p : α → Prop} {f : Π a, p a → β} (h : ∀ x ∈ l, p x) {S : β → β → Prop}
(hS : ∀ ⦃x⦄ (hx : p x) ⦃y⦄ (hy : p y), R x y → S (f x hx) (f y hy)) :
pairwise S (l.pmap f h) :=
begin
refine (pairwise_pmap h).2 (pairwise.imp_of_mem _ hl),
intros, apply hS, assumption
end
theorem pairwise_join {L : list (list α)} : pairwise R (join L) ↔
(∀ l ∈ L, pairwise R l) ∧ pairwise (λ l₁ l₂, ∀ (x ∈ l₁) (y ∈ l₂), R x y) L :=
begin
induction L with l L IH,
{simp only [join, pairwise.nil, forall_prop_of_false (not_mem_nil _), forall_const, and_self]},
have : (∀ (x : α), x ∈ l → ∀ (y : α) (x_1 : list α), x_1 ∈ L → y ∈ x_1 → R x y) ↔
∀ (a' : list α), a' ∈ L → ∀ (x : α), x ∈ l → ∀ (y : α), y ∈ a' → R x y :=
⟨λ h a b c d e, h c d e a b, λ h c d e a b, h a b c d e⟩,
simp only [join, pairwise_append, IH, mem_join, exists_imp_distrib, and_imp, this,
forall_mem_cons, pairwise_cons],
simp only [and_assoc, and_comm, and.left_comm],
end
lemma pairwise_bind {R : β → β → Prop} {l : list α} {f : α → list β} :
list.pairwise R (l.bind f) ↔
(∀ a ∈ l, pairwise R (f a)) ∧ pairwise (λ a₁ a₂, ∀ (x ∈ f a₁) (y ∈ f a₂), R x y) l :=
by simp [list.bind, list.pairwise_join, list.mem_map, list.pairwise_map]
@[simp] theorem pairwise_reverse : ∀ {R} {l : list α},
pairwise R (reverse l) ↔ pairwise (λ x y, R y x) l :=
suffices ∀ {R l}, @pairwise α R l → pairwise (λ x y, R y x) (reverse l),
from λ R l, ⟨λ p, reverse_reverse l ▸ this p, this⟩,
λ R l p, by induction p with a l h p IH;
[apply pairwise.nil, simpa only [reverse_cons, pairwise_append, IH,
pairwise_cons, forall_prop_of_false (not_mem_nil _), forall_true_iff,
pairwise.nil, mem_reverse, mem_singleton, forall_eq, true_and] using h]
lemma pairwise_of_reflexive_on_dupl_of_forall_ne [decidable_eq α] {l : list α} {r : α → α → Prop}
(hr : ∀ a, 1 < count a l → r a a)
(h : ∀ (a ∈ l) (b ∈ l), a ≠ b → r a b) : l.pairwise r :=
begin
induction l with hd tl IH,
{ simp },
{ rw list.pairwise_cons,
split,
{ intros x hx,
by_cases H : hd = x,
{ rw H,
refine hr _ _,
simpa [count_cons, H, nat.succ_lt_succ_iff, count_pos] using hx },
{ exact h hd (mem_cons_self _ _) x (mem_cons_of_mem _ hx) H } },
{ refine IH _ _,
{ intros x hx,
refine hr _ _,
rw count_cons,
split_ifs,
{ exact hx.trans (nat.lt_succ_self _) },
{ exact hx } },
{ intros x hx y hy,
exact h x (mem_cons_of_mem _ hx) y (mem_cons_of_mem _ hy) } } }
end
lemma pairwise_of_forall_mem_list {l : list α} {r : α → α → Prop} (h : ∀ (a ∈ l) (b ∈ l), r a b) :
l.pairwise r :=
begin
classical,
refine pairwise_of_reflexive_on_dupl_of_forall_ne (λ a ha', _) (λ a ha b hb _, h a ha b hb),
have ha := list.one_le_count_iff_mem.1 ha'.le,
exact h a ha a ha
end
lemma pairwise_of_reflexive_of_forall_ne {l : list α} {r : α → α → Prop}
(hr : reflexive r) (h : ∀ (a ∈ l) (b ∈ l), a ≠ b → r a b) : l.pairwise r :=
by { classical, exact pairwise_of_reflexive_on_dupl_of_forall_ne (λ _ _, hr _) h }
theorem pairwise_iff_nth_le {R} : ∀ {l : list α},
pairwise R l ↔ ∀ i j (h₁ : j < length l) (h₂ : i < j),
R (nth_le l i (lt_trans h₂ h₁)) (nth_le l j h₁)
| [] := by simp only [pairwise.nil, true_iff]; exact λ i j h, (nat.not_lt_zero j).elim h
| (a :: l) := begin
rw [pairwise_cons, pairwise_iff_nth_le],
refine ⟨λ H i j h₁ h₂, _, λ H, ⟨λ a' m, _,
λ i j h₁ h₂, H _ _ (succ_lt_succ h₁) (succ_lt_succ h₂)⟩⟩,
{ cases j with j, {exact (nat.not_lt_zero _).elim h₂},
cases i with i,
{ exact H.1 _ (nth_le_mem l _ _) },
{ exact H.2 _ _ (lt_of_succ_lt_succ h₁) (lt_of_succ_lt_succ h₂) } },
{ rcases nth_le_of_mem m with ⟨n, h, rfl⟩,
exact H _ _ (succ_lt_succ h) (succ_pos _) }
end
lemma pairwise_repeat {α : Type*} {r : α → α → Prop} {x : α} (hx : r x x) :
∀ (n : ℕ), pairwise r (repeat x n)
| 0 := by simp
| (n+1) := by simp [hx, mem_repeat, pairwise_repeat n]
/-! ### Pairwise filtering -/
variable [decidable_rel R]
@[simp] theorem pw_filter_nil : pw_filter R [] = [] := rfl
@[simp] theorem pw_filter_cons_of_pos {a : α} {l : list α} (h : ∀ b ∈ pw_filter R l, R a b) :
pw_filter R (a :: l) = a :: pw_filter R l := if_pos h
@[simp] theorem pw_filter_cons_of_neg {a : α} {l : list α} (h : ¬ ∀ b ∈ pw_filter R l, R a b) :
pw_filter R (a :: l) = pw_filter R l := if_neg h
theorem pw_filter_map (f : β → α) :
Π (l : list β), pw_filter R (map f l) = map f (pw_filter (λ x y, R (f x) (f y)) l)
| [] := rfl
| (x :: xs) :=
if h : ∀ b ∈ pw_filter R (map f xs), R (f x) b
then have h' : ∀ (b : β), b ∈ pw_filter (λ (x y : β), R (f x) (f y)) xs → R (f x) (f b),
from λ b hb, h _ (by rw [pw_filter_map]; apply mem_map_of_mem _ hb),
by rw [map,pw_filter_cons_of_pos h,pw_filter_cons_of_pos h',pw_filter_map,map]
else have h' : ¬∀ (b : β), b ∈ pw_filter (λ (x y : β), R (f x) (f y)) xs → R (f x) (f b),
from λ hh, h $ λ a ha,
by { rw [pw_filter_map,mem_map] at ha, rcases ha with ⟨b,hb₀,hb₁⟩,
subst a, exact hh _ hb₀, },
by rw [map,pw_filter_cons_of_neg h,pw_filter_cons_of_neg h',pw_filter_map]
theorem pw_filter_sublist : ∀ (l : list α), pw_filter R l <+ l
| [] := nil_sublist _
| (x :: l) := begin
by_cases (∀ y ∈ pw_filter R l, R x y),
{ rw [pw_filter_cons_of_pos h],
exact (pw_filter_sublist l).cons_cons _ },
{ rw [pw_filter_cons_of_neg h],
exact sublist_cons_of_sublist _ (pw_filter_sublist l) },
end
theorem pw_filter_subset (l : list α) : pw_filter R l ⊆ l :=
(pw_filter_sublist _).subset
theorem pairwise_pw_filter : ∀ (l : list α), pairwise R (pw_filter R l)
| [] := pairwise.nil
| (x :: l) := begin
by_cases (∀ y ∈ pw_filter R l, R x y),
{ rw [pw_filter_cons_of_pos h],
exact pairwise_cons.2 ⟨h, pairwise_pw_filter l⟩ },
{ rw [pw_filter_cons_of_neg h],
exact pairwise_pw_filter l },
end
theorem pw_filter_eq_self {l : list α} : pw_filter R l = l ↔ pairwise R l :=
⟨λ e, e ▸ pairwise_pw_filter l, λ p, begin
induction l with x l IH, {refl},
cases pairwise_cons.1 p with al p,
rw [pw_filter_cons_of_pos (ball.imp_left (pw_filter_subset l) al), IH p],
end⟩
alias pw_filter_eq_self ↔ _ pairwise.pw_filter
attribute [protected] pairwise.pw_filter
@[simp] lemma pw_filter_idempotent : pw_filter R (pw_filter R l) = pw_filter R l :=
(pairwise_pw_filter l).pw_filter
theorem forall_mem_pw_filter (neg_trans : ∀ {x y z}, R x z → R x y ∨ R y z)
(a : α) (l : list α) : (∀ b ∈ pw_filter R l, R a b) ↔ (∀ b ∈ l, R a b) :=
⟨begin
induction l with x l IH, { exact λ _ _, false.elim },
simp only [forall_mem_cons],
by_cases (∀ y ∈ pw_filter R l, R x y); dsimp at h,
{ simp only [pw_filter_cons_of_pos h, forall_mem_cons, and_imp],
exact λ r H, ⟨r, IH H⟩ },
{ rw [pw_filter_cons_of_neg h],
refine λ H, ⟨_, IH H⟩,
cases e : find (λ y, ¬ R x y) (pw_filter R l) with k,
{ refine h.elim (ball.imp_right _ (find_eq_none.1 e)),
exact λ y _, not_not.1 },
{ have := find_some e,
exact (neg_trans (H k (find_mem e))).resolve_right this } }
end, ball.imp_left (pw_filter_subset l)⟩
end list
|
47bf688243fa857656968da13ff36ec2cb5eebec | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/eformat.lean | 1babea9b468ea21b9ec43cdf077a612db1084f45 | [
"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 | 944 | lean | open tactic
meta def trace_tagged_debug : expr → tactic unit
| e := do
tf ← tactic.pp_tagged e,
f ← tagged_format.m_untag (λ a f, do a ← pp a, pure $ "[" ++ a ++ ": " ++ f ++ "]") tf,
tactic.trace f
meta def trace_tagged_debug_locals : tactic unit := do
cs ← local_context,
cs ← cs.mmap infer_type,
cs.mmap' trace_tagged_debug
example (α : Type) (x : α) (h : 1 = 2) (f : ite ff true false) (g : x ≠ x) : true :=
begin
trace_tagged_debug_locals,
trivial
end
example (k : (-3 : int) < (1 + 1 : nat)) : true :=
begin
trace_tagged_debug_locals, -- note the coe is present.
trivial
end
example (k : Π {α β : Type}, α ≠ β) : true :=
begin
trace_tagged_debug_locals,
trivial
end
example (k : (λ α β : Type, α ≠ β) Prop Prop) : true :=
begin
trace_tagged_debug_locals,
trivial
end
example (S : set nat) (k : S = {3, 2, 1}) : true :=
begin
trace_tagged_debug_locals,
trivial
end
|
9b3a9f0dd3aa94dc3a8f6ca1c4ace3014a7658eb | c8af905dcd8475f414868d303b2eb0e9d3eb32f9 | /src/data/cpi/transition/basic.lean | 7b376721d780f6e01b1333fe7f8d526faf23049f | [
"BSD-3-Clause"
] | permissive | continuouspi/lean-cpi | 81480a13842d67ff5f3698643210d8ed5dd08de4 | 443bf2cb236feadc45a01387099c236ab2b78237 | refs/heads/master | 1,650,307,316,582 | 1,587,033,364,000 | 1,587,033,364,000 | 207,499,661 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,314 | lean | import data.cpi.transition.lookup data.cpi.transition.production
namespace cpi
variables {ℍ : Type} {ω : context}
/-- A transition from one species to a production. This represents the potential
for a reaction. The label indicates the kind of reaction (spontantious or
communicating). -/
@[nolint has_inhabited_instance]
inductive transition :
Π {Γ} {k}
, species ℍ ω Γ → lookup ℍ ω Γ → label ℍ Γ k → production ℍ ω Γ k
→ Type
/- Additional transition to project project into where our choiceₙ rules apply. -/
| ξ_choice
{Γ ℓ f} {π : prefix_expr ℍ Γ f} {A : species ℍ ω (f.apply Γ)} {As : species.choices ℍ ω Γ}
{k} {l : label ℍ Γ k} {E : production ℍ ω Γ k}
: transition (Σ# As) ℓ l E
→ transition (Σ# species.whole.cons π A As) ℓ l E
| choice₁
{Γ ℓ}
(a : name Γ) {n} (b : list (name Γ)) (b_len : list.length b = n) (y : ℕ) (A : species ℍ ω (context.extend y Γ))
(As : species.choices ℍ ω Γ)
: transition (Σ# species.whole.cons (a#(b; y)) A As)
ℓ (#a)
(production.concretion (#(⟨ b, b_len ⟩; y) A))
| choice₂
{Γ ℓ}
(k : ℍ) (A : species ℍ ω Γ) (As : species.choices ℍ ω Γ)
: transition (Σ# species.whole.cons (τ@k) A As) ℓ τ@'k (production.species A)
| com₁
{Γ ℓ x y} {A B : species ℍ ω Γ} {a b : name Γ}
{F : concretion ℍ ω Γ x y} {G : concretion ℍ ω Γ y x}
{FG : species ℍ ω Γ} {α : label ℍ Γ kind.species}
: FG = concretion.pseudo_apply F G
→ α = τ⟨ a, b ⟩
→ transition A ℓ (#a) (production.concretion F)
→ transition B ℓ (#b) (production.concretion G)
→ transition (A |ₛ B) ℓ α (production.species FG)
| com₂
{Γ ℓ} (M : affinity ℍ) {p : upair (fin M.arity)} {p' : upair (name (context.extend M.arity Γ))}
{A B : species ℍ ω (context.extend M.arity Γ)}
(k : ℍ)
: M.get p = some k
→ p' = p.map name.zero
→ transition A (lookup.rename name.extend ℓ) τ⟨ p' ⟩ (production.species B)
→ transition (ν(M) A) ℓ τ@'k (production.species (ν(M) B))
| parL_species
{Γ ℓ A} B {l : label ℍ Γ kind.species} {E}
: transition A ℓ l (production.species E) → transition (A |ₛ B) ℓ l (production.species (E |ₛ B))
| parL_concretion
{Γ ℓ A} B {l : label ℍ Γ kind.concretion} {b y} {E : concretion ℍ ω Γ b y}
: transition A ℓ l (production.concretion E) → transition (A |ₛ B) ℓ l (production.concretion (E |₁ B))
| parR_species
{Γ ℓ} A {B} {l : label ℍ Γ kind.species} {E}
: transition B ℓ l (production.species E) → transition (A |ₛ B) ℓ l (production.species (A |ₛ E))
| parR_concretion
{Γ ℓ} A {B} {l : label ℍ Γ kind.concretion} {b y} {E : concretion ℍ ω Γ b y}
: transition B ℓ l (production.concretion E) → transition (A |ₛ B) ℓ l (production.concretion (A |₂ E))
| ν₁_species
{Γ ℓ} (M : affinity ℍ) {A} {l : label ℍ Γ kind.species} {l' : label ℍ (context.extend M.arity Γ) kind.species} {E}
: l' = label.rename name.extend l
→ transition A (lookup.rename name.extend ℓ) l' (production.species E)
→ transition (ν(M) A) ℓ l (production.species (ν(M) E))
| ν₁_concretion
{Γ ℓ} (M : affinity ℍ) {A} {l : label ℍ Γ kind.concretion} {l' : label ℍ (context.extend M.arity Γ) kind.concretion}
{b y} {E : concretion ℍ ω _ b y}
: l' = label.rename name.extend l
→ transition A (lookup.rename name.extend ℓ) l' (production.concretion E)
→ transition (ν(M) A) ℓ l (production.concretion (ν'(M) E))
| defn
{Γ k n} {α : label ℍ Γ k} (ℓ : lookup ℍ ω Γ)
(D : reference n ω) (as : vector (name Γ) n)
(B : species.choices ℍ ω Γ) {E}
: B = species.rename (name.mk_apply as) (ℓ n D)
→ transition (Σ# B) ℓ α E
→ transition (species.apply D as) ℓ α E
notation A ` [`:max ℓ `, ` α `]⟶ ` E:max := transition A ℓ α E
namespace transition
/-- Rename a transition with a basic renaming function. --/
protected def rename :
∀ {Γ Δ f k}
{A : species ℍ ω Γ} {l : label ℍ Γ k} {E : production ℍ ω Γ k}
(ρ : name Γ → name Δ)
, A [f, l]⟶ E
→ (species.rename ρ A) [lookup.rename ρ f, label.rename ρ l]⟶ (production.rename ρ E)
| Γ Δ f k A l E ρ t := begin
induction t generalizing Δ,
case ξ_choice : Γ ℓ f π A As k l E t ih {
have t' := ih _ ρ,
simp only [species.rename.choice, species.rename.cons] at t' ⊢,
from ξ_choice t',
},
case choice₁ : Γ ℓ a n b b_len y A As {
simp only [ species.rename.choice, species.rename.cons,
prefix_expr.ext_communicate, prefix_expr.rename_communicate ],
from choice₁ (ρ a) (list.map ρ b) _ y _ _,
},
case choice₂ : Γ ℓ k A As {
simp only [species.rename.choice, species.rename.cons],
from choice₂ k _ _,
},
case com₁ : Γ ℓ x y A B a b F G C α eqlFG eqlα tf tg ihf ihg {
subst eqlα, subst eqlFG,
simp only [species.rename.parallel, production.rename, label.rename, concretion.pseudo_apply.rename],
have tf' := ihf _ ρ, have tg' := ihg _ ρ,
from com₁ rfl rfl tf' tg',
},
case com₂ : Γ ℓ M p p' A B k eqK eqP t ih {
subst eqP,
simp only [species.rename.restriction, production.rename],
have t' := ih _ (name.ext ρ),
rw [lookup.rename_compose, name.ext_extend, ← lookup.rename_compose] at t',
simp only [label.rename] at t',
rw [upair.map_compose, name.ext_zero] at t',
from com₂ M k eqK rfl t',
},
case defn : Γ n k α ℓ D as B E eql t ih {
simp only [species.rename.invoke],
have t' := ih _ ρ,
simp only [species.rename.choice] at t',
suffices : cpi.species.rename ρ B = cpi.species.rename (name.mk_apply (vector.map ρ as)) (lookup.rename ρ ℓ k D),
from defn (lookup.rename ρ ℓ) D (vector.map ρ as) _ this t',
simp only [lookup.rename],
rw [species.rename_compose, ← name.mk_apply_rename, ← species.rename_compose (name.mk_apply as) ρ],
from congr_arg (species.rename ρ) eql,
},
case parL_species : Γ ℓ A B l E t ih {
simp only [production.rename, species.rename.parallel],
from parL_species _ (ih _ ρ),
},
case parL_concretion : Γ ℓ A B l b y E t ih {
simp only [production.rename, species.rename.parallel, concretion.rename],
from parL_concretion _ (ih _ ρ),
},
case parR_species : Γ ℓ A B l E t ih {
simp only [production.rename, species.rename.parallel],
from parR_species _ (ih _ ρ),
},
case parR_concretion : Γ ℓ A B l b y E t ih {
simp only [production.rename, species.rename.parallel, concretion.rename],
from parR_concretion _ (ih _ ρ),
},
case ν₁_species : Γ ℓ M A l l' E eql t ih {
subst eql,
simp only [production.rename, species.rename.restriction],
have t' := ih _ (name.ext ρ),
rw [label.rename_compose, name.ext_extend, ← label.rename_compose] at t',
rw [lookup.rename_compose, name.ext_extend, ← lookup.rename_compose] at t',
from ν₁_species M rfl t',
},
case ν₁_concretion : Γ ℓ M A l l' b y E eql t ih {
subst eql,
simp only [production.rename, species.rename.restriction, concretion.rename],
have t' := ih _ (name.ext ρ),
rw [label.rename_compose, name.ext_extend, ← label.rename_compose] at t',
rw [lookup.rename_compose, name.ext_extend, ← lookup.rename_compose] at t',
from ν₁_concretion M rfl t',
},
end
/-- FIXME: Actually prove this. I'm 99% sure it exists, but showing it has
proved to be rather annoying. -/
protected constant rename_from :
∀ {Γ Δ ℓ k}
{A : species ℍ ω Γ} {l : label ℍ Δ k} {E : production ℍ ω Δ k}
(ρ : name Γ → name Δ)
, species.rename ρ A [lookup.rename ρ ℓ, l]⟶ E
→ Σ'(l' : label ℍ Γ k) (E' : production ℍ ω Γ k)
, pprod (A [ℓ , l']⟶ E') (label.rename ρ l' = l ∧ production.rename ρ E' = E)
/-- A transition from a specific species, to any production. -/
@[nolint has_inhabited_instance]
def transition_from {Γ} (ℓ : lookup ℍ ω Γ) (A : species ℍ ω Γ) : Type
:= Σ k (α : label ℍ Γ k) E, A [ℓ, α]⟶ E
/-- Construct a new transition_from, wrapping a transition. -/
@[pattern]
def transition_from.mk
{Γ} {ℓ : lookup ℍ ω Γ} {A : species ℍ ω Γ} {k} {α : label ℍ Γ k} {E} (t : A [ℓ, α]⟶ E)
: transition_from ℓ A
:= ⟨ k, α, E, t ⟩
/-- Construct a new transition_from with an explicit lookup function, wrapping a
transition. -/
@[pattern]
def transition_from.mk_with
{Γ} (ℓ : lookup ℍ ω Γ) {A : species ℍ ω Γ} {k} {α : label ℍ Γ k} {E} (t : A [ℓ, α]⟶ E)
: transition_from ℓ A
:= ⟨ k, α, E, t ⟩
instance transition_from.has_repr [has_repr ℍ] {Γ} {ℓ : lookup ℍ ω Γ} {A : species ℍ ω Γ}
: has_repr (transition.transition_from ℓ A)
:= ⟨ λ ⟨ k, α, E, t ⟩, repr A ++ " [" ++ repr α ++ "]⟶ " ++ repr E ⟩
end transition
end cpi
#lint-
|
d893a50834ade84262022ef5ce2619fbdc2e65c7 | 43390109ab88557e6090f3245c47479c123ee500 | /src/Geometry/tarski_5.lean | 6bf690deb473183d6fb7d03518859e66ac33b424 | [
"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 | 35,365 | lean | import geometry.tarski_4
open classical set
namespace Euclidean_plane
variables {point : Type} [Euclidean_plane point]
local attribute [instance, priority 0] prop_decidable
-- Line Reflections
noncomputable def mid (a b : point) : point := classical.some (eight22 a b)
theorem ten1 (a b : point) : M a (mid a b) b := (classical.some_spec (eight22 a b)).1
theorem M_to_mid {a b m : point} : M a m b → mid a b = m := seven17 (ten1 a b)
@[simp] theorem mid.refl (a : point) : mid a a = a := (seven3.1 $ ten1 a a).symm
theorem mid.symm (a b : point) : mid a b = mid b a := seven17 (ten1 a b) (ten1 b a).symm
@[simp] theorem mid_to_Sa (a b : point) : S (mid a b) a = b := (seven6 $ ten1 a b).symm
@[simp] theorem mid_to_Sb (a b : point) : S (mid a b) b = a := mid.symm b a ▸ mid_to_Sa b a
@[simp] theorem mid_of_S (a b : point) : mid b (S a b) = a := seven17 (ten1 b (S a b)) (seven5 a b)
theorem mid.neq {a b : point} : a ≠ b → mid a b ≠ a := --λ h h1, h ((seven11 a) ▸ h1 ▸ mid_to_Sa a b)
begin
intros h h1,
apply h,
suffices : eqd (mid a b) a (mid a b) b,
rw h1 at this,
exact id_eqd this.symm,
exact (ten1 a b).2
end
theorem ten2 {p : point} (A : set point) [h : line A] (h_1 : p ∉ A) : ∃! q, mid p q ∈ A ∧ perp A (l p q) :=
begin
unfreezeI,
rcases h with ⟨a, b, h₁, h₂⟩,
rw h₂ at *,
cases eight18 h_1 with x hx,
apply exists_unique.intro (S x p),
split,
rw seven17 (ten1 p (S x p)) (seven5 x p),
exact hx.1.1,
apply (eight14f hx.1.2.symm (or.inl (seven5 x p).1) _).symm,
intro h_2,
have h1 := seven10.1 h_2.symm,
subst x,
exact h_1 hx.1.1,
intros y hy,
have h1 : p ≠ y,
intro h_2,
rw [←h_2, mid.refl p] at hy,
exact h_1 hy.1,
have h2 := ten1 p y,
have h3 : mid p y = x,
apply hx.2,
refine ⟨hy.1,_⟩,
suffices : l p y = l p (mid p y),
rw ←this,
exact hy.2,
apply six18 (six14 h1),
intro h_2,
rw ←h_2 at h2,
exact h1 (id_eqd h2.2.symm),
simp,
right, left,
exact h2.1.symm,
rw h3 at *,
exact seven4 h2 (seven5 x p)
end
noncomputable def Sl (A : set point) [line A] (a : point) : point := if h1 : a ∉ A then classical.some (ten2 A h1) else a
theorem ten3a {A : set point} (h : line A) {a : point} (h1 : a ∉ A) : mid a (Sl A a) ∈ A ∧ perp A (l a (Sl A a)) :=
begin
unfold Sl,
rw dif_pos h1,
exact (classical.some_spec (ten2 A h1)).1
end
theorem unique_of_Sl {p q : point} {A : set point} (h : line A) : p ∉ A → mid p q ∈ A → perp A (l p q) → q = Sl A p :=
λ h1 h2 h3, unique_of_exists_unique (ten2 A h1) ⟨h2, h3⟩ (ten3a h h1)
theorem ten3b {A : set point} (h : line A) {a : point} (h1 : a ∈ A) : Sl A a = a :=
begin
unfold Sl,
have h2 : ¬a ∉ A,
intro h_1,
contradiction,
rw dif_neg h2
end
theorem ten3c {A : set point} (h : line A) {a : point} : a ∉ A → Sl A a ∉ A :=
begin
intro h1,
have h2 := ten3a h h1,
cases em (a = Sl A a),
rwa ←h_1,
intro h3,
apply h1,
have h4 := ten1 a (Sl A a),
suffices : A = l (Sl A a) (mid a (Sl A a)),
rw this,
left,
exact h4.1.symm,
apply six18 h,
intro h_2,
apply h_1,
rw ←h_2 at h4,
exact id_eqd h4.2.flip,
exact h3,
exact h2.1
end
theorem ten3d {A : set point} (h : line A) (a : point) : Sl A a = S (mid a (Sl A a)) a :=
begin
exact (mid_to_Sa _ _).symm
end
theorem ten3e {A : set point} (h : line A) (a : point) : mid a (Sl A a) ∈ A :=
begin
cases em (a ∈ A),
rw ten3b h h_1,
simpa,
exact (ten3a h h_1).1
end
@[simp] theorem ten5 {A : set point} (h : line A) (a : point) : Sl A (Sl A a) = a :=
begin
cases em (a ∈ A),
have h1 := ten3b h h_1,
rwa h1,
have h1 := ten3a h h_1,
have h2 : Sl A a ∉ A,
exact ten3c h h_1,
rw [mid.symm, six17] at h1,
apply unique_of_exists_unique (ten2 A h2),
exact ten3a h h2,
exact h1
end
theorem ten4 {A : set point} {h : line A} {p q : point} : Sl A p = q ↔ Sl A q = p :=
begin
split;
{intro h1,
rw ←h1,
simp}
end
theorem ten6 {A : set point} (h : line A) (p : point) : ∃! q, Sl A q = p :=
begin
apply exists_unique.intro,
exact ten5 h p,
intros y hy,
exact (ten4.1 hy).symm
end
theorem ten7 {A : set point} {h : line A} {p q : point} : Sl A p = Sl A q → p = q :=
begin
intro h1,
rw ←(ten4.1 h1),
simp
end
theorem ten7a {A : set point} (h : line A) {p q : point} : p ≠ q → Sl A p ≠ Sl A q :=
λ h1 h2, h1 (ten7 h2)
theorem ten8 {A : set point} (h : line A) {a : point} : Sl A a = a ↔ a ∈ A :=
begin
split,
intro h1,
by_contradiction h_1,
apply h_1,
have h2 := ten3a h h_1,
rw h1 at *,
simp at h2,
exact h2.1,
intro h1,
exact ten3b h h1
end
theorem ten9 {A : set point} (h : line A) {a : point} : a ∉ A → xperp (mid a (Sl A a)) A (l a (mid a (Sl A a))) :=
begin
intro h1,
have h2 := ten3a h h1,
suffices : l a (Sl A a) = l a (mid a (Sl A a)),
apply eight15 _ h2.1 (six17b _ _),
rw ←this,
exact h2.2,
have h3 : a ≠ Sl A a,
intro h_1,
apply h1,
exact (ten8 h).1 h_1.symm,
have h4 := ten1 a (Sl A a),
apply six18 (six14 h3),
intro h_1,
apply h3,
rw ←h_1 at h4,
exact id_eqd h4.2.symm,
simp,
right, left,
exact h4.1.symm
end
theorem ten10 {A : set point} (h : line A) (p q : point) : eqd p q (Sl A p) (Sl A q) :=
begin
rw [ten3d h p, ten3d h q],
generalize h1 : mid p (Sl A p) = x,
generalize h2 : mid q (Sl A q) = y,
generalize h3 : mid x y = z,
have h4 := mid_to_Sa x y,
rw h3 at h4,
have h5 := seven5 x p,
have h6 := (seven14 z).1 h5,
rw h4 at h6,
have h7 := seven6 h6,
have h8 : eqd q (S z p) (S y q) (S z (S x p)),
rw h7,
apply seven13,
have h9 : R z x p,
cases em (p ∈ A),
rw (ten3b h h_1) at h1,
simp at h1,
subst p,
simp,
have h_2 : xperp x A (l p x),
rw ←h1,
exact ten9 h h_1,
apply h_2.2.2.2.2,
apply six27 h,
exact ten3e h p,
exact ten3e h q,
rw [h1, h2, ←h3],
exact (ten1 x y).1,
simp,
have h10 : R z y q,
cases em (q ∈ A),
rw (ten3b h h_1) at h2,
simp at h2,
subst q,
simp,
have h_2 : xperp y A (l q y),
rw ←h2,
exact ten9 h h_1,
apply h_2.2.2.2.2,
apply six27 h,
exact ten3e h q,
exact ten3e h p,
rw [h2, h1, ←h3],
exact (ten1 x y).1.symm,
simp,
unfold R at *,
have h11 : afs (S z p) z p q (S z (S x p)) z (S x p) (S y q),
repeat {split},
exact (seven5 z p).1.symm,
exact (seven5 z (S x p)).1.symm,
suffices : eqd (S z p) (S z z) (S z (S x p)) (S z z),
simp at this,
exact this,
exact (seven16 z).1 h9.flip,
exact h9,
exact h8.flip,
exact h10,
cases em (S z p = z),
have h12 : p = z,
exact seven9 (eq.trans h_1 (seven11 z).symm),
have h13 : (S x p) = z,
rw ←h12 at *,
exact id_eqd h9.symm.flip,
exact h13.symm ▸ h12.symm ▸ h10,
exact afive_seg h11 h_1
end
theorem ten11a {A : set point} (h : line A) {a b c : point} : B a b c ↔ B (Sl A a) (Sl A b) (Sl A c) :=
begin
split,
intro h1,
apply four6 h1,
repeat {split};
exact ten10 h _ _,
intro h1,
rw ←ten5 h a,
rw ←ten5 h b,
rw ←ten5 h c,
apply four6 h1,
repeat {split};
exact ten10 h _ _
end
theorem ten11b {A : set point} (h : line A) {a b c d : point} : eqd a b c d ↔ eqd (Sl A a) (Sl A b) (Sl A c) (Sl A d) :=
begin
split,
intro h1,
exact (ten10 h a b).symm.trans (h1.trans (ten10 h c d)),
intro h1,
have h2 := (ten10 h (Sl A a) (Sl A b)).symm.trans (h1.trans (ten10 h (Sl A c) (Sl A d))),
simpa using h2
end
theorem ten11c {A : set point} (h : line A) (a b c : point) : cong a b c (Sl A a) (Sl A b) (Sl A c) :=
by repeat {split}; exact ten10 h _ _
theorem ten11d {A : set point} (h : line A) {a b c : point} : R a b c ↔ R (Sl A a) (Sl A b) (Sl A c) :=
⟨λ h1, eight10 h1 (ten11c h a b c), λ h1, eight10 h1 (ten11c h a b c).symm⟩
theorem ten12a {a b p : point} (h : line (l a b)) : R a b p → b = mid p (Sl (l a b) p) :=
begin
intro h1,
cases em (p ∈ l a b),
cases eight9 h1 h_1,
unfreezeI,
subst b,
exfalso,
exact six13a a h,
subst p,
suffices : Sl (l a b) b = b,
rw this,
simp,
apply ten3b h (six17b a b),
suffices : S b p = Sl (l a b) p,
rw ←this,
exact (mid_of_S b p).symm,
apply eq.symm,
apply unique_of_exists_unique (ten2 (l a b) h_1),
exact ten3a h h_1,
split,
rw mid_of_S,
simp,
have h3 : p ≠ b,
intro h_2,
apply h_1,
subst p,
simp,
suffices : l p (S b p) = l p b,
rw this,
suffices : xperp b (l a b) (l p b),
constructor,
exact this,
apply eight13.2,
split,
exact h,
split,
exact six14 h3,
split,
simp,
split,
simp,
existsi [a, p],
split,
simp,
split,
simp,
split,
exact six13 h,
split,
exact h3,
exact h1,
apply six18 _ h3,
simp,
right, left,
exact (seven5 b p).1.symm,
apply six14,
intro h_2,
apply h3,
exact (seven10.1 h_2.symm).symm
end
theorem ten12b {a b c : point} (h : line (l a b)) : R a b c → c = (Sl (l a b) (S b c)) :=
begin
intro h1,
have h2 : b = mid c (Sl (l a b) c),
exact ten12a h h1,
suffices : S b c = Sl (l a b) c,
rw this,
simp,
suffices : S (mid c (Sl (l a b) c)) c = Sl (l a b) c,
rwa ←h2 at this,
exact mid_to_Sa c (Sl (l a b) c)
end
theorem ten12c {a b c a' : point} : R a b c → R a' b c → eqd a b a' b → eqd a c a' c :=
begin
intros h h1 h2,
generalize h3 : mid a a' = z,
have h4 : R b z a,
unfold R,
rw ←h3,
rw mid_to_Sa,
exact h2.flip,
cases em (b = c),
subst b,
exact h2,
cases em (b = z),
subst z,
haveI h5 : line (l c b) := six14 (ne.symm h_1),
have h6 : a' = Sl (l c b) a,
suffices : a = S b a',
rw this,
exact ten12b h5 h1.symm,
rw [h_2, mid.symm],
exact (mid_to_Sa a' a).symm,
have h7 : c = Sl (l c b) c,
apply (ten3b h5 _).symm,
simp,
rw h6,
simpa [h7.symm] using (ten10 h5 a c),
haveI h5 := six14 h_2,
have h6 : a = Sl (l b z) a',
rw [(mid_to_Sa a a').symm, h3],
exact ten12b h5 h4,
have h7 : b = Sl (l b z) b,
suffices : b ∈ l b z,
exact (ten3b h5 this).symm,
simp,
have h8 : eqd a c a (S b c),
unfold R at h,
exact h,
cases em (a = a'),
subst a',
exact eqd.refl a c,
have h9 : R z b c,
unfold R,
apply four17 h_3,
rw ←h3,
right, left,
exact (ten1 a a').1.symm,
exact h8,
unfold R at h1,
exact h1,
have h10 : (S b c) = Sl (l b z) c,
simp only [six17 b z],
rw ten4.1,
apply eq.symm,
exact ten12b _ h9,
apply h8.trans,
apply eqd.symm,
rw [h6, h10],
exact ten10 h5 a' c
end
theorem ten12 {a b c a' b' c' : point} : R a b c → R a' b' c' → eqd a b a' b' → eqd b c b' c' → eqd a c a' c' :=
begin
intros h h1 h2 h3,
generalize h4 : mid b b' = x,
have h5 : b = S x b',
rw [←h4, mid.symm],
apply eq.symm,
exact mid_to_Sa b' b,
have h6 : cong a' b' c' (S x a') b (S x c'),
rw h5,
exact seven16a x,
have h7 : R (S x a') b (S x c'),
exact eight10 h1 h6,
apply eqd.trans _ h6.2.2.symm,
generalize h8 : mid c (S x c') = y,
have h9 : R b y c,
unfold R,
rw ←h8,
rw mid_to_Sa,
exact h3.trans h6.2.1,
cases em (b = y),
subst y,
have h10 : (S b (S x c')) = c,
rw [h_1, mid.symm],
exact mid_to_Sa (S x c') c,
have h11 : cong (S x a') b (S x c') (S b (S x a')) b c,
rw ←h10,
suffices : cong (S x a') b (S x c') (S b (S x a')) (S b b) (S b (S x c')),
simpa [this],
exact seven16a b,
apply eqd.trans _ h11.2.2.symm,
apply ten12c h,
exact eight10 h7 h11,
exact h2.trans (h6.1.trans h11.1),
haveI h10 := six14 h_1,
have h11 : c = Sl (l b y) (S x c'),
rw [←mid_to_Sa c (S x c'), h8],
exact ten12b h10 h9,
have h12 : b = Sl (l b y) b,
suffices : b ∈ l b y,
exact (ten3b h10 this).symm,
simp,
have h13 : cong (S x a') b (S x c') (Sl (l b y) (S x a')) (Sl (l b y) b) (Sl (l b y) (S x c')),
repeat {split};
exact ten10 h10 _ _,
rw [←h11, ←h12] at h13,
apply eqd.trans _ h13.2.2.symm,
exact ten12c h (eight10 h7 h13) (h2.trans (h6.1.trans h13.1))
end
theorem ten14 {A : set point} (h : line A) {a : point} : a ∉ A → Bl a A (Sl A a) :=
begin
intro h1,
split,
exact h,
split,
exact h1,
split,
exact ten3c h h1,
constructor,
split,
exact (ten3a h h1).1,
exact (ten1 a (Sl A a)).1
end
theorem ten15 {A : set point} (h : line A) {a q : point} : a ∈ A → q ∉ A → ∃ p, perp A (l p a) ∧ side A p q :=
begin
intros h1 h2,
cases six22 h h1 with b hb,
cases nine10 h h2 with c hc,
rcases eight21 hb.1 c with ⟨p, t, ht⟩,
existsi p,
split,
rw hb.2,
exact ht.1,
existsi c,
split,
split,
exact h,
split,
intro h_1,
apply eight14a ht.1,
apply six18,
rwa hb.2 at h,
exact six13 (eight14e ht.1).2,
rwa hb.2 at h_1,
simp,
split,
exact hc.2.2.1,
existsi t,
split,
rw hb.2,
exact ht.2.1,
exact ht.2.2.symm,
exact hc
end
theorem ten16 {a b c p a' b' : point} : ¬col a b c → ¬col a' b' p → eqd a b a' b' → ∃! c', cong a b c a' b' c' ∧ side (l a' b') c' p :=
begin
intros h h1 h2,
apply exists_unique_of_exists_of_unique,
cases eight18 h with x hx,
cases four14 hx.1.1 h2 with x' hx',
have h3 : col a' b' x',
exact four13 hx.1.1 hx',
cases ten15 (six14 (six26 h1).1) h3 h1 with q hq,
have h4 : x ≠ c,
intro h_1,
subst x,
exact h hx.1.1,
cases six11 (six13 (eight14e hq.1).2) h4 with c' hc',
constructor,
have h5 : cong a b c a' b' c',
split,
exact h2,
have h5 : xperp x (l a b) (l c x),
exact eight15 hx.1.2 hx.1.1 (six17b c x),
have h6 : xperp x' (l a' b') (l c' x'),
suffices : perp (l a' b') (l c' x'),
exact eight15 this h3 (six17b c' x'),
suffices : l q x' = l c' x',
rw this at hq,
exact hq.1,
apply six18 (eight14e hq.1).2,
intro h_1,
apply h4,
subst c',
exact id_eqd hc'.1.2.symm,
exact (four11 (six4.1 hc'.1.1).1).2.2.2.2,
simp,
split,
have h7 : R b x c,
simp [h5.2.2.2.2],
have h8 : R b' x' c',
simp [h6.2.2.2.2],
exact ten12 h7 h8 hx'.2.1 hc'.1.2.symm,
have h7 : R a x c,
simp [h5.2.2.2.2],
have h8 : R a' x' c',
simp [h6.2.2.2.2],
exact ten12 h7 h8 hx'.2.2 hc'.1.2.symm,
split,
exact h5,
apply side.trans _ hq.2,
apply nine12 (six14 (six26 h1).1) h3 hc'.1.1,
intro h_1,
exact h (four13 h_1 h5.symm),
intros c' c'' hc' hc'',
have h3 := hc'.1.symm.trans hc''.1,
have h4 := hc'.2.trans hc''.2.symm,
haveI h5 := six14 (six26 h1).1,
generalize h6 : Sl (l a' b') c'' = c₁,
have h7 : Bl c'' (l a' b') c₁,
rw ←h6,
exact ten14 h5 (nine11 h4).2.2,
have h8 : Bl c' (l a' b') c₁,
exact (nine8 h7).2 h4.symm,
cases h8.2.2.2 with t ht,
have h9 : cong a' b' c' a' b' c₁,
apply h3.trans,
have h_1 : a' = Sl (l a' b') a',
apply (ten3b h5 _).symm,
simp,
have h_2 : b' = Sl (l a' b') b',
apply (ten3b h5 _).symm,
simp,
have h_3 : cong a' b' c'' (Sl (l a' b') a') (Sl (l a' b') b') c₁,
rw ←h6,
repeat {split};
exact ten10 h5 _ _,
simpa [h_2.symm, h_1.symm] using h_3,
have h10 : c₁ = S t c',
apply seven4 _ (seven5 t c'),
split,
exact ht.2,
exact four17 (six26 h1).1 ht.1 h9.2.2 h9.2.1,
suffices : Sl (l a' b') c' = c₁,
exact ten7 (this.trans h6.symm),
apply unique_of_exists_unique (ten2 (l a' b') h8.2.1),
exact ten3a h5 h8.2.1,
split,
rw [h10, mid_of_S],
exact ht.1,
existsi t,
apply eight13.2,
split,
exact six14 (six26 h1).1,
split,
exact six14 (nine2 h8),
split,
exact ht.1,
split,
right, left,
exact ht.2.symm,
cases em (a' = t),
have h_2 : b' ≠ t,
intro h_2,
exact (six26 h1).1 (h_1.trans h_2.symm),
existsi [b', c'],
split,
simp,
split,
simp,
split,
exact h_2,
split,
intro h_3,
subst h_3,
exact h8.2.1 ht.1,
unfold R,
rw ←h10,
exact h9.2.1,
existsi [a', c'],
split,
simp,
split,
simp,
split,
exact h_1,
split,
intro h_1,
subst t,
exact h8.2.1 ht.1,
unfold R,
rw ←h10,
exact h9.2.2
end
theorem ten17 {a b : point} {A : set point} (h : line A) : S (Sl A a) (Sl A b) = Sl A (S a b) :=
(seven6 ⟨(ten11a h).1 (seven5 a b).1, (ten11b h).1 (seven5 a b).2⟩).symm
theorem ten18 {a b p : point} {A : set point} : xperp b A (l a b) → p ∈ A → xperp (S p b) A (l (S p a) (S p b)) :=
begin
intros h h1,
by_cases h_1 : p = b,
subst p,
rw seven11,
suffices : l a b = l (S b a) b,
rwa ←this,
exact six18 h.2.1 (seven12a (six13 h.2.1)) (or.inl (seven5 b a).1) (six17b a b),
apply eight13.2 ⟨h.1, six14 (seven9a p (six13 h.2.1)), ((seven24 h.1 h1).1 h.2.2.1), six17b _ _,
p, S p a, h1, six17a _ _, (seven12a (ne.symm h_1)).symm, (seven9a p (six13 h.2.1)), _⟩,
simpa using ((eight19 p).1 (h.2.2.2.2 h1 (six17a a b)))
end
-- Angles
def eqa (a b c d e f : point) : Prop := a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e ∧ ∃ a' c' d' f',
B b a a' ∧ eqd a a' e d ∧ B b c c' ∧ eqd c c' e f ∧ B e d d' ∧ eqd d d' b a ∧ B e f f' ∧ eqd f f' b c ∧ eqd a' c' d' f'
theorem eleven3a {a b c d e f : point} : eqa a b c d e f → ∃ a' c' d' f', sided b a' a ∧
sided b c' c ∧ sided e d' d ∧ sided e f' f ∧ cong a' b c' d' e f' :=
begin
unfold eqa,
intro h,
rcases h.2.2.2.2 with ⟨a', c', d', f', h1⟩,
existsi [a', c', d', f'],
split,
exact (six7 h1.1 h.1).symm,
split,
exact (six7 h1.2.2.1 h.2.1).symm,
split,
exact (six7 h1.2.2.2.2.1 h.2.2.1).symm,
split,
exact (six7 h1.2.2.2.2.2.2.1 h.2.2.2.1).symm,
split,
exact two5 (two11 h1.1.symm h1.2.2.2.2.1 (two4 h1.2.1) (two4 h1.2.2.2.2.2.1.symm)),
split,
exact two5 (two11 h1.2.2.1 h1.2.2.2.2.2.2.1.symm (two5 h1.2.2.2.2.2.2.2.1.symm) (two5 h1.2.2.2.1)),
exact h1.2.2.2.2.2.2.2.2
end
theorem eleven4a {a b c d e f : point} : (∃ a' c' d' f', sided b a' a ∧ sided b c' c ∧ sided e d' d ∧ sided e f' f ∧ cong a' b c' d' e f') → a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e ∧
∀ {a' c' d' f'}, sided b a' a → sided b c' c → sided e d' d → sided e f' f → eqd b a' e d' → eqd b c' e f' → eqd a' c' d' f' :=
begin
intro h,
rcases h with ⟨a', c', d', f', h1⟩,
repeat {split},
exact h1.1.2.1,
exact h1.2.1.2.1,
exact h1.2.2.1.2.1,
exact h1.2.2.2.1.2.1,
intros a1 c1 d1 f1 h2 h3 h4 h5 h6 h7,
have h8 : cong b a' a1 e d' d1,
exact six10 (h1.1.trans h2.symm) (h1.2.2.1.trans h4.symm) h1.2.2.2.2.1.flip h6,
have h9 : eqd a1 c' d1 f',
suffices : fs b a' a1 c' e d' d1 f',
exact four16 this h1.1.1.symm,
repeat {split},
exact (four11 (six4.1 (h1.1.trans h2.symm)).1).2.1,
exact h8.1,
exact h8.2.1,
exact h8.2.2,
exact h1.2.2.2.2.2.1,
exact h1.2.2.2.2.2.2,
suffices : fs b c' c1 a1 e f' f1 d1,
exact (four16 this h1.2.1.1.symm).flip,
repeat {split},
exact (four11 (six4.1 (h1.2.1.trans h3.symm)).1).2.1,
exact h1.2.2.2.2.2.1,
exact (six10 (h1.2.1.trans h3.symm) (h1.2.2.2.1.trans h5.symm) h1.2.2.2.2.2.1 h7).2.1,
exact h7,
exact h6,
exact h9.flip
end
theorem eleven2a {a b c d e f : point} : (a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e ∧
∀ {a' c' d' f'}, sided b a' a → sided b c' c → sided e d' d → sided e f' f → eqd b a' e d' → eqd b c' e f' → eqd a' c' d' f') →
eqa a b c d e f :=
begin
intro h,
unfold eqa,
split,
exact h.1,
split,
exact h.2.1,
split,
exact h.2.2.1,
split,
exact h.2.2.2.1,
cases seg_cons a e d b with a' ha',
cases seg_cons c e f b with c' hc',
cases seg_cons d b a e with d' hd',
cases seg_cons f b c e with f' hf',
existsi [a', c', d', f'],
repeat {split},
exact ha'.1,
exact ha'.2,
exact hc'.1,
exact hc'.2,
exact hd'.1,
exact hd'.2,
exact hf'.1,
exact hf'.2,
apply h.2.2.2.2,
exact (six7 ha'.1 h.1).symm,
exact (six7 hc'.1 h.2.1).symm,
exact (six7 hd'.1 h.2.2.1).symm,
exact (six7 hf'.1 h.2.2.2.1).symm,
exact two5 (two11 ha'.1 hd'.1.symm (two5 hd'.2.symm) (two5 ha'.2)),
exact two5 (two11 hc'.1 hf'.1.symm (two5 hf'.2.symm) (two5 hc'.2))
end
theorem eleven3 {a b c d e f : point} : eqa a b c d e f ↔ ∃ a' c' d' f', sided b a' a ∧
sided b c' c ∧ sided e d' d ∧ sided e f' f ∧ cong a' b c' d' e f' :=
⟨λ h, eleven3a h, λ h, eleven2a (eleven4a h)⟩
theorem eleven4 {a b c d e f : point} : eqa a b c d e f ↔ a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e ∧
∀ {a' c' d' f'}, sided b a' a → sided b c' c → sided e d' d → sided e f' f → eqd b a' e d' → eqd b c' e f' → eqd a' c' d' f' :=
⟨λ h, eleven4a (eleven3a h), λ h, eleven2a h⟩
lemma eleven5 {a b c d e f : point} : eqa a b c d e f ↔ ∃ d' f', sided e d' d ∧ sided e f' f ∧ cong a b c d' e f' :=
begin
split,
intro h,
cases exists_of_exists_unique (six11 h.2.2.1 h.1.symm) with d' hd,
cases exists_of_exists_unique (six11 h.2.2.2.1 h.2.1.symm) with f' hf,
refine ⟨d', f', hd.1, hf.1, _⟩,
exact ⟨hd.2.symm.flip, hf.2.symm, (eleven4.1 h).2.2.2.2 (six5 h.1) (six5 h.2.1) hd.1 hf.1 hd.2.symm hf.2.symm⟩,
rintros ⟨d', f', h, h1, h2⟩,
apply eleven3.2 ⟨a, c, d', f', _, _, h, h1, h2⟩,
exact six5 (two7 h2.1.symm h.1),
exact six5 (two7 h2.2.1.symm.flip h1.1)
end
theorem eqa.refl {a b c : point} : a ≠ b → c ≠ b → eqa a b c a b c :=
begin
intros h h1,
rw eleven3,
existsi [a, c, a, c],
simp [six5 h, six5 h1]
end
theorem eqa.symm {a b c d e f : point} : eqa a b c d e f → eqa d e f a b c :=
begin
unfold eqa,
rintros ⟨h, h1, h2, h3, a', c', d', f', h4, h5, h6, h7, h8, h9, h10, h11, h12⟩,
simp [*, -exists_and_distrib_left],
existsi [d', f', a', c'],
simp [*, h12.symm]
end
theorem eqa.trans {a b c d e f p q r : point} : eqa a b c d e f → eqa d e f p q r → eqa a b c p q r :=
begin
intros h g,
have h1 := h,
rw eleven3 at h1,
rcases h1 with ⟨a', c', d', f', h1, h2, h3, h4, h5, h6, h7⟩,
rw eleven4 at g,
cases seg_cons a' p q b with a₁ ha,
cases seg_cons c' r q b with c₁ hc,
cases seg_cons d' p q e with d₁ hd,
cases seg_cons f' r q e with f₁ hf,
cases seg_cons p d' e q with p₁ hp,
cases seg_cons r f' e q with r₁ hr,
have h8 : eqd b a₁ e d₁,
exact two11 ha.1 hd.1 h5.flip (ha.2.trans hd.2.symm),
have h9 : eqd b c₁ e f₁,
exact two11 hc.1 hf.1 h6 (hc.2.trans hf.2.symm),
have h10 : eqd e d₁ q p₁,
exact two5 (two11 hd.1 hp.1.symm hp.2.symm.flip hd.2),
have h11 : eqd e f₁ q r₁,
exact two5 (two11 hf.1 hr.1.symm hr.2.symm.flip hf.2),
have h12 : sided b a₁ a,
exact six7a ha.1 h1,
have h13 : sided b c₁ c,
exact six7a hc.1 h2,
have h14 : sided e d₁ d,
exact six7a hd.1 h3,
have h15 : sided e f₁ f,
exact six7a hf.1 h4,
have h16 : sided q p₁ p,
exact (six7 hp.1 g.2.2.1).symm,
have h17 : sided q r₁ r,
exact (six7 hr.1 g.2.2.2.1).symm,
have h18 := g.2.2.2.2 h14 h15 h16 h17 h10 h11,
rw eleven3,
existsi [a₁, c₁, p₁, r₁],
simp *,
split,
exact (h8.trans h10).flip,
split,
exact h9.trans h11,
apply eqd.trans _ h18,
rw eleven4 at h,
exact h.2.2.2.2 h12 h13 h14 h15 h8 h9
end
theorem eleven6 {a b c : point} : a ≠ b → c ≠ b → eqa a b c c b a :=
begin
intros h h1,
cases seg_cons a c b b with a' ha,
cases seg_cons c a b b with c' hc,
rw eleven3,
existsi [a', c', c', a'],
simp [(six7 ha.1 h).symm, (six7 hc.1 h1).symm],
unfold cong,
have h3 : eqd b a' c' b,
exact two11 ha.1 hc.1.symm hc.2.symm.flip ha.2,
split,
exact two4 h3,
split,
exact two4 h3.symm,
exact two5 (eqd.refl a' c')
end
theorem eleven7 {a b c d e f : point} : eqa a b c d e f → eqa c b a d e f :=
λ h, (eleven6 h.1 h.2.1).symm.trans h
theorem eleven8 {a b c d e f : point} : eqa a b c d e f → eqa a b c f e d :=
λ h, h.trans (eleven6 h.2.2.1 h.2.2.2.1)
theorem eqa.flip {a b c d e f : point} : eqa a b c d e f → eqa c b a f e d :=
λ h, eleven8 (eleven7 h)
theorem eleven9 {a b c a' c' : point} : sided b a' a → sided b c' c → eqa a b c a' b c' :=
begin
intros h h1,
rw eleven3,
existsi [a', c', a', c'],
simp [h, h1, six5 h.1, six5 h1.1]
end
theorem eleven10 {a b c d e f a' c' d' f' : point} : eqa a b c d e f → sided b a' a → sided b c' c →
sided e d' d → sided e f' f → eqa a' b c' d' e f' :=
begin
intros h h1 h2 h3 h4,
exact (eleven9 h1 h2).symm.trans (h.trans (eleven9 h3 h4))
end
theorem eleven11 {a b c d e f : point} : a ≠ b → c ≠ b → cong a b c d e f → eqa a b c d e f :=
λ h h1 h2, eleven3.2 ⟨a, c, d, f, (six5 h), (six5 h1), (six5 (two7 h2.1 h)), (six5 (two7 h2.2.1.flip h1)), h2⟩
theorem eleven12 {a b c : point} (p : point): a ≠ b → c ≠ b → eqa a b c (S p a) (S p b) (S p c) :=
begin
intros h h1,
rw eleven3,
existsi [a, c, (S p a), (S p c)],
simp [six5 h, six5 h1, six5 (seven9a p h), six5 (seven9a p h1), seven16a p]
end
theorem eleven12a {a b c : point} {A : set point} (h : line A) : a ≠ b → c ≠ b → eqa a b c (Sl A a) (Sl A b) (Sl A c) :=
begin
intros h1 h2,
rw eleven3,
existsi [a, c, (Sl A a), (Sl A c)],
simp [six5 h1, six5 h2, six5 (ten7a h h1), six5 (ten7a h h2), ten11c h a b c]
end
theorem eleven13 {a b c d e f a' d' : point} : eqa a b c d e f → a' ≠ b → B a b a' → d' ≠ e → B d e d' → eqa a' b c d' e f :=
begin
intros h h1 h2 h3 h4,
rw eleven3 at h,
rcases h with ⟨a₁, c₁, d₁, f₁, h⟩,
suffices : eqa (S b a₁) b c (S e d₁) e f,
apply eleven10 this,
split,
exact h1,
split,
exact this.1,
suffices : B a b (S b a₁),
exact five2 h.1.2.1 h2 this,
exact (six6 (seven5 b a₁).1.symm h.1).symm,
exact six5 h.2.1.2.1,
split,
exact h3,
split,
exact this.2.2.1,
suffices : B d e (S e d₁),
exact five2 h.2.2.1.2.1 h4 this,
exact (six6 (seven5 e d₁).1.symm h.2.2.1).symm,
exact six5 h.2.2.2.1.2.1,
rw eleven3,
existsi [(S b a₁), c₁, (S e d₁), f₁],
simp [six5 (seven12a h.1.1), h.2.1, six5 (seven12a h.2.2.1.1), h.2.2.2.1],
split,
exact (seven5 b a₁).2.symm.flip.trans (h.2.2.2.2.1.trans (seven5 e d₁).2.flip),
split,
exact h.2.2.2.2.2.1,
suffices : afs a₁ b (S b a₁) c₁ d₁ e (S e d₁) f₁,
exact afive_seg this h.1.1,
repeat {split},
exact (seven5 b a₁).1,
exact (seven5 e d₁).1,
exact h.2.2.2.2.1,
exact (seven5 b a₁).2.symm.trans (h.2.2.2.2.1.flip.trans (seven5 e d₁).2),
exact h.2.2.2.2.2.2,
exact h.2.2.2.2.2.1
end
theorem eleven14 {a b c a' c' : point} : a ≠ b → c ≠ b → a' ≠ b → c' ≠ b → B a b a' → B c b c' → eqa a b c a' b c' :=
begin
intros h h1 h2 h3 h4 h5,
apply (eleven12 b h h1).trans,
simp,
suffices : sided b a' (S b a) ∧ sided b c' (S b c),
exact eleven9 this.1 this.2,
split,
apply six3.2,
split,
exact h2,
split,
exact (seven12a h),
existsi a,
split,
exact h,
split,
exact h4.symm,
exact (seven5 b a).1.symm,
apply six3.2,
split,
exact h3,
split,
exact (seven12a h1),
existsi c,
split,
exact h1,
split,
exact h5.symm,
exact (seven5 b c).1.symm
end
theorem eleven15a {a b c d e p : point} : ¬col a b c → ¬col d e p → ∃ f, eqa a b c d e f ∧ side (l d e) f p :=
begin
intros h h1,
cases exists_of_exists_unique (six11 (six26 h1).1 (six26 h).1.symm) with d' hd,
have h2 : ¬col d' e p,
intro h_1,
have h_2 := (six4.1 hd.1).1,
exact (four10 h1).2.2.1 (five4 hd.1.1.symm (four11 h_1).2.1 (four11 h_2).2.1),
cases ten16 h h2 hd.2.symm.flip with f hf,
dsimp at hf,
existsi f,
split,
rw eleven3,
existsi [a, c, d', f],
simp [six5 (six26 h).1, six5 (six26 h).2.1.symm, hd.1, hf.1.1],
apply six5,
intro h_1,
subst f,
exact (six26 h).2.1 (id_eqd hf.1.1.2.1),
have h3 : l d e = l d' e,
exact six18 (six14 (six26 h1).1) hd.1.1 (four11 (six4.1 hd.1).1).2.2.2.2 (six17b d e),
rw h3,
exact hf.1.2
end
theorem eleven15b {a b c d e p : point} : ¬col a b c → ¬col d e p → ∀ {f1 f2}, eqa a b c d e f1 →
side (l d e) f1 p → eqa a b c d e f2 → side (l d e) f2 p → sided e f1 f2 :=
begin
intros h h1 f1 f2 h2 h3 h4 h5,
cases exists_of_exists_unique (six11 (six26 h1).1 (six26 h).1.symm) with d' hd,
have h6 : ¬col d' e p,
intro h_1,
have h_2 := (six4.1 hd.1).1,
exact (four10 h1).2.2.1 (five4 hd.1.1.symm (four11 h_1).2.1 (four11 h_2).2.1),
cases ten16 h h6 hd.2.symm.flip with f hf,
dsimp at hf,
have h7 : f1 ≠ e,
intro h_1,
subst f1,
exact (nine11 h3).2.1 (six17b d e),
have h8 : f2 ≠ e,
intro h_1,
subst f2,
exact (nine11 h5).2.1 (six17b d e),
cases exists_of_exists_unique (six11 h7 (six26 h).2.1) with f₁ h9,
cases exists_of_exists_unique (six11 h8 (six26 h).2.1) with f₂ h10,
have h11 : cong a b c d' e f₁,
split,
exact hf.1.1.1,
split,
exact h9.2.symm,
suffices : eqa a b c d' e f₁,
apply (eleven4.1 this).2.2.2.2 (six5 (six26 h).1) (six5 (six26 h).2.1.symm) (six5 hd.1.1) (six5 h9.1.1),
exact hf.1.1.1.flip,
exact h9.2.symm,
exact h2.trans (eleven9 hd.1 h9.1),
have h12 : cong a b c d' e f₂,
split,
exact hf.1.1.1,
split,
exact h10.2.symm,
suffices : eqa a b c d' e f₂,
apply (eleven4.1 this).2.2.2.2 (six5 (six26 h).1) (six5 (six26 h).2.1.symm) (six5 hd.1.1) (six5 h10.1.1),
exact hf.1.1.1.flip,
exact h10.2.symm,
exact h4.trans (eleven9 hd.1 h10.1),
have h13 : l d e = l d' e,
exact six18 (six14 (six26 h1).1) hd.1.1 (four11 (six4.1 hd.1).1).2.2.2.2 (six17b d e),
have h14 : side (l d' e) f₁ p,
rw h13 at *,
exact (nine19a h3.symm (six17b d' e) h9.1.symm).symm,
have h15 : side (l d' e) f₂ p,
rw h13 at *,
exact (nine19a h5.symm (six17b d' e) h10.1.symm).symm,
have h16 : f₁ = f,
apply hf.2,
split,
exact h11,
exact h14,
subst f₁,
have h16 : f₂ = f,
apply hf.2,
split,
exact h12,
exact h15,
subst f₂,
exact h9.1.symm.trans h10.1
end
theorem eleven15c {a b c x : point} : eqa a b c a b x → side (l a b) c x → sided b c x :=
begin
intros h h1,
have h2 : ¬col a b c,
exact (nine11 h1).2.1,
apply eleven15b h2 h2 (eqa.refl (six26 h2).1 (six26 h2).2.1.symm) (side.refla h2) h,
exact h1.symm
end
theorem eleven16 {a b c a' b' c' : point} : a ≠ b → c ≠ b → a' ≠ b' → c' ≠ b' → R a b c → R a' b' c' →
eqa a b c a' b' c' :=
begin
intros h h1 h2 h3 h4 h5,
cases exists_of_exists_unique (six11 h2 h.symm) with a₁ ha,
cases exists_of_exists_unique (six11 h3 h1.symm) with c₁ hc,
rw eleven3,
existsi [a, c, a₁, c₁],
simp [six5 h, six5 h1, ha.1, hc.1],
refine ⟨ha.2.symm.flip, hc.2.symm, _⟩,
apply ten12 h4,
suffices : R a' b' c₁,
apply eight3 this h2,
exact (four11 (six4.1 ha.1).1).2.2.1,
apply R.symm,
apply eight3 h5.symm h3,
exact (four11 (six4.1 hc.1).1).2.2.1,
exact ha.2.symm.flip,
exact hc.2.symm
end
theorem eleven17 {a b c a' b' c' : point} : R a b c → eqa a b c a' b' c' → R a' b' c' :=
begin
intros h h1,
rcases eleven5.1 h1 with ⟨a₁, c₁, ha, hc, h2⟩,
apply eight3 _ ha.1 (four11 (six4.1 ha).1).2.1,
exact (eight3 (eight10 h h2).symm hc.1 (four11 (six4.1 hc).1).2.1).symm
end
theorem eleven18 {a b c d : point} : B c b d → c ≠ b → d ≠ b → a ≠ b → (R a b c ↔ eqa a b c a b d) :=
begin
intros h h1 h2 h3,
split,
intro h4,
have h5 : R a b d,
apply (eight3 h4.symm h1 _).symm,
right, right,
exact h.symm,
exact eleven16 h3 h1 h3 h2 h4 h5,
intro h4,
rw eleven3 at h4,
rcases h4 with ⟨a', c', a₁, d', h4⟩,
have : a₁ = a',
apply unique_of_exists_unique (six11 h3 h4.2.2.1.1.symm),
split,
exact h4.2.2.1,
exact eqd.refl b a₁,
split,
exact h4.1,
exact h4.2.2.2.2.1.flip,
subst a₁,
have : d' = (S b c'),
exact two12 h4.2.1.1 (six8 h4.2.1 h4.2.2.2.1 h) h4.2.2.2.2.2.1.symm (seven5 b c').1 (seven5 b c').2.symm,
subst d',
have h5 : R a' b c',
unfold R,
exact h4.2.2.2.2.2.2,
exact eleven17 h5 (eleven9 h4.1.symm h4.2.1.symm)
end
theorem eleven19 {a b p q : point} : R b a p → R b a q → side (l a b) p q → sided a p q :=
begin
intros h h1 h2,
have h3 : ¬col b a p,
exact (four10 (nine11 h2).2.1).2.1,
have h4 : ¬col b a q,
exact (four10 (nine11 h2).2.2).2.1,
rw six17 at h2,
apply (eleven15b h3 h3),
exact eqa.refl (six26 h3).1 (six26 h3).2.1.symm,
exact side.refl (nine11 h2).1 (nine11 h2).2.1,
exact eleven16 (six26 h3).1 (six26 h3).2.1.symm (six26 h4).1 (six26 h4).2.1.symm h h1,
exact h2.symm
end
theorem eleven20 {a : point} {A P : set point} : line A → plane P → a ∈ A → A ⊆ P → ∃! B, B ⊆ P ∧ xperp a A B :=
begin
intros h h1 h2 h3,
cases six22 h h2 with b hb,
cases (nine25 h1 (h3 h2) _ hb.1 ).2 with x hx,
show b ∈ P,
apply h3,
rw hb.2,
simp,
rw hb.2 at *,
have h4 : x ∉ l a b,
apply nine28 (six14 hb.1),
rwa hx at h1,
cases ten15 h h2 h4 with c hc,
have h5 : c ∈ P,
rw hx,
left,
exact hc.2,
apply exists_unique.intro (l c a),
split,
exact (nine25 h1 h5 (h3 h2) (six13 (eight14e hc.1).2)).1,
exact eight15 hc.1 (six17a a b) (six17b c a),
intros Y h6,
have h7 : c ∉ l a b,
intro h_1,
apply eight14a hc.1,
exact six18 (six14 hb.1) (six13 (eight14e hc.1).2) h_1 (six17a a b),
have h8 : P = planeof a b c,
apply nine26 h7 h1 _ _ h5,
exact h3 (six17a a b),
exact h3 (six17b a b),
cases (six22 h6.2.2.1 h6.2.2.2.2.1) with y hy,
have h9 : R b a c,
exact (eight15 hc.1 (six17a a b) (six17b c a)).2.2.2.2 (six17b a b) (six17a c a),
rw h8 at h6,
have h10 : y ∈ Y,
rw hy.2,
simp,
have h11 : R b a y,
exact h6.2.2.2.2.2 (six17b a b) h10,
rw hy.2 at *,
cases (h6.1 h10),
have h12 : sided a c y,
exact eleven19 h9 h11 h_1.symm,
exact six18 (six14 hy.1) (six13 (eight14e hc.1).2) (four11 (six4.1 h12).1).2.2.1 (six17a a y),
cases h_1,
exfalso,
apply (eight14b h6.2),
exact six18 h hy.1 (six17a a b) h_1,
haveI h12 := six14 hb.1,
have h13 : side (l a b) y (Sl (l a b) c),
exact (nine8 h_1.symm).1 (ten14 h12 h7).symm,
have h14 : side (l a b) y (S a c),
have h_2 : S a c = Sl (l a b) c,
have h_3 := ten12b h12.symm h9.flip,
simp only [six17] at h_3,
simpa using h_3,
rwa h_2,
apply eq.symm,
apply six18 (eight14e hc.1).2 hy.1 (six17b c a) (or.inl $ six6 (seven5 a c).1 (eleven19 h11 h9.flip h14).symm)
end
theorem eleven21a {a b c a' b' c' : point} (h : sided b a c) : eqa a b c a' b' c' ↔ sided b' a' c' :=
begin
split,
intro h1,
rcases eleven5.1 h1 with ⟨a₁, c₁, ha, hc, h2⟩,
suffices : sided b' a₁ c₁,
exact ha.symm.trans (this.trans hc),
apply six10a h ⟨h2.1.flip, _, h2.2.1⟩,
exact (eleven4.1 h1).2.2.2.2 (six5 h1.1) (six5 h1.2.1) ha hc h2.1.flip h2.2.1,
intro h1,
cases exists_of_exists_unique (six11 h1.1 h.1.symm) with a₁ ha,
apply eleven3.2 ⟨a, a, a₁, a₁, _ ⟩,
simp [six5 h.1, h, ha.1, ha.1.trans h1],
exact ⟨ha.2.symm.flip, ha.2.symm, two8 a a₁⟩
end
theorem eleven21b {a b c a' b' c' : point} : B a b c → eqa a b c a' b' c' → B a' b' c' :=
begin
intros h h1,
rcases eleven5.1 h1 with ⟨a₁, c₁, ha, hc, h2⟩,
exact six8 ha.symm hc.symm (four6 h h2)
end
theorem eleven21c {a b c a' b' c' : point} : a ≠ b → c ≠ b → a' ≠ b' → c' ≠ b' → B a b c → B a' b' c' → eqa a b c a' b' c' :=
begin
intros h h1 h2 h3 h4 h5,
cases exists_of_exists_unique (six11 h2 h.symm) with a₁ ha,
cases exists_of_exists_unique (six11 h3 h1.symm) with c₁ hc,
apply eleven3.2 ⟨a, c, a₁, c₁, (six5 h), (six5 h1), ha.1, hc.1, ha.2.symm.flip, hc.2.symm, _⟩,
exact two11 h4 (six8 ha.1 hc.1 h5) ha.2.symm.flip hc.2.symm
end
theorem eleven21d {a b c a' b' c' : point} : col a b c → eqa a b c a' b' c' → col a' b' c' :=
begin
intros h h1,
cases six1 h,
exact or.inl (eleven21b h_1 h1),
exact (six4.1 ((eleven21a h_1).1 h1)).1
end
end Euclidean_plane |
b514635ee149d03e6381b9c4c40af37d068b7944 | bab2ace2b909818f20ac125499a8dd88ce812721 | /src/2020/relations/equiv_partition3.lean | de385442420176c55b2b82ce3b2d7f11bc4c1af6 | [] | no_license | LaplaceKorea/M40001_lean | 8a3cd411fb821a7665132c09e436f02f674cc666 | 116e9ed1fadf59dc2e78376fca92026859a03bf2 | refs/heads/master | 1,693,347,195,820 | 1,635,517,507,000 | 1,635,517,507,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,319 | lean | import data.equiv.basic
structure partition (X : Type) :=
(C : set (set X))
(Hnonempty : ∀ c ∈ C, c ≠ ∅)
(Hcover : ∀ x, ∃ c ∈ C, x ∈ c)
(Hunique : ∀ c d ∈ C, c ∩ d ≠ ∅ → c = d)
def partition.ext {X : Type} (P Q : partition X) (H : P.C = Q.C) : P = Q :=
begin
cases P, cases Q,
simpa using H,
end
def equivalence_class {X : Type} (R : X → X → Prop) (x : X) := {y : X | R x y}
lemma mem_class {X : Type} {R : X → X → Prop} (HR : equivalence R) (x : X) : x ∈ equivalence_class R x :=
begin
cases HR with HRR HR,
exact HRR x,
end
example (X : Type) : {R : X → X → Prop // equivalence R} ≃ partition X :=
{ to_fun := λ R, {
C := { S : set X | ∃ x : X, S = equivalence_class R x},
Hnonempty := begin
intro c,
intro hc,
cases hc with x hx,
rw set.ne_empty_iff_nonempty,
use x,
rw hx,
exact mem_class R.2 x,
end,
Hcover := begin
intro x,
use equivalence_class R x,
existsi _,
{ exact mem_class R.2 x },
use x,
end,
Hunique := begin
intros c d hc hd hcd,
rw set.ne_empty_iff_nonempty at hcd,
cases hcd with x hx,
cases hc with a ha,
cases hd with b hb,
cases R with R HR,
cases hx with hxc hxd,
rw ha at *,
rw hb at *,
change R a x at hxc,
change R b x at hxd,
rcases HR with ⟨HRR, HRS, HRT⟩,
apply set.subset.antisymm,
{ intros y hy,
change R a y at hy,
change R b y,
refine HRT hxd _,
refine HRT _ hy,
apply HRS,
assumption
},
{ intros y hy,
change R a y,
change R b y at hy,
refine HRT hxc _,
refine HRT _ hy,
apply HRS,
assumption,
}
end },
inv_fun := λ P, ⟨λ x y, ∃ c ∈ P.C, x ∈ c ∧ y ∈ c, begin
split,
{ intro x,
cases P.Hcover x with c hc,
cases hc with hc hxc,
use c,
use hc,
split; assumption,
},
split,
{ intros x y hxy,
cases hxy with c hc,
cases hc with hc1 hc2,
use c,
use hc1,
cases hc2 with hx hy,
split; assumption
},
{ rintros x y z ⟨c, hc, hxc, hyc⟩ ⟨d, hd, hyd, hzd⟩,
use c,
use hc,
split,
exact hxc,
have hcd : c = d,
{ apply P.Hunique c d,
use hc,
use hd,
rw set.ne_empty_iff_nonempty,
use y,
split,
use hyc,
use hyd,
},
rw hcd,
use hzd,
}
end⟩,
left_inv := begin
rintro ⟨R, HRR, HRS, HRT⟩,
ext x y,
suffices : (∃ (c : set X), (∃ (x : X), c = equivalence_class R x) ∧ x ∈ c ∧ y ∈ c) ↔ R x y,
simpa,
split,
{ rintro ⟨c, ⟨z, rfl⟩, ⟨hx, hy⟩⟩,
refine HRT _ hy,
apply HRS,
exact hx,
},
{ intro H,
use equivalence_class R x,
use x,
split,
exact HRR x,
exact H,
}
end,
right_inv := begin
intro P,
dsimp,
cases P with C _ _ _,
dsimp,
apply partition.ext,
dsimp, -- dsimps everywhere
ext c,
split,
{ intro h,
dsimp at h,
cases h with x hx,
rw hx, clear hx,
rcases P_Hcover x with ⟨d, hd, hxd⟩,
convert hd, -- not taught in NNG
clear c,
ext y,
split,
{ intro hy,
unfold equivalence_class at hy,
dsimp at hy,
rcases hy with ⟨e, he, hxe, hye⟩,
convert hye, -- not taught
refine P_Hunique d e hd he _,
rw set.ne_empty_iff_nonempty,
use x,
split;assumption
},
{ intro hyd,
unfold equivalence_class, dsimp,
use d,
use hd,
split;assumption
},
},
{ intro hc,
dsimp,
have h := P_Hnonempty c hc,
rw set.ne_empty_iff_nonempty at h,
cases h with x hxc,
use x,
unfold equivalence_class,
ext y,
split,
{ intro hyc,
dsimp,
use c,
use hc,
split;assumption,
},
{ intro h,
dsimp at h,
rcases h with ⟨d, hd, hxd, hyd⟩,
convert hyd,
apply P_Hunique c d hc hd,
rw set.ne_empty_iff_nonempty,
use x,
split;assumption
}
}
end }
|
e1779d6e80132577b0aa0aee5f366a0131588975 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/linear_algebra/clifford_algebra/grading.lean | 62c4a7a2289a97a429d1180487fb4bbbcf471534 | [
"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 | 5,019 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import linear_algebra.clifford_algebra.basic
import data.zmod.basic
import ring_theory.graded_algebra.basic
/-!
# Results about the grading structure of the clifford algebra
The main result is `clifford_algebra.graded_algebra`, which says that the clifford algebra is a
ℤ₂-graded algebra (or "superalgebra").
-/
namespace clifford_algebra
variables {R M : Type*} [comm_ring R] [add_comm_group M] [module R M]
variables {Q : quadratic_form R M}
open_locale direct_sum
variables (Q)
/-- The even or odd submodule, defined as the supremum of the even or odd powers of
`(ι Q).range`. `even_odd 0` is the even submodule, and `even_odd 1` is the odd submodule. -/
def even_odd (i : zmod 2) : submodule R (clifford_algebra Q) :=
⨆ (j : {n : ℕ // ↑n = i}), (ι Q).range ^ (j : ℕ)
lemma one_le_even_odd_zero : 1 ≤ even_odd Q 0 :=
begin
refine le_trans _ (le_supr _ ⟨0, nat.cast_zero⟩),
exact (pow_zero _).ge,
end
lemma range_ι_le_even_odd_one : (ι Q).range ≤ even_odd Q 1 :=
begin
refine le_trans _ (le_supr _ ⟨1, nat.cast_one⟩),
exact (pow_one _).ge,
end
lemma even_odd_mul_le (i j : zmod 2) : even_odd Q i * even_odd Q j ≤ even_odd Q (i + j) :=
begin
simp_rw [even_odd, submodule.supr_eq_span, submodule.span_mul_span],
apply submodule.span_mono,
intros z hz,
obtain ⟨x, y, hx, hy, rfl⟩ := hz,
obtain ⟨xi, hx'⟩ := set.mem_Union.mp hx,
obtain ⟨yi, hy'⟩ := set.mem_Union.mp hy,
refine set.mem_Union.mpr ⟨⟨xi + yi, by simp only [nat.cast_add, xi.prop, yi.prop]⟩, _⟩,
simp only [subtype.coe_mk, nat.cast_add, pow_add],
exact submodule.mul_mem_mul hx' hy',
end
instance even_odd.graded_monoid : set_like.graded_monoid (even_odd Q) :=
{ one_mem := submodule.one_le.mp (one_le_even_odd_zero Q),
mul_mem := λ i j p q hp hq, submodule.mul_le.mp (even_odd_mul_le Q _ _) _ hp _ hq }
/-- A version of `clifford_algebra.ι` that maps directly into the graded structure. This is
primarily an auxiliary construction used to provide `clifford_algebra.graded_algebra`. -/
def graded_algebra.ι : M →ₗ[R] ⨁ i : zmod 2, even_odd Q i :=
direct_sum.lof R (zmod 2) (λ i, ↥(even_odd Q i)) 1
∘ₗ (ι Q).cod_restrict _ (λ m, range_ι_le_even_odd_one Q $ linear_map.mem_range_self _ m)
lemma graded_algebra.ι_apply (m : M) :
graded_algebra.ι Q m =
direct_sum.of (λ i, ↥(even_odd Q i)) 1
(⟨ι Q m, range_ι_le_even_odd_one Q $ linear_map.mem_range_self _ m⟩) := rfl
lemma graded_algebra.ι_sq_scalar (m : M) :
graded_algebra.ι Q m * graded_algebra.ι Q m = algebra_map R _ (Q m) :=
begin
rw [graded_algebra.ι_apply, direct_sum.of_mul_of, direct_sum.algebra_map_apply],
refine direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext rfl $ ι_sq_scalar _ _),
end
/-- The clifford algebra is graded by the even and odd parts. -/
instance graded_algebra : graded_algebra (even_odd Q) :=
graded_algebra.of_alg_hom _
(lift _ $ ⟨graded_algebra.ι Q, graded_algebra.ι_sq_scalar Q⟩)
-- the proof from here onward is mostly similar to the `tensor_algebra` case, with some extra
-- handling for the `supr` in `even_odd`.
(begin
ext m,
dsimp only [linear_map.comp_apply, alg_hom.to_linear_map_apply, alg_hom.comp_apply,
alg_hom.id_apply],
rw [lift_ι_apply, graded_algebra.ι_apply, direct_sum.submodule_coe_alg_hom_of, subtype.coe_mk],
end)
(λ i' x', begin
cases x' with x' hx',
dsimp only [subtype.coe_mk, direct_sum.lof_eq_of],
refine submodule.supr_induction' _ (λ i x hx, _) _ (λ x y hx hy ihx ihy, _) hx',
{ obtain ⟨i, rfl⟩ := i,
dsimp only [subtype.coe_mk] at hx,
refine submodule.pow_induction_on' _
(λ r, _) (λ x y i hx hy ihx ihy, _) (λ m hm i x hx ih, _) hx,
{ rw [alg_hom.commutes, direct_sum.algebra_map_apply], refl },
{ rw [alg_hom.map_add, ihx, ihy, ←map_add], refl },
{ obtain ⟨_, rfl⟩ := hm,
rw [alg_hom.map_mul, ih, lift_ι_apply, graded_algebra.ι_apply, direct_sum.of_mul_of],
refine direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext _ _),
dsimp only [graded_monoid.mk, subtype.coe_mk],
{ rw [nat.succ_eq_add_one, add_comm], refl },
refl } },
{ rw alg_hom.map_zero,
apply eq.symm,
apply dfinsupp.single_eq_zero.mpr, refl, },
{ rw [alg_hom.map_add, ihx, ihy, ←map_add], refl },
end)
lemma supr_ι_range_eq_top : (⨆ i : ℕ, (ι Q).range ^ i) = ⊤ :=
begin
rw [← (graded_algebra.is_internal $ λ i, even_odd Q i).supr_eq_top, eq_comm],
dunfold even_odd,
calc (⨆ (i : zmod 2) (j : {n // ↑n = i}), (ι Q).range ^ ↑j)
= (⨆ (i : Σ i : zmod 2, {n : ℕ // ↑n = i}), (ι Q).range ^ (i.2 : ℕ)) : by rw supr_sigma
... = (⨆ (i : ℕ), (ι Q).range ^ i) : supr_congr (λ i, i.2) (λ i, ⟨⟨_, i, rfl⟩, rfl⟩) (λ _, rfl),
end
end clifford_algebra
|
e29cd10ae67e38e49a5694e7f659aeb009d3acc4 | b2e508d02500f1512e1618150413e6be69d9db10 | /src/category_theory/types.lean | 0eab43cb8a6018e8e7c7f590630ffc97962505b8 | [
"Apache-2.0"
] | permissive | callum-sutton/mathlib | c3788f90216e9cd43eeffcb9f8c9f959b3b01771 | afd623825a3ac6bfbcc675a9b023edad3f069e89 | refs/heads/master | 1,591,371,888,053 | 1,560,990,690,000 | 1,560,990,690,000 | 192,476,045 | 0 | 0 | Apache-2.0 | 1,568,941,843,000 | 1,560,837,965,000 | Lean | UTF-8 | Lean | false | false | 4,515 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan, Scott Morrison, Johannes Hölzl
import category_theory.functor_category
import category_theory.fully_faithful
import data.equiv.basic
namespace category_theory
universes v v' w u u' -- declare the `v`'s first; see `category_theory.category` for an explanation
instance types : large_category (Sort u) :=
{ hom := λ a b, (a → b),
id := λ a, id,
comp := λ _ _ _ f g, g ∘ f }
@[simp] lemma types_hom {α β : Sort u} : (α ⟶ β) = (α → β) := rfl
@[simp] lemma types_id (X : Sort u) : 𝟙 X = id := rfl
@[simp] lemma types_comp {X Y Z : Sort u} (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ g = g ∘ f := rfl
namespace functor
variables {J : Type u} [𝒥 : category.{v} J]
include 𝒥
def sections (F : J ⥤ Type w) : set (Π j, F.obj j) :=
{ u | ∀ {j j'} (f : j ⟶ j'), F.map f (u j) = u j'}
end functor
namespace functor_to_types
variables {C : Type u} [𝒞 : category.{v} C] (F G H : C ⥤ Sort w) {X Y Z : C}
include 𝒞
variables (σ : F ⟶ G) (τ : G ⟶ H)
@[simp] lemma map_comp (f : X ⟶ Y) (g : Y ⟶ Z) (a : F.obj X) : (F.map (f ≫ g)) a = (F.map g) ((F.map f) a) :=
by simp
@[simp] lemma map_id (a : F.obj X) : (F.map (𝟙 X)) a = a :=
by simp
lemma naturality (f : X ⟶ Y) (x : F.obj X) : σ.app Y ((F.map f) x) = (G.map f) (σ.app X x) :=
congr_fun (σ.naturality f) x
@[simp] lemma comp (x : F.obj X) : (σ ≫ τ).app X x = τ.app X (σ.app X x) := rfl
variables {D : Type u'} [𝒟 : category.{u'} D] (I J : D ⥤ C) (ρ : I ⟶ J) {W : D}
@[simp] lemma hcomp (x : (I ⋙ F).obj W) : (ρ ◫ σ).app W x = (G.map (ρ.app W)) (σ.app (I.obj W) x) := rfl
end functor_to_types
def ulift_trivial (V : Type u) : ulift.{u} V ≅ V := by tidy
def ulift_functor : Type u ⥤ Type (max u v) :=
{ obj := λ X, ulift.{v} X,
map := λ X Y f, λ x : ulift.{v} X, ulift.up (f x.down) }
@[simp] lemma ulift_functor.map {X Y : Type u} (f : X ⟶ Y) (x : ulift.{v} X) :
ulift_functor.map f x = ulift.up (f x.down) := rfl
instance ulift_functor_faithful : fully_faithful ulift_functor :=
{ preimage := λ X Y f x, (f (ulift.up x)).down,
injectivity' := λ X Y f g p, funext $ λ x,
congr_arg ulift.down ((congr_fun p (ulift.up x)) : ((ulift.up (f x)) = (ulift.up (g x)))) }
def hom_of_element {X : Type u} (x : X) : punit ⟶ X := λ _, x
lemma hom_of_element_eq_iff {X : Type u} (x y : X) :
hom_of_element x = hom_of_element y ↔ x = y :=
⟨λ H, congr_fun H punit.star, by cc⟩
lemma mono_iff_injective {X Y : Type u} (f : X ⟶ Y) : mono f ↔ function.injective f :=
begin
split,
{ intros H x x' h,
resetI,
rw ←hom_of_element_eq_iff at ⊢ h,
exact (cancel_mono f).mp h },
{ refine λ H, ⟨λ Z g h H₂, _⟩,
ext z,
replace H₂ := congr_fun H₂ z,
exact H H₂ }
end
lemma epi_iff_surjective {X Y : Type u} (f : X ⟶ Y) : epi f ↔ function.surjective f :=
begin
split,
{ intros H,
let g : Y ⟶ ulift Prop := λ y, ⟨true⟩,
let h : Y ⟶ ulift Prop := λ y, ⟨∃ x, f x = y⟩,
suffices : f ≫ g = f ≫ h,
{ resetI,
rw cancel_epi at this,
intro y,
replace this := congr_fun this y,
replace this : true = ∃ x, f x = y := congr_arg ulift.down this,
rw ←this,
trivial },
ext x,
change true ↔ ∃ x', f x' = f x,
rw true_iff,
exact ⟨x, rfl⟩ },
{ intro H,
constructor,
intros Z g h H₂,
apply funext,
rw ←forall_iff_forall_surj H,
intro x,
exact (congr_fun H₂ x : _) }
end
end category_theory
-- Isomorphisms in Type and equivalences.
namespace equiv
universe u
variables {X Y : Sort u}
def to_iso (e : X ≃ Y) : X ≅ Y :=
{ hom := e.to_fun,
inv := e.inv_fun,
hom_inv_id' := funext e.left_inv,
inv_hom_id' := funext e.right_inv }
@[simp] lemma to_iso_hom {e : X ≃ Y} : e.to_iso.hom = e := rfl
@[simp] lemma to_iso_inv {e : X ≃ Y} : e.to_iso.inv = e.symm := rfl
end equiv
namespace category_theory.iso
universe u
variables {X Y : Sort u}
def to_equiv (i : X ≅ Y) : X ≃ Y :=
{ to_fun := i.hom,
inv_fun := i.inv,
left_inv := λ x, congr_fun i.hom_inv_id x,
right_inv := λ y, congr_fun i.inv_hom_id y }
@[simp] lemma to_equiv_fun (i : X ≅ Y) : (i.to_equiv : X → Y) = i.hom := rfl
@[simp] lemma to_equiv_symm_fun (i : X ≅ Y) : (i.to_equiv.symm : Y → X) = i.inv := rfl
end category_theory.iso
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.