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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5070c9a074b5dc1c5430044ba25fac4945bb5b87
|
5d76f062116fa5bd22eda20d6fd74da58dba65bb
|
/src/snarks/groth16/knowledge_soundness.lean
|
fc6e97199c8d4c92422ab4171a8bf7976c7caa93
|
[] |
no_license
|
brando90/formal_baby_snark
|
59e4732dfb43f97776a3643f2731262f58d2bb81
|
4732da237784bd461ff949729cc011db83917907
|
refs/heads/master
| 1,682,650,246,414
| 1,621,103,975,000
| 1,621,103,975,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,782
|
lean
|
/-
Author: Bolton Bailey
-/
import data.mv_polynomial.basic
import data.polynomial.div
import data.polynomial.field_division
import algebra.polynomial.big_operators
-- import .general_lemmas.polynomial_mv_sv_cast
-- import .general_lemmas.mv_divisability
-- import .general_lemmas.single_antidiagonal
-- import .general_lemmas.polynomial_smul_eq_C_mul
import .vars
/-!
# Knowledge Soundness
This file proves the knowledge-soundness property of the
[Groth16](https://eprint.iacr.org/2016/260.pdf) system.
Specifically, we prove this property for the NILP system
described in section 3.1 of that paper.
Furthermore, we carry out the reduction to non-laurent polynomials by multiplying through the CRS with γδ.
We choose r,s to be 0, todo, allow other values
-/
open_locale big_operators
section
open mv_polynomial
noncomputable theory
universes u
/-- The finite field parameter of our SNARK -/
parameter {F : Type u}
parameter [field F]
/-- The naturals representing:
n_stmt - the statement size,
n_wit - the witness size -/
parameters {n_stmt n_wit n : ℕ}
def l : ℕ := n_stmt
def m : ℕ := n_wit
-- NOTE: In the paper, n_stmt is l and n_wit is n-l. Here, n is defined from these values.
/-- u_stmt and u_wit are fin-indexed collections of polynomials from the square span program -/
parameter {u_stmt : fin n_stmt → (polynomial F) }
parameter {u_wit : fin n_wit → (polynomial F) }
parameter {v_stmt : fin n_stmt → (polynomial F) }
parameter {v_wit : fin n_wit → (polynomial F) }
parameter {w_stmt : fin n_stmt → (polynomial F) }
parameter {w_wit : fin n_wit → (polynomial F) }
/-- The roots of the polynomial t -/
parameter {r : fin m → F}
/-- t is the polynomial divisibility by which is used to verify satisfaction of the SSP -/
def t : polynomial F := ∏ i in (finset.fin_range m), (polynomial.X - polynomial.C (r i))
-- TODO this and the following lemmas about this could potentially be spun off
-- make a `monic_from_roots` function for mathlib
/-- t has degree m -/
lemma nat_degree_t : t.nat_degree = m
:=
begin
-- rw polynomial.nat_degree,
rw t,
rw polynomial.nat_degree_prod,
simp,
intros i hi,
exact polynomial.X_sub_C_ne_zero (r i),
end
lemma monic_t : t.monic
:=
begin
rw t,
apply polynomial.monic_prod_of_monic,
intros i hi,
exact polynomial.monic_X_sub_C (r i),
end
lemma degree_t_pos : 0 < m → 0 < t.degree
:=
begin
intro hm,
suffices h : t.degree = some m,
rw h,
apply with_bot.some_lt_some.2,
exact hm,
have h := nat_degree_t,
rw polynomial.nat_degree at h,
induction h1 : t.degree,
rw h1 at h,
rw option.get_or_else at h,
rw h at hm,
have h2 := has_lt.lt.false hm,
exfalso,
exact h2,
rw h1 at h,
rw option.get_or_else at h,
rw h,
end
-- Single variable form of V_wit
def V_wit_sv (a_wit : fin n_wit → F) : polynomial F
:= ∑ i in finset.fin_range n_wit, a_wit i • u_wit i
/-- The statement polynomial that the verifier computes from the statement bits, as a single variable polynomial -/
def V_stmt_sv (a_stmt : fin n_stmt → F) : polynomial F
:= ∑ i in (finset.fin_range n_stmt), a_stmt i • u_stmt i
/-- Checks whether a statement witness pair satisfies the SSP -/
def satisfying (a_stmt : fin n_stmt → F ) (a_wit : fin n_wit → F) :=
(∑ i in (finset.fin_range n_stmt), a_stmt i • u_stmt i
+ (∑ i in (finset.fin_range n_wit), a_wit i • u_wit i))
*
(∑ i in (finset.fin_range n_stmt), a_stmt i • v_stmt i
+ (∑ i in (finset.fin_range n_wit), a_wit i • v_wit i))
-
(∑ i in (finset.fin_range n_stmt), a_stmt i • w_stmt i
+ (∑ i in (finset.fin_range n_wit), a_wit i • w_wit i))
%ₘ t = 0
/- Multivariable polynomial definititons and ultilities -/
/-- Helper for converting mv_polynomial to single -/
@[simp]
def singlify : vars -> polynomial F
| vars.x := polynomial.X
| vars.α := 1
| vars.β := 1
| vars.γ := 1
| vars.δ := 1
/-- Multivariable version of t -/
def t_mv : mv_polynomial vars F := t.eval₂ mv_polynomial.C (X vars.x)
/-- V_stmt as a multivariable polynomial of vars.X -/
def V_stmt_mv (a_stmt : fin n_stmt → F) : mv_polynomial vars F
:= (V_stmt_sv a_stmt).eval₂ mv_polynomial.C (X vars.x)
run_cmd mk_simp_attr `crs
run_cmd tactic.add_doc_string `simp_attr.crs "Attribute for defintions of CRS elements"
/-- The crs elements as multivariate polynomials of the toxic waste samples -/
@[crs]
def crs_α : mv_polynomial vars F := X vars.α * X vars.γ * X vars.δ
@[crs]
def crs_β : mv_polynomial vars F := X vars.β * X vars.γ * X vars.δ
@[crs]
def crs_γ : mv_polynomial vars F := X vars.γ * X vars.γ * X vars.δ
@[crs]
def crs_δ : mv_polynomial vars F := X vars.δ * X vars.γ * X vars.δ
@[crs]
def crs_powers_of_x (i : fin m) : (mv_polynomial vars F) := (X vars.x)^(i : ℕ) * X vars.γ * X vars.δ
-- I define prodcuts of these crs elements without the division, then later claim identities. Is this right?
@[crs]
def crs_l (i : fin n_stmt) : (mv_polynomial vars F) :=
((X vars.β * X vars.δ) * (u_stmt i).eval₂ mv_polynomial.C (X vars.x)
+
(X vars.α * X vars.δ) * (v_stmt i).eval₂ mv_polynomial.C (X vars.x)
+
X vars.δ * (w_stmt i).eval₂ mv_polynomial.C (X vars.x))
@[crs]
def crs_m (i : fin n_wit) : (mv_polynomial vars F) :=
((X vars.β * X vars.γ) * (u_wit i).eval₂ mv_polynomial.C (X vars.x)
+
(X vars.α * X vars.γ) * (v_wit i).eval₂ mv_polynomial.C (X vars.x)
+
X vars.γ * (w_wit i).eval₂ mv_polynomial.C (X vars.x))
@[crs]
def crs_n (i : fin n) : (mv_polynomial vars F) :=
X vars.γ * (X vars.x)^(i : ℕ) * t.eval₂ mv_polynomial.C (X vars.x)
-- parameter crs_1 (i : fin n_stmt) : (mv_polynomial vars F)
-- parameter crs_2 (i : fin n_wit) : (mv_polynomial vars F)
-- parameter crs_t (i : fin m) : (mv_polynomial vars F)
/-- The coefficients of the CRS elements in the algebraic adversary's representation -/
parameters {a a' a'' a''' b b' b'' b''' c c' c'' c''' : F}
parameters {a1 b1 c1 : fin n_stmt → F}
parameters {a2 b2 c2 : fin n_wit → F}
parameters {a3 b3 c3 : fin n → F}
/-- Polynomial forms of the adversary's proof representation -/
def A : mv_polynomial vars F :=
a • crs_α
+
a' • crs_β
+
a'' • crs_γ
+
a''' • crs_δ
+
∑ i in (finset.fin_range n_stmt), (a1 i) • (crs_l i)
+
∑ i in (finset.fin_range n_wit), (a2 i) • (crs_m i)
+
∑ i in (finset.fin_range n), (a3 i) • (crs_n i)
def B : mv_polynomial vars F :=
a • crs_α
+
a' • crs_β
+
a'' • crs_γ
+
a''' • crs_δ
+
∑ i in (finset.fin_range n_stmt), (a1 i) • (crs_l i)
+
∑ i in (finset.fin_range n_wit), (a2 i) • (crs_m i)
+
∑ i in (finset.fin_range n), (a3 i) • (crs_n i)
def C : mv_polynomial vars F :=
a • crs_α
+
a' • crs_β
+
a'' • crs_γ
+
a''' • crs_δ
+
∑ i in (finset.fin_range n_stmt), (a1 i) • (crs_l i)
+
∑ i in (finset.fin_range n_wit), (a2 i) • (crs_m i)
+
∑ i in (finset.fin_range n), (a3 i) • (crs_n i)
/-- Show that if the adversary polynomials obey the equations,
then the coefficients give a satisfying witness.
TODO is b2 right here? Perhaps it should be replaced by some other function of the a2 b2 c2 or other coefficients -/
theorem case_1 (a_stmt : fin n_stmt → F ) :
(0 < m)
-- -> ∀ i, crs_1_γ i = crs_1 i * crs_γ
-- -> ∀ i, crs_2_δ i = crs_2 i * crs_δ
-- -> ∀ i, crs_t_δ i = crs_t i * crs_δ
-> A * B = crs_α * crs_β + (∑ i in finset.fin_range n_stmt, a_stmt i • crs_l i ) * crs_γ + C * crs_δ
-> (satisfying a_stmt c2) -- This shows that (a`+1, . . . , am) = (C`+1, . . . , Cm) is a witness for the statement (a1, . . . , a`)
:=
begin
intros hm eqn,
rw [A, B, C] at eqn,
simp only with crs at eqn,
end
end
|
cdf44a71c13969e541d50f6f2cfe035d7e6a2206
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/linear_algebra/matrix/trace.lean
|
cb643c06ff73516bae15efd2d6d94e0ec9e6e9a3
|
[
"Apache-2.0"
] |
permissive
|
jjgarzella/mathlib
|
96a345378c4e0bf26cf604aed84f90329e4896a2
|
395d8716c3ad03747059d482090e2bb97db612c8
|
refs/heads/master
| 1,686,480,124,379
| 1,625,163,323,000
| 1,625,163,323,000
| 281,190,421
| 2
| 0
|
Apache-2.0
| 1,595,268,170,000
| 1,595,268,169,000
| null |
UTF-8
|
Lean
| false
| false
| 2,334
|
lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import data.matrix.basic
/-!
# Trace of a matrix
This file defines the trace of a matrix, the linear map
sending a matrix to the sum of its diagonal entries.
See also `linear_algebra.trace` for the trace of an endomorphism.
## Tags
matrix, trace, diagonal
-/
open_locale big_operators
open_locale matrix
namespace matrix
section trace
universes u v w
variables {m : Type*} [fintype m] (n : Type*) [fintype n]
variables (R : Type*) (M : Type*) [semiring R] [add_comm_monoid M] [module R M]
/--
The diagonal of a square matrix.
-/
def diag : (matrix n n M) →ₗ[R] n → M :=
{ to_fun := λ A i, A i i,
map_add' := by { intros, ext, refl, },
map_smul' := by { intros, ext, refl, } }
variables {n} {R} {M}
@[simp] lemma diag_apply (A : matrix n n M) (i : n) : diag n R M A i = A i i := rfl
@[simp] lemma diag_one [decidable_eq n] :
diag n R R 1 = λ i, 1 := by { dunfold diag, ext, simp [one_apply_eq] }
@[simp] lemma diag_transpose (A : matrix n n M) : diag n R M Aᵀ = diag n R M A := rfl
variables (n) (R) (M)
/--
The trace of a square matrix.
-/
def trace : (matrix n n M) →ₗ[R] M :=
{ to_fun := λ A, ∑ i, diag n R M A i,
map_add' := by { intros, apply finset.sum_add_distrib, },
map_smul' := by { intros, simp [finset.smul_sum], } }
variables {n} {R} {M}
@[simp] lemma trace_diag (A : matrix n n M) : trace n R M A = ∑ i, diag n R M A i := rfl
lemma trace_apply (A : matrix n n M) : trace n R M A = ∑ i, A i i := rfl
@[simp] lemma trace_one [decidable_eq n] :
trace n R R 1 = fintype.card n :=
have h : trace n R R 1 = ∑ i, diag n R R 1 i := rfl,
by simp_rw [h, diag_one, finset.sum_const, nsmul_one]; refl
@[simp] lemma trace_transpose (A : matrix n n M) : trace n R M Aᵀ = trace n R M A := rfl
@[simp] lemma trace_transpose_mul (A : matrix m n R) (B : matrix n m R) :
trace n R R (Aᵀ ⬝ Bᵀ) = trace m R R (A ⬝ B) := finset.sum_comm
lemma trace_mul_comm {S : Type v} [comm_ring S] (A : matrix m n S) (B : matrix n m S) :
trace n S S (B ⬝ A) = trace m S S (A ⬝ B) :=
by rw [←trace_transpose, ←trace_transpose_mul, transpose_mul]
end trace
end matrix
|
dcceed53517d7b2d111a2bb88ad184af6727750c
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/logic/equiv/functor.lean
|
35b625f2b8f3550317db21bb9979b80bbf7ffd91
|
[
"Apache-2.0"
] |
permissive
|
alreadydone/mathlib
|
dc0be621c6c8208c581f5170a8216c5ba6721927
|
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
|
refs/heads/master
| 1,685,523,275,196
| 1,670,184,141,000
| 1,670,184,141,000
| 287,574,545
| 0
| 0
|
Apache-2.0
| 1,670,290,714,000
| 1,597,421,623,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,301
|
lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Simon Hudon, Scott Morrison
-/
import control.bifunctor
import logic.equiv.defs
/-!
# Functor and bifunctors can be applied to `equiv`s.
We define
```lean
def functor.map_equiv (f : Type u → Type v) [functor f] [is_lawful_functor f] :
α ≃ β → f α ≃ f β
```
and
```lean
def bifunctor.map_equiv (F : Type u → Type v → Type w) [bifunctor F] [is_lawful_bifunctor F] :
α ≃ β → α' ≃ β' → F α α' ≃ F β β'
```
-/
universes u v w
variables {α β : Type u}
open equiv
namespace functor
variables (f : Type u → Type v) [functor f] [is_lawful_functor f]
/-- Apply a functor to an `equiv`. -/
def map_equiv (h : α ≃ β) : f α ≃ f β :=
{ to_fun := map h,
inv_fun := map h.symm,
left_inv := λ x, by simp [map_map],
right_inv := λ x, by simp [map_map] }
@[simp]
lemma map_equiv_apply (h : α ≃ β) (x : f α) :
(map_equiv f h : f α ≃ f β) x = map h x := rfl
@[simp]
lemma map_equiv_symm_apply (h : α ≃ β) (y : f β) :
(map_equiv f h : f α ≃ f β).symm y = map h.symm y := rfl
@[simp]
lemma map_equiv_refl : map_equiv f (equiv.refl α) = equiv.refl (f α) :=
begin
ext x,
simp only [map_equiv_apply, refl_apply],
exact is_lawful_functor.id_map x,
end
end functor
namespace bifunctor
variables {α' β' : Type v} (F : Type u → Type v → Type w) [bifunctor F] [is_lawful_bifunctor F]
/-- Apply a bifunctor to a pair of `equiv`s. -/
def map_equiv (h : α ≃ β) (h' : α' ≃ β') : F α α' ≃ F β β' :=
{ to_fun := bimap h h',
inv_fun := bimap h.symm h'.symm,
left_inv := λ x, by simp [bimap_bimap, id_bimap],
right_inv := λ x, by simp [bimap_bimap, id_bimap] }
@[simp]
lemma map_equiv_apply (h : α ≃ β) (h' : α' ≃ β') (x : F α α') :
(map_equiv F h h' : F α α' ≃ F β β') x = bimap h h' x := rfl
@[simp]
lemma map_equiv_symm_apply (h : α ≃ β) (h' : α' ≃ β') (y : F β β') :
(map_equiv F h h' : F α α' ≃ F β β').symm y = bimap h.symm h'.symm y := rfl
@[simp]
lemma map_equiv_refl_refl : map_equiv F (equiv.refl α) (equiv.refl α') = equiv.refl (F α α') :=
begin
ext x,
simp [id_bimap]
end
end bifunctor
|
24feb8cc109275eb9801c5cbf87948866d1ed5ff
|
21871395eaf77834250a3f1b20624be105ae17be
|
/two_adj.lean
|
0650eafab93498136be3b8b9c803e9faf8f2cd12
|
[] |
no_license
|
daniel-carranza/2-adj-lean-workspace
|
a60a16d99993351a08860575831ec7c5b801c39f
|
e3e9b99883e5056d2de1856b8adcb2f4625546e6
|
refs/heads/master
| 1,666,176,695,426
| 1,592,006,470,000
| 1,592,006,470,000
| 271,910,711
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 16,922
|
lean
|
/-
Authors: Daniel Carranza, Jonathon Chang, Ryan Sandford
Under the supervision of Chris Kapulkin
Theorems about two half-adjoint equivalences,
including a proof that two left half-adjoint
and two right half-adjoint equivalences are propositions
and that the two full-adjoint equivalence is equivalent to a non-propositional type
Last updated: 2020-06-12
-/
import hott.init hott.types.sigma hott.types.prod hott.types.pi hott.types.fiber hott.types.equiv .adj .prelim .hty_rec
open hott hott.eq
hott_theory
universes u v
-- This is used in the definition of the compatibilites for
-- a two half-adjoint and two left half-adjoint equivalence
@[hott] def nat_coh {A : Type u} {B : Type _} (g : B → A) (f : A → B) (H : g ∘ f ~ id) (x : A)
: H (g (f x)) = ap g (ap f (H x)) :=
cancel_right (H x) (ap_con_eq_con H (H x))⁻¹ ⬝ ap_compose g f _
namespace equiv
variables {A B: Type u}
-- Right coherence for two half-adjoint equivalence
@[hott] def r2coh (f : A → B) (h : adj f) (x : A) :=
nat_coh h.1 f h.2.1 x ⬝ ap02 h.1 (h.2.2.2.1 x) = h.2.2.2.2 (f x)
-- Left coherence for two half-adjoint equivalence
@[hott] def l2coh (f : A → B) (h : adj f) (y : B) :=
h.2.2.2.1 (h.1 y) ⬝ (nat_coh f h.1 h.2.2.1 y) = ap02 f (h.2.2.2.2 y)
-- Definition of a two (right) half-adjoint equivalence
@[hott] def is_two_hae (f : A → B) :=
Σ(g : B → A) (η : g ∘ f ~ id) (ε: f ∘ g ~ id)
(τ : Π(x : A), rcoh f ⟨g, (η, ε)⟩ x) (θ : Π(y : B), lcoh f ⟨g, (η, ε)⟩ y),
Π(x : A), r2coh f ⟨g, ⟨η, ⟨ε, (τ, θ)⟩⟩⟩ x
@[hott] def is_two_hae_to_is_equiv (f : A → B) : is_two_hae f → is_equiv f :=
λh, hott.is_equiv.mk f h.1 h.2.2.1 h.2.1 h.2.2.2.1⁻¹ʰᵗʸ
-- Definition of a two left half-adjoint equivalence
@[hott] def is_two_hae_l (f : A → B) :=
Σ(g : B → A) (η : g ∘ f ~ id) (ε: f ∘ g ~ id)
(τ : Π(x : A), rcoh f ⟨g, (η, ε)⟩ x) (θ : Π(y : B), lcoh f ⟨g, (η, ε)⟩ y),
Π(y : B), l2coh f ⟨g, ⟨η, ⟨ε, (τ, θ)⟩⟩⟩ y
@[hott] def is_two_hae_l_to_is_equiv (f : A → B) : is_two_hae_l f → is_equiv f :=
λh, is_equiv.adjointify f h.1 h.2.2.1 h.2.1
@[hott] def l2coh_equiv_fib_eq (f : A → B) (h : is_equiv f)
: (Σ(l : Π(y : B), lcoh f ⟨h.inv, (h.left_inv, h.right_inv)⟩ y),
Π(y : B), l2coh f ⟨h.inv, ⟨h.left_inv, ⟨h.right_inv, (h.adj⁻¹ʰᵗʸ, l)⟩⟩⟩ y)
≃ Π(y : B), fiber.mk ((is_equiv.left_inv f)
((is_equiv.inv f) y)) (h.adj⁻¹ʰᵗʸ ((is_equiv.inv f) y) ⬝ nat_coh f h.inv h.right_inv y)
= fiber.mk (ap h.inv ((is_equiv.right_inv f) y)) rfl :=
sigma.sigma_pi_equiv_pi_sigma
(λ(y : B) l : lcoh f ⟨h.inv, (h.left_inv, h.right_inv)⟩ y,
h.adj⁻¹ʰᵗʸ (is_equiv.inv f y) ⬝ (nat_coh f h.inv h.right_inv y) = ap02 f l)
⬝e pi.pi_equiv_pi_right (λy : B, (fiber.fiber_eq_equiv
(fiber.mk ((is_equiv.left_inv f) ((is_equiv.inv f) y))
(@concat _ _ _ _ ((is_equiv.adj f)⁻¹ʰᵗʸ ((is_equiv.inv f) y)) (nat_coh f h.inv h.right_inv y)))
(fiber.mk (ap h.inv ((is_equiv.right_inv f) y)) rfl))⁻¹ᵉ)
@[hott] def r2coh_equiv_fib_eq (f : A → B) (h : is_hadj_l f)
: (Σ(r : Π(x : A), rcoh f ⟨h.1, (h.2.1, h.2.2.1)⟩ x),
Π(x : A), nat_coh h.1 f h.2.1 x ⬝ ap02 h.1 (r x) = h.2.2.2 (f x))
≃ Π(x : A), fiber.mk (ap f (h.2.1 x)) ((nat_coh h.1 f h.2.1 x)⁻¹ ⬝ h.2.2.2 (f x))
= fiber.mk (h.2.2.1 (f x)) rfl :=
sigma.sigma_pi_equiv_pi_sigma
(λ(x : A) r : rcoh f ⟨h.1, (h.2.1, h.2.2.1)⟩ x,
nat_coh h.1 f h.2.1 x ⬝ ap02 h.1 r = h.2.2.2 (f x))
⬝e pi.pi_equiv_pi_right (λx : A, @sigma.sigma_equiv_sigma_right
_ (λr, nat_coh h.1 f h.2.1 x ⬝ ap02 h.1 r = h.2.2.2 (f x))
(λr, (nat_coh h.1 f h.2.1 x)⁻¹ ⬝ h.2.2.2 (f x) = ap02 h.1 r)
(λr : rcoh f ⟨h.1, (h.2.1, h.2.2.1)⟩ x,
(@eq_inv_con_equiv_con_eq _ _ _ _ (ap02 h.1 r) (h.2.2.2 (f x)) (nat_coh h.1 f h.2.1 x))⁻¹ᵉ
⬝e eq_equiv_eq_symm (ap02 h.1 r) ((nat_coh h.1 f h.2.1 x)⁻¹ ⬝ h.2.2.2 (f x))))
⬝e pi.pi_equiv_pi_right (λx : A, (fiber.fiber_eq_equiv
(fiber.mk (ap f (h.2.1 x)) ((nat_coh h.1 f h.2.1 x)⁻¹ ⬝ h.2.2.2 (f x)))
(fiber.mk (h.2.2.1 (f x)) rfl))⁻¹ᵉ
)
@[hott, instance] def is_contr_r2coh (f : A → B) (h : is_hadj_l f)
: is_contr (Σ(r : Π(x : A), rcoh f ⟨h.1, (h.2.1, h.2.2.1)⟩ x),
Π(x : A), nat_coh h.1 f h.2.1 x ⬝ ap02 h.1 (r x) = h.2.2.2 (f x)) :=
@is_trunc.is_contr_equiv_closed _ _ (r2coh_equiv_fib_eq f h)⁻¹ᵉ
(@pi.is_trunc_pi _ _ -2 (λx : A, @is_trunc.is_contr_eq _
(@is_equiv.is_contr_fiber_of_is_equiv _ _ (ap h.1) (@is_equiv.is_equiv_ap _ _ h.1
(@is_equiv.is_equiv_inv _ _ f (equiv.is_hadj_l_equiv_is_equiv f h)) _ _) _)
(fiber.mk (ap f (h.2.1 x)) ((nat_coh h.1 f h.2.1 x)⁻¹ ⬝ h.2.2.2 (f x)))
(fiber.mk (h.2.2.1 (f x)) rfl)))
@[hott, instance] def is_contr_l2coh (f : A → B) (h : is_equiv f)
: is_contr (Σ(l : Π(y : B), lcoh f ⟨h.inv, (h.left_inv, h.right_inv)⟩ y),
Π(y : B), l2coh f ⟨h.inv, ⟨h.left_inv, ⟨h.right_inv, (h.adj⁻¹ʰᵗʸ, l)⟩⟩⟩ y) :=
@is_trunc.is_contr_equiv_closed _ _ (l2coh_equiv_fib_eq f h)⁻¹ᵉ
(@pi.is_trunc_pi _ _ -2 (λy : B, @is_trunc.is_contr_eq _
(@is_equiv.is_contr_fiber_of_is_equiv _ _ (ap f) _ _)
(fiber.mk ((is_equiv.left_inv f) ((is_equiv.inv f) y))
(@concat _ _ _ _ ((is_equiv.adj f)⁻¹ʰᵗʸ ((is_equiv.inv f) y)) (nat_coh f h.inv h.right_inv y)))
(fiber.mk (ap h.inv ((is_equiv.right_inv f) y)) rfl)))
@[hott] def is_two_hae_reorder (f : A → B) : is_two_hae f ≃ Σ(u : Σ(g : B → A), linv g f)
(v : Σ(ε : rinv u.1 f), Π(y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y) (τ : Π(x : A), rcoh f ⟨u.1, (u.2, v.1)⟩ x),
Π(x : A), r2coh f ⟨u.1, ⟨u.2, ⟨v.1, (τ, v.2)⟩⟩⟩ x :=
begin
apply sigma.sigma_assoc_equiv (λu : Σ(g : B → A), linv g f, Σ(ε : rinv u.1 f) (τ : Π(x : A), rcoh f ⟨u.1, (u.2, ε)⟩ x)
(θ : Π(y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y), Π(x : A), r2coh f ⟨u.1, ⟨u.2, ⟨ε, (τ, θ)⟩⟩⟩ x) ⬝e _,
apply sigma.sigma_equiv_sigma_right, intro u,
apply (@sigma.sigma_equiv_sigma_right _
(λε : rinv u.1 f, Σ(τ : Π(x : A), rcoh f ⟨u.1, (u.2, ε)⟩ x) (θ : Π(y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y),
Π(x : A), r2coh f ⟨u.1, ⟨u.2, ⟨ε, (τ, θ)⟩⟩⟩ x)
(λε : rinv u.1 f, Σ(θ : Π(y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y) (τ : Π(x : A), rcoh f ⟨u.1, (u.2, ε)⟩ x),
Π(x : A), r2coh f ⟨u.1, ⟨u.2, ⟨ε, (τ, θ)⟩⟩⟩ x)
(λε : rinv u.1 f, sigma.sigma_comm_equiv
(λ(τ : Π(x : A), rcoh f ⟨u.1, (u.2, ε)⟩ x) (θ : Π(y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y),
Π(x : A), r2coh f ⟨u.1, ⟨u.2, ⟨ε, (τ, θ)⟩⟩⟩ x))) ⬝e _,
exact sigma.sigma_assoc_equiv (λv : Σ(ε : rinv u.1 f), Π(y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y,
Σ(τ : Π(x : A), rcoh f ⟨u.1, (u.2, v.1)⟩ x), Π(x : A), r2coh f ⟨u.1, ⟨u.2, ⟨v.1, (τ, v.2)⟩⟩⟩ x)
end
-- Proof that two half-adjoint equivalence is a mere proposition
@[hott, instance] def is_prop_is_two_hae (f : A → B) : is_prop (is_two_hae f) :=
begin
apply is_trunc.is_prop_of_imp_is_contr, intro h,
apply is_trunc.is_trunc_equiv_closed_rev -2 (is_two_hae_reorder f),
have H : is_equiv f := is_two_hae_to_is_equiv f h,
apply is_trunc.is_trunc_equiv_closed_rev -2 (@sigma.sigma_equiv_of_is_contr_left _
(λu : Σ(g : B → A), linv g f, Σ(v : Σ(ε : rinv u.1 f), Π(y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y),
Σ(τ : Π(x : A), rcoh f ⟨u.1, (u.2, v.1)⟩ x), Π(x : A), r2coh f ⟨u.1, ⟨u.2, ⟨v.1, (τ, v.2)⟩⟩⟩ x)
(@is_contr_linv _ _ f H)),
dsimp,
let u := (@is_trunc.center _ (@is_contr_linv _ _ f H)),
apply is_trunc.is_trunc_equiv_closed_rev -2 (@sigma.sigma_equiv_of_is_contr_left _
(λv : Σ(ε : rinv u.1 f), Π (y : B), lcoh f ⟨u.1, (u.2, ε)⟩ y, _)
(@is_contr_lcoh _ _ f H u)),
dsimp,
let v := @is_trunc.center _ (@is_contr_lcoh _ _ f H u),
exact is_contr_r2coh f ⟨u.1, ⟨u.2, ⟨v.1, v.2⟩⟩⟩
end
@[hott] def is_two_hae_l_reorder (f : A → B) : is_two_hae_l f ≃ Σ(u : Σ(g : B → A), rinv g f)
(v : Σ(η : linv u.1 f), Π(x : A), rcoh f ⟨u.1, (η, u.2)⟩ x) (θ : Π(y : B), lcoh f ⟨u.1, (v.1, u.2)⟩ y),
Π(y : B), l2coh f ⟨u.1, ⟨v.1, ⟨u.2, (v.2, θ)⟩⟩⟩ y :=
begin
apply (@sigma.sigma_equiv_sigma_right _
(λg : B → A, Σ(l : linv g f) (r : rinv g f), _)
(λg : B → A, Σ(r : rinv g f) (l : linv g f), _)
(λg: B → A, sigma.sigma_comm_equiv (λ(l : linv g f) (r : rinv g f), _))) ⬝e _,
dsimp,
apply (sigma.sigma_assoc_equiv (λu : Σ(g : B → A), rinv g f,
Σ(η : linv u.1 f) (τ : Π(x : A), rcoh f ⟨u.1, (η, u.2)⟩ x) (θ : Π(y : B), lcoh f ⟨u.1, (η, u.2)⟩ y),
Π(y : B), l2coh f ⟨u.1, ⟨η, ⟨u.2, (τ, θ)⟩⟩⟩ y)) ⬝e _,
apply sigma.sigma_equiv_sigma_right, intro u,
exact sigma.sigma_assoc_equiv (λv : Σ(η : linv u.1 f), Π(x : A), rcoh f ⟨u.1, (η, u.2)⟩ x,
Σ(θ : Π(y : B), lcoh f ⟨u.1, (v.1, u.2)⟩ y), Π(y : B), l2coh f ⟨u.1, ⟨v.1, ⟨u.2, (v.2, θ)⟩⟩⟩ y),
end
-- Proof that two left half-adjoint equivalence is a mere proposition
@[hott, instance] def is_prop_is_two_hae_l (f : A → B) : is_prop (is_two_hae_l f) :=
begin
apply is_trunc.is_prop_of_imp_is_contr, intro h,
have H : is_equiv f := is_two_hae_l_to_is_equiv f h,
apply is_trunc.is_trunc_equiv_closed_rev -2 (is_two_hae_l_reorder f),
apply is_trunc.is_trunc_equiv_closed_rev -2 (@sigma.sigma_equiv_of_is_contr_left _
(λu: Σ(g : B → A), rinv g f, Σ(v : Σ(η : linv u.1 f), Π(x : A), rcoh f ⟨u.1, (η, u.2)⟩ x),
Σ(θ : Π(y : B), lcoh f ⟨u.1, (v.1, u.2)⟩ y), Π(y : B), l2coh f ⟨u.1, ⟨v.1, ⟨u.2, (v.2, θ)⟩⟩⟩ y)
(@is_equiv.is_contr_right_inverse _ _ f H)),
dsimp,
let u := @is_trunc.center _ (@is_equiv.is_contr_right_inverse _ _ f H),
apply is_trunc.is_trunc_is_equiv_closed_rev -2 (@sigma.sigma_equiv_of_is_contr_left _
(λv : Σ(η : linv u.1 f), Π(x : A), rcoh f ⟨u.1, (η, u.2)⟩ x, Σ(θ : Π(y : B), lcoh f ⟨u.1, (v.1, u.2)⟩ y),
Π(y : B), l2coh f ⟨u.1, ⟨v.1, ⟨u.2, (v.2, θ)⟩⟩⟩ y)
(@is_contr_rcoh _ _ f H u)),
dsimp,
let v := @is_trunc.center _ (@is_contr_rcoh _ _ f H u),
let H' := (hott.is_equiv.mk' u.1 u.2 v.1 v.2⁻¹ʰᵗʸ),
exact transport (λH, is_contr (Σ(θ : Π(y : B), lcoh f ⟨u.1, (v.1, u.2)⟩ y),
Π(y : B), l2coh f ⟨u.1, ⟨v.1, ⟨u.2, (H, θ)⟩⟩⟩ y))
(eq.inv_inv_htpy v.2) (is_contr_l2coh f H')
end
-- Promoting a left half-adjoint equivalence to a two half-adjoint equivalence
@[hott] def two_adjointify (f : A → B) : is_hadj_l f → is_two_hae f :=
λh, have _, from @is_trunc.center _ (is_contr_r2coh f h),
⟨h.1, ⟨h.2.1, ⟨h.2.2.1, ⟨this.1, ⟨h.2.2.2, this.2⟩⟩⟩⟩⟩
-- Promoting a half-adjoint equivalence to a two left half-adjoint equivalence
@[hott] def two_adjointify_left (f : A → B) : is_equiv f → is_two_hae_l f :=
λh, have _, from @is_trunc.center _ (is_contr_l2coh f h),
⟨h.inv, ⟨h.left_inv, ⟨h.right_inv, ⟨h.adj⁻¹ʰᵗʸ, this⟩⟩⟩⟩
-- Two half-adjoint equivalences and two left half-adjoint equivalences are equivalent
@[hott] def two_hae_equiv_two_hae_l (f : A → B) : is_two_hae f ≃ is_two_hae_l f :=
is_trunc.equiv_of_is_prop
(λh : is_two_hae f, two_adjointify_left f (is_equiv.mk' h.1 h.2.2.1 h.2.1 h.2.2.2.1⁻¹ʰᵗʸ))
(λh : is_two_hae_l f, two_adjointify f ⟨h.1, ⟨h.2.1, ⟨h.2.2.1, h.2.2.2.2.1⟩⟩⟩)
-- Definition of a two full-adjoint equivalence
@[hott] def two_adj (f : A → B) :=
Σ(g : B → A) (η : g ∘ f ~ id) (ε: f ∘ g ~ id)
(τ : Π(x : A), rcoh f ⟨g, (η, ε)⟩ x) (θ : Π(y : B), lcoh f ⟨g, (η, ε)⟩ y),
(Π(x : A), r2coh f ⟨g, ⟨η, ⟨ε, (τ, θ)⟩⟩⟩ x)
× Π(y : B), l2coh f ⟨g, ⟨η, ⟨ε, (τ, θ)⟩⟩⟩ y
@[hott] def two_adj_id_equiv_no_linv
: two_adj (@id A) ≃ Σ(ε : @id A ~ id) (τ : Π(x : A), rfl = ε x) (θ : Π(x : A), rfl = ap id (ε x)),
(Π(x : A), nat_coh id id (@hott.eq.refl A) x ⬝ ap02 id (τ x) = θ x) × (Π(x : A), τ x ⬝ nat_coh id id ε x = ap02 id (θ x)) :=
sigma.sigma_assoc_equiv (λu : Σ(g : A → A), g ~ id, Σ(ε : u.1 ~ id) (τ : Π(x : A), ap id (u.2 x) = ε x) (θ : Π(x : A), u.2 (u.1 x) = ap u.1 (ε x)), (Π(x : A), nat_coh u.1 id u.2 x ⬝ ap02 u.1 (τ x) = θ x) × (Π(x : A), τ (u.1 x) ⬝ nat_coh id u.1 ε x = ap02 id (θ x)))
⬝e @sigma.sigma_equiv_of_is_contr_left _
(λu : Σ(g : A → A), g ~ id, Σ(ε : u.1 ~ id) (τ : Π(x : A), ap id (u.2 x) = ε x) (θ : Π(x : A), u.2 (u.1 x) = ap u.1 (ε x)), (Π(x : A), nat_coh u.1 id u.2 x ⬝ ap02 u.1 (τ x) = θ x) × (Π(x : A), τ (u.1 x) ⬝ nat_coh id u.1 ε x = ap02 id (θ x)))
(is_trunc.sigma_hty_is_contr_right (@id A))
@[hott] def two_adj_id_equiv_no_rcoh
: (Σ(ε : @id A ~ id) (τ : Π(x : A), rfl = ε x) (θ : Π(x : A), rfl = ap id (ε x)),
(Π(x : A), nat_coh id id (@hott.eq.refl A) x ⬝ ap02 id (τ x) = θ x) × (Π(x : A), τ x ⬝ nat_coh id id ε x = ap02 id (θ x)))
≃ Σ(θ : Π(x : A), rfl = ap id (hott.eq.refl x)), (Π(x : A), nat_coh id id (@hott.eq.refl A) x ⬝ ap02 id rfl = θ x) × (Π(x : A), rfl ⬝ nat_coh id id (@hott.eq.refl A) x = ap02 id (θ x)) :=
sigma.sigma_assoc_equiv (λu : Σ(ε : @id A ~ id), Π(x : A), rfl = ε x, Σ(θ : Π(x : A), rfl = ap id (u.1 x)), (Π(x : A), nat_coh id id (@hott.eq.refl A) x ⬝ ap02 id (u.2 x) = θ x) × (Π(x : A), u.2 x ⬝ nat_coh id id u.1 x = ap02 id (θ x)))
⬝e @sigma.sigma_equiv_of_is_contr_left _
(λu : Σ(ε : @id A ~ id), hott.eq.refl ~ ε, Σ(θ : Π(x : A), rfl = ap id (u.1 x)), (Π(x : A), nat_coh id id (@hott.eq.refl A) x ⬝ ap02 id (u.2 x) = θ x) × (Π(x : A), u.2 x ⬝ nat_coh id id u.1 x = ap02 id (θ x)))
(is_trunc.sigma_hty_is_contr (@hott.eq.refl A))
@[hott] def two_adj_id_equiv_no_rcoh_simplify
: (Σ(θ : Π(x : A), rfl = ap id (hott.eq.refl x)), (Π(x : A), nat_coh id id (@hott.eq.refl A) x ⬝ ap02 id rfl = θ x) × (Π(x : A), rfl ⬝ nat_coh id id (@hott.eq.refl A) x = ap02 id (θ x)))
≃ Σ(θ : Π(x : A), hott.eq.refl x = hott.eq.refl x), (Π(x : A), hott.eq.refl (hott.eq.refl x) = θ x) × (Π(x : A), hott.eq.refl (hott.eq.refl x) = θ x) :=
begin
fapply sigma.sigma_equiv_sigma_right, intro θ,
apply prod.prod_equiv_prod,
refl,
apply pi.pi_equiv_pi_right, intro x,
exact eq_equiv_eq_closed rfl (@ap_con_eq_con _ (λp : x = x, ap id p) (λp, ap_id p) _ _ (θ x) ⬝ idp_con (θ x))
end
@[hott] def two_adj_id_equiv_no_r2coh
: (Σ(θ : Π(x : A), hott.eq.refl x = hott.eq.refl x), (Π(x : A), hott.eq.refl (hott.eq.refl x) = θ x) × (Π(x : A), hott.eq.refl (hott.eq.refl x) = θ x))
≃ Π(x : A), rfl = hott.eq.refl (hott.eq.refl x) :=
@sigma.sigma_equiv_sigma_right (Π(x : A), rfl = hott.eq.refl x)
(λθ, (Π(x : A), rfl = θ x) × (Π(x : A), rfl = θ x) ) _
(λθ, (sigma.equiv_prod (Π(x : A), rfl = θ x) (Π(x : A), rfl = θ x))⁻¹ᵉ)
⬝e sigma.sigma_assoc_equiv (λu : Σ(θ : Π(x : A), rfl = hott.eq.refl x), Π(x : A), rfl = θ x, Π(x : A), rfl = u.1 x)
⬝e @sigma.sigma_equiv_of_is_contr_left _
(λu : Σ(θ : Π(x : A), rfl = hott.eq.refl x), Π(x : A), rfl = θ x, Π(x : A), rfl= u.1 x)
(is_trunc.sigma_hty_is_contr (λx : A, @hott.eq.refl (x = x) (hott.eq.refl x)))
-- Two full-adjoint equivalence is not a mere proposition
@[hott] def two_adj_equiv_pi_refl_eq (f : A ≃ B) : two_adj f ≃ Π(x : A), hott.eq.refl (hott.eq.refl x) = rfl :=
by apply equiv.rec_on_ua_idp f; exact two_adj_id_equiv_no_linv
⬝e two_adj_id_equiv_no_rcoh
⬝e two_adj_id_equiv_no_rcoh_simplify
⬝e two_adj_id_equiv_no_r2coh
end equiv
|
f29fcd106d1e81b64db3bc951159f9f6a199795a
|
b70031c8e2c5337b91d7e70f1e0c5f528f7b0e77
|
/src/algebra/free_algebra.lean
|
89aa9ab87b25d84f19e7311a7cb0fe0fbaa79450
|
[
"Apache-2.0"
] |
permissive
|
molodiuc/mathlib
|
cae2ba3ef1601c1f42ca0b625c79b061b63fef5b
|
98ebe5a6739fbe254f9ee9d401882d4388f91035
|
refs/heads/master
| 1,674,237,127,059
| 1,606,353,533,000
| 1,606,353,533,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 15,171
|
lean
|
/-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Scott Morrison, Adam Topaz.
-/
import algebra.algebra.subalgebra
import algebra.monoid_algebra
import linear_algebra
import data.equiv.transfer_instance
/-!
# Free Algebras
Given a commutative semiring `R`, and a type `X`, we construct the free `R`-algebra on `X`.
## Notation
1. `free_algebra R X` is the free algebra itself. It is endowed with an `R`-algebra structure.
2. `free_algebra.ι R` is the function `X → free_algebra R X`.
3. Given a function `f : X → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an
`R`-algebra morphism `free_algebra R X → A`.
## Theorems
1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`.
2. `lift_unique` states that whenever an R-algebra morphism `g : free_algebra R X → A` is
given whose composition with `ι R` is `f`, then one has `g = lift R f`.
3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem.
4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift
of the composition of an algebra morphism with `ι` is the algebra morphism itself.
5. `equiv_monoid_algebra_free_monoid : free_algebra R X ≃ₐ[R] monoid_algebra R (free_monoid X)`
6. An inductive principle `induction`.
## Implementation details
We construct the free algebra on `X` as a quotient of an inductive type `free_algebra.pre` by an inductively defined relation `free_algebra.rel`.
Explicitly, the construction involves three steps:
1. We construct an inductive type `free_algebra.pre R X`, the terms of which should be thought
of as representatives for the elements of `free_algebra R X`.
It is the free type with maps from `R` and `X`, and with two binary operations `add` and `mul`.
2. We construct an inductive relation `free_algebra.rel R X` on `free_algebra.pre R X`.
This is the smallest relation for which the quotient is an `R`-algebra where addition resp.
multiplication are induced by `add` resp. `mul` from 1., and for which the map from `R` is the
structure map for the algebra.
3. The free algebra `free_algebra R X` is the quotient of `free_algebra.pre R X` by
the relation `free_algebra.rel R X`.
-/
variables (R : Type*) [comm_semiring R]
variables (X : Type*)
namespace free_algebra
/--
This inductive type is used to express representatives of the free algebra.
-/
inductive pre
| of : X → pre
| of_scalar : R → pre
| add : pre → pre → pre
| mul : pre → pre → pre
namespace pre
instance : inhabited (pre R X) := ⟨of_scalar 0⟩
-- Note: These instances are only used to simplify the notation.
/-- Coercion from `X` to `pre R X`. Note: Used for notation only. -/
def has_coe_generator : has_coe X (pre R X) := ⟨of⟩
/-- Coercion from `R` to `pre R X`. Note: Used for notation only. -/
def has_coe_semiring : has_coe R (pre R X) := ⟨of_scalar⟩
/-- Multiplication in `pre R X` defined as `pre.mul`. Note: Used for notation only. -/
def has_mul : has_mul (pre R X) := ⟨mul⟩
/-- Addition in `pre R X` defined as `pre.add`. Note: Used for notation only. -/
def has_add : has_add (pre R X) := ⟨add⟩
/-- Zero in `pre R X` defined as the image of `0` from `R`. Note: Used for notation only. -/
def has_zero : has_zero (pre R X) := ⟨of_scalar 0⟩
/-- One in `pre R X` defined as the image of `1` from `R`. Note: Used for notation only. -/
def has_one : has_one (pre R X) := ⟨of_scalar 1⟩
/--
Scalar multiplication defined as multiplication by the image of elements from `R`.
Note: Used for notation only.
-/
def has_scalar : has_scalar R (pre R X) := ⟨λ r m, mul (of_scalar r) m⟩
end pre
local attribute [instance]
pre.has_coe_generator pre.has_coe_semiring pre.has_mul pre.has_add pre.has_zero
pre.has_one pre.has_scalar
/--
Given a function from `X` to an `R`-algebra `A`, `lift_fun` provides a lift of `f` to a function
from `pre R X` to `A`. This is mainly used in the construction of `free_algebra.lift`.
-/
def lift_fun {A : Type*} [semiring A] [algebra R A] (f : X → A) : pre R X → A :=
λ t, pre.rec_on t f (algebra_map _ _) (λ _ _, (+)) (λ _ _, (*))
/--
An inductively defined relation on `pre R X` used to force the initial algebra structure on
the associated quotient.
-/
inductive rel : (pre R X) → (pre R X) → Prop
-- force `of_scalar` to be a central semiring morphism
| add_scalar {r s : R} : rel ↑(r + s) (↑r + ↑s)
| mul_scalar {r s : R} : rel ↑(r * s) (↑r * ↑s)
| central_scalar {r : R} {a : pre R X} : rel (r * a) (a * r)
-- commutative additive semigroup
| add_assoc {a b c : pre R X} : rel (a + b + c) (a + (b + c))
| add_comm {a b : pre R X} : rel (a + b) (b + a)
| zero_add {a : pre R X} : rel (0 + a) a
-- multiplicative monoid
| mul_assoc {a b c : pre R X} : rel (a * b * c) (a * (b * c))
| one_mul {a : pre R X} : rel (1 * a) a
| mul_one {a : pre R X} : rel (a * 1) a
-- distributivity
| left_distrib {a b c : pre R X} : rel (a * (b + c)) (a * b + a * c)
| right_distrib {a b c : pre R X} : rel ((a + b) * c) (a * c + b * c)
-- other relations needed for semiring
| zero_mul {a : pre R X} : rel (0 * a) 0
| mul_zero {a : pre R X} : rel (a * 0) 0
-- compatibility
| add_compat_left {a b c : pre R X} : rel a b → rel (a + c) (b + c)
| add_compat_right {a b c : pre R X} : rel a b → rel (c + a) (c + b)
| mul_compat_left {a b c : pre R X} : rel a b → rel (a * c) (b * c)
| mul_compat_right {a b c : pre R X} : rel a b → rel (c * a) (c * b)
end free_algebra
/--
The free algebra for the type `X` over the commutative semiring `R`.
-/
def free_algebra := quot (free_algebra.rel R X)
namespace free_algebra
local attribute [instance]
pre.has_coe_generator pre.has_coe_semiring pre.has_mul pre.has_add pre.has_zero
pre.has_one pre.has_scalar
instance : semiring (free_algebra R X) :=
{ add := quot.map₂ (+) (λ _ _ _, rel.add_compat_right) (λ _ _ _, rel.add_compat_left),
add_assoc := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact quot.sound rel.add_assoc },
zero := quot.mk _ 0,
zero_add := by { rintro ⟨⟩, exact quot.sound rel.zero_add },
add_zero := begin
rintros ⟨⟩,
change quot.mk _ _ = _,
rw [quot.sound rel.add_comm, quot.sound rel.zero_add],
end,
add_comm := by { rintros ⟨⟩ ⟨⟩, exact quot.sound rel.add_comm },
mul := quot.map₂ (*) (λ _ _ _, rel.mul_compat_right) (λ _ _ _, rel.mul_compat_left),
mul_assoc := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact quot.sound rel.mul_assoc },
one := quot.mk _ 1,
one_mul := by { rintros ⟨⟩, exact quot.sound rel.one_mul },
mul_one := by { rintros ⟨⟩, exact quot.sound rel.mul_one },
left_distrib := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact quot.sound rel.left_distrib },
right_distrib := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact quot.sound rel.right_distrib },
zero_mul := by { rintros ⟨⟩, exact quot.sound rel.zero_mul },
mul_zero := by { rintros ⟨⟩, exact quot.sound rel.mul_zero } }
instance : inhabited (free_algebra R X) := ⟨0⟩
instance : has_scalar R (free_algebra R X) :=
{ smul := λ r a, quot.lift_on a (λ x, quot.mk _ $ ↑r * x) $
λ a b h, quot.sound (rel.mul_compat_right h) }
instance : algebra R (free_algebra R X) :=
{ to_fun := λ r, quot.mk _ r,
map_one' := rfl,
map_mul' := λ _ _, quot.sound rel.mul_scalar,
map_zero' := rfl,
map_add' := λ _ _, quot.sound rel.add_scalar,
commutes' := λ _, by { rintros ⟨⟩, exact quot.sound rel.central_scalar },
smul_def' := λ _ _, rfl }
instance {S : Type*} [comm_ring S] : ring (free_algebra S X) := algebra.semiring_to_ring S
variables {X}
/--
The canonical function `X → free_algebra R X`.
-/
def ι : X → free_algebra R X := λ m, quot.mk _ m
@[simp] lemma quot_mk_eq_ι (m : X) : quot.mk (free_algebra.rel R X) m = ι R m := rfl
variables {A : Type*} [semiring A] [algebra R A]
/-- Internal definition used to define `lift` -/
private def lift_aux (f : X → A) : (free_algebra R X →ₐ[R] A) :=
{ to_fun := λ a, quot.lift_on a (lift_fun _ _ f) $ λ a b h,
begin
induction h,
{ exact (algebra_map R A).map_add h_r h_s, },
{ exact (algebra_map R A).map_mul h_r h_s },
{ apply algebra.commutes },
{ change _ + _ + _ = _ + (_ + _),
rw add_assoc },
{ change _ + _ = _ + _,
rw add_comm, },
{ change (algebra_map _ _ _) + lift_fun R X f _ = lift_fun R X f _,
simp, },
{ change _ * _ * _ = _ * (_ * _),
rw mul_assoc },
{ change (algebra_map _ _ _) * lift_fun R X f _ = lift_fun R X f _,
simp, },
{ change lift_fun R X f _ * (algebra_map _ _ _) = lift_fun R X f _,
simp, },
{ change _ * (_ + _) = _ * _ + _ * _,
rw left_distrib, },
{ change (_ + _) * _ = _ * _ + _ * _,
rw right_distrib, },
{ change (algebra_map _ _ _) * _ = algebra_map _ _ _,
simp },
{ change _ * (algebra_map _ _ _) = algebra_map _ _ _,
simp },
repeat { change lift_fun R X f _ + lift_fun R X f _ = _,
rw h_ih,
refl, },
repeat { change lift_fun R X f _ * lift_fun R X f _ = _,
rw h_ih,
refl, },
end,
map_one' := by { change algebra_map _ _ _ = _, simp },
map_mul' := by { rintros ⟨⟩ ⟨⟩, refl },
map_zero' := by { change algebra_map _ _ _ = _, simp },
map_add' := by { rintros ⟨⟩ ⟨⟩, refl },
commutes' := by tauto }
/--
Given a function `f : X → A` where `A` is an `R`-algebra, `lift R f` is the unique lift
of `f` to a morphism of `R`-algebras `free_algebra R X → A`.
-/
def lift : (X → A) ≃ (free_algebra R X →ₐ[R] A) :=
{ to_fun := lift_aux R,
inv_fun := λ F, F ∘ (ι R),
left_inv := λ f, by {ext, refl},
right_inv := λ F, by {
ext x,
rcases x,
induction x,
case pre.of : {
change ((F : free_algebra R X → A) ∘ (ι R)) _ = _,
refl },
case pre.of_scalar : {
change algebra_map _ _ x = F (algebra_map _ _ x),
rw alg_hom.commutes F x, },
case pre.add : a b ha hb {
change lift_aux R (F ∘ ι R) (quot.mk _ _ + quot.mk _ _) = F (quot.mk _ _ + quot.mk _ _),
rw [alg_hom.map_add, alg_hom.map_add, ha, hb], },
case pre.mul : a b ha hb {
change lift_aux R (F ∘ ι R) (quot.mk _ _ * quot.mk _ _) = F (quot.mk _ _ * quot.mk _ _),
rw [alg_hom.map_mul, alg_hom.map_mul, ha, hb], }, }, }
@[simp] lemma lift_aux_eq (f : X → A) : lift_aux R f = lift R f := rfl
@[simp]
lemma lift_symm_apply (F : free_algebra R X →ₐ[R] A) : (lift R).symm F = F ∘ (ι R) := rfl
variables {R X}
@[simp]
theorem ι_comp_lift (f : X → A) :
(lift R f : free_algebra R X → A) ∘ (ι R) = f := by {ext, refl}
@[simp]
theorem lift_ι_apply (f : X → A) (x) :
lift R f (ι R x) = f x := rfl
@[simp]
theorem lift_unique (f : X → A) (g : free_algebra R X →ₐ[R] A) :
(g : free_algebra R X → A) ∘ (ι R) = f ↔ g = lift R f :=
(lift R).symm_apply_eq
/-!
At this stage we set the basic definitions as `@[irreducible]`, so from this point onwards one should only use the universal properties of the free algebra, and consider the actual implementation as a quotient of an inductive type as completely hidden.
Of course, one still has the option to locally make these definitions `semireducible` if so desired, and Lean is still willing in some circumstances to do unification based on the underlying definition.
-/
attribute [irreducible] ι lift
-- Marking `free_algebra` irreducible makes `ring` instances inaccessible on quotients.
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241
-- For now, we avoid this by not marking it irreducible.
@[simp]
theorem lift_comp_ι (g : free_algebra R X →ₐ[R] A) :
lift R ((g : free_algebra R X → A) ∘ (ι R)) = g :=
by { rw ←lift_symm_apply, exact (lift R).apply_symm_apply g }
@[ext]
theorem hom_ext {f g : free_algebra R X →ₐ[R] A}
(w : ((f : free_algebra R X → A) ∘ (ι R)) = ((g : free_algebra R X → A) ∘ (ι R))) : f = g :=
begin
rw [←lift_symm_apply, ←lift_symm_apply] at w,
exact (lift R).symm.injective w,
end
/--
The free algebra on `X` is "just" the monoid algebra on the free monoid on `X`.
This would be useful when constructing linear maps out of a free algebra,
for example.
-/
noncomputable
def equiv_monoid_algebra_free_monoid : free_algebra R X ≃ₐ[R] monoid_algebra R (free_monoid X) :=
alg_equiv.of_alg_hom
(lift R (λ x, (monoid_algebra.of R (free_monoid X)) (free_monoid.of x)))
((monoid_algebra.lift R (free_monoid X) (free_algebra R X)) (free_monoid.lift (ι R)))
begin
apply monoid_algebra.alg_hom_ext, intro x,
apply free_monoid.rec_on x,
{ simp, refl, },
{ intros x y ih, simp at ih, simp [ih], }
end
(by { ext, simp, })
instance [nontrivial R] : nontrivial (free_algebra R X) :=
equiv_monoid_algebra_free_monoid.to_equiv.nontrivial
end free_algebra
-- There is something weird in the above namespace that breaks the typeclass resolution of `has_coe_to_sort` below.
-- Closing it and reopening it fixes it...
namespace free_algebra
/-- An induction principle for the free algebra.
If `C` holds for the `algebra_map` of `r : R` into `free_algebra R X`, the `ι` of `x : X`, and is
preserved under addition and muliplication, then it holds for all of `free_algebra R X`.
-/
@[elab_as_eliminator]
lemma induction {C : free_algebra R X → Prop}
(h_grade0 : ∀ r, C (algebra_map R (free_algebra R X) r))
(h_grade1 : ∀ x, C (ι R x))
(h_mul : ∀ a b, C a → C b → C (a * b))
(h_add : ∀ a b, C a → C b → C (a + b))
(a : free_algebra R X) :
C a :=
begin
-- the arguments are enough to construct a subalgebra, and a mapping into it from X
let s : subalgebra R (free_algebra R X) := {
carrier := C,
one_mem' := h_grade0 1,
zero_mem' := h_grade0 0,
mul_mem' := h_mul,
add_mem' := h_add,
algebra_map_mem' := h_grade0, },
let of : X → s := subtype.coind (ι R) h_grade1,
-- the mapping through the subalgebra is the identity
have of_id : alg_hom.id R (free_algebra R X) = s.val.comp (lift R of),
{ ext,
simp [of, subtype.coind], },
-- finding a proof is finding an element of the subalgebra
convert subtype.prop (lift R of a),
simp [alg_hom.ext_iff] at of_id,
exact of_id a,
end
/-- The star ring formed by reversing the elements of products -/
instance : star_ring (free_algebra R X) :=
{ star := opposite.unop ∘ lift R (opposite.op ∘ ι R),
star_involutive := λ x, by {
unfold has_star.star,
simp only [function.comp_apply],
refine free_algebra.induction R X _ _ _ _ x; intros; simp [*] },
star_mul := λ a b, by simp,
star_add := λ a b, by simp }
@[simp]
lemma star_ι (x : X) : star (ι R x) = (ι R x) :=
by simp [star, has_star.star]
@[simp]
lemma star_algebra_map (r : R) : star (algebra_map R (free_algebra R X) r) = (algebra_map R _ r) :=
by simp [star, has_star.star]
/-- `star` as an `alg_equiv` -/
def star_hom : free_algebra R X ≃ₐ[R] (free_algebra R X)ᵒᵖ :=
{ commutes' := λ r, by simp [star_algebra_map],
..star_ring_equiv }
end free_algebra
|
ff08a9ff26ea3ef37b09da27071cb7e861bbfcff
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/archive/imo/imo2008_q2.lean
|
43c6b652cb1278e171170541458b60458810c01a
|
[
"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,297
|
lean
|
/-
Copyright (c) 2021 Manuel Candales. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Manuel Candales
-/
import data.real.basic
import data.set.finite
/-!
# IMO 2008 Q2
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
(a) Prove that
```
x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1
```
for all real numbers `x`,`y`, `z`, each different from 1, and satisfying `xyz = 1`.
(b) Prove that equality holds above for infinitely many triples of rational numbers `x`, `y`, `z`,
each different from 1, and satisfying `xyz = 1`.
# Solution
(a) Since `xyz = 1`, we can apply the substitution `x = a/b`, `y = b/c`, `z = c/a`.
Then we define `m = c-b`, `n = b-a` and rewrite the inequality as `LHS - 1 ≥ 0`
using `c`, `m` and `n`. We factor `LHS - 1` as a square, which finishes the proof.
(b) We present a set `W` of rational triples. We prove that `W` is a subset of the
set of rational solutions to the equation, and that `W` is infinite.
-/
namespace imo2008_q2
lemma subst_abc {x y z : ℝ} (h : x*y*z = 1) :
∃ a b c : ℝ, a ≠ 0 ∧ b ≠ 0 ∧ c ≠ 0 ∧ x = a/b ∧ y = b/c ∧ z = c /a :=
begin
use [x, 1, 1/y],
obtain ⟨⟨hx, hy⟩, hz⟩ : (x ≠ 0 ∧ y ≠ 0) ∧ z ≠ 0,
by simpa [not_or_distrib] using trans_rel_right (≠) h one_ne_zero,
have : z * (y * x) = 1, by { rw ← h, ac_refl },
field_simp *
end
theorem imo2008_q2a (x y z : ℝ) (h : x*y*z = 1) (hx : x ≠ 1) (hy : y ≠ 1) (hz : z ≠ 1) :
x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1 :=
begin
obtain ⟨a, b, c, ha, hb, hc, rfl, rfl, rfl⟩ := subst_abc h,
obtain ⟨m, n, rfl, rfl⟩ : ∃ m n, b = c - m ∧ a = c - m - n,
{ use [c - b, b - a], simp },
have hm_ne_zero : m ≠ 0,
{ contrapose! hy, field_simp, assumption },
have hn_ne_zero : n ≠ 0,
{ contrapose! hx, field_simp, assumption },
have hmn_ne_zero : m + n ≠ 0,
{ contrapose! hz, field_simp, linarith },
have hc_sub_sub : c - (c - m - n) = m + n, by abel,
rw [ge_iff_le, ← sub_nonneg],
convert sq_nonneg ((c*(m^2+n^2+m*n) - m*(m+n)^2) / (m*n*(m+n)) ),
field_simp *, ring
end
def rational_solutions := { s : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧
x ≠ 1 ∧ y ≠ 1 ∧ z ≠ 1 ∧ x*y*z = 1 ∧ x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1 }
theorem imo2008_q2b : set.infinite rational_solutions :=
begin
let W := { s : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧
∃ t : ℚ, t > 0 ∧ x = -(t+1)/t^2 ∧ y = t/(t+1)^2 ∧ z = -t*(t+1)},
have hW_sub_S : W ⊆ rational_solutions,
{ intros s hs_in_W,
rw rational_solutions,
simp only [set.mem_set_of_eq] at hs_in_W ⊢,
rcases hs_in_W with ⟨x, y, z, h₁, t, ht_gt_zero, hx_t, hy_t, hz_t⟩,
use [x, y, z],
have ht_ne_zero : t ≠ 0, exact ne_of_gt ht_gt_zero,
have ht1_ne_zero : t+1 ≠ 0, linarith[ht_gt_zero],
have key_gt_zero : t^2 + t + 1 > 0, linarith[pow_pos ht_gt_zero 2, ht_gt_zero],
have key_ne_zero : t^2 + t + 1 ≠ 0, exact ne_of_gt key_gt_zero,
have h₂ : x ≠ 1, { rw hx_t, field_simp, linarith[key_gt_zero] },
have h₃ : y ≠ 1, { rw hy_t, field_simp, linarith[key_gt_zero] },
have h₄ : z ≠ 1, { rw hz_t, linarith[key_gt_zero] },
have h₅ : x*y*z = 1, { rw [hx_t, hy_t, hz_t], field_simp, ring },
have h₆ : x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2 = 1,
{ have hx1 : (x - 1)^2 = (t^2 + t + 1)^2/t^4, { field_simp, rw hx_t, field_simp, ring },
have hy1 : (y - 1)^2 = (t^2 + t + 1)^2/(t+1)^4, { field_simp, rw hy_t, field_simp, ring },
have hz1 : (z - 1)^2 = (t^2 + t + 1)^2, { rw hz_t, ring },
calc x^2/(x-1)^2 + y^2/(y-1)^2 + z^2/(z-1)^2
= (x^2*t^4 + y^2*(t+1)^4 + z^2)/(t^2 + t + 1)^2 :
by { rw [hx1, hy1, hz1], field_simp }
... = 1 :
by { rw [hx_t, hy_t, hz_t], field_simp, ring } },
exact ⟨h₁, h₂, h₃, h₄, h₅, h₆⟩ },
have hW_inf : set.infinite W,
{ let g : ℚ×ℚ×ℚ → ℚ := (λs, -s.2.2),
let K := g '' W,
have hK_not_bdd : ¬bdd_above K,
{ rw not_bdd_above_iff,
intro q,
let t : ℚ := max (q+1) 1,
use t*(t+1),
have h₁ : t * (t + 1) ∈ K,
{ let x : ℚ := -(t + 1)/t^2,
let y : ℚ := t/(t+1)^2,
set z : ℚ := -t*(t+1) with hz_def,
simp only [set.mem_image, prod.exists],
use [x, y, z], split,
simp only [set.mem_set_of_eq],
{ use [x, y, z], split,
refl,
{ use t, split,
{ simp only [gt_iff_lt, lt_max_iff], right, exact zero_lt_one },
exact ⟨rfl, rfl, rfl⟩ } },
{ have hg : g(x, y, z) = -z := rfl,
rw [hg, hz_def], ring } },
have h₂ : q < t * (t + 1),
{ calc q < q + 1 : by linarith
... ≤ t : le_max_left (q + 1) 1
... ≤ t+t^2 : by linarith [sq_nonneg t]
... = t*(t+1) : by ring },
exact ⟨h₁, h₂⟩ },
have hK_inf : set.infinite K,
{ intro h, apply hK_not_bdd, exact set.finite.bdd_above h },
exact hK_inf.of_image g },
exact hW_inf.mono hW_sub_S,
end
end imo2008_q2
|
922c95c717b3d8cda131d60ecb87a816d022c39a
|
35677d2df3f081738fa6b08138e03ee36bc33cad
|
/src/analysis/complex/polynomial.lean
|
507b0f73584593c86e31133d7bca86c99f59b561
|
[
"Apache-2.0"
] |
permissive
|
gebner/mathlib
|
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
|
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
|
refs/heads/master
| 1,625,574,853,976
| 1,586,712,827,000
| 1,586,712,827,000
| 99,101,412
| 1
| 0
|
Apache-2.0
| 1,586,716,389,000
| 1,501,667,958,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 5,995
|
lean
|
/-
Copyright (c) 2019 Chris Hughes All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.polynomial topology.algebra.polynomial analysis.complex.exponential
open complex polynomial metric filter is_absolute_value set
namespace complex
lemma exists_forall_abs_polynomial_eval_le (p : polynomial ℂ) :
∃ x, ∀ y, (p.eval x).abs ≤ (p.eval y).abs :=
if hp0 : 0 < degree p
then let ⟨r, hr0, hr⟩ := polynomial.tendsto_infinity complex.abs hp0 ((p.eval 0).abs) in
let ⟨x, hx₁, hx₂⟩ := (proper_space.compact_ball (0:ℂ) r).exists_forall_le
⟨0, by simp [le_of_lt hr0]⟩
(continuous_abs.comp p.continuous_eval).continuous_on in
⟨x, λ y, if hy : y.abs ≤ r then hx₂ y $ by simpa [complex.dist_eq] using hy
else le_trans (hx₂ _ (by simp [le_of_lt hr0])) (le_of_lt (hr y (lt_of_not_ge hy)))⟩
else ⟨p.coeff 0, by rw [eq_C_of_degree_le_zero (le_of_not_gt hp0)]; simp⟩
/- The following proof uses the method given at
<https://ncatlab.org/nlab/show/fundamental+theorem+of+algebra#classical_fta_via_advanced_calculus> -/
/-- The fundamental theorem of algebra. Every non constant complex polynomial
has a root -/
lemma exists_root {f : polynomial ℂ} (hf : 0 < degree f) : ∃ z : ℂ, is_root f z :=
let ⟨z₀, hz₀⟩ := exists_forall_abs_polynomial_eval_le f in
exists.intro z₀ $ classical.by_contradiction $ λ hf0,
have hfX : f - C (f.eval z₀) ≠ 0,
from mt sub_eq_zero.1 (λ h, not_le_of_gt hf (h.symm ▸ degree_C_le)),
let n := root_multiplicity z₀ (f - C (f.eval z₀)) in
let g := (f - C (f.eval z₀)) /ₘ ((X - C z₀) ^ n) in
have hg0 : g.eval z₀ ≠ 0, from eval_div_by_monic_pow_root_multiplicity_ne_zero _ hfX,
have hg : g * (X - C z₀) ^ n = f - C (f.eval z₀),
from div_by_monic_mul_pow_root_multiplicity_eq _ _,
have hn0 : 0 < n, from nat.pos_of_ne_zero $ λ hn0, by simpa [g, hn0] using hg0,
let ⟨δ', hδ'₁, hδ'₂⟩ := continuous_iff.1 (polynomial.continuous_eval g) z₀
((g.eval z₀).abs) (complex.abs_pos.2 hg0) in
let δ := min (min (δ' / 2) 1) (((f.eval z₀).abs / (g.eval z₀).abs) / 2) in
have hf0' : 0 < (f.eval z₀).abs, from complex.abs_pos.2 hf0,
have hfg0 : 0 < abs (eval z₀ f) * (abs (eval z₀ g))⁻¹, from div_pos hf0' (complex.abs_pos.2 hg0),
have hδ0 : 0 < δ, from lt_min (lt_min (half_pos hδ'₁) (by norm_num)) (half_pos hfg0),
have hδ : ∀ z : ℂ, abs (z - z₀) = δ → abs (g.eval z - g.eval z₀) < (g.eval z₀).abs,
from λ z hz, hδ'₂ z (by rw [complex.dist_eq, hz];
exact lt_of_le_of_lt (le_trans (min_le_left _ _) (min_le_left _ _))
(half_lt_self hδ'₁)),
have hδ1 : δ ≤ 1, from le_trans (min_le_left _ _) (min_le_right _ _),
let F : polynomial ℂ := C (f.eval z₀) + C (g.eval z₀) * (X - C z₀) ^ n in
let z' := (-f.eval z₀ * (g.eval z₀).abs * δ ^ n /
((f.eval z₀).abs * g.eval z₀)) ^ (n⁻¹ : ℂ) + z₀ in
have hF₁ : F.eval z' = f.eval z₀ - f.eval z₀ * (g.eval z₀).abs * δ ^ n / (f.eval z₀).abs,
by simp only [F, cpow_nat_inv_pow _ hn0, div_eq_mul_inv, eval_pow, mul_assoc, mul_comm (g.eval z₀),
mul_left_comm (g.eval z₀), mul_left_comm (g.eval z₀)⁻¹, mul_inv', inv_mul_cancel hg0,
eval_C, eval_add, eval_neg, sub_eq_add_neg, eval_mul, eval_X, add_neg_cancel_right,
neg_mul_eq_neg_mul_symm, mul_one, div_eq_mul_inv];
simp only [mul_comm, mul_left_comm, mul_assoc],
have hδs : (g.eval z₀).abs * δ ^ n / (f.eval z₀).abs < 1,
by rw [div_eq_mul_inv, mul_right_comm, mul_comm, ← @inv_inv' _ _ (complex.abs _ * _), mul_inv',
inv_inv', ← div_eq_mul_inv, div_lt_iff hfg0, one_mul];
calc δ ^ n ≤ δ ^ 1 : pow_le_pow_of_le_one (le_of_lt hδ0) hδ1 hn0
... = δ : pow_one _
... ≤ ((f.eval z₀).abs / (g.eval z₀).abs) / 2 : min_le_right _ _
... < _ : half_lt_self hfg0,
have hF₂ : (F.eval z').abs = (f.eval z₀).abs - (g.eval z₀).abs * δ ^ n,
from calc (F.eval z').abs = (f.eval z₀ - f.eval z₀ * (g.eval z₀).abs
* δ ^ n / (f.eval z₀).abs).abs : congr_arg abs hF₁
... = abs (f.eval z₀) * complex.abs (1 - (g.eval z₀).abs * δ ^ n /
(f.eval z₀).abs : ℝ) : by rw [← complex.abs_mul];
exact congr_arg complex.abs
(by simp [mul_add, add_mul, mul_assoc, div_eq_mul_inv, sub_eq_add_neg])
... = _ : by rw [complex.abs_of_nonneg (sub_nonneg.2 (le_of_lt hδs)),
mul_sub, mul_div_cancel' _ (ne.symm (ne_of_lt hf0')), mul_one],
have hef0 : abs (eval z₀ g) * (eval z₀ f).abs ≠ 0,
from mul_ne_zero (mt complex.abs_eq_zero.1 hg0) (mt complex.abs_eq_zero.1 hf0),
have hz'z₀ : abs (z' - z₀) = δ,
by simp [z', mul_assoc, mul_left_comm _ (_ ^ n), mul_comm _ (_ ^ n),
mul_comm (eval z₀ f).abs, _root_.mul_div_cancel _ hef0, of_real_mul,
neg_mul_eq_neg_mul_symm, neg_div, is_absolute_value.abv_pow complex.abs,
complex.abs_of_nonneg (le_of_lt hδ0), real.pow_nat_rpow_nat_inv (le_of_lt hδ0) hn0],
have hF₃ : (f.eval z' - F.eval z').abs < (g.eval z₀).abs * δ ^ n,
from calc (f.eval z' - F.eval z').abs
= (g.eval z' - g.eval z₀).abs * (z' - z₀).abs ^ n :
by rw [← eq_sub_iff_add_eq.1 hg, ← is_absolute_value.abv_pow complex.abs,
← complex.abs_mul, sub_mul];
simp [F, eval_pow, eval_add, eval_mul, eval_sub, eval_C, eval_X, eval_neg, add_sub_cancel,
sub_eq_add_neg]
... = (g.eval z' - g.eval z₀).abs * δ ^ n : by rw hz'z₀
... < _ : (mul_lt_mul_right (pow_pos hδ0 _)).2 (hδ _ hz'z₀),
lt_irrefl (f.eval z₀).abs $
calc (f.eval z₀).abs ≤ (f.eval z').abs : hz₀ _
... = (F.eval z' + (f.eval z' - F.eval z')).abs : by simp
... ≤ (F.eval z').abs + (f.eval z' - F.eval z').abs : complex.abs_add _ _
... < (f.eval z₀).abs - (g.eval z₀).abs * δ ^ n + (g.eval z₀).abs * δ ^ n :
add_lt_add_of_le_of_lt (by rw hF₂) hF₃
... = (f.eval z₀).abs : sub_add_cancel _ _
end complex
|
e7d0ba0dfd88fecc3dcd003361f9859064599b15
|
205f0fc16279a69ea36e9fd158e3a97b06834ce2
|
/src/00_Introduction/02_inference_rules.lean
|
f207e7f765f71ec61ce3147e473ee798b9e5624d
|
[] |
no_license
|
kevinsullivan/cs-dm-lean
|
b21d3ca1a9b2a0751ba13fcb4e7b258010a5d124
|
a06a94e98be77170ca1df486c8189338b16cf6c6
|
refs/heads/master
| 1,585,948,743,595
| 1,544,339,346,000
| 1,544,339,346,000
| 155,570,767
| 1
| 3
| null | 1,541,540,372,000
| 1,540,995,993,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 4,088
|
lean
|
/- ** Inference rules ** -/
/-
So how do we decide whether a given proposition
can be judged to be true or not? Here is where
the semantics of a logic come into play.
The semantics of a logic comprises a set of rules,
called inference rules, that define the conditions
under which a given proposition can be judged to
be true.
Oversimplifying a bit, if you can apply one or more
inference rules to propositions you already know
to be true, and if by doing this you "deduce" some
new proposition, then you can conclude that that
new proposition must also be true. Such a "chain"
of inference rules, linking things already known
to be true to propositions that you want to prove
to be true because they follow logically is called
a proof. A valid proof is incontrovertible evidence
that the final proposition is true.
An inference rule is like a little program: it says,
if you can give me evidence (i.e., proofs) showing
that certain "input" propositions can be judged to
be true, then I will hand you back evidence (i.e.,
a proof) that shows that some new proposition can
also be judged to be true. We would say that from
the proofs of the premises (the input propositions
already known to be true), the rule derives or deduces
a proof of the conclusion.
Logicians often write inference rules like this:
list of input truth judgments
----------------------------- (name-of-rule)
truth judgment for conclusion
The required input judgments, called premises (or
antecedents), are listed above the line. The name
of the rule is given to the right of the line. And
the proposition (or consequent) that can thereby
be judged to be true (the conclusion of the rule)
is written below the line.
For example, if we already have the truth judgment,
(0 = 0 : true), and another, (1 = 1: true), then the
inference rule that logicians call "and introduction"
(or "conjunction introduction") can be used to derive
a truth judgment for the new proposition, "0 = 0 and
1 = 1", typically written as 0 = 0 ∧ 1 = 1. (Hover
your mouse over special symbols in this editor to
learn how to use them in your work.)
Predicate logic will thus (in effect) include such
inference rules as this:
0 = 0 : true, 1 = 1 : true
-------------------------- and-introduction-*
0 = 0 ∧ 1 = 1
This can be pronounced as, "If you already have
evidence (a proof) supporting the judgment that
0 = 0 is true, and if you also have evidence (a
proof) supporting the judgment that 1 = 1 is true,
then by applying the and-introduction-* rule,
you can deduce (obtain a proof justifying a truth
judgment for) the proposition, 0 = 0 ∧ 1 = 1".
We've put a * on the name of this rule to indicate
that it's really just a special case of a far more
general inference rule for reasoning about equality.
Inference rules are usually written not in terms of
very specific propositions, such as 0 = 0, but in
terms of variables that can refer to any arbitrary
propositions. They are often called meta-variables.
In this way, inference rules become program-like, in
that they can take arbitrary inputs (of the correct
types), and whenever they are given such inputs, they
produce result of a promised type.
Here's a simple example of such a parameterized and
thereby generalized rule. If P is *any* proposition
(e.g., it could be 0 = 0 but might be some other
proposition), and Q is another proposition (e.g.,
1 = 1), and if both propositions are already known
to be true, then you can always conclude that the
proposition "P and Q", written P ∧ Q, must also be
true, for whatever propositions P and Q happen to
be.
Here is how the general form of this inference rule
would typically be written in a book on logic.
P : true, Q : true
------------------ (and.intro)
P ∧ Q : true
The inference rule is called "and introduction"
because it produces a proof of a proposition
that now contains an "and" (∧). The rule can be
read as follows. If P and Q are propositions,
and if you have judged P to be true and you
have judged Q to be true, then you can judge
P ∧ Q to be true.
-/
|
ddfdc07a60d49173b4785702ac8b3aa4f48f4a73
|
5ae26df177f810c5006841e9c73dc56e01b978d7
|
/src/algebra/CommRing/default.lean
|
88f25393d05b1be2a4359464f6f755e41ca0a136
|
[
"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
| 254
|
lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.CommRing.basic
import algebra.CommRing.adjunctions
import algebra.CommRing.colimits
|
feaa3abcb13c1f04e6df512b1cf0098e21ee6499
|
bb31430994044506fa42fd667e2d556327e18dfe
|
/src/data/int/modeq.lean
|
493111c330de6fb258d73fde0c4ea77a06ae51ea
|
[
"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
| 7,689
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.nat.modeq
import tactic.ring
/-!
# Congruences modulo an integer
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the equivalence relation `a ≡ b [ZMOD n]` on the integers, similarly to how
`data.nat.modeq` defines them for the natural numbers. The notation is short for `n.modeq a b`,
which is defined to be `a % n = b % n` for integers `a b n`.
## Tags
modeq, congruence, mod, MOD, modulo, integers
-/
namespace int
/-- `a ≡ b [ZMOD n]` when `a % n = b % n`. -/
@[derive decidable]
def modeq (n a b : ℤ) := a % n = b % n
notation a ` ≡ `:50 b ` [ZMOD `:50 n `]`:0 := modeq n a b
variables {m n a b c d : ℤ}
namespace modeq
@[refl] protected theorem refl (a : ℤ) : a ≡ a [ZMOD n] := @rfl _ _
protected theorem rfl : a ≡ a [ZMOD n] := modeq.refl _
instance : is_refl _ (modeq n) := ⟨modeq.refl⟩
@[symm] protected theorem symm : a ≡ b [ZMOD n] → b ≡ a [ZMOD n] := eq.symm
@[trans] protected theorem trans : a ≡ b [ZMOD n] → b ≡ c [ZMOD n] → a ≡ c [ZMOD n] := eq.trans
end modeq
lemma coe_nat_modeq_iff {a b n : ℕ} : a ≡ b [ZMOD n] ↔ a ≡ b [MOD n] :=
by unfold modeq nat.modeq; rw ← int.coe_nat_eq_coe_nat_iff; simp [coe_nat_mod]
theorem modeq_zero_iff_dvd : a ≡ 0 [ZMOD n] ↔ n ∣ a :=
by rw [modeq, zero_mod, dvd_iff_mod_eq_zero]
lemma _root_.has_dvd.dvd.modeq_zero_int (h : n ∣ a) : a ≡ 0 [ZMOD n] := modeq_zero_iff_dvd.2 h
lemma _root_.has_dvd.dvd.zero_modeq_int (h : n ∣ a) : 0 ≡ a [ZMOD n] := h.modeq_zero_int.symm
theorem modeq_iff_dvd : a ≡ b [ZMOD n] ↔ n ∣ b - a :=
by rw [modeq, eq_comm];
simp [mod_eq_mod_iff_mod_sub_eq_zero, dvd_iff_mod_eq_zero]
theorem modeq_iff_add_fac {a b n : ℤ} : a ≡ b [ZMOD n] ↔ ∃ t, b = a + n * t :=
begin
rw modeq_iff_dvd,
exact exists_congr (λ t, sub_eq_iff_eq_add'),
end
alias modeq_iff_dvd ↔ modeq.dvd modeq_of_dvd
theorem mod_modeq (a n) : a % n ≡ a [ZMOD n] := mod_mod _ _
namespace modeq
protected lemma of_dvd (d : m ∣ n) (h : a ≡ b [ZMOD n]) : a ≡ b [ZMOD m] :=
modeq_of_dvd $ d.trans h.dvd
protected theorem mul_left' (hc : 0 ≤ c) (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD (c * n)] :=
or.cases_on hc.lt_or_eq (λ hc,
by unfold modeq;
simp [mul_mod_mul_of_pos hc, (show _ = _, from h)] )
(λ hc, by simp [hc.symm])
protected theorem mul_right' (hc : 0 ≤ c) (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD (n * c)] :=
by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' hc
protected theorem add (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a + c ≡ b + d [ZMOD n] :=
modeq_iff_dvd.2 $ by { convert dvd_add h₁.dvd h₂.dvd, ring }
protected theorem add_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c + a ≡ c + b [ZMOD n] :=
modeq.rfl.add h
protected theorem add_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a + c ≡ b + c [ZMOD n] :=
h.add modeq.rfl
protected theorem add_left_cancel (h₁ : a ≡ b [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) :
c ≡ d [ZMOD n] :=
have d - c = b + d - (a + c) - (b - a) := by ring,
modeq_iff_dvd.2 $ by { rw [this], exact dvd_sub h₂.dvd h₁.dvd }
protected theorem add_left_cancel' (c : ℤ) (h : c + a ≡ c + b [ZMOD n]) : a ≡ b [ZMOD n] :=
modeq.rfl.add_left_cancel h
protected theorem add_right_cancel (h₁ : c ≡ d [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) :
a ≡ b [ZMOD n] :=
by { rw [add_comm a, add_comm b] at h₂, exact h₁.add_left_cancel h₂ }
protected theorem add_right_cancel' (c : ℤ) (h : a + c ≡ b + c [ZMOD n]) : a ≡ b [ZMOD n] :=
modeq.rfl.add_right_cancel h
protected theorem neg (h : a ≡ b [ZMOD n]) : -a ≡ -b [ZMOD n] :=
h.add_left_cancel (by simp_rw [←sub_eq_add_neg, sub_self])
protected theorem sub (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) :
a - c ≡ b - d [ZMOD n] :=
by { rw [sub_eq_add_neg, sub_eq_add_neg], exact h₁.add h₂.neg }
protected theorem sub_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c - a ≡ c - b [ZMOD n] :=
modeq.rfl.sub h
protected theorem sub_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a - c ≡ b - c [ZMOD n] :=
h.sub modeq.rfl
protected theorem mul_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD n] :=
or.cases_on (le_total 0 c)
(λ hc, (h.mul_left' hc).of_dvd (dvd_mul_left _ _) )
(λ hc, by rw [← neg_neg c, neg_mul, neg_mul _ b];
exact ((h.mul_left' $ neg_nonneg.2 hc).of_dvd (dvd_mul_left _ _)).neg)
protected theorem mul_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n] :=
by { rw [mul_comm a, mul_comm b], exact h.mul_left c }
protected theorem mul (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a * c ≡ b * d [ZMOD n] :=
(h₂.mul_left _).trans (h₁.mul_right _)
protected theorem pow (m : ℕ) (h : a ≡ b [ZMOD n]) : a ^ m ≡ b ^ m [ZMOD n] :=
begin
induction m with d hd, {refl},
rw [pow_succ, pow_succ],
exact h.mul hd,
end
theorem of_mul_left (m : ℤ) (h : a ≡ b [ZMOD m * n]) : a ≡ b [ZMOD n] :=
by rw [modeq_iff_dvd] at *; exact (dvd_mul_left n m).trans h
theorem of_mul_right (m : ℤ) : a ≡ b [ZMOD n * m] → a ≡ b [ZMOD n] :=
mul_comm m n ▸ of_mul_left _
end modeq
theorem modeq_one : a ≡ b [ZMOD 1] := modeq_of_dvd (one_dvd _)
lemma modeq_sub (a b : ℤ) : a ≡ b [ZMOD a - b] :=
(modeq_of_dvd dvd_rfl).symm
lemma modeq_and_modeq_iff_modeq_mul {a b m n : ℤ} (hmn : m.nat_abs.coprime n.nat_abs) :
a ≡ b [ZMOD m] ∧ a ≡ b [ZMOD n] ↔ (a ≡ b [ZMOD m * n]) :=
⟨λ h, begin
rw [modeq_iff_dvd, modeq_iff_dvd] at h,
rw [modeq_iff_dvd, ← nat_abs_dvd, ← dvd_nat_abs,
coe_nat_dvd, nat_abs_mul],
refine hmn.mul_dvd_of_dvd_of_dvd _ _;
rw [← coe_nat_dvd, nat_abs_dvd, dvd_nat_abs]; tauto
end,
λ h, ⟨h.of_mul_right _, h.of_mul_left _⟩⟩
lemma gcd_a_modeq (a b : ℕ) : (a : ℤ) * nat.gcd_a a b ≡ nat.gcd a b [ZMOD b] :=
by { rw [← add_zero ((a : ℤ) * _), nat.gcd_eq_gcd_ab],
exact (dvd_mul_right _ _).zero_modeq_int.add_left _ }
theorem modeq_add_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a + n*c ≡ b [ZMOD n] :=
calc a + n*c ≡ b + n*c [ZMOD n] : ha.add_right _
... ≡ b + 0 [ZMOD n] : (dvd_mul_right _ _).modeq_zero_int.add_left _
... ≡ b [ZMOD n] : by rw add_zero
theorem modeq_add_fac_self {a t n : ℤ} : a + n * t ≡ a [ZMOD n] :=
modeq_add_fac _ modeq.rfl
lemma mod_coprime {a b : ℕ} (hab : nat.coprime a b) : ∃ y : ℤ, a * y ≡ 1 [ZMOD b] :=
⟨ nat.gcd_a a b,
have hgcd : nat.gcd a b = 1, from nat.coprime.gcd_eq_one hab,
calc
↑a * nat.gcd_a a b ≡ ↑a * nat.gcd_a a b + ↑b * nat.gcd_b a b [ZMOD ↑b] : modeq.symm $
modeq_add_fac _ $ modeq.refl _
... ≡ 1 [ZMOD ↑b] : by rw [← nat.gcd_eq_gcd_ab, hgcd]; reflexivity ⟩
lemma exists_unique_equiv (a : ℤ) {b : ℤ} (hb : 0 < b) : ∃ z : ℤ, 0 ≤ z ∧ z < b ∧ z ≡ a [ZMOD b] :=
⟨ a % b, mod_nonneg _ (ne_of_gt hb),
have a % b < |b|, from mod_lt _ (ne_of_gt hb),
by rwa abs_of_pos hb at this,
by simp [modeq] ⟩
lemma exists_unique_equiv_nat (a : ℤ) {b : ℤ} (hb : 0 < b) : ∃ z : ℕ, ↑z < b ∧ ↑z ≡ a [ZMOD b] :=
let ⟨z, hz1, hz2, hz3⟩ := exists_unique_equiv a hb in
⟨z.nat_abs, by split; rw [←of_nat_eq_coe, of_nat_nat_abs_eq_of_nonneg hz1]; assumption⟩
@[simp] lemma mod_mul_right_mod (a b c : ℤ) : a % (b * c) % b = a % b :=
(mod_modeq _ _).of_mul_right _
@[simp] lemma mod_mul_left_mod (a b c : ℤ) : a % (b * c) % c = a % c :=
(mod_modeq _ _).of_mul_left _
end int
|
ba3620ca3e9eb70118df4efef3a51bde8ff9d8ed
|
9028d228ac200bbefe3a711342514dd4e4458bff
|
/src/topology/bases.lean
|
1323150c04227cfe98f59c8eedbd2f8539d4ecc4
|
[
"Apache-2.0"
] |
permissive
|
mcncm/mathlib
|
8d25099344d9d2bee62822cb9ed43aa3e09fa05e
|
fde3d78cadeec5ef827b16ae55664ef115e66f57
|
refs/heads/master
| 1,672,743,316,277
| 1,602,618,514,000
| 1,602,618,514,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 14,240
|
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
Bases of topologies. Countability axioms.
-/
import topology.continuous_on
open set filter classical
open_locale topological_space filter
noncomputable theory
namespace topological_space
/- countability axioms
For our applications we are interested that there exists a countable basis, but we do not need the
concrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins.
-/
universe u
variables {α : Type u} [t : topological_space α]
include t
/-- A topological basis is one that satisfies the necessary conditions so that
it suffices to take unions of the basis sets to get a topology (without taking
finite intersections as well). -/
def is_topological_basis (s : set (set α)) : Prop :=
(∀t₁∈s, ∀t₂∈s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃∈s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂) ∧
(⋃₀ s) = univ ∧
t = generate_from s
lemma is_topological_basis_of_subbasis {s : set (set α)} (hs : t = generate_from s) :
is_topological_basis ((λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ (⋂₀ f).nonempty}) :=
let b' := (λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ (⋂₀ f).nonempty} in
⟨assume s₁ ⟨t₁, ⟨hft₁, ht₁b, ht₁⟩, eq₁⟩ s₂ ⟨t₂, ⟨hft₂, ht₂b, ht₂⟩, eq₂⟩,
have ie : ⋂₀(t₁ ∪ t₂) = ⋂₀ t₁ ∩ ⋂₀ t₂, from Inf_union,
eq₁ ▸ eq₂ ▸ assume x h,
⟨_, ⟨t₁ ∪ t₂, ⟨hft₁.union hft₂, union_subset ht₁b ht₂b,
ie.symm ▸ ⟨_, h⟩⟩, ie⟩, h, subset.refl _⟩,
eq_univ_iff_forall.2 $ assume a, ⟨univ, ⟨∅, ⟨finite_empty, empty_subset _,
by rw sInter_empty; exact ⟨a, mem_univ a⟩⟩, sInter_empty⟩, mem_univ _⟩,
have generate_from s = generate_from b',
from le_antisymm
(le_generate_from $ assume u ⟨t, ⟨hft, htb, ne⟩, eq⟩,
eq ▸ @is_open_sInter _ (generate_from s) _ hft (assume s hs, generate_open.basic _ $ htb hs))
(le_generate_from $ assume s hs,
s.eq_empty_or_nonempty.elim
(assume : s = ∅, by rw [this]; apply @is_open_empty _ _)
(assume : s.nonempty, generate_open.basic _ ⟨{s}, ⟨finite_singleton s, singleton_subset_iff.2 hs,
by rwa sInter_singleton⟩, sInter_singleton s⟩)),
this ▸ hs⟩
lemma is_topological_basis_of_open_of_nhds {s : set (set α)}
(h_open : ∀ u ∈ s, is_open u)
(h_nhds : ∀(a:α) (u : set α), a ∈ u → is_open u → ∃v ∈ s, a ∈ v ∧ v ⊆ u) :
is_topological_basis s :=
⟨assume t₁ ht₁ t₂ ht₂ x ⟨xt₁, xt₂⟩,
h_nhds x (t₁ ∩ t₂) ⟨xt₁, xt₂⟩
(is_open_inter (h_open _ ht₁) (h_open _ ht₂)),
eq_univ_iff_forall.2 $ assume a,
let ⟨u, h₁, h₂, _⟩ := h_nhds a univ trivial is_open_univ in
⟨u, h₁, h₂⟩,
le_antisymm
(le_generate_from h_open)
(assume u hu,
(@is_open_iff_nhds α (generate_from _) _).mpr $ assume a hau,
let ⟨v, hvs, hav, hvu⟩ := h_nhds a u hau hu in
by rw nhds_generate_from; exact infi_le_of_le v (infi_le_of_le ⟨hav, hvs⟩ $ le_principal_iff.2 hvu))⟩
lemma mem_nhds_of_is_topological_basis {a : α} {s : set α} {b : set (set α)}
(hb : is_topological_basis b) : s ∈ 𝓝 a ↔ ∃t∈b, a ∈ t ∧ t ⊆ s :=
begin
change s ∈ (𝓝 a).sets ↔ ∃t∈b, a ∈ t ∧ t ⊆ s,
rw [hb.2.2, nhds_generate_from, binfi_sets_eq],
{ simp only [mem_bUnion_iff, exists_prop, mem_set_of_eq, and_assoc, and.left_comm], refl },
{ exact assume s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩,
have a ∈ s ∩ t, from ⟨hs₁, ht₁⟩,
let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ this in
⟨u, ⟨hu₂, hu₁⟩, le_principal_iff.2 (subset.trans hu₃ (inter_subset_left _ _)),
le_principal_iff.2 (subset.trans hu₃ (inter_subset_right _ _))⟩ },
{ rcases eq_univ_iff_forall.1 hb.2.1 a with ⟨i, h1, h2⟩,
exact ⟨i, h2, h1⟩ }
end
lemma is_open_of_is_topological_basis {s : set α} {b : set (set α)}
(hb : is_topological_basis b) (hs : s ∈ b) : is_open s :=
is_open_iff_mem_nhds.2 $ λ a as,
(mem_nhds_of_is_topological_basis hb).2 ⟨s, hs, as, subset.refl _⟩
lemma mem_basis_subset_of_mem_open {b : set (set α)}
(hb : is_topological_basis b) {a:α} {u : set α} (au : a ∈ u)
(ou : is_open u) : ∃v ∈ b, a ∈ v ∧ v ⊆ u :=
(mem_nhds_of_is_topological_basis hb).1 $ mem_nhds_sets ou au
lemma sUnion_basis_of_is_open {B : set (set α)}
(hB : is_topological_basis B) {u : set α} (ou : is_open u) :
∃ S ⊆ B, u = ⋃₀ S :=
⟨{s ∈ B | s ⊆ u}, λ s h, h.1, set.ext $ λ a,
⟨λ ha, let ⟨b, hb, ab, bu⟩ := mem_basis_subset_of_mem_open hB ha ou in
⟨b, ⟨hb, bu⟩, ab⟩,
λ ⟨b, ⟨hb, bu⟩, ab⟩, bu ab⟩⟩
lemma Union_basis_of_is_open {B : set (set α)}
(hB : is_topological_basis B) {u : set α} (ou : is_open u) :
∃ (β : Type u) (f : β → set α), u = (⋃ i, f i) ∧ ∀ i, f i ∈ B :=
let ⟨S, sb, su⟩ := sUnion_basis_of_is_open hB ou in
⟨S, subtype.val, su.trans set.sUnion_eq_Union, λ ⟨b, h⟩, sb h⟩
variables (α)
/-- A separable space is one with a countable dense subset. -/
class separable_space : Prop :=
(exists_countable_closure_eq_univ : ∃s:set α, countable s ∧ closure s = univ)
lemma exists_countable_closure_eq_univ [separable_space α] :
∃ s : set α, countable s ∧ closure s = univ :=
separable_space.exists_countable_closure_eq_univ
lemma exists_countable_dense [separable_space α] :
∃ s : set α, countable s ∧ dense s :=
let ⟨s, hsc, hsd⟩ := exists_countable_closure_eq_univ α
in ⟨s, hsc, dense_iff_closure_eq.2 hsd⟩
lemma exists_dense_seq [separable_space α] [nonempty α] : ∃ u : ℕ → α, closure (range u) = univ :=
begin
obtain ⟨s : set α, hs, s_dense⟩ := @separable_space.exists_countable_closure_eq_univ α _ _,
cases countable_iff_exists_surjective.mp hs with u hu,
use u,
apply eq_univ_of_univ_subset,
simpa [s_dense] using closure_mono hu
end
/-- A sequence dense in a non-empty separable topological space. -/
def dense_seq [separable_space α] [nonempty α] : ℕ → α := classical.some (exists_dense_seq α)
@[simp] lemma dense_seq_dense [separable_space α] [nonempty α] :
closure (range $ dense_seq α) = univ := classical.some_spec (exists_dense_seq α)
end topological_space
open topological_space
lemma dense_range.separable_space {α β : Type*} [topological_space α] [separable_space α]
[topological_space β] {f : α → β} (h : dense_range f) (h' : continuous f) : separable_space β :=
let ⟨s, s_cnt, s_cl⟩ := exists_countable_closure_eq_univ α in
⟨⟨f '' s, countable.image s_cnt f, h'.dense_image_of_dense_range h (dense_iff_closure_eq.mpr s_cl)⟩⟩
namespace topological_space
universe u
variables (α : Type u) [t : topological_space α]
include t
/-- A first-countable space is one in which every point has a
countable neighborhood basis. -/
class first_countable_topology : Prop :=
(nhds_generated_countable : ∀a:α, (𝓝 a).is_countably_generated)
namespace first_countable_topology
variable {α}
lemma tendsto_subseq [first_countable_topology α] {u : ℕ → α} {x : α} (hx : map_cluster_pt x at_top u) :
∃ (ψ : ℕ → ℕ), (strict_mono ψ) ∧ (tendsto (u ∘ ψ) at_top (𝓝 x)) :=
(nhds_generated_countable x).subseq_tendsto hx
end first_countable_topology
variables {α}
lemma is_countably_generated_nhds [first_countable_topology α] (x : α) :
is_countably_generated (𝓝 x) :=
first_countable_topology.nhds_generated_countable x
lemma is_countably_generated_nhds_within [first_countable_topology α] (x : α) (s : set α) :
is_countably_generated (𝓝[s] x) :=
(is_countably_generated_nhds x).inf_principal s
variable (α)
/-- A second-countable space is one with a countable basis. -/
class second_countable_topology : Prop :=
(is_open_generated_countable [] : ∃b:set (set α), countable b ∧ t = topological_space.generate_from b)
@[priority 100] -- see Note [lower instance priority]
instance second_countable_topology.to_first_countable_topology
[second_countable_topology α] : first_countable_topology α :=
let ⟨b, hb, eq⟩ := second_countable_topology.is_open_generated_countable α in
⟨begin
intros,
rw [eq, nhds_generate_from],
exact is_countably_generated_binfi_principal (hb.mono (assume x, and.right)),
end⟩
lemma second_countable_topology_induced (β)
[t : topological_space β] [second_countable_topology β] (f : α → β) :
@second_countable_topology α (t.induced f) :=
begin
rcases second_countable_topology.is_open_generated_countable β with ⟨b, hb, eq⟩,
refine { is_open_generated_countable := ⟨preimage f '' b, hb.image _, _⟩ },
rw [eq, induced_generate_from_eq]
end
instance subtype.second_countable_topology
(s : set α) [second_countable_topology α] : second_countable_topology s :=
second_countable_topology_induced s α coe
lemma is_open_generated_countable_inter [second_countable_topology α] :
∃b:set (set α), countable b ∧ ∅ ∉ b ∧ is_topological_basis b :=
let ⟨b, hb₁, hb₂⟩ := second_countable_topology.is_open_generated_countable α in
let b' := (λs, ⋂₀ s) '' {s:set (set α) | finite s ∧ s ⊆ b ∧ (⋂₀ s).nonempty} in
⟨b',
((countable_set_of_finite_subset hb₁).mono
(by { simp only [← and_assoc], apply inter_subset_left })).image _,
assume ⟨s, ⟨_, _, hn⟩, hp⟩, absurd hn (not_nonempty_iff_eq_empty.2 hp),
is_topological_basis_of_subbasis hb₂⟩
/- TODO: more fine grained instances for first_countable_topology, separable_space, t2_space, ... -/
instance {β : Type*} [topological_space β]
[second_countable_topology α] [second_countable_topology β] : second_countable_topology (α × β) :=
⟨let ⟨a, ha₁, ha₂, ha₃, ha₄, ha₅⟩ := is_open_generated_countable_inter α in
let ⟨b, hb₁, hb₂, hb₃, hb₄, hb₅⟩ := is_open_generated_countable_inter β in
⟨{g | ∃u∈a, ∃v∈b, g = set.prod u v},
have {g | ∃u∈a, ∃v∈b, g = set.prod u v} = (⋃u∈a, ⋃v∈b, {set.prod u v}),
by apply set.ext; simp,
by rw [this]; exact (ha₁.bUnion $ assume u hu, hb₁.bUnion $ by simp),
by rw [ha₅, hb₅, prod_generate_from_generate_from_eq ha₄ hb₄]⟩⟩
instance second_countable_topology_fintype {ι : Type*} {π : ι → Type*}
[fintype ι] [t : ∀a, topological_space (π a)] [sc : ∀a, second_countable_topology (π a)] :
second_countable_topology (∀a, π a) :=
have ∀i, ∃b : set (set (π i)), countable b ∧ ∅ ∉ b ∧ is_topological_basis b, from
assume a, @is_open_generated_countable_inter (π a) _ (sc a),
let ⟨g, hg⟩ := classical.axiom_of_choice this in
have t = (λa, generate_from (g a)), from funext $ assume a, (hg a).2.2.2.2,
begin
constructor,
refine ⟨pi univ '' pi univ g, countable.image _ _, _⟩,
{ suffices : countable {f : Πa, set (π a) | ∀a, f a ∈ g a}, { simpa [pi] },
exact countable_pi (assume i, (hg i).1), },
rw [this, pi_generate_from_eq_fintype],
{ congr' 1 with f, simp [pi, eq_comm] },
exact assume a, (hg a).2.2.2.1
end
@[priority 100] -- see Note [lower instance priority]
instance second_countable_topology.to_separable_space
[second_countable_topology α] : separable_space α :=
begin
rcases is_open_generated_countable_inter α with ⟨b, hbc, hbne, hb, hbU, eq⟩,
set S : α → set (set α) := λ a, {s : set α | a ∈ s ∧ s ∈ b},
have nhds_eq : ∀a, 𝓝 a = (⨅ s ∈ S a, 𝓟 s),
{ intro a, rw [eq, nhds_generate_from] },
have : ∀ s ∈ b, set.nonempty s :=
assume s hs, ne_empty_iff_nonempty.1 $ λ eq, absurd hs (eq.symm ▸ hbne),
choose f hf,
refine ⟨⟨⋃ s ∈ b, {f s ‹_›}, hbc.bUnion (λ _ _, countable_singleton _), _⟩⟩,
refine eq_univ_of_forall (λ a, _),
suffices : (⨅ s ∈ S a, 𝓟 (s ∩ ⋃ t ∈ b, {f t ‹_›})).ne_bot,
{ obtain ⟨t, htb, hta⟩ : a ∈ ⋃₀ b, { simp only [hbU] },
have A : ∃ s, s ∈ S a := ⟨t, hta, htb⟩,
simpa only [← inf_principal, mem_closure_iff_cluster_pt,
cluster_pt, nhds_eq, binfi_inf A] using this },
rw [infi_subtype'],
haveI : nonempty α := ⟨a⟩,
refine infi_ne_bot_of_directed _ _,
{ rintros ⟨s₁, has₁, hs₁⟩ ⟨s₂, has₂, hs₂⟩,
obtain ⟨t, htb, hta, ht⟩ : ∃ t ∈ b, a ∈ t ∧ t ⊆ s₁ ∩ s₂,
from hb _ hs₁ _ hs₂ a ⟨has₁, has₂⟩,
refine ⟨⟨t, hta, htb⟩, _⟩,
simp only [subset_inter_iff] at ht,
simp only [principal_mono, subtype.coe_mk, (≥)],
exact ⟨inter_subset_inter_left _ ht.1, inter_subset_inter_left _ ht.2⟩ },
rintros ⟨s, hsa, hsb⟩,
suffices : (s ∩ ⋃ t ∈ b, {f t ‹_›}).nonempty, { simpa [principal_ne_bot_iff] },
refine ⟨_, hf _ hsb, _⟩,
simp only [mem_Union],
exact ⟨s, hsb, rfl⟩
end
variables {α}
lemma is_open_Union_countable [second_countable_topology α]
{ι} (s : ι → set α) (H : ∀ i, is_open (s i)) :
∃ T : set ι, countable T ∧ (⋃ i ∈ T, s i) = ⋃ i, s i :=
let ⟨B, cB, _, bB⟩ := is_open_generated_countable_inter α in
begin
let B' := {b ∈ B | ∃ i, b ⊆ s i},
choose f hf using λ b:B', b.2.2,
haveI : encodable B' := (cB.mono (sep_subset _ _)).to_encodable,
refine ⟨_, countable_range f,
subset.antisymm (bUnion_subset_Union _ _) (sUnion_subset _)⟩,
rintro _ ⟨i, rfl⟩ x xs,
rcases mem_basis_subset_of_mem_open bB xs (H _) with ⟨b, hb, xb, bs⟩,
exact ⟨_, ⟨_, rfl⟩, _, ⟨⟨⟨_, hb, _, bs⟩, rfl⟩, rfl⟩, hf _ (by exact xb)⟩
end
lemma is_open_sUnion_countable [second_countable_topology α]
(S : set (set α)) (H : ∀ s ∈ S, is_open s) :
∃ T : set (set α), countable T ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S :=
let ⟨T, cT, hT⟩ := is_open_Union_countable (λ s:S, s.1) (λ s, H s.1 s.2) in
⟨subtype.val '' T, cT.image _,
image_subset_iff.2 $ λ ⟨x, xs⟩ xt, xs,
by rwa [sUnion_image, sUnion_eq_Union]⟩
end topological_space
|
a914eb2375bfd061c7846474d9fe137a23421284
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/analysis/calculus/dslope.lean
|
418605813896e2dddcaab2e1027ecc8641d4871f
|
[
"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
| 6,288
|
lean
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.calculus.deriv
import linear_algebra.affine_space.slope
/-!
# Slope of a differentiable function
Given a function `f : 𝕜 → E` from a nondiscrete normed field to a normed space over this field,
`dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and as `deriv f a`
for `a = b`.
In this file we define `dslope` and prove some basic lemmas about its continuity and
differentiability.
-/
open_locale classical topological_space filter
open function set filter
variables {𝕜 E : Type*} [nondiscrete_normed_field 𝕜] [normed_group E] [normed_space 𝕜 E]
/-- `dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and
`deriv f a` for `a = b`. -/
noncomputable def dslope (f : 𝕜 → E) (a : 𝕜) : 𝕜 → E := update (slope f a) a (deriv f a)
@[simp] lemma dslope_same (f : 𝕜 → E) (a : 𝕜) : dslope f a a = deriv f a := update_same _ _ _
variables {f : 𝕜 → E} {a b : 𝕜} {s : set 𝕜}
lemma dslope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a b = slope f a b :=
update_noteq h _ _
lemma continuous_linear_map.dslope_comp {F : Type*} [normed_group F] [normed_space 𝕜 F]
(f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → differentiable_at 𝕜 g a) :
dslope (f ∘ g) a b = f (dslope g a b) :=
begin
rcases eq_or_ne b a with rfl|hne,
{ simp only [dslope_same],
exact (f.has_fderiv_at.comp_has_deriv_at b (H rfl).has_deriv_at).deriv },
{ simpa only [dslope_of_ne _ hne] using f.to_linear_map.slope_comp g a b }
end
lemma eq_on_dslope_slope (f : 𝕜 → E) (a : 𝕜) : eq_on (dslope f a) (slope f a) {a}ᶜ :=
λ b, dslope_of_ne f
lemma dslope_eventually_eq_slope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a =ᶠ[𝓝 b] slope f a :=
(eq_on_dslope_slope f a).eventually_eq_of_mem (is_open_ne.mem_nhds h)
lemma dslope_eventually_eq_slope_punctured_nhds (f : 𝕜 → E) : dslope f a =ᶠ[𝓝[≠] a] slope f a :=
(eq_on_dslope_slope f a).eventually_eq_of_mem self_mem_nhds_within
@[simp] lemma sub_smul_dslope (f : 𝕜 → E) (a b : 𝕜) : (b - a) • dslope f a b = f b - f a :=
by rcases eq_or_ne b a with rfl | hne; simp [dslope_of_ne, *]
lemma dslope_sub_smul_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope (λ x, (x - a) • f x) a b = f b :=
by rw [dslope_of_ne _ h, slope_sub_smul _ h.symm]
lemma eq_on_dslope_sub_smul (f : 𝕜 → E) (a : 𝕜) : eq_on (dslope (λ x, (x - a) • f x) a) f {a}ᶜ :=
λ b, dslope_sub_smul_of_ne f
lemma dslope_sub_smul [decidable_eq 𝕜] (f : 𝕜 → E) (a : 𝕜) :
dslope (λ x, (x - a) • f x) a = update f a (deriv (λ x, (x - a) • f x) a) :=
eq_update_iff.2 ⟨dslope_same _ _, eq_on_dslope_sub_smul f a⟩
@[simp] lemma continuous_at_dslope_same : continuous_at (dslope f a) a ↔ differentiable_at 𝕜 f a :=
by simp only [dslope, continuous_at_update_same, ← has_deriv_at_deriv_iff,
has_deriv_at_iff_tendsto_slope]
lemma continuous_within_at.of_dslope (h : continuous_within_at (dslope f a) s b) :
continuous_within_at f s b :=
have continuous_within_at (λ x, (x - a) • dslope f a x + f a) s b,
from ((continuous_within_at_id.sub continuous_within_at_const).smul h).add
continuous_within_at_const,
by simpa only [sub_smul_dslope, sub_add_cancel] using this
lemma continuous_at.of_dslope (h : continuous_at (dslope f a) b) : continuous_at f b :=
(continuous_within_at_univ _ _).1 h.continuous_within_at.of_dslope
lemma continuous_on.of_dslope (h : continuous_on (dslope f a) s) : continuous_on f s :=
λ x hx, (h x hx).of_dslope
lemma continuous_within_at_dslope_of_ne (h : b ≠ a) :
continuous_within_at (dslope f a) s b ↔ continuous_within_at f s b :=
begin
refine ⟨continuous_within_at.of_dslope, λ hc, _⟩,
simp only [dslope, continuous_within_at_update_of_ne h],
exact ((continuous_within_at_id.sub continuous_within_at_const).inv₀
(sub_ne_zero.2 h)).smul (hc.sub continuous_within_at_const)
end
lemma continuous_at_dslope_of_ne (h : b ≠ a) : continuous_at (dslope f a) b ↔ continuous_at f b :=
by simp only [← continuous_within_at_univ, continuous_within_at_dslope_of_ne h]
lemma continuous_on_dslope (h : s ∈ 𝓝 a) :
continuous_on (dslope f a) s ↔ continuous_on f s ∧ differentiable_at 𝕜 f a :=
begin
refine ⟨λ hc, ⟨hc.of_dslope, continuous_at_dslope_same.1 $ hc.continuous_at h⟩, _⟩,
rintro ⟨hc, hd⟩ x hx,
rcases eq_or_ne x a with rfl | hne,
exacts [(continuous_at_dslope_same.2 hd).continuous_within_at,
(continuous_within_at_dslope_of_ne hne).2 (hc x hx)]
end
lemma differentiable_within_at.of_dslope (h : differentiable_within_at 𝕜 (dslope f a) s b) :
differentiable_within_at 𝕜 f s b :=
by simpa only [id, sub_smul_dslope f a, sub_add_cancel]
using ((differentiable_within_at_id.sub_const a).smul h).add_const (f a)
lemma differentiable_at.of_dslope (h : differentiable_at 𝕜 (dslope f a) b) :
differentiable_at 𝕜 f b :=
differentiable_within_at_univ.1 h.differentiable_within_at.of_dslope
lemma differentiable_on.of_dslope (h : differentiable_on 𝕜 (dslope f a) s) :
differentiable_on 𝕜 f s :=
λ x hx, (h x hx).of_dslope
lemma differentiable_within_at_dslope_of_ne (h : b ≠ a) :
differentiable_within_at 𝕜 (dslope f a) s b ↔ differentiable_within_at 𝕜 f s b :=
begin
refine ⟨differentiable_within_at.of_dslope, λ hd, _⟩,
refine (((differentiable_within_at_id.sub_const a).inv
(sub_ne_zero.2 h)).smul (hd.sub_const (f a))).congr_of_eventually_eq _ (dslope_of_ne _ h),
refine (eq_on_dslope_slope _ _).eventually_eq_of_mem _,
exact mem_nhds_within_of_mem_nhds (is_open_ne.mem_nhds h)
end
lemma differentiable_on_dslope_of_nmem (h : a ∉ s) :
differentiable_on 𝕜 (dslope f a) s ↔ differentiable_on 𝕜 f s :=
forall_congr $ λ x, forall_congr $ λ hx, differentiable_within_at_dslope_of_ne $
ne_of_mem_of_not_mem hx h
lemma differentiable_at_dslope_of_ne (h : b ≠ a) :
differentiable_at 𝕜 (dslope f a) b ↔ differentiable_at 𝕜 f b :=
by simp only [← differentiable_within_at_univ,
differentiable_within_at_dslope_of_ne h]
|
90fe1dd8e6807d83ba7a9c21589cff2742204e45
|
8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3
|
/src/data/nat/basic.lean
|
d3f7a05f0fa5e2e4a48c26111cb916f79a3425ef
|
[
"Apache-2.0"
] |
permissive
|
troyjlee/mathlib
|
e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5
|
45e7eb8447555247246e3fe91c87066506c14875
|
refs/heads/master
| 1,689,248,035,046
| 1,629,470,528,000
| 1,629,470,528,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 58,225
|
lean
|
/-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import algebra.ordered_ring
import algebra.ordered_sub
/-!
# Basic operations on the natural numbers
This file contains:
- instances on the natural numbers
- some basic lemmas about natural numbers
- extra recursors:
* `le_rec_on`, `le_induction`: recursion and induction principles starting at non-zero numbers
* `decreasing_induction`: recursion growing downwards
* `strong_rec'`: recursion based on strong inequalities
- decidability instances on predicates about the natural numbers
-/
universes u v
/-! ### instances -/
instance : nontrivial ℕ :=
⟨⟨0, 1, nat.zero_ne_one⟩⟩
instance : comm_semiring nat :=
{ add := nat.add,
add_assoc := nat.add_assoc,
zero := nat.zero,
zero_add := nat.zero_add,
add_zero := nat.add_zero,
add_comm := nat.add_comm,
mul := nat.mul,
mul_assoc := nat.mul_assoc,
one := nat.succ nat.zero,
one_mul := nat.one_mul,
mul_one := nat.mul_one,
left_distrib := nat.left_distrib,
right_distrib := nat.right_distrib,
zero_mul := nat.zero_mul,
mul_zero := nat.mul_zero,
mul_comm := nat.mul_comm,
nsmul := λ m n, m * n,
nsmul_zero' := nat.zero_mul,
nsmul_succ' := λ n x,
by rw [nat.succ_eq_add_one, nat.add_comm, nat.right_distrib, nat.one_mul] }
instance : linear_ordered_semiring nat :=
{ add_left_cancel := @nat.add_left_cancel,
lt := nat.lt,
add_le_add_left := @nat.add_le_add_left,
le_of_add_le_add_left := @nat.le_of_add_le_add_left,
zero_le_one := nat.le_of_lt (nat.zero_lt_succ 0),
mul_lt_mul_of_pos_left := @nat.mul_lt_mul_of_pos_left,
mul_lt_mul_of_pos_right := @nat.mul_lt_mul_of_pos_right,
decidable_eq := nat.decidable_eq,
exists_pair_ne := ⟨0, 1, ne_of_lt nat.zero_lt_one⟩,
..nat.comm_semiring, ..nat.linear_order }
-- all the fields are already included in the linear_ordered_semiring instance
instance : linear_ordered_cancel_add_comm_monoid ℕ :=
{ add_left_cancel := @nat.add_left_cancel,
..nat.linear_ordered_semiring }
instance : linear_ordered_comm_monoid_with_zero ℕ :=
{ mul_le_mul_left := λ a b h c, nat.mul_le_mul_left c h,
..nat.linear_ordered_semiring,
..(infer_instance : comm_monoid_with_zero ℕ)}
/-! Extra instances to short-circuit type class resolution -/
instance : add_comm_monoid nat := by apply_instance
instance : add_monoid nat := by apply_instance
instance : monoid nat := by apply_instance
instance : comm_monoid nat := by apply_instance
instance : comm_semigroup nat := by apply_instance
instance : semigroup nat := by apply_instance
instance : add_comm_semigroup nat := by apply_instance
instance : add_semigroup nat := by apply_instance
instance : distrib nat := by apply_instance
instance : semiring nat := by apply_instance
instance : ordered_semiring nat := by apply_instance
instance : canonically_ordered_comm_semiring ℕ :=
{ le_iff_exists_add := assume a b,
⟨assume h, let ⟨c, hc⟩ := nat.le.dest h in ⟨c, hc.symm⟩,
assume ⟨c, hc⟩, hc.symm ▸ nat.le_add_right _ _⟩,
eq_zero_or_eq_zero_of_mul_eq_zero := assume a b, nat.eq_zero_of_mul_eq_zero,
bot := 0,
bot_le := nat.zero_le,
.. nat.nontrivial,
.. (infer_instance : ordered_add_comm_monoid ℕ),
.. (infer_instance : linear_ordered_semiring ℕ),
.. (infer_instance : comm_semiring ℕ) }
instance : canonically_linear_ordered_add_monoid ℕ :=
{ .. (infer_instance : canonically_ordered_add_monoid ℕ),
.. nat.linear_order }
instance nat.subtype.semilattice_sup_bot (s : set ℕ) [decidable_pred (∈ s)] [h : nonempty s] :
semilattice_sup_bot s :=
{ bot := ⟨nat.find (nonempty_subtype.1 h), nat.find_spec (nonempty_subtype.1 h)⟩,
bot_le := λ x, nat.find_min' _ x.2,
..subtype.linear_order s,
..lattice_of_linear_order }
theorem nat.nsmul_eq_mul (m n : ℕ) : m • n = m * n :=
rfl
theorem nat.eq_of_mul_eq_mul_right {n m k : ℕ} (Hm : 0 < m) (H : n * m = k * m) : n = k :=
by rw [mul_comm n m, mul_comm k m] at H; exact nat.eq_of_mul_eq_mul_left Hm H
instance nat.comm_cancel_monoid_with_zero : comm_cancel_monoid_with_zero ℕ :=
{ mul_left_cancel_of_ne_zero :=
λ _ _ _ h1 h2, nat.eq_of_mul_eq_mul_left (nat.pos_of_ne_zero h1) h2,
mul_right_cancel_of_ne_zero :=
λ _ _ _ h1 h2, nat.eq_of_mul_eq_mul_right (nat.pos_of_ne_zero h1) h2,
.. (infer_instance : comm_monoid_with_zero ℕ) }
attribute [simp] nat.not_lt_zero nat.succ_ne_zero nat.succ_ne_self
nat.zero_ne_one nat.one_ne_zero
nat.zero_ne_bit1 nat.bit1_ne_zero
nat.bit0_ne_one nat.one_ne_bit0
nat.bit0_ne_bit1 nat.bit1_ne_bit0
/-!
Inject some simple facts into the type class system.
This `fact` should not be confused with the factorial function `nat.fact`!
-/
section facts
instance succ_pos'' (n : ℕ) : fact (0 < n.succ) := ⟨n.succ_pos⟩
instance pos_of_one_lt (n : ℕ) [h : fact (1 < n)] : fact (0 < n) :=
⟨lt_trans zero_lt_one h.1⟩
end facts
variables {m n k : ℕ}
namespace nat
/-!
### Recursion and `set.range`
-/
section set
open set
theorem zero_union_range_succ : {0} ∪ range succ = univ :=
by { ext n, cases n; simp }
variables {α : Type*}
theorem range_of_succ (f : ℕ → α) : {f 0} ∪ range (f ∘ succ) = range f :=
by rw [← image_singleton, range_comp, ← image_union, zero_union_range_succ, image_univ]
theorem range_rec {α : Type*} (x : α) (f : ℕ → α → α) :
(set.range (λ n, nat.rec x f n) : set α) =
{x} ∪ set.range (λ n, nat.rec (f 0 x) (f ∘ succ) n) :=
begin
convert (range_of_succ _).symm,
ext n,
induction n with n ihn,
{ refl },
{ dsimp at ihn ⊢,
rw ihn }
end
theorem range_cases_on {α : Type*} (x : α) (f : ℕ → α) :
(set.range (λ n, nat.cases_on n x f) : set α) = {x} ∪ set.range f :=
(range_of_succ _).symm
end set
/-! ### The units of the natural numbers as a `monoid` and `add_monoid` -/
theorem units_eq_one (u : units ℕ) : u = 1 :=
units.ext $ nat.eq_one_of_dvd_one ⟨u.inv, u.val_inv.symm⟩
theorem add_units_eq_zero (u : add_units ℕ) : u = 0 :=
add_units.ext $ (nat.eq_zero_of_add_eq_zero u.val_neg).1
@[simp] protected theorem is_unit_iff {n : ℕ} : is_unit n ↔ n = 1 :=
iff.intro
(assume ⟨u, hu⟩, match n, u, hu, nat.units_eq_one u with _, _, rfl, rfl := rfl end)
(assume h, h.symm ▸ ⟨1, rfl⟩)
instance unique_units : unique (units ℕ) :=
{ default := 1, uniq := nat.units_eq_one }
instance unique_add_units : unique (add_units ℕ) :=
{ default := 0, uniq := nat.add_units_eq_zero }
/-! ### Equalities and inequalities involving zero and one -/
lemma one_lt_iff_ne_zero_and_ne_one : ∀ {n : ℕ}, 1 < n ↔ n ≠ 0 ∧ n ≠ 1
| 0 := dec_trivial
| 1 := dec_trivial
| (n+2) := dec_trivial
protected theorem mul_ne_zero {n m : ℕ} (n0 : n ≠ 0) (m0 : m ≠ 0) : n * m ≠ 0
| nm := (eq_zero_of_mul_eq_zero nm).elim n0 m0
@[simp] protected theorem mul_eq_zero {a b : ℕ} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
iff.intro eq_zero_of_mul_eq_zero (by simp [or_imp_distrib] {contextual := tt})
@[simp] protected theorem zero_eq_mul {a b : ℕ} : 0 = a * b ↔ a = 0 ∨ b = 0 :=
by rw [eq_comm, nat.mul_eq_zero]
lemma eq_zero_of_double_le {a : ℕ} (h : 2 * a ≤ a) : a = 0 :=
nat.eq_zero_of_le_zero $
by rwa [two_mul, nat.add_le_to_le_sub, nat.sub_self] at h; refl
lemma eq_zero_of_mul_le {a b : ℕ} (hb : 2 ≤ b) (h : b * a ≤ a) : a = 0 :=
eq_zero_of_double_le $ le_trans (nat.mul_le_mul_right _ hb) h
theorem le_zero_iff {i : ℕ} : i ≤ 0 ↔ i = 0 :=
⟨nat.eq_zero_of_le_zero, assume h, h ▸ le_refl i⟩
lemma zero_max {m : ℕ} : max 0 m = m :=
max_eq_right (zero_le _)
@[simp] lemma min_eq_zero_iff {m n : ℕ} : min m n = 0 ↔ m = 0 ∨ n = 0 :=
begin
split,
{ intro h,
cases le_total n m with H H,
{ simpa [H] using or.inr h },
{ simpa [H] using or.inl h } },
{ rintro (rfl|rfl);
simp }
end
@[simp] lemma max_eq_zero_iff {m n : ℕ} : max m n = 0 ↔ m = 0 ∧ n = 0 :=
begin
split,
{ intro h,
cases le_total n m with H H,
{ simp only [H, max_eq_left] at h,
exact ⟨h, le_antisymm (H.trans h.le) (zero_le _)⟩ },
{ simp only [H, max_eq_right] at h,
exact ⟨le_antisymm (H.trans h.le) (zero_le _), h⟩ } },
{ rintro ⟨rfl, rfl⟩,
simp }
end
lemma add_eq_max_iff {n m : ℕ} :
n + m = max n m ↔ n = 0 ∨ m = 0 :=
begin
rw ←min_eq_zero_iff,
cases le_total n m with H H;
simp [H]
end
lemma add_eq_min_iff {n m : ℕ} :
n + m = min n m ↔ n = 0 ∧ m = 0 :=
begin
rw ←max_eq_zero_iff,
cases le_total n m with H H;
simp [H]
end
lemma one_le_of_lt {n m : ℕ} (h : n < m) : 1 ≤ m :=
lt_of_le_of_lt (nat.zero_le _) h
theorem eq_one_of_mul_eq_one_right {m n : ℕ} (H : m * n = 1) : m = 1 :=
eq_one_of_dvd_one ⟨n, H.symm⟩
theorem eq_one_of_mul_eq_one_left {m n : ℕ} (H : m * n = 1) : n = 1 :=
eq_one_of_mul_eq_one_right (by rwa mul_comm)
/-! ### `succ` -/
lemma succ_eq_one_add (n : ℕ) : n.succ = 1 + n :=
by rw [nat.succ_eq_add_one, nat.add_comm]
theorem eq_of_lt_succ_of_not_lt {a b : ℕ} (h1 : a < b + 1) (h2 : ¬ a < b) : a = b :=
have h3 : a ≤ b, from le_of_lt_succ h1,
or.elim (eq_or_lt_of_not_lt h2) (λ h, h) (λ h, absurd h (not_lt_of_ge h3))
lemma eq_of_le_of_lt_succ {n m : ℕ} (h₁ : n ≤ m) (h₂ : m < n + 1) : m = n :=
nat.le_antisymm (le_of_succ_le_succ h₂) h₁
theorem one_add (n : ℕ) : 1 + n = succ n := by simp [add_comm]
@[simp] lemma succ_pos' {n : ℕ} : 0 < succ n := succ_pos n
theorem succ_inj' {n m : ℕ} : succ n = succ m ↔ n = m :=
⟨succ.inj, congr_arg _⟩
theorem succ_injective : function.injective nat.succ := λ x y, succ.inj
lemma succ_ne_succ {n m : ℕ} : succ n ≠ succ m ↔ n ≠ m :=
succ_injective.ne_iff
@[simp] lemma succ_succ_ne_one (n : ℕ) : n.succ.succ ≠ 1 :=
succ_ne_succ.mpr n.succ_ne_zero
@[simp] lemma one_lt_succ_succ (n : ℕ) : 1 < n.succ.succ :=
succ_lt_succ $ succ_pos n
theorem succ_le_succ_iff {m n : ℕ} : succ m ≤ succ n ↔ m ≤ n :=
⟨le_of_succ_le_succ, succ_le_succ⟩
theorem max_succ_succ {m n : ℕ} :
max (succ m) (succ n) = succ (max m n) :=
begin
by_cases h1 : m ≤ n,
rw [max_eq_right h1, max_eq_right (succ_le_succ h1)],
{ rw not_le at h1, have h2 := le_of_lt h1,
rw [max_eq_left h2, max_eq_left (succ_le_succ h2)] }
end
lemma not_succ_lt_self {n : ℕ} : ¬succ n < n :=
not_lt_of_ge (nat.le_succ _)
theorem lt_succ_iff {m n : ℕ} : m < succ n ↔ m ≤ n :=
⟨le_of_lt_succ, lt_succ_of_le⟩
lemma succ_le_iff {m n : ℕ} : succ m ≤ n ↔ m < n :=
⟨lt_of_succ_le, succ_le_of_lt⟩
lemma lt_iff_add_one_le {m n : ℕ} : m < n ↔ m + 1 ≤ n :=
by rw succ_le_iff
-- Just a restatement of `nat.lt_succ_iff` using `+1`.
lemma lt_add_one_iff {a b : ℕ} : a < b + 1 ↔ a ≤ b :=
lt_succ_iff
-- A flipped version of `lt_add_one_iff`.
lemma lt_one_add_iff {a b : ℕ} : a < 1 + b ↔ a ≤ b :=
by simp only [add_comm, lt_succ_iff]
-- This is true reflexively, by the definition of `≤` on ℕ,
-- but it's still useful to have, to convince Lean to change the syntactic type.
lemma add_one_le_iff {a b : ℕ} : a + 1 ≤ b ↔ a < b :=
iff.refl _
lemma one_add_le_iff {a b : ℕ} : 1 + a ≤ b ↔ a < b :=
by simp only [add_comm, add_one_le_iff]
theorem of_le_succ {n m : ℕ} (H : n ≤ m.succ) : n ≤ m ∨ n = m.succ :=
H.lt_or_eq_dec.imp le_of_lt_succ id
lemma succ_lt_succ_iff {m n : ℕ} : succ m < succ n ↔ m < n :=
⟨lt_of_succ_lt_succ, succ_lt_succ⟩
@[simp] lemma lt_one_iff {n : ℕ} : n < 1 ↔ n = 0 :=
lt_succ_iff.trans le_zero_iff
lemma div_le_iff_le_mul_add_pred {m n k : ℕ} (n0 : 0 < n) : m / n ≤ k ↔ m ≤ n * k + (n - 1) :=
begin
rw [← lt_succ_iff, div_lt_iff_lt_mul _ _ n0, succ_mul, mul_comm],
cases n, {cases n0},
exact lt_succ_iff,
end
/-! ### `add` -/
-- Sometimes a bare `nat.add` or similar appears as a consequence of unfolding
-- during pattern matching. These lemmas package them back up as typeclass
-- mediated operations.
@[simp] theorem add_def {a b : ℕ} : nat.add a b = a + b := rfl
@[simp] theorem mul_def {a b : ℕ} : nat.mul a b = a * b := rfl
attribute [simp] nat.add_sub_cancel nat.add_sub_cancel_left
attribute [simp] nat.sub_self
lemma exists_eq_add_of_le : ∀ {m n : ℕ}, m ≤ n → ∃ k : ℕ, n = m + k
| 0 0 h := ⟨0, by simp⟩
| 0 (n+1) h := ⟨n+1, by simp⟩
| (m+1) (n+1) h :=
let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in
⟨k, by simp [hk, add_comm, add_left_comm]⟩
lemma exists_eq_add_of_lt : ∀ {m n : ℕ}, m < n → ∃ k : ℕ, n = m + k + 1
| 0 0 h := false.elim $ lt_irrefl _ h
| 0 (n+1) h := ⟨n, by simp⟩
| (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in
⟨k, by simp [hk]⟩
theorem add_pos_left {m : ℕ} (h : 0 < m) (n : ℕ) : 0 < m + n :=
calc
m + n > 0 + n : nat.add_lt_add_right h n
... = n : nat.zero_add n
... ≥ 0 : zero_le n
theorem add_pos_right (m : ℕ) {n : ℕ} (h : 0 < n) : 0 < m + n :=
begin rw add_comm, exact add_pos_left h m end
theorem add_pos_iff_pos_or_pos (m n : ℕ) : 0 < m + n ↔ 0 < m ∨ 0 < n :=
iff.intro
begin
intro h,
cases m with m,
{simp [zero_add] at h, exact or.inr h},
exact or.inl (succ_pos _)
end
begin
intro h, cases h with mpos npos,
{ apply add_pos_left mpos },
apply add_pos_right _ npos
end
lemma add_eq_one_iff : ∀ {a b : ℕ}, a + b = 1 ↔ (a = 0 ∧ b = 1) ∨ (a = 1 ∧ b = 0)
| 0 0 := dec_trivial
| 0 1 := dec_trivial
| 1 0 := dec_trivial
| 1 1 := dec_trivial
| (a+2) _ := by rw add_right_comm; exact dec_trivial
| _ (b+2) := by rw [← add_assoc]; simp only [nat.succ_inj', nat.succ_ne_zero]; simp
theorem le_add_one_iff {i j : ℕ} : i ≤ j + 1 ↔ (i ≤ j ∨ i = j + 1) :=
⟨assume h,
match nat.eq_or_lt_of_le h with
| or.inl h := or.inr h
| or.inr h := or.inl $ nat.le_of_succ_le_succ h
end,
or.rec (assume h, le_trans h $ nat.le_add_right _ _) le_of_eq⟩
lemma add_succ_lt_add {a b c d : ℕ} (hab : a < b) (hcd : c < d) : a + c + 1 < b + d :=
begin
rw add_assoc,
exact add_lt_add_of_lt_of_le hab (nat.succ_le_iff.2 hcd)
end
-- TODO: generalize to some ordered add_monoids, based on #6145
lemma le_of_add_le_left {a b c : ℕ} (h : a + b ≤ c) : a ≤ c :=
by { refine le_trans _ h, simp }
lemma le_of_add_le_right {a b c : ℕ} (h : a + b ≤ c) : b ≤ c :=
by { refine le_trans _ h, simp }
/-! ### `pred` -/
@[simp]
lemma add_succ_sub_one (n m : ℕ) : (n + succ m) - 1 = n + m :=
by rw [add_succ, succ_sub_one]
@[simp]
lemma succ_add_sub_one (n m : ℕ) : (succ n + m) - 1 = n + m :=
by rw [succ_add, succ_sub_one]
lemma pred_eq_sub_one (n : ℕ) : pred n = n - 1 := rfl
theorem pred_eq_of_eq_succ {m n : ℕ} (H : m = n.succ) : m.pred = n := by simp [H]
@[simp] lemma pred_eq_succ_iff {n m : ℕ} : pred n = succ m ↔ n = m + 2 :=
by cases n; split; rintro ⟨⟩; refl
theorem pred_sub (n m : ℕ) : pred n - m = pred (n - m) :=
by rw [← nat.sub_one, nat.sub_sub, one_add]; refl
lemma le_pred_of_lt {n m : ℕ} (h : m < n) : m ≤ n - 1 :=
nat.sub_le_sub_right h 1
lemma le_of_pred_lt {m n : ℕ} : pred m < n → m ≤ n :=
match m with
| 0 := le_of_lt
| m+1 := id
end
/-- This ensures that `simp` succeeds on `pred (n + 1) = n`. -/
@[simp] lemma pred_one_add (n : ℕ) : pred (1 + n) = n :=
by rw [add_comm, add_one, pred_succ]
lemma pred_le_iff {n m : ℕ} : pred n ≤ m ↔ n ≤ succ m :=
⟨le_succ_of_pred_le, by { cases n, { exact λ h, zero_le m }, exact le_of_succ_le_succ }⟩
/-! ### `sub`
Todo: remove lemmas that are proven in general for `has_ordered_sub`. -/
protected theorem sub_le_iff_right : m - n ≤ k ↔ m ≤ k + n :=
begin
induction n with n ih generalizing k,
{ simp },
{ simp only [sub_succ, add_succ, succ_add, ih, pred_le_iff] }
end
instance : has_ordered_sub ℕ :=
⟨λ n m k, nat.sub_le_iff_right⟩
protected theorem le_sub_add (n m : ℕ) : n ≤ n - m + m :=
le_sub_add
protected theorem add_sub_cancel' {n m : ℕ} (h : m ≤ n) : m + (n - m) = n :=
add_sub_cancel_of_le h
protected theorem sub_add_sub_cancel {a b c : ℕ} (hab : b ≤ a) (hbc : c ≤ b) :
(a - b) + (b - c) = a - c :=
sub_add_sub_cancel'' hab hbc
protected theorem sub_eq_of_eq_add (h : k = m + n) : k - m = n :=
sub_eq_of_eq_add'' $ by rw [add_comm, h]
theorem sub_cancel {a b c : ℕ} (h₁ : a ≤ b) (h₂ : a ≤ c) (w : b - a = c - a) : b = c :=
sub_inj_left h₁ h₂ w
lemma sub_sub_sub_cancel_right {a b c : ℕ} (h₂ : c ≤ b) : (a - c) - (b - c) = a - b :=
sub_sub_sub_cancel_right' h₂
protected lemma sub_add_eq_add_sub {a b c : ℕ} (h : b ≤ a) : (a - b) + c = (a + c) - b :=
sub_add_eq_add_sub' h
theorem sub_sub_assoc {a b c : ℕ} (h₁ : b ≤ a) (h₂ : c ≤ b) : a - (b - c) = a - b + c :=
sub_sub_assoc h₁ h₂
protected theorem lt_of_sub_pos (h : 0 < n - m) : m < n :=
sub_pos_iff_lt.mp h
protected theorem lt_of_sub_lt_sub_right : m - k < n - k → m < n :=
lt_of_sub_lt_sub_right
protected theorem lt_of_sub_lt_sub_left : m - n < m - k → k < n :=
lt_of_sub_lt_sub_left
protected theorem sub_lt_self (h₁ : 0 < m) (h₂ : 0 < n) : m - n < m :=
sub_lt_self' h₁ h₂
protected theorem le_sub_right_of_add_le (h : m + k ≤ n) : m ≤ n - k :=
le_sub_of_add_le_right' h
protected theorem le_sub_left_of_add_le (h : k + m ≤ n) : m ≤ n - k :=
le_sub_of_add_le_left' h
protected theorem lt_sub_right_of_add_lt (h : m + k < n) : m < n - k :=
lt_sub_iff_right.mpr h
protected theorem lt_sub_left_of_add_lt (h : k + m < n) : m < n - k :=
lt_sub_iff_left.mpr h
protected theorem add_lt_of_lt_sub_right (h : m < n - k) : m + k < n :=
lt_sub_iff_right.mp h
protected theorem add_lt_of_lt_sub_left (h : m < n - k) : k + m < n :=
lt_sub_iff_left.mp h
protected theorem le_add_of_sub_le_right : n - k ≤ m → n ≤ m + k :=
sub_le_iff_right.mp
protected theorem le_add_of_sub_le_left : n - k ≤ m → n ≤ k + m :=
sub_le_iff_left.mp
protected theorem lt_add_of_sub_lt_right : n - k < m → n < m + k :=
lt_add_of_sub_lt_right'
protected theorem lt_add_of_sub_lt_left : n - k < m → n < k + m :=
lt_add_of_sub_lt_left'
protected theorem sub_le_left_of_le_add : n ≤ k + m → n - k ≤ m :=
sub_le_iff_left.mpr
protected theorem sub_le_right_of_le_add : n ≤ m + k → n - k ≤ m :=
sub_le_iff_right.mpr
protected theorem sub_lt_left_iff_lt_add (H : n ≤ k) : k - n < m ↔ k < n + m :=
sub_lt_iff_left H
protected theorem le_sub_left_iff_add_le (H : m ≤ k) : n ≤ k - m ↔ m + n ≤ k :=
le_sub_iff_left H
protected theorem le_sub_right_iff_add_le (H : n ≤ k) : m ≤ k - n ↔ m + n ≤ k :=
le_sub_iff_right H
protected theorem lt_sub_left_iff_add_lt : n < k - m ↔ m + n < k :=
lt_sub_iff_left
protected theorem lt_sub_right_iff_add_lt : m < k - n ↔ m + n < k :=
lt_sub_iff_right
theorem sub_le_left_iff_le_add : m - n ≤ k ↔ m ≤ n + k :=
sub_le_iff_left
theorem sub_le_right_iff_le_add : m - k ≤ n ↔ m ≤ n + k :=
sub_le_iff_right
protected theorem sub_lt_right_iff_lt_add (H : k ≤ m) : m - k < n ↔ m < n + k :=
sub_lt_iff_right H
protected theorem sub_le_sub_left_iff (H : k ≤ m) : m - n ≤ m - k ↔ k ≤ n :=
sub_le_sub_iff_left' H
protected theorem sub_lt_sub_right_iff (H : k ≤ m) : m - k < n - k ↔ m < n :=
sub_lt_sub_iff_right' H
protected theorem sub_lt_sub_left_iff (H : n ≤ m) : m - n < m - k ↔ k < n :=
sub_lt_sub_iff_left_of_le H
protected theorem sub_le_iff : m - n ≤ k ↔ m - k ≤ n :=
sub_le_iff_sub_le
protected lemma sub_le_self (n m : ℕ) : n - m ≤ n :=
sub_le_self'
protected theorem sub_lt_iff (h₁ : n ≤ m) (h₂ : k ≤ m) : m - n < k ↔ m - k < n :=
sub_lt_iff_sub_lt h₁ h₂
lemma lt_pred_iff {n m : ℕ} : n < pred m ↔ succ n < m :=
@nat.lt_sub_right_iff_add_lt n 1 m
lemma lt_of_lt_pred {a b : ℕ} (h : a < b - 1) : a < b :=
lt_of_succ_lt (lt_pred_iff.1 h)
lemma le_or_le_of_add_eq_add_pred {a b c d : ℕ} (h : c + d = a + b - 1) : a ≤ c ∨ b ≤ d :=
begin
cases le_or_lt a c with h' h'; [left, right],
{ exact h', },
{ replace h' := add_lt_add_right h' d, rw h at h',
cases b.eq_zero_or_pos with hb hb, { rw hb, exact zero_le d, },
rw [a.add_sub_assoc hb, add_lt_add_iff_left] at h',
exact nat.le_of_pred_lt h', },
end
@[simp] lemma add_sub_sub_cancel {a c : ℕ} (h : c ≤ a) (b : ℕ) : a + b - (a - c) = b + c :=
by rw [add_comm, nat.add_sub_assoc (nat.sub_le_self _ _), nat.sub_sub_self h]
/-! ### `mul` -/
lemma succ_mul_pos (m : ℕ) (hn : 0 < n) : 0 < (succ m) * n :=
mul_pos (succ_pos m) hn
theorem mul_self_le_mul_self {n m : ℕ} (h : n ≤ m) : n * n ≤ m * m :=
decidable.mul_le_mul h h (zero_le _) (zero_le _)
theorem mul_self_lt_mul_self : Π {n m : ℕ}, n < m → n * n < m * m
| 0 m h := mul_pos h h
| (succ n) m h := decidable.mul_lt_mul h (le_of_lt h) (succ_pos _) (zero_le _)
theorem mul_self_le_mul_self_iff {n m : ℕ} : n ≤ m ↔ n * n ≤ m * m :=
⟨mul_self_le_mul_self, le_imp_le_of_lt_imp_lt mul_self_lt_mul_self⟩
theorem mul_self_lt_mul_self_iff {n m : ℕ} : n < m ↔ n * n < m * m :=
le_iff_le_iff_lt_iff_lt.1 mul_self_le_mul_self_iff
theorem le_mul_self : Π (n : ℕ), n ≤ n * n
| 0 := le_refl _
| (n+1) := let t := nat.mul_le_mul_left (n+1) (succ_pos n) in by simp at t; exact t
lemma le_mul_of_pos_left {m n : ℕ} (h : 0 < n) : m ≤ n * m :=
begin
conv {to_lhs, rw [← one_mul(m)]},
exact decidable.mul_le_mul_of_nonneg_right (nat.succ_le_of_lt h) dec_trivial,
end
lemma le_mul_of_pos_right {m n : ℕ} (h : 0 < n) : m ≤ m * n :=
begin
conv {to_lhs, rw [← mul_one(m)]},
exact decidable.mul_le_mul_of_nonneg_left (nat.succ_le_of_lt h) dec_trivial,
end
theorem two_mul_ne_two_mul_add_one {n m} : 2 * n ≠ 2 * m + 1 :=
mt (congr_arg (%2)) (by { rw [add_comm, add_mul_mod_self_left, mul_mod_right, mod_eq_of_lt]; simp })
lemma mul_eq_one_iff : ∀ {a b : ℕ}, a * b = 1 ↔ a = 1 ∧ b = 1
| 0 0 := dec_trivial
| 0 1 := dec_trivial
| 1 0 := dec_trivial
| (a+2) 0 := by simp
| 0 (b+2) := by simp
| (a+1) (b+1) := ⟨
λ h, by simp only [add_mul, mul_add, mul_add, one_mul, mul_one,
(add_assoc _ _ _).symm, nat.succ_inj', add_eq_zero_iff] at h; simp [h.1.2, h.2],
λ h, by simp only [h, mul_one]⟩
protected theorem mul_left_inj {a b c : ℕ} (ha : 0 < a) : b * a = c * a ↔ b = c :=
⟨nat.eq_of_mul_eq_mul_right ha, λ e, e ▸ rfl⟩
protected theorem mul_right_inj {a b c : ℕ} (ha : 0 < a) : a * b = a * c ↔ b = c :=
⟨nat.eq_of_mul_eq_mul_left ha, λ e, e ▸ rfl⟩
lemma mul_left_injective {a : ℕ} (ha : 0 < a) : function.injective (λ x, x * a) :=
λ _ _, eq_of_mul_eq_mul_right ha
lemma mul_right_injective {a : ℕ} (ha : 0 < a) : function.injective (λ x, a * x) :=
λ _ _, nat.eq_of_mul_eq_mul_left ha
lemma mul_ne_mul_left {a b c : ℕ} (ha : 0 < a) : b * a ≠ c * a ↔ b ≠ c :=
(mul_left_injective ha).ne_iff
lemma mul_ne_mul_right {a b c : ℕ} (ha : 0 < a) : a * b ≠ a * c ↔ b ≠ c :=
(mul_right_injective ha).ne_iff
lemma mul_right_eq_self_iff {a b : ℕ} (ha : 0 < a) : a * b = a ↔ b = 1 :=
suffices a * b = a * 1 ↔ b = 1, by rwa mul_one at this,
nat.mul_right_inj ha
lemma mul_left_eq_self_iff {a b : ℕ} (hb : 0 < b) : a * b = b ↔ a = 1 :=
by rw [mul_comm, nat.mul_right_eq_self_iff hb]
lemma lt_succ_iff_lt_or_eq {n i : ℕ} : n < i.succ ↔ (n < i ∨ n = i) :=
lt_succ_iff.trans decidable.le_iff_lt_or_eq
theorem mul_self_inj {n m : ℕ} : n * n = m * m ↔ n = m :=
le_antisymm_iff.trans (le_antisymm_iff.trans
(and_congr mul_self_le_mul_self_iff mul_self_le_mul_self_iff)).symm
/-!
### Recursion and induction principles
This section is here due to dependencies -- the lemmas here require some of the lemmas
proved above, and some of the results in later sections depend on the definitions in this section.
-/
@[simp] lemma rec_zero {C : ℕ → Sort u} (h0 : C 0) (h : ∀ n, C n → C (n + 1)) :
(nat.rec h0 h : Π n, C n) 0 = h0 :=
rfl
@[simp] lemma rec_add_one {C : ℕ → Sort u} (h0 : C 0) (h : ∀ n, C n → C (n + 1)) (n : ℕ) :
(nat.rec h0 h : Π n, C n) (n + 1) = h n ((nat.rec h0 h : Π n, C n) n) :=
rfl
/-- Recursion starting at a non-zero number: given a map `C k → C (k+1)` for each `k`,
there is a map from `C n` to each `C m`, `n ≤ m`. -/
@[elab_as_eliminator]
def le_rec_on {C : ℕ → Sort u} {n : ℕ} : Π {m : ℕ}, n ≤ m → (Π {k}, C k → C (k+1)) → C n → C m
| 0 H next x := eq.rec_on (nat.eq_zero_of_le_zero H) x
| (m+1) H next x := or.by_cases (of_le_succ H) (λ h : n ≤ m, next $ le_rec_on h @next x)
(λ h : n = m + 1, eq.rec_on h x)
theorem le_rec_on_self {C : ℕ → Sort u} {n} {h : n ≤ n} {next} (x : C n) :
(le_rec_on h next x : C n) = x :=
by cases n; unfold le_rec_on or.by_cases; rw [dif_neg n.not_succ_le_self, dif_pos rfl]
theorem le_rec_on_succ {C : ℕ → Sort u} {n m} (h1 : n ≤ m) {h2 : n ≤ m+1} {next} (x : C n) :
(le_rec_on h2 @next x : C (m+1)) = next (le_rec_on h1 @next x : C m) :=
by conv { to_lhs, rw [le_rec_on, or.by_cases, dif_pos h1] }
theorem le_rec_on_succ' {C : ℕ → Sort u} {n} {h : n ≤ n+1} {next} (x : C n) :
(le_rec_on h next x : C (n+1)) = next x :=
by rw [le_rec_on_succ (le_refl n), le_rec_on_self]
theorem le_rec_on_trans {C : ℕ → Sort u} {n m k} (hnm : n ≤ m) (hmk : m ≤ k) {next} (x : C n) :
(le_rec_on (le_trans hnm hmk) @next x : C k) = le_rec_on hmk @next (le_rec_on hnm @next x) :=
begin
induction hmk with k hmk ih, { rw le_rec_on_self },
rw [le_rec_on_succ (le_trans hnm hmk), ih, le_rec_on_succ]
end
theorem le_rec_on_succ_left {C : ℕ → Sort u} {n m} (h1 : n ≤ m) (h2 : n+1 ≤ m)
{next : Π{{k}}, C k → C (k+1)} (x : C n) :
(le_rec_on h2 next (next x) : C m) = (le_rec_on h1 next x : C m) :=
begin
rw [subsingleton.elim h1 (le_trans (le_succ n) h2),
le_rec_on_trans (le_succ n) h2, le_rec_on_succ']
end
theorem le_rec_on_injective {C : ℕ → Sort u} {n m} (hnm : n ≤ m)
(next : Π n, C n → C (n+1)) (Hnext : ∀ n, function.injective (next n)) :
function.injective (le_rec_on hnm next) :=
begin
induction hnm with m hnm ih, { intros x y H, rwa [le_rec_on_self, le_rec_on_self] at H },
intros x y H, rw [le_rec_on_succ hnm, le_rec_on_succ hnm] at H, exact ih (Hnext _ H)
end
theorem le_rec_on_surjective {C : ℕ → Sort u} {n m} (hnm : n ≤ m)
(next : Π n, C n → C (n+1)) (Hnext : ∀ n, function.surjective (next n)) :
function.surjective (le_rec_on hnm next) :=
begin
induction hnm with m hnm ih, { intros x, use x, rw le_rec_on_self },
intros x, rcases Hnext _ x with ⟨w, rfl⟩, rcases ih w with ⟨x, rfl⟩, use x, rw le_rec_on_succ
end
/-- Recursion principle based on `<`. -/
@[elab_as_eliminator]
protected def strong_rec' {p : ℕ → Sort u} (H : ∀ n, (∀ m, m < n → p m) → p n) : ∀ (n : ℕ), p n
| n := H n (λ m hm, strong_rec' m)
/-- Recursion principle based on `<` applied to some natural number. -/
@[elab_as_eliminator]
def strong_rec_on' {P : ℕ → Sort*} (n : ℕ) (h : ∀ n, (∀ m, m < n → P m) → P n) : P n :=
nat.strong_rec' h n
theorem strong_rec_on_beta' {P : ℕ → Sort*} {h} {n : ℕ} :
(strong_rec_on' n h : P n) = h n (λ m hmn, (strong_rec_on' m h : P m)) :=
by { simp only [strong_rec_on'], rw nat.strong_rec' }
/-- Induction principle starting at a non-zero number. For maps to a `Sort*` see `le_rec_on`. -/
@[elab_as_eliminator] lemma le_induction {P : nat → Prop} {m}
(h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (n + 1)) :
∀ n, m ≤ n → P n :=
by apply nat.less_than_or_equal.rec h0; exact h1
/-- Decreasing induction: if `P (k+1)` implies `P k`, then `P n` implies `P m` for all `m ≤ n`.
Also works for functions to `Sort*`. -/
@[elab_as_eliminator]
def decreasing_induction {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n)
(hP : P n) : P m :=
le_rec_on mn (λ k ih hsk, ih $ h k hsk) (λ h, h) hP
@[simp] lemma decreasing_induction_self {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {n : ℕ}
(nn : n ≤ n) (hP : P n) : (decreasing_induction h nn hP : P n) = hP :=
by { dunfold decreasing_induction, rw [le_rec_on_self] }
lemma decreasing_induction_succ {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n)
(msn : m ≤ n + 1) (hP : P (n+1)) :
(decreasing_induction h msn hP : P m) = decreasing_induction h mn (h n hP) :=
by { dunfold decreasing_induction, rw [le_rec_on_succ] }
@[simp] lemma decreasing_induction_succ' {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m : ℕ}
(msm : m ≤ m + 1) (hP : P (m+1)) : (decreasing_induction h msm hP : P m) = h m hP :=
by { dunfold decreasing_induction, rw [le_rec_on_succ'] }
lemma decreasing_induction_trans {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n k : ℕ}
(mn : m ≤ n) (nk : n ≤ k) (hP : P k) :
(decreasing_induction h (le_trans mn nk) hP : P m) =
decreasing_induction h mn (decreasing_induction h nk hP) :=
by { induction nk with k nk ih, rw [decreasing_induction_self],
rw [decreasing_induction_succ h (le_trans mn nk), ih, decreasing_induction_succ] }
lemma decreasing_induction_succ_left {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ}
(smn : m + 1 ≤ n) (mn : m ≤ n) (hP : P n) :
(decreasing_induction h mn hP : P m) = h m (decreasing_induction h smn hP) :=
by { rw [subsingleton.elim mn (le_trans (le_succ m) smn), decreasing_induction_trans,
decreasing_induction_succ'] }
/-! ### `div` -/
attribute [simp] nat.div_self
protected lemma div_le_of_le_mul' {m n : ℕ} {k} (h : m ≤ k * n) : m / k ≤ n :=
(nat.eq_zero_or_pos k).elim
(λ k0, by rw [k0, nat.div_zero]; apply zero_le)
(λ k0, (_root_.mul_le_mul_left k0).1 $
calc k * (m / k)
≤ m % k + k * (m / k) : nat.le_add_left _ _
... = m : mod_add_div _ _
... ≤ k * n : h)
protected lemma div_le_self' (m n : ℕ) : m / n ≤ m :=
(nat.eq_zero_or_pos n).elim
(λ n0, by rw [n0, nat.div_zero]; apply zero_le)
(λ n0, nat.div_le_of_le_mul' $ calc
m = 1 * m : (one_mul _).symm
... ≤ n * m : nat.mul_le_mul_right _ n0)
/-- A version of `nat.div_lt_self` using successors, rather than additional hypotheses. -/
lemma div_lt_self' (n b : ℕ) : (n+1)/(b+2) < n+1 :=
nat.div_lt_self (nat.succ_pos n) (nat.succ_lt_succ (nat.succ_pos _))
theorem le_div_iff_mul_le' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x ≤ y / k ↔ x * k ≤ y :=
le_div_iff_mul_le x y k0
theorem div_lt_iff_lt_mul' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x / k < y ↔ x < y * k :=
lt_iff_lt_of_le_iff_le $ le_div_iff_mul_le' k0
protected theorem div_le_div_right {n m : ℕ} (h : n ≤ m) {k : ℕ} : n / k ≤ m / k :=
(nat.eq_zero_or_pos k).elim (λ k0, by simp [k0]) $ λ hk,
(le_div_iff_mul_le' hk).2 $ le_trans (nat.div_mul_le_self _ _) h
lemma lt_of_div_lt_div {m n k : ℕ} : m / k < n / k → m < n :=
lt_imp_lt_of_le_imp_le $ λ h, nat.div_le_div_right h
protected lemma div_pos {a b : ℕ} (hba : b ≤ a) (hb : 0 < b) : 0 < a / b :=
nat.pos_of_ne_zero (λ h, lt_irrefl a
(calc a = a % b : by simpa [h] using (mod_add_div a b).symm
... < b : nat.mod_lt a hb
... ≤ a : hba))
protected lemma div_lt_of_lt_mul {m n k : ℕ} (h : m < n * k) : m / n < k :=
lt_of_mul_lt_mul_left
(calc n * (m / n) ≤ m % n + n * (m / n) : nat.le_add_left _ _
... = m : mod_add_div _ _
... < n * k : h)
(nat.zero_le n)
lemma lt_mul_of_div_lt {a b c : ℕ} (h : a / c < b) (w : 0 < c) : a < b * c :=
lt_of_not_ge $ not_le_of_gt h ∘ (nat.le_div_iff_mul_le _ _ w).2
protected lemma div_eq_zero_iff {a b : ℕ} (hb : 0 < b) : a / b = 0 ↔ a < b :=
⟨λ h, by rw [← mod_add_div a b, h, mul_zero, add_zero]; exact mod_lt _ hb,
λ h, by rw [← nat.mul_right_inj hb, ← @add_left_cancel_iff _ _ (a % b), mod_add_div,
mod_eq_of_lt h, mul_zero, add_zero]⟩
protected lemma div_eq_zero {a b : ℕ} (hb : a < b) : a / b = 0 :=
(nat.div_eq_zero_iff $ (zero_le a).trans_lt hb).mpr hb
lemma eq_zero_of_le_div {a b : ℕ} (hb : 2 ≤ b) (h : a ≤ a / b) : a = 0 :=
eq_zero_of_mul_le hb $
by rw mul_comm; exact (nat.le_div_iff_mul_le' (lt_of_lt_of_le dec_trivial hb)).1 h
lemma mul_div_le_mul_div_assoc (a b c : ℕ) : a * (b / c) ≤ (a * b) / c :=
if hc0 : c = 0 then by simp [hc0]
else (nat.le_div_iff_mul_le _ _ (nat.pos_of_ne_zero hc0)).2
(by rw [mul_assoc]; exact nat.mul_le_mul_left _ (nat.div_mul_le_self _ _))
lemma div_mul_div_le_div (a b c : ℕ) : ((a / c) * b) / a ≤ b / c :=
if ha0 : a = 0 then by simp [ha0]
else calc a / c * b / a ≤ b * a / c / a :
nat.div_le_div_right (by rw [mul_comm];
exact mul_div_le_mul_div_assoc _ _ _)
... = b / c : by rw [nat.div_div_eq_div_mul, mul_comm b, mul_comm c,
nat.mul_div_mul _ _ (nat.pos_of_ne_zero ha0)]
lemma eq_zero_of_le_half {a : ℕ} (h : a ≤ a / 2) : a = 0 :=
eq_zero_of_le_div (le_refl _) h
protected theorem eq_mul_of_div_eq_right {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) :
a = b * c :=
by rw [← H2, nat.mul_div_cancel' H1]
protected theorem div_eq_iff_eq_mul_right {a b c : ℕ} (H : 0 < b) (H' : b ∣ a) :
a / b = c ↔ a = b * c :=
⟨nat.eq_mul_of_div_eq_right H', nat.div_eq_of_eq_mul_right H⟩
protected theorem div_eq_iff_eq_mul_left {a b c : ℕ} (H : 0 < b) (H' : b ∣ a) :
a / b = c ↔ a = c * b :=
by rw mul_comm; exact nat.div_eq_iff_eq_mul_right H H'
protected theorem eq_mul_of_div_eq_left {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) :
a = c * b :=
by rw [mul_comm, nat.eq_mul_of_div_eq_right H1 H2]
protected theorem mul_div_cancel_left' {a b : ℕ} (Hd : a ∣ b) : a * (b / a) = b :=
by rw [mul_comm,nat.div_mul_cancel Hd]
/-- Alias of `nat.mul_div_mul` -/ --TODO: Update `nat.mul_div_mul` in the core?
protected lemma mul_div_mul_left (a b : ℕ) {c : ℕ} (hc : 0 < c) : c * a / (c * b) = a / b :=
nat.mul_div_mul a b hc
protected lemma mul_div_mul_right (a b : ℕ) {c : ℕ} (hc : 0 < c) : a * c / (b * c) = a / b :=
by rw [mul_comm, mul_comm b, a.mul_div_mul_left b hc]
/-! ### `mod`, `dvd` -/
lemma div_add_mod (m k : ℕ) : k * (m / k) + m % k = m :=
(nat.add_comm _ _).trans (mod_add_div _ _)
lemma mod_add_div' (m k : ℕ) : m % k + (m / k) * k = m :=
by { rw mul_comm, exact mod_add_div _ _ }
lemma div_add_mod' (m k : ℕ) : (m / k) * k + m % k = m :=
by { rw mul_comm, exact div_add_mod _ _ }
protected theorem div_mod_unique {n k m d : ℕ} (h : 0 < k) :
n / k = d ∧ n % k = m ↔ m + k * d = n ∧ m < k :=
⟨λ ⟨e₁, e₂⟩, e₁ ▸ e₂ ▸ ⟨mod_add_div _ _, mod_lt _ h⟩,
λ ⟨h₁, h₂⟩, h₁ ▸ by rw [add_mul_div_left _ _ h, add_mul_mod_self_left];
simp [div_eq_of_lt, mod_eq_of_lt, h₂]⟩
lemma two_mul_odd_div_two {n : ℕ} (hn : n % 2 = 1) : 2 * (n / 2) = n - 1 :=
by conv {to_rhs, rw [← nat.mod_add_div n 2, hn, nat.add_sub_cancel_left]}
lemma div_dvd_of_dvd {a b : ℕ} (h : b ∣ a) : (a / b) ∣ a :=
⟨b, (nat.div_mul_cancel h).symm⟩
protected lemma div_div_self : ∀ {a b : ℕ}, b ∣ a → 0 < a → a / (a / b) = b
| a 0 h₁ h₂ := by rw [eq_zero_of_zero_dvd h₁, nat.div_zero, nat.div_zero]
| 0 b h₁ h₂ := absurd h₂ dec_trivial
| (a+1) (b+1) h₁ h₂ :=
(nat.mul_left_inj (nat.div_pos (le_of_dvd (succ_pos a) h₁) (succ_pos b))).1 $
by rw [nat.div_mul_cancel (div_dvd_of_dvd h₁), nat.mul_div_cancel' h₁]
lemma mod_mul_right_div_self (a b c : ℕ) : a % (b * c) / b = (a / b) % c :=
begin
rcases nat.eq_zero_or_pos b with rfl|hb, { simp },
rcases nat.eq_zero_or_pos c with rfl|hc, { simp },
conv_rhs { rw ← mod_add_div a (b * c) },
rw [mul_assoc, nat.add_mul_div_left _ _ hb, add_mul_mod_self_left,
mod_eq_of_lt (nat.div_lt_of_lt_mul (mod_lt _ (mul_pos hb hc)))]
end
lemma mod_mul_left_div_self (a b c : ℕ) : a % (c * b) / b = (a / b) % c :=
by rw [mul_comm c, mod_mul_right_div_self]
@[simp] protected theorem dvd_one {n : ℕ} : n ∣ 1 ↔ n = 1 :=
⟨eq_one_of_dvd_one, λ e, e.symm ▸ dvd_refl _⟩
protected theorem dvd_add_left {k m n : ℕ} (h : k ∣ n) : k ∣ m + n ↔ k ∣ m :=
(nat.dvd_add_iff_left h).symm
protected theorem dvd_add_right {k m n : ℕ} (h : k ∣ m) : k ∣ m + n ↔ k ∣ n :=
(nat.dvd_add_iff_right h).symm
@[simp] protected theorem not_two_dvd_bit1 (n : ℕ) : ¬ 2 ∣ bit1 n :=
by { rw [bit1, nat.dvd_add_right two_dvd_bit0, nat.dvd_one], cc }
/-- A natural number `m` divides the sum `m + n` if and only if `m` divides `n`.-/
@[simp] protected lemma dvd_add_self_left {m n : ℕ} :
m ∣ m + n ↔ m ∣ n :=
nat.dvd_add_right (dvd_refl m)
/-- A natural number `m` divides the sum `n + m` if and only if `m` divides `n`.-/
@[simp] protected lemma dvd_add_self_right {m n : ℕ} :
m ∣ n + m ↔ m ∣ n :=
nat.dvd_add_left (dvd_refl m)
-- TODO: update `nat.dvd_sub` in core
lemma dvd_sub' {k m n : ℕ} (h₁ : k ∣ m) (h₂ : k ∣ n) : k ∣ m - n :=
begin
cases le_total n m with H H,
{ exact dvd_sub H h₁ h₂ },
{ rw nat.sub_eq_zero_of_le H,
exact dvd_zero k },
end
lemma not_dvd_of_pos_of_lt {a b : ℕ} (h1 : 0 < b) (h2 : b < a) : ¬ a ∣ b :=
begin
rintros ⟨c, rfl⟩,
rcases nat.eq_zero_or_pos c with (rfl | hc),
{ exact lt_irrefl 0 h1 },
{ exact not_lt.2 (le_mul_of_pos_right hc) h2 },
end
protected theorem mul_dvd_mul_iff_left {a b c : ℕ} (ha : 0 < a) : a * b ∣ a * c ↔ b ∣ c :=
exists_congr $ λ d, by rw [mul_assoc, nat.mul_right_inj ha]
protected theorem mul_dvd_mul_iff_right {a b c : ℕ} (hc : 0 < c) : a * c ∣ b * c ↔ a ∣ b :=
exists_congr $ λ d, by rw [mul_right_comm, nat.mul_left_inj hc]
lemma succ_div : ∀ (a b : ℕ), (a + 1) / b =
a / b + if b ∣ a + 1 then 1 else 0
| a 0 := by simp
| 0 1 := by simp
| 0 (b+2) := have hb2 : b + 2 > 1, from dec_trivial,
by simp [ne_of_gt hb2, div_eq_of_lt hb2]
| (a+1) (b+1) := begin
rw [nat.div_def], conv_rhs { rw nat.div_def },
by_cases hb_eq_a : b = a + 1,
{ simp [hb_eq_a, le_refl] },
by_cases hb_le_a1 : b ≤ a + 1,
{ have hb_le_a : b ≤ a, from le_of_lt_succ (lt_of_le_of_ne hb_le_a1 hb_eq_a),
have h₁ : (0 < b + 1 ∧ b + 1 ≤ a + 1 + 1),
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a1⟩,
have h₂ : (0 < b + 1 ∧ b + 1 ≤ a + 1),
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a⟩,
have dvd_iff : b + 1 ∣ a - b + 1 ↔ b + 1 ∣ a + 1 + 1,
{ rw [nat.dvd_add_iff_left (dvd_refl (b + 1)),
← nat.add_sub_add_right a 1 b, add_comm (_ - _), add_assoc,
nat.sub_add_cancel (succ_le_succ hb_le_a), add_comm 1] },
have wf : a - b < a + 1, from lt_succ_of_le (nat.sub_le_self _ _),
rw [if_pos h₁, if_pos h₂, nat.add_sub_add_right, nat.sub_add_comm hb_le_a,
by exact have _ := wf, succ_div (a - b),
nat.add_sub_add_right],
simp [dvd_iff, succ_eq_add_one, add_comm 1, add_assoc] },
{ have hba : ¬ b ≤ a,
from not_le_of_gt (lt_trans (lt_succ_self a) (lt_of_not_ge hb_le_a1)),
have hb_dvd_a : ¬ b + 1 ∣ a + 2,
from λ h, hb_le_a1 (le_of_succ_le_succ (le_of_dvd (succ_pos _) h)),
simp [hba, hb_le_a1, hb_dvd_a], }
end
lemma succ_div_of_dvd {a b : ℕ} (hba : b ∣ a + 1) :
(a + 1) / b = a / b + 1 :=
by rw [succ_div, if_pos hba]
lemma succ_div_of_not_dvd {a b : ℕ} (hba : ¬ b ∣ a + 1) :
(a + 1) / b = a / b :=
by rw [succ_div, if_neg hba, add_zero]
@[simp] theorem mod_mod_of_dvd (n : nat) {m k : nat} (h : m ∣ k) : n % k % m = n % m :=
begin
conv { to_rhs, rw ←mod_add_div n k },
rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left]
end
@[simp] theorem mod_mod (a n : ℕ) : (a % n) % n = a % n :=
(nat.eq_zero_or_pos n).elim
(λ n0, by simp [n0])
(λ npos, mod_eq_of_lt (mod_lt _ npos))
/-- If `a` and `b` are equal mod `c`, `a - b` is zero mod `c`. -/
lemma sub_mod_eq_zero_of_mod_eq {a b c : ℕ} (h : a % c = b % c) : (a - b) % c = 0 :=
by rw [←nat.mod_add_div a c, ←nat.mod_add_div b c, ←h, ←nat.sub_sub, nat.add_sub_cancel_left,
←nat.mul_sub_left_distrib, nat.mul_mod_right]
@[simp] lemma one_mod (n : ℕ) : 1 % (n + 2) = 1 := nat.mod_eq_of_lt (add_lt_add_right n.succ_pos 1)
lemma dvd_sub_mod (k : ℕ) : n ∣ (k - (k % n)) :=
⟨k / n, nat.sub_eq_of_eq_add (nat.mod_add_div k n).symm⟩
@[simp] theorem mod_add_mod (m n k : ℕ) : (m % n + k) % n = (m + k) % n :=
by have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm;
rwa [add_right_comm, mod_add_div] at this
@[simp] theorem add_mod_mod (m n k : ℕ) : (m + n % k) % k = (m + n) % k :=
by rw [add_comm, mod_add_mod, add_comm]
lemma add_mod (a b n : ℕ) : (a + b) % n = ((a % n) + (b % n)) % n :=
by rw [add_mod_mod, mod_add_mod]
theorem add_mod_eq_add_mod_right {m n k : ℕ} (i : ℕ) (H : m % n = k % n) :
(m + i) % n = (k + i) % n :=
by rw [← mod_add_mod, ← mod_add_mod k, H]
theorem add_mod_eq_add_mod_left {m n k : ℕ} (i : ℕ) (H : m % n = k % n) :
(i + m) % n = (i + k) % n :=
by rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm]
lemma add_mod_eq_ite {a b n : ℕ} :
(a + b) % n = if n ≤ a % n + b % n then a % n + b % n - n else a % n + b % n :=
begin
cases n, { simp },
rw nat.add_mod,
split_ifs with h,
{ rw [nat.mod_eq_sub_mod h, nat.mod_eq_of_lt],
exact (nat.sub_lt_right_iff_lt_add h).mpr
(nat.add_lt_add (a.mod_lt n.zero_lt_succ) (b.mod_lt n.zero_lt_succ)) },
{ exact nat.mod_eq_of_lt (lt_of_not_ge h) }
end
lemma mul_mod (a b n : ℕ) : (a * b) % n = ((a % n) * (b % n)) % n :=
begin
conv_lhs {
rw [←mod_add_div a n, ←mod_add_div' b n, right_distrib, left_distrib, left_distrib,
mul_assoc, mul_assoc, ←left_distrib n _ _, add_mul_mod_self_left, ← mul_assoc,
add_mul_mod_self_right] }
end
lemma dvd_div_of_mul_dvd {a b c : ℕ} (h : a * b ∣ c) : b ∣ c / a :=
if ha : a = 0 then
by simp [ha]
else
have ha : 0 < a, from nat.pos_of_ne_zero ha,
have h1 : ∃ d, c = a * b * d, from h,
let ⟨d, hd⟩ := h1 in
have h2 : c / a = b * d, from nat.div_eq_of_eq_mul_right ha (by simpa [mul_assoc] using hd),
show ∃ d, c / a = b * d, from ⟨d, h2⟩
lemma mul_dvd_of_dvd_div {a b c : ℕ} (hab : c ∣ b) (h : a ∣ b / c) : c * a ∣ b :=
have h1 : ∃ d, b / c = a * d, from h,
have h2 : ∃ e, b = c * e, from hab,
let ⟨d, hd⟩ := h1, ⟨e, he⟩ := h2 in
have h3 : b = a * d * c, from
nat.eq_mul_of_div_eq_left hab hd,
show ∃ d, b = c * a * d, from ⟨d, by cc⟩
lemma div_mul_div {a b c d : ℕ} (hab : b ∣ a) (hcd : d ∣ c) :
(a / b) * (c / d) = (a * c) / (b * d) :=
have exi1 : ∃ x, a = b * x, from hab,
have exi2 : ∃ y, c = d * y, from hcd,
if hb : b = 0 then by simp [hb]
else have 0 < b, from nat.pos_of_ne_zero hb,
if hd : d = 0 then by simp [hd]
else have 0 < d, from nat.pos_of_ne_zero hd,
begin
cases exi1 with x hx, cases exi2 with y hy,
rw [hx, hy, nat.mul_div_cancel_left, nat.mul_div_cancel_left],
symmetry,
apply nat.div_eq_of_eq_mul_left,
apply mul_pos,
repeat {assumption},
cc
end
@[simp]
lemma div_div_div_eq_div : ∀ {a b c : ℕ} (dvd : b ∣ a) (dvd2 : a ∣ c), (c / (a / b)) / b = c / a
| 0 _ := by simp
| (a + 1) 0 := λ _ dvd _, by simpa using dvd
| (a + 1) (c + 1) :=
have a_split : a + 1 ≠ 0 := succ_ne_zero a,
have c_split : c + 1 ≠ 0 := succ_ne_zero c,
λ b dvd dvd2,
begin
rcases dvd2 with ⟨k, rfl⟩,
rcases dvd with ⟨k2, pr⟩,
have k2_nonzero : k2 ≠ 0 := λ k2_zero, by simpa [k2_zero] using pr,
rw [nat.mul_div_cancel_left k (nat.pos_of_ne_zero a_split), pr,
nat.mul_div_cancel_left k2 (nat.pos_of_ne_zero c_split), nat.mul_comm ((c + 1) * k2) k,
←nat.mul_assoc k (c + 1) k2, nat.mul_div_cancel _ (nat.pos_of_ne_zero k2_nonzero),
nat.mul_div_cancel _ (nat.pos_of_ne_zero c_split)],
end
lemma eq_of_dvd_of_div_eq_one {a b : ℕ} (w : a ∣ b) (h : b / a = 1) : a = b :=
by rw [←nat.div_mul_cancel w, h, one_mul]
lemma eq_zero_of_dvd_of_div_eq_zero {a b : ℕ} (w : a ∣ b) (h : b / a = 0) : b = 0 :=
by rw [←nat.div_mul_cancel w, h, zero_mul]
/-- If a small natural number is divisible by a larger natural number,
the small number is zero. -/
lemma eq_zero_of_dvd_of_lt {a b : ℕ} (w : a ∣ b) (h : b < a) : b = 0 :=
nat.eq_zero_of_dvd_of_div_eq_zero w
((nat.div_eq_zero_iff (lt_of_le_of_lt (zero_le b) h)).elim_right h)
lemma div_le_div_left {a b c : ℕ} (h₁ : c ≤ b) (h₂ : 0 < c) : a / b ≤ a / c :=
(nat.le_div_iff_mul_le _ _ h₂).2 $
le_trans (nat.mul_le_mul_left _ h₁) (div_mul_le_self _ _)
lemma div_eq_self {a b : ℕ} : a / b = a ↔ a = 0 ∨ b = 1 :=
begin
split,
{ intro,
cases b,
{ simp * at * },
{ cases b,
{ right, refl },
{ left,
have : a / (b + 2) ≤ a / 2 := div_le_div_left (by simp) dec_trivial,
refine eq_zero_of_le_half _,
simp * at * } } },
{ rintros (rfl|rfl); simp }
end
lemma lt_iff_le_pred : ∀ {m n : ℕ}, 0 < n → (m < n ↔ m ≤ n - 1)
| m (n+1) _ := lt_succ_iff
lemma div_eq_sub_mod_div {m n : ℕ} : m / n = (m - m % n) / n :=
begin
by_cases n0 : n = 0,
{ rw [n0, nat.div_zero, nat.div_zero] },
{ rw [← mod_add_div m n] { occs := occurrences.pos [2] },
rw [nat.add_sub_cancel_left, mul_div_right _ (nat.pos_of_ne_zero n0)] }
end
lemma mul_div_le (m n : ℕ) : n * (m / n) ≤ m :=
begin
cases nat.eq_zero_or_pos n with n0 h,
{ rw [n0, zero_mul], exact m.zero_le },
{ rw [mul_comm, ← nat.le_div_iff_mul_le' h] },
end
lemma lt_mul_div_succ (m : ℕ) {n : ℕ} (n0 : 0 < n) : m < n * ((m / n) + 1) :=
begin
rw [mul_comm, ← nat.div_lt_iff_lt_mul' n0],
exact lt_succ_self _
end
@[simp] lemma mod_div_self (m n : ℕ) : m % n / n = 0 :=
begin
cases n,
{ exact (m % 0).div_zero },
{ exact nat.div_eq_zero (m.mod_lt n.succ_pos) }
end
/-- `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)` for some `k`. -/
lemma exists_lt_and_lt_iff_not_dvd (m : ℕ) {n : ℕ} (hn : 0 < n) :
(∃ k, n * k < m ∧ m < n * (k + 1)) ↔ ¬ n ∣ m :=
begin
split,
{ rintro ⟨k, h1k, h2k⟩ ⟨l, rfl⟩, rw [mul_lt_mul_left hn] at h1k h2k,
rw [lt_succ_iff, ← not_lt] at h2k, exact h2k h1k },
{ intro h, rw [dvd_iff_mod_eq_zero, ← ne.def, ← pos_iff_ne_zero] at h,
simp only [← mod_add_div m n] {single_pass := tt},
refine ⟨m / n, lt_add_of_pos_left _ h, _⟩,
rw [add_comm _ 1, left_distrib, mul_one], exact add_lt_add_right (mod_lt _ hn) _ }
end
/-- Two natural numbers are equal if and only if the have the same multiples. -/
lemma dvd_right_iff_eq {m n : ℕ} : (∀ a : ℕ, m ∣ a ↔ n ∣ a) ↔ m = n :=
⟨λ h, dvd_antisymm ((h _).mpr (dvd_refl _)) ((h _).mp (dvd_refl _)), λ h n, by rw h⟩
/-- Two natural numbers are equal if and only if the have the same divisors. -/
lemma dvd_left_iff_eq {m n : ℕ} : (∀ a : ℕ, a ∣ m ↔ a ∣ n) ↔ m = n :=
⟨λ h, dvd_antisymm ((h _).mp (dvd_refl _)) ((h _).mpr (dvd_refl _)), λ h n, by rw h⟩
/-- `dvd` is injective in the left argument -/
lemma dvd_left_injective : function.injective ((∣) : ℕ → ℕ → Prop) :=
λ m n h, dvd_right_iff_eq.mp $ λ a, iff_of_eq (congr_fun h a)
/-! ### `find` -/
section find
variables {p q : ℕ → Prop} [decidable_pred p] [decidable_pred q]
lemma find_eq_iff (h : ∃ n : ℕ, p n) : nat.find h = m ↔ p m ∧ ∀ n < m, ¬ p n :=
begin
split,
{ rintro rfl, exact ⟨nat.find_spec h, λ _, nat.find_min h⟩ },
{ rintro ⟨hm, hlt⟩,
exact le_antisymm (nat.find_min' h hm) (not_lt.1 $ imp_not_comm.1 (hlt _) $ nat.find_spec h) }
end
@[simp] lemma find_lt_iff (h : ∃ n : ℕ, p n) (n : ℕ) : nat.find h < n ↔ ∃ m < n, p m :=
⟨λ h2, ⟨nat.find h, h2, nat.find_spec h⟩, λ ⟨m, hmn, hm⟩, (nat.find_min' h hm).trans_lt hmn⟩
@[simp] lemma find_le_iff (h : ∃ n : ℕ, p n) (n : ℕ) : nat.find h ≤ n ↔ ∃ m ≤ n, p m :=
by simp only [exists_prop, ← lt_succ_iff, find_lt_iff]
@[simp] lemma le_find_iff (h : ∃ (n : ℕ), p n) (n : ℕ) : n ≤ nat.find h ↔ ∀ m < n, ¬ p m :=
by simp_rw [← not_lt, find_lt_iff, not_exists]
@[simp] lemma lt_find_iff (h : ∃ n : ℕ, p n) (n : ℕ) : n < nat.find h ↔ ∀ m ≤ n, ¬ p m :=
by simp only [← succ_le_iff, le_find_iff, succ_le_succ_iff]
@[simp] lemma find_eq_zero (h : ∃ n : ℕ, p n) : nat.find h = 0 ↔ p 0 :=
by simp [find_eq_iff]
@[simp] lemma find_pos (h : ∃ n : ℕ, p n) : 0 < nat.find h ↔ ¬ p 0 :=
by rw [pos_iff_ne_zero, ne, nat.find_eq_zero]
theorem find_le (h : ∀ n, q n → p n) (hp : ∃ n, p n) (hq : ∃ n, q n) :
nat.find hp ≤ nat.find hq :=
nat.find_min' _ (h _ (nat.find_spec hq))
lemma find_comp_succ (h₁ : ∃ n, p n) (h₂ : ∃ n, p (n + 1)) (h0 : ¬ p 0) :
nat.find h₁ = nat.find h₂ + 1 :=
begin
refine (find_eq_iff _).2 ⟨nat.find_spec h₂, λ n hn, _⟩,
cases n with n,
exacts [h0, @nat.find_min (λ n, p (n + 1)) _ h₂ _ (succ_lt_succ_iff.1 hn)]
end
end find
/-! ### `find_greatest` -/
section find_greatest
/-- `find_greatest P b` is the largest `i ≤ bound` such that `P i` holds, or `0` if no such `i`
exists -/
protected def find_greatest (P : ℕ → Prop) [decidable_pred P] : ℕ → ℕ
| 0 := 0
| (n + 1) := if P (n + 1) then n + 1 else find_greatest n
variables {P : ℕ → Prop} [decidable_pred P]
@[simp] lemma find_greatest_zero : nat.find_greatest P 0 = 0 := rfl
@[simp] lemma find_greatest_eq : ∀{b}, P b → nat.find_greatest P b = b
| 0 h := rfl
| (n + 1) h := by simp [nat.find_greatest, h]
@[simp] lemma find_greatest_of_not {b} (h : ¬ P (b + 1)) :
nat.find_greatest P (b + 1) = nat.find_greatest P b :=
by simp [nat.find_greatest, h]
lemma find_greatest_eq_iff {b m} :
nat.find_greatest P b = m ↔ m ≤ b ∧ (m ≠ 0 → P m) ∧ (∀ ⦃n⦄, m < n → n ≤ b → ¬P n) :=
begin
induction b with b ihb generalizing m,
{ rw [eq_comm, iff.comm],
simp only [nonpos_iff_eq_zero, ne.def, and_iff_left_iff_imp, find_greatest_zero],
rintro rfl,
exact ⟨λ h, (h rfl).elim, λ n hlt heq, (hlt.ne heq.symm).elim⟩ },
{ by_cases hb : P (b + 1),
{ rw [find_greatest_eq hb], split,
{ rintro rfl,
exact ⟨le_refl _, λ _, hb, λ n hlt hle, (hlt.not_le hle).elim⟩ },
{ rintros ⟨hle, h0, hm⟩,
rcases decidable.eq_or_lt_of_le hle with rfl|hlt,
exacts [rfl, (hm hlt (le_refl _) hb).elim] } },
{ rw [find_greatest_of_not hb, ihb],
split,
{ rintros ⟨hle, hP, hm⟩,
refine ⟨hle.trans b.le_succ, hP, λ n hlt hle, _⟩,
rcases decidable.eq_or_lt_of_le hle with rfl|hlt',
exacts [hb, hm hlt $ lt_succ_iff.1 hlt'] },
{ rintros ⟨hle, hP, hm⟩,
refine ⟨lt_succ_iff.1 (hle.lt_of_ne _), hP, λ n hlt hle, hm hlt (hle.trans b.le_succ)⟩,
rintro rfl,
exact hb (hP b.succ_ne_zero) } } }
end
lemma find_greatest_eq_zero_iff {b} :
nat.find_greatest P b = 0 ↔ ∀ ⦃n⦄, 0 < n → n ≤ b → ¬P n :=
by simp [find_greatest_eq_iff]
lemma find_greatest_spec {b} (h : ∃m, m ≤ b ∧ P m) : P (nat.find_greatest P b) :=
begin
rcases h with ⟨m, hmb, hm⟩,
by_cases h : nat.find_greatest P b = 0,
{ cases m, { rwa h },
exact ((find_greatest_eq_zero_iff.1 h) m.zero_lt_succ hmb hm).elim },
{ exact (find_greatest_eq_iff.1 rfl).2.1 h }
end
lemma find_greatest_le {b} : nat.find_greatest P b ≤ b :=
(find_greatest_eq_iff.1 rfl).1
lemma le_find_greatest {b m} (hmb : m ≤ b) (hm : P m) : m ≤ nat.find_greatest P b :=
le_of_not_lt $ λ hlt, (find_greatest_eq_iff.1 rfl).2.2 hlt hmb hm
lemma find_greatest_is_greatest {b k} (hk : nat.find_greatest P b < k) (hkb : k ≤ b) :
¬ P k :=
(find_greatest_eq_iff.1 rfl).2.2 hk hkb
lemma find_greatest_of_ne_zero {b m} (h : nat.find_greatest P b = m) (h0 : m ≠ 0) : P m :=
(find_greatest_eq_iff.1 h).2.1 h0
end find_greatest
/-! ### `bodd_div2` and `bodd` -/
@[simp] theorem bodd_div2_eq (n : ℕ) : bodd_div2 n = (bodd n, div2 n) :=
by unfold bodd div2; cases bodd_div2 n; refl
@[simp] lemma bodd_bit0 (n) : bodd (bit0 n) = ff := bodd_bit ff n
@[simp] lemma bodd_bit1 (n) : bodd (bit1 n) = tt := bodd_bit tt n
@[simp] lemma div2_bit0 (n) : div2 (bit0 n) = n := div2_bit ff n
@[simp] lemma div2_bit1 (n) : div2 (bit1 n) = n := div2_bit tt n
/-! ### `bit0` and `bit1` -/
-- There is no need to prove `bit0_eq_zero : bit0 n = 0 ↔ n = 0`
-- as this is true for any `[semiring R] [no_zero_divisors R] [char_zero R]`
-- However the lemmas `bit0_eq_bit0`, `bit1_eq_bit1`, `bit1_eq_one`, `one_eq_bit1`
-- need `[ring R] [no_zero_divisors R] [char_zero R]` in general,
-- so we prove `ℕ` specialized versions here.
@[simp] lemma bit0_eq_bit0 {m n : ℕ} : bit0 m = bit0 n ↔ m = n :=
⟨nat.bit0_inj, λ h, by subst h⟩
@[simp] lemma bit1_eq_bit1 {m n : ℕ} : bit1 m = bit1 n ↔ m = n :=
⟨nat.bit1_inj, λ h, by subst h⟩
@[simp] lemma bit1_eq_one {n : ℕ} : bit1 n = 1 ↔ n = 0 :=
⟨@nat.bit1_inj n 0, λ h, by subst h⟩
@[simp] lemma one_eq_bit1 {n : ℕ} : 1 = bit1 n ↔ n = 0 :=
⟨λ h, (@nat.bit1_inj 0 n h).symm, λ h, by subst h⟩
protected theorem bit0_le {n m : ℕ} (h : n ≤ m) : bit0 n ≤ bit0 m :=
add_le_add h h
protected theorem bit1_le {n m : ℕ} (h : n ≤ m) : bit1 n ≤ bit1 m :=
succ_le_succ (add_le_add h h)
theorem bit_le : ∀ (b : bool) {n m : ℕ}, n ≤ m → bit b n ≤ bit b m
| tt n m h := nat.bit1_le h
| ff n m h := nat.bit0_le h
theorem bit_ne_zero (b) {n} (h : n ≠ 0) : bit b n ≠ 0 :=
by cases b; [exact nat.bit0_ne_zero h, exact nat.bit1_ne_zero _]
theorem bit0_le_bit : ∀ (b) {m n : ℕ}, m ≤ n → bit0 m ≤ bit b n
| tt m n h := le_of_lt $ nat.bit0_lt_bit1 h
| ff m n h := nat.bit0_le h
theorem bit_le_bit1 : ∀ (b) {m n : ℕ}, m ≤ n → bit b m ≤ bit1 n
| ff m n h := le_of_lt $ nat.bit0_lt_bit1 h
| tt m n h := nat.bit1_le h
theorem bit_lt_bit0 : ∀ (b) {n m : ℕ}, n < m → bit b n < bit0 m
| tt n m h := nat.bit1_lt_bit0 h
| ff n m h := nat.bit0_lt h
theorem bit_lt_bit (a b) {n m : ℕ} (h : n < m) : bit a n < bit b m :=
lt_of_lt_of_le (bit_lt_bit0 _ h) (bit0_le_bit _ (le_refl _))
@[simp] lemma bit0_le_bit1_iff : bit0 k ≤ bit1 n ↔ k ≤ n :=
⟨λ h, by rwa [← nat.lt_succ_iff, n.bit1_eq_succ_bit0, ← n.bit0_succ_eq,
bit0_lt_bit0, nat.lt_succ_iff] at h, λ h, le_of_lt (nat.bit0_lt_bit1 h)⟩
@[simp] lemma bit0_lt_bit1_iff : bit0 k < bit1 n ↔ k ≤ n :=
⟨λ h, bit0_le_bit1_iff.1 (le_of_lt h), nat.bit0_lt_bit1⟩
@[simp] lemma bit1_le_bit0_iff : bit1 k ≤ bit0 n ↔ k < n :=
⟨λ h, by rwa [k.bit1_eq_succ_bit0, succ_le_iff, bit0_lt_bit0] at h,
λ h, le_of_lt (nat.bit1_lt_bit0 h)⟩
@[simp] lemma bit1_lt_bit0_iff : bit1 k < bit0 n ↔ k < n :=
⟨λ h, bit1_le_bit0_iff.1 (le_of_lt h), nat.bit1_lt_bit0⟩
@[simp] lemma one_le_bit0_iff : 1 ≤ bit0 n ↔ 0 < n :=
by { convert bit1_le_bit0_iff, refl, }
@[simp] lemma one_lt_bit0_iff : 1 < bit0 n ↔ 1 ≤ n :=
by { convert bit1_lt_bit0_iff, refl, }
@[simp] lemma bit_le_bit_iff : ∀ {b : bool}, bit b k ≤ bit b n ↔ k ≤ n
| ff := bit0_le_bit0
| tt := bit1_le_bit1
@[simp] lemma bit_lt_bit_iff : ∀ {b : bool}, bit b k < bit b n ↔ k < n
| ff := bit0_lt_bit0
| tt := bit1_lt_bit1
@[simp] lemma bit_le_bit1_iff : ∀ {b : bool}, bit b k ≤ bit1 n ↔ k ≤ n
| ff := bit0_le_bit1_iff
| tt := bit1_le_bit1
@[simp] lemma bit0_mod_two : bit0 n % 2 = 0 := by { rw nat.mod_two_of_bodd, simp }
@[simp] lemma bit1_mod_two : bit1 n % 2 = 1 := by { rw nat.mod_two_of_bodd, simp }
lemma pos_of_bit0_pos {n : ℕ} (h : 0 < bit0 n) : 0 < n :=
by { cases n, cases h, apply succ_pos, }
/-- Define a function on `ℕ` depending on parity of the argument. -/
@[elab_as_eliminator]
def bit_cases {C : ℕ → Sort u} (H : Π b n, C (bit b n)) (n : ℕ) : C n :=
eq.rec_on n.bit_decomp (H (bodd n) (div2 n))
/-! ### decidability of predicates -/
instance decidable_ball_lt (n : nat) (P : Π k < n, Prop) :
∀ [H : ∀ n h, decidable (P n h)], decidable (∀ n h, P n h) :=
begin
induction n with n IH; intro; resetI,
{ exact is_true (λ n, dec_trivial) },
cases IH (λ k h, P k (lt_succ_of_lt h)) with h,
{ refine is_false (mt _ h), intros hn k h, apply hn },
by_cases p : P n (lt_succ_self n),
{ exact is_true (λ k h',
(le_of_lt_succ h').lt_or_eq_dec.elim (h _)
(λ e, match k, e, h' with _, rfl, h := p end)) },
{ exact is_false (mt (λ hn, hn _ _) p) }
end
instance decidable_forall_fin {n : ℕ} (P : fin n → Prop)
[H : decidable_pred P] : decidable (∀ i, P i) :=
decidable_of_iff (∀ k h, P ⟨k, h⟩) ⟨λ a ⟨k, h⟩, a k h, λ a k h, a ⟨k, h⟩⟩
instance decidable_ball_le (n : ℕ) (P : Π k ≤ n, Prop)
[H : ∀ n h, decidable (P n h)] : decidable (∀ n h, P n h) :=
decidable_of_iff (∀ k (h : k < succ n), P k (le_of_lt_succ h))
⟨λ a k h, a k (lt_succ_of_le h), λ a k h, a k _⟩
instance decidable_lo_hi (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] :
decidable (∀x, lo ≤ x → x < hi → P x) :=
decidable_of_iff (∀ x < hi - lo, P (lo + x))
⟨λal x hl hh, by have := al (x - lo) (lt_of_not_ge $
(not_congr (nat.sub_le_sub_right_iff _ _ _ hl)).2 $ not_le_of_gt hh);
rwa [nat.add_sub_of_le hl] at this,
λal x h, al _ (nat.le_add_right _ _) (nat.add_lt_of_lt_sub_left h)⟩
instance decidable_lo_hi_le (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] :
decidable (∀x, lo ≤ x → x ≤ hi → P x) :=
decidable_of_iff (∀x, lo ≤ x → x < hi + 1 → P x) $
ball_congr $ λ x hl, imp_congr lt_succ_iff iff.rfl
instance decidable_exists_lt {P : ℕ → Prop} [h : decidable_pred P] :
decidable_pred (λ n, ∃ (m : ℕ), m < n ∧ P m)
| 0 := is_false (by simp)
| (n + 1) := decidable_of_decidable_of_iff (@or.decidable _ _ (decidable_exists_lt n) (h n))
(by simp only [lt_succ_iff_lt_or_eq, or_and_distrib_right, exists_or_distrib, exists_eq_left])
end nat
|
bf18c61c17f99fec1fe1fde4087e3d5ae1fdc44b
|
12dabd587ce2621d9a4eff9f16e354d02e206c8e
|
/world04/level03.lean
|
237f621a807ea911f93db2f6a515d037a1a1ebff
|
[] |
no_license
|
abdelq/natural-number-game
|
a1b5b8f1d52625a7addcefc97c966d3f06a48263
|
bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2
|
refs/heads/master
| 1,668,606,478,691
| 1,594,175,058,000
| 1,594,175,058,000
| 278,673,209
| 0
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 121
|
lean
|
lemma pow_one (a : mynat) : a ^ (1 : mynat) = a :=
begin
rw one_eq_succ_zero,
rw pow_succ,
rw pow_zero,
rwa one_mul,
end
|
529a56ed7f8016825f1b5805545c5d826d770d11
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/category_theory/preadditive/default.lean
|
6a8192a90b8d30bdf351e1a495c4063ea5468d64
|
[
"Apache-2.0"
] |
permissive
|
agjftucker/mathlib
|
d634cd0d5256b6325e3c55bb7fb2403548371707
|
87fe50de17b00af533f72a102d0adefe4a2285e8
|
refs/heads/master
| 1,625,378,131,941
| 1,599,166,526,000
| 1,599,166,526,000
| 160,748,509
| 0
| 0
|
Apache-2.0
| 1,544,141,789,000
| 1,544,141,789,000
| null |
UTF-8
|
Lean
| false
| false
| 7,847
|
lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import algebra.group.hom
import category_theory.limits.shapes.kernels
import algebra.big_operators.basic
/-!
# Preadditive categories
A preadditive category is a category in which `X ⟶ Y` is an abelian group in such a way that
composition of morphisms is linear in both variables.
This file contains a definition of preadditive category that directly encodes the definition given
above. The definition could also be phrased as follows: A preadditive category is a category
enriched over the category of Abelian groups. Once the general framework to state this in Lean is
available, the contents of this file should become obsolete.
## Main results
* Definition of preadditive categories and basic properties
* In a preadditive category, `f : Q ⟶ R` is mono if and only if `g ≫ f = 0 → g = 0` for all
composable `g`.
* A preadditive category with kernels has equalizers.
## Implementation notes
The simp normal form for negation and composition is to push negations as far as possible to
the outside. For example, `f ≫ (-g)` and `(-f) ≫ g` both become `-(f ≫ g)`, and `(-f) ≫ (-g)`
is simplified to `f ≫ g`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
## Tags
additive, preadditive, Hom group, Ab-category, Ab-enriched
-/
universes v u
open category_theory.limits
open add_monoid_hom
namespace category_theory
variables (C : Type u) [category.{v} C]
/-- A category is called preadditive if `P ⟶ Q` is an abelian group such that composition is
linear in both variables. -/
class preadditive :=
(hom_group : Π P Q : C, add_comm_group (P ⟶ Q) . tactic.apply_instance)
(add_comp' : ∀ (P Q R : C) (f f' : P ⟶ Q) (g : Q ⟶ R),
(f + f') ≫ g = f ≫ g + f' ≫ g . obviously)
(comp_add' : ∀ (P Q R : C) (f : P ⟶ Q) (g g' : Q ⟶ R),
f ≫ (g + g') = f ≫ g + f ≫ g' . obviously)
attribute [instance] preadditive.hom_group
restate_axiom preadditive.add_comp'
restate_axiom preadditive.comp_add'
attribute [simp,reassoc] preadditive.add_comp
attribute [reassoc] preadditive.comp_add -- (the linter doesn't like `simp` on this lemma)
attribute [simp] preadditive.comp_add
end category_theory
open category_theory
namespace category_theory.preadditive
section preadditive
variables {C : Type u} [category.{v} C] [preadditive C]
/-- Composition by a fixed left argument as a group homomorphism -/
def left_comp {P Q : C} (R : C) (f : P ⟶ Q) : (Q ⟶ R) →+ (P ⟶ R) :=
mk' (λ g, f ≫ g) $ λ g g', by simp
/-- Composition by a fixed right argument as a group homomorphism -/
def right_comp (P : C) {Q R : C} (g : Q ⟶ R) : (P ⟶ Q) →+ (P ⟶ R) :=
mk' (λ f, f ≫ g) $ λ f f', by simp
@[simp, reassoc] lemma sub_comp {P Q R : C} (f f' : P ⟶ Q) (g : Q ⟶ R) :
(f - f') ≫ g = f ≫ g - f' ≫ g :=
map_sub (right_comp P g) f f'
-- The redundant simp lemma linter says that simp can prove the reassoc version of this lemma.
@[reassoc, simp] lemma comp_sub {P Q R : C} (f : P ⟶ Q) (g g' : Q ⟶ R) :
f ≫ (g - g') = f ≫ g - f ≫ g' :=
map_sub (left_comp R f) g g'
@[simp, reassoc] lemma neg_comp {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : (-f) ≫ g = -(f ≫ g) :=
map_neg (right_comp _ _) _
/- The redundant simp lemma linter says that simp can prove the reassoc version of this lemma. -/
@[reassoc, simp] lemma comp_neg {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : f ≫ (-g) = -(f ≫ g) :=
map_neg (left_comp _ _) _
@[reassoc] lemma neg_comp_neg {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : (-f) ≫ (-g) = f ≫ g :=
by simp
section big_operators
open_locale big_operators
@[reassoc] lemma comp_sum {P Q R : C} {J : Type*} {s : finset J} (f : P ⟶ Q) (g : J → (Q ⟶ R)) :
f ≫ ∑ j in s, g j = ∑ j in s, f ≫ g j :=
begin
change left_comp R f _ = _,
rw [add_monoid_hom.map_sum],
refl,
end
@[reassoc] lemma sum_comp {P Q R : C} {J : Type*} {s : finset J} (f : J → (P ⟶ Q)) (g : Q ⟶ R) :
(∑ j in s, f j) ≫ g = ∑ j in s, f j ≫ g :=
begin
change right_comp P g _ = _,
rw [add_monoid_hom.map_sum],
refl,
end
end big_operators
instance {P Q : C} {f : P ⟶ Q} [epi f] : epi (-f) :=
⟨λ R g g' H, by rwa [neg_comp, neg_comp, ←comp_neg, ←comp_neg, cancel_epi, neg_inj] at H⟩
instance {P Q : C} {f : P ⟶ Q} [mono f] : mono (-f) :=
⟨λ R g g' H, by rwa [comp_neg, comp_neg, ←neg_comp, ←neg_comp, cancel_mono, neg_inj] at H⟩
@[priority 100]
instance preadditive_has_zero_morphisms : has_zero_morphisms C :=
{ has_zero := infer_instance,
comp_zero' := λ P Q f R, map_zero $ left_comp R f,
zero_comp' := λ P Q R f, map_zero $ right_comp P f }
lemma mono_of_cancel_zero {Q R : C} (f : Q ⟶ R) (h : ∀ {P : C} (g : P ⟶ Q), g ≫ f = 0 → g = 0) :
mono f :=
⟨λ P g g' hg, sub_eq_zero.1 $ h _ $ (map_sub (right_comp P f) g g').trans $ sub_eq_zero.2 hg⟩
lemma mono_iff_cancel_zero {Q R : C} (f : Q ⟶ R) :
mono f ↔ ∀ (P : C) (g : P ⟶ Q), g ≫ f = 0 → g = 0 :=
⟨λ m P g, by exactI zero_of_comp_mono _, mono_of_cancel_zero f⟩
lemma mono_of_kernel_zero {X Y : C} {f : X ⟶ Y} [has_limit (parallel_pair f 0)]
(w : kernel.ι f = 0) : mono f :=
mono_of_cancel_zero f (λ P g h, by rw [←kernel.lift_ι f g h, w, has_zero_morphisms.comp_zero])
lemma epi_of_cancel_zero {P Q : C} (f : P ⟶ Q) (h : ∀ {R : C} (g : Q ⟶ R), f ≫ g = 0 → g = 0) :
epi f :=
⟨λ R g g' hg, sub_eq_zero.1 $ h _ $ (map_sub (left_comp R f) g g').trans $ sub_eq_zero.2 hg⟩
lemma epi_iff_cancel_zero {P Q : C} (f : P ⟶ Q) :
epi f ↔ ∀ (R : C) (g : Q ⟶ R), f ≫ g = 0 → g = 0 :=
⟨λ e R g, by exactI zero_of_epi_comp _, epi_of_cancel_zero f⟩
lemma epi_of_cokernel_zero {X Y : C} (f : X ⟶ Y) [has_colimit (parallel_pair f 0 )]
(w : cokernel.π f = 0) : epi f :=
epi_of_cancel_zero f (λ P g h, by rw [←cokernel.π_desc f g h, w, has_zero_morphisms.zero_comp])
end preadditive
section equalizers
variables {C : Type u} [category.{v} C] [preadditive C]
section
variables {X Y : C} (f : X ⟶ Y) (g : X ⟶ Y)
/-- A kernel of `f - g` is an equalizer of `f` and `g`. -/
def has_limit_parallel_pair [has_kernel (f - g)] :
has_limit (parallel_pair f g) :=
{ cone := fork.of_ι (kernel.ι (f - g)) (sub_eq_zero.1 $
by { rw ←comp_sub, exact kernel.condition _ }),
is_limit := fork.is_limit.mk _
(λ s, kernel.lift (f - g) (fork.ι s) $
by { rw comp_sub, apply sub_eq_zero.2, exact fork.condition _ })
(λ s, by simp)
(λ s m h, by { ext, simpa using h walking_parallel_pair.zero }) }
end
section
/-- If a preadditive category has all kernels, then it also has all equalizers. -/
def has_equalizers_of_has_kernels [has_kernels C] : has_equalizers C :=
@has_equalizers_of_has_limit_parallel_pair _ _ (λ _ _ f g, has_limit_parallel_pair f g)
end
section
variables {X Y : C} (f : X ⟶ Y) (g : X ⟶ Y)
/-- A cokernel of `f - g` is a coequalizer of `f` and `g`. -/
def has_colimit_parallel_pair [has_cokernel (f - g)] :
has_colimit (parallel_pair f g) :=
{ cocone := cofork.of_π (cokernel.π (f - g)) (sub_eq_zero.1 $
by { rw ←sub_comp, exact cokernel.condition _ }),
is_colimit := cofork.is_colimit.mk _
(λ s, cokernel.desc (f - g) (cofork.π s) $
by { rw sub_comp, apply sub_eq_zero.2, exact cofork.condition _ })
(λ s, by simp)
(λ s m h, by { ext, simpa using h walking_parallel_pair.one }) }
end
section
/-- If a preadditive category has all cokernels, then it also has all coequalizers. -/
def has_coequalizers_of_has_cokernels [has_cokernels C] : has_coequalizers C :=
@has_coequalizers_of_has_colimit_parallel_pair _ _ (λ _ _ f g, has_colimit_parallel_pair f g)
end
end equalizers
end category_theory.preadditive
|
ca9b15b7d4253e1c9bb4d9915816546597bb091a
|
367134ba5a65885e863bdc4507601606690974c1
|
/test/differentiable.lean
|
2181a565b662ca9ac6ae536d93583a329a03d6c7
|
[
"Apache-2.0"
] |
permissive
|
kodyvajjha/mathlib
|
9bead00e90f68269a313f45f5561766cfd8d5cad
|
b98af5dd79e13a38d84438b850a2e8858ec21284
|
refs/heads/master
| 1,624,350,366,310
| 1,615,563,062,000
| 1,615,563,062,000
| 162,666,963
| 0
| 0
|
Apache-2.0
| 1,545,367,651,000
| 1,545,367,651,000
| null |
UTF-8
|
Lean
| false
| false
| 2,412
|
lean
|
import analysis.special_functions.trigonometric
namespace real
example : differentiable ℝ (λ (x : ℝ), exp x) :=
by simp
example : differentiable ℝ (λ (x : ℝ), exp ((sin x)^2) - exp (exp (cos (x - 3)))) :=
by simp
example (x : ℝ) : deriv (λ (x : ℝ), (cos x)^2 + 1 + (sin x)^2) x = 0 :=
by { simp, ring }
example (x : ℝ) : deriv (λ (x : ℝ), (1+x)^3 - x^3 - 3 * x^2 - 3 * x - 4) x = 0 :=
by { simp, ring }
example (x : ℝ) : deriv (λ x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=
by { simp, ring }
example (x : ℝ) : differentiable_at ℝ (λ x, (cos x, x)) x := by simp
example (x : ℝ) (h : 1 + sin x ≠ 0) : deriv (λ x, exp (cos x) / (1 + sin x)) x =
(-(exp (cos x) * sin x * (1 + sin x)) - exp (cos x) * cos x) / (1 + sin x) ^ 2 :=
by simp [h]
example (x : ℝ) : differentiable_at ℝ (λ x, (sin x) / (exp x)) x :=
by simp [exp_ne_zero]
example : differentiable ℝ (λ x, (sin x) / (exp x)) :=
by simp [exp_ne_zero]
example (x : ℝ) (h : x ≠ 0) : deriv (λ x, x * (log x - 1)) x = log x :=
by simp [h]
end real
namespace complex
example : differentiable ℂ (λ (x : ℂ), exp x) :=
by simp
example : differentiable ℂ (λ (x : ℂ), exp ((sin x)^2) - exp (exp (cos (x - 3)))) :=
by simp
example (x : ℂ) : deriv (λ (x : ℂ), (cos x)^2 + I + (sin x)^2) x = 0 :=
by { simp, ring }
example (x : ℂ) : deriv (λ x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=
by { simp, ring }
example (x : ℂ) : differentiable_at ℂ (λ x, (cos x, x)) x := by simp
example (x : ℂ) (h : 1 + sin x ≠ 0) : deriv (λ x, exp (cos x) / (1 + sin x)) x =
(-(exp (cos x) * sin x * (1 + sin x)) - exp (cos x) * cos x) / (1 + sin x) ^ 2 :=
by simp [h]
example (x : ℂ) : differentiable_at ℂ (λ x, (sin x) / (exp x)) x :=
by simp [exp_ne_zero]
example : differentiable ℂ (λ x, (sin x) / (exp x)) :=
by simp [exp_ne_zero]
end complex
namespace polynomial
variables {R : Type*} [comm_semiring R]
example : (2 : polynomial R).derivative = 0 :=
by conv_lhs { simp }
example : (3 + X : polynomial R).derivative = 1 :=
by conv_lhs { simp }
example : (2 * X ^ 2 : polynomial R).derivative = 4 * X :=
by conv_lhs { simp, ring, }
example : (X ^ 2 : polynomial R).derivative = 2 * X :=
by conv_lhs { simp }
example : ((C 2 * X ^ 3).derivative : polynomial R) = 6 * X ^ 2 :=
by conv_lhs { simp, ring, }
end polynomial
|
62c3a5cb7a9d9fd3d90f97c0c3ceb530685342d9
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/test/rewrite.lean
|
57914c56f4cf7ae7f72093bc20454c825c0fa6c5
|
[
"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,406
|
lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import tactic.rewrite
import data.nat.basic
open tactic
example : ∀ x y z a b c : ℕ, true :=
begin
intros,
have : x + (y + z) = 3 + y, admit,
have : a + (b + x) + y + (z + b + c) ≤ 0,
(do this ← get_local `this,
tgt ← to_expr ```(a + (b + x) + y + (z + b + c)),
assoc ← mk_mapp ``add_monoid.add_assoc [`(ℕ),none],
(l,p) ← assoc_rewrite_intl assoc this tgt,
note `h none p ),
erw h,
guard_target a + b + 3 + y + b + c ≤ 0,
admit,
trivial
end
example : ∀ x y z a b c : ℕ, true :=
begin
intros,
have : ∀ y, x + (y + z) = 3 + y, admit,
have : a + (b + x) + y + (z + b + c) ≤ 0,
(do this ← get_local `this,
tgt ← to_expr ```(a + (b + x) + y + (z + b + c)),
assoc_rewrite_target this ),
guard_target a + b + 3 + y + b + c ≤ 0,
admit,
trivial
end
variables x y z a b c : ℕ
variables h₀ : ∀ (y : ℕ), x + (y + z) = 3 + y
variables h₁ : a + (b + x) + y + (z + b + a) ≤ 0
variables h₂ : y + b + c = y + b + a
include h₀ h₁ h₂
example : a + (b + x) + y + (z + b + c) ≤ 0 :=
by { assoc_rw [h₀,h₂] at *,
guard_hyp _inst : is_associative ℕ has_add.add,
-- keep a local instance of is_associative to cache
-- type class queries
exact h₁ }
|
233c8a2ec31914b5499e6ec96edbf5111d6d3355
|
c3f2fcd060adfa2ca29f924839d2d925e8f2c685
|
/library/data/nat/order.lean
|
df5ecc750811f2c3d2a532cba9990d10a1a4d402
|
[
"Apache-2.0"
] |
permissive
|
respu/lean
|
6582d19a2f2838a28ecd2b3c6f81c32d07b5341d
|
8c76419c60b63d0d9f7bc04ebb0b99812d0ec654
|
refs/heads/master
| 1,610,882,451,231
| 1,427,747,084,000
| 1,427,747,429,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 15,968
|
lean
|
/-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: data.nat.order
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad
The order relation on the natural numbers.
-/
import data.nat.basic algebra.ordered_ring
open eq.ops
namespace nat
/- lt and le -/
theorem le_of_lt_or_eq {m n : ℕ} (H : m < n ∨ m = n) : m ≤ n :=
or.elim H (take H1, le_of_lt H1) (take H1, H1 ▸ !le.refl)
theorem lt.by_cases {a b : ℕ} {P : Prop}
(H1 : a < b → P) (H2 : a = b → P) (H3 : b < a → P) : P :=
or.elim !lt.trichotomy
(assume H, H1 H)
(assume H, or.elim H (assume H', H2 H') (assume H', H3 H'))
theorem lt_or_eq_of_le {m n : ℕ} (H : m ≤ n) : m < n ∨ m = n :=
lt.by_cases
(assume H1 : m < n, or.inl H1)
(assume H1 : m = n, or.inr H1)
(assume H1 : m > n, absurd (lt_of_le_of_lt H H1) !lt.irrefl)
theorem le_iff_lt_or_eq (m n : ℕ) : m ≤ n ↔ m < n ∨ m = n :=
iff.intro lt_or_eq_of_le le_of_lt_or_eq
theorem lt_of_le_and_ne {m n : ℕ} (H1 : m ≤ n) (H2 : m ≠ n) : m < n :=
or.elim (lt_or_eq_of_le H1)
(take H3 : m < n, H3)
(take H3 : m = n, absurd H3 H2)
theorem lt_iff_le_and_ne (m n : ℕ) : m < n ↔ m ≤ n ∧ m ≠ n :=
iff.intro
(take H, and.intro (le_of_lt H) (take H1, lt.irrefl _ (H1 ▸ H)))
(take H, lt_of_le_and_ne (and.elim_left H) (and.elim_right H))
theorem le_add_right (n k : ℕ) : n ≤ n + k :=
nat.induction_on k
(calc n ≤ n : le.refl n
... = n + zero : add_zero)
(λ k (ih : n ≤ n + k), calc
n ≤ succ (n + k) : le_succ_of_le ih
... = n + succ k : add_succ)
theorem le_add_left (n m : ℕ): n ≤ m + n :=
!add.comm ▸ !le_add_right
theorem le.intro {n m k : ℕ} (h : n + k = m) : n ≤ m :=
h ▸ le_add_right n k
theorem le.elim {n m : ℕ} (h : n ≤ m) : ∃k, n + k = m :=
le.rec_on h
(exists.intro 0 rfl)
(λ m (h : n < m), lt.rec_on h
(exists.intro 1 rfl)
(λ b hlt (ih : ∃ (k : ℕ), n + k = b),
obtain (k : ℕ) (h : n + k = b), from ih,
exists.intro (succ k) (calc
n + succ k = succ (n + k) : add_succ
... = succ b : h)))
theorem le.total {m n : ℕ} : m ≤ n ∨ n ≤ m :=
lt.by_cases
(assume H : m < n, or.inl (le_of_lt H))
(assume H : m = n, or.inl (H ▸ !le.refl))
(assume H : m > n, or.inr (le_of_lt H))
/- addition -/
theorem add_le_add_left {n m : ℕ} (H : n ≤ m) (k : ℕ) : k + n ≤ k + m :=
obtain (l : ℕ) (Hl : n + l = m), from le.elim H,
le.intro
(calc
k + n + l = k + (n + l) : !add.assoc
... = k + m : {Hl})
theorem add_le_add_right {n m : ℕ} (H : n ≤ m) (k : ℕ) : n + k ≤ m + k :=
!add.comm ▸ !add.comm ▸ add_le_add_left H k
theorem le_of_add_le_add_left {k n m : ℕ} (H : k + n ≤ k + m) : n ≤ m :=
obtain (l : ℕ) (Hl : k + n + l = k + m), from (le.elim H),
le.intro (add.cancel_left
(calc
k + (n + l) = k + n + l : (!add.assoc)⁻¹
... = k + m : Hl))
theorem add_lt_add_left {n m : ℕ} (H : n < m) (k : ℕ) : k + n < k + m :=
lt_of_succ_le (!add_succ ▸ add_le_add_left (succ_le_of_lt H) k)
theorem add_lt_add_right {n m : ℕ} (H : n < m) (k : ℕ) : n + k < m + k :=
!add.comm ▸ !add.comm ▸ add_lt_add_left H k
theorem lt_add_of_pos_right {n k : ℕ} (H : k > 0) : n < n + k :=
!add_zero ▸ add_lt_add_left H n
/- multiplication -/
theorem mul_le_mul_left {n m : ℕ} (H : n ≤ m) (k : ℕ) : k * n ≤ k * m :=
obtain (l : ℕ) (Hl : n + l = m), from le.elim H,
have H2 : k * n + k * l = k * m, by rewrite [-mul.left_distrib, Hl],
le.intro H2
theorem mul_le_mul_right {n m : ℕ} (H : n ≤ m) (k : ℕ) : n * k ≤ m * k :=
!mul.comm ▸ !mul.comm ▸ (mul_le_mul_left H k)
theorem mul_le_mul {n m k l : ℕ} (H1 : n ≤ k) (H2 : m ≤ l) : n * m ≤ k * l :=
le.trans (mul_le_mul_right H1 m) (mul_le_mul_left H2 k)
theorem mul_lt_mul_of_pos_left {n m k : ℕ} (H : n < m) (Hk : k > 0) : k * n < k * m :=
have H2 : k * n < k * n + k, from lt_add_of_pos_right Hk,
have H3 : k * n + k ≤ k * m, from !mul_succ ▸ mul_le_mul_left (succ_le_of_lt H) k,
lt_of_lt_of_le H2 H3
theorem mul_lt_mul_of_pos_right {n m k : ℕ} (H : n < m) (Hk : k > 0) : n * k < m * k :=
!mul.comm ▸ !mul.comm ▸ mul_lt_mul_of_pos_left H Hk
theorem le.antisymm {n m : ℕ} (H1 : n ≤ m) (H2 : m ≤ n) : n = m :=
obtain (k : ℕ) (Hk : n + k = m), from (le.elim H1),
obtain (l : ℕ) (Hl : m + l = n), from (le.elim H2),
have L1 : k + l = 0, from
add.cancel_left
(calc
n + (k + l) = n + k + l : (!add.assoc)⁻¹
... = m + l : {Hk}
... = n : Hl
... = n + 0 : (!add_zero)⁻¹),
have L2 : k = 0, from eq_zero_of_add_eq_zero_right L1,
calc
n = n + 0 : (!add_zero)⁻¹
... = n + k : {L2⁻¹}
... = m : Hk
theorem zero_le (n : ℕ) : 0 ≤ n :=
le.intro !zero_add
/- nat is an instance of a linearly ordered semiring -/
section
open [classes] algebra
protected definition linear_ordered_semiring [instance] [reducible] :
algebra.linear_ordered_semiring nat :=
⦃ algebra.linear_ordered_semiring, nat.comm_semiring,
add_left_cancel := @add.cancel_left,
add_right_cancel := @add.cancel_right,
lt := lt,
le := le,
le_refl := le.refl,
le_trans := @le.trans,
le_antisymm := @le.antisymm,
le_total := @le.total,
le_iff_lt_or_eq := @le_iff_lt_or_eq,
lt_iff_le_ne := lt_iff_le_and_ne,
add_le_add_left := @add_le_add_left,
le_of_add_le_add_left := @le_of_add_le_add_left,
zero_ne_one := ne.symm (succ_ne_zero zero),
mul_le_mul_of_nonneg_left := (take a b c H1 H2, mul_le_mul_left H1 c),
mul_le_mul_of_nonneg_right := (take a b c H1 H2, mul_le_mul_right H1 c),
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left,
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right ⦄
migrate from algebra with nat
replacing has_le.ge → ge, has_lt.gt → gt
hiding pos_of_mul_pos_left, pos_of_mul_pos_right, lt_of_mul_lt_mul_left, lt_of_mul_lt_mul_right
end
calc_trans ge_of_eq_of_ge
calc_trans ge_of_ge_of_eq
calc_trans gt_of_eq_of_gt
calc_trans gt_of_gt_of_eq
section port_algebra
theorem add_pos_left : ∀{a : ℕ}, 0 < a → ∀b : ℕ, 0 < a + b :=
take a H b, @algebra.add_pos_of_pos_of_nonneg _ _ a b H !zero_le
theorem add_pos_right : ∀{a : ℕ}, 0 < a → ∀b : ℕ, 0 < b + a :=
take a H b, !add.comm ▸ add_pos_left H b
theorem add_eq_zero_iff_eq_zero_and_eq_zero : ∀{a b : ℕ},
a + b = 0 ↔ a = 0 ∧ b = 0 :=
take a b : ℕ,
@algebra.add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg _ _ a b !zero_le !zero_le
theorem le_add_of_le_left : ∀{a b c : ℕ}, b ≤ c → b ≤ a + c :=
take a b c H, @algebra.le_add_of_nonneg_of_le _ _ a b c !zero_le H
theorem le_add_of_le_right : ∀{a b c : ℕ}, b ≤ c → b ≤ c + a :=
take a b c H, @algebra.le_add_of_le_of_nonneg _ _ a b c H !zero_le
theorem lt_add_of_lt_left : ∀{b c : ℕ}, b < c → ∀a, b < a + c :=
take b c H a, @algebra.lt_add_of_nonneg_of_lt _ _ a b c !zero_le H
theorem lt_add_of_lt_right : ∀{b c : ℕ}, b < c → ∀a, b < c + a :=
take b c H a, @algebra.lt_add_of_lt_of_nonneg _ _ a b c H !zero_le
theorem lt_of_mul_lt_mul_left : ∀{a b c : ℕ}, c * a < c * b → a < b :=
take a b c H, @algebra.lt_of_mul_lt_mul_left _ _ a b c H !zero_le
theorem lt_of_mul_lt_mul_right : ∀{a b c : ℕ}, a * c < b * c → a < b :=
take a b c H, @algebra.lt_of_mul_lt_mul_right _ _ a b c H !zero_le
theorem pos_of_mul_pos_left : ∀{a b : ℕ}, 0 < a * b → 0 < b :=
take a b H, @algebra.pos_of_mul_pos_left _ _ a b H !zero_le
theorem pos_of_mul_pos_right : ∀{a b : ℕ}, 0 < a * b → 0 < a :=
take a b H, @algebra.pos_of_mul_pos_right _ _ a b H !zero_le
end port_algebra
theorem zero_le_one : 0 ≤ 1 := dec_trivial
theorem zero_lt_one : 0 < 1 := dec_trivial
/- properties specific to nat -/
theorem lt_intro {n m k : ℕ} (H : succ n + k = m) : n < m :=
lt_of_succ_le (le.intro H)
theorem lt_elim {n m : ℕ} (H : n < m) : ∃k, succ n + k = m :=
le.elim (succ_le_of_lt H)
theorem lt_add_succ (n m : ℕ) : n < n + succ m :=
lt_intro !succ_add_eq_succ_add
theorem eq_zero_of_le_zero {n : ℕ} (H : n ≤ 0) : n = 0 :=
obtain (k : ℕ) (Hk : n + k = 0), from le.elim H,
eq_zero_of_add_eq_zero_right Hk
/- succ and pred -/
theorem lt_iff_succ_le (m n : nat) : m < n ↔ succ m ≤ n :=
iff.intro succ_le_of_lt lt_of_succ_le
theorem not_succ_le_zero (n : ℕ) : ¬ succ n ≤ 0 :=
(assume H : succ n ≤ 0,
have H2 : succ n = 0, from eq_zero_of_le_zero H,
absurd H2 !succ_ne_zero)
theorem succ_le_succ {n m : ℕ} (H : n ≤ m) : succ n ≤ succ m :=
!add_one ▸ !add_one ▸ add_le_add_right H 1
theorem le_of_succ_le_succ {n m : ℕ} (H : succ n ≤ succ m) : n ≤ m :=
le_of_add_le_add_right ((!add_one)⁻¹ ▸ (!add_one)⁻¹ ▸ H)
theorem self_le_succ (n : ℕ) : n ≤ succ n :=
le.intro !add_one
theorem succ_le_or_eq_of_le {n m : ℕ} (H : n ≤ m) : succ n ≤ m ∨ n = m :=
or.elim (lt_or_eq_of_le H)
(assume H1 : n < m, or.inl (succ_le_of_lt H1))
(assume H1 : n = m, or.inr H1)
theorem le_succ_of_pred_le {n m : ℕ} : pred n ≤ m → n ≤ succ m :=
nat.cases_on n
(assume H : pred 0 ≤ m, !zero_le)
(take n',
assume H : pred (succ n') ≤ m,
have H1 : n' ≤ m, from pred_succ n' ▸ H,
succ_le_succ H1)
theorem pred_le_of_le_succ {n m : ℕ} : n ≤ succ m → pred n ≤ m :=
nat.cases_on n
(assume H, !pred_zero⁻¹ ▸ zero_le m)
(take n',
assume H : succ n' ≤ succ m,
have H1 : n' ≤ m, from le_of_succ_le_succ H,
!pred_succ⁻¹ ▸ H1)
theorem succ_le_of_le_pred {n m : ℕ} : succ n ≤ m → n ≤ pred m :=
nat.cases_on m
(assume H, absurd H !not_succ_le_zero)
(take m',
assume H : succ n ≤ succ m',
have H1 : n ≤ m', from le_of_succ_le_succ H,
!pred_succ⁻¹ ▸ H1)
theorem pred_le_pred_of_le {n m : ℕ} : n ≤ m → pred n ≤ pred m :=
nat.cases_on n
(assume H, pred_zero⁻¹ ▸ zero_le (pred m))
(take n',
assume H : succ n' ≤ m,
!pred_succ⁻¹ ▸ succ_le_of_le_pred H)
theorem lt_of_pred_lt_pred {n m : ℕ} (H : pred n < pred m) : n < m :=
lt_of_not_le
(take H1 : m ≤ n,
not_lt_of_le (pred_le_pred_of_le H1) H)
theorem le_or_eq_succ_of_le_succ {n m : ℕ} (H : n ≤ succ m) : n ≤ m ∨ n = succ m :=
or_of_or_of_imp_left (succ_le_or_eq_of_le H)
(take H2 : succ n ≤ succ m, show n ≤ m, from le_of_succ_le_succ H2)
theorem le_pred_self (n : ℕ) : pred n ≤ n :=
nat.cases_on n
(pred_zero⁻¹ ▸ !le.refl)
(take k : ℕ, (!pred_succ)⁻¹ ▸ !self_le_succ)
theorem succ_pos (n : ℕ) : 0 < succ n :=
!zero_lt_succ
theorem succ_pred_of_pos {n : ℕ} (H : n > 0) : succ (pred n) = n :=
(or_resolve_right (eq_zero_or_eq_succ_pred n) (ne.symm (ne_of_lt H)))⁻¹
theorem exists_eq_succ_of_lt {n m : ℕ} (H : n < m) : exists k, m = succ k :=
discriminate
(take (Hm : m = 0), absurd (Hm ▸ H) !not_lt_zero)
(take (l : ℕ) (Hm : m = succ l), exists.intro l Hm)
theorem lt_succ_self (n : ℕ) : n < succ n :=
lt.base n
theorem le_of_lt_succ {n m : ℕ} (H : n < succ m) : n ≤ m :=
le_of_succ_le_succ (succ_le_of_lt H)
/- other forms of induction -/
protected theorem strong_induction_on {P : nat → Prop} (n : ℕ) (H : ∀n, (∀m, m < n → P m) → P n) :
P n :=
have H1 : ∀ {n m : nat}, m < n → P m, from
take n,
nat.induction_on n
(show ∀m, m < 0 → P m, from take m H, absurd H !not_lt_zero)
(take n',
assume IH : ∀ {m : nat}, m < n' → P m,
have H2: P n', from H n' @IH,
show ∀m, m < succ n' → P m, from
take m,
assume H3 : m < succ n',
or.elim (lt_or_eq_of_le (le_of_lt_succ H3))
(assume H4: m < n', IH H4)
(assume H4: m = n', H4⁻¹ ▸ H2)),
H1 !lt_succ_self
protected theorem case_strong_induction_on {P : nat → Prop} (a : nat) (H0 : P 0)
(Hind : ∀(n : nat), (∀m, m ≤ n → P m) → P (succ n)) : P a :=
strong_induction_on a (
take n,
show (∀m, m < n → P m) → P n, from
nat.cases_on n
(assume H : (∀m, m < 0 → P m), show P 0, from H0)
(take n,
assume H : (∀m, m < succ n → P m),
show P (succ n), from
Hind n (take m, assume H1 : m ≤ n, H _ (lt_succ_of_le H1))))
/- pos -/
theorem by_cases_zero_pos {P : ℕ → Prop} (y : ℕ) (H0 : P 0) (H1 : ∀ {y : nat}, y > 0 → P y) : P y :=
nat.cases_on y H0 (take y, H1 !succ_pos)
theorem eq_zero_or_pos (n : ℕ) : n = 0 ∨ n > 0 :=
or_of_or_of_imp_left
(or.swap (lt_or_eq_of_le !zero_le))
(take H : 0 = n, H⁻¹)
theorem pos_of_ne_zero {n : ℕ} (H : n ≠ 0) : n > 0 :=
or.elim !eq_zero_or_pos (take H2 : n = 0, absurd H2 H) (take H2 : n > 0, H2)
theorem ne_zero_of_pos {n : ℕ} (H : n > 0) : n ≠ 0 :=
ne.symm (ne_of_lt H)
theorem exists_eq_succ_of_pos {n : ℕ} (H : n > 0) : exists l, n = succ l :=
exists_eq_succ_of_lt H
theorem pos_of_dvd_of_pos {m n : ℕ} (H1 : (m | n)) (H2 : n > 0) : m > 0 :=
pos_of_ne_zero
(assume H3 : m = 0,
have H4 : n = 0, from eq_zero_of_zero_dvd (H3 ▸ H1),
ne_of_lt H2 H4⁻¹)
/- multiplication -/
theorem mul_lt_mul_of_le_of_lt {n m k l : ℕ} (Hk : k > 0) (H1 : n ≤ k) (H2 : m < l) :
n * m < k * l :=
lt_of_le_of_lt (mul_le_mul_right H1 m) (mul_lt_mul_of_pos_left H2 Hk)
theorem mul_lt_mul_of_lt_of_le {n m k l : ℕ} (Hl : l > 0) (H1 : n < k) (H2 : m ≤ l) :
n * m < k * l :=
lt_of_le_of_lt (mul_le_mul_left H2 n) (mul_lt_mul_of_pos_right H1 Hl)
theorem mul_lt_mul_of_le_of_le {n m k l : ℕ} (H1 : n < k) (H2 : m < l) : n * m < k * l :=
have H3 : n * m ≤ k * m, from mul_le_mul_right (le_of_lt H1) m,
have H4 : k * m < k * l, from mul_lt_mul_of_pos_left H2 (lt_of_le_of_lt !zero_le H1),
lt_of_le_of_lt H3 H4
theorem eq_of_mul_eq_mul_left {m k n : ℕ} (Hn : n > 0) (H : n * m = n * k) : m = k :=
have H2 : n * m ≤ n * k, from H ▸ !le.refl,
have H3 : n * k ≤ n * m, from H ▸ !le.refl,
have H4 : m ≤ k, from le_of_mul_le_mul_left H2 Hn,
have H5 : k ≤ m, from le_of_mul_le_mul_left H3 Hn,
le.antisymm H4 H5
theorem eq_of_mul_eq_mul_right {n m k : ℕ} (Hm : m > 0) (H : n * m = k * m) : n = k :=
eq_of_mul_eq_mul_left Hm (!mul.comm ▸ !mul.comm ▸ H)
theorem eq_zero_or_eq_of_mul_eq_mul_left {n m k : ℕ} (H : n * m = n * k) : n = 0 ∨ m = k :=
or_of_or_of_imp_right !eq_zero_or_pos
(assume Hn : n > 0, eq_of_mul_eq_mul_left Hn H)
theorem eq_zero_or_eq_of_mul_eq_mul_right {n m k : ℕ} (H : n * m = k * m) : m = 0 ∨ n = k :=
eq_zero_or_eq_of_mul_eq_mul_left (!mul.comm ▸ !mul.comm ▸ H)
theorem eq_one_of_mul_eq_one_right {n m : ℕ} (H : n * m = 1) : n = 1 :=
have H2 : n * m > 0, from H⁻¹ ▸ !succ_pos,
have H3 : n > 0, from pos_of_mul_pos_right H2,
have H4 : m > 0, from pos_of_mul_pos_left H2,
or.elim (le_or_gt n 1)
(assume H5 : n ≤ 1,
show n = 1, from le.antisymm H5 (succ_le_of_lt H3))
(assume H5 : n > 1,
have H6 : n * m ≥ 2 * 1, from mul_le_mul (succ_le_of_lt H5) (succ_le_of_lt H4),
have H7 : 1 ≥ 2, from !mul_one ▸ H ▸ H6,
absurd !lt_succ_self (not_lt_of_le H7))
theorem eq_one_of_mul_eq_one_left {n m : ℕ} (H : n * m = 1) : m = 1 :=
eq_one_of_mul_eq_one_right (!mul.comm ▸ H)
theorem eq_one_of_mul_eq_self_left {n m : ℕ} (Hpos : n > 0) (H : m * n = n) : m = 1 :=
eq_of_mul_eq_mul_right Hpos (H ⬝ !one_mul⁻¹)
theorem eq_one_of_mul_eq_self_right {n m : ℕ} (Hpos : m > 0) (H : m * n = m) : n = 1 :=
eq_one_of_mul_eq_self_left Hpos (!mul.comm ▸ H)
theorem eq_one_of_dvd_one {n : ℕ} (H : (n | 1)) : n = 1 :=
dvd.elim H
(take m,
assume H1 : 1 = n * m,
eq_one_of_mul_eq_one_right H1⁻¹)
end nat
|
3e20e10fd687d90c54889e96be59e0e75abb8648
|
491068d2ad28831e7dade8d6dff871c3e49d9431
|
/hott/algebra/field.hlean
|
6bb21b7448be52fb330a9decd8664c67a03798bc
|
[
"Apache-2.0"
] |
permissive
|
davidmueller13/lean
|
65a3ed141b4088cd0a268e4de80eb6778b21a0e9
|
c626e2e3c6f3771e07c32e82ee5b9e030de5b050
|
refs/heads/master
| 1,611,278,313,401
| 1,444,021,177,000
| 1,444,021,177,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 19,024
|
hlean
|
/-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis
Structures with multiplicative and additive components, including division rings and fields.
The development is modeled after Isabelle's library.
Ported from the standard library
-/
import algebra.ring
open core
namespace algebra
variable {A : Type}
-- in division rings, 1 / 0 = 0
structure division_ring [class] (A : Type) extends ring A, has_inv A, zero_ne_one_class A :=
(mul_inv_cancel : Π{a}, a ≠ zero → mul a (inv a) = one)
(inv_mul_cancel : Π{a}, a ≠ zero → mul (inv a) a = one)
--(inv_zero : inv zero = zero)
section division_ring
variables [s : division_ring A] {a b c : A}
include s
definition divide (a b : A) : A := a * b⁻¹
infix / := divide
-- only in this file
local attribute divide [reducible]
definition mul_inv_cancel (H : a ≠ 0) : a * a⁻¹ = 1 :=
division_ring.mul_inv_cancel H
definition inv_mul_cancel (H : a ≠ 0) : a⁻¹ * a = 1 :=
division_ring.inv_mul_cancel H
definition inv_eq_one_div : a⁻¹ = 1 / a := !one_mul⁻¹
-- the following are only theorems if we assume inv_zero here
/- definition inv_zero : 0⁻¹ = 0 := !division_ring.inv_zero
definition one_div_zero : 1 / 0 = 0 :=
calc
1 / 0 = 1 * 0⁻¹ : refl
... = 1 * 0 : division_ring.inv_zero A
... = 0 : mul_zero
-/
definition div_eq_mul_one_div : a / b = a * (1 / b) :=
by rewrite [↑divide, one_mul]
-- definition div_zero : a / 0 = 0 := by rewrite [div_eq_mul_one_div, one_div_zero, mul_zero]
definition mul_one_div_cancel (H : a ≠ 0) : a * (1 / a) = 1 :=
by rewrite [-inv_eq_one_div, (mul_inv_cancel H)]
definition one_div_mul_cancel (H : a ≠ 0) : (1 / a) * a = 1 :=
by rewrite [-inv_eq_one_div, (inv_mul_cancel H)]
definition div_self (H : a ≠ 0) : a / a = 1 := mul_inv_cancel H
definition one_div_one : 1 / 1 = (1:A) :=
div_self (ne.symm zero_ne_one)
definition mul_div_assoc : (a * b) / c = a * (b / c) := !mul.assoc
definition one_div_ne_zero (H : a ≠ 0) : 1 / a ≠ 0 :=
assume H2 : 1 / a = 0,
have C1 : 0 = (1:A), from inverse (by rewrite [-(mul_one_div_cancel H), H2, mul_zero]),
absurd C1 zero_ne_one
-- definition ne_zero_of_one_div_ne_zero (H : 1 / a ≠ 0) : a ≠ 0 :=
-- assume Ha : a = 0, absurd (Ha⁻¹ ▸ one_div_zero) H
definition inv_one_eq : 1⁻¹ = (1:A) :=
by rewrite [-mul_one, (inv_mul_cancel (ne.symm (@zero_ne_one A _)))]
definition div_one : a / 1 = a :=
by rewrite [↑divide, inv_one_eq, mul_one]
definition zero_div : 0 / a = 0 := !zero_mul
-- note: integral domain has a "mul_ne_zero". Discrete fields are int domains.
definition mul_ne_zero' (Ha : a ≠ 0) (Hb : b ≠ 0) : a * b ≠ 0 :=
assume H : a * b = 0,
have C1 : a = 0, by rewrite [-mul_one, -(mul_one_div_cancel Hb), -mul.assoc, H, zero_mul],
absurd C1 Ha
definition mul_ne_zero_comm (H : a * b ≠ 0) : b * a ≠ 0 :=
have H2 : a ≠ 0 × b ≠ 0, from ne_zero_and_ne_zero_of_mul_ne_zero H,
mul_ne_zero' (prod.pr2 H2) (prod.pr1 H2)
-- make "left" and "right" versions?
definition eq_one_div_of_mul_eq_one (H : a * b = 1) : b = 1 / a :=
have H2 : a ≠ 0, from
(assume aeq0 : a = 0,
have B : 0 = (1:A), by rewrite [-(zero_mul b), -aeq0, H],
absurd B zero_ne_one),
show b = 1 / a, from inverse (calc
1 / a = (1 / a) * 1 : mul_one
... = (1 / a) * (a * b) : H
... = (1 / a) * a * b : mul.assoc
... = 1 * b : one_div_mul_cancel H2
... = b : one_mul)
-- which one is left and which is right?
definition eq_one_div_of_mul_eq_one_left (H : b * a = 1) : b = 1 / a :=
have H2 : a ≠ 0, from
(assume A : a = 0,
have B : 0 = 1, from inverse (calc
1 = b * a : inverse H
... = b * 0 : A
... = 0 : mul_zero),
absurd B zero_ne_one),
show b = 1 / a, from inverse (calc
1 / a = 1 * (1 / a) : one_mul
... = b * a * (1 / a) : H
... = b * (a * (1 / a)) : mul.assoc
... = b * 1 : mul_one_div_cancel H2
... = b : mul_one)
definition one_div_mul_one_div (Ha : a ≠ 0) (Hb : b ≠ 0) : (1 / a) * (1 / b) = 1 / (b * a) :=
have H : (b * a) * ((1 / a) * (1 / b)) = 1, by
rewrite [mul.assoc, -(mul.assoc a), (mul_one_div_cancel Ha), one_mul, (mul_one_div_cancel Hb)],
eq_one_div_of_mul_eq_one H
definition one_div_neg_one_eq_neg_one : (1:A) / (-1) = -1 :=
have H : (-1) * (-1) = 1, by rewrite [-neg_eq_neg_one_mul, neg_neg],
inverse (eq_one_div_of_mul_eq_one H)
definition one_div_neg_eq_neg_one_div (H : a ≠ 0) : 1 / (- a) = - (1 / a) :=
have H1 : -1 ≠ 0, from
(assume H2 : -1 = 0, absurd (inverse (calc
1 = -(-1) : neg_neg
... = -0 : H2
... = (0:A) : neg_zero)) zero_ne_one),
calc
1 / (- a) = 1 / ((-1) * a) : neg_eq_neg_one_mul
... = (1 / a) * (1 / (- 1)) : one_div_mul_one_div H H1
... = (1 / a) * (-1) : one_div_neg_one_eq_neg_one
... = - (1 / a) : mul_neg_one_eq_neg
definition div_neg_eq_neg_div (Ha : a ≠ 0) : b / (- a) = - (b / a) :=
calc
b / (- a) = b * (1 / (- a)) : inv_eq_one_div
... = b * -(1 / a) : one_div_neg_eq_neg_one_div Ha
... = -(b * (1 / a)) : neg_mul_eq_mul_neg
... = - (b * a⁻¹) : inv_eq_one_div
definition neg_div (Ha : a ≠ 0) : (-b) / a = - (b / a) :=
by rewrite [neg_eq_neg_one_mul, mul_div_assoc, -neg_eq_neg_one_mul]
definition neg_div_neg_eq_div (Hb : b ≠ 0) : (-a) / (-b) = a / b :=
by rewrite [(div_neg_eq_neg_div Hb), (neg_div Hb), neg_neg]
definition div_div (H : a ≠ 0) : 1 / (1 / a) = a :=
inverse (eq_one_div_of_mul_eq_one_left (mul_one_div_cancel H))
definition eq_of_invs_eq (Ha : a ≠ 0) (Hb : b ≠ 0) (H : 1 / a = 1 / b) : a = b :=
by rewrite [-(div_div Ha), H, (div_div Hb)]
-- oops, the analogous definition in group is called inv_mul, but it *should* be called
-- mul_inv, in which case, we will have to rename this one
definition mul_inv_eq (Ha : a ≠ 0) (Hb : b ≠ 0) : (b * a)⁻¹ = a⁻¹ * b⁻¹ :=
have H1 : b * a ≠ 0, from mul_ne_zero' Hb Ha,
inverse (calc
a⁻¹ * b⁻¹ = (1 / a) * b⁻¹ : inv_eq_one_div
... = (1 / a) * (1 / b) : inv_eq_one_div
... = (1 / (b * a)) : one_div_mul_one_div Ha Hb
... = (b * a)⁻¹ : inv_eq_one_div)
definition mul_div_cancel (Hb : b ≠ 0) : a * b / b = a :=
by rewrite [↑divide, mul.assoc, (mul_inv_cancel Hb), mul_one]
definition div_mul_cancel (Hb : b ≠ 0) : a / b * b = a :=
by rewrite [↑divide, mul.assoc, (inv_mul_cancel Hb), mul_one]
definition div_add_div_same : a / c + b / c = (a + b) / c := !right_distrib⁻¹
definition inv_mul_add_mul_inv_eq_inv_add_inv (Ha : a ≠ 0) (Hb : b ≠ 0) :
(1 / a) * (a + b) * (1 / b) = 1 / a + 1 / b :=
by rewrite [(left_distrib (1 / a)), (one_div_mul_cancel Ha), right_distrib, one_mul,
mul.assoc, (mul_one_div_cancel Hb), mul_one, add.comm]
definition inv_mul_sub_mul_inv_eq_inv_add_inv (Ha : a ≠ 0) (Hb : b ≠ 0) :
(1 / a) * (b - a) * (1 / b) = 1 / a - 1 / b :=
by rewrite [(mul_sub_left_distrib (1 / a)), (one_div_mul_cancel Ha), mul_sub_right_distrib,
one_mul, mul.assoc, (mul_one_div_cancel Hb), mul_one, one_mul]
definition div_eq_one_iff_eq (Hb : b ≠ 0) : a / b = 1 ↔ a = b :=
iff.intro
(assume H1 : a / b = 1, inverse (calc
b = 1 * b : one_mul
... = a / b * b : H1
... = a : div_mul_cancel Hb))
(assume H2 : a = b, calc
a / b = b / b : H2
... = 1 : div_self Hb)
definition eq_div_iff_mul_eq (Hc : c ≠ 0) : a = b / c ↔ a * c = b :=
iff.intro
(assume H : a = b / c, by rewrite [H, (div_mul_cancel Hc)])
(assume H : a * c = b, by rewrite [-(mul_div_cancel Hc), H])
definition add_div_eq_mul_add_div (Hc : c ≠ 0) : a + b / c = (a * c + b) / c :=
have H : (a + b / c) * c = a * c + b, by rewrite [right_distrib, (div_mul_cancel Hc)],
(iff.elim_right (eq_div_iff_mul_eq Hc)) H
definition mul_mul_div (Hc : c ≠ 0) : a = a * c * (1 / c) :=
calc
a = a * 1 : mul_one
... = a * (c * (1 / c)) : mul_one_div_cancel Hc
... = a * c * (1 / c) : mul.assoc
-- There are many similar rules to these last two in the Isabelle library
-- that haven't been ported yet. Do as necessary.
end division_ring
structure field [class] (A : Type) extends division_ring A, comm_ring A
section field
variables [s : field A] {a b c d: A}
include s
local attribute divide [reducible]
definition one_div_mul_one_div' (Ha : a ≠ 0) (Hb : b ≠ 0) : (1 / a) * (1 / b) = 1 / (a * b) :=
by rewrite [(one_div_mul_one_div Ha Hb), mul.comm b]
definition div_mul_right (Hb : b ≠ 0) (H : a * b ≠ 0) : a / (a * b) = 1 / b :=
let Ha : a ≠ 0 := prod.pr1 (ne_zero_and_ne_zero_of_mul_ne_zero H) in
inverse (calc
1 / b = 1 * (1 / b) : one_mul
... = (a * a⁻¹) * (1 / b) : mul_inv_cancel Ha
... = a * (a⁻¹ * (1 / b)) : mul.assoc
... = a * ((1 / a) * (1 / b)) :inv_eq_one_div
... = a * (1 / (b * a)) : one_div_mul_one_div Ha Hb
... = a * (1 / (a * b)) : mul.comm
... = a * (a * b)⁻¹ : inv_eq_one_div)
definition div_mul_left (Ha : a ≠ 0) (H : a * b ≠ 0) : b / (a * b) = 1 / a :=
let H1 : b * a ≠ 0 := mul_ne_zero_comm H in
by rewrite [mul.comm a, (div_mul_right Ha H1)]
definition mul_div_cancel_left (Ha : a ≠ 0) : a * b / a = b :=
by rewrite [mul.comm a, (mul_div_cancel Ha)]
definition mul_div_cancel' (Hb : b ≠ 0) : b * (a / b) = a :=
by rewrite [mul.comm, (div_mul_cancel Hb)]
definition one_div_add_one_div (Ha : a ≠ 0) (Hb : b ≠ 0) : 1 / a + 1 / b = (a + b) / (a * b) :=
have H [visible] : a * b ≠ 0, from (mul_ne_zero' Ha Hb),
by rewrite [add.comm, -(div_mul_left Ha H), -(div_mul_right Hb H), ↑divide, -right_distrib]
definition div_mul_div (Hb : b ≠ 0) (Hd : d ≠ 0) : (a / b) * (c / d) = (a * c) / (b * d) :=
by rewrite [↑divide, 2 mul.assoc, (mul.comm b⁻¹), mul.assoc, (mul_inv_eq Hd Hb)]
definition mul_div_mul_left (Hb : b ≠ 0) (Hc : c ≠ 0) : (c * a) / (c * b) = a / b :=
have H [visible] : c * b ≠ 0, from mul_ne_zero' Hc Hb,
by rewrite [-(div_mul_div Hc Hb), (div_self Hc), one_mul]
definition mul_div_mul_right (Hb : b ≠ 0) (Hc : c ≠ 0) : (a * c) / (b * c) = a / b :=
by rewrite [(mul.comm a), (mul.comm b), (mul_div_mul_left Hb Hc)]
definition div_mul_eq_mul_div : (b / c) * a = (b * a) / c :=
by rewrite [↑divide, mul.assoc, (mul.comm c⁻¹), -mul.assoc]
-- this one is odd -- I am not sure what to call it, but again, the prefix is right
definition div_mul_eq_mul_div_comm (Hc : c ≠ 0) : (b / c) * a = b * (a / c) :=
by rewrite [(div_mul_eq_mul_div), -(one_mul c), -(div_mul_div (ne.symm zero_ne_one) Hc), div_one, one_mul]
definition div_add_div (Hb : b ≠ 0) (Hd : d ≠ 0) :
(a / b) + (c / d) = ((a * d) + (b * c)) / (b * d) :=
have H [visible] : b * d ≠ 0, from mul_ne_zero' Hb Hd,
by rewrite [-(mul_div_mul_right Hb Hd), -(mul_div_mul_left Hd Hb), div_add_div_same]
definition div_sub_div (Hb : b ≠ 0) (Hd : d ≠ 0) :
(a / b) - (c / d) = ((a * d) - (b * c)) / (b * d) :=
by rewrite [↑sub, neg_eq_neg_one_mul, -mul_div_assoc, (div_add_div Hb Hd),
-mul.assoc, (mul.comm b), mul.assoc, -neg_eq_neg_one_mul]
definition mul_eq_mul_of_div_eq_div (Hb : b ≠ 0) (Hd : d ≠ 0) (H : a / b = c / d) : a * d = c * b :=
by rewrite [-mul_one, mul.assoc, (mul.comm d), -mul.assoc, -(div_self Hb),
-(div_mul_eq_mul_div_comm Hb), H, (div_mul_eq_mul_div), (div_mul_cancel Hd)]
definition one_div_div (Ha : a ≠ 0) (Hb : b ≠ 0) : 1 / (a / b) = b / a :=
have H : (a / b) * (b / a) = 1, from calc
(a / b) * (b / a) = (a * b) / (b * a) : div_mul_div Hb Ha
... = (a * b) / (a * b) : mul.comm
... = 1 : div_self (mul_ne_zero' Ha Hb),
inverse (eq_one_div_of_mul_eq_one H)
definition div_div_eq_mul_div (Hb : b ≠ 0) (Hc : c ≠ 0) : a / (b / c) = (a * c) / b :=
by rewrite [div_eq_mul_one_div, (one_div_div Hb Hc), -mul_div_assoc]
definition div_div_eq_div_mul (Hb : b ≠ 0) (Hc : c ≠ 0) : (a / b) / c = a / (b * c) :=
by rewrite [div_eq_mul_one_div, (div_mul_div Hb Hc), mul_one]
definition div_div_div_div (Hb : b ≠ 0) (Hc : c ≠ 0) (Hd : d ≠ 0) : (a / b) / (c / d) = (a * d) / (b * c) :=
by rewrite [(div_div_eq_mul_div Hc Hd), (div_mul_eq_mul_div), (div_div_eq_div_mul Hb Hc)]
-- remaining to transfer from Isabelle fields: ordered fields
end field
structure discrete_field [class] (A : Type) extends field A :=
(has_decidable_eq : decidable_eq A)
(inv_zero : inv zero = zero)
attribute discrete_field.has_decidable_eq [instance]
section discrete_field
variable [s : discrete_field A]
include s
variables {a b c d : A}
-- many of the theorems in discrete_field are the same as theorems in field or division ring,
-- but with fewer hypotheses since 0⁻¹ = 0 and equality is decidable.
-- they are named with '. Is there a better convention?
definition discrete_field.eq_zero_or_eq_zero_of_mul_eq_zero
(x y : A) (H : x * y = 0) : x = 0 ⊎ y = 0 :=
decidable.by_cases
(assume H : x = 0, sum.inl H)
(assume H1 : x ≠ 0,
sum.inr (by rewrite [-one_mul, -(inv_mul_cancel H1), mul.assoc, H, mul_zero]))
definition discrete_field.to_integral_domain [instance] [reducible] [coercion] :
integral_domain A :=
⦃ integral_domain, s,
eq_zero_or_eq_zero_of_mul_eq_zero := discrete_field.eq_zero_or_eq_zero_of_mul_eq_zero⦄
definition inv_zero : 0⁻¹ = (0 : A) := !discrete_field.inv_zero
definition one_div_zero : 1 / 0 = (0:A) :=
calc
1 / 0 = 1 * 0⁻¹ : refl
... = 1 * 0 : discrete_field.inv_zero A
... = 0 : mul_zero
definition div_zero : a / 0 = 0 := by rewrite [div_eq_mul_one_div, one_div_zero, mul_zero]
definition ne_zero_of_one_div_ne_zero (H : 1 / a ≠ 0) : a ≠ 0 :=
assume Ha : a = 0, absurd (Ha⁻¹ ▸ one_div_zero) H
definition inv_zero_imp_zero (H : 1 / a = 0) : a = 0 :=
decidable.by_cases
(assume Ha, Ha)
(assume Ha, empty.elim ((one_div_ne_zero Ha) H))
-- the following could all go in "discrete_division_ring"
definition one_div_mul_one_div'' : (1 / a) * (1 / b) = 1 / (b * a) :=
decidable.by_cases
(assume Ha : a = 0,
by rewrite [Ha, div_zero, zero_mul, -(@div_zero A s 1), mul_zero b])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0,
by rewrite [Hb, div_zero, mul_zero, -(@div_zero A s 1), zero_mul a])
(assume Hb : b ≠ 0, one_div_mul_one_div Ha Hb))
definition one_div_neg_eq_neg_one_div' : 1 / (- a) = - (1 / a) :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, neg_zero, 2 div_zero, neg_zero])
(assume Ha : a ≠ 0, one_div_neg_eq_neg_one_div Ha)
definition neg_div' : (-b) / a = - (b / a) :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, 2 div_zero, neg_zero])
(assume Ha : a ≠ 0, neg_div Ha)
definition neg_div_neg_eq_div' : (-a) / (-b) = a / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, neg_zero, 2 div_zero])
(assume Hb : b ≠ 0, neg_div_neg_eq_div Hb)
definition div_div' : 1 / (1 / a) = a :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, 2 div_zero])
(assume Ha : a ≠ 0, div_div Ha)
definition eq_of_invs_eq' (H : 1 / a = 1 / b) : a = b :=
decidable.by_cases
(assume Ha : a = 0,
have Hb : b = 0, from inv_zero_imp_zero (by rewrite [-H, Ha, div_zero]),
Hb⁻¹ ▸ Ha)
(assume Ha : a ≠ 0,
have Hb : b ≠ 0, from ne_zero_of_one_div_ne_zero (H ▸ (one_div_ne_zero Ha)),
eq_of_invs_eq Ha Hb H)
definition mul_inv' : (b * a)⁻¹ = a⁻¹ * b⁻¹ :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, mul_zero, 2 inv_zero, zero_mul])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, zero_mul, 2 inv_zero, mul_zero])
(assume Hb : b ≠ 0, mul_inv_eq Ha Hb))
-- the following are specifically for fields
definition one_div_mul_one_div''' : (1 / a) * (1 / b) = 1 / (a * b) :=
by rewrite [(one_div_mul_one_div''), mul.comm b]
definition div_mul_right' (Ha : a ≠ 0) : a / (a * b) = 1 / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, mul_zero, 2 div_zero])
(assume Hb : b ≠ 0, div_mul_right Hb (mul_ne_zero Ha Hb))
definition div_mul_left' (Hb : b ≠ 0) : b / (a * b) = 1 / a :=
by rewrite [mul.comm a, div_mul_right' Hb]
definition div_mul_div' : (a / b) * (c / d) = (a * c) / (b * d) :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, div_zero, zero_mul, -(@div_zero A s (a * c)), zero_mul])
(assume Hb : b ≠ 0,
decidable.by_cases
(assume Hd : d = 0, by rewrite [Hd, div_zero, mul_zero, -(@div_zero A s (a * c)), mul_zero])
(assume Hd : d ≠ 0, div_mul_div Hb Hd))
definition mul_div_mul_left' (Hc : c ≠ 0) : (c * a) / (c * b) = a / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, mul_zero, 2 div_zero])
(assume Hb : b ≠ 0, mul_div_mul_left Hb Hc)
definition mul_div_mul_right' (Hc : c ≠ 0) : (a * c) / (b * c) = a / b :=
by rewrite [(mul.comm a), (mul.comm b), (mul_div_mul_left' Hc)]
-- this one is odd -- I am not sure what to call it, but again, the prefix is right
definition div_mul_eq_mul_div_comm' : (b / c) * a = b * (a / c) :=
decidable.by_cases
(assume Hc : c = 0, by rewrite [Hc, div_zero, zero_mul, -(mul_zero b), -(@div_zero A s a)])
(assume Hc : c ≠ 0, div_mul_eq_mul_div_comm Hc)
definition one_div_div' : 1 / (a / b) = b / a :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, zero_div, 2 div_zero])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, 2 div_zero, zero_div])
(assume Hb : b ≠ 0, one_div_div Ha Hb))
definition div_div_eq_mul_div' : a / (b / c) = (a * c) / b :=
by rewrite [div_eq_mul_one_div, one_div_div', -mul_div_assoc]
definition div_div_eq_div_mul' : (a / b) / c = a / (b * c) :=
by rewrite [div_eq_mul_one_div, div_mul_div', mul_one]
definition div_div_div_div' : (a / b) / (c / d) = (a * d) / (b * c) :=
by rewrite [div_div_eq_mul_div', div_mul_eq_mul_div, div_div_eq_div_mul']
end discrete_field
end algebra
/-
decidable.by_cases
(assume Ha : a = 0, sorry)
(assume Ha : a ≠ 0, sorry)
-/
|
6d72770d528645f52cd987d1000cb2cb4c725945
|
df561f413cfe0a88b1056655515399c546ff32a5
|
/5-advanced-proposition-world/l7.lean
|
44e74e7a5b603417c98f571624eba880347cf598
|
[] |
no_license
|
nicholaspun/natural-number-game-solutions
|
31d5158415c6f582694680044c5c6469032c2a06
|
1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0
|
refs/heads/main
| 1,675,123,625,012
| 1,607,633,548,000
| 1,607,633,548,000
| 318,933,860
| 3
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 119
|
lean
|
lemma or_symm (P Q : Prop) : P ∨ Q → Q ∨ P :=
begin
intro h,
cases h with p q,
right,
exact p,
left,
exact q,
end
|
626500154ae36d7d315d40c38d6fce3e44018c24
|
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
|
/tests/lean/run/meta3.lean
|
1e5c7eaa97a2243ec6ce99a24ae8121152e5105e
|
[
"Apache-2.0"
] |
permissive
|
collares/lean4
|
861a9269c4592bce49b71059e232ff0bfe4594cc
|
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
|
refs/heads/master
| 1,691,419,031,324
| 1,618,678,138,000
| 1,618,678,138,000
| 358,989,750
| 0
| 0
|
Apache-2.0
| 1,618,696,333,000
| 1,618,696,333,000
| null |
UTF-8
|
Lean
| false
| false
| 1,856
|
lean
|
import Lean.Meta
open Lean
open Lean.Meta
def dbgOpt : Options :=
let opt : Options := {};
let opt := opt.setBool `trace.Meta true;
-- let opt := opt.setBool `trace.Meta.check false;
opt
def print (msg : MessageData) : MetaM Unit :=
trace[Meta.debug] msg
def check (x : MetaM Bool) : MetaM Unit :=
unless (← x) do throwError "check failed"
def getAssignment (m : Expr) : MetaM Expr :=
do let v? ← getExprMVarAssignment? m.mvarId!;
(match v? with
| some v => pure v
| none => throwError "metavariable is not assigned")
unsafe def run (mods : List Name) (x : MetaM Unit) (opts : Options := dbgOpt) : IO Unit :=
withImportModules (mods.map $ fun m => {module := m}) {} 0 fun env => do
let x : MetaM Unit := do { x; printTraces };
discard $ x.toIO { options := opts } { env := env };
pure ()
def nat := mkConst `Nat
def succ := mkConst `Nat.succ
def add := mkAppN (mkConst `Add.add [levelZero]) #[nat, mkConst `Nat.add]
def tst1 : MetaM Unit :=
do let d : DiscrTree Nat := {};
let mvar ← mkFreshExprMVar nat;
let d ← d.insert (mkAppN add #[mvar, mkNatLit 10]) 1;
let d ← d.insert (mkAppN add #[mkNatLit 0, mkNatLit 10]) 2;
let d ← d.insert (mkAppN (mkConst `Nat.add) #[mkNatLit 0, mkNatLit 20]) 3;
let d ← d.insert (mkAppN add #[mvar, mkNatLit 20]) 4;
let d ← d.insert mvar 5;
print (format d);
let vs ← d.getMatch (mkAppN add #[mkNatLit 1, mkNatLit 10]);
print (format vs);
let t := mkAppN add #[mvar, mvar];
print t;
let vs ← d.getMatch t;
print (format vs);
let vs ← d.getUnify t;
print (format vs);
let vs ← d.getUnify mvar;
print (format vs);
let vs ← d.getUnify $ mkAppN add #[mkNatLit 0, mvar];
print (format vs);
let vs ← d.getUnify $ mkAppN add #[mvar, mkNatLit 20];
print (format vs);
pure ()
#eval run [`Init.Data.Nat] tst1
|
8250c77dc4cd911406373ba6e171267ecf9175a1
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/stage0/src/Lean/Util/Sorry.lean
|
cb57adfed787f2d679ceb7c1dc1ac9ab672a7f81
|
[
"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
| 2,236
|
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.Message
import Lean.Exception
import Lean.Util.FindExpr
namespace Lean
def Expr.isSorry : Expr → Bool
| app (app (.const ``sorryAx ..) ..) .. => true
| _ => false
def Expr.isSyntheticSorry : Expr → Bool
| app (app (const ``sorryAx ..) ..) (const ``Bool.true ..) => true
| _ => false
def Expr.isNonSyntheticSorry : Expr → Bool
| app (app (const ``sorryAx ..) ..) (const ``Bool.false ..) => true
| _ => false
def Expr.hasSorry (e : Expr) : Bool :=
Option.isSome <| e.find? (·.isConstOf ``sorryAx)
def Expr.hasSyntheticSorry (e : Expr) : Bool :=
Option.isSome <| e.find? (·.isSyntheticSorry)
def Expr.hasNonSyntheticSorry (e : Expr) : Bool :=
Option.isSome <| e.find? (·.isNonSyntheticSorry)
partial def MessageData.hasSorry : MessageData → Bool
| ofExpr e => e.hasSorry
| withContext _ msg => msg.hasSorry
| nest _ msg => msg.hasSorry
| group msg => msg.hasSorry
| compose msg₁ msg₂ => msg₁.hasSorry || msg₂.hasSorry
| tagged _ msg => msg.hasSorry
| node msgs => msgs.any hasSorry
| _ => false
partial def MessageData.hasSyntheticSorry (msg : MessageData) : Bool :=
visit msg.instantiateMVars
where
visit : MessageData → Bool
| ofExpr e => e.hasSyntheticSorry
| withContext _ msg => visit msg
| withNamingContext _ msg => visit msg
| nest _ msg => visit msg
| group msg => visit msg
| compose msg₁ msg₂ => visit msg₁ || visit msg₂
| tagged _ msg => visit msg
| node msgs => msgs.any hasSyntheticSorry
| _ => false
def Exception.hasSyntheticSorry : Exception → Bool
| Exception.error _ msg => msg.hasSyntheticSorry
| _ => false
def Declaration.hasSorry (d : Declaration) : Bool := Id.run do
d.foldExprM (fun r e => r || e.hasSorry) false
def Declaration.hasNonSyntheticSorry (d : Declaration) : Bool := Id.run do
d.foldExprM (fun r e => r || e.hasNonSyntheticSorry) false
end Lean
|
dfa1fa66581042c1a84ddcf8510f16956623c45e
|
3bdd27ffdff3ffa22d4bb010eba695afcc96bc4a
|
/src/combinatorics/simplicial_complex/skeleton.lean
|
45dabce4cf1b0cdce76c82ee4949d2988cb90ccb
|
[] |
no_license
|
mmasdeu/brouwerfixedpoint
|
684d712c982c6a8b258b4e2c6b2eab923f2f1289
|
548270f79ecf12d7e20a256806ccb9fcf57b87e2
|
refs/heads/main
| 1,690,539,793,996
| 1,631,801,831,000
| 1,631,801,831,000
| 368,139,809
| 4
| 3
| null | 1,624,453,250,000
| 1,621,246,034,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,453
|
lean
|
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import combinatorics.simplicial_complex.pure
namespace affine
open set
variables {m n k : ℕ} {E : Type*} [normed_group E] [normed_space ℝ E]
{S : simplicial_complex E} {X Y : finset E} {A : set (finset E)}
/--
The k-skeleton of a simplicial complex is the simplicial complex made of its simplices of dimension
less than k.
-/
def simplicial_complex.skeleton (S : simplicial_complex E) (k : ℕ) :
simplicial_complex E :=
simplicial_complex.of_surcomplex
{X ∈ S.faces | finset.card X ≤ k + 1}
(λ X ⟨hX, _⟩, hX)
(λ X Y hX hY, ⟨S.down_closed hX.1 hY, le_trans (finset.card_le_of_subset hY) hX.2⟩)
lemma skeleton_subcomplex :
(S.skeleton k).faces ⊆ S.faces :=
λ X ⟨hX, _⟩, hX
lemma skeleton_nonempty_iff :
(S.skeleton k).faces.nonempty ↔ S.faces.nonempty :=
begin
split,
{ apply nonempty.mono skeleton_subcomplex },
{ rintro ⟨X, hX⟩,
exact ⟨∅, S.down_closed hX X.empty_subset, nat.zero_le _⟩ }
end
lemma pure_skeleton_of_pure [finite_dimensional ℝ E] (hS : S.pure_of n) :
(S.skeleton k).pure_of (min n (k + 1)) :=
begin
cases le_or_gt n (k + 1) with hmin hmin,
{ rw min_eq_left hmin,
rintro X hXskel,
obtain ⟨Y, hY, hXY⟩ := subfacet (skeleton_subcomplex (facets_subset hXskel)),
have hYskel : Y ∈ (S.skeleton k).faces,
{ use facets_subset hY,
simp,
rw hS hY,
exact hmin, },
rw hXskel.2 hYskel hXY,
exact hS hY },
{ rw min_eq_right (le_of_lt hmin),
rintro X ⟨⟨hX, hXcard⟩, hXmax⟩,
obtain ⟨Y, hY, hXY⟩ := subfacet hX,
have : k + 1 - X.card + X.card ≤ Y.card,
{ rw hS hY,
rw nat.sub_add_cancel hXcard,
exact le_of_lt hmin, },
obtain ⟨Z, hXZ, hZY, hZcard⟩ := finset.exists_intermediate_set (k + 1 - X.card) this hXY,
rw nat.sub_add_cancel hXcard at hZcard,
rw hXmax ⟨S.down_closed (facets_subset hY) hZY, le_of_eq hZcard⟩ hXZ,
exact hZcard, }
end
lemma skeleton_pureness_eq_min_pureness_dimension [finite_dimensional ℝ E] (hS : S.pure)
(hS' : S.faces.nonempty) :
(S.skeleton k).pureness = min S.pureness (k + 1) :=
begin
rcases hS with ⟨n, hn⟩,
rw [pureness_def' hS' hn, pureness_def'],
{ rwa skeleton_nonempty_iff },
{ apply pure_skeleton_of_pure hn },
end
end affine
|
8b685c4f84860fe1b5c6f9943d68533fb1c39c1a
|
4d3f29a7b2eff44af8fd0d3176232e039acb9ee3
|
/Mathlib/Mathlib/Tactic/Ring.lean
|
9c0b8c355f90233a9e49ac3e87cb2b86531659a1
|
[] |
no_license
|
marijnheule/lamr
|
5fc5d69d326ff92e321242cfd7f72e78d7f99d7e
|
28cc4114c7361059bb54f407fa312bf38b48728b
|
refs/heads/main
| 1,689,338,013,620
| 1,630,359,632,000
| 1,630,359,632,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 20,615
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Aurélien Saue
-/
import Lean.Elab.Tactic.Basic
import Mathlib.Algebra.Ring.Basic
import Mathlib.Tactic.NormNum
/-!
# `ring`
Evaluate expressions in the language of commutative (semi)rings.
Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> .
-/
open Lean Parser.Tactic Elab Command Elab.Tactic Meta
namespace Tactic
namespace Ring
/-- This cache contains data required by the `ring` tactic during execution. -/
structure Cache :=
α : Expr
univ : Level
cs : Expr
structure State :=
atoms : Array Expr := #[]
numAtoms : Nat := 0
/-- The monad that `ring` works in. This is a reader monad containing a cache and
the list of atoms-up-to-defeq encountered thus far, used for atom sorting. -/
abbrev RingM := ReaderT Cache $ StateRefT State MetaM
def RingM.run (ty : Expr) (m : RingM α) : MetaM α := do
let Level.succ u _ ← getLevel ty | throwError "fail"
let inst ← synthInstance (mkApp (mkConst ``CommSemiring [u]) ty)
(m {α := ty, univ := u, cs := inst }).run' {}
def mkAppCS (f : Name) (args : Array Expr) : RingM Expr := do
let c ← read
mkAppN (mkConst f [c.univ]) (#[c.α, c.cs] ++ args)
/-- Get the index corresponding to an atomic expression, if it has already been encountered, or
put it in the list of atoms and return the new index, otherwise. -/
def addAtom (e : Expr) : RingM Nat := do
let c ← get
for i in [:c.numAtoms] do
if ← isDefEq e c.atoms[i] then
return i
modify λ c => { c with atoms := c.atoms.push e, numAtoms := c.numAtoms + 1}
return c.numAtoms
/-- The normal form that `ring` uses is mediated by the function `horner a x n b := a * x ^ n + b`.
The reason we use a definition rather than the (more readable) expression on the right is because
this expression contains a number of typeclass arguments in different positions, while `horner`
contains only one `CommSemiring` instance at the top level. See also `HornerExpr` for a
description of normal form. -/
@[reducible] def horner {α} [CommSemiring α] (a x : α) (n : ℕ) (b : α) := a * (x ^ n) + b
/-- Every expression in the language of commutative semirings can be viewed as a sum of monomials,
where each monomial is a product of powers of atoms. We fix a global order on atoms (up to
definitional equality), and then separate the terms according to their smallest atom. So the top
level expression is `a * x^n + b` where `x` is the smallest atom and `n > 0` is a numeral, and
`n` is maximal (so `a` contains at least one monomial not containing an `x`), and `b` contains no
monomials with an `x` (hence all atoms in `b` are larger than `x`).
If there is no `x` satisfying these constraints, then the expression must be a numeral. Even though
we are working over rings, we allow rational constants when these can be interpreted in the ring,
so we can solve problems like `x / 3 = 1 / 3 * x` even though these are not technically in the
language of rings.
These constraints ensure that there is a unique normal form for each ring expression, and so the
algorithm is simply to calculate the normal form of each side and compare for equality.
To allow us to efficiently pattern match on normal forms, we maintain this inductive type that
holds a normalized expression together with its structure. All the `Expr`s in this type could be
removed without loss of information, and conversely the `horner_expr` structure and the `ℕ` and
`ℚ` values can be recovered from the top level `Expr`, but we keep both in order to keep proof
producing normalization functions efficient. -/
inductive HornerExpr : Type
| const (e : Expr) (coeff : ℕ) : HornerExpr --TODO : coeff in ℚ
| xadd (e : Expr) (a : HornerExpr) (x : Expr × ℕ) (n : Expr × ℕ) (b : HornerExpr) : HornerExpr
instance : Inhabited HornerExpr := ⟨HornerExpr.const (mkRawNatLit 0) 0⟩
namespace HornerExpr
/-- Get the expression corresponding to a `HornerExpr`. This can be calculated recursively from
the structure, but we cache the exprs in all subterms so that this function can be computed in
constant time. -/
def e : HornerExpr → Expr
| (HornerExpr.const e _) => e
| (HornerExpr.xadd e _ _ _ _) => e
instance : Coe HornerExpr Expr := ⟨e⟩
/-- Is this expr the constant `0`? -/
def isZero : HornerExpr → Bool
| (HornerExpr.const _ c) => c = 0
| _ => false
/-- Construct a `xadd` node -/
def xadd' (a : HornerExpr) (x : Expr × ℕ) (n : Expr × ℕ) (b : HornerExpr) : RingM HornerExpr := do
xadd (← mkAppCS ``horner #[a, x.1, n.1, b]) a x n b
/-- Reflexivity conversion for a `HornerExpr`. -/
def reflConv (e : HornerExpr) : RingM (HornerExpr × Expr) := do (e, ← mkEqRefl e)
/-- Pretty printer for `horner_expr`. -/
def pp : HornerExpr → MetaM Format
| (const e c) => do
let pe ← PrettyPrinter.ppExpr Name.anonymous [] e
return "[" ++ pe ++ ", " ++ toString c ++ "]"
| (xadd e a x (_, n) b) => do
let pa ← a.pp
let pb ← b.pp
let px ← PrettyPrinter.ppExpr Name.anonymous [] x.1
return "(" ++ pa ++ ") * (" ++ px ++ ")^" ++ toString n ++ " + " ++ pb
end HornerExpr
open HornerExpr
theorem zero_horner {α} [CommSemiring α] (x n b) :
@horner α _ 0 x n b = b :=
by simp [horner]
theorem horner_horner {α} [CommSemiring α] (a₁ x n₁ n₂ b n')
(h : n₁ + n₂ = n') :
@horner α _ (horner a₁ x n₁ 0) x n₂ b = horner a₁ x n' b :=
by simp [h.symm, horner, pow_add, mul_assoc]
/-- Evaluate `horner a n x b` where `a` and `b` are already in normal form. -/
def evalHorner : HornerExpr → Expr × ℕ → Expr × ℕ → HornerExpr → RingM (HornerExpr × Expr)
| ha@(const a coeff), x, n, b => do
if coeff = 0 then
return (b, ← mkAppCS ``zero_horner #[x.1, n.1, b])
else (← xadd' ha x n b).reflConv
| ha@(xadd a a₁ x₁ n₁ b₁), x, n, b => do
if x₁.2 = x.2 ∧ b₁.e.numeral? = some 0 then do
let n' ← mkRawNatLit (n₁.2 + n.2)
let h ← mkEqRefl n'
return (← xadd' a₁ x (n', n₁.2 + n.2) b,
← mkAppCS ``horner_horner #[a₁, x.1, n₁.1, n.1, b, n', h])
else (← xadd' ha x n b).reflConv
theorem const_add_horner {α} [CommSemiring α] (k a x n b b') (h : k + b = b') :
k + @horner α _ a x n b = horner a x n b' :=
by
simp [horner, h.symm, add_comm k, add_assoc]
theorem horner_add_const {α} [CommSemiring α] (a x n b k b') (h : b + k = b') :
@horner α _ a x n b + k = horner a x n b' :=
by
simp [horner, h.symm ,add_left_comm k, add_assoc]
theorem horner_add_horner_lt {α} [CommSemiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₁ + k = n₂) (h₂ : (a₁ + horner a₂ x k 0 : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₁ b' :=
by
rw [← h₁, ← h₂, ← h₃]
simp [horner, add_mul, mul_assoc, (pow_add x k n₁).symm, add_comm k, @add_comm α _, @add_assoc α _]
theorem horner_add_horner_gt {α} [CommSemiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₂ + k = n₁) (h₂ : (horner a₁ x k 0 + a₂ : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₂ b' :=
by
rw [← h₁, ← h₂, ← h₃]
simp [horner, add_mul, mul_assoc, (pow_add x k n₂).symm, add_comm k, @add_comm α _, @add_assoc α _]
theorem horner_add_horner_eq {α} [CommSemiring α] (a₁ x n b₁ a₂ b₂ a' b' t)
(h₁ : a₁ + a₂ = a') (h₂ : b₁ + b₂ = b') (h₃ : horner a' x n b' = t) :
@horner α _ a₁ x n b₁ + horner a₂ x n b₂ = t :=
by
rw [← h₃, ← h₁, ← h₂]
simp [horner, add_mul, @add_comm α _, @add_assoc α _]
partial def evalAdd : HornerExpr → HornerExpr → RingM (HornerExpr × Expr)
| (const e₁ c₁), (const e₂ c₂) => do
let (e', p) ← NormNum.eval $ ← mkAdd e₁ e₂
(const e' (c₁ + c₂), p)
| he₁@(const e₁ c₁), he₂@(xadd e₂ a x n b) => do
if c₁ = 0 then
let p ← mkAppM ``zero_add #[e₂]
return (he₂, p)
else
let (b', h) ← evalAdd he₁ b
return (← xadd' a x n b',
← mkAppCS ``const_add_horner #[e₁, a, x.1, n.1, b, b', h])
| he₁@(xadd e₁ a x n b), he₂@(const e₂ c₂) => do
if c₂ = 0 then
let p ← mkAppM ``add_zero #[e₁]
return (he₁, p)
else
let (b', h) ← evalAdd b he₂
return (← xadd' a x n b',
← mkAppCS ``horner_add_const #[a, x.1, n.1, b, e₂, b', h])
| he₁@(xadd e₁ a₁ x₁ n₁ b₁), he₂@(xadd e₂ a₂ x₂ n₂ b₂) => do
let c ← get
if x₁.2 < x₂.2 then
let (b', h) ← evalAdd b₁ he₂
return (← xadd' a₁ x₁ n₁ b',
← mkAppCS ``horner_add_const #[a₁, x₁.1, n₁.1, b₁, e₂, b', h])
else if x₁.2 ≠ x₂.2 then
let (b', h) ← evalAdd he₁ b₂
return (← xadd' a₂ x₂ n₂ b',
← mkAppCS ``const_add_horner #[e₁, a₂, x₂.1, n₂.1, b₂, b', h])
else if n₁.2 < n₂.2 then do
let k := n₂.2 - n₁.2
let ek ← mkRawNatLit k
let h₁ ← mkEqRefl n₂.1
let c ← read
let α0 ← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 0, none]
let (a', h₂) ← evalAdd a₁ (← xadd' a₂ x₁ (ek, k) (const α0 0))
let (b', h₃) ← evalAdd b₁ b₂
return (← xadd' a' x₁ n₁ b',
← mkAppCS ``horner_add_horner_lt #[a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, ek, a', b', h₁, h₂, h₃])
else if n₁.2 ≠ n₂.2 then do
let k := n₁.2 - n₂.2
let ek ← mkRawNatLit k
let h₁ ← mkEqRefl n₁.1
let α0 ← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 0, none]
let (a', h₂) ← evalAdd (← xadd' a₁ x₁ (ek, k) (const α0 0)) a₂
let (b', h₃) ← evalAdd b₁ b₂
return (← xadd' a' x₁ n₂ b',
← mkAppCS ``horner_add_horner_gt #[a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, ek, a', b', h₁, h₂, h₃])
else do
let (a', h₁) ← evalAdd a₁ a₂
let (b', h₂) ← evalAdd b₁ b₂
let (t, h₃) ← evalHorner a' x₁ n₁ b'
return (t, ← mkAppCS ``horner_add_horner_eq
#[a₁, x₁.1, n₁.1, b₁, a₂, b₂, a', b', t, h₁, h₂, h₃])
theorem horner_const_mul {α} [CommSemiring α] (c a x n b a' b')
(h₁ : c * a = a') (h₂ : c * b = b') :
c * @horner α _ a x n b = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner, mul_add, mul_assoc]
theorem horner_mul_const {α} [CommSemiring α] (a x n b c a' b')
(h₁ : a * c = a') (h₂ : b * c = b') :
@horner α _ a x n b * c = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner, add_mul, @mul_right_comm α _]
/-- Evaluate `k * a` where `k` is a rational numeral and `a` is in normal form. -/
def evalConstMul (k : Expr × ℕ) : HornerExpr → RingM (HornerExpr × Expr)
| (const e coeff) => do
let (e', p) ← NormNum.eval $ ← mkMul k.1 e
return (const e' (k.2 * coeff), p)
| (xadd e a x n b) => do
let (a', h₁) ← evalConstMul k a
let (b', h₂) ← evalConstMul k b
return (← xadd' a' x n b',
← mkAppCS ``horner_const_mul #[k.1, a, x.1, n.1, b, a', b', h₁, h₂])
theorem horner_mul_horner_zero {α} [CommSemiring α] (a₁ x n₁ b₁ a₂ n₂ aa t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ 0 = t :=
by
rw [← h₂, ← h₁]
simp [horner, add_mul, mul_assoc]
theorem horner_mul_horner {α} [CommSemiring α]
(a₁ x n₁ b₁ a₂ n₂ b₂ aa haa ab bb t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = haa)
(h₃ : a₁ * b₂ = ab) (h₄ : b₁ * b₂ = bb)
(H : haa + horner ab x n₁ bb = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ b₂ = t :=
by
rw [← H, ← h₂, ← h₁, ← h₃, ← h₄]
simp [horner, mul_add, add_mul, @mul_comm α _, mul_left_comm, mul_assoc]
/-- Evaluate `a * b` where `a` and `b` are in normal form. -/
partial def evalMul : HornerExpr → HornerExpr → RingM (HornerExpr × Expr)
| (const e₁ c₁), (const e₂ c₂) => do
let (e', p) ← NormNum.eval $ ← mkMul e₁ e₂
return (const e' (c₁ * c₂), p)
| (const e₁ c₁), e₂ =>
if c₁ = 0 then do
let α0 ← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 0, none]
let p ← mkAppM ``zero_mul #[e₂]
return (const α0 0, p)
else if c₁ = 1 then do
let p ← mkAppM ``one_mul #[e₂]
return (e₂, p)
else evalConstMul (e₁, c₁) e₂
| e₁, he₂@(const e₂ c₂) => do
let p₁ ← mkAppM ``mul_comm #[e₁, e₂]
let (e', p₂) ← evalMul he₂ e₁
let p ← mkEqTrans p₁ p₂
return (e', p)
| he₁@(xadd e₁ a₁ x₁ n₁ b₁), he₂@(xadd e₂ a₂ x₂ n₂ b₂) => do
if x₁.2 < x₂.2 then do
let (a', h₁) ← evalMul a₁ he₂
let (b', h₂) ← evalMul b₁ he₂
return (← xadd' a' x₁ n₁ b',
← mkAppCS ``horner_mul_const #[a₁, x₁.1, n₁.1, b₁, e₂, a', b', h₁, h₂])
else if x₁.2 ≠ x₂.2 then do
let (a', h₁) ← evalMul he₁ a₂
let (b', h₂) ← evalMul he₁ b₂
return (← xadd' a' x₂ n₂ b',
← mkAppCS ``horner_const_mul #[e₁, a₂, x₂.1, n₂.1, b₂, a', b', h₁, h₂])
else do
let (aa, h₁) ← evalMul he₁ a₂
let α0 ← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 0, none]
let (haa, h₂) ← evalHorner aa x₁ n₂ (const α0 0)
if b₂.isZero then
return (haa, ← mkAppCS ``horner_mul_horner_zero
#[a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, aa, haa, h₁, h₂])
else do
let (ab, h₃) ← evalMul a₁ b₂
let (bb, h₄) ← evalMul b₁ b₂
let (t, H) ← evalAdd haa (← xadd' ab x₁ n₁ bb)
return (t, ← mkAppCS ``horner_mul_horner
#[a₁, x₁.1, n₁.1, b₁, a₂, n₂.1, b₂, aa, haa, ab, bb, t, h₁, h₂, h₃, h₄, H])
theorem horner_pow {α} [CommSemiring α] (a x : α) (n m n' : ℕ) (a') (h₁ : n * m = n') (h₂ : a ^ m = (a' : α)) :
@horner α _ a x n 0 ^ m = horner a' x n' 0 :=
by
simp [h₁.symm, h₂.symm, horner, mul_pow a, pow_mul]
theorem pow_succ_eq {α} [CommSemiring α] (a : α) (n : ℕ) (b c)
(h₁ : a ^ n = b) (h₂ : b * a = c) : a ^ (n + 1) = c :=
by rw [← h₂, ← h₁, pow_succ]
/-- Evaluate `a ^ n` where `a` is in normal form and `n` is a natural numeral. -/
partial def evalPow : HornerExpr → Expr × ℕ → RingM (HornerExpr × Expr)
| e, (_, 0) => do
let α1 ← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 1, none]
let p ← mkAppM ``pow_zero #[e]
(const α1 1, p)
| e, (_, 1) => do
let p ← mkAppM ``pow_one #[e]
(e, p)
| const e coeff, (e₂, m) => do
let (e', p) ← NormNum.eval $ ← mkAppM ``HPow.hPow #[e, e₂]
(const e' (coeff ^ m), p)
| he@(xadd e a x n b), m =>
match b.e.numeral? with
| some 0 => do
let n' ← mkRawNatLit (n.2 * m.2)
let h₁ ← mkEqRefl n'
let (a', h₂) ← evalPow a m
let α0 ← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 0, none]
(← xadd' a' x (n', n.2 * m.2) (const α0 0),
← mkAppCS ``horner_pow #[a, x.1, n.1, m.1, n', a', h₁, h₂])
| _ => do
let e₂ ← mkRawNatLit (m.2 - 1)
let (tl, hl) ← evalPow he (e₂, m.2-1)
let (t, p₂) ← evalMul tl he
(t, ← mkAppCS ``pow_succ_eq #[e, e₂, tl, t, hl, p₂])
theorem horner_atom {α} [CommSemiring α] (x : α) : x = horner 1 x 1 0 := by
simp [horner]
/-- Evaluate `a` where `a` is an atom. -/
def evalAtom (e : Expr) : RingM (HornerExpr × Expr) := do
let i ← addAtom e
let zero ← const (← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 0, none]) 0
let one ← const (← mkAppOptM ``OfNat.ofNat #[(← read).α, mkRawNatLit 1, none]) 1
(← xadd' one (e,i) (mkRawNatLit 1,1) zero, ← mkAppCS ``horner_atom #[e])
theorem subst_into_add {α} [Add α] (l r tl tr t)
(prl : (l : α) = tl) (prr : r = tr) (prt : tl + tr = t) : l + r = t :=
by rw [prl, prr, prt]
theorem subst_into_mul {α} [Mul α] (l r tl tr t)
(prl : (l : α) = tl) (prr : r = tr) (prt : tl * tr = t) : l * r = t :=
by rw [prl, prr, prt]
theorem subst_into_pow {α} [Monoid α] (l r tl tr t)
(prl : (l : α) = tl) (prr : (r : ℕ) = tr) (prt : tl ^ tr = t) : l ^ r = t :=
by rw [prl, prr, prt]
partial def eval (e : Expr) : RingM (HornerExpr × Expr) :=
match e.getAppFnArgs with
| (``HAdd.hAdd, #[_,_,_,_,e₁,e₂]) => do
let (e₁', p₁) ← eval e₁
let (e₂', p₂) ← eval e₂
let (e', p') ← evalAdd e₁' e₂'
let p ← mkAppM ``subst_into_add #[e₁, e₂, e₁', e₂', e', p₁, p₂, p']
(e',p)
| (``HMul.hMul, #[_,_,_,_,e₁,e₂]) => do
let (e₁', p₁) ← eval e₁
let (e₂', p₂) ← eval e₂
let (e', p') ← evalMul e₁' e₂'
let p ← mkAppM ``subst_into_mul #[e₁, e₂, e₁', e₂', e', p₁, p₂, p']
return (e', p)
| (``HPow.hPow, #[_,_,_,P,e₁,e₂]) => do
-- let (e₂', p₂) ← lift $ norm_num.derive e₂ <|> refl_conv e₂,
let (e₂', p₂) ← (e₂, ← mkEqRefl e₂)
match e₂'.numeral?, P.getAppFn with
| some k, Expr.const ``Monoid.HPow _ _ => do
let (e₁', p₁) ← eval e₁
let (e', p') ← evalPow e₁' (e₂, k)
let p ← mkAppM ``subst_into_pow #[e₁, e₂, e₁', e₂', e', p₁, p₂, p']
return (e', p)
| _, _ => evalAtom e
| _ =>
match e.numeral? with
| some n => (const e n).reflConv
| _ => evalAtom e
elab "ring" : tactic => do
let g ← getMainTarget
match g.getAppFnArgs with
| (`Eq, #[ty, e₁, e₂]) =>
let ((e₁', p₁), (e₂', p₂)) ← RingM.run ty $ do (← eval e₁, ← eval e₂)
if ← isDefEq e₁' e₂' then
let p ← mkEqTrans p₁ (← mkEqSymm p₂)
ensureHasNoMVars p
assignExprMVar (← getMainGoal) p
replaceMainGoal []
else
throwError "failed \n{← e₁'.pp}\n{← e₂'.pp}"
| _ => throwError "failed: not an equality"
example (x y : ℕ) : x + y = y + x := by ring
example (x y : ℕ) : x + y + y = 2 * y + x := by ring
example (x y : ℕ) : x + id y = y + id x := by ring
-- example {α} [CommRing α] (x y : α) : x + y + y - x = 2 * y := by ring
-- example (x y : ℚ) : x / 2 + x / 2 = x := by ring
example (x y : ℕ) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring
-- example (x y : ℝ) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring
example {α} [CommSemiring α] (x : α) : (x + 1) ^ 6 = (1 + x) ^ 6 := by ring
example (n : ℕ) : (n / 2) + (n / 2) = 2 * (n / 2) := by ring
-- example {α} [field α] [char_zero α] (a : α) : a / 2 = a / 2 := by ring
-- example {α} [linear_ordered_field α] (a b c : α) :
-- a * (-c / b) * (-c / b) + -c + c = a * (c / b * (c / b)) := by ring
-- example {α} [linear_ordered_field α] (a b c : α) :
-- b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring
-- example (x : ℚ) : x ^ (2 + 2) = x^4 := by ring_nf -- TODO: ring should work?
-- example {α} [CommRing α] (x : α) : x ^ (2 : ℤ) = x * x := by ring
-- example {α} [linear_ordered_field α] (a b c : α) :
-- b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring
-- example {α} [linear_ordered_field α] (a b c : α) :
-- b ^ 2 - 4 * a * c = 4 * a * 0 + b * b - 4 * a * c := by ring
example {α} [CommSemiring α] (x y z : α) (n : ℕ) :
(x + y) * (z * (y * y) + (x * x ^ n + (1 + ↑n) * x ^ n * y)) =
x * (x * x ^ n) + ((2 + ↑n) * (x * x ^ n) * y + (x * z + (z * y + (1 + ↑n) * x ^ n)) * (y * y)) := by ring
-- example {α} [CommRing α] (a b c d e : α) :
-- (-(a * b) + c + d) * e = (c + (d + -a * b)) * e := by ring
example (a n s: ℕ) : a * (n - s) = (n - s) * a := by ring
example (A : ℕ) : (2 * A) ^ 2 = (2 * A) ^ 2 := by ring
-- example (x y z : ℚ) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
-- x / (y / z) + y ⁻¹ + 1 / (y * -x) = -1/ (x * y) + (x * z + 1) / y :=
-- begin
-- field_simp,
-- ring
-- end
-- example (a b c d x y : ℚ) (hx : x ≠ 0) (hy : y ≠ 0) :
-- a + b / x - c / x^2 + d / x^3 = a + x⁻¹ * (y * b / y + (d / x - c) / x) :=
-- begin
-- field_simp,
-- ring
-- end
-- example : (876544 : ℤ) * -1 + (1000000 - 123456) = 0 := by ring
-- example (x y : ℝ) (hx : x ≠ 0) (hy : y ≠ 0) :
-- 2 * x ^ 3 * 2 / (24 * x) = x ^ 2 / 6 :=
-- begin
-- field_simp,
-- ring
-- end
-- -- this proof style is not recommended practice
-- example (A B : ℕ) (H : B * A = 2) : A * B = 2 := by {ring_nf, exact H}
|
fbceea9a9df7b828ba73c284a436a02a2d90f6e4
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/algebra/category/Module/adjunctions.lean
|
82e53b302f2e426bc9a6077f07a2d9cdf8bf365c
|
[
"Apache-2.0"
] |
permissive
|
urkud/mathlib
|
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
|
6379d39e6b5b279df9715f8011369a301b634e41
|
refs/heads/master
| 1,658,425,342,662
| 1,658,078,703,000
| 1,658,078,703,000
| 186,910,338
| 0
| 0
|
Apache-2.0
| 1,568,512,083,000
| 1,557,958,709,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 10,915
|
lean
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johan Commelin
-/
import algebra.category.Module.monoidal
import category_theory.monoidal.functorial
import category_theory.monoidal.types
import linear_algebra.direct_sum.finsupp
import category_theory.linear.linear_functor
/-!
The functor of forming finitely supported functions on a type with values in a `[ring R]`
is the left adjoint of
the forgetful functor from `R`-modules to types.
-/
noncomputable theory
open category_theory
namespace Module
universe u
open_locale classical
variables (R : Type u)
section
variables [ring R]
/--
The free functor `Type u ⥤ Module R` sending a type `X` to the
free `R`-module with generators `x : X`, implemented as the type `X →₀ R`.
-/
@[simps]
def free : Type u ⥤ Module R :=
{ obj := λ X, Module.of R (X →₀ R),
map := λ X Y f, finsupp.lmap_domain _ _ f,
map_id' := by { intros, exact finsupp.lmap_domain_id _ _ },
map_comp' := by { intros, exact finsupp.lmap_domain_comp _ _ _ _, } }
/--
The free-forgetful adjunction for R-modules.
-/
def adj : free R ⊣ forget (Module.{u} R) :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X M, (finsupp.lift M R X).to_equiv.symm,
hom_equiv_naturality_left_symm' := λ _ _ M f g,
finsupp.lhom_ext' (λ x, linear_map.ext_ring
(finsupp.sum_map_domain_index_add_monoid_hom (λ y, ((smul_add_hom R M).flip) (g y))).symm) }
instance : is_right_adjoint (forget (Module.{u} R)) := ⟨_, adj R⟩
end
namespace free
variables [comm_ring R]
local attribute [ext] tensor_product.ext
/-- (Implementation detail) The unitor for `free R`. -/
def ε : 𝟙_ (Module.{u} R) ⟶ (free R).obj (𝟙_ (Type u)) :=
finsupp.lsingle punit.star
@[simp] lemma ε_apply (r : R) : ε R r = finsupp.single punit.star r := rfl
/-- (Implementation detail) The tensorator for `free R`. -/
def μ (α β : Type u) : (free R).obj α ⊗ (free R).obj β ≅ (free R).obj (α ⊗ β) :=
(finsupp_tensor_finsupp' R α β).to_Module_iso
lemma μ_natural {X Y X' Y' : Type u} (f : X ⟶ Y) (g : X' ⟶ Y') :
((free R).map f ⊗ (free R).map g) ≫ (μ R Y Y').hom =
(μ R X X').hom ≫ (free R).map (f ⊗ g) :=
begin
intros,
ext x x' ⟨y, y'⟩,
dsimp [μ],
simp_rw [finsupp.map_domain_single, finsupp_tensor_finsupp'_single_tmul_single, mul_one,
finsupp.map_domain_single, category_theory.tensor_apply],
end
lemma left_unitality (X : Type u) :
(λ_ ((free R).obj X)).hom =
(ε R ⊗ 𝟙 ((free R).obj X)) ≫ (μ R (𝟙_ (Type u)) X).hom ≫ map (free R).obj (λ_ X).hom :=
begin
intros,
ext,
dsimp [ε, μ],
simp_rw [finsupp_tensor_finsupp'_single_tmul_single,
Module.monoidal_category.left_unitor_hom_apply, finsupp.smul_single', mul_one,
finsupp.map_domain_single, category_theory.left_unitor_hom_apply],
end
lemma right_unitality (X : Type u) :
(ρ_ ((free R).obj X)).hom =
(𝟙 ((free R).obj X) ⊗ ε R) ≫ (μ R X (𝟙_ (Type u))).hom ≫ map (free R).obj (ρ_ X).hom :=
begin
intros,
ext,
dsimp [ε, μ],
simp_rw [finsupp_tensor_finsupp'_single_tmul_single,
Module.monoidal_category.right_unitor_hom_apply, finsupp.smul_single', mul_one,
finsupp.map_domain_single, category_theory.right_unitor_hom_apply],
end
lemma associativity (X Y Z : Type u) :
((μ R X Y).hom ⊗ 𝟙 ((free R).obj Z)) ≫ (μ R (X ⊗ Y) Z).hom ≫ map (free R).obj (α_ X Y Z).hom =
(α_ ((free R).obj X) ((free R).obj Y) ((free R).obj Z)).hom ≫
(𝟙 ((free R).obj X) ⊗ (μ R Y Z).hom) ≫ (μ R X (Y ⊗ Z)).hom :=
begin
intros,
ext,
dsimp [μ],
simp_rw [finsupp_tensor_finsupp'_single_tmul_single, finsupp.map_domain_single, mul_one,
category_theory.associator_hom_apply],
end
/-- The free R-module functor is lax monoidal. -/
-- In fact, it's strong monoidal, but we don't yet have a typeclass for that.
@[simps]
instance : lax_monoidal.{u} (free R).obj :=
{ -- Send `R` to `punit →₀ R`
ε := ε R,
-- Send `(α →₀ R) ⊗ (β →₀ R)` to `α × β →₀ R`
μ := λ X Y, (μ R X Y).hom,
μ_natural' := λ X Y X' Y' f g, μ_natural R f g,
left_unitality' := left_unitality R,
right_unitality' := right_unitality R,
associativity' := associativity R, }
instance : is_iso (lax_monoidal.ε (free R).obj) :=
⟨⟨finsupp.lapply punit.star, ⟨by { ext, simp, }, by { ext ⟨⟩ ⟨⟩, simp, }⟩⟩⟩
end free
variables [comm_ring R]
/-- The free functor `Type u ⥤ Module R`, as a monoidal functor. -/
def monoidal_free : monoidal_functor (Type u) (Module.{u} R) :=
{ ε_is_iso := by { dsimp, apply_instance, },
μ_is_iso := λ X Y, by { dsimp, apply_instance, },
..lax_monoidal_functor.of (free R).obj }
example (X Y : Type u) : (free R).obj (X × Y) ≅ (free R).obj X ⊗ (free R).obj Y :=
((monoidal_free R).μ_iso X Y).symm
end Module
namespace category_theory
universes v u
/--
`Free R C` is a type synonym for `C`, which, given `[comm_ring R]` and `[category C]`,
we will equip with a category structure where the morphisms are formal `R`-linear combinations
of the morphisms in `C`.
-/
@[nolint unused_arguments has_inhabited_instance]
def Free (R : Type*) (C : Type u) := C
/--
Consider an object of `C` as an object of the `R`-linear completion.
It may be preferable to use `(Free.embedding R C).obj X` instead;
this functor can also be used to lift morphisms.
-/
def Free.of (R : Type*) {C : Type u} (X : C) : Free R C := X
variables (R : Type*) [comm_ring R] (C : Type u) [category.{v} C]
open finsupp
-- Conceptually, it would be nice to construct this via "transport of enrichment",
-- using the fact that `Module.free R : Type ⥤ Module R` and `Module.forget` are both lax monoidal.
-- This still seems difficult, so we just do it by hand.
instance category_Free : category (Free R C) :=
{ hom := λ (X Y : C), (X ⟶ Y) →₀ R,
id := λ (X : C), finsupp.single (𝟙 X) 1,
comp := λ (X Y Z : C) f g, f.sum (λ f' s, g.sum (λ g' t, finsupp.single (f' ≫ g') (s * t))),
assoc' := λ W X Y Z f g h,
begin
dsimp,
-- This imitates the proof of associativity for `monoid_algebra`.
simp only [sum_sum_index, sum_single_index,
single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff,
add_mul, mul_add, category.assoc, mul_assoc, zero_mul, mul_zero, sum_zero, sum_add],
end }.
namespace Free
section
local attribute [reducible] category_theory.category_Free
instance : preadditive (Free R C) :=
{ hom_group := λ X Y, finsupp.add_comm_group,
add_comp' := λ X Y Z f f' g, begin
dsimp,
rw [finsupp.sum_add_index];
{ simp [add_mul], }
end,
comp_add' := λ X Y Z f g g', begin
dsimp,
rw ← finsupp.sum_add,
congr, ext r h,
rw [finsupp.sum_add_index];
{ simp [mul_add], },
end, }
instance : linear R (Free R C) :=
{ hom_module := λ X Y, finsupp.module (X ⟶ Y) R,
smul_comp' := λ X Y Z r f g, begin
dsimp,
rw [finsupp.sum_smul_index];
simp [finsupp.smul_sum, mul_assoc],
end,
comp_smul' := λ X Y Z f r g, begin
dsimp,
simp_rw [finsupp.smul_sum],
congr, ext h s,
rw [finsupp.sum_smul_index];
simp [finsupp.smul_sum, mul_left_comm],
end, }
lemma single_comp_single {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (r s : R) :
(single f r ≫ single g s : (Free.of R X) ⟶ (Free.of R Z)) = single (f ≫ g) (r * s) :=
by { dsimp, simp, }
end
local attribute [simp] single_comp_single
/--
A category embeds into its `R`-linear completion.
-/
@[simps]
def embedding : C ⥤ Free R C :=
{ obj := λ X, X,
map := λ X Y f, finsupp.single f 1,
map_id' := λ X, rfl,
map_comp' := λ X Y Z f g, by simp, }
variables (R) {C} {D : Type u} [category.{v} D] [preadditive D] [linear R D]
open preadditive linear
/--
A functor to an `R`-linear category lifts to a functor from its `R`-linear completion.
-/
@[simps]
def lift (F : C ⥤ D) : Free R C ⥤ D :=
{ obj := λ X, F.obj X,
map := λ X Y f, f.sum (λ f' r, r • (F.map f')),
map_id' := by { dsimp [category_theory.category_Free], simp },
map_comp' := λ X Y Z f g, begin
apply finsupp.induction_linear f,
{ simp, },
{ intros f₁ f₂ w₁ w₂,
rw add_comp,
rw [finsupp.sum_add_index, finsupp.sum_add_index],
{ simp [w₁, w₂, add_comp], },
{ simp, },
{ intros, simp only [add_smul], },
{ simp, },
{ intros, simp only [add_smul], }, },
{ intros f' r,
apply finsupp.induction_linear g,
{ simp, },
{ intros f₁ f₂ w₁ w₂,
rw comp_add,
rw [finsupp.sum_add_index, finsupp.sum_add_index],
{ simp [w₁, w₂, add_comp], },
{ simp, },
{ intros, simp only [add_smul], },
{ simp, },
{ intros, simp only [add_smul], }, },
{ intros g' s,
erw single_comp_single,
simp [mul_comm r s, mul_smul], } }
end, }
@[simp]
lemma lift_map_single (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (r : R) :
(lift R F).map (single f r) = r • F.map f :=
by simp
instance lift_additive (F : C ⥤ D) : (lift R F).additive :=
{ map_add' := λ X Y f g, begin
dsimp,
rw finsupp.sum_add_index; simp [add_smul]
end, }
instance lift_linear (F : C ⥤ D) : (lift R F).linear R :=
{ map_smul' := λ X Y f r, begin
dsimp,
rw finsupp.sum_smul_index;
simp [finsupp.smul_sum, mul_smul],
end, }
/--
The embedding into the `R`-linear completion, followed by the lift,
is isomorphic to the original functor.
-/
def embedding_lift_iso (F : C ⥤ D) : embedding R C ⋙ lift R F ≅ F :=
nat_iso.of_components
(λ X, iso.refl _)
(by tidy)
/--
Two `R`-linear functors out of the `R`-linear completion are isomorphic iff their
compositions with the embedding functor are isomorphic.
-/
@[ext]
def ext {F G : Free R C ⥤ D} [F.additive] [F.linear R] [G.additive] [G.linear R]
(α : embedding R C ⋙ F ≅ embedding R C ⋙ G) : F ≅ G :=
nat_iso.of_components
(λ X, α.app X)
begin
intros X Y f,
apply finsupp.induction_linear f,
{ simp, },
{ intros f₁ f₂ w₁ w₂,
simp only [F.map_add, G.map_add, add_comp, comp_add, w₁, w₂], },
{ intros f' r,
rw [iso.app_hom, iso.app_hom, ←smul_single_one, F.map_smul, G.map_smul, smul_comp, comp_smul],
change r • (embedding R C ⋙ F).map f' ≫ _ = r • _ ≫ (embedding R C ⋙ G).map f',
rw α.hom.naturality f',
apply_instance, -- Why are these not picked up automatically when we rewrite?
apply_instance, }
end
/--
`Free.lift` is unique amongst `R`-linear functors `Free R C ⥤ D`
which compose with `embedding ℤ C` to give the original functor.
-/
def lift_unique (F : C ⥤ D) (L : Free R C ⥤ D) [L.additive] [L.linear R]
(α : embedding R C ⋙ L ≅ F) :
L ≅ lift R F :=
ext R (α.trans (embedding_lift_iso R F).symm)
end Free
end category_theory
|
16c162bbddf6b48a0cd3b7f59aa7932c1a684cf6
|
b2fe74b11b57d362c13326bc5651244f111fa6f4
|
/src/analysis/special_functions/trigonometric.lean
|
39ce5ef44b0967d03ee3d949a5235dc8c7cacdfb
|
[
"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
| 102,956
|
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_log
import data.set.intervals.infinite
import algebra.quadratic_discriminant
import ring_theory.polynomial.chebyshev.defs
/-!
# Trigonometric functions
## Main definitions
This file contains the following definitions:
* π, arcsin, arccos, arctan
* argument of a complex number
* logarithm on complex numbers
## Main statements
Many basic inequalities on trigonometric functions are established.
The continuity and differentiability of the usual trigonometric functions are proved, and their
derivatives are computed.
* `polynomial.chebyshev₁_complex_cos`: the `n`-th Chebyshev polynomial evaluates on `complex.cos θ`
to the value `n * complex.cos θ`.
## Tags
log, sin, cos, tan, arcsin, arccos, arctan, angle, argument
-/
noncomputable theory
open_locale classical topological_space
open set filter
namespace complex
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
lemma has_deriv_at_sin (x : ℂ) : has_deriv_at sin (cos x) x :=
begin
simp only [cos, div_eq_mul_inv],
convert ((((has_deriv_at_id x).neg.mul_const I).cexp.sub
((has_deriv_at_id x).mul_const I).cexp).mul_const I).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
end
lemma times_cont_diff_sin {n} : times_cont_diff ℂ n sin :=
(((times_cont_diff_neg.mul times_cont_diff_const).cexp.sub
(times_cont_diff_id.mul times_cont_diff_const).cexp).mul times_cont_diff_const).div_const
lemma differentiable_sin : differentiable ℂ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on
lemma measurable_sin : measurable sin := continuous_sin.measurable
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
lemma has_deriv_at_cos (x : ℂ) : has_deriv_at cos (-sin x) x :=
begin
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul],
convert (((has_deriv_at_id x).mul_const I).cexp.add
((has_deriv_at_id x).neg.mul_const I).cexp).mul_const (2:ℂ)⁻¹,
simp only [function.comp, id],
ring
end
lemma times_cont_diff_cos {n} : times_cont_diff ℂ n cos :=
((times_cont_diff_id.mul times_cont_diff_const).cexp.add
(times_cont_diff_neg.mul times_cont_diff_const).cexp).div_const
lemma differentiable_cos : differentiable ℂ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
lemma deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) :=
funext $ λ x, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative
`cosh x`. -/
lemma has_deriv_at_sinh (x : ℂ) : has_deriv_at sinh (cosh x) x :=
begin
simp only [cosh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).sub (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]
end
lemma times_cont_diff_sinh {n} : times_cont_diff ℂ n sinh :=
(times_cont_diff_exp.sub times_cont_diff_neg.cexp).div_const
lemma differentiable_sinh : differentiable ℂ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/
lemma has_deriv_at_cosh (x : ℂ) : has_deriv_at cosh (sinh x) x :=
begin
simp only [sinh, div_eq_mul_inv],
convert ((has_deriv_at_exp x).add (has_deriv_at_id x).neg.cexp).mul_const (2:ℂ)⁻¹,
rw [id, mul_neg_one, sub_eq_add_neg]
end
lemma times_cont_diff_cosh {n} : times_cont_diff ℂ n cosh :=
(times_cont_diff_exp.add times_cont_diff_neg.cexp).div_const
lemma differentiable_cosh : differentiable ℂ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cos x :=
differentiable_cos x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
end complex
section
/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : ℂ → ℂ` -/
variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
/-! #### `complex.cos` -/
lemma measurable.ccos {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.cos (f x)) :=
complex.measurable_cos.comp hf
lemma has_deriv_at.ccos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') x :=
(complex.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.ccos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) * f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccos (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cos (f x)) s x = - complex.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccos.deriv_within hxs
@[simp] lemma deriv_ccos (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cos (f x)) x = - complex.sin (f x) * (deriv f x) :=
hc.has_deriv_at.ccos.deriv
/-! #### `complex.sin` -/
lemma measurable.csin {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.sin (f x)) :=
complex.measurable_sin.comp hf
lemma has_deriv_at.csin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') x :=
(complex.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.csin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) * f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csin (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sin (f x)) s x = complex.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csin.deriv_within hxs
@[simp] lemma deriv_csin (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sin (f x)) x = complex.cos (f x) * (deriv f x) :=
hc.has_deriv_at.csin.deriv
/-! #### `complex.cosh` -/
lemma measurable.ccosh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.cosh (f x)) :=
complex.measurable_cosh.comp hf
lemma has_deriv_at.ccosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') x :=
(complex.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.ccosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) * f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_ccosh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.cosh (f x)) s x = complex.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.ccosh.deriv_within hxs
@[simp] lemma deriv_ccosh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.cosh (f x)) x = complex.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.ccosh.deriv
/-! #### `complex.sinh` -/
lemma measurable.csinh {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.sinh (f x)) :=
complex.measurable_sinh.comp hf
lemma has_deriv_at.csinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') x :=
(complex.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.csinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) * f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_csinh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.sinh (f x)) s x = complex.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.csinh.deriv_within hxs
@[simp] lemma deriv_csinh (hc : differentiable_at ℂ f x) :
deriv (λx, complex.sinh (f x)) x = complex.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.csinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : E → ℂ` -/
variables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ}
{x : E} {s : set E}
/-! #### `complex.cos` -/
lemma has_fderiv_at.ccos (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.cos (f x)) (- complex.sin (f x) • f') s x :=
(complex.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccos (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cos (f x)) s x :=
hf.has_fderiv_within_at.ccos.differentiable_within_at
@[simp] lemma differentiable_at.ccos (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cos (f x)) x :=
hc.has_fderiv_at.ccos.differentiable_at
lemma differentiable_on.ccos (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cos (f x)) s :=
λx h, (hc x h).ccos
@[simp] lemma differentiable.ccos (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cos (f x)) :=
λx, (hc x).ccos
lemma fderiv_within_ccos (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.cos (f x)) s x = - complex.sin (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.ccos.fderiv_within hxs
@[simp] lemma fderiv_ccos (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.cos (f x)) x = - complex.sin (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.ccos.fderiv
lemma times_cont_diff.ccos {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.cos (f x)) :=
complex.times_cont_diff_cos.comp h
lemma times_cont_diff_at.ccos {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.cos (f x)) x :=
complex.times_cont_diff_cos.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.ccos {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.cos (f x)) s :=
complex.times_cont_diff_cos.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.ccos {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.cos (f x)) s x :=
complex.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.sin` -/
lemma has_fderiv_at.csin (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.sin (f x)) (complex.cos (f x) • f') s x :=
(complex.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csin (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sin (f x)) s x :=
hf.has_fderiv_within_at.csin.differentiable_within_at
@[simp] lemma differentiable_at.csin (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sin (f x)) x :=
hc.has_fderiv_at.csin.differentiable_at
lemma differentiable_on.csin (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sin (f x)) s :=
λx h, (hc x h).csin
@[simp] lemma differentiable.csin (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sin (f x)) :=
λx, (hc x).csin
lemma fderiv_within_csin (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.sin (f x)) s x = complex.cos (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.csin.fderiv_within hxs
@[simp] lemma fderiv_csin (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.sin (f x)) x = complex.cos (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.csin.fderiv
lemma times_cont_diff.csin {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.sin (f x)) :=
complex.times_cont_diff_sin.comp h
lemma times_cont_diff_at.csin {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.sin (f x)) x :=
complex.times_cont_diff_sin.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.csin {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.sin (f x)) s :=
complex.times_cont_diff_sin.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.csin {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.sin (f x)) s x :=
complex.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.cosh` -/
lemma has_fderiv_at.ccosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.ccosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.cosh (f x)) (complex.sinh (f x) • f') s x :=
(complex.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.ccosh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.cosh (f x)) s x :=
hf.has_fderiv_within_at.ccosh.differentiable_within_at
@[simp] lemma differentiable_at.ccosh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.cosh (f x)) x :=
hc.has_fderiv_at.ccosh.differentiable_at
lemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.cosh (f x)) s :=
λx h, (hc x h).ccosh
@[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.cosh (f x)) :=
λx, (hc x).ccosh
lemma fderiv_within_ccosh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.cosh (f x)) s x = complex.sinh (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.ccosh.fderiv_within hxs
@[simp] lemma fderiv_ccosh (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.cosh (f x)) x = complex.sinh (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.ccosh.fderiv
lemma times_cont_diff.ccosh {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.cosh (f x)) :=
complex.times_cont_diff_cosh.comp h
lemma times_cont_diff_at.ccosh {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.cosh (f x)) x :=
complex.times_cont_diff_cosh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.ccosh {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.cosh (f x)) s :=
complex.times_cont_diff_cosh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.ccosh {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.cosh (f x)) s x :=
complex.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `complex.sinh` -/
lemma has_fderiv_at.csinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.csinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.sinh (f x)) (complex.cosh (f x) • f') s x :=
(complex.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.csinh (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.sinh (f x)) s x :=
hf.has_fderiv_within_at.csinh.differentiable_within_at
@[simp] lemma differentiable_at.csinh (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.sinh (f x)) x :=
hc.has_fderiv_at.csinh.differentiable_at
lemma differentiable_on.csinh (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.sinh (f x)) s :=
λx h, (hc x h).csinh
@[simp] lemma differentiable.csinh (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.sinh (f x)) :=
λx, (hc x).csinh
lemma fderiv_within_csinh (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
fderiv_within ℂ (λx, complex.sinh (f x)) s x = complex.cosh (f x) • (fderiv_within ℂ f s x) :=
hf.has_fderiv_within_at.csinh.fderiv_within hxs
@[simp] lemma fderiv_csinh (hc : differentiable_at ℂ f x) :
fderiv ℂ (λx, complex.sinh (f x)) x = complex.cosh (f x) • (fderiv ℂ f x) :=
hc.has_fderiv_at.csinh.fderiv
lemma times_cont_diff.csinh {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.sinh (f x)) :=
complex.times_cont_diff_sinh.comp h
lemma times_cont_diff_at.csinh {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.sinh (f x)) x :=
complex.times_cont_diff_sinh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.csinh {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.sinh (f x)) s :=
complex.times_cont_diff_sinh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.csinh {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.sinh (f x)) s x :=
complex.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
end
namespace real
variables {x y z : ℝ}
lemma has_deriv_at_sin (x : ℝ) : has_deriv_at sin (cos x) x :=
(complex.has_deriv_at_sin x).real_of_complex
lemma times_cont_diff_sin {n} : times_cont_diff ℝ n sin :=
complex.times_cont_diff_sin.real_of_complex
lemma differentiable_sin : differentiable ℝ sin :=
λx, (has_deriv_at_sin x).differentiable_at
lemma differentiable_at_sin : differentiable_at ℝ sin x :=
differentiable_sin x
@[simp] lemma deriv_sin : deriv sin = cos :=
funext $ λ x, (has_deriv_at_sin x).deriv
lemma continuous_sin : continuous sin :=
differentiable_sin.continuous
lemma measurable_sin : measurable sin := continuous_sin.measurable
lemma has_deriv_at_cos (x : ℝ) : has_deriv_at cos (-sin x) x :=
(complex.has_deriv_at_cos x).real_of_complex
lemma times_cont_diff_cos {n} : times_cont_diff ℝ n cos :=
complex.times_cont_diff_cos.real_of_complex
lemma differentiable_cos : differentiable ℝ cos :=
λx, (has_deriv_at_cos x).differentiable_at
lemma differentiable_at_cos : differentiable_at ℝ cos x :=
differentiable_cos x
lemma deriv_cos : deriv cos x = - sin x :=
(has_deriv_at_cos x).deriv
@[simp] lemma deriv_cos' : deriv cos = (λ x, - sin x) :=
funext $ λ _, deriv_cos
lemma continuous_cos : continuous cos :=
differentiable_cos.continuous
lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on
lemma measurable_cos : measurable cos := continuous_cos.measurable
lemma has_deriv_at_sinh (x : ℝ) : has_deriv_at sinh (cosh x) x :=
(complex.has_deriv_at_sinh x).real_of_complex
lemma times_cont_diff_sinh {n} : times_cont_diff ℝ n sinh :=
complex.times_cont_diff_sinh.real_of_complex
lemma differentiable_sinh : differentiable ℝ sinh :=
λx, (has_deriv_at_sinh x).differentiable_at
lemma differentiable_at_sinh : differentiable_at ℝ sinh x :=
differentiable_sinh x
@[simp] lemma deriv_sinh : deriv sinh = cosh :=
funext $ λ x, (has_deriv_at_sinh x).deriv
lemma continuous_sinh : continuous sinh :=
differentiable_sinh.continuous
lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
lemma has_deriv_at_cosh (x : ℝ) : has_deriv_at cosh (sinh x) x :=
(complex.has_deriv_at_cosh x).real_of_complex
lemma times_cont_diff_cosh {n} : times_cont_diff ℝ n cosh :=
complex.times_cont_diff_cosh.real_of_complex
lemma differentiable_cosh : differentiable ℝ cosh :=
λx, (has_deriv_at_cosh x).differentiable_at
lemma differentiable_at_cosh : differentiable_at ℝ cosh x :=
differentiable_cosh x
@[simp] lemma deriv_cosh : deriv cosh = sinh :=
funext $ λ x, (has_deriv_at_cosh x).deriv
lemma continuous_cosh : continuous cosh :=
differentiable_cosh.continuous
lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
/-- `sinh` is strictly monotone. -/
lemma sinh_strict_mono : strict_mono sinh :=
strict_mono_of_deriv_pos differentiable_sinh (by { rw [real.deriv_sinh], exact cosh_pos })
end real
section
/-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : ℝ → ℝ` -/
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
/-! #### `real.cos` -/
lemma measurable.cos {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.cos (f x)) :=
real.measurable_cos.comp hf
lemma has_deriv_at.cos (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cos (f x)) (- real.sin (f x) * f') x :=
(real.has_deriv_at_cos (f x)).comp x hf
lemma has_deriv_within_at.cos (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cos (f x)) (- real.sin (f x) * f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cos (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cos (f x)) s x = - real.sin (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cos.deriv_within hxs
@[simp] lemma deriv_cos (hc : differentiable_at ℝ f x) :
deriv (λx, real.cos (f x)) x = - real.sin (f x) * (deriv f x) :=
hc.has_deriv_at.cos.deriv
/-! #### `real.sin` -/
lemma measurable.sin {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.sin (f x)) :=
real.measurable_sin.comp hf
lemma has_deriv_at.sin (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sin (f x)) (real.cos (f x) * f') x :=
(real.has_deriv_at_sin (f x)).comp x hf
lemma has_deriv_within_at.sin (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sin (f x)) (real.cos (f x) * f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sin (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sin (f x)) s x = real.cos (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sin.deriv_within hxs
@[simp] lemma deriv_sin (hc : differentiable_at ℝ f x) :
deriv (λx, real.sin (f x)) x = real.cos (f x) * (deriv f x) :=
hc.has_deriv_at.sin.deriv
/-! #### `real.cosh` -/
lemma measurable.cosh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.cosh (f x)) :=
real.measurable_cosh.comp hf
lemma has_deriv_at.cosh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') x :=
(real.has_deriv_at_cosh (f x)).comp x hf
lemma has_deriv_within_at.cosh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) * f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cosh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.cosh (f x)) s x = real.sinh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cosh.deriv_within hxs
@[simp] lemma deriv_cosh (hc : differentiable_at ℝ f x) :
deriv (λx, real.cosh (f x)) x = real.sinh (f x) * (deriv f x) :=
hc.has_deriv_at.cosh.deriv
/-! #### `real.sinh` -/
lemma measurable.sinh {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.sinh (f x)) :=
real.measurable_sinh.comp hf
lemma has_deriv_at.sinh (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') x :=
(real.has_deriv_at_sinh (f x)).comp x hf
lemma has_deriv_within_at.sinh (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) * f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_sinh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.sinh (f x)) s x = real.cosh (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.sinh.deriv_within hxs
@[simp] lemma deriv_sinh (hc : differentiable_at ℝ f x) :
deriv (λx, real.sinh (f x)) x = real.cosh (f x) * (deriv f x) :=
hc.has_deriv_at.sinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : E → ℝ` -/
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ}
{x : E} {s : set E}
/-! #### `real.cos` -/
lemma has_fderiv_at.cos (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.cos (f x)) (- real.sin (f x) • f') x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cos (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.cos (f x)) (- real.sin (f x) • f') s x :=
(real.has_deriv_at_cos (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cos (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cos (f x)) s x :=
hf.has_fderiv_within_at.cos.differentiable_within_at
@[simp] lemma differentiable_at.cos (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cos (f x)) x :=
hc.has_fderiv_at.cos.differentiable_at
lemma differentiable_on.cos (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cos (f x)) s :=
λx h, (hc x h).cos
@[simp] lemma differentiable.cos (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cos (f x)) :=
λx, (hc x).cos
lemma fderiv_within_cos (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.cos (f x)) s x = - real.sin (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.cos.fderiv_within hxs
@[simp] lemma fderiv_cos (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.cos (f x)) x = - real.sin (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.cos.fderiv
lemma times_cont_diff.cos {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.cos (f x)) :=
real.times_cont_diff_cos.comp h
lemma times_cont_diff_at.cos {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.cos (f x)) x :=
real.times_cont_diff_cos.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.cos {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.cos (f x)) s :=
real.times_cont_diff_cos.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.cos {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.cos (f x)) s x :=
real.times_cont_diff_cos.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.sin` -/
lemma has_fderiv_at.sin (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.sin (f x)) (real.cos (f x) • f') x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sin (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.sin (f x)) (real.cos (f x) • f') s x :=
(real.has_deriv_at_sin (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sin (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sin (f x)) s x :=
hf.has_fderiv_within_at.sin.differentiable_within_at
@[simp] lemma differentiable_at.sin (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sin (f x)) x :=
hc.has_fderiv_at.sin.differentiable_at
lemma differentiable_on.sin (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sin (f x)) s :=
λx h, (hc x h).sin
@[simp] lemma differentiable.sin (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sin (f x)) :=
λx, (hc x).sin
lemma fderiv_within_sin (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.sin (f x)) s x = real.cos (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.sin.fderiv_within hxs
@[simp] lemma fderiv_sin (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.sin (f x)) x = real.cos (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.sin.fderiv
lemma times_cont_diff.sin {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.sin (f x)) :=
real.times_cont_diff_sin.comp h
lemma times_cont_diff_at.sin {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.sin (f x)) x :=
real.times_cont_diff_sin.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.sin {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.sin (f x)) s :=
real.times_cont_diff_sin.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.sin {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.sin (f x)) s x :=
real.times_cont_diff_sin.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.cosh` -/
lemma has_fderiv_at.cosh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cosh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.cosh (f x)) (real.sinh (f x) • f') s x :=
(real.has_deriv_at_cosh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.cosh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.cosh (f x)) s x :=
hf.has_fderiv_within_at.cosh.differentiable_within_at
@[simp] lemma differentiable_at.cosh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.cosh (f x)) x :=
hc.has_fderiv_at.cosh.differentiable_at
lemma differentiable_on.cosh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.cosh (f x)) s :=
λx h, (hc x h).cosh
@[simp] lemma differentiable.cosh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.cosh (f x)) :=
λx, (hc x).cosh
lemma fderiv_within_cosh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.cosh (f x)) s x = real.sinh (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.cosh.fderiv_within hxs
@[simp] lemma fderiv_cosh (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.cosh (f x)) x = real.sinh (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.cosh.fderiv
lemma times_cont_diff.cosh {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.cosh (f x)) :=
real.times_cont_diff_cosh.comp h
lemma times_cont_diff_at.cosh {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.cosh (f x)) x :=
real.times_cont_diff_cosh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.cosh {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.cosh (f x)) s :=
real.times_cont_diff_cosh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.cosh {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.cosh (f x)) s x :=
real.times_cont_diff_cosh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
/-! #### `real.sinh` -/
lemma has_fderiv_at.sinh (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_at x hf
lemma has_fderiv_within_at.sinh (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.sinh (f x)) (real.cosh (f x) • f') s x :=
(real.has_deriv_at_sinh (f x)).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sinh (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.sinh (f x)) s x :=
hf.has_fderiv_within_at.sinh.differentiable_within_at
@[simp] lemma differentiable_at.sinh (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.sinh (f x)) x :=
hc.has_fderiv_at.sinh.differentiable_at
lemma differentiable_on.sinh (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.sinh (f x)) s :=
λx h, (hc x h).sinh
@[simp] lemma differentiable.sinh (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.sinh (f x)) :=
λx, (hc x).sinh
lemma fderiv_within_sinh (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.sinh (f x)) s x = real.cosh (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.sinh.fderiv_within hxs
@[simp] lemma fderiv_sinh (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.sinh (f x)) x = real.cosh (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.sinh.fderiv
lemma times_cont_diff.sinh {n} (h : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.sinh (f x)) :=
real.times_cont_diff_sinh.comp h
lemma times_cont_diff_at.sinh {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.sinh (f x)) x :=
real.times_cont_diff_sinh.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.sinh {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.sinh (f x)) s :=
real.times_cont_diff_sinh.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.sinh {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.sinh (f x)) s x :=
real.times_cont_diff_sinh.times_cont_diff_at.comp_times_cont_diff_within_at x hf
end
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`. -/
noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [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 [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 [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 : pi ≠ 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]
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left pi (@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 pi (@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_add_pi (x : ℝ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
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_pos 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 [pow_two, 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_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_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
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 (sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃, ne_of_lt (sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos))
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
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,
pow_two, pow_two, ← 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, by omega,
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_mono_decr_on_cos : strict_mono_decr_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_mono_decr_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_incr_on_sin : strict_mono_incr_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_incr_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_incr_on_sin.inj_on
lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_mono_decr_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) }
lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x :=
begin
cases le_or_gt x 1 with h' h',
{ have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.2, rw [sub_le_iff_le_add', hx] at this,
apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),
apply sub_lt_sub_left, rw [sub_pos, div_eq_mul_inv (x ^ 3)], apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h },
exact lt_of_le_of_lt (sin_le_one x) h'
end
/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.
note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/
lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x :=
begin
have hx : abs x = x := abs_of_nonneg (le_of_lt h),
have : abs x ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.1, rw [le_sub_iff_add_le, hx] at this,
refine lt_of_lt_of_le _ this,
rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,
apply add_lt_of_lt_sub_left,
rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12⁻¹,
by simp [div_eq_mul_inv, ← mul_sub]; norm_num),
apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h
end
section cos_div_pow_two
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 _ (le_of_eq $ sqrt_sqr $ le_of_lt zero_lt_two),
rw [sqrt_two_add_series, sqrt_lt, ← 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 (pi / 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_sqr_eq, mul_pow, cos_square, ←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, pow_two, 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) _ 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_square_pi_over_two_pow (n : ℕ) :
sin (pi / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_square, cos_pi_over_two_pow]
lemma sin_square_pi_over_two_pow_succ (n : ℕ) :
sin (pi / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_square_pi_over_two_pow, sqrt_two_add_series, div_pow, sqr_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 (pi / 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_sqr_eq, mul_pow, sin_square_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 (pi / 4) = sqrt 2 / 2 :=
by { transitivity cos (pi / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma sin_pi_div_four : sin (pi / 4) = sqrt 2 / 2 :=
by { transitivity sin (pi / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma cos_pi_div_eight : cos (pi / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (pi / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma sin_pi_div_eight : sin (pi / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (pi / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma cos_pi_div_sixteen : cos (pi / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (pi / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma sin_pi_div_sixteen : sin (pi / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (pi / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma cos_pi_div_thirty_two : cos (pi / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (pi / 2 ^ 5), congr, norm_num, simp }
@[simp] lemma sin_pi_div_thirty_two : sin (pi / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (pi / 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 square_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 :=
begin
have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,
{ convert cos_square (π / 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_sqr_eq,
{ have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr square_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 square_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 :=
begin
rw [← cos_pi_div_two_sub, ← square_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_pow_two
/-- The type of angles -/
def angle : Type :=
quotient_add_group.quotient (add_subgroup.gmultiples (2 * π))
namespace angle
instance angle.add_comm_group : add_comm_group angle :=
quotient_add_group.add_comm_group _
instance : inhabited angle := ⟨0⟩
instance angle.has_coe : has_coe ℝ angle :=
⟨quotient.mk'⟩
@[simp] lemma coe_zero : ↑(0 : ℝ) = (0 : angle) := rfl
@[simp] lemma coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : angle) := rfl
@[simp] lemma coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : angle) := rfl
@[simp] lemma coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : angle) :=
by rw [sub_eq_add_neg, sub_eq_add_neg, coe_add, coe_neg]
@[simp, norm_cast] lemma coe_nat_mul_eq_nsmul (x : ℝ) (n : ℕ) :
↑((n : ℝ) * x) = n •ℕ (↑x : angle) :=
by simpa using add_monoid_hom.map_nsmul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp, norm_cast] lemma coe_int_mul_eq_gsmul (x : ℝ) (n : ℤ) :
↑((n : ℝ) * x : ℝ) = n •ℤ (↑x : angle) :=
by simpa using add_monoid_hom.map_gsmul ⟨coe, coe_zero, coe_add⟩ _ _
@[simp] lemma coe_two_pi : ↑(2 * π : ℝ) = (0 : angle) :=
quotient.sound' ⟨-1, show (-1 : ℤ) •ℤ (2 * π) = _, by rw [neg_one_gsmul, add_zero]⟩
lemma angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k :=
by simp only [quotient_add_group.eq, add_subgroup.gmultiples_eq_closure,
add_subgroup.mem_closure_singleton, gsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : angle) = ψ ∨ (θ : angle) = -ψ :=
begin
split,
{ intro Hcos,
rw [←sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false_intro two_ne_zero,
false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos,
rcases Hcos with ⟨n, hn⟩ | ⟨n, hn⟩,
{ right,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), ← sub_eq_iff_eq_add] at hn,
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero] },
{ left,
rw [eq_div_iff_mul_eq (@two_ne_zero ℝ _ _), eq_sub_iff_add_eq] at hn,
rw [← hn, coe_add, mul_assoc,
coe_int_mul_eq_gsmul, mul_comm, coe_two_pi, gsmul_zero, zero_add] },
apply_instance, },
{ rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero_iff_eq, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _),
mul_comm π _, sin_int_mul_pi, mul_zero],
rw [←sub_eq_zero_iff_eq, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left _ (@two_ne_zero ℝ _ _), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] }
end
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : angle) = ψ ∨ (θ : angle) + ψ = π :=
begin
split,
{ intro Hsin, rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin,
cases cos_eq_iff_eq_or_eq_neg.mp Hsin with h h,
{ left, rw [coe_sub, coe_sub] at h, exact sub_right_inj.1 h },
right, rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub,
sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h,
exact h.symm },
{ rw [angle_eq_iff_two_pi_dvd_sub, ←eq_sub_iff_add_eq, ←coe_sub, angle_eq_iff_two_pi_dvd_sub],
rintro (⟨k, H⟩ | ⟨k, H⟩),
rw [← sub_eq_zero_iff_eq, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left _ (@two_ne_zero ℝ _ _),
mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul],
have H' : θ + ψ = (2 * k) * π + π := by rwa [←sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add,
mul_assoc, mul_comm π _, ←mul_assoc] at H,
rw [← sub_eq_zero_iff_eq, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left _ (@two_ne_zero ℝ _ _),
cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] }
end
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : angle) = ψ :=
begin
cases cos_eq_iff_eq_or_eq_neg.mp Hcos with hc hc, { exact hc },
cases sin_eq_iff_eq_or_add_eq_pi.mp Hsin with hs hs, { exact hs },
rw [eq_neg_iff_add_eq_zero, hs] at hc,
cases quotient.exact' hc with n hn, change n •ℤ _ = _ at hn,
rw [← neg_one_mul, add_zero, ← sub_eq_zero_iff_eq, gsmul_eq_mul, ← mul_assoc, ← sub_mul,
mul_eq_zero, eq_false_intro (ne_of_gt pi_pos), or_false, sub_neg_eq_add,
← int.cast_zero, ← int.cast_one, ← int.cast_bit0, ← int.cast_mul, ← int.cast_add, int.cast_inj] at hn,
have : (n * 2 + 1) % (2:ℤ) = 0 % (2:ℤ) := congr_arg (%(2:ℤ)) hn,
rw [add_comm, int.add_mul_mod_self] at this,
exact absurd this one_ne_zero
end
end angle
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x` and `arcsin x ≤ π / 2`.
If the argument is not between `-1` and `1` it defaults to `0` -/
noncomputable def arcsin (x : ℝ) : ℝ :=
if hx : -1 ≤ x ∧ x ≤ 1 then classical.some (surj_on_sin hx) else 0
lemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 :=
if hx : -1 ≤ x ∧ x ≤ 1
then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (surj_on_sin hx)).1.2
else by rw [arcsin, dif_neg hx]; exact le_of_lt pi_div_two_pos
lemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x :=
if hx : -1 ≤ x ∧ x ≤ 1
then by rw [arcsin, dif_pos hx]; exact (classical.some_spec (surj_on_sin hx)).1.1
else by rw [arcsin, dif_neg hx]; exact neg_nonpos.2 (le_of_lt pi_div_two_pos)
lemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
by rw [arcsin, dif_pos (and.intro hx₁ hx₂)];
exact (classical.some_spec (surj_on_sin ⟨hx₁, hx₂⟩)).2
lemma arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
inj_on_sin ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ ⟨hx₁, hx₂⟩
(by rw sin_arcsin (neg_one_le_sin _) (sin_le_one _))
lemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1)
(hxy : arcsin x = arcsin y) : x = y :=
by rw [← sin_arcsin hx₁ hx₂, ← sin_arcsin hy₁ hy₂, hxy]
@[simp] lemma arcsin_zero : arcsin 0 = 0 :=
inj_on_sin
⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
⟨neg_nonpos.2 (le_of_lt pi_div_two_pos), le_of_lt pi_div_two_pos⟩
(by rw [sin_arcsin, sin_zero]; norm_num)
@[simp] lemma arcsin_one : arcsin 1 = π / 2 :=
inj_on_sin
⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
⟨by linarith [pi_pos], le_refl _⟩
(by rw [sin_arcsin, sin_pi_div_two]; norm_num)
@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=
if h : -1 ≤ x ∧ x ≤ 1 then
have -1 ≤ -x ∧ -x ≤ 1, by rwa [neg_le_neg_iff, neg_le, and.comm],
inj_on_sin
⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.1 (neg_pi_div_two_le_arcsin _)⟩
(by rw [sin_arcsin this.1 this.2, sin_neg, sin_arcsin h.1 h.2])
else
have ¬(-1 ≤ -x ∧ -x ≤ 1) := by rwa [neg_le_neg_iff, neg_le, and.comm],
by rw [arcsin, arcsin, dif_neg h, dif_neg this, neg_zero]
@[simp] lemma arcsin_neg_one : arcsin (-1) = -(π / 2) := by simp
lemma arcsin_nonneg {x : ℝ} (hx : 0 ≤ x) : 0 ≤ arcsin x :=
if hx₁ : x ≤ 1 then
not_lt.1 (λ h, not_lt.2 hx begin
have := sin_lt_sin_of_lt_of_le_pi_div_two
(neg_pi_div_two_le_arcsin _) (le_of_lt pi_div_two_pos) h,
rw [real.sin_arcsin, sin_zero] at this; linarith
end)
else by rw [arcsin, dif_neg]; simp [hx₁]
lemma arcsin_eq_zero_iff {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : arcsin x = 0 ↔ x = 0 :=
⟨λ h, have sin (arcsin x) = 0, by simp [h],
by rwa [sin_arcsin hx₁ hx₂] at this,
λ h, by simp [h]⟩
lemma arcsin_pos {x : ℝ} (hx₁ : 0 < x) (hx₂ : x ≤ 1) : 0 < arcsin x :=
lt_of_le_of_ne (arcsin_nonneg (le_of_lt hx₁))
(ne.symm (mt (arcsin_eq_zero_iff (by linarith) hx₂).1 (ne_of_lt hx₁).symm))
lemma arcsin_nonpos {x : ℝ} (hx : x ≤ 0) : arcsin x ≤ 0 :=
neg_nonneg.1 (arcsin_neg x ▸ arcsin_nonneg (neg_nonneg.2 hx))
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
If the argument is not between `-1` and `1` it defaults to `π / 2` -/
noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
lemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl
lemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=
by simp [sub_eq_add_neg, arccos]
lemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=
by unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
lemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=
by unfold arccos; linarith [arcsin_le_pi_div_two x]
lemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=
by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
lemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=
by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1)
(hxy : arccos x = arccos y) : x = y :=
arcsin_inj hx₁ hx₂ hy₁ hy₂ $ by simp [arccos, *] at *
@[simp] lemma arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp] lemma arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp] lemma arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
lemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=
by rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self]; simp
lemma cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
lemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arcsin x) = sqrt (1 - x ^ 2) :=
have sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x),
begin
rw [← eq_sub_iff_add_eq', ← sqrt_inj (pow_two_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))),
pow_two, sqrt_mul_self (cos_arcsin_nonneg _)] at this,
rw [this, sin_arcsin hx₁ hx₂],
end
lemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arccos x) = sqrt (1 - x ^ 2) :=
by rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin hx₁ hx₂]
lemma abs_div_sqrt_one_add_lt (x : ℝ) : abs (x / sqrt (1 + x ^ 2)) < 1 :=
have h₁ : 0 < 1 + x ^ 2, from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _),
have h₂ : 0 < sqrt (1 + x ^ 2), from sqrt_pos.2 h₁,
by rw [abs_div, div_lt_iff (abs_pos_of_pos h₂), one_mul,
mul_self_lt_mul_self_iff (abs_nonneg x) (abs_nonneg _),
← abs_mul, ← abs_mul, mul_self_sqrt (add_nonneg zero_le_one (pow_two_nonneg _)),
abs_of_nonneg (mul_self_nonneg x), abs_of_nonneg (le_of_lt h₁), pow_two, add_comm];
exact lt_add_one _
lemma div_sqrt_one_add_lt_one (x : ℝ) : x / sqrt (1 + x ^ 2) < 1 :=
(abs_lt.1 (abs_div_sqrt_one_add_lt _)).2
lemma neg_one_lt_div_sqrt_one_add (x : ℝ) : -1 < x / sqrt (1 + x ^ 2) :=
(abs_lt.1 (abs_div_sqrt_one_add_lt _)).1
@[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
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 [pi_pos]))
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 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 :=
match lt_trichotomy x y with
| or.inl h := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hx₁ hy₂ h) (by rw hxy; exact lt_irrefl _)
| or.inr (or.inl h) := h
| or.inr (or.inr h) := absurd (tan_lt_tan_of_lt_of_lt_pi_div_two hy₁ hx₂ h) (by rw hxy; exact lt_irrefl _)
end
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and `arctan x < π / 2` -/
noncomputable def arctan (x : ℝ) : ℝ :=
arcsin (x / sqrt (1 + x ^ 2))
lemma sin_arctan (x : ℝ) : sin (arctan x) = x / sqrt (1 + x ^ 2) :=
sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _))
lemma cos_arctan (x : ℝ) : cos (arctan x) = 1 / sqrt (1 + x ^ 2) :=
have h₁ : (0 : ℝ) < 1 + x ^ 2,
from add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg _),
have h₂ : (x / sqrt (1 + x ^ 2)) ^ 2 < 1,
by rw [pow_two, ← abs_mul_self, _root_.abs_mul];
exact mul_lt_one_of_nonneg_of_lt_one_left (abs_nonneg _)
(abs_div_sqrt_one_add_lt _) (le_of_lt (abs_div_sqrt_one_add_lt _)),
by rw [arctan, cos_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _)) (le_of_lt (div_sqrt_one_add_lt_one _)),
one_div, ← sqrt_inv, sqrt_inj (sub_nonneg.2 (le_of_lt h₂)) (inv_nonneg.2 (le_of_lt h₁)),
div_pow, pow_two (sqrt _), mul_self_sqrt (le_of_lt h₁),
← mul_right_inj' (ne.symm (ne_of_lt h₁)), mul_sub,
mul_div_cancel' _ (ne.symm (ne_of_lt h₁)), mul_inv_cancel (ne.symm (ne_of_lt h₁))];
simp
lemma tan_arctan (x : ℝ) : tan (arctan x) = x :=
by rw [tan_eq_sin_div_cos, sin_arctan, cos_arctan, div_div_div_div_eq, mul_one,
mul_div_assoc,
div_self (mt sqrt_eq_zero'.1 (not_le_of_gt (add_pos_of_pos_of_nonneg zero_lt_one (pow_two_nonneg x)))),
mul_one]
lemma arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
lt_of_le_of_ne (arcsin_le_pi_div_two _)
(λ h, ne_of_lt (div_sqrt_one_add_lt_one x) $
by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _))
(le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, h, sin_pi_div_two])
lemma neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
lt_of_le_of_ne (neg_pi_div_two_le_arcsin _)
(λ h, ne_of_lt (neg_one_lt_div_sqrt_one_add x) $
by rw [← sin_arcsin (le_of_lt (neg_one_lt_div_sqrt_one_add _))
(le_of_lt (div_sqrt_one_add_lt_one _)), ← arctan, ← h, sin_neg, sin_pi_div_two])
lemma arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) :=
⟨neg_pi_div_two_lt_arctan x, arctan_lt_pi_div_two x⟩
lemma tan_surjective : function.surjective tan :=
function.right_inverse.surjective tan_arctan
lemma arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan _)
(arctan_lt_pi_div_two _) hx₁ hx₂ (by rw tan_arctan)
@[simp] lemma arctan_zero : arctan 0 = 0 :=
by simp [arctan]
@[simp] lemma arctan_one : arctan 1 = π / 4 :=
begin
refine tan_inj_of_lt_of_lt_pi_div_two (neg_pi_div_two_lt_arctan 1) (arctan_lt_pi_div_two 1) _ _ _;
linarith [pi_pos, tan_arctan 1, tan_pi_div_four],
end
@[simp] lemma arctan_neg (x : ℝ) : arctan (-x) = - arctan x :=
by simp [arctan, neg_div]
end real
namespace complex
open_locale real
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re
then real.arcsin (x.im / x.abs)
else if 0 ≤ x.im
then real.arcsin ((-x).im / x.abs) + π
else real.arcsin ((-x).im / x.abs) - π
lemma arg_le_pi (x : ℂ) : arg x ≤ π :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact le_trans (real.arcsin_le_pi_div_two _) (le_of_lt (half_lt_self real.pi_pos))
else
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂];
exact le_sub_iff_add_le.1 (by rw sub_self;
exact real.arcsin_nonpos (by rw [neg_im, neg_div, neg_nonpos]; exact div_nonneg hx₂ (abs_nonneg _)))
else by rw [arg, if_neg hx₁, if_neg hx₂];
exact sub_le_iff_le_add.2 (le_trans (real.arcsin_le_pi_div_two _)
(by linarith [real.pi_pos]))
lemma neg_pi_lt_arg (x : ℂ) : -π < arg x :=
if hx₁ : 0 ≤ x.re
then by rw [arg, if_pos hx₁];
exact lt_of_lt_of_le (neg_lt_neg (half_lt_self real.pi_pos)) (real.neg_pi_div_two_le_arcsin _)
else
have hx : x ≠ 0, from λ h, by simpa [h, lt_irrefl] using hx₁,
if hx₂ : 0 ≤ x.im
then by rw [arg, if_neg hx₁, if_pos hx₂];
exact sub_lt_iff_lt_add.1
(lt_of_lt_of_le (by linarith [real.pi_pos]) (real.neg_pi_div_two_le_arcsin _))
else by rw [arg, if_neg hx₁, if_neg hx₂];
exact lt_sub_iff_add_lt.2 (by rw neg_add_self;
exact real.arcsin_pos (by rw [neg_im]; exact div_pos (neg_pos.2 (lt_of_not_ge hx₂))
(abs_pos.2 hx)) (by rw [← abs_neg x]; exact (abs_le.1 (abs_im_div_abs_le_one _)).2))
lemma arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : 0 ≤ x.im) :
arg x = arg (-x) + π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_pos this, if_pos hxi, abs_neg]
lemma arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg {x : ℂ} (hxr : x.re < 0) (hxi : x.im < 0) :
arg x = arg (-x) - π :=
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos],
by rw [arg, arg, if_neg (not_le.2 hxr), if_neg (not_le.2 hxi), if_pos this, abs_neg]
@[simp] lemma arg_zero : arg 0 = 0 :=
by simp [arg, le_refl]
@[simp] lemma arg_one : arg 1 = 0 :=
by simp [arg, zero_le_one]
@[simp] lemma arg_neg_one : arg (-1) = π :=
by simp [arg, le_refl, not_le.2 (@zero_lt_one ℝ _ _)]
@[simp] lemma arg_I : arg I = π / 2 :=
by simp [arg, le_refl]
@[simp] lemma arg_neg_I : arg (-I) = -(π / 2) :=
by simp [arg, le_refl]
lemma sin_arg (x : ℂ) : real.sin (arg x) = x.im / x.abs :=
by unfold arg; split_ifs;
simp [sub_eq_add_neg, arg, real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, real.sin_add, neg_div, real.arcsin_neg,
real.sin_neg]
private lemma cos_arg_of_re_nonneg {x : ℂ} (hx : x ≠ 0) (hxr : 0 ≤ x.re) : real.cos (arg x) = x.re / x.abs :=
have 0 ≤ 1 - (x.im / abs x) ^ 2,
from sub_nonneg.2 $ by rw [pow_two, ← _root_.abs_mul_self, _root_.abs_mul, ← pow_two];
exact pow_le_one _ (_root_.abs_nonneg _) (abs_im_div_abs_le_one _),
by rw [eq_div_iff_mul_eq (mt abs_eq_zero.1 hx), ← real.mul_self_sqrt (abs_nonneg x),
arg, if_pos hxr, real.cos_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1
(abs_le.1 (abs_im_div_abs_le_one x)).2, ← real.sqrt_mul (abs_nonneg _), ← real.sqrt_mul this,
sub_mul, div_pow, ← pow_two, div_mul_cancel _ (pow_ne_zero 2 (mt abs_eq_zero.1 hx)),
one_mul, pow_two, mul_self_abs, norm_sq, pow_two, add_sub_cancel, real.sqrt_mul_self hxr]
lemma cos_arg {x : ℂ} (hx : x ≠ 0) : real.cos (arg x) = x.re / x.abs :=
if hxr : 0 ≤ x.re then cos_arg_of_re_nonneg hx hxr
else
have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
if hxi : 0 ≤ x.im
then have 0 ≤ (-x).re, from le_of_lt $ by simpa [neg_pos] using hxr,
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg (not_le.1 hxr) hxi, real.cos_add_pi,
cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this];
simp [neg_div]
else by rw [arg_eq_arg_neg_sub_pi_of_im_neg_of_re_neg (not_le.1 hxr) (not_le.1 hxi)];
simp [sub_eq_add_neg, real.cos_add, neg_div, cos_arg_of_re_nonneg (neg_ne_zero.2 hx) this]
lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re :=
begin
by_cases h : x = 0,
{ simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },
rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
div_div_div_cancel_right _ (mt abs_eq_zero.1 h)]
end
lemma arg_cos_add_sin_mul_I {x : ℝ} (hx₁ : -π < x) (hx₂ : x ≤ π) :
arg (cos x + sin x * I) = x :=
if hx₃ : -(π / 2) ≤ x ∧ x ≤ π / 2
then
have hx₄ : 0 ≤ (cos x + sin x * I).re,
by simp; exact real.cos_nonneg_of_mem_Icc hx₃,
by rw [arg, if_pos hx₄];
simp [abs_cos_add_sin_mul_I, sin_of_real_re, real.arcsin_sin hx₃.1 hx₃.2]
else if hx₄ : x < -(π / 2)
then
have hx₅ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬ 0 ≤ real.cos x, by simpa,
not_le.2 $ by rw ← real.cos_neg;
apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₆ : ¬0 ≤ (cos ↑x + sin ↑x * I).im :=
suffices real.sin x < 0, by simpa,
by apply real.sin_neg_of_neg_of_neg_pi_lt; linarith,
suffices -π + -real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₅, if_neg hx₆];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.arcsin_neg, ← real.sin_add_pi, real.arcsin_sin]; try {simp [add_left_comm]}; linarith
else
have hx₅ : π / 2 < x, by cases not_and_distrib.1 hx₃; linarith,
have hx₆ : ¬0 ≤ (cos x + sin x * I).re :=
suffices ¬0 ≤ real.cos x, by simpa,
not_le.2 $ by apply real.cos_neg_of_pi_div_two_lt_of_lt; linarith,
have hx₇ : 0 ≤ (cos x + sin x * I).im :=
suffices 0 ≤ real.sin x, by simpa,
by apply real.sin_nonneg_of_nonneg_of_le_pi; linarith,
suffices π - real.arcsin (real.sin x) = x,
by rw [arg, if_neg hx₆, if_pos hx₇];
simpa [sub_eq_add_neg, add_comm, abs_cos_add_sin_mul_I, sin_of_real_re],
by rw [← real.sin_pi_sub, real.arcsin_sin]; simp [sub_eq_add_neg]; linarith
lemma arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (abs y / abs x : ℂ) * x = y :=
have hax : abs x ≠ 0, from (mt abs_eq_zero.1 hx),
have hay : abs y ≠ 0, from (mt abs_eq_zero.1 hy),
⟨λ h,
begin
have hcos := congr_arg real.cos h,
rw [cos_arg hx, cos_arg hy, div_eq_div_iff hax hay] at hcos,
have hsin := congr_arg real.sin h,
rw [sin_arg, sin_arg, div_eq_div_iff hax hay] at hsin,
apply complex.ext,
{ rw [mul_re, ← of_real_div, of_real_re, of_real_im, zero_mul, sub_zero, mul_comm,
← mul_div_assoc, hcos, mul_div_cancel _ hax] },
{ rw [mul_im, ← of_real_div, of_real_re, of_real_im, zero_mul, add_zero,
mul_comm, ← mul_div_assoc, hsin, mul_div_cancel _ hax] }
end,
λ h,
have hre : abs (y / x) * x.re = y.re,
by rw ← of_real_div at h;
simpa [-of_real_div] using congr_arg re h,
have hre' : abs (x / y) * y.re = x.re,
by rw [← hre, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have him : abs (y / x) * x.im = y.im,
by rw ← of_real_div at h;
simpa [-of_real_div] using congr_arg im h,
have him' : abs (x / y) * y.im = x.im,
by rw [← him, abs_div, abs_div, ← mul_assoc, div_mul_div,
mul_comm (abs _), div_self (mul_ne_zero hay hax), one_mul],
have hxya : x.im / abs x = y.im / abs y,
by rw [← him, abs_div, mul_comm, ← mul_div_comm, mul_div_cancel_left _ hay],
have hnxya : (-x).im / abs x = (-y).im / abs y,
by rw [neg_im, neg_im, neg_div, neg_div, hxya],
if hxr : 0 ≤ x.re
then
have hyr : 0 ≤ y.re, from hre ▸ mul_nonneg (abs_nonneg _) hxr,
by simp [arg, *] at *
else
have hyr : ¬ 0 ≤ y.re, from λ hyr, hxr $ hre' ▸ mul_nonneg (abs_nonneg _) hyr,
if hxi : 0 ≤ x.im
then
have hyi : 0 ≤ y.im, from him ▸ mul_nonneg (abs_nonneg _) hxi,
by simp [arg, *] at *
else
have hyi : ¬ 0 ≤ y.im, from λ hyi, hxi $ him' ▸ mul_nonneg (abs_nonneg _) hyi,
by simp [arg, *] at *⟩
lemma arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x :=
if hx : x = 0 then by simp [hx]
else (arg_eq_arg_iff (mul_ne_zero (of_real_ne_zero.2 (ne_of_lt hr).symm) hx) hx).2 $
by rw [abs_mul, abs_of_nonneg (le_of_lt hr), ← mul_assoc,
of_real_mul, mul_comm (r : ℂ), ← div_div_eq_div_mul,
div_mul_cancel _ (of_real_ne_zero.2 (ne_of_lt hr).symm),
div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), one_mul]
lemma ext_abs_arg {x y : ℂ} (h₁ : x.abs = y.abs) (h₂ : x.arg = y.arg) : x = y :=
if hy : y = 0 then by simp * at *
else have hx : x ≠ 0, from λ hx, by simp [*, eq_comm] at *,
by rwa [arg_eq_arg_iff hx hy, h₁, div_self (of_real_ne_zero.2 (mt abs_eq_zero.1 hy)), one_mul] at h₂
lemma arg_of_real_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 :=
by simp [arg, hx]
lemma arg_of_real_of_neg {x : ℝ} (hx : x < 0) : arg x = π :=
by rw [arg_eq_arg_neg_add_pi_of_im_nonneg_of_re_neg, ← of_real_neg, arg_of_real_of_nonneg];
simp [*, le_iff_eq_or_lt, lt_neg]
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`.
`log 0 = 0`-/
noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I
lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log]
lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log]
lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x :=
by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx,
← of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), ← mul_assoc,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]
lemma range_exp : range exp = {x | x ≠ 0} :=
set.ext $ λ x, ⟨by { rintro ⟨x, rfl⟩, exact exp_ne_zero x }, λ hx, ⟨log x, exp_log hx⟩⟩
lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π)
(hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y :=
by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy;
exact complex.ext
(real.exp_injective $
by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy)
(by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _),
arg_cos_add_sin_mul_I hx₁ hx₂, arg_cos_add_sin_mul_I hy₁ hy₂] using congr_arg arg hxy)
lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x :=
exp_inj_of_neg_pi_lt_of_le_pi
(by rw log_im; exact neg_pi_lt_arg _)
(by rw log_im; exact arg_le_pi _)
hx₁ hx₂ (by rw [exp_log (exp_ne_zero _)])
lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x :=
complex.ext
(by rw [log_re, of_real_re, abs_of_nonneg hx])
(by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])
lemma log_of_real_re (x : ℝ) : (log (x : ℂ)).re = real.log x := by simp [log_re]
@[simp] lemma log_zero : log 0 = 0 := by simp [log]
@[simp] lemma log_one : log 1 = 0 := by simp [log]
lemma log_neg_one : log (-1) = π * I := by simp [log]
lemma log_I : log I = π / 2 * I := by simp [log]
lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log]
lemma exists_pow_nat_eq (x : ℂ) {n : ℕ} (hn : 0 < n) : ∃ z, z ^ n = x :=
begin
by_cases hx : x = 0,
{ use 0, simp only [hx, zero_pow_eq_zero, hn] },
{ use exp (log x / n),
rw [← exp_nat_mul, mul_div_cancel', exp_log hx],
exact_mod_cast (nat.pos_iff_ne_zero.mp hn) }
end
lemma exists_eq_mul_self (x : ℂ) : ∃ z, x = z * z :=
begin
obtain ⟨z, rfl⟩ := exists_pow_nat_eq x zero_lt_two,
exact ⟨z, pow_two z⟩
end
lemma two_pi_I_ne_zero : (2 * π * I : ℂ) ≠ 0 :=
by norm_num [real.pi_ne_zero, I_ne_zero]
lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :=
have real.exp (x.re) * real.cos (x.im) = 1 → real.cos x.im ≠ -1,
from λ h₁ h₂, begin
rw [h₂, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at h₁,
have := real.exp_pos x.re,
rw ← h₁ at this,
exact absurd this (by norm_num)
end,
calc exp x = 1 ↔ (exp x).re = 1 ∧ (exp x).im = 0 : by simp [complex.ext_iff]
... ↔ real.cos x.im = 1 ∧ real.sin x.im = 0 ∧ x.re = 0 :
begin
rw exp_eq_exp_re_mul_sin_add_cos,
simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re,
real.exp_ne_zero],
split; finish [real.sin_eq_zero_iff_cos_eq]
end
... ↔ (∃ n : ℤ, ↑n * (2 * π) = x.im) ∧ (∃ n : ℤ, ↑n * π = x.im) ∧ x.re = 0 :
by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff]
... ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :
⟨λ ⟨⟨n, hn⟩, ⟨m, hm⟩, h⟩, ⟨n, by simp [complex.ext_iff, hn.symm, h]⟩,
λ ⟨n, hn⟩, ⟨⟨n, by simp [hn]⟩, ⟨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]⟩,
by simp [hn]⟩⟩
lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 :=
by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]
lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) :=
by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
@[simp] lemma 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_add_pi (x : ℂ) : sin (x + π) = -sin x :=
by simp [sin_add]
lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x :=
by simp [sin_add_pi, sin_add, sin_two_pi, cos_two_pi]
lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x :=
by simp [cos_add, cos_two_pi, sin_two_pi]
lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x :=
by simp [cos_add]
lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x :=
by simp [sub_eq_add_neg, cos_add]
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 sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
by induction n; simp [add_mul, sin_add, *]
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
by cases n; simp [add_mul, sin_add, *, sin_nat_mul_pi]
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
by induction n; simp [*, mul_add, cos_add, add_mul, cos_two_pi, sin_two_pi]
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
by cases n; simp only [cos_nat_mul_two_pi, int.of_nat_eq_coe,
int.neg_succ_of_nat_coe, int.cast_coe_nat, int.cast_neg,
(neg_mul_eq_neg_mul _ _).symm, cos_neg]
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simp [cos_add, sin_add, cos_int_mul_two_pi]
lemma exp_pi_mul_I : exp (π * I) = -1 := by { rw exp_mul_I, simp, }
theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 :=
begin
have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1,
{ rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 (by norm_num), zero_mul, add_eq_zero_iff_eq_neg,
neg_eq_neg_one_mul (exp (-θ * I)), ← div_eq_iff (exp_ne_zero (-θ * I)), ← exp_sub],
field_simp, ring },
rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int],
split; simp; intros x h2; use x,
{ field_simp, ring at h2,
rwa [mul_right_comm 2 I θ, mul_right_comm (2*(x:ℂ)+1) I (π:ℂ), mul_left_inj' I_ne_zero,
mul_comm 2 θ] at h2},
{ field_simp at h2, ring,
rw [mul_right_comm 2 I θ, mul_right_comm (2*(x:ℂ)+1) I (π:ℂ), mul_left_inj' I_ne_zero,
mul_comm 2 θ, h2] },
end
theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π :=
begin
rw [← complex.cos_sub_pi_div_two, cos_eq_zero_iff],
split,
{ rintros ⟨k, hk⟩,
use k + 1,
field_simp [eq_add_of_sub_eq hk],
ring },
{ rintros ⟨k, rfl⟩,
use k - 1,
field_simp,
ring }
end
theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma cos_eq_cos_iff {x y : ℂ} :
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
calc cos x = cos y ↔ cos x - cos y = 0 : sub_eq_zero.symm
... ↔ -2 * sin((x + y)/2) * sin((x - y)/2) = 0 : by rw cos_sub_cos
... ↔ sin((x + y)/2) = 0 ∨ sin((x - y)/2) = 0 : by { field_simp [(by norm_num : -(2:ℂ) ≠ 0)] }
... ↔ sin((x - y)/2) = 0 ∨ sin((x + y)/2) = 0 : or.comm
... ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ (∃ k :ℤ, y = 2 * k * π - x) :
begin
apply or_congr;
rw sin_eq_zero_iff;
field_simp [(by norm_num : -(2:ℂ) ≠ 0)],
work_on_goal 0 -- material specific to the left of the `or`, when x ≅ y mod 2π
{ split,
all_goals
{ rintros ⟨k, hk⟩,
refine ⟨-k, eq.symm _⟩ } },
work_on_goal 2 -- material specific to the right of the `or`, when x ≅ -y mod 2π
{ refine exists_congr (λ k, ⟨λ hk, _, λ hk, _⟩) },
all_goals -- joint material for showing two equations differ by a constant
{ rw ← sub_eq_zero at hk ⊢,
convert hk using 1,
try { push_cast },
ring }
end
... ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x : exists_or_distrib.symm
lemma sin_eq_sin_iff {x y : ℂ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
begin
rw [←complex.cos_sub_pi_div_two, ←complex.cos_sub_pi_div_two, cos_eq_cos_iff],
simp only [exists_or_distrib],
apply or_congr;
refine exists_congr (λ k, ⟨_, _⟩);
{ intros h,
rw ← sub_eq_zero at ⊢ h,
convert h using 1,
field_simp,
ring },
end
lemma has_deriv_at_tan {x : ℂ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) :
has_deriv_at tan (1 / (cos x)^2) x :=
begin
convert has_deriv_at.div (has_deriv_at_sin x) (has_deriv_at_cos x) (cos_ne_zero_iff.mpr h),
rw ← sin_sq_add_cos_sq x,
ring,
end
lemma differentiable_at_tan {x : ℂ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) : differentiable_at ℂ tan x :=
(has_deriv_at_tan h).differentiable_at
@[simp] lemma deriv_tan {x : ℂ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) : deriv tan x = 1 / (cos x)^2 :=
(has_deriv_at_tan h).deriv
lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} :=
continuous_on_sin.div continuous_on_cos $ λ x, id
lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) :=
continuous_on_iff_continuous_restrict.1 continuous_on_tan
lemma cos_surjective : function.surjective cos :=
begin
intro x,
obtain ⟨w, hw⟩ : ∃ w, 1 * w * w + (-2 * x) * w + 1 = 0,
{ exact exists_quadratic_eq_zero one_ne_zero (exists_eq_mul_self _) },
have hw' : exp (log w / I * I) = w,
{ rw [div_mul_cancel _ I_ne_zero, exp_log],
rintro rfl,
simpa only [zero_add, one_ne_zero, mul_zero] using hw },
obtain ⟨z, hz⟩ : ∃ z : ℂ, (exp (z * I)) ^ 2 - 2 * x * exp (z * I) + 1 = 0,
{ use log w / I, rw [hw', ← hw], ring },
use z,
delta cos,
rw ← mul_left_inj' (exp_ne_zero (z * I)),
rw [sub_add_eq_add_sub, sub_eq_zero, pow_two, ← exp_add, mul_comm _ x, mul_right_comm] at hz,
field_simp [add_mul, ← exp_add, hz]
end
@[simp] lemma range_cos : range cos = set.univ :=
cos_surjective.range_eq
lemma sin_surjective : function.surjective sin :=
begin
intro x,
rcases cos_surjective x with ⟨z, rfl⟩,
exact ⟨z+π/2, sin_add_pi_div_two z⟩
end
@[simp] lemma range_sin : range sin = set.univ :=
sin_surjective.range_eq
end complex
section chebyshev₁
open polynomial complex
/-- the `n`-th Chebyshev polynomial evaluates on `cos θ` to the value `cos (n * θ)`. -/
lemma chebyshev₁_complex_cos (θ : ℂ) :
∀ n, (chebyshev₁ ℂ n).eval (cos θ) = cos (n * θ)
| 0 := by simp only [chebyshev₁_zero, eval_one, nat.cast_zero, zero_mul, cos_zero]
| 1 := by simp only [eval_X, one_mul, chebyshev₁_one, nat.cast_one]
| (n + 2) :=
begin
simp only [eval_X, eval_one, chebyshev₁_add_two, eval_sub, eval_bit0, nat.cast_succ, eval_mul],
rw [chebyshev₁_complex_cos (n + 1), chebyshev₁_complex_cos n],
have aux : sin θ * sin θ = 1 - cos θ * cos θ,
{ rw ← sin_sq_add_cos_sq θ, ring, },
simp only [nat.cast_add, nat.cast_one, add_mul, cos_add, one_mul, sin_add, mul_assoc, aux],
ring,
end
/-- `cos (n * θ)` is equal to the `n`-th Chebyshev polynomial evaluated on `cos θ`. -/
lemma cos_nat_mul (n : ℕ) (θ : ℂ) :
cos (n * θ) = (chebyshev₁ ℂ n).eval (cos θ) :=
(chebyshev₁_complex_cos θ n).symm
end chebyshev₁
namespace real
open_locale real
theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 :=
begin
rw [← complex.of_real_eq_zero, complex.of_real_cos θ],
convert @complex.cos_eq_zero_iff θ,
norm_cast,
end
theorem cos_ne_zero_iff {θ : ℝ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
by rw [← not_exists, not_iff_not, cos_eq_zero_iff]
lemma cos_eq_cos_iff {x y : ℝ} :
cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
begin
have := @complex.cos_eq_cos_iff x y,
rw [← complex.of_real_cos, ← complex.of_real_cos] at this,
norm_cast at this,
simp [this],
end
lemma sin_eq_sin_iff {x y : ℝ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
begin
have := @complex.sin_eq_sin_iff x y,
rw [← complex.of_real_sin, ← complex.of_real_sin] at this,
norm_cast at this,
simp [this],
end
lemma has_deriv_at_tan {x : ℝ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) :
has_deriv_at tan (1 / (cos x)^2) x :=
begin
convert (complex.has_deriv_at_tan (by { convert h, norm_cast } )).real_of_complex,
rw ← complex.of_real_re (1/((cos x)^2)),
simp,
end
lemma differentiable_at_tan {x : ℝ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) : differentiable_at ℝ tan x :=
(has_deriv_at_tan h).differentiable_at
@[simp] lemma deriv_tan {x : ℝ} (h : ∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) : deriv tan x = 1 / (cos x)^2 :=
(has_deriv_at_tan h).deriv
lemma continuous_tan : continuous (λ x : {x | cos x ≠ 0}, tan x) :=
by simp only [tan_eq_sin_div_cos]; exact
(continuous_sin.comp continuous_subtype_val).mul
(continuous.inv subtype.property
(continuous_cos.comp continuous_subtype_val))
lemma continuous_on_tan : continuous_on tan {x | cos x ≠ 0} :=
by { rw continuous_on_iff_continuous_restrict, convert continuous_tan }
lemma has_deriv_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) :
has_deriv_at tan (1 / (cos x)^2) x :=
has_deriv_at_tan (cos_ne_zero_iff.mp (ne_of_gt (cos_pos_of_mem_Ioo h)))
lemma differentiable_at_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) :
differentiable_at ℝ tan x :=
(has_deriv_at_tan_of_mem_Ioo h).differentiable_at
lemma deriv_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π/2):ℝ) (π/2)) : deriv tan x = 1 / (cos x)^2 :=
(has_deriv_at_tan_of_mem_Ioo h).deriv
lemma continuous_on_tan_Ioo : continuous_on tan (Ioo (-(π/2)) (π/2)) :=
begin
refine continuous_on_tan.mono _,
intros x hx,
simp only [mem_set_of_eq],
exact ne_of_gt (cos_pos_of_mem_Ioo hx),
end
open filter
open_locale topological_space
lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[Iio (π/2)] (π/2)) (𝓝 1) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[Iio (π/2)] (π/2)) (𝓝[Ioi 0] 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 (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[Iio (π/2)] (π/2)) at_top :=
begin
convert (tendsto.inv_tendsto_zero tendsto_cos_pi_div_two).at_top_mul (by norm_num)
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 (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝 (-1)) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝[Ioi 0] 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 (set.left_mem_Ico.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[Ioi (-(π/2))] (-(π/2))) at_bot :=
begin
convert (tendsto.inv_tendsto_zero tendsto_cos_neg_pi_div_two).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
/-!
### Continuity and differentiability of arctan
The continuity of `arctan` is difficult to prove due to `arctan` being (indirectly) defined naively
via `classical.some`. The proof therefore uses the general theorem that monotone functions are
homeomorphisms: `homeomorph_of_strict_mono_continuous_Ioo`. We first prove that `tan` (restricted)
is a homeomorphism whose inverse is definitionally equal to `arctan`. The fact that `arctan` is
continuous is then derived from the fact that it is equal to a homeomorphism, and its
differentiability is in turn derived from its continuity using `has_deriv_at.of_local_left_inverse`.
-/
/-- The function `tan`, restricted to the open interval (-π/2, π/2), is a homeomorphism. The inverse
function of that homeomorphism is definitionally equal to `arctan` via `homeomorph.change_inv`. -/
def tan_homeomorph : (Ioo (-(π/2)) (π/2)) ≃ₜ ℝ :=
(homeomorph_of_strict_mono_continuous_Ioo tan (by linarith [pi_div_two_pos])
(λ x y, tan_lt_tan_of_lt_of_lt_pi_div_two) continuous_on_tan_Ioo tendsto_tan_pi_div_two
tendsto_tan_neg_pi_div_two).change_inv (λ x, ⟨arctan x, arctan_mem_Ioo x⟩) tan_arctan
lemma tan_homeomorph_inv_fun_eq_arctan : coe ∘ tan_homeomorph.inv_fun = arctan := rfl
lemma continuous_arctan : continuous arctan :=
continuous_subtype_coe.comp tan_homeomorph.continuous_inv_fun
lemma has_deriv_at_arctan (x : ℝ) : has_deriv_at arctan (1 / (1 + x^2)) x :=
begin
have h1 : 0 < 1 + x^2 := by nlinarith,
have h2 : cos (arctan x) ≠ 0 := by { rw cos_arctan, exact ne_of_gt (one_div_pos.mpr (sqrt_pos.mpr h1)) },
simpa [(cos_arctan x), sqr_sqrt (le_of_lt h1)] using has_deriv_at.of_local_left_inverse
continuous_arctan.continuous_at (has_deriv_at_tan (cos_ne_zero_iff.mp h2))
(one_div_ne_zero (pow_ne_zero 2 h2)) (by {apply eventually_of_forall, exact tan_arctan} ),
end
lemma differentiable_at_arctan (x : ℝ) : differentiable_at ℝ arctan x :=
(has_deriv_at_arctan x).differentiable_at
@[simp] lemma deriv_arctan : deriv arctan = (λ x, 1 / (1 + x^2)) :=
funext $ λ x, (has_deriv_at_arctan x).deriv
end real
section
/-! Register lemmas for the derivatives of the composition of `real.arctan` with a differentiable
function, for standalone use and use with `simp`. -/
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
lemma has_deriv_at.arctan (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.arctan (f x)) ((1 / (1 + (f x)^2)) * f') x :=
(real.has_deriv_at_arctan (f x)).comp x hf
lemma has_deriv_within_at.arctan (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.arctan (f x)) ((1 / (1 + (f x)^2)) * f') s x :=
(real.has_deriv_at_arctan (f x)).comp_has_deriv_within_at x hf
lemma differentiable_within_at.arctan (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.arctan (f x)) s x :=
hf.has_deriv_within_at.arctan.differentiable_within_at
@[simp] lemma differentiable_at.arctan (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λ x, real.arctan (f x)) x :=
hc.has_deriv_at.arctan.differentiable_at
lemma differentiable_on.arctan (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λ x, real.arctan (f x)) s :=
λ x h, (hc x h).arctan
@[simp] lemma differentiable.arctan (hc : differentiable ℝ f) :
differentiable ℝ (λ x, real.arctan (f x)) :=
λ x, (hc x).arctan
lemma deriv_within_arctan (hf : differentiable_within_at ℝ f s x) (hxs : unique_diff_within_at ℝ s x) :
deriv_within (λ x, real.arctan (f x)) s x = (1 / (1 + (f x)^2)) * (deriv_within f s x) :=
hf.has_deriv_within_at.arctan.deriv_within hxs
@[simp] lemma deriv_arctan (hc : differentiable_at ℝ f x) :
deriv (λ x, real.arctan (f x)) x = (1 / (1 + (f x)^2)) * (deriv f x) :=
hc.has_deriv_at.arctan.deriv
end
|
9b7c92dd84f213afecad4009c0d0f3d223762bef
|
a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7
|
/src/order/filter/at_top_bot.lean
|
86076654b2d7e9a02fd50bfbc07c45966b0c3045
|
[
"Apache-2.0"
] |
permissive
|
kmill/mathlib
|
ea5a007b67ae4e9e18dd50d31d8aa60f650425ee
|
1a419a9fea7b959317eddd556e1bb9639f4dcc05
|
refs/heads/master
| 1,668,578,197,719
| 1,593,629,163,000
| 1,593,629,163,000
| 276,482,939
| 0
| 0
| null | 1,593,637,960,000
| 1,593,637,959,000
| null |
UTF-8
|
Lean
| false
| false
| 19,945
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot
-/
import order.filter.basic
/-!
# `at_top` and `at_bot` filters on preorded sets, monoids and groups.
In this file we define the filters
* `at_top`: corresponds to `n → +∞`;
* `at_bot`: corresponds to `n → -∞`.
Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”.
-/
variables {α β γ : Type*}
open set
open_locale classical filter
namespace filter
/-- `at_top` is the filter representing the limit `→ ∞` on an ordered set.
It is generated by the collection of up-sets `{b | a ≤ b}`.
(The preorder need not have a top element for this to be well defined,
and indeed is trivial when a top element exists.) -/
def at_top [preorder α] : filter α := ⨅ a, 𝓟 {b | a ≤ b}
/-- `at_bot` is the filter representing the limit `→ -∞` on an ordered set.
It is generated by the collection of down-sets `{b | b ≤ a}`.
(The preorder need not have a bottom element for this to be well defined,
and indeed is trivial when a bottom element exists.) -/
def at_bot [preorder α] : filter α := ⨅ a, 𝓟 {b | b ≤ a}
lemma mem_at_top [preorder α] (a : α) : {b : α | a ≤ b} ∈ @at_top α _ :=
mem_infi_sets a $ subset.refl _
lemma Ioi_mem_at_top [preorder α] [no_top_order α] (x : α) : Ioi x ∈ (at_top : filter α) :=
let ⟨z, hz⟩ := no_top x in mem_sets_of_superset (mem_at_top z) $ λ y h, lt_of_lt_of_le hz h
lemma mem_at_bot [preorder α] (a : α) : {b : α | b ≤ a} ∈ @at_bot α _ :=
mem_infi_sets a $ subset.refl _
lemma Iio_mem_at_bot [preorder α] [no_bot_order α] (x : α) : Iio x ∈ (at_bot : filter α) :=
let ⟨z, hz⟩ := no_bot x in mem_sets_of_superset (mem_at_bot z) $ λ y h, lt_of_le_of_lt h hz
@[simp] lemma at_top_ne_bot [nonempty α] [semilattice_sup α] : (at_top : filter α) ≠ ⊥ :=
infi_ne_bot_of_directed (by apply_instance)
(assume a b, ⟨a ⊔ b, by simp only [ge, le_principal_iff, forall_const, set_of_subset_set_of,
mem_principal_sets, and_self, sup_le_iff, forall_true_iff] {contextual := tt}⟩)
(assume a, principal_ne_bot_iff.2 nonempty_Ici)
@[simp, nolint ge_or_gt]
lemma mem_at_top_sets [nonempty α] [semilattice_sup α] {s : set α} :
s ∈ (at_top : filter α) ↔ ∃a:α, ∀b≥a, b ∈ s :=
let ⟨a⟩ := ‹nonempty α› in
iff.intro
(assume h, infi_sets_induct h ⟨a, by simp only [forall_const, mem_univ, forall_true_iff]⟩
(assume a s₁ s₂ ha ⟨b, hb⟩, ⟨a ⊔ b,
assume c hc, ⟨ha $ le_trans le_sup_left hc, hb _ $ le_trans le_sup_right hc⟩⟩)
(assume s₁ s₂ h ⟨a, ha⟩, ⟨a, assume b hb, h $ ha _ hb⟩))
(assume ⟨a, h⟩, mem_infi_sets a $ assume x, h x)
@[simp, nolint ge_or_gt]
lemma eventually_at_top {α} [semilattice_sup α] [nonempty α] {p : α → Prop} :
(∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ b ≥ a, p b) :=
by simp only [filter.eventually, filter.mem_at_top_sets, mem_set_of_eq]
@[nolint ge_or_gt]
lemma eventually.exists_forall_of_at_top {α} [semilattice_sup α] [nonempty α] {p : α → Prop}
(h : ∀ᶠ x in at_top, p x) : ∃ a, ∀ b ≥ a, p b :=
eventually_at_top.mp h
@[nolint ge_or_gt]
lemma frequently_at_top {α} [semilattice_sup α] [nonempty α] {p : α → Prop} :
(∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b ≥ a, p b) :=
by simp only [filter.frequently, eventually_at_top, not_exists, not_forall, not_not]
@[nolint ge_or_gt]
lemma frequently_at_top' {α} [semilattice_sup α] [nonempty α] [no_top_order α] {p : α → Prop} :
(∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b > a, p b) :=
begin
rw frequently_at_top,
split ; intros h a,
{ cases no_top a with a' ha',
rcases h a' with ⟨b, hb, hb'⟩,
exact ⟨b, lt_of_lt_of_le ha' hb, hb'⟩ },
{ rcases h a with ⟨b, hb, hb'⟩,
exact ⟨b, le_of_lt hb, hb'⟩ },
end
@[nolint ge_or_gt]
lemma frequently.forall_exists_of_at_top {α} [semilattice_sup α] [nonempty α] {p : α → Prop}
(h : ∃ᶠ x in at_top, p x) : ∀ a, ∃ b ≥ a, p b :=
frequently_at_top.mp h
lemma map_at_top_eq [nonempty α] [semilattice_sup α] {f : α → β} :
at_top.map f = (⨅a, 𝓟 $ f '' {a' | a ≤ a'}) :=
calc map f (⨅a, 𝓟 {a' | a ≤ a'}) = (⨅a, map f $ 𝓟 {a' | a ≤ a'}) :
map_infi_eq (assume a b, ⟨a ⊔ b, by simp only [ge, le_principal_iff, forall_const, set_of_subset_set_of,
mem_principal_sets, and_self, sup_le_iff, forall_true_iff] {contextual := tt}⟩)
(by apply_instance)
... = (⨅a, 𝓟 $ f '' {a' | a ≤ a'}) : by simp only [map_principal, eq_self_iff_true]
lemma tendsto_at_top [preorder β] (m : α → β) (f : filter α) :
tendsto m f at_top ↔ (∀b, {a | b ≤ m a} ∈ f) :=
by simp only [at_top, tendsto_infi, tendsto_principal]; refl
lemma tendsto_at_top_mono' [preorder β] (l : filter α) ⦃f₁ f₂ : α → β⦄
(h : {x | f₁ x ≤ f₂ x} ∈ l) :
tendsto f₁ l at_top → tendsto f₂ l at_top :=
assume h₁, (tendsto_at_top _ _).2 $ λ b, mp_sets ((tendsto_at_top _ _).1 h₁ b)
(monotone_mem_sets (λ a ha ha₁, le_trans ha₁ ha) h)
lemma tendsto_at_top_mono [preorder β] (l : filter α) :
monotone (λ f : α → β, tendsto f l at_top) :=
λ f₁ f₂ h, tendsto_at_top_mono' l $ univ_mem_sets' h
/-!
### Sequences
-/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma inf_map_at_top_ne_bot_iff [semilattice_sup α] [nonempty α] {F : filter β} {u : α → β} :
F ⊓ (map u at_top) ≠ ⊥ ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U :=
by simp_rw [inf_ne_bot_iff_frequently_left, frequently_map, frequently_at_top] ; trivial
lemma extraction_of_frequently_at_top' {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=
begin
choose u hu using h,
cases forall_and_distrib.mp hu with hu hu',
exact ⟨u ∘ (nat.rec 0 (λ n v, u v)), strict_mono.nat (λ n, hu _), λ n, hu' _⟩,
end
lemma extraction_of_frequently_at_top {P : ℕ → Prop} (h : ∃ᶠ n in at_top, P n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=
begin
rw frequently_at_top' at h,
exact extraction_of_frequently_at_top' h,
end
lemma extraction_of_eventually_at_top {P : ℕ → Prop} (h : ∀ᶠ n in at_top, P n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=
extraction_of_frequently_at_top (eventually.frequently at_top_ne_bot h)
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma exists_le_of_tendsto_at_top [semilattice_sup α] [preorder β] {u : α → β}
(h : tendsto u at_top at_top) : ∀ a b, ∃ a' ≥ a, b ≤ u a' :=
begin
intros a b,
have : ∀ᶠ x in at_top, a ≤ x ∧ b ≤ u x := inter_mem_sets (mem_at_top a) (h $ mem_at_top b),
haveI : nonempty α := ⟨a⟩,
rcases this.exists at_top_ne_bot with ⟨a', ha, hb⟩,
exact ⟨a', ha, hb⟩
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma exists_lt_of_tendsto_at_top [semilattice_sup α] [preorder β] [no_top_order β]
{u : α → β} (h : tendsto u at_top at_top) : ∀ a b, ∃ a' ≥ a, b < u a' :=
begin
intros a b,
cases no_top b with b' hb',
rcases exists_le_of_tendsto_at_top h a b' with ⟨a', ha', ha''⟩,
exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩
end
/--
If `u` is a sequence which is unbounded above,
then after any point, it reaches a value strictly greater than all previous values.
-/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma high_scores [linear_order β] [no_top_order β] {u : ℕ → β}
(hu : tendsto u at_top at_top) : ∀ N, ∃ n ≥ N, ∀ k < n, u k < u n :=
begin
letI := classical.DLO β,
intros N,
let A := finset.image u (finset.range $ N+1), -- A = {u 0, ..., u N}
have Ane : A.nonempty,
from ⟨u 0, finset.mem_image_of_mem _ (finset.mem_range.mpr $ nat.zero_lt_succ _)⟩,
let M := finset.max' A Ane,
have ex : ∃ n ≥ N, M < u n,
from exists_lt_of_tendsto_at_top hu _ _,
obtain ⟨n, hnN, hnM, hn_min⟩ : ∃ n, N ≤ n ∧ M < u n ∧ ∀ k, N ≤ k → k < n → u k ≤ M,
{ use nat.find ex,
rw ← and_assoc,
split,
{ simpa using nat.find_spec ex },
{ intros k hk hk',
simpa [hk] using nat.find_min ex hk' } },
use [n, hnN],
intros k hk,
by_cases H : k ≤ N,
{ have : u k ∈ A,
from finset.mem_image_of_mem _ (finset.mem_range.mpr $ nat.lt_succ_of_le H),
have : u k ≤ M,
from finset.le_max' A Ane (u k) this,
exact lt_of_le_of_lt this hnM },
{ push_neg at H,
calc u k ≤ M : hn_min k (le_of_lt H) hk
... < u n : hnM },
end
/--
If `u` is a sequence which is unbounded above,
then it `frequently` reaches a value strictly greater than all previous values.
-/
lemma frequently_high_scores [linear_order β] [no_top_order β] {u : ℕ → β}
(hu : tendsto u at_top at_top) : ∃ᶠ n in at_top, ∀ k < n, u k < u n :=
by simpa [frequently_at_top] using high_scores hu
lemma strict_mono_subseq_of_tendsto_at_top
{β : Type*} [linear_order β] [no_top_order β]
{u : ℕ → β} (hu : tendsto u at_top at_top) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) :=
let ⟨φ, h, h'⟩ := extraction_of_frequently_at_top (frequently_high_scores hu) in
⟨φ, h, λ n m hnm, h' m _ (h hnm)⟩
lemma strict_mono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) :
∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) :=
strict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono _ hu tendsto_id)
lemma strict_mono_tendsto_at_top {φ : ℕ → ℕ} (h : strict_mono φ) :
tendsto φ at_top at_top :=
tendsto_at_top_mono _ h.id_le tendsto_id
section ordered_add_monoid
variables [ordered_cancel_add_comm_monoid β] (l : filter α) {f g : α → β}
lemma tendsto_at_top_add_nonneg_left' (hf : {x | 0 ≤ f x} ∈ l) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_mono' l (monotone_mem_sets (λ x, le_add_of_nonneg_left) hf) hg
lemma tendsto_at_top_add_nonneg_left (hf : ∀ x, 0 ≤ f x) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_nonneg_left' l (univ_mem_sets' hf) hg
lemma tendsto_at_top_add_nonneg_right' (hf : tendsto f l at_top) (hg : {x | 0 ≤ g x} ∈ l) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_mono' l (monotone_mem_sets (λ x, le_add_of_nonneg_right) hg) hf
lemma tendsto_at_top_add_nonneg_right (hf : tendsto f l at_top) (hg : ∀ x, 0 ≤ g x) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_nonneg_right' l hf (univ_mem_sets' hg)
lemma tendsto_at_top_of_add_const_left (C : β) (hf : tendsto (λ x, C + f x) l at_top) :
tendsto f l at_top :=
(tendsto_at_top _ l).2 $ assume b,
monotone_mem_sets (λ x, le_of_add_le_add_left) ((tendsto_at_top _ _).1 hf (C + b))
lemma tendsto_at_top_of_add_const_right (C : β) (hf : tendsto (λ x, f x + C) l at_top) :
tendsto f l at_top :=
(tendsto_at_top _ l).2 $ assume b,
monotone_mem_sets (λ x, le_of_add_le_add_right) ((tendsto_at_top _ _).1 hf (b + C))
lemma tendsto_at_top_of_add_bdd_above_left' (C) (hC : {x | f x ≤ C} ∈ l)
(h : tendsto (λ x, f x + g x) l at_top) :
tendsto g l at_top :=
tendsto_at_top_of_add_const_left l C
(tendsto_at_top_mono' l (monotone_mem_sets (λ x (hx : f x ≤ C), add_le_add_right hx (g x)) hC) h)
lemma tendsto_at_top_of_add_bdd_above_left (C) (hC : ∀ x, f x ≤ C) :
tendsto (λ x, f x + g x) l at_top → tendsto g l at_top :=
tendsto_at_top_of_add_bdd_above_left' l C (univ_mem_sets' hC)
lemma tendsto_at_top_of_add_bdd_above_right' (C) (hC : {x | g x ≤ C} ∈ l)
(h : tendsto (λ x, f x + g x) l at_top) :
tendsto f l at_top :=
tendsto_at_top_of_add_const_right l C
(tendsto_at_top_mono' l (monotone_mem_sets (λ x (hx : g x ≤ C), add_le_add_left hx (f x)) hC) h)
lemma tendsto_at_top_of_add_bdd_above_right (C) (hC : ∀ x, g x ≤ C) :
tendsto (λ x, f x + g x) l at_top → tendsto f l at_top :=
tendsto_at_top_of_add_bdd_above_right' l C (univ_mem_sets' hC)
end ordered_add_monoid
section ordered_group
variables [ordered_add_comm_group β] (l : filter α) {f g : α → β}
lemma tendsto_at_top_add_left_of_le' (C : β) (hf : {x | C ≤ f x} ∈ l) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
@tendsto_at_top_of_add_bdd_above_left' _ _ _ l (λ x, -(f x)) (λ x, f x + g x) (-C)
(by simp [hf]) (by simp [hg])
lemma tendsto_at_top_add_left_of_le (C : β) (hf : ∀ x, C ≤ f x) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_left_of_le' l C (univ_mem_sets' hf) hg
lemma tendsto_at_top_add_right_of_le' (C : β) (hf : tendsto f l at_top) (hg : {x | C ≤ g x} ∈ l) :
tendsto (λ x, f x + g x) l at_top :=
@tendsto_at_top_of_add_bdd_above_right' _ _ _ l (λ x, f x + g x) (λ x, -(g x)) (-C)
(by simp [hg]) (by simp [hf])
lemma tendsto_at_top_add_right_of_le (C : β) (hf : tendsto f l at_top) (hg : ∀ x, C ≤ g x) :
tendsto (λ x, f x + g x) l at_top :=
tendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' hg)
lemma tendsto_at_top_add_const_left (C : β) (hf : tendsto f l at_top) :
tendsto (λ x, C + f x) l at_top :=
tendsto_at_top_add_left_of_le' l C (univ_mem_sets' $ λ _, le_refl C) hf
lemma tendsto_at_top_add_const_right (C : β) (hf : tendsto f l at_top) :
tendsto (λ x, f x + C) l at_top :=
tendsto_at_top_add_right_of_le' l C hf (univ_mem_sets' $ λ _, le_refl C)
end ordered_group
open_locale filter
@[nolint ge_or_gt]
lemma tendsto_at_top' [nonempty α] [semilattice_sup α] (f : α → β) (l : filter β) :
tendsto f at_top l ↔ (∀s ∈ l, ∃a, ∀b≥a, f b ∈ s) :=
by simp only [tendsto_def, mem_at_top_sets]; refl
@[nolint ge_or_gt]
theorem tendsto_at_top_principal [nonempty β] [semilattice_sup β] {f : β → α} {s : set α} :
tendsto f at_top (𝓟 s) ↔ ∃N, ∀n≥N, f n ∈ s :=
by rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl
/-- A function `f` grows to infinity independent of an order-preserving embedding `e`. -/
lemma tendsto_at_top_embedding {α β γ : Type*} [preorder β] [preorder γ]
{f : α → β} {e : β → γ} {l : filter α}
(hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, c ≤ e b) :
tendsto (e ∘ f) l at_top ↔ tendsto f l at_top :=
begin
rw [tendsto_at_top, tendsto_at_top],
split,
{ assume hc b,
filter_upwards [hc (e b)] assume a, (hm b (f a)).1 },
{ assume hb c,
rcases hu c with ⟨b, hc⟩,
filter_upwards [hb b] assume a ha, le_trans hc ((hm b (f a)).2 ha) }
end
lemma tendsto_at_top_at_top [nonempty α] [semilattice_sup α] [preorder β] (f : α → β) :
tendsto f at_top at_top ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a :=
iff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal
@[nolint ge_or_gt]
lemma tendsto_at_top_at_bot [nonempty α] [decidable_linear_order α] [preorder β] (f : α → β) :
tendsto f at_top at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), i ≤ a → b ≥ f a :=
@tendsto_at_top_at_top α (order_dual β) _ _ _ f
lemma tendsto_at_top_at_top_of_monotone [nonempty α] [semilattice_sup α] [preorder β]
{f : α → β} (hf : monotone f) :
tendsto f at_top at_top ↔ ∀ b : β, ∃ a : α, b ≤ f a :=
(tendsto_at_top_at_top f).trans $ forall_congr $ λ b, exists_congr $ λ a,
⟨λ h, h a (le_refl a), λ h a' ha', le_trans h $ hf ha'⟩
alias tendsto_at_top_at_top_of_monotone ← monotone.tendsto_at_top_at_top
lemma tendsto_finset_range : tendsto finset.range at_top at_top :=
finset.range_mono.tendsto_at_top_at_top.2 finset.exists_nat_subset_range
lemma monotone.tendsto_at_top_finset [nonempty β] [semilattice_sup β]
{f : β → finset α} (h : monotone f) (h' : ∀ x : α, ∃ n, x ∈ f n) :
tendsto f at_top at_top :=
begin
classical,
apply (tendsto_at_top_at_top_of_monotone h).2,
choose N hN using h',
assume b,
have : bdd_above ↑(b.image N) := finset.bdd_above _,
rcases this with ⟨n, hn⟩,
refine ⟨n, _⟩,
assume i ib,
have : N i ∈ ↑(finset.image N b),
by { rw finset.mem_coe, exact finset.mem_image_of_mem _ ib },
exact (h (hn this)) (hN i)
end
lemma tendsto_finset_image_at_top_at_top {i : β → γ} {j : γ → β} (h : ∀x, j (i x) = x) :
tendsto (finset.image j) at_top at_top :=
have j ∘ i = id, from funext h,
(finset.image_mono j).tendsto_at_top_at_top.2 $ assume s,
⟨s.image i, by simp only [finset.image_image, this, finset.image_id, le_refl]⟩
lemma prod_at_top_at_top_eq {β₁ β₂ : Type*} [nonempty β₁] [nonempty β₂] [semilattice_sup β₁]
[semilattice_sup β₂] : (@at_top β₁ _) ×ᶠ (@at_top β₂ _) = @at_top (β₁ × β₂) _ :=
by inhabit β₁; inhabit β₂;
simp [at_top, prod_infi_left (default β₁), prod_infi_right (default β₂), infi_prod];
exact infi_comm
lemma prod_map_at_top_eq {α₁ α₂ β₁ β₂ : Type*} [nonempty β₁] [nonempty β₂]
[semilattice_sup β₁] [semilattice_sup β₂] (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) :
(map u₁ at_top) ×ᶠ (map u₂ at_top) = map (prod.map u₁ u₂) at_top :=
by rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def]
/-- A function `f` maps upwards closed sets (at_top sets) to upwards closed sets when it is a
Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an
insertion and a connetion above `b'`. -/
lemma map_at_top_eq_of_gc [semilattice_sup α] [semilattice_sup β] {f : α → β} (g : β → α) (b' : β)
(hf : monotone f) (gc : ∀a, ∀b≥b', f a ≤ b ↔ a ≤ g b) (hgi : ∀b≥b', b ≤ f (g b)) :
map f at_top = at_top :=
begin
rw [@map_at_top_eq α _ ⟨g b'⟩],
refine le_antisymm
(le_infi $ assume b, infi_le_of_le (g (b ⊔ b')) $ principal_mono.2 $ image_subset_iff.2 _)
(le_infi $ assume a, infi_le_of_le (f a ⊔ b') $ principal_mono.2 _),
{ assume a ha, exact (le_trans le_sup_left $ le_trans (hgi _ le_sup_right) $ hf ha) },
{ assume b hb,
have hb' : b' ≤ b := le_trans le_sup_right hb,
exact ⟨g b, (gc _ _ hb').1 (le_trans le_sup_left hb),
le_antisymm ((gc _ _ hb').2 (le_refl _)) (hgi _ hb')⟩ }
end
lemma map_add_at_top_eq_nat (k : ℕ) : map (λa, a + k) at_top = at_top :=
map_at_top_eq_of_gc (λa, a - k) k
(assume a b h, add_le_add_right h k)
(assume a b h, (nat.le_sub_right_iff_add_le h).symm)
(assume a h, by rw [nat.sub_add_cancel h])
lemma map_sub_at_top_eq_nat (k : ℕ) : map (λa, a - k) at_top = at_top :=
map_at_top_eq_of_gc (λa, a + k) 0
(assume a b h, nat.sub_le_sub_right h _)
(assume a b _, nat.sub_le_right_iff_le_add)
(assume b _, by rw [nat.add_sub_cancel])
lemma tendsto_add_at_top_nat (k : ℕ) : tendsto (λa, a + k) at_top at_top :=
le_of_eq (map_add_at_top_eq_nat k)
lemma tendsto_sub_at_top_nat (k : ℕ) : tendsto (λa, a - k) at_top at_top :=
le_of_eq (map_sub_at_top_eq_nat k)
lemma tendsto_add_at_top_iff_nat {f : ℕ → α} {l : filter α} (k : ℕ) :
tendsto (λn, f (n + k)) at_top l ↔ tendsto f at_top l :=
show tendsto (f ∘ (λn, n + k)) at_top l ↔ tendsto f at_top l,
by rw [← tendsto_map'_iff, map_add_at_top_eq_nat]
lemma map_div_at_top_eq_nat (k : ℕ) (hk : k > 0) : map (λa, a / k) at_top = at_top :=
map_at_top_eq_of_gc (λb, b * k + (k - 1)) 1
(assume a b h, nat.div_le_div_right h)
(assume a b _,
calc a / k ≤ b ↔ a / k < b + 1 : by rw [← nat.succ_eq_add_one, nat.lt_succ_iff]
... ↔ a < (b + 1) * k : nat.div_lt_iff_lt_mul _ _ hk
... ↔ _ :
begin
cases k,
exact (lt_irrefl _ hk).elim,
simp [mul_add, add_mul, nat.succ_add, nat.lt_succ_iff]
end)
(assume b _,
calc b = (b * k) / k : by rw [nat.mul_div_cancel b hk]
... ≤ (b * k + (k - 1)) / k : nat.div_le_div_right $ nat.le_add_right _ _)
end filter
|
de23cacfd80352bdc7dd54c0fa29ff196456a4bd
|
302c785c90d40ad3d6be43d33bc6a558354cc2cf
|
/src/linear_algebra/affine_space/midpoint.lean
|
810626c352596d55ad64c594c54b764ee40f7942
|
[
"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,872
|
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.char_p.invertible
import linear_algebra.affine_space.affine_equiv
/-!
# Midpoint of a segment
## Main definitions
* `midpoint R x y`: midpoint of the segment `[x, y]`. We define it for `x` and `y`
in a module over a ring `R` with invertible `2`.
* `add_monoid_hom.of_map_midpoint`: construct an `add_monoid_hom` given a map `f` such that
`f` sends zero to zero and midpoints to midpoints.
## Main theorems
* `midpoint_eq_iff`: `z` is the midpoint of `[x, y]` if and only if `x + y = z + z`,
* `midpoint_unique`: `midpoint R x y` does not depend on `R`;
* `midpoint x y` is linear both in `x` and `y`;
* `point_reflection_midpoint_left`, `point_reflection_midpoint_right`:
`equiv.point_reflection (midpoint R x y)` swaps `x` and `y`.
We do not mark most lemmas as `@[simp]` because it is hard to tell which side is simpler.
## Tags
midpoint, add_monoid_hom
-/
open affine_map affine_equiv
section
variables (R : Type*) {V V' P P' : Type*} [ring R] [invertible (2:R)]
[add_comm_group V] [semimodule R V] [add_torsor V P]
[add_comm_group V'] [semimodule R V'] [add_torsor V' P']
include V
/-- `midpoint x y` is the midpoint of the segment `[x, y]`. -/
def midpoint (x y : P) : P := line_map x y (⅟2:R)
variables {R} {x y z : P}
include V'
@[simp] lemma affine_map.map_midpoint (f : P →ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_line_map a b _
@[simp] lemma affine_equiv.map_midpoint (f : P ≃ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_line_map a b _
omit V'
@[simp] lemma affine_equiv.point_reflection_midpoint_left (x y : P) :
point_reflection R (midpoint R x y) x = y :=
by rw [midpoint, point_reflection_apply, line_map_apply, vadd_vsub,
vadd_vadd, ← add_smul, ← two_mul, mul_inv_of_self, one_smul, vsub_vadd]
lemma midpoint_comm (x y : P) : midpoint R x y = midpoint R y x :=
by rw [midpoint, ← line_map_apply_one_sub, one_sub_inv_of_two, midpoint]
@[simp] lemma affine_equiv.point_reflection_midpoint_right (x y : P) :
point_reflection R (midpoint R x y) y = x :=
by rw [midpoint_comm, affine_equiv.point_reflection_midpoint_left]
lemma midpoint_vsub_midpoint (p₁ p₂ p₃ p₄ : P) :
midpoint R p₁ p₂ -ᵥ midpoint R p₃ p₄ = midpoint R (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) :=
line_map_vsub_line_map _ _ _ _ _
lemma midpoint_vadd_midpoint (v v' : V) (p p' : P) :
midpoint R v v' +ᵥ midpoint R p p' = midpoint R (v +ᵥ p) (v' +ᵥ p') :=
line_map_vadd_line_map _ _ _ _ _
lemma midpoint_eq_iff {x y z : P} : midpoint R x y = z ↔ point_reflection R z x = y :=
eq_comm.trans ((injective_point_reflection_left_of_module R x).eq_iff'
(affine_equiv.point_reflection_midpoint_left x y)).symm
@[simp] lemma midpoint_vsub_left (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₁ = (⅟2:R) • (p₂ -ᵥ p₁) :=
line_map_vsub_left _ _ _
@[simp] lemma midpoint_vsub_right (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₂ = (⅟2:R) • (p₁ -ᵥ p₂) :=
by rw [midpoint_comm, midpoint_vsub_left]
@[simp] lemma left_vsub_midpoint (p₁ p₂ : P) : p₁ -ᵥ midpoint R p₁ p₂ = (⅟2:R) • (p₁ -ᵥ p₂) :=
left_vsub_line_map _ _ _
@[simp] lemma right_vsub_midpoint (p₁ p₂ : P) : p₂ -ᵥ midpoint R p₁ p₂ = (⅟2:R) • (p₂ -ᵥ p₁) :=
by rw [midpoint_comm, left_vsub_midpoint]
@[simp] lemma midpoint_sub_left (v₁ v₂ : V) : midpoint R v₁ v₂ - v₁ = (⅟2:R) • (v₂ - v₁) :=
midpoint_vsub_left v₁ v₂
@[simp] lemma midpoint_sub_right (v₁ v₂ : V) : midpoint R v₁ v₂ - v₂ = (⅟2:R) • (v₁ - v₂) :=
midpoint_vsub_right v₁ v₂
@[simp] lemma left_sub_midpoint (v₁ v₂ : V) : v₁ - midpoint R v₁ v₂ = (⅟2:R) • (v₁ - v₂) :=
left_vsub_midpoint v₁ v₂
@[simp] lemma right_sub_midpoint (v₁ v₂ : V) : v₂ - midpoint R v₁ v₂ = (⅟2:R) • (v₂ - v₁) :=
right_vsub_midpoint v₁ v₂
variable (R)
lemma midpoint_eq_midpoint_iff_vsub_eq_vsub {x x' y y' : P} :
midpoint R x y = midpoint R x' y' ↔ x -ᵥ x' = y' -ᵥ y :=
by rw [← @vsub_eq_zero_iff_eq V, midpoint_vsub_midpoint, midpoint_eq_iff, point_reflection_apply,
vsub_eq_sub, zero_sub, vadd_eq_add, add_zero, neg_eq_iff_neg_eq, neg_vsub_eq_vsub_rev, eq_comm]
lemma midpoint_eq_iff' {x y z : P} : midpoint R x y = z ↔ equiv.point_reflection z x = y :=
midpoint_eq_iff
/-- `midpoint` does not depend on the ring `R`. -/
lemma midpoint_unique (R' : Type*) [ring R'] [invertible (2:R')] [semimodule R' V] (x y : P) :
midpoint R x y = midpoint R' x y :=
(midpoint_eq_iff' R).2 $ (midpoint_eq_iff' R').1 rfl
@[simp] lemma midpoint_self (x : P) : midpoint R x x = x :=
line_map_same_apply _ _
@[simp] lemma midpoint_add_self (x y : V) : midpoint R x y + midpoint R x y = x + y :=
calc midpoint R x y +ᵥ midpoint R x y = midpoint R x y +ᵥ midpoint R y x : by rw midpoint_comm
... = x + y : by rw [midpoint_vadd_midpoint, vadd_eq_add, vadd_eq_add, add_comm, midpoint_self]
lemma midpoint_zero_add (x y : V) : midpoint R 0 (x + y) = midpoint R x y :=
(midpoint_eq_midpoint_iff_vsub_eq_vsub R).2 $ by simp [sub_add_eq_sub_sub_swap]
lemma midpoint_eq_smul_add (x y : V) : midpoint R x y = (⅟2 : R) • (x + y) :=
by rw [midpoint_eq_iff, point_reflection_apply, vsub_eq_sub, vadd_eq_add, sub_add_eq_add_sub,
← two_smul R, smul_smul, mul_inv_of_self, one_smul, add_sub_cancel']
end
lemma line_map_inv_two {R : Type*} {V P : Type*} [division_ring R] [char_zero R]
[add_comm_group V] [semimodule R V] [add_torsor V P] (a b : P) :
line_map a b (2⁻¹:R) = midpoint R a b :=
rfl
lemma line_map_one_half {R : Type*} {V P : Type*} [division_ring R] [char_zero R]
[add_comm_group V] [semimodule R V] [add_torsor V P] (a b : P) :
line_map a b (1/2:R) = midpoint R a b :=
by rw [one_div, line_map_inv_two]
lemma homothety_inv_of_two {R : Type*} {V P : Type*} [comm_ring R] [invertible (2:R)]
[add_comm_group V] [semimodule R V] [add_torsor V P] (a b : P) :
homothety a (⅟2:R) b = midpoint R a b :=
rfl
lemma homothety_inv_two {k : Type*} {V P : Type*} [field k] [char_zero k]
[add_comm_group V] [semimodule k V] [add_torsor V P] (a b : P) :
homothety a (2⁻¹:k) b = midpoint k a b :=
rfl
lemma homothety_one_half {k : Type*} {V P : Type*} [field k] [char_zero k]
[add_comm_group V] [semimodule k V] [add_torsor V P] (a b : P) :
homothety a (1/2:k) b = midpoint k a b :=
by rw [one_div, homothety_inv_two]
@[simp] lemma pi_midpoint_apply {k ι : Type*} {V : Π i : ι, Type*} {P : Π i : ι, Type*} [field k]
[invertible (2:k)] [Π i, add_comm_group (V i)] [Π i, semimodule k (V i)]
[Π i, add_torsor (V i) (P i)] (f g : Π i, P i) (i : ι) :
midpoint k f g i = midpoint k (f i) (g i) := rfl
namespace add_monoid_hom
variables (R R' : Type*) {E F : Type*}
[ring R] [invertible (2:R)] [add_comm_group E] [semimodule R E]
[ring R'] [invertible (2:R')] [add_comm_group F] [semimodule R' F]
/-- A map `f : E → F` sending zero to zero and midpoints to midpoints is an `add_monoid_hom`. -/
def of_map_midpoint (f : E → F) (h0 : f 0 = 0)
(hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) :
E →+ F :=
{ to_fun := f,
map_zero' := h0,
map_add' := λ x y,
calc f (x + y) = f 0 + f (x + y) : by rw [h0, zero_add]
... = midpoint R' (f 0) (f (x + y)) + midpoint R' (f 0) (f (x + y)) :
(midpoint_add_self _ _ _).symm
... = f (midpoint R x y) + f (midpoint R x y) : by rw [← hm, midpoint_zero_add]
... = f x + f y : by rw [hm, midpoint_add_self] }
@[simp] lemma coe_of_map_midpoint (f : E → F) (h0 : f 0 = 0)
(hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) :
⇑(of_map_midpoint R R' f h0 hm) = f := rfl
end add_monoid_hom
|
0bcdcaea67b8eb1398a36022565149dfcf348614
|
2b2a05a7af89c79da194505bf88205a6c4e05d68
|
/src/game/world_01_tutorial.lean
|
850bbb94b1f4210205b0b8b5ef9204bcc67f5226
|
[] |
no_license
|
lacrosse/natural_number_game
|
6401a11a8c965da3903ae6695f84586edf6fac85
|
400179cde1d3fcc9744901dabff98813ba2b544f
|
refs/heads/master
| 1,677,566,006,582
| 1,612,576,917,000
| 1,612,576,917,000
| 335,655,947
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 485
|
lean
|
import mynat.definition
import mynat.mul
namespace mynat
lemma example1 (x y z : mynat) : x * y + z = x * y + z := begin[nat_num_game]
refl,
end
lemma example2 (x y : mynat) (h : y = x + 7) : 2 * y = 2 * (x + 7) := begin[nat_num_game]
rwa h,
end
lemma example3 (a b : mynat) (h : succ a = b) : succ(succ(a)) = succ(b) := begin[nat_num_game]
rwa h,
end
lemma add_succ_zero (a : mynat) : a + succ(0) = succ(a) := begin[nat_num_game]
rwa [add_succ, add_zero],
end
end mynat
|
fb7c2457b76a1f6ea84779319057b9b99fb04a4d
|
48eee836fdb5c613d9a20741c17db44c8e12e61c
|
/src/util/meta/expr_ctx.lean
|
c1cb3d3d0c12aa846f808ccea583197d87ba487f
|
[
"Apache-2.0"
] |
permissive
|
fgdorais/lean-universal
|
06430443a4abe51e303e602684c2977d1f5c0834
|
9259b0f7fb3aa83a9e0a7a3eaa44c262e42cc9b1
|
refs/heads/master
| 1,592,479,744,136
| 1,589,473,399,000
| 1,589,473,399,000
| 196,287,552
| 1
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,274
|
lean
|
-- Copyright © 2019 François G. Dorais. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
import .expr
import .format
meta abbreviation expr_ctx : Type := list (name × expr × binder_info)
namespace expr_ctx
open exceptional
meta def nil : expr_ctx := list.nil
meta def add (ctx : expr_ctx) (n : name) (e : expr) (b : binder_info := binder_info.default) : expr_ctx :=
(n, e, b) :: ctx
meta def pop : expr_ctx → exceptional (expr_ctx × name × expr × binder_info)
| ((n,e,b)::ctx) := success (ctx,n,e,b)
| [] := fail "empty expr_ctx"
meta def get : expr_ctx → exceptional (name × expr × binder_info) :=
λ ctx, ctx.pop >>= λ r, success r.snd
meta def nth : expr_ctx → nat → exceptional (name × expr × binder_info)
| (_ :: ctx) (n+1) := nth ctx n
| (c :: _) 0 := success c
| [] _ := fail "empty expr_ctx"
meta def del : expr_ctx → exceptional expr_ctx :=
λ ctx, ctx.pop >>= λ r, success r.fst
meta def drop : expr_ctx → nat → exceptional expr_ctx
| ctx 0 := success ctx
| ctx (k+1) := del ctx >>= λ ctx, drop ctx k
meta def take : expr_ctx → nat → exceptional expr_ctx
| _ 0 := success nil
| ctx (k+1) :=
ctx.pop >>=
λ ⟨ctx, c⟩, ctx.take k >>=
λ ctx, success $ c :: ctx
meta def app (ctx : expr_ctx) : expr → expr :=
λ e, e.mk_app (expr.mk_num_vars ctx.length).reverse
meta def app_beta (ctx : expr_ctx) : expr → expr :=
λ e, e.mk_app_beta (expr.mk_num_vars ctx.length).reverse
meta def insert_aux : expr_ctx → nat → name × expr × binder_info → exceptional expr_ctx
| ctx (k+1) :=
λ c, ctx.pop >>=
λ ⟨ctx, n, t, b⟩, insert_aux ctx k c >>=
λ ctx, success $ ctx.add n (t.lift_vars k 1) b
| ctx 0 :=
λ ⟨n, t, b⟩, success $ ctx.add n t b
meta def insert (ctx : expr_ctx) (i : nat) (n : name) (t : expr) (b : binder_info := binder_info.default) :
exceptional expr_ctx := insert_aux ctx i (n, t.lower_vars 0 i, b)
meta def delete : expr_ctx → nat → exceptional expr_ctx
| ctx (k+1) :=
ctx.pop >>=
λ ⟨ctx, n, t, b⟩, delete ctx k >>=
λ ctx, success $ ctx.add n (t.lower_vars k 1) b
| ctx 0 := ctx.del
meta def collect_univ_params (ctx : expr_ctx) : list name :=
ctx.foldl (λ us ⟨_,e,_⟩, e.collect_univ_params.foldr list.insert us) []
meta def implicitize : expr_ctx → expr_ctx
| [] := []
| ((n,t,binder_info.default)::ctx) := (n,t,binder_info.implicit) :: implicitize ctx
| (c::ctx) := c :: implicitize ctx
meta def lam : expr_ctx → expr → expr
| [] e := e
| ((n,t,_)::ctx) e := lam ctx (expr.lam n binder_info.default t e)
meta def mk_lam : expr_ctx → nat → expr → exceptional expr :=
λ ctx k e, ctx.take k >>= λ ctx, success $ ctx.lam e
meta def pi : expr_ctx → expr → expr
| [] e := e
| ((n,t,b)::ctx) e := pi ctx (expr.pi n b t e)
meta def mk_pi : expr_ctx → nat → expr → exceptional expr :=
λ ctx k e, ctx.take k >>= λ ctx, success $ ctx.pi e
meta def get_ctx_lam_aux : expr → expr_ctx → expr × expr_ctx
| (expr.lam n b t e) ctx := get_ctx_lam_aux e ((n, t, b) :: ctx)
| e ctx := (e, ctx)
meta def get_ctx_lam : expr → expr × expr_ctx :=
λ e, get_ctx_lam_aux e nil
meta def get_ctx_pi_aux : expr → expr_ctx → expr × expr_ctx
| (expr.pi n b t e) ctx := get_ctx_pi_aux e ((n, t, b) :: ctx)
| e ctx := (e, ctx)
meta def get_ctx_pi : expr → expr × expr_ctx := λ e, get_ctx_pi_aux e nil
meta def lift_vars : expr_ctx → nat → nat → expr_ctx
| [] _ _ := []
| ((n,e,b)::ctx) s i := (n, e.lift_vars s i, b) :: lift_vars ctx (s+1) i
meta def lower_vars : expr_ctx → nat → nat → expr_ctx
| [] _ _ := []
| ((n,e,b)::ctx) s d := (n, e.lower_vars s d, b) :: lower_vars ctx (s+1) d
meta def mk_local (upfx : name) : expr_ctx → list expr
| [] := []
| ((n,t,b)::ctx) :=
let loc := mk_local ctx in
let t := t.instantiate_vars loc in
expr.local_const (mk_num_name upfx ctx.length) n b t :: loc
meta def ref_aux : expr_ctx → name → nat → exceptional nat
| [] n _ := fail $ "name " ++ n.to_string ++ " not found in expr_ctx"
| (c::ctx) n k := if c.fst = n then success k else ref_aux ctx n (k+1)
meta def ref : expr_ctx → name → exceptional nat :=
λ ctx n, ctx.ref_aux n 0
meta def ref_var : expr_ctx → name → exceptional expr :=
λ ctx n, ctx.ref n >>= λ k, success $ expr.var k
meta def refs (ctx : expr_ctx) : list name → exceptional (list nat)
| [] := success []
| (n::ns) := ctx.ref n >>= λ k, refs ns >>= λ ks, success $ k :: ks
meta def ref_vars : expr_ctx → list name → exceptional (list expr) :=
λ ctx ns, ctx.refs ns >>= λ ks, success $ ks.map expr.var
meta def expr_to_fmt (ctx : expr_ctx) : expr → format
| (expr.var i) :=
match ctx.nth i with
| success ⟨n,_⟩ := to_fmt n
| exception _ := "#" ++ to_fmt (i - ctx.length)
end
| (expr.sort l) := "Sort " ++ format.paren (to_fmt l)
| (expr.app a b) := expr_to_fmt a ++ " " ++ format.paren (expr_to_fmt b)
| (expr.pi n b t e) := "Π " ++ b.to_fmt (to_fmt n ++ " : " ++ expr_to_fmt t) ++ ", " ++ expr_to_fmt e
| (expr.lam n b t e) := "λ " ++ b.to_fmt (to_fmt n ++ " : " ++ expr_to_fmt t) ++ ", " ++ expr_to_fmt e
| (expr.local_const _ n b t) := b.to_fmt (to_fmt n ++ " : " ++ expr_to_fmt t)
| (expr.elet n t v e) := "let " ++ to_fmt n ++ " : " ++ expr_to_fmt t ++ " := " ++ expr_to_fmt v ++ " in " ++ expr_to_fmt e
| (expr.mvar n _ t) := format.paren (to_fmt n ++ " : " ++ expr_to_fmt t)
| (expr.const n l) := "@" ++ to_fmt n ++ "." ++ format.cbrace (format.join (list.intersperse format.space (l.map to_fmt)))
| (expr.macro m e) := to_fmt (expr.macro_def_name m) ++ format.sbracket (format.join $ list.intersperse ", " $ e.map expr_to_fmt)
meta def expr_to_string (ctx : expr_ctx) (e : expr) : string := to_string $ ctx.expr_to_fmt e
meta def to_format : expr_ctx → format
| (⟨n, t, b⟩ :: ctx) := to_format ctx ++ format.space ++ b.to_fmt (to_fmt n ++ " : " ++ expr_to_fmt ctx t)
| [] := ""
meta def to_format_num : expr_ctx → nat → format
| (⟨n, t, b⟩ :: ctx) (p+1) := to_format_num ctx p ++ format.space ++ b.to_fmt (to_fmt n ++ " : " ++ expr_to_fmt ctx t)
| _ 0 := ""
| [] _ := ""
end expr_ctx
meta def tactic.mk_local_ctx : expr_ctx → tactic (list expr) :=
λ ctx, tactic.mk_fresh_name >>= λ upfx, return $ expr_ctx.mk_local upfx ctx
|
607542c707d7903a14538c9c6d7da4ec750c68a8
|
a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7
|
/src/geometry/manifold/smooth_manifold_with_corners.lean
|
c52dde4513a47ae57fa886f56af1315856c54743
|
[
"Apache-2.0"
] |
permissive
|
kmill/mathlib
|
ea5a007b67ae4e9e18dd50d31d8aa60f650425ee
|
1a419a9fea7b959317eddd556e1bb9639f4dcc05
|
refs/heads/master
| 1,668,578,197,719
| 1,593,629,163,000
| 1,593,629,163,000
| 276,482,939
| 0
| 0
| null | 1,593,637,960,000
| 1,593,637,959,000
| null |
UTF-8
|
Lean
| false
| false
| 29,026
|
lean
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.calculus.times_cont_diff
import geometry.manifold.charted_space
/-!
# Smooth manifolds (possibly with boundary or corners)
A smooth manifold is a manifold modelled on a normed vector space, or a subset like a
half-space (to get manifolds with boundaries) for which the changes of coordinates are smooth maps.
We define a model with corners as a map `I : H → E` embedding nicely the topological space `H` in
the vector space `E` (or more precisely as a structure containing all the relevant properties).
Given such a model with corners `I` on `(E, H)`, we define the groupoid of local
homeomorphisms of `H` which are smooth when read in `E` (for any regularity `n : with_top ℕ`).
With this groupoid at hand and the general machinery of charted spaces, we thus get the notion
of `C^n` manifold with respect to any model with corners `I` on `(E, H)`. We also introduce a
specific type class for `C^∞` manifolds as these are the most commonly used.
## Main definitions
* `model_with_corners 𝕜 E H` :
a structure containing informations on the way a space `H` embeds in a
model vector space E over the field `𝕜`. This is all that is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
* `model_with_corners_self 𝕜 E` :
trivial model with corners structure on the space `E` embedded in itself by the identity.
* `times_cont_diff_groupoid n I` :
when `I` is a model with corners on `(𝕜, E, H)`, this is the groupoid of local homeos of `H`
which are of class `C^n` over the normed field `𝕜`, when read in `E`.
* `smooth_manifold_with_corners I M` :
a type class saying that the charted space `M`, modelled on the space `H`, has `C^∞` changes of
coordinates with respect to the model with corners `I` on `(𝕜, E, H)`. This type class is just
a shortcut for `has_groupoid M (times_cont_diff_groupoid ⊤ I)`.
* `ext_chart_at I x`:
in a smooth manifold with corners with the model `I` on `(E, H)`, the charts take values in `H`,
but often we may want to use their `E`-valued version, obtained by composing the charts with `I`.
Since the target is in general not open, we can not register them as local homeomorphisms, but
we register them as local equivs. `ext_chart_at I x` is the canonical such local equiv around `x`.
As specific examples of models with corners, we define (in the file `real_instances.lean`)
* `model_with_corners_self ℝ (euclidean_space (fin n))` for the model space used to define
`n`-dimensional real manifolds without boundary (with notation `𝓡 n` in the locale `manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_half_space n)` for the model space
used to define `n`-dimensional real manifolds with boundary (with notation `𝓡∂ n` in the locale
`manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
With these definitions at hand, to invoke an `n`-dimensional real manifold without boundary,
one could use
`variables {n : ℕ} {M : Type*} [topological_space M] [charted_space (euclidean_space (fin n)) M]
[smooth_manifold_with_corners (𝓡 n) M]`.
However, this is not the recommended way: a theorem proved using this assumption would not apply
for instance to the tangent space of such a manifold, which is modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin n))` and not on `euclidean_space (fin (2 * n))`!
In the same way, it would not apply to product manifolds, modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin m))`.
The right invocation does not focus on one specific construction, but on all constructions sharing
the right properties, like
`variables {E : Type*} [normed_group E] [normed_space ℝ E] [finite_dimensional ℝ E]
{I : model_with_corners ℝ E E} [I.boundaryless]
{M : Type*} [topological_space M] [charted_space E M] [smooth_manifold_with_corners I M]`
Here, `I.boundaryless` is a typeclass property ensuring that there is no boundary (this is for
instance the case for `model_with_corners_self`, or products of these). Note that one could consider
as a natural assumption to only use the trivial model with corners `model_with_corners_self ℝ E`,
but again in product manifolds the natural model with corners will not be this one but the product
one (and they are not defeq as `(λp : E × F, (p.1, p.2))` is not defeq to the identity). So, it is
important to use the above incantation to maximize the applicability of theorems.
## Implementation notes
We want to talk about manifolds modelled on a vector space, but also on manifolds with
boundary, modelled on a half space (or even manifolds with corners). For the latter examples,
we still want to define smooth functions, tangent bundles, and so on. As smooth functions are
well defined on vector spaces or subsets of these, one could take for model space a subtype of a
vector space. With the drawback that the whole vector space itself (which is the most basic
example) is not directly a subtype of itself: the inclusion of `univ : set E` in `set E` would
show up in the definition, instead of `id`.
A good abstraction covering both cases it to have a vector
space `E` (with basic example the Euclidean space), a model space `H` (with basic example the upper
half space), and an embedding of `H` into `E` (which can be the identity for `H = E`, or
`subtype.val` for manifolds with corners). We say that the pair `(E, H)` with their embedding is a
model with corners, and we encompass all the relevant properties (in particular the fact that the
image of `H` in `E` should have unique differentials) in the definition of `model_with_corners`.
We concentrate on `C^∞` manifolds: all the definitions work equally well for `C^n` manifolds, but
later on it is a pain to carry all over the smoothness parameter, especially when one wants to deal
with `C^k` functions as there would be additional conditions `k ≤ n` everywhere. Since one deals
almost all the time with `C^∞` (or analytic) manifolds, this seems to be a reasonable choice that
one could revisit later if needed. `C^k` manifolds are still available, but they should be called
using `has_groupoid M (times_cont_diff_groupoid k I)` where `I` is the model with corners.
I have considered using the model with corners `I` as a typeclass argument, possibly `out_param`, to
get lighter notations later on, but it did not turn out right, as on `E × F` there are two natural
model with corners, the trivial (identity) one, and the product one, and they are not defeq and one
needs to indicate to Lean which one we want to use.
This means that when talking on objects on manifolds one will most often need to specify the model
with corners one is using. For instance, the tangent bundle will be `tangent_bundle I M` and the
derivative will be `mfderiv I I' f`, instead of the more natural notations `tangent_bundle 𝕜 M` and
`mfderiv 𝕜 f` (the field has to be explicit anyway, as some manifolds could be considered both as
real and complex manifolds).
-/
noncomputable theory
universes u v w u' v' w'
open set
section model_with_corners
/-! ### Models with corners. -/
/-- A structure containing informations on the way a space `H` embeds in a
model vector space `E` over the field `𝕜`. This is all what is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
-/
@[nolint has_inhabited_instance]
structure model_with_corners (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] (H : Type*) [topological_space H]
extends local_equiv H E :=
(source_eq : source = univ)
(unique_diff' : unique_diff_on 𝕜 (range to_fun))
(continuous_to_fun : continuous to_fun)
(continuous_inv_fun : continuous inv_fun)
attribute [simp, mfld_simps] model_with_corners.source_eq
/-- A vector space is a model with corners. -/
def model_with_corners_self (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] : model_with_corners 𝕜 E E :=
{ to_fun := id,
inv_fun := id,
source := univ,
target := univ,
source_eq := rfl,
map_source' := λ_ _, mem_univ _,
map_target' := λ_ _, mem_univ _,
left_inv' := λ_ _, rfl,
right_inv' := λ_ _, rfl,
unique_diff' := by { rw range_id, exact unique_diff_on_univ },
continuous_to_fun := continuous_id,
continuous_inv_fun := continuous_id }
section
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
instance : has_coe_to_fun (model_with_corners 𝕜 E H) := ⟨_, λ e, e.to_fun⟩
/-- The inverse to a model with corners, only registered as a local equiv. -/
protected def model_with_corners.symm : local_equiv E H := I.to_local_equiv.symm
/- Register a few lemmas to make sure that `simp` puts expressions in normal form -/
@[simp, mfld_simps] lemma model_with_corners.to_local_equiv_coe : (I.to_local_equiv : H → E) = I := rfl
@[simp, mfld_simps] lemma model_with_corners.mk_coe (e : local_equiv H E) (a b c d) :
((model_with_corners.mk e a b c d : model_with_corners 𝕜 E H) : H → E) = (e : H → E) := rfl
@[simp, mfld_simps] lemma model_with_corners.to_local_equiv_coe_symm :
(I.to_local_equiv.symm : E → H) = I.symm := rfl
@[simp, mfld_simps] lemma model_with_corners.mk_coe_symm (e : local_equiv H E) (a b c d) :
((model_with_corners.mk e a b c d : model_with_corners 𝕜 E H).symm : E → H) = (e.symm : E → H) :=
rfl
lemma model_with_corners.unique_diff : unique_diff_on 𝕜 (range I) := I.unique_diff'
protected lemma model_with_corners.continuous : continuous I := I.continuous_to_fun
lemma model_with_corners.continuous_symm : continuous I.symm := I.continuous_inv_fun
section
variables (𝕜 E)
/-- In the trivial model with corners, the associated local equiv is the identity. -/
@[simp, mfld_simps] lemma model_with_corners_self_local_equiv :
(model_with_corners_self 𝕜 E).to_local_equiv = local_equiv.refl E := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe :
(model_with_corners_self 𝕜 E : E → E) = id := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe_symm :
((model_with_corners_self 𝕜 E).symm : E → E) = id := rfl
end
@[simp, mfld_simps] lemma model_with_corners.target : I.target = range (I : H → E) :=
by { rw [← image_univ, ← I.source_eq], exact (I.to_local_equiv.image_source_eq_target).symm }
@[simp, mfld_simps] lemma model_with_corners.left_inv (x : H) : I.symm (I x) = x :=
by { convert I.left_inv' _, simp }
@[simp, mfld_simps] lemma model_with_corners.left_inv' : I.symm ∘ I = id :=
by { ext x, exact model_with_corners.left_inv _ _ }
@[simp, mfld_simps] lemma model_with_corners.right_inv {x : E} (hx : x ∈ range I) :
I (I.symm x) = x :=
by { apply I.right_inv', simp [hx] }
lemma model_with_corners.image (s : set H) :
I '' s = I.symm ⁻¹' s ∩ range I :=
begin
ext x,
simp only [mem_image, mem_inter_eq, mem_range, mem_preimage],
split,
{ rintros ⟨y, ⟨ys, hy⟩⟩,
rw ← hy,
simp only [ys, true_and, model_with_corners.left_inv],
exact ⟨y, rfl⟩ },
{ rintros ⟨xs, ⟨y, yx⟩⟩,
rw ← yx at xs,
simp only [model_with_corners.left_inv] at xs,
exact ⟨y, ⟨xs, yx⟩⟩ }
end
lemma model_with_corners.unique_diff_preimage {s : set H} (hs : is_open s) :
unique_diff_on 𝕜 (I.symm ⁻¹' s ∩ range I) :=
by { rw inter_comm, exact I.unique_diff.inter (I.continuous_inv_fun _ hs) }
lemma model_with_corners.unique_diff_preimage_source {β : Type*} [topological_space β]
{e : local_homeomorph H β} : unique_diff_on 𝕜 (I.symm ⁻¹' (e.source) ∩ range I) :=
I.unique_diff_preimage e.open_source
lemma model_with_corners.unique_diff_at_image {x : H} : unique_diff_within_at 𝕜 (range I) (I x) :=
I.unique_diff _ (mem_range_self _)
end
/-- Given two model_with_corners `I` on `(E, H)` and `I'` on `(E', H')`, we define the model with
corners `I.prod I'` on `(E × E', H × H')`. This appears in particular for the manifold structure on
the tangent bundle to a manifold modelled on `(E, H)`: it will be modelled on `(E × E, H × E)`. -/
def model_with_corners.prod
{𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H)
{E' : Type v'} [normed_group E'] [normed_space 𝕜 E'] {H' : Type w'} [topological_space H']
(I' : model_with_corners 𝕜 E' H') : model_with_corners 𝕜 (E × E') (H × H') :=
{ to_fun := λp, (I p.1, I' p.2),
inv_fun := λp, (I.symm p.1, I'.symm p.2),
source := (univ : set (H × H')),
target := set.prod (range I) (range I'),
map_source' := λ ⟨x, x'⟩ _, by simp [-mem_range, mem_range_self],
map_target' := λ ⟨x, x'⟩ _, mem_univ _,
left_inv' := λ ⟨x, x'⟩ _, by simp,
right_inv' := λ ⟨x, x'⟩ ⟨hx, hx'⟩, by simp [hx, hx'],
source_eq := rfl,
unique_diff' := begin
have : range (λ(p : H × H'), (I p.1, I' p.2)) = set.prod (range I) (range I'),
by { rw ← prod_range_range_eq },
rw this,
exact unique_diff_on.prod I.unique_diff I'.unique_diff,
end,
continuous_to_fun := (continuous.comp I.continuous_to_fun continuous_fst).prod_mk
(continuous.comp I'.continuous_to_fun continuous_snd),
continuous_inv_fun := (continuous.comp I.continuous_inv_fun continuous_fst).prod_mk
(continuous.comp I'.continuous_inv_fun continuous_snd) }
/-- Special case of product model with corners, which is trivial on the second factor. This shows up
as the model to tangent bundles. -/
@[reducible] def model_with_corners.tangent
{𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) : model_with_corners 𝕜 (E × E) (H × E) :=
I.prod (model_with_corners_self 𝕜 E)
section boundaryless
/-- Property ensuring that the model with corners `I` defines manifolds without boundary. -/
class model_with_corners.boundaryless {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H) : Prop :=
(range_eq_univ : range I = univ)
/-- The trivial model with corners has no boundary -/
instance model_with_corners_self_boundaryless (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] : (model_with_corners_self 𝕜 E).boundaryless :=
⟨by simp⟩
/-- If two model with corners are boundaryless, their product also is -/
instance model_with_corners.range_eq_univ_prod {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) [I.boundaryless]
{E' : Type v'} [normed_group E'] [normed_space 𝕜 E'] {H' : Type w'} [topological_space H']
(I' : model_with_corners 𝕜 E' H') [I'.boundaryless] :
(I.prod I').boundaryless :=
begin
split,
dsimp [model_with_corners.prod],
rw [← prod_range_range_eq, model_with_corners.boundaryless.range_eq_univ,
model_with_corners.boundaryless.range_eq_univ, univ_prod_univ]
end
end boundaryless
section times_cont_diff_groupoid
/-! ### Smooth functions on models with corners -/
variables {m n : with_top ℕ} {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M]
variable (n)
/-- Given a model with corners `(E, H)`, we define the groupoid of `C^n` transformations of `H` as
the maps that are `C^n` when read in `E` through `I`. -/
def times_cont_diff_groupoid : structure_groupoid H :=
pregroupoid.groupoid
{ property := λf s, times_cont_diff_on 𝕜 n (I ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
comp := λf g u v hf hg hu hv huv, begin
have : I ∘ (g ∘ f) ∘ I.symm = (I ∘ g ∘ I.symm) ∘ (I ∘ f ∘ I.symm),
by { ext x, simp },
rw this,
apply times_cont_diff_on.comp hg _,
{ rintros x ⟨hx1, hx2⟩,
simp only with mfld_simps at ⊢ hx1,
exact hx1.2 },
{ refine hf.mono _,
rintros x ⟨hx1, hx2⟩,
exact ⟨hx1.1, hx2⟩ }
end,
id_mem := begin
apply times_cont_diff_on.congr (times_cont_diff_id.times_cont_diff_on),
rintros x ⟨hx1, hx2⟩,
rcases mem_range.1 hx2 with ⟨y, hy⟩,
rw ← hy,
simp only with mfld_simps,
end,
locality := λf u hu H, begin
apply times_cont_diff_on_of_locally_times_cont_diff_on,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rcases H x hy1 with ⟨v, v_open, xv, hv⟩,
have : ((I.symm ⁻¹' (u ∩ v)) ∩ (range I))
= ((I.symm ⁻¹' u) ∩ (range I) ∩ I.symm ⁻¹' v),
{ rw [preimage_inter, inter_assoc, inter_assoc],
congr' 1,
rw inter_comm },
rw this at hv,
exact ⟨I.symm ⁻¹' v, I.continuous_symm _ v_open, by simpa, hv⟩
end,
congr := λf g u hu fg hf, begin
apply hf.congr,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rw fg _ hy1
end }
variable {n}
/-- Inclusion of the groupoid of `C^n` local diffeos in the groupoid of `C^m` local diffeos when
`m ≤ n` -/
lemma times_cont_diff_groupoid_le (h : m ≤ n) :
times_cont_diff_groupoid n I ≤ times_cont_diff_groupoid m I :=
begin
rw [times_cont_diff_groupoid, times_cont_diff_groupoid],
apply groupoid_of_pregroupoid_le,
assume f s hfs,
exact times_cont_diff_on.of_le hfs h
end
/-- The groupoid of `0`-times continuously differentiable maps is just the groupoid of all
local homeomorphisms -/
lemma times_cont_diff_groupoid_zero_eq :
times_cont_diff_groupoid 0 I = continuous_groupoid H :=
begin
apply le_antisymm le_top,
assume u hu,
-- we have to check that every local homeomorphism belongs to `times_cont_diff_groupoid 0 I`,
-- by unfolding its definition
change u ∈ times_cont_diff_groupoid 0 I,
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
simp only [times_cont_diff_on_zero],
split,
{ apply continuous_on.comp (@continuous.continuous_on _ _ _ _ _ univ I.continuous)
_ (subset_univ _),
apply continuous_on.comp u.continuous_to_fun I.continuous_symm.continuous_on
(inter_subset_left _ _) },
{ apply continuous_on.comp (@continuous.continuous_on _ _ _ _ _ univ I.continuous)
_ (subset_univ _),
apply continuous_on.comp u.continuous_inv_fun I.continuous_inv_fun.continuous_on
(inter_subset_left _ _) },
end
variable (n)
/-- An identity local homeomorphism belongs to the `C^n` groupoid. -/
lemma of_set_mem_times_cont_diff_groupoid {s : set H} (hs : is_open s) :
local_homeomorph.of_set s hs ∈ times_cont_diff_groupoid n I :=
begin
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
suffices h : times_cont_diff_on 𝕜 n (I ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
by simp [h],
have : times_cont_diff_on 𝕜 n id (univ : set E) :=
times_cont_diff_id.times_cont_diff_on,
exact this.congr_mono (λ x hx, by simp [hx.2]) (subset_univ _)
end
/-- The composition of a local homeomorphism from `H` to `M` and its inverse belongs to
the `C^n` groupoid. -/
lemma symm_trans_mem_times_cont_diff_groupoid (e : local_homeomorph M H) :
e.symm.trans e ∈ times_cont_diff_groupoid n I :=
begin
have : e.symm.trans e ≈ local_homeomorph.of_set e.target e.open_target :=
local_homeomorph.trans_symm_self _,
exact structure_groupoid.eq_on_source _
(of_set_mem_times_cont_diff_groupoid n I e.open_target) this
end
end times_cont_diff_groupoid
end model_with_corners
/-! ### Smooth manifolds with corners -/
/-- Typeclass defining smooth manifolds with corners with respect to a model with corners, over a
field `𝕜` and with infinite smoothness to simplify typeclass search and statements later on. -/
class smooth_manifold_with_corners {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M] extends
has_groupoid M (times_cont_diff_groupoid ⊤ I) : Prop
/-- For any model with corners, the model space is a smooth manifold -/
instance model_space_smooth {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
{I : model_with_corners 𝕜 E H} :
smooth_manifold_with_corners I H := {}
namespace smooth_manifold_with_corners
/- We restate in the namespace `smooth_manifolds_with_corners` some lemmas that hold for general
charted space with a structure groupoid, avoiding the need to specify the groupoid
`times_cont_diff_groupoid ⊤ I` explicitly. -/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
/-- The maximal atlas of `M` for the smooth manifold with corners structure corresponding to the
modle with corners `I`. -/
def maximal_atlas := (times_cont_diff_groupoid ⊤ I).maximal_atlas M
variable {M}
lemma compatible [smooth_manifold_with_corners I M]
{e e' : local_homeomorph M H} (he : e ∈ atlas H M) (he' : e' ∈ atlas H M) :
e.symm.trans e' ∈ times_cont_diff_groupoid ⊤ I :=
has_groupoid.compatible _ he he'
lemma mem_maximal_atlas_of_mem_atlas [smooth_manifold_with_corners I M]
{e : local_homeomorph M H} (he : e ∈ atlas H M) : e ∈ maximal_atlas I M :=
structure_groupoid.mem_maximal_atlas_of_mem_atlas _ he
lemma chart_mem_maximal_atlas [smooth_manifold_with_corners I M] (x : M) :
chart_at H x ∈ maximal_atlas I M :=
structure_groupoid.chart_mem_maximal_atlas _ x
variable {I}
lemma compatible_of_mem_maximal_atlas
{e e' : local_homeomorph M H} (he : e ∈ maximal_atlas I M) (he' : e' ∈ maximal_atlas I M) :
e.symm.trans e' ∈ times_cont_diff_groupoid ⊤ I :=
structure_groupoid.compatible_of_mem_maximal_atlas he he'
end smooth_manifold_with_corners
section extended_charts
open_locale topological_space
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M]
(x : M) {s t : set M}
/-!
### Extended charts
In a smooth manifold with corners, the model space is the space `H`. However, we will also
need to use extended charts taking values in the model vector space `E`. These extended charts are
not `local_homeomorph` as the target is not open in `E` in general, but we can still register them
as `local_equiv`.
-/
/-- The preferred extended chart on a manifold with corners around a point `x`, from a neighborhood
of `x` to the model vector space. -/
@[simp, mfld_simps] def ext_chart_at (x : M) : local_equiv M E :=
(chart_at H x).to_local_equiv.trans I.to_local_equiv
lemma ext_chart_at_source : (ext_chart_at I x).source = (chart_at H x).source :=
by rw [ext_chart_at, local_equiv.trans_source, I.source_eq, preimage_univ, inter_univ]
lemma ext_chart_at_open_source : is_open (ext_chart_at I x).source :=
by { rw ext_chart_at_source, exact (chart_at H x).open_source }
lemma mem_ext_chart_source : x ∈ (ext_chart_at I x).source :=
by simp only with mfld_simps
lemma ext_chart_at_to_inv :
(ext_chart_at I x).symm ((ext_chart_at I x) x) = x :=
by simp only with mfld_simps
lemma ext_chart_at_source_mem_nhds : (ext_chart_at I x).source ∈ 𝓝 x :=
mem_nhds_sets (ext_chart_at_open_source I x) (mem_ext_chart_source I x)
lemma ext_chart_at_continuous_on :
continuous_on (ext_chart_at I x) (ext_chart_at I x).source :=
begin
refine continuous_on.comp I.continuous.continuous_on _ subset_preimage_univ,
rw ext_chart_at_source,
exact (chart_at H x).continuous_on
end
lemma ext_chart_at_continuous_at :
continuous_at (ext_chart_at I x) x :=
(ext_chart_at_continuous_on I x x (mem_ext_chart_source I x)).continuous_at
(ext_chart_at_source_mem_nhds I x)
lemma ext_chart_at_continuous_on_symm :
continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target :=
begin
apply continuous_on.comp (chart_at H x).continuous_on_symm I.continuous_symm.continuous_on,
simp [ext_chart_at, local_equiv.trans_target]
end
lemma ext_chart_at_target_mem_nhds_within :
(ext_chart_at I x).target ∈ nhds_within ((ext_chart_at I x) x) (range I) :=
begin
rw [ext_chart_at, local_equiv.trans_target],
simp only [function.comp_app, local_equiv.coe_trans, model_with_corners.target],
refine inter_mem_nhds_within _
(mem_nhds_sets (I.continuous_symm _ (chart_at H x).open_target) _),
simp only with mfld_simps
end
lemma ext_chart_at_coe (p : M) : (ext_chart_at I x) p = I ((chart_at H x : M → H) p) := rfl
lemma ext_chart_at_coe_symm (p : E) :
(ext_chart_at I x).symm p = ((chart_at H x).symm : H → M) (I.symm p) := rfl
lemma nhds_within_ext_chart_target_eq :
nhds_within ((ext_chart_at I x) x) (ext_chart_at I x).target =
nhds_within ((ext_chart_at I x) x) (range I) :=
begin
apply le_antisymm,
{ apply nhds_within_mono,
simp only with mfld_simps},
{ apply nhds_within_le_of_mem (ext_chart_at_target_mem_nhds_within _ _) }
end
lemma ext_chart_continuous_at_symm' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
continuous_at (ext_chart_at I x).symm ((ext_chart_at I x) x') :=
begin
apply continuous_at.comp,
{ rw ext_chart_at_source at h,
simp only with mfld_simps,
exact ((chart_at H x).continuous_on_symm _
((chart_at H x).map_source h)).continuous_at
(mem_nhds_sets (chart_at H x).open_target
((chart_at H x).map_source h)) },
{ exact I.continuous_symm.continuous_at }
end
lemma ext_chart_continuous_at_symm :
continuous_at (ext_chart_at I x).symm ((ext_chart_at I x) x) :=
ext_chart_continuous_at_symm' I x (mem_ext_chart_source I x)
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
in the source is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source)
(ht : t ∈ nhds_within x' s) :
(ext_chart_at I x).symm ⁻¹' t ∈ nhds_within ((ext_chart_at I x) x')
((ext_chart_at I x).symm ⁻¹' s ∩ range I) :=
begin
apply (ext_chart_continuous_at_symm' I x h).continuous_within_at.tendsto_nhds_within_image,
rw (ext_chart_at I x).left_inv h,
apply nhds_within_mono _ _ ht,
have : (ext_chart_at I x).symm '' ((ext_chart_at I x).symm ⁻¹' s) ⊆ s :=
image_preimage_subset _ _,
exact subset.trans (image_subset _ (inter_subset_left _ _)) this
end
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of the
base point is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within (ht : t ∈ nhds_within x s) :
(ext_chart_at I x).symm ⁻¹' t ∈ nhds_within ((ext_chart_at I x) x)
((ext_chart_at I x).symm ⁻¹' s ∩ range I) :=
ext_chart_preimage_mem_nhds_within' I x (mem_ext_chart_source I x) ht
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
is a neighborhood of the preimage. -/
lemma ext_chart_preimage_mem_nhds (ht : t ∈ 𝓝 x) :
(ext_chart_at I x).symm ⁻¹' t ∈ 𝓝 ((ext_chart_at I x) x) :=
begin
apply (ext_chart_continuous_at_symm I x).preimage_mem_nhds,
rwa (ext_chart_at I x).left_inv (mem_ext_chart_source _ _)
end
/-- Technical lemma to rewrite suitably the preimage of an intersection under an extended chart, to
bring it into a convenient form to apply derivative lemmas. -/
lemma ext_chart_preimage_inter_eq : ((ext_chart_at I x).symm ⁻¹' (s ∩ t) ∩ range I)
= ((ext_chart_at I x).symm ⁻¹' s ∩ range I)
∩ ((ext_chart_at I x).symm ⁻¹' t) :=
begin
rw [preimage_inter, inter_assoc, inter_assoc],
congr' 1,
rw inter_comm
end
end extended_charts
/-- In the case of the manifold structure on a vector space, the extended charts are just the
identity.-/
lemma ext_chart_model_space_eq_id (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] (x : E) :
ext_chart_at (model_with_corners_self 𝕜 E) x = local_equiv.refl E :=
by simp only with mfld_simps
|
58198d89f8eb1421f24a090e65634fd8b2bf7849
|
78269ad0b3c342b20786f60690708b6e328132b0
|
/src/library_dev/tools/auto/finish.lean
|
3314f0a81f30c1323a2ce5f8aa1fd3fe9873da59
|
[] |
no_license
|
dselsam/library_dev
|
e74f46010fee9c7b66eaa704654cad0fcd2eefca
|
1b4e34e7fb067ea5211714d6d3ecef5132fc8218
|
refs/heads/master
| 1,610,372,841,675
| 1,497,014,421,000
| 1,497,014,421,000
| 86,526,137
| 0
| 0
| null | 1,490,752,133,000
| 1,490,752,132,000
| null |
UTF-8
|
Lean
| false
| false
| 13,805
|
lean
|
/-
Copyright (c) 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
These tactics do straightforward things: they call the simplifier, split conjunctive assumptions,
eliminate existential quantifiers on the left, and look for contradictions. They rely on ematching
and congruence closure to try to finish off a goal at the end.
The procedures *do* split on disjunctions and recreate the smt state for each terminal call, so
they are only meant to be used on small, straightforward problems.
(For more substantial automation, I will experiment with a procedure that does similar things but
says within a single smt state, uses e-matching to chain forward with new facts, and splits
only as a last resort.)
We provide the following tactics:
finish -- solves the goal or fails
clarify -- makes as much progress as possible while not leaving more than one goal
safe -- splits freely, finishes off whatever subgoals it can, and leaves the rest
All can take a list of simplifier rules, typically definitions that should be expanded.
(The equations and identities should not refer to the local context.)
The variants ifinish, iclarify, and isafe restrict to intuitionistic logic. They do not work
well with the current heuristic instantiation method used by ematch, so they should be revisited
when the API changes.
-/
import ..tactic.simp_tactic ...logic.basic
open tactic expr
-- TODO(Jeremy): move these
theorem implies_and_iff (p q r : Prop) : (p → q ∧ r) ↔ (p → q) ∧ (p → r) :=
iff.intro (λ h, ⟨λ hp, (h hp).left, λ hp, (h hp).right⟩) (λ h hp, ⟨h.left hp, h.right hp⟩)
theorem curry_iff (p q r : Prop) : (p ∧ q → r) ↔ (p → q → r) :=
iff.intro (λ h hp hq, h ⟨hp, hq⟩) (λ h ⟨hp, hq⟩, h hp hq)
theorem iff_def (p q : Prop) : (p ↔ q) ↔ (p → q) ∧ (q → p) :=
⟨ λh, ⟨h.1, h.2⟩, λ ⟨h₁, h₂⟩, ⟨h₁, h₂⟩ ⟩
theorem {u} bexists_def {α : Type u} (p q : α → Prop) : (∃ x (h : p x), q x) ↔ ∃ x, p x ∧ q x :=
⟨λ ⟨x, px, qx⟩, ⟨x, px, qx⟩, λ ⟨x, px, qx⟩, ⟨x, px, qx⟩⟩
-- theorem {u} forall_def {α : Type u} (p q : α → Prop) : (∀ x (h : p x), q x) ↔ ∀ x, p x → q x :=
-- iff.refl _
namespace auto
/- Utilities -/
meta def whnf_reducible (e : expr) : tactic expr := whnf e reducible
-- stolen from interactive.lean
private meta def add_simps : simp_lemmas → list name → tactic simp_lemmas
| s [] := return s
| s (n::ns) := do s' ← s.add_simp n, add_simps s' ns
/-
Configuration information for the auto tactics.
-/
structure auto_config : Type :=
(use_simp := tt) -- call the simplifier
(classical := tt) -- use classical logic
/-
Preprocess goal.
We want to move everything to the left of the sequent arrow. For intuitionistic logic,
we replace the goal p with ∀ f, (p → f) → f and introduce.
-/
theorem by_contradiction_trick (p : Prop) (h : ∀ f : Prop, (p → f) → f) : p :=
h p id
meta def preprocess_goal (cfg : auto_config) : tactic unit :=
do repeat (intro1 >> skip),
tgt ← target >>= whnf_reducible,
if (¬ (is_false tgt)) then
if cfg.classical then
(mk_mapp ``classical.by_contradiction [some tgt]) >>= apply >> intro1 >> skip
else
(mk_mapp ``decidable.by_contradiction [some tgt, none] >>= apply >> intro1 >> skip) <|>
applyc ``by_contradiction_trick >> intro1 >> intro1 >> skip
else
skip
/-
Normalize hypotheses. Bring conjunctions to the outside (for splitting), bring universal quantifiers to the
outside (for ematching). The classical normalizer eliminates a → b in favor of ¬ a ∨ b.
TODO (Jeremy): using the simplifier this way is inefficient. In particular, negations should be
eliminated from the top down. Use ext_simplify_core instead.
-/
def logic_eval_simps : list name :=
[ ``not_true, ``not_false,
``or_true, ``or_false, ``true_or, ``false_or,
``true_and, ``and_true, ``false_and, ``and_false,
``true_implies_iff, ``false_implies_iff, ``implies_true_iff, ``implies_false_iff]
-- note: with current normalization procedure, or distribs cause exponential blowup
def common_normalize_lemma_names : list name :=
logic_eval_simps ++
[``and_assoc, ``or_assoc,
-- unfold bounded quantifiers
``bexists_def,
-- negations
``not_or_iff,
``not_exists_iff_forall_not,
-- bring out conjunctions
``or_implies_distrib, -- ((a ∨ b) → c) ↔ ((a → c) ∧ (b → c))
``implies_and_iff, -- (a → b ∧ c) ↔ (a → b) ∧ (a → c))
-- ``or_distrib,
-- ``or_distrib_right,
``forall_and_distrib,
-- bring out universal quantifiers
``exists_implies_distrib,
-- good for intuitionistic logic
``curry_iff]
def classical_normalize_lemma_names : list name :=
common_normalize_lemma_names ++
[ -- negations
``classical.not_not_iff,
``classical.not_and_iff,
``classical.not_forall_iff_exists_not,
-- implication
``classical.implies_iff_not_or]
meta def normalize_hyp (simps : simp_lemmas) (h : expr) : tactic expr :=
do htype ← infer_type h,
mcond (is_prop htype)
((do (new_htype, heq) ← simplify simps htype,
newh ← assert (expr.local_pp_name h) new_htype,
mk_eq_mp heq h >>= exact,
try $ clear h,
return newh) <|> return h)
(return h)
meta def normalize_hyps (cfg : auto_config) : tactic unit :=
do simps ← if cfg.classical then
add_simps simp_lemmas.mk classical_normalize_lemma_names
else
add_simps simp_lemmas.mk common_normalize_lemma_names,
local_context >>= monad.mapm' (normalize_hyp simps)
/-
Eliminate existential quantifiers.
-/
-- eliminate an existential quantifier if there is one
meta def eelim : tactic unit :=
do ctx ← local_context,
first $ ctx.for $ λ h,
do t ← infer_type h >>= whnf_reducible,
guard (is_app_of t ``Exists),
to_expr ``(exists.elim %%h) >>= apply >> intros >> clear h
-- eliminate all existential quantifiers, fails if there aren't any
meta def eelims : tactic unit := eelim >> repeat eelim
/-
Substitute if there is a hypothesis x = t or t = x.
-/
-- carries out a subst if there is one, fails otherwise
meta def do_subst : tactic unit :=
do ctx ← local_context,
first $ ctx.for $ λ h,
do t ← infer_type h >>= whnf_reducible,
match t with
| `(%%a = %%b) := subst h
| _ := failed
end
meta def do_substs : tactic unit := do_subst >> repeat do_subst
/-
Split all conjunctions.
-/
-- Assumes pr is a proof of t. Adds the consequences of t to the context
-- and returns tt if anything nontrivial has been added.
meta def add_conjuncts : expr → expr → tactic bool :=
λ pr t,
let assert_consequences := λ e t, mcond (add_conjuncts e t) skip (assertv_fresh t e >> skip) in
do t' ← whnf_reducible t,
match t' with
| `(%%a ∧ %%b) :=
do e₁ ← mk_app ``and.left [pr],
assert_consequences e₁ a,
e₂ ← mk_app ``and.right [pr],
assert_consequences e₂ b,
return tt
| `(true) :=
do return tt
| _ := return ff
end
-- return tt if any progress is made
meta def split_hyp (h : expr) : tactic bool :=
do t ← infer_type h,
mcond (add_conjuncts h t) (clear h >> return tt) (return ff)
-- return tt if any progress is made
meta def split_hyps_aux : list expr → tactic bool
| [] := return ff
| (h :: hs) := do b₁ ← split_hyp h,
b₂ ← split_hyps_aux hs,
return (b₁ || b₂)
-- fail if no progress is made
meta def split_hyps : tactic unit :=
do ctx ← local_context,
mcond (split_hyps_aux ctx) skip failed
/-
Use each hypothesis to simplify the others. For example, given a and a → b, we get b, and given
a ∨ b ∨ c and ¬ b we get a ∨ c.
TODO(Jeremy): use a version of simp_at_using_hs that takes simp lemmas
-/
meta def self_simplify_hyps_aux : tactic unit :=
do ctx ← local_context,
extra_simps ← mmap mk_const logic_eval_simps,
first $ ctx.for $ λ h,
do t ← infer_type h,
mcond (is_prop t) (simp_at_using_hs h extra_simps >> skip) failed
meta def self_simplify_hyps : tactic unit :=
self_simplify_hyps_aux >> repeat self_simplify_hyps_aux
/-
Eagerly apply all the preprocessing rules.
-/
meta def preprocess_hyps (cfg : auto_config) : tactic unit :=
do repeat (intro1 >> skip),
preprocess_goal cfg,
normalize_hyps cfg,
repeat (do_substs <|> split_hyps <|> eelim <|> self_simplify_hyps)
/-
The terminal tactic, used to try to finish off goals:
- Call the simplifier again.
- Call the contradiction tactic.
- Open an SMT state, and use ematching and congruence closure, with all the universal
statements in the context.
TODO(Jeremy): allow users to specify attribute for ematching lemmas, and maybe
also another list?
-/
meta def mk_hinst_lemmas : list expr → smt_tactic hinst_lemmas
| [] := -- return hinst_lemmas.mk
do get_hinst_lemmas_for_attr `ematch
| (h :: hs) := do his ← mk_hinst_lemmas hs,
t ← infer_type h,
match t with
| (pi _ _ _ _) :=
do t' ← infer_type t,
if t' = `(Prop) then
(do new_lemma ← hinst_lemma.mk h,
return (hinst_lemmas.add his new_lemma)) <|> return his
else return his
| _ := return his
end
meta def done (s : simp_lemmas) (cfg : auto_config := {}) : tactic unit :=
do /- if cfg^.use_simp then simp_all s else skip, -/
contradiction <|>
(solve1 $
(do revert_all,
using_smt
(do smt_tactic.intros,
ctx ← local_context,
hs ← mk_hinst_lemmas ctx,
smt_tactic.repeat (smt_tactic.ematch_using hs >> smt_tactic.try smt_tactic.close))))
/-
Tactics that perform case splits.
-/
inductive case_option
| force -- fail unless all goals are solved
| at_most_one -- leave at most one goal
| accept -- leave as many goals as necessary
private meta def case_cont (s : case_option) (cont : case_option → tactic unit) : tactic unit :=
do match s with
| case_option.force := cont case_option.force >> cont case_option.force
| case_option.at_most_one :=
-- if the first one succeeds, commit to it, and try the second
(mcond (cont case_option.force >> return tt) (cont case_option.at_most_one) skip) <|>
-- otherwise, try the second
(swap >> cont case_option.force >> cont case_option.at_most_one)
| case_option.accept := focus [cont case_option.accept, cont case_option.accept]
end
-- three possible outcomes:
-- finds something to case, the continuations succeed ==> returns tt
-- finds something to case, the continutations fail ==> fails
-- doesn't find anything to case ==> returns ff
meta def case_hyp (h : expr) (s : case_option) (cont : case_option → tactic unit) : tactic bool :=
do t ← infer_type h,
match t with
| `(%%a ∨ %%b) := cases h >> case_cont s cont >> return tt
| _ := return ff
end
meta def case_some_hyp_aux (s : case_option) (cont : case_option → tactic unit) :
list expr → tactic bool
| [] := return ff
| (h::hs) := mcond (case_hyp h s cont) (return tt) (case_some_hyp_aux hs)
meta def case_some_hyp (s : case_option) (cont : case_option → tactic unit) : tactic bool :=
local_context >>= case_some_hyp_aux s cont
/-
The main tactics.
-/
meta def safe_core (s : simp_lemmas) (cfg : auto_config) : case_option → tactic unit :=
λ co,
do if cfg^.use_simp then simp_all s else skip,
preprocess_hyps cfg,
done s cfg <|>
(mcond (case_some_hyp co safe_core)
skip
(match co with
| case_option.force := done s cfg
| case_option.at_most_one := try (done s cfg)
| case_option.accept := try (done s cfg)
end))
meta def clarify (s : simp_lemmas) (cfg : auto_config := {}) : tactic unit := safe_core s cfg case_option.at_most_one
meta def safe (s : simp_lemmas) (cfg : auto_config := {}) : tactic unit := safe_core s cfg case_option.accept
meta def finish (s : simp_lemmas) (cfg : auto_config := {}) : tactic unit := safe_core s cfg case_option.force
meta def iclarify (s : simp_lemmas) (cfg : auto_config := {}) : tactic unit := clarify s {cfg with classical := false}
meta def isafe (s : simp_lemmas) (cfg : auto_config := {}) : tactic unit := safe s {cfg with classical := false}
meta def ifinish (s : simp_lemmas) (cfg : auto_config := {}) : tactic unit := finish s {cfg with classical := false}
end auto
open auto
namespace tactic
namespace interactive
open lean lean.parser interactive interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many
meta def clarify (hs : parse opt_qexpr_list) (cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs [],
auto.clarify s cfg
meta def safe (hs : parse opt_qexpr_list) (cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs [],
auto.safe s cfg
meta def finish (hs : parse opt_qexpr_list) (cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs [],
auto.finish s cfg
meta def iclarify (hs : parse opt_qexpr_list) (cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs [],
auto.iclarify s cfg
meta def isafe (hs : parse opt_qexpr_list) (cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs [],
auto.isafe s cfg
meta def ifinish (hs : parse opt_qexpr_list) (cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs [],
auto.ifinish s cfg
end interactive
end tactic
|
c78e8e6b2cc0c671e1eb070186e8ad8da436890a
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/753.lean
|
50ca97b1e640236453c8b8cc2926a7ff52727bc4
|
[
"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
| 182
|
lean
|
inductive Val
| mk : Nat -> Val
instance : Inhabited Val where
default := Val.mk 0
@[simp]
theorem true_iff_true : True <-> True := Iff.intro (fun _ => trivial) (fun _ => trivial)
|
e3bca1ba89ff6d3a31d27ff536492623b219d291
|
d29d82a0af640c937e499f6be79fc552eae0aa13
|
/src/data/finsupp/basic.lean
|
c0f1be3fbb25c1f90236478c97d3bfc99af42861
|
[
"Apache-2.0"
] |
permissive
|
AbdulMajeedkhurasani/mathlib
|
835f8a5c5cf3075b250b3737172043ab4fa1edf6
|
79bc7323b164aebd000524ebafd198eb0e17f956
|
refs/heads/master
| 1,688,003,895,660
| 1,627,788,521,000
| 1,627,788,521,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 99,899
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Scott Morrison
-/
import data.finset.preimage
import algebra.indicator_function
import algebra.group_action_hom
/-!
# 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 := 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, norm_cast] 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
@[simp, norm_cast] lemma coe_fn_inj {f g : α →₀ M} : (f : α → M) = g ↔ f = g :=
coe_fn_injective.eq_iff
@[simp, norm_cast] lemma coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 :=
by rw [← coe_zero, coe_fn_inj]
@[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]⟩
lemma congr_fun {f g : α →₀ M} (h : f = g) (a : α) : f a = g a :=
congr_fun (congr_arg finsupp.to_fun h) a
@[simp] lemma support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
by exact_mod_cast @function.support_eq_empty_iff _ _ _ f
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, finset.eq_empty_iff_forall_not_mem]
lemma card_support_eq_zero {f : α →₀ M} : card f.support = 0 ↔ f = 0 :=
by simp
instance [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_support (f : α →₀ M) : set.finite (function.support f) :=
f.fun_support_eq.symm ▸ f.support.finite_to_set
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.) -/
@[simps] 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 [decidable (a = a')] : single a b a' = if a = a' then b else 0 :=
by convert 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]
lemma single_eq_pi_single : ⇑(single a b) = pi.single a b :=
single_eq_update
@[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
/-- `finsupp.single a b` is injective in `b`. For the statement that it is injective in `a`, see
`finsupp.single_left_injective` -/
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
/-- `finsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see
`finsupp.single_injective` -/
lemma single_left_injective (h : b ≠ 0) : function.injective (λ a : α, single a b) :=
λ a a' H, (((single_eq_single_iff _ _ _ _).mp H).resolve_right $ λ hb, h hb.1).left
lemma single_left_inj (h : b ≠ 0) : single a b = single a' b ↔ a = a' :=
(single_left_injective h).eq_iff
lemma support_single_ne_bot (i : α) (h : b ≠ 0) :
(single i b).support ≠ ⊥ :=
begin
have : i ∈ (single i b).support := by simpa using h,
intro H,
simpa [H]
end
lemma support_single_disjoint {b' : M} (hb : b ≠ 0) (hb' : b' ≠ 0) {i j : α} :
disjoint (single i b).support (single j b').support ↔ i ≠ j :=
by simpa [support_single_ne_zero, hb, hb'] using ne_comm
@[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']
@[simp] lemma equiv_fun_on_fintype_single [fintype α] (x : α) (m : M) :
(@finsupp.equiv_fun_on_fintype α M _ _) (finsupp.single x m) = pi.single x m :=
by { ext, simp [finsupp.single_eq_pi_single, finsupp.equiv_fun_on_fintype], }
@[simp] lemma equiv_fun_on_fintype_symm_single [fintype α] (x : α) (m : M) :
(@finsupp.equiv_fun_on_fintype α M _ _).symm (pi.single x m) = finsupp.single x m :=
by { ext, simp [finsupp.single_eq_pi_single, finsupp.equiv_fun_on_fintype], }
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
section of_support_finite
variables [has_zero M]
/-- The natural `finsupp` induced by the function `f` given that it has finite support. -/
noncomputable def of_support_finite
(f : α → M) (hf : (function.support f).finite) : α →₀ M :=
{ support := hf.to_finset,
to_fun := f,
mem_support_to_fun := λ _, hf.mem_to_finset }
lemma of_support_finite_coe {f : α → M} {hf : (function.support f).finite} :
(of_support_finite f hf : α → M) = f := rfl
instance : can_lift (α → M) (α →₀ M) :=
{ coe := coe_fn,
cond := λ f, (function.support f).finite,
prf := λ f hf, ⟨of_support_finite f hf, rfl⟩ }
end of_support_finite
/-! ### Declarations about `map_range` -/
section map_range
variables [has_zero M] [has_zero N] [has_zero P]
/-- The composition of `f : M → N` and `g : α →₀ M` is
`map_range f hf g : α →₀ N`, well-defined when `f 0 = 0`.
This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself
bundled:
* `finsupp.map_range.zero_hom`
* `finsupp.map_range.add_monoid_hom`
* `finsupp.map_range.add_equiv`
* `finsupp.map_range.linear_map`
* `finsupp.map_range.linear_equiv`
-/
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]
@[simp] lemma map_range_id (g : α →₀ M) : map_range id rfl g = g :=
ext $ λ _, rfl
lemma map_range_comp
(f : N → P) (hf : f 0 = 0) (f₂ : M → N) (hf₂ : f₂ 0 = 0) (h : (f ∘ f₂) 0 = 0) (g : α →₀ M) :
map_range (f ∘ f₂) h g = map_range f hf (map_range f₂ hf₂ g) :=
ext $ λ _, rfl
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 [D : decidable_eq α] {f : M → N → P} {hf : f 0 0 = 0}
{g₁ : α →₀ M} {g₂ : α →₀ N} : (zip_with f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support :=
by rw subsingleton.elim D; exact 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 }
@[to_additive]
lemma _root_.submonoid.finsupp_prod_mem (S : submonoid N) (f : α →₀ M) (g : α → M → N)
(h : ∀ c, f c ≠ 0 → g c (f c) ∈ S) : f.prod g ∈ S :=
S.prod_mem $ λ i hi, h _ (finsupp.mem_support_iff.mp hi)
end sum_prod
/-!
### Additive monoid structure on `α →₀ M`
-/
section add_zero_class
variables [add_zero_class 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 [decidable_eq α] {g₁ g₂ : α →₀ M} :
(g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
support_zip_with
lemma support_add_eq [decidable_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_zero_class (α →₀ M) :=
{ zero := 0,
add := (+),
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_zero_class 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_zero_class 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 [mul_one_class 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' [mul_one_class 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_zero_class 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_zero_class
section add_monoid
variables [add_monoid M]
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 _ _ _,
nsmul := λ n v, v.map_range ((•) n) (nsmul_zero _),
nsmul_zero' := λ v, by { ext i, simp },
nsmul_succ' := λ n v, by { ext i, simp [nat.succ_eq_one_add, add_nsmul] },
.. finsupp.add_zero_class }
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_nat_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 _,
gsmul := λ n v, v.map_range ((•) n) (gsmul_zero _),
gsmul_zero' := λ v, by { ext i, simp },
gsmul_succ' := λ n v, by { ext i, simp [nat.succ_eq_one_add, add_gsmul] },
gsmul_neg' := λ n v, by { ext i, simp only [nat.succ_eq_add_one, map_range_apply,
gsmul_neg_succ_of_nat, int.coe_nat_succ, neg_inj,
add_gsmul, add_nsmul, one_gsmul, gsmul_coe_nat, one_nsmul] },
.. 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 [decidable_eq β] [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 support_sum_eq_bUnion {α : Type*} {ι : Type*} {M : Type*} [add_comm_monoid M]
{g : ι → α →₀ M} (s : finset ι) (h : ∀ i₁ i₂, i₁ ≠ i₂ → disjoint (g i₁).support (g i₂).support) :
(∑ i in s, g i).support = s.bUnion (λ i, (g i).support) :=
begin
apply finset.induction_on s,
{ simp },
{ intros i s hi,
simp only [hi, sum_insert, not_false_iff, bUnion_insert],
intro hs,
rw [finsupp.support_add_eq, hs],
rw [hs],
intros x hx,
simp only [mem_bUnion, exists_prop, inf_eq_inter, ne.def, mem_inter] at hx,
obtain ⟨hxi, j, hj, hxj⟩ := hx,
have hn : i ≠ j := λ H, hi (H.symm ▸ hj),
apply h _ _ hn,
simp [hxi, hxj] }
end
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
section zero_hom
variables [has_zero M] [has_zero N] [has_zero P]
/-- Composition with a fixed zero-preserving homomorphism is itself an zero-preserving homomorphism
on functions. -/
@[simps]
def map_range.zero_hom (f : zero_hom M N) : zero_hom (α →₀ M) (α →₀ N) :=
{ to_fun := (map_range f f.map_zero : (α →₀ M) → (α →₀ N)),
map_zero' := map_range_zero }
@[simp]
lemma map_range.zero_hom_id :
map_range.zero_hom (zero_hom.id M) = zero_hom.id (α →₀ M) := zero_hom.ext map_range_id
lemma map_range.zero_hom_comp (f : zero_hom N P) (f₂ : zero_hom M N) :
(map_range.zero_hom (f.comp f₂) : zero_hom (α →₀ _) _) =
(map_range.zero_hom f).comp (map_range.zero_hom f₂) :=
zero_hom.ext $ map_range_comp _ _ _ _ _
end zero_hom
section add_monoid_hom
variables [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P]
/--
Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
@[simps]
def map_range.add_monoid_hom (f : M →+ N) : (α →₀ 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 _ _ }
@[simp]
lemma map_range.add_monoid_hom_id :
map_range.add_monoid_hom (add_monoid_hom.id M) = add_monoid_hom.id (α →₀ M) :=
add_monoid_hom.ext map_range_id
lemma map_range.add_monoid_hom_comp (f : N →+ P) (f₂ : M →+ N) :
(map_range.add_monoid_hom (f.comp f₂) : (α →₀ _) →+ _) =
(map_range.add_monoid_hom f).comp (map_range.add_monoid_hom f₂) :=
add_monoid_hom.ext $ map_range_comp _ _ _ _ _
lemma map_range_multiset_sum (f : M →+ N) (m : multiset (α →₀ M)) :
map_range f f.map_zero m.sum = (m.map $ λx, map_range f f.map_zero x).sum :=
(map_range.add_monoid_hom f : (α →₀ _) →+ _).map_multiset_sum _
lemma map_range_finset_sum (f : M →+ N) (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) :=
(map_range.add_monoid_hom f : (α →₀ _) →+ _).map_sum _ _
/-- `finsupp.map_range.add_monoid_hom` as an equiv. -/
@[simps apply]
def map_range.add_equiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) :=
{ to_fun := (map_range f f.map_zero : (α →₀ M) → (α →₀ N)),
inv_fun := (map_range f.symm f.symm.map_zero : (α →₀ N) → (α →₀ M)),
left_inv := λ x, begin
rw ←map_range_comp _ _ _ _; simp_rw add_equiv.symm_comp_self,
{ exact map_range_id _ },
{ refl },
end,
right_inv := λ x, begin
rw ←map_range_comp _ _ _ _; simp_rw add_equiv.self_comp_symm,
{ exact map_range_id _ },
{ refl },
end,
..(map_range.add_monoid_hom f.to_add_monoid_hom) }
@[simp]
lemma map_range.add_equiv_refl :
map_range.add_equiv (add_equiv.refl M) = add_equiv.refl (α →₀ M) :=
add_equiv.ext map_range_id
lemma map_range.add_equiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) :
(map_range.add_equiv (f.trans f₂) : (α →₀ _) ≃+ _) =
(map_range.add_equiv f).trans (map_range.add_equiv f₂) :=
add_equiv.ext $ map_range_comp _ _ _ _ _
lemma map_range.add_equiv_symm (f : M ≃+ N) :
((map_range.add_equiv f).symm : (α →₀ _) ≃+ _) = map_range.add_equiv f.symm :=
add_equiv.ext $ λ x, rfl
end add_monoid_hom
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
@[simp]
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
@[simp]
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)
@[simp] lemma map_domain_equiv_apply {f : α ≃ β} (x : α →₀ M) (a : β) :
map_domain f x a = x (f.symm a) :=
begin
conv_lhs { rw ←f.apply_symm_apply a },
exact map_domain_apply f.injective _ _,
end
/-- `finsupp.map_domain` is an `add_monoid_hom`. -/
@[simps]
def map_domain.add_monoid_hom (f : α → β) : (α →₀ M) →+ (β →₀ M) :=
{ to_fun := map_domain f,
map_zero' := map_domain_zero,
map_add' := λ _ _, map_domain_add}
@[simp]
lemma map_domain.add_monoid_hom_id : map_domain.add_monoid_hom id = add_monoid_hom.id (α →₀ M) :=
add_monoid_hom.ext $ λ _, map_domain_id
lemma map_domain.add_monoid_hom_comp (f : β → γ) (g : α → β) :
(map_domain.add_monoid_hom (f ∘ g) : (α →₀ M) →+ (γ →₀ M)) =
(map_domain.add_monoid_hom f).comp (map_domain.add_monoid_hom g) :=
add_monoid_hom.ext $ λ _, map_domain_comp
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) :=
(map_domain.add_monoid_hom f : (α →₀ M) →+ β →₀ M).map_sum _ _
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)) :=
(map_domain.add_monoid_hom f : (α →₀ M) →+ β →₀ M).map_finsupp_sum _ _
lemma map_domain_support [decidable_eq β] {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
lemma map_domain.add_monoid_hom_comp_map_range [add_comm_monoid N] (f : α → β) (g : M →+ N) :
(map_domain.add_monoid_hom f).comp (map_range.add_monoid_hom g) =
(map_range.add_monoid_hom g).comp (map_domain.add_monoid_hom f) :=
by { ext, simp }
/-- When `g` preserves addition, `map_range` and `map_domain` commute. -/
lemma map_domain_map_range [add_comm_monoid N] (f : α → β) (v : α →₀ M) (g : M → N)
(h0 : g 0 = 0) (hadd : ∀ x y, g (x + y) = g x + g y) :
map_domain f (map_range g h0 v) = map_range g h0 (map_domain f v) :=
let g' : M →+ N := { to_fun := g, map_zero' := h0, map_add' := hadd} in
add_monoid_hom.congr_fun (map_domain.add_monoid_hom_comp_map_range f g') v
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 `equiv_congr_left` -/
section equiv_congr_left
variable [has_zero M]
/-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equiv_map_domain f l : β →₀ M` (computably)
by mapping the support forwards and the function backwards. -/
def equiv_map_domain (f : α ≃ β) (l : α →₀ M) : β →₀ M :=
{ support := l.support.map f.to_embedding,
to_fun := λ a, l (f.symm a),
mem_support_to_fun := λ a, by simp only [finset.mem_map_equiv, mem_support_to_fun]; refl }
@[simp] lemma equiv_map_domain_apply (f : α ≃ β) (l : α →₀ M) (b : β) :
equiv_map_domain f l b = l (f.symm b) := rfl
lemma equiv_map_domain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) :
equiv_map_domain f.symm l a = l (f a) := rfl
@[simp] lemma equiv_map_domain_refl (l : α →₀ M) : equiv_map_domain (equiv.refl _) l = l :=
by ext x; refl
lemma equiv_map_domain_refl' : equiv_map_domain (equiv.refl _) = @id (α →₀ M) :=
by ext x; refl
lemma equiv_map_domain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) :
equiv_map_domain (f.trans g) l = equiv_map_domain g (equiv_map_domain f l) := by ext x; refl
lemma equiv_map_domain_trans' (f : α ≃ β) (g : β ≃ γ) :
@equiv_map_domain _ _ M _ (f.trans g) = equiv_map_domain g ∘ equiv_map_domain f := by ext x; refl
@[simp] lemma equiv_map_domain_single (f : α ≃ β) (a : α) (b : M) :
equiv_map_domain f (single a b) = single (f a) b :=
by ext x; simp only [single_apply, equiv.apply_eq_iff_eq_symm_apply, equiv_map_domain_apply]; congr
@[simp] lemma equiv_map_domain_zero {f : α ≃ β} : equiv_map_domain f (0 : α →₀ M) = (0 : β →₀ M) :=
by ext x; simp only [equiv_map_domain_apply, coe_zero, pi.zero_apply]
lemma equiv_map_domain_eq_map_domain {M} [add_comm_monoid M] (f : α ≃ β) (l : α →₀ M) :
equiv_map_domain f l = map_domain f l := by ext x; simp [map_domain_equiv_apply]
/-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection:
`(α →₀ M) ≃ (β →₀ M)`.
This is the finitely-supported version of `equiv.Pi_congr_left`. -/
def equiv_congr_left (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) :=
by refine ⟨equiv_map_domain f, equiv_map_domain f.symm, λ f, _, λ f, _⟩;
ext x; simp only [equiv_map_domain_apply, equiv.symm_symm,
equiv.symm_apply_apply, equiv.apply_symm_apply]
@[simp] lemma equiv_congr_left_apply (f : α ≃ β) (l : α →₀ M) :
equiv_congr_left f l = equiv_map_domain f l := rfl
@[simp] lemma equiv_congr_left_symm (f : α ≃ β) :
(@equiv_congr_left _ _ M _ f).symm = equiv_congr_left f.symm := rfl
end equiv_congr_left
/-! ### 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 : α) [D : decidable (p a)] : f.filter p a = if p a then f a else 0 :=
by rw subsingleton.elim D; refl
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 [D : decidable_pred p] : (f.filter p).support = f.support.filter p :=
by rw subsingleton.elim D; refl
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_zero_class 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 [D : decidable_pred p] {f : α →₀ M} :
(subtype_domain p f).support = f.support.subtype p :=
by rw subsingleton.elim D; refl
@[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 add_zero_class
variables [add_zero_class 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 add_zero_class
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) [D : decidable_pred p] (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 (by rw subsingleton.elim D; refl) $
λ 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
@[simp] lemma single_neg {a : α} {b : G} : single a (-b) = -single a b :=
(single_add_hom a : G →+ _).map_neg b
@[simp] lemma single_sub {a : α} {b₁ b₂ : G} : single a (b₁ - b₂) = single a b₁ - single a b₂ :=
(single_add_hom a : G →+ _).map_sub b₁ b₂
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_symm_apply (s : multiset α) (x : α) :
finsupp.to_multiset.symm s x = s.count x :=
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 to_multiset_sum {ι : Type*} {f : ι → α →₀ ℕ} (s : finset ι) :
finsupp.to_multiset (∑ i in s, f i) = ∑ i in s, finsupp.to_multiset (f i) :=
add_equiv.map_sum _ _ _
lemma to_multiset_sum_single {ι : Type*} (s : finset ι) (n : ℕ) :
finsupp.to_multiset (∑ i in s, single i n) = n • s.val :=
by simp_rw [to_multiset_sum, finsupp.to_multiset_single, multiset.singleton_eq_singleton,
sum_nsmul, sum_multiset_singleton]
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_nsmul, multiset.singleton_eq_singleton,
multiset.prod_singleton],
{ exact pow_zero a },
{ exact pow_zero },
{ exact pow_add } }
end
@[simp] lemma to_finset_to_multiset [decidable_eq α] (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 [decidable_eq α] (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_nsmul]
... = 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)
@[simp] lemma curry_apply (f : (α × β) →₀ M) (x : α) (y : β) :
f.curry x y = f (x, y) :=
begin
have : ∀ (b : α × β), single b.fst (single b.snd (f b)) x y = if b = (x, y) then f b else 0,
{ rintros ⟨b₁, b₂⟩,
simp [single_apply, ite_apply, prod.ext_iff, ite_and],
split_ifs; simp [single_apply, *] },
rw [finsupp.curry, sum_apply, sum_apply, finsupp.sum, finset.sum_eq_single, this, if_pos rfl],
{ intros b hb b_ne, rw [this b, if_neg b_ne] },
{ intros hxy, rw [this (x, y), if_pos rfl, not_mem_support_iff.mp hxy] }
end
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 [decidable_eq α] (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 sum
/-- `finsupp.sum_elim f g` maps `inl x` to `f x` and `inr y` to `g y`. -/
def sum_elim {α β γ : Type*} [has_zero γ]
(f : α →₀ γ) (g : β →₀ γ) : α ⊕ β →₀ γ :=
on_finset
((f.support.map ⟨_, sum.inl_injective⟩) ∪ g.support.map ⟨_, sum.inr_injective⟩)
(sum.elim f g)
(λ ab h, by { cases ab with a b; simp only [sum.elim_inl, sum.elim_inr] at h; simpa })
@[simp] lemma coe_sum_elim {α β γ : Type*} [has_zero γ]
(f : α →₀ γ) (g : β →₀ γ) : ⇑(sum_elim f g) = sum.elim f g := rfl
lemma sum_elim_apply {α β γ : Type*} [has_zero γ]
(f : α →₀ γ) (g : β →₀ γ) (x : α ⊕ β) : sum_elim f g x = sum.elim f g x := rfl
lemma sum_elim_inl {α β γ : Type*} [has_zero γ]
(f : α →₀ γ) (g : β →₀ γ) (x : α) : sum_elim f g (sum.inl x) = f x := rfl
lemma sum_elim_inr {α β γ : Type*} [has_zero γ]
(f : α →₀ γ) (g : β →₀ γ) (x : β) : sum_elim f g (sum.inr x) = g x := rfl
/-- The equivalence between `(α ⊕ β) →₀ γ` and `(α →₀ γ) × (β →₀ γ)`.
This is the `finsupp` version of `equiv.sum_arrow_equiv_prod_arrow`. -/
@[simps apply symm_apply]
def sum_finsupp_equiv_prod_finsupp {α β γ : Type*} [has_zero γ] :
((α ⊕ β) →₀ γ) ≃ (α →₀ γ) × (β →₀ γ) :=
{ to_fun := λ f,
⟨f.comap_domain sum.inl (sum.inl_injective.inj_on _),
f.comap_domain sum.inr (sum.inr_injective.inj_on _)⟩,
inv_fun := λ fg, sum_elim fg.1 fg.2,
left_inv := λ f, by { ext ab, cases ab with a b; simp },
right_inv := λ fg, by { ext; simp } }
lemma fst_sum_finsupp_equiv_prod_finsupp {α β γ : Type*} [has_zero γ]
(f : (α ⊕ β) →₀ γ) (x : α) :
(sum_finsupp_equiv_prod_finsupp f).1 x = f (sum.inl x) :=
rfl
lemma snd_sum_finsupp_equiv_prod_finsupp {α β γ : Type*} [has_zero γ]
(f : (α ⊕ β) →₀ γ) (y : β) :
(sum_finsupp_equiv_prod_finsupp f).2 y = f (sum.inr y) :=
rfl
lemma sum_finsupp_equiv_prod_finsupp_symm_inl {α β γ : Type*} [has_zero γ]
(fg : (α →₀ γ) × (β →₀ γ)) (x : α) :
(sum_finsupp_equiv_prod_finsupp.symm fg) (sum.inl x) = fg.1 x :=
rfl
lemma sum_finsupp_equiv_prod_finsupp_symm_inr {α β γ : Type*} [has_zero γ]
(fg : (α →₀ γ) × (β →₀ γ)) (y : β) :
(sum_finsupp_equiv_prod_finsupp.symm fg) (sum.inr y) = fg.2 y :=
rfl
variables [add_monoid M]
/-- The additive equivalence between `(α ⊕ β) →₀ M` and `(α →₀ M) × (β →₀ M)`.
This is the `finsupp` version of `equiv.sum_arrow_equiv_prod_arrow`. -/
@[simps apply symm_apply] def sum_finsupp_add_equiv_prod_finsupp {α β : Type*} :
((α ⊕ β) →₀ M) ≃+ (α →₀ M) × (β →₀ M) :=
{ map_add' :=
by { intros, ext;
simp only [equiv.to_fun_as_coe, prod.fst_add, prod.snd_add, add_apply,
snd_sum_finsupp_equiv_prod_finsupp, fst_sum_finsupp_equiv_prod_finsupp] },
.. sum_finsupp_equiv_prod_finsupp }
lemma fst_sum_finsupp_add_equiv_prod_finsupp {α β : Type*}
(f : (α ⊕ β) →₀ M) (x : α) :
(sum_finsupp_add_equiv_prod_finsupp f).1 x = f (sum.inl x) :=
rfl
lemma snd_sum_finsupp_add_equiv_prod_finsupp {α β : Type*}
(f : (α ⊕ β) →₀ M) (y : β) :
(sum_finsupp_add_equiv_prod_finsupp f).2 y = f (sum.inr y) :=
rfl
lemma sum_finsupp_add_equiv_prod_finsupp_symm_inl {α β : Type*}
(fg : (α →₀ M) × (β →₀ M)) (x : α) :
(sum_finsupp_add_equiv_prod_finsupp.symm fg) (sum.inl x) = fg.1 x :=
rfl
lemma sum_finsupp_add_equiv_prod_finsupp_symm_inr {α β : Type*}
(fg : (α →₀ M) × (β →₀ M)) (y : β) :
(sum_finsupp_add_equiv_prod_finsupp.symm fg) (sum.inr y) = fg.2 y :=
rfl
end sum
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 [monoid R] [add_monoid M] [distrib_mul_action R M] : has_scalar R (α →₀ M) :=
⟨λa v, v.map_range ((•) a) (smul_zero _)⟩
/-!
Throughout this section, some `monoid` and `semiring` arguments are specified with `{}` instead of
`[]`. See note [implicit instance arguments].
-/
@[simp] lemma coe_smul {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
(b : R) (v : α →₀ M) : ⇑(b • v) = b • v := rfl
lemma smul_apply {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
(b : R) (v : α →₀ M) (a : α) : (b • v) a = b • (v a) := rfl
variables (α M)
instance [monoid R] [add_monoid M] [distrib_mul_action R M] : distrib_mul_action R (α →₀ M) :=
{ smul := (•),
smul_add := λ a x y, ext $ λ _, smul_add _ _ _,
one_smul := λ x, ext $ λ _, one_smul _ _,
mul_smul := λ r s x, ext $ λ _, mul_smul _ _ _,
smul_zero := λ x, ext $ λ _, smul_zero _ }
instance [monoid R] [monoid S] [add_monoid M] [distrib_mul_action R M] [distrib_mul_action 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 [monoid R] [monoid S] [add_monoid M] [distrib_mul_action R M] [distrib_mul_action S M]
[smul_comm_class R S M] :
smul_comm_class R S (α →₀ M) :=
{ smul_comm := λ r s a, ext $ λ _, smul_comm _ _ _ }
instance [semiring R] [add_comm_monoid M] [module R M] : module R (α →₀ M) :=
{ smul := (•),
zero_smul := λ x, ext $ λ _, zero_smul _ _,
add_smul := λ a x y, ext $ λ _, add_smul _ _ _,
.. finsupp.distrib_mul_action α M }
variables {α M} {R}
lemma support_smul {_ : monoid R} [add_monoid M] [distrib_mul_action 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 {_ : monoid R} [add_monoid M] [distrib_mul_action 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 {_ : monoid R} [add_comm_monoid M] [distrib_mul_action 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 {_ : monoid R} [add_monoid M] [distrib_mul_action 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 map_range_smul {_ : monoid R} [add_monoid M] [distrib_mul_action R M]
[add_monoid N] [distrib_mul_action R N]
{f : M → N} {hf : f 0 = 0} (c : R) (v : α →₀ M) (hsmul : ∀ x, f (c • x) = c • f x) :
map_range f hf (c • v) = c • map_range f hf v :=
begin
erw ←map_range_comp,
have : (f ∘ (•) c) = ((•) c ∘ f) := funext hsmul,
simp_rw this,
apply map_range_comp,
rw [function.comp_apply, smul_zero, hf],
end
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' [monoid R] [add_monoid M] [distrib_mul_action 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
[monoid R] [add_monoid M] [add_comm_monoid N] [distrib_mul_action 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] [module 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 distrib_mul_action_hom
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid N] [distrib_mul_action R M] [distrib_mul_action R N]
/-- `finsupp.single` as a `distrib_mul_action_hom`.
See also `finsupp.lsingle` for the version as a linear map. -/
def distrib_mul_action_hom.single (a : α) : M →+[R] (α →₀ M) :=
{ map_smul' :=
λ k m, by simp only [add_monoid_hom.to_fun_eq_coe, single_add_hom_apply, smul_single],
.. single_add_hom a }
lemma distrib_mul_action_hom_ext {f g : (α →₀ M) →+[R] N}
(h : ∀ (a : α) (m : M), f (single a m) = g (single a m)) :
f = g :=
distrib_mul_action_hom.to_add_monoid_hom_injective $ add_hom_ext h
/-- See note [partially-applied ext lemmas]. -/
@[ext] lemma distrib_mul_action_hom_ext' {f g : (α →₀ M) →+[R] N}
(h : ∀ (a : α), f.comp (distrib_mul_action_hom.single a) =
g.comp (distrib_mul_action_hom.single a)) :
f = g :=
distrib_mul_action_hom_ext $ λ a, distrib_mul_action_hom.congr_fun (h a)
end distrib_mul_action_hom
section
variables [has_zero R]
/-- The `finsupp` version of `pi.unique`. -/
instance unique_of_right [subsingleton R] : unique (α →₀ R) :=
{ uniq := λ l, ext $ λ i, subsingleton.elim _ _,
.. finsupp.inhabited }
/-- The `finsupp` version of `pi.unique_of_is_empty`. -/
instance unique_of_left [is_empty α] : unique (α →₀ R) :=
{ uniq := λ l, ext is_empty_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`.
This is `finsupp.equiv_congr_left` as an `add_equiv`. -/
@[simps apply]
protected def dom_congr [add_comm_monoid M] (e : α ≃ β) : (α →₀ M) ≃+ (β →₀ M) :=
{ to_fun := equiv_map_domain e,
inv_fun := equiv_map_domain e.symm,
left_inv := λ v, begin
simp only [← equiv_map_domain_trans, equiv.trans_symm],
exact equiv_map_domain_refl _
end,
right_inv := begin
assume v,
simp only [← equiv_map_domain_trans, equiv.symm_trans],
exact equiv_map_domain_refl _
end,
map_add' := λ a b, by simp only [equiv_map_domain_eq_map_domain]; exact map_domain_add }
@[simp] lemma dom_congr_refl [add_comm_monoid M] :
finsupp.dom_congr (equiv.refl α) = add_equiv.refl (α →₀ M) :=
add_equiv.ext $ λ _, equiv_map_domain_refl _
@[simp] lemma dom_congr_symm [add_comm_monoid M] (e : α ≃ β) :
(finsupp.dom_congr e).symm = (finsupp.dom_congr e.symm : (β →₀ M) ≃+ (α →₀ M)):=
add_equiv.ext $ λ _, rfl
@[simp] lemma dom_congr_trans [add_comm_monoid M] (e : α ≃ β) (f : β ≃ γ) :
(finsupp.dom_congr e).trans (finsupp.dom_congr f) =
(finsupp.dom_congr (e.trans f) : (α →₀ M) ≃+ _) :=
add_equiv.ext $ λ _, (equiv_map_domain_trans _ _ _).symm
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`.
This is the `finsupp` version of `sigma.curry`.
-/
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]
variables {η : Type*} [fintype η] {ιs : η → Type*} [has_zero α]
/-- On a `fintype η`, `finsupp.split` is an equivalence between `(Σ (j : η), ιs j) →₀ α`
and `Π j, (ιs j →₀ α)`.
This is the `finsupp` version of `equiv.Pi_curry`. -/
noncomputable def sigma_finsupp_equiv_pi_finsupp :
((Σ j, ιs j) →₀ α) ≃ Π j, (ιs j →₀ α) :=
{ to_fun := split,
inv_fun := λ f, on_finset
(finset.univ.sigma (λ j, (f j).support))
(λ ji, f ji.1 ji.2)
(λ g hg, finset.mem_sigma.mpr ⟨finset.mem_univ _, mem_support_iff.mpr hg⟩),
left_inv := λ f, by { ext, simp [split] },
right_inv := λ f, by { ext, simp [split] } }
@[simp] lemma sigma_finsupp_equiv_pi_finsupp_apply
(f : (Σ j, ιs j) →₀ α) (j i) :
sigma_finsupp_equiv_pi_finsupp f j i = f ⟨j, i⟩ := rfl
/-- On a `fintype η`, `finsupp.split` is an additive equivalence between
`(Σ (j : η), ιs j) →₀ α` and `Π j, (ιs j →₀ α)`.
This is the `add_equiv` version of `finsupp.sigma_finsupp_equiv_pi_finsupp`.
-/
noncomputable def sigma_finsupp_add_equiv_pi_finsupp
{α : Type*} {ιs : η → Type*} [add_monoid α] :
((Σ j, ιs j) →₀ α) ≃+ Π j, (ιs j →₀ α) :=
{ map_add' := λ f g, by { ext, simp },
.. sigma_finsupp_equiv_pi_finsupp }
@[simp] lemma sigma_finsupp_add_equiv_pi_finsupp_apply
{α : Type*} {ιs : η → Type*} [add_monoid α] (f : (Σ j, ιs j) →₀ α) (j i) :
sigma_finsupp_add_equiv_pi_finsupp f j i = f ⟨j, i⟩ := rfl
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 [D : decidable_eq α] (s : multiset α) :
s.to_finsupp.support = s.to_finset :=
by rw subsingleton.elim D; refl
@[simp] lemma to_finsupp_apply [D : decidable_eq α] (s : multiset α) (a : α) :
to_finsupp s a = s.count a :=
by rw subsingleton.elim D; refl
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] : 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),
add_left_cancel := λ a b c h, ext $ λ s, add_left_cancel (ext_iff.1 h s),
.. finsupp.add_comm_monoid, .. finsupp.partial_order }
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)⟩
instance decidable_le [canonically_ordered_add_monoid M] [decidable_rel (@has_le.le M _)] :
decidable_rel (@has_le.le (α →₀ M) _) :=
λ f g, decidable_of_iff _ (le_iff f g).symm
@[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
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 (α →₀ ℕ)) }
end finsupp
namespace multiset
lemma to_finsuppstrict_mono : strict_mono (@to_finsupp α) :=
finsupp.order_iso_multiset.symm.strict_mono
end multiset
|
24808165f62217f3801878ea799395da8896f6b0
|
592ee40978ac7604005a4e0d35bbc4b467389241
|
/Library/generated/mathscheme-lean/PointedUnarySystem.lean
|
8614bc17658dd949d25180652bba640ecc0116ce
|
[] |
no_license
|
ysharoda/Deriving-Definitions
|
3e149e6641fae440badd35ac110a0bd705a49ad2
|
dfecb27572022de3d4aa702cae8db19957523a59
|
refs/heads/master
| 1,679,127,857,700
| 1,615,939,007,000
| 1,615,939,007,000
| 229,785,731
| 4
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,456
|
lean
|
import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section PointedUnarySystem
structure PointedUnarySystem (A : Type) : Type :=
(prim : (A → A))
(e : A)
open PointedUnarySystem
structure Sig (AS : Type) : Type :=
(primS : (AS → AS))
(eS : AS)
structure Product (A : Type) : Type :=
(primP : ((Prod A A) → (Prod A A)))
(eP : (Prod A A))
structure Hom {A1 : Type} {A2 : Type} (Po1 : (PointedUnarySystem A1)) (Po2 : (PointedUnarySystem A2)) : Type :=
(hom : (A1 → A2))
(pres_prim : (∀ {x1 : A1} , (hom ((prim Po1) x1)) = ((prim Po2) (hom x1))))
(pres_e : (hom (e Po1)) = (e Po2))
structure RelInterp {A1 : Type} {A2 : Type} (Po1 : (PointedUnarySystem A1)) (Po2 : (PointedUnarySystem A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_prim : (∀ {x1 : A1} {y1 : A2} , ((interp x1 y1) → (interp ((prim Po1) x1) ((prim Po2) y1)))))
(interp_e : (interp (e Po1) (e Po2)))
inductive PointedUnarySystemTerm : Type
| primL : (PointedUnarySystemTerm → PointedUnarySystemTerm)
| eL : PointedUnarySystemTerm
open PointedUnarySystemTerm
inductive ClPointedUnarySystemTerm (A : Type) : Type
| sing : (A → ClPointedUnarySystemTerm)
| primCl : (ClPointedUnarySystemTerm → ClPointedUnarySystemTerm)
| eCl : ClPointedUnarySystemTerm
open ClPointedUnarySystemTerm
inductive OpPointedUnarySystemTerm (n : ℕ) : Type
| v : ((fin n) → OpPointedUnarySystemTerm)
| primOL : (OpPointedUnarySystemTerm → OpPointedUnarySystemTerm)
| eOL : OpPointedUnarySystemTerm
open OpPointedUnarySystemTerm
inductive OpPointedUnarySystemTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpPointedUnarySystemTerm2)
| sing2 : (A → OpPointedUnarySystemTerm2)
| primOL2 : (OpPointedUnarySystemTerm2 → OpPointedUnarySystemTerm2)
| eOL2 : OpPointedUnarySystemTerm2
open OpPointedUnarySystemTerm2
def simplifyCl {A : Type} : ((ClPointedUnarySystemTerm A) → (ClPointedUnarySystemTerm A))
| (primCl x1) := (primCl (simplifyCl x1))
| eCl := eCl
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpPointedUnarySystemTerm n) → (OpPointedUnarySystemTerm n))
| (primOL x1) := (primOL (simplifyOpB x1))
| eOL := eOL
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpPointedUnarySystemTerm2 n A) → (OpPointedUnarySystemTerm2 n A))
| (primOL2 x1) := (primOL2 (simplifyOp x1))
| eOL2 := eOL2
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((PointedUnarySystem A) → (PointedUnarySystemTerm → A))
| Po (primL x1) := ((prim Po) (evalB Po x1))
| Po eL := (e Po)
def evalCl {A : Type} : ((PointedUnarySystem A) → ((ClPointedUnarySystemTerm A) → A))
| Po (sing x1) := x1
| Po (primCl x1) := ((prim Po) (evalCl Po x1))
| Po eCl := (e Po)
def evalOpB {A : Type} {n : ℕ} : ((PointedUnarySystem A) → ((vector A n) → ((OpPointedUnarySystemTerm n) → A)))
| Po vars (v x1) := (nth vars x1)
| Po vars (primOL x1) := ((prim Po) (evalOpB Po vars x1))
| Po vars eOL := (e Po)
def evalOp {A : Type} {n : ℕ} : ((PointedUnarySystem A) → ((vector A n) → ((OpPointedUnarySystemTerm2 n A) → A)))
| Po vars (v2 x1) := (nth vars x1)
| Po vars (sing2 x1) := x1
| Po vars (primOL2 x1) := ((prim Po) (evalOp Po vars x1))
| Po vars eOL2 := (e Po)
def inductionB {P : (PointedUnarySystemTerm → Type)} : ((∀ (x1 : PointedUnarySystemTerm) , ((P x1) → (P (primL x1)))) → ((P eL) → (∀ (x : PointedUnarySystemTerm) , (P x))))
| ppriml pel (primL x1) := (ppriml _ (inductionB ppriml pel x1))
| ppriml pel eL := pel
def inductionCl {A : Type} {P : ((ClPointedUnarySystemTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 : (ClPointedUnarySystemTerm A)) , ((P x1) → (P (primCl x1)))) → ((P eCl) → (∀ (x : (ClPointedUnarySystemTerm A)) , (P x)))))
| psing pprimcl pecl (sing x1) := (psing x1)
| psing pprimcl pecl (primCl x1) := (pprimcl _ (inductionCl psing pprimcl pecl x1))
| psing pprimcl pecl eCl := pecl
def inductionOpB {n : ℕ} {P : ((OpPointedUnarySystemTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 : (OpPointedUnarySystemTerm n)) , ((P x1) → (P (primOL x1)))) → ((P eOL) → (∀ (x : (OpPointedUnarySystemTerm n)) , (P x)))))
| pv pprimol peol (v x1) := (pv x1)
| pv pprimol peol (primOL x1) := (pprimol _ (inductionOpB pv pprimol peol x1))
| pv pprimol peol eOL := peol
def inductionOp {n : ℕ} {A : Type} {P : ((OpPointedUnarySystemTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 : (OpPointedUnarySystemTerm2 n A)) , ((P x1) → (P (primOL2 x1)))) → ((P eOL2) → (∀ (x : (OpPointedUnarySystemTerm2 n A)) , (P x))))))
| pv2 psing2 pprimol2 peol2 (v2 x1) := (pv2 x1)
| pv2 psing2 pprimol2 peol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 pprimol2 peol2 (primOL2 x1) := (pprimol2 _ (inductionOp pv2 psing2 pprimol2 peol2 x1))
| pv2 psing2 pprimol2 peol2 eOL2 := peol2
def stageB : (PointedUnarySystemTerm → (Staged PointedUnarySystemTerm))
| (primL x1) := (stage1 primL (codeLift1 primL) (stageB x1))
| eL := (Now eL)
def stageCl {A : Type} : ((ClPointedUnarySystemTerm A) → (Staged (ClPointedUnarySystemTerm A)))
| (sing x1) := (Now (sing x1))
| (primCl x1) := (stage1 primCl (codeLift1 primCl) (stageCl x1))
| eCl := (Now eCl)
def stageOpB {n : ℕ} : ((OpPointedUnarySystemTerm n) → (Staged (OpPointedUnarySystemTerm n)))
| (v x1) := (const (code (v x1)))
| (primOL x1) := (stage1 primOL (codeLift1 primOL) (stageOpB x1))
| eOL := (Now eOL)
def stageOp {n : ℕ} {A : Type} : ((OpPointedUnarySystemTerm2 n A) → (Staged (OpPointedUnarySystemTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (primOL2 x1) := (stage1 primOL2 (codeLift1 primOL2) (stageOp x1))
| eOL2 := (Now eOL2)
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(primT : ((Repr A) → (Repr A)))
(eT : (Repr A))
end PointedUnarySystem
|
d6d06dca83700ba00c870baeb103725ead0709c7
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/topology/sheaves/limits.lean
|
b654ec19f869b14bdc4d3d5182c0d819779042a3
|
[
"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
| 1,893
|
lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import topology.sheaves.sheaf_condition.sites
import category_theory.sites.limits
import category_theory.adjunction
import category_theory.limits.functor_category
/-!
# Presheaves in `C` have limits and colimits when `C` does.
-/
noncomputable theory
universes v u
open category_theory
open category_theory.limits
variables {C : Type u} [category.{v} C] {J : Type v} [small_category J]
namespace Top
instance [has_limits C] (X : Top) : has_limits (presheaf C X) :=
limits.functor_category_has_limits_of_size
instance [has_colimits C] (X : Top) : has_colimits (presheaf C X) :=
limits.functor_category_has_colimits_of_size
instance [has_limits C] (X : Top) : creates_limits (sheaf.forget C X) :=
(@@creates_limits_of_nat_iso _ _
(presheaf.Sheaf_spaces_equiv_sheaf_sites_inverse_forget C X))
(@@category_theory.comp_creates_limits _ _ _ _ _ _
Sheaf.category_theory.Sheaf_to_presheaf.category_theory.creates_limits.{u v v})
instance [has_limits C] (X : Top) : has_limits (sheaf C X) :=
has_limits_of_has_limits_creates_limits (sheaf.forget C X)
lemma is_sheaf_of_is_limit [has_limits C] {X : Top} (F : J ⥤ presheaf C X)
(H : ∀ j, (F.obj j).is_sheaf) {c : cone F} (hc : is_limit c) : c.X.is_sheaf :=
begin
let F' : J ⥤ sheaf C X := { obj := λ j, ⟨F.obj j, H j⟩, map := F.map },
let e : F' ⋙ sheaf.forget C X ≅ F := nat_iso.of_components (λ _, iso.refl _) (by tidy),
exact presheaf.is_sheaf_of_iso ((is_limit_of_preserves (sheaf.forget C X)
(limit.is_limit F')).cone_points_iso_of_nat_iso hc e) (limit F').2
end
lemma limit_is_sheaf [has_limits C] {X : Top} (F : J ⥤ presheaf C X)
(H : ∀ j, (F.obj j).is_sheaf) : (limit F).is_sheaf :=
is_sheaf_of_is_limit F H (limit.is_limit F)
end Top
|
987b6f3df28b742d54c5aff97919789542613e1c
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/measure_theory/measure_space.lean
|
6188d7f3f062bb645a992ef68dc6809f870f00f0
|
[
"Apache-2.0"
] |
permissive
|
agjftucker/mathlib
|
d634cd0d5256b6325e3c55bb7fb2403548371707
|
87fe50de17b00af533f72a102d0adefe4a2285e8
|
refs/heads/master
| 1,625,378,131,941
| 1,599,166,526,000
| 1,599,166,526,000
| 160,748,509
| 0
| 0
|
Apache-2.0
| 1,544,141,789,000
| 1,544,141,789,000
| null |
UTF-8
|
Lean
| false
| false
| 56,365
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import measure_theory.outer_measure
import order.filter.countable_Inter
/-!
# Measure spaces
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ennreal`.
We introduce the following typeclasses for measures:
* `probability_measure μ`: `μ univ = 1`;
* `finite_measure μ`: `μ univ < ⊤`;
* `locally_finite_measure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ⊤`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `measure.of_measurable` and `outer_measure.to_measure` are two important ways to define a measure.
## Implementation notes
Given `μ : measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `measure.of_measurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `outer_measure.to_measure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
A `measure_space` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable theory
open classical set filter finset function
open_locale classical topological_space big_operators filter
universes u v w x
namespace measure_theory
/-- A measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure. -/
structure measure (α : Type*) [measurable_space α] extends outer_measure α :=
(m_Union {{f : ℕ → set α}} :
(∀i, is_measurable (f i)) → pairwise (disjoint on f) →
measure_of (⋃i, f i) = (∑'i, measure_of (f i)))
(trimmed : to_outer_measure.trim = to_outer_measure)
/-- Measure projections for a measure space.
For measurable sets this returns the measure assigned by the `measure_of` field in `measure`.
But we can extend this to _all_ sets, but using the outer measure. This gives us monotonicity and
subadditivity for all sets.
-/
instance measure.has_coe_to_fun {α} [measurable_space α] : has_coe_to_fun (measure α) :=
⟨λ _, set α → ennreal, λ m, m.to_outer_measure⟩
namespace measure
/-- Obtain a measure by giving a countably additive function that sends `∅` to `0`. -/
def of_measurable {α} [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) (is_measurable.Union h) = (∑'i, m (f i) (h i))) :
measure α :=
{ m_Union := λ f hf hd,
show induced_outer_measure m _ m0 (Union f) =
∑' i, induced_outer_measure m _ m0 (f i), begin
rw [induced_outer_measure_eq m0 mU, mU hf hd],
congr, funext n, rw induced_outer_measure_eq m0 mU
end,
trimmed :=
show (induced_outer_measure m _ m0).trim = induced_outer_measure m _ m0, begin
unfold outer_measure.trim,
congr, funext s hs,
exact induced_outer_measure_eq m0 mU hs
end,
..induced_outer_measure m _ m0 }
lemma of_measurable_apply {α} [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) (is_measurable.Union h) = (∑'i, m (f i) (h i))}
(s : set α) (hs : is_measurable s) :
of_measurable m m0 mU s = m s hs :=
induced_outer_measure_eq m0 mU hs
lemma to_outer_measure_injective {α} [measurable_space α] :
injective (to_outer_measure : measure α → outer_measure α) :=
λ ⟨m₁, u₁, h₁⟩ ⟨m₂, u₂, h₂⟩ h, by { congr, exact h }
@[ext] lemma ext {α} [measurable_space α] {μ₁ μ₂ : measure α}
(h : ∀s, is_measurable s → μ₁ s = μ₂ s) :
μ₁ = μ₂ :=
to_outer_measure_injective $ by rw [← trimmed, outer_measure.trim_congr h, trimmed]
lemma ext_iff {α} [measurable_space α] {μ₁ μ₂ : measure α} :
μ₁ = μ₂ ↔ ∀s, is_measurable s → μ₁ s = μ₂ s :=
⟨by { rintro rfl s hs, refl }, measure.ext⟩
end measure
section
variables {α : Type*} {β : Type*} {ι : Type*} [measurable_space α] {μ μ₁ μ₂ : measure α}
{s s₁ s₂ : set α}
@[simp] lemma coe_to_outer_measure : ⇑μ.to_outer_measure = μ := rfl
lemma to_outer_measure_apply (s) : μ.to_outer_measure s = μ s := rfl
lemma measure_eq_trim (s) : μ s = μ.to_outer_measure.trim s :=
by rw μ.trimmed; refl
lemma measure_eq_infi (s) : μ s = ⨅ t (st : s ⊆ t) (ht : is_measurable t), μ t :=
by rw [measure_eq_trim, outer_measure.trim_eq_infi]; refl
lemma measure_eq_induced_outer_measure :
μ s = induced_outer_measure (λ s _, μ s) is_measurable.empty μ.empty s :=
measure_eq_trim _
lemma to_outer_measure_eq_induced_outer_measure :
μ.to_outer_measure = induced_outer_measure (λ s _, μ s) is_measurable.empty μ.empty :=
μ.trimmed.symm
lemma measure_eq_extend (hs : is_measurable s) :
μ s = extend (λ t (ht : is_measurable t), μ t) s :=
by { rw [measure_eq_induced_outer_measure, induced_outer_measure_eq_extend _ _ hs], exact μ.m_Union }
@[simp] lemma measure_empty : μ ∅ = 0 := μ.empty
lemma nonempty_of_measure_ne_zero (h : μ s ≠ 0) : s.nonempty :=
ne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ measure_empty
lemma measure_mono (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := μ.mono h
lemma measure_mono_null (h : s₁ ⊆ s₂) (h₂ : μ s₂ = 0) : μ s₁ = 0 :=
by rw [← le_zero_iff_eq, ← h₂]; exact measure_mono h
lemma exists_is_measurable_superset_of_measure_eq_zero {s : set α} (h : μ s = 0) :
∃t, s ⊆ t ∧ is_measurable t ∧ μ t = 0 :=
outer_measure.exists_is_measurable_superset_of_trim_eq_zero (by rw [← measure_eq_trim, h])
lemma exists_is_measurable_superset_iff_measure_eq_zero {s : set α} :
(∃ t, s ⊆ t ∧ is_measurable t ∧ μ t = 0) ↔ μ s = 0 :=
⟨λ ⟨t, hst, _, ht⟩, measure_mono_null hst ht, exists_is_measurable_superset_of_measure_eq_zero⟩
theorem measure_Union_le {β} [encodable β] (s : β → set α) : μ (⋃i, s i) ≤ (∑'i, μ (s i)) :=
μ.to_outer_measure.Union _
lemma measure_bUnion_le {s : set β} (hs : countable s) (f : β → set α) :
μ (⋃b∈s, f b) ≤ ∑'p:s, μ (f p) :=
begin
haveI := hs.to_encodable,
rw [bUnion_eq_Union],
apply measure_Union_le
end
lemma measure_bUnion_finset_le (s : finset β) (f : β → set α) :
μ (⋃b∈s, f b) ≤ ∑ p in s, μ (f p) :=
begin
rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype],
exact measure_bUnion_le s.countable_to_set f
end
lemma measure_Union_null {β} [encodable β] {s : β → set α} :
(∀ i, μ (s i) = 0) → μ (⋃i, s i) = 0 :=
μ.to_outer_measure.Union_null
theorem measure_union_le (s₁ s₂ : set α) : μ (s₁ ∪ s₂) ≤ μ s₁ + μ s₂ :=
μ.to_outer_measure.union _ _
lemma measure_union_null {s₁ s₂ : set α} : μ s₁ = 0 → μ s₂ = 0 → μ (s₁ ∪ s₂) = 0 :=
μ.to_outer_measure.union_null
lemma measure_Union {β} [encodable β] {f : β → set α}
(hn : pairwise (disjoint on f)) (h : ∀i, is_measurable (f i)) :
μ (⋃i, f i) = (∑'i, μ (f i)) :=
begin
rw [measure_eq_extend (is_measurable.Union h),
extend_Union is_measurable.empty _ is_measurable.Union _ hn h],
{ simp [measure_eq_extend, h] },
{ exact μ.empty },
{ exact μ.m_Union }
end
lemma measure_union (hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) :
μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
begin
rw [measure_eq_extend (h₁.union h₂),
extend_union is_measurable.empty _ is_measurable.Union _ hd h₁ h₂],
{ simp [measure_eq_extend, h₁, h₂] },
{ exact μ.empty },
{ exact μ.m_Union }
end
lemma measure_bUnion {s : set β} {f : β → set α} (hs : countable s)
(hd : pairwise_on s (disjoint on f)) (h : ∀b∈s, is_measurable (f b)) :
μ (⋃b∈s, f b) = ∑'p:s, μ (f p) :=
begin
haveI := hs.to_encodable,
rw [← measure_Union, bUnion_eq_Union],
{ rintro ⟨i, hi⟩ ⟨j, hj⟩ ij x ⟨h₁, h₂⟩,
exact hd i hi j hj (mt subtype.ext_val ij:_) ⟨h₁, h₂⟩ },
{ simpa }
end
lemma measure_sUnion {S : set (set α)} (hs : countable S)
(hd : pairwise_on S disjoint) (h : ∀s∈S, is_measurable s) :
μ (⋃₀ S) = ∑' s:S, μ s :=
by rw [sUnion_eq_bUnion, measure_bUnion hs hd h]
lemma measure_bUnion_finset {s : finset ι} {f : ι → set α} (hd : pairwise_on ↑s (disjoint on f))
(hm : ∀b∈s, is_measurable (f b)) :
μ (⋃b∈s, f b) = ∑ p in s, μ (f p) :=
begin
rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype],
exact measure_bUnion s.countable_to_set hd hm
end
/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
lemma tsum_measure_preimage_singleton {s : set β} (hs : countable s) {f : α → β}
(hf : ∀ y ∈ s, is_measurable (f ⁻¹' {y})) :
(∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) :=
by rw [← set.bUnion_preimage_singleton, measure_bUnion hs (pairwise_on_disjoint_fiber _ _) hf]
/-- If `s` is a `finset`, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
lemma sum_measure_preimage_singleton (s : finset β) {f : α → β}
(hf : ∀ y ∈ s, is_measurable (f ⁻¹' {y})) :
∑ b in s, μ (f ⁻¹' {b}) = μ (f ⁻¹' ↑s) :=
by simp only [← measure_bUnion_finset (pairwise_on_disjoint_fiber _ _) hf,
finset.bUnion_preimage_singleton]
lemma measure_diff {s₁ s₂ : set α} (h : s₂ ⊆ s₁)
(h₁ : is_measurable s₁) (h₂ : is_measurable s₂)
(h_fin : μ s₂ < ⊤) : μ (s₁ \ s₂) = μ s₁ - μ s₂ :=
begin
refine (ennreal.add_sub_self' h_fin).symm.trans _,
rw [← measure_union disjoint_diff h₂ (h₁.diff h₂), union_diff_cancel h]
end
lemma sum_measure_le_measure_univ {s : finset ι} {t : ι → set α} (h : ∀ i ∈ s, is_measurable (t i))
(H : pairwise_on ↑s (disjoint on t)) :
∑ i in s, μ (t i) ≤ μ (univ : set α) :=
by { rw ← measure_bUnion_finset H h, exact measure_mono (subset_univ _) }
lemma tsum_measure_le_measure_univ {s : ι → set α} (hs : ∀ i, is_measurable (s i))
(H : pairwise (disjoint on s)) :
(∑' i, μ (s i)) ≤ μ (univ : set α) :=
begin
rw [ennreal.tsum_eq_supr_sum],
exact supr_le (λ s, sum_measure_le_measure_univ (λ i hi, hs i) (λ i hi j hj hij, H i j hij))
end
/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then
one of the intersections `s i ∩ s j` is not empty. -/
lemma exists_nonempty_inter_of_measure_univ_lt_tsum_measure (μ : measure α) {s : ι → set α}
(hs : ∀ i, is_measurable (s i)) (H : μ (univ : set α) < ∑' i, μ (s i)) :
∃ i j (h : i ≠ j), (s i ∩ s j).nonempty :=
begin
contrapose! H,
apply tsum_measure_le_measure_univ hs,
exact λ i j hij x hx, H i j hij ⟨x, hx⟩
end
/-- Pigeonhole principle for measure spaces: if `s` is a `finset` and
`∑ i in s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
lemma exists_nonempty_inter_of_measure_univ_lt_sum_measure (μ : measure α) {s : finset ι}
{t : ι → set α} (h : ∀ i ∈ s, is_measurable (t i)) (H : μ (univ : set α) < ∑ i in s, μ (t i)) :
∃ (i ∈ s) (j ∈ s) (h : i ≠ j), (t i ∩ t j).nonempty :=
begin
contrapose! H,
apply sum_measure_le_measure_univ h,
exact λ i hi j hj hij x hx, H i hi j hj hij ⟨x, hx⟩
end
lemma measure_Union_eq_supr_nat {s : ℕ → set α} (h : ∀i, is_measurable (s i)) (hs : monotone s) :
μ (⋃i, s i) = (⨆i, μ (s i)) :=
begin
have : ∀ t : finset ℕ, ∃ n, t ⊆ finset.range (n + 1),
from λ t, (finset.exists_nat_subset_range t).imp (λ n hn, finset.subset.trans hn $
finset.range_mono $ (le_add_iff_nonneg_right _).2 (zero_le 1)),
rw [← Union_disjointed, measure_Union disjoint_disjointed (is_measurable.disjointed h),
ennreal.tsum_eq_supr_sum' _ this],
congr' 1 with n : 1,
rw [← measure_bUnion_finset (disjoint_disjointed.pairwise_on _)
(λ n _, is_measurable.disjointed h n)],
convert congr_arg μ (Union_disjointed_of_mono hs n),
ext, simp
end
lemma measure_Inter_eq_infi_nat {s : ℕ → set α}
(h : ∀i, is_measurable (s i)) (hs : ∀i j, i ≤ j → s j ⊆ s i)
(hfin : ∃i, μ (s i) < ⊤) :
μ (⋂i, s i) = (⨅i, μ (s i)) :=
begin
rcases hfin with ⟨k, hk⟩,
rw [← ennreal.sub_sub_cancel (by exact hk) (infi_le _ k),
ennreal.sub_infi,
← ennreal.sub_sub_cancel (by exact hk) (measure_mono (Inter_subset _ k)),
← measure_diff (Inter_subset _ k) (h k) (is_measurable.Inter h)
(lt_of_le_of_lt (measure_mono (Inter_subset _ k)) hk),
diff_Inter, measure_Union_eq_supr_nat],
{ congr, funext i,
cases le_total k i with ik ik,
{ exact measure_diff (hs _ _ ik) (h k) (h i)
(lt_of_le_of_lt (measure_mono (hs _ _ ik)) hk) },
{ rw [diff_eq_empty.2 (hs _ _ ik), measure_empty,
ennreal.sub_eq_zero_of_le (measure_mono (hs _ _ ik))] } },
{ exact λ i, (h k).diff (h i) },
{ exact λ i j ij, diff_subset_diff_right (hs _ _ ij) }
end
lemma measure_eq_inter_diff {μ : measure α} {s t : set α}
(hs : is_measurable s) (ht : is_measurable t) :
μ s = μ (s ∩ t) + μ (s \ t) :=
have hd : disjoint (s ∩ t) (s \ t) := assume a ⟨⟨_, hs⟩, _, hns⟩, hns hs ,
by rw [← measure_union hd (hs.inter ht) (hs.diff ht), inter_union_diff s t]
lemma tendsto_measure_Union {μ : measure α} {s : ℕ → set α}
(hs : ∀n, is_measurable (s n)) (hm : monotone s) :
tendsto (μ ∘ s) at_top (𝓝 (μ (⋃n, s n))) :=
begin
rw measure_Union_eq_supr_nat hs hm,
exact tendsto_at_top_supr_nat (μ ∘ s) (assume n m hnm, measure_mono $ hm $ hnm)
end
lemma tendsto_measure_Inter {μ : measure α} {s : ℕ → set α}
(hs : ∀n, is_measurable (s n)) (hm : ∀n m, n ≤ m → s m ⊆ s n) (hf : ∃i, μ (s i) < ⊤) :
tendsto (μ ∘ s) at_top (𝓝 (μ (⋂n, s n))) :=
begin
rw measure_Inter_eq_infi_nat hs hm hf,
exact tendsto_at_top_infi_nat (μ ∘ s) (assume n m hnm, measure_mono $ hm _ _ $ hnm),
end
end
/-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are
Carathéodory measurable. -/
def outer_measure.to_measure {α} (m : outer_measure α)
[ms : measurable_space α] (h : ms ≤ m.caratheodory) :
measure α :=
measure.of_measurable (λ s _, m s) m.empty
(λ f hf hd, m.Union_eq_of_caratheodory (λ i, h _ (hf i)) hd)
lemma le_to_outer_measure_caratheodory {α} [ms : measurable_space α]
(μ : measure α) : ms ≤ μ.to_outer_measure.caratheodory :=
begin
assume s hs,
rw to_outer_measure_eq_induced_outer_measure,
refine outer_measure.of_function_caratheodory (λ t, le_infi $ λ ht, _),
rw [← measure_eq_extend (ht.inter hs),
← measure_eq_extend (ht.diff hs),
← measure_union _ (ht.inter hs) (ht.diff hs),
inter_union_diff],
exact le_refl _,
exact λ x ⟨⟨_, h₁⟩, _, h₂⟩, h₂ h₁
end
@[simp] lemma to_measure_to_outer_measure {α} (m : outer_measure α)
[ms : measurable_space α] (h : ms ≤ m.caratheodory) :
(m.to_measure h).to_outer_measure = m.trim := rfl
@[simp] lemma to_measure_apply {α} (m : outer_measure α)
[ms : measurable_space α] (h : ms ≤ m.caratheodory)
{s : set α} (hs : is_measurable s) :
m.to_measure h s = m s := m.trim_eq hs
lemma le_to_measure_apply {α} (m : outer_measure α) [ms : measurable_space α]
(h : ms ≤ m.caratheodory) (s : set α) :
m s ≤ m.to_measure h s :=
m.le_trim s
@[simp] lemma to_outer_measure_to_measure {α : Type*} [ms : measurable_space α] {μ : measure α} :
μ.to_outer_measure.to_measure (le_to_outer_measure_caratheodory _) = μ :=
measure.ext $ λ s, μ.to_outer_measure.trim_eq
namespace measure
variables {α : Type*} {β : Type*} {γ : Type*}
[measurable_space α] [measurable_space β] [measurable_space γ]
instance : has_zero (measure α) :=
⟨{ to_outer_measure := 0,
m_Union := λ f hf hd, tsum_zero.symm,
trimmed := outer_measure.trim_zero }⟩
@[simp] theorem zero_to_outer_measure : (0 : measure α).to_outer_measure = 0 := rfl
@[simp, norm_cast] theorem coe_zero : ⇑(0 : measure α) = 0 := rfl
lemma eq_zero_of_not_nonempty (h : ¬nonempty α) (μ : measure α) : μ = 0 :=
ext $ λ s hs, by simp only [eq_empty_of_not_nonempty h s, measure_empty]
instance : inhabited (measure α) := ⟨0⟩
instance : has_add (measure α) :=
⟨λμ₁ μ₂, {
to_outer_measure := μ₁.to_outer_measure + μ₂.to_outer_measure,
m_Union := λs hs hd,
show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, μ₁ (s i) + μ₂ (s i),
by rw [ennreal.tsum_add, measure_Union hd hs, measure_Union hd hs],
trimmed := by rw [outer_measure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩
@[simp] theorem add_to_outer_measure (μ₁ μ₂ : measure α) :
(μ₁ + μ₂).to_outer_measure = μ₁.to_outer_measure + μ₂.to_outer_measure := rfl
@[simp, norm_cast] theorem coe_add (μ₁ μ₂ : measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl
theorem add_apply (μ₁ μ₂ : measure α) (s) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl
instance add_comm_monoid : add_comm_monoid (measure α) :=
to_outer_measure_injective.add_comm_monoid to_outer_measure zero_to_outer_measure
add_to_outer_measure
instance : has_scalar ennreal (measure α) :=
⟨λ c μ,
{ to_outer_measure := c • μ.to_outer_measure,
m_Union := λ s hs hd, by simp [measure_Union, *, ennreal.tsum_mul_left],
trimmed := by rw [outer_measure.trim_smul, μ.trimmed] }⟩
@[simp] theorem smul_to_outer_measure (c : ennreal) (μ : measure α) :
(c • μ).to_outer_measure = c • μ.to_outer_measure :=
rfl
@[simp, norm_cast] theorem coe_smul (c : ennreal) (μ : measure α) :
⇑(c • μ) = c • μ :=
rfl
theorem smul_apply (c : ennreal) (μ : measure α) (s : set α) :
(c • μ) s = c * μ s :=
rfl
instance : semimodule ennreal (measure α) :=
injective.semimodule ennreal ⟨to_outer_measure, zero_to_outer_measure, add_to_outer_measure⟩
to_outer_measure_injective smul_to_outer_measure
instance : partial_order (measure α) :=
{ le := λm₁ m₂, ∀ s, is_measurable s → m₁ s ≤ m₂ s,
le_refl := assume m s hs, le_refl _,
le_trans := assume m₁ m₂ m₃ h₁ h₂ s hs, le_trans (h₁ s hs) (h₂ s hs),
le_antisymm := assume m₁ m₂ h₁ h₂, ext $
assume s hs, le_antisymm (h₁ s hs) (h₂ s hs) }
theorem le_iff {μ₁ μ₂ : measure α} :
μ₁ ≤ μ₂ ↔ ∀ s, is_measurable s → μ₁ s ≤ μ₂ s := iff.rfl
theorem to_outer_measure_le {μ₁ μ₂ : measure α} :
μ₁.to_outer_measure ≤ μ₂.to_outer_measure ↔ μ₁ ≤ μ₂ :=
by rw [← μ₂.trimmed, outer_measure.le_trim_iff]; refl
theorem le_iff' {μ₁ μ₂ : measure α} :
μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s :=
to_outer_measure_le.symm
theorem lt_iff {μ ν : measure α} : μ < ν ↔ μ ≤ ν ∧ ∃ s, is_measurable s ∧ μ s < ν s :=
lt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff, not_forall, not_le, exists_prop]
theorem lt_iff' {μ ν : measure α} : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s :=
lt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff', not_forall, not_le]
section
variables {m : set (measure α)} {μ : measure α}
lemma Inf_caratheodory (s : set α) (hs : is_measurable s) :
(Inf (measure.to_outer_measure '' m)).caratheodory.is_measurable s :=
begin
rw [outer_measure.Inf_eq_of_function_Inf_gen],
refine outer_measure.of_function_caratheodory (assume t, _),
cases t.eq_empty_or_nonempty with ht ht, by simp [ht],
simp only [outer_measure.Inf_gen_nonempty1 _ _ ht, le_infi_iff, ball_image_iff,
coe_to_outer_measure, measure_eq_infi t],
assume μ hμ u htu hu,
have hm : ∀{s t}, s ⊆ t → outer_measure.Inf_gen (to_outer_measure '' m) s ≤ μ t,
{ assume s t hst,
rw [outer_measure.Inf_gen_nonempty2 _ _ (mem_image_of_mem _ hμ)],
refine infi_le_of_le (μ.to_outer_measure) (infi_le_of_le (mem_image_of_mem _ hμ) _),
rw [to_outer_measure_apply],
refine measure_mono hst },
rw [measure_eq_inter_diff hu hs],
refine add_le_add (hm $ inter_subset_inter_left _ htu) (hm $ diff_subset_diff_left htu)
end
instance : has_Inf (measure α) :=
⟨λm, (Inf (to_outer_measure '' m)).to_measure $ Inf_caratheodory⟩
lemma Inf_apply {m : set (measure α)} {s : set α} (hs : is_measurable s) :
Inf m s = Inf (to_outer_measure '' m) s :=
to_measure_apply _ _ hs
private lemma Inf_le (h : μ ∈ m) : Inf m ≤ μ :=
have Inf (to_outer_measure '' m) ≤ μ.to_outer_measure := Inf_le (mem_image_of_mem _ h),
assume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s
private lemma le_Inf (h : ∀μ' ∈ m, μ ≤ μ') : μ ≤ Inf m :=
have μ.to_outer_measure ≤ Inf (to_outer_measure '' m) :=
le_Inf $ ball_image_of_ball $ assume μ hμ, to_outer_measure_le.2 $ h _ hμ,
assume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s
instance : complete_lattice (measure α) :=
{ bot := 0,
bot_le := assume a s hs, by exact bot_le,
/- Adding an explicit `top` makes `leanchecker` fail, see lean#364, disable for now
top := (⊤ : outer_measure α).to_measure (by rw [outer_measure.top_caratheodory]; exact le_top),
le_top := assume a s hs,
by cases s.eq_empty_or_nonempty with h h;
simp [h, to_measure_apply ⊤ _ hs, outer_measure.top_apply],
-/
.. complete_lattice_of_Inf (measure α) (λ ms, ⟨λ _, Inf_le, λ _, le_Inf⟩) }
@[simp] lemma measure_univ_eq_zero {μ : measure α} : μ univ = 0 ↔ μ = 0 :=
⟨λ h, bot_unique $ λ s hs, trans_rel_left (≤) (measure_mono (subset_univ s)) h, λ h, h.symm ▸ rfl⟩
-- TODO: add typeclasses for `∀ c, monotone ((*) c)` and `∀ c, monotone ((+) c)`
protected lemma add_le_add_left {μ₁ μ₂ : measure α} (ν : measure α) (hμ : μ₁ ≤ μ₂) :
ν + μ₁ ≤ ν + μ₂ :=
λ s hs, add_le_add_left (hμ s hs) _
protected lemma add_le_add_right {μ₁ μ₂ : measure α} (hμ : μ₁ ≤ μ₂) (ν : measure α) :
μ₁ + ν ≤ μ₂ + ν :=
λ s hs, add_le_add_right (hμ s hs) _
protected lemma add_le_add {μ₁ μ₂ : measure α} (hμ : μ₁ ≤ μ₂) {ν₁ ν₂ : measure α} (hν : ν₁ ≤ ν₂) :
μ₁ + ν₁ ≤ μ₂ + ν₂ :=
λ s hs, add_le_add (hμ s hs) (hν s hs)
protected lemma zero_le (μ : measure α) : 0 ≤ μ := bot_le
protected lemma le_add_left {ν ν' : measure α} (h : μ ≤ ν) : μ ≤ ν' + ν :=
λ s hs, le_add_left (h s hs)
protected lemma le_add_right {ν ν' : measure α} (h : μ ≤ ν) : μ ≤ ν + ν' :=
λ s hs, le_add_right (h s hs)
end
/-- Lift a linear map between `outer_measure` spaces such that for each measure `μ` every measurable
set is caratheodory-measurable w.r.t. `f μ` to a linear map between `measure` spaces. -/
def lift_linear (f : outer_measure α →ₗ[ennreal] outer_measure β)
(hf : ∀ μ : measure α, ‹_› ≤ (f μ.to_outer_measure).caratheodory) :
measure α →ₗ[ennreal] measure β :=
{ to_fun := λ μ, (f μ.to_outer_measure).to_measure (hf μ),
map_add' := λ μ₁ μ₂, ext $ λ s hs, by simp [hs],
map_smul' := λ c μ, ext $ λ s hs, by simp [hs] }
@[simp] lemma lift_linear_apply {f : outer_measure α →ₗ[ennreal] outer_measure β} (hf)
{μ : measure α} {s : set β} (hs : is_measurable s) :
lift_linear f hf μ s = f μ.to_outer_measure s :=
to_measure_apply _ _ hs
lemma le_lift_linear_apply {f : outer_measure α →ₗ[ennreal] outer_measure β} (hf)
{μ : measure α} (s : set β) :
f μ.to_outer_measure s ≤ lift_linear f hf μ s :=
le_to_measure_apply _ _ s
/-- The pushforward of a measure. It is defined to be `0` if `f` is not a measurable function. -/
def map (f : α → β) : measure α →ₗ[ennreal] measure β :=
if hf : measurable f then
lift_linear (outer_measure.map f) $ λ μ s hs t,
le_to_outer_measure_caratheodory μ _ (hf hs) (f ⁻¹' t)
else 0
variables {μ ν : measure α}
@[simp] theorem map_apply {f : α → β} (hf : measurable f) {s : set β} (hs : is_measurable s) :
map f μ s = μ (f ⁻¹' s) :=
by simp [map, dif_pos hf, hs]
@[simp] lemma map_id : map id μ = μ :=
ext $ λ s, map_apply measurable_id
lemma map_map {g : β → γ} {f : α → β} (hg : measurable g) (hf : measurable f) :
map g (map f μ) = map (g ∘ f) μ :=
ext $ λ s hs,
by simp [hf, hg, hs, hg hs, hg.comp hf, ← preimage_comp]
/-- Pullback of a `measure`. If `f` sends each `measurable` set to a `measurable` set, then for each
measurable set `s` we have `comap f μ s = μ (f '' s)`. -/
def comap (f : α → β) : measure β →ₗ[ennreal] measure α :=
if hf : injective f ∧ ∀ s, is_measurable s → is_measurable (f '' s) then
lift_linear (outer_measure.comap f) $ λ μ s hs t,
begin
simp only [coe_to_outer_measure, outer_measure.comap_apply, ← image_inter hf.1, image_diff hf.1],
apply le_to_outer_measure_caratheodory,
exact hf.2 s hs
end
else 0
lemma comap_apply (f : α → β) (hfi : injective f)
(hf : ∀ s, is_measurable s → is_measurable (f '' s)) (μ : measure β)
{s : set α} (hs : is_measurable s) :
comap f μ s = μ (f '' s) :=
begin
rw [comap, dif_pos, lift_linear_apply _ hs, outer_measure.comap_apply, coe_to_outer_measure],
exact ⟨hfi, hf⟩
end
/-- Restrict a measure `μ` to a set `s` as an `ennreal`-linear map. -/
def restrictₗ (s : set α) : measure α →ₗ[ennreal] measure α :=
lift_linear (outer_measure.restrict s) $ λ μ s' hs' t,
begin
suffices : μ (s ∩ t) = μ (s ∩ t ∩ s') + μ (s ∩ t \ s'),
{ simpa [← set.inter_assoc, set.inter_comm _ s, ← inter_diff_assoc] },
exact le_to_outer_measure_caratheodory _ _ hs' _,
end
/-- Restrict a measure `μ` to a set `s`. -/
def restrict (μ : measure α) (s : set α) : measure α := restrictₗ s μ
@[simp] lemma restrictₗ_apply (s : set α) (μ : measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
@[simp] lemma restrict_apply {s t : set α} (ht : is_measurable t) :
μ.restrict s t = μ (t ∩ s) :=
by simp [← restrictₗ_apply, restrictₗ, ht]
lemma restrict_apply_univ (s : set α) : μ.restrict s univ = μ s :=
by rw [restrict_apply is_measurable.univ, set.univ_inter]
lemma le_restrict_apply (s t : set α) :
μ (t ∩ s) ≤ μ.restrict s t :=
by { rw [restrict, restrictₗ], convert le_lift_linear_apply _ t, simp }
@[simp] lemma restrict_add (μ ν : measure α) (s : set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp] lemma restrict_zero (s : set α) : (0 : measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp] lemma restrict_smul (c : ennreal) (μ : measure α) (s : set α) :
(c • μ).restrict s = c • μ.restrict s :=
(restrictₗ s).map_smul c μ
lemma restrict_apply_eq_zero {s t : set α} (ht : is_measurable t) :
μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=
by rw [restrict_apply ht]
lemma restrict_apply_eq_zero' {s t : set α} (hs : is_measurable s) :
μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=
begin
refine ⟨λ h, le_zero_iff_eq.1 (h ▸ le_restrict_apply _ _), λ h, _⟩,
rcases exists_is_measurable_superset_of_measure_eq_zero h with ⟨t', htt', ht', ht'0⟩,
apply measure_mono_null ((inter_subset _ _ _).1 htt'),
rw [restrict_apply (hs.compl.union ht'), union_inter_distrib_right, compl_inter_self,
set.empty_union],
exact measure_mono_null (inter_subset_left _ _) ht'0
end
@[simp] lemma restrict_eq_zero {s} : μ.restrict s = 0 ↔ μ s = 0 :=
by rw [← measure_univ_eq_zero, restrict_apply_univ]
@[simp] lemma restrict_empty : μ.restrict ∅ = 0 := ext $ λ s hs, by simp [hs]
@[simp] lemma restrict_univ : μ.restrict univ = μ := ext $ λ s hs, by simp [hs]
lemma restrict_union_apply {s s' t : set α} (h : disjoint (t ∩ s) (t ∩ s')) (hs : is_measurable s)
(hs' : is_measurable s') (ht : is_measurable t) :
μ.restrict (s ∪ s') t = μ.restrict s t + μ.restrict s' t :=
begin
simp only [restrict_apply, ht, set.inter_union_distrib_left],
exact measure_union h (ht.inter hs) (ht.inter hs'),
end
lemma restrict_union {s t : set α} (h : disjoint s t) (hs : is_measurable s)
(ht : is_measurable t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
ext $ λ t' ht', restrict_union_apply (h.mono inf_le_right inf_le_right) hs ht ht'
@[simp] lemma restrict_add_restrict_compl {s : set α} (hs : is_measurable s) :
μ.restrict s + μ.restrict sᶜ = μ :=
by rw [← restrict_union (disjoint_compl _) hs hs.compl, union_compl_self, restrict_univ]
@[simp] lemma restrict_compl_add_restrict {s : set α} (hs : is_measurable s) :
μ.restrict sᶜ + μ.restrict s = μ :=
by rw [add_comm, restrict_add_restrict_compl hs]
lemma restrict_union_le (s s' : set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
begin
intros t ht,
suffices : μ (t ∩ s ∪ t ∩ s') ≤ μ (t ∩ s) + μ (t ∩ s'),
by simpa [ht, inter_union_distrib_left],
apply measure_union_le
end
lemma restrict_Union_apply {ι} [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))
(hm : ∀ i, is_measurable (s i)) {t : set α} (ht : is_measurable t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
begin
simp only [restrict_apply, ht, inter_Union],
exact measure_Union (λ i j hij, (hd i j hij).mono inf_le_right inf_le_right)
(λ i, ht.inter (hm i))
end
lemma map_comap_subtype_coe {s : set α} (hs : is_measurable s) :
(map (coe : s → α)).comp (comap coe) = restrictₗ s :=
linear_map.ext $ λ μ, ext $ λ t ht,
by rw [restrictₗ_apply, restrict_apply ht, linear_map.comp_apply,
map_apply measurable_subtype_coe ht,
comap_apply (coe : s → α) subtype.val_injective (λ _, hs.subtype_image) _
(measurable_subtype_coe ht), subtype.image_preimage_coe]
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono] lemma restrict_mono ⦃s s' : set α⦄ (hs : s ⊆ s') ⦃μ ν : measure α⦄ (hμν : μ ≤ ν) :
μ.restrict s ≤ ν.restrict s' :=
assume t ht,
calc μ.restrict s t = μ (t ∩ s) : restrict_apply ht
... ≤ μ (t ∩ s') : measure_mono $ inter_subset_inter_right _ hs
... ≤ ν (t ∩ s') : le_iff'.1 hμν (t ∩ s')
... = ν.restrict s' t : (restrict_apply ht).symm
lemma restrict_le_self {s} : μ.restrict s ≤ μ :=
assume t ht,
calc μ.restrict s t = μ (t ∩ s) : restrict_apply ht
... ≤ μ t : measure_mono $ inter_subset_left t s
/-- The dirac measure. -/
def dirac (a : α) : measure α :=
(outer_measure.dirac a).to_measure (by simp)
lemma dirac_apply' (a : α) {s : set α} (hs : is_measurable s) :
dirac a s = ⨆ h : a ∈ s, 1 :=
to_measure_apply _ _ hs
@[simp] lemma dirac_apply (a : α) {s : set α} (hs : is_measurable s) :
dirac a s = s.indicator 1 a :=
(dirac_apply' a hs).trans $ by { by_cases h : a ∈ s; simp [h] }
lemma dirac_apply_of_mem {a : α} {s : set α} (h : a ∈ s) :
dirac a s = 1 :=
begin
rw [measure_eq_infi, infi_subtype', infi_subtype'],
convert infi_const,
{ ext1 ⟨⟨t, hst⟩, ht⟩,
dsimp only [subtype.coe_mk] at *,
simp only [dirac_apply _ ht, indicator_of_mem (hst h), pi.one_apply] },
{ exact ⟨⟨⟨set.univ, subset_univ _⟩, is_measurable.univ⟩⟩ }
end
/-- Sum of an indexed family of measures. -/
def sum {ι : Type*} (f : ι → measure α) : measure α :=
(outer_measure.sum (λ i, (f i).to_outer_measure)).to_measure $
le_trans
(by exact le_infi (λ i, le_to_outer_measure_caratheodory _))
(outer_measure.le_sum_caratheodory _)
@[simp] lemma sum_apply {ι : Type*} (f : ι → measure α) {s : set α} (hs : is_measurable s) :
sum f s = ∑' i, f i s :=
to_measure_apply _ _ hs
lemma le_sum {ι : Type*} (μ : ι → measure α) (i : ι) : μ i ≤ sum μ :=
λ s hs, by simp only [sum_apply μ hs, ennreal.le_tsum i]
lemma restrict_Union {ι} [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))
(hm : ∀ i, is_measurable (s i)) :
μ.restrict (⋃ i, s i) = sum (λ i, μ.restrict (s i)) :=
ext $ λ t ht, by simp only [sum_apply _ ht, restrict_Union_apply hd hm ht]
lemma restrict_Union_le {ι} [encodable ι] {s : ι → set α} :
μ.restrict (⋃ i, s i) ≤ sum (λ i, μ.restrict (s i)) :=
begin
intros t ht,
suffices : μ (⋃ i, t ∩ s i) ≤ ∑' i, μ (t ∩ s i), by simpa [ht, inter_Union],
apply measure_Union_le
end
@[simp] lemma sum_bool (f : bool → measure α) : sum f = f tt + f ff :=
ext $ λ s hs, by simp [hs, tsum_fintype]
@[simp] lemma restrict_sum {ι : Type*} (μ : ι → measure α) {s : set α} (hs : is_measurable s) :
(sum μ).restrict s = sum (λ i, (μ i).restrict s) :=
ext $ λ t ht, by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
/-- Counting measure on any measurable space. -/
def count : measure α := sum dirac
lemma count_apply {s : set α} (hs : is_measurable s) :
count s = ∑' i : s, 1 :=
by simp only [count, sum_apply, hs, dirac_apply, ← tsum_subtype s 1, pi.one_apply]
@[simp] lemma count_apply_finset [measurable_singleton_class α] (s : finset α) :
count (↑s : set α) = s.card :=
calc count (↑s : set α) = ∑' i : (↑s : set α), (1 : α → ennreal) i : count_apply s.is_measurable
... = ∑ i in s, 1 : s.tsum_subtype 1
... = s.card : by simp
lemma count_apply_finite [measurable_singleton_class α] (s : set α) (hs : finite s) :
count s = hs.to_finset.card :=
by rw [← count_apply_finset, finite.coe_to_finset]
/-- `count` measure evaluates to infinity at infinite sets. -/
lemma count_apply_infinite [measurable_singleton_class α] {s : set α} (hs : s.infinite) :
count s = ⊤ :=
begin
by_contra H,
rcases ennreal.exists_nat_gt H with ⟨n, hn⟩,
rcases hs.exists_subset_card_eq n with ⟨t, ht, rfl⟩,
have := lt_of_le_of_lt (measure_mono ht) hn,
simpa [lt_irrefl] using this
end
@[simp] lemma count_apply_eq_top [measurable_singleton_class α] {s : set α} :
count s = ⊤ ↔ s.infinite :=
begin
by_cases hs : s.finite,
{ simp [set.infinite, hs, count_apply_finite] },
{ change s.infinite at hs,
simp [hs, count_apply_infinite] }
end
@[simp] lemma count_apply_lt_top [measurable_singleton_class α] {s : set α} :
count s < ⊤ ↔ s.finite :=
calc count s < ⊤ ↔ count s ≠ ⊤ : lt_top_iff_ne_top
... ↔ ¬s.infinite : not_congr count_apply_eq_top
... ↔ s.finite : not_not
/-- A measure is complete if every null set is also measurable.
A null set is a subset of a measurable set with measure `0`.
Since every measure is defined as a special case of an outer measure, we can more simply state
that a set `s` is null if `μ s = 0`. -/
@[class] def is_complete {α} {_:measurable_space α} (μ : measure α) : Prop :=
∀ s, μ s = 0 → is_measurable s
/-- The “almost everywhere” filter of co-null sets. -/
def ae (μ : measure α) : filter α :=
{ sets := {s | μ sᶜ = 0},
univ_sets := by simp,
inter_sets := λ s t hs ht, by simp only [compl_inter, mem_set_of_eq];
exact measure_union_null hs ht,
sets_of_superset := λ s t hs hst, measure_mono_null (set.compl_subset_compl.2 hst) hs }
/-- The filter of sets `s` such that `sᶜ` has finite measure. -/
def cofinite (μ : measure α) : filter α :=
{ sets := {s | μ sᶜ < ⊤},
univ_sets := by simp,
inter_sets := λ s t hs ht, by { simp only [compl_inter, mem_set_of_eq],
calc μ (sᶜ ∪ tᶜ) ≤ μ sᶜ + μ tᶜ : measure_union_le _ _
... < ⊤ : ennreal.add_lt_top.2 ⟨hs, ht⟩ },
sets_of_superset := λ s t hs hst, lt_of_le_of_lt (measure_mono $ compl_subset_compl.2 hst) hs }
lemma mem_cofinite {s : set α} : s ∈ μ.cofinite ↔ μ sᶜ < ⊤ := iff.rfl
lemma compl_mem_cofinite {s : set α} : sᶜ ∈ μ.cofinite ↔ μ s < ⊤ :=
by rw [mem_cofinite, compl_compl]
lemma eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ {x | ¬p x} < ⊤ := iff.rfl
end measure
variables {α : Type*} {β : Type*} [measurable_space α] {μ : measure α}
notation `∀ᵐ` binders ` ∂` μ `, ` r:(scoped P, filter.eventually P (measure.ae μ)) := r
notation f ` =ᵐ[`:50 μ:50 `] `:0 g:50 := f =ᶠ[measure.ae μ] g
notation f ` ≤ᵐ[`:50 μ:50 `] `:0 g:50 := f ≤ᶠ[measure.ae μ] g
lemma mem_ae_iff {s : set α} : s ∈ μ.ae ↔ μ sᶜ = 0 := iff.rfl
lemma ae_iff {p : α → Prop} : (∀ᵐ a ∂ μ, p a) ↔ μ { a | ¬ p a } = 0 := iff.rfl
lemma compl_mem_ae_iff {s : set α} : sᶜ ∈ μ.ae ↔ μ s = 0 := by simp only [mem_ae_iff, compl_compl]
lemma measure_zero_iff_ae_nmem {s : set α} : μ s = 0 ↔ ∀ᵐ a ∂ μ, a ∉ s :=
compl_mem_ae_iff.symm
lemma ae_eq_bot : μ.ae = ⊥ ↔ μ = 0 :=
by rw [← empty_in_sets_eq_bot, mem_ae_iff, compl_empty, measure.measure_univ_eq_zero]
lemma ae_of_all {p : α → Prop} (μ : measure α) : (∀a, p a) → ∀ᵐ a ∂ μ, p a :=
eventually_of_forall
@[mono] lemma ae_mono {μ ν : measure α} (h : μ ≤ ν) : μ.ae ≤ ν.ae :=
λ s hs, bot_unique $ trans_rel_left (≤) (measure.le_iff'.1 h _) hs
instance : countable_Inter_filter μ.ae :=
⟨begin
intros S hSc hS,
simp only [mem_ae_iff, compl_sInter, sUnion_image, bUnion_eq_Union] at hS ⊢,
haveI := hSc.to_encodable,
exact measure_Union_null (subtype.forall.2 hS)
end⟩
instance ae_is_measurably_generated : is_measurably_generated μ.ae :=
⟨λ s hs, let ⟨t, hst, htm, htμ⟩ := exists_is_measurable_superset_of_measure_eq_zero hs in
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
lemma ae_all_iff {ι : Type*} [encodable ι] {p : α → ι → Prop} :
(∀ᵐ a ∂ μ, ∀i, p a i) ↔ (∀i, ∀ᵐ a ∂ μ, p a i) :=
eventually_countable_forall
lemma ae_ball_iff {ι} {S : set ι} (hS : countable S) {p : Π (x : α) (i ∈ S), Prop} :
(∀ᵐ x ∂ μ, ∀ i ∈ S, p x i ‹_›) ↔ ∀ i ∈ S, ∀ᵐ x ∂ μ, p x i ‹_› :=
eventually_countable_ball hS
lemma ae_eq_refl (f : α → β) : f =ᵐ[μ] f := eventually_eq.refl _ _
lemma ae_eq_symm {f g : α → β} (h : f =ᵐ[μ] g) : g =ᵐ[μ] f :=
h.symm
lemma ae_eq_trans {f g h: α → β} (h₁ : f =ᵐ[μ] g) (h₂ : g =ᵐ[μ] h) :
f =ᵐ[μ] h :=
h₁.trans h₂
lemma mem_ae_map_iff [measurable_space β] {f : α → β} (hf : measurable f)
{s : set β} (hs : is_measurable s) :
s ∈ (measure.map f μ).ae ↔ (f ⁻¹' s) ∈ μ.ae :=
by simp only [mem_ae_iff, measure.map_apply hf hs.compl, preimage_compl]
lemma ae_map_iff [measurable_space β] {f : α → β} (hf : measurable f)
{p : β → Prop} (hp : is_measurable {x | p x}) :
(∀ᵐ y ∂ (measure.map f μ), p y) ↔ ∀ᵐ x ∂ μ, p (f x) :=
mem_ae_map_iff hf hp
lemma ae_restrict_iff {s : set α} {p : α → Prop} (hp : is_measurable {x | p x}) :
(∀ᵐ x ∂(μ.restrict s), p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
begin
simp only [ae_iff, ← compl_set_of, measure.restrict_apply hp.compl],
congr' with x, simp [and_comm]
end
lemma ae_smul_measure {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) (c : ennreal) : ∀ᵐ x ∂(c • μ), p x :=
ae_iff.2 $ by rw [measure.smul_apply, ae_iff.1 h, mul_zero]
lemma ae_add_measure_iff {p : α → Prop} {ν} : (∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=
add_eq_zero_iff
@[simp] lemma ae_restrict_eq {s : set α} (hs : is_measurable s):
(μ.restrict s).ae = μ.ae ⊓ 𝓟 s :=
begin
ext t,
simp only [mem_inf_principal, mem_ae_iff, measure.restrict_apply_eq_zero' hs, compl_set_of,
not_imp, and_comm (_ ∈ s)],
refl
end
@[simp] lemma ae_restrict_eq_bot {s} : (μ.restrict s).ae = ⊥ ↔ μ s = 0 :=
ae_eq_bot.trans measure.restrict_eq_zero
@[simp] lemma ae_restrict_ne_bot {s} : (μ.restrict s).ae.ne_bot ↔ 0 < μ s :=
(not_congr ae_restrict_eq_bot).trans zero_lt_iff_ne_zero.symm
lemma mem_dirac_ae_iff {a : α} {s : set α} (hs : is_measurable s) :
s ∈ (measure.dirac a).ae ↔ a ∈ s :=
by by_cases a ∈ s; simp [mem_ae_iff, measure.dirac_apply, hs.compl, indicator_apply, *]
lemma eventually_dirac {a : α} {p : α → Prop} (hp : is_measurable {x | p x}) :
(∀ᵐ x ∂(measure.dirac a), p x) ↔ p a :=
mem_dirac_ae_iff hp
lemma eventually_eq_dirac [measurable_space β] [measurable_singleton_class β] {a : α} {f : α → β}
(hf : measurable f) :
f =ᵐ[measure.dirac a] const α (f a) :=
(eventually_dirac $ show is_measurable (f ⁻¹' {f a}), from hf $ is_measurable_singleton _).2 rfl
lemma dirac_ae_eq [measurable_singleton_class α] (a : α) : (measure.dirac a).ae = pure a :=
begin
ext s,
simp only [mem_ae_iff, mem_pure_sets],
by_cases ha : a ∈ s,
{ simp only [ha, iff_true],
rw [← set.singleton_subset_iff, ← compl_subset_compl] at ha,
refine measure_mono_null ha _,
simp [measure.dirac_apply a (is_measurable_singleton a).compl] },
{ simp only [ha, iff_false, measure.dirac_apply_of_mem (mem_compl ha)],
exact one_ne_zero }
end
lemma eventually_eq_dirac' [measurable_singleton_class α] {a : α} (f : α → β) :
f =ᵐ[measure.dirac a] const α (f a) :=
by { rw [dirac_ae_eq], show f a = f a, refl }
lemma measure_diff_of_ae_le {s t : set α} (H : s ≤ᵐ[μ] t) :
μ (s \ t) = 0 :=
flip measure_mono_null H $ λ x hx H, hx.2 (H hx.1)
/-- If `s ⊆ t` modulo a set of measure `0`, then `μ s ≤ μ t`. -/
lemma measure_mono_ae {s t : set α} (H : s ≤ᵐ[μ] t) :
μ s ≤ μ t :=
calc μ s ≤ μ (s ∪ t) : measure_mono $ subset_union_left s t
... = μ (t ∪ s \ t) : by rw [union_diff_self, set.union_comm]
... ≤ μ t + μ (s \ t) : measure_union_le _ _
... = μ t : by rw [measure_diff_of_ae_le H, add_zero]
alias measure_mono_ae ← filter.eventually_le.measure_le
/-- If two sets are equal modulo a set of measure zero, then `μ s = μ t`. -/
lemma measure_congr {s t : set α} (H : s =ᵐ[μ] t) : μ s = μ t :=
le_antisymm H.le.measure_le H.symm.le.measure_le
lemma restrict_mono_ae {s t : set α} (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
begin
intros u hu,
simp only [measure.restrict_apply hu],
exact measure_mono_ae (h.mono $ λ x hx, and.imp id hx)
end
lemma restrict_congr {s t : set α} (H : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae H.le) (restrict_mono_ae H.symm.le)
/-- A measure `μ` is called a probability measure if `μ univ = 1`. -/
class probability_measure (μ : measure α) : Prop := (measure_univ : μ univ = 1)
/-- A measure `μ` is called finite if `μ univ < ⊤`. -/
class finite_measure (μ : measure α) : Prop := (measure_univ_lt_top : μ univ < ⊤)
export probability_measure (measure_univ)
lemma measure_lt_top (μ : measure α) [finite_measure μ] (s : set α) : μ s < ⊤ :=
(measure_mono (subset_univ s)).trans_lt finite_measure.measure_univ_lt_top
lemma measure_ne_top (μ : measure α) [finite_measure μ] (s : set α) : μ s ≠ ⊤ :=
ne_of_lt (measure_lt_top μ s)
@[priority 100]
instance probability_measure.to_finite_measure (μ : measure α) [probability_measure μ] :
finite_measure μ :=
⟨by simp only [measure_univ, ennreal.one_lt_top]⟩
/-- A measure is called finite at filter `f` if it is finite at some set `s ∈ f`.
Equivalently, it is eventually finite at `s` in `f.lift' powerset`. -/
def measure.finite_at_filter (μ : measure α) (f : filter α) : Prop := ∃ s ∈ f, μ s < ⊤
lemma finite_at_filter_of_finite (μ : measure α) [finite_measure μ] (f : filter α) :
μ.finite_at_filter f :=
⟨univ, univ_mem_sets, measure_lt_top μ univ⟩
lemma measure.finite_at_bot (μ : measure α) : μ.finite_at_filter ⊥ :=
⟨∅, mem_bot_sets, by simp only [measure_empty, with_top.zero_lt_top]⟩
/-- A measure is called locally finite if it is finite in some neighborhood of each point. -/
class locally_finite_measure [topological_space α] (μ : measure α) : Prop :=
(finite_at_nhds : ∀ x, μ.finite_at_filter (𝓝 x))
@[priority 100]
instance finite_measure.to_locally_finite_measure [topological_space α] (μ : measure α)
[finite_measure μ] :
locally_finite_measure μ :=
⟨λ x, finite_at_filter_of_finite _ _⟩
lemma measure.finite_at_nhds [topological_space α] (μ : measure α)
[locally_finite_measure μ] (x : α) :
μ.finite_at_filter (𝓝 x) :=
locally_finite_measure.finite_at_nhds x
namespace measure
namespace finite_at_filter
variables {ν : measure α} {f g : filter α}
lemma filter_mono (h : f ≤ g) : μ.finite_at_filter g → μ.finite_at_filter f :=
λ ⟨s, hs, hμ⟩, ⟨s, h hs, hμ⟩
lemma inf_of_left (h : μ.finite_at_filter f) : μ.finite_at_filter (f ⊓ g) :=
h.filter_mono inf_le_left
lemma inf_of_right (h : μ.finite_at_filter g) : μ.finite_at_filter (f ⊓ g) :=
h.filter_mono inf_le_right
@[simp] lemma inf_ae_iff : μ.finite_at_filter (f ⊓ μ.ae) ↔ μ.finite_at_filter f :=
begin
refine ⟨_, λ h, h.filter_mono inf_le_left⟩,
rintros ⟨s, ⟨t, ht, u, hu, hs⟩, hμ⟩,
suffices : μ t ≤ μ s, from ⟨t, ht, this.trans_lt hμ⟩,
exact measure_mono_ae (mem_sets_of_superset hu (λ x hu ht, hs ⟨ht, hu⟩))
end
alias inf_ae_iff ↔ measure_theory.measure.finite_at_filter.of_inf_ae _
lemma filter_mono_ae (h : f ⊓ μ.ae ≤ g) (hg : μ.finite_at_filter g) : μ.finite_at_filter f :=
inf_ae_iff.1 (hg.filter_mono h)
protected lemma measure_mono (h : μ ≤ ν) : ν.finite_at_filter f → μ.finite_at_filter f :=
λ ⟨s, hs, hν⟩, ⟨s, hs, (measure.le_iff'.1 h s).trans_lt hν⟩
@[mono] protected lemma mono (hf : f ≤ g) (hμ : μ ≤ ν) :
ν.finite_at_filter g → μ.finite_at_filter f :=
λ h, (h.filter_mono hf).measure_mono hμ
protected lemma eventually (h : μ.finite_at_filter f) : ∀ᶠ s in f.lift' powerset, μ s < ⊤ :=
(eventually_lift'_powerset' $ λ s t hst ht, (measure_mono hst).trans_lt ht).2 h
lemma filter_sup : μ.finite_at_filter f → μ.finite_at_filter g → μ.finite_at_filter (f ⊔ g) :=
λ ⟨s, hsf, hsμ⟩ ⟨t, htg, htμ⟩,
⟨s ∪ t, union_mem_sup hsf htg, (measure_union_le s t).trans_lt (ennreal.add_lt_top.2 ⟨hsμ, htμ⟩)⟩
end finite_at_filter
lemma finite_at_nhds_within [topological_space α] (μ : measure α) [locally_finite_measure μ]
(x : α) (s : set α) :
μ.finite_at_filter (𝓝[s] x) :=
(finite_at_nhds μ x).inf_of_left
@[simp] lemma finite_at_principal {s : set α} : μ.finite_at_filter (𝓟 s) ↔ μ s < ⊤ :=
⟨λ ⟨t, ht, hμ⟩, (measure_mono ht).trans_lt hμ, λ h, ⟨s, mem_principal_self s, h⟩⟩
end measure
end measure_theory
section is_complete
open measure_theory
variables {α : Type*} [measurable_space α] (μ : measure α)
/-- A set is null measurable if it is the union of a null set and a measurable set. -/
def is_null_measurable (s : set α) : Prop :=
∃ t z, s = t ∪ z ∧ is_measurable t ∧ μ z = 0
theorem is_null_measurable_iff {μ : measure α} {s : set α} :
is_null_measurable μ s ↔
∃ t, t ⊆ s ∧ is_measurable t ∧ μ (s \ t) = 0 :=
begin
split,
{ rintro ⟨t, z, rfl, ht, hz⟩,
refine ⟨t, set.subset_union_left _ _, ht, measure_mono_null _ hz⟩,
simp [union_diff_left, diff_subset] },
{ rintro ⟨t, st, ht, hz⟩,
exact ⟨t, _, (union_diff_cancel st).symm, ht, hz⟩ }
end
theorem is_null_measurable_measure_eq {μ : measure α} {s t : set α}
(st : t ⊆ s) (hz : μ (s \ t) = 0) : μ s = μ t :=
begin
refine le_antisymm _ (measure_mono st),
have := measure_union_le t (s \ t),
rw [union_diff_cancel st, hz] at this, simpa
end
theorem is_measurable.is_null_measurable
{s : set α} (hs : is_measurable s) : is_null_measurable μ s :=
⟨s, ∅, by simp, hs, μ.empty⟩
theorem is_null_measurable_of_complete [c : μ.is_complete]
{s : set α} : is_null_measurable μ s ↔ is_measurable s :=
⟨by rintro ⟨t, z, rfl, ht, hz⟩; exact
is_measurable.union ht (c _ hz),
λ h, h.is_null_measurable _⟩
variables {μ}
theorem is_null_measurable.union_null {s z : set α}
(hs : is_null_measurable μ s) (hz : μ z = 0) :
is_null_measurable μ (s ∪ z) :=
begin
rcases hs with ⟨t, z', rfl, ht, hz'⟩,
exact ⟨t, z' ∪ z, set.union_assoc _ _ _, ht, le_zero_iff_eq.1
(le_trans (measure_union_le _ _) $ by simp [hz, hz'])⟩
end
theorem null_is_null_measurable {z : set α}
(hz : μ z = 0) : is_null_measurable μ z :=
by simpa using (is_measurable.empty.is_null_measurable _).union_null hz
theorem is_null_measurable.Union_nat {s : ℕ → set α}
(hs : ∀ i, is_null_measurable μ (s i)) :
is_null_measurable μ (Union s) :=
begin
choose t ht using assume i, is_null_measurable_iff.1 (hs i),
simp [forall_and_distrib] at ht,
rcases ht with ⟨st, ht, hz⟩,
refine is_null_measurable_iff.2
⟨Union t, Union_subset_Union st, is_measurable.Union ht,
measure_mono_null _ (measure_Union_null hz)⟩,
rw [diff_subset_iff, ← Union_union_distrib],
exact Union_subset_Union (λ i, by rw ← diff_subset_iff)
end
theorem is_measurable.diff_null {s z : set α}
(hs : is_measurable s) (hz : μ z = 0) :
is_null_measurable μ (s \ z) :=
begin
rw measure_eq_infi at hz,
choose f hf using show ∀ q : {q:ℚ//q>0}, ∃ t:set α,
z ⊆ t ∧ is_measurable t ∧ μ t < (nnreal.of_real q.1 : ennreal),
{ rintro ⟨ε, ε0⟩,
have : 0 < (nnreal.of_real ε : ennreal), { simpa using ε0 },
rw ← hz at this, simpa [infi_lt_iff] },
refine is_null_measurable_iff.2 ⟨s \ Inter f,
diff_subset_diff_right (subset_Inter (λ i, (hf i).1)),
hs.diff (is_measurable.Inter (λ i, (hf i).2.1)),
measure_mono_null _ (le_zero_iff_eq.1 $ le_of_not_lt $ λ h, _)⟩,
{ exact Inter f },
{ rw [diff_subset_iff, diff_union_self],
exact subset.trans (diff_subset _ _) (subset_union_left _ _) },
rcases ennreal.lt_iff_exists_rat_btwn.1 h with ⟨ε, ε0', ε0, h⟩,
simp at ε0,
apply not_le_of_lt (lt_trans (hf ⟨ε, ε0⟩).2.2 h),
exact measure_mono (Inter_subset _ _)
end
theorem is_null_measurable.diff_null {s z : set α}
(hs : is_null_measurable μ s) (hz : μ z = 0) :
is_null_measurable μ (s \ z) :=
begin
rcases hs with ⟨t, z', rfl, ht, hz'⟩,
rw [set.union_diff_distrib],
exact (ht.diff_null hz).union_null (measure_mono_null (diff_subset _ _) hz')
end
theorem is_null_measurable.compl {s : set α}
(hs : is_null_measurable μ s) :
is_null_measurable μ sᶜ :=
begin
rcases hs with ⟨t, z, rfl, ht, hz⟩,
rw compl_union,
exact ht.compl.diff_null hz
end
/-- The measurable space of all null measurable sets. -/
def null_measurable {α : Type u} [measurable_space α]
(μ : measure α) : measurable_space α :=
{ is_measurable := is_null_measurable μ,
is_measurable_empty := is_measurable.empty.is_null_measurable _,
is_measurable_compl := λ s hs, hs.compl,
is_measurable_Union := λ f, is_null_measurable.Union_nat }
/-- Given a measure we can complete it to a (complete) measure on all null measurable sets. -/
def completion {α : Type u} [measurable_space α] (μ : measure α) :
@measure_theory.measure α (null_measurable μ) :=
{ to_outer_measure := μ.to_outer_measure,
m_Union := λ s hs hd, show μ (Union s) = ∑' i, μ (s i), begin
choose t ht using assume i, is_null_measurable_iff.1 (hs i),
simp [forall_and_distrib] at ht, rcases ht with ⟨st, ht, hz⟩,
rw is_null_measurable_measure_eq (Union_subset_Union st),
{ rw measure_Union _ ht,
{ congr, funext i,
exact (is_null_measurable_measure_eq (st i) (hz i)).symm },
{ rintro i j ij x ⟨h₁, h₂⟩,
exact hd i j ij ⟨st i h₁, st j h₂⟩ } },
{ refine measure_mono_null _ (measure_Union_null hz),
rw [diff_subset_iff, ← Union_union_distrib],
exact Union_subset_Union (λ i, by rw ← diff_subset_iff) }
end,
trimmed := begin
letI := null_measurable μ,
refine le_antisymm (λ s, _) (outer_measure.le_trim _),
rw outer_measure.trim_eq_infi,
dsimp,
clear _inst,
resetI,
rw measure_eq_infi s,
exact infi_le_infi (λ t, infi_le_infi $ λ st,
infi_le_infi2 $ λ ht, ⟨ht.is_null_measurable _, le_refl _⟩)
end }
instance completion.is_complete {α : Type u} [measurable_space α] (μ : measure α) :
(completion μ).is_complete :=
λ z hz, null_is_null_measurable hz
end is_complete
namespace measure_theory
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A measure space is a measurable space equipped with a
measure, referred to as `volume`. -/
class measure_space (α : Type*) extends measurable_space α :=
(volume : measure α)
end prio
export measure_space (volume)
/-- `volume` is the canonical measure on `α`. -/
add_decl_doc volume
section measure_space
variables {α : Type*} {ι : Type*} [measure_space α] {s₁ s₂ : set α}
notation `∀ᵐ` binders `, ` r:(scoped P, filter.eventually P (measure.ae volume)) := r
/-- The tactic `exact volume`, to be used in optional (`auto_param`) arguments. -/
meta def volume_tac : tactic unit := `[exact measure_theory.measure_space.volume]
end measure_space
end measure_theory
open measure_theory
namespace is_compact
variables {α : Type*} [topological_space α] [measurable_space α] {μ : measure α} {s : set α}
lemma finite_measure_of_nhds_within (hs : is_compact s) :
(∀ a ∈ s, μ.finite_at_filter (𝓝[s] a)) → μ s < ⊤ :=
by simpa only [← measure.compl_mem_cofinite, measure.finite_at_filter]
using hs.compl_mem_sets_of_nhds_within
lemma finite_measure [locally_finite_measure μ] (hs : is_compact s) : μ s < ⊤ :=
hs.finite_measure_of_nhds_within $ λ a ha, μ.finite_at_nhds_within _ _
lemma measure_zero_of_nhds_within (hs : is_compact s) :
(∀ a ∈ s, ∃ t ∈ 𝓝[s] a, μ t = 0) → μ s = 0 :=
by simpa only [← compl_mem_ae_iff] using hs.compl_mem_sets_of_nhds_within
end is_compact
lemma metric.bounded.finite_measure {α : Type*} [metric_space α] [proper_space α]
[measurable_space α] {μ : measure α} [locally_finite_measure μ] {s : set α}
(hs : metric.bounded s) :
μ s < ⊤ :=
(measure_mono subset_closure).trans_lt (metric.compact_iff_closed_bounded.2
⟨is_closed_closure, metric.bounded_closure_of_bounded hs⟩).finite_measure
|
54be6009bb4a079cbda3640fb8ad9f24794192f1
|
12dabd587ce2621d9a4eff9f16e354d02e206c8e
|
/world04/level02.lean
|
c029c13fae6bc33f976967d7293fc93bacf0d2e1
|
[] |
no_license
|
abdelq/natural-number-game
|
a1b5b8f1d52625a7addcefc97c966d3f06a48263
|
bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2
|
refs/heads/master
| 1,668,606,478,691
| 1,594,175,058,000
| 1,594,175,058,000
| 278,673,209
| 0
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 101
|
lean
|
lemma zero_pow_succ (m : mynat) : (0 : mynat) ^ (succ m) = 0 :=
begin
rw pow_succ,
rwa mul_zero,
end
|
08ecc6b0ad16cf7d1e3044f14f6d077c22749630
|
69d4931b605e11ca61881fc4f66db50a0a875e39
|
/src/topology/separation.lean
|
cce5ab6d60ad7f131a8bcff6f07af21705ca5b56
|
[
"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
| 48,731
|
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
Separation properties of topological spaces.
-/
import topology.subset_properties
import topology.connected
open set filter
open_locale topological_space filter
local attribute [instance] classical.prop_decidable -- TODO: use "open_locale classical"
universes u v
variables {α : Type u} {β : Type v} [topological_space α]
section separation
/--
`separated` is a predicate on pairs of sub`set`s of a topological space. It holds if the two
sub`set`s are contained in disjoint open sets.
-/
def separated : set α → set α → Prop :=
λ (s t : set α), ∃ U V : (set α), (is_open U) ∧ is_open V ∧
(s ⊆ U) ∧ (t ⊆ V) ∧ disjoint U V
namespace separated
open separated
@[symm] lemma symm {s t : set α} : separated s t → separated t s :=
λ ⟨U, V, oU, oV, aU, bV, UV⟩, ⟨V, U, oV, oU, bV, aU, disjoint.symm UV⟩
lemma comm (s t : set α) : separated s t ↔ separated t s :=
⟨symm, symm⟩
lemma empty_right (a : set α) : separated a ∅ :=
⟨_, _, is_open_univ, is_open_empty, λ a h, mem_univ a, λ a h, by cases h, disjoint_empty _⟩
lemma empty_left (a : set α) : separated ∅ a :=
(empty_right _).symm
lemma union_left {a b c : set α} : separated a c → separated b c → separated (a ∪ b) c :=
λ ⟨U, V, oU, oV, aU, bV, UV⟩ ⟨W, X, oW, oX, aW, bX, WX⟩,
⟨U ∪ W, V ∩ X, is_open.union oU oW, is_open.inter oV oX,
union_subset_union aU aW, subset_inter bV bX, set.disjoint_union_left.mpr
⟨disjoint_of_subset_right (inter_subset_left _ _) UV,
disjoint_of_subset_right (inter_subset_right _ _) WX⟩⟩
lemma union_right {a b c : set α} (ab : separated a b) (ac : separated a c) :
separated a (b ∪ c) :=
(ab.symm.union_left ac.symm).symm
end separated
/-- A T₀ space, also known as a Kolmogorov space, is a topological space
where for every pair `x ≠ y`, there is an open set containing one but not the other. -/
class t0_space (α : Type u) [topological_space α] : Prop :=
(t0 : ∀ x y, x ≠ y → ∃ U:set α, is_open U ∧ (xor (x ∈ U) (y ∈ U)))
theorem is_closed.exists_closed_singleton {α : Type*} [topological_space α]
[t0_space α] [compact_space α] {S : set α} (hS : is_closed S) (hne : S.nonempty) :
∃ (x : α), x ∈ S ∧ is_closed ({x} : set α) :=
begin
obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne,
by_cases hnt : ∃ (x y : α) (hx : x ∈ V) (hy : y ∈ V), x ≠ y,
{ exfalso,
obtain ⟨x, y, hx, hy, hne⟩ := hnt,
obtain ⟨U, hU, hsep⟩ := t0_space.t0 _ _ hne,
have : ∀ (z w : α) (hz : z ∈ V) (hw : w ∈ V) (hz' : z ∈ U) (hw' : ¬ w ∈ U), false,
{ intros z w hz hw hz' hw',
have uvne : (V ∩ Uᶜ).nonempty,
{ use w, simp only [hw, hw', set.mem_inter_eq, not_false_iff, and_self, set.mem_compl_eq], },
specialize hV (V ∩ Uᶜ) (set.inter_subset_left _ _) uvne
(is_closed.inter Vcls (is_closed_compl_iff.mpr hU)),
have : V ⊆ Uᶜ,
{ rw ←hV, exact set.inter_subset_right _ _ },
exact this hz hz', },
cases hsep,
{ exact this x y hx hy hsep.1 hsep.2 },
{ exact this y x hy hx hsep.1 hsep.2 } },
{ push_neg at hnt,
obtain ⟨z, hz⟩ := Vne,
refine ⟨z, Vsub hz, _⟩,
convert Vcls,
ext,
simp only [set.mem_singleton_iff, set.mem_compl_eq],
split,
{ rintro rfl, exact hz, },
{ exact λ hx, hnt x z hx hz, }, },
end
theorem exists_open_singleton_of_open_finset [t0_space α] (s : finset α) (sne : s.nonempty)
(hso : is_open (↑s : set α)) :
∃ x ∈ s, is_open ({x} : set α):=
begin
induction s using finset.strong_induction_on with s ihs,
by_cases hs : set.subsingleton (↑s : set α),
{ rcases sne with ⟨x, hx⟩,
refine ⟨x, hx, _⟩,
have : (↑s : set α) = {x}, from hs.eq_singleton_of_mem hx,
rwa this at hso },
{ dunfold set.subsingleton at hs,
push_neg at hs,
rcases hs with ⟨x, hx, y, hy, hxy⟩,
rcases t0_space.t0 x y hxy with ⟨U, hU, hxyU⟩,
wlog H : x ∈ U ∧ y ∉ U := hxyU using [x y, y x],
obtain ⟨z, hzs, hz⟩ : ∃ z ∈ s.filter (λ z, z ∈ U), is_open ({z} : set α),
{ refine ihs _ (finset.filter_ssubset.2 ⟨y, hy, H.2⟩) ⟨x, finset.mem_filter.2 ⟨hx, H.1⟩⟩ _,
rw [finset.coe_filter],
exact is_open.inter hso hU },
exact ⟨z, (finset.mem_filter.1 hzs).1, hz⟩ }
end
theorem exists_open_singleton_of_fintype [t0_space α] [f : fintype α] [ha : nonempty α] :
∃ x:α, is_open ({x}:set α) :=
begin
refine ha.elim (λ x, _),
have : is_open (↑(finset.univ : finset α) : set α), { simp },
rcases exists_open_singleton_of_open_finset _ ⟨x, finset.mem_univ x⟩ this with ⟨x, _, hx⟩,
exact ⟨x, hx⟩
end
instance subtype.t0_space [t0_space α] {p : α → Prop} : t0_space (subtype p) :=
⟨λ x y hxy, let ⟨U, hU, hxyU⟩ := t0_space.t0 (x:α) y ((not_congr subtype.ext_iff_val).1 hxy) in
⟨(coe : subtype p → α) ⁻¹' U, is_open_induced hU, hxyU⟩⟩
/-- A T₁ space, also known as a Fréchet space, is a topological space
where every singleton set is closed. Equivalently, for every pair
`x ≠ y`, there is an open set containing `x` and not `y`. -/
class t1_space (α : Type u) [topological_space α] : Prop :=
(t1 : ∀x, is_closed ({x} : set α))
lemma is_closed_singleton [t1_space α] {x : α} : is_closed ({x} : set α) :=
t1_space.t1 x
lemma is_open_compl_singleton [t1_space α] {x : α} : is_open ({x}ᶜ : set α) :=
is_closed_singleton.is_open_compl
lemma is_open_ne [t1_space α] {x : α} : is_open {y | y ≠ x} :=
is_open_compl_singleton
instance subtype.t1_space {α : Type u} [topological_space α] [t1_space α] {p : α → Prop} :
t1_space (subtype p) :=
⟨λ ⟨x, hx⟩, is_closed_induced_iff.2 $ ⟨{x}, is_closed_singleton, set.ext $ λ y,
by simp [subtype.ext_iff_val]⟩⟩
@[priority 100] -- see Note [lower instance priority]
instance t1_space.t0_space [t1_space α] : t0_space α :=
⟨λ x y h, ⟨{z | z ≠ y}, is_open_ne, or.inl ⟨h, not_not_intro rfl⟩⟩⟩
lemma t1_iff_exists_open : t1_space α ↔
∀ (x y), x ≠ y → (∃ (U : set α) (hU : is_open U), x ∈ U ∧ y ∉ U) :=
begin
split,
{ introsI t1 x y hxy,
exact ⟨{y}ᶜ, is_open_compl_iff.mpr (t1_space.t1 y),
mem_compl_singleton_iff.mpr hxy,
not_not.mpr rfl⟩},
{ intro h,
constructor,
intro x,
rw ← is_open_compl_iff,
have p : ⋃₀ {U : set α | (x ∉ U) ∧ (is_open U)} = {x}ᶜ,
{ apply subset.antisymm; intros t ht,
{ rcases ht with ⟨A, ⟨hxA, hA⟩, htA⟩,
rw [mem_compl_eq, mem_singleton_iff],
rintro rfl,
contradiction },
{ obtain ⟨U, hU, hh⟩ := h t x (mem_compl_singleton_iff.mp ht),
exact ⟨U, ⟨hh.2, hU⟩, hh.1⟩}},
rw ← p,
exact is_open_sUnion (λ B hB, hB.2) }
end
lemma compl_singleton_mem_nhds [t1_space α] {x y : α} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y :=
is_open.mem_nhds is_open_compl_singleton $ by rwa [mem_compl_eq, mem_singleton_iff]
@[simp] lemma closure_singleton [t1_space α] {a : α} :
closure ({a} : set α) = {a} :=
is_closed_singleton.closure_eq
lemma set.subsingleton.closure [t1_space α] {s : set α} (hs : s.subsingleton) :
(closure s).subsingleton :=
hs.induction_on (by simp) $ λ x, by simp
@[simp] lemma subsingleton_closure [t1_space α] {s : set α} :
(closure s).subsingleton ↔ s.subsingleton :=
⟨λ h, h.mono subset_closure, λ h, h.closure⟩
lemma is_closed_map_const {α β} [topological_space α] [topological_space β] [t1_space β] {y : β} :
is_closed_map (function.const α y) :=
begin
apply is_closed_map.of_nonempty, intros s hs h2s, simp_rw [h2s.image_const, is_closed_singleton]
end
lemma discrete_of_t1_of_finite {X : Type*} [topological_space X] [t1_space X] [fintype X] :
discrete_topology X :=
begin
apply singletons_open_iff_discrete.mp,
intros x,
rw [← is_closed_compl_iff, ← bUnion_of_singleton ({x} : set X)ᶜ],
exact is_closed_bUnion (finite.of_fintype _) (λ y _, is_closed_singleton)
end
lemma singleton_mem_nhds_within_of_mem_discrete {s : set α} [discrete_topology s]
{x : α} (hx : x ∈ s) :
{x} ∈ 𝓝[s] x :=
begin
have : ({⟨x, hx⟩} : set s) ∈ 𝓝 (⟨x, hx⟩ : s), by simp [nhds_discrete],
simpa only [nhds_within_eq_map_subtype_coe hx, image_singleton]
using @image_mem_map _ _ _ (coe : s → α) _ this
end
lemma nhds_within_of_mem_discrete {s : set α} [discrete_topology s] {x : α} (hx : x ∈ s) :
𝓝[s] x = pure x :=
le_antisymm (le_pure_iff.2 $ singleton_mem_nhds_within_of_mem_discrete hx) (pure_le_nhds_within hx)
lemma filter.has_basis.exists_inter_eq_singleton_of_mem_discrete
{ι : Type*} {p : ι → Prop} {t : ι → set α} {s : set α} [discrete_topology s] {x : α}
(hb : (𝓝 x).has_basis p t) (hx : x ∈ s) :
∃ i (hi : p i), t i ∩ s = {x} :=
begin
rcases (nhds_within_has_basis hb s).mem_iff.1 (singleton_mem_nhds_within_of_mem_discrete hx)
with ⟨i, hi, hix⟩,
exact ⟨i, hi, subset.antisymm hix $ singleton_subset_iff.2
⟨mem_of_mem_nhds $ hb.mem_of_mem hi, hx⟩⟩
end
/-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood
that only meets `s` at `x`. -/
lemma nhds_inter_eq_singleton_of_mem_discrete {s : set α} [discrete_topology s]
{x : α} (hx : x ∈ s) :
∃ U ∈ 𝓝 x, U ∩ s = {x} :=
by simpa using (𝓝 x).basis_sets.exists_inter_eq_singleton_of_mem_discrete hx
/-- For point `x` in a discrete subset `s` of a topological space, there is a set `U`
such that
1. `U` is a punctured neighborhood of `x` (ie. `U ∪ {x}` is a neighbourhood of `x`),
2. `U` is disjoint from `s`.
-/
lemma disjoint_nhds_within_of_mem_discrete {s : set α} [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ U ∈ 𝓝[{x}ᶜ] x, disjoint U s :=
let ⟨V, h, h'⟩ := nhds_inter_eq_singleton_of_mem_discrete hx in
⟨{x}ᶜ ∩ V, inter_mem_nhds_within _ h,
(disjoint_iff_inter_eq_empty.mpr (by { rw [inter_assoc, h', compl_inter_self] }))⟩
/-- Let `X` be a topological space and let `s, t ⊆ X` be two subsets. If there is an inclusion
`t ⊆ s`, then the topological space structure on `t` induced by `X` is the same as the one
obtained by the induced topological space structure on `s`. -/
lemma topological_space.subset_trans {X : Type*} [tX : topological_space X]
{s t : set X} (ts : t ⊆ s) :
(subtype.topological_space : topological_space t) =
(subtype.topological_space : topological_space s).induced (set.inclusion ts) :=
begin
change tX.induced ((coe : s → X) ∘ (set.inclusion ts)) =
topological_space.induced (set.inclusion ts) (tX.induced _),
rw ← induced_compose,
end
/-- This lemma characterizes discrete topological spaces as those whose singletons are
neighbourhoods. -/
lemma discrete_topology_iff_nhds {X : Type*} [topological_space X] :
discrete_topology X ↔ (nhds : X → filter X) = pure :=
begin
split,
{ introI hX,
exact nhds_discrete X },
{ intro h,
constructor,
apply eq_of_nhds_eq_nhds,
simp [h, nhds_bot] }
end
/-- The topology pulled-back under an inclusion `f : X → Y` from the discrete topology (`⊥`) is the
discrete topology.
This version does not assume the choice of a topology on either the source `X`
nor the target `Y` of the inclusion `f`. -/
lemma induced_bot {X Y : Type*} {f : X → Y} (hf : function.injective f) :
topological_space.induced f ⊥ = ⊥ :=
eq_of_nhds_eq_nhds (by simp [nhds_induced, ← set.image_singleton, hf.preimage_image, nhds_bot])
/-- The topology induced under an inclusion `f : X → Y` from the discrete topological space `Y`
is the discrete topology on `X`. -/
lemma discrete_topology_induced {X Y : Type*} [tY : topological_space Y] [discrete_topology Y]
{f : X → Y} (hf : function.injective f) : @discrete_topology X (topological_space.induced f tY) :=
begin
constructor,
rw discrete_topology.eq_bot Y,
exact induced_bot hf
end
/-- Let `s, t ⊆ X` be two subsets of a topological space `X`. If `t ⊆ s` and the topology induced
by `X`on `s` is discrete, then also the topology induces on `t` is discrete. -/
lemma discrete_topology.of_subset {X : Type*} [topological_space X] {s t : set X}
(ds : discrete_topology s) (ts : t ⊆ s) :
discrete_topology t :=
begin
rw [topological_space.subset_trans ts, ds.eq_bot],
exact {eq_bot := induced_bot (set.inclusion_injective ts)}
end
/-- A T₂ space, also known as a Hausdorff space, is one in which for every
`x ≠ y` there exists disjoint open sets around `x` and `y`. This is
the most widely used of the separation axioms. -/
class t2_space (α : Type u) [topological_space α] : Prop :=
(t2 : ∀x y, x ≠ y → ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅)
lemma t2_separation [t2_space α] {x y : α} (h : x ≠ y) :
∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
t2_space.t2 x y h
@[priority 100] -- see Note [lower instance priority]
instance t2_space.t1_space [t2_space α] : t1_space α :=
⟨λ x, is_open_compl_iff.1 $ is_open_iff_forall_mem_open.2 $ λ y hxy,
let ⟨u, v, hu, hv, hyu, hxv, huv⟩ := t2_separation (mt mem_singleton_of_eq hxy) in
⟨u, λ z hz1 hz2, (ext_iff.1 huv x).1 ⟨mem_singleton_iff.1 hz2 ▸ hz1, hxv⟩, hu, hyu⟩⟩
lemma eq_of_nhds_ne_bot [ht : t2_space α] {x y : α} (h : ne_bot (𝓝 x ⊓ 𝓝 y)) : x = y :=
classical.by_contradiction $ assume : x ≠ y,
let ⟨u, v, hu, hv, hx, hy, huv⟩ := t2_space.t2 x y this in
absurd huv $ (inf_ne_bot_iff.1 h (is_open.mem_nhds hu hx) (is_open.mem_nhds hv hy)).ne_empty
lemma t2_iff_nhds : t2_space α ↔ ∀ {x y : α}, ne_bot (𝓝 x ⊓ 𝓝 y) → x = y :=
⟨assume h, by exactI λ x y, eq_of_nhds_ne_bot,
assume h, ⟨assume x y xy,
have 𝓝 x ⊓ 𝓝 y = ⊥ := not_ne_bot.1 $ mt h xy,
let ⟨u', hu', v', hv', u'v'⟩ := empty_in_sets_eq_bot.mpr this,
⟨u, uu', uo, hu⟩ := mem_nhds_iff.mp hu',
⟨v, vv', vo, hv⟩ := mem_nhds_iff.mp hv' in
⟨u, v, uo, vo, hu, hv, disjoint.eq_bot $ disjoint.mono uu' vv' u'v'⟩⟩⟩
lemma t2_iff_ultrafilter :
t2_space α ↔ ∀ {x y : α} (f : ultrafilter α), ↑f ≤ 𝓝 x → ↑f ≤ 𝓝 y → x = y :=
t2_iff_nhds.trans $ by simp only [←exists_ultrafilter_iff, and_imp, le_inf_iff, exists_imp_distrib]
lemma is_closed_diagonal [t2_space α] : is_closed (diagonal α) :=
begin
refine is_closed_iff_cluster_pt.mpr _,
rintro ⟨a₁, a₂⟩ h,
refine eq_of_nhds_ne_bot ⟨λ this : 𝓝 a₁ ⊓ 𝓝 a₂ = ⊥, h.ne _⟩,
obtain ⟨t₁, (ht₁ : t₁ ∈ 𝓝 a₁), t₂, (ht₂ : t₂ ∈ 𝓝 a₂), (h' : t₁ ∩ t₂ ⊆ ∅)⟩ :=
by rw [←empty_in_sets_eq_bot, mem_inf_sets] at this; exact this,
rw [nhds_prod_eq, ←empty_in_sets_eq_bot],
apply filter.sets_of_superset,
apply inter_mem_inf_sets (prod_mem_prod ht₁ ht₂) (mem_principal_sets.mpr (subset.refl _)),
exact assume ⟨x₁, x₂⟩ ⟨⟨hx₁, hx₂⟩, (heq : x₁ = x₂)⟩,
show false, from @h' x₁ ⟨hx₁, heq.symm ▸ hx₂⟩
end
lemma t2_iff_is_closed_diagonal : t2_space α ↔ is_closed (diagonal α) :=
begin
split,
{ introI h,
exact is_closed_diagonal },
{ intro h,
constructor,
intros x y hxy,
have : (x, y) ∈ (diagonal α)ᶜ, by rwa [mem_compl_iff],
obtain ⟨t, t_sub, t_op, xyt⟩ : ∃ t ⊆ (diagonal α)ᶜ, is_open t ∧ (x, y) ∈ t :=
is_open_iff_forall_mem_open.mp h.is_open_compl _ this,
rcases is_open_prod_iff.mp t_op x y xyt with ⟨U, V, U_op, V_op, xU, yV, H⟩,
use [U, V, U_op, V_op, xU, yV],
have := subset.trans H t_sub,
rw eq_empty_iff_forall_not_mem,
rintros z ⟨zU, zV⟩,
have : ¬ (z, z) ∈ diagonal α := this (mk_mem_prod zU zV),
exact this rfl },
end
section separated
open separated finset
lemma finset_disjoint_finset_opens_of_t2 [t2_space α] :
∀ (s t : finset α), disjoint s t → separated (s : set α) t :=
begin
refine induction_on_union _ (λ a b hi d, (hi d.symm).symm) (λ a d, empty_right a) (λ a b ab, _) _,
{ obtain ⟨U, V, oU, oV, aU, bV, UV⟩ := t2_separation
(by { rw [ne.def, ← finset.mem_singleton], exact (disjoint_singleton.mp ab.symm) }),
refine ⟨U, V, oU, oV, _, _, set.disjoint_iff_inter_eq_empty.mpr UV⟩;
exact singleton_subset_set_iff.mpr ‹_› },
{ intros a b c ac bc d,
apply_mod_cast union_left (ac (disjoint_of_subset_left (a.subset_union_left b) d)) (bc _),
exact disjoint_of_subset_left (a.subset_union_right b) d },
end
lemma point_disjoint_finset_opens_of_t2 [t2_space α] {x : α} {s : finset α} (h : x ∉ s) :
separated ({x} : set α) ↑s :=
by exact_mod_cast finset_disjoint_finset_opens_of_t2 {x} s (singleton_disjoint.mpr h)
end separated
@[simp] lemma nhds_eq_nhds_iff {a b : α} [t2_space α] : 𝓝 a = 𝓝 b ↔ a = b :=
⟨assume h, eq_of_nhds_ne_bot $ by rw [h, inf_idem]; exact nhds_ne_bot, assume h, h ▸ rfl⟩
@[simp] lemma nhds_le_nhds_iff {a b : α} [t2_space α] : 𝓝 a ≤ 𝓝 b ↔ a = b :=
⟨assume h, eq_of_nhds_ne_bot $ by rw [inf_of_le_left h]; exact nhds_ne_bot, assume h, h ▸ le_refl _⟩
lemma tendsto_nhds_unique [t2_space α] {f : β → α} {l : filter β} {a b : α}
[ne_bot l] (ha : tendsto f l (𝓝 a)) (hb : tendsto f l (𝓝 b)) : a = b :=
eq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb
lemma tendsto_nhds_unique' [t2_space α] {f : β → α} {l : filter β} {a b : α}
(hl : ne_bot l) (ha : tendsto f l (𝓝 a)) (hb : tendsto f l (𝓝 b)) : a = b :=
eq_of_nhds_ne_bot $ ne_bot_of_le $ le_inf ha hb
lemma tendsto_nhds_unique_of_eventually_eq [t2_space α] {f g : β → α} {l : filter β} {a b : α}
[ne_bot l] (ha : tendsto f l (𝓝 a)) (hb : tendsto g l (𝓝 b)) (hfg : f =ᶠ[l] g) :
a = b :=
tendsto_nhds_unique (ha.congr' hfg) hb
lemma tendsto_const_nhds_iff [t2_space α] {l : filter α} [ne_bot l] {c d : α} :
tendsto (λ x, c) l (𝓝 d) ↔ c = d :=
⟨λ h, tendsto_nhds_unique (tendsto_const_nhds) h, λ h, h ▸ tendsto_const_nhds⟩
/-- A T2,5 space, also known as a Urysohn space, is a topological space
where for every pair `x ≠ y`, there are two open sets, with the intersection of clousures
empty, one containing `x` and the other `y` . -/
class t2_5_space (α : Type u) [topological_space α]: Prop :=
(t2_5 : ∀ x y (h : x ≠ y), ∃ (U V: set α), is_open U ∧ is_open V ∧
closure U ∩ closure V = ∅ ∧ x ∈ U ∧ y ∈ V)
@[priority 100] -- see Note [lower instance priority]
instance t2_5_space.t2_space [t2_5_space α] : t2_space α :=
⟨λ x y hxy,
let ⟨U, V, hU, hV, hUV, hh⟩ := t2_5_space.t2_5 x y hxy in
⟨U, V, hU, hV, hh.1, hh.2, subset_eq_empty (powerset_mono.mpr
(closure_inter_subset_inter_closure U V) subset_closure) hUV⟩⟩
section lim
variables [t2_space α] {f : filter α}
/-!
### Properties of `Lim` and `lim`
In this section we use explicit `nonempty α` instances for `Lim` and `lim`. This way the lemmas
are useful without a `nonempty α` instance.
-/
lemma Lim_eq {a : α} [ne_bot f] (h : f ≤ 𝓝 a) :
@Lim _ _ ⟨a⟩ f = a :=
tendsto_nhds_unique (le_nhds_Lim ⟨a, h⟩) h
lemma Lim_eq_iff [ne_bot f] (h : ∃ (a : α), f ≤ nhds a) {a} : @Lim _ _ ⟨a⟩ f = a ↔ f ≤ 𝓝 a :=
⟨λ c, c ▸ le_nhds_Lim h, Lim_eq⟩
lemma ultrafilter.Lim_eq_iff_le_nhds [compact_space α] {x : α} {F : ultrafilter α} :
F.Lim = x ↔ ↑F ≤ 𝓝 x :=
⟨λ h, h ▸ F.le_nhds_Lim, Lim_eq⟩
lemma is_open_iff_ultrafilter' [compact_space α] (U : set α) :
is_open U ↔ (∀ F : ultrafilter α, F.Lim ∈ U → U ∈ F.1) :=
begin
rw is_open_iff_ultrafilter,
refine ⟨λ h F hF, h F.Lim hF F F.le_nhds_Lim, _⟩,
intros cond x hx f h,
rw [← (ultrafilter.Lim_eq_iff_le_nhds.2 h)] at hx,
exact cond _ hx
end
lemma filter.tendsto.lim_eq {a : α} {f : filter β} [ne_bot f] {g : β → α} (h : tendsto g f (𝓝 a)) :
@lim _ _ _ ⟨a⟩ f g = a :=
Lim_eq h
lemma filter.lim_eq_iff {f : filter β} [ne_bot f] {g : β → α} (h : ∃ a, tendsto g f (𝓝 a)) {a} :
@lim _ _ _ ⟨a⟩ f g = a ↔ tendsto g f (𝓝 a) :=
⟨λ c, c ▸ tendsto_nhds_lim h, filter.tendsto.lim_eq⟩
lemma continuous.lim_eq [topological_space β] {f : β → α} (h : continuous f) (a : β) :
@lim _ _ _ ⟨f a⟩ (𝓝 a) f = f a :=
(h.tendsto a).lim_eq
@[simp] lemma Lim_nhds (a : α) : @Lim _ _ ⟨a⟩ (𝓝 a) = a :=
Lim_eq (le_refl _)
@[simp] lemma lim_nhds_id (a : α) : @lim _ _ _ ⟨a⟩ (𝓝 a) id = a :=
Lim_nhds a
@[simp] lemma Lim_nhds_within {a : α} {s : set α} (h : a ∈ closure s) :
@Lim _ _ ⟨a⟩ (𝓝[s] a) = a :=
by haveI : ne_bot (𝓝[s] a) := mem_closure_iff_cluster_pt.1 h;
exact Lim_eq inf_le_left
@[simp] lemma lim_nhds_within_id {a : α} {s : set α} (h : a ∈ closure s) :
@lim _ _ _ ⟨a⟩ (𝓝[s] a) id = a :=
Lim_nhds_within h
end lim
/-!
### Instances of `t2_space` typeclass
We use two lemmas to prove that various standard constructions generate Hausdorff spaces from
Hausdorff spaces:
* `separated_by_continuous` says that two points `x y : α` can be separated by open neighborhoods
provided that there exists a continuous map `f`: α → β` with a Hausdorff codomain such that
`f x ≠ f y`. We use this lemma to prove that topological spaces defined using `induced` are
Hausdorff spaces.
* `separated_by_open_embedding` says that for an open embedding `f : α → β` of a Hausdorff space
`α`, the images of two distinct points `x y : α`, `x ≠ y` can be separated by open neighborhoods.
We use this lemma to prove that topological spaces defined using `coinduced` are Hausdorff spaces.
-/
@[priority 100] -- see Note [lower instance priority]
instance t2_space_discrete {α : Type*} [topological_space α] [discrete_topology α] : t2_space α :=
{ t2 := assume x y hxy, ⟨{x}, {y}, is_open_discrete _, is_open_discrete _, rfl, rfl,
eq_empty_iff_forall_not_mem.2 $ by intros z hz;
cases eq_of_mem_singleton hz.1; cases eq_of_mem_singleton hz.2; cc⟩ }
lemma separated_by_continuous {α : Type*} {β : Type*}
[topological_space α] [topological_space β] [t2_space β]
{f : α → β} (hf : continuous f) {x y : α} (h : f x ≠ f y) :
∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h in
⟨f ⁻¹' u, f ⁻¹' v, uo.preimage hf, vo.preimage hf, xu, yv,
by rw [←preimage_inter, uv, preimage_empty]⟩
lemma separated_by_open_embedding {α β : Type*} [topological_space α] [topological_space β]
[t2_space α] {f : α → β} (hf : open_embedding f) {x y : α} (h : x ≠ y) :
∃ u v : set β, is_open u ∧ is_open v ∧ f x ∈ u ∧ f y ∈ v ∧ u ∩ v = ∅ :=
let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h in
⟨f '' u, f '' v, hf.is_open_map _ uo, hf.is_open_map _ vo,
mem_image_of_mem _ xu, mem_image_of_mem _ yv, by rw [image_inter hf.inj, uv, image_empty]⟩
instance {α : Type*} {p : α → Prop} [t : topological_space α] [t2_space α] : t2_space (subtype p) :=
⟨assume x y h, separated_by_continuous continuous_subtype_val (mt subtype.eq h)⟩
instance {α : Type*} {β : Type*} [t₁ : topological_space α] [t2_space α]
[t₂ : topological_space β] [t2_space β] : t2_space (α × β) :=
⟨assume ⟨x₁,x₂⟩ ⟨y₁,y₂⟩ h,
or.elim (not_and_distrib.mp (mt prod.ext_iff.mpr h))
(λ h₁, separated_by_continuous continuous_fst h₁)
(λ h₂, separated_by_continuous continuous_snd h₂)⟩
lemma embedding.t2_space [topological_space β] [t2_space β] {f : α → β} (hf : embedding f) :
t2_space α :=
⟨λ x y h, separated_by_continuous hf.continuous (hf.inj.ne h)⟩
instance {α : Type*} {β : Type*} [t₁ : topological_space α] [t2_space α]
[t₂ : topological_space β] [t2_space β] : t2_space (α ⊕ β) :=
begin
constructor,
rintros (x|x) (y|y) h,
{ replace h : x ≠ y := λ c, (c.subst h) rfl,
exact separated_by_open_embedding open_embedding_inl h },
{ exact ⟨_, _, is_open_range_inl, is_open_range_inr, ⟨x, rfl⟩, ⟨y, rfl⟩,
range_inl_inter_range_inr⟩ },
{ exact ⟨_, _, is_open_range_inr, is_open_range_inl, ⟨x, rfl⟩, ⟨y, rfl⟩,
range_inr_inter_range_inl⟩ },
{ replace h : x ≠ y := λ c, (c.subst h) rfl,
exact separated_by_open_embedding open_embedding_inr h }
end
instance Pi.t2_space {α : Type*} {β : α → Type v} [t₂ : Πa, topological_space (β a)]
[∀a, t2_space (β a)] :
t2_space (Πa, β a) :=
⟨assume x y h,
let ⟨i, hi⟩ := not_forall.mp (mt funext h) in
separated_by_continuous (continuous_apply i) hi⟩
instance sigma.t2_space {ι : Type*} {α : ι → Type*} [Πi, topological_space (α i)]
[∀a, t2_space (α a)] :
t2_space (Σi, α i) :=
begin
constructor,
rintros ⟨i, x⟩ ⟨j, y⟩ neq,
rcases em (i = j) with (rfl|h),
{ replace neq : x ≠ y := λ c, (c.subst neq) rfl,
exact separated_by_open_embedding open_embedding_sigma_mk neq },
{ exact ⟨_, _, is_open_range_sigma_mk, is_open_range_sigma_mk, ⟨x, rfl⟩, ⟨y, rfl⟩, by tidy⟩ }
end
variables [topological_space β]
lemma is_closed_eq [t2_space α] {f g : β → α}
(hf : continuous f) (hg : continuous g) : is_closed {x:β | f x = g x} :=
continuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_diagonal
/-- If two continuous maps are equal on `s`, then they are equal on the closure of `s`. -/
lemma set.eq_on.closure [t2_space α] {s : set β} {f g : β → α} (h : eq_on f g s)
(hf : continuous f) (hg : continuous g) :
eq_on f g (closure s) :=
closure_minimal h (is_closed_eq hf hg)
/-- If two continuous functions are equal on a dense set, then they are equal. -/
lemma continuous.ext_on [t2_space α] {s : set β} (hs : dense s) {f g : β → α}
(hf : continuous f) (hg : continuous g) (h : eq_on f g s) :
f = g :=
funext $ λ x, h.closure hf hg (hs x)
lemma function.left_inverse.closed_range [t2_space α] {f : α → β} {g : β → α}
(h : function.left_inverse f g) (hf : continuous f) (hg : continuous g) :
is_closed (range g) :=
have eq_on (g ∘ f) id (closure $ range g),
from h.right_inv_on_range.eq_on.closure (hg.comp hf) continuous_id,
is_closed_of_closure_subset $ λ x hx,
calc x = g (f x) : (this hx).symm
... ∈ _ : mem_range_self _
lemma function.left_inverse.closed_embedding [t2_space α] {f : α → β} {g : β → α}
(h : function.left_inverse f g) (hf : continuous f) (hg : continuous g) :
closed_embedding g :=
⟨h.embedding hf hg, h.closed_range hf hg⟩
lemma diagonal_eq_range_diagonal_map {α : Type*} : {p:α×α | p.1 = p.2} = range (λx, (x,x)) :=
ext $ assume p, iff.intro
(assume h, ⟨p.1, prod.ext_iff.2 ⟨rfl, h⟩⟩)
(assume ⟨x, hx⟩, show p.1 = p.2, by rw ←hx)
lemma prod_subset_compl_diagonal_iff_disjoint {α : Type*} {s t : set α} :
set.prod s t ⊆ {p:α×α | p.1 = p.2}ᶜ ↔ s ∩ t = ∅ :=
by rw [eq_empty_iff_forall_not_mem, subset_compl_comm,
diagonal_eq_range_diagonal_map, range_subset_iff]; simp
lemma compact_compact_separated [t2_space α] {s t : set α}
(hs : is_compact s) (ht : is_compact t) (hst : s ∩ t = ∅) :
∃u v : set α, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ u ∩ v = ∅ :=
by simp only [prod_subset_compl_diagonal_iff_disjoint.symm] at ⊢ hst;
exact generalized_tube_lemma hs ht is_closed_diagonal.is_open_compl hst
/-- In a `t2_space`, every compact set is closed. -/
lemma is_compact.is_closed [t2_space α] {s : set α} (hs : is_compact s) : is_closed s :=
is_open_compl_iff.1 $ is_open_iff_forall_mem_open.mpr $ assume x hx,
let ⟨u, v, uo, vo, su, xv, uv⟩ :=
compact_compact_separated hs (is_compact_singleton : is_compact {x})
(by rwa [inter_comm, ←subset_compl_iff_disjoint, singleton_subset_iff]) in
have v ⊆ sᶜ, from
subset_compl_comm.mp (subset.trans su (subset_compl_iff_disjoint.mpr uv)),
⟨v, this, vo, by simpa using xv⟩
/-- If `V : ι → set α` is a decreasing family of compact sets then any neighborhood of
`⋂ i, V i` contains some `V i`. This is a version of `exists_subset_nhd_of_compact` where we
don't need to assume each `V i` closed because it follows from compactness since `α` is
assumed to be Hausdorff. -/
lemma exists_subset_nhd_of_compact [t2_space α] {ι : Type*} [nonempty ι] {V : ι → set α}
(hV : directed (⊇) V) (hV_cpct : ∀ i, is_compact (V i)) {U : set α}
(hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U :=
exists_subset_nhd_of_compact' hV hV_cpct (λ i, (hV_cpct i).is_closed) hU
lemma compact_exhaustion.is_closed [t2_space α] (K : compact_exhaustion α) (n : ℕ) :
is_closed (K n) :=
(K.is_compact n).is_closed
lemma is_compact.inter [t2_space α] {s t : set α} (hs : is_compact s) (ht : is_compact t) :
is_compact (s ∩ t) :=
hs.inter_right $ ht.is_closed
lemma compact_closure_of_subset_compact [t2_space α] {s t : set α} (ht : is_compact t) (h : s ⊆ t) :
is_compact (closure s) :=
compact_of_is_closed_subset ht is_closed_closure (closure_minimal h ht.is_closed)
lemma image_closure_of_compact [t2_space β]
{s : set α} (hs : is_compact (closure s)) {f : α → β} (hf : continuous_on f (closure s)) :
f '' closure s = closure (f '' s) :=
subset.antisymm hf.image_closure $ closure_minimal (image_subset f subset_closure)
(hs.image_of_continuous_on hf).is_closed
/-- If a compact set is covered by two open sets, then we can cover it by two compact subsets. -/
lemma is_compact.binary_compact_cover [t2_space α] {K U V : set α} (hK : is_compact K)
(hU : is_open U) (hV : is_open V) (h2K : K ⊆ U ∪ V) :
∃ K₁ K₂ : set α, is_compact K₁ ∧ is_compact K₂ ∧ K₁ ⊆ U ∧ K₂ ⊆ V ∧ K = K₁ ∪ K₂ :=
begin
rcases compact_compact_separated (hK.diff hU) (hK.diff hV)
(by rwa [diff_inter_diff, diff_eq_empty]) with ⟨O₁, O₂, h1O₁, h1O₂, h2O₁, h2O₂, hO⟩,
refine ⟨_, _, hK.diff h1O₁, hK.diff h1O₂,
by rwa [diff_subset_comm], by rwa [diff_subset_comm], by rw [← diff_inter, hO, diff_empty]⟩
end
lemma continuous.is_closed_map [compact_space α] [t2_space β] {f : α → β} (h : continuous f) :
is_closed_map f :=
λ s hs, (hs.is_compact.image h).is_closed
lemma continuous.closed_embedding [compact_space α] [t2_space β] {f : α → β} (h : continuous f)
(hf : function.injective f) : closed_embedding f :=
closed_embedding_of_continuous_injective_closed h hf h.is_closed_map
section
open finset function
/-- For every finite open cover `Uᵢ` of a compact set, there exists a compact cover `Kᵢ ⊆ Uᵢ`. -/
lemma is_compact.finite_compact_cover [t2_space α] {s : set α} (hs : is_compact s)
{ι} (t : finset ι) (U : ι → set α) (hU : ∀ i ∈ t, is_open (U i)) (hsC : s ⊆ ⋃ i ∈ t, U i) :
∃ K : ι → set α, (∀ i, is_compact (K i)) ∧ (∀i, K i ⊆ U i) ∧ s = ⋃ i ∈ t, K i :=
begin
classical,
induction t using finset.induction with x t hx ih generalizing U hU s hs hsC,
{ refine ⟨λ _, ∅, λ i, is_compact_empty, λ i, empty_subset _, _⟩, simpa only [subset_empty_iff,
finset.not_mem_empty, Union_neg, Union_empty, not_false_iff] using hsC },
simp only [finset.set_bUnion_insert] at hsC,
simp only [finset.mem_insert] at hU,
have hU' : ∀ i ∈ t, is_open (U i) := λ i hi, hU i (or.inr hi),
rcases hs.binary_compact_cover (hU x (or.inl rfl)) (is_open_bUnion hU') hsC
with ⟨K₁, K₂, h1K₁, h1K₂, h2K₁, h2K₂, hK⟩,
rcases ih U hU' h1K₂ h2K₂ with ⟨K, h1K, h2K, h3K⟩,
refine ⟨update K x K₁, _, _, _⟩,
{ intros i, by_cases hi : i = x,
{ simp only [update_same, hi, h1K₁] },
{ rw [← ne.def] at hi, simp only [update_noteq hi, h1K] }},
{ intros i, by_cases hi : i = x,
{ simp only [update_same, hi, h2K₁] },
{ rw [← ne.def] at hi, simp only [update_noteq hi, h2K] }},
{ simp only [set_bUnion_insert_update _ hx, hK, h3K] }
end
end
lemma locally_compact_of_compact_nhds [t2_space α] (h : ∀ x : α, ∃ s, s ∈ 𝓝 x ∧ is_compact s) :
locally_compact_space α :=
⟨assume x n hn,
let ⟨u, un, uo, xu⟩ := mem_nhds_iff.mp hn in
let ⟨k, kx, kc⟩ := h x in
-- K is compact but not necessarily contained in N.
-- K \ U is again compact and doesn't contain x, so
-- we may find open sets V, W separating x from K \ U.
-- Then K \ W is a compact neighborhood of x contained in U.
let ⟨v, w, vo, wo, xv, kuw, vw⟩ :=
compact_compact_separated is_compact_singleton (is_compact.diff kc uo)
(by rw [singleton_inter_eq_empty]; exact λ h, h.2 xu) in
have wn : wᶜ ∈ 𝓝 x, from
mem_nhds_iff.mpr
⟨v, subset_compl_iff_disjoint.mpr vw, vo, singleton_subset_iff.mp xv⟩,
⟨k \ w,
filter.inter_mem_sets kx wn,
subset.trans (diff_subset_comm.mp kuw) un,
kc.diff wo⟩⟩
@[priority 100] -- see Note [lower instance priority]
instance locally_compact_of_compact [t2_space α] [compact_space α] : locally_compact_space α :=
locally_compact_of_compact_nhds (assume x, ⟨univ, is_open_univ.mem_nhds trivial, compact_univ⟩)
/-- In a locally compact T₂ space, every point has an open neighborhood with compact closure -/
lemma exists_open_with_compact_closure [locally_compact_space α] [t2_space α] (x : α) :
∃ (U : set α), is_open U ∧ x ∈ U ∧ is_compact (closure U) :=
begin
rcases exists_compact_mem_nhds x with ⟨K, hKc, hxK⟩,
rcases mem_nhds_iff.1 hxK with ⟨t, h1t, h2t, h3t⟩,
exact ⟨t, h2t, h3t, compact_closure_of_subset_compact hKc h1t⟩
end
end separation
section regularity
/-- A T₃ space, also known as a regular space (although this condition sometimes
omits T₂), is one in which for every closed `C` and `x ∉ C`, there exist
disjoint open sets containing `x` and `C` respectively. -/
class regular_space (α : Type u) [topological_space α] extends t0_space α : Prop :=
(regular : ∀{s:set α} {a}, is_closed s → a ∉ s → ∃t, is_open t ∧ s ⊆ t ∧ 𝓝[t] a = ⊥)
@[priority 100] -- see Note [lower instance priority]
instance regular_space.t1_space [regular_space α] : t1_space α :=
begin
rw t1_iff_exists_open,
intros x y hxy,
obtain ⟨U, hU, h⟩ := t0_space.t0 x y hxy,
cases h,
{ exact ⟨U, hU, h⟩ },
{ obtain ⟨R, hR, hh⟩ := regular_space.regular (is_closed_compl_iff.mpr hU) (not_not.mpr h.1),
obtain ⟨V, hV, hhh⟩ := mem_nhds_iff.1 (filter.inf_principal_eq_bot.1 hh.2),
exact ⟨R, hR, hh.1 (mem_compl h.2), hV hhh.2⟩ }
end
lemma nhds_is_closed [regular_space α] {a : α} {s : set α} (h : s ∈ 𝓝 a) :
∃ t ∈ 𝓝 a, t ⊆ s ∧ is_closed t :=
let ⟨s', h₁, h₂, h₃⟩ := mem_nhds_iff.mp h in
have ∃t, is_open t ∧ s'ᶜ ⊆ t ∧ 𝓝[t] a = ⊥,
from regular_space.regular (is_closed_compl_iff.mpr h₂) (not_not_intro h₃),
let ⟨t, ht₁, ht₂, ht₃⟩ := this in
⟨tᶜ,
mem_sets_of_eq_bot $ by rwa [compl_compl],
subset.trans (compl_subset_comm.1 ht₂) h₁,
is_closed_compl_iff.mpr ht₁⟩
lemma closed_nhds_basis [regular_space α] (a : α) :
(𝓝 a).has_basis (λ s : set α, s ∈ 𝓝 a ∧ is_closed s) id :=
⟨λ t, ⟨λ t_in, let ⟨s, s_in, h_st, h⟩ := nhds_is_closed t_in in ⟨s, ⟨s_in, h⟩, h_st⟩,
λ ⟨s, ⟨s_in, hs⟩, hst⟩, mem_sets_of_superset s_in hst⟩⟩
instance subtype.regular_space [regular_space α] {p : α → Prop} : regular_space (subtype p) :=
⟨begin
intros s a hs ha,
rcases is_closed_induced_iff.1 hs with ⟨s, hs', rfl⟩,
rcases regular_space.regular hs' ha with ⟨t, ht, hst, hat⟩,
refine ⟨coe ⁻¹' t, is_open_induced ht, preimage_mono hst, _⟩,
rw [nhds_within, nhds_induced, ← comap_principal, ← comap_inf, ← nhds_within, hat, comap_bot]
end⟩
variable (α)
@[priority 100] -- see Note [lower instance priority]
instance regular_space.t2_space [regular_space α] : t2_space α :=
⟨λ x y hxy,
let ⟨s, hs, hys, hxs⟩ := regular_space.regular is_closed_singleton
(mt mem_singleton_iff.1 hxy),
⟨t, hxt, u, hsu, htu⟩ := empty_in_sets_eq_bot.2 hxs,
⟨v, hvt, hv, hxv⟩ := mem_nhds_iff.1 hxt in
⟨v, s, hv, hs, hxv, singleton_subset_iff.1 hys,
eq_empty_of_subset_empty $ λ z ⟨hzv, hzs⟩, htu ⟨hvt hzv, hsu hzs⟩⟩⟩
@[priority 100] -- see Note [lower instance priority]
instance regular_space.t2_5_space [regular_space α] : t2_5_space α :=
⟨λ x y hxy,
let ⟨U, V, hU, hV, hh_1, hh_2, hUV⟩ := t2_space.t2 x y hxy,
hxcV := not_not.mpr ((interior_maximal (subset_compl_iff_disjoint.mpr hUV) hU) hh_1),
⟨R, hR, hh⟩ := regular_space.regular is_closed_closure (by rwa closure_eq_compl_interior_compl),
⟨A, hA, hhh⟩ := mem_nhds_iff.1 (filter.inf_principal_eq_bot.1 hh.2) in
⟨A, V, hhh.1, hV, subset_eq_empty ((closure V).inter_subset_inter_left
(subset.trans (closure_minimal hA (is_closed_compl_iff.mpr hR)) (compl_subset_compl.mpr hh.1)))
(compl_inter_self (closure V)), hhh.2, hh_2⟩⟩
variable {α}
lemma disjoint_nested_nhds [regular_space α] {x y : α} (h : x ≠ y) :
∃ (U₁ V₁ ∈ 𝓝 x) (U₂ V₂ ∈ 𝓝 y), is_closed V₁ ∧ is_closed V₂ ∧ is_open U₁ ∧ is_open U₂ ∧
V₁ ⊆ U₁ ∧ V₂ ⊆ U₂ ∧ U₁ ∩ U₂ = ∅ :=
begin
rcases t2_separation h with ⟨U₁, U₂, U₁_op, U₂_op, x_in, y_in, H⟩,
rcases nhds_is_closed (is_open.mem_nhds U₁_op x_in) with ⟨V₁, V₁_in, h₁, V₁_closed⟩,
rcases nhds_is_closed (is_open.mem_nhds U₂_op y_in) with ⟨V₂, V₂_in, h₂, V₂_closed⟩,
use [U₁, V₁, mem_sets_of_superset V₁_in h₁, V₁_in,
U₂, V₂, mem_sets_of_superset V₂_in h₂, V₂_in],
tauto
end
end regularity
section normality
/-- A T₄ space, also known as a normal space (although this condition sometimes
omits T₂), is one in which for every pair of disjoint closed sets `C` and `D`,
there exist disjoint open sets containing `C` and `D` respectively. -/
class normal_space (α : Type u) [topological_space α] extends t1_space α : Prop :=
(normal : ∀ s t : set α, is_closed s → is_closed t → disjoint s t →
∃ u v, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v)
theorem normal_separation [normal_space α] {s t : set α}
(H1 : is_closed s) (H2 : is_closed t) (H3 : disjoint s t) :
∃ u v, is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v :=
normal_space.normal s t H1 H2 H3
theorem normal_exists_closure_subset [normal_space α] {s t : set α} (hs : is_closed s)
(ht : is_open t) (hst : s ⊆ t) :
∃ u, is_open u ∧ s ⊆ u ∧ closure u ⊆ t :=
begin
have : disjoint s tᶜ, from λ x ⟨hxs, hxt⟩, hxt (hst hxs),
rcases normal_separation hs (is_closed_compl_iff.2 ht) this
with ⟨s', t', hs', ht', hss', htt', hs't'⟩,
refine ⟨s', hs', hss',
subset.trans (closure_minimal _ (is_closed_compl_iff.2 ht')) (compl_subset_comm.1 htt')⟩,
exact λ x hxs hxt, hs't' ⟨hxs, hxt⟩
end
@[priority 100] -- see Note [lower instance priority]
instance normal_space.regular_space [normal_space α] : regular_space α :=
{ regular := λ s x hs hxs, let ⟨u, v, hu, hv, hsu, hxv, huv⟩ :=
normal_separation hs is_closed_singleton
(λ _ ⟨hx, hy⟩, hxs $ mem_of_eq_of_mem (eq_of_mem_singleton hy).symm hx) in
⟨u, hu, hsu, filter.empty_in_sets_eq_bot.1 $ filter.mem_inf_sets.2
⟨v, is_open.mem_nhds hv (singleton_subset_iff.1 hxv), u, filter.mem_principal_self u,
inter_comm u v ▸ huv⟩⟩ }
-- We can't make this an instance because it could cause an instance loop.
lemma normal_of_compact_t2 [compact_space α] [t2_space α] : normal_space α :=
begin
refine ⟨assume s t hs ht st, _⟩,
simp only [disjoint_iff],
exact compact_compact_separated hs.is_compact ht.is_compact st.eq_bot
end
end normality
/-- In a compact t2 space, the connected component of a point equals the intersection of all
its clopen neighbourhoods. -/
lemma connected_component_eq_Inter_clopen [t2_space α] [compact_space α] {x : α} :
connected_component x = ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z :=
begin
apply eq_of_subset_of_subset connected_component_subset_Inter_clopen,
-- Reduce to showing that the clopen intersection is connected.
refine is_preconnected.subset_connected_component _ (mem_Inter.2 (λ Z, Z.2.2)),
-- We do this by showing that any disjoint cover by two closed sets implies
-- that one of these closed sets must contain our whole thing.
-- To reduce to the case where the cover is disjoint on all of `α` we need that `s` is closed
have hs : @is_closed _ _inst_1 (⋂ (Z : {Z : set α // is_clopen Z ∧ x ∈ Z}), ↑Z) :=
is_closed_Inter (λ Z, Z.2.1.2),
rw (is_preconnected_iff_subset_of_fully_disjoint_closed hs),
intros a b ha hb hab ab_empty,
haveI := @normal_of_compact_t2 α _ _ _,
-- Since our space is normal, we get two larger disjoint open sets containing the disjoint
-- closed sets. If we can show that our intersection is a subset of any of these we can then
-- "descend" this to show that it is a subset of either a or b.
rcases normal_separation ha hb (disjoint_iff.2 ab_empty) with ⟨u, v, hu, hv, hau, hbv, huv⟩,
-- If we can find a clopen set around x, contained in u ∪ v, we get a disjoint decomposition
-- Z = Z ∩ u ∪ Z ∩ v of clopen sets. The intersection of all clopen neighbourhoods will then lie
-- in whichever of u or v x lies in and hence will be a subset of either a or b.
suffices : ∃ (Z : set α), is_clopen Z ∧ x ∈ Z ∧ Z ⊆ u ∪ v,
{ cases this with Z H,
rw [disjoint_iff_inter_eq_empty] at huv,
have H1 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hu hv huv,
rw [union_comm] at H,
have H2 := is_clopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hv hu (inter_comm u v ▸ huv),
by_cases (x ∈ u),
-- The x ∈ u case.
{ left,
suffices : (⋂ (Z : {Z : set α // is_clopen Z ∧ x ∈ Z}), ↑Z) ⊆ u,
{ rw ←set.disjoint_iff_inter_eq_empty at huv,
replace hab : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ a ∪ b := hab,
replace this : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ u := this,
exact disjoint.left_le_of_le_sup_right hab (huv.mono this hbv) },
{ apply subset.trans _ (inter_subset_right Z u),
apply Inter_subset (λ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, ↑Z)
⟨Z ∩ u, H1, mem_inter H.2.1 h⟩ } },
-- If x ∉ u, we get x ∈ v since x ∈ u ∪ v. The rest is then like the x ∈ u case.
have h1 : x ∈ v,
{ cases (mem_union x u v).1 (mem_of_subset_of_mem (subset.trans hab
(union_subset_union hau hbv)) (mem_Inter.2 (λ i, i.2.2))) with h1 h1,
{ exfalso, exact h h1},
{ exact h1} },
right,
suffices : (⋂ (Z : {Z : set α // is_clopen Z ∧ x ∈ Z}), ↑Z) ⊆ v,
{ rw [inter_comm, ←set.disjoint_iff_inter_eq_empty] at huv,
replace hab : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ a ∪ b := hab,
replace this : (⋂ (Z : {Z // is_clopen Z ∧ x ∈ Z}), ↑Z) ≤ v := this,
exact disjoint.left_le_of_le_sup_left hab (huv.mono this hau) },
{ apply subset.trans _ (inter_subset_right Z v),
apply Inter_subset (λ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, ↑Z)
⟨Z ∩ v, H2, mem_inter H.2.1 h1⟩ } },
-- Now we find the required Z. We utilize the fact that X \ u ∪ v will be compact,
-- so there must be some finite intersection of clopen neighbourhoods of X disjoint to it,
-- but a finite intersection of clopen sets is clopen so we let this be our Z.
have H1 := ((is_closed_compl_iff.2 (hu.union hv)).is_compact.inter_Inter_nonempty
(λ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z) (λ Z, Z.2.1.2)),
rw [←not_imp_not, not_forall, not_nonempty_iff_eq_empty, inter_comm] at H1,
have huv_union := subset.trans hab (union_subset_union hau hbv),
rw [← compl_compl (u ∪ v), subset_compl_iff_disjoint] at huv_union,
cases H1 huv_union with Zi H2,
refine ⟨(⋂ (U ∈ Zi), subtype.val U), _, _, _⟩,
{ exact is_clopen_bInter (λ Z hZ, Z.2.1) },
{ exact mem_bInter_iff.2 (λ Z hZ, Z.2.2) },
{ rwa [not_nonempty_iff_eq_empty, inter_comm, ←subset_compl_iff_disjoint, compl_compl] at H2 }
end
section profinite
open topological_space
variables [compact_space α] [t2_space α] [totally_disconnected_space α]
lemma nhds_basis_clopen (x : α) : (𝓝 x).has_basis (λ s : set α, x ∈ s ∧ is_clopen s) id :=
⟨λ U, begin
split,
{ have : connected_component x = {x},
from totally_disconnected_space_iff_connected_component_singleton.mp ‹_› x,
rw connected_component_eq_Inter_clopen at this,
intros hU,
let N := {Z // is_clopen Z ∧ x ∈ Z},
suffices : ∃ Z : N, Z.val ⊆ U,
{ rcases this with ⟨⟨s, hs, hs'⟩, hs''⟩,
exact ⟨s, ⟨hs', hs⟩, hs''⟩ },
haveI : nonempty N := ⟨⟨univ, is_clopen_univ, mem_univ x⟩⟩,
have hNcl : ∀ Z : N, is_closed Z.val := (λ Z, Z.property.1.2),
have hdir : directed superset (λ Z : N, Z.val),
{ rintros ⟨s, hs, hxs⟩ ⟨t, ht, hxt⟩,
exact ⟨⟨s ∩ t, hs.inter ht, ⟨hxs, hxt⟩⟩, inter_subset_left s t, inter_subset_right s t⟩ },
have h_nhd: ∀ y ∈ (⋂ Z : N, Z.val), U ∈ 𝓝 y,
{ intros y y_in,
erw [this, mem_singleton_iff] at y_in,
rwa y_in },
exact exists_subset_nhd_of_compact_space hdir hNcl h_nhd },
{ rintro ⟨V, ⟨hxV, V_op, -⟩, hUV : V ⊆ U⟩,
rw mem_nhds_iff,
exact ⟨V, hUV, V_op, hxV⟩ }
end⟩
lemma is_topological_basis_clopen : is_topological_basis {s : set α | is_clopen s} :=
begin
apply is_topological_basis_of_open_of_nhds (λ U (hU : is_clopen U), hU.1),
intros x U hxU U_op,
have : U ∈ 𝓝 x,
from is_open.mem_nhds U_op hxU,
rcases (nhds_basis_clopen x).mem_iff.mp this with ⟨V, ⟨hxV, hV⟩, hVU : V ⊆ U⟩,
use V,
tauto
end
end profinite
section connected_component_setoid
local attribute [instance] connected_component_setoid
/-- `connected_components α` is Hausdorff when `α` is Hausdorff and compact -/
instance connected_components.t2 [t2_space α] [compact_space α] :
t2_space (connected_components α) :=
begin
-- Proof follows that of: https://stacks.math.columbia.edu/tag/0900
-- Fix 2 distinct connected components, with points a and b
refine ⟨λ x y, quotient.induction_on x (quotient.induction_on y (λ a b ne, _))⟩,
rw connected_component_nrel_iff at ne,
have h := connected_component_disjoint ne,
-- write ⟦b⟧ as the intersection of all clopen subsets containing it
rw [connected_component_eq_Inter_clopen, disjoint_iff_inter_eq_empty, inter_comm] at h,
-- Now we show that this can be reduced to some clopen containing ⟦b⟧ being disjoint to ⟦a⟧
cases is_closed_connected_component.is_compact.elim_finite_subfamily_closed _ _ h
with fin_a ha,
swap, { exact λ Z, Z.2.1.2 },
set U : set α := (⋂ (i : {Z // is_clopen Z ∧ b ∈ Z}) (H : i ∈ fin_a), ↑i) with hU,
rw ←hU at ha,
have hu_clopen : is_clopen U := is_clopen_bInter (λ i j, i.2.1),
-- This clopen and its complement will separate the points corresponding to ⟦a⟧ and ⟦b⟧
use [quotient.mk '' U, quotient.mk '' Uᶜ],
-- Using the fact that clopens are unions of connected components, we show that
-- U and Uᶜ is the preimage of a clopen set in the quotient
have hu : quotient.mk ⁻¹' (quotient.mk '' U) = U :=
(connected_components_preimage_image U ▸ eq.symm) hu_clopen.eq_union_connected_components,
have huc : quotient.mk ⁻¹' (quotient.mk '' Uᶜ) = Uᶜ :=
(connected_components_preimage_image Uᶜ ▸ eq.symm)
(is_clopen.compl hu_clopen).eq_union_connected_components,
-- showing that U and Uᶜ are open and separates ⟦a⟧ and ⟦b⟧
refine ⟨_,_,_,_,_⟩,
{ rw [(quotient_map_iff.1 quotient_map_quotient_mk).2 _, hu],
exact hu_clopen.1 },
{ rw [(quotient_map_iff.1 quotient_map_quotient_mk).2 _, huc],
exact is_open_compl_iff.2 hu_clopen.2 },
{ exact mem_image_of_mem _ (mem_Inter.2 (λ Z, mem_Inter.2 (λ Zmem, Z.2.2))) },
{ apply mem_image_of_mem,
exact mem_of_subset_of_mem (subset_compl_iff_disjoint.2 ha) (@mem_connected_component _ _ a) },
apply preimage_injective.2 (@surjective_quotient_mk _ _),
rw [preimage_inter, preimage_empty, hu, huc, inter_compl_self _],
end
end connected_component_setoid
|
d4dd10f24ef01ff6458845bd265c4974eb6da07f
|
500f65bb93c499cd35c3254d894d762208cae042
|
/test/sanity_check.lean
|
ab889b73c302cb08ac8106b17d6ae774e8be2a22
|
[
"Apache-2.0"
] |
permissive
|
PatrickMassot/mathlib
|
c39dc0ff18bbde42f1c93a1642f6e429adad538c
|
45df75b3c9da159fe3192fa7f769dfbec0bd6bda
|
refs/heads/master
| 1,623,168,646,390
| 1,566,940,765,000
| 1,566,940,765,000
| 115,220,590
| 0
| 1
| null | 1,514,061,524,000
| 1,514,061,524,000
| null |
UTF-8
|
Lean
| false
| false
| 888
|
lean
|
import tactic.sanity_check
def foo1 (n m : ℕ) : ℕ := n + 1
def foo2 (n m : ℕ) : m = m := by refl
lemma foo3 (n m : ℕ) : ℕ := n - m
lemma foo4 (n m : ℕ) : n ≤ n := by refl
run_cmd do
let t := name × list ℕ,
e ← fold_over_with_cond
(λ d, d.in_current_file >>= λ b, if b then return (check_unused_arguments d) else return none),
guard $ e.length = 3,
let e2 : list t := e.map $ λ x, ⟨x.1.to_name, x.2⟩,
guard $ (⟨`foo1, [2]⟩ : t) ∈ e2,
guard $ (⟨`foo2, [1]⟩ : t) ∈ e2,
guard $ (⟨`foo4, [2]⟩ : t) ∈ e2
run_cmd do
e ← fold_over_with_cond
(λ d, d.in_current_file >>= λ b, if b then incorrect_def_lemma d else return none),
guard $ e.length = 2,
let e2 : list (name × _) := e.map $ λ x, ⟨x.1.to_name, x.2⟩,
guard $ ∃(x ∈ e2), (x : name × _).1 = `foo2,
guard $ ∃(x ∈ e2), (x : name × _).1 = `foo3
|
d1646ddda99ba43397e75d04c7c70b1c569e775a
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/topology/constructions.lean
|
12f3bc9a2658f4c92a356c392884af0f336cb80d
|
[
"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
| 54,228
|
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, Patrick Massot
-/
import topology.maps
import order.filter.pi
import data.fin.tuple
/-!
# Constructions of new topological spaces from old ones
This file constructs products, sums, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, sum, disjoint union, subspace, quotient space
-/
noncomputable theory
open topological_space set filter
open_locale classical topological_space filter
universes u v
variables {α : Type u} {β : Type v} {γ δ ε ζ : Type*}
section constructions
instance {p : α → Prop} [t : topological_space α] : topological_space (subtype p) :=
induced coe t
instance {r : α → α → Prop} [t : topological_space α] : topological_space (quot r) :=
coinduced (quot.mk r) t
instance {s : setoid α} [t : topological_space α] : topological_space (quotient s) :=
coinduced quotient.mk t
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α × β) :=
induced prod.fst t₁ ⊓ induced prod.snd t₂
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α ⊕ β) :=
coinduced sum.inl t₁ ⊔ coinduced sum.inr t₂
instance {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (sigma β) :=
⨆a, coinduced (sigma.mk a) (t₂ a)
instance Pi.topological_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] :
topological_space (Πa, β a) :=
⨅a, induced (λf, f a) (t₂ a)
instance ulift.topological_space [t : topological_space α] : topological_space (ulift.{v u} α) :=
t.induced ulift.down
lemma quotient.preimage_mem_nhds [topological_space α] [s : setoid α]
{V : set $ quotient s} {a : α} (hs : V ∈ 𝓝 (quotient.mk a)) : quotient.mk ⁻¹' V ∈ 𝓝 a :=
preimage_nhds_coinduced hs
/-- The image of a dense set under `quotient.mk` is a dense set. -/
lemma dense.quotient [setoid α] [topological_space α] {s : set α} (H : dense s) :
dense (quotient.mk '' s) :=
(surjective_quotient_mk α).dense_range.dense_image continuous_coinduced_rng H
/-- The composition of `quotient.mk` and a function with dense range has dense range. -/
lemma dense_range.quotient [setoid α] [topological_space α] {f : β → α} (hf : dense_range f) :
dense_range (quotient.mk ∘ f) :=
(surjective_quotient_mk α).dense_range.comp hf continuous_coinduced_rng
instance {p : α → Prop} [topological_space α] [discrete_topology α] :
discrete_topology (subtype p) :=
⟨bot_unique $ assume s hs,
⟨coe '' s, is_open_discrete _, (set.preimage_image_eq _ subtype.coe_injective)⟩⟩
instance sum.discrete_topology [topological_space α] [topological_space β]
[hα : discrete_topology α] [hβ : discrete_topology β] : discrete_topology (α ⊕ β) :=
⟨by unfold sum.topological_space; simp [hα.eq_bot, hβ.eq_bot]⟩
instance sigma.discrete_topology {β : α → Type v} [Πa, topological_space (β a)]
[h : Πa, discrete_topology (β a)] : discrete_topology (sigma β) :=
⟨by { unfold sigma.topological_space, simp [λ a, (h a).eq_bot] }⟩
section topα
variable [topological_space α]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : set α) (a : {x // x ∈ s}) (t : set {x // x ∈ s}) :
t ∈ 𝓝 a ↔ ∃ u ∈ 𝓝 (a : α), coe ⁻¹' u ⊆ t :=
mem_nhds_induced coe a t
theorem nhds_subtype (s : set α) (a : {x // x ∈ s}) :
𝓝 a = comap coe (𝓝 (a : α)) :=
nhds_induced coe a
end topα
/-- A type synonym equiped with the topology whose open sets are the empty set and the sets with
finite complements. -/
def cofinite_topology (α : Type*) := α
namespace cofinite_topology
/-- The identity equivalence between `α` and `cofinite_topology α`. -/
def of : α ≃ cofinite_topology α := equiv.refl α
instance [inhabited α] : inhabited (cofinite_topology α) :=
{ default := of default }
instance : topological_space (cofinite_topology α) :=
{ is_open := λ s, s.nonempty → set.finite sᶜ,
is_open_univ := by simp,
is_open_inter := λ s t, begin
classical,
rintros hs ht ⟨x, hxs, hxt⟩,
haveI := set.finite.fintype (hs ⟨x, hxs⟩),
haveI := set.finite.fintype (ht ⟨x, hxt⟩),
rw compl_inter,
exact set.finite.intro (sᶜ.fintype_union tᶜ),
end,
is_open_sUnion := begin
rintros s h ⟨x, t, hts, hzt⟩,
rw set.compl_sUnion,
apply set.finite.sInter _ (h t hts ⟨x, hzt⟩),
simp [hts]
end }
lemma is_open_iff {s : set (cofinite_topology α)} :
is_open s ↔ (s.nonempty → (sᶜ).finite) := iff.rfl
lemma is_open_iff' {s : set (cofinite_topology α)} :
is_open s ↔ (s = ∅ ∨ (sᶜ).finite) :=
by simp only [is_open_iff, ← ne_empty_iff_nonempty, or_iff_not_imp_left]
lemma is_closed_iff {s : set (cofinite_topology α)} :
is_closed s ↔ s = univ ∨ s.finite :=
by simp [← is_open_compl_iff, is_open_iff']
lemma nhds_eq (a : cofinite_topology α) : 𝓝 a = pure a ⊔ cofinite :=
begin
ext U,
rw mem_nhds_iff,
split,
{ rintro ⟨V, hVU, V_op, haV⟩,
exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩ },
{ rintros ⟨hU : a ∈ U, hU' : (Uᶜ).finite⟩,
exact ⟨U, subset.rfl, λ h, hU', hU⟩ }
end
lemma mem_nhds_iff {a : cofinite_topology α} {s : set (cofinite_topology α)} :
s ∈ 𝓝 a ↔ a ∈ s ∧ sᶜ.finite :=
by simp [nhds_eq]
end cofinite_topology
end constructions
section prod
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
[topological_space ε] [topological_space ζ]
@[continuity] lemma continuous_fst : continuous (@prod.fst α β) :=
continuous_inf_dom_left continuous_induced_dom
/-- Postcomposing `f` with `prod.fst` is continuous -/
lemma continuous.fst {f : α → β × γ} (hf : continuous f) : continuous (λ a : α, (f a).1) :=
continuous_fst.comp hf
/-- Precomposing `f` with `prod.fst` is continuous -/
lemma continuous.fst' {f : α → γ} (hf : continuous f) : continuous (λ x : α × β, f x.fst) :=
hf.comp continuous_fst
lemma continuous_at_fst {p : α × β} : continuous_at prod.fst p :=
continuous_fst.continuous_at
/-- Postcomposing `f` with `prod.fst` is continuous at `x` -/
lemma continuous_at.fst {f : α → β × γ} {x : α} (hf : continuous_at f x) :
continuous_at (λ a : α, (f a).1) x :=
continuous_at_fst.comp hf
/-- Precomposing `f` with `prod.fst` is continuous at `(x, y)` -/
lemma continuous_at.fst' {f : α → γ} {x : α} {y : β} (hf : continuous_at f x) :
continuous_at (λ x : α × β, f x.fst) (x, y) :=
continuous_at.comp hf continuous_at_fst
/-- Precomposing `f` with `prod.fst` is continuous at `x : α × β` -/
lemma continuous_at.fst'' {f : α → γ} {x : α × β} (hf : continuous_at f x.fst) :
continuous_at (λ x : α × β, f x.fst) x :=
hf.comp continuous_at_fst
@[continuity] lemma continuous_snd : continuous (@prod.snd α β) :=
continuous_inf_dom_right continuous_induced_dom
/-- Postcomposing `f` with `prod.snd` is continuous -/
lemma continuous.snd {f : α → β × γ} (hf : continuous f) : continuous (λ a : α, (f a).2) :=
continuous_snd.comp hf
/-- Precomposing `f` with `prod.snd` is continuous -/
lemma continuous.snd' {f : β → γ} (hf : continuous f) : continuous (λ x : α × β, f x.snd) :=
hf.comp continuous_snd
lemma continuous_at_snd {p : α × β} : continuous_at prod.snd p :=
continuous_snd.continuous_at
/-- Postcomposing `f` with `prod.snd` is continuous at `x` -/
lemma continuous_at.snd {f : α → β × γ} {x : α} (hf : continuous_at f x) :
continuous_at (λ a : α, (f a).2) x :=
continuous_at_snd.comp hf
/-- Precomposing `f` with `prod.snd` is continuous at `(x, y)` -/
lemma continuous_at.snd' {f : β → γ} {x : α} {y : β} (hf : continuous_at f y) :
continuous_at (λ x : α × β, f x.snd) (x, y) :=
continuous_at.comp hf continuous_at_snd
/-- Precomposing `f` with `prod.snd` is continuous at `x : α × β` -/
lemma continuous_at.snd'' {f : β → γ} {x : α × β} (hf : continuous_at f x.snd) :
continuous_at (λ x : α × β, f x.snd) x :=
hf.comp continuous_at_snd
@[continuity] lemma continuous.prod_mk {f : γ → α} {g : γ → β}
(hf : continuous f) (hg : continuous g) : continuous (λx, (f x, g x)) :=
continuous_inf_rng (continuous_induced_rng hf) (continuous_induced_rng hg)
@[continuity] lemma continuous.prod.mk (a : α) : continuous (λ b : β, (a, b)) :=
continuous_const.prod_mk continuous_id'
@[continuity] lemma continuous.prod.mk_left (b : β) : continuous (λ a : α, (a, b)) :=
continuous_id'.prod_mk continuous_const
lemma continuous.comp₂ {g : α × β → γ} (hg : continuous g) {e : δ → α} (he : continuous e)
{f : δ → β} (hf : continuous f) : continuous (λ x, g (e x, f x)) :=
hg.comp $ he.prod_mk hf
lemma continuous.comp₃ {g : α × β × γ → ε} (hg : continuous g)
{e : δ → α} (he : continuous e) {f : δ → β} (hf : continuous f)
{k : δ → γ} (hk : continuous k) : continuous (λ x, g (e x, f x, k x)) :=
hg.comp₂ he $ hf.prod_mk hk
lemma continuous.comp₄ {g : α × β × γ × ζ → ε} (hg : continuous g)
{e : δ → α} (he : continuous e) {f : δ → β} (hf : continuous f)
{k : δ → γ} (hk : continuous k) {l : δ → ζ} (hl : continuous l) :
continuous (λ x, g (e x, f x, k x, l x)) :=
hg.comp₃ he hf $ hk.prod_mk hl
lemma continuous.prod_map {f : γ → α} {g : δ → β} (hf : continuous f) (hg : continuous g) :
continuous (λ x : γ × δ, (f x.1, g x.2)) :=
hf.fst'.prod_mk hg.snd'
/-- A version of `continuous_inf_dom_left` for binary functions -/
lemma continuous_inf_dom_left₂ {α β γ} {f : α → β → γ}
{ta1 ta2 : topological_space α} {tb1 tb2 : topological_space β} {tc1 : topological_space γ}
(h : by haveI := ta1; haveI := tb1; exact continuous (λ p : α × β, f p.1 p.2)) :
by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact continuous (λ p : α × β, f p.1 p.2) :=
begin
have ha := @continuous_inf_dom_left _ _ id ta1 ta2 ta1 (@continuous_id _ (id _)),
have hb := @continuous_inf_dom_left _ _ id tb1 tb2 tb1 (@continuous_id _ (id _)),
have h_continuous_id := @continuous.prod_map _ _ _ _ ta1 tb1 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb,
exact @continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id,
end
/-- A version of `continuous_inf_dom_right` for binary functions -/
lemma continuous_inf_dom_right₂ {α β γ} {f : α → β → γ}
{ta1 ta2 : topological_space α} {tb1 tb2 : topological_space β} {tc1 : topological_space γ}
(h : by haveI := ta2; haveI := tb2; exact continuous (λ p : α × β, f p.1 p.2)) :
by haveI := ta1 ⊓ ta2; haveI := tb1 ⊓ tb2; exact continuous (λ p : α × β, f p.1 p.2) :=
begin
have ha := @continuous_inf_dom_right _ _ id ta1 ta2 ta2 (@continuous_id _ (id _)),
have hb := @continuous_inf_dom_right _ _ id tb1 tb2 tb2 (@continuous_id _ (id _)),
have h_continuous_id := @continuous.prod_map _ _ _ _ ta2 tb2 (ta1 ⊓ ta2) (tb1 ⊓ tb2) _ _ ha hb,
exact @continuous.comp _ _ _ (id _) (id _) _ _ _ h h_continuous_id,
end
/-- A version of `continuous_Inf_dom` for binary functions -/
lemma continuous_Inf_dom₂ {α β γ} {f : α → β → γ}
{tas : set (topological_space α)} {tbs : set (topological_space β)}
{ta : topological_space α} {tb : topological_space β} {tc : topological_space γ}
(ha : ta ∈ tas) (hb : tb ∈ tbs)
(hf : continuous (λ p : α × β, f p.1 p.2)):
by haveI := Inf tas; haveI := Inf tbs; exact @continuous _ _ _ tc (λ p : α × β, f p.1 p.2) :=
begin
let t : topological_space (α × β) := prod.topological_space,
have ha := continuous_Inf_dom ha continuous_id,
have hb := continuous_Inf_dom hb continuous_id,
have h_continuous_id := @continuous.prod_map _ _ _ _ ta tb (Inf tas) (Inf tbs) _ _ ha hb,
exact @continuous.comp _ _ _ (id _) (id _) _ _ _ hf h_continuous_id,
end
lemma filter.eventually.prod_inl_nhds {p : α → Prop} {a : α} (h : ∀ᶠ x in 𝓝 a, p x) (b : β) :
∀ᶠ x in 𝓝 (a, b), p (x : α × β).1 :=
continuous_at_fst h
lemma filter.eventually.prod_inr_nhds {p : β → Prop} {b : β} (h : ∀ᶠ x in 𝓝 b, p x) (a : α) :
∀ᶠ x in 𝓝 (a, b), p (x : α × β).2 :=
continuous_at_snd h
lemma filter.eventually.prod_mk_nhds {pa : α → Prop} {a} (ha : ∀ᶠ x in 𝓝 a, pa x)
{pb : β → Prop} {b} (hb : ∀ᶠ y in 𝓝 b, pb y) :
∀ᶠ p in 𝓝 (a, b), pa (p : α × β).1 ∧ pb p.2 :=
(ha.prod_inl_nhds b).and (hb.prod_inr_nhds a)
lemma continuous_swap : continuous (prod.swap : α × β → β × α) :=
continuous_snd.prod_mk continuous_fst
lemma continuous_uncurry_left {f : α → β → γ} (a : α)
(h : continuous (function.uncurry f)) : continuous (f a) :=
show continuous (function.uncurry f ∘ (λ b, (a, b))), from h.comp (by continuity)
lemma continuous_uncurry_right {f : α → β → γ} (b : β)
(h : continuous (function.uncurry f)) : continuous (λ a, f a b) :=
show continuous (function.uncurry f ∘ (λ a, (a, b))), from h.comp (by continuity)
lemma continuous_curry {g : α × β → γ} (a : α)
(h : continuous g) : continuous (function.curry g a) :=
show continuous (g ∘ (λ b, (a, b))), from h.comp (by continuity)
lemma is_open.prod {s : set α} {t : set β} (hs : is_open s) (ht : is_open t) :
is_open (s ×ˢ t) :=
(hs.preimage continuous_fst).inter (ht.preimage continuous_snd)
lemma nhds_prod_eq {a : α} {b : β} : 𝓝 (a, b) = 𝓝 a ×ᶠ 𝓝 b :=
by rw [filter.prod, prod.topological_space, nhds_inf, nhds_induced, nhds_induced]
/-- If a function `f x y` is such that `y ↦ f x y` is continuous for all `x`, and `x` lives in a
discrete space, then `f` is continuous. -/
lemma continuous_uncurry_of_discrete_topology [discrete_topology α]
{f : α → β → γ} (hf : ∀ a, continuous (f a)) : continuous (function.uncurry f) :=
begin
apply continuous_iff_continuous_at.2,
rintros ⟨a, x⟩,
change map _ _ ≤ _,
rw [nhds_prod_eq, nhds_discrete, filter.map_pure_prod],
exact (hf a).continuous_at
end
lemma mem_nhds_prod_iff {a : α} {b : β} {s : set (α × β)} :
s ∈ 𝓝 (a, b) ↔ ∃ (u ∈ 𝓝 a) (v ∈ 𝓝 b), u ×ˢ v ⊆ s :=
by rw [nhds_prod_eq, mem_prod_iff]
lemma mem_nhds_prod_iff' {a : α} {b : β} {s : set (α × β)} :
s ∈ 𝓝 (a, b) ↔ ∃ (u : set α) (v : set β), is_open u ∧ a ∈ u ∧ is_open v ∧ b ∈ v ∧ u ×ˢ v ⊆ s :=
begin
rw mem_nhds_prod_iff,
split,
{ rintros ⟨u, Hu, v, Hv, h⟩,
rcases mem_nhds_iff.1 Hu with ⟨u', u'u, u'_open, Hu'⟩,
rcases mem_nhds_iff.1 Hv with ⟨v', v'v, v'_open, Hv'⟩,
exact ⟨u', v', u'_open, Hu', v'_open, Hv', (set.prod_mono u'u v'v).trans h⟩ },
{ rintros ⟨u, v, u_open, au, v_open, bv, huv⟩,
exact ⟨u, u_open.mem_nhds au, v, v_open.mem_nhds bv, huv⟩ }
end
lemma _root_.prod.tendsto_iff {α} (seq : α → β × γ) {f : filter α} (x : β × γ) :
tendsto seq f (𝓝 x)
↔ tendsto (λ n, (seq n).fst) f (𝓝 x.fst) ∧ tendsto (λ n, (seq n).snd) f (𝓝 x.snd) :=
by { cases x, rw [nhds_prod_eq, filter.tendsto_prod_iff'], }
lemma filter.has_basis.prod_nhds {ιa ιb : Type*} {pa : ιa → Prop} {pb : ιb → Prop}
{sa : ιa → set α} {sb : ιb → set β} {a : α} {b : β} (ha : (𝓝 a).has_basis pa sa)
(hb : (𝓝 b).has_basis pb sb) :
(𝓝 (a, b)).has_basis (λ i : ιa × ιb, pa i.1 ∧ pb i.2) (λ i, sa i.1 ×ˢ sb i.2) :=
by { rw nhds_prod_eq, exact ha.prod hb }
lemma filter.has_basis.prod_nhds' {ιa ιb : Type*} {pa : ιa → Prop} {pb : ιb → Prop}
{sa : ιa → set α} {sb : ιb → set β} {ab : α × β} (ha : (𝓝 ab.1).has_basis pa sa)
(hb : (𝓝 ab.2).has_basis pb sb) :
(𝓝 ab).has_basis (λ i : ιa × ιb, pa i.1 ∧ pb i.2) (λ i, sa i.1 ×ˢ sb i.2) :=
by { cases ab, exact ha.prod_nhds hb }
instance [discrete_topology α] [discrete_topology β] : discrete_topology (α × β) :=
⟨eq_of_nhds_eq_nhds $ assume ⟨a, b⟩,
by rw [nhds_prod_eq, nhds_discrete α, nhds_discrete β, nhds_bot, filter.prod_pure_pure]⟩
lemma prod_mem_nhds_iff {s : set α} {t : set β} {a : α} {b : β} :
s ×ˢ t ∈ 𝓝 (a, b) ↔ s ∈ 𝓝 a ∧ t ∈ 𝓝 b :=
by rw [nhds_prod_eq, prod_mem_prod_iff]
lemma prod_is_open.mem_nhds {s : set α} {t : set β} {a : α} {b : β}
(ha : s ∈ 𝓝 a) (hb : t ∈ 𝓝 b) : s ×ˢ t ∈ 𝓝 (a, b) :=
prod_mem_nhds_iff.2 ⟨ha, hb⟩
lemma nhds_swap (a : α) (b : β) : 𝓝 (a, b) = (𝓝 (b, a)).map prod.swap :=
by rw [nhds_prod_eq, filter.prod_comm, nhds_prod_eq]; refl
lemma filter.tendsto.prod_mk_nhds {γ} {a : α} {b : β} {f : filter γ} {ma : γ → α} {mb : γ → β}
(ha : tendsto ma f (𝓝 a)) (hb : tendsto mb f (𝓝 b)) :
tendsto (λc, (ma c, mb c)) f (𝓝 (a, b)) :=
by rw [nhds_prod_eq]; exact filter.tendsto.prod_mk ha hb
lemma filter.eventually.curry_nhds {p : α × β → Prop} {x : α} {y : β} (h : ∀ᶠ x in 𝓝 (x, y), p x) :
∀ᶠ x' in 𝓝 x, ∀ᶠ y' in 𝓝 y, p (x', y') :=
by { rw [nhds_prod_eq] at h, exact h.curry }
lemma continuous_at.prod {f : α → β} {g : α → γ} {x : α}
(hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (λx, (f x, g x)) x :=
hf.prod_mk_nhds hg
lemma continuous_at.prod_map {f : α → γ} {g : β → δ} {p : α × β}
(hf : continuous_at f p.fst) (hg : continuous_at g p.snd) :
continuous_at (λ p : α × β, (f p.1, g p.2)) p :=
hf.fst''.prod hg.snd''
lemma continuous_at.prod_map' {f : α → γ} {g : β → δ} {x : α} {y : β}
(hf : continuous_at f x) (hg : continuous_at g y) :
continuous_at (λ p : α × β, (f p.1, g p.2)) (x, y) :=
hf.fst'.prod hg.snd'
lemma prod_generate_from_generate_from_eq {α β : Type*} {s : set (set α)} {t : set (set β)}
(hs : ⋃₀ s = univ) (ht : ⋃₀ t = univ) :
@prod.topological_space α β (generate_from s) (generate_from t) =
generate_from {g | ∃ u ∈ s, ∃ v ∈ t, g = u ×ˢ v} :=
let G := generate_from {g | ∃ u ∈ s, ∃ v ∈ t, g = u ×ˢ v} in
le_antisymm
(le_generate_from $ λ g ⟨u, hu, v, hv, g_eq⟩, g_eq.symm ▸
@is_open.prod _ _ (generate_from s) (generate_from t) _ _
(generate_open.basic _ hu) (generate_open.basic _ hv))
(le_inf
(coinduced_le_iff_le_induced.mp $ le_generate_from $ λ u hu,
have (⋃ v ∈ t, u ×ˢ v) = prod.fst ⁻¹' u,
by simp_rw [← prod_Union, ← sUnion_eq_bUnion, ht, prod_univ],
show G.is_open (prod.fst ⁻¹' u),
by { rw [← this], exactI is_open_Union (λ v, is_open_Union $ λ hv,
generate_open.basic _ ⟨_, hu, _, hv, rfl⟩) })
(coinduced_le_iff_le_induced.mp $ le_generate_from $ λ v hv,
have (⋃ u ∈ s, u ×ˢ v) = prod.snd ⁻¹' v,
by simp_rw [← Union_prod_const, ← sUnion_eq_bUnion, hs, univ_prod],
show G.is_open (prod.snd ⁻¹' v),
by { rw [← this], exactI is_open_Union (λ u, is_open_Union $ λ hu,
generate_open.basic _ ⟨_, hu, _, hv, rfl⟩) }))
lemma prod_eq_generate_from :
prod.topological_space =
generate_from {g | ∃(s:set α) (t:set β), is_open s ∧ is_open t ∧ g = s ×ˢ t} :=
le_antisymm
(le_generate_from $ λ g ⟨s, t, hs, ht, g_eq⟩, g_eq.symm ▸ hs.prod ht)
(le_inf
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨t, univ, by simpa [set.prod_eq] using ht⟩)
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨univ, t, by simpa [set.prod_eq] using ht⟩))
lemma is_open_prod_iff {s : set (α × β)} : is_open s ↔
(∀a b, (a, b) ∈ s →
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ a ∈ u ∧ b ∈ v ∧ u ×ˢ v ⊆ s) :=
begin
rw [is_open_iff_nhds],
simp_rw [le_principal_iff, prod.forall,
((nhds_basis_opens _).prod_nhds (nhds_basis_opens _)).mem_iff, prod.exists, exists_prop],
simp only [and_assoc, and.left_comm]
end
/-- A product of induced topologies is induced by the product map -/
lemma prod_induced_induced {α γ : Type*} (f : α → β) (g : γ → δ) :
@prod.topological_space α γ (induced f ‹_›) (induced g ‹_›) =
induced (λ p, (f p.1, g p.2)) prod.topological_space :=
by simp_rw [prod.topological_space, induced_inf, induced_compose]
lemma continuous_uncurry_of_discrete_topology_left [discrete_topology α]
{f : α → β → γ} (h : ∀ a, continuous (f a)) : continuous (function.uncurry f) :=
continuous_iff_continuous_at.2 $ λ ⟨a, b⟩,
by simp only [continuous_at, nhds_prod_eq, nhds_discrete α, pure_prod, tendsto_map'_iff, (∘),
function.uncurry, (h a).tendsto]
/-- Given a neighborhood `s` of `(x, x)`, then `(x, x)` has a square open neighborhood
that is a subset of `s`. -/
lemma exists_nhds_square {s : set (α × α)} {x : α} (hx : s ∈ 𝓝 (x, x)) :
∃ U : set α, is_open U ∧ x ∈ U ∧ U ×ˢ U ⊆ s :=
by simpa [nhds_prod_eq, (nhds_basis_opens x).prod_self.mem_iff, and.assoc, and.left_comm] using hx
/-- `prod.fst` maps neighborhood of `x : α × β` within the section `prod.snd ⁻¹' {x.2}`
to `𝓝 x.1`. -/
lemma map_fst_nhds_within (x : α × β) : map prod.fst (𝓝[prod.snd ⁻¹' {x.2}] x) = 𝓝 x.1 :=
begin
refine le_antisymm (continuous_at_fst.mono_left inf_le_left) (λ s hs, _),
rcases x with ⟨x, y⟩,
rw [mem_map, nhds_within, mem_inf_principal, mem_nhds_prod_iff] at hs,
rcases hs with ⟨u, hu, v, hv, H⟩,
simp only [prod_subset_iff, mem_singleton_iff, mem_set_of_eq, mem_preimage] at H,
exact mem_of_superset hu (λ z hz, H _ hz _ (mem_of_mem_nhds hv) rfl)
end
@[simp] lemma map_fst_nhds (x : α × β) : map prod.fst (𝓝 x) = 𝓝 x.1 :=
le_antisymm continuous_at_fst $ (map_fst_nhds_within x).symm.trans_le (map_mono inf_le_left)
/-- The first projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_fst : is_open_map (@prod.fst α β) :=
is_open_map_iff_nhds_le.2 $ λ x, (map_fst_nhds x).ge
/-- `prod.snd` maps neighborhood of `x : α × β` within the section `prod.fst ⁻¹' {x.1}`
to `𝓝 x.2`. -/
lemma map_snd_nhds_within (x : α × β) : map prod.snd (𝓝[prod.fst ⁻¹' {x.1}] x) = 𝓝 x.2 :=
begin
refine le_antisymm (continuous_at_snd.mono_left inf_le_left) (λ s hs, _),
rcases x with ⟨x, y⟩,
rw [mem_map, nhds_within, mem_inf_principal, mem_nhds_prod_iff] at hs,
rcases hs with ⟨u, hu, v, hv, H⟩,
simp only [prod_subset_iff, mem_singleton_iff, mem_set_of_eq, mem_preimage] at H,
exact mem_of_superset hv (λ z hz, H _ (mem_of_mem_nhds hu) _ hz rfl)
end
@[simp] lemma map_snd_nhds (x : α × β) : map prod.snd (𝓝 x) = 𝓝 x.2 :=
le_antisymm continuous_at_snd $ (map_snd_nhds_within x).symm.trans_le (map_mono inf_le_left)
/-- The second projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_snd : is_open_map (@prod.snd α β) :=
is_open_map_iff_nhds_le.2 $ λ x, (map_snd_nhds x).ge
/-- A product set is open in a product space if and only if each factor is open, or one of them is
empty -/
lemma is_open_prod_iff' {s : set α} {t : set β} :
is_open (s ×ˢ t) ↔ (is_open s ∧ is_open t) ∨ (s = ∅) ∨ (t = ∅) :=
begin
cases (s ×ˢ t : set _).eq_empty_or_nonempty with h h,
{ simp [h, prod_eq_empty_iff.1 h] },
{ have st : s.nonempty ∧ t.nonempty, from prod_nonempty_iff.1 h,
split,
{ assume H : is_open (s ×ˢ t),
refine or.inl ⟨_, _⟩,
show is_open s,
{ rw ← fst_image_prod s st.2,
exact is_open_map_fst _ H },
show is_open t,
{ rw ← snd_image_prod st.1 t,
exact is_open_map_snd _ H } },
{ assume H,
simp only [st.1.ne_empty, st.2.ne_empty, not_false_iff, or_false] at H,
exact H.1.prod H.2 } }
end
lemma closure_prod_eq {s : set α} {t : set β} :
closure (s ×ˢ t) = closure s ×ˢ closure t :=
set.ext $ assume ⟨a, b⟩,
have (𝓝 a ×ᶠ 𝓝 b) ⊓ 𝓟 (s ×ˢ t) = (𝓝 a ⊓ 𝓟 s) ×ᶠ (𝓝 b ⊓ 𝓟 t),
by rw [←prod_inf_prod, prod_principal_principal],
by simp [closure_eq_cluster_pts, cluster_pt, nhds_prod_eq, this]; exact prod_ne_bot
lemma interior_prod_eq (s : set α) (t : set β) :
interior (s ×ˢ t) = interior s ×ˢ interior t :=
set.ext $ λ ⟨a, b⟩, by simp only [mem_interior_iff_mem_nhds, mem_prod, prod_mem_nhds_iff]
lemma frontier_prod_eq (s : set α) (t : set β) :
frontier (s ×ˢ t) = closure s ×ˢ frontier t ∪ frontier s ×ˢ closure t :=
by simp only [frontier, closure_prod_eq, interior_prod_eq, prod_diff_prod]
@[simp] lemma frontier_prod_univ_eq (s : set α) :
frontier (s ×ˢ (univ : set β)) = frontier s ×ˢ (univ : set β) :=
by simp [frontier_prod_eq]
@[simp] lemma frontier_univ_prod_eq (s : set β) :
frontier ((univ : set α) ×ˢ s) = (univ : set α) ×ˢ (frontier s) :=
by simp [frontier_prod_eq]
lemma map_mem_closure2 {s : set α} {t : set β} {u : set γ} {f : α → β → γ} {a : α} {b : β}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(hu : ∀a b, a ∈ s → b ∈ t → f a b ∈ u) :
f a b ∈ closure u :=
have (a, b) ∈ closure (s ×ˢ t), by rw [closure_prod_eq]; from ⟨ha, hb⟩,
show (λp:α×β, f p.1 p.2) (a, b) ∈ closure u, from
map_mem_closure hf this $ assume ⟨a, b⟩ ⟨ha, hb⟩, hu a b ha hb
lemma is_closed.prod {s₁ : set α} {s₂ : set β} (h₁ : is_closed s₁) (h₂ : is_closed s₂) :
is_closed (s₁ ×ˢ s₂) :=
closure_eq_iff_is_closed.mp $ by simp only [h₁.closure_eq, h₂.closure_eq, closure_prod_eq]
/-- The product of two dense sets is a dense set. -/
lemma dense.prod {s : set α} {t : set β} (hs : dense s) (ht : dense t) :
dense (s ×ˢ t) :=
λ x, by { rw closure_prod_eq, exact ⟨hs x.1, ht x.2⟩ }
/-- If `f` and `g` are maps with dense range, then `prod.map f g` has dense range. -/
lemma dense_range.prod_map {ι : Type*} {κ : Type*} {f : ι → β} {g : κ → γ}
(hf : dense_range f) (hg : dense_range g) : dense_range (prod.map f g) :=
by simpa only [dense_range, prod_range_range_eq] using hf.prod hg
lemma inducing.prod_mk {f : α → β} {g : γ → δ} (hf : inducing f) (hg : inducing g) :
inducing (λx:α×γ, (f x.1, g x.2)) :=
⟨by rw [prod.topological_space, prod.topological_space, hf.induced, hg.induced,
induced_compose, induced_compose, induced_inf, induced_compose, induced_compose]⟩
lemma embedding.prod_mk {f : α → β} {g : γ → δ} (hf : embedding f) (hg : embedding g) :
embedding (λx:α×γ, (f x.1, g x.2)) :=
{ inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume h₁ h₂, ⟨hf.inj h₁, hg.inj h₂⟩,
..hf.to_inducing.prod_mk hg.to_inducing }
protected lemma is_open_map.prod {f : α → β} {g : γ → δ} (hf : is_open_map f) (hg : is_open_map g) :
is_open_map (λ p : α × γ, (f p.1, g p.2)) :=
begin
rw [is_open_map_iff_nhds_le],
rintros ⟨a, b⟩,
rw [nhds_prod_eq, nhds_prod_eq, ← filter.prod_map_map_eq],
exact filter.prod_mono (is_open_map_iff_nhds_le.1 hf a) (is_open_map_iff_nhds_le.1 hg b)
end
protected lemma open_embedding.prod {f : α → β} {g : γ → δ}
(hf : open_embedding f) (hg : open_embedding g) : open_embedding (λ x : α × γ, (f x.1, g x.2)) :=
open_embedding_of_embedding_open (hf.1.prod_mk hg.1)
(hf.is_open_map.prod hg.is_open_map)
lemma embedding_graph {f : α → β} (hf : continuous f) : embedding (λ x, (x, f x)) :=
embedding_of_embedding_compose (continuous_id.prod_mk hf) continuous_fst embedding_id
end prod
section sum
open sum
variables [topological_space α] [topological_space β] [topological_space γ]
@[continuity] lemma continuous_inl : continuous (@inl α β) :=
continuous_sup_rng_left continuous_coinduced_rng
@[continuity] lemma continuous_inr : continuous (@inr α β) :=
continuous_sup_rng_right continuous_coinduced_rng
@[continuity] lemma continuous_sum_rec {f : α → γ} {g : β → γ}
(hf : continuous f) (hg : continuous g) : @continuous (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) :=
begin
apply continuous_sup_dom;
rw continuous_def at hf hg ⊢;
assumption
end
lemma is_open_sum_iff {s : set (α ⊕ β)} :
is_open s ↔ is_open (inl ⁻¹' s) ∧ is_open (inr ⁻¹' s) :=
iff.rfl
lemma is_open_map_sum {f : α ⊕ β → γ}
(h₁ : is_open_map (λ a, f (inl a))) (h₂ : is_open_map (λ b, f (inr b))) :
is_open_map f :=
begin
intros u hu,
rw is_open_sum_iff at hu,
cases hu with hu₁ hu₂,
have : u = inl '' (inl ⁻¹' u) ∪ inr '' (inr ⁻¹' u),
{ ext (_|_); simp },
rw [this, set.image_union, set.image_image, set.image_image],
exact is_open.union (h₁ _ hu₁) (h₂ _ hu₂)
end
lemma embedding_inl : embedding (@inl α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact le_sup_left },
{ intros u hu, existsi (inl '' u),
change
(is_open (inl ⁻¹' (@inl α β '' u)) ∧
is_open (inr ⁻¹' (@inl α β '' u))) ∧
inl ⁻¹' (inl '' u) = u,
rw [preimage_image_eq u sum.inl_injective, preimage_inr_image_inl],
exact ⟨⟨hu, is_open_empty⟩, rfl⟩ }
end,
inj := λ _ _, inl.inj_iff.mp }
lemma embedding_inr : embedding (@inr α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact le_sup_right },
{ intros u hu, existsi (inr '' u),
change
(is_open (inl ⁻¹' (@inr α β '' u)) ∧
is_open (inr ⁻¹' (@inr α β '' u))) ∧
inr ⁻¹' (inr '' u) = u,
rw [preimage_inl_image_inr, preimage_image_eq u sum.inr_injective],
exact ⟨⟨is_open_empty, hu⟩, rfl⟩ }
end,
inj := λ _ _, inr.inj_iff.mp }
lemma is_open_range_inl : is_open (range (inl : α → α ⊕ β)) :=
is_open_sum_iff.2 $ by simp
lemma is_open_range_inr : is_open (range (inr : β → α ⊕ β)) :=
is_open_sum_iff.2 $ by simp
lemma is_closed_range_inl : is_closed (range (inl : α → α ⊕ β)) :=
by { rw [← is_open_compl_iff, compl_range_inl], exact is_open_range_inr }
lemma is_closed_range_inr : is_closed (range (inr : β → α ⊕ β)) :=
by { rw [← is_open_compl_iff, compl_range_inr], exact is_open_range_inl }
lemma open_embedding_inl : open_embedding (inl : α → α ⊕ β) :=
{ open_range := is_open_range_inl,
.. embedding_inl }
lemma open_embedding_inr : open_embedding (inr : β → α ⊕ β) :=
{ open_range := is_open_range_inr,
.. embedding_inr }
lemma closed_embedding_inl : closed_embedding (inl : α → α ⊕ β) :=
{ closed_range := is_closed_range_inl,
.. embedding_inl }
lemma closed_embedding_inr : closed_embedding (inr : β → α ⊕ β) :=
{ closed_range := is_closed_range_inr,
.. embedding_inr }
end sum
section subtype
variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop}
lemma inducing_coe {b : set β} : inducing (coe : b → β) := ⟨rfl⟩
lemma inducing.of_cod_restrict {f : α → β} {b : set β} (hb : ∀ a, f a ∈ b)
(h : inducing (b.cod_restrict f hb)) : inducing f := inducing_coe.comp h
lemma embedding_subtype_coe : embedding (coe : subtype p → α) :=
⟨⟨rfl⟩, subtype.coe_injective⟩
lemma closed_embedding_subtype_coe (h : is_closed {a | p a}) :
closed_embedding (coe : subtype p → α) :=
⟨embedding_subtype_coe, by rwa [subtype.range_coe_subtype]⟩
@[continuity] lemma continuous_subtype_val : continuous (@subtype.val α p) :=
continuous_induced_dom
lemma continuous_subtype_coe : continuous (coe : subtype p → α) :=
continuous_subtype_val
lemma continuous.subtype_coe {f : β → subtype p} (hf : continuous f) :
continuous (λ x, (f x : α)) :=
continuous_subtype_coe.comp hf
lemma is_open.open_embedding_subtype_coe {s : set α} (hs : is_open s) :
open_embedding (coe : s → α) :=
{ induced := rfl,
inj := subtype.coe_injective,
open_range := (subtype.range_coe : range coe = s).symm ▸ hs }
lemma is_open.is_open_map_subtype_coe {s : set α} (hs : is_open s) :
is_open_map (coe : s → α) :=
hs.open_embedding_subtype_coe.is_open_map
lemma is_open_map.restrict {f : α → β} (hf : is_open_map f) {s : set α} (hs : is_open s) :
is_open_map (s.restrict f) :=
hf.comp hs.is_open_map_subtype_coe
lemma is_closed.closed_embedding_subtype_coe {s : set α} (hs : is_closed s) :
closed_embedding (coe : {x // x ∈ s} → α) :=
{ induced := rfl,
inj := subtype.coe_injective,
closed_range := (subtype.range_coe : range coe = s).symm ▸ hs }
@[continuity] lemma continuous_subtype_mk {f : β → α}
(hp : ∀x, p (f x)) (h : continuous f) : continuous (λx, (⟨f x, hp x⟩ : subtype p)) :=
continuous_induced_rng h
lemma continuous_inclusion {s t : set α} (h : s ⊆ t) : continuous (inclusion h) :=
continuous_subtype_mk _ continuous_subtype_coe
lemma continuous_at_subtype_coe {p : α → Prop} {a : subtype p} :
continuous_at (coe : subtype p → α) a :=
continuous_iff_continuous_at.mp continuous_subtype_coe _
lemma map_nhds_subtype_coe_eq {a : α} (ha : p a) (h : {a | p a} ∈ 𝓝 a) :
map (coe : subtype p → α) (𝓝 ⟨a, ha⟩) = 𝓝 a :=
map_nhds_induced_of_mem $ by simpa only [subtype.coe_mk, subtype.range_coe] using h
lemma nhds_subtype_eq_comap {a : α} {h : p a} :
𝓝 (⟨a, h⟩ : subtype p) = comap coe (𝓝 a) :=
nhds_induced _ _
lemma tendsto_subtype_rng {β : Type*} {p : α → Prop} {b : filter β} {f : β → subtype p} :
∀{a:subtype p}, tendsto f b (𝓝 a) ↔ tendsto (λx, (f x : α)) b (𝓝 (a : α))
| ⟨a, ha⟩ := by rw [nhds_subtype_eq_comap, tendsto_comap_iff, subtype.coe_mk]
lemma continuous_subtype_nhds_cover {ι : Sort*} {f : α → β} {c : ι → α → Prop}
(c_cover : ∀x:α, ∃i, {x | c i x} ∈ 𝓝 x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x)) :
continuous f :=
continuous_iff_continuous_at.mpr $ assume x,
let ⟨i, (c_sets : {x | c i x} ∈ 𝓝 x)⟩ := c_cover x in
let x' : subtype (c i) := ⟨x, mem_of_mem_nhds c_sets⟩ in
calc map f (𝓝 x) = map f (map coe (𝓝 x')) :
congr_arg (map f) (map_nhds_subtype_coe_eq _ $ c_sets).symm
... = map (λx:subtype (c i), f x) (𝓝 x') : rfl
... ≤ 𝓝 (f x) : continuous_iff_continuous_at.mp (f_cont i) x'
lemma continuous_subtype_is_closed_cover {ι : Sort*} {f : α → β} (c : ι → α → Prop)
(h_lf : locally_finite (λi, {x | c i x}))
(h_is_closed : ∀i, is_closed {x | c i x})
(h_cover : ∀x, ∃i, c i x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x)) :
continuous f :=
continuous_iff_is_closed.mpr $
assume s hs,
have ∀i, is_closed ((coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' s)),
from assume i,
(closed_embedding_subtype_coe (h_is_closed _)).is_closed_map _ (hs.preimage (f_cont i)),
have is_closed (⋃i, (coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' s)),
from locally_finite.is_closed_Union
(h_lf.subset $ assume i x ⟨⟨x', hx'⟩, _, heq⟩, heq ▸ hx')
this,
have f ⁻¹' s = (⋃i, (coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' s)),
begin
apply set.ext,
have : ∀ (x : α), f x ∈ s ↔ ∃ (i : ι), c i x ∧ f x ∈ s :=
λ x, ⟨λ hx, let ⟨i, hi⟩ := h_cover x in ⟨i, hi, hx⟩,
λ ⟨i, hi, hx⟩, hx⟩,
simpa [and.comm, @and.left_comm (c _ _), ← exists_and_distrib_right],
end,
by rwa [this]
lemma closure_subtype {x : {a // p a}} {s : set {a // p a}}:
x ∈ closure s ↔ (x : α) ∈ closure ((coe : _ → α) '' s) :=
closure_induced
@[continuity] lemma continuous.cod_restrict {f : α → β} {s : set β} (hf : continuous f)
(hs : ∀ a, f a ∈ s) : continuous (s.cod_restrict f hs) := continuous_subtype_mk hs hf
lemma inducing.cod_restrict {e : α → β} (he : inducing e) {s : set β} (hs : ∀ x, e x ∈ s) :
inducing (cod_restrict e s hs) :=
inducing_of_inducing_compose (he.continuous.cod_restrict hs) continuous_subtype_coe he
lemma embedding.cod_restrict {e : α → β} (he : embedding e) (s : set β) (hs : ∀ x, e x ∈ s) :
embedding (cod_restrict e s hs) :=
embedding_of_embedding_compose (he.continuous.cod_restrict hs) continuous_subtype_coe he
end subtype
section quotient
variables [topological_space α] [topological_space β] [topological_space γ]
variables {r : α → α → Prop} {s : setoid α}
lemma quotient_map_quot_mk : quotient_map (@quot.mk α r) :=
⟨quot.exists_rep, rfl⟩
@[continuity] lemma continuous_quot_mk : continuous (@quot.mk α r) :=
continuous_coinduced_rng
@[continuity] lemma continuous_quot_lift {f : α → β} (hr : ∀ a b, r a b → f a = f b)
(h : continuous f) : continuous (quot.lift f hr : quot r → β) :=
continuous_coinduced_dom h
lemma quotient_map_quotient_mk : quotient_map (@quotient.mk α s) :=
quotient_map_quot_mk
lemma continuous_quotient_mk : continuous (@quotient.mk α s) :=
continuous_coinduced_rng
lemma continuous_quotient_lift {f : α → β} (hs : ∀ a b, a ≈ b → f a = f b)
(h : continuous f) : continuous (quotient.lift f hs : quotient s → β) :=
continuous_coinduced_dom h
lemma continuous_quotient_lift_on' {f : α → β} (hs : ∀ a b, a ≈ b → f a = f b)
(h : continuous f) : continuous (λ x, quotient.lift_on' x f hs : quotient s → β) :=
continuous_coinduced_dom h
end quotient
section pi
variables {ι : Type*} {π : ι → Type*}
@[continuity]
lemma continuous_pi [topological_space α] [∀i, topological_space (π i)] {f : α → Πi:ι, π i}
(h : ∀i, continuous (λa, f a i)) : continuous f :=
continuous_infi_rng $ assume i, continuous_induced_rng $ h i
@[continuity]
lemma continuous_apply [∀i, topological_space (π i)] (i : ι) :
continuous (λp:Πi, π i, p i) :=
continuous_infi_dom continuous_induced_dom
@[continuity]
lemma continuous_apply_apply {κ : Type*} {ρ : κ → ι → Type*}
[∀ j i, topological_space (ρ j i)] (j : κ) (i : ι) :
continuous (λ p : (Π j, Π i, ρ j i), p j i) :=
(continuous_apply i).comp (continuous_apply j)
lemma continuous_at_apply [∀i, topological_space (π i)] (i : ι) (x : Π i, π i) :
continuous_at (λ p : Π i, π i, p i) x :=
(continuous_apply i).continuous_at
lemma filter.tendsto.apply [∀i, topological_space (π i)] {l : filter α} {f : α → Π i, π i}
{x : Π i, π i} (h : tendsto f l (𝓝 x)) (i : ι) :
tendsto (λ a, f a i) l (𝓝 $ x i) :=
(continuous_at_apply i _).tendsto.comp h
lemma continuous_pi_iff [topological_space α] [∀ i, topological_space (π i)] {f : α → Π i, π i} :
continuous f ↔ ∀ i, continuous (λ y, f y i) :=
iff.intro (λ h i, (continuous_apply i).comp h) continuous_pi
lemma nhds_pi [t : ∀i, topological_space (π i)] {a : Πi, π i} :
𝓝 a = pi (λ i, 𝓝 (a i)) :=
calc 𝓝 a = (⨅i, @nhds _ (@topological_space.induced _ _ (λx:Πi, π i, x i) (t i)) a) : nhds_infi
... = (⨅i, comap (λx, x i) (𝓝 (a i))) : by simp [nhds_induced]
lemma tendsto_pi_nhds [t : ∀i, topological_space (π i)] {f : α → Πi, π i} {g : Πi, π i}
{u : filter α} :
tendsto f u (𝓝 g) ↔ ∀ x, tendsto (λ i, f i x) u (𝓝 (g x)) :=
by rw [nhds_pi, filter.tendsto_pi]
lemma continuous_at_pi [∀ i, topological_space (π i)] [topological_space α] {f : α → Π i, π i}
{x : α} :
continuous_at f x ↔ ∀ i, continuous_at (λ y, f y i) x :=
tendsto_pi_nhds
lemma filter.tendsto.update [∀i, topological_space (π i)] [decidable_eq ι]
{l : filter α} {f : α → Π i, π i} {x : Π i, π i} (hf : tendsto f l (𝓝 x)) (i : ι)
{g : α → π i} {xi : π i} (hg : tendsto g l (𝓝 xi)) :
tendsto (λ a, function.update (f a) i (g a)) l (𝓝 $ function.update x i xi) :=
tendsto_pi_nhds.2 $ λ j, by { rcases em (j = i) with rfl|hj; simp [*, hf.apply] }
lemma continuous_at.update [∀i, topological_space (π i)] [topological_space α] [decidable_eq ι]
{f : α → Π i, π i} {a : α} (hf : continuous_at f a) (i : ι) {g : α → π i}
(hg : continuous_at g a) :
continuous_at (λ a, function.update (f a) i (g a)) a :=
hf.update i hg
lemma continuous.update [∀i, topological_space (π i)] [topological_space α] [decidable_eq ι]
{f : α → Π i, π i} (hf : continuous f) (i : ι) {g : α → π i} (hg : continuous g) :
continuous (λ a, function.update (f a) i (g a)) :=
continuous_iff_continuous_at.2 $ λ x, hf.continuous_at.update i hg.continuous_at
/-- `function.update f i x` is continuous in `(f, x)`. -/
@[continuity] lemma continuous_update [∀i, topological_space (π i)] [decidable_eq ι] (i : ι) :
continuous (λ f : (Π j, π j) × π i, function.update f.1 i f.2) :=
continuous_fst.update i continuous_snd
lemma filter.tendsto.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)]
(i : fin (n + 1)) {f : α → π i} {l : filter α} {x : π i} (hf : tendsto f l (𝓝 x))
{g : α → Π j : fin n, π (i.succ_above j)} {y : Π j, π (i.succ_above j)} (hg : tendsto g l (𝓝 y)) :
tendsto (λ a, i.insert_nth (f a) (g a)) l (𝓝 $ i.insert_nth x y) :=
tendsto_pi_nhds.2 (λ j, fin.succ_above_cases i (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j)
lemma continuous_at.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)]
[topological_space α] (i : fin (n + 1)) {f : α → π i} {a : α} (hf : continuous_at f a)
{g : α → Π j : fin n, π (i.succ_above j)} (hg : continuous_at g a) :
continuous_at (λ a, i.insert_nth (f a) (g a)) a :=
hf.fin_insert_nth i hg
lemma continuous.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)]
[topological_space α] (i : fin (n + 1)) {f : α → π i} (hf : continuous f)
{g : α → Π j : fin n, π (i.succ_above j)} (hg : continuous g) :
continuous (λ a, i.insert_nth (f a) (g a)) :=
continuous_iff_continuous_at.2 $ λ a, hf.continuous_at.fin_insert_nth i hg.continuous_at
lemma is_open_set_pi [∀a, topological_space (π a)] {i : set ι} {s : Πa, set (π a)}
(hi : finite i) (hs : ∀a∈i, is_open (s a)) : is_open (pi i s) :=
by rw [pi_def]; exact (is_open_bInter hi $ assume a ha, (hs _ ha).preimage (continuous_apply _))
lemma is_closed_set_pi [∀a, topological_space (π a)] {i : set ι} {s : Πa, set (π a)}
(hs : ∀a∈i, is_closed (s a)) : is_closed (pi i s) :=
by rw [pi_def];
exact (is_closed_Inter $ λ a, is_closed_Inter $ λ ha, (hs _ ha).preimage (continuous_apply _))
lemma mem_nhds_of_pi_mem_nhds {ι : Type*} {α : ι → Type*} [Π (i : ι), topological_space (α i)]
{I : set ι} {s : Π i, set (α i)} (a : Π i, α i) (hs : I.pi s ∈ 𝓝 a) {i : ι} (hi : i ∈ I) :
s i ∈ 𝓝 (a i) :=
by { rw nhds_pi at hs, exact mem_of_pi_mem_pi hs hi }
lemma set_pi_mem_nhds [Π a, topological_space (π a)] {i : set ι} {s : Π a, set (π a)}
{x : Π a, π a} (hi : finite i) (hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) :
pi i s ∈ 𝓝 x :=
by { rw [pi_def, bInter_mem hi], exact λ a ha, (continuous_apply a).continuous_at (hs a ha) }
lemma set_pi_mem_nhds_iff {α : ι → Type*} [Π (i : ι), topological_space (α i)]
{I : set ι} (hI : I.finite) {s : Π i, set (α i)} (a : Π i, α i) :
I.pi s ∈ 𝓝 a ↔ ∀ (i : ι), i ∈ I → s i ∈ 𝓝 (a i) :=
by { rw [nhds_pi, pi_mem_pi_iff hI], apply_instance }
lemma interior_pi_set {α : ι → Type*} [Π i, topological_space (α i)]
{I : set ι} (hI : I.finite) {s : Π i, set (α i)} :
interior (pi I s) = I.pi (λ i, interior (s i)) :=
by { ext a, simp only [set.mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff hI] }
lemma exists_finset_piecewise_mem_of_mem_nhds [decidable_eq ι] [Π i, topological_space (π i)]
{s : set (Π a, π a)} {x : Π a, π a} (hs : s ∈ 𝓝 x) (y : Π a, π a) :
∃ I : finset ι, I.piecewise x y ∈ s :=
begin
simp only [nhds_pi, filter.mem_pi'] at hs,
rcases hs with ⟨I, t, htx, hts⟩,
refine ⟨I, hts $ λ i hi, _⟩,
simpa [finset.mem_coe.1 hi] using mem_of_mem_nhds (htx i)
end
lemma pi_eq_generate_from [∀a, topological_space (π a)] :
Pi.topological_space =
generate_from {g | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, is_open (s a)) ∧ g = pi ↑i s} :=
le_antisymm
(le_generate_from $ assume g ⟨s, i, hi, eq⟩, eq.symm ▸ is_open_set_pi (finset.finite_to_set _) hi)
(le_infi $ assume a s ⟨t, ht, s_eq⟩, generate_open.basic _ $
⟨function.update (λa, univ) a t, {a}, by simpa using ht, s_eq ▸ by ext f; simp [set.pi]⟩)
lemma pi_generate_from_eq {g : Πa, set (set (π a))} :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} :=
let G := {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} in
begin
rw [pi_eq_generate_from],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, i, ht, eq⟩, ⟨t, i, assume a ha, generate_open.basic _ (ht a ha), eq⟩,
{ rintros s ⟨t, i, hi, rfl⟩,
rw [pi_def],
apply is_open_bInter (finset.finite_to_set _),
assume a ha, show ((generate_from G).coinduced (λf:Πa, π a, f a)).is_open (t a),
refine le_generate_from _ _ (hi a ha),
exact assume s hs, generate_open.basic _ ⟨function.update (λa, univ) a s, {a}, by simp [hs]⟩ }
end
lemma pi_generate_from_eq_fintype {g : Πa, set (set (π a))} [fintype ι] (hg : ∀a, ⋃₀ g a = univ) :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)), (∀a, s a ∈ g a) ∧ t = pi univ s} :=
begin
rw [pi_generate_from_eq],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, ht, eq⟩, ⟨t, finset.univ, by simp [ht, eq]⟩,
{ rintros s ⟨t, i, ht, rfl⟩,
apply is_open_iff_forall_mem_open.2 _,
assume f hf,
choose c hc using show ∀a, ∃s, s ∈ g a ∧ f a ∈ s,
{ assume a, have : f a ∈ ⋃₀ g a, { rw [hg], apply mem_univ }, simpa },
refine ⟨pi univ (λa, if a ∈ i then t a else (c : Πa, set (π a)) a), _, _, _⟩,
{ simp [pi_if] },
{ refine generate_open.basic _ ⟨_, assume a, _, rfl⟩,
by_cases a ∈ i; simp [*, set.pi] at * },
{ have : f ∈ pi {a | a ∉ i} c, { simp [*, set.pi] at * },
simpa [pi_if, hf] } }
end
/-- Suppose `π i` is a family of topological spaces indexed by `i : ι`, and `X` is a type
endowed with a family of maps `f i : X → π i` for every `i : ι`, hence inducing a
map `g : X → Π i, π i`. This lemma shows that infimum of the topologies on `X` induced by
the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, π i`
where `Π i, π i` is endowed with the usual product topology. -/
lemma inducing_infi_to_pi {X : Type*} [∀ i, topological_space (π i)] (f : Π i, X → π i) :
@inducing X (Π i, π i) (⨅ i, induced (f i) infer_instance) _ (λ x i, f i x) :=
begin
constructor,
erw induced_infi,
congr' 1,
funext,
erw induced_compose,
end
variables [fintype ι] [∀ i, topological_space (π i)] [∀ i, discrete_topology (π i)]
/-- A finite product of discrete spaces is discrete. -/
instance Pi.discrete_topology : discrete_topology (Π i, π i) :=
singletons_open_iff_discrete.mp (λ x,
begin
rw show {x} = ⋂ i, {y : Π i, π i | y i = x i},
{ ext, simp only [function.funext_iff, set.mem_singleton_iff, set.mem_Inter, set.mem_set_of_eq] },
exact is_open_Inter (λ i, (continuous_apply i).is_open_preimage {x i} (is_open_discrete {x i}))
end)
end pi
section sigma
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
@[continuity]
lemma continuous_sigma_mk {i : ι} : continuous (@sigma.mk ι σ i) :=
continuous_supr_rng continuous_coinduced_rng
lemma is_open_sigma_iff {s : set (sigma σ)} : is_open s ↔ ∀ i, is_open (sigma.mk i ⁻¹' s) :=
by simp only [is_open_supr_iff, is_open_coinduced]
lemma is_closed_sigma_iff {s : set (sigma σ)} : is_closed s ↔ ∀ i, is_closed (sigma.mk i ⁻¹' s) :=
by simp only [← is_open_compl_iff, is_open_sigma_iff, preimage_compl]
lemma is_open_map_sigma_mk {i : ι} : is_open_map (@sigma.mk ι σ i) :=
begin
intros s hs,
rw is_open_sigma_iff,
intro j,
rcases eq_or_ne i j with (rfl|hne),
{ rwa set.preimage_image_eq _ sigma_mk_injective },
{ convert is_open_empty,
apply set.eq_empty_of_subset_empty,
rintro x ⟨y, _, hy⟩,
have : i = j, by cc,
contradiction }
end
lemma is_open_range_sigma_mk {i : ι} : is_open (set.range (@sigma.mk ι σ i)) :=
is_open_map_sigma_mk.is_open_range
lemma is_closed_map_sigma_mk {i : ι} : is_closed_map (@sigma.mk ι σ i) :=
begin
intros s hs,
rw is_closed_sigma_iff,
intro j,
rcases eq_or_ne i j with (rfl|hne),
{ rwa set.preimage_image_eq _ sigma_mk_injective },
{ convert is_closed_empty,
apply set.eq_empty_of_subset_empty,
rintro x ⟨y, _, hy⟩,
have : i = j, by cc,
contradiction }
end
lemma is_closed_sigma_mk {i : ι} : is_closed (set.range (@sigma.mk ι σ i)) :=
by { rw ←set.image_univ, exact is_closed_map_sigma_mk _ is_closed_univ }
lemma open_embedding_sigma_mk {i : ι} : open_embedding (@sigma.mk ι σ i) :=
open_embedding_of_continuous_injective_open
continuous_sigma_mk sigma_mk_injective is_open_map_sigma_mk
lemma closed_embedding_sigma_mk {i : ι} : closed_embedding (@sigma.mk ι σ i) :=
closed_embedding_of_continuous_injective_closed
continuous_sigma_mk sigma_mk_injective is_closed_map_sigma_mk
lemma embedding_sigma_mk {i : ι} : embedding (@sigma.mk ι σ i) :=
closed_embedding_sigma_mk.1
lemma is_open_sigma_fst_preimage (s : set ι) : is_open (sigma.fst ⁻¹' s : set (Σ a, σ a)) :=
begin
rw [← bUnion_of_singleton s, preimage_Union₂],
simp only [← range_sigma_mk],
exact is_open_bUnion (λ _ _, is_open_range_sigma_mk)
end
/-- A map out of a sum type is continuous if its restriction to each summand is. -/
@[continuity]
lemma continuous_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, continuous (λ a, f ⟨i, a⟩)) : continuous f :=
continuous_supr_dom (λ i, continuous_coinduced_dom (h i))
@[continuity]
lemma continuous_sigma_map {κ : Type*} {τ : κ → Type*} [Π k, topological_space (τ k)]
{f₁ : ι → κ} {f₂ : Π i, σ i → τ (f₁ i)} (hf : ∀ i, continuous (f₂ i)) :
continuous (sigma.map f₁ f₂) :=
continuous_sigma $ λ i,
show continuous (λ a, sigma.mk (f₁ i) (f₂ i a)),
from continuous_sigma_mk.comp (hf i)
lemma is_open_map_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, is_open_map (λ a, f ⟨i, a⟩)) : is_open_map f :=
begin
intros s hs,
rw is_open_sigma_iff at hs,
rw [← Union_image_preimage_sigma_mk_eq_self s, image_Union],
apply is_open_Union,
intro i,
rw [image_image],
exact h i _ (hs i)
end
/-- The sum of embeddings is an embedding. -/
lemma embedding_sigma_map {τ : ι → Type*} [Π i, topological_space (τ i)]
{f : Π i, σ i → τ i} (hf : ∀ i, embedding (f i)) : embedding (sigma.map id f) :=
begin
refine ⟨⟨_⟩, function.injective_id.sigma_map (λ i, (hf i).inj)⟩,
refine le_antisymm
(continuous_iff_le_induced.mp (continuous_sigma_map (λ i, (hf i).continuous))) _,
intros s hs,
replace hs := is_open_sigma_iff.mp hs,
have : ∀ i, ∃ t, is_open t ∧ f i ⁻¹' t = sigma.mk i ⁻¹' s,
{ intro i,
apply is_open_induced_iff.mp,
convert hs i,
exact (hf i).induced.symm },
choose t ht using this,
apply is_open_induced_iff.mpr,
refine ⟨⋃ i, sigma.mk i '' t i, is_open_Union (λ i, is_open_map_sigma_mk _ (ht i).1), _⟩,
ext ⟨i, x⟩,
change (sigma.mk i (f i x) ∈ ⋃ (i : ι), sigma.mk i '' t i) ↔ x ∈ sigma.mk i ⁻¹' s,
rw [←(ht i).2, mem_Union],
split,
{ rintro ⟨j, hj⟩,
rw mem_image at hj,
rcases hj with ⟨y, hy₁, hy₂⟩,
rcases sigma.mk.inj_iff.mp hy₂ with ⟨rfl, hy⟩,
replace hy := eq_of_heq hy,
subst y,
exact hy₁ },
{ intro hx,
use i,
rw mem_image,
exact ⟨f i x, hx, rfl⟩ }
end
end sigma
section ulift
@[continuity] lemma continuous_ulift_down [topological_space α] :
continuous (ulift.down : ulift.{v u} α → α) :=
continuous_induced_dom
@[continuity] lemma continuous_ulift_up [topological_space α] :
continuous (ulift.up : α → ulift.{v u} α) :=
continuous_induced_rng continuous_id
end ulift
lemma mem_closure_of_continuous [topological_space α] [topological_space β]
{f : α → β} {a : α} {s : set α} {t : set β}
(hf : continuous f) (ha : a ∈ closure s) (h : maps_to f s (closure t)) :
f a ∈ closure t :=
calc f a ∈ f '' closure s : mem_image_of_mem _ ha
... ⊆ closure (f '' s) : image_closure_subset_closure_image hf
... ⊆ closure t : closure_minimal h.image_subset is_closed_closure
lemma mem_closure_of_continuous2 [topological_space α] [topological_space β] [topological_space γ]
{f : α → β → γ} {a : α} {b : β} {s : set α} {t : set β} {u : set γ}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(h : ∀a∈s, ∀b∈t, f a b ∈ closure u) :
f a b ∈ closure u :=
have (a,b) ∈ closure (s ×ˢ t),
by simp [closure_prod_eq, ha, hb],
show f (a, b).1 (a, b).2 ∈ closure u,
from @mem_closure_of_continuous (α×β) _ _ _ (λp:α×β, f p.1 p.2) (a,b) _ u hf this $
assume ⟨p₁, p₂⟩ ⟨h₁, h₂⟩, h p₁ h₁ p₂ h₂
|
d9cebbbbc4ddca727d6231869ecbf1bfb98ea2be
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/emptyc_issue.lean
|
7c3979d4d236b90fac5daca5f50d83ed6acc58f9
|
[
"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
| 77
|
lean
|
open tactic
meta def issue (hs : hinst_lemmas) : tactic unit :=
rsimp {} hs
|
18e904d7b3fb68f0c126b9db2cb292b294499ee8
|
8eeb99d0fdf8125f5d39a0ce8631653f588ee817
|
/src/topology/algebra/module.lean
|
d164b100f5a1ecf3310d6f118d39a7e5e0feb67e
|
[
"Apache-2.0"
] |
permissive
|
jesse-michael-han/mathlib
|
a15c58378846011b003669354cbab7062b893cfe
|
fa6312e4dc971985e6b7708d99a5bc3062485c89
|
refs/heads/master
| 1,625,200,760,912
| 1,602,081,753,000
| 1,602,081,753,000
| 181,787,230
| 0
| 0
| null | 1,555,460,682,000
| 1,555,460,682,000
| null |
UTF-8
|
Lean
| false
| false
| 47,849
|
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
-/
import topology.algebra.ring
import topology.uniform_space.uniform_embedding
import algebra.algebra.basic
import linear_algebra.projection
/-!
# Theory of topological modules and continuous linear maps.
We define classes `topological_semimodule`, `topological_module` and `topological_vector_spaces`,
as extensions of the corresponding algebraic classes where the algebraic operations are continuous.
We also define continuous linear maps, as linear maps between topological modules which are
continuous. The set of continuous linear maps between the topological `R`-modules `M` and `M₂` is
denoted by `M →L[R] M₂`.
Continuous linear equivalences are denoted by `M ≃L[R] M₂`.
## Implementation notes
Topological vector spaces are defined as an `abbreviation` for topological modules,
if the base ring is a field. This has as advantage that topological vector spaces are completely
transparent for type class inference, which means that all instances for topological modules
are immediately picked up for vector spaces as well.
A cosmetic disadvantage is that one can not extend topological vector spaces.
The solution is to extend `topological_module` instead.
-/
open filter
open_locale topological_space big_operators
universes u v w u'
/-- A topological semimodule, over a semiring which is also a topological space, is a
semimodule in which scalar multiplication is continuous. In applications, R will be a topological
semiring and M a topological additive semigroup, but this is not needed for the definition -/
class topological_semimodule (R : Type u) (M : Type v)
[semiring R] [topological_space R]
[topological_space M] [add_comm_monoid M]
[semimodule R M] : Prop :=
(continuous_smul : continuous (λp : R × M, p.1 • p.2))
section
variables {R : Type u} {M : Type v}
[semiring R] [topological_space R]
[topological_space M] [add_comm_monoid M]
[semimodule R M] [topological_semimodule R M]
lemma continuous_smul : continuous (λp:R×M, p.1 • p.2) :=
topological_semimodule.continuous_smul
@[continuity]
lemma continuous.smul {α : Type*} [topological_space α] {f : α → R} {g : α → M}
(hf : continuous f) (hg : continuous g) : continuous (λp, f p • g p) :=
continuous_smul.comp (hf.prod_mk hg)
lemma tendsto_smul {c : R} {x : M} : tendsto (λp:R×M, p.fst • p.snd) (𝓝 (c, x)) (𝓝 (c • x)) :=
continuous_smul.tendsto _
lemma filter.tendsto.smul {α : Type*} {l : filter α} {f : α → R} {g : α → M} {c : R} {x : M}
(hf : tendsto f l (𝓝 c)) (hg : tendsto g l (𝓝 x)) : tendsto (λ a, f a • g a) l (𝓝 (c • x)) :=
tendsto_smul.comp (hf.prod_mk_nhds hg)
end
instance topological_semiring.to_semimodule {R : Type*} [topological_space R]
[semiring R] [topological_semiring R] :
topological_semimodule R R :=
{ continuous_smul := continuous_mul }
/-- A topological module, over a ring which is also a topological space, is a module in which
scalar multiplication is continuous. In applications, `R` will be a topological ring and `M` a
topological additive group, but this is not needed for the definition -/
abbreviation topological_module (R : Type u) (M : Type v)
[ring R] [topological_space R]
[topological_space M] [add_comm_group M] [module R M] :=
topological_semimodule R M
/-- A topological vector space is a topological module over a field. -/
abbreviation topological_vector_space (R : Type u) (M : Type v)
[field R] [topological_space R]
[topological_space M] [add_comm_group M] [module R M] :=
topological_module R M
section
variables {R : Type*} {M : Type*}
[ring R] [topological_space R]
[topological_space M] [add_comm_group M]
[module R M] [topological_module R M]
/-- Scalar multiplication by a unit is a homeomorphism from a
topological module onto itself. -/
protected def homeomorph.smul_of_unit (a : units R) : M ≃ₜ M :=
{ to_fun := λ x, (a : R) • x,
inv_fun := λ x, ((a⁻¹ : units R) : R) • x,
right_inv := λ x, calc (a : R) • ((a⁻¹ : units R) : R) • x = x :
by rw [smul_smul, units.mul_inv, one_smul],
left_inv := λ x, calc ((a⁻¹ : units R) : R) • (a : R) • x = x :
by rw [smul_smul, units.inv_mul, one_smul],
continuous_to_fun := continuous_const.smul continuous_id,
continuous_inv_fun := continuous_const.smul continuous_id }
lemma is_open_map_smul_of_unit (a : units R) : is_open_map (λ (x : M), (a : R) • x) :=
(homeomorph.smul_of_unit a).is_open_map
lemma is_closed_map_smul_of_unit (a : units R) : is_closed_map (λ (x : M), (a : R) • x) :=
(homeomorph.smul_of_unit a).is_closed_map
/-- 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 nondiscrete normed field. -/
lemma submodule.eq_top_of_nonempty_interior' [has_continuous_add M]
[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,
rcases nonempty_of_mem_sets (inter_mem_sets (mem_map.1 (this hy)) self_mem_nhds_within)
with ⟨_, hu, u, rfl⟩,
have hy' : y ∈ ↑s := mem_of_nhds hy,
exact (s.smul_mem_iff' _).1 ((s.add_mem_iff_right hy').1 hu)
end
end
section
variables {R : Type*} {M : Type*} {a : R}
[field R] [topological_space R]
[topological_space M] [add_comm_group M]
[vector_space R M] [topological_vector_space R M]
/-- Scalar multiplication by a non-zero field element is a
homeomorphism from a topological vector space onto itself. -/
protected def homeomorph.smul_of_ne_zero (ha : a ≠ 0) : M ≃ₜ M :=
{.. homeomorph.smul_of_unit (units.mk0 a ha)}
lemma is_open_map_smul_of_ne_zero (ha : a ≠ 0) : is_open_map (λ (x : M), a • x) :=
(homeomorph.smul_of_ne_zero ha).is_open_map
/-- `smul` is a closed map in the second argument.
The lemma that `smul` is a closed map in the first argument (for a normed space over a complete
normed field) is `is_closed_map_smul_left` in `analysis.normed_space.finite_dimension`. -/
lemma is_closed_map_smul_of_ne_zero (ha : a ≠ 0) : is_closed_map (λ (x : M), a • x) :=
(homeomorph.smul_of_ne_zero ha).is_closed_map
end
/-- 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*) [semiring R]
(M : Type*) [topological_space M] [add_comm_monoid M]
(M₂ : Type*) [topological_space M₂] [add_comm_monoid M₂]
[semimodule R M] [semimodule R M₂]
extends linear_map R M M₂ :=
(cont : continuous to_fun . tactic.interactive.continuity')
notation M ` →L[`:25 R `] ` M₂ := continuous_linear_map R M M₂
/-- 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 ring `R`. -/
@[nolint has_inhabited_instance]
structure continuous_linear_equiv
(R : Type*) [semiring R]
(M : Type*) [topological_space M] [add_comm_monoid M]
(M₂ : Type*) [topological_space M₂] [add_comm_monoid M₂]
[semimodule R M] [semimodule R M₂]
extends linear_equiv R M M₂ :=
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
(continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity')
notation M ` ≃L[`:50 R `] ` M₂ := continuous_linear_equiv R M M₂
namespace continuous_linear_map
section semiring
/- Properties that hold for non-necessarily commutative semirings. -/
variables
{R : Type*} [semiring 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₄]
[semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄]
/-- Coerce continuous linear maps to linear maps. -/
instance : has_coe (M →L[R] M₂) (M →ₗ[R] M₂) := ⟨to_linear_map⟩
/-- Coerce continuous linear maps to functions. -/
-- see Note [function coercion]
instance to_fun : has_coe_to_fun $ M →L[R] M₂ := ⟨λ _, M → M₂, λ f, f⟩
@[simp] lemma coe_mk (f : M →ₗ[R] M₂) (h) : (mk f h : M →ₗ[R] M₂) = f := rfl
@[simp] lemma coe_mk' (f : M →ₗ[R] M₂) (h) : (mk f h : M → M₂) = f := rfl
@[continuity]
protected lemma continuous (f : M →L[R] M₂) : continuous f := f.2
theorem coe_injective : function.injective (coe : (M →L[R] M₂) → (M →ₗ[R] M₂)) :=
by { intros f g H, cases f, cases g, congr' 1, exact H }
theorem coe_inj ⦃f g : M →L[R] M₂⦄ (H : (f : M → M₂) = g) : f = g :=
coe_injective $ linear_map.coe_inj H
@[ext] theorem ext {f g : M →L[R] M₂} (h : ∀ x, f x = g x) : f = g :=
coe_inj $ funext h
theorem ext_iff {f g : M →L[R] M₂} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, by rw h, by ext⟩
variables (c : R) (f g : M →L[R] M₂) (h : M₂ →L[R] M₃) (x y z : M)
-- make some straightforward lemmas available to `simp`.
@[simp] lemma map_zero : f (0 : M) = 0 := (to_linear_map _).map_zero
@[simp] lemma map_add : f (x + y) = f x + f y := (to_linear_map _).map_add _ _
@[simp] lemma map_smul : f (c • x) = c • f x := (to_linear_map _).map_smul _ _
lemma map_sum {ι : Type*} (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 →ₗ[R] M₂) : (M → M₂)) = (f : M → M₂) := rfl
/-- The continuous map that is constantly zero. -/
instance: has_zero (M →L[R] M₂) := ⟨⟨0, continuous_const⟩⟩
instance : inhabited (M →L[R] M₂) := ⟨0⟩
@[simp] lemma zero_apply : (0 : M →L[R] M₂) x = 0 := rfl
@[simp, norm_cast] lemma coe_zero : ((0 : M →L[R] M₂) : M →ₗ[R] 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 →L[R] M₂) : M → M₂) = 0 := rfl
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 id_apply : 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 : M → M) = _root_.id := rfl
@[simp] lemma one_apply : (1 : M →L[R] M) x = x := rfl
section add
variables [has_continuous_add M₂]
instance : has_add (M →L[R] M₂) :=
⟨λ f g, ⟨f + g, f.2.add g.2⟩⟩
@[simp] lemma add_apply : (f + g) x = f x + g x := rfl
@[simp, norm_cast] lemma coe_add : (((f + g) : M →L[R] M₂) : M →ₗ[R] M₂) = (f : M →ₗ[R] M₂) + g := rfl
@[norm_cast] lemma coe_add' : (((f + g) : M →L[R] M₂) : M → M₂) = (f : M → M₂) + g := rfl
instance : add_comm_monoid (M →L[R] M₂) :=
by { refine {zero := 0, add := (+), ..}; intros; ext;
apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] }
lemma sum_apply {ι : Type*} (t : finset ι) (f : ι → M →L[R] M₂) (b : M) :
(∑ d in t, f d) b = ∑ d in t, f d b :=
begin
haveI : is_add_monoid_hom (λ (g : M →L[R] M₂), g b) :=
{ map_add := λ f g, continuous_linear_map.add_apply f g b, map_zero := by simp },
exact (finset.sum_hom t (λ g : M →L[R] M₂, g b)).symm
end
end add
/-- Composition of bounded linear maps. -/
def comp (g : M₂ →L[R] M₃) (f : M →L[R] M₂) : M →L[R] M₃ :=
⟨linear_map.comp g.to_linear_map f.to_linear_map, g.2.comp f.2⟩
@[simp, norm_cast] lemma coe_comp : ((h.comp f) : (M →ₗ[R] M₃)) = (h : M₂ →ₗ[R] M₃).comp f := rfl
@[simp, norm_cast] lemma coe_comp' : ((h.comp f) : (M → M₃)) = (h : M₂ → M₃) ∘ f := rfl
@[simp] theorem comp_id : f.comp (id R M) = f :=
ext $ λ x, rfl
@[simp] theorem id_comp : (id R M₂).comp f = f :=
ext $ λ x, rfl
@[simp] theorem comp_zero : f.comp (0 : M₃ →L[R] M) = 0 :=
by { ext, simp }
@[simp] theorem zero_comp : (0 : M₂ →L[R] M₃).comp f = 0 :=
by { ext, simp }
@[simp] lemma comp_add [has_continuous_add M₂] [has_continuous_add M₃]
(g : M₂ →L[R] M₃) (f₁ f₂ : M →L[R] 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₂ →L[R] M₃) (f : M →L[R] M₂) :
(g₁ + g₂).comp f = g₁.comp f + g₂.comp f :=
by { ext, simp }
theorem comp_assoc (h : M₃ →L[R] M₄) (g : M₂ →L[R] M₃) (f : M →L[R] 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
/-- The cartesian product of two bounded linear maps, as a bounded linear map. -/
protected def prod (f₁ : M →L[R] M₂) (f₂ : M →L[R] M₃) : M →L[R] (M₂ × M₃) :=
{ cont := f₁.2.prod_mk f₂.2,
..f₁.to_linear_map.prod f₂.to_linear_map }
@[simp, norm_cast] lemma coe_prod (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 (f₁ : M →L[R] M₂) (f₂ : M →L[R] M₃) (x : M) :
f₁.prod f₂ x = (f₁ x, f₂ x) :=
rfl
/-- Kernel of a continuous linear map. -/
def ker (f : M →L[R] M₂) : submodule R M := (f : M →ₗ[R] M₂).ker
@[norm_cast] lemma ker_coe : (f : M →ₗ[R] M₂).ker = f.ker := rfl
@[simp] lemma mem_ker {f : M →L[R] M₂} {x} : x ∈ f.ker ↔ f x = 0 := linear_map.mem_ker
lemma is_closed_ker [t1_space M₂] : is_closed (f.ker : set M) :=
continuous_iff_is_closed.1 f.cont _ is_closed_singleton
@[simp] lemma apply_ker (x : f.ker) : f x = 0 := mem_ker.1 x.2
lemma is_complete_ker {M' : Type*} [uniform_space M'] [complete_space M'] [add_comm_monoid M']
[semimodule R M'] [t1_space M₂] (f : M' →L[R] M₂) :
is_complete (f.ker : set M') :=
f.is_closed_ker.is_complete
instance complete_space_ker {M' : Type*} [uniform_space M'] [complete_space M'] [add_comm_monoid M']
[semimodule R M'] [t1_space M₂] (f : M' →L[R] M₂) :
complete_space f.ker :=
f.is_closed_ker.complete_space_coe
@[simp] lemma ker_prod (f : M →L[R] M₂) (g : M →L[R] M₃) :
ker (f.prod g) = ker f ⊓ ker g :=
linear_map.ker_prod f g
/-- Range of a continuous linear map. -/
def range (f : M →L[R] M₂) : submodule R M₂ := (f : M →ₗ[R] M₂).range
lemma range_coe : (f.range : set M₂) = set.range f := linear_map.range_coe _
lemma mem_range {f : M →L[R] M₂} {y} : y ∈ f.range ↔ ∃ x, f x = y := linear_map.mem_range
lemma range_prod_le (f : M →L[R] M₂) (g : M →L[R] M₃) :
range (f.prod g) ≤ (range f).prod (range g) :=
(f : M →ₗ[R] M₂).range_prod_le g
/-- Restrict codomain of a continuous linear map. -/
def cod_restrict (f : M →L[R] M₂) (p : submodule R M₂) (h : ∀ x, f x ∈ p) :
M →L[R] p :=
{ cont := continuous_subtype_mk h f.continuous,
to_linear_map := (f : M →ₗ[R] M₂).cod_restrict p h}
@[norm_cast] lemma coe_cod_restrict (f : M →L[R] M₂) (p : submodule R M₂) (h : ∀ x, f x ∈ p) :
(f.cod_restrict p h : M →ₗ[R] p) = (f : M →ₗ[R] M₂).cod_restrict p h :=
rfl
@[simp] lemma coe_cod_restrict_apply (f : M →L[R] 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 →L[R] M₂) (p : submodule R M₂) (h : ∀ x, f x ∈ p) :
ker (f.cod_restrict p h) = ker f :=
(f : M →ₗ[R] M₂).ker_cod_restrict p h
/-- Embedding of a submodule into the ambient space as a continuous linear map. -/
def subtype_val (p : submodule R M) : p →L[R] M :=
{ cont := continuous_subtype_val,
to_linear_map := p.subtype }
@[simp, norm_cast] lemma coe_subtype_val (p : submodule R M) :
(subtype_val p : p →ₗ[R] M) = p.subtype :=
rfl
@[simp, norm_cast] lemma subtype_val_apply (p : submodule R M) (x : p) :
(subtype_val p : p → M) x = x :=
rfl
variables (R M M₂)
/-- `prod.fst` as a `continuous_linear_map`. -/
def fst : 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 : 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 : (fst R M M₂ : M × M₂ →ₗ[R] M) = linear_map.fst R M M₂ := rfl
@[simp, norm_cast] lemma coe_fst' : (fst R M M₂ : M × M₂ → M) = prod.fst := rfl
@[simp, norm_cast] lemma coe_snd : (snd R M M₂ : M × M₂ →ₗ[R] M₂) = linear_map.snd R M M₂ := rfl
@[simp, norm_cast] lemma coe_snd' : (snd R M M₂ : M × M₂ → M₂) = prod.snd := rfl
@[simp] lemma fst_prod_snd : (fst R M M₂).prod (snd R M M₂) = id R (M × M₂) := ext $ λ ⟨x, y⟩, rfl
/-- `prod.map` of two continuous linear maps. -/
def prod_map (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 (f₁ : M →L[R] M₂) (f₂ : M₃ →L[R] M₄) :
(f₁.prod_map f₂ : (M × M₃) →ₗ[R] (M₂ × M₄)) = ((f₁ : M →ₗ[R] M₂).prod_map (f₂ : M₃ →ₗ[R] M₄)) :=
rfl
@[simp, norm_cast] lemma coe_prod_map' (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 [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 [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 [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
variables [topological_space R] [topological_semimodule R 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] R) (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] R} {f : M₂} {x : M} :
(smul_right c f : M → M₂) x = (c : M → R) x • f :=
rfl
@[simp]
lemma smul_right_one_one (c : R →L[R] M₂) : smul_right 1 ((c : R → M₂) 1) = c :=
by ext; simp [-continuous_linear_map.map_smul, (continuous_linear_map.map_smul _ _ _).symm]
@[simp]
lemma smul_right_one_eq_iff {f f' : M₂} :
smul_right (1 : R →L[R] R) f = smul_right 1 f' ↔ f = f' :=
⟨λ h, have (smul_right (1 : R →L[R] R) f : R → M₂) 1 = (smul_right (1 : R →L[R] R) f' : R → M₂) 1,
by rw h,
by simp at this; assumption,
by cc⟩
lemma smul_right_comp [topological_semimodule R R] {x : M₂} {c : R} :
(smul_right 1 x : R →L[R] M₂).comp (smul_right 1 c : R →L[R] R) = smul_right 1 (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] [semimodule R M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂] [semimodule R M₂]
{ι : Type*} {φ : ι → Type*} [∀i, topological_space (φ i)] [∀i, add_comm_monoid (φ i)] [∀i, semimodule 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 : M →ₗ[R] φ i)),
continuous_pi (λ i, (f i).continuous)⟩
@[simp] 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 ⟨λh a b, h b a, λh a b, h b a⟩
lemma pi_zero : pi (λi, 0 : Πi, M →L[R] φ i) = 0 := by ext; refl
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) : 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) : submodule R (Πi, φ i)) ≃L[R] (Πi:I, φ i) :=
⟨ linear_map.infi_ker_proj_equiv R φ hd hu,
continuous_pi (λ i, begin
have := @continuous_subtype_coe _ _ (λ x, x ∈ (⨅i ∈ J, ker (proj i) : submodule R (Πi, φ i))),
have := continuous.comp (by exact continuous_apply i) this,
exact this
end),
continuous_subtype_mk _ (continuous_pi (λ i, begin
dsimp, split_ifs; [apply continuous_apply, exact continuous_const]
end)) ⟩
end pi
section ring
variables
{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₄]
[semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄]
variables (c : R) (f g : M →L[R] M₂) (h : M₂ →L[R] M₃) (x y z : M)
@[simp] lemma map_neg : f (-x) = - (f x) := (to_linear_map _).map_neg _
@[simp] lemma map_sub : f (x - y) = f x - f y := (to_linear_map _).map_sub _ _
@[simp] lemma sub_apply' (x : M) : ((f : M →ₗ[R] M₂) - g) x = f x - g x := rfl
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
section
variables [topological_add_group M₂]
instance : has_neg (M →L[R] M₂) := ⟨λ f, ⟨-f, f.2.neg⟩⟩
@[simp] lemma neg_apply : (-f) x = - (f x) := rfl
@[simp, norm_cast] lemma coe_neg : (((-f) : M →L[R] M₂) : M →ₗ[R] M₂) = -(f : M →ₗ[R] M₂) := rfl
@[norm_cast] lemma coe_neg' : (((-f) : M →L[R] M₂) : M → M₂) = -(f : M → M₂) := rfl
instance : add_comm_group (M →L[R] M₂) :=
by { refine {zero := 0, add := (+), neg := has_neg.neg, ..}; intros; ext;
apply_rules [zero_add, add_assoc, add_zero, add_left_neg, add_comm] }
lemma sub_apply (x : M) : (f - g) x = f x - g x := rfl
@[simp, norm_cast] lemma coe_sub : (((f - g) : M →L[R] M₂) : M →ₗ[R] M₂) = (f : M →ₗ[R] M₂) - g := rfl
@[simp, norm_cast] lemma coe_sub' : (((f - g) : M →L[R] M₂) : M → M₂) = (f : M → M₂) - g := rfl
end
instance [topological_add_group M] : ring (M →L[R] M) :=
{ mul := (*),
one := 1,
mul_one := λ _, ext $ λ _, rfl,
one_mul := λ _, ext $ λ _, rfl,
mul_assoc := λ _ _ _, ext $ λ _, rfl,
left_distrib := λ _ _ _, ext $ λ _, map_add _ _ _,
right_distrib := λ _ _ _, ext $ λ _, linear_map.add_apply _ _ _,
..continuous_linear_map.add_comm_group }
lemma smul_right_one_pow [topological_space R]
[topological_add_group R] [topological_semimodule R R] (c : R) (n : ℕ) :
(smul_right 1 c : R →L[R] R)^n = smul_right 1 (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
/-- 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 →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : function.right_inverse f₂ f₁) :
M →L[R] f₁.ker :=
(id R M - f₂.comp f₁).cod_restrict f₁.ker $ λ x, by simp [h (f₁ x)]
@[simp] lemma coe_proj_ker_of_right_inverse_apply [topological_add_group M]
(f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] 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 →L[R] M₂) (f₂ : M₂ →L[R] M) (h : function.right_inverse f₂ f₁) (x : f₁.ker) :
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 →L[R] M₂) (f₂ : M₂ →L[R] 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 ring
section comm_ring
variables
{R : Type*} [comm_ring R] [topological_space 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₃] [topological_module R M₃]
instance : has_scalar R (M →L[R] M₃) :=
⟨λ c f, ⟨c • f, continuous_const.smul f.2⟩⟩
variables (c : R) (h : M₂ →L[R] M₃) (f g : M →L[R] M₂) (x y z : M)
@[simp] lemma smul_comp : (c • h).comp f = c • (h.comp f) := rfl
variable [topological_module R M₂]
@[simp] lemma smul_apply : (c • f) x = c • (f x) := rfl
@[simp, norm_cast] lemma coe_apply : (((c • f) : M →L[R] M₂) : M →ₗ[R] M₂) = c • (f : M →ₗ[R] M₂) := rfl
@[norm_cast] lemma coe_apply' : (((c • f) : M →L[R] M₂) : M → M₂) = c • (f : M → M₂) := rfl
@[simp] lemma comp_smul : h.comp (c • f) = c • (h.comp f) := by { ext, simp }
variable [topological_add_group M₂]
instance : module R (M →L[R] M₂) :=
{ smul_zero := λ _, ext $ λ _, smul_zero _,
zero_smul := λ _, ext $ λ _, zero_smul _ _,
one_smul := λ _, ext $ λ _, one_smul _ _,
mul_smul := λ _ _ _, ext $ λ _, mul_smul _ _ _,
add_smul := λ _ _ _, ext $ λ _, add_smul _ _ _,
smul_add := λ _ _ _, ext $ λ _, smul_add _ _ _ }
instance : algebra R (M₂ →L[R] M₂) :=
algebra.of_semimodule' (λ c f, ext $ λ x, rfl) (λ c f, ext $ λ x, f.map_smul c x)
/-- 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] R) : M₂ →ₗ[R] (M →L[R] M₂) :=
{ to_fun := c.smul_right,
map_add' := λ x y, by { ext e, simp [smul_add] },
map_smul' := λ a x, by { ext e, simp [smul_comm] } }
end comm_ring
end continuous_linear_map
namespace continuous_linear_equiv
section add_comm_monoid
variables {R : Type*} [semiring 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₄]
[semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄]
/-- A continuous linear equivalence induces a continuous linear map. -/
def to_continuous_linear_map (e : M ≃L[R] M₂) : M →L[R] 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 ≃L[R] M₂) (M →L[R] M₂) := ⟨to_continuous_linear_map⟩
/-- Coerce continuous linear equivs to maps. -/
-- see Note [function coercion]
instance : has_coe_to_fun (M ≃L[R] M₂) := ⟨λ _, M → M₂, λ f, f⟩
@[simp] theorem coe_def_rev (e : M ≃L[R] M₂) : e.to_continuous_linear_map = e := rfl
@[simp] theorem coe_apply (e : M ≃L[R] M₂) (b : M) : (e : M →L[R] M₂) b = e b := rfl
@[norm_cast] lemma coe_coe (e : M ≃L[R] M₂) : ((e : M →L[R] M₂) : M → M₂) = e := rfl
@[ext] lemma ext {f g : M ≃L[R] M₂} (h : (f : M → M₂) = g) : f = g :=
begin
cases f; cases g,
simp only,
ext x,
induction h,
refl
end
/-- A continuous linear equivalence induces a homeomorphism. -/
def to_homeomorph (e : M ≃L[R] M₂) : M ≃ₜ M₂ := { ..e }
-- Make some straightforward lemmas available to `simp`.
@[simp] lemma map_zero (e : M ≃L[R] M₂) : e (0 : M) = 0 := (e : M →L[R] M₂).map_zero
@[simp] lemma map_add (e : M ≃L[R] M₂) (x y : M) : e (x + y) = e x + e y :=
(e : M →L[R] M₂).map_add x y
@[simp] lemma map_smul (e : M ≃L[R] M₂) (c : R) (x : M) : e (c • x) = c • (e x) :=
(e : M →L[R] M₂).map_smul c x
@[simp] lemma map_eq_zero_iff (e : M ≃L[R] 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 ≃L[R] M₂) : continuous (e : M → M₂) :=
e.continuous_to_fun
protected lemma continuous_on (e : M ≃L[R] M₂) {s : set M} : continuous_on (e : M → M₂) s :=
e.continuous.continuous_on
protected lemma continuous_at (e : M ≃L[R] M₂) {x : M} : continuous_at (e : M → M₂) x :=
e.continuous.continuous_at
protected lemma continuous_within_at (e : M ≃L[R] 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 ≃L[R] 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 ≃L[R] M₂) (f : α → M) :
continuous (e ∘ f) ↔ continuous f :=
e.to_homeomorph.comp_continuous_iff _
/-- 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 : M →L[R] M) = continuous_linear_map.id R M := rfl
@[simp, norm_cast] lemma coe_refl' :
(continuous_linear_equiv.refl R M : M → M) = id := rfl
/-- The inverse of a continuous linear equivalence as a continuous linear equivalence-/
@[symm] protected def symm (e : M ≃L[R] M₂) : M₂ ≃L[R] M :=
{ continuous_to_fun := e.continuous_inv_fun,
continuous_inv_fun := e.continuous_to_fun,
.. e.to_linear_equiv.symm }
@[simp] lemma symm_to_linear_equiv (e : M ≃L[R] M₂) :
e.symm.to_linear_equiv = e.to_linear_equiv.symm :=
by { ext, refl }
/-- The composition of two continuous linear equivalences as a continuous linear equivalence. -/
@[trans] protected def trans (e₁ : M ≃L[R] M₂) (e₂ : M₂ ≃L[R] M₃) : M ≃L[R] 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 }
@[simp] lemma trans_to_linear_equiv (e₁ : M ≃L[R] M₂) (e₂ : M₂ ≃L[R] M₃) :
(e₁.trans e₂).to_linear_equiv = e₁.to_linear_equiv.trans e₂.to_linear_equiv :=
by { ext, refl }
/-- Product of two continuous linear equivalences. The map comes from `equiv.prod_congr`. -/
def prod (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 (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 (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
theorem bijective (e : M ≃L[R] M₂) : function.bijective e := e.to_linear_equiv.to_equiv.bijective
theorem injective (e : M ≃L[R] M₂) : function.injective e := e.to_linear_equiv.to_equiv.injective
theorem surjective (e : M ≃L[R] M₂) : function.surjective e := e.to_linear_equiv.to_equiv.surjective
@[simp] theorem trans_apply (e₁ : M ≃L[R] M₂) (e₂ : M₂ ≃L[R] M₃) (c : M) :
(e₁.trans e₂) c = e₂ (e₁ c) :=
rfl
@[simp] theorem apply_symm_apply (e : M ≃L[R] M₂) (c : M₂) : e (e.symm c) = c := e.1.6 c
@[simp] theorem symm_apply_apply (e : M ≃L[R] M₂) (b : M) : e.symm (e b) = b := e.1.5 b
@[simp] theorem symm_trans_apply (e₁ : M₂ ≃L[R] M) (e₂ : M₃ ≃L[R] M₂) (c : M) :
(e₂.trans e₁).symm c = e₂.symm (e₁.symm c) :=
rfl
@[simp, norm_cast]
lemma comp_coe (f : M ≃L[R] M₂) (f' : M₂ ≃L[R] M₃) :
(f' : M₂ →L[R] M₃).comp (f : M →L[R] M₂) = (f.trans f' : M →L[R] M₃) :=
rfl
@[simp] theorem coe_comp_coe_symm (e : M ≃L[R] M₂) :
(e : M →L[R] M₂).comp (e.symm : M₂ →L[R] M) = continuous_linear_map.id R M₂ :=
continuous_linear_map.ext e.apply_symm_apply
@[simp] theorem coe_symm_comp_coe (e : M ≃L[R] M₂) :
(e.symm : M₂ →L[R] M).comp (e : M →L[R] M₂) = continuous_linear_map.id R M :=
continuous_linear_map.ext e.symm_apply_apply
lemma symm_comp_self (e : M ≃L[R] M₂) :
(e.symm : M₂ → M) ∘ (e : M → M₂) = id :=
by{ ext x, exact symm_apply_apply e x }
lemma self_comp_symm (e : M ≃L[R] M₂) :
(e : M → M₂) ∘ (e.symm : M₂ → M) = id :=
by{ ext x, exact apply_symm_apply e x }
@[simp] lemma symm_comp_self' (e : M ≃L[R] M₂) :
((e.symm : M₂ →L[R] M) : M₂ → M) ∘ ((e : M →L[R] M₂) : M → M₂) = id :=
symm_comp_self e
@[simp] lemma self_comp_symm' (e : M ≃L[R] M₂) :
((e : M →L[R] M₂) : M → M₂) ∘ ((e.symm : M₂ →L[R] M) : M₂ → M) = id :=
self_comp_symm e
@[simp] theorem symm_symm (e : M ≃L[R] M₂) : e.symm.symm = e :=
by { ext x, refl }
@[simp] lemma refl_symm :
(continuous_linear_equiv.refl R M).symm = continuous_linear_equiv.refl R M :=
rfl
theorem symm_symm_apply (e : M ≃L[R] M₂) (x : M) : e.symm.symm x = e x :=
rfl
lemma symm_apply_eq (e : M ≃L[R] M₂) {x y} : e.symm x = y ↔ x = e y :=
e.to_linear_equiv.symm_apply_eq
lemma eq_symm_apply (e : M ≃L[R] M₂) {x y} : y = e.symm x ↔ e y = x :=
e.to_linear_equiv.eq_symm_apply
/-- Create a `continuous_linear_equiv` from two `continuous_linear_map`s that are
inverse of each other. -/
def equiv_of_inverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M) (h₁ : function.left_inverse f₂ f₁)
(h₂ : function.right_inverse f₂ f₁) :
M ≃L[R] M₂ :=
{ to_fun := f₁,
continuous_to_fun := f₁.continuous,
inv_fun := f₂,
continuous_inv_fun := f₂.continuous,
left_inv := h₁,
right_inv := h₂,
.. f₁ }
@[simp] lemma equiv_of_inverse_apply (f₁ : M →L[R] M₂) (f₂ h₁ h₂ x) :
equiv_of_inverse f₁ f₂ h₁ h₂ x = f₁ x :=
rfl
@[simp] lemma symm_equiv_of_inverse (f₁ : M →L[R] M₂) (f₂ h₁ h₂) :
(equiv_of_inverse f₁ f₂ h₁ h₂).symm = equiv_of_inverse f₂ f₁ h₂ h₁ :=
rfl
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} }
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₄]
[semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule 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]
{M : Type*} [topological_space M] [add_comm_group M] [semimodule R M]
{M₂ : Type*} [topological_space M₂] [add_comm_group M₂] [semimodule R M₂]
@[simp] lemma map_sub (e : M ≃L[R] M₂) (x y : M) : e (x - y) = e x - e y :=
(e : M →L[R] M₂).map_sub x y
@[simp] lemma map_neg (e : M ≃L[R] M₂) (x : M) : e (-x) = -e x := (e : M →L[R] M₂).map_neg x
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 : units (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)) : units (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 : units (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 : units (M →L[R] M)) (x : M) :
(units_equiv R M f) x = f x := rfl
end
section
variables (R) [topological_space R] [topological_module R R]
/-- Continuous linear equivalences `R ≃L[R] R` are enumerated by `units R`. -/
def units_equiv_aut : units R ≃ (R ≃L[R] R) :=
{ to_fun := λ u, equiv_of_inverse
(continuous_linear_map.smul_right 1 ↑u)
(continuous_linear_map.smul_right 1 ↑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 : units R) (x : R) : units_equiv_aut R u x = x * u := rfl
@[simp] lemma units_equiv_aut_apply_symm (u : units 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 [topological_add_group M]
open continuous_linear_map (id fst snd subtype_val 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₂ × f₁.ker :=
equiv_of_inverse (f₁.prod (f₁.proj_ker_of_right_inverse f₂ h)) (f₂.coprod (subtype_val f₁.ker))
(λ 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₂ × f₁.ker) :
(equiv_of_right_inverse f₁ f₂ h).symm y = f₂ y.1 + y.2 := rfl
end ring
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₂] [semimodule R M₂]
variables [add_comm_monoid M] [semimodule 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,
ext x,
have h' := classical.some_spec h,
simpa using continuous_linear_map.ext_iff.1 (h') x -- for some reason `h'` cannot be substituted here
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)).comp e.symm :=
begin
by_cases h₁ : ∃ (e' : M ≃L[R] M₂), ↑e' = f,
{ obtain ⟨e', he'⟩ := h₁,
rw ← he',
ext,
simp },
{ suffices : ¬is_unit ((e.symm : M₂ →L[R] M).comp f),
{ simp [this, h₁] },
revert h₁,
contrapose!,
rintros ⟨F, hF⟩,
use (continuous_linear_equiv.units_equiv _ _ F).trans e,
ext,
simp [hF] }
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, ⟨f.ker, 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 - (subtype_val p).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₁) :
f₁.ker.closed_complemented :=
⟨f₁.proj_ker_of_right_inverse f₂ h, f₁.proj_ker_of_right_inverse_apply_idem f₂ h⟩
|
063f3d1714a2817c0b4a9556df97218e3fcc133e
|
ee8cdbabf07f77e7be63a449b8483ce308d37218
|
/lean/src/test/algebra-ineq-nto1onlt2m1on.lean
|
b6bf090adde9c14f7bf1f52a9bbaff5d41aabe81
|
[
"MIT",
"Apache-2.0"
] |
permissive
|
zeta1999/miniF2F
|
6d66c75d1c18152e224d07d5eed57624f731d4b7
|
c1ba9629559c5273c92ec226894baa0c1ce27861
|
refs/heads/main
| 1,681,897,460,642
| 1,620,646,361,000
| 1,620,646,361,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 233
|
lean
|
/-
Copyright (c) 2021 OpenAI. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kunhao Zheng
-/
import data.real.basic
example (n : ℕ) : n ^ (1 / n) < 2 - 1 / n :=
begin
sorry
end
|
b43956212be5ceeee3a25260f238ae52730f6820
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/tests/lean/t3.lean
|
f87c2d8b1643cec22aebf95f4d4aa49549b2e3d7
|
[
"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
| 945
|
lean
|
universe u
print raw Type.{u}
namespace tst
universe v
print raw Type.{v}
print raw Type.{tst.v}
end tst
print raw Type.{tst.v}
print raw Type.{v} -- Error: alias 'v' is not available anymore
section
universe variable z -- Remark: this is a local universe
print raw Type.{z}
end
print raw Type.{z} -- Error: local universe 'z' is gone
section
namespace foo -- Error: we cannot create a namespace inside a section
end
namespace tst
print raw Type.{v} -- Remark: alias 'v' is available again
print raw Type.{u}
namespace foo
universe U
end foo
end tst
print raw Type.{tst.foo.U}
namespace tst
namespace foo
print raw Type.{v} -- Remark: alias 'v' for 'tst.v' is available again
print raw Type.{U} -- Remark: alias 'U' for 'tst.foo.U' is available again
end foo
end tst
namespace bla
universe u -- Error: we cannot shadow universe levels
end bla
print raw Type.{bla.u} -- Error: we failed to declare bla.u
|
56445a6c705af23113f93fe48c53b49ef316405f
|
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
|
/library/data/bool/default.lean
|
8d4c46ff6cfda6068c6ac9357f16460a0de1a057
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean
|
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
|
0cca265db19f7296531e339192e9b9bae4a31f8b
|
refs/heads/master
| 1,610,909,964,159
| 1,407,084,399,000
| 1,416,857,075,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 217
|
lean
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Leonardo de Moura
import data.bool.decl data.bool.ops data.bool.thms
|
1cb21686fa95adcbb6bee835744bfbff25d6ee1f
|
e38e95b38a38a99ecfa1255822e78e4b26f65bb0
|
/src/certigrad/tgrads.lean
|
f8650f63b913af9f7eb08a8cb8874eca864d76af
|
[
"Apache-2.0"
] |
permissive
|
ColaDrill/certigrad
|
fefb1be3670adccd3bed2f3faf57507f156fd501
|
fe288251f623ac7152e5ce555f1cd9d3a20203c2
|
refs/heads/master
| 1,593,297,324,250
| 1,499,903,753,000
| 1,499,903,753,000
| 97,075,797
| 1
| 0
| null | 1,499,916,210,000
| 1,499,916,210,000
| null |
UTF-8
|
Lean
| false
| false
| 31,339
|
lean
|
/-
Copyright (c) 2017 Daniel Selsam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Daniel Selsam
Properties of gradients.
-/
import .tensor .tfacts .tactics
namespace certigrad
namespace T
open list
-- is_cdifferentiable
axiom is_cdifferentiable_binary {shape : S} (k : T shape → T shape → ℝ) (θ : T shape) :
is_cdifferentiable (λ θ₀, k θ₀ θ) θ → is_cdifferentiable (λ θ₀, k θ θ₀) θ →
is_cdifferentiable (λ θ₀, k θ₀ θ₀) θ
axiom is_cdifferentiable_multiple_args {fshape : S} (tgt : reference) (parents : list reference) (m : env) (f : dvec T parents^.p2 → T fshape)
(θ : T tgt.2) (k : T fshape → ℝ) :
(∀ (idx : ℕ) (H_idx_in_riota: idx ∈ riota (length parents)) (H_tgt_eq_dnth_idx : tgt = dnth parents idx),
is_cdifferentiable (λ θ₀, k (f (dvec.update_at θ₀ (env.get_ks parents (env.insert tgt θ m)) idx))) θ) →
is_cdifferentiable (λ θ₀, k (f (env.get_ks parents (env.insert tgt θ₀ m)))) θ
axiom is_cdifferentiable_integral : ∀ {ishape tshape : S} (f : T ishape → T tshape → ℝ) (θ : T tshape),
(∀ x, is_cdifferentiable (f x) θ) →
is_uniformly_integrable_around (λ θ₀ x, f x θ₀) θ →
is_uniformly_integrable_around (λ θ₀ x, ∇ (λ θ₁, f x θ₁) θ₀) θ →
is_cdifferentiable (λ θ₀, ∫ (λ x, f x θ₀)) θ
axiom is_cdifferentiable_const {ishape : S} (θ : T ishape) (x : ℝ) : is_cdifferentiable (λ (θ₀ : T ishape), x) θ
axiom is_cdifferentiable_id (θ : ℝ) : is_cdifferentiable (λ (θ₀ : ℝ), θ₀) θ
axiom is_cdifferentiable_exp {shape : S} (k : T shape → ℝ) (θ : T shape) :
is_cdifferentiable k (exp θ) → is_cdifferentiable (λ θ, k (exp θ)) θ
axiom is_cdifferentiable_log {shape : S} (k : T shape → ℝ) (θ : T shape) : θ > 0 →
is_cdifferentiable k (log θ) → is_cdifferentiable (λ θ, k (log θ)) θ
axiom is_cdifferentiable_sqrt {shape : S} (k : T shape → ℝ) (θ : T shape) :
is_cdifferentiable k (sqrt θ) → is_cdifferentiable (λ θ, k (sqrt θ)) θ
axiom is_cdifferentiable_inv {shape : S} (k : T shape → ℝ) (θ : T shape) : θ > 0 →
is_cdifferentiable k θ⁻¹ → is_cdifferentiable (λ θ, k θ⁻¹) θ
axiom is_cdifferentiable_scale {shape : S} (k : T shape → ℝ) (α : ℝ) (x : T shape) :
is_cdifferentiable k (α ⬝ x) → is_cdifferentiable (λ x, k (α ⬝ x)) x
axiom is_cdifferentiable_neg {shape : S} (k : T shape → ℝ) (θ : T shape) :
is_cdifferentiable k (- θ) → is_cdifferentiable (λ θ, k (- θ)) θ
axiom is_cdifferentiable_add₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
is_cdifferentiable k (x₁ + x₂) → is_cdifferentiable (λ x₁, k (x₁ + x₂)) x₁
axiom is_cdifferentiable_add₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
is_cdifferentiable k (x₁ + x₂) → is_cdifferentiable (λ x₂, k (x₁ + x₂)) x₂
axiom is_cdifferentiable_sub₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
is_cdifferentiable k (x₁ - x₂) → is_cdifferentiable (λ x₁, k (x₁ - x₂)) x₁
axiom is_cdifferentiable_sub₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
is_cdifferentiable k (x₁ - x₂) → is_cdifferentiable (λ x₂, k (x₁ - x₂)) x₂
axiom is_cdifferentiable_mul₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
is_cdifferentiable k (x₁ * x₂) → is_cdifferentiable (λ x₁, k (x₁ * x₂)) x₁
axiom is_cdifferentiable_mul₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
is_cdifferentiable k (x₁ * x₂) → is_cdifferentiable (λ x₂, k (x₁ * x₂)) x₂
axiom is_cdifferentiable_div₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) : square x₂ > 0 →
is_cdifferentiable k (x₁ / x₂) → is_cdifferentiable (λ x₁, k (x₁ / x₂)) x₁
axiom is_cdifferentiable_div₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) : square x₂ > 0 →
is_cdifferentiable k (x₁ / x₂) → is_cdifferentiable (λ x₂, k (x₁ / x₂)) x₂
axiom is_cdifferentiable_sum (k : ℝ → ℝ) (shape : S) (x : T shape) :
is_cdifferentiable k (sum x) → is_cdifferentiable (λ x, k (sum x)) x
axiom is_cdifferentiable_prod (k : ℝ → ℝ) (shape : S) (x : T shape) :
is_cdifferentiable k (prod x) → is_cdifferentiable (λ x, k (prod x)) x
axiom is_cdifferentiable_square {shape : S} (k : T shape → ℝ) (x : T shape) :
is_cdifferentiable k (square x) → is_cdifferentiable (λ x, k (square x)) x
axiom is_cdifferentiable_gemm₁ {m p : ℕ} (k : T [m, p] → ℝ) (n : ℕ) (M : T [m, n]) (N : T [n, p]) :
is_cdifferentiable k (gemm M N) → is_cdifferentiable (λ M, k (gemm M N)) M
axiom is_cdifferentiable_gemm₂ {m p : ℕ} (k : T [m, p] → ℝ) (n : ℕ) (M : T [m, n]) (N : T [n, p]) :
is_cdifferentiable k (gemm M N) → is_cdifferentiable (λ N, k (gemm M N)) N
axiom is_cdifferentiable_add_fs {shape : S} (f₁ f₂ : T shape → ℝ) (θ : T shape):
(is_cdifferentiable f₁ θ ∧ is_cdifferentiable f₂ θ) ↔ is_cdifferentiable (λ θ₀, f₁ θ₀ + f₂ θ₀) θ
axiom is_cdifferentiable_scale_f {shape : S} (α : ℝ) (f : T shape → ℝ) (θ : T shape):
is_cdifferentiable f θ ↔ is_cdifferentiable (λ x, α ⬝ f x) θ
axiom is_cdifferentiable_fscale {shape : S} (f : T shape → ℝ) (y : ℝ) (θ : T shape):
is_cdifferentiable f θ ↔ is_cdifferentiable (λ x, f x ⬝ y) θ
-- Provable
axiom is_cdifferentiable_sumr {X : Type} {shape : S} (θ : T shape) (f : T shape → X → ℝ) :
Π (xs : list X),
(∀ (x : X), x ∈ xs → is_cdifferentiable (λ θ₀, f θ₀ x) θ) →
is_cdifferentiable (λ (θ₀ : T shape), sumr (map (f θ₀) xs)) θ
--
axiom grad_binary {shape : S} (k : T shape → T shape → ℝ) (θ : T shape) :
is_cdifferentiable (λ θ₀, k θ₀ θ) θ → is_cdifferentiable (λ θ₀, k θ θ₀) θ →
∇ (λ θ₀, k θ₀ θ₀) θ = ∇ (λ θ₀, k θ₀ θ) θ + ∇ (λ θ₀, k θ θ₀) θ
axiom grad_tmulT {ishape oshape : S} : ∀ (f : T ishape → T oshape) (k : T oshape → ℝ) (θ : T ishape),
∇ (λ θ₀, k (f θ₀)) θ = tmulT (D (λ θ₀, f θ₀) θ) (∇ k (f θ))
axiom grad_chain_rule : ∀ {shape₁ shape₂ : S} (f : T shape₁ → T shape₂) (g : T shape₂ → ℝ) (θ : T shape₁),
∇ (λ (θ₀ : T shape₁), g (f θ₀)) θ = tmulT (D f θ) (∇ g (f θ))
-- See Lang (Page 340, Theorem 3.4)
-- f continuously differentiable
-- f and grad_2 f both uniformly integrable
axiom grad_integral : ∀ {ishape tshape : S} (f : T ishape → T tshape → ℝ) (θ : T tshape),
(∀ x, is_cdifferentiable (f x) θ) →
is_uniformly_integrable_around (λ θ₀ x, f x θ₀) θ →
is_uniformly_integrable_around (λ θ₀ x, ∇ (λ θ₁, f x θ₁) θ₀) θ →
∇ (λ θ₀, ∫ (λ x, f x θ₀)) θ = ∫ (λ x, ∇ (λ θ₀, f x θ₀) θ)
lemma grad_congr {shape : S} {f g : T shape → ℝ} {x : T shape} (H : ∀ x, f x = g x) : ∇ f x = ∇ g x :=
begin change (∇ (λ x, f x) x = ∇ (λ x, g x) x), rw (funext H) end
axiom grad_const : ∀ {ishape : S} (θ : T ishape) (x : ℝ), ∇ (λ (θ₀ : T ishape), x) θ = 0
axiom grad_id : ∀ (θ : ℝ), ∇ (λ θ, θ) θ = 1
-- Unary
axiom grad_exp {shape : S} (k : T shape → ℝ) (θ : T shape) :
∇ (λ θ, k (exp θ)) θ = ∇ k (exp θ) * exp θ
axiom grad_log {shape : S} (k : T shape → ℝ) (θ : T shape) : θ > 0 →
∇ (λ θ, k (log θ)) θ = ∇ k (log θ) / θ
axiom grad_sqrt {shape : S} (k : T shape → ℝ) (θ : T shape) : θ > 0 →
∇ (λ θ, k (sqrt θ)) θ = ∇ k (sqrt θ) / (2 * sqrt θ)
axiom grad_scale {shape : S} (k : T shape → ℝ) (α : ℝ) (x : T shape) :
∇ (λ x, k (α ⬝ x)) x = α ⬝ ∇ k (α ⬝ x)
axiom grad_neg {shape : S} (k : T shape → ℝ) (θ : T shape) :
∇ (λ θ, k (- θ)) θ = - (∇ k (- θ))
-- Binary
axiom grad_add₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
∇ (λ x₁, k (x₁ + x₂)) x₁ = ∇ k (x₁ + x₂)
axiom grad_add₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
∇ (λ x₂, k (x₁ + x₂)) x₂ = ∇ k (x₁ + x₂)
axiom grad_sub₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
∇ (λ x₁, k (x₁ - x₂)) x₁ = ∇ k (x₁ - x₂)
axiom grad_sub₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
∇ (λ x₂, k (x₁ - x₂)) x₂ = - ∇ k (x₁ - x₂)
axiom grad_mul₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
∇ (λ x₁, k (x₁ * x₂)) x₁ = ∇ k (x₁ * x₂) * x₂
axiom grad_mul₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) :
∇ (λ x₂, k (x₁ * x₂)) x₂ = ∇ k (x₁ * x₂) * x₁
-- Note: can be proved from grad_binary and grad_mul*, but resulting theorem
-- would have `is_cdifferentiable k` as a pre-condition.
-- It is safe to avoid that here because of the symmetry of the function.
axiom grad_square {shape : S} (k : T shape → ℝ) (x : T shape) :
∇ (λ x, k (square x)) x = ∇ k (square x) * 2 * x
axiom grad_div₁ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) : square x₂ > 0 →
∇ (λ x₁, k (x₁ / x₂)) x₁ = ∇ k (x₁ / x₂) / x₂
axiom grad_div₂ {shape : S} (k : T shape → ℝ) (x₁ x₂ : T shape) : square x₂ > 0 →
∇ (λ x₂, k (x₁ / x₂)) x₂ = - (∇ k (x₁ / x₂) * x₁) / (square x₂)
-- Tensors
axiom grad_sum (k : ℝ → ℝ) (shape : S) (x : T shape) :
∇ (λ x, k (sum x)) x = ∇ k (sum x) ⬝ 1
axiom grad_dot₁ {shape : S} (x₁ x₂ : T shape) : ∇ (λ x₁, dot x₁ x₂) x₁ = x₂
axiom grad_dot₂ {shape : S} (x₁ x₂ : T shape) : ∇ (λ x₂, dot x₁ x₂) x₂ = x₁
axiom grad_gemm₁ {m p : ℕ} (k : T [m, p] → ℝ) (n : ℕ) (M : T [m, n]) (N : T [n, p]) :
∇ (λ M, k (gemm M N)) M = gemm (∇ k (gemm M N)) (transpose N)
axiom grad_gemm₂ {m p : ℕ} (k : T [m, p] → ℝ) (n : ℕ) (M : T [m, n]) (N : T [n, p]) :
∇ (λ N, k (gemm M N)) N = gemm (transpose M) (∇ k (gemm M N))
-- Congruences
axiom grad_congr_pos {shape : S} (f g : T shape → ℝ) (θ : T shape) :
θ > 0 → (∀ (θ₀ : T shape), θ₀ > 0 → f θ₀ = g θ₀) → ∇ f θ = ∇ g θ
-- Compound
lemma grad_softplus {shape : S} (k : T shape → ℝ) (θ : T shape) :
∇ (λ θ, k (softplus θ)) θ = ∇ k (softplus θ) / (1 + exp (- θ)) :=
have H : (exp θ) / (exp θ + 1) = 1 / (1 + exp (- θ)), from
calc (exp θ) / (exp θ + 1)
= ((exp θ) / (exp θ + 1)) * ((exp θ)⁻¹ / (exp θ)⁻¹) : by simp [T.div_self (inv_pos (@exp_pos _ θ))]
... = ((exp θ * (exp θ)⁻¹) / ((exp θ + 1) * (exp θ)⁻¹)) : by simp [T.div_mul_div]
... = (1 / ((exp θ + 1) * (exp θ)⁻¹)) : by simp only [T.mul_inv_cancel (@exp_pos _ θ)]
... = 1 / ((exp θ * (exp θ)⁻¹) + 1 * (exp θ)⁻¹) : by simp only [right_distrib]
... = 1 / (1 + exp (- θ)) : by { simp only [T.mul_inv_cancel (@exp_pos _ θ), one_mul], rw exp_inv},
calc ∇ (λ θ, k (softplus θ)) θ
= ∇ (λ θ, k (log (exp θ + 1))) θ : rfl
... = ∇ (λ θ, k (log (θ + 1))) (exp θ) * exp θ : by rw T.grad_exp (λ θ, k (log (θ + 1)))
... = ∇ (λ θ, k (log θ)) (exp θ + 1) * exp θ : by rw T.grad_add₁ (λ θ, k (log θ))
... = ∇ k (log (exp θ + 1)) / (exp θ + 1) * exp θ : by rw (T.grad_log k (exp θ + 1) (plus_one_pos exp_pos))
... = ∇ k (softplus θ) * (exp θ / (exp θ + 1)) : by { rw [-T.mul_div_mul], reflexivity }
... = ∇ k (softplus θ) * (1 / (1 + exp (- θ))) : by rw H
... = ∇ k (softplus θ) / (1 + exp (- θ)) : by simp [T.one_div_inv, T.div_mul_inv]
lemma grad_sigmoid {shape : S} (k : T shape → ℝ) (θ : T shape) :
∇ (λ θ, k (sigmoid θ)) θ = ∇ k (sigmoid θ) * sigmoid θ * (1 - sigmoid θ) :=
have H_pre : 1 + exp (- θ) > 0, from one_plus_pos exp_pos,
have H : exp (- θ) / (1 + exp (- θ)) = 1 - sigmoid θ, from
calc exp (- θ) / (1 + exp (- θ))
= ((1 + exp (- θ)) - 1) / (1 + exp (- θ)) : by simp [sub_add_eq_sub_sub]
... = ((1 + exp (- θ)) / (1 + exp (- θ))) - 1 / (1 + exp (- θ)) : by simp [T.div_sub_div_same]
... = 1 - sigmoid θ : by { rw T.div_self (one_plus_pos exp_pos), reflexivity },
calc ∇ (λ θ, k (sigmoid θ)) θ
= ∇ (λ θ, k (1 / (1 + exp (- θ)))) θ : rfl
... = - ∇ (λ θ, k (1 / (1 + exp θ))) (- θ) : by rw T.grad_neg (λ θ, k (1 / (1 + exp θ)))
... = - (∇ (λ θ, k (1 / (1 + θ))) (exp (- θ)) * exp (- θ)) : by rw T.grad_exp (λ θ, k (1 / (1 + θ)))
... = - (∇ (λ θ, k (1 / θ)) (1 + exp (- θ)) * exp (- θ)) : by rw T.grad_add₂ (λ θ, k (1 / θ))
... = -(-(∇ k (1 / (1 + exp (-θ))) * 1) / square (1 + exp (-θ)) * exp (-θ)) : by rw (T.grad_div₂ k 1 (1 + exp (- θ)) (square_pos_of_pos $ one_plus_pos exp_pos))
... = (∇ k (1 / (1 + exp (-θ)))) / square (1 + exp (-θ)) * exp (-θ) : begin rw T.neg_div, simp [mul_neg_eq_neg_mul_symm] end
... = (∇ k (sigmoid θ)) / square (1 + exp (-θ)) * exp (-θ) : rfl
... = (∇ k (sigmoid θ)) * (1 / (1 + exp (-θ))) * (exp (-θ) / (1 + exp (- θ))) : by simp [square, T.div_mul_inv, T.mul_inv_pos H_pre H_pre]
... = (∇ k (sigmoid θ)) * sigmoid θ * (exp (-θ) / (1 + exp (- θ))) : rfl
... = ∇ k (sigmoid θ) * sigmoid θ * (1 - sigmoid θ) : by rw H
-- Gradients wrt arbitrary functions
lemma grad_add_fs {ishape : S} (θ : T ishape) (f₁ f₂ : T ishape → ℝ) :
is_cdifferentiable f₁ θ → is_cdifferentiable f₂ θ →
∇ (λ θ₀, f₁ θ₀ + f₂ θ₀) θ = ∇ (λ θ₀, f₁ θ₀) θ + ∇ (λ θ₀, f₂ θ₀) θ :=
assume H_f₁ H_f₂,
have H₁ : is_cdifferentiable (λ θ₀, f₁ θ₀ + f₂ θ) θ,
begin apply iff.mp (is_cdifferentiable_add_fs _ _ _), split, exact H_f₁, apply is_cdifferentiable_const end,
have H₂ : is_cdifferentiable (λ θ₀, f₁ θ + f₂ θ₀) θ,
begin apply iff.mp (is_cdifferentiable_add_fs _ _ _), split, apply is_cdifferentiable_const, exact H_f₂ end,
begin
rw grad_binary (λ θ₁ θ₂, f₁ θ₁ + f₂ θ₂) _ H₁ H₂,
rw [grad_chain_rule _ (λ θ₀, θ₀ + f₂ θ) θ, grad_chain_rule _ (λ θ₀, f₁ θ + θ₀) θ],
rw [tmulT_scalar, D_scalar, tmulT_scalar, D_scalar],
rw [grad_add₁ (λ θ, θ), grad_id, one_smul],
rw [grad_add₂ (λ θ, θ), grad_id, one_smul]
end
lemma grad_scale_f {ishape : S} (θ : T ishape) (α : ℝ) (f : T ishape → ℝ) :
∇ (λ θ₀, α ⬝ f θ₀) θ = α ⬝ ∇ (λ θ₀, f θ₀) θ :=
begin
rw grad_chain_rule f (λ θ, α ⬝ θ) θ,
rw grad_scale (λ θ, θ),
rw grad_id,
rw smul.def,
rw mul_one,
rw tmulT_scalar,
rw D_scalar,
dunfold smul has_smul.smul scalar_mul,
rw const_scalar
end
lemma grad_log_f {shape : S} (θ : T shape) (f : T shape → ℝ) : f θ > 0 → ∇ (λ θ₀, log (f θ₀)) θ = (f θ)⁻¹ ⬝ ∇ f θ :=
assume H_pos,
have H_grad_log_simple : Π {θ : ℝ}, θ > 0 → ∇ log θ = θ⁻¹, from
begin
intros θ H_pos,
rw grad_log (λ θ, θ) _ H_pos,
rw grad_id,
apply T.one_div_inv
end,
by rw [grad_chain_rule, tmulT_scalar, D_scalar, H_grad_log_simple H_pos]
section simplify_grad
open list expr tactic
lemma id_rule {A : Type*} (a : A) : id a = a := rfl
meta def reduce_k (k : expr) : tactic expr :=
do slss ← simp_lemmas.add_simp simp_lemmas.mk `certigrad.T.id_rule,
slss^.dsimplify k <|> return k
meta def has_x (x e : expr) : bool := expr.fold e ff (λ (m : expr) (d : nat) (b : bool), if m = x then tt else b)
meta def compute_outer_inner_functions_core (x : expr) : Π (k e : expr), tactic expr :=
λ (k e : expr),
do let f := get_app_fn e,
let args := get_app_args e,
let n := length args,
let barg₁ := dnth args (n-2),
let barg₂ := dnth args (n-1),
barg₁_type ← infer_type barg₁,
barg₂_type ← infer_type barg₂,
if barg₁ = x ∨ barg₂ = x
then return k
else if has_x x barg₁
then compute_outer_inner_functions_core (lam `x binder_info.default barg₁_type (app k $ mk_app f $ update_nth args (n-2) (var 0))) barg₁
else if has_x x barg₂
then compute_outer_inner_functions_core (lam `x binder_info.default barg₂_type (app k $ mk_app f $ update_nth args (n-1) (var 0))) barg₂
else tactic.fail "no var0"
meta def compute_outer_inner_functions (grad : expr) : tactic expr :=
let g := app_arg (app_fn grad) in
do f ← head_eta_expand g,
x ← mk_local_def `x (binding_domain f),
body ← return (instantiate_var (binding_body f) x),
body_type ← infer_type body,
initial_k ← return (lam `x binder_info.default body_type (var 0)),
compute_outer_inner_functions_core x initial_k body <|> return initial_k
meta def compute_k (grad : expr) : tactic expr :=
do k ← compute_outer_inner_functions grad,
k_simp ← reduce_k k,
head_eta_expand k_simp
meta def check_grad (e : expr) : tactic expr :=
if is_napp_of e `certigrad.T.grad 3 then head_eta_expand e else tactic.fail "not ∇"
meta def try_add_simp (s : simp_lemmas) (p : pexpr) : tactic simp_lemmas :=
do oe ← try_core $ to_expr p,
match oe with
| none := return s
| (some e) := simp_lemmas.add s e
end
meta def build_simplify_grad_simp_lemmas (k : expr) : tactic simp_lemmas :=
do es ← monad.mapm to_expr
[``(@certigrad.T.grad_const)
, ``(@certigrad.T.grad_id)
, ``(certigrad.T.grad_exp %%k)
, ``(certigrad.T.grad_log %%k)
, ``(certigrad.T.grad_scale %%k)
, ``(certigrad.T.grad_neg %%k)
, ``(certigrad.T.grad_add₁ %%k)
, ``(certigrad.T.grad_add₂ %%k)
, ``(certigrad.T.grad_sub₁ %%k)
, ``(certigrad.T.grad_sub₂ %%k)
, ``(certigrad.T.grad_mul₁ %%k)
, ``(certigrad.T.grad_mul₂ %%k)
, ``(certigrad.T.grad_div₁ %%k)
, ``(certigrad.T.grad_div₂ %%k)
, ``(@certigrad.T.grad_dot₁)
, ``(@certigrad.T.grad_dot₂)
, ``(certigrad.T.grad_square %%k)
, ``(certigrad.T.grad_sqrt %%k)
, ``(certigrad.T.grad_softplus %%k)
, ``(certigrad.T.grad_sigmoid %%k)
],
s ← simp_lemmas.append simp_lemmas.mk es,
-- These have shape requirements that may cause `to_expr` to fail
s ← try_add_simp s ``(certigrad.T.grad_gemm₁ %%k),
s ← try_add_simp s ``(certigrad.T.grad_gemm₂ %%k),
s ← try_add_simp s ``(certigrad.T.grad_sum %%k),
-- These haven't been defined yet
s ← try_add_simp s ```(certigrad.T.grad_mvn_iso_kl₁ %%k),
s ← try_add_simp s ```(certigrad.T.grad_mvn_iso_kl₂ %%k),
s ← try_add_simp s ```(certigrad.T.grad_bernoulli_neglogpdf₁ %%k),
s ← try_add_simp s ```(certigrad.T.grad_bernoulli_neglogpdf₂ %%k),
s ← try_add_simp s ``(@certigrad.T.grad_scale_f),
return s
meta def simplify_grad_core_helper (tac : tactic unit) : conv unit :=
λ r e, do guard $ r = `eq,
grad ← check_grad e,
k ← compute_k grad,
s ← build_simplify_grad_simp_lemmas k,
conv.apply_lemmas_core reducible s tac r e
meta def simplify_grad_core (tac : tactic unit) : tactic unit :=
at_target (λ e, do (a, new_e, pf) ← ext_simplify_core () {zeta := ff, beta := ff, eta := ff, proj := ff} simp_lemmas.mk
(λ u, failed)
(λ a s r p e, failed)
(λ a s r p e, do ⟨u, new_e, pr⟩ ← simplify_grad_core_helper tac r e,
return ((), new_e, pr, tt))
`eq e,
return (new_e, pf))
meta def check_is_cdifferentiable (e : expr) : tactic expr :=
if is_napp_of e `certigrad.T.is_cdifferentiable 3 then head_eta_expand e else tactic.fail "not is_cdifferentiable"
meta def prove_differentiable_core_helper (grad : expr) : tactic unit :=
do k ← compute_k grad,
first [applyc `certigrad.T.is_cdifferentiable_const
, applyc `certigrad.T.is_cdifferentiable_id
-- these haven't been defined yet
, to_expr ```(T.is_cdifferentiable_sigmoid %%k) >>= apply
, to_expr ```(T.is_cdifferentiable_softplus %%k) >>= apply
, to_expr ```(T.is_cdifferentiable_mvn_iso_kl₁ %%k) >>= apply
, to_expr ```(T.is_cdifferentiable_mvn_iso_kl₂ %%k) >>= apply
, to_expr ```(T.is_cdifferentiable_bernoulli_neglogpdf₁ %%k) >>= apply
, to_expr ```(T.is_cdifferentiable_bernoulli_neglogpdf₂ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_exp %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_log %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_sqrt %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_scale %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_neg %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_inv %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_add₁ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_add₂ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_sub₁ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_sub₂ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_mul₁ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_mul₂ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_div₁ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_div₂ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_square %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_sum %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_prod %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_gemm₁ %%k) >>= apply
, to_expr ``(T.is_cdifferentiable_gemm₂ %%k) >>= apply
]
meta def prove_differentiable_core : tactic unit := target >>= check_is_cdifferentiable >>= prove_differentiable_core_helper
meta def prove_differentiable : tactic unit := repeat (prove_differentiable_core <|> prove_preconditions_core)
meta def simplify_grad : tactic unit := simplify_grad_core (repeat $ prove_preconditions_core <|> prove_differentiable_core)
end simplify_grad
-- Compounds with simplify_grad
lemma grad_mvn_iso_kl₁ (k : ℝ → ℝ) (shape : S) (μ σ : T shape) : ∇ (λ μ, k (mvn_iso_kl μ σ)) μ = ∇ k (mvn_iso_kl μ σ) ⬝ μ :=
begin
dunfold T.mvn_iso_kl,
simplify_grad,
simp [T.smul.def, T.const_neg, T.const_mul, T.const_zero, T.const_one, T.const_bit0, T.const_bit1, T.const_inv],
rw [-(mul_assoc (2 : T shape) 2⁻¹), T.mul_inv_cancel two_pos],
simp
end
lemma grad_mvn_iso_kl₂ (k : ℝ → ℝ) (shape : S) (μ σ : T shape) (H_σ : σ > 0) (H_k : is_cdifferentiable k (mvn_iso_kl μ σ)) :
∇ (λ σ, k (mvn_iso_kl μ σ)) σ = ∇ k (mvn_iso_kl μ σ) ⬝ (σ - (1 / σ)) :=
have H_σ₂ : square σ > 0, from square_pos_of_pos H_σ,
have H_diff₁ : is_cdifferentiable (λ (θ₀ : T shape), k (-2⁻¹ * T.sum (1 + T.log (square θ₀) - square μ - square σ))) σ, by prove_differentiable,
have H_diff₂ : is_cdifferentiable (λ (θ₀ : T shape), k (-2⁻¹ * T.sum (1 + T.log (square σ) - square μ - square θ₀))) σ, by prove_differentiable,
begin
dunfold T.mvn_iso_kl,
rw (T.grad_binary (λ θ₁ θ₂, k ((- 2⁻¹) * T.sum (1 + T.log (square θ₁) - square μ - square θ₂))) _ H_diff₁ H_diff₂),
dsimp,
simplify_grad,
simp [T.smul.def, T.const_neg, T.const_mul, T.const_zero,
T.const_one, T.const_bit0, T.const_bit1, T.const_inv,
left_distrib, right_distrib],
rw [-(mul_assoc (2 : T shape) 2⁻¹), T.mul_inv_cancel two_pos],
erw T.neg_div,
simp [mul_neg_eq_neg_mul_symm, neg_mul_eq_neg_mul_symm],
apply congr_arg, apply congr_arg,
simp only [T.mul_div_mul, square],
rw [-mul_assoc, T.mul_div_mul, (@T.div_self_square _ σ H_σ)],
simp,
rw [-(mul_assoc (2 : T shape) 2⁻¹), T.mul_inv_cancel two_pos],
simp,
rw T.div_mul_inv,
simp
end
lemma grad_bernoulli_neglogpdf₁ (k : ℝ → ℝ) (shape : S) (p z : T shape)
(H_p₁ : 0 < p) (H_p₂ : 0 < 1 - p) (H_k : is_cdifferentiable k (bernoulli_neglogpdf p z)) :
∇ (λ p, k (bernoulli_neglogpdf p z)) p = ∇ k (bernoulli_neglogpdf p z) ⬝ ((1 - z) / (1 - p) - z / p) :=
have H_diff₁ : is_cdifferentiable (λ (θ₀ : T shape), k (-T.sum (z * T.log θ₀ + (1 - z) * T.log (1 - p)))) p, by prove_differentiable,
have H_diff₂ : is_cdifferentiable (λ (θ₀ : T shape), k (-T.sum (z * T.log p + (1 - z) * T.log (1 - θ₀)))) p, by prove_differentiable,
begin
dunfold T.bernoulli_neglogpdf,
rw T.grad_binary (λ θ₁ θ₂, k ( - T.sum (z * T.log θ₁ + (1 - z) * T.log (1 - θ₂)))) _ H_diff₁ H_diff₂,
dsimp,
simplify_grad,
simp [T.smul.def, const_neg, T.neg_div, T.div_mul_inv, left_distrib, right_distrib],
end
lemma grad_bernoulli_neglogpdf₂ (k : ℝ → ℝ) (shape : S) (p z : T shape)
(H_p₁ : 0 < p) (H_p₂ : 0 < 1 - p) (H_k : is_cdifferentiable k (bernoulli_neglogpdf p z)) :
∇ (λ z, k (bernoulli_neglogpdf p z)) z = ∇ k (bernoulli_neglogpdf p z) ⬝ (log (1 - p) - log p) :=
have H_diff₁ : is_cdifferentiable (λ (θ₀ : T shape), k (-T.sum (θ₀ * T.log p + (1 - z) * T.log (1 - p)))) z, by prove_differentiable,
have H_diff₂ : is_cdifferentiable (λ (θ₀ : T shape), k (-T.sum (z * T.log p + (1 - θ₀) * T.log (1 - p)))) z, by prove_differentiable,
begin
dunfold T.bernoulli_neglogpdf,
rw T.grad_binary (λ θ₁ θ₂, k (- T.sum (θ₁ * T.log p + (1 - θ₂) * T.log (1 - p)))) _ H_diff₁ H_diff₂,
dsimp,
simplify_grad,
simp [T.smul.def, const_neg, left_distrib, right_distrib],
end
-- Compounds with prove_differentiable
lemma is_cdifferentiable_sigmoid {shape : S} (k : T shape → ℝ) (θ : T shape) :
is_cdifferentiable k (sigmoid θ) → is_cdifferentiable (λ θ, k (sigmoid θ)) θ :=
begin intro H, dunfold sigmoid, prove_differentiable end
lemma is_cdifferentiable_softplus {shape : S} (k : T shape → ℝ) (θ : T shape) :
is_cdifferentiable k (softplus θ) → is_cdifferentiable (λ θ, k (softplus θ)) θ :=
begin intro H, dunfold softplus, prove_differentiable end
lemma is_cdifferentiable_mvn_iso_kl₁ (k : ℝ → ℝ) (shape : S) (μ σ : T shape) :
is_cdifferentiable k (mvn_iso_kl μ σ) → is_cdifferentiable (λ μ, k (mvn_iso_kl μ σ)) μ :=
begin intro H, dunfold mvn_iso_kl, prove_differentiable end
lemma is_cdifferentiable_mvn_iso_kl₂ (k : ℝ → ℝ) (shape : S) (μ σ : T shape) (H_σ : σ > 0) :
is_cdifferentiable k (mvn_iso_kl μ σ) → is_cdifferentiable (λ σ, k (mvn_iso_kl μ σ)) σ :=
begin
intro H, dunfold mvn_iso_kl,
apply is_cdifferentiable_binary (λ θ₁ θ₂, k (-2⁻¹ * T.sum (1 + T.log (square θ₁) + -square μ + -square θ₂))),
{ dsimp, prove_differentiable },
{ dsimp, prove_differentiable }
end
lemma is_cdifferentiable_bernoulli_neglogpdf₁ (k : ℝ → ℝ) (shape : S) (p z : T shape) (H_p₁ : p > 0) (H_p₂ : p < 1) :
is_cdifferentiable k (bernoulli_neglogpdf p z) → is_cdifferentiable (λ p, k (bernoulli_neglogpdf p z)) p :=
begin
intro H, dunfold bernoulli_neglogpdf,
apply is_cdifferentiable_binary (λ θ₁ θ₂, k (-T.sum (z * T.log θ₁ + (1 + -z) * T.log (1 + -θ₂)))),
{ dsimp, prove_differentiable },
{ dsimp, prove_differentiable }
end
lemma is_cdifferentiable_bernoulli_neglogpdf₂ (k : ℝ → ℝ) (shape : S) (p z : T shape) :
is_cdifferentiable k (bernoulli_neglogpdf p z) → is_cdifferentiable (λ z, k (bernoulli_neglogpdf p z)) z :=
begin
intro H, dunfold bernoulli_neglogpdf,
apply is_cdifferentiable_binary (λ θ₁ θ₂, k (-T.sum (θ₁ * T.log p + (1 + -θ₂) * T.log (1 + -p)))),
{ dsimp, prove_differentiable },
{ dsimp, prove_differentiable }
end
-- Random
lemma mvn_iso_grad_logpdf_μ_correct {shape : S} (μ σ x : T shape) (H_σ : σ > 0) :
∇ (λ θ, mvn_iso_logpdf θ σ x) μ = mvn_iso_grad_logpdf_μ μ σ x :=
begin
dunfold mvn_iso_logpdf,
note H := square_pos_of_pos H_σ,
simplify_grad,
simp [smul.def, const_bit0, const_one, const_neg, const_inv, T.neg_div],
rw -mul_assoc, rw T.mul_inv_cancel two_pos,
simp, rw T.div_div_eq_div_mul,
reflexivity
end
lemma mvn_iso_grad_logpdf_σ_correct {shape : S} (μ σ x : T shape) (H_σ : σ > 0) :
∇ (λ θ, mvn_iso_logpdf μ θ x) σ = mvn_iso_grad_logpdf_σ μ σ x :=
have H_σ₂ : square σ > 0, from square_pos_of_pos H_σ,
have H_d₁ : is_cdifferentiable (λ θ₀, -2⁻¹ * sum (square ((x - μ) / θ₀) + log (2 * pi shape) + log (square σ))) σ, by prove_differentiable,
have H_d₂ : is_cdifferentiable (λ θ₀, -2⁻¹ * sum (square ((x - μ) / σ) + log (2 * pi shape) + log (square θ₀))) σ, by prove_differentiable,
have H₁ : (2 * (2⁻¹ / square σ)) = σ⁻¹ * σ⁻¹,
begin dunfold square, rw [T.mul_div_mul_alt, T.mul_inv_cancel two_pos, one_div_inv, T.mul_inv_pos H_σ H_σ] end,
have H₂ : 2 * ((x + -μ) * ((x + -μ) * 2⁻¹)) = (2 * 2⁻¹) * square (x - μ), by simp [square],
begin
dunfold mvn_iso_logpdf,
rw grad_binary (λ θ₁ θ₂, -2⁻¹ * sum (square ((x - μ) / θ₁) + log (2 * pi shape) + log (square θ₂))) _ H_d₁ H_d₂, dsimp,
simplify_grad,
simp [smul.def, const_bit0, const_one, const_neg, const_inv, T.neg_div, T.div_div_eq_div_mul],
rw H₁,
rw -mul_assoc, rw T.mul_inv_cancel H_σ,
simp [T.mul_div_mul_alt, T.div_div_eq_div_mul],
rw [H₂, T.mul_inv_cancel two_pos],
simp [mvn_iso_grad_logpdf_σ]
end
-- With data structures
lemma grad_sumr {X : Type} {shape : S} (θ : T shape) (f : T shape → X → ℝ) :
Π (xs : list X),
is_cdifferentiable (λ (θ₀ : T shape), sumr (map (f θ₀) xs)) θ →
∇ (λ (θ₀ : T shape), list.sumr (map (f θ₀) xs)) θ
=
list.sumr (map (λ x, ∇ (λ θ₀, f θ₀ x) θ) xs)
| [] H_diff := by { dunfold map sumr, rw grad_const }
| (x::xs) H_diff :=
begin
dunfold map sumr,
dunfold map sumr at H_diff,
rw grad_add_fs _ _ _ (iff.mpr (is_cdifferentiable_add_fs _ _ _) H_diff)^.left (iff.mpr (is_cdifferentiable_add_fs _ _ _) H_diff)^.right,
rw grad_sumr _ (iff.mpr (is_cdifferentiable_add_fs _ _ _) H_diff)^.right
end
-- Note: this could be proved from a `select`/`replicate` formulation,
-- but it is arguably a more natural way of axiomatizing the property anyway.
axiom multiple_args_general :
∀ (parents : list reference) (tgt : reference) (m : env)
(f : dvec T parents^.p2 → T tgt.2 → ℝ) (θ : T tgt.2),
is_cdifferentiable (λ θ₀, f (env.get_ks parents (env.insert tgt θ m)) θ₀) θ →
is_cdifferentiable (λ θ₀, sumr (map (λ (idx : ℕ), f (dvec.update_at θ₀ (env.get_ks parents (env.insert tgt θ m)) idx) θ)
(filter (λ idx, tgt = dnth parents idx) (riota $ length parents)))) θ →
∇ (λ (θ₀ : T tgt.2), f (env.get_ks parents (env.insert tgt θ₀ m)) θ₀) θ
=
∇ (λ θ₀, f (env.get_ks parents (env.insert tgt θ m)) θ₀) θ +
sumr (map (λ (idx : ℕ),
∇ (λ θ₀, f (dvec.update_at θ₀ (env.get_ks parents (env.insert tgt θ m)) idx) θ) θ)
(filter (λ idx, tgt = dnth parents idx) (riota $ length parents)))
end T
end certigrad
|
5c251957de4c39a9e8d3147290f0770244dd786d
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/1724.lean
|
19f5777a8aca44fb2b14523bfaaf32a489f21671
|
[
"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
| 190
|
lean
|
example (h : ¬ true) : false :=
by simp * at *
example (h : true) (h' : true → false) : false :=
by simp * at *
example (p : Prop) (h : p) (h' : p → false) : false :=
by simp * at *
|
92deb999d6a8bcbfac8f725af72a368f46d16479
|
08bd4ba4ca87dba1f09d2c96a26f5d65da81f4b4
|
/src/Lean/Compiler/LCNF/Simp/Main.lean
|
8c23a7dcde928c1adb3a26349dfc9c8c8b845117
|
[
"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",
"Apache-2.0",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
gebner/lean4
|
d51c4922640a52a6f7426536ea669ef18a1d9af5
|
8cd9ce06843c9d42d6d6dc43d3e81e3b49dfc20f
|
refs/heads/master
| 1,685,732,780,391
| 1,672,962,627,000
| 1,673,459,398,000
| 373,307,283
| 0
| 0
|
Apache-2.0
| 1,691,316,730,000
| 1,622,669,271,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 12,437
|
lean
|
/-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.ImplementedByAttr
import Lean.Compiler.LCNF.ElimDead
import Lean.Compiler.LCNF.AlphaEqv
import Lean.Compiler.LCNF.PrettyPrinter
import Lean.Compiler.LCNF.Bind
import Lean.Compiler.LCNF.Simp.FunDeclInfo
import Lean.Compiler.LCNF.Simp.InlineCandidate
import Lean.Compiler.LCNF.Simp.InlineProj
import Lean.Compiler.LCNF.Simp.Used
import Lean.Compiler.LCNF.Simp.DefaultAlt
import Lean.Compiler.LCNF.Simp.SimpValue
import Lean.Compiler.LCNF.Simp.ConstantFold
namespace Lean.Compiler.LCNF
namespace Simp
/--
Return `true` if `c` has only one exit point.
This is a quick approximation. It does not check cases
such as: a `cases` with many but only one alternative is not reachable.
It is only used to avoid the creation of auxiliary join points, and does not need
to be precise.
-/
private partial def oneExitPointQuick (c : Code) : Bool :=
go c
where
go (c : Code) : Bool :=
match c with
| .let _ k | .fun _ k => go k
-- Approximation, the cases may have many unreachable alternatives, and only reachable.
| .cases c => c.alts.size == 1 && go c.alts[0]!.getCode
-- Approximation, we assume that any code containing join points have more than one exit point
| .jp .. | .jmp .. | .unreach .. => false
| .return .. => true
/--
Create a new local function declaration when `info.args.size < info.params.size`.
We use this function to inline/specialize a partial application of a local function.
-/
def specializePartialApp (info : InlineCandidateInfo) : SimpM FunDecl := do
let mut subst := {}
for param in info.params, arg in info.args do
subst := subst.insert param.fvarId arg.toExpr
let mut paramsNew := #[]
for param in info.params[info.args.size:] do
let type ← replaceExprFVars param.type subst (translator := true)
let paramNew ← mkAuxParam type
paramsNew := paramsNew.push paramNew
subst := subst.insert param.fvarId (.fvar paramNew.fvarId)
let code ← info.value.internalize subst
updateFunDeclInfo code
mkAuxFunDecl paramsNew code
/--
Try to inline a join point.
-/
partial def inlineJp? (fvarId : FVarId) (args : Array Arg) : SimpM (Option Code) := do
/- Remark: we don't need to use `findFunDecl'?` here. -/
let some decl ← findFunDecl? fvarId | return none
unless (← shouldInlineLocal decl) do return none
markSimplified
betaReduce decl.params decl.value args
/--
When the configuration flag `etaPoly = true`, we eta-expand
partial applications of functions that take local instances as arguments.
This kind of function is inlined or specialized, and we create new
simplification opportunities by eta-expanding them.
-/
def etaPolyApp? (letDecl : LetDecl) : OptionT SimpM FunDecl := do
guard <| (← read).config.etaPoly
let .const declName us args := letDecl.value | failure
let some info := (← getEnv).find? declName | failure
guard <| hasLocalInst info.type
guard <| !(← Meta.isInstance declName)
let some decl ← getDecl? declName | failure
guard <| decl.getArity > args.size
let params ← mkNewParams letDecl.type
let auxDecl ← mkAuxLetDecl (.const declName us (args ++ params.map (.fvar ·.fvarId)))
let funDecl ← mkAuxFunDecl params (.let auxDecl (.return auxDecl.fvarId))
addFVarSubst letDecl.fvarId funDecl.fvarId
eraseLetDecl letDecl
return funDecl
/--
Similar to `Code.isReturnOf`, but taking the current substitution into account.
-/
def isReturnOf (c : Code) (fvarId : FVarId) : SimpM Bool := do
match c with
| .return fvarId' => match (← normFVar fvarId') with
| .fvar fvarId'' => return fvarId'' == fvarId
| .erased => return false
| _ => return false
def elimVar? (value : LetValue) : SimpM (Option FVarId) := do
let .fvar fvarId #[] := value | return none
return fvarId
mutual
/--
If the value of the given let-declaration is an application that can be inlined,
inline it and simplify the result.
`k` is the "continuation" for the let declaration, if the application is inlined,
it will also be simplified.
Note: `inlineApp?` did not use to be in this mutually recursive declaration.
It used to be invoked by `simp`, and would return `Option Code` that would be
then simplified by `simp`. However, this simpler architecture produced an
exponential blowup in when processing functions such as `Lean.Elab.Deriving.Ord.mkMatch.mkAlts`.
The key problem is that when inlining a declaration we often can reduce the number
of exit points by simplified the inlined code, and then connecting the result to the
continuation `k`. However, this optimization is only possible if we simplify the
inlined code **before** we attach it to the continuation.
-/
partial def inlineApp? (letDecl : LetDecl) (k : Code) : SimpM (Option Code) := do
let some info ← inlineCandidate? letDecl.value | return none
let numArgs := info.args.size
withInlining letDecl.value info.recursive do
let fvarId := letDecl.fvarId
if numArgs < info.arity then
let funDecl ← specializePartialApp info
addFVarSubst fvarId funDecl.fvarId
markSimplified
simp (.fun funDecl k)
else
let code ← betaReduce info.params info.value info.args[:info.arity]
if k.isReturnOf fvarId && numArgs == info.arity then
/- Easy case, the continuation `k` is just returning the result of the application. -/
markSimplified
simp code
else
let code ← simp code
let simpK (result : FVarId) : SimpM Code := do
/- `result` contains the result of the inlined code -/
if numArgs > info.arity then
let decl ← mkAuxLetDecl (.fvar result info.args[info.arity:])
addFVarSubst fvarId decl.fvarId
simp (.let decl k)
else
addFVarSubst fvarId result
simp k
if oneExitPointQuick code then
-- TODO: if `k` is small, we should also inline it here
markSimplified
code.bind fun fvarId' => do
markUsedFVar fvarId'
simpK fvarId'
-- else if info.ifReduce then
-- eraseCode code
-- return none
else
markSimplified
let expectedType ← inferAppType info.fType info.args[:info.arity]
if expectedType.headBeta.isForall then
/-
If `code` returns a function, we create an auxiliary local function declaration (and eta-expand it)
instead of creating a joinpoint that takes a closure as an argument.
-/
let auxFunDecl ← mkAuxFunDecl #[] code
let auxFunDecl ← auxFunDecl.etaExpand
let k ← simpK auxFunDecl.fvarId
attachCodeDecls #[.fun auxFunDecl] k
else
let jpParam ← mkAuxParam expectedType
let jpValue ← simpK jpParam.fvarId
let jpDecl ← mkAuxJpDecl #[jpParam] jpValue
let code ← code.bind fun fvarId => return .jmp jpDecl.fvarId #[.fvar fvarId]
return Code.jp jpDecl code
/--
Simplify the given local function declaration.
-/
partial def simpFunDecl (decl : FunDecl) : SimpM FunDecl := do
let type ← normExpr decl.type
let params ← normParams decl.params
let value ← simp decl.value
decl.update type params value
/--
Try to simplify `cases` of `constructor`
-/
partial def simpCasesOnCtor? (cases : Cases) : SimpM (Option Code) := do
match (← normFVar cases.discr) with
| .erased => mkReturnErased
| .fvar discr =>
let some ctorInfo ← findCtor? discr | return none
let (alt, cases) := cases.extractAlt! ctorInfo.getName
eraseCode (.cases cases)
markSimplified
match alt with
| .default k => simp k
| .alt _ params k =>
match ctorInfo with
| .ctor ctorVal ctorArgs =>
let fields := ctorArgs[ctorVal.numParams:]
for param in params, field in fields do
addSubst param.fvarId field.toExpr
let k ← simp k
eraseParams params
return k
| .natVal 0 => simp k
| .natVal (n+1) =>
let auxDecl ← mkAuxLetDecl (.value (.natVal n))
addFVarSubst params[0]!.fvarId auxDecl.fvarId
let k ← simp k
eraseParams params
return some <| .let auxDecl k
/--
Simplify `code`
-/
partial def simp (code : Code) : SimpM Code := withIncRecDepth do
incVisited
match code with
| .let decl k =>
let mut decl ← normLetDecl decl
if let some value ← simpValue? decl.value then
markSimplified
decl ← decl.updateValue value
if let some decls ← ConstantFold.foldConstants decl then
markSimplified
let k ← simp k
attachCodeDecls decls k
else if let some funDecl ← etaPolyApp? decl then
simp (.fun funDecl k)
else if let some fvarId ← elimVar? decl.value then
/- Eliminate `let _x_i := _x_j;` -/
addFVarSubst decl.fvarId fvarId
eraseLetDecl decl
simp k
else if let some code ← inlineApp? decl k then
eraseLetDecl decl
return code
else if let some (decls, fvarId) ← inlineProjInst? decl.value then
addFVarSubst decl.fvarId fvarId
eraseLetDecl decl
let k ← simp k
attachCodeDecls decls k
else
let k ← simp k
if (← isUsed decl.fvarId) then
markUsedLetDecl decl
return code.updateLet! decl k
else
/- Dead variable elimination -/
eraseLetDecl decl
return k
| .fun decl k | .jp decl k =>
let mut decl := decl
let toBeInlined ← isOnceOrMustInline decl.fvarId
if toBeInlined then
/-
If the declaration will be inlined, it is wasteful to eagerly simplify it.
So, we just normalize it (i.e., apply the substitution to it).
-/
decl ← normFunDecl decl
else
/-
Note that functions in `decl` will be marked as used even if `decl` is not actually used.
They will only be deleted in the next pass. TODO: investigate whether this is a problem.
-/
if code.isFun then
if decl.isEtaExpandCandidate then
/- We must apply substitution before trying to eta-expand, otherwise `inferType` may fail. -/
decl ← normFunDecl decl
/-
We want to eta-expand **before** trying to simplify local function declaration because
eta-expansion creates many optimization opportunities.
-/
decl ← decl.etaExpand
markSimplified
decl ← simpFunDecl decl
let k ← simp k
if (← isUsed decl.fvarId) then
if toBeInlined then
/-
`decl` was supposed to be inlined, but there are still references to it.
Thus, we must all variables in `decl` as used. Recall it was not eagerly simplified.
-/
markUsedFunDecl decl
return code.updateFun! decl k
else
/- Dead function elimination -/
eraseFunDecl decl
return k
| .return fvarId =>
withNormFVarResult (← normFVar fvarId) fun fvarId => do
markUsedFVar fvarId
return code.updateReturn! fvarId
| .unreach type =>
return code.updateUnreach! (← normExpr type)
| .jmp fvarId args =>
withNormFVarResult (← normFVar fvarId) fun fvarId => do
let args ← normArgs args
if let some code ← inlineJp? fvarId args then
simp code
else
markUsedFVar fvarId
args.forM markUsedArg
return code.updateJmp! fvarId args
| .cases c =>
if let some k ← simpCasesOnCtor? c then
return k
else
withNormFVarResult (← normFVar c.discr) fun discr => do
let resultType ← normExpr c.resultType
markUsedFVar discr
let alts ← c.alts.mapMonoM fun alt => do
match alt with
| .alt ctorName ps k =>
if !(k matches .unreach ..) && (← ps.anyM fun p => isInductiveWithNoCtors p.type) then
let type ← k.inferType
eraseCode k
markSimplified
return alt.updateCode (.unreach type)
else
withDiscrCtor discr ctorName ps do
return alt.updateCode (← simp k)
| .default k => return alt.updateCode (← simp k)
let alts ← addDefaultAlt alts
if alts.size == 1 && alts[0]! matches .default .. then
return alts[0]!.getCode
else
return code.updateCases! resultType discr alts
end
|
345b6ce8d08c00db042f7d30adf90818c1d6e952
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/multiset/nodup.lean
|
b144be5a3ed90189a0558cd466b75c4eb8c64be0
|
[
"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
| 9,658
|
lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.multiset.bind
import data.multiset.powerset
import data.multiset.range
/-!
# The `nodup` predicate for multisets without duplicate elements.
-/
namespace multiset
open function list
variables {α β γ : Type*} {r : α → α → Prop} {s t : multiset α} {a : α}
/- nodup -/
/-- `nodup s` means that `s` has no duplicates, i.e. the multiplicity of
any element is at most 1. -/
def nodup (s : multiset α) : Prop :=
quot.lift_on s nodup (λ s t p, propext p.nodup_iff)
@[simp] theorem coe_nodup {l : list α} : @nodup α l ↔ l.nodup := iff.rfl
@[simp] theorem nodup_zero : @nodup α 0 := pairwise.nil
@[simp] theorem nodup_cons {a : α} {s : multiset α} : nodup (a ::ₘ s) ↔ a ∉ s ∧ nodup s :=
quot.induction_on s $ λ l, nodup_cons
lemma nodup.cons (m : a ∉ s) (n : nodup s) : nodup (a ::ₘ s) := nodup_cons.2 ⟨m, n⟩
theorem nodup_singleton : ∀ a : α, nodup ({a} : multiset α) := nodup_singleton
lemma nodup.of_cons (h : nodup (a ::ₘ s)) : nodup s := (nodup_cons.1 h).2
theorem nodup.not_mem (h : nodup (a ::ₘ s)) : a ∉ s := (nodup_cons.1 h).1
theorem nodup_of_le {s t : multiset α} (h : s ≤ t) : nodup t → nodup s :=
le_induction_on h $ λ l₁ l₂, nodup.sublist
theorem not_nodup_pair : ∀ a : α, ¬ nodup (a ::ₘ a ::ₘ 0) := not_nodup_pair
theorem nodup_iff_le {s : multiset α} : nodup s ↔ ∀ a : α, ¬ a ::ₘ a ::ₘ 0 ≤ s :=
quot.induction_on s $ λ l, nodup_iff_sublist.trans $ forall_congr $ λ a,
not_congr (@repeat_le_coe _ a 2 _).symm
lemma nodup_iff_ne_cons_cons {s : multiset α} : s.nodup ↔ ∀ a t, s ≠ a ::ₘ a ::ₘ t :=
nodup_iff_le.trans
⟨λ h a t s_eq, h a (s_eq.symm ▸ cons_le_cons a (cons_le_cons a (zero_le _))),
λ h a le, let ⟨t, s_eq⟩ := le_iff_exists_add.mp le in
h a t (by rwa [cons_add, cons_add, zero_add] at s_eq )⟩
theorem nodup_iff_count_le_one [decidable_eq α] {s : multiset α} : nodup s ↔ ∀ a, count a s ≤ 1 :=
quot.induction_on s $ λ l, nodup_iff_count_le_one
@[simp] theorem count_eq_one_of_mem [decidable_eq α] {a : α} {s : multiset α}
(d : nodup s) (h : a ∈ s) : count a s = 1 :=
le_antisymm (nodup_iff_count_le_one.1 d a) (count_pos.2 h)
lemma nodup_iff_pairwise {α} {s : multiset α} : nodup s ↔ pairwise (≠) s :=
quotient.induction_on s $ λ l, (pairwise_coe_iff_pairwise (by exact λ a b, ne.symm)).symm
protected lemma nodup.pairwise : (∀ a ∈ s, ∀ b ∈ s, a ≠ b → r a b) → nodup s → pairwise r s :=
quotient.induction_on s $ assume l h hl, ⟨l, rfl, hl.imp_of_mem $ assume a b ha hb, h a ha b hb⟩
lemma pairwise.forall (H : symmetric r) (hs : pairwise r s) :
∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ≠ b → r a b :=
let ⟨l, hl₁, hl₂⟩ := hs in hl₁.symm ▸ hl₂.forall H
theorem nodup_add {s t : multiset α} : nodup (s + t) ↔ nodup s ∧ nodup t ∧ disjoint s t :=
quotient.induction_on₂ s t $ λ l₁ l₂, nodup_append
theorem disjoint_of_nodup_add {s t : multiset α} (d : nodup (s + t)) : disjoint s t :=
(nodup_add.1 d).2.2
lemma nodup.add_iff (d₁ : nodup s) (d₂ : nodup t) : nodup (s + t) ↔ disjoint s t :=
by simp [nodup_add, d₁, d₂]
lemma nodup.of_map (f : α → β) : nodup (map f s) → nodup s :=
quot.induction_on s $ λ l, nodup.of_map f
lemma nodup.map_on {f : α → β} : (∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y) →
nodup s → nodup (map f s) :=
quot.induction_on s $ λ l, nodup.map_on
lemma nodup.map {f : α → β} {s : multiset α} (hf : injective f) : nodup s → nodup (map f s) :=
nodup.map_on (λ x _ y _ h, hf h)
theorem inj_on_of_nodup_map {f : α → β} {s : multiset α} :
nodup (map f s) → ∀ (x ∈ s) (y ∈ s), f x = f y → x = y :=
quot.induction_on s $ λ l, inj_on_of_nodup_map
theorem nodup_map_iff_inj_on {f : α → β} {s : multiset α} (d : nodup s) :
nodup (map f s) ↔ (∀ (x ∈ s) (y ∈ s), f x = f y → x = y) :=
⟨inj_on_of_nodup_map, λ h, d.map_on h⟩
lemma nodup.filter (p : α → Prop) [decidable_pred p] {s} : nodup s → nodup (filter p s) :=
quot.induction_on s $ λ l, nodup.filter p
@[simp] theorem nodup_attach {s : multiset α} : nodup (attach s) ↔ nodup s :=
quot.induction_on s $ λ l, nodup_attach
lemma nodup.pmap {p : α → Prop} {f : Π a, p a → β} {s : multiset α} {H}
(hf : ∀ a ha b hb, f a ha = f b hb → a = b) : nodup s → nodup (pmap f s H) :=
quot.induction_on s (λ l H, nodup.pmap hf) H
instance nodup_decidable [decidable_eq α] (s : multiset α) : decidable (nodup s) :=
quotient.rec_on_subsingleton s $ λ l, l.nodup_decidable
lemma nodup.erase_eq_filter [decidable_eq α] (a : α) {s} : nodup s → s.erase a = filter (≠ a) s :=
quot.induction_on s $ λ l d, congr_arg coe $ d.erase_eq_filter a
lemma nodup.erase [decidable_eq α] (a : α) {l} : nodup l → nodup (l.erase a) :=
nodup_of_le (erase_le _ _)
lemma nodup.mem_erase_iff [decidable_eq α] {a b : α} {l} (d : nodup l) :
a ∈ l.erase b ↔ a ≠ b ∧ a ∈ l :=
by rw [d.erase_eq_filter b, mem_filter, and_comm]
lemma nodup.not_mem_erase [decidable_eq α] {a : α} {s} (h : nodup s) : a ∉ s.erase a :=
λ ha, (h.mem_erase_iff.1 ha).1 rfl
protected lemma nodup.product {t : multiset β} : nodup s → nodup t → nodup (product s t) :=
quotient.induction_on₂ s t $ λ l₁ l₂ d₁ d₂, by simp [d₁.product d₂]
protected lemma nodup.sigma {σ : α → Type*} {t : Π a, multiset (σ a)} :
nodup s → (∀ a, nodup (t a)) → nodup (s.sigma t) :=
quot.induction_on s $ assume l₁,
begin
choose f hf using assume a, quotient.exists_rep (t a),
rw show t = λ a, f a, from (eq.symm $ funext $ λ a, hf a),
simpa using nodup.sigma
end
protected lemma nodup.filter_map (f : α → option β) (H : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a') :
nodup s → nodup (filter_map f s) :=
quot.induction_on s $ λ l, nodup.filter_map H
theorem nodup_range (n : ℕ) : nodup (range n) := nodup_range _
lemma nodup.inter_left [decidable_eq α] (t) : nodup s → nodup (s ∩ t) :=
nodup_of_le $ inter_le_left _ _
lemma nodup.inter_right [decidable_eq α] (s) : nodup t → nodup (s ∩ t) :=
nodup_of_le $ inter_le_right _ _
@[simp] theorem nodup_union [decidable_eq α] {s t : multiset α} :
nodup (s ∪ t) ↔ nodup s ∧ nodup t :=
⟨λ h, ⟨nodup_of_le (le_union_left _ _) h, nodup_of_le (le_union_right _ _) h⟩,
λ ⟨h₁, h₂⟩, nodup_iff_count_le_one.2 $ λ a, by rw [count_union]; exact
max_le (nodup_iff_count_le_one.1 h₁ a) (nodup_iff_count_le_one.1 h₂ a)⟩
@[simp] theorem nodup_powerset {s : multiset α} : nodup (powerset s) ↔ nodup s :=
⟨λ h, (nodup_of_le (map_single_le_powerset _) h).of_map _,
quotient.induction_on s $ λ l h,
by simp; refine (nodup_sublists'.2 h).map_on _ ; exact
λ x sx y sy e,
(h.sublist_ext (mem_sublists'.1 sx) (mem_sublists'.1 sy)).1
(quotient.exact e)⟩
alias nodup_powerset ↔ multiset.nodup.of_powerset multiset.nodup.powerset
protected lemma nodup.powerset_len {n : ℕ} (h : nodup s) : nodup (powerset_len n s) :=
nodup_of_le (powerset_len_le_powerset _ _) (nodup_powerset.2 h)
@[simp] lemma nodup_bind {s : multiset α} {t : α → multiset β} :
nodup (bind s t) ↔ ((∀a∈s, nodup (t a)) ∧ (s.pairwise (λa b, disjoint (t a) (t b)))) :=
have h₁ : ∀a, ∃l:list β, t a = l, from
assume a, quot.induction_on (t a) $ assume l, ⟨l, rfl⟩,
let ⟨t', h'⟩ := classical.axiom_of_choice h₁ in
have t = λa, t' a, from funext h',
have hd : symmetric (λa b, list.disjoint (t' a) (t' b)), from assume a b h, h.symm,
quot.induction_on s $ by simp [this, list.nodup_bind, pairwise_coe_iff_pairwise hd]
lemma nodup.ext {s t : multiset α} : nodup s → nodup t → (s = t ↔ ∀ a, a ∈ s ↔ a ∈ t) :=
quotient.induction_on₂ s t $ λ l₁ l₂ d₁ d₂, quotient.eq.trans $ perm_ext d₁ d₂
theorem le_iff_subset {s t : multiset α} : nodup s → (s ≤ t ↔ s ⊆ t) :=
quotient.induction_on₂ s t $ λ l₁ l₂ d, ⟨subset_of_le, d.subperm⟩
theorem range_le {m n : ℕ} : range m ≤ range n ↔ m ≤ n :=
(le_iff_subset (nodup_range _)).trans range_subset
theorem mem_sub_of_nodup [decidable_eq α] {a : α} {s t : multiset α} (d : nodup s) :
a ∈ s - t ↔ a ∈ s ∧ a ∉ t :=
⟨λ h, ⟨mem_of_le tsub_le_self h, λ h',
by refine count_eq_zero.1 _ h; rw [count_sub a s t, tsub_eq_zero_iff_le];
exact le_trans (nodup_iff_count_le_one.1 d _) (count_pos.2 h')⟩,
λ ⟨h₁, h₂⟩, or.resolve_right (mem_add.1 $ mem_of_le le_tsub_add h₁) h₂⟩
lemma map_eq_map_of_bij_of_nodup (f : α → γ) (g : β → γ) {s : multiset α} {t : multiset β}
(hs : s.nodup) (ht : t.nodup) (i : Πa∈s, β)
(hi : ∀a ha, i a ha ∈ t) (h : ∀a ha, f a = g (i a ha))
(i_inj : ∀a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂)
(i_surj : ∀b∈t, ∃a ha, b = i a ha) :
s.map f = t.map g :=
have t = s.attach.map (λ x, i x.1 x.2),
from (ht.ext $ (nodup_attach.2 hs).map $
show injective (λ x : {x // x ∈ s}, i x.1 x.2), from λ x y hxy,
subtype.eq $ i_inj x.1 y.1 x.2 y.2 hxy).2
(λ x, by simp only [mem_map, true_and, subtype.exists, eq_comm, mem_attach];
exact ⟨i_surj _, λ ⟨y, hy⟩, hy.snd.symm ▸ hi _ _⟩),
calc s.map f = s.pmap (λ x _, f x) (λ _, id) : by rw [pmap_eq_map]
... = s.attach.map (λ x, f x.1) : by rw [pmap_eq_map_attach]
... = t.map g : by rw [this, multiset.map_map]; exact map_congr rfl (λ x _, h _ _)
end multiset
|
603323de3ffa63bfec214d5652c78f482720131f
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/attribute_bug1.lean
|
242c0bf745a3e715ebef359df941812a1b62697e
|
[
"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
| 477
|
lean
|
open tactic
constant f : nat → nat
constant fdef : ∀ n, f n = n + 1
example (n : nat) : f n = n + 1 :=
by simp -- Failed as expected, since fdef is not marked as [simp]
local attribute [simp] fdef
example (n : nat) : f n = n + 1 :=
by simp -- Succeeded as expected
local attribute [-simp] fdef
#print fdef -- we don't get the [simp] attribute when printing fdef
example (n : nat) : f n = n + 1 :=
by simp -- Failed as expected, since we removed [simp] attribute
|
79ab8278bc7752f9acb4869771a0e11d07565861
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/synthorder.lean
|
416e2cab1ed8b0edcfb2782fb3acbb60f40ea5fc
|
[
"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
| 848
|
lean
|
class Foo (A : Type) (B : semiOutParam Type)
-- should be rejected, because C appears by itself in an out-param
instance [Foo A B] : Foo A (B × C) where
-- should be rejected, because non-out-param A can become an mvar
instance [Foo A Nat] : Foo Nat A where
set_option trace.Meta.synthOrder true
-- both instances should synthesize [Foo A B] first:
instance [Foo A B] [Foo B C] : Foo A C where
instance [Foo B C] [Foo A B] : Foo A C where
instance : Foo (Option A) A where
class One (α : Type)
class Two (α) [One α]
class TwoHalf (α) [One α] extends Two α
class Three (α : Type) (β : outParam Type) [One β] [Two β]
-- should both be accepted and synthesize `Three α β` first:
class Four (α : Type) (β : outParam Type) [One β] [TwoHalf β] extends Three α β
instance [One β] [TwoHalf β] [Three α β] : Four α β where
|
c2a78c648533c5191e06735aecd20295e0c63883
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/category_theory/closed/ideal.lean
|
84959823ad8ecb0cc1aee53fcc1aefddad0143ef
|
[
"Apache-2.0"
] |
permissive
|
alreadydone/mathlib
|
dc0be621c6c8208c581f5170a8216c5ba6721927
|
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
|
refs/heads/master
| 1,685,523,275,196
| 1,670,184,141,000
| 1,670,184,141,000
| 287,574,545
| 0
| 0
|
Apache-2.0
| 1,670,290,714,000
| 1,597,421,623,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 11,888
|
lean
|
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.preserves.shapes.binary_products
import category_theory.limits.constructions.finite_products_of_binary_products
import category_theory.monad.limits
import category_theory.adjunction.fully_faithful
import category_theory.adjunction.reflective
import category_theory.closed.cartesian
import category_theory.subterminal
/-!
# Exponential ideals
An exponential ideal of a cartesian closed category `C` is a subcategory `D ⊆ C` such that for any
`B : D` and `A : C`, the exponential `A ⟹ B` is in `D`: resembling ring theoretic ideals. We
define the notion here for inclusion functors `i : D ⥤ C` rather than explicit subcategories to
preserve the principle of equivalence.
We additionally show that if `C` is cartesian closed and `i : D ⥤ C` is a reflective functor, the
following are equivalent.
* The left adjoint to `i` preserves binary (equivalently, finite) products.
* `i` is an exponential ideal.
-/
universes v₁ v₂ u₁ u₂
noncomputable theory
namespace category_theory
open limits category
section ideal
variables {C : Type u₁} {D : Type u₂} [category.{v₁} C] [category.{v₁} D] {i : D ⥤ C}
variables (i) [has_finite_products C] [cartesian_closed C]
/--
The subcategory `D` of `C` expressed as an inclusion functor is an *exponential ideal* if
`B ∈ D` implies `A ⟹ B ∈ D` for all `A`.
-/
class exponential_ideal : Prop :=
(exp_closed : ∀ {B}, B ∈ i.ess_image → ∀ A, (A ⟹ B) ∈ i.ess_image)
/--
To show `i` is an exponential ideal it suffices to show that `A ⟹ iB` is "in" `D` for any `A` in
`C` and `B` in `D`.
-/
lemma exponential_ideal.mk' (h : ∀ (B : D) (A : C), (A ⟹ i.obj B) ∈ i.ess_image) :
exponential_ideal i :=
⟨λ B hB A,
begin
rcases hB with ⟨B', ⟨iB'⟩⟩,
exact functor.ess_image.of_iso ((exp A).map_iso iB') (h B' A),
end⟩
/-- The entire category viewed as a subcategory is an exponential ideal. -/
instance : exponential_ideal (𝟭 C) :=
exponential_ideal.mk' _ (λ B A, ⟨_, ⟨iso.refl _⟩⟩)
open cartesian_closed
/-- The subcategory of subterminal objects is an exponential ideal. -/
instance : exponential_ideal (subterminal_inclusion C) :=
begin
apply exponential_ideal.mk',
intros B A,
refine ⟨⟨A ⟹ B.1, λ Z g h, _⟩, ⟨iso.refl _⟩⟩,
exact uncurry_injective (B.2 (cartesian_closed.uncurry g) (cartesian_closed.uncurry h))
end
/--
If `D` is a reflective subcategory, the property of being an exponential ideal is equivalent to
the presence of a natural isomorphism `i ⋙ exp A ⋙ left_adjoint i ⋙ i ≅ i ⋙ exp A`, that is:
`(A ⟹ iB) ≅ i L (A ⟹ iB)`, naturally in `B`.
The converse is given in `exponential_ideal.mk_of_iso`.
-/
def exponential_ideal_reflective (A : C) [reflective i] [exponential_ideal i] :
i ⋙ exp A ⋙ left_adjoint i ⋙ i ≅ i ⋙ exp A :=
begin
symmetry,
apply nat_iso.of_components _ _,
{ intro X,
haveI := (exponential_ideal.exp_closed (i.obj_mem_ess_image X) A).unit_is_iso,
apply as_iso ((adjunction.of_right_adjoint i).unit.app (A ⟹ i.obj X)) },
{ simp }
end
/--
Given a natural isomorphism `i ⋙ exp A ⋙ left_adjoint i ⋙ i ≅ i ⋙ exp A`, we can show `i`
is an exponential ideal.
-/
lemma exponential_ideal.mk_of_iso [reflective i]
(h : Π (A : C), i ⋙ exp A ⋙ left_adjoint i ⋙ i ≅ i ⋙ exp A) :
exponential_ideal i :=
begin
apply exponential_ideal.mk',
intros B A,
exact ⟨_, ⟨(h A).app B⟩⟩,
end
end ideal
section
variables {C : Type u₁} {D : Type u₂} [category.{v₁} C] [category.{v₁} D]
variables (i : D ⥤ C)
lemma reflective_products [has_finite_products C] [reflective i] : has_finite_products D :=
⟨λ n, has_limits_of_shape_of_reflective i⟩
local attribute [instance, priority 10] reflective_products
open cartesian_closed
variables [has_finite_products C] [reflective i] [cartesian_closed C]
/--
If the reflector preserves binary products, the subcategory is an exponential ideal.
This is the converse of `preserves_binary_products_of_exponential_ideal`.
-/
@[priority 10]
instance exponential_ideal_of_preserves_binary_products
[preserves_limits_of_shape (discrete walking_pair) (left_adjoint i)] :
exponential_ideal i :=
begin
let ir := adjunction.of_right_adjoint i,
let L : C ⥤ D := left_adjoint i,
let η : 𝟭 C ⟶ L ⋙ i := ir.unit,
let ε : i ⋙ L ⟶ 𝟭 D := ir.counit,
apply exponential_ideal.mk',
intros B A,
let q : i.obj (L.obj (A ⟹ i.obj B)) ⟶ A ⟹ i.obj B,
apply cartesian_closed.curry (ir.hom_equiv _ _ _),
apply _ ≫ (ir.hom_equiv _ _).symm ((exp.ev A).app (i.obj B)),
refine prod_comparison L A _ ≫ limits.prod.map (𝟙 _) (ε.app _) ≫ inv (prod_comparison _ _ _),
have : η.app (A ⟹ i.obj B) ≫ q = 𝟙 (A ⟹ i.obj B),
{ dsimp,
rw [← curry_natural_left, curry_eq_iff, uncurry_id_eq_ev, ← ir.hom_equiv_naturality_left,
ir.hom_equiv_apply_eq, assoc, assoc, prod_comparison_natural_assoc, L.map_id,
← prod.map_id_comp_assoc, ir.left_triangle_components, prod.map_id_id, id_comp],
apply is_iso.hom_inv_id_assoc },
haveI : is_split_mono (η.app (A ⟹ i.obj B)) := is_split_mono.mk' ⟨_, this⟩,
apply mem_ess_image_of_unit_is_split_mono,
end
variables [exponential_ideal i]
/--
If `i` witnesses that `D` is a reflective subcategory and an exponential ideal, then `D` is
itself cartesian closed.
-/
def cartesian_closed_of_reflective : cartesian_closed D :=
{ closed' := λ B,
{ is_adj :=
{ right := i ⋙ exp (i.obj B) ⋙ left_adjoint i,
adj :=
begin
apply adjunction.restrict_fully_faithful i i (exp.adjunction (i.obj B)),
{ symmetry,
apply nat_iso.of_components _ _,
{ intro X,
haveI :=
adjunction.right_adjoint_preserves_limits.{0 0} (adjunction.of_right_adjoint i),
apply as_iso (prod_comparison i B X) },
{ intros X Y f,
dsimp,
rw prod_comparison_natural,
simp, } },
{ apply (exponential_ideal_reflective i _).symm }
end } } }
-- It's annoying that I need to do this.
local attribute [-instance]
category_theory.preserves_limit_of_creates_limit_and_has_limit
category_theory.preserves_limit_of_shape_of_creates_limits_of_shape_and_has_limits_of_shape
/--
We construct a bijection between morphisms `L(A ⨯ B) ⟶ X` and morphisms `LA ⨯ LB ⟶ X`.
This bijection has two key properties:
* It is natural in `X`: See `bijection_natural`.
* When `X = LA ⨯ LB`, then the backwards direction sends the identity morphism to the product
comparison morphism: See `bijection_symm_apply_id`.
Together these help show that `L` preserves binary products. This should be considered
*internal implementation* towards `preserves_binary_products_of_exponential_ideal`.
-/
noncomputable def bijection (A B : C) (X : D) :
((left_adjoint i).obj (A ⨯ B) ⟶ X) ≃ ((left_adjoint i).obj A ⨯ (left_adjoint i).obj B ⟶ X) :=
calc _ ≃ (A ⨯ B ⟶ i.obj X) :
(adjunction.of_right_adjoint i).hom_equiv _ _
... ≃ (B ⨯ A ⟶ i.obj X) :
(limits.prod.braiding _ _).hom_congr (iso.refl _)
... ≃ (A ⟶ B ⟹ i.obj X) :
(exp.adjunction _).hom_equiv _ _
... ≃ (i.obj ((left_adjoint i).obj A) ⟶ B ⟹ i.obj X) :
unit_comp_partial_bijective _ (exponential_ideal.exp_closed (i.obj_mem_ess_image _) _)
... ≃ (B ⨯ i.obj ((left_adjoint i).obj A) ⟶ i.obj X) :
((exp.adjunction _).hom_equiv _ _).symm
... ≃ (i.obj ((left_adjoint i).obj A) ⨯ B ⟶ i.obj X) :
(limits.prod.braiding _ _).hom_congr (iso.refl _)
... ≃ (B ⟶ i.obj ((left_adjoint i).obj A) ⟹ i.obj X) :
(exp.adjunction _).hom_equiv _ _
... ≃ (i.obj ((left_adjoint i).obj B) ⟶ i.obj ((left_adjoint i).obj A) ⟹ i.obj X) :
unit_comp_partial_bijective _ (exponential_ideal.exp_closed (i.obj_mem_ess_image _) _)
... ≃ (i.obj ((left_adjoint i).obj A) ⨯ i.obj ((left_adjoint i).obj B) ⟶ i.obj X) :
((exp.adjunction _).hom_equiv _ _).symm
... ≃ (i.obj ((left_adjoint i).obj A ⨯ (left_adjoint i).obj B) ⟶ i.obj X) :
begin
apply iso.hom_congr _ (iso.refl _),
haveI : preserves_limits i := (adjunction.of_right_adjoint i).right_adjoint_preserves_limits,
haveI := preserves_smallest_limits_of_preserves_limits i,
exact (preserves_limit_pair.iso _ _ _).symm,
end
... ≃ ((left_adjoint i).obj A ⨯ (left_adjoint i).obj B ⟶ X) :
(equiv_of_fully_faithful _).symm
lemma bijection_symm_apply_id (A B : C) :
(bijection i A B _).symm (𝟙 _) = prod_comparison _ _ _ :=
begin
dsimp [bijection],
rw [comp_id, comp_id, comp_id, i.map_id, comp_id, unit_comp_partial_bijective_symm_apply,
unit_comp_partial_bijective_symm_apply, uncurry_natural_left, uncurry_curry,
uncurry_natural_left, uncurry_curry, prod.lift_map_assoc, comp_id, prod.lift_map_assoc,
comp_id, prod.comp_lift_assoc, prod.lift_snd, prod.lift_fst_assoc,
prod.lift_fst_comp_snd_comp, ←adjunction.eq_hom_equiv_apply, adjunction.hom_equiv_unit,
iso.comp_inv_eq, assoc, preserves_limit_pair.iso_hom],
apply prod.hom_ext,
{ rw [limits.prod.map_fst, assoc, assoc, prod_comparison_fst, ←i.map_comp, prod_comparison_fst],
apply (adjunction.of_right_adjoint i).unit.naturality },
{ rw [limits.prod.map_snd, assoc, assoc, prod_comparison_snd, ←i.map_comp, prod_comparison_snd],
apply (adjunction.of_right_adjoint i).unit.naturality },
end
lemma bijection_natural
(A B : C) (X X' : D) (f : ((left_adjoint i).obj (A ⨯ B) ⟶ X)) (g : X ⟶ X') :
bijection i _ _ _ (f ≫ g) = bijection i _ _ _ f ≫ g :=
begin
dsimp [bijection],
apply i.map_injective,
rw [i.image_preimage, i.map_comp, i.image_preimage, comp_id, comp_id, comp_id, comp_id, comp_id,
comp_id, adjunction.hom_equiv_naturality_right, ← assoc, curry_natural_right _ (i.map g),
unit_comp_partial_bijective_natural, uncurry_natural_right, ← assoc, curry_natural_right,
unit_comp_partial_bijective_natural, uncurry_natural_right, assoc],
end
/--
The bijection allows us to show that `prod_comparison L A B` is an isomorphism, where the inverse
is the forward map of the identity morphism.
-/
lemma prod_comparison_iso (A B : C) :
is_iso (prod_comparison (left_adjoint i) A B) :=
⟨⟨bijection i _ _ _ (𝟙 _),
by rw [←(bijection i _ _ _).injective.eq_iff, bijection_natural, ← bijection_symm_apply_id,
equiv.apply_symm_apply, id_comp],
by rw [←bijection_natural, id_comp, ←bijection_symm_apply_id, equiv.apply_symm_apply]⟩⟩
local attribute [instance] prod_comparison_iso
/--
If a reflective subcategory is an exponential ideal, then the reflector preserves binary products.
This is the converse of `exponential_ideal_of_preserves_binary_products`.
-/
noncomputable def preserves_binary_products_of_exponential_ideal :
preserves_limits_of_shape (discrete walking_pair) (left_adjoint i) :=
{ preserves_limit := λ K,
begin
apply limits.preserves_limit_of_iso_diagram _ (diagram_iso_pair K).symm,
apply preserves_limit_pair.of_iso_prod_comparison,
end }
/--
If a reflective subcategory is an exponential ideal, then the reflector preserves finite products.
-/
noncomputable def preserves_finite_products_of_exponential_ideal (J : Type) [fintype J] :
preserves_limits_of_shape (discrete J) (left_adjoint i) :=
begin
letI := preserves_binary_products_of_exponential_ideal i,
letI := left_adjoint_preserves_terminal_of_reflective.{0} i,
apply preserves_finite_products_of_preserves_binary_and_terminal (left_adjoint i) J,
end
end
end category_theory
|
5b15582a053b4a80a3df8af1a55f158c9881597c
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/lua10.lean
|
b19a99bf003b6987348fe37579bc5efa0232eb64
|
[
"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
| 297
|
lean
|
variables x1 x2 x3 : Bool
definition F : Bool := x1 /\ (x2 \/ x3)
(*
local env = get_environment()
local F = env:find_object("F"):get_value()
print(F)
function expr_size(e)
local r = 0
e:for_each(function(e, offset) r = r + 1 end)
return r
end
print(expr_size(F))
*)
|
ce83a131007e2257481b68b92d7a4c7610825ad9
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/pnat/find.lean
|
a1828db9d89eb158b528a69786cee4d34fdbb041
|
[
"Apache-2.0"
] |
permissive
|
Vierkantor/mathlib
|
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
|
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
|
refs/heads/master
| 1,658,323,012,449
| 1,652,256,003,000
| 1,652,256,003,000
| 209,296,341
| 0
| 1
|
Apache-2.0
| 1,568,807,655,000
| 1,568,807,655,000
| null |
UTF-8
|
Lean
| false
| false
| 3,877
|
lean
|
/-
Copyright (c) 2022 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky, Floris van Doorn
-/
import data.pnat.basic
/-!
# Explicit least witnesses to existentials on positive natural numbers
Implemented via calling out to `nat.find`.
-/
namespace pnat
variables {p q : ℕ+ → Prop} [decidable_pred p] [decidable_pred q] (h : ∃ n, p n)
instance decidable_pred_exists_nat :
decidable_pred (λ n' : ℕ, ∃ (n : ℕ+) (hn : n' = n), p n) := λ n',
decidable_of_iff' (∃ (h : 0 < n'), p ⟨n', h⟩) $ subtype.exists.trans $
by simp_rw [subtype.coe_mk, @exists_comm (_ < _) (_ = _), exists_prop, exists_eq_left']
include h
/-- The `pnat` version of `nat.find_x` -/
protected def find_x : {n // p n ∧ ∀ m : ℕ+, m < n → ¬p m} :=
begin
have : ∃ (n' : ℕ) (n : ℕ+) (hn' : n' = n), p n, from exists.elim h (λ n hn, ⟨n, n, rfl, hn⟩),
have n := nat.find_x this,
refine ⟨⟨n, _⟩, _, λ m hm pm, _⟩,
{ obtain ⟨n', hn', -⟩ := n.prop.1,
rw hn',
exact n'.prop },
{ obtain ⟨n', hn', pn'⟩ := n.prop.1,
simpa [hn', subtype.coe_eta] using pn' },
{ exact n.prop.2 m hm ⟨m, rfl, pm⟩ }
end
/--
If `p` is a (decidable) predicate on `ℕ+` and `hp : ∃ (n : ℕ+), p n` is a proof that
there exists some positive natural number satisfying `p`, then `pnat.find hp` is the
smallest positive natural number satisfying `p`. Note that `pnat.find` is protected,
meaning that you can't just write `find`, even if the `pnat` namespace is open.
The API for `pnat.find` is:
* `pnat.find_spec` is the proof that `pnat.find hp` satisfies `p`.
* `pnat.find_min` is the proof that if `m < pnat.find hp` then `m` does not satisfy `p`.
* `pnat.find_min'` is the proof that if `m` does satisfy `p` then `pnat.find hp ≤ m`.
-/
protected def find : ℕ+ :=
pnat.find_x h
protected theorem find_spec : p (pnat.find h) :=
(pnat.find_x h).prop.left
protected theorem find_min : ∀ {m : ℕ+}, m < pnat.find h → ¬p m :=
(pnat.find_x h).prop.right
protected theorem find_min' {m : ℕ+} (hm : p m) : pnat.find h ≤ m :=
le_of_not_lt (λ l, pnat.find_min h l hm)
variables {n m : ℕ+}
lemma find_eq_iff : pnat.find h = m ↔ p m ∧ ∀ n < m, ¬ p n :=
begin
split,
{ rintro rfl, exact ⟨pnat.find_spec h, λ _, pnat.find_min h⟩ },
{ rintro ⟨hm, hlt⟩,
exact le_antisymm (pnat.find_min' h hm) (not_lt.1 $ imp_not_comm.1 (hlt _) $ pnat.find_spec h) }
end
@[simp] lemma find_lt_iff (n : ℕ+) : pnat.find h < n ↔ ∃ m < n, p m :=
⟨λ h2, ⟨pnat.find h, h2, pnat.find_spec h⟩, λ ⟨m, hmn, hm⟩, (pnat.find_min' h hm).trans_lt hmn⟩
@[simp] lemma find_le_iff (n : ℕ+) : pnat.find h ≤ n ↔ ∃ m ≤ n, p m :=
by simp only [exists_prop, ← lt_add_one_iff, find_lt_iff]
@[simp] lemma le_find_iff (n : ℕ+) : n ≤ pnat.find h ↔ ∀ m < n, ¬ p m :=
by simp_rw [← not_lt, find_lt_iff, not_exists]
@[simp] lemma lt_find_iff (n : ℕ+) : n < pnat.find h ↔ ∀ m ≤ n, ¬ p m :=
by simp only [← add_one_le_iff, le_find_iff, add_le_add_iff_right]
@[simp] lemma find_eq_one : pnat.find h = 1 ↔ p 1 :=
by simp [find_eq_iff]
@[simp] lemma one_le_find : 1 < pnat.find h ↔ ¬ p 1 :=
not_iff_not.mp $ by simp
theorem find_mono (h : ∀ n, q n → p n)
{hp : ∃ n, p n} {hq : ∃ n, q n} :
pnat.find hp ≤ pnat.find hq :=
pnat.find_min' _ (h _ (pnat.find_spec hq))
lemma find_le {h : ∃ n, p n} (hn : p n) : pnat.find h ≤ n :=
(pnat.find_le_iff _ _).2 ⟨n, le_rfl, hn⟩
lemma find_comp_succ (h : ∃ n, p n) (h₂ : ∃ n, p (n + 1)) (h1 : ¬ p 1) :
pnat.find h = pnat.find h₂ + 1 :=
begin
refine (find_eq_iff _).2 ⟨pnat.find_spec h₂, λ n, pnat.rec_on n _ _⟩,
{ simp [h1] },
intros m IH hm,
simp only [add_lt_add_iff_right, lt_find_iff] at hm,
exact hm _ le_rfl
end
end pnat
|
12d10d2bdbf4092be93267d3684498688ee9c300
|
01ae0d022f2e2fefdaaa898938c1ac1fbce3b3ab
|
/categories/universal/fubini.lean
|
939ab430ad38831fa94a8d20aa29c964d1823fce
|
[] |
no_license
|
PatrickMassot/lean-category-theory
|
0f56a83464396a253c28a42dece16c93baf8ad74
|
ef239978e91f2e1c3b8e88b6e9c64c155dc56c99
|
refs/heads/master
| 1,629,739,187,316
| 1,512,422,659,000
| 1,512,422,659,000
| 113,098,786
| 0
| 0
| null | 1,512,424,022,000
| 1,512,424,022,000
| null |
UTF-8
|
Lean
| false
| false
| 2,175
|
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 .universal
import ..isomorphism
import ..natural_transformation
import ..currying.currying_1
open categories
open categories.functor
open categories.isomorphism
open categories.initial
open categories.natural_transformation
namespace categories.universal
structure iterated_limit_for_bifunctor
{ J K : Category }
{ C : Category }
( F : Functor (J × K) C ) :=
( limitFunctor : LimitCone ( Curry_Functors J K C F ) )
( limitObject : LimitCone ( limitFunctor.terminal_object.cone_point ) )
-- definition Fubini_for_Limits
-- { J K : Category }
-- { C : Category }
-- { F : Functor (J × K) C }
-- ( lim : LimitCone F ) : iterated_limit_for_bifunctor F := {
-- limitFunctor := {
-- terminal_object := {
-- cone_point := {
-- onObjects := λ k : K.Obj, sorry,
-- onMorphisms := λ _ _ f, sorry,
-- identities := sorry,
-- functoriality := sorry
-- },
-- cone_maps := sorry,
-- commutativity := sorry
-- },
-- morphism_to_terminal_object_from := sorry,
-- uniqueness_of_morphisms_to_terminal_object := sorry
-- },
-- limitObject := sorry
-- }
-- definition Fubini_for_Limits_inverse
-- { J K : Category }
-- { C : Category }
-- { F : Functor (J × K) C }
-- ( lim : iterated_limit_for_bifunctor F ) : Limit F := sorry
-- lemma Fubini_for_Limits.objects_isomorphic
-- { J K : Category }
-- { C : Category }
-- { F : Functor (J × K) C }
-- ( lim : Limit F ) : Isomorphism C lim.object.limit (Fubini_for_Limits lim).limitObject.object.limit := sorry
-- lemma Fubini_for_Limits_inverse.objects_isomorphic
-- { J K : Category }
-- { C : Category }
-- { F : Functor (J × K) C }
-- ( lim : iterated_limit_for_bifunctor F ) : Isomorphism C lim.limitObject.object.limit (Fubini_for_Limits_inverse lim).object.limit := sorry
end categories.universal
|
7f79a41995a5f4c7602204d862db148eecee4a67
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/measure_theory/function/l1_space.lean
|
ec45f50147a7313809b807dc9c01dd9a44f88aa8
|
[
"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
| 42,243
|
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.function.lp_space
/-!
# 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.
Such a predicate is already available under the name `mem_ℒp 1`. We give a direct definition which
is easier to use, and show that it is equivalent to `mem_ℒp 1`
In the second part, we establish an API between `integrable` and the space `L¹` of equivalence
classes of integrable functions, already defined as a special case of `L^p` spaces for `p = 1`.
## Notation
* `α →₁[μ] β` is the type of `L¹` space, where `α` is a `measure_space` and `β` is a `normed_group`
with a `second_countable_topology`. `f : α →ₘ β` is a "function" in `L¹`. In comments, `[f]` is
also used to denote an `L¹` function.
`₁` can be typed as `\1`.
## Main definitions
* Let `f : α → β` be a function, where `α` is a `measure_space` and `β` a `normed_group`.
Then `has_finite_integral f` means `(∫⁻ a, nnnorm (f a)) < ∞`.
* If `β` is moreover a `measurable_space` then `f` is called `integrable` if
`f` is `measurable` and `has_finite_integral f` holds.
## Implementation notes
To prove something for an arbitrary integrable function, a useful theorem is
`integrable.induction` in the file `set_integral`.
## Tags
integrable, function space, l1
-/
noncomputable theory
open_locale classical topological_space big_operators ennreal measure_theory nnreal
open set filter topological_space ennreal emetric measure_theory
variables {α β γ δ : Type*} {m : measurable_space α} {μ ν : measure α}
variables [normed_group β]
variables [normed_group γ]
namespace measure_theory
/-! ### Some results about the Lebesgue integral involving a normed group -/
lemma lintegral_nnnorm_eq_lintegral_edist (f : α → β) :
∫⁻ a, nnnorm (f a) ∂μ = ∫⁻ a, edist (f a) 0 ∂μ :=
by simp only [edist_eq_coe_nnnorm]
lemma lintegral_norm_eq_lintegral_edist (f : α → β) :
∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ = ∫⁻ a, edist (f a) 0 ∂μ :=
by simp only [of_real_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm]
lemma lintegral_edist_triangle [second_countable_topology β] [measurable_space β]
[opens_measurable_space β] {f g h : α → β}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) (hh : ae_measurable h μ) :
∫⁻ a, edist (f a) (g a) ∂μ ≤ ∫⁻ a, edist (f a) (h a) ∂μ + ∫⁻ a, edist (g a) (h a) ∂μ :=
begin
rw ← lintegral_add' (hf.edist hh) (hg.edist hh),
refine lintegral_mono (λ a, _),
apply edist_triangle_right
end
lemma lintegral_nnnorm_zero : ∫⁻ a : α, nnnorm (0 : β) ∂μ = 0 := by simp
lemma lintegral_nnnorm_add [measurable_space β] [opens_measurable_space β]
[measurable_space γ] [opens_measurable_space γ]
{f : α → β} {g : α → γ} (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
∫⁻ a, nnnorm (f a) + nnnorm (g a) ∂μ = ∫⁻ a, nnnorm (f a) ∂μ + ∫⁻ a, nnnorm (g a) ∂μ :=
lintegral_add' hf.ennnorm hg.ennnorm
lemma lintegral_nnnorm_neg {f : α → β} :
∫⁻ a, nnnorm ((-f) a) ∂μ = ∫⁻ a, nnnorm (f a) ∂μ :=
by simp only [pi.neg_apply, nnnorm_neg]
/-! ### The predicate `has_finite_integral` -/
/-- `has_finite_integral f μ` means that the integral `∫⁻ a, ∥f a∥ ∂μ` is finite.
`has_finite_integral f` means `has_finite_integral f volume`. -/
def has_finite_integral {m : measurable_space α} (f : α → β) (μ : measure α . volume_tac) : Prop :=
∫⁻ a, nnnorm (f a) ∂μ < ∞
lemma has_finite_integral_iff_norm (f : α → β) :
has_finite_integral f μ ↔ ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ < ∞ :=
by simp only [has_finite_integral, of_real_norm_eq_coe_nnnorm]
lemma has_finite_integral_iff_edist (f : α → β) :
has_finite_integral f μ ↔ ∫⁻ a, edist (f a) 0 ∂μ < ∞ :=
by simp only [has_finite_integral_iff_norm, edist_dist, dist_zero_right]
lemma has_finite_integral_iff_of_real {f : α → ℝ} (h : 0 ≤ᵐ[μ] f) :
has_finite_integral f μ ↔ ∫⁻ a, ennreal.of_real (f a) ∂μ < ∞ :=
have lintegral_eq : ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ = ∫⁻ a, ennreal.of_real (f a) ∂μ :=
begin
refine lintegral_congr_ae (h.mono $ λ a h, _),
rwa [real.norm_eq_abs, abs_of_nonneg]
end,
by rw [has_finite_integral_iff_norm, lintegral_eq]
lemma has_finite_integral_iff_of_nnreal {f : α → ℝ≥0} :
has_finite_integral (λ x, (f x : ℝ)) μ ↔ ∫⁻ a, f a ∂μ < ∞ :=
by simp [has_finite_integral_iff_norm]
lemma has_finite_integral.mono {f : α → β} {g : α → γ} (hg : has_finite_integral g μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ ∥g a∥) : has_finite_integral f μ :=
begin
simp only [has_finite_integral_iff_norm] at *,
calc ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ ≤ ∫⁻ (a : α), (ennreal.of_real ∥g a∥) ∂μ :
lintegral_mono_ae (h.mono $ assume a h, of_real_le_of_real h)
... < ∞ : hg
end
lemma has_finite_integral.mono' {f : α → β} {g : α → ℝ} (hg : has_finite_integral g μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ g a) : has_finite_integral f μ :=
hg.mono $ h.mono $ λ x hx, le_trans hx (le_abs_self _)
lemma has_finite_integral.congr' {f : α → β} {g : α → γ} (hf : has_finite_integral f μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
has_finite_integral g μ :=
hf.mono $ eventually_eq.le $ eventually_eq.symm h
lemma has_finite_integral_congr' {f : α → β} {g : α → γ} (h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
has_finite_integral f μ ↔ has_finite_integral g μ :=
⟨λ hf, hf.congr' h, λ hg, hg.congr' $ eventually_eq.symm h⟩
lemma has_finite_integral.congr {f g : α → β} (hf : has_finite_integral f μ) (h : f =ᵐ[μ] g) :
has_finite_integral g μ :=
hf.congr' $ h.fun_comp norm
lemma has_finite_integral_congr {f g : α → β} (h : f =ᵐ[μ] g) :
has_finite_integral f μ ↔ has_finite_integral g μ :=
has_finite_integral_congr' $ h.fun_comp norm
lemma has_finite_integral_const_iff {c : β} :
has_finite_integral (λ x : α, c) μ ↔ c = 0 ∨ μ univ < ∞ :=
by simp [has_finite_integral, lintegral_const, lt_top_iff_ne_top, or_iff_not_imp_left]
lemma has_finite_integral_const [is_finite_measure μ] (c : β) :
has_finite_integral (λ x : α, c) μ :=
has_finite_integral_const_iff.2 (or.inr $ measure_lt_top _ _)
lemma has_finite_integral_of_bounded [is_finite_measure μ] {f : α → β} {C : ℝ}
(hC : ∀ᵐ a ∂μ, ∥f a∥ ≤ C) : has_finite_integral f μ :=
(has_finite_integral_const C).mono' hC
lemma has_finite_integral.mono_measure {f : α → β} (h : has_finite_integral f ν) (hμ : μ ≤ ν) :
has_finite_integral f μ :=
lt_of_le_of_lt (lintegral_mono' hμ (le_refl _)) h
lemma has_finite_integral.add_measure {f : α → β} (hμ : has_finite_integral f μ)
(hν : has_finite_integral f ν) : has_finite_integral f (μ + ν) :=
begin
simp only [has_finite_integral, lintegral_add_measure] at *,
exact add_lt_top.2 ⟨hμ, hν⟩
end
lemma has_finite_integral.left_of_add_measure {f : α → β} (h : has_finite_integral f (μ + ν)) :
has_finite_integral f μ :=
h.mono_measure $ measure.le_add_right $ le_refl _
lemma has_finite_integral.right_of_add_measure {f : α → β} (h : has_finite_integral f (μ + ν)) :
has_finite_integral f ν :=
h.mono_measure $ measure.le_add_left $ le_refl _
@[simp] lemma has_finite_integral_add_measure {f : α → β} :
has_finite_integral f (μ + ν) ↔ has_finite_integral f μ ∧ has_finite_integral f ν :=
⟨λ h, ⟨h.left_of_add_measure, h.right_of_add_measure⟩, λ h, h.1.add_measure h.2⟩
lemma has_finite_integral.smul_measure {f : α → β} (h : has_finite_integral f μ) {c : ℝ≥0∞}
(hc : c ≠ ∞) : has_finite_integral f (c • μ) :=
begin
simp only [has_finite_integral, lintegral_smul_measure] at *,
exact mul_lt_top hc h.ne
end
@[simp] lemma has_finite_integral_zero_measure {m : measurable_space α} (f : α → β) :
has_finite_integral f (0 : measure α) :=
by simp only [has_finite_integral, lintegral_zero_measure, with_top.zero_lt_top]
variables (α β μ)
@[simp] lemma has_finite_integral_zero : has_finite_integral (λa:α, (0:β)) μ :=
by simp [has_finite_integral]
variables {α β μ}
lemma has_finite_integral.neg {f : α → β} (hfi : has_finite_integral f μ) :
has_finite_integral (-f) μ :=
by simpa [has_finite_integral] using hfi
@[simp] lemma has_finite_integral_neg_iff {f : α → β} :
has_finite_integral (-f) μ ↔ has_finite_integral f μ :=
⟨λ h, neg_neg f ▸ h.neg, has_finite_integral.neg⟩
lemma has_finite_integral.norm {f : α → β} (hfi : has_finite_integral f μ) :
has_finite_integral (λa, ∥f a∥) μ :=
have eq : (λa, (nnnorm ∥f a∥ : ℝ≥0∞)) = λa, (nnnorm (f a) : ℝ≥0∞),
by { funext, rw nnnorm_norm },
by { rwa [has_finite_integral, eq] }
lemma has_finite_integral_norm_iff (f : α → β) :
has_finite_integral (λa, ∥f a∥) μ ↔ has_finite_integral f μ :=
has_finite_integral_congr' $ eventually_of_forall $ λ x, norm_norm (f x)
lemma has_finite_integral_to_real_of_lintegral_ne_top
{f : α → ℝ≥0∞} (hf : ∫⁻ x, f x ∂μ ≠ ∞) :
has_finite_integral (λ x, (f x).to_real) μ :=
begin
have : ∀ x, (∥(f x).to_real∥₊ : ℝ≥0∞) =
@coe ℝ≥0 ℝ≥0∞ _ (⟨(f x).to_real, ennreal.to_real_nonneg⟩ : ℝ≥0),
{ intro x, rw real.nnnorm_of_nonneg },
simp_rw [has_finite_integral, this],
refine lt_of_le_of_lt (lintegral_mono (λ x, _)) (lt_top_iff_ne_top.2 hf),
by_cases hfx : f x = ∞,
{ simp [hfx] },
{ lift f x to ℝ≥0 using hfx with fx,
simp [← h] }
end
lemma is_finite_measure_with_density_of_real {f : α → ℝ} (hfi : has_finite_integral f μ) :
is_finite_measure (μ.with_density (λ x, ennreal.of_real $ f x)) :=
begin
refine is_finite_measure_with_density ((lintegral_mono $ λ x, _).trans_lt hfi).ne,
exact real.of_real_le_ennnorm (f x)
end
section dominated_convergence
variables {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
lemma all_ae_of_real_F_le_bound (h : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a) :
∀ n, ∀ᵐ a ∂μ, ennreal.of_real ∥F n a∥ ≤ ennreal.of_real (bound a) :=
λn, (h n).mono $ λ a h, ennreal.of_real_le_of_real h
lemma all_ae_tendsto_of_real_norm (h : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top $ 𝓝 $ f a) :
∀ᵐ a ∂μ, tendsto (λn, ennreal.of_real ∥F n a∥) at_top $ 𝓝 $ ennreal.of_real ∥f a∥ :=
h.mono $
λ a h, tendsto_of_real $ tendsto.comp (continuous.tendsto continuous_norm _) h
lemma all_ae_of_real_f_le_bound (h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
∀ᵐ a ∂μ, ennreal.of_real ∥f a∥ ≤ ennreal.of_real (bound a) :=
begin
have F_le_bound := all_ae_of_real_F_le_bound h_bound,
rw ← ae_all_iff at F_le_bound,
apply F_le_bound.mp ((all_ae_tendsto_of_real_norm h_lim).mono _),
assume a tendsto_norm F_le_bound,
exact le_of_tendsto' tendsto_norm (F_le_bound)
end
lemma has_finite_integral_of_dominated_convergence {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(bound_has_finite_integral : has_finite_integral bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
has_finite_integral f μ :=
/- `∥F n a∥ ≤ bound a` and `∥F n a∥ --> ∥f a∥` implies `∥f a∥ ≤ bound a`,
and so `∫ ∥f∥ ≤ ∫ bound < ∞` since `bound` is has_finite_integral -/
begin
rw has_finite_integral_iff_norm,
calc ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ ≤ ∫⁻ a, ennreal.of_real (bound a) ∂μ :
lintegral_mono_ae $ all_ae_of_real_f_le_bound h_bound h_lim
... < ∞ :
begin
rw ← has_finite_integral_iff_of_real,
{ exact bound_has_finite_integral },
exact (h_bound 0).mono (λ a h, le_trans (norm_nonneg _) h)
end
end
lemma tendsto_lintegral_norm_of_dominated_convergence [measurable_space β]
[borel_space β] [second_countable_topology β]
{F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(F_measurable : ∀ n, ae_measurable (F n) μ)
(bound_has_finite_integral : has_finite_integral bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
tendsto (λn, ∫⁻ a, (ennreal.of_real ∥F n a - f a∥) ∂μ) at_top (𝓝 0) :=
have f_measurable : ae_measurable f μ := ae_measurable_of_tendsto_metric_ae F_measurable h_lim,
let b := λ a, 2 * ennreal.of_real (bound a) in
/- `∥F n a∥ ≤ bound a` and `F n a --> f a` implies `∥f a∥ ≤ bound a`, and thus by the
triangle inequality, have `∥F n a - f a∥ ≤ 2 * (bound a). -/
have hb : ∀ n, ∀ᵐ a ∂μ, ennreal.of_real ∥F n a - f a∥ ≤ b a,
begin
assume n,
filter_upwards [all_ae_of_real_F_le_bound h_bound n, all_ae_of_real_f_le_bound h_bound h_lim],
assume a h₁ h₂,
calc ennreal.of_real ∥F n a - f a∥ ≤ (ennreal.of_real ∥F n a∥) + (ennreal.of_real ∥f a∥) :
begin
rw [← ennreal.of_real_add],
apply of_real_le_of_real,
{ apply norm_sub_le }, { exact norm_nonneg _ }, { exact norm_nonneg _ }
end
... ≤ (ennreal.of_real (bound a)) + (ennreal.of_real (bound a)) : add_le_add h₁ h₂
... = b a : by rw ← two_mul
end,
/- On the other hand, `F n a --> f a` implies that `∥F n a - f a∥ --> 0` -/
have h : ∀ᵐ a ∂μ, tendsto (λ n, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 0),
begin
rw ← ennreal.of_real_zero,
refine h_lim.mono (λ a h, (continuous_of_real.tendsto _).comp _),
rwa ← tendsto_iff_norm_tendsto_zero
end,
/- Therefore, by the dominated convergence theorem for nonnegative integration, have
` ∫ ∥f a - F n a∥ --> 0 ` -/
begin
suffices h : tendsto (λn, ∫⁻ a, (ennreal.of_real ∥F n a - f a∥) ∂μ) at_top (𝓝 (∫⁻ (a:α), 0 ∂μ)),
{ rwa lintegral_zero at h },
-- Using the dominated convergence theorem.
refine tendsto_lintegral_of_dominated_convergence' _ _ hb _ _,
-- Show `λa, ∥f a - F n a∥` is almost everywhere measurable for all `n`
{ exact λn, measurable_of_real.comp_ae_measurable ((F_measurable n).sub f_measurable).norm },
-- Show `2 * bound` is has_finite_integral
{ rw has_finite_integral_iff_of_real at bound_has_finite_integral,
{ calc ∫⁻ a, b a ∂μ = 2 * ∫⁻ a, ennreal.of_real (bound a) ∂μ :
by { rw lintegral_const_mul', exact coe_ne_top }
... ≠ ∞ : mul_ne_top coe_ne_top bound_has_finite_integral.ne },
filter_upwards [h_bound 0] λ a h, le_trans (norm_nonneg _) h },
-- Show `∥f a - F n a∥ --> 0`
{ exact h }
end
end dominated_convergence
section pos_part
/-! Lemmas used for defining the positive part of a `L¹` function -/
lemma has_finite_integral.max_zero {f : α → ℝ} (hf : has_finite_integral f μ) :
has_finite_integral (λa, max (f a) 0) μ :=
hf.mono $ eventually_of_forall $ λ x, by simp [real.norm_eq_abs, abs_le, abs_nonneg, le_abs_self]
lemma has_finite_integral.min_zero {f : α → ℝ} (hf : has_finite_integral f μ) :
has_finite_integral (λa, min (f a) 0) μ :=
hf.mono $ eventually_of_forall $ λ x,
by simp [real.norm_eq_abs, abs_le, abs_nonneg, neg_le, neg_le_abs_self, abs_eq_max_neg, le_total]
end pos_part
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma has_finite_integral.smul (c : 𝕜) {f : α → β} : has_finite_integral f μ →
has_finite_integral (c • f) μ :=
begin
simp only [has_finite_integral], assume hfi,
calc
∫⁻ (a : α), nnnorm (c • f a) ∂μ = ∫⁻ (a : α), (nnnorm c) * nnnorm (f a) ∂μ :
by simp only [nnnorm_smul, ennreal.coe_mul]
... < ∞ :
begin
rw lintegral_const_mul',
exacts [mul_lt_top coe_ne_top hfi.ne, coe_ne_top]
end
end
lemma has_finite_integral_smul_iff {c : 𝕜} (hc : c ≠ 0) (f : α → β) :
has_finite_integral (c • f) μ ↔ has_finite_integral f μ :=
begin
split,
{ assume h,
simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.smul c⁻¹ },
exact has_finite_integral.smul _
end
lemma has_finite_integral.const_mul {f : α → ℝ} (h : has_finite_integral f μ) (c : ℝ) :
has_finite_integral (λ x, c * f x) μ :=
(has_finite_integral.smul c h : _)
lemma has_finite_integral.mul_const {f : α → ℝ} (h : has_finite_integral f μ) (c : ℝ) :
has_finite_integral (λ x, f x * c) μ :=
by simp_rw [mul_comm, h.const_mul _]
end normed_space
/-! ### The predicate `integrable` -/
variables [measurable_space β] [measurable_space γ] [measurable_space δ]
/-- `integrable f μ` means that `f` is measurable and that the integral `∫⁻ a, ∥f a∥ ∂μ` is finite.
`integrable f` means `integrable f volume`. -/
def integrable {α} {m : measurable_space α} (f : α → β) (μ : measure α . volume_tac) : Prop :=
ae_measurable f μ ∧ has_finite_integral f μ
lemma integrable.ae_measurable {f : α → β} (hf : integrable f μ) : ae_measurable f μ := hf.1
lemma integrable.has_finite_integral {f : α → β} (hf : integrable f μ) : has_finite_integral f μ :=
hf.2
lemma integrable.mono {f : α → β} {g : α → γ} (hg : integrable g μ) (hf : ae_measurable f μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ ∥g a∥) : integrable f μ :=
⟨hf, hg.has_finite_integral.mono h⟩
lemma integrable.mono' {f : α → β} {g : α → ℝ} (hg : integrable g μ) (hf : ae_measurable f μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ ≤ g a) : integrable f μ :=
⟨hf, hg.has_finite_integral.mono' h⟩
lemma integrable.congr' {f : α → β} {g : α → γ} (hf : integrable f μ) (hg : ae_measurable g μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) : integrable g μ :=
⟨hg, hf.has_finite_integral.congr' h⟩
lemma integrable_congr' {f : α → β} {g : α → γ} (hf : ae_measurable f μ) (hg : ae_measurable g μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) : integrable f μ ↔ integrable g μ :=
⟨λ h2f, h2f.congr' hg h, λ h2g, h2g.congr' hf $ eventually_eq.symm h⟩
lemma integrable.congr {f g : α → β} (hf : integrable f μ) (h : f =ᵐ[μ] g) :
integrable g μ :=
⟨hf.1.congr h, hf.2.congr h⟩
lemma integrable_congr {f g : α → β} (h : f =ᵐ[μ] g) :
integrable f μ ↔ integrable g μ :=
⟨λ hf, hf.congr h, λ hg, hg.congr h.symm⟩
lemma integrable_const_iff {c : β} : integrable (λ x : α, c) μ ↔ c = 0 ∨ μ univ < ∞ :=
begin
have : ae_measurable (λ (x : α), c) μ := measurable_const.ae_measurable,
rw [integrable, and_iff_right this, has_finite_integral_const_iff]
end
lemma integrable_const [is_finite_measure μ] (c : β) : integrable (λ x : α, c) μ :=
integrable_const_iff.2 $ or.inr $ measure_lt_top _ _
lemma integrable.mono_measure {f : α → β} (h : integrable f ν) (hμ : μ ≤ ν) : integrable f μ :=
⟨h.ae_measurable.mono_measure hμ, h.has_finite_integral.mono_measure hμ⟩
lemma integrable.add_measure {f : α → β} (hμ : integrable f μ) (hν : integrable f ν) :
integrable f (μ + ν) :=
⟨hμ.ae_measurable.add_measure hν.ae_measurable,
hμ.has_finite_integral.add_measure hν.has_finite_integral⟩
lemma integrable.left_of_add_measure {f : α → β} (h : integrable f (μ + ν)) : integrable f μ :=
h.mono_measure $ measure.le_add_right $ le_refl _
lemma integrable.right_of_add_measure {f : α → β} (h : integrable f (μ + ν)) : integrable f ν :=
h.mono_measure $ measure.le_add_left $ le_refl _
@[simp] lemma integrable_add_measure {f : α → β} :
integrable f (μ + ν) ↔ integrable f μ ∧ integrable f ν :=
⟨λ h, ⟨h.left_of_add_measure, h.right_of_add_measure⟩, λ h, h.1.add_measure h.2⟩
lemma integrable.smul_measure {f : α → β} (h : integrable f μ) {c : ℝ≥0∞} (hc : c ≠ ∞) :
integrable f (c • μ) :=
⟨h.ae_measurable.smul_measure c, h.has_finite_integral.smul_measure hc⟩
lemma integrable_map_measure [opens_measurable_space β] {f : α → δ} {g : δ → β}
(hg : ae_measurable g (measure.map f μ)) (hf : measurable f) :
integrable g (measure.map f μ) ↔ integrable (g ∘ f) μ :=
by simp [integrable, hg, hg.comp_measurable hf, has_finite_integral, lintegral_map' hg.ennnorm hf]
lemma _root_.measurable_embedding.integrable_map_iff {f : α → δ} (hf : measurable_embedding f)
{g : δ → β} :
integrable g (measure.map f μ) ↔ integrable (g ∘ f) μ :=
by simp only [integrable, hf.ae_measurable_map_iff, has_finite_integral, hf.lintegral_map]
lemma integrable_map_equiv (f : α ≃ᵐ δ) (g : δ → β) :
integrable g (measure.map f μ) ↔ integrable (g ∘ f) μ :=
f.measurable_embedding.integrable_map_iff
lemma lintegral_edist_lt_top [second_countable_topology β] [opens_measurable_space β] {f g : α → β}
(hf : integrable f μ) (hg : integrable g μ) :
∫⁻ a, edist (f a) (g a) ∂μ < ∞ :=
lt_of_le_of_lt
(lintegral_edist_triangle hf.ae_measurable hg.ae_measurable
(measurable_const.ae_measurable : ae_measurable (λa, (0 : β)) μ))
(ennreal.add_lt_top.2 $ by { simp_rw ← has_finite_integral_iff_edist,
exact ⟨hf.has_finite_integral, hg.has_finite_integral⟩ })
variables (α β μ)
@[simp] lemma integrable_zero : integrable (λ _, (0 : β)) μ :=
by simp [integrable, measurable_const.ae_measurable]
variables {α β μ}
lemma integrable.add' [opens_measurable_space β] {f g : α → β} (hf : integrable f μ)
(hg : integrable g μ) :
has_finite_integral (f + g) μ :=
calc ∫⁻ a, nnnorm (f a + g a) ∂μ ≤ ∫⁻ a, nnnorm (f a) + nnnorm (g a) ∂μ :
lintegral_mono (λ a, by exact_mod_cast nnnorm_add_le _ _)
... = _ : lintegral_nnnorm_add hf.ae_measurable hg.ae_measurable
... < ∞ : add_lt_top.2 ⟨hf.has_finite_integral, hg.has_finite_integral⟩
lemma integrable.add [borel_space β] [second_countable_topology β]
{f g : α → β} (hf : integrable f μ) (hg : integrable g μ) : integrable (f + g) μ :=
⟨hf.ae_measurable.add hg.ae_measurable, hf.add' hg⟩
lemma integrable_finset_sum {ι} [borel_space β] [second_countable_topology β] (s : finset ι)
{f : ι → α → β} (hf : ∀ i, integrable (f i) μ) : integrable (λ a, ∑ i in s, f i a) μ :=
begin
refine finset.induction_on s _ _,
{ simp only [finset.sum_empty, integrable_zero] },
{ assume i s his ih, simp only [his, finset.sum_insert, not_false_iff],
exact (hf _).add ih }
end
lemma integrable.neg [borel_space β] {f : α → β} (hf : integrable f μ) : integrable (-f) μ :=
⟨hf.ae_measurable.neg, hf.has_finite_integral.neg⟩
@[simp] lemma integrable_neg_iff [borel_space β] {f : α → β} :
integrable (-f) μ ↔ integrable f μ :=
⟨λ h, neg_neg f ▸ h.neg, integrable.neg⟩
lemma integrable.sub' [opens_measurable_space β] {f g : α → β}
(hf : integrable f μ) (hg : integrable g μ) : has_finite_integral (f - g) μ :=
calc ∫⁻ a, nnnorm (f a - g a) ∂μ ≤ ∫⁻ a, nnnorm (f a) + nnnorm (-g a) ∂μ :
lintegral_mono (assume a, by { simp only [sub_eq_add_neg], exact_mod_cast nnnorm_add_le _ _ } )
... = _ :
by { simp only [nnnorm_neg], exact lintegral_nnnorm_add hf.ae_measurable hg.ae_measurable }
... < ∞ : add_lt_top.2 ⟨hf.has_finite_integral, hg.has_finite_integral⟩
lemma integrable.sub [borel_space β] [second_countable_topology β] {f g : α → β}
(hf : integrable f μ) (hg : integrable g μ) : integrable (f - g) μ :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma integrable.norm [opens_measurable_space β] {f : α → β} (hf : integrable f μ) :
integrable (λa, ∥f a∥) μ :=
⟨hf.ae_measurable.norm, hf.has_finite_integral.norm⟩
lemma integrable_norm_iff [opens_measurable_space β] {f : α → β} (hf : ae_measurable f μ) :
integrable (λa, ∥f a∥) μ ↔ integrable f μ :=
by simp_rw [integrable, and_iff_right hf, and_iff_right hf.norm, has_finite_integral_norm_iff]
lemma integrable_of_norm_sub_le [opens_measurable_space β] {f₀ f₁ : α → β} {g : α → ℝ}
(hf₁_m : ae_measurable f₁ μ)
(hf₀_i : integrable f₀ μ)
(hg_i : integrable g μ)
(h : ∀ᵐ a ∂μ, ∥f₀ a - f₁ a∥ ≤ g a) :
integrable f₁ μ :=
begin
have : ∀ᵐ a ∂μ, ∥f₁ a∥ ≤ ∥f₀ a∥ + g a,
{ apply h.mono,
intros a ha,
calc ∥f₁ a∥ ≤ ∥f₀ a∥ + ∥f₀ a - f₁ a∥ : norm_le_insert _ _
... ≤ ∥f₀ a∥ + g a : add_le_add_left ha _ },
exact integrable.mono' (hf₀_i.norm.add hg_i) hf₁_m this
end
lemma integrable.prod_mk [opens_measurable_space β] [opens_measurable_space γ] {f : α → β}
{g : α → γ} (hf : integrable f μ) (hg : integrable g μ) :
integrable (λ x, (f x, g x)) μ :=
⟨hf.ae_measurable.prod_mk hg.ae_measurable,
(hf.norm.add' hg.norm).mono $ eventually_of_forall $ λ x,
calc max ∥f x∥ ∥g x∥ ≤ ∥f x∥ + ∥g x∥ : max_le_add_of_nonneg (norm_nonneg _) (norm_nonneg _)
... ≤ ∥(∥f x∥ + ∥g x∥)∥ : le_abs_self _⟩
lemma mem_ℒp_one_iff_integrable {f : α → β} : mem_ℒp f 1 μ ↔ integrable f μ :=
by simp_rw [integrable, has_finite_integral, mem_ℒp, snorm_one_eq_lintegral_nnnorm]
lemma mem_ℒp.integrable [borel_space β] {q : ℝ≥0∞} (hq1 : 1 ≤ q) {f : α → β} [is_finite_measure μ]
(hfq : mem_ℒp f q μ) : integrable f μ :=
mem_ℒp_one_iff_integrable.mp (hfq.mem_ℒp_of_exponent_le hq1)
lemma lipschitz_with.integrable_comp_iff_of_antilipschitz [complete_space β] [borel_space β]
[borel_space γ] {K K'} {f : α → β} {g : β → γ} (hg : lipschitz_with K g)
(hg' : antilipschitz_with K' g) (g0 : g 0 = 0) :
integrable (g ∘ f) μ ↔ integrable f μ :=
by simp [← mem_ℒp_one_iff_integrable, hg.mem_ℒp_comp_iff_of_antilipschitz hg' g0]
lemma integrable.real_to_nnreal {f : α → ℝ} (hf : integrable f μ) :
integrable (λ x, ((f x).to_nnreal : ℝ)) μ :=
begin
refine ⟨hf.ae_measurable.real_to_nnreal.coe_nnreal_real, _⟩,
rw has_finite_integral_iff_norm,
refine lt_of_le_of_lt _ ((has_finite_integral_iff_norm _).1 hf.has_finite_integral),
apply lintegral_mono,
assume x,
simp [real.norm_eq_abs, ennreal.of_real_le_of_real, abs_le, abs_nonneg, le_abs_self],
end
lemma of_real_to_real_ae_eq {f : α → ℝ≥0∞} (hf : ∀ᵐ x ∂μ, f x < ∞) :
(λ x, ennreal.of_real (f x).to_real) =ᵐ[μ] f :=
begin
rw ae_iff at hf,
rw [filter.eventually_eq, ae_iff],
have : {x | ¬ ennreal.of_real (f x).to_real = f x} = {x | f x = ∞},
{ ext x,
simp only [ne.def, set.mem_set_of_eq],
split; intro hx,
{ by_contra hntop,
exact hx (ennreal.of_real_to_real hntop) },
{ rw hx, simp } },
rw this,
simpa using hf,
end
lemma integrable_with_density_iff {f : α → ℝ≥0∞} (hf : measurable f)
(hflt : ∀ᵐ x ∂μ, f x < ∞) {g : α → ℝ} (hg : measurable g) :
integrable g (μ.with_density f) ↔ integrable (λ x, g x * (f x).to_real) μ :=
begin
simp only [integrable, has_finite_integral, hg.ae_measurable.mul hf.ae_measurable.ennreal_to_real,
hg.ae_measurable, true_and, coe_mul, normed_field.nnnorm_mul],
suffices h_int_eq : ∫⁻ a, ∥g a∥₊ ∂μ.with_density f = ∫⁻ a, ∥g a∥₊ * ∥(f a).to_real∥₊ ∂μ,
by rw h_int_eq,
rw lintegral_with_density_eq_lintegral_mul _ hf hg.nnnorm.coe_nnreal_ennreal,
refine lintegral_congr_ae _,
rw mul_comm,
refine filter.eventually_eq.mul (ae_eq_refl _) ((of_real_to_real_ae_eq hflt).symm.trans _),
convert ae_eq_refl _,
ext1 x,
exact real.ennnorm_eq_of_real ennreal.to_real_nonneg,
end
lemma mem_ℒ1_to_real_of_lintegral_ne_top
{f : α → ℝ≥0∞} (hfm : ae_measurable f μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) :
mem_ℒp (λ x, (f x).to_real) 1 μ :=
begin
rw [mem_ℒp, snorm_one_eq_lintegral_nnnorm],
exact ⟨ae_measurable.ennreal_to_real hfm, has_finite_integral_to_real_of_lintegral_ne_top hfi⟩
end
lemma integrable_to_real_of_lintegral_ne_top
{f : α → ℝ≥0∞} (hfm : ae_measurable f μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) :
integrable (λ x, (f x).to_real) μ :=
mem_ℒp_one_iff_integrable.1 $ mem_ℒ1_to_real_of_lintegral_ne_top hfm hfi
section pos_part
/-! ### Lemmas used for defining the positive part of a `L¹` function -/
lemma integrable.max_zero {f : α → ℝ} (hf : integrable f μ) : integrable (λa, max (f a) 0) μ :=
⟨hf.ae_measurable.max measurable_const.ae_measurable, hf.has_finite_integral.max_zero⟩
lemma integrable.min_zero {f : α → ℝ} (hf : integrable f μ) : integrable (λa, min (f a) 0) μ :=
⟨hf.ae_measurable.min measurable_const.ae_measurable, hf.has_finite_integral.min_zero⟩
end pos_part
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β] [measurable_space 𝕜]
[opens_measurable_space 𝕜]
lemma integrable.smul [borel_space β] (c : 𝕜) {f : α → β}
(hf : integrable f μ) : integrable (c • f) μ :=
⟨hf.ae_measurable.const_smul c, hf.has_finite_integral.smul c⟩
lemma integrable_smul_iff [borel_space β] {c : 𝕜} (hc : c ≠ 0) (f : α → β) :
integrable (c • f) μ ↔ integrable f μ :=
and_congr (ae_measurable_const_smul_iff₀ hc) (has_finite_integral_smul_iff hc f)
lemma integrable.const_mul {f : α → ℝ} (h : integrable f μ) (c : ℝ) :
integrable (λ x, c * f x) μ :=
integrable.smul c h
lemma integrable.mul_const {f : α → ℝ} (h : integrable f μ) (c : ℝ) :
integrable (λ x, f x * c) μ :=
by simp_rw [mul_comm, h.const_mul _]
end normed_space
section normed_space_over_complete_field
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] [complete_space 𝕜] [measurable_space 𝕜]
variables [borel_space 𝕜]
variables {E : Type*} [normed_group E] [normed_space 𝕜 E] [measurable_space E] [borel_space E]
lemma integrable_smul_const {f : α → 𝕜} {c : E} (hc : c ≠ 0) :
integrable (λ x, f x • c) μ ↔ integrable f μ :=
begin
simp_rw [integrable, ae_measurable_smul_const hc, and.congr_right_iff, has_finite_integral,
nnnorm_smul, ennreal.coe_mul],
intro hf, rw [lintegral_mul_const' _ _ ennreal.coe_ne_top, ennreal.mul_lt_top_iff],
have : ∀ x : ℝ≥0∞, x = 0 → x < ∞ := by simp,
simp [hc, or_iff_left_of_imp (this _)]
end
end normed_space_over_complete_field
section is_R_or_C
variables {𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] {f : α → 𝕜}
lemma integrable.of_real [borel_space 𝕜] {f : α → ℝ} (hf : integrable f μ) :
integrable (λ x, (f x : 𝕜)) μ :=
by { rw ← mem_ℒp_one_iff_integrable at hf ⊢, exact hf.of_real }
lemma integrable.re_im_iff [borel_space 𝕜] :
integrable (λ x, is_R_or_C.re (f x)) μ ∧ integrable (λ x, is_R_or_C.im (f x)) μ ↔
integrable f μ :=
by { simp_rw ← mem_ℒp_one_iff_integrable, exact mem_ℒp_re_im_iff }
variable [opens_measurable_space 𝕜]
lemma integrable.re (hf : integrable f μ) : integrable (λ x, is_R_or_C.re (f x)) μ :=
by { rw ← mem_ℒp_one_iff_integrable at hf ⊢, exact hf.re, }
lemma integrable.im (hf : integrable f μ) : integrable (λ x, is_R_or_C.im (f x)) μ :=
by { rw ← mem_ℒp_one_iff_integrable at hf ⊢, exact hf.im, }
end is_R_or_C
section inner_product
variables {𝕜 E : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] [borel_space 𝕜]
[inner_product_space 𝕜 E]
[measurable_space E] [opens_measurable_space E] [second_countable_topology E]
{f : α → E}
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E _ x y
lemma integrable.const_inner (c : E) (hf : integrable f μ) : integrable (λ x, ⟪c, f x⟫) μ :=
by { rw ← mem_ℒp_one_iff_integrable at hf ⊢, exact hf.const_inner c, }
lemma integrable.inner_const (hf : integrable f μ) (c : E) : integrable (λ x, ⟪f x, c⟫) μ :=
by { rw ← mem_ℒp_one_iff_integrable at hf ⊢, exact hf.inner_const c, }
end inner_product
section trim
variables {H : Type*} [normed_group H] [measurable_space H] [opens_measurable_space H]
{m0 : measurable_space α} {μ' : measure α} {f : α → H}
lemma integrable.trim (hm : m ≤ m0) (hf_int : integrable f μ') (hf : @measurable _ _ m _ f) :
integrable f (μ'.trim hm) :=
begin
refine ⟨measurable.ae_measurable hf, _⟩,
rw [has_finite_integral, lintegral_trim hm _],
{ exact hf_int.2, },
{ exact @measurable.coe_nnreal_ennreal α m _ (@measurable.nnnorm _ α _ _ _ m _ hf), },
end
lemma integrable_of_integrable_trim (hm : m ≤ m0) (hf_int : integrable f (μ'.trim hm)) :
integrable f μ' :=
begin
obtain ⟨hf_meas_ae, hf⟩ := hf_int,
refine ⟨ae_measurable_of_ae_measurable_trim hm hf_meas_ae, _⟩,
rw has_finite_integral at hf ⊢,
rwa lintegral_trim_ae hm _ at hf,
exact @ae_measurable.coe_nnreal_ennreal α m _ _
(@ae_measurable.nnnorm H α _ _ _ m _ _ hf_meas_ae),
end
end trim
section sigma_finite
variables {E : Type*} {m0 : measurable_space α} [normed_group E] [measurable_space E]
[opens_measurable_space E]
lemma integrable_of_forall_fin_meas_le' {μ : measure α} (hm : m ≤ m0)
[sigma_finite (μ.trim hm)] (C : ℝ≥0∞) (hC : C < ∞) {f : α → E} (hf_meas : ae_measurable f μ)
(hf : ∀ s, measurable_set[m] s → μ s ≠ ∞ → ∫⁻ x in s, nnnorm (f x) ∂μ ≤ C) :
integrable f μ :=
⟨hf_meas,
(lintegral_le_of_forall_fin_meas_le' hm C hf_meas.nnnorm.coe_nnreal_ennreal hf).trans_lt hC⟩
lemma integrable_of_forall_fin_meas_le [sigma_finite μ]
(C : ℝ≥0∞) (hC : C < ∞) {f : α → E} (hf_meas : ae_measurable f μ)
(hf : ∀ s : set α, measurable_set s → μ s ≠ ∞ → ∫⁻ x in s, nnnorm (f x) ∂μ ≤ C) :
integrable f μ :=
@integrable_of_forall_fin_meas_le' _ _ _ _ _ _ _ _ le_rfl (by rwa trim_eq_self) C hC _ hf_meas hf
end sigma_finite
/-! ### The predicate `integrable` on measurable functions modulo a.e.-equality -/
namespace ae_eq_fun
section
/-- A class of almost everywhere equal functions is `integrable` if its function representative
is integrable. -/
def integrable (f : α →ₘ[μ] β) : Prop := integrable f μ
lemma integrable_mk {f : α → β} (hf : ae_measurable f μ ) :
(integrable (mk f hf : α →ₘ[μ] β)) ↔ measure_theory.integrable f μ :=
begin
simp [integrable],
apply integrable_congr,
exact coe_fn_mk f hf
end
lemma integrable_coe_fn {f : α →ₘ[μ] β} : (measure_theory.integrable f μ) ↔ integrable f :=
by rw [← integrable_mk, mk_coe_fn]
lemma integrable_zero : integrable (0 : α →ₘ[μ] β) :=
(integrable_zero α β μ).congr (coe_fn_mk _ _).symm
end
section
variables [borel_space β]
lemma integrable.neg {f : α →ₘ[μ] β} : integrable f → integrable (-f) :=
induction_on f $ λ f hfm hfi, (integrable_mk _).2 ((integrable_mk hfm).1 hfi).neg
section
variable [second_countable_topology β]
lemma integrable_iff_mem_L1 {f : α →ₘ[μ] β} : integrable f ↔ f ∈ (α →₁[μ] β) :=
by rw [← integrable_coe_fn, ← mem_ℒp_one_iff_integrable, Lp.mem_Lp_iff_mem_ℒp]
lemma integrable.add {f g : α →ₘ[μ] β} : integrable f → integrable g → integrable (f + g) :=
begin
refine induction_on₂ f g (λ f hf g hg hfi hgi, _),
simp only [integrable_mk, mk_add_mk] at hfi hgi ⊢,
exact hfi.add hgi
end
lemma integrable.sub {f g : α →ₘ[μ] β} (hf : integrable f) (hg : integrable g) :
integrable (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add hg.neg
end
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β] [measurable_space 𝕜]
[opens_measurable_space 𝕜]
lemma integrable.smul {c : 𝕜} {f : α →ₘ[μ] β} : integrable f → integrable (c • f) :=
induction_on f $ λ f hfm hfi, (integrable_mk _).2 $ ((integrable_mk hfm).1 hfi).smul _
end normed_space
end
end ae_eq_fun
namespace L1
variables [second_countable_topology β] [borel_space β]
lemma integrable_coe_fn (f : α →₁[μ] β) :
integrable f μ :=
by { rw ← mem_ℒp_one_iff_integrable, exact Lp.mem_ℒp f }
lemma has_finite_integral_coe_fn (f : α →₁[μ] β) :
has_finite_integral f μ :=
(integrable_coe_fn f).has_finite_integral
lemma measurable_coe_fn (f : α →₁[μ] β) :
measurable f := Lp.measurable f
lemma ae_measurable_coe_fn (f : α →₁[μ] β) :
ae_measurable f μ := Lp.ae_measurable f
lemma edist_def (f g : α →₁[μ] β) :
edist f g = ∫⁻ a, edist (f a) (g a) ∂μ :=
by { simp [Lp.edist_def, snorm, snorm'], simp [edist_eq_coe_nnnorm_sub] }
lemma dist_def (f g : α →₁[μ] β) :
dist f g = (∫⁻ a, edist (f a) (g a) ∂μ).to_real :=
by { simp [Lp.dist_def, snorm, snorm'], simp [edist_eq_coe_nnnorm_sub] }
lemma norm_def (f : α →₁[μ] β) :
∥f∥ = (∫⁻ a, nnnorm (f a) ∂μ).to_real :=
by { simp [Lp.norm_def, snorm, snorm'] }
/-- Computing the norm of a difference between two L¹-functions. Note that this is not a
special case of `norm_def` since `(f - g) x` and `f x - g x` are not equal
(but only a.e.-equal). -/
lemma norm_sub_eq_lintegral (f g : α →₁[μ] β) :
∥f - g∥ = (∫⁻ x, (nnnorm (f x - g x) : ℝ≥0∞) ∂μ).to_real :=
begin
rw [norm_def],
congr' 1,
rw lintegral_congr_ae,
filter_upwards [Lp.coe_fn_sub f g],
assume a ha,
simp only [ha, pi.sub_apply],
end
lemma of_real_norm_eq_lintegral (f : α →₁[μ] β) :
ennreal.of_real ∥f∥ = ∫⁻ x, (nnnorm (f x) : ℝ≥0∞) ∂μ :=
by { rw [norm_def, ennreal.of_real_to_real], exact ne_of_lt (has_finite_integral_coe_fn f) }
/-- Computing the norm of a difference between two L¹-functions. Note that this is not a
special case of `of_real_norm_eq_lintegral` since `(f - g) x` and `f x - g x` are not equal
(but only a.e.-equal). -/
lemma of_real_norm_sub_eq_lintegral (f g : α →₁[μ] β) :
ennreal.of_real ∥f - g∥ = ∫⁻ x, (nnnorm (f x - g x) : ℝ≥0∞) ∂μ :=
begin
simp_rw [of_real_norm_eq_lintegral, ← edist_eq_coe_nnnorm],
apply lintegral_congr_ae,
filter_upwards [Lp.coe_fn_sub f g],
assume a ha,
simp only [ha, pi.sub_apply],
end
end L1
namespace integrable
variables [second_countable_topology β] [borel_space β]
/-- Construct the equivalence class `[f]` of an integrable function `f`, as a member of the
space `L1 β 1 μ`. -/
def to_L1 (f : α → β) (hf : integrable f μ) : α →₁[μ] β :=
(mem_ℒp_one_iff_integrable.2 hf).to_Lp f
@[simp] lemma to_L1_coe_fn (f : α →₁[μ] β) (hf : integrable f μ) : hf.to_L1 f = f :=
by simp [integrable.to_L1]
lemma coe_fn_to_L1 {f : α → β} (hf : integrable f μ) : hf.to_L1 f =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk _ _
@[simp] lemma to_L1_zero (h : integrable (0 : α → β) μ) : h.to_L1 0 = 0 := rfl
@[simp] lemma to_L1_eq_mk (f : α → β) (hf : integrable f μ) :
(hf.to_L1 f : α →ₘ[μ] β) = ae_eq_fun.mk f hf.ae_measurable :=
rfl
@[simp] lemma to_L1_eq_to_L1_iff (f g : α → β) (hf : integrable f μ) (hg : integrable g μ) :
to_L1 f hf = to_L1 g hg ↔ f =ᵐ[μ] g :=
mem_ℒp.to_Lp_eq_to_Lp_iff _ _
lemma to_L1_add (f g : α → β) (hf : integrable f μ) (hg : integrable g μ) :
to_L1 (f + g) (hf.add hg) = to_L1 f hf + to_L1 g hg := rfl
lemma to_L1_neg (f : α → β) (hf : integrable f μ) :
to_L1 (- f) (integrable.neg hf) = - to_L1 f hf := rfl
lemma to_L1_sub (f g : α → β) (hf : integrable f μ) (hg : integrable g μ) :
to_L1 (f - g) (hf.sub hg) = to_L1 f hf - to_L1 g hg := rfl
lemma norm_to_L1 (f : α → β) (hf : integrable f μ) :
∥hf.to_L1 f∥ = ennreal.to_real (∫⁻ a, edist (f a) 0 ∂μ) :=
by { simp [to_L1, snorm, snorm'], simp [edist_eq_coe_nnnorm] }
lemma norm_to_L1_eq_lintegral_norm (f : α → β) (hf : integrable f μ) :
∥hf.to_L1 f∥ = ennreal.to_real (∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ) :=
by { rw [norm_to_L1, lintegral_norm_eq_lintegral_edist] }
@[simp] lemma edist_to_L1_to_L1 (f g : α → β) (hf : integrable f μ) (hg : integrable g μ) :
edist (hf.to_L1 f) (hg.to_L1 g) = ∫⁻ a, edist (f a) (g a) ∂μ :=
by { simp [integrable.to_L1, snorm, snorm'], simp [edist_eq_coe_nnnorm_sub] }
@[simp] lemma edist_to_L1_zero (f : α → β) (hf : integrable f μ) :
edist (hf.to_L1 f) 0 = ∫⁻ a, edist (f a) 0 ∂μ :=
by { simp [integrable.to_L1, snorm, snorm'], simp [edist_eq_coe_nnnorm] }
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β] [measurable_space 𝕜]
[opens_measurable_space 𝕜]
lemma to_L1_smul (f : α → β) (hf : integrable f μ) (k : 𝕜) :
to_L1 (λ a, k • f a) (hf.smul k) = k • to_L1 f hf := rfl
lemma to_L1_smul' (f : α → β) (hf : integrable f μ) (k : 𝕜) :
to_L1 (k • f) (hf.smul k) = k • to_L1 f hf := rfl
end integrable
end measure_theory
open measure_theory
lemma integrable_zero_measure {m : measurable_space α} [measurable_space β] {f : α → β} :
integrable f (0 : measure α) :=
begin
apply (integrable_zero _ _ _).congr,
change (0 : measure α) {x | 0 ≠ f x} = 0,
refl,
end
variables {E : Type*} [normed_group E] [measurable_space E] [borel_space E] [normed_space ℝ E]
{H : Type*} [normed_group H] [normed_space ℝ H]
lemma measure_theory.integrable.apply_continuous_linear_map {φ : α → H →L[ℝ] E}
(φ_int : integrable φ μ) (v : H) : integrable (λ a, φ a v) μ :=
(φ_int.norm.mul_const ∥v∥).mono' (φ_int.ae_measurable.apply_continuous_linear_map v)
(eventually_of_forall $ λ a, (φ a).le_op_norm v)
variables {𝕜 : Type*} [is_R_or_C 𝕜]
{G : Type*} [normed_group G] [normed_space 𝕜 G] [measurable_space G] [borel_space G]
{F : Type*} [normed_group F] [normed_space 𝕜 F] [measurable_space F] [opens_measurable_space F]
lemma continuous_linear_map.integrable_comp {φ : α → F} (L : F →L[𝕜] G)
(φ_int : integrable φ μ) : integrable (λ (a : α), L (φ a)) μ :=
((integrable.norm φ_int).const_mul ∥L∥).mono' (L.measurable.comp_ae_measurable φ_int.ae_measurable)
(eventually_of_forall $ λ a, L.le_op_norm (φ a))
|
9f20325cda59d22540ccfbdebdc852090758547e
|
b19a1b7dc79c802247fdce4c04708e070863b4d2
|
/evaluate.lean
|
e47ac6706fa7f7bd21ed3726f472fc9f36e0cfa0
|
[] |
no_license
|
utanapishtim/promethazine
|
99a1e80311fb20251a54ba78a534b23852b88c40
|
08a6f9bd6dd08feb3df8d4697e19ffc8d333b249
|
refs/heads/master
| 1,653,595,504,487
| 1,480,129,933,000
| 1,480,129,933,000
| 74,801,596
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 690
|
lean
|
import data.nat data.prod data.bool
open nat prod bool
constants m n : nat
constant b : bool
print "reducing pairs"
eval pr1 (pair m n) -- m
eval pr2 (pair m n) -- n
print "reducing boolean expressions"
eval tt && ff -- ff
eval b && ff -- ff
print "reducing arithmetic expressions"
eval n + 0 -- n
eval n + 2 -- succ (succ n)
eval (2 : nat) + 3 -- 5
constants A B C : Type
constants (a : A) (f : A → B) (g : B → C) (h : A → A)
definition gfa : C := g (f a)
check gfa
print gfa
definition gfa' := g (f a)
check gfa'
print gfa'
definition gfha := g (f (h a))
check gfha
print gfha
definition g_comp_f : A → C : λ x, g (f x)
check g_comp_f
print g_comp_f
|
671ed83f79f918ab4a5cb098d8063b9bd8051686
|
32da3d0f92cab08875472ef6cacc1931c2b3eafa
|
/src/data/nat/basic.lean
|
7f1de25fd136b2766576774aaf908f3c917d6e70
|
[
"Apache-2.0"
] |
permissive
|
karthiknadig/mathlib
|
b6073c3748860bfc9a3e55da86afcddba62dc913
|
33a86cfff12d7f200d0010cd03b95e9b69a6c1a5
|
refs/heads/master
| 1,676,389,371,851
| 1,610,061,127,000
| 1,610,061,127,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 63,077
|
lean
|
/-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import algebra.group_power.basic
import algebra.order_functions
/-!
# Basic operations on the natural numbers
This file contains:
- instances on the natural numbers
- some basic lemmas about natural numbers
- extra recursors:
* `le_rec_on`, `le_induction`: recursion and induction principles starting at non-zero numbers
* `decreasing_induction`: recursion growing downwards
* `strong_rec'`: recursion based on strong inequalities
- decidability instances on predicates about the natural numbers
-/
universes u v
/-! ### instances -/
instance : nontrivial ℕ :=
⟨⟨0, 1, nat.zero_ne_one⟩⟩
instance : comm_semiring nat :=
{ add := nat.add,
add_assoc := nat.add_assoc,
zero := nat.zero,
zero_add := nat.zero_add,
add_zero := nat.add_zero,
add_comm := nat.add_comm,
mul := nat.mul,
mul_assoc := nat.mul_assoc,
one := nat.succ nat.zero,
one_mul := nat.one_mul,
mul_one := nat.mul_one,
left_distrib := nat.left_distrib,
right_distrib := nat.right_distrib,
zero_mul := nat.zero_mul,
mul_zero := nat.mul_zero,
mul_comm := nat.mul_comm }
instance : linear_ordered_semiring nat :=
{ add_left_cancel := @nat.add_left_cancel,
add_right_cancel := @nat.add_right_cancel,
lt := nat.lt,
add_le_add_left := @nat.add_le_add_left,
le_of_add_le_add_left := @nat.le_of_add_le_add_left,
zero_le_one := nat.le_of_lt (nat.zero_lt_succ 0),
mul_lt_mul_of_pos_left := @nat.mul_lt_mul_of_pos_left,
mul_lt_mul_of_pos_right := @nat.mul_lt_mul_of_pos_right,
decidable_eq := nat.decidable_eq,
exists_pair_ne := ⟨0, 1, ne_of_lt nat.zero_lt_one⟩,
..nat.comm_semiring, ..nat.linear_order }
-- all the fields are already included in the linear_ordered_semiring instance
instance : linear_ordered_cancel_add_comm_monoid ℕ :=
{ add_left_cancel := @nat.add_left_cancel,
..nat.linear_ordered_semiring }
/-! Extra instances to short-circuit type class resolution -/
instance : add_comm_monoid nat := by apply_instance
instance : add_monoid nat := by apply_instance
instance : monoid nat := by apply_instance
instance : comm_monoid nat := by apply_instance
instance : comm_semigroup nat := by apply_instance
instance : semigroup nat := by apply_instance
instance : add_comm_semigroup nat := by apply_instance
instance : add_semigroup nat := by apply_instance
instance : distrib nat := by apply_instance
instance : semiring nat := by apply_instance
instance : ordered_semiring nat := by apply_instance
instance : canonically_ordered_comm_semiring ℕ :=
{ le_iff_exists_add := assume a b,
⟨assume h, let ⟨c, hc⟩ := nat.le.dest h in ⟨c, hc.symm⟩,
assume ⟨c, hc⟩, hc.symm ▸ nat.le_add_right _ _⟩,
eq_zero_or_eq_zero_of_mul_eq_zero := assume a b, nat.eq_zero_of_mul_eq_zero,
bot := 0,
bot_le := nat.zero_le,
.. nat.nontrivial,
.. (infer_instance : ordered_add_comm_monoid ℕ),
.. (infer_instance : linear_ordered_semiring ℕ),
.. (infer_instance : comm_semiring ℕ) }
instance nat.subtype.semilattice_sup_bot (s : set ℕ) [decidable_pred s] [h : nonempty s] :
semilattice_sup_bot s :=
{ bot := ⟨nat.find (nonempty_subtype.1 h), nat.find_spec (nonempty_subtype.1 h)⟩,
bot_le := λ x, nat.find_min' _ x.2,
..subtype.linear_order s,
..lattice_of_linear_order }
theorem nat.eq_of_mul_eq_mul_right {n m k : ℕ} (Hm : 0 < m) (H : n * m = k * m) : n = k :=
by rw [mul_comm n m, mul_comm k m] at H; exact nat.eq_of_mul_eq_mul_left Hm H
instance nat.comm_cancel_monoid_with_zero : comm_cancel_monoid_with_zero ℕ :=
{ mul_left_cancel_of_ne_zero := λ _ _ _ h1 h2, nat.eq_of_mul_eq_mul_left (nat.pos_of_ne_zero h1) h2,
mul_right_cancel_of_ne_zero := λ _ _ _ h1 h2, nat.eq_of_mul_eq_mul_right (nat.pos_of_ne_zero h1) h2,
.. (infer_instance : comm_monoid_with_zero ℕ) }
/-!
Inject some simple facts into the type class system.
This `fact` should not be confused with the factorial function `nat.fact`!
-/
section facts
instance succ_pos'' (n : ℕ) : fact (0 < n.succ) := n.succ_pos
instance pos_of_one_lt (n : ℕ) [h : fact (1 < n)] : fact (0 < n) :=
lt_trans zero_lt_one h
end facts
variables {m n k : ℕ}
namespace nat
/-!
### Recursion and `set.range`
-/
section set
open set
theorem zero_union_range_succ : {0} ∪ range succ = univ :=
by { ext n, cases n; simp }
variables {α : Type*}
theorem range_of_succ (f : ℕ → α) : {f 0} ∪ range (f ∘ succ) = range f :=
by rw [← image_singleton, range_comp, ← image_union, zero_union_range_succ, image_univ]
theorem range_rec {α : Type*} (x : α) (f : ℕ → α → α) :
(set.range (λ n, nat.rec x f n) : set α) =
{x} ∪ set.range (λ n, nat.rec (f 0 x) (f ∘ succ) n) :=
begin
convert (range_of_succ _).symm,
ext n,
induction n with n ihn,
{ refl },
{ dsimp at ihn ⊢,
rw ihn }
end
theorem range_cases_on {α : Type*} (x : α) (f : ℕ → α) :
(set.range (λ n, nat.cases_on n x f) : set α) = {x} ∪ set.range f :=
(range_of_succ _).symm
end set
/-! ### The units of the natural numbers as a `monoid` and `add_monoid` -/
theorem units_eq_one (u : units ℕ) : u = 1 :=
units.ext $ nat.eq_one_of_dvd_one ⟨u.inv, u.val_inv.symm⟩
theorem add_units_eq_zero (u : add_units ℕ) : u = 0 :=
add_units.ext $ (nat.eq_zero_of_add_eq_zero u.val_neg).1
@[simp] protected theorem is_unit_iff {n : ℕ} : is_unit n ↔ n = 1 :=
iff.intro
(assume ⟨u, hu⟩, match n, u, hu, nat.units_eq_one u with _, _, rfl, rfl := rfl end)
(assume h, h.symm ▸ ⟨1, rfl⟩)
/-! ### Equalities and inequalities involving zero and one -/
theorem pos_iff_ne_zero : 0 < n ↔ n ≠ 0 :=
⟨ne_of_gt, nat.pos_of_ne_zero⟩
lemma one_lt_iff_ne_zero_and_ne_one : ∀ {n : ℕ}, 1 < n ↔ n ≠ 0 ∧ n ≠ 1
| 0 := dec_trivial
| 1 := dec_trivial
| (n+2) := dec_trivial
protected theorem mul_ne_zero {n m : ℕ} (n0 : n ≠ 0) (m0 : m ≠ 0) : n * m ≠ 0
| nm := (eq_zero_of_mul_eq_zero nm).elim n0 m0
@[simp] protected theorem mul_eq_zero {a b : ℕ} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
iff.intro eq_zero_of_mul_eq_zero (by simp [or_imp_distrib] {contextual := tt})
@[simp] protected theorem zero_eq_mul {a b : ℕ} : 0 = a * b ↔ a = 0 ∨ b = 0 :=
by rw [eq_comm, nat.mul_eq_zero]
lemma eq_zero_of_double_le {a : ℕ} (h : 2 * a ≤ a) : a = 0 :=
nat.eq_zero_of_le_zero $
by rwa [two_mul, nat.add_le_to_le_sub, nat.sub_self] at h; refl
lemma eq_zero_of_mul_le {a b : ℕ} (hb : 2 ≤ b) (h : b * a ≤ a) : a = 0 :=
eq_zero_of_double_le $ le_trans (nat.mul_le_mul_right _ hb) h
theorem le_zero_iff {i : ℕ} : i ≤ 0 ↔ i = 0 :=
⟨nat.eq_zero_of_le_zero, assume h, h ▸ le_refl i⟩
lemma zero_max {m : ℕ} : max 0 m = m :=
max_eq_right (zero_le _)
lemma one_le_of_lt {n m : ℕ} (h : n < m) : 1 ≤ m :=
lt_of_le_of_lt (nat.zero_le _) h
theorem eq_one_of_mul_eq_one_right {m n : ℕ} (H : m * n = 1) : m = 1 :=
eq_one_of_dvd_one ⟨n, H.symm⟩
theorem eq_one_of_mul_eq_one_left {m n : ℕ} (H : m * n = 1) : n = 1 :=
eq_one_of_mul_eq_one_right (by rwa mul_comm)
/-! ### `succ` -/
theorem eq_of_lt_succ_of_not_lt {a b : ℕ} (h1 : a < b + 1) (h2 : ¬ a < b) : a = b :=
have h3 : a ≤ b, from le_of_lt_succ h1,
or.elim (eq_or_lt_of_not_lt h2) (λ h, h) (λ h, absurd h (not_lt_of_ge h3))
theorem one_add (n : ℕ) : 1 + n = succ n := by simp [add_comm]
@[simp] lemma succ_pos' {n : ℕ} : 0 < succ n := succ_pos n
theorem succ_inj' {n m : ℕ} : succ n = succ m ↔ n = m :=
⟨succ.inj, congr_arg _⟩
theorem succ_injective : function.injective nat.succ := λ x y, succ.inj
theorem succ_le_succ_iff {m n : ℕ} : succ m ≤ succ n ↔ m ≤ n :=
⟨le_of_succ_le_succ, succ_le_succ⟩
theorem max_succ_succ {m n : ℕ} :
max (succ m) (succ n) = succ (max m n) :=
begin
by_cases h1 : m ≤ n,
rw [max_eq_right h1, max_eq_right (succ_le_succ h1)],
{ rw not_le at h1, have h2 := le_of_lt h1,
rw [max_eq_left h2, max_eq_left (succ_le_succ h2)] }
end
lemma not_succ_lt_self {n : ℕ} : ¬succ n < n :=
not_lt_of_ge (nat.le_succ _)
theorem lt_succ_iff {m n : ℕ} : m < succ n ↔ m ≤ n :=
succ_le_succ_iff
lemma succ_le_iff {m n : ℕ} : succ m ≤ n ↔ m < n :=
⟨lt_of_succ_le, succ_le_of_lt⟩
lemma lt_iff_add_one_le {m n : ℕ} : m < n ↔ m + 1 ≤ n :=
by rw succ_le_iff
-- Just a restatement of `nat.lt_succ_iff` using `+1`.
lemma lt_add_one_iff {a b : ℕ} : a < b + 1 ↔ a ≤ b :=
lt_succ_iff
-- A flipped version of `lt_add_one_iff`.
lemma lt_one_add_iff {a b : ℕ} : a < 1 + b ↔ a ≤ b :=
by simp only [add_comm, lt_succ_iff]
-- This is true reflexively, by the definition of `≤` on ℕ,
-- but it's still useful to have, to convince Lean to change the syntactic type.
lemma add_one_le_iff {a b : ℕ} : a + 1 ≤ b ↔ a < b :=
iff.refl _
lemma one_add_le_iff {a b : ℕ} : 1 + a ≤ b ↔ a < b :=
by simp only [add_comm, add_one_le_iff]
theorem of_le_succ {n m : ℕ} (H : n ≤ m.succ) : n ≤ m ∨ n = m.succ :=
(lt_or_eq_of_le H).imp le_of_lt_succ id
lemma succ_lt_succ_iff {m n : ℕ} : succ m < succ n ↔ m < n :=
⟨lt_of_succ_lt_succ, succ_lt_succ⟩
/-! ### `add` -/
-- Sometimes a bare `nat.add` or similar appears as a consequence of unfolding
-- during pattern matching. These lemmas package them back up as typeclass
-- mediated operations.
@[simp] theorem add_def {a b : ℕ} : nat.add a b = a + b := rfl
@[simp] theorem mul_def {a b : ℕ} : nat.mul a b = a * b := rfl
attribute [simp] nat.add_sub_cancel nat.add_sub_cancel_left
attribute [simp] nat.sub_self
lemma exists_eq_add_of_le : ∀ {m n : ℕ}, m ≤ n → ∃ k : ℕ, n = m + k
| 0 0 h := ⟨0, by simp⟩
| 0 (n+1) h := ⟨n+1, by simp⟩
| (m+1) (n+1) h :=
let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in
⟨k, by simp [hk, add_comm, add_left_comm]⟩
lemma exists_eq_add_of_lt : ∀ {m n : ℕ}, m < n → ∃ k : ℕ, n = m + k + 1
| 0 0 h := false.elim $ lt_irrefl _ h
| 0 (n+1) h := ⟨n, by simp⟩
| (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in
⟨k, by simp [hk]⟩
theorem add_pos_left {m : ℕ} (h : 0 < m) (n : ℕ) : 0 < m + n :=
calc
m + n > 0 + n : nat.add_lt_add_right h n
... = n : nat.zero_add n
... ≥ 0 : zero_le n
theorem add_pos_right (m : ℕ) {n : ℕ} (h : 0 < n) : 0 < m + n :=
begin rw add_comm, exact add_pos_left h m end
theorem add_pos_iff_pos_or_pos (m n : ℕ) : 0 < m + n ↔ 0 < m ∨ 0 < n :=
iff.intro
begin
intro h,
cases m with m,
{simp [zero_add] at h, exact or.inr h},
exact or.inl (succ_pos _)
end
begin
intro h, cases h with mpos npos,
{ apply add_pos_left mpos },
apply add_pos_right _ npos
end
lemma add_eq_one_iff : ∀ {a b : ℕ}, a + b = 1 ↔ (a = 0 ∧ b = 1) ∨ (a = 1 ∧ b = 0)
| 0 0 := dec_trivial
| 0 1 := dec_trivial
| 1 0 := dec_trivial
| 1 1 := dec_trivial
| (a+2) _ := by rw add_right_comm; exact dec_trivial
| _ (b+2) := by rw [← add_assoc]; simp only [nat.succ_inj', nat.succ_ne_zero]; simp
theorem le_add_one_iff {i j : ℕ} : i ≤ j + 1 ↔ (i ≤ j ∨ i = j + 1) :=
⟨assume h,
match nat.eq_or_lt_of_le h with
| or.inl h := or.inr h
| or.inr h := or.inl $ nat.le_of_succ_le_succ h
end,
or.rec (assume h, le_trans h $ nat.le_add_right _ _) le_of_eq⟩
lemma add_succ_lt_add {a b c d : ℕ} (hab : a < b) (hcd : c < d) : a + c + 1 < b + d :=
begin
rw add_assoc,
exact add_lt_add_of_lt_of_le hab (nat.succ_le_iff.2 hcd)
end
/-! ### `pred` -/
@[simp]
lemma add_succ_sub_one (n m : ℕ) : (n + succ m) - 1 = n + m :=
by rw [add_succ, succ_sub_one]
@[simp]
lemma succ_add_sub_one (n m : ℕ) : (succ n + m) - 1 = n + m :=
by rw [succ_add, succ_sub_one]
lemma pred_eq_sub_one (n : ℕ) : pred n = n - 1 := rfl
theorem pred_eq_of_eq_succ {m n : ℕ} (H : m = n.succ) : m.pred = n := by simp [H]
@[simp] lemma pred_eq_succ_iff {n m : ℕ} : pred n = succ m ↔ n = m + 2 :=
by cases n; split; rintro ⟨⟩; refl
theorem pred_sub (n m : ℕ) : pred n - m = pred (n - m) :=
by rw [← sub_one, nat.sub_sub, one_add]; refl
lemma le_pred_of_lt {n m : ℕ} (h : m < n) : m ≤ n - 1 :=
nat.sub_le_sub_right h 1
lemma le_of_pred_lt {m n : ℕ} : pred m < n → m ≤ n :=
match m with
| 0 := le_of_lt
| m+1 := id
end
/-- This ensures that `simp` succeeds on `pred (n + 1) = n`. -/
@[simp] lemma pred_one_add (n : ℕ) : pred (1 + n) = n :=
by rw [add_comm, add_one, pred_succ]
/-! ### `sub` -/
protected theorem le_sub_add (n m : ℕ) : n ≤ n - m + m :=
or.elim (le_total n m)
(assume : n ≤ m, begin rw [sub_eq_zero_of_le this, zero_add], exact this end)
(assume : m ≤ n, begin rw (nat.sub_add_cancel this) end)
theorem sub_add_eq_max (n m : ℕ) : n - m + m = max n m :=
eq_max (nat.le_sub_add _ _) (le_add_left _ _) $ λ k h₁ h₂,
by rw ← nat.sub_add_cancel h₂; exact
add_le_add_right (nat.sub_le_sub_right h₁ _) _
theorem add_sub_eq_max (n m : ℕ) : n + (m - n) = max n m :=
by rw [add_comm, max_comm, sub_add_eq_max]
theorem sub_add_min (n m : ℕ) : n - m + min n m = n :=
(le_total n m).elim
(λ h, by rw [min_eq_left h, sub_eq_zero_of_le h, zero_add])
(λ h, by rw [min_eq_right h, nat.sub_add_cancel h])
protected theorem add_sub_cancel' {n m : ℕ} (h : m ≤ n) : m + (n - m) = n :=
by rw [add_comm, nat.sub_add_cancel h]
protected theorem sub_add_sub_cancel {a b c : ℕ} (hab : b ≤ a) (hbc : c ≤ b) :
(a - b) + (b - c) = a - c :=
by rw [←nat.add_sub_assoc hbc, ←nat.sub_add_comm hab, nat.add_sub_cancel]
protected theorem sub_eq_of_eq_add (h : k = m + n) : k - m = n :=
begin rw [h, nat.add_sub_cancel_left] end
theorem sub_cancel {a b c : ℕ} (h₁ : a ≤ b) (h₂ : a ≤ c) (w : b - a = c - a) : b = c :=
by rw [←nat.sub_add_cancel h₁, ←nat.sub_add_cancel h₂, w]
lemma sub_sub_sub_cancel_right {a b c : ℕ} (h₂ : c ≤ b) : (a - c) - (b - c) = a - b :=
by rw [nat.sub_sub, ←nat.add_sub_assoc h₂, nat.add_sub_cancel_left]
lemma add_sub_cancel_right (n m k : ℕ) : n + (m + k) - k = n + m :=
by { rw [nat.add_sub_assoc, nat.add_sub_cancel], apply k.le_add_left }
protected lemma sub_add_eq_add_sub {a b c : ℕ} (h : b ≤ a) : (a - b) + c = (a + c) - b :=
by rw [add_comm a, nat.add_sub_assoc h, add_comm]
theorem sub_min (n m : ℕ) : n - min n m = n - m :=
nat.sub_eq_of_eq_add $ by rw [add_comm, sub_add_min]
theorem sub_sub_assoc {a b c : ℕ} (h₁ : b ≤ a) (h₂ : c ≤ b) : a - (b - c) = a - b + c :=
(nat.sub_eq_iff_eq_add (le_trans (nat.sub_le _ _) h₁)).2 $
by rw [add_right_comm, add_assoc, nat.sub_add_cancel h₂, nat.sub_add_cancel h₁]
protected theorem lt_of_sub_pos (h : 0 < n - m) : m < n :=
lt_of_not_ge
(assume : n ≤ m,
have n - m = 0, from sub_eq_zero_of_le this,
begin rw this at h, exact lt_irrefl _ h end)
protected theorem lt_of_sub_lt_sub_right : m - k < n - k → m < n :=
lt_imp_lt_of_le_imp_le (λ h, nat.sub_le_sub_right h _)
protected theorem lt_of_sub_lt_sub_left : m - n < m - k → k < n :=
lt_imp_lt_of_le_imp_le (nat.sub_le_sub_left _)
protected theorem sub_lt_self (h₁ : 0 < m) (h₂ : 0 < n) : m - n < m :=
calc
m - n = succ (pred m) - succ (pred n) : by rw [succ_pred_eq_of_pos h₁, succ_pred_eq_of_pos h₂]
... = pred m - pred n : by rw succ_sub_succ
... ≤ pred m : sub_le _ _
... < succ (pred m) : lt_succ_self _
... = m : succ_pred_eq_of_pos h₁
protected theorem le_sub_right_of_add_le (h : m + k ≤ n) : m ≤ n - k :=
by rw ← nat.add_sub_cancel m k; exact nat.sub_le_sub_right h k
protected theorem le_sub_left_of_add_le (h : k + m ≤ n) : m ≤ n - k :=
nat.le_sub_right_of_add_le (by rwa add_comm at h)
protected theorem lt_sub_right_of_add_lt (h : m + k < n) : m < n - k :=
lt_of_succ_le $ nat.le_sub_right_of_add_le $
by rw succ_add; exact succ_le_of_lt h
protected theorem lt_sub_left_of_add_lt (h : k + m < n) : m < n - k :=
nat.lt_sub_right_of_add_lt (by rwa add_comm at h)
protected theorem add_lt_of_lt_sub_right (h : m < n - k) : m + k < n :=
@nat.lt_of_sub_lt_sub_right _ _ k (by rwa nat.add_sub_cancel)
protected theorem add_lt_of_lt_sub_left (h : m < n - k) : k + m < n :=
by rw add_comm; exact nat.add_lt_of_lt_sub_right h
protected theorem le_add_of_sub_le_right : n - k ≤ m → n ≤ m + k :=
le_imp_le_of_lt_imp_lt nat.lt_sub_right_of_add_lt
protected theorem le_add_of_sub_le_left : n - k ≤ m → n ≤ k + m :=
le_imp_le_of_lt_imp_lt nat.lt_sub_left_of_add_lt
protected theorem lt_add_of_sub_lt_right : n - k < m → n < m + k :=
lt_imp_lt_of_le_imp_le nat.le_sub_right_of_add_le
protected theorem lt_add_of_sub_lt_left : n - k < m → n < k + m :=
lt_imp_lt_of_le_imp_le nat.le_sub_left_of_add_le
protected theorem sub_le_left_of_le_add : n ≤ k + m → n - k ≤ m :=
le_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_left
protected theorem sub_le_right_of_le_add : n ≤ m + k → n - k ≤ m :=
le_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_right
protected theorem sub_lt_left_iff_lt_add (H : n ≤ k) : k - n < m ↔ k < n + m :=
⟨nat.lt_add_of_sub_lt_left,
λ h₁,
have succ k ≤ n + m, from succ_le_of_lt h₁,
have succ (k - n) ≤ m, from
calc succ (k - n) = succ k - n : by rw (succ_sub H)
... ≤ n + m - n : nat.sub_le_sub_right this n
... = m : by rw nat.add_sub_cancel_left,
lt_of_succ_le this⟩
protected theorem le_sub_left_iff_add_le (H : m ≤ k) : n ≤ k - m ↔ m + n ≤ k :=
le_iff_le_iff_lt_iff_lt.2 (nat.sub_lt_left_iff_lt_add H)
protected theorem le_sub_right_iff_add_le (H : n ≤ k) : m ≤ k - n ↔ m + n ≤ k :=
by rw [nat.le_sub_left_iff_add_le H, add_comm]
protected theorem lt_sub_left_iff_add_lt : n < k - m ↔ m + n < k :=
⟨nat.add_lt_of_lt_sub_left, nat.lt_sub_left_of_add_lt⟩
protected theorem lt_sub_right_iff_add_lt : m < k - n ↔ m + n < k :=
by rw [nat.lt_sub_left_iff_add_lt, add_comm]
theorem sub_le_left_iff_le_add : m - n ≤ k ↔ m ≤ n + k :=
le_iff_le_iff_lt_iff_lt.2 nat.lt_sub_left_iff_add_lt
theorem sub_le_right_iff_le_add : m - k ≤ n ↔ m ≤ n + k :=
by rw [nat.sub_le_left_iff_le_add, add_comm]
protected theorem sub_lt_right_iff_lt_add (H : k ≤ m) : m - k < n ↔ m < n + k :=
by rw [nat.sub_lt_left_iff_lt_add H, add_comm]
protected theorem sub_le_sub_left_iff (H : k ≤ m) : m - n ≤ m - k ↔ k ≤ n :=
⟨λ h,
have k + (m - k) - n ≤ m - k, by rwa nat.add_sub_cancel' H,
nat.le_of_add_le_add_right (nat.le_add_of_sub_le_left this),
nat.sub_le_sub_left _⟩
protected theorem sub_lt_sub_right_iff (H : k ≤ m) : m - k < n - k ↔ m < n :=
lt_iff_lt_of_le_iff_le (nat.sub_le_sub_right_iff _ _ _ H)
protected theorem sub_lt_sub_left_iff (H : n ≤ m) : m - n < m - k ↔ k < n :=
lt_iff_lt_of_le_iff_le (nat.sub_le_sub_left_iff H)
protected theorem sub_le_iff : m - n ≤ k ↔ m - k ≤ n :=
nat.sub_le_left_iff_le_add.trans nat.sub_le_right_iff_le_add.symm
protected lemma sub_le_self (n m : ℕ) : n - m ≤ n :=
nat.sub_le_left_of_le_add (nat.le_add_left _ _)
protected theorem sub_lt_iff (h₁ : n ≤ m) (h₂ : k ≤ m) : m - n < k ↔ m - k < n :=
(nat.sub_lt_left_iff_lt_add h₁).trans (nat.sub_lt_right_iff_lt_add h₂).symm
lemma pred_le_iff {n m : ℕ} : pred n ≤ m ↔ n ≤ succ m :=
@nat.sub_le_right_iff_le_add n m 1
lemma lt_pred_iff {n m : ℕ} : n < pred m ↔ succ n < m :=
@nat.lt_sub_right_iff_add_lt n 1 m
lemma lt_of_lt_pred {a b : ℕ} (h : a < b - 1) : a < b :=
lt_of_succ_lt (lt_pred_iff.1 h)
/-! ### `mul` -/
theorem mul_self_le_mul_self {n m : ℕ} (h : n ≤ m) : n * n ≤ m * m :=
mul_le_mul h h (zero_le _) (zero_le _)
theorem mul_self_lt_mul_self : Π {n m : ℕ}, n < m → n * n < m * m
| 0 m h := mul_pos h h
| (succ n) m h := mul_lt_mul h (le_of_lt h) (succ_pos _) (zero_le _)
theorem mul_self_le_mul_self_iff {n m : ℕ} : n ≤ m ↔ n * n ≤ m * m :=
⟨mul_self_le_mul_self, λh, decidable.by_contradiction $
λhn, not_lt_of_ge h $ mul_self_lt_mul_self $ lt_of_not_ge hn⟩
theorem mul_self_lt_mul_self_iff {n m : ℕ} : n < m ↔ n * n < m * m :=
iff.trans (lt_iff_not_ge _ _) $ iff.trans (not_iff_not_of_iff mul_self_le_mul_self_iff) $
iff.symm (lt_iff_not_ge _ _)
theorem le_mul_self : Π (n : ℕ), n ≤ n * n
| 0 := le_refl _
| (n+1) := let t := mul_le_mul_left (n+1) (succ_pos n) in by simp at t; exact t
lemma le_mul_of_pos_left {m n : ℕ} (h : 0 < n) : m ≤ n * m :=
begin
conv {to_lhs, rw [← one_mul(m)]},
exact mul_le_mul_of_nonneg_right (nat.succ_le_of_lt h) dec_trivial,
end
lemma le_mul_of_pos_right {m n : ℕ} (h : 0 < n) : m ≤ m * n :=
begin
conv {to_lhs, rw [← mul_one(m)]},
exact mul_le_mul_of_nonneg_left (nat.succ_le_of_lt h) dec_trivial,
end
theorem two_mul_ne_two_mul_add_one {n m} : 2 * n ≠ 2 * m + 1 :=
mt (congr_arg (%2)) (by rw [add_comm, add_mul_mod_self_left, mul_mod_right]; exact dec_trivial)
lemma mul_eq_one_iff : ∀ {a b : ℕ}, a * b = 1 ↔ a = 1 ∧ b = 1
| 0 0 := dec_trivial
| 0 1 := dec_trivial
| 1 0 := dec_trivial
| (a+2) 0 := by simp
| 0 (b+2) := by simp
| (a+1) (b+1) := ⟨λ h, by simp only [add_mul, mul_add, mul_add, one_mul, mul_one,
(add_assoc _ _ _).symm, nat.succ_inj', add_eq_zero_iff] at h; simp [h.1.2, h.2],
by clear_aux_decl; finish⟩
protected theorem mul_left_inj {a b c : ℕ} (ha : 0 < a) : b * a = c * a ↔ b = c :=
⟨nat.eq_of_mul_eq_mul_right ha, λ e, e ▸ rfl⟩
protected theorem mul_right_inj {a b c : ℕ} (ha : 0 < a) : a * b = a * c ↔ b = c :=
⟨nat.eq_of_mul_eq_mul_left ha, λ e, e ▸ rfl⟩
lemma mul_left_injective {a : ℕ} (ha : 0 < a) : function.injective (λ x, x * a) :=
λ _ _, eq_of_mul_eq_mul_right ha
lemma mul_right_injective {a : ℕ} (ha : 0 < a) : function.injective (λ x, a * x) :=
λ _ _, eq_of_mul_eq_mul_left ha
lemma mul_right_eq_self_iff {a b : ℕ} (ha : 0 < a) : a * b = a ↔ b = 1 :=
suffices a * b = a * 1 ↔ b = 1, by rwa mul_one at this,
nat.mul_right_inj ha
lemma mul_left_eq_self_iff {a b : ℕ} (hb : 0 < b) : a * b = b ↔ a = 1 :=
by rw [mul_comm, nat.mul_right_eq_self_iff hb]
lemma lt_succ_iff_lt_or_eq {n i : ℕ} : n < i.succ ↔ (n < i ∨ n = i) :=
lt_succ_iff.trans le_iff_lt_or_eq
theorem mul_self_inj {n m : ℕ} : n * n = m * m ↔ n = m :=
le_antisymm_iff.trans (le_antisymm_iff.trans
(and_congr mul_self_le_mul_self_iff mul_self_le_mul_self_iff)).symm
/-!
### Recursion and induction principles
This section is here due to dependencies -- the lemmas here require some of the lemmas
proved above, and some of the results in later sections depend on the definitions in this section.
-/
/-- Recursion starting at a non-zero number: given a map `C k → C (k+1)` for each `k`,
there is a map from `C n` to each `C m`, `n ≤ m`. -/
@[elab_as_eliminator]
def le_rec_on {C : ℕ → Sort u} {n : ℕ} : Π {m : ℕ}, n ≤ m → (Π {k}, C k → C (k+1)) → C n → C m
| 0 H next x := eq.rec_on (eq_zero_of_le_zero H) x
| (m+1) H next x := or.by_cases (of_le_succ H) (λ h : n ≤ m, next $ le_rec_on h @next x)
(λ h : n = m + 1, eq.rec_on h x)
theorem le_rec_on_self {C : ℕ → Sort u} {n} {h : n ≤ n} {next} (x : C n) :
(le_rec_on h next x : C n) = x :=
by cases n; unfold le_rec_on or.by_cases; rw [dif_neg n.not_succ_le_self, dif_pos rfl]
theorem le_rec_on_succ {C : ℕ → Sort u} {n m} (h1 : n ≤ m) {h2 : n ≤ m+1} {next} (x : C n) :
(le_rec_on h2 @next x : C (m+1)) = next (le_rec_on h1 @next x : C m) :=
by conv { to_lhs, rw [le_rec_on, or.by_cases, dif_pos h1] }
theorem le_rec_on_succ' {C : ℕ → Sort u} {n} {h : n ≤ n+1} {next} (x : C n) :
(le_rec_on h next x : C (n+1)) = next x :=
by rw [le_rec_on_succ (le_refl n), le_rec_on_self]
theorem le_rec_on_trans {C : ℕ → Sort u} {n m k} (hnm : n ≤ m) (hmk : m ≤ k) {next} (x : C n) :
(le_rec_on (le_trans hnm hmk) @next x : C k) = le_rec_on hmk @next (le_rec_on hnm @next x) :=
begin
induction hmk with k hmk ih, { rw le_rec_on_self },
rw [le_rec_on_succ (le_trans hnm hmk), ih, le_rec_on_succ]
end
theorem le_rec_on_succ_left {C : ℕ → Sort u} {n m} (h1 : n ≤ m) (h2 : n+1 ≤ m)
{next : Π{{k}}, C k → C (k+1)} (x : C n) :
(le_rec_on h2 next (next x) : C m) = (le_rec_on h1 next x : C m) :=
begin
rw [subsingleton.elim h1 (le_trans (le_succ n) h2),
le_rec_on_trans (le_succ n) h2, le_rec_on_succ']
end
theorem le_rec_on_injective {C : ℕ → Sort u} {n m} (hnm : n ≤ m)
(next : Π n, C n → C (n+1)) (Hnext : ∀ n, function.injective (next n)) :
function.injective (le_rec_on hnm next) :=
begin
induction hnm with m hnm ih, { intros x y H, rwa [le_rec_on_self, le_rec_on_self] at H },
intros x y H, rw [le_rec_on_succ hnm, le_rec_on_succ hnm] at H, exact ih (Hnext _ H)
end
theorem le_rec_on_surjective {C : ℕ → Sort u} {n m} (hnm : n ≤ m)
(next : Π n, C n → C (n+1)) (Hnext : ∀ n, function.surjective (next n)) :
function.surjective (le_rec_on hnm next) :=
begin
induction hnm with m hnm ih, { intros x, use x, rw le_rec_on_self },
intros x, rcases Hnext _ x with ⟨w, rfl⟩, rcases ih w with ⟨x, rfl⟩, use x, rw le_rec_on_succ
end
/-- Recursion principle based on `<`. -/
@[elab_as_eliminator]
protected def strong_rec' {p : ℕ → Sort u} (H : ∀ n, (∀ m, m < n → p m) → p n) : ∀ (n : ℕ), p n
| n := H n (λ m hm, strong_rec' m)
/-- Recursion principle based on `<` applied to some natural number. -/
@[elab_as_eliminator]
def strong_rec_on' {P : ℕ → Sort*} (n : ℕ) (h : ∀ n, (∀ m, m < n → P m) → P n) : P n :=
nat.strong_rec' h n
theorem strong_rec_on_beta' {P : ℕ → Sort*} {h} {n : ℕ} :
(strong_rec_on' n h : P n) = h n (λ m hmn, (strong_rec_on' m h : P m)) :=
by { simp only [strong_rec_on'], rw nat.strong_rec' }
/-- Induction principle starting at a non-zero number. For maps to a `Sort*` see `le_rec_on`. -/
@[elab_as_eliminator] lemma le_induction {P : nat → Prop} {m}
(h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (n + 1)) :
∀ n, m ≤ n → P n :=
by apply nat.less_than_or_equal.rec h0; exact h1
/-- Decreasing induction: if `P (k+1)` implies `P k`, then `P n` implies `P m` for all `m ≤ n`.
Also works for functions to `Sort*`. -/
@[elab_as_eliminator]
def decreasing_induction {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n)
(hP : P n) : P m :=
le_rec_on mn (λ k ih hsk, ih $ h k hsk) (λ h, h) hP
@[simp] lemma decreasing_induction_self {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {n : ℕ}
(nn : n ≤ n) (hP : P n) : (decreasing_induction h nn hP : P n) = hP :=
by { dunfold decreasing_induction, rw [le_rec_on_self] }
lemma decreasing_induction_succ {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n)
(msn : m ≤ n + 1) (hP : P (n+1)) :
(decreasing_induction h msn hP : P m) = decreasing_induction h mn (h n hP) :=
by { dunfold decreasing_induction, rw [le_rec_on_succ] }
@[simp] lemma decreasing_induction_succ' {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m : ℕ}
(msm : m ≤ m + 1) (hP : P (m+1)) : (decreasing_induction h msm hP : P m) = h m hP :=
by { dunfold decreasing_induction, rw [le_rec_on_succ'] }
lemma decreasing_induction_trans {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n k : ℕ}
(mn : m ≤ n) (nk : n ≤ k) (hP : P k) :
(decreasing_induction h (le_trans mn nk) hP : P m) =
decreasing_induction h mn (decreasing_induction h nk hP) :=
by { induction nk with k nk ih, rw [decreasing_induction_self],
rw [decreasing_induction_succ h (le_trans mn nk), ih, decreasing_induction_succ] }
lemma decreasing_induction_succ_left {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ}
(smn : m + 1 ≤ n) (mn : m ≤ n) (hP : P n) :
(decreasing_induction h mn hP : P m) = h m (decreasing_induction h smn hP) :=
by { rw [subsingleton.elim mn (le_trans (le_succ m) smn), decreasing_induction_trans,
decreasing_induction_succ'] }
/-! ### `div` -/
attribute [simp] nat.div_self
protected lemma div_le_of_le_mul' {m n : ℕ} {k} (h : m ≤ k * n) : m / k ≤ n :=
(eq_zero_or_pos k).elim
(λ k0, by rw [k0, nat.div_zero]; apply zero_le)
(λ k0, (decidable.mul_le_mul_left k0).1 $
calc k * (m / k)
≤ m % k + k * (m / k) : le_add_left _ _
... = m : mod_add_div _ _
... ≤ k * n : h)
protected lemma div_le_self' (m n : ℕ) : m / n ≤ m :=
(eq_zero_or_pos n).elim
(λ n0, by rw [n0, nat.div_zero]; apply zero_le)
(λ n0, nat.div_le_of_le_mul' $ calc
m = 1 * m : (one_mul _).symm
... ≤ n * m : mul_le_mul_right _ n0)
/-- A version of `nat.div_lt_self` using successors, rather than additional hypotheses. -/
lemma div_lt_self' (n b : ℕ) : (n+1)/(b+2) < n+1 :=
nat.div_lt_self (nat.succ_pos n) (nat.succ_lt_succ (nat.succ_pos _))
theorem le_div_iff_mul_le' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x ≤ y / k ↔ x * k ≤ y :=
begin
revert x, refine nat.strong_rec' _ y,
clear y, intros y IH x,
cases decidable.lt_or_le y k with h h,
{ rw [div_eq_of_lt h],
cases x with x,
{ simp [zero_mul, zero_le] },
{ rw succ_mul,
exact iff_of_false (not_succ_le_zero _)
(not_le_of_lt $ lt_of_lt_of_le h (le_add_left _ _)) } },
{ rw [div_eq_sub_div k0 h],
cases x with x,
{ simp [zero_mul, zero_le] },
{ rw [← add_one, nat.add_le_add_iff_le_right, succ_mul,
IH _ (sub_lt_of_pos_le _ _ k0 h), add_le_to_le_sub _ h] } }
end
theorem div_mul_le_self' (m n : ℕ) : m / n * n ≤ m :=
(nat.eq_zero_or_pos n).elim (λ n0, by simp [n0, zero_le]) $ λ n0,
(le_div_iff_mul_le' n0).1 (le_refl _)
theorem div_lt_iff_lt_mul' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x / k < y ↔ x < y * k :=
lt_iff_lt_of_le_iff_le $ le_div_iff_mul_le' k0
protected theorem div_le_div_right {n m : ℕ} (h : n ≤ m) {k : ℕ} : n / k ≤ m / k :=
(nat.eq_zero_or_pos k).elim (λ k0, by simp [k0]) $ λ hk,
(le_div_iff_mul_le' hk).2 $ le_trans (nat.div_mul_le_self' _ _) h
lemma lt_of_div_lt_div {m n k : ℕ} (h : m / k < n / k) : m < n :=
by_contradiction $ λ h₁, absurd h (not_lt_of_ge (nat.div_le_div_right (not_lt.1 h₁)))
protected lemma div_pos {a b : ℕ} (hba : b ≤ a) (hb : 0 < b) : 0 < a / b :=
nat.pos_of_ne_zero (λ h, lt_irrefl a
(calc a = a % b : by simpa [h] using (mod_add_div a b).symm
... < b : nat.mod_lt a hb
... ≤ a : hba))
protected lemma div_lt_of_lt_mul {m n k : ℕ} (h : m < n * k) : m / n < k :=
lt_of_mul_lt_mul_left
(calc n * (m / n) ≤ m % n + n * (m / n) : nat.le_add_left _ _
... = m : mod_add_div _ _
... < n * k : h)
(nat.zero_le n)
lemma lt_mul_of_div_lt {a b c : ℕ} (h : a / c < b) (w : 0 < c) : a < b * c :=
lt_of_not_ge $ not_le_of_gt h ∘ (nat.le_div_iff_mul_le _ _ w).2
protected lemma div_eq_zero_iff {a b : ℕ} (hb : 0 < b) : a / b = 0 ↔ a < b :=
⟨λ h, by rw [← mod_add_div a b, h, mul_zero, add_zero]; exact mod_lt _ hb,
λ h, by rw [← nat.mul_right_inj hb, ← @add_left_cancel_iff _ _ (a % b), mod_add_div,
mod_eq_of_lt h, mul_zero, add_zero]⟩
protected lemma div_eq_zero {a b : ℕ} (hb : a < b) : a / b = 0 :=
(nat.div_eq_zero_iff $ (zero_le a).trans_lt hb).mpr hb
lemma eq_zero_of_le_div {a b : ℕ} (hb : 2 ≤ b) (h : a ≤ a / b) : a = 0 :=
eq_zero_of_mul_le hb $
by rw mul_comm; exact (nat.le_div_iff_mul_le' (lt_of_lt_of_le dec_trivial hb)).1 h
lemma mul_div_le_mul_div_assoc (a b c : ℕ) : a * (b / c) ≤ (a * b) / c :=
if hc0 : c = 0 then by simp [hc0]
else (nat.le_div_iff_mul_le _ _ (nat.pos_of_ne_zero hc0)).2
(by rw [mul_assoc]; exact mul_le_mul_left _ (nat.div_mul_le_self _ _))
lemma div_mul_div_le_div (a b c : ℕ) : ((a / c) * b) / a ≤ b / c :=
if ha0 : a = 0 then by simp [ha0]
else calc a / c * b / a ≤ b * a / c / a :
nat.div_le_div_right (by rw [mul_comm];
exact mul_div_le_mul_div_assoc _ _ _)
... = b / c : by rw [nat.div_div_eq_div_mul, mul_comm b, mul_comm c,
nat.mul_div_mul _ _ (nat.pos_of_ne_zero ha0)]
lemma eq_zero_of_le_half {a : ℕ} (h : a ≤ a / 2) : a = 0 :=
eq_zero_of_le_div (le_refl _) h
protected theorem eq_mul_of_div_eq_right {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) :
a = b * c :=
by rw [← H2, nat.mul_div_cancel' H1]
protected theorem div_eq_iff_eq_mul_right {a b c : ℕ} (H : 0 < b) (H' : b ∣ a) :
a / b = c ↔ a = b * c :=
⟨nat.eq_mul_of_div_eq_right H', nat.div_eq_of_eq_mul_right H⟩
protected theorem div_eq_iff_eq_mul_left {a b c : ℕ} (H : 0 < b) (H' : b ∣ a) :
a / b = c ↔ a = c * b :=
by rw mul_comm; exact nat.div_eq_iff_eq_mul_right H H'
protected theorem eq_mul_of_div_eq_left {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) :
a = c * b :=
by rw [mul_comm, nat.eq_mul_of_div_eq_right H1 H2]
protected theorem mul_div_cancel_left' {a b : ℕ} (Hd : a ∣ b) : a * (b / a) = b :=
by rw [mul_comm,nat.div_mul_cancel Hd]
/-! ### `mod`, `dvd` -/
protected theorem div_mod_unique {n k m d : ℕ} (h : 0 < k) :
n / k = d ∧ n % k = m ↔ m + k * d = n ∧ m < k :=
⟨λ ⟨e₁, e₂⟩, e₁ ▸ e₂ ▸ ⟨mod_add_div _ _, mod_lt _ h⟩,
λ ⟨h₁, h₂⟩, h₁ ▸ by rw [add_mul_div_left _ _ h, add_mul_mod_self_left];
simp [div_eq_of_lt, mod_eq_of_lt, h₂]⟩
lemma two_mul_odd_div_two {n : ℕ} (hn : n % 2 = 1) : 2 * (n / 2) = n - 1 :=
by conv {to_rhs, rw [← nat.mod_add_div n 2, hn, nat.add_sub_cancel_left]}
lemma div_dvd_of_dvd {a b : ℕ} (h : b ∣ a) : (a / b) ∣ a :=
⟨b, (nat.div_mul_cancel h).symm⟩
protected lemma div_div_self : ∀ {a b : ℕ}, b ∣ a → 0 < a → a / (a / b) = b
| a 0 h₁ h₂ := by rw eq_zero_of_zero_dvd h₁; refl
| 0 b h₁ h₂ := absurd h₂ dec_trivial
| (a+1) (b+1) h₁ h₂ :=
(nat.mul_left_inj (nat.div_pos (le_of_dvd (succ_pos a) h₁) (succ_pos b))).1 $
by rw [nat.div_mul_cancel (div_dvd_of_dvd h₁), nat.mul_div_cancel' h₁]
lemma mod_mul_right_div_self (a b c : ℕ) : a % (b * c) / b = (a / b) % c :=
if hb : b = 0 then by simp [hb] else if hc : c = 0 then by simp [hc]
else by conv {to_rhs, rw ← mod_add_div a (b * c)};
rw [mul_assoc, nat.add_mul_div_left _ _ (nat.pos_of_ne_zero hb), add_mul_mod_self_left,
mod_eq_of_lt (nat.div_lt_of_lt_mul (mod_lt _ (mul_pos (nat.pos_of_ne_zero hb) (nat.pos_of_ne_zero hc))))]
lemma mod_mul_left_div_self (a b c : ℕ) : a % (c * b) / b = (a / b) % c :=
by rw [mul_comm c, mod_mul_right_div_self]
@[simp] protected theorem dvd_one {n : ℕ} : n ∣ 1 ↔ n = 1 :=
⟨eq_one_of_dvd_one, λ e, e.symm ▸ dvd_refl _⟩
protected theorem dvd_add_left {k m n : ℕ} (h : k ∣ n) : k ∣ m + n ↔ k ∣ m :=
(nat.dvd_add_iff_left h).symm
protected theorem dvd_add_right {k m n : ℕ} (h : k ∣ m) : k ∣ m + n ↔ k ∣ n :=
(nat.dvd_add_iff_right h).symm
@[simp] protected theorem not_two_dvd_bit1 (n : ℕ) : ¬ 2 ∣ bit1 n :=
mt (nat.dvd_add_right two_dvd_bit0).1 dec_trivial
/-- A natural number `m` divides the sum `m + n` if and only if `m` divides `n`.-/
@[simp] protected lemma dvd_add_self_left {m n : ℕ} :
m ∣ m + n ↔ m ∣ n :=
nat.dvd_add_right (dvd_refl m)
/-- A natural number `m` divides the sum `n + m` if and only if `m` divides `n`.-/
@[simp] protected lemma dvd_add_self_right {m n : ℕ} :
m ∣ n + m ↔ m ∣ n :=
nat.dvd_add_left (dvd_refl m)
lemma not_dvd_of_pos_of_lt {a b : ℕ} (h1 : 0 < b) (h2 : b < a) : ¬ a ∣ b :=
begin
rintros ⟨c, rfl⟩,
rcases eq_zero_or_pos c with (rfl | hc),
{ exact lt_irrefl 0 h1 },
{ exact not_lt.2 (le_mul_of_pos_right hc) h2 },
end
protected theorem mul_dvd_mul_iff_left {a b c : ℕ} (ha : 0 < a) : a * b ∣ a * c ↔ b ∣ c :=
exists_congr $ λ d, by rw [mul_assoc, nat.mul_right_inj ha]
protected theorem mul_dvd_mul_iff_right {a b c : ℕ} (hc : 0 < c) : a * c ∣ b * c ↔ a ∣ b :=
exists_congr $ λ d, by rw [mul_right_comm, nat.mul_left_inj hc]
lemma succ_div : ∀ (a b : ℕ), (a + 1) / b =
a / b + if b ∣ a + 1 then 1 else 0
| a 0 := by simp
| 0 1 := rfl
| 0 (b+2) := have hb2 : b + 2 > 1, from dec_trivial,
by simp [ne_of_gt hb2, div_eq_of_lt hb2]
| (a+1) (b+1) := begin
rw [nat.div_def], conv_rhs { rw nat.div_def },
by_cases hb_eq_a : b = a + 1,
{ simp [hb_eq_a, le_refl] },
by_cases hb_le_a1 : b ≤ a + 1,
{ have hb_le_a : b ≤ a, from le_of_lt_succ (lt_of_le_of_ne hb_le_a1 hb_eq_a),
have h₁ : (0 < b + 1 ∧ b + 1 ≤ a + 1 + 1),
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a1⟩,
have h₂ : (0 < b + 1 ∧ b + 1 ≤ a + 1),
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a⟩,
have dvd_iff : b + 1 ∣ a - b + 1 ↔ b + 1 ∣ a + 1 + 1,
{ rw [nat.dvd_add_iff_left (dvd_refl (b + 1)),
← nat.add_sub_add_right a 1 b, add_comm (_ - _), add_assoc,
nat.sub_add_cancel (succ_le_succ hb_le_a), add_comm 1] },
have wf : a - b < a + 1, from lt_succ_of_le (nat.sub_le_self _ _),
rw [if_pos h₁, if_pos h₂, nat.add_sub_add_right, nat.sub_add_comm hb_le_a,
by exact have _ := wf, succ_div (a - b),
nat.add_sub_add_right],
simp [dvd_iff, succ_eq_add_one, add_comm 1, add_assoc] },
{ have hba : ¬ b ≤ a,
from not_le_of_gt (lt_trans (lt_succ_self a) (lt_of_not_ge hb_le_a1)),
have hb_dvd_a : ¬ b + 1 ∣ a + 2,
from λ h, hb_le_a1 (le_of_succ_le_succ (le_of_dvd (succ_pos _) h)),
simp [hba, hb_le_a1, hb_dvd_a], }
end
lemma succ_div_of_dvd {a b : ℕ} (hba : b ∣ a + 1) :
(a + 1) / b = a / b + 1 :=
by rw [succ_div, if_pos hba]
lemma succ_div_of_not_dvd {a b : ℕ} (hba : ¬ b ∣ a + 1) :
(a + 1) / b = a / b :=
by rw [succ_div, if_neg hba, add_zero]
@[simp] theorem mod_mod_of_dvd (n : nat) {m k : nat} (h : m ∣ k) : n % k % m = n % m :=
begin
conv { to_rhs, rw ←mod_add_div n k },
rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left]
end
@[simp] theorem mod_mod (a n : ℕ) : (a % n) % n = a % n :=
(eq_zero_or_pos n).elim
(λ n0, by simp [n0])
(λ npos, mod_eq_of_lt (mod_lt _ npos))
/-- If `a` and `b` are equal mod `c`, `a - b` is zero mod `c`. -/
lemma sub_mod_eq_zero_of_mod_eq {a b c : ℕ} (h : a % c = b % c) : (a - b) % c = 0 :=
by rw [←nat.mod_add_div a c, ←nat.mod_add_div b c, ←h, ←nat.sub_sub, nat.add_sub_cancel_left,
←nat.mul_sub_left_distrib, nat.mul_mod_right]
@[simp] lemma one_mod (n : ℕ) : 1 % (n + 2) = 1 := nat.mod_eq_of_lt (add_lt_add_right n.succ_pos 1)
lemma dvd_sub_mod (k : ℕ) : n ∣ (k - (k % n)) :=
⟨k / n, nat.sub_eq_of_eq_add (nat.mod_add_div k n).symm⟩
@[simp] theorem mod_add_mod (m n k : ℕ) : (m % n + k) % n = (m + k) % n :=
by have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm;
rwa [add_right_comm, mod_add_div] at this
@[simp] theorem add_mod_mod (m n k : ℕ) : (m + n % k) % k = (m + n) % k :=
by rw [add_comm, mod_add_mod, add_comm]
lemma add_mod (a b n : ℕ) : (a + b) % n = ((a % n) + (b % n)) % n :=
by rw [add_mod_mod, mod_add_mod]
theorem add_mod_eq_add_mod_right {m n k : ℕ} (i : ℕ) (H : m % n = k % n) :
(m + i) % n = (k + i) % n :=
by rw [← mod_add_mod, ← mod_add_mod k, H]
theorem add_mod_eq_add_mod_left {m n k : ℕ} (i : ℕ) (H : m % n = k % n) :
(i + m) % n = (i + k) % n :=
by rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm]
lemma mul_mod (a b n : ℕ) : (a * b) % n = ((a % n) * (b % n)) % n :=
begin
conv_lhs {
rw [←mod_add_div a n, ←mod_add_div b n, right_distrib, left_distrib, left_distrib,
mul_assoc, mul_assoc, ←left_distrib n _ _, add_mul_mod_self_left,
mul_comm _ (n * (b / n)), mul_assoc, add_mul_mod_self_left] }
end
lemma dvd_div_of_mul_dvd {a b c : ℕ} (h : a * b ∣ c) : b ∣ c / a :=
if ha : a = 0 then
by simp [ha]
else
have ha : 0 < a, from nat.pos_of_ne_zero ha,
have h1 : ∃ d, c = a * b * d, from h,
let ⟨d, hd⟩ := h1 in
have h2 : c / a = b * d, from nat.div_eq_of_eq_mul_right ha (by simpa [mul_assoc] using hd),
show ∃ d, c / a = b * d, from ⟨d, h2⟩
lemma mul_dvd_of_dvd_div {a b c : ℕ} (hab : c ∣ b) (h : a ∣ b / c) : c * a ∣ b :=
have h1 : ∃ d, b / c = a * d, from h,
have h2 : ∃ e, b = c * e, from hab,
let ⟨d, hd⟩ := h1, ⟨e, he⟩ := h2 in
have h3 : b = a * d * c, from
nat.eq_mul_of_div_eq_left hab hd,
show ∃ d, b = c * a * d, from ⟨d, by cc⟩
lemma div_mul_div {a b c d : ℕ} (hab : b ∣ a) (hcd : d ∣ c) :
(a / b) * (c / d) = (a * c) / (b * d) :=
have exi1 : ∃ x, a = b * x, from hab,
have exi2 : ∃ y, c = d * y, from hcd,
if hb : b = 0 then by simp [hb]
else have 0 < b, from nat.pos_of_ne_zero hb,
if hd : d = 0 then by simp [hd]
else have 0 < d, from nat.pos_of_ne_zero hd,
begin
cases exi1 with x hx, cases exi2 with y hy,
rw [hx, hy, nat.mul_div_cancel_left, nat.mul_div_cancel_left],
symmetry,
apply nat.div_eq_of_eq_mul_left,
apply mul_pos,
repeat {assumption},
cc
end
@[simp]
lemma div_div_div_eq_div : ∀ {a b c : ℕ} (dvd : b ∣ a) (dvd2 : a ∣ c), (c / (a / b)) / b = c / a
| 0 _ := by simp
| (a + 1) 0 := λ _ dvd _, by simpa using dvd
| (a + 1) (c + 1) :=
have a_split : a + 1 ≠ 0 := succ_ne_zero a,
have c_split : c + 1 ≠ 0 := succ_ne_zero c,
λ b dvd dvd2,
begin
rcases dvd2 with ⟨k, rfl⟩,
rcases dvd with ⟨k2, pr⟩,
have k2_nonzero : k2 ≠ 0 := λ k2_zero, by simpa [k2_zero] using pr,
rw [nat.mul_div_cancel_left k (nat.pos_of_ne_zero a_split), pr,
nat.mul_div_cancel_left k2 (nat.pos_of_ne_zero c_split), nat.mul_comm ((c + 1) * k2) k,
←nat.mul_assoc k (c + 1) k2, nat.mul_div_cancel _ (nat.pos_of_ne_zero k2_nonzero),
nat.mul_div_cancel _ (nat.pos_of_ne_zero c_split)],
end
lemma eq_of_dvd_of_div_eq_one {a b : ℕ} (w : a ∣ b) (h : b / a = 1) : a = b :=
by rw [←nat.div_mul_cancel w, h, one_mul]
lemma eq_zero_of_dvd_of_div_eq_zero {a b : ℕ} (w : a ∣ b) (h : b / a = 0) : b = 0 :=
by rw [←nat.div_mul_cancel w, h, zero_mul]
/-- If a small natural number is divisible by a larger natural number,
the small number is zero. -/
lemma eq_zero_of_dvd_of_lt {a b : ℕ} (w : a ∣ b) (h : b < a) : b = 0 :=
nat.eq_zero_of_dvd_of_div_eq_zero w
((nat.div_eq_zero_iff (lt_of_le_of_lt (zero_le b) h)).elim_right h)
lemma div_le_div_left {a b c : ℕ} (h₁ : c ≤ b) (h₂ : 0 < c) : a / b ≤ a / c :=
(nat.le_div_iff_mul_le _ _ h₂).2 $
le_trans (mul_le_mul_left _ h₁) (div_mul_le_self _ _)
lemma div_eq_self {a b : ℕ} : a / b = a ↔ a = 0 ∨ b = 1 :=
begin
split,
{ intro,
cases b,
{ simp * at * },
{ cases b,
{ right, refl },
{ left,
have : a / (b + 2) ≤ a / 2 := div_le_div_left (by simp) dec_trivial,
refine eq_zero_of_le_half _,
simp * at * } } },
{ rintros (rfl|rfl); simp }
end
/-! ### `pow` -/
-- This is redundant with `canonically_ordered_semiring.pow_le_pow_of_le_left`,
-- but `canonically_ordered_semiring` is not such an obvious abstraction, and also quite long.
-- So, we leave a version in the `nat` namespace as well.
-- (The global `pow_le_pow_of_le_left` needs an extra hypothesis `0 ≤ x`.)
protected theorem pow_le_pow_of_le_left {x y : ℕ} (H : x ≤ y) : ∀ i : ℕ, x^i ≤ y^i :=
canonically_ordered_semiring.pow_le_pow_of_le_left H
theorem pow_le_pow_of_le_right {x : ℕ} (H : x > 0) {i : ℕ} : ∀ {j}, i ≤ j → x^i ≤ x^j
| 0 h := by rw eq_zero_of_le_zero h; apply le_refl
| (succ j) h := (lt_or_eq_of_le h).elim
(λhl, by rw [pow_succ', ← nat.mul_one (x^i)]; exact
nat.mul_le_mul (pow_le_pow_of_le_right $ le_of_lt_succ hl) H)
(λe, by rw e; refl)
theorem pow_lt_pow_of_lt_left {x y : ℕ} (H : x < y) {i} (h : 0 < i) : x^i < y^i :=
begin
cases i with i, { exact absurd h (not_lt_zero _) },
rw [pow_succ', pow_succ'],
exact nat.mul_lt_mul' (nat.pow_le_pow_of_le_left (le_of_lt H) _) H
(pow_pos (lt_of_le_of_lt (zero_le _) H) _)
end
theorem pow_lt_pow_of_lt_right {x : ℕ} (H : x > 1) {i j : ℕ} (h : i < j) : x^i < x^j :=
begin
have xpos := lt_of_succ_lt H,
refine lt_of_lt_of_le _ (pow_le_pow_of_le_right xpos h),
rw [← nat.mul_one (x^i), pow_succ'],
exact nat.mul_lt_mul_of_pos_left H (pow_pos xpos _)
end
-- TODO: Generalize?
lemma pow_lt_pow_succ {p : ℕ} (h : 1 < p) (n : ℕ) : p^n < p^(n+1) :=
suffices 1*p^n < p*p^n, by simpa,
nat.mul_lt_mul_of_pos_right h (pow_pos (lt_of_succ_lt h) n)
lemma lt_pow_self {p : ℕ} (h : 1 < p) : ∀ n : ℕ, n < p ^ n
| 0 := by simp [zero_lt_one]
| (n+1) := calc
n + 1 < p^n + 1 : nat.add_lt_add_right (lt_pow_self _) _
... ≤ p ^ (n+1) : pow_lt_pow_succ h _
lemma lt_two_pow (n : ℕ) : n < 2^n :=
lt_pow_self dec_trivial n
lemma one_le_pow (n m : ℕ) (h : 0 < m) : 1 ≤ m^n :=
by { rw ←one_pow n, exact nat.pow_le_pow_of_le_left h n }
lemma one_le_pow' (n m : ℕ) : 1 ≤ (m+1)^n := one_le_pow n (m+1) (succ_pos m)
lemma one_le_two_pow (n : ℕ) : 1 ≤ 2^n := one_le_pow n 2 dec_trivial
lemma one_lt_pow (n m : ℕ) (h₀ : 0 < n) (h₁ : 1 < m) : 1 < m^n :=
by { rw ←one_pow n, exact pow_lt_pow_of_lt_left h₁ h₀ }
lemma one_lt_pow' (n m : ℕ) : 1 < (m+2)^(n+1) :=
one_lt_pow (n+1) (m+2) (succ_pos n) (nat.lt_of_sub_eq_succ rfl)
lemma one_lt_two_pow (n : ℕ) (h₀ : 0 < n) : 1 < 2^n := one_lt_pow n 2 h₀ dec_trivial
lemma one_lt_two_pow' (n : ℕ) : 1 < 2^(n+1) := one_lt_pow (n+1) 2 (succ_pos n) dec_trivial
lemma pow_right_strict_mono {x : ℕ} (k : 2 ≤ x) : strict_mono (λ (n : ℕ), x^n) :=
λ _ _, pow_lt_pow_of_lt_right k
lemma pow_le_iff_le_right {x m n : ℕ} (k : 2 ≤ x) : x^m ≤ x^n ↔ m ≤ n :=
strict_mono.le_iff_le (pow_right_strict_mono k)
lemma pow_lt_iff_lt_right {x m n : ℕ} (k : 2 ≤ x) : x^m < x^n ↔ m < n :=
strict_mono.lt_iff_lt (pow_right_strict_mono k)
lemma pow_right_injective {x : ℕ} (k : 2 ≤ x) : function.injective (λ (n : ℕ), x^n) :=
strict_mono.injective (pow_right_strict_mono k)
lemma pow_left_strict_mono {m : ℕ} (k : 1 ≤ m) : strict_mono (λ (x : ℕ), x^m) :=
λ _ _ h, pow_lt_pow_of_lt_left h k
end nat
lemma strict_mono.nat_pow {n : ℕ} (hn : 1 ≤ n) {f : ℕ → ℕ} (hf : strict_mono f) :
strict_mono (λ m, (f m) ^ n) :=
(nat.pow_left_strict_mono hn).comp hf
namespace nat
lemma pow_le_iff_le_left {m x y : ℕ} (k : 1 ≤ m) : x^m ≤ y^m ↔ x ≤ y :=
strict_mono.le_iff_le (pow_left_strict_mono k)
lemma pow_lt_iff_lt_left {m x y : ℕ} (k : 1 ≤ m) : x^m < y^m ↔ x < y :=
strict_mono.lt_iff_lt (pow_left_strict_mono k)
lemma pow_left_injective {m : ℕ} (k : 1 ≤ m) : function.injective (λ (x : ℕ), x^m) :=
strict_mono.injective (pow_left_strict_mono k)
/-! ### `pow` and `mod` / `dvd` -/
theorem mod_pow_succ {b : ℕ} (b_pos : 0 < b) (w m : ℕ)
: m % (b^succ w) = b * (m/b % b^w) + m % b :=
begin
apply nat.strong_induction_on m,
clear m,
intros p IH,
cases lt_or_ge p (b^succ w) with h₁ h₁,
-- base case: p < b^succ w
{ have h₂ : p / b < b^w,
{ rw [div_lt_iff_lt_mul p _ b_pos],
simpa [pow_succ'] using h₁ },
rw [mod_eq_of_lt h₁, mod_eq_of_lt h₂],
simp [mod_add_div, nat.add_comm] },
-- step: p ≥ b^succ w
{ -- Generate condition for induction hypothesis
have h₂ : p - b^succ w < p,
{ apply sub_lt_of_pos_le _ _ (pow_pos b_pos _) h₁ },
-- Apply induction
rw [mod_eq_sub_mod h₁, IH _ h₂],
-- Normalize goal and h1
simp only [pow_succ],
simp only [ge, pow_succ] at h₁,
-- Pull subtraction outside mod and div
rw [sub_mul_mod _ _ _ h₁, sub_mul_div _ _ _ h₁],
-- Cancel subtraction inside mod b^w
have p_b_ge : b^w ≤ p / b,
{ rw [le_div_iff_mul_le _ _ b_pos, mul_comm],
exact h₁ },
rw [eq.symm (mod_eq_sub_mod p_b_ge)] }
end
lemma pow_dvd_pow_iff_pow_le_pow {k l : ℕ} : Π {x : ℕ} (w : 0 < x), x^k ∣ x^l ↔ x^k ≤ x^l
| (x+1) w :=
begin
split,
{ intro a, exact le_of_dvd (pow_pos (succ_pos x) l) a, },
{ intro a, cases x with x,
{ simp only [one_pow], },
{ have le := (pow_le_iff_le_right (le_add_left _ _)).mp a,
use (x+2)^(l-k),
rw [←pow_add, add_comm k, nat.sub_add_cancel le], } }
end
/-- If `1 < x`, then `x^k` divides `x^l` if and only if `k` is at most `l`. -/
lemma pow_dvd_pow_iff_le_right {x k l : ℕ} (w : 1 < x) : x^k ∣ x^l ↔ k ≤ l :=
by rw [pow_dvd_pow_iff_pow_le_pow (lt_of_succ_lt w), pow_le_iff_le_right w]
lemma pow_dvd_pow_iff_le_right' {b k l : ℕ} : (b+2)^k ∣ (b+2)^l ↔ k ≤ l :=
pow_dvd_pow_iff_le_right (nat.lt_of_sub_eq_succ rfl)
lemma not_pos_pow_dvd : ∀ {p k : ℕ} (hp : 1 < p) (hk : 1 < k), ¬ p^k ∣ p
| (succ p) (succ k) hp hk h :=
have succ p * (succ p)^k ∣ succ p * 1, by simpa,
have (succ p) ^ k ∣ 1, from dvd_of_mul_dvd_mul_left (succ_pos _) this,
have he : (succ p) ^ k = 1, from eq_one_of_dvd_one this,
have k < (succ p) ^ k, from lt_pow_self hp k,
have k < 1, by rwa [he] at this,
have k = 0, from eq_zero_of_le_zero $ le_of_lt_succ this,
have 1 < 1, by rwa [this] at hk,
absurd this dec_trivial
lemma pow_dvd_of_le_of_pow_dvd {p m n k : ℕ} (hmn : m ≤ n) (hdiv : p ^ n ∣ k) : p ^ m ∣ k :=
have p ^ m ∣ p ^ n, from pow_dvd_pow _ hmn,
dvd_trans this hdiv
lemma dvd_of_pow_dvd {p k m : ℕ} (hk : 1 ≤ k) (hpk : p^k ∣ m) : p ∣ m :=
by rw ←pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk
/-- `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)` for some `k`. -/
lemma exists_lt_and_lt_iff_not_dvd (m : ℕ) {n : ℕ} (hn : 0 < n) :
(∃ k, n * k < m ∧ m < n * (k + 1)) ↔ ¬ n ∣ m :=
begin
split,
{ rintro ⟨k, h1k, h2k⟩ ⟨l, rfl⟩, rw [mul_lt_mul_left hn] at h1k h2k,
rw [lt_succ_iff, ← not_lt] at h2k, exact h2k h1k },
{ intro h, rw [dvd_iff_mod_eq_zero, ← ne.def, ← pos_iff_ne_zero] at h,
simp only [← mod_add_div m n] {single_pass := tt},
refine ⟨m / n, lt_add_of_pos_left _ h, _⟩,
rw [add_comm _ 1, left_distrib, mul_one], exact add_lt_add_right (mod_lt _ hn) _ }
end
/-! ### `find` -/
section find
lemma find_eq_iff {p : ℕ → Prop} [decidable_pred p] (h : ∃ n, p n) {m} :
nat.find h = m ↔ p m ∧ ∀ n < m, ¬ p n :=
begin
split,
{ rintro rfl, exact ⟨nat.find_spec h, λ _, nat.find_min h⟩ },
{ rintro ⟨hm, hlt⟩,
exact le_antisymm (nat.find_min' h hm) (not_lt.1 $ imp_not_comm.1 (hlt _) $ nat.find_spec h) }
end
@[simp] lemma find_eq_zero {p : ℕ → Prop} [decidable_pred p] (h : ∃ (n : ℕ), p n) :
nat.find h = 0 ↔ p 0 :=
by simp [find_eq_iff]
@[simp] lemma find_pos {p : ℕ → Prop} [decidable_pred p] (h : ∃ (n : ℕ), p n) :
0 < nat.find h ↔ ¬ p 0 :=
by rw [nat.pos_iff_ne_zero, not_iff_not, nat.find_eq_zero]
end find
/-! ### `find_greatest` -/
section find_greatest
/-- `find_greatest P b` is the largest `i ≤ bound` such that `P i` holds, or `0` if no such `i`
exists -/
protected def find_greatest (P : ℕ → Prop) [decidable_pred P] : ℕ → ℕ
| 0 := 0
| (n + 1) := if P (n + 1) then n + 1 else find_greatest n
variables {P : ℕ → Prop} [decidable_pred P]
@[simp] lemma find_greatest_zero : nat.find_greatest P 0 = 0 := rfl
@[simp] lemma find_greatest_eq : ∀{b}, P b → nat.find_greatest P b = b
| 0 h := rfl
| (n + 1) h := by simp [nat.find_greatest, h]
@[simp] lemma find_greatest_of_not {b} (h : ¬ P (b + 1)) :
nat.find_greatest P (b + 1) = nat.find_greatest P b :=
by simp [nat.find_greatest, h]
lemma find_greatest_eq_iff {b m} :
nat.find_greatest P b = m ↔ m ≤ b ∧ (m ≠ 0 → P m) ∧ (∀ ⦃n⦄, m < n → n ≤ b → ¬P n) :=
begin
induction b with b ihb generalizing m,
{ rw [eq_comm, iff.comm],
simp only [le_zero_iff_eq, ne.def, and_iff_left_iff_imp, find_greatest_zero],
rintro rfl,
exact ⟨λ h, (h rfl).elim, λ n hlt heq, (hlt.ne heq.symm).elim⟩ },
{ by_cases hb : P (b + 1),
{ rw [find_greatest_eq hb], split,
{ rintro rfl,
exact ⟨le_refl _, λ _, hb, λ n hlt hle, (hlt.not_le hle).elim⟩ },
{ rintros ⟨hle, h0, hm⟩,
rcases hle.eq_or_lt with rfl|hlt,
exacts [rfl, (hm hlt (le_refl _) hb).elim] } },
{ rw [find_greatest_of_not hb, ihb],
split,
{ rintros ⟨hle, hP, hm⟩,
refine ⟨hle.trans b.le_succ, hP, λ n hlt hle, _⟩,
rcases hle.eq_or_lt with rfl|hlt',
exacts [hb, hm hlt $ lt_succ_iff.1 hlt'] },
{ rintros ⟨hle, hP, hm⟩,
refine ⟨lt_succ_iff.1 (hle.lt_of_ne _), hP, λ n hlt hle, hm hlt (hle.trans b.le_succ)⟩,
rintro rfl,
exact hb (hP b.succ_ne_zero) } } }
end
lemma find_greatest_eq_zero_iff {b} :
nat.find_greatest P b = 0 ↔ ∀ ⦃n⦄, 0 < n → n ≤ b → ¬P n :=
by simp [find_greatest_eq_iff]
lemma find_greatest_spec {b} (h : ∃m, m ≤ b ∧ P m) : P (nat.find_greatest P b) :=
begin
rcases h with ⟨m, hmb, hm⟩,
by_cases h : nat.find_greatest P b = 0,
{ cases m, { rwa h },
exact ((find_greatest_eq_zero_iff.1 h) m.zero_lt_succ hmb hm).elim },
{ exact (find_greatest_eq_iff.1 rfl).2.1 h }
end
lemma find_greatest_le {b} : nat.find_greatest P b ≤ b :=
(find_greatest_eq_iff.1 rfl).1
lemma le_find_greatest {b m} (hmb : m ≤ b) (hm : P m) : m ≤ nat.find_greatest P b :=
le_of_not_lt $ λ hlt, (find_greatest_eq_iff.1 rfl).2.2 hlt hmb hm
lemma find_greatest_is_greatest {b k} (hk : nat.find_greatest P b < k) (hkb : k ≤ b) :
¬ P k :=
(find_greatest_eq_iff.1 rfl).2.2 hk hkb
lemma find_greatest_of_ne_zero {b m} (h : nat.find_greatest P b = m) (h0 : m ≠ 0) : P m :=
(find_greatest_eq_iff.1 h).2.1 h0
end find_greatest
/-! ### `bodd_div2` and `bodd` -/
@[simp] theorem bodd_div2_eq (n : ℕ) : bodd_div2 n = (bodd n, div2 n) :=
by unfold bodd div2; cases bodd_div2 n; refl
@[simp] lemma bodd_bit0 (n) : bodd (bit0 n) = ff := bodd_bit ff n
@[simp] lemma bodd_bit1 (n) : bodd (bit1 n) = tt := bodd_bit tt n
@[simp] lemma div2_bit0 (n) : div2 (bit0 n) = n := div2_bit ff n
@[simp] lemma div2_bit1 (n) : div2 (bit1 n) = n := div2_bit tt n
/-! ### `bit0` and `bit1` -/
protected theorem bit0_le {n m : ℕ} (h : n ≤ m) : bit0 n ≤ bit0 m :=
add_le_add h h
protected theorem bit1_le {n m : ℕ} (h : n ≤ m) : bit1 n ≤ bit1 m :=
succ_le_succ (add_le_add h h)
theorem bit_le : ∀ (b : bool) {n m : ℕ}, n ≤ m → bit b n ≤ bit b m
| tt n m h := nat.bit1_le h
| ff n m h := nat.bit0_le h
theorem bit_ne_zero (b) {n} (h : n ≠ 0) : bit b n ≠ 0 :=
by cases b; [exact nat.bit0_ne_zero h, exact nat.bit1_ne_zero _]
theorem bit0_le_bit : ∀ (b) {m n : ℕ}, m ≤ n → bit0 m ≤ bit b n
| tt m n h := le_of_lt $ nat.bit0_lt_bit1 h
| ff m n h := nat.bit0_le h
theorem bit_le_bit1 : ∀ (b) {m n : ℕ}, m ≤ n → bit b m ≤ bit1 n
| ff m n h := le_of_lt $ nat.bit0_lt_bit1 h
| tt m n h := nat.bit1_le h
theorem bit_lt_bit0 : ∀ (b) {n m : ℕ}, n < m → bit b n < bit0 m
| tt n m h := nat.bit1_lt_bit0 h
| ff n m h := nat.bit0_lt h
theorem bit_lt_bit (a b) {n m : ℕ} (h : n < m) : bit a n < bit b m :=
lt_of_lt_of_le (bit_lt_bit0 _ h) (bit0_le_bit _ (le_refl _))
@[simp] lemma bit0_le_bit1_iff : bit0 k ≤ bit1 n ↔ k ≤ n :=
⟨λ h, by rwa [← nat.lt_succ_iff, n.bit1_eq_succ_bit0, ← n.bit0_succ_eq,
bit0_lt_bit0, nat.lt_succ_iff] at h, λ h, le_of_lt (nat.bit0_lt_bit1 h)⟩
@[simp] lemma bit0_lt_bit1_iff : bit0 k < bit1 n ↔ k ≤ n :=
⟨λ h, bit0_le_bit1_iff.1 (le_of_lt h), nat.bit0_lt_bit1⟩
@[simp] lemma bit1_le_bit0_iff : bit1 k ≤ bit0 n ↔ k < n :=
⟨λ h, by rwa [k.bit1_eq_succ_bit0, succ_le_iff, bit0_lt_bit0] at h,
λ h, le_of_lt (nat.bit1_lt_bit0 h)⟩
@[simp] lemma bit1_lt_bit0_iff : bit1 k < bit0 n ↔ k < n :=
⟨λ h, bit1_le_bit0_iff.1 (le_of_lt h), nat.bit1_lt_bit0⟩
@[simp] lemma one_le_bit0_iff : 1 ≤ bit0 n ↔ 0 < n :=
by { convert bit1_le_bit0_iff, refl, }
@[simp] lemma one_lt_bit0_iff : 1 < bit0 n ↔ 1 ≤ n :=
by { convert bit1_lt_bit0_iff, refl, }
@[simp] lemma bit_le_bit_iff : ∀ {b : bool}, bit b k ≤ bit b n ↔ k ≤ n
| ff := bit0_le_bit0
| tt := bit1_le_bit1
@[simp] lemma bit_lt_bit_iff : ∀ {b : bool}, bit b k < bit b n ↔ k < n
| ff := bit0_lt_bit0
| tt := bit1_lt_bit1
@[simp] lemma bit_le_bit1_iff : ∀ {b : bool}, bit b k ≤ bit1 n ↔ k ≤ n
| ff := bit0_le_bit1_iff
| tt := bit1_le_bit1
@[simp] lemma bit0_mod_two : bit0 n % 2 = 0 := by { rw nat.mod_two_of_bodd, simp }
@[simp] lemma bit1_mod_two : bit1 n % 2 = 1 := by { rw nat.mod_two_of_bodd, simp }
lemma pos_of_bit0_pos {n : ℕ} (h : 0 < bit0 n) : 0 < n :=
by { cases n, cases h, apply succ_pos, }
/-- Define a function on `ℕ` depending on parity of the argument. -/
@[elab_as_eliminator]
def bit_cases {C : ℕ → Sort u} (H : Π b n, C (bit b n)) (n : ℕ) : C n :=
eq.rec_on n.bit_decomp (H (bodd n) (div2 n))
/-! ### `shiftl` and `shiftr` -/
lemma shiftl_eq_mul_pow (m) : ∀ n, shiftl m n = m * 2 ^ n
| 0 := (nat.mul_one _).symm
| (k+1) := show bit0 (shiftl m k) = m * (2 * 2 ^ k),
by rw [bit0_val, shiftl_eq_mul_pow, mul_left_comm]
lemma shiftl'_tt_eq_mul_pow (m) : ∀ n, shiftl' tt m n + 1 = (m + 1) * 2 ^ n
| 0 := by simp [shiftl, shiftl', pow_zero, nat.one_mul]
| (k+1) :=
begin
change bit1 (shiftl' tt m k) + 1 = (m + 1) * (2 * 2 ^ k),
rw bit1_val,
change 2 * (shiftl' tt m k + 1) = _,
rw [shiftl'_tt_eq_mul_pow, mul_left_comm]
end
lemma one_shiftl (n) : shiftl 1 n = 2 ^ n :=
(shiftl_eq_mul_pow _ _).trans (nat.one_mul _)
@[simp] lemma zero_shiftl (n) : shiftl 0 n = 0 :=
(shiftl_eq_mul_pow _ _).trans (nat.zero_mul _)
lemma shiftr_eq_div_pow (m) : ∀ n, shiftr m n = m / 2 ^ n
| 0 := (nat.div_one _).symm
| (k+1) := (congr_arg div2 (shiftr_eq_div_pow k)).trans $
by rw [div2_val, nat.div_div_eq_div_mul, mul_comm]; refl
@[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 :=
(shiftr_eq_div_pow _ _).trans (nat.zero_div _)
theorem shiftl'_ne_zero_left (b) {m} (h : m ≠ 0) (n) : shiftl' b m n ≠ 0 :=
by induction n; simp [shiftl', bit_ne_zero, *]
theorem shiftl'_tt_ne_zero (m) : ∀ {n} (h : n ≠ 0), shiftl' tt m n ≠ 0
| 0 h := absurd rfl h
| (succ n) _ := nat.bit1_ne_zero _
/-! ### `size` -/
@[simp] theorem size_zero : size 0 = 0 := rfl
@[simp] theorem size_bit {b n} (h : bit b n ≠ 0) : size (bit b n) = succ (size n) :=
begin
rw size,
conv { to_lhs, rw [binary_rec], simp [h] },
rw div2_bit,
end
@[simp] theorem size_bit0 {n} (h : n ≠ 0) : size (bit0 n) = succ (size n) :=
@size_bit ff n (nat.bit0_ne_zero h)
@[simp] theorem size_bit1 (n) : size (bit1 n) = succ (size n) :=
@size_bit tt n (nat.bit1_ne_zero n)
@[simp] theorem size_one : size 1 = 1 := by apply size_bit1 0
@[simp] theorem size_shiftl' {b m n} (h : shiftl' b m n ≠ 0) :
size (shiftl' b m n) = size m + n :=
begin
induction n with n IH; simp [shiftl'] at h ⊢,
rw [size_bit h, nat.add_succ],
by_cases s0 : shiftl' b m n = 0; [skip, rw [IH s0]],
rw s0 at h ⊢,
cases b, {exact absurd rfl h},
have : shiftl' tt m n + 1 = 1 := congr_arg (+1) s0,
rw [shiftl'_tt_eq_mul_pow] at this,
have m0 := succ.inj (eq_one_of_dvd_one ⟨_, this.symm⟩),
subst m0,
simp at this,
have : n = 0 := eq_zero_of_le_zero (le_of_not_gt $ λ hn,
ne_of_gt (pow_lt_pow_of_lt_right dec_trivial hn) this),
subst n, refl
end
@[simp] theorem size_shiftl {m} (h : m ≠ 0) (n) :
size (shiftl m n) = size m + n :=
size_shiftl' (shiftl'_ne_zero_left _ h _)
theorem lt_size_self (n : ℕ) : n < 2^size n :=
begin
rw [← one_shiftl],
have : ∀ {n}, n = 0 → n < shiftl 1 (size n) :=
λ n e, by subst e; exact dec_trivial,
apply binary_rec _ _ n, {apply this rfl},
intros b n IH,
by_cases bit b n = 0, {apply this h},
rw [size_bit h, shiftl_succ],
exact bit_lt_bit0 _ IH
end
theorem size_le {m n : ℕ} : size m ≤ n ↔ m < 2^n :=
⟨λ h, lt_of_lt_of_le (lt_size_self _) (pow_le_pow_of_le_right dec_trivial h),
begin
rw [← one_shiftl], revert n,
apply binary_rec _ _ m,
{ intros n h, apply zero_le },
{ intros b m IH n h,
by_cases e : bit b m = 0, { rw e, apply zero_le },
rw [size_bit e],
cases n with n,
{ exact e.elim (eq_zero_of_le_zero (le_of_lt_succ h)) },
{ apply succ_le_succ (IH _),
apply lt_imp_lt_of_le_imp_le (λ h', bit0_le_bit _ h') h } }
end⟩
theorem lt_size {m n : ℕ} : m < size n ↔ 2^m ≤ n :=
by rw [← not_lt, iff_not_comm, not_lt, size_le]
theorem size_pos {n : ℕ} : 0 < size n ↔ 0 < n :=
by rw lt_size; refl
theorem size_eq_zero {n : ℕ} : size n = 0 ↔ n = 0 :=
by have := @size_pos n; simp [pos_iff_ne_zero] at this;
exact not_iff_not.1 this
theorem size_pow {n : ℕ} : size (2^n) = n+1 :=
le_antisymm
(size_le.2 $ pow_lt_pow_of_lt_right dec_trivial (lt_succ_self _))
(lt_size.2 $ le_refl _)
theorem size_le_size {m n : ℕ} (h : m ≤ n) : size m ≤ size n :=
size_le.2 $ lt_of_le_of_lt h (lt_size_self _)
/-! ### decidability of predicates -/
instance decidable_ball_lt (n : nat) (P : Π k < n, Prop) :
∀ [H : ∀ n h, decidable (P n h)], decidable (∀ n h, P n h) :=
begin
induction n with n IH; intro; resetI,
{ exact is_true (λ n, dec_trivial) },
cases IH (λ k h, P k (lt_succ_of_lt h)) with h,
{ refine is_false (mt _ h), intros hn k h, apply hn },
by_cases p : P n (lt_succ_self n),
{ exact is_true (λ k h',
(lt_or_eq_of_le $ le_of_lt_succ h').elim (h _)
(λ e, match k, e, h' with _, rfl, h := p end)) },
{ exact is_false (mt (λ hn, hn _ _) p) }
end
instance decidable_forall_fin {n : ℕ} (P : fin n → Prop)
[H : decidable_pred P] : decidable (∀ i, P i) :=
decidable_of_iff (∀ k h, P ⟨k, h⟩) ⟨λ a ⟨k, h⟩, a k h, λ a k h, a ⟨k, h⟩⟩
instance decidable_ball_le (n : ℕ) (P : Π k ≤ n, Prop)
[H : ∀ n h, decidable (P n h)] : decidable (∀ n h, P n h) :=
decidable_of_iff (∀ k (h : k < succ n), P k (le_of_lt_succ h))
⟨λ a k h, a k (lt_succ_of_le h), λ a k h, a k _⟩
instance decidable_lo_hi (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] :
decidable (∀x, lo ≤ x → x < hi → P x) :=
decidable_of_iff (∀ x < hi - lo, P (lo + x))
⟨λal x hl hh, by have := al (x - lo) (lt_of_not_ge $
(not_congr (nat.sub_le_sub_right_iff _ _ _ hl)).2 $ not_le_of_gt hh);
rwa [nat.add_sub_of_le hl] at this,
λal x h, al _ (nat.le_add_right _ _) (nat.add_lt_of_lt_sub_left h)⟩
instance decidable_lo_hi_le (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] :
decidable (∀x, lo ≤ x → x ≤ hi → P x) :=
decidable_of_iff (∀x, lo ≤ x → x < hi + 1 → P x) $
ball_congr $ λ x hl, imp_congr lt_succ_iff iff.rfl
/-! ### find -/
theorem find_le {p q : ℕ → Prop} [decidable_pred p] [decidable_pred q]
(h : ∀ n, q n → p n) (hp : ∃ n, p n) (hq : ∃ n, q n) :
nat.find hp ≤ nat.find hq :=
nat.find_min' _ ((h _) (nat.find_spec hq))
end nat
|
4d94e87e53d4cb20a482eb6497eb555e405ba255
|
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
|
/src/ring_theory/ideal_operations.lean
|
b80f1a04f1f240ba23bee57c31e5c3870a493ccf
|
[
"Apache-2.0"
] |
permissive
|
johoelzl/mathlib
|
253f46daa30b644d011e8e119025b01ad69735c4
|
592e3c7a2dfbd5826919b4605559d35d4d75938f
|
refs/heads/master
| 1,625,657,216,488
| 1,551,374,946,000
| 1,551,374,946,000
| 98,915,829
| 0
| 0
|
Apache-2.0
| 1,522,917,267,000
| 1,501,524,499,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 20,234
|
lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
More operations on modules and ideals.
-/
import ring_theory.ideals data.nat.choose order.zorn
import linear_algebra.tensor_product
universes u v w x
open lattice
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
instance has_scalar' : has_scalar (ideal R) (submodule R M) :=
⟨λ I N, ⨆ r : I, N.map (r.1 • linear_map.id)⟩
def annihilator (N : submodule R M) : ideal R :=
(linear_map.lsmul R N).ker
def colon (N P : submodule R M) : ideal R :=
annihilator (P.map N.mkq)
variables {I J : ideal R} {N N₁ N₂ P P₁ P₂ : submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0:M) :=
⟨λ hr n hn, congr_arg subtype.val (linear_map.ext_iff.1 (linear_map.mem_ker.1 hr) ⟨n, hn⟩),
λ h, linear_map.mem_ker.2 $ linear_map.ext $ λ n, subtype.eq $ h n.1 n.2⟩
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • linear_map.id) ⊥ :=
mem_annihilator.trans ⟨λ H n hn, (mem_bot R).2 $ H n hn, λ H n hn, (mem_bot R).1 $ H hn⟩
theorem annihilator_bot : (⊥ : submodule R M).annihilator = ⊤ :=
(ideal.eq_top_iff_one _).2 $ mem_annihilator'.2 bot_le
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ :=
⟨λ H, eq_bot_iff.2 $ λ (n:M) hn, (mem_bot R).2 $ one_smul R n ▸ mem_annihilator.1 ((ideal.eq_top_iff_one _).1 H) n hn,
λ H, H.symm ▸ annihilator_bot⟩
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator :=
λ r hrp, mem_annihilator.2 $ λ n hn, mem_annihilator.1 hrp n $ h hn
theorem annihilator_supr (ι : Type w) (f : ι → submodule R M) :
(annihilator ⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_infi $ λ i, annihilator_mono $ le_supr _ _)
(λ r H, mem_annihilator'.2 $ supr_le $ λ i,
have _ := (mem_infi _).1 H i, mem_annihilator'.1 this)
theorem mem_colon {r} : r ∈ N.colon P ↔ ∀ p ∈ P, r • p ∈ N :=
mem_annihilator.trans ⟨λ H p hp, (quotient.mk_eq_zero N).1 (H (quotient.mk p) (mem_map_of_mem hp)),
λ H m ⟨p, hp, hpm⟩, hpm ▸ (N.mkq).map_smul r p ▸ (quotient.mk_eq_zero N).2 $ H p hp⟩
theorem mem_colon' {r} : r ∈ N.colon P ↔ P ≤ comap (r • linear_map.id) N :=
mem_colon
theorem colon_mono (hn : N₁ ≤ N₂) (hp : P₁ ≤ P₂) : N₁.colon P₂ ≤ N₂.colon P₁ :=
λ r hrnp, mem_colon.2 $ λ p₁ hp₁, hn $ mem_colon.1 hrnp p₁ $ hp hp₁
theorem infi_colon_supr (ι₁ : Type w) (f : ι₁ → submodule R M)
(ι₂ : Type x) (g : ι₂ → submodule R M) :
(⨅ i, f i).colon (⨆ j, g j) = ⨅ i j, (f i).colon (g j) :=
le_antisymm (le_infi $ λ i, le_infi $ λ j, colon_mono (infi_le _ _) (le_supr _ _))
(λ r H, mem_colon'.2 $ supr_le $ λ j, map_le_iff_le_comap.1 $ le_infi $ λ i,
map_le_iff_le_comap.2 $ mem_colon'.1 $ have _ := ((mem_infi _).1 H i),
have _ := ((mem_infi _).1 this j), this)
theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N :=
(le_supr _ ⟨r, hr⟩ : _ ≤ I • N) ⟨n, hn, rfl⟩
theorem smul_le {P : submodule R M} : I • N ≤ P ↔ ∀ (r ∈ I) (n ∈ N), r • n ∈ P :=
⟨λ H r hr n hn, H $ smul_mem_smul hr hn,
λ H, supr_le $ λ r, map_le_iff_le_comap.2 $ λ n hn, H r.1 r.2 n hn⟩
@[elab_as_eliminator]
theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N)
(Hb : ∀ (r ∈ I) (n ∈ N), p (r • n)) (H0 : p 0)
(H1 : ∀ x y, p x → p y → p (x + y))
(H2 : ∀ (c:R) n, p n → p (c • n)) : p x :=
(@smul_le _ _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hb H
theorem smul_le_right : I • N ≤ N :=
smul_le.2 $ λ r hr n, N.smul_mem r
theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P :=
smul_le.2 $ λ r hr n hn, smul_mem_smul (hij hr) (hnp hn)
theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N :=
smul_mono h (le_refl N)
theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P :=
smul_mono (le_refl I) h
variables (I J N P)
theorem smul_bot : I • (⊥ : submodule R M) = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hri s hsb,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hsb).symm ▸ smul_zero r
theorem bot_smul : (⊥ : ideal R) • N = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hrb s hsi,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hrb).symm ▸ zero_smul _ s
theorem top_smul : (⊤ : ideal R) • N = N :=
le_antisymm smul_le_right $ λ r hri, one_smul R r ▸ smul_mem_smul mem_top hri
theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P :=
le_antisymm (smul_le.2 $ λ r hri m hmnp, let ⟨n, hn, p, hp, hnpm⟩ := mem_sup.1 hmnp in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hri hp, hnpm ▸ (smul_add _ _ _).symm⟩)
(sup_le (smul_mono_right le_sup_left)
(smul_mono_right le_sup_right))
theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N :=
le_antisymm (smul_le.2 $ λ r hrij n hn, let ⟨ri, hri, rj, hrj, hrijr⟩ := mem_sup.1 hrij in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hrj hn, hrijr ▸ (add_smul _ _ _).symm⟩)
(sup_le (smul_mono_left le_sup_left)
(smul_mono_left le_sup_right))
theorem smul_assoc : (I • J) • N = I • (J • N) :=
le_antisymm (smul_le.2 $ λ rs hrsij t htn,
smul_induction_on hrsij
(λ r hr s hs, (@smul_eq_mul R _ r s).symm ▸ smul_smul _ r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn))
((zero_smul R t).symm ▸ submodule.zero_mem _)
(λ x y, (add_smul x y t).symm ▸ submodule.add_mem _)
(λ r s h, (@smul_eq_mul R _ r s).symm ▸ smul_smul _ r s t ▸ submodule.smul_mem _ _ h))
(smul_le.2 $ λ r hr sn hsn, suffices J • N ≤ submodule.comap (r • linear_map.id) ((I • J) • N), from this hsn,
smul_le.2 $ λ s hs n hn, show r • (s • n) ∈ (I • J) • N, from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn)
variables (S : set R) (T : set M)
theorem span_smul_span : (ideal.span S) • (span R T) =
span R (⋃ (s ∈ S) (t ∈ T), {s • t}) :=
le_antisymm (smul_le.2 $ λ r hrS n hnT, span_induction hrS
(λ r hrS, span_induction hnT
(λ n hnT, subset_span $ set.mem_bUnion hrS $
set.mem_bUnion hnT $ set.mem_singleton _)
((smul_zero r : r • 0 = (0:M)).symm ▸ submodule.zero_mem _)
(λ x y, (smul_add r x y).symm ▸ submodule.add_mem _)
(λ c m, by rw [smul_smul, mul_comm, mul_smul]; exact submodule.smul_mem _ _))
((zero_smul R n).symm ▸ submodule.zero_mem _)
(λ r s, (add_smul r s n).symm ▸ submodule.add_mem _)
(λ c r, by rw [smul_eq_mul, mul_smul]; exact submodule.smul_mem _ _)) $
span_le.2 $ set.bUnion_subset $ λ r hrS, set.bUnion_subset $ λ n hnT, set.singleton_subset_iff.2 $
smul_mem_smul (subset_span hrS) (subset_span hnT)
end submodule
namespace ideal
section mul_and_radical
variables {R : Type u} [comm_ring R]
variables {I J K L: ideal R}
instance : has_mul (ideal R) := ⟨(•)⟩
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
submodule.smul_mem_smul hr hs
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
theorem mul_le : I * J ≤ K ↔ ∀ (r ∈ I) (s ∈ J), r * s ∈ K :=
submodule.smul_le
variables (I J K)
protected theorem mul_comm : I * J = J * I :=
le_antisymm (mul_le.2 $ λ r hrI s hsJ, mul_mem_mul_rev hsJ hrI)
(mul_le.2 $ λ r hrJ s hsI, mul_mem_mul_rev hsI hrJ)
protected theorem mul_assoc : (I * J) * K = I * (J * K) :=
submodule.smul_assoc I J K
theorem span_mul_span (S T : set R) : span S * span T =
span ⋃ (s ∈ S) (t ∈ T), {s * t} :=
submodule.span_smul_span S T
variables {I J K}
theorem mul_le_inf : I * J ≤ I ⊓ J :=
mul_le.2 $ λ r hri s hsj, ⟨I.mul_mem_right hri, J.mul_mem_left hsj⟩
theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J :=
le_antisymm mul_le_inf $ λ r ⟨hri, hrj⟩,
let ⟨s, hsi, t, htj, hst⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in
mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj)
variables (I)
theorem mul_bot : I * ⊥ = ⊥ :=
submodule.smul_bot I
theorem bot_mul : ⊥ * I = ⊥ :=
submodule.bot_smul I
theorem mul_top : I * ⊤ = I :=
ideal.mul_comm ⊤ I ▸ submodule.top_smul I
theorem top_mul : ⊤ * I = I :=
submodule.top_smul I
variables {I}
theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L :=
submodule.smul_mono hik hjl
theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K :=
submodule.smul_mono_left h
theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K :=
submodule.smul_mono_right h
variables (I J K)
theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K :=
submodule.smul_sup I J K
theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K :=
submodule.sup_smul I J K
variables {I J K}
def radical (I : ideal R) : ideal R :=
{ carrier := { r | ∃ n : ℕ, r ^ n ∈ I },
zero := ⟨1, (pow_one (0:R)).symm ▸ I.zero_mem⟩,
add := λ x y ⟨m, hxmi⟩ ⟨n, hyni⟩, ⟨m + n,
(add_pow x y (m + n)).symm ▸ I.sum_mem $
show ∀ c ∈ finset.range (nat.succ (m + n)), x ^ c * y ^ (m + n - c) * (choose (m + n) c) ∈ I,
from λ c hc, or.cases_on (le_total c m)
(λ hcm, I.mul_mem_right $ I.mul_mem_left $ nat.add_comm n m ▸ (nat.add_sub_assoc hcm n).symm ▸
(pow_add y n (m-c)).symm ▸ I.mul_mem_right hyni)
(λ hmc, I.mul_mem_right $ I.mul_mem_right $ nat.add_sub_cancel' hmc ▸
(pow_add x m (c-m)).symm ▸ I.mul_mem_right hxmi)⟩,
smul := λ r s ⟨n, hsni⟩, ⟨n, show (r * s)^n ∈ I,
from (mul_pow r s n).symm ▸ I.mul_mem_left hsni⟩ }
theorem le_radical : I ≤ radical I :=
λ r hri, ⟨1, (pow_one r).symm ▸ hri⟩
variables (R)
theorem radical_top : (radical ⊤ : ideal R) = ⊤ :=
(eq_top_iff_one _).2 ⟨0, submodule.mem_top⟩
variables {R}
theorem radical_mono (H : I ≤ J) : radical I ≤ radical J :=
λ r ⟨n, hrni⟩, ⟨n, H hrni⟩
variables (I)
theorem radical_idem : radical (radical I) = radical I :=
le_antisymm (λ r ⟨n, k, hrnki⟩, ⟨n * k, (pow_mul r n k).symm ▸ hrnki⟩) le_radical
variables {I}
theorem radical_eq_top : radical I = ⊤ ↔ I = ⊤ :=
⟨λ h, (eq_top_iff_one _).2 $ let ⟨n, hn⟩ := (eq_top_iff_one _).1 h in
@one_pow R _ n ▸ hn, λ h, h.symm ▸ radical_top R⟩
theorem is_prime.radical (H : is_prime I) : radical I = I :=
le_antisymm (λ r ⟨n, hrni⟩, H.mem_of_pow_mem n hrni) le_radical
variables (I J)
theorem radical_sup : radical (I ⊔ J) = radical (radical I ⊔ radical J) :=
le_antisymm (radical_mono $ sup_le_sup le_radical le_radical) $
λ r ⟨n, hrnij⟩, let ⟨s, hs, t, ht, hst⟩ := submodule.mem_sup.1 hrnij in
@radical_idem _ _ (I ⊔ J) ▸ ⟨n, hst ▸ ideal.add_mem _
(radical_mono le_sup_left hs) (radical_mono le_sup_right ht)⟩
theorem radical_inf : radical (I ⊓ J) = radical I ⊓ radical J :=
le_antisymm (le_inf (radical_mono inf_le_left) (radical_mono inf_le_right))
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ I.mul_mem_right hrm,
(pow_add r m n).symm ▸ J.mul_mem_left hrn⟩)
theorem radical_mul : radical (I * J) = radical I ⊓ radical J :=
le_antisymm (radical_inf I J ▸ radical_mono $ @mul_le_inf _ _ I J)
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ mul_mem_mul hrm hrn⟩)
variables {I J}
theorem is_prime.radical_le_iff (hj : is_prime J) :
radical I ≤ J ↔ I ≤ J :=
⟨le_trans le_radical, λ hij r ⟨n, hrni⟩, hj.mem_of_pow_mem n $ hij hrni⟩
theorem radical_eq_Inf (I : ideal R) :
radical I = Inf { J : ideal R | I ≤ J ∧ is_prime J } :=
le_antisymm (le_Inf $ λ J hJ, hJ.2.radical_le_iff.2 hJ.1) $
λ r hr, classical.by_contradiction $ λ hri,
let ⟨m, (hrm : r ∉ radical m), him, hm⟩ := zorn.zorn_partial_order₀ {K : ideal R | r ∉ radical K}
(λ c hc hcc y hyc, ⟨Sup c, λ ⟨n, hrnc⟩, let ⟨y, hyc, hrny⟩ :=
submodule.mem_Sup_of_directed hrnc y hyc hcc.directed_on in hc hyc ⟨n, hrny⟩,
λ z, le_Sup⟩) I hri in
have ∀ x ∉ m, r ∈ radical (m ⊔ span {x}) := λ x hxm, classical.by_contradiction $ λ hrmx, hxm $
hm (m ⊔ span {x}) hrmx le_sup_left ▸ (le_sup_right : _ ≤ m ⊔ span {x}) (subset_span $ set.mem_singleton _),
have is_prime m, from ⟨by rintro rfl; rw radical_top at hrm; exact hrm trivial,
λ x y hxym, classical.or_iff_not_imp_left.2 $ λ hxm, classical.by_contradiction $ λ hym,
let ⟨n, hrn⟩ := this _ hxm, ⟨p, hpm, q, hq, hpqrn⟩ := submodule.mem_sup.1 hrn, ⟨c, hcxq⟩ := mem_span_singleton'.1 hq in
let ⟨k, hrk⟩ := this _ hym, ⟨f, hfm, g, hg, hfgrk⟩ := submodule.mem_sup.1 hrk, ⟨d, hdyg⟩ := mem_span_singleton'.1 hg in
hrm ⟨n + k, by rw [pow_add, ← hpqrn, ← hcxq, ← hfgrk, ← hdyg, add_mul, mul_add (c*x), mul_assoc c x (d*y), mul_left_comm x, ← mul_assoc];
refine m.add_mem (m.mul_mem_right hpm) (m.add_mem (m.mul_mem_left hfm) (m.mul_mem_left hxym))⟩⟩,
hrm $ this.radical.symm ▸ (Inf_le ⟨him, this⟩ : Inf {J : ideal R | I ≤ J ∧ is_prime J} ≤ m) hr
instance : comm_semiring (ideal R) :=
{ mul := (*),
mul_assoc := ideal.mul_assoc,
zero_mul := bot_mul,
mul_zero := mul_bot,
one := ⊤,
one_mul := top_mul,
mul_one := mul_top,
left_distrib := mul_sup,
right_distrib := sup_mul,
mul_comm := ideal.mul_comm,
.. submodule.add_comm_monoid }
@[simp] lemma add_eq_sup : I + J = I ⊔ J := rfl
@[simp] lemma zero_eq_bot : (0 : ideal R) = ⊥ := rfl
@[simp] lemma one_eq_top : (1 : ideal R) = ⊤ := rfl
variables (I)
theorem radical_pow (n : ℕ) (H : n > 0) : radical (I^n) = radical I :=
nat.rec_on n (not.elim dec_trivial) (λ n ih H,
or.cases_on (lt_or_eq_of_le $ nat.le_of_lt_succ H)
(λ H, calc radical (I^(n+1))
= radical I ⊓ radical (I^n) : radical_mul _ _
... = radical I ⊓ radical I : by rw ih H
... = radical I : inf_idem)
(λ H, H ▸ (pow_one I).symm ▸ rfl)) H
end mul_and_radical
section map_and_comap
variables {R : Type u} {S : Type v} [comm_ring R] [comm_ring S]
variables (f : R → S) [is_ring_hom f]
variables {I J : ideal R} {K L : ideal S}
def map (I : ideal R) : ideal S :=
span (f '' I)
def comap (I : ideal S) : ideal R :=
{ carrier := f ⁻¹' I,
zero := show f 0 ∈ I, by rw is_ring_hom.map_zero f; exact I.zero_mem,
add := λ x y hx hy, show f (x + y) ∈ I, by rw is_ring_hom.map_add f; exact I.add_mem hx hy,
smul := λ c x hx, show f (c * x) ∈ I, by rw is_ring_hom.map_mul f; exact I.mul_mem_left hx }
variables {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono $ set.image_subset _ h
theorem mem_map_of_mem {x} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem map_le_iff_le_comap :
map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans set.image_subset_iff
@[simp] theorem mem_comap {x} : x ∈ comap f K ↔ f x ∈ K := iff.rfl
theorem comap_mono (h : K ≤ L) : comap f K ≤ comap f L :=
set.preimage_mono h
variables (f)
theorem comap_ne_top (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 $ by rw [mem_comap, is_ring_hom.map_one f];
exact (ne_top_iff_one _).1 hK
instance is_prime.comap {hK : K.is_prime} : (comap f K).is_prime :=
⟨comap_ne_top _ hK.1, λ x y,
by simp only [mem_comap, is_ring_hom.map_mul f]; apply hK.2⟩
variables (I J K L)
theorem map_bot : map f ⊥ = ⊥ :=
le_antisymm (map_le_iff_le_comap.2 bot_le) bot_le
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 $ subset_span ⟨1, trivial, is_ring_hom.map_one f⟩
theorem comap_top : comap f ⊤ = ⊤ :=
(eq_top_iff_one _).2 trivial
theorem map_sup : map f (I ⊔ J) = map f I ⊔ map f J :=
le_antisymm (map_le_iff_le_comap.2 $ sup_le
(map_le_iff_le_comap.1 le_sup_left)
(map_le_iff_le_comap.1 le_sup_right))
(sup_le (map_mono le_sup_left) (map_mono le_sup_right))
theorem map_mul : map f (I * J) = map f I * map f J :=
le_antisymm (map_le_iff_le_comap.2 $ mul_le.2 $ λ r hri s hsj,
show f (r * s) ∈ _, by rw is_ring_hom.map_mul f;
exact mul_mem_mul (mem_map_of_mem hri) (mem_map_of_mem hsj))
(trans_rel_right _ (span_mul_span _ _) $ span_le.2 $
set.bUnion_subset $ λ i ⟨r, hri, hfri⟩,
set.bUnion_subset $ λ j ⟨s, hsj, hfsj⟩,
set.singleton_subset_iff.2 $ hfri ▸ hfsj ▸
by rw [← is_ring_hom.map_mul f];
exact mem_map_of_mem (mul_mem_mul hri hsj))
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl
theorem comap_radical : comap f (radical K) = radical (comap f K) :=
le_antisymm (λ r ⟨n, hfrnk⟩, ⟨n, show f (r ^ n) ∈ K,
from (is_semiring_hom.map_pow f r n).symm ▸ hfrnk⟩)
(λ r ⟨n, hfrnk⟩, ⟨n, is_semiring_hom.map_pow f r n ▸ hfrnk⟩)
variables {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
map_le_iff_le_comap.2 $ (comap_inf f (map f I) (map f J)).symm ▸
inf_le_inf (map_le_iff_le_comap.1 $ le_refl _) (map_le_iff_le_comap.1 $ le_refl _)
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 $ λ r ⟨n, hrni⟩, ⟨n, is_semiring_hom.map_pow f r n ▸ mem_map_of_mem hrni⟩
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
map_le_iff_le_comap.1 $ (map_sup f (comap f K) (comap f L)).symm ▸
sup_le_sup (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 $ (map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)
section surjective
variables (hf : function.surjective f)
include hf
theorem map_comap_of_surjective (I : ideal S) :
map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 (le_refl _))
(λ s hsi, let ⟨r, hfrs⟩ := hf s in
hfrs ▸ (mem_map_of_mem $ show f r ∈ I, from hfrs.symm ▸ hsi))
theorem mem_image_of_mem_map_of_surjective {I : ideal R} {y}
(H : y ∈ map f I) : y ∈ f '' I :=
submodule.span_induction H (λ _, id) ⟨0, I.zero_mem, is_ring_hom.map_zero f⟩
(λ y1 y2 ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩, ⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ is_ring_hom.map_add f⟩)
(λ c y ⟨x, hxi, hxy⟩, let ⟨d, hdc⟩ := hf c in ⟨d • x, I.smul_mem _ hxi, hdc ▸ hxy ▸ is_ring_hom.map_mul f⟩)
theorem comap_map_of_surjective (I : ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm (assume r h, let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h in
submodule.mem_sup.2 ⟨s, hsi, r - s, (submodule.mem_bot S).2 $ by rw [is_ring_hom.map_sub f, hfsr, sub_self],
add_sub_cancel'_right s r⟩)
(sup_le (map_le_iff_le_comap.1 (le_refl _)) (comap_mono bot_le))
/-- Correspondence theorem -/
def order_iso_of_surjective :
((≤) : ideal S → ideal S → Prop) ≃o
((≤) : { p : ideal R // comap f ⊥ ≤ p } → { p : ideal R // comap f ⊥ ≤ p } → Prop) :=
{ to_fun := λ J, ⟨comap f J, comap_mono bot_le⟩,
inv_fun := λ I, map f I.1,
left_inv := λ J, map_comap_of_surjective f hf J,
right_inv := λ I, subtype.eq $ show comap f (map f I.1) = I.1,
from (comap_map_of_surjective f hf I).symm ▸ le_antisymm
(sup_le (le_refl _) I.2) le_sup_left,
ord := λ I1 I2, ⟨comap_mono, λ H, map_comap_of_surjective f hf I1 ▸
map_comap_of_surjective f hf I2 ▸ map_mono H⟩ }
def le_order_embedding_of_surjective :
((≤) : ideal S → ideal S → Prop) ≼o ((≤) : ideal R → ideal R → Prop) :=
(order_iso_of_surjective f hf).to_order_embedding.trans (subtype.order_embedding _ _)
def lt_order_embedding_of_surjective :
((<) : ideal S → ideal S → Prop) ≼o ((<) : ideal R → ideal R → Prop) :=
(le_order_embedding_of_surjective f hf).lt_embedding_of_le_embedding
end surjective
end map_and_comap
end ideal
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
variables (I J : ideal R) (N P : submodule R M)
instance : semimodule (ideal R) (submodule R M) :=
{ smul_add := smul_sup,
add_smul := sup_smul,
mul_smul := smul_assoc,
one_smul := top_smul,
zero_smul := bot_smul,
smul_zero := smul_bot }
end submodule
|
c1896383ba84df4a06e66a4fa4e6d4ccd7d31c65
|
ee8cdbabf07f77e7be63a449b8483ce308d37218
|
/lean/src/valid/mathd-algebra-96.lean
|
50a83820f53bd6a0f4245fabfa553a4b054f70a2
|
[
"Apache-2.0",
"MIT"
] |
permissive
|
zeta1999/miniF2F
|
6d66c75d1c18152e224d07d5eed57624f731d4b7
|
c1ba9629559c5273c92ec226894baa0c1ce27861
|
refs/heads/main
| 1,681,897,460,642
| 1,620,646,361,000
| 1,620,646,361,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 422
|
lean
|
/-
Copyright (c) 2021 OpenAI. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kunhao Zheng
-/
import data.real.basic
import analysis.special_functions.exp_log
example (x y z a : ℝ) (h₀ : 0 < x ∧ 0 < y ∧ 0 < z ∧ 0 < a) (h₁ : real.log x - real.log y = a) (h₂ : real.log y - real.log z = 15) (h₃ : real.log z - real.log x = -7) : a = -8 :=
begin
sorry
end
|
fe3b749a6e7de09f059782f2925d097ca9f176ca
|
c31182a012eec69da0a1f6c05f42b0f0717d212d
|
/src/prop819.lean
|
1a8dc93c5b627aee96d86bdd13c01b18cf9e1086
|
[] |
no_license
|
Ja1941/lean-liquid
|
fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc
|
8e80ed0cbdf5145d6814e833a674eaf05a1495c1
|
refs/heads/master
| 1,689,437,983,362
| 1,628,362,719,000
| 1,628,362,719,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 20,196
|
lean
|
import algebra.homology.homological_complex
import topology.category.Profinite.cofiltered_limit
import for_mathlib.Cech.split
import for_mathlib.Profinite.arrow_limit
import for_mathlib.Profinite.clopen_limit
import for_mathlib.simplicial.complex
import locally_constant.Vhat
import prop819.completion
--import prop819.locally_constant
open_locale nnreal
noncomputable theory
open category_theory opposite
open SemiNormedGroup
universes u
-- We have a surjective morphism of profinite sets.
variables (F : arrow Profinite.{u}) (surj : function.surjective F.hom)
variables (M : SemiNormedGroup.{u})
/-- The cochain complex built out of the cosimplicial object obtained by applying
`LocallyConstant.obj M` to the augmented Cech nerve of `F`. -/
abbreviation FL : cochain_complex SemiNormedGroup ℕ :=
(((cosimplicial_object.augmented.whiskering _ _).obj (LocallyConstant.{u u}.obj M)).obj
F.augmented_cech_nerve.right_op).to_cocomplex
/-- The cochain complex built out of the cosimplicial object obtained by applying
`LCC.obj M` to the augmented Cech nerve of `F`. -/
abbreviation FLC : cochain_complex SemiNormedGroup ℕ :=
(((cosimplicial_object.augmented.whiskering _ _).obj (LCC.{u u}.obj M)).obj
F.augmented_cech_nerve.right_op).to_cocomplex
--def Rop : (simplicial_object.augmented Profinite)ᵒᵖ ⥤ cosimplicial_object.augmented Profiniteᵒᵖ :=
--{ obj := λ X, X.unop.right_op,
-- map := λ X Y f,
-- { left := quiver.hom.op (comma_morphism.right f.unop),
-- right := nat_trans.right_op (comma_morphism.left f.unop),
-- w' := by { ext, exact congr_arg (λ η, (nat_trans.app η (op x)).op) f.unop.w.symm, } } }
/-- A functorial version of `FL`. -/
def FL_functor : (arrow Profinite.{u})ᵒᵖ ⥤ cochain_complex SemiNormedGroup ℕ :=
simplicial_object.augmented_cech_nerve.op ⋙
simplicial_to_cosimplicial_augmented _ ⋙
(cosimplicial_object.augmented.whiskering _ _).obj (LocallyConstant.obj M) ⋙
cosimplicial_object.augmented.cocomplex
/-- The functor sending an augmented cosimplicial object `X` to
the cochain complex associated to the composition of `X` with `LCC.obj M`. -/
@[simps obj map]
def FLC_functor' : (simplicial_object.augmented Profinite.{u})ᵒᵖ ⥤ cochain_complex SemiNormedGroup ℕ :=
simplicial_to_cosimplicial_augmented _ ⋙
(cosimplicial_object.augmented.whiskering _ _).obj (SemiNormedGroup.LCC.{u u}.obj M) ⋙
cosimplicial_object.augmented.cocomplex
/-- A functorial version of `FLC`. -/
def FLC_functor : (arrow Profinite.{u})ᵒᵖ ⥤ cochain_complex SemiNormedGroup ℕ :=
simplicial_object.augmented_cech_nerve.op ⋙ FLC_functor' M
-- Sanity checks
example : FL F M = (FL_functor M).obj (op F) := rfl
example : FLC F M = (FLC_functor M).obj (op F) := rfl
lemma _root_.cosimplicial_object.augmented.cocomplex_map_norm_noninc
{C₁ C₂ : cosimplicial_object.augmented SemiNormedGroup} (f : C₁ ⟶ C₂)
(hf1 : f.left.norm_noninc) (hf2 : ∀ n, (f.right.app n).norm_noninc) (i : ℕ) :
((cosimplicial_object.augmented.cocomplex.map f).f i).norm_noninc :=
begin
cases i,
{ exact hf1 },
{ exact hf2 _ },
end
lemma FLC_functor_map_norm_noninc {f g : (arrow Profinite.{u})ᵒᵖ} (α : f ⟶ g) (i : ℕ) :
(((FLC_functor M).map α).f i).norm_noninc :=
begin
refine cosimplicial_object.augmented.cocomplex_map_norm_noninc _ _ _ _,
{ exact SemiNormedGroup.LCC_obj_map_norm_noninc _ _ },
{ intro n,
exact SemiNormedGroup.LCC_obj_map_norm_noninc _ _ },
end
--⊢ cosimplicial_object.δ
-- (functor.right_op F.cech_nerve ⋙ (curry.obj (uncurry.obj LocallyConstant ⋙ Completion)).obj M)
-- k =
-- Completion.map (cosimplicial_object.δ (functor.right_op F.cech_nerve ⋙ LocallyConstant.obj M) k)
lemma FLC_iso_helper {x y : simplex_category} (f : x ⟶ y) :
(F.cech_nerve.right_op ⋙ LCC.obj M).map f =
Completion.map ((F.cech_nerve.right_op ⋙ LocallyConstant.obj M).map f) :=
begin
change Completion.map _ = _,
congr' 1,
dsimp [uncurry],
erw locally_constant.map_hom_id,
change 𝟙 _ ≫ _ = _,
rw category.id_comp,
end
/--
This is a strict (i.e. norm-preserving) isomorphism between `FLC F M` and
the cochain complex obtained by mapping `FL F M` along the `Completion` functor.
-/
def FLC_iso : strict_iso ((Completion.map_homological_complex _).obj (FL F M)) (FLC F M) :=
{ iso := homological_complex.hom.iso_of_components
(λ i, nat.rec_on i (eq_to_iso rfl) (λ _ _, eq_to_iso rfl))
begin
rintro (_|i) (_|j) (_|⟨i,w⟩); ext,
{ dsimp only [],
delta FLC FL,
dsimp only [
cosimplicial_object.augmented.whiskering,
cosimplicial_object.augmented.whiskering_obj,
cosimplicial_object.augmented.to_cocomplex,
cosimplicial_object.augmented.to_cocomplex_obj,
cochain_complex.of,
functor.map_homological_complex ],
rw dif_pos rfl,
rw dif_pos rfl,
erw [category.id_comp, category.comp_id, category.comp_id, category.comp_id],
dsimp only [cosimplicial_object.augmented.to_cocomplex_d,
cosimplicial_object.augmented.drop, comma.snd, cosimplicial_object.whiskering,
whiskering_right, cosimplicial_object.coboundary, functor.const_comp, LCC],
simp only [quiver.hom.unop_op, arrow.augmented_cech_nerve_hom_app,
whisker_right_app, nat_trans.comp_app, curry.obj_obj_map, category.id_comp,
nat_trans.right_op_app, uncurry.obj_map, nat_trans.id_app,
simplicial_object.augmented.right_op_hom,
category_theory.functor.map_id, category_theory.functor.comp_map,
SemiNormedGroup.LocallyConstant_obj_map, SemiNormedGroup.Completion_map],
erw category.id_comp },
{ dsimp only [],
delta FLC FL,
dsimp only [
cosimplicial_object.augmented.whiskering,
cosimplicial_object.augmented.whiskering_obj,
cosimplicial_object.augmented.to_cocomplex,
cosimplicial_object.augmented.to_cocomplex_obj,
cochain_complex.of,
functor.map_homological_complex ],
rw dif_pos rfl,
rw dif_pos rfl,
erw [category.id_comp, category.comp_id, category.comp_id, category.comp_id],
dsimp only [
cosimplicial_object.augmented.to_cocomplex_d,
cosimplicial_object.augmented.drop,
comma.snd,
cosimplicial_object.whiskering,
whiskering_right,
cosimplicial_object.coboundary,
LCC ],
rw [Completion.map_sum],
congr,
funext k,
rw [Completion.map_gsmul],
congr' 1,
apply FLC_iso_helper }
end,
is_strict := λ i, { strict_hom' := λ a, by { cases i; refl } } }.
open_locale simplicial
-- TODO: Move this to mathlib (also relax the has_limits condition).
/-- the isomorphism between the 0-th term of the Cech nerve and F.left-/
@[simps]
def cech_iso_zero {C : Type*} [category C] (F : arrow C) [limits.has_limits C]
: F.cech_nerve _[0] ≅ F.left :=
{ hom := limits.wide_pullback.π _ ⟨0⟩,
inv := limits.wide_pullback.lift F.hom (λ _, 𝟙 _) (by simp),
hom_inv_id' := begin
apply limits.wide_pullback.hom_ext,
{ intro i,
simp only [limits.wide_pullback.lift_π, category.id_comp, category.comp_id, category.assoc],
congr,
tidy },
{ simp }
end }
lemma augmentation_zero {C : Type*} [category C] (F : arrow C) [limits.has_limits C] :
(cech_iso_zero F).inv ≫ F.augmented_cech_nerve.hom.app _ = F.hom := by tidy
lemma locally_constant_norm_empty (X : Profinite) (hX : ¬ nonempty X)
(g : (LocallyConstant.obj M).obj (op X)) : ∥ g ∥ = 0 :=
begin
rw locally_constant.norm_def,
dsimp [supr],
suffices : set.range (λ x : ↥X, ∥ g.to_fun x ∥) = ∅,
{ erw [this, real.Sup_empty], },
simp only [set.range_eq_empty, not_nonempty_iff],
exact not_nonempty_iff.mp hX
end
lemma Profinite.coe_comp_apply {X Y Z : Profinite} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) :
(f ≫ g) x = g (f x) := rfl
lemma locally_constant_to_fun_eq {X : Profinite} (f : locally_constant X M) :
f.to_fun = f := rfl
lemma locally_constant_eq {X : Profinite} (f g : locally_constant X M) :
f.to_fun = g.to_fun ↔ f = g :=
begin
split,
{ intro h, ext, change f.to_fun _ = _, rw h, refl, },
{ intro h, rw h }
end
lemma locally_constant_eq_zero {X : Profinite} (f : locally_constant X M) :
f = 0 ↔ set.range f.to_fun ⊆ {0} :=
begin
split,
{ intro h, rw h, simp, },
{ intro h, ext x,
dsimp,
apply h,
use x,
refl }
end
include surj
lemma prop819_degree_zero_helper :
function.surjective (limits.wide_pullback.base (λ i : ulift (fin 1), F.hom)) :=
begin
intro x,
obtain ⟨x,rfl⟩ := surj x,
dsimp at *,
refine ⟨(cech_iso_zero F).inv x, _⟩,
dsimp,
change (limits.wide_pullback.lift F.hom _ _ ≫ limits.wide_pullback.base _) _ = _,
simp,
end
lemma prop819_zero_norm_le (g : (LocallyConstant.obj M).obj (op F.right)) : ∥ g ∥ ≤
∥(LocallyConstant.obj M).map (limits.wide_pullback.base (λ i : ulift (fin 1), F.hom)).op g∥ :=
begin
by_cases hh : nonempty F.right,
{ apply cSup_le,
{ rcases hh with ⟨x⟩,
refine ⟨∥g.to_fun x∥, x, rfl⟩ },
{ rintros z ⟨z,rfl⟩,
obtain ⟨z,rfl⟩ := (prop819_degree_zero_helper _ surj) z,
change ∥g.to_fun _∥ ≤ _,
erw ← LocallyConstant_map_apply M _ F.right (limits.wide_pullback.base (λ i, F.hom)) g z,
apply locally_constant.norm_apply_le } },
{ rw locally_constant_norm_empty _ _ hh g,
simp }
end
theorem prop819_degree_zero (f : (FLC F M).X 0) (hf : (FLC F M).d 0 1 f = 0) :
f = 0 :=
begin
apply injective_of_strict_iso _ _ (FLC_iso F M) _ _ hf,
intros f hf,
have := @controlled_exactness ((FL F M).X 0) (0 : SemiNormedGroup) ((FL F M).X 1) _ _ _ 0 1
zero_lt_one 1 ((FL F M).d _ _) _ _ 1 zero_lt_one f _,
{ rcases this with ⟨g,h1,h2⟩,
rw ← h1,
simp },
{ intros g hg,
refine ⟨0,_, by simp⟩,
change (FL F M).d 0 1 g = 0 at hg,
dsimp,
symmetry,
delta FL at hg,
dsimp only [cosimplicial_object.augmented.whiskering,
cosimplicial_object.augmented.whiskering_obj,
cosimplicial_object.augmented.to_cocomplex,
cochain_complex.of] at hg,
rw dif_pos at hg,
swap, {simp},
dsimp [cosimplicial_object.augmented.to_cocomplex_d] at hg,
ext x,
obtain ⟨x,rfl⟩ := (prop819_degree_zero_helper F surj) x,
apply_fun (λ e, e x) at hg,
rw locally_constant.coe_comap at hg,
swap, { continuity },
exact hg },
{ rintro g ⟨g,rfl⟩,
refine ⟨g,rfl,_⟩,
dsimp [cosimplicial_object.augmented.to_cocomplex_d],
simp only [locally_constant.comap_hom_apply, one_mul,
if_true, eq_self_iff_true, category.id_comp, category.comp_id],
apply prop819_zero_norm_le _ surj },
{ exact hf }
end
.
/-- Any discrete quotient `S` of `F.left` yields a cochain complex, as follows.
First, let `T` be the maximal quotient of `F.right` such that `F.hom : F.left ⟶ F.right`
descends to `S → T`. Next construct the augmented Cech nerve of `S → T`, and finally
apply `FL_functor M` to this augmented Cech nerve.
-/
def FLF : (discrete_quotient F.left)ᵒᵖ ⥤ cochain_complex SemiNormedGroup ℕ :=
(Profinite.arrow_diagram F surj).op ⋙ FL_functor M
/--
The diagram of cochain complexes given by `FLF F surj` fits together into a cocone
whose cocone point is defeq to `FL F M`. This is precisely this cocone.
-/
def FLF_cocone : limits.cocone (FLF F surj M) :=
(FL_functor M).map_cocone $ (Profinite.arrow_cone F surj).op
open Profinite
lemma exists_locally_constant_FLF (n : ℕ) (f : (FL F M).X (n+1)) :
∃ (S : discrete_quotient F.left) (g : ((FLF F surj M).obj (op S)).X (n+1)),
((FLF_cocone F surj M).ι.app (op S)).f _ g = f :=
begin
have hC := Cech_cone_is_limit F surj n,
obtain ⟨i,g,hg⟩ := Profinite.exists_locally_constant _ hC f,
use [i, g],
exact hg.symm,
end
lemma FLF_cocone_app_coe_eq (n : ℕ) (S : discrete_quotient F.left)
(g : ((FLF F surj M).obj (op S)).X (n+1)) :
(((FLF_cocone F surj M).ι.app (op S)).f _ g).to_fun =
g.to_fun ∘ ((Cech_cone F surj n).π.app _) :=
begin
ext x,
change locally_constant.comap _ _ _ = _,
rw locally_constant.coe_comap,
swap, { continuity },
refl,
end
lemma FLF_map_coe_eq (n : ℕ) (S T : discrete_quotient F.left) (hh : T ≤ S)
(g : ((FLF F surj M).obj (op S)).X (n+1)) :
(((FLF F surj M).map (hom_of_le hh).op).f _ g).to_fun =
g.to_fun ∘ ((Cech_cone_diagram F surj n).map (hom_of_le hh)) :=
begin
ext x,
change locally_constant.comap _ _ _ = _,
rw locally_constant.coe_comap,
swap, { continuity },
refl,
end
lemma eq_zero_FLF (n : ℕ) (S : discrete_quotient F.left)
(g : ((FLF F surj M).obj (op S)).X (n+1))
(hg : ((FLF_cocone F surj M).ι.app (op S)).f _ g = 0) :
∃ (T : discrete_quotient F.left) (hT : T ≤ S),
((FLF F surj M).map (hom_of_le hT).op).f _ g = 0 :=
begin
have := exists_image (Cech_cone_diagram F surj n)
(Cech_cone F surj n) (Cech_cone_is_limit F surj n) S,
obtain ⟨T,hT,hh⟩ := this,
use T, use hT,
rw [locally_constant_eq_zero, FLF_map_coe_eq],
rw [locally_constant_eq_zero, FLF_cocone_app_coe_eq] at hg,
rintro x ⟨x,rfl⟩,
apply hg,
let P : (Cech_cone F surj n).X ⟶ (Cech_cone_diagram F surj n).obj S :=
(Cech_cone F surj n).π.app _,
let p : (Cech_cone_diagram F surj n).obj T ⟶ (Cech_cone_diagram F surj n).obj S :=
(Cech_cone_diagram F surj n).map (hom_of_le hT),
change ↥((Cech_cone_diagram F surj n).obj T) at x,
have : p x ∈ set.range p, use x,
erw ← hh at this,
obtain ⟨y,hy⟩ := this,
dsimp only [p] at hy,
use y,
dsimp only [function.comp_apply],
erw hy,
end
.
lemma d_eq_zero_FLF (n : ℕ) (S : discrete_quotient F.left)
(g : ((FLF F surj M).obj (op S)).X (n+1))
(hg : (FL F M).d (n+1) (n+2)
(((FLF_cocone F surj M).ι.app (op S)).f _ g) = 0) :
∃ (T : discrete_quotient F.left) (hT : T ≤ S),
((FLF F surj M).obj (op T)).d (n+1) (n+2)
(((FLF F surj M).map $ (hom_of_le hT).op).f _ g) = 0 :=
begin
have := ((FLF_cocone F surj M).ι.app (op S)).comm (n+1) (n+2),
apply_fun (λ e, e g) at this,
erw this at hg,
dsimp only [SemiNormedGroup.coe_comp] at hg,
have := eq_zero_FLF F surj M (n+1) S _ hg,
obtain ⟨T,hT,h⟩ := this,
use T, use hT,
have hh := ((FLF F surj M).map (hom_of_le hT).op).comm (n+1) (n+2),
apply_fun (λ e, e g) at hh,
erw ← hh at h,
exact h,
end
lemma norm_eq_FLF (n : ℕ) (S : discrete_quotient F.left)
(g : ((FLF F surj M).obj (op S)).X (n+1)) :
∃ (T : discrete_quotient F.left) (hT : T ≤ S),
∥((FLF_cocone F surj M).ι.app (op S)).f _ g∥₊ =
∥(((FLF F surj M)).map (hom_of_le hT).op).f _ g∥₊ :=
begin
have := exists_image (Cech_cone_diagram F surj n)
(Cech_cone F surj n) (Cech_cone_is_limit F surj n) S,
obtain ⟨T,hT,hh⟩ := this,
use T, use hT,
ext,
dsimp,
change Sup _ = Sup _,
congr' 1,
ext r,
split,
{ rintros ⟨x,rfl⟩,
dsimp only,
change ↥(Cech_cone F surj n).X at x,
use (Cech_cone F surj n).π.app T x,
dsimp only,
rw [← locally_constant_to_fun_eq, FLF_map_coe_eq,
function.comp_apply, ← Profinite.coe_comp_apply,
(Cech_cone F surj n).w, ← locally_constant_to_fun_eq,
FLF_cocone_app_coe_eq],
refl },
{ rintros ⟨x,rfl⟩,
dsimp only,
change ↥((Cech_cone_diagram F surj n).obj T) at x,
have : (Cech_cone_diagram F surj n).map (hom_of_le hT) x ∈
set.range ((Cech_cone_diagram F surj n).map (hom_of_le hT)), use x,
rw ← hh at this,
obtain ⟨y,hy⟩ := this,
change ↥(Cech_cone F surj n).X at y,
use y,
dsimp only,
simp_rw ← locally_constant_to_fun_eq,
rw [FLF_map_coe_eq, FLF_cocone_app_coe_eq],
dsimp only [function.comp_apply],
erw hy }
end
lemma exists_locally_constant (n : ℕ) (f : (FL F M).X (n+1))
(hf : (FL F M).d _ (n+2) f = 0) :
-- TODO: ∃ ..., true looks a bit fuuny
∃ (S : discrete_quotient F.left)
(g : ((FLF F surj M).obj (op S)).X (n+1))
(hgf : ((FLF_cocone F surj M).ι.app (op S)).f _ g = f)
(hgd : (((FLF F surj M).obj (op S)).d _ (n+2) g = 0))
(hgnorm : ∥f∥₊ = ∥g∥₊), true :=
begin
obtain ⟨S,f,rfl⟩ := exists_locally_constant_FLF F surj M n f,
obtain ⟨T1,hT1,h1⟩ := d_eq_zero_FLF F surj M n S f hf,
obtain ⟨T2,hT2,h2⟩ := norm_eq_FLF F surj M n S f,
let T := T1 ⊓ T2,
have hT : T ≤ S := le_trans inf_le_left hT1,
have hhT1 : T ≤ T1 := inf_le_left,
have hhT2 : T ≤ T2 := inf_le_right,
let g := ((FLF F surj M).map (hom_of_le hT).op).f _ f,
let g1 := ((FLF F surj M).map (hom_of_le hT1).op).f _ f,
let g2 := ((FLF F surj M).map (hom_of_le hT2).op).f _ f,
have hg1 : ((FLF F surj M).map (hom_of_le hhT1).op).f _ g1 = g,
{ dsimp only [g, g1],
have : (hom_of_le hT).op = (hom_of_le hT1).op ≫ (hom_of_le hhT1).op, refl,
rw [this, functor.map_comp],
refl },
have hg2 : ((FLF F surj M).map (hom_of_le hhT2).op).f _ g2 = g,
{ dsimp only [g, g2],
have : (hom_of_le hT).op = (hom_of_le hT2).op ≫ (hom_of_le hhT2).op, refl,
rw [this, functor.map_comp],
refl },
refine ⟨T, g, _, _, _, trivial⟩,
{ rw ← (FLF_cocone F surj M).w (hom_of_le hT).op,
refl },
{ rw ← hg1,
have := ((FLF F surj M).map (hom_of_le hhT1).op).comm (n+1) (n+2),
apply_fun (λ e, e g1) at this,
erw this, clear this,
dsimp only [g1, SemiNormedGroup.coe_comp, function.comp_app],
rw [h1, normed_group_hom.map_zero] },
{ apply le_antisymm,
{ dsimp only [g],
have := (FLF_cocone F surj M).w (hom_of_le hT).op,
rw ← this, clear this,
apply LocallyConstant_obj_map_norm_noninc },
{ rw [← hg2, h2],
apply LocallyConstant_obj_map_norm_noninc } }
end
lemma FLF_norm_noninc (n : ℕ) (S : discrete_quotient F.left)
(f : ((FLF F surj M).obj (op S)).X n) :
∥((FLF_cocone F surj M).ι.app (op S)).f _ f∥₊ ≤ ∥f∥₊ :=
begin
cases n,
apply LocallyConstant_obj_map_norm_noninc,
apply LocallyConstant_obj_map_norm_noninc,
end
theorem prop819 {m : ℕ} (ε : ℝ≥0) (hε : 0 < ε)
(f : (FLC F M).X (m+1)) (hf : (FLC F M).d (m+1) (m+2) f = 0) :
∃ g : (FLC F M).X m, (FLC F M).d m (m+1) g = f ∧ ∥g∥₊ ≤ (1 + ε) * ∥f∥₊ :=
begin
apply exact_of_strict_iso _ _ (FLC_iso F M) ε hε _ _ _ hf,
apply cmpl_exact_of_exact _ _ hε,
clear hf f m hε ε,
intros n f hf,
-- We've reduced to the non-completed case.
have := exists_locally_constant F surj M _ f hf,
rcases this with ⟨S,g,rfl,h2,h3,-⟩,
--let gg := ((FLF_cocone F surj M).ι.app (op S)).f _ g,
let CC : Π (n : ℕ), ((FLF F surj M).obj (op S)).X (n+1) ⟶
((FLF F surj M).obj (op S)).X n :=
((Profinite.arrow_diagram F surj).obj S).contracting_homotopy
(LocallyConstant.{u u}.obj M),
let gc := CC _ g,
let GG := ((FLF_cocone F surj M).ι.app (op S)).f _ gc,
refine ⟨GG,_,_⟩,
{ dsimp only [GG],
have := ((FLF_cocone F surj M).ι.app (op S)).comm n (n+1),
apply_fun (λ e, e gc) at this,
erw this, clear this,
change ((FLF_cocone F surj M).ι.app (op S)).f (n + 1) _ = _,
congr' 1,
change (CC n ≫ _) g = g,
cases n,
{ have hh := arrow.is_contracting_homotopy_one (LocallyConstant.{u u}.obj M)
((Profinite.arrow_diagram F surj).obj S),
apply_fun (λ e, e g) at hh,
change CC 1 (_) + _ = g at hh,
conv at hh {
congr,
congr,
erw h2 },
rw [normed_group_hom.map_zero, zero_add] at hh,
exact hh },
{ have hh := arrow.is_contracting_homotopy (LocallyConstant.{u u}.obj M)
((Profinite.arrow_diagram F surj).obj S) _,
apply_fun (λ e, e g) at hh,
change CC _ (_) + _ = g at hh,
conv at hh {
congr,
congr,
erw h2 },
rw [normed_group_hom.map_zero, zero_add] at hh,
exact hh } },
{ rw h3,
suffices : ∥GG∥₊ ≤ ∥gc∥₊,
{ apply le_trans this _,
cases n,
apply LocallyConstant_obj_map_norm_noninc,
apply LocallyConstant_obj_map_norm_noninc },
apply FLF_norm_noninc }
end
|
70de4b02dd007ceaa383c622152a288dff8805d3
|
64874bd1010548c7f5a6e3e8902efa63baaff785
|
/tests/lean/fold.lean
|
1aa2f5039c4795b75597153dedc7bfde1b2feffe
|
[
"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
| 701
|
lean
|
import data.prod data.num
variables a b c : num
context
notation `(` t:(foldr `,` (e r, prod.mk e r)) `)` := t
check (a, false, b, true, c)
set_option pp.notation false
check (a, false, b, true, c)
end
context
notation `(` t:(foldr `,` (e r, prod.mk r e)) `)` := t
check (a, false, b, true, c)
set_option pp.notation false
check (a, false, b, true, c)
end
context
notation `(` t:(foldl `,` (e r, prod.mk r e)) `)` := t
check (a, false, b, true, c)
set_option pp.notation false
check (a, false, b, true, c)
end
context
notation `(` t:(foldl `,` (e r, prod.mk e r)) `)` := t
check (a, false, b, true, c)
set_option pp.notation false
check (a, false, b, true, c)
end
|
1aa5e435a1cad3d614edc74a1b4c5392ff03eccd
|
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
|
/library/init/meta/rec_util.lean
|
dab27522d312dabc1106b99c9b61deae28803009
|
[
"Apache-2.0"
] |
permissive
|
pacchiano/lean
|
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
|
fdadada3a970377a6df8afcd629a6f2eab6e84e8
|
refs/heads/master
| 1,611,357,380,399
| 1,489,870,101,000
| 1,489,870,101,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,798
|
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
Helper tactic for showing that a type has decidable equality.
-/
prelude
import init.meta.tactic
namespace tactic
open expr
/- Return tt iff e's type is of the form `(I_name ...)` -/
meta def is_type_app_of (e : expr) (I_name : name) : tactic bool :=
do t ← infer_type e,
return $ is_constant_of (get_app_fn t) I_name
/- Auxiliary function for using brec_on "dictionary" -/
private meta def mk_rec_inst_aux : expr → nat → tactic expr
| F 0 := do
P ← mk_app `pprod.fst [F],
mk_app `pprod.fst [P]
| F (n+1) := do
F' ← mk_app `pprod.snd [F],
mk_rec_inst_aux F' n
/- Construct brec_on "recursive value". F_name is the name of the brec_on "dictionary".
Type of the F_name hypothesis should be of the form (below (C ...)) where C is a constructor.
The result is the "recursive value" for the (i+1)-th recursive value of the constructor C. -/
meta def mk_brec_on_rec_value (F_name : name) (i : nat) : tactic expr :=
do F ← get_local F_name,
mk_rec_inst_aux F i
meta def constructor_num_fields (c : name) : tactic nat :=
do env ← get_env,
decl ← env^.get c,
ctype ← return decl^.type,
arity ← get_pi_arity ctype,
I ← env^.inductive_type_of c,
nparams ← return (env^.inductive_num_params I),
return $ arity - nparams
private meta def mk_name_list_aux : name → nat → nat → list name → list name × nat
| p i 0 l := (list.reverse l, i)
| p i (j+1) l := mk_name_list_aux p (i+1) j (mk_num_name p i :: l)
private meta def mk_name_list (p : name) (i : nat) (n : nat) : list name × nat :=
mk_name_list_aux p i n []
/- Return a list of names of the form [p.i, ..., p.{i+n}] where n is
the number of fields of the constructor c -/
meta def mk_constructor_arg_names (c : name) (p : name) (i : nat) : tactic (list name × nat) :=
do nfields ← constructor_num_fields c,
return $ mk_name_list p i nfields
private meta def mk_constructors_arg_names_aux : list name → name → nat → list (list name) → tactic (list (list name))
| [] p i r := return (list.reverse r)
| (c::cs) p i r := do
v : list name × nat ← mk_constructor_arg_names c p i,
match v with (l, i') := mk_constructors_arg_names_aux cs p i' (l :: r) end
/- Given an inductive datatype I with k constructors and where constructor i has n_i fields,
return the list [[p.1, ..., p.n_1], [p.{n_1 + 1}, ..., p.{n_1 + n_2}], ..., [..., p.{n_1 + ... + n_k}]] -/
meta def mk_constructors_arg_names (I : name) (p : name) : tactic (list (list name)) :=
do env ← get_env,
cs ← return $ env^.constructors_of I,
mk_constructors_arg_names_aux cs p 1 []
end tactic
|
15b79182c7709c2ce23c6c8680ae42c811c9c78e
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/linarith/preprocessing.lean
|
4c3923ce784a0ae0ddcdb5e21687463537766644
|
[] |
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,266
|
lean
|
/-
Copyright (c) 2020 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.linarith.datatypes
import Mathlib.tactic.zify
import Mathlib.tactic.cancel_denoms
import Mathlib.PostPort
namespace Mathlib
/-!
# Linarith preprocessing
This file contains methods used to preprocess inputs to `linarith`.
In particular, `linarith` works over comparisons of the form `t R 0`, where `R ∈ {<,≤,=}`.
It assumes that expressions in `t` have integer coefficients and that the type of `t` has
well-behaved subtraction.
## Implementation details
A `global_preprocessor` is a function `list expr → tactic(list expr)`. Users can add custom
preprocessing steps by adding them to the `linarith_config` object. `linarith.default_preprocessors`
is the main list, and generally none of these should be skipped unless you know what you're doing.
-/
namespace linarith
/-! ### Preprocessing -/
/--
If `prf` is a proof of `¬ e`, where `e` is a comparison,
`rem_neg prf e` flips the comparison in `e` and returns a proof.
For example, if `prf : ¬ a < b`, ``rem_neg prf `(a < b)`` returns a proof of `a ≥ b`.
-/
|
706183e4ab15b180e67f691ac58a2f70985a7fcb
|
26b8b0964ca8e1c2e203585ba5940f83fe05e48a
|
/src/tidy/edit_distance.lean
|
06ad2b5e21c046c43b60791b2f19bee0782db06b
|
[] |
no_license
|
jcommelin/lean-tidy
|
ef3cd32a3804221d93f0dff9e180bb2c52f4b143
|
9cecf497e90db64b5ea140ad6ae1603976dcd402
|
refs/heads/master
| 1,585,129,919,276
| 1,533,512,680,000
| 1,533,512,680,000
| 143,677,361
| 0
| 0
| null | 1,616,803,481,000
| 1,533,530,576,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 5,205
|
lean
|
def edit_distance_naive {α} [decidable_eq α] : list α → list α → ℕ
| [] l := l.length
| l [] := l.length
| (a :: b) (c :: d) := if a = c then
edit_distance_naive b d
else
1 + min (min (edit_distance_naive (a :: b) d) (edit_distance_naive b (c :: d))) (edit_distance_naive b d)
-- PROJECT it would be great to be able to specify a maximum distance here, and bail out if we got beyond that.
-- The type signature would be:
-- def edit_distance {α} [decidable_eq α] (l₁ l₂ : list α) (max : option ℕ) : option ℕ :=
-- with a value of `none` meaning that `max` was `some L`, and the edit distance is at least `L`.
def edit_distance.aux {α} [decidable_eq α] (a : α) (b : list α) : list α → ℕ → list ℕ → ℕ × list ℕ
| [] _ _ := (b.length + 1, [])
| (c::d) _ [] := (0, []) -- won't happen
| (c::d) bc (bd::bd') :=
let (ad, ad') := edit_distance.aux d bd bd' in
(if a = c then bd else 1 + min (min ad bc) bd, ad::ad')
def edit_distance.aux' {α} [decidable_eq α] : list α → list α → ℕ × list ℕ
| [] [] := (0, [])
| [] (c::d) := let (n, ih) := edit_distance.aux' [] d in (n+1, n::ih)
| (a::b) l := let (n, ih) := edit_distance.aux' b l in
edit_distance.aux a b l n ih
def edit_distance {α} [decidable_eq α] (l₁ l₂ : list α) : ℕ :=
(edit_distance.aux' l₁ l₂).1
-- PROJECT some lemmas that show edit_distance behaves correctly?
-- PROJECT edit distance with transpositions?
-- PROJECT edit distance on trees?
def list.split_on_aux {α} [decidable_eq α] (a : α) : list α → list α → list (list α)
| [] l := [l.reverse]
| (h :: t) l := if h = a then
l.reverse :: (list.split_on_aux t [])
else
list.split_on_aux t (h :: l)
def list.split_on {α} [decidable_eq α] (a : α) : list α → list (list α)
| l := list.split_on_aux a l []
def string.split_on (c : char) (s : string) := (s.to_list.split_on c).map(λ l, l.as_string)
def string_edit_distance (s₁ s₂ : string) := edit_distance s₁.to_list s₂.to_list
def word_edit_distance (s₁ s₂ : string) := edit_distance (s₁.split_on ' ') (s₂.split_on ' ')
-- #eval string_edit_distance "the quick brown fox" "jumped over the lazy dog"
-- #eval word_edit_distance "big oak flat" "oak big flat"
variables {α : Type} [decidable_eq α]
@[derive decidable_eq]
structure partial_edit_distance_data (α : Type) :=
(prefix_length : ℕ)
(suffix : list α)
(distances : list ℕ) -- distances from the prefix of l₁ to each non-empty prefix of l₂
def empty_partial_edit_distance_data {α : Type} (l₁ l₂: list α) : partial_edit_distance_data α := ⟨ 0, l₁, (list.range l₂.length).map(λ n, n+1) ⟩
@[derive decidable_eq]
inductive edit_distance_progress (l₁: list α) (l₂: list α)
| exactly : ℕ → edit_distance_progress
| at_least : ℕ → partial_edit_distance_data α → edit_distance_progress
variables {l₁: list α} {l₂: list α}
open edit_distance_progress
def edit_distance_progress.to_string : edit_distance_progress l₁ l₂ → string
| (exactly _ _ k) := "= " ++ (to_string k)
| (at_least _ _ k _) := "≥ " ++ (to_string k)
def triples (p : partial_edit_distance_data α) (l₂ : list α): list (ℕ × ℕ × α) := p.distances.zip ((p.prefix_length :: p.distances).zip l₂)
def update_edit_distance_one_step : edit_distance_progress l₁ l₂ → edit_distance_progress l₁ l₂
| (exactly l₁ l₂ n) := exactly l₁ l₂ n
| (at_least l₁ l₂ n p) := match p.suffix with
| [] := exactly l₁ l₂ p.distances.ilast
| (h :: t) := let new_distances : ℕ × list ℕ := (triples p l₂).foldl (λ n : ℕ × list ℕ, λ t : ℕ × ℕ × α,
let m := (if h = t.2.2 then t.2.1 else 1 + min (min (t.2.1) (t.1)) n.2.head) in
(if m < n.1 then m else n.1, m :: n.2)) (p.prefix_length + 1, [p.prefix_length + 1]) in
at_least l₁ l₂ new_distances.1 ⟨ p.prefix_length + 1, t, new_distances.2.reverse.drop 1 ⟩
end
-- PROJECT for the enthusiastic: show these inductions are well-founded, and remove the metas
meta def update_edit_distance_until (m : ℕ) : edit_distance_progress l₁ l₂ → edit_distance_progress l₁ l₂
| (exactly l₁ l₂ n) := exactly l₁ l₂ n
| (at_least l₁ l₂ n p) := if n > m then (at_least l₁ l₂ n p) else update_edit_distance_until (update_edit_distance_one_step (at_least l₁ l₂ n p))
meta def update_edit_distance : edit_distance_progress l₁ l₂ → edit_distance_progress l₁ l₂
| (exactly l₁ l₂ n) := exactly l₁ l₂ n
| (at_least l₁ l₂ n p) := update_edit_distance_until n (at_least l₁ l₂ n p)
meta def edit_distance_core : edit_distance_progress l₁ l₂ → ℕ
| (exactly _ _ n) := n
| (p@_) := edit_distance_core (update_edit_distance p)
meta def edit_distance' (l₁: list α) (l₂: list α) := edit_distance_core (at_least l₁ l₂ 0 (empty_partial_edit_distance_data l₁ l₂))
|
b7d9464aad938144a5cafa35f8110324e5cefb5e
|
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
|
/library/algebra/category/default.lean
|
7e84a0731aba08fe0c40bd933dc7009e413ed7e1
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean
|
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
|
0cca265db19f7296531e339192e9b9bae4a31f8b
|
refs/heads/master
| 1,610,909,964,159
| 1,407,084,399,000
| 1,416,857,075,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 193
|
lean
|
-- Copyright (c) 2014 Floris van Doorn. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Floris van Doorn
import .morphism .constructions
|
404183d269129ee43a464da7551308da02ff1fef
|
626e312b5c1cb2d88fca108f5933076012633192
|
/src/topology/metric_space/basic.lean
|
3acc1253bcf8d42812e8641cac62a55b64d0f800
|
[
"Apache-2.0"
] |
permissive
|
Bioye97/mathlib
|
9db2f9ee54418d29dd06996279ba9dc874fd6beb
|
782a20a27ee83b523f801ff34efb1a9557085019
|
refs/heads/master
| 1,690,305,956,488
| 1,631,067,774,000
| 1,631,067,774,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 98,810
|
lean
|
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
-/
import topology.metric_space.emetric_space
import topology.algebra.ordered.basic
import data.fintype.intervals
/-!
# Metric spaces
This file defines metric spaces. Many definitions and theorems expected
on metric spaces are already introduced on uniform spaces and topological spaces.
For example: open and closed sets, compactness, completeness, continuity and uniform continuity
## Main definitions
* `has_dist α`: Endows a space `α` with a function `dist a b`.
* `pseudo_metric_space α`: A space endowed with a distance function, which can
be zero even if the two elements are non-equal.
* `metric.ball x ε`: The set of all points `y` with `dist y x < ε`.
* `metric.bounded s`: Whether a subset of a `pseudo_metric_space` is bounded.
* `metric_space α`: A `pseudo_metric_space` with the guarantee `dist x y = 0 → x = y`.
Additional useful definitions:
* `nndist a b`: `dist` as a function to the non-negative reals.
* `metric.closed_ball x ε`: The set of all points `y` with `dist y x ≤ ε`.
* `metric.sphere x ε`: The set of all points `y` with `dist y x = ε`.
* `proper_space α`: A `pseudo_metric_space` where all closed balls are compact.
* `metric.diam s` : The `supr` of the distances of members of `s`.
Defined in terms of `emetric.diam`, for better handling of the case when it should be infinite.
TODO (anyone): Add "Main results" section.
## Implementation notes
Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the
theory of `pseudo_metric_space`, where we don't require `dist x y = 0 → x = y` and we specialize
to `metric_space` at the end.
## Tags
metric, pseudo_metric, dist
-/
open set filter topological_space
noncomputable theory
open_locale uniformity topological_space big_operators filter nnreal ennreal
universes u v w
variables {α : Type u} {β : Type v}
/-- Construct a uniform structure core from a distance function and metric space axioms.
This is a technical construction that can be immediately used to construct a uniform structure
from a distance function and metric space axioms but is also useful when discussing
metrizable topologies, see `pseudo_metric_space.of_metrizable`. -/
def uniform_space.core_of_dist {α : Type*} (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space.core α :=
{ uniformity := (⨅ ε>0, 𝓟 {p:α×α | dist p.1 p.2 < ε}),
refl := le_infi $ assume ε, le_infi $
by simp [set.subset_def, id_rel, dist_self, (>)] {contextual := tt},
comp := le_infi $ assume ε, le_infi $ assume h, lift'_le
(mem_infi_of_mem (ε / 2) $ mem_infi_of_mem (div_pos h zero_lt_two) (subset.refl _)) $
have ∀ (a b c : α), dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε,
from assume a b c hac hcb,
calc dist a b ≤ dist a c + dist c b : dist_triangle _ _ _
... < ε / 2 + ε / 2 : add_lt_add hac hcb
... = ε : by rw [div_add_div_same, add_self_div_two],
by simpa [comp_rel],
symm := tendsto_infi.2 $ assume ε, tendsto_infi.2 $ assume h,
tendsto_infi' ε $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [dist_comm] }
/-- Construct a uniform structure from a distance function and metric space axioms -/
def uniform_space_of_dist
(dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space α :=
uniform_space.of_core (uniform_space.core_of_dist dist dist_self dist_comm dist_triangle)
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
class has_dist (α : Type*) := (dist : α → α → ℝ)
export has_dist (dist)
-- the uniform structure and the emetric space structure are embedded in the metric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- Metric space
Each metric space induces a canonical `uniform_space` and hence a canonical `topological_space`.
This is enforced in the type class definition, by extending the `uniform_space` structure. When
instantiating a `metric_space` structure, the uniformity fields are not necessary, they will be
filled in by default. In the same way, each metric space induces an emetric space structure.
It is included in the structure, but filled in by default.
-/
class pseudo_metric_space (α : Type u) extends has_dist α : Type u :=
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(edist : α → α → ℝ≥0∞ := λx y, ennreal.of_real (dist x y))
(edist_dist : ∀ x y : α, edist x y = ennreal.of_real (dist x y) . control_laws_tac)
(to_uniform_space : uniform_space α := uniform_space_of_dist dist dist_self dist_comm dist_triangle)
(uniformity_dist : 𝓤 α = ⨅ ε>0, 𝓟 {p:α×α | dist p.1 p.2 < ε} . control_laws_tac)
variables [pseudo_metric_space α]
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_uniform_space' : uniform_space α :=
pseudo_metric_space.to_uniform_space
@[priority 200] -- see Note [lower instance priority]
instance pseudo_metric_space.to_has_edist : has_edist α := ⟨pseudo_metric_space.edist⟩
/-- Construct a pseudo-metric space structure whose underlying topological space structure
(definitionally) agrees which a pre-existing topology which is compatible with a given distance
function. -/
def pseudo_metric_space.of_metrizable {α : Type*} [topological_space α] (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(H : ∀ s : set α, is_open s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) :
pseudo_metric_space α :=
{ dist := dist,
dist_self := dist_self,
dist_comm := dist_comm,
dist_triangle := dist_triangle,
to_uniform_space := { is_open_uniformity := begin
dsimp only [uniform_space.core_of_dist],
intros s,
change is_open s ↔ _,
rw H s,
apply forall_congr, intro x,
apply forall_congr, intro x_in,
erw (has_basis_binfi_principal _ nonempty_Ioi).mem_iff,
{ apply exists_congr, intros ε,
apply exists_congr, intros ε_pos,
simp only [prod.forall, set_of_subset_set_of],
split,
{ rintros h _ y H rfl,
exact h y H },
{ intros h y hxy,
exact h _ _ hxy rfl } },
{ exact λ r (hr : 0 < r) p (hp : 0 < p), ⟨min r p, lt_min hr hp,
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_left r p),
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_right r p)⟩ },
{ apply_instance }
end,
..uniform_space.core_of_dist dist dist_self dist_comm dist_triangle },
uniformity_dist := rfl }
@[simp] theorem dist_self (x : α) : dist x x = 0 := pseudo_metric_space.dist_self x
theorem dist_comm (x y : α) : dist x y = dist y x := pseudo_metric_space.dist_comm x y
theorem edist_dist (x y : α) : edist x y = ennreal.of_real (dist x y) :=
pseudo_metric_space.edist_dist x y
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
pseudo_metric_space.dist_triangle x y z
theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y :=
by rw dist_comm z; apply dist_triangle
theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z :=
by rw dist_comm y; apply dist_triangle
lemma dist_triangle4 (x y z w : α) :
dist x w ≤ dist x y + dist y z + dist z w :=
calc dist x w ≤ dist x z + dist z w : dist_triangle x z w
... ≤ (dist x y + dist y z) + dist z w : add_le_add_right (dist_triangle x y z) _
lemma dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :
dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) :=
by { rw [add_left_comm, dist_comm x₁, ← add_assoc], apply dist_triangle4 }
lemma dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :
dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ :=
by { rw [add_right_comm, dist_comm y₁], apply dist_triangle4 }
/-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
lemma dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) :
dist (f m) (f n) ≤ ∑ i in finset.Ico m n, dist (f i) (f (i + 1)) :=
begin
revert n,
apply nat.le_induction,
{ simp only [finset.sum_empty, finset.Ico.self_eq_empty, dist_self] },
{ assume n hn hrec,
calc dist (f m) (f (n+1)) ≤ dist (f m) (f n) + dist _ _ : dist_triangle _ _ _
... ≤ ∑ i in finset.Ico m n, _ + _ : add_le_add hrec (le_refl _)
... = ∑ i in finset.Ico m (n+1), _ :
by rw [finset.Ico.succ_top hn, finset.sum_insert, add_comm]; simp }
end
/-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
lemma dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) :
dist (f 0) (f n) ≤ ∑ i in finset.range n, dist (f i) (f (i + 1)) :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_dist f (nat.zero_le n)
/-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n)
{d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f m) (f n) ≤ ∑ i in finset.Ico m n, d i :=
le_trans (dist_le_Ico_sum_dist f hmn) $
finset.sum_le_sum $ λ k hk, hd (finset.Ico.mem.1 hk).1 (finset.Ico.mem.1 hk).2
/-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ)
{d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f 0) (f n) ≤ ∑ i in finset.range n, d i :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_of_dist_le (zero_le n) (λ _ _, hd)
theorem swap_dist : function.swap (@dist α _) = dist :=
by funext x y; exact dist_comm _ _
theorem abs_dist_sub_le (x y z : α) : abs (dist x z - dist y z) ≤ dist x y :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add.2 (dist_triangle _ _ _),
sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
have 2 * dist x y ≥ 0,
from calc 2 * dist x y = dist x y + dist y x : by rw [dist_comm x y, two_mul]
... ≥ 0 : by rw ← dist_self x; apply dist_triangle,
nonneg_of_mul_nonneg_left this zero_lt_two
@[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b :=
abs_of_nonneg dist_nonneg
/-- A version of `has_dist` that takes value in `ℝ≥0`. -/
class has_nndist (α : Type*) := (nndist : α → α → ℝ≥0)
export has_nndist (nndist)
/-- Distance as a nonnegative real number. -/
@[priority 100] -- see Note [lower instance priority]
instance pseudo_metric_space.to_has_nndist : has_nndist α := ⟨λ a b, ⟨dist a b, dist_nonneg⟩⟩
/--Express `nndist` in terms of `edist`-/
lemma nndist_edist (x y : α) : nndist x y = (edist x y).to_nnreal :=
by simp [nndist, edist_dist, real.to_nnreal, max_eq_left dist_nonneg, ennreal.of_real]
/--Express `edist` in terms of `nndist`-/
lemma edist_nndist (x y : α) : edist x y = ↑(nndist x y) :=
by { simpa only [edist_dist, ennreal.of_real_eq_coe_nnreal dist_nonneg] }
@[simp, norm_cast] lemma coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y :=
(edist_nndist x y).symm
@[simp, norm_cast] lemma edist_lt_coe {x y : α} {c : ℝ≥0} :
edist x y < c ↔ nndist x y < c :=
by rw [edist_nndist, ennreal.coe_lt_coe]
@[simp, norm_cast] lemma edist_le_coe {x y : α} {c : ℝ≥0} :
edist x y ≤ c ↔ nndist x y ≤ c :=
by rw [edist_nndist, ennreal.coe_le_coe]
/--In a pseudometric space, the extended distance is always finite-/
lemma edist_ne_top (x y : α) : edist x y ≠ ⊤ :=
by rw [edist_dist x y]; apply ennreal.coe_ne_top
/--In a pseudometric space, the extended distance is always finite-/
lemma edist_lt_top {α : Type*} [pseudo_metric_space α] (x y : α) : edist x y < ⊤ :=
ennreal.lt_top_iff_ne_top.2 (edist_ne_top x y)
/--`nndist x x` vanishes-/
@[simp] lemma nndist_self (a : α) : nndist a a = 0 := (nnreal.coe_eq_zero _).1 (dist_self a)
/--Express `dist` in terms of `nndist`-/
lemma dist_nndist (x y : α) : dist x y = ↑(nndist x y) := rfl
@[simp, norm_cast] lemma coe_nndist (x y : α) : ↑(nndist x y) = dist x y :=
(dist_nndist x y).symm
@[simp, norm_cast] lemma dist_lt_coe {x y : α} {c : ℝ≥0} :
dist x y < c ↔ nndist x y < c :=
iff.rfl
@[simp, norm_cast] lemma dist_le_coe {x y : α} {c : ℝ≥0} :
dist x y ≤ c ↔ nndist x y ≤ c :=
iff.rfl
/--Express `nndist` in terms of `dist`-/
lemma nndist_dist (x y : α) : nndist x y = real.to_nnreal (dist x y) :=
by rw [dist_nndist, real.to_nnreal_coe]
theorem nndist_comm (x y : α) : nndist x y = nndist y x :=
by simpa only [dist_nndist, nnreal.coe_eq] using dist_comm x y
/--Triangle inequality for the nonnegative distance-/
theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
dist_triangle _ _ _
theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
dist_triangle_left _ _ _
theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
dist_triangle_right _ _ _
/--Express `dist` in terms of `edist`-/
lemma dist_edist (x y : α) : dist x y = (edist x y).to_real :=
by rw [edist_dist, ennreal.to_real_of_real (dist_nonneg)]
namespace metric
/- instantiate pseudometric space as a topology -/
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
def ball (x : α) (ε : ℝ) : set α := {y | dist y x < ε}
@[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := iff.rfl
theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw dist_comm; refl
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε :=
dist_nonneg.trans_lt hy
theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε :=
show dist x x < ε, by rw dist_self; assumption
@[simp] lemma nonempty_ball : (ball x ε).nonempty ↔ 0 < ε :=
⟨λ ⟨x, hx⟩, pos_of_mem_ball hx, λ h, ⟨x, mem_ball_self h⟩⟩
@[simp] lemma ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 :=
by rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt]
@[simp] lemma ball_zero : ball x 0 = ∅ :=
by rw [ball_eq_empty]
lemma ball_eq_ball (ε : ℝ) (x : α) :
uniform_space.ball x {p | dist p.2 p.1 < ε} = metric.ball x ε := rfl
lemma ball_eq_ball' (ε : ℝ) (x : α) :
uniform_space.ball x {p | dist p.1 p.2 < ε} = metric.ball x ε :=
by { ext, simp [dist_comm, uniform_space.ball] }
@[simp] lemma Union_ball_nat (x : α) : (⋃ n : ℕ, ball x n) = univ :=
Union_eq_univ_iff.2 $ λ y, exists_nat_gt (dist y x)
@[simp] lemma Union_ball_nat_succ (x : α) : (⋃ n : ℕ, ball x (n + 1)) = univ :=
Union_eq_univ_iff.2 $ λ y, (exists_nat_gt (dist y x)).imp $ λ n hn,
hn.trans (lt_add_one _)
/-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/
def closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}
@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl
/-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/
def sphere (x : α) (ε : ℝ) := {y | dist y x = ε}
@[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := iff.rfl
theorem mem_closed_ball' : y ∈ closed_ball x ε ↔ dist x y ≤ ε :=
by { rw dist_comm, refl }
theorem mem_closed_ball_self (h : 0 ≤ ε) : x ∈ closed_ball x ε :=
show dist x x ≤ ε, by rw dist_self; assumption
@[simp] lemma nonempty_closed_ball : (closed_ball x ε).nonempty ↔ 0 ≤ ε :=
⟨λ ⟨x, hx⟩, dist_nonneg.trans hx, λ h, ⟨x, mem_closed_ball_self h⟩⟩
@[simp] lemma closed_ball_eq_empty : closed_ball x ε = ∅ ↔ ε < 0 :=
by rw [← not_nonempty_iff_eq_empty, nonempty_closed_ball, not_le]
theorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=
assume y (hy : _ < _), le_of_lt hy
theorem sphere_subset_closed_ball : sphere x ε ⊆ closed_ball x ε :=
λ y, le_of_eq
theorem sphere_disjoint_ball : disjoint (sphere x ε) (ball x ε) :=
λ y ⟨hy₁, hy₂⟩, absurd hy₁ $ ne_of_lt hy₂
@[simp] theorem ball_union_sphere : ball x ε ∪ sphere x ε = closed_ball x ε :=
set.ext $ λ y, (@le_iff_lt_or_eq ℝ _ _ _).symm
@[simp] theorem sphere_union_ball : sphere x ε ∪ ball x ε = closed_ball x ε :=
by rw [union_comm, ball_union_sphere]
@[simp] theorem closed_ball_diff_sphere : closed_ball x ε \ sphere x ε = ball x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_right sphere_disjoint_ball.symm]
@[simp] theorem closed_ball_diff_ball : closed_ball x ε \ ball x ε = sphere x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_left sphere_disjoint_ball.symm]
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=
by simp [dist_comm]
theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ :=
λ y (yx : _ < ε₁), lt_of_lt_of_le yx h
theorem closed_ball_subset_closed_ball (h : ε₁ ≤ ε₂) :
closed_ball x ε₁ ⊆ closed_ball x ε₂ :=
λ y (yx : _ ≤ ε₁), le_trans yx h
theorem closed_ball_subset_ball (h : ε₁ < ε₂) :
closed_ball x ε₁ ⊆ ball x ε₂ :=
λ y (yh : dist y x ≤ ε₁), lt_of_le_of_lt yh h
@[simp] lemma Union_closed_ball_nat (x : α) : (⋃ n : ℕ, closed_ball x n) = univ :=
Union_eq_univ_iff.2 $ λ y, exists_nat_ge (dist y x)
theorem ball_disjoint (h : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ z ⟨h₁, h₂⟩,
not_lt_of_le (dist_triangle_left x y z)
(lt_of_lt_of_le (add_lt_add h₁ h₂) h)
theorem ball_disjoint_same (h : ε ≤ dist x y / 2) : ball x ε ∩ ball y ε = ∅ :=
ball_disjoint $ by rwa [← two_mul, ← le_div_iff' (@zero_lt_two ℝ _ _)]
theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ :=
λ z zx, by rw ← add_sub_cancel'_right ε₁ ε₂; exact
lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)
theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=
ball_subset $ by rw sub_self_div_two; exact le_of_lt h
theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
⟨_, sub_pos.2 h, ball_subset $ by rw sub_sub_self⟩
theorem uniformity_basis_dist :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 < ε}) :=
begin
rw ← pseudo_metric_space.uniformity_dist.symm,
refine has_basis_binfi_principal _ nonempty_Ioi,
exact λ r (hr : 0 < r) p (hp : 0 < p), ⟨min r p, lt_min hr hp,
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_left r p),
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_right r p)⟩
end
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`.
For specific bases see `uniformity_basis_dist`, `uniformity_basis_dist_inv_nat_succ`,
and `uniformity_basis_dist_inv_nat_pos`. -/
protected theorem mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ i, p i → 0 < f i) (hf : ∀ ⦃ε⦄, 0 < ε → ∃ i (hi : p i), f i ≤ ε) :
(𝓤 α).has_basis p (λ i, {p:α×α | dist p.1 p.2 < f i}) :=
begin
refine ⟨λ s, uniformity_basis_dist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
obtain ⟨i, hi, H⟩ : ∃ i (hi : p i), f i ≤ ε, from hf ε₀,
exact ⟨i, hi, λ x (hx : _ < _), hε $ lt_of_lt_of_le hx H⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, H⟩ }
end
theorem uniformity_basis_dist_inv_nat_succ :
(𝓤 α).has_basis (λ _, true) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / (↑n+1) }) :=
metric.mk_uniformity_basis (λ n _, div_pos zero_lt_one $ nat.cast_add_one_pos n)
(λ ε ε0, (exists_nat_one_div_lt ε0).imp $ λ n hn, ⟨trivial, le_of_lt hn⟩)
theorem uniformity_basis_dist_inv_nat_pos :
(𝓤 α).has_basis (λ n:ℕ, 0<n) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / ↑n }) :=
metric.mk_uniformity_basis (λ n hn, div_pos zero_lt_one $ nat.cast_pos.2 hn)
(λ ε ε0, let ⟨n, hn⟩ := exists_nat_one_div_lt ε0 in ⟨n+1, nat.succ_pos n, hn.le⟩)
theorem uniformity_basis_dist_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓤 α).has_basis (λ n:ℕ, true) (λ n:ℕ, {p:α×α | dist p.1 p.2 < r ^ n }) :=
metric.mk_uniformity_basis (λ n hn, pow_pos h0 _)
(λ ε ε0, let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1 in ⟨n, trivial, hn.le⟩)
theorem uniformity_basis_dist_lt {R : ℝ} (hR : 0 < R) :
(𝓤 α).has_basis (λ r : ℝ, 0 < r ∧ r < R) (λ r, {p : α × α | dist p.1 p.2 < r}) :=
metric.mk_uniformity_basis (λ r, and.left) $ λ r hr,
⟨min r (R / 2), ⟨lt_min hr (half_pos hR), min_lt_iff.2 $ or.inr (half_lt_self hR)⟩,
min_le_left _ _⟩
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}`
form a basis of `𝓤 α`.
Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor.
More can be easily added if needed in the future. -/
protected theorem mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x (hx : p x), f x ≤ ε) :
(𝓤 α).has_basis p (λ x, {p:α×α | dist p.1 p.2 ≤ f x}) :=
begin
refine ⟨λ s, uniformity_basis_dist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
rcases exists_between ε₀ with ⟨ε', hε'⟩,
rcases hf ε' hε'.1 with ⟨i, hi, H⟩,
exact ⟨i, hi, λ x (hx : _ ≤ _), hε $ lt_of_le_of_lt (le_trans hx H) hε'.2⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, λ x (hx : _ < _), H (le_of_lt hx)⟩ }
end
/-- Contant size closed neighborhoods of the diagonal form a basis
of the uniformity filter. -/
theorem uniformity_basis_dist_le :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 ≤ ε}) :=
metric.mk_uniformity_basis_le (λ _, id) (λ ε ε₀, ⟨ε, ε₀, le_refl ε⟩)
theorem uniformity_basis_dist_le_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓤 α).has_basis (λ n:ℕ, true) (λ n:ℕ, {p:α×α | dist p.1 p.2 ≤ r ^ n }) :=
metric.mk_uniformity_basis_le (λ n hn, pow_pos h0 _)
(λ ε ε0, let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1 in ⟨n, trivial, hn.le⟩)
theorem mem_uniformity_dist {s : set (α×α)} :
s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) :=
uniformity_basis_dist.mem_uniformity_iff
/-- A constant size neighborhood of the diagonal is an entourage. -/
theorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) :
{p:α×α | dist p.1 p.2 < ε} ∈ 𝓤 α :=
mem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩
theorem uniform_continuous_iff [pseudo_metric_space β] {f : α → β} :
uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,
∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε :=
uniformity_basis_dist.uniform_continuous_iff uniformity_basis_dist
lemma uniform_continuous_on_iff [pseudo_metric_space β] {f : α → β} {s : set α} :
uniform_continuous_on f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x y ∈ s, dist x y < δ → dist (f x) (f y) < ε :=
metric.uniformity_basis_dist.uniform_continuous_on_iff metric.uniformity_basis_dist
lemma uniform_continuous_on_iff_le [pseudo_metric_space β] {f : α → β} {s : set α} :
uniform_continuous_on f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x y ∈ s, dist x y ≤ δ → dist (f x) (f y) ≤ ε :=
metric.uniformity_basis_dist_le.uniform_continuous_on_iff metric.uniformity_basis_dist_le
theorem uniform_embedding_iff [pseudo_metric_space β] {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0),
⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu in
⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,
λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in
⟨_, dist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩
/-- If a map between pseudometric spaces is a uniform embedding then the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y`. -/
theorem controlled_of_uniform_embedding [pseudo_metric_space β] {f : α → β} :
uniform_embedding f →
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧
(∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ) :=
begin
assume h,
exact ⟨uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1, (uniform_embedding_iff.1 h).2.2⟩
end
theorem totally_bounded_iff {s : set α} :
totally_bounded s ↔ ∀ ε > 0, ∃t : set α, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
⟨λ H ε ε0, H _ (dist_mem_uniformity ε0),
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
⟨t, ft, h⟩ := H ε ε0 in
⟨t, ft, subset.trans h $ Union_subset_Union $ λ y, Union_subset_Union $ λ yt z, hε⟩⟩
/-- A pseudometric space space is totally bounded if one can reconstruct up to any ε>0 any element
of the space from finitely many data. -/
lemma totally_bounded_of_finite_discretization {s : set α}
(H : ∀ε > (0 : ℝ), ∃ (β : Type u) [fintype β] (F : s → β),
∀x y, F x = F y → dist (x:α) y < ε) :
totally_bounded s :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ rw hs, exact totally_bounded_empty },
rcases hs with ⟨x0, hx0⟩,
haveI : inhabited s := ⟨⟨x0, hx0⟩⟩,
refine totally_bounded_iff.2 (λ ε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
resetI,
let Finv := function.inv_fun F,
refine ⟨range (subtype.val ∘ Finv), finite_range _, λ x xs, _⟩,
let x' := Finv (F ⟨x, xs⟩),
have : F x' = F ⟨x, xs⟩ := function.inv_fun_eq ⟨⟨x, xs⟩, rfl⟩,
simp only [set.mem_Union, set.mem_range],
exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩
end
theorem finite_approx_of_totally_bounded {s : set α} (hs : totally_bounded s) :
∀ ε > 0, ∃ t ⊆ s, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
begin
intros ε ε_pos,
rw totally_bounded_iff_subset at hs,
exact hs _ (dist_mem_uniformity ε_pos),
end
/-- Expressing locally uniform convergence on a set using `dist`. -/
lemma tendsto_locally_uniformly_on_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_locally_uniformly_on F f p s ↔
∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu x hx, _⟩,
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩,
rcases H ε εpos x hx with ⟨t, ht, Ht⟩,
exact ⟨t, ht, Ht.mono (λ n hs x hx, hε (hs x hx))⟩
end
/-- Expressing uniform convergence on a set using `dist`. -/
lemma tendsto_uniformly_on_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_uniformly_on F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, dist (f x) (F n x) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu, _⟩,
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩,
exact (H ε εpos).mono (λ n hs x hx, hε (hs x hx))
end
/-- Expressing locally uniform convergence using `dist`. -/
lemma tendsto_locally_uniformly_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_locally_uniformly F f p ↔
∀ ε > 0, ∀ (x : β), ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
by simp only [← tendsto_locally_uniformly_on_univ, tendsto_locally_uniformly_on_iff,
nhds_within_univ, mem_univ, forall_const, exists_prop]
/-- Expressing uniform convergence using `dist`. -/
lemma tendsto_uniformly_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_uniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, dist (f x) (F n x) < ε :=
by { rw [← tendsto_uniformly_on_univ, tendsto_uniformly_on_iff], simp }
protected lemma cauchy_iff {f : filter α} :
cauchy f ↔ ne_bot f ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, dist x y < ε :=
uniformity_basis_dist.cauchy_iff
theorem nhds_basis_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (ball x) :=
nhds_basis_uniformity uniformity_basis_dist
theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ε>0, ball x ε ⊆ s :=
nhds_basis_ball.mem_iff
theorem eventually_nhds_iff {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ε>0, ∀ ⦃y⦄, dist y x < ε → p y :=
mem_nhds_iff
lemma eventually_nhds_iff_ball {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε>0, ∀ y ∈ ball x ε, p y :=
mem_nhds_iff
theorem nhds_basis_closed_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (closed_ball x) :=
nhds_basis_uniformity uniformity_basis_dist_le
theorem nhds_basis_ball_inv_nat_succ :
(𝓝 x).has_basis (λ _, true) (λ n:ℕ, ball x (1 / (↑n+1))) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ
theorem nhds_basis_ball_inv_nat_pos :
(𝓝 x).has_basis (λ n, 0<n) (λ n:ℕ, ball x (1 / ↑n)) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos
theorem nhds_basis_ball_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓝 x).has_basis (λ n, true) (λ n:ℕ, ball x (r ^ n)) :=
nhds_basis_uniformity (uniformity_basis_dist_pow h0 h1)
theorem nhds_basis_closed_ball_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) :
(𝓝 x).has_basis (λ n, true) (λ n:ℕ, closed_ball x (r ^ n)) :=
nhds_basis_uniformity (uniformity_basis_dist_le_pow h0 h1)
theorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=
by simp only [is_open_iff_mem_nhds, mem_nhds_iff]
theorem is_open_ball : is_open (ball x ε) :=
is_open_iff.2 $ λ y, exists_ball_subset_ball
theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x :=
is_open.mem_nhds is_open_ball (mem_ball_self ε0)
theorem closed_ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : closed_ball x ε ∈ 𝓝 x :=
mem_of_superset (ball_mem_nhds x ε0) ball_subset_closed_ball
theorem nhds_within_basis_ball {s : set α} :
(𝓝[s] x).has_basis (λ ε:ℝ, 0 < ε) (λ ε, ball x ε ∩ s) :=
nhds_within_has_basis nhds_basis_ball s
theorem mem_nhds_within_iff {t : set α} : s ∈ 𝓝[t] x ↔ ∃ε>0, ball x ε ∩ t ⊆ s :=
nhds_within_basis_ball.mem_iff
theorem tendsto_nhds_within_nhds_within [pseudo_metric_space β] {t : set β} {f : α → β} {a b} :
tendsto f (𝓝[s] a) (𝓝[t] b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε :=
(nhds_within_basis_ball.tendsto_iff nhds_within_basis_ball).trans $
by simp only [inter_comm, mem_inter_iff, and_imp, mem_ball]
theorem tendsto_nhds_within_nhds [pseudo_metric_space β] {f : α → β} {a b} :
tendsto f (𝓝[s] a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) b < ε :=
by { rw [← nhds_within_univ b, tendsto_nhds_within_nhds_within],
simp only [mem_univ, true_and] }
theorem tendsto_nhds_nhds [pseudo_metric_space β] {f : α → β} {a b} :
tendsto f (𝓝 a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε :=
nhds_basis_ball.tendsto_iff nhds_basis_ball
theorem continuous_at_iff [pseudo_metric_space β] {f : α → β} {a : α} :
continuous_at f a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_at, tendsto_nhds_nhds]
theorem continuous_within_at_iff [pseudo_metric_space β] {f : α → β} {a : α} {s : set α} :
continuous_within_at f s a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_within_at, tendsto_nhds_within_nhds]
theorem continuous_on_iff [pseudo_metric_space β] {f : α → β} {s : set α} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∃ δ > 0, ∀a ∈ s, dist a b < δ → dist (f a) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff]
theorem continuous_iff [pseudo_metric_space β] {f : α → β} :
continuous f ↔
∀b (ε > 0), ∃ δ > 0, ∀a, dist a b < δ → dist (f a) (f b) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_nhds
theorem tendsto_nhds {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, dist (u x) a < ε :=
nhds_basis_ball.tendsto_right_iff
theorem continuous_at_iff' [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔
∀ ε > 0, ∀ᶠ x in 𝓝 b, dist (f x) (f b) < ε :=
by rw [continuous_at, tendsto_nhds]
theorem continuous_within_at_iff' [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔
∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε :=
by rw [continuous_within_at, tendsto_nhds]
theorem continuous_on_iff' [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff']
theorem continuous_iff' [topological_space β] {f : β → α} :
continuous f ↔ ∀a (ε > 0), ∀ᶠ x in 𝓝 a, dist (f x) (f a) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds
theorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} :
tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) a < ε :=
(at_top_basis.tendsto_iff nhds_basis_ball).trans $
by { simp only [exists_prop, true_and], refl }
/--
A variant of `tendsto_at_top` that
uses `∃ N, ∀ n > N, ...` rather than `∃ N, ∀ n ≥ N, ...`
-/
theorem tendsto_at_top' [nonempty β] [semilattice_sup β] [no_top_order β] {u : β → α} {a : α} :
tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n>N, dist (u n) a < ε :=
(at_top_basis_Ioi.tendsto_iff nhds_basis_ball).trans $
by { simp only [exists_prop, true_and], refl }
lemma is_open_singleton_iff {α : Type*} [pseudo_metric_space α] {x : α} :
is_open ({x} : set α) ↔ ∃ ε > 0, ∀ y, dist y x < ε → y = x :=
by simp [is_open_iff, subset_singleton_iff, mem_ball]
/-- Given a point `x` in a discrete subset `s` of a pseudometric space, there is an open ball
centered at `x` and intersecting `s` only at `x`. -/
lemma exists_ball_inter_eq_singleton_of_mem_discrete [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, metric.ball x ε ∩ s = {x} :=
nhds_basis_ball.exists_inter_eq_singleton_of_mem_discrete hx
/-- Given a point `x` in a discrete subset `s` of a pseudometric space, there is a closed ball
of positive radius centered at `x` and intersecting `s` only at `x`. -/
lemma exists_closed_ball_inter_eq_singleton_of_discrete [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, metric.closed_ball x ε ∩ s = {x} :=
nhds_basis_closed_ball.exists_inter_eq_singleton_of_mem_discrete hx
end metric
open metric
/-Instantiate a pseudometric space as a pseudoemetric space. Before we can state the instance,
we need to show that the uniform structure coming from the edistance and the
distance coincide. -/
/-- Expressing the uniformity in terms of `edist` -/
protected lemma pseudo_metric.uniformity_basis_edist :
(𝓤 α).has_basis (λ ε:ℝ≥0∞, 0 < ε) (λ ε, {p | edist p.1 p.2 < ε}) :=
⟨begin
intro t,
refine mem_uniformity_dist.trans ⟨_, _⟩; rintro ⟨ε, ε0, Hε⟩,
{ use [ennreal.of_real ε, ennreal.of_real_pos.2 ε0],
rintros ⟨a, b⟩,
simp only [edist_dist, ennreal.of_real_lt_of_real_iff ε0],
exact Hε },
{ rcases ennreal.lt_iff_exists_real_btwn.1 ε0 with ⟨ε', _, ε0', hε⟩,
rw [ennreal.of_real_pos] at ε0',
refine ⟨ε', ε0', λ a b h, Hε (lt_trans _ hε)⟩,
rwa [edist_dist, ennreal.of_real_lt_of_real_iff ε0'] }
end⟩
theorem metric.uniformity_edist : 𝓤 α = (⨅ ε>0, 𝓟 {p:α×α | edist p.1 p.2 < ε}) :=
pseudo_metric.uniformity_basis_edist.eq_binfi
/-- A pseudometric space induces a pseudoemetric space -/
@[priority 100] -- see Note [lower instance priority]
instance pseudo_metric_space.to_pseudo_emetric_space : pseudo_emetric_space α :=
{ edist := edist,
edist_self := by simp [edist_dist],
edist_comm := by simp only [edist_dist, dist_comm]; simp,
edist_triangle := assume x y z, begin
simp only [edist_dist, ← ennreal.of_real_add, dist_nonneg],
rw ennreal.of_real_le_of_real_iff _,
{ exact dist_triangle _ _ _ },
{ simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg }
end,
uniformity_edist := metric.uniformity_edist,
..‹pseudo_metric_space α› }
/-- In a pseudometric space, an open ball of infinite radius is the whole space -/
lemma metric.eball_top_eq_univ (x : α) :
emetric.ball x ∞ = set.univ :=
set.eq_univ_iff_forall.mpr (λ y, edist_lt_top y x)
/-- Balls defined using the distance or the edistance coincide -/
@[simp] lemma metric.emetric_ball {x : α} {ε : ℝ} : emetric.ball x (ennreal.of_real ε) = ball x ε :=
begin
ext y,
simp only [emetric.mem_ball, mem_ball, edist_dist],
exact ennreal.of_real_lt_of_real_iff_of_nonneg dist_nonneg
end
/-- Balls defined using the distance or the edistance coincide -/
@[simp] lemma metric.emetric_ball_nnreal {x : α} {ε : ℝ≥0} : emetric.ball x ε = ball x ε :=
by { convert metric.emetric_ball, simp }
/-- Closed balls defined using the distance or the edistance coincide -/
lemma metric.emetric_closed_ball {x : α} {ε : ℝ} (h : 0 ≤ ε) :
emetric.closed_ball x (ennreal.of_real ε) = closed_ball x ε :=
by ext y; simp [edist_dist]; rw ennreal.of_real_le_of_real_iff h
/-- Closed balls defined using the distance or the edistance coincide -/
@[simp] lemma metric.emetric_closed_ball_nnreal {x : α} {ε : ℝ≥0} :
emetric.closed_ball x ε = closed_ball x ε :=
by { convert metric.emetric_closed_ball ε.2, simp }
@[simp] lemma metric.emetric_ball_top (x : α) : emetric.ball x ⊤ = univ :=
eq_univ_of_forall $ λ y, edist_lt_top _ _
/-- Build a new pseudometric space from an old one where the bundled uniform structure is provably
(but typically non-definitionaly) equal to some given uniform structure.
See Note [forgetful inheritance].
-/
def pseudo_metric_space.replace_uniformity {α} [U : uniform_space α] (m : pseudo_metric_space α)
(H : @uniformity _ U = @uniformity _ pseudo_emetric_space.to_uniform_space') :
pseudo_metric_space α :=
{ dist := @dist _ m.to_has_dist,
dist_self := dist_self,
dist_comm := dist_comm,
dist_triangle := dist_triangle,
edist := edist,
edist_dist := edist_dist,
to_uniform_space := U,
uniformity_dist := H.trans pseudo_metric_space.uniformity_dist }
/-- One gets a pseudometric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the pseudometric space and the pseudoemetric space. In this definition, the
distance is given separately, to be able to prescribe some expression which is not defeq to the
push-forward of the edistance to reals. -/
def pseudo_emetric_space.to_pseudo_metric_space_of_dist {α : Type u} [e : pseudo_emetric_space α]
(dist : α → α → ℝ)
(edist_ne_top : ∀x y: α, edist x y ≠ ⊤)
(h : ∀x y, dist x y = ennreal.to_real (edist x y)) :
pseudo_metric_space α :=
let m : pseudo_metric_space α :=
{ dist := dist,
dist_self := λx, by simp [h],
dist_comm := λx y, by simp [h, pseudo_emetric_space.edist_comm],
dist_triangle := λx y z, begin
simp only [h],
rw [← ennreal.to_real_add (edist_ne_top _ _) (edist_ne_top _ _),
ennreal.to_real_le_to_real (edist_ne_top _ _)],
{ exact edist_triangle _ _ _ },
{ simp [ennreal.add_eq_top, edist_ne_top] }
end,
edist := λx y, edist x y,
edist_dist := λx y, by simp [h, ennreal.of_real_to_real, edist_ne_top] } in
m.replace_uniformity $ by { rw [uniformity_pseudoedist, metric.uniformity_edist], refl }
/-- One gets a pseudometric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the pseudometric space and the emetric space. -/
def pseudo_emetric_space.to_pseudo_metric_space {α : Type u} [e : emetric_space α]
(h : ∀x y: α, edist x y ≠ ⊤) : pseudo_metric_space α :=
pseudo_emetric_space.to_pseudo_metric_space_of_dist
(λx y, ennreal.to_real (edist x y)) h (λx y, rfl)
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem metric.complete_of_convergent_controlled_sequences (B : ℕ → real) (hB : ∀n, 0 < B n)
(H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) →
∃x, tendsto u at_top (𝓝 x)) :
complete_space α :=
begin
-- this follows from the same criterion in emetric spaces. We just need to translate
-- the convergence assumption from `dist` to `edist`
apply emetric.complete_of_convergent_controlled_sequences (λn, ennreal.of_real (B n)),
{ simp [hB] },
{ assume u Hu,
apply H,
assume N n m hn hm,
rw [← ennreal.of_real_lt_of_real_iff (hB N), ← edist_dist],
exact Hu N n m hn hm }
end
theorem metric.complete_of_cauchy_seq_tendsto :
(∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) → complete_space α :=
emetric.complete_of_cauchy_seq_tendsto
section real
/-- Instantiate the reals as a pseudometric space. -/
instance real.pseudo_metric_space : pseudo_metric_space ℝ :=
{ dist := λx y, abs (x - y),
dist_self := by simp [abs_zero],
dist_comm := assume x y, abs_sub_comm _ _,
dist_triangle := assume x y z, abs_sub_le _ _ _ }
theorem real.dist_eq (x y : ℝ) : dist x y = abs (x - y) := rfl
theorem real.nndist_eq (x y : ℝ) : nndist x y = real.nnabs (x - y) := rfl
theorem real.nndist_eq' (x y : ℝ) : nndist x y = real.nnabs (y - x) := nndist_comm _ _
theorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x :=
by simp [real.dist_eq]
theorem real.dist_left_le_of_mem_interval {x y z : ℝ} (h : y ∈ interval x z) :
dist x y ≤ dist x z :=
by simpa only [dist_comm x] using abs_sub_left_of_mem_interval h
theorem real.dist_right_le_of_mem_interval {x y z : ℝ} (h : y ∈ interval x z) :
dist y z ≤ dist x z :=
by simpa only [dist_comm _ z] using abs_sub_right_of_mem_interval h
theorem real.dist_le_of_mem_interval {x y x' y' : ℝ} (hx : x ∈ interval x' y')
(hy : y ∈ interval x' y') : dist x y ≤ dist x' y' :=
abs_sub_le_of_subinterval $ interval_subset_interval (by rwa interval_swap) (by rwa interval_swap)
theorem real.dist_le_of_mem_Icc {x y x' y' : ℝ} (hx : x ∈ Icc x' y') (hy : y ∈ Icc x' y') :
dist x y ≤ y' - x' :=
by simpa only [real.dist_eq, abs_of_nonpos (sub_nonpos.2 $ hx.1.trans hx.2), neg_sub]
using real.dist_le_of_mem_interval (Icc_subset_interval hx) (Icc_subset_interval hy)
theorem real.dist_le_of_mem_Icc_01 {x y : ℝ} (hx : x ∈ Icc (0:ℝ) 1) (hy : y ∈ Icc (0:ℝ) 1) :
dist x y ≤ 1 :=
by simpa only [sub_zero] using real.dist_le_of_mem_Icc hx hy
instance : order_topology ℝ :=
order_topology_of_nhds_abs $ λ x,
by simp only [nhds_basis_ball.eq_binfi, ball, real.dist_eq, abs_sub_comm]
lemma real.ball_eq (x r : ℝ) : ball x r = Ioo (x - r) (x + r) :=
set.ext $ λ y, by rw [mem_ball, dist_comm, real.dist_eq,
abs_sub_lt_iff, mem_Ioo, ← sub_lt_iff_lt_add', sub_lt]
lemma real.closed_ball_eq {x r : ℝ} : closed_ball x r = Icc (x - r) (x + r) :=
by ext y; rw [mem_closed_ball, dist_comm, real.dist_eq,
abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add', sub_le]
section metric_ordered
variables [conditionally_complete_linear_order α] [order_topology α]
lemma totally_bounded_Icc (a b : α) : totally_bounded (Icc a b) :=
is_compact_Icc.totally_bounded
lemma totally_bounded_Ico (a b : α) : totally_bounded (Ico a b) :=
totally_bounded_subset Ico_subset_Icc_self (totally_bounded_Icc a b)
lemma totally_bounded_Ioc (a b : α) : totally_bounded (Ioc a b) :=
totally_bounded_subset Ioc_subset_Icc_self (totally_bounded_Icc a b)
lemma totally_bounded_Ioo (a b : α) : totally_bounded (Ioo a b) :=
totally_bounded_subset Ioo_subset_Icc_self (totally_bounded_Icc a b)
end metric_ordered
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the
general case. -/
lemma squeeze_zero' {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀ᶠ t in t₀, 0 ≤ f t)
(hft : ∀ᶠ t in t₀, f t ≤ g t) (g0 : tendsto g t₀ (nhds 0)) : tendsto f t₀ (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds g0 hf hft
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le`
and `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/
lemma squeeze_zero {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀t, 0 ≤ f t) (hft : ∀t, f t ≤ g t)
(g0 : tendsto g t₀ (𝓝 0)) : tendsto f t₀ (𝓝 0) :=
squeeze_zero' (eventually_of_forall hf) (eventually_of_forall hft) g0
theorem metric.uniformity_eq_comap_nhds_zero :
𝓤 α = comap (λp:α×α, dist p.1 p.2) (𝓝 (0 : ℝ)) :=
by { ext s,
simp [mem_uniformity_dist, (nhds_basis_ball.comap _).mem_iff, subset_def, real.dist_0_eq_abs] }
lemma cauchy_seq_iff_tendsto_dist_at_top_0 [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ tendsto (λ (n : β × β), dist (u n.1) (u n.2)) at_top (𝓝 0) :=
by rw [cauchy_seq_iff_tendsto, metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff,
prod.map_def]
lemma tendsto_uniformity_iff_dist_tendsto_zero {ι : Type*} {f : ι → α × α} {p : filter ι} :
tendsto f p (𝓤 α) ↔ tendsto (λ x, dist (f x).1 (f x).2) p (𝓝 0) :=
by rw [metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff]
lemma filter.tendsto.congr_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h₁ : tendsto f₁ p (𝓝 a)) (h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₂ p (𝓝 a) :=
h₁.congr_uniformity $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
alias filter.tendsto.congr_dist ← tendsto_of_tendsto_of_dist
lemma tendsto_iff_of_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₁ p (𝓝 a) ↔ tendsto f₂ p (𝓝 a) :=
uniform.tendsto_congr $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
end real
section cauchy_seq
variables [nonempty β] [semilattice_sup β]
/-- In a pseudometric space, Cauchy sequences are characterized by the fact that, eventually,
the distance between its elements is arbitrarily small -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem metric.cauchy_seq_iff {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, dist (u m) (u n) < ε :=
uniformity_basis_dist.cauchy_seq_iff
/-- A variation around the pseudometric characterization of Cauchy sequences -/
theorem metric.cauchy_seq_iff' {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) (u N) < ε :=
uniformity_basis_dist.cauchy_seq_iff'
/-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N`
and `b` converges to zero, then `s` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_tendsto_0 {s : β → α} (b : β → ℝ)
(h : ∀ n m N : β, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : tendsto b at_top (nhds 0)) :
cauchy_seq s :=
metric.cauchy_seq_iff.2 $ λ ε ε0,
(metric.tendsto_at_top.1 h₀ ε ε0).imp $ λ N hN m n hm hn,
calc dist (s m) (s n) ≤ b N : h m n N hm hn
... ≤ abs (b N) : le_abs_self _
... = dist (b N) 0 : by rw real.dist_0_eq_abs; refl
... < ε : (hN _ (le_refl N))
/-- A Cauchy sequence on the natural numbers is bounded. -/
theorem cauchy_seq_bdd {u : ℕ → α} (hu : cauchy_seq u) :
∃ R > 0, ∀ m n, dist (u m) (u n) < R :=
begin
rcases metric.cauchy_seq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩,
suffices : ∃ R > 0, ∀ n, dist (u n) (u N) < R,
{ rcases this with ⟨R, R0, H⟩,
exact ⟨_, add_pos R0 R0, λ m n,
lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩ },
let R := finset.sup (finset.range N) (λ n, nndist (u n) (u N)),
refine ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, λ n, _⟩,
cases le_or_lt N n,
{ exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2) },
{ have : _ ≤ R := finset.le_sup (finset.mem_range.2 h),
exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one) }
end
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma cauchy_seq_iff_le_tendsto_0 {s : ℕ → α} : cauchy_seq s ↔ ∃ b : ℕ → ℝ,
(∀ n, 0 ≤ b n) ∧
(∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧
tendsto b at_top (𝓝 0) :=
⟨λ hs, begin
/- `s` is a Cauchy sequence. The sequence `b` will be constructed by taking
the supremum of the distances between `s n` and `s m` for `n m ≥ N`.
First, we prove that all these distances are bounded, as otherwise the Sup
would not make sense. -/
let S := λ N, (λ(p : ℕ × ℕ), dist (s p.1) (s p.2)) '' {p | p.1 ≥ N ∧ p.2 ≥ N},
have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x,
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
refine λ N, ⟨R, _⟩, rintro _ ⟨⟨m, n⟩, _, rfl⟩,
exact le_of_lt (hR m n) },
have bdd : bdd_above (range (λ(p : ℕ × ℕ), dist (s p.1) (s p.2))),
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
use R, rintro _ ⟨⟨m, n⟩, rfl⟩, exact le_of_lt (hR m n) },
-- Prove that it bounds the distances of points in the Cauchy sequence
have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ Sup (S N) :=
λ m n N hm hn, le_cSup (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩,
have S0m : ∀ n, (0:ℝ) ∈ S n := λ n, ⟨⟨n, n⟩, ⟨le_refl _, le_refl _⟩, dist_self _⟩,
have S0 := λ n, le_cSup (hS n) (S0m n),
-- Prove that it tends to `0`, by using the Cauchy property of `s`
refine ⟨λ N, Sup (S N), S0, ub, metric.tendsto_at_top.2 (λ ε ε0, _)⟩,
refine (metric.cauchy_seq_iff.1 hs (ε/2) (half_pos ε0)).imp (λ N hN n hn, _),
rw [real.dist_0_eq_abs, abs_of_nonneg (S0 n)],
refine lt_of_le_of_lt (cSup_le ⟨_, S0m _⟩ _) (half_lt_self ε0),
rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩,
exact le_of_lt (hN _ _ (le_trans hn hm') (le_trans hn hn'))
end,
λ ⟨b, _, b_bound, b_lim⟩, cauchy_seq_of_le_tendsto_0 b b_bound b_lim⟩
end cauchy_seq
/-- Pseudometric space structure pulled back by a function. -/
def pseudo_metric_space.induced {α β} (f : α → β)
(m : pseudo_metric_space β) : pseudo_metric_space α :=
{ dist := λ x y, dist (f x) (f y),
dist_self := λ x, dist_self _,
dist_comm := λ x y, dist_comm _ _,
dist_triangle := λ x y z, dist_triangle _ _ _,
edist := λ x y, edist (f x) (f y),
edist_dist := λ x y, edist_dist _ _,
to_uniform_space := uniform_space.comap f m.to_uniform_space,
uniformity_dist := begin
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, dist (f x) (f y)),
refine λ s, mem_comap.trans _,
split; intro H,
{ rcases H with ⟨r, ru, rs⟩,
rcases mem_uniformity_dist.1 ru with ⟨ε, ε0, hε⟩,
refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
{ rcases H with ⟨ε, ε0, hε⟩,
exact ⟨_, dist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
end }
/-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of
`pseudo_metric_space.induced` useful in case if the domain already has a `uniform_space`
structure. -/
def uniform_inducing.comap_pseudo_metric_space {α β} [uniform_space α] [pseudo_metric_space β]
(f : α → β) (h : uniform_inducing f) : pseudo_metric_space α :=
(pseudo_metric_space.induced f ‹_›).replace_uniformity h.comap_uniformity.symm
instance subtype.psudo_metric_space {α : Type*} {p : α → Prop} [t : pseudo_metric_space α] :
pseudo_metric_space (subtype p) :=
pseudo_metric_space.induced coe t
theorem subtype.pseudo_dist_eq {p : α → Prop} (x y : subtype p) : dist x y = dist (x : α) y := rfl
section nnreal
instance : pseudo_metric_space ℝ≥0 := by unfold nnreal; apply_instance
lemma nnreal.dist_eq (a b : ℝ≥0) : dist a b = abs ((a:ℝ) - b) := rfl
lemma nnreal.nndist_eq (a b : ℝ≥0) :
nndist a b = max (a - b) (b - a) :=
begin
wlog h : a ≤ b,
{ apply nnreal.coe_eq.1,
rw [nnreal.sub_eq_zero h, max_eq_right (zero_le $ b - a), ← dist_nndist, nnreal.dist_eq,
nnreal.coe_sub h, abs_eq_max_neg, neg_sub],
apply max_eq_right,
linarith [nnreal.coe_le_coe.2 h] },
rwa [nndist_comm, max_comm]
end
end nnreal
section prod
instance prod.pseudo_metric_space_max [pseudo_metric_space β] : pseudo_metric_space (α × β) :=
{ dist := λ x y, max (dist x.1 y.1) (dist x.2 y.2),
dist_self := λ x, by simp,
dist_comm := λ x y, by simp [dist_comm],
dist_triangle := λ x y z, max_le
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
edist := λ x y, max (edist x.1 y.1) (edist x.2 y.2),
edist_dist := assume x y, begin
have : monotone ennreal.of_real := assume x y h, ennreal.of_real_le_of_real h,
rw [edist_dist, edist_dist, ← this.map_max]
end,
uniformity_dist := begin
refine uniformity_prod.trans _,
simp only [uniformity_basis_dist.eq_binfi, comap_infi],
rw ← infi_inf_eq, congr, funext,
rw ← infi_inf_eq, congr, funext,
simp [inf_principal, ext_iff, max_lt_iff]
end,
to_uniform_space := prod.uniform_space }
lemma prod.dist_eq [pseudo_metric_space β] {x y : α × β} :
dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl
theorem ball_prod_same [pseudo_metric_space β] (x : α) (y : β) (r : ℝ) :
(ball x r).prod (ball y r) = ball (x, y) r :=
ext $ λ z, by simp [prod.dist_eq]
theorem closed_ball_prod_same [pseudo_metric_space β] (x : α) (y : β) (r : ℝ) :
(closed_ball x r).prod (closed_ball y r) = closed_ball (x, y) r :=
ext $ λ z, by simp [prod.dist_eq]
end prod
theorem uniform_continuous_dist : uniform_continuous (λp:α×α, dist p.1 p.2) :=
metric.uniform_continuous_iff.2 (λ ε ε0, ⟨ε/2, half_pos ε0,
begin
suffices,
{ intros p q h, cases p with p₁ p₂, cases q with q₁ q₂,
cases max_lt_iff.1 h with h₁ h₂, clear h,
dsimp at h₁ h₂ ⊢,
rw real.dist_eq,
refine abs_sub_lt_iff.2 ⟨_, _⟩,
{ revert p₁ p₂ q₁ q₂ h₁ h₂, exact this },
{ apply this; rwa dist_comm } },
intros p₁ p₂ q₁ q₂ h₁ h₂,
have := add_lt_add
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1,
rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this
end⟩)
theorem uniform_continuous.dist [uniform_space β] {f g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (λb, dist (f b) (g b)) :=
uniform_continuous_dist.comp (hf.prod_mk hg)
@[continuity]
theorem continuous_dist : continuous (λp:α×α, dist p.1 p.2) :=
uniform_continuous_dist.continuous
@[continuity]
theorem continuous.dist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, dist (f b) (g b)) :=
continuous_dist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.dist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, dist (f x) (g x)) x (𝓝 (dist a b)) :=
(continuous_dist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma nhds_comap_dist (a : α) : (𝓝 (0 : ℝ)).comap (λa', dist a' a) = 𝓝 a :=
by simp only [@nhds_eq_comap_uniformity α, metric.uniformity_eq_comap_nhds_zero,
comap_comap, (∘), dist_comm]
lemma tendsto_iff_dist_tendsto_zero {f : β → α} {x : filter β} {a : α} :
(tendsto f x (𝓝 a)) ↔ (tendsto (λb, dist (f b) a) x (𝓝 0)) :=
by rw [← nhds_comap_dist a, tendsto_comap_iff]
lemma uniform_continuous_nndist : uniform_continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_subtype_mk uniform_continuous_dist _
lemma uniform_continuous.nndist [uniform_space β] {f g : β → α} (hf : uniform_continuous f)
(hg : uniform_continuous g) :
uniform_continuous (λ b, nndist (f b) (g b)) :=
uniform_continuous_nndist.comp (hf.prod_mk hg)
lemma continuous_nndist : continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_nndist.continuous
lemma continuous.nndist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, nndist (f b) (g b)) :=
continuous_nndist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.nndist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, nndist (f x) (g x)) x (𝓝 (nndist a b)) :=
(continuous_nndist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
namespace metric
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
theorem is_closed_ball : is_closed (closed_ball x ε) :=
is_closed_le (continuous_id.dist continuous_const) continuous_const
lemma is_closed_sphere : is_closed (sphere x ε) :=
is_closed_eq (continuous_id.dist continuous_const) continuous_const
@[simp] theorem closure_closed_ball : closure (closed_ball x ε) = closed_ball x ε :=
is_closed_ball.closure_eq
theorem closure_ball_subset_closed_ball : closure (ball x ε) ⊆ closed_ball x ε :=
closure_minimal ball_subset_closed_ball is_closed_ball
theorem frontier_ball_subset_sphere : frontier (ball x ε) ⊆ sphere x ε :=
frontier_lt_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem frontier_closed_ball_subset_sphere : frontier (closed_ball x ε) ⊆ sphere x ε :=
frontier_le_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem ball_subset_interior_closed_ball : ball x ε ⊆ interior (closed_ball x ε) :=
interior_maximal ball_subset_closed_ball is_open_ball
/-- ε-characterization of the closure in pseudometric spaces-/
theorem mem_closure_iff {α : Type u} [pseudo_metric_space α] {s : set α} {a : α} :
a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
(mem_closure_iff_nhds_basis nhds_basis_ball).trans $
by simp only [mem_ball, dist_comm]
lemma mem_closure_range_iff {α : Type u} [pseudo_metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀ε>0, ∃ k : β, dist a (e k) < ε :=
by simp only [mem_closure_iff, exists_range_iff]
lemma mem_closure_range_iff_nat {α : Type u} [pseudo_metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀n : ℕ, ∃ k : β, dist a (e k) < 1 / ((n : ℝ) + 1) :=
(mem_closure_iff_nhds_basis nhds_basis_ball_inv_nat_succ).trans $
by simp only [mem_ball, dist_comm, exists_range_iff, forall_const]
theorem mem_of_closed' {α : Type u} [pseudo_metric_space α] {s : set α} (hs : is_closed s)
{a : α} : a ∈ s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
by simpa only [hs.closure_eq] using @mem_closure_iff _ _ s a
end metric
section pi
open finset
variables {π : β → Type*} [fintype β] [∀b, pseudo_metric_space (π b)]
/-- A finite product of pseudometric spaces is a pseudometric space, with the sup distance. -/
instance pseudo_metric_space_pi : pseudo_metric_space (Πb, π b) :=
begin
/- we construct the instance from the pseudoemetric space instance to avoid checking again that
the uniformity is the same as the product uniformity, but we register nevertheless a nice formula
for the distance -/
refine pseudo_emetric_space.to_pseudo_metric_space_of_dist
(λf g, ((sup univ (λb, nndist (f b) (g b)) : ℝ≥0) : ℝ)) _ _,
show ∀ (x y : Π (b : β), π b), edist x y ≠ ⊤,
{ assume x y,
rw ← lt_top_iff_ne_top,
have : (⊥ : ℝ≥0∞) < ⊤ := ennreal.coe_lt_top,
simp [edist_pi_def, finset.sup_lt_iff this, edist_lt_top] },
show ∀ (x y : Π (b : β), π b), ↑(sup univ (λ (b : β), nndist (x b) (y b))) =
ennreal.to_real (sup univ (λ (b : β), edist (x b) (y b))),
{ assume x y,
simp only [edist_nndist],
norm_cast }
end
lemma nndist_pi_def (f g : Πb, π b) : nndist f g = sup univ (λb, nndist (f b) (g b)) :=
subtype.eta _ _
lemma dist_pi_def (f g : Πb, π b) :
dist f g = (sup univ (λb, nndist (f b) (g b)) : ℝ≥0) := rfl
@[simp] lemma dist_pi_const [nonempty β] (a b : α) : dist (λ x : β, a) (λ _, b) = dist a b :=
by simpa only [dist_edist] using congr_arg ennreal.to_real (edist_pi_const a b)
@[simp] lemma nndist_pi_const [nonempty β] (a b : α) :
nndist (λ x : β, a) (λ _, b) = nndist a b := nnreal.eq $ dist_pi_const a b
lemma dist_pi_lt_iff {f g : Πb, π b} {r : ℝ} (hr : 0 < r) :
dist f g < r ↔ ∀b, dist (f b) (g b) < r :=
begin
lift r to ℝ≥0 using hr.le,
simp [dist_pi_def, finset.sup_lt_iff (show ⊥ < r, from hr)],
end
lemma dist_pi_le_iff {f g : Πb, π b} {r : ℝ} (hr : 0 ≤ r) :
dist f g ≤ r ↔ ∀b, dist (f b) (g b) ≤ r :=
begin
lift r to ℝ≥0 using hr,
simp [nndist_pi_def]
end
lemma nndist_le_pi_nndist (f g : Πb, π b) (b : β) : nndist (f b) (g b) ≤ nndist f g :=
by { rw [nndist_pi_def], exact finset.le_sup (finset.mem_univ b) }
lemma dist_le_pi_dist (f g : Πb, π b) (b : β) : dist (f b) (g b) ≤ dist f g :=
by simp only [dist_nndist, nnreal.coe_le_coe, nndist_le_pi_nndist f g b]
/-- An open ball in a product space is a product of open balls. See also `metric.ball_pi'`
for a version assuming `nonempty β` instead of `0 < r`. -/
lemma ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 < r) :
ball x r = set.pi univ (λ b, ball (x b) r) :=
by { ext p, simp [dist_pi_lt_iff hr] }
/-- An open ball in a product space is a product of open balls. See also `metric.ball_pi`
for a version assuming `0 < r` instead of `nonempty β`. -/
lemma ball_pi' [nonempty β] (x : Π b, π b) (r : ℝ) :
ball x r = set.pi univ (λ b, ball (x b) r) :=
(lt_or_le 0 r).elim (ball_pi x) $ λ hr, by simp [ball_eq_empty.2 hr]
/-- A closed ball in a product space is a product of closed balls. See also `metric.closed_ball_pi'`
for a version assuming `nonempty β` instead of `0 ≤ r`. -/
lemma closed_ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 ≤ r) :
closed_ball x r = set.pi univ (λ b, closed_ball (x b) r) :=
by { ext p, simp [dist_pi_le_iff hr] }
/-- A closed ball in a product space is a product of closed balls. See also `metric.closed_ball_pi`
for a version assuming `0 ≤ r` instead of `nonempty β`. -/
lemma closed_ball_pi' [nonempty β] (x : Π b, π b) (r : ℝ) :
closed_ball x r = set.pi univ (λ b, closed_ball (x b) r) :=
(le_or_lt 0 r).elim (closed_ball_pi x) $ λ hr, by simp [closed_ball_eq_empty.2 hr]
end pi
section compact
/-- Any compact set in a pseudometric space can be covered by finitely many balls of a given
positive radius -/
lemma finite_cover_balls_of_compact {α : Type u} [pseudo_metric_space α] {s : set α}
(hs : is_compact s) {e : ℝ} (he : 0 < e) :
∃t ⊆ s, finite t ∧ s ⊆ ⋃x∈t, ball x e :=
begin
apply hs.elim_finite_subcover_image,
{ simp [is_open_ball] },
{ intros x xs,
simp,
exact ⟨x, ⟨xs, by simpa⟩⟩ }
end
alias finite_cover_balls_of_compact ← is_compact.finite_cover_balls
end compact
section proper_space
open metric
/-- A pseudometric space is proper if all closed balls are compact. -/
class proper_space (α : Type u) [pseudo_metric_space α] : Prop :=
(compact_ball : ∀x:α, ∀r, is_compact (closed_ball x r))
/-- In a proper pseudometric space, all spheres are compact. -/
lemma is_compact_sphere {α : Type*} [pseudo_metric_space α] [proper_space α] (x : α) (r : ℝ) :
is_compact (sphere x r) :=
compact_of_is_closed_subset (proper_space.compact_ball x r) is_closed_sphere
sphere_subset_closed_ball
/-- In a proper pseudometric space, any sphere is a `compact_space` when considered as a subtype. -/
instance {α : Type*} [pseudo_metric_space α] [proper_space α] (x : α) (r : ℝ) :
compact_space (sphere x r) :=
is_compact_iff_compact_space.mp (is_compact_sphere _ _)
/-- A proper pseudo metric space is sigma compact, and therefore second countable. -/
@[priority 100] -- see Note [lower instance priority]
instance second_countable_of_proper [proper_space α] :
second_countable_topology α :=
begin
-- We already have `sigma_compact_space_of_locally_compact_second_countable`, so we don't
-- add an instance for `sigma_compact_space`.
suffices : sigma_compact_space α, by exactI emetric.second_countable_of_sigma_compact α,
rcases em (nonempty α) with ⟨⟨x⟩⟩|hn,
{ exact ⟨⟨λ n, closed_ball x n, λ n, proper_space.compact_ball _ _,
Union_closed_ball_nat _⟩⟩ },
{ exact ⟨⟨λ n, ∅, λ n, is_compact_empty, Union_eq_univ_iff.2 $ λ x, (hn ⟨x⟩).elim⟩⟩ }
end
lemma tendsto_dist_right_cocompact_at_top [proper_space α] (x : α) :
tendsto (λ y, dist y x) (cocompact α) at_top :=
(has_basis_cocompact.tendsto_iff at_top_basis).2 $ λ r hr,
⟨closed_ball x r, proper_space.compact_ball x r, λ y hy, (not_le.1 $ mt mem_closed_ball.2 hy).le⟩
lemma tendsto_dist_left_cocompact_at_top [proper_space α] (x : α) :
tendsto (dist x) (cocompact α) at_top :=
by simpa only [dist_comm] using tendsto_dist_right_cocompact_at_top x
/-- If all closed balls of large enough radius are compact, then the space is proper. Especially
useful when the lower bound for the radius is 0. -/
lemma proper_space_of_compact_closed_ball_of_le
(R : ℝ) (h : ∀x:α, ∀r, R ≤ r → is_compact (closed_ball x r)) :
proper_space α :=
⟨begin
assume x r,
by_cases hr : R ≤ r,
{ exact h x r hr },
{ have : closed_ball x r = closed_ball x R ∩ closed_ball x r,
{ symmetry,
apply inter_eq_self_of_subset_right,
exact closed_ball_subset_closed_ball (le_of_lt (not_le.1 hr)) },
rw this,
exact (h x R (le_refl _)).inter_right is_closed_ball }
end⟩
/- A compact pseudometric space is proper -/
@[priority 100] -- see Note [lower instance priority]
instance proper_of_compact [compact_space α] : proper_space α :=
⟨assume x r, is_closed_ball.is_compact⟩
/-- A proper space is locally compact -/
@[priority 100] -- see Note [lower instance priority]
instance locally_compact_of_proper [proper_space α] :
locally_compact_space α :=
locally_compact_space_of_has_basis (λ x, nhds_basis_closed_ball) $
λ x ε ε0, proper_space.compact_ball _ _
/-- A proper space is complete -/
@[priority 100] -- see Note [lower instance priority]
instance complete_of_proper [proper_space α] : complete_space α :=
⟨begin
intros f hf,
/- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
ball (therefore compact by properness) where it is nontrivial. -/
obtain ⟨t, t_fset, ht⟩ : ∃ t ∈ f, ∀ x y ∈ t, dist x y < 1 :=
(metric.cauchy_iff.1 hf).2 1 zero_lt_one,
rcases hf.1.nonempty_of_mem t_fset with ⟨x, xt⟩,
have : closed_ball x 1 ∈ f := mem_of_superset t_fset (λ y yt, (ht y x yt xt).le),
rcases (compact_iff_totally_bounded_complete.1 (proper_space.compact_ball x 1)).2 f hf
(le_principal_iff.2 this) with ⟨y, -, hy⟩,
exact ⟨y, hy⟩
end⟩
/-- A finite product of proper spaces is proper. -/
instance pi_proper_space {π : β → Type*} [fintype β] [∀b, pseudo_metric_space (π b)]
[h : ∀b, proper_space (π b)] : proper_space (Πb, π b) :=
begin
refine proper_space_of_compact_closed_ball_of_le 0 (λx r hr, _),
rw closed_ball_pi _ hr,
apply is_compact_univ_pi (λb, _),
apply (h b).compact_ball
end
variables [proper_space α] {x : α} {r : ℝ} {s : set α}
/-- If a nonempty ball in a proper space includes a closed set `s`, then there exists a nonempty
ball with the same center and a strictly smaller radius that includes `s`. -/
lemma exists_pos_lt_subset_ball (hr : 0 < r) (hs : is_closed s) (h : s ⊆ ball x r) :
∃ r' ∈ Ioo 0 r, s ⊆ ball x r' :=
begin
unfreezingI { rcases eq_empty_or_nonempty s with rfl|hne },
{ exact ⟨r / 2, ⟨half_pos hr, half_lt_self hr⟩, empty_subset _⟩ },
have : is_compact s,
from compact_of_is_closed_subset (proper_space.compact_ball x r) hs
(subset.trans h ball_subset_closed_ball),
obtain ⟨y, hys, hy⟩ : ∃ y ∈ s, s ⊆ closed_ball x (dist y x),
from this.exists_forall_ge hne (continuous_id.dist continuous_const).continuous_on,
have hyr : dist y x < r, from h hys,
rcases exists_between hyr with ⟨r', hyr', hrr'⟩,
exact ⟨r', ⟨dist_nonneg.trans_lt hyr', hrr'⟩, subset.trans hy $ closed_ball_subset_ball hyr'⟩
end
/-- If a ball in a proper space includes a closed set `s`, then there exists a ball with the same
center and a strictly smaller radius that includes `s`. -/
lemma exists_lt_subset_ball (hs : is_closed s) (h : s ⊆ ball x r) :
∃ r' < r, s ⊆ ball x r' :=
begin
cases le_or_lt r 0 with hr hr,
{ rw [ball_eq_empty.2 hr, subset_empty_iff] at h, unfreezingI { subst s },
exact (no_bot r).imp (λ r' hr', ⟨hr', empty_subset _⟩) },
{ exact (exists_pos_lt_subset_ball hr hs h).imp (λ r' hr', ⟨hr'.fst.2, hr'.snd⟩) }
end
end proper_space
namespace metric
section second_countable
open topological_space
/-- A pseudometric space is second countable if, for every `ε > 0`, there is a countable set which
is `ε`-dense. -/
lemma second_countable_of_almost_dense_set
(H : ∀ε > (0 : ℝ), ∃ s : set α, countable s ∧ (∀x, ∃y ∈ s, dist x y ≤ ε)) :
second_countable_topology α :=
begin
refine emetric.second_countable_of_almost_dense_set (λ ε ε0, _),
rcases ennreal.lt_iff_exists_nnreal_btwn.1 ε0 with ⟨ε', ε'0, ε'ε⟩,
choose s hsc y hys hyx using H ε' (by exact_mod_cast ε'0),
refine ⟨s, hsc, bUnion_eq_univ_iff.2 (λ x, ⟨y x, hys _, le_trans _ ε'ε.le⟩)⟩,
exact_mod_cast hyx x
end
end second_countable
end metric
lemma lebesgue_number_lemma_of_metric
{s : set α} {ι} {c : ι → set α} (hs : is_compact s)
(hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=
let ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂,
⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en in
⟨δ, δ0, assume x hx, let ⟨i, hi⟩ := hn x hx in
⟨i, assume y hy, hi (hδ (mem_ball'.mp hy))⟩⟩
lemma lebesgue_number_lemma_of_metric_sUnion
{s : set α} {c : set (set α)} (hs : is_compact s)
(hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t :=
by rw sUnion_eq_Union at hc₂;
simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
namespace metric
/-- Boundedness of a subset of a pseudometric space. We formulate the definition to work
even in the empty space. -/
def bounded (s : set α) : Prop :=
∃C, ∀x y ∈ s, dist x y ≤ C
section bounded
variables {x : α} {s t : set α} {r : ℝ}
@[simp] lemma bounded_empty : bounded (∅ : set α) :=
⟨0, by simp⟩
lemma bounded_iff_mem_bounded : bounded s ↔ ∀ x ∈ s, bounded s :=
⟨λ h _ _, h, λ H,
s.eq_empty_or_nonempty.elim
(λ hs, hs.symm ▸ bounded_empty)
(λ ⟨x, hx⟩, H x hx)⟩
/-- Subsets of a bounded set are also bounded -/
lemma bounded.subset (incl : s ⊆ t) : bounded t → bounded s :=
Exists.imp $ λ C hC x y hx hy, hC x y (incl hx) (incl hy)
/-- Closed balls are bounded -/
lemma bounded_closed_ball : bounded (closed_ball x r) :=
⟨r + r, λ y z hy hz, begin
simp only [mem_closed_ball] at *,
calc dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add hy hz
end⟩
/-- Open balls are bounded -/
lemma bounded_ball : bounded (ball x r) :=
bounded_closed_ball.subset ball_subset_closed_ball
/-- Given a point, a bounded subset is included in some ball around this point -/
lemma bounded_iff_subset_ball (c : α) : bounded s ↔ ∃r, s ⊆ closed_ball c r :=
begin
split; rintro ⟨C, hC⟩,
{ cases s.eq_empty_or_nonempty with h h,
{ subst s, exact ⟨0, by simp⟩ },
{ rcases h with ⟨x, hx⟩,
exact ⟨C + dist x c, λ y hy, calc
dist y c ≤ dist y x + dist x c : dist_triangle _ _ _
... ≤ C + dist x c : add_le_add_right (hC y x hy hx) _⟩ } },
{ exact bounded_closed_ball.subset hC }
end
lemma bounded.subset_ball (h : bounded s) (c : α) : ∃ r, s ⊆ closed_ball c r :=
(bounded_iff_subset_ball c).1 h
lemma bounded_closure_of_bounded (h : bounded s) : bounded (closure s) :=
let ⟨C, h⟩ := h in
⟨C, λ a b ha hb, (is_closed_le' C).closure_subset $ map_mem_closure2 continuous_dist ha hb h⟩
alias bounded_closure_of_bounded ← metric.bounded.closure
@[simp] lemma bounded_closure_iff : bounded (closure s) ↔ bounded s :=
⟨λ h, h.subset subset_closure, λ h, h.closure⟩
/-- The union of two bounded sets is bounded iff each of the sets is bounded -/
@[simp] lemma bounded_union :
bounded (s ∪ t) ↔ bounded s ∧ bounded t :=
⟨λh, ⟨h.subset (by simp), h.subset (by simp)⟩,
begin
rintro ⟨hs, ht⟩,
refine bounded_iff_mem_bounded.2 (λ x _, _),
rw bounded_iff_subset_ball x at hs ht ⊢,
rcases hs with ⟨Cs, hCs⟩, rcases ht with ⟨Ct, hCt⟩,
exact ⟨max Cs Ct, union_subset
(subset.trans hCs $ closed_ball_subset_closed_ball $ le_max_left _ _)
(subset.trans hCt $ closed_ball_subset_closed_ball $ le_max_right _ _)⟩,
end⟩
/-- A finite union of bounded sets is bounded -/
lemma bounded_bUnion {I : set β} {s : β → set α} (H : finite I) :
bounded (⋃i∈I, s i) ↔ ∀i ∈ I, bounded (s i) :=
finite.induction_on H (by simp) $ λ x I _ _ IH,
by simp [or_imp_distrib, forall_and_distrib, IH]
/-- A totally bounded set is bounded -/
lemma _root_.totally_bounded.bounded {s : set α} (h : totally_bounded s) : bounded s :=
-- We cover the totally bounded set by finitely many balls of radius 1,
-- and then argue that a finite union of bounded sets is bounded
let ⟨t, fint, subs⟩ := (totally_bounded_iff.mp h) 1 zero_lt_one in
bounded.subset subs $ (bounded_bUnion fint).2 $ λ i hi, bounded_ball
/-- A compact set is bounded -/
lemma _root_.is_compact.bounded {s : set α} (h : is_compact s) : bounded s :=
-- A compact set is totally bounded, thus bounded
h.totally_bounded.bounded
/-- A finite set is bounded -/
lemma bounded_of_finite {s : set α} (h : finite s) : bounded s :=
h.is_compact.bounded
alias bounded_of_finite ← set.finite.bounded
/-- A singleton is bounded -/
lemma bounded_singleton {x : α} : bounded ({x} : set α) :=
bounded_of_finite $ finite_singleton _
/-- Characterization of the boundedness of the range of a function -/
lemma bounded_range_iff {f : β → α} : bounded (range f) ↔ ∃C, ∀x y, dist (f x) (f y) ≤ C :=
exists_congr $ λ C, ⟨
λ H x y, H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩,
by rintro H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact H x y⟩
/-- In a compact space, all sets are bounded -/
lemma bounded_of_compact_space [compact_space α] : bounded s :=
compact_univ.bounded.subset (subset_univ _)
/-- The Heine–Borel theorem:
In a proper space, a set is compact if and only if it is closed and bounded -/
lemma compact_iff_closed_bounded [t2_space α] [proper_space α] :
is_compact s ↔ is_closed s ∧ bounded s :=
⟨λ h, ⟨h.is_closed, h.bounded⟩, begin
rintro ⟨hc, hb⟩,
cases s.eq_empty_or_nonempty with h h, {simp [h, is_compact_empty]},
rcases h with ⟨x, hx⟩,
rcases (bounded_iff_subset_ball x).1 hb with ⟨r, hr⟩,
exact compact_of_is_closed_subset (proper_space.compact_ball x r) hc hr
end⟩
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] [order_topology α]
lemma bounded_Icc (a b : α) : bounded (Icc a b) :=
(totally_bounded_Icc a b).bounded
lemma bounded_Ico (a b : α) : bounded (Ico a b) :=
(totally_bounded_Ico a b).bounded
lemma bounded_Ioc (a b : α) : bounded (Ioc a b) :=
(totally_bounded_Ioc a b).bounded
lemma bounded_Ioo (a b : α) : bounded (Ioo a b) :=
(totally_bounded_Ioo a b).bounded
/-- In a pseudo metric space with a conditionally complete linear order such that the order and the
metric structure give the same topology, any order-bounded set is metric-bounded. -/
lemma bounded_of_bdd_above_of_bdd_below {s : set α} (h₁ : bdd_above s) (h₂ : bdd_below s) :
bounded s :=
let ⟨u, hu⟩ := h₁, ⟨l, hl⟩ := h₂ in
bounded.subset (λ x hx, mem_Icc.mpr ⟨hl hx, hu hx⟩) (bounded_Icc l u)
end conditionally_complete_linear_order
end bounded
section diam
variables {s : set α} {x y z : α}
/-- The diameter of a set in a metric space. To get controllable behavior even when the diameter
should be infinite, we express it in terms of the emetric.diameter -/
def diam (s : set α) : ℝ := ennreal.to_real (emetric.diam s)
/-- The diameter of a set is always nonnegative -/
lemma diam_nonneg : 0 ≤ diam s := ennreal.to_real_nonneg
lemma diam_subsingleton (hs : s.subsingleton) : diam s = 0 :=
by simp only [diam, emetric.diam_subsingleton hs, ennreal.zero_to_real]
/-- The empty set has zero diameter -/
@[simp] lemma diam_empty : diam (∅ : set α) = 0 :=
diam_subsingleton subsingleton_empty
/-- A singleton has zero diameter -/
@[simp] lemma diam_singleton : diam ({x} : set α) = 0 :=
diam_subsingleton subsingleton_singleton
-- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x})
lemma diam_pair : diam ({x, y} : set α) = dist x y :=
by simp only [diam, emetric.diam_pair, dist_edist]
-- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x}))
lemma diam_triple :
metric.diam ({x, y, z} : set α) = max (max (dist x y) (dist x z)) (dist y z) :=
begin
simp only [metric.diam, emetric.diam_triple, dist_edist],
rw [ennreal.to_real_max, ennreal.to_real_max];
apply_rules [ne_of_lt, edist_lt_top, max_lt]
end
/-- If the distance between any two points in a set is bounded by some constant `C`,
then `ennreal.of_real C` bounds the emetric diameter of this set. -/
lemma ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
emetric.diam s ≤ ennreal.of_real C :=
emetric.diam_le $
λ x hx y hy, (edist_dist x y).symm ▸ ennreal.of_real_le_of_real (h x hx y hy)
/-- If the distance between any two points in a set is bounded by some non-negative constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
diam s ≤ C :=
ennreal.to_real_le_of_le_of_real h₀ (ediam_le_of_forall_dist_le h)
/-- If the distance between any two points in a nonempty set is bounded by some constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le_of_nonempty (hs : s.nonempty) {C : ℝ}
(h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) : diam s ≤ C :=
have h₀ : 0 ≤ C, from let ⟨x, hx⟩ := hs in le_trans dist_nonneg (h x hx x hx),
diam_le_of_forall_dist_le h₀ h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem' (h : emetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) :
dist x y ≤ diam s :=
begin
rw [diam, dist_edist],
rw ennreal.to_real_le_to_real (edist_ne_top _ _) h,
exact emetric.edist_le_diam_of_mem hx hy
end
/-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/
lemma bounded_iff_ediam_ne_top : bounded s ↔ emetric.diam s ≠ ⊤ :=
iff.intro
(λ ⟨C, hC⟩, ne_top_of_le_ne_top ennreal.of_real_ne_top
(ediam_le_of_forall_dist_le $ λ x hx y hy, hC x y hx hy))
(λ h, ⟨diam s, λ x y hx hy, dist_le_diam_of_mem' h hx hy⟩)
lemma bounded.ediam_ne_top (h : bounded s) : emetric.diam s ≠ ⊤ :=
bounded_iff_ediam_ne_top.1 h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem (h : bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=
dist_le_diam_of_mem' h.ediam_ne_top hx hy
lemma ediam_of_unbounded (h : ¬(bounded s)) : emetric.diam s = ∞ :=
by rwa [bounded_iff_ediam_ne_top, not_not] at h
/-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`.
This lemma makes it possible to avoid side conditions in some situations -/
lemma diam_eq_zero_of_unbounded (h : ¬(bounded s)) : diam s = 0 :=
by rw [diam, ediam_of_unbounded h, ennreal.top_to_real]
/-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/
lemma diam_mono {s t : set α} (h : s ⊆ t) (ht : bounded t) : diam s ≤ diam t :=
begin
unfold diam,
rw ennreal.to_real_le_to_real (bounded.subset h ht).ediam_ne_top ht.ediam_ne_top,
exact emetric.diam_mono h
end
/-- The diameter of a union is controlled by the sum of the diameters, and the distance between
any two points in each of the sets. This lemma is true without any side condition, since it is
obviously true if `s ∪ t` is unbounded. -/
lemma diam_union {t : set α} (xs : x ∈ s) (yt : y ∈ t) :
diam (s ∪ t) ≤ diam s + dist x y + diam t :=
begin
by_cases H : bounded (s ∪ t),
{ have hs : bounded s, from H.subset (subset_union_left _ _),
have ht : bounded t, from H.subset (subset_union_right _ _),
rw [bounded_iff_ediam_ne_top] at H hs ht,
rw [dist_edist, diam, diam, diam, ← ennreal.to_real_add, ← ennreal.to_real_add,
ennreal.to_real_le_to_real];
repeat { apply ennreal.add_ne_top.2; split }; try { assumption };
try { apply edist_ne_top },
exact emetric.diam_union xs yt },
{ rw [diam_eq_zero_of_unbounded H],
apply_rules [add_nonneg, diam_nonneg, dist_nonneg] }
end
/-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/
lemma diam_union' {t : set α} (h : (s ∩ t).nonempty) : diam (s ∪ t) ≤ diam s + diam t :=
begin
rcases h with ⟨x, ⟨xs, xt⟩⟩,
simpa using diam_union xs xt
end
/-- The diameter of a closed ball of radius `r` is at most `2 r`. -/
lemma diam_closed_ball {r : ℝ} (h : 0 ≤ r) : diam (closed_ball x r) ≤ 2 * r :=
diam_le_of_forall_dist_le (mul_nonneg (le_of_lt zero_lt_two) h) $ λa ha b hb, calc
dist a b ≤ dist a x + dist b x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add ha hb
... = 2 * r : by simp [mul_two, mul_comm]
/-- The diameter of a ball of radius `r` is at most `2 r`. -/
lemma diam_ball {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ 2 * r :=
le_trans (diam_mono ball_subset_closed_ball bounded_closed_ball) (diam_closed_ball h)
end diam
end metric
lemma comap_dist_right_at_top_le_cocompact (x : α) : comap (λ y, dist y x) at_top ≤ cocompact α :=
begin
refine filter.has_basis_cocompact.ge_iff.2 (λ s hs, mem_comap.2 _),
rcases hs.bounded.subset_ball x with ⟨r, hr⟩,
exact ⟨Ioi r, Ioi_mem_at_top r, λ y hy hys, (mem_closed_ball.1 $ hr hys).not_lt hy⟩
end
lemma comap_dist_left_at_top_le_cocompact (x : α) : comap (dist x) at_top ≤ cocompact α :=
by simpa only [dist_comm _ x] using comap_dist_right_at_top_le_cocompact x
lemma comap_dist_right_at_top_eq_cocompact [proper_space α] (x : α) :
comap (λ y, dist y x) at_top = cocompact α :=
(comap_dist_right_at_top_le_cocompact x).antisymm $ (tendsto_dist_right_cocompact_at_top x).le_comap
lemma comap_dist_left_at_top_eq_cocompact [proper_space α] (x : α) :
comap (dist x) at_top = cocompact α :=
(comap_dist_left_at_top_le_cocompact x).antisymm $ (tendsto_dist_left_cocompact_at_top x).le_comap
lemma tendsto_cocompact_of_tendsto_dist_comp_at_top {f : β → α} {l : filter β} (x : α)
(h : tendsto (λ y, dist (f y) x) l at_top) : tendsto f l (cocompact α) :=
by { refine tendsto.mono_right _ (comap_dist_right_at_top_le_cocompact x), rwa tendsto_comap_iff }
namespace int
open metric
/-- Under the coercion from `ℤ` to `ℝ`, inverse images of compact sets are finite. -/
lemma tendsto_coe_cofinite : tendsto (coe : ℤ → ℝ) cofinite (cocompact ℝ) :=
begin
refine tendsto_cocompact_of_tendsto_dist_comp_at_top (0 : ℝ) _,
simp only [filter.tendsto_at_top, eventually_cofinite, not_le, ← mem_ball],
change ∀ r : ℝ, finite (coe ⁻¹' (ball (0 : ℝ) r)),
simp [real.ball_eq, Ioo_ℤ_finite]
end
end int
/-- We now define `metric_space`, extending `pseudo_metric_space`. -/
class metric_space (α : Type u) extends pseudo_metric_space α : Type u :=
(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
/-- Construct a metric space structure whose underlying topological space structure
(definitionally) agrees which a pre-existing topology which is compatible with a given distance
function. -/
def metric_space.of_metrizable {α : Type*} [topological_space α] (dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(H : ∀ s : set α, is_open s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s)
(eq_of_dist_eq_zero : ∀ x y : α, dist x y = 0 → x = y) : metric_space α :=
{ eq_of_dist_eq_zero := eq_of_dist_eq_zero,
..pseudo_metric_space.of_metrizable dist dist_self dist_comm dist_triangle H }
variables {γ : Type w} [metric_space γ]
theorem eq_of_dist_eq_zero {x y : γ} : dist x y = 0 → x = y :=
metric_space.eq_of_dist_eq_zero
@[simp] theorem dist_eq_zero {x y : γ} : dist x y = 0 ↔ x = y :=
iff.intro eq_of_dist_eq_zero (assume : x = y, this ▸ dist_self _)
@[simp] theorem zero_eq_dist {x y : γ} : 0 = dist x y ↔ x = y :=
by rw [eq_comm, dist_eq_zero]
theorem dist_ne_zero {x y : γ} : dist x y ≠ 0 ↔ x ≠ y :=
by simpa only [not_iff_not] using dist_eq_zero
@[simp] theorem dist_le_zero {x y : γ} : dist x y ≤ 0 ↔ x = y :=
by simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y
@[simp] theorem dist_pos {x y : γ} : 0 < dist x y ↔ x ≠ y :=
by simpa only [not_le] using not_congr dist_le_zero
theorem eq_of_forall_dist_le {x y : γ} (h : ∀ ε > 0, dist x y ≤ ε) : x = y :=
eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)
/--Deduce the equality of points with the vanishing of the nonnegative distance-/
theorem eq_of_nndist_eq_zero {x y : γ} : nndist x y = 0 → x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
/--Characterize the equality of points with the vanishing of the nonnegative distance-/
@[simp] theorem nndist_eq_zero {x y : γ} : nndist x y = 0 ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
@[simp] theorem zero_eq_nndist {x y : γ} : 0 = nndist x y ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, zero_eq_dist]
namespace metric
variables {x : γ} {s : set γ}
@[simp] lemma closed_ball_zero : closed_ball x 0 = {x} :=
set.ext $ λ y, dist_le_zero
/-- A map between metric spaces is a uniform embedding if and only if the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem uniform_embedding_iff' [metric_space β] {f : γ → β} :
uniform_embedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, dist a b < δ → dist (f a) (f b) < ε) ∧
(∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, dist (f a) (f b) < ε → dist a b < δ) :=
begin
split,
{ assume h,
exact ⟨uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1,
(uniform_embedding_iff.1 h).2.2⟩ },
{ rintros ⟨h₁, h₂⟩,
refine uniform_embedding_iff.2 ⟨_, uniform_continuous_iff.2 h₁, h₂⟩,
assume x y hxy,
have : dist x y ≤ 0,
{ refine le_of_forall_lt' (λδ δpos, _),
rcases h₂ δ δpos with ⟨ε, εpos, hε⟩,
have : dist (f x) (f y) < ε, by simpa [hxy],
exact hε this },
simpa using this }
end
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_separated : separated_space γ :=
separated_def.2 $ λ x y h, eq_of_forall_dist_le $
λ ε ε0, le_of_lt (h _ (dist_mem_uniformity ε0))
/-- If a `pseudo_metric_space` is separated, then it is a `metric_space`. -/
def of_t2_pseudo_metric_space {α : Type*} [pseudo_metric_space α]
(h : separated_space α) : metric_space α :=
{ eq_of_dist_eq_zero := λ x y hdist,
begin
refine separated_def.1 h x y (λ s hs, _),
obtain ⟨ε, hε, H⟩ := mem_uniformity_dist.1 hs,
exact H (show dist x y < ε, by rwa [hdist])
end
..‹pseudo_metric_space α› }
/-- A metric space induces an emetric space -/
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_emetric_space : emetric_space γ :=
{ eq_of_edist_eq_zero := assume x y h, by simpa [edist_dist] using h,
..pseudo_metric_space.to_pseudo_emetric_space, }
end metric
/-- Build a new metric space from an old one where the bundled uniform structure is provably
(but typically non-definitionaly) equal to some given uniform structure.
See Note [forgetful inheritance].
-/
def metric_space.replace_uniformity {γ} [U : uniform_space γ] (m : metric_space γ)
(H : @uniformity _ U = @uniformity _ emetric_space.to_uniform_space') :
metric_space γ :=
{ eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _,
..pseudo_metric_space.replace_uniformity m.to_pseudo_metric_space H, }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. In this definition, the distance
is given separately, to be able to prescribe some expression which is not defeq to the push-forward
of the edistance to reals. -/
def emetric_space.to_metric_space_of_dist {α : Type u} [e : emetric_space α]
(dist : α → α → ℝ)
(edist_ne_top : ∀x y: α, edist x y ≠ ⊤)
(h : ∀x y, dist x y = ennreal.to_real (edist x y)) :
metric_space α :=
{ dist := dist,
eq_of_dist_eq_zero := λx y hxy,
by simpa [h, ennreal.to_real_eq_zero_iff, edist_ne_top x y] using hxy,
..pseudo_emetric_space.to_pseudo_metric_space_of_dist dist edist_ne_top h, }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. -/
def emetric_space.to_metric_space {α : Type u} [e : emetric_space α] (h : ∀x y: α, edist x y ≠ ⊤) :
metric_space α :=
emetric_space.to_metric_space_of_dist (λx y, ennreal.to_real (edist x y)) h (λx y, rfl)
/-- Metric space structure pulled back by an injective function. Injectivity is necessary to
ensure that `dist x y = 0` only if `x = y`. -/
def metric_space.induced {γ β} (f : γ → β) (hf : function.injective f)
(m : metric_space β) : metric_space γ :=
{ eq_of_dist_eq_zero := λ x y h, hf (dist_eq_zero.1 h),
..pseudo_metric_space.induced f m.to_pseudo_metric_space }
/-- Pull back a metric space structure by a uniform embedding. This is a version of
`metric_space.induced` useful in case if the domain already has a `uniform_space` structure. -/
def uniform_embedding.comap_metric_space {α β} [uniform_space α] [metric_space β] (f : α → β)
(h : uniform_embedding f) : metric_space α :=
(metric_space.induced f h.inj ‹_›).replace_uniformity h.comap_uniformity.symm
instance subtype.metric_space {α : Type*} {p : α → Prop} [t : metric_space α] :
metric_space (subtype p) :=
metric_space.induced coe (λ x y, subtype.ext) t
theorem subtype.dist_eq {p : α → Prop} (x y : subtype p) : dist x y = dist (x : α) y := rfl
instance : metric_space empty :=
{ dist := λ _ _, 0,
dist_self := λ _, rfl,
dist_comm := λ _ _, rfl,
eq_of_dist_eq_zero := λ _ _ _, subsingleton.elim _ _,
dist_triangle := λ _ _ _, show (0:ℝ) ≤ 0 + 0, by rw add_zero, }
instance : metric_space punit :=
{ dist := λ _ _, 0,
dist_self := λ _, rfl,
dist_comm := λ _ _, rfl,
eq_of_dist_eq_zero := λ _ _ _, subsingleton.elim _ _,
dist_triangle := λ _ _ _, show (0:ℝ) ≤ 0 + 0, by rw add_zero, }
section real
/-- Instantiate the reals as a metric space. -/
instance real.metric_space : metric_space ℝ :=
{ eq_of_dist_eq_zero := λ x y h, by simpa [dist, sub_eq_zero] using h,
..real.pseudo_metric_space }
end real
section nnreal
instance : metric_space ℝ≥0 := subtype.metric_space
end nnreal
section prod
instance prod.metric_space_max [metric_space β] : metric_space (γ × β) :=
{ eq_of_dist_eq_zero := λ x y h, begin
cases max_le_iff.1 (le_of_eq h) with h₁ h₂,
exact prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩
end,
..prod.pseudo_metric_space_max, }
end prod
section pi
open finset
variables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
/-- A finite product of metric spaces is a metric space, with the sup distance. -/
instance metric_space_pi : metric_space (Πb, π b) :=
/- we construct the instance from the emetric space instance to avoid checking again that the
uniformity is the same as the product uniformity, but we register nevertheless a nice formula
for the distance -/
{ eq_of_dist_eq_zero := assume f g eq0,
begin
have eq1 : edist f g = 0 := by simp only [edist_dist, eq0, ennreal.of_real_zero],
have eq2 : sup univ (λ (b : β), edist (f b) (g b)) ≤ 0 := le_of_eq eq1,
simp only [finset.sup_le_iff] at eq2,
exact (funext $ assume b, edist_le_zero.1 $ eq2 b $ mem_univ b)
end,
..pseudo_metric_space_pi }
end pi
namespace metric
section second_countable
open topological_space
/-- A metric space space is second countable if one can reconstruct up to any `ε>0` any element of
the space from countably many data. -/
lemma second_countable_of_countable_discretization {α : Type u} [metric_space α]
(H : ∀ε > (0 : ℝ), ∃ (β : Type*) [encodable β] (F : α → β), ∀x y, F x = F y → dist x y ≤ ε) :
second_countable_topology α :=
begin
cases (univ : set α).eq_empty_or_nonempty with hs hs,
{ haveI : compact_space α := ⟨by rw hs; exact is_compact_empty⟩, by apply_instance },
rcases hs with ⟨x0, hx0⟩,
letI : inhabited α := ⟨x0⟩,
refine second_countable_of_almost_dense_set (λε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
resetI,
let Finv := function.inv_fun F,
refine ⟨range Finv, ⟨countable_range _, λx, _⟩⟩,
let x' := Finv (F x),
have : F x' = F x := function.inv_fun_eq ⟨x, rfl⟩,
exact ⟨x', mem_range_self _, hF _ _ this.symm⟩
end
end second_countable
end metric
section eq_rel
/-- The canonical equivalence relation on a pseudometric space. -/
def pseudo_metric.dist_setoid (α : Type u) [pseudo_metric_space α] : setoid α :=
setoid.mk (λx y, dist x y = 0)
begin
unfold equivalence,
repeat { split },
{ exact pseudo_metric_space.dist_self },
{ assume x y h, rwa pseudo_metric_space.dist_comm },
{ assume x y z hxy hyz,
refine le_antisymm _ dist_nonneg,
calc dist x z ≤ dist x y + dist y z : pseudo_metric_space.dist_triangle _ _ _
... = 0 + 0 : by rw [hxy, hyz]
... = 0 : by simp }
end
local attribute [instance] pseudo_metric.dist_setoid
/-- The canonical quotient of a pseudometric space, identifying points at distance `0`. -/
@[reducible] definition pseudo_metric_quot (α : Type u) [pseudo_metric_space α] : Type* :=
quotient (pseudo_metric.dist_setoid α)
instance has_dist_metric_quot {α : Type u} [pseudo_metric_space α] :
has_dist (pseudo_metric_quot α) :=
{ dist := quotient.lift₂ (λp q : α, dist p q)
begin
assume x y x' y' hxx' hyy',
have Hxx' : dist x x' = 0 := hxx',
have Hyy' : dist y y' = 0 := hyy',
have A : dist x y ≤ dist x' y' := calc
dist x y ≤ dist x x' + dist x' y : pseudo_metric_space.dist_triangle _ _ _
... = dist x' y : by simp [Hxx']
... ≤ dist x' y' + dist y' y : pseudo_metric_space.dist_triangle _ _ _
... = dist x' y' : by simp [pseudo_metric_space.dist_comm, Hyy'],
have B : dist x' y' ≤ dist x y := calc
dist x' y' ≤ dist x' x + dist x y' : pseudo_metric_space.dist_triangle _ _ _
... = dist x y' : by simp [pseudo_metric_space.dist_comm, Hxx']
... ≤ dist x y + dist y y' : pseudo_metric_space.dist_triangle _ _ _
... = dist x y : by simp [Hyy'],
exact le_antisymm A B
end }
lemma pseudo_metric_quot_dist_eq {α : Type u} [pseudo_metric_space α] (p q : α) :
dist ⟦p⟧ ⟦q⟧ = dist p q := rfl
instance metric_space_quot {α : Type u} [pseudo_metric_space α] :
metric_space (pseudo_metric_quot α) :=
{ dist_self := begin
refine quotient.ind (λy, _),
exact pseudo_metric_space.dist_self _
end,
eq_of_dist_eq_zero := λxc yc, by exact quotient.induction_on₂ xc yc (λx y H, quotient.sound H),
dist_comm :=
λxc yc, quotient.induction_on₂ xc yc (λx y, pseudo_metric_space.dist_comm _ _),
dist_triangle :=
λxc yc zc, quotient.induction_on₃ xc yc zc (λx y z, pseudo_metric_space.dist_triangle _ _ _) }
end eq_rel
|
78b36f52a33ca1bca3a04d54d0fe44e3a8f035b1
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/sig5.lean
|
ab3de534caaaccf0e26b96596b89c5b2c1325d51
|
[
"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
| 251
|
lean
|
variable vec : Nat → Type
definition vec_with_len := sig len, vec len
variable n : Nat
variable v : vec n
check pair n v
check (show vec_with_len, from pair n v)
check (let v2 : vec_with_len := pair n v
in v2)
check (pair n v : vec_with_len)
|
5fd18536e0a8c5c0d67179a88d9a7328a9197ea2
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/analysis/calculus/iterated_deriv.lean
|
aa360588d8c87502b4a7cd6f21476c77f46b9ff3
|
[] |
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
| 15,533
|
lean
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.analysis.calculus.deriv
import Mathlib.analysis.calculus.times_cont_diff
import Mathlib.PostPort
universes u_1 u_2
namespace Mathlib
/-!
# One-dimensional iterated derivatives
We define the `n`-th derivative of a function `f : 𝕜 → F` as a function
`iterated_deriv n f : 𝕜 → F`, as well as a version on domains `iterated_deriv_within n f s : 𝕜 → F`,
and prove their basic properties.
## Main definitions and results
Let `𝕜` be a nondiscrete normed field, and `F` a normed vector space over `𝕜`. Let `f : 𝕜 → F`.
* `iterated_deriv n f` is the `n`-th derivative of `f`, seen as a function from `𝕜` to `F`.
It is defined as the `n`-th Fréchet derivative (which is a multilinear map) applied to the
vector `(1, ..., 1)`, to take advantage of all the existing framework, but we show that it
coincides with the naive iterative definition.
* `iterated_deriv_eq_iterate` states that the `n`-th derivative of `f` is obtained by starting
from `f` and differentiating it `n` times.
* `iterated_deriv_within n f s` is the `n`-th derivative of `f` within the domain `s`. It only
behaves well when `s` has the unique derivative property.
* `iterated_deriv_within_eq_iterate` states that the `n`-th derivative of `f` in the domain `s` is
obtained by starting from `f` and differentiating it `n` times within `s`. This only holds when
`s` has the unique derivative property.
## Implementation details
The results are deduced from the corresponding results for the more general (multilinear) iterated
Fréchet derivative. For this, we write `iterated_deriv n f` as the composition of
`iterated_fderiv 𝕜 n f` and a continuous linear equiv. As continuous linear equivs respect
differentiability and commute with differentiation, this makes it possible to prove readily that
the derivative of the `n`-th derivative is the `n+1`-th derivative in `iterated_deriv_within_succ`,
by translating the corresponding result `iterated_fderiv_within_succ_apply_left` for the
iterated Fréchet derivative.
-/
/-- The `n`-th iterated derivative of a function from `𝕜` to `F`, as a function from `𝕜` to `F`. -/
def iterated_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] (n : ℕ) (f : 𝕜 → F) (x : 𝕜) : F :=
coe_fn (iterated_fderiv 𝕜 n f x) fun (i : fin n) => 1
/-- The `n`-th iterated derivative of a function from `𝕜` to `F` within a set `s`, as a function
from `𝕜` to `F`. -/
def iterated_deriv_within {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] (n : ℕ) (f : 𝕜 → F) (s : set 𝕜) (x : 𝕜) : F :=
coe_fn (iterated_fderiv_within 𝕜 n f s x) fun (i : fin n) => 1
theorem iterated_deriv_within_univ {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} : iterated_deriv_within n f set.univ = iterated_deriv n f := sorry
/-! ### Properties of the iterated derivative within a set -/
theorem iterated_deriv_within_eq_iterated_fderiv_within {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {s : set 𝕜} {x : 𝕜} : iterated_deriv_within n f s x = coe_fn (iterated_fderiv_within 𝕜 n f s x) fun (i : fin n) => 1 :=
rfl
/-- Write the iterated derivative as the composition of a continuous linear equiv and the iterated
Fréchet derivative -/
theorem iterated_deriv_within_eq_equiv_comp {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {s : set 𝕜} : iterated_deriv_within n f s =
⇑(continuous_linear_equiv.symm (continuous_multilinear_map.pi_field_equiv 𝕜 (fin n) F)) ∘
iterated_fderiv_within 𝕜 n f s :=
funext fun (x : 𝕜) => Eq.refl (iterated_deriv_within n f s x)
/-- Write the iterated Fréchet derivative as the composition of a continuous linear equiv and the
iterated derivative. -/
theorem iterated_fderiv_within_eq_equiv_comp {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {s : set 𝕜} : iterated_fderiv_within 𝕜 n f s = ⇑(continuous_multilinear_map.pi_field_equiv 𝕜 (fin n) F) ∘ iterated_deriv_within n f s := sorry
/-- The `n`-th Fréchet derivative applied to a vector `(m 0, ..., m (n-1))` is the derivative
multiplied by the product of the `m i`s. -/
theorem iterated_fderiv_within_apply_eq_iterated_deriv_within_mul_prod {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {s : set 𝕜} {x : 𝕜} {m : fin n → 𝕜} : coe_fn (iterated_fderiv_within 𝕜 n f s x) m =
(finset.prod finset.univ fun (i : fin n) => m i) • iterated_deriv_within n f s x := sorry
@[simp] theorem iterated_deriv_within_zero {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {s : set 𝕜} : iterated_deriv_within 0 f s = f := sorry
@[simp] theorem iterated_deriv_within_one {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {s : set 𝕜} (hs : unique_diff_on 𝕜 s) {x : 𝕜} (hx : x ∈ s) : iterated_deriv_within 1 f s x = deriv_within f s x := sorry
/-- If the first `n` derivatives within a set of a function are continuous, and its first `n-1`
derivatives are differentiable, then the function is `C^n`. This is not an equivalence in general,
but this is an equivalence when the set has unique derivatives, see
`times_cont_diff_on_iff_continuous_on_differentiable_on_deriv`. -/
theorem times_cont_diff_on_of_continuous_on_differentiable_on_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {s : set 𝕜} {n : with_top ℕ} (Hcont : ∀ (m : ℕ), ↑m ≤ n → continuous_on (fun (x : 𝕜) => iterated_deriv_within m f s x) s) (Hdiff : ∀ (m : ℕ), ↑m < n → differentiable_on 𝕜 (fun (x : 𝕜) => iterated_deriv_within m f s x) s) : times_cont_diff_on 𝕜 n f s := sorry
/-- To check that a function is `n` times continuously differentiable, it suffices to check that its
first `n` derivatives are differentiable. This is slightly too strong as the condition we
require on the `n`-th derivative is differentiability instead of continuity, but it has the
advantage of avoiding the discussion of continuity in the proof (and for `n = ∞` this is optimal).
-/
theorem times_cont_diff_on_of_differentiable_on_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {s : set 𝕜} {n : with_top ℕ} (h : ∀ (m : ℕ), ↑m ≤ n → differentiable_on 𝕜 (iterated_deriv_within m f s) s) : times_cont_diff_on 𝕜 n f s := sorry
/-- On a set with unique derivatives, a `C^n` function has derivatives up to `n` which are
continuous. -/
theorem times_cont_diff_on.continuous_on_iterated_deriv_within {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {s : set 𝕜} {n : with_top ℕ} {m : ℕ} (h : times_cont_diff_on 𝕜 n f s) (hmn : ↑m ≤ n) (hs : unique_diff_on 𝕜 s) : continuous_on (iterated_deriv_within m f s) s := sorry
/-- On a set with unique derivatives, a `C^n` function has derivatives less than `n` which are
differentiable. -/
theorem times_cont_diff_on.differentiable_on_iterated_deriv_within {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {s : set 𝕜} {n : with_top ℕ} {m : ℕ} (h : times_cont_diff_on 𝕜 n f s) (hmn : ↑m < n) (hs : unique_diff_on 𝕜 s) : differentiable_on 𝕜 (iterated_deriv_within m f s) s := sorry
/-- The property of being `C^n`, initially defined in terms of the Fréchet derivative, can be
reformulated in terms of the one-dimensional derivative on sets with unique derivatives. -/
theorem times_cont_diff_on_iff_continuous_on_differentiable_on_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {s : set 𝕜} {n : with_top ℕ} (hs : unique_diff_on 𝕜 s) : times_cont_diff_on 𝕜 n f s ↔
(∀ (m : ℕ), ↑m ≤ n → continuous_on (iterated_deriv_within m f s) s) ∧
∀ (m : ℕ), ↑m < n → differentiable_on 𝕜 (iterated_deriv_within m f s) s := sorry
/-- The `n+1`-th iterated derivative within a set with unique derivatives can be obtained by
differentiating the `n`-th iterated derivative. -/
theorem iterated_deriv_within_succ {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {s : set 𝕜} {x : 𝕜} (hxs : unique_diff_within_at 𝕜 s x) : iterated_deriv_within (n + 1) f s x = deriv_within (iterated_deriv_within n f s) s x := sorry
/-- The `n`-th iterated derivative within a set with unique derivatives can be obtained by
iterating `n` times the differentiation operation. -/
theorem iterated_deriv_within_eq_iterate {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {s : set 𝕜} {x : 𝕜} (hs : unique_diff_on 𝕜 s) (hx : x ∈ s) : iterated_deriv_within n f s x = nat.iterate (fun (g : 𝕜 → F) => deriv_within g s) n f x := sorry
/-- The `n+1`-th iterated derivative within a set with unique derivatives can be obtained by
taking the `n`-th derivative of the derivative. -/
theorem iterated_deriv_within_succ' {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {s : set 𝕜} {x : 𝕜} (hxs : unique_diff_on 𝕜 s) (hx : x ∈ s) : iterated_deriv_within (n + 1) f s x = iterated_deriv_within n (deriv_within f s) s x := sorry
/-! ### Properties of the iterated derivative on the whole space -/
theorem iterated_deriv_eq_iterated_fderiv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {x : 𝕜} : iterated_deriv n f x = coe_fn (iterated_fderiv 𝕜 n f x) fun (i : fin n) => 1 :=
rfl
/-- Write the iterated derivative as the composition of a continuous linear equiv and the iterated
Fréchet derivative -/
theorem iterated_deriv_eq_equiv_comp {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} : iterated_deriv n f =
⇑(continuous_linear_equiv.symm (continuous_multilinear_map.pi_field_equiv 𝕜 (fin n) F)) ∘ iterated_fderiv 𝕜 n f :=
funext fun (x : 𝕜) => Eq.refl (iterated_deriv n f x)
/-- Write the iterated Fréchet derivative as the composition of a continuous linear equiv and the
iterated derivative. -/
theorem iterated_fderiv_eq_equiv_comp {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} : iterated_fderiv 𝕜 n f = ⇑(continuous_multilinear_map.pi_field_equiv 𝕜 (fin n) F) ∘ iterated_deriv n f := sorry
/-- The `n`-th Fréchet derivative applied to a vector `(m 0, ..., m (n-1))` is the derivative
multiplied by the product of the `m i`s. -/
theorem iterated_fderiv_apply_eq_iterated_deriv_mul_prod {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} {x : 𝕜} {m : fin n → 𝕜} : coe_fn (iterated_fderiv 𝕜 n f x) m = (finset.prod finset.univ fun (i : fin n) => m i) • iterated_deriv n f x := sorry
@[simp] theorem iterated_deriv_zero {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} : iterated_deriv 0 f = f := sorry
@[simp] theorem iterated_deriv_one {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} : iterated_deriv 1 f = deriv f := sorry
/-- The property of being `C^n`, initially defined in terms of the Fréchet derivative, can be
reformulated in terms of the one-dimensional derivative. -/
theorem times_cont_diff_iff_iterated_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {n : with_top ℕ} : times_cont_diff 𝕜 n f ↔
(∀ (m : ℕ), ↑m ≤ n → continuous (iterated_deriv m f)) ∧ ∀ (m : ℕ), ↑m < n → differentiable 𝕜 (iterated_deriv m f) := sorry
/-- To check that a function is `n` times continuously differentiable, it suffices to check that its
first `n` derivatives are differentiable. This is slightly too strong as the condition we
require on the `n`-th derivative is differentiability instead of continuity, but it has the
advantage of avoiding the discussion of continuity in the proof (and for `n = ∞` this is optimal).
-/
theorem times_cont_diff_of_differentiable_iterated_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {n : with_top ℕ} (h : ∀ (m : ℕ), ↑m ≤ n → differentiable 𝕜 (iterated_deriv m f)) : times_cont_diff 𝕜 n f :=
iff.mpr times_cont_diff_iff_iterated_deriv
{ left := fun (m : ℕ) (hm : ↑m ≤ n) => differentiable.continuous (h m hm),
right := fun (m : ℕ) (hm : ↑m < n) => h m (le_of_lt hm) }
theorem times_cont_diff.continuous_iterated_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {n : with_top ℕ} (m : ℕ) (h : times_cont_diff 𝕜 n f) (hmn : ↑m ≤ n) : continuous (iterated_deriv m f) :=
and.left (iff.mp times_cont_diff_iff_iterated_deriv h) m hmn
theorem times_cont_diff.differentiable_iterated_deriv {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {n : with_top ℕ} (m : ℕ) (h : times_cont_diff 𝕜 n f) (hmn : ↑m < n) : differentiable 𝕜 (iterated_deriv m f) :=
and.right (iff.mp times_cont_diff_iff_iterated_deriv h) m hmn
/-- The `n+1`-th iterated derivative can be obtained by differentiating the `n`-th
iterated derivative. -/
theorem iterated_deriv_succ {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} : iterated_deriv (n + 1) f = deriv (iterated_deriv n f) := sorry
/-- The `n`-th iterated derivative can be obtained by iterating `n` times the
differentiation operation. -/
theorem iterated_deriv_eq_iterate {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} : iterated_deriv n f = nat.iterate deriv n f := sorry
/-- The `n+1`-th iterated derivative can be obtained by taking the `n`-th derivative of the
derivative. -/
theorem iterated_deriv_succ' {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {F : Type u_2} [normed_group F] [normed_space 𝕜 F] {n : ℕ} {f : 𝕜 → F} : iterated_deriv (n + 1) f = iterated_deriv n (deriv f) := sorry
|
dcb8b8eadc7997dd4eddbfa06a2b4508a32ee563
|
874a8d2247ab9a4516052498f80da2e32d0e3a48
|
/pigeonhole_init_v2.lean
|
47fc5490bd810cb664b63cda3ccb24c19d8bb8a6
|
[] |
no_license
|
AlexKontorovich/Spring2020Math492
|
378b36c643ee029f5ab91c1677889baa591f5e85
|
659108c5d864ff5c75b9b3b13b847aa5cff4348a
|
refs/heads/master
| 1,610,780,595,457
| 1,588,174,859,000
| 1,588,174,859,000
| 243,017,788
| 0
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,914
|
lean
|
import tactic
import data.real.basic
def injective {X Y} (f : X → Y)
:= ∀ x₁ x₂, f x₁ = f x₂ → x₁ = x₂
def range {X Y} (f : X → Y)
:= { y | ∃ x, f x = y }
/--
Type of pairs (k,p) where k
is a natural number and p is a witness to the proof that k < n.
-/
def finite_subset (n : ℕ) := Σ' k, k < n
def lift_finite (m n : ℕ) (p : m < n) : finite_subset m → finite_subset n
:= λ k, ⟨k.1, lt.trans k.2 p⟩
#print nat.sub_le
#print nat.lt_succ_of_le
#print nat.sub_lt_succ
#print nat.
lemma pred_exists (n : ℕ) (p: n > 0) : exists k, nat.succ k = n
:=
begin
/-
start with k:ℤ set k=n-1 but k>= 0 so k :ℕ
let k:ℤ := n-1,
let k_ge_zero : k ≥ 0 :=
begin
sorry,
end,
-/
induction n with d hd,
{linarith,},
{
existsi d,
refl}
end
lemma succ_greater_than_nat (n : ℕ) : nat.succ n > n
:=
begin
rw nat.succ_eq_add_one,
linarith,
/-
--exact nat.less_than_or_equal,
induction n with d hd,
{exact nat.zero_lt_one,
},
{
rw nat.succ_eq_add_one,
simp,
sorry,
-- nat.less_than_or_equal
-- exact nat.lt_of_succ_lt,
}
-/
end
/--
Pigeonhole principle, induction on n
-/
theorem pigeonhole_principle
(n m : ℕ)
(f : finite_subset n → finite_subset m)
: (n > m) → ¬(injective f)
:= begin
intros n_gt_m f_injective,
induction n with d hd,
linarith, -- case d=0
let g := f∘ (lift_finite d (d+1) (succ_greater_than_nat d)),
let hd' := hd g,
/-
induction m with d hd,
{
cases pred_exists n n_gt_m with k hk,
let n_gt_k := succ_greater_than_nat k,
rw hk at n_gt_k,
let fk := f ⟨k, n_gt_k⟩,
let fk2 := fk.2,
linarith,
},
{
let n_gt_d : n>d :=
begin
exact lt.trans (succ_greater_than_nat d) n_gt_m,
end,
sorry
},
-/
end
#print pigeonhole_principle
|
b5036a304c70249163589fb56044962ec77fb0d9
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/interactive/internalNamesIssue.lean
|
c5017978c9d5fd9a7520553d50c6cc626873c488
|
[
"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
| 178
|
lean
|
namespace Foo
def foo (x : Nat) := x + x + x
def bla (x : Nat) : Nat :=
if x > foo (10 + 10) then 1 else x * x * x
end Foo
#check Foo.
--^ textDocument/completion
|
f9e3c6a0da0150a8e9cfa5913fe8ce5270e668bf
|
43390109ab88557e6090f3245c47479c123ee500
|
/src/Topology/Material/Sutherland_Chapter_9.lean
|
a2ab57b42a1cabddf33008cb2b9e4da172e19847
|
[
"Apache-2.0"
] |
permissive
|
Ja1941/xena-UROP-2018
|
41f0956519f94d56b8bf6834a8d39473f4923200
|
b111fb87f343cf79eca3b886f99ee15c1dd9884b
|
refs/heads/master
| 1,662,355,955,139
| 1,590,577,325,000
| 1,590,577,325,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,447
|
lean
|
import analysis.topology.continuity
import analysis.topology.topological_space
import analysis.topology.infinite_sum
import analysis.topology.topological_structures
import analysis.topology.uniform_space
import data.equiv.basic
local attribute [instance] classical.prop_decidable
universes u v w
open set filter lattice classical
definition is_open_sets {α : Type u} (is_open : set α → Prop) :=
is_open univ ∧ (∀s t, is_open s → is_open t → is_open (s ∩ t)) ∧ (∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))
definition is_to_top {α : Type u} (is_open : set α → Prop) (H : is_open_sets (is_open)) : topological_space α :=
{ is_open := is_open,
is_open_univ := H.left,
is_open_inter := H.right.left,
is_open_sUnion := H.right.right
}
definition top_to_is {α : Type u} (T : topological_space α) : is_open_sets (T.is_open) :=
⟨T.is_open_univ,T.is_open_inter,T.is_open_sUnion⟩
--Definition 9.9
definition topology_dense {α : Type u} [topological_space α] (s : set α) : Prop := closure s = univ
--Proposition 9.11
theorem continuous_iff_image_closure_subset_closure_image {α : Type u} {β : Type v} [topological_space α] [topological_space β] (f : α → β) :
continuous f ↔ ∀ s, f '' closure s ⊆ closure (f '' s) :=
begin
split,
intros Hf s,
exact image_closure_subset_closure_image Hf,
intros Hf,
rw continuous_iff_is_closed,
intros b Hb,
let f_inv_b := f ⁻¹' (b),
let f_f_inv_b := f '' f_inv_b,
have H1 : f '' (closure f_inv_b) ⊆ closure (f '' f_inv_b), by exact Hf f_inv_b,
have H2 : closure (f '' f_inv_b) ⊆ closure b, by exact closure_mono (set.image_preimage_subset f b),
have H3 : closure b = b, by exact closure_eq_of_is_closed Hb,
rw H3 at H2,
have H4 : f '' (closure f_inv_b) ⊆ b := set.subset.trans H1 H2,
have H5 : f ⁻¹' (f '' closure f_inv_b) ⊆ f ⁻¹' b := set.preimage_mono H4,
have H6 : closure f_inv_b ⊆ f_inv_b := set.subset.trans (set.subset_preimage_image f (closure f_inv_b)) H5,
exact closure_eq_iff_is_closed.1 (set.eq_of_subset_of_subset H6 subset_closure),
end
--Prooposition 9.13
lemma closure_sInter' {α : Type u} [topological_space α] {I : set (set α)} :
closure (sInter I) ⊆ (⋂ (i ∈ I), closure i) :=
begin
have H1 : ⋂₀ I ⊆ ⋂ (i ∈ I), closure i,
apply subset_bInter,
intros x Hx,
exact subset.trans (sInter_subset_of_mem Hx) subset_closure,
have H2 : is_closed (⋂ (i : set α) (H : i ∈ I), closure i),
have H6 : (⋂ (i : set α) (H : i ∈ I), closure i) = ⋂ (i : I), closure i,
apply set.ext,
intro x, simp,
split, intro Hx,
intros i Hi,
exact Hx i Hi,
intro Hx,
intros x_1 Hx_1,
exact Hx x_1 Hx_1,
have H7 : is_closed (⋂ (i : I), closure ↑i) := @is_closed_Inter α _ _ _ (λ (i : I), @is_closed_closure _ _ ↑i),
rw ←H6 at H7,
assumption,
have H3 : closure ⋂₀ I ⊆ closure ⋂ (i ∈ I), closure i := closure_mono H1,
have H4 : @closure α _ (⋂ (i ∈ I), closure i) = ⋂ (i ∈ I), closure i,
apply closure_eq_of_is_closed,
exact H2,
rw H4 at H3,
exact H3,
end
#print Inter
--Corollary 9.21
lemma frontier_eq_frontier_compl {α : Type u} [topological_space α] {s : set α} : frontier s = frontier (-s) :=
begin
rw frontier_eq_closure_inter_closure, rw frontier_eq_closure_inter_closure,
finish,
end
--What should I have done instead of finish??
|
e086c19233d4889e14c1f1f31dcdc5022133a36b
|
69d4931b605e11ca61881fc4f66db50a0a875e39
|
/src/data/mv_polynomial/variables.lean
|
495b04d227efc8c84b285c135eb8dadd8d53ef8c
|
[
"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
| 23,088
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import data.mv_polynomial.monad
import data.set.disjointed
/-!
# Degrees and variables of polynomials
This file establishes many results about the degree and variable sets of a multivariate polynomial.
The *variable set* of a polynomial $P \in R[X]$ is a `finset` containing each $x \in X$
that appears in a monomial in $P$.
The *degree set* of a polynomial $P \in R[X]$ is a `multiset` containing, for each $x$ in the
variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a
monomial of $P$.
## Main declarations
* `mv_polynomial.degrees p` : the multiset of variables representing the union of the multisets
corresponding to each non-zero monomial in `p`.
For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}`
* `mv_polynomial.vars p` : the finset of variables occurring in `p`.
For example if `p = x⁴y+yz` then `vars p = {x, y, z}`
* `mv_polynomial.degree_of n p : ℕ` : the total degree of `p` with respect to the variable `n`.
For example if `p = x⁴y+yz` then `degree_of y p = 1`.
* `mv_polynomial.total_degree p : ℕ` :
the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`.
For example if `p = x⁴y+yz` then `total_degree p = 5`.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R : Type*` `[comm_semiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `mv_polynomial σ R` which mathematicians might call `X^s`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : mv_polynomial σ R`
-/
noncomputable theory
open_locale classical big_operators
open set function finsupp add_monoid_algebra
open_locale big_operators
universes u v w
variables {R : Type u} {S : Type v}
namespace mv_polynomial
variables {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section comm_semiring
variables [comm_semiring R] {p q : mv_polynomial σ R}
section degrees
/-! ### `degrees` -/
/--
The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
(For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.)
-/
def degrees (p : mv_polynomial σ R) : multiset σ :=
p.support.sup (λs:σ →₀ ℕ, s.to_multiset)
lemma degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ s.to_multiset :=
finset.sup_le $ assume t h,
begin
have := finsupp.support_single_subset h,
rw [finset.mem_singleton] at this,
rw this
end
lemma degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) :
degrees (monomial s a) = s.to_multiset :=
le_antisymm (degrees_monomial s a) $ finset.le_sup $
by rw [support_monomial, if_neg ha, finset.mem_singleton]
lemma degrees_C (a : R) : degrees (C a : mv_polynomial σ R) = 0 :=
multiset.le_zero.1 $ degrees_monomial _ _
lemma degrees_X' (n : σ) : degrees (X n : mv_polynomial σ R) ≤ {n} :=
le_trans (degrees_monomial _ _) $ le_of_eq $ to_multiset_single _ _
@[simp] lemma degrees_X [nontrivial R] (n : σ) : degrees (X n : mv_polynomial σ R) = {n} :=
(degrees_monomial_eq _ _ one_ne_zero).trans (to_multiset_single _ _)
@[simp] lemma degrees_zero : degrees (0 : mv_polynomial σ R) = 0 :=
by { rw ← C_0, exact degrees_C 0 }
@[simp] lemma degrees_one : degrees (1 : mv_polynomial σ R) = 0 := degrees_C 1
lemma degrees_add (p q : mv_polynomial σ R) : (p + q).degrees ≤ p.degrees ⊔ q.degrees :=
begin
refine finset.sup_le (assume b hb, _),
have := finsupp.support_add hb, rw finset.mem_union at this,
cases this,
{ exact le_sup_left_of_le (finset.le_sup this) },
{ exact le_sup_right_of_le (finset.le_sup this) },
end
lemma degrees_sum {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ R) :
(∑ i in s, f i).degrees ≤ s.sup (λi, (f i).degrees) :=
begin
refine s.induction _ _,
{ simp only [finset.sum_empty, finset.sup_empty, degrees_zero], exact le_refl _ },
{ assume i s his ih,
rw [finset.sup_insert, finset.sum_insert his],
exact le_trans (degrees_add _ _) (sup_le_sup_left ih _) }
end
lemma degrees_mul (p q : mv_polynomial σ R) : (p * q).degrees ≤ p.degrees + q.degrees :=
begin
refine finset.sup_le (assume b hb, _),
have := support_mul p q hb,
simp only [finset.mem_bUnion, finset.mem_singleton] at this,
rcases this with ⟨a₁, h₁, a₂, h₂, rfl⟩,
rw [finsupp.to_multiset_add],
exact add_le_add (finset.le_sup h₁) (finset.le_sup h₂)
end
lemma degrees_prod {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ R) :
(∏ i in s, f i).degrees ≤ ∑ i in s, (f i).degrees :=
begin
refine s.induction _ _,
{ simp only [finset.prod_empty, finset.sum_empty, degrees_one] },
{ assume i s his ih,
rw [finset.prod_insert his, finset.sum_insert his],
exact le_trans (degrees_mul _ _) (add_le_add_left ih _) }
end
lemma degrees_pow (p : mv_polynomial σ R) :
∀(n : ℕ), (p^n).degrees ≤ n • p.degrees
| 0 := begin rw [pow_zero, degrees_one], exact multiset.zero_le _ end
| (n + 1) := by { rw [pow_succ, add_smul, add_comm, one_smul],
exact le_trans (degrees_mul _ _) (add_le_add_left (degrees_pow n) _) }
lemma mem_degrees {p : mv_polynomial σ R} {i : σ} :
i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support :=
by simp only [degrees, multiset.mem_sup, ← mem_support_iff,
finsupp.mem_to_multiset, exists_prop]
lemma le_degrees_add {p q : mv_polynomial σ R} (h : p.degrees.disjoint q.degrees) :
p.degrees ≤ (p + q).degrees :=
begin
apply finset.sup_le,
intros d hd,
rw multiset.disjoint_iff_ne at h,
rw multiset.le_iff_count,
intros i,
rw [degrees, multiset.count_sup],
simp only [finsupp.count_to_multiset],
by_cases h0 : d = 0,
{ simp only [h0, zero_le, finsupp.zero_apply], },
{ refine @finset.le_sup _ _ _ (p + q).support _ d _,
rw [mem_support_iff, coeff_add],
suffices : q.coeff d = 0,
{ rwa [this, add_zero, coeff, ← finsupp.mem_support_iff], },
rw [← finsupp.support_eq_empty, ← ne.def, ← finset.nonempty_iff_ne_empty] at h0,
obtain ⟨j, hj⟩ := h0,
contrapose! h,
rw mem_support_iff at hd,
refine ⟨j, _, j, _, rfl⟩,
all_goals { rw mem_degrees, refine ⟨d, _, hj⟩, assumption } }
end
lemma degrees_add_of_disjoint
{p q : mv_polynomial σ R} (h : multiset.disjoint p.degrees q.degrees) :
(p + q).degrees = p.degrees ∪ q.degrees :=
begin
apply le_antisymm,
{ apply degrees_add },
{ apply multiset.union_le,
{ apply le_degrees_add h },
{ rw add_comm, apply le_degrees_add h.symm } }
end
lemma degrees_map [comm_semiring S] (p : mv_polynomial σ R) (f : R →+* S) :
(map f p).degrees ⊆ p.degrees :=
begin
dsimp only [degrees],
apply multiset.subset_of_le,
apply finset.sup_mono,
apply mv_polynomial.support_map_subset
end
lemma degrees_rename (f : σ → τ) (φ : mv_polynomial σ R) :
(rename f φ).degrees ⊆ (φ.degrees.map f) :=
begin
intros i,
rw [mem_degrees, multiset.mem_map],
rintro ⟨d, hd, hi⟩,
obtain ⟨x, rfl, hx⟩ := coeff_rename_ne_zero _ _ _ hd,
simp only [map_domain, finsupp.mem_support_iff] at hi,
rw [sum_apply, finsupp.sum] at hi,
contrapose! hi,
rw [finset.sum_eq_zero],
intros j hj,
simp only [exists_prop, mem_degrees] at hi,
specialize hi j ⟨x, hx, hj⟩,
rw [single_apply, if_neg hi],
end
lemma degrees_map_of_injective [comm_semiring S] (p : mv_polynomial σ R)
{f : R →+* S} (hf : injective f) : (map f p).degrees = p.degrees :=
by simp only [degrees, mv_polynomial.support_map_of_injective _ hf]
end degrees
section vars
/-! ### `vars` -/
/-- `vars p` is the set of variables appearing in the polynomial `p` -/
def vars (p : mv_polynomial σ R) : finset σ := p.degrees.to_finset
@[simp] lemma vars_0 : (0 : mv_polynomial σ R).vars = ∅ :=
by rw [vars, degrees_zero, multiset.to_finset_zero]
@[simp] lemma vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support :=
by rw [vars, degrees_monomial_eq _ _ h, finsupp.to_finset_to_multiset]
@[simp] lemma vars_C : (C r : mv_polynomial σ R).vars = ∅ :=
by rw [vars, degrees_C, multiset.to_finset_zero]
@[simp] lemma vars_X [nontrivial R] : (X n : mv_polynomial σ R).vars = {n} :=
by rw [X, vars_monomial (@one_ne_zero R _ _), finsupp.support_single_ne_zero (one_ne_zero : 1 ≠ 0)]
lemma mem_vars (i : σ) :
i ∈ p.vars ↔ ∃ (d : σ →₀ ℕ) (H : d ∈ p.support), i ∈ d.support :=
by simp only [vars, multiset.mem_to_finset, mem_degrees, mem_support_iff,
exists_prop]
lemma mem_support_not_mem_vars_zero
{f : mv_polynomial σ R} {x : σ →₀ ℕ} (H : x ∈ f.support) {v : σ} (h : v ∉ vars f) :
x v = 0 :=
begin
rw [vars, multiset.mem_to_finset] at h,
rw ← finsupp.not_mem_support_iff,
contrapose! h,
unfold degrees,
rw (show f.support = insert x f.support, from eq.symm $ finset.insert_eq_of_mem H),
rw finset.sup_insert,
simp only [multiset.mem_union, multiset.sup_eq_union],
left,
rwa [←to_finset_to_multiset, multiset.mem_to_finset] at h,
end
lemma vars_add_subset (p q : mv_polynomial σ R) :
(p + q).vars ⊆ p.vars ∪ q.vars :=
begin
intros x hx,
simp only [vars, finset.mem_union, multiset.mem_to_finset] at hx ⊢,
simpa using multiset.mem_of_le (degrees_add _ _) hx,
end
lemma vars_add_of_disjoint (h : disjoint p.vars q.vars) :
(p + q).vars = p.vars ∪ q.vars :=
begin
apply finset.subset.antisymm (vars_add_subset p q),
intros x hx,
simp only [vars, multiset.disjoint_to_finset] at h hx ⊢,
rw [degrees_add_of_disjoint h, multiset.to_finset_union],
exact hx
end
section mul
lemma vars_mul (φ ψ : mv_polynomial σ R) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars :=
begin
intro i,
simp only [mem_vars, finset.mem_union],
rintro ⟨d, hd, hi⟩,
rw [mem_support_iff, coeff_mul] at hd,
contrapose! hd, cases hd,
rw finset.sum_eq_zero,
rintro ⟨d₁, d₂⟩ H,
rw finsupp.mem_antidiagonal at H,
subst H,
obtain H|H : i ∈ d₁.support ∨ i ∈ d₂.support,
{ simpa only [finset.mem_union] using finsupp.support_add hi, },
{ suffices : coeff d₁ φ = 0, by simp [this],
rw [coeff, ← finsupp.not_mem_support_iff], intro, solve_by_elim, },
{ suffices : coeff d₂ ψ = 0, by simp [this],
rw [coeff, ← finsupp.not_mem_support_iff], intro, solve_by_elim, },
end
@[simp] lemma vars_one : (1 : mv_polynomial σ R).vars = ∅ :=
vars_C
lemma vars_pow (φ : mv_polynomial σ R) (n : ℕ) : (φ ^ n).vars ⊆ φ.vars :=
begin
induction n with n ih,
{ simp },
{ rw pow_succ,
apply finset.subset.trans (vars_mul _ _),
exact finset.union_subset (finset.subset.refl _) ih }
end
/--
The variables of the product of a family of polynomials
are a subset of the union of the sets of variables of each polynomial.
-/
lemma vars_prod {ι : Type*} {s : finset ι} (f : ι → mv_polynomial σ R) :
(∏ i in s, f i).vars ⊆ s.bUnion (λ i, (f i).vars) :=
begin
apply s.induction_on,
{ simp },
{ intros a s hs hsub,
simp only [hs, finset.bUnion_insert, finset.prod_insert, not_false_iff],
apply finset.subset.trans (vars_mul _ _),
exact finset.union_subset_union (finset.subset.refl _) hsub }
end
section integral_domain
variables {A : Type*} [integral_domain A]
lemma vars_C_mul (a : A) (ha : a ≠ 0) (φ : mv_polynomial σ A) : (C a * φ).vars = φ.vars :=
begin
ext1 i,
simp only [mem_vars, exists_prop, mem_support_iff],
apply exists_congr,
intro d,
apply and_congr _ iff.rfl,
rw [coeff_C_mul, mul_ne_zero_iff, eq_true_intro ha, true_and],
end
end integral_domain
end mul
section sum
variables {ι : Type*} (t : finset ι) (φ : ι → mv_polynomial σ R)
lemma vars_sum_subset :
(∑ i in t, φ i).vars ⊆ finset.bUnion t (λ i, (φ i).vars) :=
begin
apply t.induction_on,
{ simp },
{ intros a s has hsum,
rw [finset.bUnion_insert, finset.sum_insert has],
refine finset.subset.trans (vars_add_subset _ _)
(finset.union_subset_union (finset.subset.refl _) _),
assumption }
end
lemma vars_sum_of_disjoint (h : pairwise $ disjoint on (λ i, (φ i).vars)) :
(∑ i in t, φ i).vars = finset.bUnion t (λ i, (φ i).vars) :=
begin
apply t.induction_on,
{ simp },
{ intros a s has hsum,
rw [finset.bUnion_insert, finset.sum_insert has, vars_add_of_disjoint, hsum],
unfold pairwise on_fun at h,
rw hsum,
simp only [finset.disjoint_iff_ne] at h ⊢,
intros v hv v2 hv2,
rw finset.mem_bUnion at hv2,
rcases hv2 with ⟨i, his, hi⟩,
refine h a i _ _ hv _ hi,
rintro rfl,
contradiction }
end
end sum
section map
variables [comm_semiring S] (f : R →+* S)
variable (p)
lemma vars_map : (map f p).vars ⊆ p.vars :=
by simp [vars, degrees_map]
variable {f}
lemma vars_map_of_injective (hf : injective f) :
(map f p).vars = p.vars :=
by simp [vars, degrees_map_of_injective _ hf]
lemma vars_monomial_single (i : σ) {e : ℕ} {r : R} (he : e ≠ 0) (hr : r ≠ 0) :
(monomial (finsupp.single i e) r).vars = {i} :=
by rw [vars_monomial hr, finsupp.support_single_ne_zero he]
lemma vars_eq_support_bUnion_support : p.vars = p.support.bUnion finsupp.support :=
by { ext i, rw [mem_vars, finset.mem_bUnion] }
end map
end vars
section degree_of
/-! ### `degree_of` -/
/-- `degree_of n p` gives the highest power of X_n that appears in `p` -/
def degree_of (n : σ) (p : mv_polynomial σ R) : ℕ := p.degrees.count n
end degree_of
section total_degree
/-! ### `total_degree` -/
/-- `total_degree p` gives the maximum |s| over the monomials X^s in `p` -/
def total_degree (p : mv_polynomial σ R) : ℕ := p.support.sup (λs, s.sum $ λn e, e)
lemma total_degree_eq (p : mv_polynomial σ R) :
p.total_degree = p.support.sup (λm, m.to_multiset.card) :=
begin
rw [total_degree],
congr, funext m,
exact (finsupp.card_to_multiset _).symm
end
lemma total_degree_le_degrees_card (p : mv_polynomial σ R) :
p.total_degree ≤ p.degrees.card :=
begin
rw [total_degree_eq],
exact finset.sup_le (assume s hs, multiset.card_le_of_le $ finset.le_sup hs)
end
@[simp] lemma total_degree_C (a : R) : (C a : mv_polynomial σ R).total_degree = 0 :=
nat.eq_zero_of_le_zero $ finset.sup_le $ assume n hn,
have _ := finsupp.support_single_subset hn,
begin
rw [finset.mem_singleton] at this,
subst this,
exact le_refl _
end
@[simp] lemma total_degree_zero : (0 : mv_polynomial σ R).total_degree = 0 :=
by rw [← C_0]; exact total_degree_C (0 : R)
@[simp] lemma total_degree_one : (1 : mv_polynomial σ R).total_degree = 0 :=
total_degree_C (1 : R)
@[simp] lemma total_degree_X {R} [comm_semiring R] [nontrivial R] (s : σ) :
(X s : mv_polynomial σ R).total_degree = 1 :=
begin
rw [total_degree, support_X],
simp only [finset.sup, sum_single_index, finset.fold_singleton, sup_bot_eq],
end
lemma total_degree_add (a b : mv_polynomial σ R) :
(a + b).total_degree ≤ max a.total_degree b.total_degree :=
finset.sup_le $ assume n hn,
have _ := finsupp.support_add hn,
begin
rw finset.mem_union at this,
cases this,
{ exact le_max_left_of_le (finset.le_sup this) },
{ exact le_max_right_of_le (finset.le_sup this) }
end
lemma total_degree_mul (a b : mv_polynomial σ R) :
(a * b).total_degree ≤ a.total_degree + b.total_degree :=
finset.sup_le $ assume n hn,
have _ := add_monoid_algebra.support_mul a b hn,
begin
simp only [finset.mem_bUnion, finset.mem_singleton] at this,
rcases this with ⟨a₁, h₁, a₂, h₂, rfl⟩,
rw [finsupp.sum_add_index],
{ exact add_le_add (finset.le_sup h₁) (finset.le_sup h₂) },
{ assume a, refl },
{ assume a b₁ b₂, refl }
end
lemma total_degree_pow (a : mv_polynomial σ R) (n : ℕ) :
(a ^ n).total_degree ≤ n * a.total_degree :=
begin
induction n with n ih,
{ simp only [nat.nat_zero_eq_zero, zero_mul, pow_zero, total_degree_one] },
rw pow_succ,
calc total_degree (a * a ^ n) ≤ a.total_degree + (a^n).total_degree : total_degree_mul _ _
... ≤ a.total_degree + n * a.total_degree : add_le_add_left ih _
... = (n+1) * a.total_degree : by rw [add_mul, one_mul, add_comm]
end
lemma total_degree_list_prod :
∀(s : list (mv_polynomial σ R)), s.prod.total_degree ≤ (s.map mv_polynomial.total_degree).sum
| [] := by rw [@list.prod_nil (mv_polynomial σ R) _, total_degree_one]; refl
| (p :: ps) :=
begin
rw [@list.prod_cons (mv_polynomial σ R) _, list.map, list.sum_cons],
exact le_trans (total_degree_mul _ _) (add_le_add_left (total_degree_list_prod ps) _)
end
lemma total_degree_multiset_prod (s : multiset (mv_polynomial σ R)) :
s.prod.total_degree ≤ (s.map mv_polynomial.total_degree).sum :=
begin
refine quotient.induction_on s (assume l, _),
rw [multiset.quot_mk_to_coe, multiset.coe_prod, multiset.coe_map, multiset.coe_sum],
exact total_degree_list_prod l
end
lemma total_degree_finset_prod {ι : Type*}
(s : finset ι) (f : ι → mv_polynomial σ R) :
(s.prod f).total_degree ≤ ∑ i in s, (f i).total_degree :=
begin
refine le_trans (total_degree_multiset_prod _) _,
rw [multiset.map_map],
refl
end
lemma exists_degree_lt [fintype σ] (f : mv_polynomial σ R) (n : ℕ)
(h : f.total_degree < n * fintype.card σ) {d : σ →₀ ℕ} (hd : d ∈ f.support) :
∃ i, d i < n :=
begin
contrapose! h,
calc n * fintype.card σ
= ∑ s:σ, n : by rw [finset.sum_const, nat.nsmul_eq_mul, mul_comm, finset.card_univ]
... ≤ ∑ s, d s : finset.sum_le_sum (λ s _, h s)
... ≤ d.sum (λ i e, e) : by { rw [finsupp.sum_fintype], intros, refl }
... ≤ f.total_degree : finset.le_sup hd,
end
lemma coeff_eq_zero_of_total_degree_lt {f : mv_polynomial σ R} {d : σ →₀ ℕ}
(h : f.total_degree < ∑ i in d.support, d i) :
coeff d f = 0 :=
begin
classical,
rw [total_degree, finset.sup_lt_iff] at h,
{ specialize h d, rw mem_support_iff at h,
refine not_not.mp (mt h _), exact lt_irrefl _, },
{ exact lt_of_le_of_lt (nat.zero_le _) h, }
end
lemma total_degree_rename_le (f : σ → τ) (p : mv_polynomial σ R) :
(rename f p).total_degree ≤ p.total_degree :=
finset.sup_le $ assume b,
begin
assume h,
rw rename_eq at h,
have h' := finsupp.map_domain_support h,
rw finset.mem_image at h',
rcases h' with ⟨s, hs, rfl⟩,
rw finsupp.sum_map_domain_index,
exact le_trans (le_refl _) (finset.le_sup hs),
exact assume _, rfl,
exact assume _ _ _, rfl
end
end total_degree
section eval_vars
/-! ### `vars` and `eval` -/
variables [comm_semiring S]
lemma eval₂_hom_eq_constant_coeff_of_vars (f : R →+* S) {g : σ → S}
{p : mv_polynomial σ R} (hp : ∀ i ∈ p.vars, g i = 0) :
eval₂_hom f g p = f (constant_coeff p) :=
begin
conv_lhs { rw p.as_sum },
simp only [ring_hom.map_sum, eval₂_hom_monomial],
by_cases h0 : constant_coeff p = 0,
work_on_goal 0
{ rw [h0, f.map_zero, finset.sum_eq_zero],
intros d hd },
work_on_goal 1
{ rw [finset.sum_eq_single (0 : σ →₀ ℕ)],
{ rw [finsupp.prod_zero_index, mul_one],
refl },
intros d hd hd0, },
repeat
{ obtain ⟨i, hi⟩ : d.support.nonempty,
{ rw [constant_coeff_eq, coeff, ← finsupp.not_mem_support_iff] at h0,
rw [finset.nonempty_iff_ne_empty, ne.def, finsupp.support_eq_empty],
rintro rfl, contradiction },
rw [finsupp.prod, finset.prod_eq_zero hi, mul_zero],
rw [hp, zero_pow (nat.pos_of_ne_zero $ finsupp.mem_support_iff.mp hi)],
rw [mem_vars],
exact ⟨d, hd, hi⟩ },
{ rw [constant_coeff_eq, coeff, ← ne.def, ← finsupp.mem_support_iff] at h0,
intro, contradiction }
end
lemma aeval_eq_constant_coeff_of_vars [algebra R S] {g : σ → S}
{p : mv_polynomial σ R} (hp : ∀ i ∈ p.vars, g i = 0) :
aeval g p = algebra_map _ _ (constant_coeff p) :=
eval₂_hom_eq_constant_coeff_of_vars _ hp
lemma eval₂_hom_congr' {f₁ f₂ : R →+* S} {g₁ g₂ : σ → S} {p₁ p₂ : mv_polynomial σ R} :
f₁ = f₂ → (∀ i, i ∈ p₁.vars → i ∈ p₂.vars → g₁ i = g₂ i) → p₁ = p₂ →
eval₂_hom f₁ g₁ p₁ = eval₂_hom f₂ g₂ p₂ :=
begin
rintro rfl h rfl,
rename [p₁ p, f₁ f],
rw p.as_sum,
simp only [ring_hom.map_sum, eval₂_hom_monomial],
apply finset.sum_congr rfl,
intros d hd,
congr' 1,
simp only [finsupp.prod],
apply finset.prod_congr rfl,
intros i hi,
have : i ∈ p.vars, { rw mem_vars, exact ⟨d, hd, hi⟩ },
rw h i this this,
end
lemma vars_bind₁ (f : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) :
(bind₁ f φ).vars ⊆ φ.vars.bUnion (λ i, (f i).vars) :=
begin
calc (bind₁ f φ).vars
= (φ.support.sum (λ (x : σ →₀ ℕ), (bind₁ f) (monomial x (coeff x φ)))).vars :
by { rw [← alg_hom.map_sum, ← φ.as_sum], }
... ≤ φ.support.bUnion (λ (i : σ →₀ ℕ), ((bind₁ f) (monomial i (coeff i φ))).vars) :
vars_sum_subset _ _
... = φ.support.bUnion (λ (d : σ →₀ ℕ), (C (coeff d φ) * ∏ i in d.support, f i ^ d i).vars) :
by simp only [bind₁_monomial]
... ≤ φ.support.bUnion (λ (d : σ →₀ ℕ), d.support.bUnion (λ i, (f i).vars)) : _ -- proof below
... ≤ φ.vars.bUnion (λ (i : σ), (f i).vars) : _, -- proof below
{ apply finset.bUnion_mono,
intros d hd,
calc (C (coeff d φ) * ∏ (i : σ) in d.support, f i ^ d i).vars
≤ (C (coeff d φ)).vars ∪ (∏ (i : σ) in d.support, f i ^ d i).vars : vars_mul _ _
... ≤ (∏ (i : σ) in d.support, f i ^ d i).vars :
by simp only [finset.empty_union, vars_C, finset.le_iff_subset, finset.subset.refl]
... ≤ d.support.bUnion (λ (i : σ), (f i ^ d i).vars) : vars_prod _
... ≤ d.support.bUnion (λ (i : σ), (f i).vars) : _,
apply finset.bUnion_mono,
intros i hi,
apply vars_pow, },
{ intro j,
simp_rw finset.mem_bUnion,
rintro ⟨d, hd, ⟨i, hi, hj⟩⟩,
exact ⟨i, (mem_vars _).mpr ⟨d, hd, hi⟩, hj⟩ }
end
lemma mem_vars_bind₁ (f : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) {j : τ}
(h : j ∈ (bind₁ f φ).vars) :
∃ (i : σ), i ∈ φ.vars ∧ j ∈ (f i).vars :=
by simpa only [exists_prop, finset.mem_bUnion, mem_support_iff, ne.def] using vars_bind₁ f φ h
lemma vars_rename (f : σ → τ) (φ : mv_polynomial σ R) :
(rename f φ).vars ⊆ (φ.vars.image f) :=
begin
intros i hi,
simp only [vars, exists_prop, multiset.mem_to_finset, finset.mem_image] at hi ⊢,
simpa only [multiset.mem_map] using degrees_rename _ _ hi
end
lemma mem_vars_rename (f : σ → τ) (φ : mv_polynomial σ R) {j : τ} (h : j ∈ (rename f φ).vars) :
∃ (i : σ), i ∈ φ.vars ∧ f i = j :=
by simpa only [exists_prop, finset.mem_image] using vars_rename f φ h
end eval_vars
end comm_semiring
end mv_polynomial
|
8f2593275352d64644bbbb460f4f58c0db68eb98
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/algebra/char_p/subring.lean
|
7cfaf15dbf0846d539d445c85f6e7f94d6569ddb
|
[
"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,137
|
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.char_p.basic
import ring_theory.subring.basic
/-!
# Characteristic of subrings
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
universes u v
namespace char_p
instance subsemiring (R : Type u) [semiring R] (p : ℕ) [char_p R p] (S : subsemiring R) :
char_p S p :=
⟨λ x, iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [map_nat_cast, h],
λ h, map_nat_cast S.subtype x ▸ by rw [h, ring_hom.map_zero]⟩⟩
instance subring (R : Type u) [ring R] (p : ℕ) [char_p R p] (S : subring R) :
char_p S p :=
⟨λ x, iff.symm $ (char_p.cast_eq_zero_iff R p x).symm.trans
⟨λ h, subtype.eq $ show S.subtype x = 0, by rw [map_nat_cast, h],
λ h, map_nat_cast S.subtype x ▸ by rw [h, ring_hom.map_zero]⟩⟩
instance subring' (R : Type u) [comm_ring R] (p : ℕ) [char_p R p] (S : subring R) :
char_p S p :=
char_p.subring R p S
end char_p
|
faf289f8f1319b85408746dbc2fabfcf100cd36d
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/mkProjStx.lean
|
f131073c3aa197e54d435075f9d8558e0b5ef0a4
|
[
"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
| 482
|
lean
|
import Lean
structure A where
x : Nat := 0
structure B extends A where
y : Nat := 0
structure C extends B where
z : Nat := 0
def c : C := {}
open Lean
open Lean.Elab
def tst (varName structName fieldName : Name) : TermElabM Unit := do
let c := mkIdent varName
let some p ← Lean.Elab.Term.StructInst.mkProjStx? c structName fieldName | throwError "failed"
let p ← Term.elabTerm p none
logInfo s!"{p}"
#eval tst `c `C `x
#eval tst `c `C `y
#eval tst `c `C `z
|
4101fdf52d85c1725350440d4d7ded7575e2a5e9
|
b392eb79fb36952401156496daa60628ccb07438
|
/MathPort/bid.lean
|
2737ec544780d43ee01a398eb06366909a5b67bb
|
[
"Apache-2.0"
] |
permissive
|
AurelienSaue/mathportsource
|
d9eabe74e3ab7774baa6a10a6dc8d4855ff92266
|
1a164e4fff7204c522c1f4ecc5024fd909be3b0b
|
refs/heads/master
| 1,685,214,377,305
| 1,623,621,223,000
| 1,623,621,223,000
| 364,191,042
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 272
|
lean
|
structure A where
a : Nat
b : Nat
#print A
structure B extends A where
x : Nat
#print B
structure C (a b : Prop) : Prop where
intro ::
(mp : a → b)
(mpr : b → a)
#print C
inductive loc
where
| wildcard : loc
| ns : List (Option Nat) → loc
|
00c73865a562fe4aa76bceb78b8e993e60fbcfc2
|
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
|
/02_Dependent_Type_Theory.org.28.lean
|
8ecd7fdd3f39f443d76cdcad7b760f264efbacaa
|
[] |
no_license
|
cjmazey/lean-tutorial
|
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
|
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
|
refs/heads/master
| 1,610,286,098,832
| 1,447,124,923,000
| 1,447,124,923,000
| 43,082,433
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 296
|
lean
|
/- page 25 -/
import standard
namespace foo
constant A : Type
constant a : A
constant f : A → A
definition fa : A := f a
namespace bar
definition ffa : A := f (f a)
check fa
check ffa
end bar
check fa
check bar.ffa
end foo
check foo.fa
check foo.bar.ffa
open foo
check fa
check bar.ffa
|
eb194cc357c7d2182bf17dcd55d42f3a44123d8c
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/analysis/analytic/radius_liminf_auto.lean
|
29257a36f567d37136a923979bebca3473fd15a6
|
[] |
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,301
|
lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.analysis.analytic.basic
import Mathlib.analysis.special_functions.pow
import Mathlib.PostPort
universes u_1 u_2 u_3
namespace Mathlib
/-!
# Representation of `formal_multilinear_series.radius` as a `liminf`
In this file we prove that the radius of convergence of a `formal_multilinear_series` is equal to
$\liminf_{n\to\infty} \frac{1}{\sqrt[n]{∥p n∥}}$. This lemma can't go to `basic.lean` because this
would create a circular dependency once we redefine `exp` using `formal_multilinear_series`.
-/
namespace formal_multilinear_series
/-- The radius of a formal multilinear series is equal to
$\liminf_{n\to\infty} \frac{1}{\sqrt[n]{∥p n∥}}$. The actual statement uses `ℝ≥0` and some
coercions. -/
theorem radius_eq_liminf {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [normed_group E]
[normed_space 𝕜 E] {F : Type u_3} [normed_group F] [normed_space 𝕜 F]
(p : formal_multilinear_series 𝕜 E F) :
radius p = filter.liminf filter.at_top fun (n : ℕ) => 1 / ↑(nnnorm (p n) ^ (1 / ↑n)) :=
sorry
end Mathlib
|
fb8bfcb802201f30f20dcf5b864e9e331ff6f808
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/extra/denote_rec.lean
|
0bdece8de4becf7d607576027d8651f62cb18cd2
|
[
"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
| 750
|
lean
|
inductive formula :=
eqf : nat → nat → formula,
andf : formula → formula → formula,
impf : formula → formula → formula,
allf : (nat → formula) → formula
check @formula.rec_on
namespace formula
definition denote : formula → Prop,
denote (eqf n1 n2) := n1 = n2,
denote (andf f1 f2) := denote f1 ∧ denote f2,
denote (impf f1 f2) := denote f1 → denote f2,
denote (allf f) := ∀ n : nat, denote (f n)
end formula
definition denote (f : formula) : Prop :=
formula.rec_on f
(λ n₁ n₂, n₁ = n₂)
(λ f₁ f₂ r₁ r₂, r₁ ∧ r₂)
(λ f₁ f₂ r₁ r₂, r₁ → r₂)
(λ f r, ∀ n : nat, r n)
open formula
eval denote (allf (λ n₁, allf (λ n₂, impf (eqf n₁ n₂) (eqf n₂ n₁))))
|
32ab666597584961279468ebfd492fd0c43e2961
|
46125763b4dbf50619e8846a1371029346f4c3db
|
/src/ring_theory/power_series.lean
|
a1f67371fac28fe67b0a3e79390137f68aa22439
|
[
"Apache-2.0"
] |
permissive
|
thjread/mathlib
|
a9d97612cedc2c3101060737233df15abcdb9eb1
|
7cffe2520a5518bba19227a107078d83fa725ddc
|
refs/heads/master
| 1,615,637,696,376
| 1,583,953,063,000
| 1,583,953,063,000
| 246,680,271
| 0
| 0
|
Apache-2.0
| 1,583,960,875,000
| 1,583,960,875,000
| null |
UTF-8
|
Lean
| false
| false
| 58,590
|
lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import data.finsupp order.complete_lattice algebra.ordered_group data.mv_polynomial
import algebra.order_functions
import ring_theory.ideal_operations
/-!
# Formal power series
This file defines (multivariate) formal power series
and develops the basic properties of these objects.
A formal power series is to a polynomial like an infinite sum is to a finite sum.
We provide the natural inclusion from polynomials to formal power series.
## Generalities
The file starts with setting up the (semi)ring structure on multivariate power series.
`trunc n φ` truncates a formal power series to the polynomial
that has the same coefficients as φ, for all m ≤ n, and 0 otherwise.
If the constant coefficient of a formal power series is invertible,
then this formal power series is invertible.
Formal power series over a local ring form a local ring.
## Formal power series in one variable
We prove that if the ring of coefficients is an integral domain,
then formal power series in one variable form an integral domain.
The `order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`.
If the coefficients form an integral domain, then `order` is a valuation
(`order_mul`, `order_add_ge`).
## Implementation notes
In this file we define multivariate formal power series with
variables indexed by `σ` and coefficients in `α` as
mv_power_series σ α := (σ →₀ ℕ) → α.
Unfortunately there is not yet enough API to show that they are the completion
of the ring of multivariate polynomials. However, we provide most of the infrastructure
that is needed to do this. Once I-adic completion (topological or algebraic) is available
it should not be hard to fill in the details.
Formal power series in one variable are defined as
power_series α := mv_power_series unit α.
This allows us to port a lot of proofs and properties
from the multivariate case to the single variable case.
However, it means that formal power series are indexed by (unit →₀ ℕ),
which is of course canonically isomorphic to ℕ.
We then build some glue to treat formal power series as if they are indexed by ℕ.
Occasionally this leads to proofs that are uglier than expected.
-/
noncomputable theory
open_locale classical
/-- Multivariate formal power series, where `σ` is the index set of the variables
and `α` is the coefficient ring.-/
def mv_power_series (σ : Type*) (α : Type*) := (σ →₀ ℕ) → α
namespace mv_power_series
open finsupp
variables {σ : Type*} {α : Type*}
instance [inhabited α] : inhabited (mv_power_series σ α) := ⟨λ _, default _⟩
instance [has_zero α] : has_zero (mv_power_series σ α) := pi.has_zero
instance [add_monoid α] : add_monoid (mv_power_series σ α) := pi.add_monoid
instance [add_group α] : add_group (mv_power_series σ α) := pi.add_group
instance [add_comm_monoid α] : add_comm_monoid (mv_power_series σ α) := pi.add_comm_monoid
instance [add_comm_group α] : add_comm_group (mv_power_series σ α) := pi.add_comm_group
section add_monoid
variables [add_monoid α]
variables (α)
/-- The `n`th monomial with coefficient `a` as multivariate formal power series.-/
def monomial (n : σ →₀ ℕ) : α →+ mv_power_series σ α :=
{ to_fun := λ a m, if m = n then a else 0,
map_zero' := funext $ λ m, by { split_ifs; refl },
map_add' := λ a b, funext $ λ m,
show (if m = n then a + b else 0) = (if m = n then a else 0) + (if m = n then b else 0),
from if h : m = n then by simp only [if_pos h] else by simp only [if_neg h, add_zero] }
/-- The `n`th coefficient of a multivariate formal power series.-/
def coeff (n : σ →₀ ℕ) : (mv_power_series σ α) →+ α :=
{ to_fun := λ φ, φ n,
map_zero' := rfl,
map_add' := λ _ _, rfl }
variables {α}
/-- Two multivariate formal power series are equal if all their coefficients are equal.-/
@[ext] lemma ext {φ ψ} (h : ∀ (n : σ →₀ ℕ), coeff α n φ = coeff α n ψ) :
φ = ψ :=
funext h
/-- Two multivariate formal power series are equal
if and only if all their coefficients are equal.-/
lemma ext_iff {φ ψ : mv_power_series σ α} :
φ = ψ ↔ (∀ (n : σ →₀ ℕ), coeff α n φ = coeff α n ψ) :=
⟨λ h n, congr_arg (coeff α n) h, ext⟩
lemma coeff_monomial (m n : σ →₀ ℕ) (a : α) :
coeff α m (monomial α n a) = if m = n then a else 0 := rfl
@[simp] lemma coeff_monomial' (n : σ →₀ ℕ) (a : α) :
coeff α n (monomial α n a) = a := if_pos rfl
@[simp] lemma coeff_comp_monomial (n : σ →₀ ℕ) :
(coeff α n).comp (monomial α n) = add_monoid_hom.id α :=
add_monoid_hom.ext $ coeff_monomial' n
@[simp] lemma coeff_zero (n : σ →₀ ℕ) : coeff α n (0 : mv_power_series σ α) = 0 := rfl
end add_monoid
section semiring
variables [semiring α] (n : σ →₀ ℕ) (φ ψ : mv_power_series σ α)
instance : has_one (mv_power_series σ α) := ⟨monomial α (0 : σ →₀ ℕ) 1⟩
lemma coeff_one :
coeff α n (1 : mv_power_series σ α) = if n = 0 then 1 else 0 := rfl
@[simp, priority 1100] lemma coeff_zero_one : coeff α (0 : σ →₀ ℕ) 1 = 1 :=
coeff_monomial' 0 1
instance : has_mul (mv_power_series σ α) :=
⟨λ φ ψ n, (finsupp.antidiagonal n).support.sum (λ p, φ p.1 * ψ p.2)⟩
lemma coeff_mul : coeff α n (φ * ψ) =
(finsupp.antidiagonal n).support.sum (λ p, coeff α p.1 φ * coeff α p.2 ψ) := rfl
protected lemma zero_mul : (0 : mv_power_series σ α) * φ = 0 :=
ext $ λ n, by simp [coeff_mul]
protected lemma mul_zero : φ * 0 = 0 :=
ext $ λ n, by simp [coeff_mul]
protected lemma one_mul : (1 : mv_power_series σ α) * φ = φ :=
ext $ λ n,
begin
rw [coeff_mul, finset.sum_eq_single ((0 : σ →₀ ℕ), n)];
simp [mem_antidiagonal_support, coeff_one],
show ∀ (i j : σ →₀ ℕ), i + j = n → (i = 0 → j ≠ n) →
(if i = 0 then coeff α j φ else 0) = 0,
intros i j hij h,
rw [if_neg],
contrapose! h,
simpa [h] using hij,
end
protected lemma mul_one : φ * 1 = φ :=
ext $ λ n,
begin
rw [coeff_mul, finset.sum_eq_single (n, (0 : σ →₀ ℕ))],
rotate,
{ rintros ⟨i, j⟩ hij h,
rw [coeff_one, if_neg, mul_zero],
rw mem_antidiagonal_support at hij,
contrapose! h,
simpa [h] using hij },
all_goals { simp [mem_antidiagonal_support, coeff_one] }
end
protected lemma mul_add (φ₁ φ₂ φ₃ : mv_power_series σ α) :
φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, mul_add, finset.sum_add_distrib, add_monoid_hom.map_add]
protected lemma add_mul (φ₁ φ₂ φ₃ : mv_power_series σ α) :
(φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, add_mul, finset.sum_add_distrib, add_monoid_hom.map_add]
protected lemma mul_assoc (φ₁ φ₂ φ₃ : mv_power_series σ α) :
(φ₁ * φ₂) * φ₃ = φ₁ * (φ₂ * φ₃) :=
ext $ λ n,
begin
simp only [coeff_mul],
have := @finset.sum_sigma ((σ →₀ ℕ) × (σ →₀ ℕ)) α _ _ (antidiagonal n).support
(λ p, (antidiagonal (p.1)).support) (λ x, coeff α x.2.1 φ₁ * coeff α x.2.2 φ₂ * coeff α x.1.2 φ₃),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl,
intros p hp, exact finset.sum_mul },
have := @finset.sum_sigma ((σ →₀ ℕ) × (σ →₀ ℕ)) α _ _ (antidiagonal n).support
(λ p, (antidiagonal (p.2)).support) (λ x, coeff α x.1.1 φ₁ * (coeff α x.2.1 φ₂ * coeff α x.2.2 φ₃)),
convert this.symm using 1; clear this,
{ apply finset.sum_congr rfl, intros p hp, rw finset.mul_sum },
apply finset.sum_bij,
swap 5,
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, exact ⟨(k, l+j), (l, j)⟩ },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H,
simp only [finset.mem_sigma, mem_antidiagonal_support] at H ⊢, finish },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, rw mul_assoc },
{ rintros ⟨⟨a,b⟩, ⟨c,d⟩⟩ ⟨⟨i,j⟩, ⟨k,l⟩⟩ H₁ H₂,
simp only [finset.mem_sigma, mem_antidiagonal_support,
and_imp, prod.mk.inj_iff, add_comm, heq_iff_eq] at H₁ H₂ ⊢,
finish },
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H, refine ⟨⟨(i+k, l), (i, k)⟩, _, _⟩;
{ simp only [finset.mem_sigma, mem_antidiagonal_support] at H ⊢, finish } }
end
instance : semiring (mv_power_series σ α) :=
{ mul_one := mv_power_series.mul_one,
one_mul := mv_power_series.one_mul,
mul_assoc := mv_power_series.mul_assoc,
mul_zero := mv_power_series.mul_zero,
zero_mul := mv_power_series.zero_mul,
left_distrib := mv_power_series.mul_add,
right_distrib := mv_power_series.add_mul,
.. mv_power_series.has_one,
.. mv_power_series.has_mul,
.. mv_power_series.add_comm_monoid }
end semiring
instance [comm_semiring α] : comm_semiring (mv_power_series σ α) :=
{ mul_comm := λ φ ψ, ext $ λ n, finset.sum_bij (λ p hp, p.swap)
(λ p hp, swap_mem_antidiagonal_support hp)
(λ p hp, mul_comm _ _)
(λ p q hp hq H, by simpa using congr_arg prod.swap H)
(λ p hp, ⟨p.swap, swap_mem_antidiagonal_support hp, p.swap_swap.symm⟩),
.. mv_power_series.semiring }
instance [ring α] : ring (mv_power_series σ α) :=
{ .. mv_power_series.semiring,
.. mv_power_series.add_comm_group }
instance [comm_ring α] : comm_ring (mv_power_series σ α) :=
{ .. mv_power_series.comm_semiring,
.. mv_power_series.add_comm_group }
section semiring
variables [semiring α]
lemma monomial_mul_monomial (m n : σ →₀ ℕ) (a b : α) :
monomial α m a * monomial α n b = monomial α (m + n) (a * b) :=
begin
ext k, rw [coeff_mul, coeff_monomial], split_ifs with h,
{ rw [h, finset.sum_eq_single (m,n)],
{ rw [coeff_monomial', coeff_monomial'] },
{ rintros ⟨i,j⟩ hij hne,
rw [ne.def, prod.mk.inj_iff, not_and] at hne,
by_cases H : i = m,
{ rw [coeff_monomial j n b, if_neg (hne H), mul_zero] },
{ rw [coeff_monomial, if_neg H, zero_mul] } },
{ intro H, rw finsupp.mem_antidiagonal_support at H,
exfalso, exact H rfl } },
{ rw [finset.sum_eq_zero], rintros ⟨i,j⟩ hij,
rw finsupp.mem_antidiagonal_support at hij,
by_cases H : i = m,
{ subst i, have : j ≠ n, { rintro rfl, exact h hij.symm },
{ rw [coeff_monomial j n b, if_neg this, mul_zero] } },
{ rw [coeff_monomial, if_neg H, zero_mul] } }
end
variables (σ) (α)
/-- The constant multivariate formal power series.-/
def C : α →+* mv_power_series σ α :=
{ map_one' := rfl,
map_mul' := λ a b, (monomial_mul_monomial 0 0 a b).symm,
.. monomial α (0 : σ →₀ ℕ) }
variables {σ} {α}
@[simp] lemma monomial_zero_eq_C : monomial α (0 : σ →₀ ℕ) = C σ α := rfl
@[simp] lemma monomial_zero_eq_C_apply (a : α) : monomial α (0 : σ →₀ ℕ) a = C σ α a := rfl
lemma coeff_C (n : σ →₀ ℕ) (a : α) :
coeff α n (C σ α a) = if n = 0 then a else 0 := rfl
@[simp, priority 1100]
lemma coeff_zero_C (a : α) : coeff α (0 : σ →₀ℕ) (C σ α a) = a :=
coeff_monomial' 0 a
/-- The variables of the multivariate formal power series ring.-/
def X (s : σ) : mv_power_series σ α := monomial α (single s 1) 1
lemma coeff_X (n : σ →₀ ℕ) (s : σ) :
coeff α n (X s : mv_power_series σ α) = if n = (single s 1) then 1 else 0 := rfl
lemma coeff_index_single_X (s t : σ) :
coeff α (single t 1) (X s : mv_power_series σ α) = if t = s then 1 else 0 :=
by { simp only [coeff_X, single_right_inj one_ne_zero], split_ifs; refl }
@[simp] lemma coeff_index_single_self_X (s : σ) :
coeff α (single s 1) (X s : mv_power_series σ α) = 1 :=
if_pos rfl
@[simp, priority 1100]
lemma coeff_zero_X (s : σ) : coeff α (0 : σ →₀ ℕ) (X s : mv_power_series σ α) = 0 :=
by { rw [coeff_X, if_neg], intro h, exact one_ne_zero (single_eq_zero.mp h.symm) }
lemma X_def (s : σ) : X s = monomial α (single s 1) 1 := rfl
lemma X_pow_eq (s : σ) (n : ℕ) :
(X s : mv_power_series σ α)^n = monomial α (single s n) 1 :=
begin
induction n with n ih,
{ rw [pow_zero, finsupp.single_zero], refl },
{ rw [pow_succ', ih, nat.succ_eq_add_one, finsupp.single_add, X, monomial_mul_monomial, one_mul] }
end
lemma coeff_X_pow (m : σ →₀ ℕ) (s : σ) (n : ℕ) :
coeff α m ((X s : mv_power_series σ α)^n) = if m = single s n then 1 else 0 :=
by rw [X_pow_eq s n, coeff_monomial]
@[simp] lemma coeff_mul_C (n : σ →₀ ℕ) (φ : mv_power_series σ α) (a : α) :
coeff α n (φ * (C σ α a)) = (coeff α n φ) * a :=
begin
rw [coeff_mul n φ], rw [finset.sum_eq_single (n,(0 : σ →₀ ℕ))],
{ rw [coeff_C, if_pos rfl] },
{ rintro ⟨i,j⟩ hij hne,
rw finsupp.mem_antidiagonal_support at hij,
by_cases hj : j = 0,
{ subst hj, simp at *, contradiction },
{ rw [coeff_C, if_neg hj, mul_zero] } },
{ intro h, exfalso, apply h,
rw finsupp.mem_antidiagonal_support,
apply add_zero }
end
lemma coeff_zero_mul_X (φ : mv_power_series σ α) (s : σ) :
coeff α (0 : σ →₀ ℕ) (φ * X s) = 0 :=
begin
rw [coeff_mul _ φ, finset.sum_eq_zero],
rintro ⟨i,j⟩ hij,
obtain ⟨rfl, rfl⟩ : i = 0 ∧ j = 0,
{ rw finsupp.mem_antidiagonal_support at hij,
simpa using hij },
simp,
end
variables (σ) (α)
/-- The constant coefficient of a formal power series.-/
def constant_coeff : (mv_power_series σ α) →+* α :=
{ to_fun := coeff α (0 : σ →₀ ℕ),
map_one' := coeff_zero_one,
map_mul' := λ φ ψ, by simp [coeff_mul, support_single_ne_zero],
.. coeff α (0 : σ →₀ ℕ) }
variables {σ} {α}
@[simp] lemma coeff_zero_eq_constant_coeff :
coeff α (0 : σ →₀ ℕ) = constant_coeff σ α := rfl
@[simp] lemma coeff_zero_eq_constant_coeff_apply (φ : mv_power_series σ α) :
coeff α (0 : σ →₀ ℕ) φ = constant_coeff σ α φ := rfl
@[simp] lemma constant_coeff_C (a : α) : constant_coeff σ α (C σ α a) = a := rfl
@[simp] lemma constant_coeff_comp_C :
(constant_coeff σ α).comp (C σ α) = ring_hom.id α := rfl
@[simp] lemma constant_coeff_zero : constant_coeff σ α 0 = 0 := rfl
@[simp] lemma constant_coeff_one : constant_coeff σ α 1 = 1 := rfl
@[simp] lemma constant_coeff_X (s : σ) : constant_coeff σ α (X s) = 0 := coeff_zero_X s
/-- If a multivariate formal power series is invertible,
then so is its constant coefficient.-/
lemma is_unit_constant_coeff (φ : mv_power_series σ α) (h : is_unit φ) :
is_unit (constant_coeff σ α φ) :=
h.map' (constant_coeff σ α)
instance : semimodule α (mv_power_series σ α) :=
{ smul := λ a φ, C σ α a * φ,
one_smul := λ φ, one_mul _,
mul_smul := λ a b φ, by simp [ring_hom.map_mul, mul_assoc],
smul_add := λ a φ ψ, mul_add _ _ _,
smul_zero := λ a, mul_zero _,
add_smul := λ a b φ, by simp only [ring_hom.map_add, add_mul],
zero_smul := λ φ, by simp only [zero_mul, ring_hom.map_zero] }
end semiring
instance [ring α] : module α (mv_power_series σ α) :=
{ ..mv_power_series.semimodule }
instance [comm_ring α] : algebra α (mv_power_series σ α) :=
{ to_fun := C σ α,
commutes' := λ _ _, mul_comm _ _,
smul_def' := λ c p, rfl,
.. mv_power_series.module }
section map
variables {β : Type*} {γ : Type*} [semiring α] [semiring β] [semiring γ]
variables (f : α →+* β) (g : β →+* γ)
variable (σ)
/-- The map between multivariate formal power series induced by a map on the coefficients.-/
def map : mv_power_series σ α →+* mv_power_series σ β :=
{ to_fun := λ φ n, f $ coeff α n φ,
map_zero' := ext $ λ n, f.map_zero,
map_one' := ext $ λ n, show f ((coeff α n) 1) = (coeff β n) 1,
by { rw [coeff_one, coeff_one], split_ifs; simp [f.map_one, f.map_zero] },
map_add' := λ φ ψ, ext $ λ n,
show f ((coeff α n) (φ + ψ)) = f ((coeff α n) φ) + f ((coeff α n) ψ), by simp,
map_mul' := λ φ ψ, ext $ λ n, show f _ = _,
begin
rw [coeff_mul, ← finset.sum_hom _ f, coeff_mul, finset.sum_congr rfl],
rintros ⟨i,j⟩ hij, rw [f.map_mul], refl,
end }
variable {σ}
@[simp] lemma map_id : map σ (ring_hom.id α) = ring_hom.id _ := rfl
lemma map_comp : map σ (g.comp f) = (map σ g).comp (map σ f) := rfl
@[simp] lemma coeff_map (n : σ →₀ ℕ) (φ : mv_power_series σ α) :
coeff β n (map σ f φ) = f (coeff α n φ) := rfl
@[simp] lemma constant_coeff_map (φ : mv_power_series σ α) :
constant_coeff σ β (map σ f φ) = f (constant_coeff σ α φ) := rfl
end map
section trunc
variables [comm_semiring α] (n : σ →₀ ℕ)
-- Auxiliary definition for the truncation function.
def trunc_fun (φ : mv_power_series σ α) : mv_polynomial σ α :=
{ support := (n.antidiagonal.support.image prod.fst).filter (λ m, coeff α m φ ≠ 0),
to_fun := λ m, if m ≤ n then coeff α m φ else 0,
mem_support_to_fun := λ m,
begin
suffices : m ∈ finset.image prod.fst ((antidiagonal n).support) ↔ m ≤ n,
{ rw [finset.mem_filter, this], split,
{ intro h, rw [if_pos h.1], exact h.2 },
{ intro h, split_ifs at h with H H,
{ exact ⟨H, h⟩ },
{ exfalso, exact h rfl } } },
rw finset.mem_image, split,
{ rintros ⟨⟨i,j⟩, h, rfl⟩ s,
rw finsupp.mem_antidiagonal_support at h,
rw ← h, exact nat.le_add_right _ _ },
{ intro h, refine ⟨(m, n-m), _, rfl⟩,
rw finsupp.mem_antidiagonal_support, ext s, exact nat.add_sub_of_le (h s) }
end }
variable (α)
/-- The `n`th truncation of a multivariate formal power series to a multivariate polynomial -/
def trunc : mv_power_series σ α →+ mv_polynomial σ α :=
{ to_fun := trunc_fun n,
map_zero' := mv_polynomial.ext _ _ $ λ m, by { change ite _ _ _ = _, split_ifs; refl },
map_add' := λ φ ψ, mv_polynomial.ext _ _ $ λ m,
begin
rw mv_polynomial.coeff_add,
change ite _ _ _ = ite _ _ _ + ite _ _ _,
split_ifs with H, {refl}, {rw [zero_add]}
end }
variable {α}
lemma coeff_trunc (m : σ →₀ ℕ) (φ : mv_power_series σ α) :
mv_polynomial.coeff m (trunc α n φ) =
if m ≤ n then coeff α m φ else 0 := rfl
@[simp] lemma trunc_one : trunc α n 1 = 1 :=
mv_polynomial.ext _ _ $ λ m,
begin
rw [coeff_trunc, coeff_one],
split_ifs with H H' H',
{ subst m, erw mv_polynomial.coeff_C 0, simp },
{ symmetry, erw mv_polynomial.coeff_monomial, convert if_neg (ne.elim (ne.symm H')), },
{ symmetry, erw mv_polynomial.coeff_monomial, convert if_neg _,
intro H', apply H, subst m, intro s, exact nat.zero_le _ }
end
@[simp] lemma trunc_C (a : α) : trunc α n (C σ α a) = mv_polynomial.C a :=
mv_polynomial.ext _ _ $ λ m,
begin
rw [coeff_trunc, coeff_C, mv_polynomial.coeff_C],
split_ifs with H; refl <|> try {simp * at *},
exfalso, apply H, subst m, intro s, exact nat.zero_le _
end
end trunc
section comm_semiring
variable [comm_semiring α]
lemma X_pow_dvd_iff {s : σ} {n : ℕ} {φ : mv_power_series σ α} :
(X s : mv_power_series σ α)^n ∣ φ ↔ ∀ m : σ →₀ ℕ, m s < n → coeff α m φ = 0 :=
begin
split,
{ rintros ⟨φ, rfl⟩ m h,
rw [coeff_mul, finset.sum_eq_zero],
rintros ⟨i,j⟩ hij, rw [coeff_X_pow, if_neg, zero_mul],
contrapose! h, subst i, rw finsupp.mem_antidiagonal_support at hij,
rw [← hij, finsupp.add_apply, finsupp.single_eq_same], exact nat.le_add_right n _ },
{ intro h, refine ⟨λ m, coeff α (m + (single s n)) φ, _⟩,
ext m, by_cases H : m - single s n + single s n = m,
{ rw [coeff_mul, finset.sum_eq_single (single s n, m - single s n)],
{ rw [coeff_X_pow, if_pos rfl, one_mul],
simpa using congr_arg (λ (m : σ →₀ ℕ), coeff α m φ) H.symm },
{ rintros ⟨i,j⟩ hij hne, rw finsupp.mem_antidiagonal_support at hij,
rw coeff_X_pow, split_ifs with hi,
{ exfalso, apply hne, rw [← hij, ← hi, prod.mk.inj_iff], refine ⟨rfl, _⟩,
ext t, simp only [nat.add_sub_cancel_left, finsupp.add_apply, finsupp.nat_sub_apply] },
{ exact zero_mul _ } },
{ intro hni, exfalso, apply hni, rwa [finsupp.mem_antidiagonal_support, add_comm] } },
{ rw [h, coeff_mul, finset.sum_eq_zero],
{ rintros ⟨i,j⟩ hij, rw finsupp.mem_antidiagonal_support at hij,
rw coeff_X_pow, split_ifs with hi,
{ exfalso, apply H, rw [← hij, hi], ext t,
simp only [nat.add_sub_cancel_left, add_comm,
finsupp.add_apply, add_right_inj, finsupp.nat_sub_apply] },
{ exact zero_mul _ } },
{ classical, contrapose! H, ext t,
by_cases hst : s = t,
{ subst t, simpa using nat.sub_add_cancel H },
{ simp [finsupp.single_apply, hst] } } } }
end
lemma X_dvd_iff {s : σ} {φ : mv_power_series σ α} :
(X s : mv_power_series σ α) ∣ φ ↔ ∀ m : σ →₀ ℕ, m s = 0 → coeff α m φ = 0 :=
begin
rw [← pow_one (X s : mv_power_series σ α), X_pow_dvd_iff],
split; intros h m hm,
{ exact h m (hm.symm ▸ zero_lt_one) },
{ exact h m (nat.eq_zero_of_le_zero $ nat.le_of_succ_le_succ hm) }
end
end comm_semiring
section ring
variables [ring α]
/-
The inverse of a multivariate formal power series is defined by
well-founded recursion on the coeffients of the inverse.
-/
/-- Auxiliary definition that unifies
the totalised inverse formal power series `(_)⁻¹` and
the inverse formal power series that depends on
an inverse of the constant coefficient `inv_of_unit`.-/
protected noncomputable def inv.aux (a : α) (φ : mv_power_series σ α) : mv_power_series σ α
| n := if n = 0 then a else
- a * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if h : x.2 < n then coeff α x.1 φ * inv.aux x.2 else 0)
using_well_founded
{ rel_tac := λ _ _, `[exact ⟨_, finsupp.lt_wf σ⟩],
dec_tac := tactic.assumption }
lemma coeff_inv_aux (n : σ →₀ ℕ) (a : α) (φ : mv_power_series σ α) :
coeff α n (inv.aux a φ) = if n = 0 then a else
- a * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv.aux a φ) else 0) :=
show inv.aux a φ n = _, by { rw inv.aux, refl }
/-- A multivariate formal power series is invertible if the constant coefficient is invertible.-/
def inv_of_unit (φ : mv_power_series σ α) (u : units α) : mv_power_series σ α :=
inv.aux (↑u⁻¹) φ
lemma coeff_inv_of_unit (n : σ →₀ ℕ) (φ : mv_power_series σ α) (u : units α) :
coeff α n (inv_of_unit φ u) = if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv_of_unit φ u) else 0) :=
coeff_inv_aux n (↑u⁻¹) φ
@[simp] lemma constant_coeff_inv_of_unit (φ : mv_power_series σ α) (u : units α) :
constant_coeff σ α (inv_of_unit φ u) = ↑u⁻¹ :=
by rw [← coeff_zero_eq_constant_coeff_apply, coeff_inv_of_unit, if_pos rfl]
lemma mul_inv_of_unit (φ : mv_power_series σ α) (u : units α) (h : constant_coeff σ α φ = u) :
φ * inv_of_unit φ u = 1 :=
ext $ λ n, if H : n = 0 then by { rw H, simp [coeff_mul, support_single_ne_zero, h], }
else
begin
have : ((0 : σ →₀ ℕ), n) ∈ n.antidiagonal.support,
{ rw [finsupp.mem_antidiagonal_support, zero_add] },
rw [coeff_one, if_neg H, coeff_mul,
← finset.insert_erase this, finset.sum_insert (finset.not_mem_erase _ _),
coeff_zero_eq_constant_coeff_apply, h, coeff_inv_of_unit, if_neg H,
neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm, units.mul_inv_cancel_left,
← finset.insert_erase this, finset.sum_insert (finset.not_mem_erase _ _),
finset.insert_erase this, if_neg (not_lt_of_ge $ le_refl _), zero_add, add_comm,
← sub_eq_add_neg, sub_eq_zero, finset.sum_congr rfl],
rintros ⟨i,j⟩ hij, rw [finset.mem_erase, finsupp.mem_antidiagonal_support] at hij,
cases hij with h₁ h₂,
subst n, rw if_pos,
suffices : (0 : _) + j < i + j, {simpa},
apply add_lt_add_right,
split,
{ intro s, exact nat.zero_le _ },
{ intro H, apply h₁,
suffices : i = 0, {simp [this]},
ext1 s, exact nat.eq_zero_of_le_zero (H s) }
end
end ring
section comm_ring
variable [comm_ring α]
/-- Multivariate formal power series over a local ring form a local ring.-/
lemma is_local_ring (h : is_local_ring α) : is_local_ring (mv_power_series σ α) :=
begin
split,
{ have H : (0:α) ≠ 1 := ‹is_local_ring α›.1, contrapose! H,
simpa using congr_arg (constant_coeff σ α) H },
{ intro φ, rcases ‹is_local_ring α›.2 (constant_coeff σ α φ) with ⟨u,h⟩|⟨u,h⟩; [left, right];
{ refine is_unit_of_mul_one _ _ (mul_inv_of_unit _ u _),
simpa using h } }
end
-- TODO(jmc): once adic topology lands, show that this is complete
end comm_ring
section nonzero_comm_ring
variables [nonzero_comm_ring α]
instance : nonzero_comm_ring (mv_power_series σ α) :=
{ zero_ne_one := assume h, zero_ne_one $ show (0:α) = 1, from congr_arg (constant_coeff σ α) h,
.. mv_power_series.comm_ring }
lemma X_inj {s t : σ} : (X s : mv_power_series σ α) = X t ↔ s = t :=
⟨begin
intro h, replace h := congr_arg (coeff α (single s 1)) h, rw [coeff_X, if_pos rfl, coeff_X] at h,
split_ifs at h with H,
{ rw finsupp.single_eq_single_iff at H,
cases H, { exact H.1 }, { exfalso, exact one_ne_zero H.1 } },
{ exfalso, exact one_ne_zero h }
end, congr_arg X⟩
end nonzero_comm_ring
section local_ring
variables {β : Type*} [local_ring α] [local_ring β] (f : α →+* β) [is_local_ring_hom f]
instance : local_ring (mv_power_series σ α) :=
local_of_is_local_ring $ is_local_ring ⟨zero_ne_one, local_ring.is_local⟩
instance map.is_local_ring_hom :
is_local_ring_hom (map σ f : mv_power_series σ α → mv_power_series σ β) :=
{ map_one := (map σ f).map_one,
map_mul := (map σ f).map_mul,
map_add := (map σ f).map_add,
map_nonunit :=
begin
rintros φ ⟨ψ, h⟩,
replace h := congr_arg (constant_coeff σ β) h,
rw constant_coeff_map at h,
have : is_unit (constant_coeff σ β ↑ψ) := @is_unit_constant_coeff σ β _ (↑ψ) (is_unit_unit ψ),
rw ← h at this,
rcases is_unit_of_map_unit f _ this with ⟨c, hc⟩,
exact is_unit_of_mul_one φ (inv_of_unit φ c) (mul_inv_of_unit φ c hc)
end }
end local_ring
section field
variables [field α]
protected def inv (φ : mv_power_series σ α) : mv_power_series σ α :=
inv.aux (constant_coeff σ α φ)⁻¹ φ
instance : has_inv (mv_power_series σ α) := ⟨mv_power_series.inv⟩
lemma coeff_inv (n : σ →₀ ℕ) (φ : mv_power_series σ α) :
coeff α n (φ⁻¹) = if n = 0 then (constant_coeff σ α φ)⁻¹ else
- (constant_coeff σ α φ)⁻¹ * n.antidiagonal.support.sum (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (φ⁻¹) else 0) :=
coeff_inv_aux n _ φ
@[simp] lemma constant_coeff_inv (φ : mv_power_series σ α) :
constant_coeff σ α (φ⁻¹) = (constant_coeff σ α φ)⁻¹ :=
by rw [← coeff_zero_eq_constant_coeff_apply, coeff_inv, if_pos rfl]
lemma inv_eq_zero {φ : mv_power_series σ α} :
φ⁻¹ = 0 ↔ constant_coeff σ α φ = 0 :=
⟨λ h, by simpa using congr_arg (constant_coeff σ α) h,
λ h, ext $ λ n, by { rw coeff_inv, split_ifs;
simp only [h, mv_power_series.coeff_zero, zero_mul, inv_zero, neg_zero] }⟩
@[simp, priority 1100] lemma inv_of_unit_eq (φ : mv_power_series σ α) (h : constant_coeff σ α φ ≠ 0) :
inv_of_unit φ (units.mk0 _ h) = φ⁻¹ := rfl
@[simp] lemma inv_of_unit_eq' (φ : mv_power_series σ α) (u : units α) (h : constant_coeff σ α φ = u) :
inv_of_unit φ u = φ⁻¹ :=
begin
rw ← inv_of_unit_eq φ (h.symm ▸ u.ne_zero),
congr' 1, rw [units.ext_iff], exact h.symm,
end
@[simp] protected lemma mul_inv (φ : mv_power_series σ α) (h : constant_coeff σ α φ ≠ 0) :
φ * φ⁻¹ = 1 :=
by rw [← inv_of_unit_eq φ h, mul_inv_of_unit φ (units.mk0 _ h) rfl]
@[simp] protected lemma inv_mul (φ : mv_power_series σ α) (h : constant_coeff σ α φ ≠ 0) :
φ⁻¹ * φ = 1 :=
by rw [mul_comm, φ.mul_inv h]
end field
end mv_power_series
namespace mv_polynomial
open finsupp
variables {σ : Type*} {α : Type*} [comm_semiring α]
/-- The natural inclusion from multivariate polynomials into multivariate formal power series.-/
instance coe_to_mv_power_series : has_coe (mv_polynomial σ α) (mv_power_series σ α) :=
⟨λ φ n, coeff n φ⟩
@[simp, elim_cast] lemma coeff_coe (φ : mv_polynomial σ α) (n : σ →₀ ℕ) :
mv_power_series.coeff α n ↑φ = coeff n φ := rfl
@[simp, elim_cast] lemma coe_monomial (n : σ →₀ ℕ) (a : α) :
(monomial n a : mv_power_series σ α) = mv_power_series.monomial α n a :=
mv_power_series.ext $ λ m,
begin
rw [coeff_coe, coeff_monomial, mv_power_series.coeff_monomial],
split_ifs with h₁ h₂; refl <|> subst m; contradiction
end
@[simp, elim_cast] lemma coe_zero : ((0 : mv_polynomial σ α) : mv_power_series σ α) = 0 := rfl
@[simp, elim_cast] lemma coe_one : ((1 : mv_polynomial σ α) : mv_power_series σ α) = 1 :=
coe_monomial _ _
@[simp, elim_cast] lemma coe_add (φ ψ : mv_polynomial σ α) :
((φ + ψ : mv_polynomial σ α) : mv_power_series σ α) = φ + ψ := rfl
@[simp, elim_cast] lemma coe_mul (φ ψ : mv_polynomial σ α) :
((φ * ψ : mv_polynomial σ α) : mv_power_series σ α) = φ * ψ :=
mv_power_series.ext $ λ n,
by simp only [coeff_coe, mv_power_series.coeff_mul, coeff_mul]
@[simp, elim_cast] lemma coe_C (a : α) :
((C a : mv_polynomial σ α) : mv_power_series σ α) = mv_power_series.C σ α a :=
coe_monomial _ _
@[simp, elim_cast] lemma coe_X (s : σ) :
((X s : mv_polynomial σ α) : mv_power_series σ α) = mv_power_series.X s :=
coe_monomial _ _
namespace coe_to_mv_power_series
instance : is_semiring_hom (coe : mv_polynomial σ α → mv_power_series σ α) :=
{ map_zero := coe_zero,
map_one := coe_one,
map_add := coe_add,
map_mul := coe_mul }
end coe_to_mv_power_series
end mv_polynomial
/-- Formal power series over the coefficient ring `α`.-/
def power_series (α : Type*) := mv_power_series unit α
namespace power_series
open finsupp (single)
variable {α : Type*}
instance [inhabited α] : inhabited (power_series α) := by delta power_series; apply_instance
instance [add_monoid α] : add_monoid (power_series α) := by delta power_series; apply_instance
instance [add_group α] : add_group (power_series α) := by delta power_series; apply_instance
instance [add_comm_monoid α] : add_comm_monoid (power_series α) := by delta power_series; apply_instance
instance [add_comm_group α] : add_comm_group (power_series α) := by delta power_series; apply_instance
instance [semiring α] : semiring (power_series α) := by delta power_series; apply_instance
instance [comm_semiring α] : comm_semiring (power_series α) := by delta power_series; apply_instance
instance [ring α] : ring (power_series α) := by delta power_series; apply_instance
instance [comm_ring α] : comm_ring (power_series α) := by delta power_series; apply_instance
instance [nonzero_comm_ring α] : nonzero_comm_ring (power_series α) := by delta power_series; apply_instance
instance [semiring α] : semimodule α (power_series α) := by delta power_series; apply_instance
instance [ring α] : module α (power_series α) := by delta power_series; apply_instance
instance [comm_ring α] : algebra α (power_series α) := by delta power_series; apply_instance
section add_monoid
variables (α) [add_monoid α]
/-- The `n`th coefficient of a formal power series.-/
def coeff (n : ℕ) : power_series α →+ α := mv_power_series.coeff α (single () n)
/-- The `n`th monomial with coefficient `a` as formal power series.-/
def monomial (n : ℕ) : α →+ power_series α := mv_power_series.monomial α (single () n)
variables {α}
lemma coeff_def {s : unit →₀ ℕ} {n : ℕ} (h : s () = n) :
coeff α n = mv_power_series.coeff α s :=
by erw [coeff, ← h, ← finsupp.unique_single s]
/-- Two formal power series are equal if all their coefficients are equal.-/
@[ext] lemma ext {φ ψ : power_series α} (h : ∀ n, coeff α n φ = coeff α n ψ) :
φ = ψ :=
mv_power_series.ext $ λ n,
by { rw ← coeff_def, { apply h }, refl }
/-- Two formal power series are equal if all their coefficients are equal.-/
lemma ext_iff {φ ψ : power_series α} : φ = ψ ↔ (∀ n, coeff α n φ = coeff α n ψ) :=
⟨λ h n, congr_arg (coeff α n) h, ext⟩
/-- Constructor for formal power series.-/
def mk (f : ℕ → α) : power_series α := λ s, f (s ())
@[simp] lemma coeff_mk (n : ℕ) (f : ℕ → α) : coeff α n (mk f) = f n :=
congr_arg f finsupp.single_eq_same
lemma coeff_monomial (m n : ℕ) (a : α) :
coeff α m (monomial α n a) = if m = n then a else 0 :=
calc coeff α m (monomial α n a) = _ : mv_power_series.coeff_monomial _ _ _
... = if m = n then a else 0 :
by { simp only [finsupp.unique_single_eq_iff], split_ifs; refl }
lemma monomial_eq_mk (n : ℕ) (a : α) :
monomial α n a = mk (λ m, if m = n then a else 0) :=
ext $ λ m, by { rw [coeff_monomial, coeff_mk] }
@[simp] lemma coeff_monomial' (n : ℕ) (a : α) :
coeff α n (monomial α n a) = a :=
by convert if_pos rfl
@[simp] lemma coeff_comp_monomial (n : ℕ) :
(coeff α n).comp (monomial α n) = add_monoid_hom.id α :=
add_monoid_hom.ext $ coeff_monomial' n
end add_monoid
section semiring
variable [semiring α]
variable (α)
/--The constant coefficient of a formal power series. -/
def constant_coeff : power_series α →+* α := mv_power_series.constant_coeff unit α
/-- The constant formal power series.-/
def C : α →+* power_series α := mv_power_series.C unit α
variable {α}
/-- The variable of the formal power series ring.-/
def X : power_series α := mv_power_series.X ()
@[simp] lemma coeff_zero_eq_constant_coeff :
coeff α 0 = constant_coeff α :=
begin
rw [constant_coeff, ← mv_power_series.coeff_zero_eq_constant_coeff, coeff_def], refl
end
@[simp] lemma coeff_zero_eq_constant_coeff_apply (φ : power_series α) :
coeff α 0 φ = constant_coeff α φ :=
by rw [coeff_zero_eq_constant_coeff]; refl
@[simp] lemma monomial_zero_eq_C : monomial α 0 = C α :=
by rw [monomial, finsupp.single_zero, mv_power_series.monomial_zero_eq_C, C]
@[simp] lemma monomial_zero_eq_C_apply (a : α) : monomial α 0 a = C α a :=
by rw [monomial_zero_eq_C]; refl
lemma coeff_C (n : ℕ) (a : α) :
coeff α n (C α a : power_series α) = if n = 0 then a else 0 :=
by rw [← monomial_zero_eq_C_apply, coeff_monomial]
@[simp] lemma coeff_zero_C (a : α) : coeff α 0 (C α a) = a :=
by rw [← monomial_zero_eq_C_apply, coeff_monomial' 0 a]
lemma X_eq : (X : power_series α) = monomial α 1 1 := rfl
lemma coeff_X (n : ℕ) :
coeff α n (X : power_series α) = if n = 1 then 1 else 0 :=
by rw [X_eq, coeff_monomial]
@[simp] lemma coeff_zero_X : coeff α 0 (X : power_series α) = 0 :=
by rw [coeff, finsupp.single_zero, X, mv_power_series.coeff_zero_X]
@[simp] lemma coeff_one_X : coeff α 1 (X : power_series α) = 1 :=
by rw [coeff_X, if_pos rfl]
lemma X_pow_eq (n : ℕ) : (X : power_series α)^n = monomial α n 1 :=
mv_power_series.X_pow_eq _ n
lemma coeff_X_pow (m n : ℕ) :
coeff α m ((X : power_series α)^n) = if m = n then 1 else 0 :=
by rw [X_pow_eq, coeff_monomial]
@[simp] lemma coeff_X_pow_self (n : ℕ) :
coeff α n ((X : power_series α)^n) = 1 :=
by rw [coeff_X_pow, if_pos rfl]
@[simp] lemma coeff_one (n : ℕ) :
coeff α n (1 : power_series α) = if n = 0 then 1 else 0 :=
calc coeff α n (1 : power_series α) = _ : mv_power_series.coeff_one _
... = if n = 0 then 1 else 0 :
by { simp only [finsupp.single_eq_zero], split_ifs; refl }
@[simp] lemma coeff_zero_one : coeff α 0 (1 : power_series α) = 1 :=
coeff_zero_C 1
lemma coeff_mul (n : ℕ) (φ ψ : power_series α) :
coeff α n (φ * ψ) = (finset.nat.antidiagonal n).sum (λ p, coeff α p.1 φ * coeff α p.2 ψ) :=
begin
symmetry,
apply finset.sum_bij (λ (p : ℕ × ℕ) h, (single () p.1, single () p.2)),
{ rintros ⟨i,j⟩ hij, rw finset.nat.mem_antidiagonal at hij,
rw [finsupp.mem_antidiagonal_support, ← finsupp.single_add, hij], },
{ rintros ⟨i,j⟩ hij, refl },
{ rintros ⟨i,j⟩ ⟨k,l⟩ hij hkl,
simpa only [prod.mk.inj_iff, finsupp.unique_single_eq_iff] using id },
{ rintros ⟨f,g⟩ hfg,
refine ⟨(f (), g ()), _, _⟩,
{ rw finsupp.mem_antidiagonal_support at hfg,
rw [finset.nat.mem_antidiagonal, ← finsupp.add_apply, hfg, finsupp.single_eq_same] },
{ rw prod.mk.inj_iff, dsimp,
exact ⟨finsupp.unique_single f, finsupp.unique_single g⟩ } }
end
@[simp] lemma coeff_mul_C (n : ℕ) (φ : power_series α) (a : α) :
coeff α n (φ * (C α a)) = (coeff α n φ) * a :=
mv_power_series.coeff_mul_C _ φ a
@[simp] lemma coeff_succ_mul_X (n : ℕ) (φ : power_series α) :
coeff α (n+1) (φ * X) = coeff α n φ :=
begin
rw [coeff_mul _ φ, finset.sum_eq_single (n,1)],
{ rw [coeff_X, if_pos rfl, mul_one] },
{ rintro ⟨i,j⟩ hij hne,
by_cases hj : j = 1,
{ subst hj, simp at *, contradiction },
{ simp [coeff_X, hj] } },
{ intro h, exfalso, apply h, simp },
end
@[simp] lemma coeff_zero_mul_X (φ : power_series α) :
coeff α 0 (φ * X) = 0 :=
begin
rw [coeff_mul _ φ, finset.sum_eq_zero],
rintro ⟨i,j⟩ hij,
obtain ⟨rfl, rfl⟩ : i = 0 ∧ j = 0, { simpa using hij },
simp,
end
@[simp] lemma constant_coeff_C (a : α) : constant_coeff α (C α a) = a := rfl
@[simp] lemma constant_coeff_comp_C :
(constant_coeff α).comp (C α) = ring_hom.id α := rfl
@[simp] lemma constant_coeff_zero : constant_coeff α 0 = 0 := rfl
@[simp] lemma constant_coeff_one : constant_coeff α 1 = 1 := rfl
@[simp] lemma constant_coeff_X : constant_coeff α X = 0 := mv_power_series.coeff_zero_X _
/-- If a formal power series is invertible, then so is its constant coefficient.-/
lemma is_unit_constant_coeff (φ : power_series α) (h : is_unit φ) :
is_unit (constant_coeff α φ) :=
mv_power_series.is_unit_constant_coeff φ h
section map
variables {β : Type*} {γ : Type*} [semiring β] [semiring γ]
variables (f : α →+* β) (g : β →+* γ)
/-- The map between formal power series induced by a map on the coefficients.-/
def map : power_series α →+* power_series β :=
mv_power_series.map _ f
@[simp] lemma map_id : (map (ring_hom.id α) :
power_series α → power_series α) = id := rfl
lemma map_comp : map (g.comp f) = (map g).comp (map f) := rfl
@[simp] lemma coeff_map (n : ℕ) (φ : power_series α) :
coeff β n (map f φ) = f (coeff α n φ) := rfl
end map
end semiring
section comm_semiring
variables [comm_semiring α]
lemma X_pow_dvd_iff {n : ℕ} {φ : power_series α} :
(X : power_series α)^n ∣ φ ↔ ∀ m, m < n → coeff α m φ = 0 :=
begin
convert @mv_power_series.X_pow_dvd_iff unit α _ () n φ, apply propext,
classical, split; intros h m hm,
{ rw finsupp.unique_single m, convert h _ hm },
{ apply h, simpa only [finsupp.single_eq_same] using hm }
end
lemma X_dvd_iff {φ : power_series α} :
(X : power_series α) ∣ φ ↔ constant_coeff α φ = 0 :=
begin
rw [← pow_one (X : power_series α), X_pow_dvd_iff, ← coeff_zero_eq_constant_coeff_apply],
split; intro h,
{ exact h 0 zero_lt_one },
{ intros m hm, rwa nat.eq_zero_of_le_zero (nat.le_of_succ_le_succ hm) }
end
section trunc
/-- The `n`th truncation of a formal power series to a polynomial -/
def trunc (n : ℕ) (φ : power_series α) : polynomial α :=
{ support := ((finset.nat.antidiagonal n).image prod.fst).filter (λ m, coeff α m φ ≠ 0),
to_fun := λ m, if m ≤ n then coeff α m φ else 0,
mem_support_to_fun := λ m,
begin
suffices : m ∈ ((finset.nat.antidiagonal n).image prod.fst) ↔ m ≤ n,
{ rw [finset.mem_filter, this], split,
{ intro h, rw [if_pos h.1], exact h.2 },
{ intro h, split_ifs at h with H H,
{ exact ⟨H, h⟩ },
{ exfalso, exact h rfl } } },
rw finset.mem_image, split,
{ rintros ⟨⟨i,j⟩, h, rfl⟩,
rw finset.nat.mem_antidiagonal at h,
rw ← h, exact nat.le_add_right _ _ },
{ intro h, refine ⟨(m, n-m), _, rfl⟩,
rw finset.nat.mem_antidiagonal, exact nat.add_sub_of_le h }
end }
lemma coeff_trunc (m) (n) (φ : power_series α) :
polynomial.coeff (trunc n φ) m = if m ≤ n then coeff α m φ else 0 := rfl
@[simp] lemma trunc_zero (n) : trunc n (0 : power_series α) = 0 :=
polynomial.ext $ λ m,
begin
rw [coeff_trunc, add_monoid_hom.map_zero, polynomial.coeff_zero],
split_ifs; refl
end
@[simp] lemma trunc_one (n) : trunc n (1 : power_series α) = 1 :=
polynomial.ext $ λ m,
begin
rw [coeff_trunc, coeff_one],
split_ifs with H H' H'; rw [polynomial.coeff_one],
{ subst m, rw [if_pos rfl] },
{ symmetry, exact if_neg (ne.elim (ne.symm H')) },
{ symmetry, refine if_neg _,
intro H', apply H, subst m, exact nat.zero_le _ }
end
@[simp] lemma trunc_C (n) (a : α) : trunc n (C α a) = polynomial.C a :=
polynomial.ext $ λ m,
begin
rw [coeff_trunc, coeff_C, polynomial.coeff_C],
split_ifs with H; refl <|> try {simp * at *}
end
@[simp] lemma trunc_add (n) (φ ψ : power_series α) :
trunc n (φ + ψ) = trunc n φ + trunc n ψ :=
polynomial.ext $ λ m,
begin
simp only [coeff_trunc, add_monoid_hom.map_add, polynomial.coeff_add],
split_ifs with H, {refl}, {rw [zero_add]}
end
end trunc
end comm_semiring
section ring
variables [ring α]
protected def inv.aux : α → power_series α → power_series α :=
mv_power_series.inv.aux
lemma coeff_inv_aux (n : ℕ) (a : α) (φ : power_series α) :
coeff α n (inv.aux a φ) = if n = 0 then a else
- a * (finset.nat.antidiagonal n).sum (λ (x : ℕ × ℕ),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv.aux a φ) else 0) :=
begin
rw [coeff, inv.aux, mv_power_series.coeff_inv_aux],
simp only [finsupp.single_eq_zero],
split_ifs, {refl},
congr' 1,
symmetry,
apply finset.sum_bij (λ (p : ℕ × ℕ) h, (single () p.1, single () p.2)),
{ rintros ⟨i,j⟩ hij, rw finset.nat.mem_antidiagonal at hij,
rw [finsupp.mem_antidiagonal_support, ← finsupp.single_add, hij], },
{ rintros ⟨i,j⟩ hij,
by_cases H : j < n,
{ rw [if_pos H, if_pos], {refl},
split,
{ rintro ⟨⟩, simpa [finsupp.single_eq_same] using le_of_lt H },
{ intro hh, rw lt_iff_not_ge at H, apply H,
simpa [finsupp.single_eq_same] using hh () } },
{ rw [if_neg H, if_neg], rintro ⟨h₁, h₂⟩, apply h₂, rintro ⟨⟩,
simpa [finsupp.single_eq_same] using not_lt.1 H } },
{ rintros ⟨i,j⟩ ⟨k,l⟩ hij hkl,
simpa only [prod.mk.inj_iff, finsupp.unique_single_eq_iff] using id },
{ rintros ⟨f,g⟩ hfg,
refine ⟨(f (), g ()), _, _⟩,
{ rw finsupp.mem_antidiagonal_support at hfg,
rw [finset.nat.mem_antidiagonal, ← finsupp.add_apply, hfg, finsupp.single_eq_same] },
{ rw prod.mk.inj_iff, dsimp,
exact ⟨finsupp.unique_single f, finsupp.unique_single g⟩ } }
end
/-- A formal power series is invertible if the constant coefficient is invertible.-/
def inv_of_unit (φ : power_series α) (u : units α) : power_series α :=
mv_power_series.inv_of_unit φ u
lemma coeff_inv_of_unit (n : ℕ) (φ : power_series α) (u : units α) :
coeff α n (inv_of_unit φ u) = if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * (finset.nat.antidiagonal n).sum (λ (x : ℕ × ℕ),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (inv_of_unit φ u) else 0) :=
coeff_inv_aux n ↑u⁻¹ φ
@[simp] lemma constant_coeff_inv_of_unit (φ : power_series α) (u : units α) :
constant_coeff α (inv_of_unit φ u) = ↑u⁻¹ :=
by rw [← coeff_zero_eq_constant_coeff_apply, coeff_inv_of_unit, if_pos rfl]
lemma mul_inv_of_unit (φ : power_series α) (u : units α) (h : constant_coeff α φ = u) :
φ * inv_of_unit φ u = 1 :=
mv_power_series.mul_inv_of_unit φ u $ h
end ring
section integral_domain
variable [integral_domain α]
lemma eq_zero_or_eq_zero_of_mul_eq_zero (φ ψ : power_series α) (h : φ * ψ = 0) :
φ = 0 ∨ ψ = 0 :=
begin
rw classical.or_iff_not_imp_left, intro H,
have ex : ∃ m, coeff α m φ ≠ 0, { contrapose! H, exact ext H },
let P : ℕ → Prop := λ k, coeff α k φ ≠ 0,
let m := nat.find ex,
have hm₁ : coeff α m φ ≠ 0 := nat.find_spec ex,
have hm₂ : ∀ k < m, ¬coeff α k φ ≠ 0 := λ k, nat.find_min ex,
ext n, rw (coeff α n).map_zero, apply nat.strong_induction_on n,
clear n, intros n ih,
replace h := congr_arg (coeff α (m + n)) h,
rw [add_monoid_hom.map_zero, coeff_mul, finset.sum_eq_single (m,n)] at h,
{ replace h := eq_zero_or_eq_zero_of_mul_eq_zero h,
rw or_iff_not_imp_left at h, exact h hm₁ },
{ rintro ⟨i,j⟩ hij hne,
by_cases hj : j < n, { rw [ih j hj, mul_zero] },
by_cases hi : i < m,
{ specialize hm₂ _ hi, push_neg at hm₂, rw [hm₂, zero_mul] },
rw finset.nat.mem_antidiagonal at hij,
push_neg at hi hj,
suffices : m < i,
{ have : m + n < i + j := add_lt_add_of_lt_of_le this hj,
exfalso, exact ne_of_lt this hij.symm },
contrapose! hne, have : i = m := le_antisymm hne hi, subst i, clear hi hne,
simpa [ne.def, prod.mk.inj_iff] using (add_left_inj m).mp hij },
{ contrapose!, intro h, rw finset.nat.mem_antidiagonal }
end
instance : integral_domain (power_series α) :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := eq_zero_or_eq_zero_of_mul_eq_zero,
.. power_series.nonzero_comm_ring }
/-- The ideal spanned by the variable in the power series ring
over an integral domain is a prime ideal.-/
lemma span_X_is_prime : (ideal.span ({X} : set (power_series α))).is_prime :=
begin
suffices : ideal.span ({X} : set (power_series α)) = is_ring_hom.ker (constant_coeff α),
{ rw this, exact is_ring_hom.ker_is_prime _ },
apply ideal.ext, intro φ,
rw [is_ring_hom.mem_ker, ideal.mem_span_singleton, X_dvd_iff]
end
/-- The variable of the power series ring over an integral domain is prime.-/
lemma X_prime : prime (X : power_series α) :=
begin
rw ← ideal.span_singleton_prime,
{ exact span_X_is_prime },
{ intro h, simpa using congr_arg (coeff α 1) h }
end
end integral_domain
section local_ring
variables [comm_ring α]
lemma is_local_ring (h : is_local_ring α) :
is_local_ring (power_series α) :=
mv_power_series.is_local_ring h
end local_ring
section local_ring
variables {β : Type*} [local_ring α] [local_ring β] (f : α →+* β) [is_local_ring_hom f]
instance : local_ring (power_series α) :=
mv_power_series.local_ring
instance map.is_local_ring_hom :
is_local_ring_hom (map f) :=
mv_power_series.map.is_local_ring_hom f
end local_ring
section field
variables [field α]
protected def inv : power_series α → power_series α :=
mv_power_series.inv
instance : has_inv (power_series α) := ⟨power_series.inv⟩
lemma inv_eq_inv_aux (φ : power_series α) :
φ⁻¹ = inv.aux (constant_coeff α φ)⁻¹ φ := rfl
lemma coeff_inv (n) (φ : power_series α) :
coeff α n (φ⁻¹) = if n = 0 then (constant_coeff α φ)⁻¹ else
- (constant_coeff α φ)⁻¹ * (finset.nat.antidiagonal n).sum (λ (x : ℕ × ℕ),
if x.2 < n then coeff α x.1 φ * coeff α x.2 (φ⁻¹) else 0) :=
by rw [inv_eq_inv_aux, coeff_inv_aux n (constant_coeff α φ)⁻¹ φ]
@[simp] lemma constant_coeff_inv (φ : power_series α) :
constant_coeff α (φ⁻¹) = (constant_coeff α φ)⁻¹ :=
mv_power_series.constant_coeff_inv φ
lemma inv_eq_zero {φ : power_series α} :
φ⁻¹ = 0 ↔ constant_coeff α φ = 0 :=
mv_power_series.inv_eq_zero
@[simp, priority 1100] lemma inv_of_unit_eq (φ : power_series α) (h : constant_coeff α φ ≠ 0) :
inv_of_unit φ (units.mk0 _ h) = φ⁻¹ :=
mv_power_series.inv_of_unit_eq _ _
@[simp] lemma inv_of_unit_eq' (φ : power_series α) (u : units α) (h : constant_coeff α φ = u) :
inv_of_unit φ u = φ⁻¹ :=
mv_power_series.inv_of_unit_eq' φ _ h
@[simp] protected lemma mul_inv (φ : power_series α) (h : constant_coeff α φ ≠ 0) :
φ * φ⁻¹ = 1 :=
mv_power_series.mul_inv φ h
@[simp] protected lemma inv_mul (φ : power_series α) (h : constant_coeff α φ ≠ 0) :
φ⁻¹ * φ = 1 :=
mv_power_series.inv_mul φ h
end field
end power_series
namespace power_series
variable {α : Type*}
local attribute [instance, priority 1] classical.prop_decidable
noncomputable theory
section order_basic
open multiplicity
variables [comm_semiring α]
/-- The order of a formal power series `φ` is the smallest `n : enat`
such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/
@[reducible] def order (φ : power_series α) : enat :=
multiplicity X φ
lemma order_finite_of_coeff_ne_zero (φ : power_series α) (h : ∃ n, coeff α n φ ≠ 0) :
(order φ).dom :=
begin
cases h with n h, refine ⟨n, _⟩,
rw X_pow_dvd_iff, push_neg, exact ⟨n, lt_add_one n, h⟩
end
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero.-/
lemma coeff_order (φ : power_series α) (h : (order φ).dom) :
coeff α (φ.order.get h) φ ≠ 0 :=
begin
have H := nat.find_spec h, contrapose! H, rw X_pow_dvd_iff,
intros m hm, by_cases Hm : m < nat.find h,
{ have := nat.find_min h Hm, push_neg at this,
rw X_pow_dvd_iff at this, exact this m (lt_add_one m) },
have : m = nat.find h, {linarith}, {rwa this}
end
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
lemma order_le (φ : power_series α) (n : ℕ) (h : coeff α n φ ≠ 0) :
order φ ≤ n :=
begin
have h : ¬ X^(n+1) ∣ φ,
{ rw X_pow_dvd_iff, push_neg, exact ⟨n, lt_add_one n, h⟩ },
have : (order φ).dom := ⟨n, h⟩,
rw [← enat.coe_get this, enat.coe_le_coe],
refine nat.find_min' this h
end
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series.-/
lemma coeff_of_lt_order (φ : power_series α) (n : ℕ) (h: ↑n < order φ) :
coeff α n φ = 0 :=
by { contrapose! h, exact order_le _ _ h }
/-- The `0` power series is the unique power series with infinite order.-/
lemma order_eq_top {φ : power_series α} :
φ.order = ⊤ ↔ φ = 0 :=
begin
rw eq_top_iff,
split,
{ intro h, ext n, specialize h (n+1), rw X_pow_dvd_iff at h, exact h n (lt_add_one _) },
{ rintros rfl n, exact dvd_zero _ }
end
/-- The order of the `0` power series is infinite.-/
@[simp] lemma order_zero : order (0 : power_series α) = ⊤ :=
multiplicity.zero _
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`.-/
lemma order_ge_nat (φ : power_series α) (n : ℕ) (h : ∀ i < n, coeff α i φ = 0) :
order φ ≥ n :=
begin
by_contra H, rw not_le at H,
have : (order φ).dom := enat.dom_of_le_some (le_of_lt H),
rw [← enat.coe_get this, enat.coe_lt_coe] at H,
exact coeff_order _ this (h _ H)
end
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`.-/
lemma order_ge (φ : power_series α) (n : enat) (h : ∀ i : ℕ, ↑i < n → coeff α i φ = 0) :
order φ ≥ n :=
begin
induction n using enat.cases_on,
{ show _ ≤ _, rw [lattice.top_le_iff, order_eq_top],
ext i, exact h _ (enat.coe_lt_top i) },
{ apply order_ge_nat, simpa only [enat.coe_lt_coe] using h }
end
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`.-/
lemma order_eq_nat {φ : power_series α} {n : ℕ} :
order φ = n ↔ (coeff α n φ ≠ 0) ∧ (∀ i, i < n → coeff α i φ = 0) :=
begin
simp only [eq_some_iff, X_pow_dvd_iff], push_neg,
split,
{ rintros ⟨h₁, m, hm₁, hm₂⟩, refine ⟨_, h₁⟩,
suffices : n = m, { rwa this },
suffices : m ≥ n, { linarith },
contrapose! hm₂, exact h₁ _ hm₂ },
{ rintros ⟨h₁, h₂⟩, exact ⟨h₂, n, lt_add_one n, h₁⟩ }
end
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`.-/
lemma order_eq {φ : power_series α} {n : enat} :
order φ = n ↔ (∀ i:ℕ, ↑i = n → coeff α i φ ≠ 0) ∧ (∀ i:ℕ, ↑i < n → coeff α i φ = 0) :=
begin
induction n using enat.cases_on,
{ rw order_eq_top, split,
{ rintro rfl, split; intros,
{ exfalso, exact enat.coe_ne_top ‹_› ‹_› },
{ exact (coeff _ _).map_zero } },
{ rintro ⟨h₁, h₂⟩, ext i, exact h₂ i (enat.coe_lt_top i) } },
{ simpa [enat.coe_inj] using order_eq_nat }
end
/-- The order of the sum of two formal power series
is at least the minimum of their orders.-/
lemma order_add_ge (φ ψ : power_series α) :
order (φ + ψ) ≥ min (order φ) (order ψ) :=
multiplicity.min_le_multiplicity_add
private lemma order_add_of_order_eq.aux (φ ψ : power_series α)
(h : order φ ≠ order ψ) (H : order φ < order ψ) :
order (φ + ψ) ≤ order φ ⊓ order ψ :=
begin
suffices : order (φ + ψ) = order φ,
{ rw [lattice.le_inf_iff, this], exact ⟨le_refl _, le_of_lt H⟩ },
{ rw order_eq, split,
{ intros i hi, rw [(coeff _ _).map_add, coeff_of_lt_order ψ i (hi.symm ▸ H), add_zero],
exact (order_eq_nat.1 hi.symm).1 },
{ intros i hi,
rw [(coeff _ _).map_add, coeff_of_lt_order φ i hi,
coeff_of_lt_order ψ i (lt_trans hi H), zero_add] } }
end
/-- The order of the sum of two formal power series
is the minimum of their orders if their orders differ.-/
lemma order_add_of_order_eq (φ ψ : power_series α) (h : order φ ≠ order ψ) :
order (φ + ψ) = order φ ⊓ order ψ :=
begin
refine le_antisymm _ (order_add_ge _ _),
by_cases H₁ : order φ < order ψ,
{ apply order_add_of_order_eq.aux _ _ h H₁ },
by_cases H₂ : order ψ < order φ,
{ simpa only [add_comm, lattice.inf_comm] using order_add_of_order_eq.aux _ _ h.symm H₂ },
exfalso, exact h (le_antisymm (not_lt.1 H₂) (not_lt.1 H₁))
end
/-- The order of the product of two formal power series
is at least the sum of their orders.-/
lemma order_mul_ge (φ ψ : power_series α) :
order (φ * ψ) ≥ order φ + order ψ :=
begin
apply order_ge,
intros n hn, rw [coeff_mul, finset.sum_eq_zero],
rintros ⟨i,j⟩ hij,
by_cases hi : ↑i < order φ,
{ rw [coeff_of_lt_order φ i hi, zero_mul] },
by_cases hj : ↑j < order ψ,
{ rw [coeff_of_lt_order ψ j hj, mul_zero] },
rw not_lt at hi hj, rw finset.nat.mem_antidiagonal at hij,
exfalso,
apply ne_of_lt (lt_of_lt_of_le hn $ add_le_add' hi hj),
rw [← enat.coe_add, hij]
end
/-- The order of the monomial `a*X^n` is infinite if `a = 0` and `n` otherwise.-/
lemma order_monomial (n : ℕ) (a : α) :
order (monomial α n a) = if a = 0 then ⊤ else n :=
begin
split_ifs with h,
{ rw [h, order_eq_top, add_monoid_hom.map_zero] },
{ rw [order_eq], split; intros i hi,
{ rw [enat.coe_inj] at hi, rwa [hi, coeff_monomial'] },
{ rw [enat.coe_lt_coe] at hi, rw [coeff_monomial, if_neg], exact ne_of_lt hi } }
end
/-- The order of the monomial `a*X^n` is `n` if `a ≠ 0`.-/
lemma order_monomial_of_ne_zero (n : ℕ) (a : α) (h : a ≠ 0) :
order (monomial α n a) = n :=
by rw [order_monomial, if_neg h]
end order_basic
section order_zero_ne_one
variables [nonzero_comm_ring α]
/-- The order of the formal power series `1` is `0`.-/
@[simp] lemma order_one : order (1 : power_series α) = 0 :=
by simpa using order_monomial_of_ne_zero 0 (1:α) one_ne_zero
/-- The order of the formal power series `X` is `1`.-/
@[simp] lemma order_X : order (X : power_series α) = 1 :=
order_monomial_of_ne_zero 1 (1:α) one_ne_zero
/-- The order of the formal power series `X^n` is `n`.-/
@[simp] lemma order_X_pow (n : ℕ) : order ((X : power_series α)^n) = n :=
by { rw [X_pow_eq, order_monomial_of_ne_zero], exact one_ne_zero }
end order_zero_ne_one
section order_integral_domain
variables [integral_domain α]
/-- The order of the product of two formal power series over an integral domain
is the sum of their orders.-/
lemma order_mul (φ ψ : power_series α) :
order (φ * ψ) = order φ + order ψ :=
multiplicity.mul (X_prime)
end order_integral_domain
end power_series
namespace polynomial
open finsupp
variables {σ : Type*} {α : Type*} [comm_semiring α]
/-- The natural inclusion from polynomials into formal power series.-/
instance coe_to_power_series : has_coe (polynomial α) (power_series α) :=
⟨λ φ, power_series.mk $ λ n, coeff φ n⟩
@[simp, elim_cast] lemma coeff_coe (φ : polynomial α) (n) :
power_series.coeff α n φ = coeff φ n :=
congr_arg (coeff φ) (finsupp.single_eq_same)
@[reducible] def monomial (n : ℕ) (a : α) : polynomial α := single n a
@[simp, elim_cast] lemma coe_monomial (n : ℕ) (a : α) :
(monomial n a : power_series α) = power_series.monomial α n a :=
power_series.ext $ λ m,
begin
rw [coeff_coe, power_series.coeff_monomial],
simp only [@eq_comm _ m n],
convert finsupp.single_apply,
end
@[simp, elim_cast] lemma coe_zero : ((0 : polynomial α) : power_series α) = 0 := rfl
@[simp, elim_cast] lemma coe_one : ((1 : polynomial α) : power_series α) = 1 :=
begin
have := coe_monomial 0 (1:α),
rwa power_series.monomial_zero_eq_C_apply at this,
end
@[simp, elim_cast] lemma coe_add (φ ψ : polynomial α) :
((φ + ψ : polynomial α) : power_series α) = φ + ψ := rfl
@[simp, elim_cast] lemma coe_mul (φ ψ : polynomial α) :
((φ * ψ : polynomial α) : power_series α) = φ * ψ :=
power_series.ext $ λ n,
by simp only [coeff_coe, power_series.coeff_mul, coeff_mul]
@[simp, elim_cast] lemma coe_C (a : α) :
((C a : polynomial α) : power_series α) = power_series.C α a :=
begin
have := coe_monomial 0 a,
rwa power_series.monomial_zero_eq_C_apply at this,
end
@[simp, elim_cast] lemma coe_X :
((X : polynomial α) : power_series α) = power_series.X :=
coe_monomial _ _
namespace coe_to_mv_power_series
instance : is_semiring_hom (coe : polynomial α → power_series α) :=
{ map_zero := coe_zero,
map_one := coe_one,
map_add := coe_add,
map_mul := coe_mul }
end coe_to_mv_power_series
end polynomial
|
29a035ae2bb1608537ca9ab2f076e0ff45f0a29f
|
626e312b5c1cb2d88fca108f5933076012633192
|
/src/ring_theory/jacobson.lean
|
407f319b5203da35ba7815f3ce4b4f9c64f3fb79
|
[
"Apache-2.0"
] |
permissive
|
Bioye97/mathlib
|
9db2f9ee54418d29dd06996279ba9dc874fd6beb
|
782a20a27ee83b523f801ff34efb1a9557085019
|
refs/heads/master
| 1,690,305,956,488
| 1,631,067,774,000
| 1,631,067,774,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 34,345
|
lean
|
/-
Copyright (c) 2020 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma
-/
import data.mv_polynomial
import ring_theory.ideal.over
import ring_theory.jacobson_ideal
import ring_theory.localization
/-!
# Jacobson Rings
The following conditions are equivalent for a ring `R`:
1. Every radical ideal `I` is equal to its Jacobson radical
2. Every radical ideal `I` can be written as an intersection of maximal ideals
3. Every prime ideal `I` is equal to its Jacobson radical
Any ring satisfying any of these equivalent conditions is said to be Jacobson.
Some particular examples of Jacobson rings are also proven.
`is_jacobson_quotient` says that the quotient of a Jacobson ring is Jacobson.
`is_jacobson_localization` says the localization of a Jacobson ring to a single element is Jacobson.
`is_jacobson_polynomial_iff_is_jacobson` says polynomials over a Jacobson ring form a Jacobson ring.
## Main definitions
Let `R` be a commutative ring. Jacobson Rings are defined using the first of the above conditions
* `is_jacobson R` is the proposition that `R` is a Jacobson ring. It is a class,
implemented as the predicate that for any ideal, `I.radical = I` implies `I.jacobson = I`.
## Main statements
* `is_jacobson_iff_prime_eq` is the equivalence between conditions 1 and 3 above.
* `is_jacobson_iff_Inf_maximal` is the equivalence between conditions 1 and 2 above.
* `is_jacobson_of_surjective` says that if `R` is a Jacobson ring and `f : R →+* S` is surjective,
then `S` is also a Jacobson ring
* `is_jacobson_mv_polynomial` says that multi-variate polynomials over a Jacobson ring are Jacobson.
## Tags
Jacobson, Jacobson Ring
-/
namespace ideal
open polynomial
section is_jacobson
variables {R S : Type*} [comm_ring R] [comm_ring S] {I : ideal R}
/-- A ring is a Jacobson ring if for every radical ideal `I`,
the Jacobson radical of `I` is equal to `I`.
See `is_jacobson_iff_prime_eq` and `is_jacobson_iff_Inf_maximal` for equivalent definitions. -/
class is_jacobson (R : Type*) [comm_ring R] : Prop :=
(out' : ∀ (I : ideal R), I.radical = I → I.jacobson = I)
theorem is_jacobson_iff {R} [comm_ring R] :
is_jacobson R ↔ ∀ (I : ideal R), I.radical = I → I.jacobson = I :=
⟨λ h, h.1, λ h, ⟨h⟩⟩
theorem is_jacobson.out {R} [comm_ring R] :
is_jacobson R → ∀ {I : ideal R}, I.radical = I → I.jacobson = I := is_jacobson_iff.1
/-- A ring is a Jacobson ring if and only if for all prime ideals `P`,
the Jacobson radical of `P` is equal to `P`. -/
lemma is_jacobson_iff_prime_eq : is_jacobson R ↔ ∀ P : ideal R, is_prime P → P.jacobson = P :=
begin
refine is_jacobson_iff.trans ⟨λ h I hI, h I (is_prime.radical hI), _⟩,
refine λ h I hI, le_antisymm (λ x hx, _) (λ x hx, mem_Inf.mpr (λ _ hJ, hJ.left hx)),
rw [← hI, radical_eq_Inf I, mem_Inf],
intros P hP,
rw set.mem_set_of_eq at hP,
erw mem_Inf at hx,
erw [← h P hP.right, mem_Inf],
exact λ J hJ, hx ⟨le_trans hP.left hJ.left, hJ.right⟩
end
/-- A ring `R` is Jacobson if and only if for every prime ideal `I`,
`I` can be written as the infimum of some collection of maximal ideals.
Allowing ⊤ in the set `M` of maximal ideals is equivalent, but makes some proofs cleaner. -/
lemma is_jacobson_iff_Inf_maximal : is_jacobson R ↔
∀ {I : ideal R}, I.is_prime → ∃ M : set (ideal R), (∀ J ∈ M, is_maximal J ∨ J = ⊤) ∧ I = Inf M :=
⟨λ H I h, eq_jacobson_iff_Inf_maximal.1 (H.out (is_prime.radical h)),
λ H, is_jacobson_iff_prime_eq.2 (λ P hP, eq_jacobson_iff_Inf_maximal.2 (H hP))⟩
lemma is_jacobson_iff_Inf_maximal' : is_jacobson R ↔
∀ {I : ideal R}, I.is_prime → ∃ M : set (ideal R),
(∀ (J ∈ M) (K : ideal R), J < K → K = ⊤) ∧ I = Inf M :=
⟨λ H I h, eq_jacobson_iff_Inf_maximal'.1 (H.out (is_prime.radical h)),
λ H, is_jacobson_iff_prime_eq.2 (λ P hP, eq_jacobson_iff_Inf_maximal'.2 (H hP))⟩
lemma radical_eq_jacobson [H : is_jacobson R] (I : ideal R) : I.radical = I.jacobson :=
le_antisymm (le_Inf (λ J ⟨hJ, hJ_max⟩, (is_prime.radical_le_iff hJ_max.is_prime).mpr hJ))
((H.out (radical_idem I)) ▸ (jacobson_mono le_radical))
/-- Fields have only two ideals, and the condition holds for both of them. -/
@[priority 100]
instance is_jacobson_field {K : Type*} [field K] : is_jacobson K :=
⟨λ I hI, or.rec_on (eq_bot_or_top I)
(λ h, le_antisymm
(Inf_le ⟨le_of_eq rfl, (eq.symm h) ▸ bot_is_maximal⟩)
((eq.symm h) ▸ bot_le))
(λ h, by rw [h, jacobson_eq_top_iff])⟩
theorem is_jacobson_of_surjective [H : is_jacobson R] :
(∃ (f : R →+* S), function.surjective f) → is_jacobson S :=
begin
rintros ⟨f, hf⟩,
rw is_jacobson_iff_Inf_maximal,
intros p hp,
use map f '' {J : ideal R | comap f p ≤ J ∧ J.is_maximal },
use λ j ⟨J, hJ, hmap⟩, hmap ▸ or.symm (map_eq_top_or_is_maximal_of_surjective f hf hJ.right),
have : p = map f ((comap f p).jacobson),
from (is_jacobson.out' (comap f p) (by rw [← comap_radical, is_prime.radical hp])).symm
▸ (map_comap_of_surjective f hf p).symm,
exact eq.trans this (map_Inf hf (λ J ⟨hJ, _⟩, le_trans (ideal.ker_le_comap f) hJ)),
end
@[priority 100]
instance is_jacobson_quotient [is_jacobson R] : is_jacobson (quotient I) :=
is_jacobson_of_surjective ⟨quotient.mk I, (by rintro ⟨x⟩; use x; refl)⟩
lemma is_jacobson_iso (e : R ≃+* S) : is_jacobson R ↔ is_jacobson S :=
⟨λ h, @is_jacobson_of_surjective _ _ _ _ h ⟨(e : R →+* S), e.surjective⟩,
λ h, @is_jacobson_of_surjective _ _ _ _ h ⟨(e.symm : S →+* R), e.symm.surjective⟩⟩
lemma is_jacobson_of_is_integral [algebra R S] (hRS : algebra.is_integral R S)
(hR : is_jacobson R) : is_jacobson S :=
begin
rw is_jacobson_iff_prime_eq,
introsI P hP,
by_cases hP_top : comap (algebra_map R S) P = ⊤,
{ simp [comap_eq_top_iff.1 hP_top] },
{ haveI : nontrivial (comap (algebra_map R S) P).quotient := quotient.nontrivial hP_top,
rw jacobson_eq_iff_jacobson_quotient_eq_bot,
refine eq_bot_of_comap_eq_bot (is_integral_quotient_of_is_integral hRS) _,
rw [eq_bot_iff, ← jacobson_eq_iff_jacobson_quotient_eq_bot.1 ((is_jacobson_iff_prime_eq.1 hR)
(comap (algebra_map R S) P) (comap_is_prime _ _)), comap_jacobson],
refine Inf_le_Inf (λ J hJ, _),
simp only [true_and, set.mem_image, bot_le, set.mem_set_of_eq],
haveI : J.is_maximal, { simpa using hJ },
exact exists_ideal_over_maximal_of_is_integral (is_integral_quotient_of_is_integral hRS) J
(comap_bot_le_of_injective _ algebra_map_quotient_injective) }
end
lemma is_jacobson_of_is_integral' (f : R →+* S) (hf : f.is_integral)
(hR : is_jacobson R) : is_jacobson S :=
@is_jacobson_of_is_integral _ _ _ _ f.to_algebra hf hR
end is_jacobson
section localization
open is_localization submonoid
variables {R S : Type*} [comm_ring R] [comm_ring S] {I : ideal R}
variables (y : R) [algebra R S] [is_localization.away y S]
lemma disjoint_powers_iff_not_mem (hI : I.radical = I) :
disjoint ((submonoid.powers y) : set R) ↑I ↔ y ∉ I.1 :=
begin
refine ⟨λ h, set.disjoint_left.1 h (mem_powers _), λ h, (disjoint_iff).mpr (eq_bot_iff.mpr _)⟩,
rintros x ⟨⟨n, rfl⟩, hx'⟩,
rw [← hI] at hx',
exact absurd (hI ▸ mem_radical_of_pow_mem hx' : y ∈ I.carrier) h
end
variables (S)
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y`.
This lemma gives the correspondence in the particular case of an ideal and its comap.
See `le_rel_iso_of_maximal` for the more general relation isomorphism -/
lemma is_maximal_iff_is_maximal_disjoint [H : is_jacobson R] (J : ideal S) :
J.is_maximal ↔ (comap (algebra_map R S) J).is_maximal ∧ y ∉ ideal.comap (algebra_map R S) J :=
begin
split,
{ refine λ h, ⟨_, λ hy, h.ne_top (ideal.eq_top_of_is_unit_mem _ hy
(map_units _ ⟨y, submonoid.mem_powers _⟩))⟩,
have hJ : J.is_prime := is_maximal.is_prime h,
rw is_prime_iff_is_prime_disjoint (submonoid.powers y) at hJ,
have : y ∉ (comap (algebra_map R S) J).1 :=
set.disjoint_left.1 hJ.right (submonoid.mem_powers _),
erw [← H.out (is_prime.radical hJ.left), mem_Inf] at this,
push_neg at this,
rcases this with ⟨I, hI, hI'⟩,
convert hI.right,
by_cases hJ : J = map (algebra_map R S) I,
{ rw [hJ, comap_map_of_is_prime_disjoint (powers y) S I (is_maximal.is_prime hI.right)],
rwa disjoint_powers_iff_not_mem y (is_maximal.is_prime hI.right).radical },
{ have hI_p : (map (algebra_map R S) I).is_prime,
{ refine is_prime_of_is_prime_disjoint (powers y) _ I hI.right.is_prime _,
rwa disjoint_powers_iff_not_mem y (is_maximal.is_prime hI.right).radical },
have : J ≤ map (algebra_map R S) I :=
(map_comap (submonoid.powers y) S J) ▸ (map_mono hI.left),
exact absurd (h.1.2 _ (lt_of_le_of_ne this hJ)) hI_p.1 } },
{ refine λ h, ⟨⟨λ hJ, h.1.ne_top (eq_top_iff.2 _), λ I hI, _⟩⟩,
{ rwa [eq_top_iff, ← (is_localization.order_embedding (powers y) S).le_iff_le] at hJ },
{ have := congr_arg (map (algebra_map R S)) (h.1.1.2 _ ⟨comap_mono (le_of_lt hI), _⟩),
rwa [map_comap (powers y) S I, map_top] at this,
refine λ hI', hI.right _,
rw [← map_comap (powers y) S I, ← map_comap (powers y) S J],
exact map_mono hI' } }
end
variables {S}
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y`.
This lemma gives the correspondence in the particular case of an ideal and its map.
See `le_rel_iso_of_maximal` for the more general statement, and the reverse of this implication -/
lemma is_maximal_of_is_maximal_disjoint [is_jacobson R] (I : ideal R) (hI : I.is_maximal)
(hy : y ∉ I) : (map (algebra_map R S) I).is_maximal :=
begin
rw [is_maximal_iff_is_maximal_disjoint S y,
comap_map_of_is_prime_disjoint (powers y) S I (is_maximal.is_prime hI)
((disjoint_powers_iff_not_mem y (is_maximal.is_prime hI).radical).2 hy)],
exact ⟨hI, hy⟩
end
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y` -/
def order_iso_of_maximal [is_jacobson R] :
{p : ideal S // p.is_maximal} ≃o {p : ideal R // p.is_maximal ∧ y ∉ p} :=
{ to_fun := λ p,
⟨ideal.comap (algebra_map R S) p.1, (is_maximal_iff_is_maximal_disjoint S y p.1).1 p.2⟩,
inv_fun := λ p,
⟨ideal.map (algebra_map R S) p.1, is_maximal_of_is_maximal_disjoint y p.1 p.2.1 p.2.2⟩,
left_inv := λ J, subtype.eq (map_comap (powers y) S J),
right_inv := λ I, subtype.eq (comap_map_of_is_prime_disjoint _ _ I.1 (is_maximal.is_prime I.2.1)
((disjoint_powers_iff_not_mem y I.2.1.is_prime.radical).2 I.2.2)),
map_rel_iff' := λ I I', ⟨λ h, (show I.val ≤ I'.val,
from (map_comap (powers y) S I.val) ▸ (map_comap (powers y) S I'.val) ▸ (ideal.map_mono h)),
λ h x hx, h hx⟩ }
include y
/-- If `S` is the localization of the Jacobson ring `R` at the submonoid generated by `y : R`, then
`S` is Jacobson. -/
lemma is_jacobson_localization [H : is_jacobson R] : is_jacobson S :=
begin
rw is_jacobson_iff_prime_eq,
refine λ P' hP', le_antisymm _ le_jacobson,
obtain ⟨hP', hPM⟩ := (is_localization.is_prime_iff_is_prime_disjoint (powers y) S P').mp hP',
have hP := H.out (is_prime.radical hP'),
refine (le_of_eq (is_localization.map_comap (powers y) S P'.jacobson).symm).trans
((map_mono _).trans (le_of_eq (is_localization.map_comap (powers y) S P'))),
have : Inf { I : ideal R | comap (algebra_map R S) P' ≤ I ∧ I.is_maximal ∧ y ∉ I } ≤
comap (algebra_map R S) P',
{ intros x hx,
have hxy : x * y ∈ (comap (algebra_map R S) P').jacobson,
{ rw [ideal.jacobson, mem_Inf],
intros J hJ,
by_cases y ∈ J,
{ exact J.smul_mem x h },
{ exact (mul_comm y x) ▸ J.smul_mem y ((mem_Inf.1 hx) ⟨hJ.left, ⟨hJ.right, h⟩⟩) } },
rw hP at hxy,
cases hP'.mem_or_mem hxy with hxy hxy,
{ exact hxy },
{ exact (hPM ⟨submonoid.mem_powers _, hxy⟩).elim } },
refine le_trans _ this,
rw [ideal.jacobson, comap_Inf', Inf_eq_infi],
refine infi_le_infi_of_subset (λ I hI, ⟨map (algebra_map R S) I, ⟨_, _⟩⟩),
{ exact ⟨le_trans (le_of_eq ((is_localization.map_comap (powers y) S P').symm)) (map_mono hI.1),
is_maximal_of_is_maximal_disjoint y _ hI.2.1 hI.2.2⟩ },
{ exact is_localization.comap_map_of_is_prime_disjoint _ S I (is_maximal.is_prime hI.2.1)
((disjoint_powers_iff_not_mem y hI.2.1.is_prime.radical).2 hI.2.2) }
end
end localization
namespace polynomial
open polynomial
section comm_ring
variables {R S : Type*} [comm_ring R] [integral_domain S]
variables {Rₘ Sₘ : Type*} [comm_ring Rₘ] [comm_ring Sₘ]
/-- If `I` is a prime ideal of `polynomial R` and `pX ∈ I` is a non-constant polynomial,
then the map `R →+* R[x]/I` descends to an integral map when localizing at `pX.leading_coeff`.
In particular `X` is integral because it satisfies `pX`, and constants are trivially integral,
so integrality of the entire extension follows by closure under addition and multiplication. -/
lemma is_integral_is_localization_polynomial_quotient
(P : ideal (polynomial R)) [P.is_prime] (pX : polynomial R) (hpX : pX ∈ P)
[algebra (P.comap (C : R →+* _)).quotient Rₘ]
[is_localization.away (pX.map (quotient.mk (P.comap C))).leading_coeff Rₘ]
[algebra P.quotient Sₘ]
[is_localization ((submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff).map
(quotient_map P C le_rfl) : submonoid P.quotient) Sₘ] :
(is_localization.map Sₘ (quotient_map P C le_rfl)
((submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff).le_comap_map) : Rₘ →+* _)
.is_integral :=
begin
let P' : ideal R := P.comap C,
let M : submonoid P'.quotient :=
submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff,
let M' : submonoid P.quotient :=
(submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff).map (quotient_map P C le_rfl),
let φ : P'.quotient →+* P.quotient := quotient_map P C le_rfl,
let φ' := is_localization.map Sₘ φ M.le_comap_map,
have hφ' : φ.comp (quotient.mk P') = (quotient.mk P).comp C := rfl,
intro p,
obtain ⟨⟨p', ⟨q, hq⟩⟩, hp⟩ := is_localization.surj M' p,
suffices : φ'.is_integral_elem (algebra_map _ _ p'),
{ obtain ⟨q', hq', rfl⟩ := hq,
obtain ⟨q'', hq''⟩ := is_unit_iff_exists_inv'.1 (is_localization.map_units Rₘ (⟨q', hq'⟩ : M)),
refine φ'.is_integral_of_is_integral_mul_unit p (algebra_map _ _ (φ q')) q'' _ (hp.symm ▸ this),
convert trans (trans (φ'.map_mul _ _).symm (congr_arg φ' hq'')) φ'.map_one using 2,
rw [← φ'.comp_apply, is_localization.map_comp, ring_hom.comp_apply, subtype.coe_mk] },
refine is_integral_of_mem_closure''
(((algebra_map _ Sₘ).comp (quotient.mk P)) '' (insert X {p | p.degree ≤ 0})) _ _ _,
{ rintros x ⟨p, hp, rfl⟩,
refine hp.rec_on (λ hy, _) (λ hy, _),
{ refine hy.symm ▸ (φ.is_integral_elem_localization_at_leading_coeff ((quotient.mk P) X)
(pX.map (quotient.mk P')) _ M ⟨1, pow_one _⟩),
rwa [eval₂_map, hφ', ← hom_eval₂, quotient.eq_zero_iff_mem, eval₂_C_X] },
{ rw [set.mem_set_of_eq, degree_le_zero_iff] at hy,
refine hy.symm ▸ ⟨X - C (algebra_map _ _ ((quotient.mk P') (p.coeff 0))), monic_X_sub_C _, _⟩,
simp only [eval₂_sub, eval₂_C, eval₂_X],
rw [sub_eq_zero, ← φ'.comp_apply, is_localization.map_comp],
refl } },
{ obtain ⟨p, rfl⟩ := quotient.mk_surjective p',
refine polynomial.induction_on p
(λ r, subring.subset_closure $ set.mem_image_of_mem _ (or.inr degree_C_le))
(λ _ _ h1 h2, _) (λ n _ hr, _),
{ convert subring.add_mem _ h1 h2,
rw [ring_hom.map_add, ring_hom.map_add] },
{ rw [pow_succ X n, mul_comm X, ← mul_assoc, ring_hom.map_mul, ring_hom.map_mul],
exact subring.mul_mem _ hr (subring.subset_closure (set.mem_image_of_mem _ (or.inl rfl))) } },
end
/-- If `f : R → S` descends to an integral map in the localization at `x`,
and `R` is a Jacobson ring, then the intersection of all maximal ideals in `S` is trivial -/
lemma jacobson_bot_of_integral_localization {R : Type*} [integral_domain R] [is_jacobson R]
(Rₘ Sₘ : Type*) [comm_ring Rₘ] [comm_ring Sₘ]
(φ : R →+* S) (hφ : function.injective φ) (x : R) (hx : x ≠ 0)
[algebra R Rₘ] [is_localization.away x Rₘ]
[algebra S Sₘ] [is_localization ((submonoid.powers x).map φ : submonoid S) Sₘ]
(hφ' : ring_hom.is_integral
(is_localization.map Sₘ φ (submonoid.powers x).le_comap_map : Rₘ →+* Sₘ)) :
(⊥ : ideal S).jacobson = (⊥ : ideal S) :=
begin
have hM : ((submonoid.powers x).map φ : submonoid S) ≤ non_zero_divisors S :=
φ.map_le_non_zero_divisors_of_injective hφ (powers_le_non_zero_divisors_of_no_zero_divisors hx),
letI : integral_domain Sₘ := is_localization.integral_domain_of_le_non_zero_divisors _ hM,
let φ' : Rₘ →+* Sₘ := is_localization.map _ φ (submonoid.powers x).le_comap_map,
suffices : ∀ I : ideal Sₘ, I.is_maximal → (I.comap (algebra_map S Sₘ)).is_maximal,
{ have hϕ' : comap (algebra_map S Sₘ) (⊥ : ideal Sₘ) = (⊥ : ideal S),
{ rw [← ring_hom.ker_eq_comap_bot, ← ring_hom.injective_iff_ker_eq_bot],
exact is_localization.injective Sₘ hM },
have hSₘ : is_jacobson Sₘ := is_jacobson_of_is_integral' φ' hφ' (is_jacobson_localization x),
refine eq_bot_iff.mpr (le_trans _ (le_of_eq hϕ')),
rw [← hSₘ.out radical_bot_of_integral_domain, comap_jacobson],
exact Inf_le_Inf (λ j hj, ⟨bot_le, let ⟨J, hJ⟩ := hj in hJ.2 ▸ this J hJ.1.2⟩) },
introsI I hI,
-- Remainder of the proof is pulling and pushing ideals around the square and the quotient square
haveI : (I.comap (algebra_map S Sₘ)).is_prime := comap_is_prime _ I,
haveI : (I.comap φ').is_prime := comap_is_prime φ' I,
haveI : (⊥ : ideal (I.comap (algebra_map S Sₘ)).quotient).is_prime := bot_prime,
have hcomm: φ'.comp (algebra_map R Rₘ) = (algebra_map S Sₘ).comp φ := is_localization.map_comp _,
let f := quotient_map (I.comap (algebra_map S Sₘ)) φ le_rfl,
let g := quotient_map I (algebra_map S Sₘ) le_rfl,
have := is_maximal_comap_of_is_integral_of_is_maximal' φ' hφ' I
(by convert hI; casesI _inst_4; refl),
have := ((is_maximal_iff_is_maximal_disjoint Rₘ x _).1 this).left,
have : ((I.comap (algebra_map S Sₘ)).comap φ).is_maximal,
{ rwa [comap_comap, hcomm, ← comap_comap] at this },
rw ← bot_quotient_is_maximal_iff at this ⊢,
refine is_maximal_of_is_integral_of_is_maximal_comap' f _ ⊥
((eq_bot_iff.2 (comap_bot_le_of_injective f quotient_map_injective)).symm ▸ this),
exact f.is_integral_tower_bot_of_is_integral g quotient_map_injective
((comp_quotient_map_eq_of_comp_eq hcomm I).symm ▸
(ring_hom.is_integral_trans _ _ (ring_hom.is_integral_of_surjective _
(is_localization.surjective_quotient_map_of_maximal_of_localization (submonoid.powers x) Rₘ
(by rwa [comap_comap, hcomm, ← bot_quotient_is_maximal_iff])))
(ring_hom.is_integral_quotient_of_is_integral _ hφ'))),
end
/-- Used to bootstrap the proof of `is_jacobson_polynomial_iff_is_jacobson`.
That theorem is more general and should be used instead of this one. -/
private lemma is_jacobson_polynomial_of_domain (R : Type*) [integral_domain R] [hR : is_jacobson R]
(P : ideal (polynomial R)) [is_prime P] (hP : ∀ (x : R), C x ∈ P → x = 0) :
P.jacobson = P :=
begin
by_cases Pb : P = ⊥,
{ exact Pb.symm ▸ jacobson_bot_polynomial_of_jacobson_bot
(hR.out radical_bot_of_integral_domain) },
{ rw jacobson_eq_iff_jacobson_quotient_eq_bot,
haveI : (P.comap (C : R →+* polynomial R)).is_prime := comap_is_prime C P,
obtain ⟨p, pP, p0⟩ := exists_nonzero_mem_of_ne_bot Pb hP,
let x := (polynomial.map (quotient.mk (comap (C : R →+* _) P)) p).leading_coeff,
have hx : x ≠ 0 := by rwa [ne.def, leading_coeff_eq_zero],
refine jacobson_bot_of_integral_localization
(localization.away x)
(localization ((submonoid.powers x).map (P.quotient_map C le_rfl) : submonoid P.quotient))
(quotient_map P C le_rfl) quotient_map_injective
x hx
_,
-- `convert` is noticeably faster than `exact` here:
convert is_integral_is_localization_polynomial_quotient P p pP }
end
lemma is_jacobson_polynomial_of_is_jacobson (hR : is_jacobson R) :
is_jacobson (polynomial R) :=
begin
refine is_jacobson_iff_prime_eq.mpr (λ I, _),
introI hI,
let R' : subring I.quotient := ((quotient.mk I).comp C).range,
let i : R →+* R' := ((quotient.mk I).comp C).range_restrict,
have hi : function.surjective (i : R → R') := ((quotient.mk I).comp C).range_restrict_surjective,
have hi' : (polynomial.map_ring_hom i : polynomial R →+* polynomial R').ker ≤ I,
{ refine λ f hf, polynomial_mem_ideal_of_coeff_mem_ideal I f (λ n, _),
replace hf := congr_arg (λ (g : polynomial (((quotient.mk I).comp C).range)), g.coeff n) hf,
change (polynomial.map ((quotient.mk I).comp C).range_restrict f).coeff n = 0 at hf,
rw [coeff_map, subtype.ext_iff] at hf,
rwa [mem_comap, ← quotient.eq_zero_iff_mem, ← ring_hom.comp_apply], },
haveI : (ideal.map (map_ring_hom i) I).is_prime :=
map_is_prime_of_surjective (map_surjective i hi) hi',
suffices : (I.map (polynomial.map_ring_hom i)).jacobson = (I.map (polynomial.map_ring_hom i)),
{ replace this := congr_arg (comap (polynomial.map_ring_hom i)) this,
rw [← map_jacobson_of_surjective _ hi',
comap_map_of_surjective _ _, comap_map_of_surjective _ _] at this,
refine le_antisymm (le_trans (le_sup_of_le_left le_rfl)
(le_trans (le_of_eq this) (sup_le le_rfl hi'))) le_jacobson,
all_goals {exact polynomial.map_surjective i hi} },
exact @is_jacobson_polynomial_of_domain R' _ (is_jacobson_of_surjective ⟨i, hi⟩)
(map (map_ring_hom i) I) _ (eq_zero_of_polynomial_mem_map_range I),
end
theorem is_jacobson_polynomial_iff_is_jacobson :
is_jacobson (polynomial R) ↔ is_jacobson R :=
begin
refine ⟨_, is_jacobson_polynomial_of_is_jacobson⟩,
introI H,
exact is_jacobson_of_surjective ⟨eval₂_ring_hom (ring_hom.id _) 1, λ x,
⟨C x, by simp only [coe_eval₂_ring_hom, ring_hom.id_apply, eval₂_C]⟩⟩,
end
instance [is_jacobson R] : is_jacobson (polynomial R) :=
is_jacobson_polynomial_iff_is_jacobson.mpr ‹is_jacobson R›
end comm_ring
section integral_domain
variables {R : Type*} [integral_domain R] [is_jacobson R]
variables (P : ideal (polynomial R)) [hP : P.is_maximal]
include P hP
lemma is_maximal_comap_C_of_is_maximal (hP' : ∀ (x : R), C x ∈ P → x = 0) :
is_maximal (comap C P : ideal R) :=
begin
haveI hp'_prime : (P.comap C : ideal R).is_prime := comap_is_prime C P,
obtain ⟨m, hm⟩ := submodule.nonzero_mem_of_bot_lt (bot_lt_of_maximal P polynomial_not_is_field),
have : (m : polynomial R) ≠ 0, rwa [ne.def, submodule.coe_eq_zero],
let φ : (P.comap C : ideal R).quotient →+* P.quotient := quotient_map P C le_rfl,
let M : submonoid (P.comap C : ideal R).quotient :=
submonoid.powers ((m : polynomial R).map (quotient.mk (P.comap C : ideal R))).leading_coeff,
rw ← bot_quotient_is_maximal_iff at hP ⊢,
have hp0 : ((m : polynomial R).map (quotient.mk (P.comap C : ideal R))).leading_coeff ≠ 0 :=
λ hp0', this $ map_injective (quotient.mk (P.comap C : ideal R))
((quotient.mk (P.comap C : ideal R)).injective_iff.2 (λ x hx,
by rwa [quotient.eq_zero_iff_mem, (by rwa eq_bot_iff : (P.comap C : ideal R) = ⊥)] at hx))
(by simpa only [leading_coeff_eq_zero, map_zero] using hp0'),
have hM : (0 : ((P.comap C : ideal R)).quotient) ∉ M := λ ⟨n, hn⟩, hp0 (pow_eq_zero hn),
suffices : (⊥ : ideal (localization M)).is_maximal,
{ rw ← is_localization.comap_map_of_is_prime_disjoint M (localization M) ⊥ bot_prime
(λ x hx, hM (hx.2 ▸ hx.1)),
refine ((is_maximal_iff_is_maximal_disjoint (localization M) _ _).mp (by rwa map_bot)).1,
swap, exact localization.is_localization },
let M' : submonoid P.quotient := M.map φ,
have hM' : (0 : P.quotient) ∉ M' :=
λ ⟨z, hz⟩, hM (quotient_map_injective (trans hz.2 φ.map_zero.symm) ▸ hz.1),
letI : integral_domain (localization M') :=
is_localization.integral_domain_localization (le_non_zero_divisors_of_no_zero_divisors hM'),
suffices : (⊥ : ideal (localization M')).is_maximal,
{ rw le_antisymm bot_le (comap_bot_le_of_injective _ (is_localization.map_injective_of_injective
M (localization M) (localization M')
quotient_map_injective (le_non_zero_divisors_of_no_zero_divisors hM'))),
refine is_maximal_comap_of_is_integral_of_is_maximal' _ _ ⊥ this,
apply is_integral_is_localization_polynomial_quotient P _ (submodule.coe_mem m) },
rw (map_bot.symm : (⊥ : ideal (localization M')) =
map (algebra_map P.quotient (localization M')) ⊥),
refine map.is_maximal (algebra_map _ _) (localization_map_bijective_of_field hM' _) hP,
rwa [← quotient.maximal_ideal_iff_is_field_quotient, ← bot_quotient_is_maximal_iff],
end
/-- Used to bootstrap the more general `quotient_mk_comp_C_is_integral_of_jacobson` -/
private lemma quotient_mk_comp_C_is_integral_of_jacobson' (hR : is_jacobson R)
(hP' : ∀ (x : R), C x ∈ P → x = 0) :
((quotient.mk P).comp C : R →+* P.quotient).is_integral :=
begin
refine (is_integral_quotient_map_iff _).mp _,
let P' : ideal R := P.comap C,
obtain ⟨pX, hpX, hp0⟩ :=
exists_nonzero_mem_of_ne_bot (ne_of_lt (bot_lt_of_maximal P polynomial_not_is_field)).symm hP',
let M : submonoid P'.quotient := submonoid.powers (pX.map (quotient.mk P')).leading_coeff,
let φ : P'.quotient →+* P.quotient := quotient_map P C le_rfl,
haveI hp'_prime : P'.is_prime := comap_is_prime C P,
have hM : (0 : P'.quotient) ∉ M := λ ⟨n, hn⟩, hp0 $ leading_coeff_eq_zero.mp (pow_eq_zero hn),
let M' : submonoid P.quotient := M.map (quotient_map P C le_rfl),
refine ((quotient_map P C le_rfl).is_integral_tower_bot_of_is_integral
(algebra_map _ (localization M')) _ _),
{ refine is_localization.injective (localization M')
(show M' ≤ _, from le_non_zero_divisors_of_no_zero_divisors (λ hM', hM _)),
exact (let ⟨z, zM, z0⟩ := hM' in (quotient_map_injective (trans z0 φ.map_zero.symm)) ▸ zM) },
{ rw ← is_localization.map_comp M.le_comap_map,
refine ring_hom.is_integral_trans (algebra_map P'.quotient (localization M))
(is_localization.map _ _ M.le_comap_map) _ _,
{ exact (algebra_map P'.quotient (localization M)).is_integral_of_surjective
(localization_map_bijective_of_field hM
((quotient.maximal_ideal_iff_is_field_quotient _).mp
(is_maximal_comap_C_of_is_maximal P hP'))).2 },
{ -- `convert` here is faster than `exact`, and this proof is near the time limit.
convert is_integral_is_localization_polynomial_quotient P pX hpX } }
end
/-- If `R` is a Jacobson ring, and `P` is a maximal ideal of `polynomial R`,
then `R → (polynomial R)/P` is an integral map. -/
lemma quotient_mk_comp_C_is_integral_of_jacobson :
((quotient.mk P).comp C : R →+* P.quotient).is_integral :=
begin
let P' : ideal R := P.comap C,
haveI : P'.is_prime := comap_is_prime C P,
let f : polynomial R →+* polynomial P'.quotient := polynomial.map_ring_hom (quotient.mk P'),
have hf : function.surjective f := map_surjective (quotient.mk P') quotient.mk_surjective,
have hPJ : P = (P.map f).comap f,
{ rw comap_map_of_surjective _ hf,
refine le_antisymm (le_sup_of_le_left le_rfl) (sup_le le_rfl _),
refine λ p hp, polynomial_mem_ideal_of_coeff_mem_ideal P p (λ n, quotient.eq_zero_iff_mem.mp _),
simpa only [coeff_map, coe_map_ring_hom] using (polynomial.ext_iff.mp hp) n },
refine ring_hom.is_integral_tower_bot_of_is_integral _ _ (injective_quotient_le_comap_map P) _,
rw ← quotient_mk_maps_eq,
refine ring_hom.is_integral_trans _ _
((quotient.mk P').is_integral_of_surjective quotient.mk_surjective) _,
apply quotient_mk_comp_C_is_integral_of_jacobson' _ _ (λ x hx, _),
any_goals { exact ideal.is_jacobson_quotient },
{ exact or.rec_on (map_eq_top_or_is_maximal_of_surjective f hf hP)
(λ h, absurd (trans (h ▸ hPJ : P = comap f ⊤) comap_top : P = ⊤) hP.ne_top) id },
{ obtain ⟨z, rfl⟩ := quotient.mk_surjective x,
rwa [quotient.eq_zero_iff_mem, mem_comap, hPJ, mem_comap, coe_map_ring_hom, map_C] }
end
lemma is_maximal_comap_C_of_is_jacobson : (P.comap (C : R →+* polynomial R)).is_maximal :=
begin
rw [← @mk_ker _ _ P, ring_hom.ker_eq_comap_bot, comap_comap],
exact is_maximal_comap_of_is_integral_of_is_maximal' _
(quotient_mk_comp_C_is_integral_of_jacobson P) ⊥ ((bot_quotient_is_maximal_iff _).mpr hP),
end
omit P hP
lemma comp_C_integral_of_surjective_of_jacobson
{S : Type*} [field S] (f : (polynomial R) →+* S) (hf : function.surjective f) :
(f.comp C).is_integral :=
begin
haveI : (f.ker).is_maximal := @comap_is_maximal_of_surjective _ _ _ _ f ⊥ hf bot_is_maximal,
let g : f.ker.quotient →+* S := ideal.quotient.lift f.ker f (λ _ h, h),
have hfg : (g.comp (quotient.mk f.ker)) = f := ring_hom_ext' rfl rfl,
rw [← hfg, ring_hom.comp_assoc],
refine ring_hom.is_integral_trans _ g (quotient_mk_comp_C_is_integral_of_jacobson f.ker)
(g.is_integral_of_surjective _), --(quotient.lift_surjective f.ker f _ hf)),
rw [← hfg] at hf,
exact function.surjective.of_comp hf,
end
end integral_domain
end polynomial
namespace mv_polynomial
open mv_polynomial ring_hom
lemma is_jacobson_mv_polynomial_fin {R : Type*} [comm_ring R] [H : is_jacobson R] :
∀ (n : ℕ), is_jacobson (mv_polynomial (fin n) R)
| 0 := ((is_jacobson_iso ((rename_equiv R
(equiv.equiv_pempty (fin 0))).to_ring_equiv.trans (pempty_ring_equiv R))).mpr H)
| (n+1) := (is_jacobson_iso (fin_succ_equiv R n).to_ring_equiv).2
(polynomial.is_jacobson_polynomial_iff_is_jacobson.2 (is_jacobson_mv_polynomial_fin n))
/-- General form of the nullstellensatz for Jacobson rings, since in a Jacobson ring we have
`Inf {P maximal | P ≥ I} = Inf {P prime | P ≥ I} = I.radical`. Fields are always Jacobson,
and in that special case this is (most of) the classical Nullstellensatz,
since `I(V(I))` is the intersection of maximal ideals containing `I`, which is then `I.radical` -/
instance {R : Type*} [comm_ring R] {ι : Type*} [fintype ι] [is_jacobson R] :
is_jacobson (mv_polynomial ι R) :=
begin
haveI := classical.dec_eq ι,
let e := fintype.equiv_fin ι,
rw is_jacobson_iso (rename_equiv R e).to_ring_equiv,
exact is_jacobson_mv_polynomial_fin _
end
variables {n : ℕ}
lemma quotient_mk_comp_C_is_integral_of_jacobson {R : Type*} [integral_domain R] [is_jacobson R]
(P : ideal (mv_polynomial (fin n) R)) [P.is_maximal] :
((quotient.mk P).comp mv_polynomial.C : R →+* P.quotient).is_integral :=
begin
unfreezingI {induction n with n IH},
{ refine ring_hom.is_integral_of_surjective _ (function.surjective.comp quotient.mk_surjective _),
exact C_surjective (fin 0) },
{ rw [← fin_succ_equiv_comp_C_eq_C, ← ring_hom.comp_assoc, ← ring_hom.comp_assoc,
← quotient_map_comp_mk le_rfl, ring_hom.comp_assoc (polynomial.C),
← quotient_map_comp_mk le_rfl, ring_hom.comp_assoc, ring_hom.comp_assoc,
← quotient_map_comp_mk le_rfl, ← ring_hom.comp_assoc (quotient.mk _)],
refine ring_hom.is_integral_trans _ _ _ _,
{ refine ring_hom.is_integral_trans _ _ (is_integral_of_surjective _ quotient.mk_surjective) _,
refine ring_hom.is_integral_trans _ _ _ _,
{ apply (is_integral_quotient_map_iff _).mpr (IH _),
apply polynomial.is_maximal_comap_C_of_is_jacobson _,
{ exact mv_polynomial.is_jacobson_mv_polynomial_fin n },
{ apply comap_is_maximal_of_surjective,
exact (fin_succ_equiv R n).symm.surjective } },
{ refine (is_integral_quotient_map_iff _).mpr _,
rw ← quotient_map_comp_mk le_rfl,
refine ring_hom.is_integral_trans _ _ _ ((is_integral_quotient_map_iff _).mpr _),
{ exact ring_hom.is_integral_of_surjective _ quotient.mk_surjective },
{ apply polynomial.quotient_mk_comp_C_is_integral_of_jacobson _,
{ exact mv_polynomial.is_jacobson_mv_polynomial_fin n },
{ exact comap_is_maximal_of_surjective _ (fin_succ_equiv R n).symm.surjective } } } },
{ refine (is_integral_quotient_map_iff _).mpr _,
refine ring_hom.is_integral_trans _ _ _ (is_integral_of_surjective _ quotient.mk_surjective),
exact ring_hom.is_integral_of_surjective _ (fin_succ_equiv R n).symm.surjective } }
end
lemma comp_C_integral_of_surjective_of_jacobson {R : Type*} [integral_domain R] [is_jacobson R]
{σ : Type*} [fintype σ] {S : Type*} [field S] (f : mv_polynomial σ R →+* S)
(hf : function.surjective f) : (f.comp C).is_integral :=
begin
haveI := classical.dec_eq σ,
obtain ⟨e⟩ := fintype.trunc_equiv_fin σ,
let f' : mv_polynomial (fin _) R →+* S :=
f.comp (rename_equiv R e.symm).to_ring_equiv.to_ring_hom,
have hf' : function.surjective f' :=
((function.surjective.comp hf (rename_equiv R e.symm).surjective)),
have : (f'.comp C).is_integral,
{ haveI : (f'.ker).is_maximal := @comap_is_maximal_of_surjective _ _ _ _ f' ⊥ hf' bot_is_maximal,
let g : f'.ker.quotient →+* S := ideal.quotient.lift f'.ker f' (λ _ h, h),
have hfg : (g.comp (quotient.mk f'.ker)) = f' := ring_hom_ext (λ r, rfl) (λ i, rfl),
rw [← hfg, ring_hom.comp_assoc],
refine ring_hom.is_integral_trans _ g (quotient_mk_comp_C_is_integral_of_jacobson f'.ker)
(g.is_integral_of_surjective _),
rw ← hfg at hf',
exact function.surjective.of_comp hf' },
rw ring_hom.comp_assoc at this,
convert this,
refine ring_hom.ext (λ x, _),
exact ((rename_equiv R e.symm).commutes' x).symm,
end
end mv_polynomial
end ideal
|
cb84cf9aa7602336936e0d802bb7fec63b131a98
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/analysis/normed_space/units.lean
|
e766f2ff6a3d84d9e2c0e2d1855b10f89010cbd4
|
[
"Apache-2.0"
] |
permissive
|
Lix0120/mathlib
|
0020745240315ed0e517cbf32e738d8f9811dd80
|
e14c37827456fc6707f31b4d1d16f1f3a3205e91
|
refs/heads/master
| 1,673,102,855,024
| 1,604,151,044,000
| 1,604,151,044,000
| 308,930,245
| 0
| 0
|
Apache-2.0
| 1,604,164,710,000
| 1,604,163,547,000
| null |
UTF-8
|
Lean
| false
| false
| 11,030
|
lean
|
/-
Copyright (c) 2020 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import analysis.specific_limits
import analysis.asymptotics
/-!
# The group of units of a complete normed ring
This file contains the basic theory for the group of units (invertible elements) of a complete
normed ring (Banach algebras being a notable special case).
## Main results
The constructions `one_sub`, `add` and `unit_of_nearby` state, in varying forms, that perturbations
of a unit are units. The latter two are not stated in their optimal form; more precise versions
would use the spectral radius.
The first main result is `is_open`: the group of units of a complete normed ring is an open subset
of the ring.
The function `inverse` (defined in `algebra.ring`), for a ring `R`, sends `a : R` to `a⁻¹` if `a` is
a unit and 0 if not. The other major results of this file (notably `inverse_add`,
`inverse_add_norm` and `inverse_add_norm_diff_nth_order`) cover the asymptotic properties of
`inverse (x + t)` as `t → 0`.
-/
noncomputable theory
open_locale topological_space
variables {R : Type*} [normed_ring R] [complete_space R]
namespace units
/-- In a complete normed ring, a perturbation of `1` by an element `t` of distance less than `1`
from `1` is a unit. Here we construct its `units` structure. -/
def one_sub (t : R) (h : ∥t∥ < 1) : units R :=
{ val := 1 - t,
inv := ∑' (n : ℕ), t ^ n,
val_inv := mul_neg_geom_series t h,
inv_val := geom_series_mul_neg t h }
@[simp] lemma one_sub_coe (t : R) (h : ∥t∥ < 1) : ↑(one_sub t h) = 1 - t := rfl
/-- In a complete normed ring, a perturbation of a unit `x` by an element `t` of distance less than
`∥x⁻¹∥⁻¹` from `x` is a unit. Here we construct its `units` structure. -/
def add (x : units R) (t : R) (h : ∥t∥ < ∥(↑x⁻¹ : R)∥⁻¹) : units R :=
x * (units.one_sub (-(↑x⁻¹ * t))
begin
nontriviality R using [zero_lt_one],
have hpos : 0 < ∥(↑x⁻¹ : R)∥ := units.norm_pos x⁻¹,
calc ∥-(↑x⁻¹ * t)∥
= ∥↑x⁻¹ * t∥ : by { rw norm_neg }
... ≤ ∥(↑x⁻¹ : R)∥ * ∥t∥ : norm_mul_le x.inv _
... < ∥(↑x⁻¹ : R)∥ * ∥(↑x⁻¹ : R)∥⁻¹ : by nlinarith only [h, hpos]
... = 1 : mul_inv_cancel (ne_of_gt hpos)
end)
@[simp] lemma add_coe (x : units R) (t : R) (h : ∥t∥ < ∥(↑x⁻¹ : R)∥⁻¹) :
((x.add t h) : R) = x + t := by { unfold units.add, simp [mul_add] }
/-- In a complete normed ring, an element `y` of distance less than `∥x⁻¹∥⁻¹` from `x` is a unit.
Here we construct its `units` structure. -/
def unit_of_nearby (x : units R) (y : R) (h : ∥y - x∥ < ∥(↑x⁻¹ : R)∥⁻¹) : units R :=
x.add ((y : R) - x) h
@[simp] lemma unit_of_nearby_coe (x : units R) (y : R) (h : ∥y - x∥ < ∥(↑x⁻¹ : R)∥⁻¹) :
↑(x.unit_of_nearby y h) = y := by { unfold units.unit_of_nearby, simp }
/-- The group of units of a complete normed ring is an open subset of the ring. -/
lemma is_open : is_open {x : R | is_unit x} :=
begin
nontriviality R,
apply metric.is_open_iff.mpr,
rintros x' ⟨x, h⟩,
refine ⟨∥(↑x⁻¹ : R)∥⁻¹, inv_pos.mpr (units.norm_pos x⁻¹), _⟩,
intros y hy,
rw [metric.mem_ball, dist_eq_norm, ←h] at hy,
use x.unit_of_nearby y hy,
simp
end
lemma nhds (x : units R) : {x : R | is_unit x} ∈ 𝓝 (x : R) :=
mem_nhds_sets is_open (by { rw [set.mem_set_of_eq], exact is_unit_unit x })
end units
namespace normed_ring
open_locale classical big_operators
open asymptotics filter metric finset ring
lemma inverse_one_sub (t : R) (h : ∥t∥ < 1) : inverse (1 - t) = ↑(units.one_sub t h)⁻¹ :=
begin
rw ← inverse_unit (units.one_sub t h),
refl,
end
/-- The formula `inverse (x + t) = inverse (1 + x⁻¹ * t) * x⁻¹` holds for `t` sufficiently small. -/
lemma inverse_add (x : units R) :
∀ᶠ t in (𝓝 0), inverse ((x : R) + t) = inverse (1 + ↑x⁻¹ * t) * ↑x⁻¹ :=
begin
nontriviality R,
rw [eventually_iff, mem_nhds_iff],
have hinv : 0 < ∥(↑x⁻¹ : R)∥⁻¹, by cancel_denoms,
use [∥(↑x⁻¹ : R)∥⁻¹, hinv],
intros t ht,
simp only [mem_ball, dist_zero_right] at ht,
have ht' : ∥-↑x⁻¹ * t∥ < 1,
{ refine lt_of_le_of_lt (norm_mul_le _ _) _,
rw norm_neg,
refine lt_of_lt_of_le (mul_lt_mul_of_pos_left ht x⁻¹.norm_pos) _,
cancel_denoms },
have hright := inverse_one_sub (-↑x⁻¹ * t) ht',
have hleft := inverse_unit (x.add t ht),
simp only [← neg_mul_eq_neg_mul, sub_neg_eq_add] at hright,
simp only [units.add_coe] at hleft,
simp [hleft, hright, units.add]
end
lemma inverse_one_sub_nth_order (n : ℕ) :
∀ᶠ t in (𝓝 0), inverse ((1:R) - t) = (∑ i in range n, t ^ i) + (t ^ n) * inverse (1 - t) :=
begin
simp only [eventually_iff, mem_nhds_iff],
use [1, by norm_num],
intros t ht,
simp only [mem_ball, dist_zero_right] at ht,
simp only [inverse_one_sub t ht, set.mem_set_of_eq],
have h : 1 = ((range n).sum (λ i, t ^ i)) * (units.one_sub t ht) + t ^ n,
{ simp only [units.one_sub_coe],
rw [← geom_series, geom_sum_mul_neg],
simp },
rw [← one_mul ↑(units.one_sub t ht)⁻¹, h, add_mul],
congr,
{ rw [mul_assoc, (units.one_sub t ht).mul_inv],
simp },
{ simp only [units.one_sub_coe],
rw [← add_mul, ← geom_series, geom_sum_mul_neg],
simp }
end
/-- The formula
`inverse (x + t) = (∑ i in range n, (- x⁻¹ * t) ^ i) * x⁻¹ + (- x⁻¹ * t) ^ n * inverse (x + t)`
holds for `t` sufficiently small. -/
lemma inverse_add_nth_order (x : units R) (n : ℕ) :
∀ᶠ t in (𝓝 0), inverse ((x : R) + t)
= (∑ i in range n, (- ↑x⁻¹ * t) ^ i) * ↑x⁻¹ + (- ↑x⁻¹ * t) ^ n * inverse (x + t) :=
begin
refine (inverse_add x).mp _,
have hzero : tendsto (λ (t : R), - ↑x⁻¹ * t) (𝓝 0) (𝓝 0),
{ convert ((mul_left_continuous (- (↑x⁻¹ : R))).tendsto 0).comp tendsto_id,
simp },
refine (hzero.eventually (inverse_one_sub_nth_order n)).mp (eventually_of_forall _),
simp only [neg_mul_eq_neg_mul_symm, sub_neg_eq_add],
intros t h1 h2,
have h := congr_arg (λ (a : R), a * ↑x⁻¹) h1,
dsimp at h,
convert h,
rw [add_mul, mul_assoc],
simp [h2.symm]
end
lemma inverse_one_sub_norm : is_O (λ t, inverse ((1:R) - t)) (λ t, (1:ℝ)) (𝓝 (0:R)) :=
begin
simp only [is_O, is_O_with, eventually_iff, mem_nhds_iff],
refine ⟨∥(1:R)∥ + 1, (2:ℝ)⁻¹, by norm_num, _⟩,
intros t ht,
simp only [ball, dist_zero_right, set.mem_set_of_eq] at ht,
have ht' : ∥t∥ < 1,
{ have : (2:ℝ)⁻¹ < 1 := by cancel_denoms,
linarith },
simp only [inverse_one_sub t ht', norm_one, mul_one, set.mem_set_of_eq],
change ∥(∑' (n : ℕ), t ^ n)∥ ≤ _,
have := normed_ring.tsum_geometric_of_norm_lt_1 t ht',
have : (1 - ∥t∥)⁻¹ ≤ 2,
{ rw ← inv_inv' (2:ℝ),
refine inv_le_inv_of_le (by norm_num) _,
have : (2:ℝ)⁻¹ + (2:ℝ)⁻¹ = 1 := by ring,
linarith },
linarith
end
/-- The function `λ t, inverse (x + t)` is O(1) as `t → 0`. -/
lemma inverse_add_norm (x : units R) : is_O (λ t, inverse (↑x + t)) (λ t, (1:ℝ)) (𝓝 (0:R)) :=
begin
nontriviality R,
simp only [is_O_iff, norm_one, mul_one],
cases is_O_iff.mp (@inverse_one_sub_norm R _ _) with C hC,
use C * ∥((x⁻¹:units R):R)∥,
have hzero : tendsto (λ t, - (↑x⁻¹ : R) * t) (𝓝 0) (𝓝 0),
{ convert ((mul_left_continuous (-↑x⁻¹ : R)).tendsto 0).comp tendsto_id,
simp },
refine (inverse_add x).mp ((hzero.eventually hC).mp (eventually_of_forall _)),
intros t bound iden,
rw iden,
simp at bound,
have hmul := norm_mul_le (inverse (1 + ↑x⁻¹ * t)) ↑x⁻¹,
nlinarith [norm_nonneg (↑x⁻¹ : R)]
end
/-- The function
`λ t, inverse (x + t) - (∑ i in range n, (- x⁻¹ * t) ^ i) * x⁻¹`
is `O(t ^ n)` as `t → 0`. -/
lemma inverse_add_norm_diff_nth_order (x : units R) (n : ℕ) :
is_O (λ (t : R), inverse (↑x + t) - (∑ i in range n, (- ↑x⁻¹ * t) ^ i) * ↑x⁻¹)
(λ t, ∥t∥ ^ n) (𝓝 (0:R)) :=
begin
by_cases h : n = 0,
{ simpa [h] using inverse_add_norm x },
have hn : 0 < n := nat.pos_of_ne_zero h,
simp [is_O_iff],
cases (is_O_iff.mp (inverse_add_norm x)) with C hC,
use C * ∥(1:ℝ)∥ * ∥(↑x⁻¹ : R)∥ ^ n,
have h : eventually_eq (𝓝 (0:R))
(λ t, inverse (↑x + t) - (∑ i in range n, (- ↑x⁻¹ * t) ^ i) * ↑x⁻¹)
(λ t, ((- ↑x⁻¹ * t) ^ n) * inverse (x + t)),
{ refine (inverse_add_nth_order x n).mp (eventually_of_forall _),
intros t ht,
convert congr_arg (λ a, a - (range n).sum (pow (-↑x⁻¹ * t)) * ↑x⁻¹) ht,
simp },
refine h.mp (hC.mp (eventually_of_forall _)),
intros t _ hLHS,
simp only [neg_mul_eq_neg_mul_symm] at hLHS,
rw hLHS,
refine le_trans (norm_mul_le _ _ ) _,
have h' : ∥(-(↑x⁻¹ * t)) ^ n∥ ≤ ∥(↑x⁻¹ : R)∥ ^ n * ∥t∥ ^ n,
{ calc ∥(-(↑x⁻¹ * t)) ^ n∥ ≤ ∥(-(↑x⁻¹ * t))∥ ^ n : norm_pow_le' _ hn
... = ∥↑x⁻¹ * t∥ ^ n : by rw norm_neg
... ≤ (∥(↑x⁻¹ : R)∥ * ∥t∥) ^ n : _
... = ∥(↑x⁻¹ : R)∥ ^ n * ∥t∥ ^ n : mul_pow _ _ n,
exact pow_le_pow_of_le_left (norm_nonneg _) (norm_mul_le ↑x⁻¹ t) n },
have h'' : 0 ≤ ∥(↑x⁻¹ : R)∥ ^ n * ∥t∥ ^ n,
{ refine mul_nonneg _ _;
exact pow_nonneg (norm_nonneg _) n },
nlinarith [norm_nonneg (inverse (↑x + t))],
end
/-- The function `λ t, inverse (x + t) - x⁻¹` is `O(t)` as `t → 0`. -/
lemma inverse_add_norm_diff_first_order (x : units R) :
is_O (λ t, inverse (↑x + t) - ↑x⁻¹) (λ t, ∥t∥) (𝓝 (0:R)) :=
by { convert inverse_add_norm_diff_nth_order x 1; simp }
/-- The function
`λ t, inverse (x + t) - x⁻¹ + x⁻¹ * t * x⁻¹`
is `O(t ^ 2)` as `t → 0`. -/
lemma inverse_add_norm_diff_second_order (x : units R) :
is_O (λ t, inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) (λ t, ∥t∥ ^ 2) (𝓝 (0:R)) :=
begin
convert inverse_add_norm_diff_nth_order x 2,
ext t,
simp only [range_succ, range_one, sum_insert, mem_singleton, sum_singleton, not_false_iff,
one_ne_zero, pow_zero, add_mul],
abel,
simp
end
/-- The function `inverse` is continuous at each unit of `R`. -/
lemma inverse_continuous_at (x : units R) : continuous_at inverse (x : R) :=
begin
have h_is_o : is_o (λ (t : R), ∥inverse (↑x + t) - ↑x⁻¹∥) (λ (t : R), (1:ℝ)) (𝓝 0),
{ refine is_o_norm_left.mpr ((inverse_add_norm_diff_first_order x).trans_is_o _),
exact is_o_norm_left.mpr (is_o_id_const one_ne_zero) },
have h_lim : tendsto (λ (y:R), y - x) (𝓝 x) (𝓝 0),
{ refine tendsto_zero_iff_norm_tendsto_zero.mpr _,
exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },
simp only [continuous_at],
rw [tendsto_iff_norm_tendsto_zero, inverse_unit],
convert h_is_o.tendsto_0.comp h_lim,
ext, simp
end
end normed_ring
|
48ca270bd35280f1635ca172a1ee5d0bac8c68db
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/algebra/hom/aut.lean
|
5ab45565bf26f6bb743c85d0a4eae37fd9194bb7
|
[
"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
| 7,327
|
lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov
-/
import group_theory.perm.basic
/-!
# Multiplicative and additive group automorphisms
This file defines the automorphism group structure on `add_aut R := add_equiv R R` and
`mul_aut R := mul_equiv R R`.
## Implementation notes
The definition of multiplication in the automorphism groups agrees with function composition,
multiplication in `equiv.perm`, and multiplication in `category_theory.End`, but not with
`category_theory.comp`.
This file is kept separate from `data/equiv/mul_add` so that `group_theory.perm` is free to use
equivalences (and other files that use them) before the group structure is defined.
## Tags
mul_aut, add_aut
-/
variables {A : Type*} {M : Type*} {G : Type*}
/-- The group of multiplicative automorphisms. -/
@[reducible, to_additive "The group of additive automorphisms."]
def mul_aut (M : Type*) [has_mul M] := M ≃* M
namespace mul_aut
variables (M) [has_mul M]
/--
The group operation on multiplicative automorphisms is defined by
`λ g h, mul_equiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance : group (mul_aut M) :=
by refine_struct
{ mul := λ g h, mul_equiv.trans h g,
one := mul_equiv.refl M,
inv := mul_equiv.symm,
div := _,
npow := @npow_rec _ ⟨mul_equiv.refl M⟩ ⟨λ g h, mul_equiv.trans h g⟩,
zpow := @zpow_rec _ ⟨mul_equiv.refl M⟩ ⟨λ g h, mul_equiv.trans h g⟩ ⟨mul_equiv.symm⟩ };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (mul_aut M) := ⟨1⟩
@[simp] lemma coe_mul (e₁ e₂ : mul_aut M) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl
@[simp] lemma coe_one : ⇑(1 : mul_aut M) = id := rfl
lemma mul_def (e₁ e₂ : mul_aut M) : e₁ * e₂ = e₂.trans e₁ := rfl
lemma one_def : (1 : mul_aut M) = mul_equiv.refl _ := rfl
lemma inv_def (e₁ : mul_aut M) : e₁⁻¹ = e₁.symm := rfl
@[simp] lemma mul_apply (e₁ e₂ : mul_aut M) (m : M) : (e₁ * e₂) m = e₁ (e₂ m) := rfl
@[simp] lemma one_apply (m : M) : (1 : mul_aut M) m = m := rfl
@[simp] lemma apply_inv_self (e : mul_aut M) (m : M) : e (e⁻¹ m) = m :=
mul_equiv.apply_symm_apply _ _
@[simp] lemma inv_apply_self (e : mul_aut M) (m : M) : e⁻¹ (e m) = m :=
mul_equiv.apply_symm_apply _ _
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def to_perm : mul_aut M →* equiv.perm M :=
by refine_struct { to_fun := mul_equiv.to_equiv }; intros; refl
/-- The tautological action by `mul_aut M` on `M`.
This generalizes `function.End.apply_mul_action`. -/
instance apply_mul_distrib_mul_action {M} [monoid M] : mul_distrib_mul_action (mul_aut M) M :=
{ smul := ($),
one_smul := λ _, rfl,
mul_smul := λ _ _ _, rfl,
smul_one := mul_equiv.map_one,
smul_mul := mul_equiv.map_mul }
@[simp] protected lemma smul_def {M} [monoid M] (f : mul_aut M) (a : M) : f • a = f a := rfl
/-- `mul_aut.apply_mul_action` is faithful. -/
instance apply_has_faithful_scalar {M} [monoid M] : has_faithful_scalar (mul_aut M) M :=
⟨λ _ _, mul_equiv.ext⟩
/-- Group conjugation, `mul_aut.conj g h = g * h * g⁻¹`, as a monoid homomorphism
mapping multiplication in `G` into multiplication in the automorphism group `mul_aut G`.
See also the type `conj_act G` for any group `G`, which has a `mul_action (conj_act G) G` instance
where `conj G` acts on `G` by conjugation. -/
def conj [group G] : G →* mul_aut G :=
{ to_fun := λ g,
{ to_fun := λ h, g * h * g⁻¹,
inv_fun := λ h, g⁻¹ * h * g,
left_inv := λ _, by simp [mul_assoc],
right_inv := λ _, by simp [mul_assoc],
map_mul' := by simp [mul_assoc] },
map_mul' := λ _ _, by ext; simp [mul_assoc],
map_one' := by ext; simp [mul_assoc] }
@[simp] lemma conj_apply [group G] (g h : G) : conj g h = g * h * g⁻¹ := rfl
@[simp] lemma conj_symm_apply [group G] (g h : G) : (conj g).symm h = g⁻¹ * h * g := rfl
@[simp] lemma conj_inv_apply [group G] (g h : G) : (conj g)⁻¹ h = g⁻¹ * h * g := rfl
end mul_aut
namespace add_aut
variables (A) [has_add A]
/--
The group operation on additive automorphisms is defined by
`λ g h, add_equiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance group : group (add_aut A) :=
by refine_struct
{ mul := λ g h, add_equiv.trans h g,
one := add_equiv.refl A,
inv := add_equiv.symm,
div := _,
npow := @npow_rec _ ⟨add_equiv.refl A⟩ ⟨λ g h, add_equiv.trans h g⟩,
zpow := @zpow_rec _ ⟨add_equiv.refl A⟩ ⟨λ g h, add_equiv.trans h g⟩ ⟨add_equiv.symm⟩ };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (add_aut A) := ⟨1⟩
@[simp] lemma coe_mul (e₁ e₂ : add_aut A) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl
@[simp] lemma coe_one : ⇑(1 : add_aut A) = id := rfl
lemma mul_def (e₁ e₂ : add_aut A) : e₁ * e₂ = e₂.trans e₁ := rfl
lemma one_def : (1 : add_aut A) = add_equiv.refl _ := rfl
lemma inv_def (e₁ : add_aut A) : e₁⁻¹ = e₁.symm := rfl
@[simp] lemma mul_apply (e₁ e₂ : add_aut A) (a : A) : (e₁ * e₂) a = e₁ (e₂ a) := rfl
@[simp] lemma one_apply (a : A) : (1 : add_aut A) a = a := rfl
@[simp] lemma apply_inv_self (e : add_aut A) (a : A) : e⁻¹ (e a) = a :=
add_equiv.apply_symm_apply _ _
@[simp] lemma inv_apply_self (e : add_aut A) (a : A) : e (e⁻¹ a) = a :=
add_equiv.apply_symm_apply _ _
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def to_perm : add_aut A →* equiv.perm A :=
by refine_struct { to_fun := add_equiv.to_equiv }; intros; refl
/-- The tautological action by `add_aut A` on `A`.
This generalizes `function.End.apply_mul_action`. -/
instance apply_distrib_mul_action {A} [add_monoid A] : distrib_mul_action (add_aut A) A :=
{ smul := ($),
smul_zero := add_equiv.map_zero,
smul_add := add_equiv.map_add,
one_smul := λ _, rfl,
mul_smul := λ _ _ _, rfl }
@[simp] protected lemma smul_def {A} [add_monoid A] (f : add_aut A) (a : A) : f • a = f a := rfl
/-- `add_aut.apply_distrib_mul_action` is faithful. -/
instance apply_has_faithful_scalar {A} [add_monoid A] : has_faithful_scalar (add_aut A) A :=
⟨λ _ _, add_equiv.ext⟩
/-- Additive group conjugation, `add_aut.conj g h = g + h - g`, as an additive monoid
homomorphism mapping addition in `G` into multiplication in the automorphism group `add_aut G`
(written additively in order to define the map). -/
def conj [add_group G] : G →+ additive (add_aut G) :=
{ to_fun := λ g, @additive.of_mul (add_aut G)
{ to_fun := λ h, g + h + -g, -- this definition is chosen to match `mul_aut.conj`
inv_fun := λ h, -g + h + g,
left_inv := λ _, by simp [add_assoc],
right_inv := λ _, by simp [add_assoc],
map_add' := by simp [add_assoc] },
map_add' := λ _ _, by apply additive.to_mul.injective; ext; simp [add_assoc],
map_zero' := by ext; simpa }
@[simp] lemma conj_apply [add_group G] (g h : G) : conj g h = g + h + -g := rfl
@[simp] lemma conj_symm_apply [add_group G] (g h : G) : (conj g).symm h = -g + h + g := rfl
@[simp] lemma conj_inv_apply [add_group G] (g h : G) : (-(conj g)) h = -g + h + g := rfl
end add_aut
|
6855be5dd7fd0b9f85f321141dd7c6f26fca55ea
|
675b8263050a5d74b89ceab381ac81ce70535688
|
/src/ring_theory/multiplicity.lean
|
131c085f698248bffaf40f6cbf68af3db388e15d
|
[
"Apache-2.0"
] |
permissive
|
vozor/mathlib
|
5921f55235ff60c05f4a48a90d616ea167068adf
|
f7e728ad8a6ebf90291df2a4d2f9255a6576b529
|
refs/heads/master
| 1,675,607,702,231
| 1,609,023,279,000
| 1,609,023,279,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 17,457
|
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
theorem nat.find_le {p q : ℕ → Prop} [decidable_pred p] [decidable_pred q]
(h : ∀ n, q n → p n) (hp : ∃ n, p n) (hq : ∃ n, q n) :
nat.find hp ≤ nat.find hq :=
nat.find_min' _ ((h _) (nat.find_spec hq))
/-- `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 :=
⟨∃ n : ℕ, ¬a ^ (n + 1) ∣ b, λ h, nat.find h⟩
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, have finite a b, from enat.dom_of_le_some (le_of_lt hm),
by rw [← enat.coe_get (finite_iff_dom.1 this), enat.coe_lt_coe] at hm;
exact nat.find_spec this (dvd.trans (pow_dvd_pow _ hm) 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.coe_get (finite_iff_dom.1 this), enat.coe_le_coe];
exact 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 conv_lhs {rw ← enat.coe_get h₁ }; rw [enat.coe_lt_coe]; exact 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 :=
⟨λ h n, nat.cases_on n (one_dvd _)
(λ n, by_contradiction (not_exists.1 (eq_none_iff'.1 h) n : _)),
λ h, eq_none_iff.2 (λ n ⟨⟨_, h₁⟩, _⟩, h₁ (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, 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 _))
-- TODO: What happened here? Do we still need both this one and a `nat.` version?
(by exact _root_.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 [← le_zero_iff_eq, ← 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
|
74c18264f12b55911ed2d91e70956f0f759dd164
|
ad0c7d243dc1bd563419e2767ed42fb323d7beea
|
/group_theory/perm.lean
|
4fd3b855a8e96e4e64e387d5b7a8567b2c80cc51
|
[
"Apache-2.0"
] |
permissive
|
sebzim4500/mathlib
|
e0b5a63b1655f910dee30badf09bd7e191d3cf30
|
6997cafbd3a7325af5cb318561768c316ceb7757
|
refs/heads/master
| 1,585,549,958,618
| 1,538,221,723,000
| 1,538,221,723,000
| 150,869,076
| 0
| 0
|
Apache-2.0
| 1,538,229,323,000
| 1,538,229,323,000
| null |
UTF-8
|
Lean
| false
| false
| 28,622
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.fintype
universes u v
open equiv function fintype finset
variables {α : Type u} {β : Type v}
namespace equiv.perm
def subtype_perm (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} :=
⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩,
λ _, by simp, λ _, by simp⟩
def of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) : perm α :=
⟨λ x, if h : p x then f ⟨x, h⟩ else x, λ x, if h : p x then f⁻¹ ⟨x, h⟩ else x,
λ x, have h : ∀ h : p x, p (f ⟨x, h⟩), from λ h, (f ⟨x, h⟩).2,
by simp; split_ifs at *; simp * at *,
λ x, have h : ∀ h : p x, p (f⁻¹ ⟨x, h⟩), from λ h, (f⁻¹ ⟨x, h⟩).2,
by simp; split_ifs at *; simp * at *⟩
instance of_subtype.is_group_hom {p : α → Prop} [decidable_pred p] : is_group_hom (@of_subtype α p _) :=
⟨λ f g, equiv.ext _ _ $ λ x, begin
rw [of_subtype, of_subtype, of_subtype],
by_cases h : p x,
{ have h₁ : p (f (g ⟨x, h⟩)), from (f (g ⟨x, h⟩)).2,
have h₂ : p (g ⟨x, h⟩), from (g ⟨x, h⟩).2,
simp [h, h₁, h₂] },
{ simp [h] }
end⟩
lemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y :=
by conv {to_lhs, rw [← injective.eq_iff f.bijective.1, apply_inv_self]}
lemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y :=
by rw [eq_comm, eq_inv_iff_eq, eq_comm]
def is_cycle (f : perm α) := ∃ x, f x ≠ x ∧ ∀ y, f y ≠ y → ∃ i : ℤ, (f ^ i) x = y
lemma exists_int_pow_eq_of_is_cycle {f : perm α} (hf : is_cycle f) {x y : α}
(hx : f x ≠ x) (hy : f y ≠ y) : ∃ i : ℤ, (f ^ i) x = y :=
let ⟨g, hg⟩ := hf in
let ⟨a, ha⟩ := hg.2 x hx in
let ⟨b, hb⟩ := hg.2 y hy in
⟨b - a, by rw [← ha, ← mul_apply, ← gpow_add, sub_add_cancel, hb]⟩
lemma of_subtype_subtype_perm {f : perm α} {p : α → Prop} [decidable_pred p] (h₁ : ∀ x, p x ↔ p (f x))
(h₂ : ∀ x, f x ≠ x → p x) : of_subtype (subtype_perm f h₁) = f :=
equiv.ext _ _ $ λ x, begin
rw [of_subtype, subtype_perm],
by_cases hx : p x,
{ simp [hx] },
{ haveI := classical.prop_decidable,
simp [hx, not_not.1 (mt (h₂ x) hx)] }
end
lemma of_subtype_apply_of_not_mem {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) {x : α} (hx : ¬ p x) :
of_subtype f x = x := dif_neg hx
lemma mem_iff_of_subtype_apply_mem {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) (x : α) :
p x ↔ p ((of_subtype f : α → α) x) :=
if h : p x then by dsimp [of_subtype]; simpa [h] using (f ⟨x, h⟩).2
else by simp [h, of_subtype_apply_of_not_mem f h]
@[simp] lemma subtype_perm_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) :
subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f :=
equiv.ext _ _ $ λ ⟨x, hx⟩, by dsimp [subtype_perm, of_subtype]; simp [show p x, from hx]
lemma pow_apply_eq_of_apply_apply_eq_self_nat {f : perm α} {x : α} (hffx : f (f x) = x) :
∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x
| 0 := or.inl rfl
| (n+1) := (pow_apply_eq_of_apply_apply_eq_self_nat n).elim
(λ h, or.inr (by rw [pow_succ, mul_apply, h]))
(λ h, or.inl (by rw [pow_succ, mul_apply, h, hffx]))
lemma pow_apply_eq_of_apply_apply_eq_self_int {f : perm α} {x : α} (hffx : f (f x) = x) :
∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x
| (n : ℕ) := pow_apply_eq_of_apply_apply_eq_self_nat hffx n
| -[1+ n] :=
by rw [gpow_neg_succ, inv_eq_iff_eq, ← injective.eq_iff f.bijective.1, ← mul_apply, ← pow_succ,
eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ', @eq_comm _ x, or.comm];
exact pow_apply_eq_of_apply_apply_eq_self_nat hffx _
variable [decidable_eq α]
def support [fintype α] (f : perm α) := univ.filter (λ x, f x ≠ x)
@[simp] lemma mem_support [fintype α] {f : perm α} {x : α} : x ∈ f.support ↔ f x ≠ x :=
by simp [support]
def is_swap (f : perm α) := ∃ x y, x ≠ y ∧ f = swap x y
lemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) :=
equiv.ext _ _ $ λ z, begin
simp [mul_apply, swap_apply_def],
split_ifs;
simp [*, eq_inv_iff_eq] at * <|> cc
end
lemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f :=
by rw [swap_mul_eq_mul_swap, inv_apply_self, inv_apply_self]
lemma is_swap_of_subtype {p : α → Prop} [decidable_pred p]
{f : perm (subtype p)} (h : is_swap f) : is_swap (of_subtype f) :=
let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h in
⟨x, y, by simp at hxy; tauto,
equiv.ext _ _ $ λ z, begin
rw [hxy.2, of_subtype],
simp [swap_apply_def],
split_ifs;
cc <|> simp * at *
end⟩
lemma support_swap_mul {f : perm α} {x : α}
{y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x :=
begin
simp only [swap_apply_def, mul_apply, injective.eq_iff f.bijective.1] at *,
by_cases h : f y = x,
{ split; intro; simp * at * },
{ split_ifs at hy; cc }
end
def swap_factors_aux : Π (l : list α) (f : perm α), (∀ {x}, f x ≠ x → x ∈ l) →
{l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g}
| [] := λ f h, ⟨[], equiv.ext _ _ $ λ x, by rw [list.prod_nil];
exact eq.symm (not_not.1 (mt h (list.not_mem_nil _))), by simp⟩
| (x :: l) := λ f h,
if hfx : x = f x
then swap_factors_aux l f
(λ y hy, list.mem_of_ne_of_mem (λ h : y = x, by simpa [h, hfx.symm] using hy) (h hy))
else let m := swap_factors_aux l (swap x (f x) * f)
(λ y hy, have f y ≠ y ∧ y ≠ x, from support_swap_mul hy,
list.mem_of_ne_of_mem this.2 (h this.1)) in
⟨swap x (f x) :: m.1,
by rw [list.prod_cons, m.2.1, ← mul_assoc,
mul_def (swap x (f x)), swap_swap, ← one_def, one_mul],
λ g hg, ((list.mem_cons_iff _ _ _).1 hg).elim (λ h, ⟨x, f x, hfx, h⟩) (m.2.2 _)⟩
/-- `swap_factors` represents a permutation as a product of a list of transpositions.
The representation is non unique and depends on the linear order structure.
For types without linear order `trunc_swap_factors` can be used -/
def swap_factors [fintype α] [decidable_linear_order α] (f : perm α) :
{l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} :=
swap_factors_aux ((@univ α _).sort (≤)) f (λ _ _, (mem_sort _).2 (mem_univ _))
def trunc_swap_factors [fintype α] (f : perm α) :
trunc {l : list (perm α) // l.prod = f ∧ ∀ g ∈ l, is_swap g} :=
quotient.rec_on_subsingleton (@univ α _).1
(λ l h, trunc.mk (swap_factors_aux l f h))
(show ∀ x, f x ≠ x → x ∈ (@univ α _).1, from λ _ _, mem_univ _)
lemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) :
swap y z * swap x y * swap y z = swap z x :=
equiv.ext _ _ $ λ n, by simp only [swap_apply_def, mul_apply]; split_ifs; cc
lemma is_conj_swap {w x y z : α} (hwx : w ≠ x) (hyz : y ≠ z) : is_conj (swap w x) (swap y z) :=
have h : ∀ {y z : α}, y ≠ z → w ≠ z →
(swap w y * swap x z) * swap w x * (swap w y * swap x z)⁻¹ = swap y z :=
λ y z hyz hwz, by rw [mul_inv_rev, swap_inv, swap_inv, mul_assoc (swap w y),
mul_assoc (swap w y), ← mul_assoc _ (swap x z), swap_mul_swap_mul_swap hwx hwz,
← mul_assoc, swap_mul_swap_mul_swap hwz.symm hyz.symm],
if hwz : w = z
then have hwy : w ≠ y, by cc,
⟨swap w z * swap x y, by rw [swap_comm y z, h hyz.symm hwy]⟩
else ⟨swap w y * swap x z, h hyz hwz⟩
/-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/
def fin_pairs_lt (n : ℕ) : finset (Σ a : fin n, fin n) :=
(univ : finset (fin n)).sigma (λ a, (range a.1).attach_fin
(λ m hm, lt_trans (mem_range.1 hm) a.2))
lemma mem_fin_pairs_lt {n : ℕ} {a : Σ a : fin n, fin n} :
a ∈ fin_pairs_lt n ↔ a.2 < a.1 :=
by simp [fin_pairs_lt, fin.lt_def]
def sign_aux {n : ℕ} (a : perm (fin n)) : units ℤ :=
(fin_pairs_lt n).prod (λ x, if a x.1 ≤ a x.2 then -1 else 1)
@[simp] lemma sign_aux_one (n : ℕ) : sign_aux (1 : perm (fin n)) = 1 :=
begin
unfold sign_aux,
conv { to_rhs, rw ← @finset.prod_const_one _ (units ℤ)
(fin_pairs_lt n) },
exact finset.prod_congr rfl (λ a ha, if_neg
(not_le_of_gt (mem_fin_pairs_lt.1 ha)))
end
def sign_bij_aux {n : ℕ} (f : perm (fin n)) (a : Σ a : fin n, fin n) :
Σ a : fin n, fin n :=
if hxa : f a.2 < f a.1 then ⟨f a.1, f a.2⟩ else ⟨f a.2, f a.1⟩
lemma sign_bij_aux_inj {n : ℕ} {f : perm (fin n)} : ∀ a b : Σ a : fin n, fin n,
a ∈ fin_pairs_lt n → b ∈ fin_pairs_lt n →
sign_bij_aux f a = sign_bij_aux f b → a = b :=
λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ha hb h, begin
unfold sign_bij_aux at h,
rw mem_fin_pairs_lt at *,
have : ¬b₁ < b₂ := not_lt_of_ge (le_of_lt hb),
split_ifs at h;
simp [*, injective.eq_iff f.bijective.1, sigma.mk.inj_eq] at *
end
lemma sign_bij_aux_surj {n : ℕ} {f : perm (fin n)} : ∀ a ∈ fin_pairs_lt n,
∃ b ∈ fin_pairs_lt n, a = sign_bij_aux f b :=
λ ⟨a₁, a₂⟩ ha,
if hxa : f⁻¹ a₂ < f⁻¹ a₁
then ⟨⟨f⁻¹ a₁, f⁻¹ a₂⟩, mem_fin_pairs_lt.2 hxa,
by dsimp [sign_bij_aux];
rw [apply_inv_self, apply_inv_self, dif_pos (mem_fin_pairs_lt.1 ha)]⟩
else ⟨⟨f⁻¹ a₂, f⁻¹ a₁⟩, mem_fin_pairs_lt.2 $ lt_of_le_of_ne
(le_of_not_gt hxa) $ λ h,
by simpa [mem_fin_pairs_lt, (f⁻¹).bijective.1 h, lt_irrefl] using ha,
by dsimp [sign_bij_aux];
rw [apply_inv_self, apply_inv_self,
dif_neg (not_lt_of_ge (le_of_lt (mem_fin_pairs_lt.1 ha)))]⟩
lemma sign_bij_aux_mem {n : ℕ} {f : perm (fin n)}: ∀ a : Σ a : fin n, fin n,
a ∈ fin_pairs_lt n → sign_bij_aux f a ∈ fin_pairs_lt n :=
λ ⟨a₁, a₂⟩ ha, begin
unfold sign_bij_aux,
split_ifs with h,
{ exact mem_fin_pairs_lt.2 h },
{ exact mem_fin_pairs_lt.2
(lt_of_le_of_ne (le_of_not_gt h)
(λ h, ne_of_lt (mem_fin_pairs_lt.1 ha) (f.bijective.1 h.symm))) }
end
@[simp] lemma sign_aux_inv {n : ℕ} (f : perm (fin n)) : sign_aux f⁻¹ = sign_aux f :=
prod_bij (λ a ha, sign_bij_aux f⁻¹ a)
sign_bij_aux_mem
(λ ⟨a, b⟩ hab, if h : f⁻¹ b < f⁻¹ a
then by rw [sign_bij_aux, dif_pos h, if_neg (not_le_of_gt h), apply_inv_self,
apply_inv_self, if_neg (not_le_of_gt $ mem_fin_pairs_lt.1 hab)]
else by rw [sign_bij_aux, if_pos (le_of_not_gt h), dif_neg h, apply_inv_self,
apply_inv_self, if_pos (le_of_lt $ mem_fin_pairs_lt.1 hab)])
sign_bij_aux_inj
sign_bij_aux_surj
lemma sign_aux_mul {n : ℕ} (f g : perm (fin n)) :
sign_aux (f * g) = sign_aux f * sign_aux g :=
begin
rw ← sign_aux_inv g,
unfold sign_aux,
rw ← prod_mul_distrib,
refine prod_bij (λ a ha, sign_bij_aux g a) sign_bij_aux_mem _
sign_bij_aux_inj sign_bij_aux_surj,
rintros ⟨a, b⟩ hab,
rw [sign_bij_aux, mul_apply, mul_apply],
rw mem_fin_pairs_lt at hab,
by_cases h : g b < g a,
{ rw dif_pos h,
simp [not_le_of_gt hab]; congr },
{ rw [dif_neg h, inv_apply_self, inv_apply_self, if_pos (le_of_lt hab)],
by_cases h₁ : f (g b) ≤ f (g a),
{ have : f (g b) ≠ f (g a),
{ rw [ne.def, injective.eq_iff f.bijective.1,
injective.eq_iff g.bijective.1];
exact ne_of_lt hab },
rw [if_pos h₁, if_neg (not_le_of_gt (lt_of_le_of_ne h₁ this))],
refl },
{ rw [if_neg h₁, if_pos (le_of_lt (lt_of_not_ge h₁))],
refl } }
end
instance sign_aux.is_group_hom {n : ℕ} : is_group_hom (@sign_aux n) := ⟨sign_aux_mul⟩
private lemma sign_aux_swap_zero_one {n : ℕ} (hn : 2 ≤ n) :
sign_aux (swap (⟨0, lt_of_lt_of_le dec_trivial hn⟩ : fin n)
⟨1, lt_of_lt_of_le dec_trivial hn⟩) = -1 :=
let zero : fin n := ⟨0, lt_of_lt_of_le dec_trivial hn⟩ in
let one : fin n := ⟨1, lt_of_lt_of_le dec_trivial hn⟩ in
have hzo : zero < one := dec_trivial,
show _ = (finset.singleton (⟨one, zero⟩ : Σ a : fin n, fin n)).prod
(λ x : Σ a : fin n, fin n, if (equiv.swap zero one) x.1
≤ swap zero one x.2 then (-1 : units ℤ) else 1),
begin
refine eq.symm (prod_subset (λ ⟨x₁, x₂⟩, by simp [mem_fin_pairs_lt, hzo] {contextual := tt})
(λ a ha₁ ha₂, _)),
rcases a with ⟨⟨a₁, ha₁⟩, ⟨a₂, ha₂⟩⟩,
replace ha₁ : a₂ < a₁ := mem_fin_pairs_lt.1 ha₁,
simp only [swap_apply_def],
have : ¬ 1 ≤ a₂ → a₂ = 0, from λ h, nat.le_zero_iff.1 (nat.le_of_lt_succ (lt_of_not_ge h)),
have : a₁ ≤ 1 → a₁ = 0 ∨ a₁ = 1, from nat.cases_on a₁ (λ _, or.inl rfl)
(λ a₁, nat.cases_on a₁ (λ _, or.inr rfl) (λ _ h, absurd h dec_trivial)),
split_ifs;
simp [*, lt_irrefl, -not_lt, not_le.symm, -not_le, le_refl, fin.lt_def, fin.le_def, nat.zero_le,
zero, one, iff.intro fin.veq_of_eq fin.eq_of_veq, nat.le_zero_iff] at *,
end
lemma sign_aux_swap : ∀ {n : ℕ} {x y : fin n} (hxy : x ≠ y),
sign_aux (swap x y) = -1
| 0 := dec_trivial
| 1 := dec_trivial
| (n+2) := λ x y hxy,
have h2n : 2 ≤ n + 2 := dec_trivial,
by rw [← is_conj_iff_eq, ← sign_aux_swap_zero_one h2n];
exact is_group_hom.is_conj _ (is_conj_swap hxy dec_trivial)
def sign_aux2 : list α → perm α → units ℤ
| [] f := 1
| (x::l) f := if x = f x then sign_aux2 l f else -sign_aux2 l (swap x (f x) * f)
lemma sign_aux_eq_sign_aux2 {n : ℕ} : ∀ (l : list α) (f : perm α) (e : α ≃ fin n)
(h : ∀ x, f x ≠ x → x ∈ l), sign_aux ((e.symm.trans f).trans e) = sign_aux2 l f
| [] f e h := have f = 1, from equiv.ext _ _ $
λ y, not_not.1 (mt (h y) (list.not_mem_nil _)),
by rw [this, one_def, equiv.trans_refl, equiv.symm_trans, ← one_def,
sign_aux_one, sign_aux2]
| (x::l) f e h := begin
rw sign_aux2,
by_cases hfx : x = f x,
{ rw if_pos hfx,
exact sign_aux_eq_sign_aux2 l f _ (λ y (hy : f y ≠ y), list.mem_of_ne_of_mem
(λ h : y = x, by simpa [h, hfx.symm] using hy) (h y hy) ) },
{ have hy : ∀ y : α, (swap x (f x) * f) y ≠ y → y ∈ l,
from λ y hy, have f y ≠ y ∧ y ≠ x, from support_swap_mul hy,
list.mem_of_ne_of_mem this.2 (h _ this.1),
have : (e.symm.trans (swap x (f x) * f)).trans e =
(swap (e x) (e (f x))) * (e.symm.trans f).trans e,
from equiv.ext _ _ (λ z, by rw ← equiv.symm_trans_swap_trans; simp [mul_def]),
have hefx : e x ≠ e (f x), from mt (injective.eq_iff e.bijective.1).1 hfx,
rw [if_neg hfx, ← sign_aux_eq_sign_aux2 _ _ e hy, this, sign_aux_mul, sign_aux_swap hefx],
simp }
end
def sign_aux3 [fintype α] (f : perm α) {s : multiset α} : (∀ x, x ∈ s) → units ℤ :=
quotient.hrec_on s (λ l h, sign_aux2 l f)
(trunc.induction_on (equiv_fin α)
(λ e l₁ l₂ h, function.hfunext
(show (∀ x, x ∈ l₁) = ∀ x, x ∈ l₂, by simp [list.mem_of_perm h])
(λ h₁ h₂ _, by rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₁ _),
← sign_aux_eq_sign_aux2 _ _ e (λ _ _, h₂ _)])))
lemma sign_aux3_mul_and_swap [fintype α] (f g : perm α) (s : multiset α) (hs : ∀ x, x ∈ s) :
sign_aux3 (f * g) hs = sign_aux3 f hs * sign_aux3 g hs ∧ ∀ x y, x ≠ y →
sign_aux3 (swap x y) hs = -1 :=
let ⟨l, hl⟩ := quotient.exists_rep s in
let ⟨e, _⟩ := trunc.exists_rep (equiv_fin α) in
begin
clear _let_match _let_match,
subst hl,
show sign_aux2 l (f * g) = sign_aux2 l f * sign_aux2 l g ∧
∀ x y, x ≠ y → sign_aux2 l (swap x y) = -1,
have hfg : (e.symm.trans (f * g)).trans e = (e.symm.trans f).trans e * (e.symm.trans g).trans e,
from equiv.ext _ _ (λ h, by simp [mul_apply]),
split,
{ rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), ← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _),
← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), hfg, sign_aux_mul] },
{ assume x y hxy,
have hexy : e x ≠ e y, from mt (injective.eq_iff e.bijective.1).1 hxy,
rw [← sign_aux_eq_sign_aux2 _ _ e (λ _ _, hs _), equiv.symm_trans_swap_trans, sign_aux_swap hexy] }
end
/-- `sign` of a permutation returns the signature or parity of a permutation, `1` for even
permutations, `-1` for odd permutations. It is the unique surjective group homomorphism from
`perm α` to the group with two elements.-/
def sign [fintype α] (f : perm α) := sign_aux3 f mem_univ
instance sign.is_group_hom [fintype α] : is_group_hom (@sign α _ _) :=
⟨λ f g, (sign_aux3_mul_and_swap f g _ mem_univ).1⟩
@[simp] lemma sign_mul [fintype α] (f g : perm α) : sign (f * g) = sign f * sign g :=
is_group_hom.mul sign _ _
@[simp] lemma sign_one [fintype α] : (sign (1 : perm α)) = 1 :=
is_group_hom.one sign
@[simp] lemma sign_inv [fintype α] (f : perm α) : sign f⁻¹ = sign f :=
by rw [is_group_hom.inv sign, int.units_inv_eq_self]; apply_instance
lemma sign_swap [fintype α] {x y : α} (h : x ≠ y) : sign (swap x y) = -1 :=
(sign_aux3_mul_and_swap 1 1 _ mem_univ).2 x y h
lemma sign_eq_of_is_swap [fintype α] {f : perm α} (h : is_swap f) : sign f = -1 :=
let ⟨x, y, hxy⟩ := h in hxy.2.symm ▸ sign_swap hxy.1
lemma sign_aux3_symm_trans_trans [fintype α] [decidable_eq β] [fintype β] (f : perm α)
(e : α ≃ β) {s : multiset α} {t : multiset β} (hs : ∀ x, x ∈ s) (ht : ∀ x, x ∈ t) :
sign_aux3 ((e.symm.trans f).trans e) ht = sign_aux3 f hs :=
quotient.induction_on₂ t s
(λ l₁ l₂ h₁ h₂, show sign_aux2 _ _ = sign_aux2 _ _,
from let n := trunc.out (equiv_fin β) in
by rw [← sign_aux_eq_sign_aux2 _ _ n (λ _ _, h₁ _),
← sign_aux_eq_sign_aux2 _ _ (e.trans n) (λ _ _, h₂ _)];
exact congr_arg sign_aux (equiv.ext _ _ (λ x, by simp)))
ht hs
lemma sign_symm_trans_trans [fintype α] [decidable_eq β] [fintype β] (f : perm α)
(e : α ≃ β) : sign ((e.symm.trans f).trans e) = sign f :=
sign_aux3_symm_trans_trans f e mem_univ mem_univ
lemma sign_prod_list_swap [fintype α] {l : list (perm α)}
(hl : ∀ g ∈ l, is_swap g) : sign l.prod = -1 ^ l.length :=
have h₁ : l.map sign = list.repeat (-1) l.length :=
list.eq_repeat.2 ⟨by simp, λ u hu,
let ⟨g, hg⟩ := list.mem_map.1 hu in
hg.2 ▸ sign_eq_of_is_swap (hl _ hg.1)⟩,
by rw [← list.prod_repeat, ← h₁, ← is_group_hom.prod (@sign α _ _)]
lemma eq_sign_of_surjective_hom [fintype α] {s : perm α → units ℤ}
[is_group_hom s] (hs : surjective s) : s = sign :=
have ∀ {f}, is_swap f → s f = -1 :=
λ f ⟨x, y, hxy, hxy'⟩, hxy'.symm ▸ by_contradiction (λ h,
have ∀ f, is_swap f → s f = 1 := λ f ⟨a, b, hab, hab'⟩,
by rw [← is_conj_iff_eq, ← or.resolve_right (int.units_eq_one_or _) h, hab'];
exact is_group_hom.is_conj _ (is_conj_swap hab hxy),
let ⟨g, hg⟩ := hs (-1) in
let ⟨l, hl⟩ := trunc.out (trunc_swap_factors g) in
have ∀ a ∈ l.map s, a = (1 : units ℤ) := λ a ha,
let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this _ (hl.2 _ hg.1),
have s l.prod = 1,
by rw [is_group_hom.prod s, list.eq_repeat'.2 this, list.prod_repeat, one_pow],
by rw [hl.1, hg] at this;
exact absurd this dec_trivial),
funext $ λ f,
let ⟨l, hl₁, hl₂⟩ := trunc.out (trunc_swap_factors f) in
have hsl : ∀ a ∈ l.map s, a = (-1 : units ℤ) := λ a ha,
let ⟨g, hg⟩ := list.mem_map.1 ha in hg.2 ▸ this (hl₂ _ hg.1),
by rw [← hl₁, is_group_hom.prod s, list.eq_repeat'.2 hsl, list.length_map,
list.prod_repeat, sign_prod_list_swap hl₂]
lemma sign_subtype_perm [fintype α] (f : perm α) {p : α → Prop} [decidable_pred p]
(h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : sign (subtype_perm f h₁) = sign f :=
let l := trunc.out (trunc_swap_factors (subtype_perm f h₁)) in
have hl' : ∀ g' ∈ l.1.map of_subtype, is_swap g' :=
λ g' hg',
let ⟨g, hg⟩ := list.mem_map.1 hg' in
hg.2 ▸ is_swap_of_subtype (l.2.2 _ hg.1),
have hl'₂ : (l.1.map of_subtype).prod = f,
by rw [← is_group_hom.prod of_subtype l.1, l.2.1, of_subtype_subtype_perm _ h₂],
by conv {congr, rw ← l.2.1, skip, rw ← hl'₂};
rw [sign_prod_list_swap l.2.2, sign_prod_list_swap hl', list.length_map]
@[simp] lemma sign_of_subtype [fintype α] {p : α → Prop} [decidable_pred p]
(f : perm (subtype p)) : sign (of_subtype f) = sign f :=
have ∀ x, of_subtype f x ≠ x → p x, from λ x, not_imp_comm.1 (of_subtype_apply_of_not_mem f),
by conv {to_rhs, rw [← subtype_perm_of_subtype f, sign_subtype_perm _ _ this]}
lemma sign_eq_sign_of_equiv [fintype α] [decidable_eq β] [fintype β] (f : perm α) (g : perm β)
(e : α ≃ β) (h : ∀ x, e (f x) = g (e x)) : sign f = sign g :=
have hg : g = (e.symm.trans f).trans e, from equiv.ext _ _ $ by simp [h],
by rw [hg, sign_symm_trans_trans]
lemma sign_bij [fintype α] [decidable_eq β] [fintype β]
{f : perm α} {g : perm β} (i : Π x : α, f x ≠ x → β)
(h : ∀ x hx hx', i (f x) hx' = g (i x hx))
(hi : ∀ x₁ x₂ hx₁ hx₂, i x₁ hx₁ = i x₂ hx₂ → x₁ = x₂)
(hg : ∀ y, g y ≠ y → ∃ x hx, i x hx = y) :
sign f = sign g :=
calc sign f = sign (@subtype_perm _ f (λ x, f x ≠ x) (by simp)) :
eq.symm (sign_subtype_perm _ _ (λ _, id))
... = sign (@subtype_perm _ g (λ x, g x ≠ x) (by simp)) :
sign_eq_sign_of_equiv _ _
(equiv.of_bijective
(show function.bijective (λ x : {x // f x ≠ x},
(⟨i x.1 x.2, have f (f x) ≠ f x, from mt (λ h, f.bijective.1 h) x.2,
by rw [← h _ x.2 this]; exact mt (hi _ _ this x.2) x.2⟩ : {y // g y ≠ y})),
from ⟨λ ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq (hi _ _ _ _ (subtype.mk.inj h)),
λ ⟨y, hy⟩, let ⟨x, hfx, hx⟩ := hg y hy in ⟨⟨x, hfx⟩, subtype.eq hx⟩⟩))
(λ ⟨x, _⟩, subtype.eq (h x _ _))
... = sign g : sign_subtype_perm _ _ (λ _, id)
lemma is_cycle_swap {x y : α} (hxy : x ≠ y) : is_cycle (swap x y) :=
⟨y, by rwa swap_apply_right,
λ a (ha : ite (a = x) y (ite (a = y) x a) ≠ a),
if hya : y = a then ⟨0, hya⟩
else ⟨1, by rw [gpow_one, swap_apply_def]; split_ifs at *; cc⟩⟩
lemma is_cycle_inv {f : perm α} (hf : is_cycle f) : is_cycle (f⁻¹) :=
let ⟨x, hx⟩ := hf in
⟨x, by simp [eq_inv_iff_eq, inv_eq_iff_eq, *] at *; cc,
λ y hy, let ⟨i, hi⟩ := hx.2 y (by simp [eq_inv_iff_eq, inv_eq_iff_eq, *] at *; cc) in
⟨-i, by rwa [gpow_neg, inv_gpow, inv_inv]⟩⟩
lemma is_cycle_swap_mul_aux₁ : ∀ (n : ℕ) {b x : α} {f : perm α}
(hf : is_cycle f) (hb : (swap x (f x) * f) b ≠ b) (h : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b
| 0 := λ b x f hf hb h, ⟨0, h⟩
| (n+1 : ℕ) := λ b x f hf hb h,
if hfbx : f x = b then ⟨0, hfbx⟩
else
have f b ≠ b ∧ b ≠ x, from support_swap_mul hb,
have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b,
by rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (ne.symm hfbx),
ne.def, ← injective.eq_iff f.bijective.1, apply_inv_self];
exact this.1,
let ⟨i, hi⟩ := is_cycle_swap_mul_aux₁ n hf hb'
(f.bijective.1 $
by rw [apply_inv_self];
rwa [pow_succ, mul_apply] at h) in
⟨i + 1, by rw [add_comm, gpow_add, mul_apply, hi, gpow_one, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne (support_swap_mul hb).2 (ne.symm hfbx)]⟩
lemma is_cycle_swap_mul_aux₂ : ∀ (n : ℤ) {b x : α} {f : perm α}
(hf : is_cycle f) (hb : (swap x (f x) * f) b ≠ b) (h : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b
| (n : ℕ) := λ b x f hf, is_cycle_swap_mul_aux₁ n hf
| -[1+ n] := λ b x f hf hb h,
if hfbx : f⁻¹ x = b then ⟨-1, by rwa [gpow_neg, gpow_one, mul_inv_rev, mul_apply, swap_inv, swap_apply_right]⟩
else if hfbx' : f x = b then ⟨0, hfbx'⟩
else
have f b ≠ b ∧ b ≠ x := support_swap_mul hb,
have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b,
by rw [mul_apply, swap_apply_def];
split_ifs;
simp [inv_eq_iff_eq, eq_inv_iff_eq] at *; cc,
let ⟨i, hi⟩ := is_cycle_swap_mul_aux₁ n (is_cycle_inv hf) hb
(show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b, by
rw [← gpow_coe_nat, ← h, ← mul_apply, ← mul_apply, ← mul_apply, gpow_neg_succ, ← inv_pow, pow_succ', mul_assoc,
mul_assoc, inv_mul_self, mul_one, gpow_coe_nat, ← pow_succ', ← pow_succ]) in
have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x, by rw [mul_apply, inv_apply_self, swap_apply_left],
⟨-i, by rw [← add_sub_cancel i 1, neg_sub, sub_eq_add_neg, gpow_add, gpow_one, gpow_neg, ← inv_gpow,
mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x, gpow_add, gpow_one,
mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (ne.symm hfbx')]⟩
lemma eq_swap_of_is_cycle_of_apply_apply_eq_self {f : perm α} (hf : is_cycle f) {x : α}
(hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) :=
equiv.ext _ _ $ λ y,
let ⟨z, hz⟩ := hf in
let ⟨i, hi⟩ := hz.2 x hfx in
if hyx : y = x then by simp [hyx]
else if hfyx : y = f x then by simp [hfyx, hffx]
else begin
rw [swap_apply_of_ne_of_ne hyx hfyx],
refine by_contradiction (λ hy, _),
cases hz.2 y hy with j hj,
rw [← sub_add_cancel j i, gpow_add, mul_apply, hi] at hj,
cases pow_apply_eq_of_apply_apply_eq_self_int hffx (j - i) with hji hji,
{ rw [← hj, hji] at hyx, cc },
{ rw [← hj, hji] at hfyx, cc }
end
lemma is_cycle_swap_mul {f : perm α} (hf : is_cycle f) {x : α}
(hx : f x ≠ x) (hffx : f (f x) ≠ x) : is_cycle (swap x (f x) * f) :=
⟨f x, by simp only [swap_apply_def, mul_apply];
split_ifs; simp [injective.eq_iff f.bijective.1] at *; cc,
λ y hy,
let ⟨i, hi⟩ := exists_int_pow_eq_of_is_cycle hf hx (support_swap_mul hy).1 in
have hi : (f ^ (i - 1)) (f x) = y, from
calc (f ^ (i - 1)) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ)) x : by rw [gpow_one, mul_apply]
... = y : by rwa [← gpow_add, sub_add_cancel],
is_cycle_swap_mul_aux₂ (i - 1) hf hy hi⟩
lemma support_swap_mul_cycle [fintype α] {f : perm α} (hf : is_cycle f) {x : α}
(hffx : f (f x) ≠ x) : (swap x (f x) * f).support = f.support.erase x :=
have hfx : f x ≠ x, from λ hfx, by simpa [hfx] using hffx,
finset.ext.2 $ λ y, begin
have h1 : swap x (f x) * f ≠ 1,
from λ h1, hffx $ by
rw [mul_eq_one_iff_inv_eq, swap_inv] at h1;
rw ← h1; simp,
have hfyxor : f y ≠ x ∨ f x ≠ y :=
not_and_distrib.1 (λ h, h1 $
by have := eq_swap_of_is_cycle_of_apply_apply_eq_self hf hfx (by rw [h.2, h.1]);
rw [← this, this, mul_def, swap_swap, one_def]),
rw [mem_support, mem_erase, mem_support],
split,
{ assume h,
refine not_or_distrib.1 (λ h₁, h₁.elim
(λ hyx, by simpa [hyx, mul_apply] using h) _),
assume hfy,
have hyx : x ≠ y := λ h, by rw h at hfx; tauto,
have hfyx : f x ≠ y := by rwa [← hfy, ne.def, injective.eq_iff f.bijective.1],
simpa [mul_apply, hfy, swap_apply_of_ne_of_ne hyx.symm hfyx.symm] using h },
{ assume h,
simp [swap_apply_def],
split_ifs; cc }
end
@[simp] lemma support_swap [fintype α] {x y : α} (hxy : x ≠ y) : (swap x y).support = {x, y} :=
finset.ext.2 $ λ a, by simp [swap_apply_def]; split_ifs; cc
lemma card_support_swap [fintype α] {x y : α} (hxy : x ≠ y) : (swap x y).support.card = 2 :=
show (swap x y).support.card = finset.card ⟨x::y::0, by simp [hxy]⟩,
from congr_arg card $ by rw [support_swap hxy]; simp [*, finset.ext]; cc
lemma sign_cycle [fintype α] : ∀ {f : perm α} (hf : is_cycle f),
sign f = -(-1 ^ f.support.card)
| f := λ hf,
let ⟨x, hx⟩ := hf in
calc sign f = sign (swap x (f x) * (swap x (f x) * f)) :
by rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl]
... = -(-1 ^ f.support.card) :
if h1 : f (f x) = x
then
have h : swap x (f x) * f = 1,
by conv in (f) {rw eq_swap_of_is_cycle_of_apply_apply_eq_self hf hx.1 h1 };
simp [mul_def, one_def],
by rw [sign_mul, sign_swap hx.1.symm, h, sign_one, eq_swap_of_is_cycle_of_apply_apply_eq_self hf hx.1 h1,
card_support_swap hx.1.symm]; refl
else
have h : card (support (swap x (f x) * f)) + 1 = card (support f),
by rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_cycle hf h1,
card_insert_of_not_mem (not_mem_erase _ _)],
have wf : card (support (swap x (f x) * f)) < card (support f),
from h ▸ nat.lt_succ_self _,
by rw [sign_mul, sign_swap hx.1.symm, sign_cycle (is_cycle_swap_mul hf hx.1 h1), ← h];
simp [pow_add]
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ f, f.support.card)⟩]}
end equiv.perm
|
59476b62d4c2f02a7443222fa4742401ac6ca5c0
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/subst_test.lean
|
929e7a3e8baf56ef6d04c95ecd062797d13a7be2
|
[
"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
| 445
|
lean
|
import data.nat
open nat
structure less_than (n : nat) := (val : nat) (lt : val < n)
namespace less_than
open decidable
set_option pp.beta false
definition less_than.has_decidable_eq [instance] (n : nat) : ∀ (i j : less_than n), decidable (i = j)
| (mk ival ilt) (mk jval jlt) :=
match nat.has_decidable_eq ival jval with
| inl veq := inl (by subst veq)
| inr vne := inr (by intro h; injection h; contradiction)
end
end less_than
|
f7058f22d825aa1c82c40c579144a43658287774
|
f10d66a159ce037d07005bd6021cee6bbd6d5ff0
|
/Sup_fin.lean
|
2224953ca7cd16be790cf30f5df69722c6e8598d
|
[] |
no_license
|
johoelzl/mason-stother
|
0c78bca183eb729d7f0f93e87ce073bc8cd8808d
|
573ecfaada288176462c03c87b80ad05bdab4644
|
refs/heads/master
| 1,631,751,973,492
| 1,528,923,934,000
| 1,528,923,934,000
| 109,133,224
| 0
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,246
|
lean
|
import order.lattice data.finset
universes u v w
noncomputable theory
open classical set function lattice
instance {α : Type u} [semilattice_sup α] : is_idempotent α (⊔) := ⟨assume a, sup_idem⟩
namespace finset
section general
variables {α : Type u} {β : Type w} [decidable_eq β] [semilattice_sup_bot α]
def Sup_fin (s : finset β) (f : β → α) : α := s.fold (⊔) ⊥ f
variables {s s₁ s₂ : finset β} {f : β → α}
@[simp] lemma Sup_fin_empty : (∅ : finset β).Sup_fin f = ⊥ :=
fold_empty
@[simp] lemma Sup_fin_insert {b : β} : (insert b s : finset β).Sup_fin f = f b ⊔ s.Sup_fin f :=
fold_insert_idem
@[simp] lemma Sup_fin_singleton {b : β} : (finset.singleton b).Sup_fin f = f b :=
calc _ = f b ⊔ (∅:finset β).Sup_fin f : Sup_fin_insert
... = f b : by simp
lemma Sup_fin_union : (s₁ ∪ s₂).Sup_fin f = s₁.Sup_fin f ⊔ s₂.Sup_fin f :=
finset.induction_on s₁ (by simp) (by simp {contextual := tt}; cc)
lemma Sup_fin_mono_fun {g : β → α} : (∀b∈s, f b ≤ g b) → s.Sup_fin f ≤ s.Sup_fin g :=
finset.induction_on s (by simp) (by simp [-sup_le_iff, sup_le_sup] {contextual := tt})
lemma le_Sup_fin {b : β} (hb : b ∈ s) : f b ≤ s.Sup_fin f :=
calc f b ≤ f b ⊔ s.Sup_fin f : le_sup_left
... = (insert b s).Sup_fin f : by simp
... = s.Sup_fin f : by simp [hb]
lemma Sup_fin_le {a : α} : (∀b ∈ s, f b ≤ a) → s.Sup_fin f ≤ a :=
finset.induction_on s (by simp) (by simp {contextual := tt})
lemma Sup_fin_mono (h : s₁ ⊆ s₂) : s₁.Sup_fin f ≤ s₂.Sup_fin f :=
Sup_fin_le $ assume b hb, le_Sup_fin (finset.subset_iff.mpr h hb)
end general
end finset
instance nat.distrib_lattice : distrib_lattice ℕ :=
by apply_instance
instance nat.semilattice_sup_bot : semilattice_sup_bot ℕ :=
{ bot := 0, bot_le := nat.zero_le , .. nat.distrib_lattice }
lemma nat.sup_eq_max {n m : ℕ} : n ⊔ m = max n m := rfl
lemma forall_eq_zero_of_sup_fin_eq_bot {s : finset ℕ} : finset.Sup_fin s id = 0 → ∀x ∈ s, x = 0 :=
begin
intros h x h2,
have : x ≤ 0,
exact calc x = id x : rfl
... ≤ finset.Sup_fin s id : finset.le_Sup_fin h2
... = 0 : h,
exact nat.eq_zero_of_le_zero this
end
lemma eq_singleton_or_eq_empty_of_sup_fin_eq_bot {s : finset ℕ} : finset.Sup_fin s id = 0 → s = {0} ∨ s = ∅ :=
begin
intro h,
by_cases h1 : (s = ∅),
simp [h1],
have h2 : ∀x ∈ s, x = 0,
from forall_eq_zero_of_sup_fin_eq_bot h,
have hex : ∃x : ℕ, x ∈ s,
from finset.exists_mem_of_ne_empty h1,
have h3: {0} ⊆ s,
have h4 : (some hex) ∈ s,
from some_spec hex,
have h5: (some hex) = 0,
from h2 (some hex) h4,
have h6: 0 ∈ s,
rw [←h5],
exact h4,
exact iff.elim_right singleton_subset_iff h6,
have h7 : s ⊆ {0},
dunfold has_subset.subset,
intros a h4,
have h8 : a = 0,
from h2 a h4,
rw h8,
exact mem_singleton 0,
have h9 : s = {0},
exact finset.subset.antisymm h7 h3,
simp [h9]
end
open finset
lemma Sup_fin_mem_of_id_nat {s : finset ℕ} : s ≠ ∅ → Sup_fin s id ∈ s :=
finset.induction_on s
(by contradiction)
(by intros a s; by_cases s = ∅; cases le_total a (Sup_fin s id);
simp [*, nat.sup_eq_max, max_eq_left, max_eq_right] {contextual := tt})
|
94681d33597728ff935b8f78a4541db24376ea6f
|
2eab05920d6eeb06665e1a6df77b3157354316ad
|
/src/topology/unit_interval.lean
|
3a3904039bcbee8e914db35eec755527178553dd
|
[
"Apache-2.0"
] |
permissive
|
ayush1801/mathlib
|
78949b9f789f488148142221606bf15c02b960d2
|
ce164e28f262acbb3de6281b3b03660a9f744e3c
|
refs/heads/master
| 1,692,886,907,941
| 1,635,270,866,000
| 1,635,270,866,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,454
|
lean
|
/-
Copyright (c) 2020 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Scott Morrison
-/
import topology.instances.real
import topology.algebra.field
/-!
# The unit interval, as a topological space
Use `open_locale unit_interval` to turn on the notation `I := set.Icc (0 : ℝ) (1 : ℝ)`.
We provide basic instances, as well as a custom tactic for discharging
`0 ≤ x`, `0 ≤ 1 - x`, `x ≤ 1`, and `1 - x ≤ 1` when `x : I`.
-/
noncomputable theory
open_locale classical topological_space filter
open set
/-! ### The unit interval -/
/-- The unit interval `[0,1]` in ℝ. -/
abbreviation unit_interval : set ℝ := set.Icc 0 1
localized "notation `I` := unit_interval" in unit_interval
namespace unit_interval
lemma mem_iff_one_sub_mem {t : ℝ} : t ∈ I ↔ 1 - t ∈ I :=
begin
rw [mem_Icc, mem_Icc],
split ; intro ; split ; linarith
end
instance has_zero : has_zero I := ⟨⟨0, by split ; norm_num⟩⟩
@[simp, norm_cast] lemma coe_zero : ((0 : I) : ℝ) = 0 := rfl
@[simp] lemma mk_zero (h : (0 : ℝ) ∈ Icc (0 : ℝ) 1) : (⟨0, h⟩ : I) = 0 := rfl
instance has_one : has_one I := ⟨⟨1, by split ; norm_num⟩⟩
@[simp, norm_cast] lemma coe_one : ((1 : I) : ℝ) = 1 := rfl
@[simp] lemma mk_one (h : (1 : ℝ) ∈ Icc (0 : ℝ) 1) : (⟨1, h⟩ : I) = 1 := rfl
instance : nonempty I := ⟨0⟩
/-- Unit interval central symmetry. -/
def symm : I → I := λ t, ⟨1 - t.val, mem_iff_one_sub_mem.mp t.property⟩
localized "notation `σ` := unit_interval.symm" in unit_interval
@[simp] lemma symm_zero : σ 0 = 1 :=
subtype.ext $ by simp [symm]
@[simp] lemma symm_one : σ 1 = 0 :=
subtype.ext $ by simp [symm]
@[simp] lemma symm_symm (x : I) : σ (σ x) = x :=
subtype.ext $ by simp [symm]
@[simp] lemma coe_symm_eq (x : I) : (σ x : ℝ) = 1 - x := rfl
@[continuity]
lemma continuous_symm : continuous σ :=
by continuity!
instance : connected_space I :=
subtype.connected_space ⟨nonempty_Icc.mpr zero_le_one, is_preconnected_Icc⟩
/-- Verify there is an instance for `compact_space I`. -/
example : compact_space I := by apply_instance
lemma nonneg (x : I) : 0 ≤ (x : ℝ) := x.2.1
lemma one_minus_nonneg (x : I) : 0 ≤ 1 - (x : ℝ) := by simpa using x.2.2
lemma le_one (x : I) : (x : ℝ) ≤ 1 := x.2.2
lemma one_minus_le_one (x : I) : 1 - (x : ℝ) ≤ 1 := by simpa using x.2.1
lemma mul_pos_mem_iff {a t : ℝ} (ha : 0 < a) : a * t ∈ I ↔ t ∈ set.Icc (0 : ℝ) (1/a) :=
begin
split; rintros ⟨h₁, h₂⟩; split,
{ exact nonneg_of_mul_nonneg_left h₁ ha },
{ rwa [le_div_iff ha, mul_comm] },
{ exact mul_nonneg ha.le h₁ },
{ rwa [le_div_iff ha, mul_comm] at h₂ }
end
lemma two_mul_sub_one_mem_iff {t : ℝ} : 2 * t - 1 ∈ I ↔ t ∈ set.Icc (1/2 : ℝ) 1 :=
by split; rintros ⟨h₁, h₂⟩; split; linarith
end unit_interval
namespace tactic.interactive
/-- A tactic that solves `0 ≤ x`, `0 ≤ 1 - x`, `x ≤ 1`, and `1 - x ≤ 1` for `x : I`. -/
meta def unit_interval : tactic unit :=
`[apply unit_interval.nonneg] <|> `[apply unit_interval.one_minus_nonneg] <|>
`[apply unit_interval.le_one] <|> `[apply unit_interval.one_minus_le_one]
end tactic.interactive
section
variables {𝕜 : Type*} [linear_ordered_field 𝕜] [topological_space 𝕜] [topological_ring 𝕜]
/--
The image of `[0,1]` under the homeomorphism `λ x, a * x + b` is `[b, a+b]`.
-/
-- We only need the ordering on `𝕜` here to avoid talking about flipping the interval over.
-- At the end of the day I only care about `ℝ`, so I'm hesitant to put work into generalizing.
lemma affine_homeomorph_image_I (a b : 𝕜) (h : 0 < a) :
affine_homeomorph a b h.ne.symm '' set.Icc 0 1 = set.Icc b (a + b) :=
by simp [h]
/--
The affine homeomorphism from a nontrivial interval `[a,b]` to `[0,1]`.
-/
def Icc_homeo_I (a b : 𝕜) (h : a < b) : set.Icc a b ≃ₜ set.Icc (0 : 𝕜) (1 : 𝕜) :=
begin
let e := homeomorph.image (affine_homeomorph (b-a) a (sub_pos.mpr h).ne.symm) (set.Icc 0 1),
refine (e.trans _).symm,
apply homeomorph.set_congr,
simp [sub_pos.mpr h],
end
@[simp] lemma Icc_homeo_I_apply_coe (a b : 𝕜) (h : a < b) (x : set.Icc a b) :
((Icc_homeo_I a b h) x : 𝕜) = (x - a) / (b - a) :=
rfl
@[simp] lemma Icc_homeo_I_symm_apply_coe (a b : 𝕜) (h : a < b) (x : set.Icc (0 : 𝕜) (1 : 𝕜)) :
((Icc_homeo_I a b h).symm x : 𝕜) = (b - a) * x + a :=
rfl
end
|
b761562ae99d6d79310504629510ba9749fa2851
|
56e5b79a7ab4f2c52e6eb94f76d8100a25273cf3
|
/src/tools/theorem_naming_eval.lean
|
e86b12a1e110418a7c096e73334222d0ed273917
|
[
"Apache-2.0"
] |
permissive
|
DyeKuu/lean-tpe-public
|
3a9968f286ca182723ef7e7d97e155d8cb6b1e70
|
750ade767ab28037e80b7a80360d213a875038f8
|
refs/heads/master
| 1,682,842,633,115
| 1,621,330,793,000
| 1,621,330,793,000
| 368,475,816
| 0
| 0
|
Apache-2.0
| 1,621,330,745,000
| 1,621,330,744,000
| null |
UTF-8
|
Lean
| false
| false
| 5,160
|
lean
|
/-
Runs theorem naming evaluation.
-/
import all
import backends.bfs.openai
import utils.util
import evaluation
section main
meta structure TheoremNamingEvalResult : Type :=
(decl_nm : name) -- name of top-level theorem (i.e. ground truth)
(decl_tp : expr) -- goal of top-level theorem
(predictions : list (string × native.float)) -- sorted list of predictions
meta instance : has_to_tactic_json TheoremNamingEvalResult :=
let fn : Π (σ : TheoremNamingEvalResult), tactic json := λ σ, match σ with
| ⟨nm, tp, preds⟩ := do {
tp_msg ← json.of_string <$> format.to_string <$> format.flatten <$> tactic.pp tp,
let pred_msg : json := json.array $ preds.map (λ ⟨candidate_name, score⟩, json.array $ [candidate_name, score]),
pure $ json.object $ [
("name", nm.to_string)
, ("type", tp_msg)
, ("predictions", pred_msg)
]
}
end
in ⟨fn⟩
open openai
meta def autoname_core (e : expr) (req : CompletionRequest) (engine_id : string) (api_key : string) : tactic (list $ string × native.float) := do {
ts_str ← format.to_string <$> format.flatten <$> (tactic.with_full_names $ tactic.pp e),
let prompt : string := "[LN] GOAL " ++ ts_str ++ (format!" {req.prompt_token} ").to_string,
let completion_request := {prompt := prompt, ..req},
response_msg ← tactic.unsafe_run_io $ (openai_api engine_id api_key).query completion_request,
responses ←
((list.qsort (λ x y : string × native.float, prod.snd x > prod.snd y) <$>
unwrap_lm_response_logprobs "autonamer" response_msg) -- >>= list.dedup'
),
eval_trace format! "[autoname_core] RESPONSES: {responses}",
pure responses
}
meta def get_theorem_naming_result
(decl_nm : name)
(decl_tp : expr)
(req : openai.CompletionRequest)
(engine_id : string)
(api_key : string)
: tactic TheoremNamingEvalResult := do {
predictions ← autoname_core decl_tp req engine_id api_key,
pure $ {decl_nm := decl_nm, decl_tp := decl_tp, predictions := predictions}
}
meta def theorem_naming_eval_core
(decls_file : string)
(dest : string)
(engine_id : string)
(api_key : string)
(req : openai.CompletionRequest)
: io unit := do {
nm_strs ← (io.mk_file_handle decls_file io.mode.read >>= λ f,
(string.split (λ c, c = '\n') <$> buffer.to_string <$> io.fs.read_to_end f)),
-- io.put_str_ln' format!"NM STRS: {nm_strs}",
(nms : list (name × list name)) ← (nm_strs.filter $ λ nm_str, string.length nm_str > 0).mmap $ λ nm_str, do {
((io.run_tactic' ∘ parse_decl_nm_and_open_ns) $ nm_str)
},
io.put_str_ln' format!"[theorem_naming_eval_core] GOT {nms.length} NAMES",
let nms_unfiltered_len := nms.length,
nms ← io.run_tactic' $ do {
env ← tactic.get_env,
nms.mfilter $ λ ⟨nm, _⟩, (do {
decl ← env.get nm,
pure decl.is_theorem
} <|> pure ff)
},
io.put_str_ln' format! "[evaluation_harness_from_decls_file] WARNING: SKIPPING {nms_unfiltered_len - nms.length}",
dest_handle ← io.mk_file_handle dest io.mode.write,
let process_result : TheoremNamingEvalResult → io unit := λ result, do {
msg ← json.unparse <$> (io.run_tactic' $ has_to_tactic_json.to_tactic_json result),
io.fs.put_str_ln_flush dest_handle msg
},
for_ nms $ λ ⟨nm, _⟩, do {
tp ← io.run_tactic' $ do {
env ← tactic.get_env,
decl ← env.get nm,
pure $ decl.type
},
result ← io.run_tactic' $ get_theorem_naming_result nm tp req engine_id api_key,
process_result result
}
}
/--
Loops through all the names in `names_file`, queries the model given by `engine_id` for `n` completions,
and records the predictions
-/
meta def main : io unit := do {
args ← io.cmdline_args,
decls_file ← args.nth_except 0 "decls_file",
dest ← args.nth_except 1 "dest",
max_tokens ← string.to_nat <$> args.nth_except 2 "max_tokens",
(some temperature) ← (native.float.of_string <$> (args.nth_except 3 "temperature")) | io.fail "failed to parse temperature",
(some top_p) ← (native.float.of_string <$> (args.nth_except 4 "top_p")) | io.fail "failed to parse top_p",
n ← string.to_nat <$> args.nth_except 5 "n",
best_of ← string.to_nat <$> args.nth_except 6 "best_of",
fuel ← string.to_nat <$> args.nth_except 7 "fuel",
max_width ← string.to_nat <$> args.nth_except 8 "max_width",
max_depth ← string.to_nat <$> args.nth_except 9 "max_depth",
engine_id ← args.nth_except 10 "engine_id",
api_key ← args.nth_except 11 "api_key",
tac_timeout ← string.to_nat <$> args.nth_except 12 "tac_timeout in seconds",
global_timeout ← string.to_nat <$> args.nth_except 13 "global_timeout in seconds",
let req : openai.CompletionRequest := {
max_tokens := max_tokens,
temperature := temperature,
top_p := top_p,
n := n,
best_of := best_of,
prompt_token := "PREDICTNAME",
..openai.default_partial_req
},
theorem_naming_eval_core decls_file dest engine_id api_key req
-- evaluation_harness_from_decls_file (SEARCH_CORE req engine_id api_key fuel)
-- decls_file dest global_timeout
-- $ BFSState.of_current_state 0 max_width max_depth tac_timeout
}
end main
|
f6951850e274401b212b85a833f0cbda26543a32
|
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
|
/tests/lean/run/struct2.lean
|
758f88e9e28fe2290b801e16a2479f013ab8b40c
|
[
"Apache-2.0"
] |
permissive
|
collares/lean4
|
861a9269c4592bce49b71059e232ff0bfe4594cc
|
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
|
refs/heads/master
| 1,691,419,031,324
| 1,618,678,138,000
| 1,618,678,138,000
| 358,989,750
| 0
| 0
|
Apache-2.0
| 1,618,696,333,000
| 1,618,696,333,000
| null |
UTF-8
|
Lean
| false
| false
| 1,573
|
lean
|
universes u v w
structure A (α : Type u) :=
(f : (β : Type u) → α → β → α)
set_option pp.all true
structure B (α : Type u) extends A α :=
(x : Nat)
(f := fun β a b => a)
#check B.f._default
#check { x := 10 : B Nat}
namespace New
structure A (α : Type u) where
f : (β : Type u) → α → β → α
structure B (α : Type u) extends A α where
x : Nat
f := fun β a b => a
#check B.f._default
#check { x := 10 : B Nat }
structure Data where
index? : Option Nat := none
lowlink? : Option Nat := none
onStack : Bool := false
structure State (α : Type) where
stack : List α := []
nextIndex : Nat := 0
data : Array Data := #[]
sccs : List (List α) := []
inductive Format where
| nil : Format
| line : Format
| text : String → Format
| nest (indent : Int) : Format → Format
| append : Format → Format → Format
| group : Format → Format
class MonadControl (m : Type u → Type v) (n : Type u → Type w) where
stM : Type u → Type u
liftWith {α} : (({β : Type u} → n β → m (stM β)) → m α) → n α
restoreM {α} : m (stM α) → n α
instance : MonadControl m (ReaderT ρ m) where
stM := id
liftWith f := fun ctx => f fun x => x ctx
restoreM x := fun ctx => x
instance [Monad m] : MonadControl m (StateT σ m) where
stM α := α × σ
liftWith f := do let s ← get; liftM (f (fun x => x.run s))
restoreM x := do let (a, s) ← liftM x; set s; pure a
end New
|
bd6868819e275845b05c9f514c6a9cead4116b3d
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/category_theory/elements.lean
|
2229113de827ea7c004146937f00980bb3ddc904
|
[
"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
| 9,533
|
lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.structured_arrow
import category_theory.groupoid
import category_theory.punit
/-!
# The category of elements
This file defines the category of elements, also known as (a special case of) the Grothendieck
construction.
Given a functor `F : C ⥤ Type`, an object of `F.elements` is a pair `(X : C, x : F.obj X)`.
A morphism `(X, x) ⟶ (Y, y)` is a morphism `f : X ⟶ Y` in `C`, so `F.map f` takes `x` to `y`.
## Implementation notes
This construction is equivalent to a special case of a comma construction, so this is mostly just a
more convenient API. We prove the equivalence in
`category_theory.category_of_elements.structured_arrow_equivalence`.
## References
* [Emily Riehl, *Category Theory in Context*, Section 2.4][riehl2017]
* <https://en.wikipedia.org/wiki/Category_of_elements>
* <https://ncatlab.org/nlab/show/category+of+elements>
## Tags
category of elements, Grothendieck construction, comma category
-/
namespace category_theory
universes w v u
variables {C : Type u} [category.{v} C]
/--
The type of objects for the category of elements of a functor `F : C ⥤ Type`
is a pair `(X : C, x : F.obj X)`.
-/
@[nolint has_nonempty_instance]
def functor.elements (F : C ⥤ Type w) := (Σ c : C, F.obj c)
/-- The category structure on `F.elements`, for `F : C ⥤ Type`.
A morphism `(X, x) ⟶ (Y, y)` is a morphism `f : X ⟶ Y` in `C`, so `F.map f` takes `x` to `y`.
-/
instance category_of_elements (F : C ⥤ Type w) : category.{v} F.elements :=
{ hom := λ p q, { f : p.1 ⟶ q.1 // (F.map f) p.2 = q.2 },
id := λ p, ⟨𝟙 p.1, by obviously⟩,
comp := λ p q r f g, ⟨f.val ≫ g.val, by obviously⟩ }
namespace category_of_elements
@[ext]
lemma ext (F : C ⥤ Type w) {x y : F.elements} (f g : x ⟶ y) (w : f.val = g.val) : f = g :=
subtype.ext_val w
@[simp] lemma comp_val {F : C ⥤ Type w} {p q r : F.elements} {f : p ⟶ q} {g : q ⟶ r} :
(f ≫ g).val = f.val ≫ g.val := rfl
@[simp] lemma id_val {F : C ⥤ Type w} {p : F.elements} : (𝟙 p : p ⟶ p).val = 𝟙 p.1 := rfl
end category_of_elements
noncomputable
instance groupoid_of_elements {G : Type u} [groupoid.{v} G] (F : G ⥤ Type w) :
groupoid F.elements :=
{ inv := λ p q f, ⟨inv f.val,
calc F.map (inv f.val) q.2 = F.map (inv f.val) (F.map f.val p.2) : by rw f.2
... = (F.map f.val ≫ F.map (inv f.val)) p.2 : rfl
... = p.2 : by {rw ← F.map_comp, simp} ⟩,
inv_comp' := λ _ _ _, by { ext, simp },
comp_inv' := λ _ _ _, by { ext, simp } }
namespace category_of_elements
variable (F : C ⥤ Type w)
/-- The functor out of the category of elements which forgets the element. -/
@[simps]
def π : F.elements ⥤ C :=
{ obj := λ X, X.1,
map := λ X Y f, f.val }
/--
A natural transformation between functors induces a functor between the categories of elements.
-/
@[simps]
def map {F₁ F₂ : C ⥤ Type w} (α : F₁ ⟶ F₂) : F₁.elements ⥤ F₂.elements :=
{ obj := λ t, ⟨t.1, α.app t.1 t.2⟩,
map := λ t₁ t₂ k, ⟨k.1, by simpa [←k.2] using (functor_to_types.naturality _ _ α k.1 t₁.2).symm⟩ }
@[simp] lemma map_π {F₁ F₂ : C ⥤ Type w} (α : F₁ ⟶ F₂) : map α ⋙ π F₂ = π F₁ := rfl
/-- The forward direction of the equivalence `F.elements ≅ (*, F)`. -/
def to_structured_arrow : F.elements ⥤ structured_arrow punit F :=
{ obj := λ X, structured_arrow.mk (λ _, X.2),
map := λ X Y f, structured_arrow.hom_mk f.val (by tidy) }
@[simp] lemma to_structured_arrow_obj (X) :
(to_structured_arrow F).obj X = { left := ⟨⟨⟩⟩, right := X.1, hom := λ _, X.2 } := rfl
@[simp] lemma to_comma_map_right {X Y} (f : X ⟶ Y) :
((to_structured_arrow F).map f).right = f.val := rfl
/-- The reverse direction of the equivalence `F.elements ≅ (*, F)`. -/
def from_structured_arrow : structured_arrow punit F ⥤ F.elements :=
{ obj := λ X, ⟨X.right, X.hom (punit.star)⟩,
map := λ X Y f, ⟨f.right, congr_fun f.w'.symm punit.star⟩ }
@[simp] lemma from_structured_arrow_obj (X) :
(from_structured_arrow F).obj X = ⟨X.right, X.hom (punit.star)⟩ := rfl
@[simp] lemma from_structured_arrow_map {X Y} (f : X ⟶ Y) :
(from_structured_arrow F).map f = ⟨f.right, congr_fun f.w'.symm punit.star⟩ := rfl
/-- The equivalence between the category of elements `F.elements`
and the comma category `(*, F)`. -/
@[simps]
def structured_arrow_equivalence : F.elements ≌ structured_arrow punit F :=
equivalence.mk (to_structured_arrow F) (from_structured_arrow F)
(nat_iso.of_components (λ X, eq_to_iso (by tidy)) (by tidy))
(nat_iso.of_components
(λ X, { hom := { right := 𝟙 _ }, inv := { right := 𝟙 _ } })
(by tidy))
open opposite
/--
The forward direction of the equivalence `F.elementsᵒᵖ ≅ (yoneda, F)`,
given by `category_theory.yoneda_sections`.
-/
@[simps]
def to_costructured_arrow (F : Cᵒᵖ ⥤ Type v) : (F.elements)ᵒᵖ ⥤ costructured_arrow yoneda F :=
{ obj := λ X, costructured_arrow.mk
((yoneda_sections (unop (unop X).fst) F).inv (ulift.up (unop X).2)),
map := λ X Y f,
begin
fapply costructured_arrow.hom_mk,
exact f.unop.val.unop,
ext y,
simp only [costructured_arrow.mk_hom_eq_self, yoneda_map_app, functor_to_types.comp, op_comp,
yoneda_sections_inv_app, functor_to_types.map_comp_apply, quiver.hom.op_unop,
subtype.val_eq_coe],
congr,
exact f.unop.2,
end }
/--
The reverse direction of the equivalence `F.elementsᵒᵖ ≅ (yoneda, F)`,
given by `category_theory.yoneda_equiv`.
-/
@[simps]
def from_costructured_arrow (F : Cᵒᵖ ⥤ Type v) : (costructured_arrow yoneda F)ᵒᵖ ⥤ F.elements :=
{ obj := λ X, ⟨op (unop X).1, yoneda_equiv.1 (unop X).3⟩,
map := λ X Y f, ⟨f.unop.1.op,
begin
convert (congr_fun ((unop X).hom.naturality f.unop.left.op) (𝟙 _)).symm,
simp only [equiv.to_fun_as_coe, quiver.hom.unop_op, yoneda_equiv_apply,
types_comp_apply, category.comp_id, yoneda_obj_map],
have : yoneda.map f.unop.left ≫ (unop X).hom = (unop Y).hom,
{ convert f.unop.3, erw category.comp_id },
erw ← this,
simp only [yoneda_map_app, functor_to_types.comp],
erw category.id_comp
end ⟩}
@[simp]
lemma from_costructured_arrow_obj_mk (F : Cᵒᵖ ⥤ Type v) {X : C} (f : yoneda.obj X ⟶ F) :
(from_costructured_arrow F).obj (op (costructured_arrow.mk f)) = ⟨op X, yoneda_equiv.1 f⟩ := rfl
/-- The unit of the equivalence `F.elementsᵒᵖ ≅ (yoneda, F)` is indeed iso. -/
lemma from_to_costructured_arrow_eq (F : Cᵒᵖ ⥤ Type v) :
(to_costructured_arrow F).right_op ⋙ from_costructured_arrow F = 𝟭 _ :=
begin
apply functor.ext,
intros X Y f,
have : ∀ {a b : F.elements} (H : a = b),
↑(eq_to_hom H) = eq_to_hom (show a.fst = b.fst, by { cases H, refl }) :=
λ _ _ H, by { cases H, refl },
ext, simp[this],
tidy
end
/-- The counit of the equivalence `F.elementsᵒᵖ ≅ (yoneda, F)` is indeed iso. -/
lemma to_from_costructured_arrow_eq (F : Cᵒᵖ ⥤ Type v) :
(from_costructured_arrow F).right_op ⋙ to_costructured_arrow F = 𝟭 _ :=
begin
apply functor.hext,
{ intro X, cases X, cases X_right,
simp only [functor.id_obj, functor.right_op_obj,
to_costructured_arrow_obj, functor.comp_obj, costructured_arrow.mk],
congr,
ext x f,
convert congr_fun (X_hom.naturality f.op).symm (𝟙 X_left),
simp only [quiver.hom.unop_op, yoneda_obj_map],
erw category.comp_id },
intros X Y f,
rcases X with ⟨X_left, ⟨⟨⟩⟩⟩, rcases Y with ⟨Y_left, ⟨⟨⟩⟩⟩, cases f,
simp [costructured_arrow.hom_mk],
delta costructured_arrow.mk,
congr,
{ ext x f,
convert congr_fun (X_hom.naturality f.op).symm (𝟙 X_left),
simp only [quiver.hom.unop_op, category_theory.yoneda_obj_map],
erw category.comp_id },
{ ext x f,
convert congr_fun (Y_hom.naturality f.op).symm (𝟙 Y_left),
simp only [quiver.hom.unop_op, category_theory.yoneda_obj_map],
erw category.comp_id },
simp,
exact proof_irrel_heq _ _,
end
/-- The equivalence `F.elementsᵒᵖ ≅ (yoneda, F)` given by yoneda lemma. -/
@[simps] def costructured_arrow_yoneda_equivalence (F : Cᵒᵖ ⥤ Type v) :
(F.elements)ᵒᵖ ≌ costructured_arrow yoneda F :=
equivalence.mk (to_costructured_arrow F) (from_costructured_arrow F).right_op
(nat_iso.op (eq_to_iso (from_to_costructured_arrow_eq F)))
(eq_to_iso $ to_from_costructured_arrow_eq F)
/--
The equivalence `(-.elements)ᵒᵖ ≅ (yoneda, -)` of is actually a natural isomorphism of functors.
-/
lemma costructured_arrow_yoneda_equivalence_naturality {F₁ F₂ : Cᵒᵖ ⥤ Type v}
(α : F₁ ⟶ F₂) : (map α).op ⋙ to_costructured_arrow F₂ =
to_costructured_arrow F₁ ⋙ costructured_arrow.map α :=
begin
fapply functor.ext,
{ intro X,
simp only [costructured_arrow.map_mk, to_costructured_arrow_obj,
functor.op_obj, functor.comp_obj],
congr,
ext x f,
simpa using congr_fun (α.naturality f.op).symm (unop X).snd },
{ intros X Y f, ext,
have : ∀ {F : Cᵒᵖ ⥤ Type v} {a b : costructured_arrow yoneda F} (H : a = b),
comma_morphism.left (eq_to_hom H) = eq_to_hom (show a.left = b.left, by { cases H, refl }) :=
λ _ _ _ H, by { cases H, refl },
simp [this] }
end
end category_of_elements
end category_theory
|
c225c9e18fb1ba97bc2ee2f29f0fe0f758c1fcde
|
8cb37a089cdb4af3af9d8bf1002b417e407a8e9e
|
/tests/lean/run/local_shadowing_projection.lean
|
19687a266925855d5248e2fe47ae25058fa69c93
|
[
"Apache-2.0"
] |
permissive
|
kbuzzard/lean
|
ae3c3db4bb462d750dbf7419b28bafb3ec983ef7
|
ed1788fd674bb8991acffc8fca585ec746711928
|
refs/heads/master
| 1,620,983,366,617
| 1,618,937,600,000
| 1,618,937,600,000
| 359,886,396
| 1
| 0
|
Apache-2.0
| 1,618,936,987,000
| 1,618,936,987,000
| null |
UTF-8
|
Lean
| false
| false
| 129
|
lean
|
def prod.cmp (a b : nat × nat) : ordering :=
cmp a b
namespace prod
def foo (a : nat × nat) (cmp : nat) :=
a.cmp
end prod
|
f54ce4517f681006f4397f1df120fd5811044183
|
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
|
/tests/lean/file_not_found.lean
|
8002cc2ce2a8af4f87bda0c6a8e3f0ead782c1c9
|
[
"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
| 580
|
lean
|
prelude
import Init.System.IO
open IO.FS
#eval (discard $ IO.FS.Handle.mk "non-existent-file.txt" Mode.read : IO Unit)
#eval do condM (IO.fileExists "readonly.txt")
(pure ())
(IO.FS.withFile "readonly.txt" Mode.write $ fun _ => pure ());
IO.setAccessRights "readonly.txt" { user := { read := true } };
(pure () : IO Unit)
#eval (discard $ IO.FS.Handle.mk "readonly.txt" Mode.write : IO Unit)
#eval do h ← IO.FS.Handle.mk "readonly.txt" Mode.read;
h.putStr "foo";
IO.println "foo";
(pure () : IO Unit)
|
17b1cca3302f42d3898962b56880fba07fc442e7
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/fun_like/basic.lean
|
dd8d40155d436bdef0dbc34a9535a1898cd33a19
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 7,238
|
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 logic.function.basic
import tactic.lint
import tactic.norm_cast
/-!
# Typeclass for a type `F` with an injective map to `A → B`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This typeclass is primarily for use by homomorphisms like `monoid_hom` and `linear_map`.
## Basic usage of `fun_like`
A typical type of morphisms should be declared as:
```
structure my_hom (A B : Type*) [my_class A] [my_class B] :=
(to_fun : A → B)
(map_op' : ∀ {x y : A}, to_fun (my_class.op x y) = my_class.op (to_fun x) (to_fun y))
namespace my_hom
variables (A B : Type*) [my_class A] [my_class B]
-- This instance is optional if you follow the "morphism class" design below:
instance : fun_like (my_hom A B) A (λ _, B) :=
{ coe := my_hom.to_fun, coe_injective' := λ f g h, by cases f; cases g; congr' }
/-- Helper instance for when there's too many metavariables to apply
`fun_like.has_coe_to_fun` directly. -/
instance : has_coe_to_fun (my_hom A B) (λ _, A → B) := fun_like.has_coe_to_fun
@[simp] lemma to_fun_eq_coe {f : my_hom A B} : f.to_fun = (f : A → B) := rfl
@[ext] theorem ext {f g : my_hom A B} (h : ∀ x, f x = g x) : f = g := fun_like.ext f g h
/-- Copy of a `my_hom` with a new `to_fun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : my_hom A B) (f' : A → B) (h : f' = ⇑f) : my_hom A B :=
{ to_fun := f',
map_op' := h.symm ▸ f.map_op' }
end my_hom
```
This file will then provide a `has_coe_to_fun` instance and various
extensionality and simp lemmas.
## Morphism classes extending `fun_like`
The `fun_like` design provides further benefits if you put in a bit more work.
The first step is to extend `fun_like` to create a class of those types satisfying
the axioms of your new type of morphisms.
Continuing the example above:
```
section
set_option old_structure_cmd true
/-- `my_hom_class F A B` states that `F` is a type of `my_class.op`-preserving morphisms.
You should extend this class when you extend `my_hom`. -/
class my_hom_class (F : Type*) (A B : out_param $ Type*) [my_class A] [my_class B]
extends fun_like F A (λ _, B) :=
(map_op : ∀ (f : F) (x y : A), f (my_class.op x y) = my_class.op (f x) (f y))
end
@[simp] lemma map_op {F A B : Type*} [my_class A] [my_class B] [my_hom_class F A B]
(f : F) (x y : A) : f (my_class.op x y) = my_class.op (f x) (f y) :=
my_hom_class.map_op
-- You can replace `my_hom.fun_like` with the below instance:
instance : my_hom_class (my_hom A B) A B :=
{ coe := my_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_op := my_hom.map_op' }
-- [Insert `has_coe_to_fun`, `to_fun_eq_coe`, `ext` and `copy` here]
```
The second step is to add instances of your new `my_hom_class` for all types extending `my_hom`.
Typically, you can just declare a new class analogous to `my_hom_class`:
```
structure cooler_hom (A B : Type*) [cool_class A] [cool_class B]
extends my_hom A B :=
(map_cool' : to_fun cool_class.cool = cool_class.cool)
section
set_option old_structure_cmd true
class cooler_hom_class (F : Type*) (A B : out_param $ Type*) [cool_class A] [cool_class B]
extends my_hom_class F A B :=
(map_cool : ∀ (f : F), f cool_class.cool = cool_class.cool)
end
@[simp] lemma map_cool {F A B : Type*} [cool_class A] [cool_class B] [cooler_hom_class F A B]
(f : F) : f cool_class.cool = cool_class.cool :=
my_hom_class.map_op
-- You can also replace `my_hom.fun_like` with the below instance:
instance : cool_hom_class (cool_hom A B) A B :=
{ coe := cool_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_op := cool_hom.map_op',
map_cool := cool_hom.map_cool' }
-- [Insert `has_coe_to_fun`, `to_fun_eq_coe`, `ext` and `copy` here]
```
Then any declaration taking a specific type of morphisms as parameter can instead take the
class you just defined:
```
-- Compare with: lemma do_something (f : my_hom A B) : sorry := sorry
lemma do_something {F : Type*} [my_hom_class F A B] (f : F) : sorry := sorry
```
This means anything set up for `my_hom`s will automatically work for `cool_hom_class`es,
and defining `cool_hom_class` only takes a constant amount of effort,
instead of linearly increasing the work per `my_hom`-related declaration.
-/
-- This instance should have low priority, to ensure we follow the chain
-- `fun_like → has_coe_to_fun`
attribute [instance, priority 10] coe_fn_trans
/-- The class `fun_like F α β` expresses that terms of type `F` have an
injective coercion to functions from `α` to `β`.
This typeclass is used in the definition of the homomorphism typeclasses,
such as `zero_hom_class`, `mul_hom_class`, `monoid_hom_class`, ....
-/
class fun_like (F : Sort*) (α : out_param Sort*) (β : out_param $ α → Sort*) :=
(coe : F → Π a : α, β a)
(coe_injective' : function.injective coe)
section dependent
/-! ### `fun_like F α β` where `β` depends on `a : α` -/
variables (F α : Sort*) (β : α → Sort*)
namespace fun_like
variables {F α β} [i : fun_like F α β]
include i
@[priority 100, -- Give this a priority between `coe_fn_trans` and the default priority
nolint dangerous_instance] -- `α` and `β` are out_params, so this instance should not be dangerous
instance : has_coe_to_fun F (λ _, Π a : α, β a) := { coe := fun_like.coe }
@[simp] lemma coe_eq_coe_fn : (fun_like.coe : F → Π a : α, β a) = coe_fn := rfl
theorem coe_injective : function.injective (coe_fn : F → Π a : α, β a) :=
fun_like.coe_injective'
@[simp, norm_cast]
theorem coe_fn_eq {f g : F} : (f : Π a : α, β a) = (g : Π a : α, β a) ↔ f = g :=
⟨λ h, @coe_injective _ _ _ i _ _ h, λ h, by cases h; refl⟩
theorem ext' {f g : F} (h : (f : Π a : α, β a) = (g : Π a : α, β a)) : f = g :=
coe_injective h
theorem ext'_iff {f g : F} : f = g ↔ ((f : Π a : α, β a) = (g : Π a : α, β a)) :=
coe_fn_eq.symm
theorem ext (f g : F) (h : ∀ (x : α), f x = g x) : f = g :=
coe_injective (funext h)
theorem ext_iff {f g : F} : f = g ↔ (∀ x, f x = g x) :=
coe_fn_eq.symm.trans function.funext_iff
protected lemma congr_fun {f g : F} (h₁ : f = g) (x : α) : f x = g x :=
congr_fun (congr_arg _ h₁) x
lemma ne_iff {f g : F} : f ≠ g ↔ ∃ a, f a ≠ g a :=
ext_iff.not.trans not_forall
lemma exists_ne {f g : F} (h : f ≠ g) : ∃ x, f x ≠ g x :=
ne_iff.mp h
/-- This is not an instance to avoid slowing down every single `subsingleton` typeclass search.-/
lemma subsingleton_cod [∀ a, subsingleton (β a)] : subsingleton F :=
⟨λ f g, coe_injective $ subsingleton.elim _ _⟩
end fun_like
end dependent
section non_dependent
/-! ### `fun_like F α (λ _, β)` where `β` does not depend on `a : α` -/
variables {F α β : Sort*} [i : fun_like F α (λ _, β)]
include i
namespace fun_like
protected lemma congr {f g : F} {x y : α} (h₁ : f = g) (h₂ : x = y) : f x = g y :=
congr (congr_arg _ h₁) h₂
protected lemma congr_arg (f : F) {x y : α} (h₂ : x = y) : f x = f y :=
congr_arg _ h₂
end fun_like
end non_dependent
|
36c807d674a5518a66408f0db3934284a589f16a
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/topology/alexandroff.lean
|
6dacac3369e96ebb42f2f7ddb92b26e6f02ba644
|
[
"Apache-2.0"
] |
permissive
|
urkud/mathlib
|
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
|
6379d39e6b5b279df9715f8011369a301b634e41
|
refs/heads/master
| 1,658,425,342,662
| 1,658,078,703,000
| 1,658,078,703,000
| 186,910,338
| 0
| 0
|
Apache-2.0
| 1,568,512,083,000
| 1,557,958,709,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 18,663
|
lean
|
/-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang, Yury Kudryashov
-/
import topology.separation
import topology.sets.opens
/-!
# The Alexandroff Compactification
We construct the Alexandroff compactification (the one-point compactification) of an arbitrary
topological space `X` and prove some properties inherited from `X`.
## Main definitions
* `alexandroff`: the Alexandroff compactification, we use coercion for the canonical embedding
`X → alexandroff X`; when `X` is already compact, the compactification adds an isolated point
to the space.
* `alexandroff.infty`: the extra point
## Main results
* The topological structure of `alexandroff X`
* The connectedness of `alexandroff X` for a noncompact, preconnected `X`
* `alexandroff X` is `T₀` for a T₀ space `X`
* `alexandroff X` is `T₁` for a T₁ space `X`
* `alexandroff X` is normal if `X` is a locally compact Hausdorff space
## Tags
one-point compactification, compactness
-/
open set filter
open_locale classical topological_space filter
/-!
### Definition and basic properties
In this section we define `alexandroff X` to be the disjoint union of `X` and `∞`, implemented as
`option X`. Then we restate some lemmas about `option X` for `alexandroff X`.
-/
variables {X : Type*}
/-- The Alexandroff extension of an arbitrary topological space `X` -/
def alexandroff (X : Type*) := option X
/-- The repr uses the notation from the `alexandroff` locale. -/
instance [has_repr X] : has_repr (alexandroff X) :=
⟨λ o, match o with | none := "∞" | (some a) := "↑" ++ repr a end⟩
namespace alexandroff
/-- The point at infinity -/
def infty : alexandroff X := none
localized "notation `∞` := alexandroff.infty" in alexandroff
instance : has_coe_t X (alexandroff X) := ⟨option.some⟩
instance : inhabited (alexandroff X) := ⟨∞⟩
instance [fintype X] : fintype (alexandroff X) := option.fintype
instance infinite [infinite X] : infinite (alexandroff X) := option.infinite
lemma coe_injective : function.injective (coe : X → alexandroff X) :=
option.some_injective X
@[norm_cast] lemma coe_eq_coe {x y : X} : (x : alexandroff X) = y ↔ x = y :=
coe_injective.eq_iff
@[simp] lemma coe_ne_infty (x : X) : (x : alexandroff X) ≠ ∞ .
@[simp] lemma infty_ne_coe (x : X) : ∞ ≠ (x : alexandroff X) .
/-- Recursor for `alexandroff` using the preferred forms `∞` and `↑x`. -/
@[elab_as_eliminator]
protected def rec (C : alexandroff X → Sort*) (h₁ : C ∞) (h₂ : Π x : X, C x) :
Π (z : alexandroff X), C z :=
option.rec h₁ h₂
lemma is_compl_range_coe_infty : is_compl (range (coe : X → alexandroff X)) {∞} :=
is_compl_range_some_none X
@[simp] lemma range_coe_union_infty : (range (coe : X → alexandroff X) ∪ {∞}) = univ :=
range_some_union_none X
@[simp] lemma range_coe_inter_infty : (range (coe : X → alexandroff X) ∩ {∞}) = ∅ :=
range_some_inter_none X
@[simp] lemma compl_range_coe : (range (coe : X → alexandroff X))ᶜ = {∞} :=
compl_range_some X
lemma compl_infty : ({∞}ᶜ : set (alexandroff X)) = range (coe : X → alexandroff X) :=
(@is_compl_range_coe_infty X).symm.compl_eq
lemma compl_image_coe (s : set X) : (coe '' s : set (alexandroff X))ᶜ = coe '' sᶜ ∪ {∞} :=
by rw [coe_injective.compl_image_eq, compl_range_coe]
lemma ne_infty_iff_exists {x : alexandroff X} :
x ≠ ∞ ↔ ∃ (y : X), (y : alexandroff X) = x :=
by induction x using alexandroff.rec; simp
instance : can_lift (alexandroff X) X :=
{ coe := coe,
cond := λ x, x ≠ ∞,
prf := λ x, ne_infty_iff_exists.1 }
lemma not_mem_range_coe_iff {x : alexandroff X} :
x ∉ range (coe : X → alexandroff X) ↔ x = ∞ :=
by rw [← mem_compl_iff, compl_range_coe, mem_singleton_iff]
lemma infty_not_mem_range_coe : ∞ ∉ range (coe : X → alexandroff X) :=
not_mem_range_coe_iff.2 rfl
lemma infty_not_mem_image_coe {s : set X} : ∞ ∉ (coe : X → alexandroff X) '' s :=
not_mem_subset (image_subset_range _ _) infty_not_mem_range_coe
@[simp] lemma coe_preimage_infty : (coe : X → alexandroff X) ⁻¹' {∞} = ∅ :=
by { ext, simp }
/-!
### Topological space structure on `alexandroff X`
We define a topological space structure on `alexandroff X` so that `s` is open if and only if
* `coe ⁻¹' s` is open in `X`;
* if `∞ ∈ s`, then `(coe ⁻¹' s)ᶜ` is compact.
Then we reformulate this definition in a few different ways, and prove that
`coe : X → alexandroff X` is an open embedding. If `X` is not a compact space, then we also prove
that `coe` has dense range, so it is a dense embedding.
-/
variables [topological_space X]
instance : topological_space (alexandroff X) :=
{ is_open := λ s, (∞ ∈ s → is_compact ((coe : X → alexandroff X) ⁻¹' s)ᶜ) ∧
is_open ((coe : X → alexandroff X) ⁻¹' s),
is_open_univ := by simp,
is_open_inter := λ s t,
begin
rintros ⟨hms, hs⟩ ⟨hmt, ht⟩,
refine ⟨_, hs.inter ht⟩,
rintros ⟨hms', hmt'⟩,
simpa [compl_inter] using (hms hms').union (hmt hmt')
end,
is_open_sUnion := λ S ho,
begin
suffices : is_open (coe ⁻¹' ⋃₀ S : set X),
{ refine ⟨_, this⟩,
rintro ⟨s, hsS : s ∈ S, hs : ∞ ∈ s⟩,
refine compact_of_is_closed_subset ((ho s hsS).1 hs) this.is_closed_compl _,
exact compl_subset_compl.mpr (preimage_mono $ subset_sUnion_of_mem hsS) },
rw [preimage_sUnion],
exact is_open_bUnion (λ s hs, (ho s hs).2)
end }
variables {s : set (alexandroff X)} {t : set X}
lemma is_open_def :
is_open s ↔ (∞ ∈ s → is_compact (coe ⁻¹' s : set X)ᶜ) ∧ is_open (coe ⁻¹' s : set X) :=
iff.rfl
lemma is_open_iff_of_mem' (h : ∞ ∈ s) :
is_open s ↔ is_compact (coe ⁻¹' s : set X)ᶜ ∧ is_open (coe ⁻¹' s : set X) :=
by simp [is_open_def, h]
lemma is_open_iff_of_mem (h : ∞ ∈ s) :
is_open s ↔ is_closed (coe ⁻¹' s : set X)ᶜ ∧ is_compact (coe ⁻¹' s : set X)ᶜ :=
by simp only [is_open_iff_of_mem' h, is_closed_compl_iff, and.comm]
lemma is_open_iff_of_not_mem (h : ∞ ∉ s) :
is_open s ↔ is_open (coe ⁻¹' s : set X) :=
by simp [is_open_def, h]
lemma is_closed_iff_of_mem (h : ∞ ∈ s) :
is_closed s ↔ is_closed (coe ⁻¹' s : set X) :=
have ∞ ∉ sᶜ, from λ H, H h,
by rw [← is_open_compl_iff, is_open_iff_of_not_mem this, ← is_open_compl_iff, preimage_compl]
lemma is_closed_iff_of_not_mem (h : ∞ ∉ s) :
is_closed s ↔ is_closed (coe ⁻¹' s : set X) ∧ is_compact (coe ⁻¹' s : set X) :=
by rw [← is_open_compl_iff, is_open_iff_of_mem (mem_compl h), ← preimage_compl, compl_compl]
@[simp] lemma is_open_image_coe {s : set X} :
is_open (coe '' s : set (alexandroff X)) ↔ is_open s :=
by rw [is_open_iff_of_not_mem infty_not_mem_image_coe, preimage_image_eq _ coe_injective]
lemma is_open_compl_image_coe {s : set X} :
is_open (coe '' s : set (alexandroff X))ᶜ ↔ is_closed s ∧ is_compact s :=
begin
rw [is_open_iff_of_mem, ← preimage_compl, compl_compl, preimage_image_eq _ coe_injective],
exact infty_not_mem_image_coe
end
@[simp] lemma is_closed_image_coe {s : set X} :
is_closed (coe '' s : set (alexandroff X)) ↔ is_closed s ∧ is_compact s :=
by rw [← is_open_compl_iff, is_open_compl_image_coe]
/-- An open set in `alexandroff X` constructed from a closed compact set in `X` -/
def opens_of_compl (s : set X) (h₁ : is_closed s) (h₂ : is_compact s) :
topological_space.opens (alexandroff X) :=
⟨(coe '' s)ᶜ, is_open_compl_image_coe.2 ⟨h₁, h₂⟩⟩
lemma infty_mem_opens_of_compl {s : set X} (h₁ : is_closed s) (h₂ : is_compact s) :
∞ ∈ opens_of_compl s h₁ h₂ :=
mem_compl infty_not_mem_image_coe
@[continuity] lemma continuous_coe : continuous (coe : X → alexandroff X) :=
continuous_def.mpr (λ s hs, hs.right)
lemma is_open_map_coe : is_open_map (coe : X → alexandroff X) :=
λ s, is_open_image_coe.2
lemma open_embedding_coe : open_embedding (coe : X → alexandroff X) :=
open_embedding_of_continuous_injective_open continuous_coe coe_injective is_open_map_coe
lemma is_open_range_coe : is_open (range (coe : X → alexandroff X)) :=
open_embedding_coe.open_range
lemma is_closed_infty : is_closed ({∞} : set (alexandroff X)) :=
by { rw [← compl_range_coe, is_closed_compl_iff], exact is_open_range_coe }
lemma nhds_coe_eq (x : X) : 𝓝 ↑x = map (coe : X → alexandroff X) (𝓝 x) :=
(open_embedding_coe.map_nhds_eq x).symm
lemma nhds_within_coe_image (s : set X) (x : X) :
𝓝[coe '' s] (x : alexandroff X) = map coe (𝓝[s] x) :=
(open_embedding_coe.to_embedding.map_nhds_within_eq _ _).symm
lemma nhds_within_coe (s : set (alexandroff X)) (x : X) :
𝓝[s] ↑x = map coe (𝓝[coe ⁻¹' s] x) :=
(open_embedding_coe.map_nhds_within_preimage_eq _ _).symm
lemma comap_coe_nhds (x : X) : comap (coe : X → alexandroff X) (𝓝 x) = 𝓝 x :=
(open_embedding_coe.to_inducing.nhds_eq_comap x).symm
/-- If `x` is not an isolated point of `X`, then `x : alexandroff X` is not an isolated point
of `alexandroff X`. -/
instance nhds_within_compl_coe_ne_bot (x : X) [h : ne_bot (𝓝[≠] x)] :
ne_bot (𝓝[≠] (x : alexandroff X)) :=
by simpa [nhds_within_coe, preimage, coe_eq_coe] using h.map coe
lemma nhds_within_compl_infty_eq : 𝓝[≠] (∞ : alexandroff X) = map coe (coclosed_compact X) :=
begin
refine (nhds_within_basis_open ∞ _).ext (has_basis_coclosed_compact.map _) _ _,
{ rintro s ⟨hs, hso⟩,
refine ⟨_, (is_open_iff_of_mem hs).mp hso, _⟩,
simp },
{ rintro s ⟨h₁, h₂⟩,
refine ⟨_, ⟨mem_compl infty_not_mem_image_coe, is_open_compl_image_coe.2 ⟨h₁, h₂⟩⟩, _⟩,
simp [compl_image_coe, ← diff_eq, subset_preimage_image] }
end
/-- If `X` is a non-compact space, then `∞` is not an isolated point of `alexandroff X`. -/
instance nhds_within_compl_infty_ne_bot [noncompact_space X] :
ne_bot (𝓝[≠] (∞ : alexandroff X)) :=
by { rw nhds_within_compl_infty_eq, apply_instance }
@[priority 900]
instance nhds_within_compl_ne_bot [∀ x : X, ne_bot (𝓝[≠] x)] [noncompact_space X]
(x : alexandroff X) : ne_bot (𝓝[≠] x) :=
alexandroff.rec _ alexandroff.nhds_within_compl_infty_ne_bot
(λ y, alexandroff.nhds_within_compl_coe_ne_bot y) x
lemma nhds_infty_eq : 𝓝 (∞ : alexandroff X) = map coe (coclosed_compact X) ⊔ pure ∞ :=
by rw [← nhds_within_compl_infty_eq, nhds_within_compl_singleton_sup_pure]
lemma has_basis_nhds_infty :
(𝓝 (∞ : alexandroff X)).has_basis (λ s : set X, is_closed s ∧ is_compact s)
(λ s, coe '' sᶜ ∪ {∞}) :=
begin
rw nhds_infty_eq,
exact (has_basis_coclosed_compact.map _).sup_pure _
end
@[simp] lemma comap_coe_nhds_infty : comap (coe : X → alexandroff X) (𝓝 ∞) = coclosed_compact X :=
by simp [nhds_infty_eq, comap_sup, comap_map coe_injective]
lemma le_nhds_infty {f : filter (alexandroff X)} :
f ≤ 𝓝 ∞ ↔ ∀ s : set X, is_closed s → is_compact s → coe '' sᶜ ∪ {∞} ∈ f :=
by simp only [has_basis_nhds_infty.ge_iff, and_imp]
lemma ultrafilter_le_nhds_infty {f : ultrafilter (alexandroff X)} :
(f : filter (alexandroff X)) ≤ 𝓝 ∞ ↔ ∀ s : set X, is_closed s → is_compact s → coe '' s ∉ f :=
by simp only [le_nhds_infty, ← compl_image_coe, ultrafilter.mem_coe,
ultrafilter.compl_mem_iff_not_mem]
lemma tendsto_nhds_infty' {α : Type*} {f : alexandroff X → α} {l : filter α} :
tendsto f (𝓝 ∞) l ↔ tendsto f (pure ∞) l ∧ tendsto (f ∘ coe) (coclosed_compact X) l :=
by simp [nhds_infty_eq, and_comm]
lemma tendsto_nhds_infty {α : Type*} {f : alexandroff X → α} {l : filter α} :
tendsto f (𝓝 ∞) l ↔
∀ s ∈ l, f ∞ ∈ s ∧ ∃ t : set X, is_closed t ∧ is_compact t ∧ maps_to (f ∘ coe) tᶜ s :=
tendsto_nhds_infty'.trans $ by simp only [tendsto_pure_left,
has_basis_coclosed_compact.tendsto_left_iff, forall_and_distrib, and_assoc, exists_prop]
lemma continuous_at_infty' {Y : Type*} [topological_space Y] {f : alexandroff X → Y} :
continuous_at f ∞ ↔ tendsto (f ∘ coe) (coclosed_compact X) (𝓝 (f ∞)) :=
tendsto_nhds_infty'.trans $ and_iff_right (tendsto_pure_nhds _ _)
lemma continuous_at_infty {Y : Type*} [topological_space Y] {f : alexandroff X → Y} :
continuous_at f ∞ ↔
∀ s ∈ 𝓝 (f ∞), ∃ t : set X, is_closed t ∧ is_compact t ∧ maps_to (f ∘ coe) tᶜ s :=
continuous_at_infty'.trans $
by simp only [has_basis_coclosed_compact.tendsto_left_iff, exists_prop, and_assoc]
lemma continuous_at_coe {Y : Type*} [topological_space Y] {f : alexandroff X → Y} {x : X} :
continuous_at f x ↔ continuous_at (f ∘ coe) x :=
by rw [continuous_at, nhds_coe_eq, tendsto_map'_iff, continuous_at]
/-- If `X` is not a compact space, then the natural embedding `X → alexandroff X` has dense range.
-/
lemma dense_range_coe [noncompact_space X] :
dense_range (coe : X → alexandroff X) :=
begin
rw [dense_range, ← compl_infty],
exact dense_compl_singleton _
end
lemma dense_embedding_coe [noncompact_space X] :
dense_embedding (coe : X → alexandroff X) :=
{ dense := dense_range_coe, .. open_embedding_coe }
@[simp] lemma specializes_coe {x y : X} : (x : alexandroff X) ⤳ y ↔ x ⤳ y :=
open_embedding_coe.to_inducing.specializes_iff
@[simp] lemma inseparable_coe {x y : X} : inseparable (x : alexandroff X) y ↔ inseparable x y :=
open_embedding_coe.to_inducing.inseparable_iff
lemma not_specializes_infty_coe {x : X} : ¬specializes ∞ (x : alexandroff X) :=
is_closed_infty.not_specializes rfl (coe_ne_infty x)
lemma not_inseparable_infty_coe {x : X} : ¬inseparable ∞ (x : alexandroff X) :=
λ h, not_specializes_infty_coe h.specializes
lemma not_inseparable_coe_infty {x : X} : ¬inseparable (x : alexandroff X) ∞ :=
λ h, not_specializes_infty_coe h.specializes'
lemma inseparable_iff {x y : alexandroff X} :
inseparable x y ↔ x = ∞ ∧ y = ∞ ∨ ∃ x' : X, x = x' ∧ ∃ y' : X, y = y' ∧ inseparable x' y' :=
by induction x using alexandroff.rec; induction y using alexandroff.rec;
simp [not_inseparable_infty_coe, not_inseparable_coe_infty, coe_eq_coe]
/-!
### Compactness and separation properties
In this section we prove that `alexandroff X` is a compact space; it is a T₀ (resp., T₁) space if
the original space satisfies the same separation axiom. If the original space is a locally compact
Hausdorff space, then `alexandroff X` is a normal (hence, T₃ and Hausdorff) space.
Finally, if the original space `X` is *not* compact and is a preconnected space, then
`alexandroff X` is a connected space.
-/
/-- For any topological space `X`, its one point compactification is a compact space. -/
instance : compact_space (alexandroff X) :=
{ compact_univ :=
begin
have : tendsto (coe : X → alexandroff X) (cocompact X) (𝓝 ∞),
{ rw [nhds_infty_eq],
exact (tendsto_map.mono_left cocompact_le_coclosed_compact).mono_right le_sup_left },
convert ← this.is_compact_insert_range_of_cocompact continuous_coe,
exact insert_none_range_some X
end }
/-- The one point compactification of a `t0_space` space is a `t0_space`. -/
instance [t0_space X] : t0_space (alexandroff X) :=
begin
refine ⟨λ x y hxy, _⟩,
rcases inseparable_iff.1 hxy with ⟨rfl, rfl⟩|⟨x, rfl, y, rfl, h⟩,
exacts [rfl, congr_arg coe h.eq]
end
/-- The one point compactification of a `t1_space` space is a `t1_space`. -/
instance [t1_space X] : t1_space (alexandroff X) :=
{ t1 := λ z,
begin
induction z using alexandroff.rec,
{ exact is_closed_infty },
{ rw [← image_singleton, is_closed_image_coe],
exact ⟨is_closed_singleton, is_compact_singleton⟩ }
end }
/-- The one point compactification of a locally compact Hausdorff space is a normal (hence,
Hausdorff and regular) topological space. -/
instance [locally_compact_space X] [t2_space X] : normal_space (alexandroff X) :=
begin
have key : ∀ z : X,
∃ u v : set (alexandroff X), is_open u ∧ is_open v ∧ ↑z ∈ u ∧ ∞ ∈ v ∧ disjoint u v,
{ intro z,
rcases exists_open_with_compact_closure z with ⟨u, hu, huy', Hu⟩,
exact ⟨coe '' u, (coe '' closure u)ᶜ, is_open_image_coe.2 hu,
is_open_compl_image_coe.2 ⟨is_closed_closure, Hu⟩, mem_image_of_mem _ huy',
mem_compl infty_not_mem_image_coe, (image_subset _ subset_closure).disjoint_compl_right⟩ },
refine @normal_of_compact_t2 _ _ _ ⟨λ x y hxy, _⟩,
induction x using alexandroff.rec; induction y using alexandroff.rec,
{ exact (hxy rfl).elim },
{ rcases key y with ⟨u, v, hu, hv, hxu, hyv, huv⟩,
exact ⟨v, u, hv, hu, hyv, hxu, huv.symm⟩ },
{ exact key x },
{ exact separated_by_open_embedding open_embedding_coe (mt coe_eq_coe.mpr hxy) }
end
/-- If `X` is not a compact space, then `alexandroff X` is a connected space. -/
instance [preconnected_space X] [noncompact_space X] : connected_space (alexandroff X) :=
{ to_preconnected_space := dense_embedding_coe.to_dense_inducing.preconnected_space,
to_nonempty := infer_instance }
/-- If `X` is an infinite type with discrete topology (e.g., `ℕ`), then the identity map from
`cofinite_topology (alexandroff X)` to `alexandroff X` is not continuous. -/
lemma not_continuous_cofinite_topology_of_symm [infinite X] [discrete_topology X] :
¬(continuous (@cofinite_topology.of (alexandroff X)).symm) :=
begin
inhabit X,
simp only [continuous_iff_continuous_at, continuous_at, not_forall],
use [cofinite_topology.of ↑(default : X)],
simpa [nhds_coe_eq, nhds_discrete, cofinite_topology.nhds_eq]
using (finite_singleton ((default : X) : alexandroff X)).infinite_compl
end
end alexandroff
/--
A concrete counterexample shows that `continuous.homeo_of_equiv_compact_to_t2`
cannot be generalized from `t2_space` to `t1_space`.
Let `α = alexandroff ℕ` be the one-point compactification of `ℕ`, and let `β` be the same space
`alexandroff ℕ` with the cofinite topology. Then `α` is compact, `β` is T1, and the identity map
`id : α → β` is a continuous equivalence that is not a homeomorphism.
-/
lemma continuous.homeo_of_equiv_compact_to_t2.t1_counterexample :
∃ (α β : Type) (Iα : topological_space α) (Iβ : topological_space β), by exactI
compact_space α ∧ t1_space β ∧ ∃ f : α ≃ β, continuous f ∧ ¬ continuous f.symm :=
⟨alexandroff ℕ, cofinite_topology (alexandroff ℕ), infer_instance, infer_instance,
infer_instance, infer_instance, cofinite_topology.of, cofinite_topology.continuous_of,
alexandroff.not_continuous_cofinite_topology_of_symm⟩
|
ee99de11949f7343766589841ffd72a54bd26751
|
bdd56e6eb0f467437e368d613de75299495d4054
|
/src/category_theory/finite_limits.lean
|
5f6d8aad39b281ae2b7d7f2383dfef37e268506b
|
[] |
no_license
|
truong111000/formalabstracts
|
49a04c268ccee136e48e24e9d5dcb6fedea4b53e
|
93a89a5c05c6fbc23eb9b914b60dcc353e609cd2
|
refs/heads/master
| 1,589,551,767,824
| 1,555,708,723,000
| 1,555,708,723,000
| 182,326,292
| 0
| 0
| null | 1,555,708,332,000
| 1,555,708,331,000
| null |
UTF-8
|
Lean
| false
| false
| 5,690
|
lean
|
-- Copyright (c) 2018 Jesse Han. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Jesse Han
import category_theory.limits.shapes.products basic data.dvector
category_theory.limits.shapes.equalizers
category_theory.limits.limits
universes u v
open category_theory
namespace category_theory.limits
@[derive decidable_eq] inductive two : Type u
| left | right
def two.map {C : Type*} (X Y : C) : two → C
| two.left := X
| two.right := Y
def two.functor {C : Type u} (X Y : C) [category.{v u} C] : (discrete two) ⥤ C :=
functor.of_function (two.map X Y)
def empty.functor (C : Type*) [category C] : (discrete pempty) ⥤ C :=
functor.of_function (λ x, by {cases x} : pempty → C)
def empty_cone {C : Type u} [category.{v u} C] (A : C) : limits.cone (empty.functor C) :=
{ X := A,
π := { app := λ x, by cases x,
naturality' := by tidy}}
def commutative_square {C : Type u} [category.{v u} C] {A B A' B' : C}
(f_top : A ⟶ B) (d_left : A ⟶ A') (d_right : B ⟶ B') (f_bot : A' ⟶ B') :=
f_top ≫ d_right = d_left ≫ f_bot
variables {C : Type u} [𝒞 : category.{v u} C]
include 𝒞
variable(C)
@[class, reducible] def has_binary_products := has_limits_of_shape (discrete two) C
@[instance] def has_limit_two_of_has_binary_products [H : has_binary_products C] {X Y : C} :
has_limit $ two.functor X Y :=
H (two.functor _ _)
variable{C}
/-- The binary product is the vertex of the limiting cone to the canonical functor two → 𝒞
associated to X and Y -/
def binary_product (X Y : C) [has_limit $ two.functor X Y] : C :=
limit (two.functor X Y)
namespace binary_product
def π₁ {X Y : C} [has_limit $ two.functor X Y] : binary_product X Y ⟶ X := limit.π _ two.left
def π₂ {X Y : C} [has_limit $ two.functor X Y] : binary_product X Y ⟶ Y := limit.π _ two.right
local infix ` × `:60 := binary_product
def dfin.map {n : ℕ} : dvector C n → dfin n → C :=
λ v d, by {induction v, cases d, cases d, exact v_x, exact v_ih d_a}
example {X : C} [has_binary_products C] : X × X × X = (X × X) × X := by refl
def cone_of_two_maps {W A₁ A₂: C} (f₁ : W ⟶ A₁) (f₂ : W ⟶ A₂) : cone (two.functor A₁ A₂) :=
{ X := W,
π := { app := λ l, two.rec_on l f₁ f₂,
naturality' := by tidy}}
lemma cone_of_two_maps_object [has_binary_products C] {B₁ B₂ A₁ A₂: C} {f₁ : B₁ × B₂ ⟶ A₁} {f₂ : B₁ × B₂ ⟶ A₂}
: (cone_of_two_maps f₁ f₂).X = B₁ × B₂ := by refl
def map_to_product.mk [H : has_binary_products C] {W B₁ B₂ : C} (f₁ : W ⟶ B₁) (f₂ : W ⟶ B₂) : W ⟶ B₁ × B₂ :=
is_limit.lift (by apply limit.is_limit) (cone_of_two_maps f₁ f₂)
set_option trace.class_instances false
set_option class.instance_max_depth 15
def binary_product.map [H : has_binary_products C] {A A' B B' : C} (f : A ⟶ A') (g : B ⟶ B') : A × B ⟶ A' × B' :=
by apply map_to_product.mk (π₁ ≫ f) (π₂ ≫ g)
local infix ` ×.map `:60 := binary_product.map
def reassoc_hom [has_binary_products C] (X : C) : ((X × X) × X) ⟶ (X × (X × X)) :=
by apply map_to_product.mk (π₁ ≫ π₁) (π₂ ×.map (𝟙 X))
def reassoc_inv [has_binary_products C] (X : C) : (X × (X × X)) ⟶ ((X × X) × X) :=
by apply map_to_product.mk ((𝟙 X) ×.map π₁)(π₂ ≫ π₂)
def reassoc_iso [has_binary_products C] (X : C) : iso ((X × X) × X) (X × (X × X)) :=
{ hom := by apply reassoc_hom X,
inv := by apply reassoc_inv X,
hom_inv_id' := omitted,
inv_hom_id' := omitted}
example :
commutative_square
/-unit-/ (𝟙 unit) /- unit -/
(𝟙 unit) (𝟙 unit)
/-unit-/ (𝟙 unit) /- unit -/
:= by tidy
section terminal_object
def terminal_object [has_limits_of_shape (discrete pempty) C] : C
:= limit (functor.of_function (λ x, by {cases x} : pempty → C))
notation `term` := terminal_object
def terminal_map [has_limits_of_shape (discrete pempty) C] (A : C) : A ⟶ term :=
(is_limit.lift (limit.is_limit (empty.functor C)) (empty_cone A))
lemma mul_one [has_limits_of_shape (discrete pempty) C] [has_binary_products C] (G : C) : nonempty $ iso (term × G) G := omitted
lemma one_mul [has_limits_of_shape (discrete pempty) C] [has_binary_products C] (G : C) : nonempty $ iso (G × term) G := omitted
def mul_one_inv [has_limits_of_shape (discrete pempty) C] [has_binary_products C] (G : C) : G ⟶ (G × term) :=
by apply map_to_product.mk (𝟙 _) (terminal_map G)
def one_mul_inv [has_limits_of_shape (discrete pempty) C] [has_binary_products C] (G : C) : G ⟶ (term × G) :=
by apply map_to_product.mk (terminal_map G) (𝟙 _)
end terminal_object
end binary_product
namespace finite_limits
open binary_product
instance fintype_two : fintype two :=
{elems := { val := ⟦[two.left, two.right]⟧,
nodup := by tidy },
complete := λ x, by cases x; tidy}
example : fintype pempty := by apply_instance
section finite_products
variable (C)
@[class]def has_finite_products := Π α : Type*, (fintype α) → has_limits_of_shape (discrete α) C
@[class]def has_equalizers := has_limits_of_shape (walking_pair) C
def has_binary_products_of_has_finite_products [H : has_finite_products C] :
has_binary_products C := H _ $ by apply_instance
attribute [instance] has_binary_products_of_has_finite_products
@[instance]def has_terminal_object_of_has_finite_products [H : has_finite_products C] :
has_limits_of_shape (discrete pempty) C := H _ $ by apply_instance
@[class]def has_finite_limits := (@has_finite_products C 𝒞) × (@has_equalizers C 𝒞)
end finite_products
end finite_limits
end category_theory.limits
|
2a6ef9edcb11181e7b8c89bd282f61c0f562b620
|
d1a52c3f208fa42c41df8278c3d280f075eb020c
|
/src/Init/Control/Reader.lean
|
7372222f2b23a487d6ca4a09ef61d0b036b43efd
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
cipher1024/lean4
|
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
|
69114d3b50806264ef35b57394391c3e738a9822
|
refs/heads/master
| 1,642,227,983,603
| 1,642,011,696,000
| 1,642,011,696,000
| 228,607,691
| 0
| 0
|
Apache-2.0
| 1,576,584,269,000
| 1,576,584,268,000
| null |
UTF-8
|
Lean
| false
| false
| 1,054
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
The Reader monad transformer for passing immutable State.
-/
prelude
import Init.Control.Basic
import Init.Control.Id
import Init.Control.Except
namespace ReaderT
@[inline] protected def orElse [Alternative m] (x₁ : ReaderT ρ m α) (x₂ : Unit → ReaderT ρ m α) : ReaderT ρ m α :=
fun s => x₁ s <|> x₂ () s
@[inline] protected def failure [Alternative m] : ReaderT ρ m α :=
fun s => failure
instance [Alternative m] [Monad m] : Alternative (ReaderT ρ m) where
failure := ReaderT.failure
orElse := ReaderT.orElse
end ReaderT
instance : MonadControl m (ReaderT ρ m) where
stM := id
liftWith f ctx := f fun x => x ctx
restoreM x ctx := x
instance ReaderT.tryFinally [MonadFinally m] [Monad m] : MonadFinally (ReaderT ρ m) where
tryFinally' x h ctx := tryFinally' (x ctx) (fun a? => h a? ctx)
@[reducible] def Reader (ρ : Type u) := ReaderT ρ Id
|
80307700b03101ec95ae4102a10853f67835a002
|
437dc96105f48409c3981d46fb48e57c9ac3a3e4
|
/src/algebra/group/hom.lean
|
e8575dbaae6681339a71f0f3c7523da46f0286b8
|
[
"Apache-2.0"
] |
permissive
|
dan-c-k/mathlib
|
08efec79bd7481ee6da9cc44c24a653bff4fbe0d
|
96efc220f6225bc7a5ed8349900391a33a38cc56
|
refs/heads/master
| 1,658,082,847,093
| 1,589,013,201,000
| 1,589,013,201,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 11,089
|
lean
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes,
Johannes Hölzl, Yury Kudryashov
-/
import algebra.group.basic
/-!
# monoid and group homomorphisms
This file defines the bundled structures for monoid and group homomorphisms. Namely, we define
`monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp.,
additive) monoids or groups.
We also define coercion to a function, and usual operations: composition, identity homomorphism,
pointwise multiplication and pointwise inversion.
## Notations
* `→*` for bundled monoid homs (also use for group homs)
* `→+` for bundled add_monoid homs (also use for add_group homs)
## implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `group_hom` -- the idea is that `monoid_hom` is used.
The constructor for `monoid_hom` needs a proof of `map_one` as well
as `map_mul`; a separate constructor `monoid_hom.mk'` will construct
group homs (i.e. monoid homs between groups) given only a proof
that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they
can be inferred from the type it is faster to use this method than to use type class inference.
Historically this file also included definitions of unbundled homomorphism classes; they were
deprecated and moved to `deprecated/group`.
## Tags
monoid_hom, add_monoid_hom
-/
variables {M : Type*} {N : Type*} {P : Type*} -- monoids
{G : Type*} {H : Type*} -- groups
/-- Bundled add_monoid homomorphisms; use this for bundled add_group homomorphisms too. -/
structure add_monoid_hom (M : Type*) (N : Type*) [add_monoid M] [add_monoid N] :=
(to_fun : M → N)
(map_zero' : to_fun 0 = 0)
(map_add' : ∀ x y, to_fun (x + y) = to_fun x + to_fun y)
infixr ` →+ `:25 := add_monoid_hom
/-- Bundled monoid homomorphisms; use this for bundled group homomorphisms too. -/
@[to_additive add_monoid_hom]
structure monoid_hom (M : Type*) (N : Type*) [monoid M] [monoid N] :=
(to_fun : M → N)
(map_one' : to_fun 1 = 1)
(map_mul' : ∀ x y, to_fun (x * y) = to_fun x * to_fun y)
infixr ` →* `:25 := monoid_hom
@[to_additive]
instance {M : Type*} {N : Type*} {mM : monoid M} {mN : monoid N} : has_coe_to_fun (M →* N) :=
⟨_, monoid_hom.to_fun⟩
namespace monoid_hom
variables {mM : monoid M} {mN : monoid N} {mP : monoid P}
variables [group G] [comm_group H]
include mM mN
@[simp, to_additive]
lemma coe_mk (f : M → N) (h1 hmul) : ⇑(monoid_hom.mk f h1 hmul) = f := rfl
@[to_additive]
lemma coe_inj ⦃f g : M →* N⦄ (h : (f : M → N) = g) : f = g :=
by cases f; cases g; cases h; refl
@[ext, to_additive]
lemma ext ⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g :=
coe_inj (funext h)
attribute [ext] _root_.add_monoid_hom.ext
@[to_additive]
lemma ext_iff {f g : M →* N} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, λ h, ext h⟩
/-- If f is a monoid homomorphism then f 1 = 1. -/
@[simp, to_additive]
lemma map_one (f : M →* N) : f 1 = 1 := f.map_one'
/-- If f is a monoid homomorphism then f (a * b) = f a * f b. -/
@[simp, to_additive]
lemma map_mul (f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
@[to_additive]
lemma map_mul_eq_one (f : M →* N) {a b : M} (h : a * b = 1) : f a * f b = 1 :=
by rw [← f.map_mul, h, f.map_one]
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse,
then `f x` has a right inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a right inverse, then `f x` has a right inverse too."]
lemma map_exists_right_inv (f : M →* N) {x : M} (hx : ∃ y, x * y = 1) :
∃ y, f x * y = 1 :=
let ⟨y, hy⟩ := hx in ⟨f y, f.map_mul_eq_one hy⟩
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse,
then `f x` has a left inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see
`is_add_unit.map`."]
lemma map_exists_left_inv (f : M →* N) {x : M} (hx : ∃ y, y * x = 1) :
∃ y, y * f x = 1 :=
let ⟨y, hy⟩ := hx in ⟨f y, f.map_mul_eq_one hy⟩
omit mN mM
/-- The identity map from a monoid to itself. -/
@[to_additive]
def id (M : Type*) [monoid M] : M →* M :=
{ to_fun := id,
map_one' := rfl,
map_mul' := λ _ _, rfl }
@[simp, to_additive] lemma id_apply {M : Type*} [monoid M] (x : M) :
id M x = x := rfl
include mM mN mP
/-- Composition of monoid morphisms is a monoid morphism. -/
@[to_additive]
def comp (hnp : N →* P) (hmn : M →* N) : M →* P :=
{ to_fun := hnp ∘ hmn,
map_one' := by simp,
map_mul' := by simp }
@[simp, to_additive] lemma comp_apply (g : N →* P) (f : M →* N) (x : M) :
g.comp f x = g (f x) := rfl
/-- Composition of monoid homomorphisms is associative. -/
@[to_additive] lemma comp_assoc {Q : Type*} [monoid Q] (f : M →* N) (g : N →* P) (h : P →* Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive]
lemma cancel_right {g₁ g₂ : N →* P} {f : M →* N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, monoid_hom.ext $ (forall_iff_forall_surj hf).1 (ext_iff.1 h), λ h, h ▸ rfl⟩
@[to_additive]
lemma cancel_left {g : N →* P} {f₁ f₂ : M →* N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, monoid_hom.ext $ λ x, hg $ by rw [← comp_apply, h, comp_apply], λ h, h ▸ rfl⟩
omit mP
@[simp, to_additive] lemma comp_id (f : M →* N) : f.comp (id M) = f := ext $ λ x, rfl
@[simp, to_additive] lemma id_comp (f : M →* N) : (id N).comp f = f := ext $ λ x, rfl
variables [mM] [mN]
@[to_additive]
protected def one : M →* N :=
{ to_fun := λ _, 1,
map_one' := rfl,
map_mul' := λ _ _, (one_mul 1).symm }
@[to_additive]
instance : has_one (M →* N) := ⟨monoid_hom.one⟩
@[simp, to_additive] lemma one_apply (x : M) : (1 : M →* N) x = 1 := rfl
@[to_additive]
instance : inhabited (M →* N) := ⟨1⟩
omit mM mN
/-- The product of two monoid morphisms is a monoid morphism if the target is commutative. -/
@[to_additive]
protected def mul {M N} {mM : monoid M} [comm_monoid N] (f g : M →* N) : M →* N :=
{ to_fun := λ m, f m * g m,
map_one' := show f 1 * g 1 = 1, by simp,
map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y),
rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end }
@[to_additive]
instance {M N} {mM : monoid M} [comm_monoid N] : has_mul (M →* N) := ⟨monoid_hom.mul⟩
@[simp, to_additive] lemma mul_apply {M N} {mM : monoid M} {mN : comm_monoid N}
(f g : M →* N) (x : M) :
(f * g) x = f x * g x := rfl
/-- (M →* N) is a comm_monoid if N is commutative. -/
@[to_additive add_comm_monoid]
instance {M N} [monoid M] [comm_monoid N] : comm_monoid (M →* N) :=
{ mul := (*),
mul_assoc := by intros; ext; apply mul_assoc,
one := 1,
one_mul := by intros; ext; apply one_mul,
mul_one := by intros; ext; apply mul_one,
mul_comm := by intros; ext; apply mul_comm }
/-- `flip` arguments of `f : M →* N →* P` -/
@[to_additive "`flip` arguments of `f : M →+ N →+ P`"]
def flip {mM : monoid M} {mN : monoid N} {mP : comm_monoid P} (f : M →* N →* P) :
N →* M →* P :=
{ to_fun := λ y, ⟨λ x, f x y, by rw [f.map_one, one_apply], λ x₁ x₂, by rw [f.map_mul, mul_apply]⟩,
map_one' := ext $ λ x, (f x).map_one,
map_mul' := λ y₁ y₂, ext $ λ x, (f x).map_mul y₁ y₂ }
@[simp, to_additive] lemma flip_apply {mM : monoid M} {mN : monoid N} {mP : comm_monoid P}
(f : M →* N →* P) (x : M) (y : N) :
f.flip y x = f x y :=
rfl
/-- Group homomorphisms preserve inverse. -/
@[simp, to_additive]
theorem map_inv {G H} [group G] [group H] (f : G →* H) (g : G) : f g⁻¹ = (f g)⁻¹ :=
eq_inv_of_mul_eq_one $ by rw [←f.map_mul, inv_mul_self, f.map_one]
/-- Group homomorphisms preserve division. -/
@[simp, to_additive]
theorem map_mul_inv {G H} [group G] [group H] (f : G →* H) (g h : G) :
f (g * h⁻¹) = (f g) * (f h)⁻¹ := by rw [f.map_mul, f.map_inv]
/-- A group homomorphism is injective iff its kernel is trivial. -/
@[to_additive]
lemma injective_iff {G H} [group G] [group H] (f : G →* H) :
function.injective f ↔ (∀ a, f a = 1 → a = 1) :=
⟨λ h _, by rw ← f.map_one; exact @h _ _,
λ h x y hxy, by rw [← inv_inv (f x), inv_eq_iff_mul_eq_one, ← f.map_inv,
← f.map_mul] at hxy;
simpa using inv_eq_of_mul_eq_one (h _ hxy)⟩
include mM
/-- Makes a group homomomorphism from a proof that the map preserves multiplication. -/
@[to_additive]
def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G :=
{ to_fun := f,
map_mul' := map_mul,
map_one' := mul_self_iff_eq_one.1 $ by rw [←map_mul, mul_one] }
omit mM
/-- The inverse of a monoid homomorphism is a monoid homomorphism if the target is
a commutative group.-/
@[to_additive]
protected def inv {M G} {mM : monoid M} [comm_group G] (f : M →* G) : M →* G :=
mk' (λ g, (f g)⁻¹) $ λ a b, by rw [←mul_inv, f.map_mul]
@[to_additive]
instance {M G} [monoid M] [comm_group G] : has_inv (M →* G) := ⟨monoid_hom.inv⟩
@[simp, to_additive] lemma inv_apply {M G} {mM : monoid M} {gG : comm_group G}
(f : M →* G) (x : M) :
f⁻¹ x = (f x)⁻¹ := rfl
/-- (M →* G) is a comm_group if G is a comm_group -/
@[to_additive add_comm_group]
instance {M G} [monoid M] [comm_group G] : comm_group (M →* G) :=
{ inv := has_inv.inv,
mul_left_inv := by intros; ext; apply mul_left_inv,
..monoid_hom.comm_monoid }
end monoid_hom
namespace add_monoid_hom
/-- Additive group homomorphisms preserve subtraction. -/
@[simp] theorem map_sub {G H} [add_group G] [add_group H] (f : G →+ H) (g h : G) :
f (g - h) = (f g) - (f h) := f.map_add_neg g h
/-- Left multiplication by an element of a (semi)ring is an `add_monoid_hom` -/
def mul_left {R : Type*} [semiring R] (r : R) : R →+ R :=
{ to_fun := (*) r,
map_zero' := mul_zero r,
map_add' := mul_add r }
@[simp] lemma coe_mul_left {R : Type*} [semiring R] (r : R) : ⇑(mul_left r) = (*) r := rfl
/-- Right multiplication by an element of a (semi)ring is an `add_monoid_hom` -/
def mul_right {R : Type*} [semiring R] (r : R) : R →+ R :=
{ to_fun := λ a, a * r,
map_zero' := zero_mul r,
map_add' := λ _ _, add_mul _ _ r }
@[simp] lemma mul_right_apply {R : Type*} [semiring R] (a r : R) :
(mul_right r : R → R) a = a * r := rfl
end add_monoid_hom
|
dca0925af276dabc85156970df09cb2cf87ef3e9
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/algebra/hom/non_unital_alg.lean
|
80cfcc6a71363489a55832bca545be8828e6e946
|
[
"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,431
|
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.basic
/-!
# Morphisms of non-unital algebras
This file defines morphisms between two types, each of which carries:
* an addition,
* an additive zero,
* a multiplication,
* a scalar action.
The multiplications are not assumed to be associative or unital, or even to be compatible with the
scalar actions. In a typical application, the operations will satisfy compatibility conditions
making them into algebras (albeit possibly non-associative and/or non-unital) but such conditions
are not required to make this definition.
This notion of morphism should be useful for any category of non-unital algebras. The motivating
application at the time it was introduced was to be able to state the adjunction property for
magma algebras. These are non-unital, non-associative algebras obtained by applying the
group-algebra construction except where we take a type carrying just `has_mul` instead of `group`.
For a plausible future application, one could take the non-unital algebra of compactly-supported
functions on a non-compact topological space. A proper map between a pair of such spaces
(contravariantly) induces a morphism between their algebras of compactly-supported functions which
will be a `non_unital_alg_hom`.
TODO: add `non_unital_alg_equiv` when needed.
## Main definitions
* `non_unital_alg_hom`
* `alg_hom.to_non_unital_alg_hom`
## Tags
non-unital, algebra, morphism
-/
universes u v w w₁ w₂ w₃
variables (R : Type u) (A : Type v) (B : Type w) (C : Type w₁)
set_option old_structure_cmd true
/-- A morphism respecting addition, multiplication, and scalar multiplication. When these arise from
algebra structures, this is the same as a not-necessarily-unital morphism of algebras. -/
structure non_unital_alg_hom [monoid R]
[non_unital_non_assoc_semiring A] [distrib_mul_action R A]
[non_unital_non_assoc_semiring B] [distrib_mul_action R B]
extends A →+[R] B, A →ₙ* B
infixr ` →ₙₐ `:25 := non_unital_alg_hom _
notation A ` →ₙₐ[`:25 R `] ` B := non_unital_alg_hom R A B
attribute [nolint doc_blame] non_unital_alg_hom.to_distrib_mul_action_hom
attribute [nolint doc_blame] non_unital_alg_hom.to_mul_hom
/-- `non_unital_alg_hom_class F R A B` asserts `F` is a type of bundled algebra homomorphisms
from `A` to `B`. -/
class non_unital_alg_hom_class (F : Type*) (R : out_param Type*) (A : out_param Type*)
(B : out_param Type*) [monoid R]
[non_unital_non_assoc_semiring A] [non_unital_non_assoc_semiring B]
[distrib_mul_action R A] [distrib_mul_action R B]
extends distrib_mul_action_hom_class F R A B, mul_hom_class F A B
-- `R` becomes a metavariable but that's fine because it's an `out_param`
attribute [nolint dangerous_instance] non_unital_alg_hom_class.to_mul_hom_class
namespace non_unital_alg_hom_class
-- `R` becomes a metavariable but that's fine because it's an `out_param`
@[priority 100, nolint dangerous_instance] -- See note [lower instance priority]
instance non_unital_alg_hom_class.to_non_unital_ring_hom_class {F R A B : Type*} [monoid R]
[non_unital_non_assoc_semiring A] [distrib_mul_action R A]
[non_unital_non_assoc_semiring B] [distrib_mul_action R B]
[non_unital_alg_hom_class F R A B] : non_unital_ring_hom_class F A B :=
{ coe := coe_fn, ..‹non_unital_alg_hom_class F R A B› }
variables [semiring R]
[non_unital_non_assoc_semiring A] [module R A]
[non_unital_non_assoc_semiring B] [module R B]
@[priority 100] -- see Note [lower instance priority]
instance {F : Type*} [non_unital_alg_hom_class F R A B] : linear_map_class F R A B :=
{ map_smulₛₗ := distrib_mul_action_hom_class.map_smul,
..‹non_unital_alg_hom_class F R A B› }
instance {F R A B : Type*} [monoid R]
[non_unital_non_assoc_semiring A] [distrib_mul_action R A]
[non_unital_non_assoc_semiring B] [distrib_mul_action R B]
[non_unital_alg_hom_class F R A B] : has_coe_t F (A →ₙₐ[R] B) :=
{ coe := λ f,
{ to_fun := f,
map_smul' := map_smul f,
.. (f : A →ₙ+* B) } }
end non_unital_alg_hom_class
namespace non_unital_alg_hom
variables {R A B C} [monoid R]
variables [non_unital_non_assoc_semiring A] [distrib_mul_action R A]
variables [non_unital_non_assoc_semiring B] [distrib_mul_action R B]
variables [non_unital_non_assoc_semiring C] [distrib_mul_action R C]
/-- see Note [function coercion] -/
instance : has_coe_to_fun (A →ₙₐ[R] B) (λ _, A → B) := ⟨to_fun⟩
@[simp] lemma to_fun_eq_coe (f : A →ₙₐ[R] B) : f.to_fun = ⇑f := rfl
initialize_simps_projections non_unital_alg_hom (to_fun → apply)
@[simp, protected] lemma coe_coe {F : Type*} [non_unital_alg_hom_class F R A B] (f : F) :
⇑(f : A →ₙₐ[R] B) = f := rfl
lemma coe_injective :
@function.injective (A →ₙₐ[R] B) (A → B) coe_fn :=
by rintro ⟨f, _⟩ ⟨g, _⟩ ⟨h⟩; congr
instance : non_unital_alg_hom_class (A →ₙₐ[R] B) R A B :=
{ coe := to_fun,
coe_injective' := coe_injective,
map_smul := λ f, f.map_smul',
map_add := λ f, f.map_add',
map_zero := λ f, f.map_zero',
map_mul := λ f, f.map_mul' }
@[ext] lemma ext {f g : A →ₙₐ[R] B} (h : ∀ x, f x = g x) : f = g :=
coe_injective $ funext h
lemma ext_iff {f g : A →ₙₐ[R] B} : f = g ↔ ∀ x, f x = g x :=
⟨by { rintro rfl x, refl }, ext⟩
lemma congr_fun {f g : A →ₙₐ[R] B} (h : f = g) (x : A) : f x = g x := h ▸ rfl
@[simp] lemma coe_mk (f : A → B) (h₁ h₂ h₃ h₄) :
((⟨f, h₁, h₂, h₃, h₄⟩ : A →ₙₐ[R] B) : A → B) = f :=
rfl
@[simp] lemma mk_coe (f : A →ₙₐ[R] B) (h₁ h₂ h₃ h₄) :
(⟨f, h₁, h₂, h₃, h₄⟩ : A →ₙₐ[R] B) = f :=
by { ext, refl, }
instance : has_coe (A →ₙₐ[R] B) (A →+[R] B) :=
⟨to_distrib_mul_action_hom⟩
instance : has_coe (A →ₙₐ[R] B) (A →ₙ* B) := ⟨to_mul_hom⟩
@[simp] lemma to_distrib_mul_action_hom_eq_coe (f : A →ₙₐ[R] B) :
f.to_distrib_mul_action_hom = ↑f :=
rfl
@[simp] lemma to_mul_hom_eq_coe (f : A →ₙₐ[R] B) : f.to_mul_hom = ↑f :=
rfl
@[simp, norm_cast] lemma coe_to_distrib_mul_action_hom (f : A →ₙₐ[R] B) :
((f : A →+[R] B) : A → B) = f :=
rfl
@[simp, norm_cast] lemma coe_to_mul_hom (f : A →ₙₐ[R] B) :
((f : A →ₙ* B) : A → B) = f :=
rfl
lemma to_distrib_mul_action_hom_injective {f g : A →ₙₐ[R] B}
(h : (f : A →+[R] B) = (g : A →+[R] B)) : f = g :=
by { ext a, exact distrib_mul_action_hom.congr_fun h a, }
lemma to_mul_hom_injective {f g : A →ₙₐ[R] B}
(h : (f : A →ₙ* B) = (g : A →ₙ* B)) : f = g :=
by { ext a, exact mul_hom.congr_fun h a, }
@[norm_cast] lemma coe_distrib_mul_action_hom_mk (f : A →ₙₐ[R] B) (h₁ h₂ h₃ h₄) :
((⟨f, h₁, h₂, h₃, h₄⟩ : A →ₙₐ[R] B) : A →+[R] B) =
⟨f, h₁, h₂, h₃⟩ :=
by { ext, refl, }
@[norm_cast] lemma coe_mul_hom_mk (f : A →ₙₐ[R] B) (h₁ h₂ h₃ h₄) :
((⟨f, h₁, h₂, h₃, h₄⟩ : A →ₙₐ[R] B) : A →ₙ* B) = ⟨f, h₄⟩ :=
by { ext, refl, }
@[simp] protected lemma map_smul (f : A →ₙₐ[R] B) (c : R) (x : A) :
f (c • x) = c • f x := map_smul _ _ _
@[simp] protected lemma map_add (f : A →ₙₐ[R] B) (x y : A) :
f (x + y) = (f x) + (f y) := map_add _ _ _
@[simp] protected lemma map_mul (f : A →ₙₐ[R] B) (x y : A) :
f (x * y) = (f x) * (f y) := map_mul _ _ _
@[simp] protected lemma map_zero (f : A →ₙₐ[R] B) : f 0 = 0 := map_zero _
instance : has_zero (A →ₙₐ[R] B) :=
⟨{ map_mul' := by simp,
.. (0 : A →+[R] B) }⟩
instance : has_one (A →ₙₐ[R] A) :=
⟨{ map_mul' := by simp,
.. (1 : A →+[R] A) }⟩
@[simp] lemma coe_zero : ((0 : A →ₙₐ[R] B) : A → B) = 0 := rfl
@[simp] lemma coe_one : ((1 : A →ₙₐ[R] A) : A → A) = id := rfl
lemma zero_apply (a : A) : (0 : A →ₙₐ[R] B) a = 0 := rfl
lemma one_apply (a : A) : (1 : A →ₙₐ[R] A) a = a := rfl
instance : inhabited (A →ₙₐ[R] B) := ⟨0⟩
/-- The composition of morphisms is a morphism. -/
def comp (f : B →ₙₐ[R] C) (g : A →ₙₐ[R] B) : A →ₙₐ[R] C :=
{ .. (f : B →ₙ* C).comp (g : A →ₙ* B),
.. (f : B →+[R] C).comp (g : A →+[R] B) }
@[simp, norm_cast] lemma coe_comp (f : B →ₙₐ[R] C) (g : A →ₙₐ[R] B) :
(f.comp g : A → C) = (f : B → C) ∘ (g : A → B) :=
rfl
lemma comp_apply (f : B →ₙₐ[R] C) (g : A →ₙₐ[R] B) (x : A) :
f.comp g x = f (g x) :=
rfl
/-- The inverse of a bijective morphism is a morphism. -/
def inverse (f : A →ₙₐ[R] B) (g : B → A)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) :
B →ₙₐ[R] A :=
{ .. (f : A →ₙ* B).inverse g h₁ h₂,
.. (f : A →+[R] B).inverse g h₁ h₂ }
@[simp] lemma coe_inverse (f : A →ₙₐ[R] B) (g : B → A)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) :
(inverse f g h₁ h₂ : B → A) = g :=
rfl
/-! ### Operations on the product type
Note that much of this is copied from [`linear_algebra/prod`](../../linear_algebra/prod). -/
section prod
variables (R A B)
/-- The first projection of a product is a non-unital alg_hom. -/
@[simps]
def fst : A × B →ₙₐ[R] A :=
{ to_fun := prod.fst,
map_zero' := rfl, map_add' := λ x y, rfl, map_smul' := λ x y, rfl, map_mul' := λ x y, rfl }
/-- The second projection of a product is a non-unital alg_hom. -/
@[simps]
def snd : A × B →ₙₐ[R] B :=
{ to_fun := prod.snd,
map_zero' := rfl, map_add' := λ x y, rfl, map_smul' := λ x y, rfl, map_mul' := λ x y, rfl }
variables {R A B}
/-- The prod of two morphisms is a morphism. -/
@[simps] def prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) : (A →ₙₐ[R] B × C) :=
{ to_fun := pi.prod f g,
map_zero' := by simp only [pi.prod, prod.zero_eq_mk, map_zero],
map_add' := λ x y, by simp only [pi.prod, prod.mk_add_mk, map_add],
map_mul' := λ x y, by simp only [pi.prod, prod.mk_mul_mk, map_mul],
map_smul' := λ c x, by simp only [pi.prod, prod.smul_mk, map_smul, ring_hom.id_apply] }
lemma coe_prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) : ⇑(f.prod g) = pi.prod f g := rfl
@[simp] theorem fst_prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) :
(fst R B C).comp (prod f g) = f := by ext; refl
@[simp] theorem snd_prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) :
(snd R B C).comp (prod f g) = g := by ext; refl
@[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = 1 :=
coe_injective pi.prod_fst_snd
/-- Taking the product of two maps with the same domain is equivalent to taking the product of
their codomains. -/
@[simps] def prod_equiv : ((A →ₙₐ[R] B) × (A →ₙₐ[R] C)) ≃ (A →ₙₐ[R] B × C) :=
{ 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 }
variables (R A B)
/-- The left injection into a product is a non-unital algebra homomorphism. -/
def inl : A →ₙₐ[R] A × B := prod 1 0
/-- The right injection into a product is a non-unital algebra homomorphism. -/
def inr : B →ₙₐ[R] A × B := prod 0 1
variables {R A B}
@[simp] theorem coe_inl : (inl R A B : A → A × B) = λ x, (x, 0) := rfl
theorem inl_apply (x : A) : inl R A B x = (x, 0) := rfl
@[simp] theorem coe_inr : (inr R A B : B → A × B) = prod.mk 0 := rfl
theorem inr_apply (x : B) : inr R A B x = (0, x) := rfl
end prod
end non_unital_alg_hom
/-! ### Interaction with `alg_hom` -/
namespace alg_hom
variables {R A B} [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
@[priority 100] -- see Note [lower instance priority]
instance {F : Type*} [alg_hom_class F R A B] : non_unital_alg_hom_class F R A B :=
{ map_smul := map_smul,
..‹alg_hom_class F R A B› }
/-- A unital morphism of algebras is a `non_unital_alg_hom`. -/
def to_non_unital_alg_hom (f : A →ₐ[R] B) : A →ₙₐ[R] B :=
{ map_smul' := map_smul f, .. f, }
instance non_unital_alg_hom.has_coe : has_coe (A →ₐ[R] B) (A →ₙₐ[R] B) :=
⟨to_non_unital_alg_hom⟩
@[simp] lemma to_non_unital_alg_hom_eq_coe (f : A →ₐ[R] B) : f.to_non_unital_alg_hom = f :=
rfl
@[simp, norm_cast] lemma coe_to_non_unital_alg_hom (f : A →ₐ[R] B) :
((f : A →ₙₐ[R] B) : A → B) = f :=
rfl
end alg_hom
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.