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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
16361a408cef319ee0568d0dcb0a0ec6858869c2 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/lie/weights.lean | 32bc6b4540044dc81ba7d5bfba170a6eafbf144e | [
"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 | 24,094 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.nilpotent
import algebra.lie.tensor_product
import algebra.lie.character
import algebra.lie.engel
import algebra.lie.cartan_subalgebra
import linear_algebra.eigenspace.basic
import ring_theory.tensor_product
/-!
# Weights and roots of Lie modules and Lie algebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Just as a key tool when studying the behaviour of a linear operator is to decompose the space on
which it acts into a sum of (generalised) eigenspaces, a key tool when studying a representation `M`
of Lie algebra `L` is to decompose `M` into a sum of simultaneous eigenspaces of `x` as `x` ranges
over `L`. These simultaneous generalised eigenspaces are known as the weight spaces of `M`.
When `L` is nilpotent, it follows from the binomial theorem that weight spaces are Lie submodules.
Even when `L` is not nilpotent, it may be useful to study its representations by restricting them
to a nilpotent subalgebra (e.g., a Cartan subalgebra). In the particular case when we view `L` as a
module over itself via the adjoint action, the weight spaces of `L` restricted to a nilpotent
subalgebra are known as root spaces.
Basic definitions and properties of the above ideas are provided in this file.
## Main definitions
* `lie_module.weight_space`
* `lie_module.is_weight`
* `lie_algebra.root_space`
* `lie_algebra.is_root`
* `lie_algebra.root_space_weight_space_product`
* `lie_algebra.root_space_product`
* `lie_algebra.zero_root_subalgebra_eq_iff_is_cartan`
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b)
## Tags
lie character, eigenvalue, eigenspace, weight, weight vector, root, root vector
-/
universes u v w w₁ w₂ w₃
variables {R : Type u} {L : Type v} [comm_ring R] [lie_ring L] [lie_algebra R L]
variables (H : lie_subalgebra R L) [lie_algebra.is_nilpotent R H]
variables (M : Type w) [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
namespace lie_module
open lie_algebra
open tensor_product
open tensor_product.lie_module
open_locale big_operators
open_locale tensor_product
/-- Given a Lie module `M` over a Lie algebra `L`, the pre-weight space of `M` with respect to a
map `χ : L → R` is the simultaneous generalized eigenspace of the action of all `x : L` on `M`,
with eigenvalues `χ x`.
See also `lie_module.weight_space`. -/
def pre_weight_space (χ : L → R) : submodule R M :=
⨅ (x : L), (to_endomorphism R L M x).maximal_generalized_eigenspace (χ x)
lemma mem_pre_weight_space (χ : L → R) (m : M) :
m ∈ pre_weight_space M χ ↔ ∀ x, ∃ (k : ℕ), ((to_endomorphism R L M x - (χ x) • 1)^k) m = 0 :=
by simp [pre_weight_space, -linear_map.pow_apply]
variables (R)
lemma exists_pre_weight_space_zero_le_ker_of_is_noetherian [is_noetherian R M] (x : L) :
∃ (k : ℕ), pre_weight_space M (0 : L → R) ≤ ((to_endomorphism R L M x)^k).ker :=
begin
use (to_endomorphism R L M x).maximal_generalized_eigenspace_index 0,
simp only [← module.End.generalized_eigenspace_zero, pre_weight_space, pi.zero_apply, infi_le,
← (to_endomorphism R L M x).maximal_generalized_eigenspace_eq],
end
variables {R} (L)
/-- See also `bourbaki1975b` Chapter VII §1.1, Proposition 2 (ii). -/
protected lemma weight_vector_multiplication (M₁ : Type w₁) (M₂ : Type w₂) (M₃ : Type w₃)
[add_comm_group M₁] [module R M₁] [lie_ring_module L M₁] [lie_module R L M₁]
[add_comm_group M₂] [module R M₂] [lie_ring_module L M₂] [lie_module R L M₂]
[add_comm_group M₃] [module R M₃] [lie_ring_module L M₃] [lie_module R L M₃]
(g : M₁ ⊗[R] M₂ →ₗ⁅R,L⁆ M₃) (χ₁ χ₂ : L → R) :
((g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp
(map_incl (pre_weight_space M₁ χ₁) (pre_weight_space M₂ χ₂))).range ≤
pre_weight_space M₃ (χ₁ + χ₂) :=
begin
/- Unpack the statement of the goal. -/
intros m₃,
simp only [lie_module_hom.coe_to_linear_map, pi.add_apply, function.comp_app,
mem_pre_weight_space, linear_map.coe_comp, tensor_product.map_incl, exists_imp_distrib,
linear_map.mem_range],
rintros t rfl x,
/- Set up some notation. -/
let F : module.End R M₃ := (to_endomorphism R L M₃ x) - (χ₁ x + χ₂ x) • 1,
change ∃ k, (F^k) (g _) = 0,
/- The goal is linear in `t` so use induction to reduce to the case that `t` is a pure tensor. -/
apply t.induction_on,
{ use 0, simp only [linear_map.map_zero, lie_module_hom.map_zero], },
swap,
{ rintros t₁ t₂ ⟨k₁, hk₁⟩ ⟨k₂, hk₂⟩, use max k₁ k₂,
simp only [lie_module_hom.map_add, linear_map.map_add,
linear_map.pow_map_zero_of_le (le_max_left k₁ k₂) hk₁,
linear_map.pow_map_zero_of_le (le_max_right k₁ k₂) hk₂, add_zero], },
/- Now the main argument: pure tensors. -/
rintros ⟨m₁, hm₁⟩ ⟨m₂, hm₂⟩,
change ∃ k, (F^k) ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃) (m₁ ⊗ₜ m₂)) = 0,
/- Eliminate `g` from the picture. -/
let f₁ : module.End R (M₁ ⊗[R] M₂) := (to_endomorphism R L M₁ x - (χ₁ x) • 1).rtensor M₂,
let f₂ : module.End R (M₁ ⊗[R] M₂) := (to_endomorphism R L M₂ x - (χ₂ x) • 1).ltensor M₁,
have h_comm_square : F ∘ₗ ↑g = (g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (f₁ + f₂),
{ ext m₁ m₂, simp only [← g.map_lie x (m₁ ⊗ₜ m₂), add_smul, sub_tmul, tmul_sub, smul_tmul,
lie_tmul_right, tmul_smul, to_endomorphism_apply_apply, lie_module_hom.map_smul,
linear_map.one_apply, lie_module_hom.coe_to_linear_map, linear_map.smul_apply,
function.comp_app, linear_map.coe_comp, linear_map.rtensor_tmul, lie_module_hom.map_add,
linear_map.add_apply, lie_module_hom.map_sub, linear_map.sub_apply, linear_map.ltensor_tmul,
algebra_tensor_module.curry_apply, curry_apply, linear_map.to_fun_eq_coe,
linear_map.coe_restrict_scalars_eq_coe], abel, },
rsuffices ⟨k, hk⟩ : ∃ k, ((f₁ + f₂)^k) (m₁ ⊗ₜ m₂) = 0,
{ use k,
rw [← linear_map.comp_apply, linear_map.commute_pow_left_of_commute h_comm_square,
linear_map.comp_apply, hk, linear_map.map_zero], },
/- Unpack the information we have about `m₁`, `m₂`. -/
simp only [mem_pre_weight_space] at hm₁ hm₂,
obtain ⟨k₁, hk₁⟩ := hm₁ x,
obtain ⟨k₂, hk₂⟩ := hm₂ x,
have hf₁ : (f₁^k₁) (m₁ ⊗ₜ m₂) = 0,
{ simp only [hk₁, zero_tmul, linear_map.rtensor_tmul, linear_map.rtensor_pow], },
have hf₂ : (f₂^k₂) (m₁ ⊗ₜ m₂) = 0,
{ simp only [hk₂, tmul_zero, linear_map.ltensor_tmul, linear_map.ltensor_pow], },
/- It's now just an application of the binomial theorem. -/
use k₁ + k₂ - 1,
have hf_comm : commute f₁ f₂,
{ ext m₁ m₂, simp only [linear_map.mul_apply, linear_map.rtensor_tmul, linear_map.ltensor_tmul,
algebra_tensor_module.curry_apply, linear_map.to_fun_eq_coe, linear_map.ltensor_tmul,
curry_apply, linear_map.coe_restrict_scalars_eq_coe], },
rw hf_comm.add_pow',
simp only [tensor_product.map_incl, submodule.subtype_apply, finset.sum_apply,
submodule.coe_mk, linear_map.coe_fn_sum, tensor_product.map_tmul, linear_map.smul_apply],
/- The required sum is zero because each individual term is zero. -/
apply finset.sum_eq_zero,
rintros ⟨i, j⟩ hij,
/- Eliminate the binomial coefficients from the picture. -/
suffices : (f₁^i * f₂^j) (m₁ ⊗ₜ m₂) = 0, { rw this, apply smul_zero, },
/- Finish off with appropriate case analysis. -/
cases nat.le_or_le_of_add_eq_add_pred (finset.nat.mem_antidiagonal.mp hij) with hi hj,
{ rw [(hf_comm.pow_pow i j).eq, linear_map.mul_apply, linear_map.pow_map_zero_of_le hi hf₁,
linear_map.map_zero], },
{ rw [linear_map.mul_apply, linear_map.pow_map_zero_of_le hj hf₂, linear_map.map_zero], },
end
variables {L M}
lemma lie_mem_pre_weight_space_of_mem_pre_weight_space {χ₁ χ₂ : L → R} {x : L} {m : M}
(hx : x ∈ pre_weight_space L χ₁) (hm : m ∈ pre_weight_space M χ₂) :
⁅x, m⁆ ∈ pre_weight_space M (χ₁ + χ₂) :=
begin
apply lie_module.weight_vector_multiplication L L M M (to_module_hom R L M) χ₁ χ₂,
simp only [lie_module_hom.coe_to_linear_map, function.comp_app, linear_map.coe_comp,
tensor_product.map_incl, linear_map.mem_range],
use [⟨x, hx⟩ ⊗ₜ ⟨m, hm⟩],
simp only [submodule.subtype_apply, to_module_hom_apply, tensor_product.map_tmul],
refl,
end
variables (M)
/-- If a Lie algebra is nilpotent, then pre-weight spaces are Lie submodules. -/
def weight_space [lie_algebra.is_nilpotent R L] (χ : L → R) : lie_submodule R L M :=
{ lie_mem := λ x m hm,
begin
rw ← zero_add χ,
refine lie_mem_pre_weight_space_of_mem_pre_weight_space _ hm,
suffices : pre_weight_space L (0 : L → R) = ⊤, { simp only [this, submodule.mem_top], },
exact lie_algebra.infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L,
end,
.. pre_weight_space M χ }
lemma mem_weight_space [lie_algebra.is_nilpotent R L] (χ : L → R) (m : M) :
m ∈ weight_space M χ ↔ m ∈ pre_weight_space M χ :=
iff.rfl
/-- See also the more useful form `lie_module.zero_weight_space_eq_top_of_nilpotent`. -/
@[simp] lemma zero_weight_space_eq_top_of_nilpotent'
[lie_algebra.is_nilpotent R L] [is_nilpotent R L M] :
weight_space M (0 : L → R) = ⊤ :=
begin
rw [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule],
exact infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L M,
end
lemma coe_weight_space_of_top [lie_algebra.is_nilpotent R L] (χ : L → R) :
(weight_space M (χ ∘ (⊤ : lie_subalgebra R L).incl) : submodule R M) = weight_space M χ :=
begin
ext m,
simp only [weight_space, lie_submodule.coe_to_submodule_mk, lie_subalgebra.coe_bracket_of_module,
function.comp_app, mem_pre_weight_space],
split; intros h x,
{ obtain ⟨k, hk⟩ := h ⟨x, set.mem_univ x⟩, use k, exact hk, },
{ obtain ⟨k, hk⟩ := h x, use k, exact hk, },
end
@[simp] lemma zero_weight_space_eq_top_of_nilpotent
[lie_algebra.is_nilpotent R L] [is_nilpotent R L M] :
weight_space M (0 : (⊤ : lie_subalgebra R L) → R) = ⊤ :=
begin
/- We use `coe_weight_space_of_top` as a trick to circumvent the fact that we don't (yet) know
`is_nilpotent R (⊤ : lie_subalgebra R L) M` is equivalent to `is_nilpotent R L M`. -/
have h₀ : (0 : L → R) ∘ (⊤ : lie_subalgebra R L).incl = 0, { ext, refl, },
rw [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule, ← h₀,
coe_weight_space_of_top, ← infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L M],
refl,
end
/-- Given a Lie module `M` of a Lie algebra `L`, a weight of `M` with respect to a nilpotent
subalgebra `H ⊆ L` is a Lie character whose corresponding weight space is non-empty. -/
def is_weight (χ : lie_character R H) : Prop := weight_space M χ ≠ ⊥
/-- For a non-trivial nilpotent Lie module over a nilpotent Lie algebra, the zero character is a
weight with respect to the `⊤` Lie subalgebra. -/
lemma is_weight_zero_of_nilpotent
[nontrivial M] [lie_algebra.is_nilpotent R L] [is_nilpotent R L M] :
is_weight (⊤ : lie_subalgebra R L) M 0 :=
by { rw [is_weight, lie_hom.coe_zero, zero_weight_space_eq_top_of_nilpotent], exact top_ne_bot, }
/-- A (nilpotent) Lie algebra acts nilpotently on the zero weight space of a Noetherian Lie
module. -/
lemma is_nilpotent_to_endomorphism_weight_space_zero
[lie_algebra.is_nilpotent R L] [is_noetherian R M] (x : L) :
_root_.is_nilpotent $ to_endomorphism R L (weight_space M (0 : L → R)) x :=
begin
obtain ⟨k, hk⟩ := exists_pre_weight_space_zero_le_ker_of_is_noetherian R M x,
use k,
ext ⟨m, hm⟩,
rw [linear_map.zero_apply, lie_submodule.coe_zero, submodule.coe_eq_zero,
← lie_submodule.to_endomorphism_restrict_eq_to_endomorphism, linear_map.pow_restrict,
← set_like.coe_eq_coe, linear_map.restrict_apply, submodule.coe_mk, submodule.coe_zero],
exact hk hm,
end
/-- By Engel's theorem, when the Lie algebra is Noetherian, the zero weight space of a Noetherian
Lie module is nilpotent. -/
instance [lie_algebra.is_nilpotent R L] [is_noetherian R L] [is_noetherian R M] :
is_nilpotent R L (weight_space M (0 : L → R)) :=
is_nilpotent_iff_forall.mpr $ is_nilpotent_to_endomorphism_weight_space_zero M
end lie_module
namespace lie_algebra
open_locale tensor_product
open tensor_product.lie_module
open lie_module
/-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of a map `χ : H → R` is the weight
space of `L` regarded as a module of `H` via the adjoint action. -/
abbreviation root_space (χ : H → R) : lie_submodule R H L := weight_space L χ
@[simp] lemma zero_root_space_eq_top_of_nilpotent [h : is_nilpotent R L] :
root_space (⊤ : lie_subalgebra R L) 0 = ⊤ :=
zero_weight_space_eq_top_of_nilpotent L
/-- A root of a Lie algebra `L` with respect to a nilpotent subalgebra `H ⊆ L` is a weight of `L`,
regarded as a module of `H` via the adjoint action. -/
abbreviation is_root := is_weight H L
@[simp] lemma root_space_comap_eq_weight_space (χ : H → R) :
(root_space H χ).comap H.incl' = weight_space H χ :=
begin
ext x,
let f : H → module.End R L := λ y, to_endomorphism R H L y - (χ y) • 1,
let g : H → module.End R H := λ y, to_endomorphism R H H y - (χ y) • 1,
suffices : (∀ (y : H), ∃ (k : ℕ), ((f y)^k).comp (H.incl : H →ₗ[R] L) x = 0) ↔
∀ (y : H), ∃ (k : ℕ), (H.incl : H →ₗ[R] L).comp ((g y)^k) x = 0,
{ simp only [lie_hom.coe_to_linear_map, lie_subalgebra.coe_incl, function.comp_app,
linear_map.coe_comp, submodule.coe_eq_zero] at this,
simp only [mem_weight_space, mem_pre_weight_space,
lie_subalgebra.coe_incl', lie_submodule.mem_comap, this], },
have hfg : ∀ (y : H), (f y).comp (H.incl : H →ₗ[R] L) = (H.incl : H →ₗ[R] L).comp (g y),
{ rintros ⟨y, hy⟩, ext ⟨z, hz⟩,
simp only [submodule.coe_sub, to_endomorphism_apply_apply, lie_hom.coe_to_linear_map,
linear_map.one_apply, lie_subalgebra.coe_incl, lie_subalgebra.coe_bracket_of_module,
lie_subalgebra.coe_bracket, linear_map.smul_apply, function.comp_app,
submodule.coe_smul_of_tower, linear_map.coe_comp, linear_map.sub_apply], },
simp_rw [linear_map.commute_pow_left_of_commute (hfg _)],
end
variables {H M}
lemma lie_mem_weight_space_of_mem_weight_space {χ₁ χ₂ : H → R} {x : L} {m : M}
(hx : x ∈ root_space H χ₁) (hm : m ∈ weight_space M χ₂) : ⁅x, m⁆ ∈ weight_space M (χ₁ + χ₂) :=
begin
apply lie_module.weight_vector_multiplication
H L M M ((to_module_hom R L M).restrict_lie H) χ₁ χ₂,
simp only [lie_module_hom.coe_to_linear_map, function.comp_app, linear_map.coe_comp,
tensor_product.map_incl, linear_map.mem_range],
use [⟨x, hx⟩ ⊗ₜ ⟨m, hm⟩],
simp only [submodule.subtype_apply, to_module_hom_apply, submodule.coe_mk,
lie_module_hom.coe_restrict_lie, tensor_product.map_tmul],
end
variables (R L H M)
/--
Auxiliary definition for `root_space_weight_space_product`,
which is close to the deterministic timeout limit.
-/
def root_space_weight_space_product_aux {χ₁ χ₂ χ₃ : H → R} (hχ : χ₁ + χ₂ = χ₃) :
(root_space H χ₁) →ₗ[R] (weight_space M χ₂) →ₗ[R] (weight_space M χ₃) :=
{ to_fun := λ x,
{ to_fun :=
λ m, ⟨⁅(x : L), (m : M)⁆,
hχ ▸ (lie_mem_weight_space_of_mem_weight_space x.property m.property) ⟩,
map_add' := λ m n, by { simp only [lie_submodule.coe_add, lie_add], refl, },
map_smul' := λ t m, by { conv_lhs { congr, rw [lie_submodule.coe_smul, lie_smul], }, refl, }, },
map_add' := λ x y, by ext m; rw [linear_map.add_apply, linear_map.coe_mk, linear_map.coe_mk,
linear_map.coe_mk, subtype.coe_mk, lie_submodule.coe_add, lie_submodule.coe_add, add_lie,
subtype.coe_mk, subtype.coe_mk],
map_smul' := λ t x,
begin
simp only [ring_hom.id_apply],
ext m,
rw [linear_map.smul_apply, linear_map.coe_mk, linear_map.coe_mk,
subtype.coe_mk, lie_submodule.coe_smul, smul_lie, lie_submodule.coe_smul, subtype.coe_mk],
end, }
/-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural
`R`-bilinear product of root vectors and weight vectors, compatible with the actions of `H`. -/
def root_space_weight_space_product (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) :
(root_space H χ₁) ⊗[R] (weight_space M χ₂) →ₗ⁅R,H⁆ weight_space M χ₃ :=
lift_lie R H (root_space H χ₁) (weight_space M χ₂) (weight_space M χ₃)
{ to_linear_map := root_space_weight_space_product_aux R L H M hχ,
map_lie' := λ x y, by ext m; rw [root_space_weight_space_product_aux,
lie_hom.lie_apply, lie_submodule.coe_sub, linear_map.coe_mk,
linear_map.coe_mk, subtype.coe_mk, subtype.coe_mk, lie_submodule.coe_bracket,
lie_submodule.coe_bracket, subtype.coe_mk, lie_subalgebra.coe_bracket_of_module,
lie_subalgebra.coe_bracket_of_module, lie_submodule.coe_bracket,
lie_subalgebra.coe_bracket_of_module, lie_lie], }
@[simp] lemma coe_root_space_weight_space_product_tmul
(χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : root_space H χ₁) (m : weight_space M χ₂) :
(root_space_weight_space_product R L H M χ₁ χ₂ χ₃ hχ (x ⊗ₜ m) : M) = ⁅(x : L), (m : M)⁆ :=
by simp only [root_space_weight_space_product, root_space_weight_space_product_aux,
lift_apply, lie_module_hom.coe_to_linear_map,
coe_lift_lie_eq_lift_coe, submodule.coe_mk, linear_map.coe_mk, lie_module_hom.coe_mk]
/-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural
`R`-bilinear product of root vectors, compatible with the actions of `H`. -/
def root_space_product (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) :
(root_space H χ₁) ⊗[R] (root_space H χ₂) →ₗ⁅R,H⁆ root_space H χ₃ :=
root_space_weight_space_product R L H L χ₁ χ₂ χ₃ hχ
@[simp] lemma root_space_product_def :
root_space_product R L H = root_space_weight_space_product R L H L :=
rfl
lemma root_space_product_tmul
(χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : root_space H χ₁) (y : root_space H χ₂) :
(root_space_product R L H χ₁ χ₂ χ₃ hχ (x ⊗ₜ y) : L) = ⁅(x : L), (y : L)⁆ :=
by simp only [root_space_product_def, coe_root_space_weight_space_product_tmul]
/-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of the zero map `0 : H → R` is a Lie
subalgebra of `L`. -/
def zero_root_subalgebra : lie_subalgebra R L :=
{ lie_mem' := λ x y hx hy, by
{ let xy : (root_space H 0) ⊗[R] (root_space H 0) := ⟨x, hx⟩ ⊗ₜ ⟨y, hy⟩,
suffices : (root_space_product R L H 0 0 0 (add_zero 0) xy : L) ∈ root_space H 0,
{ rwa [root_space_product_tmul, subtype.coe_mk, subtype.coe_mk] at this, },
exact (root_space_product R L H 0 0 0 (add_zero 0) xy).property, },
.. (root_space H 0 : submodule R L) }
@[simp] lemma coe_zero_root_subalgebra :
(zero_root_subalgebra R L H : submodule R L) = root_space H 0 :=
rfl
lemma mem_zero_root_subalgebra (x : L) :
x ∈ zero_root_subalgebra R L H ↔ ∀ (y : H), ∃ (k : ℕ), ((to_endomorphism R H L y)^k) x = 0 :=
by simp only [zero_root_subalgebra, mem_weight_space, mem_pre_weight_space, pi.zero_apply, sub_zero,
set_like.mem_coe, zero_smul, lie_submodule.mem_coe_submodule, submodule.mem_carrier,
lie_subalgebra.mem_mk_iff]
lemma to_lie_submodule_le_root_space_zero : H.to_lie_submodule ≤ root_space H 0 :=
begin
intros x hx,
simp only [lie_subalgebra.mem_to_lie_submodule] at hx,
simp only [mem_weight_space, mem_pre_weight_space, pi.zero_apply, sub_zero, zero_smul],
intros y,
unfreezingI { obtain ⟨k, hk⟩ := (infer_instance : is_nilpotent R H) },
use k,
let f : module.End R H := to_endomorphism R H H y,
let g : module.End R L := to_endomorphism R H L y,
have hfg : g.comp (H : submodule R L).subtype = (H : submodule R L).subtype.comp f,
{ ext z, simp only [to_endomorphism_apply_apply, submodule.subtype_apply,
lie_subalgebra.coe_bracket_of_module, lie_subalgebra.coe_bracket, function.comp_app,
linear_map.coe_comp], },
change (g^k).comp (H : submodule R L).subtype ⟨x, hx⟩ = 0,
rw linear_map.commute_pow_left_of_commute hfg k,
have h := iterate_to_endomorphism_mem_lower_central_series R H H y ⟨x, hx⟩ k,
rw [hk, lie_submodule.mem_bot] at h,
simp only [submodule.subtype_apply, function.comp_app, linear_map.pow_apply, linear_map.coe_comp,
submodule.coe_eq_zero],
exact h,
end
lemma le_zero_root_subalgebra : H ≤ zero_root_subalgebra R L H :=
begin
rw [← lie_subalgebra.coe_submodule_le_coe_submodule, ← H.coe_to_lie_submodule,
coe_zero_root_subalgebra, lie_submodule.coe_submodule_le_coe_submodule],
exact to_lie_submodule_le_root_space_zero R L H,
end
@[simp] lemma zero_root_subalgebra_normalizer_eq_self :
(zero_root_subalgebra R L H).normalizer = zero_root_subalgebra R L H :=
begin
refine le_antisymm _ (lie_subalgebra.le_normalizer _),
intros x hx,
rw lie_subalgebra.mem_normalizer_iff at hx,
rw mem_zero_root_subalgebra,
rintros ⟨y, hy⟩,
specialize hx y (le_zero_root_subalgebra R L H hy),
rw mem_zero_root_subalgebra at hx,
obtain ⟨k, hk⟩ := hx ⟨y, hy⟩,
rw [← lie_skew, linear_map.map_neg, neg_eq_zero] at hk,
use k + 1,
rw [linear_map.iterate_succ, linear_map.coe_comp, function.comp_app, to_endomorphism_apply_apply,
lie_subalgebra.coe_bracket_of_module, submodule.coe_mk, hk],
end
/-- If the zero root subalgebra of a nilpotent Lie subalgebra `H` is just `H` then `H` is a Cartan
subalgebra.
When `L` is Noetherian, it follows from Engel's theorem that the converse holds. See
`lie_algebra.zero_root_subalgebra_eq_iff_is_cartan` -/
lemma is_cartan_of_zero_root_subalgebra_eq (h : zero_root_subalgebra R L H = H) :
H.is_cartan_subalgebra :=
{ nilpotent := infer_instance,
self_normalizing := by { rw ← h, exact zero_root_subalgebra_normalizer_eq_self R L H, } }
@[simp] lemma zero_root_subalgebra_eq_of_is_cartan (H : lie_subalgebra R L)
[H.is_cartan_subalgebra] [is_noetherian R L] :
zero_root_subalgebra R L H = H :=
begin
refine le_antisymm _ (le_zero_root_subalgebra R L H),
suffices : root_space H 0 ≤ H.to_lie_submodule, { exact λ x hx, this hx, },
obtain ⟨k, hk⟩ := (root_space H 0).is_nilpotent_iff_exists_self_le_ucs.mp (by apply_instance),
exact hk.trans (lie_submodule.ucs_le_of_normalizer_eq_self (by simp) k),
end
lemma zero_root_subalgebra_eq_iff_is_cartan [is_noetherian R L] :
zero_root_subalgebra R L H = H ↔ H.is_cartan_subalgebra :=
⟨is_cartan_of_zero_root_subalgebra_eq R L H, by { introsI, simp, }⟩
end lie_algebra
namespace lie_module
open lie_algebra
variables {R L H}
/-- A priori, weight spaces are Lie submodules over the Lie subalgebra `H` used to define them.
However they are naturally Lie submodules over the (in general larger) Lie subalgebra
`zero_root_subalgebra R L H`. Even though it is often the case that
`zero_root_subalgebra R L H = H`, it is likely to be useful to have the flexibility not to have
to invoke this equality (as well as to work more generally). -/
def weight_space' (χ : H → R) : lie_submodule R (zero_root_subalgebra R L H) M :=
{ lie_mem := λ x m hm, by
{ have hx : (x : L) ∈ root_space H 0,
{ rw [← lie_submodule.mem_coe_submodule, ← coe_zero_root_subalgebra], exact x.property, },
rw ← zero_add χ,
exact lie_mem_weight_space_of_mem_weight_space hx hm, },
.. (weight_space M χ : submodule R M) }
@[simp] lemma coe_weight_space' (χ : H → R) :
(weight_space' M χ : submodule R M) = weight_space M χ :=
rfl
end lie_module
|
20deeb3d969044ce938628947d7fbdbc35ff676b | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/ring_theory/rees_algebra.lean | 24b596d3bd89dbe90ea9601c559cab14781b9ff7 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 4,144 | lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import ring_theory.finiteness
import ring_theory.ideal.local_ring
import ring_theory.nakayama
/-!
# Rees algebra
The Rees algebra of an ideal `I` is the subalgebra `R[It]` of `R[t]` defined as `R[It] = ⨁ₙ Iⁿ tⁿ`.
This is used to prove the Artin-Rees lemma, and will potentially enable us to calculate some
blowup in the future.
## Main definition
- `rees_algebra` : The Rees algebra of an ideal `I`, defined as a subalgebra of `R[X]`.
- `adjoin_monomial_eq_rees_algebra` : The Rees algebra is generated by the degree one elements.
- `rees_algebra.fg` : The Rees algebra of a f.g. ideal is of finite type. In particular, this
implies that the rees algebra over a noetherian ring is still noetherian.
-/
universes u v
variables {R M : Type u} [comm_ring R] [add_comm_group M] [module R M] (I : ideal R)
open polynomial
open_locale polynomial big_operators
/-- The Rees algebra of an ideal `I`, defined as the subalgebra of `R[X]` whose `i`-th coefficient
falls in `I ^ i`. -/
def rees_algebra : subalgebra R R[X] :=
{ carrier := { f | ∀ i, f.coeff i ∈ I ^ i },
mul_mem' := λ f g hf hg i, begin
rw coeff_mul,
apply ideal.sum_mem,
rintros ⟨j, k⟩ e,
rw [← finset.nat.mem_antidiagonal.mp e, pow_add],
exact ideal.mul_mem_mul (hf j) (hg k)
end,
one_mem' := λ i, begin
rw coeff_one,
split_ifs,
{ subst h, simp },
{ simp }
end,
add_mem' := λ f g hf hg i, begin
rw coeff_add,
exact ideal.add_mem _ (hf i) (hg i)
end,
zero_mem' := λ i, ideal.zero_mem _,
algebra_map_mem' := λ r i, begin
rw [algebra_map_apply, coeff_C],
split_ifs,
{ subst h, simp },
{ simp }
end }
lemma mem_rees_algebra_iff (f : R[X]) :
f ∈ rees_algebra I ↔ ∀ i, f.coeff i ∈ I ^ i := iff.rfl
lemma mem_rees_algebra_iff_support (f : R[X]) :
f ∈ rees_algebra I ↔ ∀ i ∈ f.support, f.coeff i ∈ I ^ i :=
begin
apply forall_congr,
intro a,
rw [mem_support_iff, iff.comm, imp_iff_right_iff, ne.def, ← imp_iff_not_or],
exact λ e, e.symm ▸ (I ^ a).zero_mem
end
lemma rees_algebra.monomial_mem {I : ideal R} {i : ℕ} {r : R} :
monomial i r ∈ rees_algebra I ↔ r ∈ I ^ i :=
by simp [mem_rees_algebra_iff_support, coeff_monomial, ← imp_iff_not_or] { contextual := tt }
lemma monomial_mem_adjoin_monomial {I : ideal R} {n : ℕ} {r : R} (hr : r ∈ I ^ n) :
monomial n r ∈ algebra.adjoin R (submodule.map (monomial 1 : R →ₗ[R] R[X]) I : set R[X]) :=
begin
induction n with n hn generalizing r,
{ exact subalgebra.algebra_map_mem _ _ },
{ rw pow_succ at hr,
apply submodule.smul_induction_on hr,
{ intros r hr s hs,
rw [nat.succ_eq_one_add, smul_eq_mul, ← monomial_mul_monomial],
exact subalgebra.mul_mem _ (algebra.subset_adjoin (set.mem_image_of_mem _ hr)) (hn hs) },
{ intros x y hx hy, rw monomial_add, exact subalgebra.add_mem _ hx hy } }
end
lemma adjoin_monomial_eq_rees_algebra :
algebra.adjoin R (submodule.map (monomial 1 : R →ₗ[R] R[X]) I : set R[X]) = rees_algebra I :=
begin
apply le_antisymm,
{ apply algebra.adjoin_le _,
rintro _ ⟨r, hr, rfl⟩,
exact rees_algebra.monomial_mem.mpr (by rwa pow_one) },
{ intros p hp,
rw p.as_sum_support,
apply subalgebra.sum_mem _ _,
rintros i -,
exact monomial_mem_adjoin_monomial (hp i) }
end
variables {I}
lemma rees_algebra.fg (hI : I.fg) : (rees_algebra I).fg :=
begin
classical,
obtain ⟨s, hs⟩ := hI,
rw [← adjoin_monomial_eq_rees_algebra, ← hs],
use s.image (monomial 1),
rw finset.coe_image,
change _ = algebra.adjoin R (submodule.map (monomial 1 : R →ₗ[R] R[X])
(submodule.span R ↑s) : set R[X]),
rw [submodule.map_span, algebra.adjoin_span]
end
instance [is_noetherian_ring R] : algebra.finite_type R (rees_algebra I) :=
⟨(rees_algebra I).fg_top.mpr (rees_algebra.fg $ is_noetherian.noetherian I)⟩
instance [is_noetherian_ring R] : is_noetherian_ring (rees_algebra I) :=
algebra.finite_type.is_noetherian_ring R _
|
ac41182ced9cd055d2ae9e36b85e6df6092dde71 | 934eae675a9d997202bb021816325184e7d694aa | /_notes/Languages/lean/myproject/Myproject.lean | b2147ef4c5d21c9b421282f362834b13f3e815a4 | [] | no_license | philzook58/philzook58.github.io | da78841df4ffd9a19c81e0eab833983d95a64b70 | 76000a5847bd6ee41dff25937ae916835bbcf03f | refs/heads/master | 1,692,951,958,916 | 1,692,631,945,000 | 1,692,631,945,000 | 91,513,884 | 9 | 4 | null | 1,677,330,791,000 | 1,494,977,989,000 | Jupyter Notebook | UTF-8 | Lean | false | false | 1,048 | lean | import Std.Data.List.Basic
import Mathlib.Tactic.LibrarySearch
import Mathlib.Tactic.Linarith
import Aesop
-- aesop is an auto tactic
example : α → α :=
by aesop
theorem foo : 1 = 1 := by
-- library_search
exact _root_.trans rfl rfl
#check _root_.trans
theorem bar : x <= 7 + 3*x := by
linarith
#print bar
def hello := "world"
theorem and_commutative (p q : Prop) : p ∧ q → q ∧ p :=
fun hpq : p ∧ q =>
have hp : p := And.left hpq
have hq : q := And.right hpq
show q ∧ p from And.intro hq hp
theorem plus_comm : forall a b, a + b + 0 = b + a := by
intros a b
have c : a + b = b + a := by exact IsSymmOp.symm_op a b
rw [c]
have d : forall x, x + 0 = x := by intros; exact namedPattern rfl rfl rfl
rw [d]
-- ok, so unification variables can be made by apply, or explicit ?x maybe?
theorem existstry : exists x, x = 11 := by
apply Exists.intro
rfl
example : exists x, x = 11 := by
exists ?x
exact 11
rfl
-- simp?
/-
repeat (apply r1 | apply r2 | apply r3 <;> simp)
-/
#check existstry
|
585c626b026ee270cdd97921c9a9a3d0fc4217ec | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/linear_recurrence.lean | a86510078f2acb3dd9ccf0c9e288ce35c555f893 | [] | 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,252 | lean | /-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.polynomial.ring_division
import Mathlib.linear_algebra.dimension
import Mathlib.algebra.polynomial.big_operators
import Mathlib.PostPort
universes u_1 l
namespace Mathlib
/-!
# Linear recurrence
Informally, a "linear recurrence" is an assertion of the form
`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,
where `u` is a sequence, `d` is the *order* of the recurrence and the `a i`
are its *coefficients*.
In this file, we define the structure `linear_recurrence` so that
`linear_recurrence.mk d a` represents the above relation, and we call
a sequence `u` which verifies it a *solution* of the linear recurrence.
We prove a few basic lemmas about this concept, such as :
* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`
is a field)
* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`
between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two
solutions are equal if and only if their first `d` terms are equals.
* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,
which we call the *characteristic polynomial* of the recurrence
Of course, although we can inductively generate solutions (cf `mk_sol`), the
interesting part would be to determinate closed-forms for the solutions.
This is currently *not implemented*, as we are waiting for definition and
properties of eigenvalues and eigenvectors.
-/
/-- A "linear recurrence relation" over a commutative semiring is given by its
order `n` and `n` coefficients. -/
structure linear_recurrence (α : Type u_1) [comm_semiring α]
where
order : ℕ
coeffs : fin order → α
protected instance linear_recurrence.inhabited (α : Type u_1) [comm_semiring α] : Inhabited (linear_recurrence α) :=
{ default := linear_recurrence.mk 0 Inhabited.default }
namespace linear_recurrence
/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have
`u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/
def is_solution {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) (u : ℕ → α) :=
∀ (n : ℕ), u (n + order E) = finset.sum finset.univ fun (i : fin (order E)) => coeffs E i * u (n + ↑i)
/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.
We will prove this is the only such solution. -/
def mk_sol {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) (init : fin (order E) → α) : ℕ → α :=
sorry
/-- `E.mk_sol` indeed gives solutions to `E`. -/
theorem is_sol_mk_sol {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) (init : fin (order E) → α) : is_solution E (mk_sol α _inst_1 E init) := sorry
/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/
theorem mk_sol_eq_init {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) (init : fin (order E) → α) (n : fin (order E)) : mk_sol α _inst_1 E init ↑n = init n := sorry
/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,
then `∀ n, u n = E.mk_sol init n`. -/
theorem eq_mk_of_is_sol_of_eq_init {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) {u : ℕ → α} {init : fin (order E) → α} (h : is_solution E u) (heq : ∀ (n : fin (order E)), u ↑n = init n) (n : ℕ) : u n = mk_sol α _inst_1 E init n := sorry
/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,
then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution
of `E` whose first `E.order` values are given by `init`. -/
theorem eq_mk_of_is_sol_of_eq_init' {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) {u : ℕ → α} {init : fin (order E) → α} (h : is_solution E u) (heq : ∀ (n : fin (order E)), u ↑n = init n) : u = mk_sol α _inst_1 E init :=
funext (eq_mk_of_is_sol_of_eq_init α _inst_1 E (fun (x : ℕ) => u x) init h heq)
/-- The space of solutions of `E`, as a `submodule` over `α` of the semimodule `ℕ → α`. -/
def sol_space {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) : submodule α (ℕ → α) :=
submodule.mk (set_of fun (u : ℕ → α) => is_solution E u) sorry sorry sorry
/-- Defining property of the solution space : `u` is a solution
iff it belongs to the solution space. -/
theorem is_sol_iff_mem_sol_space {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) (u : ℕ → α) : is_solution E u ↔ u ∈ sol_space E :=
iff.rfl
/-- The function that maps a solution `u` of `E` to its first
`E.order` terms as a `linear_equiv`. -/
def to_init {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) : linear_equiv α (↥(sol_space E)) (fin (order E) → α) :=
linear_equiv.mk (fun (u : ↥(sol_space E)) (x : fin (order E)) => coe u ↑x) sorry sorry
(fun (u : fin (order E) → α) => { val := mk_sol α _inst_1 E u, property := is_sol_mk_sol α _inst_1 E u }) sorry sorry
/-- Two solutions are equal iff they are equal on `range E.order`. -/
theorem sol_eq_of_eq_init {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) (u : ℕ → α) (v : ℕ → α) (hu : is_solution E u) (hv : is_solution E v) : u = v ↔ set.eq_on u v ↑(finset.range (order E)) := sorry
/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,
where `n := E.order`. This operation is quite useful for determining closed-form
solutions of `E`. -/
/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,
where `n := E.order`. -/
def tuple_succ {α : Type u_1} [comm_semiring α] (E : linear_recurrence α) : linear_map α (fin (order E) → α) (fin (order E) → α) :=
linear_map.mk
(fun (X : fin (order E) → α) (i : fin (order E)) =>
dite (↑i + 1 < order E) (fun (h : ↑i + 1 < order E) => X { val := ↑i + 1, property := h })
fun (h : ¬↑i + 1 < order E) => finset.sum finset.univ fun (i : fin (order E)) => coeffs E i * X i)
sorry sorry
/-- The dimension of `E.sol_space` is `E.order`. -/
theorem sol_space_dim {α : Type u_1} [field α] (E : linear_recurrence α) : vector_space.dim α ↥(sol_space E) = ↑(order E) :=
dim_fin_fun (order E) ▸ linear_equiv.dim_eq (to_init α comm_ring.to_comm_semiring E)
/-- The characteristic polynomial of `E` is
`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/
def char_poly {α : Type u_1} [comm_ring α] (E : linear_recurrence α) : polynomial α :=
coe_fn (polynomial.monomial (order E)) 1 -
finset.sum finset.univ fun (i : fin (order E)) => coe_fn (polynomial.monomial ↑i) (coeffs E i)
/-- The geometric sequence `q^n` is a solution of `E` iff
`q` is a root of `E`'s characteristic polynomial. -/
theorem geom_sol_iff_root_char_poly {α : Type u_1} [comm_ring α] (E : linear_recurrence α) (q : α) : (is_solution E fun (n : ℕ) => q ^ n) ↔ polynomial.is_root (char_poly E) q := sorry
|
39ec078c827a9c94f899cb94329ef05f58c2ce46 | bb31430994044506fa42fd667e2d556327e18dfe | /src/topology/algebra/module/basic.lean | 014bc026c3e3b9647f410ae74bdd0534bf637415 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 92,948 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import topology.algebra.ring
import topology.algebra.mul_action
import topology.algebra.uniform_group
import topology.continuous_function.basic
import topology.uniform_space.uniform_embedding
import algebra.algebra.basic
import linear_algebra.projection
import linear_algebra.pi
import ring_theory.simple_module
/-!
# Theory of topological modules and continuous linear maps.
We use the class `has_continuous_smul` for topological (semi) modules and topological vector spaces.
In this file we define continuous (semi-)linear maps, as semilinear maps between topological
modules which are continuous. The set of continuous semilinear maps between the topological
`R₁`-module `M` and `R₂`-module `M₂` with respect to the `ring_hom` `σ` is denoted by `M →SL[σ] M₂`.
Plain linear maps are denoted by `M →L[R] M₂` and star-linear maps by `M →L⋆[R] M₂`.
The corresponding notation for equivalences is `M ≃SL[σ] M₂`, `M ≃L[R] M₂` and `M ≃L⋆[R] M₂`.
-/
open filter linear_map (ker range)
open_locale topological_space big_operators filter
universes u v w u'
section
variables {R : Type*} {M : Type*}
[ring R] [topological_space R]
[topological_space M] [add_comm_group M]
[module R M]
lemma has_continuous_smul.of_nhds_zero [topological_ring R] [topological_add_group M]
(hmul : tendsto (λ p : R × M, p.1 • p.2) (𝓝 0 ×ᶠ (𝓝 0)) (𝓝 0))
(hmulleft : ∀ m : M, tendsto (λ a : R, a • m) (𝓝 0) (𝓝 0))
(hmulright : ∀ a : R, tendsto (λ m : M, a • m) (𝓝 0) (𝓝 0)) : has_continuous_smul R M :=
⟨begin
rw continuous_iff_continuous_at,
rintros ⟨a₀, m₀⟩,
have key : ∀ p : R × M,
p.1 • p.2 = a₀ • m₀ + ((p.1 - a₀) • m₀ + a₀ • (p.2 - m₀) + (p.1 - a₀) • (p.2 - m₀)),
{ rintro ⟨a, m⟩,
simp [sub_smul, smul_sub],
abel },
rw funext key, clear key,
refine tendsto_const_nhds.add (tendsto.add (tendsto.add _ _) _),
{ rw [sub_self, zero_smul],
apply (hmulleft m₀).comp,
rw [show (λ p : R × M, p.1 - a₀) = (λ a, a - a₀) ∘ prod.fst, by {ext, refl }, nhds_prod_eq],
have : tendsto (λ a, a - a₀) (𝓝 a₀) (𝓝 0),
{ rw ← sub_self a₀,
exact tendsto_id.sub tendsto_const_nhds },
exact this.comp tendsto_fst },
{ rw [sub_self, smul_zero],
apply (hmulright a₀).comp,
rw [show (λ p : R × M, p.2 - m₀) = (λ m, m - m₀) ∘ prod.snd, by {ext, refl }, nhds_prod_eq],
have : tendsto (λ m, m - m₀) (𝓝 m₀) (𝓝 0),
{ rw ← sub_self m₀,
exact tendsto_id.sub tendsto_const_nhds },
exact this.comp tendsto_snd },
{ rw [sub_self, zero_smul, nhds_prod_eq,
show (λ p : R × M, (p.fst - a₀) • (p.snd - m₀)) =
(λ p : R × M, p.1 • p.2) ∘ (prod.map (λ a, a - a₀) (λ m, m - m₀)), by { ext, refl }],
apply hmul.comp (tendsto.prod_map _ _);
{ rw ← sub_self ,
exact tendsto_id.sub tendsto_const_nhds } },
end⟩
end
section
variables {R : Type*} {M : Type*}
[ring R] [topological_space R]
[topological_space M] [add_comm_group M] [has_continuous_add M]
[module R M] [has_continuous_smul R M]
/-- If `M` is a topological module over `R` and `0` is a limit of invertible elements of `R`, then
`⊤` is the only submodule of `M` with a nonempty interior.
This is the case, e.g., if `R` is a nontrivially normed field. -/
lemma submodule.eq_top_of_nonempty_interior'
[ne_bot (𝓝[{x : R | is_unit x}] 0)]
(s : submodule R M) (hs : (interior (s:set M)).nonempty) :
s = ⊤ :=
begin
rcases hs with ⟨y, hy⟩,
refine (submodule.eq_top_iff'.2 $ λ x, _),
rw [mem_interior_iff_mem_nhds] at hy,
have : tendsto (λ c:R, y + c • x) (𝓝[{x : R | is_unit x}] 0) (𝓝 (y + (0:R) • x)),
from tendsto_const_nhds.add ((tendsto_nhds_within_of_tendsto_nhds tendsto_id).smul
tendsto_const_nhds),
rw [zero_smul, add_zero] at this,
obtain ⟨_, hu : y + _ • _ ∈ s, u, rfl⟩ :=
nonempty_of_mem (inter_mem (mem_map.1 (this hy)) self_mem_nhds_within),
have hy' : y ∈ ↑s := mem_of_mem_nhds hy,
rwa [s.add_mem_iff_right hy', ←units.smul_def, s.smul_mem_iff' u] at hu,
end
variables (R M)
/-- Let `R` be a topological ring such that zero is not an isolated point (e.g., a nontrivially
normed field, see `normed_field.punctured_nhds_ne_bot`). Let `M` be a nontrivial module over `R`
such that `c • x = 0` implies `c = 0 ∨ x = 0`. Then `M` has no isolated points. We formulate this
using `ne_bot (𝓝[≠] x)`.
This lemma is not an instance because Lean would need to find `[has_continuous_smul ?m_1 M]` with
unknown `?m_1`. We register this as an instance for `R = ℝ` in `real.punctured_nhds_module_ne_bot`.
One can also use `haveI := module.punctured_nhds_ne_bot R M` in a proof.
-/
lemma module.punctured_nhds_ne_bot [nontrivial M] [ne_bot (𝓝[≠] (0 : R))]
[no_zero_smul_divisors R M] (x : M) :
ne_bot (𝓝[≠] x) :=
begin
rcases exists_ne (0 : M) with ⟨y, hy⟩,
suffices : tendsto (λ c : R, x + c • y) (𝓝[≠] 0) (𝓝[≠] x), from this.ne_bot,
refine tendsto.inf _ (tendsto_principal_principal.2 $ _),
{ convert tendsto_const_nhds.add ((@tendsto_id R _).smul_const y),
rw [zero_smul, add_zero] },
{ intros c hc,
simpa [hy] using hc }
end
end
section lattice_ops
variables {ι R M₁ M₂ : Type*} [semiring R] [add_comm_monoid M₁] [add_comm_monoid M₂]
[module R M₁] [module R M₂] [u : topological_space R] {t : topological_space M₂}
[has_continuous_smul R M₂] (f : M₁ →ₗ[R] M₂)
lemma has_continuous_smul_induced :
@has_continuous_smul R M₁ _ u (t.induced f) :=
{ continuous_smul :=
begin
letI : topological_space M₁ := t.induced f,
refine continuous_induced_rng.2 _,
simp_rw [function.comp, f.map_smul],
refine continuous_fst.smul (continuous_induced_dom.comp continuous_snd)
end }
end lattice_ops
namespace submodule
variables {α β : Type*} [topological_space β]
instance [topological_space α] [semiring α] [add_comm_monoid β] [module α β]
[has_continuous_smul α β] (S : submodule α β) :
has_continuous_smul α S :=
{ continuous_smul :=
begin
rw embedding_subtype_coe.to_inducing.continuous_iff,
exact continuous_fst.smul
(continuous_subtype_coe.comp continuous_snd)
end }
instance [ring α] [add_comm_group β] [module α β] [topological_add_group β] (S : submodule α β) :
topological_add_group S :=
S.to_add_subgroup.topological_add_group
end submodule
section closure
variables {R R' : Type u} {M M' : Type v}
[semiring R] [topological_space R]
[ring R'] [topological_space R']
[topological_space M] [add_comm_monoid M]
[topological_space M'] [add_comm_group M']
[module R M] [has_continuous_smul R M]
[module R' M'] [has_continuous_smul R' M']
lemma submodule.closure_smul_self_subset (s : submodule R M) :
(λ p : R × M, p.1 • p.2) '' (set.univ ×ˢ closure s) ⊆ closure s :=
calc
(λ p : R × M, p.1 • p.2) '' (set.univ ×ˢ closure s)
= (λ p : R × M, p.1 • p.2) '' closure (set.univ ×ˢ s) :
by simp [closure_prod_eq]
... ⊆ closure ((λ p : R × M, p.1 • p.2) '' (set.univ ×ˢ s)) :
image_closure_subset_closure_image continuous_smul
... = closure s : begin
congr,
ext x,
refine ⟨_, λ hx, ⟨⟨1, x⟩, ⟨set.mem_univ _, hx⟩, one_smul R _⟩⟩,
rintros ⟨⟨c, y⟩, ⟨hc, hy⟩, rfl⟩,
simp [s.smul_mem c hy]
end
lemma submodule.closure_smul_self_eq (s : submodule R M) :
(λ p : R × M, p.1 • p.2) '' (set.univ ×ˢ closure s) = closure s :=
s.closure_smul_self_subset.antisymm $ λ x hx, ⟨⟨1, x⟩, ⟨set.mem_univ _, hx⟩, one_smul R _⟩
variables [has_continuous_add M]
/-- The (topological-space) closure of a submodule of a topological `R`-module `M` is itself
a submodule. -/
def submodule.topological_closure (s : submodule R M) : submodule R M :=
{ carrier := closure (s : set M),
smul_mem' := λ c x hx, s.closure_smul_self_subset ⟨⟨c, x⟩, ⟨set.mem_univ _, hx⟩, rfl⟩,
..s.to_add_submonoid.topological_closure }
@[simp] lemma submodule.topological_closure_coe (s : submodule R M) :
(s.topological_closure : set M) = closure (s : set M) :=
rfl
lemma submodule.le_topological_closure (s : submodule R M) :
s ≤ s.topological_closure :=
subset_closure
lemma submodule.is_closed_topological_closure (s : submodule R M) :
is_closed (s.topological_closure : set M) :=
by convert is_closed_closure
lemma submodule.topological_closure_minimal
(s : submodule R M) {t : submodule R M} (h : s ≤ t) (ht : is_closed (t : set M)) :
s.topological_closure ≤ t :=
closure_minimal h ht
lemma submodule.topological_closure_mono {s : submodule R M} {t : submodule R M} (h : s ≤ t) :
s.topological_closure ≤ t.topological_closure :=
s.topological_closure_minimal (h.trans t.le_topological_closure)
t.is_closed_topological_closure
/-- The topological closure of a closed submodule `s` is equal to `s`. -/
lemma is_closed.submodule_topological_closure_eq {s : submodule R M} (hs : is_closed (s : set M)) :
s.topological_closure = s :=
le_antisymm (s.topological_closure_minimal rfl.le hs) s.le_topological_closure
/-- A subspace is dense iff its topological closure is the entire space. -/
lemma submodule.dense_iff_topological_closure_eq_top {s : submodule R M} :
dense (s : set M) ↔ s.topological_closure = ⊤ :=
by { rw [←set_like.coe_set_eq, dense_iff_closure_eq], simp }
instance {M' : Type*} [add_comm_monoid M'] [module R M'] [uniform_space M']
[has_continuous_add M'] [has_continuous_smul R M'] [complete_space M'] (U : submodule R M') :
complete_space U.topological_closure :=
is_closed_closure.complete_space_coe
/-- A maximal proper subspace of a topological module (i.e a `submodule` satisfying `is_coatom`)
is either closed or dense. -/
lemma submodule.is_closed_or_dense_of_is_coatom (s : submodule R M) (hs : is_coatom s) :
is_closed (s : set M) ∨ dense (s : set M) :=
(hs.le_iff.mp s.le_topological_closure).swap.imp (is_closed_of_closure_subset ∘ eq.le)
submodule.dense_iff_topological_closure_eq_top.mpr
lemma linear_map.is_closed_or_dense_ker [has_continuous_add M'] [is_simple_module R' R']
(l : M' →ₗ[R'] R') :
is_closed (l.ker : set M') ∨ dense (l.ker : set M') :=
begin
rcases l.surjective_or_eq_zero with (hl|rfl),
{ refine l.ker.is_closed_or_dense_of_is_coatom (linear_map.is_coatom_ker_of_surjective hl) },
{ rw linear_map.ker_zero,
left,
exact is_closed_univ },
end
end closure
/-- Continuous linear maps between modules. We only put the type classes that are necessary for the
definition, although in applications `M` and `M₂` will be topological modules over the topological
ring `R`. -/
structure continuous_linear_map
{R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
(M : Type*) [topological_space M] [add_comm_monoid M]
(M₂ : Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module S M₂]
extends M →ₛₗ[σ] M₂ :=
(cont : continuous to_fun . tactic.interactive.continuity')
notation M ` →SL[`:25 σ `] ` M₂ := continuous_linear_map σ M M₂
notation M ` →L[`:25 R `] ` M₂ := continuous_linear_map (ring_hom.id R) M M₂
notation M ` →L⋆[`:25 R `] ` M₂ := continuous_linear_map (star_ring_end R) M M₂
set_option old_structure_cmd true
/-- `continuous_semilinear_map_class F σ M M₂` asserts `F` is a type of bundled continuous
`σ`-semilinear maps `M → M₂`. See also `continuous_linear_map_class F R M M₂` for the case where
`σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring
homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y`
and `f (c • x) = (σ c) • f x`. -/
class continuous_semilinear_map_class (F : Type*) {R S : out_param Type*} [semiring R] [semiring S]
(σ : out_param $ R →+* S) (M : out_param Type*) [topological_space M] [add_comm_monoid M]
(M₂ : out_param Type*) [topological_space M₂] [add_comm_monoid M₂] [module R M] [module S M₂]
extends semilinear_map_class F σ M M₂, continuous_map_class F M M₂
-- `σ`, `R` and `S` become metavariables, but they are all outparams so it's OK
attribute [nolint dangerous_instance] continuous_semilinear_map_class.to_continuous_map_class
/-- `continuous_linear_map_class F R M M₂` asserts `F` is a type of bundled continuous
`R`-linear maps `M → M₂`. This is an abbreviation for
`continuous_semilinear_map_class F (ring_hom.id R) M M₂`. -/
abbreviation continuous_linear_map_class (F : Type*)
(R : out_param Type*) [semiring R]
(M : out_param Type*) [topological_space M] [add_comm_monoid M]
(M₂ : out_param Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module R M₂] :=
continuous_semilinear_map_class F (ring_hom.id R) M M₂
set_option old_structure_cmd false
/-- Continuous linear equivalences between modules. We only put the type classes that are necessary
for the definition, although in applications `M` and `M₂` will be topological modules over the
topological semiring `R`. -/
@[nolint has_nonempty_instance]
structure continuous_linear_equiv
{R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
{σ' : S →+* R} [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ]
(M : Type*) [topological_space M] [add_comm_monoid M]
(M₂ : Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module S M₂]
extends M ≃ₛₗ[σ] M₂ :=
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
(continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity')
notation M ` ≃SL[`:50 σ `] ` M₂ := continuous_linear_equiv σ M M₂
notation M ` ≃L[`:50 R `] ` M₂ := continuous_linear_equiv (ring_hom.id R) M M₂
notation M ` ≃L⋆[`:50 R `] ` M₂ := continuous_linear_equiv (star_ring_end R) M M₂
set_option old_structure_cmd true
/-- `continuous_semilinear_equiv_class F σ M M₂` asserts `F` is a type of bundled continuous
`σ`-semilinear equivs `M → M₂`. See also `continuous_linear_equiv_class F R M M₂` for the case
where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring
homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y`
and `f (c • x) = (σ c) • f x`. -/
class continuous_semilinear_equiv_class (F : Type*)
{R : out_param Type*} {S : out_param Type*} [semiring R] [semiring S] (σ : out_param $ R →+* S)
{σ' : out_param $ S →+* R} [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ]
(M : out_param Type*) [topological_space M] [add_comm_monoid M]
(M₂ : out_param Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module S M₂]
extends semilinear_equiv_class F σ M M₂ :=
(map_continuous : ∀ (f : F), continuous f . tactic.interactive.continuity')
(inv_continuous : ∀ (f : F), continuous (inv f) . tactic.interactive.continuity')
/-- `continuous_linear_equiv_class F σ M M₂` asserts `F` is a type of bundled continuous
`R`-linear equivs `M → M₂`. This is an abbreviation for
`continuous_semilinear_equiv_class F (ring_hom.id) M M₂`. -/
abbreviation continuous_linear_equiv_class (F : Type*)
(R : out_param Type*) [semiring R]
(M : out_param Type*) [topological_space M] [add_comm_monoid M]
(M₂ : out_param Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module R M₂] :=
continuous_semilinear_equiv_class F (ring_hom.id R) M M₂
set_option old_structure_cmd false
namespace continuous_semilinear_equiv_class
variables (F : Type*)
{R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
{σ' : S →+* R} [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ]
(M : Type*) [topological_space M] [add_comm_monoid M]
(M₂ : Type*) [topological_space M₂] [add_comm_monoid M₂]
[module R M] [module S M₂]
include σ'
-- `σ'` becomes a metavariable, but it's OK since it's an outparam
@[priority 100, nolint dangerous_instance]
instance [s: continuous_semilinear_equiv_class F σ M M₂] :
continuous_semilinear_map_class F σ M M₂ :=
{ coe := (coe : F → M → M₂),
coe_injective' := @fun_like.coe_injective F _ _ _,
..s }
omit σ'
end continuous_semilinear_equiv_class
section pointwise_limits
variables
{M₁ M₂ α R S : Type*}
[topological_space M₂] [t2_space M₂] [semiring R] [semiring S]
[add_comm_monoid M₁] [add_comm_monoid M₂] [module R M₁] [module S M₂]
[has_continuous_const_smul S M₂]
section
variables (M₁ M₂) (σ : R →+* S)
lemma is_closed_set_of_map_smul : is_closed {f : M₁ → M₂ | ∀ c x, f (c • x) = σ c • f x} :=
begin
simp only [set.set_of_forall],
exact is_closed_Inter (λ c, is_closed_Inter (λ x, is_closed_eq (continuous_apply _)
((continuous_apply _).const_smul _)))
end
end
variables [has_continuous_add M₂] {σ : R →+* S} {l : filter α}
/-- Constructs a bundled linear map from a function and a proof that this function belongs to the
closure of the set of linear maps. -/
@[simps { fully_applied := ff }] def linear_map_of_mem_closure_range_coe (f : M₁ → M₂)
(hf : f ∈ closure (set.range (coe_fn : (M₁ →ₛₗ[σ] M₂) → (M₁ → M₂)))) :
M₁ →ₛₗ[σ] M₂ :=
{ to_fun := f,
map_smul' := (is_closed_set_of_map_smul M₁ M₂ σ).closure_subset_iff.2
(set.range_subset_iff.2 linear_map.map_smulₛₗ) hf,
.. add_monoid_hom_of_mem_closure_range_coe f hf }
/-- Construct a bundled linear map from a pointwise limit of linear maps -/
@[simps { fully_applied := ff }]
def linear_map_of_tendsto (f : M₁ → M₂) (g : α → M₁ →ₛₗ[σ] M₂) [l.ne_bot]
(h : tendsto (λ a x, g a x) l (𝓝 f)) : M₁ →ₛₗ[σ] M₂ :=
linear_map_of_mem_closure_range_coe f $ mem_closure_of_tendsto h $
eventually_of_forall $ λ a, set.mem_range_self _
variables (M₁ M₂ σ)
lemma linear_map.is_closed_range_coe :
is_closed (set.range (coe_fn : (M₁ →ₛₗ[σ] M₂) → (M₁ → M₂))) :=
is_closed_of_closure_subset $ λ f hf, ⟨linear_map_of_mem_closure_range_coe f hf, rfl⟩
end pointwise_limits
namespace continuous_linear_map
section semiring
/-!
### Properties that hold for non-necessarily commutative semirings.
-/
variables
{R₁ : Type*} {R₂ : Type*} {R₃ : Type*} [semiring R₁] [semiring R₂] [semiring R₃]
{σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃}
{M₁ : Type*} [topological_space M₁] [add_comm_monoid M₁]
{M'₁ : Type*} [topological_space M'₁] [add_comm_monoid M'₁]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_monoid M₄]
[module R₁ M₁] [module R₁ M'₁] [module R₂ M₂] [module R₃ M₃]
/-- Coerce continuous linear maps to linear maps. -/
instance : has_coe (M₁ →SL[σ₁₂] M₂) (M₁ →ₛₗ[σ₁₂] M₂) := ⟨to_linear_map⟩
-- make the coercion the preferred form
@[simp] lemma to_linear_map_eq_coe (f : M₁ →SL[σ₁₂] M₂) : f.to_linear_map = f := rfl
theorem coe_injective : function.injective (coe : (M₁ →SL[σ₁₂] M₂) → (M₁ →ₛₗ[σ₁₂] M₂)) :=
by { intros f g H, cases f, cases g, congr' }
instance : continuous_semilinear_map_class (M₁ →SL[σ₁₂] M₂) σ₁₂ M₁ M₂ :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, coe_injective (fun_like.coe_injective h),
map_add := λ f, map_add f.to_linear_map,
map_continuous := λ f, f.2,
map_smulₛₗ := λ f, f.to_linear_map.map_smul' }
/-- Coerce continuous linear maps to functions. -/
-- see Note [function coercion]
instance to_fun : has_coe_to_fun (M₁ →SL[σ₁₂] M₂) (λ _, M₁ → M₂) := ⟨λ f, f.to_fun⟩
@[simp] lemma coe_mk (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl
@[simp] lemma coe_mk' (f : M₁ →ₛₗ[σ₁₂] M₂) (h) : (mk f h : M₁ → M₂) = f := rfl
@[continuity]
protected lemma continuous (f : M₁ →SL[σ₁₂] M₂) : continuous f := f.2
protected lemma uniform_continuous {E₁ E₂ : Type*} [uniform_space E₁] [uniform_space E₂]
[add_comm_group E₁] [add_comm_group E₂] [module R₁ E₁] [module R₂ E₂]
[uniform_add_group E₁] [uniform_add_group E₂] (f : E₁ →SL[σ₁₂] E₂) :
uniform_continuous f :=
uniform_continuous_add_monoid_hom_of_continuous f.continuous
@[simp, norm_cast] lemma coe_inj {f g : M₁ →SL[σ₁₂] M₂} :
(f : M₁ →ₛₗ[σ₁₂] M₂) = g ↔ f = g :=
coe_injective.eq_iff
theorem coe_fn_injective : @function.injective (M₁ →SL[σ₁₂] M₂) (M₁ → M₂) coe_fn :=
fun_like.coe_injective
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : M₁ →SL[σ₁₂] M₂) : M₁ → M₂ := h
/-- See Note [custom simps projection]. -/
def simps.coe (h : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂ := h
initialize_simps_projections continuous_linear_map
(to_linear_map_to_fun → apply, to_linear_map → coe)
@[ext] theorem ext {f g : M₁ →SL[σ₁₂] M₂} (h : ∀ x, f x = g x) : f = g :=
fun_like.ext f g h
theorem ext_iff {f g : M₁ →SL[σ₁₂] M₂} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Copy of a `continuous_linear_map` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : M₁ →SL[σ₁₂] M₂ :=
{ to_linear_map := f.to_linear_map.copy f' h,
cont := show continuous f', from h.symm ▸ f.continuous }
@[simp]
lemma coe_copy (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : ⇑(f.copy f' h) = f' := rfl
lemma copy_eq (f : M₁ →SL[σ₁₂] M₂) (f' : M₁ → M₂) (h : f' = ⇑f) : f.copy f' h = f := fun_like.ext' h
-- make some straightforward lemmas available to `simp`.
protected lemma map_zero (f : M₁ →SL[σ₁₂] M₂) : f (0 : M₁) = 0 := map_zero f
protected lemma map_add (f : M₁ →SL[σ₁₂] M₂) (x y : M₁) : f (x + y) = f x + f y := map_add f x y
@[simp]
protected lemma map_smulₛₗ (f : M₁ →SL[σ₁₂] M₂) (c : R₁) (x : M₁) :
f (c • x) = (σ₁₂ c) • f x := (to_linear_map _).map_smulₛₗ _ _
@[simp]
protected lemma map_smul [module R₁ M₂] (f : M₁ →L[R₁] M₂)(c : R₁) (x : M₁) : f (c • x) = c • f x :=
by simp only [ring_hom.id_apply, continuous_linear_map.map_smulₛₗ]
@[simp, priority 900]
lemma map_smul_of_tower {R S : Type*} [semiring S] [has_smul R M₁]
[module S M₁] [has_smul R M₂] [module S M₂]
[linear_map.compatible_smul M₁ M₂ R S] (f : M₁ →L[S] M₂) (c : R) (x : M₁) :
f (c • x) = c • f x :=
linear_map.compatible_smul.map_smul f c x
protected lemma map_sum {ι : Type*} (f : M₁ →SL[σ₁₂] M₂) (s : finset ι) (g : ι → M₁) :
f (∑ i in s, g i) = ∑ i in s, f (g i) := f.to_linear_map.map_sum
@[simp, norm_cast] lemma coe_coe (f : M₁ →SL[σ₁₂] M₂) : ⇑(f : M₁ →ₛₗ[σ₁₂] M₂) = f := rfl
@[ext] theorem ext_ring [topological_space R₁] {f g : R₁ →L[R₁] M₁} (h : f 1 = g 1) : f = g :=
coe_inj.1 $ linear_map.ext_ring h
theorem ext_ring_iff [topological_space R₁] {f g : R₁ →L[R₁] M₁} : f = g ↔ f 1 = g 1 :=
⟨λ h, h ▸ rfl, ext_ring⟩
/-- If two continuous linear maps are equal on a set `s`, then they are equal on the closure
of the `submodule.span` of this set. -/
lemma eq_on_closure_span [t2_space M₂] {s : set M₁} {f g : M₁ →SL[σ₁₂] M₂} (h : set.eq_on f g s) :
set.eq_on f g (closure (submodule.span R₁ s : set M₁)) :=
(linear_map.eq_on_span' h).closure f.continuous g.continuous
/-- If the submodule generated by a set `s` is dense in the ambient module, then two continuous
linear maps equal on `s` are equal. -/
lemma ext_on [t2_space M₂] {s : set M₁} (hs : dense (submodule.span R₁ s : set M₁))
{f g : M₁ →SL[σ₁₂] M₂} (h : set.eq_on f g s) :
f = g :=
ext $ λ x, eq_on_closure_span h (hs x)
/-- Under a continuous linear map, the image of the `topological_closure` of a submodule is
contained in the `topological_closure` of its image. -/
lemma _root_.submodule.topological_closure_map [ring_hom_surjective σ₁₂] [topological_space R₁]
[topological_space R₂] [has_continuous_smul R₁ M₁] [has_continuous_add M₁]
[has_continuous_smul R₂ M₂] [has_continuous_add M₂] (f : M₁ →SL[σ₁₂] M₂) (s : submodule R₁ M₁) :
(s.topological_closure.map (f : M₁ →ₛₗ[σ₁₂] M₂))
≤ (s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topological_closure :=
image_closure_subset_closure_image f.continuous
/-- Under a dense continuous linear map, a submodule whose `topological_closure` is `⊤` is sent to
another such submodule. That is, the image of a dense set under a map with dense range is dense.
-/
lemma _root_.dense_range.topological_closure_map_submodule [ring_hom_surjective σ₁₂]
[topological_space R₁] [topological_space R₂] [has_continuous_smul R₁ M₁] [has_continuous_add M₁]
[has_continuous_smul R₂ M₂] [has_continuous_add M₂] {f : M₁ →SL[σ₁₂] M₂} (hf' : dense_range f)
{s : submodule R₁ M₁} (hs : s.topological_closure = ⊤) :
(s.map (f : M₁ →ₛₗ[σ₁₂] M₂)).topological_closure = ⊤ :=
begin
rw set_like.ext'_iff at hs ⊢,
simp only [submodule.topological_closure_coe, submodule.top_coe, ← dense_iff_closure_eq] at hs ⊢,
exact hf'.dense_image f.continuous hs
end
section smul_monoid
variables {S₂ T₂ : Type*} [monoid S₂] [monoid T₂]
variables [distrib_mul_action S₂ M₂] [smul_comm_class R₂ S₂ M₂] [has_continuous_const_smul S₂ M₂]
variables [distrib_mul_action T₂ M₂] [smul_comm_class R₂ T₂ M₂] [has_continuous_const_smul T₂ M₂]
instance : mul_action S₂ (M₁ →SL[σ₁₂] M₂) :=
{ smul := λ c f, ⟨c • f, (f.2.const_smul _ : continuous (λ x, c • f x))⟩,
one_smul := λ f, ext $ λ x, one_smul _ _,
mul_smul := λ a b f, ext $ λ x, mul_smul _ _ _ }
lemma smul_apply (c : S₂) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (c • f) x = c • (f x) := rfl
@[simp, norm_cast]
lemma coe_smul (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : (↑(c • f) : M₁ →ₛₗ[σ₁₂] M₂) = c • f := rfl
@[simp, norm_cast] lemma coe_smul' (c : S₂) (f : M₁ →SL[σ₁₂] M₂) : ⇑(c • f) = c • f := rfl
instance [has_smul S₂ T₂] [is_scalar_tower S₂ T₂ M₂] : is_scalar_tower S₂ T₂ (M₁ →SL[σ₁₂] M₂) :=
⟨λ a b f, ext $ λ x, smul_assoc a b (f x)⟩
instance [smul_comm_class S₂ T₂ M₂] : smul_comm_class S₂ T₂ (M₁ →SL[σ₁₂] M₂) :=
⟨λ a b f, ext $ λ x, smul_comm a b (f x)⟩
end smul_monoid
/-- The continuous map that is constantly zero. -/
instance: has_zero (M₁ →SL[σ₁₂] M₂) := ⟨⟨0, continuous_zero⟩⟩
instance : inhabited (M₁ →SL[σ₁₂] M₂) := ⟨0⟩
@[simp] lemma default_def : (default : M₁ →SL[σ₁₂] M₂) = 0 := rfl
@[simp] lemma zero_apply (x : M₁) : (0 : M₁ →SL[σ₁₂] M₂) x = 0 := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : M₁ →SL[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₂] M₂) = 0 := rfl
/- no simp attribute on the next line as simp does not always simplify `0 x` to `0`
when `0` is the zero function, while it does for the zero continuous linear map,
and this is the most important property we care about. -/
@[norm_cast] lemma coe_zero' : ⇑(0 : M₁ →SL[σ₁₂] M₂) = 0 := rfl
instance unique_of_left [subsingleton M₁] : unique (M₁ →SL[σ₁₂] M₂) :=
coe_injective.unique
instance unique_of_right [subsingleton M₂] : unique (M₁ →SL[σ₁₂] M₂) :=
coe_injective.unique
lemma exists_ne_zero {f : M₁ →SL[σ₁₂] M₂} (hf : f ≠ 0) : ∃ x, f x ≠ 0 :=
by { by_contra' h, exact hf (continuous_linear_map.ext h) }
section
variables (R₁ M₁)
/-- the identity map as a continuous linear map. -/
def id : M₁ →L[R₁] M₁ :=
⟨linear_map.id, continuous_id⟩
end
instance : has_one (M₁ →L[R₁] M₁) := ⟨id R₁ M₁⟩
lemma one_def : (1 : M₁ →L[R₁] M₁) = id R₁ M₁ := rfl
lemma id_apply (x : M₁) : id R₁ M₁ x = x := rfl
@[simp, norm_cast] lemma coe_id : (id R₁ M₁ : M₁ →ₗ[R₁] M₁) = linear_map.id := rfl
@[simp, norm_cast] lemma coe_id' : ⇑(id R₁ M₁) = _root_.id := rfl
@[simp, norm_cast] lemma coe_eq_id {f : M₁ →L[R₁] M₁} :
(f : M₁ →ₗ[R₁] M₁) = linear_map.id ↔ f = id _ _ :=
by rw [← coe_id, coe_inj]
@[simp] lemma one_apply (x : M₁) : (1 : M₁ →L[R₁] M₁) x = x := rfl
section add
variables [has_continuous_add M₂]
instance : has_add (M₁ →SL[σ₁₂] M₂) :=
⟨λ f g, ⟨f + g, f.2.add g.2⟩⟩
@[simp] lemma add_apply (f g : M₁ →SL[σ₁₂] M₂) (x : M₁) : (f + g) x = f x + g x := rfl
@[simp, norm_cast] lemma coe_add (f g : M₁ →SL[σ₁₂] M₂) : (↑(f + g) : M₁ →ₛₗ[σ₁₂] M₂) = f + g := rfl
@[norm_cast] lemma coe_add' (f g : M₁ →SL[σ₁₂] M₂) : ⇑(f + g) = f + g := rfl
instance : add_comm_monoid (M₁ →SL[σ₁₂] M₂) :=
{ zero := (0 : M₁ →SL[σ₁₂] M₂),
add := (+),
zero_add := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
add_zero := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
add_comm := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
add_assoc := by intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm],
nsmul := (•),
nsmul_zero' := λ f, by { ext, simp },
nsmul_succ' := λ n f, by { ext, simp [nat.succ_eq_one_add, add_smul] } }
@[simp, norm_cast] lemma coe_sum {ι : Type*} (t : finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) :
↑(∑ d in t, f d) = (∑ d in t, f d : M₁ →ₛₗ[σ₁₂] M₂) :=
(add_monoid_hom.mk (coe : (M₁ →SL[σ₁₂] M₂) → (M₁ →ₛₗ[σ₁₂] M₂)) rfl (λ _ _, rfl)).map_sum _ _
@[simp, norm_cast] lemma coe_sum' {ι : Type*} (t : finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) :
⇑(∑ d in t, f d) = ∑ d in t, f d :=
by simp only [← coe_coe, coe_sum, linear_map.coe_fn_sum]
lemma sum_apply {ι : Type*} (t : finset ι) (f : ι → M₁ →SL[σ₁₂] M₂) (b : M₁) :
(∑ d in t, f d) b = ∑ d in t, f d b :=
by simp only [coe_sum', finset.sum_apply]
end add
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
/-- Composition of bounded linear maps. -/
def comp (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) : M₁ →SL[σ₁₃] M₃ :=
⟨(g : M₂ →ₛₗ[σ₂₃] M₃).comp ↑f, g.2.comp f.2⟩
infixr ` ∘L `:80 := @continuous_linear_map.comp _ _ _ _ _ _
(ring_hom.id _) (ring_hom.id _) (ring_hom.id _) _ _ _ _ _ _ _ _ _ _ _ _ ring_hom_comp_triple.ids
@[simp, norm_cast] lemma coe_comp (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) :
(h.comp f : M₁ →ₛₗ[σ₁₃] M₃) = (h : M₂ →ₛₗ[σ₂₃] M₃).comp (f : M₁ →ₛₗ[σ₁₂] M₂) := rfl
include σ₁₃
@[simp, norm_cast] lemma coe_comp' (h : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) :
⇑(h.comp f) = h ∘ f := rfl
lemma comp_apply (g : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) (x : M₁) : (g.comp f) x = g (f x) := rfl
omit σ₁₃
@[simp] theorem comp_id (f : M₁ →SL[σ₁₂] M₂) : f.comp (id R₁ M₁) = f :=
ext $ λ x, rfl
@[simp] theorem id_comp (f : M₁ →SL[σ₁₂] M₂) : (id R₂ M₂).comp f = f :=
ext $ λ x, rfl
include σ₁₃
@[simp] theorem comp_zero (g : M₂ →SL[σ₂₃] M₃) : g.comp (0 : M₁ →SL[σ₁₂] M₂) = 0 :=
by { ext, simp }
@[simp] theorem zero_comp (f : M₁ →SL[σ₁₂] M₂) : (0 : M₂ →SL[σ₂₃] M₃).comp f = 0 :=
by { ext, simp }
@[simp] lemma comp_add [has_continuous_add M₂] [has_continuous_add M₃]
(g : M₂ →SL[σ₂₃] M₃) (f₁ f₂ : M₁ →SL[σ₁₂] M₂) :
g.comp (f₁ + f₂) = g.comp f₁ + g.comp f₂ :=
by { ext, simp }
@[simp] lemma add_comp [has_continuous_add M₃]
(g₁ g₂ : M₂ →SL[σ₂₃] M₃) (f : M₁ →SL[σ₁₂] M₂) :
(g₁ + g₂).comp f = g₁.comp f + g₂.comp f :=
by { ext, simp }
omit σ₁₃
theorem comp_assoc {R₄ : Type*} [semiring R₄] [module R₄ M₄] {σ₁₄ : R₁ →+* R₄} {σ₂₄ : R₂ →+* R₄}
{σ₃₄ : R₃ →+* R₄} [ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄] [ring_hom_comp_triple σ₂₃ σ₃₄ σ₂₄]
[ring_hom_comp_triple σ₁₂ σ₂₄ σ₁₄] (h : M₃ →SL[σ₃₄] M₄) (g : M₂ →SL[σ₂₃] M₃)
(f : M₁ →SL[σ₁₂] M₂) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
instance : has_mul (M₁ →L[R₁] M₁) := ⟨comp⟩
lemma mul_def (f g : M₁ →L[R₁] M₁) : f * g = f.comp g := rfl
@[simp] lemma coe_mul (f g : M₁ →L[R₁] M₁) : ⇑(f * g) = f ∘ g := rfl
lemma mul_apply (f g : M₁ →L[R₁] M₁) (x : M₁) : (f * g) x = f (g x) := rfl
instance : monoid_with_zero (M₁ →L[R₁] M₁) :=
{ mul := (*),
one := 1,
zero := 0,
mul_zero := λ f, ext $ λ _, map_zero f,
zero_mul := λ _, ext $ λ _, rfl,
mul_one := λ _, ext $ λ _, rfl,
one_mul := λ _, ext $ λ _, rfl,
mul_assoc := λ _ _ _, ext $ λ _, rfl, }
instance [has_continuous_add M₁] : semiring (M₁ →L[R₁] M₁) :=
{ mul := (*),
one := 1,
left_distrib := λ f g h, ext $ λ x, map_add f (g x) (h x),
right_distrib := λ _ _ _, ext $ λ _, linear_map.add_apply _ _ _,
..continuous_linear_map.monoid_with_zero,
..continuous_linear_map.add_comm_monoid }
/-- `continuous_linear_map.to_linear_map` as a `ring_hom`.-/
@[simps]
def to_linear_map_ring_hom [has_continuous_add M₁] : (M₁ →L[R₁] M₁) →+* (M₁ →ₗ[R₁] M₁) :=
{ to_fun := to_linear_map,
map_zero' := rfl,
map_one' := rfl,
map_add' := λ _ _, rfl,
map_mul' := λ _ _, rfl }
section apply_action
variables [has_continuous_add M₁]
/-- The tautological action by `M₁ →L[R₁] M₁` on `M`.
This generalizes `function.End.apply_mul_action`. -/
instance apply_module : module (M₁ →L[R₁] M₁) M₁ :=
module.comp_hom _ to_linear_map_ring_hom
@[simp] protected lemma smul_def (f : M₁ →L[R₁] M₁) (a : M₁) : f • a = f a := rfl
/-- `continuous_linear_map.apply_module` is faithful. -/
instance apply_has_faithful_smul : has_faithful_smul (M₁ →L[R₁] M₁) M₁ :=
⟨λ _ _, continuous_linear_map.ext⟩
instance apply_smul_comm_class : smul_comm_class R₁ (M₁ →L[R₁] M₁) M₁ :=
{ smul_comm := λ r e m, (e.map_smul r m).symm }
instance apply_smul_comm_class' : smul_comm_class (M₁ →L[R₁] M₁) R₁ M₁ :=
{ smul_comm := continuous_linear_map.map_smul }
instance : has_continuous_const_smul (M₁ →L[R₁] M₁) M₁ :=
⟨continuous_linear_map.continuous⟩
end apply_action
/-- The cartesian product of two bounded linear maps, as a bounded linear map. -/
protected def prod [module R₁ M₂] [module R₁ M₃] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₁ →L[R₁] M₃) :
M₁ →L[R₁] (M₂ × M₃) :=
⟨(f₁ : M₁ →ₗ[R₁] M₂).prod f₂, f₁.2.prod_mk f₂.2⟩
@[simp, norm_cast] lemma coe_prod [module R₁ M₂] [module R₁ M₃] (f₁ : M₁ →L[R₁] M₂)
(f₂ : M₁ →L[R₁] M₃) :
(f₁.prod f₂ : M₁ →ₗ[R₁] M₂ × M₃) = linear_map.prod f₁ f₂ :=
rfl
@[simp, norm_cast] lemma prod_apply [module R₁ M₂] [module R₁ M₃] (f₁ : M₁ →L[R₁] M₂)
(f₂ : M₁ →L[R₁] M₃) (x : M₁) :
f₁.prod f₂ x = (f₁ x, f₂ x) :=
rfl
section
variables (R₁ M₁ M₂)
/-- The left injection into a product is a continuous linear map. -/
def inl [module R₁ M₂] : M₁ →L[R₁] M₁ × M₂ := (id R₁ M₁).prod 0
/-- The right injection into a product is a continuous linear map. -/
def inr [module R₁ M₂] : M₂ →L[R₁] M₁ × M₂ := (0 : M₂ →L[R₁] M₁).prod (id R₁ M₂)
end
variables {F : Type*}
@[simp] lemma inl_apply [module R₁ M₂] (x : M₁) : inl R₁ M₁ M₂ x = (x, 0) := rfl
@[simp] lemma inr_apply [module R₁ M₂] (x : M₂) : inr R₁ M₁ M₂ x = (0, x) := rfl
@[simp, norm_cast] lemma coe_inl [module R₁ M₂] :
(inl R₁ M₁ M₂ : M₁ →ₗ[R₁] M₁ × M₂) = linear_map.inl R₁ M₁ M₂ := rfl
@[simp, norm_cast] lemma coe_inr [module R₁ M₂] :
(inr R₁ M₁ M₂ : M₂ →ₗ[R₁] M₁ × M₂) = linear_map.inr R₁ M₁ M₂ := rfl
lemma is_closed_ker [t1_space M₂] [continuous_semilinear_map_class F σ₁₂ M₁ M₂]
(f : F) : is_closed (ker f : set M₁) :=
continuous_iff_is_closed.1 (map_continuous f) _ is_closed_singleton
lemma is_complete_ker {M' : Type*} [uniform_space M'] [complete_space M'] [add_comm_monoid M']
[module R₁ M'] [t1_space M₂] [continuous_semilinear_map_class F σ₁₂ M' M₂]
(f : F) : is_complete (ker f : set M') :=
(is_closed_ker f).is_complete
@[priority 100]
instance complete_space_ker {M' : Type*} [uniform_space M'] [complete_space M'] [add_comm_monoid M']
[module R₁ M'] [t1_space M₂] [continuous_semilinear_map_class F σ₁₂ M' M₂]
(f : F) : complete_space (ker f) :=
(is_closed_ker f).complete_space_coe
@[simp] lemma ker_prod [module R₁ M₂] [module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) :
ker (f.prod g) = ker f ⊓ ker g :=
linear_map.ker_prod f g
/-- Restrict codomain of a continuous linear map. -/
def cod_restrict (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p) :
M₁ →SL[σ₁₂] p :=
{ cont := f.continuous.subtype_mk _,
to_linear_map := (f : M₁ →ₛₗ[σ₁₂] M₂).cod_restrict p h}
@[norm_cast] lemma coe_cod_restrict (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p) :
(f.cod_restrict p h : M₁ →ₛₗ[σ₁₂] p) = (f : M₁ →ₛₗ[σ₁₂] M₂).cod_restrict p h :=
rfl
@[simp] lemma coe_cod_restrict_apply (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p)
(x) :
(f.cod_restrict p h x : M₂) = f x :=
rfl
@[simp] lemma ker_cod_restrict (f : M₁ →SL[σ₁₂] M₂) (p : submodule R₂ M₂) (h : ∀ x, f x ∈ p) :
ker (f.cod_restrict p h) = ker f :=
(f : M₁ →ₛₗ[σ₁₂] M₂).ker_cod_restrict p h
/-- `submodule.subtype` as a `continuous_linear_map`. -/
def _root_.submodule.subtypeL (p : submodule R₁ M₁) : p →L[R₁] M₁ :=
{ cont := continuous_subtype_val,
to_linear_map := p.subtype }
@[simp, norm_cast] lemma _root_.submodule.coe_subtypeL (p : submodule R₁ M₁) :
(p.subtypeL : p →ₗ[R₁] M₁) = p.subtype :=
rfl
@[simp] lemma _root_.submodule.coe_subtypeL' (p : submodule R₁ M₁) :
⇑p.subtypeL = p.subtype :=
rfl
@[simp, norm_cast] lemma _root_.submodule.subtypeL_apply (p : submodule R₁ M₁) (x : p) :
p.subtypeL x = x :=
rfl
@[simp] lemma _root_.submodule.range_subtypeL (p : submodule R₁ M₁) :
range p.subtypeL = p :=
submodule.range_subtype _
@[simp] lemma _root_.submodule.ker_subtypeL (p : submodule R₁ M₁) :
ker p.subtypeL = ⊥ :=
submodule.ker_subtype _
variables (R₁ M₁ M₂)
/-- `prod.fst` as a `continuous_linear_map`. -/
def fst [module R₁ M₂] : M₁ × M₂ →L[R₁] M₁ :=
{ cont := continuous_fst, to_linear_map := linear_map.fst R₁ M₁ M₂ }
/-- `prod.snd` as a `continuous_linear_map`. -/
def snd [module R₁ M₂] : M₁ × M₂ →L[R₁] M₂ :=
{ cont := continuous_snd, to_linear_map := linear_map.snd R₁ M₁ M₂ }
variables {R₁ M₁ M₂}
@[simp, norm_cast] lemma coe_fst [module R₁ M₂] : ↑(fst R₁ M₁ M₂) = linear_map.fst R₁ M₁ M₂ := rfl
@[simp, norm_cast] lemma coe_fst' [module R₁ M₂] : ⇑(fst R₁ M₁ M₂) = prod.fst := rfl
@[simp, norm_cast] lemma coe_snd [module R₁ M₂] : ↑(snd R₁ M₁ M₂) = linear_map.snd R₁ M₁ M₂ := rfl
@[simp, norm_cast] lemma coe_snd' [module R₁ M₂] : ⇑(snd R₁ M₁ M₂) = prod.snd := rfl
@[simp] lemma fst_prod_snd [module R₁ M₂] : (fst R₁ M₁ M₂).prod (snd R₁ M₁ M₂) = id R₁ (M₁ × M₂) :=
ext $ λ ⟨x, y⟩, rfl
@[simp] lemma fst_comp_prod [module R₁ M₂] [module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) :
(fst R₁ M₂ M₃).comp (f.prod g) = f :=
ext $ λ x, rfl
@[simp] lemma snd_comp_prod [module R₁ M₂] [module R₁ M₃] (f : M₁ →L[R₁] M₂) (g : M₁ →L[R₁] M₃) :
(snd R₁ M₂ M₃).comp (f.prod g) = g :=
ext $ λ x, rfl
/-- `prod.map` of two continuous linear maps. -/
def prod_map [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) :
(M₁ × M₃) →L[R₁] (M₂ × M₄) :=
(f₁.comp (fst R₁ M₁ M₃)).prod (f₂.comp (snd R₁ M₁ M₃))
@[simp, norm_cast] lemma coe_prod_map [module R₁ M₂] [module R₁ M₃] [module R₁ M₄]
(f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) :
↑(f₁.prod_map f₂) = ((f₁ : M₁ →ₗ[R₁] M₂).prod_map (f₂ : M₃ →ₗ[R₁] M₄)) :=
rfl
@[simp, norm_cast] lemma coe_prod_map' [module R₁ M₂] [module R₁ M₃] [module R₁ M₄]
(f₁ : M₁ →L[R₁] M₂) (f₂ : M₃ →L[R₁] M₄) :
⇑(f₁.prod_map f₂) = prod.map f₁ f₂ :=
rfl
/-- The continuous linear map given by `(x, y) ↦ f₁ x + f₂ y`. -/
def coprod [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃] (f₁ : M₁ →L[R₁] M₃)
(f₂ : M₂ →L[R₁] M₃) :
(M₁ × M₂) →L[R₁] M₃ :=
⟨linear_map.coprod f₁ f₂, (f₁.cont.comp continuous_fst).add (f₂.cont.comp continuous_snd)⟩
@[norm_cast, simp] lemma coe_coprod [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃]
(f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) :
(f₁.coprod f₂ : (M₁ × M₂) →ₗ[R₁] M₃) = linear_map.coprod f₁ f₂ :=
rfl
@[simp] lemma coprod_apply [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃]
(f₁ : M₁ →L[R₁] M₃) (f₂ : M₂ →L[R₁] M₃) (x) :
f₁.coprod f₂ x = f₁ x.1 + f₂ x.2 := rfl
lemma range_coprod [module R₁ M₂] [module R₁ M₃] [has_continuous_add M₃] (f₁ : M₁ →L[R₁] M₃)
(f₂ : M₂ →L[R₁] M₃) :
range (f₁.coprod f₂) = range f₁ ⊔ range f₂ :=
linear_map.range_coprod _ _
section
variables {R S : Type*} [semiring R] [semiring S] [module R M₁] [module R M₂] [module R S]
[module S M₂] [is_scalar_tower R S M₂] [topological_space S] [has_continuous_smul S M₂]
/-- The linear map `λ x, c x • f`. Associates to a scalar-valued linear map and an element of
`M₂` the `M₂`-valued linear map obtained by multiplying the two (a.k.a. tensoring by `M₂`).
See also `continuous_linear_map.smul_rightₗ` and `continuous_linear_map.smul_rightL`. -/
def smul_right (c : M₁ →L[R] S) (f : M₂) : M₁ →L[R] M₂ :=
{ cont := c.2.smul continuous_const,
..c.to_linear_map.smul_right f }
@[simp]
lemma smul_right_apply {c : M₁ →L[R] S} {f : M₂} {x : M₁} :
(smul_right c f : M₁ → M₂) x = c x • f :=
rfl
end
variables [module R₁ M₂] [topological_space R₁] [has_continuous_smul R₁ M₂]
@[simp]
lemma smul_right_one_one (c : R₁ →L[R₁] M₂) : smul_right (1 : R₁ →L[R₁] R₁) (c 1) = c :=
by ext; simp [← continuous_linear_map.map_smul_of_tower]
@[simp]
lemma smul_right_one_eq_iff {f f' : M₂} :
smul_right (1 : R₁ →L[R₁] R₁) f = smul_right (1 : R₁ →L[R₁] R₁) f' ↔ f = f' :=
by simp only [ext_ring_iff, smul_right_apply, one_apply, one_smul]
lemma smul_right_comp [has_continuous_mul R₁] {x : M₂} {c : R₁} :
(smul_right (1 : R₁ →L[R₁] R₁) x).comp (smul_right (1 : R₁ →L[R₁] R₁) c) =
smul_right (1 : R₁ →L[R₁] R₁) (c • x) :=
by { ext, simp [mul_smul] }
end semiring
section pi
variables
{R : Type*} [semiring R]
{M : Type*} [topological_space M] [add_comm_monoid M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [module R M₂]
{ι : Type*} {φ : ι → Type*} [∀i, topological_space (φ i)] [∀i, add_comm_monoid (φ i)]
[∀i, module R (φ i)]
/-- `pi` construction for continuous linear functions. From a family of continuous linear functions
it produces a continuous linear function into a family of topological modules. -/
def pi (f : Πi, M →L[R] φ i) : M →L[R] (Πi, φ i) :=
⟨linear_map.pi (λ i, f i), continuous_pi (λ i, (f i).continuous)⟩
@[simp] lemma coe_pi' (f : Π i, M →L[R] φ i) : ⇑(pi f) = λ c i, f i c := rfl
@[simp] lemma coe_pi (f : Π i, M →L[R] φ i) :
(pi f : M →ₗ[R] Π i, φ i) = linear_map.pi (λ i, f i) :=
rfl
lemma pi_apply (f : Πi, M →L[R] φ i) (c : M) (i : ι) :
pi f c i = f i c := rfl
lemma pi_eq_zero (f : Πi, M →L[R] φ i) : pi f = 0 ↔ (∀i, f i = 0) :=
by { simp only [ext_iff, pi_apply, function.funext_iff], exact forall_swap }
lemma pi_zero : pi (λi, 0 : Πi, M →L[R] φ i) = 0 := ext $ λ _, rfl
lemma pi_comp (f : Πi, M →L[R] φ i) (g : M₂ →L[R] M) : (pi f).comp g = pi (λi, (f i).comp g) := rfl
/-- The projections from a family of topological modules are continuous linear maps. -/
def proj (i : ι) : (Πi, φ i) →L[R] φ i :=
⟨linear_map.proj i, continuous_apply _⟩
@[simp] lemma proj_apply (i : ι) (b : Πi, φ i) : (proj i : (Πi, φ i) →L[R] φ i) b = b i := rfl
lemma proj_pi (f : Πi, M₂ →L[R] φ i) (i : ι) : (proj i).comp (pi f) = f i :=
ext $ assume c, rfl
lemma infi_ker_proj : (⨅i, ker (proj i : (Πi, φ i) →L[R] φ i) :
submodule R (Πi, φ i)) = ⊥ :=
linear_map.infi_ker_proj
variables (R φ)
/-- If `I` and `J` are complementary index sets, the product of the kernels of the `J`th projections
of `φ` is linearly equivalent to the product over `I`. -/
def infi_ker_proj_equiv {I J : set ι} [decidable_pred (λi, i ∈ I)]
(hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) :
(⨅i ∈ J, ker (proj i : (Πi, φ i) →L[R] φ i) :
submodule R (Πi, φ i)) ≃L[R] (Πi:I, φ i) :=
{ to_linear_equiv := linear_map.infi_ker_proj_equiv R φ hd hu,
continuous_to_fun := continuous_pi (λ i, begin
have := @continuous_subtype_coe _ _
(λ x, x ∈ (⨅i ∈ J, ker (proj i : (Πi, φ i) →L[R] φ i) : submodule R (Πi, φ i))),
have := continuous.comp (by exact continuous_apply i) this,
exact this
end),
continuous_inv_fun := continuous.subtype_mk (continuous_pi (λ i, begin
dsimp, split_ifs; [apply continuous_apply, exact continuous_zero]
end)) _ }
end pi
section ring
variables
{R : Type*} [ring R] {R₂ : Type*} [ring R₂] {R₃ : Type*} [ring R₃]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_group M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_group M₄]
[module R M] [module R₂ M₂] [module R₃ M₃]
{σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
section
protected lemma map_neg (f : M →SL[σ₁₂] M₂) (x : M) : f (-x) = - (f x) := map_neg _ _
protected lemma map_sub (f : M →SL[σ₁₂] M₂) (x y : M) : f (x - y) = f x - f y := map_sub _ _ _
@[simp] lemma sub_apply' (f g : M →SL[σ₁₂] M₂) (x : M) : ((f : M →ₛₗ[σ₁₂] M₂) - g) x = f x - g x :=
rfl
end
section
variables [module R M₂] [module R M₃] [module R M₄]
lemma range_prod_eq {f : M →L[R] M₂} {g : M →L[R] M₃}
(h : ker f ⊔ ker g = ⊤) :
range (f.prod g) = (range f).prod (range g) :=
linear_map.range_prod_eq h
lemma ker_prod_ker_le_ker_coprod [has_continuous_add M₃]
(f : M →L[R] M₃) (g : M₂ →L[R] M₃) :
(linear_map.ker f).prod (linear_map.ker g) ≤ linear_map.ker (f.coprod g) :=
linear_map.ker_prod_ker_le_ker_coprod f.to_linear_map g.to_linear_map
lemma ker_coprod_of_disjoint_range [has_continuous_add M₃]
(f : M →L[R] M₃) (g : M₂ →L[R] M₃) (hd : disjoint (range f) (range g)) :
linear_map.ker (f.coprod g) = (linear_map.ker f).prod (linear_map.ker g) :=
linear_map.ker_coprod_of_disjoint_range f.to_linear_map g.to_linear_map hd
end
section
variables [topological_add_group M₂]
instance : has_neg (M →SL[σ₁₂] M₂) := ⟨λ f, ⟨-f, f.2.neg⟩⟩
@[simp] lemma neg_apply (f : M →SL[σ₁₂] M₂) (x : M) : (-f) x = - (f x) := rfl
@[simp, norm_cast] lemma coe_neg (f : M →SL[σ₁₂] M₂) : (↑(-f) : M →ₛₗ[σ₁₂] M₂) = -f := rfl
@[norm_cast] lemma coe_neg' (f : M →SL[σ₁₂] M₂) : ⇑(-f) = -f := rfl
instance : has_sub (M →SL[σ₁₂] M₂) := ⟨λ f g, ⟨f - g, f.2.sub g.2⟩⟩
instance : add_comm_group (M →SL[σ₁₂] M₂) :=
by refine
{ zero := 0,
add := (+),
neg := has_neg.neg,
sub := has_sub.sub,
sub_eq_add_neg := _,
nsmul := (•),
zsmul := (•),
zsmul_zero' := λ f, by { ext, simp },
zsmul_succ' := λ n f, by { ext, simp [add_smul, add_comm] },
zsmul_neg' := λ n f, by { ext, simp [nat.succ_eq_add_one, add_smul] },
.. continuous_linear_map.add_comm_monoid, .. };
intros; ext; apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm, sub_eq_add_neg]
lemma sub_apply (f g : M →SL[σ₁₂] M₂) (x : M) : (f - g) x = f x - g x := rfl
@[simp, norm_cast] lemma coe_sub (f g : M →SL[σ₁₂] M₂) : (↑(f - g) : M →ₛₗ[σ₁₂] M₂) = f - g := rfl
@[simp, norm_cast] lemma coe_sub' (f g : M →SL[σ₁₂] M₂) : ⇑(f - g) = f - g := rfl
end
@[simp] lemma comp_neg [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [topological_add_group M₂]
[topological_add_group M₃] (g : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) :
g.comp (-f) = -g.comp f :=
by { ext, simp }
@[simp] lemma neg_comp [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [topological_add_group M₃]
(g : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) :
(-g).comp f = -g.comp f :=
by { ext, simp }
@[simp] lemma comp_sub [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [topological_add_group M₂]
[topological_add_group M₃] (g : M₂ →SL[σ₂₃] M₃) (f₁ f₂ : M →SL[σ₁₂] M₂) :
g.comp (f₁ - f₂) = g.comp f₁ - g.comp f₂ :=
by { ext, simp }
@[simp] lemma sub_comp [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [topological_add_group M₃]
(g₁ g₂ : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) :
(g₁ - g₂).comp f = g₁.comp f - g₂.comp f :=
by { ext, simp }
instance [topological_add_group M] : ring (M →L[R] M) :=
{ mul := (*),
one := 1,
..continuous_linear_map.semiring,
..continuous_linear_map.add_comm_group }
lemma smul_right_one_pow [topological_space R] [topological_ring R] (c : R) (n : ℕ) :
(smul_right (1 : R →L[R] R) c)^n = smul_right (1 : R →L[R] R) (c^n) :=
begin
induction n with n ihn,
{ ext, simp },
{ rw [pow_succ, ihn, mul_def, smul_right_comp, smul_eq_mul, pow_succ'] }
end
section
variables {σ₂₁ : R₂ →+* R} [ring_hom_inv_pair σ₁₂ σ₂₁]
/-- Given a right inverse `f₂ : M₂ →L[R] M` to `f₁ : M →L[R] M₂`,
`proj_ker_of_right_inverse f₁ f₂ h` is the projection `M →L[R] f₁.ker` along `f₂.range`. -/
def proj_ker_of_right_inverse [topological_add_group M] (f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M)
(h : function.right_inverse f₂ f₁) :
M →L[R] (linear_map.ker f₁) :=
(id R M - f₂.comp f₁).cod_restrict (linear_map.ker f₁) $ λ x, by simp [h (f₁ x)]
@[simp] lemma coe_proj_ker_of_right_inverse_apply [topological_add_group M]
(f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M) (h : function.right_inverse f₂ f₁) (x : M) :
(f₁.proj_ker_of_right_inverse f₂ h x : M) = x - f₂ (f₁ x) :=
rfl
@[simp] lemma proj_ker_of_right_inverse_apply_idem [topological_add_group M]
(f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M) (h : function.right_inverse f₂ f₁)
(x : linear_map.ker f₁) : f₁.proj_ker_of_right_inverse f₂ h x = x :=
subtype.ext_iff_val.2 $ by simp
@[simp] lemma proj_ker_of_right_inverse_comp_inv [topological_add_group M]
(f₁ : M →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M) (h : function.right_inverse f₂ f₁) (y : M₂) :
f₁.proj_ker_of_right_inverse f₂ h (f₂ y) = 0 :=
subtype.ext_iff_val.2 $ by simp [h y]
end
end ring
section division_monoid
variables {R M : Type*}
/-- A nonzero continuous linear functional is open. -/
protected lemma is_open_map_of_ne_zero [topological_space R] [division_ring R]
[has_continuous_sub R] [add_comm_group M] [topological_space M] [has_continuous_add M]
[module R M] [has_continuous_smul R M] (f : M →L[R] R) (hf : f ≠ 0) : is_open_map f :=
let ⟨x, hx⟩ := exists_ne_zero hf in is_open_map.of_sections $ λ y,
⟨λ a, y + (a - f y) • (f x)⁻¹ • x, continuous.continuous_at $ by continuity,
by simp, λ a, by simp [hx]⟩
end division_monoid
section smul_monoid
-- The M's are used for semilinear maps, and the N's for plain linear maps
variables {R R₂ R₃ S S₃ : Type*} [semiring R] [semiring R₂] [semiring R₃]
[monoid S] [monoid S₃]
{M : Type*} [topological_space M] [add_comm_monoid M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [module R₂ M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃] [module R₃ M₃]
{N₂ : Type*} [topological_space N₂] [add_comm_monoid N₂] [module R N₂]
{N₃ : Type*} [topological_space N₃] [add_comm_monoid N₃] [module R N₃]
[distrib_mul_action S₃ M₃] [smul_comm_class R₃ S₃ M₃] [has_continuous_const_smul S₃ M₃]
[distrib_mul_action S N₃] [smul_comm_class R S N₃] [has_continuous_const_smul S N₃]
{σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
include σ₁₃
@[simp] lemma smul_comp (c : S₃) (h : M₂ →SL[σ₂₃] M₃) (f : M →SL[σ₁₂] M₂) :
(c • h).comp f = c • (h.comp f) := rfl
omit σ₁₃
variables [distrib_mul_action S₃ M₂] [has_continuous_const_smul S₃ M₂] [smul_comm_class R₂ S₃ M₂]
variables [distrib_mul_action S N₂] [has_continuous_const_smul S N₂] [smul_comm_class R S N₂]
@[simp] lemma comp_smul [linear_map.compatible_smul N₂ N₃ S R]
(hₗ : N₂ →L[R] N₃) (c : S) (fₗ : M →L[R] N₂) :
hₗ.comp (c • fₗ) = c • (hₗ.comp fₗ) :=
by { ext x, exact hₗ.map_smul_of_tower c (fₗ x) }
include σ₁₃
@[simp] lemma comp_smulₛₗ [smul_comm_class R₂ R₂ M₂] [smul_comm_class R₃ R₃ M₃]
[has_continuous_const_smul R₂ M₂] [has_continuous_const_smul R₃ M₃]
(h : M₂ →SL[σ₂₃] M₃) (c : R₂) (f : M →SL[σ₁₂] M₂) :
h.comp (c • f) = (σ₂₃ c) • (h.comp f) :=
by { ext x, simp only [coe_smul', coe_comp', function.comp_app, pi.smul_apply,
continuous_linear_map.map_smulₛₗ] }
omit σ₁₃
instance [has_continuous_add M₂] : distrib_mul_action S₃ (M →SL[σ₁₂] M₂) :=
{ smul_add := λ a f g, ext $ λ x, smul_add a (f x) (g x),
smul_zero := λ a, ext $ λ x, smul_zero _ }
end smul_monoid
section smul
-- The M's are used for semilinear maps, and the N's for plain linear maps
variables {R R₂ R₃ S S₃ : Type*} [semiring R] [semiring R₂] [semiring R₃]
[semiring S] [semiring S₃]
{M : Type*} [topological_space M] [add_comm_monoid M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [module R₂ M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃] [module R₃ M₃]
{N₂ : Type*} [topological_space N₂] [add_comm_monoid N₂] [module R N₂]
{N₃ : Type*} [topological_space N₃] [add_comm_monoid N₃] [module R N₃]
[module S₃ M₃] [smul_comm_class R₃ S₃ M₃] [has_continuous_const_smul S₃ M₃]
[module S N₂] [has_continuous_const_smul S N₂] [smul_comm_class R S N₂]
[module S N₃] [smul_comm_class R S N₃] [has_continuous_const_smul S N₃]
{σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
(c : S) (h : M₂ →SL[σ₂₃] M₃) (f g : M →SL[σ₁₂] M₂) (x y z : M)
/-- `continuous_linear_map.prod` as an `equiv`. -/
@[simps apply] def prod_equiv : ((M →L[R] N₂) × (M →L[R] N₃)) ≃ (M →L[R] N₂ × N₃) :=
{ to_fun := λ f, f.1.prod f.2,
inv_fun := λ f, ⟨(fst _ _ _).comp f, (snd _ _ _).comp f⟩,
left_inv := λ f, by ext; refl,
right_inv := λ f, by ext; refl }
lemma prod_ext_iff {f g : M × N₂ →L[R] N₃} :
f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) :=
by { simp only [← coe_inj, linear_map.prod_ext_iff], refl }
@[ext] lemma prod_ext {f g : M × N₂ →L[R] N₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _))
(hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g :=
prod_ext_iff.2 ⟨hl, hr⟩
variables [has_continuous_add M₂] [has_continuous_add M₃] [has_continuous_add N₂]
instance : module S₃ (M →SL[σ₁₃] M₃) :=
{ zero_smul := λ _, ext $ λ _, zero_smul _ _,
add_smul := λ _ _ _, ext $ λ _, add_smul _ _ _ }
instance [module S₃ᵐᵒᵖ M₃] [is_central_scalar S₃ M₃] : is_central_scalar S₃ (M →SL[σ₁₃] M₃) :=
{ op_smul_eq_smul := λ _ _, ext $ λ _, op_smul_eq_smul _ _ }
variables (S) [has_continuous_add N₃]
/-- `continuous_linear_map.prod` as a `linear_equiv`. -/
@[simps apply] def prodₗ : ((M →L[R] N₂) × (M →L[R] N₃)) ≃ₗ[S] (M →L[R] N₂ × N₃) :=
{ map_add' := λ f g, rfl,
map_smul' := λ c f, rfl,
.. prod_equiv }
/-- The coercion from `M →L[R] M₂` to `M →ₗ[R] M₂`, as a linear map. -/
@[simps]
def coe_lm : (M →L[R] N₃) →ₗ[S] (M →ₗ[R] N₃) :=
{ to_fun := coe,
map_add' := λ f g, coe_add f g,
map_smul' := λ c f, coe_smul c f }
variables {S} (σ₁₃)
/-- The coercion from `M →SL[σ] M₂` to `M →ₛₗ[σ] M₂`, as a linear map. -/
@[simps]
def coe_lmₛₗ : (M →SL[σ₁₃] M₃) →ₗ[S₃] (M →ₛₗ[σ₁₃] M₃) :=
{ to_fun := coe,
map_add' := λ f g, coe_add f g,
map_smul' := λ c f, coe_smul c f }
variables {σ₁₃}
end smul
section smul_rightₗ
variables {R S T M M₂ : Type*} [semiring R] [semiring S] [semiring T] [module R S]
[add_comm_monoid M₂] [module R M₂] [module S M₂] [is_scalar_tower R S M₂]
[topological_space S] [topological_space M₂] [has_continuous_smul S M₂]
[topological_space M] [add_comm_monoid M] [module R M] [has_continuous_add M₂]
[module T M₂] [has_continuous_const_smul T M₂]
[smul_comm_class R T M₂] [smul_comm_class S T M₂]
/-- Given `c : E →L[𝕜] 𝕜`, `c.smul_rightₗ` is the linear map from `F` to `E →L[𝕜] F`
sending `f` to `λ e, c e • f`. See also `continuous_linear_map.smul_rightL`. -/
def smul_rightₗ (c : M →L[R] S) : M₂ →ₗ[T] (M →L[R] M₂) :=
{ to_fun := c.smul_right,
map_add' := λ x y, by { ext e, apply smul_add },
map_smul' := λ a x, by { ext e, dsimp, apply smul_comm } }
@[simp] lemma coe_smul_rightₗ (c : M →L[R] S) :
⇑(smul_rightₗ c : M₂ →ₗ[T] (M →L[R] M₂)) = c.smul_right := rfl
end smul_rightₗ
section comm_ring
variables
{R : Type*} [comm_ring R]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_group M₃]
[module R M] [module R M₂] [module R M₃] [has_continuous_const_smul R M₃]
variables [topological_add_group M₂] [has_continuous_const_smul R M₂]
instance : algebra R (M₂ →L[R] M₂) :=
algebra.of_module smul_comp (λ _ _ _, comp_smul _ _ _)
end comm_ring
section restrict_scalars
variables {A M M₂ : Type*} [ring A] [add_comm_group M] [add_comm_group M₂]
[module A M] [module A M₂] [topological_space M] [topological_space M₂]
(R : Type*) [ring R] [module R M] [module R M₂] [linear_map.compatible_smul M M₂ R A]
/-- If `A` is an `R`-algebra, then a continuous `A`-linear map can be interpreted as a continuous
`R`-linear map. We assume `linear_map.compatible_smul M M₂ R A` to match assumptions of
`linear_map.map_smul_of_tower`. -/
def restrict_scalars (f : M →L[A] M₂) : M →L[R] M₂ :=
⟨(f : M →ₗ[A] M₂).restrict_scalars R, f.continuous⟩
variable {R}
@[simp, norm_cast] lemma coe_restrict_scalars (f : M →L[A] M₂) :
(f.restrict_scalars R : M →ₗ[R] M₂) = (f : M →ₗ[A] M₂).restrict_scalars R := rfl
@[simp] lemma coe_restrict_scalars' (f : M →L[A] M₂) : ⇑(f.restrict_scalars R) = f := rfl
@[simp] lemma restrict_scalars_zero : (0 : M →L[A] M₂).restrict_scalars R = 0 := rfl
section
variable [topological_add_group M₂]
@[simp] lemma restrict_scalars_add (f g : M →L[A] M₂) :
(f + g).restrict_scalars R = f.restrict_scalars R + g.restrict_scalars R := rfl
@[simp] lemma restrict_scalars_neg (f : M →L[A] M₂) :
(-f).restrict_scalars R = -f.restrict_scalars R := rfl
end
variables {S : Type*} [ring S] [module S M₂] [has_continuous_const_smul S M₂]
[smul_comm_class A S M₂] [smul_comm_class R S M₂]
@[simp] lemma restrict_scalars_smul (c : S) (f : M →L[A] M₂) :
(c • f).restrict_scalars R = c • f.restrict_scalars R := rfl
variables (A M M₂ R S) [topological_add_group M₂]
/-- `continuous_linear_map.restrict_scalars` as a `linear_map`. See also
`continuous_linear_map.restrict_scalarsL`. -/
def restrict_scalarsₗ : (M →L[A] M₂) →ₗ[S] (M →L[R] M₂) :=
{ to_fun := restrict_scalars R,
map_add' := restrict_scalars_add,
map_smul' := restrict_scalars_smul }
variables {A M M₂ R S}
@[simp] lemma coe_restrict_scalarsₗ : ⇑(restrict_scalarsₗ A M M₂ R S) = restrict_scalars R := rfl
end restrict_scalars
end continuous_linear_map
namespace continuous_linear_equiv
section add_comm_monoid
variables {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} [semiring R₁] [semiring R₂] [semiring R₃]
{σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} [ring_hom_inv_pair σ₂₃ σ₃₂] [ring_hom_inv_pair σ₃₂ σ₂₃]
{σ₁₃ : R₁ →+* R₃} {σ₃₁ : R₃ →+* R₁} [ring_hom_inv_pair σ₁₃ σ₃₁] [ring_hom_inv_pair σ₃₁ σ₁₃]
[ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [ring_hom_comp_triple σ₃₂ σ₂₁ σ₃₁]
{M₁ : Type*} [topological_space M₁] [add_comm_monoid M₁]
{M'₁ : Type*} [topological_space M'₁] [add_comm_monoid M'₁]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_monoid M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_monoid M₄]
[module R₁ M₁] [module R₁ M'₁] [module R₂ M₂] [module R₃ M₃]
include σ₂₁
/-- A continuous linear equivalence induces a continuous linear map. -/
def to_continuous_linear_map (e : M₁ ≃SL[σ₁₂] M₂) : M₁ →SL[σ₁₂] M₂ :=
{ cont := e.continuous_to_fun,
..e.to_linear_equiv.to_linear_map }
/-- Coerce continuous linear equivs to continuous linear maps. -/
instance : has_coe (M₁ ≃SL[σ₁₂] M₂) (M₁ →SL[σ₁₂] M₂) := ⟨to_continuous_linear_map⟩
instance : continuous_semilinear_equiv_class (M₁ ≃SL[σ₁₂] M₂) σ₁₂ M₁ M₂ :=
{ coe := λ f, f,
inv := λ f, f.inv_fun,
coe_injective' := λ f g h₁ h₂, by { cases f with f' _, cases g with g' _, cases f', cases g',
congr' },
left_inv := λ f, f.left_inv,
right_inv := λ f, f.right_inv,
map_add := λ f, f.map_add',
map_smulₛₗ := λ f, f.map_smul',
map_continuous := continuous_to_fun,
inv_continuous := continuous_inv_fun }
/-- Coerce continuous linear equivs to maps. -/
-- see Note [function coercion]
instance : has_coe_to_fun (M₁ ≃SL[σ₁₂] M₂) (λ _, M₁ → M₂) := ⟨λ f, f⟩
@[simp] theorem coe_def_rev (e : M₁ ≃SL[σ₁₂] M₂) : e.to_continuous_linear_map = e := rfl
theorem coe_apply (e : M₁ ≃SL[σ₁₂] M₂) (b : M₁) : (e : M₁ →SL[σ₁₂] M₂) b = e b := rfl
@[simp] lemma coe_to_linear_equiv (f : M₁ ≃SL[σ₁₂] M₂) : ⇑f.to_linear_equiv = f := rfl
@[simp, norm_cast] lemma coe_coe (e : M₁ ≃SL[σ₁₂] M₂) : ⇑(e : M₁ →SL[σ₁₂] M₂) = e := rfl
lemma to_linear_equiv_injective :
function.injective (to_linear_equiv : (M₁ ≃SL[σ₁₂] M₂) → (M₁ ≃ₛₗ[σ₁₂] M₂))
| ⟨e, _, _⟩ ⟨e', _, _⟩ rfl := rfl
@[ext] lemma ext {f g : M₁ ≃SL[σ₁₂] M₂} (h : (f : M₁ → M₂) = g) : f = g :=
to_linear_equiv_injective $ linear_equiv.ext $ congr_fun h
lemma coe_injective : function.injective (coe : (M₁ ≃SL[σ₁₂] M₂) → (M₁ →SL[σ₁₂] M₂)) :=
λ e e' h, ext $ funext $ continuous_linear_map.ext_iff.1 h
@[simp, norm_cast] lemma coe_inj {e e' : M₁ ≃SL[σ₁₂] M₂} : (e : M₁ →SL[σ₁₂] M₂) = e' ↔ e = e' :=
coe_injective.eq_iff
/-- A continuous linear equivalence induces a homeomorphism. -/
def to_homeomorph (e : M₁ ≃SL[σ₁₂] M₂) : M₁ ≃ₜ M₂ := { to_equiv := e.to_linear_equiv.to_equiv, ..e }
@[simp] lemma coe_to_homeomorph (e : M₁ ≃SL[σ₁₂] M₂) : ⇑e.to_homeomorph = e := rfl
lemma image_closure (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) : e '' closure s = closure (e '' s) :=
e.to_homeomorph.image_closure s
lemma preimage_closure (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) : e ⁻¹' closure s = closure (e ⁻¹' s) :=
e.to_homeomorph.preimage_closure s
@[simp] lemma is_closed_image (e : M₁ ≃SL[σ₁₂] M₂) {s : set M₁} :
is_closed (e '' s) ↔ is_closed s :=
e.to_homeomorph.is_closed_image
lemma map_nhds_eq (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : map e (𝓝 x) = 𝓝 (e x) :=
e.to_homeomorph.map_nhds_eq x
-- Make some straightforward lemmas available to `simp`.
@[simp] lemma map_zero (e : M₁ ≃SL[σ₁₂] M₂) : e (0 : M₁) = 0 := (e : M₁ →SL[σ₁₂] M₂).map_zero
@[simp] lemma map_add (e : M₁ ≃SL[σ₁₂] M₂) (x y : M₁) : e (x + y) = e x + e y :=
(e : M₁ →SL[σ₁₂] M₂).map_add x y
@[simp] lemma map_smulₛₗ (e : M₁ ≃SL[σ₁₂] M₂) (c : R₁) (x : M₁) : e (c • x) = σ₁₂ c • (e x) :=
(e : M₁ →SL[σ₁₂] M₂).map_smulₛₗ c x
omit σ₂₁
@[simp] lemma map_smul [module R₁ M₂] (e : M₁ ≃L[R₁] M₂) (c : R₁) (x : M₁) :
e (c • x) = c • (e x) :=
(e : M₁ →L[R₁] M₂).map_smul c x
include σ₂₁
@[simp] lemma map_eq_zero_iff (e : M₁ ≃SL[σ₁₂] M₂) {x : M₁} : e x = 0 ↔ x = 0 :=
e.to_linear_equiv.map_eq_zero_iff
attribute [continuity]
continuous_linear_equiv.continuous_to_fun continuous_linear_equiv.continuous_inv_fun
@[continuity]
protected lemma continuous (e : M₁ ≃SL[σ₁₂] M₂) : continuous (e : M₁ → M₂) :=
e.continuous_to_fun
protected lemma continuous_on (e : M₁ ≃SL[σ₁₂] M₂) {s : set M₁} : continuous_on (e : M₁ → M₂) s :=
e.continuous.continuous_on
protected lemma continuous_at (e : M₁ ≃SL[σ₁₂] M₂) {x : M₁} : continuous_at (e : M₁ → M₂) x :=
e.continuous.continuous_at
protected lemma continuous_within_at (e : M₁ ≃SL[σ₁₂] M₂) {s : set M₁} {x : M₁} :
continuous_within_at (e : M₁ → M₂) s x :=
e.continuous.continuous_within_at
lemma comp_continuous_on_iff
{α : Type*} [topological_space α] (e : M₁ ≃SL[σ₁₂] M₂) {f : α → M₁} {s : set α} :
continuous_on (e ∘ f) s ↔ continuous_on f s :=
e.to_homeomorph.comp_continuous_on_iff _ _
lemma comp_continuous_iff
{α : Type*} [topological_space α] (e : M₁ ≃SL[σ₁₂] M₂) {f : α → M₁} :
continuous (e ∘ f) ↔ continuous f :=
e.to_homeomorph.comp_continuous_iff
omit σ₂₁
/-- An extensionality lemma for `R ≃L[R] M`. -/
lemma ext₁ [topological_space R₁] {f g : R₁ ≃L[R₁] M₁} (h : f 1 = g 1) : f = g :=
ext $ funext $ λ x, mul_one x ▸ by rw [← smul_eq_mul, map_smul, h, map_smul]
section
variables (R₁ M₁)
/-- The identity map as a continuous linear equivalence. -/
@[refl] protected def refl : M₁ ≃L[R₁] M₁ :=
{ continuous_to_fun := continuous_id,
continuous_inv_fun := continuous_id,
.. linear_equiv.refl R₁ M₁ }
end
@[simp, norm_cast] lemma coe_refl :
↑(continuous_linear_equiv.refl R₁ M₁) = continuous_linear_map.id R₁ M₁ := rfl
@[simp, norm_cast] lemma coe_refl' : ⇑(continuous_linear_equiv.refl R₁ M₁) = id := rfl
/-- The inverse of a continuous linear equivalence as a continuous linear equivalence-/
@[symm] protected def symm (e : M₁ ≃SL[σ₁₂] M₂) : M₂ ≃SL[σ₂₁] M₁ :=
{ continuous_to_fun := e.continuous_inv_fun,
continuous_inv_fun := e.continuous_to_fun,
.. e.to_linear_equiv.symm }
include σ₂₁
@[simp] lemma symm_to_linear_equiv (e : M₁ ≃SL[σ₁₂] M₂) :
e.symm.to_linear_equiv = e.to_linear_equiv.symm :=
by { ext, refl }
@[simp] lemma symm_to_homeomorph (e : M₁ ≃SL[σ₁₂] M₂) :
e.to_homeomorph.symm = e.symm.to_homeomorph :=
rfl
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : M₁ ≃SL[σ₁₂] M₂) : M₁ → M₂ := h
/-- See Note [custom simps projection] -/
def simps.symm_apply (h : M₁ ≃SL[σ₁₂] M₂) : M₂ → M₁ := h.symm
initialize_simps_projections continuous_linear_equiv
(to_linear_equiv_to_fun → apply, to_linear_equiv_inv_fun → symm_apply)
lemma symm_map_nhds_eq (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : map e.symm (𝓝 (e x)) = 𝓝 x :=
e.to_homeomorph.symm_map_nhds_eq x
omit σ₂₁
include σ₂₁ σ₃₂ σ₃₁
/-- The composition of two continuous linear equivalences as a continuous linear equivalence. -/
@[trans] protected def trans (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) : M₁ ≃SL[σ₁₃] M₃ :=
{ continuous_to_fun := e₂.continuous_to_fun.comp e₁.continuous_to_fun,
continuous_inv_fun := e₁.continuous_inv_fun.comp e₂.continuous_inv_fun,
.. e₁.to_linear_equiv.trans e₂.to_linear_equiv }
include σ₁₃
@[simp] lemma trans_to_linear_equiv (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) :
(e₁.trans e₂).to_linear_equiv = e₁.to_linear_equiv.trans e₂.to_linear_equiv :=
by { ext, refl }
omit σ₁₃ σ₂₁ σ₃₂ σ₃₁
/-- Product of two continuous linear equivalences. The map comes from `equiv.prod_congr`. -/
def prod [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (e : M₁ ≃L[R₁] M₂) (e' : M₃ ≃L[R₁] M₄) :
(M₁ × M₃) ≃L[R₁] (M₂ × M₄) :=
{ continuous_to_fun := e.continuous_to_fun.prod_map e'.continuous_to_fun,
continuous_inv_fun := e.continuous_inv_fun.prod_map e'.continuous_inv_fun,
.. e.to_linear_equiv.prod e'.to_linear_equiv }
@[simp, norm_cast] lemma prod_apply [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (e : M₁ ≃L[R₁] M₂)
(e' : M₃ ≃L[R₁] M₄) (x) :
e.prod e' x = (e x.1, e' x.2) := rfl
@[simp, norm_cast] lemma coe_prod [module R₁ M₂] [module R₁ M₃] [module R₁ M₄] (e : M₁ ≃L[R₁] M₂)
(e' : M₃ ≃L[R₁] M₄) :
(e.prod e' : (M₁ × M₃) →L[R₁] (M₂ × M₄)) = (e : M₁ →L[R₁] M₂).prod_map (e' : M₃ →L[R₁] M₄) :=
rfl
lemma prod_symm [module R₁ M₂] [module R₁ M₃] [module R₁ M₄]
(e : M₁ ≃L[R₁] M₂) (e' : M₃ ≃L[R₁] M₄) :
(e.prod e').symm = e.symm.prod e'.symm :=
rfl
include σ₂₁
protected theorem bijective (e : M₁ ≃SL[σ₁₂] M₂) : function.bijective e :=
e.to_linear_equiv.to_equiv.bijective
protected theorem injective (e : M₁ ≃SL[σ₁₂] M₂) : function.injective e :=
e.to_linear_equiv.to_equiv.injective
protected theorem surjective (e : M₁ ≃SL[σ₁₂] M₂) : function.surjective e :=
e.to_linear_equiv.to_equiv.surjective
include σ₃₂ σ₃₁ σ₁₃
@[simp] theorem trans_apply (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) (c : M₁) :
(e₁.trans e₂) c = e₂ (e₁ c) :=
rfl
omit σ₃₂ σ₃₁ σ₁₃
@[simp] theorem apply_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) (c : M₂) : e (e.symm c) = c :=
e.1.right_inv c
@[simp] theorem symm_apply_apply (e : M₁ ≃SL[σ₁₂] M₂) (b : M₁) : e.symm (e b) = b := e.1.left_inv b
include σ₁₂ σ₂₃ σ₁₃ σ₃₁
@[simp] theorem symm_trans_apply (e₁ : M₂ ≃SL[σ₂₁] M₁) (e₂ : M₃ ≃SL[σ₃₂] M₂) (c : M₁) :
(e₂.trans e₁).symm c = e₂.symm (e₁.symm c) :=
rfl
omit σ₁₂ σ₂₃ σ₁₃ σ₃₁
@[simp] theorem symm_image_image (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) : e.symm '' (e '' s) = s :=
e.to_linear_equiv.to_equiv.symm_image_image s
@[simp] theorem image_symm_image (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image s
include σ₃₂ σ₃₁
@[simp, norm_cast]
lemma comp_coe (f : M₁ ≃SL[σ₁₂] M₂) (f' : M₂ ≃SL[σ₂₃] M₃) :
(f' : M₂ →SL[σ₂₃] M₃).comp (f : M₁ →SL[σ₁₂] M₂) = (f.trans f' : M₁ →SL[σ₁₃] M₃) :=
rfl
omit σ₃₂ σ₃₁ σ₂₁
@[simp] theorem coe_comp_coe_symm (e : M₁ ≃SL[σ₁₂] M₂) :
(e : M₁ →SL[σ₁₂] M₂).comp (e.symm : M₂ →SL[σ₂₁] M₁) = continuous_linear_map.id R₂ M₂ :=
continuous_linear_map.ext e.apply_symm_apply
@[simp] theorem coe_symm_comp_coe (e : M₁ ≃SL[σ₁₂] M₂) :
(e.symm : M₂ →SL[σ₂₁] M₁).comp (e : M₁ →SL[σ₁₂] M₂) = continuous_linear_map.id R₁ M₁ :=
continuous_linear_map.ext e.symm_apply_apply
include σ₂₁
@[simp] lemma symm_comp_self (e : M₁ ≃SL[σ₁₂] M₂) :
(e.symm : M₂ → M₁) ∘ (e : M₁ → M₂) = id :=
by{ ext x, exact symm_apply_apply e x }
@[simp] lemma self_comp_symm (e : M₁ ≃SL[σ₁₂] M₂) :
(e : M₁ → M₂) ∘ (e.symm : M₂ → M₁) = id :=
by{ ext x, exact apply_symm_apply e x }
@[simp] theorem symm_symm (e : M₁ ≃SL[σ₁₂] M₂) : e.symm.symm = e :=
by { ext x, refl }
omit σ₂₁
@[simp] lemma refl_symm :
(continuous_linear_equiv.refl R₁ M₁).symm = continuous_linear_equiv.refl R₁ M₁ :=
rfl
include σ₂₁
theorem symm_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : e.symm.symm x = e x :=
rfl
lemma symm_apply_eq (e : M₁ ≃SL[σ₁₂] M₂) {x y} : e.symm x = y ↔ x = e y :=
e.to_linear_equiv.symm_apply_eq
lemma eq_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) {x y} : y = e.symm x ↔ e y = x :=
e.to_linear_equiv.eq_symm_apply
protected lemma image_eq_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) : e '' s = e.symm ⁻¹' s :=
e.to_linear_equiv.to_equiv.image_eq_preimage s
protected lemma image_symm_eq_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) : e.symm '' s = e ⁻¹' s :=
by rw [e.symm.image_eq_preimage, e.symm_symm]
@[simp] protected lemma symm_preimage_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₂) :
e.symm ⁻¹' (e ⁻¹' s) = s := e.to_linear_equiv.to_equiv.symm_preimage_preimage s
@[simp] protected lemma preimage_symm_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : set M₁) :
e ⁻¹' (e.symm ⁻¹' s) = s := e.symm.symm_preimage_preimage s
protected lemma uniform_embedding {E₁ E₂ : Type*} [uniform_space E₁] [uniform_space E₂]
[add_comm_group E₁] [add_comm_group E₂] [module R₁ E₁] [module R₂ E₂]
[uniform_add_group E₁] [uniform_add_group E₂]
(e : E₁ ≃SL[σ₁₂] E₂) :
uniform_embedding e :=
e.to_linear_equiv.to_equiv.uniform_embedding
e.to_continuous_linear_map.uniform_continuous
e.symm.to_continuous_linear_map.uniform_continuous
protected lemma _root_.linear_equiv.uniform_embedding {E₁ E₂ : Type*} [uniform_space E₁]
[uniform_space E₂] [add_comm_group E₁] [add_comm_group E₂] [module R₁ E₁] [module R₂ E₂]
[uniform_add_group E₁] [uniform_add_group E₂]
(e : E₁ ≃ₛₗ[σ₁₂] E₂) (h₁ : continuous e) (h₂ : continuous e.symm) :
uniform_embedding e :=
continuous_linear_equiv.uniform_embedding
({ continuous_to_fun := h₁,
continuous_inv_fun := h₂,
.. e } : E₁ ≃SL[σ₁₂] E₂)
omit σ₂₁
/-- Create a `continuous_linear_equiv` from two `continuous_linear_map`s that are
inverse of each other. -/
def equiv_of_inverse (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M₁) (h₁ : function.left_inverse f₂ f₁)
(h₂ : function.right_inverse f₂ f₁) :
M₁ ≃SL[σ₁₂] M₂ :=
{ to_fun := f₁,
continuous_to_fun := f₁.continuous,
inv_fun := f₂,
continuous_inv_fun := f₂.continuous,
left_inv := h₁,
right_inv := h₂,
.. f₁ }
include σ₂₁
@[simp] lemma equiv_of_inverse_apply (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂ x) :
equiv_of_inverse f₁ f₂ h₁ h₂ x = f₁ x :=
rfl
@[simp] lemma symm_equiv_of_inverse (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂) :
(equiv_of_inverse f₁ f₂ h₁ h₂).symm = equiv_of_inverse f₂ f₁ h₂ h₁ :=
rfl
omit σ₂₁
variable (M₁)
/-- The continuous linear equivalences from `M` to itself form a group under composition. -/
instance automorphism_group : group (M₁ ≃L[R₁] M₁) :=
{ mul := λ f g, g.trans f,
one := continuous_linear_equiv.refl R₁ M₁,
inv := λ f, f.symm,
mul_assoc := λ f g h, by {ext, refl},
mul_one := λ f, by {ext, refl},
one_mul := λ f, by {ext, refl},
mul_left_inv := λ f, by {ext, exact f.left_inv x} }
variables {M₁} {R₄ : Type*} [semiring R₄] [module R₄ M₄]
{σ₃₄ : R₃ →+* R₄} {σ₄₃ : R₄ →+* R₃} [ring_hom_inv_pair σ₃₄ σ₄₃] [ring_hom_inv_pair σ₄₃ σ₃₄]
{σ₂₄ : R₂ →+* R₄} {σ₁₄ : R₁ →+* R₄}
[ring_hom_comp_triple σ₂₁ σ₁₄ σ₂₄] [ring_hom_comp_triple σ₂₄ σ₄₃ σ₂₃]
[ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄]
/-- The continuous linear equivalence between `ulift M₁` and `M₁`. -/
def ulift : ulift M₁ ≃L[R₁] M₁ :=
{ map_add' := λ x y, rfl,
map_smul' := λ c x, rfl,
continuous_to_fun := continuous_ulift_down,
continuous_inv_fun := continuous_ulift_up,
.. equiv.ulift }
include σ₂₁ σ₃₄ σ₂₃ σ₂₄ σ₁₃
/-- A pair of continuous (semi)linear equivalences generates an equivalence between the spaces of
continuous linear maps. See also `continuous_linear_equiv.arrow_congr`. -/
@[simps] def arrow_congr_equiv (e₁₂ : M₁ ≃SL[σ₁₂] M₂) (e₄₃ : M₄ ≃SL[σ₄₃] M₃) :
(M₁ →SL[σ₁₄] M₄) ≃ (M₂ →SL[σ₂₃] M₃) :=
{ to_fun := λ f, (e₄₃ : M₄ →SL[σ₄₃] M₃).comp (f.comp (e₁₂.symm : M₂ →SL[σ₂₁] M₁)),
inv_fun := λ f, (e₄₃.symm : M₃ →SL[σ₃₄] M₄).comp (f.comp (e₁₂ : M₁ →SL[σ₁₂] M₂)),
left_inv := λ f, continuous_linear_map.ext $ λ x,
by simp only [continuous_linear_map.comp_apply, symm_apply_apply, coe_coe],
right_inv := λ f, continuous_linear_map.ext $ λ x,
by simp only [continuous_linear_map.comp_apply, apply_symm_apply, coe_coe] }
end add_comm_monoid
section add_comm_group
variables {R : Type*} [semiring R]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂]
{M₃ : Type*} [topological_space M₃] [add_comm_group M₃]
{M₄ : Type*} [topological_space M₄] [add_comm_group M₄]
[module R M] [module R M₂] [module R M₃] [module R M₄]
variables [topological_add_group M₄]
/-- Equivalence given by a block lower diagonal matrix. `e` and `e'` are diagonal square blocks,
and `f` is a rectangular block below the diagonal. -/
def skew_prod (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[R] M₄) :
(M × M₃) ≃L[R] M₂ × M₄ :=
{ continuous_to_fun := (e.continuous_to_fun.comp continuous_fst).prod_mk
((e'.continuous_to_fun.comp continuous_snd).add $ f.continuous.comp continuous_fst),
continuous_inv_fun := (e.continuous_inv_fun.comp continuous_fst).prod_mk
(e'.continuous_inv_fun.comp $ continuous_snd.sub $ f.continuous.comp $
e.continuous_inv_fun.comp continuous_fst),
.. e.to_linear_equiv.skew_prod e'.to_linear_equiv ↑f }
@[simp] lemma skew_prod_apply (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[R] M₄) (x) :
e.skew_prod e' f x = (e x.1, e' x.2 + f x.1) := rfl
@[simp] lemma skew_prod_symm_apply (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[R] M₄) (x) :
(e.skew_prod e' f).symm x = (e.symm x.1, e'.symm (x.2 - f (e.symm x.1))) := rfl
end add_comm_group
section ring
variables {R : Type*} [ring R] {R₂ : Type*} [ring R₂]
{M : Type*} [topological_space M] [add_comm_group M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂] [module R₂ M₂]
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
include σ₂₁
@[simp] lemma map_sub (e : M ≃SL[σ₁₂] M₂) (x y : M) : e (x - y) = e x - e y :=
(e : M →SL[σ₁₂] M₂).map_sub x y
@[simp] lemma map_neg (e : M ≃SL[σ₁₂] M₂) (x : M) : e (-x) = -e x := (e : M →SL[σ₁₂] M₂).map_neg x
omit σ₂₁
section
/-! The next theorems cover the identification between `M ≃L[𝕜] M`and the group of units of the ring
`M →L[R] M`. -/
variables [topological_add_group M]
/-- An invertible continuous linear map `f` determines a continuous equivalence from `M` to itself.
-/
def of_unit (f : (M →L[R] M)ˣ) : (M ≃L[R] M) :=
{ to_linear_equiv :=
{ to_fun := f.val,
map_add' := by simp,
map_smul' := by simp,
inv_fun := f.inv,
left_inv := λ x, show (f.inv * f.val) x = x, by {rw f.inv_val, simp},
right_inv := λ x, show (f.val * f.inv) x = x, by {rw f.val_inv, simp}, },
continuous_to_fun := f.val.continuous,
continuous_inv_fun := f.inv.continuous }
/-- A continuous equivalence from `M` to itself determines an invertible continuous linear map. -/
def to_unit (f : (M ≃L[R] M)) : (M →L[R] M)ˣ :=
{ val := f,
inv := f.symm,
val_inv := by {ext, simp},
inv_val := by {ext, simp} }
variables (R M)
/-- The units of the algebra of continuous `R`-linear endomorphisms of `M` is multiplicatively
equivalent to the type of continuous linear equivalences between `M` and itself. -/
def units_equiv : (M →L[R] M)ˣ ≃* (M ≃L[R] M) :=
{ to_fun := of_unit,
inv_fun := to_unit,
left_inv := λ f, by {ext, refl},
right_inv := λ f, by {ext, refl},
map_mul' := λ x y, by {ext, refl} }
@[simp] lemma units_equiv_apply (f : (M →L[R] M)ˣ) (x : M) :
units_equiv R M f x = f x := rfl
end
section
variables (R) [topological_space R] [has_continuous_mul R]
/-- Continuous linear equivalences `R ≃L[R] R` are enumerated by `Rˣ`. -/
def units_equiv_aut : Rˣ ≃ (R ≃L[R] R) :=
{ to_fun := λ u, equiv_of_inverse
(continuous_linear_map.smul_right (1 : R →L[R] R) ↑u)
(continuous_linear_map.smul_right (1 : R →L[R] R) ↑u⁻¹)
(λ x, by simp) (λ x, by simp),
inv_fun := λ e, ⟨e 1, e.symm 1,
by rw [← smul_eq_mul, ← map_smul, smul_eq_mul, mul_one, symm_apply_apply],
by rw [← smul_eq_mul, ← map_smul, smul_eq_mul, mul_one, apply_symm_apply]⟩,
left_inv := λ u, units.ext $ by simp,
right_inv := λ e, ext₁ $ by simp }
variable {R}
@[simp] lemma units_equiv_aut_apply (u : Rˣ) (x : R) : units_equiv_aut R u x = x * u := rfl
@[simp] lemma units_equiv_aut_apply_symm (u : Rˣ) (x : R) :
(units_equiv_aut R u).symm x = x * ↑u⁻¹ := rfl
@[simp] lemma units_equiv_aut_symm_apply (e : R ≃L[R] R) :
↑((units_equiv_aut R).symm e) = e 1 :=
rfl
end
variables [module R M₂] [topological_add_group M]
open _root_.continuous_linear_map (id fst snd)
open _root_.linear_map (mem_ker)
/-- A pair of continuous linear maps such that `f₁ ∘ f₂ = id` generates a continuous
linear equivalence `e` between `M` and `M₂ × f₁.ker` such that `(e x).2 = x` for `x ∈ f₁.ker`,
`(e x).1 = f₁ x`, and `(e (f₂ y)).2 = 0`. The map is given by `e x = (f₁ x, x - f₂ (f₁ x))`. -/
def equiv_of_right_inverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M) (h : function.right_inverse f₂ f₁) :
M ≃L[R] M₂ × ker f₁:=
equiv_of_inverse (f₁.prod (f₁.proj_ker_of_right_inverse f₂ h)) (f₂.coprod (ker f₁).subtypeL)
(λ x, by simp)
(λ ⟨x, y⟩, by simp [h x])
@[simp] lemma fst_equiv_of_right_inverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) (x : M) :
(equiv_of_right_inverse f₁ f₂ h x).1 = f₁ x := rfl
@[simp] lemma snd_equiv_of_right_inverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) (x : M) :
((equiv_of_right_inverse f₁ f₂ h x).2 : M) = x - f₂ (f₁ x) := rfl
@[simp] lemma equiv_of_right_inverse_symm_apply (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) (y : M₂ × ker f₁) :
(equiv_of_right_inverse f₁ f₂ h).symm y = f₂ y.1 + y.2 := rfl
end ring
section
variables (ι R M : Type*) [unique ι] [semiring R] [add_comm_monoid M] [module R M]
[topological_space M]
/-- If `ι` has a unique element, then `ι → M` is continuously linear equivalent to `M`. -/
def fun_unique : (ι → M) ≃L[R] M :=
{ to_linear_equiv := linear_equiv.fun_unique ι R M,
.. homeomorph.fun_unique ι M }
variables {ι R M}
@[simp] lemma coe_fun_unique : ⇑(fun_unique ι R M) = function.eval default := rfl
@[simp] lemma coe_fun_unique_symm : ⇑(fun_unique ι R M).symm = function.const ι := rfl
variables (R M)
/-- Continuous linear equivalence between dependent functions `Π i : fin 2, M i` and `M 0 × M 1`. -/
@[simps { fully_applied := ff }]
def pi_fin_two (M : fin 2 → Type*) [Π i, add_comm_monoid (M i)] [Π i, module R (M i)]
[Π i, topological_space (M i)] :
(Π i, M i) ≃L[R] M 0 × M 1 :=
{ to_linear_equiv := linear_equiv.pi_fin_two R M, .. homeomorph.pi_fin_two M }
/-- Continuous linear equivalence between vectors in `M² = fin 2 → M` and `M × M`. -/
@[simps { fully_applied := ff }]
def fin_two_arrow : (fin 2 → M) ≃L[R] M × M :=
{ to_linear_equiv := linear_equiv.fin_two_arrow R M, .. pi_fin_two R (λ _, M) }
end
end continuous_linear_equiv
namespace continuous_linear_map
open_locale classical
variables {R : Type*} {M : Type*} {M₂ : Type*} [topological_space M] [topological_space M₂]
section
variables [semiring R]
variables [add_comm_monoid M₂] [module R M₂]
variables [add_comm_monoid M] [module R M]
/-- Introduce a function `inverse` from `M →L[R] M₂` to `M₂ →L[R] M`, which sends `f` to `f.symm` if
`f` is a continuous linear equivalence and to `0` otherwise. This definition is somewhat ad hoc,
but one needs a fully (rather than partially) defined inverse function for some purposes, including
for calculus. -/
noncomputable def inverse : (M →L[R] M₂) → (M₂ →L[R] M) :=
λ f, if h : ∃ (e : M ≃L[R] M₂), (e : M →L[R] M₂) = f then ((classical.some h).symm : M₂ →L[R] M)
else 0
/-- By definition, if `f` is invertible then `inverse f = f.symm`. -/
@[simp] lemma inverse_equiv (e : M ≃L[R] M₂) : inverse (e : M →L[R] M₂) = e.symm :=
begin
have h : ∃ (e' : M ≃L[R] M₂), (e' : M →L[R] M₂) = ↑e := ⟨e, rfl⟩,
simp only [inverse, dif_pos h],
congr,
exact_mod_cast (classical.some_spec h)
end
/-- By definition, if `f` is not invertible then `inverse f = 0`. -/
@[simp] lemma inverse_non_equiv (f : M →L[R] M₂) (h : ¬∃ (e' : M ≃L[R] M₂), ↑e' = f) :
inverse f = 0 :=
dif_neg h
end
section
variables [ring R]
variables [add_comm_group M] [topological_add_group M] [module R M]
variables [add_comm_group M₂] [module R M₂]
@[simp] lemma ring_inverse_equiv (e : M ≃L[R] M) :
ring.inverse ↑e = inverse (e : M →L[R] M) :=
begin
suffices :
ring.inverse ((((continuous_linear_equiv.units_equiv _ _).symm e) : M →L[R] M)) = inverse ↑e,
{ convert this },
simp,
refl,
end
/-- The function `continuous_linear_equiv.inverse` can be written in terms of `ring.inverse` for the
ring of self-maps of the domain. -/
lemma to_ring_inverse (e : M ≃L[R] M₂) (f : M →L[R] M₂) :
inverse f = (ring.inverse ((e.symm : (M₂ →L[R] M)).comp f)) ∘L ↑e.symm :=
begin
by_cases h₁ : ∃ (e' : M ≃L[R] M₂), ↑e' = f,
{ obtain ⟨e', he'⟩ := h₁,
rw ← he',
change _ = (ring.inverse ↑(e'.trans e.symm)) ∘L ↑e.symm,
ext,
simp },
{ suffices : ¬is_unit ((e.symm : M₂ →L[R] M).comp f),
{ simp [this, h₁] },
contrapose! h₁,
rcases h₁ with ⟨F, hF⟩,
use (continuous_linear_equiv.units_equiv _ _ F).trans e,
ext,
dsimp, rw [coe_fn_coe_base' F, hF], simp }
end
lemma ring_inverse_eq_map_inverse : ring.inverse = @inverse R M M _ _ _ _ _ _ _ :=
begin
ext,
simp [to_ring_inverse (continuous_linear_equiv.refl R M)],
end
end
end continuous_linear_map
namespace submodule
variables
{R : Type*} [ring R]
{M : Type*} [topological_space M] [add_comm_group M] [module R M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂] [module R M₂]
open continuous_linear_map
/-- A submodule `p` is called *complemented* if there exists a continuous projection `M →ₗ[R] p`. -/
def closed_complemented (p : submodule R M) : Prop := ∃ f : M →L[R] p, ∀ x : p, f x = x
lemma closed_complemented.has_closed_complement {p : submodule R M} [t1_space p]
(h : closed_complemented p) :
∃ (q : submodule R M) (hq : is_closed (q : set M)), is_compl p q :=
exists.elim h $ λ f hf, ⟨ker f, f.is_closed_ker, linear_map.is_compl_of_proj hf⟩
protected lemma closed_complemented.is_closed [topological_add_group M] [t1_space M]
{p : submodule R M} (h : closed_complemented p) :
is_closed (p : set M) :=
begin
rcases h with ⟨f, hf⟩,
have : ker (id R M - p.subtypeL.comp f) = p := linear_map.ker_id_sub_eq_of_proj hf,
exact this ▸ (is_closed_ker _)
end
@[simp] lemma closed_complemented_bot : closed_complemented (⊥ : submodule R M) :=
⟨0, λ x, by simp only [zero_apply, eq_zero_of_bot_submodule x]⟩
@[simp] lemma closed_complemented_top : closed_complemented (⊤ : submodule R M) :=
⟨(id R M).cod_restrict ⊤ (λ x, trivial), λ x, subtype.ext_iff_val.2 $ by simp⟩
end submodule
lemma continuous_linear_map.closed_complemented_ker_of_right_inverse {R : Type*} [ring R]
{M : Type*} [topological_space M] [add_comm_group M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂] [module R M] [module R M₂]
[topological_add_group M] (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) :
(ker f₁).closed_complemented :=
⟨f₁.proj_ker_of_right_inverse f₂ h, f₁.proj_ker_of_right_inverse_apply_idem f₂ h⟩
section quotient
namespace submodule
variables {R M : Type*} [ring R] [add_comm_group M] [module R M] [topological_space M]
(S : submodule R M)
lemma is_open_map_mkq [topological_add_group M] : is_open_map S.mkq :=
quotient_add_group.is_open_map_coe S.to_add_subgroup
instance topological_add_group_quotient [topological_add_group M] :
topological_add_group (M ⧸ S) :=
topological_add_group_quotient S.to_add_subgroup
instance has_continuous_smul_quotient [topological_space R] [topological_add_group M]
[has_continuous_smul R M] :
has_continuous_smul R (M ⧸ S) :=
begin
split,
have quot : quotient_map (λ au : R × M, (au.1, S.mkq au.2)),
from is_open_map.to_quotient_map
(is_open_map.id.prod S.is_open_map_mkq)
(continuous_id.prod_map continuous_quot_mk)
(function.surjective_id.prod_map $ surjective_quot_mk _),
rw quot.continuous_iff,
exact continuous_quot_mk.comp continuous_smul
end
instance t3_quotient_of_is_closed [topological_add_group M] [is_closed (S : set M)] :
t3_space (M ⧸ S) :=
begin
letI : is_closed (S.to_add_subgroup : set M) := ‹_›,
exact S.to_add_subgroup.t3_quotient_of_is_closed
end
end submodule
end quotient
|
53cbd65699e0b6889622beaf9ebad40f10df36e7 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/analytic/basic.lean | c33669722d9d57df6515ee2a2d74ec306fd664b7 | [
"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 | 66,340 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import analysis.calculus.formal_multilinear_series
import analysis.specific_limits.normed
import logic.equiv.fin
import topology.algebra.infinite_sum.module
/-!
# Analytic functions
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two
dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : ℕ`.
* `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_is_O`: if `‖p n‖ * r ^ n`
is bounded above, then `r ≤ p.radius`;
* `p.is_o_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.is_o_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`‖p n‖ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_is_O`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partial_sum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`.
* `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`.
Additionally, let `f` be a function from `E` to `F`.
* `has_fpower_series_on_ball f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = ∑'_n pₙ yⁿ`.
* `has_fpower_series_at f p x`: on some ball of center `x` with positive radius, holds
`has_fpower_series_on_ball f p x r`.
* `analytic_at 𝕜 f x`: there exists a power series `p` such that holds
`has_fpower_series_at f p x`.
* `analytic_on 𝕜 f s`: the function `f` is analytic at every point of `s`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`has_fpower_series_on_ball.continuous_on` and `has_fpower_series_at.continuous_at` and
`analytic_at.continuous_at`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `formal_multilinear_series.has_fpower_series_on_ball`.
* If a function admits a power series in a ball, then it is analytic at any point `y` of this ball,
and the power series there can be expressed in terms of the initial power series `p` as
`p.change_origin y`. See `has_fpower_series_on_ball.change_origin`. It follows in particular that
the set of points at which a given function is analytic is open, see `is_open_analytic_at`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable theory
variables {𝕜 E F G : Type*}
open_locale topology classical big_operators nnreal filter ennreal
open set filter asymptotics
namespace formal_multilinear_series
variables [ring 𝕜] [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F]
variables [topological_space E] [topological_space F]
variables [topological_add_group E] [topological_add_group F]
variables [has_continuous_const_smul 𝕜 E] [has_continuous_const_smul 𝕜 F]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A
priori, it only behaves well when `‖x‖ < p.radius`. -/
protected def sum (p : formal_multilinear_series 𝕜 E F) (x : E) : F := ∑' n : ℕ , p n (λ i, x)
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partial_sum n x` is the sum
`Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/
def partial_sum (p : formal_multilinear_series 𝕜 E F) (n : ℕ) (x : E) : F :=
∑ k in finset.range n, p k (λ(i : fin k), x)
/-- The partial sums of a formal multilinear series are continuous. -/
lemma partial_sum_continuous (p : formal_multilinear_series 𝕜 E F) (n : ℕ) :
continuous (p.partial_sum n) :=
by continuity
end formal_multilinear_series
/-! ### The radius of a formal multilinear series -/
variables [nontrivially_normed_field 𝕜]
[normed_add_comm_group E] [normed_space 𝕜 E]
[normed_add_comm_group F] [normed_space 𝕜 F]
[normed_add_comm_group G] [normed_space 𝕜 G]
namespace formal_multilinear_series
variables (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ`
converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these
definitions are *not* equivalent in general. -/
def radius (p : formal_multilinear_series 𝕜 E F) : ℝ≥0∞ :=
⨆ (r : ℝ≥0) (C : ℝ) (hr : ∀ n, ‖p n‖ * r ^ n ≤ C), (r : ℝ≥0∞)
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ (n : ℕ), ‖p n‖ * r^n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
le_supr_of_le r $ le_supr_of_le C $ (le_supr (λ _, (r : ℝ≥0∞)) h)
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ (n : ℕ), ‖p n‖₊ * r^n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
p.le_radius_of_bound C $ λ n, by exact_mod_cast (h n)
/-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_is_O (h : (λ n, ‖p n‖ * r^n) =O[at_top] (λ n, (1 : ℝ))) : ↑r ≤ p.radius :=
exists.elim (is_O_one_nat_at_top_iff.1 h) $ λ C hC, p.le_radius_of_bound C $
λ n, (le_abs_self _).trans (hC n)
lemma le_radius_of_eventually_le (C) (h : ∀ᶠ n in at_top, ‖p n‖ * r ^ n ≤ C) : ↑r ≤ p.radius :=
p.le_radius_of_is_O $ is_O.of_bound C $ h.mono $ λ n hn, by simpa
lemma le_radius_of_summable_nnnorm (h : summable (λ n, ‖p n‖₊ * r ^ n)) : ↑r ≤ p.radius :=
p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) $ λ n, le_tsum' h _
lemma le_radius_of_summable (h : summable (λ n, ‖p n‖ * r ^ n)) : ↑r ≤ p.radius :=
p.le_radius_of_summable_nnnorm $ by { simp only [← coe_nnnorm] at h, exact_mod_cast h }
lemma radius_eq_top_of_forall_nnreal_is_O
(h : ∀ r : ℝ≥0, (λ n, ‖p n‖ * r^n) =O[at_top] (λ n, (1 : ℝ))) : p.radius = ∞ :=
ennreal.eq_top_of_forall_nnreal_le $ λ r, p.le_radius_of_is_O (h r)
lemma radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in at_top, p n = 0) : p.radius = ∞ :=
p.radius_eq_top_of_forall_nnreal_is_O $
λ r, (is_O_zero _ _).congr' (h.mono $ λ n hn, by simp [hn]) eventually_eq.rfl
lemma radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) : p.radius = ∞ :=
p.radius_eq_top_of_eventually_eq_zero $ mem_at_top_sets.2
⟨n, λ k hk, tsub_add_cancel_of_le hk ▸ hn _⟩
@[simp] lemma const_formal_multilinear_series_radius {v : F} :
(const_formal_multilinear_series 𝕜 E v).radius = ⊤ :=
(const_formal_multilinear_series 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1
(by simp [const_formal_multilinear_series])
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/
lemma is_o_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, (λ n, ‖p n‖ * r ^ n) =o[at_top] (pow a) :=
begin
rw (tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 1 4,
simp only [radius, lt_supr_iff] at h,
rcases h with ⟨t, C, hC, rt⟩,
rw [ennreal.coe_lt_coe, ← nnreal.coe_lt_coe] at rt,
have : 0 < (t : ℝ), from r.coe_nonneg.trans_lt rt,
rw [← div_lt_one this] at rt,
refine ⟨_, rt, C, or.inr zero_lt_one, λ n, _⟩,
calc |‖p n‖ * r ^ n| = (‖p n‖ * t ^ n) * (r / t) ^ n :
by field_simp [mul_right_comm, abs_mul, this.ne']
... ≤ C * (r / t) ^ n : mul_le_mul_of_nonneg_right (hC n) (pow_nonneg (div_nonneg r.2 t.2) _)
end
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/
lemma is_o_one_of_lt_radius (h : ↑r < p.radius) :
(λ n, ‖p n‖ * r ^ n) =o[at_top] (λ _, 1 : ℕ → ℝ) :=
let ⟨a, ha, hp⟩ := p.is_o_of_lt_radius h in
hp.trans $ (is_o_pow_pow_of_lt_left ha.1.le ha.2).congr (λ n, rfl) one_pow
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/
lemma norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ‖p n‖ * r^n ≤ C * a^n :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 1 5).mp (p.is_o_of_lt_radius h)
with ⟨a, ha, C, hC, H⟩,
exact ⟨a, ha, C, hC, λ n, (le_abs_self _).trans (H n)⟩
end
/-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/
lemma lt_radius_of_is_O (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1)
(hp : (λ n, ‖p n‖ * r ^ n) =O[at_top] (pow a)) :
↑r < p.radius :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 2 5).mp ⟨a, ha, hp⟩
with ⟨a, ha, C, hC, hp⟩,
rw [← pos_iff_ne_zero, ← nnreal.coe_pos] at h₀,
lift a to ℝ≥0 using ha.1.le,
have : (r : ℝ) < r / a :=
by simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2,
norm_cast at this,
rw [← ennreal.coe_lt_coe] at this,
refine this.trans_le (p.le_radius_of_bound C $ λ n, _),
rw [nnreal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)],
exact (le_abs_self _).trans (hp n)
end
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
lemma norm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * r^n ≤ C :=
let ⟨a, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
in ⟨C, hC, λ n, (h n).trans $ mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
lemma norm_le_div_pow_of_pos_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / r ^ n :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h in
⟨C, hC, λ n, iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
lemma nnnorm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r^n ≤ C :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
in ⟨⟨C, hC.lt.le⟩, hC, by exact_mod_cast hp⟩
lemma le_radius_of_tendsto (p : formal_multilinear_series 𝕜 E F) {l : ℝ}
(h : tendsto (λ n, ‖p n‖ * r^n) at_top (𝓝 l)) : ↑r ≤ p.radius :=
p.le_radius_of_is_O (h.is_O_one _)
lemma le_radius_of_summable_norm (p : formal_multilinear_series 𝕜 E F)
(hs : summable (λ n, ‖p n‖ * r^n)) : ↑r ≤ p.radius :=
p.le_radius_of_tendsto hs.tendsto_at_top_zero
lemma not_summable_norm_of_radius_lt_nnnorm (p : formal_multilinear_series 𝕜 E F) {x : E}
(h : p.radius < ‖x‖₊) : ¬ summable (λ n, ‖p n‖ * ‖x‖^n) :=
λ hs, not_le_of_lt h (p.le_radius_of_summable_norm hs)
lemma summable_norm_mul_pow (p : formal_multilinear_series 𝕜 E F)
{r : ℝ≥0} (h : ↑r < p.radius) :
summable (λ n : ℕ, ‖p n‖ * r ^ n) :=
begin
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h,
exact summable_of_nonneg_of_le (λ n, mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _)) hp
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _),
end
lemma summable_norm_apply (p : formal_multilinear_series 𝕜 E F)
{x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
summable (λ n : ℕ, ‖p n (λ _, x)‖) :=
begin
rw mem_emetric_ball_zero_iff at hx,
refine summable_of_nonneg_of_le (λ _, norm_nonneg _) (λ n, ((p n).le_op_norm _).trans_eq _)
(p.summable_norm_mul_pow hx),
simp
end
lemma summable_nnnorm_mul_pow (p : formal_multilinear_series 𝕜 E F)
{r : ℝ≥0} (h : ↑r < p.radius) :
summable (λ n : ℕ, ‖p n‖₊ * r ^ n) :=
by { rw ← nnreal.summable_coe, push_cast, exact p.summable_norm_mul_pow h }
protected lemma summable [complete_space F]
(p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
summable (λ n : ℕ, p n (λ _, x)) :=
summable_of_summable_norm (p.summable_norm_apply hx)
lemma radius_eq_top_of_summable_norm (p : formal_multilinear_series 𝕜 E F)
(hs : ∀ r : ℝ≥0, summable (λ n, ‖p n‖ * r^n)) : p.radius = ∞ :=
ennreal.eq_top_of_forall_nnreal_le (λ r, p.le_radius_of_summable_norm (hs r))
lemma radius_eq_top_iff_summable_norm (p : formal_multilinear_series 𝕜 E F) :
p.radius = ∞ ↔ ∀ r : ℝ≥0, summable (λ n, ‖p n‖ * r^n) :=
begin
split,
{ intros h r,
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ :=
p.norm_mul_pow_le_mul_pow_of_lt_radius
(show (r:ℝ≥0∞) < p.radius, from h.symm ▸ ennreal.coe_lt_top),
refine (summable_of_norm_bounded (λ n, (C : ℝ) * a ^ n)
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _) (λ n, _)),
specialize hp n,
rwa real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n)) },
{ exact p.radius_eq_top_of_summable_norm }
end
/-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/
lemma le_mul_pow_of_radius_pos (p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) :
∃ C r (hC : 0 < C) (hr : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n :=
begin
rcases ennreal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩,
have rpos : 0 < (r : ℝ), by simp [ennreal.coe_pos.1 r0],
rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩,
refine ⟨C, r ⁻¹, Cpos, by simp [rpos], λ n, _⟩,
convert hCp n,
exact inv_pow _ _,
end
/-- The radius of the sum of two formal series is at least the minimum of their two radii. -/
lemma min_radius_le_radius_add (p q : formal_multilinear_series 𝕜 E F) :
min p.radius q.radius ≤ (p + q).radius :=
begin
refine ennreal.le_of_forall_nnreal_lt (λ r hr, _),
rw lt_min_iff at hr,
have := ((p.is_o_one_of_lt_radius hr.1).add (q.is_o_one_of_lt_radius hr.2)).is_O,
refine (p + q).le_radius_of_is_O ((is_O_of_le _ $ λ n, _).trans this),
rw [← add_mul, norm_mul, norm_mul, norm_norm],
exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _)
end
@[simp] lemma radius_neg (p : formal_multilinear_series 𝕜 E F) : (-p).radius = p.radius :=
by simp [radius]
protected lemma has_sum [complete_space F]
(p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
has_sum (λ n : ℕ, p n (λ _, x)) (p.sum x) :=
(p.summable hx).has_sum
lemma radius_le_radius_continuous_linear_map_comp
(p : formal_multilinear_series 𝕜 E F) (f : F →L[𝕜] G) :
p.radius ≤ (f.comp_formal_multilinear_series p).radius :=
begin
refine ennreal.le_of_forall_nnreal_lt (λ r hr, _),
apply le_radius_of_is_O,
apply (is_O.trans_is_o _ (p.is_o_one_of_lt_radius hr)).is_O,
refine is_O.mul (@is_O_with.is_O _ _ _ _ _ (‖f‖) _ _ _ _) (is_O_refl _ _),
apply is_O_with.of_bound (eventually_of_forall (λ n, _)),
simpa only [norm_norm] using f.norm_comp_continuous_multilinear_map_le (p n)
end
end formal_multilinear_series
/-! ### Expanding a function as a power series -/
section
variables {f g : E → F} {p pf pg : formal_multilinear_series 𝕜 E F} {x : E} {r r' : ℝ≥0∞}
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `‖y‖ < r`.
-/
structure has_fpower_series_on_ball
(f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) (r : ℝ≥0∞) : Prop :=
(r_le : r ≤ p.radius)
(r_pos : 0 < r)
(has_sum : ∀ {y}, y ∈ emetric.ball (0 : E) r → has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)))
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/
def has_fpower_series_at (f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) :=
∃ r, has_fpower_series_on_ball f p x r
variable (𝕜)
/-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power
series expansion around `x`. -/
def analytic_at (f : E → F) (x : E) :=
∃ (p : formal_multilinear_series 𝕜 E F), has_fpower_series_at f p x
/-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around
every point of `s`. -/
def analytic_on (f : E → F) (s : set E) :=
∀ x, x ∈ s → analytic_at 𝕜 f x
variable {𝕜}
lemma has_fpower_series_on_ball.has_fpower_series_at (hf : has_fpower_series_on_ball f p x r) :
has_fpower_series_at f p x := ⟨r, hf⟩
lemma has_fpower_series_at.analytic_at (hf : has_fpower_series_at f p x) : analytic_at 𝕜 f x :=
⟨p, hf⟩
lemma has_fpower_series_on_ball.analytic_at (hf : has_fpower_series_on_ball f p x r) :
analytic_at 𝕜 f x :=
hf.has_fpower_series_at.analytic_at
lemma has_fpower_series_on_ball.congr (hf : has_fpower_series_on_ball f p x r)
(hg : eq_on f g (emetric.ball x r)) :
has_fpower_series_on_ball g p x r :=
{ r_le := hf.r_le,
r_pos := hf.r_pos,
has_sum := λ y hy,
begin
convert hf.has_sum hy,
apply hg.symm,
simpa [edist_eq_coe_nnnorm_sub] using hy,
end }
/-- If a function `f` has a power series `p` around `x`, then the function `z ↦ f (z - y)` has the
same power series around `x + y`. -/
lemma has_fpower_series_on_ball.comp_sub (hf : has_fpower_series_on_ball f p x r) (y : E) :
has_fpower_series_on_ball (λ z, f (z - y)) p (x + y) r :=
{ r_le := hf.r_le,
r_pos := hf.r_pos,
has_sum := λ z hz, by { convert hf.has_sum hz, abel } }
lemma has_fpower_series_on_ball.has_sum_sub (hf : has_fpower_series_on_ball f p x r) {y : E}
(hy : y ∈ emetric.ball x r) :
has_sum (λ n : ℕ, p n (λ i, y - x)) (f y) :=
have y - x ∈ emetric.ball (0 : E) r, by simpa [edist_eq_coe_nnnorm_sub] using hy,
by simpa only [add_sub_cancel'_right] using hf.has_sum this
lemma has_fpower_series_on_ball.radius_pos (hf : has_fpower_series_on_ball f p x r) :
0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
lemma has_fpower_series_at.radius_pos (hf : has_fpower_series_at f p x) :
0 < p.radius :=
let ⟨r, hr⟩ := hf in hr.radius_pos
lemma has_fpower_series_on_ball.mono
(hf : has_fpower_series_on_ball f p x r) (r'_pos : 0 < r') (hr : r' ≤ r) :
has_fpower_series_on_ball f p x r' :=
⟨le_trans hr hf.1, r'_pos, λ y hy, hf.has_sum (emetric.ball_subset_ball hr hy)⟩
lemma has_fpower_series_at.congr (hf : has_fpower_series_at f p x) (hg : f =ᶠ[𝓝 x] g) :
has_fpower_series_at g p x :=
begin
rcases hf with ⟨r₁, h₁⟩,
rcases emetric.mem_nhds_iff.mp hg with ⟨r₂, h₂pos, h₂⟩,
exact ⟨min r₁ r₂, (h₁.mono (lt_min h₁.r_pos h₂pos) inf_le_left).congr
(λ y hy, h₂ (emetric.ball_subset_ball inf_le_right hy))⟩
end
protected lemma has_fpower_series_at.eventually (hf : has_fpower_series_at f p x) :
∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, has_fpower_series_on_ball f p x r :=
let ⟨r, hr⟩ := hf in
mem_of_superset (Ioo_mem_nhds_within_Ioi (left_mem_Ico.2 hr.r_pos)) $
λ r' hr', hr.mono hr'.1 hr'.2.le
lemma has_fpower_series_on_ball.eventually_has_sum (hf : has_fpower_series_on_ball f p x r) :
∀ᶠ y in 𝓝 0, has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)) :=
by filter_upwards [emetric.ball_mem_nhds (0 : E) hf.r_pos] using λ _, hf.has_sum
lemma has_fpower_series_at.eventually_has_sum (hf : has_fpower_series_at f p x) :
∀ᶠ y in 𝓝 0, has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)) :=
let ⟨r, hr⟩ := hf in hr.eventually_has_sum
lemma has_fpower_series_on_ball.eventually_has_sum_sub (hf : has_fpower_series_on_ball f p x r) :
∀ᶠ y in 𝓝 x, has_sum (λn:ℕ, p n (λ(i : fin n), y - x)) (f y) :=
by filter_upwards [emetric.ball_mem_nhds x hf.r_pos] with y using hf.has_sum_sub
lemma has_fpower_series_at.eventually_has_sum_sub (hf : has_fpower_series_at f p x) :
∀ᶠ y in 𝓝 x, has_sum (λn:ℕ, p n (λ(i : fin n), y - x)) (f y) :=
let ⟨r, hr⟩ := hf in hr.eventually_has_sum_sub
lemma has_fpower_series_on_ball.eventually_eq_zero
(hf : has_fpower_series_on_ball f (0 : formal_multilinear_series 𝕜 E F) x r) :
∀ᶠ z in 𝓝 x, f z = 0 :=
by filter_upwards [hf.eventually_has_sum_sub] with z hz using hz.unique has_sum_zero
lemma has_fpower_series_at.eventually_eq_zero
(hf : has_fpower_series_at f (0 : formal_multilinear_series 𝕜 E F) x) :
∀ᶠ z in 𝓝 x, f z = 0 :=
let ⟨r, hr⟩ := hf in hr.eventually_eq_zero
lemma has_fpower_series_on_ball_const {c : F} {e : E} :
has_fpower_series_on_ball (λ _, c) (const_formal_multilinear_series 𝕜 E c) e ⊤ :=
begin
refine ⟨by simp, with_top.zero_lt_top, λ y hy, has_sum_single 0 (λ n hn, _)⟩,
simp [const_formal_multilinear_series_apply hn]
end
lemma has_fpower_series_at_const {c : F} {e : E} :
has_fpower_series_at (λ _, c) (const_formal_multilinear_series 𝕜 E c) e :=
⟨⊤, has_fpower_series_on_ball_const⟩
lemma analytic_at_const {v : F} : analytic_at 𝕜 (λ _, v) x :=
⟨const_formal_multilinear_series 𝕜 E v, has_fpower_series_at_const⟩
lemma analytic_on_const {v : F} {s : set E} : analytic_on 𝕜 (λ _, v) s :=
λ z _, analytic_at_const
lemma has_fpower_series_on_ball.add
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f + g) (pf + pg) x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg),
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).add (hg.has_sum hy) }
lemma has_fpower_series_at.add
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f + g) (pf + pg) x :=
begin
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩,
exact ⟨r, hr.1.add hr.2⟩
end
lemma analytic_at.add (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f + g) x :=
let ⟨pf, hpf⟩ := hf, ⟨qf, hqf⟩ := hg in (hpf.add hqf).analytic_at
lemma has_fpower_series_on_ball.neg (hf : has_fpower_series_on_ball f pf x r) :
has_fpower_series_on_ball (-f) (-pf) x r :=
{ r_le := by { rw pf.radius_neg, exact hf.r_le },
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).neg }
lemma has_fpower_series_at.neg
(hf : has_fpower_series_at f pf x) : has_fpower_series_at (-f) (-pf) x :=
let ⟨rf, hrf⟩ := hf in hrf.neg.has_fpower_series_at
lemma analytic_at.neg (hf : analytic_at 𝕜 f x) : analytic_at 𝕜 (-f) x :=
let ⟨pf, hpf⟩ := hf in hpf.neg.analytic_at
lemma has_fpower_series_on_ball.sub
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f - g) (pf - pg) x r :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma has_fpower_series_at.sub
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f - g) (pf - pg) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma analytic_at.sub (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f - g) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma analytic_on.mono {s t : set E} (hf : analytic_on 𝕜 f t) (hst : s ⊆ t) :
analytic_on 𝕜 f s :=
λ z hz, hf z (hst hz)
lemma analytic_on.add {s : set E} (hf : analytic_on 𝕜 f s) (hg : analytic_on 𝕜 g s) :
analytic_on 𝕜 (f + g) s :=
λ z hz, (hf z hz).add (hg z hz)
lemma analytic_on.sub {s : set E} (hf : analytic_on 𝕜 f s) (hg : analytic_on 𝕜 g s) :
analytic_on 𝕜 (f - g) s :=
λ z hz, (hf z hz).sub (hg z hz)
lemma has_fpower_series_on_ball.coeff_zero (hf : has_fpower_series_on_ball f pf x r)
(v : fin 0 → E) : pf 0 v = f x :=
begin
have v_eq : v = (λ i, 0) := subsingleton.elim _ _,
have zero_mem : (0 : E) ∈ emetric.ball (0 : E) r, by simp [hf.r_pos],
have : ∀ i ≠ 0, pf i (λ j, 0) = 0,
{ assume i hi,
have : 0 < i := pos_iff_ne_zero.2 hi,
exact continuous_multilinear_map.map_coord_zero _ (⟨0, this⟩ : fin i) rfl },
have A := (hf.has_sum zero_mem).unique (has_sum_single _ this),
simpa [v_eq] using A.symm,
end
lemma has_fpower_series_at.coeff_zero (hf : has_fpower_series_at f pf x) (v : fin 0 → E) :
pf 0 v = f x :=
let ⟨rf, hrf⟩ := hf in hrf.coeff_zero v
/-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the
power series `g ∘ p` on the same ball. -/
lemma _root_.continuous_linear_map.comp_has_fpower_series_on_ball
(g : F →L[𝕜] G) (h : has_fpower_series_on_ball f p x r) :
has_fpower_series_on_ball (g ∘ f) (g.comp_formal_multilinear_series p) x r :=
{ r_le := h.r_le.trans (p.radius_le_radius_continuous_linear_map_comp _),
r_pos := h.r_pos,
has_sum := λ y hy, by simpa only [continuous_linear_map.comp_formal_multilinear_series_apply,
continuous_linear_map.comp_continuous_multilinear_map_coe, function.comp_app]
using g.has_sum (h.has_sum hy) }
/-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic
on `s`. -/
lemma _root_.continuous_linear_map.comp_analytic_on {s : set E}
(g : F →L[𝕜] G) (h : analytic_on 𝕜 f s) :
analytic_on 𝕜 (g ∘ f) s :=
begin
rintros x hx,
rcases h x hx with ⟨p, r, hp⟩,
exact ⟨g.comp_formal_multilinear_series p, r, g.comp_has_fpower_series_on_ball hp⟩,
end
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence.
This version provides an upper estimate that decreases both in `‖y‖` and `n`. See also
`has_fpower_series_on_ball.uniform_geometric_approx` for a weaker version. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ‖p n‖ * r' ^n ≤ C * a^n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le),
refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), λ y hy n, _⟩,
have yr' : ‖y‖ < r', by { rw ball_zero_eq at hy, exact hy },
have hr'0 : 0 < (r' : ℝ), from (norm_nonneg _).trans_lt yr',
have : y ∈ emetric.ball (0 : E) r,
{ refine mem_emetric_ball_zero_iff.2 (lt_trans _ h),
exact_mod_cast yr' },
rw [norm_sub_rev, ← mul_div_right_comm],
have ya : a * (‖y‖ / ↑r') ≤ a,
from mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg),
suffices : ‖p.partial_sum n y - f (x + y)‖ ≤ C * (a * (‖y‖ / r')) ^ n / (1 - a * (‖y‖ / r')),
{ refine this.trans _,
apply_rules [div_le_div_of_le_left, sub_pos.2, div_nonneg, mul_nonneg, pow_nonneg, hC.lt.le,
ha.1.le, norm_nonneg, nnreal.coe_nonneg, ha.2, (sub_le_sub_iff_left _).2]; apply_instance },
apply norm_sub_le_of_geometric_bound_of_has_sum (ya.trans_lt ha.2) _ (hf.has_sum this),
assume n,
calc ‖(p n) (λ (i : fin n), y)‖ ≤ ‖p n‖ * (∏ i : fin n, ‖y‖) :
continuous_multilinear_map.le_op_norm _ _
... = (‖p n‖ * r' ^ n) * (‖y‖ / r') ^ n : by field_simp [hr'0.ne', mul_right_comm]
... ≤ (C * a ^ n) * (‖y‖ / r') ^ n :
mul_le_mul_of_nonneg_right (hp n) (pow_nonneg (div_nonneg (norm_nonneg _) r'.coe_nonneg) _)
... ≤ C * (a * (‖y‖ / r')) ^ n : by rw [mul_pow, mul_assoc]
end
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partial_sum n y‖ ≤ C * a ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine ⟨a, ha, C, hC, λ y hy n, (hp y hy n).trans _⟩,
have yr' : ‖y‖ < r', by rwa ball_zero_eq at hy,
refine mul_le_mul_of_nonneg_left (pow_le_pow_of_le_left _ _ _) hC.lt.le,
exacts [mul_nonneg ha.1.le (div_nonneg (norm_nonneg y) r'.coe_nonneg),
mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)]
end
/-- Taylor formula for an analytic function, `is_O` version. -/
lemma has_fpower_series_at.is_O_sub_partial_sum_pow (hf : has_fpower_series_at f p x) (n : ℕ) :
(λ y : E, f (x + y) - p.partial_sum n y) =O[𝓝 0] (λ y, ‖y‖ ^ n) :=
begin
rcases hf with ⟨r, hf⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩,
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine is_O_iff.2 ⟨C * (a / r') ^ n, _⟩,
replace r'0 : 0 < (r' : ℝ), by exact_mod_cast r'0,
filter_upwards [metric.ball_mem_nhds (0 : E) r'0] with y hy,
simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n,
end
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. This lemma formulates this property using `is_O` and
`filter.principal` on `E × E`. -/
lemma has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal
(hf : has_fpower_series_on_ball f p x r) (hr : r' < r) :
(λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))) =O[𝓟 (emetric.ball (x, x) r')]
(λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖) :=
begin
lift r' to ℝ≥0 using ne_top_of_lt hr,
rcases (zero_le r').eq_or_lt with rfl|hr'0,
{ simp only [is_O_bot, emetric.ball_zero, principal_empty, ennreal.coe_zero] },
obtain ⟨a, ha, C, hC : 0 < C, hp⟩ :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ (n : ℕ), ‖p n‖ * ↑r' ^ n ≤ C * a ^ n,
from p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le),
simp only [← le_div_iff (pow_pos (nnreal.coe_pos.2 hr'0) _)] at hp,
set L : E × E → ℝ := λ y,
(C * (a / r') ^ 2) * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * (a / (1 - a) ^ 2 + 2 / (1 - a)),
have hL : ∀ y ∈ emetric.ball (x, x) r',
‖f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))‖ ≤ L y,
{ intros y hy',
have hy : y ∈ emetric.ball x r ×ˢ emetric.ball x r,
{ rw [emetric.ball_prod_same], exact emetric.ball_subset_ball hr.le hy' },
set A : ℕ → F := λ n, p n (λ _, y.1 - x) - p n (λ _, y.2 - x),
have hA : has_sum (λ n, A (n + 2)) (f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))),
{ convert (has_sum_nat_add_iff' 2).2 ((hf.has_sum_sub hy.1).sub (hf.has_sum_sub hy.2)) using 1,
rw [finset.sum_range_succ, finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self,
zero_add, ← subsingleton.pi_single_eq (0 : fin 1) (y.1 - x), pi.single,
← subsingleton.pi_single_eq (0 : fin 1) (y.2 - x), pi.single, ← (p 1).map_sub, ← pi.single,
subsingleton.pi_single_eq, sub_sub_sub_cancel_right] },
rw [emetric.mem_ball, edist_eq_coe_nnnorm_sub, ennreal.coe_lt_coe] at hy',
set B : ℕ → ℝ := λ n,
(C * (a / r') ^ 2) * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * ((n + 2) * a ^ n),
have hAB : ∀ n, ‖A (n + 2)‖ ≤ B n := λ n,
calc ‖A (n + 2)‖ ≤ ‖p (n + 2)‖ * ↑(n + 2) * ‖y - (x, x)‖ ^ (n + 1) * ‖y.1 - y.2‖ :
by simpa only [fintype.card_fin, pi_norm_const (_ : E), prod.norm_def, pi.sub_def,
prod.fst_sub, prod.snd_sub, sub_sub_sub_cancel_right]
using (p $ n + 2).norm_image_sub_le (λ _, y.1 - x) (λ _, y.2 - x)
... = ‖p (n + 2)‖ * ‖y - (x, x)‖ ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) :
by { rw [pow_succ ‖y - (x, x)‖], ring }
... ≤ (C * a ^ (n + 2) / r' ^ (n + 2)) * r' ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) :
by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul, hp, pow_le_pow_of_le_left,
hy'.le, norm_nonneg, pow_nonneg, div_nonneg, mul_nonneg, nat.cast_nonneg,
hC.le, r'.coe_nonneg, ha.1.le]
... = B n :
by { field_simp [B, pow_succ, hr'0.ne'], simp only [mul_assoc, mul_comm, mul_left_comm] },
have hBL : has_sum B (L y),
{ apply has_sum.mul_left,
simp only [add_mul],
have : ‖a‖ < 1, by simp only [real.norm_eq_abs, abs_of_pos ha.1, ha.2],
convert (has_sum_coe_mul_geometric_of_norm_lt_1 this).add
((has_sum_geometric_of_norm_lt_1 this).mul_left 2) },
exact hA.norm_le_of_bounded hBL hAB },
suffices : L =O[𝓟 (emetric.ball (x, x) r')] (λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖),
{ refine (is_O.of_bound 1 (eventually_principal.2 $ λ y hy, _)).trans this,
rw one_mul,
exact (hL y hy).trans (le_abs_self _) },
simp_rw [L, mul_right_comm _ (_ * _)],
exact (is_O_refl _ _).const_mul_left _,
end
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. -/
lemma has_fpower_series_on_ball.image_sub_sub_deriv_le
(hf : has_fpower_series_on_ball f p x r) (hr : r' < r) :
∃ C, ∀ (y z ∈ emetric.ball x r'),
‖f y - f z - (p 1 (λ _, y - z))‖ ≤ C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖ :=
by simpa only [is_O_principal, mul_assoc, norm_mul, norm_norm, prod.forall,
emetric.mem_ball, prod.edist_eq, max_lt_iff, and_imp, @forall_swap (_ < _) E]
using hf.is_O_image_sub_image_sub_deriv_principal hr
/-- If `f` has formal power series `∑ n, pₙ` at `x`, then
`f y - f z - p 1 (λ _, y - z) = O(‖(y, z) - (x, x)‖ * ‖y - z‖)` as `(y, z) → (x, x)`.
In particular, `f` is strictly differentiable at `x`. -/
lemma has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub (hf : has_fpower_series_at f p x) :
(λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))) =O[𝓝 (x, x)]
(λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖) :=
begin
rcases hf with ⟨r, hf⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩,
refine (hf.is_O_image_sub_image_sub_deriv_principal h).mono _,
exact le_principal_iff.2 (emetric.ball_mem_nhds _ r'0)
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)`
is the uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n y)
(λ y, f (x + y)) at_top (metric.ball (0 : E) r') :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * a ^ n),
from hf.uniform_geometric_approx h,
refine metric.tendsto_uniformly_on_iff.2 (λ ε εpos, _),
have L : tendsto (λ n, (C : ℝ) * a^n) at_top (𝓝 ((C : ℝ) * 0)) :=
tendsto_const_nhds.mul (tendsto_pow_at_top_nhds_0_of_lt_1 ha.1.le ha.2),
rw mul_zero at L,
refine (L.eventually (gt_mem_nhds εpos)).mono (λ n hn y hy, _),
rw dist_eq_norm,
exact (hp y hy n).trans_lt hn
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f (x + y)`
is the locally uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n y) (λ y, f (x + y))
at_top (emetric.ball (0 : E) r) :=
begin
assume u hu x hx,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩,
have : emetric.ball (0 : E) r' ∈ 𝓝 x :=
is_open.mem_nhds emetric.is_open_ball xr',
refine ⟨emetric.ball (0 : E) r', mem_nhds_within_of_mem_nhds this, _⟩,
simpa [metric.emetric_ball_nnreal] using hf.tendsto_uniformly_on hr' u hu
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y`
is the uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (metric.ball (x : E) r') :=
begin
convert (hf.tendsto_uniformly_on h).comp (λ y, y - x),
{ simp [(∘)] },
{ ext z, simp [dist_eq_norm] }
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f y`
is the locally uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on'
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (emetric.ball (x : E) r) :=
begin
have A : continuous_on (λ (y : E), y - x) (emetric.ball (x : E) r) :=
(continuous_id.sub continuous_const).continuous_on,
convert (hf.tendsto_locally_uniformly_on).comp (λ (y : E), y - x) _ A,
{ ext z, simp },
{ assume z, simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] }
end
/-- If a function admits a power series expansion on a disk, then it is continuous there. -/
protected lemma has_fpower_series_on_ball.continuous_on
(hf : has_fpower_series_on_ball f p x r) : continuous_on f (emetric.ball x r) :=
hf.tendsto_locally_uniformly_on'.continuous_on $ eventually_of_forall $ λ n,
((p.partial_sum_continuous n).comp (continuous_id.sub continuous_const)).continuous_on
protected lemma has_fpower_series_at.continuous_at (hf : has_fpower_series_at f p x) :
continuous_at f x :=
let ⟨r, hr⟩ := hf in hr.continuous_on.continuous_at (emetric.ball_mem_nhds x (hr.r_pos))
protected lemma analytic_at.continuous_at (hf : analytic_at 𝕜 f x) : continuous_at f x :=
let ⟨p, hp⟩ := hf in hp.continuous_at
protected lemma analytic_on.continuous_on {s : set E} (hf : analytic_on 𝕜 f s) :
continuous_on f s :=
λ x hx, (hf x hx).continuous_at.continuous_within_at
/-- In a complete space, the sum of a converging power series `p` admits `p` as a power series.
This is not totally obvious as we need to check the convergence of the series. -/
protected lemma formal_multilinear_series.has_fpower_series_on_ball [complete_space F]
(p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) :
has_fpower_series_on_ball p.sum p 0 p.radius :=
{ r_le := le_rfl,
r_pos := h,
has_sum := λ y hy, by { rw zero_add, exact p.has_sum hy } }
lemma has_fpower_series_on_ball.sum (h : has_fpower_series_on_ball f p x r)
{y : E} (hy : y ∈ emetric.ball (0 : E) r) : f (x + y) = p.sum y :=
(h.has_sum hy).tsum_eq.symm
/-- The sum of a converging power series is continuous in its disk of convergence. -/
protected lemma formal_multilinear_series.continuous_on [complete_space F] :
continuous_on p.sum (emetric.ball 0 p.radius) :=
begin
cases (zero_le p.radius).eq_or_lt with h h,
{ simp [← h, continuous_on_empty] },
{ exact (p.has_fpower_series_on_ball h).continuous_on }
end
end
/-!
### Uniqueness of power series
If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding
to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is,
for any `n : ℕ` and `y : E`, `p₁ n (λ i, y) = p₂ n (λ i, y)`. In the one-dimensional case, when
`f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by
`formal_multilinear_series.mk_pi_field`, and hence are determined completely by the value of
`p₁ n (λ i, 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be
transferred to the other.
-/
section uniqueness
open continuous_multilinear_map
lemma asymptotics.is_O.continuous_multilinear_map_apply_eq_zero {n : ℕ} {p : E [×n]→L[𝕜] F}
(h : (λ y, p (λ i, y)) =O[𝓝 0] (λ y, ‖y‖ ^ (n + 1))) (y : E) :
p (λ i, y) = 0 :=
begin
obtain ⟨c, c_pos, hc⟩ := h.exists_pos,
obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (is_O_with_iff.mp hc),
obtain ⟨δ, δ_pos, δε⟩ := (metric.is_open_iff.mp t_open) 0 z_mem,
clear h hc z_mem,
cases n,
{ exact norm_eq_zero.mp (by simpa only [fin0_apply_norm, norm_eq_zero, norm_zero, zero_pow',
ne.def, nat.one_ne_zero, not_false_iff, mul_zero, norm_le_zero_iff]
using ht 0 (δε (metric.mem_ball_self δ_pos))), },
{ refine or.elim (em (y = 0)) (λ hy, by simpa only [hy] using p.map_zero) (λ hy, _),
replace hy := norm_pos_iff.mpr hy,
refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add (λ ε ε_pos, _)) (norm_nonneg _)),
have h₀ := mul_pos c_pos (pow_pos hy (n.succ + 1)),
obtain ⟨k, k_pos, k_norm⟩ := normed_field.exists_norm_lt 𝕜
(lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀))),
have h₁ : ‖k • y‖ < δ,
{ rw norm_smul,
exact inv_mul_cancel_right₀ hy.ne.symm δ ▸ mul_lt_mul_of_pos_right
(lt_of_lt_of_le k_norm (min_le_left _ _)) hy },
have h₂ := calc
‖p (λ i, k • y)‖ ≤ c * ‖k • y‖ ^ (n.succ + 1)
: by simpa only [norm_pow, norm_norm]
using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
... = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))
: by { simp only [norm_smul, mul_pow], rw pow_succ, ring },
have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε, from inv_mul_cancel_right₀ h₀.ne.symm ε ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀,
calc ‖p (λ i, y)‖ = ‖(k⁻¹) ^ n.succ‖ * ‖p (λ i, k • y)‖
: by simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos),
norm_smul, finset.prod_const, finset.card_fin] using
congr_arg norm (p.map_smul_univ (λ (i : fin n.succ), k⁻¹) (λ (i : fin n.succ), k • y))
... ≤ ‖(k⁻¹) ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))))
: mul_le_mul_of_nonneg_left h₂ (norm_nonneg _)
... = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))
: by { rw ←mul_assoc, simp [norm_mul, mul_pow] }
... ≤ 0 + ε
: by { rw inv_mul_cancel (norm_pos_iff.mp k_pos), simpa using h₃.le }, },
end
/-- If a formal multilinear series `p` represents the zero function at `x : E`, then the
terms `p n (λ i, y)` appearing the in sum are zero for any `n : ℕ`, `y : E`. -/
lemma has_fpower_series_at.apply_eq_zero {p : formal_multilinear_series 𝕜 E F} {x : E}
(h : has_fpower_series_at 0 p x) (n : ℕ) :
∀ y : E, p n (λ i, y) = 0 :=
begin
refine nat.strong_rec_on n (λ k hk, _),
have psum_eq : p.partial_sum (k + 1) = (λ y, p k (λ i, y)),
{ funext z,
refine finset.sum_eq_single _ (λ b hb hnb, _) (λ hn, _),
{ have := finset.mem_range_succ_iff.mp hb,
simp only [hk b (this.lt_of_ne hnb), pi.zero_apply, zero_apply] },
{ exact false.elim (hn (finset.mem_range.mpr (lt_add_one k))) } },
replace h := h.is_O_sub_partial_sum_pow k.succ,
simp only [psum_eq, zero_sub, pi.zero_apply, asymptotics.is_O_neg_left] at h,
exact h.continuous_multilinear_map_apply_eq_zero,
end
/-- A one-dimensional formal multilinear series representing the zero function is zero. -/
lemma has_fpower_series_at.eq_zero {p : formal_multilinear_series 𝕜 𝕜 E} {x : 𝕜}
(h : has_fpower_series_at 0 p x) : p = 0 :=
by { ext n x, rw ←mk_pi_field_apply_one_eq_self (p n), simp [h.apply_eq_zero n 1] }
/-- One-dimensional formal multilinear series representing the same function are equal. -/
theorem has_fpower_series_at.eq_formal_multilinear_series
{p₁ p₂ : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {x : 𝕜}
(h₁ : has_fpower_series_at f p₁ x) (h₂ : has_fpower_series_at f p₂ x) :
p₁ = p₂ :=
sub_eq_zero.mp (has_fpower_series_at.eq_zero (by simpa only [sub_self] using h₁.sub h₂))
lemma has_fpower_series_at.eq_formal_multilinear_series_of_eventually
{p q : formal_multilinear_series 𝕜 𝕜 E} {f g : 𝕜 → E} {x : 𝕜} (hp : has_fpower_series_at f p x)
(hq : has_fpower_series_at g q x) (heq : ∀ᶠ z in 𝓝 x, f z = g z) :
p = q :=
(hp.congr heq).eq_formal_multilinear_series hq
/-- A one-dimensional formal multilinear series representing a locally zero function is zero. -/
lemma has_fpower_series_at.eq_zero_of_eventually {p : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E}
{x : 𝕜} (hp : has_fpower_series_at f p x) (hf : f =ᶠ[𝓝 x] 0) : p = 0 :=
(hp.congr hf).eq_zero
/-- If a function `f : 𝕜 → E` has two power series representations at `x`, then the given radii in
which convergence is guaranteed may be interchanged. This can be useful when the formal multilinear
series in one representation has a particularly nice form, but the other has a larger radius. -/
theorem has_fpower_series_on_ball.exchange_radius
{p₁ p₂ : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {r₁ r₂ : ℝ≥0∞} {x : 𝕜}
(h₁ : has_fpower_series_on_ball f p₁ x r₁) (h₂ : has_fpower_series_on_ball f p₂ x r₂) :
has_fpower_series_on_ball f p₁ x r₂ :=
h₂.has_fpower_series_at.eq_formal_multilinear_series h₁.has_fpower_series_at ▸ h₂
/-- If a function `f : 𝕜 → E` has power series representation `p` on a ball of some radius and for
each positive radius it has some power series representation, then `p` converges to `f` on the whole
`𝕜`. -/
theorem has_fpower_series_on_ball.r_eq_top_of_exists {f : 𝕜 → E} {r : ℝ≥0∞} {x : 𝕜}
{p : formal_multilinear_series 𝕜 𝕜 E} (h : has_fpower_series_on_ball f p x r)
(h' : ∀ (r' : ℝ≥0) (hr : 0 < r'),
∃ p' : formal_multilinear_series 𝕜 𝕜 E, has_fpower_series_on_ball f p' x r') :
has_fpower_series_on_ball f p x ∞ :=
{ r_le := ennreal.le_of_forall_pos_nnreal_lt $ λ r hr hr',
let ⟨p', hp'⟩ := h' r hr in (h.exchange_radius hp').r_le,
r_pos := ennreal.coe_lt_top,
has_sum := λ y hy, let ⟨r', hr'⟩ := exists_gt ‖y‖₊, ⟨p', hp'⟩ := h' r' hr'.ne_bot.bot_lt
in (h.exchange_radius hp').has_sum $ mem_emetric_ball_zero_iff.mpr (ennreal.coe_lt_coe.2 hr') }
end uniqueness
/-!
### Changing origin in a power series
If a function is analytic in a disk `D(x, R)`, then it is analytic in any disk contained in that
one. Indeed, one can write
$$
f (x + y + z) = \sum_{n} p_n (y + z)^n = \sum_{n, k} \binom{n}{k} p_n y^{n-k} z^k
= \sum_{k} \Bigl(\sum_{n} \binom{n}{k} p_n y^{n-k}\Bigr) z^k.
$$
The corresponding power series has thus a `k`-th coefficient equal to
$\sum_{n} \binom{n}{k} p_n y^{n-k}$. In the general case where `pₙ` is a multilinear map, this has
to be interpreted suitably: instead of having a binomial coefficient, one should sum over all
possible subsets `s` of `fin n` of cardinal `k`, and attribute `z` to the indices in `s` and
`y` to the indices outside of `s`.
In this paragraph, we implement this. The new power series is called `p.change_origin y`. Then, we
check its convergence and the fact that its sum coincides with the original sum. The outcome of this
discussion is that the set of points where a function is analytic is open.
-/
namespace formal_multilinear_series
section
variables (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0}
/-- A term of `formal_multilinear_series.change_origin_series`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.change_origin x` is a formal multilinear series such that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. Each term of `p.change_origin x`
is itself an analytic function of `x` given by the series `p.change_origin_series`. Each term in
`change_origin_series` is the sum of `change_origin_series_term`'s over all `s` of cardinality `l`.
The definition is such that
`p.change_origin_series_term k l s hs (λ _, x) (λ _, y) = p (k + l) (s.piecewise (λ _, x) (λ _, y))`
-/
def change_origin_series_term (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) :
E [×l]→L[𝕜] E [×k]→L[𝕜] F :=
continuous_multilinear_map.curry_fin_finset 𝕜 E F hs
(by erw [finset.card_compl, fintype.card_fin, hs, add_tsub_cancel_right]) (p $ k + l)
lemma change_origin_series_term_apply (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l)
(x y : E) :
p.change_origin_series_term k l s hs (λ _, x) (λ _, y) =
p (k + l) (s.piecewise (λ _, x) (λ _, y)) :=
continuous_multilinear_map.curry_fin_finset_apply_const _ _ _ _ _
@[simp] lemma norm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) :
‖p.change_origin_series_term k l s hs‖ = ‖p (k + l)‖ :=
by simp only [change_origin_series_term, linear_isometry_equiv.norm_map]
@[simp] lemma nnnorm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) :
‖p.change_origin_series_term k l s hs‖₊ = ‖p (k + l)‖₊ :=
by simp only [change_origin_series_term, linear_isometry_equiv.nnnorm_map]
lemma nnnorm_change_origin_series_term_apply_le (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) (x y : E) :
‖p.change_origin_series_term k l s hs (λ _, x) (λ _, y)‖₊ ≤ ‖p (k + l)‖₊ * ‖x‖₊ ^ l * ‖y‖₊ ^ k :=
begin
rw [← p.nnnorm_change_origin_series_term k l s hs, ← fin.prod_const, ← fin.prod_const],
apply continuous_multilinear_map.le_of_op_nnnorm_le,
apply continuous_multilinear_map.le_op_nnnorm
end
/-- The power series for `f.change_origin k`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.change_origin x` is a formal multilinear series such that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. Its `k`-th term is the sum of
the series `p.change_origin_series k`. -/
def change_origin_series (k : ℕ) : formal_multilinear_series 𝕜 E (E [×k]→L[𝕜] F) :=
λ l, ∑ s : {s : finset (fin (k + l)) // finset.card s = l}, p.change_origin_series_term k l s s.2
lemma nnnorm_change_origin_series_le_tsum (k l : ℕ) :
‖p.change_origin_series k l‖₊ ≤
∑' (x : {s : finset (fin (k + l)) // s.card = l}), ‖p (k + l)‖₊ :=
(nnnorm_sum_le _ _).trans_eq $ by simp only [tsum_fintype, nnnorm_change_origin_series_term]
lemma nnnorm_change_origin_series_apply_le_tsum (k l : ℕ) (x : E) :
‖p.change_origin_series k l (λ _, x)‖₊ ≤
∑' s : {s : finset (fin (k + l)) // s.card = l}, ‖p (k + l)‖₊ * ‖x‖₊ ^ l :=
begin
rw [nnreal.tsum_mul_right, ← fin.prod_const],
exact (p.change_origin_series k l).le_of_op_nnnorm_le _
(p.nnnorm_change_origin_series_le_tsum _ _)
end
/--
Changing the origin of a formal multilinear series `p`, so that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense.
-/
def change_origin (x : E) : formal_multilinear_series 𝕜 E F :=
λ k, (p.change_origin_series k).sum x
/-- An auxiliary equivalence useful in the proofs about
`formal_multilinear_series.change_origin_series`: the set of triples `(k, l, s)`, where `s` is a
`finset (fin (k + l))` of cardinality `l` is equivalent to the set of pairs `(n, s)`, where `s` is a
`finset (fin n)`.
The forward map sends `(k, l, s)` to `(k + l, s)` and the inverse map sends `(n, s)` to
`(n - finset.card s, finset.card s, s)`. The actual definition is less readable because of problems
with non-definitional equalities. -/
@[simps] def change_origin_index_equiv :
(Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l}) ≃ Σ n : ℕ, finset (fin n) :=
{ to_fun := λ s, ⟨s.1 + s.2.1, s.2.2⟩,
inv_fun := λ s, ⟨s.1 - s.2.card, s.2.card, ⟨s.2.map
(fin.cast $ (tsub_add_cancel_of_le $ card_finset_fin_le s.2).symm).to_equiv.to_embedding,
finset.card_map _⟩⟩,
left_inv :=
begin
rintro ⟨k, l, ⟨s : finset (fin $ k + l), hs : s.card = l⟩⟩,
dsimp only [subtype.coe_mk],
-- Lean can't automatically generalize `k' = k + l - s.card`, `l' = s.card`, so we explicitly
-- formulate the generalized goal
suffices : ∀ k' l', k' = k → l' = l → ∀ (hkl : k + l = k' + l') hs',
(⟨k', l', ⟨finset.map (fin.cast hkl).to_equiv.to_embedding s, hs'⟩⟩ :
(Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l})) = ⟨k, l, ⟨s, hs⟩⟩,
{ apply this; simp only [hs, add_tsub_cancel_right] },
rintro _ _ rfl rfl hkl hs',
simp only [equiv.refl_to_embedding, fin.cast_refl, finset.map_refl, eq_self_iff_true,
order_iso.refl_to_equiv, and_self, heq_iff_eq]
end,
right_inv :=
begin
rintro ⟨n, s⟩,
simp [tsub_add_cancel_of_le (card_finset_fin_le s), fin.cast_to_equiv]
end }
lemma change_origin_series_summable_aux₁ {r r' : ℝ≥0} (hr : (r + r' : ℝ≥0∞) < p.radius) :
summable (λ s : Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l},
‖p (s.1 + s.2.1)‖₊ * r ^ s.2.1 * r' ^ s.1) :=
begin
rw ← change_origin_index_equiv.symm.summable_iff,
dsimp only [(∘), change_origin_index_equiv_symm_apply_fst,
change_origin_index_equiv_symm_apply_snd_fst],
have : ∀ n : ℕ, has_sum
(λ s : finset (fin n), ‖p (n - s.card + s.card)‖₊ * r ^ s.card * r' ^ (n - s.card))
(‖p n‖₊ * (r + r') ^ n),
{ intro n,
-- TODO: why `simp only [tsub_add_cancel_of_le (card_finset_fin_le _)]` fails?
convert_to has_sum (λ s : finset (fin n), ‖p n‖₊ * (r ^ s.card * r' ^ (n - s.card))) _,
{ ext1 s, rw [tsub_add_cancel_of_le (card_finset_fin_le _), mul_assoc] },
rw ← fin.sum_pow_mul_eq_add_pow,
exact (has_sum_fintype _).mul_left _ },
refine nnreal.summable_sigma.2 ⟨λ n, (this n).summable, _⟩,
simp only [(this _).tsum_eq],
exact p.summable_nnnorm_mul_pow hr
end
lemma change_origin_series_summable_aux₂ (hr : (r : ℝ≥0∞) < p.radius) (k : ℕ) :
summable (λ s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * r ^ s.1) :=
begin
rcases ennreal.lt_iff_exists_add_pos_lt.1 hr with ⟨r', h0, hr'⟩,
simpa only [mul_inv_cancel_right₀ (pow_pos h0 _).ne']
using ((nnreal.summable_sigma.1
(p.change_origin_series_summable_aux₁ hr')).1 k).mul_right (r' ^ k)⁻¹
end
lemma change_origin_series_summable_aux₃ {r : ℝ≥0} (hr : ↑r < p.radius) (k : ℕ) :
summable (λ l : ℕ, ‖p.change_origin_series k l‖₊ * r ^ l) :=
begin
refine nnreal.summable_of_le (λ n, _)
(nnreal.summable_sigma.1 $ p.change_origin_series_summable_aux₂ hr k).2,
simp only [nnreal.tsum_mul_right],
exact mul_le_mul' (p.nnnorm_change_origin_series_le_tsum _ _) le_rfl
end
lemma le_change_origin_series_radius (k : ℕ) :
p.radius ≤ (p.change_origin_series k).radius :=
ennreal.le_of_forall_nnreal_lt $ λ r hr,
le_radius_of_summable_nnnorm _ (p.change_origin_series_summable_aux₃ hr k)
lemma nnnorm_change_origin_le (k : ℕ) (h : (‖x‖₊ : ℝ≥0∞) < p.radius) :
‖p.change_origin x k‖₊ ≤
∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * ‖x‖₊ ^ s.1 :=
begin
refine tsum_of_nnnorm_bounded _ (λ l, p.nnnorm_change_origin_series_apply_le_tsum k l x),
have := p.change_origin_series_summable_aux₂ h k,
refine has_sum.sigma this.has_sum (λ l, _),
exact ((nnreal.summable_sigma.1 this).1 l).has_sum
end
/-- The radius of convergence of `p.change_origin x` is at least `p.radius - ‖x‖`. In other words,
`p.change_origin x` is well defined on the largest ball contained in the original ball of
convergence.-/
lemma change_origin_radius : p.radius - ‖x‖₊ ≤ (p.change_origin x).radius :=
begin
refine ennreal.le_of_forall_pos_nnreal_lt (λ r h0 hr, _),
rw [lt_tsub_iff_right, add_comm] at hr,
have hr' : (‖x‖₊ : ℝ≥0∞) < p.radius, from (le_add_right le_rfl).trans_lt hr,
apply le_radius_of_summable_nnnorm,
have : ∀ k : ℕ, ‖p.change_origin x k‖₊ * r ^ k ≤
(∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * ‖x‖₊ ^ s.1) * r ^ k,
from λ k, mul_le_mul_right' (p.nnnorm_change_origin_le k hr') (r ^ k),
refine nnreal.summable_of_le this _,
simpa only [← nnreal.tsum_mul_right]
using (nnreal.summable_sigma.1 (p.change_origin_series_summable_aux₁ hr)).2
end
end
-- From this point on, assume that the space is complete, to make sure that series that converge
-- in norm also converge in `F`.
variables [complete_space F] (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0}
lemma has_fpower_series_on_ball_change_origin (k : ℕ) (hr : 0 < p.radius) :
has_fpower_series_on_ball (λ x, p.change_origin x k) (p.change_origin_series k) 0 p.radius :=
have _ := p.le_change_origin_series_radius k,
((p.change_origin_series k).has_fpower_series_on_ball (hr.trans_le this)).mono hr this
/-- Summing the series `p.change_origin x` at a point `y` gives back `p (x + y)`-/
theorem change_origin_eval (h : (‖x‖₊ + ‖y‖₊ : ℝ≥0∞) < p.radius) :
(p.change_origin x).sum y = (p.sum (x + y)) :=
begin
have radius_pos : 0 < p.radius := lt_of_le_of_lt (zero_le _) h,
have x_mem_ball : x ∈ emetric.ball (0 : E) p.radius,
from mem_emetric_ball_zero_iff.2 ((le_add_right le_rfl).trans_lt h),
have y_mem_ball : y ∈ emetric.ball (0 : E) (p.change_origin x).radius,
{ refine mem_emetric_ball_zero_iff.2 (lt_of_lt_of_le _ p.change_origin_radius),
rwa [lt_tsub_iff_right, add_comm] },
have x_add_y_mem_ball : x + y ∈ emetric.ball (0 : E) p.radius,
{ refine mem_emetric_ball_zero_iff.2 (lt_of_le_of_lt _ h),
exact_mod_cast nnnorm_add_le x y },
set f : (Σ (k l : ℕ), {s : finset (fin (k + l)) // s.card = l}) → F :=
λ s, p.change_origin_series_term s.1 s.2.1 s.2.2 s.2.2.2 (λ _, x) (λ _, y),
have hsf : summable f,
{ refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₁ h) _,
rintro ⟨k, l, s, hs⟩, dsimp only [subtype.coe_mk],
exact p.nnnorm_change_origin_series_term_apply_le _ _ _ _ _ _ },
have hf : has_sum f ((p.change_origin x).sum y),
{ refine has_sum.sigma_of_has_sum ((p.change_origin x).summable y_mem_ball).has_sum (λ k, _) hsf,
{ dsimp only [f],
refine continuous_multilinear_map.has_sum_eval _ _,
have := (p.has_fpower_series_on_ball_change_origin k radius_pos).has_sum x_mem_ball,
rw zero_add at this,
refine has_sum.sigma_of_has_sum this (λ l, _) _,
{ simp only [change_origin_series, continuous_multilinear_map.sum_apply],
apply has_sum_fintype },
{ refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₂
(mem_emetric_ball_zero_iff.1 x_mem_ball) k) (λ s, _),
refine (continuous_multilinear_map.le_op_nnnorm _ _).trans_eq _,
simp } } },
refine hf.unique (change_origin_index_equiv.symm.has_sum_iff.1 _),
refine has_sum.sigma_of_has_sum (p.has_sum x_add_y_mem_ball) (λ n, _)
(change_origin_index_equiv.symm.summable_iff.2 hsf),
erw [(p n).map_add_univ (λ _, x) (λ _, y)],
convert has_sum_fintype _,
ext1 s,
dsimp only [f, change_origin_series_term, (∘), change_origin_index_equiv_symm_apply_fst,
change_origin_index_equiv_symm_apply_snd_fst, change_origin_index_equiv_symm_apply_snd_snd_coe],
rw continuous_multilinear_map.curry_fin_finset_apply_const,
have : ∀ m (hm : n = m), p n (s.piecewise (λ _, x) (λ _, y)) =
p m ((s.map (fin.cast hm).to_equiv.to_embedding).piecewise (λ _, x) (λ _, y)),
{ rintro m rfl, simp },
apply this
end
end formal_multilinear_series
section
variables [complete_space F] {f : E → F} {p : formal_multilinear_series 𝕜 E F} {x y : E}
{r : ℝ≥0∞}
/-- If a function admits a power series expansion `p` on a ball `B (x, r)`, then it also admits a
power series on any subball of this ball (even with a different center), given by `p.change_origin`.
-/
theorem has_fpower_series_on_ball.change_origin
(hf : has_fpower_series_on_ball f p x r) (h : (‖y‖₊ : ℝ≥0∞) < r) :
has_fpower_series_on_ball f (p.change_origin y) (x + y) (r - ‖y‖₊) :=
{ r_le := begin
apply le_trans _ p.change_origin_radius,
exact tsub_le_tsub hf.r_le le_rfl
end,
r_pos := by simp [h],
has_sum := λ z hz, begin
convert (p.change_origin y).has_sum _,
{ rw [mem_emetric_ball_zero_iff, lt_tsub_iff_right, add_comm] at hz,
rw [p.change_origin_eval (hz.trans_le hf.r_le), add_assoc, hf.sum],
refine mem_emetric_ball_zero_iff.2 (lt_of_le_of_lt _ hz),
exact_mod_cast nnnorm_add_le y z },
{ refine emetric.ball_subset_ball (le_trans _ p.change_origin_radius) hz,
exact tsub_le_tsub hf.r_le le_rfl }
end }
/-- If a function admits a power series expansion `p` on an open ball `B (x, r)`, then
it is analytic at every point of this ball. -/
lemma has_fpower_series_on_ball.analytic_at_of_mem
(hf : has_fpower_series_on_ball f p x r) (h : y ∈ emetric.ball x r) :
analytic_at 𝕜 f y :=
begin
have : (‖y - x‖₊ : ℝ≥0∞) < r, by simpa [edist_eq_coe_nnnorm_sub] using h,
have := hf.change_origin this,
rw [add_sub_cancel'_right] at this,
exact this.analytic_at
end
lemma has_fpower_series_on_ball.analytic_on (hf : has_fpower_series_on_ball f p x r) :
analytic_on 𝕜 f (emetric.ball x r) :=
λ y hy, hf.analytic_at_of_mem hy
variables (𝕜 f)
/-- For any function `f` from a normed vector space to a Banach space, the set of points `x` such
that `f` is analytic at `x` is open. -/
lemma is_open_analytic_at : is_open {x | analytic_at 𝕜 f x} :=
begin
rw is_open_iff_mem_nhds,
rintro x ⟨p, r, hr⟩,
exact mem_of_superset (emetric.ball_mem_nhds _ hr.r_pos) (λ y hy, hr.analytic_at_of_mem hy)
end
end
section
open formal_multilinear_series
variables {p : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {z₀ : 𝕜}
/-- A function `f : 𝕜 → E` has `p` as power series expansion at a point `z₀` iff it is the sum of
`p` in a neighborhood of `z₀`. This makes some proofs easier by hiding the fact that
`has_fpower_series_at` depends on `p.radius`. -/
lemma has_fpower_series_at_iff : has_fpower_series_at f p z₀ ↔
∀ᶠ z in 𝓝 0, has_sum (λ n, z ^ n • p.coeff n) (f (z₀ + z)) :=
begin
refine ⟨λ ⟨r, r_le, r_pos, h⟩, eventually_of_mem (emetric.ball_mem_nhds 0 r_pos)
(λ _, by simpa using h), _⟩,
simp only [metric.eventually_nhds_iff],
rintro ⟨r, r_pos, h⟩,
refine ⟨p.radius ⊓ r.to_nnreal, by simp, _, _⟩,
{ simp only [r_pos.lt, lt_inf_iff, ennreal.coe_pos, real.to_nnreal_pos, and_true],
obtain ⟨z, z_pos, le_z⟩ := normed_field.exists_norm_lt 𝕜 r_pos.lt,
have : (‖z‖₊ : ennreal) ≤ p.radius,
by { simp only [dist_zero_right] at h,
apply formal_multilinear_series.le_radius_of_tendsto,
convert tendsto_norm.comp (h le_z).summable.tendsto_at_top_zero,
funext; simp [norm_smul, mul_comm] },
refine lt_of_lt_of_le _ this,
simp only [ennreal.coe_pos],
exact zero_lt_iff.mpr (nnnorm_ne_zero_iff.mpr (norm_pos_iff.mp z_pos)) },
{ simp only [emetric.mem_ball, lt_inf_iff, edist_lt_coe, apply_eq_pow_smul_coeff, and_imp,
dist_zero_right] at h ⊢,
refine λ y hyp hyr, h _,
simpa [nndist_eq_nnnorm, real.lt_to_nnreal_iff_coe_lt] using hyr }
end
lemma has_fpower_series_at_iff' : has_fpower_series_at f p z₀ ↔
∀ᶠ z in 𝓝 z₀, has_sum (λ n, (z - z₀) ^ n • p.coeff n) (f z) :=
begin
rw [← map_add_left_nhds_zero, eventually_map, has_fpower_series_at_iff],
congrm ∀ᶠ z in (𝓝 0 : filter 𝕜), has_sum (λ n, _) (f (z₀ + z)),
rw add_sub_cancel'
end
end
|
1a45ac2e3350d6c146587e84b610a052b69831b9 | eb9357a70318e50e095b58730bebfe0cffee457f | /lean/love05_inductive_predicates_demo.lean | ccab0c8734c8e7545204f7c257aa0cd86b54541a | [] | no_license | Vierkantor/logical_verification_2021 | 7485dd916953131d501760f023d5b30fbb74d36a | 9500b9c194e22a9ab4067321cfed7a1f445afcfc | refs/heads/main | 1,692,560,845,086 | 1,624,721,275,000 | 1,624,721,275,000 | 416,354,079 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,796 | lean | import .love03_forward_proofs_demo
import .love04_functional_programming_demo
/-! # LoVe Demo 5: Inductive Predicates
__Inductive predicates__, or inductively defined propositions, are a convenient
way to specify functions of type `⋯ → Prop`. They are reminiscent of formal
systems and of the Horn clauses of Prolog, the logic programming language par
excellence.
A possible view of Lean:
Lean = functional programming + logic programming + more logic -/
set_option pp.beta true
set_option pp.generalized_field_notation false
namespace LoVe
/-! ## Introductory Examples
### Even Numbers
Mathematicians often define sets as the smallest that meets some criteria. For
example:
The set `E` of even natural numbers is defined as the smallest set closed
under the following rules: (1) `0 ∈ E` and (2) for every `k ∈ ℕ`, if
`k ∈ E`, then `k + 2 ∈ E`.
In Lean, we can define the corresponding "is even" predicate as follows: -/
inductive even : ℕ → Prop
| zero : even 0
| add_two : ∀k : ℕ, even k → even (k + 2)
/-! This should look familiar. We have used the same syntax, except with `Type`
instead of `Prop`, for inductive types.
The above command introduces a new unary predicate `even` as well as two
constructors, `even.zero` and `even.add_two`, which can be used to build proof
terms. Thanks to the "no junk" guarantee of inductive definitions, `even.zero`
and `even.add_two` are the only two ways to construct proofs of `even`.
By the PAT principle, `even` can be seen as an inductive type, the values being
the proof terms. -/
lemma even_4 :
even 4 :=
have even_0 : even 0 :=
even.zero,
have even_2 : even 2 :=
even.add_two _ even_0,
show even 4, from
even.add_two _ even_2
/-! Why cannot we simply define `even` recursively? Indeed, why not? -/
def even₂ : ℕ → bool
| 0 := tt
| 1 := ff
| (k + 2) := even₂ k
/-! There are advantages and disadvantages to both styles.
The recursive version requires us to specify a false case (1), and it requires
us to worry about termination. On the other hand, because it is computational,
it works well with `refl`, `simp`, `#reduce`, and `#eval`.
The inductive version is often considered more abstract and elegant. Each rule
is stated independently of the others.
Yet another way to define `even` is as a nonrecursive definition: -/
def even₃ (k : ℕ) : bool :=
k % 2 = 0
/-! Mathematicians would probably find this the most satisfactory definition.
But the inductive version is a convenient, intuitive example that is typical of
many realistic inductive definitions.
### Tennis Games
Transition systems consists of transition rules, which together specify a
binary predicate connecting a "before" and an "after" state. As a simple
specimen of a transition system, we consider the possible transitions, in a game
of tennis, starting from 0–0. -/
inductive score : Type
| vs : ℕ → ℕ → score
| adv_srv : score
| adv_rcv : score
| game_srv : score
| game_rcv : score
infixr ` – ` : 10 := score.vs
inductive step : score → score → Prop
| srv_0_15 : ∀n, step (0–n) (15–n)
| srv_15_30 : ∀n, step (15–n) (30–n)
| srv_30_40 : ∀n, step (30–n) (40–n)
| srv_40_game : ∀n, n < 40 → step (40–n) score.game_srv
| srv_40_adv : step (40–40) score.adv_srv
| srv_adv_40 : step score.adv_srv (40–40)
| rcv_0_15 : ∀n, step (n–0) (n–15)
| rcv_15_30 : ∀n, step (n–15) (n–30)
| rcv_30_40 : ∀n, step (n–30) (n–40)
| rcv_40_game : ∀n, n < 40 → step (n–40) score.game_rcv
| rcv_40_adv : step (40–40) score.adv_rcv
| rcv_adv_40 : step score.adv_rcv (40–40)
infixr ` ⇒ ` := step
/-! We can ask, and formally answer, questions such as: Can the score ever
return to 0–0? -/
lemma no_step_to_0_0 (s : score) :
¬ step s (0–0) :=
begin
intro h,
cases h
end
/-! ### Reflexive Transitive Closure
Our last introductory example is the reflexive transitive closure of a
relation `r`, modeled as a binary predicate `star r`. -/
inductive star {α : Type} (r : α → α → Prop) : α → α → Prop
| base (a b : α) : r a b → star a b
| refl (a : α) : star a a
| trans (a b c : α) : star a b → star b c → star a c
/-! The first rule embeds `r` into `star r`. The second rule achieves the
reflexive closure. The third rule achieves the transitive closure.
The definition is truly elegant. If you doubt this, try implementing `star` as a
recursive function: -/
def star_rec {α : Type} (r : α → α → bool) :
α → α → bool :=
sorry
/-! ### A Nonexample
Not all inductive definitions admit a least solution. -/
-- fails
inductive illegal₂ : Prop
| intro : ¬ illegal₂ → illegal₂
/-! ## Logical Symbols
The truth values `false` and `true`, the connectives `∧` and `∨`, the
`∃`-quantifier, and the equality predicate `=` are all defined as inductive
propositions or predicates. In contrast, `∀` (= `Π`) and `→` are built into
the logic.
Syntactic sugar:
`∃x : α, p` := `Exists (λx : α, p)`
`x = y` := `eq x y` -/
namespace logical_symbols
inductive and (a b : Prop) : Prop
| intro : a → b → and
inductive or (a b : Prop) : Prop
| intro_left : a → or
| intro_right : b → or
inductive iff (a b : Prop) : Prop
| intro : (a → b) → (b → a) → iff
inductive Exists {α : Type} (p : α → Prop) : Prop
| intro : ∀a : α, p a → Exists
inductive true : Prop
| intro : true
inductive false : Prop
inductive eq {α : Type} : α → α → Prop
| refl : ∀a : α, eq a a
end logical_symbols
#print and
#print or
#print iff
#print Exists
#print true
#print false
#print eq
/-! ## Rule Induction
Just as we can perform induction on a term, we can perform induction on a proof
term.
This is called __rule induction__, because the induction is on the introduction
rules (i.e., the constructors of the proof term). Thanks to the PAT principle,
this works as expected. -/
lemma mod_two_eq_zero_of_even (n : ℕ) (h : even n) :
n % 2 = 0 :=
begin
induction' h,
case zero {
refl },
case add_two : k hk ih {
simp [ih] }
end
lemma not_even_two_mul_add_one (n : ℕ) :
¬ even (2 * n + 1) :=
begin
intro h,
induction' h,
apply ih (n - 1),
cases' n,
case zero {
linarith },
case succ {
simp [nat.succ_eq_add_one] at *,
linarith }
end
/-! `linarith` proves goals involving linear arithmetic equalities or
inequalities. "Linear" means it works only with `+` and `-`, not `*` and `/`
(but multiplication by a constant is supported). -/
lemma linarith_example (i : ℤ) (hi : i > 5) :
2 * i + 3 > 11 :=
by linarith
lemma star_star_iff_star {α : Type} (r : α → α → Prop)
(a b : α) :
star (star r) a b ↔ star r a b :=
begin
apply iff.intro,
{ intro h,
induction' h,
case base : a b hab {
exact hab },
case refl : a {
apply star.refl },
case trans : a b c hab hbc ihab ihbc {
apply star.trans a b,
{ exact ihab },
{ exact ihbc } } },
{ intro h,
apply star.base,
exact h }
end
@[simp] lemma star_star_eq_star {α : Type}
(r : α → α → Prop) :
star (star r) = star r :=
begin
apply funext,
intro a,
apply funext,
intro b,
apply propext,
apply star_star_iff_star
end
#check funext
#check propext
/-! ## Elimination
Given an inductive predicate `p`, its introduction rules typically have the form
`∀…, ⋯ → p …` and can be used to prove goals of the form `⊢ p …`.
Elimination works the other way around: It extracts information from a lemma or
hypothesis of the form `p …`. Elimination takes various forms: pattern matching,
the `cases'` and `induction'` tactics, and custom elimination rules (e.g.,
`and.elim_left`).
* `cases'` works like `induction'` but without induction hypothesis.
* `match` is available as well, but it corresponds to dependently typed pattern
matching (cf. `vector` in lecture 4).
Now we can finally analyze how `cases' h`, where `h : l = r`, and how
`cases' classical.em h` work. -/
#print eq
lemma cases_eq_example {α : Type} (l r : α) (h : l = r)
(p : α → α → Prop) :
p l r :=
begin
cases' h,
sorry
end
#check classical.em
#print or
lemma cases_classical_em_example {α : Type} (a : α)
(p q : α → Prop) :
q a :=
begin
have h : p a ∨ ¬ p a :=
classical.em (p a),
cases' h,
case inl {
sorry },
case inr {
sorry }
end
/-! Often it is convenient to rewrite concrete terms of the form `p (c …)`,
where `c` is typically a constructor. We can state and prove an
__inversion rule__ to support such eliminative reasoning.
Typical inversion rule:
`∀x y, p (c x y) → (∃…, ⋯ ∧ ⋯) ∨ ⋯ ∨ (∃…, ⋯ ∧ ⋯)`
It can be useful to combine introduction and elimination into a single lemma,
which can be used for rewriting both the hypotheses and conclusions of goals:
`∀x y, p (c x y) ↔ (∃…, ⋯ ∧ ⋯) ∨ ⋯ ∨ (∃…, ⋯ ∧ ⋯)` -/
lemma even_iff (n : ℕ) :
even n ↔ n = 0 ∨ (∃m : ℕ, n = m + 2 ∧ even m) :=
begin
apply iff.intro,
{ intro hn,
cases' hn,
case zero {
simp },
case add_two : k hk {
apply or.intro_right,
apply exists.intro k,
simp [hk] } },
{ intro hor,
cases' hor,
case inl : heq {
simp [heq, even.zero] },
case inr : hex {
cases' hex with k hand,
cases' hand with heq hk,
simp [heq, even.add_two _ hk] } }
end
lemma even_iff₂ (n : ℕ) :
even n ↔ n = 0 ∨ (∃m : ℕ, n = m + 2 ∧ even m) :=
iff.intro
(assume hn : even n,
match n, hn with
| _, even.zero :=
show 0 = 0 ∨ _, from
by simp
| _, even.add_two k hk :=
show _ ∨ (∃m, k + 2 = m + 2 ∧ even m), from
or.intro_right _ (exists.intro k (by simp [*]))
end)
(assume hor : n = 0 ∨ (∃m, n = m + 2 ∧ even m),
match hor with
| or.inl heq :=
show even n, from
by simp [heq, even.zero]
| or.inr hex :=
match hex with
| Exists.intro m hand :=
match hand with
| and.intro heq hm :=
show even n, from
by simp [heq, even.add_two _ hm]
end
end
end)
/-! ## Further Examples
### Sorted Lists -/
inductive sorted : list ℕ → Prop
| nil : sorted []
| single {x : ℕ} : sorted [x]
| two_or_more {x y : ℕ} {zs : list ℕ} (hle : x ≤ y)
(hsorted : sorted (y :: zs)) :
sorted (x :: y :: zs)
lemma sorted_nil :
sorted [] :=
sorted.nil
lemma sorted_2 :
sorted [2] :=
sorted.single
lemma sorted_3_5 :
sorted [3, 5] :=
begin
apply sorted.two_or_more,
{ linarith },
{ exact sorted.single }
end
lemma sorted_3_5₂ :
sorted [3, 5] :=
sorted.two_or_more (by linarith) sorted.single
lemma sorted_7_9_9_11 :
sorted [7, 9, 9, 11] :=
sorted.two_or_more (by linarith)
(sorted.two_or_more (by linarith)
(sorted.two_or_more (by linarith)
sorted.single))
lemma not_sorted_17_13 :
¬ sorted [17, 13] :=
begin
intro h,
cases' h,
linarith
end
/-! ### Palindromes -/
inductive palindrome {α : Type} : list α → Prop
| nil : palindrome []
| single (x : α) : palindrome [x]
| sandwich (x : α) (xs : list α) (hxs : palindrome xs) :
palindrome ([x] ++ xs ++ [x])
-- fails
def palindrome₂ {α : Type} : list α → Prop
| [] := true
| [_] := true
| ([x] ++ xs ++ [x]) := palindrome₂ xs
| _ := false
lemma palindrome_aa {α : Type} (a : α) :
palindrome [a, a] :=
palindrome.sandwich a _ palindrome.nil
lemma palindrome_aba {α : Type} (a b : α) :
palindrome [a, b, a] :=
palindrome.sandwich a _ (palindrome.single b)
lemma reverse_palindrome {α : Type} (xs : list α)
(hxs : palindrome xs) :
palindrome (reverse xs) :=
begin
induction' hxs,
case nil {
exact palindrome.nil },
case single {
exact palindrome.single x },
case sandwich {
simp [reverse, reverse_append],
exact palindrome.sandwich _ _ ih }
end
/-! ### Full Binary Trees -/
#check btree
inductive is_full {α : Type} : btree α → Prop
| empty : is_full btree.empty
| node (a : α) (l r : btree α)
(hl : is_full l) (hr : is_full r)
(hiff : l = btree.empty ↔ r = btree.empty) :
is_full (btree.node a l r)
lemma is_full_singleton {α : Type} (a : α) :
is_full (btree.node a btree.empty btree.empty) :=
begin
apply is_full.node,
{ exact is_full.empty },
{ exact is_full.empty },
{ refl }
end
lemma is_full_mirror {α : Type} (t : btree α)
(ht : is_full t) :
is_full (mirror t) :=
begin
induction' ht,
case empty {
exact is_full.empty },
case node : a l r hl hr hiff ih_l ih_r {
rw mirror,
apply is_full.node,
{ exact ih_r },
{ exact ih_l },
{ simp [mirror_eq_empty_iff, *] } }
end
lemma is_full_mirror₂ {α : Type} (t : btree α) :
is_full t → is_full (mirror t) :=
begin
induction' t,
case empty {
intro ht,
exact ht },
case node : a l r ih_l ih_r {
intro ht,
cases' ht with _ _ _ hl hr hiff,
rw mirror,
apply is_full.node,
{ exact ih_r hr },
{ apply ih_l hl },
{ simp [mirror_eq_empty_iff, *] } }
end
/-! ### First-Order Terms -/
inductive term (α β : Type) : Type
| var {} : β → term
| fn : α → list term → term
inductive well_formed {α β : Type} (arity : α → ℕ) :
term α β → Prop
| var (x : β) : well_formed (term.var x)
| fn (f : α) (ts : list (term α β))
(hargs : ∀t ∈ ts, well_formed t)
(hlen : list.length ts = arity f) :
well_formed (term.fn f ts)
inductive variable_free {α β : Type} : term α β → Prop
| fn (f : α) (ts : list (term α β))
(hargs : ∀t ∈ ts, variable_free t) :
variable_free (term.fn f ts)
end LoVe
|
417028172430a9e3cc557051fa7e89942363bc63 | fecda8e6b848337561d6467a1e30cf23176d6ad0 | /src/measure_theory/lebesgue_measure.lean | 9e80a9032294e6aef1ec6b84faa9cdb129c1b68f | [
"Apache-2.0"
] | permissive | spolu/mathlib | bacf18c3d2a561d00ecdc9413187729dd1f705ed | 480c92cdfe1cf3c2d083abded87e82162e8814f4 | refs/heads/master | 1,671,684,094,325 | 1,600,736,045,000 | 1,600,736,045,000 | 297,564,749 | 1 | 0 | null | 1,600,758,368,000 | 1,600,758,367,000 | null | UTF-8 | Lean | false | false | 13,723 | 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 measure_theory.measure_space
import measure_theory.borel_space
/-!
# Lebesgue measure on the real line
-/
noncomputable theory
open classical set filter
open ennreal (of_real)
open_locale big_operators
namespace measure_theory
/-- Length of an interval. This is the largest monotonic function which correctly
measures all intervals. -/
def lebesgue_length (s : set ℝ) : ennreal := ⨅a b (h : s ⊆ Ico a b), of_real (b - a)
@[simp] lemma lebesgue_length_empty : lebesgue_length ∅ = 0 :=
le_zero_iff_eq.1 $ infi_le_of_le 0 $ infi_le_of_le 0 $ by simp
@[simp] lemma lebesgue_length_Ico (a b : ℝ) :
lebesgue_length (Ico a b) = of_real (b - a) :=
begin
refine le_antisymm (infi_le_of_le a $ binfi_le b (subset.refl _))
(le_infi $ λ a', le_infi $ λ b', le_infi $ λ h, ennreal.coe_le_coe.2 _),
cases le_or_lt b a with ab ab,
{ rw nnreal.of_real_of_nonpos (sub_nonpos.2 ab), apply zero_le },
cases (Ico_subset_Ico_iff ab).1 h with h₁ h₂,
exact nnreal.of_real_le_of_real (sub_le_sub h₂ h₁)
end
lemma lebesgue_length_mono {s₁ s₂ : set ℝ} (h : s₁ ⊆ s₂) :
lebesgue_length s₁ ≤ lebesgue_length s₂ :=
infi_le_infi $ λ a, infi_le_infi $ λ b, infi_le_infi2 $ λ h', ⟨subset.trans h h', le_refl _⟩
lemma lebesgue_length_eq_infi_Ioo (s) :
lebesgue_length s = ⨅a b (h : s ⊆ Ioo a b), of_real (b - a) :=
begin
refine le_antisymm
(infi_le_infi $ λ a, infi_le_infi $ λ b, infi_le_infi2 $ λ h,
⟨subset.trans h Ioo_subset_Ico_self, le_refl _⟩) _,
refine le_infi (λ a, le_infi $ λ b, le_infi $ λ h, _),
refine ennreal.le_of_forall_epsilon_le (λ ε ε0 _, _),
refine infi_le_of_le (a - ε) (infi_le_of_le b $ infi_le_of_le
(subset.trans h $ Ico_subset_Ioo_left $ (sub_lt_self_iff _).2 ε0) _),
rw ← sub_add,
refine le_trans ennreal.of_real_add_le (add_le_add_left _ _),
simp only [ennreal.of_real_coe_nnreal, le_refl]
end
@[simp] lemma lebesgue_length_Ioo (a b : ℝ) :
lebesgue_length (Ioo a b) = of_real (b - a) :=
begin
rw ← lebesgue_length_Ico,
refine le_antisymm (lebesgue_length_mono Ioo_subset_Ico_self) _,
rw lebesgue_length_eq_infi_Ioo (Ioo a b),
refine (le_infi $ λ a', le_infi $ λ b', le_infi $ λ h, _),
cases le_or_lt b a with ab ab, {simp [ab]},
cases (Ioo_subset_Ioo_iff ab).1 h with h₁ h₂,
rw [lebesgue_length_Ico],
exact ennreal.of_real_le_of_real (sub_le_sub h₂ h₁)
end
lemma lebesgue_length_eq_infi_Icc (s) :
lebesgue_length s = ⨅a b (h : s ⊆ Icc a b), of_real (b - a) :=
begin
refine le_antisymm _
(infi_le_infi $ λ a, infi_le_infi $ λ b, infi_le_infi2 $ λ h,
⟨subset.trans h Ico_subset_Icc_self, le_refl _⟩),
refine le_infi (λ a, le_infi $ λ b, le_infi $ λ h, _),
refine ennreal.le_of_forall_epsilon_le (λ ε ε0 _, _),
refine infi_le_of_le a (infi_le_of_le (b + ε) $ infi_le_of_le
(subset.trans h $ Icc_subset_Ico_right $ (lt_add_iff_pos_right _).2 ε0) _),
rw [← sub_add_eq_add_sub],
refine le_trans ennreal.of_real_add_le (add_le_add_left _ _),
simp only [ennreal.of_real_coe_nnreal, le_refl]
end
@[simp] lemma lebesgue_length_Icc (a b : ℝ) :
lebesgue_length (Icc a b) = of_real (b - a) :=
begin
rw ← lebesgue_length_Ico,
refine le_antisymm _ (lebesgue_length_mono Ico_subset_Icc_self),
rw lebesgue_length_eq_infi_Icc (Icc a b),
exact infi_le_of_le a (infi_le_of_le b $ infi_le_of_le (by refl) (by simp [le_refl]))
end
/-- The Lebesgue outer measure, as an outer measure of ℝ. -/
def lebesgue_outer : outer_measure ℝ :=
outer_measure.of_function lebesgue_length lebesgue_length_empty
lemma lebesgue_outer_le_length (s : set ℝ) : lebesgue_outer s ≤ lebesgue_length s :=
outer_measure.of_function_le _
lemma lebesgue_length_subadditive {a b : ℝ} {c d : ℕ → ℝ}
(ss : Icc a b ⊆ ⋃i, Ioo (c i) (d i)) :
(of_real (b - a) : ennreal) ≤ ∑' i, of_real (d i - c i) :=
begin
suffices : ∀ (s:finset ℕ) b
(cv : Icc a b ⊆ ⋃ i ∈ (↑s:set ℕ), Ioo (c i) (d i)),
(of_real (b - a) : ennreal) ≤ ∑ i in s, of_real (d i - c i),
{ rcases compact_Icc.elim_finite_subcover_image (λ (i : ℕ) (_ : i ∈ univ),
@is_open_Ioo _ _ _ _ (c i) (d i)) (by simpa using ss) with ⟨s, su, hf, hs⟩,
have e : (⋃ i ∈ (↑hf.to_finset:set ℕ),
Ioo (c i) (d i)) = (⋃ i ∈ s, Ioo (c i) (d i)), {simp [set.ext_iff]},
rw ennreal.tsum_eq_supr_sum,
refine le_trans _ (le_supr _ hf.to_finset),
exact this hf.to_finset _ (by simpa [e]) },
clear ss b,
refine λ s, finset.strong_induction_on s (λ s IH b cv, _),
cases le_total b a with ab ab,
{ rw ennreal.of_real_eq_zero.2 (sub_nonpos.2 ab), exact zero_le _ },
have := cv ⟨ab, le_refl _⟩, simp at this,
rcases this with ⟨i, is, cb, bd⟩,
rw [← finset.insert_erase is] at cv ⊢,
rw [finset.coe_insert, bUnion_insert] at cv,
rw [finset.sum_insert (finset.not_mem_erase _ _)],
refine le_trans _ (add_le_add_left (IH _ (finset.erase_ssubset is) (c i) _) _),
{ refine le_trans (ennreal.of_real_le_of_real _) ennreal.of_real_add_le,
rw sub_add_sub_cancel,
exact sub_le_sub_right (le_of_lt bd) _ },
{ rintro x ⟨h₁, h₂⟩,
refine (cv ⟨h₁, le_trans h₂ (le_of_lt cb)⟩).resolve_left
(mt and.left (not_lt_of_le h₂)) }
end
@[simp] lemma lebesgue_outer_Icc (a b : ℝ) :
lebesgue_outer (Icc a b) = of_real (b - a) :=
begin
refine le_antisymm (by rw ← lebesgue_length_Icc; apply lebesgue_outer_le_length)
(le_binfi $ λ f hf, ennreal.le_of_forall_epsilon_le $ λ ε ε0 h, _),
rcases ennreal.exists_pos_sum_of_encodable
(ennreal.zero_lt_coe_iff.2 ε0) ℕ with ⟨ε', ε'0, hε⟩,
refine le_trans _ (add_le_add_left (le_of_lt hε) _),
rw ← ennreal.tsum_add,
choose g hg using show
∀ i, ∃ p:ℝ×ℝ, f i ⊆ Ioo p.1 p.2 ∧ (of_real (p.2 - p.1) : ennreal) < lebesgue_length (f i) + ε' i,
{ intro i,
have := (ennreal.lt_add_right (lt_of_le_of_lt (ennreal.le_tsum i) h)
(ennreal.zero_lt_coe_iff.2 (ε'0 i))),
conv at this {to_lhs, rw lebesgue_length_eq_infi_Ioo},
simpa [infi_lt_iff] },
refine le_trans _ (ennreal.tsum_le_tsum $ λ i, le_of_lt (hg i).2),
exact lebesgue_length_subadditive (subset.trans hf $
Union_subset_Union $ λ i, (hg i).1)
end
@[simp] lemma lebesgue_outer_singleton (a : ℝ) : lebesgue_outer {a} = 0 :=
by simpa using lebesgue_outer_Icc a a
@[simp] lemma lebesgue_outer_Ico (a b : ℝ) :
lebesgue_outer (Ico a b) = of_real (b - a) :=
by rw [← Icc_diff_right, lebesgue_outer.diff_null _ (lebesgue_outer_singleton _),
lebesgue_outer_Icc]
@[simp] lemma lebesgue_outer_Ioo (a b : ℝ) :
lebesgue_outer (Ioo a b) = of_real (b - a) :=
by rw [← Ico_diff_left, lebesgue_outer.diff_null _ (lebesgue_outer_singleton _), lebesgue_outer_Ico]
@[simp] lemma lebesgue_outer_Ioc (a b : ℝ) :
lebesgue_outer (Ioc a b) = of_real (b - a) :=
by rw [← Icc_diff_left, lebesgue_outer.diff_null _ (lebesgue_outer_singleton _), lebesgue_outer_Icc]
lemma is_lebesgue_measurable_Iio {c : ℝ} :
lebesgue_outer.caratheodory.is_measurable (Iio c) :=
outer_measure.of_function_caratheodory $ λ t,
le_infi $ λ a, le_infi $ λ b, le_infi $ λ h, begin
refine le_trans (add_le_add
(lebesgue_length_mono $ inter_subset_inter_left _ h)
(lebesgue_length_mono $ diff_subset_diff_left h)) _,
cases le_total a c with hac hca; cases le_total b c with hbc hcb;
simp [*, -sub_eq_add_neg, sub_add_sub_cancel', le_refl],
{ simp [*, ← ennreal.of_real_add, -sub_eq_add_neg, sub_add_sub_cancel', le_refl] },
{ simp only [ennreal.of_real_eq_zero.2 (sub_nonpos.2 (le_trans hbc hca)), zero_add, le_refl] }
end
theorem lebesgue_outer_trim : lebesgue_outer.trim = lebesgue_outer :=
begin
refine le_antisymm (λ s, _) (outer_measure.le_trim _),
rw outer_measure.trim_eq_infi,
refine le_infi (λ f, le_infi $ λ hf,
ennreal.le_of_forall_epsilon_le $ λ ε ε0 h, _),
rcases ennreal.exists_pos_sum_of_encodable
(ennreal.zero_lt_coe_iff.2 ε0) ℕ with ⟨ε', ε'0, hε⟩,
refine le_trans _ (add_le_add_left (le_of_lt hε) _),
rw ← ennreal.tsum_add,
choose g hg using show
∀ i, ∃ s, f i ⊆ s ∧ is_measurable s ∧ lebesgue_outer s ≤ lebesgue_length (f i) + of_real (ε' i),
{ intro i,
have := (ennreal.lt_add_right (lt_of_le_of_lt (ennreal.le_tsum i) h)
(ennreal.zero_lt_coe_iff.2 (ε'0 i))),
conv at this {to_lhs, rw lebesgue_length},
simp only [infi_lt_iff] at this,
rcases this with ⟨a, b, h₁, h₂⟩,
rw ← lebesgue_outer_Ico at h₂,
exact ⟨_, h₁, is_measurable_Ico, le_of_lt $ by simpa using h₂⟩ },
simp at hg,
apply infi_le_of_le (Union g) _,
apply infi_le_of_le (subset.trans hf $ Union_subset_Union (λ i, (hg i).1)) _,
apply infi_le_of_le (is_measurable.Union (λ i, (hg i).2.1)) _,
exact le_trans (lebesgue_outer.Union _) (ennreal.tsum_le_tsum $ λ i, (hg i).2.2)
end
lemma borel_le_lebesgue_measurable : borel ℝ ≤ lebesgue_outer.caratheodory :=
begin
rw real.borel_eq_generate_from_Iio_rat,
refine measurable_space.generate_from_le _,
simp [is_lebesgue_measurable_Iio] { contextual := tt }
end
/-- Lebesgue measure on the Borel sets
The outer Lebesgue measure is the completion of this measure. (TODO: proof this)
-/
instance real.measure_space : measure_space ℝ :=
⟨{to_outer_measure := lebesgue_outer,
m_Union := λ f hf, lebesgue_outer.Union_eq_of_caratheodory $
λ i, borel_le_lebesgue_measurable _ (hf i),
trimmed := lebesgue_outer_trim }⟩
@[simp] theorem lebesgue_to_outer_measure :
(volume : measure ℝ).to_outer_measure = lebesgue_outer := rfl
end measure_theory
open measure_theory
namespace real
open_locale topological_space
theorem volume_val (s) : volume s = lebesgue_outer s := rfl
instance has_no_atoms_volume : has_no_atoms (volume : measure ℝ) :=
⟨lebesgue_outer_singleton⟩
@[simp] lemma volume_Ico {a b : ℝ} : volume (Ico a b) = of_real (b - a) := lebesgue_outer_Ico a b
@[simp] lemma volume_Icc {a b : ℝ} : volume (Icc a b) = of_real (b - a) := lebesgue_outer_Icc a b
@[simp] lemma volume_Ioo {a b : ℝ} : volume (Ioo a b) = of_real (b - a) := lebesgue_outer_Ioo a b
@[simp] lemma volume_Ioc {a b : ℝ} : volume (Ioc a b) = of_real (b - a) := lebesgue_outer_Ioc a b
@[simp] lemma volume_singleton {a : ℝ} : volume ({a} : set ℝ) = 0 := lebesgue_outer_singleton a
@[simp] lemma volume_interval {a b : ℝ} : volume (interval a b) = of_real (abs (b - a)) :=
by rw [interval, volume_Icc, max_sub_min_eq_abs]
instance locally_finite_volume : locally_finite_measure (volume : measure ℝ) :=
⟨λ x, ⟨Ioo (x - 1) (x + 1),
mem_nhds_sets is_open_Ioo ⟨sub_lt_self _ zero_lt_one, lt_add_of_pos_right _ zero_lt_one⟩,
by simp only [real.volume_Ioo, ennreal.of_real_lt_top]⟩⟩
lemma map_volume_add_left (a : ℝ) : measure.map ((+) a) volume = volume :=
eq.symm $ real.measure_ext_Ioo_rat $ λ p q,
by simp [measure.map_apply (measurable_add_left a) is_measurable_Ioo, sub_sub_sub_cancel_right]
lemma map_volume_add_right (a : ℝ) : measure.map (+ a) volume = volume :=
by simpa only [add_comm] using real.map_volume_add_left a
lemma smul_map_volume_mul_left {a : ℝ} (h : a ≠ 0) :
ennreal.of_real (abs a) • measure.map ((*) a) volume = volume :=
begin
refine (real.measure_ext_Ioo_rat $ λ p q, _).symm,
cases lt_or_gt_of_ne h with h h,
{ simp only [real.volume_Ioo, measure.smul_apply, ← ennreal.of_real_mul (le_of_lt $ neg_pos.2 h),
measure.map_apply (measurable_mul_left a) is_measurable_Ioo, neg_sub_neg,
← neg_mul_eq_neg_mul, preimage_const_mul_Ioo_of_neg _ _ h, abs_of_neg h, mul_sub,
mul_div_cancel' _ (ne_of_lt h)] },
{ simp only [real.volume_Ioo, measure.smul_apply, ← ennreal.of_real_mul (le_of_lt h),
measure.map_apply (measurable_mul_left a) is_measurable_Ioo, preimage_const_mul_Ioo _ _ h,
abs_of_pos h, mul_sub, mul_div_cancel' _ (ne_of_gt h)] }
end
lemma map_volume_mul_left {a : ℝ} (h : a ≠ 0) :
measure.map ((*) a) volume = ennreal.of_real (abs a⁻¹) • volume :=
by conv_rhs { rw [← real.smul_map_volume_mul_left h, smul_smul,
← ennreal.of_real_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel h, abs_one, ennreal.of_real_one,
one_smul] }
lemma smul_map_volume_mul_right {a : ℝ} (h : a ≠ 0) :
ennreal.of_real (abs a) • measure.map (* a) volume = volume :=
by simpa only [mul_comm] using real.smul_map_volume_mul_left h
lemma map_volume_mul_right {a : ℝ} (h : a ≠ 0) :
measure.map (* a) volume = ennreal.of_real (abs a⁻¹) • volume :=
by simpa only [mul_comm] using real.map_volume_mul_left h
@[simp] lemma map_volume_neg : measure.map has_neg.neg (volume : measure ℝ) = volume :=
eq.symm $ real.measure_ext_Ioo_rat $ λ p q,
by simp [measure.map_apply measurable_neg is_measurable_Ioo]
end real
/-
section vitali
def vitali_aux_h (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) :
∃ y ∈ Icc (0:ℝ) 1, ∃ q:ℚ, ↑q = x - y :=
⟨x, h, 0, by simp⟩
def vitali_aux (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : ℝ :=
classical.some (vitali_aux_h x h)
theorem vitali_aux_mem (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) : vitali_aux x h ∈ Icc (0:ℝ) 1 :=
Exists.fst (classical.some_spec (vitali_aux_h x h):_)
theorem vitali_aux_rel (x : ℝ) (h : x ∈ Icc (0:ℝ) 1) :
∃ q:ℚ, ↑q = x - vitali_aux x h :=
Exists.snd (classical.some_spec (vitali_aux_h x h):_)
def vitali : set ℝ := {x | ∃ h, x = vitali_aux x h}
theorem vitali_nonmeasurable : ¬ is_null_measurable measure_space.μ vitali :=
sorry
end vitali
-/
|
2fc90e12b8bf4559b9bfe50bdcb2251bdbd837a0 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /hott/hit/colimit.hlean | 333c17068cee93ef8fdddfc49ac0da2c8c1739d0 | [
"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 | 7,910 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Definition of general colimits and sequential colimits.
-/
/- definition of a general colimit -/
open eq nat quotient sigma equiv is_trunc
namespace colimit
section
parameters {I J : Type} (A : I → Type) (dom cod : J → I)
(f : Π(j : J), A (dom j) → A (cod j))
variables {i : I} (a : A i) (j : J) (b : A (dom j))
local abbreviation B := Σ(i : I), A i
inductive colim_rel : B → B → Type :=
| Rmk : Π{j : J} (a : A (dom j)), colim_rel ⟨cod j, f j a⟩ ⟨dom j, a⟩
open colim_rel
local abbreviation R := colim_rel
-- TODO: define this in root namespace
definition colimit : Type :=
quotient colim_rel
definition incl : colimit :=
class_of R ⟨i, a⟩
abbreviation ι := @incl
definition cglue : ι (f j b) = ι b :=
eq_of_rel colim_rel (Rmk f b)
protected definition rec {P : colimit → Type}
(Pincl : Π⦃i : I⦄ (x : A i), P (ι x))
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) =[cglue j x] Pincl x)
(y : colimit) : P y :=
begin
fapply (quotient.rec_on y),
{ intro a, cases a, apply Pincl},
{ intro a a' H, cases H, apply Pglue}
end
protected definition rec_on [reducible] {P : colimit → Type} (y : colimit)
(Pincl : Π⦃i : I⦄ (x : A i), P (ι x))
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) =[cglue j x] Pincl x) : P y :=
rec Pincl Pglue y
theorem rec_cglue {P : colimit → Type}
(Pincl : Π⦃i : I⦄ (x : A i), P (ι x))
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) =[cglue j x] Pincl x)
{j : J} (x : A (dom j)) : apd (rec Pincl Pglue) (cglue j x) = Pglue j x :=
!rec_eq_of_rel
protected definition elim {P : Type} (Pincl : Π⦃i : I⦄ (x : A i), P)
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) = Pincl x) (y : colimit) : P :=
rec Pincl (λj a, pathover_of_eq _ (Pglue j a)) y
protected definition elim_on [reducible] {P : Type} (y : colimit)
(Pincl : Π⦃i : I⦄ (x : A i), P)
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) = Pincl x) : P :=
elim Pincl Pglue y
theorem elim_cglue {P : Type}
(Pincl : Π⦃i : I⦄ (x : A i), P)
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) = Pincl x)
{j : J} (x : A (dom j)) : ap (elim Pincl Pglue) (cglue j x) = Pglue j x :=
begin
apply eq_of_fn_eq_fn_inv !(pathover_constant (cglue j x)),
rewrite [▸*,-apd_eq_pathover_of_eq_ap,↑elim,rec_cglue],
end
protected definition elim_type (Pincl : Π⦃i : I⦄ (x : A i), Type)
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) ≃ Pincl x) (y : colimit) : Type :=
elim Pincl (λj a, ua (Pglue j a)) y
protected definition elim_type_on [reducible] (y : colimit)
(Pincl : Π⦃i : I⦄ (x : A i), Type)
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) ≃ Pincl x) : Type :=
elim_type Pincl Pglue y
theorem elim_type_cglue (Pincl : Π⦃i : I⦄ (x : A i), Type)
(Pglue : Π(j : J) (x : A (dom j)), Pincl (f j x) ≃ Pincl x)
{j : J} (x : A (dom j)) : transport (elim_type Pincl Pglue) (cglue j x) = Pglue j x :=
by rewrite [tr_eq_cast_ap_fn,↑elim_type,elim_cglue];apply cast_ua_fn
protected definition rec_prop {P : colimit → Type} [H : Πx, is_prop (P x)]
(Pincl : Π⦃i : I⦄ (x : A i), P (ι x)) (y : colimit) : P y :=
rec Pincl (λa b, !is_prop.elimo) y
protected definition elim_prop {P : Type} [H : is_prop P] (Pincl : Π⦃i : I⦄ (x : A i), P)
(y : colimit) : P :=
elim Pincl (λa b, !is_prop.elim) y
end
end colimit
/- definition of a sequential colimit -/
namespace seq_colim
section
/-
we define it directly in terms of quotients. An alternative definition could be
definition seq_colim := colimit.colimit A id succ f
-/
parameters {A : ℕ → Type} (f : Π⦃n⦄, A n → A (succ n))
variables {n : ℕ} (a : A n)
local abbreviation B := Σ(n : ℕ), A n
inductive seq_rel : B → B → Type :=
| Rmk : Π{n : ℕ} (a : A n), seq_rel ⟨succ n, f a⟩ ⟨n, a⟩
open seq_rel
local abbreviation R := seq_rel
-- TODO: define this in root namespace
definition seq_colim : Type :=
quotient seq_rel
definition inclusion : seq_colim :=
class_of R ⟨n, a⟩
abbreviation sι := @inclusion
definition glue : sι (f a) = sι a :=
eq_of_rel seq_rel (Rmk f a)
protected definition rec {P : seq_colim → Type}
(Pincl : Π⦃n : ℕ⦄ (a : A n), P (sι a))
(Pglue : Π(n : ℕ) (a : A n), Pincl (f a) =[glue a] Pincl a) (aa : seq_colim) : P aa :=
begin
fapply (quotient.rec_on aa),
{ intro a, cases a, apply Pincl},
{ intro a a' H, cases H, apply Pglue}
end
protected definition rec_on [reducible] {P : seq_colim → Type} (aa : seq_colim)
(Pincl : Π⦃n : ℕ⦄ (a : A n), P (sι a))
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) =[glue a] Pincl a)
: P aa :=
rec Pincl Pglue aa
theorem rec_glue {P : seq_colim → Type} (Pincl : Π⦃n : ℕ⦄ (a : A n), P (sι a))
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) =[glue a] Pincl a) {n : ℕ} (a : A n)
: apd (rec Pincl Pglue) (glue a) = Pglue a :=
!rec_eq_of_rel
protected definition elim {P : Type} (Pincl : Π⦃n : ℕ⦄ (a : A n), P)
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) = Pincl a) : seq_colim → P :=
rec Pincl (λn a, pathover_of_eq _ (Pglue a))
protected definition elim_on [reducible] {P : Type} (aa : seq_colim)
(Pincl : Π⦃n : ℕ⦄ (a : A n), P)
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) = Pincl a) : P :=
elim Pincl Pglue aa
theorem elim_glue {P : Type} (Pincl : Π⦃n : ℕ⦄ (a : A n), P)
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) = Pincl a) {n : ℕ} (a : A n)
: ap (elim Pincl Pglue) (glue a) = Pglue a :=
begin
apply eq_of_fn_eq_fn_inv !(pathover_constant (glue a)),
rewrite [▸*,-apd_eq_pathover_of_eq_ap,↑elim,rec_glue],
end
protected definition elim_type (Pincl : Π⦃n : ℕ⦄ (a : A n), Type)
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) ≃ Pincl a) : seq_colim → Type :=
elim Pincl (λn a, ua (Pglue a))
protected definition elim_type_on [reducible] (aa : seq_colim)
(Pincl : Π⦃n : ℕ⦄ (a : A n), Type)
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) ≃ Pincl a) : Type :=
elim_type Pincl Pglue aa
theorem elim_type_glue (Pincl : Π⦃n : ℕ⦄ (a : A n), Type)
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) ≃ Pincl a) {n : ℕ} (a : A n)
: transport (elim_type Pincl Pglue) (glue a) = Pglue a :=
by rewrite [tr_eq_cast_ap_fn,↑elim_type,elim_glue]; apply cast_ua_fn
theorem elim_type_glue_inv (Pincl : Π⦃n : ℕ⦄ (a : A n), Type)
(Pglue : Π⦃n : ℕ⦄ (a : A n), Pincl (f a) ≃ Pincl a) {n : ℕ} (a : A n)
: transport (seq_colim.elim_type f Pincl Pglue) (glue a)⁻¹ = to_inv (Pglue a) :=
by rewrite [tr_eq_cast_ap_fn, ↑seq_colim.elim_type, ap_inv, elim_glue]; apply cast_ua_inv_fn
protected definition rec_prop {P : seq_colim → Type} [H : Πx, is_prop (P x)]
(Pincl : Π⦃n : ℕ⦄ (a : A n), P (sι a)) (aa : seq_colim) : P aa :=
rec Pincl (λa b, !is_prop.elimo) aa
protected definition elim_prop {P : Type} [H : is_prop P] (Pincl : Π⦃n : ℕ⦄ (a : A n), P)
: seq_colim → P :=
elim Pincl (λa b, !is_prop.elim)
end
end seq_colim
attribute colimit.incl seq_colim.inclusion [constructor]
attribute colimit.rec colimit.elim [unfold 10] [recursor 10]
attribute colimit.elim_type [unfold 9]
attribute colimit.rec_on colimit.elim_on [unfold 8]
attribute colimit.elim_type_on [unfold 7]
attribute seq_colim.rec seq_colim.elim [unfold 6] [recursor 6]
attribute seq_colim.elim_type [unfold 5]
attribute seq_colim.rec_on seq_colim.elim_on [unfold 4]
attribute seq_colim.elim_type_on [unfold 3]
|
e2dfffe0818442639113fe910a2d3bf5b2f36ac7 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Parser/Do.lean | 58b95cd5eb5f22d734258f1a07b30df78683a622 | [
"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 | 7,640 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Parser.Term
namespace Lean
namespace Parser
builtin_initialize registerBuiltinParserAttribute `builtinDoElemParser ``Category.doElem
builtin_initialize registerBuiltinDynamicParserAttribute `doElemParser `doElem
@[inline] def doElemParser (rbp : Nat := 0) : Parser :=
categoryParser `doElem rbp
namespace Term
def leftArrow : Parser := unicodeSymbol "← " "<- "
@[builtinTermParser] def liftMethod := leading_parser:minPrec leftArrow >> termParser
def doSeqItem := leading_parser ppLine >> doElemParser >> optional "; "
def doSeqIndent := leading_parser many1Indent doSeqItem
def doSeqBracketed := leading_parser "{" >> withoutPosition (many1 doSeqItem) >> ppLine >> "}"
def doSeq := withAntiquot (mkAntiquot "doSeq" `Lean.Parser.Term.doSeq (isPseudoKind := true)) <| doSeqBracketed <|> doSeqIndent
def termBeforeDo := withForbidden "do" termParser
attribute [runBuiltinParserAttributeHooks] doSeq termBeforeDo
builtin_initialize
register_parser_alias doSeq
register_parser_alias termBeforeDo
def notFollowedByRedefinedTermToken :=
-- Remark: we don't currently support `open` and `set_option` in `do`-blocks, but we include them in the following list to fix the ambiguity
-- "open" command following `do`-block. If we don't add `do`, then users would have to indent `do` blocks or use `{ ... }`.
notFollowedBy ("set_option" <|> "open" <|> "if" <|> "match" <|> "let" <|> "have" <|> "do" <|> "dbg_trace" <|> "assert!" <|> "for" <|> "unless" <|> "return" <|> symbol "try") "token at 'do' element"
@[builtinDoElemParser] def doLet := leading_parser "let " >> optional "mut " >> letDecl
@[builtinDoElemParser] def doLetElse := leading_parser "let " >> optional "mut " >> termParser >> " := " >> termParser >> checkColGt >> " | " >> doElemParser
@[builtinDoElemParser] def doLetRec := leading_parser group ("let " >> nonReservedSymbol "rec ") >> letRecDecls
def doIdDecl := leading_parser atomic (ident >> optType >> ppSpace >> leftArrow) >> doElemParser
def doPatDecl := leading_parser atomic (termParser >> ppSpace >> leftArrow) >> doElemParser >> optional (checkColGt >> " | " >> doElemParser)
@[builtinDoElemParser] def doLetArrow := leading_parser withPosition ("let " >> optional "mut " >> (doIdDecl <|> doPatDecl))
-- We use `letIdDeclNoBinders` to define `doReassign`.
-- Motivation: we do not reassign functions, and avoid parser conflict
def letIdDeclNoBinders := node `Lean.Parser.Term.letIdDecl $ atomic (ident >> pushNone >> optType >> " := ") >> termParser
@[builtinDoElemParser] def doReassign := leading_parser notFollowedByRedefinedTermToken >> (letIdDeclNoBinders <|> letPatDecl)
@[builtinDoElemParser] def doReassignArrow := leading_parser notFollowedByRedefinedTermToken >> withPosition (doIdDecl <|> doPatDecl)
@[builtinDoElemParser] def doHave := leading_parser "have " >> Term.haveDecl
/--
In `do` blocks, we support `if` without an `else`. Thus, we use indentation to prevent examples such as
```
if c_1 then
if c_2 then
action_1
else
action_2
```
from being parsed as
```
if c_1 then {
if c_2 then {
action_1
} else {
action_2
}
}
```
We also have special support for `else if` because we don't want to write
```
if c_1 then
action_1
else if c_2 then
action_2
else
action_3
```
-/
def elseIf := atomic (group (withPosition (" else " >> checkLineEq >> " if ")))
-- ensure `if $e then ...` still binds to `e:term`
def doIfLetPure := leading_parser " := " >> termParser
def doIfLetBind := leading_parser " ← " >> termParser
def doIfLet := leading_parser (withAnonymousAntiquot := false) "let " >> termParser >> (doIfLetPure <|> doIfLetBind)
def doIfProp := leading_parser (withAnonymousAntiquot := false) optIdent >> termParser
def doIfCond := withAntiquot (mkAntiquot "doIfCond" `Lean.Parser.Term.doIfCond (anonymous := false) (isPseudoKind := true)) <| doIfLet <|> doIfProp
@[builtinDoElemParser] def doIf := leading_parser withPositionAfterLinebreak $
"if " >> doIfCond >> " then " >> doSeq
>> many (checkColGe "'else if' in 'do' must be indented" >> group (elseIf >> doIfCond >> " then " >> doSeq))
>> optional (checkColGe "'else' in 'do' must be indented" >> " else " >> doSeq)
@[builtinDoElemParser] def doUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq
def doForDecl := leading_parser optional (atomic (ident >> " : ")) >> termParser >> " in " >> withForbidden "do" termParser
@[builtinDoElemParser] def doFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq
def doMatchAlts := ppDedent <| matchAlts (rhsParser := doSeq)
@[builtinDoElemParser] def doMatch := leading_parser:leadPrec "match " >> optional Term.generalizingParam >> optional Term.motive >> sepBy1 matchDiscr ", " >> " with " >> doMatchAlts
def doCatch := leading_parser atomic ("catch " >> binderIdent) >> optional (" : " >> termParser) >> darrow >> doSeq
def doCatchMatch := leading_parser "catch " >> doMatchAlts
def doFinally := leading_parser "finally " >> doSeq
@[builtinDoElemParser] def doTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally
@[builtinDoElemParser] def doBreak := leading_parser "break"
@[builtinDoElemParser] def doContinue := leading_parser "continue"
@[builtinDoElemParser] def doReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser))
@[builtinDoElemParser] def doDbgTrace := leading_parser:leadPrec "dbg_trace " >> ((interpolatedStr termParser) <|> termParser)
@[builtinDoElemParser] def doAssert := leading_parser:leadPrec "assert! " >> termParser
/--
We use `notFollowedBy` to avoid counterintuitive behavior.
For example, the `if`-term parser
doesn't enforce indentation restrictions, but we don't want it to be used when `doIf` fails.
Note that parser priorities would not solve this problem since the `doIf` parser is failing while the `if`
parser is succeeding. The first `notFollowedBy` prevents this problem.
Consider the `doElem` `x := (a, b⟩` it contains an error since we are using `⟩` instead of `)`. Thus, `doReassign` parser fails.
However, `doExpr` would succeed consuming just `x`, and cryptic error message is generated after that.
The second `notFollowedBy` prevents this problem.
-/
@[builtinDoElemParser] def doExpr := leading_parser notFollowedByRedefinedTermToken >> termParser >> notFollowedBy (symbol ":=" <|> symbol "←" <|> symbol "<-") "unexpected token after 'expr' in 'do' block"
@[builtinDoElemParser] def doNested := leading_parser "do " >> doSeq
@[builtinTermParser] def «do» := leading_parser:argPrec ppAllowUngrouped >> "do " >> doSeq
@[builtinTermParser] def doElem.quot : Parser := leading_parser "`(doElem|" >> incQuotDepth doElemParser >> ")"
/- macros for using `unless`, `for`, `try`, `return` as terms. They expand into `do unless ...`, `do for ...`, `do try ...`, and `do return ...` -/
@[builtinTermParser] def termUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq
@[builtinTermParser] def termFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq
@[builtinTermParser] def termTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally
@[builtinTermParser] def termReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser))
end Term
end Parser
end Lean
|
b8867587dca2002193d23041dbc9141facefa34a | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /tests/lean/run/forest2.lean | 82aee3f764fdc9f0651f66b87cec1b8af195c2ba | [
"Apache-2.0"
] | permissive | tjiaqi/lean | 4634d729795c164664d10d093f3545287c76628f | d0ce4cf62f4246b0600c07e074d86e51f2195e30 | refs/heads/master | 1,622,323,796,480 | 1,422,643,069,000 | 1,422,643,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,649 | lean | import data.prod data.unit
open prod
inductive tree (A : Type) : Type :=
node : A → forest A → tree A
with forest : Type :=
nil : forest A,
cons : tree A → forest A → forest A
namespace solution1
inductive tree_forest (A : Type) :=
of_tree : tree A → tree_forest A,
of_forest : forest A → tree_forest A
inductive same_kind {A : Type} : tree_forest A → tree_forest A → Type :=
is_tree : Π (t₁ t₂ : tree A), same_kind (tree_forest.of_tree t₁) (tree_forest.of_tree t₂),
is_forest : Π (f₁ f₂ : forest A), same_kind (tree_forest.of_forest f₁) (tree_forest.of_forest f₂)
definition to_tree {A : Type} (tf : tree_forest A) (t : tree A) : same_kind tf (tree_forest.of_tree t) → tree A :=
tree_forest.cases_on tf
(λ t₁ H, t₁)
(λ f₁ H, by cases H)
end solution1
namespace solution2
variables {A B : Type}
inductive same_kind : sum A B → sum A B → Prop :=
isl : Π (a₁ a₂ : A), same_kind (sum.inl a₁) (sum.inl a₂),
isr : Π (b₁ b₂ : B), same_kind (sum.inr b₁) (sum.inr b₂)
definition to_left (s : sum A B) (a : A) : same_kind s (sum.inl a) → A :=
sum.cases_on s
(λ a₁ H, a₁)
(λ b₁ H, false.rec _ (by cases H))
definition to_right (s : sum A B) (b : B) : same_kind s (sum.inr b) → B :=
sum.cases_on s
(λ a₁ H, false.rec _ (by cases H))
(λ b₁ H, b₁)
theorem to_left_inl (a₁ a₂ : A) (H : same_kind (sum.intro_left B a₁) (sum.inl a₂)) : to_left (sum.inl a₁) a₂ H = a₁ :=
rfl
theorem to_right_inr (b₁ b₂ : B) (H : same_kind (sum.intro_right A b₁) (sum.inr b₂)) : to_right (sum.inr b₁) b₂ H = b₁ :=
rfl
end solution2
|
0ce0ee6aea66576e1211f24f1b8ea33ca33e260a | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/indbug2.lean | 556d7dc4f9138d49487db30d395c361fb57682af | [
"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 | 196 | lean | set_option pp.implicit true
set_option pp.universes true
section
parameter {A : Type*}
definition foo : A → A → Type* := (λ x y, Type*)
inductive bar {a b : A} (f : foo a b)
| bar2 : bar
end
|
c9e314139a590a1d2050686a546af47b9519259a | 8e2026ac8a0660b5a490dfb895599fb445bb77a0 | /tests/lean/auto_quote_error2.lean | ad615ed2bf266abfbcce939497db84532c6411b8 | [
"Apache-2.0"
] | permissive | pcmoritz/lean | 6a8575115a724af933678d829b4f791a0cb55beb | 35eba0107e4cc8a52778259bb5392300267bfc29 | refs/heads/master | 1,607,896,326,092 | 1,490,752,175,000 | 1,490,752,175,000 | 86,612,290 | 0 | 0 | null | 1,490,809,641,000 | 1,490,809,641,000 | null | UTF-8 | Lean | false | false | 783 | lean | example (a b c : nat) : a = b → b = c → c = a :=
begin
tactic.intros,
apply eq.symm,
apply eq.refl, -- Error: unification
assumption,
assumption
end
example (a b c : nat) : a = b → b = c → c = a :=
begin
tactic.intros,
apply eq.symm,
begin
tactic.trace "hello world",
end, -- Error unsolved goals
assumption,
assumption
end
example (a b c : nat) : a = b → b = c → c = a :=
begin
tactic.intros,
apply eq.symm,
apply eq.trans,
begin
tactic.trace "hello world",
end, -- Error unsolved goals (remark: nested 'begin ... end' blocks focus on the main goal)
assumption
end
example (a b c : nat) : a = b → b = c → c = a :=
begin
intro h1, intro h2,
apply eq.symm,
begin
exact eq.trans h1 _, -- Error unsolved
end,
end
|
f1ab417e45be1839cfa3ec23dc40458b2761b61c | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/algebra/category/Mon/basic.lean | 9500a430de7ef7e4d0033f1e8531b7228c3c9b88 | [
"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 | 7,439 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.concrete_category.bundled_hom
import category_theory.concrete_category.reflects_isomorphisms
import algebra.punit_instances
import tactic.elementwise
/-!
# Category instances for monoid, add_monoid, comm_monoid, and add_comm_monoid.
We introduce the bundled categories:
* `Mon`
* `AddMon`
* `CommMon`
* `AddCommMon`
along with the relevant forgetful functors between them.
-/
universes u v
open category_theory
/-- The category of monoids and monoid morphisms. -/
@[to_additive AddMon]
def Mon : Type (u+1) := bundled monoid
/-- The category of additive monoids and monoid morphisms. -/
add_decl_doc AddMon
namespace Mon
/-- `monoid_hom` doesn't actually assume associativity. This alias is needed to make the category
theory machinery work. -/
@[to_additive "`add_monoid_hom` doesn't actually assume associativity. This alias is needed to make
the category theory machinery work."]
abbreviation assoc_monoid_hom (M N : Type*) [monoid M] [monoid N] := monoid_hom M N
@[to_additive]
instance bundled_hom : bundled_hom assoc_monoid_hom :=
⟨λ M N [monoid M] [monoid N], by exactI @monoid_hom.to_fun M N _ _,
λ M [monoid M], by exactI @monoid_hom.id M _,
λ M N P [monoid M] [monoid N] [monoid P], by exactI @monoid_hom.comp M N P _ _ _,
λ M N [monoid M] [monoid N], by exactI @monoid_hom.coe_inj M N _ _⟩
attribute [derive [has_coe_to_sort, large_category, concrete_category]] Mon AddMon
/-- Construct a bundled `Mon` from the underlying type and typeclass. -/
@[to_additive]
def of (M : Type u) [monoid M] : Mon := bundled.of M
/-- Construct a bundled `Mon` from the underlying type and typeclass. -/
add_decl_doc AddMon.of
@[to_additive]
instance : inhabited Mon :=
-- The default instance for `monoid punit` is derived via `punit.comm_ring`,
-- which breaks to_additive.
⟨@of punit $ @group.to_monoid _ $ @comm_group.to_group _ punit.comm_group⟩
@[to_additive]
instance (M : Mon) : monoid M := M.str
@[simp, to_additive] lemma coe_of (R : Type u) [monoid R] : (Mon.of R : Type u) = R := rfl
end Mon
/-- The category of commutative monoids and monoid morphisms. -/
@[to_additive AddCommMon]
def CommMon : Type (u+1) := bundled comm_monoid
/-- The category of additive commutative monoids and monoid morphisms. -/
add_decl_doc AddCommMon
namespace CommMon
@[to_additive]
instance : bundled_hom.parent_projection comm_monoid.to_monoid := ⟨⟩
attribute [derive [has_coe_to_sort, large_category, concrete_category]] CommMon AddCommMon
/-- Construct a bundled `CommMon` from the underlying type and typeclass. -/
@[to_additive]
def of (M : Type u) [comm_monoid M] : CommMon := bundled.of M
/-- Construct a bundled `AddCommMon` from the underlying type and typeclass. -/
add_decl_doc AddCommMon.of
@[to_additive]
instance : inhabited CommMon :=
-- The default instance for `comm_monoid punit` is derived via `punit.comm_ring`,
-- which breaks to_additive.
⟨@of punit $ @comm_group.to_comm_monoid _ punit.comm_group⟩
@[to_additive]
instance (M : CommMon) : comm_monoid M := M.str
@[simp, to_additive] lemma coe_of (R : Type u) [comm_monoid R] : (CommMon.of R : Type u) = R := rfl
@[to_additive has_forget_to_AddMon]
instance has_forget_to_Mon : has_forget₂ CommMon Mon := bundled_hom.forget₂ _ _
end CommMon
-- We verify that the coercions of morphisms to functions work correctly:
example {R S : Mon} (f : R ⟶ S) : (R : Type) → (S : Type) := f
example {R S : CommMon} (f : R ⟶ S) : (R : Type) → (S : Type) := f
-- We verify that when constructing a morphism in `CommMon`,
-- when we construct the `to_fun` field, the types are presented as `↥R`,
-- rather than `R.α` or (as we used to have) `↥(bundled.map comm_monoid.to_monoid R)`.
example (R : CommMon.{u}) : R ⟶ R :=
{ to_fun := λ x,
begin
match_target (R : Type u),
match_hyp x : (R : Type u),
exact x * x
end ,
map_one' := by simp,
map_mul' := λ x y,
begin rw [mul_assoc x y (x * y), ←mul_assoc y x y, mul_comm y x, mul_assoc, mul_assoc], end, }
variables {X Y : Type u}
section
variables [monoid X] [monoid Y]
/-- Build an isomorphism in the category `Mon` from a `mul_equiv` between `monoid`s. -/
@[simps, to_additive add_equiv.to_AddMon_iso "Build an isomorphism in the category `AddMon` from
an `add_equiv` between `add_monoid`s."]
def mul_equiv.to_Mon_iso (e : X ≃* Y) : Mon.of X ≅ Mon.of Y :=
{ hom := e.to_monoid_hom,
inv := e.symm.to_monoid_hom }
end
section
variables [comm_monoid X] [comm_monoid Y]
/-- Build an isomorphism in the category `CommMon` from a `mul_equiv` between `comm_monoid`s. -/
@[simps, to_additive add_equiv.to_AddCommMon_iso "Build an isomorphism in the category `AddCommMon`
from an `add_equiv` between `add_comm_monoid`s."]
def mul_equiv.to_CommMon_iso (e : X ≃* Y) : CommMon.of X ≅ CommMon.of Y :=
{ hom := e.to_monoid_hom,
inv := e.symm.to_monoid_hom }
end
namespace category_theory.iso
/-- Build a `mul_equiv` from an isomorphism in the category `Mon`. -/
@[to_additive AddMon_iso_to_add_equiv "Build an `add_equiv` from an isomorphism in the category
`AddMon`."]
def Mon_iso_to_mul_equiv {X Y : Mon} (i : X ≅ Y) : X ≃* Y :=
i.hom.to_mul_equiv i.inv i.hom_inv_id i.inv_hom_id
/-- Build a `mul_equiv` from an isomorphism in the category `CommMon`. -/
@[to_additive "Build an `add_equiv` from an isomorphism in the category
`AddCommMon`."]
def CommMon_iso_to_mul_equiv {X Y : CommMon} (i : X ≅ Y) : X ≃* Y :=
i.hom.to_mul_equiv i.inv i.hom_inv_id i.inv_hom_id
end category_theory.iso
/-- multiplicative equivalences between `monoid`s are the same as (isomorphic to) isomorphisms
in `Mon` -/
@[to_additive add_equiv_iso_AddMon_iso "additive equivalences between `add_monoid`s are the same
as (isomorphic to) isomorphisms in `AddMon`"]
def mul_equiv_iso_Mon_iso {X Y : Type u} [monoid X] [monoid Y] :
(X ≃* Y) ≅ (Mon.of X ≅ Mon.of Y) :=
{ hom := λ e, e.to_Mon_iso,
inv := λ i, i.Mon_iso_to_mul_equiv, }
/-- multiplicative equivalences between `comm_monoid`s are the same as (isomorphic to) isomorphisms
in `CommMon` -/
@[to_additive add_equiv_iso_AddCommMon_iso "additive equivalences between `add_comm_monoid`s are
the same as (isomorphic to) isomorphisms in `AddCommMon`"]
def mul_equiv_iso_CommMon_iso {X Y : Type u} [comm_monoid X] [comm_monoid Y] :
(X ≃* Y) ≅ (CommMon.of X ≅ CommMon.of Y) :=
{ hom := λ e, e.to_CommMon_iso,
inv := λ i, i.CommMon_iso_to_mul_equiv, }
@[to_additive]
instance Mon.forget_reflects_isos : reflects_isomorphisms (forget Mon.{u}) :=
{ reflects := λ X Y f _,
begin
resetI,
let i := as_iso ((forget Mon).map f),
let e : X ≃* Y := { ..f, ..i.to_equiv },
exact ⟨(is_iso.of_iso e.to_Mon_iso).1⟩,
end }
@[to_additive]
instance CommMon.forget_reflects_isos : reflects_isomorphisms (forget CommMon.{u}) :=
{ reflects := λ X Y f _,
begin
resetI,
let i := as_iso ((forget CommMon).map f),
let e : X ≃* Y := { ..f, ..i.to_equiv },
exact ⟨(is_iso.of_iso e.to_CommMon_iso).1⟩,
end }
/-!
Once we've shown that the forgetful functors to type reflect isomorphisms,
we automatically obtain that the `forget₂` functors between our concrete categories
reflect isomorphisms.
-/
example : reflects_isomorphisms (forget₂ CommMon Mon) := by apply_instance
|
31cd4708c6f6be7a3f074407612f8062f087e6cf | e09201d437062e1f95e6e5360aab0c9f947901aa | /src/automata/nfa.lean | dcbac09d79d3f5c6d06b3137cf991c7809d38f41 | [] | no_license | VArtem/lean-regular-languages | 34f4b093f28ef2f09ba7e684e642a0f97c901560 | e877243188253d0ac17ccf0ae2da7bf608686ff0 | refs/heads/master | 1,683,590,111,306 | 1,622,307,234,000 | 1,622,307,234,000 | 284,232,653 | 7 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,009 | lean | import data.set.basic
import data.fintype.basic
import data.finset.basic
import tactic
import automata.dfa
namespace nfa
open set list DFA finset
variables {S Q : Type} [fintype S] [fintype Q] [decidable_eq Q]
structure NFA (S : Type) (Q : Type) [fintype S] [fintype Q] [decidable_eq Q] :=
(start : Q) -- starting state
(term : set Q) -- terminal states
(next : Q → S → set Q) -- transitions
inductive go (nfa : NFA S Q) : Q → list S → Q → Prop
| finish : Π {q : Q}, go q [] q
| step : Π {head : S} {tail : list S} {q n f : Q} (h : n ∈ nfa.next q head),
go n tail f → go q (head::tail) f
@[simp] def nfa_accepts_word (nfa : NFA S Q) (w : list S) : Prop :=
∃ {t}, go nfa nfa.start w t ∧ t ∈ nfa.term
@[simp] def lang_of_nfa (nfa : NFA S Q) := {w | nfa_accepts_word nfa w}
def nfa_lang (lang : set (list S)) :=
∃ {Q : Type} [fintype Q] [decidable_eq Q], by exactI ∃ (nfa : NFA S Q), lang = lang_of_nfa nfa
lemma nfa_go_append {nfa : NFA S Q} {a b c : Q} {left right : list S}:
go nfa a left b → go nfa b right c → go nfa a (left ++ right) c :=
begin
induction left generalizing a,
case list.nil : {
rintro ⟨_⟩ hbc,
exact hbc,
},
case list.cons : head tail ih {
rintro (⟨_⟩ | ⟨head, tail, _, nxt, _, h, hab⟩) hbc,
specialize @ih nxt,
exact go.step h (ih hab hbc),
}
end
def dfa_to_nfa (dfa : DFA S Q) : NFA S Q := {
start := dfa.start,
term := dfa.term,
next := λ q c, {dfa.next q c}
}
lemma dfa_to_nfa_goes_to
{d : DFA S Q} {w : list S} {q r : Q}
: go (dfa_to_nfa d) q w r ↔ DFA.go d q w = r :=
begin
split, {
intro go_nfa,
induction go_nfa,
case nfa.go.finish {
rw DFA.go_finish,
},
case nfa.go.step : head tail q nxt f hnxt go_tail ih {
rw DFA.go_step,
convert ih,
simp only [dfa_to_nfa, mem_singleton_iff] at hnxt,
exact hnxt.symm,
}
}, {
intro go_dfa,
induction w generalizing q,
case list.nil {
cases go_dfa, exact go.finish,
},
case list.cons : head tail ih {
cases go_dfa,
specialize @ih (d.next q head) go_dfa,
refine go.step _ ih,
simp only [dfa_to_nfa, set.mem_singleton],
}
}
end
theorem dfa_to_nfa_eq {L : set (list S)} (hdfa : dfa_lang L) : nfa_lang L :=
begin
rcases hdfa with ⟨Q, fQ, dQ, d, rfl⟩,
letI := fQ,
existsi [Q, _, _, dfa_to_nfa d],
ext x,
rw [lang_of_dfa, lang_of_nfa, mem_set_of_eq, mem_set_of_eq],
split, {
rintro dfa_go,
dsimp at dfa_go,
use [DFA.go d (d.start) x],
rw dfa_to_nfa_goes_to,
use [rfl, dfa_go],
}, {
rintro ⟨t, t_go, t_term⟩,
rw dfa_to_nfa_goes_to at t_go,
subst t_go,
use t_term,
}
end
noncomputable def nfa_to_dfa (nfa : NFA S Q) : DFA S (set Q) := {
start := {nfa.start},
term := {q | ∃ t, t ∈ q ∧ t ∈ nfa.term},
next := λ q c, (⋃ t ∈ q, nfa.next t c),
}
lemma nfa_to_dfa_goes_to
{n : NFA S Q} {d : DFA S (set Q)} (w : list S) {S1 : set Q}
: d = nfa_to_dfa n → DFA.go d S1 w = {e2 : Q | ∃ (s2 : Q), s2 ∈ S1 ∧ go n s2 w e2} :=
begin
rintro rfl,
induction w with head tail ih generalizing S1, {
ext, split,
{ intro xe1, use [x, xe1, go.finish] },
{ rintro ⟨s2, s2ins1, ⟨s2go⟩⟩, exact s2ins1 },
}, {
specialize @ih ((nfa_to_dfa n).next S1 head),
ext value, split, {
intro dfa_go,
rw [go_step, ih] at dfa_go,
rcases dfa_go with ⟨s2, s2innext, s2go⟩,
rw [nfa_to_dfa, mem_bUnion_iff] at s2innext,
rcases s2innext with ⟨x, x_in_s1, x_next⟩,
use [x, x_in_s1, go.step x_next s2go],
}, {
rintro ⟨s2, s2ins1, s2go⟩,
rw [DFA.go_step, ih],
cases s2go,
use s2go_n,
split, {
dsimp [nfa_to_dfa],
rw mem_bUnion_iff,
use [s2, s2ins1, s2go_h],
}, {
assumption,
}
},
},
end
theorem nfa_to_dfa_eq {L : set (list S)} (hnfa : nfa_lang L) : dfa_lang L :=
begin
rcases hnfa with ⟨Q, fQ, dQ, nfa, rfl⟩,
letI := fQ,
existsi [set Q, _, _, nfa_to_dfa nfa],
ext x,
split, {
rintro ⟨tset, tsetgo, tsetterm⟩,
use tset,
rw (nfa_to_dfa_goes_to x rfl),
simp,
use [nfa.start],
simp [nfa_to_dfa, tsetgo],
exact tsetterm,
}, {
rintro ⟨tset, tsetgo, tsetterm⟩,
simp only [nfa_to_dfa_goes_to x rfl, mem_set_of_eq] at tsetgo,
rcases tsetgo with ⟨s2, s2start, s2go⟩,
use [tset],
simp [nfa_to_dfa] at s2start,
subst s2start,
use [s2go, tsetterm],
},
end
end nfa |
a681ceb5bb1af22e3385b89a344e1b7419541204 | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/data/real/sqrt.lean | deb8e5efd248e2130adb29a2acafbcd86dd5386a | [
"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 | 10,493 | lean | /-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Yury Kudryashov
-/
import topology.instances.nnreal
/-!
# Square root of a real number
In this file we define
* `nnreal.sqrt` to be the square root of a nonnegative real number.
* `real.sqrt` to be the square root of a real number, defined to be zero on negative numbers.
Then we prove some basic properties of these functions.
## Implementation notes
We define `nnreal.sqrt` as the noncomputable inverse to the function `x ↦ x * x`. We use general
theory of inverses of strictly monotone functions to prove that `nnreal.sqrt x` exists. As a side
effect, `nnreal.sqrt` is a bundled `order_iso`, so for `nnreal` numbers we get continuity as well as
theorems like `sqrt x ≤ y ↔ x * x ≤ y` for free.
Then we define `real.sqrt x` to be `nnreal.sqrt (nnreal.of_real x)`. We also define a Cauchy
sequence `real.sqrt_aux (f : cau_seq ℚ abs)` which converges to `sqrt (mk f)` but do not prove (yet)
that this sequence actually converges to `sqrt (mk f)`.
## Tags
square root
-/
open set filter
open_locale filter nnreal topological_space
namespace nnreal
variables {x y : ℝ≥0}
/-- Square root of a nonnegative real number. -/
@[pp_nodot] noncomputable def sqrt : ℝ≥0 ≃o ℝ≥0 :=
order_iso.symm $ strict_mono.order_iso_of_surjective (λ x, x * x)
(λ x y h, mul_self_lt_mul_self x.2 h) $
(continuous_id.mul continuous_id).surjective tendsto_mul_self_at_top $
by simp [order_bot.at_bot_eq]
lemma sqrt_eq_iff_sq_eq : sqrt x = y ↔ y * y = x :=
sqrt.to_equiv.apply_eq_iff_eq_symm_apply.trans eq_comm
lemma sqrt_le_iff : sqrt x ≤ y ↔ x ≤ y * y :=
sqrt.to_galois_connection _ _
lemma le_sqrt_iff : x ≤ sqrt y ↔ x * x ≤ y :=
(sqrt.symm.to_galois_connection _ _).symm
@[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 :=
sqrt_eq_iff_sq_eq.trans $ by rw [eq_comm, zero_mul]
@[simp] lemma sqrt_zero : sqrt 0 = 0 := sqrt_eq_zero.2 rfl
@[simp] lemma sqrt_one : sqrt 1 = 1 := sqrt_eq_iff_sq_eq.2 $ mul_one 1
@[simp] lemma mul_sqrt_self (x : ℝ≥0) : sqrt x * sqrt x = x :=
sqrt.symm_apply_apply x
@[simp] lemma sqrt_mul_self (x : ℝ≥0) : sqrt (x * x) = x := sqrt.apply_symm_apply x
lemma sqrt_mul (x y : ℝ≥0) : sqrt (x * y) = sqrt x * sqrt y :=
by rw [sqrt_eq_iff_sq_eq, mul_mul_mul_comm, mul_sqrt_self, mul_sqrt_self]
/-- `nnreal.sqrt` as a `monoid_with_zero_hom`. -/
noncomputable def sqrt_hom : monoid_with_zero_hom ℝ≥0 ℝ≥0 := ⟨sqrt, sqrt_zero, sqrt_one, sqrt_mul⟩
lemma sqrt_inv (x : ℝ≥0) : sqrt (x⁻¹) = (sqrt x)⁻¹ := sqrt_hom.map_inv' x
lemma sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y := sqrt_hom.map_div x y
lemma continuous_sqrt : continuous sqrt := sqrt.continuous
end nnreal
namespace real
/-- An auxiliary sequence of rational numbers that converges to `real.sqrt (mk f)`.
Currently this sequence is not used in `mathlib`. -/
def sqrt_aux (f : cau_seq ℚ abs) : ℕ → ℚ
| 0 := rat.mk_nat (f 0).num.to_nat.sqrt (f 0).denom.sqrt
| (n + 1) := let s := sqrt_aux n in max 0 $ (s + f (n+1) / s) / 2
theorem sqrt_aux_nonneg (f : cau_seq ℚ abs) : ∀ i : ℕ, 0 ≤ sqrt_aux f i
| 0 := by rw [sqrt_aux, rat.mk_nat_eq, rat.mk_eq_div];
apply div_nonneg; exact int.cast_nonneg.2 (int.of_nat_nonneg _)
| (n + 1) := le_max_left _ _
/- TODO(Mario): finish the proof
theorem sqrt_aux_converges (f : cau_seq ℚ abs) : ∃ h x, 0 ≤ x ∧ x * x = max 0 (mk f) ∧
mk ⟨sqrt_aux f, h⟩ = x :=
begin
rcases sqrt_exists (le_max_left 0 (mk f)) with ⟨x, x0, hx⟩,
suffices : ∃ h, mk ⟨sqrt_aux f, h⟩ = x,
{ exact this.imp (λ h e, ⟨x, x0, hx, e⟩) },
apply of_near,
suffices : ∃ δ > 0, ∀ i, abs (↑(sqrt_aux f i) - x) < δ / 2 ^ i,
{ rcases this with ⟨δ, δ0, hδ⟩,
intros,
}
end -/
/-- The square root of a real number. This returns 0 for negative inputs. -/
@[pp_nodot] noncomputable def sqrt (x : ℝ) : ℝ :=
nnreal.sqrt (nnreal.of_real x)
/-quotient.lift_on x
(λ f, mk ⟨sqrt_aux f, (sqrt_aux_converges f).fst⟩)
(λ f g e, begin
rcases sqrt_aux_converges f with ⟨hf, x, x0, xf, xs⟩,
rcases sqrt_aux_converges g with ⟨hg, y, y0, yg, ys⟩,
refine xs.trans (eq.trans _ ys.symm),
rw [← @mul_self_inj_of_nonneg ℝ _ x y x0 y0, xf, yg],
congr' 1, exact quotient.sound e
end)-/
variables {x y : ℝ}
@[continuity]
lemma continuous_sqrt : continuous sqrt :=
nnreal.continuous_coe.comp $ nnreal.sqrt.continuous.comp nnreal.continuous_of_real
theorem sqrt_eq_zero_of_nonpos (h : x ≤ 0) : sqrt x = 0 :=
by simp [sqrt, nnreal.of_real_eq_zero.2 h]
theorem sqrt_nonneg (x : ℝ) : 0 ≤ sqrt x := nnreal.coe_nonneg _
@[simp] theorem mul_self_sqrt (h : 0 ≤ x) : sqrt x * sqrt x = x :=
by simp [sqrt, ← nnreal.coe_mul, nnreal.coe_of_real _ h]
@[simp] theorem sqrt_mul_self (h : 0 ≤ x) : sqrt (x * x) = x :=
(mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _))
theorem sqrt_eq_iff_mul_self_eq (hx : 0 ≤ x) (hy : 0 ≤ y) :
sqrt x = y ↔ y * y = x :=
⟨λ h, by rw [← h, mul_self_sqrt hx], λ h, by rw [← h, sqrt_mul_self hy]⟩
@[simp] theorem sq_sqrt (h : 0 ≤ x) : sqrt x ^ 2 = x :=
by rw [sq, mul_self_sqrt h]
@[simp] theorem sqrt_sq (h : 0 ≤ x) : sqrt (x ^ 2) = x :=
by rw [sq, sqrt_mul_self h]
theorem sqrt_eq_iff_sq_eq (hx : 0 ≤ x) (hy : 0 ≤ y) :
sqrt x = y ↔ y ^ 2 = x :=
by rw [sq, sqrt_eq_iff_mul_self_eq hx hy]
theorem sqrt_mul_self_eq_abs (x : ℝ) : sqrt (x * x) = abs x :=
by rw [← abs_mul_abs_self x, sqrt_mul_self (abs_nonneg _)]
theorem sqrt_sq_eq_abs (x : ℝ) : sqrt (x ^ 2) = abs x :=
by rw [sq, sqrt_mul_self_eq_abs]
@[simp] theorem sqrt_zero : sqrt 0 = 0 := by simp [sqrt]
@[simp] theorem sqrt_one : sqrt 1 = 1 := by simp [sqrt]
@[simp] theorem sqrt_le (hy : 0 ≤ y) : sqrt x ≤ sqrt y ↔ x ≤ y :=
by simp [sqrt, nnreal.of_real_le_of_real_iff, *]
@[simp] theorem sqrt_lt (hx : 0 ≤ x) : sqrt x < sqrt y ↔ x < y :=
lt_iff_lt_of_le_iff_le (sqrt_le hx)
theorem sqrt_le_sqrt (h : x ≤ y) : sqrt x ≤ sqrt y :=
by simp [sqrt, nnreal.of_real_le_of_real h]
theorem sqrt_le_left (hy : 0 ≤ y) : sqrt x ≤ y ↔ x ≤ y ^ 2 :=
by rw [sqrt, ← nnreal.le_of_real_iff_coe_le hy, nnreal.sqrt_le_iff, ← nnreal.of_real_mul hy,
nnreal.of_real_le_of_real_iff (mul_self_nonneg y), sq]
theorem sqrt_le_iff : sqrt x ≤ y ↔ 0 ≤ y ∧ x ≤ y ^ 2 :=
begin
rw [← and_iff_right_of_imp (λ h, (sqrt_nonneg x).trans h), and.congr_right_iff],
exact sqrt_le_left
end
/- note: if you want to conclude `x ≤ sqrt y`, then use `le_sqrt_of_sq_le`.
if you have `x > 0`, consider using `le_sqrt'` -/
theorem le_sqrt (hx : 0 ≤ x) (hy : 0 ≤ y) : x ≤ sqrt y ↔ x ^ 2 ≤ y :=
by rw [mul_self_le_mul_self_iff hx (sqrt_nonneg _), sq, mul_self_sqrt hy]
theorem le_sqrt' (hx : 0 < x) : x ≤ sqrt y ↔ x ^ 2 ≤ y :=
by { rw [sqrt, ← nnreal.coe_mk x hx.le, nnreal.coe_le_coe, nnreal.le_sqrt_iff,
nnreal.le_of_real_iff_coe_le', sq, nnreal.coe_mul], exact mul_pos hx hx }
theorem abs_le_sqrt (h : x^2 ≤ y) : abs x ≤ sqrt y :=
by rw ← sqrt_sq_eq_abs; exact sqrt_le_sqrt h
theorem sq_le (h : 0 ≤ y) : x^2 ≤ y ↔ -sqrt y ≤ x ∧ x ≤ sqrt y :=
begin
split,
{ simpa only [abs_le] using abs_le_sqrt },
{ rw [← abs_le, ← sq_abs],
exact (le_sqrt (abs_nonneg x) h).mp },
end
theorem neg_sqrt_le_of_sq_le (h : x^2 ≤ y) : -sqrt y ≤ x :=
((sq_le ((sq_nonneg x).trans h)).mp h).1
theorem le_sqrt_of_sq_le (h : x^2 ≤ y) : x ≤ sqrt y :=
((sq_le ((sq_nonneg x).trans h)).mp h).2
@[simp] theorem sqrt_inj (hx : 0 ≤ x) (hy : 0 ≤ y) : sqrt x = sqrt y ↔ x = y :=
by simp [le_antisymm_iff, hx, hy]
@[simp] theorem sqrt_eq_zero (h : 0 ≤ x) : sqrt x = 0 ↔ x = 0 :=
by simpa using sqrt_inj h (le_refl _)
theorem sqrt_eq_zero' : sqrt x = 0 ↔ x ≤ 0 :=
by rw [sqrt, nnreal.coe_eq_zero, nnreal.sqrt_eq_zero, nnreal.of_real_eq_zero]
theorem sqrt_ne_zero (h : 0 ≤ x) : sqrt x ≠ 0 ↔ x ≠ 0 :=
by rw [not_iff_not, sqrt_eq_zero h]
theorem sqrt_ne_zero' : sqrt x ≠ 0 ↔ 0 < x :=
by rw [← not_le, not_iff_not, sqrt_eq_zero']
@[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le (iff.trans
(by simp [le_antisymm_iff, sqrt_nonneg]) sqrt_eq_zero')
@[simp] theorem sqrt_mul (hx : 0 ≤ x) (y : ℝ) : sqrt (x * y) = sqrt x * sqrt y :=
by simp_rw [sqrt, ← nnreal.coe_mul, nnreal.coe_eq, nnreal.of_real_mul hx, nnreal.sqrt_mul]
@[simp] theorem sqrt_mul' (x) {y : ℝ} (hy : 0 ≤ y) : sqrt (x * y) = sqrt x * sqrt y :=
by rw [mul_comm, sqrt_mul hy, mul_comm]
@[simp] theorem sqrt_inv (x : ℝ) : sqrt x⁻¹ = (sqrt x)⁻¹ :=
by rw [sqrt, nnreal.of_real_inv, nnreal.sqrt_inv, nnreal.coe_inv, sqrt]
@[simp] theorem sqrt_div (hx : 0 ≤ x) (y : ℝ) : sqrt (x / y) = sqrt x / sqrt y :=
by rw [division_def, sqrt_mul hx, sqrt_inv, division_def]
@[simp] theorem div_sqrt : x / sqrt x = sqrt x :=
begin
cases le_or_lt x 0,
{ rw [sqrt_eq_zero'.mpr h, div_zero] },
{ rw [div_eq_iff (sqrt_ne_zero'.mpr h), mul_self_sqrt h.le] },
end
theorem lt_sqrt (hx : 0 ≤ x) (hy : 0 ≤ y) : x < sqrt y ↔ x ^ 2 < y :=
by rw [mul_self_lt_mul_self_iff hx (sqrt_nonneg y), sq, mul_self_sqrt hy]
theorem sq_lt : x^2 < y ↔ -sqrt y < x ∧ x < sqrt y :=
begin
split,
{ simpa only [← sqrt_lt (sq_nonneg x), sqrt_sq_eq_abs] using abs_lt.mp },
{ rw [← abs_lt, ← sq_abs],
exact λ h, (lt_sqrt (abs_nonneg x) (sqrt_pos.mp (lt_of_le_of_lt (abs_nonneg x) h)).le).mp h },
end
theorem neg_sqrt_lt_of_sq_lt (h : x^2 < y) : -sqrt y < x := (sq_lt.mp h).1
theorem lt_sqrt_of_sq_lt (h : x^2 < y) : x < sqrt y := (sq_lt.mp h).2
end real
open real
variables {α : Type*}
lemma filter.tendsto.sqrt {f : α → ℝ} {l : filter α} {x : ℝ} (h : tendsto f l (𝓝 x)) :
tendsto (λ x, sqrt (f x)) l (𝓝 (sqrt x)) :=
(continuous_sqrt.tendsto _).comp h
variables [topological_space α] {f : α → ℝ} {s : set α} {x : α}
lemma continuous_within_at.sqrt (h : continuous_within_at f s x) :
continuous_within_at (λ x, sqrt (f x)) s x :=
h.sqrt
lemma continuous_at.sqrt (h : continuous_at f x) : continuous_at (λ x, sqrt (f x)) x := h.sqrt
lemma continuous_on.sqrt (h : continuous_on f s) : continuous_on (λ x, sqrt (f x)) s :=
λ x hx, (h x hx).sqrt
@[continuity]
lemma continuous.sqrt (h : continuous f) : continuous (λ x, sqrt (f x)) := continuous_sqrt.comp h
|
e0bef49b0879aec355a2421449cc8741d773ea22 | c8b4b578b2fe61d500fbca7480e506f6603ea698 | /src/flt_three/spts.lean | fefcea45a7127f4414773ca62da9c0717d2f24de | [] | no_license | leanprover-community/flt-regular | aa7e564f2679dfd2e86015a5a9674a6e1197f7cc | 67fb3e176584bbc03616c221a7be6fa28c5ccd32 | refs/heads/master | 1,692,188,905,751 | 1,691,766,312,000 | 1,691,766,312,000 | 421,021,216 | 19 | 4 | null | 1,694,532,115,000 | 1,635,166,136,000 | Lean | UTF-8 | Lean | false | false | 17,028 | lean | /-
Copyright (c) 2020 Ruben Van de Velde. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
import data.int.order.units
import number_theory.zsqrtd.basic
import ring_theory.prime
import .primes
lemma zsqrtd.exists {d : ℤ} (a : ℤ√d) (him : a.im ≠ 0) :
∃ (c : ℤ√d), a.norm = c.norm ∧ 0 ≤ c.re ∧ c.im ≠ 0 :=
begin
cases le_or_lt a.re 0 with hre hre,
{ use -a,
simp only [hre, him, zsqrtd.norm_neg, eq_self_iff_true, zsqrtd.neg_im, zsqrtd.neg_re, and_self,
neg_nonneg, ne.def, not_false_iff, neg_eq_zero] },
{ use a, simp only [hre.le, him, eq_self_iff_true, and_self, ne.def, not_false_iff] },
end
-- Edwards p49 step (2')
lemma factors2
{a : ℤ√-3}
(heven : even a.norm) :
∃ b : ℤ√-3, a.norm = 4 * b.norm :=
begin
have hparity : even a.re ↔ even a.im,
{ simpa [two_ne_zero, zsqrtd.norm_def] with parity_simps using heven },
simp only [iff_iff_and_or_not_and_not, ←int.odd_iff_not_even] at hparity,
obtain ⟨⟨c, hc⟩, ⟨d, hd⟩⟩|⟨hre, him⟩ := hparity,
{ use ⟨c, d⟩,
simp only [zsqrtd.norm_def, hc, hd],
ring },
{ cases int.four_dvd_add_or_sub_of_odd hre him with h4 h4,
{ obtain ⟨v, hv⟩ := h4,
use ⟨v - a.im, v⟩,
rw [eq_comm, ←sub_eq_iff_eq_add] at hv,
simp only [zsqrtd.norm_def, ←hv],
ring },
{ obtain ⟨v, hv⟩ := h4,
use ⟨v + a.im, v⟩,
rw [sub_eq_iff_eq_add] at hv,
simp only [zsqrtd.norm_def, hv],
ring } }
end
lemma spts.mul_of_dvd'
{a p : ℤ√-3}
(hdvd : p.norm ∣ a.norm)
(hpprime : prime p.norm) :
∃ u : ℤ√-3, a = p * u ∨ a = star p * u :=
begin
obtain ⟨f, hf⟩ := hdvd,
have h0 : p.norm ∣ p.re * a.im - a.re * p.im ∨
p.norm ∣ p.re * a.im + a.re * p.im,
{ apply hpprime.dvd_or_dvd,
convert dvd_mul_right p.norm (a.im ^ 2 - p.im ^ 2 * f) using 1,
transitivity a.im ^ 2 * p.norm - p.im ^ 2 * (p.norm * f),
{ rw [←hf, zsqrtd.norm_def, zsqrtd.norm_def], ring },
{ rw [zsqrtd.norm_def], ring } },
obtain ⟨A, HA⟩ : ∃ A : units ℤ, p.norm ∣ p.re * a.im + A * a.re * p.im,
{ cases h0 with h0 h0;
[use -1, use 1];
convert h0;
simp, },
have HAsq : (A : ℤ) ^ 2 = 1,
{ calc (A : ℤ) ^ 2
= ((A ^ 2 : units ℤ) : ℤ) : (units.coe_pow _ _).symm
... = ((1 : units ℤ) : ℤ) : congr_arg _ (int.units_sq A)
... = 1 : units.coe_one },
{ set X : ℤ√-3 := ⟨p.re * a.re - A * 3 * p.im * a.im, p.re * a.im + A * a.re * p.im⟩ with HX,
obtain ⟨U, HU⟩ : (p.norm : ℤ√-3) ∣ X,
{ rw zsqrtd.coe_int_dvd_iff,
refine ⟨_, HA⟩,
apply @prime.dvd_of_dvd_pow _ _ _ hpprime _ 2,
have : X.re ^ 2 = X.norm - 3 * X.im ^ 2,
{ rw [zsqrtd.norm_def], ring },
rw this,
apply dvd_sub,
{ use a.norm,
transitivity (p.re * a.re) ^ 2 + (A : ℤ) ^ 2 * (3 * p.im * a.im) ^ 2 +
3 * ((p.re * a.im) ^ 2 + (A : ℤ) ^ 2 * (a.re * p.im) ^ 2),
{ simp only [zsqrtd.norm_def],
ring },
{ simp only [zsqrtd.norm_def, HAsq],
ring } },
{ apply dvd_mul_of_dvd_right,
exact dvd_pow HA two_ne_zero } },
use U,
suffices : a = ⟨p.re, -A * p.im⟩ * U,
{ apply or.imp _ _ (int.units_eq_one_or A).symm; rintro rfl; simpa [zsqrtd.ext] using this },
apply zsqrtd.eq_of_smul_eq_smul_left hpprime.ne_zero,
have : p.norm = p.re ^ 2 + 3 * ↑A ^ 2 * p.im ^ 2,
{ rw [zsqrtd.norm_def, HAsq], ring },
rw [mul_comm _ U, ←mul_assoc, ←HU, HX],
simp only [zsqrtd.ext, neg_mul, add_zero, zsqrtd.coe_int_re, zero_mul,
mul_neg, zsqrtd.mul_im, zsqrtd.mul_re, neg_neg, mul_zero, neg_zero,
zsqrtd.coe_int_im, this],
split; ring },
end
-- Edwards p49 step (3')
lemma spts.mul_of_dvd''
{a p : ℤ√-3}
(hdvd : p.norm ∣ a.norm)
(hpprime : prime p.norm) :
∃ u : ℤ√-3,
(a = p * u ∨ a = star p * u) ∧
a.norm = p.norm * u.norm :=
begin
obtain ⟨u, hu⟩ := spts.mul_of_dvd' hdvd hpprime,
refine ⟨u, hu, _⟩,
obtain (rfl|rfl) := hu,
{ rw [zsqrtd.norm_mul] },
{ rw [zsqrtd.norm_mul, zsqrtd.norm_conj] },
end
-- Edwards p49 step (4'), contraposed
lemma factors'
(a : ℤ√-3)
(f : ℤ)
(g : ℤ)
(hodd : odd f)
(hgpos : g ≠ 0)
(hfactor : f * g = a.norm)
(hnotform : ∀ (f' : ℤ), f' ∣ g → odd f' → (∃ (p : ℤ√-3), abs f' = p.norm)) :
∃ (p : ℤ√-3), abs f = p.norm :=
begin
induction hg : g.nat_abs using nat.strong_induction_on with g'' IH generalizing a g,
subst g'',
dsimp at IH,
have ha : a.norm ≠ 0,
{ rw [←hfactor, mul_ne_zero_iff, and_iff_left hgpos],
rintro rfl,
exact int.odd_iff_not_even.mp hodd even_zero },
by_cases H : even (zsqrtd.norm a),
{ obtain ⟨c, hc⟩ := factors2 H,
obtain ⟨g', rfl⟩ : 4 ∣ g,
{ apply is_coprime.dvd_of_dvd_mul_left,
{ show is_coprime _ f,
rw [int.odd_iff_not_even, even_iff_two_dvd, ←int.prime_two.coprime_iff_not_dvd] at hodd,
convert hodd.pow_left,
rw sq,
norm_num },
{ rw [hfactor, hc],
exact dvd_mul_right _ _ } },
have hg'pos : g' ≠ 0 := right_ne_zero_of_mul hgpos,
have hgcdcd : 0 < int.gcd c.re c.im,
{ rw [zsqrtd.gcd_pos_iff, ne.def, ←c.norm_eq_zero_iff (by norm_num)],
apply right_ne_zero_of_mul,
rwa ←hc },
refine IH g'.nat_abs _ c g' hg'pos _ _ rfl,
{ rw [int.nat_abs_mul],
apply lt_mul_of_one_lt_left (int.nat_abs_pos_of_ne_zero hg'pos),
norm_num },
{ rw [←mul_right_inj' (four_ne_zero' ℤ), ←hc, ←hfactor, mul_left_comm] },
{ intros f' hf'dvd hf'odd,
refine hnotform f' _ hf'odd,
exact hf'dvd.mul_left _ } },
{ by_cases h : |g| = 1,
{ apply_fun abs at hfactor,
rw [abs_mul, h, mul_one, abs_of_nonneg (zsqrtd.norm_nonneg (by norm_num) a)] at hfactor,
exact ⟨_, hfactor⟩ },
{ rw [int.abs_eq_nat_abs, ←int.coe_nat_one, int.coe_nat_inj'] at h,
obtain ⟨p, pprime, pdvd⟩ := int.exists_prime_and_dvd h,
have : p ∣ a.norm,
{ rw [←hfactor],
exact pdvd.mul_left _ },
have podd : odd p := int.odd_iff_not_even.mpr (by {
intro X,
apply H,
apply even_iff_two_dvd.mpr,
apply dvd_trans _ this,
apply even_iff_two_dvd.mp X
}),
obtain ⟨A, HA⟩ := hnotform p pdvd podd,
have pprime' := pprime.abs,
rw [HA] at pprime',
have pdvd' : A.norm ∣ a.norm,
{ rw [←hfactor, ←HA, abs_dvd],
exact dvd_mul_of_dvd_right pdvd _ },
obtain ⟨c, -, hcd⟩ := spts.mul_of_dvd'' pdvd' pprime',
obtain ⟨q, rfl⟩ := pdvd,
have hqpos : q ≠ 0 := right_ne_zero_of_mul hgpos,
have : (p.sign * q).nat_abs = q.nat_abs,
{ rw [int.nat_abs_mul, int.nat_abs_sign_of_nonzero pprime.ne_zero, one_mul] },
refine IH q.nat_abs _ c (p.sign * q) _ _ _ this,
{ rw [int.nat_abs_mul],
apply lt_mul_of_one_lt_left (int.nat_abs_pos_of_ne_zero hqpos),
rw int.prime_iff_nat_abs_prime at pprime,
exact pprime.one_lt },
{ rwa [←int.nat_abs_eq_zero, this, int.nat_abs_eq_zero] },
{ rw [←mul_right_inj' pprime'.ne_zero, ←hcd, mul_left_comm, ←hfactor, ←HA, ←mul_assoc (|p|),
mul_comm (|p|), int.sign_mul_abs] },
{ intros f' hf'dvd hf'odd,
refine hnotform f' _ hf'odd,
rw [←int.dvd_nat_abs, this, int.dvd_nat_abs] at hf'dvd,
exact hf'dvd.mul_left _ } } }
end
lemma zqrtd.factor_div (a : ℤ√-3) {x : ℤ} (hodd : odd x) :
∃ c m : ℤ√-3, a = c + m * x ∧ c.norm < x ^ 2 :=
begin
obtain ⟨m, c, ha, hc⟩ := int.factor_div a.re x hodd,
obtain ⟨n, d, hb, hd⟩ := int.factor_div a.im x hodd,
set c' : ℤ√-3 := ⟨c, d⟩,
refine ⟨c', ⟨m, n⟩, _, _⟩,
{ simp only [zsqrtd.ext, ha, hb, add_zero, zsqrtd.coe_int_re, eq_self_iff_true, zsqrtd.mul_im,
zero_add, zsqrtd.add_im, and_self, zsqrtd.mul_re, mul_zero, zsqrtd.add_re, zsqrtd.coe_int_im] },
{ rw ←mul_lt_mul_left (by norm_num : (0 : ℤ) < 4),
calc 4 * c'.norm
= (2 * c) ^ 2 + 3 * (2 * d) ^ 2 : by { rw zsqrtd.norm_def, ring }
... < x ^ 2 + 3 * x ^ 2 : add_lt_add _ _
... = 4 * x ^ 2 : by ring,
{ rw [mul_pow, ←int.nat_abs_pow_two c, ←int.nat_abs_pow_two x, ←mul_pow],
norm_cast,
exact nat.pow_lt_pow_of_lt_left hc zero_lt_two },
{ rw [mul_pow, ←int.nat_abs_pow_two d, ←int.nat_abs_pow_two x, ←mul_pow,
mul_lt_mul_left (by norm_num : (0 : ℤ) < 3)],
norm_cast,
exact nat.pow_lt_pow_of_lt_left hd zero_lt_two } },
end
lemma zqrtd.factor_div' (a : ℤ√-3) {x : ℤ} (hodd : odd x) (h : 1 < |x|)
(hcoprime : is_coprime a.re a.im) (hfactor : x ∣ a.norm) :
∃ c m : ℤ√-3, a = c + m * x ∧ c.norm < x ^ 2 ∧ c ≠ 0 ∧
∃ y, c.norm = x * y ∧ y.nat_abs < x.nat_abs :=
begin
obtain ⟨c, m, rfl, h2⟩ := zqrtd.factor_div a hodd,
refine ⟨c, m, rfl, h2, _, _⟩,
{ rintro rfl,
apply h.ne',
rw ←int.is_unit_iff_abs_eq,
apply hcoprime.is_unit_of_dvd';
simp only [zero_add, mul_comm m, zsqrtd.smul_re, zsqrtd.smul_im, dvd_mul_right] },
{ obtain ⟨y, hy⟩ : x ∣ c.norm,
{ set e : ℤ := m.re ^ 2 * x + 2 * m.re * c.re + 3 * m.im ^ 2 * x + 6 * m.im * c.im with he,
convert dvd_sub hfactor (dvd_mul_right x e),
rw [he, zsqrtd.norm_def, zsqrtd.norm_def],
simp only [zsqrtd.coe_int_re, zsqrtd.mul_im, zsqrtd.add_im, zsqrtd.mul_re, zsqrtd.add_re,
zsqrtd.coe_int_im],
ring },
refine ⟨y, hy, _⟩,
have h0'' : 0 < x.nat_abs,
{ zify,
exact zero_lt_one.trans h },
rw [←mul_lt_mul_left h0'', ←pow_two, ←int.nat_abs_mul, ←hy],
zify,
rwa [← int.coe_nat_abs x, int.nat_abs_pow_two x, ← int.coe_nat_abs,
int.nat_abs_of_nonneg (zsqrtd.norm_nonneg (by norm_num) c)] },
end
-- Edwards p50 step (5')
lemma factors
(a : ℤ√-3)
(x : ℤ)
(hcoprime : is_coprime a.re a.im)
(hodd : odd x)
(hfactor : x ∣ a.norm) :
∃ c : ℤ√-3, abs x = c.norm :=
begin
induction hx' : x.nat_abs using nat.strong_induction_on with x' IH generalizing a x,
subst hx',
have hneg1 : 1 ≤ a.norm,
{ rw [←int.sub_one_lt_iff, sub_self],
apply lt_of_le_of_ne (zsqrtd.norm_nonneg (by norm_num) a),
rw [ne.def, eq_comm, zsqrtd.norm_eq_zero_iff (by norm_num : (-3 : ℤ) < 0)],
rintro rfl,
rw [zsqrtd.zero_im, zsqrtd.zero_re] at hcoprime,
exact not_coprime_zero_zero hcoprime },
have h0 : x ≠ 0,
{ rintro rfl,
simpa only [even_zero, not_true, int.odd_iff_not_even] using hodd },
have h0' : 1 ≤ abs x,
{ rwa [←int.sub_one_lt_iff, sub_self, abs_pos] },
cases h0'.eq_or_lt with h h,
{ rw ←h,
refine ⟨⟨1, 0⟩, _⟩,
norm_num [zsqrtd.norm_def] },
obtain ⟨c', m, rfl, h2', h1, ⟨y, hy, h3⟩⟩ := zqrtd.factor_div' a hodd h hcoprime hfactor,
have h4 : c'.norm ≠ 0,
{ rwa [ne.def, zsqrtd.norm_eq_zero_iff (by norm_num) c'] },
set g := int.gcd c'.re c'.im with hg,
have hgpos : 0 < g,
{ rwa [hg, zsqrtd.gcd_pos_iff] },
obtain ⟨C', HC', HCDcoprime⟩ := zsqrtd.exists_coprime_of_gcd_pos hgpos,
have h5 : x * y = g ^ 2 * C'.norm,
{ rw [←hy, HC', zsqrtd.norm_mul, zsqrtd.norm_int_cast, ←pow_two] },
obtain ⟨z, hz⟩ : (g ^ 2 : ℤ) ∣ y,
{ have : (g ^ 2 : ℤ) ∣ x * y,
{ rw h5, exact dvd_mul_right _ _ },
apply is_coprime.dvd_of_dvd_mul_left _ this,
apply is_coprime_of_prime_dvd,
{ contrapose! h0, exact h0.2 },
intros p hpprime hpdvdleft hpdvdright,
have : ↑p ∣ c' + m * x,
{ rw [HC'],
exact dvd_add
(dvd_mul_of_dvd_left
((zsqrtd.coe_int_dvd_coe_int _ _).mpr (hpprime.dvd_of_dvd_pow hpdvdleft)) _)
(dvd_mul_of_dvd_right ((zsqrtd.coe_int_dvd_coe_int _ _).mpr hpdvdright) _) },
have := zsqrtd.coprime_of_dvd_coprime hcoprime this,
simpa only [zsqrtd.coe_int_re, is_coprime_zero_right, zsqrtd.coe_int_im, hpprime.not_unit] using this },
have h6 : x * z = C'.norm,
{ have hgnezero := int.coe_nat_ne_zero_iff_pos.mpr hgpos,
apply int.eq_of_mul_eq_mul_left (pow_ne_zero 2 hgnezero),
rw [←h5, hz, mul_left_comm] },
have h8 : z ≠ 0,
{ apply right_ne_zero_of_mul,
apply right_ne_zero_of_mul,
rwa [h6, ←h5, ←hy] },
refine factors' _ x z hodd h8 h6 _,
intros w hwdvd hwodd,
refine IH w.nat_abs _ C' w HCDcoprime hwodd _ rfl,
{ calc w.nat_abs
≤ z.nat_abs : nat.le_of_dvd (int.nat_abs_pos_of_ne_zero h8) (int.nat_abs_dvd_iff_dvd.mpr hwdvd)
... ≤ y.nat_abs : by { rw [hz, int.nat_abs_mul], exact nat.le_mul_of_pos_left (pow_pos hgpos 2) }
... < x.nat_abs : h3 },
{ rw ←h6,
exact dvd_mul_of_dvd_right hwdvd x },
end
theorem spts.eq_one
{a : ℤ√-3}
(h : a.norm = 1) :
abs a.re = 1 ∧ a.im = 0 :=
begin
suffices H : abs a.re = 1,
{ refine ⟨H, _⟩,
rw [zsqrtd.norm_def, mul_assoc, ←int.nat_abs_mul_self' a.re, ←int.abs_eq_nat_abs, H, one_mul,
neg_mul, sub_neg_eq_add, add_right_eq_self, mul_eq_zero,
mul_self_eq_zero] at h,
exact h.resolve_left three_ne_zero },
contrapose! h,
cases lt_or_gt_of_ne h with H H,
{ have : a.re = 0,
{ rwa [←int.abs_lt_one_iff] },
simp only [zsqrtd.norm_def, this, zero_mul, zero_sub, neg_mul, neg_neg],
by_cases hb : a.im = 0,
{ simp only [hb, not_false_iff, zero_ne_one, mul_zero] },
{ have : 1 ≤ abs a.im,
{ rwa [←int.abs_lt_one_iff, not_lt] at hb },
have : 1 ≤ a.im ^ 2,
{ rw ←sq_abs,
exact pow_le_pow_of_le_left zero_le_one this 2 },
linarith } },
{ apply ne_of_gt,
rw [zsqrtd.norm_def, neg_mul, neg_mul, sub_neg_eq_add],
apply lt_add_of_lt_of_nonneg,
{ rw [←sq, ←sq_abs],
exact pow_lt_pow_of_lt_left H zero_le_one zero_lt_two },
{ rw mul_assoc,
exact mul_nonneg zero_lt_three.le (mul_self_nonneg _) } }
end
theorem spts.eq_one'
{a : ℤ√-3}
(h : a.norm = 1) :
a = 1 ∨ a = -1 :=
begin
simp only [zsqrtd.ext, zsqrtd.one_re, zsqrtd.one_im, zsqrtd.neg_im, zsqrtd.neg_re, neg_zero,
←or_and_distrib_right, ←abs_eq (zero_le_one' ℤ), spts.eq_one h, eq_self_iff_true, and_self],
end
lemma spts.ne_zero_of_coprime'
(a : ℤ√-3)
(hcoprime : is_coprime a.re a.im) :
a.norm ≠ 0 :=
begin
contrapose! hcoprime with H,
obtain ⟨rfl, rfl⟩ := (zsqrtd.norm_eq_zero_iff (by norm_num) _).mp H,
exact not_coprime_zero_zero,
end
lemma spts.pos_of_coprime'
{a : ℤ√-3}
(hcoprime : is_coprime a.re a.im) :
0 < a.norm :=
begin
apply lt_of_le_of_ne,
{ apply zsqrtd.norm_nonneg, norm_num },
{ symmetry, exact spts.ne_zero_of_coprime' _ hcoprime }
end
lemma spts.one_lt_of_im_ne_zero
(a : ℤ√-3)
(hb : a.im ≠ 0) :
1 < a.norm :=
begin
apply lt_of_le_of_ne,
{ rw [←int.sub_one_lt_iff, sub_self],
apply lt_of_le_of_ne (zsqrtd.norm_nonneg (by norm_num) a),
contrapose! hb,
rw [eq_comm, zsqrtd.norm_eq_zero_iff (by norm_num) a] at hb,
rw [hb, zsqrtd.zero_im] },
{ intro H,
exact hb (spts.eq_one H.symm).2 }
end
lemma spts.not_two
(a : ℤ√-3) :
a.norm ≠ 2 :=
begin
rw zsqrtd.norm_def,
obtain him|him := eq_or_ne a.im 0,
{ rw [him, mul_zero, sub_zero, ←int.nat_abs_mul_self, ←sq],
norm_cast,
apply (nat.pow_left_strict_mono one_le_two).monotone.ne_of_lt_of_lt_nat 1; norm_num },
{ apply ne_of_gt,
apply lt_add_of_nonneg_of_lt (mul_self_nonneg a.re),
rw ←int.add_one_le_iff,
rw [mul_assoc, neg_mul_eq_neg_mul, neg_neg],
refine le_mul_of_one_le_right zero_lt_three.le _,
rwa [←int.sub_one_lt_iff, sub_self, mul_self_pos] }
end
lemma spts.four
{p : ℤ√-3}
(hfour : p.norm = 4)
(hq : p.im ≠ 0) :
abs p.re = 1 ∧ abs p.im = 1 :=
begin
suffices : p.re ^ 2 = 1 ∧ p.im ^ 2 = 1,
{ apply and.imp _ _ this;
{ intro h,
rwa [←sq_eq_sq (abs_nonneg (_ : ℤ)) zero_le_one, one_pow, sq_abs] } },
have hq : p.im ^ 2 = 1,
{ apply le_antisymm,
{ contrapose! hfour with hq',
apply ne_of_gt,
rw ←int.add_one_le_iff at hq',
calc 4 < 3 * 2 : by norm_num
... ≤ 3 * p.im ^ 2 : int.mul_le_mul_of_nonneg_left hq' (by norm_num)
... ≤ p.re ^ 2 + 3 * p.im ^ 2 : le_add_of_nonneg_left (pow_two_nonneg p.re)
... = p.norm : by { rw [zsqrtd.norm_def], ring } },
{ rw [←int.sub_one_lt_iff, sub_self],
exact sq_pos_of_ne_zero _ hq, } },
refine ⟨_, hq⟩,
calc p.re ^ 2
= p.re ^ 2 + 3 * p.im ^ 2 - 3 : by rw [hq, mul_one, add_sub_cancel]
... = p.norm - 3 : by { rw [zsqrtd.norm_def], ring }
... = 1 : by { rw hfour, norm_num },
end
lemma spts.four_of_coprime
{p : ℤ√-3}
(hcoprime : is_coprime p.re p.im)
(hfour : p.norm = 4) :
abs p.re = 1 ∧ abs p.im = 1 :=
begin
apply spts.four hfour,
rintro him,
rw [him, is_coprime_zero_right, int.is_unit_iff_abs_eq] at hcoprime,
rw [zsqrtd.norm_def, him, mul_zero, sub_zero, ←sq, ←sq_abs, hcoprime] at hfour,
norm_num at hfour
end
|
0d4453edc27d113f49108387156f04aa79b08cbe | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/498.lean | 4c4692b166fe2dc9703f0734886969e506405da6 | [
"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 | 2,878 | lean | structure ParamType where
/-- Name of the type, used when displaying the help. -/
name : String
/-- Function to check whether a value conforms to the type. -/
isValid : String → Bool
structure Flag where
/-- Designates `x` in `-x`. -/
shortName? : Option String := none
/-- Designates `x` in `--x`. -/
longName : String
/-- Description that is displayed in the help. -/
description : String
/--
Type according to which the parameter is validated.
`Unit` is used to designate flags without a parameter.
-/
type : ParamType
structure InputFlag where
/-- Flag name input by the user. -/
name : String
/-- Whether the flag input by the user was a short one. -/
isShort : Bool
instance : ToString InputFlag where
toString f :=
let pre := if f.isShort then "-" else "--"
s!"{pre}{f.name}"
structure Arg where
/- Name that is displayed in the help. -/
name : String
/- Description that is displayed in the help. -/
description : String
/- Description that is displayed in the help. -/
type : ParamType
-- (deterministic) timeout at 'whnf', maximum number of heartbeats (50000) has been reached (use 'set_option maxHeartbeats <num>' to set the limit)
inductive Kind
| unknownFlag
(inputFlag : InputFlag)
(msg : String :=
s!"Unknown flag `{inputFlag}`.")
| missingFlagArg
(flag : Flag)
(inputFlag : InputFlag)
(msg : String :=
s!"Missing argument for flag `{inputFlag}`.")
| duplicateFlag
(flag : Flag)
(inputFlag : InputFlag)
(msg : String :=
let complementaryName? : Option String := do
if inputFlag.isShort then
pure s!" (`--{flag.longName}`)"
else
pure s!" (`-{← flag.shortName?}`)"
s!"Duplicate flag `{inputFlag}`.")
| redundantFlagArg
(flag : Flag)
(inputFlag : InputFlag)
(inputValue : String)
(msg : String :=
s!"Redundant argument `{inputValue}` for flag `{inputFlag}` that takes no arguments.")
| invalidFlagType
(flag : Flag)
(inputFlag : InputFlag)
(inputValue : String)
(msg : String :=
s!"Invalid type of argument `{inputValue}` for flag `{inputFlag} : {flag.type.name}`.")
| missingPositionalArg
(arg : Arg)
(msg : String :=
s!"Missing positional argument `<{arg.name}>.`")
| invalidPositionalArgType
(arg : Arg)
(inputArg : String)
(msg : String :=
s!"Invalid type of argument `{inputArg}` for positional argument `<{arg.name} : {arg.type.name}>`.")
| redundantPositionalArg
(inputArg : String)
(msg : String :=
s!"Redundant positional argument `{inputArg}`.")
| invalidVariableArgType
(arg : Arg)
(inputArg : String)
(msg : String :=
s!"Invalid type of argument `{inputArg}` for variable argument `<{arg.name} : {arg.type.name}>...`.")
#check @Kind.missingFlagArg.inj
|
0c6b4cae3a850a51cf48534adf9f20a38430c25d | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/match_expr.lean | 2e20c2795b4156e85625632a214e962332fce59a | [
"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 | 410 | lean | open tactic
axiom Sorry : ∀ {A:Sort*}, A
example (a b c : nat) (h₀ : c > 0) (h₁ : a > 1) (h₂ : b > 0) : a + b + c = 0 :=
by do
[x, y] ← match_target_subexpr ``(λ x y : nat, x + y) | failed,
trace "------ subterms -------",
trace x, trace y,
(h, [z]) ← match_hypothesis ``(λ x : nat, x > 1) | failed,
trace "--- hypothesis of the form x > 1 ---",
trace h, trace z,
refine ``(Sorry)
|
23405b759eb49aa6136ea1b0ad356089237f318f | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/special_functions/trigonometric/basic.lean | 63146c0dedc68920fbb59a958001fe02096ff152 | [
"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 | 41,869 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.exp
/-!
# Trigonometric functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Main definitions
This file contains the definition of `π`.
See also `analysis.special_functions.trigonometric.inverse` and
`analysis.special_functions.trigonometric.arctan` for the inverse trigonometric functions.
See also `analysis.special_functions.complex.arg` and
`analysis.special_functions.complex.log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`analysis.special_functions.trigonometric.complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `analysis.special_functions.trigonometric.chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable theory
open_locale classical topology filter
open set filter
namespace complex
@[continuity] lemma continuous_sin : continuous sin :=
by { change continuous (λ z, ((exp (-z * I) - exp (z * I)) * I) / 2), continuity, }
lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on
@[continuity] lemma continuous_cos : continuous cos :=
by { change continuous (λ z, (exp (z * I) + exp (-z * I)) / 2), continuity, }
lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on
@[continuity] lemma continuous_sinh : continuous sinh :=
by { change continuous (λ z, (exp z - exp (-z)) / 2), continuity, }
@[continuity] lemma continuous_cosh : continuous cosh :=
by { change continuous (λ z, (exp z + exp (-z)) / 2), continuity, }
end complex
namespace real
variables {x y z : ℝ}
@[continuity] lemma continuous_sin : continuous sin :=
complex.continuous_re.comp (complex.continuous_sin.comp complex.continuous_of_real)
lemma continuous_on_sin {s} : continuous_on sin s :=
continuous_sin.continuous_on
@[continuity] lemma continuous_cos : continuous cos :=
complex.continuous_re.comp (complex.continuous_cos.comp complex.continuous_of_real)
lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on
@[continuity] lemma continuous_sinh : continuous sinh :=
complex.continuous_re.comp (complex.continuous_sinh.comp complex.continuous_of_real)
@[continuity] lemma continuous_cosh : continuous cosh :=
complex.continuous_re.comp (complex.continuous_cosh.comp complex.continuous_of_real)
end real
namespace real
lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuous_on_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `data.real.pi.bounds`. -/
protected noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation (name := real.pi) `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 :=
by rw [real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : π / 2 ≤ 2 :=
by rw [real.pi, mul_div_cancel_left _ (two_ne_zero' ℝ)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(by rw div_self (two_ne_zero' ℝ); exact one_le_pi_div_two)
lemma pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(calc π / 2 ≤ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_ne_zero : π ≠ 0 :=
ne_of_gt pi_pos
lemma pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * π :=
by linarith [pi_pos]
end real
namespace nnreal
open real
open_locale real nnreal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 := ⟨π, real.pi_pos.le⟩
@[simp] lemma coe_real_pi : (pi : ℝ) = π := rfl
lemma pi_pos : 0 < pi := by exact_mod_cast real.pi_pos
lemma pi_ne_zero : pi ≠ 0 := pi_pos.ne'
end nnreal
namespace real
open_locale real
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left π (two_ne_zero' ℝ), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← mul_div_cancel_left π (two_ne_zero' ℝ), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_antiperiodic : function.antiperiodic sin π :=
by simp [sin_add]
lemma sin_periodic : function.periodic sin (2 * π) :=
sin_antiperiodic.periodic
@[simp] lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
@[simp] lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
@[simp] lemma sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
@[simp] lemma sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
@[simp] lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
@[simp] lemma sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
@[simp] lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
@[simp] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
@[simp] lemma sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
@[simp] lemma sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
@[simp] lemma sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
@[simp] lemma sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
@[simp] lemma sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
@[simp] lemma sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
lemma cos_antiperiodic : function.antiperiodic cos π :=
by simp [cos_add]
lemma cos_periodic : function.periodic cos (2 * π) :=
cos_antiperiodic.periodic
@[simp] lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
@[simp] lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
@[simp] lemma cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
@[simp] lemma cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
@[simp] lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
@[simp] lemma cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
@[simp] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
@[simp] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
@[simp] lemma cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
@[simp] lemma cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
@[simp] lemma cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
@[simp] lemma cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
@[simp] lemma cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
@[simp] lemma cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
@[simp] lemma cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : ℝ) + 2 = 4, from rfl,
have π - x ≤ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
lemma sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x :=
begin
rw ← closure_Ioo pi_ne_zero.symm at hx,
exact closure_lt_subset_le continuous_const continuous_sin
(closure_mono (λ y, sin_pos_of_mem_Ioo) hx)
end
lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
have sin (π / 2) = 1 ∨ sin (π / 2) = -1 :=
by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2),
this.resolve_right
(λ h, (show ¬(0 : ℝ) < -1, by norm_num) $
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
lemma sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = sqrt (1 - cos x ^ 2) :=
by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
lemma cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = sqrt (1 - sin x ^ 2) :=
by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) :
sin x = 0 ↔ x = 0 :=
⟨λ h, le_antisymm
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂
... = 0 : h))
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)),
λ h, by simp [h]⟩
lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (int.sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃,
(sin_pos_of_pos_of_lt_pi h₃ (int.sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
lemma sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x,
sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
(λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [← hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))⟩,
λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩
lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨λ h,
begin
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩,
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁,
norm_cast at hx₁ hx₂,
obtain rfl : n = 0 := le_antisymm (by linarith) (by linarith),
simp
end,
λ h, by simp [h]⟩
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) :
cos y < cos x :=
begin
rw [← sub_lt_zero, cos_sub_cos],
have : 0 < sin ((y + x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
have : 0 < sin ((y - x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
nlinarith,
end
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x :=
match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_mem_Ioo ⟨by linarith, hx⟩)
(λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma strict_anti_on_cos : strict_anti_on cos (Icc 0 π) :=
λ x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strict_anti_on_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
lemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y :=
by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma strict_mono_on_sin : strict_mono_on sin (Icc (-(π / 2)) (π / 2)) :=
λ x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y :=
(strict_mono_on_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
lemma inj_on_sin : inj_on sin (Icc (-(π / 2)) (π / 2)) :=
strict_mono_on_sin.inj_on
lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_anti_on_cos.inj_on
lemma surj_on_sin : surj_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
by simpa only [sin_neg, sin_pi_div_two]
using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on
lemma surj_on_cos : surj_on cos (Icc 0 π) (Icc (-1) 1) :=
by simpa only [cos_zero, cos_pi]
using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on
lemma sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩
lemma cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩
lemma maps_to_sin (s : set ℝ) : maps_to sin s (Icc (-1 : ℝ) 1) := λ x _, sin_mem_Icc x
lemma maps_to_cos (s : set ℝ) : maps_to cos s (Icc (-1 : ℝ) 1) := λ x _, cos_mem_Icc x
lemma bij_on_sin : bij_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨maps_to_sin _, inj_on_sin, surj_on_sin⟩
lemma bij_on_cos : bij_on cos (Icc 0 π) (Icc (-1) 1) :=
⟨maps_to_cos _, inj_on_cos, surj_on_cos⟩
@[simp] lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range
@[simp] lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range
lemma range_cos_infinite : (range real.cos).infinite :=
by { rw real.range_cos, exact Icc_infinite (by norm_num) }
lemma range_sin_infinite : (range real.sin).infinite :=
by { rw real.range_sin, exact Icc_infinite (by norm_num) }
section cos_div_sq
variable (x : ℝ)
/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`
-/
@[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ
| 0 := x
| (n+1) := sqrt (2 + sqrt_two_add_series n)
lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp
lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp
lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp
lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n
| 0 := le_refl 0
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n
| 0 := h
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2
| 0 := by norm_num
| (n+1) :=
begin
refine lt_of_lt_of_le _ (sqrt_sq zero_lt_two.le).le,
rw [sqrt_two_add_series, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'],
{ refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num },
{ exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) }
end
lemma sqrt_two_add_series_succ (x : ℝ) :
∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n
| 0 := rfl
| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]
lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) :
∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n
| 0 := h
| (n+1) :=
begin
rw [sqrt_two_add_series, sqrt_two_add_series],
exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _)
end
@[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (π / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2
| 0 := by simp
| (n+1) :=
begin
have : (2 : ℝ) ≠ 0 := two_ne_zero,
symmetry, rw [div_eq_iff_mul_eq this], symmetry,
rw [sqrt_two_add_series, sqrt_eq_iff_sq_eq, mul_pow, cos_sq, ←mul_div_assoc,
nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul],
congr, { norm_num },
rw [mul_comm, sq, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc,
mul_div_cancel_left]; try { exact this },
apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,
apply le_of_lt, apply cos_pos_of_mem_Ioo ⟨_, _⟩,
{ transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos,
apply div_pos pi_pos, apply pow_pos, norm_num },
apply div_lt_div' (le_refl π) _ pi_pos _,
refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}
end
lemma sin_sq_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_sq, cos_pi_over_two_pow]
lemma sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_sq_pi_over_two_pow, sqrt_two_add_series, div_pow, sq_sqrt, add_div, ←sub_sub],
congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,
end
@[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_eq_iff_sq_eq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul],
{ congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },
{ rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },
apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],
refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,
apply pow_pos, all_goals {norm_num}
end
@[simp] lemma cos_pi_div_four : cos (π / 4) = sqrt 2 / 2 :=
by { transitivity cos (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma sin_pi_div_four : sin (π / 4) = sqrt 2 / 2 :=
by { transitivity sin (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma cos_pi_div_eight : cos (π / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma sin_pi_div_eight : sin (π / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma cos_pi_div_sixteen : cos (π / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma sin_pi_div_sixteen : sin (π / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma cos_pi_div_thirty_two : cos (π / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (π / 2 ^ 5), congr, norm_num, simp }
@[simp] lemma sin_pi_div_thirty_two : sin (π / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (π / 2 ^ 5), congr, norm_num, simp }
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp] lemma cos_pi_div_three : cos (π / 3) = 1 / 2 :=
begin
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0,
{ have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring },
linarith [cos_pi, cos_three_mul (π / 3)] },
cases mul_eq_zero.mp h₁ with h h,
{ linarith [pow_eq_zero h] },
{ have : cos π < cos (π / 3),
{ refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _;
linarith [pi_pos] },
linarith [cos_pi] }
end
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 :=
begin
have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,
{ convert cos_sq (π / 6),
have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms,
rw [h2, cos_pi_div_three] },
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring
end
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp] lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 :=
begin
suffices : sqrt 3 = cos (π / 6) * 2,
{ field_simp [(by norm_num : 0 ≠ 2)], exact this.symm },
rw sqrt_eq_iff_sq_eq,
{ have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr sq_cos_pi_div_six,
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring },
{ norm_num },
{ have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] },
linarith },
end
/-- The sine of `π / 6` is `1 / 2`. -/
@[simp] lemma sin_pi_div_six : sin (π / 6) = 1 / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_three],
congr,
ring
end
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 :=
begin
rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six],
congr,
ring
end
/-- The sine of `π / 3` is `√3 / 2`. -/
@[simp] lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_six],
congr,
ring
end
end cos_div_sq
/-- `real.sin` as an `order_iso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/
def sin_order_iso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1:ℝ) 1 :=
(strict_mono_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq
@[simp] lemma coe_sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
(sin_order_iso x : ℝ) = sin x := rfl
lemma sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
sin_order_iso x = ⟨sin x, sin_mem_Icc x⟩ := rfl
@[simp] lemma tan_pi_div_four : tan (π / 4) = 1 :=
begin
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four],
have h : (sqrt 2) / 2 > 0 := by cancel_denoms,
exact div_self (ne_of_gt h),
end
@[simp] lemma tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos]
lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x :=
by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩)
lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]
| or.inr hx0, _ := by simp [hx0.symm]
end
lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) :
tan x ≤ 0 :=
neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))
lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ}
(hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) :
tan x < tan y :=
begin
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],
exact div_lt_div
(sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy)
(cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩)
end
lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x)
(hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y :=
match le_total x 0, le_total y 0 with
| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact
tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0)
(neg_lt.2 hx₁) (neg_lt_neg hxy)
| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim
(λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁)
... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂)
(λ hy0, by rw [← hy0, tan_zero]; exact
tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁)
| or.inr hx0, or.inl hy0 := by linarith
| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy
end
lemma strict_mono_on_tan : strict_mono_on tan (Ioo (-(π / 2)) (π / 2)) :=
λ x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2
lemma inj_on_tan : inj_on tan (Ioo (-(π / 2)) (π / 2)) :=
strict_mono_on_tan.inj_on
lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y :=
inj_on_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy
lemma tan_periodic : function.periodic tan π :=
by simpa only [function.periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
lemma tan_add_pi (x : ℝ) : tan (x + π) = tan x :=
tan_periodic x
lemma tan_sub_pi (x : ℝ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
lemma tan_pi_sub (x : ℝ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
lemma tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ :=
by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
lemma tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
lemma tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
lemma tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
lemma tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
lemma tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
lemma tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
lemma tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[<] (π/2)) (𝓝 1) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[<] (π/2)) (𝓝[>] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (neg_lt_self pi_div_two_pos))]
with x hx using cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[<] (π/2)) at_top :=
begin
convert tendsto_cos_pi_div_two.inv_tendsto_zero.at_top_mul zero_lt_one
tendsto_sin_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
lemma tendsto_sin_neg_pi_div_two : tendsto sin (𝓝[>] (-(π/2))) (𝓝 (-1)) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[>] (-(π/2))) (𝓝[>] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Ioi (left_mem_Ico.mpr (neg_lt_self pi_div_two_pos))]
with x hx using cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[>] (-(π/2))) at_bot :=
begin
convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.at_top_mul_neg (by norm_num)
tendsto_sin_neg_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
end real
namespace complex
open_locale real
lemma sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp
... = 0 : by simp
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp
... = 1 : by simp
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← of_real_sin, real.sin_pi]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← of_real_cos, real.cos_pi]; simp
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_antiperiodic : function.antiperiodic sin π :=
by simp [sin_add]
lemma sin_periodic : function.periodic sin (2 * π) :=
sin_antiperiodic.periodic
lemma sin_add_pi (x : ℂ) : sin (x + π) = -sin x :=
sin_antiperiodic x
lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x :=
sin_periodic x
lemma sin_sub_pi (x : ℂ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
lemma sin_sub_two_pi (x : ℂ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
lemma sin_two_pi_sub (x : ℂ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
lemma sin_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
lemma sin_add_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
lemma sin_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
lemma sin_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
lemma sin_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
lemma sin_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
lemma cos_antiperiodic : function.antiperiodic cos π :=
by simp [cos_add]
lemma cos_periodic : function.periodic cos (2 * π) :=
cos_antiperiodic.periodic
lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x :=
cos_antiperiodic x
lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x :=
cos_periodic x
lemma cos_sub_pi (x : ℂ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
lemma cos_sub_two_pi (x : ℂ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
lemma cos_two_pi_sub (x : ℂ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
lemma cos_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
lemma cos_add_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
lemma cos_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
lemma cos_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
lemma cos_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
lemma cos_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
lemma cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
lemma cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
lemma cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
lemma sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma tan_periodic : function.periodic tan π :=
by simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
lemma tan_add_pi (x : ℂ) : tan (x + π) = tan x :=
tan_periodic x
lemma tan_sub_pi (x : ℂ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
lemma tan_pi_sub (x : ℂ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
lemma tan_pi_div_two_sub (x : ℂ) : tan (π / 2 - x) = (tan x)⁻¹ :=
by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
lemma tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
lemma tan_add_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
lemma tan_add_int_mul_pi (x : ℂ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
lemma tan_sub_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
lemma tan_sub_int_mul_pi (x : ℂ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
lemma tan_nat_mul_pi_sub (x : ℂ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
lemma tan_int_mul_pi_sub (x : ℂ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
lemma exp_antiperiodic : function.antiperiodic exp (π * I) :=
by simp [exp_add, exp_mul_I]
lemma exp_periodic : function.periodic exp (2 * π * I) :=
(mul_assoc (2:ℂ) π I).symm ▸ exp_antiperiodic.periodic
lemma exp_mul_I_antiperiodic : function.antiperiodic (λ x, exp (x * I)) π :=
by simpa only [mul_inv_cancel_right₀ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero
lemma exp_mul_I_periodic : function.periodic (λ x, exp (x * I)) (2 * π) :=
exp_mul_I_antiperiodic.periodic
@[simp] lemma exp_pi_mul_I : exp (π * I) = -1 :=
exp_zero ▸ exp_antiperiodic.eq
@[simp] lemma exp_two_pi_mul_I : exp (2 * π * I) = 1 :=
exp_periodic.eq.trans exp_zero
@[simp] lemma exp_nat_mul_two_pi_mul_I (n : ℕ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.nat_mul_eq n).trans exp_zero
@[simp] lemma exp_int_mul_two_pi_mul_I (n : ℤ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.int_mul_eq n).trans exp_zero
@[simp] lemma exp_add_pi_mul_I (z : ℂ) : exp (z + π * I) = -exp z :=
exp_antiperiodic z
@[simp] lemma exp_sub_pi_mul_I (z : ℂ) : exp (z - π * I) = -exp z :=
exp_antiperiodic.sub_eq z
/-- A supporting lemma for the **Phragmen-Lindelöf principle** in a horizontal strip. If `z : ℂ`
belongs to a horizontal strip `|complex.im z| ≤ b`, `b ≤ π / 2`, and `a ≤ 0`, then
$$\left|exp^{a\left(e^{z}+e^{-z}\right)}\right| \le e^{a\cos b \exp^{|re z|}}.$$
-/
lemma abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le {a b : ℝ} (ha : a ≤ 0)
{z : ℂ} (hz : |z.im| ≤ b) (hb : b ≤ π / 2) :
abs (exp (a * (exp z + exp (-z)))) ≤ real.exp (a * real.cos b * real.exp (|z.re|)) :=
begin
simp only [abs_exp, real.exp_le_exp, of_real_mul_re, add_re, exp_re, neg_im, real.cos_neg,
← add_mul, mul_assoc, mul_comm (real.cos b), neg_re, ← real.cos_abs z.im],
have : real.exp (|z.re|) ≤ real.exp z.re + real.exp (-z.re),
from apply_abs_le_add_of_nonneg (λ x, (real.exp_pos x).le) z.re,
refine mul_le_mul_of_nonpos_left (mul_le_mul this _ _ ((real.exp_pos _).le.trans this)) ha,
{ exact real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _)
(hb.trans $ half_le_self $ real.pi_pos.le) hz },
{ refine real.cos_nonneg_of_mem_Icc ⟨_, hb⟩,
exact (neg_nonpos.2 $ real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz) }
end
end complex
|
6b11005fba71f7dd9a5fccd54d61987cdb4502ce | f3a5af2927397cf346ec0e24312bfff077f00425 | /src/game/world3/level8.lean | 867ef68144edd88b82e2a43df4b5e4b9c0a62d31 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/natural_number_game | 05c39e1586408cfb563d1a12e1085a90726ab655 | f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd | refs/heads/master | 1,688,570,964,990 | 1,636,908,242,000 | 1,636,908,242,000 | 195,403,790 | 277 | 84 | Apache-2.0 | 1,694,547,955,000 | 1,562,328,792,000 | Lean | UTF-8 | Lean | false | false | 1,124 | lean | import game.world3.level7 -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 8: `mul_comm`
Finally, the boss level of multiplication world. But (assuming you
didn't cheat) you are well-prepared for it -- you have `zero_mul`
and `mul_zero`, as well as `succ_mul` and `mul_succ`. After this
level you can of course throw away one of each pair if you like,
but I would recommend you hold on to them, sometimes it's convenient
to have exactly the right tools to do a job.
-/
/- Lemma
Multiplication is commutative.
-/
lemma mul_comm (a b : mynat) : a * b = b * a :=
begin [nat_num_game]
induction b with d hd,
{
rw zero_mul,
rw mul_zero,
refl,
},
{
rw succ_mul,
rw ←hd,
rw mul_succ,
refl,
}
end
/-
You've now proved that the natural numbers are a commutative semiring!
That's the last collectible in Multiplication World.
-/
instance mynat.comm_semiring : comm_semiring mynat := by structure_helper
/-
But don't leave multiplication just yet -- prove `mul_left_comm`, the last
level of the world, and then we can beef up the power of `simp`.
-/
end mynat -- hide
|
c8ac99e397d5a876bd9ee4dde81414a8b547cc7e | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/finset/order.lean | af8b632cd9c4f48ba6212f9dd39ca9cdbfa05578 | [
"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 | 893 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau
-/
import data.finset.basic
/-!
# Finsets of ordered types
-/
universes u v w
variables {α : Type u}
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₂)⟩
lemma finset.exists_le [nonempty α] [preorder α] [is_directed α (≤)] (s : finset α) :
∃ M, ∀ i ∈ s, i ≤ M :=
directed_id.finset_le _
|
97ccb3219cbd3ea635038c41b155741de85d9e32 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/field_theory/fixed.lean | 295414fb9ea819df53c33b33e5bc43ccc8095877 | [
"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 | 12,487 | 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 deprecated.subfield
import field_theory.normal
import field_theory.separable
import field_theory.tower
import linear_algebra.matrix
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 (G : Type u) [group G] (F : Type v) [field F] [mul_semiring_action G F] (g : G)
instance fixed_by.is_subfield : is_subfield (fixed_by G F g) :=
{ zero_mem := smul_zero g,
add_mem := λ x y hx hy, (smul_add g x y).trans $ congr_arg2 _ hx hy,
neg_mem := λ x hx, (smul_neg g x).trans $ congr_arg _ hx,
one_mem := smul_one g,
mul_mem := λ x y hx hy, (smul_mul' g x y).trans $ congr_arg2 _ hx hy,
inv_mem := λ x hx, (smul_inv F g x).trans $ congr_arg _ hx }
namespace fixed_points
instance : is_subfield (fixed_points G F) :=
by convert @is_subfield.Inter F _ G (fixed_by G F) _; rw fixed_eq_Inter_fixed_by
instance : is_invariant_subring G (fixed_points G F) :=
{ smul_mem := λ g x hx g', by rw [hx, hx] }
@[simp] theorem smul (g : G) (x : fixed_points G F) : g • x = x :=
subtype.eq $ x.2 g
-- Why is this so slow?
@[simp] theorem smul_polynomial (g : G) (p : polynomial (fixed_points G F)) : g • 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 G F) F :=
algebra.of_is_subring _
theorem coe_algebra_map :
algebra_map (fixed_points G F) F = is_subring.subtype (fixed_points G F) :=
rfl
lemma linear_independent_smul_of_linear_independent {s : finset F} :
linear_independent (fixed_points G F) (λ i : (↑s : set F), (i : F)) →
linear_independent F (λ i : (↑s : set F), mul_action.to_fun G F i) :=
begin
refine finset.induction_on s (λ _, linear_independent_empty_type $ λ ⟨x⟩, x.2)
(λ 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_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 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 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 G F) :=
(prod_X_sub_smul G F x).to_subring _ $ λ c hc g,
let ⟨hc0, n, hn⟩ := finsupp.mem_frange.1 hc in hn ▸ prod_X_sub_smul.coeff G F x g n
namespace minpoly
theorem monic : (minpoly G F x).monic :=
subtype.eq $ prod_X_sub_smul.monic G F x
theorem eval₂ :
polynomial.eval₂ (is_subring.subtype $ fixed_points G F) x (minpoly G F x) = 0 :=
begin
rw [← prod_X_sub_smul.eval G F x, polynomial.eval₂_eq_eval_map],
simp [minpoly],
end
theorem ne_one :
minpoly G F x ≠ (1 : polynomial (fixed_points 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 G F))
(hf : polynomial.eval₂ (is_subring.subtype $ fixed_points G F) x f = 0) :
minpoly G F x ∣ f :=
begin
rw [← polynomial.map_dvd_map' (is_subring.subtype $ fixed_points G F),
minpoly, polynomial.map_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', ← is_invariant_subring.coe_subtype_hom' G (fixed_points G F),
← 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, hf, smul_zero]
end
/- Why is this so slow? -/
theorem irreducible_aux (f g : polynomial (fixed_points 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 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 G F) x :=
minpoly.unique' (minpoly.irreducible G F x)
(minpoly.eval₂ G F x) (minpoly.monic G F x)
instance normal : normal (fixed_points 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, polynomial.map_to_subring, prod_X_sub_smul],
exact polynomial.splits_prod _ (λ _ _, polynomial.splits_X_sub_C _) }⟩
instance separable : is_separable (fixed_points G F) F :=
⟨λ x, is_integral G F x,
λ x, by {
rw [← minpoly_eq_minpoly, ← polynomial.separable_map (is_subring.subtype (fixed_points G F)),
minpoly, polynomial.map_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 G F) F ≤ fintype.card G :=
begin
refine dim_le (λ s hs, cardinal.nat_cast_le.1 _),
rw [← @dim_fun' F G, ← cardinal.lift_nat_cast.{v (max u v)},
cardinal.finset_card, ← cardinal.lift_id (module.rank F (G → F))],
exact linear_independent_le_dim'.{_ _ _ (max u v)}
(linear_independent_smul_of_linear_independent G F hs)
end
instance : finite_dimensional (fixed_points G F) F :=
finite_dimensional.finite_dimensional_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 G F) F ≤ fintype.card G :=
by exact_mod_cast trans_rel_right (≤) (finrank_eq_dim _ _) (dim_le_card G F)
end fixed_points
lemma linear_independent_to_linear_map (R : Type u) (A : Type v) (B : Type w)
[comm_semiring R] [integral_domain A] [algebra R A] [integral_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
/-- Embedding produced from a faithful action. -/
@[simps apply {fully_applied := ff}]
def to_alg_hom (G : Type u) (F : Type v) [group G] [field F]
[faithful_mul_semiring_action G F] : G ↪ (F →ₐ[fixed_points G F] F) :=
{ to_fun := λ g, { commutes' := λ x, x.2 g,
.. mul_semiring_action.to_semiring_hom G F g },
inj' := λ g₁ g₂ hg, to_semiring_hom_injective G F $ ring_hom.ext $ λ x, alg_hom.ext_iff.1 hg x, }
lemma to_alg_hom_apply_apply {G : Type u} {F : Type v} [group G] [field F]
[faithful_mul_semiring_action G F] (g : G) (x : F) :
to_alg_hom G F g x = g • x :=
rfl
theorem finrank_eq_card (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [faithful_mul_semiring_action G F] :
finrank (fixed_points G F) F = fintype.card G :=
le_antisymm (fixed_points.finrank_le_card G F) $
calc fintype.card G
≤ fintype.card (F →ₐ[fixed_points G F] F) : fintype.card_le_of_injective _ (to_alg_hom G F).2
... ≤ finrank F (F →ₗ[fixed_points G F] F) : finrank_alg_hom (fixed_points G F) F
... = finrank (fixed_points G F) F : finrank_linear_map' _ _ _
theorem to_alg_hom_bijective (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [faithful_mul_semiring_action G F] :
function.bijective (to_alg_hom G F) :=
begin
rw fintype.bijective_iff_injective_and_card,
split,
{ exact (to_alg_hom G F).injective },
{ apply le_antisymm,
{ exact fintype.card_le_of_injective _ (to_alg_hom G F).injective },
{ 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] [faithful_mul_semiring_action G F] : G ≃ (F →ₐ[fixed_points G F] F) :=
function.embedding.equiv_of_surjective (to_alg_hom G F) (to_alg_hom_bijective G F).2
end fixed_points
|
00cbdf59e9b3a74e848161cf5ccaf074848deb16 | 618003631150032a5676f229d13a079ac875ff77 | /src/algebra/homology/chain_complex.lean | c8ae06a1a433e503af4da51a41630e37d8cbccf3 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 4,471 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.graded_object
import category_theory.differential_object
/-!
# Chain complexes
We define a chain complex in `V` as a differential `ℤ`-graded object in `V`.
This is fancy language for the obvious definition,
and it seems we can use it straightforwardly:
```
example (C : chain_complex V) : C.X 5 ⟶ C.X 6 := C.d 5
```
We define the forgetful functor to `ℤ`-graded objects, and show that
`chain_complex V` is concrete when `V` is, and `V` has coproducts.
-/
universes v u
open category_theory
open category_theory.limits
section
variables (V : Type u) [𝒱 : category.{v} V]
include 𝒱
variables [has_zero_morphisms.{v} V]
/--
A chain complex in `V` is "just" a differential `ℤ`-graded object in `V`,
with differential graded `-1`.
-/
abbreviation chain_complex : Type (max v u) :=
differential_object.{v} (graded_object_with_shift (-1 : ℤ) V)
/--
A cochain complex in `V` is "just" a differential `ℤ`-graded object in `V`,
with differential graded `+1`.
-/
abbreviation cochain_complex : Type (max v u) :=
differential_object.{v} (graded_object_with_shift (1 : ℤ) V)
-- The chain groups of a chain complex `C` are accessed as `C.X i`,
-- and the differentials as `C.d i : C.X i ⟶ C.X (i-1)`.
example (C : chain_complex V) : C.X 5 ⟶ C.X 4 := C.d 5
end
namespace cochain_complex
variables {V : Type u} [𝒱 : category.{v} V]
include 𝒱
variables [has_zero_morphisms.{v} V]
@[simp]
lemma d_squared (C : cochain_complex.{v} V) (i : ℤ) :
C.d i ≫ C.d (i+1) = 0 :=
congr_fun (C.d_squared) i
/--
A convenience lemma for morphisms of cochain complexes,
picking out one component of the commutation relation.
-/
-- I haven't been able to get this to work with projection notation: `f.comm_at i`
@[simp]
lemma comm_at {C D : cochain_complex V} (f : C ⟶ D) (i : ℤ) :
C.d i ≫ f.f (i+1) = f.f i ≫ D.d i :=
congr_fun f.comm i
@[simp]
lemma comm {C D : cochain_complex V} (f : C ⟶ D) : C.d ≫ f.f⟦1⟧' = f.f ≫ D.d := differential_object.hom.comm _
-- The components of a cochain map `f : C ⟶ D` are accessed as `f.f i`.
example {C D : cochain_complex V} (f : C ⟶ D) : C.X 5 ⟶ D.X 5 := f.f 5
example {C D : cochain_complex V} (f : C ⟶ D) : C.d ≫ f.f⟦1⟧' = f.f ≫ D.d := by simp
example {C D : cochain_complex V} (f : C ⟶ D) : C.d 5 ≫ f.f 6 = f.f 5 ≫ D.d 5 := comm_at f 5
variables (V)
/-- The forgetful functor from cochain complexes to graded objects, forgetting the differential. -/
abbreviation forget : (cochain_complex V) ⥤ (graded_object ℤ V) :=
differential_object.forget _
section
omit 𝒱
local attribute [instance] has_zero_object.has_zero
instance : inhabited (cochain_complex.{v} punit.{v+1}) := ⟨0⟩
end
end cochain_complex
namespace chain_complex
variables {V : Type u} [𝒱 : category.{v} V]
include 𝒱
variables [has_zero_morphisms.{v} V]
@[simp]
lemma d_squared (C : chain_complex.{v} V) (i : ℤ) :
C.d i ≫ C.d (i-1) = 0 :=
congr_fun (C.d_squared) i
/--
A convenience lemma for morphisms of chain complexes,
picking out one component of the commutation relation.
-/
@[simp]
lemma comm_at {C D : chain_complex V} (f : C ⟶ D) (i : ℤ) :
C.d i ≫ f.f (i-1) = f.f i ≫ D.d i :=
congr_fun f.comm i
@[simp]
lemma comm {C D : chain_complex V} (f : C ⟶ D) : C.d ≫ f.f⟦1⟧' = f.f ≫ D.d := differential_object.hom.comm _
variables (V)
/-- The forgetful functor from chain complexes to graded objects, forgetting the differential. -/
abbreviation forget : (chain_complex V) ⥤ (graded_object ℤ V) :=
differential_object.forget _
section
omit 𝒱
local attribute [instance] has_zero_object.has_zero
instance : inhabited (chain_complex.{v} punit.{v+1}) := ⟨0⟩
end
end chain_complex
-- TODO when V is enriched in W, what do we need to ensure
-- `chain_complex V` is also enriched in W?
-- TODO `chain_complex V` is a module category for `V` when `V` is monoidal
-- TODO When V is enriched in AddCommGroup, and has coproducts,
-- we can collapse a double complex to obtain a complex.
-- If the double complex is supported in a quadrant, we only need finite coproducts.
-- TODO when V is monoidal, enriched in `AddCommGroup`,
-- and has coproducts then
-- `chain_complex V` is monoidal too.
-- If the complexes are bounded below we only need finite coproducts.
|
6a4f046f1180b60fa5652c5b311e31691f2bcf59 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /tests/lean/run/match1.lean | 6c58bc9246aa91b8a737e0fa6a30dbeeb8bd78e2 | [
"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 | 4,884 | lean | import Lean
def checkWithMkMatcherInput (matcher : Lean.Name) : Lean.MetaM Unit :=
Lean.Meta.Match.withMkMatcherInput matcher fun input => do
let res ← Lean.Meta.Match.mkMatcher input
let origMatcher ← Lean.getConstInfo matcher
if not <| input.matcherName == matcher then
throwError "matcher name not reconstructed correctly: {matcher} ≟ {input.matcherName}"
let lCtx ← Lean.getLCtx
let fvars := Lean.collectFVars {} res.matcher
let closure := Lean.Meta.Closure.mkLambda (fvars.fvarSet.toList.toArray.map lCtx.get!) res.matcher
let origTy := origMatcher.value!
let newTy := closure
if not <| ←Lean.Meta.isDefEq origTy newTy then
throwError "matcher {matcher} does not round-trip correctly:\n{origTy} ≟ {newTy}"
set_option smartUnfolding false
def f (xs : List Nat) : List Bool :=
xs.map fun
| 0 => true
| _ => false
#eval checkWithMkMatcherInput ``f.match_1
#eval f [1, 2, 0, 2]
theorem ex1 : f [1, 0, 2] = [false, true, false] :=
rfl
#check f
set_option pp.raw true
set_option pp.raw.maxDepth 10
set_option trace.Elab.step true in
def g (xs : List Nat) : List Bool :=
xs.map <| by {
intro
| 0 => exact true
| _ => exact false
}
theorem ex2 : g [1, 0, 2] = [false, true, false] :=
rfl
theorem ex3 {p q r : Prop} : p ∨ q → r → (q ∧ r) ∨ (p ∧ r) :=
by intro
| Or.inl hp, h => { apply Or.inr; apply And.intro; assumption; assumption }
| Or.inr hq, h => { apply Or.inl; exact ⟨hq, h⟩ }
#eval checkWithMkMatcherInput ``ex3.match_1
inductive C
| mk₁ : Nat → C
| mk₂ : Nat → Nat → C
def C.x : C → Nat
| C.mk₁ x => x
| C.mk₂ x _ => x
#eval checkWithMkMatcherInput ``C.x.match_1
def head : {α : Type} → List α → Option α
| _, a::as => some a
| _, _ => none
#eval checkWithMkMatcherInput ``head.match_1
theorem ex4 : head [1, 2] = some 1 :=
rfl
def head2 : {α : Type} → List α → Option α :=
@fun
| _, a::as => some a
| _, _ => none
theorem ex5 : head2 [1, 2] = some 1 :=
rfl
def head3 {α : Type} (xs : List α) : Option α :=
let rec aux {α : Type} : List α → Option α
| a::_ => some a
| _ => none;
aux xs
theorem ex6 : head3 [1, 2] = some 1 :=
rfl
inductive Vec.{u} (α : Type u) : Nat → Type u
| nil : Vec α 0
| cons {n} (head : α) (tail : Vec α n) : Vec α (n+1)
def Vec.mapHead1 {α β δ} : {n : Nat} → Vec α n → Vec β n → (α → β → δ) → Option δ
| _, nil, nil, f => none
| _, cons a as, cons b bs, f => some (f a b)
#eval checkWithMkMatcherInput ``Vec.mapHead1.match_1
def Vec.mapHead2 {α β δ} : {n : Nat} → Vec α n → Vec β n → (α → β → δ) → Option δ
| _, nil, nil, f => none
| _, @cons _ n a as, cons b bs, f => some (f a b)
set_option pp.match false in
#print Vec.mapHead2 -- reused Vec.mapHead1.match_1
def Vec.mapHead3 {α β δ} : {n : Nat} → Vec α n → Vec β n → (α → β → δ) → Option δ
| _, nil, nil, f => none
| _, cons (tail := as) (head := a), cons b bs, f => some (f a b)
inductive Foo
| mk₁ (x y z w : Nat)
| mk₂ (x y z w : Nat)
def Foo.z : Foo → Nat
| mk₁ (z := z) .. => z
| mk₂ (z := z) .. => z
#eval checkWithMkMatcherInput ``Foo.z.match_1
#eval (Foo.mk₁ 10 20 30 40).z
theorem ex7 : (Foo.mk₁ 10 20 30 40).z = 30 :=
rfl
def Foo.addY? : Foo × Foo → Option Nat
| (mk₁ (y := y₁) .., mk₁ (y := y₂) ..) => some (y₁ + y₂)
| _ => none
#eval checkWithMkMatcherInput ``Foo.addY?.match_1
#eval Foo.addY? (Foo.mk₁ 1 2 3 4, Foo.mk₁ 10 20 30 40)
theorem ex8 : Foo.addY? (Foo.mk₁ 1 2 3 4, Foo.mk₁ 10 20 30 40) = some 22 :=
rfl
instance {α} : Inhabited (Sigma fun m => Vec α m) :=
⟨⟨0, Vec.nil⟩⟩
partial def filter {α} (p : α → Bool) : {n : Nat} → Vec α n → Sigma fun m => Vec α m
| _, Vec.nil => ⟨0, Vec.nil⟩
| _, Vec.cons x xs => match p x, filter p xs with
| true, ⟨_, ys⟩ => ⟨_, Vec.cons x ys⟩
| false, ys => ys
#eval checkWithMkMatcherInput ``filter.match_1
inductive Bla
| ofNat (x : Nat)
| ofBool (x : Bool)
def Bla.optional? : Bla → Option Nat
| ofNat x => some x
| ofBool _ => none
#eval checkWithMkMatcherInput ``Bla.optional?.match_1
def Bla.isNat? (b : Bla) : Option { x : Nat // optional? b = some x } :=
match b.optional? with
| some y => some ⟨y, rfl⟩
| none => none
#eval checkWithMkMatcherInput ``Bla.isNat?.match_1
def foo (b : Bla) : Option Nat := b.optional?
theorem fooEq (b : Bla) : foo b = b.optional? :=
rfl
def Bla.isNat2? (b : Bla) : Option { x : Nat // optional? b = some x } :=
match h : foo b with
| some y => some ⟨y, Eq.trans (fooEq b).symm h⟩
| none => none
#eval checkWithMkMatcherInput ``Bla.isNat2?.match_1
def foo2 (x : Nat) : Nat :=
match (motive := (y : Nat) → x = y → Nat) x, rfl with
| 0, h => 0
| x+1, h => 1
#eval checkWithMkMatcherInput ``foo2.match_1
|
2c1f15aad5203a0976b2c8a3381acf1dc390b1e5 | aa101d73b1a3173c7ec56de02b96baa8ca64c42e | /src/solutions/09_limits_final.lean | c3a4ca778b8f8235a305a693c029fe075ac10694 | [
"Apache-2.0"
] | permissive | gihanmarasingha/tutorials | b554d4d53866c493c4341dc13e914b01444e95a6 | 56617114ef0f9f7b808476faffd11e22e4380918 | refs/heads/master | 1,671,141,758,153 | 1,599,173,318,000 | 1,599,173,318,000 | 282,405,870 | 0 | 0 | Apache-2.0 | 1,595,666,751,000 | 1,595,666,750,000 | null | UTF-8 | Lean | false | false | 12,787 | lean | import tuto_lib
set_option pp.beta true
set_option pp.coercions false
/-
This is the final file in the series. Here we use everything covered
in previous files to prove a couple of famous theorems from
elementary real analysis. Of course they all have more general versions
in mathlib.
As usual, keep in mind the following:
abs_le (x y : ℝ) : |x| ≤ y ↔ -y ≤ x ∧ x ≤ y
ge_max_iff (p q r) : r ≥ max p q ↔ r ≥ p ∧ r ≥ q
le_max_left p q : p ≤ max p q
le_max_right p q : q ≤ max p q
as well as a lemma from the previous file:
le_of_le_add_all : (∀ ε > 0, y ≤ x + ε) → y ≤ x
Let's start with a variation on a known exercise.
-/
-- 0071
lemma le_lim {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)
(ineg : ∃ N, ∀ n ≥ N, y ≤ u n) : y ≤ x :=
begin
-- sorry
apply le_of_le_add_all,
intros ε ε_pos,
cases hu ε ε_pos with N hN,
cases ineg with N' hN',
let N₀ := max N N',
specialize hN N₀ (le_max_left N N'),
specialize hN' N₀ (le_max_right N N'),
rw abs_le at hN,
linarith,
-- sorry
end
/-
Let's now return to the result proved in the `00_` file of this series,
and prove again the sequential characterization of upper bounds (with a slighly
different proof).
For this, and other exercises below, we'll need many things that we proved in previous files,
and a couple of extras.
From the 5th file:
limit_const (x : ℝ) : seq_limit (λ n, x) x
squeeze (lim_u : seq_limit u l) (lim_w : seq_limit w l)
(hu : ∀ n, u n ≤ v n) (hw : ∀ n, v n ≤ w n) : seq_limit v l
From the 8th:
def upper_bound (A : set ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x
def is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ y
lt_sup (hx : is_sup A x) : ∀ y, y < x → ∃ a ∈ A, y < a :=
You can also use:
nat.one_div_pos_of_nat {n : ℕ} : 0 < 1 / (n + 1 : ℝ)
inv_succ_le_all : ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε
and their easy consequences:
limit_of_sub_le_inv_succ (h : ∀ n, |u n - x| ≤ 1/(n+1)) : seq_limit u x
limit_const_add_inv_succ (x : ℝ) : seq_limit (λ n, x + 1/(n+1)) x
limit_const_sub_inv_succ (x : ℝ) : seq_limit (λ n, x - 1/(n+1)) x
The structure of the proof is offered. It features a new tactic:
`choose` which invokes the axiom of choice (observing the tactic state before and
after using it should be enough to understand everything).
-/
-- 0072
lemma is_sup_iff (A : set ℝ) (x : ℝ) :
(is_sup A x) ↔ (upper_bound A x ∧ ∃ u : ℕ → ℝ, seq_limit u x ∧ ∀ n, u n ∈ A ) :=
begin
split,
{ intro h,
split,
{
-- sorry
exact h.left,
-- sorry
},
{ have : ∀ n : ℕ, ∃ a ∈ A, x - 1/(n+1) < a,
{ intros n,
have : 1/(n+1 : ℝ) > 0,
exact nat.one_div_pos_of_nat,
-- sorry
exact lt_sup h _ (by linarith),
-- sorry
},
choose u hu using this,
-- sorry
use u,
split,
{ apply squeeze (limit_const_sub_inv_succ x) (limit_const x),
{ intros n,
exact le_of_lt (hu n).2, },
{ intro n,
exact h.1 _ (hu n).left, } },
{ intro n,
exact (hu n).left },
-- sorry
} },
{ rintro ⟨maj, u, limu, u_in⟩,
-- sorry
split,
{ exact maj },
{ intros y ymaj,
apply lim_le limu,
intro n,
apply ymaj,
apply u_in },
-- sorry
},
end
/-- Continuity of a function at a point -/
def continuous_at_pt (f : ℝ → ℝ) (x₀ : ℝ) : Prop :=
∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - f x₀| ≤ ε
variables {f : ℝ → ℝ} {x₀ : ℝ} {u : ℕ → ℝ}
-- 0073
lemma seq_continuous_of_continuous (hf : continuous_at_pt f x₀)
(hu : seq_limit u x₀) : seq_limit (f ∘ u) (f x₀) :=
begin
-- sorry
intros ε ε_pos,
rcases hf ε ε_pos with ⟨δ, δ_pos, hδ⟩,
cases hu δ δ_pos with N hN,
use N,
intros n hn,
apply hδ,
exact hN n hn,
-- sorry
end
-- 0074
example :
(∀ u : ℕ → ℝ, seq_limit u x₀ → seq_limit (f ∘ u) (f x₀)) →
continuous_at_pt f x₀ :=
begin
-- sorry
contrapose!,
intro hf,
unfold continuous_at_pt at hf,
push_neg at hf,
cases hf with ε h,
cases h with ε_pos hf,
have H : ∀ n : ℕ, ∃ x, |x - x₀| ≤ 1/(n+1) ∧ ε < |f x - f x₀|,
intro n,
apply hf,
exact nat.one_div_pos_of_nat,
clear hf,
choose u hu using H,
use u,
split,
intros η η_pos,
have fait : ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → 1 / (↑n + 1) ≤ η,
exact inv_succ_le_all η η_pos,
cases fait with N hN,
use N,
intros n hn,
calc |u n - x₀| ≤ 1/(n+1) : (hu n).left
... ≤ η : hN n hn,
unfold seq_limit,
push_neg,
use [ε, ε_pos],
intro N,
use N,
split,
linarith,
exact (hu N).right,
-- sorry
end
/-
Recall from the 6th file:
def extraction (φ : ℕ → ℕ) := ∀ n m, n < m → φ n < φ m
def cluster_point (u : ℕ → ℝ) (a : ℝ) :=
∃ φ, extraction φ ∧ seq_limit (u ∘ φ) a
id_le_extraction : extraction φ → ∀ n, n ≤ φ n
and from the 8th file:
def tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A
not_seq_limit_of_tendstoinfinity : tendsto_infinity u → ∀ l, ¬ seq_limit u l
-/
variables {φ : ℕ → ℕ}
-- 0075
lemma subseq_tenstoinfinity
(h : tendsto_infinity u) (hφ : extraction φ) :
tendsto_infinity (u ∘ φ) :=
begin
-- sorry
intros A,
cases h A with N hN,
use N,
intros n hn,
apply hN,
calc N ≤ n : hn
... ≤ φ n : id_le_extraction hφ n,
-- sorry
end
-- 0076
lemma squeeze_infinity {u v : ℕ → ℝ} (hu : tendsto_infinity u)
(huv : ∀ n, u n ≤ v n) : tendsto_infinity v :=
begin
-- sorry
intros A,
cases hu A with N hN,
use N,
intros n hn,
specialize hN n hn,
specialize huv n,
linarith,
-- sorry
end
/-
We will use segments: Icc a b := { x | a ≤ x ∧ x ≤ b }
The notation stands for Interval-closed-closed. Variations exist with
o or i instead of c, where o stands for open and i for infinity.
We will use the following version of Bolzano-Weirstrass
bolzano_weierstrass (h : ∀ n, u n ∈ [a, b]) :
∃ c ∈ [a, b], cluster_point u c
as well as the obvious
seq_limit_id : tendsto_infinity (λ n, n)
-/
open set
-- 0077
lemma bdd_above_segment {f : ℝ → ℝ} {a b : ℝ} (hf : ∀ x ∈ Icc a b, continuous_at_pt f x) :
∃ M, ∀ x ∈ Icc a b, f x ≤ M :=
begin
-- sorry
by_contradiction H,
push_neg at H,
have clef : ∀ n : ℕ, ∃ x, x ∈ Icc a b ∧ f x > n,
intro n, apply H, clear H,
choose u hu using clef,
have lim_infinie : tendsto_infinity (f ∘ u),
apply squeeze_infinity (seq_limit_id),
intros n,
specialize hu n,
linarith,
have bornes : ∀ n, u n ∈ Icc a b,
intro n, exact (hu n).left,
rcases bolzano_weierstrass bornes with ⟨c, c_dans, φ, φ_extr, lim⟩,
have lim_infinie_extr : tendsto_infinity (f ∘ (u ∘ φ)),
exact subseq_tenstoinfinity lim_infinie φ_extr,
have lim_extr : seq_limit (f ∘ (u ∘ φ)) (f c),
exact seq_continuous_of_continuous (hf c c_dans) lim,
exact not_seq_limit_of_tendstoinfinity lim_infinie_extr (f c) lim_extr,
-- sorry
end
/-
In the next exercise, we can use:
abs_neg x : |-x| = |x|
-/
-- 0078
lemma continuous_opposite {f : ℝ → ℝ} {x₀ : ℝ} (h : continuous_at_pt f x₀) :
continuous_at_pt (λ x, -f x) x₀ :=
begin
-- sorry
intros ε ε_pos,
cases h ε ε_pos with δ h,
cases h with δ_pos h,
use [δ, δ_pos],
intros y hy,
have : -f y - -f x₀ = -(f y - f x₀), ring,
rw [this, abs_neg],
exact h y hy,
-- sorry
end
/-
Now let's combine the two exercises above
-/
-- 0079
lemma bdd_below_segment {f : ℝ → ℝ} {a b : ℝ} (hf : ∀ x ∈ Icc a b, continuous_at_pt f x) :
∃ m, ∀ x ∈ Icc a b, m ≤ f x :=
begin
-- sorry
have : ∃ M, ∀ x ∈ Icc a b, -f x ≤ M,
{ apply bdd_above_segment,
intros x x_dans,
exact continuous_opposite (hf x x_dans), },
cases this with M hM,
use -M,
intros x x_dans,
specialize hM x x_dans,
linarith,
-- sorry
end
/-
Remember from the 5th file:
unique_limit : seq_limit u l → seq_limit u l' → l = l'
and from the 6th one:
subseq_tendsto_of_tendsto (h : seq_limit u l) (hφ : extraction φ) :
seq_limit (u ∘ φ) l
We now admit the following version of the least upper bound theorem
(that cannot be proved without discussing the construction of real numbers
or admitting another strong theorem).
sup_segment {a b : ℝ} {A : set ℝ} (hnonvide : ∃ x, x ∈ A) (h : A ⊆ Icc a b) :
∃ x ∈ Icc a b, is_sup A x
In the next exercise, it can be useful to prove inclusions of sets of real number.
By definition, A ⊆ B means : ∀ x, x ∈ A → x ∈ B.
Hence one can start a proof of A ⊆ B by `intros x x_in`,
which brings `x : ℝ` and `x_in : x ∈ A` in the local context,
and then prove `x ∈ B`.
Note also the use of
{x | P x}
which denotes the set of x satisfying predicate P.
Hence `x' ∈ { x | P x} ↔ P x'`, by definition.
-/
-- 0080
example {a b : ℝ} (hab : a ≤ b) (hf : ∀ x ∈ Icc a b, continuous_at_pt f x) :
∃ x₀ ∈ Icc a b, ∀ x ∈ Icc a b, f x ≤ f x₀ :=
begin
-- sorry
cases bdd_below_segment hf with m hm,
cases bdd_above_segment hf with M hM,
let A := {y | ∃ x ∈ Icc a b, y = f x},
obtain ⟨y₀, y_dans, y_sup⟩ : ∃ y₀ ∈ Icc m M, is_sup A y₀,
{ apply sup_segment,
{ use [f a, a, by linarith, hab, by ring], },
{ rintros y ⟨x, x_in, rfl⟩,
exact ⟨hm x x_in, hM x x_in⟩ } },
rw is_sup_iff at y_sup,
rcases y_sup with ⟨y_maj, u, lim_u, u_dans⟩,
choose v hv using u_dans,
cases forall_and_distrib.mp hv with v_dans hufv,
replace hufv : u = f ∘ v := funext hufv,
rcases bolzano_weierstrass v_dans with ⟨x₀, x₀_in, φ, φ_extr, lim_vφ⟩,
use [x₀, x₀_in],
intros x x_dans,
have lim : seq_limit (f ∘ v ∘ φ) (f x₀),
{ apply seq_continuous_of_continuous,
exact hf x₀ x₀_in,
exact lim_vφ },
have unique : f x₀ = y₀,
{ apply unique_limit lim,
rw hufv at lim_u,
exact subseq_tendsto_of_tendsto lim_u φ_extr },
rw unique,
apply y_maj,
use [x, x_dans],
-- sorry
end
lemma stupid {a b x : ℝ} (h : x ∈ Icc a b) (h' : x ≠ b) : x < b :=
lt_of_le_of_ne h.right h'
/-
And now the final boss...
-/
def I := (Icc 0 1 : set ℝ) -- the type ascription makes sure 0 and 1 are real numbers here
-- 0081
example (f : ℝ → ℝ) (hf : ∀ x, continuous_at_pt f x) (h₀ : f 0 < 0) (h₁ : f 1 > 0) :
∃ x₀ ∈ I, f x₀ = 0 :=
begin
let A := { x | x ∈ I ∧ f x < 0},
have ex_x₀ : ∃ x₀ ∈ I, is_sup A x₀,
{
-- sorry
apply sup_segment,
use 0,
split,
split, linarith, linarith,
exact h₀,
intros x hx,
exact hx.left
-- sorry
},
rcases ex_x₀ with ⟨x₀, x₀_in, x₀_sup⟩,
use [x₀, x₀_in],
have : f x₀ ≤ 0,
{
-- sorry
rw is_sup_iff at x₀_sup,
rcases x₀_sup with ⟨maj_x₀, u, lim_u, u_dans⟩,
have : seq_limit (f ∘ u) (f x₀),
exact seq_continuous_of_continuous (hf x₀) lim_u,
apply lim_le this,
intros n,
have : f (u n) < 0,
exact (u_dans n).right,
linarith
-- sorry
},
have x₀_1: x₀ < 1,
{
-- sorry
apply stupid x₀_in,
intro h,
rw ← h at h₁,
linarith
-- sorry
},
have : f x₀ ≥ 0,
{ have in_I : ∃ N : ℕ, ∀ n ≥ N, x₀ + 1/(n+1) ∈ I,
{ have : ∃ N : ℕ, ∀ n≥ N, 1/(n+1 : ℝ) ≤ 1-x₀,
{
-- sorry
apply inv_succ_le_all,
linarith,
-- sorry
},
-- sorry
cases this with N hN,
use N,
intros n hn,
specialize hN n hn,
have : 1/(n+1 : ℝ) > 0,
exact nat.one_div_pos_of_nat,
change 0 ≤ x₀ ∧ x₀ ≤ 1 at x₀_in,
split ; linarith,
-- sorry
},
have not_in : ∀ n : ℕ, x₀ + 1/(n+1) ∉ A,
-- By definition, x ∉ A means ¬ (x ∈ A).
{
-- sorry
intros n hn,
cases x₀_sup with x₀_maj _,
specialize x₀_maj _ hn,
have : 1/(n+1 : ℝ) > 0,
from nat.one_div_pos_of_nat,
linarith,
-- sorry
},
dsimp [A] at not_in, -- This is useful to unfold a let
-- sorry
push_neg at not_in,
have lim : seq_limit (λ n, f(x₀ + 1/(n+1))) (f x₀),
{ apply seq_continuous_of_continuous (hf x₀),
apply limit_const_add_inv_succ },
apply le_lim lim,
cases in_I with N hN,
use N,
intros n hn,
exact not_in n (hN n hn),
-- sorry
},
linarith,
end
|
560917881e7f2f91b72cd15a2f285db55f6a0408 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/blast_ematch_cast1.lean | 83c02c38148ba0e1bc68871d40b826fb249fb227 | [
"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 | 266 | lean | import data.nat
open nat
constant C : nat → Type₁
constant f : ∀ n, C n → C n
lemma fax [forward] (n : nat) (a : C (2*n)) : (: f (2*n) a :) = a :=
sorry
set_option blast.strategy "ematch"
example (n m : nat) (a : C n) : n = 2*m → f n a = a :=
by blast
|
8754740c3377650a49b02be1e4035544dac77727 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/ring_theory/principal_ideal_domain.lean | c0603f90d6d8f26527a16d5065787b3183d295de | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 16,431 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Morenikeji Neri
-/
import ring_theory.unique_factorization_domain
/-!
# Principal ideal rings and principal ideal domains
A principal ideal ring (PIR) is a ring in which all left 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
`[is_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 rings, saying that every left ideal is principal.
- `generator`: a generator of a principal ideal (or more generally submodule)
- `to_unique_factorization_monoid`: a PID is a unique factorization domain
# 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
section
variables [ring R] [add_comm_group M] [module R M]
/-- An `R`-submodule of `M` is principal if it is generated by one element. -/
@[mk_iff]
class submodule.is_principal (S : submodule R M) : Prop :=
(principal [] : ∃ a, S = span R {a})
instance bot_is_principal : (⊥ : submodule R M).is_principal :=
⟨⟨0, by simp⟩⟩
instance top_is_principal : (⊤ : submodule R R).is_principal :=
⟨⟨1, ideal.span_singleton_one.symm⟩⟩
variables (R)
/-- A ring is a principal ideal ring if all (left) ideals are principal. -/
class is_principal_ideal_ring (R : Type u) [ring R] : Prop :=
(principal : ∀ (S : ideal R), S.is_principal)
attribute [instance] is_principal_ideal_ring.principal
@[priority 100]
instance division_ring.is_principal_ideal_ring (K : Type u) [division_ring K] :
is_principal_ideal_ring K :=
{ principal := λ S, by rcases ideal.eq_bot_or_top S with (rfl|rfl); apply_instance }
end
namespace submodule.is_principal
variables [add_comm_group M]
section ring
variables [ring R] [module R M]
/-- `generator I`, if `I` is a principal submodule, is an `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))
lemma _root_.ideal.span_singleton_generator (I : ideal R) [I.is_principal] :
ideal.span ({generator I} : set R) = I :=
eq.symm (classical.some_spec (principal I))
@[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 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 ring
section comm_ring
variables [comm_ring R] [module R M]
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 prime_generator_of_is_prime (S : ideal R) [submodule.is_principal S] [is_prime : S.is_prime]
(ne_bot : S ≠ ⊥) :
prime (generator S) :=
⟨λ h, ne_bot ((eq_bot_iff_generator_eq_zero S).2 h),
λ h, is_prime.ne_top (S.eq_top_of_is_unit_mem (generator_mem S) h),
λ _ _, by simpa only [← mem_iff_generator_dvd S] using is_prime.2⟩
-- Note that the converse may not hold if `ϕ` is not injective.
lemma generator_map_dvd_of_mem {N : submodule R M}
(ϕ : M →ₗ[R] R) [(N.map ϕ).is_principal] {x : M} (hx : x ∈ N) :
generator (N.map ϕ) ∣ ϕ x :=
by { rw [← mem_iff_generator_dvd, submodule.mem_map], exact ⟨x, hx, rfl⟩ }
-- Note that the converse may not hold if `ϕ` is not injective.
lemma generator_submodule_image_dvd_of_mem {N O : submodule R M} (hNO : N ≤ O)
(ϕ : O →ₗ[R] R) [(ϕ.submodule_image N).is_principal] {x : M} (hx : x ∈ N) :
generator (ϕ.submodule_image N) ∣ ϕ ⟨x, hNO hx⟩ :=
by { rw [← mem_iff_generator_dvd, linear_map.mem_submodule_image_of_le hNO], exact ⟨x, hx, rfl⟩ }
end comm_ring
end submodule.is_principal
namespace is_prime
open submodule.is_principal ideal
-- TODO -- for a non-ID one could perhaps prove that if p < q are prime then q maximal;
-- 0 isn't prime in a non-ID PIR but the Krull dimension is still <= 1.
-- The below result follows from this, but we could also use the below result to
-- prove this (quotient out by p).
lemma to_maximal_ideal [comm_ring R] [is_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.mem_or_mem (show generator T * z ∈ S, from hz ▸ generator_mem S),
{ have hTS : T ≤ S, rwa [← T.span_singleton_generator, ideal.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, mul_right_inj' this] at hz,
exact hz.symm ▸ T.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 ▸ S.add_mem (S.mul_mem_right _ hy) hxy,
λ hx, (mod_eq_sub_mul_div x y).symm ▸ S.sub_mem hx (S.mul_mem_right _ 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 { simp only [not_and_distrib, set.mem_set_of_eq, not_ne_iff] at this,
cases this, cases this ((mod_mem_iff hmin.1).2 hx), exact this },
by simp *),
λ hx, let ⟨y, hy⟩ := ideal.mem_span_singleton.1 hx in hy.symm ▸ S.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
lemma is_field.is_principal_ideal_ring
{R : Type*} [comm_ring R] (h : is_field R) :
is_principal_ideal_ring R :=
@euclidean_domain.to_principal_ideal_domain R (@field.to_euclidean_domain R h.to_field)
namespace principal_ideal_ring
open is_principal_ideal_ring
@[priority 100] -- see Note [lower instance priority]
instance is_noetherian_ring [ring R] [is_principal_ideal_ring R] :
is_noetherian_ring R :=
is_noetherian_ring_iff.2 ⟨assume s : ideal R,
begin
rcases (is_principal_ideal_ring.principal s).principal with ⟨a, rfl⟩,
rw [← finset.coe_singleton],
exact ⟨{a}, set_like.coe_injective rfl⟩
end⟩
lemma is_maximal_of_irreducible [comm_ring R] [is_principal_ideal_ring R]
{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, is_unit.mul_right_dvd hb]
end⟩⟩
variables [comm_ring R] [is_domain R] [is_principal_ideal_ring R]
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,
prime.irreducible⟩
lemma associates_irreducible_iff_prime : ∀{p : associates R}, irreducible p ↔ prime p :=
associates.irreducible_iff_prime_iff.1 (λ _, 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 (wf_dvd_monoid.exists_factors a h)
lemma factors_spec (a : R) (h : a ≠ 0) :
(∀b∈factors a, irreducible b) ∧ associated (factors a).prod a :=
begin
unfold factors, rw [dif_neg h],
exact classical.some_spec (wf_dvd_monoid.exists_factors a h)
end
lemma ne_zero_of_mem_factors
{R : Type v} [comm_ring R] [is_domain R] [is_principal_ideal_ring R] {a b : R}
(ha : a ≠ 0) (hb : b ∈ factors a) : b ≠ 0 := irreducible.ne_zero ((factors_spec a ha).1 b hb)
lemma mem_submonoid_of_factors_subset_of_units_subset (s : submonoid R)
{a : R} (ha : a ≠ 0) (hfac : ∀ b ∈ factors a, b ∈ s) (hunit : ∀ c : Rˣ, (c : R) ∈ s) :
a ∈ s :=
begin
rcases ((factors_spec a ha).2) with ⟨c, hc⟩,
rw [← hc],
exact mul_mem (multiset_prod_mem _ hfac) (hunit _)
end
/-- If a `ring_hom` maps all units and all factors of an element `a` into a submonoid `s`, then it
also maps `a` into that submonoid. -/
lemma ring_hom_mem_submonoid_of_factors_subset_of_units_subset {R S : Type*}
[comm_ring R] [is_domain R] [is_principal_ideal_ring R] [semiring S]
(f : R →+* S) (s : submonoid S) (a : R) (ha : a ≠ 0)
(h : ∀ b ∈ factors a, f b ∈ s) (hf: ∀ c : Rˣ, f c ∈ s) :
f a ∈ s :=
mem_submonoid_of_factors_subset_of_units_subset (s.comap f.to_monoid_hom) ha h hf
/-- A principal ideal domain has unique factorization -/
@[priority 100] -- see Note [lower instance priority]
instance to_unique_factorization_monoid : unique_factorization_monoid R :=
{ irreducible_iff_prime := λ _, principal_ideal_ring.irreducible_iff_prime
.. (is_noetherian_ring.wf_dvd_monoid : wf_dvd_monoid R) }
end
end principal_ideal_ring
section surjective
open submodule
variables {S N : Type*} [ring R] [add_comm_group M] [add_comm_group N] [ring S]
variables [module R M] [module R N]
lemma submodule.is_principal.of_comap (f : M →ₗ[R] N) (hf : function.surjective f)
(S : submodule R N) [hI : is_principal (S.comap f)] :
is_principal S :=
⟨⟨f (is_principal.generator (S.comap f)),
by rw [← set.image_singleton, ← submodule.map_span,
is_principal.span_singleton_generator, submodule.map_comap_eq_of_surjective hf]⟩⟩
lemma ideal.is_principal.of_comap (f : R →+* S) (hf : function.surjective f)
(I : ideal S) [hI : is_principal (I.comap f)] :
is_principal I :=
⟨⟨f (is_principal.generator (I.comap f)),
by rw [ideal.submodule_span_eq, ← set.image_singleton, ← ideal.map_span,
ideal.span_singleton_generator, ideal.map_comap_of_surjective f hf]⟩⟩
/-- The surjective image of a principal ideal ring is again a principal ideal ring. -/
lemma is_principal_ideal_ring.of_surjective [is_principal_ideal_ring R]
(f : R →+* S) (hf : function.surjective f) :
is_principal_ideal_ring S :=
⟨λ I, ideal.is_principal.of_comap f hf I⟩
end surjective
section
open ideal
variables [comm_ring R] [is_domain R] [is_principal_ideal_ring R] [gcd_monoid R]
theorem span_gcd (x y : R) : span ({gcd x y} : set R) = span ({x, y} : set R) :=
begin
obtain ⟨d, hd⟩ := is_principal_ideal_ring.principal (span ({x, y} : set R)),
rw submodule_span_eq at hd,
rw [hd],
suffices : associated d (gcd x y),
{ obtain ⟨D, HD⟩ := this,
rw ←HD,
exact (span_singleton_mul_right_unit D.is_unit _) },
apply associated_of_dvd_dvd,
{ rw dvd_gcd_iff,
split; rw [←ideal.mem_span_singleton, ←hd, mem_span_pair],
{ use [1, 0],
rw [one_mul, zero_mul, add_zero] },
{ use [0, 1],
rw [one_mul, zero_mul, zero_add] } },
{ obtain ⟨r, s, rfl⟩ : ∃ r s, r * x + s * y = d,
{ rw [←mem_span_pair, hd, ideal.mem_span_singleton] },
apply dvd_add; apply dvd_mul_of_dvd_right,
exacts [gcd_dvd_left x y, gcd_dvd_right x y] },
end
theorem gcd_dvd_iff_exists (a b : R) {z} : gcd a b ∣ z ↔ ∃ x y, z = a * x + b * y :=
by simp_rw [mul_comm a, mul_comm b, @eq_comm _ z, ←mem_span_pair, ←span_gcd,
ideal.mem_span_singleton]
/-- **Bézout's lemma** -/
theorem exists_gcd_eq_mul_add_mul (a b : R) : ∃ x y, gcd a b = a * x + b * y :=
by rw [←gcd_dvd_iff_exists]
theorem gcd_is_unit_iff (x y : R) : is_unit (gcd x y) ↔ is_coprime x y :=
by rw [is_coprime, ←mem_span_pair, ←span_gcd, ←span_singleton_eq_top, eq_top_iff_one]
-- this should be proved for UFDs surely?
theorem is_coprime_of_dvd (x y : R)
(nonzero : ¬ (x = 0 ∧ y = 0)) (H : ∀ z ∈ nonunits R, z ≠ 0 → z ∣ x → ¬ z ∣ y) :
is_coprime x y :=
begin
rw [← gcd_is_unit_iff],
by_contra h,
refine H _ h _ (gcd_dvd_left _ _) (gcd_dvd_right _ _),
rwa [ne, gcd_eq_zero_iff]
end
-- this should be proved for UFDs surely?
theorem dvd_or_coprime (x y : R) (h : irreducible x) : x ∣ y ∨ is_coprime x y :=
begin
refine or_iff_not_imp_left.2 (λ h', _),
apply is_coprime_of_dvd,
{ unfreezingI { rintro ⟨rfl, rfl⟩ }, simpa using h },
{ unfreezingI { rintro z nu nz ⟨w, rfl⟩ dy },
refine h' (dvd_trans _ dy),
simpa using mul_dvd_mul_left z (is_unit_iff_dvd_one.1 $
(of_irreducible_mul h).resolve_left nu) }
end
theorem is_coprime_of_irreducible_dvd {x y : R}
(nonzero : ¬ (x = 0 ∧ y = 0))
(H : ∀ z : R, irreducible z → z ∣ x → ¬ z ∣ y) :
is_coprime x y :=
begin
apply is_coprime_of_dvd x y nonzero,
intros z znu znz zx zy,
obtain ⟨i, h1, h2⟩ := wf_dvd_monoid.exists_irreducible_factor znu znz,
apply H i h1;
{ apply dvd_trans h2, assumption },
end
theorem is_coprime_of_prime_dvd {x y : R}
(nonzero : ¬ (x = 0 ∧ y = 0))
(H : ∀ z : R, prime z → z ∣ x → ¬ z ∣ y) :
is_coprime x y :=
is_coprime_of_irreducible_dvd nonzero $ λ z zi, H z $ gcd_monoid.prime_of_irreducible zi
theorem irreducible.coprime_iff_not_dvd {p n : R} (pp : irreducible p) : is_coprime p n ↔ ¬ p ∣ n :=
begin
split,
{ intros co H,
apply pp.not_unit,
rw is_unit_iff_dvd_one,
apply is_coprime.dvd_of_dvd_mul_left co,
rw mul_one n,
exact H },
{ intro nd,
apply is_coprime_of_irreducible_dvd,
{ rintro ⟨hp, -⟩,
exact pp.ne_zero hp },
rintro z zi zp zn,
exact nd (((zi.associated_of_dvd pp zp).symm.dvd).trans zn) },
end
theorem prime.coprime_iff_not_dvd {p n : R} (pp : prime p) : is_coprime p n ↔ ¬ p ∣ n :=
pp.irreducible.coprime_iff_not_dvd
theorem irreducible.dvd_iff_not_coprime {p n : R} (hp : irreducible p) : p ∣ n ↔ ¬ is_coprime p n :=
iff_not_comm.2 hp.coprime_iff_not_dvd
theorem irreducible.coprime_pow_of_not_dvd {p a : R} (m : ℕ) (hp : irreducible p) (h : ¬ p ∣ a) :
is_coprime a (p ^ m) :=
(hp.coprime_iff_not_dvd.2 h).symm.pow_right
theorem irreducible.coprime_or_dvd {p : R} (hp : irreducible p) (i : R) :
is_coprime p i ∨ p ∣ i :=
(em _).imp_right hp.dvd_iff_not_coprime.2
theorem exists_associated_pow_of_mul_eq_pow' {a b c : R}
(hab : is_coprime a b) {k : ℕ} (h : a * b = c ^ k) : ∃ d, associated (d ^ k) a :=
exists_associated_pow_of_mul_eq_pow ((gcd_is_unit_iff _ _).mpr hab) h
end
|
5f00d700973986017eee4d31d2e268b16bd935fb | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/data/nat/power.lean | 9f91d6ee62505385450373053aeccac84dc65942 | [
"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 | 4,684 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
The power function on the natural numbers.
-/
-- TODO(Leo): remove after refactoring
exit
import data.nat.basic data.nat.order data.nat.div data.nat.gcd algebra.ring_power
namespace nat
attribute [instance, priority nat.prio]
definition nat_has_pow_nat : has_pow_nat nat :=
has_pow_nat.mk has_pow_nat.pow_nat
theorem pow_le_pow_of_le {x y : ℕ} (i : ℕ) (H : x ≤ y) : x^i ≤ y^i :=
pow_le_pow_of_le i !zero_le H
theorem eq_zero_of_pow_eq_zero {a m : ℕ} (H : a^m = 0) : a = 0 :=
or.elim (eq_zero_or_pos m)
(suppose m = 0,
by rewrite [`m = 0` at H, pow_zero at H]; contradiction)
(suppose m > 0,
have h₁ : ∀ m, a^succ m = 0 → a = 0,
begin
intro m,
induction m with m ih,
{krewrite pow_one; intros; assumption},
rewrite pow_succ,
intro H,
cases eq_zero_or_eq_zero_of_mul_eq_zero H with h₃ h₄,
assumption,
exact ih h₄
end,
obtain m' (h₂ : m = succ m'), from exists_eq_succ_of_pos `m > 0`,
show a = 0, by rewrite h₂ at H; apply h₁ m' H)
-- generalize to semirings?
theorem le_pow_self {x : ℕ} (H : x > 1) : ∀ i, i ≤ x^i
| 0 := !zero_le
| (succ j) := have x > 0, from lt.trans zero_lt_one H,
have h₁ : x^j ≥ 1, from succ_le_of_lt (pow_pos_of_pos _ this),
have x ≥ 2, from succ_le_of_lt H,
calc
succ j = j + 1 : rfl
... ≤ x^j + 1 : add_le_add_right (le_pow_self j)
... ≤ x^j + x^j : add_le_add_left h₁
... = x^j * (1 + 1) : by rewrite [left_distrib, *mul_one]
... = x^j * 2 : rfl
... ≤ x^j * x : mul_le_mul_left _ `x ≥ 2`
... = x^(succ j) : pow_succ'
-- TODO: eventually this will be subsumed under the algebraic theorems
theorem mul_self_eq_pow_2 (a : nat) : a * a = a ^ 2 :=
show a * a = a ^ (succ (succ zero)), from
by krewrite [*pow_succ, *pow_zero, mul_one]
theorem pow_cancel_left : ∀ {a b c : nat}, a > 1 → a ^ b = a ^ c → b = c
| a 0 0 h₁ h₂ := rfl
| a (succ b) 0 h₁ h₂ :=
have a = 1, by rewrite [pow_succ at h₂, pow_zero at h₂]; exact (eq_one_of_mul_eq_one_right h₂),
have (1:nat) < 1, by rewrite [this at h₁]; exact h₁,
absurd `1 <[nat] 1` !lt.irrefl
| a 0 (succ c) h₁ h₂ :=
have a = 1, by rewrite [pow_succ at h₂, pow_zero at h₂]; exact (eq_one_of_mul_eq_one_right (eq.symm h₂)),
have (1:nat) < 1, by rewrite [this at h₁]; exact h₁,
absurd `1 <[nat] 1` !lt.irrefl
| a (succ b) (succ c) h₁ h₂ :=
have a ≠ 0, from assume aeq0, by rewrite [aeq0 at h₁]; exact (absurd h₁ dec_trivial),
have a^b = a^c, by rewrite [*pow_succ at h₂]; exact (eq_of_mul_eq_mul_left (pos_of_ne_zero this) h₂),
by rewrite [pow_cancel_left h₁ this]
theorem pow_div_cancel : ∀ {a b : nat}, a ≠ 0 → (a ^ succ b) / a = a ^ b
| a 0 h := by rewrite [pow_succ, pow_zero, mul_one, nat.div_self (pos_of_ne_zero h)]
| a (succ b) h := by rewrite [pow_succ, nat.mul_div_cancel_left _ (pos_of_ne_zero h)]
lemma dvd_pow : ∀ (i : nat) {n : nat}, n > 0 → i ∣ i^n
| i 0 h := absurd h !lt.irrefl
| i (succ n) h := by rewrite [pow_succ']; apply dvd_mul_left
lemma dvd_pow_of_dvd_of_pos : ∀ {i j n : nat}, i ∣ j → n > 0 → i ∣ j^n
| i j 0 h₁ h₂ := absurd h₂ !lt.irrefl
| i j (succ n) h₁ h₂ := by rewrite [pow_succ']; apply dvd_mul_of_dvd_right h₁
lemma pow_mod_eq_zero (i : nat) {n : nat} (h : n > 0) : (i ^ n) % i = 0 :=
iff.mp !dvd_iff_mod_eq_zero (dvd_pow i h)
lemma pow_dvd_of_pow_succ_dvd {p i n : nat} : p^(succ i) ∣ n → p^i ∣ n :=
suppose p^(succ i) ∣ n,
have p^i ∣ p^(succ i),
by rewrite [pow_succ']; apply nat.dvd_of_eq_mul; apply rfl,
dvd.trans `p^i ∣ p^(succ i)` `p^(succ i) ∣ n`
lemma dvd_of_pow_succ_dvd_mul_pow {p i n : nat} (Ppos : p > 0) :
p^(succ i) ∣ (n * p^i) → p ∣ n :=
by rewrite [pow_succ]; apply nat.dvd_of_mul_dvd_mul_right; apply pow_pos_of_pos _ Ppos
lemma coprime_pow_right {a b} : ∀ n, coprime b a → coprime b (a^n)
| 0 h := !comprime_one_right
| (succ n) h :=
begin
rewrite [pow_succ'],
apply coprime_mul_right,
exact coprime_pow_right n h,
exact h
end
lemma coprime_pow_left {a b} : ∀ n, coprime b a → coprime (b^n) a :=
take n, suppose coprime b a,
coprime_swap (coprime_pow_right n (coprime_swap this))
end nat
|
cbbe922bf51a506df380b1bfcbfdbad8946beec6 | 80746c6dba6a866de5431094bf9f8f841b043d77 | /src/category_theory/opposites.lean | 41098f554577d56cc8e5b2c9ff448d9f71964f4f | [
"Apache-2.0"
] | permissive | leanprover-fork/mathlib-backup | 8b5c95c535b148fca858f7e8db75a76252e32987 | 0eb9db6a1a8a605f0cf9e33873d0450f9f0ae9b0 | refs/heads/master | 1,585,156,056,139 | 1,548,864,430,000 | 1,548,864,438,000 | 143,964,213 | 0 | 0 | Apache-2.0 | 1,550,795,966,000 | 1,533,705,322,000 | Lean | UTF-8 | Lean | false | false | 6,267 | 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.products
import category_theory.types
namespace category_theory
universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
/-- The type of objects of the opposite of C (which should be a category).
In order to avoid confusion between C and its opposite category, we
set up the type of objects `opposite C` using the following pattern,
which will be repeated later for the morphisms.
1. Define `opposite C := C`.
2. Define the isomorphisms `op : C → opposite C`, `unop : opposite C → C`.
3. Make the definition `opposite` irreducible.
This has the following consequences.
* `opposite C` and `C` are distinct types in the elaborator, so you
must use `op` and `unop` explicitly to convert between them.
* Both `unop (op X) = X` and `op (unop X) = X` are definitional
equalities. Notably, every object of the opposite category is
definitionally of the form `op X`, which greatly simplifies the
definition of the structure of the opposite category, for example.
(If Lean supported definitional eta equality for records, we could
achieve the same goals using a structure with one field.)
-/
def opposite (C : Type u₁) : Type u₁ := C
-- Use a high right binding power (like that of postfix ⁻¹) so that, for example,
-- `presheaf Cᵒᵖ` parses as `presheaf (Cᵒᵖ)` and not `(presheaf C)ᵒᵖ`.
notation C `ᵒᵖ`:std.prec.max_plus := opposite C
variables {C : Type u₁}
def op (X : C) : Cᵒᵖ := X
def unop (X : Cᵒᵖ) : C := X
attribute [irreducible] opposite
@[simp] lemma unop_op (X : C) : unop (op X) = X := rfl
@[simp] lemma op_unop (X : Cᵒᵖ) : op (unop X) = X := rfl
section has_hom
variables [𝒞 : has_hom.{v₁} C]
include 𝒞
/-- The hom types of the opposite of a category (or graph).
As with the objects, we'll make this irreducible below.
Use `f.op` and `f.unop` to convert between morphisms of C
and morphisms of Cᵒᵖ.
-/
instance has_hom.opposite : has_hom Cᵒᵖ :=
{ hom := λ X Y, unop Y ⟶ unop X }
def has_hom.hom.op {X Y : C} (f : X ⟶ Y) : op Y ⟶ op X := f
def has_hom.hom.unop {X Y : Cᵒᵖ} (f : X ⟶ Y) : unop Y ⟶ unop X := f
attribute [irreducible] has_hom.opposite
lemma has_hom.hom.op_inj {X Y : C} :
function.injective (has_hom.hom.op : (X ⟶ Y) → (op Y ⟶ op X)) :=
λ _ _ H, congr_arg has_hom.hom.unop H
lemma has_hom.hom.unop_inj {X Y : Cᵒᵖ} :
function.injective (has_hom.hom.unop : (X ⟶ Y) → (unop Y ⟶ unop X)) :=
λ _ _ H, congr_arg has_hom.hom.op H
@[simp] lemma has_hom.hom.unop_op {X Y : C} {f : X ⟶ Y} : f.op.unop = f := rfl
@[simp] lemma has_hom.hom.op_unop {X Y : Cᵒᵖ} {f : X ⟶ Y} : f.unop.op = f := rfl
end has_hom
variables [𝒞 : category.{v₁} C]
include 𝒞
instance category.opposite : category.{v₁} Cᵒᵖ :=
{ comp := λ _ _ _ f g, (g.unop ≫ f.unop).op,
id := λ X, (𝟙 (unop X)).op }
@[simp] lemma op_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).op = g.op ≫ f.op := rfl
@[simp] lemma op_id {X : C} : (𝟙 X).op = 𝟙 (op X) := rfl
@[simp] lemma unop_comp {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).unop = g.unop ≫ f.unop := rfl
@[simp] lemma unop_id {X : Cᵒᵖ} : (𝟙 X).unop = 𝟙 (unop X) := rfl
def op_op : (Cᵒᵖ)ᵒᵖ ⥤ C :=
{ obj := λ X, unop (unop X),
map := λ X Y f, f.unop.unop }
-- TODO this is an equivalence
namespace functor
section
variables {D : Type u₂} [𝒟 : category.{v₂} D]
include 𝒟
variables {C D}
protected definition op (F : C ⥤ D) : Cᵒᵖ ⥤ Dᵒᵖ :=
{ obj := λ X, op (F.obj (unop X)),
map := λ X Y f, (F.map f.unop).op }
@[simp] lemma op_obj (F : C ⥤ D) (X : Cᵒᵖ) : (F.op).obj X = op (F.obj (unop X)) := rfl
@[simp] lemma op_map (F : C ⥤ D) {X Y : Cᵒᵖ} (f : X ⟶ Y) : (F.op).map f = (F.map f.unop).op := rfl
protected definition unop (F : Cᵒᵖ ⥤ Dᵒᵖ) : C ⥤ D :=
{ obj := λ X, unop (F.obj (op X)),
map := λ X Y f, (F.map f.op).unop }
@[simp] lemma unop_obj (F : Cᵒᵖ ⥤ Dᵒᵖ) (X : C) : (F.unop).obj X = unop (F.obj (op X)) := rfl
@[simp] lemma unop_map (F : Cᵒᵖ ⥤ Dᵒᵖ) {X Y : C} (f : X ⟶ Y) : (F.unop).map f = (F.map f.op).unop := rfl
variables (C D)
definition op_hom : (C ⥤ D)ᵒᵖ ⥤ (Cᵒᵖ ⥤ Dᵒᵖ) :=
{ obj := λ F, (unop F).op,
map := λ F G α,
{ app := λ X, (α.unop.app (unop X)).op,
naturality' := λ X Y f, has_hom.hom.unop_inj $ eq.symm (α.unop.naturality f.unop) } }
@[simp] lemma op_hom.obj (F : (C ⥤ D)ᵒᵖ) : (op_hom C D).obj F = (unop F).op := rfl
@[simp] lemma op_hom.map_app {F G : (C ⥤ D)ᵒᵖ} (α : F ⟶ G) (X : Cᵒᵖ) :
((op_hom C D).map α).app X = (α.unop.app (unop X)).op := rfl
definition op_inv : (Cᵒᵖ ⥤ Dᵒᵖ) ⥤ (C ⥤ D)ᵒᵖ :=
{ obj := λ F, op F.unop,
map := λ F G α, has_hom.hom.op
{ app := λ X, (α.app (op X)).unop,
naturality' := λ X Y f, has_hom.hom.op_inj $ eq.symm (α.naturality f.op) } }
@[simp] lemma op_inv.obj (F : Cᵒᵖ ⥤ Dᵒᵖ) : (op_inv C D).obj F = op F.unop := rfl
@[simp] lemma op_inv.map_app {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ⟶ G) (X : C) :
(((op_inv C D).map α).unop).app X = (α.app (op X)).unop := rfl
-- TODO show these form an equivalence
instance {F : C ⥤ D} [full F] : full F.op :=
{ preimage := λ X Y f, (F.preimage f.unop).op }
instance {F : C ⥤ D} [faithful F] : faithful F.op :=
{ injectivity' := λ X Y f g h,
has_hom.hom.unop_inj $ by simpa using injectivity F (has_hom.hom.op_inj h) }
end
section
variable (C)
/-- `functor.hom` is the hom-pairing, sending (X,Y) to X → Y, contravariant in X and covariant in Y. -/
definition hom : Cᵒᵖ × C ⥤ Type v₁ :=
{ obj := λ p, unop p.1 ⟶ p.2,
map := λ X Y f, λ h, f.1.unop ≫ h ≫ f.2 }
@[simp] lemma hom_obj (X : Cᵒᵖ × C) : (functor.hom C).obj X = (unop X.1 ⟶ X.2) := rfl
@[simp] lemma hom_pairing_map {X Y : Cᵒᵖ × C} (f : X ⟶ Y) :
(functor.hom C).map f = λ h, f.1.unop ≫ h ≫ f.2 := rfl
end
end functor
end category_theory
|
8bfc786fe1e4465d1939000d31a426fddff779a0 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/category/monad/writer.lean | 9afc8579db88044c61c9d8366a655e2f8fa9d25d | [
"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 | 7,070 | lean |
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
The writer monad transformer for passing immutable state.
-/
import tactic.basic category.monad.basic
universes u v w
structure writer_t (ω : Type u) (m : Type u → Type v) (α : Type u) : Type (max u v) :=
(run : m (α × ω))
@[reducible] def writer (ω : Type u) := writer_t ω id
attribute [pp_using_anonymous_constructor] writer_t
namespace writer_t
section
variable {ω : Type u}
variable {m : Type u → Type v}
variable [monad m]
variables {α β : Type u}
open function
@[ext]
protected lemma ext (x x' : writer_t ω m α)
(h : x.run = x'.run) :
x = x' := by cases x; cases x'; congr; apply h
@[inline] protected def tell (w : ω) : writer_t ω m punit :=
⟨pure (punit.star, w)⟩
@[inline] protected def listen : writer_t ω m α → writer_t ω m (α × ω)
| ⟨ cmd ⟩ := ⟨ (λ x : α × ω, ((x.1,x.2),x.2)) <$> cmd ⟩
@[inline] protected def pass : writer_t ω m (α × (ω → ω)) → writer_t ω m α
| ⟨ cmd ⟩ := ⟨ uncurry (uncurry $ λ x (f : ω → ω) w, (x,f w)) <$> cmd ⟩
@[inline] protected def pure [has_one ω] (a : α) : writer_t ω m α :=
⟨ pure (a,1) ⟩
@[inline] protected def bind [has_mul ω] (x : writer_t ω m α) (f : α → writer_t ω m β) : writer_t ω m β :=
⟨ do x ← x.run,
x' ← (f x.1).run,
pure (x'.1,x.2 * x'.2) ⟩
instance [has_one ω] [has_mul ω] : monad (writer_t ω m) :=
{ pure := λ α, writer_t.pure, bind := λ α β, writer_t.bind }
instance [monoid ω] [is_lawful_monad m] : is_lawful_monad (writer_t ω m) :=
{ id_map := by { intros, cases x, simp [(<$>),writer_t.bind,writer_t.pure] },
pure_bind := by { intros, simp [has_pure.pure,writer_t.pure,(>>=),writer_t.bind], ext; refl },
bind_assoc := by { intros, simp [(>>=),writer_t.bind,mul_assoc] with functor_norm } }
@[inline] protected def lift [has_one ω] (a : m α) : writer_t ω m α :=
⟨ flip prod.mk 1 <$> a ⟩
instance (m) [monad m] [has_one ω] : has_monad_lift m (writer_t ω m) :=
⟨ λ α, writer_t.lift ⟩
@[inline] protected def monad_map {m m'} [monad m] [monad m'] {α} (f : Π {α}, m α → m' α) : writer_t ω m α → writer_t ω m' α :=
λ x, ⟨ f x.run ⟩
instance (m m') [monad m] [monad m'] : monad_functor m m' (writer_t ω m) (writer_t ω m') :=
⟨@writer_t.monad_map ω m m' _ _⟩
@[inline] protected def adapt {ω' : Type u} {α : Type u} (f : ω → ω') : writer_t ω m α → writer_t ω' m α :=
λ x, ⟨prod.map id f <$> x.run⟩
instance (ε) [has_one ω] [monad m] [monad_except ε m] : monad_except ε (writer_t ω m) :=
{ throw := λ α, writer_t.lift ∘ throw,
catch := λ α x c, ⟨catch x.run (λ e, (c e).run)⟩ }
end
end writer_t
/-- An implementation of [MonadReader](https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Reader-Class.html#t:MonadReader).
It does not contain `local` because this function cannot be lifted using `monad_lift`.
Instead, the `monad_reader_adapter` class provides the more general `adapt_reader` function.
Note: This class can be seen as a simplification of the more "principled" definition
```
class monad_reader (ρ : out_param (Type u)) (n : Type u → Type u) :=
(lift {} {α : Type u} : (∀ {m : Type u → Type u} [monad m], reader_t ρ m α) → n α)
```
-/
class monad_writer (ω : out_param (Type u)) (m : Type u → Type v) :=
(tell {} (w : ω) : m punit)
(listen {α} : m α → m (α × ω))
(pass {α : Type u} : m (α × (ω → ω)) → m α)
export monad_writer
instance {ω : Type u} {m : Type u → Type v} [monad m] : monad_writer ω (writer_t ω m) :=
{ tell := writer_t.tell,
listen := λ α, writer_t.listen,
pass := λ α, writer_t.pass }
instance {ω ρ : Type u} {m : Type u → Type v} [monad m] [monad_writer ω m] : monad_writer ω (reader_t ρ m) :=
{ tell := λ x, monad_lift (tell x : m punit),
listen := λ α ⟨ cmd ⟩, ⟨ λ r, listen (cmd r) ⟩,
pass := λ α ⟨ cmd ⟩, ⟨ λ r, pass (cmd r) ⟩ }
def swap_right {α β γ} : (α × β) × γ → (α × γ) × β
| ⟨⟨x,y⟩,z⟩ := ((x,z),y)
instance {ω σ : Type u} {m : Type u → Type v} [monad m] [monad_writer ω m] : monad_writer ω (state_t σ m) :=
{ tell := λ x, monad_lift (tell x : m punit),
listen := λ α ⟨ cmd ⟩, ⟨ λ r, swap_right <$> listen (cmd r) ⟩,
pass := λ α ⟨ cmd ⟩, ⟨ λ r, pass (swap_right <$> cmd r) ⟩ }
open function
def except_t.pass_aux {ε α ω} : except ε (α × (ω → ω)) → except ε α × (ω → ω)
| (except.error a) := (except.error a,id)
| (except.ok (x,y)) := (except.ok x,y)
instance {ω ε : Type u} {m : Type u → Type v} [monad m] [monad_writer ω m] : monad_writer ω (except_t ε m) :=
{ tell := λ x, monad_lift (tell x : m punit),
listen := λ α ⟨ cmd ⟩, ⟨ uncurry (λ x y, flip prod.mk y <$> x) <$> listen cmd ⟩,
pass := λ α ⟨ cmd ⟩, ⟨ pass (except_t.pass_aux <$> cmd) ⟩ }
def option_t.pass_aux {α ω} : option (α × (ω → ω)) → option α × (ω → ω)
| none := (none ,id)
| (some (x,y)) := (some x,y)
instance {ω : Type u} {m : Type u → Type v} [monad m] [monad_writer ω m] : monad_writer ω (option_t m) :=
{ tell := λ x, monad_lift (tell x : m punit),
listen := λ α ⟨ cmd ⟩, ⟨ uncurry (λ x y, flip prod.mk y <$> x) <$> listen cmd ⟩,
pass := λ α ⟨ cmd ⟩, ⟨ pass (option_t.pass_aux <$> cmd) ⟩ }
/-- Adapt a monad stack, changing the type of its top-most environment.
This class is comparable to [Control.Lens.Magnify](https://hackage.haskell.org/package/lens-4.15.4/docs/Control-Lens-Zoom.html#t:Magnify), but does not use lenses (why would it), and is derived automatically for any transformer implementing `monad_functor`.
Note: This class can be seen as a simplification of the more "principled" definition
```
class monad_reader_functor (ρ ρ' : out_param (Type u)) (n n' : Type u → Type u) :=
(map {} {α : Type u} : (∀ {m : Type u → Type u} [monad m], reader_t ρ m α → reader_t ρ' m α) → n α → n' α)
```
-/
class monad_writer_adapter (ω ω' : out_param (Type u)) (m m' : Type u → Type v) :=
(adapt_writer {} {α : Type u} : (ω → ω') → m α → m' α)
export monad_writer_adapter (adapt_writer)
section
variables {ω ω' : Type u} {m m' : Type u → Type v}
@[priority 100] -- see Note [lower instance priority]
instance monad_writer_adapter_trans {n n' : Type u → Type v} [monad_functor m m' n n'] [monad_writer_adapter ω ω' m m'] : monad_writer_adapter ω ω' n n' :=
⟨λ α f, monad_map (λ α, (adapt_writer f : m α → m' α))⟩
instance [monad m] : monad_writer_adapter ω ω' (writer_t ω m) (writer_t ω' m) :=
⟨λ α, writer_t.adapt⟩
end
instance (ω : Type u) (m out) [monad_run out m] : monad_run (λ α, out (α × ω)) (writer_t ω m) :=
⟨λ α x, run $ x.run ⟩
|
90fe993b09693c8da6e1c6086faf83737ddefe92 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/special_functions/gaussian.lean | 7705bdc53828285ebc0cecc661f2602ace14ef64 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 28,605 | lean | /-
Copyright (c) 2022 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.special_functions.gamma.basic
import analysis.special_functions.polar_coord
import analysis.convex.complex
import analysis.complex.cauchy_integral
import analysis.fourier.poisson_summation
/-!
# Gaussian integral
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We prove various versions of the formula for the Gaussian integral:
* `integral_gaussian`: for real `b` we have `∫ x:ℝ, exp (-b * x^2) = sqrt (π / b)`.
* `integral_gaussian_complex`: for complex `b` with `0 < re b` we have
`∫ x:ℝ, exp (-b * x^2) = (π / b) ^ (1 / 2)`.
* `integral_gaussian_Ioi` and `integral_gaussian_complex_Ioi`: variants for integrals over `Ioi 0`.
* `complex.Gamma_one_half_eq`: the formula `Γ (1 / 2) = √π`.
We also prove, more generally, that the Fourier transform of the Gaussian is another Gaussian:
* `integral_cexp_neg_mul_sq_add_const`: for all complex `b` and `c` with `0 < re b` we have
`∫ (x : ℝ), exp (-b * (x + c) ^ 2) = (π / b) ^ (1 / 2)`.
* `fourier_transform_gaussian`: for all complex `b` and `t` with `0 < re b`, we have
`∫ x:ℝ, exp (I * t * x) * exp (-b * x^2) = (π / b) ^ (1 / 2) * exp (-t ^ 2 / (4 * b))`.
* `fourier_transform_gaussian_pi`: a variant with `b` and `t` scaled to give a more symmetric
statement, and formulated in terms of the Fourier transform operator `𝓕`.
As an application, in `real.tsum_exp_neg_mul_int_sq` and `complex.tsum_exp_neg_mul_int_sq`, we use
Poisson summation to prove the identity
`∑' (n : ℤ), exp (-π * a * n ^ 2) = 1 / a ^ (1 / 2) * ∑' (n : ℤ), exp (-π / a * n ^ 2)`
for positive real `a`, or complex `a` with positive real part. (See also
`number_theory.modular_forms.jacobi_theta`.)
-/
noncomputable theory
open real set measure_theory filter asymptotics
open_locale real topology fourier_transform
open complex (hiding exp continuous_exp abs_of_nonneg sq_abs)
notation `cexp` := complex.exp
notation `rexp` := real.exp
lemma exp_neg_mul_sq_is_o_exp_neg {b : ℝ} (hb : 0 < b) :
(λ x:ℝ, exp (-b * x^2)) =o[at_top] (λ x:ℝ, exp (-x)) :=
begin
have A : (λ (x : ℝ), -x - -b * x ^ 2) = (λ x, x * (b * x + (- 1))), by { ext x, ring },
rw [is_o_exp_comp_exp_comp, A],
apply tendsto.at_top_mul_at_top tendsto_id,
apply tendsto_at_top_add_const_right at_top (-1 : ℝ),
exact tendsto.const_mul_at_top hb tendsto_id,
end
lemma rpow_mul_exp_neg_mul_sq_is_o_exp_neg {b : ℝ} (hb : 0 < b) (s : ℝ) :
(λ x:ℝ, x ^ s * exp (-b * x^2)) =o[at_top] (λ x:ℝ, exp (-(1/2) * x)) :=
begin
apply ((is_O_refl (λ x:ℝ, x ^ s) at_top).mul_is_o (exp_neg_mul_sq_is_o_exp_neg hb)).trans,
convert Gamma_integrand_is_o s,
simp_rw [mul_comm],
end
lemma integrable_on_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) :
integrable_on (λ x:ℝ, x ^ s * exp (-b * x^2)) (Ioi 0) :=
begin
rw [← Ioc_union_Ioi_eq_Ioi (zero_le_one : (0 : ℝ) ≤ 1), integrable_on_union],
split,
{ rw [←integrable_on_Icc_iff_integrable_on_Ioc],
refine integrable_on.mul_continuous_on _ _ is_compact_Icc,
{ refine (interval_integrable_iff_integrable_Icc_of_le zero_le_one).mp _,
exact interval_integral.interval_integrable_rpow' hs },
{ exact (continuous_exp.comp (continuous_const.mul (continuous_pow 2))).continuous_on } },
{ have B : (0 : ℝ) < 1/2, by norm_num,
apply integrable_of_is_O_exp_neg B _ (is_o.is_O (rpow_mul_exp_neg_mul_sq_is_o_exp_neg hb _)),
assume x hx,
have N : x ≠ 0, { refine (zero_lt_one.trans_le _).ne', exact hx },
apply ((continuous_at_rpow_const _ _ (or.inl N)).mul _).continuous_within_at,
exact (continuous_exp.comp (continuous_const.mul (continuous_pow 2))).continuous_at },
end
lemma integrable_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) :
integrable (λ x:ℝ, x ^ s * exp (-b * x^2)) :=
begin
rw [← integrable_on_univ, ← @Iio_union_Ici _ _ (0 : ℝ), integrable_on_union,
integrable_on_Ici_iff_integrable_on_Ioi],
refine ⟨_, integrable_on_rpow_mul_exp_neg_mul_sq hb hs⟩,
rw ← (measure.measure_preserving_neg (volume : measure ℝ)).integrable_on_comp_preimage
((homeomorph.neg ℝ).to_measurable_equiv.measurable_embedding),
simp only [function.comp, neg_sq, neg_preimage, preimage_neg_Iio, neg_neg, neg_zero],
apply integrable.mono' (integrable_on_rpow_mul_exp_neg_mul_sq hb hs),
{ apply measurable.ae_strongly_measurable,
exact (measurable_id'.neg.pow measurable_const).mul
((measurable_id'.pow measurable_const).const_mul (-b)).exp },
{ have : measurable_set (Ioi (0 : ℝ)) := measurable_set_Ioi,
filter_upwards [ae_restrict_mem this] with x hx,
have h'x : 0 ≤ x := le_of_lt hx,
rw [real.norm_eq_abs, abs_mul, abs_of_nonneg (exp_pos _).le],
apply mul_le_mul_of_nonneg_right _ (exp_pos _).le,
simpa [abs_of_nonneg h'x] using abs_rpow_le_abs_rpow (-x) s }
end
lemma integrable_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) :
integrable (λ x:ℝ, exp (-b * x^2)) :=
by simpa using integrable_rpow_mul_exp_neg_mul_sq hb (by norm_num : (-1 : ℝ) < 0)
lemma integrable_on_Ioi_exp_neg_mul_sq_iff {b : ℝ} :
integrable_on (λ x:ℝ, exp (-b * x^2)) (Ioi 0) ↔ 0 < b :=
begin
refine ⟨λ h, _, λ h, (integrable_exp_neg_mul_sq h).integrable_on⟩,
by_contra' hb,
have : ∫⁻ x:ℝ in Ioi 0, 1 ≤ ∫⁻ x:ℝ in Ioi 0, ‖exp (-b * x^2)‖₊,
{ apply lintegral_mono (λ x, _),
simp only [neg_mul, ennreal.one_le_coe_iff, ← to_nnreal_one, to_nnreal_le_iff_le_coe,
real.norm_of_nonneg (exp_pos _).le, coe_nnnorm, one_le_exp_iff, right.nonneg_neg_iff],
exact mul_nonpos_of_nonpos_of_nonneg hb (sq_nonneg _) },
simpa using this.trans_lt h.2,
end
lemma integrable_exp_neg_mul_sq_iff {b : ℝ} : integrable (λ x:ℝ, exp (-b * x^2)) ↔ 0 < b :=
⟨λ h, integrable_on_Ioi_exp_neg_mul_sq_iff.mp h.integrable_on, integrable_exp_neg_mul_sq⟩
lemma integrable_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) : integrable (λ x:ℝ, x * exp (-b * x^2)) :=
by simpa using integrable_rpow_mul_exp_neg_mul_sq hb (by norm_num : (-1 : ℝ) < 1)
lemma norm_cexp_neg_mul_sq (b : ℂ) (x : ℝ) : ‖complex.exp (-b * x^2)‖ = exp (-b.re * x^2) :=
by rw [complex.norm_eq_abs, complex.abs_exp, ←of_real_pow, mul_comm (-b) _, of_real_mul_re,
neg_re, mul_comm]
lemma integrable_cexp_neg_mul_sq {b : ℂ} (hb : 0 < b.re) : integrable (λ x:ℝ, cexp (-b * x^2)) :=
begin
refine ⟨(complex.continuous_exp.comp
(continuous_const.mul (continuous_of_real.pow 2))).ae_strongly_measurable, _⟩,
rw ←has_finite_integral_norm_iff,
simp_rw norm_cexp_neg_mul_sq,
exact (integrable_exp_neg_mul_sq hb).2,
end
lemma integrable_mul_cexp_neg_mul_sq {b : ℂ} (hb : 0 < b.re) :
integrable (λ x:ℝ, ↑x * cexp (-b * x^2)) :=
begin
refine ⟨(continuous_of_real.mul (complex.continuous_exp.comp _)).ae_strongly_measurable, _⟩,
{ exact continuous_const.mul (continuous_of_real.pow 2) },
have := (integrable_mul_exp_neg_mul_sq hb).has_finite_integral,
rw ←has_finite_integral_norm_iff at this ⊢,
convert this,
ext1 x,
rw [norm_mul, norm_mul, norm_cexp_neg_mul_sq b, complex.norm_eq_abs, abs_of_real,
real.norm_eq_abs, norm_of_nonneg (exp_pos _).le],
end
lemma integral_mul_cexp_neg_mul_sq {b : ℂ} (hb : 0 < b.re) :
∫ r:ℝ in Ioi 0, (r : ℂ) * cexp (-b * r ^ 2) = (2 * b)⁻¹ :=
begin
have hb' : b ≠ 0 := by { contrapose! hb, rw [hb, zero_re], },
have A : ∀ x:ℂ, has_deriv_at (λ x, - (2 * b)⁻¹ * cexp (-b * x^2)) (x * cexp (- b * x^2)) x,
{ intro x,
convert (((has_deriv_at_pow 2 x)).const_mul (-b)).cexp.const_mul (- (2 * b)⁻¹) using 1,
field_simp [hb'],
ring },
have B : tendsto (λ (y : ℝ), -(2 * b)⁻¹ * cexp (-b * ↑y ^ 2)) at_top (𝓝 (-(2 * b)⁻¹ * 0)),
{ refine (tendsto.const_mul _ (tendsto_zero_iff_norm_tendsto_zero.mpr _)),
simp_rw norm_cexp_neg_mul_sq b,
exact tendsto_exp_at_bot.comp
(tendsto.neg_const_mul_at_top (neg_lt_zero.2 hb) (tendsto_pow_at_top two_ne_zero)) },
convert integral_Ioi_of_has_deriv_at_of_tendsto' (λ x hx, (A ↑x).comp_of_real)
(integrable_mul_cexp_neg_mul_sq hb).integrable_on B,
simp only [mul_zero, of_real_zero, zero_pow', ne.def, bit0_eq_zero, nat.one_ne_zero,
not_false_iff, complex.exp_zero, mul_one, sub_neg_eq_add, zero_add],
end
/-- The *square* of the Gaussian integral `∫ x:ℝ, exp (-b * x^2)` is equal to `π / b`. -/
lemma integral_gaussian_sq_complex {b : ℂ} (hb : 0 < b.re) :
(∫ x:ℝ, cexp (-b * x^2)) ^ 2 = π / b :=
begin
/- We compute `(∫ exp (-b x^2))^2` as an integral over `ℝ^2`, and then make a polar change
of coordinates. We are left with `∫ r * exp (-b r^2)`, which has been computed in
`integral_mul_cexp_neg_mul_sq` using the fact that this function has an obvious primitive. -/
calc
(∫ x:ℝ, cexp (-b * (x:ℂ)^2)) ^ 2
= ∫ p : ℝ × ℝ, cexp (-b * ((p.1) : ℂ) ^ 2) * cexp (-b * ((p.2) : ℂ) ^ 2) :
by { rw [pow_two, ← integral_prod_mul], refl }
... = ∫ p : ℝ × ℝ, cexp (- b * (p.1 ^ 2 + p.2 ^ 2)) :
by { congr, ext1 p, rw [← complex.exp_add, mul_add], }
... = ∫ p in polar_coord.target, (p.1) • cexp (- b * ((p.1 * cos p.2) ^ 2 + (p.1 * sin p.2)^2)) :
begin
rw ← integral_comp_polar_coord_symm,
simp only [polar_coord_symm_apply, of_real_mul, of_real_cos, of_real_sin],
end
... = (∫ r in Ioi (0 : ℝ), r * cexp (-b * r^2)) * (∫ θ in Ioo (-π) π, 1) :
begin
rw ← set_integral_prod_mul,
congr' with p : 1,
rw mul_one,
congr,
conv_rhs { rw [← one_mul ((p.1 : ℂ)^2), ← sin_sq_add_cos_sq (p.2 : ℂ)], },
ring_exp,
end
... = ↑π / b :
begin
have : 0 ≤ π + π, by linarith [real.pi_pos],
simp only [integral_const, measure.restrict_apply', measurable_set_Ioo, univ_inter,
volume_Ioo, sub_neg_eq_add, ennreal.to_real_of_real, this],
rw [←two_mul, real_smul, mul_one, of_real_mul, of_real_bit0, of_real_one,
integral_mul_cexp_neg_mul_sq hb],
field_simp [(by { contrapose! hb, rw [hb, zero_re] } : b ≠ 0)],
ring,
end
end
theorem integral_gaussian (b : ℝ) : ∫ x, exp (-b * x^2) = sqrt (π / b) :=
begin
/- First we deal with the crazy case where `b ≤ 0`: then both sides vanish. -/
rcases le_or_lt b 0 with hb|hb,
{ rw [integral_undef, sqrt_eq_zero_of_nonpos],
{ exact div_nonpos_of_nonneg_of_nonpos pi_pos.le hb },
{ simpa only [not_lt, integrable_exp_neg_mul_sq_iff] using hb } },
/- Assume now `b > 0`. Then both sides are non-negative and their squares agree. -/
refine (sq_eq_sq _ (sqrt_nonneg _)).1 _,
{ exact integral_nonneg (λ x, (exp_pos _).le) },
rw [←of_real_inj, of_real_pow, ←integral_of_real, sq_sqrt (div_pos pi_pos hb).le, of_real_div],
convert integral_gaussian_sq_complex (by rwa of_real_re : 0 < (b:ℂ).re),
ext1 x,
rw [of_real_exp, of_real_mul, of_real_pow, of_real_neg],
end
lemma continuous_at_gaussian_integral (b : ℂ) (hb : 0 < re b) :
continuous_at (λ c:ℂ, ∫ x:ℝ, cexp (-c * x^2)) b :=
begin
let f : ℂ → ℝ → ℂ := λ (c : ℂ) (x : ℝ), cexp (-c * x ^ 2),
obtain ⟨d, hd, hd'⟩ := exists_between hb,
have f_meas : ∀ (c:ℂ), ae_strongly_measurable (f c) volume := λ c, by
{ apply continuous.ae_strongly_measurable,
exact complex.continuous_exp.comp (continuous_const.mul (continuous_of_real.pow 2)) },
have f_int : integrable (f b) volume,
{ simp_rw [←integrable_norm_iff (f_meas b), norm_cexp_neg_mul_sq b],
exact integrable_exp_neg_mul_sq hb, },
have f_cts : ∀ (x : ℝ), continuous_at (λ c, f c x) b :=
λ x, (complex.continuous_exp.comp (continuous_id'.neg.mul continuous_const)).continuous_at,
have f_le_bd : ∀ᶠ (c : ℂ) in 𝓝 b, ∀ᵐ (x : ℝ), ‖f c x‖ ≤ exp (-d * x ^ 2),
{ refine eventually_of_mem ((continuous_re.is_open_preimage _ is_open_Ioi).mem_nhds hd') _,
refine λ c hc, ae_of_all _ (λ x, _),
rw [norm_cexp_neg_mul_sq, exp_le_exp],
exact mul_le_mul_of_nonneg_right (neg_le_neg (le_of_lt hc)) (sq_nonneg _) },
exact continuous_at_of_dominated (eventually_of_forall f_meas) f_le_bd
(integrable_exp_neg_mul_sq hd) (ae_of_all _ f_cts),
end
theorem integral_gaussian_complex {b : ℂ} (hb : 0 < re b) :
∫ x:ℝ, cexp (-b * x^2) = (π / b) ^ (1 / 2 : ℂ) :=
begin
have nv : ∀ {b : ℂ}, (0 < re b) → (b ≠ 0),
{ intros b hb, contrapose! hb, rw hb, simp },
refine (convex_halfspace_re_gt 0).is_preconnected.eq_of_sq_eq
_ _ (λ c hc, _) (λ c hc, _) (by simp : 0 < re (1 : ℂ)) _ hb,
{ -- integral is continuous
exact continuous_at.continuous_on continuous_at_gaussian_integral, },
{ -- `(π / b) ^ (1 / 2 : ℂ)` is continuous
refine continuous_at.continuous_on (λ b hb, (continuous_at_cpow_const (or.inl _)).comp
(continuous_at_const.div continuous_at_id (nv hb))),
rw [div_re, of_real_im, of_real_re, zero_mul, zero_div, add_zero],
exact div_pos (mul_pos pi_pos hb) (norm_sq_pos.mpr (nv hb)), },
{ -- squares of both sides agree
dsimp only [pi.pow_apply],
rw [integral_gaussian_sq_complex hc, sq],
conv_lhs { rw ←cpow_one (↑π / c)},
rw ← cpow_add _ _ (div_ne_zero (of_real_ne_zero.mpr pi_ne_zero) (nv hc)),
norm_num },
{ -- RHS doesn't vanish
rw [ne.def, cpow_eq_zero_iff, not_and_distrib],
exact or.inl (div_ne_zero (of_real_ne_zero.mpr pi_ne_zero) (nv hc)) },
{ -- equality at 1
have : ∀ (x : ℝ), cexp (-1 * x ^ 2) = exp (-1 * x ^ 2),
{ intro x,
simp only [of_real_exp, neg_mul, one_mul, of_real_neg, of_real_pow] },
simp_rw [this, integral_of_real],
conv_rhs { congr, rw [←of_real_one, ←of_real_div], skip,
rw [←of_real_one, ←of_real_bit0, ←of_real_div] },
rw [←of_real_cpow, of_real_inj],
convert integral_gaussian (1 : ℝ),
{ rwa [sqrt_eq_rpow] },
{ rw [div_one], exact pi_pos.le } },
end
/- The Gaussian integral on the half-line, `∫ x in Ioi 0, exp (-b * x^2)`, for complex `b`. -/
lemma integral_gaussian_complex_Ioi {b : ℂ} (hb : 0 < re b) :
∫ x:ℝ in Ioi 0, cexp (-b * x^2) = (π / b) ^ (1 / 2 : ℂ) / 2 :=
begin
have full_integral := integral_gaussian_complex hb,
have : measurable_set (Ioi (0:ℝ)) := measurable_set_Ioi,
rw [←integral_add_compl this (integrable_cexp_neg_mul_sq hb), compl_Ioi] at full_integral,
suffices : ∫ x:ℝ in Iic 0, cexp (-b * x^2) = ∫ x:ℝ in Ioi 0, cexp (-b * x^2),
{ rw [this, ←mul_two] at full_integral,
rwa eq_div_iff, exact two_ne_zero },
have : ∀ (c : ℝ), ∫ x in 0 .. c, cexp (-b * x^2) = ∫ x in -c .. 0, cexp (-b * x^2),
{ intro c,
have := @interval_integral.integral_comp_sub_left _ _ _ _ 0 c (λ x, cexp (-b * x^2)) 0,
simpa [zero_sub, neg_sq, neg_zero] using this },
have t1 := interval_integral_tendsto_integral_Ioi _
((integrable_cexp_neg_mul_sq hb).integrable_on) tendsto_id,
have t2 : tendsto (λ c:ℝ, ∫ x:ℝ in 0..c,
cexp (-b * x^2)) at_top (𝓝 ∫ x:ℝ in Iic 0, cexp (-b * x^2)),
{ simp_rw this,
refine interval_integral_tendsto_integral_Iic _ _ tendsto_neg_at_top_at_bot,
apply (integrable_cexp_neg_mul_sq hb).integrable_on },
exact tendsto_nhds_unique t2 t1,
end
/- The Gaussian integral on the half-line, `∫ x in Ioi 0, exp (-b * x^2)`, for real `b`. -/
lemma integral_gaussian_Ioi (b : ℝ) : ∫ x in Ioi 0, exp (-b * x^2) = sqrt (π / b) / 2 :=
begin
rcases le_or_lt b 0 with hb|hb,
{ rw [integral_undef, sqrt_eq_zero_of_nonpos, zero_div],
exact div_nonpos_of_nonneg_of_nonpos pi_pos.le hb,
rwa [←integrable_on, integrable_on_Ioi_exp_neg_mul_sq_iff, not_lt] },
rw [←of_real_inj, ←integral_of_real],
convert integral_gaussian_complex_Ioi (by rwa of_real_re : 0 < (b:ℂ).re),
{ ext1 x, simp, },
{ rw [sqrt_eq_rpow, ←of_real_div, of_real_div, of_real_cpow],
norm_num,
exact (div_pos pi_pos hb).le, }
end
/-- The special-value formula `Γ(1/2) = √π`, which is equivalent to the Gaussian integral. -/
lemma real.Gamma_one_half_eq : real.Gamma (1 / 2) = sqrt π :=
begin
rw [Gamma_eq_integral one_half_pos, ←integral_comp_rpow_Ioi_of_pos zero_lt_two],
convert congr_arg (λ x:ℝ, 2 * x) (integral_gaussian_Ioi 1),
{ rw ←integral_mul_left,
refine set_integral_congr measurable_set_Ioi (λ x hx, _),
dsimp only,
have : (x ^ (2:ℝ)) ^ (1 / (2:ℝ) - 1) = x⁻¹,
{ rw ←rpow_mul (le_of_lt hx),
norm_num,
rw [rpow_neg (le_of_lt hx), rpow_one] },
rw [smul_eq_mul, this],
field_simp [(ne_of_lt hx).symm],
norm_num, ring },
{ rw [div_one, ←mul_div_assoc, mul_comm, mul_div_cancel _ (two_ne_zero' ℝ)], }
end
/-- The special-value formula `Γ(1/2) = √π`, which is equivalent to the Gaussian integral. -/
lemma complex.Gamma_one_half_eq : complex.Gamma (1 / 2) = π ^ (1 / 2 : ℂ) :=
begin
convert congr_arg coe real.Gamma_one_half_eq,
{ simpa only [one_div, of_real_inv, of_real_bit0] using Gamma_of_real (1 / 2)},
{ rw [sqrt_eq_rpow, of_real_cpow pi_pos.le, of_real_div, of_real_bit0, of_real_one] }
end
namespace gaussian_fourier
/-! ## Fourier transform of the Gaussian integral
-/
open interval_integral
open_locale real
variables {b : ℂ}
/-- The integral of the Gaussian function over the vertical edges of a rectangle
with vertices at `(±T, 0)` and `(±T, c)`. -/
def vertical_integral (b : ℂ) (c T : ℝ) : ℂ :=
∫ (y : ℝ) in 0..c, I * (cexp (-b * (T + y * I) ^ 2) - cexp (-b * (T - y * I) ^ 2))
/-- Explicit formula for the norm of the Gaussian function along the vertical
edges. -/
lemma norm_cexp_neg_mul_sq_add_mul_I (b : ℂ) (c T : ℝ) :
‖cexp (-b * (T + c * I) ^ 2)‖ = exp (-(b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2)) :=
begin
rw [complex.norm_eq_abs, complex.abs_exp, neg_mul, neg_re, ←re_add_im b],
simp only [sq, re_add_im, mul_re, mul_im, add_re, add_im, of_real_re, of_real_im, I_re, I_im],
ring_nf,
end
lemma norm_cexp_neg_mul_sq_add_mul_I' (hb : b.re ≠ 0) (c T : ℝ) :
‖cexp (-b * (T + c * I) ^ 2)‖ =
exp (-(b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re))) :=
begin
have : (b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2) =
b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re),
{ field_simp, ring },
rw [norm_cexp_neg_mul_sq_add_mul_I, this],
end
lemma vertical_integral_norm_le (hb : 0 < b.re) (c : ℝ) {T : ℝ} (hT : 0 ≤ T) :
‖vertical_integral b c T‖
≤ 2 * |c| * exp (-(b.re * T ^ 2 - 2 * |b.im| * |c| * T - b.re * c ^ 2)) :=
begin
-- first get uniform bound for integrand
have vert_norm_bound : ∀ {T : ℝ}, 0 ≤ T → ∀ {c y : ℝ}, |y| ≤ |c| →
‖cexp (-b * (T + y * I) ^ 2)‖ ≤ exp (-(b.re * T ^ 2 - 2 * |b.im| * |c| * T - b.re * c ^ 2)),
{ intros T hT c y hy,
rw [norm_cexp_neg_mul_sq_add_mul_I b, exp_le_exp, neg_le_neg_iff],
refine sub_le_sub (sub_le_sub (le_refl _) (mul_le_mul_of_nonneg_right _ hT)) _,
{ conv_lhs {rw mul_assoc}, conv_rhs {rw mul_assoc},
refine mul_le_mul_of_nonneg_left ((le_abs_self _).trans _) zero_le_two,
rw abs_mul,
exact mul_le_mul_of_nonneg_left hy (abs_nonneg _), },
{ refine mul_le_mul_of_nonneg_left _ hb.le,
rwa sq_le_sq, } },
-- now main proof
refine (interval_integral.norm_integral_le_of_norm_le_const _).trans _,
swap 3,
{ rw sub_zero,
conv_lhs { rw mul_comm },
conv_rhs { conv { congr, rw mul_comm }, rw mul_assoc } },
{ intros y hy,
have absy : |y| ≤ |c|,
{ rcases le_or_lt 0 c,
{ rw uIoc_of_le h at hy,
rw [abs_of_nonneg h, abs_of_pos hy.1],
exact hy.2, },
{ rw uIoc_of_lt h at hy,
rw [abs_of_neg h, abs_of_nonpos hy.2, neg_le_neg_iff],
exact hy.1.le } },
rw [norm_mul, complex.norm_eq_abs, abs_I, one_mul, two_mul],
refine (norm_sub_le _ _).trans (add_le_add (vert_norm_bound hT absy) _),
rw ←abs_neg y at absy,
simpa only [neg_mul, of_real_neg] using vert_norm_bound hT absy },
end
lemma tendsto_vertical_integral (hb : 0 < b.re) (c : ℝ) :
tendsto (vertical_integral b c) at_top (𝓝 0) :=
begin
-- complete proof using squeeze theorem:
rw tendsto_zero_iff_norm_tendsto_zero,
refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds _
(eventually_of_forall (λ _, norm_nonneg _))
((eventually_ge_at_top (0:ℝ)).mp (eventually_of_forall
(λ T hT, vertical_integral_norm_le hb c hT))),
rw (by ring : 0 = 2 * |c| * 0),
refine (tendsto_exp_at_bot.comp (tendsto_neg_at_top_at_bot.comp _)).const_mul _ ,
apply tendsto_at_top_add_const_right,
simp_rw [sq, ←mul_assoc, ←sub_mul],
refine tendsto.at_top_mul_at_top (tendsto_at_top_add_const_right _ _ _) tendsto_id,
exact (tendsto_const_mul_at_top_of_pos hb).mpr tendsto_id,
end
lemma integrable_cexp_neg_mul_sq_add_real_mul_I (hb : 0 < b.re) (c : ℝ) :
integrable (λ (x : ℝ), cexp (-b * (x + c * I) ^ 2)) :=
begin
refine ⟨(complex.continuous_exp.comp (continuous_const.mul ((continuous_of_real.add
continuous_const).pow 2))).ae_strongly_measurable, _⟩,
rw ←has_finite_integral_norm_iff,
simp_rw [norm_cexp_neg_mul_sq_add_mul_I' hb.ne', neg_sub _ (c ^ 2 * _),
sub_eq_add_neg _ (b.re * _), real.exp_add],
suffices : integrable (λ (x : ℝ), exp (-(b.re * x ^ 2))),
{ exact (integrable.comp_sub_right this (b.im * c / b.re)).has_finite_integral.const_mul _, },
simp_rw ←neg_mul,
apply integrable_exp_neg_mul_sq hb,
end
lemma integral_cexp_neg_mul_sq_add_real_mul_I (hb : 0 < b.re) (c : ℝ) :
∫ (x : ℝ), cexp (-b * (x + c * I) ^ 2) = (π / b) ^ (1 / 2 : ℂ) :=
begin
refine tendsto_nhds_unique (interval_integral_tendsto_integral
(integrable_cexp_neg_mul_sq_add_real_mul_I hb c) tendsto_neg_at_top_at_bot tendsto_id) _,
set I₁ := (λ T, ∫ (x : ℝ) in -T..T, cexp (-b * (x + c * I) ^ 2)) with HI₁,
let I₂ := λ (T : ℝ), ∫ (x : ℝ) in -T..T, cexp (-b * x ^ 2),
let I₄ := λ (T : ℝ), ∫ (y : ℝ) in 0..c, cexp (-b * (T + y * I) ^ 2),
let I₅ := λ (T : ℝ), ∫ (y : ℝ) in 0..c, cexp (-b * (-T + y * I) ^ 2),
have C : ∀ (T : ℝ), I₂ T - I₁ T + I * I₄ T - I * I₅ T = 0,
{ assume T,
have := integral_boundary_rect_eq_zero_of_differentiable_on
(λ z, cexp (-b * z ^ 2)) (-T) (T + c * I)
(by { refine differentiable.differentiable_on (differentiable.const_mul _ _).cexp,
exact differentiable_pow 2, }),
simpa only [neg_im, of_real_im, neg_zero, of_real_zero, zero_mul, add_zero, neg_re, of_real_re,
add_re, mul_re, I_re, mul_zero, I_im, tsub_zero, add_im, mul_im, mul_one, zero_add,
algebra.id.smul_eq_mul, of_real_neg] using this },
simp_rw [id.def, ←HI₁],
have : I₁ = λ (T : ℝ), I₂ T + vertical_integral b c T,
{ ext1 T,
specialize C T,
rw sub_eq_zero at C,
unfold vertical_integral,
rw [integral_const_mul, interval_integral.integral_sub],
{ simp_rw (λ a b, by { rw sq, ring_nf } : ∀ (a b : ℂ), (a - b * I)^2 = (- a + b * I)^2),
change I₁ T = I₂ T + I * (I₄ T - I₅ T),
rw [mul_sub, ←C],
abel },
all_goals { apply continuous.interval_integrable, continuity }, },
rw [this, ←add_zero ((π / b : ℂ) ^ (1 / 2 : ℂ)), ←integral_gaussian_complex hb],
refine tendsto.add _ (tendsto_vertical_integral hb c),
exact interval_integral_tendsto_integral (integrable_cexp_neg_mul_sq hb)
tendsto_neg_at_top_at_bot tendsto_id,
end
lemma _root_.integral_cexp_neg_mul_sq_add_const (hb : 0 < b.re) (c : ℂ) :
∫ (x : ℝ), cexp (-b * (x + c) ^ 2) = (π / b) ^ (1 / 2 : ℂ) :=
begin
rw ←re_add_im c,
simp_rw [←add_assoc, ←of_real_add],
rw integral_add_right_eq_self (λ(x : ℝ), cexp (-b * (↑x + ↑(c.im) * I) ^ 2)),
{ apply integral_cexp_neg_mul_sq_add_real_mul_I hb },
{ apply_instance },
end
lemma _root_.fourier_transform_gaussian (hb : 0 < b.re) (t : ℂ) :
∫ (x : ℝ), cexp (I * t * x) * cexp (-b * x ^ 2) = cexp (-t^2 / (4 * b)) * (π / b) ^ (1 / 2 : ℂ) :=
begin
have : b ≠ 0,
{ contrapose! hb, rw [hb, zero_re] },
simp_rw [←complex.exp_add],
have : ∀ (x : ℂ), I * t * x + (-b * x ^ 2) = -t ^ 2 / (4 * b) + -b * (x + (-I * t / 2 / b)) ^ 2,
{ intro x,
ring_nf SOP,
rw I_sq,
field_simp, ring },
simp_rw [this, complex.exp_add, integral_mul_left, integral_cexp_neg_mul_sq_add_const hb]
end
lemma _root_.fourier_transform_gaussian_pi (hb : 0 < b.re) :
𝓕 (λ x : ℝ, cexp (-π * b * x ^ 2)) = λ t : ℝ, 1 / b ^ (1 / 2 : ℂ) * cexp (-π / b * t ^ 2) :=
begin
ext1 t,
simp_rw [fourier_integral_eq_integral_exp_smul, smul_eq_mul],
have h1 : 0 < re (π * b) := by { rw of_real_mul_re, exact mul_pos pi_pos hb },
have h2 : b ≠ 0 := by { contrapose! hb, rw [hb, zero_re], },
convert _root_.fourier_transform_gaussian h1 (-2 * π * t) using 1,
{ congr' 1 with x:1,
congr' 2,
all_goals { push_cast, ring } },
{ conv_lhs { rw mul_comm },
congr' 2,
{ field_simp [of_real_ne_zero.mpr pi_ne_zero], ring, },
{ rw [←div_div, div_self (of_real_ne_zero.mpr pi_ne_zero), one_div, one_div b, inv_cpow],
rw [ne.def, arg_eq_pi_iff, not_and_distrib, not_lt],
exact or.inl hb.le } },
end
end gaussian_fourier
section gaussian_poisson
/-! ## Poisson summation applied to the Gaussian -/
variables {E : Type*} [normed_add_comm_group E]
lemma tendsto_rpow_abs_mul_exp_neg_mul_sq_cocompact {a : ℝ} (ha : 0 < a) (s : ℝ) :
tendsto (λ x : ℝ, |x| ^ s * rexp (-a * x ^ 2)) (cocompact ℝ) (𝓝 0) :=
begin
conv in (rexp _) { rw ←sq_abs },
rw [cocompact_eq, ←comap_abs_at_top,
@tendsto_comap'_iff _ _ _ (λ y, y ^ s * rexp (-a * y ^ 2)) _ _ _
(mem_at_top_sets.mpr ⟨0, λ b hb, ⟨b, abs_of_nonneg hb⟩⟩)],
exact (rpow_mul_exp_neg_mul_sq_is_o_exp_neg ha s).tendsto_zero_of_tendsto
(tendsto_exp_at_bot.comp $ tendsto_id.neg_const_mul_at_top (neg_lt_zero.mpr one_half_pos)),
end
lemma is_o_exp_neg_mul_sq_cocompact {a : ℂ} (ha : 0 < a.re) (s : ℝ) :
(λ x : ℝ, complex.exp (-a * x ^ 2)) =o[cocompact ℝ] (λ x : ℝ, |x| ^ s) :=
begin
rw ←is_o_norm_left,
simp_rw norm_cexp_neg_mul_sq,
apply is_o_of_tendsto',
{ refine eventually.filter_mono cocompact_le_cofinite _,
refine (eventually_cofinite_ne 0).mp (eventually_of_forall (λ x hx h, _)),
exact ((rpow_pos_of_pos (abs_pos.mpr hx) _).ne' h).elim },
{ refine tendsto.congr' (eventually.filter_mono cocompact_le_cofinite _)
(tendsto_zero_iff_norm_tendsto_zero.mp $
tendsto_rpow_abs_mul_exp_neg_mul_sq_cocompact ha (-s)),
refine (eventually_cofinite_ne 0).mp (eventually_of_forall (λ x hx, _)),
rw [norm_mul, norm_of_nonneg (rpow_nonneg_of_nonneg (abs_nonneg _) _), mul_comm,
rpow_neg (abs_nonneg x), div_eq_mul_inv, norm_of_nonneg (exp_pos _).le] },
end
lemma complex.tsum_exp_neg_mul_int_sq {a : ℂ} (ha : 0 < a.re) :
∑' (n : ℤ), cexp (-π * a * n ^ 2) = 1 / a ^ (1 / 2 : ℂ) * ∑' (n : ℤ), cexp (-π / a * n ^ 2) :=
begin
let f := λ x : ℝ, cexp (-π * a * x ^ 2),
have h1 : 0 < (↑π * a).re,
{ rw [of_real_mul_re],
exact mul_pos pi_pos ha },
have h2 : 0 < (↑π / a).re,
{ rw [div_eq_mul_inv, of_real_mul_re, inv_re],
refine mul_pos pi_pos (div_pos ha $ norm_sq_pos.mpr _),
contrapose! ha,
rw [ha, zero_re] },
have f_bd : f =O[cocompact ℝ] (λ x, |x| ^ (-2 : ℝ)),
{ convert (is_o_exp_neg_mul_sq_cocompact h1 _).is_O,
ext1 x,
dsimp only [f],
congr' 1,
ring },
have Ff_bd : 𝓕 f =O[cocompact ℝ] (λ x, |x| ^ (-2 : ℝ)),
{ rw fourier_transform_gaussian_pi ha,
convert (is_o_exp_neg_mul_sq_cocompact h2 _).is_O.const_mul_left _,
ext1 x,
congr' 1,
ring_nf },
simpa only [fourier_transform_gaussian_pi ha, tsum_mul_left] using
real.tsum_eq_tsum_fourier_integral_of_rpow_decay
(complex.continuous_exp.comp (continuous_const.mul (continuous_of_real.pow 2)) : continuous f)
one_lt_two f_bd Ff_bd
end
lemma real.tsum_exp_neg_mul_int_sq {a : ℝ} (ha : 0 < a) :
∑' (n : ℤ), exp (-π * a * n ^ 2) = 1 / a ^ (1 / 2 : ℝ) * ∑' (n : ℤ), exp (-π / a * n ^ 2) :=
by simpa only [←of_real_inj, of_real_mul, of_real_tsum, of_real_exp, of_real_div, of_real_pow,
of_real_int_cast, of_real_neg, of_real_cpow ha.le, of_real_bit0, of_real_one] using
complex.tsum_exp_neg_mul_int_sq (by rwa [of_real_re] : 0 < (a : ℂ).re)
end gaussian_poisson
|
a476263e103ea4702dc52f16290d770699b77e07 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/ring_theory/subsemiring.lean | e8975cbdd08f795592e982a359d2ab89b7ef9428 | [
"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 | 34,468 | lean | /-
Copyright (c) 2020 Yury Kudryashov All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import algebra.ring.prod
import group_theory.submonoid
import group_theory.submonoid.center
import data.equiv.ring
/-!
# Bundled subsemirings
We define bundled subsemirings and some standard constructions: `complete_lattice` structure,
`subtype` and `inclusion` ring homomorphisms, subsemiring `map`, `comap` and range (`srange`) of
a `ring_hom` etc.
-/
open_locale big_operators
universes u v w
variables {R : Type u} {S : Type v} {T : Type w}
[non_assoc_semiring R] [non_assoc_semiring S] [non_assoc_semiring T]
(M : submonoid R)
set_option old_structure_cmd true
/-- A subsemiring of a semiring `R` is a subset `s` that is both a multiplicative and an additive
submonoid. -/
structure subsemiring (R : Type u) [non_assoc_semiring R] extends submonoid R, add_submonoid R
/-- Reinterpret a `subsemiring` as a `submonoid`. -/
add_decl_doc subsemiring.to_submonoid
/-- Reinterpret a `subsemiring` as an `add_submonoid`. -/
add_decl_doc subsemiring.to_add_submonoid
namespace subsemiring
instance : set_like (subsemiring R) R :=
⟨subsemiring.carrier, λ p q h, by cases p; cases q; congr'⟩
@[simp]
lemma mem_carrier {s : subsemiring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := iff.rfl
/-- Two subsemirings are equal if they have the same elements. -/
@[ext] theorem ext {S T : subsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := set_like.ext h
/-- Copy of a subsemiring with a new `carrier` equal to the old one. Useful to fix definitional
equalities.-/
protected def copy (S : subsemiring R) (s : set R) (hs : s = ↑S) : subsemiring R :=
{ carrier := s,
..S.to_add_submonoid.copy s hs,
..S.to_submonoid.copy s hs }
@[simp] lemma coe_copy (S : subsemiring R) (s : set R) (hs : s = ↑S) :
(S.copy s hs : set R) = s := rfl
lemma copy_eq (S : subsemiring R) (s : set R) (hs : s = ↑S) : S.copy s hs = S :=
set_like.coe_injective hs
lemma to_submonoid_injective : function.injective (to_submonoid : subsemiring R → submonoid R)
| r s h := ext (set_like.ext_iff.mp h : _)
@[mono] lemma to_submonoid_strict_mono : strict_mono (to_submonoid : subsemiring R → submonoid R) :=
λ _ _, id
@[mono] lemma to_submonoid_mono : monotone (to_submonoid : subsemiring R → submonoid R) :=
to_submonoid_strict_mono.monotone
lemma to_add_submonoid_injective :
function.injective (to_add_submonoid : subsemiring R → add_submonoid R)
| r s h := ext (set_like.ext_iff.mp h : _)
@[mono] lemma to_add_submonoid_strict_mono :
strict_mono (to_add_submonoid : subsemiring R → add_submonoid R) := λ _ _, id
@[mono]
lemma to_add_submonoid_mono : monotone (to_add_submonoid : subsemiring R → add_submonoid R) :=
to_add_submonoid_strict_mono.monotone
/-- Construct a `subsemiring R` from a set `s`, a submonoid `sm`, and an additive
submonoid `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/
protected def mk' (s : set R) (sm : submonoid R) (hm : ↑sm = s)
(sa : add_submonoid R) (ha : ↑sa = s) :
subsemiring R :=
{ carrier := s,
zero_mem' := ha ▸ sa.zero_mem,
one_mem' := hm ▸ sm.one_mem,
add_mem' := λ x y, by simpa only [← ha] using sa.add_mem,
mul_mem' := λ x y, by simpa only [← hm] using sm.mul_mem }
@[simp] lemma coe_mk' {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa = s) :
(subsemiring.mk' s sm hm sa ha : set R) = s := rfl
@[simp] lemma mem_mk' {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa = s) {x : R} :
x ∈ subsemiring.mk' s sm hm sa ha ↔ x ∈ s :=
iff.rfl
@[simp] lemma mk'_to_submonoid {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa = s) :
(subsemiring.mk' s sm hm sa ha).to_submonoid = sm :=
set_like.coe_injective hm.symm
@[simp] lemma mk'_to_add_submonoid {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa =s) :
(subsemiring.mk' s sm hm sa ha).to_add_submonoid = sa :=
set_like.coe_injective ha.symm
end subsemiring
namespace subsemiring
variables (s : subsemiring R)
/-- A subsemiring contains the semiring's 1. -/
theorem one_mem : (1 : R) ∈ s := s.one_mem'
/-- A subsemiring contains the semiring's 0. -/
theorem zero_mem : (0 : R) ∈ s := s.zero_mem'
/-- A subsemiring is closed under multiplication. -/
theorem mul_mem : ∀ {x y : R}, x ∈ s → y ∈ s → x * y ∈ s := s.mul_mem'
/-- A subsemiring is closed under addition. -/
theorem add_mem : ∀ {x y : R}, x ∈ s → y ∈ s → x + y ∈ s := s.add_mem'
/-- Product of a list of elements in a `subsemiring` is in the `subsemiring`. -/
lemma list_prod_mem {R : Type*} [semiring R] (s : subsemiring R) {l : list R} :
(∀x ∈ l, x ∈ s) → l.prod ∈ s :=
s.to_submonoid.list_prod_mem
/-- Sum of a list of elements in a `subsemiring` is in the `subsemiring`. -/
lemma list_sum_mem {l : list R} : (∀x ∈ l, x ∈ s) → l.sum ∈ s :=
s.to_add_submonoid.list_sum_mem
/-- Product of a multiset of elements in a `subsemiring` of a `comm_semiring`
is in the `subsemiring`. -/
lemma multiset_prod_mem {R} [comm_semiring R] (s : subsemiring R) (m : multiset R) :
(∀a ∈ m, a ∈ s) → m.prod ∈ s :=
s.to_submonoid.multiset_prod_mem m
/-- Sum of a multiset of elements in a `subsemiring` of a `semiring` is
in the `add_subsemiring`. -/
lemma multiset_sum_mem (m : multiset R) :
(∀a ∈ m, a ∈ s) → m.sum ∈ s :=
s.to_add_submonoid.multiset_sum_mem m
/-- Product of elements of a subsemiring of a `comm_semiring` indexed by a `finset` is in the
subsemiring. -/
lemma prod_mem {R : Type*} [comm_semiring R] (s : subsemiring R)
{ι : Type*} {t : finset ι} {f : ι → R} (h : ∀c ∈ t, f c ∈ s) :
∏ i in t, f i ∈ s :=
s.to_submonoid.prod_mem h
/-- Sum of elements in an `subsemiring` of an `semiring` indexed by a `finset`
is in the `add_subsemiring`. -/
lemma sum_mem (s : subsemiring R)
{ι : Type*} {t : finset ι} {f : ι → R} (h : ∀c ∈ t, f c ∈ s) :
∑ i in t, f i ∈ s :=
s.to_add_submonoid.sum_mem h
lemma pow_mem {R : Type*} [semiring R] (s : subsemiring R) {x : R} (hx : x ∈ s) (n : ℕ) :
x^n ∈ s := s.to_submonoid.pow_mem hx n
lemma nsmul_mem {x : R} (hx : x ∈ s) (n : ℕ) :
n • x ∈ s := s.to_add_submonoid.nsmul_mem hx n
lemma coe_nat_mem (n : ℕ) : (n : R) ∈ s :=
by simp only [← nsmul_one, nsmul_mem, one_mem]
/-- A subsemiring of a `non_assoc_semiring` inherits a `non_assoc_semiring` structure -/
instance to_non_assoc_semiring : non_assoc_semiring s :=
{ mul_zero := λ x, subtype.eq $ mul_zero x,
zero_mul := λ x, subtype.eq $ zero_mul x,
right_distrib := λ x y z, subtype.eq $ right_distrib x y z,
left_distrib := λ x y z, subtype.eq $ left_distrib x y z,
.. s.to_submonoid.to_mul_one_class, .. s.to_add_submonoid.to_add_comm_monoid }
@[simp, norm_cast] lemma coe_one : ((1 : s) : R) = (1 : R) := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : s) : R) = (0 : R) := rfl
@[simp, norm_cast] lemma coe_add (x y : s) : ((x + y : s) : R) = (x + y : R) := rfl
@[simp, norm_cast] lemma coe_mul (x y : s) : ((x * y : s) : R) = (x * y : R) := rfl
instance nontrivial [nontrivial R] : nontrivial s :=
nontrivial_of_ne 0 1 $ λ H, zero_ne_one (congr_arg subtype.val H)
instance no_zero_divisors [no_zero_divisors R] : no_zero_divisors s :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ x y h,
or.cases_on (eq_zero_or_eq_zero_of_mul_eq_zero $ subtype.ext_iff.mp h)
(λ h, or.inl $ subtype.eq h) (λ h, or.inr $ subtype.eq h) }
/-- A subsemiring of a `semiring` is a `semiring`. -/
instance to_semiring {R} [semiring R] (s : subsemiring R) : semiring s :=
{ ..s.to_non_assoc_semiring, ..s.to_submonoid.to_monoid }
@[simp, norm_cast] lemma coe_pow {R} [semiring R] (s : subsemiring R) (x : s) (n : ℕ) :
((x^n : s) : R) = (x^n : R) :=
begin
induction n with n ih,
{ simp, },
{ simp [pow_succ, ih], },
end
/-- A subsemiring of a `comm_semiring` is a `comm_semiring`. -/
instance to_comm_semiring {R} [comm_semiring R] (s : subsemiring R) : comm_semiring s :=
{ mul_comm := λ _ _, subtype.eq $ mul_comm _ _, ..s.to_semiring}
/-- The natural ring hom from a subsemiring of semiring `R` to `R`. -/
def subtype : s →+* R :=
{ to_fun := coe, .. s.to_submonoid.subtype, .. s.to_add_submonoid.subtype }
@[simp] theorem coe_subtype : ⇑s.subtype = coe := rfl
/-- A subsemiring of an `ordered_semiring` is an `ordered_semiring`. -/
instance to_ordered_semiring {R} [ordered_semiring R] (s : subsemiring R) : ordered_semiring s :=
subtype.coe_injective.ordered_semiring coe rfl rfl (λ _ _, rfl) (λ _ _, rfl)
/-- A subsemiring of an `ordered_comm_semiring` is an `ordered_comm_semiring`. -/
instance to_ordered_comm_semiring {R} [ordered_comm_semiring R] (s : subsemiring R) :
ordered_comm_semiring s :=
subtype.coe_injective.ordered_comm_semiring coe rfl rfl (λ _ _, rfl) (λ _ _, rfl)
/-- A subsemiring of a `linear_ordered_semiring` is a `linear_ordered_semiring`. -/
instance to_linear_ordered_semiring {R} [linear_ordered_semiring R] (s : subsemiring R) :
linear_ordered_semiring s :=
subtype.coe_injective.linear_ordered_semiring coe rfl rfl (λ _ _, rfl) (λ _ _, rfl)
/-! Note: currently, there is no `linear_ordered_comm_semiring`. -/
@[simp] lemma mem_to_submonoid {s : subsemiring R} {x : R} : x ∈ s.to_submonoid ↔ x ∈ s := iff.rfl
@[simp] lemma coe_to_submonoid (s : subsemiring R) : (s.to_submonoid : set R) = s := rfl
@[simp] lemma mem_to_add_submonoid {s : subsemiring R} {x : R} :
x ∈ s.to_add_submonoid ↔ x ∈ s := iff.rfl
@[simp] lemma coe_to_add_submonoid (s : subsemiring R) : (s.to_add_submonoid : set R) = s := rfl
/-- The subsemiring `R` of the semiring `R`. -/
instance : has_top (subsemiring R) :=
⟨{ .. (⊤ : submonoid R), .. (⊤ : add_submonoid R) }⟩
@[simp] lemma mem_top (x : R) : x ∈ (⊤ : subsemiring R) := set.mem_univ x
@[simp] lemma coe_top : ((⊤ : subsemiring R) : set R) = set.univ := rfl
/-- The preimage of a subsemiring along a ring homomorphism is a subsemiring. -/
def comap (f : R →+* S) (s : subsemiring S) : subsemiring R :=
{ carrier := f ⁻¹' s,
.. s.to_submonoid.comap (f : R →* S), .. s.to_add_submonoid.comap (f : R →+ S) }
@[simp] lemma coe_comap (s : subsemiring S) (f : R →+* S) : (s.comap f : set R) = f ⁻¹' s := rfl
@[simp]
lemma mem_comap {s : subsemiring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s := iff.rfl
lemma comap_comap (s : subsemiring T) (g : S →+* T) (f : R →+* S) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-- The image of a subsemiring along a ring homomorphism is a subsemiring. -/
def map (f : R →+* S) (s : subsemiring R) : subsemiring S :=
{ carrier := f '' s,
.. s.to_submonoid.map (f : R →* S), .. s.to_add_submonoid.map (f : R →+ S) }
@[simp] lemma coe_map (f : R →+* S) (s : subsemiring R) : (s.map f : set S) = f '' s := rfl
@[simp] lemma mem_map {f : R →+* S} {s : subsemiring R} {y : S} :
y ∈ s.map f ↔ ∃ x ∈ s, f x = y :=
set.mem_image_iff_bex
@[simp] lemma map_id : s.map (ring_hom.id R) = s :=
set_like.coe_injective $ set.image_id _
lemma map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) :=
set_like.coe_injective $ set.image_image _ _ _
lemma map_le_iff_le_comap {f : R →+* S} {s : subsemiring R} {t : subsemiring S} :
s.map f ≤ t ↔ s ≤ t.comap f :=
set.image_subset_iff
lemma gc_map_comap (f : R →+* S) : galois_connection (map f) (comap f) :=
λ S T, map_le_iff_le_comap
/-- A subsemiring is isomorphic to its image under an injective function -/
noncomputable def equiv_map_of_injective
(f : R →+* S) (hf : function.injective f) : s ≃+* s.map f :=
{ map_mul' := λ _ _, subtype.ext (f.map_mul _ _),
map_add' := λ _ _, subtype.ext (f.map_add _ _),
..equiv.set.image f s hf }
@[simp] lemma coe_equiv_map_of_injective_apply
(f : R →+* S) (hf : function.injective f) (x : s) :
(equiv_map_of_injective s f hf x : S) = f x := rfl
end subsemiring
namespace ring_hom
variables (g : S →+* T) (f : R →+* S)
/-- The range of a ring homomorphism is a subsemiring. See Note [range copy pattern]. -/
def srange : subsemiring S :=
((⊤ : subsemiring R).map f).copy (set.range f) set.image_univ.symm
@[simp] lemma coe_srange : (f.srange : set S) = set.range f := rfl
@[simp] lemma mem_srange {f : R →+* S} {y : S} : y ∈ f.srange ↔ ∃ x, f x = y :=
iff.rfl
lemma srange_eq_map (f : R →+* S) : f.srange = (⊤ : subsemiring R).map f :=
by { ext, simp }
lemma mem_srange_self (f : R →+* S) (x : R) : f x ∈ f.srange :=
mem_srange.mpr ⟨x, rfl⟩
lemma map_srange : f.srange.map g = (g.comp f).srange :=
by simpa only [srange_eq_map] using (⊤ : subsemiring R).map_map g f
/-- The range of a morphism of semirings is a fintype, if the domain is a fintype.
Note: this instance can form a diamond with `subtype.fintype` in the
presence of `fintype S`.-/
instance fintype_srange [fintype R] [decidable_eq S] (f : R →+* S) : fintype (srange f) :=
set.fintype_range f
end ring_hom
namespace subsemiring
instance : has_bot (subsemiring R) := ⟨(nat.cast_ring_hom R).srange⟩
instance : inhabited (subsemiring R) := ⟨⊥⟩
lemma coe_bot : ((⊥ : subsemiring R) : set R) = set.range (coe : ℕ → R) :=
(nat.cast_ring_hom R).coe_srange
lemma mem_bot {x : R} : x ∈ (⊥ : subsemiring R) ↔ ∃ n : ℕ, ↑n=x := ring_hom.mem_srange
/-- The inf of two subsemirings is their intersection. -/
instance : has_inf (subsemiring R) :=
⟨λ s t,
{ carrier := s ∩ t,
.. s.to_submonoid ⊓ t.to_submonoid,
.. s.to_add_submonoid ⊓ t.to_add_submonoid }⟩
@[simp] lemma coe_inf (p p' : subsemiring R) : ((p ⊓ p' : subsemiring R) : set R) = p ∩ p' := rfl
@[simp] lemma mem_inf {p p' : subsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl
instance : has_Inf (subsemiring R) :=
⟨λ s, subsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, subsemiring.to_submonoid t) (by simp)
(⨅ t ∈ s, subsemiring.to_add_submonoid t) (by simp)⟩
@[simp, norm_cast] lemma coe_Inf (S : set (subsemiring R)) :
((Inf S : subsemiring R) : set R) = ⋂ s ∈ S, ↑s := rfl
lemma mem_Inf {S : set (subsemiring R)} {x : R} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p := set.mem_bInter_iff
@[simp] lemma Inf_to_submonoid (s : set (subsemiring R)) :
(Inf s).to_submonoid = ⨅ t ∈ s, subsemiring.to_submonoid t :=
mk'_to_submonoid _ _
@[simp] lemma Inf_to_add_submonoid (s : set (subsemiring R)) :
(Inf s).to_add_submonoid = ⨅ t ∈ s, subsemiring.to_add_submonoid t :=
mk'_to_add_submonoid _ _
/-- Subsemirings of a semiring form a complete lattice. -/
instance : complete_lattice (subsemiring R) :=
{ bot := (⊥),
bot_le := λ s x hx, let ⟨n, hn⟩ := mem_bot.1 hx in hn ▸ s.coe_nat_mem n,
top := (⊤),
le_top := λ s x hx, trivial,
inf := (⊓),
inf_le_left := λ s t x, and.left,
inf_le_right := λ s t x, and.right,
le_inf := λ s t₁ t₂ h₁ h₂ x hx, ⟨h₁ hx, h₂ hx⟩,
.. complete_lattice_of_Inf (subsemiring R)
(λ s, is_glb.of_image (λ s t,
show (s : set R) ≤ t ↔ s ≤ t, from set_like.coe_subset_coe) is_glb_binfi)}
lemma eq_top_iff' (A : subsemiring R) : A = ⊤ ↔ ∀ x : R, x ∈ A :=
eq_top_iff.trans ⟨λ h m, h $ mem_top m, λ h m _, h m⟩
section
/-- The center of a semiring `R` is the set of elements that commute with everything in `R` -/
def center (R) [semiring R] : subsemiring R :=
{ carrier := set.center R,
zero_mem' := set.zero_mem_center R,
add_mem' := λ a b, set.add_mem_center,
.. submonoid.center R }
lemma coe_center (R) [semiring R] : ↑(center R) = set.center R := rfl
@[simp]
lemma center_to_submonoid (R) [semiring R] : (center R).to_submonoid = submonoid.center R := rfl
lemma mem_center_iff {R} [semiring R] {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g :=
iff.rfl
@[simp] lemma center_eq_top (R) [comm_semiring R] : center R = ⊤ :=
set_like.coe_injective (set.center_eq_univ R)
/-- The center is commutative. -/
instance {R} [semiring R] : comm_semiring (center R) :=
{ ..submonoid.center.comm_monoid,
..(center R).to_semiring}
end
/-- The `subsemiring` generated by a set. -/
def closure (s : set R) : subsemiring R := Inf {S | s ⊆ S}
lemma mem_closure {x : R} {s : set R} : x ∈ closure s ↔ ∀ S : subsemiring R, s ⊆ S → x ∈ S :=
mem_Inf
/-- The subsemiring generated by a set includes the set. -/
@[simp] lemma subset_closure {s : set R} : s ⊆ closure s := λ x hx, mem_closure.2 $ λ S hS, hS hx
lemma not_mem_of_not_mem_closure {s : set R} {P : R} (hP : P ∉ closure s) : P ∉ s :=
λ h, hP (subset_closure h)
/-- A subsemiring `S` includes `closure s` if and only if it includes `s`. -/
@[simp]
lemma closure_le {s : set R} {t : subsemiring R} : closure s ≤ t ↔ s ⊆ t :=
⟨set.subset.trans subset_closure, λ h, Inf_le h⟩
/-- Subsemiring closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/
lemma closure_mono ⦃s t : set R⦄ (h : s ⊆ t) : closure s ≤ closure t :=
closure_le.2 $ set.subset.trans h subset_closure
lemma closure_eq_of_le {s : set R} {t : subsemiring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) :
closure s = t :=
le_antisymm (closure_le.2 h₁) h₂
lemma mem_map_equiv {f : R ≃+* S} {K : subsemiring R} {x : S} :
x ∈ K.map (f : R →+* S) ↔ f.symm x ∈ K :=
@set.mem_image_equiv _ _ ↑K f.to_equiv x
lemma map_equiv_eq_comap_symm (f : R ≃+* S) (K : subsemiring R) :
K.map (f : R →+* S) = K.comap f.symm :=
set_like.coe_injective (f.to_equiv.image_eq_preimage K)
lemma comap_equiv_eq_map_symm (f : R ≃+* S) (K : subsemiring S) :
K.comap (f : R →+* S) = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
end subsemiring
namespace submonoid
/-- The additive closure of a submonoid is a subsemiring. -/
def subsemiring_closure (M : submonoid R) : subsemiring R :=
{ one_mem' := add_submonoid.mem_closure.mpr (λ y hy, hy M.one_mem),
mul_mem' := λ x y, M.mul_mem_add_closure,
..add_submonoid.closure (M : set R)}
lemma subsemiring_closure_coe :
(M.subsemiring_closure : set R) = add_submonoid.closure (M : set R) := rfl
lemma subsemiring_closure_to_add_submonoid :
M.subsemiring_closure.to_add_submonoid = add_submonoid.closure (M : set R) := rfl
/-- The `subsemiring` generated by a multiplicative submonoid coincides with the
`subsemiring.closure` of the submonoid itself . -/
lemma subsemiring_closure_eq_closure : M.subsemiring_closure = subsemiring.closure (M : set R) :=
begin
ext,
refine ⟨λ hx, _, λ hx, (subsemiring.mem_closure.mp hx) M.subsemiring_closure (λ s sM, _)⟩;
rintros - ⟨H1, rfl⟩;
rintros - ⟨H2, rfl⟩,
{ exact add_submonoid.mem_closure.mp hx H1.to_add_submonoid H2 },
{ exact H2 sM }
end
end submonoid
namespace subsemiring
@[simp]
lemma closure_submonoid_closure (s : set R) : closure ↑(submonoid.closure s) = closure s :=
le_antisymm
(closure_le.mpr (λ y hy, (submonoid.mem_closure.mp hy) (closure s).to_submonoid subset_closure))
(closure_mono (submonoid.subset_closure))
/-- The elements of the subsemiring closure of `M` are exactly the elements of the additive closure
of a multiplicative submonoid `M`. -/
lemma coe_closure_eq (s : set R) :
(closure s : set R) = add_submonoid.closure (submonoid.closure s : set R) :=
by simp [← submonoid.subsemiring_closure_to_add_submonoid, submonoid.subsemiring_closure_eq_closure]
lemma mem_closure_iff {s : set R} {x} :
x ∈ closure s ↔ x ∈ add_submonoid.closure (submonoid.closure s : set R) :=
set.ext_iff.mp (coe_closure_eq s) x
@[simp]
lemma closure_add_submonoid_closure {s : set R} : closure ↑(add_submonoid.closure s) = closure s :=
begin
ext x,
refine ⟨λ hx, _, λ hx, closure_mono add_submonoid.subset_closure hx⟩,
rintros - ⟨H, rfl⟩,
rintros - ⟨J, rfl⟩,
refine (add_submonoid.mem_closure.mp (mem_closure_iff.mp hx)) H.to_add_submonoid (λ y hy, _),
refine (submonoid.mem_closure.mp hy) H.to_submonoid (λ z hz, _),
exact (add_submonoid.mem_closure.mp hz) H.to_add_submonoid (λ w hw, J hw),
end
/-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements
of `s`, and is preserved under addition and multiplication, then `p` holds for all elements
of the closure of `s`. -/
@[elab_as_eliminator]
lemma closure_induction {s : set R} {p : R → Prop} {x} (h : x ∈ closure s)
(Hs : ∀ x ∈ s, p x) (H0 : p 0) (H1 : p 1)
(Hadd : ∀ x y, p x → p y → p (x + y)) (Hmul : ∀ x y, p x → p y → p (x * y)) : p x :=
(@closure_le _ _ _ ⟨p, H1, Hmul, H0, Hadd⟩).2 Hs h
lemma mem_closure_iff_exists_list {R} [semiring R] {s : set R} {x} : x ∈ closure s ↔
∃ L : list (list R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s) ∧ (L.map list.prod).sum = x :=
⟨λ hx, add_submonoid.closure_induction (mem_closure_iff.1 hx)
(λ x hx, suffices ∃ t : list R, (∀ y ∈ t, y ∈ s) ∧ t.prod = x,
from let ⟨t, ht1, ht2⟩ := this in ⟨[t], list.forall_mem_singleton.2 ht1,
by rw [list.map_singleton, list.sum_singleton, ht2]⟩,
submonoid.closure_induction hx
(λ x hx, ⟨[x], list.forall_mem_singleton.2 hx, one_mul x⟩)
⟨[], list.forall_mem_nil _, rfl⟩
(λ x y ⟨t, ht1, ht2⟩ ⟨u, hu1, hu2⟩, ⟨t ++ u, list.forall_mem_append.2 ⟨ht1, hu1⟩,
by rw [list.prod_append, ht2, hu2]⟩))
⟨[], list.forall_mem_nil _, rfl⟩
(λ x y ⟨L, HL1, HL2⟩ ⟨M, HM1, HM2⟩, ⟨L ++ M, list.forall_mem_append.2 ⟨HL1, HM1⟩,
by rw [list.map_append, list.sum_append, HL2, HM2]⟩),
λ ⟨L, HL1, HL2⟩, HL2 ▸ list_sum_mem _ (λ r hr, let ⟨t, ht1, ht2⟩ := list.mem_map.1 hr in
ht2 ▸ list_prod_mem _ (λ y hy, subset_closure $ HL1 t ht1 y hy))⟩
variable (R)
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : galois_insertion (@closure R _) coe :=
{ choice := λ s _, closure s,
gc := λ s t, closure_le,
le_l_u := λ s, subset_closure,
choice_eq := λ s h, rfl }
variable {R}
/-- Closure of a subsemiring `S` equals `S`. -/
lemma closure_eq (s : subsemiring R) : closure (s : set R) = s := (subsemiring.gi R).l_u_eq s
@[simp] lemma closure_empty : closure (∅ : set R) = ⊥ := (subsemiring.gi R).gc.l_bot
@[simp] lemma closure_univ : closure (set.univ : set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤
lemma closure_union (s t : set R) : closure (s ∪ t) = closure s ⊔ closure t :=
(subsemiring.gi R).gc.l_sup
lemma closure_Union {ι} (s : ι → set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(subsemiring.gi R).gc.l_supr
lemma closure_sUnion (s : set (set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t :=
(subsemiring.gi R).gc.l_Sup
lemma map_sup (s t : subsemiring R) (f : R →+* S) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
lemma map_supr {ι : Sort*} (f : R →+* S) (s : ι → subsemiring R) :
(supr s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_supr
lemma comap_inf (s t : subsemiring S) (f : R →+* S) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f :=
(gc_map_comap f).u_inf
lemma comap_infi {ι : Sort*} (f : R →+* S) (s : ι → subsemiring S) :
(infi s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_infi
@[simp] lemma map_bot (f : R →+* S) : (⊥ : subsemiring R).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma comap_top (f : R →+* S) : (⊤ : subsemiring S).comap f = ⊤ :=
(gc_map_comap f).u_top
/-- Given `subsemiring`s `s`, `t` of semirings `R`, `S` respectively, `s.prod t` is `s × t`
as a subsemiring of `R × S`. -/
def prod (s : subsemiring R) (t : subsemiring S) : subsemiring (R × S) :=
{ carrier := (s : set R).prod t,
.. s.to_submonoid.prod t.to_submonoid, .. s.to_add_submonoid.prod t.to_add_submonoid}
@[norm_cast]
lemma coe_prod (s : subsemiring R) (t : subsemiring S) :
(s.prod t : set (R × S)) = (s : set R).prod (t : set S) :=
rfl
lemma mem_prod {s : subsemiring R} {t : subsemiring S} {p : R × S} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl
@[mono] lemma prod_mono ⦃s₁ s₂ : subsemiring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : subsemiring S⦄
(ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ :=
set.prod_mono hs ht
lemma prod_mono_right (s : subsemiring R) : monotone (λ t : subsemiring S, s.prod t) :=
prod_mono (le_refl s)
lemma prod_mono_left (t : subsemiring S) : monotone (λ s : subsemiring R, s.prod t) :=
λ s₁ s₂ hs, prod_mono hs (le_refl t)
lemma prod_top (s : subsemiring R) :
s.prod (⊤ : subsemiring S) = s.comap (ring_hom.fst R S) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_fst]
lemma top_prod (s : subsemiring S) :
(⊤ : subsemiring R).prod s = s.comap (ring_hom.snd R S) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_snd]
@[simp]
lemma top_prod_top : (⊤ : subsemiring R).prod (⊤ : subsemiring S) = ⊤ :=
(top_prod _).trans $ comap_top _
/-- Product of subsemirings is isomorphic to their product as monoids. -/
def prod_equiv (s : subsemiring R) (t : subsemiring S) : s.prod t ≃+* s × t :=
{ map_mul' := λ x y, rfl, map_add' := λ x y, rfl, .. equiv.set.prod ↑s ↑t }
lemma mem_supr_of_directed {ι} [hι : nonempty ι] {S : ι → subsemiring R} (hS : directed (≤) S)
{x : R} :
x ∈ (⨆ i, S i) ↔ ∃ i, x ∈ S i :=
begin
refine ⟨_, λ ⟨i, hi⟩, (set_like.le_def.1 $ le_supr S i) hi⟩,
let U : subsemiring R := subsemiring.mk' (⋃ i, (S i : set R))
(⨆ i, (S i).to_submonoid) (submonoid.coe_supr_of_directed $ hS.mono_comp _ (λ _ _, id))
(⨆ i, (S i).to_add_submonoid) (add_submonoid.coe_supr_of_directed $ hS.mono_comp _ (λ _ _, id)),
suffices : (⨆ i, S i) ≤ U, by simpa using @this x,
exact supr_le (λ i x hx, set.mem_Union.2 ⟨i, hx⟩),
end
lemma coe_supr_of_directed {ι} [hι : nonempty ι] {S : ι → subsemiring R} (hS : directed (≤) S) :
((⨆ i, S i : subsemiring R) : set R) = ⋃ i, ↑(S i) :=
set.ext $ λ x, by simp [mem_supr_of_directed hS]
lemma mem_Sup_of_directed_on {S : set (subsemiring R)} (Sne : S.nonempty)
(hS : directed_on (≤) S) {x : R} :
x ∈ Sup S ↔ ∃ s ∈ S, x ∈ s :=
begin
haveI : nonempty S := Sne.to_subtype,
simp only [Sup_eq_supr', mem_supr_of_directed hS.directed_coe, set_coe.exists, subtype.coe_mk]
end
lemma coe_Sup_of_directed_on {S : set (subsemiring R)} (Sne : S.nonempty) (hS : directed_on (≤) S) :
(↑(Sup S) : set R) = ⋃ s ∈ S, ↑s :=
set.ext $ λ x, by simp [mem_Sup_of_directed_on Sne hS]
end subsemiring
namespace ring_hom
variables [non_assoc_semiring T] {s : subsemiring R}
open subsemiring
/-- Restriction of a ring homomorphism to a subsemiring of the domain. -/
def srestrict (f : R →+* S) (s : subsemiring R) : s →+* S := f.comp s.subtype
@[simp] lemma srestrict_apply (f : R →+* S) (x : s) : f.srestrict s x = f x := rfl
/-- Restriction of a ring homomorphism to a subsemiring of the codomain. -/
def cod_srestrict (f : R →+* S) (s : subsemiring S) (h : ∀ x, f x ∈ s) : R →+* s :=
{ to_fun := λ n, ⟨f n, h n⟩,
.. (f : R →* S).cod_mrestrict s.to_submonoid h,
.. (f : R →+ S).cod_mrestrict s.to_add_submonoid h }
/-- Restriction of a ring homomorphism to its range interpreted as a subsemiring.
This is the bundled version of `set.range_factorization`. -/
def srange_restrict (f : R →+* S) : R →+* f.srange :=
f.cod_srestrict f.srange f.mem_srange_self
@[simp] lemma coe_srange_restrict (f : R →+* S) (x : R) :
(f.srange_restrict x : S) = f x :=
rfl
lemma srange_restrict_surjective (f : R →+* S) : function.surjective f.srange_restrict :=
λ ⟨y, hy⟩, let ⟨x, hx⟩ := mem_srange.mp hy in ⟨x, subtype.ext hx⟩
lemma srange_top_iff_surjective {f : R →+* S} :
f.srange = (⊤ : subsemiring S) ↔ function.surjective f :=
set_like.ext'_iff.trans $ iff.trans (by rw [coe_srange, coe_top]) set.range_iff_surjective
/-- The range of a surjective ring homomorphism is the whole of the codomain. -/
lemma srange_top_of_surjective (f : R →+* S) (hf : function.surjective f) :
f.srange = (⊤ : subsemiring S) :=
srange_top_iff_surjective.2 hf
/-- The subsemiring of elements `x : R` such that `f x = g x` -/
def eq_slocus (f g : R →+* S) : subsemiring R :=
{ carrier := {x | f x = g x}, .. (f : R →* S).eq_mlocus g, .. (f : R →+ S).eq_mlocus g }
/-- If two ring homomorphisms are equal on a set, then they are equal on its subsemiring closure. -/
lemma eq_on_sclosure {f g : R →+* S} {s : set R} (h : set.eq_on f g s) :
set.eq_on f g (closure s) :=
show closure s ≤ f.eq_slocus g, from closure_le.2 h
lemma eq_of_eq_on_stop {f g : R →+* S} (h : set.eq_on f g (⊤ : subsemiring R)) :
f = g :=
ext $ λ x, h trivial
lemma eq_of_eq_on_sdense {s : set R} (hs : closure s = ⊤) {f g : R →+* S} (h : s.eq_on f g) :
f = g :=
eq_of_eq_on_stop $ hs ▸ eq_on_sclosure h
lemma sclosure_preimage_le (f : R →+* S) (s : set S) :
closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 $ λ x hx, set_like.mem_coe.2 $ mem_comap.2 $ subset_closure hx
/-- The image under a ring homomorphism of the subsemiring generated by a set equals
the subsemiring generated by the image of the set. -/
lemma map_sclosure (f : R →+* S) (s : set R) :
(closure s).map f = closure (f '' s) :=
le_antisymm
(map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _)
(sclosure_preimage_le _ _))
(closure_le.2 $ set.image_subset _ subset_closure)
end ring_hom
namespace subsemiring
open ring_hom
/-- The ring homomorphism associated to an inclusion of subsemirings. -/
def inclusion {S T : subsemiring R} (h : S ≤ T) : S →* T :=
S.subtype.cod_srestrict _ (λ x, h x.2)
@[simp] lemma srange_subtype (s : subsemiring R) : s.subtype.srange = s :=
set_like.coe_injective $ (coe_srange _).trans subtype.range_coe
@[simp]
lemma range_fst : (fst R S).srange = ⊤ :=
(fst R S).srange_top_of_surjective $ prod.fst_surjective
@[simp]
lemma range_snd : (snd R S).srange = ⊤ :=
(snd R S).srange_top_of_surjective $ prod.snd_surjective
@[simp]
lemma prod_bot_sup_bot_prod (s : subsemiring R) (t : subsemiring S) :
(s.prod ⊥) ⊔ (prod ⊥ t) = s.prod t :=
le_antisymm (sup_le (prod_mono_right s bot_le) (prod_mono_left t bot_le)) $
assume p hp, prod.fst_mul_snd p ▸ mul_mem _
((le_sup_left : s.prod ⊥ ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨hp.1, set_like.mem_coe.2 $ one_mem ⊥⟩)
((le_sup_right : prod ⊥ t ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨set_like.mem_coe.2 $ one_mem ⊥, hp.2⟩)
end subsemiring
namespace ring_equiv
variables {s t : subsemiring R}
/-- Makes the identity isomorphism from a proof two subsemirings of a multiplicative
monoid are equal. -/
def subsemiring_congr (h : s = t) : s ≃+* t :=
{ map_mul' := λ _ _, rfl, map_add' := λ _ _, rfl, ..equiv.set_congr $ congr_arg _ h }
/-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its
`ring_hom.srange`. -/
def sof_left_inverse {g : S → R} {f : R →+* S} (h : function.left_inverse g f) :
R ≃+* f.srange :=
{ to_fun := λ x, f.srange_restrict x,
inv_fun := λ x, (g ∘ f.srange.subtype) x,
left_inv := h,
right_inv := λ x, subtype.ext $
let ⟨x', hx'⟩ := ring_hom.mem_srange.mp x.prop in
show f (g x) = x, by rw [←hx', h x'],
..f.srange_restrict }
@[simp] lemma sof_left_inverse_apply
{g : S → R} {f : R →+* S} (h : function.left_inverse g f) (x : R) :
↑(sof_left_inverse h x) = f x := rfl
@[simp] lemma sof_left_inverse_symm_apply
{g : S → R} {f : R →+* S} (h : function.left_inverse g f) (x : f.srange) :
(sof_left_inverse h).symm x = g x := rfl
end ring_equiv
/-! ### Actions by `subsemiring`s
These are just copies of the definitions about `submonoid` starting from `submonoid.mul_action`.
The only new result is `subsemiring.module`.
When `R` is commutative, `algebra.of_subsemiring` provides a stronger result than those found in
this file, which uses the same scalar action.
-/
section actions
namespace subsemiring
variables {R' α β : Type*} [semiring R']
/-- The action by a subsemiring is the action by the underlying semiring. -/
instance [mul_action R' α] (S : subsemiring R') : mul_action S α :=
S.to_submonoid.mul_action
lemma smul_def [mul_action R' α] {S : subsemiring R'} (g : S) (m : α) : g • m = (g : R') • m := rfl
instance smul_comm_class_left
[mul_action R' β] [has_scalar α β] [smul_comm_class R' α β] (S : subsemiring R') :
smul_comm_class S α β :=
S.to_submonoid.smul_comm_class_left
instance smul_comm_class_right
[has_scalar α β] [mul_action R' β] [smul_comm_class α R' β] (S : subsemiring R') :
smul_comm_class α S β :=
S.to_submonoid.smul_comm_class_right
/-- Note that this provides `is_scalar_tower S R R` which is needed by `smul_mul_assoc`. -/
instance
[has_scalar α β] [mul_action R' α] [mul_action R' β] [is_scalar_tower R' α β]
(S : subsemiring R') :
is_scalar_tower S α β :=
S.to_submonoid.is_scalar_tower
instance [mul_action R' α] [has_faithful_scalar R' α] (S : subsemiring R') :
has_faithful_scalar S α :=
S.to_submonoid.has_faithful_scalar
/-- The action by a subsemiring is the action by the underlying semiring. -/
instance [add_monoid α] [distrib_mul_action R' α] (S : subsemiring R') : distrib_mul_action S α :=
S.to_submonoid.distrib_mul_action
/-- The action by a subsemiring is the action by the underlying semiring. -/
instance [monoid α] [mul_distrib_mul_action R' α] (S : subsemiring R') :
mul_distrib_mul_action S α :=
S.to_submonoid.mul_distrib_mul_action
/-- The action by a subsemiring is the action by the underlying semiring. -/
instance [add_comm_monoid α] [module R' α] (S : subsemiring R') : module S α :=
{ smul := (•), .. module.comp_hom _ S.subtype }
end subsemiring
end actions
-- While this definition is not about `subsemiring`s, this is the earliest we have
-- both `ordered_semiring` and `submonoid` available.
/-- Submonoid of positive elements of an ordered semiring. -/
def pos_submonoid (R : Type*) [ordered_semiring R] [nontrivial R] : submonoid R :=
{ carrier := {x | 0 < x},
one_mem' := show (0 : R) < 1, from zero_lt_one,
mul_mem' := λ x y (hx : 0 < x) (hy : 0 < y), mul_pos hx hy }
@[simp] lemma mem_pos_monoid {R : Type*} [ordered_semiring R] [nontrivial R] (u : units R) :
↑u ∈ pos_submonoid R ↔ (0 : R) < u := iff.rfl
|
48bad1e06921b4372381f7580f36cfaff48f98d2 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/quandle.lean | 50c82ac3cf1fd36d457413629902b895d20ede1e | [
"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 | 24,780 | lean | /-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import algebra.hom.equiv.basic
import algebra.hom.aut
import data.zmod.defs
import tactic.group
/-!
# Racks and Quandles
This file defines racks and quandles, algebraic structures for sets
that bijectively act on themselves with a self-distributivity
property. If `R` is a rack and `act : R → (R ≃ R)` is the self-action,
then the self-distributivity is, equivalently, that
```
act (act x y) = act x * act y * (act x)⁻¹
```
where multiplication is composition in `R ≃ R` as a group.
Quandles are racks such that `act x x = x` for all `x`.
One example of a quandle (not yet in mathlib) is the action of a Lie
algebra on itself, defined by `act x y = Ad (exp x) y`.
Quandles and racks were independently developed by multiple
mathematicians. David Joyce introduced quandles in his thesis
[Joyce1982] to define an algebraic invariant of knot and link
complements that is analogous to the fundamental group of the
exterior, and he showed that the quandle associated to an oriented
knot is invariant up to orientation-reversed mirror image. Racks were
used by Fenn and Rourke for framed codimension-2 knots and
links.[FennRourke1992]
The name "rack" came from wordplay by Conway and Wraith for the "wrack
and ruin" of forgetting everything but the conjugation operation for a
group.
## Main definitions
* `shelf` is a type with a self-distributive action
* `rack` is a shelf whose action for each element is invertible
* `quandle` is a rack whose action for an element fixes that element
* `quandle.conj` defines a quandle of a group acting on itself by conjugation.
* `shelf_hom` is homomorphisms of shelves, racks, and quandles.
* `rack.envel_group` gives the universal group the rack maps to as a conjugation quandle.
* `rack.opp` gives the rack with the action replaced by its inverse.
## Main statements
* `rack.envel_group` is left adjoint to `quandle.conj` (`to_envel_group.map`).
The universality statements are `to_envel_group.univ` and `to_envel_group.univ_uniq`.
## Notation
The following notation is localized in `quandles`:
* `x ◃ y` is `shelf.act x y`
* `x ◃⁻¹ y` is `rack.inv_act x y`
* `S →◃ S'` is `shelf_hom S S'`
Use `open_locale quandles` to use these.
## Todo
* If `g` is the Lie algebra of a Lie group `G`, then `(x ◃ y) = Ad (exp x) x` forms a quandle.
* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,
forming a quandle.
* Alexander quandle with `a ◃ b = t * b + (1 - t) * b`, with `a` and `b` elements
of a module over `Z[t,t⁻¹]`.
* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by
`yH ◃ xH = yzy⁻¹xH`. Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts
transitively on `Q` as a set) is isomorphic to such a quandle.
There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].
## Tags
rack, quandle
-/
open mul_opposite
universes u v
/--
A *shelf* is a structure with a self-distributive binary operation.
The binary operation is regarded as a left action of the type on itself.
-/
class shelf (α : Type u) :=
(act : α → α → α)
(self_distrib : ∀ {x y z : α}, act x (act y z) = act (act x y) (act x z))
/--
The type of homomorphisms between shelves.
This is also the notion of rack and quandle homomorphisms.
-/
@[ext]
structure shelf_hom (S₁ : Type*) (S₂ : Type*) [shelf S₁] [shelf S₂] :=
(to_fun : S₁ → S₂)
(map_act' : ∀ {x y : S₁}, to_fun (shelf.act x y) = shelf.act (to_fun x) (to_fun y))
/--
A *rack* is an automorphic set (a set with an action on itself by
bijections) that is self-distributive. It is a shelf such that each
element's action is invertible.
The notations `x ◃ y` and `x ◃⁻¹ y` denote the action and the
inverse action, respectively, and they are right associative.
-/
class rack (α : Type u) extends shelf α :=
(inv_act : α → α → α)
(left_inv : ∀ x, function.left_inverse (inv_act x) (act x))
(right_inv : ∀ x, function.right_inverse (inv_act x) (act x))
localized "infixr (name := shelf.act) ` ◃ `:65 := shelf.act" in quandles
localized "infixr (name := rack.inv_act) ` ◃⁻¹ `:65 := rack.inv_act" in quandles
localized "infixr (name := shelf_hom) ` →◃ `:25 := shelf_hom" in quandles
open_locale quandles
namespace rack
variables {R : Type*} [rack R]
lemma self_distrib {x y z : R} : x ◃ (y ◃ z) = (x ◃ y) ◃ (x ◃ z) :=
shelf.self_distrib
/--
A rack acts on itself by equivalences.
-/
def act (x : R) : R ≃ R :=
{ to_fun := shelf.act x,
inv_fun := inv_act x,
left_inv := left_inv x,
right_inv := right_inv x }
@[simp] lemma act_apply (x y : R) : act x y = x ◃ y := rfl
@[simp] lemma act_symm_apply (x y : R) : (act x).symm y = x ◃⁻¹ y := rfl
@[simp] lemma inv_act_apply (x y : R) : (act x)⁻¹ y = x ◃⁻¹ y := rfl
@[simp] lemma inv_act_act_eq (x y : R) : x ◃⁻¹ x ◃ y = y := left_inv x y
@[simp] lemma act_inv_act_eq (x y : R) : x ◃ x ◃⁻¹ y = y := right_inv x y
lemma left_cancel (x : R) {y y' : R} : x ◃ y = x ◃ y' ↔ y = y' :=
by { split, apply (act x).injective, rintro rfl, refl }
lemma left_cancel_inv (x : R) {y y' : R} : x ◃⁻¹ y = x ◃⁻¹ y' ↔ y = y' :=
by { split, apply (act x).symm.injective, rintro rfl, refl }
lemma self_distrib_inv {x y z : R} : x ◃⁻¹ y ◃⁻¹ z = (x ◃⁻¹ y) ◃⁻¹ (x ◃⁻¹ z) :=
begin
rw [←left_cancel (x ◃⁻¹ y), right_inv, ←left_cancel x, right_inv, self_distrib],
repeat {rw right_inv },
end
/--
The *adjoint action* of a rack on itself is `op'`, and the adjoint
action of `x ◃ y` is the conjugate of the action of `y` by the action
of `x`. It is another way to understand the self-distributivity axiom.
This is used in the natural rack homomorphism `to_conj` from `R` to
`conj (R ≃ R)` defined by `op'`.
-/
lemma ad_conj {R : Type*} [rack R] (x y : R) :
act (x ◃ y) = act x * act y * (act x)⁻¹ :=
begin
apply @mul_right_cancel _ _ _ (act x), ext z,
simp only [inv_mul_cancel_right],
apply self_distrib.symm,
end
/--
The opposite rack, swapping the roles of `◃` and `◃⁻¹`.
-/
instance opposite_rack : rack Rᵐᵒᵖ :=
{ act := λ x y, op (inv_act (unop x) (unop y)),
self_distrib := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, mul_opposite.rec $ λ z, begin
simp only [unop_op, op_inj],
exact self_distrib_inv,
end,
inv_act := λ x y, op (shelf.act (unop x) (unop y)),
left_inv := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, by simp,
right_inv := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, by simp }
@[simp] lemma op_act_op_eq {x y : R} : (op x) ◃ (op y) = op (x ◃⁻¹ y) := rfl
@[simp] lemma op_inv_act_op_eq {x y : R} : (op x) ◃⁻¹ (op y) = op (x ◃ y) := rfl
@[simp]
lemma self_act_act_eq {x y : R} : (x ◃ x) ◃ y = x ◃ y :=
by { rw [←right_inv x y, ←self_distrib] }
@[simp]
lemma self_inv_act_inv_act_eq {x y : R} : (x ◃⁻¹ x) ◃⁻¹ y = x ◃⁻¹ y :=
by { have h := @self_act_act_eq _ _ (op x) (op y), simpa using h }
@[simp]
lemma self_act_inv_act_eq {x y : R} : (x ◃ x) ◃⁻¹ y = x ◃⁻¹ y :=
by { rw ←left_cancel (x ◃ x), rw right_inv, rw self_act_act_eq, rw right_inv }
@[simp]
lemma self_inv_act_act_eq {x y : R} : (x ◃⁻¹ x) ◃ y = x ◃ y :=
by { have h := @self_act_inv_act_eq _ _ (op x) (op y), simpa using h }
lemma self_act_eq_iff_eq {x y : R} : x ◃ x = y ◃ y ↔ x = y :=
begin
split, swap, rintro rfl, refl,
intro h,
transitivity (x ◃ x) ◃⁻¹ (x ◃ x),
rw [←left_cancel (x ◃ x), right_inv, self_act_act_eq],
rw [h, ←left_cancel (y ◃ y), right_inv, self_act_act_eq],
end
lemma self_inv_act_eq_iff_eq {x y : R} : x ◃⁻¹ x = y ◃⁻¹ y ↔ x = y :=
by { have h := @self_act_eq_iff_eq _ _ (op x) (op y), simpa using h }
/--
The map `x ↦ x ◃ x` is a bijection. (This has applications for the
regular isotopy version of the Reidemeister I move for knot diagrams.)
-/
def self_apply_equiv (R : Type*) [rack R] : R ≃ R :=
{ to_fun := λ x, x ◃ x,
inv_fun := λ x, x ◃⁻¹ x,
left_inv := λ x, by simp,
right_inv := λ x, by simp }
/--
An involutory rack is one for which `rack.op R x` is an involution for every x.
-/
def is_involutory (R : Type*) [rack R] : Prop := ∀ x : R, function.involutive (shelf.act x)
lemma involutory_inv_act_eq_act {R : Type*} [rack R] (h : is_involutory R) (x y : R) :
x ◃⁻¹ y = x ◃ y :=
begin
rw [←left_cancel x, right_inv],
exact ((h x).left_inverse y).symm,
end
/--
An abelian rack is one for which the mediality axiom holds.
-/
def is_abelian (R : Type*) [rack R] : Prop :=
∀ (x y z w : R), (x ◃ y) ◃ (z ◃ w) = (x ◃ z) ◃ (y ◃ w)
/--
Associative racks are uninteresting.
-/
lemma assoc_iff_id {R : Type*} [rack R] {x y z : R} :
x ◃ y ◃ z = (x ◃ y) ◃ z ↔ x ◃ z = z :=
by { rw self_distrib, rw left_cancel }
end rack
namespace shelf_hom
variables {S₁ : Type*} {S₂ : Type*} {S₃ : Type*} [shelf S₁] [shelf S₂] [shelf S₃]
instance : has_coe_to_fun (S₁ →◃ S₂) (λ _, S₁ → S₂) := ⟨shelf_hom.to_fun⟩
@[simp] lemma to_fun_eq_coe (f : S₁ →◃ S₂) : f.to_fun = f := rfl
@[simp] lemma map_act (f : S₁ →◃ S₂) {x y : S₁} : f (x ◃ y) = f x ◃ f y := map_act' f
/-- The identity homomorphism -/
def id (S : Type*) [shelf S] : S →◃ S :=
{ to_fun := id,
map_act' := by simp }
instance inhabited (S : Type*) [shelf S] : inhabited (S →◃ S) :=
⟨id S⟩
/-- The composition of shelf homomorphisms -/
def comp (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) : S₁ →◃ S₃ :=
{ to_fun := g.to_fun ∘ f.to_fun,
map_act' := by simp }
@[simp]
lemma comp_apply (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) (x : S₁) :
(g.comp f) x = g (f x) := rfl
end shelf_hom
/--
A quandle is a rack such that each automorphism fixes its corresponding element.
-/
class quandle (α : Type*) extends rack α :=
(fix : ∀ {x : α}, act x x = x)
namespace quandle
open rack
variables {Q : Type*} [quandle Q]
attribute [simp] fix
@[simp]
lemma fix_inv {x : Q} : x ◃⁻¹ x = x :=
by { rw ←left_cancel x, simp }
instance opposite_quandle : quandle Qᵐᵒᵖ :=
{ fix := λ x, by { induction x using mul_opposite.rec, simp } }
/--
The conjugation quandle of a group. Each element of the group acts by
the corresponding inner automorphism.
-/
@[nolint has_nonempty_instance]
def conj (G : Type*) := G
instance conj.quandle (G : Type*) [group G] : quandle (conj G) :=
{ act := (λ x, @mul_aut.conj G _ x),
self_distrib := λ x y z, begin
dsimp only [mul_equiv.coe_to_equiv, mul_aut.conj_apply, conj],
group,
end,
inv_act := (λ x, (@mul_aut.conj G _ x).symm),
left_inv := λ x y, by { dsimp [act, conj], group },
right_inv := λ x y, by { dsimp [act, conj], group },
fix := λ x, by simp }
@[simp]
lemma conj_act_eq_conj {G : Type*} [group G] (x y : conj G) :
x ◃ y = ((x : G) * (y : G) * (x : G)⁻¹ : G) := rfl
lemma conj_swap {G : Type*} [group G] (x y : conj G) :
x ◃ y = y ↔ y ◃ x = x :=
begin
dsimp [conj] at *, split,
repeat { intro h, conv_rhs { rw eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h) }, simp, },
end
/--
`conj` is functorial
-/
def conj.map {G : Type*} {H : Type*} [group G] [group H] (f : G →* H) : conj G →◃ conj H :=
{ to_fun := f,
map_act' := by simp }
instance {G : Type*} {H : Type*} [group G] [group H] : has_lift (G →* H) (conj G →◃ conj H) :=
{ lift := conj.map }
/--
The dihedral quandle. This is the conjugation quandle of the dihedral group restrict to flips.
Used for Fox n-colorings of knots.
-/
@[nolint has_nonempty_instance]
def dihedral (n : ℕ) := zmod n
/--
The operation for the dihedral quandle. It does not need to be an equivalence
because it is an involution (see `dihedral_act.inv`).
-/
def dihedral_act (n : ℕ) (a : zmod n) : zmod n → zmod n :=
λ b, 2 * a - b
lemma dihedral_act.inv (n : ℕ) (a : zmod n) : function.involutive (dihedral_act n a) :=
by { intro b, dsimp [dihedral_act], ring }
instance (n : ℕ) : quandle (dihedral n) :=
{ act := dihedral_act n,
self_distrib := λ x y z, begin
dsimp [dihedral_act], ring,
end,
inv_act := dihedral_act n,
left_inv := λ x, (dihedral_act.inv n x).left_inverse,
right_inv := λ x, (dihedral_act.inv n x).right_inverse,
fix := λ x, begin
dsimp [dihedral_act], ring,
end }
end quandle
namespace rack
/--
This is the natural rack homomorphism to the conjugation quandle of the group `R ≃ R`
that acts on the rack.
-/
def to_conj (R : Type*) [rack R] : R →◃ quandle.conj (R ≃ R) :=
{ to_fun := act,
map_act' := ad_conj }
section envel_group
/-!
### Universal enveloping group of a rack
The universal enveloping group `envel_group R` of a rack `R` is the
universal group such that every rack homomorphism `R →◃ conj G` is
induced by a unique group homomorphism `envel_group R →* G`.
For quandles, Joyce called this group `AdConj R`.
The `envel_group` functor is left adjoint to the `conj` forgetful
functor, and the way we construct the enveloping group is via a
technique that should work for left adjoints of forgetful functors in
general. It involves thinking a little about 2-categories, but the
payoff is that the map `envel_group R →* G` has a nice description.
Let's think of a group as being a one-object category. The first step
is to define `pre_envel_group`, which gives formal expressions for all
the 1-morphisms and includes the unit element, elements of `R`,
multiplication, and inverses. To introduce relations, the second step
is to define `pre_envel_group_rel'`, which gives formal expressions
for all 2-morphisms between the 1-morphisms. The 2-morphisms include
associativity, multiplication by the unit, multiplication by inverses,
compatibility with multiplication and inverses (`congr_mul` and
`congr_inv`), the axioms for an equivalence relation, and,
importantly, the relationship between conjugation and the rack action
(see `rack.ad_conj`).
None of this forms a 2-category yet, for example due to lack of
associativity of `trans`. The `pre_envel_group_rel` relation is a
`Prop`-valued version of `pre_envel_group_rel'`, and making it
`Prop`-valued essentially introduces enough 3-isomorphisms so that
every pair of compatible 2-morphisms is isomorphic. Now, while
composition in `pre_envel_group` does not strictly satisfy the category
axioms, `pre_envel_group` and `pre_envel_group_rel'` do form a weak
2-category.
Since we just want a 1-category, the last step is to quotient
`pre_envel_group` by `pre_envel_group_rel'`, and the result is the
group `envel_group`.
For a homomorphism `f : R →◃ conj G`, how does
`envel_group.map f : envel_group R →* G` work? Let's think of `G` as
being a 2-category with one object, a 1-morphism per element of `G`,
and a single 2-morphism called `eq.refl` for each 1-morphism. We
define the map using a "higher `quotient.lift`" -- not only do we
evaluate elements of `pre_envel_group` as expressions in `G` (this is
`to_envel_group.map_aux`), but we evaluate elements of
`pre_envel_group'` as expressions of 2-morphisms of `G` (this is
`to_envel_group.map_aux.well_def`). That is to say,
`to_envel_group.map_aux.well_def` recursively evaluates formal
expressions of 2-morphisms as equality proofs in `G`. Now that all
morphisms are accounted for, the map descends to a homomorphism
`envel_group R →* G`.
Note: `Type`-valued relations are not common. The fact it is
`Type`-valued is what makes `to_envel_group.map_aux.well_def` have
well-founded recursion.
-/
/--
Free generators of the enveloping group.
-/
inductive pre_envel_group (R : Type u) : Type u
| unit : pre_envel_group
| incl (x : R) : pre_envel_group
| mul (a b : pre_envel_group) : pre_envel_group
| inv (a : pre_envel_group) : pre_envel_group
instance pre_envel_group.inhabited (R : Type u) : inhabited (pre_envel_group R) :=
⟨pre_envel_group.unit⟩
open pre_envel_group
/--
Relations for the enveloping group. This is a type-valued relation because
`to_envel_group.map_aux.well_def` inducts on it to show `to_envel_group.map`
is well-defined. The relation `pre_envel_group_rel` is the `Prop`-valued version,
which is used to define `envel_group` itself.
-/
inductive pre_envel_group_rel' (R : Type u) [rack R] :
pre_envel_group R → pre_envel_group R → Type u
| refl {a : pre_envel_group R} : pre_envel_group_rel' a a
| symm {a b : pre_envel_group R} (hab : pre_envel_group_rel' a b) : pre_envel_group_rel' b a
| trans {a b c : pre_envel_group R}
(hab : pre_envel_group_rel' a b) (hbc : pre_envel_group_rel' b c) : pre_envel_group_rel' a c
| congr_mul {a b a' b' : pre_envel_group R}
(ha : pre_envel_group_rel' a a') (hb : pre_envel_group_rel' b b') :
pre_envel_group_rel' (mul a b) (mul a' b')
| congr_inv {a a' : pre_envel_group R} (ha : pre_envel_group_rel' a a') :
pre_envel_group_rel' (inv a) (inv a')
| assoc (a b c : pre_envel_group R) : pre_envel_group_rel' (mul (mul a b) c) (mul a (mul b c))
| one_mul (a : pre_envel_group R) : pre_envel_group_rel' (mul unit a) a
| mul_one (a : pre_envel_group R) : pre_envel_group_rel' (mul a unit) a
| mul_left_inv (a : pre_envel_group R) : pre_envel_group_rel' (mul (inv a) a) unit
| act_incl (x y : R) :
pre_envel_group_rel' (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x ◃ y))
instance pre_envel_group_rel'.inhabited (R : Type u) [rack R] :
inhabited (pre_envel_group_rel' R unit unit) :=
⟨pre_envel_group_rel'.refl⟩
/--
The `pre_envel_group_rel` relation as a `Prop`. Used as the relation for `pre_envel_group.setoid`.
-/
inductive pre_envel_group_rel (R : Type u) [rack R] : pre_envel_group R → pre_envel_group R → Prop
| rel {a b : pre_envel_group R} (r : pre_envel_group_rel' R a b) : pre_envel_group_rel a b
/--
A quick way to convert a `pre_envel_group_rel'` to a `pre_envel_group_rel`.
-/
lemma pre_envel_group_rel'.rel {R : Type u} [rack R] {a b : pre_envel_group R} :
pre_envel_group_rel' R a b → pre_envel_group_rel R a b :=
pre_envel_group_rel.rel
@[refl]
lemma pre_envel_group_rel.refl {R : Type u} [rack R] {a : pre_envel_group R} :
pre_envel_group_rel R a a :=
pre_envel_group_rel.rel pre_envel_group_rel'.refl
@[symm]
lemma pre_envel_group_rel.symm {R : Type u} [rack R] {a b : pre_envel_group R} :
pre_envel_group_rel R a b → pre_envel_group_rel R b a
| ⟨r⟩ := r.symm.rel
@[trans]
lemma pre_envel_group_rel.trans {R : Type u} [rack R] {a b c : pre_envel_group R} :
pre_envel_group_rel R a b → pre_envel_group_rel R b c → pre_envel_group_rel R a c
| ⟨rab⟩ ⟨rbc⟩ := (rab.trans rbc).rel
instance pre_envel_group.setoid (R : Type*) [rack R] : setoid (pre_envel_group R) :=
{ r := pre_envel_group_rel R,
iseqv := begin
split, apply pre_envel_group_rel.refl,
split, apply pre_envel_group_rel.symm,
apply pre_envel_group_rel.trans
end }
/--
The universal enveloping group for the rack R.
-/
def envel_group (R : Type*) [rack R] := quotient (pre_envel_group.setoid R)
-- Define the `group` instances in two steps so `inv` can be inferred correctly.
-- TODO: is there a non-invasive way of defining the instance directly?
instance (R : Type*) [rack R] : div_inv_monoid (envel_group R) :=
{ mul := λ a b, quotient.lift_on₂ a b
(λ a b, ⟦pre_envel_group.mul a b⟧)
(λ a b a' b' ⟨ha⟩ ⟨hb⟩,
quotient.sound (pre_envel_group_rel'.congr_mul ha hb).rel),
one := ⟦unit⟧,
inv := λ a, quotient.lift_on a
(λ a, ⟦pre_envel_group.inv a⟧)
(λ a a' ⟨ha⟩,
quotient.sound (pre_envel_group_rel'.congr_inv ha).rel),
mul_assoc := λ a b c,
quotient.induction_on₃ a b c (λ a b c, quotient.sound (pre_envel_group_rel'.assoc a b c).rel),
one_mul := λ a,
quotient.induction_on a (λ a, quotient.sound (pre_envel_group_rel'.one_mul a).rel),
mul_one := λ a,
quotient.induction_on a (λ a, quotient.sound (pre_envel_group_rel'.mul_one a).rel),}
instance (R : Type*) [rack R] : group (envel_group R) :=
{ mul_left_inv := λ a,
quotient.induction_on a (λ a, quotient.sound (pre_envel_group_rel'.mul_left_inv a).rel),
.. envel_group.div_inv_monoid _ }
instance envel_group.inhabited (R : Type*) [rack R] : inhabited (envel_group R) := ⟨1⟩
/--
The canonical homomorphism from a rack to its enveloping group.
Satisfies universal properties given by `to_envel_group.map` and `to_envel_group.univ`.
-/
def to_envel_group (R : Type*) [rack R] : R →◃ quandle.conj (envel_group R) :=
{ to_fun := λ x, ⟦incl x⟧,
map_act' := λ x y, quotient.sound (pre_envel_group_rel'.act_incl x y).symm.rel }
/--
The preliminary definition of the induced map from the enveloping group.
See `to_envel_group.map`.
-/
def to_envel_group.map_aux {R : Type*} [rack R] {G : Type*} [group G]
(f : R →◃ quandle.conj G) : pre_envel_group R → G
| unit := 1
| (incl x) := f x
| (mul a b) := to_envel_group.map_aux a * to_envel_group.map_aux b
| (inv a) := (to_envel_group.map_aux a)⁻¹
namespace to_envel_group.map_aux
open pre_envel_group_rel'
/--
Show that `to_envel_group.map_aux` sends equivalent expressions to equal terms.
-/
lemma well_def {R : Type*} [rack R] {G : Type*} [group G] (f : R →◃ quandle.conj G) :
Π {a b : pre_envel_group R}, pre_envel_group_rel' R a b →
to_envel_group.map_aux f a = to_envel_group.map_aux f b
| a b refl := rfl
| a b (symm h) := (well_def h).symm
| a b (trans hac hcb) := eq.trans (well_def hac) (well_def hcb)
| _ _ (congr_mul ha hb) := by { simp [to_envel_group.map_aux, well_def ha, well_def hb] }
| _ _ (congr_inv ha) := by { simp [to_envel_group.map_aux, well_def ha] }
| _ _ (assoc a b c) := by { apply mul_assoc }
| _ _ (one_mul a) := by { simp [to_envel_group.map_aux] }
| _ _ (mul_one a) := by { simp [to_envel_group.map_aux] }
| _ _ (mul_left_inv a) := by { simp [to_envel_group.map_aux] }
| _ _ (act_incl x y) := by { simp [to_envel_group.map_aux] }
end to_envel_group.map_aux
/--
Given a map from a rack to a group, lift it to being a map from the enveloping group.
More precisely, the `envel_group` functor is left adjoint to `quandle.conj`.
-/
def to_envel_group.map {R : Type*} [rack R] {G : Type*} [group G] :
(R →◃ quandle.conj G) ≃ (envel_group R →* G) :=
{ to_fun := λ f,
{ to_fun := λ x, quotient.lift_on x (to_envel_group.map_aux f)
(λ a b ⟨hab⟩, to_envel_group.map_aux.well_def f hab),
map_one' := begin
change quotient.lift_on ⟦rack.pre_envel_group.unit⟧ (to_envel_group.map_aux f) _ = 1,
simp [to_envel_group.map_aux],
end,
map_mul' := λ x y, quotient.induction_on₂ x y (λ x y, begin
change quotient.lift_on ⟦mul x y⟧ (to_envel_group.map_aux f) _ = _,
simp [to_envel_group.map_aux],
end) },
inv_fun := λ F, (quandle.conj.map F).comp (to_envel_group R),
left_inv := λ f, by { ext, refl },
right_inv := λ F, monoid_hom.ext $ λ x, quotient.induction_on x $ λ x, begin
induction x,
{ exact F.map_one.symm, },
{ refl, },
{ have hm : ⟦x_a.mul x_b⟧ = @has_mul.mul (envel_group R) _ ⟦x_a⟧ ⟦x_b⟧ := rfl,
rw [hm, F.map_mul, monoid_hom.map_mul, ←x_ih_a, ←x_ih_b] },
{ have hm : ⟦x_a.inv⟧ = @has_inv.inv (envel_group R) _ ⟦x_a⟧ := rfl,
rw [hm, F.map_inv, monoid_hom.map_inv, x_ih], }
end, }
/--
Given a homomorphism from a rack to a group, it factors through the enveloping group.
-/
lemma to_envel_group.univ (R : Type*) [rack R] (G : Type*) [group G]
(f : R →◃ quandle.conj G) :
(quandle.conj.map (to_envel_group.map f)).comp (to_envel_group R) = f :=
to_envel_group.map.symm_apply_apply f
/--
The homomorphism `to_envel_group.map f` is the unique map that fits into the commutative
triangle in `to_envel_group.univ`.
-/
lemma to_envel_group.univ_uniq (R : Type*) [rack R] (G : Type*) [group G]
(f : R →◃ quandle.conj G)
(g : envel_group R →* G) (h : f = (quandle.conj.map g).comp (to_envel_group R)) :
g = to_envel_group.map f :=
h.symm ▸ (to_envel_group.map.apply_symm_apply g).symm
/--
The induced group homomorphism from the enveloping group into bijections of the rack,
using `rack.to_conj`. Satisfies the property `envel_action_prop`.
This gives the rack `R` the structure of an augmented rack over `envel_group R`.
-/
def envel_action {R : Type*} [rack R] : envel_group R →* (R ≃ R) :=
to_envel_group.map (to_conj R)
@[simp]
lemma envel_action_prop {R : Type*} [rack R] (x y : R) :
envel_action (to_envel_group R x) y = x ◃ y := rfl
end envel_group
end rack
|
9b3e9d36851b4f3b401bc20a9e0c3e2c15893b43 | 159fed64bfae88f3b6a6166836d6278f953bcbf9 | /Structure/Generic/Axioms/AbstractEquivalences.lean | 9ef0ef531a7631e21ead3c295db351a4ac4bd343 | [
"MIT"
] | permissive | SReichelt/lean4-experiments | 3e56830c8b2fbe3814eda071c48e3c8810d254a8 | ff55357a01a34a91bf670d712637480089085ee4 | refs/heads/main | 1,683,977,454,907 | 1,622,991,121,000 | 1,622,991,121,000 | 340,765,677 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 15,318 | lean | import Structure.Generic.Axioms.Universes
import Structure.Generic.Axioms.AbstractFunctors
import mathlib4_experiments.Data.Equiv.Basic
set_option autoBoundImplicitLocal false
--set_option pp.universes true
universes u v
class HasExternalEquivalences (U : Universe.{u}) (V : Universe.{v})
[hUV : HasExternalFunctors U V] [hVU : HasExternalFunctors V U] : Type (max u v) where
(IsEquiv {α : U} {β : V} : (α ⟶' β) → (β ⟶' α) → Sort (max u v))
structure BundledEquivalence {U : Universe.{u}} {V : Universe.{v}}
[hUV : HasExternalFunctors U V] [hVU : HasExternalFunctors V U]
[h : HasExternalEquivalences U V]
(α : U) (β : V) : Sort (max 1 u v) where
(toFun : α ⟶' β)
(invFun : β ⟶' α)
(isEquiv : h.IsEquiv toFun invFun)
namespace BundledEquivalence
infix:20 " ⟷' " => BundledEquivalence
variable {U V : Universe} [hUV : HasExternalFunctors U V] [hVU : HasExternalFunctors V U]
[h : HasExternalEquivalences U V]
def mkEquiv {α : U} {β : V} {to : α ⟶' β} {inv : β ⟶' α} (he : h.IsEquiv to inv) : α ⟷' β :=
⟨to, inv, he⟩
end BundledEquivalence
class HasInternalEquivalences (U : Universe.{u}) [h : HasInternalFunctors U] extends HasExternalEquivalences U U : Type u where
(Equiv : U → U → U)
(equivEquiv (α β : U) : ⌈Equiv α β⌉ ≃ (α ⟷' β))
(equivElimToFunIsFun (α β : U) : h.IsFun (λ E : Equiv α β => HasInternalFunctors.fromBundled ((equivEquiv α β).toFun E).toFun))
(equivElimInvFunIsFun (α β : U) : h.IsFun (λ E : Equiv α β => HasInternalFunctors.fromBundled ((equivEquiv α β).toFun E).invFun))
namespace HasInternalEquivalences
infix:20 " ⟷ " => HasInternalEquivalences.Equiv
variable {U : Universe} [HasInternalFunctors U] [h : HasInternalEquivalences U]
def toBundled {α β : U} (E : α ⟷ β) : α ⟷' β := (h.equivEquiv α β).toFun E
def fromBundled {α β : U} (E : α ⟷' β) : α ⟷ β := (h.equivEquiv α β).invFun E
@[simp] theorem fromToBundled {α β : U} (E : α ⟷ β) : fromBundled (toBundled E) = E :=
(h.equivEquiv α β).leftInv E
@[simp] theorem toFromBundled {α β : U} (E : α ⟷' β) : toBundled (fromBundled E) = E :=
(h.equivEquiv α β).rightInv E
def to {α β : U} (E : α ⟷ β) (a : α) : β := (toBundled E).toFun a
def inv {α β : U} (E : α ⟷ β) (b : β) : α := (toBundled E).invFun b
def toFun {α β : U} (E : α ⟷ β) : α ⟶ β := HasInternalFunctors.fromBundled (toBundled E).toFun
def invFun {α β : U} (E : α ⟷ β) : β ⟶ α := HasInternalFunctors.fromBundled (toBundled E).invFun
@[simp] theorem toFun.eff {α β : U} (E : α ⟷ β) (a : α) : (toFun E) a = to E a :=
by apply HasInternalFunctors.fromBundled.eff
@[simp] theorem invFun.eff {α β : U} (E : α ⟷ β) (b : β) : (invFun E) b = inv E b :=
by apply HasInternalFunctors.fromBundled.eff
def toFunFun' (α β : U) : (α ⟷ β) ⟶' (α ⟶ β) := BundledFunctor.mkFun (h.equivElimToFunIsFun α β)
def invFunFun' (α β : U) : (α ⟷ β) ⟶' (β ⟶ α) := BundledFunctor.mkFun (h.equivElimInvFunIsFun α β)
def toFunFun (α β : U) : (α ⟷ β) ⟶ (α ⟶ β) := HasInternalFunctors.fromBundled (toFunFun' α β)
def invFunFun (α β : U) : (α ⟷ β) ⟶ (β ⟶ α) := HasInternalFunctors.fromBundled (invFunFun' α β)
@[simp] theorem toFunFun.eff {α β : U} (E : α ⟷ β) : (toFunFun α β) E = toFun E :=
by apply HasInternalFunctors.fromBundled.eff
@[simp] theorem invFunFun.eff {α β : U} (E : α ⟷ β) : (invFunFun α β) E = invFun E :=
by apply HasInternalFunctors.fromBundled.eff
@[simp] theorem toFunFun.effEff {α β : U} (E : α ⟷ β) (a : α) : ((toFunFun α β) E) a = to E a :=
by simp
@[simp] theorem invFunFun.effEff {α β : U} (E : α ⟷ β) (b : β) : ((invFunFun α β) E) b = inv E b :=
by simp
@[simp] theorem toFun.bundledEq {α β : U} (E : α ⟷ β) : HasInternalFunctors.toBundled (toFun E) = (toBundled E).toFun :=
HasInternalFunctors.toFromBundled (toBundled E).toFun
@[simp] theorem invFun.bundledEq {α β : U} (E : α ⟷ β) : HasInternalFunctors.toBundled (invFun E) = (toBundled E).invFun :=
HasInternalFunctors.toFromBundled (toBundled E).invFun
def isEquiv {α β : U} (E : α ⟷ β) : h.IsEquiv (toBundled E).toFun (toBundled E).invFun :=
(toBundled E).isEquiv
def isEquiv' {α β : U} (E : α ⟷ β) :
h.IsEquiv (HasInternalFunctors.toBundled (toFun E)) (HasInternalFunctors.toBundled (invFun E)) :=
by simp; apply isEquiv
@[simp] theorem fromBundled.to.coe' {α β : U} (E : α ⟷' β) : (toBundled (fromBundled E)).toFun = E.toFun :=
congrArg BundledEquivalence.toFun (toFromBundled E)
@[simp] theorem fromBundled.inv.coe' {α β : U} (E : α ⟷' β) : (toBundled (fromBundled E)).invFun = E.invFun :=
congrArg BundledEquivalence.invFun (toFromBundled E)
@[simp] theorem fromBundled.to.coe {α β : U} (E : α ⟷' β) : (toBundled (fromBundled E)).toFun.f = E.toFun.f :=
congrArg BundledFunctor.f (fromBundled.to.coe' E)
@[simp] theorem fromBundled.inv.coe {α β : U} (E : α ⟷' β) : (toBundled (fromBundled E)).invFun.f = E.invFun.f :=
congrArg BundledFunctor.f (fromBundled.inv.coe' E)
@[simp] theorem fromBundled.to.eff {α β : U} (E : α ⟷' β) (a : α) : to (fromBundled E) a = E.toFun a :=
congrFun (fromBundled.to.coe E) a
@[simp] theorem fromBundled.inv.eff {α β : U} (E : α ⟷' β) (b : β) : inv (fromBundled E) b = E.invFun b :=
congrFun (fromBundled.inv.coe E) b
def mkEquiv {α β : U} {to : α ⟶' β} {inv : β ⟶' α} (he : h.IsEquiv to inv) : α ⟷ β :=
fromBundled (BundledEquivalence.mkEquiv he)
end HasInternalEquivalences
class HasIdEquiv (U : Universe) [HasExternalFunctors U U] [HasIdFun U] [h : HasExternalEquivalences U U] where
(idIsEquiv (α : U) : h.IsEquiv (HasIdFun.idFun' α) (HasIdFun.idFun' α))
namespace HasIdEquiv
variable {U : Universe} [HasExternalFunctors U U] [HasIdFun U] [HasExternalEquivalences U U] [h : HasIdEquiv U]
def idEquiv' (α : U) : α ⟷' α := BundledEquivalence.mkEquiv (h.idIsEquiv α)
end HasIdEquiv
class HasCompEquiv (U V W : Universe)
[HasExternalFunctors U V] [HasExternalFunctors V W] [HasExternalFunctors U W]
[HasExternalFunctors V U] [HasExternalFunctors W V] [HasExternalFunctors W U]
[HasCompFun U V W] [HasCompFun W V U]
[HasExternalEquivalences U V] [HasExternalEquivalences V W] [h : HasExternalEquivalences U W] where
(compIsEquiv {α : U} {β : V} {γ : W} (E : α ⟷' β) (F : β ⟷' γ) : h.IsEquiv (F.toFun ⊙' E.toFun) (E.invFun ⊙' F.invFun))
namespace HasCompEquiv
variable {U V W : Universe} [HasExternalFunctors U V] [HasExternalFunctors V W] [HasExternalFunctors U W]
[HasExternalFunctors V U] [HasExternalFunctors W V] [HasExternalFunctors W U]
[HasCompFun U V W] [HasCompFun W V U]
[HasExternalEquivalences U V] [HasExternalEquivalences V W] [HasExternalEquivalences U W]
[h : HasCompEquiv U V W]
def compEquiv' {α : U} {β : V} {γ : W} (E : α ⟷' β) (F : β ⟷' γ) : α ⟷' γ := BundledEquivalence.mkEquiv (h.compIsEquiv E F)
end HasCompEquiv
class HasInvEquiv (U V : Universe) [HasExternalFunctors U V] [HasExternalFunctors V U]
[HasExternalEquivalences U V] [h : HasExternalEquivalences V U] where
(invIsEquiv {α : U} {β : V} (E : α ⟷' β) : h.IsEquiv E.invFun E.toFun)
namespace HasInvEquiv
variable {U V : Universe} [HasExternalFunctors U V] [HasExternalFunctors V U]
[HasExternalEquivalences U V] [HasExternalEquivalences V U] [h : HasInvEquiv U V]
def invEquiv' {α : U} {β : V} (E : α ⟷' β) : β ⟷' α := BundledEquivalence.mkEquiv (h.invIsEquiv E)
end HasInvEquiv
class HasEquivOp (U : Universe.{u}) [h : HasInternalFunctors U] [HasLinearFunOp U] extends
HasInternalEquivalences U, HasIdEquiv U, HasCompEquiv U U U, HasInvEquiv U U : Type u where
(compEquivIsFun {α β : U} (E : α ⟷' β) (γ : U) : h.IsFun (λ F : β ⟷ γ => HasInternalEquivalences.mkEquiv (compIsEquiv E (HasInternalEquivalences.toBundled F))))
(compEquivFunIsFun (α β γ : U) : h.IsFun (λ E : α ⟷ β => HasInternalFunctors.mkFun (compEquivIsFun (HasInternalEquivalences.toBundled E) γ)))
(invEquivIsFun (α β : U) : h.IsFun (λ E : α ⟷ β => HasInternalEquivalences.mkEquiv (invIsEquiv (HasInternalEquivalences.toBundled E))))
(invEquivIsEquiv (α β : U) : IsEquiv (BundledFunctor.mkFun (invEquivIsFun α β)) (BundledFunctor.mkFun (invEquivIsFun β α)))
namespace HasEquivOp
variable {U : Universe.{u}} [HasInternalFunctors U] [HasLinearFunOp U] [h : HasEquivOp U]
def idEquiv' (α : U) : α ⟷' α := HasIdEquiv.idEquiv' α
def idEquiv (α : U) : α ⟷ α := HasInternalEquivalences.fromBundled (idEquiv' α)
@[simp] theorem idEquiv.to.eff (α : U) (a : α) : HasInternalEquivalences.to (idEquiv α) a = a :=
by apply HasInternalEquivalences.fromBundled.to.eff
@[simp] theorem idEquiv.inv.eff (α : U) (a : α) : HasInternalEquivalences.inv (idEquiv α) a = a :=
by apply HasInternalEquivalences.fromBundled.inv.eff
def compEquiv' {α β γ : U} (E : α ⟷' β) (F : β ⟷' γ) : α ⟷' γ := HasCompEquiv.compEquiv' E F
def compEquiv {α β γ : U} (E : α ⟷ β) (F : β ⟷ γ) : α ⟷ γ :=
HasInternalEquivalences.fromBundled (compEquiv' (HasInternalEquivalences.toBundled E) (HasInternalEquivalences.toBundled F))
@[simp] theorem compEquiv.to.eff {α β γ : U} (E : α ⟷ β) (F : β ⟷ γ) (a : α) :
HasInternalEquivalences.to (compEquiv E F) a = HasInternalEquivalences.to F (HasInternalEquivalences.to E a) :=
by apply HasInternalEquivalences.fromBundled.to.eff
@[simp] theorem compEquiv.inv.eff {α β γ : U} (E : α ⟷ β) (F : β ⟷ γ) (c : γ) :
HasInternalEquivalences.inv (compEquiv E F) c = HasInternalEquivalences.inv E (HasInternalEquivalences.inv F c) :=
by apply HasInternalEquivalences.fromBundled.inv.eff
def compEquivFun' {α β : U} (E : α ⟷' β) (γ : U) : (β ⟷ γ) ⟶' (α ⟷ γ) := BundledFunctor.mkFun (h.compEquivIsFun E γ)
def compEquivFun {α β : U} (E : α ⟷ β) (γ : U) : (β ⟷ γ) ⟶ (α ⟷ γ) :=
HasInternalFunctors.fromBundled (compEquivFun' (HasInternalEquivalences.toBundled E) γ)
@[simp] theorem compEquivFun.eff {α β : U} (E : α ⟷ β) (γ : U) (F : β ⟷ γ) : (compEquivFun E γ) F = compEquiv E F :=
by apply HasInternalFunctors.fromBundled.eff
@[simp] theorem compEquivFun.to.effEff {α β : U} (E : α ⟷ β) (γ : U) (F : β ⟷ γ) (a : α) :
HasInternalEquivalences.to ((compEquivFun E γ) F) a = HasInternalEquivalences.to F (HasInternalEquivalences.to E a) :=
by simp
@[simp] theorem compEquivFun.inv.effEff {α β : U} (E : α ⟷ β) (γ : U) (F : β ⟷ γ) (c : γ) :
HasInternalEquivalences.inv ((compEquivFun E γ) F) c = HasInternalEquivalences.inv E (HasInternalEquivalences.inv F c) :=
by simp
def compEquivFunFun' (α β γ : U) : (α ⟷ β) ⟶' (β ⟷ γ) ⟶ (α ⟷ γ) := BundledFunctor.mkFun (h.compEquivFunIsFun α β γ)
def compEquivFunFun (α β γ : U) : (α ⟷ β) ⟶ (β ⟷ γ) ⟶ (α ⟷ γ) := HasInternalFunctors.fromBundled (compEquivFunFun' α β γ)
@[simp] theorem compEquivFunFun.eff (α β γ : U) (E : α ⟷ β) : (compEquivFunFun α β γ) E = compEquivFun E γ :=
by apply HasInternalFunctors.fromBundled.eff
@[simp] theorem compEquivFunFun.effEff (α β γ : U) (E : α ⟷ β) (F : β ⟷ γ) : ((compEquivFunFun α β γ) E) F = compEquiv E F :=
by simp
@[simp] theorem compEquivFunFun.to.effEffEff (α β γ : U) (E : α ⟷ β) (F : β ⟷ γ) (a : α) :
HasInternalEquivalences.to (((compEquivFunFun α β γ) E) F) a = HasInternalEquivalences.to F (HasInternalEquivalences.to E a) := by simp
@[simp] theorem compEquivFunFun.inv.effEffEff (α β γ : U) (E : α ⟷ β) (F : β ⟷ γ) (c : γ) :
HasInternalEquivalences.inv (((compEquivFunFun α β γ) E) F) c = HasInternalEquivalences.inv E (HasInternalEquivalences.inv F c) := by simp
def invEquiv' {α β : U} (E : α ⟷' β) : β ⟷' α := HasInvEquiv.invEquiv' E
def invEquiv {α β : U} (E : α ⟷ β) : β ⟷ α :=
HasInternalEquivalences.fromBundled (invEquiv' (HasInternalEquivalences.toBundled E))
@[simp] theorem invEquiv.to.eff {α β : U} (E : α ⟷ β) (b : β) : HasInternalEquivalences.to (invEquiv E) b = HasInternalEquivalences.inv E b :=
by apply HasInternalEquivalences.fromBundled.to.eff
@[simp] theorem invEquiv.inv.eff {α β : U} (E : α ⟷ β) (a : α) : HasInternalEquivalences.inv (invEquiv E) a = HasInternalEquivalences.to E a :=
by apply HasInternalEquivalences.fromBundled.inv.eff
def invEquivFun' (α β : U) : (α ⟷ β) ⟶' (β ⟷ α) := BundledFunctor.mkFun (h.invEquivIsFun α β)
def invEquivFun (α β : U) : (α ⟷ β) ⟶ (β ⟷ α) := HasInternalFunctors.fromBundled (invEquivFun' α β)
@[simp] theorem invEquivFun.eff (α β : U) (E : α ⟷ β) : (invEquivFun α β) E = invEquiv E :=
by apply HasInternalFunctors.fromBundled.eff
@[simp] theorem invEquivFun.to.effEff (α β : U) (E : α ⟷ β) (b : β) :
HasInternalEquivalences.to ((invEquivFun α β) E) b = HasInternalEquivalences.inv E b := by simp
@[simp] theorem invEquivFun.inv.effEff (α β : U) (E : α ⟷ β) (a : α) :
HasInternalEquivalences.inv ((invEquivFun α β) E) a = HasInternalEquivalences.to E a := by simp
def invEquivEquiv' (α β : U) : (α ⟷ β) ⟷' (β ⟷ α) := BundledEquivalence.mkEquiv (h.invEquivIsEquiv α β)
def invEquivEquiv (α β : U) : (α ⟷ β) ⟷ (β ⟷ α) := HasInternalEquivalences.fromBundled (invEquivEquiv' α β)
@[simp] theorem invEquivEquiv.to.eff (α β : U) (E : α ⟷ β) : HasInternalEquivalences.to (invEquivEquiv α β) E = invEquiv E :=
by apply HasInternalEquivalences.fromBundled.to.eff
@[simp] theorem invEquivEquiv.inv.eff (α β : U) (E : β ⟷ α) : HasInternalEquivalences.inv (invEquivEquiv α β) E = invEquiv E :=
by apply HasInternalEquivalences.fromBundled.inv.eff
@[simp] theorem invEquivEquiv.to.to.effEff (α β : U) (E : α ⟷ β) (b : β) :
HasInternalEquivalences.to (HasInternalEquivalences.to (invEquivEquiv α β) E) b = HasInternalEquivalences.inv E b := by simp
@[simp] theorem invEquivEquiv.to.inv.effEff (α β : U) (E : α ⟷ β) (a : α) :
HasInternalEquivalences.inv (HasInternalEquivalences.to (invEquivEquiv α β) E) a = HasInternalEquivalences.to E a := by simp
@[simp] theorem invEquivEquiv.inv.to.effEff (α β : U) (E : β ⟷ α) (a : α) :
HasInternalEquivalences.to (HasInternalEquivalences.inv (invEquivEquiv α β) E) a = HasInternalEquivalences.inv E a := by simp
@[simp] theorem invEquivEquiv.inv.inv.effEff (α β : U) (E : β ⟷ α) (b : β) :
HasInternalEquivalences.inv (HasInternalEquivalences.inv (invEquivEquiv α β) E) b = HasInternalEquivalences.to E b := by simp
end HasEquivOp
|
b36bb9b76f75a5940a4845cfe96adf99a7618f13 | 5749d8999a76f3a8fddceca1f6941981e33aaa96 | /src/measure_theory/l1_space.lean | a30b4d28ffe8ed8481f750d6abc136088a0f10ac | [
"Apache-2.0"
] | permissive | jdsalchow/mathlib | 13ab43ef0d0515a17e550b16d09bd14b76125276 | 497e692b946d93906900bb33a51fd243e7649406 | refs/heads/master | 1,585,819,143,348 | 1,580,072,892,000 | 1,580,072,892,000 | 154,287,128 | 0 | 0 | Apache-2.0 | 1,540,281,610,000 | 1,540,281,609,000 | null | UTF-8 | Lean | false | false | 28,267 | lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import measure_theory.ae_eq_fun
/-!
# Integrable functions and `L¹` space
In the first part of this file, the predicate `integrable` is defined and basic properties of
integrable functions are proved.
In the second part, the space `L¹` of equivalence classes of integrable functions under the relation
of being almost everywhere equal is defined as a subspace of the space `L⁰`. See the file
`src/measure_theory/ae_eq_fun.lean` for information on `L⁰` space.
## Notation
* `α →₁ β` is the type of `L¹` space, where `α` is a `measure_space` and `β` is a `normed_group` with
a `second_countable_topology`. `f : α →ₘ β` is a "function" in `L¹`. In comments, `[f]` is also used
to denote an `L¹` function.
`₁` can be typed as `\1`.
## Main definitions
* Let `f : α → β` be a function, where `α` is a `measure_space` and `β` a `normed_group`.
Then `f` is called `integrable` if `(∫⁻ a, nnnorm (f a)) < ⊤` holds.
* The space `L¹` is defined as a subspace of `L⁰` :
An `ae_eq_fun` `[f] : α →ₘ β` is in the space `L¹` if `edist [f] 0 < ⊤`, which means
`(∫⁻ a, edist (f a) 0) < ⊤` if we expand the definition of `edist` in `L⁰`.
## Main statements
`L¹`, as a subspace, inherits most of the structures of `L⁰`.
## Implementation notes
Maybe `integrable f` should be mean `(∫⁻ a, edist (f a) 0) < ⊤`, so that `integrable` and
`ae_eq_fun.integrable` are more aligned. But in the end one can use the lemma
`lintegral_nnnorm_eq_lintegral_edist : (∫⁻ a, nnnorm (f a)) = (∫⁻ a, edist (f a) 0)` to switch the
two forms.
## Tags
integrable, function space, l1
-/
noncomputable theory
open_locale classical topological_space
set_option class.instance_max_depth 100
namespace measure_theory
open set lattice filter topological_space ennreal emetric
universes u v w
variables {α : Type u} [measure_space α]
variables {β : Type v} [normed_group β] {γ : Type w} [normed_group γ]
/-- A function is `integrable` if the integral of its pointwise norm is less than infinity. -/
def integrable (f : α → β) : Prop := (∫⁻ a, nnnorm (f a)) < ⊤
lemma integrable_iff_norm (f : α → β) : integrable f ↔ (∫⁻ a, ennreal.of_real ∥f a∥) < ⊤ :=
have eq : (λa, ennreal.of_real ∥f a∥) = (λa, (nnnorm(f a) : ennreal)),
by { funext, rw of_real_norm_eq_coe_nnnorm },
iff.intro (by { rw eq, exact λh, h }) $ by { rw eq, exact λh, h }
lemma integrable_iff_edist (f : α → β) : integrable f ↔ (∫⁻ a, edist (f a) 0) < ⊤ :=
have eq : (λa, edist (f a) 0) = (λa, (nnnorm(f a) : ennreal)),
by { funext, rw edist_eq_coe_nnnorm },
iff.intro (by { rw eq, exact λh, h }) $ by { rw eq, exact λh, h }
lemma integrable_iff_of_real {f : α → ℝ} (h : ∀ₘ a, 0 ≤ f a) :
integrable f ↔ (∫⁻ a, ennreal.of_real (f a)) < ⊤ :=
have lintegral_eq : (∫⁻ a, ennreal.of_real ∥f a∥) = (∫⁻ a, ennreal.of_real (f a)) :=
begin
apply lintegral_congr_ae,
filter_upwards [h],
simp only [mem_set_of_eq],
assume a h,
rw [real.norm_eq_abs, abs_of_nonneg],
exact h
end,
by rw [integrable_iff_norm, lintegral_eq]
lemma integrable_of_ae_eq {f g : α → β} (hf : integrable f) (h : ∀ₘ a, f a = g a) : integrable g :=
begin
simp only [integrable] at *,
have : (∫⁻ (a : α), ↑(nnnorm (f a))) = (∫⁻ (a : α), ↑(nnnorm (g a))),
{ apply lintegral_congr_ae,
filter_upwards [h],
assume a,
simp only [mem_set_of_eq],
assume h,
rw h },
rwa ← this
end
lemma integrable_congr_ae {f g : α → β} (h : ∀ₘ a, f a = g a) : integrable f ↔ integrable g :=
iff.intro (λhf, integrable_of_ae_eq hf h) (λhg, integrable_of_ae_eq hg (all_ae_eq_symm h))
lemma integrable_of_le_ae {f : α → β} {g : α → γ} (h : ∀ₘ a, ∥f a∥ ≤ ∥g a∥) (hg : integrable g) :
integrable f :=
begin
simp only [integrable_iff_norm] at *,
calc (∫⁻ a, ennreal.of_real ∥f a∥) ≤ (∫⁻ (a : α), ennreal.of_real ∥g a∥) :
lintegral_le_lintegral_ae (by { filter_upwards [h], assume a h, exact of_real_le_of_real h })
... < ⊤ : hg
end
lemma integrable_of_le {f : α → β} {g : α → γ} (h : ∀a, ∥f a∥ ≤ ∥g a∥) (hg : integrable g) :
integrable f :=
integrable_of_le_ae (univ_mem_sets' h) hg
lemma lintegral_nnnorm_eq_lintegral_edist (f : α → β) :
(∫⁻ a, nnnorm (f a)) = ∫⁻ a, edist (f a) 0 :=
by { congr, funext, rw edist_eq_coe_nnnorm }
lemma lintegral_norm_eq_lintegral_edist (f : α → β) :
(∫⁻ a, ennreal.of_real ∥f a∥) = ∫⁻ a, edist (f a) 0 :=
by { congr, funext, rw [of_real_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm] }
lemma lintegral_edist_triangle [second_countable_topology β] {f g h : α → β}
(hf : measurable f) (hg : measurable g) (hh : measurable h) :
(∫⁻ a, edist (f a) (g a)) ≤ (∫⁻ a, edist (f a) (h a)) + ∫⁻ a, edist (g a) (h a) :=
begin
rw ← lintegral_add (measurable.edist hf hh) (measurable.edist hg hh),
apply lintegral_le_lintegral,
assume a,
have := edist_triangle (f a) (h a) (g a),
convert this,
rw edist_comm (h a) (g a),
end
lemma lintegral_edist_lt_top [second_countable_topology β] {f g : α → β}
(hfm : measurable f) (hfi : integrable f) (hgm : measurable g) (hgi : integrable g) :
(∫⁻ a, edist (f a) (g a)) < ⊤ :=
lt_of_le_of_lt
(lintegral_edist_triangle hfm hgm (measurable_const : measurable (λa, (0 : β))))
(ennreal.add_lt_top.2 $ by { split; rw ← integrable_iff_edist; assumption })
@[simp] lemma lintegral_nnnorm_zero : (∫⁻ a : α, nnnorm (0 : β)) = 0 := by simp
variables (α β)
@[simp] lemma integrable_zero : integrable (λa:α, (0:β)) :=
by { have := coe_lt_top, simpa [integrable] }
variables {α β}
lemma lintegral_nnnorm_add {f : α → β} {g : α → γ} (hf : measurable f) (hg : measurable g) :
(∫⁻ a, nnnorm (f a) + nnnorm (g a)) = (∫⁻ a, nnnorm (f a)) + ∫⁻ a, nnnorm (g a) :=
lintegral_add (measurable.coe_nnnorm hf) (measurable.coe_nnnorm hg)
lemma integrable.add {f g : α → β} (hfm : measurable f) (hfi : integrable f) (hgm : measurable g)
(hgi : integrable g): integrable (λa, f a + g a) :=
calc
(∫⁻ (a : α), ↑(nnnorm ((f + g) a))) ≤ ∫⁻ (a : α), ↑(nnnorm (f a)) + ↑(nnnorm (g a)) :
lintegral_le_lintegral _ _
(assume a, by { simp only [coe_add.symm, coe_le_coe], exact nnnorm_add_le _ _ })
... = _ :
lintegral_nnnorm_add hfm hgm
... < ⊤ : add_lt_top.2 ⟨hfi, hgi⟩
lemma integrable_finset_sum {ι} [second_countable_topology β] (s : finset ι) {f : ι → α → β}
(hfm : ∀ i, measurable (f i)) (hfi : ∀ i, integrable (f i)) :
integrable (λ a, s.sum (λ i, f i a)) :=
begin
refine finset.induction_on s _ _,
{ simp only [finset.sum_empty, integrable_zero] },
{ assume i s his ih,
simp only [his, finset.sum_insert, not_false_iff],
refine (hfi _).add (hfm _) (measurable_finset_sum s hfm) ih }
end
lemma lintegral_nnnorm_neg {f : α → β} :
(∫⁻ (a : α), ↑(nnnorm ((-f) a))) = ∫⁻ (a : α), ↑(nnnorm ((f) a)) :=
lintegral_congr_ae $ by { filter_upwards [], simp }
lemma integrable.neg {f : α → β} : integrable f → integrable (λa, -f a) :=
assume hfi, calc _ = _ : lintegral_nnnorm_neg
... < ⊤ : hfi
@[simp] lemma integrable_neg_iff (f : α → β) : integrable (λa, -f a) ↔ integrable f :=
begin
split,
{ assume h,
simpa only [_root_.neg_neg] using h.neg },
exact integrable.neg
end
lemma integrable.sub {f g : α → β} (hfm : measurable f) (hfi : integrable f) (hgm : measurable g)
(hgi : integrable g) : integrable (λa, f a - g a) :=
by { simp only [sub_eq_add_neg], exact hfi.add hfm (measurable.neg hgm) (integrable.neg hgi) }
lemma integrable.norm {f : α → β} (hfi : integrable f) : integrable (λa, ∥f a∥) :=
have eq : (λa, (nnnorm ∥f a∥ : ennreal)) = λa, (nnnorm (f a) : ennreal),
by { funext, rw nnnorm_norm },
by { rwa [integrable, eq] }
lemma integrable_norm_iff (f : α → β) : integrable (λa, ∥f a∥) ↔ integrable f :=
have eq : (λa, (nnnorm ∥f a∥ : ennreal)) = λa, (nnnorm (f a) : ennreal),
by { funext, rw nnnorm_norm },
by { rw [integrable, integrable, eq] }
lemma integrable_of_integrable_bound {f : α → β} {bound : α → ℝ} (h : integrable bound)
(h_bound : ∀ₘ a, ∥f a∥ ≤ bound a) : integrable f :=
have h₁ : ∀ₘ a, (nnnorm (f a) : ennreal) ≤ ennreal.of_real (bound a),
begin
filter_upwards [h_bound],
simp only [mem_set_of_eq],
assume a h,
calc (nnnorm (f a) : ennreal) = ennreal.of_real (∥f a∥) : by rw of_real_norm_eq_coe_nnnorm
... ≤ ennreal.of_real (bound a) : ennreal.of_real_le_of_real h
end,
calc (∫⁻ a, nnnorm (f a)) ≤ (∫⁻ a, ennreal.of_real (bound a)) :
by { apply lintegral_le_lintegral_ae, exact h₁ }
... ≤ (∫⁻ a, ennreal.of_real ∥bound a∥) : lintegral_le_lintegral _ _ $
by { assume a, apply ennreal.of_real_le_of_real, exact le_max_left (bound a) (-bound a) }
... < ⊤ : by { rwa [integrable_iff_norm] at h }
section dominated_convergence
variables {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
lemma all_ae_of_real_F_le_bound (h : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a) :
∀ n, ∀ₘ a, ennreal.of_real ∥F n a∥ ≤ ennreal.of_real (bound a) :=
λn, by filter_upwards [h n] λ a h, ennreal.of_real_le_of_real h
lemma all_ae_tendsto_of_real_norm (h : ∀ₘ a, tendsto (λ n, F n a) at_top $ 𝓝 $ f a) :
∀ₘ a, tendsto (λn, ennreal.of_real ∥F n a∥) at_top $ 𝓝 $ ennreal.of_real ∥f a∥ :=
by filter_upwards [h]
λ a h, tendsto_of_real $ tendsto.comp (continuous.tendsto continuous_norm _) h
lemma all_ae_of_real_f_le_bound (h_bound : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
∀ₘ a, ennreal.of_real ∥f a∥ ≤ ennreal.of_real (bound a) :=
begin
have F_le_bound := all_ae_of_real_F_le_bound h_bound,
rw ← all_ae_all_iff at F_le_bound,
filter_upwards [all_ae_tendsto_of_real_norm h_lim, F_le_bound],
assume a tendsto_norm F_le_bound,
refine le_of_tendsto at_top_ne_bot tendsto_norm _,
simp only [mem_at_top_sets, ge_iff_le, mem_set_of_eq, preimage_set_of_eq, nonempty_of_inhabited],
use 0,
assume n hn,
exact F_le_bound n
end
lemma integrable_of_dominated_convergence {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(bound_integrable : integrable bound)
(h_bound : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
integrable f :=
/- `∥F n a∥ ≤ bound a` and `∥F n a∥ --> ∥f a∥` implies `∥f a∥ ≤ bound a`,
and so `∫ ∥f∥ ≤ ∫ bound < ⊤` since `bound` is integrable -/
begin
rw integrable_iff_norm,
calc (∫⁻ a, (ennreal.of_real ∥f a∥)) ≤ ∫⁻ a, ennreal.of_real (bound a) :
lintegral_le_lintegral_ae $ all_ae_of_real_f_le_bound h_bound h_lim
... < ⊤ :
begin
rw ← integrable_iff_of_real,
{ exact bound_integrable },
filter_upwards [h_bound 0] λ a h, le_trans (norm_nonneg _) h,
end
end
lemma tendsto_lintegral_norm_of_dominated_convergence [second_countable_topology β]
{F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(F_measurable : ∀ n, measurable (F n))
(f_measurable : measurable f)
(bound_integrable : integrable bound)
(h_bound : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
tendsto (λn, ∫⁻ a, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 0) :=
let b := λa, 2 * ennreal.of_real (bound a) in
/- `∥F n a∥ ≤ bound a` and `F n a --> f a` implies `∥f a∥ ≤ bound a`, and thus by the
triangle inequality, have `∥F n a - f a∥ ≤ 2 * (bound a). -/
have hb : ∀ n, ∀ₘ a, ennreal.of_real ∥F n a - f a∥ ≤ b a,
begin
assume n,
filter_upwards [all_ae_of_real_F_le_bound h_bound n, all_ae_of_real_f_le_bound h_bound h_lim],
assume a h₁ h₂,
calc ennreal.of_real ∥F n a - f a∥ ≤ (ennreal.of_real ∥F n a∥) + (ennreal.of_real ∥f a∥) :
begin
rw [← ennreal.of_real_add],
apply of_real_le_of_real,
{ apply norm_sub_le }, { exact norm_nonneg _ }, { exact norm_nonneg _ }
end
... ≤ (ennreal.of_real (bound a)) + (ennreal.of_real (bound a)) : add_le_add' h₁ h₂
... = b a : by rw ← two_mul
end,
/- On the other hand, `F n a --> f a` implies that `∥F n a - f a∥ --> 0` -/
have h : ∀ₘ a, tendsto (λ n, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 0),
begin
suffices h : ∀ₘ a, tendsto (λ n, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 $ ennreal.of_real 0),
{ rwa ennreal.of_real_zero at h },
filter_upwards [h_lim],
assume a h,
refine tendsto.comp (continuous.tendsto continuous_of_real _) _,
rw ← tendsto_iff_norm_tendsto_zero,
exact h
end,
/- Therefore, by the dominated convergence theorem for nonnegative integration, have
` ∫ ∥f a - F n a∥ --> 0 ` -/
begin
suffices h : tendsto (λn, ∫⁻ a, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 (∫⁻ (a:α), 0)),
{ rwa lintegral_zero at h },
-- Using the dominated convergence theorem.
refine tendsto_lintegral_of_dominated_convergence _ _ hb _ _,
-- Show `λa, ∥f a - F n a∥` is measurable for all `n`
{ exact λn, measurable.comp measurable_of_real (measurable.norm (measurable.sub (F_measurable n)
f_measurable)) },
-- Show `2 * bound` is integrable
{ rw integrable_iff_of_real at bound_integrable,
{ calc (∫⁻ a, b a) = 2 * (∫⁻ a, ennreal.of_real (bound a)) :
by { rw lintegral_const_mul', exact coe_ne_top }
... < ⊤ : mul_lt_top (coe_lt_top) bound_integrable },
filter_upwards [h_bound 0] λ a h, le_trans (norm_nonneg _) h },
-- Show `∥f a - F n a∥ --> 0`
{ exact h }
end
end dominated_convergence
section pos_part
/-! Lemmas used for defining the positive part of a `L¹` function -/
lemma integrable.max_zero {f : α → ℝ} (hf : integrable f) : integrable (λa, max (f a) 0) :=
begin
simp only [integrable_iff_norm] at *,
calc (∫⁻ a, ennreal.of_real ∥max (f a) 0∥) ≤ (∫⁻ (a : α), ennreal.of_real ∥f a∥) :
lintegral_le_lintegral _ _
begin
assume a,
apply of_real_le_of_real,
simp only [real.norm_eq_abs],
calc abs (max (f a) 0) = max (f a) 0 : by { rw abs_of_nonneg, apply le_max_right }
... ≤ abs (f a) : max_le (le_abs_self _) (abs_nonneg _)
end
... < ⊤ : hf
end
lemma integrable.min_zero {f : α → ℝ} (hf : integrable f) : integrable (λa, min (f a) 0) :=
begin
have : (λa, min (f a) 0) = (λa, - max (-f a) 0),
{ funext, rw [min_eq_neg_max_neg_neg, neg_zero] },
rw this,
exact (integrable.max_zero hf.neg).neg,
end
end pos_part
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul (c : 𝕜) {f : α → β} : integrable f → integrable (λa, c • f a) :=
begin
simp only [integrable], assume hfi,
calc
(∫⁻ (a : α), nnnorm ((c • f) a)) = (∫⁻ (a : α), (nnnorm c) * nnnorm (f a)) :
begin
apply lintegral_congr_ae,
filter_upwards [],
assume a,
simp only [nnnorm_smul, set.mem_set_of_eq, pi.smul_apply, ennreal.coe_mul]
end
... < ⊤ :
begin
rw lintegral_const_mul',
apply mul_lt_top,
{ exact coe_lt_top },
{ exact hfi },
{ simp only [ennreal.coe_ne_top, ne.def, not_false_iff] }
end
end
lemma integrable_smul_iff {c : 𝕜} (hc : c ≠ 0) (f : α → β) : integrable (λa, c • f a) ↔ integrable f :=
begin
split,
{ assume h,
simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.smul c⁻¹ },
exact integrable.smul _
end
end normed_space
variables [second_countable_topology β]
namespace ae_eq_fun
/-- An almost everywhere equal function is `integrable` if it has a finite distance to the origin.
Should mean the same thing as the predicate `integrable` over functions. -/
def integrable (f : α →ₘ β) : Prop := f ∈ ball (0 : α →ₘ β) ⊤
lemma integrable_mk (f : α → β) (hf : measurable f) :
(integrable (mk f hf)) ↔ measure_theory.integrable f :=
by simp [integrable, zero_def, edist_mk_mk', measure_theory.integrable, nndist_eq_nnnorm]
lemma integrable_to_fun (f : α →ₘ β) : integrable f ↔ (measure_theory.integrable f.to_fun) :=
by conv_lhs { rw [self_eq_mk f, integrable_mk] }
local attribute [simp] integrable_mk
lemma integrable_zero : integrable (0 : α →ₘ β) := mem_ball_self coe_lt_top
lemma integrable.add : ∀ {f g : α →ₘ β}, integrable f → integrable g → integrable (f + g) :=
begin
rintros ⟨f, hf⟩ ⟨g, hg⟩,
simp only [mem_ball, zero_def, mk_add_mk, integrable_mk, quot_mk_eq_mk],
assume hfi hgi,
exact hfi.add hf hg hgi
end
lemma integrable.neg : ∀ {f : α →ₘ β}, integrable f → integrable (-f) :=
by { rintros ⟨f, hf⟩, have := measure_theory.integrable.neg, simpa }
lemma integrable.sub : ∀ {f g : α →ₘ β}, integrable f → integrable g → integrable (f - g) :=
begin
rintros ⟨f, hfm⟩ ⟨g, hgm⟩,
simp only [mem_ball, zero_def, mk_sub_mk, integrable_mk, quot_mk_eq_mk],
assume hfi hgi,
exact hfi.sub hfm hgm hgi
end
protected lemma is_add_subgroup : is_add_subgroup (ball (0 : α →ₘ β) ⊤) :=
{ zero_mem := integrable_zero,
add_mem := λ _ _, integrable.add,
neg_mem := λ _, integrable.neg }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul : ∀ {c : 𝕜} {f : α →ₘ β}, integrable f → integrable (c • f) :=
by { assume c, rintros ⟨f, hf⟩, simpa using integrable.smul _ }
end normed_space
end ae_eq_fun
section
variables (α β)
/-- The space of equivalence classes of integrable (and measurable) functions, where two integrable
functions are equivalent if they agree almost everywhere, i.e., they differ on a set of measure
`0`. -/
def l1 : Type (max u v) := subtype (@ae_eq_fun.integrable α _ β _ _)
infixr ` →₁ `:25 := l1
end
namespace l1
open ae_eq_fun
local attribute [instance] ae_eq_fun.is_add_subgroup
instance : has_coe (α →₁ β) (α →ₘ β) := ⟨subtype.val⟩
protected lemma eq {f g : α →₁ β} : (f : α →ₘ β) = (g : α →ₘ β) → f = g := subtype.eq
@[elim_cast] protected lemma eq_iff {f g : α →₁ β} : (f : α →ₘ β) = (g : α →ₘ β) ↔ f = g :=
iff.intro (l1.eq) (congr_arg coe)
/- TODO : order structure of l1-/
/-- `L¹` space forms a `emetric_space`, with the emetric being inherited from almost everywhere
functions, i.e., `edist f g = ∫⁻ a, edist (f a) (g a)`. -/
instance : emetric_space (α →₁ β) := subtype.emetric_space
/-- `L¹` space forms a `metric_space`, with the metric being inherited from almost everywhere
functions, i.e., `edist f g = ennreal.to_real (∫⁻ a, edist (f a) (g a))`. -/
instance : metric_space (α →₁ β) := metric_space_emetric_ball 0 ⊤
instance : add_comm_group (α →₁ β) := subtype.add_comm_group
@[simp, elim_cast] lemma coe_zero : ((0 : α →₁ β) : α →ₘ β) = 0 := rfl
@[simp, move_cast] lemma coe_add (f g : α →₁ β) : ((f + g : α →₁ β) : α →ₘ β) = f + g := rfl
@[simp, move_cast] lemma coe_neg (f : α →₁ β) : ((-f : α →₁ β) : α →ₘ β) = -f := rfl
@[simp, move_cast] lemma coe_sub (f g : α →₁ β) : ((f - g : α →₁ β) : α →ₘ β) = f - g := rfl
@[simp] lemma edist_eq (f g : α →₁ β) : edist f g = edist (f : α →ₘ β) (g : α →ₘ β) := rfl
lemma dist_eq (f g : α →₁ β) : dist f g = ennreal.to_real (edist (f : α →ₘ β) (g : α →ₘ β)) := rfl
/-- The norm on `L¹` space is defined to be `∥f∥ = ∫⁻ a, edist (f a) 0`. -/
instance : has_norm (α →₁ β) := ⟨λ f, dist f 0⟩
lemma norm_eq (f : α →₁ β) : ∥f∥ = ennreal.to_real (edist (f : α →ₘ β) 0) := rfl
instance : normed_group (α →₁ β) := normed_group.of_add_dist (λ x, rfl) $ by
{ intros, simp only [dist_eq, coe_add], rw edist_eq_add_add }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
instance : has_scalar 𝕜 (α →₁ β) := ⟨λ x f, ⟨x • (f : α →ₘ β), ae_eq_fun.integrable.smul f.2⟩⟩
@[simp, move_cast] lemma coe_smul (c : 𝕜) (f : α →₁ β) :
((c • f : α →₁ β) : α →ₘ β) = c • (f : α →ₘ β) := rfl
instance : semimodule 𝕜 (α →₁ β) :=
{ one_smul := λf, l1.eq (by { simp only [coe_smul], exact one_smul _ _ }),
mul_smul := λx y f, l1.eq (by { simp only [coe_smul], exact mul_smul _ _ _ }),
smul_add := λx f g, l1.eq (by { simp only [coe_smul, coe_add], exact smul_add _ _ _ }),
smul_zero := λx, l1.eq (by { simp only [coe_zero, coe_smul], exact smul_zero _ }),
add_smul := λx y f, l1.eq (by { simp only [coe_smul], exact add_smul _ _ _ }),
zero_smul := λf, l1.eq (by { simp only [coe_smul], exact zero_smul _ _ }) }
instance : module 𝕜 (α →₁ β) := { .. l1.semimodule }
instance : vector_space 𝕜 (α →₁ β) := { .. l1.semimodule }
instance : normed_space 𝕜 (α →₁ β) :=
⟨ begin
rintros x ⟨f, hf⟩,
show ennreal.to_real (edist (x • f) 0) = ∥x∥ * ennreal.to_real (edist f 0),
rw [edist_smul, to_real_of_real_mul],
exact norm_nonneg _
end ⟩
end normed_space
section of_fun
/-- Construct the equivalence class `[f]` of a measurable and integrable function `f`. -/
def of_fun (f : α → β) (hfm : measurable f) (hfi : integrable f) : (α →₁ β) :=
⟨mk f hfm, by { rw integrable_mk, exact hfi }⟩
lemma of_fun_eq_mk (f : α → β) (hfm hfi) : (of_fun f hfm hfi : α →ₘ β) = mk f hfm := rfl
lemma of_fun_eq_of_fun (f g : α → β) (hfm hfi hgm hgi) :
of_fun f hfm hfi = of_fun g hgm hgi ↔ ∀ₘ a, f a = g a :=
by { rw ← l1.eq_iff, simp only [of_fun_eq_mk, mk_eq_mk] }
lemma of_fun_zero :
of_fun (λa:α, (0:β)) (@measurable_const _ _ _ _ (0:β)) (integrable_zero α β) = 0 := rfl
lemma of_fun_add (f g : α → β) (hfm hfi hgm hgi) :
of_fun (λa, f a + g a) (measurable.add hfm hgm) (integrable.add hfm hfi hgm hgi)
= of_fun f hfm hfi + of_fun g hgm hgi :=
rfl
lemma of_fun_neg (f : α → β) (hfm hfi) :
of_fun (λa, - f a) (measurable.neg hfm) (integrable.neg hfi) = - of_fun f hfm hfi := rfl
lemma of_fun_sub (f g : α → β) (hfm hfi hgm hgi) :
of_fun (λa, f a - g a) (measurable.sub hfm hgm) (integrable.sub hfm hfi hgm hgi)
= of_fun f hfm hfi - of_fun g hgm hgi :=
rfl
lemma norm_of_fun (f : α → β) (hfm hfi) : ∥of_fun f hfm hfi∥ = ennreal.to_real (∫⁻ a, edist (f a) 0) :=
rfl
lemma norm_of_fun_eq_lintegral_norm (f : α → β) (hfm hfi) :
∥of_fun f hfm hfi∥ = ennreal.to_real (∫⁻ a, ennreal.of_real ∥f a∥) :=
by { rw [norm_of_fun, lintegral_norm_eq_lintegral_edist] }
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma of_fun_smul (f : α → β) (hfm hfi) (k : 𝕜) :
of_fun (λa, k • f a) (measurable.smul _ hfm) (integrable.smul _ hfi) = k • of_fun f hfm hfi := rfl
end of_fun
section to_fun
/-- Find a representative of a `L¹` function [f] -/
@[reducible]
protected def to_fun (f : α →₁ β) : α → β := (f : α →ₘ β).to_fun
protected lemma measurable (f : α →₁ β) : measurable f.to_fun := f.1.measurable
protected lemma integrable (f : α →₁ β) : integrable f.to_fun :=
by { rw [l1.to_fun, ← integrable_to_fun], exact f.2 }
lemma of_fun_to_fun (f : α →₁ β) : of_fun (f.to_fun) f.measurable f.integrable = f :=
begin
rcases f with ⟨f, hfi⟩,
rw [of_fun, subtype.mk_eq_mk],
exact (self_eq_mk f).symm
end
lemma mk_to_fun (f : α →₁ β) : mk (f.to_fun) f.measurable = f :=
by { rw ← of_fun_eq_mk, rw l1.eq_iff, exact of_fun_to_fun f }
lemma to_fun_of_fun (f : α → β) (hfm hfi) : ∀ₘ a, (of_fun f hfm hfi).to_fun a = f a :=
begin
filter_upwards [all_ae_mk_to_fun f hfm],
assume a,
simp only [mem_set_of_eq],
assume h,
rw ← h,
refl
end
variables (α β)
lemma zero_to_fun : ∀ₘ a, (0 : α →₁ β).to_fun a = 0 := ae_eq_fun.zero_to_fun
variables {α β}
lemma add_to_fun (f g : α →₁ β) : ∀ₘ a, (f + g).to_fun a = f.to_fun a + g.to_fun a :=
ae_eq_fun.add_to_fun _ _
lemma neg_to_fun (f : α →₁ β) : ∀ₘ a, (-f).to_fun a = -f.to_fun a := ae_eq_fun.neg_to_fun _
lemma sub_to_fun (f g : α →₁ β) : ∀ₘ a, (f - g).to_fun a = f.to_fun a - g.to_fun a :=
ae_eq_fun.sub_to_fun _ _
lemma dist_to_fun (f g : α →₁ β) : dist f g = ennreal.to_real (∫⁻ x, edist (f.to_fun x) (g.to_fun x)) :=
by { simp only [dist_eq, edist_to_fun] }
lemma norm_eq_nnnorm_to_fun (f : α →₁ β) : ∥f∥ = ennreal.to_real (∫⁻ a, nnnorm (f.to_fun a)) :=
by { rw [lintegral_nnnorm_eq_lintegral_edist, ← edist_zero_to_fun], refl }
lemma norm_eq_norm_to_fun (f : α →₁ β) : ∥f∥ = ennreal.to_real (∫⁻ a, ennreal.of_real ∥f.to_fun a∥) :=
by { rw norm_eq_nnnorm_to_fun, congr, funext, rw of_real_norm_eq_coe_nnnorm }
lemma lintegral_edist_to_fun_lt_top (f g : α →₁ β) : (∫⁻ a, edist (f.to_fun a) (g.to_fun a)) < ⊤ :=
begin
apply lintegral_edist_lt_top,
exact f.measurable, exact f.integrable, exact g.measurable, exact g.integrable
end
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma smul_to_fun (c : 𝕜) (f : α →₁ β) : ∀ₘ a, (c • f).to_fun a = c • f.to_fun a :=
ae_eq_fun.smul_to_fun _ _
end to_fun
section pos_part
/-- Positive part of a function in `L¹` space. -/
def pos_part (f : α →₁ ℝ) : α →₁ ℝ :=
⟨ ae_eq_fun.pos_part f,
begin
rw [ae_eq_fun.integrable_to_fun, integrable_congr_ae (pos_part_to_fun _)],
exact integrable.max_zero f.integrable
end ⟩
/-- Negative part of a function in `L¹` space. -/
def neg_part (f : α →₁ ℝ) : α →₁ ℝ := pos_part (-f)
@[move_cast] lemma coe_pos_part (f : α →₁ ℝ) : (f.pos_part : α →ₘ ℝ) = (f : α →ₘ ℝ).pos_part := rfl
lemma pos_part_to_fun (f : α →₁ ℝ) : ∀ₘ a, (pos_part f).to_fun a = max (f.to_fun a) 0 :=
ae_eq_fun.pos_part_to_fun _
lemma neg_part_to_fun_eq_max (f : α →₁ ℝ) : ∀ₘ a, (neg_part f).to_fun a = max (- f.to_fun a) 0 :=
begin
rw neg_part,
filter_upwards [pos_part_to_fun (-f), neg_to_fun f],
simp only [mem_set_of_eq],
assume a h₁ h₂,
rw [h₁, h₂]
end
lemma neg_part_to_fun_eq_min (f : α →₁ ℝ) : ∀ₘ a, (neg_part f).to_fun a = - min (f.to_fun a) 0 :=
begin
filter_upwards [neg_part_to_fun_eq_max f],
simp only [mem_set_of_eq],
assume a h,
rw [h, min_eq_neg_max_neg_neg, _root_.neg_neg, neg_zero],
end
lemma norm_le_norm_of_ae_le {f g : α →₁ β} (h : ∀ₘ a, ∥f.to_fun a∥ ≤ ∥g.to_fun a∥) : ∥f∥ ≤ ∥g∥ :=
begin
simp only [l1.norm_eq_norm_to_fun],
rw to_real_le_to_real,
{ apply lintegral_le_lintegral_ae,
filter_upwards [h],
simp only [mem_set_of_eq],
assume a h,
exact of_real_le_of_real h },
{ rw [← lt_top_iff_ne_top, ← integrable_iff_norm], exact f.integrable },
{ rw [← lt_top_iff_ne_top, ← integrable_iff_norm], exact g.integrable }
end
lemma continuous_pos_part : continuous $ λf : α →₁ ℝ, pos_part f :=
begin
simp only [metric.continuous_iff],
assume g ε hε,
use ε, use hε,
simp only [dist_eq_norm],
assume f hfg,
refine lt_of_le_of_lt (norm_le_norm_of_ae_le _) hfg,
filter_upwards [l1.sub_to_fun f g, l1.sub_to_fun (pos_part f) (pos_part g),
pos_part_to_fun f, pos_part_to_fun g],
simp only [mem_set_of_eq],
assume a h₁ h₂ h₃ h₄,
simp only [real.norm_eq_abs, h₁, h₂, h₃, h₄],
exact abs_max_sub_max_le_abs _ _ _
end
lemma continuous_neg_part : continuous $ λf : α →₁ ℝ, neg_part f :=
have eq : (λf : α →₁ ℝ, neg_part f) = (λf : α →₁ ℝ, pos_part (-f)) := rfl,
by { rw eq, exact continuous_pos_part.comp continuous_neg }
end pos_part
/- TODO: l1 is a complete space -/
end l1
end measure_theory
|
67d104fc12740991d7a83533984ef8595be3a807 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/theories/topology/basic.lean | ee4b3c228a72edfb825dfc250bebfbbebb33ff58 | [
"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 | 11,048 | lean | /-
Copyright (c) 2015 Jacob Gross. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jacob Gross, Jeremy Avigad
Open and closed sets, seperation axioms and generated topologies.
-/
import data.set data.nat
open algebra eq.ops set nat
structure topology [class] (X : Type) :=
(opens : set (set X))
(univ_mem_opens : univ ∈ opens)
(sUnion_mem_opens : ∀ {S : set (set X)}, S ⊆ opens → ⋃₀ S ∈ opens)
(inter_mem_opens : ∀₀ s ∈ opens, ∀₀ t ∈ opens, s ∩ t ∈ opens)
-- the bundled version
structure TopologicalSpace : Type :=
(carrier : Type) (struct : topology carrier)
attribute TopologicalSpace.carrier [coercion]
attribute TopologicalSpace.struct [instance]
namespace topology
variables {X : Type} [topology X]
/- open sets -/
definition Open (s : set X) : Prop := s ∈ opens X
theorem Open_empty : Open (∅ : set X) :=
have ∅ ⊆ opens X, from empty_subset _,
have ⋃₀ ∅ ∈ opens X, from sUnion_mem_opens this,
show ∅ ∈ opens X, by rewrite -sUnion_empty; apply this
theorem Open_univ : Open (univ : set X) :=
univ_mem_opens X
theorem Open_sUnion {S : set (set X)} (H : ∀₀ t ∈ S, Open t) : Open (⋃₀ S) :=
sUnion_mem_opens H
theorem Open_Union {I : Type} {s : I → set X} (H : ∀ i, Open (s i)) : Open (⋃ i, s i) :=
have ∀₀ t ∈ s ' univ, Open t,
from take t, suppose t ∈ s ' univ,
obtain i [univi (Hi : s i = t)], from this,
show Open t, by rewrite -Hi; exact H i,
using this, by rewrite Union_eq_sUnion_image; apply Open_sUnion this
theorem Open_union {s t : set X} (Hs : Open s) (Ht : Open t) : Open (s ∪ t) :=
have ∀ i, Open (bin_ext s t i), by intro i; cases i; exact Hs; exact Ht,
show Open (s ∪ t), by rewrite -Union_bin_ext; exact Open_Union this
theorem Open_inter {s t : set X} (Hs : Open s) (Ht : Open t) : Open (s ∩ t) :=
inter_mem_opens X Hs Ht
theorem Open_sInter_of_finite {s : set (set X)} [fins : finite s] (H : ∀₀ t ∈ s, Open t) :
Open (⋂₀ s) :=
begin
induction fins with a s fins anins ih,
{rewrite sInter_empty, exact Open_univ},
rewrite sInter_insert,
apply Open_inter,
show Open a, from H (mem_insert a s),
apply ih, intros t ts,
show Open t, from H (mem_insert_of_mem a ts)
end
/- closed sets -/
definition closed [reducible] (s : set X) : Prop := Open (-s)
theorem closed_iff_Open_compl (s : set X) : closed s ↔ Open (-s) := !iff.refl
theorem Open_iff_closed_compl (s : set X) : Open s ↔ closed (-s) :=
by rewrite [closed_iff_Open_compl, compl_compl]
theorem closed_compl {s : set X} (H : Open s) : closed (-s) :=
by rewrite [-Open_iff_closed_compl]; apply H
theorem closed_empty : closed (∅ : set X) :=
by rewrite [↑closed, compl_empty]; exact Open_univ
theorem closed_univ : closed (univ : set X) :=
by rewrite [↑closed, compl_univ]; exact Open_empty
theorem closed_sInter {S : set (set X)} (H : ∀₀ t ∈ S, closed t) : closed (⋂₀ S) :=
begin
rewrite [↑closed, compl_sInter],
apply Open_sUnion,
intro t,
rewrite [mem_image_compl, Open_iff_closed_compl],
apply H
end
theorem closed_Inter {I : Type} {s : I → set X} (H : ∀ i, closed (s i : set X)) :
closed (⋂ i, s i) :=
by rewrite [↑closed, compl_Inter]; apply Open_Union; apply H
theorem closed_inter {s t : set X} (Hs : closed s) (Ht : closed t) : closed (s ∩ t) :=
by rewrite [↑closed, compl_inter]; apply Open_union; apply Hs; apply Ht
theorem closed_union {s t : set X} (Hs : closed s) (Ht : closed t) : closed (s ∪ t) :=
by rewrite [↑closed, compl_union]; apply Open_inter; apply Hs; apply Ht
theorem closed_sUnion_of_finite {s : set (set X)} [fins : finite s] (H : ∀₀ t ∈ s, closed t) :
closed (⋂₀ s) :=
begin
rewrite [↑closed, compl_sInter],
apply Open_sUnion,
intro t,
rewrite [mem_image_compl, Open_iff_closed_compl],
apply H
end
theorem open_diff {s t : set X} (Hs : Open s) (Ht : closed t) : Open (s \ t) :=
Open_inter Hs Ht
theorem closed_diff {s t : set X} (Hs : closed s) (Ht : Open t) : closed (s \ t) :=
closed_inter Hs (closed_compl Ht)
section
open classical
theorem Open_of_forall_exists_Open_nbhd {s : set X} (H : ∀₀ x ∈ s, ∃ tx : set X, Open tx ∧ x ∈ tx ∧ tx ⊆ s) :
Open s :=
let Hset : X → set X := λ x, if Hxs : x ∈ s then some (H Hxs) else univ in
let sFam := image (λ x, Hset x) s in
have H_union_open : Open (⋃₀ sFam), from Open_sUnion
(take t : set X, suppose t ∈ sFam,
have H_preim : ∃ t', t' ∈ s ∧ Hset t' = t, from this,
obtain t' (Ht' : t' ∈ s) (Ht't : Hset t' = t), from H_preim,
have HHsett : t = some (H Ht'), from Ht't ▸ dif_pos Ht',
show Open t, from and.left (HHsett⁻¹ ▸ some_spec (H Ht'))),
have H_subset_union : s ⊆ ⋃₀ sFam, from
(take x : X, suppose x ∈ s,
have HxHset : x ∈ Hset x, from (dif_pos this)⁻¹ ▸ (and.left (and.right (some_spec (H this)))),
show x ∈ ⋃₀ sFam, from mem_sUnion HxHset (mem_image this rfl)),
have H_union_subset : ⋃₀ sFam ⊆ s, from
(take x : X, suppose x ∈ ⋃₀ sFam,
obtain (t : set X) (Ht : t ∈ sFam) (Hxt : x ∈ t), from this,
have H_preim : ∃ t', t' ∈ s ∧ Hset t' = t, from Ht,
obtain t' (Ht' : t' ∈ s) (Ht't : Hset t' = t), from H_preim,
have HHsett : t = some (H Ht'), from Ht't ▸ dif_pos Ht',
have t ⊆ s, from and.right (and.right (HHsett⁻¹ ▸ some_spec (H Ht'))),
show x ∈ s, from this Hxt),
have H_union_eq : ⋃₀ sFam = s, from eq_of_subset_of_subset H_union_subset H_subset_union,
show Open s, from H_union_eq ▸ H_union_open
end
end topology
/- separation -/
structure T0_space [class] (X : Type) extends topology X :=
(T0 : ∀ {x y}, x ≠ y → ∃ U, U ∈ opens ∧ ¬(x ∈ U ↔ y ∈ U))
namespace topology
variables {X : Type} [T0_space X]
theorem separation_T0 {x y : X} : x ≠ y ↔ ∃ U, Open U ∧ ¬(x ∈ U ↔ y ∈ U) :=
iff.intro
(T0_space.T0)
(assume H, obtain U [OpU xyU], from H,
suppose x = y,
have x ∈ U ↔ y ∈ U, from iff.intro
(assume xU, this ▸ xU)
(assume yU, this⁻¹ ▸ yU),
absurd this xyU)
end topology
structure T1_space [class] (X : Type) extends topology X :=
(T1 : ∀ {x y}, x ≠ y → ∃ U, U ∈ opens ∧ x ∈ U ∧ y ∉ U)
protected definition T0_space.of_T1 [trans_instance] {X : Type} [T : T1_space X] :
T0_space X :=
⦃T0_space, T,
T0 := abstract
take x y, assume H,
obtain U [Uopens [xU ynU]], from T1_space.T1 H,
exists.intro U (and.intro Uopens
(show ¬ (x ∈ U ↔ y ∈ U), from assume H, ynU (iff.mp H xU)))
end ⦄
namespace topology
variables {X : Type} [T1_space X]
theorem separation_T1 {x y : X} : x ≠ y ↔ (∃ U, Open U ∧ x ∈ U ∧ y ∉ U) :=
iff.intro
(T1_space.T1)
(suppose ∃ U, Open U ∧ x ∈ U ∧ y ∉ U,
obtain U [OpU xU nyU], from this,
suppose x = y,
absurd xU (this⁻¹ ▸ nyU))
theorem closed_singleton {a : X} : closed '{a} :=
let T := ⋃₀ {S| Open S ∧ a ∉ S} in
have Open T, from Open_sUnion (λS HS, and.elim_left HS),
have T = -'{a}, from ext(take x, iff.intro
(assume xT, assume xa,
obtain S [[OpS aS] xS], from xT,
have ∃ U, Open U ∧ x ∈ U ∧ a ∉ U, from
exists.intro S (and.intro OpS (and.intro xS aS)),
have x ≠ a, from (iff.elim_right separation_T1) this,
absurd ((iff.elim_left !mem_singleton_iff) xa) this)
(assume xa,
have x ≠ a, from not.intro(
assume H, absurd ((iff.elim_right !mem_singleton_iff) H) xa),
obtain U [OpU xU aU], from (iff.elim_left separation_T1) this,
show _, from exists.intro U (and.intro (and.intro OpU aU) xU))),
show _, from this ▸ `Open T`
end topology
structure T2_space [class] (X : Type) extends topology X :=
(T2 : ∀ {x y}, x ≠ y → ∃ U V, U ∈ opens ∧ V ∈ opens ∧ x ∈ U ∧ y ∈ V ∧ U ∩ V = ∅)
protected definition T1_space.of_T2 [trans_instance] {X : Type} [T : T2_space X] :
T1_space X :=
⦃T1_space, T,
T1 := abstract
take x y, assume H,
obtain U [V [Uopens [Vopens [xU [yV UVempty]]]]], from T2_space.T2 H,
exists.intro U (and.intro Uopens (and.intro xU
(show y ∉ U, from assume yU,
have y ∈ U ∩ V, from and.intro yU yV,
show y ∈ ∅, from UVempty ▸ this)))
end ⦄
namespace topology
variables {X : Type} [T2_space X]
theorem seperation_T2 {x y : X} : x ≠ y ↔ ∃ U V, Open U ∧ Open V ∧ x ∈ U ∧ y ∈ V ∧ U ∩ V = ∅ :=
iff.intro
(T2_space.T2)
(assume H, obtain U V [OpU OpV xU yV UV], from H,
suppose x = y,
have ¬(x ∈ U ∩ V), from not.intro(
assume xUV, absurd (UV ▸ xUV) !not_mem_empty),
absurd (and.intro xU (`x = y`⁻¹ ▸ yV)) this)
end topology
structure perfect_space [class] (X : Type) extends topology X :=
(perfect : ∀ x, '{x} ∉ opens)
/- topology generated by a set -/
namespace topology
inductive opens_generated_by {X : Type} (B : set (set X)) : set X → Prop :=
| generators_mem : ∀ ⦃s : set X⦄, s ∈ B → opens_generated_by B s
| univ_mem : opens_generated_by B univ
| inter_mem : ∀ ⦃s t⦄, opens_generated_by B s → opens_generated_by B t →
opens_generated_by B (s ∩ t)
| sUnion_mem : ∀ ⦃S : set (set X)⦄, S ⊆ opens_generated_by B → opens_generated_by B (⋃₀ S)
protected definition generated_by [instance] {X : Type} (B : set (set X)) : topology X :=
⦃topology,
opens := opens_generated_by B,
univ_mem_opens := opens_generated_by.univ_mem B,
inter_mem_opens := λ s Hs t Ht, opens_generated_by.inter_mem Hs Ht,
sUnion_mem_opens := opens_generated_by.sUnion_mem
⦄
theorem generators_mem_topology_generated_by {X : Type} (B : set (set X)) :
let T := topology.generated_by B in
∀₀ s ∈ B, @Open _ T s :=
λ s H, opens_generated_by.generators_mem H
theorem opens_generated_by_initial {X : Type} {B : set (set X)} {T : topology X} (H : B ⊆ @opens _ T) :
opens_generated_by B ⊆ @opens _ T :=
begin
intro s Hs,
induction Hs with s sB s t os ot soX toX S SB SOX,
{exact H sB},
{exact univ_mem_opens X},
{exact inter_mem_opens X soX toX},
exact sUnion_mem_opens SOX
end
theorem topology_generated_by_initial {X : Type} {B : set (set X)} {T : topology X}
(H : ∀₀ s ∈ B, @Open _ T s) {s : set X} (H1 : @Open _ (topology.generated_by B) s) :
@Open _ T s :=
opens_generated_by_initial H H1
section boundary
variables {X : Type} [TX : topology X]
include TX
definition on_boundary (x : X) (u : set X) := ∀ v : set X, Open v → x ∈ v → u ∩ v ≠ ∅ ∧ ¬ v ⊆ u
theorem not_open_of_on_boundary {x : X} {u : set X} (Hxu : x ∈ u) (Hob : on_boundary x u) : ¬ Open u :=
begin
intro Hop,
note Hbxu := Hob _ Hop Hxu,
apply and.right Hbxu,
apply subset.refl
end
end boundary
end topology
|
a85166f7a376da243b2b38b3a4c55dbc7688a109 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/ring_theory/polynomial.lean | aa72bc59305f859cf0fd691af5234a0f960196f4 | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 14,095 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Ring-theoretic supplement of data.polynomial.
Main result: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring.
-/
import data.polynomial data.mv_polynomial
import ring_theory.subring
import ring_theory.ideals ring_theory.noetherian
universes u v w
namespace polynomial
variables (R : Type u) [comm_ring R] [decidable_eq R]
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/
def degree_le (n : with_bot ℕ) : submodule R (polynomial R) :=
⨅ k : ℕ, ⨅ h : ↑k > n, (lcoeff R k).ker
variable {R}
theorem mem_degree_le {n : with_bot ℕ} {f : polynomial R} :
f ∈ degree_le R n ↔ degree f ≤ n :=
by simp only [degree_le, submodule.mem_infi, degree_le_iff_coeff_zero, linear_map.mem_ker]; refl
theorem degree_le_mono {m n : with_bot ℕ} (H : m ≤ n) :
degree_le R m ≤ degree_le R n :=
λ f hf, mem_degree_le.2 (le_trans (mem_degree_le.1 hf) H)
theorem degree_le_eq_span_X_pow {n : ℕ} :
degree_le R n = submodule.span R ↑((finset.range (n+1)).image (λ n, X^n) : finset (polynomial R)) :=
begin
apply le_antisymm,
{ intros p hp, replace hp := mem_degree_le.1 hp,
rw [← finsupp.sum_single p, finsupp.sum, submodule.mem_coe],
refine submodule.sum_mem _ (λ k hk, _),
have := with_bot.coe_le_coe.1 (finset.sup_le_iff.1 hp k hk),
rw [single_eq_C_mul_X, C_mul'],
refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $
finset.mem_image.2 ⟨_, finset.mem_range.2 (nat.lt_succ_of_le this), rfl⟩) },
rw [submodule.span_le, finset.coe_image, set.image_subset_iff],
intros k hk, apply mem_degree_le.2,
apply le_trans (degree_X_pow_le _) (with_bot.coe_le_coe.2 $ nat.le_of_lt_succ $ finset.mem_range.1 hk)
end
/-- Given a polynomial, return the polynomial whose coefficients are in
the ring closure of the original coefficients. -/
def restriction (p : polynomial R) : polynomial (ring.closure (↑p.frange : set R)) :=
⟨p.support, λ i, ⟨p.to_fun i,
if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem _
else ring.subset_closure $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩,
λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩
@[simp] theorem coeff_restriction {p : polynomial R} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := rfl
@[simp] theorem coeff_restriction' {p : polynomial R} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := rfl
@[simp] theorem degree_restriction {p : polynomial R} : (restriction p).degree = p.degree := rfl
@[simp] theorem nat_degree_restriction {p : polynomial R} : (restriction p).nat_degree = p.nat_degree := rfl
@[simp] theorem monic_restriction {p : polynomial R} : monic (restriction p) ↔ monic p :=
⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩
@[simp] theorem restriction_zero : restriction (0 : polynomial R) = 0 := rfl
@[simp] theorem restriction_one : restriction (1 : polynomial R) = 1 :=
ext.2 $ λ i, subtype.eq $ by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs; refl
variables {S : Type v} [comm_ring S] {f : R → S} {x : S}
theorem eval₂_restriction {p : polynomial R} :
eval₂ f x p = eval₂ (f ∘ subtype.val) x p.restriction :=
rfl
section to_subring
variables (p : polynomial R) (T : set R) [is_subring T]
/-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`,
return the corresponding polynomial whose coefficients are in `T. -/
def to_subring (hp : ↑p.frange ⊆ T) : polynomial T :=
⟨p.support, λ i, ⟨p.to_fun i,
if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem _
else hp $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩,
λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩
variables (hp : ↑p.frange ⊆ T)
include hp
@[simp] theorem coeff_to_subring {n : ℕ} : ↑(coeff (to_subring p T hp) n) = coeff p n := rfl
@[simp] theorem coeff_to_subring' {n : ℕ} : (coeff (to_subring p T hp) n).1 = coeff p n := rfl
@[simp] theorem degree_to_subring : (to_subring p T hp).degree = p.degree := rfl
@[simp] theorem nat_degree_to_subring : (to_subring p T hp).nat_degree = p.nat_degree := rfl
@[simp] theorem monic_to_subring : monic (to_subring p T hp) ↔ monic p :=
⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩
omit hp
@[simp] theorem to_subring_zero : to_subring (0 : polynomial R) T (set.empty_subset _) = 0 := rfl
@[simp] theorem to_subring_one : to_subring (1 : polynomial R) T
(set.subset.trans (finset.coe_subset.2 finsupp.frange_single)
(set.singleton_subset_iff.2 (is_submonoid.one_mem _))) = 1 :=
ext.2 $ λ i, subtype.eq $ by rw [coeff_to_subring', coeff_one, coeff_one]; split_ifs; refl
end to_subring
variables (T : set R) [is_subring T]
/-- Given a polynomial whose coefficients are in some subring, return
the corresponding polynomial whose coefificents are in the ambient ring. -/
def of_subring (p : polynomial T) : polynomial R :=
⟨p.support, subtype.val ∘ p.to_fun,
λ n, finsupp.mem_support_iff.trans (not_iff_not_of_iff
⟨λ h, congr_arg subtype.val h, λ h, subtype.eq h⟩)⟩
@[simp] theorem frange_of_subring {p : polynomial T} :
↑(p.of_subring T).frange ⊆ T :=
λ y H, let ⟨hy, x, hx⟩ := finsupp.mem_frange.1 H in hx ▸ (p.to_fun x).2
end polynomial
variables {R : Type u} [comm_ring R] [decidable_eq R]
namespace ideal
open polynomial
/-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/
def of_polynomial (I : ideal (polynomial R)) : submodule R (polynomial R) :=
{ carrier := I.carrier,
zero := I.zero_mem,
add := λ _ _, I.add_mem,
smul := λ c x H, by rw [← C_mul']; exact submodule.smul_mem _ _ H }
variables {I : ideal (polynomial R)}
theorem mem_of_polynomial (x) : x ∈ I.of_polynomial ↔ x ∈ I := iff.rfl
variables (I)
/-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I`
consisting of polynomials of degree ≤ `n`. -/
def degree_le (n : with_bot ℕ) : submodule R (polynomial R) :=
degree_le R n ⊓ I.of_polynomial
/-- Given an ideal `I` of `R[X]`, make the ideal in `R` of
leading coefficients of polynomials in `I` with degree ≤ `n`. -/
def leading_coeff_nth (n : ℕ) : ideal R :=
(I.degree_le n).map $ lcoeff R n
theorem mem_leading_coeff_nth (n : ℕ) (x) :
x ∈ I.leading_coeff_nth n ↔ ∃ p ∈ I, degree p ≤ n ∧ leading_coeff p = x :=
begin
simp only [leading_coeff_nth, degree_le, submodule.mem_map, lcoeff_apply, submodule.mem_inf, mem_degree_le],
split,
{ rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩,
cases lt_or_eq_of_le hpdeg with hpdeg hpdeg,
{ refine ⟨0, I.zero_mem, lattice.bot_le, _⟩,
rw [leading_coeff_zero, eq_comm],
exact coeff_eq_zero_of_degree_lt hpdeg },
{ refine ⟨p, hpI, le_of_eq hpdeg, _⟩,
rw [leading_coeff, nat_degree, hpdeg], refl } },
{ rintro ⟨p, hpI, hpdeg, rfl⟩,
have : nat_degree p + (n - nat_degree p) = n,
{ exact nat.add_sub_cancel' (nat_degree_le_of_degree_le hpdeg) },
refine ⟨p * X ^ (n - nat_degree p), ⟨_, I.mul_mem_right hpI⟩, _⟩,
{ apply le_trans (degree_mul_le _ _) _,
apply le_trans (add_le_add' (degree_le_nat_degree) (degree_X_pow_le _)) _,
rw [← with_bot.coe_add, this],
exact le_refl _ },
{ rw [leading_coeff, ← coeff_mul_X_pow p (n - nat_degree p), this] } }
end
theorem mem_leading_coeff_nth_zero (x) :
x ∈ I.leading_coeff_nth 0 ↔ C x ∈ I :=
(mem_leading_coeff_nth _ _ _).trans
⟨λ ⟨p, hpI, hpdeg, hpx⟩, by rwa [← hpx, leading_coeff,
nat.eq_zero_of_le_zero (nat_degree_le_of_degree_le hpdeg),
← eq_C_of_degree_le_zero hpdeg],
λ hx, ⟨C x, hx, degree_C_le, leading_coeff_C x⟩⟩
theorem leading_coeff_nth_mono {m n : ℕ} (H : m ≤ n) :
I.leading_coeff_nth m ≤ I.leading_coeff_nth n :=
begin
intros r hr,
simp only [submodule.mem_coe, mem_leading_coeff_nth] at hr ⊢,
rcases hr with ⟨p, hpI, hpdeg, rfl⟩,
refine ⟨p * X ^ (n - m), I.mul_mem_right hpI, _, leading_coeff_mul_X_pow⟩,
refine le_trans (degree_mul_le _ _) _,
refine le_trans (add_le_add' hpdeg (degree_X_pow_le _)) _,
rw [← with_bot.coe_add, nat.add_sub_cancel' H],
exact le_refl _
end
/-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the
leading coefficients in `I`. -/
def leading_coeff : ideal R :=
⨆ n : ℕ, I.leading_coeff_nth n
theorem mem_leading_coeff (x) :
x ∈ I.leading_coeff ↔ ∃ p ∈ I, polynomial.leading_coeff p = x :=
begin
rw [leading_coeff, submodule.mem_supr_of_directed],
simp only [mem_leading_coeff_nth],
{ split, { rintro ⟨i, p, hpI, hpdeg, rfl⟩, exact ⟨p, hpI, rfl⟩ },
rintro ⟨p, hpI, rfl⟩, exact ⟨nat_degree p, p, hpI, degree_le_nat_degree, rfl⟩ },
{ exact ⟨0⟩ },
intros i j, exact ⟨i + j, I.leading_coeff_nth_mono (nat.le_add_right _ _),
I.leading_coeff_nth_mono (nat.le_add_left _ _)⟩
end
theorem is_fg_degree_le [is_noetherian_ring R] (n : ℕ) :
submodule.fg (I.degree_le n) :=
is_noetherian_submodule_left.1 (is_noetherian_of_fg_of_noetherian _
⟨_, degree_le_eq_span_X_pow.symm⟩) _
end ideal
/-- Hilbert basis theorem. -/
theorem is_noetherian_ring_polynomial [is_noetherian_ring R] : is_noetherian_ring (polynomial R) :=
⟨assume I : ideal (polynomial R),
let L := I.leading_coeff in
let M := well_founded.min (is_noetherian_iff_well_founded.1 (by apply_instance))
(set.range I.leading_coeff_nth) (set.ne_empty_of_mem ⟨0, rfl⟩) in
have hm : M ∈ set.range I.leading_coeff_nth := well_founded.min_mem _ _ _,
let ⟨N, HN⟩ := hm, ⟨s, hs⟩ := I.is_fg_degree_le N in
have hm2 : ∀ k, I.leading_coeff_nth k ≤ M := λ k, or.cases_on (le_or_lt k N)
(λ h, HN ▸ I.leading_coeff_nth_mono h)
(λ h x hx, classical.by_contradiction $ λ hxm,
have ¬M < I.leading_coeff_nth k, by refine well_founded.not_lt_min
(well_founded_submodule_gt _ _) _ _ _; exact ⟨k, rfl⟩,
this ⟨HN ▸ I.leading_coeff_nth_mono (le_of_lt h), λ H, hxm (H hx)⟩),
have hs2 : ∀ {x}, x ∈ I.degree_le N → x ∈ ideal.span (↑s : set (polynomial R)),
from hs ▸ λ x hx, submodule.span_induction hx (λ _ hx, ideal.subset_span hx) (ideal.zero_mem _)
(λ _ _, ideal.add_mem _) (λ c f hf, f.C_mul' c ▸ ideal.mul_mem_left _ hf),
⟨s, le_antisymm (ideal.span_le.2 $ λ x hx, have x ∈ I.degree_le N, from hs ▸ submodule.subset_span hx, this.2) $ begin
change I ≤ ideal.span ↑s,
intros p hp, generalize hn : p.nat_degree = k,
induction k using nat.strong_induction_on with k ih generalizing p,
cases le_or_lt k N,
{ subst k, refine hs2 ⟨polynomial.mem_degree_le.2
(le_trans polynomial.degree_le_nat_degree $ with_bot.coe_le_coe.2 h), hp⟩ },
{ have hp0 : p ≠ 0,
{ rintro rfl, cases hn, exact nat.not_lt_zero _ h },
have : (0 : R) ≠ 1,
{ intro h, apply hp0, ext i, refine (mul_one _).symm.trans _,
rw [← h, mul_zero], refl },
letI : nonzero_comm_ring R := { zero_ne_one := this,
..(infer_instance : comm_ring R) },
have : p.leading_coeff ∈ I.leading_coeff_nth N,
{ rw HN, exact hm2 k ((I.mem_leading_coeff_nth _ _).2
⟨_, hp, hn ▸ polynomial.degree_le_nat_degree, rfl⟩) },
rw I.mem_leading_coeff_nth at this,
rcases this with ⟨q, hq, hdq, hlqp⟩,
have hq0 : q ≠ 0,
{ intro H, rw [← polynomial.leading_coeff_eq_zero] at H,
rw [hlqp, polynomial.leading_coeff_eq_zero] at H, exact hp0 H },
have h1 : p.degree = (q * polynomial.X ^ (k - q.nat_degree)).degree,
{ rw [polynomial.degree_mul_eq', polynomial.degree_X_pow],
rw [polynomial.degree_eq_nat_degree hp0, polynomial.degree_eq_nat_degree hq0],
rw [← with_bot.coe_add, nat.add_sub_cancel', hn],
{ refine le_trans (polynomial.nat_degree_le_of_degree_le hdq) (le_of_lt h) },
rw [polynomial.leading_coeff_X_pow, mul_one],
exact mt polynomial.leading_coeff_eq_zero.1 hq0 },
have h2 : p.leading_coeff = (q * polynomial.X ^ (k - q.nat_degree)).leading_coeff,
{ rw [← hlqp, polynomial.leading_coeff_mul_X_pow] },
have := polynomial.degree_sub_lt h1 hp0 h2,
rw [polynomial.degree_eq_nat_degree hp0] at this,
rw ← sub_add_cancel p (q * polynomial.X ^ (k - q.nat_degree)),
refine (ideal.span ↑s).add_mem _ ((ideal.span ↑s).mul_mem_right _),
{ by_cases hpq : p - q * polynomial.X ^ (k - q.nat_degree) = 0,
{ rw hpq, exact ideal.zero_mem _ },
refine ih _ _ (I.sub_mem hp (I.mul_mem_right hq)) rfl,
rwa [polynomial.degree_eq_nat_degree hpq, with_bot.coe_lt_coe, hn] at this },
exact hs2 ⟨polynomial.mem_degree_le.2 hdq, hq⟩ }
end⟩⟩
theorem is_noetherian_ring_mv_polynomial_fin {n : ℕ} [is_noetherian_ring R] :
is_noetherian_ring (mv_polynomial (fin n) R) :=
begin
induction n with n ih,
{ exact is_noetherian_ring_of_ring_equiv R
((mv_polynomial.pempty_ring_equiv R).symm.trans $ mv_polynomial.ring_equiv_of_equiv _
⟨pempty.elim, fin.elim0, λ x, pempty.elim x, λ x, fin.elim0 x⟩) },
exact @is_noetherian_ring_of_ring_equiv (polynomial (mv_polynomial (fin n) R)) _
(mv_polynomial (fin (n+1)) R) _
((mv_polynomial.option_equiv_left _ _).symm.trans (mv_polynomial.ring_equiv_of_equiv _
⟨λ x, option.rec_on x 0 fin.succ, λ x, fin.cases none some x,
by rintro ⟨none | x⟩; [refl, exact fin.cases_succ _],
λ x, fin.cases rfl (λ i, show (option.rec_on (fin.cases none some (fin.succ i) : option (fin n))
0 fin.succ : fin n.succ) = _, by rw fin.cases_succ) x⟩))
(@@is_noetherian_ring_polynomial _ _ ih)
end
theorem is_noetherian_ring_mv_polynomial_of_fintype {σ : Type v} [fintype σ] [decidable_eq σ]
[is_noetherian_ring R] : is_noetherian_ring (mv_polynomial σ R) :=
trunc.induction_on (fintype.equiv_fin σ) $ λ e,
@is_noetherian_ring_of_ring_equiv (mv_polynomial (fin (fintype.card σ)) R) _ _ _
(mv_polynomial.ring_equiv_of_equiv _ e.symm) is_noetherian_ring_mv_polynomial_fin
|
56ad86e1ad1d5ef81af7c3420f46b366d67630da | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/category_theory/concrete_category/basic.lean | 89dafd6dfb18c4d395b4f65d1621245797e864fc | [
"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 | 7,557 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johannes Hölzl, Reid Barton, Sean Leather, Yury Kudryashov
-/
import category_theory.types
import category_theory.epi_mono
/-!
# Concrete categories
A concrete category is a category `C` with a fixed faithful functor
`forget : C ⥤ Type*`. We define concrete categories using `class
concrete_category`. In particular, we impose no restrictions on the
carrier type `C`, so `Type` is a concrete category with the identity
forgetful functor.
Each concrete category `C` comes with a canonical faithful functor
`forget C : C ⥤ Type*`. We say that a concrete category `C` admits a
*forgetful functor* to a concrete category `D`, if it has a functor
`forget₂ C D : C ⥤ D` such that `(forget₂ C D) ⋙ (forget D) = forget C`,
see `class has_forget₂`. Due to `faithful.div_comp`, it suffices
to verify that `forget₂.obj` and `forget₂.map` agree with the equality
above; then `forget₂` will satisfy the functor laws automatically, see
`has_forget₂.mk'`.
Two classes helping construct concrete categories in the two most
common cases are provided in the files `bundled_hom` and
`unbundled_hom`, see their documentation for details.
## References
See [Ahrens and Lumsdaine, *Displayed Categories*][ahrens2017] for
related work.
-/
universes w v v' u
namespace category_theory
/--
A concrete category is a category `C` with a fixed faithful functor `forget : C ⥤ Type`.
Note that `concrete_category` potentially depends on three independent universe levels,
* the universe level `w` appearing in `forget : C ⥤ Type w`
* the universe level `v` of the morphisms (i.e. we have a `category.{v} C`)
* the universe level `u` of the objects (i.e `C : Type u`)
They are specified that order, to avoid unnecessary universe annotations.
-/
class concrete_category (C : Type u) [category.{v} C] :=
(forget [] : C ⥤ Type w)
[forget_faithful : faithful forget]
attribute [instance] concrete_category.forget_faithful
/-- The forgetful functor from a concrete category to `Type u`. -/
@[reducible] def forget (C : Type v) [category C] [concrete_category.{u} C] : C ⥤ Type u :=
concrete_category.forget C
instance concrete_category.types : concrete_category (Type u) :=
{ forget := 𝟭 _ }
/--
Provide a coercion to `Type u` for a concrete category. This is not marked as an instance
as it could potentially apply to every type, and so is too expensive in typeclass search.
You can use it on particular examples as:
```
instance : has_coe_to_sort X := concrete_category.has_coe_to_sort X
```
-/
def concrete_category.has_coe_to_sort (C : Type v) [category C] [concrete_category C] :
has_coe_to_sort C :=
{ S := Type u, coe := (concrete_category.forget C).obj }
section
local attribute [instance] concrete_category.has_coe_to_sort
variables {C : Type v} [category C] [concrete_category C]
@[simp] lemma forget_obj_eq_coe {X : C} : (forget C).obj X = X := rfl
/-- Usually a bundled hom structure already has a coercion to function
that works with different universes. So we don't use this as a global instance. -/
def concrete_category.has_coe_to_fun {X Y : C} : has_coe_to_fun (X ⟶ Y) :=
{ F := λ f, X → Y,
coe := λ f, (forget _).map f }
local attribute [instance] concrete_category.has_coe_to_fun
/-- In any concrete category, we can test equality of morphisms by pointwise evaluations.-/
lemma concrete_category.hom_ext {X Y : C} (f g : X ⟶ Y) (w : ∀ x : X, f x = g x) : f = g :=
begin
apply faithful.map_injective (forget C),
ext,
exact w x,
end
@[simp] lemma forget_map_eq_coe {X Y : C} (f : X ⟶ Y) : (forget C).map f = f := rfl
/--
Analogue of `congr_fun h x`,
when `h : f = g` is an equality between morphisms in a concrete category.
-/
lemma congr_hom {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x :=
congr_fun (congr_arg (λ k : X ⟶ Y, (k : X → Y)) h) x
@[simp] lemma coe_id {X : C} (x : X) : ((𝟙 X) : X → X) x = x :=
congr_fun ((forget _).map_id X) x
@[simp] lemma coe_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) :
(f ≫ g) x = g (f x) :=
congr_fun ((forget _).map_comp _ _) x
@[simp] lemma coe_hom_inv_id {X Y : C} (f : X ≅ Y) (x : X) :
f.inv (f.hom x) = x :=
congr_fun ((forget C).map_iso f).hom_inv_id x
@[simp] lemma coe_inv_hom_id {X Y : C} (f : X ≅ Y) (y : Y) :
f.hom (f.inv y) = y :=
congr_fun ((forget C).map_iso f).inv_hom_id y
lemma concrete_category.congr_hom {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x :=
congr_fun (congr_arg (λ f : X ⟶ Y, (f : X → Y)) h) x
lemma concrete_category.congr_arg {X Y : C} (f : X ⟶ Y) {x x' : X} (h : x = x') : f x = f x' :=
congr_arg (f : X → Y) h
/-- In any concrete category, injective morphisms are monomorphisms. -/
lemma concrete_category.mono_of_injective {X Y : C} (f : X ⟶ Y) (i : function.injective f) :
mono f :=
faithful_reflects_mono (forget C) ((mono_iff_injective f).2 i)
/-- In any concrete category, surjective morphisms are epimorphisms. -/
lemma concrete_category.epi_of_surjective {X Y : C} (f : X ⟶ Y) (s : function.surjective f) :
epi f :=
faithful_reflects_epi (forget C) ((epi_iff_surjective f).2 s)
@[simp] lemma concrete_category.has_coe_to_fun_Type {X Y : Type u} (f : X ⟶ Y) :
coe_fn f = f :=
rfl
end
/--
`has_forget₂ C D`, where `C` and `D` are both concrete categories, provides a functor
`forget₂ C D : C ⥤ D` and a proof that `forget₂ ⋙ (forget D) = forget C`.
-/
class has_forget₂ (C : Type v) (D : Type v') [category C] [concrete_category.{u} C] [category D]
[concrete_category.{u} D] :=
(forget₂ : C ⥤ D)
(forget_comp : forget₂ ⋙ (forget D) = forget C . obviously)
/-- The forgetful functor `C ⥤ D` between concrete categories for which we have an instance
`has_forget₂ C `. -/
@[reducible] def forget₂ (C : Type v) (D : Type v') [category C] [concrete_category C] [category D]
[concrete_category D] [has_forget₂ C D] : C ⥤ D :=
has_forget₂.forget₂
instance forget_faithful (C : Type v) (D : Type v') [category C] [concrete_category C] [category D]
[concrete_category D] [has_forget₂ C D] : faithful (forget₂ C D) :=
has_forget₂.forget_comp.faithful_of_comp
instance induced_category.concrete_category {C : Type v} {D : Type v'} [category D]
[concrete_category D] (f : C → D) :
concrete_category (induced_category D f) :=
{ forget := induced_functor f ⋙ forget D }
instance induced_category.has_forget₂ {C : Type v} {D : Type v'} [category D] [concrete_category D]
(f : C → D) :
has_forget₂ (induced_category D f) D :=
{ forget₂ := induced_functor f,
forget_comp := rfl }
/--
In order to construct a “partially forgetting” functor, we do not need to verify functor laws;
it suffices to ensure that compositions agree with `forget₂ C D ⋙ forget D = forget C`.
-/
def has_forget₂.mk' {C : Type v} {D : Type v'} [category C] [concrete_category C] [category D]
[concrete_category D] (obj : C → D) (h_obj : ∀ X, (forget D).obj (obj X) = (forget C).obj X)
(map : Π {X Y}, (X ⟶ Y) → (obj X ⟶ obj Y))
(h_map : ∀ {X Y} {f : X ⟶ Y}, (forget D).map (map f) == (forget C).map f) :
has_forget₂ C D :=
{ forget₂ := faithful.div _ _ _ @h_obj _ @h_map,
forget_comp := by apply faithful.div_comp }
instance has_forget_to_Type (C : Type v) [category C] [concrete_category C] :
has_forget₂ C (Type u) :=
{ forget₂ := forget C,
forget_comp := functor.comp_id _ }
end category_theory
|
07b51367915a49822c6a02c302df04debcffae71 | 9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e | /src/undergraduate/MAS114/Semester 1/Q10.lean | 9ea596c3664ebd1faa4e5b2a1fb45b576170bc4a | [] | no_license | agusakov/lean_lib | c0e9cc29fc7d2518004e224376adeb5e69b5cc1a | f88d162da2f990b87c4d34f5f46bbca2bbc5948e | refs/heads/master | 1,642,141,461,087 | 1,557,395,798,000 | 1,557,395,798,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,245 | lean | import data.real.basic data.fintype algebra.big_operators data.nat.modeq
import tactic.find tactic.squeeze
namespace MAS114
namespace exercises_1
namespace Q10
def f : ℝ → ℝ := λ x, x ^ 2 - 7 * x + 10
def f_alt : ℝ → ℝ := λ x, (x - 2) * (x - 5)
lemma f_eq (x : ℝ) : f x = f_alt x := by {dsimp[f,f_alt],ring}
lemma f_two : f 2 = 0 := by {dsimp[f],ring}
lemma f_five : f 5 = 0 := by {dsimp[f],ring}
lemma two_ne_five : (2 : ℝ) ≠ (5 : ℝ) :=
begin
intro e,
have h2 : (2 : ℝ) = ((2 : ℕ) : ℝ) := by {simp},
have h5 : (5 : ℝ) = ((5 : ℕ) : ℝ) := by {simp},
rw[h5,h2] at e,
exact (dec_trivial : 2 ≠ 5) (nat.cast_inj.mp e),
end
def P1 (x : ℝ) : Prop := f x = 0 → x = 2 ∧ x = 5
def P2 (x : ℝ) : Prop := f x = 0 → x = 2 ∨ x = 5
lemma L1 : ¬ (∀ x : ℝ, P1 x) :=
begin
intro h_P1,
exact two_ne_five (h_P1 2 f_two).right,
end
lemma L2 : ∀ x : ℝ, P2 x :=
begin
intros x fx,
rw[f_eq x] at fx,
dsimp[f_alt] at fx,
rcases eq_zero_or_eq_zero_of_mul_eq_zero fx with x_eq_2 | x_eq_5,
{rw[← sub_eq_add_neg] at x_eq_2,
exact or.inl (sub_eq_zero.mp x_eq_2),
},{
rw[← sub_eq_add_neg] at x_eq_5,
exact or.inr (sub_eq_zero.mp x_eq_5),
}
end
end Q10
end exercises_1
end MAS114 |
02b12f81b637a4b94c4ddf8325baf5149b6610a8 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /tests/lean/run/inj2.lean | 5fbec4ecf0dbb6a3262c8a82da081822aa820ca0 | [
"Apache-2.0"
] | permissive | WojciechKarpiel/lean4 | 7f89706b8e3c1f942b83a2c91a3a00b05da0e65b | f6e1314fa08293dea66a329e05b6c196a0189163 | refs/heads/master | 1,686,633,402,214 | 1,625,821,189,000 | 1,625,821,258,000 | 384,640,886 | 0 | 0 | Apache-2.0 | 1,625,903,617,000 | 1,625,903,026,000 | null | UTF-8 | Lean | false | false | 1,129 | lean | universe u v
inductive Vec2 (α : Type u) (β : Type v) : Nat → Type (max u v)
| nil : Vec2 α β 0
| cons : α → β → forall {n}, Vec2 α β n → Vec2 α β (n+1)
inductive Fin2 : Nat → Type
| zero (n : Nat) : Fin2 (n+1)
| succ {n : Nat} (s : Fin2 n) : Fin2 (n+1)
theorem test1 {α β} {n} (a₁ a₂ : α) (b₁ b₂ : β) (v w : Vec2 α β n) (h : Vec2.cons a₁ b₁ v = Vec2.cons a₂ b₂ w) : a₁ = a₂ :=
by {
injection h;
assumption
}
theorem test2 {α β} {n} (a₁ a₂ : α) (b₁ b₂ : β) (v w : Vec2 α β n) (h : Vec2.cons a₁ b₁ v = Vec2.cons a₂ b₂ w) : v = w :=
by {
injection h with h1 h2 h3 h4;
assumption
}
theorem test3 {α β} {n} (a₁ a₂ : α) (b₁ b₂ : β) (v w : Vec2 α β n) (h : Vec2.cons a₁ b₁ v = Vec2.cons a₂ b₂ w) : v = w :=
by {
injection h with _ _ _ h4;
exact h4
}
theorem test4 {α} (v : Fin2 0) : α :=
by cases v
def test5 {α β} {n} (v : Vec2 α β (n+1)) : α := by
cases v with
| cons h1 h2 n tail => exact h1
def test6 {α β} {n} (v : Vec2 α β (n+2)) : α := by
cases v with
| cons h1 h2 n tail => exact h1
|
c1c68e910233ecb22b15da29198c774f3a6f04e4 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/set_theory/cardinal/basic.lean | d3d08052171f7aef3339d3c70d6c28d9951b2a24 | [
"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 | 73,725 | 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, Floris van Doorn
-/
import data.fintype.big_operators
import data.finsupp.defs
import data.nat.part_enat
import data.set.countable
import logic.small.basic
import order.conditionally_complete_lattice.basic
import order.succ_pred.limit
import set_theory.cardinal.schroeder_bernstein
import tactic.positivity
/-!
# Cardinal Numbers
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity.
## Main definitions
* `cardinal` the type of cardinal numbers (in a given universe).
* `cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale
`cardinal`.
* Addition `c₁ + c₂` is defined by `cardinal.add_def α β : #α + #β = #(α ⊕ β)`.
* Multiplication `c₁ * c₂` is defined by `cardinal.mul_def : #α * #β = #(α × β)`.
* The order `c₁ ≤ c₂` is defined by `cardinal.le_def α β : #α ≤ #β ↔ nonempty (α ↪ β)`.
* Exponentiation `c₁ ^ c₂` is defined by `cardinal.power_def α β : #α ^ #β = #(β → α)`.
* `cardinal.is_limit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`.
* `cardinal.aleph_0` or `ℵ₀` is the cardinality of `ℕ`. This definition is universe polymorphic:
`cardinal.aleph_0.{u} : cardinal.{u}` (contrast with `ℕ : Type`, which lives in a specific
universe). In some cases the universe level has to be given explicitly.
* `cardinal.sum` is the sum of an indexed family of cardinals, i.e. the cardinality of the
corresponding sigma type.
* `cardinal.prod` is the product of an indexed family of cardinals, i.e. the cardinality of the
corresponding pi type.
* `cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`.
## Main instances
* Cardinals form a `canonically_ordered_comm_semiring` with the aforementioned sum and product.
* Cardinals form a `succ_order`. Use `order.succ c` for the smallest cardinal greater than `c`.
* The less than relation on cardinals forms a well-order.
* Cardinals form a `conditionally_complete_linear_order_bot`. Bounded sets for cardinals in universe
`u` are precisely the sets indexed by some type in universe `u`, see
`cardinal.bdd_above_iff_small`. One can use `Sup` for the cardinal supremum, and `Inf` for the
minimum of a set of cardinals.
## Main Statements
* Cantor's theorem: `cardinal.cantor c : c < 2 ^ c`.
* König's theorem: `cardinal.sum_lt_prod`
## 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`.
The operation `cardinal.lift` lifts cardinal numbers to a higher level.
* Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file
`set_theory/cardinal_ordinal.lean`.
* There is an instance `has_pow cardinal`, but this will only fire if Lean already knows that both
the base and the exponent live in the same universe. As a workaround, you can add
```
local infixr (name := cardinal.pow) ^ := @has_pow.pow cardinal cardinal cardinal.has_pow
```
to a file. This notation will work even if Lean doesn't know yet that the base and the exponent
live in the same universe (but no exponents in other types can be used).
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, aleph,
Cantor's theorem, König's theorem, Konig's theorem
-/
open function set order
open_locale big_operators classical
noncomputable theory
universes u v w
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 "prefix (name := cardinal.mk) `#` := cardinal.mk" in cardinal
instance can_lift_cardinal_Type : can_lift cardinal.{u} (Type u) mk (λ _, true) :=
⟨λ c _, quot.induction_on c $ λ α, ⟨α, rfl⟩⟩
@[elab_as_eliminator]
lemma induction_on {p : cardinal → Prop} (c : cardinal) (h : ∀ α, p (#α)) : p c :=
quotient.induction_on c h
@[elab_as_eliminator]
lemma induction_on₂ {p : cardinal → cardinal → Prop} (c₁ : cardinal) (c₂ : cardinal)
(h : ∀ α β, p (#α) (#β)) : p c₁ c₂ :=
quotient.induction_on₂ c₁ c₂ h
@[elab_as_eliminator]
lemma induction_on₃ {p : cardinal → cardinal → cardinal → Prop} (c₁ : cardinal) (c₂ : cardinal)
(c₃ : cardinal) (h : ∀ α β γ, p (#α) (#β) (#γ)) : p c₁ c₂ c₃ :=
quotient.induction_on₃ c₁ c₂ c₃ h
protected lemma eq : #α = #β ↔ nonempty (α ≃ β) := quotient.eq
@[simp] theorem mk_def (α : Type u) : @eq cardinal ⟦α⟧ (#α) := rfl
@[simp] theorem mk_out (c : cardinal) : #(c.out) = c := quotient.out_eq _
/-- The representative of the cardinal of a type is equivalent ot the original type. -/
def out_mk_equiv {α : Type v} : (#α).out ≃ α :=
nonempty.some $ cardinal.eq.mp (by simp)
lemma mk_congr (e : α ≃ β) : # α = # β := quot.sound ⟨e⟩
alias mk_congr ← _root_.equiv.cardinal_eq
/-- Lift a function between `Type*`s to a function between `cardinal`s. -/
def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) :
cardinal.{u} → cardinal.{v} :=
quotient.map f (λ α β ⟨e⟩, ⟨hf α β e⟩)
@[simp] lemma map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) :
map f hf (#α) = #(f α) := rfl
/-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `cardinal`s. -/
def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) :
cardinal.{u} → cardinal.{v} → cardinal.{w} :=
quotient.map₂ f $ λ α β ⟨e₁⟩ γ δ ⟨e₂⟩, ⟨hf α β γ δ e₁ e₂⟩
/-- The universe lift operation on cardinals. You can specify the universes explicitly with
`lift.{u v} : cardinal.{v} → cardinal.{max v u}` -/
def lift (c : cardinal.{v}) : cardinal.{max v u} :=
map ulift (λ α β e, equiv.ulift.trans $ e.trans equiv.ulift.symm) c
@[simp] theorem mk_ulift (α) : #(ulift.{v u} α) = lift.{v} (#α) := rfl
/-- `lift.{(max u v) u}` equals `lift.{v u}`. Using `set_option pp.universes true` will make it much
easier to understand what's happening when using this lemma. -/
@[simp] theorem lift_umax : lift.{(max u v) u} = lift.{v u} :=
funext $ λ a, induction_on a $ λ α, (equiv.ulift.trans equiv.ulift.symm).cardinal_eq
/-- `lift.{(max v u) u}` equals `lift.{v u}`. Using `set_option pp.universes true` will make it much
easier to understand what's happening when using this lemma. -/
@[simp] theorem lift_umax' : lift.{(max v u) u} = lift.{v u} := lift_umax
/-- A cardinal lifted to a lower or equal universe equals itself. -/
@[simp] theorem lift_id' (a : cardinal.{max u v}) : lift.{u} a = a :=
induction_on a $ λ α, mk_congr equiv.ulift
/-- A cardinal lifted to the same universe equals itself. -/
@[simp] theorem lift_id (a : cardinal) : lift.{u u} a = a := lift_id'.{u u} a
/-- A cardinal lifted to the zero universe equals itself. -/
@[simp] theorem lift_uzero (a : cardinal.{u}) : lift.{0} a = a := lift_id'.{0 u} a
@[simp] theorem lift_lift (a : cardinal) :
lift.{w} (lift.{v} a) = lift.{max v w} a :=
induction_on a $ λ α,
(equiv.ulift.trans $ equiv.ulift.trans equiv.ulift.symm).cardinal_eq
/-- We define the order on cardinal numbers by `#α ≤ #β` 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 $ α ↪ β) $
λ α β γ δ ⟨e₁⟩ ⟨e₂⟩, propext ⟨λ ⟨e⟩, ⟨e.congr e₁ e₂⟩, λ ⟨e⟩, ⟨e.congr e₁.symm e₂.symm⟩⟩⟩
instance : partial_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₂) }, }
instance : linear_order cardinal.{u} :=
{ le_total := by { rintros ⟨α⟩ ⟨β⟩, apply embedding.total },
decidable_le := classical.dec_rel _,
..cardinal.partial_order.{u}, }
theorem le_def (α β : Type u) : #α ≤ #β ↔ nonempty (α ↪ β) :=
iff.rfl
theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : injective f) : #α ≤ #β :=
⟨⟨f, hf⟩⟩
theorem _root_.function.embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β := ⟨f⟩
theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : surjective f) : #β ≤ #α :=
⟨embedding.of_surjective f hf⟩
theorem le_mk_iff_exists_set {c : cardinal} {α : Type u} :
c ≤ #α ↔ ∃ p : set α, #p = c :=
⟨induction_on c $ λ β ⟨⟨f, hf⟩⟩,
⟨set.range f, (equiv.of_injective f hf).cardinal_eq.symm⟩,
λ ⟨p, e⟩, e ▸ ⟨⟨subtype.val, λ a b, subtype.eq⟩⟩⟩
theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(subtype p) ≤ #α :=
⟨embedding.subtype p⟩
theorem mk_set_le (s : set α) : #s ≤ #α :=
mk_subtype_le s
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 }
theorem lift_mk_le {α : Type u} {β : Type v} :
lift.{max v w} (#α) ≤ lift.{max u w} (#β) ↔ nonempty (α ↪ β) :=
⟨λ ⟨f⟩, ⟨embedding.congr equiv.ulift equiv.ulift f⟩,
λ ⟨f⟩, ⟨embedding.congr equiv.ulift.symm equiv.ulift.symm f⟩⟩
/-- A variant of `cardinal.lift_mk_le` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_le' {α : Type u} {β : Type v} :
lift.{v} (#α) ≤ lift.{u} (#β) ↔ nonempty (α ↪ β) :=
lift_mk_le.{u v 0}
theorem lift_mk_eq {α : Type u} {β : Type v} :
lift.{max v w} (#α) = lift.{max u w} (#β) ↔ nonempty (α ≃ β) :=
quotient.eq.trans
⟨λ ⟨f⟩, ⟨equiv.ulift.symm.trans $ f.trans equiv.ulift⟩,
λ ⟨f⟩, ⟨equiv.ulift.trans $ f.trans equiv.ulift.symm⟩⟩
/-- A variant of `cardinal.lift_mk_eq` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_eq' {α : Type u} {β : Type v} :
lift.{v} (#α) = lift.{u} (#β) ↔ nonempty (α ≃ β) :=
lift_mk_eq.{u v 0}
@[simp] theorem lift_le {a b : cardinal} : lift a ≤ lift b ↔ a ≤ b :=
induction_on₂ a b $ λ α β, by { rw ← lift_umax, exact lift_mk_le }
/-- `cardinal.lift` as an `order_embedding`. -/
@[simps { fully_applied := ff }] def lift_order_embedding : cardinal.{v} ↪o cardinal.{max v u} :=
order_embedding.of_map_le_iff lift (λ _ _, lift_le)
theorem lift_injective : injective lift.{u v} := lift_order_embedding.injective
@[simp] theorem lift_inj {a b : cardinal} : lift a = lift b ↔ a = b :=
lift_injective.eq_iff
@[simp] theorem lift_lt {a b : cardinal} : lift a < lift b ↔ a < b :=
lift_order_embedding.lt_iff_lt
theorem lift_strict_mono : strict_mono lift :=
λ a b, lift_lt.2
theorem lift_monotone : monotone lift :=
lift_strict_mono.monotone
instance : has_zero cardinal.{u} := ⟨#pempty⟩
instance : inhabited cardinal.{u} := ⟨0⟩
lemma mk_eq_zero (α : Type u) [is_empty α] : #α = 0 :=
(equiv.equiv_pempty α).cardinal_eq
@[simp] theorem lift_zero : lift 0 = 0 := mk_congr (equiv.equiv_pempty _)
@[simp] theorem lift_eq_zero {a : cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 :=
lift_injective.eq_iff' lift_zero
lemma mk_eq_zero_iff {α : Type u} : #α = 0 ↔ is_empty α :=
⟨λ e, let ⟨h⟩ := quotient.exact e in h.is_empty, @mk_eq_zero α⟩
theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ nonempty α :=
(not_iff_not.2 mk_eq_zero_iff).trans not_is_empty_iff
@[simp] lemma mk_ne_zero (α : Type u) [nonempty α] : #α ≠ 0 := mk_ne_zero_iff.2 ‹_›
instance : has_one cardinal.{u} := ⟨#punit⟩
instance : nontrivial cardinal.{u} := ⟨⟨1, 0, mk_ne_zero _⟩⟩
lemma mk_eq_one (α : Type u) [unique α] : #α = 1 :=
(equiv.equiv_punit α).cardinal_eq
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ subsingleton α :=
⟨λ ⟨f⟩, ⟨λ a b, f.injective (subsingleton.elim _ _)⟩,
λ ⟨h⟩, ⟨⟨λ a, punit.star, λ a b _, h _ _⟩⟩⟩
@[simp] lemma mk_le_one_iff_set_subsingleton {s : set α} : #s ≤ 1 ↔ s.subsingleton :=
le_one_iff_subsingleton.trans s.subsingleton_coe
alias mk_le_one_iff_set_subsingleton ↔ _ _root_.set.subsingleton.cardinal_mk_le_one
instance : has_add cardinal.{u} := ⟨map₂ sum $ λ α β γ δ, equiv.sum_congr⟩
theorem add_def (α β : Type u) : #α + #β = #(α ⊕ β) := rfl
instance : has_nat_cast cardinal.{u} := ⟨nat.unary_cast⟩
@[simp] lemma mk_sum (α : Type u) (β : Type v) :
#(α ⊕ β) = lift.{v u} (#α) + lift.{u v} (#β) :=
mk_congr ((equiv.ulift).symm.sum_congr (equiv.ulift).symm)
@[simp] theorem mk_option {α : Type u} : #(option α) = #α + 1 :=
(equiv.option_equiv_sum_punit α).cardinal_eq
@[simp] lemma mk_psum (α : Type u) (β : Type v) : #(psum α β) = lift.{v} (#α) + lift.{u} (#β) :=
(mk_congr (equiv.psum_equiv_sum α β)).trans (mk_sum α β)
@[simp] lemma mk_fintype (α : Type u) [fintype α] : #α = fintype.card α :=
begin
refine fintype.induction_empty_option _ _ _ α,
{ introsI α β h e hα, letI := fintype.of_equiv β e.symm,
rwa [mk_congr e, fintype.card_congr e] at hα },
{ refl },
{ introsI α h hα, simp [hα], refl }
end
instance : has_mul cardinal.{u} := ⟨map₂ prod $ λ α β γ δ, equiv.prod_congr⟩
theorem mul_def (α β : Type u) : #α * #β = #(α × β) := rfl
@[simp] lemma mk_prod (α : Type u) (β : Type v) :
#(α × β) = lift.{v u} (#α) * lift.{u v} (#β) :=
mk_congr (equiv.ulift.symm.prod_congr (equiv.ulift).symm)
private theorem mul_comm' (a b : cardinal.{u}) : a * b = b * a :=
induction_on₂ a b $ λ α β, mk_congr $ equiv.prod_comm α β
/-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/
instance : has_pow cardinal.{u} cardinal.{u} :=
⟨map₂ (λ α β, β → α) (λ α β γ δ e₁ e₂, e₂.arrow_congr e₁)⟩
local infixr (name := cardinal.pow) ^ := @has_pow.pow cardinal cardinal cardinal.has_pow
local infixr (name := cardinal.pow.nat) ` ^ℕ `:80 := @has_pow.pow cardinal ℕ monoid.has_pow
theorem power_def (α β) : #α ^ #β = #(β → α) := rfl
theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = lift.{u} (#β) ^ lift.{v} (#α) :=
mk_congr (equiv.ulift.symm.arrow_congr equiv.ulift.symm)
@[simp] theorem lift_power (a b) : lift (a ^ b) = lift a ^ lift b :=
induction_on₂ a b $ λ α β,
mk_congr $ equiv.ulift.trans (equiv.ulift.arrow_congr equiv.ulift).symm
@[simp] theorem power_zero {a : cardinal} : a ^ 0 = 1 :=
induction_on a $ λ α, mk_congr $ equiv.pempty_arrow_equiv_punit α
@[simp] theorem power_one {a : cardinal} : a ^ 1 = a :=
induction_on a $ λ α, mk_congr $ equiv.punit_arrow_equiv α
theorem power_add {a b c : cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
induction_on₃ a b c $ λ α β γ, mk_congr $ equiv.sum_arrow_equiv_prod_arrow β γ α
instance : comm_semiring cardinal.{u} :=
{ zero := 0,
one := 1,
add := (+),
mul := (*),
zero_add := λ a, induction_on a $ λ α, mk_congr $ equiv.empty_sum pempty α,
add_zero := λ a, induction_on a $ λ α, mk_congr $ equiv.sum_empty α pempty,
add_assoc := λ a b c, induction_on₃ a b c $ λ α β γ, mk_congr $ equiv.sum_assoc α β γ,
add_comm := λ a b, induction_on₂ a b $ λ α β, mk_congr $ equiv.sum_comm α β,
zero_mul := λ a, induction_on a $ λ α, mk_congr $ equiv.pempty_prod α,
mul_zero := λ a, induction_on a $ λ α, mk_congr $ equiv.prod_pempty α,
one_mul := λ a, induction_on a $ λ α, mk_congr $ equiv.punit_prod α,
mul_one := λ a, induction_on a $ λ α, mk_congr $ equiv.prod_punit α,
mul_assoc := λ a b c, induction_on₃ a b c $ λ α β γ, mk_congr $ equiv.prod_assoc α β γ,
mul_comm := mul_comm',
left_distrib := λ a b c, induction_on₃ a b c $ λ α β γ, mk_congr $ equiv.prod_sum_distrib α β γ,
right_distrib := λ a b c, induction_on₃ a b c $ λ α β γ, mk_congr $ equiv.sum_prod_distrib α β γ,
npow := λ n c, c ^ n,
npow_zero' := @power_zero,
npow_succ' := λ n c, show c ^ (n + 1) = c * c ^ n, by rw [power_add, power_one, mul_comm'] }
theorem power_bit0 (a b : cardinal) : a ^ (bit0 b) = a ^ b * a ^ b :=
power_add
theorem power_bit1 (a b : cardinal) : a ^ (bit1 b) = a ^ b * a ^ b * a :=
by rw [bit1, ←power_bit0, power_add, power_one]
@[simp] theorem one_power {a : cardinal} : 1 ^ a = 1 :=
induction_on a $ λ α, (equiv.arrow_punit_equiv_punit α).cardinal_eq
@[simp] theorem mk_bool : #bool = 2 := by simp
@[simp] theorem mk_Prop : #(Prop) = 2 := by simp
@[simp] theorem zero_power {a : cardinal} : a ≠ 0 → 0 ^ a = 0 :=
induction_on a $ λ α heq, mk_eq_zero_iff.2 $ is_empty_pi.2 $
let ⟨a⟩ := mk_ne_zero_iff.1 heq in ⟨a, pempty.is_empty⟩
theorem power_ne_zero {a : cardinal} (b) : a ≠ 0 → a ^ b ≠ 0 :=
induction_on₂ a b $ λ α β h,
let ⟨a⟩ := mk_ne_zero_iff.1 h in mk_ne_zero_iff.2 ⟨λ _, a⟩
theorem mul_power {a b c : cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
induction_on₃ a b c $ λ α β γ, mk_congr $ equiv.arrow_prod_equiv_prod_arrow α β γ
theorem power_mul {a b c : cardinal} : a ^ (b * c) = (a ^ b) ^ c :=
by { rw [mul_comm b c], exact induction_on₃ a b c (λ α β γ, mk_congr $ equiv.curry γ β α) }
@[simp] lemma pow_cast_right (a : cardinal.{u}) (n : ℕ) : (a ^ (↑n : cardinal.{u})) = a ^ℕ n :=
rfl
@[simp] theorem lift_one : lift 1 = 1 :=
mk_congr $ equiv.ulift.trans equiv.punit_equiv_punit
@[simp] theorem lift_add (a b) : lift (a + b) = lift a + lift b :=
induction_on₂ a b $ λ α β,
mk_congr $ equiv.ulift.trans (equiv.sum_congr equiv.ulift equiv.ulift).symm
@[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b :=
induction_on₂ a b $ λ α β,
mk_congr $ equiv.ulift.trans (equiv.prod_congr equiv.ulift equiv.ulift).symm
@[simp] theorem lift_bit0 (a : cardinal) : lift (bit0 a) = bit0 (lift a) :=
lift_add a a
@[simp] theorem lift_bit1 (a : cardinal) : lift (bit1 a) = bit1 (lift a) :=
by simp [bit1]
theorem lift_two : lift.{u v} 2 = 2 := by simp
@[simp] theorem mk_set {α : Type u} : #(set α) = 2 ^ #α := by simp [set, mk_arrow]
/-- A variant of `cardinal.mk_set` expressed in terms of a `set` instead of a `Type`. -/
@[simp] theorem mk_powerset {α : Type u} (s : set α) : #↥(𝒫 s) = 2 ^ #↥s :=
(mk_congr (equiv.set.powerset s)).trans mk_set
theorem lift_two_power (a) : lift (2 ^ a) = 2 ^ lift a := by simp
section order_properties
open sum
protected theorem zero_le : ∀ a : cardinal, 0 ≤ a :=
by rintro ⟨α⟩; exact ⟨embedding.of_is_empty⟩
private 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₂⟩
instance add_covariant_class : covariant_class cardinal cardinal (+) (≤) :=
⟨λ a b c, add_le_add' le_rfl⟩
instance add_swap_covariant_class : covariant_class cardinal cardinal (swap (+)) (≤) :=
⟨λ a b c h, add_le_add' h le_rfl⟩
instance : canonically_ordered_comm_semiring cardinal.{u} :=
{ bot := 0,
bot_le := cardinal.zero_le,
add_le_add_left := λ a b, add_le_add_left,
exists_add_of_le := λ a b, induction_on₂ a b $ λ α β ⟨⟨f, hf⟩⟩,
have (α ⊕ ((range f)ᶜ : set β)) ≃ β, from
(equiv.sum_congr (equiv.of_injective f hf) (equiv.refl _)).trans $
(equiv.set.sum_compl (range f)),
⟨#↥(range f)ᶜ, mk_congr this.symm⟩,
le_self_add := λ a b, (add_zero a).ge.trans $ add_le_add_left (cardinal.zero_le _) _,
eq_zero_or_eq_zero_of_mul_eq_zero := λ a b, induction_on₂ a b $ λ α β,
by simpa only [mul_def, mk_eq_zero_iff, is_empty_prod] using id,
..cardinal.comm_semiring, ..cardinal.partial_order }
instance : canonically_linear_ordered_add_monoid cardinal.{u} :=
{ ..cardinal.canonically_ordered_comm_semiring,
..cardinal.linear_order }
-- Computable instance to prevent a non-computable one being found via the one above
instance : canonically_ordered_add_monoid cardinal.{u} :=
{ ..cardinal.canonically_ordered_comm_semiring }
instance : linear_ordered_comm_monoid_with_zero cardinal.{u} :=
{ mul_le_mul_left := @mul_le_mul_left' _ _ _ _,
zero_le_one := zero_le _,
..cardinal.comm_semiring,
..cardinal.linear_order }
-- Computable instance to prevent a non-computable one being found via the one above
instance : comm_monoid_with_zero cardinal.{u} :=
{ ..cardinal.canonically_ordered_comm_semiring }
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 power_le_power_left : ∀ {a b c : cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩; exact
let ⟨a⟩ := mk_ne_zero_iff.1 hα in
⟨@embedding.arrow_congr_left _ _ _ ⟨a⟩ e⟩
theorem self_le_power (a : cardinal) {b : cardinal} (hb : 1 ≤ b) : a ≤ a ^ b :=
begin
rcases eq_or_ne a 0 with rfl|ha,
{ exact zero_le _ },
{ convert power_le_power_left ha hb, exact power_one.symm }
end
/-- **Cantor's theorem** -/
theorem cantor (a : cardinal.{u}) : a < 2 ^ a :=
begin
induction a using cardinal.induction_on with α,
rw [← mk_set],
refine ⟨⟨⟨singleton, λ a b, singleton_eq_singleton_iff.1⟩⟩, _⟩,
rintro ⟨⟨f, hf⟩⟩,
exact cantor_injective f hf
end
instance : no_max_order cardinal.{u} :=
{ exists_gt := λ a, ⟨_, cantor a⟩ }
-- short-circuit type class inference
instance : distrib_lattice cardinal.{u} := by apply_instance
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ nontrivial α :=
by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, not_not]
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 (power_le_power_left ha h).trans (le_max_left _ _)
end
theorem power_le_power_right {a b c : cardinal} : a ≤ b → a ^ c ≤ b ^ c :=
induction_on₃ a b c $ λ α β γ ⟨e⟩, ⟨embedding.arrow_congr_right e⟩
theorem power_pos {a : cardinal} (b) (ha : 0 < a) : 0 < a ^ b := (power_ne_zero _ ha.ne').bot_lt
end order_properties
protected theorem lt_wf : @well_founded cardinal.{u} (<) :=
⟨λ a, classical.by_contradiction $ λ h, begin
let ι := {c : cardinal // ¬ acc (<) c},
let f : ι → cardinal := subtype.val,
haveI hι : nonempty ι := ⟨⟨_, h⟩⟩,
obtain ⟨⟨c : cardinal, hc : ¬acc (<) c⟩, ⟨h_1 : Π j, (f ⟨c, hc⟩).out ↪ (f j).out⟩⟩ :=
embedding.min_injective (λ i, (f i).out),
apply hc (acc.intro _ (λ j h', classical.by_contradiction (λ hj, h'.2 _))),
have : #_ ≤ #_ := ⟨h_1 ⟨j, hj⟩⟩,
simpa only [f, mk_out] using this
end⟩
instance : has_well_founded cardinal.{u} := ⟨(<), cardinal.lt_wf⟩
instance wo : @is_well_order cardinal.{u} (<) := { }
instance : conditionally_complete_linear_order_bot cardinal :=
is_well_order.conditionally_complete_linear_order_bot _
@[simp] theorem Inf_empty : Inf (∅ : set cardinal.{u}) = 0 :=
dif_neg not_nonempty_empty
/-- Note that the successor of `c` is not the same as `c + 1` except in the case of finite `c`. -/
instance : succ_order cardinal :=
succ_order.of_succ_le_iff (λ c, Inf {c' | c < c'})
(λ a b, ⟨lt_of_lt_of_le $ Inf_mem $ exists_gt a, cInf_le'⟩)
theorem succ_def (c : cardinal) : succ c = Inf {c' | c < c'} := rfl
lemma succ_pos : ∀ c : cardinal, 0 < succ c := bot_lt_succ
lemma succ_ne_zero (c : cardinal) : succ c ≠ 0 := (succ_pos _).ne'
theorem add_one_le_succ (c : cardinal.{u}) : c + 1 ≤ succ c :=
begin
refine (le_cInf_iff'' (exists_gt c)).2 (λ b hlt, _),
rcases ⟨b, c⟩ with ⟨⟨β⟩, ⟨γ⟩⟩,
cases le_of_lt hlt with f,
have : ¬ surjective f := λ hn, (not_le_of_lt hlt) (mk_le_of_surjective hn),
simp only [surjective, not_forall] at this,
rcases this with ⟨b, hb⟩,
calc #γ + 1 = #(option γ) : mk_option.symm
... ≤ #β : (f.option_elim b hb).cardinal_le
end
/-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ℵ₀` is a limit
cardinal by this definition, but `0` isn't.
Use `is_succ_limit` if you want to include the `c = 0` case. -/
def is_limit (c : cardinal) : Prop := c ≠ 0 ∧ is_succ_limit c
protected theorem is_limit.ne_zero {c} (h : is_limit c) : c ≠ 0 := h.1
protected theorem is_limit.is_succ_limit {c} (h : is_limit c) : is_succ_limit c := h.2
theorem is_limit.succ_lt {x c} (h : is_limit c) : x < c → succ x < c := h.is_succ_limit.succ_lt
theorem is_succ_limit_zero : is_succ_limit (0 : cardinal) := is_succ_limit_bot
/-- 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 mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum (λ i, #(f i)) :=
mk_congr $ equiv.sigma_congr_right $ λ i, out_mk_equiv.symm
@[simp] theorem sum_const (ι : Type u) (a : cardinal.{v}) :
sum (λ i : ι, a) = lift.{v} (#ι) * lift.{u} a :=
induction_on a $ λ α, mk_congr $
calc (Σ i : ι, quotient.out (#α)) ≃ ι × quotient.out (#α) : equiv.sigma_equiv_prod _ _
... ≃ ulift ι × ulift α : equiv.ulift.symm.prod_congr (out_mk_equiv.trans equiv.ulift.symm)
theorem sum_const' (ι : Type u) (a : cardinal.{u}) : sum (λ _:ι, a) = #ι * a := by simp
@[simp] theorem sum_add_distrib {ι} (f g : ι → cardinal) :
sum (f + g) = sum f + sum g :=
by simpa only [mk_sigma, mk_sum, mk_out, lift_id] using
mk_congr (equiv.sigma_sum_distrib (quotient.out ∘ f) (quotient.out ∘ g))
@[simp] theorem sum_add_distrib' {ι} (f g : ι → cardinal) :
cardinal.sum (λ i, f i + g i) = sum f + sum g :=
sum_add_distrib f g
@[simp] theorem lift_sum {ι : Type u} (f : ι → cardinal.{v}) :
cardinal.lift.{w} (cardinal.sum f) = cardinal.sum (λ i, cardinal.lift.{w} (f i)) :=
equiv.cardinal_eq $ equiv.ulift.trans $ equiv.sigma_congr_right $ λ a, nonempty.some $
by rw [←lift_mk_eq, mk_out, mk_out, lift_lift]
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⟩
lemma mk_le_mk_mul_of_mk_preimage_le {c : cardinal} (f : α → β) (hf : ∀ b : β, #(f ⁻¹' {b}) ≤ c) :
#α ≤ #β * c :=
by simpa only [←mk_congr (@equiv.sigma_fiber_equiv α β f), mk_sigma, ←sum_const']
using sum_le_sum _ _ hf
lemma lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le {α : Type u} {β : Type v} {c : cardinal}
(f : α → β) (hf : ∀ b : β, lift.{v} #(f ⁻¹' {b}) ≤ c) :
lift.{v} #α ≤ lift.{u} #β * c :=
mk_le_mk_mul_of_mk_preimage_le (λ x : ulift.{v} α, ulift.up.{u} (f x.1)) $ ulift.forall.2 $ λ b,
(mk_congr $ (equiv.ulift.image _).trans (equiv.trans
(by { rw [equiv.image_eq_preimage], simp [set.preimage] }) equiv.ulift.symm)).trans_le (hf b)
/-- The range of an indexed cardinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. -/
theorem bdd_above_range {ι : Type u} (f : ι → cardinal.{max u v}) : bdd_above (set.range f) :=
⟨_, by { rintros a ⟨i, rfl⟩, exact le_sum f i }⟩
instance (a : cardinal.{u}) : small.{u} (set.Iic a) :=
begin
rw ←mk_out a,
apply @small_of_surjective (set a.out) (Iic (#a.out)) _ (λ x, ⟨#x, mk_set_le x⟩),
rintro ⟨x, hx⟩,
simpa using le_mk_iff_exists_set.1 hx
end
instance (a : cardinal.{u}) : small.{u} (set.Iio a) :=
small_subset Iio_subset_Iic_self
/-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to an usual ZFC set. -/
theorem bdd_above_iff_small {s : set cardinal.{u}} : bdd_above s ↔ small.{u} s :=
⟨λ ⟨a, ha⟩, @small_subset _ (Iic a) s (λ x h, ha h) _, begin
rintro ⟨ι, ⟨e⟩⟩,
suffices : range (λ x : ι, (e.symm x).1) = s,
{ rw ←this,
apply bdd_above_range.{u u} },
ext x,
refine ⟨_, λ hx, ⟨e ⟨x, hx⟩, _⟩⟩,
{ rintro ⟨a, rfl⟩,
exact (e.symm a).prop },
{ simp_rw [subtype.val_eq_coe, equiv.symm_apply_apply], refl }
end⟩
theorem bdd_above_of_small (s : set cardinal.{u}) [h : small.{u} s] : bdd_above s :=
bdd_above_iff_small.2 h
theorem bdd_above_image (f : cardinal.{u} → cardinal.{max u v}) {s : set cardinal.{u}}
(hs : bdd_above s) : bdd_above (f '' s) :=
by { rw bdd_above_iff_small at hs ⊢, exactI small_lift _ }
theorem bdd_above_range_comp {ι : Type u} {f : ι → cardinal.{v}} (hf : bdd_above (range f))
(g : cardinal.{v} → cardinal.{max v w}) : bdd_above (range (g ∘ f)) :=
by { rw range_comp, exact bdd_above_image g hf }
theorem supr_le_sum {ι} (f : ι → cardinal) : supr f ≤ sum f :=
csupr_le' $ le_sum _
theorem sum_le_supr_lift {ι : Type u} (f : ι → cardinal.{max u v}) :
sum f ≤ (#ι).lift * supr f :=
begin
rw [←(supr f).lift_id, ←lift_umax, lift_umax.{(max u v) u}, ←sum_const],
exact sum_le_sum _ _ (le_csupr $ bdd_above_range.{u v} f)
end
theorem sum_le_supr {ι : Type u} (f : ι → cardinal.{u}) : sum f ≤ #ι * supr f :=
by { rw ←lift_id (#ι), exact sum_le_supr_lift f }
theorem sum_nat_eq_add_sum_succ (f : ℕ → cardinal.{u}) :
cardinal.sum f = f 0 + cardinal.sum (λ i, f (i + 1)) :=
begin
refine (equiv.sigma_nat_succ (λ i, quotient.out (f i))).cardinal_eq.trans _,
simp only [mk_sum, mk_out, lift_id, mk_sigma],
end
/-- A variant of `csupr_of_empty` but with `0` on the RHS for convenience -/
@[simp] protected theorem supr_of_empty {ι} (f : ι → cardinal) [is_empty ι] : supr f = 0 :=
csupr_of_empty f
@[simp] lemma lift_mk_shrink (α : Type u) [small.{v} α] :
cardinal.lift.{max u w} (# (shrink.{v} α)) = cardinal.lift.{max v w} (# α) :=
lift_mk_eq.2 ⟨(equiv_shrink α).symm⟩
@[simp] lemma lift_mk_shrink' (α : Type u) [small.{v} α] :
cardinal.lift.{u} (# (shrink.{v} α)) = cardinal.lift.{v} (# α) :=
lift_mk_shrink.{u v 0} α
@[simp] lemma lift_mk_shrink'' (α : Type (max u v)) [small.{v} α] :
cardinal.lift.{u} (# (shrink.{v} α)) = # α :=
by rw [← lift_umax', lift_mk_shrink.{(max u v) v 0} α, ← lift_umax, lift_id]
/-- The indexed product of cardinals is the cardinality of the Pi type
(dependent product). -/
def prod {ι : Type u} (f : ι → cardinal) : cardinal := #(Π i, (f i).out)
@[simp] theorem mk_pi {ι : Type u} (α : ι → Type v) : #(Π i, α i) = prod (λ i, #(α i)) :=
mk_congr $ equiv.Pi_congr_right $ λ i, out_mk_equiv.symm
@[simp] theorem prod_const (ι : Type u) (a : cardinal.{v}) :
prod (λ i : ι, a) = lift.{u} a ^ lift.{v} (#ι) :=
induction_on a $ λ α, mk_congr $ equiv.Pi_congr equiv.ulift.symm $
λ i, out_mk_equiv.trans equiv.ulift.symm
theorem prod_const' (ι : Type u) (a : cardinal.{u}) : prod (λ _:ι, a) = a ^ #ι :=
induction_on a $ λ α, (mk_pi _).symm
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⟩
@[simp] theorem prod_eq_zero {ι} (f : ι → cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 :=
by { lift f to ι → Type u using λ _, trivial, simp only [mk_eq_zero_iff, ← mk_pi, is_empty_pi] }
theorem prod_ne_zero {ι} (f : ι → cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 :=
by simp [prod_eq_zero]
@[simp] theorem lift_prod {ι : Type u} (c : ι → cardinal.{v}) :
lift.{w} (prod c) = prod (λ i, lift.{w} (c i)) :=
begin
lift c to ι → Type v using λ _, trivial,
simp only [← mk_pi, ← mk_ulift],
exact mk_congr (equiv.ulift.trans $ equiv.Pi_congr_right $ λ i, equiv.ulift.symm)
end
lemma prod_eq_of_fintype {α : Type u} [fintype α] (f : α → cardinal.{v}) :
prod f = cardinal.lift.{u} (∏ i, f i) :=
begin
revert f,
refine fintype.induction_empty_option _ _ _ α,
{ introsI α β hβ e h f,
letI := fintype.of_equiv β e.symm,
rw [←e.prod_comp f, ←h],
exact mk_congr (e.Pi_congr_left _).symm },
{ intro f,
rw [fintype.univ_pempty, finset.prod_empty, lift_one, cardinal.prod, mk_eq_one] },
{ intros α hα h f,
rw [cardinal.prod, mk_congr equiv.pi_option_equiv_prod, mk_prod, lift_umax', mk_out,
←cardinal.prod, lift_prod, fintype.prod_option, lift_mul, ←h (λ a, f (some a))],
simp only [lift_id] },
end
@[simp] theorem lift_Inf (s : set cardinal) : lift (Inf s) = Inf (lift '' s) :=
begin
rcases eq_empty_or_nonempty s with rfl | hs,
{ simp },
{ exact lift_monotone.map_Inf hs }
end
@[simp] theorem lift_infi {ι} (f : ι → cardinal) : lift (infi f) = ⨅ i, lift (f i) :=
by { unfold infi, convert lift_Inf (range f), rw range_comp }
theorem lift_down {a : cardinal.{u}} {b : cardinal.{max u v}} :
b ≤ lift a → ∃ a', lift a' = b :=
induction_on₂ a b $ λ α β,
by rw [← lift_id (#β), ← lift_umax, ← lift_umax.{u v}, lift_mk_le]; exact
λ ⟨f⟩, ⟨#(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 h.le 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_iff, ← lift_le, e] at h,
exact h.not_lt (lt_succ _)
end)
(succ_le_of_lt $ lift_lt.2 $ lt_succ a)
@[simp] theorem lift_umax_eq {a : cardinal.{u}} {b : cardinal.{v}} :
lift.{max v w} a = lift.{max u w} b ↔ lift.{v} a = lift.{u} b :=
by rw [←lift_lift, ←lift_lift, lift_inj]
@[simp] theorem lift_min {a b : cardinal} : lift (min a b) = min (lift a) (lift b) :=
lift_monotone.map_min
@[simp] theorem lift_max {a b : cardinal} : lift (max a b) = max (lift a) (lift b) :=
lift_monotone.map_max
/-- The lift of a supremum is the supremum of the lifts. -/
lemma lift_Sup {s : set cardinal} (hs : bdd_above s) : lift.{u} (Sup s) = Sup (lift.{u} '' s) :=
begin
apply ((le_cSup_iff' (bdd_above_image _ hs)).2 (λ c hc, _)).antisymm (cSup_le' _),
{ by_contra h,
obtain ⟨d, rfl⟩ := cardinal.lift_down (not_le.1 h).le,
simp_rw lift_le at h hc,
rw cSup_le_iff' hs at h,
exact h (λ a ha, lift_le.1 $ hc (mem_image_of_mem _ ha)) },
{ rintros i ⟨j, hj, rfl⟩,
exact lift_le.2 (le_cSup hs hj) },
end
/-- The lift of a supremum is the supremum of the lifts. -/
lemma lift_supr {ι : Type v} {f : ι → cardinal.{w}} (hf : bdd_above (range f)) :
lift.{u} (supr f) = ⨆ i, lift.{u} (f i) :=
by rw [supr, supr, lift_Sup hf, ←range_comp]
/-- To prove that the lift of a supremum is bounded by some cardinal `t`,
it suffices to show that the lift of each cardinal is bounded by `t`. -/
lemma lift_supr_le {ι : Type v} {f : ι → cardinal.{w}} {t : cardinal} (hf : bdd_above (range f))
(w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (supr f) ≤ t :=
by { rw lift_supr hf, exact csupr_le' w }
@[simp] lemma lift_supr_le_iff {ι : Type v} {f : ι → cardinal.{w}} (hf : bdd_above (range f))
{t : cardinal} : lift.{u} (supr f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t :=
by { rw lift_supr hf, exact csupr_le_iff' (bdd_above_range_comp hf _) }
universes v' w'
/--
To prove an inequality between the lifts to a common universe of two different supremums,
it suffices to show that the lift of each cardinal from the smaller supremum
if bounded by the lift of some cardinal from the larger supremum.
-/
lemma lift_supr_le_lift_supr
{ι : Type v} {ι' : Type v'} {f : ι → cardinal.{w}} {f' : ι' → cardinal.{w'}}
(hf : bdd_above (range f)) (hf' : bdd_above (range f'))
{g : ι → ι'} (h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) :
lift.{w'} (supr f) ≤ lift.{w} (supr f') :=
begin
rw [lift_supr hf, lift_supr hf'],
exact csupr_mono' (bdd_above_range_comp hf' _) (λ i, ⟨_, h i⟩)
end
/-- A variant of `lift_supr_le_lift_supr` with universes specialized via `w = v` and `w' = v'`.
This is sometimes necessary to avoid universe unification issues. -/
lemma lift_supr_le_lift_supr'
{ι : Type v} {ι' : Type v'} {f : ι → cardinal.{v}} {f' : ι' → cardinal.{v'}}
(hf : bdd_above (range f)) (hf' : bdd_above (range f'))
(g : ι → ι') (h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) :
lift.{v'} (supr f) ≤ lift.{v} (supr f') :=
lift_supr_le_lift_supr hf hf' h
/-- `ℵ₀` is the smallest infinite cardinal. -/
def aleph_0 : cardinal.{u} := lift (#ℕ)
localized "notation (name := cardinal.aleph_0) `ℵ₀` := cardinal.aleph_0" in cardinal
lemma mk_nat : #ℕ = ℵ₀ := (lift_id _).symm
theorem aleph_0_ne_zero : ℵ₀ ≠ 0 := mk_ne_zero _
theorem aleph_0_pos : 0 < ℵ₀ :=
pos_iff_ne_zero.2 aleph_0_ne_zero
@[simp] theorem lift_aleph_0 : lift ℵ₀ = ℵ₀ := lift_lift _
@[simp] theorem aleph_0_le_lift {c : cardinal.{u}} : ℵ₀ ≤ lift.{v} c ↔ ℵ₀ ≤ c :=
by rw [←lift_aleph_0, lift_le]
@[simp] theorem lift_le_aleph_0 {c : cardinal.{u}} : lift.{v} c ≤ ℵ₀ ↔ c ≤ ℵ₀ :=
by rw [←lift_aleph_0, lift_le]
@[simp] theorem aleph_0_lt_lift {c : cardinal.{u}} : ℵ₀ < lift.{v} c ↔ ℵ₀ < c :=
by rw [←lift_aleph_0, lift_lt]
@[simp] theorem lift_lt_aleph_0 {c : cardinal.{u}} : lift.{v} c < ℵ₀ ↔ c < ℵ₀ :=
by rw [←lift_aleph_0, lift_lt]
/-! ### Properties about the cast from `ℕ` -/
@[simp] theorem mk_fin (n : ℕ) : #(fin n) = n := by simp
@[simp] theorem lift_nat_cast (n : ℕ) : lift.{u} (n : cardinal.{v}) = n :=
by induction n; simp *
@[simp] lemma lift_eq_nat_iff {a : cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n :=
lift_injective.eq_iff' (lift_nat_cast n)
@[simp] lemma nat_eq_lift_iff {n : ℕ} {a : cardinal.{u}} :
(n : cardinal) = lift.{v} a ↔ (n : cardinal) = a :=
by rw [←lift_nat_cast.{v} n, lift_inj]
@[simp] lemma lift_le_nat_iff {a : cardinal.{u}} {n : ℕ} : lift.{v} a ≤ n ↔ a ≤ n :=
by simp only [←lift_nat_cast, lift_le]
@[simp] lemma nat_le_lift_iff {n : ℕ} {a : cardinal.{u}} :
(n : cardinal) ≤ lift.{v} a ↔ (n : cardinal) ≤ a :=
by simp only [←lift_nat_cast, lift_le]
@[simp] lemma lift_lt_nat_iff {a : cardinal.{u}} {n : ℕ} : lift.{v} a < n ↔ a < n :=
by simp only [←lift_nat_cast, lift_lt]
@[simp] lemma nat_lt_lift_iff {n : ℕ} {a : cardinal.{u}} :
(n : cardinal) < lift.{v} a ↔ (n : cardinal) < a :=
by simp only [←lift_nat_cast, lift_lt]
theorem lift_mk_fin (n : ℕ) : lift (#(fin n)) = n := by simp
lemma mk_coe_finset {α : Type u} {s : finset α} : #s = ↑(finset.card s) := by simp
lemma mk_finset_of_fintype [fintype α] : #(finset α) = 2 ^ℕ fintype.card α := by simp
@[simp] lemma mk_finsupp_lift_of_fintype (α : Type u) (β : Type v) [fintype α] [has_zero β] :
#(α →₀ β) = lift.{u} (#β) ^ℕ fintype.card α :=
by simpa using (@finsupp.equiv_fun_on_finite α β _ _).cardinal_eq
lemma mk_finsupp_of_fintype (α β : Type u) [fintype α] [has_zero β] :
#(α →₀ β) = (#β) ^ℕ fintype.card α :=
by simp
theorem card_le_of_finset {α} (s : finset α) : (s.card : cardinal) ≤ #α :=
@mk_coe_finset _ s ▸ mk_set_le _
@[simp, norm_cast] theorem nat_cast_pow {m n : ℕ} : (↑(pow m n) : cardinal) = m ^ n :=
by induction n; simp [pow_succ', 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, le_def, function.embedding.nonempty_iff_card_le,
fintype.card_fin, fintype.card_fin]
@[simp, norm_cast] theorem nat_cast_lt {m n : ℕ} : (m : cardinal) < n ↔ m < n :=
by simp [lt_iff_le_not_le, ←not_le]
instance : char_zero cardinal := ⟨strict_mono.injective $ λ m n, nat_cast_lt.2⟩
theorem nat_cast_inj {m n : ℕ} : (m : cardinal) = n ↔ m = n := nat.cast_inj
lemma nat_cast_injective : injective (coe : ℕ → cardinal) :=
nat.cast_injective
@[simp, norm_cast, priority 900] theorem nat_succ (n : ℕ) : (n.succ : cardinal) = succ n :=
(add_one_le_succ _).antisymm (succ_le_of_lt $ nat_cast_lt.2 $ nat.lt_succ_self _)
@[simp] theorem succ_zero : succ (0 : cardinal) = 1 := by norm_cast
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : finset α, s.card ≤ n) : # α ≤ n :=
begin
refine le_of_lt_succ (lt_of_not_ge $ λ hn, _),
rw [←cardinal.nat_succ, ←lift_mk_fin n.succ] at hn,
cases hn with f,
refine (H $ finset.univ.map f).not_lt _,
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 :=
begin
rw [←succ_le_iff, (by norm_cast : succ (1 : cardinal) = 2)] at hb,
exact (cantor a).trans_le (power_le_power_right hb)
end
theorem one_le_iff_pos {c : cardinal} : 1 ≤ c ↔ 0 < c :=
by rw [←succ_zero, succ_le_iff]
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_aleph_0 (n : ℕ) : (n : cardinal.{u}) < ℵ₀ :=
succ_le_iff.1 begin
rw [←nat_succ, ←lift_mk_fin, aleph_0, lift_mk_le.{0 0 u}],
exact ⟨⟨coe, λ a b, fin.ext⟩⟩
end
@[simp] theorem one_lt_aleph_0 : 1 < ℵ₀ := by simpa using nat_lt_aleph_0 1
theorem one_le_aleph_0 : 1 ≤ ℵ₀ := one_lt_aleph_0.le
theorem lt_aleph_0 {c : cardinal} : c < ℵ₀ ↔ ∃ 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 : S.finite,
{ lift S to finset ℕ using this,
simp },
contrapose! h',
haveI := infinite.to_subtype h',
exact ⟨infinite.nat_embedding S⟩
end, λ ⟨n, e⟩, e.symm ▸ nat_lt_aleph_0 _⟩
theorem aleph_0_le {c : cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c :=
⟨λ h n, (nat_lt_aleph_0 _).le.trans h,
λ h, le_of_not_lt $ λ hn, begin
rcases lt_aleph_0.1 hn with ⟨n, rfl⟩,
exact (nat.lt_succ_self _).not_le (nat_cast_le.1 (h (n+1)))
end⟩
theorem is_succ_limit_aleph_0 : is_succ_limit ℵ₀ :=
is_succ_limit_of_succ_lt $ λ a ha, begin
rcases lt_aleph_0.1 ha with ⟨n, rfl⟩,
rw ←nat_succ,
apply nat_lt_aleph_0
end
theorem is_limit_aleph_0 : is_limit ℵ₀ := ⟨aleph_0_ne_zero, is_succ_limit_aleph_0⟩
theorem is_limit.aleph_0_le {c : cardinal} (h : is_limit c) : ℵ₀ ≤ c :=
begin
by_contra' h',
rcases lt_aleph_0.1 h' with ⟨_ | n, rfl⟩,
{ exact h.ne_zero.irrefl },
{ rw nat_succ at h,
exact not_is_succ_limit_succ _ h.is_succ_limit }
end
@[simp] lemma range_nat_cast : range (coe : ℕ → cardinal) = Iio ℵ₀ :=
ext $ λ x, by simp only [mem_Iio, mem_range, eq_comm, lt_aleph_0]
theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ nonempty (α ≃ fin n) :=
by rw [← lift_mk_fin, ← lift_uzero (#α), lift_mk_eq']
theorem lt_aleph_0_iff_finite {α : Type u} : #α < ℵ₀ ↔ finite α :=
by simp only [lt_aleph_0, mk_eq_nat_iff, finite_iff_exists_equiv_fin]
theorem lt_aleph_0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ nonempty (fintype α) :=
lt_aleph_0_iff_finite.trans (finite_iff_nonempty_fintype _)
theorem lt_aleph_0_of_finite (α : Type u) [finite α] : #α < ℵ₀ :=
lt_aleph_0_iff_finite.2 ‹_›
@[simp] theorem lt_aleph_0_iff_set_finite {S : set α} : #S < ℵ₀ ↔ S.finite :=
lt_aleph_0_iff_finite.trans finite_coe_iff
alias lt_aleph_0_iff_set_finite ↔ _ _root_.set.finite.lt_aleph_0
@[simp] theorem lt_aleph_0_iff_subtype_finite {p : α → Prop} :
#{x // p x} < ℵ₀ ↔ {x | p x}.finite :=
lt_aleph_0_iff_set_finite
lemma mk_le_aleph_0_iff : #α ≤ ℵ₀ ↔ countable α :=
by rw [countable_iff_nonempty_embedding, aleph_0, ← lift_uzero (#α), lift_mk_le']
@[simp] lemma mk_le_aleph_0 [countable α] : #α ≤ ℵ₀ := mk_le_aleph_0_iff.mpr ‹_›
@[simp] lemma le_aleph_0_iff_set_countable {s : set α} : #s ≤ ℵ₀ ↔ s.countable :=
by rw [mk_le_aleph_0_iff, countable_coe_iff]
alias le_aleph_0_iff_set_countable ↔ _ _root_.set.countable.le_aleph_0
@[simp] lemma le_aleph_0_iff_subtype_countable {p : α → Prop} :
#{x // p x} ≤ ℵ₀ ↔ {x | p x}.countable :=
le_aleph_0_iff_set_countable
instance can_lift_cardinal_nat : can_lift cardinal ℕ coe (λ x, x < ℵ₀) :=
⟨λ x hx, let ⟨n, hn⟩ := lt_aleph_0.mp hx in ⟨n, hn.symm⟩⟩
theorem add_lt_aleph_0 {a b : cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ :=
match a, b, lt_aleph_0.1 ha, lt_aleph_0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_add]; apply nat_lt_aleph_0
end
lemma add_lt_aleph_0_iff {a b : cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ :=
⟨λ h, ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩,
λ ⟨h1, h2⟩, add_lt_aleph_0 h1 h2⟩
lemma aleph_0_le_add_iff {a b : cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b :=
by simp only [←not_lt, add_lt_aleph_0_iff, not_and_distrib]
/-- See also `cardinal.nsmul_lt_aleph_0_iff_of_ne_zero` if you already have `n ≠ 0`. -/
lemma nsmul_lt_aleph_0_iff {n : ℕ} {a : cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ :=
begin
cases n,
{ simpa using nat_lt_aleph_0 0 },
simp only [nat.succ_ne_zero, false_or],
induction n with n ih,
{ simp },
rw [succ_nsmul, add_lt_aleph_0_iff, ih, and_self]
end
/-- See also `cardinal.nsmul_lt_aleph_0_iff` for a hypothesis-free version. -/
lemma nsmul_lt_aleph_0_iff_of_ne_zero {n : ℕ} {a : cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ :=
nsmul_lt_aleph_0_iff.trans $ or_iff_right h
theorem mul_lt_aleph_0 {a b : cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ :=
match a, b, lt_aleph_0.1 ha, lt_aleph_0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_mul]; apply nat_lt_aleph_0
end
lemma mul_lt_aleph_0_iff {a b : cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ :=
begin
refine ⟨λ h, _, _⟩,
{ by_cases ha : a = 0, { exact or.inl ha },
right, by_cases hb : b = 0, { exact or.inl hb },
right, rw [←ne, ←one_le_iff_ne_zero] at ha hb, split,
{ rw ←mul_one a,
refine (mul_le_mul' le_rfl hb).trans_lt h },
{ rw ←one_mul b,
refine (mul_le_mul' ha le_rfl).trans_lt h }},
rintro (rfl|rfl|⟨ha,hb⟩); simp only [*, mul_lt_aleph_0, aleph_0_pos, zero_mul, mul_zero]
end
/-- See also `cardinal.aleph_0_le_mul_iff`. -/
lemma aleph_0_le_mul_iff {a b : cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) :=
let h := (@mul_lt_aleph_0_iff a b).not in
by rwa [not_lt, not_or_distrib, not_or_distrib, not_and_distrib, not_lt, not_lt] at h
/-- See also `cardinal.aleph_0_le_mul_iff'`. -/
lemma aleph_0_le_mul_iff' {a b : cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 :=
begin
have : ∀ {a : cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0, from λ a, ne_bot_of_le_ne_bot aleph_0_ne_zero,
simp only [aleph_0_le_mul_iff, and_or_distrib_left, and_iff_right_of_imp this,
@and.left_comm (a ≠ 0)],
simp only [and.comm, or.comm]
end
lemma mul_lt_aleph_0_iff_of_ne_zero {a b : cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ :=
by simp [mul_lt_aleph_0_iff, ha, hb]
theorem power_lt_aleph_0 {a b : cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ :=
match a, b, lt_aleph_0.1 ha, lt_aleph_0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat_cast_pow]; apply nat_lt_aleph_0
end
lemma eq_one_iff_unique {α : Type*} :
#α = 1 ↔ subsingleton α ∧ nonempty α :=
calc #α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α : le_antisymm_iff
... ↔ subsingleton α ∧ nonempty α :
le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff)
theorem infinite_iff {α : Type u} : infinite α ↔ ℵ₀ ≤ #α :=
by rw [← not_lt, lt_aleph_0_iff_finite, not_finite_iff_infinite]
@[simp] lemma aleph_0_le_mk (α : Type u) [infinite α] : ℵ₀ ≤ #α := infinite_iff.1 ‹_›
@[simp] lemma mk_eq_aleph_0 (α : Type*) [countable α] [infinite α] : #α = ℵ₀ :=
mk_le_aleph_0.antisymm $ aleph_0_le_mk _
lemma denumerable_iff {α : Type u} : nonempty (denumerable α) ↔ #α = ℵ₀ :=
⟨λ ⟨h⟩, mk_congr ((@denumerable.eqv α h).trans equiv.ulift.symm),
λ h, by { cases quotient.exact h with f, exact ⟨denumerable.mk' $ f.trans equiv.ulift⟩ }⟩
@[simp] lemma mk_denumerable (α : Type u) [denumerable α] : #α = ℵ₀ :=
denumerable_iff.1 ⟨‹_›⟩
@[simp] lemma aleph_0_add_aleph_0 : ℵ₀ + ℵ₀ = ℵ₀ := mk_denumerable _
lemma aleph_0_mul_aleph_0 : ℵ₀ * ℵ₀ = ℵ₀ := mk_denumerable _
@[simp] lemma nat_mul_aleph_0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ :=
le_antisymm (lift_mk_fin n ▸ mk_le_aleph_0) $ le_mul_of_one_le_left (zero_le _) $
by rwa [← nat.cast_one, nat_cast_le, nat.one_le_iff_ne_zero]
@[simp] lemma aleph_0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ :=
by rw [mul_comm, nat_mul_aleph_0 hn]
@[simp] lemma add_le_aleph_0 {c₁ c₂ : cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ :=
⟨λ h, ⟨le_self_add.trans h, le_add_self.trans h⟩, λ h, aleph_0_add_aleph_0 ▸ add_le_add h.1 h.2⟩
@[simp] lemma aleph_0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ :=
(add_le_aleph_0.2 ⟨le_rfl, (nat_lt_aleph_0 n).le⟩).antisymm le_self_add
@[simp] lemma nat_add_aleph_0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph_0_add_nat]
/-- This function sends finite cardinals to the corresponding natural, and infinite cardinals
to 0. -/
def to_nat : zero_hom cardinal ℕ :=
⟨λ c, if h : c < aleph_0.{v} then classical.some (lt_aleph_0.1 h) else 0,
begin
have h : 0 < ℵ₀ := nat_lt_aleph_0 0,
rw [dif_pos h, ← cardinal.nat_cast_inj, ← classical.some_spec (lt_aleph_0.1 h), nat.cast_zero],
end⟩
lemma to_nat_apply_of_lt_aleph_0 {c : cardinal} (h : c < ℵ₀) :
c.to_nat = classical.some (lt_aleph_0.1 h) :=
dif_pos h
lemma to_nat_apply_of_aleph_0_le {c : cardinal} (h : ℵ₀ ≤ c) : c.to_nat = 0 :=
dif_neg h.not_lt
lemma cast_to_nat_of_lt_aleph_0 {c : cardinal} (h : c < ℵ₀) : ↑c.to_nat = c :=
by rw [to_nat_apply_of_lt_aleph_0 h, ← classical.some_spec (lt_aleph_0.1 h)]
lemma cast_to_nat_of_aleph_0_le {c : cardinal} (h : ℵ₀ ≤ c) : ↑c.to_nat = (0 : cardinal) :=
by rw [to_nat_apply_of_aleph_0_le h, nat.cast_zero]
lemma to_nat_le_iff_le_of_lt_aleph_0 {c d : cardinal} (hc : c < ℵ₀) (hd : d < ℵ₀) :
c.to_nat ≤ d.to_nat ↔ c ≤ d :=
by rw [←nat_cast_le, cast_to_nat_of_lt_aleph_0 hc, cast_to_nat_of_lt_aleph_0 hd]
lemma to_nat_lt_iff_lt_of_lt_aleph_0 {c d : cardinal} (hc : c < ℵ₀) (hd : d < ℵ₀) :
c.to_nat < d.to_nat ↔ c < d :=
by rw [←nat_cast_lt, cast_to_nat_of_lt_aleph_0 hc, cast_to_nat_of_lt_aleph_0 hd]
lemma to_nat_le_of_le_of_lt_aleph_0 {c d : cardinal} (hd : d < ℵ₀) (hcd : c ≤ d) :
c.to_nat ≤ d.to_nat :=
(to_nat_le_iff_le_of_lt_aleph_0 (hcd.trans_lt hd) hd).mpr hcd
lemma to_nat_lt_of_lt_of_lt_aleph_0 {c d : cardinal} (hd : d < ℵ₀) (hcd : c < d) :
c.to_nat < d.to_nat :=
(to_nat_lt_iff_lt_of_lt_aleph_0 (hcd.trans hd) hd).mpr hcd
@[simp] lemma to_nat_cast (n : ℕ) : cardinal.to_nat n = n :=
begin
rw [to_nat_apply_of_lt_aleph_0 (nat_lt_aleph_0 n), ← nat_cast_inj],
exact (classical.some_spec (lt_aleph_0.1 (nat_lt_aleph_0 n))).symm,
end
/-- `to_nat` has a right-inverse: coercion. -/
lemma to_nat_right_inverse : function.right_inverse (coe : ℕ → cardinal) to_nat := to_nat_cast
lemma to_nat_surjective : surjective to_nat := to_nat_right_inverse.surjective
lemma exists_nat_eq_of_le_nat {c : cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m :=
let he := cast_to_nat_of_lt_aleph_0 (h.trans_lt $ nat_lt_aleph_0 n) in
⟨c.to_nat, nat_cast_le.1 (he.trans_le h), he.symm⟩
@[simp] lemma mk_to_nat_of_infinite [h : infinite α] : (#α).to_nat = 0 :=
dif_neg (infinite_iff.1 h).not_lt
@[simp] theorem aleph_0_to_nat : to_nat ℵ₀ = 0 :=
to_nat_apply_of_aleph_0_le le_rfl
lemma mk_to_nat_eq_card [fintype α] : (#α).to_nat = fintype.card α := by simp
@[simp] lemma zero_to_nat : to_nat 0 = 0 :=
by rw [←to_nat_cast 0, nat.cast_zero]
@[simp] lemma one_to_nat : to_nat 1 = 1 :=
by rw [←to_nat_cast 1, nat.cast_one]
lemma to_nat_eq_iff {c : cardinal} {n : ℕ} (hn : n ≠ 0) : to_nat c = n ↔ c = n :=
⟨λ h, (cast_to_nat_of_lt_aleph_0 (lt_of_not_ge (hn ∘ h.symm.trans ∘
to_nat_apply_of_aleph_0_le))).symm.trans (congr_arg coe h),
λ h, (congr_arg to_nat h).trans (to_nat_cast n)⟩
@[simp] lemma to_nat_eq_one {c : cardinal} : to_nat c = 1 ↔ c = 1 :=
by rw [to_nat_eq_iff one_ne_zero, nat.cast_one]
lemma to_nat_eq_one_iff_unique {α : Type*} : (#α).to_nat = 1 ↔ subsingleton α ∧ nonempty α :=
to_nat_eq_one.trans eq_one_iff_unique
@[simp] lemma to_nat_lift (c : cardinal.{v}) : (lift.{u v} c).to_nat = c.to_nat :=
begin
apply nat_cast_injective,
cases lt_or_ge c ℵ₀ with hc hc,
{ rw [cast_to_nat_of_lt_aleph_0, ←lift_nat_cast, cast_to_nat_of_lt_aleph_0 hc],
rwa [lift_lt_aleph_0] },
{ rw [cast_to_nat_of_aleph_0_le, ←lift_nat_cast, cast_to_nat_of_aleph_0_le hc, lift_zero],
rwa [aleph_0_le_lift] },
end
lemma to_nat_congr {β : Type v} (e : α ≃ β) : (#α).to_nat = (#β).to_nat :=
by rw [←to_nat_lift, lift_mk_eq.mpr ⟨e⟩, to_nat_lift]
@[simp] lemma to_nat_mul (x y : cardinal) : (x * y).to_nat = x.to_nat * y.to_nat :=
begin
rcases eq_or_ne x 0 with rfl | hx1,
{ rw [zero_mul, zero_to_nat, zero_mul] },
rcases eq_or_ne y 0 with rfl | hy1,
{ rw [mul_zero, zero_to_nat, mul_zero] },
cases lt_or_le x ℵ₀ with hx2 hx2,
{ cases lt_or_le y ℵ₀ with hy2 hy2,
{ lift x to ℕ using hx2, lift y to ℕ using hy2,
rw [← nat.cast_mul, to_nat_cast, to_nat_cast, to_nat_cast] },
{ rw [to_nat_apply_of_aleph_0_le hy2, mul_zero, to_nat_apply_of_aleph_0_le],
exact aleph_0_le_mul_iff'.2 (or.inl ⟨hx1, hy2⟩) } },
{ rw [to_nat_apply_of_aleph_0_le hx2, zero_mul, to_nat_apply_of_aleph_0_le],
exact aleph_0_le_mul_iff'.2 (or.inr ⟨hx2, hy1⟩) },
end
/-- `cardinal.to_nat` as a `monoid_with_zero_hom`. -/
@[simps]
def to_nat_hom : cardinal →*₀ ℕ :=
{ to_fun := to_nat,
map_zero' := zero_to_nat,
map_one' := one_to_nat,
map_mul' := to_nat_mul }
lemma to_nat_finset_prod (s : finset α) (f : α → cardinal) :
to_nat (∏ i in s, f i) = ∏ i in s, to_nat (f i) :=
map_prod to_nat_hom _ _
@[simp] lemma to_nat_add_of_lt_aleph_0 {a : cardinal.{u}} {b : cardinal.{v}}
(ha : a < ℵ₀) (hb : b < ℵ₀) : ((lift.{v u} a) + (lift.{u v} b)).to_nat = a.to_nat + b.to_nat :=
begin
apply cardinal.nat_cast_injective,
replace ha : (lift.{v u} a) < ℵ₀ := by rwa lift_lt_aleph_0,
replace hb : (lift.{u v} b) < ℵ₀ := by rwa lift_lt_aleph_0,
rw [nat.cast_add, ←to_nat_lift.{v u} a, ←to_nat_lift.{u v} b, cast_to_nat_of_lt_aleph_0 ha,
cast_to_nat_of_lt_aleph_0 hb, cast_to_nat_of_lt_aleph_0 (add_lt_aleph_0 ha hb)]
end
/-- This function sends finite cardinals to the corresponding natural, and infinite cardinals
to `⊤`. -/
def to_part_enat : cardinal →+ part_enat :=
{ to_fun := λ c, if c < ℵ₀ then c.to_nat else ⊤,
map_zero' := by simp [if_pos (zero_lt_one.trans one_lt_aleph_0)],
map_add' := λ x y, begin
by_cases hx : x < ℵ₀,
{ obtain ⟨x0, rfl⟩ := lt_aleph_0.1 hx,
by_cases hy : y < ℵ₀,
{ obtain ⟨y0, rfl⟩ := lt_aleph_0.1 hy,
simp only [add_lt_aleph_0 hx hy, hx, hy, to_nat_cast, if_true],
rw [← nat.cast_add, to_nat_cast, nat.cast_add] },
{ rw [if_neg hy, if_neg, part_enat.add_top],
contrapose! hy,
apply le_add_self.trans_lt hy } },
{ rw [if_neg hx, if_neg, part_enat.top_add],
contrapose! hx,
apply le_self_add.trans_lt hx },
end }
lemma to_part_enat_apply_of_lt_aleph_0 {c : cardinal} (h : c < ℵ₀) : c.to_part_enat = c.to_nat :=
if_pos h
lemma to_part_enat_apply_of_aleph_0_le {c : cardinal} (h : ℵ₀ ≤ c) : c.to_part_enat = ⊤ :=
if_neg h.not_lt
@[simp] lemma to_part_enat_cast (n : ℕ) : cardinal.to_part_enat n = n :=
by rw [to_part_enat_apply_of_lt_aleph_0 (nat_lt_aleph_0 n), to_nat_cast]
@[simp] lemma mk_to_part_enat_of_infinite [h : infinite α] : (#α).to_part_enat = ⊤ :=
to_part_enat_apply_of_aleph_0_le (infinite_iff.1 h)
@[simp] theorem aleph_0_to_part_enat : to_part_enat ℵ₀ = ⊤ :=
to_part_enat_apply_of_aleph_0_le le_rfl
lemma to_part_enat_surjective : surjective to_part_enat :=
λ x, part_enat.cases_on x ⟨ℵ₀, to_part_enat_apply_of_aleph_0_le le_rfl⟩ $
λ n, ⟨n, to_part_enat_cast n⟩
lemma mk_to_part_enat_eq_coe_card [fintype α] : (#α).to_part_enat = fintype.card α :=
by simp
lemma mk_int : #ℤ = ℵ₀ := mk_denumerable ℤ
lemma mk_pnat : #ℕ+ = ℵ₀ := mk_denumerable ℕ+
/-- **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
haveI : inhabited (Π (i : ι), (g i).out),
{ refine ⟨λ i, classical.choice $ mk_ne_zero_iff.1 _⟩,
rw mk_out,
exact (H i).ne_bot },
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,
{ intro i,
simp only [- not_exists, not_exists.symm, not_forall.symm],
refine λ h, (H i).not_le _,
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 : #empty = 0 := mk_eq_zero _
@[simp] theorem mk_pempty : #pempty = 0 := mk_eq_zero _
@[simp] theorem mk_punit : #punit = 1 := mk_eq_one punit
theorem mk_unit : #unit = 1 := mk_punit
@[simp] theorem mk_singleton {α : Type u} (x : α) : #({x} : set α) = 1 :=
mk_eq_one _
@[simp] theorem mk_plift_true : #(plift true) = 1 := mk_eq_one _
@[simp] theorem mk_plift_false : #(plift false) = 0 := mk_eq_zero _
@[simp] theorem mk_vector (α : Type u) (n : ℕ) : #(vector α n) = (#α) ^ℕ n :=
(mk_congr (equiv.vector_equiv_fin α n)).trans $ by simp
theorem mk_list_eq_sum_pow (α : Type u) : #(list α) = sum (λ n : ℕ, (#α) ^ℕ n) :=
calc #(list α) = #(Σ n, vector α n) : mk_congr (equiv.sigma_fiber_equiv list.length).symm
... = sum (λ n : ℕ, (#α) ^ℕ n) : by simp
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(quot r) ≤ #α :=
mk_le_of_surjective quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : setoid α} : #(quotient s) ≤ #α :=
mk_quot_le
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
#(subtype p) ≤ #(subtype q) :=
⟨embedding.subtype_map (embedding.refl α) h⟩
@[simp] theorem mk_emptyc (α : Type u) : #(∅ : set α) = 0 := mk_eq_zero _
lemma mk_emptyc_iff {α : Type u} {s : set α} : #s = 0 ↔ s = ∅ :=
begin
split,
{ intro h,
rw mk_eq_zero_iff at h,
exact eq_empty_iff_forall_not_mem.2 (λ x hx, h.elim' ⟨x, hx⟩) },
{ rintro rfl, exact mk_emptyc _ }
end
@[simp] theorem mk_univ {α : Type u} : #(@univ α) = #α :=
mk_congr (equiv.set.univ α)
theorem mk_image_le {α β : Type u} {f : α → β} {s : set α} : #(f '' s) ≤ #s :=
mk_le_of_surjective surjective_onto_image
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : set α} :
lift.{u} (#(f '' s)) ≤ lift.{v} (#s) :=
lift_mk_le.{v u 0}.mpr ⟨embedding.of_surjective _ surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α :=
mk_le_of_surjective surjective_onto_range
theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} :
lift.{u} (#(range f)) ≤ lift.{v} (#α) :=
lift_mk_le.{v u 0}.mpr ⟨embedding.of_surjective _ surjective_onto_range⟩
lemma mk_range_eq (f : α → β) (h : injective f) : #(range f) = #α :=
mk_congr ((equiv.of_injective f h).symm)
lemma mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{u} (#(range f)) = lift.{v} (#α) :=
lift_mk_eq'.mpr ⟨(equiv.of_injective f hf).symm⟩
lemma mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{max u w} (# (range f)) = lift.{max v w} (# α) :=
lift_mk_eq.mpr ⟨(equiv.of_injective f hf).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : set α} (hf : injective f) :
#(f '' s) = #s :=
mk_congr ((equiv.set.image f s hf).symm)
theorem mk_Union_le_sum_mk {α ι : Type u} {f : ι → set α} : #(⋃ i, f i) ≤ sum (λ i, #(f i)) :=
calc #(⋃ i, f i) ≤ #(Σ i, f i) : mk_le_of_surjective (set.sigma_to_Union_surjective f)
... = sum (λ i, #(f i)) : mk_sigma _
theorem mk_Union_eq_sum_mk {α ι : Type u} {f : ι → set α} (h : ∀i j, i ≠ j → disjoint (f i) (f j)) :
#(⋃ i, f i) = sum (λ i, #(f i)) :=
calc #(⋃ i, f i) = #(Σ i, f i) : mk_congr (set.Union_eq_sigma_of_disjoint h)
... = sum (λi, #(f i)) : mk_sigma _
lemma mk_Union_le {α ι : Type u} (f : ι → set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) :=
mk_Union_le_sum_mk.trans (sum_le_supr _)
lemma mk_sUnion_le {α : Type u} (A : set (set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s :=
by { rw sUnion_eq_Union, apply mk_Union_le }
lemma mk_bUnion_le {ι α : Type u} (A : ι → set α) (s : set ι) :
#(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) :=
by { rw bUnion_eq_Union, apply mk_Union_le }
lemma finset_card_lt_aleph_0 (s : finset α) : #(↑s : set α) < ℵ₀ :=
lt_aleph_0_of_finite _
theorem mk_set_eq_nat_iff_finset {α} {s : set α} {n : ℕ} :
#s = n ↔ ∃ t : finset α, (t : set α) = s ∧ t.card = n :=
begin
split,
{ intro h,
lift s to finset α using lt_aleph_0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph_0 n),
simpa using h },
{ rintro ⟨t, rfl, rfl⟩,
exact mk_coe_finset }
end
theorem mk_eq_nat_iff_finset {n : ℕ} : #α = n ↔ ∃ t : finset α, (t : set α) = univ ∧ t.card = n :=
by rw [← mk_univ, mk_set_eq_nat_iff_finset]
theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ (h : fintype α), @fintype.card α h = n :=
begin
rw [mk_eq_nat_iff_finset],
split,
{ rintro ⟨t, ht, hn⟩,
exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩ },
{ rintro ⟨⟨t, ht⟩, hn⟩,
exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩ }
end
theorem mk_union_add_mk_inter {α : Type u} {S T : set α} :
#(S ∪ T : set α) + #(S ∩ T : set α) = #S + #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 α) : #(S ∪ T : set α) ≤ #S + #T :=
@mk_union_add_mk_inter α S T ▸ self_le_add_right (#(S ∪ T : set α)) (#(S ∩ T : set α))
theorem mk_union_of_disjoint {α : Type u} {S T : set α} (H : disjoint S T) :
#(S ∪ T : set α) = #S + #T :=
quot.sound ⟨equiv.set.union H.le_bot⟩
theorem mk_insert {α : Type u} {s : set α} {a : α} (h : a ∉ s) :
#(insert a s : set α) = #s + 1 :=
by { rw [← union_singleton, mk_union_of_disjoint, mk_singleton], simpa }
lemma mk_sum_compl {α} (s : set α) : #s + #(sᶜ : set α) = #α :=
mk_congr (equiv.set.sum_compl s)
lemma mk_le_mk_of_subset {α} {s t : set α} (h : s ⊆ t) : #s ≤ #t :=
⟨set.embedding_of_subset s t h⟩
lemma mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) : #{x // p x} ≤ #{x // q x} :=
⟨embedding_of_subset _ _ h⟩
lemma le_mk_diff_add_mk (S T : set α) : #S ≤ #(S \ T : set α) + #T :=
(mk_le_mk_of_subset $ subset_diff_union _ _).trans $ mk_union_le _ _
lemma mk_diff_add_mk {S T : set α} (h : T ⊆ S) : #(S \ T : set α) + #T = #S :=
(mk_union_of_disjoint $ by exact disjoint_sdiff_self_left).symm.trans $ by rw diff_union_of_subset h
lemma mk_union_le_aleph_0 {α} {P Q : set α} : #((P ∪ Q : set α)) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ :=
by simp
lemma mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : set α) (h : injective f) :
lift.{u} (#(f '' s)) = lift.{v} (#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.{u} (#(f '' s)) = lift.{v} (#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) :
#(f '' s) = #s :=
mk_congr ((equiv.set.image_of_inj_on f s h).symm)
lemma mk_subtype_of_equiv {α β : Type u} (p : β → Prop) (e : α ≃ β) :
#{a : α // p (e a)} = #{b : β // p b} :=
mk_congr (equiv.subtype_equiv_of_subtype e)
lemma mk_sep (s : set α) (t : α → Prop) : #({ x ∈ s | t x } : set α) = #{ x : s | t x.1 } :=
mk_congr (equiv.set.sep s t)
lemma mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : set β)
(h : injective f) : lift.{v} (#(f ⁻¹' s)) ≤ lift.{u} (#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.{u} (#s) ≤ lift.{v} (#(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.{v} (#(f ⁻¹' s)) = lift.{u} (#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) :
#(f ⁻¹' s) ≤ #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) : #s ≤ #(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) : #(f ⁻¹' s) = #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.{u} (#t) ≤ lift.{v} (#({ 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) :
#t ≤ #({ 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 ≤ #s ↔ ∃ p : set α, p ⊆ s ∧ #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
lemma two_le_iff : (2 : cardinal) ≤ #α ↔ ∃x y : α, x ≠ y :=
by rw [← nat.cast_two, nat_succ, succ_le_iff, nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff]
lemma two_le_iff' (x : α) : (2 : cardinal) ≤ #α ↔ ∃y : α, y ≠ x :=
by rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x]
lemma mk_eq_two_iff : #α = 2 ↔ ∃ x y : α, x ≠ y ∧ ({x, y} : set α) = univ :=
begin
simp only [← @nat.cast_two cardinal, mk_eq_nat_iff_finset, finset.card_eq_two],
split,
{ rintro ⟨t, ht, x, y, hne, rfl⟩,
exact ⟨x, y, hne, by simpa using ht⟩ },
{ rintro ⟨x, y, hne, h⟩,
exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩ }
end
lemma mk_eq_two_iff' (x : α) : #α = 2 ↔ ∃! y, y ≠ x :=
begin
rw [mk_eq_two_iff], split,
{ rintro ⟨a, b, hne, h⟩,
simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h,
rcases h x with rfl|rfl,
exacts [⟨b, hne.symm, λ z, (h z).resolve_left⟩, ⟨a, hne, λ z, (h z).resolve_right⟩] },
{ rintro ⟨y, hne, hy⟩,
exact ⟨x, y, hne.symm, eq_univ_of_forall $ λ z, or_iff_not_imp_left.2 (hy z)⟩ }
end
lemma exists_not_mem_of_length_lt {α : Type*} (l : list α) (h : ↑l.length < # α) :
∃ (z : α), z ∉ l :=
begin
contrapose! h,
calc # α = # (set.univ : set α) : mk_univ.symm
... ≤ # l.to_finset : mk_le_mk_of_subset (λ x _, list.mem_to_finset.mpr (h x))
... = l.to_finset.card : cardinal.mk_coe_finset
... ≤ l.length : cardinal.nat_cast_le.mpr (list.to_finset_card_le l),
end
lemma three_le {α : Type*} (h : 3 ≤ # α) (x : α) (y : α) :
∃ (z : α), z ≠ x ∧ z ≠ y :=
begin
have : ↑(3 : ℕ) ≤ # α, simpa using h,
have : ↑(2 : ℕ) < # α, rwa [← succ_le_iff, ← cardinal.nat_succ],
have := exists_not_mem_of_length_lt [x, y] this,
simpa [not_or_distrib] using this,
end
/-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/
def powerlt (a b : cardinal.{u}) : cardinal.{u} :=
⨆ c : Iio b, a ^ c
infix ` ^< `:80 := powerlt
lemma le_powerlt {b c : cardinal.{u}} (a) (h : c < b) : a ^ c ≤ a ^< b :=
begin
apply @le_csupr _ _ _ (λ y : Iio b, a ^ y) _ ⟨c, h⟩,
rw ←image_eq_range,
exact bdd_above_image.{u u} _ bdd_above_Iio
end
lemma powerlt_le {a b c : cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c :=
begin
rw [powerlt, csupr_le_iff'],
{ simp },
{ rw ←image_eq_range,
exact bdd_above_image.{u u} _ bdd_above_Iio }
end
lemma powerlt_le_powerlt_left {a b c : cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
powerlt_le.2 $ λ x hx, le_powerlt a $ hx.trans_le h
lemma powerlt_mono_left (a) : monotone (λ c, a ^< c) :=
λ b c, powerlt_le_powerlt_left
lemma powerlt_succ {a b : cardinal} (h : a ≠ 0) : a ^< (succ b) = a ^ b :=
(powerlt_le.2 $ λ c h', power_le_power_left h $ le_of_lt_succ h').antisymm $
le_powerlt a (lt_succ b)
lemma powerlt_min {a b c : cardinal} : a ^< min b c = min (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_min
lemma powerlt_max {a b c : cardinal} : a ^< max b c = max (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_max
lemma zero_powerlt {a : cardinal} (h : a ≠ 0) : 0 ^< a = 1 :=
begin
apply (powerlt_le.2 (λ c hc, zero_power_le _)).antisymm,
rw ←power_zero,
exact le_powerlt 0 (pos_iff_ne_zero.2 h)
end
@[simp] lemma powerlt_zero {a : cardinal} : a ^< 0 = 0 :=
begin
convert cardinal.supr_of_empty _,
exact subtype.is_empty_of_false (λ x, (cardinal.zero_le _).not_lt),
end
end cardinal
namespace tactic
open cardinal positivity
/-- Extension for the `positivity` tactic: The cardinal power of a positive cardinal is positive. -/
@[positivity]
meta def positivity_cardinal_pow : expr → tactic strictness
| `(@has_pow.pow _ _ %%inst %%a %%b) := do
strictness_a ← core a,
match strictness_a with
| positive p := positive <$> mk_app ``power_pos [b, p]
| _ := failed -- We already know that `0 ≤ x` for all `x : cardinal`
end
| _ := failed
end tactic
|
24105329ce0680d71cfef77a01ecda83165cea0f | e61a235b8468b03aee0120bf26ec615c045005d2 | /stage0/src/Init/Lean/Elab/StructInst.lean | ec1999e51118802791c8c77c3a81cd838bfeeadf | [
"Apache-2.0"
] | permissive | SCKelemen/lean4 | 140dc63a80539f7c61c8e43e1c174d8500ec3230 | e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc | refs/heads/master | 1,660,973,595,917 | 1,590,278,033,000 | 1,590,278,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 33,192 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Util.FindExpr
import Init.Lean.Elab.App
import Init.Lean.Elab.Binders
import Init.Lean.Elab.Quotation
namespace Lean
namespace Elab
namespace Term
namespace StructInst
/- parser! symbol "{" appPrec >> optional (try (termParser >> "with")) >> sepBy structInstField ", " true >> optional ".." >> optional (" : " >> termParser) >> "}" -/
/-
If `stx` is of the form `{ s with ... }` and `s` is not a local variable, expand into `let src := s; { src with ... }`.
-/
private def expandNonAtomicExplicitSource (stx : Syntax) : TermElabM (Option Syntax) :=
withFreshMacroScope $
let sourceOpt := stx.getArg 1;
if sourceOpt.isNone then pure none else do
let source := sourceOpt.getArg 0;
fvar? ← isLocalTermId? source;
match fvar? with
| some _ => pure none
| none => do
src ← `(src);
let sourceOpt := sourceOpt.setArg 0 src;
let stxNew := stx.setArg 1 sourceOpt;
`(let src := $source; $stxNew)
inductive Source
| none -- structure instance source has not been provieded
| implicit (stx : Syntax) -- `..`
| explicit (stx : Syntax) (src : Expr) -- `src with`
instance Source.inhabited : Inhabited Source := ⟨Source.none⟩
def Source.isNone : Source → Bool
| Source.none => true
| _ => false
def setStructSourceSyntax (structStx : Syntax) : Source → Syntax
| Source.none => (structStx.setArg 1 mkNullNode).setArg 3 mkNullNode
| Source.implicit stx => (structStx.setArg 1 mkNullNode).setArg 3 stx
| Source.explicit stx _ => (structStx.setArg 1 stx).setArg 3 mkNullNode
private def getStructSource (stx : Syntax) : TermElabM Source :=
let explicitSource := stx.getArg 1;
let implicitSource := stx.getArg 3;
if explicitSource.isNone && implicitSource.isNone then
pure Source.none
else if explicitSource.isNone then
pure $ Source.implicit implicitSource
else if implicitSource.isNone then do
fvar? ← isLocalTermId? (explicitSource.getArg 0);
match fvar? with
| none => unreachable! -- expandNonAtomicExplicitSource must have been used when we get here
| some src => pure $ Source.explicit explicitSource src
else
throwError stx "invalid structure instance `with` and `..` cannot be used together"
/-
We say a `{ ... }` notation is a `modifyOp` if it contains only one
```
def structInstArrayRef := parser! "[" >> termParser >>"]"
``` -/
private def isModifyOp? (stx : Syntax) : TermElabM (Option Syntax) := do
let args := (stx.getArg 2).getArgs;
s? ← args.foldSepByM
(fun arg s? =>
/- Remark: the syntax for `structInstField` is
```
def structInstLVal := (ident <|> numLit <|> structInstArrayRef) >> many (group ("." >> (ident <|> numLit)) <|> structInstArrayRef)
def structInstField := parser! structInstLVal >> " := " >> termParser
``` -/
let lval := arg.getArg 0;
let k := lval.getKind;
if k == `Lean.Parser.Term.structInstArrayRef then
match s? with
| none => pure (some arg)
| some s =>
if s.getKind == `Lean.Parser.Term.structInstArrayRef then
throwError arg "invalid {...} notation, at most one `[..]` at a given level"
else
throwError arg "invalid {...} notation, can't mix field and `[..]` at a given level"
else
match s? with
| none => pure (some arg)
| some s =>
if s.getKind == `Lean.Parser.Term.structInstArrayRef then
throwError arg "invalid {...} notation, can't mix field and `[..]` at a given level"
else
pure s?)
none;
match s? with
| none => pure none
| some s => if (s.getArg 0).getKind == `Lean.Parser.Term.structInstArrayRef then pure s? else pure none
private def elabModifyOp (stx modifyOp source : Syntax) (expectedType? : Option Expr) : TermElabM Expr :=
let continue (val : Syntax) : TermElabM Expr := do {
let lval := modifyOp.getArg 0;
let idx := lval.getArg 1;
let self := source.getArg 0;
stxNew ← `($(self).modifyOp (idx := $idx) (fun s => $val));
trace `Elab.struct.modifyOp stx $ fun _ => stx ++ "\n===>\n" ++ stxNew;
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
}; do
trace `Elab.struct.modifyOp stx $ fun _ => modifyOp ++ "\nSource: " ++ source;
let rest := modifyOp.getArg 1;
if rest.isNone then do
continue (modifyOp.getArg 3)
else do
s ← `(s);
let valFirst := rest.getArg 0;
let valFirst := if valFirst.getKind == `Lean.Parser.Term.structInstArrayRef then valFirst else valFirst.getArg 1;
let restArgs := rest.getArgs;
let valRest := mkNullNode (restArgs.extract 1 restArgs.size);
let valField := modifyOp.setArg 0 valFirst;
let valField := valField.setArg 1 valRest;
let valSource := source.modifyArg 0 $ fun _ => s;
let val := stx.setArg 1 valSource;
let val := val.setArg 2 $ mkNullNode #[valField];
trace `Elab.struct.modifyOp stx $ fun _ => stx ++ "\nval: " ++ val;
continue val
/- Get structure name and elaborate explicit source (if available) -/
private def getStructName (stx : Syntax) (expectedType? : Option Expr) (sourceView : Source) : TermElabM Name := do
let ref := stx;
tryPostponeIfNoneOrMVar expectedType?;
let useSource : Unit → TermElabM Name := fun _ =>
match sourceView with
| Source.explicit _ src => do
srcType ← inferType stx src;
srcType ← whnf stx srcType;
tryPostponeIfMVar srcType;
match srcType.getAppFn with
| Expr.const constName _ _ => pure constName
| _ => throwError stx ("invalid {...} notation, source type is not of the form (C ...)" ++ indentExpr srcType)
| _ => throwError ref ("invalid {...} notation, expected type is not of the form (C ...)" ++ indentExpr expectedType?.get!);
match expectedType? with
| none => useSource ()
| some expectedType => do
expectedType ← whnf ref expectedType;
match expectedType.getAppFn with
| Expr.const constName _ _ => pure constName
| _ => useSource ()
inductive FieldLHS
| fieldName (ref : Syntax) (name : Name)
| fieldIndex (ref : Syntax) (idx : Nat)
| modifyOp (ref : Syntax) (index : Syntax)
instance FieldLHS.inhabited : Inhabited FieldLHS := ⟨FieldLHS.fieldName (arbitrary _) (arbitrary _)⟩
instance FieldLHS.hasFormat : HasFormat FieldLHS :=
⟨fun lhs => match lhs with
| FieldLHS.fieldName _ n => fmt n
| FieldLHS.fieldIndex _ i => fmt i
| FieldLHS.modifyOp _ i => "[" ++ i.prettyPrint ++ "]"⟩
inductive FieldVal (σ : Type)
| term (stx : Syntax) : FieldVal
| nested (s : σ) : FieldVal
| default : FieldVal -- mark that field must be synthesized using default value
structure Field (σ : Type) :=
(ref : Syntax) (lhs : List FieldLHS) (val : FieldVal σ) (expr? : Option Expr := none)
instance Field.inhabited {σ} : Inhabited (Field σ) := ⟨⟨arbitrary _, [], FieldVal.term (arbitrary _), arbitrary _⟩⟩
def Field.isSimple {σ} : Field σ → Bool
| { lhs := [_], .. } => true
| _ => false
inductive Struct
| mk (ref : Syntax) (structName : Name) (fields : List (Field Struct)) (source : Source)
instance Struct.inhabited : Inhabited Struct := ⟨⟨arbitrary _, arbitrary _, [], arbitrary _⟩⟩
abbrev Fields := List (Field Struct)
def Struct.ref : Struct → Syntax
| ⟨ref, _, _, _⟩ => ref
def Struct.structName : Struct → Name
| ⟨_, structName, _, _⟩ => structName
def Struct.fields : Struct → Fields
| ⟨_, _, fields, _⟩ => fields
def Struct.source : Struct → Source
| ⟨_, _, _, s⟩ => s
def formatField (formatStruct : Struct → Format) (field : Field Struct) : Format :=
Format.joinSep field.lhs " . " ++ " := " ++
match field.val with
| FieldVal.term v => v.prettyPrint
| FieldVal.nested s => formatStruct s
| FieldVal.default => "<default>"
partial def formatStruct : Struct → Format
| ⟨_, structName, fields, source⟩ =>
let fieldsFmt := Format.joinSep (fields.map (formatField formatStruct)) ", ";
match source with
| Source.none => "{" ++ fieldsFmt ++ "}"
| Source.implicit _ => "{" ++ fieldsFmt ++ " .. }"
| Source.explicit _ src => "{" ++ format src ++ " with " ++ fieldsFmt ++ "}"
instance Struct.hasFormat : HasFormat Struct := ⟨formatStruct⟩
instance Struct.hasToString : HasToString Struct := ⟨toString ∘ format⟩
instance Field.hasFormat : HasFormat (Field Struct) := ⟨formatField formatStruct⟩
instance Field.hasToString : HasToString (Field Struct) := ⟨toString ∘ format⟩
/-
Recall that `structInstField` elements have the form
```
def structInstField := parser! structInstLVal >> " := " >> termParser
def structInstLVal := (ident <|> numLit <|> structInstArrayRef) >> many (("." >> (ident <|> numLit)) <|> structInstArrayRef)
def structInstArrayRef := parser! "[" >> termParser >>"]"
-/
-- Remark: this code relies on the fact that `expandStruct` only transforms `fieldLHS.fieldName`
def FieldLHS.toSyntax (first : Bool) : FieldLHS → Syntax
| FieldLHS.modifyOp stx _ => stx
| FieldLHS.fieldName stx name => if first then mkIdentFrom stx name else mkNullNode #[mkAtomFrom stx ".", mkIdentFrom stx name]
| FieldLHS.fieldIndex stx _ => if first then stx else mkNullNode #[mkAtomFrom stx ".", stx]
def FieldVal.toSyntax : FieldVal Struct → Syntax
| FieldVal.term stx => stx
| _ => unreachable!
def Field.toSyntax : Field Struct → Syntax
| field =>
let stx := field.ref;
let stx := stx.setArg 3 field.val.toSyntax;
match field.lhs with
| first::rest =>
let stx := stx.setArg 0 $ first.toSyntax true;
let stx := stx.setArg 1 $ mkNullNode $ rest.toArray.map (FieldLHS.toSyntax false);
stx
| _ => unreachable!
private def toFieldLHS (stx : Syntax) : Except String FieldLHS :=
if stx.getKind == `Lean.Parser.Term.structInstArrayRef then
pure $ FieldLHS.modifyOp stx (stx.getArg 1)
else
-- Note that the representation of the first field is different.
let stx := if stx.getKind == nullKind then stx.getArg 1 else stx;
if stx.isIdent then pure $ FieldLHS.fieldName stx stx.getId
else match stx.isFieldIdx? with
| some idx => pure $ FieldLHS.fieldIndex stx idx
| none => throw "unexpected structure syntax"
private def mkStructView (stx : Syntax) (structName : Name) (source : Source) : Except String Struct := do
let args := (stx.getArg 2).getArgs;
let fieldsStx := args.filter $ fun arg => arg.getKind == `Lean.Parser.Term.structInstField;
fields ← fieldsStx.toList.mapM $ fun fieldStx => do {
let val := fieldStx.getArg 3;
first ← toFieldLHS (fieldStx.getArg 0);
rest ← (fieldStx.getArg 1).getArgs.toList.mapM toFieldLHS;
pure $ ({ref := fieldStx, lhs := first :: rest, val := FieldVal.term val } : Field Struct)
};
pure ⟨stx, structName, fields, source⟩
def Struct.modifyFieldsM {m : Type → Type} [Monad m] (s : Struct) (f : Fields → m Fields) : m Struct :=
match s with
| ⟨ref, structName, fields, source⟩ => do fields ← f fields; pure ⟨ref, structName, fields, source⟩
@[inline] def Struct.modifyFields (s : Struct) (f : Fields → Fields) : Struct :=
Id.run $ s.modifyFieldsM f
def Struct.setFields (s : Struct) (fields : Fields) : Struct :=
s.modifyFields $ fun _ => fields
private def expandCompositeFields (s : Struct) : Struct :=
s.modifyFields $ fun fields => fields.map $ fun field => match field with
| { lhs := FieldLHS.fieldName ref (Name.str Name.anonymous _ _) :: rest, .. } => field
| { lhs := FieldLHS.fieldName ref n@(Name.str _ _ _) :: rest, .. } =>
let newEntries := n.components.map $ FieldLHS.fieldName ref;
{ field with lhs := newEntries ++ rest }
| _ => field
private def expandNumLitFields (s : Struct) : TermElabM Struct :=
s.modifyFieldsM $ fun fields => do
env ← getEnv;
let fieldNames := getStructureFields env s.structName;
fields.mapM $ fun field => match field with
| { lhs := FieldLHS.fieldIndex ref idx :: rest, .. } =>
if idx == 0 then throwError ref "invalid field index, index must be greater than 0"
else if idx > fieldNames.size then throwError ref ("invalid field index, structure has only #" ++ toString fieldNames.size ++ " fields")
else pure { field with lhs := FieldLHS.fieldName ref (fieldNames.get! $ idx - 1) :: rest }
| _ => pure field
/- For example, consider the following structures:
```
structure A := (x : Nat)
structure B extends A := (y : Nat)
structure C extends B := (z : Bool)
```
This method expands parent structure fields using the path to the parent structure.
For example,
```
{ x := 0, y := 0, z := true : C }
```
is expanded into
```
{ toB.toA.x := 0, toB.y := 0, z := true : C }
``` -/
private def expandParentFields (s : Struct) : TermElabM Struct := do
env ← getEnv;
s.modifyFieldsM $ fun fields => fields.mapM $ fun field => match field with
| { lhs := FieldLHS.fieldName ref fieldName :: rest, .. } =>
match findField? env s.structName fieldName with
| none => throwError ref ("'" ++ fieldName ++ "' is not a field of structure '" ++ s.structName ++ "'")
| some baseStructName =>
if baseStructName == s.structName then pure field
else match getPathToBaseStructure? env baseStructName s.structName with
| some path => do
let path := path.map $ fun funName => match funName with
| Name.str _ s _ => FieldLHS.fieldName ref (mkNameSimple s)
| _ => unreachable!;
pure { field with lhs := path ++ field.lhs }
| _ => throwError ref ("failed to access field '" ++ fieldName ++ "' in parent structure")
| _ => pure field
private abbrev FieldMap := HashMap Name Fields
private def mkFieldMap (fields : Fields) : TermElabM FieldMap :=
fields.foldlM
(fun fieldMap field =>
match field.lhs with
| FieldLHS.fieldName _ fieldName :: rest =>
match fieldMap.find? fieldName with
| some (prevField::restFields) =>
if field.isSimple || prevField.isSimple then
throwError field.ref ("field '" ++ fieldName ++ "' has already beed specified")
else
pure $ fieldMap.insert fieldName (field::prevField::restFields)
| _ => pure $ fieldMap.insert fieldName [field]
| _ => unreachable!)
{}
private def isSimpleField? : Fields → Option (Field Struct)
| [field] => if field.isSimple then some field else none
| _ => none
private def getFieldIdx (ref : Syntax) (structName : Name) (fieldNames : Array Name) (fieldName : Name) : TermElabM Nat := do
match fieldNames.findIdx? $ fun n => n == fieldName with
| some idx => pure idx
| none => throwError ref ("field '" ++ fieldName ++ "' is not a valid field of '" ++ structName ++ "'")
private def mkProjStx (s : Syntax) (fieldName : Name) : Syntax :=
Syntax.node `Lean.Parser.Term.proj #[s, mkAtomFrom s ".", mkIdentFrom s fieldName]
private def mkSubstructSource (ref : Syntax) (structName : Name) (fieldNames : Array Name) (fieldName : Name) (src : Source) : TermElabM Source :=
match src with
| Source.explicit stx src => do
idx ← getFieldIdx ref structName fieldNames fieldName;
let stx := stx.modifyArg 0 $ fun stx => mkProjStx stx fieldName;
pure $ Source.explicit stx (mkProj structName idx src)
| s => pure s
@[specialize] private def groupFields (expandStruct : Struct → TermElabM Struct) (s : Struct) : TermElabM Struct := do
env ← getEnv;
let fieldNames := getStructureFields env s.structName;
s.modifyFieldsM $ fun fields => do
fieldMap ← mkFieldMap fields;
fieldMap.toList.mapM $ fun ⟨fieldName, fields⟩ =>
match isSimpleField? fields with
| some field => pure field
| none => do
let substructFields := fields.map $ fun field => { field with lhs := field.lhs.tail! };
substructSource ← mkSubstructSource s.ref s.structName fieldNames fieldName s.source;
let field := fields.head!;
match Lean.isSubobjectField? env s.structName fieldName with
| some substructName => do
let substruct := Struct.mk s.ref substructName substructFields substructSource;
substruct ← expandStruct substruct;
pure { field with lhs := [field.lhs.head!], val := FieldVal.nested substruct }
| none => do
-- It is not a substructure field. Thus, we wrap fields using `Syntax`, and use `elabTerm` to process them.
let valStx := s.ref; -- construct substructure syntax using s.ref as template
let valStx := valStx.setArg 4 mkNullNode; -- erase optional expected type
let args := substructFields.toArray.map $ Field.toSyntax;
let valStx := valStx.setArg 2 (mkSepStx args (mkAtomFrom s.ref ","));
let valStx := setStructSourceSyntax valStx substructSource;
pure { field with lhs := [field.lhs.head!], val := FieldVal.term valStx }
def findField? (fields : Fields) (fieldName : Name) : Option (Field Struct) :=
fields.find? $ fun field =>
match field.lhs with
| [FieldLHS.fieldName _ n] => n == fieldName
| _ => false
@[specialize] private def addMissingFields (expandStruct : Struct → TermElabM Struct) (s : Struct) : TermElabM Struct := do
env ← getEnv;
let fieldNames := getStructureFields env s.structName;
let ref := s.ref;
fields ← fieldNames.foldlM
(fun fields fieldName => do
match findField? s.fields fieldName with
| some field => pure $ field::fields
| none =>
let addField (val : FieldVal Struct) : TermElabM Fields := do {
pure $ { ref := s.ref, lhs := [FieldLHS.fieldName s.ref fieldName], val := val } :: fields
};
match Lean.isSubobjectField? env s.structName fieldName with
| some substructName => do
substructSource ← mkSubstructSource s.ref s.structName fieldNames fieldName s.source;
let substruct := Struct.mk s.ref substructName [] substructSource;
substruct ← expandStruct substruct;
addField (FieldVal.nested substruct)
| none =>
match s.source with
| Source.none => addField FieldVal.default
| Source.implicit _ => addField (FieldVal.term (mkHole s.ref))
| Source.explicit stx _ =>
-- stx is of the form `optional (try (termParser >> "with"))`
let src := (stx.getArg 0).getArg 0;
let val := mkProjStx src fieldName;
addField (FieldVal.term val))
[];
pure $ s.setFields fields.reverse
private partial def expandStruct : Struct → TermElabM Struct
| s => do
let s := expandCompositeFields s;
s ← expandNumLitFields s;
s ← expandParentFields s;
s ← groupFields expandStruct s;
addMissingFields expandStruct s
structure CtorHeaderResult :=
(ctorFn : Expr)
(ctorFnType : Expr)
(instMVars : Array MVarId := #[])
private def mkCtorHeaderAux (ref : Syntax) : Nat → Expr → Expr → Array MVarId → TermElabM CtorHeaderResult
| 0, type, ctorFn, instMVars => pure { ctorFn := ctorFn, ctorFnType := type, instMVars := instMVars }
| n+1, type, ctorFn, instMVars => do
type ← whnfForall ref type;
match type with
| Expr.forallE _ d b c =>
match c.binderInfo with
| BinderInfo.instImplicit => do
a ← mkFreshExprMVar ref d MetavarKind.synthetic;
mkCtorHeaderAux n (b.instantiate1 a) (mkApp ctorFn a) (instMVars.push a.mvarId!)
| _ => do
a ← mkFreshExprMVar ref d;
mkCtorHeaderAux n (b.instantiate1 a) (mkApp ctorFn a) instMVars
| _ => throwError ref "unexpected constructor type"
private partial def getForallBody : Nat → Expr → Option Expr
| i+1, Expr.forallE _ _ b _ => getForallBody i b
| i+1, _ => none
| 0, type => type
private def propagateExpectedType (ref : Syntax) (type : Expr) (numFields : Nat) (expectedType? : Option Expr) : TermElabM Unit :=
match expectedType? with
| none => pure ()
| some expectedType =>
match getForallBody numFields type with
| none => pure ()
| some typeBody =>
unless typeBody.hasLooseBVars $ do
_ ← isDefEq ref expectedType typeBody;
pure ()
private def mkCtorHeader (ref : Syntax) (ctorVal : ConstructorVal) (expectedType? : Option Expr) : TermElabM CtorHeaderResult := do
lvls ← ctorVal.lparams.mapM $ fun _ => mkFreshLevelMVar ref;
let val := Lean.mkConst ctorVal.name lvls;
let type := (ConstantInfo.ctorInfo ctorVal).instantiateTypeLevelParams lvls;
r ← mkCtorHeaderAux ref ctorVal.nparams type val #[];
propagateExpectedType ref r.ctorFnType ctorVal.nfields expectedType?;
synthesizeAppInstMVars ref r.instMVars;
pure r
def markDefaultMissing (e : Expr) : Expr :=
mkAnnotation `structInstDefault e
def isDefaultMissing? (e : Expr) : Option Expr :=
isAnnotation? `structInstDefault e
def throwFailedToElabField {α} (ref : Syntax) (fieldName : Name) (structName : Name) (msgData : MessageData) : TermElabM α :=
throwError ref ("failed to elaborate field '" ++ fieldName ++ "' of '" ++ structName ++ ", " ++ msgData)
private partial def elabStruct : Struct → Option Expr → TermElabM (Expr × Struct)
| s, expectedType? => do
env ← getEnv;
let ctorVal := getStructureCtor env s.structName;
{ ctorFn := ctorFn, ctorFnType := ctorFnType, .. } ← mkCtorHeader s.ref ctorVal expectedType?;
(e, _, fields) ← s.fields.foldlM
(fun (acc : Expr × Expr × Fields) field =>
let (e, type, fields) := acc;
match field.lhs with
| [FieldLHS.fieldName ref fieldName] => do
type ← whnfForall field.ref type;
match type with
| Expr.forallE _ d b c =>
let continue (val : Expr) (field : Field Struct) : TermElabM (Expr × Expr × Fields) := do {
let e := mkApp e val;
let type := b.instantiate1 val;
let field := { field with expr? := some val };
pure (e, type, field::fields)
};
match field.val with
| FieldVal.term stx => do val ← elabTerm stx (some d); val ← ensureHasType stx d val; continue val field
| FieldVal.nested s => do (val, sNew) ← elabStruct s (some d); val ← ensureHasType s.ref d val; continue val { field with val := FieldVal.nested sNew }
| FieldVal.default => do val ← mkFreshExprMVar field.ref (some d); continue (markDefaultMissing val) field
| _ => throwFailedToElabField field.ref fieldName s.structName ("unexpected constructor type" ++ indentExpr type)
| _ => throwError field.ref "unexpected unexpanded structure field")
(ctorFn, ctorFnType, []);
pure (e, s.setFields fields.reverse)
namespace DefaultFields
structure Context :=
-- We must search for default values overriden in derived structures
(structs : Array Struct := #[])
(allStructNames : Array Name := #[])
/-
Consider the following example:
```
structure A :=
(x : Nat := 1)
structure B extends A :=
(y : Nat := x + 1) (x := y + 1)
structure C extends B :=
(z : Nat := 2*y) (x := z + 3)
```
And we are trying to elaborate a structure instance for `C`. There are default values for `x` at `A`, `B`, and `C`.
We say the default value at `C` has distance 0, the one at `B` distance 1, and the one at `A` distance 2.
The field `maxDistance` specifies the maximum distance considered in a round of Default field computation.
Remark: since `C` does not set a default value of `y`, the default value at `B` is at distance 0.
The fixpoint for setting default values works in the following way.
- Keep computing default values using `maxDistance == 0`.
- We increase `maxDistance` whenever we failed to compute a new default value in a round.
- If `maxDistance > 0`, then we interrupt a round as soon as we compute some default value.
We use depth-first search.
- We sign an error if no progress is made when `maxDistance` == structure hierarchy depth (2 in the example above).
-/
(maxDistance : Nat := 0)
structure State :=
(progress : Bool := false)
partial def collectStructNames : Struct → Array Name → Array Name
| struct, names =>
let names := names.push struct.structName;
struct.fields.foldl
(fun names field =>
match field.val with
| FieldVal.nested struct => collectStructNames struct names
| _ => names)
names
partial def getHierarchyDepth : Struct → Nat
| struct =>
struct.fields.foldl
(fun max field =>
match field.val with
| FieldVal.nested struct => Nat.max max (getHierarchyDepth struct + 1)
| _ => max)
0
partial def findDefaultMissing? (mctx : MetavarContext) : Struct → Option (Field Struct)
| struct =>
struct.fields.findSome? $ fun field =>
match field.val with
| FieldVal.nested struct => findDefaultMissing? struct
| _ => match field.expr? with
| none => unreachable!
| some expr => match isDefaultMissing? expr with
| some (Expr.mvar mvarId _) => if mctx.isExprAssigned mvarId then none else some field
| _ => none
def getFieldName (field : Field Struct) : Name :=
match field.lhs with
| [FieldLHS.fieldName _ fieldName] => fieldName
| _ => unreachable!
abbrev M := ReaderT Context (StateT State TermElabM)
def isRoundDone : M Bool := do
ctx ← read;
s ← get;
pure (s.progress && ctx.maxDistance > 0)
def getFieldValue? (struct : Struct) (fieldName : Name) : Option Expr :=
struct.fields.findSome? $ fun field =>
if getFieldName field == fieldName then
field.expr?
else
none
partial def mkDefaultValueAux? (struct : Struct) : Expr → TermElabM (Option Expr)
| Expr.lam n d b c =>
let ref := struct.ref;
if c.binderInfo.isExplicit then
let fieldName := n;
match getFieldValue? struct fieldName with
| none => pure none
| some val => do
valType ← inferType ref val;
condM (isDefEq ref valType d)
(mkDefaultValueAux? (b.instantiate1 val))
(pure none)
else do
arg ← mkFreshExprMVar ref d;
mkDefaultValueAux? (b.instantiate1 arg)
| e =>
if e.isAppOfArity `id 2 then
pure (some e.appArg!)
else
pure (some e)
def mkDefaultValue? (struct : Struct) (cinfo : ConstantInfo) : TermElabM (Option Expr) := do
let ref := struct.ref;
us ← cinfo.lparams.mapM $ fun _ => mkFreshLevelMVar ref;
mkDefaultValueAux? struct (cinfo.instantiateValueLevelParams us)
/-- If `e` is a projection function of one of the given structures, then reduce it -/
def reduceProjOf? (structNames : Array Name) (e : Expr) : MetaM (Option Expr) := do
if !e.isApp then pure none
else match e.getAppFn with
| Expr.const name _ _ => do
env ← Meta.getEnv;
if env.isProjectionFn name then
match name with
| Name.str structName fieldName _ => do
if structNames.contains structName then
Meta.unfoldDefinition? e
else
pure none
| _ => pure none
else
pure none
| _ => pure none
/-- Reduce default value. It performs beta reduction and projections of the given structures. -/
partial def reduce (structNames : Array Name) : Expr → MetaM Expr
| e@(Expr.lam _ _ _ _) => Meta.lambdaTelescope e $ fun xs b => do b ← reduce b; Meta.mkLambda xs b
| e@(Expr.forallE _ _ _ _) => Meta.forallTelescope e $ fun xs b => do b ← reduce b; Meta.mkForall xs b
| e@(Expr.letE _ _ _ _ _) => Meta.lambdaTelescope e $ fun xs b => do b ← reduce b; Meta.mkLambda xs b
| e@(Expr.proj _ i b _) => do
r? ← Meta.reduceProj? b i;
match r? with
| some r => reduce r
| none => do b ← reduce b; pure $ e.updateProj! b
| e@(Expr.app f _ _) => do
r? ← reduceProjOf? structNames e;
match r? with
| some r => reduce r
| none => do
let f := f.getAppFn;
f' ← reduce f;
if f'.isLambda then
let revArgs := e.getAppRevArgs;
reduce $ f'.betaRev revArgs
else do
args ← e.getAppArgs.mapM reduce;
pure (mkAppN f' args)
| e@(Expr.mdata _ b _) => do
b ← reduce b;
if (isDefaultMissing? e).isSome && !b.isMVar then
pure b
else
pure $ e.updateMData! b
| e@(Expr.mvar mvarId _) => do
val? ← Meta.getExprMVarAssignment? mvarId;
match val? with
| some val => if val.isMVar then reduce val else pure val
| none => pure e
| e => pure e
partial def tryToSynthesizeDefaultAux (ref : Syntax) (structs : Array Struct) (allStructNames : Array Name) (maxDistance : Nat)
(fieldName : Name) (mvarId : MVarId) : Nat → Nat → TermElabM Bool
| i, dist =>
if dist > maxDistance then pure false
else if h : i < structs.size then do
let struct := structs.get ⟨i, h⟩;
let defaultName := struct.structName ++ fieldName ++ `_default;
env ← getEnv;
match env.find? defaultName with
| some cinfo@(ConstantInfo.defnInfo defVal) => do
mctx ← getMCtx;
val? ← mkDefaultValue? struct cinfo;
match val? with
| none => do setMCtx mctx; tryToSynthesizeDefaultAux (i+1) (dist+1)
| some val => do
val ← liftMetaM struct.ref $ reduce allStructNames val;
match val.find? $ fun e => (isDefaultMissing? e).isSome with
| some _ => do setMCtx mctx; tryToSynthesizeDefaultAux (i+1) (dist+1)
| none => do
mvarDecl ← getMVarDecl mvarId;
val ← ensureHasType ref mvarDecl.type val;
assignExprMVar mvarId val;
pure true
| _ => tryToSynthesizeDefaultAux (i+1) dist
else
pure false
def tryToSynthesizeDefault (ref : Syntax) (structs : Array Struct) (allStructNames : Array Name)
(maxDistance : Nat) (fieldName : Name) (mvarId : MVarId) : TermElabM Bool :=
tryToSynthesizeDefaultAux ref structs allStructNames maxDistance fieldName mvarId 0 0
partial def step : Struct → M Unit
| struct => unlessM isRoundDone $ adaptReader (fun (ctx : Context) => { ctx with structs := ctx.structs.push struct }) $ do
struct.fields.forM $ fun field =>
match field.val with
| FieldVal.nested struct => step struct
| _ => match field.expr? with
| none => unreachable!
| some expr => match isDefaultMissing? expr with
| some (Expr.mvar mvarId _) =>
unlessM (liftM $ isExprMVarAssigned mvarId) $ do
ctx ← read;
whenM (liftM $ tryToSynthesizeDefault field.ref ctx.structs ctx.allStructNames ctx.maxDistance (getFieldName field) mvarId) $ do
modify $ fun s => { s with progress := true }
| _ => pure ()
partial def propagateLoop (hierarchyDepth : Nat) : Nat → Struct → M Unit
| d, struct => do
mctx ← liftM $ getMCtx;
match findDefaultMissing? mctx struct with
| none => pure () -- Done
| some field =>
if d > hierarchyDepth then
liftM $ throwError field.ref ("field '" ++ getFieldName field ++ "' is missing")
else adaptReader (fun (ctx : Context) => { ctx with maxDistance := d }) $ do
modify $ fun (s : State) => { s with progress := false };
step struct;
s ← get;
if s.progress then do
propagateLoop 0 struct
else
propagateLoop (d+1) struct
def propagate (struct : Struct) : TermElabM Unit :=
let hierarchyDepth := getHierarchyDepth struct;
let structNames := collectStructNames struct #[];
(propagateLoop hierarchyDepth 0 struct { allStructNames := structNames }).run' {}
end DefaultFields
private def elabStructInstAux (stx : Syntax) (expectedType? : Option Expr) (source : Source) : TermElabM Expr := do
structName ← getStructName stx expectedType? source;
env ← getEnv;
unless (isStructureLike env structName) $
throwError stx ("invalid {...} notation, '" ++ structName ++ "' is not a structure");
match mkStructView stx structName source with
| Except.error ex => throwError stx ex
| Except.ok struct => do
struct ← expandStruct struct;
trace `Elab.struct stx $ fun _ => toString struct;
(r, struct) ← elabStruct struct expectedType?;
DefaultFields.propagate struct;
pure r
private def expandStructInstExpectedType (stx : Syntax) : MacroM (Option Syntax) :=
let expectedArg := stx.getArg 4;
if expectedArg.isNone then pure none
else
let expected := expectedArg.getArg 1;
let stxNew := stx.setArg 4 mkNullNode;
`(($stxNew : $expected))
@[builtinTermElab structInst] def elabStructInst : TermElab :=
fun stx expectedType? => do
stxNew? ← liftMacroM $ expandStructInstExpectedType stx;
match stxNew? with
| some stxNew => withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
| none => do
stxNew? ← expandNonAtomicExplicitSource stx;
match stxNew? with
| some stxNew => withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
| none => do
sourceView ← getStructSource stx;
modifyOp? ← isModifyOp? stx;
match modifyOp?, sourceView with
| some modifyOp, Source.explicit source _ => elabModifyOp stx modifyOp source expectedType?
| some _, _ => throwError stx ("invalid {...} notation, explicit source is required when using '[<index>] := <value>'")
| _, _ => elabStructInstAux stx expectedType? sourceView
@[init] private def regTraceClasses : IO Unit := do
registerTraceClass `Elab.struct;
pure ()
end StructInst
end Term
end Elab
end Lean
|
35bf2033c61063e41512885a78f8c1fea5010ef7 | 88892181780ff536a81e794003fe058062f06758 | /src/100_theorems/t066.lean | e0af985f8e3391caf99e5b6a613f7c39d89bfc51 | [] | no_license | AtnNn/lean-sandbox | fe2c44280444e8bb8146ab8ac391c82b480c0a2e | 8c68afbdc09213173aef1be195da7a9a86060a97 | refs/heads/master | 1,623,004,395,876 | 1,579,969,507,000 | 1,579,969,507,000 | 146,666,368 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 374 | lean | import algebra.big_operators
import analysis.specific_limits
-- Sum of a Geometric Series
open finset
theorem t066_finite {α} [division_ring α] {x : α} : Π (h : x ≠ 1) (n : ℕ),
(range n).sum (λ i, x^i) = (x^n-1)/(x-1)
:= geom_sum
lemma t066_infinite {r : ℝ} : Π (h₁ : 0 ≤ r) (h₂ : r < 1),
has_sum (λn:ℕ, r ^ n) (1 - r)⁻¹
:= has_sum_geometric
|
b6682eeb1ed683bff05307c4fa1ffa6578281e63 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/analysis/calculus/deriv.lean | b78d3afa55eb2ae35a68d12d002fcb1e62652660 | [
"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 | 85,893 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel
-/
import analysis.calculus.fderiv
import data.polynomial.derivative
/-!
# One-dimensional derivatives
This file defines the derivative of a function `f : 𝕜 → F` where `𝕜` is a
normed field and `F` is a normed space over this field. The derivative of
such a function `f` at a point `x` is given by an element `f' : F`.
The theory is developed analogously to the [Fréchet
derivatives](./fderiv.lean). We first introduce predicates defined in terms
of the corresponding predicates for Fréchet derivatives:
- `has_deriv_at_filter f f' x L` states that the function `f` has the
derivative `f'` at the point `x` as `x` goes along the filter `L`.
- `has_deriv_within_at f f' s x` states that the function `f` has the
derivative `f'` at the point `x` within the subset `s`.
- `has_deriv_at f f' x` states that the function `f` has the derivative `f'`
at the point `x`.
- `has_strict_deriv_at f f' x` states that the function `f` has the derivative `f'`
at the point `x` in the sense of strict differentiability, i.e.,
`f y - f z = (y - z) • f' + o (y - z)` as `y, z → x`.
For the last two notions we also define a functional version:
- `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the
derivative does not exist, then `deriv_within f s x` equals zero.
- `deriv f x` is a derivative of `f` at `x`. If the derivative does not
exist, then `deriv f x` equals zero.
The theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the
one-dimensional derivatives coincide with the general Fréchet derivatives.
We also show the existence and compute the derivatives of:
- constants
- the identity function
- linear maps
- addition
- sum of finitely many functions
- negation
- subtraction
- multiplication
- inverse `x → x⁻¹`
- multiplication of two functions in `𝕜 → 𝕜`
- multiplication of a function in `𝕜 → 𝕜` and of a function in `𝕜 → E`
- composition of a function in `𝕜 → F` with a function in `𝕜 → 𝕜`
- composition of a function in `F → E` with a function in `𝕜 → F`
- inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`)
- division
- polynomials
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.
We set up the simplifier so that it can compute the derivative of simple functions. For instance,
```lean
example (x : ℝ) : deriv (λ x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=
by { simp, ring }
```
## Implementation notes
Most of the theorems are direct restatements of the corresponding theorems
for Fréchet derivatives.
The strategy to construct simp lemmas that give the simplifier the possibility to compute
derivatives is the same as the one for differentiability statements, as explained in `fderiv.lean`.
See the explanations there.
-/
universes u v w
noncomputable theory
open_locale classical topological_space big_operators filter ennreal
open filter asymptotics set
open continuous_linear_map (smul_right smul_right_one_eq_iff)
variables {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
section
variables {F : Type v} [normed_group F] [normed_space 𝕜 F]
variables {E : Type w} [normed_group E] [normed_space 𝕜 E]
/--
`f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges along the filter `L`.
-/
def has_deriv_at_filter (f : 𝕜 → F) (f' : F) (x : 𝕜) (L : filter 𝕜) :=
has_fderiv_at_filter f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x L
/--
`f` has the derivative `f'` at the point `x` within the subset `s`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def has_deriv_within_at (f : 𝕜 → F) (f' : F) (s : set 𝕜) (x : 𝕜) :=
has_deriv_at_filter f f' x (𝓝[s] x)
/--
`f` has the derivative `f'` at the point `x`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x`.
-/
def has_deriv_at (f : 𝕜 → F) (f' : F) (x : 𝕜) :=
has_deriv_at_filter f f' x (𝓝 x)
/-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability.
That is, `f y - f z = (y - z) • f' + o(y - z)` as `y, z → x`. -/
def has_strict_deriv_at (f : 𝕜 → F) (f' : F) (x : 𝕜) :=
has_strict_fderiv_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x
/--
Derivative of `f` at the point `x` within the set `s`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_within_at f f' s x`), then
`f x' = f x + (x' - x) • deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def deriv_within (f : 𝕜 → F) (s : set 𝕜) (x : 𝕜) :=
fderiv_within 𝕜 f s x 1
/--
Derivative of `f` at the point `x`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_at f f' x`), then
`f x' = f x + (x' - x) • deriv f x + o(x' - x)` where `x'` converges to `x`.
-/
def deriv (f : 𝕜 → F) (x : 𝕜) :=
fderiv 𝕜 f x 1
variables {f f₀ f₁ g : 𝕜 → F}
variables {f' f₀' f₁' g' : F}
variables {x : 𝕜}
variables {s t : set 𝕜}
variables {L L₁ L₂ : filter 𝕜}
/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/
lemma has_fderiv_at_filter_iff_has_deriv_at_filter {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at_filter f f' x L ↔ has_deriv_at_filter f (f' 1) x L :=
by simp [has_deriv_at_filter]
lemma has_fderiv_at_filter.has_deriv_at_filter {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at_filter f f' x L → has_deriv_at_filter f (f' 1) x L :=
has_fderiv_at_filter_iff_has_deriv_at_filter.mp
/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/
lemma has_fderiv_within_at_iff_has_deriv_within_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_within_at f f' s x ↔ has_deriv_within_at f (f' 1) s x :=
has_fderiv_at_filter_iff_has_deriv_at_filter
/-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/
lemma has_deriv_within_at_iff_has_fderiv_within_at {f' : F} :
has_deriv_within_at f f' s x ↔
has_fderiv_within_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') s x :=
iff.rfl
lemma has_fderiv_within_at.has_deriv_within_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_within_at f f' s x → has_deriv_within_at f (f' 1) s x :=
has_fderiv_within_at_iff_has_deriv_within_at.mp
lemma has_deriv_within_at.has_fderiv_within_at {f' : F} :
has_deriv_within_at f f' s x → has_fderiv_within_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') s x :=
has_deriv_within_at_iff_has_fderiv_within_at.mp
/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/
lemma has_fderiv_at_iff_has_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at f f' x ↔ has_deriv_at f (f' 1) x :=
has_fderiv_at_filter_iff_has_deriv_at_filter
lemma has_fderiv_at.has_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at f f' x → has_deriv_at f (f' 1) x :=
has_fderiv_at_iff_has_deriv_at.mp
lemma has_strict_fderiv_at_iff_has_strict_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_strict_fderiv_at f f' x ↔ has_strict_deriv_at f (f' 1) x :=
by simp [has_strict_deriv_at, has_strict_fderiv_at]
protected lemma has_strict_fderiv_at.has_strict_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_strict_fderiv_at f f' x → has_strict_deriv_at f (f' 1) x :=
has_strict_fderiv_at_iff_has_strict_deriv_at.mp
lemma has_strict_deriv_at_iff_has_strict_fderiv_at :
has_strict_deriv_at f f' x ↔ has_strict_fderiv_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x :=
iff.rfl
alias has_strict_deriv_at_iff_has_strict_fderiv_at ↔ has_strict_deriv_at.has_strict_fderiv_at _
/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/
lemma has_deriv_at_iff_has_fderiv_at {f' : F} :
has_deriv_at f f' x ↔
has_fderiv_at f (smul_right (1 : 𝕜 →L[𝕜] 𝕜) f') x :=
iff.rfl
alias has_deriv_at_iff_has_fderiv_at ↔ has_deriv_at.has_fderiv_at _
lemma deriv_within_zero_of_not_differentiable_within_at
(h : ¬ differentiable_within_at 𝕜 f s x) : deriv_within f s x = 0 :=
by { unfold deriv_within, rw fderiv_within_zero_of_not_differentiable_within_at, simp, assumption }
lemma deriv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : deriv f x = 0 :=
by { unfold deriv, rw fderiv_zero_of_not_differentiable_at, simp, assumption }
theorem unique_diff_within_at.eq_deriv (s : set 𝕜) (H : unique_diff_within_at 𝕜 s x)
(h : has_deriv_within_at f f' s x) (h₁ : has_deriv_within_at f f₁' s x) : f' = f₁' :=
smul_right_one_eq_iff.mp $ unique_diff_within_at.eq H h h₁
theorem has_deriv_at_filter_iff_tendsto :
has_deriv_at_filter f f' x L ↔
tendsto (λ x' : 𝕜, ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) L (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_within_at_iff_tendsto : has_deriv_within_at f f' s x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (𝓝[s] x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_at_iff_tendsto : has_deriv_at f f' x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (𝓝 x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_strict_deriv_at.has_deriv_at (h : has_strict_deriv_at f f' x) :
has_deriv_at f f' x :=
h.has_fderiv_at
/-- If the domain has dimension one, then Fréchet derivative is equivalent to the classical
definition with a limit. In this version we have to take the limit along the subset `-{x}`,
because for `y=x` the slope equals zero due to the convention `0⁻¹=0`. -/
lemma has_deriv_at_filter_iff_tendsto_slope {x : 𝕜} {L : filter 𝕜} :
has_deriv_at_filter f f' x L ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') :=
begin
conv_lhs { simp only [has_deriv_at_filter_iff_tendsto, (normed_field.norm_inv _).symm,
(norm_smul _ _).symm, tendsto_zero_iff_norm_tendsto_zero.symm] },
conv_rhs { rw [← nhds_translation f', tendsto_comap_iff] },
refine (tendsto_inf_principal_nhds_iff_of_forall_eq $ by simp).symm.trans (tendsto_congr' _),
refine (eventually_principal.2 $ λ z hz, _).filter_mono inf_le_right,
simp only [(∘)],
rw [smul_sub, ← mul_smul, inv_mul_cancel (sub_ne_zero.2 hz), one_smul]
end
lemma has_deriv_within_at_iff_tendsto_slope :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[s \ {x}] x) (𝓝 f') :=
begin
simp only [has_deriv_within_at, nhds_within, diff_eq, inf_assoc.symm, inf_principal.symm],
exact has_deriv_at_filter_iff_tendsto_slope
end
lemma has_deriv_within_at_iff_tendsto_slope' (hs : x ∉ s) :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[s] x) (𝓝 f') :=
begin
convert ← has_deriv_within_at_iff_tendsto_slope,
exact diff_singleton_eq_self hs
end
lemma has_deriv_at_iff_tendsto_slope :
has_deriv_at f f' x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (𝓝[{x}ᶜ] x) (𝓝 f') :=
has_deriv_at_filter_iff_tendsto_slope
theorem has_deriv_within_at_congr_set {s t u : set 𝕜}
(hu : u ∈ 𝓝 x) (h : s ∩ u = t ∩ u) :
has_deriv_within_at f f' s x ↔ has_deriv_within_at f f' t x :=
by simp_rw [has_deriv_within_at, nhds_within_eq_nhds_within' hu h]
alias has_deriv_within_at_congr_set ↔ has_deriv_within_at.congr_set _
@[simp] lemma has_deriv_within_at_diff_singleton :
has_deriv_within_at f f' (s \ {x}) x ↔ has_deriv_within_at f f' s x :=
by simp only [has_deriv_within_at_iff_tendsto_slope, sdiff_idem]
@[simp] lemma has_deriv_within_at_Ioi_iff_Ici [partial_order 𝕜] :
has_deriv_within_at f f' (Ioi x) x ↔ has_deriv_within_at f f' (Ici x) x :=
by rw [← Ici_diff_left, has_deriv_within_at_diff_singleton]
alias has_deriv_within_at_Ioi_iff_Ici ↔
has_deriv_within_at.Ici_of_Ioi has_deriv_within_at.Ioi_of_Ici
@[simp] lemma has_deriv_within_at_Iio_iff_Iic [partial_order 𝕜] :
has_deriv_within_at f f' (Iio x) x ↔ has_deriv_within_at f f' (Iic x) x :=
by rw [← Iic_diff_right, has_deriv_within_at_diff_singleton]
alias has_deriv_within_at_Iio_iff_Iic ↔
has_deriv_within_at.Iic_of_Iio has_deriv_within_at.Iio_of_Iic
theorem has_deriv_within_at.Ioi_iff_Ioo [linear_order 𝕜] [order_closed_topology 𝕜] {x y : 𝕜}
(h : x < y) :
has_deriv_within_at f f' (Ioo x y) x ↔ has_deriv_within_at f f' (Ioi x) x :=
has_deriv_within_at_congr_set (is_open_Iio.mem_nhds h) $
by { rw [Ioi_inter_Iio, inter_eq_left_iff_subset], exact Ioo_subset_Iio_self }
alias has_deriv_within_at.Ioi_iff_Ioo ↔
has_deriv_within_at.Ioi_of_Ioo has_deriv_within_at.Ioo_of_Ioi
theorem has_deriv_at_iff_is_o_nhds_zero : has_deriv_at f f' x ↔
is_o (λh, f (x + h) - f x - h • f') (λh, h) (𝓝 0) :=
has_fderiv_at_iff_is_o_nhds_zero
theorem has_deriv_at_filter.mono (h : has_deriv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) :
has_deriv_at_filter f f' x L₁ :=
has_fderiv_at_filter.mono h hst
theorem has_deriv_within_at.mono (h : has_deriv_within_at f f' t x) (hst : s ⊆ t) :
has_deriv_within_at f f' s x :=
has_fderiv_within_at.mono h hst
theorem has_deriv_at.has_deriv_at_filter (h : has_deriv_at f f' x) (hL : L ≤ 𝓝 x) :
has_deriv_at_filter f f' x L :=
has_fderiv_at.has_fderiv_at_filter h hL
theorem has_deriv_at.has_deriv_within_at
(h : has_deriv_at f f' x) : has_deriv_within_at f f' s x :=
has_fderiv_at.has_fderiv_within_at h
lemma has_deriv_within_at.differentiable_within_at (h : has_deriv_within_at f f' s x) :
differentiable_within_at 𝕜 f s x :=
has_fderiv_within_at.differentiable_within_at h
lemma has_deriv_at.differentiable_at (h : has_deriv_at f f' x) : differentiable_at 𝕜 f x :=
has_fderiv_at.differentiable_at h
@[simp] lemma has_deriv_within_at_univ : has_deriv_within_at f f' univ x ↔ has_deriv_at f f' x :=
has_fderiv_within_at_univ
theorem has_deriv_at.unique
(h₀ : has_deriv_at f f₀' x) (h₁ : has_deriv_at f f₁' x) : f₀' = f₁' :=
smul_right_one_eq_iff.mp $ h₀.has_fderiv_at.unique h₁
lemma has_deriv_within_at_inter' (h : t ∈ 𝓝[s] x) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter' h
lemma has_deriv_within_at_inter (h : t ∈ 𝓝 x) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter h
lemma has_deriv_within_at.union (hs : has_deriv_within_at f f' s x)
(ht : has_deriv_within_at f f' t x) :
has_deriv_within_at f f' (s ∪ t) x :=
begin
simp only [has_deriv_within_at, nhds_within_union],
exact hs.join ht,
end
lemma has_deriv_within_at.nhds_within (h : has_deriv_within_at f f' s x)
(ht : s ∈ 𝓝[t] x) : has_deriv_within_at f f' t x :=
(has_deriv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
lemma has_deriv_within_at.has_deriv_at (h : has_deriv_within_at f f' s x) (hs : s ∈ 𝓝 x) :
has_deriv_at f f' x :=
has_fderiv_within_at.has_fderiv_at h hs
lemma differentiable_within_at.has_deriv_within_at (h : differentiable_within_at 𝕜 f s x) :
has_deriv_within_at f (deriv_within f s x) s x :=
h.has_fderiv_within_at.has_deriv_within_at
lemma differentiable_at.has_deriv_at (h : differentiable_at 𝕜 f x) : has_deriv_at f (deriv f x) x :=
h.has_fderiv_at.has_deriv_at
lemma differentiable_on.has_deriv_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :
has_deriv_at f (deriv f x) x :=
(h.has_fderiv_at hs).has_deriv_at
lemma has_deriv_at.deriv (h : has_deriv_at f f' x) : deriv f x = f' :=
h.differentiable_at.has_deriv_at.unique h
lemma has_deriv_within_at.deriv_within
(h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within f s x = f' :=
hxs.eq_deriv _ h.differentiable_within_at.has_deriv_within_at h
lemma fderiv_within_deriv_within : (fderiv_within 𝕜 f s x : 𝕜 → F) 1 = deriv_within f s x :=
rfl
lemma deriv_within_fderiv_within :
smul_right (1 : 𝕜 →L[𝕜] 𝕜) (deriv_within f s x) = fderiv_within 𝕜 f s x :=
by simp [deriv_within]
lemma fderiv_deriv : (fderiv 𝕜 f x : 𝕜 → F) 1 = deriv f x :=
rfl
lemma deriv_fderiv :
smul_right (1 : 𝕜 →L[𝕜] 𝕜) (deriv f x) = fderiv 𝕜 f x :=
by simp [deriv]
lemma differentiable_at.deriv_within (h : differentiable_at 𝕜 f x)
(hxs : unique_diff_within_at 𝕜 s x) : deriv_within f s x = deriv f x :=
by { unfold deriv_within deriv, rw h.fderiv_within hxs }
lemma deriv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f t x) :
deriv_within f s x = deriv_within f t x :=
((differentiable_within_at.has_deriv_within_at h).mono st).deriv_within ht
@[simp] lemma deriv_within_univ : deriv_within f univ = deriv f :=
by { ext, unfold deriv_within deriv, rw fderiv_within_univ }
lemma deriv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) :
deriv_within f (s ∩ t) x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_inter ht hs }
lemma deriv_within_of_open (hs : is_open s) (hx : x ∈ s) :
deriv_within f s x = deriv f x :=
by { unfold deriv_within, rw fderiv_within_of_open hs hx, refl }
section congr
/-! ### Congruence properties of derivatives -/
theorem filter.eventually_eq.has_deriv_at_filter_iff
(h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') :
has_deriv_at_filter f₀ f₀' x L ↔ has_deriv_at_filter f₁ f₁' x L :=
h₀.has_fderiv_at_filter_iff hx (by simp [h₁])
lemma has_deriv_at_filter.congr_of_eventually_eq (h : has_deriv_at_filter f f' x L)
(hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_deriv_at_filter f₁ f' x L :=
by rwa hL.has_deriv_at_filter_iff hx rfl
lemma has_deriv_within_at.congr_mono (h : has_deriv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : has_deriv_within_at f₁ f' t x :=
has_fderiv_within_at.congr_mono h ht hx h₁
lemma has_deriv_within_at.congr (h : has_deriv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
h.congr_mono hs hx (subset.refl _)
lemma has_deriv_within_at.congr_of_eventually_eq (h : has_deriv_within_at f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
has_deriv_at_filter.congr_of_eventually_eq h h₁ hx
lemma has_deriv_within_at.congr_of_eventually_eq_of_mem (h : has_deriv_within_at f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : has_deriv_within_at f₁ f' s x :=
h.congr_of_eventually_eq h₁ (h₁.eq_of_nhds_within hx)
lemma has_deriv_at.congr_of_eventually_eq (h : has_deriv_at f f' x)
(h₁ : f₁ =ᶠ[𝓝 x] f) : has_deriv_at f₁ f' x :=
has_deriv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _)
lemma filter.eventually_eq.deriv_within_eq (hs : unique_diff_within_at 𝕜 s x)
(hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw hL.fderiv_within_eq hs hx }
lemma deriv_within_congr (hs : unique_diff_within_at 𝕜 s x)
(hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_congr hs hL hx }
lemma filter.eventually_eq.deriv_eq (hL : f₁ =ᶠ[𝓝 x] f) : deriv f₁ x = deriv f x :=
by { unfold deriv, rwa filter.eventually_eq.fderiv_eq }
protected lemma filter.eventually_eq.deriv (h : f₁ =ᶠ[𝓝 x] f) : deriv f₁ =ᶠ[𝓝 x] deriv f :=
h.eventually_eq_nhds.mono $ λ x h, h.deriv_eq
end congr
section id
/-! ### Derivative of the identity -/
variables (s x L)
theorem has_deriv_at_filter_id : has_deriv_at_filter id 1 x L :=
(has_fderiv_at_filter_id x L).has_deriv_at_filter
theorem has_deriv_within_at_id : has_deriv_within_at id 1 s x :=
has_deriv_at_filter_id _ _
theorem has_deriv_at_id : has_deriv_at id 1 x :=
has_deriv_at_filter_id _ _
theorem has_deriv_at_id' : has_deriv_at (λ (x : 𝕜), x) 1 x :=
has_deriv_at_filter_id _ _
theorem has_strict_deriv_at_id : has_strict_deriv_at id 1 x :=
(has_strict_fderiv_at_id x).has_strict_deriv_at
lemma deriv_id : deriv id x = 1 :=
has_deriv_at.deriv (has_deriv_at_id x)
@[simp] lemma deriv_id' : deriv (@id 𝕜) = λ _, 1 := funext deriv_id
@[simp] lemma deriv_id'' : deriv (λ x : 𝕜, x) = λ _, 1 := deriv_id'
lemma deriv_within_id (hxs : unique_diff_within_at 𝕜 s x) : deriv_within id s x = 1 :=
(has_deriv_within_at_id x s).deriv_within hxs
end id
section const
/-! ### Derivative of constant functions -/
variables (c : F) (s x L)
theorem has_deriv_at_filter_const : has_deriv_at_filter (λ x, c) 0 x L :=
(has_fderiv_at_filter_const c x L).has_deriv_at_filter
theorem has_strict_deriv_at_const : has_strict_deriv_at (λ x, c) 0 x :=
(has_strict_fderiv_at_const c x).has_strict_deriv_at
theorem has_deriv_within_at_const : has_deriv_within_at (λ x, c) 0 s x :=
has_deriv_at_filter_const _ _ _
theorem has_deriv_at_const : has_deriv_at (λ x, c) 0 x :=
has_deriv_at_filter_const _ _ _
lemma deriv_const : deriv (λ x, c) x = 0 :=
has_deriv_at.deriv (has_deriv_at_const x c)
@[simp] lemma deriv_const' : deriv (λ x:𝕜, c) = λ x, 0 :=
funext (λ x, deriv_const x c)
lemma deriv_within_const (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (λ x, c) s x = 0 :=
(has_deriv_within_at_const _ _ _).deriv_within hxs
end const
section continuous_linear_map
/-! ### Derivative of continuous linear maps -/
variables (e : 𝕜 →L[𝕜] F)
protected lemma continuous_linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.has_fderiv_at_filter.has_deriv_at_filter
protected lemma continuous_linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.has_strict_fderiv_at.has_strict_deriv_at
protected lemma continuous_linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
protected lemma continuous_linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] protected lemma continuous_linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
protected lemma continuous_linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end continuous_linear_map
section linear_map
/-! ### Derivative of bundled linear maps -/
variables (e : 𝕜 →ₗ[𝕜] F)
protected lemma linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L :=
e.to_continuous_linear_map₁.has_deriv_at_filter
protected lemma linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x :=
e.to_continuous_linear_map₁.has_strict_deriv_at
protected lemma linear_map.has_deriv_at : has_deriv_at e (e 1) x :=
e.has_deriv_at_filter
protected lemma linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x :=
e.has_deriv_at_filter
@[simp] protected lemma linear_map.deriv : deriv e x = e 1 :=
e.has_deriv_at.deriv
protected lemma linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within e s x = e 1 :=
e.has_deriv_within_at.deriv_within hxs
end linear_map
section add
/-! ### Derivative of the sum of two functions -/
theorem has_deriv_at_filter.add
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_at_filter (λ y, f y + g y) (f' + g') x L :=
by simpa using (hf.add hg).has_deriv_at_filter
theorem has_strict_deriv_at.add
(hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :
has_strict_deriv_at (λ y, f y + g y) (f' + g') x :=
by simpa using (hf.add hg).has_strict_deriv_at
theorem has_deriv_within_at.add
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ y, f y + g y) (f' + g') s x :=
hf.add hg
theorem has_deriv_at.add
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x + g x) (f' + g') x :=
hf.add hg
lemma deriv_within_add (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y + g y) s x = deriv_within f s x + deriv_within g s x :=
(hf.has_deriv_within_at.add hg.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λy, f y + g y) x = deriv f x + deriv g x :=
(hf.has_deriv_at.add hg.has_deriv_at).deriv
theorem has_deriv_at_filter.add_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ y, f y + c) f' x L :=
add_zero f' ▸ hf.add (has_deriv_at_filter_const x L c)
theorem has_deriv_within_at.add_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ y, f y + c) f' s x :=
hf.add_const c
theorem has_deriv_at.add_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x + c) f' x :=
hf.add_const c
lemma deriv_within_add_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, f y + c) s x = deriv_within f s x :=
by simp only [deriv_within, fderiv_within_add_const hxs]
lemma deriv_add_const (c : F) : deriv (λy, f y + c) x = deriv f x :=
by simp only [deriv, fderiv_add_const]
@[simp] lemma deriv_add_const' (c : F) : deriv (λ y, f y + c) = deriv f :=
funext $ λ x, deriv_add_const c
theorem has_deriv_at_filter.const_add (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ y, c + f y) f' x L :=
zero_add f' ▸ (has_deriv_at_filter_const x L c).add hf
theorem has_deriv_within_at.const_add (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c + f y) f' s x :=
hf.const_add c
theorem has_deriv_at.const_add (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c + f x) f' x :=
hf.const_add c
lemma deriv_within_const_add (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, c + f y) s x = deriv_within f s x :=
by simp only [deriv_within, fderiv_within_const_add hxs]
lemma deriv_const_add (c : F) : deriv (λy, c + f y) x = deriv f x :=
by simp only [deriv, fderiv_const_add]
@[simp] lemma deriv_const_add' (c : F) : deriv (λ y, c + f y) = deriv f :=
funext $ λ x, deriv_const_add c
end add
section sum
/-! ### Derivative of a finite sum of functions -/
open_locale big_operators
variables {ι : Type*} {u : finset ι} {A : ι → (𝕜 → F)} {A' : ι → F}
theorem has_deriv_at_filter.sum (h : ∀ i ∈ u, has_deriv_at_filter (A i) (A' i) x L) :
has_deriv_at_filter (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x L :=
by simpa [continuous_linear_map.sum_apply] using (has_fderiv_at_filter.sum h).has_deriv_at_filter
theorem has_strict_deriv_at.sum (h : ∀ i ∈ u, has_strict_deriv_at (A i) (A' i) x) :
has_strict_deriv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
by simpa [continuous_linear_map.sum_apply] using (has_strict_fderiv_at.sum h).has_strict_deriv_at
theorem has_deriv_within_at.sum (h : ∀ i ∈ u, has_deriv_within_at (A i) (A' i) s x) :
has_deriv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x :=
has_deriv_at_filter.sum h
theorem has_deriv_at.sum (h : ∀ i ∈ u, has_deriv_at (A i) (A' i) x) :
has_deriv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=
has_deriv_at_filter.sum h
lemma deriv_within_sum (hxs : unique_diff_within_at 𝕜 s x)
(h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :
deriv_within (λ y, ∑ i in u, A i y) s x = ∑ i in u, deriv_within (A i) s x :=
(has_deriv_within_at.sum (λ i hi, (h i hi).has_deriv_within_at)).deriv_within hxs
@[simp] lemma deriv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :
deriv (λ y, ∑ i in u, A i y) x = ∑ i in u, deriv (A i) x :=
(has_deriv_at.sum (λ i hi, (h i hi).has_deriv_at)).deriv
end sum
section pi
/-! ### Derivatives of functions `f : 𝕜 → Π i, E i` -/
variables {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)]
[Π i, normed_space 𝕜 (E' i)] {φ : 𝕜 → Π i, E' i} {φ' : Π i, E' i}
@[simp] lemma has_strict_deriv_at_pi :
has_strict_deriv_at φ φ' x ↔ ∀ i, has_strict_deriv_at (λ x, φ x i) (φ' i) x :=
has_strict_fderiv_at_pi'
@[simp] lemma has_deriv_at_filter_pi :
has_deriv_at_filter φ φ' x L ↔
∀ i, has_deriv_at_filter (λ x, φ x i) (φ' i) x L :=
has_fderiv_at_filter_pi'
lemma has_deriv_at_pi :
has_deriv_at φ φ' x ↔ ∀ i, has_deriv_at (λ x, φ x i) (φ' i) x:=
has_deriv_at_filter_pi
lemma has_deriv_within_at_pi :
has_deriv_within_at φ φ' s x ↔ ∀ i, has_deriv_within_at (λ x, φ x i) (φ' i) s x:=
has_deriv_at_filter_pi
lemma deriv_within_pi (h : ∀ i, differentiable_within_at 𝕜 (λ x, φ x i) s x)
(hs : unique_diff_within_at 𝕜 s x) :
deriv_within φ s x = λ i, deriv_within (λ x, φ x i) s x :=
(has_deriv_within_at_pi.2 (λ i, (h i).has_deriv_within_at)).deriv_within hs
lemma deriv_pi (h : ∀ i, differentiable_at 𝕜 (λ x, φ x i) x) :
deriv φ x = λ i, deriv (λ x, φ x i) x :=
(has_deriv_at_pi.2 (λ i, (h i).has_deriv_at)).deriv
end pi
section mul_vector
/-! ### Derivative of the multiplication of a scalar function and a vector function -/
variables {c : 𝕜 → 𝕜} {c' : 𝕜}
theorem has_deriv_within_at.smul
(hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c y • f y) (c x • f' + c' • f x) s x :=
by simpa using (has_fderiv_within_at.smul hc hf).has_deriv_within_at
theorem has_deriv_at.smul
(hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c y • f y) (c x • f' + c' • f x) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul hf
end
theorem has_strict_deriv_at.smul
(hc : has_strict_deriv_at c c' x) (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ y, c y • f y) (c x • f' + c' • f x) x :=
by simpa using (hc.smul hf).has_strict_deriv_at
lemma deriv_within_smul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c y • f y) s x = c x • deriv_within f s x + (deriv_within c s x) • f x :=
(hc.has_deriv_within_at.smul hf.has_deriv_within_at).deriv_within hxs
lemma deriv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c y • f y) x = c x • deriv f x + (deriv c x) • f x :=
(hc.has_deriv_at.smul hf.has_deriv_at).deriv
theorem has_deriv_within_at.smul_const
(hc : has_deriv_within_at c c' s x) (f : F) :
has_deriv_within_at (λ y, c y • f) (c' • f) s x :=
begin
have := hc.smul (has_deriv_within_at_const x s f),
rwa [smul_zero, zero_add] at this
end
theorem has_deriv_at.smul_const
(hc : has_deriv_at c c' x) (f : F) :
has_deriv_at (λ y, c y • f) (c' • f) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul_const f
end
lemma deriv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
deriv_within (λ y, c y • f) s x = (deriv_within c s x) • f :=
(hc.has_deriv_within_at.smul_const f).deriv_within hxs
lemma deriv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
deriv (λ y, c y • f) x = (deriv c x) • f :=
(hc.has_deriv_at.smul_const f).deriv
theorem has_deriv_within_at.const_smul
(c : 𝕜) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c • f y) (c • f') s x :=
begin
convert (has_deriv_within_at_const x s c).smul hf,
rw [zero_smul, add_zero]
end
theorem has_deriv_at.const_smul (c : 𝕜) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c • f y) (c • f') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hf.const_smul c
end
lemma deriv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝕜) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c • f y) s x = c • deriv_within f s x :=
(hf.has_deriv_within_at.const_smul c).deriv_within hxs
lemma deriv_const_smul (c : 𝕜) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c • f y) x = c • deriv f x :=
(hf.has_deriv_at.const_smul c).deriv
end mul_vector
section neg
/-! ### Derivative of the negative of a function -/
theorem has_deriv_at_filter.neg (h : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, -f x) (-f') x L :=
by simpa using h.neg.has_deriv_at_filter
theorem has_deriv_within_at.neg (h : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, -f x) (-f') s x :=
h.neg
theorem has_deriv_at.neg (h : has_deriv_at f f' x) : has_deriv_at (λ x, -f x) (-f') x :=
h.neg
theorem has_strict_deriv_at.neg (h : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, -f x) (-f') x :=
by simpa using h.neg.has_strict_deriv_at
lemma deriv_within.neg (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λy, -f y) s x = - deriv_within f s x :=
by simp only [deriv_within, fderiv_within_neg hxs, continuous_linear_map.neg_apply]
lemma deriv.neg : deriv (λy, -f y) x = - deriv f x :=
by simp only [deriv, fderiv_neg, continuous_linear_map.neg_apply]
@[simp] lemma deriv.neg' : deriv (λy, -f y) = (λ x, - deriv f x) :=
funext $ λ x, deriv.neg
end neg
section neg2
/-! ### Derivative of the negation function (i.e `has_neg.neg`) -/
variables (s x L)
theorem has_deriv_at_filter_neg : has_deriv_at_filter has_neg.neg (-1) x L :=
has_deriv_at_filter.neg $ has_deriv_at_filter_id _ _
theorem has_deriv_within_at_neg : has_deriv_within_at has_neg.neg (-1) s x :=
has_deriv_at_filter_neg _ _
theorem has_deriv_at_neg : has_deriv_at has_neg.neg (-1) x :=
has_deriv_at_filter_neg _ _
theorem has_deriv_at_neg' : has_deriv_at (λ x, -x) (-1) x :=
has_deriv_at_filter_neg _ _
theorem has_strict_deriv_at_neg : has_strict_deriv_at has_neg.neg (-1) x :=
has_strict_deriv_at.neg $ has_strict_deriv_at_id _
lemma deriv_neg : deriv has_neg.neg x = -1 :=
has_deriv_at.deriv (has_deriv_at_neg x)
@[simp] lemma deriv_neg' : deriv (has_neg.neg : 𝕜 → 𝕜) = λ _, -1 :=
funext deriv_neg
@[simp] lemma deriv_neg'' : deriv (λ x : 𝕜, -x) x = -1 :=
deriv_neg x
lemma deriv_within_neg (hxs : unique_diff_within_at 𝕜 s x) : deriv_within has_neg.neg s x = -1 :=
(has_deriv_within_at_neg x s).deriv_within hxs
lemma differentiable_neg : differentiable 𝕜 (has_neg.neg : 𝕜 → 𝕜) :=
differentiable.neg differentiable_id
lemma differentiable_on_neg : differentiable_on 𝕜 (has_neg.neg : 𝕜 → 𝕜) s :=
differentiable_on.neg differentiable_on_id
end neg2
section sub
/-! ### Derivative of the difference of two functions -/
theorem has_deriv_at_filter.sub
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_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_deriv_within_at.sub
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ x, f x - g x) (f' - g') s x :=
hf.sub hg
theorem has_deriv_at.sub
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x - g x) (f' - g') x :=
hf.sub hg
theorem has_strict_deriv_at.sub
(hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) :
has_strict_deriv_at (λ x, f x - g x) (f' - g') x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma deriv_within_sub (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y - g y) s x = deriv_within f s x - deriv_within g s x :=
(hf.has_deriv_within_at.sub hg.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λ y, f y - g y) x = deriv f x - deriv g x :=
(hf.has_deriv_at.sub hg.has_deriv_at).deriv
theorem has_deriv_at_filter.is_O_sub (h : has_deriv_at_filter f f' x L) :
is_O (λ x', f x' - f x) (λ x', x' - x) L :=
has_fderiv_at_filter.is_O_sub h
theorem has_deriv_at_filter.sub_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ x, f x - c) f' x L :=
by simpa only [sub_eq_add_neg] using hf.add_const (-c)
theorem has_deriv_within_at.sub_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ x, f x - c) f' s x :=
hf.sub_const c
theorem has_deriv_at.sub_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x - c) f' x :=
hf.sub_const c
lemma deriv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, f y - c) s x = deriv_within f s x :=
by simp only [deriv_within, fderiv_within_sub_const hxs]
lemma deriv_sub_const (c : F) : deriv (λ y, f y - c) x = deriv f x :=
by simp only [deriv, fderiv_sub_const]
theorem has_deriv_at_filter.const_sub (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, c - f x) (-f') x L :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_deriv_within_at.const_sub (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, c - f x) (-f') s x :=
hf.const_sub c
theorem has_strict_deriv_at.const_sub (c : F) (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (λ x, c - f x) (-f') x :=
by simpa only [sub_eq_add_neg] using hf.neg.const_add c
theorem has_deriv_at.const_sub (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c - f x) (-f') x :=
hf.const_sub c
lemma deriv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x) (c : F) :
deriv_within (λy, c - f y) s x = -deriv_within f s x :=
by simp [deriv_within, fderiv_within_const_sub hxs]
lemma deriv_const_sub (c : F) : deriv (λ y, c - f y) x = -deriv f x :=
by simp only [← deriv_within_univ, deriv_within_const_sub unique_diff_within_at_univ]
end sub
section continuous
/-! ### Continuity of a function admitting a derivative -/
theorem has_deriv_at_filter.tendsto_nhds
(hL : L ≤ 𝓝 x) (h : has_deriv_at_filter f f' x L) :
tendsto f L (𝓝 (f x)) :=
h.tendsto_nhds hL
theorem has_deriv_within_at.continuous_within_at
(h : has_deriv_within_at f f' s x) : continuous_within_at f s x :=
has_deriv_at_filter.tendsto_nhds inf_le_left h
theorem has_deriv_at.continuous_at (h : has_deriv_at f f' x) : continuous_at f x :=
has_deriv_at_filter.tendsto_nhds (le_refl _) h
protected theorem has_deriv_at.continuous_on {f f' : 𝕜 → F}
(hderiv : ∀ x ∈ s, has_deriv_at f (f' x) x) : continuous_on f s :=
λ x hx, (hderiv x hx).continuous_at.continuous_within_at
end continuous
section cartesian_product
/-! ### Derivative of the cartesian product of two functions -/
variables {G : Type w} [normed_group G] [normed_space 𝕜 G]
variables {f₂ : 𝕜 → G} {f₂' : G}
lemma has_deriv_at_filter.prod
(hf₁ : has_deriv_at_filter f₁ f₁' x L) (hf₂ : has_deriv_at_filter f₂ f₂' x L) :
has_deriv_at_filter (λ x, (f₁ x, f₂ x)) (f₁', f₂') x L :=
hf₁.prod hf₂
lemma has_deriv_within_at.prod
(hf₁ : has_deriv_within_at f₁ f₁' s x) (hf₂ : has_deriv_within_at f₂ f₂' s x) :
has_deriv_within_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') s x :=
hf₁.prod hf₂
lemma has_deriv_at.prod (hf₁ : has_deriv_at f₁ f₁' x) (hf₂ : has_deriv_at f₂ f₂' x) :
has_deriv_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') x :=
hf₁.prod hf₂
lemma has_strict_deriv_at.prod (hf₁ : has_strict_deriv_at f₁ f₁' x)
(hf₂ : has_strict_deriv_at f₂ f₂' x) :
has_strict_deriv_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') x :=
hf₁.prod hf₂
end cartesian_product
section composition
/-!
### Derivative of the composition of a vector function and a scalar function
We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`
in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also
because the `comp` version with the shorter name will show up much more often in applications).
The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to
usual multiplication in `comp` lemmas.
-/
variables {h h₁ h₂ : 𝕜 → 𝕜} {h' h₁' h₂' : 𝕜}
/- 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_deriv_at_filter.scomp
(hg : has_deriv_at_filter g g' (h x) (L.map h))
(hh : has_deriv_at_filter h h' x L) :
has_deriv_at_filter (g ∘ h) (h' • g') x L :=
by simpa using (hg.comp x hh).has_deriv_at_filter
theorem has_deriv_within_at.scomp {t : set 𝕜}
(hg : has_deriv_within_at g g' t (h x))
(hh : has_deriv_within_at h h' s x) (hst : s ⊆ h ⁻¹' t) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
has_deriv_at_filter.scomp _ (has_deriv_at_filter.mono hg $
hh.continuous_within_at.tendsto_nhds_within hst) hh
/-- The chain rule. -/
theorem has_deriv_at.scomp
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_at h h' x) :
has_deriv_at (g ∘ h) (h' • g') x :=
(hg.mono hh.continuous_at).scomp x hh
theorem has_strict_deriv_at.scomp
(hg : has_strict_deriv_at g g' (h x)) (hh : has_strict_deriv_at h h' x) :
has_strict_deriv_at (g ∘ h) (h' • g') x :=
by simpa using (hg.comp x hh).has_strict_deriv_at
theorem has_deriv_at.scomp_has_deriv_within_at
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_within_at h h' s x) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
begin
rw ← has_deriv_within_at_univ at hg,
exact has_deriv_within_at.scomp x hg hh subset_preimage_univ
end
lemma deriv_within.scomp
(hg : differentiable_within_at 𝕜 g t (h x)) (hh : differentiable_within_at 𝕜 h s x)
(hs : s ⊆ h ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (g ∘ h) s x = deriv_within h s x • deriv_within g t (h x) :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact has_deriv_within_at.scomp x (hg.has_deriv_within_at) (hh.has_deriv_within_at) hs
end
lemma deriv.scomp
(hg : differentiable_at 𝕜 g (h x)) (hh : differentiable_at 𝕜 h x) :
deriv (g ∘ h) x = deriv h x • deriv g (h x) :=
begin
apply has_deriv_at.deriv,
exact has_deriv_at.scomp x hg.has_deriv_at hh.has_deriv_at
end
/-! ### Derivative of the composition of a scalar and vector functions -/
theorem has_deriv_at_filter.comp_has_fderiv_at_filter {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
{L : filter E} (hh₁ : has_deriv_at_filter h₁ h₁' (f x) (L.map f))
(hf : has_fderiv_at_filter f f' x L) :
has_fderiv_at_filter (h₁ ∘ f) (h₁' • f') x L :=
by { convert has_fderiv_at_filter.comp x hh₁ hf, ext x, simp [mul_comm] }
theorem has_strict_deriv_at.comp_has_strict_fderiv_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
(hh₁ : has_strict_deriv_at h₁ h₁' (f x)) (hf : has_strict_fderiv_at f f' x) :
has_strict_fderiv_at (h₁ ∘ f) (h₁' • f') x :=
by { rw has_strict_deriv_at at hh₁, convert hh₁.comp x hf, ext x, simp [mul_comm] }
theorem has_deriv_at.comp_has_fderiv_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} (x)
(hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_at f f' x) :
has_fderiv_at (h₁ ∘ f) (h₁' • f') x :=
(hh₁.mono hf.continuous_at).comp_has_fderiv_at_filter x hf
theorem has_deriv_at.comp_has_fderiv_within_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} {s} (x)
(hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x :=
(hh₁.mono hf.continuous_within_at).comp_has_fderiv_at_filter x hf
theorem has_deriv_within_at.comp_has_fderiv_within_at {f : E → 𝕜} {f' : E →L[𝕜] 𝕜} {s t} (x)
(hh₁ : has_deriv_within_at h₁ h₁' t (f x)) (hf : has_fderiv_within_at f f' s x)
(hst : maps_to f s t) :
has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x :=
(has_deriv_at_filter.mono hh₁ $
hf.continuous_within_at.tendsto_nhds_within hst).comp_has_fderiv_at_filter x hf
/-! ### Derivative of the composition of two scalar functions -/
theorem has_deriv_at_filter.comp
(hh₁ : has_deriv_at_filter h₁ h₁' (h₂ x) (L.map h₂))
(hh₂ : has_deriv_at_filter h₂ h₂' x L) :
has_deriv_at_filter (h₁ ∘ h₂) (h₁' * h₂') x L :=
by { rw mul_comm, exact hh₁.scomp x hh₂ }
theorem has_deriv_within_at.comp {t : set 𝕜}
(hh₁ : has_deriv_within_at h₁ h₁' t (h₂ x))
(hh₂ : has_deriv_within_at h₂ h₂' s x) (hst : s ⊆ h₂ ⁻¹' t) :
has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=
by { rw mul_comm, exact hh₁.scomp x hh₂ hst, }
/-- The chain rule. -/
theorem has_deriv_at.comp
(hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_at h₂ h₂' x) :
has_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=
(hh₁.mono hh₂.continuous_at).comp x hh₂
theorem has_strict_deriv_at.comp
(hh₁ : has_strict_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_strict_deriv_at h₂ h₂' x) :
has_strict_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=
by { rw mul_comm, exact hh₁.scomp x hh₂ }
theorem has_deriv_at.comp_has_deriv_within_at
(hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_within_at h₂ h₂' s x) :
has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=
begin
rw ← has_deriv_within_at_univ at hh₁,
exact has_deriv_within_at.comp x hh₁ hh₂ subset_preimage_univ
end
lemma deriv_within.comp
(hh₁ : differentiable_within_at 𝕜 h₁ t (h₂ x)) (hh₂ : differentiable_within_at 𝕜 h₂ s x)
(hs : s ⊆ h₂ ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (h₁ ∘ h₂) s x = deriv_within h₁ t (h₂ x) * deriv_within h₂ s x :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact has_deriv_within_at.comp x (hh₁.has_deriv_within_at) (hh₂.has_deriv_within_at) hs
end
lemma deriv.comp
(hh₁ : differentiable_at 𝕜 h₁ (h₂ x)) (hh₂ : differentiable_at 𝕜 h₂ x) :
deriv (h₁ ∘ h₂) x = deriv h₁ (h₂ x) * deriv h₂ x :=
begin
apply has_deriv_at.deriv,
exact has_deriv_at.comp x hh₁.has_deriv_at hh₂.has_deriv_at
end
protected lemma has_deriv_at_filter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) :
has_deriv_at_filter (f^[n]) (f'^n) x L :=
begin
have := hf.iterate hL hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_deriv_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_at f f' x) (hx : f x = x) (n : ℕ) :
has_deriv_at (f^[n]) (f'^n) x :=
begin
have := has_fderiv_at.iterate hf hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_deriv_within_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_deriv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) :
has_deriv_within_at (f^[n]) (f'^n) s x :=
begin
have := has_fderiv_within_at.iterate hf hx hs n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
protected lemma has_strict_deriv_at.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : has_strict_deriv_at f f' x) (hx : f x = x) (n : ℕ) :
has_strict_deriv_at (f^[n]) (f'^n) x :=
begin
have := hf.iterate hx n,
rwa [continuous_linear_map.smul_right_one_pow] at this
end
end composition
section composition_vector
/-! ### Derivative of the composition of a function between vector spaces and a function on `𝕜` -/
open continuous_linear_map
variables {l : F → E} {l' : F →L[𝕜] E}
variable (x)
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set
equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_within_at.comp_has_deriv_within_at {t : set F}
(hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x)
(hst : maps_to f s t) :
has_deriv_within_at (l ∘ f) (l' f') s x :=
by simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (∘)]
using (hl.comp x hf.has_fderiv_within_at hst).has_deriv_within_at
theorem has_fderiv_at.comp_has_deriv_within_at
(hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (l ∘ f) (l' f') s x :=
hl.has_fderiv_within_at.comp_has_deriv_within_at x hf (maps_to_univ _ _)
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the
Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_at.comp_has_deriv_at (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) :
has_deriv_at (l ∘ f) (l' f') x :=
has_deriv_within_at_univ.mp $ hl.comp_has_deriv_within_at x hf.has_deriv_within_at
theorem has_strict_fderiv_at.comp_has_strict_deriv_at
(hl : has_strict_fderiv_at l l' (f x)) (hf : has_strict_deriv_at f f' x) :
has_strict_deriv_at (l ∘ f) (l' f') x :=
by simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (∘)]
using (hl.comp x hf.has_strict_fderiv_at).has_strict_deriv_at
lemma fderiv_within.comp_deriv_within {t : set F}
(hl : differentiable_within_at 𝕜 l t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(hs : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (l ∘ f) s x = (fderiv_within 𝕜 l t (f x) : F → E) (deriv_within f s x) :=
(hl.has_fderiv_within_at.comp_has_deriv_within_at x hf.has_deriv_within_at hs).deriv_within hxs
lemma fderiv.comp_deriv
(hl : differentiable_at 𝕜 l (f x)) (hf : differentiable_at 𝕜 f x) :
deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) :=
(hl.has_fderiv_at.comp_has_deriv_at x hf.has_deriv_at).deriv
end composition_vector
section mul
/-! ### Derivative of the multiplication of two functions -/
variables {𝕜' 𝔸 : Type*} [normed_field 𝕜'] [normed_ring 𝔸] [normed_algebra 𝕜 𝕜']
[normed_algebra 𝕜 𝔸] {c d : 𝕜 → 𝔸} {c' d' : 𝔸} {u v : 𝕜 → 𝕜'}
theorem has_deriv_within_at.mul
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c y * d y) (c' * d x + c x * d') s x :=
begin
have := (has_fderiv_within_at.mul' hc hd).has_deriv_within_at,
rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply,
one_smul, one_smul, add_comm] at this,
end
theorem has_deriv_at.mul (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c y * d y) (c' * d x + c x * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul hd
end
theorem has_strict_deriv_at.mul
(hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) :
has_strict_deriv_at (λ y, c y * d y) (c' * d x + c x * d') x :=
begin
have := (has_strict_fderiv_at.mul' hc hd).has_strict_deriv_at,
rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply,
one_smul, one_smul, add_comm] at this,
end
lemma deriv_within_mul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x :=
(hc.has_deriv_within_at.mul hd.has_deriv_within_at).deriv_within hxs
@[simp] lemma deriv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c y * d y) x = deriv c x * d x + c x * deriv d x :=
(hc.has_deriv_at.mul hd.has_deriv_at).deriv
theorem has_deriv_within_at.mul_const (hc : has_deriv_within_at c c' s x) (d : 𝔸) :
has_deriv_within_at (λ y, c y * d) (c' * d) s x :=
begin
convert hc.mul (has_deriv_within_at_const x s d),
rw [mul_zero, add_zero]
end
theorem has_deriv_at.mul_const (hc : has_deriv_at c c' x) (d : 𝔸) :
has_deriv_at (λ y, c y * d) (c' * d) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul_const d
end
theorem has_strict_deriv_at.mul_const (hc : has_strict_deriv_at c c' x) (d : 𝔸) :
has_strict_deriv_at (λ y, c y * d) (c' * d) x :=
begin
convert hc.mul (has_strict_deriv_at_const x d),
rw [mul_zero, add_zero]
end
lemma deriv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (d : 𝔸) :
deriv_within (λ y, c y * d) s x = deriv_within c s x * d :=
(hc.has_deriv_within_at.mul_const d).deriv_within hxs
lemma deriv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝔸) :
deriv (λ y, c y * d) x = deriv c x * d :=
(hc.has_deriv_at.mul_const d).deriv
lemma deriv_mul_const_field (v : 𝕜') :
deriv (λ y, u y * v) x = deriv u x * v :=
begin
by_cases hu : differentiable_at 𝕜 u x,
{ exact deriv_mul_const hu v },
{ rw [deriv_zero_of_not_differentiable_at hu, zero_mul],
rcases eq_or_ne v 0 with rfl|hd,
{ simp only [mul_zero, deriv_const] },
{ refine deriv_zero_of_not_differentiable_at (mt (λ H, _) hu),
simpa only [mul_inv_cancel_right₀ hd] using H.mul_const v⁻¹ } }
end
@[simp] lemma deriv_mul_const_field' (v : 𝕜') : deriv (λ x, u x * v) = λ x, deriv u x * v :=
funext $ λ _, deriv_mul_const_field v
theorem has_deriv_within_at.const_mul (c : 𝔸) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c * d y) (c * d') s x :=
begin
convert (has_deriv_within_at_const x s c).mul hd,
rw [zero_mul, zero_add]
end
theorem has_deriv_at.const_mul (c : 𝔸) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c * d y) (c * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hd.const_mul c
end
theorem has_strict_deriv_at.const_mul (c : 𝔸) (hd : has_strict_deriv_at d d' x) :
has_strict_deriv_at (λ y, c * d y) (c * d') x :=
begin
convert (has_strict_deriv_at_const _ _).mul hd,
rw [zero_mul, zero_add]
end
lemma deriv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝔸) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c * d y) s x = c * deriv_within d s x :=
(hd.has_deriv_within_at.const_mul c).deriv_within hxs
lemma deriv_const_mul (c : 𝔸) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c * d y) x = c * deriv d x :=
(hd.has_deriv_at.const_mul c).deriv
lemma deriv_const_mul_field (u : 𝕜') : deriv (λ y, u * v y) x = u * deriv v x :=
by simp only [mul_comm u, deriv_mul_const_field]
@[simp] lemma deriv_const_mul_field' (u : 𝕜') : deriv (λ x, u * v x) = λ x, u * deriv v x :=
funext (λ x, deriv_const_mul_field u)
end mul
section inverse
/-! ### Derivative of `x ↦ x⁻¹` -/
theorem has_strict_deriv_at_inv (hx : x ≠ 0) : has_strict_deriv_at has_inv.inv (-(x^2)⁻¹) x :=
begin
suffices : is_o (λ p : 𝕜 × 𝕜, (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹))
(λ (p : 𝕜 × 𝕜), (p.1 - p.2) * 1) (𝓝 (x, x)),
{ refine this.congr' _ (eventually_of_forall $ λ _, mul_one _),
refine eventually.mono (is_open.mem_nhds (is_open_ne.prod is_open_ne) ⟨hx, hx⟩) _,
rintro ⟨y, z⟩ ⟨hy, hz⟩,
simp only [mem_set_of_eq] at hy hz, -- hy : y ≠ 0, hz : z ≠ 0
field_simp [hx, hy, hz], ring, },
refine (is_O_refl (λ p : 𝕜 × 𝕜, p.1 - p.2) _).mul_is_o ((is_o_one_iff _).2 _),
rw [← sub_self (x * x)⁻¹],
exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv₀ $ mul_ne_zero hx hx)
end
theorem has_deriv_at_inv (x_ne_zero : x ≠ 0) :
has_deriv_at (λy, y⁻¹) (-(x^2)⁻¹) x :=
(has_strict_deriv_at_inv x_ne_zero).has_deriv_at
theorem has_deriv_within_at_inv (x_ne_zero : x ≠ 0) (s : set 𝕜) :
has_deriv_within_at (λx, x⁻¹) (-(x^2)⁻¹) s x :=
(has_deriv_at_inv x_ne_zero).has_deriv_within_at
lemma differentiable_at_inv :
differentiable_at 𝕜 (λx, x⁻¹) x ↔ x ≠ 0:=
⟨λ H, normed_field.continuous_at_inv.1 H.continuous_at,
λ H, (has_deriv_at_inv H).differentiable_at⟩
lemma differentiable_within_at_inv (x_ne_zero : x ≠ 0) :
differentiable_within_at 𝕜 (λx, x⁻¹) s x :=
(differentiable_at_inv.2 x_ne_zero).differentiable_within_at
lemma differentiable_on_inv : differentiable_on 𝕜 (λx:𝕜, x⁻¹) {x | x ≠ 0} :=
λx hx, differentiable_within_at_inv hx
lemma deriv_inv : deriv (λx, x⁻¹) x = -(x^2)⁻¹ :=
begin
rcases eq_or_ne x 0 with rfl|hne,
{ simp [deriv_zero_of_not_differentiable_at (mt differentiable_at_inv.1 (not_not.2 rfl))] },
{ exact (has_deriv_at_inv hne).deriv }
end
@[simp] lemma deriv_inv' : deriv (λ x : 𝕜, x⁻¹) = λ x, -(x ^ 2)⁻¹ := funext (λ x, deriv_inv)
lemma deriv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x⁻¹) s x = -(x^2)⁻¹ :=
begin
rw differentiable_at.deriv_within (differentiable_at_inv.2 x_ne_zero) hxs,
exact deriv_inv
end
lemma has_fderiv_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_at (λx, x⁻¹) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x :=
has_deriv_at_inv x_ne_zero
lemma has_fderiv_within_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_within_at (λx, x⁻¹) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) s x :=
(has_fderiv_at_inv x_ne_zero).has_fderiv_within_at
lemma fderiv_inv :
fderiv 𝕜 (λx, x⁻¹) x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) :=
by rw [← deriv_fderiv, deriv_inv]
lemma fderiv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, x⁻¹) s x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (-(x^2)⁻¹) :=
begin
rw differentiable_at.fderiv_within (differentiable_at_inv.2 x_ne_zero) hxs,
exact fderiv_inv
end
variables {c : 𝕜 → 𝕜} {c' : 𝕜}
lemma has_deriv_within_at.inv
(hc : has_deriv_within_at c c' s x) (hx : c x ≠ 0) :
has_deriv_within_at (λ y, (c y)⁻¹) (- c' / (c x)^2) s x :=
begin
convert (has_deriv_at_inv hx).comp_has_deriv_within_at x hc,
field_simp
end
lemma has_deriv_at.inv (hc : has_deriv_at c c' x) (hx : c x ≠ 0) :
has_deriv_at (λ y, (c y)⁻¹) (- c' / (c x)^2) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hc.inv hx
end
lemma differentiable_within_at.inv (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0) :
differentiable_within_at 𝕜 (λx, (c x)⁻¹) s x :=
(hc.has_deriv_within_at.inv hx).differentiable_within_at
@[simp] lemma differentiable_at.inv (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) :
differentiable_at 𝕜 (λx, (c x)⁻¹) x :=
(hc.has_deriv_at.inv hx).differentiable_at
lemma differentiable_on.inv (hc : differentiable_on 𝕜 c s) (hx : ∀ x ∈ s, c x ≠ 0) :
differentiable_on 𝕜 (λx, (c x)⁻¹) s :=
λx h, (hc x h).inv (hx x h)
@[simp] lemma differentiable.inv (hc : differentiable 𝕜 c) (hx : ∀ x, c x ≠ 0) :
differentiable 𝕜 (λx, (c x)⁻¹) :=
λx, (hc x).inv (hx x)
lemma deriv_within_inv' (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, (c x)⁻¹) s x = - (deriv_within c s x) / (c x)^2 :=
(hc.has_deriv_within_at.inv hx).deriv_within hxs
@[simp] lemma deriv_inv'' (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) :
deriv (λx, (c x)⁻¹) x = - (deriv c x) / (c x)^2 :=
(hc.has_deriv_at.inv hx).deriv
end inverse
section division
/-! ### Derivative of `x ↦ c x / d x` -/
variables {c d : 𝕜 → 𝕜} {c' d' : 𝕜}
lemma has_deriv_within_at.div
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x ≠ 0) :
has_deriv_within_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) s x :=
begin
convert hc.mul ((has_deriv_at_inv hx).comp_has_deriv_within_at x hd),
{ simp only [div_eq_mul_inv] },
{ field_simp, ring }
end
lemma has_strict_deriv_at.div (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x)
(hx : d x ≠ 0) :
has_strict_deriv_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=
begin
convert hc.mul ((has_strict_deriv_at_inv hx).comp x hd),
{ simp only [div_eq_mul_inv] },
{ field_simp, ring }
end
lemma has_deriv_at.div (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x ≠ 0) :
has_deriv_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hc.div hd hx
end
lemma differentiable_within_at.div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0) :
differentiable_within_at 𝕜 (λx, c x / d x) s x :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).differentiable_within_at
@[simp] lemma differentiable_at.div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
differentiable_at 𝕜 (λx, c x / d x) x :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).differentiable_at
lemma differentiable_on.div
(hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) (hx : ∀ x ∈ s, d x ≠ 0) :
differentiable_on 𝕜 (λx, c x / d x) s :=
λx h, (hc x h).div (hd x h) (hx x h)
@[simp] lemma differentiable.div
(hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) (hx : ∀ x, d x ≠ 0) :
differentiable 𝕜 (λx, c x / d x) :=
λx, (hc x).div (hd x) (hx x)
lemma deriv_within_div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, c x / d x) s x
= ((deriv_within c s x) * d x - c x * (deriv_within d s x)) / (d x)^2 :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).deriv_within hxs
@[simp] lemma deriv_div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
deriv (λx, c x / d x) x = ((deriv c x) * d x - c x * (deriv d x)) / (d x)^2 :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).deriv
lemma differentiable_within_at.div_const (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜} :
differentiable_within_at 𝕜 (λx, c x / d) s x :=
by simp [div_eq_inv_mul, differentiable_within_at.const_mul, hc]
@[simp] lemma differentiable_at.div_const (hc : differentiable_at 𝕜 c x) {d : 𝕜} :
differentiable_at 𝕜 (λ x, c x / d) x :=
by simpa only [div_eq_mul_inv] using (hc.has_deriv_at.mul_const d⁻¹).differentiable_at
lemma differentiable_on.div_const (hc : differentiable_on 𝕜 c s) {d : 𝕜} :
differentiable_on 𝕜 (λx, c x / d) s :=
by simp [div_eq_inv_mul, differentiable_on.const_mul, hc]
@[simp] lemma differentiable.div_const (hc : differentiable 𝕜 c) {d : 𝕜} :
differentiable 𝕜 (λx, c x / d) :=
by simp [div_eq_inv_mul, differentiable.const_mul, hc]
lemma deriv_within_div_const (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜}
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, c x / d) s x = (deriv_within c s x) / d :=
by simp [div_eq_inv_mul, deriv_within_const_mul, hc, hxs]
@[simp] lemma deriv_div_const (d : 𝕜) :
deriv (λx, c x / d) x = (deriv c x) / d :=
by simp only [div_eq_mul_inv, deriv_mul_const_field]
end division
section clm_comp_apply
/-! ### Derivative of the pointwise composition/application of continuous linear maps -/
open continuous_linear_map
variables {G : Type*} [normed_group G] [normed_space 𝕜 G] {c : 𝕜 → F →L[𝕜] G} {c' : F →L[𝕜] G}
{d : 𝕜 → E →L[𝕜] F} {d' : E →L[𝕜] F} {u : 𝕜 → F} {u' : F}
lemma has_strict_deriv_at.clm_comp (hc : has_strict_deriv_at c c' x)
(hd : has_strict_deriv_at d d' x) :
has_strict_deriv_at (λ y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x :=
begin
have := (hc.has_strict_fderiv_at.clm_comp hd.has_strict_fderiv_at).has_strict_deriv_at,
rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_within_at.clm_comp (hc : has_deriv_within_at c c' s x)
(hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') s x :=
begin
have := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).has_deriv_within_at,
rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_at.clm_comp (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, (c y).comp (d y))
(c'.comp (d x) + (c x).comp d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.clm_comp hd
end
lemma deriv_within_clm_comp (hc : differentiable_within_at 𝕜 c s x)
(hd : differentiable_within_at 𝕜 d s x) (hxs : unique_diff_within_at 𝕜 s x):
deriv_within (λ y, (c y).comp (d y)) s x =
((deriv_within c s x).comp (d x) + (c x).comp (deriv_within d s x)) :=
(hc.has_deriv_within_at.clm_comp hd.has_deriv_within_at).deriv_within hxs
lemma deriv_clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, (c y).comp (d y)) x =
((deriv c x).comp (d x) + (c x).comp (deriv d x)) :=
(hc.has_deriv_at.clm_comp hd.has_deriv_at).deriv
lemma has_strict_deriv_at.clm_apply (hc : has_strict_deriv_at c c' x)
(hu : has_strict_deriv_at u u' x) :
has_strict_deriv_at (λ y, (c y) (u y)) (c' (u x) + c x u') x :=
begin
have := (hc.has_strict_fderiv_at.clm_apply hu.has_strict_fderiv_at).has_strict_deriv_at,
rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_within_at.clm_apply (hc : has_deriv_within_at c c' s x)
(hu : has_deriv_within_at u u' s x) :
has_deriv_within_at (λ y, (c y) (u y)) (c' (u x) + c x u') s x :=
begin
have := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).has_deriv_within_at,
rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma has_deriv_at.clm_apply (hc : has_deriv_at c c' x) (hu : has_deriv_at u u' x) :
has_deriv_at (λ y, (c y) (u y)) (c' (u x) + c x u') x :=
begin
have := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).has_deriv_at,
rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul,
one_smul, add_comm] at this,
end
lemma deriv_within_clm_apply (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) :
deriv_within (λ y, (c y) (u y)) s x = (deriv_within c s x (u x) + c x (deriv_within u s x)) :=
(hc.has_deriv_within_at.clm_apply hu.has_deriv_within_at).deriv_within hxs
lemma deriv_clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) :
deriv (λ y, (c y) (u y)) x = (deriv c x (u x) + c x (deriv u x)) :=
(hc.has_deriv_at.clm_apply hu.has_deriv_at).deriv
end clm_comp_apply
theorem has_strict_deriv_at.has_strict_fderiv_at_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜}
(hf : has_strict_deriv_at f f' x) (hf' : f' ≠ 0) :
has_strict_fderiv_at f
(continuous_linear_equiv.units_equiv_aut 𝕜 (units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x :=
hf
theorem has_deriv_at.has_fderiv_at_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜}
(hf : has_deriv_at f f' x) (hf' : f' ≠ 0) :
has_fderiv_at f
(continuous_linear_equiv.units_equiv_aut 𝕜 (units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x :=
hf
/-- 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_deriv_at.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜}
(hg : continuous_at g a) (hf : has_strict_deriv_at f f' (g a)) (hf' : f' ≠ 0)
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_strict_deriv_at g f'⁻¹ a :=
(hf.has_strict_fderiv_at_equiv hf').of_local_left_inverse hg hfg
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a
nonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` 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. -/
lemma local_homeomorph.has_strict_deriv_at_symm (f : local_homeomorph 𝕜 𝕜) {a f' : 𝕜}
(ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : has_strict_deriv_at f f' (f.symm a)) :
has_strict_deriv_at f.symm f'⁻¹ a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)
/-- 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_deriv_at.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜}
(hg : continuous_at g a) (hf : has_deriv_at f f' (g a)) (hf' : f' ≠ 0)
(hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :
has_deriv_at g f'⁻¹ a :=
(hf.has_fderiv_at_equiv hf').of_local_left_inverse hg hfg
/-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an
nonzero 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_deriv_at_symm (f : local_homeomorph 𝕜 𝕜) {a f' : 𝕜}
(ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : has_deriv_at f f' (f.symm a)) :
has_deriv_at f.symm f'⁻¹ a :=
htff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha)
lemma has_deriv_at.eventually_ne (h : has_deriv_at f f' x) (hf' : f' ≠ 0) :
∀ᶠ z in 𝓝[{x}ᶜ] x, f z ≠ f x :=
(has_deriv_at_iff_has_fderiv_at.1 h).eventually_ne
⟨∥f'∥⁻¹, λ z, by field_simp [norm_smul, mt norm_eq_zero.1 hf']⟩
theorem not_differentiable_within_at_of_local_left_inverse_has_deriv_within_at_zero
{f g : 𝕜 → 𝕜} {a : 𝕜} {s t : set 𝕜} (ha : a ∈ s) (hsu : unique_diff_within_at 𝕜 s a)
(hf : has_deriv_within_at f 0 t (g a)) (hst : maps_to g s t) (hfg : f ∘ g =ᶠ[𝓝[s] a] id) :
¬differentiable_within_at 𝕜 g s a :=
begin
intro hg,
have := (hf.comp a hg.has_deriv_within_at hst).congr_of_eventually_eq_of_mem hfg.symm ha,
simpa using hsu.eq_deriv _ this (has_deriv_within_at_id _ _)
end
theorem not_differentiable_at_of_local_left_inverse_has_deriv_at_zero
{f g : 𝕜 → 𝕜} {a : 𝕜} (hf : has_deriv_at f 0 (g a)) (hfg : f ∘ g =ᶠ[𝓝 a] id) :
¬differentiable_at 𝕜 g a :=
begin
intro hg,
have := (hf.comp a hg.has_deriv_at).congr_of_eventually_eq hfg.symm,
simpa using this.unique (has_deriv_at_id a)
end
end
namespace polynomial
/-! ### Derivative of a polynomial -/
variables {x : 𝕜} {s : set 𝕜}
variable (p : polynomial 𝕜)
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected lemma has_strict_deriv_at (x : 𝕜) :
has_strict_deriv_at (λx, p.eval x) (p.derivative.eval x) x :=
begin
apply p.induction_on,
{ simp [has_strict_deriv_at_const] },
{ assume p q hp hq,
convert hp.add hq;
simp },
{ assume n a h,
convert h.mul (has_strict_deriv_at_id x),
{ ext y, simp [pow_add, mul_assoc] },
{ simp [pow_add], ring } }
end
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected lemma has_deriv_at (x : 𝕜) : has_deriv_at (λx, p.eval x) (p.derivative.eval x) x :=
(p.has_strict_deriv_at x).has_deriv_at
protected theorem has_deriv_within_at (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, p.eval x) (p.derivative.eval x) s x :=
(p.has_deriv_at x).has_deriv_within_at
protected lemma differentiable_at : differentiable_at 𝕜 (λx, p.eval x) x :=
(p.has_deriv_at x).differentiable_at
protected lemma differentiable_within_at : differentiable_within_at 𝕜 (λx, p.eval x) s x :=
p.differentiable_at.differentiable_within_at
protected lemma differentiable : differentiable 𝕜 (λx, p.eval x) :=
λx, p.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 (λx, p.eval x) s :=
p.differentiable.differentiable_on
@[simp] protected lemma deriv : deriv (λx, p.eval x) x = p.derivative.eval x :=
(p.has_deriv_at x).deriv
protected lemma deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, p.eval x) s x = p.derivative.eval x :=
begin
rw differentiable_at.deriv_within p.differentiable_at hxs,
exact p.deriv
end
protected lemma has_fderiv_at (x : 𝕜) :
has_fderiv_at (λx, p.eval x) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) x :=
p.has_deriv_at x
protected lemma has_fderiv_within_at (x : 𝕜) :
has_fderiv_within_at (λx, p.eval x) (smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) s x :=
(p.has_fderiv_at x).has_fderiv_within_at
@[simp] protected lemma fderiv :
fderiv 𝕜 (λx, p.eval x) x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) :=
(p.has_fderiv_at x).fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, p.eval x) s x = smul_right (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) :=
(p.has_fderiv_within_at x).fderiv_within hxs
end polynomial
section pow
/-! ### Derivative of `x ↦ x^n` for `n : ℕ` -/
variables {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜}
variable {n : ℕ }
lemma has_strict_deriv_at_pow (n : ℕ) (x : 𝕜) :
has_strict_deriv_at (λx, x^n) ((n : 𝕜) * x^(n-1)) x :=
begin
convert (polynomial.C (1 : 𝕜) * (polynomial.X)^n).has_strict_deriv_at x,
{ simp },
{ rw [polynomial.derivative_C_mul_X_pow], simp }
end
lemma has_deriv_at_pow (n : ℕ) (x : 𝕜) : has_deriv_at (λx, x^n) ((n : 𝕜) * x^(n-1)) x :=
(has_strict_deriv_at_pow n x).has_deriv_at
theorem has_deriv_within_at_pow (n : ℕ) (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, x^n) ((n : 𝕜) * x^(n-1)) s x :=
(has_deriv_at_pow n x).has_deriv_within_at
lemma differentiable_at_pow : differentiable_at 𝕜 (λx, x^n) x :=
(has_deriv_at_pow n x).differentiable_at
lemma differentiable_within_at_pow : differentiable_within_at 𝕜 (λx, x^n) s x :=
differentiable_at_pow.differentiable_within_at
lemma differentiable_pow : differentiable 𝕜 (λx:𝕜, x^n) :=
λx, differentiable_at_pow
lemma differentiable_on_pow : differentiable_on 𝕜 (λx, x^n) s :=
differentiable_pow.differentiable_on
lemma deriv_pow : deriv (λx, x^n) x = (n : 𝕜) * x^(n-1) :=
(has_deriv_at_pow n x).deriv
@[simp] lemma deriv_pow' : deriv (λx, x^n) = λ x, (n : 𝕜) * x^(n-1) :=
funext $ λ x, deriv_pow
lemma deriv_within_pow (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x^n) s x = (n : 𝕜) * x^(n-1) :=
(has_deriv_within_at_pow n x s).deriv_within hxs
lemma has_deriv_within_at.pow (hc : has_deriv_within_at c c' s x) :
has_deriv_within_at (λ y, (c y)^n) ((n : 𝕜) * (c x)^(n-1) * c') s x :=
(has_deriv_at_pow n (c x)).comp_has_deriv_within_at x hc
lemma has_deriv_at.pow (hc : has_deriv_at c c' x) :
has_deriv_at (λ y, (c y)^n) ((n : 𝕜) * (c x)^(n-1) * c') x :=
by { rw ← has_deriv_within_at_univ at *, exact hc.pow }
lemma differentiable_within_at.pow (hc : differentiable_within_at 𝕜 c s x) :
differentiable_within_at 𝕜 (λx, (c x)^n) s x :=
hc.has_deriv_within_at.pow.differentiable_within_at
@[simp] lemma differentiable_at.pow (hc : differentiable_at 𝕜 c x) :
differentiable_at 𝕜 (λx, (c x)^n) x :=
hc.has_deriv_at.pow.differentiable_at
lemma differentiable_on.pow (hc : differentiable_on 𝕜 c s) :
differentiable_on 𝕜 (λx, (c x)^n) s :=
λx h, (hc x h).pow
@[simp] lemma differentiable.pow (hc : differentiable 𝕜 c) :
differentiable 𝕜 (λx, (c x)^n) :=
λx, (hc x).pow
lemma deriv_within_pow' (hc : differentiable_within_at 𝕜 c s x)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, (c x)^n) s x = (n : 𝕜) * (c x)^(n-1) * (deriv_within c s x) :=
hc.has_deriv_within_at.pow.deriv_within hxs
@[simp] lemma deriv_pow'' (hc : differentiable_at 𝕜 c x) :
deriv (λx, (c x)^n) x = (n : 𝕜) * (c x)^(n-1) * (deriv c x) :=
hc.has_deriv_at.pow.deriv
end pow
section fpow
/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/
variables {x : 𝕜} {s : set 𝕜} {m : ℤ}
lemma has_strict_deriv_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
has_strict_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
begin
have : ∀ m : ℤ, 0 < m → has_strict_deriv_at (λx, x^m) ((m:𝕜) * x^(m-1)) x,
{ assume m hm,
lift m to ℕ using (le_of_lt hm),
simp only [gpow_coe_nat, int.cast_coe_nat],
convert has_strict_deriv_at_pow _ _ using 2,
rw [← int.coe_nat_one, ← int.coe_nat_sub, gpow_coe_nat],
norm_cast at hm,
exact nat.succ_le_of_lt hm },
rcases lt_trichotomy m 0 with hm|hm|hm,
{ have hx : x ≠ 0, from h.resolve_right hm.not_le,
have := (has_strict_deriv_at_inv _).scomp _ (this (-m) (neg_pos.2 hm));
[skip, exact fpow_ne_zero_of_ne_zero hx _],
simp only [(∘), fpow_neg, one_div, inv_inv₀, smul_eq_mul] at this,
convert this using 1,
rw [sq, mul_inv₀, inv_inv₀, int.cast_neg, ← neg_mul_eq_neg_mul, neg_mul_neg,
← fpow_add hx, mul_assoc, ← fpow_add hx], congr, abel },
{ simp only [hm, gpow_zero, int.cast_zero, zero_mul, has_strict_deriv_at_const] },
{ exact this m hm }
end
lemma has_deriv_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
has_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
(has_strict_deriv_at_fpow m x h).has_deriv_at
theorem has_deriv_within_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) (s : set 𝕜) :
has_deriv_within_at (λx, x^m) ((m : 𝕜) * x^(m-1)) s x :=
(has_deriv_at_fpow m x h).has_deriv_within_at
lemma differentiable_at_fpow : differentiable_at 𝕜 (λx, x^m) x ↔ x ≠ 0 ∨ 0 ≤ m :=
⟨λ H, normed_field.continuous_at_fpow.1 H.continuous_at,
λ H, (has_deriv_at_fpow m x H).differentiable_at⟩
lemma differentiable_within_at_fpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
differentiable_within_at 𝕜 (λx, x^m) s x :=
(differentiable_at_fpow.mpr h).differentiable_within_at
lemma differentiable_on_fpow (m : ℤ) (s : set 𝕜) (h : (0 : 𝕜) ∉ s ∨ 0 ≤ m) :
differentiable_on 𝕜 (λx, x^m) s :=
λ x hxs, differentiable_within_at_fpow m x $ h.imp_left $ ne_of_mem_of_not_mem hxs
lemma deriv_fpow (m : ℤ) (x : 𝕜) : deriv (λ x, x ^ m) x = m * x ^ (m - 1) :=
begin
by_cases H : x ≠ 0 ∨ 0 ≤ m,
{ exact (has_deriv_at_fpow m x H).deriv },
{ rw deriv_zero_of_not_differentiable_at (mt differentiable_at_fpow.1 H),
push_neg at H, rcases H with ⟨rfl, hm⟩,
rw [zero_fpow _ ((sub_one_lt _).trans hm).ne, mul_zero] }
end
@[simp] lemma deriv_fpow' (m : ℤ) : deriv (λ x : 𝕜, x ^ m) = λ x, m * x ^ (m - 1) :=
funext $ deriv_fpow m
lemma deriv_within_fpow (hxs : unique_diff_within_at 𝕜 s x) (h : x ≠ 0 ∨ 0 ≤ m) :
deriv_within (λx, x^m) s x = (m : 𝕜) * x^(m-1) :=
(has_deriv_within_at_fpow m x h s).deriv_within hxs
@[simp] lemma iter_deriv_fpow' (m : ℤ) (k : ℕ) :
deriv^[k] (λ x : 𝕜, x ^ m) = λ x, (∏ i in finset.range k, (m - i)) * x ^ (m - k) :=
begin
induction k with k ihk,
{ simp only [one_mul, int.coe_nat_zero, id, sub_zero, finset.prod_range_zero,
function.iterate_zero] },
{ simp only [function.iterate_succ_apply', ihk, deriv_const_mul_field', deriv_fpow',
finset.prod_range_succ, int.coe_nat_succ, ← sub_sub, int.cast_sub, int.cast_coe_nat,
mul_assoc], }
end
lemma iter_deriv_fpow (m : ℤ) (x : 𝕜) (k : ℕ) :
deriv^[k] (λ y, y ^ m) x = (∏ i in finset.range k, (m - i)) * x ^ (m - k) :=
congr_fun (iter_deriv_fpow' m k) x
lemma iter_deriv_pow (n : ℕ) (x : 𝕜) (k : ℕ) :
deriv^[k] (λx:𝕜, x^n) x = (∏ i in finset.range k, (n - i)) * x^(n-k) :=
begin
simp only [← gpow_coe_nat, iter_deriv_fpow, int.cast_coe_nat],
cases le_or_lt k n with hkn hnk,
{ rw int.coe_nat_sub hkn },
{ have : ∏ i in finset.range k, (n - i : 𝕜) = 0,
from finset.prod_eq_zero (finset.mem_range.2 hnk) (sub_self _),
simp only [this, zero_mul] }
end
@[simp] lemma iter_deriv_pow' (n k : ℕ) :
deriv^[k] (λ x : 𝕜, x ^ n) = λ x, (∏ i in finset.range k, (n - i)) * x ^ (n - k) :=
funext $ λ x, iter_deriv_pow n x k
lemma iter_deriv_inv (k : ℕ) (x : 𝕜) :
deriv^[k] has_inv.inv x = (∏ i in finset.range k, (-1 - i)) * x ^ (-1 - k : ℤ) :=
by simpa only [fpow_neg_one, int.cast_neg, int.cast_one] using iter_deriv_fpow (-1) x k
@[simp] lemma iter_deriv_inv' (k : ℕ) :
deriv^[k] has_inv.inv = λ x : 𝕜, (∏ i in finset.range k, (-1 - i)) * x ^ (-1 - k : ℤ) :=
funext (iter_deriv_inv k)
end fpow
/-! ### Upper estimates on liminf and limsup -/
section real
variables {f : ℝ → ℝ} {f' : ℝ} {s : set ℝ} {x : ℝ} {r : ℝ}
lemma has_deriv_within_at.limsup_slope_le (hf : has_deriv_within_at f f' s x) (hr : f' < r) :
∀ᶠ z in 𝓝[s \ {x}] x, (z - x)⁻¹ * (f z - f x) < r :=
has_deriv_within_at_iff_tendsto_slope.1 hf (is_open.mem_nhds is_open_Iio hr)
lemma has_deriv_within_at.limsup_slope_le' (hf : has_deriv_within_at f f' s x)
(hs : x ∉ s) (hr : f' < r) :
∀ᶠ z in 𝓝[s] x, (z - x)⁻¹ * (f z - f x) < r :=
(has_deriv_within_at_iff_tendsto_slope' hs).1 hf (is_open.mem_nhds is_open_Iio hr)
lemma has_deriv_within_at.liminf_right_slope_le
(hf : has_deriv_within_at f f' (Ici x) x) (hr : f' < r) :
∃ᶠ z in 𝓝[Ioi x] x, (z - x)⁻¹ * (f z - f x) < r :=
(hf.Ioi_of_Ici.limsup_slope_le' (lt_irrefl x) hr).frequently
end real
section real_space
open metric
variables {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {s : set ℝ}
{x r : ℝ}
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`. -/
lemma has_deriv_within_at.limsup_norm_slope_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in 𝓝[s] x, ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
begin
have hr₀ : 0 < r, from lt_of_le_of_lt (norm_nonneg f') hr,
have A : ∀ᶠ z in 𝓝[s \ {x}] x, ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from (has_deriv_within_at_iff_tendsto_slope.1 hf).norm (is_open.mem_nhds is_open_Iio hr),
have B : ∀ᶠ z in 𝓝[{x}] x, ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from mem_of_superset self_mem_nhds_within
(singleton_subset_iff.2 $ by simp [hr₀]),
have C := mem_sup.2 ⟨A, B⟩,
rw [← nhds_within_union, diff_union_self, nhds_within_union, mem_sup] at C,
filter_upwards [C.1],
simp only [norm_smul, mem_Iio, normed_field.norm_inv],
exact λ _, id
end
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`.
This lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`
where `∥f z∥ - ∥f x∥` is replaced by `∥f z - f x∥`. -/
lemma has_deriv_within_at.limsup_slope_norm_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in 𝓝[s] x, ∥z - x∥⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
apply (hf.limsup_norm_slope_le hr).mono,
assume z hz,
refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz,
exact inv_nonneg.2 (norm_nonneg _)
end
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`. See also `has_deriv_within_at.limsup_norm_slope_le`
for a stronger version using limit superior and any set `s`. -/
lemma has_deriv_within_at.liminf_right_norm_slope_le
(hf : has_deriv_within_at f f' (Ici x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in 𝓝[Ioi x] x, ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
(hf.Ioi_of_Ici.limsup_norm_slope_le hr).frequently
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / (z - x)` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`.
See also
* `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using
limit superior and any set `s`;
* `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using
`∥f z - f x∥` instead of `∥f z∥ - ∥f x∥`. -/
lemma has_deriv_within_at.liminf_right_slope_norm_le
(hf : has_deriv_within_at f f' (Ici x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in 𝓝[Ioi x] x, (z - x)⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
have := (hf.Ioi_of_Ici.limsup_slope_norm_le hr).frequently,
refine this.mp (eventually.mono self_mem_nhds_within _),
assume z hxz hz,
rwa [real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz
end
end real_space
|
7d9422c06f0cf6e256e3b49623dd5bfb7b8ec05c | b2fe74b11b57d362c13326bc5651244f111fa6f4 | /src/linear_algebra/tensor_product.lean | 776721bc69e1a380cd4d1c8a42720a77a1da4f07 | [
"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 | 31,562 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro
-/
import group_theory.congruence
import linear_algebra.basic
/-!
# Tensor product of semimodules over commutative semirings.
This file constructs the tensor product of semimodules over commutative semirings. Given a semiring
`R` and semimodules over it `M` and `N`, the standard construction of the tensor product is
`tensor_product R M N`. It is also a semimodule over `R`.
It comes with a canonical bilinear map `M → N → tensor_product R M N`.
Given any bilinear map `M → N → P`, there is a unique linear map `tensor_product R M N → P` whose
composition with the canonical bilinear map `M → N → tensor_product R M N` is the given bilinear
map `M → N → P`.
We start by proving basic lemmas about bilinear maps.
## Notations
This file uses the localized notation `M ⊗ N` and `M ⊗[R] N` for `tensor_product R M N`, as well
as `m ⊗ₜ n` and `m ⊗ₜ[R] n` for `tensor_product.tmul R m n`.
## Tags
bilinear, tensor, tensor product
-/
namespace linear_map
variables {R : Type*} [comm_semiring R]
variables {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*}
variables [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P] [add_comm_monoid Q]
[add_comm_monoid S]
variables [semimodule R M] [semimodule R N] [semimodule R P] [semimodule R Q] [semimodule R S]
include R
variables (R)
/-- Create a bilinear map from a function that is linear in each component. -/
def mk₂ (f : M → N → P)
(H1 : ∀ m₁ m₂ n, f (m₁ + m₂) n = f m₁ n + f m₂ n)
(H2 : ∀ (c:R) m n, f (c • m) n = c • f m n)
(H3 : ∀ m n₁ n₂, f m (n₁ + n₂) = f m n₁ + f m n₂)
(H4 : ∀ (c:R) m n, f m (c • n) = c • f m n) : M →ₗ N →ₗ P :=
⟨λ m, ⟨f m, H3 m, λ c, H4 c m⟩,
λ m₁ m₂, linear_map.ext $ H1 m₁ m₂,
λ c m, linear_map.ext $ H2 c m⟩
variables {R}
@[simp] theorem mk₂_apply
(f : M → N → P) {H1 H2 H3 H4} (m : M) (n : N) :
(mk₂ R f H1 H2 H3 H4 : M →ₗ[R] N →ₗ P) m n = f m n := rfl
theorem ext₂ {f g : M →ₗ[R] N →ₗ[R] P}
(H : ∀ m n, f m n = g m n) : f = g :=
linear_map.ext (λ m, linear_map.ext $ λ n, H m n)
/-- Given a linear map from `M` to linear maps from `N` to `P`, i.e., a bilinear map from `M × N` to
`P`, change the order of variables and get a linear map from `N` to linear maps from `M` to `P`. -/
def flip (f : M →ₗ[R] N →ₗ[R] P) : N →ₗ M →ₗ P :=
mk₂ R (λ n m, f m n)
(λ n₁ n₂ m, (f m).map_add _ _)
(λ c n m, (f m).map_smul _ _)
(λ n m₁ m₂, by rw f.map_add; refl)
(λ c n m, by rw f.map_smul; refl)
variable (f : M →ₗ[R] N →ₗ[R] P)
@[simp] theorem flip_apply (m : M) (n : N) : flip f n m = f m n := rfl
variables {R}
theorem flip_inj {f g : M →ₗ[R] N →ₗ P} (H : flip f = flip g) : f = g :=
ext₂ $ λ m n, show flip f n m = flip g n m, by rw H
variables (R M N P)
/-- Given a linear map from `M` to linear maps from `N` to `P`, i.e., a bilinear map `M → N → P`,
change the order of variables and get a linear map from `N` to linear maps from `M` to `P`. -/
def lflip : (M →ₗ[R] N →ₗ P) →ₗ[R] N →ₗ M →ₗ P :=
⟨flip, λ _ _, rfl, λ _ _, rfl⟩
variables {R M N P}
@[simp] theorem lflip_apply (m : M) (n : N) : lflip R M N P f n m = f m n := rfl
theorem map_zero₂ (y) : f 0 y = 0 := (flip f y).map_zero
theorem map_neg₂ {R : Type*} [comm_semiring R] {M N P : Type*}
[add_comm_group M] [add_comm_group N] [add_comm_group P]
[semimodule R M] [semimodule R N] [semimodule R P] (f : M →ₗ[R] N →ₗ[R] P) (x y) :
f (-x) y = -f x y :=
(flip f y).map_neg _
theorem map_add₂ (x₁ x₂ y) : f (x₁ + x₂) y = f x₁ y + f x₂ y := (flip f y).map_add _ _
theorem map_smul₂ (r:R) (x y) : f (r • x) y = r • f x y := (flip f y).map_smul _ _
variables (R P)
/-- Composing a linear map `M → N` and a linear map `N → P` to form a linear map `M → P`. -/
def lcomp (f : M →ₗ[R] N) : (N →ₗ[R] P) →ₗ[R] M →ₗ[R] P :=
flip $ linear_map.comp (flip id) f
variables {R P}
@[simp] theorem lcomp_apply (f : M →ₗ[R] N) (g : N →ₗ P) (x : M) :
lcomp R P f g x = g (f x) := rfl
variables (R M N P)
/-- Composing a linear map `M → N` and a linear map `N → P` to form a linear map `M → P`. -/
def llcomp : (N →ₗ[R] P) →ₗ[R] (M →ₗ[R] N) →ₗ M →ₗ P :=
flip ⟨lcomp R P,
λ f f', ext₂ $ λ g x, g.map_add _ _,
λ c f, ext₂ $ λ g x, g.map_smul _ _⟩
variables {R M N P}
section
@[simp] theorem llcomp_apply (f : N →ₗ[R] P) (g : M →ₗ[R] N) (x : M) :
llcomp R M N P f g x = f (g x) := rfl
end
/-- Composing a linear map `Q → N` and a bilinear map `M → N → P` to
form a bilinear map `M → Q → P`. -/
def compl₂ (g : Q →ₗ N) : M →ₗ Q →ₗ P := (lcomp R _ g).comp f
@[simp] theorem compl₂_apply (g : Q →ₗ[R] N) (m : M) (q : Q) :
f.compl₂ g m q = f m (g q) := rfl
/-- Composing a linear map `P → Q` and a bilinear map `M × N → P` to
form a bilinear map `M → N → Q`. -/
def compr₂ (g : P →ₗ Q) : M →ₗ N →ₗ Q :=
linear_map.comp (llcomp R N P Q g) f
@[simp] theorem compr₂_apply (g : P →ₗ[R] Q) (m : M) (n : N) :
f.compr₂ g m n = g (f m n) := rfl
variables (R M)
/-- Scalar multiplication as a bilinear map `R → M → M`. -/
def lsmul : R →ₗ M →ₗ M :=
mk₂ R (•) add_smul (λ _ _ _, mul_smul _ _ _) smul_add
(λ r s m, by simp only [smul_smul, smul_eq_mul, mul_comm])
variables {R M}
@[simp] theorem lsmul_apply (r : R) (m : M) : lsmul R M r m = r • m := rfl
end linear_map
section semiring
variables {R : Type*} [comm_semiring R]
variables {R' : Type*} [comm_semiring R'] [has_scalar R' R]
variables {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*}
variables [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P] [add_comm_monoid Q]
[add_comm_monoid S]
variables [semimodule R M] [semimodule R N] [semimodule R P] [semimodule R Q] [semimodule R S]
variables [semimodule R' M] [semimodule R' N]
variables [is_scalar_tower R' R M] [is_scalar_tower R' R N]
include R
variables (M N)
namespace tensor_product
section
-- open free_add_monoid
variables (R)
/-- The relation on `free_add_monoid (M × N)` that generates a congruence whose quotient is
the tensor product. -/
inductive eqv : free_add_monoid (M × N) → free_add_monoid (M × N) → Prop
| of_zero_left : ∀ n : N, eqv (free_add_monoid.of (0, n)) 0
| of_zero_right : ∀ m : M, eqv (free_add_monoid.of (m, 0)) 0
| of_add_left : ∀ (m₁ m₂ : M) (n : N), eqv
(free_add_monoid.of (m₁, n) + free_add_monoid.of (m₂, n)) (free_add_monoid.of (m₁ + m₂, n))
| of_add_right : ∀ (m : M) (n₁ n₂ : N), eqv
(free_add_monoid.of (m, n₁) + free_add_monoid.of (m, n₂)) (free_add_monoid.of (m, n₁ + n₂))
| of_smul : ∀ (r : R) (m : M) (n : N), eqv
(free_add_monoid.of (r • m, n)) (free_add_monoid.of (m, r • n))
| add_comm : ∀ x y, eqv (x + y) (y + x)
end
end tensor_product
variables (R)
/-- The tensor product of two semimodules `M` and `N` over the same commutative semiring `R`.
The localized notations are `M ⊗ N` and `M ⊗[R] N`, accessed by `open_locale tensor_product`. -/
def tensor_product : Type* :=
(add_con_gen (tensor_product.eqv R M N)).quotient
variables {R}
localized "infix ` ⊗ `:100 := tensor_product _" in tensor_product
localized "notation M ` ⊗[`:100 R `] ` N:100 := tensor_product R M N" in tensor_product
namespace tensor_product
section module
instance : add_comm_monoid (M ⊗[R] N) :=
{ add_comm := λ x y, add_con.induction_on₂ x y $ λ x y, quotient.sound' $
add_con_gen.rel.of _ _ $ eqv.add_comm _ _,
.. (add_con_gen (tensor_product.eqv R M N)).add_monoid }
instance : inhabited (M ⊗[R] N) := ⟨0⟩
variables (R) {M N}
/-- The canonical function `M → N → M ⊗ N`. The localized notations are `m ⊗ₜ n` and `m ⊗ₜ[R] n`,
accessed by `open_locale tensor_product`. -/
def tmul (m : M) (n : N) : M ⊗[R] N := add_con.mk' _ $ free_add_monoid.of (m, n)
variables {R}
infix ` ⊗ₜ `:100 := tmul _
notation x ` ⊗ₜ[`:100 R `] ` y := tmul R x y
@[elab_as_eliminator]
protected theorem induction_on
{C : (M ⊗[R] N) → Prop}
(z : M ⊗[R] N)
(C0 : C 0)
(C1 : ∀ {x y}, C $ x ⊗ₜ[R] y)
(Cp : ∀ {x y}, C x → C y → C (x + y)) : C z :=
add_con.induction_on z $ λ x, free_add_monoid.rec_on x C0 $ λ ⟨m, n⟩ y ih,
by { rw add_con.coe_add, exact Cp C1 ih }
variables (M)
@[simp] lemma zero_tmul (n : N) : (0 ⊗ₜ n : M ⊗[R] N) = 0 :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_zero_left _
variables {M}
lemma add_tmul (m₁ m₂ : M) (n : N) : (m₁ + m₂) ⊗ₜ n = m₁ ⊗ₜ n + m₂ ⊗ₜ[R] n :=
eq.symm $ quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_add_left _ _ _
variables (N)
@[simp] lemma tmul_zero (m : M) : (m ⊗ₜ 0 : M ⊗[R] N) = 0 :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_zero_right _
variables {N}
lemma tmul_add (m : M) (n₁ n₂ : N) : m ⊗ₜ (n₁ + n₂) = m ⊗ₜ n₁ + m ⊗ₜ[R] n₂ :=
eq.symm $ quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_add_right _ _ _
lemma smul_tmul (r : R') (m : M) (n : N) : (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) :=
begin
conv_lhs {rw ← one_smul R m},
conv_rhs {rw ← one_smul R n},
rw [←smul_assoc, ←smul_assoc],
exact (quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_smul _ _ _),
end
/-- Auxiliary function to defining scalar multiplication on tensor product. -/
def smul.aux {R' : Type*} [has_scalar R' M] (r : R') : free_add_monoid (M × N) →+ M ⊗[R] N :=
free_add_monoid.lift $ λ p : M × N, (r • p.1) ⊗ₜ p.2
theorem smul.aux_of {R' : Type*} [has_scalar R' M] (r : R') (m : M) (n : N) :
smul.aux r (free_add_monoid.of (m, n)) = (r • m) ⊗ₜ[R] n :=
rfl
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
@[priority 900]
instance has_scalar' : has_scalar R' (M ⊗[R] N) :=
⟨λ r, (add_con_gen (tensor_product.eqv R M N)).lift (smul.aux r : _ →+ M ⊗[R] N) $
add_con.add_con_gen_le $ λ x y hxy, match x, y, hxy with
| _, _, (eqv.of_zero_left n) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_zero, smul.aux_of, smul_zero, zero_tmul]
| _, _, (eqv.of_zero_right m) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_zero, smul.aux_of, tmul_zero]
| _, _, (eqv.of_add_left m₁ m₂ n) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, smul.aux_of, smul_add, add_tmul]
| _, _, (eqv.of_add_right m n₁ n₂) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, smul.aux_of, tmul_add]
| _, _, (eqv.of_smul s m n) := (add_con.ker_rel _).2 $
by rw [smul.aux_of, smul.aux_of, ←smul_assoc, smul_tmul, smul_tmul, smul_assoc]
| _, _, (eqv.add_comm x y) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, add_comm]
end⟩
instance : has_scalar R (M ⊗[R] N) := tensor_product.has_scalar'
protected theorem smul_zero (r : R') : (r • 0 : M ⊗[R] N) = 0 :=
add_monoid_hom.map_zero _
protected theorem smul_add (r : R') (x y : M ⊗[R] N) :
r • (x + y) = r • x + r • y :=
add_monoid_hom.map_add _ _ _
theorem smul_tmul' (r : R') (m : M) (n : N) :
r • (m ⊗ₜ n : M ⊗[R] N) = (r • m) ⊗ₜ n :=
rfl
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
@[priority 900]
instance semimodule' : semimodule R' (M ⊗[R] N) :=
{ smul := (•),
smul_add := λ r x y, tensor_product.smul_add r x y,
mul_smul := λ r s x, tensor_product.induction_on x
(by simp_rw tensor_product.smul_zero)
(λ m n, by simp_rw [smul_tmul', mul_smul])
(λ x y ihx ihy, by { simp_rw tensor_product.smul_add, rw [ihx, ihy] }),
one_smul := λ x, tensor_product.induction_on x
(by rw tensor_product.smul_zero)
(λ m n, by rw [smul_tmul', one_smul])
(λ x y ihx ihy, by rw [tensor_product.smul_add, ihx, ihy]),
add_smul := λ r s x, tensor_product.induction_on x
(by simp_rw [tensor_product.smul_zero, add_zero])
(λ m n, by simp_rw [smul_tmul', add_smul, add_tmul])
(λ x y ihx ihy, by { simp_rw tensor_product.smul_add, rw [ihx, ihy, add_add_add_comm] }),
smul_zero := λ r, tensor_product.smul_zero r,
zero_smul := λ x, tensor_product.induction_on x
(by rw tensor_product.smul_zero)
(λ m n, by rw [smul_tmul', zero_smul, zero_tmul])
(λ x y ihx ihy, by rw [tensor_product.smul_add, ihx, ihy, add_zero]) }
instance : semimodule R (M ⊗[R] N) := tensor_product.semimodule'
@[simp] lemma tmul_smul (r : R') (x : M) (y : N) : x ⊗ₜ (r • y) = r • (x ⊗ₜ[R] y) :=
(smul_tmul _ _ _).symm
variables (R M N)
/-- The canonical bilinear map `M → N → M ⊗[R] N`. -/
def mk : M →ₗ N →ₗ M ⊗[R] N :=
linear_map.mk₂ R (⊗ₜ) add_tmul (λ c m n, by rw [smul_tmul, tmul_smul]) tmul_add tmul_smul
variables {R M N}
@[simp] lemma mk_apply (m : M) (n : N) : mk R M N m n = m ⊗ₜ n := rfl
lemma ite_tmul (x₁ : M) (x₂ : N) (P : Prop) [decidable P] :
((if P then x₁ else 0) ⊗ₜ[R] x₂) = if P then (x₁ ⊗ₜ x₂) else 0 :=
by { split_ifs; simp }
lemma tmul_ite (x₁ : M) (x₂ : N) (P : Prop) [decidable P] :
(x₁ ⊗ₜ[R] (if P then x₂ else 0)) = if P then (x₁ ⊗ₜ x₂) else 0 :=
by { split_ifs; simp }
section
open_locale big_operators
lemma sum_tmul {α : Type*} (s : finset α) (m : α → M) (n : N) :
((∑ a in s, m a) ⊗ₜ[R] n) = ∑ a in s, m a ⊗ₜ[R] n :=
begin
classical,
induction s using finset.induction with a s has ih h,
{ simp, },
{ simp [finset.sum_insert has, add_tmul, ih], },
end
lemma tmul_sum (m : M) {α : Type*} (s : finset α) (n : α → N) :
(m ⊗ₜ[R] (∑ a in s, n a)) = ∑ a in s, m ⊗ₜ[R] n a :=
begin
classical,
induction s using finset.induction with a s has ih h,
{ simp, },
{ simp [finset.sum_insert has, tmul_add, ih], },
end
end
end module
section UMP
variables {M N P Q}
variables (f : M →ₗ[R] N →ₗ[R] P)
/-- Auxiliary function to constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P`
with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is
the given bilinear map `M → N → P`. -/
def lift_aux : (M ⊗[R] N) →+ P :=
(add_con_gen (tensor_product.eqv R M N)).lift (free_add_monoid.lift $ λ p : M × N, f p.1 p.2) $
add_con.add_con_gen_le $ λ x y hxy, match x, y, hxy with
| _, _, (eqv.of_zero_left n) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_zero, free_add_monoid.lift_eval_of, f.map_zero₂]
| _, _, (eqv.of_zero_right m) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_zero, free_add_monoid.lift_eval_of, (f m).map_zero]
| _, _, (eqv.of_add_left m₁ m₂ n) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, free_add_monoid.lift_eval_of, f.map_add₂]
| _, _, (eqv.of_add_right m n₁ n₂) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, free_add_monoid.lift_eval_of, (f m).map_add]
| _, _, (eqv.of_smul r m n) := (add_con.ker_rel _).2 $
by simp_rw [free_add_monoid.lift_eval_of, f.map_smul₂, (f m).map_smul]
| _, _, (eqv.add_comm x y) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, add_comm]
end
lemma lift_aux_tmul (m n) : lift_aux f (m ⊗ₜ n) = f m n :=
zero_add _
variable {f}
@[simp] lemma lift_aux.smul (r : R) (x) : lift_aux f (r • x) = r • lift_aux f x :=
tensor_product.induction_on x (smul_zero _).symm
(λ p q, by rw [← tmul_smul, lift_aux_tmul, lift_aux_tmul, (f p).map_smul])
(λ p q ih1 ih2, by rw [smul_add, (lift_aux f).map_add, ih1, ih2, (lift_aux f).map_add, smul_add])
variable (f)
/-- Constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that
its composition with the canonical bilinear map `M → N → M ⊗ N` is
the given bilinear map `M → N → P`. -/
def lift : M ⊗ N →ₗ P :=
{ map_smul' := lift_aux.smul,
.. lift_aux f }
variable {f}
@[simp] lemma lift.tmul (x y) : lift f (x ⊗ₜ y) = f x y :=
zero_add _
@[simp] lemma lift.tmul' (x y) : (lift f).1 (x ⊗ₜ y) = f x y :=
lift.tmul _ _
@[ext]
theorem ext {g h : (M ⊗[R] N) →ₗ[R] P}
(H : ∀ x y, g (x ⊗ₜ y) = h (x ⊗ₜ y)) : g = h :=
linear_map.ext $ λ z, tensor_product.induction_on z (by simp_rw linear_map.map_zero) H $
λ x y ihx ihy, by rw [g.map_add, h.map_add, ihx, ihy]
theorem lift.unique {g : (M ⊗[R] N) →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = f x y) :
g = lift f :=
ext $ λ m n, by rw [H, lift.tmul]
theorem lift_mk : lift (mk R M N) = linear_map.id :=
eq.symm $ lift.unique $ λ x y, rfl
theorem lift_compr₂ (g : P →ₗ Q) : lift (f.compr₂ g) = g.comp (lift f) :=
eq.symm $ lift.unique $ λ x y, by simp
theorem lift_mk_compr₂ (f : M ⊗ N →ₗ P) : lift ((mk R M N).compr₂ f) = f :=
by rw [lift_compr₂ f, lift_mk, linear_map.comp_id]
theorem mk_compr₂_inj {g h : M ⊗ N →ₗ P}
(H : (mk R M N).compr₂ g = (mk R M N).compr₂ h) : g = h :=
by rw [← lift_mk_compr₂ g, H, lift_mk_compr₂]
example : M → N → (M → N → P) → P :=
λ m, flip $ λ f, f m
variables (R M N P)
/-- Linearly constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P`
with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is
the given bilinear map `M → N → P`. -/
def uncurry : (M →ₗ[R] N →ₗ[R] P) →ₗ[R] M ⊗[R] N →ₗ[R] P :=
linear_map.flip $ lift $ (linear_map.lflip _ _ _ _).comp (linear_map.flip linear_map.id)
variables {R M N P}
@[simp] theorem uncurry_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) :
uncurry R M N P f (m ⊗ₜ n) = f m n :=
by rw [uncurry, linear_map.flip_apply, lift.tmul]; refl
variables (R M N P)
/-- A linear equivalence constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P`
with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is
the given bilinear map `M → N → P`. -/
def lift.equiv : (M →ₗ N →ₗ P) ≃ₗ (M ⊗ N →ₗ P) :=
{ inv_fun := λ f, (mk R M N).compr₂ f,
left_inv := λ f, linear_map.ext₂ $ λ m n, lift.tmul _ _,
right_inv := λ f, ext $ λ m n, lift.tmul _ _,
.. uncurry R M N P }
/-- Given a linear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to
form a bilinear map `M → N → P`. -/
def lcurry : (M ⊗[R] N →ₗ[R] P) →ₗ[R] M →ₗ[R] N →ₗ[R] P :=
(lift.equiv R M N P).symm
variables {R M N P}
@[simp] theorem lcurry_apply (f : M ⊗[R] N →ₗ[R] P) (m : M) (n : N) :
lcurry R M N P f m n = f (m ⊗ₜ n) := rfl
/-- Given a linear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to
form a bilinear map `M → N → P`. -/
def curry (f : M ⊗ N →ₗ P) : M →ₗ N →ₗ P := lcurry R M N P f
@[simp] theorem curry_apply (f : M ⊗ N →ₗ[R] P) (m : M) (n : N) :
curry f m n = f (m ⊗ₜ n) := rfl
theorem ext_threefold {g h : (M ⊗[R] N) ⊗[R] P →ₗ[R] Q}
(H : ∀ x y z, g ((x ⊗ₜ y) ⊗ₜ z) = h ((x ⊗ₜ y) ⊗ₜ z)) : g = h :=
begin
let e := linear_equiv.to_equiv (lift.equiv R (M ⊗[R] N) P Q),
apply e.symm.injective,
refine ext _,
intros x y,
ext z,
exact H x y z
end
-- We'll need this one for checking the pentagon identity!
theorem ext_fourfold {g h : ((M ⊗[R] N) ⊗[R] P) ⊗[R] Q →ₗ[R] S}
(H : ∀ w x y z, g (((w ⊗ₜ x) ⊗ₜ y) ⊗ₜ z) = h (((w ⊗ₜ x) ⊗ₜ y) ⊗ₜ z)) : g = h :=
begin
let e := linear_equiv.to_equiv (lift.equiv R ((M ⊗[R] N) ⊗[R] P) Q S),
apply e.symm.injective,
refine ext_threefold _,
intros x y z,
ext w,
exact H x y z w,
end
end UMP
variables {M N}
section
variables (R M)
/--
The base ring is a left identity for the tensor product of modules, up to linear equivalence.
-/
protected def lid : R ⊗ M ≃ₗ M :=
linear_equiv.of_linear (lift $ linear_map.lsmul R M) (mk R R M 1)
(linear_map.ext $ λ _, by simp)
(ext $ λ r m, by simp; rw [← tmul_smul, ← smul_tmul, smul_eq_mul, mul_one])
end
@[simp] theorem lid_tmul (m : M) (r : R) :
((tensor_product.lid R M) : (R ⊗ M → M)) (r ⊗ₜ m) = r • m :=
begin
dsimp [tensor_product.lid],
simp,
end
@[simp] lemma lid_symm_apply (m : M) :
(tensor_product.lid R M).symm m = 1 ⊗ₜ m := rfl
section
variables (R M N)
/--
The tensor product of modules is commutative, up to linear equivalence.
-/
protected def comm : M ⊗ N ≃ₗ N ⊗ M :=
linear_equiv.of_linear (lift (mk R N M).flip) (lift (mk R M N).flip)
(ext $ λ m n, rfl)
(ext $ λ m n, rfl)
@[simp] theorem comm_tmul (m : M) (n : N) :
(tensor_product.comm R M N) (m ⊗ₜ n) = n ⊗ₜ m := rfl
@[simp] theorem comm_symm_tmul (m : M) (n : N) :
(tensor_product.comm R M N).symm (n ⊗ₜ m) = m ⊗ₜ n := rfl
end
section
variables (R M)
/--
The base ring is a right identity for the tensor product of modules, up to linear equivalence.
-/
protected def rid : M ⊗[R] R ≃ₗ M :=
linear_equiv.trans (tensor_product.comm R M R) (tensor_product.lid R M)
end
@[simp] theorem rid_tmul (m : M) (r : R) :
(tensor_product.rid R M) (m ⊗ₜ r) = r • m :=
begin
dsimp [tensor_product.rid, tensor_product.comm, tensor_product.lid],
simp,
end
@[simp] lemma rid_symm_apply (m : M) :
(tensor_product.rid R M).symm m = m ⊗ₜ 1 := rfl
open linear_map
section
variables (R M N P)
/-- The associator for tensor product of R-modules, as a linear equivalence. -/
protected def assoc : (M ⊗[R] N) ⊗[R] P ≃ₗ[R] M ⊗[R] (N ⊗[R] P) :=
begin
refine linear_equiv.of_linear
(lift $ lift $ comp (lcurry R _ _ _) $ mk _ _ _)
(lift $ comp (uncurry R _ _ _) $ curry $ mk _ _ _)
(mk_compr₂_inj $ linear_map.ext $ λ m, ext $ λ n p, _)
(mk_compr₂_inj $ flip_inj $ linear_map.ext $ λ p, ext $ λ m n, _);
repeat { rw lift.tmul <|> rw compr₂_apply <|> rw comp_apply <|>
rw mk_apply <|> rw flip_apply <|> rw lcurry_apply <|>
rw uncurry_apply <|> rw curry_apply <|> rw id_apply }
end
end
@[simp] theorem assoc_tmul (m : M) (n : N) (p : P) :
(tensor_product.assoc R M N P) ((m ⊗ₜ n) ⊗ₜ p) = m ⊗ₜ (n ⊗ₜ p) := rfl
@[simp] theorem assoc_symm_tmul (m : M) (n : N) (p : P) :
(tensor_product.assoc R M N P).symm (m ⊗ₜ (n ⊗ₜ p)) = (m ⊗ₜ n) ⊗ₜ p := rfl
/-- The tensor product of a pair of linear maps between modules. -/
def map (f : M →ₗ[R] P) (g : N →ₗ Q) : M ⊗ N →ₗ[R] P ⊗ Q :=
lift $ comp (compl₂ (mk _ _ _) g) f
@[simp] theorem map_tmul (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (m : M) (n : N) :
map f g (m ⊗ₜ n) = f m ⊗ₜ g n :=
rfl
section
variables {P' Q' : Type*}
variables [add_comm_monoid P'] [semimodule R P']
variables [add_comm_monoid Q'] [semimodule R Q']
lemma map_comp (f₂ : P →ₗ[R] P') (f₁ : M →ₗ[R] P) (g₂ : Q →ₗ[R] Q') (g₁ : N →ₗ[R] Q) :
map (f₂.comp f₁) (g₂.comp g₁) = (map f₂ g₂).comp (map f₁ g₁) :=
by { ext1, simp only [linear_map.comp_apply, map_tmul] }
lemma lift_comp_map (i : P →ₗ[R] Q →ₗ[R] Q') (f : M →ₗ[R] P) (g : N →ₗ[R] Q) :
(lift i).comp (map f g) = lift ((i.comp f).compl₂ g) :=
by { ext1, simp only [lift.tmul, map_tmul, linear_map.compl₂_apply, linear_map.comp_apply] }
end
/-- If `M` and `P` are linearly equivalent and `N` and `Q` are linearly equivalent
then `M ⊗ N` and `P ⊗ Q` are linearly equivalent. -/
def congr (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : M ⊗ N ≃ₗ[R] P ⊗ Q :=
linear_equiv.of_linear (map f g) (map f.symm g.symm)
(ext $ λ m n, by simp; simp only [linear_equiv.apply_symm_apply])
(ext $ λ m n, by simp; simp only [linear_equiv.symm_apply_apply])
@[simp] theorem congr_tmul (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (m : M) (n : N) :
congr f g (m ⊗ₜ n) = f m ⊗ₜ g n :=
rfl
@[simp] theorem congr_symm_tmul (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (p : P) (q : Q) :
(congr f g).symm (p ⊗ₜ q) = f.symm p ⊗ₜ g.symm q :=
rfl
end tensor_product
namespace linear_map
variables {R} (M) {N P Q}
/-- `ltensor M f : M ⊗ N →ₗ M ⊗ P` is the natural linear map induced by `f : N →ₗ P`. -/
def ltensor (f : N →ₗ[R] P) : M ⊗ N →ₗ[R] M ⊗ P :=
tensor_product.map id f
/-- `rtensor f M : N₁ ⊗ M →ₗ N₂ ⊗ M` is the natural linear map induced by `f : N₁ →ₗ N₂`. -/
def rtensor (f : N →ₗ[R] P) : N ⊗ M →ₗ[R] P ⊗ M :=
tensor_product.map f id
variables (g : P →ₗ[R] Q) (f : N →ₗ[R] P)
@[simp] lemma ltensor_tmul (m : M) (n : N) : f.ltensor M (m ⊗ₜ n) = m ⊗ₜ (f n) := rfl
@[simp] lemma rtensor_tmul (m : M) (n : N) : f.rtensor M (n ⊗ₜ m) = (f n) ⊗ₜ m := rfl
open tensor_product
/-- `ltensor_hom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `M ⊗ f`. -/
def ltensor_hom : (N →ₗ[R] P) →ₗ[R] (M ⊗[R] N →ₗ[R] M ⊗[R] P) :=
{ to_fun := ltensor M,
map_add' := λ f g, by { ext x y, simp only [add_apply, ltensor_tmul, tmul_add] },
map_smul' := λ r f, by { ext x y, simp only [tmul_smul, smul_apply, ltensor_tmul] } }
/-- `rtensor_hom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `M ⊗ f`. -/
def rtensor_hom : (N →ₗ[R] P) →ₗ[R] (N ⊗[R] M →ₗ[R] P ⊗[R] M) :=
{ to_fun := λ f, f.rtensor M,
map_add' := λ f g, by { ext x y, simp only [add_apply, rtensor_tmul, add_tmul] },
map_smul' := λ r f, by { ext x y, simp only [smul_tmul, tmul_smul, smul_apply, rtensor_tmul] } }
@[simp] lemma coe_ltensor_hom :
(ltensor_hom M : (N →ₗ[R] P) → (M ⊗[R] N →ₗ[R] M ⊗[R] P)) = ltensor M := rfl
@[simp] lemma coe_rtensor_hom :
(rtensor_hom M : (N →ₗ[R] P) → (N ⊗[R] M →ₗ[R] P ⊗[R] M)) = rtensor M := rfl
@[simp] lemma ltensor_add (f g : N →ₗ[R] P) : (f + g).ltensor M = f.ltensor M + g.ltensor M :=
(ltensor_hom M).map_add f g
@[simp] lemma rtensor_add (f g : N →ₗ[R] P) : (f + g).rtensor M = f.rtensor M + g.rtensor M :=
(rtensor_hom M).map_add f g
@[simp] lemma ltensor_zero : ltensor M (0 : N →ₗ[R] P) = 0 :=
(ltensor_hom M).map_zero
@[simp] lemma rtensor_zero : rtensor M (0 : N →ₗ[R] P) = 0 :=
(rtensor_hom M).map_zero
@[simp] lemma ltensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).ltensor M = r • (f.ltensor M) :=
(ltensor_hom M).map_smul r f
@[simp] lemma rtensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).rtensor M = r • (f.rtensor M) :=
(rtensor_hom M).map_smul r f
lemma ltensor_comp : (g.comp f).ltensor M = (g.ltensor M).comp (f.ltensor M) :=
by { ext m n, simp only [comp_apply, ltensor_tmul] }
lemma rtensor_comp : (g.comp f).rtensor M = (g.rtensor M).comp (f.rtensor M) :=
by { ext m n, simp only [comp_apply, rtensor_tmul] }
variables (N)
@[simp] lemma ltensor_id : (id : N →ₗ[R] N).ltensor M = id :=
by { ext m n, simp only [id_coe, id.def, ltensor_tmul] }
@[simp] lemma rtensor_id : (id : N →ₗ[R] N).rtensor M = id :=
by { ext m n, simp only [id_coe, id.def, rtensor_tmul] }
variables {N}
@[simp] lemma ltensor_comp_rtensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) :
(g.ltensor P).comp (f.rtensor N) = map f g :=
by simp only [ltensor, rtensor, ← map_comp, id_comp, comp_id]
@[simp] lemma rtensor_comp_ltensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) :
(f.rtensor Q).comp (g.ltensor M) = map f g :=
by simp only [ltensor, rtensor, ← map_comp, id_comp, comp_id]
@[simp] lemma map_comp_rtensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (f' : S →ₗ[R] M) :
(map f g).comp (f'.rtensor _) = map (f.comp f') g :=
by simp only [ltensor, rtensor, ← map_comp, id_comp, comp_id]
@[simp] lemma map_comp_ltensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (g' : S →ₗ[R] N) :
(map f g).comp (g'.ltensor _) = map f (g.comp g') :=
by simp only [ltensor, rtensor, ← map_comp, id_comp, comp_id]
@[simp] lemma rtensor_comp_map (f' : P →ₗ[R] S) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) :
(f'.rtensor _).comp (map f g) = map (f'.comp f) g :=
by simp only [ltensor, rtensor, ← map_comp, id_comp, comp_id]
@[simp] lemma ltensor_comp_map (g' : Q →ₗ[R] S) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) :
(g'.ltensor _).comp (map f g) = map f (g'.comp g) :=
by simp only [ltensor, rtensor, ← map_comp, id_comp, comp_id]
end linear_map
end semiring
section ring
variables {R : Type*} [comm_semiring R]
variables {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*}
variables [add_comm_group M] [add_comm_group N] [add_comm_group P] [add_comm_group Q]
[add_comm_group S]
variables [semimodule R M] [semimodule R N] [semimodule R P] [semimodule R Q] [semimodule R S]
namespace tensor_product
open_locale tensor_product
open linear_map
variables (R)
/-- Auxiliary function to defining negation multiplication on tensor product. -/
def neg.aux : free_add_monoid (M × N) →+ M ⊗[R] N :=
free_add_monoid.lift $ λ p : M × N, (-p.1) ⊗ₜ p.2
variables {R}
theorem neg.aux_of (m : M) (n : N) :
neg.aux R (free_add_monoid.of (m, n)) = (-m) ⊗ₜ[R] n :=
rfl
instance : has_neg (M ⊗[R] N) :=
{ neg := (add_con_gen (tensor_product.eqv R M N)).lift (neg.aux R) $ add_con.add_con_gen_le $
λ x y hxy, match x, y, hxy with
| _, _, (eqv.of_zero_left n) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_zero, neg.aux_of, neg_zero, zero_tmul]
| _, _, (eqv.of_zero_right m) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_zero, neg.aux_of, tmul_zero]
| _, _, (eqv.of_add_left m₁ m₂ n) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, neg.aux_of, neg_add, add_tmul]
| _, _, (eqv.of_add_right m n₁ n₂) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, neg.aux_of, tmul_add]
| _, _, (eqv.of_smul s m n) := (add_con.ker_rel _).2 $
by simp_rw [neg.aux_of, tmul_smul s, smul_tmul', smul_neg]
| _, _, (eqv.add_comm x y) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, add_comm]
end }
lemma neg_tmul (m : M) (n : N) : (-m) ⊗ₜ n = -(m ⊗ₜ[R] n) := rfl
instance : add_comm_group (M ⊗[R] N) :=
{ neg := has_neg.neg,
sub := _,
sub_eq_add_neg := λ _ _, rfl,
add_left_neg := λ x, tensor_product.induction_on x
(by { rw [add_zero], apply (neg.aux R).map_zero, })
(λ x y, by { convert (add_tmul (-x) x y).symm, rw [add_left_neg, zero_tmul], })
(λ x y hx hy, by {
unfold has_neg.neg sub_neg_monoid.neg,
rw add_monoid_hom.map_add,
ac_change (-x + x) + (-y + y) = 0,
rw [hx, hy, add_zero], }),
..(infer_instance : add_comm_monoid (M ⊗[R] N)) }
lemma tmul_neg (m : M) (n : N) : m ⊗ₜ (-n) = -(m ⊗ₜ[R] n) := (mk R M N _).map_neg _
end tensor_product
namespace linear_map
@[simp] lemma ltensor_sub (f g : N →ₗ[R] P) : (f - g).ltensor M = f.ltensor M - g.ltensor M :=
by simp only [← coe_ltensor_hom, map_sub]
@[simp] lemma rtensor_sub (f g : N →ₗ[R] P) : (f - g).rtensor M = f.rtensor M - g.rtensor M :=
by simp only [← coe_rtensor_hom, map_sub]
@[simp] lemma ltensor_neg (f : N →ₗ[R] P) : (-f).ltensor M = -(f.ltensor M) :=
by simp only [← coe_ltensor_hom, map_neg]
@[simp] lemma rtensor_neg (f : N →ₗ[R] P) : (-f).rtensor M = -(f.rtensor M) :=
by simp only [← coe_rtensor_hom, map_neg]
end linear_map
end ring
|
c1ff0c2dda6db7591557caf37e58e6c822ca8bf6 | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/order/filter/default.lean | 371a3760859a323be94bbaaad012ef80dfdf3172 | [
"Apache-2.0"
] | permissive | fpvandoorn/mathlib | b21ab4068db079cbb8590b58fda9cc4bc1f35df4 | b3433a51ea8bc07c4159c1073838fc0ee9b8f227 | refs/heads/master | 1,624,791,089,608 | 1,556,715,231,000 | 1,556,715,231,000 | 165,722,980 | 5 | 0 | Apache-2.0 | 1,552,657,455,000 | 1,547,494,646,000 | Lean | UTF-8 | Lean | false | false | 47 | lean | import order.filter.basic order.filter.partial
|
fa3d3e0cac611b8bd890cfaf8a9531450ed8ae6a | f4bff2062c030df03d65e8b69c88f79b63a359d8 | /src/game/limits/seq_limitTimesConst.lean | 65d88ff918284bacb52ff058e02990b3b0622259 | [
"Apache-2.0"
] | permissive | adastra7470/real-number-game | 776606961f52db0eb824555ed2f8e16f92216ea3 | f9dcb7d9255a79b57e62038228a23346c2dc301b | refs/heads/master | 1,669,221,575,893 | 1,594,669,800,000 | 1,594,669,800,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,714 | lean | import game.limits.L01defs
import game.limits.seq_lim_add
namespace xena -- hide
notation `|` x `|` := abs x -- hide
/-
A basic result for working with sequences.
-/
/- Lemma
If $\lim_{n \to \infty} a_n = \alpha$ and $c \in \mathbb{R}$, then
$\lim_{n \to \infty} (c \cdot a_n) = c \cdot \alpha$
-/
lemma lim_times_const (a : ℕ → ℝ) (α c : ℝ) (hL : is_limit a α) :
is_limit (λ n, c * (a n)) (c*α) :=
begin
rcases lt_trichotomy c 0 with hc | hc | hc,
{
intros ε hε,
set e := ε / |c| with he,
have cnz : c ≠ 0, linarith,
have habsc := abs_pos_iff.mpr cnz,
have he_pos := div_pos hε habsc,
cases hL e he_pos with M hM,
use M, intros n hn, rw he at hM, simp,
have H := hM n hn,
have G := (lt_div_iff' habsc).mp H,
have F := abs_mul c,
set b := a n - α with hb,
have E := F b,
rw hb at E,
have D := mul_sub c (a n) α,
rw D at E,
rw ← hb at E,
linarith,
},
{
intros ε hε,
cases hL ε hε with M hM,
use M, intros n hn, simp,
have H : c * (a n) = 0, norm_num, left, exact hc, rw H,
have G : c * α = 0, norm_num, left, exact hc, rw G,
norm_num, exact hε,
},
{ -- this can be merged with first case
intros ε hε,
set e := ε / c with he,
have he_pos := div_pos hε hc,
cases hL e he_pos with M hM,
use M, intros n hn, rw he at hM, simp,
have H := hM n hn,
have G := (lt_div_iff' hc).mp H,
have F := abs_mul c,
set b := a n - α with hb,
have E := F b,
have D : |c| = c, exact abs_of_pos hc,
rw D at E, rw hb at E,
have C := mul_sub c (a n) α,
rw C at E,
rw ← hb at E,
linarith,
},
done
end
end xena -- hide
|
85ac3057eec5aec469fbf26c24f30b93e8b6dbba | b82c5bb4c3b618c23ba67764bc3e93f4999a1a39 | /src/formal_ml/hahn.lean | a9a1865c308852e5e3304b0b9937402c11698abc | [
"Apache-2.0"
] | permissive | nouretienne/formal-ml | 83c4261016955bf9bcb55bd32b4f2621b44163e0 | 40b6da3b6e875f47412d50c7cd97936cb5091a2b | refs/heads/master | 1,671,216,448,724 | 1,600,472,285,000 | 1,600,472,285,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 138,401 | lean | /-
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import measure_theory.measurable_space
import measure_theory.measure_space
import measure_theory.outer_measure
import measure_theory.lebesgue_measure
import measure_theory.integration
import measure_theory.set_integral
import measure_theory.borel_space
import data.set.countable
import formal_ml.nnreal
import formal_ml.sum
import formal_ml.core
import formal_ml.measurable_space
import formal_ml.semiring
import formal_ml.real_measurable_space
import formal_ml.set
import formal_ml.filter_util
import topology.instances.ennreal
import formal_ml.integral
import formal_ml.int
import formal_ml.with_density_compose_eq_multiply
import formal_ml.classical
/-
This does not prove the classic Hahn decomposition theorem for signed measures.
Instead, it proves a similar theorem for unsigned measures. To understand various
operations on unsigned measures (like the supremum of two measures, the infimum of
two measures, or the "difference" of two measures), it is important to be able
to consider two non-negative measures and partition the space into a set where
the first measure is less than or equal to the second, and a set where the second
is less than or equal to the first. So, given measures μ and ν, we want a measurable
set S such that:
μ.restrict S ≤ ν.restrict S and ν.restrict Sᶜ ≤ μ.restrict Sᶜ.
This means that for any set T ⊆ S, μ T ≤ ν T, and for any U ⊆ Sᶜ, ν U ≤ μ U.
By partitioning the space like so, we can separately consider supremum, infimum,
and difference in each half, and combine them back together. This in turn
helps to prove the Lebesgue-Radon-Nikodym theorem.
-/
lemma nonnegative_fn {α β:Type*} [canonically_ordered_add_monoid β] {f:α → β}:0 ≤ f :=
begin
intro x,
simp,
end
lemma real.add_lt_of_lt_sub {a b c:real}:a < b - c → a + c < b :=
begin
intro A1,
have B1:a + c < (b - c) + c,
{
apply add_lt_add_right,
apply A1,
},
simp at B1,
apply B1,
end
lemma real.lt_sub_of_add_lt {a b c:real}:a + c < b → a < b - c :=
begin
intro A1,
have B1:a + c + (-c) < b + (-c),
{
apply add_lt_add_right,
apply A1,
},
simp at B1,
apply B1,
end
lemma real.le_sub_add {a b c:real}:b ≤ c →
a ≤ a - b + c :=
begin
intros A1,
have B1:a - b + b ≤ a - b + c,
{
apply add_le_add_left,
apply A1,
},
simp at B1,
apply B1,
end
lemma real.lt_of_le_of_add_le_of_le_of_sub_lt {a b c d e:real}:
a + b ≤ c → d ≤ b → c - e < a → d < e :=
begin
intros A1 A2 A3,
have B1:c < a + e,
{
have B1A:(c - e) + e < a + e,
{
apply add_lt_add_right,
apply A3,
},
simp at B1A,
apply B1A,
},
have B2:a + b < a + e,
{
apply lt_of_le_of_lt A1 B1,
},
simp at B2,
apply lt_of_le_of_lt A2 B2,
end
lemma real.lt_of_lt_of_le_of_add_le_of_le_of_sub_lt {a b c d e:real}:
c < e → a + b ≤ c → d ≤ b → 0 < a → d < e :=
begin
intros A1 A2 A3 A4,
apply lt_of_le_of_lt _ A1,
apply le_trans A3,
clear A1 A3,
have B1:0 + c < a + c,
{
simp,
apply A4,
},
rw zero_add at B1,
have B2 := lt_of_le_of_lt A2 B1,
simp at B2,
apply le_of_lt B2,
end
lemma real.lt_of_add_lt_of_pos {a b c:real}:
b + c ≤ a →
0 < b →
c < a :=
begin
intros A1 A2,
have A3:0 + c < b + c,
{
apply add_lt_add_right A2,
},
rw zero_add at A3,
apply lt_of_lt_of_le A3,
apply A1,
end
lemma nnreal.add_lt_of_lt_sub {a b c:nnreal}:a < b - c → a + c < b :=
begin
cases (classical.em (c ≤ b)) with B1 B1,
{
repeat {rw ← nnreal.coe_lt_coe <|> rw nnreal.coe_add},
rw nnreal.coe_sub B1,
apply real.add_lt_of_lt_sub,
},
{
intros A1,
rw nnreal.sub_eq_zero at A1,
exfalso,
simp at A1,
apply A1,
apply le_of_not_le B1,
},
end
lemma nnreal.lt_sub_of_add_lt {a b c:nnreal}:a + c < b → a < b - c :=
begin
intro A1,
have B1:c ≤ b,
{
have B1A := le_of_lt A1,
have B1B:a + c ≤ a + b,
{
have B1BA:b ≤ a + b,
{
rw add_comm,
apply le_add_nonnegative _ _,
},
apply le_trans B1A B1BA,
},
simp at B1B,
apply B1B,
},
revert A1,
repeat {rw ← nnreal.coe_lt_coe <|> rw nnreal.coe_add},
rw nnreal.coe_sub B1,
apply real.lt_sub_of_add_lt,
end
lemma nnreal.le_sub_add {a b c:nnreal}:b ≤ c → c ≤ a →
a ≤ a - b + c :=
begin
repeat {rw ← nnreal.coe_le_coe},
repeat {rw nnreal.coe_add},
intros A1 A2,
repeat {rw nnreal.coe_sub},
apply real.le_sub_add A1,
apply le_trans A1 A2,
end
lemma nnreal.lt_of_add_le_of_le_of_sub_lt {a b c d e:nnreal}:
a + b ≤ c → d ≤ b → c - e < a → d < e :=
begin
rw ← nnreal.coe_le_coe,
rw ← nnreal.coe_le_coe,
rw ← nnreal.coe_lt_coe,
rw ← nnreal.coe_lt_coe,
rw nnreal.coe_add,
cases (le_or_lt e c) with B1 B1,
{
rw nnreal.coe_sub B1,
rw ← nnreal.coe_le_coe at B1,
apply real.lt_of_le_of_add_le_of_le_of_sub_lt,
},
{
rw nnreal.sub_eq_zero (le_of_lt B1),
rw ← nnreal.coe_lt_coe at B1,
apply real.lt_of_lt_of_le_of_add_le_of_le_of_sub_lt B1,
},
end
lemma nnreal.epsilon_half_lt_epsilon {ε:nnreal}: 0 < ε → (ε / 2) < ε :=
begin
rw ← nnreal.coe_lt_coe,
rw ← nnreal.coe_lt_coe,
--rw ← nnreal.coe_two,
rw nnreal.coe_div,
apply epsilon_half_lt_epsilon,
end
lemma nnreal.inv_as_fraction {c:nnreal}:(1)/(c) = (c)⁻¹ :=
begin
rw nnreal.div_def,
rw one_mul,
end
lemma nnreal.lt_of_add_lt_of_pos {a b c:nnreal}:
b + c ≤ a →
0 < b →
c < a :=
begin
--intros A1 A2,
rw ← nnreal.coe_le_coe,
rw ← nnreal.coe_lt_coe,
rw ← nnreal.coe_lt_coe,
rw nnreal.coe_add,
apply real.lt_of_add_lt_of_pos,
end
lemma nnreal.mul_le_mul_of_le_left {a b c:nnreal}:
a ≤ b → c * a ≤ c * b :=
begin
intro A1,
apply ordered_comm_monoid.mul_le_mul_left,
apply A1,
end
lemma with_top.not_none_lt {α:Type*} [preorder α] (a:with_top α):
¬(@has_lt.lt (with_top α) _ (none:with_top α) a):=
begin
intro A1,
rw lt_iff_le_not_le at A1,
cases A1 with A1 A2,
apply A2,
apply with_top.none_le,
end
lemma with_top.not_none_le_some {α:Type*} [partial_order α] (a:α):
¬(@has_le.le (with_top α) _ (none) (some a)):=
begin
intro A1,
have B1:(some a) ≠ (none:with_top α),
{
simp,
},
have B3:(@has_le.le (with_top α) _ (some a) (none)) := with_top.none_le,
have B4 := @le_antisymm (with_top α) _ (some a) (none) B3 A1,
apply B1,
apply B4
end
lemma not_top_eq_some {x:ennreal}:x≠ ⊤ → (∃ (y:nnreal), (y:ennreal) = x) :=
begin
intro A1,
cases x,
{
exfalso,
simp at A1,
apply A1,
},
apply exists.intro x,
refl
end
lemma ennreal.inv_as_fraction {c:ennreal}:(1)/(c) = (c)⁻¹ :=
begin
rw ennreal.div_def,
rw one_mul,
end
lemma ennreal.add_lt_of_lt_sub {a b c:ennreal}:a < b - c → a + c < b :=
begin
--intros AX A1,
cases a;cases b;cases c;try {simp},
{
rw ← ennreal.coe_add,
apply with_top.none_lt_some,
},
{
repeat {rw ← ennreal.coe_sub
<|> rw ennreal.coe_lt_coe
<|> rw ← ennreal.coe_add},
apply nnreal.add_lt_of_lt_sub,
},
end
lemma ennreal.lt_sub_of_add_lt {a b c:ennreal}: a + c < b → a < b - c :=
begin
--intros AX A1,
cases a;cases b;cases c;try {simp},
{
repeat {rw ← ennreal.coe_sub
<|> rw ennreal.coe_lt_coe
<|> rw ← ennreal.coe_add},
apply nnreal.lt_sub_of_add_lt,
},
end
lemma ennreal.eq_zero_or_zero_lt {x:ennreal}:¬(x=0) → (0 < x) :=
begin
intro A1,
have A2:= @lt_trichotomy ennreal _ x 0,
cases A2,
{
exfalso,
apply @ennreal.not_lt_zero x,
apply A2,
},
cases A2,
{
exfalso,
apply A1,
apply A2,
},
{
apply A2,
},
end
lemma ennreal.sub_eq_of_add_of_not_top_of_le {a b c:ennreal}:a = b + c →
c ≠ ⊤ →
c ≤ a → a - c = b :=
begin
intros A1 A4 A2,
cases c,
{
exfalso,
simp at A4,
apply A4,
},
cases a,
{
simp,
cases b,
{
refl,
},
exfalso,
simp at A1,
rw ← ennreal.coe_add at A1,
apply ennreal.top_ne_coe A1,
},
cases b,
{
simp at A1,
exfalso,
apply A1,
},
{
repeat {rw ennreal.some_eq_coe},
rw ← ennreal.coe_sub,
rw ennreal.coe_eq_coe,
repeat {rw ennreal.some_eq_coe at A1},
rw ← ennreal.coe_add at A1,
rw ennreal.coe_eq_coe at A1,
repeat {rw ennreal.some_eq_coe at A2},
rw ennreal.coe_le_coe at A2,
apply nnreal.sub_eq_of_add_of_le A1 A2,
},
end
lemma ennreal.eq_add_of_sub_eq {a b c:ennreal}:b ≤ a →
a - b = c → a = b + c :=
begin
intros A1 A2,
cases a;cases b,
{
simp,
},
{
cases c,
{
simp,
},
exfalso,
simp at A2,
apply A2,
},
{
exfalso,
apply with_top.not_none_le_some _ A1,
},
simp at A2,
rw ← ennreal.coe_sub at A2,
cases c,
{
exfalso,
simp at A2,
apply A2,
},
{
simp,
rw ← ennreal.coe_add,
rw ennreal.coe_eq_coe,
simp at A2,
simp at A1,
apply nnreal.eq_add_of_sub_eq A1 A2,
},
end
lemma ennreal.sub_lt_sub_of_lt_of_le {a b c d:ennreal}:a < b →
c ≤ d →
d ≤ a →
a - d < b - c :=
begin
intros A1 A2 A3,
have B1:(⊤:ennreal) = none := rfl,
have B2:∀ n:nnreal, (some n) = n,
{
intro n,
refl,
},
cases a,
{
exfalso,
apply @with_top.not_none_lt nnreal _ b A1,
},
cases d,
{
exfalso,
apply @with_top.not_none_le_some nnreal _ a A3,
},
cases c,
{
exfalso,
apply @with_top.not_none_le_some nnreal _ d A2,
},
cases b,
{
simp,
rw ← ennreal.coe_sub,
rw B1,
rw ← B2,
apply with_top.none_lt_some,
},
repeat {rw B2},
repeat {rw ← ennreal.coe_sub},
rw ennreal.coe_lt_coe,
apply nnreal.sub_lt_sub_of_lt_of_le,
repeat {rw B2 at A1},
rw ennreal.coe_lt_coe at A1,
apply A1,
repeat {rw B2 at A2},
rw ennreal.coe_le_coe at A2,
apply A2,
repeat {rw B2 at A3},
rw ennreal.coe_le_coe at A3,
apply A3,
end
lemma ennreal.le_sub_add {a b c:ennreal}:b ≤ c → c ≤ a →
a ≤ a - b + c :=
begin
cases a;cases b;cases c;try {simp},
rw ← ennreal.coe_sub,
rw ← ennreal.coe_add,
rw ennreal.coe_le_coe,
apply nnreal.le_sub_add,
end
lemma ennreal.add_sub_cancel {a b:ennreal}:b < ⊤ → a + b - b = a :=
begin
cases a;cases b;try {simp},
end
lemma ennreal.exists_coe {x:ennreal}:x < ⊤ → ∃ v:nnreal, x = v :=
begin
cases x;try {simp},
end
lemma ennreal.lt_of_add_le_of_le_of_sub_lt {a b c d e:ennreal}:c < ⊤ →
a + b ≤ c → d ≤ b → c - e < a → d < e :=
begin
cases c,simp,
cases a;cases b;cases d;cases e;try {simp},
rw ← ennreal.coe_add,
rw ← ennreal.coe_sub,
rw ennreal.coe_le_coe,
rw ennreal.coe_lt_coe,
apply nnreal.lt_of_add_le_of_le_of_sub_lt,
end
lemma ennreal.coe_sub_lt_self {a:nnreal} {b:ennreal}:
0 < a → 0 < b →
(a:ennreal) - b < (a:ennreal) :=
begin
cases b;simp,
intros A1 A2,
rw ← ennreal.coe_sub,
rw ennreal.coe_lt_coe,
apply nnreal.sub_lt_self A1 A2,
end
lemma ennreal.epsilon_half_lt_epsilon {ε:ennreal}: ε < ⊤ → 0 < ε → (ε / 2) < ε :=
begin
cases ε;simp,
--rw ennreal.coe_div,
have B1:((2:nnreal):ennreal) = 2 := rfl,
rw ← B1,
rw ← ennreal.coe_div,
rw ennreal.coe_lt_coe,
apply nnreal.epsilon_half_lt_epsilon,
intro C1,
have C2:(0:nnreal) < (2:nnreal),
{
apply zero_lt_two,
},
rw C1 at C2,
simp at C2,
apply C2,
end
lemma ennreal.lt_of_lt_top_of_add_lt_of_pos {a b c:ennreal}:a < ⊤ →
b + c ≤ a →
0 < b →
c < a :=
begin
cases a;simp;
cases b;cases c;simp,
rw ← ennreal.coe_add,
rw ennreal.coe_le_coe,
apply nnreal.lt_of_add_lt_of_pos,
end
/-
enneral could be a linear_ordered_comm_group_with_zero,
and therefore a ordered_comm_monoid.
HOWEVER, I am not sure how to integrate this.
I am going to just prove the basic results from the class.
NOTE that this is strictly more general than
ennreal.mul_le_mul_left.
-/
lemma ennreal.mul_le_mul_of_le_left {a b c:ennreal}:
a ≤ b → c * a ≤ c * b :=
begin
cases a;cases b;cases c;simp;
try {
cases (classical.em (c=0)) with B1 B1,
{
subst c,
simp,
},
{
have B2:(c:ennreal) * ⊤ = ⊤,
{
rw ennreal.mul_top,
rw if_neg,
intro B2A,
apply B1,
simp at B2A,
apply B2A,
},
rw B2,
{apply le_refl _ <|> simp},
},
},
{
cases (classical.em (b=0)) with B1 B1,
{
subst b,
simp,
},
{
have B2:⊤ * (b:ennreal) = ⊤,
{
rw ennreal.top_mul,
rw if_neg,
intro B2A,
apply B1,
simp at B2A,
apply B2A,
},
rw B2,
simp,
},
},
rw ← ennreal.coe_mul,
rw ← ennreal.coe_mul,
rw ennreal.coe_le_coe,
apply nnreal.mul_le_mul_of_le_left,
end
lemma ennreal.inverse_le_of_le {a b:ennreal}:
a ≤ b →
b⁻¹ ≤ a⁻¹ :=
begin
intros A2,
cases (classical.em (a = 0)) with A1 A1,
{
subst a,
simp,
},
cases b,
{
simp,
},
cases (classical.em (b = 0)) with C1 C1,
{
subst b,
simp at A2,
exfalso,
apply A1,
apply A2,
},
simp,
simp at A2,
have B1: (a⁻¹ * b⁻¹) * a ≤ (a⁻¹ * b⁻¹) * b,
{
apply ennreal.mul_le_mul_of_le_left A2,
},
rw mul_comm a⁻¹ b⁻¹ at B1,
rw mul_assoc at B1,
rw ennreal.inv_mul_cancel at B1,
rw mul_comm (b:ennreal)⁻¹ a⁻¹ at B1,
rw mul_assoc at B1,
rw mul_one at B1,
rw ennreal.inv_mul_cancel at B1,
rw mul_one at B1,
apply A2,
{
simp [C1],
},
{
simp,
},
{
apply A1,
},
{
rw ← lt_top_iff_ne_top,
apply lt_of_le_of_lt A2,
simp,
},
end
lemma ennreal.nat_coe_add {a b:ℕ}:(a:ennreal) + (b:ennreal) =
((@has_add.add nat _ a b):ennreal) :=
begin
simp,
end
lemma ennreal.nat_coe_le_coe {a b:ℕ}:(a:ennreal) ≤ (b:ennreal) ↔ (a ≤ b) :=
begin
have B1:(a:ennreal) = ((a:nnreal):ennreal),
{
simp,
},
have B2:(b:ennreal) = ((b:nnreal):ennreal),
{
simp,
},
rw B1,
rw B2,
rw ennreal.coe_le_coe,
split;intros A1,
{
simp at A1,
apply A1,
},
{
simp,
apply A1,
},
end
lemma measures_equal {Ω:Type*} {M:measurable_space Ω}
(μ ν:measure_theory.measure Ω) [measure_theory.finite_measure ν]:
(μ ≤ ν) →
(μ set.univ = ν set.univ) →
(μ = ν) :=
begin
intros A3 A4,
apply measure_theory.measure.ext,
intros S A5,
have B3:is_measurable (Sᶜ),
{
apply is_measurable.compl,
apply A5,
},
apply le_antisymm,
{
apply A3,
apply A5,
},
{
apply @le_of_not_lt ennreal _,
intro A6,
have A7:μ (Sᶜ) ≤ ν (Sᶜ),
{
apply A3,
apply B3,
},
have B1:S ∪ (Sᶜ) = set.univ ,
{
simp,
},
have B2:disjoint S (Sᶜ),
{
unfold disjoint,
simp,
},
have A8:μ set.univ = μ S + μ (Sᶜ),
{
rw ← B1,
apply measure_theory.measure_union,
apply B2,
apply A5,
apply B3,
},
have A9:ν set.univ = ν S + ν (Sᶜ),
{
rw ← B1,
apply measure_theory.measure_union,
apply B2,
apply A5,
apply B3,
},
have A10:μ set.univ < ν set.univ,
{
rw A8,
rw A9,
apply ennreal.add_lt_add_of_lt_of_le_of_lt_top,
{
apply measure_theory.measure_lt_top,
},
{
apply A7,
},
{
apply A6,
},
},
rw A4 at A10,
apply lt_irrefl _ A10,
},
end
lemma measurable_supr_of_measurable {Ω:Type*} [M:measurable_space Ω]
{h:ℕ → Ω → ennreal}:
(∀ n:ℕ, measurable (h n)) →
(measurable (supr h)) :=
begin
intros A1,
apply is_ennreal_measurable_intro_Ioi,
intro x,
have A3:((supr h) ⁻¹' {y : ennreal | x < y}) =⋃ (n:ℕ), (h n) ⁻¹' {y:ennreal | x < y},
{
simp,
ext ω,
have A3B:supr h ω = supr (λ n, h n ω),
{
apply supr_apply,
},
split;
intros A3A;simp;simp at A3A,
{
rw A3B at A3A,
rw @lt_supr_iff ennreal _ at A3A,
apply A3A,
},
{
cases A3A with i A3A,
apply lt_of_lt_of_le A3A,
rw A3B,
apply @le_supr ennreal ℕ _,
},
},
rw A3,
apply is_measurable.Union,
intro b,
apply A1 b,
apply is_ennreal_is_measurable_intro_Ioi,
end
lemma monotone_set_indicator {Ω β:Type*} [has_zero β] [preorder β] {S:set Ω}:
monotone ((set.indicator S):(Ω → β) → (Ω → β)) :=
begin
unfold monotone,
intros f g A1,
rw le_func_def2,
intro ω,
cases (classical.em (ω ∈ S)) with A2 A2,
{
rw set.indicator_of_mem A2,
rw set.indicator_of_mem A2,
apply A1,
},
{
rw set.indicator_of_not_mem A2,
rw set.indicator_of_not_mem A2,
},
end
lemma supr_with_density_apply_eq_with_density_supr_apply {Ω:Type*} [measurable_space Ω] {μ:measure_theory.measure Ω}
{h:ℕ → Ω → ennreal} {S:set Ω}:
is_measurable S →
(∀ n:ℕ, measurable (h n)) →
(monotone h) →
supr (λ n:ℕ, μ.with_density (h n) S) = μ.with_density (supr h) S :=
begin
intros A1 A2 A3,
have A4:(λ n, μ.with_density (h n) S) = (λ n, μ.integral (set.indicator S (h n))),
{
apply funext,
intro n,
rw measure_theory.with_density_apply2,
--apply A2 n,
apply A1,
},
rw A4,
clear A4,
rw measure_theory.with_density_apply2,
rw supr_indicator,
rw measure_theory.integral_supr,
{
intro n,
apply measurable_set_indicator,
apply A1,
apply A2 n,
},
{
have B1:(λ (n:ℕ), set.indicator S (h n)) = (set.indicator S) ∘ h := rfl,
rw B1,
apply @monotone.comp ℕ (Ω → ennreal) (Ω → ennreal) _ _ _,
apply @monotone_set_indicator Ω ennreal _ _,
apply A3,
},
{
apply A1,
},
end
lemma with_density_supr_apply_le {Ω:Type*} [measurable_space Ω] {μ ν:measure_theory.measure Ω}
{h:ℕ → Ω → ennreal} {S:set Ω}:
is_measurable S →
(∀ n:ℕ, measurable (h n)) →
(monotone h) →
(∀ n:ℕ, μ.with_density (h n) ≤ ν) →
μ.with_density (supr h) S ≤ ν S :=
begin
intros A1 A2 A3 A4,
rw ← supr_with_density_apply_eq_with_density_supr_apply A1 A2 A3,
apply @supr_le ennreal ℕ _,
intro n,
apply A4,
apply A1,
end
-- So, although there is a LOT below, this is the easiest third of the
-- Radon-Nikodym derivative: namely, that if we have a monotone sequence
-- of functions, the sequence will be less than or equal to ν.
lemma with_density_supr_le {Ω:Type*} [measurable_space Ω] {μ ν:measure_theory.measure Ω}
{h:ℕ → Ω → ennreal}:
(∀ n:ℕ, measurable (h n)) →
(monotone h) →
(∀ n:ℕ, μ.with_density (h n) ≤ ν) →
μ.with_density (supr h) ≤ ν :=
begin
intros A1 A2 A3,
intros S A4,
apply with_density_supr_apply_le A4 A1 A2 A3,
end
lemma measure_of_monotone' {Ω:Type*} [measurable_space Ω] {S:set Ω}
:is_measurable S →
monotone (λ μ:measure_theory.measure Ω, μ S) :=
begin
intros A0 μ ν A1,
simp,
rw measure.apply,
rw measure.apply,
apply A1,
apply A0,
end
-- Compare with ennreal.has_sub.
-- I think that this is the equivalent of (a - b)⁺, if
-- a and b were signed measures.
-- Specifically, note that if you have α = {1,2}, and
-- a {1} = 2, a {2} = 0, and
-- b {2} = 2, b {1} = 0, then
-- (a - b) {1, 2} = 2. However, if a ≤ b, and
-- a set.univ ≠ ⊤, then (a - b) + b = a.
-- Also, a - b ≤ a.
noncomputable instance measure_theory.measure.has_sub {α:Type*}
[measurable_space α]:has_sub (measure_theory.measure α) := ⟨λa b, Inf {d | a ≤ d + b}⟩
lemma measure_theory.measure.sub_def {α:Type*}
[measurable_space α] {a b:measure_theory.measure α}:
(a - b) = Inf {d | a ≤ d + b} := rfl
def sub_pred {α:Type*} (f:ℕ → set α):ℕ → set α
| (nat.succ n) := f n.succ \ f n
| 0 := f 0
lemma sub_pred_subset {α:Type*} (f:ℕ → set α) {n:ℕ}:
sub_pred f n ⊆ f n :=
begin
cases n,
{
unfold sub_pred,
},
{
unfold sub_pred,
apply set.diff_subset,
},
end
lemma sub_pred_subset' {α:Type*} (f:ℕ → set α) {n:ℕ} {x:α}:
x∈ sub_pred f n → x ∈ f n :=
begin
intro A1,
have A2:sub_pred f n ⊆ f n := @sub_pred_subset α f n,
rw set.subset_def at A2,
apply A2 _ A1,
end
def prefix_union {α:Type*} (f:ℕ → set α) (n:ℕ):=
(⋃ (m∈ finset.range n.succ), f m )
lemma prefix_union_def {α:Type*} (f:ℕ → set α) (n:ℕ):
(⋃ (m∈ finset.range n.succ), f m )= prefix_union f n := rfl
lemma prefix_union_zero {α:Type*} (f:ℕ → set α):
(prefix_union f 0) = f 0 :=
begin
rw ← prefix_union_def,
apply set.ext,
intros a,
split;intros A1,
{
simp at A1,
apply A1,
},
{
simp,
apply A1,
},
end
lemma prefix_union_succ {α:Type*} (f:ℕ → set α) (n:ℕ):
(prefix_union f n.succ) = (prefix_union f n) ∪ f n.succ :=
begin
rw ← prefix_union_def,
rw ← prefix_union_def,
ext,
split;intros A1;simp;simp at A1,
{
cases A1 with m A1,
cases (classical.em (m = nat.succ n)) with A2 A2,
{
subst m,
right,
apply A1.right,
},
{
left,
apply exists.intro m,
split,
apply lt_of_le_of_ne,
apply lt_succ_imp_le m (nat.succ n) A1.left,
apply A2,
apply A1.right,
},
},
{
cases A1 with A1 A1,
{
cases A1 with m A1,
apply exists.intro m,
split,
apply lt_trans A1.left,
apply nat.lt.base,
apply A1.right,
},
{
apply exists.intro (nat.succ n),
split,
apply nat.lt.base,
apply A1,
},
},
end
lemma prefix_union_def2 {α:Type*} (f:ℕ → set α) (n:ℕ):
(⨆ (m:ℕ) (H:m ≤ n), f m)=prefix_union f n :=
begin
unfold prefix_union,
ext,split;intros A1;simp at A1;simp,
{
cases A1 with m A1,
apply exists.intro m,
split,
apply nat.lt_succ_of_le A1.left,
apply A1.right,
},
{
cases A1 with m A1,
apply exists.intro m,
split,
apply lt_succ_imp_le m n A1.left,
apply A1.right,
},
end
lemma prefix_union_contains {α:Type*} (f:ℕ → set α) {m n:ℕ}:
m ≤ n →
f m ⊆ prefix_union f n :=
begin
intro A1,
rw ← prefix_union_def2,
rw set.subset_def,
intros ω A2,
simp,
apply exists.intro m,
apply and.intro A1 A2,
end
lemma prefix_union_contains' {α:Type*} (f:ℕ → set α) {m n:ℕ} {x:α}:
m ≤ n →
x∈ f m → x ∈ prefix_union f n :=
begin
intros A1 A2,
have A3 := prefix_union_contains f A1,
rw set.subset_def at A3,
apply A3 x A2,
end
lemma prefix_union_sub_pred {α:Type*} (f:ℕ → set α):
prefix_union (sub_pred f) = prefix_union f :=
begin
apply funext,
intro n,
induction n,
{
repeat {rw prefix_union_zero},
unfold sub_pred,
},
{
rw prefix_union_succ,
rw prefix_union_succ f,
rw n_ih,
ext;split;intros A1;simp;simp at A1;cases A1 with A1 A1;
try {
apply or.inl A1,
},
{
right,
apply sub_pred_subset',
apply A1,
},
{
cases (classical.em (x ∈ f n_n)) with A2 A2,
{
left,
apply prefix_union_contains' f _ A2,
apply le_refl,
},
{
right,
unfold sub_pred,
simp,
apply and.intro A1 A2,
},
},
},
end
lemma Union_sub_pred {α:Type*} {f:ℕ → set α}:
set.Union (sub_pred f) = set.Union f :=
begin
apply set.ext,
intro a,
split;intros A1;simp at A1;simp;cases A1 with n A1,
{
apply exists.intro n,
apply sub_pred_subset',
apply A1,
},
{
have A2:a ∈ prefix_union f n,
{
apply prefix_union_contains' f (le_refl n) A1,
},
rw ← prefix_union_sub_pred at A2,
rw ← prefix_union_def at A2,
simp at A2,
cases A2 with n A2,
apply exists.intro n,
apply A2.right,
},
end
lemma mem_sub_pred_succ {α:Type*} {n:ℕ} {x:α} {f:ℕ → set α}:
x ∉ f n → (x ∈ f (nat.succ n)) →
x ∈ sub_pred f (nat.succ n) :=
begin
intros A1 A2,
unfold sub_pred,
apply and.intro A2 A1,
end
lemma not_mem_of_sub_pred_succ {α:Type*} {n:ℕ} {x:α} {f:ℕ → set α}:
x ∈ sub_pred f (nat.succ n) → x ∉ f n :=
begin
intros A1,
unfold sub_pred at A1,
simp at A1,
apply A1.right,
end
lemma sub_pred_pairwise_disjoint_helper {α:Type*} {f:ℕ → set α} {m n:ℕ}:
(monotone f) →
m < n →
disjoint (sub_pred f m) (sub_pred f n) :=
begin
intros A1 A2,
rw set.disjoint_right,
intros x A4 A3,
cases n,
{
apply nat.not_lt_zero m A2,
},
have A5 := lt_succ_imp_le m n A2,
have A6:f m ⊆ f n,
{
apply A1 A5,
},
have A7:sub_pred f m ⊆ f m,
{
apply sub_pred_subset,
},
have A8:x ∈ f n,
{
have A8:=set.subset.trans A7 A6,
rw set.subset_def at A8,
apply A8 x A3,
},
apply not_mem_of_sub_pred_succ A4 A8,
end
lemma sub_pred_pairwise_disjoint {α:Type*} {f:ℕ → set α}:
(monotone f) →
pairwise (disjoint on (sub_pred f)) :=
begin
intro A1,
intros m n A2,
have A3:disjoint (sub_pred f m) (sub_pred f n),
{
have A3A:=lt_trichotomy m n,
cases A3A with A3A A3A,
{
apply sub_pred_pairwise_disjoint_helper A1 A3A,
},
cases A3A with A3A A3A,
{
exfalso,
apply A2,
apply A3A,
},
{
apply set.disjoint.symm,
apply sub_pred_pairwise_disjoint_helper A1 A3A,
},
},
apply A3,
end
lemma measure_finset_sum {α:Type*}
[measurable_space α] {μ:measure_theory.measure α}
{f:ℕ → set α} {n:ℕ}:(∀ n, is_measurable (f n)) →
(pairwise (disjoint on f)) →
(finset.range n).sum (λ m, μ (f m)) =
μ (⋃ (m∈ finset.range n), f m) :=
begin
intros A1 A2,
rw measure_theory.measure_bUnion_finset,
{
intros m B1 n B2 B3,
apply A2,
apply B3,
},
{
intros m C1,
apply A1,
},
end
lemma union_range_sub_pred {α:Type*} {f:ℕ → set α} {n:ℕ}:
(⋃ (m : ℕ) (H : m ∈ finset.range n), sub_pred f m) =
(⋃ (m : ℕ) (H : m ∈ finset.range n), f m) :=
begin
cases n,
{
simp,
},
{
rw prefix_union_def,
rw prefix_union_def,
rw prefix_union_sub_pred,
},
end
lemma is_measurable_sub_pred {α:Type*} [measurable_space α]
{f:ℕ → set α} {n:ℕ}:
(∀ m, is_measurable (f m)) → is_measurable (sub_pred f n) :=
begin
intro A1,
cases n,
{
unfold sub_pred,
apply A1,
},
{
unfold sub_pred,
apply is_measurable.diff,
repeat {apply A1},
},
end
lemma union_finset_range_monotone {α:Type*} {f:ℕ → set α} {n:ℕ}:
monotone f →
(⋃ m ∈ finset.range (n.succ), f m) = f n :=
begin
intro A1,
ext,split;intros A2,
{
simp at A2,
cases A2 with m A2,
have A3 := lt_succ_imp_le m n A2.left,
have A4 := A1 A3,
have A5:(f m ⊆ f n)= (f m ≤ f n ):= rfl,
rw ← A5 at A4,
rw set.subset_def at A4,
apply A4,
apply A2.right,
},
{
simp,
apply exists.intro n,
split,
apply nat.lt.base,
apply A2,
},
end
def le_on_subsets {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):Prop :=
is_measurable X ∧
(∀ X':set α, X'⊆ X → is_measurable X' → μ X' ≤ ν X')
lemma le_on_subsets_def {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):
le_on_subsets μ ν X =
(is_measurable X ∧
(∀ X':set α, X'⊆ X → is_measurable X' → μ X' ≤ ν X')) := rfl
lemma le_on_subsets_is_measurable {α:Type*} [measurable_space α]
{μ ν:measure_theory.measure α} {X:set α}:
le_on_subsets μ ν X →
(is_measurable X) :=
begin
intros A1,
rw le_on_subsets_def at A1,
apply A1.left,
end
lemma le_on_subsets_self {α:Type*} [measurable_space α]
{μ ν:measure_theory.measure α} {X:set α}:
le_on_subsets μ ν X →
μ X ≤ ν X :=
begin
intro A1,
rw le_on_subsets_def at A1,
apply A1.right X (le_refl X) A1.left,
end
lemma le_on_subsets_empty {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):
le_on_subsets μ ν ∅ :=
begin
rw le_on_subsets_def,
split,
{
apply is_measurable.empty,
},
{
intros X' A1 A2,
have A3 := empty_of_subset_empty X' A1,
subst X',
simp,
},
end
lemma le_on_subsets_union {α:Type*} [measurable_space α]
{μ ν:measure_theory.measure α} {X Y:set α}:
le_on_subsets μ ν X →
le_on_subsets μ ν Y →
le_on_subsets μ ν (X ∪ Y) :=
begin
repeat {rw le_on_subsets_def},
intros A1 A2,
split,
{
apply is_measurable.union A1.left A2.left,
},
{
intros X' A3 A4,
rw @measure_theory.measure_eq_inter_diff _ _ μ _ X A4 A1.left,
rw @measure_theory.measure_eq_inter_diff _ _ ν _ X A4 A1.left,
have A5:X' ∩ X ⊆ X := set.inter_subset_right X' X,
have A6:X' \ X ⊆ Y,
{
rw set.subset_def,
intros a A6A,
rw set.subset_def at A3,
simp at A6A,
have A6B := A3 a A6A.left,
simp at A6B,
cases A6B,
{
exfalso,
apply A6A.right,
apply A6B,
},
{
apply A6B,
},
},
have A7:is_measurable (X' ∩ X) := is_measurable.inter A4 A1.left,
have A8:is_measurable (X' \ X) := is_measurable.diff A4 A1.left,
have A9:=A1.right (X' ∩ X) A5 A7,
have A10:=A2.right (X' \ X) A6 A8,
apply @add_le_add ennreal _ _ _ _ _ A9 A10,
},
end
lemma le_on_subsets_subset {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X Y:set α):
le_on_subsets μ ν X →
Y ⊆ X →
is_measurable Y →
le_on_subsets μ ν Y :=
begin
repeat {rw le_on_subsets_def},
intros A1 A2 A3,
split,
apply A3,
intros X' A4 A5,
apply A1.right X' (set.subset.trans A4 A2) A5,
end
lemma le_on_subsets_diff {α:Type*} [measurable_space α]
{μ ν:measure_theory.measure α} {X Y:set α}:
le_on_subsets μ ν X →
le_on_subsets μ ν Y →
le_on_subsets μ ν (X \ Y) :=
begin
intros A1 A2,
apply le_on_subsets_subset μ ν X (X \ Y) A1,
{
apply set.diff_subset,
},
{
apply is_measurable.diff
(le_on_subsets_is_measurable A1)
(le_on_subsets_is_measurable A2),
},
end
lemma le_on_subsets_m_Union {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) {f:ℕ → set α}:
monotone f →
(∀ n:ℕ, le_on_subsets μ ν (f n)) →
(le_on_subsets μ ν (set.Union f)) :=
begin
intros A1 A2,
have A3:∀ n, le_on_subsets μ ν ((sub_pred f) n),
{
intros n,
cases n,
{
unfold sub_pred,
apply A2,
},
{
unfold sub_pred,
apply le_on_subsets_diff,
apply A2,
apply A2,
},
},
rw ← Union_sub_pred,
rw le_on_subsets_def,
split,
{
apply is_measurable.Union,
intro n,
apply le_on_subsets_is_measurable (A3 n),
},
{
intros X' A4 A5,
have D1:pairwise (disjoint on λ (i : ℕ), X' ∩ sub_pred f i),
{
intros m n C1,
have C2:disjoint (X' ∩ sub_pred f m) (X' ∩ sub_pred f n),
{
rw set.inter_comm,
apply set.disjoint_inter_left,
apply set.disjoint_inter_right,
apply sub_pred_pairwise_disjoint A1,
apply C1,
},
apply C2,
},
have D2:∀ n, is_measurable (X' ∩ (sub_pred f n)),
{
intro n,
apply is_measurable.inter A5 (le_on_subsets_is_measurable (A3 n)),
},
have A6:X' = ⋃ n, X' ∩ (sub_pred f n),
{
ext,split;intros A4A,
{
simp,
apply and.intro A4A,
rw set.subset_def at A4,
have A4B := A4 x A4A,
simp at A4B,
apply A4B,
},
{
simp at A4A,
apply A4A.left,
},
},
rw A6,
repeat {rw measure_theory.measure_Union},
apply @tsum_le_tsum ennreal ℕ _ _ _,
{
intro b,
have B1 := A3 b,
rw le_on_subsets_def at B1,
apply B1.right,
apply set.inter_subset_right,
apply is_measurable.inter A5 B1.left,
},
repeat {
apply ennreal.summable,
},
apply D1,
apply D2,
apply D1,
apply D2,
},
end
lemma le_measurable_add {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) {X Y:set α}:
μ X < ⊤ →
μ Y < ⊤ →
is_measurable X →
is_measurable Y →
μ X ≤ ν X →
μ Y ≤ ν Y →
disjoint X Y →
ν (X ∪ Y) - μ (X ∪ Y) = (ν X - μ X) + (ν Y - μ Y) :=
begin
intros A1 A2 A3 A4 A5 A6 A7,
rw measure_theory.measure_union A7 A3 A4,
rw measure_theory.measure_union A7 A3 A4,
rw ennreal.add_sub_add_eq_sub_add_sub A1 A2 A5 A6,
end
lemma le_on_subsets_add {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) {X Y:set α}:
μ X < ⊤ →
μ Y < ⊤ →
le_on_subsets μ ν X → le_on_subsets μ ν Y →
disjoint X Y →
ν (X ∪ Y) - μ (X ∪ Y) = (ν X - μ X) + (ν Y - μ Y) :=
begin
intros A1 A2 A5 A6 A7,
have A3 := le_on_subsets_is_measurable A5,
have A4 := le_on_subsets_is_measurable A6,
apply le_measurable_add μ ν A1 A2 A3 A4
(le_on_subsets_self A5) (le_on_subsets_self A6) A7,
end
--This is a function that is equivalent to the above if
--ν ≤ μ and ν is finite (ν set.univ ≠ ⊤).
--This definition is "wrong", in the sense that the
--definition below is closer to subtraction.
--This definition falls apart unless ν ≤ μ.
noncomputable def measure_sub_fn {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):Π (s:set α),is_measurable s → ennreal :=
λ (S:set α) (H:is_measurable S), (μ S - ν S)
--A better variant of measure_sub_fn.
--This definition is valid even if ¬(ν ≤ μ).
noncomputable def measure_sub_fn' {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):Π (s:set α),is_measurable s → ennreal :=
λ (S:set α) (H:is_measurable S),
⨆ (S' ⊆ S) (H2:le_on_subsets ν μ S'), (μ S' - ν S')
lemma measure_sub_fn_def {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):
measure_sub_fn μ ν = λ (S:set α) (H:is_measurable S), (μ S - ν S) := rfl
lemma measure_sub_fn_def' {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):measure_sub_fn' μ ν =
λ (S:set α) (H:is_measurable S),
⨆ (S' ⊆ S) (H2:le_on_subsets ν μ S'), (μ S' - ν S') := rfl
lemma measure_sub_fn_apply {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (s:set α) (H:is_measurable s):
measure_sub_fn μ ν s H = (μ s - ν s) := rfl
lemma measure_sub_fn_apply' {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (s:set α) (H:is_measurable s):
measure_sub_fn' μ ν s H =
⨆ (S' ⊆ s) (H2:le_on_subsets ν μ S'), (μ S' - ν S') := rfl
lemma measure_sub_fn_apply_empty {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):
(measure_sub_fn μ ν) ∅ is_measurable.empty = 0 :=
begin
rw measure_sub_fn_apply,
rw measure_theory.measure_empty,
rw measure_theory.measure_empty,
rw ennreal.sub_zero,
end
lemma measure_sub_fn_apply_empty' {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):
(measure_sub_fn' μ ν) ∅ is_measurable.empty = 0 :=
begin
rw measure_sub_fn_apply',
apply le_antisymm,
{
apply @supr_le ennreal _ _,
intro S',
apply @supr_le ennreal _ _,
intro A1,
apply @supr_le ennreal _ _,
intros A2,
have A3:= empty_of_subset_empty S' A1,
subst S',
simp,
},
{
simp,
},
end
lemma sub_eq_supr_le {x y:ennreal}:
x - y = (⨆ (H:y ≤ x), x) - (⨆ (H:y ≤ x), y) :=
begin
cases classical.em (y ≤ x) with A1 A1,
{
repeat {rw supr_prop_def A1},
},
{
repeat {rw supr_prop_false A1},
simp,
apply le_of_not_le A1,
},
end
/-
This only works if the sum of g is finite.
The consequence of this is that f minus g
is only well-defined if either f or g.
-/
lemma ennreal.tsum_sub {f:ℕ → ennreal} {g:ℕ → ennreal}:
(∑' i, g i) ≠ ⊤ → (g ≤ f) → (∑' i, (f i - g i)) = (∑' i, f i) - (∑' i, g i) :=
begin
intros A1 B2,
let h:ℕ → ennreal := (λ i, f i - g i),
begin
have B1:h = (λ i, f i - g i) := rfl,
have A2:(∑' i, (h i) + (g i))=(∑' i, h i) + (∑' i, g i),
{
apply tsum_add,
apply ennreal.summable,
apply ennreal.summable,
},
have A3:g ≤ (h + g),
{
rw B1,
rw le_func_def2,
intro n,
simp,
rw ennreal.sub_add_cancel_of_le,
apply B2,
apply B2,
},
have A4:(∑' i, g i) ≤ (∑' i, (h i) + (g i)),
{
apply @tsum_le_tsum ennreal ℕ _ _ _,
{
intro n,
apply A3,
},
apply ennreal.summable,
apply ennreal.summable,
},
have A5:(∑' i, (h i) + (g i))-(∑' i, g i)=(∑' i, h i),
{
apply ennreal.sub_eq_of_add_of_not_top_of_le A2 A1 A4,
},
have A6:(λ i, (h i) + (g i)) = f,
{
apply funext,
intro n,
rw B1,
simp,
rw ennreal.sub_add_cancel_of_le,
apply B2,
},
rw A6 at A5,
rw B1 at A5,
symmetry,
apply A5,
end
end
lemma measure_sub_fn_m_Union {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (H:ν ≤ μ)
[H2:measure_theory.finite_measure ν]:
(∀ (g : ℕ → set α) (h : ∀ (i : ℕ), is_measurable (g i)),
pairwise (disjoint on g) →
((measure_sub_fn μ ν) (⋃ (i : ℕ), g i) (M.is_measurable_Union g h)) =
∑' (i : ℕ), (measure_sub_fn μ ν) (g i) (h i)) :=
begin
intros g A1 A2,
have A5:(λ i, ν (g i)) = (λ i, ν.to_outer_measure.measure_of (g i)) := rfl,
have A6:(λ i, μ (g i)) = (λ i, μ.to_outer_measure.measure_of (g i)) := rfl,
rw measure_sub_fn_apply,
have A3:(λ n:ℕ, (measure_sub_fn μ ν (g n) (A1 n)))
=(λ n:ℕ, (μ (g n)) - (ν (g n))),
{
apply funext,
intro n,
rw measure_sub_fn_apply,
},
rw A3,
clear A3,
have A4:(∑' (n:ℕ), (μ (g n))-(ν (g n))) =
(∑' (n:ℕ), (μ (g n)))-
(∑' (n:ℕ), (ν (g n))),
{
apply ennreal.tsum_sub,
{
rw A5,
rw ← ν.m_Union A1 A2,
apply measure_theory.measure_ne_top,
},
{
rw le_func_def2,
intro i,
apply H,
apply A1,
},
},
rw A4,
repeat {rw measure.apply},
rw ν.m_Union A1 A2,
rw μ.m_Union A1 A2,
rw ← A5,
rw ← A6,
end
--TODO:Remove if possible. The theorems from the Hahn decomposition cover this.
noncomputable def measure_sub {α:Type*} [M:measurable_space α]
{μ ν:measure_theory.measure α} (H:ν ≤ μ)
[H2:measure_theory.finite_measure ν]:measure_theory.measure α := @measure_theory.measure.of_measurable α M (measure_sub_fn μ ν) (measure_sub_fn_apply_empty μ ν) (measure_sub_fn_m_Union μ ν H)
lemma measure_sub_def {α:Type*} [M:measurable_space α]
{μ ν:measure_theory.measure α} (H:ν ≤ μ) [H2:measure_theory.finite_measure ν]
:measure_sub H = @measure_theory.measure.of_measurable α M (measure_sub_fn μ ν) (measure_sub_fn_apply_empty μ ν) (measure_sub_fn_m_Union μ ν H) := rfl
lemma measure_sub_apply {α:Type*} [M:measurable_space α]
{μ ν:measure_theory.measure α} (H:ν ≤ μ)
[H2:measure_theory.finite_measure ν] {S:set α} (H3:is_measurable S):
measure_sub H S = μ S - ν S :=
begin
rw measure_sub_def,
rw measure_theory.measure.of_measurable_apply,
rw measure_sub_fn_apply,
apply H3,
end
lemma measure_theory.measure.le_of_add_le_add_left {α:Type*}
[M:measurable_space α]
{μ ν₁ ν₂:measure_theory.measure α} [measure_theory.finite_measure μ]:
μ + ν₁ ≤ μ + ν₂ → ν₁ ≤ ν₂ :=
begin
intros A2,
rw measure_theory.measure.le_iff,
intros S B1,
rw measure_theory.measure.le_iff at A2,
have A3 := A2 S B1,
simp at A3,
apply ennreal.le_of_add_le_add_left _ A3,
apply measure_theory.measure_lt_top,
end
lemma measure_theory.measure.le_of_add_le_add_right
{α:Type*} [M:measurable_space α]
{μ₁ ν μ₂:measure_theory.measure α} [measure_theory.finite_measure ν]:
(μ₁ + ν ≤ μ₂ + ν) → (μ₁ ≤ μ₂) :=
begin
intros A2,
rw add_comm μ₁ ν at A2,
rw add_comm μ₂ ν at A2,
apply measure_theory.measure.le_of_add_le_add_left A2,
end
def measure_theory.measure.is_support {α:Type*} [measurable_space α]
(μ:measure_theory.measure α) (S:set α):Prop := is_measurable S ∧ μ (Sᶜ) = 0
noncomputable def scale_measure_fn {α:Type*}
[measurable_space α] (x:ennreal)
(μ:measure_theory.measure α)
(S:set α) (H:is_measurable S):ennreal := x * μ S
noncomputable def scale_measure {α:Type*}
[M:measurable_space α] (x:ennreal)
(μ:measure_theory.measure α):(measure_theory.measure α) :=
measure_theory.measure.of_measurable
(λ (s:set α) (H:is_measurable s), x * (μ s))
begin
simp,
end
begin
intros f A1 A2,
simp,
rw measure.apply,
rw μ.m_Union A1 A2,
have A3:(λ i, μ.to_outer_measure.measure_of (f i)) =
λ i, μ (f i) := rfl,
rw A3,
rw ennreal.tsum_mul_left,
end
lemma scale_measure_apply {α:Type*}
[M:measurable_space α] (x:ennreal)
(μ:measure_theory.measure α)
(s:set α) (H:is_measurable s):
scale_measure x μ s =
(λ (s:set α) (H:is_measurable s), x * (μ s)) s H :=
begin
apply measure_theory.measure.of_measurable_apply,
apply H,
end
lemma scale_measure_apply2 {α:Type*}
[M:measurable_space α] (x:ennreal)
(μ:measure_theory.measure α)
(s:set α) (H:is_measurable s):
scale_measure x μ s = x * (μ s) :=
begin
rw scale_measure_apply,
apply H,
end
noncomputable instance has_scalar_ennreal_measure {α:Type*}
[measurable_space α]:
has_scalar (ennreal) (measure_theory.measure α) := {
smul := λ x y, scale_measure x y,
}
lemma ennreal_smul_measure_def {α:Type*}
[measurable_space α] (x:ennreal)
(μ:measure_theory.measure α):
(x • μ) = (scale_measure x μ) := rfl
lemma ennreal_smul_measure_apply {α:Type*}
[measurable_space α] (x:ennreal)
(μ:measure_theory.measure α)
(s:set α) (H:is_measurable s):
(x • μ) s = x * (μ s) :=
begin
rw ennreal_smul_measure_def,
rw scale_measure_apply2,
apply H,
end
lemma ennreal_measure_zero_smul {α:Type*}
[measurable_space α] (μ:measure_theory.measure α):
(0:ennreal) • μ = 0 :=
begin
apply measure_theory.measure.ext,
intros s A1,
rw ennreal_smul_measure_apply,
simp,
apply A1,
end
noncomputable instance mul_action_ennreal_measure
{α:Type*}
[M:measurable_space α]:
mul_action (ennreal) (measure_theory.measure α)
:= {
mul_smul :=
begin
intros x y μ,
apply measure_theory.measure.ext,
intros s A1,
rw ennreal_smul_measure_apply,
rw ennreal_smul_measure_apply,
rw ennreal_smul_measure_apply,
rw mul_assoc,
repeat {apply A1},
end,
one_smul :=
begin
intro μ,
apply measure_theory.measure.ext,
intros s A1,
rw ennreal_smul_measure_apply,
rw one_mul,
apply A1,
end,
}
noncomputable instance distrib_mul_action_ennreal_measure
{α:Type*}
[M:measurable_space α]:
distrib_mul_action (ennreal) (measure_theory.measure α)
:= {
smul_zero :=
begin
intro r,
apply measure_theory.measure.ext,
intros s A1,
rw ennreal_smul_measure_apply,
apply mul_zero,
apply A1,
end,
smul_add :=
begin
intros r μ ν,
apply measure_theory.measure.ext,
intros s A1,
rw ennreal_smul_measure_apply _ _ _ A1,
have A2:(μ + ν) s = (μ s) + (ν s)
:= rfl,
rw A2,
have A3:((r • μ) + (r • ν)) s = ((r • μ) s) + ((r • ν) s)
:= rfl,
rw A3,
repeat {rw scale_measure_apply2 _ _ _ A1},
rw left_distrib,
rw ennreal_smul_measure_apply _ _ _ A1,
rw ennreal_smul_measure_apply _ _ _ A1,
end,
}
noncomputable instance ennreal_measure_semimodule {α:Type*}
[M:measurable_space α]:
semimodule (ennreal) (measure_theory.measure α) := {
zero_smul :=
begin
intro μ,
apply measure_theory.measure.ext,
intros s A1,
rw ennreal_smul_measure_apply _ _ _ A1,
apply zero_mul,
end,
add_smul :=
begin
intros r t μ,
apply measure_theory.measure.ext,
intros s A1,
rw ennreal_smul_measure_apply _ _ _ A1,
rw measure_theory.measure.add_apply,
repeat {rw scale_measure_apply2 _ _ _ A1},
rw right_distrib,
rw ennreal_smul_measure_apply _ _ _ A1,
rw ennreal_smul_measure_apply _ _ _ A1,
end,
}
lemma ennreal.zero_if_lt_pos {x:ennreal}:
(∀ y >0, x ≤ y) → x = 0 :=
begin
intro A1,
have A2:(0:ennreal)=⊥ := rfl,
rw A2,
rw ← le_bot_iff,
rw ← A2,
apply ennreal.le_of_forall_epsilon_le,
intros ε A3 A4,
rw zero_add,
apply A1,
have A5:(0:ennreal)=(0:nnreal) := rfl,
rw A5,
simp,
apply A3,
end
lemma outer_measure_measure_of_le {Ω:Type*} {μ ν:measure_theory.outer_measure Ω}:
μ ≤ ν ↔
(μ.measure_of) ≤
(ν.measure_of) :=
begin
refl,
end
lemma to_outer_measure_measure_of_le {Ω:Type*} [measurable_space Ω] {μ ν:measure_theory.measure Ω}:
μ ≤ ν ↔
(μ.to_outer_measure.measure_of) ≤
(ν.to_outer_measure.measure_of) :=
begin
split;intro A1,
{
rw ← measure_theory.measure.to_outer_measure_le at A1,
rw le_func_def2,
intro ω,
apply A1,
},
{
intros S A2,
apply A1,
},
end
lemma monotone_to_outer_measure {Ω:Type*} [measurable_space Ω]:
monotone (λ μ:measure_theory.measure Ω, μ.to_outer_measure) :=
begin
intros μ ν A1,
simp,
rw ← measure_theory.measure.to_outer_measure_le at A1,
apply A1,
end
lemma monotone_to_outer_measure_measure_of {Ω:Type*} [measurable_space Ω]:
monotone (λ μ:measure_theory.measure Ω, μ.to_outer_measure.measure_of) :=
begin
intros μ ν A1,
simp,
rw ← measure_theory.measure.to_outer_measure_le at A1,
apply A1,
end
lemma measure_apply_le_measure_apply {Ω:Type*} [measurable_space Ω] {μ ν:measure_theory.measure Ω} {S:set Ω}:
μ ≤ ν →
(μ S) ≤ (ν S) :=
begin
intro A1,
rw to_outer_measure_measure_of_le at A1,
apply A1,
end
noncomputable def measure_theory.outer_measure.of_function' {Ω:Type*}
(f:set Ω → ennreal):
measure_theory.outer_measure Ω := measure_theory.outer_measure.of_function
(set.indicator ({(∅:set Ω)}ᶜ) f)
begin
rw set.indicator_of_not_mem,
simp,
end
lemma outer_measure_measure_of_def {Ω:Type*} {μ:measure_theory.outer_measure Ω}
{S:set Ω}:μ S = μ.measure_of S := rfl
lemma measure_theory.outer_measure.of_function_def
{α : Type*} (m : set α → ennreal) (m_empty : m ∅ = 0) :
(measure_theory.outer_measure.of_function m m_empty).measure_of
= λs, ⨅{f : ℕ → set α} (h : s ⊆ ⋃i, f i), ∑'i, m (f i) := rfl
lemma measure_theory.outer_measure.of_function_le_of_function_of_le {Ω:Type*}
{f g:set Ω → ennreal} {Hf:f ∅ = 0} {Hg:g ∅ = 0}:
f ≤ g →
(measure_theory.outer_measure.of_function f Hf ≤
measure_theory.outer_measure.of_function g Hg) :=
begin
intro A1,
rw measure_theory.outer_measure.le_of_function,
intro S,
have A2 := @measure_theory.outer_measure.of_function_le _ f Hf S,
apply le_trans A2,
apply A1,
end
lemma measure_theory.outer_measure.monotone_of_function' {Ω:Type*}:
monotone (@measure_theory.outer_measure.of_function' Ω) :=
begin
unfold monotone measure_theory.outer_measure.of_function',
intros f g A1,
apply measure_theory.outer_measure.of_function_le_of_function_of_le,
have A2 := @monotone_set_indicator (set Ω) ennreal _ _ ({∅}ᶜ),
apply A2,
apply A1,
end
lemma measure_theory.outer_measure.of_function'_le {Ω:Type*}
{f:set Ω → ennreal} {S:set Ω}:
(measure_theory.outer_measure.of_function' f S ≤ f S) :=
begin
have A2 := @measure_theory.outer_measure.of_function_le _
(@set.indicator (set Ω) ennreal _ ({(∅:set Ω)}ᶜ) f) _ S,
apply le_trans A2,
clear A2,
cases classical.em (S = ∅) with A3 A3,
{
subst S,
rw set.indicator_of_not_mem,
{
simp,
},
{
simp,
},
},
{
rw set.indicator_of_mem,
apply le_refl (f S),
simp [A3],
},
end
lemma galois_connection_measure_of_of_function' {Ω:Type*}:
galois_connection
(λ μ:measure_theory.outer_measure Ω, μ.measure_of)
(λ f:set Ω → ennreal, measure_theory.outer_measure.of_function' f) :=
begin
unfold galois_connection,
intros μ f,
unfold measure_theory.outer_measure.of_function',
rw measure_theory.outer_measure.le_of_function,
split;intros A1,
{
intro S,
cases (classical.em (S = ∅)) with B1 B1,
{
subst S,
rw outer_measure_measure_of_def,
rw measure_theory.outer_measure.empty,
simp,
},
{
rw set.indicator_of_mem,
apply A1,
simp [B1],
},
},
{
rw le_func_def2,
intro S,
cases (classical.em (S = ∅)) with C1 C1,
{
subst S,
rw measure_theory.outer_measure.empty,
simp,
},
{
have C2:= A1 S,
rw set.indicator_of_mem at C2,
apply C2,
simp [C1],
},
},
end
lemma of_function_replace {Ω:Type*} {f g:set Ω → ennreal} {Hf:f ∅ = 0} {Hg:g ∅ = 0}:
(f = g) →
measure_theory.outer_measure.of_function f Hf =
measure_theory.outer_measure.of_function g Hg :=
begin
intro A1,
apply measure_theory.outer_measure.ext,
intro S,
repeat {rw outer_measure_measure_of_def},
repeat {rw measure_theory.outer_measure.of_function_def},
rw A1,
end
lemma of_function_invariant {Ω:Type*} {μ:measure_theory.outer_measure Ω}:
measure_theory.outer_measure.of_function (μ.measure_of) (μ.empty) = μ :=
begin
apply le_antisymm,
{
rw outer_measure_measure_of_le,
rw le_func_def2,
intro S,
apply measure_theory.outer_measure.of_function_le,
apply μ.empty,
},
{
rw measure_theory.outer_measure.le_of_function,
intro S,
apply le_refl (μ.measure_of S),
},
end
noncomputable def galois_insertion_measure_of_of_function' {Ω:Type*}:
@galois_insertion (order_dual (set Ω → ennreal)) (order_dual (measure_theory.outer_measure Ω)) _ _
(λ f:set Ω → ennreal, measure_theory.outer_measure.of_function' f)
(λ μ:measure_theory.outer_measure Ω, μ.measure_of)
:=
begin
apply galois_insertion.monotone_intro,
{
intros μ ν B1,
simp,
apply B1,
},
{
intros f g C1,
apply measure_theory.outer_measure.monotone_of_function',
apply C1,
},
{
intro f,
apply measure_theory.outer_measure.of_function'_le,
},
{
intro μ,
unfold measure_theory.outer_measure.of_function',
have D1:(set.indicator ({∅}ᶜ) μ.measure_of)=μ.measure_of,
{
apply funext,
intro S,
cases (classical.em (S = ∅)) with D1A D1A,
{
subst S,
rw set.indicator_of_not_mem,
rw measure_theory.outer_measure.empty,
simp,
},
{
rw set.indicator_of_mem,
simp [D1A],
},
},
rw of_function_replace D1,
clear D1,
apply of_function_invariant,
},
end
def strictly_monotone {α β:Type*} [preorder α] [preorder β] (f:α → β):Prop :=
∀ a b:α, a < b → f a < f b
lemma monotone_of_strictly_monotone {α β:Type*} [partial_order α] [partial_order β] {f:α → β}:strictly_monotone f → monotone f :=
begin
intros A1,
intros b1 b2 A3,
cases (classical.em (b1 = b2)) with A4 A4,
{
subst b2,
},
{
apply le_of_lt,
apply A1,
apply lt_of_le_of_ne A3 A4,
},
end
/-
This represents that for all a, a', the converse of a the monotone property holds.
-/
def monotone_converse {α β:Type*} [partial_order α] [partial_order β] (f:α → β):Prop :=
∀ a a':α, f a ≤ f a' → a ≤ a'
lemma Sup_eq_Sup_of_monotone_converse {α β:Type*} [complete_lattice α] [complete_lattice β] {f:α → β} {s:set α} (a:α):monotone f →
monotone_converse f →
(Sup (f '' s) = f a) →
(Sup (f '' s) = f (Sup s)) :=
begin
intros A1 A2 A3,
apply le_antisymm,
{
apply Sup_le_Sup_of_monotone A1,
},
{
rw A3,
apply A1,
apply Sup_le,
intros b A4,
apply A2,
rw ← A3,
apply le_Sup,
apply exists.intro b,
apply and.intro A4 rfl,
},
end
lemma supr_eq_supr_of_monotone_converse {α β γ:Type*} [complete_lattice α] [complete_lattice β] {f:α → β} {g:γ → α} (a:α):monotone f →
monotone_converse f →
(supr (f ∘ g) = f a) →
(supr (f ∘ g) = f (supr g)) :=
begin
intros A1 A2 A3,
apply le_antisymm,
{
apply supr_le_supr_of_monotone A1,
},
{
rw A3,
apply A1,
apply Sup_le,
intros b A4,
apply A2,
rw ← A3,
cases A4 with y A4,
subst b,
apply le_supr (f ∘ g),
},
end
lemma infi_eq_infi_of_monotone_converse {α β γ:Type*} [complete_lattice α] [complete_lattice β] {f:α → β} {g:γ → α} (a:α):monotone f →
monotone_converse f →
(infi (f ∘ g) = f a) →
(infi (f ∘ g) = f (infi g)) :=
begin
intros A1 A2 A3,
apply le_antisymm,
{
rw A3,
apply A1,
apply le_infi,
intros b,
apply A2,
rw ← A3,
apply infi_le,
},
{
apply infi_le_infi_of_monotone A1,
},
end
lemma Inf_eq_Inf_of_monotone_converse {α β:Type*} [complete_lattice α] [complete_lattice β] {f:α → β} {s:set α} (a:α):monotone f →
monotone_converse f →
(Inf (f '' s) = f a) →
(Inf (f '' s) = f (Inf s)) :=
begin
intros A1 A2 A3,
apply le_antisymm,
{
rw A3,
apply A1,
apply le_Inf,
intros b A4,
apply A2,
rw ← A3,
apply Inf_le,
simp,
apply exists.intro b,
split,
apply A4,
refl,
},
{
apply Inf_le_Inf_of_monotone A1,
},
end
lemma monotone_converse_to_outer_measure_measure_of {Ω:Type*} [measurable_space Ω]:
monotone_converse (λ μ:measure_theory.measure Ω, μ.to_outer_measure.measure_of) :=
begin
intros μ ν A1,
intros s A2,
apply A1,
end
--TODO: write infi_eq_infi_to_outer_measure_measure_of,
-- or better, Inf_eq_Inf_to_outer_measure_measure_of...
lemma supr_eq_supr_to_outer_measure_measure_of {α γ:Type*}
[measurable_space α] {g:γ → measure_theory.measure α}
(μ:measure_theory.measure α):
(supr ((λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) ∘ g) =
(λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) μ) →
(supr ((λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) ∘ g) =
(λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) (supr g)) :=
begin
intros A1,
apply supr_eq_supr_of_monotone_converse μ,
apply monotone_to_outer_measure_measure_of,
apply monotone_converse_to_outer_measure_measure_of,
apply A1,
end
-- This would be better if it required only for all measurable sets.
lemma supr_eq_supr_of_apply {α γ:Type*}
[measurable_space α] {g:γ → measure_theory.measure α}
{μ:measure_theory.measure α}:
(∀ (s:set α),
(supr ((λ ν:measure_theory.measure α, ν s) ∘ g) = μ s)) →
(supr ((λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) ∘ g) =
(λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) (supr g)) :=
begin
intros A1,
apply supr_eq_supr_to_outer_measure_measure_of μ,
apply funext,
intro s,
rw supr_apply,
simp,
apply A1,
end
lemma dual_galois_insertion.l_infi_u' {α : Type*} {β : Type*} {l : α → β} {u : β → α}
[_inst_1 : complete_lattice α] [_inst_2 : complete_lattice β]:
@galois_insertion (order_dual α) (order_dual β) _ _ l u → ∀ {ι : Type*} (f : ι → β), l (⨅ (i : ι), u (f i)) = ⨅ (i : ι), f i :=
begin
intros A1 γ f,
have A2 := @galois_insertion.l_supr_u (order_dual α) (order_dual β) l u _ _ A1 γ f,
apply A2,
end
lemma dual_galois_insertion.l_supr_u' {α : Type*} {β : Type*} {l : α → β} {u : β → α}
[_inst_1 : complete_lattice α] [_inst_2 : complete_lattice β]:
@galois_insertion (order_dual α) (order_dual β) _ _ l u → ∀ {ι : Type*} (f : ι → β), l (⨆ (i : ι), u (f i)) = ⨆ (i : ι), f i :=
begin
intros A1 γ f,
have A2 := @galois_insertion.l_infi_u (order_dual α) (order_dual β) l u _ _ A1 γ f,
apply A2,
end
lemma galois_insertion.le_iff_u_le_u {α : Type*} {β : Type*} {l : α → β} {u : β → α}
[_inst_1 : complete_lattice α] [_inst_2 : complete_lattice β] {b b':β}:
@galois_insertion α β _ _ l u →
((b ≤ b') ↔ (u b ≤ u b')) :=
begin
intro A1,
split;intros A2,
{
apply A1.gc.monotone_u A2,
},
{
rw ← A1.gc at A2,
rw A1.l_u_eq at A2,
apply A2,
},
end
lemma galois_insertion.Sup_u_eq_u_Sup {α : Type*} {β : Type*} {l : α → β} {u : β → α}
[_inst_1 : complete_lattice α] [_inst_2 : complete_lattice β]:
@galois_insertion α β _ _ l u →
∀ (S:set β), (∃ b:β, u b = Sup (u '' S)) → u (Sup S) = Sup (u '' S) :=
begin
intros A1 S A2,
cases A2 with b A2,
apply le_antisymm,
{
rw ← A2,
have A3 := A1.gc.monotone_u,
apply A3,
apply Sup_le,
intros b' A4,
rw A1.le_iff_u_le_u,
rw A2,
apply le_Sup,
simp,
apply exists.intro b',
apply and.intro A4 _,
refl,
},
{
apply Sup_le,
intros a A3,
rw ← A1.gc,
apply le_Sup,
simp at A3,
cases A3 with b' A3,
cases A3 with A3 A4,
subst a,
rw A1.l_u_eq,
apply A3,
},
end
lemma dual_galois_connection.u_Sup {α β : Type*}
[_inst_1 : complete_lattice α] [_inst_2 : complete_lattice β]
{l : α → β} {u : β → α}:
@galois_connection (order_dual α) (order_dual β) _ _ l u →
∀ (s : set β), u (Sup s) = (⨆a∈s, u a) :=
begin
intros A1 s,
apply A1.u_Inf,
end
lemma dual_galois_connection.u_supr {α β : Type*} {ι: Sort*}
[_inst_1 : complete_lattice α] [_inst_2 : complete_lattice β]
{l : α → β} {u : β → α}:
@galois_connection (order_dual α) (order_dual β) _ _ l u →
∀ (γ:Type*) (f : γ → β), u (supr f) = (⨆a, u (f a)) :=
begin
intros A1 γ f,
apply A1.u_infi,
end
-- A local function for mapping the supremum as a function back to a measure.
-- It is sufficient that such a measure exists.
noncomputable def supr_as_fun {α:Type*} [measurable_space α]
(f:ℕ → (measure_theory.measure α)):Π (s:set α), (is_measurable s) → ennreal :=
(λ s H,(⨆ n:ℕ, f n s))
lemma supr_as_fun_apply {α:Type*} [measurable_space α]
(f:ℕ → (measure_theory.measure α)) (s:set α) (H:is_measurable s):
supr_as_fun f s H = (⨆ n:ℕ, f n s) := rfl
lemma supr_as_fun_empty {α:Type*} [measurable_space α]
{f:ℕ → (measure_theory.measure α)}:
(supr_as_fun f) ∅ is_measurable.empty = 0 :=
begin
unfold supr_as_fun,
have A1:(λ n:ℕ, f n ∅ ) = 0,
{
apply funext,
intro n,
apply measure_theory.measure_empty,
},
rw A1,
apply @supr_const ennreal ℕ _ _ 0,
end
lemma supr_sum_le_sum_supr {g:ℕ → ℕ → ennreal}:
(⨆ m:ℕ, ∑' n, g m n) ≤
(∑' m, ⨆ n:ℕ, g n m) :=
begin
apply @supr_le ennreal ℕ _,
intro i,
apply @tsum_le_tsum ennreal ℕ _ _,
intro b,
apply @le_supr ennreal ℕ _,
repeat {apply ennreal.summable},
end
lemma tsum_single {α : Type*} {β : Type*} [_inst_1 : add_comm_monoid α] [_inst_2 : topological_space α] [t2_space α] {f : β → α} (b : β): (∀ (b' : β), b' ≠ b → f b' = 0) → tsum f = (f b) :=
begin
intro A1,
have A2:=has_sum_single b A1,
have A3:summable f := has_sum.summable A2,
rw ← summable.has_sum_iff A3,
apply A2,
end
lemma ennreal.tsum {α:Type*} {f:α → ennreal}:tsum f = supr (λ s:finset α,s.sum f) :=
begin
rw ← summable.has_sum_iff ennreal.summable,
apply @ennreal.has_sum α f,
end
lemma ennreal.tsum_le {f:ℕ → ennreal} {x:ennreal}:(∀ n:ℕ,
(finset.range n).sum f ≤ x) ↔
(tsum f ≤ x) :=
begin
rw ennreal.tsum,
split;intros A1,
{
apply @supr_le ennreal (finset ℕ) _ (λ s:finset ℕ,s.sum f),
intro s,
have B1:=finset_range_bound s,
cases B1 with n B1,
apply le_trans _ (A1 n),
simp,
apply @finset.sum_le_sum_of_subset ℕ ennreal s (finset.range n) f _ B1,
},
{
intro n,
apply le_trans _ A1,
apply @le_supr ennreal (finset ℕ) _ (λ s, s.sum f),
},
end
lemma ennreal.finset_sum_le_tsum {f:ℕ → ennreal} {n:ℕ}:
(finset.range n).sum f ≤ tsum f :=
begin
rw ennreal.tsum,
apply @le_supr ennreal (finset ℕ) _ (λ s, s.sum f),
end
lemma ennreal.lim_finset_sum_eq_tsum {f:ℕ → ennreal}:
(⨆ n, (finset.range n).sum f) = tsum f :=
begin
apply le_antisymm,
apply @supr_le ennreal _ _,
intro n,
apply ennreal.finset_sum_le_tsum,
rw ← ennreal.tsum_le,
intro n,
apply @le_supr ennreal _ _,
end
lemma supr_sum_eq_sum_supr {g:ℕ → ℕ → ennreal}:
monotone g →
(⨆ m:ℕ, ∑' n, g m n) =
(∑' m, ⨆ n:ℕ, g n m) :=
begin
intro A1,
apply le_antisymm,
{
apply supr_sum_le_sum_supr,
},
{
rw ← @ennreal.tsum_le (λ m, ⨆ n:ℕ, g n m) (⨆ m:ℕ, ∑' n, g m n),
intros n2,
have A2:(λ m, (finset.range n2).sum (g m)) ≤ (λ m, ∑' n, g m n),
{
rw le_func_def2,
intro m,
simp,
apply ennreal.finset_sum_le_tsum,
},
have A3:(⨆ m, (finset.range n2).sum (g m)) ≤ (⨆ m, ∑' n, g m n),
{
apply supr_le_supr A2,
},
apply le_trans _ A3,
rw @ennreal.finset_sum_supr_nat ℕ ℕ _ (finset.range n2) (λ m n, g n m),
simp,
intro i,
apply @le_supr ennreal ℕ _,
intros a,
simp,
intros x y A4,
simp,
apply A1,
apply A4,
},
end
lemma supr_as_fun_m_Union {α:Type*} [M:measurable_space α]
(f:ℕ → (measure_theory.measure α)) (H:monotone f):
(∀ {g : ℕ → set α} (h : ∀ (i : ℕ), is_measurable (g i)),
pairwise (disjoint on g) →
((supr_as_fun f) (⋃ (i : ℕ), g i) (M.is_measurable_Union g h)) =
∑' (i : ℕ), (supr_as_fun f) (g i) (h i)) :=
begin
intros g h A1,
rw supr_as_fun_apply,
have A2:(λ i, supr_as_fun f (g i) (h i)) = (λ i, (⨆ n:ℕ, f n (g i) )),
{
apply funext,
intro i,
rw supr_as_fun_apply,
},
rw A2,
clear A2,
have A3:(λ (n : ℕ), (f n) (⋃ (i : ℕ), g i))= (λ (n : ℕ),∑' i, (f n) (g i)),
{
apply funext,
intro n,
apply (f n).m_Union h A1,
},
rw A3,
clear A3,
apply supr_sum_eq_sum_supr,
intros x y A4,
simp,
rw le_func_def2,
intro n,
apply H,
apply A4,
apply h,
end
noncomputable def supr_as_measure {α:Type*} [M:measurable_space α]
(f:ℕ → (measure_theory.measure α)) (H:monotone f):measure_theory.measure α :=
measure_theory.measure.of_measurable (supr_as_fun f) (@supr_as_fun_empty α M f)
(@supr_as_fun_m_Union α M f H)
lemma supr_as_measure_def {α:Type*} [M:measurable_space α]
(f:ℕ → (measure_theory.measure α)) (H:monotone f):(supr_as_measure f H) =
measure_theory.measure.of_measurable (supr_as_fun f) (@supr_as_fun_empty α M f)
(@supr_as_fun_m_Union α M f H) := rfl
lemma supr_as_measure_apply {α:Type*} [M:measurable_space α]
(f:ℕ → (measure_theory.measure α)) (H2:monotone f) (s:set α) (H:is_measurable s):
(supr_as_measure f H2) s = (λ s,(⨆ n:ℕ, f n s)) s :=
begin
rw supr_as_measure_def,
rw measure_theory.measure.of_measurable_apply s H,
rw supr_as_fun_apply f s,
end
lemma measure_theory.measure.Union_nat {α : Type*} [M : measurable_space α]
{μ:measure_theory.measure α} {f:ℕ → set α}:μ (⋃ i, f i) ≤ ∑' i, μ (f i) :=
begin
rw measure.apply,
have A1:(λ i, μ (f i))=(λ i, μ.to_outer_measure.measure_of (f i)) := rfl,
rw A1,
apply measure_theory.outer_measure.Union_nat,
end
lemma infi_eq_infi {α β:Type*} [has_Inf β] {f:α → β} {g:α → β}:
(∀ a:α, f a = g a) →
(⨅ a:α, f a) = ⨅ a:α, g a :=
begin
intro A1,
have A2:f = g,
{
ext,
apply A1,
},
rw A2,
end
lemma supr_eq_supr {α β:Type*} [has_Sup β] {f:α → β} {g:α → β}:
(∀ a:α, f a = g a) →
(⨆ a:α, f a) = ⨆ a:α, g a :=
begin
intro A1,
have A2:f = g,
{
ext,
apply A1,
},
rw A2,
end
lemma infi_commute_helper {α β:Sort} {γ:Type*} [complete_lattice γ] {f:α → β → γ}:
(⨅ a:α,⨅ b:β, f a b) ≤ ⨅ b:β, ⨅ a:α, f a b :=
begin
apply le_infi,
intro b,
apply le_infi,
intro a,
have A1:(⨅ (a : α) (b : β), f a b)≤(⨅ (b : β), f a b),
{
apply infi_le,
},
apply le_trans A1,
apply infi_le,
end
lemma infi_commute {α β:Sort} {γ:Type*} [complete_lattice γ] {f:α → β → γ}:
(⨅ a:α,⨅ b:β, f a b) = ⨅ b:β, ⨅ a:α, f a b :=
begin
apply le_antisymm,
{
apply infi_commute_helper,
},
{
apply infi_commute_helper,
},
end
lemma measure_theory.measure.to_outer_measure_def {α : Type*} [M : measurable_space α]
{μ:measure_theory.measure α} {s:set α}:
μ s = ⨅ (s':set α) (H:is_measurable s') (H2:s⊆ s'), μ s' :=
begin
rw measure_theory.measure_eq_infi,
apply infi_eq_infi,
intro s',
rw infi_commute,
end
lemma measure_theory.measure.of_measurable_apply3 {α : Type*} [M : measurable_space α]
{m : Π (s : set α), is_measurable s → ennreal} {m0 : m ∅ is_measurable.empty = 0}
{mU : ∀ (f : ℕ → set α) (h : ∀ (i : ℕ), is_measurable (f i)), pairwise (disjoint on f) → (m
(⋃ (i : ℕ), f i) (M.is_measurable_Union f h)) = ∑' (i : ℕ), m (f i) (h i)}
(s : set α):
(measure_theory.measure.of_measurable m m0 mU) s =
⨅ (s':set α) (H:is_measurable s') (H2:s⊆ s'), m s' H :=
begin
rw measure_theory.measure.to_outer_measure_def,
have A1:(λ s':set α, ⨅ (H : is_measurable s') (H2 : s ⊆ s'), (measure_theory.measure.of_measurable m m0 mU) s') =
(λ s':set α, ⨅ (H : is_measurable s') (H2 : s ⊆ s'), m s' H),
{
apply funext,
intro s',
have A1A:(λ (H : is_measurable s'), ⨅ (H2 : s ⊆ s'),
(measure_theory.measure.of_measurable m m0 mU) s') =
λ (H : is_measurable s'), ⨅ (H2 : s ⊆ s'), m s' H,
{
apply funext,
intro A1A1,
have A1A2:(λ (H2 : s ⊆ s'), (measure_theory.measure.of_measurable m m0 mU) s') =
λ (H2 : s ⊆ s'), m s' A1A1,
{
apply funext,
intro A1A2A,
apply @measure_theory.measure.of_measurable_apply α M m m0 mU,
},
rw A1A2,
},
rw A1A,
},
rw A1,
end
lemma supr_as_measure_apply2 {α:Type*} [M:measurable_space α]
(f:ℕ → (measure_theory.measure α)) (H2:monotone f) (s:set α):
(supr_as_measure f H2) s = ⨅ (s':set α) (H:is_measurable s') (H2:s⊆ s'), (⨆ n:ℕ, f n s') :=
begin
rw supr_as_measure_def,
rw measure_theory.measure.of_measurable_apply3,
have A1:(λ (s' : set α), ⨅ (H : is_measurable s') (H2 : s ⊆ s'), supr_as_fun f s' H) =
λ (s' : set α), ⨅ (H : is_measurable s') (H2 : s ⊆ s'), ⨆ (n : ℕ), (f n) s',
{
apply funext,
intro s',
have A1A:(λ (H : is_measurable s'), ⨅ (H2 : s ⊆ s'), supr_as_fun f s' H) =
λ (H : is_measurable s'), ⨅ (H2 : s ⊆ s'), ⨆ (n : ℕ), (f n) s',
{
apply funext,
intro H,
have A1A1:(λ (H2 : s ⊆ s'), supr_as_fun f s' H) =
λ (H2 : s ⊆ s'), ⨆ (n : ℕ), (f n) s',
{
apply funext,
intro H2,
rw supr_as_fun_apply,
},
rw A1A1,
},
rw A1A,
},
rw A1,
end
lemma supr_eq_supr_to_outer_measure_measure_of_of_monotone {α:Type*}
[M:measurable_space α] {g:ℕ → measure_theory.measure α}
:monotone g →
(supr ((λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) ∘ g) =
(λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) (supr g)) :=
begin
intro A1,
apply @supr_eq_supr_to_outer_measure_measure_of α ℕ M g (@supr_as_measure α M g A1),
simp,
apply funext,
intro s,
rw supr_as_measure_apply2,
apply le_antisymm,
{
apply @le_infi ennreal (set α) _,
intro s',
apply @le_infi ennreal _ _,
intro H,
apply @le_infi ennreal _ _,
intro H2,
rw supr_apply,
apply @supr_le_supr ennreal ℕ _,
intro n,
apply measure_theory.measure_mono,
apply H2,
},
{
rw supr_apply,
have C1:(λ (i : ℕ), (g i) s)
= λ i, ⨅ (s':set α) (H:is_measurable s') (H2:s⊆ s'), (g i) s' ,
{
apply funext,
intro i,
apply measure_theory.measure.to_outer_measure_def,
},
rw C1,
clear C1,
apply ennreal.infi_le,
intros ε C2 C3,
have C4:∃ (f:ℕ → (set α)), (∀ i:ℕ,
(is_measurable (f i)) ∧
(s ⊆ (f i)) ∧
((g i (f i)) ≤
( ⨅ (s' : set α) (H : is_measurable s') (H2 : s ⊆ s'), (g i) s') + (ε:ennreal))),
{
have C4A:(∀ i:ℕ, ∃ s'':set α,
(is_measurable (s'')) ∧
(s ⊆ (s'')) ∧
((g i (s'')) ≤
( ⨅ (s' : set α) (H : is_measurable s') (H2 : s ⊆ s'), (g i) s') + (ε:ennreal))),
{
intro i,
rw @lt_top_iff_ne_top ennreal _ _ at C3,
have C4B:=@ne_top_of_supr_ne_top ℕ _ i C3,
have C4C:(⨅ (s' : set α) (H : is_measurable s') (H2 : s ⊆ s'), (g i) s')≠ ⊤ ,
{
apply C4B,
},
have C4E := lt_top_iff_ne_top.mpr C4C,
have C4D := ennreal.infi_elim C2 C4E,
cases C4D with s'' C4D,
apply exists.intro s'',
simp at C4D,
have C4F: (⨅ (s' : set α) (H : is_measurable s') (H2 : s ⊆ s'), (g i) s') + ↑ε < ⊤,
{
rw with_top.add_lt_top,
split,
apply C4E,
simp,
},
have C4G := lt_of_le_of_lt C4D C4F,
have C4H := of_infi_lt_top C4G,
rw infi_prop_def at C4G,
have C4I := of_infi_lt_top C4G,
rw infi_prop_def at C4G,
split,
{
apply C4H,
},
split,
{
apply C4I,
},
rw infi_prop_def at C4D,
rw infi_prop_def at C4D,
apply C4D,
apply C4I,
apply C4H,
apply C4I,
apply C4H,
},
apply @classical.some_func ℕ (set α) _ C4A,
},
cases C4 with f C4,
apply exists.intro (set.Inter f),
rw infi_prop_def,
rw infi_prop_def,
rw ennreal.supr_add,
apply @supr_le_supr ennreal ℕ _ (λ n, (g n) (set.Inter f)),
{
intro i,
have D1:(λ (n : ℕ), (g n) (set.Inter f)) i ≤ (g i) (f i),
{
simp,
apply measure_theory.measure_mono,
apply @set.Inter_subset α ℕ f,
},
apply le_trans D1 (C4 i).right.right,
},
{
apply set.subset_Inter,
intro i,
apply (C4 i).right.left,
},
{
apply is_measurable.Inter,
intro i,
apply (C4 i).left,
},
},
end
lemma supr_eq_supr_to_outer_measure_measure_of_of_monotone' {α:Type*}
[M:measurable_space α] {g:ℕ → measure_theory.measure α}
:monotone g →
(supr ((λ ν:measure_theory.measure α, ν.to_outer_measure.measure_of) ∘ g) =
(supr g).to_outer_measure.measure_of) :=
begin
apply supr_eq_supr_to_outer_measure_measure_of_of_monotone,
end
lemma ennreal.Sup_eq_supr {S:set ennreal}:S.nonempty →
(∃ f:ℕ → ennreal,
(∀ n, f n ∈ S) ∧
(supr f = Sup S)) :=
begin
intro A1,
cases (classical.em (Sup S = ⊤)) with A2 A2,
{
-- If Sup S = ⊤, then we have a sequence that is larger than every natural.
have B1:∀ n:ℕ, ∃ s:ennreal, (s∈ S) ∧ (n:ennreal) ≤ s,
{
intro n,
rw Sup_eq_top at A2,
have B1A:=A2 n _,
cases B1A with s B1A,
cases B1A with B1A B1B,
apply exists.intro s,
apply and.intro B1A (@le_of_lt ennreal _ _ _ B1B),
have B1C:(n:ennreal) = ((n:nnreal):ennreal),
{
simp,
},
rw B1C,
apply ennreal.coe_lt_top,
},
have B2:=classical.some_func B1,
cases B2 with f B2,
apply exists.intro f,
simp at B2,
split,
{
intro n,
apply (B2 n).left,
},
{
rw A2,
rw ← top_le_iff,
rw ← ennreal.supr_coe_nat,
apply @supr_le_supr ennreal ℕ _,
intro n,
apply (B2 n).right,
},
},
{
have C1:∀ n:ℕ, ∃ s:ennreal, (s∈S) ∧ (Sup S - (1/(n.succ:ennreal)) ≤ s),
{
intro n,
have C1A:=@ennreal.Sup_elim S (1/(n.succ:nnreal)) _ A1 A2,
cases C1A with s C1A,
cases C1A with C1A C1B,
apply exists.intro s,
apply and.intro C1A _,
rw ennreal.coe_div at C1B,
simp at C1B,
simp,
apply C1B,
simp,
simp,
apply zero_lt_one,
},
have C2:=classical.some_func C1,
cases C2 with f C2,
apply exists.intro f,
split,
{
intro n,
apply (C2 n).left,
},
apply le_antisymm,
{
apply @supr_le ennreal _ _,
intro i,
have C3 := C2 i,
apply @le_Sup ennreal _ _,
apply C3.left,
},
apply @ennreal.le_of_forall_epsilon_le,
intros ε C4 C5,
have C6 := nnreal.exists_unit_frac_lt_pos C4,
cases C6 with n C6,
have C7 := C2 n,
have C8:Sup S ≤ f n + ε,
{
have C8A:1/ ((nat.succ n):ennreal) ≤ (ε:ennreal),
{
simp,
rw ← ennreal.coe_one,
have C8A1:(n:ennreal) = ((n:nnreal):ennreal),
{
simp,
},
rw C8A1,
rw ← ennreal.coe_add,
rw ← ennreal.coe_div,
rw ennreal.coe_le_coe,
apply le_of_lt,
apply C6,
simp,
},
have C8B:Sup S - (ε:ennreal) ≤
Sup S - 1/ ((nat.succ n):ennreal),
{
apply ennreal.sub_le_sub,
apply le_refl (Sup S),
apply C8A,
},
have C8C:Sup S - (ε:ennreal) ≤ f n,
{
apply le_trans C8B C7.right,
},
rw add_comm,
rw ← ennreal.sub_le_iff_le_add',
apply C8C,
},
apply le_trans C8,
have C9 := le_supr f n,
apply add_le_add_right C9,
},
end
def Sup_so_far {α:Type*} [semilattice_sup_bot α] (f:ℕ → α) (n:ℕ):α :=
(finset.range (n.succ)).sup f
lemma Sup_so_far_def {α:Type*} [semilattice_sup_bot α] {f:ℕ → α}
{n:ℕ}:
Sup_so_far f n = (finset.range (n.succ)).sup f := rfl
lemma le_Sup_so_far {α:Type*} [semilattice_sup_bot α] (f:ℕ → α):
f ≤ (Sup_so_far f) :=
begin
rw le_func_def2,
intro n,
rw Sup_so_far_def,
apply finset.le_sup,
simp,
end
lemma finset.sup_closed {α β:Type*} [decidable_eq α]
[semilattice_sup_bot β]
(S:finset α)
(f:α → β) (T:set β):
(⊥ ∈ T) →
(∀ a∈ S, f a ∈ T) →
(∀ a∈ T, ∀ b∈ T, a⊔b ∈ T) →
(S.sup f ∈ T) :=
begin
intros A1 A2 A3,
revert A2,
apply finset.induction_on S,
{
intros B1,
simp,
apply A1,
},
{
intros a S C1 C2 C3,
simp,
apply A3,
{
apply C3,
simp,
},
{
apply C2,
intro a2,
intro C4,
apply C3,
simp,
apply or.inr C4,
},
},
end
lemma finset.sup_closed_nonempty {α β:Type*} [decidable_eq α]
[semilattice_sup_bot β]
(S:finset α)
(f:α → β) (T:set β):
(S ≠ ∅) →
(∀ a∈ S, f a ∈ T) →
(∀ a∈ T, ∀ b∈ T, a⊔b ∈ T) →
(S.sup f ∈ T) :=
begin
intros A2 A4 A3,
revert A2,
revert A4,
apply finset.induction_on S,
{
intros B1,
simp,
},
{
intros a S C1 C2 C3,
simp,
cases classical.em (S = ∅) with C5 C5,
{
subst S,
simp,
apply C3,
simp,
},
apply A3,
{
apply C3,
simp,
},
{
apply C2,
intro a2,
intro C4,
apply C3,
simp,
apply or.inr C4,
apply C5,
},
},
end
lemma Sup_so_far_of_closed {α:Type*} [semilattice_sup_bot α] (f:ℕ → α) (S:set α):
(∀ n:ℕ, f n ∈ S) →
(∀ a∈ S, ∀ b∈ S, a⊔b ∈ S) →
(∀ n:ℕ, (Sup_so_far f n ∈ S)) :=
begin
intros A1 A2 n,
rw Sup_so_far_def,
apply finset.sup_closed_nonempty,
{
rw finset.range_eq_Ico,
intro B1,
rw finset.Ico.eq_empty_iff at B1,
simp at B1,
apply nat.succ_ne_zero n B1,
},
{
intros n2 C1,
apply A1,
},
{
apply A2,
},
end
lemma monotone_Sup_so_far {α:Type*} [semilattice_sup_bot α] (f:ℕ → α):
monotone (Sup_so_far f) :=
begin
intros a b A1,
rw Sup_so_far_def,
rw Sup_so_far_def,
apply finset.sup_mono,
simp,
apply nat.succ_le_succ A1,
end
/- For supr_measure_eq_measure_supr, this is a more
useful rewrite, as (finset.range (nat.succ n)).sum f = f n -/
lemma ennreal.lim_finset_sum_succ_eq_tsum {f:ℕ → ennreal}:
(⨆ n, (finset.range (nat.succ n)).sum f) = tsum f :=
begin
apply le_antisymm,
{
apply @supr_le ennreal _ _,
intro n,
apply ennreal.finset_sum_le_tsum,
},
{
rw ← ennreal.tsum_le,
intro n,
cases n,
{
simp,
},
{
apply @le_supr ennreal _ _,
},
}
end
/-
This is useful to prove Hahn decomposition.
No wait, it's not.
-/
lemma supr_measure_eq_measure_supr {α:Type*}
[M:measurable_space α] {μ:measure_theory.measure α}
{f:ℕ → set α}:(∀ n, is_measurable (f n)) →
monotone f →
supr (λ n, μ (f n)) = μ (supr f) :=
begin
intros A1 A2,
rw supr_eq_Union,
rw ← Union_sub_pred,
rw measure.apply,
rw measure_theory.measure.m_Union,
rw ← ennreal.lim_finset_sum_succ_eq_tsum,
have A3:(λ (i : ℕ), μ.to_outer_measure.measure_of (sub_pred f i))
= (λ (i : ℕ), μ (sub_pred f i)),
{
apply funext,
intro i,
rw measure.apply,
},
rw A3,
have A5:(λ (n : ℕ), finset.sum (finset.range n.succ)
(λ (i : ℕ), μ (sub_pred f i)))=
(λ n, μ (f n) ),
{
apply funext,
intro n,
rw @measure_finset_sum α M μ (sub_pred f) _,
rw union_range_sub_pred,
rw union_finset_range_monotone,
apply A2,
intro m,
apply is_measurable_sub_pred A1,
apply sub_pred_pairwise_disjoint,
apply A2,
},
rw A5,
intro m,
apply is_measurable_sub_pred A1,
apply sub_pred_pairwise_disjoint,
apply A2,
end
/-
This theorem is immediately useful to prove the
existence of the Radon-Nikodym derivative, if
α = measure_theory.measure Ω, and g = (λ μ, μ T)
(see Sup_apply_eq_supr_apply_of_closed).
However, if α = set Ω, and g = μ, then this
can be used to prove the Hahn decomposition variant.
The critical proof is that supr (μ T) =
μ (supr T).
-/
lemma Sup_apply_eq_supr_apply_of_closed' {α:Type*}
[complete_lattice α] {S:set α} (g:α → ennreal):
(∀ (a∈ S) (b∈ S), a ≤ b → g a ≤ g b) →
(∀ f:ℕ → α, (set.range f ⊆ S) →
monotone f → supr (g ∘ f) = g (supr f)) →
(S.nonempty) →
(∀ a ∈ S, ∀ b ∈ S, a ⊔ b ∈ S)→
(∃ f:ℕ → α,
(∀ n, f n ∈ S) ∧
(monotone f) ∧
g (supr f) = Sup (g '' S)) :=
begin
intros A1 AX A2 A3,
have B1:(g '' S).nonempty,
{
apply set.nonempty_image_of_nonempty A2,
},
have B1X := ennreal.Sup_eq_supr B1,
cases B1X with f' B1X,
have B2:∃ f'':ℕ → α, ∀ n:ℕ,
(f'' n)∈ S ∧ g (f'' n) = f' n,
{
apply @classical.some_func ℕ α (λ (n:ℕ) (a:α),
a∈ S ∧ g a = f' n),
intro n,
have B2A:=(B1X.left) n,
simp at B2A,
cases B2A with a B2A,
apply exists.intro a,
simp,
apply B2A,
},
cases B2 with f'' B2,
have C1:∀ (n : ℕ), Sup_so_far f'' n ∈ S,
{
apply Sup_so_far_of_closed,
intro n,
apply (B2 n).left,
apply A3,
},
apply exists.intro (Sup_so_far f''),
split,
{
apply C1,
},
split,
{
apply monotone_Sup_so_far,
},
{
rw ← AX,
apply le_antisymm,
{
apply @supr_le ennreal _ _,
intro n,
apply @le_Sup ennreal _ _,
simp,
apply exists.intro (Sup_so_far f'' n),
apply and.intro (C1 n),
refl,
},
{
rw ← B1X.right,
apply @supr_le_supr ennreal _ _,
intros n,
rw ← (B2 n).right,
simp,
apply A1,
apply (B2 n).left,
apply C1 n,
apply le_Sup_so_far,
},
{
rw set.subset_def,
intros x C2,
simp at C2,
cases C2 with n C2,
rw ← C2,
apply C1,
},
apply monotone_Sup_so_far,
},
end
/- This lemma presents a pattern that is repeated
many times, both for Hahn decomposition and for
the Lebesgue-Radon-Nikodym theorem. -/
lemma Sup_apply_has_max {α:Type*}
[complete_lattice α] {S:set α} (g:α → ennreal):
(∀ (a∈ S) (b∈ S), a ≤ b → g a ≤ g b) →
(∀ f:ℕ → α, (set.range f ⊆ S) →
monotone f → supr (g ∘ f) = g (supr f)) →
(∀ f:ℕ → α, (set.range f ⊆ S) →
monotone f → supr f ∈ S) →
(S).nonempty →
(∀ a ∈ S, ∀ b ∈ S, a ⊔ b ∈ S)→
(∃ a∈ S, g a = Sup (g '' S)) :=
begin
intros A1 A2 A3 A4 A5,
have B1 := Sup_apply_eq_supr_apply_of_closed' g A1 A2 A4 A5,
cases B1 with f B1,
apply exists.intro (supr f),
have C1:set.range f ⊆ S,
{
rw set.range_subset_iff,
apply B1.left,
},
have C2 := A3 f C1 B1.right.left,
apply exists.intro C2,
apply B1.right.right,
end
lemma Sup_apply_eq_supr_apply_of_closed {α:Type*}
[M:measurable_space α] {S:set (measure_theory.measure α)}
{T:set α}:
(S.nonempty) →
(is_measurable T) →
(∀ μ ∈ S, ∀ ν ∈ S, μ ⊔ ν ∈ S)→
(∃ f:ℕ → (measure_theory.measure α),
(∀ n, f n ∈ S) ∧
(monotone f) ∧
(supr f T = Sup ((λ μ:measure_theory.measure α, μ T) '' S))) :=
begin
intros A1 A2 A3,
apply @Sup_apply_eq_supr_apply_of_closed' (measure_theory.measure α) _ S (λ μ:measure_theory.measure α, μ T),
{
intros x B1 y B2 B3,
apply monotone_to_outer_measure_measure_of,
apply B3,
},
{
intros f CX C1,
simp,
have C2:= supr_eq_supr_to_outer_measure_measure_of_of_monotone' C1,
rw measure.apply,
rw ← C2,
rw supr_apply,
refl,
},
{
apply A1,
},
{
apply A3,
},
end
/- Note that for outer measures, the supremum commutes with measure_of, in a way. -/
lemma of_function'_supr_measure_of_eq_supr {Ω γ:Type*}
{h:γ → (measure_theory.outer_measure Ω)}:
(λ f:set Ω → ennreal, measure_theory.outer_measure.of_function' f)
(⨆ (i:γ),
(λ μ:measure_theory.outer_measure Ω, μ.measure_of) (h i))
= supr h
:=
begin
apply dual_galois_insertion.l_supr_u',
apply @galois_insertion_measure_of_of_function' Ω,
end
lemma monotone_integral {Ω:Type*} [M:measurable_space Ω]
{μ:measure_theory.measure Ω} {f g:Ω → ennreal}:f ≤ g →
(μ.integral f)≤μ.integral g :=
begin
intro A1,
apply measure_theory.lintegral_mono,
apply A1,
end
lemma monotone_integral' {Ω:Type*} [M:measurable_space Ω]
{μ:measure_theory.measure Ω} {f g:Ω → ennreal}:monotone (μ.integral) :=
begin
apply monotone_integral,
end
-- TODO(martinz): remove measurability requirement?
lemma monotone_with_density {Ω:Type*} [M:measurable_space Ω]
{μ:measure_theory.measure Ω}
{f:ℕ → (Ω → ennreal)}:
monotone f →
(∀ n, measurable (f n)) →
monotone ((μ.with_density) ∘ f) :=
begin
intros B1 B2 a b A1,
intros S A2,
rw measure_theory.with_density_apply2,
rw measure_theory.with_density_apply2,
apply monotone_integral,
apply @monotone_set_indicator Ω ennreal _ _,
apply B1,
apply A1,
--apply B2,
apply A2,
--apply B2,
apply A2,
end
-- Update: I am using this now in R-N theorem.
-- It's not clear to me anymore that this is necessary.
-- However, I am fairly certain it is true.
-- What is missing is proving that (λ i, with_density (h i)) itself is a
-- monotone. It is also probably useful.
lemma supr_with_density_eq_with_density_supr {Ω:Type*} [M:measurable_space Ω]
{μ:measure_theory.measure Ω}
{h:ℕ → Ω → ennreal}:
(∀ n:ℕ, measurable (h n)) →
(monotone h) →
supr (λ n:ℕ, μ.with_density (h n)) = μ.with_density (supr h) :=
begin
intros A1 A2,
apply measure_theory.measure.ext,
intros S A3,
rw ← @supr_with_density_apply_eq_with_density_supr_apply Ω M μ h S A3 A1 A2,
rw measure.apply,
rw ← @supr_eq_supr_to_outer_measure_measure_of_of_monotone' Ω M (λ n, μ.with_density (h n)),
rw supr_apply,
apply @supr_eq_supr ℕ ennreal _,
intro n,
refl,
apply monotone_with_density,
apply A2,
apply A1,
end
-- The nature of this proof suggests the lemma already exists.
lemma measure_theory.measure.sup_le {Ω:Type*} {N:measurable_space Ω} (μ₁ μ₂ ν:measure_theory.measure Ω):μ₁ ≤ ν → μ₂ ≤ ν → μ₁ ⊔ μ₂ ≤ ν :=
begin
intros A1 A2,
simp,
apply and.intro A1 A2,
end
lemma sup_fun_def {Ω:Type*} {f g:Ω → ennreal}:
(f ⊔ g) = λ ω:Ω, f ω ⊔ g ω :=
begin
refl
end
--TODO:remove, trivial?
lemma ennreal.sup_apply {Ω:Type*} {f g:Ω → ennreal} {x:Ω}:
(f ⊔ g) x = f x ⊔ g x :=
begin
apply sup_apply,
end
--Extensible to a (complete?) linear order.
lemma ennreal.lt_sup_iff {a b c:ennreal}:
c < a ⊔ b ↔ c < a ∨ c < b :=
begin
split;intros A1,
{
simp at A1,
apply A1,
},
{
simp,
apply A1,
},
end
lemma measurable_sup {Ω:Type*} {M:measurable_space Ω}
{f g:Ω → ennreal}:measurable f → measurable g →
measurable (f ⊔ g) :=
begin
intros A1 A2,
/- Proof sketch:
x is measurable iff if ∀ a, x⁻¹ (a,⊤] is measurable.
(f ⊔ g)⁻¹ (a,⊤] =f⁻¹ (a,⊤]∪g⁻¹ (a,⊤].
Since the union of two measurable functions is measurable,
we are done.
-/
apply is_ennreal_measurable_intro_Ioi,
intro a,
have A3:(f ⊔ g) ⁻¹' {y : ennreal | a < y}=
f ⁻¹' {y : ennreal | a < y}∪
g ⁻¹' {y : ennreal | a < y},
{
simp,
ext,
split;intros A3A;simp at A3A;simp;apply A3A,
},
rw A3,
apply is_measurable.union,
{
apply A1,
apply is_ennreal_is_measurable_intro_Ioi,
},
{
apply A2,
apply is_ennreal_is_measurable_intro_Ioi,
},
end
--Could remove, but let's leave it here for now.
lemma ennreal.is_measurable_le {Ω:Type*} {M:measurable_space Ω}
{x y:Ω → ennreal}:measurable x → measurable y →
is_measurable {ω:Ω|x ω ≤ y ω} :=
begin
intros A1 A2,
apply is_measurable_le A1 A2,
end
lemma with_density_le_with_density {Ω:Type*} {M:measurable_space Ω}
{μ:measure_theory.measure Ω} {x y:Ω → ennreal}
{S:set Ω}:
is_measurable S →
(∀ ω ∈ S, x ω ≤ y ω) →
μ.with_density x S ≤ μ.with_density y S :=
begin
intros A3 A4,
rw measure_theory.with_density_apply2 μ x S A3,
rw measure_theory.with_density_apply2 μ y S A3,
apply integral.monotone,
rw le_func_def2,
intros ω,
cases (classical.em (ω ∈ S)) with A5 A5,
{
rw set.indicator_of_mem A5,
rw set.indicator_of_mem A5,
apply A4 _ A5,
},
{
rw set.indicator_of_not_mem A5,
rw set.indicator_of_not_mem A5,
apply le_refl _,
},
end
--TODO(martinz): Remove measurability?
lemma with_density_sup_of_le {Ω:Type*} {M:measurable_space Ω}
{μ:measure_theory.measure Ω} {x y:Ω → ennreal}
{S:set Ω}:measurable x → measurable y →
is_measurable S →
(∀ ω ∈ S, x ω ≤ y ω) →
μ.with_density (x⊔y) S = μ.with_density y S :=
begin
intros A1 A2 A3 A4,
rw measure_theory.with_density_apply2 μ (x ⊔ y) S A3,
rw measure_theory.with_density_apply2 μ y S A3,
have A5:set.indicator S (x ⊔ y) = set.indicator S y,
{
apply funext,
intro ω,
cases (classical.em (ω∈ S)) with A5A A5A,
{
rw set.indicator_of_mem A5A,
rw set.indicator_of_mem A5A,
rw sup_apply,
simp,
apply max_eq_right (A4 _ A5A),
--simp,
},
{
rw set.indicator_of_not_mem A5A,
rw set.indicator_of_not_mem A5A,
},
},
rw A5,
end
lemma measure_theory.measure.sup_le_apply {Ω:Type*}
{M:measurable_space Ω}
{μ ν m:measure_theory.measure Ω}
{S:set Ω}:is_measurable S →
(μ ≤ m) →
(ν ≤ m) →
(μ ⊔ ν) S ≤ m S :=
begin
intros A1 A2 A3,
have A4:μ ⊔ ν ≤ m :=
@sup_le (measure_theory.measure Ω) _ μ ν m A2 A3,
apply A4,
apply A1,
end
------------------------------------------------
--No such (sane) set exists, certainly not if μ and ν are finite.
--Note that we don't make the system inconsistent
--by constructing a definition that is possibly unsatisfiable.
--The general idea that we want to prove is that if μ X < ν X,
--then there must be some pure set X'⊆ X, where for all subsets
-- X''⊆ X', μ X'' ≤ ν X'', and μ X' < ν X'. A hahn crazy set
--is a counterexample to this theorem.
def hahn_crazy_set {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):Prop :=
(μ X < ν X) ∧
is_measurable X ∧
(∀ X':set α, (X' ⊆ X) → (μ X' < ν X') →
¬ (le_on_subsets μ ν X'))
lemma hahn_crazy_set_def {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):
hahn_crazy_set μ ν X =
((μ X < ν X) ∧
is_measurable X ∧
(∀ X':set α, (X' ⊆ X) → (μ X' < ν X') →
¬ (le_on_subsets μ ν X'))) := rfl
lemma measure_theory.measure_diff' {α:Type*}
[measurable_space α] {μ:measure_theory.measure α}
{s₁ s₂:set α}:s₂ ⊆ s₁ → is_measurable s₁ →
is_measurable s₂ → μ s₂ < ⊤ →
μ (s₁ \ s₂) = μ s₁ - μ s₂ :=
begin
apply measure_theory.measure_diff,
end
--The contradiction proofs chip away at this set. This
--theorem shows that when you chip a piece off a crazy set,
--a crazy set remains.
lemma hahn_crazy_set_subset {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α)
(X:set α) (X':set α):
hahn_crazy_set μ ν X →
X' ⊆ X →
is_measurable X' →
--μ X' < ⊤ →
ν X' ≤ μ X' →
hahn_crazy_set μ ν (X\X') :=
begin
intros A1 A2 A3 A5,
rw hahn_crazy_set_def at A1,
have A4:μ X' < ⊤,
{
have A4A:μ X' ≤ μ X,
{
apply measure_theory.measure_mono A2,
},
apply lt_of_le_of_lt A4A,
apply lt_of_lt_of_le A1.left,
apply @le_top ennreal _,
--A1.left,
},
have B1:is_measurable (X \ X'),
{
apply is_measurable.diff A1.right.left A3,
},
have B2:μ (X \ X') < ν (X \ X'),
{
rw measure_theory.measure_diff' A2 A1.right.left A3 A4,
rw measure_theory.measure_diff' A2 A1.right.left A3
(lt_of_le_of_lt A5 A4),
-- ⊢ ⇑μ X - ⇑μ X' < ⇑ν X - ⇑ν X'
apply ennreal.sub_lt_sub_of_lt_of_le,
{ -- ⊢ ⇑μ X < ⇑ν X
apply A1.left,
},
{ -- ⊢ ⇑ν X' ≤ ⇑μ X'
apply A5,
},
{ -- ⊢ ⇑μ X' ≤ ⇑μ X
apply (measure_theory.measure_mono A2),
},
},
rw hahn_crazy_set_def,
apply and.intro B2,
apply and.intro B1,
intros X'' C1 C2,
apply A1.right.right,
apply @set.subset.trans α X'' (X \ X') X C1,
apply set.diff_subset,
apply C2,
end
lemma hahn_crazy_set_self {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α)
(X:set α):hahn_crazy_set μ ν X →
¬le_on_subsets μ ν X :=
begin
intros A1,
rw hahn_crazy_set_def at A1,
apply A1.right.right X (set.subset.refl _) A1.left,
end
--In a hahn_crazy_set μ ν X, you will find sets X'⊆ X where ν X' < μ X',
--even though μ X < ν X. So, by creating X - X', you get an even crazier
--set. In hahn_crazy_diff_big below, we show how we can select an element
--that is big ENOUGH.
def hahn_crazy_diff_set {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α)
(X:set α):set (set α) := { X':set α|X' ⊆ X ∧ is_measurable X' ∧
μ X' < ν X'}
lemma hahn_crazy_diff_set_def {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):hahn_crazy_diff_set μ ν X =
{ X':set α|X' ⊆ X ∧ is_measurable X' ∧ μ X' < ν X'} := rfl
lemma hahn_crazy_diff_set_nonempty {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):is_measurable X →
¬le_on_subsets ν μ X →
(hahn_crazy_diff_set μ ν X).nonempty :=
begin
intros A1 A2,
rw ← set.ne_empty_iff_nonempty,
intro A3,
apply A2,
rw le_on_subsets_def,
apply and.intro A1,
intros X' B1 B2,
rw hahn_crazy_diff_set_def at A3,
apply @le_of_not_lt ennreal _,
intro C1,
rw set.eq_empty_iff_forall_not_mem at A3,
have C2 := A3 X',
simp at C2,
have C3 := C2 B1 B2,
apply not_lt_of_le C3 C1,
end
lemma hahn_crazy_diff_set_nonempty' {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):
hahn_crazy_set ν μ X →
(hahn_crazy_diff_set μ ν X).nonempty :=
begin
intros A1,
apply hahn_crazy_diff_set_nonempty,
have A2 := (hahn_crazy_set_def ν μ X).mp A1,
apply A2.right.left,
apply hahn_crazy_set_self,
apply A1,
end
lemma pred_eq_set {α:Type*} {S:set α} {a:α}:
(S a) = (a∈ S) := rfl
lemma nat.find_spec_set {S : set ℕ} [_inst_1 : decidable_pred S] (H : ∃ (n : ℕ), S n):(nat.find H) ∈ S :=
begin
rw ← pred_eq_set,
apply nat.find_spec,
end
lemma nat.Inf_of_nonempty {S:set ℕ}:S.nonempty → Inf S ∈ S :=
begin
intro A1,
have A2:=set.nonempty_def.mp A1,
rw nat.Inf_def A2,
have A3:decidable_pred S := classical_set ℕ S,
apply nat.find_spec_set,
end
lemma nat.exists_le_Inf_map
{α:Type*} {f:α → ℕ} {S:set α}:S.nonempty → ∃ s∈ S,
∀ a∈ S, f s ≤ f a :=
begin
intro A1,
let n := Inf (f '' S),
begin
have A2:(f '' S).nonempty,
{
apply set.nonempty_image_of_nonempty A1,
},
have A3 := nat.Inf_of_nonempty A2,
simp at A3,
cases A3 with a A3,
apply exists.intro a,
apply exists.intro A3.left,
intros b B1,
rw A3.right,
apply nat.Inf_le,
simp,
apply exists.intro b,
apply and.intro B1,
refl,
end
end
lemma nat.le_Inf {S:set ℕ} {a:ℕ}:S.nonempty → (∀ s∈ S,
a ≤ s) → a ≤ Inf S :=
begin
intros A1 A2,
apply A2,
apply nat.Inf_of_nonempty A1,
end
lemma nat.exists_eq_Inf_map {α:Type*} {f:α → ℕ} {S:set α}:S.nonempty →
∃ s∈ S, f s = Inf (f '' S) :=
begin
intros A1,
have B1:(f '' S).nonempty,
{
apply set.nonempty_image_of_nonempty A1,
},
have B2 := nat.Inf_of_nonempty B1,
simp at B2,
cases B2 with a B2,
cases B2 with B2 B3,
apply exists.intro a,
apply exists.intro B2,
apply B3,
end
--Notice that this function chooses the minimum n that is greater than or equal to the inverse.
--Put another way, this chooses the maximum 1/n that is less than or equal to the value.
noncomputable def floor_simple_fraction (x:ennreal):ℕ := Inf {n:ℕ|(n:ennreal) ≥ x⁻¹}
--This is a way of selecting a "big" input of a function when it is hard to select a maximum
--input. Because we are mapping the extended non-negative reals onto the naturals with a
--monotonically decreasing function, and for any nonempty set of natural numbers there is
--a minimum, we get a set of "big" inputs to the function, and we apply classical.some, we
--get one of these values.
--
--This is good for showing progress: if we whittle away something, and get smaller and
--smaller results, we eventually grab every nonzero result remaining.
lemma hahn_infi_ennreal {α:Type*} {f:α→ ennreal} (S:set α):S.nonempty →
∃ a∈ S,
(floor_simple_fraction ∘ f) a = Inf ((floor_simple_fraction ∘ f) '' S) :=
begin
intro A1,
apply nat.exists_eq_Inf_map,
apply A1,
end
/-
When we start with some hahn_crazy_set μ ν X, we know μ X < ν X. We want to
grab a big chunk X' where ν X' < μ X'. This can only go on for so long.
NOTE: there WAS a sign mistake here, where I flipped μ and ν in the difference.
-/
def hahn_crazy_diff_big {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α) (H:hahn_crazy_set μ ν X):set α :=
classical.some
(@hahn_infi_ennreal (set α) (λ X':set α, μ X' - ν X')
(hahn_crazy_diff_set ν μ X) (hahn_crazy_diff_set_nonempty' ν μ X H))
lemma hahn_crazy_diff_big_def {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α) (H:hahn_crazy_set μ ν X):hahn_crazy_diff_big μ ν X H =
classical.some
(@hahn_infi_ennreal (set α) (λ X':set α, μ X' - ν X')
(hahn_crazy_diff_set ν μ X) (hahn_crazy_diff_set_nonempty' ν μ X H)) := rfl
lemma hahn_crazy_diff_big_spec {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α) (H:hahn_crazy_set μ ν X):
(hahn_crazy_diff_big μ ν X H) ∈
(hahn_crazy_diff_set ν μ X) ∧
(floor_simple_fraction ∘ (λ X':set α, μ X' - ν X')) (hahn_crazy_diff_big μ ν X H)
= Inf ((floor_simple_fraction ∘ (λ X':set α, μ X' - ν X'))''(hahn_crazy_diff_set ν μ X)) :=
begin
let f := (λ X':set α, μ X' - ν X'),
let S := (hahn_crazy_diff_set ν μ X),
let P := (λ (a:set α),
(∃ (H:a∈ hahn_crazy_diff_set ν μ X),
(floor_simple_fraction ∘ f)
a =
Inf ((floor_simple_fraction ∘ f) '' S))),
begin
have A1: f = (λ X':set α, μ X' - ν X') := rfl,
have A2: S = (hahn_crazy_diff_set ν μ X) := rfl,
have A3: P = (λ (a:set α),
(∃ (H:a∈ hahn_crazy_diff_set ν μ X),
(floor_simple_fraction ∘ f)
a =
Inf ((floor_simple_fraction ∘ f) '' S))) := rfl,
have B1:(λ (a:set α),
(∃ (H:a∈ hahn_crazy_diff_set ν μ X),
(floor_simple_fraction ∘ f)
a =
Inf ((floor_simple_fraction ∘ f) '' S)))
(hahn_crazy_diff_big μ ν X H),
{
rw hahn_crazy_diff_big_def,
have B1A:∃ y:set α, P y,
{
rw A3,
apply hahn_infi_ennreal,
apply hahn_crazy_diff_set_nonempty,
{
rw hahn_crazy_set_def at H,
apply H.right.left,
},
{
apply hahn_crazy_set_self,
apply H,
},
},
apply @classical.some_spec (set α) P B1A,
},
cases B1 with B1 B2,
split,
apply B1,
apply B2
end
end
lemma hahn_crazy_diff_big_Inf {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α) (H:hahn_crazy_set μ ν X):
(floor_simple_fraction ∘ (λ X':set α, μ X' - ν X')) (hahn_crazy_diff_big μ ν X H)
= Inf ((floor_simple_fraction ∘ (λ X':set α, μ X' - ν X'))''(hahn_crazy_diff_set ν μ X)) :=
begin
have A1 := hahn_crazy_diff_big_spec μ ν X H,
apply A1.right,
end
lemma hahn_crazy_diff_big_mem {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α) (H:hahn_crazy_set μ ν X):
(hahn_crazy_diff_big μ ν X H) ∈ (hahn_crazy_diff_set ν μ X) :=
begin
have A1 := hahn_crazy_diff_big_spec μ ν X H,
apply A1.left,
end
lemma lt_of_hahn_crazy_diff_big {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α) (H:hahn_crazy_set μ ν X):
ν (hahn_crazy_diff_big μ ν X H) < μ (hahn_crazy_diff_big μ ν X H) :=
begin
have A1 := hahn_crazy_diff_big_mem μ ν X H,
rw hahn_crazy_diff_set_def at A1,
simp at A1,
apply A1.right.right,
end
lemma hahn_crazy_set_of_hahn_crazy_diff_big {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:set α) (H:hahn_crazy_set μ ν X):
(hahn_crazy_set μ ν (X \ (hahn_crazy_diff_big μ ν X H))) :=
begin
have B1:=hahn_crazy_diff_big_mem μ ν X H,
rw hahn_crazy_diff_set_def at B1,
simp at B1,
apply hahn_crazy_set_subset,
{
apply H,
},
{
-- ⊢ hahn_crazy_diff_big μ ν X H ⊆ X
apply B1.left,
},
{
apply B1.right.left,
},
{
apply le_of_lt B1.right.right,
},
end
--open subtype
def next_hahn_crazy_set {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:subtype (hahn_crazy_set μ ν)):
subtype (hahn_crazy_set μ ν) := subtype.mk
(X.1 \ (hahn_crazy_diff_big μ ν X.1 X.2))
(hahn_crazy_set_of_hahn_crazy_diff_big μ ν X.1 X.2)
lemma next_hahn_crazy_set_val {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (S:set α) (H:hahn_crazy_set μ ν S):
((next_hahn_crazy_set μ ν (subtype.mk S H)):set α) =
(S \ (hahn_crazy_diff_big μ ν S H)) := rfl
lemma set.diff_diff_eq_of_subset {α:Type*} (S T:set α):S ⊆ T →
T \ (T \ S) = S :=
begin
intro A1,
ext a,split;intros B1,
{
rw set.mem_diff at B1,
cases B1 with B1 B2,
rw set.mem_diff at B2,
simp at B2,
apply B2 B1,
},
{
simp,
rw set.subset_def at A1,
apply and.intro (A1 a B1),
intro C1,
apply B1,
},
end
lemma next_hahn_crazy_set_diff {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (S:set α) (H:hahn_crazy_set μ ν S):
S \ (next_hahn_crazy_set μ ν (subtype.mk S H)) =
(hahn_crazy_diff_big μ ν S H) :=
begin
rw next_hahn_crazy_set_val,
apply set.diff_diff_eq_of_subset (hahn_crazy_diff_big μ ν S H) S,
have B1:=hahn_crazy_diff_big_mem μ ν S H,
rw hahn_crazy_diff_set_def at B1,
cases B1 with B1 B2,
apply B1,
end
/-
begin
refl
end-/
def nth_hahn_crazy_set {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) (X:subtype (hahn_crazy_set μ ν)):
ℕ → subtype (hahn_crazy_set μ ν)
| 0 := X
| (nat.succ n) := next_hahn_crazy_set μ ν (nth_hahn_crazy_set n)
lemma neg_monotone_of_succ_le {α:Type*} [partial_order α] {f:ℕ → α}:
(∀ n:ℕ, f (n.succ) ≤ f n) →
(∀ i j, i ≤ j → f j ≤ f i) :=
begin
intros A1,
intros i j,
induction j,
{
intro B1,
simp at B1,
subst i,
},
{
intro C1,
cases C1 with C1 C1,
apply le_refl _,
have C2 := j_ih C1,
apply le_trans (A1 j_n) C2,
},
end
lemma measure_Inter_eq_infi_nat' {α:Type*} [measurable_space α]
{μ:measure_theory.measure α} {f:ℕ → set α}:
(∀ n:ℕ, f n.succ ⊆ f n) →
(∀ n, is_measurable (f n)) →
(μ (f 0) < ⊤) →
μ (⋂ n, f n) = ⨅ n, μ (f n) :=
begin
intros A1 A2 A3,
apply measure_theory.measure_Inter_eq_infi_nat,
apply A2,
{
intros i j B1,
have B2:∀ n:ℕ, f (n.succ) ≤ f n,
{
intro n,
apply A1 n,
},
apply neg_monotone_of_succ_le B2 i j B1,
},
apply exists.intro 0,
apply A3,
end
lemma measure_monotone_finite {α:Type*} [measurable_space α]
{μ:measure_theory.measure α} {f:ℕ → set α}:
(∀ n:ℕ, f n.succ ⊆ f n) →
(∀ n, is_measurable (f n)) →
(μ (f 0) < ⊤) →
(∀ n, μ (f n) < ⊤) :=
begin
intros A1 A2 A3,
intro n,
induction n,
{
apply A3,
},
{
have B1:μ (f (n_n.succ)) ≤ μ (f (n_n)),
{
apply measure_theory.measure_mono,
apply A1,
},
apply lt_of_le_of_lt B1,
apply n_ih,
},
end
--∀ᶠ
--All of the variants of has_classical_limit follow easily from this.
lemma has_classical_limit_nonneg {β:Type*} [ordered_add_comm_monoid β] [topological_space β]
[order_topology β]
[t2_space β] (f:ℕ → β) (v:β):(0≤ f) →
(∀ z<v, ∃ m, z < (finset.sum (finset.range m) f)) →
(∀ m', (finset.sum (finset.range m') f) ≤ v) →
has_sum f v
:=
begin
intros A1 A2 A3,
unfold has_sum,
rw tendsto_order,
split,
{
intros x B1,
rw filter.eventually_iff,
simp,
have B2 := A2 x B1,
cases B2 with m B2,
apply exists.intro (finset.range m),
intros T B3,
apply lt_of_lt_of_le B2,
apply finset.sum_monotone_of_nonnegative A1 B3,
},
{
intros b C1,
rw filter.eventually_iff,
simp,
apply exists.intro finset.empty,
intros T C2,
apply lt_of_le_of_lt _ C1,
have C3:∃ m, T ⊆ (finset.range m) := finset_range_bound T,
cases C3 with m C3,
apply le_trans _ (A3 m),
apply finset.sum_monotone_of_nonnegative A1 C3,
},
end
--Not quite the classical way of thinking about a limit, but
--more practical for nonnegative sums.
--See has_classical_limit_nnreal'
lemma has_classical_limit_ennreal (f:ℕ → ennreal) (v:ennreal):
(∀ z<v, ∃ m, z < (finset.sum (finset.range m) f)) →
(∀ m', (finset.sum (finset.range m') f) ≤ v) →
has_sum f v
:=
begin
intros A1 A2,
apply has_classical_limit_nonneg,
{
apply @nonnegative_fn ℕ ennreal _,
},
{
apply A1,
},
{
apply A2,
},
end
lemma ennreal_telescope_helper2 {f:ℕ → ennreal} {m:ℕ}:
(∀ n:ℕ, f n.succ ≤ f n) →
(f 0) - (f m) = (finset.range m).sum (λ n, (f n) - (f n.succ)) :=
begin
intros A1,
induction m,
{
simp,
},
{
rw finset.range_succ,
simp,
rw ← m_ih,
rw add_comm,
symmetry,
apply ennreal.sub_add_sub,
apply A1,
apply neg_monotone_of_succ_le A1,
simp,
},
end
lemma Inf_lt {α:Type*} [complete_linear_order α]
{S:set α} {z:α}:S.nonempty →
Inf S < z → ∃ s∈ S, s < z :=
begin
intros A1 A2,
apply classical.exists_of_not_forall_not,
intro A3,
have A4:z ≤ Inf S,
{
apply @le_Inf α _ _,
intros b A4A,
have A4B := A3 b,
rw not_exists_iff_forall_not at A4B,
have A4C := A4B A4A,
apply le_of_not_lt A4C,
},
apply not_lt_of_le A4,
apply A2,
end
lemma infi_lt {α β:Type*} [nonempty α] [complete_linear_order β]
{f:α → β} {z:β}:
infi f < z → ∃ a, f a < z :=
begin
intro A1,
have B1:(set.range f).nonempty,
{
apply set.range_nonempty,
},
have B2:(Inf (set.range f)) < z,
{
unfold infi at A1,
apply A1,
},
have B3:=Inf_lt B1 B2,
cases B3 with x B3,
cases B3 with B3 B4,
cases B3 with a B3,
apply exists.intro a,
subst x,
apply B4,
end
lemma ennreal_infi_diff {f:ℕ → ennreal} {z:ennreal}:z < f 0 - infi f →
∃ n, z < f 0 - f n :=
begin
intros A1,
have B1:infi f ≤ f 0 := @infi_le ennreal _ _ f 0,
have B2:= ennreal.add_lt_of_lt_sub A1,
rw add_comm at B2,
have B3 := ennreal.lt_sub_of_add_lt B2,
have B4 := infi_lt B3,
cases B4 with n B4,
apply exists.intro n,
apply ennreal.lt_sub_of_add_lt,
rw add_comm,
apply ennreal.add_lt_of_lt_sub,
apply B4,
end
lemma ennreal_telescope_helper {f:ℕ → ennreal}:
(∀ n:ℕ, f n.succ ≤ f n) →
(f 0) - (infi f) = (∑' n, (f n) - (f n.succ)) :=
begin
intro A1,
symmetry,
rw ← summable.has_sum_iff (ennreal.summable),
apply has_classical_limit_ennreal,
{
intros z B1,
have B2 := ennreal_infi_diff B1,
cases B2 with n B2,
apply exists.intro n,
rw ← ennreal_telescope_helper2 A1,
apply B2,
},
{
intro m,
rw ← ennreal_telescope_helper2 A1,
simp,
apply ennreal.le_sub_add,
apply @infi_le ennreal ℕ _,
apply neg_monotone_of_succ_le A1,
simp,
},
end
lemma ennreal_telescope {f:ℕ → ennreal}:
(∀ n:ℕ, f n.succ ≤ f n) →
(f 0) = (∑' n, (f n) - (f n.succ)) + (infi f) :=
begin
intros A1,
have B1 := ennreal_telescope_helper A1,
rw add_comm,
apply ennreal.eq_add_of_sub_eq _ B1,
apply @infi_le ennreal _ _,
end
lemma measure_Inter_telescope {α:Type*} [measurable_space α]
{μ:measure_theory.measure α} {f:ℕ → set α}:
(∀ n:ℕ, f n.succ ⊆ f n) →
(∀ n, is_measurable (f n)) →
(μ (f 0) < ⊤) →
μ (f 0) = (∑' n, μ (f n \ (f (n.succ)))) + μ (⋂ n, f n) :=
begin
intros A1 A2 A3,
rw measure_Inter_eq_infi_nat' A1 A2 A3,
have B1:(λ n, μ (f n \ (f (n.succ))))=(λ n, μ (f n) - μ (f (n.succ))),
{
apply funext,
intro n,
have B1A:μ (f n \ f (n.succ))=μ (f n \ (f (n.succ))) := rfl,
rw B1A,
rw measure_theory.measure_diff,
apply A1,
apply A2,
apply A2,
apply measure_monotone_finite A1 A2 A3,
},
rw B1,
apply @ennreal_telescope (μ ∘ f),
intro n,
apply measure_theory.measure_mono,
apply A1,
end
lemma measure_Inter_telescope' {α:Type*} [measurable_space α]
{μ:measure_theory.measure α} {f:ℕ → set α}:
(∀ n:ℕ, f n.succ ⊆ f n) →
(∀ n, is_measurable (f n)) →
(μ (f 0) < ⊤) →
μ (⋂ n, f n) =
μ (f 0) - (∑' n, μ (f n \ (f (n.succ)))) :=
begin
intros A1 A2 A3,
have B1 := measure_Inter_telescope A1 A2 A3,
rw B1,
rw add_comm,
simp,
rw ennreal.add_sub_cancel,
rw B1 at A3,
apply lt_of_le_of_lt _ A3,
apply @le_add_nonnegative ennreal _ _ _,
end
lemma lt_Sup {α:Type*} [complete_linear_order α]
{S:set α} {z:α}:S.nonempty →
z < Sup S → ∃ s∈ S, z < s :=
begin
intros A1 A2,
apply classical.exists_of_not_forall_not,
intro A3,
have A4:Sup S ≤ z,
{
apply @Sup_le α _ _,
intros b A4A,
have A4B := A3 b,
rw not_exists_iff_forall_not at A4B,
have A4C := A4B A4A,
apply le_of_not_lt A4C,
},
apply not_lt_of_le A4,
apply A2,
end
lemma lt_supr {α β:Type*} [nonempty α] [complete_linear_order β]
{f:α → β} {z:β}:
z < supr f → ∃ a, z < f a :=
begin
intro A1,
have B1:(set.range f).nonempty,
{
apply set.range_nonempty,
},
have B2:z < (Sup (set.range f)),
{
unfold supr at A1,
apply A1,
},
have B3:= lt_Sup B1 B2,
cases B3 with x B3,
cases B3 with B3 B4,
cases B3 with a B3,
apply exists.intro a,
subst x,
apply B4,
end
--This is true WITHOUT the non-negative part. So long as the sum is
--well-defined, this should be true.
--Revisit later (and search mathlib).
lemma ennreal.tendsto_zero_of_finite_sum (f:ℕ → ennreal):tsum f < ⊤ →
filter.tendsto f filter.at_top (nhds 0) :=
begin
intro A1,
rw tendsto_order,
split,
{
intros a B1,
exfalso,
simp at B1,
apply B1,
},
{
intros x C1,
rw filter.eventually_iff,
simp,
have C2:=ennreal.exists_coe A1,
cases C2 with v C2,
have C5:(⨆ n, (finset.range n).sum f) = (v:ennreal),
{
rw ennreal.lim_finset_sum_eq_tsum,
apply C2,
},
cases (lt_or_le x (v:ennreal)) with C4 C4,
{ -- C4 : a < ↑v
have D1:(v:ennreal) - x < (⨆ (n : ℕ), (finset.range n).sum f),
{
rw C5,
simp,
apply ennreal.coe_sub_lt_self,
have D1A:0 < (v:ennreal),
{
apply lt_trans C1 C4,
},
simp at D1A,
apply D1A,
apply C1,
},
have D2 := lt_supr D1,
cases D2 with b D2,
apply exists.intro b,
intros c D3,
have D4:(finset.range (c.succ)).sum f ≤ (v:ennreal),
{
rw ← C5,
apply @le_supr ennreal ℕ _,
},
have D5:0 ≤ b,
{
simp,
},
have D6:b ≤ c.succ,
{
apply le_trans D3,
apply nat.le_succ,
},
rw ← finset.Ico.zero_bot at D4,
have D7:disjoint (finset.Ico 0 b) (finset.Ico b c.succ),
{
apply finset.Ico.disjoint_consecutive,
},
rw ← finset.Ico.union_consecutive D5 D6 at D4,
rw finset.sum_union D7 at D4,
rw finset.Ico.zero_bot at D4,
-- b' + c'' ≤ v
-- c' ≤ c''
-- v - x < b'
-- ⊢ c' < x
-- Working here.
have D8:f c ≤ (finset.Ico b c.succ).sum f,
{
apply @finset.element_le_sum ℕ ennreal _ _,
{
simp [D3,lt_succ],
},
},
have D9:(v:ennreal) < ⊤,
{
simp,
},
apply ennreal.lt_of_add_le_of_le_of_sub_lt D9 D4 D8 D2,
},
cases (@eq_or_ne nnreal _ v 0) with C6 C6,
{
subst v,
apply exists.intro 0,
intros n E1,
simp at C5,
have E2:(finset.range (n.succ)).sum f ≤ 0,
{
rw ← C5,
apply @le_supr ennreal ℕ _,
},
--have E3:
simp at C1,
apply lt_of_le_of_lt _ C1,
apply le_trans _ E2,
apply @finset.element_le_sum ℕ ennreal _ _ _ n f,
{
simp,
},
},
{
have F1:0 < v,
{
rw lt_iff_le_and_ne,
split,
simp,
symmetry,
apply C6,
},
have F2:0 < (⨆ (n : ℕ), (finset.range n).sum f),
{
rw C5,
simp,
apply F1,
},
--have F3 := lt_supr F2,
have F3 := lt_supr F2,
cases F3 with a F3,
apply exists.intro a,
intros b F4,
apply lt_of_lt_of_le _ C4,
have F5:(finset.range (b.succ)).sum f ≤ (v:ennreal),
{
rw ← C5,
apply @le_supr ennreal ℕ _,
},
have F6:0 ≤ a,
{
simp,
},
have F7:a ≤ b.succ,
{
apply le_trans F4,
apply nat.le_succ,
},
rw ← finset.Ico.zero_bot at F5,
have F8:disjoint (finset.Ico 0 a) (finset.Ico a b.succ),
{
apply finset.Ico.disjoint_consecutive,
},
rw ← finset.Ico.union_consecutive F6 F7 at F5,
rw finset.sum_union F8 at F5,
rw finset.Ico.zero_bot at F5,
--apply ennreal.lt_of_add_le_of_le_of_sub_lt D9 D4 D8 D2,
have F9:f b ≤ (finset.Ico a b.succ).sum f,
{
apply @finset.element_le_sum ℕ ennreal _ _,
{
simp [F4,lt_succ],
},
},
have F10:(v:ennreal) < ⊤,
{
simp,
},
have F11: (finset.range a).sum (λ (x : ℕ), f x) + f b ≤ ↑v,
{
apply le_trans _ F5,
apply add_le_add_left F9,
--apply add_le_add_of_le,
},
apply ennreal.lt_of_lt_top_of_add_lt_of_pos F10 F11 F3,
},
},
end
lemma filter.tendsto_const {α β:Type*} [topological_space β]
{v:β} {F:filter α}:
filter.tendsto (λ n:α, v) F (nhds v) :=
begin
unfold filter.tendsto,
unfold filter.map,
unfold nhds,
simp,
intros S B1 B2,
have C1:(λ n:α, v) ⁻¹' S = set.univ,
{
ext;split;intro C1A,
simp,
simp,
apply B1,
},
rw C1,
apply filter.univ_sets,
end
lemma filter.tendsto_le {α β:Type*} [topological_space β]
[partial_order β] [order_topology β] {F:filter α}
{f g h:α → β} {v:β}:
f ≤ g →
g ≤ h →
filter.tendsto f F (nhds v) →
filter.tendsto h F (nhds v) →
filter.tendsto g F (nhds v) :=
begin
intros A1 A2 A3 A4,
rw tendsto_order,
split,
{
intros x B1,
rw filter.eventually_iff,
rw tendsto_order at A3,
have B2 := A3.left x B1,
rw filter.eventually_iff at B2,
have B4: {x_1 : α | x < f x_1}⊆ {x_1 : α | x < g x_1},
{
rw set.subset_def,
intros a B4A,
simp at B4A,
simp,
apply lt_of_lt_of_le B4A (A1 a),
},
apply filter.sets_of_superset F B2 B4,
},
{
intros x B1,
rw filter.eventually_iff,
rw tendsto_order at A4,
have B2 := A4.right x B1,
rw filter.eventually_iff at B2,
have B4: {x_1 : α | h x_1 < x}⊆ {x_1 : α | g x_1 < x},
{
rw set.subset_def,
intros a B4A,
simp at B4A,
simp,
apply lt_of_le_of_lt (A2 a) B4A,
},
apply filter.sets_of_superset F B2 B4,
},
end
--Extend to nonnegative type (well, nnreal).
lemma ennreal.tendsto_le {α:Type*} {F:filter α} {g h:α → ennreal}:
g ≤ h →
filter.tendsto h F (nhds 0) →
filter.tendsto g F (nhds 0) :=
begin
intros A1 A2,
let f:α → ennreal := (λ a:α, 0),
begin
have B1:f = (λ a:α, 0) := rfl,
have B2:f ≤ g,
{
rw B1,
intros a,
simp,
},
have B3:filter.tendsto f F (nhds 0),
{
apply filter.tendsto_const,
},
apply filter.tendsto_le B2 A1 B3 A2,
end
end
lemma set.preimage_subset_preimage_of_subset {α β:Type*} {S T:set α} {f:β → α}:
(S⊆ T)→ set.preimage f S ⊆ set.preimage f T :=
begin
--{x:β |f x ∈ S} ⊆ {x:β |f x ∈ T} :=
intro A1,
have B1:set.preimage f S = {x:β |f x ∈ S} := rfl,
have B2:set.preimage f T = {x:β |f x ∈ T} := rfl,
rw B1,
rw B2,
apply set.preimage_mono,
apply A1,
end
--∀ᶠ (b : ℕ) in filter.at_top, f b < x
lemma tendsto_top {α β:Type*} [NE:nonempty β] [SL:semilattice_sup β] {g:α → β} {F:filter α}:filter.tendsto g F filter.at_top ↔ (∀ b:β, ∀ᶠ (c:α) in F, b ≤ g c) :=
begin
split;intros A1,
{
rw filter.tendsto_iff_eventually at A1,
intro b,apply A1,
rw filter.eventually_iff,
simp,
apply exists.intro b,
intros b_1,
simp,
},
{
rw filter.tendsto_def,
intros S C1,
rw filter.mem_at_top_sets at C1,
cases C1 with a C1,
have C2 := A1 a,
rw filter.eventually_iff at C2,
apply filter.mem_sets_of_superset C2,
apply set.preimage_subset_preimage_of_subset,
rw set.subset_def,
intros b C3,
apply C1,
apply C3,
},
end
lemma tendsto_top' {α β:Type*} [NE:nonempty β] [SL:semilattice_sup β] {g:α → β} {F:filter α}:filter.tendsto g F filter.at_top ↔ (∀ b:β, g⁻¹' {c|b≤ c} ∈ F) :=
begin
rw tendsto_top,
split;intros A1;intros b;have B1 := A1 b,
{
rw filter.eventually_iff at B1,
apply B1,
},
{
rw filter.eventually_iff,
apply B1,
},
end
lemma eventually_at_top_iff {α:Type*} [nonempty α] [semilattice_sup α] {P:α → Prop}:
(∀ᶠ (c:α) in filter.at_top, P c) ↔ ∃ (a : α), ∀ (b : α), b ≥ a → b ∈ {x : α | P x}:=
begin
rw filter.eventually_iff,
split;intros A1,
{
rw filter.mem_at_top_sets at A1,
---cases A1 with a A1,
apply A1,
},
{
rw filter.mem_at_top_sets,
apply A1,
},
end
lemma floor_simple_fraction_def (x:ennreal):floor_simple_fraction x = Inf {n:ℕ|(n:ennreal) ≥ x⁻¹} := rfl
lemma floor_simple_fraction_bound (b:ℕ) (x:ennreal):0 < x →
x < (1/(b:ennreal)) →
b ≤ floor_simple_fraction x :=
begin
intros A1 A2,
cases b,
{
simp,
},
rw floor_simple_fraction_def,
apply @nat.le_Inf,
{
simp,
cases x,
{
simp,
},
simp,
simp at A1,
have A3 := nnreal.exists_unit_frac_lt_pos A1,
cases A3 with a A3,
have A4 := le_of_lt A3,
rw nnreal.inv_as_fraction at A4,
have A6 := nnreal.inverse_le_of_le _ A4,
rw nnreal.inv_inv at A6,
rw set.nonempty_def,
apply exists.intro a.succ,
simp,
rw ← ennreal.coe_inv,
have A7:((a + 1:nnreal):ennreal) = (a:ennreal) + 1,
{
simp,
},
rw ← A7,
rw ennreal.coe_le_coe,
apply A6,
{
intro B1,
subst x,
simp at A1,
apply A1,
},
{
rw nnreal.inv_pos,
rw add_comm,
have B2:(0:nnreal) < (1:nnreal) := zero_lt_one,
apply lt_of_lt_of_le B2,
apply le_add_nonnegative _ _,
},
},
{
intros c C1,
simp at C1,
simp at A2,
have C2:(1:ennreal)/(c:ennreal) ≤ x,
{
rw ennreal.inv_as_fraction,
rw ← @ennreal.inv_inv x,
apply ennreal.inverse_le_of_le,
have C2A:x < ⊤,
{
apply lt_trans A2,
rw ennreal.inv_as_fraction,
simp,
rw add_comm,
apply @lt_of_lt_of_le ennreal _ 0 1 _
(ennreal.zero_lt_one),
apply le_add_nonnegative 1 (b:ennreal),
},
rw lt_top_iff_ne_top at C2A,
rw ← ennreal.inv_pos at C2A,
apply C1,
},
have C3 := lt_of_le_of_lt C2 A2,
have C4 := le_of_lt C3,
rw ennreal.inv_as_fraction at C4,
rw ennreal.inv_as_fraction at C4,
have C5 := ennreal.inverse_le_of_le C4,
rw ennreal.inv_inv at C5,
rw ennreal.inv_inv at C5,
have C6:((1:nat):ennreal) = (1:ennreal),
{
simp,
},
rw ← C6 at C5,
rw ennreal.nat_coe_add at C5,
rw ennreal.nat_coe_le_coe at C5,
apply C5,
},
end
lemma floor_simple_fraction_limit_top {g:ℕ → ennreal}:
(∀ n, 0 < g n) →
filter.tendsto g filter.at_top (nhds 0) →
filter.tendsto (floor_simple_fraction∘ g) filter.at_top filter.at_top :=
begin
intros AX A1,
rw tendsto_order at A1,
cases A1 with A1 A2,
clear A1,
rw tendsto_top,
intro b,
rw eventually_at_top_iff,
have B1:((1:ennreal)/(b.succ:ennreal)) > 0,
{
simp,
have B1A:(b:ennreal) = ((b:nnreal):ennreal),
{
simp,
},
rw B1A,
have B1B:(1:ennreal) = ((1:nnreal):ennreal),
{
simp,
},
rw B1B,
rw ← ennreal.coe_add,
apply ennreal.coe_ne_top,
},
have B2 := A2 ((1:ennreal)/(b.succ:ennreal)) B1,
rw eventually_at_top_iff at B2,
cases B2 with a B2,
apply exists.intro a,
intros c B3,
have B4 := B2 c B3,
simp,
simp at B4,
have B5:b ≤ b.succ,
{
apply nat.le_succ,
},
apply le_trans B5,
apply floor_simple_fraction_bound,
apply AX,
apply B4
end
/-
This is the crux of the hahn decomposition theorem, the key of a proof by induction by
contradiction. We assume that there is a set X where μ X < ν X and v X < ⊤, and there
does not exista a subset X' ⊆ X where μ X' < ν X', where for all X''⊆ X', μ X'' ≤ ν X''.
The proof follows the contradiction part in An Epsilon of Room. If such a hahn crazy set
existed, then we could find a set Y ⊆ X where ν Y < μ Y. And if we subtracted this set
off, we would be back where we started with X-Y being a set where μ (X - Y) < ν (X - Y)
and no subset X' ⊆ X - Y where μ X' < ν X' and le_on_subsets μ ν X'.
What if we want to grab a set Y which maximizes μ Y - ν Y?
Unfortunately, we find this as hard as the entire Hahn decomposition
problem itself. But we don't need to find the biggest one, just one
that is big enough. What follows is one of the most unusual mathematical
tricks I have seen. We basically chunk the reals into (1,∞],(1/2,1],(1/3,1/2],
et cetera. Instead of grabbing the absolute largest element, we grab an
element in the first populated range. Thus, if we do this an infinite number
of times, either the values we get sum to infinity (which they can't),
or each range gets eventually depopulated. Thus, after this point, any remaining
set must have μ Y - ν Y=0, a contradiction.
-/
lemma hahn_crazy_set_not_finite {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (X:set α):
(hahn_crazy_set μ ν X) →
¬(measure_theory.finite_measure ν) :=
begin
intros A1 A2,
let h:ℕ → set α :=
(λ n, (nth_hahn_crazy_set μ ν (subtype.mk X A1) n).val),
let d:ℕ → (set α) :=
λ n, h n \ h (n.succ),
let Z:=⋂ n, (h n),
begin
have B1:h =λ n, (nth_hahn_crazy_set μ ν (subtype.mk X A1) n).val := rfl,
have B2:d = λ n, h (n) \ h (n.succ) := rfl,
have B3:Z = ⋂ n, (h n) := rfl,
have B4:(h 0) = X,
{
rw B1,
refl,
},
have B5:∀ n:ℕ, nth_hahn_crazy_set μ ν (subtype.mk X A1) (nat.succ n)
= next_hahn_crazy_set μ ν (nth_hahn_crazy_set μ ν (subtype.mk X A1) (n)),
{
intro n,
refl,
},
have B6:∀ n:ℕ, h (n.succ) = next_hahn_crazy_set μ ν (nth_hahn_crazy_set μ ν (subtype.mk X A1) (n)),
{
intro n,
rw B1,
refl,
},
have J0:∀ n:ℕ, (hahn_crazy_set μ ν (h n)),
{
intros n,
rw B1,
apply (nth_hahn_crazy_set μ ν (subtype.mk X A1) n).property,
},
have J0B:∀ n:ℕ, h (n.succ) = next_hahn_crazy_set μ ν
(subtype.mk (h n) (J0 n)),
{
intro n,
rw B6,
refl,
},
have J1:∀ n:ℕ, h (n.succ) ⊆ h n,
{
intro n,
rw J0B,
unfold next_hahn_crazy_set,
apply set.diff_subset,
},
have J2:∀ n:ℕ, is_measurable (h n),
{
intro n,
have J2A := J0 n,
rw hahn_crazy_set_def at J2A,
apply J2A.right.left,
},
have C1A:ν (h 0) < ⊤,
{
rw B4,
apply @measure_theory.measure_lt_top α M ν A2 X,
},
have J4:μ (h 0) < ν (h 0),
{
rw B4,
rw hahn_crazy_set_def at A1,
apply A1.left,
},
have C1:ν Z = ν (h 0) - (∑' n, ν (d n)),
{
rw B3,
rw B2,
simp,
apply @measure_Inter_telescope' α M ν h J1 J2 C1A,
},
have C2A:μ (h 0) < ⊤,
{
apply lt_trans J4 C1A,
},
have C2:μ Z = μ (h 0) - (∑' n, μ (d n)),
{
rw B3,
rw B2,
apply @measure_Inter_telescope' α M μ h J1 J2 C2A,
},
have C3C:(∑' (n : ℕ), μ (d n)) ≤ μ (h 0),
{
rw measure_Inter_telescope J1 J2 C2A,
have C3B1:(∑' (n : ℕ), μ (d n)) =
(∑' (n : ℕ), μ (h n \ h n.succ)) := rfl,
rw ← C3B1,
apply le_add_nonnegative _ _,
},
have C3X:(∑' (n : ℕ), ν (d n)) ≤ ν (h 0),
{
rw measure_Inter_telescope J1 J2 C1A,
have C3B1:(∑' (n : ℕ), ν (d n)) =
(∑' (n : ℕ), ν (h n \ h n.succ)) := rfl,
rw ← C3B1,
apply le_add_nonnegative _ _,
},
have C3:μ Z < ν Z,
{
rw C1,
rw C2,
apply ennreal.sub_lt_sub_of_lt_of_le,
{
rw B4,
rw hahn_crazy_set_def at A1,
apply A1.left,
},
{
apply tsum_le_tsum _ ennreal.summable ennreal.summable,
intro n,
rw B2,
simp,
rw J0B,
rw next_hahn_crazy_set_diff,
have C3A1:= hahn_crazy_diff_big_mem μ ν (h n) (J0 n),
rw hahn_crazy_diff_set_def at C3A1,
apply le_of_lt (C3A1.right.right),
},
{
apply C3C,
},
},
have D1:is_measurable Z,
{
apply is_measurable.Inter,
apply J2,
},
have D3:Z ⊆ X,
{
rw B3,
rw ← B4,
simp,
apply set.Inter_subset,
},
have D2:hahn_crazy_set μ ν Z,
{
rw hahn_crazy_set_def,
apply and.intro C3,
apply and.intro D1,
intros X' D2A D2B,
rw hahn_crazy_set_def at A1,
apply A1.right.right,
apply set.subset.trans D2A D3,
apply D2B,
},
have D3:filter.tendsto
(λ n:ℕ, μ (d n)) filter.at_top (nhds 0),
{
--There is a sequence of positive numbers with a finite sum.
--Thus, their limit must be zero.
apply ennreal.tendsto_zero_of_finite_sum,
apply lt_of_le_of_lt C3C C2A,
},
have D3B:filter.tendsto
(λ n:ℕ, ν (d n)) filter.at_top (nhds 0),
{
--This is definitely true, but I am not sure if I need it,
--or D3 above is what is needed. I need to walk through the
--rest of this proof.
apply ennreal.tendsto_zero_of_finite_sum,
apply lt_of_le_of_lt C3X C1A,
},
have D4:filter.tendsto
(λ n:ℕ, Inf ((floor_simple_fraction ∘ (λ X':set α, μ X' - ν X'))
''(hahn_crazy_diff_set ν μ (h n)))) filter.at_top filter.at_top,
{
--I reversed this: I need to figure out if I can make the rest of the proof work.
--Now, I need to reverse it back.
have D4A:(λ n:ℕ, Inf ((floor_simple_fraction ∘ (λ X':set α, μ X' - ν X'))
''(hahn_crazy_diff_set ν μ (h n)))) =
(λ n:ℕ, (floor_simple_fraction ∘ (λ X':set α, μ X' - ν X'))
(hahn_crazy_diff_big μ ν (h n) (J0 n))),
{
-- J0 n:hahn_crazy_set μ ν (h n)
apply funext,
intro n,
symmetry,
apply @hahn_crazy_diff_big_Inf α _ μ ν (h n) (J0 n),
},
have D4B:∀ n, (hahn_crazy_diff_big μ ν (h n) (J0 n)) = d n,
{
intro n,
rw B2,
simp,
rw ← next_hahn_crazy_set_diff,
rw J0B,
},
have D4C:(λ n:ℕ, Inf ((floor_simple_fraction ∘ (λ X':set α, μ X' - ν X'))
''(hahn_crazy_diff_set ν μ (h n)))) =
(λ n:ℕ, (floor_simple_fraction ∘ (λ X':set α, μ X' - ν X'))
(d n)),
{
rw D4A,
apply funext,
intro n,
rw D4B n,
},
have D4E: (λ n:ℕ, (λ X':set α, μ X' - ν X')
(d n)) ≤ (λ n:ℕ, μ (d n)),
{
intro n,
simp,
apply le_add_nonnegative _ _,
},
have D4G:∀ n, ν (d n) < μ (d n),
{
intro n,
rw ← D4B,
apply @lt_of_hahn_crazy_diff_big α _ μ ν (h n),
},
have D4F:filter.tendsto (λ n:ℕ, (λ X':set α, μ X' - ν X')
(d n)) filter.at_top (nhds (0:ennreal)),
{
apply ennreal.tendsto_le D4E D3,
},
rw D4C,
apply floor_simple_fraction_limit_top,
{
intro n,
simp,
rw ← D4B,
apply @lt_of_hahn_crazy_diff_big α _ μ ν (h n),
},
apply D4F,
},
have E1:(hahn_crazy_diff_set ν μ Z).nonempty,
{
apply hahn_crazy_diff_set_nonempty' ν μ Z D2,
},
have E2:∃ S, S∈(hahn_crazy_diff_set ν μ Z),
{
apply set.nonempty_def.mp E1,
},
cases E2 with S E2,
rw hahn_crazy_diff_set_def at E2,
simp at E2,
let n := floor_simple_fraction (μ S - ν S),
begin
have G1:n = floor_simple_fraction (μ S - ν S) := rfl,
have H1: {m:ℕ| n.succ ≤ m} ∈ filter.at_top,
{
apply filter.mem_at_top,
},
have H2 := filter_tendsto_elim D4 H1,
simp at H2,
cases H2 with n2 H2,
have H3 := H2 n2 (le_refl n2),
have H4:Inf ((λ (a : set α), floor_simple_fraction (μ a - ν a)) '' hahn_crazy_diff_set ν μ (h n2))
≤ n,
{
apply nat.Inf_le,
simp,
apply exists.intro S,
split,
{
rw hahn_crazy_diff_set_def,
simp,
split,
{
apply @set.subset.trans α S Z (h n2) E2.left,
rw B3,
apply set.Inter_subset,
},
apply (E2.right),
},
rw G1,
},
have H5 := le_trans H3 H4,
apply not_lt_of_le H5,
apply nat.lt.base,
end
end
end
lemma finite_set_not_hahn_crazy_set {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (X:set α)
[F:measure_theory.finite_measure ν]:
¬ (hahn_crazy_set μ ν X) :=
begin
intros A2,
apply hahn_crazy_set_not_finite μ ν X A2 F,
end
/-
This theorem is a weak variant of hahn_unsigned_inequality_decomp.
However, it probably has uses in its own right, beyond that of
its parent theorem.
-/
lemma hahn_unsigned_inequality_decomp_junior {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) {X:set α} [A1:measure_theory.finite_measure ν]:
(is_measurable X) →
(μ X < ν X) →
(∃ X':set α,
X' ⊆ X ∧
μ X' < ν X' ∧
le_on_subsets μ ν X') :=
begin
intros A2 A3,
have B1:= @finite_set_not_hahn_crazy_set _ _ μ ν X A1,
rw hahn_crazy_set_def at B1,
simp at B1,
apply B1 A3 A2,
end
lemma Sup_apply_eq_supr_apply_of_closed'' {α:Type*}
[complete_lattice α] {S:set α} (g:α → ennreal):
(∀ (a∈ S) (b∈ S), a ≤ b → g a ≤ g b) →
(∀ f:ℕ → α, set.range f ⊆ S → monotone f → (supr f)∈ S) →
(S.nonempty) →
(∀ a ∈ S, ∀ b ∈ S, a ⊔ b ∈ S)→
(∃ f:ℕ → α,
(∀ n, f n ∈ S) ∧
(monotone f) ∧
g (supr f) = Sup (g '' S)) :=
begin
intros A1 AX A2 A3,
have B1:(g '' S).nonempty,
{
apply set.nonempty_image_of_nonempty A2,
},
have B1X := ennreal.Sup_eq_supr B1,
cases B1X with f' B1X,
have B2:∃ f'':ℕ → α, ∀ n:ℕ,
(f'' n)∈ S ∧ g (f'' n) = f' n,
{
apply @classical.some_func ℕ α (λ (n:ℕ) (a:α),
a∈ S ∧ g a = f' n),
intro n,
have B2A:=(B1X.left) n,
simp at B2A,
cases B2A with a B2A,
apply exists.intro a,
simp,
apply B2A,
},
cases B2 with f'' B2,
have C1:∀ (n : ℕ), Sup_so_far f'' n ∈ S,
{
apply Sup_so_far_of_closed,
intro n,
apply (B2 n).left,
apply A3,
},
apply exists.intro (Sup_so_far f''),
split,
{
apply C1,
},
split,
{
apply monotone_Sup_so_far,
},
{
--rw ← AX,
have D1:(supr (Sup_so_far f''))∈ S,
{
apply AX,
{
rw set.subset_def,
intros x D1A,
--apply C1,
simp at D1A,
cases D1A with y D1A,
subst x,
apply C1,
},
apply monotone_Sup_so_far,
},
apply le_antisymm,
{
apply @le_Sup ennreal _ _,
simp,
apply exists.intro (supr (Sup_so_far f'')),
apply and.intro D1,
refl,
},
{
rw ← B1X.right,
apply @supr_le ennreal _ _,
intro i,
rw ← (B2 i).right,
apply A1,
apply (B2 i).left,
apply D1,
have D2:f'' i ≤ (Sup_so_far f'') i,
{
apply le_Sup_so_far,
},
apply le_trans D2,
apply @le_supr _ ℕ _ (Sup_so_far f'') i,
},
},
end
lemma hahn_unsigned_inequality_decomp {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) [A1:measure_theory.finite_measure ν]:
(∃ X:set α, le_on_subsets μ ν X ∧ le_on_subsets ν μ (Xᶜ)) :=
begin
/-
What we want is the argmax of f on S: this is our candidate for X.
However, we must first establish that such an argmax exists.
First, we construct an M that is our candidate for X.
It is the supremum of
-/
let S:set (set α) := {X:set α|le_on_subsets μ ν X},
let f:set α → ennreal := (λ T:set α, (ν T) - (μ T)),
-- M is unused.
let M:ennreal := Sup (f '' S),
begin
have A2:S = {X:set α|le_on_subsets μ ν X} := rfl,
have A3:f = (λ T:set α, (ν T) - (μ T)) := rfl,
have A5:∀ X, le_on_subsets μ ν X → μ X < ⊤,
{
intros X A5A,
apply lt_of_le_of_lt (le_on_subsets_self A5A),
apply measure_theory.measure_lt_top,
},
have A6:∀ T, f T = ν T - μ T,
{
intro T,
refl,
},
have B1:∀ (a∈ S) (b∈ S), a ≤ b → f a ≤ f b,
{
intros T1 B1A T2 B1B B1C,
rw A2 at B1A,
simp at B1A,
rw A2 at B1B,
simp at B1B,
repeat {rw A6},
have B1F:le_on_subsets μ ν (T2 \ T1),
{
apply le_on_subsets_diff B1B B1A,
},
have B1G:T2 = T1 ∪ (T2 \ T1),
{
rw set.union_diff_cancel,
apply B1C,
},
rw B1G,
rw le_on_subsets_add,
apply @le_add_of_nonneg_right ennreal _,
simp,
{
apply A5 T1 B1A,
},
{
apply A5 _ B1F,
},
apply B1A,
apply B1F,
apply set.disjoint_diff,
},
have B2B:(∀ h:ℕ → set α, set.range h ⊆ S → monotone h → (supr h)∈ S),
{
intros h B2C B2D,
rw A2,
rw supr_eq_Union,
apply le_on_subsets_m_Union,
apply B2D,
intro n,
have B2E:h n ∈ S,
{
apply B2C,
simp,
},
rw A2 at B2E,
simp at B2E,
apply B2E,
},
have B3:S.nonempty,
{
apply set.nonempty_of_mem,
rw A2,
simp,
apply le_on_subsets_empty,
},
have B4:(∀ (a ∈ S) (b ∈ S), a ⊔ b ∈ S),
{
rw A2,
simp,
intros a B4A b B4B,
have B4C:a ⊔ b = a ∪ b := rfl,
--rw B4C,
apply le_on_subsets_union B4A B4B,
},
have C1:=@Sup_apply_eq_supr_apply_of_closed'' (set α) _ S f B1 B2B B3 B4,
cases C1 with g C1,
apply exists.intro (supr g),
have C2:le_on_subsets μ ν (supr g),
{
rw supr_eq_Union,
apply le_on_subsets_m_Union,
apply C1.right.left,
intro n,
have D1:=C1.left n,
rw A2 at D1,
apply D1,
},
apply and.intro C2,
-- ⊢ le_on_subsets ν μ (-supr g)
rw le_on_subsets_def,
split,
{
apply is_measurable.compl,
apply le_on_subsets_is_measurable C2,
},
{
intros X' D1 D2,
apply le_of_not_lt _,
intro D3,
have D4:= hahn_unsigned_inequality_decomp_junior μ ν D2 D3,
cases D4 with X'' D4,
have D5:f (X'' ∪ supr g) ≤ f (supr g),
{
rw C1.right.right,
apply @le_Sup ennreal _ _,
simp,
apply exists.intro (X'' ∪ supr g),
split,
{
apply le_on_subsets_union,
apply D4.right.right,
apply C2,
},
refl,
},
repeat {rw A6 at D5},
rw le_on_subsets_add at D5,
repeat {rw ← A6 at D5},
rw add_comm at D5,
apply @ennreal.not_add_le_of_lt_of_lt_top (f (supr g)) (f X'') _ _ _,
{
rw A6,
simp,
apply D4.right.left,
},
{
rw A6,
have D6:ν (supr g) < ⊤,
{
apply measure_theory.measure_lt_top,
},
apply lt_of_le_of_lt _ D6,
simp,
apply ennreal.le_add,
apply le_refl _,
},
apply D5,
apply A5 _ D4.right.right,
apply A5 _ C2,
apply D4.right.right,
apply C2,
{
apply @set.disjoint_of_subset_left _ _ _ ((supr g)ᶜ),
apply set.subset.trans D4.left D1,
apply set.disjoint.symm,
apply set.disjoint_compl,
},
},
end
end
|
e0ddcd19ebad09427b0dcfac36c35e7a998c2052 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /test/units.lean | cddd38d2c293c55e4104983c5d5d003135e591a0 | [
"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 | 250 | lean | import algebra.ring.basic
/--
Test division of units in a commutative ring.
Used to cause `simp` (i.e. instance resolution) to time out.
-/
example (R : Type*) [comm_ring R] (a b : Rˣ) : a * (b / a) = b :=
by simp
-- Or: `rw mul_div_cancel'_right`
|
95d86ff901effb3076db3caac98190aff11238cd | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/finsupp/basic.lean | f18a2a239ace54337ee1391054de6341569860cc | [
"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 | 83,213 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Scott Morrison
-/
import algebra.group.pi
import algebra.big_operators.order
import algebra.module.basic
import algebra.module.pi
import group_theory.submonoid.basic
import data.fintype.card
import data.finset.preimage
import data.multiset.antidiagonal
import data.indicator_function
/-!
# Type of functions with finite support
For any type `α` and a type `M` with zero, we define the type `finsupp α M` (notation: `α →₀ M`)
of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere
on `α` except on a finite set.
Functions with finite support are used (at least) in the following parts of the library:
* `monoid_algebra R M` and `add_monoid_algebra R M` are defined as `M →₀ R`;
* polynomials and multivariate polynomials are defined as `add_monoid_algebra`s, hence they use
`finsupp` under the hood;
* the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to
define linearly independent family `linear_independent`) is defined as a map
`finsupp.total : (ι → M) → (ι →₀ R) →ₗ[R] M`.
Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined
in a different way in the library:
* `multiset α ≃+ α →₀ ℕ`;
* `free_abelian_group α ≃+ α →₀ ℤ`.
Most of the theory assumes that the range is a commutative additive monoid. This gives us the big
sum operator as a powerful way to construct `finsupp` elements.
Many constructions based on `α →₀ M` use `semireducible` type tags to avoid reusing unwanted type
instances. E.g., `monoid_algebra`, `add_monoid_algebra`, and types based on these two have
non-pointwise multiplication.
## Notations
This file adds `α →₀ M` as a global notation for `finsupp α M`. We also use the following convention
for `Type*` variables in this file
* `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `finsupp`
somewhere in the statement;
* `ι` : an auxiliary index type;
* `M`, `M'`, `N`, `P`: types with `has_zero` or `(add_)(comm_)monoid` structure; `M` is also used
for a (semi)module over a (semi)ring.
* `G`, `H`: groups (commutative or not, multiplicative or additive);
* `R`, `S`: (semi)rings.
## TODO
* This file is currently ~2K lines long, so possibly it should be splitted into smaller chunks;
* Add the list of definitions and important lemmas to the module docstring.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## Notation
This file defines `α →₀ β` as notation for `finsupp α β`.
-/
noncomputable theory
open_locale classical big_operators
open finset
variables {α β γ ι M M' N P G H R S : Type*}
/-- `finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that
`f x = 0` for all but finitely many `x`. -/
structure finsupp (α : Type*) (M : Type*) [has_zero M] :=
(support : finset α)
(to_fun : α → M)
(mem_support_to_fun : ∀a, a ∈ support ↔ to_fun a ≠ 0)
infixr ` →₀ `:25 := finsupp
namespace finsupp
/-! ### Basic declarations about `finsupp` -/
section basic
variable [has_zero M]
instance : has_coe_to_fun (α →₀ M) := ⟨λ _, α → M, to_fun⟩
@[simp] lemma coe_mk (f : α → M) (s : finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) :
⇑(⟨s, f, h⟩ : α →₀ M) = f := rfl
instance : has_zero (α →₀ M) := ⟨⟨∅, (λ _, 0), λ _, ⟨false.elim, λ H, H rfl⟩⟩⟩
@[simp] lemma coe_zero : ⇑(0 : α →₀ M) = (λ _, (0:M)) := rfl
lemma zero_apply {a : α} : (0 : α →₀ M) a = 0 := rfl
@[simp] lemma support_zero : (0 : α →₀ M).support = ∅ := rfl
instance : inhabited (α →₀ M) := ⟨0⟩
@[simp] lemma mem_support_iff {f : α →₀ M} : ∀{a:α}, a ∈ f.support ↔ f a ≠ 0 :=
f.mem_support_to_fun
@[simp] lemma fun_support_eq (f : α →₀ M) : function.support f = f.support :=
set.ext $ λ x, mem_support_iff.symm
lemma not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 :=
not_iff_comm.1 mem_support_iff.symm
lemma coe_fn_injective : @function.injective (α →₀ M) (α → M) coe_fn
| ⟨s, f, hf⟩ ⟨t, g, hg⟩ h :=
begin
change f = g at h, subst h,
have : s = t, { ext a, exact (hf a).trans (hg a).symm },
subst this
end
@[ext] lemma ext {f g : α →₀ M} (h : ∀a, f a = g a) : f = g := coe_fn_injective (funext h)
lemma ext_iff {f g : α →₀ M} : f = g ↔ (∀a:α, f a = g a) :=
⟨by rintros rfl a; refl, ext⟩
lemma ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x :=
⟨λ h, h ▸ ⟨rfl, λ _ _, rfl⟩, λ ⟨h₁, h₂⟩, ext $ λ a,
if h : a ∈ f.support then h₂ a h else
have hf : f a = 0, from not_mem_support_iff.1 h,
have hg : g a = 0, by rwa [h₁, not_mem_support_iff] at h,
by rw [hf, hg]⟩
@[simp] lemma support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
⟨assume h, ext $ assume a, by_contradiction $ λ H, (finset.ext_iff.1 h a).1 $
mem_support_iff.2 H, by rintro rfl; refl⟩
lemma support_nonempty_iff {f : α →₀ M} : f.support.nonempty ↔ f ≠ 0 :=
by simp only [finsupp.support_eq_empty, finset.nonempty_iff_ne_empty, ne.def]
lemma nonzero_iff_exists {f : α →₀ M} : f ≠ 0 ↔ ∃ a : α, f a ≠ 0 :=
by simp [finsupp.support_eq_empty.symm, finset.eq_empty_iff_forall_not_mem]
lemma card_support_eq_zero {f : α →₀ M} : card f.support = 0 ↔ f = 0 :=
by simp
instance finsupp.decidable_eq [decidable_eq α] [decidable_eq M] : decidable_eq (α →₀ M) :=
assume f g, decidable_of_iff (f.support = g.support ∧ (∀a∈f.support, f a = g a)) ext_iff'.symm
lemma finite_supp (f : α →₀ M) : set.finite {a | f a ≠ 0} :=
⟨fintype.of_finset f.support (λ _, mem_support_iff)⟩
lemma support_subset_iff {s : set α} {f : α →₀ M} :
↑f.support ⊆ s ↔ (∀a∉s, f a = 0) :=
by simp only [set.subset_def, mem_coe, mem_support_iff];
exact forall_congr (assume a, not_imp_comm)
/-- Given `fintype α`, `equiv_fun_on_fintype` is the `equiv` between `α →₀ β` and `α → β`.
(All functions on a finite type are finitely supported.) -/
def equiv_fun_on_fintype [fintype α] : (α →₀ M) ≃ (α → M) :=
⟨λf a, f a, λf, mk (finset.univ.filter $ λa, f a ≠ 0) f (by simp only [true_and, finset.mem_univ,
iff_self, finset.mem_filter, finset.filter_congr_decidable, forall_true_iff]),
begin intro f, ext a, refl end,
begin intro f, ext a, refl end⟩
end basic
/-! ### Declarations about `single` -/
section single
variables [has_zero M] {a a' : α} {b : M}
/-- `single a b` is the finitely supported function which has
value `b` at `a` and zero otherwise. -/
def single (a : α) (b : M) : α →₀ M :=
⟨if b = 0 then ∅ else {a}, λ a', if a = a' then b else 0, λ a', begin
by_cases hb : b = 0; by_cases a = a';
simp only [hb, h, if_pos, if_false, mem_singleton],
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨λ _, hb, λ _, rfl⟩ },
{ exact ⟨λ H _, h H.symm, λ H, (H rfl).elim⟩ }
end⟩
lemma single_apply : single a b a' = if a = a' then b else 0 :=
rfl
lemma single_eq_indicator : ⇑(single a b) = set.indicator {a} (λ _, b) :=
by { ext, simp [single_apply, set.indicator, @eq_comm _ a] }
@[simp] lemma single_eq_same : (single a b : α →₀ M) a = b :=
if_pos rfl
@[simp] lemma single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ M) a' = 0 :=
if_neg h
lemma single_eq_update : ⇑(single a b) = function.update 0 a b :=
by rw [single_eq_indicator, ← set.piecewise_eq_indicator, set.piecewise_singleton]
@[simp] lemma single_zero : (single a 0 : α →₀ M) = 0 :=
coe_fn_injective $ by simpa only [single_eq_update, coe_zero]
using function.update_eq_self a (0 : α → M)
lemma single_of_single_apply (a a' : α) (b : M) :
single a ((single a' b) a) = single a' (single a' b) a :=
begin
rw [single_apply, single_apply],
ext,
split_ifs,
{ rw h, },
{ rw [zero_apply, single_apply, if_t_t], },
end
lemma support_single_ne_zero (hb : b ≠ 0) : (single a b).support = {a} :=
if_neg hb
lemma support_single_subset : (single a b).support ⊆ {a} :=
show ite _ _ _ ⊆ _, by split_ifs; [exact empty_subset _, exact subset.refl _]
lemma single_apply_mem (x) : single a b x ∈ ({0, b} : set M) :=
by rcases em (a = x) with (rfl|hx); [simp, simp [single_eq_of_ne hx]]
lemma range_single_subset : set.range (single a b) ⊆ {0, b} :=
set.range_subset_iff.2 single_apply_mem
lemma single_injective (a : α) : function.injective (single a : M → α →₀ M) :=
assume b₁ b₂ eq,
have (single a b₁ : α →₀ M) a = (single a b₂ : α →₀ M) a, by rw eq,
by rwa [single_eq_same, single_eq_same] at this
lemma single_apply_eq_zero {a x : α} {b : M} : single a b x = 0 ↔ (x = a → b = 0) :=
by simp [single_eq_indicator]
lemma mem_support_single (a a' : α) (b : M) :
a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 :=
by simp [single_apply_eq_zero, not_or_distrib]
lemma eq_single_iff {f : α →₀ M} {a b} : f = single a b ↔ f.support ⊆ {a} ∧ f a = b :=
begin
refine ⟨λ h, h.symm ▸ ⟨support_single_subset, single_eq_same⟩, _⟩,
rintro ⟨h, rfl⟩,
ext x,
by_cases hx : a = x; simp only [hx, single_eq_same, single_eq_of_ne, ne.def, not_false_iff],
exact not_mem_support_iff.1 (mt (λ hx, (mem_singleton.1 (h hx)).symm) hx)
end
lemma single_eq_single_iff (a₁ a₂ : α) (b₁ b₂ : M) :
single a₁ b₁ = single a₂ b₂ ↔ ((a₁ = a₂ ∧ b₁ = b₂) ∨ (b₁ = 0 ∧ b₂ = 0)) :=
begin
split,
{ assume eq,
by_cases a₁ = a₂,
{ refine or.inl ⟨h, _⟩,
rwa [h, (single_injective a₂).eq_iff] at eq },
{ rw [ext_iff] at eq,
have h₁ := eq a₁,
have h₂ := eq a₂,
simp only [single_eq_same, single_eq_of_ne h, single_eq_of_ne (ne.symm h)] at h₁ h₂,
exact or.inr ⟨h₁, h₂.symm⟩ } },
{ rintros (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩),
{ refl },
{ rw [single_zero, single_zero] } }
end
lemma single_left_inj (h : b ≠ 0) :
single a b = single a' b ↔ a = a' :=
⟨λ H, by simpa only [h, single_eq_single_iff,
and_false, or_false, eq_self_iff_true, and_true] using H,
λ H, by rw [H]⟩
@[simp] lemma single_eq_zero : single a b = 0 ↔ b = 0 :=
by simp [ext_iff, single_eq_indicator]
lemma single_swap (a₁ a₂ : α) (b : M) : single a₁ b a₂ = single a₂ b a₁ :=
by simp only [single_apply]; ac_refl
instance [nonempty α] [nontrivial M] : nontrivial (α →₀ M) :=
begin
inhabit α,
rcases exists_ne (0 : M) with ⟨x, hx⟩,
exact nontrivial_of_ne (single (default α) x) 0 (mt single_eq_zero.1 hx)
end
lemma unique_single [unique α] (x : α →₀ M) : x = single (default α) (x (default α)) :=
ext $ unique.forall_iff.2 single_eq_same.symm
lemma unique_ext [unique α] {f g : α →₀ M} (h : f (default α) = g (default α)) : f = g :=
ext $ λ a, by rwa [unique.eq_default a]
lemma unique_ext_iff [unique α] {f g : α →₀ M} : f = g ↔ f (default α) = g (default α) :=
⟨λ h, h ▸ rfl, unique_ext⟩
@[simp] lemma unique_single_eq_iff [unique α] {b' : M} :
single a b = single a' b' ↔ b = b' :=
by rw [unique_ext_iff, unique.eq_default a, unique.eq_default a', single_eq_same, single_eq_same]
lemma support_eq_singleton {f : α →₀ M} {a : α} :
f.support = {a} ↔ f a ≠ 0 ∧ f = single a (f a) :=
⟨λ h, ⟨mem_support_iff.1 $ h.symm ▸ finset.mem_singleton_self a,
eq_single_iff.2 ⟨subset_of_eq h, rfl⟩⟩, λ h, h.2.symm ▸ support_single_ne_zero h.1⟩
lemma support_eq_singleton' {f : α →₀ M} {a : α} :
f.support = {a} ↔ ∃ b ≠ 0, f = single a b :=
⟨λ h, let h := support_eq_singleton.1 h in ⟨_, h.1, h.2⟩,
λ ⟨b, hb, hf⟩, hf.symm ▸ support_single_ne_zero hb⟩
lemma card_support_eq_one {f : α →₀ M} : card f.support = 1 ↔ ∃ a, f a ≠ 0 ∧ f = single a (f a) :=
by simp only [card_eq_one, support_eq_singleton]
lemma card_support_eq_one' {f : α →₀ M} : card f.support = 1 ↔ ∃ a (b ≠ 0), f = single a b :=
by simp only [card_eq_one, support_eq_singleton']
end single
/-! ### Declarations about `on_finset` -/
section on_finset
variables [has_zero M]
/-- `on_finset s f hf` is the finsupp function representing `f` restricted to the finset `s`.
The function needs to be `0` outside of `s`. Use this when the set needs to be filtered anyways,
otherwise a better set representation is often available. -/
def on_finset (s : finset α) (f : α → M) (hf : ∀a, f a ≠ 0 → a ∈ s) : α →₀ M :=
⟨s.filter (λa, f a ≠ 0), f, by simpa⟩
@[simp] lemma on_finset_apply {s : finset α} {f : α → M} {hf a} :
(on_finset s f hf : α →₀ M) a = f a :=
rfl
@[simp] lemma support_on_finset_subset {s : finset α} {f : α → M} {hf} :
(on_finset s f hf).support ⊆ s :=
filter_subset _ _
@[simp] lemma mem_support_on_finset
{s : finset α} {f : α → M} (hf : ∀ (a : α), f a ≠ 0 → a ∈ s) {a : α} :
a ∈ (finsupp.on_finset s f hf).support ↔ f a ≠ 0 :=
by rw [finsupp.mem_support_iff, finsupp.on_finset_apply]
lemma support_on_finset
{s : finset α} {f : α → M} (hf : ∀ (a : α), f a ≠ 0 → a ∈ s) :
(finsupp.on_finset s f hf).support = s.filter (λ a, f a ≠ 0) :=
rfl
end on_finset
/-! ### Declarations about `map_range` -/
section map_range
variables [has_zero M] [has_zero N]
/-- The composition of `f : M → N` and `g : α →₀ M` is
`map_range f hf g : α →₀ N`, well-defined when `f 0 = 0`. -/
def map_range (f : M → N) (hf : f 0 = 0) (g : α →₀ M) : α →₀ N :=
on_finset g.support (f ∘ g) $
assume a, by rw [mem_support_iff, not_imp_not]; exact λ H, (congr_arg f H).trans hf
@[simp] lemma map_range_apply {f : M → N} {hf : f 0 = 0} {g : α →₀ M} {a : α} :
map_range f hf g a = f (g a) :=
rfl
@[simp] lemma map_range_zero {f : M → N} {hf : f 0 = 0} : map_range f hf (0 : α →₀ M) = 0 :=
ext $ λ a, by simp only [hf, zero_apply, map_range_apply]
lemma support_map_range {f : M → N} {hf : f 0 = 0} {g : α →₀ M} :
(map_range f hf g).support ⊆ g.support :=
support_on_finset_subset
@[simp] lemma map_range_single {f : M → N} {hf : f 0 = 0} {a : α} {b : M} :
map_range f hf (single a b) = single a (f b) :=
ext $ λ a', show f (ite _ _ _) = ite _ _ _, by split_ifs; [refl, exact hf]
end map_range
/-! ### Declarations about `emb_domain` -/
section emb_domain
variables [has_zero M] [has_zero N]
/-- Given `f : α ↪ β` and `v : α →₀ M`, `emb_domain f v : β →₀ M`
is the finitely supported function whose value at `f a : β` is `v a`.
For a `b : β` outside the range of `f`, it is zero. -/
def emb_domain (f : α ↪ β) (v : α →₀ M) : β →₀ M :=
begin
refine ⟨v.support.map f, λa₂,
if h : a₂ ∈ v.support.map f then v (v.support.choose (λa₁, f a₁ = a₂) _) else 0, _⟩,
{ rcases finset.mem_map.1 h with ⟨a, ha, rfl⟩,
exact exists_unique.intro a ⟨ha, rfl⟩ (assume b ⟨_, hb⟩, f.injective hb) },
{ assume a₂,
split_ifs,
{ simp only [h, true_iff, ne.def],
rw [← not_mem_support_iff, not_not],
apply finset.choose_mem },
{ simp only [h, ne.def, ne_self_iff_false] } }
end
@[simp] lemma support_emb_domain (f : α ↪ β) (v : α →₀ M) :
(emb_domain f v).support = v.support.map f :=
rfl
@[simp] lemma emb_domain_zero (f : α ↪ β) : (emb_domain f 0 : β →₀ M) = 0 :=
rfl
@[simp] lemma emb_domain_apply (f : α ↪ β) (v : α →₀ M) (a : α) :
emb_domain f v (f a) = v a :=
begin
change dite _ _ _ = _,
split_ifs; rw [finset.mem_map' f] at h,
{ refine congr_arg (v : α → M) (f.inj' _),
exact finset.choose_property (λa₁, f a₁ = f a) _ _ },
{ exact (not_mem_support_iff.1 h).symm }
end
lemma emb_domain_notin_range (f : α ↪ β) (v : α →₀ M) (a : β) (h : a ∉ set.range f) :
emb_domain f v a = 0 :=
begin
refine dif_neg (mt (assume h, _) h),
rcases finset.mem_map.1 h with ⟨a, h, rfl⟩,
exact set.mem_range_self a
end
lemma emb_domain_injective (f : α ↪ β) :
function.injective (emb_domain f : (α →₀ M) → (β →₀ M)) :=
λ l₁ l₂ h, ext $ λ a, by simpa only [emb_domain_apply] using ext_iff.1 h (f a)
@[simp] lemma emb_domain_inj {f : α ↪ β} {l₁ l₂ : α →₀ M} :
emb_domain f l₁ = emb_domain f l₂ ↔ l₁ = l₂ :=
(emb_domain_injective f).eq_iff
@[simp] lemma emb_domain_eq_zero {f : α ↪ β} {l : α →₀ M} :
emb_domain f l = 0 ↔ l = 0 :=
(emb_domain_injective f).eq_iff' $ emb_domain_zero f
lemma emb_domain_map_range
(f : α ↪ β) (g : M → N) (p : α →₀ M) (hg : g 0 = 0) :
emb_domain f (map_range g hg p) = map_range g hg (emb_domain f p) :=
begin
ext a,
by_cases a ∈ set.range f,
{ rcases h with ⟨a', rfl⟩,
rw [map_range_apply, emb_domain_apply, emb_domain_apply, map_range_apply] },
{ rw [map_range_apply, emb_domain_notin_range, emb_domain_notin_range, ← hg]; assumption }
end
lemma single_of_emb_domain_single
(l : α →₀ M) (f : α ↪ β) (a : β) (b : M) (hb : b ≠ 0)
(h : l.emb_domain f = single a b) :
∃ x, l = single x b ∧ f x = a :=
begin
have h_map_support : finset.map f (l.support) = {a},
by rw [←support_emb_domain, h, support_single_ne_zero hb]; refl,
have ha : a ∈ finset.map f (l.support),
by simp only [h_map_support, finset.mem_singleton],
rcases finset.mem_map.1 ha with ⟨c, hc₁, hc₂⟩,
use c,
split,
{ ext d,
rw [← emb_domain_apply f l, h],
by_cases h_cases : c = d,
{ simp only [eq.symm h_cases, hc₂, single_eq_same] },
{ rw [single_apply, single_apply, if_neg, if_neg h_cases],
by_contra hfd,
exact h_cases (f.injective (hc₂.trans hfd)) } },
{ exact hc₂ }
end
end emb_domain
/-! ### Declarations about `zip_with` -/
section zip_with
variables [has_zero M] [has_zero N] [has_zero P]
/-- `zip_with f hf g₁ g₂` is the finitely supported function satisfying
`zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a)`, and it is well-defined when `f 0 0 = 0`. -/
def zip_with (f : M → N → P) (hf : f 0 0 = 0) (g₁ : α →₀ M) (g₂ : α →₀ N) : (α →₀ P) :=
on_finset (g₁.support ∪ g₂.support) (λa, f (g₁ a) (g₂ a)) $ λ a H,
begin
simp only [mem_union, mem_support_iff, ne], rw [← not_and_distrib],
rintro ⟨h₁, h₂⟩, rw [h₁, h₂] at H, exact H hf
end
@[simp] lemma zip_with_apply
{f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M} {g₂ : α →₀ N} {a : α} :
zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a) :=
rfl
lemma support_zip_with {f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M} {g₂ : α →₀ N} :
(zip_with f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support :=
support_on_finset_subset
end zip_with
/-! ### Declarations about `erase` -/
section erase
variables [has_zero M]
/-- `erase a f` is the finitely supported function equal to `f` except at `a` where it is equal to
`0`. -/
def erase (a : α) (f : α →₀ M) : α →₀ M :=
⟨f.support.erase a, (λa', if a' = a then 0 else f a'),
assume a', by rw [mem_erase, mem_support_iff]; split_ifs;
[exact ⟨λ H _, H.1 h, λ H, (H rfl).elim⟩,
exact and_iff_right h]⟩
@[simp] lemma support_erase {a : α} {f : α →₀ M} :
(f.erase a).support = f.support.erase a :=
rfl
@[simp] lemma erase_same {a : α} {f : α →₀ M} : (f.erase a) a = 0 :=
if_pos rfl
@[simp] lemma erase_ne {a a' : α} {f : α →₀ M} (h : a' ≠ a) : (f.erase a) a' = f a' :=
if_neg h
@[simp] lemma erase_single {a : α} {b : M} : (erase a (single a b)) = 0 :=
begin
ext s, by_cases hs : s = a,
{ rw [hs, erase_same], refl },
{ rw [erase_ne hs], exact single_eq_of_ne (ne.symm hs) }
end
lemma erase_single_ne {a a' : α} {b : M} (h : a ≠ a') : (erase a (single a' b)) = single a' b :=
begin
ext s, by_cases hs : s = a,
{ rw [hs, erase_same, single_eq_of_ne (h.symm)] },
{ rw [erase_ne hs] }
end
@[simp] lemma erase_zero (a : α) : erase a (0 : α →₀ M) = 0 :=
by rw [← support_eq_empty, support_erase, support_zero, erase_empty]
end erase
/-!
### Declarations about `sum` and `prod`
In most of this section, the domain `β` is assumed to be an `add_monoid`.
-/
section sum_prod
-- [to_additive sum] for finsupp.prod doesn't work, the equation lemmas are not generated
/-- `sum f g` is the sum of `g a (f a)` over the support of `f`. -/
def sum [has_zero M] [add_comm_monoid N] (f : α →₀ M) (g : α → M → N) : N :=
∑ a in f.support, g a (f a)
/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/
@[to_additive]
def prod [has_zero M] [comm_monoid N] (f : α →₀ M) (g : α → M → N) : N :=
∏ a in f.support, g a (f a)
variables [has_zero M] [has_zero M'] [comm_monoid N]
@[to_additive]
lemma prod_of_support_subset (f : α →₀ M) {s : finset α}
(hs : f.support ⊆ s) (g : α → M → N) (h : ∀ i ∈ s, g i 0 = 1) :
f.prod g = ∏ x in s, g x (f x) :=
finset.prod_subset hs $ λ x hxs hx, h x hxs ▸ congr_arg (g x) $ not_mem_support_iff.1 hx
@[to_additive]
lemma prod_fintype [fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :
f.prod g = ∏ i, g i (f i) :=
f.prod_of_support_subset (subset_univ _) g (λ x _, h x)
@[simp, to_additive]
lemma prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :
(single a b).prod h = h a b :=
calc (single a b).prod h = ∏ x in {a}, h x (single a b x) :
prod_of_support_subset _ support_single_subset h $ λ x hx, (mem_singleton.1 hx).symm ▸ h_zero
... = h a b : by simp
@[to_additive]
lemma prod_map_range_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}
(h0 : ∀a, h a 0 = 1) : (map_range f hf g).prod h = g.prod (λa b, h a (f b)) :=
finset.prod_subset support_map_range $ λ _ _ H,
by rw [not_mem_support_iff.1 H, h0]
@[simp, to_additive]
lemma prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 := rfl
@[to_additive]
lemma prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :
f.prod (λ x v, g.prod (λ x' v', h x v x' v')) = g.prod (λ x' v', f.prod (λ x v, h x v x' v')) :=
finset.prod_comm
@[simp, to_additive]
lemma prod_ite_eq [decidable_eq α] (f : α →₀ M) (a : α) (b : α → M → N) :
f.prod (λ x v, ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 :=
by { dsimp [finsupp.prod], rw f.support.prod_ite_eq, }
@[simp] lemma sum_ite_self_eq
[decidable_eq α] {N : Type*} [add_comm_monoid N] (f : α →₀ N) (a : α) :
f.sum (λ x v, ite (a = x) v 0) = f a :=
by { convert f.sum_ite_eq a (λ x, id), simp [ite_eq_right_iff.2 eq.symm] }
/-- A restatement of `prod_ite_eq` with the equality test reversed. -/
@[simp, to_additive "A restatement of `sum_ite_eq` with the equality test reversed."]
lemma prod_ite_eq' [decidable_eq α] (f : α →₀ M) (a : α) (b : α → M → N) :
f.prod (λ x v, ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 :=
by { dsimp [finsupp.prod], rw f.support.prod_ite_eq', }
@[simp] lemma sum_ite_self_eq'
[decidable_eq α] {N : Type*} [add_comm_monoid N] (f : α →₀ N) (a : α) :
f.sum (λ x v, ite (x = a) v 0) = f a :=
by { convert f.sum_ite_eq' a (λ x, id), simp [ite_eq_right_iff.2 eq.symm] }
@[simp] lemma prod_pow [fintype α] (f : α →₀ ℕ) (g : α → N) :
f.prod (λ a b, g a ^ b) = ∏ a, g a ^ (f a) :=
f.prod_fintype _ $ λ a, pow_zero _
/-- If `g` maps a second argument of 0 to 1, then multiplying it over the
result of `on_finset` is the same as multiplying it over the original
`finset`. -/
@[to_additive "If `g` maps a second argument of 0 to 0, summing it over the
result of `on_finset` is the same as summing it over the original
`finset`."]
lemma on_finset_prod {s : finset α} {f : α → M} {g : α → M → N}
(hf : ∀a, f a ≠ 0 → a ∈ s) (hg : ∀ a, g a 0 = 1) :
(on_finset s f hf).prod g = ∏ a in s, g a (f a) :=
finset.prod_subset support_on_finset_subset $ by simp [*] { contextual := tt }
end sum_prod
/-!
### Additive monoid structure on `α →₀ M`
-/
section add_monoid
variables [add_monoid M]
instance : has_add (α →₀ M) := ⟨zip_with (+) (add_zero 0)⟩
@[simp] lemma coe_add (f g : α →₀ M) : ⇑(f + g) = f + g := rfl
lemma add_apply (g₁ g₂ : α →₀ M) (a : α) : (g₁ + g₂) a = g₁ a + g₂ a := rfl
lemma support_add {g₁ g₂ : α →₀ M} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
support_zip_with
lemma support_add_eq {g₁ g₂ : α →₀ M} (h : disjoint g₁.support g₂.support) :
(g₁ + g₂).support = g₁.support ∪ g₂.support :=
le_antisymm support_zip_with $ assume a ha,
(finset.mem_union.1 ha).elim
(assume ha, have a ∉ g₂.support, from disjoint_left.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, add_zero])
(assume ha, have a ∉ g₁.support, from disjoint_right.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, zero_add])
@[simp] lemma single_add {a : α} {b₁ b₂ : M} : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, add_apply, single_eq_same, single_eq_same, single_eq_same] },
{ rw [add_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, zero_add] }
end
instance : add_monoid (α →₀ M) :=
{ add_monoid .
zero := 0,
add := (+),
add_assoc := assume ⟨s, f, hf⟩ ⟨t, g, hg⟩ ⟨u, h, hh⟩, ext $ assume a, add_assoc _ _ _,
zero_add := assume ⟨s, f, hf⟩, ext $ assume a, zero_add _,
add_zero := assume ⟨s, f, hf⟩, ext $ assume a, add_zero _ }
/-- `finsupp.single` as an `add_monoid_hom`.
See `finsupp.lsingle` for the stronger version as a linear map.
-/
@[simps] def single_add_hom (a : α) : M →+ α →₀ M :=
⟨single a, single_zero, λ _ _, single_add⟩
/-- Evaluation of a function `f : α →₀ M` at a point as an additive monoid homomorphism.
See `finsupp.lapply` for the stronger version as a linear map. -/
@[simps apply]
def apply_add_hom (a : α) : (α →₀ M) →+ M := ⟨λ g, g a, zero_apply, λ _ _, add_apply _ _ _⟩
lemma single_add_erase (a : α) (f : α →₀ M) : single a (f a) + f.erase a = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, add_zero]
else by simp only [add_apply, single_eq_of_ne h, zero_add, erase_ne (ne.symm h)]
lemma erase_add_single (a : α) (f : α →₀ M) : f.erase a + single a (f a) = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, zero_add]
else by simp only [add_apply, single_eq_of_ne h, add_zero, erase_ne (ne.symm h)]
@[simp] lemma erase_add (a : α) (f f' : α →₀ M) : erase a (f + f') = erase a f + erase a f' :=
begin
ext s, by_cases hs : s = a,
{ rw [hs, add_apply, erase_same, erase_same, erase_same, add_zero] },
rw [add_apply, erase_ne hs, erase_ne hs, erase_ne hs, add_apply],
end
@[elab_as_eliminator]
protected theorem induction {p : (α →₀ M) → Prop} (f : α →₀ M)
(h0 : p 0) (ha : ∀a b (f : α →₀ M), a ∉ f.support → b ≠ 0 → p f → p (single a b + f)) :
p f :=
suffices ∀s (f : α →₀ M), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (single a (f a) + f.erase a), by rwa [single_add_erase] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
lemma induction₂ {p : (α →₀ M) → Prop} (f : α →₀ M)
(h0 : p 0) (ha : ∀a b (f : α →₀ M), a ∉ f.support → b ≠ 0 → p f → p (f + single a b)) :
p f :=
suffices ∀s (f : α →₀ M), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (f.erase a + single a (f a)), by rwa [erase_add_single] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
lemma induction_linear {p : (α →₀ M) → Prop} (f : α →₀ M)
(h0 : p 0) (hadd : ∀ f g : α →₀ M, p f → p g → p (f + g)) (hsingle : ∀ a b, p (single a b)) :
p f :=
induction₂ f h0 (λ a b f _ _ w, hadd _ _ w (hsingle _ _))
@[simp] lemma add_closure_Union_range_single :
add_submonoid.closure (⋃ a : α, set.range (single a : M → α →₀ M)) = ⊤ :=
top_unique $ λ x hx, finsupp.induction x (add_submonoid.zero_mem _) $
λ a b f ha hb hf, add_submonoid.add_mem _
(add_submonoid.subset_closure $ set.mem_Union.2 ⟨a, set.mem_range_self _⟩) hf
/-- If two additive homomorphisms from `α →₀ M` are equal on each `single a b`, then
they are equal. -/
lemma add_hom_ext [add_monoid N] ⦃f g : (α →₀ M) →+ N⦄
(H : ∀ x y, f (single x y) = g (single x y)) :
f = g :=
begin
refine add_monoid_hom.eq_of_eq_on_mdense add_closure_Union_range_single (λ f hf, _),
simp only [set.mem_Union, set.mem_range] at hf,
rcases hf with ⟨x, y, rfl⟩,
apply H
end
/-- If two additive homomorphisms from `α →₀ M` are equal on each `single a b`, then
they are equal.
We formulate this using equality of `add_monoid_hom`s so that `ext` tactic can apply a type-specific
extensionality lemma after this one. E.g., if the fiber `M` is `ℕ` or `ℤ`, then it suffices to
verify `f (single a 1) = g (single a 1)`. -/
@[ext] lemma add_hom_ext' [add_monoid N] ⦃f g : (α →₀ M) →+ N⦄
(H : ∀ x, f.comp (single_add_hom x) = g.comp (single_add_hom x)) :
f = g :=
add_hom_ext $ λ x, add_monoid_hom.congr_fun (H x)
lemma mul_hom_ext [monoid N] ⦃f g : multiplicative (α →₀ M) →* N⦄
(H : ∀ x y, f (multiplicative.of_add $ single x y) = g (multiplicative.of_add $ single x y)) :
f = g :=
monoid_hom.ext $ add_monoid_hom.congr_fun $
@add_hom_ext α M (additive N) _ _ f.to_additive'' g.to_additive'' H
@[ext] lemma mul_hom_ext' [monoid N] {f g : multiplicative (α →₀ M) →* N}
(H : ∀ x, f.comp (single_add_hom x).to_multiplicative =
g.comp (single_add_hom x).to_multiplicative) :
f = g :=
mul_hom_ext $ λ x, monoid_hom.congr_fun (H x)
lemma map_range_add [add_monoid N]
{f : M → N} {hf : f 0 = 0} (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : α →₀ M) :
map_range f hf (v₁ + v₂) = map_range f hf v₁ + map_range f hf v₂ :=
ext $ λ a, by simp only [hf', add_apply, map_range_apply]
end add_monoid
end finsupp
@[to_additive]
lemma mul_equiv.map_finsupp_prod [has_zero M] [comm_monoid N] [comm_monoid P]
(h : N ≃* P) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod (λ a b, h (g a b)) :=
h.map_prod _ _
@[to_additive]
lemma monoid_hom.map_finsupp_prod [has_zero M] [comm_monoid N] [comm_monoid P]
(h : N →* P) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod (λ a b, h (g a b)) :=
h.map_prod _ _
lemma ring_hom.map_finsupp_sum [has_zero M] [semiring R] [semiring S]
(h : R →+* S) (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum (λ a b, h (g a b)) :=
h.map_sum _ _
lemma ring_hom.map_finsupp_prod [has_zero M] [comm_semiring R] [comm_semiring S]
(h : R →+* S) (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod (λ a b, h (g a b)) :=
h.map_prod _ _
@[to_additive]
lemma monoid_hom.coe_finsupp_prod [has_zero β] [monoid N] [comm_monoid P]
(f : α →₀ β) (g : α → β → N →* P) :
⇑(f.prod g) = f.prod (λ i fi, g i fi) :=
monoid_hom.coe_prod _ _
@[simp, to_additive]
lemma monoid_hom.finsupp_prod_apply [has_zero β] [monoid N] [comm_monoid P]
(f : α →₀ β) (g : α → β → N →* P) (x : N) :
f.prod g x = f.prod (λ i fi, g i fi x) :=
monoid_hom.finset_prod_apply _ _ _
namespace finsupp
section nat_sub
instance nat_sub : has_sub (α →₀ ℕ) := ⟨zip_with (λ m n, m - n) (nat.sub_zero 0)⟩
@[simp] lemma coe_nat_sub (g₁ g₂ : α →₀ ℕ) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl
lemma nat_sub_apply (g₁ g₂ : α →₀ ℕ) (a : α) : (g₁ - g₂) a = g₁ a - g₂ a := rfl
@[simp] lemma single_sub {a : α} {n₁ n₂ : ℕ} : single a (n₁ - n₂) = single a n₁ - single a n₂ :=
begin
ext f,
by_cases h : (a = f),
{ rw [h, nat_sub_apply, single_eq_same, single_eq_same, single_eq_same] },
rw [nat_sub_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h]
end
-- These next two lemmas are used in developing
-- the partial derivative on `mv_polynomial`.
lemma sub_single_one_add {a : α} {u u' : α →₀ ℕ} (h : u a ≠ 0) :
u - single a 1 + u' = u + u' - single a 1 :=
begin
ext b,
rw [add_apply, nat_sub_apply, nat_sub_apply, add_apply],
by_cases h : a = b,
{ rw [←h, single_eq_same], cases (u a), { contradiction }, { simp }, },
{ simp [h], }
end
lemma add_sub_single_one {a : α} {u u' : α →₀ ℕ} (h : u' a ≠ 0) :
u + (u' - single a 1) = u + u' - single a 1 :=
begin
ext b,
rw [add_apply, nat_sub_apply, nat_sub_apply, add_apply],
by_cases h : a = b,
{ rw [←h, single_eq_same], cases (u' a), { contradiction }, { simp }, },
{ simp [h], }
end
@[simp] lemma nat_zero_sub (f : α →₀ ℕ) : 0 - f = 0 := ext $ λ x, nat.zero_sub _
end nat_sub
instance [add_comm_monoid M] : add_comm_monoid (α →₀ M) :=
{ add_comm := assume ⟨s, f, _⟩ ⟨t, g, _⟩, ext $ assume a, add_comm _ _,
.. finsupp.add_monoid }
instance [add_group G] : has_sub (α →₀ G) := ⟨zip_with has_sub.sub (sub_zero _)⟩
instance [add_group G] : add_group (α →₀ G) :=
{ neg := map_range (has_neg.neg) neg_zero,
sub := has_sub.sub,
sub_eq_add_neg := λ x y, ext (λ i, sub_eq_add_neg _ _),
add_left_neg := assume ⟨s, f, _⟩, ext $ assume x, add_left_neg _,
.. finsupp.add_monoid }
instance [add_comm_group G] : add_comm_group (α →₀ G) :=
{ add_comm := add_comm, ..finsupp.add_group }
lemma single_multiset_sum [add_comm_monoid M] (s : multiset M) (a : α) :
single a s.sum = (s.map (single a)).sum :=
multiset.induction_on s single_zero $ λ a s ih,
by rw [multiset.sum_cons, single_add, ih, multiset.map_cons, multiset.sum_cons]
lemma single_finset_sum [add_comm_monoid M] (s : finset ι) (f : ι → M) (a : α) :
single a (∑ b in s, f b) = ∑ b in s, single a (f b) :=
begin
transitivity,
apply single_multiset_sum,
rw [multiset.map_map],
refl
end
lemma single_sum [has_zero M] [add_comm_monoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :
single a (s.sum f) = s.sum (λd c, single a (f d c)) :=
single_finset_sum _ _ _
@[to_additive]
lemma prod_neg_index [add_group G] [comm_monoid M] {g : α →₀ G} {h : α → G → M}
(h0 : ∀a, h a 0 = 1) :
(-g).prod h = g.prod (λa b, h a (- b)) :=
prod_map_range_index h0
@[simp] lemma coe_neg [add_group G] (g : α →₀ G) : ⇑(-g) = -g := rfl
lemma neg_apply [add_group G] (g : α →₀ G) (a : α) : (- g) a = - g a := rfl
@[simp] lemma coe_sub [add_group G] (g₁ g₂ : α →₀ G) : ⇑(g₁ - g₂) = g₁ - g₂ := rfl
lemma sub_apply [add_group G] (g₁ g₂ : α →₀ G) (a : α) : (g₁ - g₂) a = g₁ a - g₂ a := rfl
@[simp] lemma support_neg [add_group G] {f : α →₀ G} : support (-f) = support f :=
finset.subset.antisymm
support_map_range
(calc support f = support (- (- f)) : congr_arg support (neg_neg _).symm
... ⊆ support (- f) : support_map_range)
@[simp] lemma sum_apply [has_zero M] [add_comm_monoid N]
{f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :
(f.sum g) a₂ = f.sum (λa₁ b, g a₁ b a₂) :=
(apply_add_hom a₂ : (β →₀ N) →+ _).map_sum _ _
lemma support_sum [has_zero M] [add_comm_monoid N]
{f : α →₀ M} {g : α → M → (β →₀ N)} :
(f.sum g).support ⊆ f.support.bUnion (λa, (g a (f a)).support) :=
have ∀ c, f.sum (λ a b, g a b c) ≠ 0 → (∃ a, f a ≠ 0 ∧ ¬ (g a (f a)) c = 0),
from assume a₁ h,
let ⟨a, ha, ne⟩ := finset.exists_ne_zero_of_sum_ne_zero h in
⟨a, mem_support_iff.mp ha, ne⟩,
by simpa only [finset.subset_iff, mem_support_iff, finset.mem_bUnion, sum_apply, exists_prop]
@[simp] lemma sum_zero [has_zero M] [add_comm_monoid N] {f : α →₀ M} :
f.sum (λa b, (0 : N)) = 0 :=
finset.sum_const_zero
@[simp, to_additive]
lemma prod_mul [has_zero M] [comm_monoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :
f.prod (λa b, h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=
finset.prod_mul_distrib
@[simp, to_additive]
lemma prod_inv [has_zero M] [comm_group G] {f : α →₀ M}
{h : α → M → G} : f.prod (λa b, (h a b)⁻¹) = (f.prod h)⁻¹ :=
(((monoid_hom.id G)⁻¹).map_prod _ _).symm
@[simp] lemma sum_sub [has_zero M] [add_comm_group G] {f : α →₀ M}
{h₁ h₂ : α → M → G} :
f.sum (λa b, h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=
finset.sum_sub_distrib
@[to_additive]
lemma prod_add_index [add_comm_monoid M] [comm_monoid N] {f g : α →₀ M}
{h : α → M → N} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f + g).prod h = f.prod h * g.prod h :=
have hf : f.prod h = ∏ a in f.support ∪ g.support, h a (f a),
from f.prod_of_support_subset (subset_union_left _ _) _ $ λ a ha, h_zero a,
have hg : g.prod h = ∏ a in f.support ∪ g.support, h a (g a),
from g.prod_of_support_subset (subset_union_right _ _) _ $ λ a ha, h_zero a,
have hfg : (f + g).prod h = ∏ a in f.support ∪ g.support, h a ((f + g) a),
from (f + g).prod_of_support_subset support_add _ $ λ a ha, h_zero a,
by simp only [*, add_apply, prod_mul_distrib]
@[simp]
lemma sum_add_index' [add_comm_monoid M] [add_comm_monoid N] {f g : α →₀ M} (h : α → M →+ N) :
(f + g).sum (λ x, h x) = f.sum (λ x, h x) + g.sum (λ x, h x) :=
sum_add_index (λ a, (h a).map_zero) (λ a, (h a).map_add)
@[simp]
lemma prod_add_index' [add_comm_monoid M] [comm_monoid N] {f g : α →₀ M}
(h : α → multiplicative M →* N) :
(f + g).prod (λ a b, h a (multiplicative.of_add b)) =
f.prod (λ a b, h a (multiplicative.of_add b)) * g.prod (λ a b, h a (multiplicative.of_add b)) :=
prod_add_index (λ a, (h a).map_one) (λ a, (h a).map_mul)
/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`
and monoid homomorphisms `(α →₀ M) →+ N`. -/
def lift_add_hom [add_comm_monoid M] [add_comm_monoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N) :=
{ to_fun := λ F,
{ to_fun := λ f, f.sum (λ x, F x),
map_zero' := finset.sum_empty,
map_add' := λ _ _, sum_add_index (λ x, (F x).map_zero) (λ x, (F x).map_add) },
inv_fun := λ F x, F.comp $ single_add_hom x,
left_inv := λ F, by { ext, simp },
right_inv := λ F, by { ext, simp },
map_add' := λ F G, by { ext, simp } }
@[simp] lemma lift_add_hom_apply [add_comm_monoid M] [add_comm_monoid N]
(F : α → M →+ N) (f : α →₀ M) :
lift_add_hom F f = f.sum (λ x, F x) :=
rfl
@[simp] lemma lift_add_hom_symm_apply [add_comm_monoid M] [add_comm_monoid N]
(F : (α →₀ M) →+ N) (x : α) :
lift_add_hom.symm F x = F.comp (single_add_hom x) :=
rfl
lemma lift_add_hom_symm_apply_apply [add_comm_monoid M] [add_comm_monoid N]
(F : (α →₀ M) →+ N) (x : α) (y : M) :
lift_add_hom.symm F x y = F (single x y) :=
rfl
@[simp] lemma lift_add_hom_single_add_hom [add_comm_monoid M] :
lift_add_hom (single_add_hom : α → M →+ α →₀ M) = add_monoid_hom.id _ :=
lift_add_hom.to_equiv.apply_eq_iff_eq_symm_apply.2 rfl
@[simp] lemma sum_single [add_comm_monoid M] (f : α →₀ M) :
f.sum single = f :=
add_monoid_hom.congr_fun lift_add_hom_single_add_hom f
@[simp] lemma lift_add_hom_apply_single [add_comm_monoid M] [add_comm_monoid N]
(f : α → M →+ N) (a : α) (b : M) :
lift_add_hom f (single a b) = f a b :=
sum_single_index (f a).map_zero
@[simp] lemma lift_add_hom_comp_single [add_comm_monoid M] [add_comm_monoid N] (f : α → M →+ N)
(a : α) :
(lift_add_hom f).comp (single_add_hom a) = f a :=
add_monoid_hom.ext $ λ b, lift_add_hom_apply_single f a b
lemma comp_lift_add_hom [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P]
(g : N →+ P) (f : α → M →+ N) :
g.comp (lift_add_hom f) = lift_add_hom (λ a, g.comp (f a)) :=
lift_add_hom.symm_apply_eq.1 $ funext $ λ a,
by rw [lift_add_hom_symm_apply, add_monoid_hom.comp_assoc, lift_add_hom_comp_single]
lemma sum_sub_index [add_comm_group β] [add_comm_group γ] {f g : α →₀ β}
{h : α → β → γ} (h_sub : ∀a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) :
(f - g).sum h = f.sum h - g.sum h :=
(lift_add_hom (λ a, add_monoid_hom.of_map_sub (h a) (h_sub a))).map_sub f g
@[to_additive]
lemma prod_emb_domain [has_zero M] [comm_monoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :
(v.emb_domain f).prod g = v.prod (λ a b, g (f a) b) :=
begin
rw [prod, prod, support_emb_domain, finset.prod_map],
simp_rw emb_domain_apply,
end
@[to_additive]
lemma prod_finset_sum_index [add_comm_monoid M] [comm_monoid N]
{s : finset ι} {g : ι → α →₀ M}
{h : α → M → N} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
∏ i in s, (g i).prod h = (∑ i in s, g i).prod h :=
finset.induction_on s rfl $ λ a s has ih,
by rw [prod_insert has, ih, sum_insert has, prod_add_index h_zero h_add]
@[to_additive]
lemma prod_sum_index
[add_comm_monoid M] [add_comm_monoid N] [comm_monoid P]
{f : α →₀ M} {g : α → M → β →₀ N}
{h : β → N → P} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f.sum g).prod h = f.prod (λa b, (g a b).prod h) :=
(prod_finset_sum_index h_zero h_add).symm
lemma multiset_sum_sum_index
[add_comm_monoid M] [add_comm_monoid N]
(f : multiset (α →₀ M)) (h : α → M → N)
(h₀ : ∀a, h a 0 = 0) (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :
(f.sum.sum h) = (f.map $ λg:α →₀ M, g.sum h).sum :=
multiset.induction_on f rfl $ assume a s ih,
by rw [multiset.sum_cons, multiset.map_cons, multiset.sum_cons, sum_add_index h₀ h₁, ih]
lemma multiset_map_sum [has_zero M] {f : α →₀ M} {m : β → γ} {h : α → M → multiset β} :
multiset.map m (f.sum h) = f.sum (λa b, (h a b).map m) :=
(f.support.sum_hom _).symm
lemma multiset_sum_sum [has_zero M] [add_comm_monoid N] {f : α →₀ M} {h : α → M → multiset N} :
multiset.sum (f.sum h) = f.sum (λa b, multiset.sum (h a b)) :=
(f.support.sum_hom multiset.sum).symm
section map_range
variables
[add_comm_monoid M] [add_comm_monoid N] (f : M →+ N)
/--
Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
def map_range.add_monoid_hom : (α →₀ M) →+ (α →₀ N) :=
{ to_fun := (map_range f f.map_zero : (α →₀ M) → (α →₀ N)),
map_zero' := map_range_zero,
map_add' := λ a b, map_range_add f.map_add _ _ }
lemma map_range_multiset_sum (m : multiset (α →₀ M)) :
map_range f f.map_zero m.sum = (m.map $ λx, map_range f f.map_zero x).sum :=
(m.sum_hom (map_range.add_monoid_hom f)).symm
lemma map_range_finset_sum (s : finset ι) (g : ι → (α →₀ M)) :
map_range f f.map_zero (∑ x in s, g x) = ∑ x in s, map_range f f.map_zero (g x) :=
by rw [finset.sum.equations._eqn_1, map_range_multiset_sum, multiset.map_map]; refl
end map_range
/-! ### Declarations about `map_domain` -/
section map_domain
variables [add_comm_monoid M] {v v₁ v₂ : α →₀ M}
/-- Given `f : α → β` and `v : α →₀ M`, `map_domain f v : β →₀ M`
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/
def map_domain (f : α → β) (v : α →₀ M) : β →₀ M :=
v.sum $ λa, single (f a)
lemma map_domain_apply {f : α → β} (hf : function.injective f) (x : α →₀ M) (a : α) :
map_domain f x (f a) = x a :=
begin
rw [map_domain, sum_apply, sum, finset.sum_eq_single a, single_eq_same],
{ assume b _ hba, exact single_eq_of_ne (hf.ne hba) },
{ assume h, rw [not_mem_support_iff.1 h, single_zero, zero_apply] }
end
lemma map_domain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ set.range f) :
map_domain f x a = 0 :=
begin
rw [map_domain, sum_apply, sum],
exact finset.sum_eq_zero
(assume a' h', single_eq_of_ne $ assume eq, h $ eq ▸ set.mem_range_self _)
end
lemma map_domain_id : map_domain id v = v :=
sum_single _
lemma map_domain_comp {f : α → β} {g : β → γ} :
map_domain (g ∘ f) v = map_domain g (map_domain f v) :=
begin
refine ((sum_sum_index _ _).trans _).symm,
{ intros, exact single_zero },
{ intros, exact single_add },
refine sum_congr rfl (λ _ _, sum_single_index _),
{ exact single_zero }
end
lemma map_domain_single {f : α → β} {a : α} {b : M} : map_domain f (single a b) = single (f a) b :=
sum_single_index single_zero
@[simp] lemma map_domain_zero {f : α → β} : map_domain f (0 : α →₀ M) = (0 : β →₀ M) :=
sum_zero_index
lemma map_domain_congr {f g : α → β} (h : ∀x∈v.support, f x = g x) :
v.map_domain f = v.map_domain g :=
finset.sum_congr rfl $ λ _ H, by simp only [h _ H]
lemma map_domain_add {f : α → β} : map_domain f (v₁ + v₂) = map_domain f v₁ + map_domain f v₂ :=
sum_add_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_finset_sum {f : α → β} {s : finset ι} {v : ι → α →₀ M} :
map_domain f (∑ i in s, v i) = ∑ i in s, map_domain f (v i) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_sum [has_zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} :
map_domain f (s.sum v) = s.sum (λa b, map_domain f (v a b)) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_support {f : α → β} {s : α →₀ M} :
(s.map_domain f).support ⊆ s.support.image f :=
finset.subset.trans support_sum $
finset.subset.trans (finset.bUnion_mono $ assume a ha, support_single_subset) $
by rw [finset.bUnion_singleton]; exact subset.refl _
@[to_additive]
lemma prod_map_domain_index [comm_monoid N] {f : α → β} {s : α →₀ M}
{h : β → M → N} (h_zero : ∀b, h b 0 = 1) (h_add : ∀b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) :
(map_domain f s).prod h = s.prod (λa m, h (f a) m) :=
(prod_sum_index h_zero h_add).trans $ prod_congr rfl $ λ _ _, prod_single_index (h_zero _)
/--
A version of `sum_map_domain_index` that takes a bundled `add_monoid_hom`,
rather than separate linearity hypotheses.
-/
-- Note that in `prod_map_domain_index`, `M` is still an additive monoid,
-- so there is no analogous version in terms of `monoid_hom`.
@[simp]
lemma sum_map_domain_index_add_monoid_hom [add_comm_monoid N] {f : α → β}
{s : α →₀ M} (h : β → M →+ N) :
(map_domain f s).sum (λ b m, h b m) = s.sum (λ a m, h (f a) m) :=
@sum_map_domain_index _ _ _ _ _ _ _ _
(λ b m, h b m)
(λ b, (h b).map_zero)
(λ b m₁ m₂, (h b).map_add _ _)
lemma emb_domain_eq_map_domain (f : α ↪ β) (v : α →₀ M) :
emb_domain f v = map_domain f v :=
begin
ext a,
by_cases a ∈ set.range f,
{ rcases h with ⟨a, rfl⟩,
rw [map_domain_apply f.injective, emb_domain_apply] },
{ rw [map_domain_notin_range, emb_domain_notin_range]; assumption }
end
@[to_additive]
lemma prod_map_domain_index_inj [comm_monoid N] {f : α → β} {s : α →₀ M}
{h : β → M → N} (hf : function.injective f) :
(s.map_domain f).prod h = s.prod (λa b, h (f a) b) :=
by rw [←function.embedding.coe_fn_mk f hf, ←emb_domain_eq_map_domain, prod_emb_domain]
lemma map_domain_injective {f : α → β} (hf : function.injective f) :
function.injective (map_domain f : (α →₀ M) → (β →₀ M)) :=
begin
assume v₁ v₂ eq, ext a,
have : map_domain f v₁ (f a) = map_domain f v₂ (f a), { rw eq },
rwa [map_domain_apply hf, map_domain_apply hf] at this,
end
end map_domain
/-! ### Declarations about `comap_domain` -/
section comap_domain
/-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on
the preimage of `l.support`, `comap_domain f l hf` is the finitely supported function
from `α` to `M` given by composing `l` with `f`. -/
def comap_domain [has_zero M] (f : α → β) (l : β →₀ M) (hf : set.inj_on f (f ⁻¹' ↑l.support)) :
α →₀ M :=
{ support := l.support.preimage f hf,
to_fun := (λ a, l (f a)),
mem_support_to_fun :=
begin
intros a,
simp only [finset.mem_def.symm, finset.mem_preimage],
exact l.mem_support_to_fun (f a),
end }
@[simp]
lemma comap_domain_apply [has_zero M] (f : α → β) (l : β →₀ M)
(hf : set.inj_on f (f ⁻¹' ↑l.support)) (a : α) :
comap_domain f l hf a = l (f a) :=
rfl
lemma sum_comap_domain [has_zero M] [add_comm_monoid N]
(f : α → β) (l : β →₀ M) (g : β → M → N)
(hf : set.bij_on f (f ⁻¹' ↑l.support) ↑l.support) :
(comap_domain f l hf.inj_on).sum (g ∘ f) = l.sum g :=
begin
simp only [sum, comap_domain_apply, (∘)],
simp [comap_domain, finset.sum_preimage_of_bij f _ _ (λ x, g x (l x))],
end
lemma eq_zero_of_comap_domain_eq_zero [add_comm_monoid M]
(f : α → β) (l : β →₀ M) (hf : set.bij_on f (f ⁻¹' ↑l.support) ↑l.support) :
comap_domain f l hf.inj_on = 0 → l = 0 :=
begin
rw [← support_eq_empty, ← support_eq_empty, comap_domain],
simp only [finset.ext_iff, finset.not_mem_empty, iff_false, mem_preimage],
assume h a ha,
cases hf.2.2 ha with b hb,
exact h b (hb.2.symm ▸ ha)
end
lemma map_domain_comap_domain [add_comm_monoid M] (f : α → β) (l : β →₀ M)
(hf : function.injective f) (hl : ↑l.support ⊆ set.range f):
map_domain f (comap_domain f l (hf.inj_on _)) = l :=
begin
ext a,
by_cases h_cases: a ∈ set.range f,
{ rcases set.mem_range.1 h_cases with ⟨b, hb⟩,
rw [hb.symm, map_domain_apply hf, comap_domain_apply] },
{ rw map_domain_notin_range _ _ h_cases,
by_contra h_contr,
apply h_cases (hl $ finset.mem_coe.2 $ mem_support_iff.2 $ λ h, h_contr h.symm) }
end
end comap_domain
/-! ### Declarations about `filter` -/
section filter
section has_zero
variables [has_zero M] (p : α → Prop) (f : α →₀ M)
/-- `filter p f` is the function which is `f a` if `p a` is true and 0 otherwise. -/
def filter (p : α → Prop) (f : α →₀ M) : α →₀ M :=
{ to_fun := λ a, if p a then f a else 0,
support := f.support.filter (λ a, p a),
mem_support_to_fun := λ a, by split_ifs; { simp only [h, mem_filter, mem_support_iff], tauto } }
lemma filter_apply (a : α) : f.filter p a = if p a then f a else 0 := rfl
lemma filter_eq_indicator : ⇑(f.filter p) = set.indicator {x | p x} f := rfl
@[simp] lemma filter_apply_pos {a : α} (h : p a) : f.filter p a = f a :=
if_pos h
@[simp] lemma filter_apply_neg {a : α} (h : ¬ p a) : f.filter p a = 0 :=
if_neg h
@[simp] lemma support_filter : (f.filter p).support = f.support.filter p := rfl
lemma filter_zero : (0 : α →₀ M).filter p = 0 :=
by rw [← support_eq_empty, support_filter, support_zero, finset.filter_empty]
@[simp] lemma filter_single_of_pos
{a : α} {b : M} (h : p a) : (single a b).filter p = single a b :=
coe_fn_injective $ by simp [filter_eq_indicator, set.subset_def, mem_support_single, h]
@[simp] lemma filter_single_of_neg
{a : α} {b : M} (h : ¬ p a) : (single a b).filter p = 0 :=
ext $ by simp [filter_eq_indicator, single_apply_eq_zero, @imp.swap (p _), h]
end has_zero
lemma filter_pos_add_filter_neg [add_monoid M] (f : α →₀ M) (p : α → Prop) :
f.filter p + f.filter (λa, ¬ p a) = f :=
coe_fn_injective $ set.indicator_self_add_compl {x | p x} f
end filter
/-! ### Declarations about `frange` -/
section frange
variables [has_zero M]
/-- `frange f` is the image of `f` on the support of `f`. -/
def frange (f : α →₀ M) : finset M := finset.image f f.support
theorem mem_frange {f : α →₀ M} {y : M} :
y ∈ f.frange ↔ y ≠ 0 ∧ ∃ x, f x = y :=
finset.mem_image.trans
⟨λ ⟨x, hx1, hx2⟩, ⟨hx2 ▸ mem_support_iff.1 hx1, x, hx2⟩,
λ ⟨hy, x, hx⟩, ⟨x, mem_support_iff.2 (hx.symm ▸ hy), hx⟩⟩
theorem zero_not_mem_frange {f : α →₀ M} : (0:M) ∉ f.frange :=
λ H, (mem_frange.1 H).1 rfl
theorem frange_single {x : α} {y : M} : frange (single x y) ⊆ {y} :=
λ r hr, let ⟨t, ht1, ht2⟩ := mem_frange.1 hr in ht2 ▸
(by rw single_apply at ht2 ⊢; split_ifs at ht2 ⊢; [exact finset.mem_singleton_self _, cc])
end frange
/-! ### Declarations about `subtype_domain` -/
section subtype_domain
section zero
variables [has_zero M] {p : α → Prop}
/-- `subtype_domain p f` is the restriction of the finitely supported function
`f` to the subtype `p`. -/
def subtype_domain (p : α → Prop) (f : α →₀ M) : (subtype p →₀ M) :=
⟨f.support.subtype p, f ∘ coe, λ a, by simp only [mem_subtype, mem_support_iff]⟩
@[simp] lemma support_subtype_domain {f : α →₀ M} :
(subtype_domain p f).support = f.support.subtype p :=
rfl
@[simp] lemma subtype_domain_apply {a : subtype p} {v : α →₀ M} :
(subtype_domain p v) a = v (a.val) :=
rfl
@[simp] lemma subtype_domain_zero : subtype_domain p (0 : α →₀ M) = 0 :=
rfl
lemma subtype_domain_eq_zero_iff' {f : α →₀ M} :
f.subtype_domain p = 0 ↔ ∀ x, p x → f x = 0 :=
by simp_rw [← support_eq_empty, support_subtype_domain, subtype_eq_empty, not_mem_support_iff]
lemma subtype_domain_eq_zero_iff {f : α →₀ M} (hf : ∀ x ∈ f.support , p x) :
f.subtype_domain p = 0 ↔ f = 0 :=
subtype_domain_eq_zero_iff'.trans ⟨λ H, ext $ λ x,
if hx : p x then H x hx else not_mem_support_iff.1 $ mt (hf x) hx, λ H x _, by simp [H]⟩
@[to_additive]
lemma prod_subtype_domain_index [comm_monoid N] {v : α →₀ M}
{h : α → M → N} (hp : ∀x∈v.support, p x) :
(v.subtype_domain p).prod (λa b, h a b) = v.prod h :=
prod_bij (λp _, p.val)
(λ _, mem_subtype.1)
(λ _ _, rfl)
(λ _ _ _ _, subtype.eq)
(λ b hb, ⟨⟨b, hp b hb⟩, mem_subtype.2 hb, rfl⟩)
end zero
section monoid
variables [add_monoid M] {p : α → Prop} {v v' : α →₀ M}
@[simp] lemma subtype_domain_add {v v' : α →₀ M} :
(v + v').subtype_domain p = v.subtype_domain p + v'.subtype_domain p :=
ext $ λ _, rfl
instance subtype_domain.is_add_monoid_hom :
is_add_monoid_hom (subtype_domain p : (α →₀ M) → subtype p →₀ M) :=
{ map_add := λ _ _, subtype_domain_add, map_zero := subtype_domain_zero }
/-- `finsupp.filter` as an `add_monoid_hom`. -/
def filter_add_hom (p : α → Prop) : (α →₀ M) →+ (α →₀ M) :=
{ to_fun := filter p,
map_zero' := filter_zero p,
map_add' := λ f g, coe_fn_injective $ set.indicator_add {x | p x} f g }
@[simp] lemma filter_add {v v' : α →₀ M} : (v + v').filter p = v.filter p + v'.filter p :=
(filter_add_hom p).map_add v v'
end monoid
section comm_monoid
variables [add_comm_monoid M] {p : α → Prop}
lemma subtype_domain_sum {s : finset ι} {h : ι → α →₀ M} :
(∑ c in s, h c).subtype_domain p = ∑ c in s, (h c).subtype_domain p :=
eq.symm (s.sum_hom _)
lemma subtype_domain_finsupp_sum [has_zero N] {s : β →₀ N} {h : β → N → α →₀ M} :
(s.sum h).subtype_domain p = s.sum (λc d, (h c d).subtype_domain p) :=
subtype_domain_sum
lemma filter_sum (s : finset ι) (f : ι → α →₀ M) :
(∑ a in s, f a).filter p = ∑ a in s, filter p (f a) :=
(filter_add_hom p : (α →₀ M) →+ _).map_sum f s
lemma filter_eq_sum (p : α → Prop) (f : α →₀ M) :
f.filter p = ∑ i in f.support.filter p, single i (f i) :=
(f.filter p).sum_single.symm.trans $ finset.sum_congr rfl $
λ x hx, by rw [filter_apply_pos _ _ (mem_filter.1 hx).2]
end comm_monoid
section group
variables [add_group G] {p : α → Prop} {v v' : α →₀ G}
@[simp] lemma subtype_domain_neg : (- v).subtype_domain p = - v.subtype_domain p :=
ext $ λ _, rfl
@[simp] lemma subtype_domain_sub :
(v - v').subtype_domain p = v.subtype_domain p - v'.subtype_domain p :=
ext $ λ _, rfl
end group
end subtype_domain
/-! ### Declarations relating `finsupp` to `multiset` -/
section multiset
/-- Given `f : α →₀ ℕ`, `f.to_multiset` is the multiset with multiplicities given by the values of
`f` on the elements of `α`. We define this function as an `add_equiv`. -/
def to_multiset : (α →₀ ℕ) ≃+ multiset α :=
{ to_fun := λ f, f.sum (λa n, n •ℕ {a}),
inv_fun := λ s, ⟨s.to_finset, λ a, s.count a, λ a, by simp⟩,
left_inv := λ f, ext $ λ a,
suffices (if f a = 0 then 0 else f a) = f a,
by simpa [finsupp.sum, multiset.count_sum', multiset.count_cons],
by split_ifs with h; [rw h, refl],
right_inv := λ s, by simp [finsupp.sum],
map_add' := λ f g, sum_add_index (λ a, zero_nsmul _) (λ a, add_nsmul _) }
lemma to_multiset_zero : (0 : α →₀ ℕ).to_multiset = 0 :=
rfl
lemma to_multiset_add (m n : α →₀ ℕ) :
(m + n).to_multiset = m.to_multiset + n.to_multiset :=
to_multiset.map_add m n
lemma to_multiset_apply (f : α →₀ ℕ) : f.to_multiset = f.sum (λ a n, n •ℕ {a}) := rfl
@[simp] lemma to_multiset_single (a : α) (n : ℕ) : to_multiset (single a n) = n •ℕ {a} :=
by rw [to_multiset_apply, sum_single_index]; apply zero_nsmul
lemma card_to_multiset (f : α →₀ ℕ) : f.to_multiset.card = f.sum (λa, id) :=
by simp [to_multiset_apply, add_monoid_hom.map_finsupp_sum, function.id_def]
lemma to_multiset_map (f : α →₀ ℕ) (g : α → β) :
f.to_multiset.map g = (f.map_domain g).to_multiset :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.map_zero, map_domain_zero, to_multiset_zero] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.map_add, ih, map_domain_add, map_domain_single,
to_multiset_single, to_multiset_add, to_multiset_single,
is_add_monoid_hom.map_nsmul (multiset.map g)],
refl }
end
@[simp] lemma prod_to_multiset [comm_monoid M] (f : M →₀ ℕ) :
f.to_multiset.prod = f.prod (λa n, a ^ n) :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.prod_zero, finsupp.prod_zero_index] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.prod_add, ih, to_multiset_single, finsupp.prod_add_index,
finsupp.prod_single_index, multiset.prod_smul, multiset.singleton_eq_singleton,
multiset.prod_singleton],
{ exact pow_zero a },
{ exact pow_zero },
{ exact pow_add } }
end
@[simp] lemma to_finset_to_multiset (f : α →₀ ℕ) : f.to_multiset.to_finset = f.support :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.to_finset_zero, support_zero] },
{ assume a n f ha hn ih,
rw [to_multiset_add, multiset.to_finset_add, ih, to_multiset_single, support_add_eq,
support_single_ne_zero hn, multiset.to_finset_nsmul _ _ hn,
multiset.singleton_eq_singleton, multiset.to_finset_cons, multiset.to_finset_zero],
refl,
refine disjoint.mono_left support_single_subset _,
rwa [finset.singleton_disjoint] }
end
@[simp] lemma count_to_multiset (f : α →₀ ℕ) (a : α) :
f.to_multiset.count a = f a :=
calc f.to_multiset.count a = f.sum (λx n, (n •ℕ {x} : multiset α).count a) :
(f.support.sum_hom $ multiset.count a).symm
... = f.sum (λx n, n * ({x} : multiset α).count a) : by simp only [multiset.count_smul]
... = f.sum (λx n, n * (x ::ₘ 0 : multiset α).count a) : rfl
... = f a * (a ::ₘ 0 : multiset α).count a : sum_eq_single _
(λ a' _ H, by simp only [multiset.count_cons_of_ne (ne.symm H), multiset.count_zero, mul_zero])
(λ H, by simp only [not_mem_support_iff.1 H, zero_mul])
... = f a : by simp only [multiset.count_singleton, mul_one]
lemma mem_support_multiset_sum [add_comm_monoid M]
{s : multiset (α →₀ M)} (a : α) :
a ∈ s.sum.support → ∃f∈s, a ∈ (f : α →₀ M).support :=
multiset.induction_on s false.elim
begin
assume f s ih ha,
by_cases a ∈ f.support,
{ exact ⟨f, multiset.mem_cons_self _ _, h⟩ },
{ simp only [multiset.sum_cons, mem_support_iff, add_apply,
not_mem_support_iff.1 h, zero_add] at ha,
rcases ih (mem_support_iff.2 ha) with ⟨f', h₀, h₁⟩,
exact ⟨f', multiset.mem_cons_of_mem h₀, h₁⟩ }
end
lemma mem_support_finset_sum [add_comm_monoid M]
{s : finset ι} {h : ι → α →₀ M} (a : α) (ha : a ∈ (∑ c in s, h c).support) :
∃ c ∈ s, a ∈ (h c).support :=
let ⟨f, hf, hfa⟩ := mem_support_multiset_sum a ha in
let ⟨c, hc, eq⟩ := multiset.mem_map.1 hf in
⟨c, hc, eq.symm ▸ hfa⟩
@[simp] lemma mem_to_multiset (f : α →₀ ℕ) (i : α) :
i ∈ f.to_multiset ↔ i ∈ f.support :=
by rw [← multiset.count_ne_zero, finsupp.count_to_multiset, finsupp.mem_support_iff]
end multiset
/-! ### Declarations about `curry` and `uncurry` -/
section curry_uncurry
variables [add_comm_monoid M] [add_comm_monoid N]
/-- Given a finitely supported function `f` from a product type `α × β` to `γ`,
`curry f` is the "curried" finitely supported function from `α` to the type of
finitely supported functions from `β` to `γ`. -/
protected def curry (f : (α × β) →₀ M) : α →₀ (β →₀ M) :=
f.sum $ λp c, single p.1 (single p.2 c)
lemma sum_curry_index (f : (α × β) →₀ M) (g : α → β → M → N)
(hg₀ : ∀ a b, g a b 0 = 0) (hg₁ : ∀a b c₀ c₁, g a b (c₀ + c₁) = g a b c₀ + g a b c₁) :
f.curry.sum (λa f, f.sum (g a)) = f.sum (λp c, g p.1 p.2 c) :=
begin
rw [finsupp.curry],
transitivity,
{ exact sum_sum_index (assume a, sum_zero_index)
(assume a b₀ b₁, sum_add_index (assume a, hg₀ _ _) (assume c d₀ d₁, hg₁ _ _ _ _)) },
congr, funext p c,
transitivity,
{ exact sum_single_index sum_zero_index },
exact sum_single_index (hg₀ _ _)
end
/-- Given a finitely supported function `f` from `α` to the type of
finitely supported functions from `β` to `M`,
`uncurry f` is the "uncurried" finitely supported function from `α × β` to `M`. -/
protected def uncurry (f : α →₀ (β →₀ M)) : (α × β) →₀ M :=
f.sum $ λa g, g.sum $ λb c, single (a, b) c
/-- `finsupp_prod_equiv` defines the `equiv` between `((α × β) →₀ M)` and `(α →₀ (β →₀ M))` given by
currying and uncurrying. -/
def finsupp_prod_equiv : ((α × β) →₀ M) ≃ (α →₀ (β →₀ M)) :=
by refine ⟨finsupp.curry, finsupp.uncurry, λ f, _, λ f, _⟩; simp only [
finsupp.curry, finsupp.uncurry, sum_sum_index, sum_zero_index, sum_add_index,
sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff,
forall_3_true_iff, prod.mk.eta, (single_sum _ _ _).symm, sum_single]
lemma filter_curry (f : α × β →₀ M) (p : α → Prop) :
(f.filter (λa:α×β, p a.1)).curry = f.curry.filter p :=
begin
rw [finsupp.curry, finsupp.curry, finsupp.sum, finsupp.sum, filter_sum, support_filter,
sum_filter],
refine finset.sum_congr rfl _,
rintros ⟨a₁, a₂⟩ ha,
dsimp only,
split_ifs,
{ rw [filter_apply_pos, filter_single_of_pos]; exact h },
{ rwa [filter_single_of_neg] }
end
lemma support_curry (f : α × β →₀ M) : f.curry.support ⊆ f.support.image prod.fst :=
begin
rw ← finset.bUnion_singleton,
refine finset.subset.trans support_sum _,
refine finset.bUnion_mono (assume a _, support_single_subset)
end
end curry_uncurry
section
variables [group G] [mul_action G α] [add_comm_monoid M]
/--
Scalar multiplication by a group element g,
given by precomposition with the action of g⁻¹ on the domain.
-/
def comap_has_scalar : has_scalar G (α →₀ M) :=
{ smul := λ g f, f.comap_domain (λ a, g⁻¹ • a)
(λ a a' m m' h, by simpa [←mul_smul] using (congr_arg (λ a, g • a) h)) }
local attribute [instance] comap_has_scalar
/--
Scalar multiplication by a group element,
given by precomposition with the action of g⁻¹ on the domain,
is multiplicative in g.
-/
def comap_mul_action : mul_action G (α →₀ M) :=
{ one_smul := λ f, by { ext, dsimp [(•)], simp, },
mul_smul := λ g g' f, by { ext, dsimp [(•)], simp [mul_smul], }, }
local attribute [instance] comap_mul_action
/--
Scalar multiplication by a group element,
given by precomposition with the action of g⁻¹ on the domain,
is additive in the second argument.
-/
def comap_distrib_mul_action :
distrib_mul_action G (α →₀ M) :=
{ smul_zero := λ g, by { ext, dsimp [(•)], simp, },
smul_add := λ g f f', by { ext, dsimp [(•)], simp, }, }
/--
Scalar multiplication by a group element on finitely supported functions on a group,
given by precomposition with the action of g⁻¹. -/
def comap_distrib_mul_action_self :
distrib_mul_action G (G →₀ M) :=
@finsupp.comap_distrib_mul_action G M G _ (monoid.to_mul_action G) _
@[simp]
lemma comap_smul_single (g : G) (a : α) (b : M) :
g • single a b = single (g • a) b :=
begin
ext a',
dsimp [(•)],
by_cases h : g • a = a',
{ subst h, simp [←mul_smul], },
{ simp [single_eq_of_ne h], rw [single_eq_of_ne],
rintro rfl, simpa [←mul_smul] using h, }
end
@[simp]
lemma comap_smul_apply (g : G) (f : α →₀ M) (a : α) :
(g • f) a = f (g⁻¹ • a) := rfl
end
section
instance [semiring R] [add_comm_monoid M] [semimodule R M] : has_scalar R (α →₀ M) :=
⟨λa v, v.map_range ((•) a) (smul_zero _)⟩
/-!
Throughout this section, some `semiring` arguments are specified with `{}` instead of `[]`.
See note [implicit instance arguments].
-/
@[simp] lemma coe_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M]
(b : R) (v : α →₀ M) : ⇑(b • v) = b • v := rfl
lemma smul_apply {_ : semiring R} [add_comm_monoid M] [semimodule R M]
(b : R) (v : α →₀ M) (a : α) : (b • v) a = b • (v a) := rfl
variables (α M)
instance [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule R (α →₀ M) :=
{ smul := (•),
smul_add := λ a x y, ext $ λ _, smul_add _ _ _,
add_smul := λ a x y, ext $ λ _, add_smul _ _ _,
one_smul := λ x, ext $ λ _, one_smul _ _,
mul_smul := λ r s x, ext $ λ _, mul_smul _ _ _,
zero_smul := λ x, ext $ λ _, zero_smul _ _,
smul_zero := λ x, ext $ λ _, smul_zero _ }
instance [semiring R] [semiring S] [add_comm_monoid M] [semimodule R M] [semimodule S M]
[has_scalar R S] [is_scalar_tower R S M] :
is_scalar_tower R S (α →₀ M) :=
{ smul_assoc := λ r s a, ext $ λ _, smul_assoc _ _ _ }
instance [semiring R] [semiring S] [add_comm_monoid M] [semimodule R M] [semimodule S M]
[smul_comm_class R S M] :
smul_comm_class R S (α →₀ M) :=
{ smul_comm := λ r s a, ext $ λ _, smul_comm _ _ _ }
variables {α M} {R}
lemma support_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M] {b : R} {g : α →₀ M} :
(b • g).support ⊆ g.support :=
λ a, by simp only [smul_apply, mem_support_iff, ne.def]; exact mt (λ h, h.symm ▸ smul_zero _)
section
variables {p : α → Prop}
@[simp] lemma filter_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M]
{b : R} {v : α →₀ M} : (b • v).filter p = b • v.filter p :=
coe_fn_injective $ set.indicator_smul {x | p x} b v
end
lemma map_domain_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M]
{f : α → β} (b : R) (v : α →₀ M) : map_domain f (b • v) = b • map_domain f v :=
begin
change map_domain f (map_range _ _ _) = map_range _ _ _,
apply finsupp.induction v, { simp only [map_domain_zero, map_range_zero] },
intros a b v' hv₁ hv₂ IH,
rw [map_range_add, map_domain_add, IH, map_domain_add, map_range_add,
map_range_single, map_domain_single, map_domain_single, map_range_single];
apply smul_add
end
@[simp] lemma smul_single {_ : semiring R} [add_comm_monoid M] [semimodule R M]
(c : R) (a : α) (b : M) : c • finsupp.single a b = finsupp.single a (c • b) :=
map_range_single
@[simp] lemma smul_single' {_ : semiring R}
(c : R) (a : α) (b : R) : c • finsupp.single a b = finsupp.single a (c * b) :=
smul_single _ _ _
lemma smul_single_one [semiring R] (a : α) (b : R) : b • single a 1 = single a b :=
by rw [smul_single, smul_eq_mul, mul_one]
end
lemma sum_smul_index [semiring R] [add_comm_monoid M] {g : α →₀ R} {b : R} {h : α → R → M}
(h0 : ∀i, h i 0 = 0) : (b • g).sum h = g.sum (λi a, h i (b * a)) :=
finsupp.sum_map_range_index h0
lemma sum_smul_index' [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid N]
{g : α →₀ M} {b : R} {h : α → M → N} (h0 : ∀i, h i 0 = 0) :
(b • g).sum h = g.sum (λi c, h i (b • c)) :=
finsupp.sum_map_range_index h0
/-- A version of `finsupp.sum_smul_index'` for bundled additive maps. -/
lemma sum_smul_index_add_monoid_hom
[semiring R] [add_comm_monoid M] [add_comm_monoid N] [semimodule R M]
{g : α →₀ M} {b : R} {h : α → M →+ N} :
(b • g).sum (λ a, h a) = g.sum (λ i c, h i (b • c)) :=
sum_map_range_index (λ i, (h i).map_zero)
instance [semiring R] [add_comm_monoid M] [semimodule R M] {ι : Type*}
[no_zero_smul_divisors R M] : no_zero_smul_divisors R (ι →₀ M) :=
⟨λ c f h, or_iff_not_imp_left.mpr (λ hc, finsupp.ext
(λ i, (smul_eq_zero.mp (finsupp.ext_iff.mp h i)).resolve_left hc))⟩
section
variables [semiring R] [semiring S]
lemma sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :
(s.sum f) * b = s.sum (λ a c, (f a c) * b) :=
by simp only [finsupp.sum, finset.sum_mul]
lemma mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :
b * (s.sum f) = s.sum (λ a c, b * (f a c)) :=
by simp only [finsupp.sum, finset.mul_sum]
instance unique_of_right [subsingleton R] : unique (α →₀ R) :=
{ uniq := λ l, ext $ λ i, subsingleton.elim _ _,
.. finsupp.inhabited }
end
/-- Given an `add_comm_monoid M` and `s : set α`, `restrict_support_equiv s M` is the `equiv`
between the subtype of finitely supported functions with support contained in `s` and
the type of finitely supported functions from `s`. -/
def restrict_support_equiv (s : set α) (M : Type*) [add_comm_monoid M] :
{f : α →₀ M // ↑f.support ⊆ s } ≃ (s →₀ M):=
begin
refine ⟨λf, subtype_domain (λx, x ∈ s) f.1, λ f, ⟨f.map_domain subtype.val, _⟩, _, _⟩,
{ refine set.subset.trans (finset.coe_subset.2 map_domain_support) _,
rw [finset.coe_image, set.image_subset_iff],
exact assume x hx, x.2 },
{ rintros ⟨f, hf⟩,
apply subtype.eq,
ext a,
dsimp only,
refine classical.by_cases (assume h : a ∈ set.range (subtype.val : s → α), _) (assume h, _),
{ rcases h with ⟨x, rfl⟩,
rw [map_domain_apply subtype.val_injective, subtype_domain_apply] },
{ convert map_domain_notin_range _ _ h,
rw [← not_mem_support_iff],
refine mt _ h,
exact assume ha, ⟨⟨a, hf ha⟩, rfl⟩ } },
{ assume f,
ext ⟨a, ha⟩,
dsimp only,
rw [subtype_domain_apply, map_domain_apply subtype.val_injective] }
end
/-- Given `add_comm_monoid M` and `e : α ≃ β`, `dom_congr e` is the corresponding `equiv` between
`α →₀ M` and `β →₀ M`. -/
protected def dom_congr [add_comm_monoid M] (e : α ≃ β) : (α →₀ M) ≃+ (β →₀ M) :=
{ to_fun := map_domain e,
inv_fun := map_domain e.symm,
left_inv := begin
assume v,
simp only [map_domain_comp.symm, (∘), equiv.symm_apply_apply],
exact map_domain_id
end,
right_inv := begin
assume v,
simp only [map_domain_comp.symm, (∘), equiv.apply_symm_apply],
exact map_domain_id
end,
map_add' := λ a b, map_domain_add, }
end finsupp
namespace finsupp
/-! ### Declarations about sigma types -/
section sigma
variables {αs : ι → Type*} [has_zero M] (l : (Σ i, αs i) →₀ M)
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `M` and
an index element `i : ι`, `split l i` is the `i`th component of `l`,
a finitely supported function from `as i` to `M`. -/
def split (i : ι) : αs i →₀ M :=
l.comap_domain (sigma.mk i) (λ x1 x2 _ _ hx, heq_iff_eq.1 (sigma.mk.inj hx).2)
lemma split_apply (i : ι) (x : αs i) : split l i x = l ⟨i, x⟩ :=
begin
dunfold split,
rw comap_domain_apply
end
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `β`,
`split_support l` is the finset of indices in `ι` that appear in the support of `l`. -/
def split_support : finset ι := l.support.image sigma.fst
lemma mem_split_support_iff_nonzero (i : ι) :
i ∈ split_support l ↔ split l i ≠ 0 :=
begin
rw [split_support, mem_image, ne.def, ← support_eq_empty, ← ne.def,
← finset.nonempty_iff_ne_empty, split, comap_domain, finset.nonempty],
simp only [exists_prop, finset.mem_preimage, exists_and_distrib_right, exists_eq_right,
mem_support_iff, sigma.exists, ne.def]
end
/-- Given `l`, a finitely supported function from the sigma type `Σ i, αs i` to `β` and
an `ι`-indexed family `g` of functions from `(αs i →₀ β)` to `γ`, `split_comp` defines a
finitely supported function from the index type `ι` to `γ` given by composing `g i` with
`split l i`. -/
def split_comp [has_zero N] (g : Π i, (αs i →₀ M) → N)
(hg : ∀ i x, x = 0 ↔ g i x = 0) : ι →₀ N :=
{ support := split_support l,
to_fun := λ i, g i (split l i),
mem_support_to_fun :=
begin
intros i,
rw [mem_split_support_iff_nonzero, not_iff_not, hg],
end }
lemma sigma_support : l.support = l.split_support.sigma (λ i, (l.split i).support) :=
by simp only [finset.ext_iff, split_support, split, comap_domain, mem_image,
mem_preimage, sigma.forall, mem_sigma]; tauto
lemma sigma_sum [add_comm_monoid N] (f : (Σ (i : ι), αs i) → M → N) :
l.sum f = ∑ i in split_support l, (split l i).sum (λ (a : αs i) b, f ⟨i, a⟩ b) :=
by simp only [sum, sigma_support, sum_sigma, split_apply]
end sigma
end finsupp
/-! ### Declarations relating `multiset` to `finsupp` -/
namespace multiset
/-- Given a multiset `s`, `s.to_finsupp` returns the finitely supported function on `ℕ` given by
the multiplicities of the elements of `s`. -/
def to_finsupp : multiset α ≃+ (α →₀ ℕ) := finsupp.to_multiset.symm
@[simp] lemma to_finsupp_support (s : multiset α) :
s.to_finsupp.support = s.to_finset :=
rfl
@[simp] lemma to_finsupp_apply (s : multiset α) (a : α) :
to_finsupp s a = s.count a :=
rfl
lemma to_finsupp_zero : to_finsupp (0 : multiset α) = 0 := add_equiv.map_zero _
lemma to_finsupp_add (s t : multiset α) :
to_finsupp (s + t) = to_finsupp s + to_finsupp t :=
to_finsupp.map_add s t
@[simp] lemma to_finsupp_singleton (a : α) : to_finsupp (a ::ₘ 0) = finsupp.single a 1 :=
finsupp.to_multiset.symm_apply_eq.2 $ by simp
@[simp] lemma to_finsupp_to_multiset (s : multiset α) :
s.to_finsupp.to_multiset = s :=
finsupp.to_multiset.apply_symm_apply s
lemma to_finsupp_eq_iff {s : multiset α} {f : α →₀ ℕ} : s.to_finsupp = f ↔ s = f.to_multiset :=
finsupp.to_multiset.symm_apply_eq
end multiset
@[simp] lemma finsupp.to_multiset_to_finsupp (f : α →₀ ℕ) :
f.to_multiset.to_finsupp = f :=
finsupp.to_multiset.symm_apply_apply f
/-! ### Declarations about order(ed) instances on `finsupp` -/
namespace finsupp
instance [preorder M] [has_zero M] : preorder (α →₀ M) :=
{ le := λ f g, ∀ s, f s ≤ g s,
le_refl := λ f s, le_refl _,
le_trans := λ f g h Hfg Hgh s, le_trans (Hfg s) (Hgh s) }
instance [partial_order M] [has_zero M] : partial_order (α →₀ M) :=
{ le_antisymm := λ f g hfg hgf, ext $ λ s, le_antisymm (hfg s) (hgf s),
.. finsupp.preorder }
instance [ordered_cancel_add_comm_monoid M] : add_left_cancel_semigroup (α →₀ M) :=
{ add_left_cancel := λ a b c h, ext $ λ s,
by { rw ext_iff at h, exact add_left_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_add_comm_monoid M] : add_right_cancel_semigroup (α →₀ M) :=
{ add_right_cancel := λ a b c h, ext $ λ s,
by { rw ext_iff at h, exact add_right_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_add_comm_monoid M] : ordered_cancel_add_comm_monoid (α →₀ M) :=
{ add_le_add_left := λ a b h c s, add_le_add_left (h s) (c s),
le_of_add_le_add_left := λ a b c h s, le_of_add_le_add_left (h s),
.. finsupp.add_comm_monoid, .. finsupp.partial_order,
.. finsupp.add_left_cancel_semigroup, .. finsupp.add_right_cancel_semigroup }
lemma le_def [preorder M] [has_zero M] {f g : α →₀ M} : f ≤ g ↔ ∀ x, f x ≤ g x := iff.rfl
lemma le_iff [canonically_ordered_add_monoid M] (f g : α →₀ M) :
f ≤ g ↔ ∀ s ∈ f.support, f s ≤ g s :=
⟨λ h s hs, h s,
λ h s, if H : s ∈ f.support then h s H else (not_mem_support_iff.1 H).symm ▸ zero_le (g s)⟩
@[simp] lemma add_eq_zero_iff [canonically_ordered_add_monoid M] (f g : α →₀ M) :
f + g = 0 ↔ f = 0 ∧ g = 0 :=
by simp [ext_iff, forall_and_distrib]
/-- `finsupp.to_multiset` as an order isomorphism. -/
def order_iso_multiset : (α →₀ ℕ) ≃o multiset α :=
{ to_equiv := to_multiset.to_equiv,
map_rel_iff' := λ f g, by simp [multiset.le_iff_count, le_def] }
@[simp] lemma coe_order_iso_multiset : ⇑(@order_iso_multiset α) = to_multiset := rfl
@[simp] lemma coe_order_iso_multiset_symm :
⇑(@order_iso_multiset α).symm = multiset.to_finsupp := rfl
lemma to_multiset_strict_mono : strict_mono (@to_multiset α) :=
order_iso_multiset.strict_mono
lemma sum_id_lt_of_lt (m n : α →₀ ℕ) (h : m < n) :
m.sum (λ _, id) < n.sum (λ _, id) :=
begin
rw [← card_to_multiset, ← card_to_multiset],
apply multiset.card_lt_of_lt,
exact to_multiset_strict_mono h
end
variable (α)
/-- The order on `σ →₀ ℕ` is well-founded.-/
lemma lt_wf : well_founded (@has_lt.lt (α →₀ ℕ) _) :=
subrelation.wf (sum_id_lt_of_lt) $ inv_image.wf _ nat.lt_wf
instance decidable_le : decidable_rel (@has_le.le (α →₀ ℕ) _) :=
λ m n, by rw le_iff; apply_instance
variable {α}
@[simp] lemma nat_add_sub_cancel (f g : α →₀ ℕ) : f + g - g = f :=
ext $ λ a, nat.add_sub_cancel _ _
@[simp] lemma nat_add_sub_cancel_left (f g : α →₀ ℕ) : f + g - f = g :=
ext $ λ a, nat.add_sub_cancel_left _ _
lemma nat_add_sub_of_le {f g : α →₀ ℕ} (h : f ≤ g) : f + (g - f) = g :=
ext $ λ a, nat.add_sub_of_le (h a)
lemma nat_sub_add_cancel {f g : α →₀ ℕ} (h : f ≤ g) : g - f + f = g :=
ext $ λ a, nat.sub_add_cancel (h a)
instance : canonically_ordered_add_monoid (α →₀ ℕ) :=
{ bot := 0,
bot_le := λ f s, zero_le (f s),
le_iff_exists_add := λ f g, ⟨λ H, ⟨g - f, (nat_add_sub_of_le H).symm⟩,
λ ⟨c, hc⟩, hc.symm ▸ λ x, by simp⟩,
.. (infer_instance : ordered_add_comm_monoid (α →₀ ℕ)) }
/-- The `finsupp` counterpart of `multiset.antidiagonal`: the antidiagonal of
`s : α →₀ ℕ` consists of all pairs `(t₁, t₂) : (α →₀ ℕ) × (α →₀ ℕ)` such that `t₁ + t₂ = s`.
The finitely supported function `antidiagonal s` is equal to the multiplicities of these pairs. -/
def antidiagonal (f : α →₀ ℕ) : ((α →₀ ℕ) × (α →₀ ℕ)) →₀ ℕ :=
(f.to_multiset.antidiagonal.map (prod.map multiset.to_finsupp multiset.to_finsupp)).to_finsupp
@[simp] lemma mem_antidiagonal_support {f : α →₀ ℕ} {p : (α →₀ ℕ) × (α →₀ ℕ)} :
p ∈ (antidiagonal f).support ↔ p.1 + p.2 = f :=
begin
rcases p with ⟨p₁, p₂⟩,
simp [antidiagonal, ← and.assoc, ← finsupp.to_multiset.apply_eq_iff_eq]
end
lemma swap_mem_antidiagonal_support {n : α →₀ ℕ} {f : (α →₀ ℕ) × (α →₀ ℕ)} :
f.swap ∈ (antidiagonal n).support ↔ f ∈ (antidiagonal n).support :=
by simp only [mem_antidiagonal_support, add_comm, prod.swap]
lemma antidiagonal_support_filter_fst_eq (f g : α →₀ ℕ) :
(antidiagonal f).support.filter (λ p, p.1 = g) = if g ≤ f then {(g, f - g)} else ∅ :=
begin
ext ⟨a, b⟩,
suffices : a = g → (a + b = f ↔ g ≤ f ∧ b = f - g),
{ simpa [apply_ite ((∈) (a, b)), ← and.assoc, @and.right_comm _ (a = _), and.congr_left_iff] },
rintro rfl, split,
{ rintro rfl, exact ⟨le_add_right le_rfl, (nat_add_sub_cancel_left _ _).symm⟩ },
{ rintro ⟨h, rfl⟩, exact nat_add_sub_of_le h }
end
lemma antidiagonal_support_filter_snd_eq (f g : α →₀ ℕ) :
(antidiagonal f).support.filter (λ p, p.2 = g) = if g ≤ f then {(f - g, g)} else ∅ :=
begin
ext ⟨a, b⟩,
suffices : b = g → (a + b = f ↔ g ≤ f ∧ a = f - g),
{ simpa [apply_ite ((∈) (a, b)), ← and.assoc, and.congr_left_iff] },
rintro rfl, split,
{ rintro rfl, exact ⟨le_add_left le_rfl, (nat_add_sub_cancel _ _).symm⟩ },
{ rintro ⟨h, rfl⟩, exact nat_sub_add_cancel h }
end
@[simp] lemma antidiagonal_zero : antidiagonal (0 : α →₀ ℕ) = single (0,0) 1 :=
by rw [← multiset.to_finsupp_singleton]; refl
@[to_additive]
lemma prod_antidiagonal_support_swap {M : Type*} [comm_monoid M] (n : α →₀ ℕ)
(f : (α →₀ ℕ) → (α →₀ ℕ) → M) :
∏ p in (antidiagonal n).support, f p.1 p.2 = ∏ p in (antidiagonal n).support, f p.2 p.1 :=
finset.prod_bij (λ p hp, p.swap) (λ p, swap_mem_antidiagonal_support.2) (λ p hp, rfl)
(λ p₁ p₂ _ _ h, prod.swap_injective h)
(λ p hp, ⟨p.swap, swap_mem_antidiagonal_support.2 hp, p.swap_swap.symm⟩)
/-- The set `{m : α →₀ ℕ | m ≤ n}` as a `finset`. -/
def Iic_finset (n : α →₀ ℕ) : finset (α →₀ ℕ) :=
(antidiagonal n).support.image prod.fst
@[simp] lemma mem_Iic_finset {m n : α →₀ ℕ} : m ∈ Iic_finset n ↔ m ≤ n :=
by simp [Iic_finset, le_iff_exists_add, eq_comm]
@[simp] lemma coe_Iic_finset (n : α →₀ ℕ) : ↑(Iic_finset n) = set.Iic n :=
by { ext, simp }
/-- Let `n : α →₀ ℕ` be a finitely supported function.
The set of `m : α →₀ ℕ` that are coordinatewise less than or equal to `n`,
is a finite set. -/
lemma finite_le_nat (n : α →₀ ℕ) : set.finite {m | m ≤ n} :=
by simpa using (Iic_finset n).finite_to_set
/-- Let `n : α →₀ ℕ` be a finitely supported function.
The set of `m : α →₀ ℕ` that are coordinatewise less than or equal to `n`,
but not equal to `n` everywhere, is a finite set. -/
lemma finite_lt_nat (n : α →₀ ℕ) : set.finite {m | m < n} :=
(finite_le_nat n).subset $ λ m, le_of_lt
end finsupp
namespace multiset
lemma to_finsuppstrict_mono : strict_mono (@to_finsupp α) :=
finsupp.order_iso_multiset.symm.strict_mono
end multiset
|
35036675854752b810e3be28fdd75e884bcaa153 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Meta/Tactic/Split.lean | 847029153fecb965794b3e8f3dd17bc07a8e71fd | [
"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 | 15,444 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Tactic.Simp.Main
import Lean.Meta.Tactic.SplitIf
import Lean.Meta.Tactic.Apply
import Lean.Meta.Tactic.Generalize
namespace Lean.Meta
namespace Split
def getSimpMatchContext : MetaM Simp.Context :=
return {
simpTheorems := {}
congrTheorems := (← getSimpCongrTheorems)
config := { Simp.neutralConfig with dsimp := false }
}
def simpMatch (e : Expr) : MetaM Simp.Result := do
(·.1) <$> Simp.main e (← getSimpMatchContext) (methods := { pre })
where
pre (e : Expr) : SimpM Simp.Step := do
let some app ← matchMatcherApp? e | return Simp.Step.visit { expr := e }
-- First try to reduce matcher
match (← reduceRecMatcher? e) with
| some e' => return Simp.Step.done { expr := e' }
| none =>
match (← Simp.simpMatchCore? app e SplitIf.discharge?) with
| some r => return r
| none => return Simp.Step.visit { expr := e }
def simpMatchTarget (mvarId : MVarId) : MetaM MVarId := mvarId.withContext do
let target ← instantiateMVars (← mvarId.getType)
let r ← simpMatch target
applySimpResultToTarget mvarId target r
private def simpMatchCore (matchDeclName : Name) (matchEqDeclName : Name) (e : Expr) : MetaM Simp.Result := do
(·.1) <$> Simp.main e (← getSimpMatchContext) (methods := { pre })
where
pre (e : Expr) : SimpM Simp.Step := do
if e.isAppOf matchDeclName then
-- First try to reduce matcher
match (← reduceRecMatcher? e) with
| some e' => return Simp.Step.done { expr := e' }
| none =>
-- Try lemma
let simpTheorem := {
origin := .decl matchEqDeclName
proof := mkConst matchEqDeclName
rfl := (← isRflTheorem matchEqDeclName)
}
match (← withReducible <| Simp.tryTheorem? e simpTheorem SplitIf.discharge?) with
| none => return Simp.Step.visit { expr := e }
| some r => return Simp.Step.done r
else
return Simp.Step.visit { expr := e }
private def simpMatchTargetCore (mvarId : MVarId) (matchDeclName : Name) (matchEqDeclName : Name) : MetaM MVarId := do
mvarId.withContext do
let target ← instantiateMVars (← mvarId.getType)
let r ← simpMatchCore matchDeclName matchEqDeclName target
match r.proof? with
| some proof => mvarId.replaceTargetEq r.expr proof
| none => mvarId.replaceTargetDefEq r.expr
private partial def withEqs (lhs rhs : Array Expr) (k : Array Expr → Array Expr → MetaM α) : MetaM α := do
go 0 #[] #[]
where
go (i : Nat) (hs : Array Expr) (rfls : Array Expr) : MetaM α := do
if i < lhs.size then
withLocalDeclD (← mkFreshUserName `heq) (← mkEqHEq lhs[i]! rhs[i]!) fun h => do
let rfl ← if (← inferType h).isEq then mkEqRefl lhs[i]! else mkHEqRefl lhs[i]!
go (i+1) (hs.push h) (rfls.push rfl)
else
k hs rfls
/--
This method makes sure each discriminant is a free variable.
Return the tuple `(discrsNew, discrEqs, mvarId)`. `discrsNew` in an array representing the new discriminants, `discrEqs` is an array of auxiliary equality hypotheses
that connect the new discriminants to the original terms they represent.
Remark: `discrEqs.size ≤ discrsNew.size`
Remark:
We should only generalize `discrs` occurrences as `match`-expression discriminants.
For example, given the following goal.
```
x : Nat
⊢ (match g x with
| 0 => 1
| Nat.succ y => g x) =
2 * x + 1
```
we should not generalize the `g x` in the rhs of the second alternative, and the two resulting goals
for the `split` tactic should be
```
case h_1
x x✝ : Nat
h✝ : g x = 0
⊢ 1 = 2 * x + 1
case h_2
x x✝ y✝ : Nat
h✝ : g x = Nat.succ y✝
⊢ g x = 2 * x + 1
```
-/
private partial def generalizeMatchDiscrs (mvarId : MVarId) (matcherDeclName : Name) (motiveType : Expr) (discrs : Array Expr) : MetaM (Array FVarId × Array FVarId × MVarId) := mvarId.withContext do
if discrs.all (·.isFVar) then
return (discrs.map (·.fvarId!), #[], mvarId)
let some matcherInfo ← getMatcherInfo? matcherDeclName | unreachable!
let numDiscrEqs := matcherInfo.getNumDiscrEqs -- Number of `h : discr = pattern` equations
let (targetNew, rfls) ←
forallTelescope motiveType fun discrVars _ =>
withEqs discrs discrVars fun eqs rfls => do
let foundRef ← IO.mkRef false
let rec mkNewTarget (e : Expr) : MetaM Expr := do
let pre (e : Expr) : MetaM TransformStep := do
if !e.isAppOf matcherDeclName || e.getAppNumArgs != matcherInfo.arity then
return .continue
let some matcherApp ← matchMatcherApp? e | return .continue
for matcherDiscr in matcherApp.discrs, discr in discrs do
unless matcherDiscr == discr do
trace[Meta.Tactic.split] "discr mismatch {matcherDiscr} != {discr}"
return .continue
let matcherApp := { matcherApp with discrs := discrVars }
foundRef.set true
let mut altsNew := #[]
for i in [:matcherApp.alts.size] do
let alt := matcherApp.alts[i]!
let altNumParams := matcherApp.altNumParams[i]!
let altNew ← lambdaTelescope alt fun xs body => do
if xs.size < altNumParams || xs.size < numDiscrEqs then
throwError "'applyMatchSplitter' failed, unexpected `match` alternative"
let body ← mkLambdaFVars xs[altNumParams:] (← mkNewTarget body)
let ys := xs[:altNumParams - numDiscrEqs]
if numDiscrEqs == 0 then
mkLambdaFVars ys body
else
let altEqs := xs[altNumParams - numDiscrEqs : altNumParams]
withNewAltEqs matcherInfo eqs altEqs fun altEqsNew subst => do
let body := body.replaceFVars altEqs subst
mkLambdaFVars (ys++altEqsNew) body
altsNew := altsNew.push altNew
return .done { matcherApp with alts := altsNew }.toExpr
transform (← instantiateMVars e) pre
let targetNew ← mkNewTarget (← mvarId.getType)
unless (← foundRef.get) do
throwError "'applyMatchSplitter' failed, did not find discriminants"
let targetNew ← mkForallFVars (discrVars ++ eqs) targetNew
unless (← isTypeCorrect targetNew) do
throwError "'applyMatchSplitter' failed, failed to generalize target"
return (targetNew, rfls)
let mvarNew ← mkFreshExprSyntheticOpaqueMVar targetNew (← mvarId.getTag)
trace[Meta.Tactic.split] "targetNew:\n{mvarNew.mvarId!}"
mvarId.assign (mkAppN (mkAppN mvarNew discrs) rfls)
let (discrs', mvarId') ← mvarNew.mvarId!.introNP discrs.size
let (discrEqs, mvarId') ← mvarId'.introNP discrs.size
return (discrs', discrEqs, mvarId')
where
/--
- `eqs` are free variables `h_eq : discr = discrVar`. `eqs.size == discrs.size`
- `altEqs` are free variables of the form `h_altEq : discr = pattern`. `altEqs.size = numDiscrEqs ≤ discrs.size`
This method executes `k altEqsNew subst` where
- `altEqsNew` are fresh free variables of the form `h_altEqNew : discrVar = pattern`
- `subst` are terms of the form `h_eq.trans h_altEqNew : discr = pattern`. We use `subst` later to replace occurences of `h_altEq` with `h_eq.trans h_altEqNew`.
-/
withNewAltEqs (matcherInfo : MatcherInfo) (eqs : Array Expr) (altEqs : Array Expr) (k : Array Expr → Array Expr → MetaM Expr) : MetaM Expr := do
let eqs' := (eqs.zip matcherInfo.discrInfos).filterMap fun (eq, info) => if info.hName?.isNone then none else some eq
-- `eqs'.size == altEqs.size ≤ eqs.size`
let rec go (i : Nat) (altEqsNew : Array Expr) (subst : Array Expr) : MetaM Expr := do
if i < altEqs.size then
let altEqDecl ← getFVarLocalDecl altEqs[i]!
let eq := eqs'[i]!
let eqType ← inferType eq
let altEqType := altEqDecl.type
match eqType.eq?, altEqType.eq? with
| some (_, _, discrVar), some (_, _ /- discr -/, pattern) =>
withLocalDeclD altEqDecl.userName (← mkEq discrVar pattern) fun altEqNew => do
go (i+1) (altEqsNew.push altEqNew) (subst.push (← mkEqTrans eq altEqNew))
| _, _ =>
match eqType.heq?, altEqType.heq? with
| some (_, _, _, discrVar), some (_, _ /- discr -/, _, pattern) =>
withLocalDeclD altEqDecl.userName (← mkHEq discrVar pattern) fun altEqNew => do
go (i+1) (altEqsNew.push altEqNew) (subst.push (← mkHEqTrans eq altEqNew))
| _, _ =>
throwError "'applyMatchSplitter' failed, unexpected discriminant equalities"
else
k altEqsNew subst
go 0 #[] #[]
private def substDiscrEqs (mvarId : MVarId) (fvarSubst : FVarSubst) (discrEqs : Array FVarId) : MetaM MVarId := mvarId.withContext do
let mut mvarId := mvarId
let mut fvarSubst := fvarSubst
for fvarId in discrEqs do
if let .fvar fvarId := fvarSubst.apply (mkFVar fvarId) then
let (fvarId, mvarId') ← heqToEq mvarId fvarId
match (← substCore? mvarId' fvarId (symm := false) fvarSubst) with
| some (fvarSubst', mvarId') => mvarId := mvarId'; fvarSubst := fvarSubst'
| none =>
match (← substCore? mvarId' fvarId (symm := true) fvarSubst) with
| some (fvarSubst', mvarId') => mvarId := mvarId'; fvarSubst := fvarSubst'
| none => mvarId := mvarId'
return mvarId
def applyMatchSplitter (mvarId : MVarId) (matcherDeclName : Name) (us : Array Level) (params : Array Expr) (discrs : Array Expr) : MetaM (List MVarId) := do
let some info ← getMatcherInfo? matcherDeclName | throwError "'applyMatchSplitter' failed, '{matcherDeclName}' is not a 'match' auxiliary declaration."
let matchEqns ← Match.getEquationsFor matcherDeclName
-- splitterPre does not have the correct universe elimination level, but this is fine, we only use it to compute the `motiveType`,
-- and we only care about the `motiveType` arguments, and not the resulting `Sort u`.
let splitterPre := mkAppN (mkConst matchEqns.splitterName us.toList) params
let motiveType := (← whnfForall (← inferType splitterPre)).bindingDomain!
trace[Meta.Tactic.split] "applyMatchSplitter\n{mvarId}"
let (discrFVarIds, discrEqs, mvarId) ← generalizeMatchDiscrs mvarId matcherDeclName motiveType discrs
trace[Meta.Tactic.split] "after generalizeMatchDiscrs\n{mvarId}"
let mvarId ← generalizeTargetsEq mvarId motiveType (discrFVarIds.map mkFVar)
mvarId.withContext do trace[Meta.Tactic.split] "discrEqs after generalizeTargetsEq: {discrEqs.map mkFVar}"
trace[Meta.Tactic.split] "after generalize\n{mvarId}"
let numEqs := discrs.size
let (discrFVarIdsNew, mvarId) ← mvarId.introN discrs.size
trace[Meta.Tactic.split] "after introN\n{mvarId}"
let discrsNew := discrFVarIdsNew.map mkFVar
let mvarType ← mvarId.getType
let elimUniv ← mvarId.withContext <| getLevel mvarType
let us ← if let some uElimPos := info.uElimPos? then
pure <| us.set! uElimPos elimUniv
else
unless elimUniv.isZero do
throwError "match-splitter can only eliminate into `Prop`"
pure us
let splitter := mkAppN (mkConst matchEqns.splitterName us.toList) params
mvarId.withContext do
let motive ← mkLambdaFVars discrsNew mvarType
let splitter := mkAppN (mkApp splitter motive) discrsNew
check splitter
trace[Meta.Tactic.split] "after check splitter"
let mvarIds ← mvarId.apply splitter
unless mvarIds.length == matchEqns.size do
throwError "'applyMatchSplitter' failed, unexpected number of goals created after applying splitter for '{matcherDeclName}'."
let (_, mvarIds) ← mvarIds.foldlM (init := (0, [])) fun (i, mvarIds) mvarId => do
let numParams := matchEqns.splitterAltNumParams[i]!
let (_, mvarId) ← mvarId.introN numParams
trace[Meta.Tactic.split] "before unifyEqs\n{mvarId}"
match (← Cases.unifyEqs? (numEqs + info.getNumDiscrEqs) mvarId {}) with
| none => return (i+1, mvarIds) -- case was solved
| some (mvarId, fvarSubst) =>
trace[Meta.Tactic.split] "after unifyEqs\n{mvarId}"
let mvarId ← substDiscrEqs mvarId fvarSubst discrEqs
return (i+1, mvarId::mvarIds)
return mvarIds.reverse
def splitMatch (mvarId : MVarId) (e : Expr) : MetaM (List MVarId) := do
try
let some app ← matchMatcherApp? e | throwError "match application expected"
let matchEqns ← Match.getEquationsFor app.matcherName
let mvarIds ← applyMatchSplitter mvarId app.matcherName app.matcherLevels app.params app.discrs
let (_, mvarIds) ← mvarIds.foldlM (init := (0, [])) fun (i, mvarIds) mvarId => do
let mvarId ← simpMatchTargetCore mvarId app.matcherName matchEqns.eqnNames[i]!
return (i+1, mvarId::mvarIds)
return mvarIds.reverse
catch ex =>
throwNestedTacticEx `splitMatch ex
/-- Return an `if-then-else` or `match-expr` to split. -/
partial def findSplit? (env : Environment) (e : Expr) (splitIte := true) (exceptionSet : ExprSet := {}) : Option Expr :=
go e
where
go (e : Expr) : Option Expr :=
if let some target := e.find? isCandidate then
if e.isIte || e.isDIte then
let cond := target.getArg! 1 5
-- Try to find a nested `if` in `cond`
go cond |>.getD target
else
some target
else
none
isCandidate (e : Expr) : Bool := Id.run do
if exceptionSet.contains e then
false
else if splitIte && (e.isIte || e.isDIte) then
!(e.getArg! 1 5).hasLooseBVars
else if let some info := isMatcherAppCore? env e then
let args := e.getAppArgs
for i in [info.getFirstDiscrPos : info.getFirstDiscrPos + info.numDiscrs] do
if args[i]!.hasLooseBVars then
return false
return true
else
false
end Split
open Split
partial def splitTarget? (mvarId : MVarId) (splitIte := true) : MetaM (Option (List MVarId)) := commitWhenSome? do
let target ← instantiateMVars (← mvarId.getType)
let rec go (badCases : ExprSet) : MetaM (Option (List MVarId)) := do
if let some e := findSplit? (← getEnv) target splitIte badCases then
if e.isIte || e.isDIte then
return (← splitIfTarget? mvarId).map fun (s₁, s₂) => [s₁.mvarId, s₂.mvarId]
else
try
splitMatch mvarId e
catch _ =>
go (badCases.insert e)
else
trace[Meta.Tactic.split] "did not find term to split\n{MessageData.ofGoal mvarId}"
return none
go {}
def splitLocalDecl? (mvarId : MVarId) (fvarId : FVarId) : MetaM (Option (List MVarId)) := commitWhenSome? do
mvarId.withContext do
if let some e := findSplit? (← getEnv) (← instantiateMVars (← inferType (mkFVar fvarId))) then
if e.isIte || e.isDIte then
return (← splitIfLocalDecl? mvarId fvarId).map fun (mvarId₁, mvarId₂) => [mvarId₁, mvarId₂]
else
let (fvarIds, mvarId) ← mvarId.revert #[fvarId]
let num := fvarIds.size
let mvarIds ← splitMatch mvarId e
let mvarIds ← mvarIds.mapM fun mvarId => return (← mvarId.introNP num).2
return some mvarIds
else
return none
builtin_initialize registerTraceClass `Meta.Tactic.split
end Lean.Meta
|
e521e87318aed8d86463a33ece16bdc900dcfda1 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/imp.lean | a3027e742dcc12101c17b9b43203117fa816cedb | [
"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 | 706 | lean | constant N : Type.{1}
constants a b c : N
constant f : forall {a b : N}, N → N
check f
check @f
check @f a
check @f a b
check @f a b c
noncomputable definition l1 : N → N → N → N := @f
noncomputable definition l2 : N → N → N := @f a
noncomputable definition l3 : N → N := @f a b
noncomputable definition l4 : N := @f a b c
constant g : forall ⦃a b : N⦄, N → N
check g
check g a
check @g
check @g a
check @g a b
check @g a b c
noncomputable definition l5 : N → N → N → N := @g
noncomputable definition l6 : N → N → N := @g a
noncomputable definition l7 : N → N := @g a b
noncomputable definition l8 : N := @g a b c
noncomputable definition l9 : N → N → N → N := g
|
ce9244504095026458c46114b5c94aaa529db472 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/finset/n_ary.lean | dd7d4df71f086abf9178edf993234587e4c3f598 | [
"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 | 21,603 | lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.finset.prod
import data.set.finite
/-!
# N-ary images of finsets
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines `finset.image₂`, the binary image of finsets. This is the finset version of
`set.image2`. This is mostly useful to define pointwise operations.
## Notes
This file is very similar to `data.set.n_ary`, `order.filter.n_ary` and `data.option.n_ary`. Please
keep them in sync.
We do not define `finset.image₃` as its only purpose would be to prove properties of `finset.image₂`
and `set.image2` already fulfills this task.
-/
open function set
variables {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*}
namespace finset
variables [decidable_eq α'] [decidable_eq β'] [decidable_eq γ] [decidable_eq γ'] [decidable_eq δ]
[decidable_eq δ'] [decidable_eq ε] [decidable_eq ε']
{f f' : α → β → γ} {g g' : α → β → γ → δ} {s s' : finset α} {t t' : finset β} {u u' : finset γ}
{a a' : α} {b b' : β} {c : γ}
/-- The image of a binary function `f : α → β → γ` as a function `finset α → finset β → finset γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def image₂ (f : α → β → γ) (s : finset α) (t : finset β) : finset γ :=
(s ×ˢ t).image $ uncurry f
@[simp] lemma mem_image₂ : c ∈ image₂ f s t ↔ ∃ a b, a ∈ s ∧ b ∈ t ∧ f a b = c :=
by simp [image₂, and_assoc]
@[simp, norm_cast] lemma coe_image₂ (f : α → β → γ) (s : finset α) (t : finset β) :
(image₂ f s t : set γ) = set.image2 f s t :=
set.ext $ λ _, mem_image₂
lemma card_image₂_le (f : α → β → γ) (s : finset α) (t : finset β) :
(image₂ f s t).card ≤ s.card * t.card :=
card_image_le.trans_eq $ card_product _ _
lemma card_image₂_iff :
(image₂ f s t).card = s.card * t.card ↔ (s ×ˢ t : set (α × β)).inj_on (λ x, f x.1 x.2) :=
by { rw [←card_product, ←coe_product], exact card_image_iff }
lemma card_image₂ (hf : injective2 f) (s : finset α) (t : finset β) :
(image₂ f s t).card = s.card * t.card :=
(card_image_of_injective _ hf.uncurry).trans $ card_product _ _
lemma mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t :=
mem_image₂.2 ⟨a, b, ha, hb, rfl⟩
lemma mem_image₂_iff (hf : injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t :=
by rw [←mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe]
lemma image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' :=
by { rw [←coe_subset, coe_image₂, coe_image₂], exact image2_subset hs ht }
lemma image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' := image₂_subset subset.rfl ht
lemma image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t :=
image₂_subset hs subset.rfl
lemma image_subset_image₂_left (hb : b ∈ t) : s.image (λ a, f a b) ⊆ image₂ f s t :=
image_subset_iff.2 $ λ a ha, mem_image₂_of_mem ha hb
lemma image_subset_image₂_right (ha : a ∈ s) : t.image (λ b, f a b) ⊆ image₂ f s t :=
image_subset_iff.2 $ λ b, mem_image₂_of_mem ha
lemma forall_image₂_iff {p : γ → Prop} : (∀ z ∈ image₂ f s t, p z) ↔ ∀ (x ∈ s) (y ∈ t), p (f x y) :=
by simp_rw [←mem_coe, coe_image₂, forall_image2_iff]
@[simp] lemma image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ (x ∈ s) (y ∈ t), f x y ∈ u :=
forall_image₂_iff
lemma image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, t.image (λ b, f a b) ⊆ u :=
by simp_rw [image₂_subset_iff, image_subset_iff]
lemma image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, s.image (λ a, f a b) ⊆ u :=
by simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α]
@[simp] lemma image₂_nonempty_iff : (image₂ f s t).nonempty ↔ s.nonempty ∧ t.nonempty :=
by { rw [←coe_nonempty, coe_image₂], exact image2_nonempty_iff }
lemma nonempty.image₂ (hs : s.nonempty) (ht : t.nonempty) : (image₂ f s t).nonempty :=
image₂_nonempty_iff.2 ⟨hs, ht⟩
lemma nonempty.of_image₂_left (h : (image₂ f s t).nonempty) : s.nonempty :=
(image₂_nonempty_iff.1 h).1
lemma nonempty.of_image₂_right (h : (image₂ f s t).nonempty) : t.nonempty :=
(image₂_nonempty_iff.1 h).2
@[simp] lemma image₂_empty_left : image₂ f ∅ t = ∅ := coe_injective $ by simp
@[simp] lemma image₂_empty_right : image₂ f s ∅ = ∅ := coe_injective $ by simp
@[simp] lemma image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ :=
by simp_rw [←not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_distrib]
@[simp] lemma image₂_singleton_left : image₂ f {a} t = t.image (λ b, f a b) := ext $ λ x, by simp
@[simp] lemma image₂_singleton_right : image₂ f s {b} = s.image (λ a, f a b) := ext $ λ x, by simp
lemma image₂_singleton_left' : image₂ f {a} t = t.image (f a) := image₂_singleton_left
lemma image₂_singleton : image₂ f {a} {b} = {f a b} := by simp
lemma image₂_union_left [decidable_eq α] : image₂ f (s ∪ s') t = image₂ f s t ∪ image₂ f s' t :=
coe_injective $ by { push_cast, exact image2_union_left }
lemma image₂_union_right [decidable_eq β] : image₂ f s (t ∪ t') = image₂ f s t ∪ image₂ f s t' :=
coe_injective $ by { push_cast, exact image2_union_right }
@[simp] lemma image₂_insert_left [decidable_eq α] :
image₂ f (insert a s) t = t.image (λ b, f a b) ∪ image₂ f s t :=
coe_injective $ by { push_cast, exact image2_insert_left }
@[simp] lemma image₂_insert_right [decidable_eq β] :
image₂ f s (insert b t) = s.image (λ a, f a b) ∪ image₂ f s t :=
coe_injective $ by { push_cast, exact image2_insert_right }
lemma image₂_inter_left [decidable_eq α] (hf : injective2 f) :
image₂ f (s ∩ s') t = image₂ f s t ∩ image₂ f s' t :=
coe_injective $ by { push_cast, exact image2_inter_left hf }
lemma image₂_inter_right [decidable_eq β] (hf : injective2 f) :
image₂ f s (t ∩ t') = image₂ f s t ∩ image₂ f s t' :=
coe_injective $ by { push_cast, exact image2_inter_right hf }
lemma image₂_inter_subset_left [decidable_eq α] :
image₂ f (s ∩ s') t ⊆ image₂ f s t ∩ image₂ f s' t :=
coe_subset.1 $ by { push_cast, exact image2_inter_subset_left }
lemma image₂_inter_subset_right [decidable_eq β] :
image₂ f s (t ∩ t') ⊆ image₂ f s t ∩ image₂ f s t' :=
coe_subset.1 $ by { push_cast, exact image2_inter_subset_right }
lemma image₂_congr (h : ∀ (a ∈ s) (b ∈ t), f a b = f' a b) : image₂ f s t = image₂ f' s t :=
coe_injective $ by { push_cast, exact image2_congr h }
/-- A common special case of `image₂_congr` -/
lemma image₂_congr' (h : ∀ a b, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
image₂_congr $ λ a _ b _, h a b
lemma subset_image₂ {s : set α} {t : set β} (hu : ↑u ⊆ image2 f s t) :
∃ (s' : finset α) (t' : finset β), ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ image₂ f s' t' :=
begin
apply finset.induction_on' u,
{ exact ⟨∅, ∅, set.empty_subset _, set.empty_subset _, empty_subset _⟩ },
rintro a u ha _ _ ⟨s', t', hs, hs', h⟩,
obtain ⟨x, y, hx, hy, ha⟩ := hu ha,
haveI := classical.dec_eq α,
haveI := classical.dec_eq β,
refine ⟨insert x s', insert y t', _⟩,
simp_rw [coe_insert, set.insert_subset],
exact ⟨⟨hx, hs⟩, ⟨hy, hs'⟩, insert_subset.2 ⟨mem_image₂.2 ⟨x, y, mem_insert_self _ _,
mem_insert_self _ _, ha⟩, h.trans $ image₂_subset (subset_insert _ _) $ subset_insert _ _⟩⟩,
end
variables (s t)
lemma card_image₂_singleton_left (hf : injective (f a)) : (image₂ f {a} t).card = t.card :=
by rw [image₂_singleton_left, card_image_of_injective _ hf]
lemma card_image₂_singleton_right (hf : injective (λ a, f a b)) : (image₂ f s {b}).card = s.card :=
by rw [image₂_singleton_right, card_image_of_injective _ hf]
lemma image₂_singleton_inter [decidable_eq β] (t₁ t₂ : finset β) (hf : injective (f a)) :
image₂ f {a} (t₁ ∩ t₂) = image₂ f {a} t₁ ∩ image₂ f {a} t₂ :=
by simp_rw [image₂_singleton_left, image_inter _ _ hf]
lemma image₂_inter_singleton [decidable_eq α] (s₁ s₂ : finset α) (hf : injective (λ a, f a b)) :
image₂ f (s₁ ∩ s₂) {b} = image₂ f s₁ {b} ∩ image₂ f s₂ {b} :=
by simp_rw [image₂_singleton_right, image_inter _ _ hf]
lemma card_le_card_image₂_left {s : finset α} (hs : s.nonempty) (hf : ∀ a, injective (f a)) :
t.card ≤ (image₂ f s t).card :=
begin
obtain ⟨a, ha⟩ := hs,
rw ←card_image₂_singleton_left _ (hf a),
exact card_le_of_subset (image₂_subset_right $ singleton_subset_iff.2 ha),
end
lemma card_le_card_image₂_right {t : finset β} (ht : t.nonempty)
(hf : ∀ b, injective (λ a, f a b)) :
s.card ≤ (image₂ f s t).card :=
begin
obtain ⟨b, hb⟩ := ht,
rw ←card_image₂_singleton_right _ (hf b),
exact card_le_of_subset (image₂_subset_left $ singleton_subset_iff.2 hb),
end
variables {s t}
lemma bUnion_image_left : s.bUnion (λ a, t.image $ f a) = image₂ f s t :=
coe_injective $ by { push_cast, exact set.Union_image_left _ }
lemma bUnion_image_right : t.bUnion (λ b, s.image $ λ a, f a b) = image₂ f s t :=
coe_injective $ by { push_cast, exact set.Union_image_right _ }
/-!
### Algebraic replacement rules
A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations
to the associativity, commutativity, distributivity, ... of `finset.image₂` of those operations.
The proof pattern is `image₂_lemma operation_lemma`. For example, `image₂_comm mul_comm` proves that
`image₂ (*) f g = image₂ (*) g f` in a `comm_semigroup`.
-/
lemma image_image₂ (f : α → β → γ) (g : γ → δ) :
(image₂ f s t).image g = image₂ (λ a b, g (f a b)) s t :=
coe_injective $ by { push_cast, exact image_image2 _ _ }
lemma image₂_image_left (f : γ → β → δ) (g : α → γ) :
image₂ f (s.image g) t = image₂ (λ a b, f (g a) b) s t :=
coe_injective $ by { push_cast, exact image2_image_left _ _ }
lemma image₂_image_right (f : α → γ → δ) (g : β → γ) :
image₂ f s (t.image g) = image₂ (λ a b, f a (g b)) s t :=
coe_injective $ by { push_cast, exact image2_image_right _ _ }
@[simp] lemma image₂_mk_eq_product [decidable_eq α] [decidable_eq β] (s : finset α) (t : finset β) :
image₂ prod.mk s t = s ×ˢ t :=
by ext; simp [prod.ext_iff]
@[simp] lemma image₂_curry (f : α × β → γ) (s : finset α) (t : finset β) :
image₂ (curry f) s t = (s ×ˢ t).image f :=
by { classical, rw [←image₂_mk_eq_product, image_image₂, curry] }
@[simp] lemma image_uncurry_product (f : α → β → γ) (s : finset α) (t : finset β) :
(s ×ˢ t).image (uncurry f) = image₂ f s t := by rw [←image₂_curry, curry_uncurry]
lemma image₂_swap (f : α → β → γ) (s : finset α) (t : finset β) :
image₂ f s t = image₂ (λ a b, f b a) t s :=
coe_injective $ by { push_cast, exact image2_swap _ _ _ }
@[simp] lemma image₂_left [decidable_eq α] (h : t.nonempty) : image₂ (λ x y, x) s t = s :=
coe_injective $ by { push_cast, exact image2_left h }
@[simp] lemma image₂_right [decidable_eq β] (h : s.nonempty) : image₂ (λ x y, y) s t = t :=
coe_injective $ by { push_cast, exact image2_right h }
lemma image₂_assoc {γ : Type*} {u : finset γ} {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε}
{g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
image₂ f (image₂ g s t) u = image₂ f' s (image₂ g' t u) :=
coe_injective $ by { push_cast, exact image2_assoc h_assoc }
lemma image₂_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image₂ f s t = image₂ g t s :=
(image₂_swap _ _ _).trans $ by simp_rw h_comm
lemma image₂_left_comm {γ : Type*} {u : finset γ} {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'}
{g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
image₂ f s (image₂ g t u) = image₂ g' t (image₂ f' s u) :=
coe_injective $ by { push_cast, exact image2_left_comm h_left_comm }
lemma image₂_right_comm {γ : Type*} {u : finset γ} {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'}
{g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
image₂ f (image₂ g s t) u = image₂ g' (image₂ f' s u) t :=
coe_injective $ by { push_cast, exact image2_right_comm h_right_comm }
lemma image₂_image₂_image₂_comm {γ δ : Type*} {u : finset γ} {v : finset δ} [decidable_eq ζ]
[decidable_eq ζ'] [decidable_eq ν] {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ}
{f' : ε' → ζ' → ν} {g' : α → γ → ε'} {h' : β → δ → ζ'}
(h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) :
image₂ f (image₂ g s t) (image₂ h u v) = image₂ f' (image₂ g' s u) (image₂ h' t v) :=
coe_injective $ by { push_cast, exact image2_image2_image2_comm h_comm }
lemma image_image₂_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
(image₂ f s t).image g = image₂ f' (s.image g₁) (t.image g₂) :=
coe_injective $ by { push_cast, exact image_image2_distrib h_distrib }
/-- Symmetric statement to `finset.image₂_image_left_comm`. -/
lemma image_image₂_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
(image₂ f s t).image g = image₂ f' (s.image g') t :=
coe_injective $ by { push_cast, exact image_image2_distrib_left h_distrib }
/-- Symmetric statement to `finset.image_image₂_right_comm`. -/
lemma image_image₂_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' a (g' b)) :
(image₂ f s t).image g = image₂ f' s (t.image g') :=
coe_injective $ by { push_cast, exact image_image2_distrib_right h_distrib }
/-- Symmetric statement to `finset.image_image₂_distrib_left`. -/
lemma image₂_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ}
(h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) :
image₂ f (s.image g) t = (image₂ f' s t).image g' :=
(image_image₂_distrib_left $ λ a b, (h_left_comm a b).symm).symm
/-- Symmetric statement to `finset.image_image₂_distrib_right`. -/
lemma image_image₂_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ}
(h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) :
image₂ f s (t.image g) = (image₂ f' s t).image g' :=
(image_image₂_distrib_right $ λ a b, (h_right_comm a b).symm).symm
/-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/
lemma image₂_distrib_subset_left {γ : Type*} {u : finset γ} {f : α → δ → ε} {g : β → γ → δ}
{f₁ : α → β → β'} {f₂ : α → γ → γ'} {g' : β' → γ' → ε}
(h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) :
image₂ f s (image₂ g t u) ⊆ image₂ g' (image₂ f₁ s t) (image₂ f₂ s u) :=
coe_subset.1 $ by { push_cast, exact set.image2_distrib_subset_left h_distrib }
/-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
lemma image₂_distrib_subset_right {γ : Type*} {u : finset γ} {f : δ → γ → ε} {g : α → β → δ}
{f₁ : α → γ → α'} {f₂ : β → γ → β'} {g' : α' → β' → ε}
(h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) :
image₂ f (image₂ g s t) u ⊆ image₂ g' (image₂ f₁ s u) (image₂ f₂ t u) :=
coe_subset.1 $ by { push_cast, exact set.image2_distrib_subset_right h_distrib }
lemma image_image₂_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) :
(image₂ f s t).image g = image₂ f' (t.image g₁) (s.image g₂) :=
by { rw image₂_swap f, exact image_image₂_distrib (λ _ _, h_antidistrib _ _) }
/-- Symmetric statement to `finset.image₂_image_left_anticomm`. -/
lemma image_image₂_antidistrib_left {g : γ → δ} {f' : β' → α → δ} {g' : β → β'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g' b) a) :
(image₂ f s t).image g = image₂ f' (t.image g') s :=
coe_injective $ by { push_cast, exact image_image2_antidistrib_left h_antidistrib }
/-- Symmetric statement to `finset.image_image₂_right_anticomm`. -/
lemma image_image₂_antidistrib_right {g : γ → δ} {f' : β → α' → δ} {g' : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' b (g' a)) :
(image₂ f s t).image g = image₂ f' t (s.image g') :=
coe_injective $ by { push_cast, exact image_image2_antidistrib_right h_antidistrib }
/-- Symmetric statement to `finset.image_image₂_antidistrib_left`. -/
lemma image₂_image_left_anticomm {f : α' → β → γ} {g : α → α'} {f' : β → α → δ} {g' : δ → γ}
(h_left_anticomm : ∀ a b, f (g a) b = g' (f' b a)) :
image₂ f (s.image g) t = (image₂ f' t s).image g' :=
(image_image₂_antidistrib_left $ λ a b, (h_left_anticomm b a).symm).symm
/-- Symmetric statement to `finset.image_image₂_antidistrib_right`. -/
lemma image_image₂_right_anticomm {f : α → β' → γ} {g : β → β'} {f' : β → α → δ} {g' : δ → γ}
(h_right_anticomm : ∀ a b, f a (g b) = g' (f' b a)) :
image₂ f s (t.image g) = (image₂ f' t s).image g' :=
(image_image₂_antidistrib_right $ λ a b, (h_right_anticomm b a).symm).symm
/-- If `a` is a left identity for `f : α → β → β`, then `{a}` is a left identity for
`finset.image₂ f`. -/
lemma image₂_left_identity {f : α → γ → γ} {a : α} (h : ∀ b, f a b = b) (t : finset γ) :
image₂ f {a} t = t :=
coe_injective $ by rw [coe_image₂, coe_singleton, set.image2_left_identity h]
/-- If `b` is a right identity for `f : α → β → α`, then `{b}` is a right identity for
`finset.image₂ f`. -/
lemma image₂_right_identity {f : γ → β → γ} {b : β} (h : ∀ a, f a b = a) (s : finset γ) :
image₂ f s {b} = s :=
by rw [image₂_singleton_right, funext h, image_id']
/-- If each partial application of `f` is injective, and images of `s` under those partial
applications are disjoint (but not necessarily distinct!), then the size of `t` divides the size of
`finset.image₂ f s t`. -/
lemma card_dvd_card_image₂_right (hf : ∀ a ∈ s, injective (f a))
(hs : ((λ a, t.image $ f a) '' s).pairwise_disjoint id) :
t.card ∣ (image₂ f s t).card :=
begin
classical,
induction s using finset.induction with a s ha ih,
{ simp },
specialize ih (forall_of_forall_insert hf)
(hs.subset $ set.image_subset _ $ coe_subset.2 $ subset_insert _ _),
rw image₂_insert_left,
by_cases h : disjoint (image (f a) t) (image₂ f s t),
{ rw card_union_eq h,
exact (card_image_of_injective _ $ hf _ $ mem_insert_self _ _).symm.dvd.add ih },
simp_rw [←bUnion_image_left, disjoint_bUnion_right, not_forall] at h,
obtain ⟨b, hb, h⟩ := h,
rwa union_eq_right_iff_subset.2,
exact (hs.eq (set.mem_image_of_mem _ $ mem_insert_self _ _)
(set.mem_image_of_mem _ $ mem_insert_of_mem hb) h).trans_subset (image_subset_image₂_right hb),
end
/-- If each partial application of `f` is injective, and images of `t` under those partial
applications are disjoint (but not necessarily distinct!), then the size of `s` divides the size of
`finset.image₂ f s t`. -/
lemma card_dvd_card_image₂_left (hf : ∀ b ∈ t, injective (λ a, f a b))
(ht : ((λ b, s.image $ λ a, f a b) '' t).pairwise_disjoint id) :
s.card ∣ (image₂ f s t).card :=
by { rw ←image₂_swap, exact card_dvd_card_image₂_right hf ht }
variables [decidable_eq α] [decidable_eq β]
lemma image₂_inter_union_subset_union :
image₂ f (s ∩ s') (t ∪ t') ⊆ image₂ f s t ∪ image₂ f s' t' :=
coe_subset.1 $ by { push_cast, exact set.image2_inter_union_subset_union }
lemma image₂_union_inter_subset_union :
image₂ f (s ∪ s') (t ∩ t') ⊆ image₂ f s t ∪ image₂ f s' t' :=
coe_subset.1 $ by { push_cast, exact set.image2_union_inter_subset_union }
lemma image₂_inter_union_subset {f : α → α → β} {s t : finset α} (hf : ∀ a b, f a b = f b a) :
image₂ f (s ∩ t) (s ∪ t) ⊆ image₂ f s t :=
coe_subset.1 $ by { push_cast, exact image2_inter_union_subset hf }
lemma image₂_union_inter_subset {f : α → α → β} {s t : finset α} (hf : ∀ a b, f a b = f b a) :
image₂ f (s ∪ t) (s ∩ t) ⊆ image₂ f s t :=
coe_subset.1 $ by { push_cast, exact image2_union_inter_subset hf }
end finset
namespace set
variables [decidable_eq γ] {s : set α} {t : set β}
@[simp] lemma to_finset_image2 (f : α → β → γ) (s : set α) (t : set β) [fintype s] [fintype t]
[fintype (image2 f s t)] :
(image2 f s t).to_finset = finset.image₂ f s.to_finset t.to_finset :=
finset.coe_injective $ by simp
lemma finite.to_finset_image2 (f : α → β → γ) (hs : s.finite) (ht : t.finite)
(hf := hs.image2 f ht) :
hf.to_finset = finset.image₂ f hs.to_finset ht.to_finset :=
finset.coe_injective $ by simp
end set
|
2a12989ee6249c7a5a7c8fa690a79e31b68be708 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/measure_theory/function/simple_func_dense.lean | a775ca11488396a199dd6b1efa1abfbf0a7075e7 | [
"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 | 41,378 | 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, Heather Macbeth
-/
import measure_theory.function.l1_space
/-!
# Density of simple functions
Show that each Borel measurable function can be approximated pointwise, and each `Lᵖ` Borel
measurable function can be approximated in `Lᵖ` norm, by a sequence of simple functions.
## Main definitions
* `measure_theory.simple_func.nearest_pt (e : ℕ → α) (N : ℕ) : α →ₛ ℕ`: the `simple_func` sending
each `x : α` to the point `e k` which is the nearest to `x` among `e 0`, ..., `e N`.
* `measure_theory.simple_func.approx_on (f : β → α) (hf : measurable f) (s : set α) (y₀ : α)
(h₀ : y₀ ∈ s) [separable_space s] (n : ℕ) : β →ₛ α` : a simple function that takes values in `s`
and approximates `f`.
* `measure_theory.Lp.simple_func`, the type of `Lp` simple functions
* `coe_to_Lp`, the embedding of `Lp.simple_func E p μ` into `Lp E p μ`
## Main results
* `tendsto_approx_on` (pointwise convergence): If `f x ∈ s`, then the sequence of simple
approximations `measure_theory.simple_func.approx_on f hf s y₀ h₀ n`, evaluated at `x`,
tends to `f x` as `n` tends to `∞`.
* `tendsto_approx_on_univ_Lp` (Lᵖ convergence): If `E` is a `normed_group` and `f` is measurable
and `mem_ℒp` (for `p < ∞`), then the simple functions `simple_func.approx_on f hf s 0 h₀ n` may
be considered as elements of `Lp E p μ`, and they tend in Lᵖ to `f`.
* `Lp.simple_func.dense_embedding`: the embedding `coe_to_Lp` of the `Lp` simple functions into
`Lp` is dense.
* `Lp.simple_func.induction`, `Lp.induction`, `mem_ℒp.induction`, `integrable.induction`: to prove
a predicate for all elements of one of these classes of functions, it suffices to check that it
behaves correctly on simple functions.
## TODO
For `E` finite-dimensional, simple functions `α →ₛ E` are dense in L^∞ -- prove this.
## Notations
* `α →ₛ β` (local notation): the type of simple functions `α → β`.
* `α →₁ₛ[μ] E`: the type of `L1` simple functions `α → β`.
-/
open set function filter topological_space ennreal emetric finset
open_locale classical topological_space ennreal measure_theory big_operators
variables {α β ι E F 𝕜 : Type*}
noncomputable theory
namespace measure_theory
local infixr ` →ₛ `:25 := simple_func
namespace simple_func
/-! ### Pointwise approximation by simple functions -/
section pointwise
variables [measurable_space α] [emetric_space α] [opens_measurable_space α]
/-- `nearest_pt_ind e N x` is the index `k` such that `e k` is the nearest point to `x` among the
points `e 0`, ..., `e N`. If more than one point are at the same distance from `x`, then
`nearest_pt_ind e N x` returns the least of their indexes. -/
noncomputable def nearest_pt_ind (e : ℕ → α) : ℕ → α →ₛ ℕ
| 0 := const α 0
| (N + 1) := piecewise (⋂ k ≤ N, {x | edist (e (N + 1)) x < edist (e k) x})
(measurable_set.Inter $ λ k, measurable_set.Inter_Prop $ λ hk,
measurable_set_lt measurable_edist_right measurable_edist_right)
(const α $ N + 1) (nearest_pt_ind N)
/-- `nearest_pt e N x` is the nearest point to `x` among the points `e 0`, ..., `e N`. If more than
one point are at the same distance from `x`, then `nearest_pt e N x` returns the point with the
least possible index. -/
noncomputable def nearest_pt (e : ℕ → α) (N : ℕ) : α →ₛ α :=
(nearest_pt_ind e N).map e
@[simp] lemma nearest_pt_ind_zero (e : ℕ → α) : nearest_pt_ind e 0 = const α 0 := rfl
@[simp] lemma nearest_pt_zero (e : ℕ → α) : nearest_pt e 0 = const α (e 0) := rfl
lemma nearest_pt_ind_succ (e : ℕ → α) (N : ℕ) (x : α) :
nearest_pt_ind e (N + 1) x =
if ∀ k ≤ N, edist (e (N + 1)) x < edist (e k) x
then N + 1 else nearest_pt_ind e N x :=
by { simp only [nearest_pt_ind, coe_piecewise, set.piecewise], congr, simp }
lemma nearest_pt_ind_le (e : ℕ → α) (N : ℕ) (x : α) : nearest_pt_ind e N x ≤ N :=
begin
induction N with N ihN, { simp },
simp only [nearest_pt_ind_succ],
split_ifs,
exacts [le_rfl, ihN.trans N.le_succ]
end
lemma edist_nearest_pt_le (e : ℕ → α) (x : α) {k N : ℕ} (hk : k ≤ N) :
edist (nearest_pt e N x) x ≤ edist (e k) x :=
begin
induction N with N ihN generalizing k,
{ simp [nonpos_iff_eq_zero.1 hk, le_refl] },
{ simp only [nearest_pt, nearest_pt_ind_succ, map_apply],
split_ifs,
{ rcases hk.eq_or_lt with rfl|hk,
exacts [le_rfl, (h k (nat.lt_succ_iff.1 hk)).le] },
{ push_neg at h,
rcases h with ⟨l, hlN, hxl⟩,
rcases hk.eq_or_lt with rfl|hk,
exacts [(ihN hlN).trans hxl, ihN (nat.lt_succ_iff.1 hk)] } }
end
lemma tendsto_nearest_pt {e : ℕ → α} {x : α} (hx : x ∈ closure (range e)) :
tendsto (λ N, nearest_pt e N x) at_top (𝓝 x) :=
begin
refine (at_top_basis.tendsto_iff nhds_basis_eball).2 (λ ε hε, _),
rcases emetric.mem_closure_iff.1 hx ε hε with ⟨_, ⟨N, rfl⟩, hN⟩,
rw [edist_comm] at hN,
exact ⟨N, trivial, λ n hn, (edist_nearest_pt_le e x hn).trans_lt hN⟩
end
variables [measurable_space β] {f : β → α}
/-- Approximate a measurable function by a sequence of simple functions `F n` such that
`F n x ∈ s`. -/
noncomputable def approx_on (f : β → α) (hf : measurable f) (s : set α) (y₀ : α) (h₀ : y₀ ∈ s)
[separable_space s] (n : ℕ) :
β →ₛ α :=
by haveI : nonempty s := ⟨⟨y₀, h₀⟩⟩;
exact comp (nearest_pt (λ k, nat.cases_on k y₀ (coe ∘ dense_seq s) : ℕ → α) n) f hf
@[simp] lemma approx_on_zero {f : β → α} (hf : measurable f) {s : set α} {y₀ : α} (h₀ : y₀ ∈ s)
[separable_space s] (x : β) :
approx_on f hf s y₀ h₀ 0 x = y₀ :=
rfl
lemma approx_on_mem {f : β → α} (hf : measurable f) {s : set α} {y₀ : α} (h₀ : y₀ ∈ s)
[separable_space s] (n : ℕ) (x : β) :
approx_on f hf s y₀ h₀ n x ∈ s :=
begin
haveI : nonempty s := ⟨⟨y₀, h₀⟩⟩,
suffices : ∀ n, (nat.cases_on n y₀ (coe ∘ dense_seq s) : α) ∈ s, { apply this },
rintro (_|n),
exacts [h₀, subtype.mem _]
end
@[simp] lemma approx_on_comp {γ : Type*} [measurable_space γ] {f : β → α} (hf : measurable f)
{g : γ → β} (hg : measurable g) {s : set α} {y₀ : α} (h₀ : y₀ ∈ s) [separable_space s] (n : ℕ) :
approx_on (f ∘ g) (hf.comp hg) s y₀ h₀ n = (approx_on f hf s y₀ h₀ n).comp g hg :=
rfl
lemma tendsto_approx_on {f : β → α} (hf : measurable f) {s : set α} {y₀ : α} (h₀ : y₀ ∈ s)
[separable_space s] {x : β} (hx : f x ∈ closure s) :
tendsto (λ n, approx_on f hf s y₀ h₀ n x) at_top (𝓝 $ f x) :=
begin
haveI : nonempty s := ⟨⟨y₀, h₀⟩⟩,
rw [← @subtype.range_coe _ s, ← image_univ, ← (dense_range_dense_seq s).closure_eq] at hx,
simp only [approx_on, coe_comp],
refine tendsto_nearest_pt (closure_minimal _ is_closed_closure hx),
simp only [nat.range_cases_on, closure_union, range_comp coe],
exact subset.trans (image_closure_subset_closure_image continuous_subtype_coe)
(subset_union_right _ _)
end
lemma edist_approx_on_le {f : β → α} (hf : measurable f) {s : set α} {y₀ : α} (h₀ : y₀ ∈ s)
[separable_space s] (x : β) (n : ℕ) :
edist (approx_on f hf s y₀ h₀ n x) (f x) ≤ edist y₀ (f x) :=
begin
dsimp only [approx_on, coe_comp, (∘)],
exact edist_nearest_pt_le _ _ (zero_le _)
end
lemma edist_approx_on_y0_le {f : β → α} (hf : measurable f) {s : set α} {y₀ : α} (h₀ : y₀ ∈ s)
[separable_space s] (x : β) (n : ℕ) :
edist y₀ (approx_on f hf s y₀ h₀ n x) ≤ edist y₀ (f x) + edist y₀ (f x) :=
calc edist y₀ (approx_on f hf s y₀ h₀ n x) ≤
edist y₀ (f x) + edist (approx_on f hf s y₀ h₀ n x) (f x) : edist_triangle_right _ _ _
... ≤ edist y₀ (f x) + edist y₀ (f x) : add_le_add_left (edist_approx_on_le hf h₀ x n) _
end pointwise
/-! ### Lp approximation by simple functions -/
section Lp
variables [measurable_space β]
variables [measurable_space E] [normed_group E] {q : ℝ} {p : ℝ≥0∞}
lemma nnnorm_approx_on_le [opens_measurable_space E] {f : β → E} (hf : measurable f)
{s : set E} {y₀ : E} (h₀ : y₀ ∈ s) [separable_space s] (x : β) (n : ℕ) :
∥approx_on f hf s y₀ h₀ n x - f x∥₊ ≤ ∥f x - y₀∥₊ :=
begin
have := edist_approx_on_le hf h₀ x n,
rw edist_comm y₀ at this,
simp only [edist_nndist, nndist_eq_nnnorm] at this,
exact_mod_cast this
end
lemma norm_approx_on_y₀_le [opens_measurable_space E] {f : β → E} (hf : measurable f)
{s : set E} {y₀ : E} (h₀ : y₀ ∈ s) [separable_space s] (x : β) (n : ℕ) :
∥approx_on f hf s y₀ h₀ n x - y₀∥ ≤ ∥f x - y₀∥ + ∥f x - y₀∥ :=
begin
have := edist_approx_on_y0_le hf h₀ x n,
repeat { rw [edist_comm y₀, edist_eq_coe_nnnorm_sub] at this },
exact_mod_cast this,
end
lemma norm_approx_on_zero_le [opens_measurable_space E] {f : β → E} (hf : measurable f)
{s : set E} (h₀ : (0 : E) ∈ s) [separable_space s] (x : β) (n : ℕ) :
∥approx_on f hf s 0 h₀ n x∥ ≤ ∥f x∥ + ∥f x∥ :=
begin
have := edist_approx_on_y0_le hf h₀ x n,
simp [edist_comm (0 : E), edist_eq_coe_nnnorm] at this,
exact_mod_cast this,
end
lemma tendsto_approx_on_Lp_snorm [opens_measurable_space E]
{f : β → E} (hf : measurable f) {s : set E} {y₀ : E} (h₀ : y₀ ∈ s) [separable_space s]
(hp_ne_top : p ≠ ∞) {μ : measure β} (hμ : ∀ᵐ x ∂μ, f x ∈ closure s)
(hi : snorm (λ x, f x - y₀) p μ < ∞) :
tendsto (λ n, snorm (approx_on f hf s y₀ h₀ n - f) p μ) at_top (𝓝 0) :=
begin
by_cases hp_zero : p = 0,
{ simpa only [hp_zero, snorm_exponent_zero] using tendsto_const_nhds },
have hp : 0 < p.to_real := to_real_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr hp_zero, hp_ne_top⟩,
suffices : tendsto (λ n, ∫⁻ x, ∥approx_on f hf s y₀ h₀ n x - f x∥₊ ^ p.to_real ∂μ) at_top (𝓝 0),
{ simp only [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_ne_top],
convert continuous_rpow_const.continuous_at.tendsto.comp this;
simp [_root_.inv_pos.mpr hp] },
-- We simply check the conditions of the Dominated Convergence Theorem:
-- (1) The function "`p`-th power of distance between `f` and the approximation" is measurable
have hF_meas : ∀ n, measurable (λ x, (∥approx_on f hf s y₀ h₀ n x - f x∥₊ : ℝ≥0∞) ^ p.to_real),
{ simpa only [← edist_eq_coe_nnnorm_sub] using
λ n, (approx_on f hf s y₀ h₀ n).measurable_bind (λ y x, (edist y (f x)) ^ p.to_real)
(λ y, (measurable_edist_right.comp hf).pow_const p.to_real) },
-- (2) The functions "`p`-th power of distance between `f` and the approximation" are uniformly
-- bounded, at any given point, by `λ x, ∥f x - y₀∥ ^ p.to_real`
have h_bound : ∀ n, (λ x, (∥approx_on f hf s y₀ h₀ n x - f x∥₊ : ℝ≥0∞) ^ p.to_real)
≤ᵐ[μ] (λ x, ∥f x - y₀∥₊ ^ p.to_real),
{ exact λ n, eventually_of_forall
(λ x, rpow_le_rpow (coe_mono (nnnorm_approx_on_le hf h₀ x n)) to_real_nonneg) },
-- (3) The bounding function `λ x, ∥f x - y₀∥ ^ p.to_real` has finite integral
have h_fin : ∫⁻ (a : β), ∥f a - y₀∥₊ ^ p.to_real ∂μ < ⊤,
{ exact lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_zero hp_ne_top hi },
-- (4) The functions "`p`-th power of distance between `f` and the approximation" tend pointwise
-- to zero
have h_lim : ∀ᵐ (a : β) ∂μ,
tendsto (λ n, (∥approx_on f hf s y₀ h₀ n a - f a∥₊ : ℝ≥0∞) ^ p.to_real) at_top (𝓝 0),
{ filter_upwards [hμ],
intros a ha,
have : tendsto (λ n, (approx_on f hf s y₀ h₀ n) a - f a) at_top (𝓝 (f a - f a)),
{ exact (tendsto_approx_on hf h₀ ha).sub tendsto_const_nhds },
convert continuous_rpow_const.continuous_at.tendsto.comp (tendsto_coe.mpr this.nnnorm),
simp [zero_rpow_of_pos hp] },
-- Then we apply the Dominated Convergence Theorem
simpa using tendsto_lintegral_of_dominated_convergence _ hF_meas h_bound h_fin h_lim,
end
lemma mem_ℒp_approx_on [borel_space E]
{f : β → E} {μ : measure β} (fmeas : measurable f) (hf : mem_ℒp f p μ) {s : set E} {y₀ : E}
(h₀ : y₀ ∈ s) [separable_space s] (hi₀ : mem_ℒp (λ x, y₀) p μ) (n : ℕ) :
mem_ℒp (approx_on f fmeas s y₀ h₀ n) p μ :=
begin
refine ⟨(approx_on f fmeas s y₀ h₀ n).ae_measurable, _⟩,
suffices : snorm (λ x, approx_on f fmeas s y₀ h₀ n x - y₀) p μ < ⊤,
{ have : mem_ℒp (λ x, approx_on f fmeas s y₀ h₀ n x - y₀) p μ :=
⟨(approx_on f fmeas s y₀ h₀ n - const β y₀).ae_measurable, this⟩,
convert snorm_add_lt_top this hi₀,
ext x,
simp },
-- We don't necessarily have `mem_ℒp (λ x, f x - y₀) p μ`, because the `ae_measurable` part
-- requires `ae_measurable.add`, which requires second-countability
have hf' : mem_ℒp (λ x, ∥f x - y₀∥) p μ,
{ have h_meas : measurable (λ x, ∥f x - y₀∥),
{ simp only [← dist_eq_norm],
exact (continuous_id.dist continuous_const).measurable.comp fmeas },
refine ⟨h_meas.ae_measurable, _⟩,
rw snorm_norm,
convert snorm_add_lt_top hf hi₀.neg,
ext x,
simp [sub_eq_add_neg] },
have : ∀ᵐ x ∂μ, ∥approx_on f fmeas s y₀ h₀ n x - y₀∥ ≤ ∥(∥f x - y₀∥ + ∥f x - y₀∥)∥,
{ refine eventually_of_forall _,
intros x,
convert norm_approx_on_y₀_le fmeas h₀ x n,
rw [real.norm_eq_abs, abs_of_nonneg],
exact add_nonneg (norm_nonneg _) (norm_nonneg _) },
calc snorm (λ x, approx_on f fmeas s y₀ h₀ n x - y₀) p μ
≤ snorm (λ x, ∥f x - y₀∥ + ∥f x - y₀∥) p μ : snorm_mono_ae this
... < ⊤ : snorm_add_lt_top hf' hf',
end
lemma tendsto_approx_on_univ_Lp_snorm [opens_measurable_space E] [second_countable_topology E]
{f : β → E} (hp_ne_top : p ≠ ∞) {μ : measure β} (fmeas : measurable f) (hf : snorm f p μ < ∞) :
tendsto (λ n, snorm (approx_on f fmeas univ 0 trivial n - f) p μ) at_top (𝓝 0) :=
tendsto_approx_on_Lp_snorm fmeas trivial hp_ne_top (by simp) (by simpa using hf)
lemma mem_ℒp_approx_on_univ [borel_space E] [second_countable_topology E]
{f : β → E} {μ : measure β} (fmeas : measurable f) (hf : mem_ℒp f p μ) (n : ℕ) :
mem_ℒp (approx_on f fmeas univ 0 trivial n) p μ :=
mem_ℒp_approx_on fmeas hf (mem_univ _) zero_mem_ℒp n
lemma tendsto_approx_on_univ_Lp [borel_space E] [second_countable_topology E]
{f : β → E} [hp : fact (1 ≤ p)] (hp_ne_top : p ≠ ∞) {μ : measure β} (fmeas : measurable f)
(hf : mem_ℒp f p μ) :
tendsto (λ n, (mem_ℒp_approx_on_univ fmeas hf n).to_Lp (approx_on f fmeas univ 0 trivial n))
at_top (𝓝 (hf.to_Lp f)) :=
by simp [Lp.tendsto_Lp_iff_tendsto_ℒp'', tendsto_approx_on_univ_Lp_snorm hp_ne_top fmeas hf.2]
end Lp
/-! ### L1 approximation by simple functions -/
section integrable
variables [measurable_space β]
variables [measurable_space E] [normed_group E]
lemma tendsto_approx_on_L1_nnnorm [opens_measurable_space E]
{f : β → E} (hf : measurable f) {s : set E} {y₀ : E} (h₀ : y₀ ∈ s) [separable_space s]
{μ : measure β} (hμ : ∀ᵐ x ∂μ, f x ∈ closure s) (hi : has_finite_integral (λ x, f x - y₀) μ) :
tendsto (λ n, ∫⁻ x, ∥approx_on f hf s y₀ h₀ n x - f x∥₊ ∂μ) at_top (𝓝 0) :=
by simpa [snorm_one_eq_lintegral_nnnorm] using tendsto_approx_on_Lp_snorm hf h₀ one_ne_top hμ
(by simpa [snorm_one_eq_lintegral_nnnorm] using hi)
lemma integrable_approx_on [borel_space E]
{f : β → E} {μ : measure β} (fmeas : measurable f) (hf : integrable f μ)
{s : set E} {y₀ : E} (h₀ : y₀ ∈ s)
[separable_space s] (hi₀ : integrable (λ x, y₀) μ) (n : ℕ) :
integrable (approx_on f fmeas s y₀ h₀ n) μ :=
begin
rw ← mem_ℒp_one_iff_integrable at hf hi₀ ⊢,
exact mem_ℒp_approx_on fmeas hf h₀ hi₀ n,
end
lemma tendsto_approx_on_univ_L1_nnnorm [opens_measurable_space E] [second_countable_topology E]
{f : β → E} {μ : measure β} (fmeas : measurable f) (hf : integrable f μ) :
tendsto (λ n, ∫⁻ x, ∥approx_on f fmeas univ 0 trivial n x - f x∥₊ ∂μ) at_top (𝓝 0) :=
tendsto_approx_on_L1_nnnorm fmeas trivial (by simp) (by simpa using hf.2)
lemma integrable_approx_on_univ [borel_space E] [second_countable_topology E]
{f : β → E} {μ : measure β} (fmeas : measurable f) (hf : integrable f μ) (n : ℕ) :
integrable (approx_on f fmeas univ 0 trivial n) μ :=
integrable_approx_on fmeas hf _ (integrable_zero _ _ _) n
end integrable
section simple_func_properties
variables [measurable_space α]
variables [normed_group E] [measurable_space E] [normed_group F]
variables {μ : measure α} {p : ℝ≥0∞}
/-!
### Properties of simple functions in `Lp` spaces
A simple function `f : α →ₛ E` into a normed group `E` verifies, for a measure `μ`:
- `mem_ℒp f 0 μ` and `mem_ℒp f ∞ μ`, since `f` is a.e.-measurable and bounded,
- for `0 < p < ∞`,
`mem_ℒp f p μ ↔ integrable f μ ↔ f.fin_meas_supp μ ↔ ∀ y ≠ 0, μ (f ⁻¹' {y}) < ∞`.
-/
lemma exists_forall_norm_le (f : α →ₛ F) : ∃ C, ∀ x, ∥f x∥ ≤ C :=
exists_forall_le (f.map (λ x, ∥x∥))
lemma mem_ℒp_zero (f : α →ₛ E) (μ : measure α) : mem_ℒp f 0 μ :=
mem_ℒp_zero_iff_ae_measurable.mpr f.ae_measurable
lemma mem_ℒp_top (f : α →ₛ E) (μ : measure α) : mem_ℒp f ∞ μ :=
let ⟨C, hfC⟩ := f.exists_forall_norm_le in
mem_ℒp_top_of_bound f.ae_measurable C $ eventually_of_forall hfC
protected lemma snorm'_eq {p : ℝ} (f : α →ₛ F) (μ : measure α) :
snorm' f p μ = (∑ y in f.range, (nnnorm y : ℝ≥0∞) ^ p * μ (f ⁻¹' {y})) ^ (1/p) :=
have h_map : (λ a, (nnnorm (f a) : ℝ≥0∞) ^ p) = f.map (λ a : F, (nnnorm a : ℝ≥0∞) ^ p), by simp,
by rw [snorm', h_map, lintegral_eq_lintegral, map_lintegral]
lemma measure_preimage_lt_top_of_mem_ℒp (hp_pos : 0 < p) (hp_ne_top : p ≠ ∞) (f : α →ₛ E)
(hf : mem_ℒp f p μ) (y : E) (hy_ne : y ≠ 0) :
μ (f ⁻¹' {y}) < ∞ :=
begin
have hp_pos_real : 0 < p.to_real, from ennreal.to_real_pos_iff.mpr ⟨hp_pos, hp_ne_top⟩,
have hf_snorm := mem_ℒp.snorm_lt_top hf,
rw [snorm_eq_snorm' hp_pos.ne.symm hp_ne_top, f.snorm'_eq,
← @ennreal.lt_rpow_one_div_iff _ _ (1 / p.to_real) (by simp [hp_pos_real]),
@ennreal.top_rpow_of_pos (1 / (1 / p.to_real)) (by simp [hp_pos_real]),
ennreal.sum_lt_top_iff] at hf_snorm,
by_cases hyf : y ∈ f.range,
swap,
{ suffices h_empty : f ⁻¹' {y} = ∅,
by { rw [h_empty, measure_empty], exact ennreal.coe_lt_top, },
ext1 x,
rw [set.mem_preimage, set.mem_singleton_iff, mem_empty_eq, iff_false],
refine λ hxy, hyf _,
rw [mem_range, set.mem_range],
exact ⟨x, hxy⟩, },
specialize hf_snorm y hyf,
rw ennreal.mul_lt_top_iff at hf_snorm,
cases hf_snorm,
{ exact hf_snorm.2, },
cases hf_snorm,
{ refine absurd _ hy_ne,
simpa [hp_pos_real] using hf_snorm, },
{ simp [hf_snorm], },
end
lemma mem_ℒp_of_finite_measure_preimage (p : ℝ≥0∞) {f : α →ₛ E} (hf : ∀ y ≠ 0, μ (f ⁻¹' {y}) < ∞) :
mem_ℒp f p μ :=
begin
by_cases hp0 : p = 0,
{ rw [hp0, mem_ℒp_zero_iff_ae_measurable], exact f.ae_measurable, },
by_cases hp_top : p = ∞,
{ rw hp_top, exact mem_ℒp_top f μ, },
refine ⟨f.ae_measurable, _⟩,
rw [snorm_eq_snorm' hp0 hp_top, f.snorm'_eq],
refine ennreal.rpow_lt_top_of_nonneg (by simp) (ennreal.sum_lt_top_iff.mpr (λ y hy, _)).ne,
by_cases hy0 : y = 0,
{ simp [hy0, ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) (ne.symm hp0), hp_top⟩], },
{ refine ennreal.mul_lt_top _ (hf y hy0),
exact ennreal.rpow_lt_top_of_nonneg ennreal.to_real_nonneg ennreal.coe_ne_top, },
end
lemma mem_ℒp_iff {f : α →ₛ E} (hp_pos : 0 < p) (hp_ne_top : p ≠ ∞) :
mem_ℒp f p μ ↔ ∀ y ≠ 0, μ (f ⁻¹' {y}) < ∞ :=
⟨λ h, measure_preimage_lt_top_of_mem_ℒp hp_pos hp_ne_top f h,
λ h, mem_ℒp_of_finite_measure_preimage p h⟩
lemma integrable_iff {f : α →ₛ E} : integrable f μ ↔ ∀ y ≠ 0, μ (f ⁻¹' {y}) < ∞ :=
mem_ℒp_one_iff_integrable.symm.trans $ mem_ℒp_iff ennreal.zero_lt_one ennreal.coe_ne_top
lemma mem_ℒp_iff_integrable {f : α →ₛ E} (hp_pos : 0 < p) (hp_ne_top : p ≠ ∞) :
mem_ℒp f p μ ↔ integrable f μ :=
(mem_ℒp_iff hp_pos hp_ne_top).trans integrable_iff.symm
lemma mem_ℒp_iff_fin_meas_supp {f : α →ₛ E} (hp_pos : 0 < p) (hp_ne_top : p ≠ ∞) :
mem_ℒp f p μ ↔ f.fin_meas_supp μ :=
(mem_ℒp_iff hp_pos hp_ne_top).trans fin_meas_supp_iff.symm
lemma integrable_iff_fin_meas_supp {f : α →ₛ E} : integrable f μ ↔ f.fin_meas_supp μ :=
integrable_iff.trans fin_meas_supp_iff.symm
lemma fin_meas_supp.integrable {f : α →ₛ E} (h : f.fin_meas_supp μ) : integrable f μ :=
integrable_iff_fin_meas_supp.2 h
lemma integrable_pair [measurable_space F] {f : α →ₛ E} {g : α →ₛ F} :
integrable f μ → integrable g μ → integrable (pair f g) μ :=
by simpa only [integrable_iff_fin_meas_supp] using fin_meas_supp.pair
lemma mem_ℒp_of_is_finite_measure (f : α →ₛ E) (p : ℝ≥0∞) (μ : measure α) [is_finite_measure μ] :
mem_ℒp f p μ :=
let ⟨C, hfC⟩ := f.exists_forall_norm_le in
mem_ℒp.of_bound f.ae_measurable C $ eventually_of_forall hfC
lemma integrable_of_is_finite_measure [is_finite_measure μ] (f : α →ₛ E) : integrable f μ :=
mem_ℒp_one_iff_integrable.mp (f.mem_ℒp_of_is_finite_measure 1 μ)
lemma measure_preimage_lt_top_of_integrable (f : α →ₛ E) (hf : integrable f μ) {x : E}
(hx : x ≠ 0) :
μ (f ⁻¹' {x}) < ∞ :=
integrable_iff.mp hf x hx
lemma measure_support_lt_top [has_zero β] (f : α →ₛ β) (hf : ∀ y ≠ 0, μ (f ⁻¹' {y}) < ∞) :
μ (support f) < ∞ :=
begin
rw support_eq,
refine (measure_bUnion_finset_le _ _).trans_lt (ennreal.sum_lt_top_iff.mpr (λ y hy, _)),
rw finset.mem_filter at hy,
exact hf y hy.2,
end
lemma measure_support_lt_top_of_mem_ℒp (f : α →ₛ E) (hf : mem_ℒp f p μ) (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) :
μ (support f) < ∞ :=
f.measure_support_lt_top ((mem_ℒp_iff (pos_iff_ne_zero.mpr hp_ne_zero) hp_ne_top).mp hf)
lemma measure_support_lt_top_of_integrable (f : α →ₛ E) (hf : integrable f μ) :
μ (support f) < ∞ :=
f.measure_support_lt_top (integrable_iff.mp hf)
lemma measure_lt_top_of_mem_ℒp_indicator (hp_pos : 0 < p) (hp_ne_top : p ≠ ∞) {c : E} (hc : c ≠ 0)
{s : set α} (hs : measurable_set s)
(hcs : mem_ℒp ((const α c).piecewise s hs (const α 0)) p μ) :
μ s < ⊤ :=
begin
have : function.support (const α c) = set.univ := function.support_const hc,
simpa only [mem_ℒp_iff_fin_meas_supp hp_pos hp_ne_top, fin_meas_supp_iff_support,
support_indicator, set.inter_univ, this] using hcs
end
end simple_func_properties
end simple_func
/-! Construction of the space of `Lp` simple functions, and its dense embedding into `Lp`. -/
namespace Lp
open ae_eq_fun
variables
[measurable_space α]
[normed_group E] [second_countable_topology E] [measurable_space E] [borel_space E]
[normed_group F] [second_countable_topology F] [measurable_space F] [borel_space F]
(p : ℝ≥0∞) (μ : measure α)
variables (E)
/-- `Lp.simple_func` is a subspace of Lp consisting of equivalence classes of an integrable simple
function. -/
def simple_func : add_subgroup (Lp E p μ) :=
{ carrier := {f : Lp E p μ | ∃ (s : α →ₛ E), (ae_eq_fun.mk s s.ae_measurable : α →ₘ[μ] E) = f},
zero_mem' := ⟨0, rfl⟩,
add_mem' := λ f g ⟨s, hs⟩ ⟨t, ht⟩, ⟨s + t,
by simp only [←hs, ←ht, mk_add_mk, add_subgroup.coe_add, mk_eq_mk, simple_func.coe_add]⟩,
neg_mem' := λ f ⟨s, hs⟩, ⟨-s,
by simp only [←hs, neg_mk, simple_func.coe_neg, mk_eq_mk, add_subgroup.coe_neg]⟩ }
variables {E p μ}
namespace simple_func
section instances
/-! Simple functions in Lp space form a `normed_space`. -/
@[norm_cast] lemma coe_coe (f : Lp.simple_func E p μ) : ⇑(f : Lp E p μ) = f := rfl
protected lemma eq' {f g : Lp.simple_func E p μ} : (f : α →ₘ[μ] E) = (g : α →ₘ[μ] E) → f = g :=
subtype.eq ∘ subtype.eq
/-! Implementation note: If `Lp.simple_func E p μ` were defined as a `𝕜`-submodule of `Lp E p μ`,
then the next few lemmas, putting a normed `𝕜`-group structure on `Lp.simple_func E p μ`, would be
unnecessary. But instead, `Lp.simple_func E p μ` is defined as an `add_subgroup` of `Lp E p μ`,
which does not permit this (but has the advantage of working when `E` itself is a normed group,
i.e. has no scalar action). -/
variables [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
/-- If `E` is a normed space, `Lp.simple_func E p μ` is a `has_scalar`. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def has_scalar : has_scalar 𝕜 (Lp.simple_func E p μ) := ⟨λk f, ⟨k • f,
begin
rcases f with ⟨f, ⟨s, hs⟩⟩,
use k • s,
apply eq.trans (smul_mk k s s.ae_measurable).symm _,
rw hs,
refl,
end ⟩⟩
local attribute [instance] simple_func.has_scalar
@[simp, norm_cast] lemma coe_smul (c : 𝕜) (f : Lp.simple_func E p μ) :
((c • f : Lp.simple_func E p μ) : Lp E p μ) = c • (f : Lp E p μ) := rfl
/-- If `E` is a normed space, `Lp.simple_func E p μ` is a module. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def module : module 𝕜 (Lp.simple_func E p μ) :=
{ one_smul := λf, by { ext1, exact one_smul _ _ },
mul_smul := λx y f, by { ext1, exact mul_smul _ _ _ },
smul_add := λx f g, by { ext1, exact smul_add _ _ _ },
smul_zero := λx, by { ext1, exact smul_zero _ },
add_smul := λx y f, by { ext1, exact add_smul _ _ _ },
zero_smul := λf, by { ext1, exact zero_smul _ _ } }
local attribute [instance] simple_func.module
/-- If `E` is a normed space, `Lp.simple_func E p μ` is a normed space. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def normed_space [fact (1 ≤ p)] : normed_space 𝕜 (Lp.simple_func E p μ) :=
⟨ λc f, by { rw [coe_norm_subgroup, coe_norm_subgroup, coe_smul, norm_smul] } ⟩
end instances
local attribute [instance] simple_func.module simple_func.normed_space
section to_Lp
/-- Construct the equivalence class `[f]` of a simple function `f` satisfying `mem_ℒp`. -/
@[reducible] def to_Lp (f : α →ₛ E) (hf : mem_ℒp f p μ) : (Lp.simple_func E p μ) :=
⟨hf.to_Lp f, ⟨f, rfl⟩⟩
lemma to_Lp_eq_to_Lp (f : α →ₛ E) (hf : mem_ℒp f p μ) :
(to_Lp f hf : Lp E p μ) = hf.to_Lp f := rfl
lemma to_Lp_eq_mk (f : α →ₛ E) (hf : mem_ℒp f p μ) :
(to_Lp f hf : α →ₘ[μ] E) = ae_eq_fun.mk f f.ae_measurable := rfl
lemma to_Lp_zero : to_Lp (0 : α →ₛ E) zero_mem_ℒp = (0 : Lp.simple_func E p μ) := rfl
lemma to_Lp_add (f g : α →ₛ E) (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
to_Lp (f + g) (hf.add hg) = to_Lp f hf + to_Lp g hg := rfl
lemma to_Lp_neg (f : α →ₛ E) (hf : mem_ℒp f p μ) :
to_Lp (-f) hf.neg = -to_Lp f hf := rfl
lemma to_Lp_sub (f g : α →ₛ E) (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
to_Lp (f - g) (hf.sub hg) = to_Lp f hf - to_Lp g hg :=
by { simp only [sub_eq_add_neg, ← to_Lp_neg, ← to_Lp_add], refl }
variables [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
lemma to_Lp_smul (f : α →ₛ E) (hf : mem_ℒp f p μ) (c : 𝕜) :
to_Lp (c • f) (hf.const_smul c) = c • to_Lp f hf := rfl
lemma norm_to_Lp [fact (1 ≤ p)] (f : α →ₛ E) (hf : mem_ℒp f p μ) :
∥to_Lp f hf∥ = ennreal.to_real (snorm f p μ) :=
norm_to_Lp f hf
end to_Lp
section to_simple_func
/-- Find a representative of a `Lp.simple_func`. -/
def to_simple_func (f : Lp.simple_func E p μ) : α →ₛ E := classical.some f.2
/-- `(to_simple_func f)` is measurable. -/
@[measurability]
protected lemma measurable (f : Lp.simple_func E p μ) : measurable (to_simple_func f) :=
(to_simple_func f).measurable
@[measurability]
protected lemma ae_measurable (f : Lp.simple_func E p μ) : ae_measurable (to_simple_func f) μ :=
(simple_func.measurable f).ae_measurable
lemma to_simple_func_eq_to_fun (f : Lp.simple_func E p μ) : to_simple_func f =ᵐ[μ] f :=
show ⇑(to_simple_func f) =ᵐ[μ] ⇑(f : α →ₘ[μ] E), by
begin
convert (ae_eq_fun.coe_fn_mk (to_simple_func f) (simple_func.ae_measurable f)).symm using 2,
exact (classical.some_spec f.2).symm,
end
/-- `to_simple_func f` satisfies the predicate `mem_ℒp`. -/
protected lemma mem_ℒp (f : Lp.simple_func E p μ) : mem_ℒp (to_simple_func f) p μ :=
mem_ℒp.ae_eq (to_simple_func_eq_to_fun f).symm $ mem_Lp_iff_mem_ℒp.mp (f : Lp E p μ).2
lemma to_Lp_to_simple_func (f : Lp.simple_func E p μ) :
to_Lp (to_simple_func f) (simple_func.mem_ℒp f) = f :=
simple_func.eq' (classical.some_spec f.2)
lemma to_simple_func_to_Lp (f : α →ₛ E) (hfi : mem_ℒp f p μ) :
to_simple_func (to_Lp f hfi) =ᵐ[μ] f :=
by { rw ← mk_eq_mk, exact classical.some_spec (to_Lp f hfi).2 }
variables (E μ)
lemma zero_to_simple_func : to_simple_func (0 : Lp.simple_func E p μ) =ᵐ[μ] 0 :=
begin
filter_upwards [to_simple_func_eq_to_fun (0 : Lp.simple_func E p μ), Lp.coe_fn_zero E 1 μ],
assume a h₁ h₂,
rwa h₁,
end
variables {E μ}
lemma add_to_simple_func (f g : Lp.simple_func E p μ) :
to_simple_func (f + g) =ᵐ[μ] to_simple_func f + to_simple_func g :=
begin
filter_upwards [to_simple_func_eq_to_fun (f + g), to_simple_func_eq_to_fun f,
to_simple_func_eq_to_fun g, Lp.coe_fn_add (f : Lp E p μ) g],
assume a,
simp only [← coe_coe, add_subgroup.coe_add, pi.add_apply],
iterate 4 { assume h, rw h }
end
lemma neg_to_simple_func (f : Lp.simple_func E p μ) :
to_simple_func (-f) =ᵐ[μ] - to_simple_func f :=
begin
filter_upwards [to_simple_func_eq_to_fun (-f), to_simple_func_eq_to_fun f,
Lp.coe_fn_neg (f : Lp E p μ)],
assume a,
simp only [pi.neg_apply, add_subgroup.coe_neg, ← coe_coe],
repeat { assume h, rw h }
end
lemma sub_to_simple_func (f g : Lp.simple_func E p μ) :
to_simple_func (f - g) =ᵐ[μ] to_simple_func f - to_simple_func g :=
begin
filter_upwards [to_simple_func_eq_to_fun (f - g), to_simple_func_eq_to_fun f,
to_simple_func_eq_to_fun g, Lp.coe_fn_sub (f : Lp E p μ) g],
assume a,
simp only [add_subgroup.coe_sub, pi.sub_apply, ← coe_coe],
repeat { assume h, rw h }
end
variables [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
lemma smul_to_simple_func (k : 𝕜) (f : Lp.simple_func E p μ) :
to_simple_func (k • f) =ᵐ[μ] k • to_simple_func f :=
begin
filter_upwards [to_simple_func_eq_to_fun (k • f), to_simple_func_eq_to_fun f,
Lp.coe_fn_smul k (f : Lp E p μ)],
assume a,
simp only [pi.smul_apply, coe_smul, ← coe_coe],
repeat { assume h, rw h }
end
lemma norm_to_simple_func [fact (1 ≤ p)] (f : Lp.simple_func E p μ) :
∥f∥ = ennreal.to_real (snorm (to_simple_func f) p μ) :=
by simpa [to_Lp_to_simple_func] using norm_to_Lp (to_simple_func f) (simple_func.mem_ℒp f)
end to_simple_func
section induction
variables (p)
/-- The characteristic function of a finite-measure measurable set `s`, as an `Lp` simple function.
-/
def indicator_const {s : set α} (hs : measurable_set s) (hμs : μ s ≠ ∞) (c : E) :
Lp.simple_func E p μ :=
to_Lp ((simple_func.const _ c).piecewise s hs (simple_func.const _ 0))
(mem_ℒp_indicator_const p hs c (or.inr hμs))
variables {p}
@[simp] lemma coe_indicator_const {s : set α} (hs : measurable_set s) (hμs : μ s ≠ ∞) (c : E) :
(↑(indicator_const p hs hμs c) : Lp E p μ) = indicator_const_Lp p hs hμs c :=
rfl
lemma to_simple_func_indicator_const {s : set α} (hs : measurable_set s) (hμs : μ s ≠ ∞) (c : E) :
to_simple_func (indicator_const p hs hμs c)
=ᵐ[μ] (simple_func.const _ c).piecewise s hs (simple_func.const _ 0) :=
Lp.simple_func.to_simple_func_to_Lp _ _
/-- To prove something for an arbitrary `Lp` simple function, with `0 < p < ∞`, it suffices to show
that the property holds for (multiples of) characteristic functions of finite-measure measurable
sets and is closed under addition (of functions with disjoint support). -/
@[elab_as_eliminator]
protected lemma induction (hp_pos : 0 < p) (hp_ne_top : p ≠ ∞) {P : Lp.simple_func E p μ → Prop}
(h_ind : ∀ (c : E) {s : set α} (hs : measurable_set s) (hμs : μ s < ∞),
P (Lp.simple_func.indicator_const p hs hμs.ne c))
(h_add : ∀ ⦃f g : α →ₛ E⦄, ∀ hf : mem_ℒp f p μ, ∀ hg : mem_ℒp g p μ,
disjoint (support f) (support g) → P (Lp.simple_func.to_Lp f hf)
→ P (Lp.simple_func.to_Lp g hg) → P (Lp.simple_func.to_Lp f hf + Lp.simple_func.to_Lp g hg))
(f : Lp.simple_func E p μ) : P f :=
begin
suffices : ∀ f : α →ₛ E, ∀ hf : mem_ℒp f p μ, P (to_Lp f hf),
{ rw ← to_Lp_to_simple_func f,
apply this }, clear f,
refine simple_func.induction _ _,
{ intros c s hs hf,
by_cases hc : c = 0,
{ convert h_ind 0 measurable_set.empty (by simp) using 1,
ext1,
simp [hc] },
exact h_ind c hs (simple_func.measure_lt_top_of_mem_ℒp_indicator hp_pos hp_ne_top hc hs hf) },
{ intros f g hfg hf hg hfg',
obtain ⟨hf', hg'⟩ : mem_ℒp f p μ ∧ mem_ℒp g p μ,
{ exact (mem_ℒp_add_of_disjoint hfg f.measurable g.measurable).mp hfg' },
exact h_add hf' hg' hfg (hf hf') (hg hg') },
end
end induction
section coe_to_Lp
variables [fact (1 ≤ p)]
protected lemma uniform_continuous :
uniform_continuous (coe : (Lp.simple_func E p μ) → (Lp E p μ)) :=
uniform_continuous_comap
protected lemma uniform_embedding :
uniform_embedding (coe : (Lp.simple_func E p μ) → (Lp E p μ)) :=
uniform_embedding_comap subtype.val_injective
protected lemma uniform_inducing : uniform_inducing (coe : (Lp.simple_func E p μ) → (Lp E p μ)) :=
simple_func.uniform_embedding.to_uniform_inducing
protected lemma dense_embedding (hp_ne_top : p ≠ ∞) :
dense_embedding (coe : (Lp.simple_func E p μ) → (Lp E p μ)) :=
begin
apply simple_func.uniform_embedding.dense_embedding,
assume f,
rw mem_closure_iff_seq_limit,
have hfi' : mem_ℒp f p μ := Lp.mem_ℒp f,
refine ⟨λ n, ↑(to_Lp (simple_func.approx_on f (Lp.measurable f) univ 0 trivial n)
(simple_func.mem_ℒp_approx_on_univ (Lp.measurable f) hfi' n)), λ n, mem_range_self _, _⟩,
convert simple_func.tendsto_approx_on_univ_Lp hp_ne_top (Lp.measurable f) hfi',
rw to_Lp_coe_fn f (Lp.mem_ℒp f)
end
protected lemma dense_inducing (hp_ne_top : p ≠ ∞) :
dense_inducing (coe : (Lp.simple_func E p μ) → (Lp E p μ)) :=
(simple_func.dense_embedding hp_ne_top).to_dense_inducing
protected lemma dense_range (hp_ne_top : p ≠ ∞) :
dense_range (coe : (Lp.simple_func E p μ) → (Lp E p μ)) :=
(simple_func.dense_inducing hp_ne_top).dense
variables [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
variables (α E 𝕜)
/-- The embedding of Lp simple functions into Lp functions, as a continuous linear map. -/
def coe_to_Lp : (Lp.simple_func E p μ) →L[𝕜] (Lp E p μ) :=
{ map_smul' := λk f, rfl,
cont := Lp.simple_func.uniform_continuous.continuous,
.. add_subgroup.subtype (Lp.simple_func E p μ) }
variables {α E 𝕜}
end coe_to_Lp
end simple_func
end Lp
variables [measurable_space α] [normed_group E] [measurable_space E] [borel_space E]
[second_countable_topology E] {f : α → E} {p : ℝ≥0∞} {μ : measure α}
/-- To prove something for an arbitrary `Lp` function in a second countable Borel normed group, it
suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in `Lp` for which the property holds is closed.
-/
@[elab_as_eliminator]
lemma Lp.induction [_i : fact (1 ≤ p)] (hp_ne_top : p ≠ ∞) (P : Lp E p μ → Prop)
(h_ind : ∀ (c : E) {s : set α} (hs : measurable_set s) (hμs : μ s < ∞),
P (Lp.simple_func.indicator_const p hs hμs.ne c))
(h_add : ∀ ⦃f g⦄, ∀ hf : mem_ℒp f p μ, ∀ hg : mem_ℒp g p μ, disjoint (support f) (support g) →
P (hf.to_Lp f) → P (hg.to_Lp g) → P ((hf.to_Lp f) + (hg.to_Lp g)))
(h_closed : is_closed {f : Lp E p μ | P f}) :
∀ f : Lp E p μ, P f :=
begin
refine λ f, (Lp.simple_func.dense_range hp_ne_top).induction_on f h_closed _,
refine Lp.simple_func.induction (lt_of_lt_of_le ennreal.zero_lt_one _i.elim) hp_ne_top _ _,
{ exact λ c s, h_ind c },
{ exact λ f g hf hg, h_add hf hg },
end
/-- To prove something for an arbitrary `mem_ℒp` function in a second countable
Borel normed group, it suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in the `Lᵖ` space for which the property holds is closed.
* the property is closed under the almost-everywhere equal relation.
It is possible to make the hypotheses in the induction steps a bit stronger, and such conditions
can be added once we need them (for example in `h_add` it is only necessary to consider the sum of
a simple function with a multiple of a characteristic function and that the intersection
of their images is a subset of `{0}`).
-/
@[elab_as_eliminator]
lemma mem_ℒp.induction [_i : fact (1 ≤ p)] (hp_ne_top : p ≠ ∞) (P : (α → E) → Prop)
(h_ind : ∀ (c : E) ⦃s⦄, measurable_set s → μ s < ∞ → P (s.indicator (λ _, c)))
(h_add : ∀ ⦃f g : α → E⦄, disjoint (support f) (support g) → mem_ℒp f p μ → mem_ℒp g p μ →
P f → P g → P (f + g))
(h_closed : is_closed {f : Lp E p μ | P f} )
(h_ae : ∀ ⦃f g⦄, f =ᵐ[μ] g → mem_ℒp f p μ → P f → P g) :
∀ ⦃f : α → E⦄ (hf : mem_ℒp f p μ), P f :=
begin
have : ∀ (f : simple_func α E), mem_ℒp f p μ → P f,
{ refine simple_func.induction _ _,
{ intros c s hs h,
by_cases hc : c = 0,
{ subst hc, convert h_ind 0 measurable_set.empty (by simp) using 1, ext, simp [const] },
have hp_pos : 0 < p := lt_of_lt_of_le ennreal.zero_lt_one _i.elim,
exact h_ind c hs (simple_func.measure_lt_top_of_mem_ℒp_indicator hp_pos hp_ne_top hc hs h) },
{ intros f g hfg hf hg int_fg,
rw [simple_func.coe_add, mem_ℒp_add_of_disjoint hfg f.measurable g.measurable] at int_fg,
refine h_add hfg int_fg.1 int_fg.2 (hf int_fg.1) (hg int_fg.2) } },
have : ∀ (f : Lp.simple_func E p μ), P f,
{ intro f,
exact h_ae (Lp.simple_func.to_simple_func_eq_to_fun f) (Lp.simple_func.mem_ℒp f)
(this (Lp.simple_func.to_simple_func f) (Lp.simple_func.mem_ℒp f)) },
have : ∀ (f : Lp E p μ), P f :=
λ f, (Lp.simple_func.dense_range hp_ne_top).induction_on f h_closed this,
exact λ f hf, h_ae hf.coe_fn_to_Lp (Lp.mem_ℒp _) (this (hf.to_Lp f)),
end
section integrable
local attribute [instance] fact_one_le_one_ennreal
notation α ` →₁ₛ[`:25 μ `] ` E := @measure_theory.Lp.simple_func α E _ _ _ _ _ 1 μ
lemma L1.simple_func.to_Lp_one_eq_to_L1 (f : α →ₛ E) (hf : integrable f μ) :
(Lp.simple_func.to_Lp f (mem_ℒp_one_iff_integrable.2 hf) : α →₁[μ] E) = hf.to_L1 f :=
rfl
protected lemma L1.simple_func.integrable (f : α →₁ₛ[μ] E) :
integrable (Lp.simple_func.to_simple_func f) μ :=
by { rw ← mem_ℒp_one_iff_integrable, exact (Lp.simple_func.mem_ℒp f) }
/-- To prove something for an arbitrary integrable function in a second countable
Borel normed group, it suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in the `L¹` space for which the property holds is closed.
* the property is closed under the almost-everywhere equal relation.
It is possible to make the hypotheses in the induction steps a bit stronger, and such conditions
can be added once we need them (for example in `h_add` it is only necessary to consider the sum of
a simple function with a multiple of a characteristic function and that the intersection
of their images is a subset of `{0}`).
-/
@[elab_as_eliminator]
lemma integrable.induction (P : (α → E) → Prop)
(h_ind : ∀ (c : E) ⦃s⦄, measurable_set s → μ s < ∞ → P (s.indicator (λ _, c)))
(h_add : ∀ ⦃f g : α → E⦄, disjoint (support f) (support g) → integrable f μ → integrable g μ →
P f → P g → P (f + g))
(h_closed : is_closed {f : α →₁[μ] E | P f} )
(h_ae : ∀ ⦃f g⦄, f =ᵐ[μ] g → integrable f μ → P f → P g) :
∀ ⦃f : α → E⦄ (hf : integrable f μ), P f :=
begin
simp only [← mem_ℒp_one_iff_integrable] at *,
exact mem_ℒp.induction one_ne_top P h_ind h_add h_closed h_ae
end
end integrable
end measure_theory
|
d51b90e18cd90f8b5ebfbac9aa5d27456f807b62 | 32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7 | /src/Lean/Meta/LevelDefEq.lean | 30ff2b9bb8624bd29585c3fa9c143ebd9af8279d | [
"Apache-2.0"
] | permissive | walterhu1015/lean4 | b2c71b688975177402758924eaa513475ed6ce72 | 2214d81e84646a905d0b20b032c89caf89c737ad | refs/heads/master | 1,671,342,096,906 | 1,599,695,985,000 | 1,599,695,985,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,533 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Basic
import Lean.Meta.InferType
namespace Lean
namespace Meta
private partial def decAux? : Level → MetaM (Option Level)
| Level.zero _ => pure none
| Level.param _ _ => pure none
| Level.mvar mvarId _ => do
mctx ← getMCtx;
match mctx.getLevelAssignment? mvarId with
| some u => decAux? u
| none =>
condM (isReadOnlyLevelMVar mvarId) (pure none) $ do
u ← mkFreshLevelMVar;
assignLevelMVar mvarId (mkLevelSucc u);
pure u
| Level.succ u _ => pure u
| u =>
let process (u v : Level) : MetaM (Option Level) := do {
u? ← decAux? u;
match u? with
| none => pure none
| some u => do
v? ← decAux? v;
match v? with
| none => pure none
| some v => pure $ mkLevelMax u v
};
match u with
| Level.max u v _ => process u v
/- Remark: If `decAux? v` returns `some ...`, then `imax u v` is equivalent to `max u v`. -/
| Level.imax u v _ => process u v
| _ => unreachable!
variables {m : Type → Type} [MonadLiftT MetaM m]
private def decLevelImp (u : Level) : MetaM (Option Level) := do
mctx ← getMCtx;
result? ← decAux? u;
match result? with
| some v => pure $ some v
| none => do
modify $ fun s => { s with mctx := mctx };
pure none
def decLevel? (u : Level) : m (Option Level) :=
liftMetaM $ decLevelImp u
def decLevel (u : Level) : m Level := liftMetaM do
u? ← decLevel? u;
match u? with
| some u => pure u
| none => throwError ("invalid universe level, " ++ u ++ " is not greater than 0")
/- This method is useful for inferring universe level parameters for function that take arguments such as `{α : Type u}`.
Recall that `Type u` is `Sort (u+1)` in Lean. Thus, given `α`, we must infer its universe level,
and then decrement 1 to obtain `u`. -/
def getDecLevel (type : Expr) : m Level := liftMetaM do
u ← getLevel type;
decLevel u
private def strictOccursMaxAux (lvl : Level) : Level → Bool
| Level.max u v _ => strictOccursMaxAux u || strictOccursMaxAux v
| u => u != lvl && lvl.occurs u
/--
Return true iff `lvl` occurs in `max u_1 ... u_n` and `lvl != u_i` for all `i in [1, n]`.
That is, `lvl` is a proper level subterm of some `u_i`. -/
private def strictOccursMax (lvl : Level) : Level → Bool
| Level.max u v _ => strictOccursMaxAux lvl u || strictOccursMaxAux lvl v
| _ => false
/-- `mkMaxArgsDiff mvarId (max u_1 ... (mvar mvarId) ... u_n) v` => `max v u_1 ... u_n` -/
private def mkMaxArgsDiff (mvarId : MVarId) : Level → Level → Level
| Level.max u v _, acc => mkMaxArgsDiff v $ mkMaxArgsDiff u acc
| l@(Level.mvar id _), acc => if id != mvarId then mkLevelMax acc l else acc
| l, acc => mkLevelMax acc l
/--
Solve `?m =?= max ?m v` by creating a fresh metavariable `?n`
and assigning `?m := max ?n v` -/
private def solveSelfMax (mvarId : MVarId) (v : Level) : MetaM Unit := do
n ← mkFreshLevelMVar;
assignLevelMVar mvarId $ mkMaxArgsDiff mvarId v n
private def postponeIsLevelDefEq (lhs : Level) (rhs : Level) : MetaM Unit :=
modify $ fun s => { s with postponed := s.postponed.push { lhs := lhs, rhs := rhs } }
inductive LevelConstraintKind
| mvarEq -- ?m =?= l where ?m does not occur in l
| mvarEqSelfMax -- ?m =?= max ?m l where ?m does not occur in l
| other
private def getLevelConstraintKind (u v : Level) : MetaM LevelConstraintKind :=
match u with
| Level.mvar mvarId _ =>
condM (isReadOnlyLevelMVar mvarId)
(pure LevelConstraintKind.other)
(if !u.occurs v then pure LevelConstraintKind.mvarEq
else if !strictOccursMax u v then pure LevelConstraintKind.mvarEqSelfMax
else pure LevelConstraintKind.other)
| _ =>
pure LevelConstraintKind.other
partial def isLevelDefEqAux : Level → Level → MetaM Bool
| Level.succ lhs _, Level.succ rhs _ => isLevelDefEqAux lhs rhs
| lhs, rhs =>
if lhs == rhs then
pure true
else do
trace! `Meta.isLevelDefEq.step (lhs ++ " =?= " ++ rhs);
lhs' ← instantiateLevelMVars lhs;
let lhs' := lhs'.normalize;
rhs' ← instantiateLevelMVars rhs;
let rhs' := rhs'.normalize;
if lhs != lhs' || rhs != rhs' then
isLevelDefEqAux lhs' rhs'
else do
mctx ← getMCtx;
if !mctx.hasAssignableLevelMVar lhs && !mctx.hasAssignableLevelMVar rhs then do
ctx ← read;
if ctx.config.isDefEqStuckEx && (lhs.isMVar || rhs.isMVar) then do
trace! `Meta.isLevelDefEq.stuck (lhs ++ " =?= " ++ rhs);
Meta.throwIsDefEqStuck
else
pure false
else do
k ← getLevelConstraintKind lhs rhs;
match k with
| LevelConstraintKind.mvarEq => do assignLevelMVar lhs.mvarId! rhs; pure true
| LevelConstraintKind.mvarEqSelfMax => do solveSelfMax lhs.mvarId! rhs; pure true
| _ => do
k ← getLevelConstraintKind rhs lhs;
match k with
| LevelConstraintKind.mvarEq => do assignLevelMVar rhs.mvarId! lhs; pure true
| LevelConstraintKind.mvarEqSelfMax => do solveSelfMax rhs.mvarId! lhs; pure true
| _ =>
if lhs.isMVar || rhs.isMVar then
pure false
else
let isSuccEq (u v : Level) : MetaM Bool :=
match u with
| Level.succ u _ => do
v? ← Meta.decLevel? v;
match v? with
| some v => isLevelDefEqAux u v
| none => pure false
| _ => pure false;
condM (isSuccEq lhs rhs) (pure true) $
condM (isSuccEq rhs lhs) (pure true) $ do
postponeIsLevelDefEq lhs rhs; pure true
def isListLevelDefEqAux : List Level → List Level → MetaM Bool
| [], [] => pure true
| u::us, v::vs => isLevelDefEqAux u v <&&> isListLevelDefEqAux us vs
| _, _ => pure false
private def getNumPostponed : MetaM Nat := do
s ← get; pure s.postponed.size
open Std (PersistentArray)
private def getResetPostponed : MetaM (PersistentArray PostponedEntry) := do
s ← get;
let ps := s.postponed;
modify $ fun s => { s with postponed := {} };
pure ps
private def processPostponedStep : MetaM Bool :=
traceCtx `Meta.isLevelDefEq.postponed.step $ do
ps ← getResetPostponed;
ps.foldlM
(fun (r : Bool) (p : PostponedEntry) =>
if r then
isLevelDefEqAux p.lhs p.rhs
else
pure false)
true
private partial def processPostponedAux : Unit → MetaM Bool
| _ => do
numPostponed ← getNumPostponed;
if numPostponed == 0 then
pure true
else do
trace! `Meta.isLevelDefEq.postponed ("processing #" ++ toString numPostponed ++ " postponed is-def-eq level constraints");
r ← processPostponedStep;
if !r then
pure r
else do
numPostponed' ← getNumPostponed;
if numPostponed' == 0 then
pure true
else if numPostponed' < numPostponed then
processPostponedAux ()
else do
trace! `Meta.isLevelDefEq.postponed (format "no progress solving pending is-def-eq level constraints");
pure false
private def processPostponed : MetaM Bool := do
numPostponed ← getNumPostponed;
if numPostponed == 0 then pure true
else traceCtx `Meta.isLevelDefEq.postponed $ processPostponedAux ()
def restore (env : Environment) (mctx : MetavarContext) (postponed : PersistentArray PostponedEntry) : MetaM Unit := do
setEnv env;
modify $ fun s => { s with mctx := mctx, postponed := postponed }
/--
`commitWhenSome? x` executes `x` and process all postponed universe level constraints produced by `x`.
We keep the modifications only if `processPostponed` return true and `x` returned `some a`.
Remark: postponed universe level constraints must be solved before returning. Otherwise,
we don't know whether `x` really succeeded. -/
@[specialize] def commitWhenSome? {α} (x? : MetaM (Option α)) : MetaM (Option α) := do
env ← getEnv;
s ← get;
let mctx := s.mctx;
let postponed := s.postponed;
modify $ fun s => { s with postponed := {} };
catch
(do
a? ← x?;
match a? with
| some a =>
(condM processPostponed
(pure (some a))
(do restore env mctx postponed; pure none))
| none => do
restore env mctx postponed; pure none)
(fun ex => do restore env mctx postponed; throw ex)
@[specialize] def commitWhen (x : MetaM Bool) : MetaM Bool := do
r? ← commitWhenSome? (condM x (pure $ some ()) (pure none));
match r? with
| some _ => pure true
| none => pure false
@[init] private def regTraceClasses : IO Unit := do
registerTraceClass `Meta.isLevelDefEq;
registerTraceClass `Meta.isLevelDefEq.step;
registerTraceClass `Meta.isLevelDefEq.postponed
def isLevelDefEq (u v : Level) : m Bool := liftMetaM do
traceCtx `Meta.isLevelDefEq $ do
b ← Meta.commitWhen $ Meta.isLevelDefEqAux u v;
trace! `Meta.isLevelDefEq (u ++ " =?= " ++ v ++ " ... " ++ if b then "success" else "failure");
pure b
def isExprDefEq (t s : Expr) : m Bool := liftMetaM do
traceCtx `Meta.isDefEq $ do
b ← Meta.commitWhen $ Meta.isExprDefEqAux t s;
trace! `Meta.isDefEq (t ++ " =?= " ++ s ++ " ... " ++ if b then "success" else "failure");
pure b
abbrev isDefEq (t s : Expr) : m Bool :=
isExprDefEq t s
def isDefEqNoConstantApprox (t s : Expr) : m Bool := liftMetaM do
approxDefEq $ isDefEq t s
end Meta
end Lean
|
adef51fd937dfb570b88cde22ff0f4db0fb029e5 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/ring_theory/adjoin/power_basis.lean | 008ff327c4a210ba6de0207a40fa03dba5335877 | [
"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 | 2,162 | lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import ring_theory.adjoin.basic
import ring_theory.power_basis
/-!
# Power basis for `algebra.adjoin R {x}`
This file defines the canonical power basis on `algebra.adjoin R {x}`,
where `x` is an integral element over `R`.
-/
variables {K S : Type*} [field K] [comm_ring S] [algebra K S]
namespace algebra
open polynomial
open power_basis
open_locale big_operators
/-- The elements `1, x, ..., x ^ (d - 1)` for a basis for the `K`-module `K[x]`,
where `d` is the degree of the minimal polynomial of `x`. -/
noncomputable def adjoin.power_basis_aux {x : S} (hx : _root_.is_integral K x) :
basis (fin (minpoly K x).nat_degree) K (adjoin K ({x} : set S)) :=
begin
have hST : function.injective (algebra_map (adjoin K ({x} : set S)) S) := subtype.coe_injective,
have hx' : _root_.is_integral K
(show adjoin K ({x} : set S), from ⟨x, subset_adjoin (set.mem_singleton x)⟩),
{ apply (is_integral_algebra_map_iff hST).mp,
convert hx,
apply_instance },
have minpoly_eq := minpoly.eq_of_algebra_map_eq hST hx' rfl,
apply @basis.mk (fin (minpoly K x).nat_degree) _
(adjoin K {x}) (λ i, ⟨x, subset_adjoin (set.mem_singleton x)⟩ ^ (i : ℕ)),
{ have := hx'.linear_independent_pow,
rwa minpoly_eq at this },
{ rw _root_.eq_top_iff,
rintros ⟨y, hy⟩ _,
have := hx'.mem_span_pow,
rw minpoly_eq at this,
apply this,
{ rw [adjoin_singleton_eq_range_aeval] at hy,
obtain ⟨f, rfl⟩ := (aeval x).mem_range.mp hy,
use f,
ext,
exact (is_scalar_tower.algebra_map_aeval K (adjoin K {x}) S ⟨x, _⟩ _).symm } }
end
/-- The power basis `1, x, ..., x ^ (d - 1)` for `K[x]`,
where `d` is the degree of the minimal polynomial of `x`. -/
noncomputable def adjoin.power_basis {x : S} (hx : _root_.is_integral K x) :
power_basis K (adjoin K ({x} : set S)) :=
{ gen := ⟨x, subset_adjoin (set.mem_singleton x)⟩,
dim := (minpoly K x).nat_degree,
basis := adjoin.power_basis_aux hx,
basis_eq_pow := basis.mk_apply _ _ }
end algebra
|
c2b9d76af6ae92d6f5bc4431ddc2f5fdf843261e | dac4e6671410f506c880986cbb2212dd7f5b3dfd | /folklore/core.lean | 6dbf941e743941c52d253d8dc246916177e312aa | [
"CC-BY-4.0"
] | permissive | thalesant/formalabstracts-2018 | e6ddfe8b3ce5c6f055ddcccf345bf55c41f850c1 | d206dfa32a6b4a84aacc3a5500a144757e6d3454 | refs/heads/master | 1,642,678,879,231 | 1,561,648,713,000 | 1,561,648,713,000 | 97,608,420 | 1 | 0 | null | 1,564,063,995,000 | 1,500,388,250,000 | Lean | UTF-8 | Lean | false | false | 15,100 | lean | /- Thomas Hales
Start over, using bundled structures.
Feb 3, 2018
-/
prelude
--basic core stuff
/- The default behavior for Type is Type u,
for an arbitrary type variable u
(unlike Official-Lean).
The intention is for universe variables to be mostly
handled behind the scenes. -/
notation `Prop` := Sort 0
notation f ` $ `:1 a:0 := f a
inductive true : Prop
| intro : true
inductive false : Prop
inductive empty : Type
def not (a : Prop) := a → false
prefix `(¬) := not
@[reducible] def ne {α : Sort} (a b : α) := ¬(a = b)
notation a ≠ b := ne a b
inductive eq {α : Sort} (a : α) : α → Prop
| refl : eq a
infix ` = `:50 := eq
structure prod (α : Type) (β : Type) :=
(fst : α)
(snd : β)
structure and (a b : Prop) : Prop :=
(left : a)
(right : b)
inductive sum (α : Type) (β : Type)
| inl {} (val : α) : sum
| inr {} (val : β) : sum
inductive or (a b : Prop) : Prop
| inl {} (h : a) : or
| inr {} (h : b) : or
structure sigma {α : Type} (β : α → Type) :=
(fst : α)
(snd : β fst)
inductive bool : Type
| ff : bool
| tt : bool
structure subtype {α : Sort} (p : α → Prop) :=
(val : α) (property : p val)
inductive option (α : Type)
| none {} : option
| some (val : α) : option
inductive list (T : Type)
| nil {} : list
| cons (hd : T) (tl : list) : list
notation h :: t := list.cons h t
notation `[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) := l
inductive nat
| zero : nat
| succ (n : nat) : nat
structure unification_constraint :=
{α : Type} (lhs : α) (rhs : α)
infix ` ≟ `:50 := unification_constraint.mk
infix ` =?= `:50 := unification_constraint.mk
structure unification_hint :=
(pattern : unification_constraint)
(constraints : list unification_constraint)
-- basic set notation.
class_infix `has_mem.mem `(∈)
class_infix `has_sub.sub `(-)
class_infix `has_div.div `(/)
class_infix `has_dvd.dvd `(∣)
class_infix `has_mod.mod `(%)
class_infix `has_le.le `(<=)
class_infix `has_le.le `(≤)
class_infix `has_lt.lt `(<)
class_infix `has_append.append `(++)
class_infix `has_andthen `(;)
class_field `has_emptyc.emptyc `(∅)
class_infix `has_union.union `(∪)
class_infix `has_inter.inter `(∩)
class_infix `has_subset.subset `(⊆)
class_infix `has_ssubset.ssubset `(⊂)
class_infix `has_sdiff.sdiff `(\)
class_infix `has_equiv.equiv `(≈)
/-
Here we tie α to the carrier type.
But we might want to include into differently named carriers.
class something :=
(β : Type)
(has_sub (α = β))
-/
class has_sub := (α : Type) ((-) : α → α → α)
class has_div := (α : Type) ((/) : α → α → α)
class has_dvd := (α : Type) ((|) : α → α → Prop)
class has_mod := (α : Type) ((%) : α → α → α)
class has_le := (α : Type) ((≤) : α → α → Prop)
class has_lt := (α : Type) ((<) : α → α → Prop)
class has_append := (α : Type) ((++) : α → α → α)
class has_andthen := (α : Type) (β : Type) (σ : Type) ((;) : α → β → σ)
class has_union := (α : Type) ((∪) : α → α → α)
class has_inter := (α : Type) ((∩) : α → α → α)
class has_sdiff := (α : Type) ((\) : α → α → α)
class has_equiv := (α : Sort) ((≈) : α → α → Prop)
class has_subset := (α : Type) ((⊆) : α → α → Prop)
class has_ssubset := (α : Type) ((⊂) : α → α → Prop)
class has_subset :=
(has_subset)
(has_ssubset)
((⊂) :≡ λ a a', (a ⊆ a' ∧ ¬ (a' ⊆ a)))
/- polymorphic notation for collections.
Example: {a, b, c}. -/
class has_emptyc := (α : Type) (emptyc : α)
class has_insert := (α : Type) (γ : Type) := (insert : α → γ → γ)
class has_mem := (α : Type) (β : Type) ((∈) : α → β → Prop)
notation a ∉ s := ¬ has_mem.mem a s
/- repetition of earlier declaration, adding derived fields
Might use += notation. -/
class has_mem :=
(has_mem)
(has_subset (renaming α → β))
((⊆) :≡ λ b b', ∀ (x : α ), x ∈ b → x ∈ b')
/- Type class used to implement the notation { a ∈ c | p a } -/
class has_sep := (α : Type) (γ : Type) (sep : (α → Prop) → γ → γ)
def set (α : Type) := α → Prop
def set_of {α : Type} (p : α → Prop) : set α := p
protected def set.mem (a : α) (s : set α) := s a
instance {α} (set α) : has_mem :=
{α := α, β := set α, (∈) := set.mem}
protected def set.sep (p : α → Prop) (s : set α) : set α :=
{a | a ∈ s ∧ p a}
instance {α} (set α): has_sep :=
{α := α, γ := set α, set.sep⟩
instance {α} (set α) : has_emptyc :=
⟨set α , (λ a, false) ⟩
def univ : set α := λ a, true
protected def set.insert (a : α) (s : set α) : set α :=
{b | b = a ∨ b ∈ s}
instance {α} (set α) : has_insert :=
⟨set α, set.insert⟩
protected def set.union (s₁ s₂ : set α) : set α :=
{a | a ∈ s₁ ∨ a ∈ s₂}
instance {α} (set α) : set.has_union :=
⟨set α, set.union⟩
protected def set.inter (s₁ s₂ : set α) : set α :=
{a | a ∈ s₁ ∧ a ∈ s₂}
instance {α} (set α) : set.has_inter :=
⟨set α, set.inter⟩
def compl (s : set α) : set α :=
{a | a ∉ s}
instance {α} (set α) : has_neg :=
⟨set α, compl⟩
protected def diff (s t : set α) : set α :=
{a ∈ s | a ∉ t}
instance {α} (set α) : has_sdiff :=
⟨set α, set.diff⟩
def powerset (s : set α) : set (set α) :=
{t | t ⊆ s}
prefix `𝒫`:100 := powerset
@[reducible]
def sUnion (s : set (set α)) : set α := {t | ∃ a ∈ s, t ∈ a}
prefix `⋃₀`:110 := sUnion
def image (f : α → β) (s : set α) : set β :=
{b | ∃ a, a ∈ s ∧ f a = b}
/-
Using 1 as a field name in structures is problematic,
because the natural numbers are used to name the projections:
semigroup.1 is the first field of the semigroup structure.
We need a notational way to distinguish them. Say
semigroup.(1) (field name) vs. semigroup.1 (first field)
The class_* records the hidden name that is used for the
field, `mul `one `inv, etc.
Elaboration is expected to replace each ` * ` with the
appropriate instance R.mul, where R has upcast to has_mul
Field must have exact name match,
and the class must have upcast to has_mul (e.g.)
Special notation does not survive renaming of fields.
-/
class_infixl `has_mul.mul `( * ):70
class_field `has_one.one `( 1 )
class_postfix `has_inv.inv `( ⁻¹ ):70
class_infixl `has_add.add `( + ):70
class_fix `has_zero.zero `( 0 )
class_prefix `has_neg.neg `( - ):70 -- unary
class_infix `has_le.le `( ≤ ):50
class_infix `has_le.lt `( < ):50
/- We might have to choose non-generic names α and β
for fields because they effectively become global
names for algebraic structure carriers. -/
structure has_mul :=
(α : Type)
( ( * ) : α → α → α )
structure semigroup :=
(has_mul)
(mul_assoc : ∀ a b c : α, a * b * c = a * (b * c))
structure has_one :=
(α : Type)
( ( 1 ) : α)
structure monoid :=
(semigroup)
(has_one)
(one_mul : ∀ a : α, 1 * a = a)
(mul_one : ∀ a : α, a * 1 = a)
structure has_inv :=
(α : Type)
( ( ⁻¹ ) : α → α )
structure group :=
(monoid)
(has_inv)
(mul_left_inv : ∀ a : α, a⁻¹ * a = 1)
/-
"abelian" is a mixin for semigroup.
-/
structure abelian :=
(semigroup)
(mul_comm : ∀ (a b : α), a * b = b * a)
-- additive structures
structure has_add :=
(α : Type)
( ( + ) : α → α → α)
structure has_zero :=
(α : Type)
( ( 0 ) : α)
structure has_neg :=
(α : Type)
( ( - ) : α → α)
/-
We must not prove any theorems about add_monoid.
We use the upcast to monoid to use all its theorems.
-/
structure add_monoid :=
(has_add)
(has_zero)
(monoid + abelian
(renaming
( * ) -> ( + ),
( 1 ) -> ( 0 ),
mul_assoc -> add_assoc,
one_mul -> zero_add,
mul_one -> add_zero,
mul_comm -> add_comm
))
/-
add_group repeats add_monoid renamings,
but we tolerate repetition, because renaming is infrequent.
-/
structure add_group :=
(has_neg)
(add_monoid)
(group + abelian
(renaming
( * ) -> ( + ),
( 1 ) -> ( 0 ),
mul_assoc -> add_assoc,
one_mul -> zero_add,
mul_one -> add_zero,
mul_comm -> add_comm
( ⁻¹ ) -> ( - )
(mul_left_inv -> add_left_inv)
(group -> add_group)
))
structure semiring :=
(monoid)
(add_monoid)
(left_distrib : ∀ a b c : α, a * (b + c) = (a * b) + (a * c))
(right_distrib : ∀ a b c : α, (a + b) * c = (a * c) + (b * c))
(zero_mul : ∀ a : α, 0 * a = 0)
(mul_zero : ∀ a : α, a * 0 = 0)
structure commutative :=
(semiring)
(mul_comm : ∀ a b : α, a * b = b * a)
structure ring :=
(semiring)
(add_group)
structure integral_domain :=
(ring + commutative)
(zero_ne_one : 0 ≠ (1:α))
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0)
structure division_ring :=
(ring)
( ( ⁻¹ ) : α → α )
(zero_ne_one : 0 ≠ (1:α))
(mul_inv_cancel : ∀ {a : α}, a ≠ 0 → a * a⁻¹ = 1)
(inv_mul_cancel : ∀ {a : α}, a ≠ 0 → a⁻¹ * a = 1)
/-
qed box ▢ "\sqo" has the facetious meaning "quite easily done".
It marks true statements that are to be filled in by automation or the user.
Internally, it means sorry.
-/
/-
If there are two identical fields, the parser should remove duplicates.
For prop fields, it should keep one that provides a proof, if one exists, and
retain its given position among fields.
-/
structure field :=
(division_ring)
(integral_domain)
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0 := ▢ )
-- modules
class_infixl `scalar ` • `:73
class has_scalar :=
(scalar : Type)
(car : Type)
( ( • ) : scalar → car → car)
/-
We pull the ring out as a parameter because mathematicians
do when they write "R-module".
α := R.α creates definitional equality.
-/
class module (R : ring) :=
(has_scalar)
(α := R.α)
(add_group (renaming α -> β ))
(smul_left_distrib : ∀r (x y : β), r • (x + y) = r • x + r • y)
(smul_right_distrib : ∀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)
/-
We don't need a separate definition of vector_space.
Upcasting occurs to allow us to write module F.
variables (F : field) (V : module F)
-/
/- order structures -/
/-
The symbol :≡ marks a static (immutable) field.
-/
structure has_le :=
(α : Type)
( ( ≤ ) : α → α → Prop)
( ( < ) :≡ λ a b, a ≤ b ∧ ¬ b ≤ a)
structure preorder :=
(has_le)
(le_refl : ∀ a : α, a ≤ a)
(le_trans : ∀ a b c : α, a ≤ b → b ≤ c → a ≤ c)
structure partial_order :=
(preorder)
(le_antisymm : ∀ a b : α, a ≤ b → b ≤ a → a = b)
structure linear_order :=
(partial_order)
(le_total : ∀ a b : α, a ≤ b ∨ b ≤ a)
structure ordered_cancel_add_monoid :=
(add_monoid)
(partial_order)
(add_left_cancel : ∀ a b c : α, a + b = a + c → b = c)
(add_right_cancel : ∀ a b c : α, a + b = c + b → a = c := ▢ )
(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)
structure ordered_add_group :=
(ordered_cancel_add_monoid)
(add_group)
(mul_lt_mul_left : ∀ a b : α, a < b → ∀ c : α, c + a < c + b)
/- No separate definition is necessary for linear_order mixin.
For this to work smoothly, an upcast to target A
needs to extend automatically to target A + mixins.
-/
/-
structure linear_ordered_add_group := (ordered_add_group + linear_order)
structure linear_ordered_cancel_add_monoid :=
(ordered_cancel_add_monoid + linear_order)
-/
structure ordered_semiring :=
(semiring)
(ordered_cancel_add_monoid)
(mul_le_mul_of_nonneg_left: ∀ a b c : α, a ≤ b → 0 ≤ c → c * a ≤ c * b)
(mul_le_mul_of_nonneg_right: ∀ a b c : α, a ≤ b → 0 ≤ c → a * c ≤ b * c)
(mul_lt_mul_of_pos_left: ∀ a b c : α, a < b → 0 < c → c * a < c * b)
(mul_lt_mul_of_pos_right: ∀ a b c : α, a < b → 0 < c → a * c < b * c)
structure linear_ordered_semiring :=
(ordered_semiring)
(linear_order)
(zero_lt_one : zero < one)
structure ordered_ring :=
(ring)
(ordered_add_group)
(ordered_semiring) -- redundant, but adds it to the hierarchy.
(zero_ne_one : 0 ≠ (1:α))
(mul_nonneg : ∀ a b : α, 0 ≤ a → 0 ≤ b → 0 ≤ a * b)
(mul_pos : ∀ a b : α, 0 < a → 0 < b → 0 < a * b)
(mul_le_mul_of_nonneg_left:= ▢ )
(mul_le_mul_of_nonneg_right:= ▢ )
(mul_lt_mul_of_pos_left:= ▢ )
(mul_lt_mul_of_pos_right:= ▢ )
class linear_ordered_ring :=
(linear_ordered_semiring)
(ordered_ring)
/-
linear_ordered_comm_ring, is replaced with
linear_ordered_ring + commutative.
-/
class linear_ordered_field :=
(linear_ordered_ring)
(field)
-- powers
class_infixr `has_pow_nat.pow_nat `pow ` ^ `:70
/-
XX We meed to introduce natural numbers, integers,
and associated notation and operations here.
-/
class has_pow_nat :=
(α : Type)
( ( ^ ) : α → ℕ → α)
class has_pow_int :=
(α : Type)
(pow_int : α → ℤ → α)
def monoid.pow (monoid M) (a : M.α) : ℕ → α
| 0 := 1
| (n+1) := a * monoid.pow n
/-
We allow conservative extensions of the class.
In this case we are adding has_pow_nat to the hierarchy.
It also propagates automatically to a field of descendants.
Handling of "this": when inside the class declaration,
"this" becomes an implicit argument, so that
monoid.pow _ a n becomes monoid.pow a n.
-/
class monoid :=
(monoid)
(has_pow_nat)
( ( ^ ) :≡ λ a n, monoid.pow a n)
/-
-[1+n] is an abbreviation in Official-Lean.
-/
def gpow (a : α) : ℤ → α
| (of_nat n) := a^n
| -[1+n] := (a^(nat.succ n))⁻¹
/-
Lattices
-/
class_field `has_top.top ` ⊤ `
class_field `has_bot.bot ` ⊥ `
class_infixl `has_inf.inf ` ⊓ `:70
class_infixl `has_sup.sup ` ⊔ `:65
structure has_top :=
(α : Type)
( ( ⊤ ) : α)
structure has_bot :=
(α : Type)
( ( ⊥ ) : α)
structure has_inf :=
(α : Type)
( ( ⊓ ) : α → α → α)
structure has_sup :=
(α : Type)
( ( ⊔ ) : α → α → α)
-- class has_imp (α : Type u) := (imp : α → α → α) /- Better name -/
structure order_top :=
(has_top)
(partial_order)
(le_top : ∀ a : α, a ≤ ⊤)
structure order_bot :=
(has_bot)
(partial_order)
(bot_le : ∀ a : α, ⊥ ≤ a)
structure semilattice_sup :=
(has_sup)
(partial_order)
(le_sup_left : ∀ a b : α, a ≤ a ⊔ b)
(le_sup_right : ∀ a b : α, b ≤ a ⊔ b)
(sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c)
structure semilattice_inf :=
(has_inf)
(partial_order)
(inf_le_left : ∀ a b : α, a ⊓ b ≤ a)
(inf_le_right : ∀ a b : α, a ⊓ b ≤ b)
(le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c)
structure semilattice_sup_top :=
(order_top)
(semilattice_sup)
structure semilattice_sup_bot :=
(order_bot)
(semilattice_sup)
structure semilattice_inf_top :=
(order_top)
(semilattice_inf)
structure semilattice_inf_bot :=
(order_bot)
(semilattice_inf)
structure lattice :=
(semilattice_sup)
(semilattice_inf)
def galois_connection (A : preorder) (B : preorder)
(l : A.α → B.α) (u : B.α → A.α) := ∀a b, l a ≤ b ↔ a ≤ u b
|
00d8758983da9cb1437b28c4c0a0aaba56de7513 | d0f9af2b0ace5ce352570d61b09019c8ef4a3b96 | /notes/2020.01.28-identifiers.lean | 70f4f2b25f0adfd0ac2fddcc682a7166a6eaddb8 | [] | no_license | jngo13/Discrete-Mathematics | 8671540ef2da7c75915d32332dd20c02f001474e | bf674a866e61f60e6e6d128df85fa73819091787 | refs/heads/master | 1,675,615,657,924 | 1,609,142,011,000 | 1,609,142,011,000 | 267,190,341 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,078 | lean | def z := nat.zero
#eval z
-- Bind identifer bool_true to term, tt, for Boolean true
def bool_true := tt
-- Bind the name, a_string, to the string, "I love logic!"
def a_string := "I love logic!"
#eval a_string
a_string = "logic is cool"
#eval a_string
def z' : ℕ := (nat.zero : ℕ)
def z'' := (nat.zero : ℕ)
def z''' : ℕ := nat.zero
def z := 0
-- If you want a rational or real, you'd have to say so
def q := (0 : ℚ)
def r := (0 : ℝ)
def z := (0 : ℤ)
def b := tt
#eval b
def s := "exercise"
#eval s
--Func Notes
-- Function expression are terms that have types
#check band
#check nat.add
#check string.append
-- Function application expressions are terms that have types
#check band tt tt
#check nat.add 2 3
#check string.append "I love " "logic!"
-- Function application expessions reduce to return values
#eval band tt tt
#eval nat.add 2 3
#eval string.append "I love " "logic!"
-- Lean strictly and statically enforces typing
#check band ff "Hi!"
#check nat.add 4 tt
#eval string.append "I love " 5 -- strange error, same problem
#check bor tt tt |
d4d012daf5879c2ba9db6f0ee825ae8a2082d850 | 6fbf10071e62af7238f2de8f9aa83d55d8763907 | /answers/practice-exam2-key.lean | 832e2622b0493faf311a8d3fca44f72d4ccbbf36 | [] | no_license | HasanMukati/uva-cs-dm-s19 | ee5aad4568a3ca330c2738ed579c30e1308b03b0 | 3e7177682acdb56a2d16914e0344c10335583dcf | refs/heads/master | 1,596,946,213,130 | 1,568,221,949,000 | 1,568,221,949,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 14,425 | lean |
/-
Conjunctions, disjunctions, implication, iff,
negation
-/
/-
1. Prove that 3 + 3 = 6 and 2 + 6 = 8 implies
that 1 + 1 = 2.
-/
-- answer:
example: 3 + 3 = 6 ∧ 2 + 6 = 8 → 1 + 1 = 2
:=
begin
assume pf_conj,
exact rfl,
end
/-
2. Prove that 2 + 5 = 3 or 9 + 1 = 5 implies
that 2 + 3 = 9.
-/
-- answer:
example: 2 + 5 = 3 ∨ 9 + 1 = 5 → 2 + 3 = 9
:=
begin
assume pf_disj,
cases pf_disj with left right,
-- 2 + 5 = 0
/-
have pf_contra: 2 + 5 ≠ 0 :=
begin
apply nat.no_confusion,
end,
contradiction,
-/
cases left,
-- 9 + 1 = 0
/-
have pf_contra: 9 + 1 ≠ 0 :=
begin
apply nat.no_confusion,
end,
contradiction,
-/
cases right,
end
/-
3. Prove that ¬(A ∧ B ∧ C) ↔ (¬A ∨ ¬B ∨ ¬C).
You may use the axiom of the excluded middle.
-/
axiom em: ∀(P: Prop), P ∨ ¬P
-- answer:
example: ∀(A B C: Prop),
¬(A ∧ B ∧ C) ↔ (¬A ∨ ¬B ∨ ¬C) :=
begin
assume P Q R,
split,
-- ¬(P ∧ Q ∧ R) → ¬P ∨ ¬Q ∨ ¬R
assume pf_not_conj,
cases (em P) with pf_p pf_not_p,
cases (em Q) with pf_q pf_not_q,
cases (em R) with pf_r pf_not_r,
-- P ∧ Q ∧ R
have pf_conj: P ∧ Q ∧ R := ⟨pf_p, ⟨pf_q, pf_r⟩⟩,
contradiction,
-- ¬R
exact or.inr (or.inr pf_not_r),
-- ¬Q
exact or.inr (or.inl pf_not_q),
-- ¬P
exact or.inl pf_not_p,
/-
Think about what we just proved and how we proved
it. The em principle allowed us to consider two cases
for each of P, Q, and R. In case any one of them is
false, the an ease "or introduction" will prove the
goal. In the case all of them are true, well, that
contradicts the assumption, and (using false elim)
we can ignore cases with contradictory assumptions
because they can't actually happen.
-/
-- ¬P ∨ ¬Q ∨ ¬R → ¬(P ∧ Q ∧ R)
assume pf_disj_not,
assume pf_conj,
cases pf_disj_not with pf_not_p pf_disj_not,
-- ¬P
have pf_p := pf_conj.left,
contradiction,
-- ¬Q ∨ ¬R
cases pf_disj_not with pf_not_q pf_not_r,
-- ¬Q
have pf_q := pf_conj.right.left,
contradiction,
-- ¬R
have pf_r := pf_conj.right.right,
contradiction,
/-
In this case, we've assumed all of P, Q, and R
are true. In this context, the assumption that at
least one of them is false is contradictory. What
the proof script confirms is that this intuition
can be proved formally.
-/
end
/-
4. Prove that ¬(A ∨ B ∨ C) ↔ (¬A ∧ ¬B ∧ ¬C).
You may *NOT* use the axiom of the excluded middle.
-/
-- answer:
example: ∀(A B C: Prop),
¬(A ∨ B ∨ C) ↔ (¬A ∧ ¬B ∧ ¬C) :=
begin
intros,
split,
-- ¬(A ∨ B ∨ C) → ¬A ∧ ¬B ∧ ¬C
assume pf_not_disj,
split,
-- ¬A
assume pf_A,
/-
Here again the key insight is that from a proof
of just A we can construct proof of a contradiction
that directly contradicts an assumption, at which
point we have shown that this case can be dismissed
using false elimination (via the contradiction tactic).
-/
have pf_disj: A ∨ B ∨ C :=
or.inl pf_A,
contradiction,
split, -- short for apply and.intro _ _,
-- ¬B
assume pf_B,
-- same trick
have pf_disj: A ∨ B ∨ C :=
or.inr (or.inl pf_B),
contradiction,
-- ¬C
assume pf_C,
-- same trick
have pf_disj: A ∨ B ∨ C :=
or.inr (or.inr pf_C),
contradiction,
-- ¬A ∧ ¬B ∧ ¬C → ¬(A ∨ B ∨ C)
assume pf_conj_not,
assume pf_disj,
-- each one false + at least one true = contradiction
cases pf_disj with pf_A pf_disj,
-- A
-- basically same trick: expose direct contradition
have pf_not_A := pf_conj_not.left,
contradiction,
-- repeat until done
cases pf_disj with pf_B pf_C,
-- B
have pf_not_B := pf_conj_not.right.left,
contradiction,
-- C
have pf_not_C := pf_conj_not.right.right,
contradiction,
end
/-
5a. Prove that ¬(A ∨ ¬B) ↔ (¬A ∧ B).
You may use the axiom of the excluded middle.
-/
-- answer:
example: ∀(A B: Prop),
¬(A ∨ ¬B) ↔ (¬A ∧ B) :=
begin
assume X Y,
split, -- short for "apply IFF.intro _ _"
-- ¬(X ∨ ¬Y) → ¬X ∧ Y
assume pf_not_disj,
split, -- short for "apply AND.intro _ _"
-- ¬X
assume pf_X,
-- here's that same trick again
have pf_disj: X ∨ ¬Y := or.inl pf_X,
contradiction,
-- Y
/-
Case analysis on (Y ∨ ¬ Y). Think about the two
cases before proceeding "blindly". In the case that
Y is true, then the goal is proved. What happens in
the case where Y is false? Yep: that's a contradiction,
which you can expose with the same trick we've seen
several times here already.
-/
cases (em Y) with pf_Y pf_not_Y,
-- Y,
assumption,
-- ¬Y
have pf_disj: X ∨ ¬Y := or.inr pf_not_Y,
contradiction,
-- ¬X ∧ Y → ¬(X ∨ ¬Y)
assume pf_not_X_and_Y,
assume pf_X_or_not_Y,
cases pf_X_or_not_Y with pf_X pf_not_Y,
-- X
have pf_not_X := pf_not_X_and_Y.left,
contradiction,
-- ¬Y
have pf_Y := pf_not_X_and_Y.right,
contradiction,
end
/-
5b. Prove that ¬(A ∧ ¬B) ↔ (¬A ∨ B).
You may use the axiom of the excluded middle.
-/
-- answer:
example: ∀(A B: Prop),
¬(A ∧ ¬B) ↔ (¬A ∨ B) :=
begin
intros,
split,
-- ¬(A ∧ ¬B) → ¬A ∨ B
assume pf_not_conj,
/-
At this point there's nothing we can do *unless*
we use excluded middle to consider only two cases,
one where we have a proof that A is true and one
where we have a proof that it is not true. Then we
do the same kind of case analysis for B. In effect
we're *just looking at the truth table*. There are
four cases: A true, B true; A true, A false; B true,
A false; B false. Before proceeding, just think
about what happens in each case. Write out the
truth table.
-/
cases (em A) with pf_A pf_not_A,
-- A
cases (em B) with pf_B pf_not_B,
-- B
exact or.inr pf_B,
-- ¬B
-- here's that trick again!
have pf_conj: A ∧ ¬B := ⟨pf_A, pf_not_B⟩,
contradiction,
-- ¬A
exact or.inl pf_not_A,
-- ¬A ∨ B → ¬(A ∧ ¬B)
assume pf_disj,
assume pf_conj,
/-
Look at and *think about* what's in the context.
You must be able to reason logically at this point.
If ¬ A or B is true, it is true because at least one
of them is true. If ¬ A is true, that contradicts the
other assumption, that both A and ¬ B are true. If B
is true, on the other hand, that's also a contradiction.
-/
cases pf_disj with pf_not_A pf_B,
-- ¬A
have pf_A := pf_conj.left,
contradiction,
-- B
have pf_not_B := pf_conj.right,
contradiction,
end
/-
6. Prove that ¬P ∨ ¬Q ∨ R is true if and only
if P → Q → R. You may use the axiom of the
excluded middle.
-/
-- answer:
example: ∀(P Q R: Prop),
(¬P ∨ ¬Q ∨ R) ↔ (P → Q → R) :=
begin
intros,
split,
-- ¬P ∨ ¬Q ∨ R → (P → Q → R)
assume pf_disj,
assume pf_P,
assume pf_Q,
/-
Beyond just mechanically applying tactics,
stop now and think about what you've got. As
a mathematician, you want to start to "look
ahead" to see "what will happen" if you try
different approaches. Here, for example, you
can see that if the disjunction is true because
¬ P is true, that will immediately give you a
contradiction that you can use to be done with
that case. Think ahead about the other case.
Start to see beyond the current instant, to
see what's coming if you take certain paths.
-/
cases pf_disj with pf_not_P pf_disj,
-- ¬P
contradiction,
cases pf_disj with pf_not_Q pf_R,
-- ¬Q
contradiction,
-- R
assumption,
-- (P → Q → R) → ¬P ∨ ¬Q ∨ R
assume pf_impl,
/-
There's no way forward constructively.
But if we can assume that there are only
two possible cases for P, Q, and R, then
we can just consider each case in turn,
again using what amounts to the method
of "truth tables".
-/
cases (em P) with pf_P pf_not_P,
-- P
/-
Right here you use another absolutely (!!)
fundamental insight. If you have a proof
of an implication and you have a proof of
its premise you can derive a proof of its
conclusion. In constructive logic this is
done by "applying" the implication proof
(a function!) to the premise proof (a valid
argument).
-/
have pf_Q_to_R := pf_impl pf_P,
cases (em Q) with pf_Q pf_not_Q,
-- Q
have pf_R := pf_Q_to_R pf_Q,
/-
We have a proof of R and now only
need to prove a disjunction in which
R is one of the disjunctions. You have
to understand the associativity of ∨.
It's right associative.
-/
exact or.inr (or.inr pf_R),
-- ¬Q
exact or.inr (or.inl pf_not_Q),
-- ¬P
exact or.inl pf_not_P,
end
/-
7. Prove that ¬¬¬P → ¬P. You may use the axiom
of the excluded middle.
-/
-- answer:
example: ∀(P: Prop), ¬¬¬P → ¬P :=
begin
assume P,
assume pf_trip_neg,
assume pf_P,
/-
How to proceed here is a little tricky. A key
insight is that you can apply em to whatever
proposition you want, to get a proof that is is
either true or a proof that it is false. Here,
applying em to ¬ P does the trick. Think ahead
to see if you can see why. Then *confirm* what
you see by going through the proof script.
-/
cases (em ¬P) with pf_not_P pf_nn_P,
-- ¬P
contradiction, -- contradicts P
-- ¬¬P
contradiction, -- contradicts ¬¬¬P
end
/-
Universal Quantifiers, Existential Quantifiers, and
Satisfiability.
-/
/-
8. Prove the following statements are satisfiable
or prove that they are not. You may use the axiom
of the excluded middle to prove cases where the
statements are not satisfiable.
-/
/-
8a. (P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q)
-/
/-
Note: Problems that start with ∃ are basically
search problems: you have to "searcg for, find,
and then use a witness that makes the proposition
true." In the worse case, use a truth table. That
is the way to systematically consider all possible
solutions. A problem with two "variables" will have
only four cases to consider. You can of course try
a value, and if you get stuck, "backtrack" (go back
and change your choice then try going forward again).
Also note that ∃(P Q: Prop), _ is short for
∃( P : Prop), ∃ (Q : Prop), _.
-/
-- answer:
example: ∃(P Q: Prop),
(P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q) :=
begin
apply exists.intro true,
apply exists.intro true,
split,
-- P ∨ Q
exact or.inl true.intro,
split,
-- ¬P ∨ Q
exact or.inr true.intro,
-- P ∨ ¬Q
exact or.inl true.intro,
end
/-
8b. (P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q) ∧ (¬P ∨ ¬Q)
-/
-- answer:
example: ¬∃(P Q: Prop),
(P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q) ∧ (¬P ∨ ¬Q) :=
begin
assume pf_exists,
apply exists.elim pf_exists,
assume P pf_w',
apply exists.elim pf_w',
assume Q pf_w,
cases (em P) with pf_P pf_not_P,
cases (em Q) with pf_Q pf_not_Q,
-- P, Q
have pf_not_P_or_not_Q := pf_w.right.right.right,
cases pf_not_P_or_not_Q with pf_not_P pf_not_Q,
contradiction, contradiction,
-- P, ¬Q
have pf_not_P_or_Q := pf_w.right.left,
cases pf_not_P_or_Q with pf_not_P pf_Q,
contradiction, contradiction,
cases (em Q) with pf_Q pf_not_Q,
-- ¬P, Q
have pf_P_or_not_Q := pf_w.right.right.left,
cases pf_P_or_not_Q with pf_P pf_not_Q,
contradiction, contradiction,
-- ¬P, ¬Q
have pf_P_or_Q := pf_w.left,
cases pf_P_or_Q with pf_P pf_Q,
contradiction, contradiction,
end
/-
8c. (P ∨ Q ∨ R) ∧ (¬P ∨ Q ∨ R) ∧
(P ∨ ¬Q ∨ ¬R) ∧ (¬P ∨ ¬Q ∨ ¬R)
-/
-- answer:
example: ∃(P Q R: Prop),
(P ∨ Q ∨ R) ∧ (¬P ∨ Q ∨ R) ∧
(P ∨ ¬Q ∨ ¬R) ∧ (¬P ∨ ¬Q ∨ ¬R) :=
begin
apply exists.intro true,
apply exists.intro true,
apply exists.intro false,
split,
-- P ∨ Q ∨ R
exact or.inl true.intro,
split,
-- ¬P ∨ Q ∨ R
exact or.inr (or.inl true.intro),
split,
-- P ∨ ¬Q ∨ ¬R
exact or.inl true.intro,
-- ¬P ∨ ¬Q ∨ ¬R
exact or.inr (or.inr false.elim),
end
/-
9. Prove that exists a number such that
it is both even and a multiple of 3.
Use the supplied definitions of even and prime.
-/
def isEven(n: ℕ) := (∃(m: ℕ), m * 2 = n)
def isMult3(n: ℕ) := (∃(m: ℕ), m * 3 = n)
-- answer
example:
∃(n: ℕ), isEven n ∧ isMult3 n :=
begin
have isEven6: isEven 6 := ⟨3, rfl⟩, -- exists.intro
have isPrime6: isMult3 6 := ⟨2, rfl⟩, -- exists.intro
have both := and.intro isEven6 isPrime6,
exact ⟨6, both⟩, -- exists.intro
end
/-
10a. Write the lemma that if there exists
someone that you can fool all of the time,
then there always exists someone you can fool.
Use the supplied axioms, and make sure you use
at least as many parentheses as needed. (It's
okay to use more than you need.)
10b. Prove the above lemma.
Note that this problem really requires that
you be able not only to prove but to write
propositions involving several quantifiers,
translating from English into the correct
logical formalism.
-/
axioms Person Time: Type
axiom fool: Person → Time → Prop
-- answers:
example:
(∃(p: Person), ∀ (t: Time), fool p t) →
(∀(t: Time), ∃(p: Person), fool p t) :=
begin
assume pfIdiotExists,
assume t,
apply exists.elim pfIdiotExists,
assume witness pf_witness,
have pfCurIdiot := pf_witness t,
exact ⟨witness, pfCurIdiot⟩,
end
|
2be32d7b22f5ebd2f966d7d7c6d2ac505920e24f | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/endofunctor/algebra.lean | 436f6db1bc61652b55cb2c80bbb12881468bf0b4 | [
"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 | 16,954 | lean | /-
Copyright (c) 2022 Joseph Hua. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta, Johan Commelin, Reid Barton, Rob Lewis, Joseph Hua
-/
import category_theory.functor.reflects_isomorphisms
import category_theory.limits.shapes.terminal
/-!
# Algebras of endofunctors
This file defines (co)algebras of an endofunctor, and provides the category instance for them.
It also defines the forgetful functor from the category of (co)algebras. It is shown that the
structure map of the initial algebra of an endofunctor is an isomorphism. Furthermore, it is shown
that for an adjunction `F ⊣ G` the category of algebras over `F` is equivalent to the category of
coalgebras over `G`.
## TODO
* Prove the dual result about the structure map of the terminal coalgebra of an endofunctor.
* Prove that if the countable infinite product over the powers of the endofunctor exists, then
algebras over the endofunctor coincide with algebras over the free monad on the endofunctor.
-/
universes v u
namespace category_theory
namespace endofunctor
variables {C : Type u} [category.{v} C]
/-- An algebra of an endofunctor; `str` stands for "structure morphism" -/
structure algebra (F : C ⥤ C) :=
(A : C)
(str : F.obj A ⟶ A)
instance [inhabited C] : inhabited (algebra (𝟭 C)) := ⟨⟨ default , 𝟙 _ ⟩⟩
namespace algebra
variables {F : C ⥤ C} (A : algebra F) {A₀ A₁ A₂ : algebra F}
/-
```
str
F A₀ -----> A₀
| |
F f | | f
V V
F A₁ -----> A₁
str
```
-/
/-- A morphism between algebras of endofunctor `F` -/
@[ext] structure hom (A₀ A₁ : algebra F) :=
(f : A₀.1 ⟶ A₁.1)
(h' : F.map f ≫ A₁.str = A₀.str ≫ f . obviously)
restate_axiom hom.h'
attribute [simp, reassoc] hom.h
namespace hom
/-- The identity morphism of an algebra of endofunctor `F` -/
def id : hom A A := { f := 𝟙 _ }
instance : inhabited (hom A A) := ⟨{ f := 𝟙 _ }⟩
/-- The composition of morphisms between algebras of endofunctor `F` -/
def comp (f : hom A₀ A₁) (g : hom A₁ A₂) : hom A₀ A₂ := { f := f.1 ≫ g.1 }
end hom
instance (F : C ⥤ C) : category_struct (algebra F) :=
{ hom := hom,
id := hom.id,
comp := @hom.comp _ _ _ }
@[simp] lemma id_eq_id : algebra.hom.id A = 𝟙 A := rfl
@[simp] lemma id_f : (𝟙 _ : A ⟶ A).1 = 𝟙 A.1 := rfl
variables {A₀ A₁ A₂} (f : A₀ ⟶ A₁) (g : A₁ ⟶ A₂)
@[simp] lemma comp_eq_comp : algebra.hom.comp f g = f ≫ g := rfl
@[simp] lemma comp_f : (f ≫ g).1 = f.1 ≫ g.1 := rfl
/-- Algebras of an endofunctor `F` form a category -/
instance (F : C ⥤ C) : category (algebra F) := {}
/--
To construct an isomorphism of algebras, it suffices to give an isomorphism of the As which
commutes with the structure morphisms.
-/
@[simps]
def iso_mk (h : A₀.1 ≅ A₁.1) (w : F.map h.hom ≫ A₁.str = A₀.str ≫ h.hom) : A₀ ≅ A₁ :=
{ hom := { f := h.hom },
inv :=
{ f := h.inv,
h' := by { rw [h.eq_comp_inv, category.assoc, ←w, ←functor.map_comp_assoc], simp } } }
/-- The forgetful functor from the category of algebras, forgetting the algebraic structure. -/
@[simps] def forget (F : C ⥤ C) : algebra F ⥤ C :=
{ obj := λ A, A.1,
map := λ A B f, f.1 }
/-- An algebra morphism with an underlying isomorphism hom in `C` is an algebra isomorphism. -/
lemma iso_of_iso (f : A₀ ⟶ A₁) [is_iso f.1] : is_iso f :=
⟨⟨{ f := inv f.1,
h' := by { rw [is_iso.eq_comp_inv f.1, category.assoc, ← f.h], simp } }, by tidy⟩⟩
instance forget_reflects_iso : reflects_isomorphisms (forget F) :=
{ reflects := λ A B, iso_of_iso }
instance forget_faithful : faithful (forget F) := {}
/-- An algebra morphism with an underlying epimorphism hom in `C` is an algebra epimorphism. -/
lemma epi_of_epi {X Y : algebra F} (f : X ⟶ Y) [h : epi f.1] : epi f :=
(forget F).epi_of_epi_map h
/-- An algebra morphism with an underlying monomorphism hom in `C` is an algebra monomorphism. -/
lemma mono_of_mono {X Y : algebra F} (f : X ⟶ Y) [h : mono f.1] : mono f :=
(forget F).mono_of_mono_map h
/--
From a natural transformation `α : G → F` we get a functor from
algebras of `F` to algebras of `G`.
-/
@[simps]
def functor_of_nat_trans {F G : C ⥤ C} (α : G ⟶ F) : algebra F ⥤ algebra G :=
{ obj := λ A,
{ A := A.1,
str := α.app A.1 ≫ A.str },
map := λ A₀ A₁ f,
{ f := f.1 } }
/-- The identity transformation induces the identity endofunctor on the category of algebras. -/
@[simps {rhs_md := semireducible}]
def functor_of_nat_trans_id :
functor_of_nat_trans (𝟙 F) ≅ 𝟭 _ :=
nat_iso.of_components
(λ X, iso_mk (iso.refl _) (by { dsimp, simp, }))
(λ X Y f, by { ext, dsimp, simp })
/-- A composition of natural transformations gives the composition of corresponding functors. -/
@[simps {rhs_md := semireducible}]
def functor_of_nat_trans_comp {F₀ F₁ F₂ : C ⥤ C} (α : F₀ ⟶ F₁) (β : F₁ ⟶ F₂) :
functor_of_nat_trans (α ≫ β) ≅
functor_of_nat_trans β ⋙ functor_of_nat_trans α :=
nat_iso.of_components
(λ X, iso_mk (iso.refl _) (by { dsimp, simp }))
(λ X Y f, by { ext, dsimp, simp })
/--
If `α` and `β` are two equal natural transformations, then the functors of algebras induced by them
are isomorphic.
We define it like this as opposed to using `eq_to_iso` so that the components are nicer to prove
lemmas about.
-/
@[simps {rhs_md := semireducible}]
def functor_of_nat_trans_eq {F G : C ⥤ C} {α β : F ⟶ G} (h : α = β) :
functor_of_nat_trans α ≅ functor_of_nat_trans β :=
nat_iso.of_components
(λ X, iso_mk (iso.refl _) (by { dsimp, simp [h] }))
(λ X Y f, by { ext, dsimp, simp })
/--
Naturally isomorphic endofunctors give equivalent categories of algebras.
Furthermore, they are equivalent as categories over `C`, that is,
we have `equiv_of_nat_iso h ⋙ forget = forget`.
-/
@[simps]
def equiv_of_nat_iso {F G : C ⥤ C} (α : F ≅ G) :
algebra F ≌ algebra G :=
{ functor := functor_of_nat_trans α.inv,
inverse := functor_of_nat_trans α.hom,
unit_iso :=
functor_of_nat_trans_id.symm ≪≫
functor_of_nat_trans_eq (by simp) ≪≫
functor_of_nat_trans_comp _ _,
counit_iso :=
(functor_of_nat_trans_comp _ _).symm ≪≫
functor_of_nat_trans_eq (by simp) ≪≫
functor_of_nat_trans_id }.
namespace initial
variables {A} (h : limits.is_initial A)
/-- The inverse of the structure map of an initial algebra -/
@[simp] def str_inv : A.1 ⟶ F.obj A.1 := (h.to ⟨ F.obj A.1 , F.map A.str ⟩).1
lemma left_inv' : (⟨str_inv h ≫ A.str⟩ : A ⟶ A) = 𝟙 A :=
limits.is_initial.hom_ext h _ (𝟙 A)
lemma left_inv : str_inv h ≫ A.str = 𝟙 _ := congr_arg hom.f (left_inv' h)
lemma right_inv : A.str ≫ str_inv h = 𝟙 _ :=
by { rw [str_inv, ← (h.to ⟨ F.obj A.1 , F.map A.str ⟩).h,
← F.map_id, ← F.map_comp], congr, exact (left_inv h) }
/--
The structure map of the inital algebra is an isomorphism,
hence endofunctors preserve their initial algebras
-/
lemma str_is_iso (h : limits.is_initial A) : is_iso A.str :=
{ out := ⟨ str_inv h, right_inv _ , left_inv _ ⟩ }
end initial
end algebra
/-- A coalgebra of an endofunctor; `str` stands for "structure morphism" -/
structure coalgebra (F : C ⥤ C) :=
(V : C)
(str : V ⟶ F.obj V)
instance [inhabited C] : inhabited (coalgebra (𝟭 C)) := ⟨⟨ default , 𝟙 _ ⟩⟩
namespace coalgebra
variables {F : C ⥤ C} (V : coalgebra F) {V₀ V₁ V₂ : coalgebra F}
/-
```
str
V₀ -----> F V₀
| |
f | | F f
V V
V₁ -----> F V₁
str
```
-/
/-- A morphism between coalgebras of an endofunctor `F` -/
@[ext] structure hom (V₀ V₁ : coalgebra F) :=
(f : V₀.1 ⟶ V₁.1)
(h' : V₀.str ≫ F.map f = f ≫ V₁.str . obviously)
restate_axiom hom.h'
attribute [simp, reassoc] hom.h
namespace hom
/-- The identity morphism of an algebra of endofunctor `F` -/
def id : hom V V := { f := 𝟙 _ }
instance : inhabited (hom V V) := ⟨{ f := 𝟙 _ }⟩
/-- The composition of morphisms between algebras of endofunctor `F` -/
def comp (f : hom V₀ V₁) (g : hom V₁ V₂) : hom V₀ V₂ := { f := f.1 ≫ g.1 }
end hom
instance (F : C ⥤ C) : category_struct (coalgebra F) :=
{ hom := hom,
id := hom.id,
comp := @hom.comp _ _ _ }
@[simp] lemma id_eq_id : coalgebra.hom.id V = 𝟙 V := rfl
@[simp] lemma id_f : (𝟙 _ : V ⟶ V).1 = 𝟙 V.1 := rfl
variables {V₀ V₁ V₂} (f : V₀ ⟶ V₁) (g : V₁ ⟶ V₂)
@[simp] lemma comp_eq_comp : coalgebra.hom.comp f g = f ≫ g := rfl
@[simp] lemma comp_f : (f ≫ g).1 = f.1 ≫ g.1 := rfl
/-- Coalgebras of an endofunctor `F` form a category -/
instance (F : C ⥤ C) : category (coalgebra F) := {}
/--
To construct an isomorphism of coalgebras, it suffices to give an isomorphism of the Vs which
commutes with the structure morphisms.
-/
@[simps]
def iso_mk (h : V₀.1 ≅ V₁.1) (w : V₀.str ≫ F.map h.hom = h.hom ≫ V₁.str ) : V₀ ≅ V₁ :=
{ hom := { f := h.hom },
inv :=
{ f := h.inv,
h' := by { rw [h.eq_inv_comp, ← category.assoc, ←w, category.assoc, ← functor.map_comp],
simp only [iso.hom_inv_id, functor.map_id, category.comp_id] } } }
/-- The forgetful functor from the category of coalgebras, forgetting the coalgebraic structure. -/
@[simps] def forget (F : C ⥤ C) : coalgebra F ⥤ C :=
{ obj := λ A, A.1,
map := λ A B f, f.1 }
/-- A coalgebra morphism with an underlying isomorphism hom in `C` is a coalgebra isomorphism. -/
lemma iso_of_iso (f : V₀ ⟶ V₁) [is_iso f.1] : is_iso f :=
⟨⟨{ f := inv f.1,
h' := by { rw [is_iso.eq_inv_comp f.1, ← category.assoc, ← f.h, category.assoc], simp } },
by tidy⟩⟩
instance forget_reflects_iso : reflects_isomorphisms (forget F) :=
{ reflects := λ A B, iso_of_iso }
instance forget_faithful : faithful (forget F) := {}
/-- An algebra morphism with an underlying epimorphism hom in `C` is an algebra epimorphism. -/
lemma epi_of_epi {X Y : coalgebra F} (f : X ⟶ Y) [h : epi f.1] : epi f :=
(forget F).epi_of_epi_map h
/-- An algebra morphism with an underlying monomorphism hom in `C` is an algebra monomorphism. -/
lemma mono_of_mono {X Y : coalgebra F} (f : X ⟶ Y) [h : mono f.1] : mono f :=
(forget F).mono_of_mono_map h
/--
From a natural transformation `α : F → G` we get a functor from
coalgebras of `F` to coalgebras of `G`.
-/
@[simps]
def functor_of_nat_trans {F G : C ⥤ C} (α : F ⟶ G) : coalgebra F ⥤ coalgebra G :=
{ obj := λ V,
{ V := V.1,
str := V.str ≫ α.app V.1 },
map := λ V₀ V₁ f, { f := f.1,
h' := by rw [category.assoc, ← α.naturality, ← category.assoc, f.h, category.assoc] } }
/-- The identity transformation induces the identity endofunctor on the category of coalgebras. -/
@[simps {rhs_md := semireducible}]
def functor_of_nat_trans_id :
functor_of_nat_trans (𝟙 F) ≅ 𝟭 _ :=
nat_iso.of_components
(λ X, iso_mk (iso.refl _) (by { dsimp, simp, }))
(λ X Y f, by { ext, dsimp, simp })
/-- A composition of natural transformations gives the composition of corresponding functors. -/
@[simps {rhs_md := semireducible}]
def functor_of_nat_trans_comp {F₀ F₁ F₂ : C ⥤ C} (α : F₀ ⟶ F₁) (β : F₁ ⟶ F₂) :
functor_of_nat_trans (α ≫ β) ≅
functor_of_nat_trans α ⋙ functor_of_nat_trans β :=
nat_iso.of_components
(λ X, iso_mk (iso.refl _) (by { dsimp, simp }))
(λ X Y f, by { ext, dsimp, simp })
/--
If `α` and `β` are two equal natural transformations, then the functors of coalgebras induced by
them are isomorphic.
We define it like this as opposed to using `eq_to_iso` so that the components are nicer to prove
lemmas about.
-/
@[simps {rhs_md := semireducible}]
def functor_of_nat_trans_eq {F G : C ⥤ C} {α β : F ⟶ G} (h : α = β) :
functor_of_nat_trans α ≅ functor_of_nat_trans β :=
nat_iso.of_components
(λ X, iso_mk (iso.refl _) (by { dsimp, simp [h] }))
(λ X Y f, by { ext, dsimp, simp })
/--
Naturally isomorphic endofunctors give equivalent categories of coalgebras.
Furthermore, they are equivalent as categories over `C`, that is,
we have `equiv_of_nat_iso h ⋙ forget = forget`.
-/
@[simps]
def equiv_of_nat_iso {F G : C ⥤ C} (α : F ≅ G) :
coalgebra F ≌ coalgebra G :=
{ functor := functor_of_nat_trans α.hom,
inverse := functor_of_nat_trans α.inv,
unit_iso :=
functor_of_nat_trans_id.symm ≪≫
functor_of_nat_trans_eq (by simp) ≪≫
functor_of_nat_trans_comp _ _,
counit_iso :=
(functor_of_nat_trans_comp _ _).symm ≪≫
functor_of_nat_trans_eq (by simp) ≪≫
functor_of_nat_trans_id }.
end coalgebra
namespace adjunction
variables {F : C ⥤ C} {G : C ⥤ C}
lemma algebra.hom_equiv_naturality_str (adj : F ⊣ G) (A₁ A₂ : algebra F)
(f : A₁ ⟶ A₂) : (adj.hom_equiv A₁.A A₁.A) A₁.str ≫ G.map f.f =
f.f ≫ (adj.hom_equiv A₂.A A₂.A) A₂.str :=
by { rw [← adjunction.hom_equiv_naturality_right, ← adjunction.hom_equiv_naturality_left, f.h] }
lemma coalgebra.hom_equiv_naturality_str_symm (adj : F ⊣ G) (V₁ V₂ : coalgebra G)
(f : V₁ ⟶ V₂) : F.map f.f ≫ ((adj.hom_equiv V₂.V V₂.V).symm) V₂.str =
((adj.hom_equiv V₁.V V₁.V).symm) V₁.str ≫ f.f :=
by { rw [← adjunction.hom_equiv_naturality_left_symm, ← adjunction.hom_equiv_naturality_right_symm,
f.h] }
/-- Given an adjunction `F ⊣ G`, the functor that associates to an algebra over `F` a
coalgebra over `G` defined via adjunction applied to the structure map. -/
def algebra.to_coalgebra_of (adj : F ⊣ G) : algebra F ⥤ coalgebra G :=
{ obj := λ A, { V := A.1,
str := (adj.hom_equiv A.1 A.1).to_fun A.2 },
map := λ A₁ A₂ f, { f := f.1,
h' := (algebra.hom_equiv_naturality_str adj A₁ A₂ f) } }
/-- Given an adjunction `F ⊣ G`, the functor that associates to a coalgebra over `G` an algebra over
`F` defined via adjunction applied to the structure map. -/
def coalgebra.to_algebra_of (adj : F ⊣ G) : coalgebra G ⥤ algebra F :=
{ obj := λ V, { A := V.1,
str := (adj.hom_equiv V.1 V.1).inv_fun V.2 },
map := λ V₁ V₂ f, { f := f.1,
h' := (coalgebra.hom_equiv_naturality_str_symm adj V₁ V₂ f) } }
/-- Given an adjunction, assigning to an algebra over the left adjoint a coalgebra over its right
adjoint and going back is isomorphic to the identity functor. -/
def alg_coalg_equiv.unit_iso (adj : F ⊣ G) :
𝟭 (algebra F) ≅ (algebra.to_coalgebra_of adj) ⋙ (coalgebra.to_algebra_of adj) :=
{ hom :=
{ app := λ A,
{ f := (𝟙 A.1),
h' := by { erw [F.map_id, category.id_comp, category.comp_id],
apply (adj.hom_equiv _ _).left_inv A.str } },
naturality' := λ A₁ A₂ f, by { ext1, dsimp, erw [category.id_comp, category.comp_id], refl } },
inv :=
{ app := λ A,
{ f := (𝟙 A.1),
h' := by { erw [F.map_id, category.id_comp, category.comp_id],
apply ((adj.hom_equiv _ _).left_inv A.str).symm } },
naturality' := λ A₁ A₂ f,
by { ext1, dsimp, erw [category.comp_id, category.id_comp], refl } },
hom_inv_id' := by { ext, exact category.comp_id _ },
inv_hom_id' := by { ext, exact category.comp_id _ } }
/-- Given an adjunction, assigning to a coalgebra over the right adjoint an algebra over the left
adjoint and going back is isomorphic to the identity functor. -/
def alg_coalg_equiv.counit_iso (adj : F ⊣ G) :
(coalgebra.to_algebra_of adj) ⋙ (algebra.to_coalgebra_of adj) ≅ 𝟭 (coalgebra G) :=
{ hom :=
{ app := λ V,
{ f := (𝟙 V.1),
h' := by { dsimp, erw [G.map_id, category.id_comp, category.comp_id],
apply (adj.hom_equiv _ _).right_inv V.str } },
naturality' := λ V₁ V₂ f,
by { ext1, dsimp, erw [category.comp_id, category.id_comp], refl, } },
inv :=
{ app := λ V,
{ f := (𝟙 V.1),
h' := by { dsimp, rw [G.map_id, category.comp_id, category.id_comp],
apply ((adj.hom_equiv _ _).right_inv V.str).symm } },
naturality' := λ V₁ V₂ f,
by { ext1, dsimp, erw [category.comp_id, category.id_comp], refl } },
hom_inv_id' := by { ext, exact category.comp_id _ },
inv_hom_id' := by { ext, exact category.comp_id _ } }
/-- If `F` is left adjoint to `G`, then the category of algebras over `F` is equivalent to the
category of coalgebras over `G`. -/
def algebra_coalgebra_equiv (adj : F ⊣ G) : algebra F ≌ coalgebra G :=
{ functor := algebra.to_coalgebra_of adj,
inverse := coalgebra.to_algebra_of adj,
unit_iso := alg_coalg_equiv.unit_iso adj,
counit_iso := alg_coalg_equiv.counit_iso adj,
functor_unit_iso_comp' := λ A, by { ext, exact category.comp_id _ } }
end adjunction
end endofunctor
end category_theory
|
e567dbc4542c7f8c46c5f572ff36259843155afd | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /library/init/category/state.lean | a5edf84a37c4a997e55f1b12935438d03268fa69 | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,871 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic init.category.monad init.category.alternative
def state (σ : Type) (α : Type) : Type :=
σ → α × σ
section
variables {σ : Type} {α β : Type}
@[inline] def state_fmap (f : α → β) (a : state σ α) : state σ β :=
λ s, match (a s) with (a', s') := (f a', s') end
@[inline] def state_return (a : α) : state σ α :=
λ s, (a, s)
@[inline] def state_bind (a : state σ α) (b : α → state σ β) : state σ β :=
λ s, match (a s) with (a', s') := b a' s' end
instance (σ : Type) : monad (state σ) :=
{ map := @state_fmap σ,
ret := @state_return σ,
bind := @state_bind σ }
end
namespace state
@[inline] def read {σ : Type} : state σ σ :=
λ s, (s, s)
@[inline] def write {σ : Type} : σ → state σ unit :=
λ s' s, ((), s')
end state
def state_t (σ : Type) (m : Type → Type) [monad m] (α : Type) : Type :=
σ → m (α × σ)
section
variable {σ : Type}
variable {m : Type → Type}
variable [monad m]
variables {α β : Type}
def state_t_fmap (f : α → β) (act : state_t σ m α) : state_t σ m β :=
λ s, show m (β × σ), from
do (a, new_s) ← act s,
return (f a, new_s)
def state_t_return (a : α) : state_t σ m α :=
λ s, show m (α × σ), from
return (a, s)
def state_t_bind (act₁ : state_t σ m α) (act₂ : α → state_t σ m β) : state_t σ m β :=
λ s, show m (β × σ), from
do (a, new_s) ← act₁ s,
act₂ a new_s
end
instance (σ : Type) (m : Type → Type) [monad m] : monad (state_t σ m) :=
{ map := @state_t_fmap σ m _,
ret := @state_t_return σ m _,
bind := @state_t_bind σ m _}
section
variable {σ : Type}
variable {m : Type → Type}
variable [monad m]
variable [alternative m]
variable {α : Type}
def state_t_orelse (act₁ act₂ : state_t σ m α) : state_t σ m α :=
λ s, act₁ s <|> act₂ s
def state_t_failure : state_t σ m α :=
λ s, failure
end
instance (σ : Type) (m : Type → Type) [alternative m] [monad m] : alternative (state_t σ m) :=
{ map := @state_t_fmap σ m _,
pure := @state_t_return σ m _,
seq := @fapp _ _,
failure := @state_t_failure σ m _ _,
orelse := @state_t_orelse σ m _ _ }
namespace state_t
def read {σ : Type} {m : Type → Type} [monad m] : state_t σ m σ :=
λ s, return (s, s)
def write {σ : Type} {m : Type → Type} [monad m] : σ → state_t σ m unit :=
λ s' s, return ((), s')
def modify {σ : Type} {m : Type → Type} [monad m] (f : σ → σ) : state_t σ m unit :=
do s ← read, write (f s)
def lift {α σ : Type} {m : Type → Type} [monad m] (t : m α) : state_t σ m α :=
λ s, do a ← t, return (a, s)
end state_t
|
96033e02bf133fa023dfc1bcb7c392f0153daa49 | 4950bf76e5ae40ba9f8491647d0b6f228ddce173 | /src/data/polynomial/monic.lean | 40d2d31ddd8971368e4ee4f8a82be079217479a9 | [
"Apache-2.0"
] | permissive | ntzwq/mathlib | ca50b21079b0a7c6781c34b62199a396dd00cee2 | 36eec1a98f22df82eaccd354a758ef8576af2a7f | refs/heads/master | 1,675,193,391,478 | 1,607,822,996,000 | 1,607,822,996,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,192 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.degree
import algebra.associated
import tactic.omega
/-!
# Theory of monic polynomials
We give several tools for proving that polynomials are monic, e.g.
`monic_mul`, `monic_map`.
-/
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
open finset
open_locale big_operators
namespace polynomial
universes u v y
variables {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section semiring
variables [semiring R] {p q r : polynomial R}
lemma monic.as_sum {p : polynomial R} (hp : p.monic) :
p = X^(p.nat_degree) + (∑ i in finset.range p.nat_degree, C (p.coeff i) * X^i) :=
begin
conv_lhs { rw [p.as_sum_range_C_mul_X_pow, finset.sum_range_succ] },
suffices : C (p.coeff p.nat_degree) = 1,
{ rw [this, one_mul] },
exact congr_arg C hp
end
lemma ne_zero_of_monic_of_zero_ne_one (hp : monic p) (h : (0 : R) ≠ 1) :
p ≠ 0 := mt (congr_arg leading_coeff) $ by rw [monic.def.1 hp, leading_coeff_zero]; cc
lemma ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : monic q) : q ≠ 0 :=
begin
intro h, 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 monic_map [semiring S] (f : R →+* S) (hp : monic p) : monic (p.map f) :=
if h : (0 : S) = 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
begin
rw [monic, leading_coeff, coeff_map],
suffices : p.coeff (map f p).nat_degree = 1, simp [this],
suffices : (map f p).nat_degree = p.nat_degree, rw this, exact hp,
rwa nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero _ _),
end
lemma monic_mul_C_of_leading_coeff_mul_eq_one [nontrivial R] {b : R}
(hp : p.leading_coeff * b = 1) : monic (p * C b) :=
by rw [monic, leading_coeff_mul' _]; simp [leading_coeff_C b, hp]
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, eq_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 : R) : monic (X + C x) :=
pow_one (X : polynomial R) ▸ monic_X_pow_add degree_C_le
lemma monic_mul (hp : monic p) (hq : monic q) : monic (p * q) :=
if h0 : (0 : R) = 1 then by haveI := subsingleton_of_zero_eq_one h0;
exact subsingleton.elim _ _
else
have leading_coeff p * leading_coeff q ≠ 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0],
by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul]
lemma monic_pow (hp : monic p) : ∀ (n : ℕ), monic (p ^ n)
| 0 := monic_one
| (n+1) := monic_mul hp (monic_pow n)
lemma monic_add_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :
monic (p + q) :=
by rwa [monic, add_comm, leading_coeff_add_of_degree_lt hpq]
lemma monic_add_of_right {p q : polynomial R} (hq : monic q) (hpq : degree p < degree q) :
monic (p + q) :=
by rwa [monic, leading_coeff_add_of_degree_lt hpq]
end semiring
section comm_semiring
variables [comm_semiring R] {p : polynomial R}
lemma monic_prod_of_monic (s : finset ι) (f : ι → polynomial R) (hs : ∀ i ∈ s, monic (f i)) :
monic (∏ i in s, f i) :=
prod_induction _ _ (@monic_mul _ _) monic_one hs
lemma is_unit_C {x : R} : is_unit (C x) ↔ is_unit x :=
begin
rw [is_unit_iff_dvd_one, is_unit_iff_dvd_one],
split,
{ rintros ⟨g, hg⟩,
replace hg := congr_arg (eval 0) hg,
rw [eval_one, eval_mul, eval_C] at hg,
exact ⟨g.eval 0, hg⟩ },
{ rintros ⟨y, hy⟩,
exact ⟨C y, by rw [← C_mul, ← hy, C_1]⟩ }
end
lemma eq_one_of_is_unit_of_monic (hm : monic p) (hpu : is_unit p) : p = 1 :=
have degree p ≤ 0,
from calc degree p ≤ degree (1 : polynomial R) :
let ⟨u, hu⟩ := is_unit_iff_dvd_one.1 hpu in
if hu0 : u = 0
then begin
rw [hu0, mul_zero] at hu,
rw [← mul_one p, hu, mul_zero],
simp
end
else have p.leading_coeff * u.leading_coeff ≠ 0,
by rw [hm.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero];
exact hu0,
by rw [hu, degree_mul' this];
exact le_add_of_nonneg_right (degree_nonneg_iff_ne_zero.2 hu0)
... ≤ 0 : degree_one_le,
by rw [eq_C_of_degree_le_zero this, ← nat_degree_eq_zero_iff_degree_le_zero.2 this,
← leading_coeff, hm.leading_coeff, C_1]
end comm_semiring
section comm_ring
variables [comm_ring R]
namespace monic
lemma coeff_nat_degree {p : polynomial R} (hp : p.monic) : p.coeff (p.nat_degree) = 1 := hp
@[simp]
lemma degree_eq_zero_iff_eq_one {p : polynomial R} (hp : p.monic) :
p.nat_degree = 0 ↔ p = 1 :=
begin
split; intro h,
swap, { rw h, exact nat_degree_one },
have : p = C (p.coeff 0),
{ rw ← polynomial.degree_le_zero_iff,
rwa polynomial.nat_degree_eq_zero_iff_degree_le_zero at h },
rw this, convert C_1, rw ← h, apply hp,
end
lemma nat_degree_mul [nontrivial R] {p q : polynomial R} (hp : p.monic) (hq : q.monic) :
(p * q).nat_degree = p.nat_degree + q.nat_degree :=
by { apply nat_degree_mul', rw [hp.leading_coeff, hq.leading_coeff], simp }
lemma next_coeff_mul {p q : polynomial R} (hp : monic p) (hq : monic q) :
next_coeff (p * q) = next_coeff p + next_coeff q :=
begin
classical,
nontriviality R,
simp only [next_coeff, monic.nat_degree_mul hp hq],
simp only [hp, hq, degree_eq_zero_iff_eq_one, add_eq_zero_iff],
set dp := p.nat_degree, set dq := q.nat_degree,
suffices : p ≠ 1 → q ≠ 1 → (p * q).coeff (dp + dq - 1) = p.coeff (dp - 1) + q.coeff (dq - 1),
{ by_cases hp0 : p = 1; by_cases hq0 : q = 1; simp [dp, dq, hp0, hq0, this] },
intros hp0 hq0,
replace hp0 : dp ≠ 0 := mt hp.degree_eq_zero_iff_eq_one.1 hp0,
replace hq0 : dq ≠ 0 := mt hq.degree_eq_zero_iff_eq_one.1 hq0,
rw coeff_mul,
have : {(dp - 1, dq), (dp, dq - 1)} ⊆ nat.antidiagonal (dp + dq - 1),
{ suffices : dp - 1 + dq = dp + dq - 1 ∧ dp + (dq - 1) = dp + dq - 1,
by simpa [insert_subset, singleton_subset_iff],
omega },
rw [← sum_subset this, sum_pair],
{ simp [hp, hq] },
{ suffices : dp - 1 ≠ dp, from mt (congr_arg prod.fst) this,
omega },
{ rintros ⟨x, y⟩ hx hx1,
simp only [nat.mem_antidiagonal] at hx,
simp only [mem_insert, mem_singleton] at hx1,
contrapose! hx1,
have hxp : x ≤ dp, from le_nat_degree_of_ne_zero (left_ne_zero_of_mul hx1),
have hyq : y ≤ dq, from le_nat_degree_of_ne_zero (right_ne_zero_of_mul hx1),
have : dq - 1 ≤ y, omega,
by_cases hy : y = dq,
{ subst y, left, congr, omega },
{ have : y = dq - 1, by omega, subst y, right, congr, omega } }
end
lemma next_coeff_prod
(s : finset ι) (f : ι → polynomial R) (h : ∀ i ∈ s, monic (f i)) :
next_coeff (∏ i in s, f i) = ∑ i in s, next_coeff (f i) :=
begin
classical,
revert h, apply finset.induction_on s,
{ simp only [finset.not_mem_empty, forall_prop_of_true, forall_prop_of_false, finset.sum_empty,
finset.prod_empty, not_false_iff, forall_true_iff],
rw ← C_1, rw next_coeff_C_eq_zero },
{ intros a s ha hs monic,
rw finset.prod_insert ha,
rw finset.sum_insert ha,
rw next_coeff_mul (monic a (finset.mem_insert_self a s)), swap,
{ apply monic_prod_of_monic, intros b bs,
apply monic, apply finset.mem_insert_of_mem bs },
{ refine congr rfl (hs _),
intros b bs, apply monic, apply finset.mem_insert_of_mem bs }}
end
end monic
end comm_ring
section ring
variables [ring R] {p : polynomial R}
theorem monic_X_sub_C (x : R) : monic (X - C x) :=
by simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) - p) :=
by simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) ≤ n, by rwa ←degree_neg p at H)
/-- `X ^ n - a` is monic. -/
lemma monic_X_pow_sub_C {R : Type u} [ring R] (a : R) {n : ℕ} (h : n ≠ 0) : (X ^ n - C a).monic :=
begin
obtain ⟨k, hk⟩ := nat.exists_eq_succ_of_ne_zero h,
convert monic_X_pow_sub _,
exact le_trans degree_C_le nat.with_bot.coe_nonneg,
end
lemma monic_sub_of_left {p q : polynomial R} (hp : monic p) (hpq : degree q < degree p) :
monic (p - q) :=
by { rw sub_eq_add_neg, apply monic_add_of_left hp, rwa degree_neg }
lemma monic_sub_of_right {p q : polynomial R}
(hq : q.leading_coeff = -1) (hpq : degree p < degree q) : monic (p - q) :=
have (-q).coeff (-q).nat_degree = 1 :=
by rw [nat_degree_neg, coeff_neg, show q.coeff q.nat_degree = -1, from hq, neg_neg],
by { rw sub_eq_add_neg, apply monic_add_of_right this, rwa degree_neg }
section injective
open function
variables [semiring S] {f : R →+* S} (hf : injective f)
include hf
lemma leading_coeff_of_injective (p : polynomial R) :
leading_coeff (p.map f) = f (leading_coeff p) :=
begin
delta leading_coeff,
rw [coeff_map f, nat_degree_map' hf p]
end
lemma monic_of_injective {p : polynomial R} (hp : (p.map f).monic) : p.monic :=
begin
apply hf,
rw [← leading_coeff_of_injective hf, hp.leading_coeff, is_semiring_hom.map_one f]
end
end injective
end ring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : polynomial R}
@[simp] lemma not_monic_zero : ¬monic (0 : polynomial R) :=
by simpa only [monic, leading_coeff_zero] using (zero_ne_one : (0 : R) ≠ 1)
lemma ne_zero_of_monic (h : monic p) : p ≠ 0 :=
λ h₁, @not_monic_zero R _ _ (h₁ ▸ h)
end nonzero_semiring
end polynomial
|
1231f927feccd89fc6759d8fcadf095b3bb8a3de | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/1590.lean | bdf9eeb0816761ce0915b13607c369a81d9320fc | [
"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 | 104 | lean | #check `(true.intro)
#check (`(true.intro) : expr)
variables (h : true) [reflected _ h]
#check `(id h)
|
36816f05e4f18fd35af822e9624e360926fad8d5 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /archive/imo/imo2013_q5.lean | 83d5bfc9ae1a5a74b68c016c2a9a708e21a73f22 | [
"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 | 14,932 | lean | /-
Copyright (c) 2021 David Renshaw. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Renshaw
-/
import algebra.geom_sum
import data.rat.basic
import data.real.basic
/-!
# IMO 2013 Q5
Let ℚ>₀ be the set of positive rational numbers. Let f: ℚ>₀ → ℝ be a function satisfying
the conditions
(1) f(x) * f(y) ≥ f(x * y)
(2) f(x + y) ≥ f(x) + f(y)
for all x,y ∈ ℚ>₀. Given that f(a) = a for some rational a > 1, prove that f(x) = x for
all x ∈ ℚ>₀.
# Solution
We provide a direct translation of the solution found in
https://www.imo-official.org/problems/IMO2013SL.pdf
-/
open_locale big_operators
lemma le_of_all_pow_lt_succ {x y : ℝ} (hx : 1 < x) (hy : 1 < y)
(h : ∀ n : ℕ, 0 < n → x^n - 1 < y^n) :
x ≤ y :=
begin
by_contra hxy,
push_neg at hxy,
have hxmy : 0 < x - y := sub_pos.mpr hxy,
have hn : ∀ n : ℕ, 0 < n → (x - y) * (n : ℝ) ≤ x^n - y^n,
{ intros n hn,
have hterm : ∀ i : ℕ, i ∈ finset.range n → 1 ≤ x^i * y^(n - 1 - i),
{ intros i hi,
have hx' : 1 ≤ x ^ i := one_le_pow_of_one_le hx.le i,
have hy' : 1 ≤ y ^ (n - 1 - i) := one_le_pow_of_one_le hy.le (n - 1 - i),
calc 1 ≤ x^i : hx'
... = x^i * 1 : (mul_one _).symm
... ≤ x^i * y^(n-1-i) : mul_le_mul_of_nonneg_left hy' (zero_le_one.trans hx') },
calc (x - y) * (n : ℝ)
= (n : ℝ) * (x - y) : mul_comm _ _
... = (∑ (i : ℕ) in finset.range n, (1 : ℝ)) * (x - y) :
by simp only [mul_one, finset.sum_const, nsmul_eq_mul,
finset.card_range]
... ≤ (∑ (i : ℕ) in finset.range n, x ^ i * y ^ (n - 1 - i)) * (x-y) :
(mul_le_mul_right hxmy).mpr (finset.sum_le_sum hterm)
... = x^n - y^n : geom_sum₂_mul x y n, },
-- Choose n larger than 1 / (x - y).
obtain ⟨N, hN⟩ := exists_nat_gt (1 / (x - y)),
have hNp : 0 < N, { exact_mod_cast (one_div_pos.mpr hxmy).trans hN },
have := calc 1 = (x - y) * (1 / (x - y)) : by field_simp [ne_of_gt hxmy]
... < (x - y) * N : (mul_lt_mul_left hxmy).mpr hN
... ≤ x^N - y^N : hn N hNp,
linarith [h N hNp]
end
/--
Like le_of_all_pow_lt_succ, but with a weaker assumption for y.
-/
lemma le_of_all_pow_lt_succ' {x y : ℝ} (hx : 1 < x) (hy : 0 < y)
(h : ∀ n : ℕ, 0 < n → x^n - 1 < y^n) :
x ≤ y :=
begin
refine le_of_all_pow_lt_succ hx _ h,
by_contra hy'',
push_neg at hy'', -- hy'' : y ≤ 1.
-- Then there exists y' such that 0 < y ≤ 1 < y' < x.
let y' := (x + 1) / 2,
have h_y'_lt_x : y' < x,
{ have hh : (x + 1)/2 < (x * 2) / 2, { linarith },
calc y' < (x * 2) / 2 : hh
... = x : by field_simp },
have h1_lt_y' : 1 < y',
{ have hh' : 1 * 2 / 2 < (x + 1) / 2, { linarith },
calc 1 = 1 * 2 / 2 : by field_simp
... < y' : hh' },
have h_y_lt_y' : y < y' := hy''.trans_lt h1_lt_y',
have hh : ∀ n, 0 < n → x^n - 1 < y'^n,
{ intros n hn,
calc x^n - 1 < y^n : h n hn
... ≤ y'^n : pow_le_pow_of_le_left hy.le h_y_lt_y'.le n },
exact h_y'_lt_x.not_le (le_of_all_pow_lt_succ hx h1_lt_y' hh)
end
lemma f_pos_of_pos {f : ℚ → ℝ} {q : ℚ} (hq : 0 < q)
(H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)
(H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n) :
0 < f q :=
begin
have hfqn := calc f q.num = f (q * q.denom) : by rw ←rat.mul_denom_eq_num
... ≤ f q * f q.denom : H1 q q.denom hq (nat.cast_pos.mpr q.pos),
-- Now we just need to show that `f q.num` and `f q.denom` are positive.
-- Then nlinarith will be able to close the goal.
have num_pos : 0 < q.num := rat.num_pos_iff_pos.mpr hq,
have hqna : (q.num.nat_abs : ℤ) = q.num := int.nat_abs_of_nonneg num_pos.le,
have hqfn' :=
calc (q.num : ℝ)
= ((q.num.nat_abs : ℤ) : ℝ) : congr_arg coe (eq.symm hqna)
... ≤ f q.num.nat_abs : H4 q.num.nat_abs
(int.nat_abs_pos_of_ne_zero (ne_of_gt num_pos))
... = f q.num : by exact_mod_cast congr_arg f (congr_arg coe hqna),
have f_num_pos := calc (0 : ℝ) < q.num : int.cast_pos.mpr num_pos
... ≤ f q.num : hqfn',
have f_denom_pos := calc (0 : ℝ) < q.denom : nat.cast_pos.mpr q.pos
... ≤ f q.denom : H4 q.denom q.pos,
nlinarith
end
lemma fx_gt_xm1 {f : ℚ → ℝ} {x : ℚ} (hx : 1 ≤ x)
(H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)
(H2 : ∀ x y, 0 < x → 0 < y → f x + f y ≤ f (x + y))
(H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n) :
((x - 1 : ℚ) : ℝ) < f x :=
begin
have hfe : (⌊x⌋.nat_abs : ℤ) = ⌊x⌋ := int.nat_abs_of_nonneg
(floor_nonneg.mpr (zero_le_one.trans hx)),
have hfe' : (⌊x⌋.nat_abs : ℚ) = ⌊x⌋, { exact_mod_cast hfe },
have h0fx : 0 < ⌊x⌋ := int.cast_pos.mp ((sub_nonneg.mpr hx).trans_lt (sub_one_lt_floor x)),
have h_nat_abs_floor_pos : 0 < ⌊x⌋.nat_abs := int.nat_abs_pos_of_ne_zero (ne_of_gt h0fx),
have hx0 := calc ((x - 1 : ℚ) : ℝ)
< ⌊x⌋ : by exact_mod_cast sub_one_lt_floor x
... = ↑⌊x⌋.nat_abs : by exact_mod_cast hfe.symm
... ≤ f ⌊x⌋.nat_abs : H4 ⌊x⌋.nat_abs h_nat_abs_floor_pos
... = f ⌊x⌋ : by rw hfe',
obtain (h_eq : (⌊x⌋ : ℚ) = x) | (h_lt : (⌊x⌋ : ℚ) < x) := (floor_le x).eq_or_lt,
{ rwa h_eq at hx0 },
calc ((x - 1 : ℚ) : ℝ) < f ⌊x⌋ : hx0
... < f (x - ⌊x⌋) + f ⌊x⌋ : lt_add_of_pos_left (f ↑⌊x⌋)
(f_pos_of_pos (sub_pos.mpr h_lt) H1 H4)
... ≤ f (x - ⌊x⌋ + ⌊x⌋) : H2 (x - ⌊x⌋) ⌊x⌋ (sub_pos.mpr h_lt)
(by exact_mod_cast h0fx)
... = f x : by simp only [sub_add_cancel]
end
lemma pow_f_le_f_pow {f : ℚ → ℝ} {n : ℕ} (hn : 0 < n) {x : ℚ} (hx : 1 < x)
(H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)
(H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n) :
f (x^n) ≤ (f x)^n :=
begin
induction n with pn hpn,
{ exfalso, exact nat.lt_asymm hn hn },
cases pn,
{ simp only [pow_one] },
have hpn' := hpn pn.succ_pos,
rw [pow_succ' x (pn + 1), pow_succ' (f x) (pn + 1)],
have hxp : 0 < x := zero_lt_one.trans hx,
calc f ((x ^ (pn+1)) * x)
≤ f (x ^ (pn+1)) * f x : H1 (x ^ (pn+1)) x (pow_pos hxp (pn+1)) hxp
... ≤ (f x) ^ (pn+1) * f x : (mul_le_mul_right (f_pos_of_pos hxp H1 H4)).mpr hpn'
end
lemma fixed_point_of_pos_nat_pow {f : ℚ → ℝ} {n : ℕ} (hn : 0 < n)
(H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)
(H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n)
(H5 : ∀ x : ℚ, 1 < x → (x : ℝ) ≤ f x)
{a : ℚ} (ha1 : 1 < a) (hae : f a = a) :
f (a^n) = a^n :=
begin
have hh0 : (a : ℝ) ^ n ≤ f (a ^ n),
{ exact_mod_cast H5 (a ^ n) (one_lt_pow ha1 (nat.succ_le_iff.mpr hn)) },
have hh1 := calc f (a^n) ≤ (f a)^n : pow_f_le_f_pow hn ha1 H1 H4
... = (a : ℝ)^n : by rw ← hae,
exact hh1.antisymm hh0
end
lemma fixed_point_of_gt_1 {f : ℚ → ℝ} {x : ℚ} (hx : 1 < x)
(H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)
(H2 : ∀ x y, 0 < x → 0 < y → f x + f y ≤ f (x + y))
(H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n)
(H5 : ∀ x : ℚ, 1 < x → (x : ℝ) ≤ f x)
{a : ℚ} (ha1 : 1 < a) (hae : f a = a) :
f x = x :=
begin
-- Choose n such that 1 + x < a^n.
have hbound : ∀ m : ℕ, 1 + (m : ℚ) * (a - 1) ≤ a^m,
{ intros m,
have ha : -1 ≤ a := le_of_lt (lt_trans (neg_one_lt_zero.trans zero_lt_one) ha1),
exact one_add_mul_sub_le_pow ha m },
-- Choose N greater than x / (a - 1).
obtain ⟨N, hN⟩ := exists_nat_gt (max 0 (x / (a - 1))),
have hN' := calc x / (a - 1) ≤ max 0 (x / (a - 1)) : le_max_right _ _
... < N : hN,
have h_big_enough :=
calc (1 : ℚ)
= (1 + N * (a - 1)) - N * (a - 1) : by ring
... ≤ a^N - N * (a - 1) : sub_le_sub_right (hbound N) (↑N * (a - 1))
... < a^N - (x / (a - 1)) * (a - 1) : sub_lt_sub_left
((mul_lt_mul_right (sub_pos.mpr ha1)).mpr hN') (a^N)
... = a^N - x : by field_simp [ne_of_gt (sub_pos.mpr ha1)],
have h1 := calc (x : ℝ) + ((a^N - x) : ℚ)
≤ f x + ((a^N - x) : ℚ) : add_le_add_right (H5 x hx) _
... ≤ f x + f (a^N - x) : add_le_add_left (H5 _ h_big_enough) _,
have hxp : 0 < x := zero_lt_one.trans hx,
have hNp : 0 < N,
{ exact_mod_cast calc ((0 : ℕ) : ℚ) = (0 : ℚ) : nat.cast_zero
... ≤ max 0 (x / (a - 1)) : le_max_left 0 _
... < N : hN, },
have h2 := calc f x + f (a^N - x)
≤ f (x + (a^N - x)) : H2 x (a^N - x) hxp (zero_lt_one.trans h_big_enough)
... = f (a^N) : by ring_nf
... = a^N : fixed_point_of_pos_nat_pow hNp H1 H4 H5 ha1 hae
... = x + (a^N - x) : by ring,
have heq := h1.antisymm (by exact_mod_cast h2),
linarith [H5 x hx, H5 _ h_big_enough]
end
theorem imo2013_q5
(f : ℚ → ℝ)
(H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)
(H2 : ∀ x y, 0 < x → 0 < y → f x + f y ≤ f (x + y))
(H_fixed_point : ∃ a, 1 < a ∧ f a = a) :
∀ x, 0 < x → f x = x :=
begin
obtain ⟨a, ha1, hae⟩ := H_fixed_point,
have H3 : ∀ x : ℚ, 0 < x → ∀ n : ℕ, 0 < n → ↑n * f x ≤ f (n * x),
{ intros x hx n hn,
cases n,
{ exfalso, exact nat.lt_asymm hn hn },
induction n with pn hpn,
{ simp only [one_mul, nat.cast_one] },
calc (↑pn + 1 + 1) * f x
= ((pn : ℝ) + 1) * f x + 1 * f x : add_mul (↑pn + 1) 1 (f x)
... = (↑pn + 1) * f x + f x : by rw one_mul
... ≤ f ((↑pn.succ) * x) + f x : by exact_mod_cast add_le_add_right
(hpn pn.succ_pos) (f x)
... ≤ f ((↑pn + 1) * x + x) : by exact_mod_cast H2 _ _
(mul_pos pn.cast_add_one_pos hx) hx
... = f ((↑pn + 1) * x + 1 * x) : by rw one_mul
... = f ((↑pn + 1 + 1) * x) : congr_arg f (add_mul (↑pn + 1) 1 x).symm },
have H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n,
{ intros n hn,
have hf1 : 1 ≤ f 1,
{ have a_pos : (0 : ℝ) < a := rat.cast_pos.mpr (zero_lt_one.trans ha1),
suffices : ↑a * 1 ≤ ↑a * f 1, from (mul_le_mul_left a_pos).mp this,
calc ↑a * 1 = ↑a : mul_one ↑a
... = f a : hae.symm
... = f (a * 1) : by rw mul_one
... ≤ f a * f 1 : (H1 a 1) (zero_lt_one.trans ha1) zero_lt_one
... = ↑a * f 1 : by rw hae },
calc (n : ℝ) = (n : ℝ) * 1 : (mul_one _).symm
... ≤ (n : ℝ) * f 1 : (mul_le_mul_left (nat.cast_pos.mpr hn)).mpr hf1
... ≤ f (n * 1) : H3 1 zero_lt_one n hn
... = f n : by rw mul_one },
have H5 : ∀ x : ℚ, 1 < x → (x : ℝ) ≤ f x,
{ intros x hx,
have hxnm1 : ∀ n : ℕ, 0 < n → (x : ℝ)^n - 1 < (f x)^n,
{ intros n hn,
calc (x : ℝ)^n - 1 < f (x^n) : by exact_mod_cast fx_gt_xm1 (one_le_pow_of_one_le hx.le n)
H1 H2 H4
... ≤ (f x)^n : pow_f_le_f_pow hn hx H1 H4 },
have hx' : 1 < (x : ℝ) := by exact_mod_cast hx,
have hxp : 0 < x := zero_lt_one.trans hx,
exact le_of_all_pow_lt_succ' hx' (f_pos_of_pos hxp H1 H4) hxnm1 },
have h_f_commutes_with_pos_nat_mul : ∀ n : ℕ, 0 < n → ∀ x : ℚ, 0 < x → f (n * x) = n * f x,
{ intros n hn x hx,
have h2 : f (n * x) ≤ n * f x,
{ cases n,
{ exfalso, exact nat.lt_asymm hn hn },
cases n,
{ simp only [one_mul, nat.cast_one] },
have hfneq : f (n.succ.succ) = n.succ.succ,
{ have := fixed_point_of_gt_1
(nat.one_lt_cast.mpr (nat.succ_lt_succ n.succ_pos)) H1 H2 H4 H5 ha1 hae,
rwa (rat.cast_coe_nat n.succ.succ) at this },
rw ← hfneq,
exact H1 (n.succ.succ : ℚ) x (nat.cast_pos.mpr hn) hx },
exact h2.antisymm (H3 x hx n hn) },
-- For the final calculation, we expand x as (2*x.num) / (2*x.denom), because
-- we need the top of the fraction to be strictly greater than 1 in order
-- to apply fixed_point_of_gt_1.
intros x hx,
let x2denom := 2 * x.denom,
let x2num := 2 * x.num,
have hx2pos := calc 0 < x.denom : x.pos
... < x.denom + x.denom : lt_add_of_pos_left x.denom x.pos
... = 2 * x.denom : by ring,
have hxcnez : (x.denom : ℚ) ≠ (0 : ℚ) := ne_of_gt (nat.cast_pos.mpr x.pos),
have hx2cnezr : (x2denom : ℝ) ≠ (0 : ℝ) := nat.cast_ne_zero.mpr (ne_of_gt hx2pos),
have hrat_expand2 := calc x = x.num / x.denom : by exact_mod_cast rat.num_denom.symm
... = x2num / x2denom : by { field_simp, linarith [hxcnez] },
have h_denom_times_fx :=
calc (x2denom : ℝ) * f x = f (x2denom * x) : (h_f_commutes_with_pos_nat_mul
x2denom hx2pos x hx).symm
... = f (x2denom * (x2num / x2denom)) : by rw hrat_expand2
... = f x2num : by { congr, field_simp, ring },
have h_fx2num_fixed : f x2num = x2num,
{ have hx2num_gt_one : (1 : ℚ) < (2 * x.num : ℤ),
{ norm_cast, linarith [rat.num_pos_iff_pos.mpr hx] },
have hh := fixed_point_of_gt_1 hx2num_gt_one H1 H2 H4 H5 ha1 hae,
rwa (rat.cast_coe_int x2num) at hh },
calc f x = f x * 1 : (mul_one (f x)).symm
... = f x * (x2denom / x2denom) : by rw ←(div_self hx2cnezr)
... = (f x * x2denom) / x2denom : mul_div_assoc' (f x) _ _
... = (x2denom * f x) / x2denom : by rw mul_comm
... = f x2num / x2denom : by rw h_denom_times_fx
... = x2num / x2denom : by rw h_fx2num_fixed
... = (((x2num : ℚ) / (x2denom : ℚ) : ℚ) : ℝ) : by norm_cast
... = x : by rw ←hrat_expand2
end
|
3b8a80da39b22289a71bb9214bd4ede70855dc25 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/normed_space/compact_operator.lean | 38ff69e6c926f5d141bc83ee0a189756abfe8d36 | [
"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 | 22,012 | lean | /-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import analysis.normed_space.operator_norm
import analysis.locally_convex.bounded
/-!
# Compact operators
In this file we define compact linear operators between two topological vector spaces (TVS).
## Main definitions
* `is_compact_operator` : predicate for compact operators
## Main statements
* `is_compact_operator_iff_is_compact_closure_image_closed_ball` : the usual characterization of
compact operators from a normed space to a T2 TVS.
* `is_compact_operator.comp_clm` : precomposing a compact operator by a continuous linear map gives
a compact operator
* `is_compact_operator.clm_comp` : postcomposing a compact operator by a continuous linear map
gives a compact operator
* `is_compact_operator.continuous` : compact operators are automatically continuous
* `is_closed_set_of_is_compact_operator` : the set of compact operators is closed for the operator
norm
## Implementation details
We define `is_compact_operator` as a predicate, because the space of compact operators inherits all
of its structure from the space of continuous linear maps (e.g we want to have the usual operator
norm on compact operators).
The two natural options then would be to make it a predicate over linear maps or continuous linear
maps. Instead we define it as a predicate over bare functions, although it really only makes sense
for linear functions, because Lean is really good at finding coercions to bare functions (whereas
coercing from continuous linear maps to linear maps often needs type ascriptions).
## TODO
Once we have the strong operator topology on spaces of linear maps between two TVSs,
`is_closed_set_of_is_compact_operator` should be generalized to this setup.
## References
* Bourbaki, *Spectral Theory*, chapters 3 to 5, to be published (2022)
## Tags
Compact operator
-/
open function set filter bornology metric
open_locale pointwise big_operators topological_space
/-- A compact operator between two topological vector spaces. This definition is usually
given as "there exists a neighborhood of zero whose image is contained in a compact set",
but we choose a definition which involves fewer existential quantifiers and replaces images
with preimages.
We prove the equivalence in `is_compact_operator_iff_exists_mem_nhds_image_subset_compact`. -/
def is_compact_operator {M₁ M₂ : Type*} [has_zero M₁] [topological_space M₁]
[topological_space M₂] (f : M₁ → M₂) : Prop :=
∃ K, is_compact K ∧ f ⁻¹' K ∈ (𝓝 0 : filter M₁)
lemma is_compact_operator_zero {M₁ M₂ : Type*} [has_zero M₁] [topological_space M₁]
[topological_space M₂] [has_zero M₂] : is_compact_operator (0 : M₁ → M₂) :=
⟨{0}, is_compact_singleton, mem_of_superset univ_mem (λ x _, rfl)⟩
section characterizations
section
variables {R₁ R₂ : Type*} [semiring R₁] [semiring R₂] {σ₁₂ : R₁ →+* R₂} {M₁ M₂ : Type*}
[topological_space M₁] [add_comm_monoid M₁] [topological_space M₂]
lemma is_compact_operator_iff_exists_mem_nhds_image_subset_compact (f : M₁ → M₂) :
is_compact_operator f ↔ ∃ V ∈ (𝓝 0 : filter M₁), ∃ (K : set M₂), is_compact K ∧ f '' V ⊆ K :=
⟨λ ⟨K, hK, hKf⟩, ⟨f ⁻¹' K, hKf, K, hK, image_preimage_subset _ _⟩,
λ ⟨V, hV, K, hK, hVK⟩, ⟨K, hK, mem_of_superset hV (image_subset_iff.mp hVK)⟩⟩
lemma is_compact_operator_iff_exists_mem_nhds_is_compact_closure_image [t2_space M₂]
(f : M₁ → M₂) :
is_compact_operator f ↔ ∃ V ∈ (𝓝 0 : filter M₁), is_compact (closure $ f '' V) :=
begin
rw is_compact_operator_iff_exists_mem_nhds_image_subset_compact,
exact ⟨λ ⟨V, hV, K, hK, hKV⟩, ⟨V, hV, compact_closure_of_subset_compact hK hKV⟩,
λ ⟨V, hV, hVc⟩, ⟨V, hV, closure (f '' V), hVc, subset_closure⟩⟩,
end
end
section bounded
variables {𝕜₁ 𝕜₂ : Type*} [nontrivially_normed_field 𝕜₁] [semi_normed_ring 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂}
{M₁ M₂ : Type*} [topological_space M₁] [add_comm_monoid M₁] [topological_space M₂]
[add_comm_monoid M₂] [module 𝕜₁ M₁] [module 𝕜₂ M₂] [has_continuous_const_smul 𝕜₂ M₂]
lemma is_compact_operator.image_subset_compact_of_vonN_bounded {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : is_compact_operator f) {S : set M₁} (hS : is_vonN_bounded 𝕜₁ S) :
∃ (K : set M₂), is_compact K ∧ f '' S ⊆ K :=
let ⟨K, hK, hKf⟩ := hf,
⟨r, hr, hrS⟩ := hS hKf,
⟨c, hc⟩ := normed_field.exists_lt_norm 𝕜₁ r,
this := ne_zero_of_norm_ne_zero (hr.trans hc).ne.symm in
⟨σ₁₂ c • K, hK.image $ continuous_id.const_smul (σ₁₂ c),
by rw [image_subset_iff, preimage_smul_setₛₗ _ _ _ f this.is_unit]; exact hrS c hc.le⟩
lemma is_compact_operator.is_compact_closure_image_of_vonN_bounded [t2_space M₂]
{f : M₁ →ₛₗ[σ₁₂] M₂} (hf : is_compact_operator f) {S : set M₁}
(hS : is_vonN_bounded 𝕜₁ S) : is_compact (closure $ f '' S) :=
let ⟨K, hK, hKf⟩ := hf.image_subset_compact_of_vonN_bounded hS in
compact_closure_of_subset_compact hK hKf
end bounded
section normed_space
variables {𝕜₁ 𝕜₂ : Type*} [nontrivially_normed_field 𝕜₁] [semi_normed_ring 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂}
{M₁ M₂ M₃ : Type*} [seminormed_add_comm_group M₁] [topological_space M₂]
[add_comm_monoid M₂] [normed_space 𝕜₁ M₁] [module 𝕜₂ M₂]
lemma is_compact_operator.image_subset_compact_of_bounded [has_continuous_const_smul 𝕜₂ M₂]
{f : M₁ →ₛₗ[σ₁₂] M₂} (hf : is_compact_operator f) {S : set M₁} (hS : metric.bounded S) :
∃ (K : set M₂), is_compact K ∧ f '' S ⊆ K :=
hf.image_subset_compact_of_vonN_bounded
(by rwa [normed_space.is_vonN_bounded_iff, ← metric.bounded_iff_is_bounded])
lemma is_compact_operator.is_compact_closure_image_of_bounded [has_continuous_const_smul 𝕜₂ M₂]
[t2_space M₂] {f : M₁ →ₛₗ[σ₁₂] M₂} (hf : is_compact_operator f) {S : set M₁}
(hS : metric.bounded S) : is_compact (closure $ f '' S) :=
hf.is_compact_closure_image_of_vonN_bounded
(by rwa [normed_space.is_vonN_bounded_iff, ← metric.bounded_iff_is_bounded])
lemma is_compact_operator.image_ball_subset_compact [has_continuous_const_smul 𝕜₂ M₂]
{f : M₁ →ₛₗ[σ₁₂] M₂} (hf : is_compact_operator f) (r : ℝ) :
∃ (K : set M₂), is_compact K ∧ f '' metric.ball 0 r ⊆ K :=
hf.image_subset_compact_of_vonN_bounded (normed_space.is_vonN_bounded_ball 𝕜₁ M₁ r)
lemma is_compact_operator.image_closed_ball_subset_compact [has_continuous_const_smul 𝕜₂ M₂]
{f : M₁ →ₛₗ[σ₁₂] M₂} (hf : is_compact_operator f) (r : ℝ) :
∃ (K : set M₂), is_compact K ∧ f '' metric.closed_ball 0 r ⊆ K :=
hf.image_subset_compact_of_vonN_bounded (normed_space.is_vonN_bounded_closed_ball 𝕜₁ M₁ r)
lemma is_compact_operator.is_compact_closure_image_ball [has_continuous_const_smul 𝕜₂ M₂]
[t2_space M₂] {f : M₁ →ₛₗ[σ₁₂] M₂} (hf : is_compact_operator f) (r : ℝ) :
is_compact (closure $ f '' metric.ball 0 r) :=
hf.is_compact_closure_image_of_vonN_bounded (normed_space.is_vonN_bounded_ball 𝕜₁ M₁ r)
lemma is_compact_operator.is_compact_closure_image_closed_ball [has_continuous_const_smul 𝕜₂ M₂]
[t2_space M₂] {f : M₁ →ₛₗ[σ₁₂] M₂} (hf : is_compact_operator f) (r : ℝ) :
is_compact (closure $ f '' metric.closed_ball 0 r) :=
hf.is_compact_closure_image_of_vonN_bounded (normed_space.is_vonN_bounded_closed_ball 𝕜₁ M₁ r)
lemma is_compact_operator_iff_image_ball_subset_compact [has_continuous_const_smul 𝕜₂ M₂]
(f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
is_compact_operator f ↔ ∃ (K : set M₂), is_compact K ∧ f '' metric.ball 0 r ⊆ K :=
⟨λ hf, hf.image_ball_subset_compact r,
λ ⟨K, hK, hKr⟩, (is_compact_operator_iff_exists_mem_nhds_image_subset_compact f).mpr
⟨metric.ball 0 r, ball_mem_nhds _ hr, K, hK, hKr⟩⟩
lemma is_compact_operator_iff_image_closed_ball_subset_compact [has_continuous_const_smul 𝕜₂ M₂]
(f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
is_compact_operator f ↔ ∃ (K : set M₂), is_compact K ∧ f '' metric.closed_ball 0 r ⊆ K :=
⟨λ hf, hf.image_closed_ball_subset_compact r,
λ ⟨K, hK, hKr⟩, (is_compact_operator_iff_exists_mem_nhds_image_subset_compact f).mpr
⟨metric.closed_ball 0 r, closed_ball_mem_nhds _ hr, K, hK, hKr⟩⟩
lemma is_compact_operator_iff_is_compact_closure_image_ball [has_continuous_const_smul 𝕜₂ M₂]
[t2_space M₂] (f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
is_compact_operator f ↔ is_compact (closure $ f '' metric.ball 0 r) :=
⟨λ hf, hf.is_compact_closure_image_ball r,
λ hf, (is_compact_operator_iff_exists_mem_nhds_is_compact_closure_image f).mpr
⟨metric.ball 0 r, ball_mem_nhds _ hr, hf⟩⟩
lemma is_compact_operator_iff_is_compact_closure_image_closed_ball
[has_continuous_const_smul 𝕜₂ M₂] [t2_space M₂] (f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
is_compact_operator f ↔ is_compact (closure $ f '' metric.closed_ball 0 r) :=
⟨λ hf, hf.is_compact_closure_image_closed_ball r,
λ hf, (is_compact_operator_iff_exists_mem_nhds_is_compact_closure_image f).mpr
⟨metric.closed_ball 0 r, closed_ball_mem_nhds _ hr, hf⟩⟩
end normed_space
end characterizations
section operations
variables {R₁ R₂ R₃ R₄ : Type*} [semiring R₁] [semiring R₂] [comm_semiring R₃] [comm_semiring R₄]
{σ₁₂ : R₁ →+* R₂} {σ₁₄ : R₁ →+* R₄} {σ₃₄ : R₃ →+* R₄} {M₁ M₂ M₃ M₄ : Type*}
[topological_space M₁] [add_comm_monoid M₁] [topological_space M₂] [add_comm_monoid M₂]
[topological_space M₃] [add_comm_group M₃] [topological_space M₄] [add_comm_group M₄]
lemma is_compact_operator.smul {S : Type*} [monoid S] [distrib_mul_action S M₂]
[has_continuous_const_smul S M₂] {f : M₁ → M₂}
(hf : is_compact_operator f) (c : S) :
is_compact_operator (c • f) :=
let ⟨K, hK, hKf⟩ := hf in ⟨c • K, hK.image $ continuous_id.const_smul c,
mem_of_superset hKf (λ x hx, smul_mem_smul_set hx)⟩
lemma is_compact_operator.add [has_continuous_add M₂] {f g : M₁ → M₂}
(hf : is_compact_operator f) (hg : is_compact_operator g) :
is_compact_operator (f + g) :=
let ⟨A, hA, hAf⟩ := hf, ⟨B, hB, hBg⟩ := hg in
⟨A + B, hA.add hB, mem_of_superset (inter_mem hAf hBg) (λ x ⟨hxA, hxB⟩, set.add_mem_add hxA hxB)⟩
lemma is_compact_operator.neg [has_continuous_neg M₄] {f : M₁ → M₄}
(hf : is_compact_operator f) : is_compact_operator (-f) :=
let ⟨K, hK, hKf⟩ := hf in
⟨-K, hK.neg, mem_of_superset hKf $ λ x (hx : f x ∈ K), set.neg_mem_neg.mpr hx⟩
lemma is_compact_operator.sub [topological_add_group M₄] {f g : M₁ → M₄}
(hf : is_compact_operator f) (hg : is_compact_operator g) : is_compact_operator (f - g) :=
by rw sub_eq_add_neg; exact hf.add hg.neg
variables (σ₁₄ M₁ M₄)
/-- The submodule of compact continuous linear maps. -/
def compact_operator [module R₁ M₁] [module R₄ M₄] [has_continuous_const_smul R₄ M₄]
[topological_add_group M₄] :
submodule R₄ (M₁ →SL[σ₁₄] M₄) :=
{ carrier := {f | is_compact_operator f},
add_mem' := λ f g hf hg, hf.add hg,
zero_mem' := is_compact_operator_zero,
smul_mem' := λ c f hf, hf.smul c }
end operations
section comp
variables {R₁ R₂ R₃ : Type*} [semiring R₁] [semiring R₂] [semiring R₃] {σ₁₂ : R₁ →+* R₂}
{σ₂₃ : R₂ →+* R₃} {M₁ M₂ M₃ : Type*} [topological_space M₁] [topological_space M₂]
[topological_space M₃] [add_comm_monoid M₁] [module R₁ M₁]
lemma is_compact_operator.comp_clm [add_comm_monoid M₂] [module R₂ M₂] {f : M₂ → M₃}
(hf : is_compact_operator f) (g : M₁ →SL[σ₁₂] M₂) :
is_compact_operator (f ∘ g) :=
begin
have := g.continuous.tendsto 0,
rw map_zero at this,
rcases hf with ⟨K, hK, hKf⟩,
exact ⟨K, hK, this hKf⟩
end
lemma is_compact_operator.continuous_comp {f : M₁ → M₂} (hf : is_compact_operator f) {g : M₂ → M₃}
(hg : continuous g) :
is_compact_operator (g ∘ f) :=
begin
rcases hf with ⟨K, hK, hKf⟩,
refine ⟨g '' K, hK.image hg, mem_of_superset hKf _⟩,
nth_rewrite 1 preimage_comp,
exact preimage_mono (subset_preimage_image _ _)
end
lemma is_compact_operator.clm_comp [add_comm_monoid M₂] [module R₂ M₂] [add_comm_monoid M₃]
[module R₃ M₃] {f : M₁ → M₂} (hf : is_compact_operator f) (g : M₂ →SL[σ₂₃] M₃) :
is_compact_operator (g ∘ f) :=
hf.continuous_comp g.continuous
end comp
section cod_restrict
variables {R₁ R₂ : Type*} [semiring R₁] [semiring R₂] {σ₁₂ : R₁ →+* R₂}
{M₁ M₂ : Type*} [topological_space M₁] [topological_space M₂]
[add_comm_monoid M₁] [add_comm_monoid M₂] [module R₁ M₁] [module R₂ M₂]
lemma is_compact_operator.cod_restrict {f : M₁ → M₂} (hf : is_compact_operator f)
{V : submodule R₂ M₂} (hV : ∀ x, f x ∈ V) (h_closed : is_closed (V : set M₂)):
is_compact_operator (set.cod_restrict f V hV) :=
let ⟨K, hK, hKf⟩ := hf in
⟨coe ⁻¹' K, (closed_embedding_subtype_coe h_closed).is_compact_preimage hK, hKf⟩
end cod_restrict
section restrict
variables {R₁ R₂ R₃ : Type*} [semiring R₁] [semiring R₂] [semiring R₃] {σ₁₂ : R₁ →+* R₂}
{σ₂₃ : R₂ →+* R₃} {M₁ M₂ M₃ : Type*} [topological_space M₁] [uniform_space M₂]
[topological_space M₃] [add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₃]
[module R₁ M₁] [module R₂ M₂] [module R₃ M₃]
/-- If a compact operator preserves a closed submodule, its restriction to that submodule is
compact.
Note that, following mathlib's convention in linear algebra, `restrict` designates the restriction
of an endomorphism `f : E →ₗ E` to an endomorphism `f' : ↥V →ₗ ↥V`. To prove that the restriction
`f' : ↥U →ₛₗ ↥V` of a compact operator `f : E →ₛₗ F` is compact, apply
`is_compact_operator.cod_restrict` to `f ∘ U.subtypeL`, which is compact by
`is_compact_operator.comp_clm`. -/
lemma is_compact_operator.restrict {f : M₁ →ₗ[R₁] M₁} (hf : is_compact_operator f)
{V : submodule R₁ M₁} (hV : ∀ v ∈ V, f v ∈ V) (h_closed : is_closed (V : set M₁)):
is_compact_operator (f.restrict hV) :=
(hf.comp_clm V.subtypeL).cod_restrict (set_like.forall.2 hV) h_closed
/-- If a compact operator preserves a complete submodule, its restriction to that submodule is
compact.
Note that, following mathlib's convention in linear algebra, `restrict` designates the restriction
of an endomorphism `f : E →ₗ E` to an endomorphism `f' : ↥V →ₗ ↥V`. To prove that the restriction
`f' : ↥U →ₛₗ ↥V` of a compact operator `f : E →ₛₗ F` is compact, apply
`is_compact_operator.cod_restrict` to `f ∘ U.subtypeL`, which is compact by
`is_compact_operator.comp_clm`. -/
lemma is_compact_operator.restrict' [separated_space M₂] {f : M₂ →ₗ[R₂] M₂}
(hf : is_compact_operator f) {V : submodule R₂ M₂} (hV : ∀ v ∈ V, f v ∈ V)
[hcomplete : complete_space V] : is_compact_operator (f.restrict hV) :=
hf.restrict hV (complete_space_coe_iff_is_complete.mp hcomplete).is_closed
end restrict
section continuous
variables {𝕜₁ 𝕜₂ : Type*} [nontrivially_normed_field 𝕜₁] [nontrivially_normed_field 𝕜₂]
{σ₁₂ : 𝕜₁ →+* 𝕜₂} [ring_hom_isometric σ₁₂] {M₁ M₂ : Type*} [topological_space M₁]
[add_comm_group M₁] [topological_space M₂] [add_comm_group M₂] [module 𝕜₁ M₁] [module 𝕜₂ M₂]
[topological_add_group M₁] [has_continuous_const_smul 𝕜₁ M₁]
[topological_add_group M₂] [has_continuous_smul 𝕜₂ M₂]
@[continuity] lemma is_compact_operator.continuous {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : is_compact_operator f) : continuous f :=
begin
letI : uniform_space M₂ := topological_add_group.to_uniform_space _,
haveI : uniform_add_group M₂ := topological_add_comm_group_is_uniform,
-- Since `f` is linear, we only need to show that it is continuous at zero.
-- Let `U` be a neighborhood of `0` in `M₂`.
refine continuous_of_continuous_at_zero f (λ U hU, _),
rw map_zero at hU,
-- The compactness of `f` gives us a compact set `K : set M₂` such that `f ⁻¹' K` is a
-- neighborhood of `0` in `M₁`.
rcases hf with ⟨K, hK, hKf⟩,
-- But any compact set is totally bounded, hence Von-Neumann bounded. Thus, `K` absorbs `U`.
-- This gives `r > 0` such that `∀ a : 𝕜₂, r ≤ ∥a∥ → K ⊆ a • U`.
rcases hK.totally_bounded.is_vonN_bounded 𝕜₂ hU with ⟨r, hr, hrU⟩,
-- Choose `c : 𝕜₂` with `r < ∥c∥`.
rcases normed_field.exists_lt_norm 𝕜₁ r with ⟨c, hc⟩,
have hcnz : c ≠ 0 := ne_zero_of_norm_ne_zero (hr.trans hc).ne.symm,
-- We have `f ⁻¹' ((σ₁₂ c⁻¹) • K) = c⁻¹ • f ⁻¹' K ∈ 𝓝 0`. Thus, showing that
-- `(σ₁₂ c⁻¹) • K ⊆ U` is enough to deduce that `f ⁻¹' U ∈ 𝓝 0`.
suffices : (σ₁₂ $ c⁻¹) • K ⊆ U,
{ refine mem_of_superset _ this,
have : is_unit c⁻¹ := hcnz.is_unit.inv,
rwa [mem_map, preimage_smul_setₛₗ _ _ _ f this, set_smul_mem_nhds_zero_iff (inv_ne_zero hcnz)],
apply_instance },
-- Since `σ₁₂ c⁻¹` = `(σ₁₂ c)⁻¹`, we have to prove that `K ⊆ σ₁₂ c • U`.
rw [map_inv₀, ← subset_set_smul_iff₀ ((map_ne_zero σ₁₂).mpr hcnz)],
-- But `σ₁₂` is isometric, so `∥σ₁₂ c∥ = ∥c∥ > r`, which concludes the argument since
-- `∀ a : 𝕜₂, r ≤ ∥a∥ → K ⊆ a • U`.
refine hrU (σ₁₂ c) _,
rw ring_hom_isometric.is_iso,
exact hc.le
end
/-- Upgrade a compact `linear_map` to a `continuous_linear_map`. -/
def continuous_linear_map.mk_of_is_compact_operator {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : is_compact_operator f) : M₁ →SL[σ₁₂] M₂ :=
⟨f, hf.continuous⟩
@[simp] lemma continuous_linear_map.mk_of_is_compact_operator_to_linear_map {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : is_compact_operator f) :
(continuous_linear_map.mk_of_is_compact_operator hf : M₁ →ₛₗ[σ₁₂] M₂) = f :=
rfl
@[simp] lemma continuous_linear_map.coe_mk_of_is_compact_operator {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : is_compact_operator f) :
(continuous_linear_map.mk_of_is_compact_operator hf : M₁ → M₂) = f :=
rfl
lemma continuous_linear_map.mk_of_is_compact_operator_mem_compact_operator {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : is_compact_operator f) :
continuous_linear_map.mk_of_is_compact_operator hf ∈ compact_operator σ₁₂ M₁ M₂ :=
hf
end continuous
lemma is_closed_set_of_is_compact_operator {𝕜₁ 𝕜₂ : Type*} [nontrivially_normed_field 𝕜₁]
[nontrivially_normed_field 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂} [ring_hom_isometric σ₁₂] {M₁ M₂ : Type*}
[seminormed_add_comm_group M₁] [normed_add_comm_group M₂] [normed_space 𝕜₁ M₁]
[normed_space 𝕜₂ M₂] [complete_space M₂] :
is_closed {f : M₁ →SL[σ₁₂] M₂ | is_compact_operator f} :=
begin
refine is_closed_of_closure_subset _,
rintros u hu,
rw metric.mem_closure_iff at hu,
suffices : totally_bounded (u '' metric.closed_ball 0 1),
{ change is_compact_operator (u : M₁ →ₛₗ[σ₁₂] M₂),
rw is_compact_operator_iff_is_compact_closure_image_closed_ball (u : M₁ →ₛₗ[σ₁₂] M₂)
zero_lt_one,
exact compact_of_totally_bounded_is_closed this.closure is_closed_closure },
rw metric.totally_bounded_iff,
intros ε hε,
rcases hu (ε/2) (by linarith) with ⟨v, hv, huv⟩,
rcases (hv.is_compact_closure_image_closed_ball 1).finite_cover_balls
(show 0 < ε/2, by linarith) with ⟨T, -, hT, hTv⟩,
have hTv : v '' closed_ball 0 1 ⊆ _ := subset_closure.trans hTv,
refine ⟨T, hT, _⟩,
rw image_subset_iff at ⊢ hTv,
intros x hx,
specialize hTv hx,
rw [mem_preimage, mem_Union₂] at ⊢ hTv,
rcases hTv with ⟨t, ht, htx⟩,
refine ⟨t, ht, _⟩,
suffices : dist (u x) (v x) < ε/2,
{ rw mem_ball at *,
linarith [dist_triangle (u x) (v x) t] },
rw mem_closed_ball_zero_iff at hx,
calc dist (u x) (v x)
= ∥u x - v x∥ : dist_eq_norm _ _
... = ∥(u - v) x∥ : by rw continuous_linear_map.sub_apply; refl
... ≤ ∥u - v∥ : (u - v).unit_le_op_norm x hx
... = dist u v : (dist_eq_norm _ _).symm
... < ε/2 : huv
end
lemma compact_operator_topological_closure {𝕜₁ 𝕜₂ : Type*} [nontrivially_normed_field 𝕜₁]
[nontrivially_normed_field 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂} [ring_hom_isometric σ₁₂] {M₁ M₂ : Type*}
[seminormed_add_comm_group M₁] [normed_add_comm_group M₂] [normed_space 𝕜₁ M₁]
[normed_space 𝕜₂ M₂] [complete_space M₂] :
(compact_operator σ₁₂ M₁ M₂).topological_closure = compact_operator σ₁₂ M₁ M₂ :=
set_like.ext' (is_closed_set_of_is_compact_operator.closure_eq)
lemma is_compact_operator_of_tendsto {ι 𝕜₁ 𝕜₂ : Type*} [nontrivially_normed_field 𝕜₁]
[nontrivially_normed_field 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂} [ring_hom_isometric σ₁₂] {M₁ M₂ : Type*}
[seminormed_add_comm_group M₁] [normed_add_comm_group M₂] [normed_space 𝕜₁ M₁]
[normed_space 𝕜₂ M₂] [complete_space M₂] {l : filter ι} [l.ne_bot] {F : ι → M₁ →SL[σ₁₂] M₂}
{f : M₁ →SL[σ₁₂] M₂} (hf : tendsto F l (𝓝 f)) (hF : ∀ᶠ i in l, is_compact_operator (F i)) :
is_compact_operator f :=
is_closed_set_of_is_compact_operator.mem_of_tendsto hf hF
|
df9dbc51700dcd6c2d0754f3d54f58ce1eed12a7 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/ring_theory/principal_ideal_domain.lean | f37bee1fc251500cc87cab3caff680e8f7165e92 | [
"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 | 8,155 | 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, 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
|
5df1f0bfdfed0b34cb9ce751ef56eeb1e1c4fc65 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/computability/primrec.lean | b38a1ad81d0ceae72d54145e3a81e02de8a32846 | [
"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 | 51,922 | 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.equiv.list
import data.list.join
import logic.function.iterate
/-!
# The primitive recursive functions
The primitive recursive functions are the least collection of functions
`nat → nat` which are closed under projections (using the mkpair
pairing function), composition, zero, successor, and primitive recursion
(i.e. nat.rec where the motive is C n := nat).
We can extend this definition to a large class of basic types by
using canonical encodings of types as natural numbers (Gödel numbering),
which we implement through the type class `encodable`. (More precisely,
we need that the composition of encode with decode yields a
primitive recursive function, so we have the `primcodable` type class
for this.)
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open denumerable encodable function
namespace nat
def elim {C : Sort*} : C → (ℕ → C → C) → ℕ → C := @nat.rec (λ _, C)
@[simp] theorem elim_zero {C} (a f) : @nat.elim C a f 0 = a := rfl
@[simp] theorem elim_succ {C} (a f n) :
@nat.elim C a f (succ n) = f n (nat.elim a f n) := rfl
def cases {C : Sort*} (a : C) (f : ℕ → C) : ℕ → C := nat.elim a (λ n _, f n)
@[simp] theorem cases_zero {C} (a f) : @nat.cases C a f 0 = a := rfl
@[simp] theorem cases_succ {C} (a f n) : @nat.cases C a f (succ n) = f n := rfl
@[simp, reducible] def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α :=
f n.unpair.1 n.unpair.2
/-- The primitive recursive functions `ℕ → ℕ`. -/
inductive primrec : (ℕ → ℕ) → Prop
| zero : primrec (λ n, 0)
| succ : primrec succ
| left : primrec (λ n, n.unpair.1)
| right : primrec (λ n, n.unpair.2)
| pair {f g} : primrec f → primrec g → primrec (λ n, mkpair (f n) (g n))
| comp {f g} : primrec f → primrec g → primrec (λ n, f (g n))
| prec {f g} : primrec f → primrec g → primrec (unpaired (λ z n,
n.elim (f z) (λ y IH, g $ mkpair z $ mkpair y IH)))
namespace primrec
theorem of_eq {f g : ℕ → ℕ} (hf : primrec f) (H : ∀ n, f n = g n) : primrec g :=
(funext H : f = g) ▸ hf
theorem const : ∀ (n : ℕ), primrec (λ _, n)
| 0 := zero
| (n+1) := succ.comp (const n)
protected theorem id : primrec id :=
(left.pair right).of_eq $ λ n, by simp
theorem prec1 {f} (m : ℕ) (hf : primrec f) : primrec (λ n,
n.elim m (λ y IH, f $ mkpair y IH)) :=
((prec (const m) (hf.comp right)).comp
(zero.pair primrec.id)).of_eq $
λ n, by simp; dsimp; rw [unpair_mkpair]
theorem cases1 {f} (m : ℕ) (hf : primrec f) : primrec (nat.cases m f) :=
(prec1 m (hf.comp left)).of_eq $ by simp [cases]
theorem cases {f g} (hf : primrec f) (hg : primrec g) :
primrec (unpaired (λ z n, n.cases (f z) (λ y, g $ mkpair z y))) :=
(prec hf (hg.comp (pair left (left.comp right)))).of_eq $ by simp [cases]
protected theorem swap : primrec (unpaired (swap mkpair)) :=
(pair right left).of_eq $ λ n, by simp
theorem swap' {f} (hf : primrec (unpaired f)) : primrec (unpaired (swap f)) :=
(hf.comp primrec.swap).of_eq $ λ n, by simp
theorem pred : primrec pred :=
(cases1 0 primrec.id).of_eq $ λ n, by cases n; simp *
theorem add : primrec (unpaired (+)) :=
(prec primrec.id ((succ.comp right).comp right)).of_eq $
λ p, by simp; induction p.unpair.2; simp [*, -add_comm, add_succ]
theorem sub : primrec (unpaired has_sub.sub) :=
(prec primrec.id ((pred.comp right).comp right)).of_eq $
λ p, by simp; induction p.unpair.2; simp [*, -add_comm, sub_succ]
theorem mul : primrec (unpaired (*)) :=
(prec zero (add.comp (pair left (right.comp right)))).of_eq $
λ p, by simp; induction p.unpair.2; simp [*, mul_succ, add_comm]
theorem pow : primrec (unpaired (^)) :=
(prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq $
λ p, by simp; induction p.unpair.2; simp [*, pow_succ']
end primrec
end nat
/-- A `primcodable` type is an `encodable` type for which
the encode/decode functions are primitive recursive. -/
class primcodable (α : Type*) extends encodable α :=
(prim [] : nat.primrec (λ n, encodable.encode (decode n)))
namespace primcodable
open nat.primrec
@[priority 10] instance of_denumerable (α) [denumerable α] : primcodable α :=
⟨succ.of_eq $ by simp⟩
def of_equiv (α) {β} [primcodable α] (e : β ≃ α) : primcodable β :=
{ prim := (primcodable.prim α).of_eq $ λ n,
show encode (decode α n) =
(option.cases_on (option.map e.symm (decode α n))
0 (λ a, nat.succ (encode (e a))) : ℕ),
by cases decode α n; dsimp; simp,
..encodable.of_equiv α e }
instance empty : primcodable empty :=
⟨zero⟩
instance unit : primcodable punit :=
⟨(cases1 1 zero).of_eq $ λ n, by cases n; simp⟩
instance option {α : Type*} [h : primcodable α] : primcodable (option α) :=
⟨(cases1 1 ((cases1 0 (succ.comp succ)).comp (primcodable.prim α))).of_eq $
λ n, by cases n; simp; cases decode α n; refl⟩
instance bool : primcodable bool :=
⟨(cases1 1 (cases1 2 zero)).of_eq $
λ n, begin
cases n, {refl}, cases n, {refl},
rw decode_ge_two, {refl},
exact dec_trivial
end⟩
end primcodable
/-- `primrec f` means `f` is primitive recursive (after
encoding its input and output as natural numbers). -/
def primrec {α β} [primcodable α] [primcodable β] (f : α → β) : Prop :=
nat.primrec (λ n, encode ((decode α n).map f))
namespace primrec
variables {α : Type*} {β : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable σ]
open nat.primrec
protected theorem encode : primrec (@encode α _) :=
(primcodable.prim α).of_eq $ λ n, by cases decode α n; refl
protected theorem decode : primrec (decode α) :=
succ.comp (primcodable.prim α)
theorem dom_denumerable {α β} [denumerable α] [primcodable β]
{f : α → β} : primrec f ↔ nat.primrec (λ n, encode (f (of_nat α n))) :=
⟨λ h, (pred.comp h).of_eq $ λ n, by simp; refl,
λ h, (succ.comp h).of_eq $ λ n, by simp; refl⟩
theorem nat_iff {f : ℕ → ℕ} : primrec f ↔ nat.primrec f :=
dom_denumerable
theorem encdec : primrec (λ n, encode (decode α n)) :=
nat_iff.2 (primcodable.prim α)
theorem option_some : primrec (@some α) :=
((cases1 0 (succ.comp succ)).comp (primcodable.prim α)).of_eq $
λ n, by cases decode α n; simp
theorem of_eq {f g : α → σ} (hf : primrec f) (H : ∀ n, f n = g n) : primrec g :=
(funext H : f = g) ▸ hf
theorem const (x : σ) : primrec (λ a : α, x) :=
((cases1 0 (const (encode x).succ)).comp (primcodable.prim α)).of_eq $
λ n, by cases decode α n; refl
protected theorem id : primrec (@id α) :=
(primcodable.prim α).of_eq $ by simp
theorem comp {f : β → σ} {g : α → β}
(hf : primrec f) (hg : primrec g) : primrec (λ a, f (g a)) :=
((cases1 0 (hf.comp $ pred.comp hg)).comp (primcodable.prim α)).of_eq $
λ n, begin
cases decode α n, {refl},
simp [encodek]
end
theorem succ : primrec nat.succ := nat_iff.2 nat.primrec.succ
theorem pred : primrec nat.pred := nat_iff.2 nat.primrec.pred
theorem encode_iff {f : α → σ} : primrec (λ a, encode (f a)) ↔ primrec f :=
⟨λ h, nat.primrec.of_eq h $ λ n, by cases decode α n; refl,
primrec.encode.comp⟩
theorem of_nat_iff {α β} [denumerable α] [primcodable β]
{f : α → β} : primrec f ↔ primrec (λ n, f (of_nat α n)) :=
dom_denumerable.trans $ nat_iff.symm.trans encode_iff
protected theorem of_nat (α) [denumerable α] : primrec (of_nat α) :=
of_nat_iff.1 primrec.id
theorem option_some_iff {f : α → σ} : primrec (λ a, some (f a)) ↔ primrec f :=
⟨λ h, encode_iff.1 $ pred.comp $ encode_iff.2 h, option_some.comp⟩
theorem of_equiv {β} {e : β ≃ α} :
by haveI := primcodable.of_equiv α e; exact
primrec e :=
by letI : primcodable β := primcodable.of_equiv α e; exact encode_iff.1 primrec.encode
theorem of_equiv_symm {β} {e : β ≃ α} :
by haveI := primcodable.of_equiv α e; exact
primrec e.symm :=
by letI := primcodable.of_equiv α e; exact
encode_iff.1
(show primrec (λ a, encode (e (e.symm a))), by simp [primrec.encode])
theorem of_equiv_iff {β} (e : β ≃ α)
{f : σ → β} :
by haveI := primcodable.of_equiv α e; exact
primrec (λ a, e (f a)) ↔ primrec f :=
by letI := primcodable.of_equiv α e; exact
⟨λ h, (of_equiv_symm.comp h).of_eq (λ a, by simp), of_equiv.comp⟩
theorem of_equiv_symm_iff {β} (e : β ≃ α)
{f : σ → α} :
by haveI := primcodable.of_equiv α e; exact
primrec (λ a, e.symm (f a)) ↔ primrec f :=
by letI := primcodable.of_equiv α e; exact
⟨λ h, (of_equiv.comp h).of_eq (λ a, by simp), of_equiv_symm.comp⟩
end primrec
namespace primcodable
open nat.primrec
instance prod {α β} [primcodable α] [primcodable β] : primcodable (α × β) :=
⟨((cases zero ((cases zero succ).comp
(pair right ((primcodable.prim β).comp left)))).comp
(pair right ((primcodable.prim α).comp left))).of_eq $
λ n, begin
simp [nat.unpaired],
cases decode α n.unpair.1, { simp },
cases decode β n.unpair.2; simp
end⟩
end primcodable
namespace primrec
variables {α : Type*} {σ : Type*} [primcodable α] [primcodable σ]
open nat.primrec
theorem fst {α β} [primcodable α] [primcodable β] :
primrec (@prod.fst α β) :=
((cases zero ((cases zero (nat.primrec.succ.comp left)).comp
(pair right ((primcodable.prim β).comp left)))).comp
(pair right ((primcodable.prim α).comp left))).of_eq $
λ n, begin
simp,
cases decode α n.unpair.1; simp,
cases decode β n.unpair.2; simp
end
theorem snd {α β} [primcodable α] [primcodable β] :
primrec (@prod.snd α β) :=
((cases zero ((cases zero (nat.primrec.succ.comp right)).comp
(pair right ((primcodable.prim β).comp left)))).comp
(pair right ((primcodable.prim α).comp left))).of_eq $
λ n, begin
simp,
cases decode α n.unpair.1; simp,
cases decode β n.unpair.2; simp
end
theorem pair {α β γ} [primcodable α] [primcodable β] [primcodable γ]
{f : α → β} {g : α → γ} (hf : primrec f) (hg : primrec g) :
primrec (λ a, (f a, g a)) :=
((cases1 0 (nat.primrec.succ.comp $
pair (nat.primrec.pred.comp hf) (nat.primrec.pred.comp hg))).comp
(primcodable.prim α)).of_eq $
λ n, by cases decode α n; simp [encodek]; refl
theorem unpair : primrec nat.unpair :=
(pair (nat_iff.2 nat.primrec.left) (nat_iff.2 nat.primrec.right)).of_eq $
λ n, by simp
theorem list_nth₁ : ∀ (l : list α), primrec l.nth
| [] := dom_denumerable.2 zero
| (a::l) := dom_denumerable.2 $
(cases1 (encode a).succ $ dom_denumerable.1 $ list_nth₁ l).of_eq $
λ n, by cases n; simp
end primrec
/-- `primrec₂ f` means `f` is a binary primitive recursive function.
This is technically unnecessary since we can always curry all
the arguments together, but there are enough natural two-arg
functions that it is convenient to express this directly. -/
def primrec₂ {α β σ} [primcodable α] [primcodable β] [primcodable σ] (f : α → β → σ) :=
primrec (λ p : α × β, f p.1 p.2)
/-- `primrec_pred p` means `p : α → Prop` is a (decidable)
primitive recursive predicate, which is to say that
`to_bool ∘ p : α → bool` is primitive recursive. -/
def primrec_pred {α} [primcodable α] (p : α → Prop)
[decidable_pred p] := primrec (λ a, to_bool (p a))
/-- `primrec_rel p` means `p : α → β → Prop` is a (decidable)
primitive recursive relation, which is to say that
`to_bool ∘ p : α → β → bool` is primitive recursive. -/
def primrec_rel {α β} [primcodable α] [primcodable β]
(s : α → β → Prop) [∀ a b, decidable (s a b)] :=
primrec₂ (λ a b, to_bool (s a b))
namespace primrec₂
variables {α : Type*} {β : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable σ]
theorem of_eq {f g : α → β → σ} (hg : primrec₂ f) (H : ∀ a b, f a b = g a b) : primrec₂ g :=
(by funext a b; apply H : f = g) ▸ hg
theorem const (x : σ) : primrec₂ (λ (a : α) (b : β), x) := primrec.const _
protected theorem pair : primrec₂ (@prod.mk α β) :=
primrec.pair primrec.fst primrec.snd
theorem left : primrec₂ (λ (a : α) (b : β), a) := primrec.fst
theorem right : primrec₂ (λ (a : α) (b : β), b) := primrec.snd
theorem mkpair : primrec₂ nat.mkpair :=
by simp [primrec₂, primrec]; constructor
theorem unpaired {f : ℕ → ℕ → α} : primrec (nat.unpaired f) ↔ primrec₂ f :=
⟨λ h, by simpa using h.comp mkpair,
λ h, h.comp primrec.unpair⟩
theorem unpaired' {f : ℕ → ℕ → ℕ} : nat.primrec (nat.unpaired f) ↔ primrec₂ f :=
primrec.nat_iff.symm.trans unpaired
theorem encode_iff {f : α → β → σ} : primrec₂ (λ a b, encode (f a b)) ↔ primrec₂ f :=
primrec.encode_iff
theorem option_some_iff {f : α → β → σ} : primrec₂ (λ a b, some (f a b)) ↔ primrec₂ f :=
primrec.option_some_iff
theorem of_nat_iff {α β σ}
[denumerable α] [denumerable β] [primcodable σ]
{f : α → β → σ} : primrec₂ f ↔ primrec₂ (λ m n : ℕ,
f (of_nat α m) (of_nat β n)) :=
(primrec.of_nat_iff.trans $ by simp).trans unpaired
theorem uncurry {f : α → β → σ} : primrec (function.uncurry f) ↔ primrec₂ f :=
by rw [show function.uncurry f = λ (p : α × β), f p.1 p.2,
from funext $ λ ⟨a, b⟩, rfl]; refl
theorem curry {f : α × β → σ} : primrec₂ (function.curry f) ↔ primrec f :=
by rw [← uncurry, function.uncurry_curry]
end primrec₂
section comp
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable δ] [primcodable σ]
theorem primrec.comp₂ {f : γ → σ} {g : α → β → γ}
(hf : primrec f) (hg : primrec₂ g) :
primrec₂ (λ a b, f (g a b)) := hf.comp hg
theorem primrec₂.comp
{f : β → γ → σ} {g : α → β} {h : α → γ}
(hf : primrec₂ f) (hg : primrec g) (hh : primrec h) :
primrec (λ a, f (g a) (h a)) := hf.comp (hg.pair hh)
theorem primrec₂.comp₂
{f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ}
(hf : primrec₂ f) (hg : primrec₂ g) (hh : primrec₂ h) :
primrec₂ (λ a b, f (g a b) (h a b)) := hf.comp hg hh
theorem primrec_pred.comp
{p : β → Prop} [decidable_pred p] {f : α → β} :
primrec_pred p → primrec f →
primrec_pred (λ a, p (f a)) := primrec.comp
theorem primrec_rel.comp
{R : β → γ → Prop} [∀ a b, decidable (R a b)] {f : α → β} {g : α → γ} :
primrec_rel R → primrec f → primrec g →
primrec_pred (λ a, R (f a) (g a)) := primrec₂.comp
theorem primrec_rel.comp₂
{R : γ → δ → Prop} [∀ a b, decidable (R a b)] {f : α → β → γ} {g : α → β → δ} :
primrec_rel R → primrec₂ f → primrec₂ g →
primrec_rel (λ a b, R (f a b) (g a b)) := primrec_rel.comp
end comp
theorem primrec_pred.of_eq {α} [primcodable α]
{p q : α → Prop} [decidable_pred p] [decidable_pred q]
(hp : primrec_pred p) (H : ∀ a, p a ↔ q a) : primrec_pred q :=
primrec.of_eq hp (λ a, to_bool_congr (H a))
theorem primrec_rel.of_eq {α β} [primcodable α] [primcodable β]
{r s : α → β → Prop} [∀ a b, decidable (r a b)] [∀ a b, decidable (s a b)]
(hr : primrec_rel r) (H : ∀ a b, r a b ↔ s a b) : primrec_rel s :=
primrec₂.of_eq hr (λ a b, to_bool_congr (H a b))
namespace primrec₂
variables {α : Type*} {β : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable σ]
open nat.primrec
theorem swap {f : α → β → σ} (h : primrec₂ f) : primrec₂ (swap f) :=
h.comp₂ primrec₂.right primrec₂.left
theorem nat_iff {f : α → β → σ} : primrec₂ f ↔
nat.primrec (nat.unpaired $ λ m n : ℕ,
encode $ (decode α m).bind $ λ a, (decode β n).map (f a)) :=
have ∀ (a : option α) (b : option β),
option.map (λ (p : α × β), f p.1 p.2)
(option.bind a (λ (a : α), option.map (prod.mk a) b)) =
option.bind a (λ a, option.map (f a) b),
by intros; cases a; [refl, {cases b; refl}],
by simp [primrec₂, primrec, this]
theorem nat_iff' {f : α → β → σ} : primrec₂ f ↔ primrec₂ (λ m n : ℕ,
option.bind (decode α m) (λ a, option.map (f a) (decode β n))) :=
nat_iff.trans $ unpaired'.trans encode_iff
end primrec₂
namespace primrec
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable δ] [primcodable σ]
theorem to₂ {f : α × β → σ} (hf : primrec f) : primrec₂ (λ a b, f (a, b)) :=
hf.of_eq $ λ ⟨a, b⟩, rfl
theorem nat_elim {f : α → β} {g : α → ℕ × β → β}
(hf : primrec f) (hg : primrec₂ g) :
primrec₂ (λ a (n : ℕ), n.elim (f a) (λ n IH, g a (n, IH))) :=
primrec₂.nat_iff.2 $ ((nat.primrec.cases nat.primrec.zero $
(nat.primrec.prec hf $ nat.primrec.comp hg $ nat.primrec.left.pair $
(nat.primrec.left.comp nat.primrec.right).pair $
nat.primrec.pred.comp $ nat.primrec.right.comp nat.primrec.right).comp $
nat.primrec.right.pair $
nat.primrec.right.comp nat.primrec.left).comp $
nat.primrec.id.pair $ (primcodable.prim α).comp nat.primrec.left).of_eq $
λ n, begin
simp,
cases decode α n.unpair.1 with a, {refl},
simp [encodek],
induction n.unpair.2 with m; simp [encodek],
simp [ih, encodek]
end
theorem nat_elim' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β}
(hf : primrec f) (hg : primrec g) (hh : primrec₂ h) :
primrec (λ a, (f a).elim (g a) (λ n IH, h a (n, IH))) :=
(nat_elim hg hh).comp primrec.id hf
theorem nat_elim₁ {f : ℕ → α → α} (a : α) (hf : primrec₂ f) :
primrec (nat.elim a f) :=
nat_elim' primrec.id (const a) $ comp₂ hf primrec₂.right
theorem nat_cases' {f : α → β} {g : α → ℕ → β}
(hf : primrec f) (hg : primrec₂ g) :
primrec₂ (λ a, nat.cases (f a) (g a)) :=
nat_elim hf $ hg.comp₂ primrec₂.left $
comp₂ fst primrec₂.right
theorem nat_cases {f : α → ℕ} {g : α → β} {h : α → ℕ → β}
(hf : primrec f) (hg : primrec g) (hh : primrec₂ h) :
primrec (λ a, (f a).cases (g a) (h a)) :=
(nat_cases' hg hh).comp primrec.id hf
theorem nat_cases₁ {f : ℕ → α} (a : α) (hf : primrec f) :
primrec (nat.cases a f) :=
nat_cases primrec.id (const a) (comp₂ hf primrec₂.right)
theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β}
(hf : primrec f) (hg : primrec g) (hh : primrec₂ h) :
primrec (λ a, (h a)^[f a] (g a)) :=
(nat_elim' hf hg (hh.comp₂ primrec₂.left $ snd.comp₂ primrec₂.right)).of_eq $
λ a, by induction f a; simp [*, function.iterate_succ']
theorem option_cases {o : α → option β} {f : α → σ} {g : α → β → σ}
(ho : primrec o) (hf : primrec f) (hg : primrec₂ g) :
@primrec _ σ _ _ (λ a, option.cases_on (o a) (f a) (g a)) :=
encode_iff.1 $
(nat_cases (encode_iff.2 ho) (encode_iff.2 hf) $
pred.comp₂ $ primrec₂.encode_iff.2 $
(primrec₂.nat_iff'.1 hg).comp₂
((@primrec.encode α _).comp fst).to₂
primrec₂.right).of_eq $
λ a, by cases o a with b; simp [encodek]; refl
theorem option_bind {f : α → option β} {g : α → β → option σ}
(hf : primrec f) (hg : primrec₂ g) :
primrec (λ a, (f a).bind (g a)) :=
(option_cases hf (const none) hg).of_eq $
λ a, by cases f a; refl
theorem option_bind₁ {f : α → option σ} (hf : primrec f) :
primrec (λ o, option.bind o f) :=
option_bind primrec.id (hf.comp snd).to₂
theorem option_map {f : α → option β} {g : α → β → σ}
(hf : primrec f) (hg : primrec₂ g) : primrec (λ a, (f a).map (g a)) :=
option_bind hf (option_some.comp₂ hg)
theorem option_map₁ {f : α → σ} (hf : primrec f) : primrec (option.map f) :=
option_map primrec.id (hf.comp snd).to₂
theorem option_iget [inhabited α] : primrec (@option.iget α _) :=
(option_cases primrec.id (const $ default α) primrec₂.right).of_eq $
λ o, by cases o; refl
theorem option_is_some : primrec (@option.is_some α) :=
(option_cases primrec.id (const ff) (const tt).to₂).of_eq $
λ o, by cases o; refl
theorem option_get_or_else : primrec₂ (@option.get_or_else α) :=
primrec.of_eq (option_cases primrec₂.left primrec₂.right primrec₂.right) $
λ ⟨o, a⟩, by cases o; refl
theorem bind_decode_iff {f : α → β → option σ} : primrec₂ (λ a n,
(decode β n).bind (f a)) ↔ primrec₂ f :=
⟨λ h, by simpa [encodek] using
h.comp fst ((@primrec.encode β _).comp snd),
λ h, option_bind (primrec.decode.comp snd) $
h.comp (fst.comp fst) snd⟩
theorem map_decode_iff {f : α → β → σ} : primrec₂ (λ a n,
(decode β n).map (f a)) ↔ primrec₂ f :=
bind_decode_iff.trans primrec₂.option_some_iff
theorem nat_add : primrec₂ ((+) : ℕ → ℕ → ℕ) :=
primrec₂.unpaired'.1 nat.primrec.add
theorem nat_sub : primrec₂ (has_sub.sub : ℕ → ℕ → ℕ) :=
primrec₂.unpaired'.1 nat.primrec.sub
theorem nat_mul : primrec₂ ((*) : ℕ → ℕ → ℕ) :=
primrec₂.unpaired'.1 nat.primrec.mul
theorem cond {c : α → bool} {f : α → σ} {g : α → σ}
(hc : primrec c) (hf : primrec f) (hg : primrec g) :
primrec (λ a, cond (c a) (f a) (g a)) :=
(nat_cases (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq $
λ a, by cases c a; refl
theorem ite {c : α → Prop} [decidable_pred c] {f : α → σ} {g : α → σ}
(hc : primrec_pred c) (hf : primrec f) (hg : primrec g) :
primrec (λ a, if c a then f a else g a) :=
by simpa using cond hc hf hg
theorem nat_le : primrec_rel ((≤) : ℕ → ℕ → Prop) :=
(nat_cases nat_sub (const tt) (const ff).to₂).of_eq $
λ p, begin
dsimp [swap],
cases e : p.1 - p.2 with n,
{ simp [tsub_eq_zero_iff_le.1 e] },
{ simp [not_le.2 (nat.lt_of_sub_eq_succ e)] }
end
theorem nat_min : primrec₂ (@min ℕ _) := ite nat_le fst snd
theorem nat_max : primrec₂ (@max ℕ _) := ite (nat_le.comp primrec.snd primrec.fst) fst snd
theorem dom_bool (f : bool → α) : primrec f :=
(cond primrec.id (const (f tt)) (const (f ff))).of_eq $
λ b, by cases b; refl
theorem dom_bool₂ (f : bool → bool → α) : primrec₂ f :=
(cond fst
((dom_bool (f tt)).comp snd)
((dom_bool (f ff)).comp snd)).of_eq $
λ ⟨a, b⟩, by cases a; refl
protected theorem bnot : primrec bnot := dom_bool _
protected theorem band : primrec₂ band := dom_bool₂ _
protected theorem bor : primrec₂ bor := dom_bool₂ _
protected theorem not {p : α → Prop} [decidable_pred p]
(hp : primrec_pred p) : primrec_pred (λ a, ¬ p a) :=
(primrec.bnot.comp hp).of_eq $ λ n, by simp
protected theorem and {p q : α → Prop}
[decidable_pred p] [decidable_pred q]
(hp : primrec_pred p) (hq : primrec_pred q) :
primrec_pred (λ a, p a ∧ q a) :=
(primrec.band.comp hp hq).of_eq $ λ n, by simp
protected theorem or {p q : α → Prop}
[decidable_pred p] [decidable_pred q]
(hp : primrec_pred p) (hq : primrec_pred q) :
primrec_pred (λ a, p a ∨ q a) :=
(primrec.bor.comp hp hq).of_eq $ λ n, by simp
protected theorem eq [decidable_eq α] : primrec_rel (@eq α) :=
have primrec_rel (λ a b : ℕ, a = b), from
(primrec.and nat_le nat_le.swap).of_eq $
λ a, by simp [le_antisymm_iff],
(this.comp₂
(primrec.encode.comp₂ primrec₂.left)
(primrec.encode.comp₂ primrec₂.right)).of_eq $
λ a b, encode_injective.eq_iff
theorem nat_lt : primrec_rel ((<) : ℕ → ℕ → Prop) :=
(nat_le.comp snd fst).not.of_eq $ λ p, by simp
theorem option_guard {p : α → β → Prop}
[∀ a b, decidable (p a b)] (hp : primrec_rel p)
{f : α → β} (hf : primrec f) :
primrec (λ a, option.guard (p a) (f a)) :=
ite (hp.comp primrec.id hf) (option_some_iff.2 hf) (const none)
theorem option_orelse :
primrec₂ ((<|>) : option α → option α → option α) :=
(option_cases fst snd (fst.comp fst).to₂).of_eq $
λ ⟨o₁, o₂⟩, by cases o₁; cases o₂; refl
protected theorem decode₂ : primrec (decode₂ α) :=
option_bind primrec.decode $
option_guard ((@primrec.eq _ _ nat.decidable_eq).comp
(encode_iff.2 snd) (fst.comp fst)) snd
theorem list_find_index₁ {p : α → β → Prop}
[∀ a b, decidable (p a b)] (hp : primrec_rel p) :
∀ (l : list β), primrec (λ a, l.find_index (p a))
| [] := const 0
| (a::l) := ite (hp.comp primrec.id (const a)) (const 0)
(succ.comp (list_find_index₁ l))
theorem list_index_of₁ [decidable_eq α] (l : list α) :
primrec (λ a, l.index_of a) := list_find_index₁ primrec.eq l
theorem dom_fintype [fintype α] (f : α → σ) : primrec f :=
let ⟨l, nd, m⟩ := fintype.exists_univ_list α in
option_some_iff.1 $ begin
haveI := decidable_eq_of_encodable α,
refine ((list_nth₁ (l.map f)).comp (list_index_of₁ l)).of_eq (λ a, _),
rw [list.nth_map, list.nth_le_nth (list.index_of_lt_length.2 (m _)),
list.index_of_nth_le]; refl
end
theorem nat_bodd_div2 : primrec nat.bodd_div2 :=
(nat_elim' primrec.id (const (ff, 0))
(((cond fst
(pair (const ff) (succ.comp snd))
(pair (const tt) snd)).comp snd).comp snd).to₂).of_eq $
λ n, begin
simp [-nat.bodd_div2_eq],
induction n with n IH, {refl},
simp [-nat.bodd_div2_eq, nat.bodd_div2, *],
rcases nat.bodd_div2 n with ⟨_|_, m⟩; simp [nat.bodd_div2]
end
theorem nat_bodd : primrec nat.bodd := fst.comp nat_bodd_div2
theorem nat_div2 : primrec nat.div2 := snd.comp nat_bodd_div2
theorem nat_bit0 : primrec (@bit0 ℕ _) :=
nat_add.comp primrec.id primrec.id
theorem nat_bit1 : primrec (@bit1 ℕ _ _) :=
nat_add.comp nat_bit0 (const 1)
theorem nat_bit : primrec₂ nat.bit :=
(cond primrec.fst
(nat_bit1.comp primrec.snd)
(nat_bit0.comp primrec.snd)).of_eq $
λ n, by cases n.1; refl
theorem nat_div_mod : primrec₂ (λ n k : ℕ, (n / k, n % k)) :=
let f (a : ℕ × ℕ) : ℕ × ℕ := a.1.elim (0, 0) (λ _ IH,
if nat.succ IH.2 = a.2
then (nat.succ IH.1, 0)
else (IH.1, nat.succ IH.2)) in
have hf : primrec f, from
nat_elim' fst (const (0, 0)) $
((ite ((@primrec.eq ℕ _ _).comp (succ.comp $ snd.comp snd) fst)
(pair (succ.comp $ fst.comp snd) (const 0))
(pair (fst.comp snd) (succ.comp $ snd.comp snd)))
.comp (pair (snd.comp fst) (snd.comp snd))).to₂,
suffices ∀ k n, (n / k, n % k) = f (n, k),
from hf.of_eq $ λ ⟨m, n⟩, by simp [this],
λ k n, begin
have : (f (n, k)).2 + k * (f (n, k)).1 = n
∧ (0 < k → (f (n, k)).2 < k)
∧ (k = 0 → (f (n, k)).1 = 0),
{ induction n with n IH, {exact ⟨rfl, id, λ _, rfl⟩},
rw [λ n:ℕ, show f (n.succ, k) =
_root_.ite ((f (n, k)).2.succ = k)
(nat.succ (f (n, k)).1, 0)
((f (n, k)).1, (f (n, k)).2.succ), from rfl],
by_cases h : (f (n, k)).2.succ = k; simp [h],
{ have := congr_arg nat.succ IH.1,
refine ⟨_, λ k0, nat.no_confusion (h.trans k0)⟩,
rwa [← nat.succ_add, h, add_comm, ← nat.mul_succ] at this },
{ exact ⟨by rw [nat.succ_add, IH.1],
λ k0, lt_of_le_of_ne (IH.2.1 k0) h, IH.2.2⟩ } },
revert this, cases f (n, k) with D M,
simp, intros h₁ h₂ h₃,
cases nat.eq_zero_or_pos k,
{ simp [h, h₃ h] at h₁ ⊢, simp [h₁] },
{ exact (nat.div_mod_unique h).2 ⟨h₁, h₂ h⟩ }
end
theorem nat_div : primrec₂ ((/) : ℕ → ℕ → ℕ) := fst.comp₂ nat_div_mod
theorem nat_mod : primrec₂ ((%) : ℕ → ℕ → ℕ) := snd.comp₂ nat_div_mod
end primrec
section
variables {α : Type*} {β : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable σ]
variable (H : nat.primrec (λ n, encodable.encode (decode (list β) n)))
include H
open primrec
private def prim : primcodable (list β) := ⟨H⟩
private lemma list_cases'
{f : α → list β} {g : α → σ} {h : α → β × list β → σ}
(hf : by haveI := prim H; exact primrec f) (hg : primrec g)
(hh : by haveI := prim H; exact primrec₂ h) :
@primrec _ σ _ _ (λ a, list.cases_on (f a) (g a) (λ b l, h a (b, l))) :=
by letI := prim H; exact
have @primrec _ (option σ) _ _ (λ a,
(decode (option (β × list β)) (encode (f a))).map
(λ o, option.cases_on o (g a) (h a))), from
((@map_decode_iff _ (option (β × list β)) _ _ _ _ _).2 $
to₂ $ option_cases snd (hg.comp fst)
(hh.comp₂ (fst.comp₂ primrec₂.left) primrec₂.right))
.comp primrec.id (encode_iff.2 hf),
option_some_iff.1 $ this.of_eq $
λ a, by cases f a with b l; simp [encodek]; refl
private lemma list_foldl'
{f : α → list β} {g : α → σ} {h : α → σ × β → σ}
(hf : by haveI := prim H; exact primrec f) (hg : primrec g)
(hh : by haveI := prim H; exact primrec₂ h) :
primrec (λ a, (f a).foldl (λ s b, h a (s, b)) (g a)) :=
by letI := prim H; exact
let G (a : α) (IH : σ × list β) : σ × list β :=
list.cases_on IH.2 IH (λ b l, (h a (IH.1, b), l)) in
let F (a : α) (n : ℕ) := (G a)^[n] (g a, f a) in
have primrec (λ a, (F a (encode (f a))).1), from
fst.comp $ nat_iterate (encode_iff.2 hf) (pair hg hf) $
list_cases' H (snd.comp snd) snd $ to₂ $ pair
(hh.comp (fst.comp fst) $
pair ((fst.comp snd).comp fst) (fst.comp snd))
(snd.comp snd),
this.of_eq $ λ a, begin
have : ∀ n, F a n =
((list.take n (f a)).foldl (λ s b, h a (s, b)) (g a),
list.drop n (f a)),
{ intro, simp [F],
generalize : f a = l, generalize : g a = x,
induction n with n IH generalizing l x, {refl},
simp, cases l with b l; simp [IH] },
rw [this, list.take_all_of_le (length_le_encode _)]
end
private lemma list_cons' : by haveI := prim H; exact primrec₂ (@list.cons β) :=
by letI := prim H; exact
encode_iff.1 (succ.comp $
primrec₂.mkpair.comp (encode_iff.2 fst) (encode_iff.2 snd))
private lemma list_reverse' : by haveI := prim H; exact
primrec (@list.reverse β) :=
by letI := prim H; exact
(list_foldl' H primrec.id (const []) $ to₂ $
((list_cons' H).comp snd fst).comp snd).of_eq
(suffices ∀ l r, list.foldl (λ (s : list β) (b : β), b :: s) r l = list.reverse_core l r,
from λ l, this l [],
λ l, by induction l; simp [*, list.reverse_core])
end
namespace primcodable
variables {α : Type*} {β : Type*}
variables [primcodable α] [primcodable β]
open primrec
instance sum : primcodable (α ⊕ β) :=
⟨primrec.nat_iff.1 $
(encode_iff.2 (cond nat_bodd
(((@primrec.decode β _).comp nat_div2).option_map $ to₂ $
nat_bit.comp (const tt) (primrec.encode.comp snd))
(((@primrec.decode α _).comp nat_div2).option_map $ to₂ $
nat_bit.comp (const ff) (primrec.encode.comp snd)))).of_eq $
λ n, show _ = encode (decode_sum n), begin
simp [decode_sum],
cases nat.bodd n; simp [decode_sum],
{ cases decode α n.div2; refl },
{ cases decode β n.div2; refl }
end⟩
instance list : primcodable (list α) := ⟨
by letI H := primcodable.prim (list ℕ); exact
have primrec₂ (λ (a : α) (o : option (list ℕ)),
o.map (list.cons (encode a))), from
option_map snd $
(list_cons' H).comp ((@primrec.encode α _).comp (fst.comp fst)) snd,
have primrec (λ n, (of_nat (list ℕ) n).reverse.foldl
(λ o m, (decode α m).bind (λ a, o.map (list.cons (encode a))))
(some [])), from
list_foldl' H
((list_reverse' H).comp (primrec.of_nat (list ℕ)))
(const (some []))
(primrec.comp₂ (bind_decode_iff.2 $ primrec₂.swap this) primrec₂.right),
nat_iff.1 $ (encode_iff.2 this).of_eq $ λ n, begin
rw list.foldl_reverse,
apply nat.case_strong_induction_on n, { simp },
intros n IH, simp,
cases decode α n.unpair.1 with a, {refl},
simp,
suffices : ∀ (o : option (list ℕ)) p (_ : encode o = encode p),
encode (option.map (list.cons (encode a)) o) =
encode (option.map (list.cons a) p),
from this _ _ (IH _ (nat.unpair_right_le n)),
intros o p IH,
cases o; cases p; injection IH with h,
exact congr_arg (λ k, (nat.mkpair (encode a) k).succ.succ) h
end⟩
end primcodable
namespace primrec
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
theorem sum_inl : primrec (@sum.inl α β) :=
encode_iff.1 $ nat_bit0.comp primrec.encode
theorem sum_inr : primrec (@sum.inr α β) :=
encode_iff.1 $ nat_bit1.comp primrec.encode
theorem sum_cases
{f : α → β ⊕ γ} {g : α → β → σ} {h : α → γ → σ}
(hf : primrec f) (hg : primrec₂ g) (hh : primrec₂ h) :
@primrec _ σ _ _ (λ a, sum.cases_on (f a) (g a) (h a)) :=
option_some_iff.1 $
(cond (nat_bodd.comp $ encode_iff.2 hf)
(option_map (primrec.decode.comp $ nat_div2.comp $ encode_iff.2 hf) hh)
(option_map (primrec.decode.comp $ nat_div2.comp $ encode_iff.2 hf) hg)).of_eq $
λ a, by cases f a with b c;
simp [nat.div2_bit, nat.bodd_bit, encodek]; refl
theorem list_cons : primrec₂ (@list.cons α) :=
list_cons' (primcodable.prim _)
theorem list_cases
{f : α → list β} {g : α → σ} {h : α → β × list β → σ} :
primrec f → primrec g → primrec₂ h →
@primrec _ σ _ _ (λ a, list.cases_on (f a) (g a) (λ b l, h a (b, l))) :=
list_cases' (primcodable.prim _)
theorem list_foldl
{f : α → list β} {g : α → σ} {h : α → σ × β → σ} :
primrec f → primrec g → primrec₂ h →
primrec (λ a, (f a).foldl (λ s b, h a (s, b)) (g a)) :=
list_foldl' (primcodable.prim _)
theorem list_reverse : primrec (@list.reverse α) :=
list_reverse' (primcodable.prim _)
theorem list_foldr
{f : α → list β} {g : α → σ} {h : α → β × σ → σ}
(hf : primrec f) (hg : primrec g) (hh : primrec₂ h) :
primrec (λ a, (f a).foldr (λ b s, h a (b, s)) (g a)) :=
(list_foldl (list_reverse.comp hf) hg $ to₂ $
hh.comp fst $ (pair snd fst).comp snd).of_eq $
λ a, by simp [list.foldl_reverse]
theorem list_head' : primrec (@list.head' α) :=
(list_cases primrec.id (const none)
(option_some_iff.2 $ (fst.comp snd)).to₂).of_eq $
λ l, by cases l; refl
theorem list_head [inhabited α] : primrec (@list.head α _) :=
(option_iget.comp list_head').of_eq $
λ l, l.head_eq_head'.symm
theorem list_tail : primrec (@list.tail α) :=
(list_cases primrec.id (const []) (snd.comp snd).to₂).of_eq $
λ l, by cases l; refl
theorem list_rec
{f : α → list β} {g : α → σ} {h : α → β × list β × σ → σ}
(hf : primrec f) (hg : primrec g) (hh : primrec₂ h) :
@primrec _ σ _ _ (λ a,
list.rec_on (f a) (g a) (λ b l IH, h a (b, l, IH))) :=
let F (a : α) := (f a).foldr
(λ (b : β) (s : list β × σ), (b :: s.1, h a (b, s))) ([], g a) in
have primrec F, from
list_foldr hf (pair (const []) hg) $ to₂ $
pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh,
(snd.comp this).of_eq $ λ a, begin
suffices : F a = (f a,
list.rec_on (f a) (g a) (λ b l IH, h a (b, l, IH))), {rw this},
simp [F], induction f a with b l IH; simp *
end
theorem list_nth : primrec₂ (@list.nth α) :=
let F (l : list α) (n : ℕ) :=
l.foldl (λ (s : ℕ ⊕ α) (a : α),
sum.cases_on s
(@nat.cases (ℕ ⊕ α) (sum.inr a) sum.inl) sum.inr)
(sum.inl n) in
have hF : primrec₂ F, from
list_foldl fst (sum_inl.comp snd) ((sum_cases fst
(nat_cases snd
(sum_inr.comp $ snd.comp fst)
(sum_inl.comp snd).to₂).to₂
(sum_inr.comp snd).to₂).comp snd).to₂,
have @primrec _ (option α) _ _ (λ p : list α × ℕ,
sum.cases_on (F p.1 p.2) (λ _, none) some), from
sum_cases hF (const none).to₂ (option_some.comp snd).to₂,
this.to₂.of_eq $ λ l n, begin
dsimp, symmetry,
induction l with a l IH generalizing n, {refl},
cases n with n,
{ rw [(_ : F (a :: l) 0 = sum.inr a)], {refl},
clear IH, dsimp [F],
induction l with b l IH; simp * },
{ apply IH }
end
theorem list_inth [inhabited α] : primrec₂ (@list.inth α _) :=
option_iget.comp₂ list_nth
theorem list_append : primrec₂ ((++) : list α → list α → list α) :=
(list_foldr fst snd $ to₂ $ comp (@list_cons α _) snd).to₂.of_eq $
λ l₁ l₂, by induction l₁; simp *
theorem list_concat : primrec₂ (λ l (a:α), l ++ [a]) :=
list_append.comp fst (list_cons.comp snd (const []))
theorem list_map
{f : α → list β} {g : α → β → σ}
(hf : primrec f) (hg : primrec₂ g) :
primrec (λ a, (f a).map (g a)) :=
(list_foldr hf (const []) $ to₂ $ list_cons.comp
(hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq $
λ a, by induction f a; simp *
theorem list_range : primrec list.range :=
(nat_elim' primrec.id (const [])
((list_concat.comp snd fst).comp snd).to₂).of_eq $
λ n, by simp; induction n; simp [*, list.range_succ]; refl
theorem list_join : primrec (@list.join α) :=
(list_foldr primrec.id (const []) $ to₂ $
comp (@list_append α _) snd).of_eq $
λ l, by dsimp; induction l; simp *
theorem list_length : primrec (@list.length α) :=
(list_foldr (@primrec.id (list α) _) (const 0) $ to₂ $
(succ.comp $ snd.comp snd).to₂).of_eq $
λ l, by dsimp; induction l; simp [*, -add_comm]
theorem list_find_index {f : α → list β} {p : α → β → Prop}
[∀ a b, decidable (p a b)]
(hf : primrec f) (hp : primrec_rel p) :
primrec (λ a, (f a).find_index (p a)) :=
(list_foldr hf (const 0) $ to₂ $
ite (hp.comp fst $ fst.comp snd) (const 0)
(succ.comp $ snd.comp snd)).of_eq $
λ a, eq.symm $ by dsimp; induction f a with b l;
[refl, simp [*, list.find_index]]
theorem list_index_of [decidable_eq α] : primrec₂ (@list.index_of α _) :=
to₂ $ list_find_index snd $ primrec.eq.comp₂ (fst.comp fst).to₂ snd.to₂
theorem nat_strong_rec
(f : α → ℕ → σ) {g : α → list σ → option σ} (hg : primrec₂ g)
(H : ∀ a n, g a ((list.range n).map (f a)) = some (f a n)) : primrec₂ f :=
suffices primrec₂ (λ a n, (list.range n).map (f a)), from
primrec₂.option_some_iff.1 $
(list_nth.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq $
λ a n, by simp [list.nth_range (nat.lt_succ_self n)]; refl,
primrec₂.option_some_iff.1 $
(nat_elim (const (some [])) (to₂ $
option_bind (snd.comp snd) $ to₂ $
option_map
(hg.comp (fst.comp fst) snd)
(to₂ $ list_concat.comp (snd.comp fst) snd))).of_eq $
λ a n, begin
simp, induction n with n IH, {refl},
simp [IH, H, list.range_succ]
end
end primrec
namespace primcodable
variables {α : Type*} {β : Type*}
variables [primcodable α] [primcodable β]
open primrec
def subtype {p : α → Prop} [decidable_pred p]
(hp : primrec_pred p) : primcodable (subtype p) :=
⟨have primrec (λ n, (decode α n).bind (λ a, option.guard p a)),
from option_bind primrec.decode (option_guard (hp.comp snd) snd),
nat_iff.1 $ (encode_iff.2 this).of_eq $ λ n,
show _ = encode ((decode α n).bind (λ a, _)), begin
cases decode α n with a, {refl},
dsimp [option.guard],
by_cases h : p a; simp [h]; refl
end⟩
instance fin {n} : primcodable (fin n) :=
@of_equiv _ _
(subtype $ nat_lt.comp primrec.id (const n))
(equiv.fin_equiv_subtype _)
instance vector {n} : primcodable (vector α n) :=
subtype ((@primrec.eq _ _ nat.decidable_eq).comp list_length (const _))
instance fin_arrow {n} : primcodable (fin n → α) :=
of_equiv _ (equiv.vector_equiv_fin _ _).symm
instance array {n} : primcodable (array n α) :=
of_equiv _ (equiv.array_equiv_fin _ _)
section ulower
local attribute [instance, priority 100]
encodable.decidable_range_encode encodable.decidable_eq_of_encodable
instance ulower : primcodable (ulower α) :=
have primrec_pred (λ n, encodable.decode₂ α n ≠ none),
from primrec.not (primrec.eq.comp (primrec.option_bind primrec.decode
(primrec.ite (primrec.eq.comp (primrec.encode.comp primrec.snd) primrec.fst)
(primrec.option_some.comp primrec.snd) (primrec.const _))) (primrec.const _)),
primcodable.subtype $
primrec_pred.of_eq this (λ n, decode₂_ne_none_iff)
end ulower
end primcodable
namespace primrec
variables {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variables [primcodable α] [primcodable β] [primcodable γ] [primcodable σ]
theorem subtype_val {p : α → Prop} [decidable_pred p]
{hp : primrec_pred p} :
by haveI := primcodable.subtype hp; exact
primrec (@subtype.val α p) :=
begin
letI := primcodable.subtype hp,
refine (primcodable.prim (subtype p)).of_eq (λ n, _),
rcases decode (subtype p) n with _|⟨a,h⟩; refl
end
theorem subtype_val_iff {p : β → Prop} [decidable_pred p]
{hp : primrec_pred p} {f : α → subtype p} :
by haveI := primcodable.subtype hp; exact
primrec (λ a, (f a).1) ↔ primrec f :=
begin
letI := primcodable.subtype hp,
refine ⟨λ h, _, λ hf, subtype_val.comp hf⟩,
refine nat.primrec.of_eq h (λ n, _),
cases decode α n with a, {refl},
simp, cases f a; refl
end
theorem subtype_mk {p : β → Prop} [decidable_pred p] {hp : primrec_pred p}
{f : α → β} {h : ∀ a, p (f a)} (hf : primrec f) :
by haveI := primcodable.subtype hp; exact
primrec (λ a, @subtype.mk β p (f a) (h a)) :=
subtype_val_iff.1 hf
theorem option_get {f : α → option β} {h : ∀ a, (f a).is_some} :
primrec f → primrec (λ a, option.get (h a)) :=
begin
intro hf,
refine (nat.primrec.pred.comp hf).of_eq (λ n, _),
generalize hx : decode α n = x,
cases x; simp
end
theorem ulower_down : primrec (ulower.down : α → ulower α) :=
by letI : ∀ a, decidable (a ∈ set.range (encode : α → ℕ)) := decidable_range_encode _; exact
subtype_mk primrec.encode
theorem ulower_up : primrec (ulower.up : ulower α → α) :=
by letI : ∀ a, decidable (a ∈ set.range (encode : α → ℕ)) := decidable_range_encode _; exact
option_get (primrec.decode₂.comp subtype_val)
theorem fin_val_iff {n} {f : α → fin n} :
primrec (λ a, (f a).1) ↔ primrec f :=
begin
let : primcodable {a//id a<n}, swap,
exactI (iff.trans (by refl) subtype_val_iff).trans (of_equiv_iff _)
end
theorem fin_val {n} : primrec (coe : fin n → ℕ) := fin_val_iff.2 primrec.id
theorem fin_succ {n} : primrec (@fin.succ n) :=
fin_val_iff.1 $ by simp [succ.comp fin_val]
theorem vector_to_list {n} : primrec (@vector.to_list α n) := subtype_val
theorem vector_to_list_iff {n} {f : α → vector β n} :
primrec (λ a, (f a).to_list) ↔ primrec f := subtype_val_iff
theorem vector_cons {n} : primrec₂ (@vector.cons α n) :=
vector_to_list_iff.1 $ by simp; exact
list_cons.comp fst (vector_to_list_iff.2 snd)
theorem vector_length {n} : primrec (@vector.length α n) := const _
theorem vector_head {n} : primrec (@vector.head α n) :=
option_some_iff.1 $
(list_head'.comp vector_to_list).of_eq $ λ ⟨a::l, h⟩, rfl
theorem vector_tail {n} : primrec (@vector.tail α n) :=
vector_to_list_iff.1 $ (list_tail.comp vector_to_list).of_eq $
λ ⟨l, h⟩, by cases l; refl
theorem vector_nth {n} : primrec₂ (@vector.nth α n) :=
option_some_iff.1 $
(list_nth.comp (vector_to_list.comp fst) (fin_val.comp snd)).of_eq $
λ a, by simp [vector.nth_eq_nth_le]; rw [← list.nth_le_nth]
theorem list_of_fn : ∀ {n} {f : fin n → α → σ},
(∀ i, primrec (f i)) → primrec (λ a, list.of_fn (λ i, f i a))
| 0 f hf := const []
| (n+1) f hf := by simp [list.of_fn_succ]; exact
list_cons.comp (hf 0) (list_of_fn (λ i, hf i.succ))
theorem vector_of_fn {n} {f : fin n → α → σ}
(hf : ∀ i, primrec (f i)) : primrec (λ a, vector.of_fn (λ i, f i a)) :=
vector_to_list_iff.1 $ by simp [list_of_fn hf]
theorem vector_nth' {n} : primrec (@vector.nth α n) := of_equiv_symm
theorem vector_of_fn' {n} : primrec (@vector.of_fn α n) := of_equiv
theorem fin_app {n} : primrec₂ (@id (fin n → σ)) :=
(vector_nth.comp (vector_of_fn'.comp fst) snd).of_eq $
λ ⟨v, i⟩, by simp
theorem fin_curry₁ {n} {f : fin n → α → σ} : primrec₂ f ↔ ∀ i, primrec (f i) :=
⟨λ h i, h.comp (const i) primrec.id,
λ h, (vector_nth.comp ((vector_of_fn h).comp snd) fst).of_eq $ λ a, by simp⟩
theorem fin_curry {n} {f : α → fin n → σ} : primrec f ↔ primrec₂ f :=
⟨λ h, fin_app.comp (h.comp fst) snd,
λ h, (vector_nth'.comp (vector_of_fn (λ i,
show primrec (λ a, f a i), from
h.comp primrec.id (const i)))).of_eq $
λ a, by funext i; simp⟩
end primrec
namespace nat
open vector
/-- An alternative inductive definition of `primrec` which
does not use the pairing function on ℕ, and so has to
work with n-ary functions on ℕ instead of unary functions.
We prove that this is equivalent to the regular notion
in `to_prim` and `of_prim`. -/
inductive primrec' : ∀ {n}, (vector ℕ n → ℕ) → Prop
| zero : @primrec' 0 (λ _, 0)
| succ : @primrec' 1 (λ v, succ v.head)
| nth {n} (i : fin n) : primrec' (λ v, v.nth i)
| comp {m n f} (g : fin n → vector ℕ m → ℕ) :
primrec' f → (∀ i, primrec' (g i)) →
primrec' (λ a, f (of_fn (λ i, g i a)))
| prec {n f g} : @primrec' n f → @primrec' (n+2) g →
primrec' (λ v : vector ℕ (n+1),
v.head.elim (f v.tail) (λ y IH, g (y ::ᵥ IH ::ᵥ v.tail)))
end nat
namespace nat.primrec'
open vector primrec nat (primrec') nat.primrec'
hide ite
theorem to_prim {n f} (pf : @primrec' n f) : primrec f :=
begin
induction pf,
case nat.primrec'.zero { exact const 0 },
case nat.primrec'.succ { exact primrec.succ.comp vector_head },
case nat.primrec'.nth : n i {
exact vector_nth.comp primrec.id (const i) },
case nat.primrec'.comp : m n f g _ _ hf hg {
exact hf.comp (vector_of_fn (λ i, hg i)) },
case nat.primrec'.prec : n f g _ _ hf hg {
exact nat_elim' vector_head (hf.comp vector_tail) (hg.comp $
vector_cons.comp (fst.comp snd) $
vector_cons.comp (snd.comp snd) $
(@vector_tail _ _ (n+1)).comp fst).to₂ },
end
theorem of_eq {n} {f g : vector ℕ n → ℕ}
(hf : primrec' f) (H : ∀ i, f i = g i) : primrec' g :=
(funext H : f = g) ▸ hf
theorem const {n} : ∀ m, @primrec' n (λ v, m)
| 0 := zero.comp fin.elim0 (λ i, i.elim0)
| (m+1) := succ.comp _ (λ i, const m)
theorem head {n : ℕ} : @primrec' n.succ head :=
(nth 0).of_eq $ λ v, by simp [nth_zero]
theorem tail {n f} (hf : @primrec' n f) : @primrec' n.succ (λ v, f v.tail) :=
(hf.comp _ (λ i, @nth _ i.succ)).of_eq $
λ v, by rw [← of_fn_nth v.tail]; congr; funext i; simp
def vec {n m} (f : vector ℕ n → vector ℕ m) :=
∀ i, primrec' (λ v, (f v).nth i)
protected theorem nil {n} : @vec n 0 (λ _, nil) := λ i, i.elim0
protected theorem cons {n m f g}
(hf : @primrec' n f) (hg : @vec n m g) :
vec (λ v, (f v ::ᵥ g v)) :=
λ i, fin.cases (by simp *) (λ i, by simp [hg i]) i
theorem idv {n} : @vec n n id := nth
theorem comp' {n m f g}
(hf : @primrec' m f) (hg : @vec n m g) :
primrec' (λ v, f (g v)) :=
(hf.comp _ hg).of_eq $ λ v, by simp
theorem comp₁ (f : ℕ → ℕ) (hf : @primrec' 1 (λ v, f v.head))
{n g} (hg : @primrec' n g) : primrec' (λ v, f (g v)) :=
hf.comp _ (λ i, hg)
theorem comp₂ (f : ℕ → ℕ → ℕ)
(hf : @primrec' 2 (λ v, f v.head v.tail.head))
{n g h} (hg : @primrec' n g) (hh : @primrec' n h) :
primrec' (λ v, f (g v) (h v)) :=
by simpa using hf.comp' (hg.cons $ hh.cons primrec'.nil)
theorem prec' {n f g h}
(hf : @primrec' n f) (hg : @primrec' n g) (hh : @primrec' (n+2) h) :
@primrec' n (λ v, (f v).elim (g v)
(λ (y IH : ℕ), h (y ::ᵥ IH ::ᵥ v))) :=
by simpa using comp' (prec hg hh) (hf.cons idv)
theorem pred : @primrec' 1 (λ v, v.head.pred) :=
(prec' head (const 0) head).of_eq $
λ v, by simp; cases v.head; refl
theorem add : @primrec' 2 (λ v, v.head + v.tail.head) :=
(prec head (succ.comp₁ _ (tail head))).of_eq $
λ v, by simp; induction v.head; simp [*, nat.succ_add]
theorem sub : @primrec' 2 (λ v, v.head - v.tail.head) :=
begin
suffices, simpa using comp₂ (λ a b, b - a) this (tail head) head,
refine (prec head (pred.comp₁ _ (tail head))).of_eq (λ v, _),
simp, induction v.head; simp [*, nat.sub_succ]
end
theorem mul : @primrec' 2 (λ v, v.head * v.tail.head) :=
(prec (const 0) (tail (add.comp₂ _ (tail head) (head)))).of_eq $
λ v, by simp; induction v.head; simp [*, nat.succ_mul]; rw add_comm
theorem if_lt {n a b f g}
(ha : @primrec' n a) (hb : @primrec' n b)
(hf : @primrec' n f) (hg : @primrec' n g) :
@primrec' n (λ v, if a v < b v then f v else g v) :=
(prec' (sub.comp₂ _ hb ha) hg (tail $ tail hf)).of_eq $
λ v, begin
cases e : b v - a v,
{ simp [not_lt.2 (tsub_eq_zero_iff_le.mp e)] },
{ simp [nat.lt_of_sub_eq_succ e] }
end
theorem mkpair : @primrec' 2 (λ v, v.head.mkpair v.tail.head) :=
if_lt head (tail head)
(add.comp₂ _ (tail $ mul.comp₂ _ head head) head)
(add.comp₂ _ (add.comp₂ _
(mul.comp₂ _ head head) head) (tail head))
protected theorem encode : ∀ {n}, @primrec' n encode
| 0 := (const 0).of_eq (λ v, by rw v.eq_nil; refl)
| (n+1) := (succ.comp₁ _ (mkpair.comp₂ _ head (tail encode)))
.of_eq $ λ ⟨a::l, e⟩, rfl
theorem sqrt : @primrec' 1 (λ v, v.head.sqrt) :=
begin
suffices H : ∀ n : ℕ, n.sqrt = n.elim 0 (λ x y,
if x.succ < y.succ*y.succ then y else y.succ),
{ simp [H],
have := @prec' 1 _ _ (λ v,
by have x := v.head; have y := v.tail.head; from
if x.succ < y.succ*y.succ then y else y.succ) head (const 0) _,
{ convert this, funext, congr, funext x y, congr; simp },
have x1 := succ.comp₁ _ head,
have y1 := succ.comp₁ _ (tail head),
exact if_lt x1 (mul.comp₂ _ y1 y1) (tail head) y1 },
intro, symmetry,
induction n with n IH, {simp},
dsimp, rw IH, split_ifs,
{ exact le_antisymm (nat.sqrt_le_sqrt (nat.le_succ _))
(nat.lt_succ_iff.1 $ nat.sqrt_lt.2 h) },
{ exact nat.eq_sqrt.2 ⟨not_lt.1 h, nat.sqrt_lt.1 $
nat.lt_succ_iff.2 $ nat.sqrt_succ_le_succ_sqrt _⟩ },
end
theorem unpair₁ {n f} (hf : @primrec' n f) :
@primrec' n (λ v, (f v).unpair.1) :=
begin
have s := sqrt.comp₁ _ hf,
have fss := sub.comp₂ _ hf (mul.comp₂ _ s s),
refine (if_lt fss s fss s).of_eq (λ v, _),
simp [nat.unpair], split_ifs; refl
end
theorem unpair₂ {n f} (hf : @primrec' n f) :
@primrec' n (λ v, (f v).unpair.2) :=
begin
have s := sqrt.comp₁ _ hf,
have fss := sub.comp₂ _ hf (mul.comp₂ _ s s),
refine (if_lt fss s s (sub.comp₂ _ fss s)).of_eq (λ v, _),
simp [nat.unpair], split_ifs; refl
end
theorem of_prim : ∀ {n f}, primrec f → @primrec' n f :=
suffices ∀ f, nat.primrec f → @primrec' 1 (λ v, f v.head), from
λ n f hf, (pred.comp₁ _ $ (this _ hf).comp₁
(λ m, encodable.encode $ (decode (vector ℕ n) m).map f)
primrec'.encode).of_eq (λ i, by simp [encodek]),
λ f hf, begin
induction hf,
case nat.primrec.zero { exact const 0 },
case nat.primrec.succ { exact succ },
case nat.primrec.left { exact unpair₁ head },
case nat.primrec.right { exact unpair₂ head },
case nat.primrec.pair : f g _ _ hf hg {
exact mkpair.comp₂ _ hf hg },
case nat.primrec.comp : f g _ _ hf hg {
exact hf.comp₁ _ hg },
case nat.primrec.prec : f g _ _ hf hg {
simpa using prec' (unpair₂ head)
(hf.comp₁ _ (unpair₁ head))
(hg.comp₁ _ $ mkpair.comp₂ _ (unpair₁ $ tail $ tail head)
(mkpair.comp₂ _ head (tail head))) },
end
theorem prim_iff {n f} : @primrec' n f ↔ primrec f := ⟨to_prim, of_prim⟩
theorem prim_iff₁ {f : ℕ → ℕ} :
@primrec' 1 (λ v, f v.head) ↔ primrec f :=
prim_iff.trans ⟨
λ h, (h.comp $ vector_of_fn $ λ i, primrec.id).of_eq (λ v, by simp),
λ h, h.comp vector_head⟩
theorem prim_iff₂ {f : ℕ → ℕ → ℕ} :
@primrec' 2 (λ v, f v.head v.tail.head) ↔ primrec₂ f :=
prim_iff.trans ⟨
λ h, (h.comp $ vector_cons.comp fst $
vector_cons.comp snd (primrec.const nil)).of_eq (λ v, by simp),
λ h, h.comp vector_head (vector_head.comp vector_tail)⟩
theorem vec_iff {m n f} :
@vec m n f ↔ primrec f :=
⟨λ h, by simpa using vector_of_fn (λ i, to_prim (h i)),
λ h i, of_prim $ vector_nth.comp h (primrec.const i)⟩
end nat.primrec'
theorem primrec.nat_sqrt : primrec nat.sqrt :=
nat.primrec'.prim_iff₁.1 nat.primrec'.sqrt
|
cd3508b67340eb24e61839b1c2a98bff5df88c67 | 1e561612e7479c100cd9302e3fe08cbd2914aa25 | /mathlib4_experiments/Tactic/Refl.lean | 7514ee3b6c6f70d008f7a81cac9c33f9048f2b96 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib4_experiments | 8de8ed7193f70748a7529e05d831203a7c64eedb | 87cb879b4d602c8ecfd9283b7c0b06015abdbab1 | refs/heads/master | 1,687,971,389,316 | 1,620,336,942,000 | 1,620,336,942,000 | 353,994,588 | 7 | 4 | Apache-2.0 | 1,622,410,748,000 | 1,617,361,732,000 | Lean | UTF-8 | Lean | false | false | 196 | lean | /-
## `refl`
Currently works for iff and =
-/
syntax "refl" : tactic
macro_rules
| `(tactic| refl) => `(tactic| apply Eq.refl)
macro_rules
| `(tactic| refl) => `(tactic| apply Iff.refl)
|
f372ab5b4810097f9f1dcb8d7783d7ca106afddd | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/int/cast_field.lean | 8631b4040075724403322e27c58f426cf16a8ff3 | [
"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 | 1,098 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import data.int.cast
import data.nat.cast_field
/-!
# Cast of integers into fields
This file concerns the canonical homomorphism `ℤ → F`, where `F` is a field.
## Main results
* `int.cast_div`: if `n` divides `m`, then `↑(m / n) = ↑m / ↑n`
-/
namespace int
open nat
variables {α : Type*}
/--
Auxiliary lemma for norm_cast to move the cast `-↑n` upwards to `↑-↑n`.
(The restriction to `field` is necessary, otherwise this would also apply in the case where
`R = ℤ` and cause nontermination.)
-/
@[norm_cast]
lemma cast_neg_nat_cast {R} [field R] (n : ℕ) : ((-n : ℤ) : R) = -n := by simp
@[simp] theorem cast_div [field α] {m n : ℤ} (n_dvd : n ∣ m) (n_nonzero : (n : α) ≠ 0) :
((m / n : ℤ) : α) = m / n :=
begin
rcases n_dvd with ⟨k, rfl⟩,
have : n ≠ 0, { rintro rfl, simpa using n_nonzero },
rw [int.mul_div_cancel_left _ this, int.cast_mul, mul_div_cancel_left _ n_nonzero],
end
end int
|
d5769c8e360c041749076d6eaa4fe338373cbdc1 | 969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb | /src/topology/algebra/open_subgroup.lean | 153dcb5dc50aae4e8b988aa0c91bbbe9a6d4775f | [
"Apache-2.0"
] | permissive | SAAluthwela/mathlib | 62044349d72dd63983a8500214736aa7779634d3 | 83a4b8b990907291421de54a78988c024dc8a552 | refs/heads/master | 1,679,433,873,417 | 1,615,998,031,000 | 1,615,998,031,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,434 | lean | /-
Copyright (c) 2019 Johan Commelin All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import order.filter.lift
import topology.opens
import topology.algebra.ring
open topological_space
open_locale topological_space
set_option old_structure_cmd true
/-- The type of open subgroups of a topological additive group. -/
@[ancestor add_subgroup]
structure open_add_subgroup (G : Type*) [add_group G] [topological_space G]
extends add_subgroup G :=
(is_open' : is_open carrier)
/-- The type of open subgroups of a topological group. -/
@[ancestor subgroup, to_additive]
structure open_subgroup (G : Type*) [group G] [topological_space G] extends subgroup G :=
(is_open' : is_open carrier)
/-- Reinterpret an `open_subgroup` as a `subgroup`. -/
add_decl_doc open_subgroup.to_subgroup
/-- Reinterpret an `open_add_subgroup` as an `add_subgroup`. -/
add_decl_doc open_add_subgroup.to_add_subgroup
-- Tell Lean that `open_add_subgroup` is a namespace
namespace open_add_subgroup
end open_add_subgroup
namespace open_subgroup
open function topological_space
variables {G : Type*} [group G] [topological_space G]
variables {U V : open_subgroup G} {g : G}
@[to_additive]
instance has_coe_set : has_coe_t (open_subgroup G) (set G) := ⟨λ U, U.1⟩
@[to_additive]
instance : has_mem G (open_subgroup G) := ⟨λ g U, g ∈ (U : set G)⟩
@[to_additive]
instance has_coe_subgroup : has_coe_t (open_subgroup G) (subgroup G) := ⟨to_subgroup⟩
@[to_additive]
instance has_coe_opens : has_coe_t (open_subgroup G) (opens G) := ⟨λ U, ⟨U, U.is_open'⟩⟩
@[simp, to_additive] lemma mem_coe : g ∈ (U : set G) ↔ g ∈ U := iff.rfl
@[simp, to_additive] lemma mem_coe_opens : g ∈ (U : opens G) ↔ g ∈ U := iff.rfl
@[simp, to_additive]
lemma mem_coe_subgroup : g ∈ (U : subgroup G) ↔ g ∈ U := iff.rfl
attribute [norm_cast] mem_coe mem_coe_opens mem_coe_subgroup open_add_subgroup.mem_coe
open_add_subgroup.mem_coe_opens open_add_subgroup.mem_coe_add_subgroup
@[to_additive] lemma coe_injective : injective (coe : open_subgroup G → set G) :=
λ U V h, by cases U; cases V; congr; assumption
@[ext, to_additive]
lemma ext (h : ∀ x, x ∈ U ↔ x ∈ V) : (U = V) := coe_injective $ set.ext h
@[to_additive]
lemma ext_iff : (U = V) ↔ (∀ x, x ∈ U ↔ x ∈ V) := ⟨λ h x, h ▸ iff.rfl, ext⟩
variable (U)
@[to_additive]
protected lemma is_open : is_open (U : set G) := U.is_open'
@[to_additive]
protected lemma one_mem : (1 : G) ∈ U := U.one_mem'
@[to_additive]
protected lemma inv_mem {g : G} (h : g ∈ U) : g⁻¹ ∈ U := U.inv_mem' h
@[to_additive]
protected lemma mul_mem {g₁ g₂ : G} (h₁ : g₁ ∈ U) (h₂ : g₂ ∈ U) : g₁ * g₂ ∈ U := U.mul_mem' h₁ h₂
@[to_additive]
lemma mem_nhds_one : (U : set G) ∈ 𝓝 (1 : G) :=
mem_nhds_sets U.is_open U.one_mem
variable {U}
@[to_additive]
instance : has_top (open_subgroup G) := ⟨{ is_open' := is_open_univ, .. (⊤ : subgroup G) }⟩
@[to_additive]
instance : inhabited (open_subgroup G) := ⟨⊤⟩
@[to_additive]
lemma is_closed [has_continuous_mul G] (U : open_subgroup G) : is_closed (U : set G) :=
begin
apply is_open_compl_iff.1,
refine is_open_iff_forall_mem_open.2 (λ x hx, ⟨(λ y, y * x⁻¹) ⁻¹' U, _, _, _⟩),
{ intros u hux,
simp only [set.mem_preimage, set.mem_compl_iff, mem_coe] at hux hx ⊢,
refine mt (λ hu, _) hx,
convert U.mul_mem (U.inv_mem hux) hu,
simp },
{ exact U.is_open.preimage (continuous_mul_right _) },
{ simp [U.one_mem] }
end
section
variables {H : Type*} [group H] [topological_space H]
/-- The product of two open subgroups as an open subgroup of the product group. -/
@[to_additive "The product of two open subgroups as an open subgroup of the product group."]
def prod (U : open_subgroup G) (V : open_subgroup H) : open_subgroup (G × H) :=
{ carrier := (U : set G).prod (V : set H),
is_open' := U.is_open.prod V.is_open,
.. (U : subgroup G).prod (V : subgroup H) }
end
@[to_additive]
instance : partial_order (open_subgroup G) :=
{ le := λ U V, ∀ ⦃x⦄, x ∈ U → x ∈ V,
.. partial_order.lift (coe : open_subgroup G → set G) coe_injective }
@[to_additive]
instance : semilattice_inf_top (open_subgroup G) :=
{ inf := λ U V, { is_open' := is_open_inter U.is_open V.is_open, .. (U : subgroup G) ⊓ V },
inf_le_left := λ U V, set.inter_subset_left _ _,
inf_le_right := λ U V, set.inter_subset_right _ _,
le_inf := λ U V W hV hW, set.subset_inter hV hW,
top := ⊤,
le_top := λ U, set.subset_univ _,
..open_subgroup.partial_order }
@[simp, to_additive] lemma coe_inf : (↑(U ⊓ V) : set G) = (U : set G) ∩ V := rfl
@[simp, to_additive] lemma coe_subset : (U : set G) ⊆ V ↔ U ≤ V := iff.rfl
@[simp, to_additive] lemma coe_subgroup_le : (U : subgroup G) ≤ (V : subgroup G) ↔ U ≤ V := iff.rfl
attribute [norm_cast] coe_inf coe_subset coe_subgroup_le open_add_subgroup.coe_inf
open_add_subgroup.coe_subset open_add_subgroup.coe_add_subgroup_le
variables {N : Type*} [group N] [topological_space N]
/-- The preimage of an `open_subgroup` along a continuous `monoid` homomorphism
is an `open_subgroup`. -/
@[to_additive "The preimage of an `open_add_subgroup` along a continuous `add_monoid` homomorphism
is an `open_add_subgroup`."]
def comap (f : G →* N)
(hf : continuous f) (H : open_subgroup N) : open_subgroup G :=
{ is_open' := H.is_open.preimage hf,
.. (H : subgroup N).comap f }
@[simp, to_additive]
lemma coe_comap (H : open_subgroup N) (f : G →* N) (hf : continuous f) :
(H.comap f hf : set G) = f ⁻¹' H := rfl
@[simp, to_additive]
lemma mem_comap {H : open_subgroup N} {f : G →* N} {hf : continuous f} {x : G} :
x ∈ H.comap f hf ↔ f x ∈ H := iff.rfl
@[to_additive]
lemma comap_comap {P : Type*} [group P] [topological_space P]
(K : open_subgroup P) (f₂ : N →* P) (hf₂ : continuous f₂) (f₁ : G →* N) (hf₁ : continuous f₁) :
(K.comap f₂ hf₂).comap f₁ hf₁ = K.comap (f₂.comp f₁) (hf₂.comp hf₁) :=
rfl
end open_subgroup
namespace subgroup
variables {G : Type*} [group G] [topological_space G] [has_continuous_mul G] (H : subgroup G)
@[to_additive]
lemma is_open_of_mem_nhds {g : G} (hg : (H : set G) ∈ 𝓝 g) :
is_open (H : set G) :=
begin
simp only [is_open_iff_mem_nhds, subgroup.mem_coe] at hg ⊢,
intros x hx,
have : filter.tendsto (λ y, y * (x⁻¹ * g)) (𝓝 x) (𝓝 $ x * (x⁻¹ * g)) :=
(continuous_id.mul continuous_const).tendsto _,
rw [mul_inv_cancel_left] at this,
have := filter.mem_map.1 (this hg),
replace hg : g ∈ H := subgroup.mem_coe.1 (mem_of_nhds hg),
simp only [subgroup.mem_coe, H.mul_mem_cancel_right (H.mul_mem (H.inv_mem hx) hg)] at this,
exact this
end
@[to_additive]
lemma is_open_of_open_subgroup {U : open_subgroup G} (h : U.1 ≤ H) :
is_open (H : set G) :=
H.is_open_of_mem_nhds (filter.mem_sets_of_superset U.mem_nhds_one h)
@[to_additive]
lemma is_open_mono {H₁ H₂ : subgroup G} (h : H₁ ≤ H₂) (h₁ : is_open (H₁ :set G)) :
is_open (H₂ : set G) :=
@is_open_of_open_subgroup _ _ _ _ H₂ { is_open' := h₁, .. H₁ } h
end subgroup
namespace open_subgroup
variables {G : Type*} [group G] [topological_space G] [has_continuous_mul G]
@[to_additive]
instance : semilattice_sup_top (open_subgroup G) :=
{ sup := λ U V,
{ is_open' := show is_open (((U : subgroup G) ⊔ V : subgroup G) : set G),
from subgroup.is_open_mono le_sup_left U.is_open,
.. ((U : subgroup G) ⊔ V) },
le_sup_left := λ U V, coe_subgroup_le.1 le_sup_left,
le_sup_right := λ U V, coe_subgroup_le.1 le_sup_right,
sup_le := λ U V W hU hV, coe_subgroup_le.1 (sup_le hU hV),
..open_subgroup.semilattice_inf_top }
end open_subgroup
namespace submodule
open open_add_subgroup
variables {R : Type*} {M : Type*} [comm_ring R]
variables [add_comm_group M] [topological_space M] [topological_add_group M] [module R M]
lemma is_open_mono {U P : submodule R M} (h : U ≤ P) (hU : is_open (U : set M)) :
is_open (P : set M) :=
@add_subgroup.is_open_mono M _ _ _ U.to_add_subgroup P.to_add_subgroup h hU
end submodule
namespace ideal
variables {R : Type*} [comm_ring R]
variables [topological_space R] [topological_ring R]
lemma is_open_of_open_subideal {U I : ideal R} (h : U ≤ I) (hU : is_open (U : set R)) :
is_open (I : set R) :=
submodule.is_open_mono h hU
end ideal
|
8a16a02838228ec78773694483d55898fae177e1 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/ring_theory/multiplicity.lean | 7fd8de82efa83ab77b94f5a86f9efed873486d53 | [
"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 | 16,953 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import algebra.associated
import algebra.big_operators.basic
import data.nat.enat
variables {α : Type*}
open nat roption
open_locale big_operators
/-- `multiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as an `enat` or natural with infinity. If `∀ n, a ^ n ∣ b`,
then it returns `⊤`-/
def multiplicity [comm_monoid α] [decidable_rel ((∣) : α → α → Prop)] (a b : α) : enat :=
enat.find $ λ n, ¬a ^ (n + 1) ∣ b
namespace multiplicity
section comm_monoid
variables [comm_monoid α]
/-- `multiplicity.finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
@[reducible] def finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b
lemma finite_iff_dom [decidable_rel ((∣) : α → α → Prop)] {a b : α} :
finite a b ↔ (multiplicity a b).dom := iff.rfl
lemma finite_def {a b : α} : finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := iff.rfl
@[norm_cast]
theorem int.coe_nat_multiplicity (a b : ℕ) :
multiplicity (a : ℤ) (b : ℤ) = multiplicity a b :=
begin
apply roption.ext',
{ repeat {rw [← finite_iff_dom, finite_def]},
norm_cast },
{ intros h1 h2,
apply _root_.le_antisymm; { apply nat.find_le, norm_cast, simp }}
end
lemma not_finite_iff_forall {a b : α} : (¬ finite a b) ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨λ h n, nat.cases_on n (one_dvd _) (by simpa [finite, not_not] using h),
by simp [finite, multiplicity, not_not]; tauto⟩
lemma not_unit_of_finite {a b : α} (h : finite a b) : ¬is_unit a :=
let ⟨n, hn⟩ := h in mt (is_unit_iff_forall_dvd.1 ∘ is_unit.pow (n + 1)) $
λ h, hn (h b)
lemma finite_of_finite_mul_left {a b c : α} : finite a (b * c) → finite a c :=
λ ⟨n, hn⟩, ⟨n, λ h, hn (dvd.trans h (by simp [mul_pow]))⟩
lemma finite_of_finite_mul_right {a b c : α} : finite a (b * c) → finite a b :=
by rw mul_comm; exact finite_of_finite_mul_left
variable [decidable_rel ((∣) : α → α → Prop)]
lemma pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : enat) ≤ multiplicity a b → a ^ k ∣ b :=
nat.cases_on k (λ _, one_dvd _)
(λ k ⟨h₁, h₂⟩, by_contradiction (λ hk, (nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk)))
lemma pow_multiplicity_dvd {a b : α} (h : finite a b) : a ^ get (multiplicity a b) h ∣ b :=
pow_dvd_of_le_multiplicity (by rw enat.coe_get)
lemma is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b :=
λ h, by rw [enat.lt_coe_iff] at hm; exact nat.find_spec hm.fst (dvd.trans (pow_dvd_pow _ hm.snd) h)
lemma is_greatest' {a b : α} {m : ℕ} (h : finite a b) (hm : get (multiplicity a b) h < m) :
¬a ^ m ∣ b :=
is_greatest (by rwa [← enat.coe_lt_coe, enat.coe_get] at hm)
lemma unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
(k : enat) = multiplicity a b :=
le_antisymm (le_of_not_gt (λ hk', is_greatest hk' hk)) $
have finite a b, from ⟨k, hsucc⟩,
by { rw [enat.le_coe_iff], exact ⟨this, nat.find_min' _ hsucc⟩ }
lemma unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬ a ^ (k + 1) ∣ b) :
k = get (multiplicity a b) ⟨k, hsucc⟩ :=
by rw [← enat.coe_inj, enat.coe_get, unique hk hsucc]
lemma le_multiplicity_of_pow_dvd {a b : α}
{k : ℕ} (hk : a ^ k ∣ b) : (k : enat) ≤ multiplicity a b :=
le_of_not_gt $ λ hk', is_greatest hk' hk
lemma pow_dvd_iff_le_multiplicity {a b : α}
{k : ℕ} : a ^ k ∣ b ↔ (k : enat) ≤ multiplicity a b :=
⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩
lemma multiplicity_lt_iff_neg_dvd {a b : α} {k : ℕ} :
multiplicity a b < (k : enat) ↔ ¬ a ^ k ∣ b :=
by { rw [pow_dvd_iff_le_multiplicity, not_le] }
lemma eq_some_iff {a b : α} {n : ℕ} :
multiplicity a b = (n : enat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b :=
⟨λ h, let ⟨h₁, h₂⟩ := eq_some_iff.1 h in
h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest
(by { rw [enat.lt_coe_iff], exact ⟨h₁, lt_succ_self _⟩ })⟩,
λ h, eq_some_iff.2 ⟨⟨n, h.2⟩, eq.symm $ unique' h.1 h.2⟩⟩
lemma eq_top_iff {a b : α} :
multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b :=
(enat.find_eq_top_iff _).trans $
by { simp only [not_not], exact ⟨λ h n, nat.cases_on n (one_dvd _) (λ n, h _), λ h n, h _⟩ }
lemma one_right {a : α} (ha : ¬is_unit a) : multiplicity a 1 = 0 :=
eq_some_iff.2 ⟨dvd_refl _, mt is_unit_iff_dvd_one.2 $ by simpa⟩
@[simp] lemma get_one_right {a : α} (ha : finite a 1) : get (multiplicity a 1) ha = 0 :=
get_eq_iff_eq_some.2 (eq_some_iff.2 ⟨dvd_refl _,
by simpa [is_unit_iff_dvd_one.symm] using not_unit_of_finite ha⟩)
@[simp] lemma multiplicity_unit {a : α} (b : α) (ha : is_unit a) : multiplicity a b = ⊤ :=
eq_top_iff.2 (λ _, is_unit_iff_forall_dvd.1 (ha.pow _) _)
@[simp] lemma one_left (b : α) : multiplicity 1 b = ⊤ := by simp [eq_top_iff]
lemma multiplicity_eq_zero_of_not_dvd {a b : α} (ha : ¬a ∣ b) : multiplicity a b = 0 :=
eq_some_iff.2 (by simpa)
lemma eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬ finite a b :=
roption.eq_none_iff'
open_locale classical
lemma multiplicity_le_multiplicity_iff {a b c d : α} : multiplicity a b ≤ multiplicity c d ↔
(∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d) :=
⟨λ h n hab, (pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h)),
λ h, if hab : finite a b
then by rw [← enat.coe_get (finite_iff_dom.1 hab)];
exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _))
else
have ∀ n : ℕ, c ^ n ∣ d, from λ n, h n (not_finite_iff_forall.1 hab _),
by rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2
(not_finite_iff_forall.2 this)]⟩
lemma multiplicity_le_multiplicity_of_dvd {a b c : α} (hdvd : a ∣ b) :
multiplicity b c ≤ multiplicity a c :=
multiplicity_le_multiplicity_iff.2 $ λ n h, dvd_trans (pow_dvd_pow_of_dvd hdvd n) h
lemma dvd_of_multiplicity_pos {a b : α} (h : (0 : enat) < multiplicity a b) : a ∣ b :=
by rw [← pow_one a]; exact pow_dvd_of_le_multiplicity (enat.pos_iff_one_le.1 h)
lemma dvd_iff_multiplicity_pos {a b : α} : (0 : enat) < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos,
λ hdvd, lt_of_le_of_ne (zero_le _) (λ heq, is_greatest
(show multiplicity a b < 1, from heq ▸ enat.coe_lt_coe.mpr zero_lt_one)
(by rwa pow_one a))⟩
lemma finite_nat_iff {a b : ℕ} : finite a b ↔ (a ≠ 1 ∧ 0 < b) :=
begin
rw [← not_iff_not, not_finite_iff_forall, not_and_distrib, ne.def,
not_not, not_lt, nat.le_zero_iff],
exact ⟨λ h, or_iff_not_imp_right.2 (λ hb,
have ha : a ≠ 0, from λ ha, by simpa [ha] using h 1,
by_contradiction (λ ha1 : a ≠ 1,
have ha_gt_one : 1 < a, from
lt_of_not_ge (λ ha', by { clear h, revert ha ha1, dec_trivial! }),
not_lt_of_ge (le_of_dvd (nat.pos_of_ne_zero hb) (h b))
(lt_pow_self ha_gt_one b))),
λ h, by cases h; simp *⟩
end
end comm_monoid
section comm_monoid_with_zero
variable [comm_monoid_with_zero α]
lemma ne_zero_of_finite {a b : α} (h : finite a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h in λ hb, by simpa [hb] using hn
variable [decidable_rel ((∣) : α → α → Prop)]
@[simp] protected lemma zero (a : α) : multiplicity a 0 = ⊤ :=
roption.eq_none_iff.2 (λ n ⟨⟨k, hk⟩, _⟩, hk (dvd_zero _))
@[simp] lemma multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
begin
apply multiplicity.multiplicity_eq_zero_of_not_dvd,
rwa zero_dvd_iff,
end
end comm_monoid_with_zero
section comm_semiring
variables [comm_semiring α] [decidable_rel ((∣) : α → α → Prop)]
lemma min_le_multiplicity_add {p a b : α} :
min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) :=
(le_total (multiplicity p a) (multiplicity p b)).elim
(λ h, by rw [min_eq_left h, multiplicity_le_multiplicity_iff];
exact λ n hn, dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn))
(λ h, by rw [min_eq_right h, multiplicity_le_multiplicity_iff];
exact λ n hn, dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn)
end comm_semiring
section comm_ring
variables [comm_ring α] [decidable_rel ((∣) : α → α → Prop)]
open_locale classical
@[simp] protected lemma neg (a b : α) : multiplicity a (-b) = multiplicity a b :=
roption.ext' (by simp only [multiplicity, enat.find, dvd_neg])
(λ h₁ h₂, enat.coe_inj.1 (by rw [enat.coe_get]; exact
eq.symm (unique ((dvd_neg _ _).2 (pow_multiplicity_dvd _))
(mt (dvd_neg _ _).1 (is_greatest' _ (lt_succ_self _))))))
lemma multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a + b) = multiplicity p b :=
begin
apply le_antisymm,
{ apply enat.le_of_lt_add_one,
cases enat.ne_top_iff.mp (enat.ne_top_of_lt h) with k hk,
rw [hk], rw_mod_cast [multiplicity_lt_iff_neg_dvd], intro h_dvd,
rw [← dvd_add_iff_right] at h_dvd,
apply multiplicity.is_greatest _ h_dvd, rw [hk], apply_mod_cast nat.lt_succ_self,
rw [pow_dvd_iff_le_multiplicity, enat.coe_add, ← hk], exact enat.add_one_le_of_lt h },
{ convert min_le_multiplicity_add, rw [min_eq_right (le_of_lt h)] }
end
lemma multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) :
multiplicity p (a - b) = multiplicity p b :=
by { rw [sub_eq_add_neg, multiplicity_add_of_gt]; rwa [multiplicity.neg] }
lemma multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) :
multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) :=
begin
rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with hab|hab|hab,
{ rw [add_comm, multiplicity_add_of_gt hab, min_eq_left], exact le_of_lt hab },
{ contradiction },
{ rw [multiplicity_add_of_gt hab, min_eq_right], exact le_of_lt hab},
end
end comm_ring
section comm_cancel_monoid_with_zero
variables [comm_cancel_monoid_with_zero α]
lemma finite_mul_aux {p : α} (hp : prime p) : ∀ {n m : ℕ} {a b : α},
¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b
| n m := λ a b ha hb ⟨s, hs⟩,
have p ∣ a * b, from ⟨p ^ (n + m) * s,
by simp [hs, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩,
(hp.2.2 a b this).elim
(λ ⟨x, hx⟩, have hn0 : 0 < n,
from nat.pos_of_ne_zero (λ hn0, by clear _fun_match _fun_match; simpa [hx, hn0] using ha),
have wf : (n - 1) < n, from nat.sub_lt_self hn0 dec_trivial,
have hpx : ¬ p ^ (n - 1 + 1) ∣ x,
from λ ⟨y, hy⟩, ha (hx.symm ▸ ⟨y, mul_right_cancel' hp.1
$ by rw [nat.sub_add_cancel hn0] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩),
have 1 ≤ n + m, from le_trans hn0 (le_add_right n m),
finite_mul_aux hpx hb ⟨s, mul_right_cancel' hp.1 begin
rw [← nat.sub_add_comm hn0, nat.sub_add_cancel this],
clear _fun_match _fun_match finite_mul_aux,
simp [*, mul_comm, mul_assoc, mul_left_comm, pow_add] at *
end⟩)
(λ ⟨x, hx⟩, have hm0 : 0 < m,
from nat.pos_of_ne_zero (λ hm0, by clear _fun_match _fun_match; simpa [hx, hm0] using hb),
have wf : (m - 1) < m, from nat.sub_lt_self hm0 dec_trivial,
have hpx : ¬ p ^ (m - 1 + 1) ∣ x,
from λ ⟨y, hy⟩, hb (hx.symm ▸ ⟨y, mul_right_cancel' hp.1
$ by rw [nat.sub_add_cancel hm0] at hy;
simp [hy, pow_add, mul_comm, mul_assoc, mul_left_comm]⟩),
finite_mul_aux ha hpx ⟨s, mul_right_cancel' hp.1 begin
rw [add_assoc, nat.sub_add_cancel hm0],
clear _fun_match _fun_match finite_mul_aux,
simp [*, mul_comm, mul_assoc, mul_left_comm, pow_add] at *
end⟩)
lemma finite_mul {p a b : α} (hp : prime p) : finite p a → finite p b → finite p (a * b) :=
λ ⟨n, hn⟩ ⟨m, hm⟩, ⟨n + m, finite_mul_aux hp hn hm⟩
lemma finite_mul_iff {p a b : α} (hp : prime p) : finite p (a * b) ↔ finite p a ∧ finite p b :=
⟨λ h, ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩,
λ h, finite_mul hp h.1 h.2⟩
lemma finite_pow {p a : α} (hp : prime p) : Π {k : ℕ} (ha : finite p a), finite p (a ^ k)
| 0 ha := ⟨0, by simp [mt is_unit_iff_dvd_one.2 hp.2.1]⟩
| (k+1) ha := by rw [pow_succ]; exact finite_mul hp ha (finite_pow ha)
variable [decidable_rel ((∣) : α → α → Prop)]
@[simp] lemma multiplicity_self {a : α} (ha : ¬is_unit a) (ha0 : a ≠ 0) :
multiplicity a a = 1 :=
eq_some_iff.2 ⟨by simp, λ ⟨b, hb⟩, ha (is_unit_iff_dvd_one.2
⟨b, mul_left_cancel' ha0 $ by clear _fun_match;
simpa [pow_succ, mul_assoc] using hb⟩)⟩
@[simp] lemma get_multiplicity_self {a : α} (ha : finite a a) :
get (multiplicity a a) ha = 1 :=
roption.get_eq_iff_eq_some.2 (eq_some_iff.2
⟨by simp, λ ⟨b, hb⟩,
by rw [← mul_one a, pow_add, pow_one, mul_assoc, mul_assoc,
mul_right_inj' (ne_zero_of_finite ha)] at hb;
exact mt is_unit_iff_dvd_one.2 (not_unit_of_finite ha)
⟨b, by clear _fun_match; simp * at *⟩⟩)
protected lemma mul' {p a b : α} (hp : prime p)
(h : (multiplicity p (a * b)).dom) :
get (multiplicity p (a * b)) h =
get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2 :=
have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a, from pow_multiplicity_dvd _,
have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b, from pow_multiplicity_dvd _,
have hpoweq : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) =
p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 *
p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2,
by simp [pow_add],
have hdiv : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣ a * b,
by rw [hpoweq]; apply mul_dvd_mul; assumption,
have hsucc : ¬p ^ ((get (multiplicity p a) ((finite_mul_iff hp).1 h).1 +
get (multiplicity p b) ((finite_mul_iff hp).1 h).2) + 1) ∣ a * b,
from λ h, not_or (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _))
(by exact succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp hdiva hdivb h),
by rw [← enat.coe_inj, enat.coe_get, eq_some_iff];
exact ⟨hdiv, hsucc⟩
open_locale classical
protected lemma mul {p a b : α} (hp : prime p) :
multiplicity p (a * b) = multiplicity p a + multiplicity p b :=
if h : finite p a ∧ finite p b then
by rw [← enat.coe_get (finite_iff_dom.1 h.1), ← enat.coe_get (finite_iff_dom.1 h.2),
← enat.coe_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)),
← enat.coe_add, enat.coe_inj, multiplicity.mul' hp]; refl
else begin
rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)],
cases not_and_distrib.1 h with h h;
simp [eq_top_iff_not_finite.2 h]
end
lemma finset.prod {β : Type*} {p : α} (hp : prime p) (s : finset β) (f : β → α) :
multiplicity p (∏ x in s, f x) = ∑ x in s, multiplicity p (f x) :=
begin
classical,
induction s using finset.induction with a s has ih h,
{ simp only [finset.sum_empty, finset.prod_empty],
convert one_right hp.not_unit },
{ simp [has, ← ih],
convert multiplicity.mul hp }
end
protected lemma pow' {p a : α} (hp : prime p) (ha : finite p a) : ∀ {k : ℕ},
get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha
| 0 := by dsimp [pow_zero]; simp [one_right hp.not_unit]; refl
| (k+1) := by dsimp only [pow_succ];
erw [multiplicity.mul' hp, pow', add_mul, one_mul, add_comm]
lemma pow {p a : α} (hp : prime p) : ∀ {k : ℕ},
multiplicity p (a ^ k) = k •ℕ (multiplicity p a)
| 0 := by simp [one_right hp.not_unit]
| (succ k) := by simp [pow_succ, succ_nsmul, pow, multiplicity.mul hp]
lemma multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬ is_unit p) (n : ℕ) :
multiplicity p (p ^ n) = n :=
by { rw [eq_some_iff], use dvd_refl _, rw [pow_dvd_pow_iff h0 hu], apply nat.not_succ_le_self }
lemma multiplicity_pow_self_of_prime {p : α} (hp : prime p) (n : ℕ) :
multiplicity p (p ^ n) = n :=
multiplicity_pow_self hp.ne_zero hp.not_unit n
end comm_cancel_monoid_with_zero
end multiplicity
section nat
open multiplicity
lemma multiplicity_eq_zero_of_coprime {p a b : ℕ} (hp : p ≠ 1)
(hle : multiplicity p a ≤ multiplicity p b)
(hab : nat.coprime a b) : multiplicity p a = 0 :=
begin
rw [multiplicity_le_multiplicity_iff] at hle,
rw [← nonpos_iff_eq_zero, ← not_lt, enat.pos_iff_one_le, ← enat.coe_one,
← pow_dvd_iff_le_multiplicity],
assume h,
have := nat.dvd_gcd h (hle _ h),
rw [coprime.gcd_eq_one hab, nat.dvd_one, pow_one] at this,
exact hp this
end
end nat
|
fa1c2cfc4b50894e876ad27bd65e6554968876a3 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/stream/basic_auto.lean | cecd843c6b2b191cf0cbea54f5d797ff05241461 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,145 | lean | /-
Copyright (c) 2020 Gabriel Ebner, Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.ext
import Mathlib.Lean3Lib.data.stream
import Mathlib.data.list.basic
import Mathlib.data.list.range
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# Additional instances and attributes for streams
-/
protected instance stream.inhabited {α : Type u_1} [Inhabited α] : Inhabited (stream α) :=
{ default := stream.const Inhabited.default }
namespace stream
/-- `take s n` returns a list of the `n` first elements of stream `s` -/
def take {α : Type u_1} (s : stream α) (n : ℕ) : List α := list.map s (list.range n)
theorem length_take {α : Type u_1} (s : stream α) (n : ℕ) : list.length (take s n) = n := sorry
/-- Use a state monad to generate a stream through corecursion -/
def corec_state {σ : Type u_1} {α : Type u_1} (cmd : state σ α) (s : σ) : stream α :=
corec prod.fst (state_t.run cmd ∘ prod.snd) (state_t.run cmd s)
end Mathlib |
853d354ffede03fe13086687b646f6c2a7148dd1 | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/scope.lean | cc9a44bb9825585c5168a693bfe5cbeee4c849bc | [
"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 | 912 | lean | import Int.
scope
variable A : Type
variable B : Type
variable f : A -> A -> A
definition g (x y : A) : A := f y x
variable h : A -> B
variable hinv : B -> A
axiom Inv (x : A) : hinv (h x) = x
axiom H1 (x y : A) : f x y = f y x
theorem f_eq_g : f = g := funext (fun x, (funext (fun y,
let L1 : f x y = f y x := H1 x y,
L2 : f y x = g x y := refl (g x y)
in trans L1 L2)))
theorem Inj (x y : A) (H : h x = h y) : x = y :=
let L1 : hinv (h x) = hinv (h y) := congr2 hinv H,
L2 : hinv (h x) = x := Inv x,
L3 : hinv (h y) = y := Inv y,
L4 : x = hinv (h x) := symm L2,
L5 : x = hinv (h y) := trans L4 L1
in trans L5 L3.
end
print environment 3.
eval g Int Int::sub 10 20 |
22f0bb1312549bd551c489975eec9ed479bab885 | 0845ae2ca02071debcfd4ac24be871236c01784f | /library/init/data/list/default.lean | 869f13423b915ba112f03f61c6b958e67a10bb0d | [
"Apache-2.0"
] | permissive | GaloisInc/lean4 | 74c267eb0e900bfaa23df8de86039483ecbd60b7 | 228ddd5fdcd98dd4e9c009f425284e86917938aa | refs/heads/master | 1,643,131,356,301 | 1,562,715,572,000 | 1,562,715,572,000 | 192,390,898 | 0 | 0 | null | 1,560,792,750,000 | 1,560,792,749,000 | null | UTF-8 | Lean | false | false | 225 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.list.basic init.data.list.instances
|
5bb0ba8c9eb5921b24e4e9519db553f193012a88 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/field_auto.lean | 78ceebaa1c47181bca3c5fa623aeeabd356bfddc | [] | 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,644 | lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.ring.basic
import Mathlib.algebra.group_with_zero.default
import Mathlib.PostPort
universes u l u_1 u_2
namespace Mathlib
/-- A `division_ring` is a `ring` with multiplicative inverses for nonzero elements -/
class division_ring (K : Type u) extends div_inv_monoid K, ring K, nontrivial K where
mul_inv_cancel : ∀ {a : K}, a ≠ 0 → a * (a⁻¹) = 1
inv_zero : 0⁻¹ = 0
/-- Every division ring is a `group_with_zero`. -/
protected instance division_ring.to_group_with_zero {K : Type u} [division_ring K] :
group_with_zero K :=
group_with_zero.mk division_ring.mul division_ring.mul_assoc division_ring.one
division_ring.one_mul division_ring.mul_one division_ring.zero sorry sorry division_ring.inv
division_ring.div division_ring.exists_pair_ne division_ring.inv_zero
division_ring.mul_inv_cancel
theorem inverse_eq_has_inv {K : Type u} [division_ring K] : ring.inverse = has_inv.inv := sorry
theorem one_div_neg_one_eq_neg_one {K : Type u} [division_ring K] : 1 / -1 = -1 :=
(fun (this : -1 * -1 = 1) => Eq.symm (eq_one_div_of_mul_eq_one this))
(eq.mpr (id (Eq._oldrec (Eq.refl (-1 * -1 = 1)) (neg_mul_neg 1 1)))
(eq.mpr (id (Eq._oldrec (Eq.refl (1 * 1 = 1)) (one_mul 1))) (Eq.refl 1)))
theorem one_div_neg_eq_neg_one_div {K : Type u} [division_ring K] (a : K) : 1 / -a = -(1 / a) :=
sorry
theorem div_neg_eq_neg_div {K : Type u} [division_ring K] (a : K) (b : K) : b / -a = -(b / a) :=
sorry
theorem neg_div {K : Type u} [division_ring K] (a : K) (b : K) : -b / a = -(b / a) := sorry
theorem neg_div' {K : Type u_1} [division_ring K] (a : K) (b : K) : -(b / a) = -b / a := sorry
theorem neg_div_neg_eq {K : Type u} [division_ring K] (a : K) (b : K) : -a / -b = a / b :=
eq.mpr (id (Eq._oldrec (Eq.refl (-a / -b = a / b)) (div_neg_eq_neg_div b (-a))))
(eq.mpr (id (Eq._oldrec (Eq.refl (-(-a / b) = a / b)) (neg_div b a)))
(eq.mpr (id (Eq._oldrec (Eq.refl ( --(a / b) = a / b)) (neg_neg (a / b)))) (Eq.refl (a / b))))
theorem div_add_div_same {K : Type u} [division_ring K] (a : K) (b : K) (c : K) :
a / c + b / c = (a + b) / c :=
sorry
theorem same_add_div {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
(b + a) / b = 1 + a / b :=
sorry
theorem one_add_div {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
1 + a / b = (b + a) / b :=
Eq.symm (same_add_div h)
theorem div_add_same {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
(a + b) / b = a / b + 1 :=
sorry
theorem div_add_one {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
a / b + 1 = (a + b) / b :=
Eq.symm (div_add_same h)
theorem div_sub_div_same {K : Type u} [division_ring K] (a : K) (b : K) (c : K) :
a / c - b / c = (a - b) / c :=
sorry
theorem same_sub_div {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
(b - a) / b = 1 - a / b :=
sorry
theorem one_sub_div {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
1 - a / b = (b - a) / b :=
Eq.symm (same_sub_div h)
theorem div_sub_same {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
(a - b) / b = a / b - 1 :=
sorry
theorem div_sub_one {K : Type u} [division_ring K] {a : K} {b : K} (h : b ≠ 0) :
a / b - 1 = (a - b) / b :=
Eq.symm (div_sub_same h)
theorem neg_inv {K : Type u} [division_ring K] {a : K} : -(a⁻¹) = (-a⁻¹) :=
eq.mpr (id (Eq._oldrec (Eq.refl (-(a⁻¹) = (-a⁻¹))) (inv_eq_one_div a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (-(1 / a) = (-a⁻¹))) (inv_eq_one_div (-a))))
(eq.mpr (id (Eq._oldrec (Eq.refl (-(1 / a) = 1 / -a)) (div_neg_eq_neg_div a 1)))
(Eq.refl (-(1 / a)))))
theorem add_div {K : Type u} [division_ring K] (a : K) (b : K) (c : K) :
(a + b) / c = a / c + b / c :=
Eq.symm (div_add_div_same a b c)
theorem sub_div {K : Type u} [division_ring K] (a : K) (b : K) (c : K) :
(a - b) / c = a / c - b / c :=
Eq.symm (div_sub_div_same a b c)
theorem div_neg {K : Type u} [division_ring K] {b : K} (a : K) : a / -b = -(a / b) :=
eq.mpr (id (Eq._oldrec (Eq.refl (a / -b = -(a / b))) (Eq.symm (div_neg_eq_neg_div b a))))
(Eq.refl (a / -b))
theorem inv_neg {K : Type u} [division_ring K] {a : K} : -a⁻¹ = -(a⁻¹) :=
eq.mpr (id (Eq._oldrec (Eq.refl (-a⁻¹ = -(a⁻¹))) neg_inv)) (Eq.refl (-a⁻¹))
theorem one_div_mul_add_mul_one_div_eq_one_div_add_one_div {K : Type u} [division_ring K] {a : K}
{b : K} (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a * (a + b) * (1 / b) = 1 / a + 1 / b :=
sorry
theorem one_div_mul_sub_mul_one_div_eq_one_div_add_one_div {K : Type u} [division_ring K] {a : K}
{b : K} (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a * (b - a) * (1 / b) = 1 / a - 1 / b :=
sorry
theorem add_div_eq_mul_add_div {K : Type u} [division_ring K] (a : K) (b : K) {c : K} (hc : c ≠ 0) :
a + b / c = (a * c + b) / c :=
iff.mpr (eq_div_iff_mul_eq hc)
(eq.mpr (id (Eq._oldrec (Eq.refl ((a + b / c) * c = a * c + b)) (right_distrib a (b / c) c)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * c + b / c * c = a * c + b)) (div_mul_cancel b hc)))
(Eq.refl (a * c + b))))
protected instance division_ring.to_domain {K : Type u} [division_ring K] : domain K :=
domain.mk division_ring.add division_ring.add_assoc division_ring.zero division_ring.zero_add
division_ring.add_zero division_ring.neg division_ring.sub division_ring.add_left_neg
division_ring.add_comm division_ring.mul division_ring.mul_assoc division_ring.one
division_ring.one_mul division_ring.mul_one division_ring.left_distrib
division_ring.right_distrib division_ring.exists_pair_ne sorry
/-- A `field` is a `comm_ring` with multiplicative inverses for nonzero elements -/
class field (K : Type u) extends has_inv K, comm_ring K, nontrivial K where
mul_inv_cancel : ∀ {a : K}, a ≠ 0 → a * (a⁻¹) = 1
inv_zero : 0⁻¹ = 0
protected instance field.to_division_ring {K : Type u} [field K] : division_ring K :=
division_ring.mk field.add sorry field.zero sorry sorry field.neg field.sub sorry sorry field.mul
sorry field.one sorry sorry sorry sorry field.inv
(div_inv_monoid.div._default field.mul sorry field.one sorry sorry field.inv) sorry sorry sorry
/-- Every field is a `comm_group_with_zero`. -/
protected instance field.to_comm_group_with_zero {K : Type u} [field K] : comm_group_with_zero K :=
comm_group_with_zero.mk group_with_zero.mul sorry group_with_zero.one sorry sorry field.mul_comm
group_with_zero.zero sorry sorry group_with_zero.inv group_with_zero.div sorry sorry sorry
theorem one_div_add_one_div {K : Type u} [field K] {a : K} {b : K} (ha : a ≠ 0) (hb : b ≠ 0) :
1 / a + 1 / b = (a + b) / (a * b) :=
sorry
theorem div_add_div {K : Type u} [field K] (a : K) {b : K} (c : K) {d : K} (hb : b ≠ 0)
(hd : d ≠ 0) : a / b + c / d = (a * d + b * c) / (b * d) :=
sorry
theorem div_sub_div {K : Type u} [field K] (a : K) {b : K} (c : K) {d : K} (hb : b ≠ 0)
(hd : d ≠ 0) : a / b - c / d = (a * d - b * c) / (b * d) :=
sorry
theorem inv_add_inv {K : Type u} [field K] {a : K} {b : K} (ha : a ≠ 0) (hb : b ≠ 0) :
a⁻¹ + (b⁻¹) = (a + b) / (a * b) :=
sorry
theorem inv_sub_inv {K : Type u} [field K] {a : K} {b : K} (ha : a ≠ 0) (hb : b ≠ 0) :
a⁻¹ - (b⁻¹) = (b - a) / (a * b) :=
sorry
theorem add_div' {K : Type u} [field K] (a : K) (b : K) (c : K) (hc : c ≠ 0) :
b + a / c = (b * c + a) / c :=
sorry
theorem sub_div' {K : Type u} [field K] (a : K) (b : K) (c : K) (hc : c ≠ 0) :
b - a / c = (b * c - a) / c :=
sorry
theorem div_add' {K : Type u} [field K] (a : K) (b : K) (c : K) (hc : c ≠ 0) :
a / c + b = (a + b * c) / c :=
sorry
theorem div_sub' {K : Type u} [field K] (a : K) (b : K) (c : K) (hc : c ≠ 0) :
a / c - b = (a - c * b) / c :=
sorry
protected instance field.to_integral_domain {K : Type u} [field K] : integral_domain K :=
integral_domain.mk field.add field.add_assoc field.zero field.zero_add field.add_zero field.neg
field.sub field.add_left_neg field.add_comm field.mul field.mul_assoc field.one field.one_mul
field.mul_one field.left_distrib field.right_distrib field.mul_comm field.exists_pair_ne sorry
/-- A predicate to express that a ring is a field.
This is mainly useful because such a predicate does not contain data,
and can therefore be easily transported along ring isomorphisms.
Additionaly, this is useful when trying to prove that
a particular ring structure extends to a field. -/
structure is_field (R : Type u) [ring R] where
exists_pair_ne : ∃ (x : R), ∃ (y : R), x ≠ y
mul_comm : ∀ (x y : R), x * y = y * x
mul_inv_cancel : ∀ {a : R}, a ≠ 0 → ∃ (b : R), a * b = 1
/-- Transferring from field to is_field -/
theorem field.to_is_field (R : Type u) [field R] : is_field R :=
is_field.mk field.exists_pair_ne field.mul_comm
fun (a : R) (ha : a ≠ 0) => Exists.intro (a⁻¹) (field.mul_inv_cancel ha)
/-- Transferring from is_field to field -/
def is_field.to_field (R : Type u) [ring R] (h : is_field R) : field R :=
field.mk ring.add ring.add_assoc ring.zero ring.zero_add ring.add_zero ring.neg ring.sub
ring.add_left_neg ring.add_comm ring.mul ring.mul_assoc ring.one ring.one_mul ring.mul_one
ring.left_distrib ring.right_distrib (is_field.mul_comm h)
(fun (a : R) =>
dite (a = 0) (fun (ha : a = 0) => 0)
fun (ha : ¬a = 0) => classical.some (is_field.mul_inv_cancel h ha))
(is_field.exists_pair_ne h) sorry sorry
/-- For each field, and for each nonzero element of said field, there is a unique inverse.
Since `is_field` doesn't remember the data of an `inv` function and as such,
a lemma that there is a unique inverse could be useful.
-/
theorem uniq_inv_of_is_field (R : Type u) [ring R] (hf : is_field R) (x : R) :
x ≠ 0 → exists_unique fun (y : R) => x * y = 1 :=
sorry
namespace ring_hom
@[simp] theorem map_units_inv {K : Type u} {R : Type u_1} [semiring R] [division_ring K]
(f : R →+* K) (u : units R) : coe_fn f ↑(u⁻¹) = (coe_fn f ↑u⁻¹) :=
monoid_hom.map_units_inv (↑f) u
theorem map_ne_zero {K : Type u} {R : Type u_1} [division_ring K] [semiring R] [nontrivial R]
(f : K →+* R) {x : K} : coe_fn f x ≠ 0 ↔ x ≠ 0 :=
monoid_with_zero_hom.map_ne_zero (to_monoid_with_zero_hom f)
@[simp] theorem map_eq_zero {K : Type u} {R : Type u_1} [division_ring K] [semiring R]
[nontrivial R] (f : K →+* R) {x : K} : coe_fn f x = 0 ↔ x = 0 :=
monoid_with_zero_hom.map_eq_zero (to_monoid_with_zero_hom f)
theorem map_inv {K : Type u} {K' : Type u_2} [division_ring K] [division_ring K'] (g : K →+* K')
(x : K) : coe_fn g (x⁻¹) = (coe_fn g x⁻¹) :=
monoid_with_zero_hom.map_inv' (to_monoid_with_zero_hom g) x
theorem map_div {K : Type u} {K' : Type u_2} [division_ring K] [division_ring K'] (g : K →+* K')
(x : K) (y : K) : coe_fn g (x / y) = coe_fn g x / coe_fn g y :=
monoid_with_zero_hom.map_div (to_monoid_with_zero_hom g) x y
protected theorem injective {K : Type u} {R : Type u_1} [division_ring K] [semiring R]
[nontrivial R] (f : K →+* R) : function.injective ⇑f :=
iff.mpr (injective_iff f) fun (x : K) => iff.mp (map_eq_zero f)
end ring_hom
/-- Constructs a `division_ring` structure on a `ring` consisting only of units and 0. -/
def division_ring_of_is_unit_or_eq_zero {R : Type u_1} [nontrivial R] [hR : ring R]
(h : ∀ (a : R), is_unit a ∨ a = 0) : division_ring R :=
division_ring.mk ring.add ring.add_assoc group_with_zero.zero ring.zero_add ring.add_zero ring.neg
ring.sub ring.add_left_neg ring.add_comm group_with_zero.mul sorry group_with_zero.one sorry
sorry ring.left_distrib ring.right_distrib group_with_zero.inv group_with_zero.div sorry sorry
sorry
/-- Constructs a `field` structure on a `comm_ring` consisting only of units and 0. -/
def field_of_is_unit_or_eq_zero {R : Type u_1} [nontrivial R] [hR : comm_ring R]
(h : ∀ (a : R), is_unit a ∨ a = 0) : field R :=
field.mk comm_ring.add comm_ring.add_assoc group_with_zero.zero comm_ring.zero_add
comm_ring.add_zero comm_ring.neg comm_ring.sub comm_ring.add_left_neg comm_ring.add_comm
group_with_zero.mul sorry group_with_zero.one sorry sorry comm_ring.left_distrib
comm_ring.right_distrib comm_ring.mul_comm group_with_zero.inv sorry sorry sorry
end Mathlib |
6f6f09ed40d194ab01d6be21495afd5a7b73bd7d | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /test/norm_cast_cardinal.lean | f0d34157ffec7903084f7678803e1757280401d8 | [
"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 | 1,002 | lean | import tactic.norm_cast
constant cardinal : Type
@[instance] constant cardinal.has_zero : has_zero cardinal
@[instance] constant cardinal.has_one : has_one cardinal
@[instance] constant cardinal.has_add : has_add cardinal
constant cardinal.succ : cardinal → cardinal
@[instance] constant cardinal.has_coe_from_nat : has_coe ℕ cardinal
@[norm_cast] axiom coe_zero : ((0 : ℕ) : cardinal) = 0
@[norm_cast] axiom coe_one : ((1 : ℕ) : cardinal) = 1
@[norm_cast] axiom coe_add {a b : ℕ} : ((a + b : ℕ) : cardinal) = a + b
@[norm_cast] lemma coe_bit0 {a : ℕ} : ((bit0 a : ℕ) : cardinal) = bit0 a := coe_add
@[norm_cast] lemma coe_bit1 {a : ℕ} : ((bit1 a : ℕ) : cardinal) = bit1 a :=
by unfold bit1; norm_cast
@[norm_cast, priority 900] axiom coe_succ {n : ℕ} : (n.succ : cardinal) = cardinal.succ n
example : cardinal.succ 0 = 1 := by norm_cast
example : cardinal.succ 1 = 2 := by norm_cast
example : cardinal.succ 2 = 3 := by norm_cast
example : cardinal.succ 3 = 4 := by norm_cast
|
6828e48fd66a11508f65faaf8a02374d32067c82 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/mulcomm.lean | 053aa6daa7bc7239ea24135eaa8a71b4ea697d45 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,435 | lean | class MulComm (α : Type u) [Mul α] : Prop where
mulComm : {a b : α} → a * b = b * a
instance : Mul Bool where
mul := and
instance : MulComm Bool where
mulComm {a b} :=
match a, b with
| true, true => rfl
| true, false => rfl
| false, true => rfl
| false, false => rfl
instance : MulComm Bool where
mulComm := fun {a b} =>
match a, b with
| true, true => rfl
| true, false => rfl
| false, true => rfl
| false, false => rfl
instance : MulComm Bool := {
mulComm := fun {a b} =>
match a, b with
| true, true => rfl
| true, false => rfl
| false, true => rfl
| false, false => rfl
}
instance : MulComm Bool := {
mulComm := @fun a b =>
match a, b with
| true, true => rfl
| true, false => rfl
| false, true => rfl
| false, false => rfl
}
instance : MulComm Bool where
mulComm {a b} := by cases a <;> cases b <;> rfl
instance : MulComm Bool :=
⟨by intro a b; cases a <;> cases b <;> rfl⟩
instance : MulComm Bool :=
⟨fun {a b} => by cases a <;> cases b <;> rfl⟩
instance : MulComm Bool :=
⟨fun {a b} =>
match a, b with
| true, true => rfl
| true, false => rfl
| false, true => rfl
| false, false => rfl⟩
instance : MulComm Bool :=
⟨@fun a b =>
match a, b with
| true, true => rfl
| true, false => rfl
| false, true => rfl
| false, false => rfl⟩
|
70fedadb8a6c641596f9c8c5f4ae7a175316ea1b | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/geometry/manifold/algebra/left_invariant_derivation.lean | 5f6b6b87d9285f2048cd62025bde981917c78fe8 | [
"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 | 8,573 | lean | /-
Copyright © 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri
-/
import geometry.manifold.derivation_bundle
/-!
# Left invariant derivations
In this file we define the concept of left invariant derivation for a Lie group. The concept is
analogous to the more classical concept of left invariant vector fields, and it holds that the
derivation associated to a vector field is left invariant iff the field is.
Moreover we prove that `left_invariant_derivation I G` has the structure of a Lie algebra, hence
implementing one of the possible definitions of the Lie algebra attached to a Lie group.
-/
noncomputable theory
open_locale lie_group manifold derivation
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(G : Type*) [topological_space G] [charted_space H G] [monoid G] [has_smooth_mul I G] (g h : G)
-- Generate trivial has_sizeof instance. It prevents weird type class inference timeout problems
local attribute [nolint instance_priority, instance, priority 10000]
private def disable_has_sizeof {α} : has_sizeof α := ⟨λ _, 0⟩
/--
Left-invariant global derivations.
A global derivation is left-invariant if it is equal to its pullback along left multiplication by
an arbitrary element of `G`.
-/
structure left_invariant_derivation extends derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯ :=
(left_invariant'' : ∀ g, 𝒅ₕ(smooth_left_mul_one I g) (derivation.eval_at 1 to_derivation) =
derivation.eval_at g to_derivation)
variables {I G}
namespace left_invariant_derivation
instance : has_coe (left_invariant_derivation I G) (derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) :=
⟨λ X, X.to_derivation⟩
instance : has_coe_to_fun (left_invariant_derivation I G) (λ _, C^∞⟮I, G; 𝕜⟯ → C^∞⟮I, G; 𝕜⟯) :=
⟨λ X, X.to_derivation.to_fun⟩
variables
{M : Type*} [topological_space M] [charted_space H M] {x : M} {r : 𝕜}
{X Y : left_invariant_derivation I G} {f f' : C^∞⟮I, G; 𝕜⟯}
lemma to_fun_eq_coe : X.to_fun = ⇑X := rfl
lemma coe_to_linear_map : ⇑(X : C^∞⟮I, G; 𝕜⟯ →ₗ[𝕜] C^∞⟮I, G; 𝕜⟯) = X := rfl
@[simp] lemma to_derivation_eq_coe : X.to_derivation = X := rfl
lemma coe_injective :
@function.injective (left_invariant_derivation I G) (_ → C^⊤⟮I, G; 𝕜⟯) coe_fn :=
λ X Y h, by { cases X, cases Y, congr', exact derivation.coe_injective h }
@[ext] theorem ext (h : ∀ f, X f = Y f) : X = Y :=
coe_injective $ funext h
variables (X Y f)
lemma coe_derivation :
⇑(X : derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) = (X : C^∞⟮I, G; 𝕜⟯ → C^∞⟮I, G; 𝕜⟯) := rfl
lemma coe_derivation_injective : function.injective
(coe : left_invariant_derivation I G → derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) :=
λ X Y h, by { cases X, cases Y, congr, exact h }
/-- Premature version of the lemma. Prefer using `left_invariant` instead. -/
lemma left_invariant' :
𝒅ₕ (smooth_left_mul_one I g) (derivation.eval_at (1 : G) ↑X) = derivation.eval_at g ↑X :=
left_invariant'' X g
@[simp] lemma map_add : X (f + f') = X f + X f' := derivation.map_add X f f'
@[simp] lemma map_zero : X 0 = 0 := derivation.map_zero X
@[simp] lemma map_neg : X (-f) = -X f := derivation.map_neg X f
@[simp] lemma map_sub : X (f - f') = X f - X f' := derivation.map_sub X f f'
@[simp] lemma map_smul : X (r • f) = r • X f := derivation.map_smul X r f
@[simp] lemma leibniz : X (f * f') = f • X f' + f' • X f := X.leibniz' _ _
instance : has_zero (left_invariant_derivation I G) :=
⟨⟨0, λ g, by simp only [linear_map.map_zero, derivation.coe_zero]⟩⟩
instance : inhabited (left_invariant_derivation I G) := ⟨0⟩
instance : has_add (left_invariant_derivation I G) :=
{ add := λ X Y, ⟨X + Y, λ g, by simp only [linear_map.map_add, derivation.coe_add,
left_invariant', pi.add_apply]⟩ }
instance : has_neg (left_invariant_derivation I G) :=
{ neg := λ X, ⟨-X, λ g, by simp [left_invariant']⟩ }
instance : has_sub (left_invariant_derivation I G) :=
{ sub := λ X Y, ⟨X - Y, λ g, by simp [left_invariant']⟩ }
@[simp] lemma coe_add : ⇑(X + Y) = X + Y := rfl
@[simp] lemma coe_zero : ⇑(0 : left_invariant_derivation I G) = 0 := rfl
@[simp] lemma coe_neg : ⇑(-X) = -X := rfl
@[simp] lemma coe_sub : ⇑(X - Y) = X - Y := rfl
@[simp, norm_cast] lemma lift_add :
(↑(X + Y) : derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) = X + Y := rfl
@[simp, norm_cast] lemma lift_zero :
(↑(0 : left_invariant_derivation I G) : derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) = 0 := rfl
instance : add_comm_group (left_invariant_derivation I G) :=
coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub
instance : has_scalar 𝕜 (left_invariant_derivation I G) :=
{ smul := λ r X, ⟨r • X, λ g, by simp only [derivation.smul_apply, smul_eq_mul,
mul_eq_mul_left_iff, linear_map.map_smul, left_invariant']⟩ }
variables (r X)
@[simp] lemma coe_smul : ⇑(r • X) = r • X := rfl
@[simp] lemma lift_smul (k : 𝕜) : (↑(k • X) : derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) = k • X := rfl
variables (I G)
/-- The coercion to function is a monoid homomorphism. -/
@[simps] def coe_fn_add_monoid_hom :
(left_invariant_derivation I G) →+ (C^∞⟮I, G; 𝕜⟯ → C^∞⟮I, G; 𝕜⟯) :=
⟨λ X, X.to_derivation.to_fun, coe_zero, coe_add⟩
variables {I G}
instance : module 𝕜 (left_invariant_derivation I G) :=
coe_injective.module _ (coe_fn_add_monoid_hom I G) coe_smul
/-- Evaluation at a point for left invariant derivation. Same thing as for generic global
derivations (`derivation.eval_at`). -/
def eval_at : (left_invariant_derivation I G) →ₗ[𝕜] (point_derivation I g) :=
{ to_fun := λ X, derivation.eval_at g ↑X,
map_add' := λ X Y, rfl,
map_smul' := λ k X, rfl }
lemma eval_at_apply : eval_at g X f = (X f) g := rfl
@[simp] lemma eval_at_coe : derivation.eval_at g ↑X = eval_at g X := rfl
lemma left_invariant : 𝒅ₕ(smooth_left_mul_one I g) (eval_at (1 : G) X) = eval_at g X :=
(X.left_invariant'' g)
lemma eval_at_mul : eval_at (g * h) X = 𝒅ₕ(L_apply I g h) (eval_at h X) :=
by { ext f, rw [←left_invariant, apply_hfdifferential, apply_hfdifferential, L_mul,
fdifferential_comp, apply_fdifferential, linear_map.comp_apply, apply_fdifferential,
←apply_hfdifferential, left_invariant] }
lemma comp_L : (X f).comp (𝑳 I g) = X (f.comp (𝑳 I g)) :=
by ext h; rw [times_cont_mdiff_map.comp_apply, L_apply, ←eval_at_apply, eval_at_mul,
apply_hfdifferential, apply_fdifferential, eval_at_apply]
instance : has_bracket (left_invariant_derivation I G) (left_invariant_derivation I G) :=
{ bracket := λ X Y, ⟨⁅(X : derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯), Y⁆, λ g, begin
ext f,
have hX := derivation.congr_fun (left_invariant' g X) (Y f),
have hY := derivation.congr_fun (left_invariant' g Y) (X f),
rw [apply_hfdifferential, apply_fdifferential, derivation.eval_at_apply] at hX hY ⊢,
rw comp_L at hX hY,
rw [derivation.commutator_apply, smooth_map.coe_sub, pi.sub_apply, coe_derivation],
rw coe_derivation at hX hY ⊢,
rw [hX, hY],
refl
end⟩ }
@[simp] lemma commutator_coe_derivation :
⇑⁅X, Y⁆ = (⁅(X : derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯), Y⁆ :
derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) := rfl
lemma commutator_apply : ⁅X, Y⁆ f = X (Y f) - Y (X f) := rfl
instance : lie_ring (left_invariant_derivation I G) :=
{ add_lie := λ X Y Z, by { ext1, simp only [commutator_apply, coe_add, pi.add_apply,
linear_map.map_add, left_invariant_derivation.map_add], ring },
lie_add := λ X Y Z, by { ext1, simp only [commutator_apply, coe_add, pi.add_apply,
linear_map.map_add, left_invariant_derivation.map_add], ring },
lie_self := λ X, by { ext1, simp only [commutator_apply, sub_self], refl },
leibniz_lie := λ X Y Z, by { ext1, simp only [commutator_apply, coe_add, coe_sub, map_sub,
pi.add_apply], ring, } }
instance : lie_algebra 𝕜 (left_invariant_derivation I G) :=
{ lie_smul := λ r Y Z, by { ext1, simp only [commutator_apply, map_smul, smul_sub, coe_smul,
pi.smul_apply] } }
end left_invariant_derivation
|
61e57ebd18b334985fb1d0c9c6722f1b0f6389f1 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/match_convoy.lean | 03ba823406ab1385746fdc5fe24f84bbd46e01d9 | [
"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 | 2,720 | lean | definition foo (a b : bool) : bool :=
match a, b with
| tt, ff := tt
| tt, tt := tt
| ff, tt := tt
| ff, ff := ff
end
example : foo tt tt = tt := rfl
example : foo tt ff = tt := rfl
example : foo ff tt = tt := rfl
example : foo ff ff = ff := rfl
inductive vec (A : Type) : nat → Type
| nil {} : vec nat.zero
| cons : ∀ {n}, A → vec n → vec (nat.succ n)
open vec
definition boo (n : nat) (v : vec bool n) : vec bool n :=
match n, v : ∀ (n : _), vec bool n → _ with
| 0, nil := nil
| n+1, cons a v := cons (bnot a) v
end
constant bag_setoid : ∀ A, setoid (list A)
attribute [instance] bag_setoid
noncomputable definition bag (A : Type) : Type :=
quotient (bag_setoid A)
constant subcount : ∀ {A}, list A → list A → bool
constant list.count : ∀ {A}, A → list A → nat
constant all_of_subcount_eq_tt : ∀ {A} {l₁ l₂ : list A}, subcount l₁ l₂ = tt → ∀ a, list.count a l₁ ≤ list.count a l₂
constant ex_of_subcount_eq_ff : ∀ {A} {l₁ l₂ : list A}, subcount l₁ l₂ = ff → ∃ a, ¬ list.count a l₁ ≤ list.count a l₂
noncomputable definition count {A} (a : A) (b : bag A) : nat :=
quotient.lift_on b (λ l, list.count a l)
(λ l₁ l₂ h, sorry)
noncomputable definition subbag {A} (b₁ b₂ : bag A) := ∀ a, count a b₁ ≤ count a b₂
infix ⊆ := subbag
attribute [instance]
noncomputable definition decidable_subbag {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) :=
quotient.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂,
match subcount l₁ l₂, rfl : ∀ (b : _), subcount l₁ l₂ = b → _ with
| tt, H := is_true (all_of_subcount_eq_tt H)
| ff, H := is_false (λ h,
exists.elim (ex_of_subcount_eq_ff H)
(λ w hw, absurd (h w) hw))
end)
attribute [instance]
noncomputable definition decidable_subbag2 {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) :=
quotient.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂,
match psigma.mk (subcount l₁ l₂) rfl : (Σ' (b : _), subcount l₁ l₂ = b) → _ with
| psigma.mk tt H := is_true (all_of_subcount_eq_tt H)
| psigma.mk ff H := is_false (λ h,
exists.elim (ex_of_subcount_eq_ff H)
(λ w hw, absurd (h w) hw))
end)
local notation ⟦ a , b ⟧ := psigma.mk a b
attribute [instance]
noncomputable definition decidable_subbag3 {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) :=
quotient.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂,
match ⟦subcount l₁ l₂, rfl⟧ : (Σ' (b : _), subcount l₁ l₂ = b) → _ with
| ⟦tt, H⟧ := is_true (all_of_subcount_eq_tt H)
| ⟦ff, H⟧ := is_false (λ h,
exists.elim (ex_of_subcount_eq_ff H)
(λ w hw, absurd (h w) hw))
end)
|
e6a8d291f0d590abd203bb60bdf469741c32dd6b | f7315930643edc12e76c229a742d5446dad77097 | /tests/lean/run/tactic10.lean | fa0daaf29b238939057f506a2e37d0854b0a144c | [
"Apache-2.0"
] | permissive | bmalehorn/lean | 8f77b762a76c59afff7b7403f9eb5fc2c3ce70c1 | 53653c352643751c4b62ff63ec5e555f11dae8eb | refs/heads/master | 1,610,945,684,489 | 1,429,681,220,000 | 1,429,681,449,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 202 | lean | import logic
theorem tst (a b : Prop) (H : a ↔ b) : b ↔ a
:= by rapply iff.intro;
intro Ha;
apply (iff.elim_left H Ha);
intro Hb;
apply (iff.elim_right H Hb)
check tst
|
9c3d8c62bcb7e8fa4337038a488df9d740094525 | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/analysis/topology.lean | bb1c79ff5f38d61a45398e637b95ae8a1dcc0e7e | [
"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 | 8,266 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Computational realization of topological spaces (experimental).
-/
import topology.bases
import data.analysis.filter
open set
open filter (hiding realizer)
open_locale topological_space
/-- A `ctop α σ` is a realization of a topology (basis) on `α`,
represented by a type `σ` together with operations for the top element and
the intersection operation. -/
structure ctop (α σ : Type*) :=
(f : σ → set α)
(top : α → σ)
(top_mem : ∀ x : α, x ∈ f (top x))
(inter : Π a b (x : α), x ∈ f a ∩ f b → σ)
(inter_mem : ∀ a b x h, x ∈ f (inter a b x h))
(inter_sub : ∀ a b x h, f (inter a b x h) ⊆ f a ∩ f b)
variables {α : Type*} {β : Type*} {σ : Type*} {τ : Type*}
namespace ctop
section
variables (F : ctop α σ)
instance : has_coe_to_fun (ctop α σ) := ⟨_, ctop.f⟩
@[simp] theorem coe_mk (f T h₁ I h₂ h₃ a) : (@ctop.mk α σ f T h₁ I h₂ h₃) a = f a := rfl
/-- Map a ctop to an equivalent representation type. -/
def of_equiv (E : σ ≃ τ) : ctop α σ → ctop α τ
| ⟨f, T, h₁, I, h₂, h₃⟩ :=
{ f := λ a, f (E.symm a),
top := λ x, E (T x),
top_mem := λ x, by simpa using h₁ x,
inter := λ a b x h, E (I (E.symm a) (E.symm b) x h),
inter_mem := λ a b x h, by simpa using h₂ (E.symm a) (E.symm b) x h,
inter_sub := λ a b x h, by simpa using h₃ (E.symm a) (E.symm b) x h }
@[simp] theorem of_equiv_val (E : σ ≃ τ) (F : ctop α σ) (a : τ) :
F.of_equiv E a = F (E.symm a) := by cases F; refl
end
/-- Every `ctop` is a topological space. -/
def to_topsp (F : ctop α σ) : topological_space α :=
topological_space.generate_from (set.range F.f)
theorem to_topsp_is_topological_basis (F : ctop α σ) :
@topological_space.is_topological_basis _ F.to_topsp (set.range F.f) :=
⟨λ u ⟨a, e₁⟩ v ⟨b, e₂⟩, e₁ ▸ e₂ ▸
λ x h, ⟨_, ⟨_, rfl⟩, F.inter_mem a b x h, F.inter_sub a b x h⟩,
eq_univ_iff_forall.2 $ λ x, ⟨_, ⟨_, rfl⟩, F.top_mem x⟩, rfl⟩
@[simp] theorem mem_nhds_to_topsp (F : ctop α σ) {s : set α} {a : α} :
s ∈ @nhds _ F.to_topsp a ↔ ∃ b, a ∈ F b ∧ F b ⊆ s :=
(@topological_space.mem_nhds_of_is_topological_basis
_ F.to_topsp _ _ _ F.to_topsp_is_topological_basis).trans $
⟨λ ⟨_, ⟨x, rfl⟩, h⟩, ⟨x, h⟩, λ ⟨x, h⟩, ⟨_, ⟨x, rfl⟩, h⟩⟩
end ctop
/-- A `ctop` realizer for the topological space `T` is a `ctop`
which generates `T`. -/
structure ctop.realizer (α) [T : topological_space α] :=
(σ : Type*)
(F : ctop α σ)
(eq : F.to_topsp = T)
open ctop
protected def ctop.to_realizer (F : ctop α σ) : @ctop.realizer _ F.to_topsp :=
@ctop.realizer.mk _ F.to_topsp σ F rfl
namespace ctop.realizer
protected theorem is_basis [T : topological_space α] (F : realizer α) :
topological_space.is_topological_basis (set.range F.F.f) :=
by have := to_topsp_is_topological_basis F.F; rwa F.eq at this
protected theorem mem_nhds [T : topological_space α] (F : realizer α) {s : set α} {a : α} :
s ∈ 𝓝 a ↔ ∃ b, a ∈ F.F b ∧ F.F b ⊆ s :=
by have := mem_nhds_to_topsp F.F; rwa F.eq at this
theorem is_open_iff [topological_space α] (F : realizer α) {s : set α} :
is_open s ↔ ∀ a ∈ s, ∃ b, a ∈ F.F b ∧ F.F b ⊆ s :=
is_open_iff_mem_nhds.trans $ ball_congr $ λ a h, F.mem_nhds
theorem is_closed_iff [topological_space α] (F : realizer α) {s : set α} :
is_closed s ↔ ∀ a, (∀ b, a ∈ F.F b → ∃ z, z ∈ F.F b ∩ s) → a ∈ s :=
is_open_compl_iff.symm.trans $ F.is_open_iff.trans $ forall_congr $ λ a,
show (a ∉ s → (∃ (b : F.σ), a ∈ F.F b ∧ ∀ z ∈ F.F b, z ∉ s)) ↔ _,
by haveI := classical.prop_decidable; rw [not_imp_comm];
simp [not_exists, not_and, not_forall, and_comm]
theorem mem_interior_iff [topological_space α] (F : realizer α) {s : set α} {a : α} :
a ∈ interior s ↔ ∃ b, a ∈ F.F b ∧ F.F b ⊆ s :=
mem_interior_iff_mem_nhds.trans F.mem_nhds
protected theorem is_open [topological_space α] (F : realizer α) (s : F.σ) : is_open (F.F s) :=
is_open_iff_nhds.2 $ λ a m, by simpa using F.mem_nhds.2 ⟨s, m, subset.refl _⟩
theorem ext' [T : topological_space α] {σ : Type*} {F : ctop α σ}
(H : ∀ a s, s ∈ 𝓝 a ↔ ∃ b, a ∈ F b ∧ F b ⊆ s) :
F.to_topsp = T :=
begin
refine eq_of_nhds_eq_nhds (λ x, _),
ext s,
rw [mem_nhds_to_topsp, H]
end
theorem ext [T : topological_space α] {σ : Type*} {F : ctop α σ}
(H₁ : ∀ a, is_open (F a))
(H₂ : ∀ a s, s ∈ 𝓝 a → ∃ b, a ∈ F b ∧ F b ⊆ s) :
F.to_topsp = T :=
ext' $ λ a s, ⟨H₂ a s, λ ⟨b, h₁, h₂⟩, mem_nhds_sets_iff.2 ⟨_, h₂, H₁ _, h₁⟩⟩
variable [topological_space α]
protected def id : realizer α := ⟨{x:set α // is_open x},
{ f := subtype.val,
top := λ _, ⟨univ, is_open_univ⟩,
top_mem := mem_univ,
inter := λ ⟨x, h₁⟩ ⟨y, h₂⟩ a h₃, ⟨_, is_open_inter h₁ h₂⟩,
inter_mem := λ ⟨x, h₁⟩ ⟨y, h₂⟩ a, id,
inter_sub := λ ⟨x, h₁⟩ ⟨y, h₂⟩ a h₃, subset.refl _ },
ext subtype.property $ λ x s h,
let ⟨t, h, o, m⟩ := mem_nhds_sets_iff.1 h in ⟨⟨t, o⟩, m, h⟩⟩
def of_equiv (F : realizer α) (E : F.σ ≃ τ) : realizer α :=
⟨τ, F.F.of_equiv E, ext' (λ a s, F.mem_nhds.trans $
⟨λ ⟨s, h⟩, ⟨E s, by simpa using h⟩, λ ⟨t, h⟩, ⟨E.symm t, by simpa using h⟩⟩)⟩
@[simp] theorem of_equiv_σ (F : realizer α) (E : F.σ ≃ τ) : (F.of_equiv E).σ = τ := rfl
@[simp] theorem of_equiv_F (F : realizer α) (E : F.σ ≃ τ) (s : τ) :
(F.of_equiv E).F s = F.F (E.symm s) := by delta of_equiv; simp
protected def nhds (F : realizer α) (a : α) : (𝓝 a).realizer :=
⟨{s : F.σ // a ∈ F.F s},
{ f := λ s, F.F s.1,
pt := ⟨_, F.F.top_mem a⟩,
inf := λ ⟨x, h₁⟩ ⟨y, h₂⟩, ⟨_, F.F.inter_mem x y a ⟨h₁, h₂⟩⟩,
inf_le_left := λ ⟨x, h₁⟩ ⟨y, h₂⟩ z h, (F.F.inter_sub x y a ⟨h₁, h₂⟩ h).1,
inf_le_right := λ ⟨x, h₁⟩ ⟨y, h₂⟩ z h, (F.F.inter_sub x y a ⟨h₁, h₂⟩ h).2 },
filter_eq $ set.ext $ λ x,
⟨λ ⟨⟨s, as⟩, h⟩, mem_nhds_sets_iff.2 ⟨_, h, F.is_open _, as⟩,
λ h, let ⟨s, h, as⟩ := F.mem_nhds.1 h in ⟨⟨s, h⟩, as⟩⟩⟩
@[simp] theorem nhds_σ (m : α → β) (F : realizer α) (a : α) :
(F.nhds a).σ = {s : F.σ // a ∈ F.F s} := rfl
@[simp] theorem nhds_F (m : α → β) (F : realizer α) (a : α) (s) :
(F.nhds a).F s = F.F s.1 := rfl
theorem tendsto_nhds_iff {m : β → α} {f : filter β} (F : f.realizer) (R : realizer α) {a : α} :
tendsto m f (𝓝 a) ↔ ∀ t, a ∈ R.F t → ∃ s, ∀ x ∈ F.F s, m x ∈ R.F t :=
(F.tendsto_iff _ (R.nhds a)).trans subtype.forall
end ctop.realizer
structure locally_finite.realizer [topological_space α] (F : realizer α) (f : β → set α) :=
(bas : ∀ a, {s // a ∈ F.F s})
(sets : ∀ x:α, fintype {i | (f i ∩ F.F (bas x)).nonempty})
theorem locally_finite.realizer.to_locally_finite [topological_space α]
{F : realizer α} {f : β → set α} (R : locally_finite.realizer F f) :
locally_finite f :=
λ a, ⟨_, F.mem_nhds.2
⟨(R.bas a).1, (R.bas a).2, subset.refl _⟩, ⟨R.sets a⟩⟩
theorem locally_finite_iff_exists_realizer [topological_space α]
(F : realizer α) {f : β → set α} : locally_finite f ↔ nonempty (locally_finite.realizer F f) :=
⟨λ h, let ⟨g, h₁⟩ := classical.axiom_of_choice h,
⟨g₂, h₂⟩ := classical.axiom_of_choice (λ x,
show ∃ (b : F.σ), x ∈ (F.F) b ∧ (F.F) b ⊆ g x, from
let ⟨h, h'⟩ := h₁ x in F.mem_nhds.1 h) in
⟨⟨λ x, ⟨g₂ x, (h₂ x).1⟩, λ x, finite.fintype $
let ⟨h, h'⟩ := h₁ x in h'.subset $ λ i hi,
hi.mono (inter_subset_inter_right _ (h₂ x).2)⟩⟩,
λ ⟨R⟩, R.to_locally_finite⟩
def compact.realizer [topological_space α] (R : realizer α) (s : set α) :=
∀ {f : filter α} (F : f.realizer) (x : F.σ), f ≠ ⊥ →
F.F x ⊆ s → {a // a∈s ∧ 𝓝 a ⊓ f ≠ ⊥}
|
d32c0823f53951772e92df5285a719fc7f0a21aa | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/lie/base_change.lean | 2403b345978e8f85abadcd157dcf4f5603ec8afa | [
"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 | 5,843 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.algebra.restrict_scalars
import algebra.lie.tensor_product
/-!
# Extension and restriction of scalars for Lie algebras
Lie algebras have a well-behaved theory of extension and restriction of scalars.
## Main definitions
* `lie_algebra.extend_scalars.lie_algebra`
* `lie_algebra.restrict_scalars.lie_algebra`
## Tags
lie ring, lie algebra, extension of scalars, restriction of scalars, base change
-/
universes u v w w₁ w₂ w₃
open_locale tensor_product
variables (R : Type u) (A : Type w) (L : Type v)
namespace lie_algebra
namespace extend_scalars
variables [comm_ring R] [comm_ring A] [algebra R A] [lie_ring L] [lie_algebra R L]
/-- The Lie bracket on the extension of a Lie algebra `L` over `R` by an algebra `A` over `R`.
In fact this bracket is fully `A`-bilinear but without a significant upgrade to our mixed-scalar
support in the tensor product library, it is far easier to bootstrap like this, starting with the
definition below. -/
private def bracket' : (A ⊗[R] L) →ₗ[R] (A ⊗[R] L) →ₗ[R] A ⊗[R] L :=
tensor_product.curry $
(tensor_product.map (algebra.lmul' R) (lie_module.to_module_hom R L L : L ⊗[R] L →ₗ[R] L))
∘ₗ ↑(tensor_product.tensor_tensor_tensor_comm R A L A L)
@[simp] private lemma bracket'_tmul (s t : A) (x y : L) :
bracket' R A L (s ⊗ₜ[R] x) (t ⊗ₜ[R] y) = (s*t) ⊗ₜ ⁅x, y⁆ :=
by simp [bracket']
instance : has_bracket (A ⊗[R] L) (A ⊗[R] L) := { bracket := λ x y, bracket' R A L x y, }
private lemma bracket_def (x y : A ⊗[R] L) : ⁅x, y⁆ = bracket' R A L x y := rfl
@[simp] lemma bracket_tmul (s t : A) (x y : L) : ⁅s ⊗ₜ[R] x, t ⊗ₜ[R] y⁆ = (s*t) ⊗ₜ ⁅x, y⁆ :=
by rw [bracket_def, bracket'_tmul]
private lemma bracket_lie_self (x : A ⊗[R] L) : ⁅x, x⁆ = 0 :=
begin
simp only [bracket_def],
apply x.induction_on,
{ simp only [linear_map.map_zero, eq_self_iff_true, linear_map.zero_apply], },
{ intros a l,
simp only [bracket'_tmul, tensor_product.tmul_zero, eq_self_iff_true, lie_self], },
{ intros z₁ z₂ h₁ h₂,
suffices : bracket' R A L z₁ z₂ + bracket' R A L z₂ z₁ = 0,
{ rw [linear_map.map_add, linear_map.map_add, linear_map.add_apply, linear_map.add_apply,
h₁, h₂, zero_add, add_zero, add_comm, this], },
apply z₁.induction_on,
{ simp only [linear_map.map_zero, add_zero, linear_map.zero_apply], },
{ intros a₁ l₁, apply z₂.induction_on,
{ simp only [linear_map.map_zero, add_zero, linear_map.zero_apply], },
{ intros a₂ l₂,
simp only [← lie_skew l₂ l₁, mul_comm a₁ a₂, tensor_product.tmul_neg, bracket'_tmul,
add_right_neg], },
{ intros y₁ y₂ hy₁ hy₂,
simp only [hy₁, hy₂, add_add_add_comm, add_zero, linear_map.add_apply,
linear_map.map_add], }, },
{ intros y₁ y₂ hy₁ hy₂,
simp only [add_add_add_comm, hy₁, hy₂, add_zero, linear_map.add_apply,
linear_map.map_add], }, },
end
private lemma bracket_leibniz_lie (x y z : A ⊗[R] L) : ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆ :=
begin
simp only [bracket_def],
apply x.induction_on,
{ simp only [linear_map.map_zero, add_zero, eq_self_iff_true, linear_map.zero_apply], },
{ intros a₁ l₁,
apply y.induction_on,
{ simp only [linear_map.map_zero, add_zero, eq_self_iff_true, linear_map.zero_apply], },
{ intros a₂ l₂,
apply z.induction_on,
{ simp only [linear_map.map_zero, add_zero], },
{ intros a₃ l₃, simp only [bracket'_tmul],
rw [mul_left_comm a₂ a₁ a₃, mul_assoc, leibniz_lie, tensor_product.tmul_add], },
{ intros u₁ u₂ h₁ h₂,
simp only [add_add_add_comm, h₁, h₂, linear_map.map_add], }, },
{ intros u₁ u₂ h₁ h₂,
simp only [add_add_add_comm, h₁, h₂, linear_map.add_apply, linear_map.map_add], }, },
{ intros u₁ u₂ h₁ h₂,
simp only [add_add_add_comm, h₁, h₂, linear_map.add_apply, linear_map.map_add], },
end
instance : lie_ring (A ⊗[R] L) :=
{ add_lie := λ x y z, by simp only [bracket_def, linear_map.add_apply, linear_map.map_add],
lie_add := λ x y z, by simp only [bracket_def, linear_map.map_add],
lie_self := bracket_lie_self R A L,
leibniz_lie := bracket_leibniz_lie R A L, }
private lemma bracket_lie_smul (a : A) (x y : A ⊗[R] L) : ⁅x, a • y⁆ = a • ⁅x, y⁆ :=
begin
apply x.induction_on,
{ simp only [zero_lie, smul_zero], },
{ intros a₁ l₁, apply y.induction_on,
{ simp only [lie_zero, smul_zero], },
{ intros a₂ l₂,
simp only [bracket_def, bracket', tensor_product.smul_tmul', mul_left_comm a₁ a a₂,
tensor_product.curry_apply, algebra.lmul'_apply, algebra.id.smul_eq_mul, function.comp_app,
linear_equiv.coe_coe, linear_map.coe_comp, tensor_product.map_tmul,
tensor_product.tensor_tensor_tensor_comm_tmul], },
{ intros z₁ z₂ h₁ h₂,
simp only [h₁, h₂, smul_add, lie_add], }, },
{ intros z₁ z₂ h₁ h₂,
simp only [h₁, h₂, smul_add, add_lie], },
end
instance lie_algebra : lie_algebra A (A ⊗[R] L) :=
{ lie_smul := bracket_lie_smul R A L, }
end extend_scalars
namespace restrict_scalars
open restrict_scalars
variables [h : lie_ring L]
include h
instance : lie_ring (restrict_scalars R A L) := h
variables [comm_ring A] [lie_algebra A L]
instance lie_algebra [comm_ring R] [algebra R A] : lie_algebra R (restrict_scalars R A L) :=
{ lie_smul := λ t x y, (lie_smul (algebra_map R A t)
(restrict_scalars.add_equiv R A L x) (restrict_scalars.add_equiv R A L y) : _) }
end restrict_scalars
end lie_algebra
|
3b447128f603a6922e0d9c70814aba007f06a0c0 | 2de8c1580f92bb6c28b60135f589fe9d0513faba | /src/finset.lean | 9591374db04f5003da63476b27eda984d0b27fe0 | [] | no_license | FCL-lean/verification | 44a52e40ab78b18654b8d61bb55c2c912a40d2f4 | be02c698c0ca78b18762e3fe7749cdc72a55d197 | refs/heads/master | 1,585,960,207,309 | 1,560,259,990,000 | 1,560,259,990,000 | 155,650,137 | 0 | 0 | null | 1,541,039,704,000 | 1,541,038,972,000 | Lean | UTF-8 | Lean | false | false | 2,878 | lean | import data.finset
namespace finset
variables {α : Type*}
section
@[simp] lemma subset_to_set (s₁ s₂ : finset α) : s₁.to_set ⊆ s₂.to_set ↔ s₁ ⊆ s₂ := by finish
@[simp] lemma mem_to_set (s : finset α) : ∀ a, a ∈ s.to_set ↔ a ∈ s := by finish
lemma insert_to_set [decidable_eq α] (s : finset α) (a : α) : (insert a s).to_set = insert a (s.to_set) :=
by ext x; finish
lemma ne_of_mem_and_not_mem {s : finset α} {a b : α} (ha : a ∈ s) (hb : b ∉ s) : a ≠ b :=
λ h, hb (by rwa h at ha)
lemma not_mem_subset_of_not_mem {s₁ s₂ : finset α} {a : α} (hs : s₁ ⊆ s₂) (ha : a ∉ s₂) : a ∉ s₁ := λ h, ha (hs h)
lemma subset_of_union_left [decidable_eq α] {s₁ s₂} (s₃ : finset α) (hs : s₁ ⊆ s₂) :
s₁ ⊆ s₂ ∪ s₃ := subset.trans hs (subset_union_left s₂ s₃)
lemma subset_of_union_right [decidable_eq α] {s₁ s₃} (s₂ : finset α) (hs : s₁ ⊆ s₃) :
s₁ ⊆ s₂ ∪ s₃ := subset.trans hs (subset_union_right s₂ s₃)
lemma union_subset' [decidable_eq α] {s₁ s₂ s₃ s₄ : finset α} (h₁ : s₁ ⊆ s₂) (h₂ : s₃ ⊆ s₄) :
s₁ ∪ s₃ ⊆ s₂ ∪ s₄ := union_subset (subset_of_union_left s₄ h₁) (subset_of_union_right s₂ h₂)
lemma union_subset'_symm [decidable_eq α] {s₁ s₂ s₃ s₄ : finset α} (h₁ : s₁ ⊆ s₄) (h₂ : s₃ ⊆ s₂) :
s₁ ∪ s₃ ⊆ s₂ ∪ s₄ := union_subset (subset_of_union_right s₂ h₁) (subset_of_union_left s₄ h₂)
end
lemma mem_fold_union {β : Type*} [decidable_eq α] [decidable_eq β] {s : finset α} {a : β} {f : α → finset β} :
{a} ⊆ s.fold (∪) ∅ f → ∃ b ∈ s, {a} ⊆ f b :=
begin
apply finset.induction_on s, finish [subset_empty],
intros a' s' has' ih ha,
simp [subset_iff] at ha ih ⊢,
cases ha, apply exists.intro a', simp [ha],
cases ih ha, apply exists.intro w, finish,
end
section sort
variables [decidable_linear_order α]
@[simp] lemma sort_eq_nil (s : finset α) : s.sort (≥) = [] ↔ s = ∅ :=
⟨λ h, begin
have h' : ↑(sort (≥) s) = (∅ : multiset α),
simp [h],
simpa using h',
end,
λ h, by finish⟩
lemma sort_ne_nil (s : finset α) : (s.sort (≥)) ≠ [] ↔ s ≠ ∅ := by simp
lemma sort_singleton [decidable_eq α] {s : finset α} {a} : (s.sort (≥)) = [a] ↔ s = {a} := ⟨λ hs, begin
ext a',
have h := @mem_sort _ (≥) _ _ _ _ s,
split; intro ha',
rwa [←@h a', hs] at ha',
simpa [(@h a').symm, hs] using ha',
end, λ h, begin finish [h], end⟩
lemma sort_hd_rel [inhabited α] [decidable_eq α] {s : finset α} : ∀ a ∈ (s.sort (≥)).tail, (s.sort (≥)).head ≥ a := begin
have h := sort_sorted (≥) s,
cases (s.sort (≥)); simp at h ⊢, exact h.left,
end
end sort
end finset |
0ea71ff03168dd3f0ee776db9f48b169fdb812b4 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/category_theory/discrete_category.lean | c846a5adf3b71de4ff05731c550c1e9f5ec46bc4 | [
"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 | 3,197 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import data.ulift
import data.fintype.basic
import category_theory.opposites category_theory.equivalence
namespace category_theory
universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
def discrete (α : Type u₁) := α
instance discrete_category (α : Type u₁) : small_category (discrete α) :=
{ hom := λ X Y, ulift (plift (X = Y)),
id := λ X, ulift.up (plift.up rfl),
comp := λ X Y Z g f, by { rcases f with ⟨⟨rfl⟩⟩, exact g } }
namespace discrete
variables {α : Type u₁}
instance [inhabited α] : inhabited (discrete α) :=
by unfold discrete; apply_instance
instance [fintype α] : fintype (discrete α) :=
by { dsimp [discrete], apply_instance }
instance fintype_fun [decidable_eq α] (X Y : discrete α) : fintype (X ⟶ Y) :=
by { apply ulift.fintype }
@[simp] lemma id_def (X : discrete α) : ulift.up (plift.up (eq.refl X)) = 𝟙 X := rfl
end discrete
variables {C : Type u₂} [𝒞 : category.{v₂} C]
include 𝒞
namespace functor
def of_function {I : Type u₁} (F : I → C) : (discrete I) ⥤ C :=
{ obj := F,
map := λ X Y f, begin cases f, cases f, cases f, exact 𝟙 (F X) end }
@[simp] lemma of_function_obj {I : Type u₁} (F : I → C) (i : I) : (of_function F).obj i = F i := rfl
lemma of_function_map {I : Type u₁} (F : I → C) {i : discrete I} (f : i ⟶ i) :
(of_function F).map f = 𝟙 (F i) :=
by { cases f, cases f, cases f, refl }
end functor
namespace nat_trans
def of_homs {I : Type u₁} {F G : discrete I ⥤ C}
(f : Π i : discrete I, F.obj i ⟶ G.obj i) : F ⟶ G :=
{ app := f }
@[simp] lemma of_homs_app {I : Type u₁} {F G : discrete I ⥤ C} (f : Π i : discrete I, F.obj i ⟶ G.obj i) (i) :
(of_homs f).app i = f i := rfl
def of_function {I : Type u₁} {F G : I → C} (f : Π i : I, F i ⟶ G i) :
(functor.of_function F) ⟶ (functor.of_function G) :=
of_homs f
@[simp] lemma of_function_app {I : Type u₁} {F G : I → C} (f : Π i : I, F i ⟶ G i) (i : I) :
(of_function f).app i = f i := rfl
end nat_trans
namespace nat_iso
def of_isos {I : Type u₁} {F G : discrete I ⥤ C}
(f : Π i : discrete I, F.obj i ≅ G.obj i) : F ≅ G :=
of_components f (by tidy)
end nat_iso
namespace discrete
variables {J : Type v₁}
omit 𝒞
def lift {α : Type u₁} {β : Type u₂} (f : α → β) : (discrete α) ⥤ (discrete β) :=
functor.of_function f
open opposite
protected def opposite (α : Type u₁) : (discrete α)ᵒᵖ ≌ discrete α :=
let F : discrete α ⥤ (discrete α)ᵒᵖ := functor.of_function (λ x, op x) in
begin
refine equivalence.mk (functor.left_op F) F _ (nat_iso.of_isos $ λ X, by simp [F]),
refine nat_iso.of_components (λ X, by simp [F]) _,
tidy
end
include 𝒞
@[simp] lemma functor_map_id
(F : discrete J ⥤ C) {j : discrete J} (f : j ⟶ j) : F.map f = 𝟙 (F.obj j) :=
begin
have h : f = 𝟙 j, { cases f, cases f, ext, },
rw h,
simp,
end
end discrete
end category_theory
|
6c4e4ca9670fae4b6d0503513d52917865245b09 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/data/list/alist.lean | cd6b872431e8c604223822368b1e9c5dd049ff34 | [
"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 | 10,649 | lean | /-
Copyright (c) 2018 Sean Leather. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sean Leather, Mario Carneiro
Association lists.
-/
import data.list.sigma
universes u v w
open list
variables {α : Type u} {β : α → Type v}
/-- `alist β` is a key-value map stored as a `list` (i.e. a linked list).
It is a wrapper around certain `list` functions with the added constraint
that the list have unique keys. -/
structure alist (β : α → Type v) : Type (max u v) :=
(entries : list (sigma β))
(nodupkeys : entries.nodupkeys)
def list.to_alist [decidable_eq α] {β : α → Type v} (l : list (sigma β)) : alist β :=
{ entries := _,
nodupkeys := nodupkeys_erase_dupkeys l }
namespace alist
@[ext] theorem ext : ∀ {s t : alist β}, s.entries = t.entries → s = t
| ⟨l₁, h₁⟩ ⟨l₂, h₂⟩ H := by congr'
/- keys -/
/-- The list of keys of an association list. -/
def keys (s : alist β) : list α := s.entries.keys
theorem keys_nodup (s : alist β) : s.keys.nodup := s.nodupkeys
/- mem -/
/-- The predicate `a ∈ s` means that `s` has a value associated to the key `a`. -/
instance : has_mem α (alist β) := ⟨λ a s, a ∈ s.keys⟩
theorem mem_keys {a : α} {s : alist β} : a ∈ s ↔ a ∈ s.keys := iff.rfl
theorem mem_of_perm {a : α} {s₁ s₂ : alist β} (p : s₁.entries ~ s₂.entries) : a ∈ s₁ ↔ a ∈ s₂ :=
mem_of_perm $ perm_map sigma.fst p
/- empty -/
/-- The empty association list. -/
instance : has_emptyc (alist β) := ⟨⟨[], nodupkeys_nil⟩⟩
theorem not_mem_empty (a : α) : a ∉ (∅ : alist β) :=
not_mem_nil a
@[simp] theorem empty_entries : (∅ : alist β).entries = [] := rfl
@[simp] theorem keys_empty : (∅ : alist β).keys = [] := rfl
/- singleton -/
/-- The singleton association list. -/
def singleton (a : α) (b : β a) : alist β :=
⟨[⟨a, b⟩], nodupkeys_singleton _⟩
@[simp] theorem singleton_entries (a : α) (b : β a) :
(singleton a b).entries = [sigma.mk a b] := rfl
@[simp] theorem keys_singleton (a : α) (b : β a) : (singleton a b).keys = [a] := rfl
variables [decidable_eq α]
/- lookup -/
/-- Look up the value associated to a key in an association list. -/
def lookup (a : α) (s : alist β) : option (β a) :=
s.entries.lookup a
@[simp] theorem lookup_empty (a) : lookup a (∅ : alist β) = none :=
rfl
theorem lookup_is_some {a : α} {s : alist β} :
(s.lookup a).is_some ↔ a ∈ s := lookup_is_some
theorem lookup_eq_none {a : α} {s : alist β} :
lookup a s = none ↔ a ∉ s :=
lookup_eq_none
theorem perm_lookup {a : α} {s₁ s₂ : alist β} (p : s₁.entries ~ s₂.entries) :
s₁.lookup a = s₂.lookup a :=
perm_lookup _ s₁.nodupkeys s₂.nodupkeys p
instance (a : α) (s : alist β) : decidable (a ∈ s) :=
decidable_of_iff _ lookup_is_some
/- replace -/
/-- Replace a key with a given value in an association list.
If the key is not present it does nothing. -/
def replace (a : α) (b : β a) (s : alist β) : alist β :=
⟨kreplace a b s.entries, (kreplace_nodupkeys a b).2 s.nodupkeys⟩
@[simp] theorem keys_replace (a : α) (b : β a) (s : alist β) :
(replace a b s).keys = s.keys :=
keys_kreplace _ _ _
@[simp] theorem mem_replace {a a' : α} {b : β a} {s : alist β} :
a' ∈ replace a b s ↔ a' ∈ s :=
by rw [mem_keys, keys_replace, ←mem_keys]
theorem perm_replace {a : α} {b : β a} {s₁ s₂ : alist β} :
s₁.entries ~ s₂.entries → (replace a b s₁).entries ~ (replace a b s₂).entries :=
perm_kreplace s₁.nodupkeys
/-- Fold a function over the key-value pairs in the map. -/
def foldl {δ : Type w} (f : δ → Π a, β a → δ) (d : δ) (m : alist β) : δ :=
m.entries.foldl (λ r a, f r a.1 a.2) d
/- erase -/
/-- Erase a key from the map. If the key is not present it does nothing. -/
def erase (a : α) (s : alist β) : alist β :=
⟨kerase a s.entries, kerase_nodupkeys _ s.nodupkeys⟩
@[simp] theorem keys_erase (a : α) (s : alist β) :
(erase a s).keys = s.keys.erase a :=
by simp only [erase, keys, keys_kerase]
@[simp] theorem mem_erase {a a' : α} {s : alist β} : a' ∈ erase a s ↔ a' ≠ a ∧ a' ∈ s :=
by rw [mem_keys, keys_erase, mem_erase_iff_of_nodup s.keys_nodup, ←mem_keys]
theorem perm_erase {a : α} {s₁ s₂ : alist β} :
s₁.entries ~ s₂.entries → (erase a s₁).entries ~ (erase a s₂).entries :=
perm_kerase s₁.nodupkeys
@[simp] theorem lookup_erase (a) (s : alist β) : lookup a (erase a s) = none :=
lookup_kerase a s.nodupkeys
@[simp] theorem lookup_erase_ne {a a'} {s : alist β} (h : a ≠ a') :
lookup a (erase a' s) = lookup a s :=
lookup_kerase_ne h
@[simp] theorem erase_erase (a a' : α) (s : alist β) :
(s.erase a).erase a' = (s.erase a').erase a :=
ext $ kerase_kerase
/- insert -/
/-- Insert a key-value pair into an association list and erase any existing pair
with the same key. -/
def insert (a : α) (b : β a) (s : alist β) : alist β :=
⟨kinsert a b s.entries, kinsert_nodupkeys a b s.nodupkeys⟩
@[simp] theorem insert_entries {a} {b : β a} {s : alist β} :
(insert a b s).entries = sigma.mk a b :: kerase a s.entries :=
rfl
theorem insert_entries_of_neg {a} {b : β a} {s : alist β} (h : a ∉ s) :
(insert a b s).entries = ⟨a, b⟩ :: s.entries :=
by rw [insert_entries, kerase_of_not_mem_keys h]
@[simp] theorem mem_insert {a a'} {b' : β a'} (s : alist β) :
a ∈ insert a' b' s ↔ a = a' ∨ a ∈ s :=
mem_keys_kinsert
@[simp] theorem keys_insert {a} {b : β a} (s : alist β) :
(insert a b s).keys = a :: s.keys.erase a :=
by simp [insert, keys, keys_kerase]
theorem perm_insert {a} {b : β a} {s₁ s₂ : alist β} (p : s₁.entries ~ s₂.entries) :
(insert a b s₁).entries ~ (insert a b s₂).entries :=
by simp only [insert_entries]; exact perm_kinsert s₁.nodupkeys p
@[simp] theorem lookup_insert {a} {b : β a} (s : alist β) : lookup a (insert a b s) = some b :=
by simp only [lookup, insert, lookup_kinsert]
@[simp] theorem lookup_insert_ne {a a'} {b' : β a'} {s : alist β} (h : a ≠ a') :
lookup a (insert a' b' s) = lookup a s :=
lookup_kinsert_ne h
@[simp] theorem lookup_to_alist {a} (s : list (sigma β)) : lookup a s.to_alist = s.lookup a :=
by rw [list.to_alist,lookup,lookup_erase_dupkeys]
@[simp] theorem insert_insert {a} {b b' : β a} (s : alist β) : (s.insert a b).insert a b' = s.insert a b' :=
by ext : 1; simp only [alist.insert_entries, list.kerase_cons_eq];
constructor_matching* [_ ∧ _]; refl
@[simp] theorem insert_insert_of_ne {a a'} {b : β a} {b' : β a'} (s : alist β) (h : a ≠ a') :
((s.insert a b).insert a' b').entries ~ ((s.insert a' b').insert a b).entries :=
by simp only [insert_entries]; rw [kerase_cons_ne,kerase_cons_ne,kerase_comm];
[apply perm.swap, exact h, exact h.symm]
@[simp] lemma insert_singleton_eq {a : α} {b b' : β a} : insert a b (singleton a b') = singleton a b :=
ext (by simp only [alist.insert_entries, list.kerase_cons_eq, and_self, alist.singleton_entries, heq_iff_eq, eq_self_iff_true])
@[simp] theorem entries_to_alist (xs : list (sigma β)) : (list.to_alist xs).entries = erase_dupkeys xs := rfl
theorem to_alist_cons (a : α) (b : β a) (xs : list (sigma β)) : list.to_alist (⟨a,b⟩ :: xs) = insert a b xs.to_alist := rfl
/- extract -/
/-- Erase a key from the map, and return the corresponding value, if found. -/
def extract (a : α) (s : alist β) : option (β a) × alist β :=
have (kextract a s.entries).2.nodupkeys,
by rw [kextract_eq_lookup_kerase]; exact kerase_nodupkeys _ s.nodupkeys,
match kextract a s.entries, this with
| (b, l), h := (b, ⟨l, h⟩)
end
@[simp] theorem extract_eq_lookup_erase (a : α) (s : alist β) :
extract a s = (lookup a s, erase a s) :=
by simp [extract]; split; refl
/- union -/
/-- `s₁ ∪ s₂` is the key-based union of two association lists. It is
left-biased: if there exists an `a ∈ s₁`, `lookup a (s₁ ∪ s₂) = lookup a s₁`.
-/
def union (s₁ s₂ : alist β) : alist β :=
⟨kunion s₁.entries s₂.entries, kunion_nodupkeys s₁.nodupkeys s₂.nodupkeys⟩
instance : has_union (alist β) := ⟨union⟩
@[simp] theorem union_entries {s₁ s₂ : alist β} :
(s₁ ∪ s₂).entries = kunion s₁.entries s₂.entries :=
rfl
@[simp] theorem empty_union {s : alist β} : (∅ : alist β) ∪ s = s :=
ext rfl
@[simp] theorem union_empty {s : alist β} : s ∪ (∅ : alist β) = s :=
ext $ by simp
@[simp] theorem mem_union {a} {s₁ s₂ : alist β} :
a ∈ s₁ ∪ s₂ ↔ a ∈ s₁ ∨ a ∈ s₂ :=
mem_keys_kunion
theorem perm_union {s₁ s₂ s₃ s₄ : alist β}
(p₁₂ : s₁.entries ~ s₂.entries) (p₃₄ : s₃.entries ~ s₄.entries) :
(s₁ ∪ s₃).entries ~ (s₂ ∪ s₄).entries :=
by simp [perm_kunion s₃.nodupkeys p₁₂ p₃₄]
theorem union_erase (a : α) (s₁ s₂ : alist β) : erase a (s₁ ∪ s₂) = erase a s₁ ∪ erase a s₂ :=
ext kunion_kerase.symm
@[simp] theorem lookup_union_left {a} {s₁ s₂ : alist β} :
a ∈ s₁ → lookup a (s₁ ∪ s₂) = lookup a s₁ :=
lookup_kunion_left
@[simp] theorem lookup_union_right {a} {s₁ s₂ : alist β} :
a ∉ s₁ → lookup a (s₁ ∪ s₂) = lookup a s₂ :=
lookup_kunion_right
@[simp] theorem mem_lookup_union {a} {b : β a} {s₁ s₂ : alist β} :
b ∈ lookup a (s₁ ∪ s₂) ↔ b ∈ lookup a s₁ ∨ a ∉ s₁ ∧ b ∈ lookup a s₂ :=
mem_lookup_kunion
theorem mem_lookup_union_middle {a} {b : β a} {s₁ s₂ s₃ : alist β} :
b ∈ lookup a (s₁ ∪ s₃) → a ∉ s₂ → b ∈ lookup a (s₁ ∪ s₂ ∪ s₃) :=
mem_lookup_kunion_middle
theorem insert_union {a} {b : β a} {s₁ s₂ : alist β} :
insert a b (s₁ ∪ s₂) = insert a b s₁ ∪ s₂ :=
by ext; simp
theorem union_assoc {s₁ s₂ s₃ : alist β} : ((s₁ ∪ s₂) ∪ s₃).entries ~ (s₁ ∪ (s₂ ∪ s₃)).entries :=
lookup_ext (alist.nodupkeys _) (alist.nodupkeys _)
(by simp [decidable.not_or_iff_and_not,or_assoc,and_or_distrib_left,and_assoc])
/- disjoint -/
def disjoint (s₁ s₂ : alist β) :=
∀ k ∈ s₁.keys, ¬ k ∈ s₂.keys
theorem union_comm_of_disjoint {s₁ s₂ : alist β} (h : disjoint s₁ s₂) : (s₁ ∪ s₂).entries ~ (s₂ ∪ s₁).entries :=
lookup_ext (alist.nodupkeys _) (alist.nodupkeys _)
(begin
intros, simp,
split; intro h',
cases h',
{ right, refine ⟨_,h'⟩,
apply h, rw [keys,← list.lookup_is_some,h'], exact rfl },
{ left, rw h'.2 },
cases h',
{ right, refine ⟨_,h'⟩, intro h'',
apply h _ h'', rw [keys,← list.lookup_is_some,h'], exact rfl },
{ left, rw h'.2 },
end)
end alist
|
168b867cc6d5b10991c485bafcb758910f601626 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /stage0/src/Lean/Elab/BuiltinNotation.lean | 205a9a29efd37f57b2ad5cb871ebf3eed01b368b | [
"Apache-2.0"
] | permissive | banksonian/lean4 | 3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc | 78da6b3aa2840693eea354a41e89fc5b212a5011 | refs/heads/master | 1,673,703,624,165 | 1,605,123,551,000 | 1,605,123,551,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 16,165 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Init.Data.ToString
import Lean.Compiler.BorrowedAnnotation
import Lean.Meta.KAbstract
import Lean.Elab.Term
import Lean.Elab.Quotation
import Lean.Elab.SyntheticMVars
namespace Lean.Elab.Term
open Meta
@[builtinMacro Lean.Parser.Term.dollar] def expandDollar : Macro := fun stx =>
match_syntax stx with
| `($f $args* $ $a) => let args := args.push a; `($f $args*)
| `($f $ $a) => `($f $a)
| _ => Macro.throwUnsupported
@[builtinMacro Lean.Parser.Term.subtype] def expandSubtype : Macro := fun stx =>
match_syntax stx with
| `({ $x : $type // $p }) => `(Subtype (fun ($x:ident : $type) => $p))
| `({ $x // $p }) => `(Subtype (fun ($x:ident : _) => $p))
| _ => Macro.throwUnsupported
@[builtinTermElab anonymousCtor] def elabAnonymousCtor : TermElab := fun stx expectedType? =>
match_syntax stx with
| `(⟨$args*⟩) => do
tryPostponeIfNoneOrMVar expectedType?
match expectedType? with
| some expectedType =>
let expectedType ← whnf expectedType
matchConstInduct expectedType.getAppFn
(fun _ => throwError! "invalid constructor ⟨...⟩, expected type must be an inductive type {indentExpr expectedType}")
(fun ival us => do
match ival.ctors with
| [ctor] =>
let newStx ← `($(mkCIdentFrom stx ctor) $(args.getSepElems)*)
withMacroExpansion stx newStx $ elabTerm newStx expectedType?
| _ => throwError! "invalid constructor ⟨...⟩, expected type must be an inductive type with only one constructor {indentExpr expectedType}")
| none => throwError "invalid constructor ⟨...⟩, expected type must be known"
| _ => throwUnsupportedSyntax
@[builtinTermElab borrowed] def elabBorrowed : TermElab := fun stx expectedType? =>
match_syntax stx with
| `(@& $e) => return markBorrowed (← elabTerm e expectedType?)
| _ => throwUnsupportedSyntax
@[builtinMacro Lean.Parser.Term.show] def expandShow : Macro := fun stx =>
match_syntax stx with
| `(show $type from $val) => let thisId := mkIdentFrom stx `this; `(let! $thisId : $type := $val; $thisId)
| `(show $type by $tac:tacticSeq) => `(show $type from by $tac:tacticSeq)
| _ => Macro.throwUnsupported
@[builtinMacro Lean.Parser.Term.have] def expandHave : Macro := fun stx =>
let stx := stx.setArg 4 (mkNullNode #[mkAtomFrom stx ";"]) -- HACK
match_syntax stx with
| `(have $type from $val; $body) => let thisId := mkIdentFrom stx `this; `(let! $thisId : $type := $val; $body)
| `(have $type by $tac:tacticSeq; $body) => `(have $type from by $tac:tacticSeq; $body)
| `(have $type := $val; $body) => let thisId := mkIdentFrom stx `this; `(let! $thisId : $type := $val; $body)
| `(have $x : $type from $val; $body) => `(let! $x:ident : $type := $val; $body)
| `(have $x : $type by $tac:tacticSeq; $body) => `(have $x : $type from by $tac:tacticSeq; $body)
| `(have $x : $type := $val; $body) => `(let! $x:ident : $type := $val; $body)
| _ => Macro.throwUnsupported
@[builtinMacro Lean.Parser.Term.suffices] def expandSuffices : Macro := fun stx =>
let stx := stx.setArg 4 (mkNullNode #[mkAtomFrom stx ";"]) -- HACK
match_syntax stx with
| `(suffices $type from $val; $body) => `(have $type from $body; $val)
| `(suffices $type by $tac:tacticSeq; $body) => `(have $type from $body; by $tac:tacticSeq)
| `(suffices $x : $type from $val; $body) => `(have $x:ident : $type from $body; $val)
| `(suffices $x : $type by $tac:tacticSeq; $body) => `(have $x:ident : $type from $body; by $tac:tacticSeq)
| _ => Macro.throwUnsupported
private def elabParserMacroAux (prec : Syntax) (e : Syntax) : TermElabM Syntax := do
let (some declName) ← getDeclName?
| throwError "invalid `parser!` macro, it must be used in definitions"
match extractMacroScopes declName with
| { name := Name.str _ s _, scopes := scps, .. } =>
let kind := quote declName
let s := quote s
let p ← `(Lean.Parser.leadingNode $kind $prec $e)
if scps == [] then
-- TODO simplify the following quotation as soon as we have coercions
`(OrElse.orElse (Lean.Parser.mkAntiquot $s (some $kind)) $p)
else
-- if the parser decl is hidden by hygiene, it doesn't make sense to provide an antiquotation kind
`(OrElse.orElse (Lean.Parser.mkAntiquot $s none) $p)
| _ => throwError "invalid `parser!` macro, unexpected declaration name"
@[builtinTermElab «parser!»] def elabParserMacro : TermElab :=
adaptExpander fun stx => match_syntax stx with
| `(parser! $e) => elabParserMacroAux (quote Parser.maxPrec) e
| `(parser! : $prec $e) => elabParserMacroAux prec e
| _ => throwUnsupportedSyntax
private def elabTParserMacroAux (prec : Syntax) (e : Syntax) : TermElabM Syntax := do
let declName? ← getDeclName?
match declName? with
| some declName => let kind := quote declName; `(Lean.Parser.trailingNode $kind $prec $e)
| none => throwError "invalid `tparser!` macro, it must be used in definitions"
@[builtinTermElab «tparser!»] def elabTParserMacro : TermElab :=
adaptExpander fun stx => match_syntax stx with
| `(tparser! $e) => elabTParserMacroAux (quote Parser.maxPrec) e
| `(tparser! : $prec $e) => elabTParserMacroAux prec e
| _ => throwUnsupportedSyntax
private def mkNativeReflAuxDecl (type val : Expr) : TermElabM Name := do
let auxName ← mkAuxName `_nativeRefl
let decl := Declaration.defnDecl {
name := auxName, lparams := [], type := type, value := val,
hints := ReducibilityHints.abbrev,
isUnsafe := false }
addDecl decl
compileDecl decl
pure auxName
private def elabClosedTerm (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
let e ← elabTermAndSynthesize stx expectedType?
if e.hasMVar then
throwError! "invalid macro application, term contains metavariables{indentExpr e}"
if e.hasFVar then
throwError! "invalid macro application, term contains free variables{indentExpr e}"
pure e
@[builtinTermElab «nativeRefl»] def elabNativeRefl : TermElab := fun stx _ => do
let arg := stx[1]
let e ← elabClosedTerm arg none
let type ← inferType e
let type ← whnf type
unless type.isConstOf `Bool || type.isConstOf `Nat do
throwError! "invalid `nativeRefl!` macro application, term must have type `Nat` or `Bool`{indentExpr type}"
let auxDeclName ← mkNativeReflAuxDecl type e
let isBool := type.isConstOf `Bool
let reduceValFn := if isBool then `Lean.reduceBool else `Lean.reduceNat
let reduceThm := if isBool then `Lean.ofReduceBool else `Lean.ofReduceNat
let aux := Lean.mkConst auxDeclName
let reduceVal := mkApp (Lean.mkConst reduceValFn) aux
let val? ← liftMetaM $ Meta.reduceNative? reduceVal
match val? with
| none => throwError! "failed to reduce term at `nativeRefl!` macro application{e}"
| some val =>
let rflPrf ← mkEqRefl val
let r := mkApp3 (Lean.mkConst reduceThm) aux val rflPrf
let eq ← mkEq e val
mkExpectedTypeHint r eq
private def getPropToDecide (expectedType? : Option Expr) : TermElabM Expr := do
tryPostponeIfNoneOrMVar expectedType?
match expectedType? with
| none => throwError "invalid macro, expected type is not available"
| some expectedType =>
synthesizeSyntheticMVars
let expectedType ← instantiateMVars expectedType
if expectedType.hasFVar || expectedType.hasMVar then
throwError! "expected type must not contain free or meta variables{indentExpr expectedType}"
pure expectedType
@[builtinTermElab «nativeDecide»] def elabNativeDecide : TermElab := fun stx expectedType? => do
let p ← getPropToDecide expectedType?
let d ← mkDecide p
let auxDeclName ← mkNativeReflAuxDecl (Lean.mkConst `Bool) d
let rflPrf ← mkEqRefl (toExpr true)
let r := mkApp3 (Lean.mkConst `Lean.ofReduceBool) (Lean.mkConst auxDeclName) (toExpr true) rflPrf
mkExpectedTypeHint r p
@[builtinTermElab Lean.Parser.Term.decide] def elabDecide : TermElab := fun stx expectedType? => do
let p ← getPropToDecide expectedType?
let d ← mkDecide p
let d ← instantiateMVars d
let s := d.appArg! -- get instance from `d`
let rflPrf ← mkEqRefl (toExpr true)
pure $ mkApp3 (Lean.mkConst `ofDecideEqTrue) p s rflPrf
def expandInfix (f : Syntax) : Macro := fun stx => do
-- term `op` term
let a := stx[0]
let b := stx[2]
pure (Syntax.mkApp f #[a, b])
def expandInfixOp (op : Name) : Macro := fun stx =>
expandInfix (mkCIdentFrom stx[1] op) stx
def expandPrefixOp (op : Name) : Macro := fun stx => do
-- `op` term
let a := stx[1]
pure (Syntax.mkApp (mkCIdentFrom stx[0] op) #[a])
@[builtinMacro Lean.Parser.Term.not] def expandNot : Macro := expandPrefixOp `Not
@[builtinMacro Lean.Parser.Term.bnot] def expandBNot : Macro := expandPrefixOp `not
@[builtinMacro Lean.Parser.Term.uminus] def expandUMinus : Macro := expandPrefixOp `Neg.neg
@[builtinTermElab panic] def elabPanic : TermElab := fun stx expectedType? => do
let arg := stx[1]
let pos ← getRefPosition
let env ← getEnv
let stxNew ← match (← getDeclName?) with
| some declName => `(panicWithPosWithDecl $(quote (toString env.mainModule)) $(quote (toString declName)) $(quote pos.line) $(quote pos.column) $arg)
| none => `(panicWithPos $(quote (toString env.mainModule)) $(quote pos.line) $(quote pos.column) $arg)
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
@[builtinMacro Lean.Parser.Term.unreachable] def expandUnreachable : Macro := fun stx =>
`(panic! "unreachable code has been reached")
@[builtinMacro Lean.Parser.Term.assert] def expandAssert : Macro := fun stx =>
-- TODO: support for disabling runtime assertions
let cond := stx[1]
let body := stx[3]
match cond.reprint with
| some code => `(if $cond then $body else panic! ("assertion violation: " ++ $(quote code)))
| none => `(if $cond then $body else panic! ("assertion violation"))
@[builtinMacro Lean.Parser.Term.dbgTrace] def expandDbgTrace : Macro := fun stx =>
let arg := stx[1]
let body := stx[3]
if arg.getKind == interpolatedStrKind then
`(dbgTrace (s! $arg) fun _ => $body)
else
`(dbgTrace (toString $arg) fun _ => $body)
@[builtinMacro Lean.Parser.Term.«sorry»] def expandSorry : Macro := fun _ =>
`(sorryAx _ false)
@[builtinTermElab emptyC] def expandEmptyC : TermElab := fun stx expectedType? => do
let stxNew ← `(EmptyCollection.emptyCollection)
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
/-- Return syntax `Prod.mk elems[0] (Prod.mk elems[1] ... (Prod.mk elems[elems.size - 2] elems[elems.size - 1])))` -/
partial def mkPairs (elems : Array Syntax) : MacroM Syntax :=
let rec loop (i : Nat) (acc : Syntax) := do
if i > 0 then
let i := i - 1
let elem := elems[i]
let acc ← `(Prod.mk $elem $acc)
loop i acc
else
pure acc
loop (elems.size - 1) elems.back
private partial def hasCDot : Syntax → Bool
| Syntax.node k args =>
if k == `Lean.Parser.Term.paren then false
else if k == `Lean.Parser.Term.cdot then true
else args.any hasCDot
| _ => false
/--
Auxiliary function for expandind the `·` notation.
The extra state `Array Syntax` contains the new binder names.
If `stx` is a `·`, we create a fresh identifier, store in the
extra state, and return it. Otherwise, we just return `stx`. -/
private partial def expandCDot : Syntax → StateT (Array Syntax) MacroM Syntax
| stx@(Syntax.node k args) =>
if k == `Lean.Parser.Term.paren then pure stx
else if k == `Lean.Parser.Term.cdot then withFreshMacroScope do
let id ← `(a)
modify fun s => s.push id;
pure id
else do
let args ← args.mapM expandCDot
pure $ Syntax.node k args
| stx => pure stx
/--
Return `some` if succeeded expanding `·` notation occurring in
the given syntax. Otherwise, return `none`.
Examples:
- `· + 1` => `fun _a_1 => _a_1 + 1`
- `f · · b` => `fun _a_1 _a_2 => f _a_1 _a_2 b` -/
def expandCDot? (stx : Syntax) : MacroM (Option Syntax) := do
if hasCDot stx then
let (newStx, binders) ← (expandCDot stx).run #[];
`(fun $binders* => $newStx)
else
pure none
/--
Try to expand `·` notation, and if successful elaborate result.
This method is used to elaborate the Lean parentheses notation.
Recall that in Lean the `·` notation must be surrounded by parentheses.
We may change this is the future, but right now, here are valid examples
- `(· + 1)`
- `(f ⟨·, 1⟩ ·)`
- `(· + ·)`
- `(f · a b)` -/
private def elabCDot (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
match (← liftMacroM $ expandCDot? stx) with
| some stx' => withMacroExpansion stx stx' (elabTerm stx' expectedType?)
| none => elabTerm stx expectedType?
@[builtinTermElab paren] def elabParen : TermElab := fun stx expectedType? =>
match_syntax stx with
| `(()) => pure $ Lean.mkConst `Unit.unit
| `(($e : $type)) => do
let type ← withSynthesize (mayPostpone := true) $ elabType type
let e ← elabCDot e type
ensureHasType type e
| `(($e)) => elabCDot e expectedType?
| `(($e, $es*)) => do
let pairs ← liftMacroM $ mkPairs (#[e] ++ es.getEvenElems)
withMacroExpansion stx pairs (elabTerm pairs expectedType?)
| _ => throwError "unexpected parentheses notation"
@[builtinTermElab subst] def elabSubst : TermElab := fun stx expectedType? => do
let expectedType ← tryPostponeIfHasMVars expectedType? "invalid `▸` notation"
match_syntax stx with
| `($heq ▸ $h) => do
let mut heq ← elabTerm heq none
let heqType ← inferType heq
let heqType ← instantiateMVars heqType
match (← Meta.matchEq? heqType) with
| none => throwError! "invalid `▸` notation, argument{indentExpr heq}\nhas type{indentExpr heqType}\nequality expected"
| some (α, lhs, rhs) =>
let mut lhs := lhs
let mut rhs := rhs
let mkMotive (typeWithLooseBVar : Expr) :=
withLocalDeclD (← mkFreshUserName `x) α fun x => do
mkLambdaFVars #[x] $ typeWithLooseBVar.instantiate1 x
let mut expectedAbst ← kabstract expectedType rhs
unless expectedAbst.hasLooseBVars do
expectedAbst ← kabstract expectedType lhs
unless expectedAbst.hasLooseBVars do
throwError! "invalid `▸` notation, expected type{indentExpr expectedType}\ndoes contain equation left-hand-side nor right-hand-side{indentExpr heqType}"
heq ← mkEqSymm heq
(lhs, rhs) := (rhs, lhs)
let hExpectedType := expectedAbst.instantiate1 lhs
let h ← withRef h do
let h ← elabTerm h hExpectedType
try
ensureHasType hExpectedType h
catch ex =>
-- if `rhs` occurs in `hType`, we try to apply `heq` to `h` too
let hType ← inferType h
let hTypeAbst ← kabstract hType rhs
unless hTypeAbst.hasLooseBVars do
throw ex
let hTypeNew := hTypeAbst.instantiate1 lhs
unless (← isDefEq hExpectedType hTypeNew) do
throw ex
mkEqNDRec (← mkMotive hTypeAbst) h (← mkEqSymm heq)
mkEqNDRec (← mkMotive expectedAbst) h heq
| _ => throwUnsupportedSyntax
@[builtinTermElab stateRefT] def elabStateRefT : TermElab := fun stx _ => do
let σ ← elabType stx[1]
let mut m := stx[2]
if m.getKind == `Lean.Parser.Term.macroDollarArg then
m := m[1]
let m ← elabTerm m (← mkArrow (mkSort levelOne) (mkSort levelOne))
let ω ← mkFreshExprMVar (mkSort levelOne)
let stWorld ← mkAppM `STWorld #[ω, m]
mkInstMVar stWorld
mkAppM `StateRefT' #[ω, σ, m]
end Lean.Elab.Term
|
c966667d55b0d230b9ce89d8dd208e0e7b35e075 | 3dd1b66af77106badae6edb1c4dea91a146ead30 | /tests/lean/run/section1.lean | 9b009525bc4974797d6d81513847c25bc3258a7f | [
"Apache-2.0"
] | permissive | silky/lean | 79c20c15c93feef47bb659a2cc139b26f3614642 | df8b88dca2f8da1a422cb618cd476ef5be730546 | refs/heads/master | 1,610,737,587,697 | 1,406,574,534,000 | 1,406,574,534,000 | 22,362,176 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 232 | lean | import standard
using tactic
section
set_option pp.universes true
set_option pp.implicit true
parameter {A : Type}
parameters {a b : A}
parameter H : a = b
parameters H1 H2 : b = a
check H1
check H
check H2
end |
4e5364a72ed54d4645f476fac09a98878a2180ce | 0845ae2ca02071debcfd4ac24be871236c01784f | /library/init/lean/message.lean | 0ec37f6a6ef88324dbe583a0d4e36330583c4dff | [
"Apache-2.0"
] | permissive | GaloisInc/lean4 | 74c267eb0e900bfaa23df8de86039483ecbd60b7 | 228ddd5fdcd98dd4e9c009f425284e86917938aa | refs/heads/master | 1,643,131,356,301 | 1,562,715,572,000 | 1,562,715,572,000 | 192,390,898 | 0 | 0 | null | 1,560,792,750,000 | 1,560,792,749,000 | null | UTF-8 | Lean | false | false | 1,758 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich
Message Type used by the Lean frontend
-/
prelude
import init.data.tostring init.lean.position
namespace Lean
inductive MessageSeverity
| information | warning | error
-- TODO: structured messages
structure Message :=
(filename : String)
(pos : Position)
(endPos : Option Position := none)
(severity : MessageSeverity := MessageSeverity.error)
(caption : String := "")
(text : String)
namespace Message
protected def toString (msg : Message) : String :=
msg.filename ++ ":" ++ toString msg.pos.line ++ ":" ++ toString msg.pos.column ++ ": " ++
(match msg.severity with
| MessageSeverity.information => ""
| MessageSeverity.warning => "warning: "
| MessageSeverity.error => "error: ") ++
(if msg.caption = "" then "" else msg.caption ++ ":\n") ++
msg.text
instance : Inhabited Message :=
⟨{ filename := "", pos := ⟨0, 1⟩, text := ""}⟩
instance : HasToString Message :=
⟨Message.toString⟩
end Message
structure MessageLog :=
-- messages are stored in reverse for efficient append
(revList : List Message)
namespace MessageLog
def empty : MessageLog :=
⟨[]⟩
def add (msg : Message) (log : MessageLog) : MessageLog :=
⟨msg :: log.revList⟩
protected def append (l₁ l₂ : MessageLog) : MessageLog :=
⟨l₂.revList ++ l₁.revList⟩
instance : HasAppend MessageLog :=
⟨MessageLog.append⟩
def hasErrors (log : MessageLog) : Bool :=
log.revList.any $ fun m => match m.severity with
| MessageSeverity.error => true
| _ => false
def toList (log : MessageLog) : List Message :=
log.revList.reverse
end MessageLog
end Lean
|
5d44d3c07b3a9f74b4e4beed3f5f0900e7455648 | 3dd1b66af77106badae6edb1c4dea91a146ead30 | /tests/lean/run/tactic7.lean | 26f8042f13c68809b77e132f27a3ba84d4306c48 | [
"Apache-2.0"
] | permissive | silky/lean | 79c20c15c93feef47bb659a2cc139b26f3614642 | df8b88dca2f8da1a422cb618cd476ef5be730546 | refs/heads/master | 1,610,737,587,697 | 1,406,574,534,000 | 1,406,574,534,000 | 22,362,176 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 326 | lean | import standard
using tactic
theorem tst {A B : Prop} (H1 : A) (H2 : B) : A ∧ B ∧ A
:= by apply and_intro; state; assumption; apply and_intro; !assumption
check tst
theorem tst2 {A B : Prop} (H1 : A) (H2 : B) : A ∧ B ∧ A
:= by !([apply @and_intro | assumption] ; trace "STEP"; state; trace "----------")
check tst2
|
8e17aa5689b7d84f997ac6a89dea68500b1e1b72 | 0845ae2ca02071debcfd4ac24be871236c01784f | /library/init/lean/evalconst.lean | 17a80eef52c49f511b238bd2de8ea050667d1009 | [
"Apache-2.0"
] | permissive | GaloisInc/lean4 | 74c267eb0e900bfaa23df8de86039483ecbd60b7 | 228ddd5fdcd98dd4e9c009f425284e86917938aa | refs/heads/master | 1,643,131,356,301 | 1,562,715,572,000 | 1,562,715,572,000 | 192,390,898 | 0 | 0 | null | 1,560,792,750,000 | 1,560,792,749,000 | null | UTF-8 | Lean | false | false | 1,672 | 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.io
import init.data.array
import init.lean.name
namespace Lean
/- We mark this primitive as `unsafe` because it assumes the table is
being accessed by a single thread. -/
@[extern 2 "lean_modify_constant_table"]
unsafe constant modifyConstTable (f : Array (Name × NonScalar) → Array (Name × NonScalar)) : IO Unit := default _
/- We mark this primitive as `unsafe` because it assumes the table is
being accessed by a single thread. -/
@[extern 1 "lean_get_constant_table"]
unsafe constant getConstTable : IO (Array (Name × NonScalar)) := default _
/- We mark this primitive as `unsafe` because it assumes the table is
being accessed by a single thread. We meet this requirement by invoking
it after we have initialized all modules.
See `src/init/init.cpp` -/
@[export lean.sort_const_table_core]
unsafe def sortConstTable : IO Unit :=
modifyConstTable (fun cs => cs.qsort (fun e₁ e₂ => Name.quickLt e₁.1 e₂.1))
/- We make this primitive as `unsafe` because it uses `unsafeCast`, and
the program may crash if the type provided by the user is incorrect.
It also assumes there are no threads trying to update the table concurrently. -/
unsafe def evalConst (α : Type) [Inhabited α] (c : Name) : IO α :=
do cs ← getConstTable;
match cs.binSearch (c, default _) (fun e₁ e₂ => Name.quickLt e₁.1 e₂.1) with
| some (_, v) => pure (unsafeCast v)
| none => throw (IO.userError ("unknow constant '" ++ toString c ++ "'"))
end Lean
|
f0e66c9dc2c5d73099588d372b80e2de6e8e6272 | 0b3933727d99a2f351f5dbe6e24716bb786a6649 | /src/sesh/context.lean | 5939dd4f394bc8b0e5f99b04a5e2eeeb789223db | [] | no_license | Vtec234/lean-sesh | 1e770858215279f65aba92b4782b483ab4f09353 | d11d7bb0599406e27d3a4d26242aec13d639ecf7 | refs/heads/master | 1,587,497,515,696 | 1,558,362,223,000 | 1,558,362,223,000 | 169,809,439 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,771 | lean | /- Introduces typing contexts, which are lists of assumptions with associated
multiplicities from an arbitrary semiring. -/
import tactic.ring
import tactic.abel
import algebra
import metastuff
import sesh.types
import sesh.mult
/- In the QTT paper, this would be a "pre-precontext". -/
@[reducible]
def precontext := list tp
/- In the QTT paper, this is the "precontext".
τ is the Lean Type representing types of the embedded language.
mult is the Lean Type representing elements of an arbitrary semiring,
which describe the multiplicity of resources (how many times a resource
can or will be used). -/
inductive context: precontext → Type
| nil: context []
-- "You have a dependent pi (n) after a recursive arg (_ : context ns)
-- and Lean doesn't like this."
| cons {γ: precontext} (π: mult) (T: tp): context γ → context (T::γ)
notation `⟦`π`⬝`T`⟧::`Γ:90 := context.cons π T Γ
/- Indexes a judgment in the typing context. Definition follows
the inductive structure of natural numbers. -/
inductive debrujin_idx: precontext → tp → Type
infix ` ∋ `:55 := debrujin_idx
| ZVar: Π (γ: precontext) (T: tp),
----------
(T::γ) ∋ T
| SVar: Π {γ: precontext} {T: tp} (U: tp),
γ ∋ T
----------
→ (U::γ) ∋ T
infix ` ∋ `:55 := debrujin_idx
namespace context
-- An ugly hack which makes the contexts non-generic, but rather specific
-- to `tp`. Necessary because generic lemmas make `simp` slow to the point
-- of timing out and being generally unusable. This whole module should
-- still work when the variables are reintroduced.
--variable {τ: Type}
@[reducible]
def τ := tp
--variables {mult: Type} [semiring mult]
def zeros: Π (γ: precontext), context γ
| [] := nil
| (T::δ) := ⟦0⬝T⟧::(zeros δ)
instance {γ: precontext} : has_zero (context γ) :=
⟨zeros γ⟩
@[unfold_] lemma zeros_nil
: (0: context []) = nil := by refl
@[unfold_] lemma zeros_cons {γ: precontext} {T: τ}
: (0: context (T::γ)) = ⟦(0: mult)⬝T⟧::(0: context γ) := by refl
protected def add: Π {γ}, context γ → context γ → context γ
| _ nil nil := nil
| _ (⟦π₁⬝T⟧::Γ₁) (⟦π₂⬝.(T)⟧::Γ₂) := ⟦(π₁+π₂)⬝T⟧::(add Γ₁ Γ₂)
instance {γ: precontext} : has_add (context γ) :=
⟨context.add⟩
@[simp] lemma add_nil
: (nil: context []) + nil = nil := by refl
@[unfold_] lemma add_cons {γ} {Γ₁ Γ₂: context γ} {π₁ π₂: mult} {T: τ}
: ⟦π₁⬝T⟧::Γ₁ + ⟦π₂⬝T⟧::Γ₂ = ⟦(π₁+π₂)⬝T⟧::(Γ₁ + Γ₂) := by refl
/- addition makes a commutative monoid -/
@[simp] lemma zero_add
: ∀ {γ} {Γ: context γ},
0 + Γ = Γ :=
begin
intros,
induction Γ with γ π T Γ ih,
{ refl },
{ unfold has_zero.zero zeros at *,
simp * with unfold_, show 0+π=π,
abel },
end
@[simp] lemma add_zero
: ∀ {γ} {Γ: context γ},
Γ + 0 = Γ :=
begin
intros,
induction Γ with γ π T Γ ih,
{ refl },
{ unfold has_zero.zero zeros at *,
simp * with unfold_, show 0+π=π,
abel },
end
lemma zeros_left {γ} {Γ₁ Γ₂: context γ}
(h: Γ₁ + Γ₂ = 0)
: Γ₁ = 0 :=
begin
induction Γ₁ with γ π T Γ ih,
{ unfold has_zero.zero zeros },
{ cases Γ₂ with _ π₂ _ Γ₂,
unfold has_zero.zero zeros at h,
rw [add_cons] at h, simp at h,
congr' 1,
{ exact mult.zeros_left h.left },
{ exact ih h.right },
}
end
lemma zeros_right {γ} {Γ₁ Γ₂: context γ}
(h: Γ₁ + Γ₂ = 0)
: Γ₂ = 0 :=
begin
induction Γ₂ with γ π T Γ ih,
{ unfold has_zero.zero zeros },
{ cases Γ₁ with _ π₁ _ Γ₁,
unfold has_zero.zero zeros at h,
rw [add_cons] at h, simp at h,
congr' 1,
{ exact mult.zeros_left h.left },
{ exact ih h.right },
}
end
lemma add_comm
: ∀ {γ} {Γ₁ Γ₂: context γ},
Γ₁ + Γ₂ = Γ₂ + Γ₁ :=
begin
intros,
induction Γ₁ with γ₁ π₁ T₁ Γ₁ ih₁,
{ cases Γ₂, refl },
{ cases Γ₂ with _ π₂,
simp * with unfold_ },
end
lemma add_assoc
: ∀ {γ} {Γ₁ Γ₂ Γ₃: context γ},
(Γ₁ + Γ₂) + Γ₃ = Γ₁ + (Γ₂ + Γ₃) :=
begin
intros,
induction Γ₁ with γ₁ π₁ T₁ Γ₁ ih₁,
{ cases Γ₂, cases Γ₃, refl },
{ cases Γ₂ with _ π₂,
cases Γ₃ with _ π₃,
simp * with unfold_ },
end
instance {γ: precontext} : add_comm_monoid (context γ) :=
{ add := context.add,
zero := zeros γ,
zero_add := @zero_add γ,
add_zero := @add_zero γ,
add_comm := @add_comm γ,
add_assoc := @add_assoc γ }
protected def smul: Π {γ}, mult → context γ → context γ
| _ π nil := nil
| _ π (⟦π'⬝T⟧::Γ) := ⟦(π*π')⬝T⟧::(smul π Γ)
instance {γ: precontext} : has_scalar mult (context γ) :=
⟨context.smul⟩
@[simp] lemma smul_nil {π: mult}
: π • (nil: context []) = nil := by refl
@[unfold_] lemma smul_cons {γ} {Γ: context γ} {π π': mult} {T: τ}
: π • ⟦π'⬝T⟧::Γ = ⟦(π*π')⬝T⟧::(π • Γ) := by refl
/- scalar multiplication (mult • context) makes a semimodule -/
@[simp] lemma one_smul
: ∀ {γ} {Γ: context γ},
((1: mult) • Γ: context γ) = Γ :=
begin
intros,
induction Γ with γ π T Δ ih,
{ refl },
{ simp * with unfold_ },
end
@[simp] lemma zero_smul
: ∀ {γ} {Γ: context γ},
((0: mult) • Γ: context γ) = 0 :=
begin
intros,
induction Γ with γ π T Γ ih,
{ refl },
{ simp * with unfold_ },
end
@[simp] lemma smul_zero
: ∀ {γ} {π: mult},
(π • 0: context γ) = 0 :=
begin
intros,
induction γ with T γ ih,
{ refl },
{ unfold has_zero.zero zeros,
unfold has_zero.zero zeros at ih,
simp * with unfold_,
show π*0=0, simp * },
end
@[sop_form] lemma smul_add
: ∀ {γ} {π: mult} {Γ₁ Γ₂: context γ},
π • (Γ₁ + Γ₂) = π•Γ₁ + π•Γ₂ :=
begin
intros,
induction Γ₁ with γ₁ π₁ T₁ Γ₁ ih₁,
{ cases Γ₂, refl },
{ cases Γ₂ with _ π₂,
simp [*, left_distrib] with unfold_ },
end
@[sop_form] lemma add_smul
: ∀ {γ} {π₁ π₂: mult} {Γ: context γ},
(π₁ + π₂) • Γ = π₁•Γ + π₂•Γ :=
begin
intros,
induction Γ with γ π T Γ ih,
{ refl },
{ simp [*, right_distrib] with unfold_ },
end
lemma mul_smul
: ∀ {γ} {π π': mult} {Γ: context γ},
(π * π') • Γ = π • (π' • Γ) :=
begin
intros, induction Γ with γ π T Γ ih,
{ refl },
{ simp [*, mul_assoc] with unfold_ },
end
instance {γ: precontext} : semimodule mult (context γ) :=
{ one_smul := @one_smul γ,
zero_smul := @zero_smul γ,
smul_zero := @smul_zero γ,
smul_add := @smul_add γ,
add_smul := @add_smul γ,
mul_smul := @mul_smul γ }
end context
|
a3da0d99f1dda949a000b898061dc4732576546c | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/fin/interval.lean | 46e3a23c11bdfe947e0d9da7b1424f7550069156 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 5,981 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.nat.interval
import data.finset.locally_finite
/-!
# Finite intervals in `fin n`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file proves that `fin n` is a `locally_finite_order` and calculates the cardinality of its
intervals as finsets and fintypes.
-/
namespace fin
variables {n : ℕ} (a b : fin n)
@[simp, norm_cast] lemma coe_sup : (↑(a ⊔ b) : ℕ) = a ⊔ b := rfl
@[simp, norm_cast] lemma coe_inf : (↑(a ⊓ b) : ℕ) = a ⊓ b := rfl
@[simp, norm_cast] lemma coe_max : (↑(max a b) : ℕ) = max a b := rfl
@[simp, norm_cast] lemma coe_min : (↑(min a b) : ℕ) = min a b := rfl
end fin
open finset fin function
open_locale big_operators
variables (n : ℕ)
instance : locally_finite_order (fin n) :=
order_iso.locally_finite_order fin.order_iso_subtype
instance : locally_finite_order_bot (fin n) :=
order_iso.locally_finite_order_bot fin.order_iso_subtype
instance : Π n, locally_finite_order_top (fin n)
| 0 := is_empty.to_locally_finite_order_top
| (n + 1) := infer_instance
namespace fin
variables {n} (a b : fin n)
lemma Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).fin n := rfl
lemma Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).fin n := rfl
lemma Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).fin n := rfl
lemma Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).fin n := rfl
lemma uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).fin n := rfl
@[simp] lemma map_subtype_embedding_Icc : (Icc a b).map fin.coe_embedding = Icc a b :=
by simp [Icc_eq_finset_subtype, finset.fin, finset.map_map, Icc_filter_lt_of_lt_right]
@[simp] lemma map_subtype_embedding_Ico : (Ico a b).map fin.coe_embedding = Ico a b :=
by simp [Ico_eq_finset_subtype, finset.fin, finset.map_map]
@[simp] lemma map_subtype_embedding_Ioc : (Ioc a b).map fin.coe_embedding = Ioc a b :=
by simp [Ioc_eq_finset_subtype, finset.fin, finset.map_map, Ioc_filter_lt_of_lt_right]
@[simp] lemma map_subtype_embedding_Ioo : (Ioo a b).map fin.coe_embedding = Ioo a b :=
by simp [Ioo_eq_finset_subtype, finset.fin, finset.map_map]
@[simp] lemma map_subtype_embedding_uIcc : (uIcc a b).map coe_embedding = uIcc a b :=
map_subtype_embedding_Icc _ _
@[simp] lemma card_Icc : (Icc a b).card = b + 1 - a :=
by rw [←nat.card_Icc, ←map_subtype_embedding_Icc, card_map]
@[simp] lemma card_Ico : (Ico a b).card = b - a :=
by rw [←nat.card_Ico, ←map_subtype_embedding_Ico, card_map]
@[simp] lemma card_Ioc : (Ioc a b).card = b - a :=
by rw [←nat.card_Ioc, ←map_subtype_embedding_Ioc, card_map]
@[simp] lemma card_Ioo : (Ioo a b).card = b - a - 1 :=
by rw [←nat.card_Ioo, ←map_subtype_embedding_Ioo, card_map]
@[simp] lemma card_uIcc : (uIcc a b).card = (b - a : ℤ).nat_abs + 1 :=
by rw [coe_coe, coe_coe, ←nat.card_uIcc, ←map_subtype_embedding_uIcc, card_map]
@[simp] lemma card_fintype_Icc : fintype.card (set.Icc a b) = b + 1 - a :=
by rw [←card_Icc, fintype.card_of_finset]
@[simp] lemma card_fintype_Ico : fintype.card (set.Ico a b) = b - a :=
by rw [←card_Ico, fintype.card_of_finset]
@[simp] lemma card_fintype_Ioc : fintype.card (set.Ioc a b) = b - a :=
by rw [←card_Ioc, fintype.card_of_finset]
@[simp] lemma card_fintype_Ioo : fintype.card (set.Ioo a b) = b - a - 1 :=
by rw [←card_Ioo, fintype.card_of_finset]
@[simp] lemma card_fintype_uIcc : fintype.card (set.uIcc a b) = (b - a : ℤ).nat_abs + 1 :=
by rw [←card_uIcc, fintype.card_of_finset]
lemma Ici_eq_finset_subtype : Ici a = (Icc (a : ℕ) n).fin n := by { ext, simp }
lemma Ioi_eq_finset_subtype : Ioi a = (Ioc (a : ℕ) n).fin n := by { ext, simp }
lemma Iic_eq_finset_subtype : Iic b = (Iic (b : ℕ)).fin n := rfl
lemma Iio_eq_finset_subtype : Iio b = (Iio (b : ℕ)).fin n := rfl
@[simp] lemma map_subtype_embedding_Ici : (Ici a).map fin.coe_embedding = Icc a (n - 1) :=
begin
ext x,
simp only [exists_prop, embedding.coe_subtype, mem_Ici, mem_map, mem_Icc],
split,
{ rintro ⟨x, hx, rfl⟩,
exact ⟨hx, le_tsub_of_add_le_right $ x.2⟩ },
cases n,
{ exact fin.elim0 a },
{ exact λ hx, ⟨⟨x, nat.lt_succ_iff.2 hx.2⟩, hx.1, rfl⟩ }
end
@[simp] lemma map_subtype_embedding_Ioi : (Ioi a).map fin.coe_embedding = Ioc a (n - 1) :=
begin
ext x,
simp only [exists_prop, embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc],
split,
{ rintro ⟨x, hx, rfl⟩,
exact ⟨hx, le_tsub_of_add_le_right $ x.2⟩ },
cases n,
{ exact fin.elim0 a },
{ exact λ hx, ⟨⟨x, nat.lt_succ_iff.2 hx.2⟩, hx.1, rfl⟩ }
end
@[simp] lemma map_subtype_embedding_Iic : (Iic b).map fin.coe_embedding = Iic b :=
by simp [Iic_eq_finset_subtype, finset.fin, finset.map_map, Iic_filter_lt_of_lt_right]
@[simp] lemma map_subtype_embedding_Iio : (Iio b).map fin.coe_embedding = Iio b :=
by simp [Iio_eq_finset_subtype, finset.fin, finset.map_map]
@[simp] lemma card_Ici : (Ici a).card = n - a :=
by { cases n, { exact fin.elim0 a }, rw [←card_map, map_subtype_embedding_Ici, nat.card_Icc], refl }
@[simp] lemma card_Ioi : (Ioi a).card = n - 1 - a :=
by { rw [←card_map, map_subtype_embedding_Ioi, nat.card_Ioc] }
@[simp] lemma card_Iic : (Iic b).card = b + 1 :=
by rw [←nat.card_Iic b, ←map_subtype_embedding_Iic, card_map]
@[simp] lemma card_Iio : (Iio b).card = b :=
by rw [←nat.card_Iio b, ←map_subtype_embedding_Iio, card_map]
@[simp] lemma card_fintype_Ici : fintype.card (set.Ici a) = n - a :=
by rw [fintype.card_of_finset, card_Ici]
@[simp] lemma card_fintype_Ioi : fintype.card (set.Ioi a) = n - 1 - a :=
by rw [fintype.card_of_finset, card_Ioi]
@[simp] lemma card_fintype_Iic : fintype.card (set.Iic b) = b + 1 :=
by rw [fintype.card_of_finset, card_Iic]
@[simp] lemma card_fintype_Iio : fintype.card (set.Iio b) = b :=
by rw [fintype.card_of_finset, card_Iio]
end fin
|
cee4fe10f65a1010eed04806f9fed2bfd9231490 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/topology/metric_space/baire.lean | b8aa85592c25fcd1c6247ed6727996ba3b8d7279 | [
"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 | 15,217 | 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.metric_space.basic analysis.specific_limits
/-!
# Baire theorem
In a complete metric space, a countable intersection of dense open subsets is dense.
The good concept underlying the theorem is that of a Gδ set, i.e., a countable intersection
of open sets. Then Baire theorem can also be formulated as the fact that a countable
intersection of dense Gδ sets is a dense Gδ set. We prove Baire theorem, giving several different
formulations that can be handy. We also prove the important consequence that, if the space is
covered by a countable union of closed sets, then the union of their interiors is dense.
The names of the theorems do not contain the string "Baire", but are instead built from the form of
the statement. "Baire" is however in the docstring of all the theorems, to facilitate grep searches.
-/
noncomputable theory
open_locale classical
open filter lattice encodable set
variables {α : Type*} {β : Type*} {γ : Type*}
section is_Gδ
variable [topological_space α]
/-- A Gδ set is a countable intersection of open sets. -/
def is_Gδ (s : set α) : Prop :=
∃T : set (set α), (∀t ∈ T, is_open t) ∧ countable T ∧ s = (⋂₀ T)
/-- An open set is a Gδ set. -/
lemma is_open.is_Gδ {s : set α} (h : is_open s) : is_Gδ s :=
⟨{s}, by simp [h], countable_singleton _, (set.sInter_singleton _).symm⟩
lemma is_Gδ_bInter_of_open {ι : Type*} {I : set ι} (hI : countable I) {f : ι → set α}
(hf : ∀i ∈ I, is_open (f i)) : is_Gδ (⋂i∈I, f i) :=
⟨f '' I, by rwa ball_image_iff, countable_image _ hI, by rw sInter_image⟩
lemma is_Gδ_Inter_of_open {ι : Type*} [encodable ι] {f : ι → set α}
(hf : ∀i, is_open (f i)) : is_Gδ (⋂i, f i) :=
⟨range f, by rwa forall_range_iff, countable_range _, by rw sInter_range⟩
/-- A countable intersection of Gδ sets is a Gδ set. -/
lemma is_Gδ_sInter {S : set (set α)} (h : ∀s∈S, is_Gδ s) (hS : countable S) : is_Gδ (⋂₀ S) :=
begin
have : ∀s : set α, ∃T : set (set α), s ∈ S → ((∀t ∈ T, is_open t) ∧ countable T ∧ s = (⋂₀ T)),
{ assume s,
by_cases hs : s ∈ S,
{ simp [hs], exact h s hs },
{ simp [hs] }},
choose T hT using this,
refine ⟨⋃s∈S, T s, λt ht, _, _, _⟩,
{ simp only [exists_prop, set.mem_Union] at ht,
rcases ht with ⟨s, hs, tTs⟩,
exact (hT s hs).1 t tTs },
{ exact countable_bUnion hS (λs hs, (hT s hs).2.1) },
{ exact (sInter_bUnion (λs hs, (hT s hs).2.2)).symm }
end
/-- The union of two Gδ sets is a Gδ set. -/
lemma is_Gδ.union {s t : set α} (hs : is_Gδ s) (ht : is_Gδ t) : is_Gδ (s ∪ t) :=
begin
rcases hs with ⟨S, Sopen, Scount, sS⟩,
rcases ht with ⟨T, Topen, Tcount, tT⟩,
rw [sS, tT, sInter_union_sInter],
apply is_Gδ_bInter_of_open (countable_prod Scount Tcount),
rintros ⟨a, b⟩ hab,
simp only [set.prod_mk_mem_set_prod_eq] at hab,
have aopen : is_open a := Sopen a hab.1,
have bopen : is_open b := Topen b hab.2,
simp [aopen, bopen, is_open_union]
end
end is_Gδ
section Baire_theorem
open metric
variables [metric_space α] [complete_space α]
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here when
the source space is ℕ (and subsumed below by `dense_Inter_of_open` working with any
encodable source space). -/
theorem dense_Inter_of_open_nat {f : ℕ → set α} (ho : ∀n, is_open (f n))
(hd : ∀n, closure (f n) = univ) : closure (⋂n, f n) = univ :=
begin
let B : ℕ → ℝ := λn, ((1/2)^n : ℝ),
have Bpos : ∀n, 0 < B n := λn, begin apply pow_pos, by norm_num end,
/- Translate the density assumption into two functions `center` and `radius` associating
to any n, x, δ, δpos a center and a positive radius such that
`closed_ball center radius` is included both in `f n` and in `closed_ball x δ`.
We can also require `radius ≤ (1/2)^(n+1), to ensure we get a Cauchy sequence later. -/
have : ∀n x δ, ∃y r, δ > 0 → (r > 0 ∧ r ≤ B (n+1) ∧ closed_ball y r ⊆ (closed_ball x δ) ∩ f n),
{ assume n x δ,
by_cases δpos : δ > 0,
{ have : x ∈ closure (f n) := by simpa only [(hd n).symm] using mem_univ x,
rcases mem_closure_iff'.1 this (δ/2) (half_pos δpos) with ⟨y, ys, xy⟩,
rw dist_comm at xy,
rcases is_open_iff.1 (ho n) y ys with ⟨r, rpos, hr⟩,
refine ⟨y, min (min (δ/2) (r/2)) (B (n+1)), λ_, ⟨_, _, λz hz, ⟨_, _⟩⟩⟩,
show 0 < min (min (δ / 2) (r/2)) (B (n+1)),
from lt_min (lt_min (half_pos δpos) (half_pos rpos)) (Bpos (n+1)),
show min (min (δ / 2) (r/2)) (B (n+1)) ≤ B (n+1), from min_le_right _ _,
show z ∈ closed_ball x δ, from calc
dist z x ≤ dist z y + dist y x : dist_triangle _ _ _
... ≤ (min (min (δ / 2) (r/2)) (B (n+1))) + (δ/2) : add_le_add hz (le_of_lt xy)
... ≤ δ/2 + δ/2 : add_le_add (le_trans (min_le_left _ _) (min_le_left _ _)) (le_refl _)
... = δ : add_halves _,
show z ∈ f n, from hr (calc
dist z y ≤ min (min (δ / 2) (r/2)) (B (n+1)) : hz
... ≤ r/2 : le_trans (min_le_left _ _) (min_le_right _ _)
... < r : half_lt_self rpos) },
{ use [x, 0] }},
choose center radius H using this,
refine subset.antisymm (subset_univ _) (λx hx, _),
refine metric.mem_closure_iff'.2 (λε εpos, _),
/- ε is positive. We have to find a point in the ball of radius ε around x belonging to all `f n`.
For this, we construct inductively a sequence `F n = (c n, r n)` such that the closed ball
`closed_ball (c n) (r n)` is included in the previous ball and in `f n`, and such that
`r n` is small enough to ensure that `c n` is a Cauchy sequence. Then `c n` converges to a
limit which belongs to all the `f n`. -/
let F : ℕ → (α × ℝ) := λn, nat.rec_on n (prod.mk x (min (ε/2) 1))
(λn p, prod.mk (center n p.1 p.2) (radius n p.1 p.2)),
let c : ℕ → α := λn, (F n).1,
let r : ℕ → ℝ := λn, (F n).2,
have rpos : ∀n, r n > 0,
{ assume n,
induction n with n hn,
exact lt_min (half_pos εpos) (zero_lt_one),
exact (H n (c n) (r n) hn).1 },
have rB : ∀n, r n ≤ B n,
{ assume n,
induction n with n hn,
exact min_le_right _ _,
exact (H n (c n) (r n) (rpos n)).2.1 },
have incl : ∀n, closed_ball (c (n+1)) (r (n+1)) ⊆ (closed_ball (c n) (r n)) ∩ (f n) :=
λn, (H n (c n) (r n) (rpos n)).2.2,
have cdist : ∀n, dist (c n) (c (n+1)) ≤ B n,
{ assume n,
rw dist_comm,
have A : c (n+1) ∈ closed_ball (c (n+1)) (r (n+1)) :=
mem_closed_ball_self (le_of_lt (rpos (n+1))),
have I := calc
closed_ball (c (n+1)) (r (n+1)) ⊆ closed_ball (c n) (r n) :
subset.trans (incl n) (inter_subset_left _ _)
... ⊆ closed_ball (c n) (B n) : closed_ball_subset_closed_ball (rB n),
exact I A },
have : cauchy_seq c,
{ refine cauchy_seq_of_le_geometric (1/2) 1 (by norm_num) (λn, _),
rw one_mul,
exact cdist n },
-- as the sequence `c n` is Cauchy in a complete space, it converges to a limit `y`.
rcases cauchy_seq_tendsto_of_complete this with ⟨y, ylim⟩,
-- this point `y` will be the desired point. We will check that it belongs to all
-- `f n` and to `ball x ε`.
use y,
simp only [exists_prop, set.mem_Inter],
have I : ∀n, ∀m ≥ n, closed_ball (c m) (r m) ⊆ closed_ball (c n) (r n),
{ assume n,
refine nat.le_induction _ (λm hnm h, _),
{ exact subset.refl _ },
{ exact subset.trans (incl m) (subset.trans (inter_subset_left _ _) h) }},
have yball : ∀n, y ∈ closed_ball (c n) (r n),
{ assume n,
refine mem_of_closed_of_tendsto (by simp) ylim is_closed_ball _,
simp only [filter.mem_at_top_sets, nonempty_of_inhabited, set.mem_preimage],
exact ⟨n, λm hm, I n m hm (mem_closed_ball_self (le_of_lt (rpos m)))⟩ },
split,
show ∀n, y ∈ f n,
{ assume n,
have : closed_ball (c (n+1)) (r (n+1)) ⊆ f n := subset.trans (incl n) (inter_subset_right _ _),
exact this (yball (n+1)) },
show dist x y < ε, from calc
dist x y = dist y x : dist_comm _ _
... ≤ r 0 : yball 0
... < ε : lt_of_le_of_lt (min_le_left _ _) (half_lt_self εpos)
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with ⋂₀. -/
theorem dense_sInter_of_open {S : set (set α)} (ho : ∀s∈S, is_open s) (hS : countable S)
(hd : ∀s∈S, closure s = univ) : closure (⋂₀S) = univ :=
begin
by_cases h : S = ∅,
{ simp [h] },
{ rcases exists_surjective_of_countable h hS with ⟨f, hf⟩,
have F : ∀n, f n ∈ S := λn, by rw hf; exact mem_range_self _,
rw [hf, sInter_range],
exact dense_Inter_of_open_nat (λn, ho _ (F n)) (λn, hd _ (F n)) }
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is a countable set in any type. -/
theorem dense_bInter_of_open {S : set β} {f : β → set α} (ho : ∀s∈S, is_open (f s))
(hS : countable S) (hd : ∀s∈S, closure (f s) = univ) : closure (⋂s∈S, f s) = univ :=
begin
rw ← sInter_image,
apply dense_sInter_of_open,
{ rwa ball_image_iff },
{ exact countable_image _ hS },
{ rwa ball_image_iff }
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is an encodable type. -/
theorem dense_Inter_of_open [encodable β] {f : β → set α} (ho : ∀s, is_open (f s))
(hd : ∀s, closure (f s) = univ) : closure (⋂s, f s) = univ :=
begin
rw ← sInter_range,
apply dense_sInter_of_open,
{ rwa forall_range_iff },
{ exact countable_range _ },
{ rwa forall_range_iff }
end
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with ⋂₀. -/
theorem dense_sInter_of_Gδ {S : set (set α)} (ho : ∀s∈S, is_Gδ s) (hS : countable S)
(hd : ∀s∈S, closure s = univ) : closure (⋂₀S) = univ :=
begin
-- the result follows from the result for a countable intersection of dense open sets,
-- by rewriting each set as a countable intersection of open sets, which are of course dense.
have : ∀s : set α, ∃T : set (set α), s ∈ S → ((∀t ∈ T, is_open t) ∧ countable T ∧ s = (⋂₀ T)),
{ assume s,
by_cases hs : s ∈ S,
{ simp [hs], exact ho s hs },
{ simp [hs] }},
choose T hT using this,
have : ⋂₀ S = ⋂₀ (⋃s∈S, T s) := (sInter_bUnion (λs hs, (hT s hs).2.2)).symm,
rw this,
refine dense_sInter_of_open (λt ht, _) (countable_bUnion hS (λs hs, (hT s hs).2.1)) (λt ht, _),
show is_open t,
{ simp only [exists_prop, set.mem_Union] at ht,
rcases ht with ⟨s, hs, tTs⟩,
exact (hT s hs).1 t tTs },
show closure t = univ,
{ simp only [exists_prop, set.mem_Union] at ht,
rcases ht with ⟨s, hs, tTs⟩,
apply subset.antisymm (subset_univ _),
rw ← (hd s hs),
apply closure_mono,
have := sInter_subset_of_mem tTs,
rwa ← (hT s hs).2.2 at this }
end
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with
an index set which is a countable set in any type. -/
theorem dense_bInter_of_Gδ {S : set β} {f : β → set α} (ho : ∀s∈S, is_Gδ (f s))
(hS : countable S) (hd : ∀s∈S, closure (f s) = univ) : closure (⋂s∈S, f s) = univ :=
begin
rw ← sInter_image,
apply dense_sInter_of_Gδ,
{ rwa ball_image_iff },
{ exact countable_image _ hS },
{ rwa ball_image_iff }
end
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with
an index set which is an encodable type. -/
theorem dense_Inter_of_Gδ [encodable β] {f : β → set α} (ho : ∀s, is_Gδ (f s))
(hd : ∀s, closure (f s) = univ) : closure (⋂s, f s) = univ :=
begin
rw ← sInter_range,
apply dense_sInter_of_Gδ,
{ rwa forall_range_iff },
{ exact countable_range _ },
{ rwa forall_range_iff }
end
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with an index set which is a countable set in any type. -/
theorem dense_bUnion_interior_of_closed {S : set β} {f : β → set α} (hc : ∀s∈S, is_closed (f s))
(hS : countable S) (hU : (⋃s∈S, f s) = univ) : closure (⋃s∈S, interior (f s)) = univ :=
begin
let g := λs, - (frontier (f s)),
have clos_g : closure (⋂s∈S, g s) = univ,
{ refine dense_bInter_of_open (λs hs, _) hS (λs hs, _),
show is_open (g s), from is_open_compl_iff.2 is_closed_frontier,
show closure (g s) = univ,
{ apply subset.antisymm (subset_univ _),
simp [g, interior_frontier (hc s hs)] }},
have : (⋂s∈S, g s) ⊆ (⋃s∈S, interior (f s)),
{ assume x hx,
have : x ∈ ⋃s∈S, f s, { have := mem_univ x, rwa ← hU at this },
rcases mem_bUnion_iff.1 this with ⟨s, hs, xs⟩,
have : x ∈ g s := mem_bInter_iff.1 hx s hs,
have : x ∈ interior (f s),
{ have : x ∈ f s \ (frontier (f s)) := mem_inter xs this,
simpa [frontier, xs, closure_eq_of_is_closed (hc s hs)] using this },
exact mem_bUnion_iff.2 ⟨s, ⟨hs, this⟩⟩ },
have := closure_mono this,
rw clos_g at this,
exact subset.antisymm (subset_univ _) this
end
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with ⋃₀. -/
theorem dense_sUnion_interior_of_closed {S : set (set α)} (hc : ∀s∈S, is_closed s)
(hS : countable S) (hU : (⋃₀ S) = univ) : closure (⋃s∈S, interior s) = univ :=
by rw sUnion_eq_bUnion at hU; exact dense_bUnion_interior_of_closed hc hS hU
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with an index set which is an encodable type. -/
theorem dense_Union_interior_of_closed [encodable β] {f : β → set α} (hc : ∀s, is_closed (f s))
(hU : (⋃s, f s) = univ) : closure (⋃s, interior (f s)) = univ :=
begin
rw ← bUnion_univ,
apply dense_bUnion_interior_of_closed,
{ simp [hc] },
{ apply countable_encodable },
{ rwa ← bUnion_univ at hU }
end
/-- One of the most useful consequences of Baire theorem: if a countable union of closed sets
covers the space, then one of the sets has nonempty interior. -/
theorem nonempty_interior_of_Union_of_closed [n : nonempty α] [encodable β] {f : β → set α}
(hc : ∀s, is_closed (f s)) (hU : (⋃s, f s) = univ) : ∃s x ε, ε > 0 ∧ ball x ε ⊆ f s :=
begin
have : ∃s, interior (f s) ≠ ∅,
{ by_contradiction h,
simp only [not_exists_not, ne.def] at h,
have := calc ∅ = closure (⋃s, interior (f s)) : by simp [h]
... = univ : dense_Union_interior_of_closed hc hU,
exact nonempty_iff_univ_ne_empty.1 n this.symm },
rcases this with ⟨s, hs⟩,
rcases ne_empty_iff_exists_mem.1 hs with ⟨x, hx⟩,
rcases mem_nhds_iff.1 (mem_interior_iff_mem_nhds.1 hx) with ⟨ε, εpos, hε⟩,
exact ⟨s, x, ε, εpos, hε⟩,
end
end Baire_theorem
|
b090ac6b693e4969846cde4320b9efb5a723409c | 8c02fed42525b65813b55c064afe2484758d6d09 | /src/spec/refinement.lean | 1e4fd8add646c40534756eb537def95eae181f2b | [
"LicenseRef-scancode-generic-cla",
"MIT"
] | permissive | microsoft/AliveInLean | 3eac351a34154efedd3ffc4fe2fa4ec01b219e0d | 4b739dd6e4266b26a045613849df221374119871 | refs/heads/master | 1,691,419,737,939 | 1,689,365,567,000 | 1,689,365,568,000 | 131,156,103 | 23 | 18 | NOASSERTION | 1,660,342,040,000 | 1,524,747,538,000 | Lean | UTF-8 | Lean | false | false | 13,648 | lean | -- Copyright (c) Microsoft Corporation. All rights reserved.
-- Licensed under the MIT license.
import ..smtexpr
import ..smtcompile
import ..bitvector
import ..verifyopt
import .spec
import .lemmas
import .irstate
import .freevar
import .equiv
import .openprog
import ..irsem_exec
import smt2.syntax
import system.io
import init.meta.tactic
import init.meta.interactive
namespace spec
open opt
open irsem
set_option pp.proofs true
lemma check_val_exec_spec_prf : check_val_exec_spec
:= begin
unfold check_val_exec_spec,
intros,
cases vsrc with szsrc vsrc psrc,
cases vtgt with sztgt vtgt ptgt,
unfold check_val at H,
have HSZ:decidable (sztgt = szsrc), apply_instance,
cases HSZ,
{ rw dif_neg at H, cases H, apply neq_symm, assumption },
{
rw dif_pos at H,
rw valty_rwsize_exec sztgt szsrc,
injection H with H,
generalize H0: (vsrc =_{irsem_exec.boolty}
cast (check_val._match_1._proof_1
irsem_exec szsrc sztgt (eq.symm HSZ)) vtgt) = t,
rw H0 at H,
unfold has_not.not at H,
unfold has_or.or at H,
unfold has_and.and at H,
cases psrc,
{
apply val_refines.poison_intty, refl
},
{
apply val_refines.concrete_intty,
{ refl },
{ cases ptgt,
{
cases t, cases H, cases H
},
refl },
{
cases t,
{ cases ptgt, cases H, cases H },
{
unfold has_eq.eq at H0,
unfold has_comp.eq at H0,
unfold bitvector.eq at H0,
simp at H0, rw H0
}
}
},
any_goals { assumption }
}
end
set_option pp.proofs true
lemma check_val_replace: ∀ vssrc vstgt (η:freevar.env),
η⟦opt.check_val irsem_smt vssrc vstgt⟧' = opt.check_val irsem_smt (η⟦vssrc⟧) (η⟦vstgt⟧)
:= begin
intros,
cases vssrc, cases vstgt,
unfold opt.check_val,
unfold freevar.env.replace_valty,
have HSZ: decidable (vssrc_sz = vstgt_sz), apply_instance,
cases HSZ,
{
unfold check_val._match_1,
rw dif_neg HSZ,
rw dif_neg HSZ
},
{
unfold check_val._match_1,
rw dif_pos HSZ,
rw dif_pos HSZ,
unfold apply,
unfold_coes,
unfold id,
rw env.replace_sb_or,
rw env.replace_sb_not,
rw env.replace_sb_and,
unfold has_eq.eq, unfold has_comp.eq,
rw env.replace_sb_eqbv,
rw env.replace_sbv_cast, rw HSZ
}
end
lemma check_val_some: ∀ {vssrc vstgt vesrc vetgt sres eres}
(HEQS:equals_size vssrc vesrc = tt)
(HEQT:equals_size vstgt vetgt = tt)
(HS:sres = opt.check_val irsem_smt vssrc vstgt)
(HE:eres = opt.check_val irsem_exec vesrc vetgt),
none_or_some sres eres (λ s e, true)
:= begin
intros,
cases vssrc, cases vesrc, cases vstgt, cases vetgt,
unfold equals_size at HEQS, simp at HEQS,
unfold equals_size at HEQT, simp at HEQT,
unfold check_val at HS,
unfold check_val at HE,
have HSZ': decidable (vssrc_sz = vstgt_sz), apply_instance,
cases HSZ',
{
have HSZ'': vesrc_sz ≠ vetgt_sz,
{ rw ← HEQS, rw ← HEQT, assumption },
rw dif_neg HSZ' at HS,
rw dif_neg HSZ'' at HE,
unfold none_or_some, left, split; assumption
},
{
have HSZ'': vesrc_sz = vetgt_sz,
{ rw ← HEQS, rw ← HEQT, assumption },
rw dif_pos HSZ' at HS,
rw dif_pos HSZ'' at HE,
cases sres, cases HS, injection HS,
cases eres, cases HE, injection HE,
unfold none_or_some, right, apply exists.intro,
apply exists.intro, split, refl, split, refl, constructor
}
end
lemma check_val_equiv: ∀ {vssrc vstgt vesrc vetgt sres eres}
(HEQS:val_equiv vssrc vesrc)
(HEQT:val_equiv vstgt vetgt)
(HS:sres = opt.check_val irsem_smt vssrc vstgt)
(HE:eres = opt.check_val irsem_exec vesrc vetgt),
none_or_some sres eres (λ s e, b_equiv s e)
:= begin
intros,
cases vssrc, cases vstgt,
cases vesrc, cases vetgt, -- make ivals
have HSSZEQ := val_equiv_eqsize HEQS,
have HTSZEQ := val_equiv_eqsize HEQT,
unfold opt.check_val at *,
have HSZ': decidable (vssrc_sz = vstgt_sz), apply_instance,
cases HSZ',
{
have HSZ'': vesrc_sz ≠ vetgt_sz,
{
rw ← HSSZEQ, rw ← HTSZEQ, assumption
},
rw dif_neg HSZ' at HS,
rw dif_neg HSZ'' at HE,
rw HS, rw HE, unfold none_or_some, left, split;refl
},
{
have HSZ'': vesrc_sz = vetgt_sz,
{ rw [← HSSZEQ, ← HTSZEQ], rw HSZ' },
rw dif_pos HSZ' at HS,
rw dif_pos HSZ'' at HE,
cases sres, cases HS,
cases eres, cases HE,
injection HS with HS, injection HE with HE,
unfold none_or_some,
right,
existsi sres, existsi eres,
split, refl, split, refl,
rw [HS, HE],
cases HEQS,
{ -- source is poison.
cases HEQS_a with HEQS_a,
apply b_equiv.or1,
{ apply b_equiv.not, unfold_coes, unfold id, assumption },
{ intros H, rw HEQS_a_2 at H, cases H }
},
{ -- source is concrete value,
cases HEQS_a,
cases HEQT,
{ -- target is poison
apply b_equiv.or1, apply b_equiv.not, assumption,
intros, apply b_equiv.and1, cases HEQT_a, assumption,
intros, rw HEQT_a_2 at a_1, cases a_1
},
{
cases HEQT_a,
apply b_equiv.or1,
{ apply b_equiv.not, assumption },
{ intros, apply b_equiv.and1, assumption, intros,
apply b_equiv.eq, assumption, --apply HEQT_a_1, apply bv_equiv.cast,
apply bv_equiv_cast, assumption, rw HSZ''
}
}
}
}
end
universe u
lemma check_single_reg0_replace: ∀ psrc ptgt root ss0 (η:freevar.env),
η⟦opt.check_single_reg0 irsem_smt psrc ptgt root ss0⟧' =
opt.check_single_reg0 irsem_smt psrc ptgt root (η⟦ss0⟧)
:= begin
intros,
unfold opt.check_single_reg0,
generalize HSS: irsem.bigstep irsem_smt ss0 psrc = oss,
generalize HSS': irsem.bigstep irsem_smt ss0 ptgt = oss',
rw ← bigstep_replace,
rw ← bigstep_replace,
rw HSS, rw HSS',
unfold has_bind.bind,
cases oss; cases oss';unfold option.bind,
generalize HSV: irstate.getreg irsem_smt oss root = ovs,
generalize HSV': irstate.getreg irsem_smt oss' root = ovs',
rw getreg_replace HSV,
rw getreg_replace HSV',
cases ovs; cases ovs'; unfold option.bind,
rw ← check_val_replace,
generalize HCV: check_val irsem_smt ovs ovs' = ocv,
cases ocv;unfold option.bind,
unfold return, unfold pure,
unfold apply,
rw env.replace_sb_or,
rw env.replace_sb_not,
rw replace_getub,
rw env.replace_sb_and,
rw replace_getub
end
lemma check_single_reg0_equiv: ∀ psrc ptgt root ss0 se0 sres eres
(HEQ:irstate_equiv ss0 se0)
(HS:sres = opt.check_single_reg0 irsem_smt psrc ptgt root ss0)
(HE:eres = opt.check_single_reg0 irsem_exec psrc ptgt root se0)
(HEQS:irstate_equiv ss0 se0),
none_or_some sres eres (λ s e, b_equiv s e)
:= begin
intros,
unfold opt.check_single_reg0 at *,
unfold has_bind.bind at HS,
unfold has_bind.bind at HE,
generalize HSS: irsem.bigstep irsem_smt ss0 psrc = oss,
generalize HSS': irsem.bigstep irsem_smt ss0 ptgt = oss',
generalize HSE: irsem.bigstep irsem_exec se0 psrc = ose,
generalize HSE': irsem.bigstep irsem_exec se0 ptgt = ose',
rw [HSS, HSS'] at HS,
rw [HSE, HSE'] at HE,
have HPTGT_ENTANGLED: none_or_some oss' ose' (λ ss' se', irstate_equiv ss' se'),
{
apply bigstep_both_equiv,
assumption, rw HSS', rw HSE'
},
have HPSRC_ENTANGLED: none_or_some oss ose (λ ss' se', irstate_equiv ss' se'),
{
apply bigstep_both_equiv,
assumption, rw HSS, rw HSE
},
cases oss; cases oss';
cases ose; cases ose',
any_goals { unfold option.bind at HS, unfold option.bind at HE,
rw HS, rw HE, unfold none_or_some, left, split; refl },
any_goals {
exfalso, apply none_or_some_false2, apply HPSRC_ENTANGLED
},
any_goals {
exfalso, apply none_or_some_false1, apply HPSRC_ENTANGLED
},
any_goals {
exfalso, apply none_or_some_false2, apply HPTGT_ENTANGLED
},
any_goals {
exfalso, apply none_or_some_false1, apply HPTGT_ENTANGLED
},
rw none_or_some_apply at HPSRC_ENTANGLED,
rw none_or_some_apply at HPTGT_ENTANGLED,
unfold option.bind at HS,
unfold option.bind at HE,
generalize HSV: irstate.getreg irsem_smt oss root = ovs,
generalize HSV': irstate.getreg irsem_smt oss' root = ovs',
generalize HEV: irstate.getreg irsem_exec ose root = ove,
generalize HEV': irstate.getreg irsem_exec ose' root = ove',
have HSRCVEQ := irstate.getreg_equiv HPSRC_ENTANGLED (eq.symm HSV) (eq.symm HEV),
have HTGTVEQ := irstate.getreg_equiv HPTGT_ENTANGLED (eq.symm HSV') (eq.symm HEV'),
rw [HSV, HSV'] at HS,
rw [HEV, HEV'] at HE,
cases ovs; cases ovs'; cases ove; cases ove',
any_goals { unfold option.bind at HS, unfold option.bind at HE,
rw HS, rw HE, unfold none_or_some, left, split; refl },
any_goals {
exfalso, apply none_or_some_false2, apply HSRCVEQ
},
any_goals {
exfalso, apply none_or_some_false1, apply HSRCVEQ
},
any_goals {
exfalso, apply none_or_some_false2, apply HTGTVEQ
},
any_goals {
exfalso, apply none_or_some_false1, apply HTGTVEQ
},
rw none_or_some_apply at HSRCVEQ,
rw none_or_some_apply at HTGTVEQ,
unfold option.bind at HS,
unfold option.bind at HE,
cases HSRCVEQ with HSRCSZEQ HSRCVEQ,
cases HTGTVEQ with HTGTSZEQ HTGTVEQ,
generalize HSCV: check_val irsem_smt ovs ovs' = scv,
generalize HECV: check_val irsem_exec ove ove' = ecv,
rw HSCV at HS, rw HECV at HE,
have HCVRET := check_val_some HSRCSZEQ HTGTSZEQ (eq.symm HSCV) (eq.symm HECV),
cases scv ; cases ecv,
{ unfold option.bind at HS, unfold option.bind at HE,
rw HS, rw HE, unfold none_or_some, left, split; refl },
{
unfold option.bind at HS,
unfold option.bind at HE,
exfalso, apply none_or_some_false2,
assumption
},
{
unfold option.bind at HS,
unfold option.bind at HE,
exfalso, apply none_or_some_false1,
assumption
},
unfold option.bind at HS,
unfold option.bind at HE,
unfold return at *, unfold pure at *,
unfold none_or_some, right,
apply exists.intro,
apply exists.intro,
split, assumption,
split, assumption,
generalize HUB: (~irstate.getub irsem_exec ose) = ub,
cases ub,
{
apply b_equiv.or1,
{
rw ← HUB, apply b_equiv.not,
apply irstate.getub_equiv,
apply HPSRC_ENTANGLED,
refl, refl
},
{
generalize HUB': irstate.getub irsem_exec ose' = ub',
cases ub',
{
intros, apply b_equiv.and1,
rw ← HUB',
apply irstate.getub_equiv,
apply HPTGT_ENTANGLED, refl, rw HUB', intros Q, cases Q
},
{
intros, apply b_equiv.and1,
apply irstate.getub_equiv,
apply HPTGT_ENTANGLED, refl, rw HUB',
have HNOUB: has_no_ub ose = tt,
{
cases ose, unfold irstate.getub at HUB,
simp at HUB, unfold has_not.not at HUB,
cases ose_fst, cases HUB, refl
},
have HNOUB': has_no_ub ose' = tt,
{
cases ose', unfold irstate.getub at HUB',
simp at HUB',
cases ose'_fst, cases HUB', refl
},
have HV := HSRCVEQ HNOUB,
have HV' := HTGTVEQ HNOUB',
have HCVRET := check_val_equiv HV HV' (eq.symm HSCV) (eq.symm HECV),
rw none_or_some_apply at HCVRET,
intros, assumption
}
}
},
{
apply b_equiv.or1,
{
rw ← HUB, apply b_equiv.not, apply irstate.getub_equiv, apply HPSRC_ENTANGLED,
refl, refl
},
{
intros Q, cases Q
}
}
end
theorem refines_single_reg_correct_prf: refines_single_reg_correct
:= begin
unfold refines_single_reg_correct,
intros,
unfold root_refines_smt,
intros,
unfold root_refines_finalstate,
intros,
generalize HEREF: check_single_reg0 irsem_exec psrc ptgt root se0 = oeb,
have HSREF': some (η⟦sb⟧) = check_single_reg0 irsem_smt psrc ptgt root (η⟦ss0⟧),
{
rw ← check_single_reg0_replace,
rw ← HSREF
},
have HCHKEQ: none_or_some (some (η⟦sb⟧)) oeb (λ s e, b_equiv s e),
{
apply check_single_reg0_equiv,
unfold encode at a, apply a,
rw HSREF', rw HEREF, unfold encode at a, apply a
},
cases oeb with eb,
{ exfalso, apply none_or_some_false1, assumption },
rw none_or_some_apply at HCHKEQ,
have HCHKTT := HEQ η eb HCHKEQ,
unfold root_refines,
unfold check_single_reg0 at HEREF,
rw [← a_1, ← a_2] at HEREF,
unfold has_bind.bind at HEREF,
unfold option.bind at HEREF,
generalize HV: (irstate.getreg irsem_exec se root) = ov,
generalize HV': (irstate.getreg irsem_exec se' root) = ov',
rw [HV, HV'] at HEREF,
cases ov with v; cases ov' with v',
any_goals { unfold option.bind at HEREF, cases HEREF, done },
unfold option.bind at HEREF,
generalize HCV: check_val irsem_exec v v' = ocv,
rw HCV at HEREF,
cases ocv with cv,
any_goals { unfold option.bind at HEREF, cases HEREF, done },
unfold option.bind at HEREF,
injection HEREF with HEREF,
subst HCHKTT,
split,
{
generalize HUBSRC : irstate.getub irsem_exec se = ubsrc,
generalize HUBTGT : irstate.getub irsem_exec se' = ubtgt,
rw HUBSRC at HEREF,
rw HUBTGT at HEREF,
cases ubsrc,
{
apply ub_refines.ub,
rw HUBSRC, refl
},
{
apply ub_refines.noub, rw HUBSRC, refl,
cases ubtgt,
{ cases cv; cases HEREF },
{ rw HUBTGT, refl }
}
},
{
intros HUBTRUE,
existsi v, existsi v',
split, refl, split, refl,
apply check_val_exec_spec_prf,
rw HUBTRUE at HEREF,
cases (irstate.getub irsem_exec se'); cases cv,
any_goals { cases HEREF, done },
assumption
}
end
end spec |
ebb3444a21c76dc9a722fb792b6d5de2ea1f72d8 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/polynomial/coeff.lean | 4b0e61c61642a68cc5cdc924a37850a7963087e5 | [
"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 | 12,337 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.basic
import data.finset.nat_antidiagonal
import data.nat.choose.sum
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
noncomputable theory
open finsupp finset add_monoid_algebra
open_locale big_operators polynomial
namespace polynomial
universes u v
variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
variables [semiring R] {p q r : R[X]}
section coeff
lemma coeff_one (n : ℕ) : coeff (1 : R[X]) n = if 0 = n then 1 else 0 :=
coeff_monomial
@[simp]
lemma coeff_add (p q : R[X]) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n :=
by { rcases p, rcases q, simp_rw [←of_finsupp_add, coeff], exact finsupp.add_apply _ _ _ }
@[simp] lemma coeff_bit0 (p : R[X]) (n : ℕ) : coeff (bit0 p) n = bit0 (coeff p n) := by simp [bit0]
@[simp] lemma coeff_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) (n : ℕ) :
coeff (r • p) n = r • coeff p n :=
by { rcases p, simp_rw [←of_finsupp_smul, coeff], exact finsupp.smul_apply _ _ _ }
lemma support_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) :
support (r • p) ⊆ support p :=
begin
assume i hi,
simp [mem_support_iff] at hi ⊢,
contrapose! hi,
simp [hi]
end
/-- `polynomial.sum` as a linear map. -/
@[simps] def lsum {R A M : Type*} [semiring R] [semiring A] [add_comm_monoid M]
[module R A] [module R M] (f : ℕ → A →ₗ[R] M) :
A[X] →ₗ[R] M :=
{ to_fun := λ p, p.sum (λ n r, f n r),
map_add' := λ p q, sum_add_index p q _ (λ n, (f n).map_zero) (λ n _ _, (f n).map_add _ _),
map_smul' := λ c p,
begin
rw [sum_eq_of_subset _ (λ n r, f n r) (λ n, (f n).map_zero) _ (support_smul c p)],
simp only [sum_def, finset.smul_sum, coeff_smul, linear_map.map_smul, ring_hom.id_apply]
end }
variable (R)
/-- The nth coefficient, as a linear map. -/
def lcoeff (n : ℕ) : R[X] →ₗ[R] R :=
{ to_fun := λ p, coeff p n,
map_add' := λ p q, coeff_add p q n,
map_smul' := λ r p, coeff_smul r p n }
variable {R}
@[simp] lemma lcoeff_apply (n : ℕ) (f : R[X]) : lcoeff R n f = coeff f n := rfl
@[simp] lemma finset_sum_coeff {ι : Type*} (s : finset ι) (f : ι → R[X]) (n : ℕ) :
coeff (∑ b in s, f b) n = ∑ b in s, coeff (f b) n :=
(lcoeff R n).map_sum
lemma coeff_sum [semiring S] (n : ℕ) (f : ℕ → R → S[X]) :
coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) :=
by { rcases p, simp [polynomial.sum, support, coeff] }
/-- Decomposes the coefficient of the product `p * q` as a sum
over `nat.antidiagonal`. A version which sums over `range (n + 1)` can be obtained
by using `finset.nat.sum_antidiagonal_eq_sum_range_succ`. -/
lemma coeff_mul (p q : R[X]) (n : ℕ) :
coeff (p * q) n = ∑ x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 :=
begin
rcases p, rcases q,
simp_rw [←of_finsupp_mul, coeff],
exact add_monoid_algebra.mul_apply_antidiagonal p q n _ (λ x, nat.mem_antidiagonal)
end
@[simp] lemma mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 :=
by simp [coeff_mul]
-- TODO: golf using `constant_coeff` once #17664 is merged
lemma is_unit_C {x : R} : is_unit (C x) ↔ is_unit x :=
⟨by { rintros ⟨⟨q, p, hqp, hpq⟩, rfl : q = C x⟩,
exact ⟨⟨(C x).coeff 0, p.coeff 0, by rw [←mul_coeff_zero, hqp, coeff_one_zero],
by rw [←mul_coeff_zero, hpq, coeff_one_zero]⟩, coeff_C_zero⟩ }, is_unit.map C⟩
lemma coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp
lemma coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp
lemma coeff_C_mul_X_pow (x : R) (k n : ℕ) : coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 :=
by { rw [C_mul_X_pow_eq_monomial, coeff_monomial], congr' 1, simp [eq_comm] }
lemma coeff_C_mul_X (x : R) (n : ℕ) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 :=
by rw [← pow_one X, coeff_C_mul_X_pow]
@[simp] lemma coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n :=
begin
rcases p,
simp_rw [←monomial_zero_left, ←of_finsupp_single, ←of_finsupp_mul, coeff],
exact add_monoid_algebra.single_zero_mul_apply p a n
end
lemma C_mul' (a : R) (f : R[X]) : C a * f = a • f :=
by { ext, rw [coeff_C_mul, coeff_smul, smul_eq_mul] }
@[simp] lemma coeff_mul_C (p : R[X]) (n : ℕ) (a : R) :
coeff (p * C a) n = coeff p n * a :=
begin
rcases p,
simp_rw [←monomial_zero_left, ←of_finsupp_single, ←of_finsupp_mul, coeff],
exact add_monoid_algebra.mul_single_zero_apply p a n
end
lemma coeff_X_pow (k n : ℕ) :
coeff (X^k : R[X]) n = if n = k then 1 else 0 :=
by simp only [one_mul, ring_hom.map_one, ← coeff_C_mul_X_pow]
@[simp]
lemma coeff_X_pow_self (n : ℕ) :
coeff (X^n : R[X]) n = 1 :=
by simp [coeff_X_pow]
section fewnomials
open finset
lemma support_binomial {k m : ℕ} (hkm : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
(C x * X ^ k + C y * X ^ m).support = {k, m} :=
begin
apply subset_antisymm (support_binomial' k m x y),
simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm,
mul_zero, zero_add, add_zero, ne.def, hx, hy, and_self, not_false_iff],
end
lemma support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0)
(hy : y ≠ 0) (hz : z ≠ 0) : (C x * X ^ k + C y * X ^ m + C z * X ^ n).support = {k, m, n} :=
begin
apply subset_antisymm (support_trinomial' k m n x y z),
simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne,
if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne',
mul_zero, add_zero, zero_add, ne.def, hx, hy, hz, and_self, not_false_iff],
end
lemma card_support_binomial {k m : ℕ} (h : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
(C x * X ^ k + C y * X ^ m).support.card = 2 :=
by rw [support_binomial h hx hy, card_insert_of_not_mem (mt mem_singleton.mp h), card_singleton]
lemma card_support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0)
(hy : y ≠ 0) (hz : z ≠ 0) : (C x * X ^ k + C y * X ^ m + C z * X ^ n).support.card = 3 :=
by rw [support_trinomial hkm hmn hx hy hz, card_insert_of_not_mem
(mt mem_insert.mp (not_or hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))),
card_insert_of_not_mem (mt mem_singleton.mp hmn.ne), card_singleton]
end fewnomials
@[simp]
theorem coeff_mul_X_pow (p : R[X]) (n d : ℕ) :
coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=
begin
rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one],
{ rintros ⟨i,j⟩ h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,
rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },
{ exact λ h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }
end
@[simp]
theorem coeff_X_pow_mul (p : R[X]) (n d : ℕ) :
coeff (polynomial.X ^ n * p) (d + n) = coeff p d :=
by rw [(commute_X_pow p n).eq, coeff_mul_X_pow]
lemma coeff_mul_X_pow' (p : R[X]) (n d : ℕ) :
(p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 :=
begin
split_ifs,
{ rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] },
{ refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (λ x hx, _)),
rw [coeff_X_pow, if_neg, mul_zero],
exact ((le_of_add_le_right (finset.nat.mem_antidiagonal.mp hx).le).trans_lt $ not_le.mp h).ne }
end
lemma coeff_X_pow_mul' (p : R[X]) (n d : ℕ) :
(X ^ n * p).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 :=
by rw [(commute_X_pow p n).eq, coeff_mul_X_pow']
@[simp] theorem coeff_mul_X (p : R[X]) (n : ℕ) :
coeff (p * X) (n + 1) = coeff p n :=
by simpa only [pow_one] using coeff_mul_X_pow p 1 n
@[simp] theorem coeff_X_mul (p : R[X]) (n : ℕ) :
coeff (X * p) (n + 1) = coeff p n := by rw [(commute_X p).eq, coeff_mul_X]
theorem coeff_mul_monomial (p : R[X]) (n d : ℕ) (r : R) :
coeff (p * monomial n r) (d + n) = coeff p d * r :=
by rw [← C_mul_X_pow_eq_monomial, ←X_pow_mul, ←mul_assoc, coeff_mul_C, coeff_mul_X_pow]
theorem coeff_monomial_mul (p : R[X]) (n d : ℕ) (r : R) :
coeff (monomial n r * p) (d + n) = r * coeff p d :=
by rw [← C_mul_X_pow_eq_monomial, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow]
-- This can already be proved by `simp`.
theorem coeff_mul_monomial_zero (p : R[X]) (d : ℕ) (r : R) :
coeff (p * monomial 0 r) d = coeff p d * r :=
coeff_mul_monomial p 0 d r
-- This can already be proved by `simp`.
theorem coeff_monomial_zero_mul (p : R[X]) (d : ℕ) (r : R) :
coeff (monomial 0 r * p) d = r * coeff p d :=
coeff_monomial_mul p 0 d r
theorem mul_X_pow_eq_zero {p : R[X]} {n : ℕ}
(H : p * X ^ n = 0) : p = 0 :=
ext $ λ k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n)
lemma mul_X_pow_injective (n : ℕ) : function.injective (λ P : R[X], X ^ n * P) :=
begin
intros P Q hPQ,
simp only at hPQ,
ext i,
rw [← coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i]
end
lemma mul_X_injective : function.injective (λ P : R[X], X * P) :=
pow_one (X : R[X]) ▸ mul_X_pow_injective 1
lemma coeff_X_add_C_pow (r : R) (n k : ℕ) :
((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) :=
begin
rw [(commute_X (C r : R[X])).add_pow, ← lcoeff_apply, linear_map.map_sum],
simp only [one_pow, mul_one, lcoeff_apply, ← C_eq_nat_cast, ←C_pow, coeff_mul_C, nat.cast_id],
rw [finset.sum_eq_single k, coeff_X_pow_self, one_mul],
{ intros _ _ h,
simp [coeff_X_pow, h.symm] },
{ simp only [coeff_X_pow_self, one_mul, not_lt, finset.mem_range],
intro h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero] }
end
lemma coeff_X_add_one_pow (R : Type*) [semiring R] (n k : ℕ) :
((X + 1) ^ n).coeff k = (n.choose k : R) :=
by rw [←C_1, coeff_X_add_C_pow, one_pow, one_mul]
lemma coeff_one_add_X_pow (R : Type*) [semiring R] (n k : ℕ) :
((1 + X) ^ n).coeff k = (n.choose k : R) :=
by rw [add_comm _ X, coeff_X_add_one_pow]
lemma C_dvd_iff_dvd_coeff (r : R) (φ : R[X]) :
C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i :=
begin
split,
{ rintros ⟨φ, rfl⟩ c, rw coeff_C_mul, apply dvd_mul_right },
{ intro h,
choose c hc using h,
classical,
let c' : ℕ → R := λ i, if i ∈ φ.support then c i else 0,
let ψ : R[X] := ∑ i in φ.support, monomial i (c' i),
use ψ,
ext i,
simp only [ψ, c', coeff_C_mul, mem_support_iff, coeff_monomial,
finset_sum_coeff, finset.sum_ite_eq'],
split_ifs with hi hi,
{ rw hc },
{ rw [not_not] at hi, rwa mul_zero } },
end
lemma coeff_bit0_mul (P Q : R[X]) (n : ℕ) :
coeff (bit0 P * Q) n = 2 * coeff (P * Q) n :=
by simp [bit0, add_mul]
lemma coeff_bit1_mul (P Q : R[X]) (n : ℕ) :
coeff (bit1 P * Q) n = 2 * coeff (P * Q) n + coeff Q n :=
by simp [bit1, add_mul, coeff_bit0_mul]
lemma smul_eq_C_mul (a : R) : a • p = C a * p := by simp [ext_iff]
lemma update_eq_add_sub_coeff {R : Type*} [ring R] (p : R[X]) (n : ℕ) (a : R) :
p.update n a = p + (polynomial.C (a - p.coeff n) * polynomial.X ^ n) :=
begin
ext,
rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow],
split_ifs with h;
simp [h]
end
end coeff
section cast
@[simp] lemma nat_cast_coeff_zero {n : ℕ} {R : Type*} [semiring R] :
(n : R[X]).coeff 0 = n :=
begin
induction n with n ih,
{ simp, },
{ simp [ih], },
end
@[simp, norm_cast] theorem nat_cast_inj
{m n : ℕ} {R : Type*} [semiring R] [char_zero R] : (↑m : R[X]) = ↑n ↔ m = n :=
begin
fsplit,
{ intro h,
apply_fun (λ p, p.coeff 0) at h,
simpa using h, },
{ rintro rfl, refl, },
end
@[simp] lemma int_cast_coeff_zero {i : ℤ} {R : Type*} [ring R] :
(i : R[X]).coeff 0 = i :=
by cases i; simp
@[simp, norm_cast] theorem int_cast_inj
{m n : ℤ} {R : Type*} [ring R] [char_zero R] : (↑m : R[X]) = ↑n ↔ m = n :=
begin
fsplit,
{ intro h,
apply_fun (λ p, p.coeff 0) at h,
simpa using h, },
{ rintro rfl, refl, },
end
end cast
instance [char_zero R] : char_zero R[X] :=
{ cast_injective := λ x y, nat_cast_inj.mp }
end polynomial
|
ea3cfb19fca29b661df7266767a3a36a332563e9 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/discrete_category.lean | f3c0a1164336953b6b144bc3bfd4cc2de5e39c9c | [
"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,838 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import category_theory.eq_to_hom
import data.ulift
/-!
# Discrete categories
We define `discrete α` as a structure containing a term `a : α` for any type `α`,
and use this type alias to provide a `small_category` instance
whose only morphisms are the identities.
There is an annoying technical difficulty that it has turned out to be inconvenient
to allow categories with morphisms living in `Prop`,
so instead of defining `X ⟶ Y` in `discrete α` as `X = Y`,
one might define it as `plift (X = Y)`.
In fact, to allow `discrete α` to be a `small_category`
(i.e. with morphisms in the same universe as the objects),
we actually define the hom type `X ⟶ Y` as `ulift (plift (X = Y))`.
`discrete.functor` promotes a function `f : I → C` (for any category `C`) to a functor
`discrete.functor f : discrete I ⥤ C`.
Similarly, `discrete.nat_trans` and `discrete.nat_iso` promote `I`-indexed families of morphisms,
or `I`-indexed families of isomorphisms to natural transformations or natural isomorphism.
We show equivalences of types are the same as (categorical) equivalences of the corresponding
discrete categories.
-/
namespace category_theory
-- morphism levels before object levels. See note [category_theory universes].
universes v₁ v₂ v₃ u₁ u₁' u₂ u₃
/--
A wrapper for promoting any type to a category,
with the only morphisms being equalities.
-/
-- This is intentionally a structure rather than a type synonym
-- to enforce using `discrete_equiv` (or `discrete.mk` and `discrete.as`) to move between
-- `discrete α` and `α`. Otherwise there is too much API leakage.
@[ext] structure discrete (α : Type u₁) :=
(as : α)
@[simp] lemma discrete.mk_as {α : Type u₁} (X : discrete α) : discrete.mk X.as = X :=
by { ext, refl, }
/-- `discrete α` is equivalent to the original type `α`.-/
@[simps] def discrete_equiv {α : Type u₁} : discrete α ≃ α :=
{ to_fun := discrete.as,
inv_fun := discrete.mk,
left_inv := by tidy,
right_inv := by tidy, }
instance {α : Type u₁} [decidable_eq α] : decidable_eq (discrete α) :=
discrete_equiv.decidable_eq
/--
The "discrete" category on a type, whose morphisms are equalities.
Because we do not allow morphisms in `Prop` (only in `Type`),
somewhat annoyingly we have to define `X ⟶ Y` as `ulift (plift (X = Y))`.
See <https://stacks.math.columbia.edu/tag/001A>
-/
instance discrete_category (α : Type u₁) : small_category (discrete α) :=
{ hom := λ X Y, ulift (plift (X.as = Y.as)),
id := λ X, ulift.up (plift.up rfl),
comp := λ X Y Z g f, by { cases X, cases Y, cases Z, rcases f with ⟨⟨⟨⟩⟩⟩, exact g } }
namespace discrete
variables {α : Type u₁}
instance [inhabited α] : inhabited (discrete α) :=
⟨⟨default⟩⟩
instance [subsingleton α] : subsingleton (discrete α) :=
⟨by { intros, ext, apply subsingleton.elim, }⟩
/-- A simple tactic to run `cases` on any `discrete α` hypotheses. -/
meta def _root_.tactic.discrete_cases : tactic unit :=
`[cases_matching* [discrete _, (_ : discrete _) ⟶ (_ : discrete _), plift _]]
run_cmd add_interactive [``tactic.discrete_cases]
local attribute [tidy] tactic.discrete_cases
instance [unique α] : unique (discrete α) :=
unique.mk' (discrete α)
/-- Extract the equation from a morphism in a discrete category. -/
lemma eq_of_hom {X Y : discrete α} (i : X ⟶ Y) : X.as = Y.as := i.down.down
/-- Promote an equation between the wrapped terms in `X Y : discrete α` to a morphism `X ⟶ Y`
in the discrete category. -/
abbreviation eq_to_hom {X Y : discrete α} (h : X.as = Y.as) : X ⟶ Y :=
eq_to_hom (by { ext, exact h, })
/-- Promote an equation between the wrapped terms in `X Y : discrete α` to an isomorphism `X ≅ Y`
in the discrete category. -/
abbreviation eq_to_iso {X Y : discrete α} (h : X.as = Y.as) : X ≅ Y :=
eq_to_iso (by { ext, exact h, })
/-- A variant of `eq_to_hom` that lifts terms to the discrete category. -/
abbreviation eq_to_hom' {a b : α} (h : a = b) : discrete.mk a ⟶ discrete.mk b :=
eq_to_hom h
/-- A variant of `eq_to_iso` that lifts terms to the discrete category. -/
abbreviation eq_to_iso' {a b : α} (h : a = b) : discrete.mk a ≅ discrete.mk b :=
eq_to_iso h
@[simp] lemma id_def (X : discrete α) : ulift.up (plift.up (eq.refl X.as)) = 𝟙 X := rfl
variables {C : Type u₂} [category.{v₂} C]
instance {I : Type u₁} {i j : discrete I} (f : i ⟶ j) : is_iso f :=
⟨⟨eq_to_hom (eq_of_hom f).symm, by tidy⟩⟩
/--
Any function `I → C` gives a functor `discrete I ⥤ C`.
-/
def functor {I : Type u₁} (F : I → C) : discrete I ⥤ C :=
{ obj := F ∘ discrete.as,
map := λ X Y f, by { discrete_cases, cases f, exact 𝟙 (F X), } }
@[simp] lemma functor_obj {I : Type u₁} (F : I → C) (i : I) :
(discrete.functor F).obj (discrete.mk i) = F i := rfl
lemma functor_map {I : Type u₁} (F : I → C) {i : discrete I} (f : i ⟶ i) :
(discrete.functor F).map f = 𝟙 (F i.as) :=
by tidy
/--
The discrete functor induced by a composition of maps can be written as a
composition of two discrete functors.
-/
@[simps]
def functor_comp {I : Type u₁} {J : Type u₁'} (f : J → C) (g : I → J) :
discrete.functor (f ∘ g) ≅ discrete.functor (discrete.mk ∘ g) ⋙ discrete.functor f :=
nat_iso.of_components (λ X, iso.refl _) (by tidy)
/--
For functors out of a discrete category,
a natural transformation is just a collection of maps,
as the naturality squares are trivial.
-/
@[simps]
def nat_trans {I : Type u₁} {F G : discrete I ⥤ C}
(f : Π i : discrete I, F.obj i ⟶ G.obj i) : F ⟶ G :=
{ app := f,
naturality' := λ X Y g, by { discrete_cases, cases g, simp, } }
/--
For functors out of a discrete category,
a natural isomorphism is just a collection of isomorphisms,
as the naturality squares are trivial.
-/
@[simps]
def nat_iso {I : Type u₁} {F G : discrete I ⥤ C}
(f : Π i : discrete I, F.obj i ≅ G.obj i) : F ≅ G :=
nat_iso.of_components f (λ X Y g, by { discrete_cases, cases g, simp, })
@[simp]
lemma nat_iso_app {I : Type u₁} {F G : discrete I ⥤ C}
(f : Π i : discrete I, F.obj i ≅ G.obj i) (i : discrete I) :
(discrete.nat_iso f).app i = f i :=
by tidy
/-- Every functor `F` from a discrete category is naturally isomorphic (actually, equal) to
`discrete.functor (F.obj)`. -/
@[simp]
def nat_iso_functor {I : Type u₁} {F : discrete I ⥤ C} :
F ≅ discrete.functor (F.obj ∘ discrete.mk) :=
nat_iso $ λ i, by { discrete_cases, refl, }
/-- Composing `discrete.functor F` with another functor `G` amounts to composing `F` with `G.obj` -/
@[simp]
def comp_nat_iso_discrete {I : Type u₁} {D : Type u₃} [category.{v₃} D]
(F : I → C) (G : C ⥤ D) : discrete.functor F ⋙ G ≅ discrete.functor (G.obj ∘ F) :=
nat_iso $ λ i, iso.refl _
/--
We can promote a type-level `equiv` to
an equivalence between the corresponding `discrete` categories.
-/
@[simps]
def equivalence {I : Type u₁} {J : Type u₂} (e : I ≃ J) : discrete I ≌ discrete J :=
{ functor := discrete.functor (discrete.mk ∘ (e : I → J)),
inverse := discrete.functor (discrete.mk ∘ (e.symm : J → I)),
unit_iso := discrete.nat_iso (λ i, eq_to_iso (by { discrete_cases, simp })),
counit_iso := discrete.nat_iso (λ j, eq_to_iso (by { discrete_cases, simp })), }
/-- We can convert an equivalence of `discrete` categories to a type-level `equiv`. -/
@[simps]
def equiv_of_equivalence {α : Type u₁} {β : Type u₂} (h : discrete α ≌ discrete β) : α ≃ β :=
{ to_fun := discrete.as ∘ h.functor.obj ∘ discrete.mk,
inv_fun := discrete.as ∘ h.inverse.obj ∘ discrete.mk,
left_inv := λ a, by simpa using eq_of_hom (h.unit_iso.app (discrete.mk a)).2,
right_inv := λ a, by simpa using eq_of_hom (h.counit_iso.app (discrete.mk a)).1, }
end discrete
namespace discrete
variables {J : Type v₁}
open opposite
/-- A discrete category is equivalent to its opposite category. -/
@[simps functor_obj_as inverse_obj]
protected def opposite (α : Type u₁) : (discrete α)ᵒᵖ ≌ discrete α :=
let F : discrete α ⥤ (discrete α)ᵒᵖ := discrete.functor (λ x, op (discrete.mk x)) in
begin
refine equivalence.mk (functor.left_op F) F _
(discrete.nat_iso $ λ X, by { discrete_cases, simp [F] }),
refine nat_iso.of_components (λ X, by { tactic.op_induction', discrete_cases, simp [F], }) _,
tidy
end
variables {C : Type u₂} [category.{v₂} C]
@[simp] lemma functor_map_id
(F : discrete J ⥤ C) {j : discrete J} (f : j ⟶ j) : F.map f = 𝟙 (F.obj j) :=
begin
have h : f = 𝟙 j, { cases f, cases f, ext, },
rw h,
simp,
end
end discrete
end category_theory
|
316a864328c76da883bd7f5d5ecd522b877e2b69 | 8930e38ac0fae2e5e55c28d0577a8e44e2639a6d | /analysis/limits.lean | bf3ff057857ac81f32d74b20a86ac59f10554ead | [
"Apache-2.0"
] | permissive | SG4316/mathlib | 3d64035d02a97f8556ad9ff249a81a0a51a3321a | a7846022507b531a8ab53b8af8a91953fceafd3a | refs/heads/master | 1,584,869,960,527 | 1,530,718,645,000 | 1,530,724,110,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,026 | 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
A collection of limit properties.
-/
import algebra.big_operators algebra.group_power
analysis.real analysis.topology.infinite_sum
noncomputable theory
open classical finset function filter
local attribute [instance] prop_decidable
section real
lemma has_sum_of_absolute_convergence {f : ℕ → ℝ}
(hf : ∃r, tendsto (λn, (range n).sum (λi, abs (f i))) at_top (nhds r)) : has_sum f :=
let f' := λs:finset ℕ, s.sum (λi, abs (f i)) in
suffices cauchy (map (λs:finset ℕ, s.sum f) at_top),
from complete_space.complete this,
cauchy_iff.mpr $ and.intro (map_ne_bot at_top_ne_bot) $
assume s hs,
let ⟨ε, hε, hsε⟩ := mem_uniformity_dist.mp hs, ⟨r, hr⟩ := hf in
have hε' : {p : ℝ × ℝ | dist p.1 p.2 < ε / 2} ∈ (@uniformity ℝ _).sets,
from mem_uniformity_dist.mpr ⟨ε / 2, div_pos_of_pos_of_pos hε two_pos, assume a b h, h⟩,
have cauchy (at_top.map $ λn, f' (range n)),
from cauchy_downwards cauchy_nhds (map_ne_bot at_top_ne_bot) hr,
have ∃n, ∀{n'}, n ≤ n' → dist (f' (range n)) (f' (range n')) < ε / 2,
by simp [cauchy_iff, mem_at_top_sets] at this;
from let ⟨t, ⟨u, hu⟩, ht⟩ := this _ hε' in
⟨u, assume n' hn, ht $ set.prod_mk_mem_set_prod_eq.mpr ⟨hu _ (le_refl _), hu _ hn⟩⟩,
let ⟨n, hn⟩ := this in
have ∀{s}, range n ⊆ s → abs ((s \ range n).sum f) < ε / 2,
from assume s hs,
let ⟨n', hn'⟩ := @exists_nat_subset_range s in
have range n ⊆ range n', from finset.subset.trans hs hn',
have f'_nn : 0 ≤ f' (range n' \ range n), from zero_le_sum $ assume _ _, abs_nonneg _,
calc abs ((s \ range n).sum f) ≤ f' (s \ range n) : abs_sum_le_sum_abs
... ≤ f' (range n' \ range n) : sum_le_sum_of_subset_of_nonneg
(finset.sdiff_subset_sdiff hn' (finset.subset.refl _))
(assume _ _ _, abs_nonneg _)
... = abs (f' (range n' \ range n)) : (abs_of_nonneg f'_nn).symm
... = abs (f' (range n') - f' (range n)) :
by simp [f', (sum_sdiff ‹range n ⊆ range n'›).symm]
... = abs (f' (range n) - f' (range n')) : abs_sub _ _
... < ε / 2 : hn $ range_subset.mp this,
have ∀{s t}, range n ⊆ s → range n ⊆ t → dist (s.sum f) (t.sum f) < ε,
from assume s t hs ht,
calc abs (s.sum f - t.sum f) = abs ((s \ range n).sum f + - (t \ range n).sum f) :
by rw [←sum_sdiff hs, ←sum_sdiff ht]; simp
... ≤ abs ((s \ range n).sum f) + abs ((t \ range n).sum f) :
le_trans (abs_add_le_abs_add_abs _ _) $ by rw [abs_neg]; exact le_refl _
... < ε / 2 + ε / 2 : add_lt_add (this hs) (this ht)
... = ε : by rw [←add_div, add_self_div_two],
⟨(λs:finset ℕ, s.sum f) '' {s | range n ⊆ s}, image_mem_map $ mem_at_top (range n),
assume ⟨a, b⟩ ⟨⟨t, ht, ha⟩, ⟨s, hs, hb⟩⟩, by simp at ha hb; exact ha ▸ hb ▸ hsε (this ht hs)⟩
lemma is_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} {r : ℝ} (hf : ∀n, 0 ≤ f n) :
is_sum f r ↔ tendsto (λn, (range n).sum f) at_top (nhds r) :=
⟨tendsto_sum_nat_of_is_sum,
assume hr,
have tendsto (λn, (range n).sum (λn, abs (f n))) at_top (nhds r),
by simp [(λi, abs_of_nonneg (hf i)), hr],
let ⟨p, h⟩ := has_sum_of_absolute_convergence ⟨r, this⟩ in
have hp : tendsto (λn, (range n).sum f) at_top (nhds p), from tendsto_sum_nat_of_is_sum h,
have p = r, from tendsto_nhds_unique at_top_ne_bot hp hr,
this ▸ h⟩
end real
lemma mul_add_one_le_pow {r : ℝ} (hr : 0 ≤ r) : ∀{n:ℕ}, (n:ℝ) * r + 1 ≤ (r + 1) ^ n
| 0 := by simp; exact le_refl 1
| (n + 1) :=
let h : (n:ℝ) ≥ 0 := nat.cast_nonneg n in
calc ↑(n + 1) * r + 1 ≤ ((n + 1) * r + 1) + r * r * n :
le_add_of_le_of_nonneg (le_refl _) (mul_nonneg (mul_nonneg hr hr) h)
... = (r + 1) * (n * r + 1) : by simp [mul_add, add_mul, mul_comm, mul_assoc]
... ≤ (r + 1) * (r + 1) ^ n : mul_le_mul (le_refl _) mul_add_one_le_pow
(add_nonneg (mul_nonneg h hr) zero_le_one) (add_nonneg hr zero_le_one)
lemma tendsto_pow_at_top_at_top_of_gt_1 {r : ℝ} (h : r > 1) : tendsto (λn:ℕ, r ^ n) at_top at_top :=
tendsto_infi.2 $ assume p, tendsto_principal.2 $
let ⟨n, hn⟩ := exists_nat_gt (p / (r - 1)) in
have hn_nn : (0:ℝ) ≤ n, from nat.cast_nonneg n,
have r - 1 > 0, from sub_lt_iff_lt_add.mp $ by simp; assumption,
have p ≤ r ^ n,
from calc p = (p / (r - 1)) * (r - 1) : (div_mul_cancel _ $ ne_of_gt this).symm
... ≤ n * (r - 1) : mul_le_mul (le_of_lt hn) (le_refl _) (le_of_lt this) hn_nn
... ≤ n * (r - 1) + 1 : le_add_of_le_of_nonneg (le_refl _) zero_le_one
... ≤ ((r - 1) + 1) ^ n : mul_add_one_le_pow $ le_of_lt this
... ≤ r ^ n : by simp; exact le_refl _,
show {n | p ≤ r ^ n} ∈ at_top.sets,
from mem_at_top_sets.mpr ⟨n, assume m hnm, le_trans this (pow_le_pow (le_of_lt h) hnm)⟩
lemma tendsto_inverse_at_top_nhds_0 : tendsto (λr:ℝ, r⁻¹) at_top (nhds 0) :=
tendsto_orderable_unbounded (no_top 0) (no_bot 0) $ assume l u hl hu,
mem_at_top_sets.mpr ⟨u⁻¹ + 1, assume b hb,
have u⁻¹ < b, from lt_of_lt_of_le (lt_add_of_pos_right _ zero_lt_one) hb,
⟨lt_trans hl $ inv_pos $ lt_trans (inv_pos hu) this,
lt_of_one_div_lt_one_div hu $
begin
rw [inv_eq_one_div],
simp [-one_div_eq_inv, div_div_eq_mul_div, div_one],
simp [this]
end⟩⟩
lemma map_succ_at_top_eq : map nat.succ at_top = at_top :=
le_antisymm
(assume s hs,
let ⟨b, hb⟩ := mem_at_top_sets.mp hs in
mem_at_top_sets.mpr ⟨b, assume c hc, hb (c + 1) $ le_trans hc $ nat.le_succ _⟩)
(assume s hs,
let ⟨b, hb⟩ := mem_at_top_sets.mp hs in
mem_at_top_sets.mpr ⟨b + 1, assume c,
match c with
| 0 := assume h,
have 0 > 0, from lt_of_lt_of_le (lt_add_of_le_of_pos (nat.zero_le _) zero_lt_one) h,
(lt_irrefl 0 this).elim
| (c+1) := assume h, hb _ (nat.le_of_succ_le_succ h)
end⟩)
lemma tendsto_comp_succ_at_top_iff {α : Type*} {f : ℕ → α} {x : filter α} :
tendsto (λn, f (nat.succ n)) at_top x ↔ tendsto f at_top x :=
calc tendsto (f ∘ nat.succ) at_top x ↔ tendsto f (map nat.succ at_top) x : by simp [tendsto, filter.map_map]
... ↔ _ : by rw [map_succ_at_top_eq]
lemma tendsto_pow_at_top_nhds_0_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
tendsto (λn:ℕ, r^n) at_top (nhds 0) :=
by_cases
(assume : r = 0, tendsto_comp_succ_at_top_iff.mp $ by simp [pow_succ, this, tendsto_const_nhds])
(assume : r ≠ 0,
have tendsto (λn, (r⁻¹ ^ n)⁻¹) at_top (nhds 0),
from (tendsto_pow_at_top_at_top_of_gt_1 $ one_lt_inv (lt_of_le_of_ne h₁ this.symm) h₂).comp
tendsto_inverse_at_top_nhds_0,
tendsto_cong this $ univ_mem_sets' $ by simp *)
lemma sum_geometric' {r : ℝ} (h : r ≠ 0) :
∀{n}, (finset.range n).sum (λi, (r + 1) ^ i) = ((r + 1) ^ n - 1) / r
| 0 := by simp [zero_div]
| (n+1) :=
by simp [@sum_geometric' n, h, pow_succ, add_div_eq_mul_add_div, add_mul, mul_comm, mul_assoc]
lemma sum_geometric {r : ℝ} {n : ℕ} (h : r ≠ 1) :
(range n).sum (λi, r ^ i) = (r ^ n - 1) / (r - 1) :=
calc (range n).sum (λi, r ^ i) = (range n).sum (λi, ((r - 1) + 1) ^ i) :
by simp
... = (((r - 1) + 1) ^ n - 1) / (r - 1) :
sum_geometric' $ by simp [sub_eq_iff_eq_add, -sub_eq_add_neg, h]
... = (r ^ n - 1) / (r - 1) :
by simp
lemma is_sum_geometric {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
is_sum (λn:ℕ, r ^ n) (1 / (1 - r)) :=
have r ≠ 1, from ne_of_lt h₂,
have r + -1 ≠ 0,
by rw [←sub_eq_add_neg, ne, sub_eq_iff_eq_add]; simp; assumption,
have tendsto (λn, (r ^ n - 1) * (r - 1)⁻¹) at_top (nhds ((0 - 1) * (r - 1)⁻¹)),
from tendsto_mul
(tendsto_sub (tendsto_pow_at_top_nhds_0_of_lt_1 h₁ h₂) tendsto_const_nhds) tendsto_const_nhds,
(is_sum_iff_tendsto_nat_of_nonneg $ pow_nonneg h₁).mpr $
by simp [neg_inv, sum_geometric, div_eq_mul_inv, *] at *
|
9eefe12536f89583a728bea56539a8f8d8ac0e35 | 853df553b1d6ca524e3f0a79aedd32dde5d27ec3 | /src/order/directed.lean | 6e022318462868d5695ff1436f9fd61ae80bea96 | [
"Apache-2.0"
] | permissive | DanielFabian/mathlib | efc3a50b5dde303c59eeb6353ef4c35a345d7112 | f520d07eba0c852e96fe26da71d85bf6d40fcc2a | refs/heads/master | 1,668,739,922,971 | 1,595,201,756,000 | 1,595,201,756,000 | 279,469,476 | 0 | 0 | null | 1,594,696,604,000 | 1,594,696,604,000 | null | UTF-8 | Lean | false | false | 2,832 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
-/
import order.lattice
import data.set.basic
universes u v w
variables {α : Type u} {β : Type v} {ι : Sort w} (r : α → α → Prop)
local infix ` ≼ ` : 50 := r
/-- A family of elements of α is directed (with respect to a relation `≼` on α)
if there is a member of the family `≼`-above any pair in the family. -/
def directed (f : ι → α) := ∀x y, ∃z, f x ≼ f z ∧ f y ≼ f z
/-- A subset of α is directed if there is an element of the set `≼`-above any
pair of elements in the set. -/
def directed_on (s : set α) := ∀ (x ∈ s) (y ∈ s), ∃z ∈ s, x ≼ z ∧ y ≼ z
theorem directed_on_iff_directed {s} : @directed_on α r s ↔ directed r (coe : s → α) :=
by simp [directed, directed_on]; refine ball_congr (λ x hx, by simp; refl)
theorem directed_on_image {s} {f : β → α} :
directed_on r (f '' s) ↔ directed_on (f ⁻¹'o r) s :=
by simp only [directed_on, set.ball_image_iff, set.bex_image_iff, order.preimage]
theorem directed_on.mono {s : set α} (h : directed_on r s)
{r' : α → α → Prop} (H : ∀ {a b}, r a b → r' a b) :
directed_on r' s :=
λ x hx y hy, let ⟨z, zs, xz, yz⟩ := h x hx y hy in ⟨z, zs, H xz, H yz⟩
theorem directed_comp {ι} (f : ι → β) (g : β → α) :
directed r (g ∘ f) ↔ directed (g ⁻¹'o r) f := iff.rfl
variable {r}
theorem directed.mono {s : α → α → Prop} {ι} {f : ι → α}
(H : ∀ a b, r a b → s a b) (h : directed r f) : directed s f :=
λ a b, let ⟨c, h₁, h₂⟩ := h a b in ⟨c, H _ _ h₁, H _ _ h₂⟩
theorem directed.mono_comp {ι} {rb : β → β → Prop} {g : α → β} {f : ι → α}
(hg : ∀ ⦃x y⦄, x ≼ y → rb (g x) (g y)) (hf : directed r f) :
directed rb (g ∘ f) :=
(directed_comp rb f g).2 $ hf.mono hg
/-- A monotone function on a sup-semilattice is directed. -/
lemma directed_of_sup [semilattice_sup α] {f : α → β} {r : β → β → Prop}
(H : ∀ ⦃i j⦄, i ≤ j → r (f i) (f j)) : directed r f :=
λ a b, ⟨a ⊔ b, H le_sup_left, H le_sup_right⟩
/-- An antimonotone function on an inf-semilattice is directed. -/
lemma directed_of_inf [semilattice_inf α] {r : β → β → Prop} {f : α → β}
(hf : ∀a₁ a₂, a₁ ≤ a₂ → r (f a₂) (f a₁)) : directed r f :=
assume x y, ⟨x ⊓ y, hf _ _ inf_le_left, hf _ _ inf_le_right⟩
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A `preorder` is a `directed_order` if for any two elements `i`, `j`
there is an element `k` such that `i ≤ k` and `j ≤ k`. -/
class directed_order (α : Type u) extends preorder α :=
(directed : ∀ i j : α, ∃ k, i ≤ k ∧ j ≤ k)
end prio
|
95c912a660503c08df74ff965fd2b5e30c3e8aff | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/measure_theory/tactic.lean | 195407aa7b0eec36d73f6133929ca980ab1353a0 | [
"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 | 6,765 | lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import measure_theory.measure.measure_space_def
import tactic.auto_cases
import tactic.tidy
import tactic.with_local_reducibility
/-!
# Tactics for measure theory
Currently we have one domain-specific tactic for measure theory: `measurability`.
This tactic is to a large extent a copy of the `continuity` tactic by Reid Barton.
-/
/-!
### `measurability` tactic
Automatically solve goals of the form `measurable f`, `ae_measurable f μ` and `measurable_set s`.
Mark lemmas with `@[measurability]` to add them to the set of lemmas
used by `measurability`. Note: `to_additive` doesn't know yet how to
copy the attribute to the additive version.
-/
/-- User attribute used to mark tactics used by `measurability`. -/
@[user_attribute]
meta def measurability : user_attribute :=
{ name := `measurability,
descr := "lemmas usable to prove (ae)-measurability" }
/- Mark some measurability lemmas already defined in `measure_theory.measurable_space_def` and
`measure_theory.measure_space_def` -/
attribute [measurability]
measurable_id
measurable_id'
ae_measurable_id
ae_measurable_id'
measurable_const
ae_measurable_const
ae_measurable.measurable_mk
measurable_set.empty
measurable_set.univ
measurable_set.compl
subsingleton.measurable_set
measurable_set.Union
measurable_set.Inter
measurable_set.Union_Prop
measurable_set.Inter_Prop
measurable_set.union
measurable_set.inter
measurable_set.diff
measurable_set.symm_diff
measurable_set.ite
measurable_set.cond
measurable_set.disjointed
measurable_set.const
measurable_set.insert
measurable_set_eq
finset.measurable_set
measurable_space.measurable_set_top
namespace tactic
/--
Tactic to apply `measurable.comp` when appropriate.
Applying `measurable.comp` is not always a good idea, so we have some
extra logic here to try to avoid bad cases.
* If the function we're trying to prove measurable is actually
constant, and that constant is a function application `f z`, then
measurable.comp would produce new goals `measurable f`, `measurable
(λ _, z)`, which is silly. We avoid this by failing if we could
apply `measurable_const`.
* measurable.comp will always succeed on `measurable (λ x, f x)` and
produce new goals `measurable (λ x, x)`, `measurable f`. We detect
this by failing if a new goal can be closed by applying
measurable_id.
-/
meta def apply_measurable.comp : tactic unit :=
`[fail_if_success { exact measurable_const };
refine measurable.comp _ _;
fail_if_success { exact measurable_id }]
/--
Tactic to apply `measurable.comp_ae_measurable` when appropriate.
Applying `measurable.comp_ae_measurable` is not always a good idea, so we have some
extra logic here to try to avoid bad cases.
* If the function we're trying to prove measurable is actually
constant, and that constant is a function application `f z`, then
`measurable.comp_ae_measurable` would produce new goals `measurable f`, `ae_measurable
(λ _, z) μ`, which is silly. We avoid this by failing if we could
apply `ae_measurable_const`.
* `measurable.comp_ae_measurable` will always succeed on `ae_measurable (λ x, f x) μ` and
can produce new goals (`measurable (λ x, x)`, `ae_measurable f μ`) or
(`measurable f`, `ae_measurable (λ x, x) μ`). We detect those by failing if a new goal can be
closed by applying `measurable_id` or `ae_measurable_id`.
-/
meta def apply_measurable.comp_ae_measurable : tactic unit :=
`[fail_if_success { exact ae_measurable_const };
refine measurable.comp_ae_measurable _ _;
fail_if_success { exact measurable_id };
fail_if_success { exact ae_measurable_id }]
/--
We don't want the intro1 tactic to apply to a goal of the form `measurable f`, `ae_measurable f μ`
or `measurable_set s`. This tactic tests the target to see if it matches that form.
-/
meta def goal_is_not_measurable : tactic unit :=
do t ← tactic.target,
match t with
| `(measurable %%l) := failed
| `(ae_measurable %%l %%r) := failed
| `(measurable_set %%l) := failed
| _ := skip
end
/-- List of tactics used by `measurability` internally. The option `use_exfalso := ff` is passed to
the tactic `apply_assumption` in order to avoid loops in the presence of negated hypotheses in
the context. -/
meta def measurability_tactics (md : transparency := semireducible) : list (tactic string) :=
[
propositional_goal >> tactic.interactive.apply_assumption none {use_exfalso := ff}
>> pure "apply_assumption {use_exfalso := ff}",
goal_is_not_measurable >> intro1
>>= λ ns, pure ("intro " ++ ns.to_string),
apply_rules [] [``measurability] 50 { md := md }
>> pure "apply_rules with measurability",
apply_measurable.comp >> pure "refine measurable.comp _ _",
apply_measurable.comp_ae_measurable
>> pure "refine measurable.comp_ae_measurable _ _",
`[ refine measurable.ae_measurable _ ]
>> pure "refine measurable.ae_measurable _",
`[ refine measurable.ae_strongly_measurable _ ]
>> pure "refine measurable.ae_strongly_measurable _"
]
namespace interactive
setup_tactic_parser
/--
Solve goals of the form `measurable f`, `ae_measurable f μ`, `ae_strongly_measurable f μ` or
`measurable_set s`. `measurability?` reports back the proof term it found.
-/
meta def measurability
(bang : parse $ optional (tk "!")) (trace : parse $ optional (tk "?")) (cfg : tidy.cfg := {}) :
tactic unit :=
let md := if bang.is_some then semireducible else reducible,
measurability_core := tactic.tidy { tactics := measurability_tactics md, ..cfg },
trace_fn := if trace.is_some then show_term else id in
trace_fn measurability_core
/-- Version of `measurability` for use with auto_param. -/
meta def measurability' : tactic unit := measurability none none {}
/--
`measurability` solves goals of the form `measurable f`, `ae_measurable f μ`,
`ae_strongly_measurable f μ` or `measurable_set s` by applying lemmas tagged with the
`measurability` user attribute.
You can also use `measurability!`, which applies lemmas with `{ md := semireducible }`.
The default behaviour is more conservative, and only unfolds `reducible` definitions
when attempting to match lemmas with the goal.
`measurability?` reports back the proof term it found.
-/
add_tactic_doc
{ name := "measurability / measurability'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.measurability, `tactic.interactive.measurability'],
tags := ["lemma application"] }
end interactive
end tactic
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.