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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
f0e5b9eb907263b2b2ed23636b2aed4e6a3af1ef | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/theories/analysis/ivt.lean | 527a3ebfc07875dba7d6282e16b8a60976335d30 | [
"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 | 9,677 | lean | /-
Copyright (c) 2015 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
The intermediate value theorem.
-/
import .real_limit
open real analysis set classical topology
noncomputable theory
private definition inter_sup (a b : ℝ) (f : ℝ → ℝ) := sup {x | x < b ∧ f x < 0}
section
parameters {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b) (Ha : f a < 0) (Hb : f b > 0)
include Hf Ha Hb Hab
private theorem Hinh : ∃ x, x ∈ {x | x < b ∧ f x < 0} := exists.intro a (and.intro Hab Ha)
private theorem Hmem : ∀ x, x ∈ {x | x < b ∧ f x < 0} → x ≤ b := λ x Hx, le_of_lt (and.left Hx)
private theorem Hsupleb : inter_sup a b f ≤ b := sup_le (Hinh) Hmem
local notation 2 := of_num 1 + of_num 1
private theorem ex_delta_lt {x : ℝ} (Hx : f x < 0) (Hxb : x < b) : ∃ δ : ℝ, δ > 0 ∧ x + δ < b ∧ f (x + δ) < 0 :=
begin
let Hcont := neg_on_nbhd_of_cts_of_neg Hf Hx,
cases Hcont with δ Hδ,
{cases em (x + δ < b) with Haδ Haδ,
existsi δ / 2,
split,
{exact div_pos_of_pos_of_pos (and.left Hδ) two_pos},
split,
{apply lt.trans,
apply add_lt_add_left,
exact div_two_lt_of_pos (and.left Hδ),
exact Haδ},
{apply and.right Hδ,
krewrite [abs_sub, sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg,
abs_of_pos (div_pos_of_pos_of_pos (and.left Hδ) two_pos)],
exact div_two_lt_of_pos (and.left Hδ)},
existsi (b - x) / 2,
split,
{apply div_pos_of_pos_of_pos,
exact sub_pos_of_lt Hxb,
exact two_pos},
split,
{apply add_midpoint Hxb},
{apply and.right Hδ,
krewrite [abs_sub, sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg,
abs_of_pos (div_pos_of_pos_of_pos (sub_pos_of_lt Hxb) two_pos)],
apply lt_of_lt_of_le,
apply div_two_lt_of_pos (sub_pos_of_lt Hxb),
apply sub_left_le_of_le_add,
apply le_of_not_gt Haδ}}
end
private lemma sup_near_b {δ : ℝ} (Hpos : 0 < δ)
(Hgeb : inter_sup a b f + δ / 2 ≥ b) : abs (inter_sup a b f - b) < δ :=
begin
apply abs_lt_of_lt_of_neg_lt,
apply sub_lt_left_of_lt_add,
apply lt_of_le_of_lt,
apply Hsupleb,
apply lt_add_of_pos_right Hpos,
rewrite neg_sub,
apply sub_lt_left_of_lt_add,
apply lt_of_le_of_lt,
apply Hgeb,
apply add_lt_add_left,
apply div_two_lt_of_pos Hpos
end
private lemma delta_of_lt (Hflt : f (inter_sup a b f) < 0) :
∃ δ : ℝ, δ > 0 ∧ inter_sup a b f + δ < b ∧ f (inter_sup a b f + δ) < 0 :=
if Hlt : inter_sup a b f < b then ex_delta_lt Hflt Hlt else
begin
let Heq := eq_of_le_of_ge Hsupleb (le_of_not_gt Hlt),
apply absurd Hflt,
apply not_lt_of_ge,
apply le_of_lt,
rewrite Heq,
exact Hb
end
private theorem sup_fn_interval_aux1 : f (inter_sup a b f) ≥ 0 :=
have ¬ f (inter_sup a b f) < 0, from
(suppose f (inter_sup a b f) < 0,
obtain δ Hδ, from delta_of_lt this,
have inter_sup a b f + δ ∈ {x | x < b ∧ f x < 0},
from and.intro (and.left (and.right Hδ)) (and.right (and.right Hδ)),
have ¬ inter_sup a b f < inter_sup a b f + δ,
from not_lt_of_ge (le_sup this Hmem),
show false, from this (lt_add_of_pos_right (and.left Hδ))),
le_of_not_gt this
private theorem sup_fn_interval_aux2 : f (inter_sup a b f) ≤ 0 :=
have ¬ f (inter_sup a b f) > 0, from
(assume Hfsup : f (inter_sup a b f) > 0,
obtain δ Hδ, from pos_on_nbhd_of_cts_of_pos Hf Hfsup,
have ∀ x, x ∈ {x | x < b ∧ f x < 0} → x ≤ inter_sup a b f - δ / 2, from
(take x, assume Hxset : x ∈ {x | x < b ∧ f x < 0},
have ¬ x > inter_sup a b f - δ / 2, from
(assume Hngt,
have Habs : abs (x - inter_sup a b f) < δ, begin
rewrite abs_sub,
apply abs_lt_of_lt_of_neg_lt,
apply sub_lt_of_sub_lt,
apply gt.trans,
exact Hngt,
apply sub_lt_sub_left,
exact div_two_lt_of_pos (and.left Hδ),
rewrite neg_sub,
apply lt_of_le_of_lt,
rotate 1,
apply and.left Hδ,
apply sub_nonpos_of_le,
apply le_sup,
exact Hxset,
exact Hmem
end,
have f x > 0, from and.right Hδ x Habs,
show false, from (not_lt_of_gt this) (and.right Hxset)),
le_of_not_gt this),
have Hle : inter_sup a b f ≤ inter_sup a b f - δ / 2, from sup_le Hinh this,
show false, from not_le_of_gt
(sub_lt_of_pos _ (div_pos_of_pos_of_pos (and.left Hδ) (two_pos))) Hle),
le_of_not_gt this
private theorem sup_fn_interval : f (inter_sup a b f) = 0 :=
eq_of_le_of_ge sup_fn_interval_aux2 sup_fn_interval_aux1
private theorem intermediate_value_incr_aux2 : ∃ δ : ℝ, δ > 0 ∧ a + δ < b ∧ f (a + δ) < 0 :=
begin
let Hcont := neg_on_nbhd_of_cts_of_neg Hf Ha,
cases Hcont with δ Hδ,
{cases em (a + δ < b) with Haδ Haδ,
existsi δ / 2,
split,
{exact div_pos_of_pos_of_pos (and.left Hδ) two_pos},
split,
{apply lt.trans,
apply add_lt_add_left,
exact div_two_lt_of_pos (and.left Hδ),
exact Haδ},
{apply and.right Hδ,
krewrite [abs_sub, sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg,
abs_of_pos (div_pos_of_pos_of_pos (and.left Hδ) two_pos)],
exact div_two_lt_of_pos (and.left Hδ)},
existsi (b - a) / 2,
split,
{apply div_pos_of_pos_of_pos,
exact sub_pos_of_lt Hab,
exact two_pos},
split,
{apply add_midpoint Hab},
{apply and.right Hδ,
krewrite [abs_sub, sub_add_eq_sub_sub, sub_self, zero_sub, abs_neg,
abs_of_pos (div_pos_of_pos_of_pos (sub_pos_of_lt Hab) two_pos)],
apply lt_of_lt_of_le,
apply div_two_lt_of_pos (sub_pos_of_lt Hab),
apply sub_left_le_of_le_add,
apply le_of_not_gt Haδ}}
end
theorem intermediate_value_incr_zero : ∃ c, a < c ∧ c < b ∧ f c = 0 :=
begin
existsi inter_sup a b f,
split,
{cases intermediate_value_incr_aux2 with δ Hδ,
apply lt_of_lt_of_le,
apply lt_add_of_pos_right,
exact and.left Hδ,
apply le_sup,
exact and.right Hδ,
intro x Hx,
apply le_of_lt,
exact and.left Hx},
split,
{cases pos_on_nbhd_of_cts_of_pos Hf Hb with δ Hδ,
apply lt_of_le_of_lt,
rotate 1,
apply sub_lt_of_pos,
exact and.left Hδ,
rotate_right 1,
apply sup_le,
exact exists.intro a (and.intro Hab Ha),
intro x Hx,
apply le_of_not_gt,
intro Hxgt,
have Hxgt' : b - x < δ, from sub_lt_of_sub_lt Hxgt,
krewrite [-(abs_of_pos (sub_pos_of_lt (and.left Hx))) at Hxgt', abs_sub at Hxgt'],
note Hxgt'' := and.right Hδ _ Hxgt',
exact not_lt_of_ge (le_of_lt Hxgt'') (and.right Hx)},
{exact sup_fn_interval}
end
end
theorem intermediate_value_decr_zero {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b)
(Ha : f a > 0) (Hb : f b < 0) : ∃ c, a < c ∧ c < b ∧ f c = 0 :=
begin
have Ha' : - f a < 0, from neg_neg_of_pos Ha,
have Hb' : - f b > 0, from neg_pos_of_neg Hb,
have Hcon : continuous (λ x, - f x), from neg_continuous Hf,
let Hiv := intermediate_value_incr_zero Hcon Hab Ha' Hb',
cases Hiv with c Hc,
existsi c,
split,
exact and.left Hc,
split,
exact and.left (and.right Hc),
apply eq_zero_of_neg_eq_zero,
apply and.right (and.right Hc)
end
theorem intermediate_value_incr {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b) {v : ℝ}
(Hav : f a < v) (Hbv : f b > v) : ∃ c, a < c ∧ c < b ∧ f c = v :=
have Hav' : f a - v < 0, from sub_neg_of_lt Hav,
have Hbv' : f b - v > 0, from sub_pos_of_lt Hbv,
have Hcon : continuous (λ x, f x - v), from sub_continuous Hf (continuous_const _),
have Hiv : ∃ c, a < c ∧ c < b ∧ f c - v = 0, from intermediate_value_incr_zero Hcon Hab Hav' Hbv',
obtain c Hc, from Hiv,
exists.intro c
(and.intro (and.left Hc) (and.intro (and.left (and.right Hc)) (eq_of_sub_eq_zero (and.right (and.right Hc)))))
theorem intermediate_value_decr {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a < b) {v : ℝ}
(Hav : f a > v) (Hbv : f b < v) : ∃ c, a < c ∧ c < b ∧ f c = v :=
have Hav' : f a - v > 0, from sub_pos_of_lt Hav,
have Hbv' : f b - v < 0, from sub_neg_of_lt Hbv,
have Hcon : continuous (λ x, f x - v), from sub_continuous Hf (continuous_const _),
have Hiv : ∃ c, a < c ∧ c < b ∧ f c - v = 0, from intermediate_value_decr_zero Hcon Hab Hav' Hbv',
obtain c Hc, from Hiv,
exists.intro c
(and.intro (and.left Hc) (and.intro (and.left (and.right Hc)) (eq_of_sub_eq_zero (and.right (and.right Hc)))))
theorem intermediate_value_incr_weak {f : ℝ → ℝ} (Hf : continuous f) {a b : ℝ} (Hab : a ≤ b) {v : ℝ}
(Hav : f a ≤ v) (Hbv : f b ≥ v) : ∃ c, a ≤ c ∧ c ≤ b ∧ f c = v :=
begin
cases lt_or_eq_of_le Hab with Hlt Heq,
cases lt_or_eq_of_le Hav with Hlt' Heq',
cases lt_or_eq_of_le Hbv with Hlt'' Heq'',
cases intermediate_value_incr Hf Hlt Hlt' Hlt'' with c Hc,
cases Hc with Hc1 Hc2,
cases Hc2 with Hc2 Hc3,
existsi c,
repeat (split; apply le_of_lt; assumption),
assumption,
existsi b,
split,
apply le_of_lt,
assumption,
split,
apply le.refl,
rewrite Heq'',
existsi a,
split,
apply le.refl,
split,
apply le_of_lt,
repeat assumption,
existsi a,
split,
apply le.refl,
split,
assumption,
apply eq_of_le_of_ge,
apply Hav,
rewrite Heq,
apply Hbv
end
|
1e33183485e780d46151a83608f5f35f954f9490 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/group_theory/submonoid/center.lean | 483e9f1bec8c69b8cf41e4c131124f03add38d9f | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,486 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import group_theory.submonoid.operations
/-!
# Centers of magmas and monoids
## Main definitions
* `set.center`: the center of a magma
* `submonoid.center`: the center of a monoid
* `set.add_center`: the center of an additive magma
* `add_submonoid.center`: the center of an additive monoid
We provide `subgroup.center`, `add_subgroup.center`, `subsemiring.center`, and `subring.center` in
other files.
-/
variables {M : Type*}
namespace set
variables (M)
/-- The center of a magma. -/
@[to_additive add_center /-" The center of an additive magma. "-/]
def center [has_mul M] : set M := {z | ∀ m, m * z = z * m}
@[to_additive mem_add_center]
lemma mem_center_iff [has_mul M] {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl
@[simp, to_additive zero_mem_add_center]
lemma one_mem_center [mul_one_class M] : (1 : M) ∈ set.center M := by simp [mem_center_iff]
@[simp]
lemma zero_mem_center [mul_zero_class M] : (0 : M) ∈ set.center M := by simp [mem_center_iff]
variables {M}
@[simp, to_additive add_mem_add_center]
lemma mul_mem_center [semigroup M] {a b : M}
(ha : a ∈ set.center M) (hb : b ∈ set.center M) : a * b ∈ set.center M :=
λ g, by rw [mul_assoc, ←hb g, ← mul_assoc, ha g, mul_assoc]
@[simp, to_additive neg_mem_add_center]
lemma inv_mem_center [group M] {a : M} (ha : a ∈ set.center M) : a⁻¹ ∈ set.center M :=
λ g, by rw [← inv_inj, mul_inv_rev, inv_inv, ← ha, mul_inv_rev, inv_inv]
@[simp]
lemma add_mem_center [distrib M] {a b : M}
(ha : a ∈ set.center M) (hb : b ∈ set.center M) : a + b ∈ set.center M :=
λ c, by rw [add_mul, mul_add, ha c, hb c]
@[simp]
lemma neg_mem_center [ring M] {a : M} (ha : a ∈ set.center M) : -a ∈ set.center M :=
λ c, by rw [←neg_mul_comm, ha (-c), neg_mul_comm]
@[to_additive subset_add_center_add_units]
lemma subset_center_units [monoid M] :
(coe : units M → M) ⁻¹' center M ⊆ set.center (units M) :=
λ a ha b, units.ext $ ha _
lemma center_units_subset [group_with_zero M] :
set.center (units M) ⊆ (coe : units M → M) ⁻¹' center M :=
λ a ha b, begin
obtain rfl | hb := eq_or_ne b 0,
{ rw [zero_mul, mul_zero], },
{ exact units.ext_iff.mp (ha (units.mk0 _ hb)) }
end
/-- In a group with zero, the center of the units is the preimage of the center. -/
lemma center_units_eq [group_with_zero M] :
set.center (units M) = (coe : units M → M) ⁻¹' center M :=
subset.antisymm center_units_subset subset_center_units
@[simp]
lemma inv_mem_center₀ [group_with_zero M] {a : M} (ha : a ∈ set.center M) : a⁻¹ ∈ set.center M :=
begin
obtain rfl | ha0 := eq_or_ne a 0,
{ rw inv_zero, exact zero_mem_center M },
lift a to units M using ha0,
rw ←units.coe_inv',
exact center_units_subset (inv_mem_center (subset_center_units ha)),
end
@[simp, to_additive sub_mem_add_center]
lemma div_mem_center [group M] {a b : M} (ha : a ∈ set.center M) (hb : b ∈ set.center M) :
a / b ∈ set.center M :=
begin
rw [div_eq_mul_inv],
exact mul_mem_center ha (inv_mem_center hb),
end
@[simp]
lemma div_mem_center₀ [group_with_zero M] {a b : M} (ha : a ∈ set.center M)
(hb : b ∈ set.center M) : a / b ∈ set.center M :=
begin
rw div_eq_mul_inv,
exact mul_mem_center ha (inv_mem_center₀ hb),
end
variables (M)
@[simp, to_additive add_center_eq_univ]
lemma center_eq_univ [comm_semigroup M] : center M = set.univ :=
subset.antisymm (subset_univ _) $ λ x _ y, mul_comm y x
end set
namespace submonoid
section
variables (M) [monoid M]
/-- The center of a monoid `M` is the set of elements that commute with everything in `M` -/
@[to_additive "The center of a monoid `M` is the set of elements that commute with everything in
`M`"]
def center : submonoid M :=
{ carrier := set.center M,
one_mem' := set.one_mem_center M,
mul_mem' := λ a b, set.mul_mem_center }
@[to_additive] lemma coe_center : ↑(center M) = set.center M := rfl
variables {M}
@[to_additive] lemma mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl
/-- The center of a monoid is commutative. -/
instance : comm_monoid (center M) :=
{ mul_comm := λ a b, subtype.ext $ b.prop _,
.. (center M).to_monoid }
end
section
variables (M) [comm_monoid M]
@[simp] lemma center_eq_top : center M = ⊤ :=
set_like.coe_injective (set.center_eq_univ M)
end
end submonoid
|
c65f60cfac9bc739ce25caf2823e42f8f69605ad | bb31430994044506fa42fd667e2d556327e18dfe | /src/data/finsupp/defs.lean | ac9ae1845a73b6e6abbc6e8badedcbf1f85c039a | [
"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 | 39,969 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Scott Morrison
-/
import algebra.indicator_function
import group_theory.submonoid.basic
/-!
# Type of functions with finite support
For any type `α` and any 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, which is defined in
`algebra/big_operators/finsupp`.
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.
## Main declarations
* `finsupp`: The type of finitely supported functions from `α` to `β`.
* `finsupp.single`: The `finsupp` which is nonzero in exactly one point.
* `finsupp.update`: Changes one value of a `finsupp`.
* `finsupp.erase`: Replaces one value of a `finsupp` by `0`.
* `finsupp.on_finset`: The restriction of a function to a `finset` as a `finsupp`.
* `finsupp.map_range`: Composition of a `zero_hom` with a `finsupp`.
* `finsupp.emb_domain`: Maps the domain of a `finsupp` by an embedding.
* `finsupp.zip_with`: Postcomposition of two `finsupp`s with a function `f` such that `f 0 0 = 0`.
## 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.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* Expand the list of definitions and important lemmas to the module docstring.
-/
noncomputable theory
open finset function
open_locale classical big_operators
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 fun_like : fun_like (α →₀ M) α (λ _, M) := ⟨to_fun, begin
rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g),
congr',
ext a,
exact (hf _).trans (hg _).symm,
end⟩
/-- Helper instance for when there are too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (α →₀ M) (λ _, α → M) := fun_like.has_coe_to_fun
@[ext] lemma ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g := fun_like.ext _ _ h
/-- Deprecated. Use `fun_like.ext_iff` instead. -/
lemma ext_iff {f g : α →₀ M} : f = g ↔ ∀ a, f a = g a := fun_like.ext_iff
/-- Deprecated. Use `fun_like.coe_fn_eq` instead. -/
lemma coe_fn_inj {f g : α →₀ M} : (f : α → M) = g ↔ f = g := fun_like.coe_fn_eq
/-- Deprecated. Use `fun_like.coe_injective` instead. -/
lemma coe_fn_injective : @function.injective (α →₀ M) (α → M) coe_fn := fun_like.coe_injective
/-- Deprecated. Use `fun_like.congr_fun` instead. -/
lemma congr_fun {f g : α →₀ M} (h : f = g) (a : α) : f a = g a := fun_like.congr_fun h _
@[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
@[simp, norm_cast] lemma coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 :=
by rw [← coe_zero, coe_fn_inj]
lemma ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x :=
⟨λ h, h ▸ ⟨rfl, λ _ _, rfl⟩, λ ⟨h₁, h₂⟩, ext $ λ a,
if h : a ∈ f.support then h₂ a h else
have hf : f a = 0, from not_mem_support_iff.1 h,
have hg : g a = 0, by rwa [h₁, not_mem_support_iff] at h,
by rw [hf, hg]⟩
@[simp] lemma support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
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 `finite α`, `equiv_fun_on_finite` is the `equiv` between `α →₀ β` and `α → β`.
(All functions on a finite type are finitely supported.) -/
@[simps] def equiv_fun_on_finite [finite α] : (α →₀ M) ≃ (α → M) :=
{ to_fun := coe_fn,
inv_fun := λ f, mk (function.support f).to_finite.to_finset f (λ a, set.finite.mem_to_finset _),
left_inv := λ f, ext $ λ x, rfl,
right_inv := λ f, rfl }
@[simp] lemma equiv_fun_on_finite_symm_coe {α} [finite α] (f : α →₀ M) :
equiv_fun_on_finite.symm f = f :=
equiv_fun_on_finite.symm_apply_apply f
/--
If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`.
-/
@[simps] noncomputable
def _root_.equiv.finsupp_unique {ι : Type*} [unique ι] : (ι →₀ M) ≃ M :=
finsupp.equiv_fun_on_finite.trans (equiv.fun_unique ι M)
end basic
/-! ### Declarations about `single` -/
section single
variables [has_zero M] {a a' : α} {b : M}
/-- `single a b` is the finitely supported function with value `b` at `a` and zero otherwise. -/
def single (a : α) (b : M) : α →₀ M :=
⟨if b = 0 then ∅ else {a}, pi.single a b, λ a', begin
obtain rfl | hb := eq_or_ne b 0,
{ simp },
rw [if_neg hb, mem_singleton],
obtain rfl | ha := eq_or_ne a' a,
{ simp [hb] },
simp [pi.single_eq_of_ne', ha],
end⟩
lemma single_apply [decidable (a = a')] : single a b a' = if a = a' then b else 0 :=
by { simp_rw [@eq_comm _ a a'], convert pi.single_apply _ _ _, }
lemma single_apply_left {f : α → β} (hf : function.injective f)
(x z : α) (y : M) :
single (f x) y (f z) = single x y z :=
by simp only [single_apply, hf.eq_iff]
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 :=
pi.single_eq_same a b
@[simp] lemma single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ M) a' = 0 :=
pi.single_eq_of_ne' h _
lemma single_eq_update [decidable_eq α] (a : α) (b : M) : ⇑(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 [decidable_eq α] (a : α) (b : M) : ⇑(single a b) = pi.single a b :=
single_eq_update a b
@[simp] lemma single_zero (a : α) : (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 (a : α) (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 single_apply_ne_zero {a x : α} {b : M} : single a b x ≠ 0 ↔ (x = a ∧ b ≠ 0) :=
by simp [single_apply_eq_zero]
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 ≠ ⊥ :=
by simpa only [support_single_ne_zero _ h] using singleton_ne_empty _
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 rw [support_single_ne_zero _ hb, support_single_ne_zero _ hb', disjoint_singleton]
@[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
@[ext]
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']
lemma support_subset_singleton {f : α →₀ M} {a : α} :
f.support ⊆ {a} ↔ f = single a (f a) :=
⟨λ h, eq_single_iff.mpr ⟨h, rfl⟩, λ h, (eq_single_iff.mp h).left⟩
lemma support_subset_singleton' {f : α →₀ M} {a : α} :
f.support ⊆ {a} ↔ ∃ b, f = single a b :=
⟨λ h, ⟨f a, support_subset_singleton.mp h⟩,
λ ⟨b, hb⟩, by rw [hb, support_subset_singleton, single_eq_same]⟩
lemma card_support_le_one [nonempty α] {f : α →₀ M} :
card f.support ≤ 1 ↔ ∃ a, f = single a (f a) :=
by simp only [card_le_one_iff_subset_singleton, support_subset_singleton]
lemma card_support_le_one' [nonempty α] {f : α →₀ M} :
card f.support ≤ 1 ↔ ∃ a b, f = single a b :=
by simp only [card_le_one_iff_subset_singleton, support_subset_singleton']
@[simp] lemma equiv_fun_on_finite_single [decidable_eq α] [finite α] (x : α) (m : M) :
finsupp.equiv_fun_on_finite (finsupp.single x m) = pi.single x m :=
by { ext, simp [finsupp.single_eq_pi_single], }
@[simp] lemma equiv_fun_on_finite_symm_single [decidable_eq α] [finite α] (x : α) (m : M) :
finsupp.equiv_fun_on_finite.symm (pi.single x m) = finsupp.single x m :=
by rw [← equiv_fun_on_finite_single, equiv.symm_apply_apply]
end single
/-! ### Declarations about `update` -/
section update
variables [has_zero M] (f : α →₀ M) (a : α) (b : M) (i : α)
/-- Replace the value of a `α →₀ M` at a given point `a : α` by a given value `b : M`.
If `b = 0`, this amounts to removing `a` from the `finsupp.support`.
Otherwise, if `a` was not in the `finsupp.support`, it is added to it.
This is the finitely-supported version of `function.update`. -/
def update : α →₀ M :=
⟨if b = 0 then f.support.erase a else insert a f.support,
function.update f a b,
λ i, begin
simp only [function.update_apply, ne.def],
split_ifs with hb ha ha hb;
simp [ha, hb]
end⟩
@[simp] lemma coe_update [decidable_eq α] : (f.update a b : α → M) = function.update f a b :=
by convert rfl
@[simp] lemma update_self : f.update a (f a) = f :=
by { ext, simp }
@[simp] lemma zero_update : update 0 a b = single a b :=
by { ext, rw single_eq_update, refl }
lemma support_update [decidable_eq α] : support (f.update a b) =
if b = 0 then f.support.erase a else insert a f.support := by convert rfl
@[simp] lemma support_update_zero [decidable_eq α] :
support (f.update a 0) = f.support.erase a := by convert if_pos rfl
variables {b}
lemma support_update_ne_zero [decidable_eq α] (h : b ≠ 0) :
support (f.update a b) = insert a f.support := by convert if_neg h
end update
/-! ### 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`.
If `a` is not in the support of `f` then `erase a f = f`.
-/
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 [decidable_eq α] {a : α} {f : α →₀ M} :
(f.erase a).support = f.support.erase a :=
by convert 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_of_not_mem_support {f : α →₀ M} {a} (haf : a ∉ f.support) : erase a f = f :=
begin
ext b, by_cases hab : b = a,
{ rwa [hab, erase_same, eq_comm, ←not_mem_support_iff] },
{ rw erase_ne hab }
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 `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 must 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 : can_lift (α → M) (α →₀ M) coe_fn (λ 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`,
which is well-defined when `f 0 = 0`.
This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself
bundled (defined in `data/finsupp/basic`):
* `finsupp.map_range.equiv`
* `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', by simpa only [single_eq_pi_single] using pi.apply_single _ (λ _, hf) a _ a'
lemma support_map_range_of_injective
{e : M → N} (he0 : e 0 = 0) (f : ι →₀ M) (he : function.injective e) :
(finsupp.map_range e he0 f).support = f.support :=
begin
ext,
simp only [finsupp.mem_support_iff, ne.def, finsupp.map_range_apply],
exact he.ne_iff' he0,
end
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
@[simp] lemma emb_domain_single (f : α ↪ β) (a : α) (m : M) :
emb_domain f (single a m) = single (f a) m :=
begin
ext b,
by_cases h : b ∈ set.range f,
{ rcases h with ⟨a', rfl⟩,
simp [single_apply], },
{ simp only [emb_domain_notin_range, h, single_apply, not_false_iff],
rw if_neg,
rintro rfl,
simpa using h, },
end
end emb_domain
/-! ### Declarations about `zip_with` -/
section zip_with
variables [has_zero M] [has_zero N] [has_zero P]
/-- Given finitely supported functions `g₁ : α →₀ M` and `g₂ : α →₀ N` and function `f : M → N → P`,
`zip_with f hf g₁ g₂` is the finitely supported function `α →₀ P` satisfying
`zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a)`, which 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
/-! ### 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) :=
fun_like.coe_injective.add_zero_class _ coe_zero coe_add
/-- `finsupp.single` as an `add_monoid_hom`.
See `finsupp.lsingle` in `linear_algebra/finsupp` for the stronger version as a linear map. -/
@[simps] def single_add_hom (a : α) : M →+ α →₀ M :=
⟨single a, single_zero a, single_add a⟩
/-- Evaluation of a function `f : α →₀ M` at a point as an additive monoid homomorphism.
See `finsupp.lapply` in `linear_algebra/finsupp` for the stronger version as a linear map. -/
@[simps apply]
def apply_add_hom (a : α) : (α →₀ M) →+ M := ⟨λ g, g a, zero_apply, λ _ _, add_apply _ _ _⟩
/-- Coercion from a `finsupp` to a function type is an `add_monoid_hom`. -/
@[simps]
noncomputable def coe_fn_add_hom : (α →₀ M) →+ (α → M) :=
{ to_fun := coe_fn,
map_zero' := coe_zero,
map_add' := coe_add }
lemma update_eq_single_add_erase (f : α →₀ M) (a : α) (b : M) :
f.update a b = single a b + f.erase a :=
begin
ext j,
rcases eq_or_ne a j with rfl|h,
{ simp },
{ simp [function.update_noteq h.symm, single_apply, h, erase_ne, h.symm] }
end
lemma update_eq_erase_add_single (f : α →₀ M) (a : α) (b : M) :
f.update a b = f.erase a + single a b :=
begin
ext j,
rcases eq_or_ne a j with rfl|h,
{ simp },
{ simp [function.update_noteq h.symm, single_apply, h, erase_ne, h.symm] }
end
lemma single_add_erase (a : α) (f : α →₀ M) : single a (f a) + f.erase a = f :=
by rw [←update_eq_single_add_erase, update_self]
lemma erase_add_single (a : α) (f : α →₀ M) : f.erase a + single a (f a) = f :=
by rw [←update_eq_erase_add_single, update_self]
@[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
/-- `finsupp.erase` as an `add_monoid_hom`. -/
@[simps]
def erase_add_hom (a : α) : (α →₀ M) →+ (α →₀ M) :=
{ to_fun := erase a, map_zero' := erase_zero a, map_add' := erase_add a }
@[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_set_of_eq_single :
add_submonoid.closure {f : α →₀ M | ∃ a b, f = single a b} = ⊤ :=
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 $ ⟨a, b, rfl⟩) 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_set_of_eq_single _,
rintro _ ⟨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 $ λ _, by simp only [hf', add_apply, map_range_apply]
lemma map_range_add' [add_zero_class N] [add_monoid_hom_class β M N]
{f : β} (v₁ v₂ : α →₀ M) :
map_range f (map_zero f) (v₁ + v₂) = map_range f (map_zero f) v₁ + map_range f (map_zero f) v₂ :=
map_range_add (map_add f) v₁ v₂
/-- Bundle `emb_domain f` as an additive map from `α →₀ M` to `β →₀ M`. -/
@[simps] def emb_domain.add_monoid_hom (f : α ↪ β) : (α →₀ M) →+ β →₀ M :=
{ to_fun := λ v, emb_domain f v,
map_zero' := by simp,
map_add' := λ v w,
begin
ext b,
by_cases h : b ∈ set.range f,
{ rcases h with ⟨a, rfl⟩,
simp, },
{ simp [emb_domain_notin_range, h], },
end, }
@[simp] lemma emb_domain_add (f : α ↪ β) (v w : α →₀ M) :
emb_domain f (v + w) = emb_domain f v + emb_domain f w :=
(emb_domain.add_monoid_hom f).map_add v w
end add_zero_class
section add_monoid
variables [add_monoid M]
/-- Note the general `finsupp.has_smul` instance doesn't apply as `ℕ` is not distributive
unless `β i`'s addition is commutative. -/
instance has_nat_scalar : has_smul ℕ (α →₀ M) :=
⟨λ n v, v.map_range ((•) n) (nsmul_zero _)⟩
instance : add_monoid (α →₀ M) :=
fun_like.coe_injective.add_monoid _ coe_zero coe_add (λ _ _, rfl)
end add_monoid
instance [add_comm_monoid M] : add_comm_monoid (α →₀ M) :=
fun_like.coe_injective.add_comm_monoid _ coe_zero coe_add (λ _ _, rfl)
instance [neg_zero_class G] : has_neg (α →₀ G) := ⟨map_range (has_neg.neg) neg_zero⟩
@[simp] lemma coe_neg [neg_zero_class G] (g : α →₀ G) : ⇑(-g) = -g := rfl
lemma neg_apply [neg_zero_class G] (g : α →₀ G) (a : α) : (- g) a = - g a := rfl
lemma map_range_neg [neg_zero_class G] [neg_zero_class H]
{f : G → H} {hf : f 0 = 0} (hf' : ∀ x, f (-x) = -f x) (v : α →₀ G) :
map_range f hf (-v) = -map_range f hf v :=
ext $ λ _, by simp only [hf', neg_apply, map_range_apply]
lemma map_range_neg' [add_group G] [subtraction_monoid H] [add_monoid_hom_class β G H]
{f : β} (v : α →₀ G) :
map_range f (map_zero f) (-v) = -map_range f (map_zero f) v :=
map_range_neg (map_neg f) v
instance [sub_neg_zero_monoid G] : has_sub (α →₀ G) := ⟨zip_with has_sub.sub (sub_zero _)⟩
@[simp] lemma coe_sub [sub_neg_zero_monoid G] (g₁ g₂ : α →₀ G) : ⇑(g₁ - g₂) = g₁ - g₂ :=
rfl
lemma sub_apply [sub_neg_zero_monoid G] (g₁ g₂ : α →₀ G) (a : α) : (g₁ - g₂) a = g₁ a - g₂ a := rfl
lemma map_range_sub [sub_neg_zero_monoid G] [sub_neg_zero_monoid H]
{f : G → H} {hf : f 0 = 0} (hf' : ∀ x y, f (x - y) = f x - f y) (v₁ v₂ : α →₀ G) :
map_range f hf (v₁ - v₂) = map_range f hf v₁ - map_range f hf v₂ :=
ext $ λ _, by simp only [hf', sub_apply, map_range_apply]
lemma map_range_sub' [add_group G] [subtraction_monoid H] [add_monoid_hom_class β G H]
{f : β} (v₁ v₂ : α →₀ G) :
map_range f (map_zero f) (v₁ - v₂) = map_range f (map_zero f) v₁ - map_range f (map_zero f) v₂ :=
map_range_sub (map_sub f) v₁ v₂
/-- Note the general `finsupp.has_smul` instance doesn't apply as `ℤ` is not distributive
unless `β i`'s addition is commutative. -/
instance has_int_scalar [add_group G] : has_smul ℤ (α →₀ G) :=
⟨λ n v, v.map_range ((•) n) (zsmul_zero _)⟩
instance [add_group G] : add_group (α →₀ G) :=
fun_like.coe_injective.add_group _ coe_zero coe_add coe_neg coe_sub
(λ _ _, rfl) (λ _ _, rfl)
instance [add_comm_group G] : add_comm_group (α →₀ G) :=
fun_like.coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub
(λ _ _, rfl) (λ _ _, rfl)
lemma single_add_single_eq_single_add_single [add_comm_monoid M]
{k l m n : α} {u v : M} (hu : u ≠ 0) (hv : v ≠ 0) :
single k u + single l v = single m u + single n v ↔
(k = m ∧ l = n) ∨ (u = v ∧ k = n ∧ l = m) ∨ (u + v = 0 ∧ k = l ∧ m = n) :=
begin
simp_rw [fun_like.ext_iff, coe_add, single_eq_pi_single, ←funext_iff],
exact pi.single_add_single_eq_single_add_single hu hv,
end
@[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)
lemma support_sub [decidable_eq α] [add_group G] {f g : α →₀ G} :
support (f - g) ⊆ support f ∪ support g :=
begin
rw [sub_eq_add_neg, ←support_neg g],
exact support_add,
end
lemma erase_eq_sub_single [add_group G] (f : α →₀ G) (a : α) :
f.erase a = f - single a (f a) :=
begin
ext a',
rcases eq_or_ne a a' with rfl|h,
{ simp },
{ simp [erase_ne h.symm, single_eq_of_ne h] }
end
lemma update_eq_sub_add_single [add_group G] (f : α →₀ G) (a : α) (b : G) :
f.update a b = f - single a (f a) + single a b :=
by rw [update_eq_erase_add_single, erase_eq_sub_single]
end finsupp
|
8e15fd48f43652f2a4cc180dac6a8f8d57c8dea8 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/geometry/manifold/diffeomorph.lean | 0ece1a4cae809a6fff901d46c074d723257aa3f8 | [
"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 | 19,776 | lean | /-
Copyright © 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri, Yury Kudryashov
-/
import geometry.manifold.times_cont_mdiff_map
/-!
# Diffeomorphisms
This file implements diffeomorphisms.
## Definitions
* `diffeomorph I I' M M' n`: `n`-times continuously differentiable diffeomorphism between
`M` and `M'` with respect to I and I'; we do not introduce a separate definition for the case
`n = ∞`; we use notation instead.
* `diffeomorph.to_homeomorph`: reinterpret a diffeomorphism as a homeomorphism.
* `continuous_linear_equiv.to_diffeomorph`: reinterpret a continuous equivalence as
a diffeomorphism.
* `model_with_corners.trans_diffeomorph`: compose a given `model_with_corners` with a diffeomorphism
between the old and the new target spaces. Useful, e.g, to turn any finite dimensional manifold
into a manifold modelled on a Euclidean space.
* `diffeomorph.to_trans_diffeomorph`: the identity diffeomorphism between `M` with model `I` and `M`
with model `I.trans_diffeomorph e`.
## Notations
* `M ≃ₘ^n⟮I, I'⟯ M'` := `diffeomorph I J M N n`
* `M ≃ₘ⟮I, I'⟯ M'` := `diffeomorph I J M N ⊤`
* `E ≃ₘ^n[𝕜] E'` := `E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'`
* `E ≃ₘ[𝕜] E'` := `E ≃ₘ⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'`
## Implementation notes
This notion of diffeomorphism is needed although there is already a notion of structomorphism
because structomorphisms do not allow the model spaces `H` and `H'` of the two manifolds to be
different, i.e. for a structomorphism one has to impose `H = H'` which is often not the case in
practice.
## Keywords
diffeomorphism, manifold
-/
open_locale manifold topological_space
open function set
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{F : Type*} [normed_group F] [normed_space 𝕜 F]
{H : Type*} [topological_space H]
{H' : Type*} [topological_space H']
{G : Type*} [topological_space G]
{I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'}
{J : model_with_corners 𝕜 F G}
variables {M : Type*} [topological_space M] [charted_space H M]
{M' : Type*} [topological_space M'] [charted_space H' M']
{N : Type*} [topological_space N] [charted_space G N]
{n : with_top ℕ}
section defs
variables (I I' M M' n)
/--
`n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I'
-/
@[protect_proj, nolint has_inhabited_instance]
structure diffeomorph extends M ≃ M' :=
(times_cont_mdiff_to_fun : times_cont_mdiff I I' n to_equiv)
(times_cont_mdiff_inv_fun : times_cont_mdiff I' I n to_equiv.symm)
end defs
localized "notation M ` ≃ₘ^` n:1000 `⟮`:50 I `,` J `⟯ ` N := diffeomorph I J M N n" in manifold
localized "notation M ` ≃ₘ⟮` I `,` J `⟯ ` N := diffeomorph I J M N ⊤" in manifold
localized "notation E ` ≃ₘ^` n:1000 `[`:50 𝕜 `] ` E' :=
diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' n" in manifold
localized "notation E ` ≃ₘ[` 𝕜 `] ` E' :=
diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' ⊤" in manifold
namespace diffeomorph
instance : has_coe_to_fun (M ≃ₘ^n⟮I, I'⟯ M') := ⟨λ _, M → M', λe, e.to_equiv⟩
instance : has_coe (M ≃ₘ^n⟮I, I'⟯ M') C^n⟮I, M; I', M'⟯ := ⟨λ Φ, ⟨Φ, Φ.times_cont_mdiff_to_fun⟩⟩
@[continuity] protected lemma continuous (h : M ≃ₘ^n⟮I, I'⟯ M') : continuous h :=
h.times_cont_mdiff_to_fun.continuous
protected lemma times_cont_mdiff (h : M ≃ₘ^n⟮I, I'⟯ M') : times_cont_mdiff I I' n h :=
h.times_cont_mdiff_to_fun
protected lemma times_cont_mdiff_at (h : M ≃ₘ^n⟮I, I'⟯ M') {x} : times_cont_mdiff_at I I' n h x :=
h.times_cont_mdiff.times_cont_mdiff_at
protected lemma times_cont_mdiff_within_at (h : M ≃ₘ^n⟮I, I'⟯ M') {s x} :
times_cont_mdiff_within_at I I' n h s x :=
h.times_cont_mdiff_at.times_cont_mdiff_within_at
protected lemma times_cont_diff (h : E ≃ₘ^n[𝕜] E') : times_cont_diff 𝕜 n h :=
h.times_cont_mdiff.times_cont_diff
protected lemma smooth (h : M ≃ₘ⟮I, I'⟯ M') : smooth I I' h := h.times_cont_mdiff_to_fun
protected lemma mdifferentiable (h : M ≃ₘ^n⟮I, I'⟯ M') (hn : 1 ≤ n) : mdifferentiable I I' h :=
h.times_cont_mdiff.mdifferentiable hn
protected lemma mdifferentiable_on (h : M ≃ₘ^n⟮I, I'⟯ M') (s : set M) (hn : 1 ≤ n) :
mdifferentiable_on I I' h s :=
(h.mdifferentiable hn).mdifferentiable_on
@[simp] lemma coe_to_equiv (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑h.to_equiv = h := rfl
@[simp, norm_cast] lemma coe_coe (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑(h : C^n⟮I, M; I', M'⟯) = h := rfl
lemma to_equiv_injective : injective (diffeomorph.to_equiv : (M ≃ₘ^n⟮I, I'⟯ M') → (M ≃ M'))
| ⟨e, _, _⟩ ⟨e', _, _⟩ rfl := rfl
@[simp] lemma to_equiv_inj {h h' : M ≃ₘ^n⟮I, I'⟯ M'} : h.to_equiv = h'.to_equiv ↔ h = h' :=
to_equiv_injective.eq_iff
/-- Coercion to function `λ h : M ≃ₘ^n⟮I, I'⟯ M', (h : M → M')` is injective. -/
lemma coe_fn_injective : injective (λ (h : M ≃ₘ^n⟮I, I'⟯ M') (x : M), h x) :=
equiv.coe_fn_injective.comp to_equiv_injective
@[ext] lemma ext {h h' : M ≃ₘ^n⟮I, I'⟯ M'} (Heq : ∀ x, h x = h' x) : h = h' :=
coe_fn_injective $ funext Heq
section
variables (M I n)
/-- Identity map as a diffeomorphism. -/
protected def refl : M ≃ₘ^n⟮I, I⟯ M :=
{ times_cont_mdiff_to_fun := times_cont_mdiff_id,
times_cont_mdiff_inv_fun := times_cont_mdiff_id,
to_equiv := equiv.refl M }
@[simp] lemma refl_to_equiv : (diffeomorph.refl I M n).to_equiv = equiv.refl _ := rfl
@[simp] lemma coe_refl : ⇑(diffeomorph.refl I M n) = id := rfl
end
/-- Composition of two diffeomorphisms. -/
protected def trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) :
M ≃ₘ^n⟮I, J⟯ N :=
{ times_cont_mdiff_to_fun := h₂.times_cont_mdiff_to_fun.comp h₁.times_cont_mdiff_to_fun,
times_cont_mdiff_inv_fun := h₁.times_cont_mdiff_inv_fun.comp h₂.times_cont_mdiff_inv_fun,
to_equiv := h₁.to_equiv.trans h₂.to_equiv }
@[simp] lemma trans_refl (h : M ≃ₘ^n⟮I, I'⟯ M') : h.trans (diffeomorph.refl I' M' n) = h :=
ext $ λ _, rfl
@[simp] lemma refl_trans (h : M ≃ₘ^n⟮I, I'⟯ M') : (diffeomorph.refl I M n).trans h = h :=
ext $ λ _, rfl
@[simp] lemma coe_trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) :
⇑(h₁.trans h₂) = h₂ ∘ h₁ := rfl
/-- Inverse of a diffeomorphism. -/
protected def symm (h : M ≃ₘ^n⟮I, J⟯ N) : N ≃ₘ^n⟮J, I⟯ M :=
{ times_cont_mdiff_to_fun := h.times_cont_mdiff_inv_fun,
times_cont_mdiff_inv_fun := h.times_cont_mdiff_to_fun,
to_equiv := h.to_equiv.symm }
@[simp] lemma apply_symm_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : N) : h (h.symm x) = x :=
h.to_equiv.apply_symm_apply x
@[simp] lemma symm_apply_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : M) : h.symm (h x) = x :=
h.to_equiv.symm_apply_apply x
@[simp] lemma symm_refl : (diffeomorph.refl I M n).symm = diffeomorph.refl I M n :=
ext $ λ _, rfl
@[simp] lemma trans_symm (h : M ≃ₘ^n⟮I, J⟯ N) : h.trans h.symm = diffeomorph.refl I M n :=
ext h.symm_apply_apply
@[simp] lemma symm_trans (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.trans h = diffeomorph.refl J N n :=
ext h.apply_symm_apply
@[simp] lemma symm_trans' (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) :
(h₁.trans h₂).symm = h₂.symm.trans h₁.symm := rfl
@[simp] lemma symm_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.to_equiv = h.to_equiv.symm := rfl
@[simp, mfld_simps] lemma to_equiv_coe_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_equiv.symm = h.symm := rfl
lemma image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h '' s = h.symm ⁻¹' s :=
h.to_equiv.image_eq_preimage s
lemma symm_image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h.symm '' s = h ⁻¹' s :=
h.symm.image_eq_preimage s
@[simp, mfld_simps] lemma range_comp {α} (h : M ≃ₘ^n⟮I, J⟯ N) (f : α → M) :
range (h ∘ f) = h.symm ⁻¹' (range f) :=
by rw [range_comp, image_eq_preimage]
@[simp] lemma image_symm_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h '' (h.symm '' s) = s :=
h.to_equiv.image_symm_image s
@[simp] lemma symm_image_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h.symm '' (h '' s) = s :=
h.to_equiv.symm_image_image s
/-- A diffeomorphism is a homeomorphism. -/
def to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : M ≃ₜ N :=
⟨h.to_equiv, h.continuous, h.symm.continuous⟩
@[simp] lemma to_homeomorph_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) :
h.to_homeomorph.to_equiv = h.to_equiv :=
rfl
@[simp] lemma symm_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) :
h.symm.to_homeomorph = h.to_homeomorph.symm :=
rfl
@[simp] lemma coe_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_homeomorph = h := rfl
@[simp] lemma coe_to_homeomorph_symm (h : M ≃ₘ^n⟮I, J⟯ N) :
⇑h.to_homeomorph.symm = h.symm := rfl
@[simp] lemma times_cont_mdiff_within_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'}
{s x} (hm : m ≤ n) :
times_cont_mdiff_within_at I I' m (f ∘ h) s x ↔
times_cont_mdiff_within_at J I' m f (h.symm ⁻¹' s) (h x) :=
begin
split,
{ intro Hfh,
rw [← h.symm_apply_apply x] at Hfh,
simpa only [(∘), h.apply_symm_apply]
using Hfh.comp (h x) (h.symm.times_cont_mdiff_within_at.of_le hm) (maps_to_preimage _ _) },
{ rw ← h.image_eq_preimage,
exact λ hf, hf.comp x (h.times_cont_mdiff_within_at.of_le hm) (maps_to_image _ _) }
end
@[simp] lemma times_cont_mdiff_on_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'}
{s} (hm : m ≤ n) :
times_cont_mdiff_on I I' m (f ∘ h) s ↔ times_cont_mdiff_on J I' m f (h.symm ⁻¹' s) :=
h.to_equiv.forall_congr $ λ x, by simp only [hm, coe_to_equiv, symm_apply_apply,
times_cont_mdiff_within_at_comp_diffeomorph_iff, mem_preimage]
@[simp] lemma times_cont_mdiff_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {x}
(hm : m ≤ n) :
times_cont_mdiff_at I I' m (f ∘ h) x ↔ times_cont_mdiff_at J I' m f (h x) :=
h.times_cont_mdiff_within_at_comp_diffeomorph_iff hm
@[simp] lemma times_cont_mdiff_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'}
(hm : m ≤ n) :
times_cont_mdiff I I' m (f ∘ h) ↔ times_cont_mdiff J I' m f :=
h.to_equiv.forall_congr $ λ x, (h.times_cont_mdiff_at_comp_diffeomorph_iff hm)
@[simp] lemma times_cont_mdiff_within_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) {s x} :
times_cont_mdiff_within_at I' J m (h ∘ f) s x ↔ times_cont_mdiff_within_at I' I m f s x :=
⟨λ Hhf, by simpa only [(∘), h.symm_apply_apply]
using (h.symm.times_cont_mdiff_at.of_le hm).comp_times_cont_mdiff_within_at _ Hhf,
λ Hf, (h.times_cont_mdiff_at.of_le hm).comp_times_cont_mdiff_within_at _ Hf⟩
@[simp] lemma times_cont_mdiff_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) {x} :
times_cont_mdiff_at I' J m (h ∘ f) x ↔ times_cont_mdiff_at I' I m f x :=
h.times_cont_mdiff_within_at_diffeomorph_comp_iff hm
@[simp] lemma times_cont_mdiff_on_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) {s} :
times_cont_mdiff_on I' J m (h ∘ f) s ↔ times_cont_mdiff_on I' I m f s :=
forall_congr $ λ x, forall_congr $ λ hx, h.times_cont_mdiff_within_at_diffeomorph_comp_iff hm
@[simp] lemma times_cont_mdiff_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M}
(hm : m ≤ n) :
times_cont_mdiff I' J m (h ∘ f) ↔ times_cont_mdiff I' I m f :=
forall_congr $ λ x, h.times_cont_mdiff_within_at_diffeomorph_comp_iff hm
lemma to_local_homeomorph_mdifferentiable (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) :
h.to_homeomorph.to_local_homeomorph.mdifferentiable I J :=
⟨h.mdifferentiable_on _ hn, h.symm.mdifferentiable_on _ hn⟩
variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners J N]
lemma unique_mdiff_on_image_aux (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n)
{s : set M} (hs : unique_mdiff_on I s) :
unique_mdiff_on J (h '' s) :=
begin
convert hs.unique_mdiff_on_preimage (h.to_local_homeomorph_mdifferentiable hn),
simp [h.image_eq_preimage]
end
@[simp] lemma unique_mdiff_on_image (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set M} :
unique_mdiff_on J (h '' s) ↔ unique_mdiff_on I s :=
⟨λ hs, h.symm_image_image s ▸ h.symm.unique_mdiff_on_image_aux hn hs,
h.unique_mdiff_on_image_aux hn⟩
@[simp] lemma unique_mdiff_on_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set N} :
unique_mdiff_on I (h ⁻¹' s) ↔ unique_mdiff_on J s :=
h.symm_image_eq_preimage s ▸ h.symm.unique_mdiff_on_image hn
@[simp] lemma unique_diff_on_image (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set E} :
unique_diff_on 𝕜 (h '' s) ↔ unique_diff_on 𝕜 s :=
by simp only [← unique_mdiff_on_iff_unique_diff_on, unique_mdiff_on_image, hn]
@[simp] lemma unique_diff_on_preimage (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set F} :
unique_diff_on 𝕜 (h ⁻¹' s) ↔ unique_diff_on 𝕜 s :=
h.symm_image_eq_preimage s ▸ h.symm.unique_diff_on_image hn
end diffeomorph
namespace continuous_linear_equiv
variable (e : E ≃L[𝕜] E')
/-- A continuous linear equivalence between normed spaces is a diffeomorphism. -/
def to_diffeomorph : E ≃ₘ[𝕜] E' :=
{ times_cont_mdiff_to_fun := e.times_cont_diff.times_cont_mdiff,
times_cont_mdiff_inv_fun := e.symm.times_cont_diff.times_cont_mdiff,
to_equiv := e.to_linear_equiv.to_equiv }
@[simp] lemma coe_to_diffeomorph : ⇑e.to_diffeomorph = e := rfl
@[simp] lemma symm_to_diffeomorph : e.symm.to_diffeomorph = e.to_diffeomorph.symm := rfl
@[simp] lemma coe_to_diffeomorph_symm : ⇑e.to_diffeomorph.symm = e.symm := rfl
end continuous_linear_equiv
namespace model_with_corners
variables (I) (e : E ≃ₘ[𝕜] E')
/-- Apply a diffeomorphism (e.g., a continuous linear equivalence) to the model vector space. -/
def trans_diffeomorph (I : model_with_corners 𝕜 E H) (e : E ≃ₘ[𝕜] E') :
model_with_corners 𝕜 E' H :=
{ to_local_equiv := I.to_local_equiv.trans e.to_equiv.to_local_equiv,
source_eq := by simp,
unique_diff' := by simp [range_comp e, I.unique_diff],
continuous_to_fun := e.continuous.comp I.continuous,
continuous_inv_fun := I.continuous_symm.comp e.symm.continuous }
@[simp, mfld_simps] lemma coe_trans_diffeomorph : ⇑(I.trans_diffeomorph e) = e ∘ I := rfl
@[simp, mfld_simps] lemma coe_trans_diffeomorph_symm :
⇑(I.trans_diffeomorph e).symm = I.symm ∘ e.symm := rfl
lemma trans_diffeomorph_range : range (I.trans_diffeomorph e) = e '' (range I) :=
range_comp e I
lemma coe_ext_chart_at_trans_diffeomorph (x : M) :
⇑(ext_chart_at (I.trans_diffeomorph e) x) = e ∘ ext_chart_at I x := rfl
lemma coe_ext_chart_at_trans_diffeomorph_symm (x : M) :
⇑(ext_chart_at (I.trans_diffeomorph e) x).symm = (ext_chart_at I x).symm ∘ e.symm := rfl
lemma ext_chart_at_trans_diffeomorph_target (x : M) :
(ext_chart_at (I.trans_diffeomorph e) x).target = e.symm ⁻¹' (ext_chart_at I x).target :=
by simp only [range_comp e, e.image_eq_preimage, preimage_preimage] with mfld_simps
end model_with_corners
namespace diffeomorph
variables (e : E ≃ₘ[𝕜] F)
instance smooth_manifold_with_corners_trans_diffeomorph [smooth_manifold_with_corners I M] :
smooth_manifold_with_corners (I.trans_diffeomorph e) M :=
begin
refine smooth_manifold_with_corners_of_times_cont_diff_on _ _ (λ e₁ e₂ h₁ h₂, _),
refine e.times_cont_diff.comp_times_cont_diff_on
(((times_cont_diff_groupoid ⊤ I).compatible h₁ h₂).1.comp
e.symm.times_cont_diff.times_cont_diff_on _),
mfld_set_tac
end
variables (I M)
/-- The identity diffeomorphism between a manifold with model `I` and the same manifold
with model `I.trans_diffeomorph e`. -/
def to_trans_diffeomorph (e : E ≃ₘ[𝕜] F) : M ≃ₘ⟮I, I.trans_diffeomorph e⟯ M :=
{ to_equiv := equiv.refl M,
times_cont_mdiff_to_fun := λ x,
begin
refine times_cont_mdiff_within_at_iff.2 ⟨continuous_within_at_id, _⟩,
refine e.times_cont_diff.times_cont_diff_within_at.congr' (λ y hy, _) _,
{ simp only [equiv.coe_refl, id, (∘), I.coe_ext_chart_at_trans_diffeomorph,
(ext_chart_at I x).right_inv hy.1] },
exact ⟨(ext_chart_at I x).map_source (mem_ext_chart_source I x), trivial,
by simp only with mfld_simps⟩
end,
times_cont_mdiff_inv_fun := λ x,
begin
refine times_cont_mdiff_within_at_iff.2 ⟨continuous_within_at_id, _⟩,
refine e.symm.times_cont_diff.times_cont_diff_within_at.congr' (λ y hy, _) _,
{ simp only [mem_inter_eq, I.ext_chart_at_trans_diffeomorph_target] at hy,
simp only [equiv.coe_refl, equiv.refl_symm, id, (∘),
I.coe_ext_chart_at_trans_diffeomorph_symm, (ext_chart_at I x).right_inv hy.1] },
exact ⟨(ext_chart_at _ x).map_source (mem_ext_chart_source _ x), trivial,
by simp only [e.symm_apply_apply, equiv.refl_symm, equiv.coe_refl] with mfld_simps⟩
end }
variables {I M}
@[simp] lemma times_cont_mdiff_within_at_trans_diffeomorph_right {f : M' → M} {x s} :
times_cont_mdiff_within_at I' (I.trans_diffeomorph e) n f s x ↔
times_cont_mdiff_within_at I' I n f s x :=
(to_trans_diffeomorph I M e).times_cont_mdiff_within_at_diffeomorph_comp_iff le_top
@[simp] lemma times_cont_mdiff_at_trans_diffeomorph_right {f : M' → M} {x} :
times_cont_mdiff_at I' (I.trans_diffeomorph e) n f x ↔ times_cont_mdiff_at I' I n f x :=
(to_trans_diffeomorph I M e).times_cont_mdiff_at_diffeomorph_comp_iff le_top
@[simp] lemma times_cont_mdiff_on_trans_diffeomorph_right {f : M' → M} {s} :
times_cont_mdiff_on I' (I.trans_diffeomorph e) n f s ↔ times_cont_mdiff_on I' I n f s :=
(to_trans_diffeomorph I M e).times_cont_mdiff_on_diffeomorph_comp_iff le_top
@[simp] lemma times_cont_mdiff_trans_diffeomorph_right {f : M' → M} :
times_cont_mdiff I' (I.trans_diffeomorph e) n f ↔ times_cont_mdiff I' I n f :=
(to_trans_diffeomorph I M e).times_cont_mdiff_diffeomorph_comp_iff le_top
@[simp] lemma smooth_trans_diffeomorph_right {f : M' → M} :
smooth I' (I.trans_diffeomorph e) f ↔ smooth I' I f :=
times_cont_mdiff_trans_diffeomorph_right e
@[simp] lemma times_cont_mdiff_within_at_trans_diffeomorph_left {f : M → M'} {x s} :
times_cont_mdiff_within_at (I.trans_diffeomorph e) I' n f s x ↔
times_cont_mdiff_within_at I I' n f s x :=
((to_trans_diffeomorph I M e).times_cont_mdiff_within_at_comp_diffeomorph_iff le_top).symm
@[simp] lemma times_cont_mdiff_at_trans_diffeomorph_left {f : M → M'} {x} :
times_cont_mdiff_at (I.trans_diffeomorph e) I' n f x ↔ times_cont_mdiff_at I I' n f x :=
((to_trans_diffeomorph I M e).times_cont_mdiff_at_comp_diffeomorph_iff le_top).symm
@[simp] lemma times_cont_mdiff_on_trans_diffeomorph_left {f : M → M'} {s} :
times_cont_mdiff_on (I.trans_diffeomorph e) I' n f s ↔ times_cont_mdiff_on I I' n f s :=
((to_trans_diffeomorph I M e).times_cont_mdiff_on_comp_diffeomorph_iff le_top).symm
@[simp] lemma times_cont_mdiff_trans_diffeomorph_left {f : M → M'} :
times_cont_mdiff (I.trans_diffeomorph e) I' n f ↔ times_cont_mdiff I I' n f :=
((to_trans_diffeomorph I M e).times_cont_mdiff_comp_diffeomorph_iff le_top).symm
@[simp] lemma smooth_trans_diffeomorph_left {f : M → M'} :
smooth (I.trans_diffeomorph e) I' f ↔ smooth I I' f :=
e.times_cont_mdiff_trans_diffeomorph_left
end diffeomorph
|
942972e127bfca359e44a5caef47c21490c36642 | 4aca55eba10c989f0d58647d3c2f371e7da44355 | /src/set_finset_fintype.lean | e19ead7ca6b7a8fd3e4b85523d025e759d594fe7 | [] | no_license | eric-wieser/l534zhan-my_project | f9fc75fb5454405e1a2fa9b56cf96c355f6f2336 | febc91e76b7b00fe2517f258ca04d27b7f35fcf3 | refs/heads/master | 1,689,218,910,420 | 1,630,439,440,000 | 1,630,439,440,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,753 | lean | /-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Lu-Ming Zhang.
-/
import tactic
import data.finset.basic
import data.fintype.card
/-!
This file supplements things about `set`, `finset`, `fintype`, that are current missing in mathlib.
## Main definition
- `set.card`: given a set `S : set I`, `S.card` is a shortcut of `S.to_finset.card`,
under the conditions `[decidable_pred (λ (x : I), x ∈ S)] [fintype ↥S]`.
-/
local attribute [instance] set_fintype
open_locale big_operators
namespace set
variables {I : Type*} (S T U : set I)
lemma union_compl : S ∪ set.compl S = @set.univ I := by ext; simp
lemma union_compl' : S ∪ (λ x, ¬ (S x)) = @set.univ I :=
by {ext, simp, exact em (S x)}
@[simp] lemma inter_eq_empty_of_compl : S ∩ S.compl = ∅ := by simp
@[simp] lemma inter_eq_empty_of_compl' : S ∩ (λ x, ¬ (S x)) = ∅ := by {ext, simp, tauto}
lemma disjoint_of_compl: disjoint S S.compl := by simp [set.disjoint_iff_inter_eq_empty]
lemma disjoint_of_compl': disjoint S (λ x, ¬ (S x)) := by simp [set.disjoint_iff_inter_eq_empty]
/-- Given a set `S : set I`, `S.card` is a shortcut of `S.to_finset.card`. -/
def card [decidable_pred (λ (x : I), x ∈ S)] [fintype ↥S] : ℕ := S.to_finset.card
lemma univ_card_eq_fintype_card [fintype I] : (@set.univ I).card = fintype.card I :=
by simp [card, fintype.card]
@[simp] lemma coe_union_to_finset
[decidable_eq I] [fintype ↥S] [fintype ↥T] :
↑(S.to_finset ∪ T.to_finset) = S ∪ T :=
by ext; simp
instance union_decidable (x : I)
[decidable_pred (λ (x : I), x ∈ S)] [decidable_pred (λ (x : I), x ∈ T)] :
decidable (x ∈ (S ∪ T)) :=
by {simp [set.mem_union x S T], exact or.decidable}
instance union_decidable_pred
[decidable_pred (λ (x : I), x ∈ S)] [decidable_pred (λ (x : I), x ∈ T)] :
decidable_pred (λ (x : I), x ∈ (S ∪ T)) :=
infer_instance
variables {S T U}
lemma to_finset_union_eq_iff [decidable_eq I]
[fintype ↥S] [fintype ↥T] [fintype ↥U] :
S.to_finset ∪ T.to_finset = U.to_finset ↔ S ∪ T = U :=
by simp [←to_finset_union, set.to_finset_inj]
lemma card_disjoint_union [decidable_eq I]
[decidable_pred (λ (x : I), x ∈ S)] [fintype ↥S]
[decidable_pred (λ (x : I), x ∈ T)] [fintype ↥T]
(h : disjoint S T):
(S ∪ T).card = S.card + T.card :=
begin
have h' := to_finset_disjoint_iff.2 h,
dsimp [card],
rw [← finset.card_disjoint_union h', to_finset_union],
end
lemma card_disjoint_union' [decidable_eq I]
[decidable_pred (λ (x : I), x ∈ S)] [fintype ↥S]
[decidable_pred (λ (x : I), x ∈ T)] [fintype ↥T]
[decidable_pred (λ (x : I), x ∈ U)] [fintype ↥U]
(d : disjoint S T) (u : S ∪ T = U) :
(U).card = S.card + T.card :=
begin
rw ← card_disjoint_union d,
congr,
rw u,
end
end set
variables {α β I : Type*} [comm_monoid β] [fintype I]
open fintype finset
lemma finset.univ_eq_set_univ_to_finset : -- DO NOT use in simp!!!
finset.univ = (@set.univ I).to_finset := set.to_finset_univ.symm
lemma fintype.card_eq_finset_card_of_set (S : set α)
[fintype ↥S] [decidable_pred (λ (x : α), x ∈ S)]:
fintype.card S = finset.card (set.to_finset S) :=
by simp only [set.to_finset_card]
variable (I)
lemma fintype.card_eq_finset_card_of_univ :
fintype.card I = finset.card (@finset.univ I _):=
by simp only [fintype.card]
lemma fintype.card_eq_set_card_of_univ :
fintype.card I = (@set.univ I).card :=
by simp [set.card, fintype.card]
variable {I}
lemma finset.card_eq_sum_ones_ℚ {s : finset α}: (s.card : ℚ) = ∑ _ in s, 1 :=
by rw (finset.card_eq_sum_ones s); simp
@[to_additive]
lemma finset.prod_union' [decidable_eq α] {s₁ s₂ s : finset α} {f : α → β}
(d : disjoint s₁ s₂) (u : s₁ ∪ s₂ = s):
(∏ x in s, f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=
by simp [*, ← finset.prod_union]
@[to_additive]
lemma set.prod_union' [decidable_eq α] {S T U : set α} {f : α → β}
[fintype ↥S] [fintype ↥T] [fintype ↥U]
(d : disjoint S T) (u : S ∪ T = U):
(∏ x in U.to_finset, f x) =
(∏ x in S.to_finset, f x) *
(∏ x in T.to_finset, f x) :=
begin
have d' := set.to_finset_disjoint_iff.2 d,
have u' := set.to_finset_union_eq_iff.2 u,
rw ← finset.prod_union' d' u',
end
lemma finset.card_erase_of_mem' [decidable_eq α] {a : α} {s : finset α} :
a ∈ s → finset.card s = finset.card (finset.erase s a) + 1:=
begin
intro ha,
have h:= finset.card_pos.mpr ⟨a, ha⟩,
simp [finset.card_erase_of_mem ha, *],
exact (nat.succ_pred_eq_of_pos h).symm
end
attribute [to_additive] fintype.prod_dite
lemma fintype.sum_split {α} {β} [fintype α] [add_comm_monoid β]
{f : α → β} (p : α → Prop) [decidable_pred p] :
∑ j, f j =
∑ j : {j : α // p j}, f j +
∑ j : {j : α //¬ p j}, f j :=
by simp [←fintype.sum_dite (λ a _, f a) (λ a _, f a)]
lemma fintype.sum_split' {α} {β} [fintype α] [add_comm_monoid β]
{f : α → β} (p q : α → Prop) [decidable_pred p] [decidable_pred q] :
∑ j : {j : α // p j}, f j =
∑ j : {j : α // p j ∧ q j}, f j +
∑ j : {j : α // p j ∧ ¬ q j}, f j :=
begin
set q': (subtype p) → Prop := λ a, q (a.1),
simp [fintype.sum_split q'],
suffices h₁ : ∑ (j : {j // q' j}), f j = ∑ (j : {j // p j ∧ q j}), f j,
suffices h₂ : ∑ (j : {j // ¬q' j}), f j = ∑ (j : {j // p j ∧ ¬q j}), f j,
simp [←h₁, ←h₂],
set g : {j // ¬q' j} → {j // p j ∧ ¬q j} := λ a, ⟨a.1.1, by tidy⟩,
swap 2,
set g : {j // q' j} → {j // p j ∧ q j} := λ a, ⟨a.1.1, by tidy⟩,
any_goals
{ have hg : function.bijective g :=
⟨λ a b hab, by tidy, λ a, by tidy⟩,
convert function.bijective.sum_comp hg _,
ext, congr' 1 },
end
lemma fintype.card_split {α} [fintype α]
(p : α → Prop) [decidable_pred p] :
fintype.card α =
fintype.card {j : α // p j} +
fintype.card {j : α // ¬ p j} :=
by simp only [fintype.card_eq_sum_ones, fintype.sum_split p]
lemma fintype.card_split' {α} [fintype α]
(p q : α → Prop) [decidable_pred p] [decidable_pred q]:
fintype.card {j : α // p j} =
fintype.card {j : α // p j ∧ q j} +
fintype.card {j : α // p j ∧ ¬ q j} :=
begin
have eq:= @fintype.sum_split' _ _ _ _ (λ _, 1) p q _ _,
simp[*, fintype.card_eq_sum_ones] at *,
end
lemma finset.sum_split {α} {β} [add_comm_monoid β]
(s : finset α) {f : α → β} (p : α → Prop) [decidable_pred p] :
∑ j in s, f j =
∑ j in filter p s, f j +
∑ j in filter (λ (x : α), ¬p x) s, f j :=
by simp [←finset.sum_ite (λ j, f j) (λ j, f j)]
@[simp]
lemma finset.sum_filter_one {β} [add_comm_monoid β] [decidable_eq I]
(i : I) {f : I → β}:
∑ (x : I) in filter (λ (x : I), x = i) univ, f x = f i :=
begin
simp [finset.filter_eq'],
end
@[simp]
lemma finset.sum_filter_two {β} [add_comm_monoid β] [decidable_eq I]
{i j : I} (h : i ≠ j) {f : I → β}:
∑ (k : I) in filter (λ (k : I), k = i ∨ k = j) univ, f k = f i + f j :=
begin
rw [finset.sum_split _ (λ k, k = i)],
simp [finset.filter_eq', finset.filter_ne'],
have : ∑ (x : I) in (filter (λ (k : I), k = i ∨ k = j) univ).erase i, f x
= ∑ (x : I) in filter (λ (x : I), x = j) univ, f x,
{ apply finset.sum_congr,
{ ext, simp, split,
{ rintros ⟨h₁, (h₂ | h₂)⟩, contradiction, assumption },
{ rintros rfl, use ⟨h.symm, or.inr rfl⟩ } },
{ rintros, refl } },
simp [this],
end
|
c3ec71955debfe62add29a0aad193c76dc9aec04 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/data/polynomial/degree/definitions.lean | e212344aefcbe145440f58725a0e18d01d5b19b9 | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 38,928 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.monomial
import data.nat.with_bot
/-!
# Theory of univariate polynomials
The definitions include
`degree`, `monic`, `leading_coeff`
Results include
- `degree_mul` : The degree of the product is the sum of degrees
- `leading_coeff_add_of_degree_eq` and `leading_coeff_add_of_degree_lt` :
The leading_coefficient of a sum is determined by the leading coefficients and degrees
-/
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
open finsupp finset
open_locale big_operators
namespace polynomial
universes u v
variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
section semiring
variables [semiring R] {p q r : polynomial R}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : polynomial R) : with_bot ℕ := p.support.sup some
lemma degree_lt_wf : well_founded (λp q : polynomial R, degree p < degree q) :=
inv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)
instance : has_well_founded (polynomial R) := ⟨_, degree_lt_wf⟩
/-- `nat_degree p` forces `degree p` to ℕ, by defining nat_degree 0 = 0. -/
def nat_degree (p : polynomial R) : ℕ := (degree p).get_or_else 0
/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/
def leading_coeff (p : polynomial R) : R := coeff p (nat_degree p)
/-- a polynomial is `monic` if its leading coefficient is 1 -/
def monic (p : polynomial R) := leading_coeff p = (1 : R)
@[nontriviality] lemma monic_of_subsingleton [subsingleton R] (p : polynomial R) : monic p :=
subsingleton.elim _ _
lemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl
instance monic.decidable [decidable_eq R] : decidable (monic p) :=
by unfold monic; apply_instance
@[simp] lemma monic.leading_coeff {p : polynomial R} (hp : p.monic) :
leading_coeff p = 1 := hp
lemma monic.coeff_nat_degree {p : polynomial R} (hp : p.monic) : p.coeff p.nat_degree = 1 := hp
@[simp] lemma degree_zero : degree (0 : polynomial R) = ⊥ := rfl
@[simp] lemma nat_degree_zero : nat_degree (0 : polynomial R) = 0 := rfl
@[simp] lemma coeff_nat_degree : coeff p (nat_degree p) = leading_coeff p := rfl
lemma degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h;
exact support_eq_empty.1 (max_eq_none.1 h),
λ h, h.symm ▸ rfl⟩
@[nontriviality] lemma degree_of_subsingleton [subsingleton R] : degree p = ⊥ :=
by rw [subsingleton.elim p 0, degree_zero]
@[nontriviality] lemma nat_degree_of_subsingleton [subsingleton R] : nat_degree p = 0 :=
by rw [subsingleton.elim p 0, nat_degree_zero]
lemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) :=
let ⟨n, hn⟩ :=
not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in
have hn : degree p = some n := not_not.1 hn,
by rw [nat_degree, hn]; refl
lemma degree_eq_iff_nat_degree_eq {p : polynomial R} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.nat_degree = n :=
by rw [degree_eq_nat_degree hp, with_bot.coe_eq_coe]
lemma degree_eq_iff_nat_degree_eq_of_pos {p : polynomial R} {n : ℕ} (hn : 0 < n) :
p.degree = n ↔ p.nat_degree = n :=
begin
split,
{ intro H, rwa ← degree_eq_iff_nat_degree_eq, rintro rfl,
rw degree_zero at H, exact option.no_confusion H },
{ intro H, rwa degree_eq_iff_nat_degree_eq, rintro rfl,
rw nat_degree_zero at H, rw H at hn, exact lt_irrefl _ hn }
end
lemma nat_degree_eq_of_degree_eq_some {p : polynomial R} {n : ℕ}
(h : degree p = n) : nat_degree p = n :=
have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,
option.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n,
by rwa [← degree_eq_nat_degree hp0]
@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=
with_bot.gi_get_or_else_bot.gc.le_u_l _
lemma nat_degree_eq_of_degree_eq [semiring S] {q : polynomial S} (h : degree p = degree q) :
nat_degree p = nat_degree q :=
by unfold nat_degree; rw h
lemma le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : with_bot ℕ) ≤ degree p :=
show @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ),
from finset.le_sup (finsupp.mem_support_iff.2 h)
lemma le_nat_degree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ nat_degree p :=
begin
rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],
exact le_degree_of_ne_zero h,
{ assume h, subst h, exact h rfl }
end
lemma le_nat_degree_of_mem_supp (a : ℕ) :
a ∈ p.support → a ≤ nat_degree p:=
le_nat_degree_of_ne_zero ∘ mem_support_iff.mp
lemma supp_subset_range (h : nat_degree p < m) : p.support ⊆ finset.range m :=
λ n hn, mem_range.2 $ (le_nat_degree_of_mem_supp _ hn).trans_lt h
lemma supp_subset_range_nat_degree_succ : p.support ⊆ finset.range (nat_degree p + 1) :=
supp_subset_range (nat.lt_succ_self _)
lemma degree_le_degree (h : coeff q (nat_degree p) ≠ 0) : degree p ≤ degree q :=
begin
by_cases hp : p = 0,
{ rw hp, exact bot_le },
{ rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h }
end
lemma degree_ne_of_nat_degree_ne {n : ℕ} :
p.nat_degree ≠ n → degree p ≠ n :=
mt $ λ h, by rw [nat_degree, h, option.get_or_else_coe]
theorem nat_degree_le_iff_degree_le {n : ℕ} : nat_degree p ≤ n ↔ degree p ≤ n :=
with_bot.get_or_else_bot_le_iff
alias polynomial.nat_degree_le_iff_degree_le ↔ . .
lemma nat_degree_le_nat_degree (hpq : p.degree ≤ q.degree) : p.nat_degree ≤ q.nat_degree :=
with_bot.gi_get_or_else_bot.gc.monotone_l hpq
@[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) :=
show sup (ite (a = 0) ∅ {0}) some = 0, by rw if_neg ha; refl
lemma degree_C_le : degree (C a) ≤ (0 : with_bot ℕ) :=
by by_cases h : a = 0; [rw [h, C_0], rw [degree_C h]]; [exact bot_le, exact le_refl _]
lemma degree_one_le : degree (1 : polynomial R) ≤ (0 : with_bot ℕ) :=
by rw [← C_1]; exact degree_C_le
@[simp] lemma nat_degree_C (a : R) : nat_degree (C a) = 0 :=
begin
by_cases ha : a = 0,
{ have : C a = 0, { rw [ha, C_0] },
rw [nat_degree, degree_eq_bot.2 this],
refl },
{ rw [nat_degree, degree_C ha], refl }
end
@[simp] lemma nat_degree_one : nat_degree (1 : polynomial R) = 0 := nat_degree_C 1
@[simp] lemma nat_degree_nat_cast (n : ℕ) : nat_degree (n : polynomial R) = 0 :=
by simp only [←C_eq_nat_cast, nat_degree_C]
@[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n :=
by rw [degree, support_monomial _ _ ha]; refl
@[simp] lemma degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n :=
by rw [← single_eq_C_mul_X, degree_monomial n ha]
lemma degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=
if h : a = 0 then by rw [h, (monomial n).map_zero]; exact bot_le else le_of_eq (degree_monomial n h)
lemma degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n :=
by { rw C_mul_X_pow_eq_monomial, apply degree_monomial_le }
@[simp] lemma nat_degree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : nat_degree (C a * X ^ n) = n :=
nat_degree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)
@[simp] lemma nat_degree_C_mul_X (a : R) (ha : a ≠ 0) : nat_degree (C a * X) = 1 :=
by simpa only [pow_one] using nat_degree_C_mul_X_pow 1 a ha
@[simp] lemma nat_degree_monomial (i : ℕ) (r : R) (hr : r ≠ 0) :
nat_degree (monomial i r) = i :=
by rw [← C_mul_X_pow_eq_monomial, nat_degree_C_mul_X_pow i r hr]
lemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=
not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))
lemma coeff_eq_zero_of_nat_degree_lt {p : polynomial R} {n : ℕ} (h : p.nat_degree < n) :
p.coeff n = 0 :=
begin
apply coeff_eq_zero_of_degree_lt,
by_cases hp : p = 0,
{ subst hp, exact with_bot.bot_lt_coe n },
{ rwa [degree_eq_nat_degree hp, with_bot.coe_lt_coe] }
end
@[simp] lemma coeff_nat_degree_succ_eq_zero {p : polynomial R} : p.coeff (p.nat_degree + 1) = 0 :=
coeff_eq_zero_of_nat_degree_lt (lt_add_one _)
-- We need the explicit `decidable` argument here because an exotic one shows up in a moment!
lemma ite_le_nat_degree_coeff (p : polynomial R) (n : ℕ) (I : decidable (n < 1 + nat_degree p)) :
@ite _ (n < 1 + nat_degree p) I (coeff p n) 0 = coeff p n :=
begin
split_ifs,
{ refl },
{ exact (coeff_eq_zero_of_nat_degree_lt (not_le.1 (λ w, h (nat.lt_one_add_iff.2 w)))).symm, }
end
lemma as_sum_support (p : polynomial R) :
p = ∑ i in p.support, monomial i (p.coeff i) :=
p.sum_single.symm
lemma as_sum_support_C_mul_X_pow (p : polynomial R) :
p = ∑ i in p.support, C (p.coeff i) * X^i :=
trans p.as_sum_support $ by simp only [C_mul_X_pow_eq_monomial]
/--
We can reexpress a sum over `p.support` as a sum over `range n`,
for any `n` satisfying `p.nat_degree < n`.
-/
lemma sum_over_range' [add_comm_monoid S] (p : polynomial R) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0)
(n : ℕ) (w : p.nat_degree < n) :
p.sum f = ∑ (a : ℕ) in range n, f a (coeff p a) :=
finsupp.sum_of_support_subset _ (supp_subset_range w) _ $ λ n hn, h n
/--
We can reexpress a sum over `p.support` as a sum over `range (p.nat_degree + 1)`.
-/
lemma sum_over_range [add_comm_monoid S] (p : polynomial R) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) :
p.sum f = ∑ (a : ℕ) in range (p.nat_degree + 1), f a (coeff p a) :=
sum_over_range' p h (p.nat_degree + 1) (lt_add_one _)
lemma as_sum_range' (p : polynomial R) (n : ℕ) (w : p.nat_degree < n) :
p = ∑ i in range n, monomial i (coeff p i) :=
p.sum_single.symm.trans $ p.sum_over_range' (λ n, single_zero) _ w
lemma as_sum_range (p : polynomial R) :
p = ∑ i in range (p.nat_degree + 1), monomial i (coeff p i) :=
p.sum_single.symm.trans $ p.sum_over_range $ λ n, single_zero
lemma as_sum_range_C_mul_X_pow (p : polynomial R) :
p = ∑ i in range (p.nat_degree + 1), C (coeff p i) * X ^ i :=
p.as_sum_range.trans $ by simp only [C_mul_X_pow_eq_monomial]
lemma coeff_ne_zero_of_eq_degree (hn : degree p = n) :
coeff p n ≠ 0 :=
λ h, mem_support_iff.mp (mem_of_max hn) h
lemma eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) :
p = C (p.coeff 1) * X + C (p.coeff 0) :=
ext (λ n, nat.cases_on n (by simp)
(λ n, nat.cases_on n (by simp [coeff_C])
(λ m, have degree p < m.succ.succ, from lt_of_le_of_lt h dec_trivial,
by simp [coeff_eq_zero_of_degree_lt this, coeff_C, nat.succ_ne_zero, coeff_X,
nat.succ_inj', @eq_comm ℕ 0])))
lemma eq_X_add_C_of_degree_eq_one (h : degree p = 1) :
p = C (p.leading_coeff) * X + C (p.coeff 0) :=
(eq_X_add_C_of_degree_le_one (show degree p ≤ 1, from h ▸ le_refl _)).trans
(by simp [leading_coeff, nat_degree_eq_of_degree_eq_some h])
lemma eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :
p = C (p.coeff 1) * X + C (p.coeff 0) :=
eq_X_add_C_of_degree_le_one $ degree_le_of_nat_degree_le h
lemma exists_eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :
∃ a b, p = C a * X + C b :=
⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_nat_degree_le_one h⟩
theorem degree_X_pow_le (n : ℕ) : degree (X^n : polynomial R) ≤ n :=
by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1:R)
theorem degree_X_le : degree (X : polynomial R) ≤ 1 :=
degree_monomial_le _ _
lemma nat_degree_X_le : (X : polynomial R).nat_degree ≤ 1 :=
nat_degree_le_of_degree_le degree_X_le
lemma support_C_mul_X_pow (c : R) (n : ℕ) : (C c * X ^ n).support ⊆ singleton n :=
begin
rw [C_mul_X_pow_eq_monomial],
exact support_single_subset
end
lemma mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ (C c * X ^ n).support) : a = n :=
mem_singleton.1 $ support_C_mul_X_pow _ _ h
lemma card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : (C c * X ^ n).support.card ≤ 1 :=
begin
rw ← card_singleton n,
apply card_le_of_subset (support_C_mul_X_pow c n),
end
lemma card_supp_le_succ_nat_degree (p : polynomial R) : p.support.card ≤ p.nat_degree + 1 :=
begin
rw ← finset.card_range (p.nat_degree + 1),
exact finset.card_le_of_subset supp_subset_range_nat_degree_succ,
end
lemma le_degree_of_mem_supp (a : ℕ) :
a ∈ p.support → ↑a ≤ degree p :=
le_degree_of_ne_zero ∘ mem_support_iff.mp
lemma nonempty_support_iff : p.support.nonempty ↔ p ≠ 0 :=
by rw [ne.def, nonempty_iff_ne_empty, ne.def, ← support_eq_empty]
lemma support_C_mul_X_pow_nonzero {c : R} {n : ℕ} (h : c ≠ 0) :
(C c * X ^ n).support = singleton n :=
begin
rw [C_mul_X_pow_eq_monomial],
exact support_single_ne_zero h
end
end semiring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : polynomial R}
@[simp] lemma degree_one : degree (1 : polynomial R) = (0 : with_bot ℕ) :=
degree_C (show (1 : R) ≠ 0, from zero_ne_one.symm)
@[simp] lemma degree_X : degree (X : polynomial R) = 1 :=
degree_monomial _ one_ne_zero
@[simp] lemma nat_degree_X : (X : polynomial R).nat_degree = 1 :=
nat_degree_eq_of_degree_eq_some degree_X
end nonzero_semiring
section ring
variables [ring R]
lemma coeff_mul_X_sub_C {p : polynomial R} {r : R} {a : ℕ} :
coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r :=
by simp [mul_sub]
lemma C_eq_int_cast (n : ℤ) : C (n : R) = n :=
(C : R →+* _).map_int_cast n
@[simp] lemma degree_neg (p : polynomial R) : degree (-p) = degree p :=
by unfold degree; rw support_neg
@[simp] lemma nat_degree_neg (p : polynomial R) : nat_degree (-p) = nat_degree p :=
by simp [nat_degree]
@[simp] lemma nat_degree_int_cast (n : ℤ) : nat_degree (n : polynomial R) = 0 :=
by simp only [←C_eq_int_cast, nat_degree_C]
end ring
section semiring
variables [semiring R]
/-- The second-highest coefficient, or 0 for constants -/
def next_coeff (p : polynomial R) : R :=
if p.nat_degree = 0 then 0 else p.coeff (p.nat_degree - 1)
@[simp]
lemma next_coeff_C_eq_zero (c : R) :
next_coeff (C c) = 0 := by { rw next_coeff, simp }
lemma next_coeff_of_pos_nat_degree (p : polynomial R) (hp : 0 < p.nat_degree) :
next_coeff p = p.coeff (p.nat_degree - 1) :=
by { rw [next_coeff, if_neg], contrapose! hp, simpa }
end semiring
section semiring
variables [semiring R] {p q : polynomial R} {ι : Type*}
lemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) :
coeff p (nat_degree q) = 0 :=
coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)
lemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 :=
mt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))
lemma ne_zero_of_degree_ge_degree (hpq : p.degree ≤ q.degree) (hp : p ≠ 0) : q ≠ 0 :=
polynomial.ne_zero_of_degree_gt (lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr
(by rwa [ne.def, polynomial.degree_eq_bot])) hpq : q.degree > ⊥)
lemma ne_zero_of_nat_degree_gt {n : ℕ} (h : n < nat_degree p) : p ≠ 0 :=
λ H, by simpa [H, nat.not_lt_zero] using h
lemma degree_lt_degree (h : nat_degree p < nat_degree q) : degree p < degree q :=
begin
by_cases hp : p = 0,
{ simp [hp],
rw bot_lt_iff_ne_bot,
intro hq,
simpa [hp, degree_eq_bot.mp hq, lt_irrefl] using h },
{ rw [degree_eq_nat_degree hp, degree_eq_nat_degree $ ne_zero_of_nat_degree_gt h],
exact_mod_cast h }
end
lemma nat_degree_lt_nat_degree_iff (hp : p ≠ 0) :
nat_degree p < nat_degree q ↔ degree p < degree q :=
⟨degree_lt_degree, begin
intro h,
have hq : q ≠ 0 := ne_zero_of_degree_gt h,
rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq] at h,
exact_mod_cast h
end⟩
lemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) :=
begin
ext (_|n), { simp },
rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt],
exact h.trans_lt (with_bot.some_lt_some.2 n.succ_pos),
end
lemma eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero (h ▸ le_refl _)
lemma degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) :=
⟨eq_C_of_degree_le_zero, λ h, h.symm ▸ degree_C_le⟩
lemma degree_add_le (p q : polynomial R) : degree (p + q) ≤ max (degree p) (degree q) :=
calc degree (p + q) = ((p + q).support).sup some : rfl
... ≤ (p.support ∪ q.support).sup some : by convert sup_mono support_add
... = p.support.sup some ⊔ q.support.sup some : by convert sup_union
... = _ : with_bot.sup_eq_max _ _
@[simp] lemma leading_coeff_zero : leading_coeff (0 : polynomial R) = 0 := rfl
@[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 :=
⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1
(not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)),
λ h, h.symm ▸ leading_coeff_zero⟩
lemma leading_coeff_ne_zero : leading_coeff p ≠ 0 ↔ p ≠ 0 :=
by rw [ne.def, leading_coeff_eq_zero]
lemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = ⊥ :=
by rw [leading_coeff_eq_zero, degree_eq_bot]
lemma nat_degree_mem_support_of_nonzero (H : p ≠ 0) : p.nat_degree ∈ p.support :=
(p.mem_support_to_fun p.nat_degree).mpr ((not_congr leading_coeff_eq_zero).mpr H)
lemma nat_degree_eq_support_max' (h : p ≠ 0) :
p.nat_degree = p.support.max' (nonempty_support_iff.mpr h) :=
(le_max' _ _ $ nat_degree_mem_support_of_nonzero h).antisymm $
max'_le _ _ _ le_nat_degree_of_mem_supp
lemma nat_degree_C_mul_X_pow_le (a : R) (n : ℕ) : nat_degree (C a * X ^ n) ≤ n :=
nat_degree_le_iff_degree_le.2 $ degree_C_mul_X_pow_le _ _
lemma degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p :=
le_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $
begin
rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, add_zero],
exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h)
end
lemma degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q :=
by rw [add_comm, degree_add_eq_left_of_degree_lt h]
lemma degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p :=
add_comm (C a) p ▸ degree_add_eq_right_of_degree_lt $ lt_of_le_of_lt degree_C_le hp
lemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) :
degree (p + q) = max p.degree q.degree :=
le_antisymm (degree_add_le _ _) $
match lt_trichotomy (degree p) (degree q) with
| or.inl hlt :=
by rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_refl _
| or.inr (or.inl heq) :=
le_of_not_gt $
assume hlt : max (degree p) (degree q) > degree (p + q),
h $ show leading_coeff p + leading_coeff q = 0,
begin
rw [heq, max_self] at hlt,
rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add],
exact coeff_nat_degree_eq_zero_of_degree_lt hlt
end
| or.inr (or.inr hlt) :=
by rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_refl _
end
lemma degree_erase_le (p : polynomial R) (n : ℕ) : degree (p.erase n) ≤ degree p :=
by convert sup_mono (erase_subset _ _)
lemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p :=
lt_of_le_of_ne (degree_erase_le _ _) $
(degree_eq_nat_degree hp).symm ▸ (by convert λ h, not_mem_erase _ _ (mem_of_max h))
lemma degree_sum_le (s : finset ι) (f : ι → polynomial R) :
degree (∑ i in s, f i) ≤ s.sup (λ b, degree (f b)) :=
finset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $
assume a s has ih,
calc degree (∑ i in insert a s, f i) ≤ max (degree (f a)) (degree (∑ i in s, f i)) :
by rw sum_insert has; exact degree_add_le _ _
... ≤ _ : by rw [sup_insert, with_bot.sup_eq_max]; exact max_le_max (le_refl _) ih
lemma degree_mul_le (p q : polynomial R) : degree (p * q) ≤ degree p + degree q :=
calc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (coeff p i * a) * X ^ (i + j)))) :
by simp only [single_eq_C_mul_X.symm]; exact degree_sum_le _ _
... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) :
finset.sup_mono_fun (assume i hi, degree_sum_le _ _)
... ≤ degree p + degree q :
begin
refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_C_mul_X_pow_le _ _) _)),
rw [with_bot.coe_add],
rw mem_support_iff at ha hb,
exact add_le_add (le_degree_of_ne_zero ha) (le_degree_of_ne_zero hb)
end
lemma degree_pow_le (p : polynomial R) : ∀ (n : ℕ), degree (p ^ n) ≤ n • (degree p)
| 0 := by rw [pow_zero, zero_nsmul]; exact degree_one_le
| (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) :
by rw pow_succ; exact degree_mul_le _ _
... ≤ _ : by rw succ_nsmul; exact add_le_add (le_refl _) (degree_pow_le _)
@[simp] lemma leading_coeff_monomial (a : R) (n : ℕ) : leading_coeff (monomial n a) = a :=
begin
by_cases ha : a = 0,
{ simp only [ha, (monomial n).map_zero, leading_coeff_zero] },
{ rw [leading_coeff, nat_degree_monomial _ _ ha],
exact @finsupp.single_eq_same _ _ _ n a }
end
lemma leading_coeff_C_mul_X_pow (a : R) (n : ℕ) : leading_coeff (C a * X ^ n) = a :=
by rw [C_mul_X_pow_eq_monomial, leading_coeff_monomial]
@[simp] lemma leading_coeff_C (a : R) : leading_coeff (C a) = a :=
leading_coeff_monomial a 0
@[simp] lemma leading_coeff_X_pow (n : ℕ) : leading_coeff ((X : polynomial R) ^ n) = 1 :=
by simpa only [C_1, one_mul] using leading_coeff_C_mul_X_pow (1 : R) n
@[simp] lemma leading_coeff_X : leading_coeff (X : polynomial R) = 1 :=
by simpa only [pow_one] using @leading_coeff_X_pow R _ 1
@[simp] lemma monic_X_pow (n : ℕ) : monic (X ^ n : polynomial R) := leading_coeff_X_pow n
@[simp] lemma monic_X : monic (X : polynomial R) := leading_coeff_X
@[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial R) = 1 :=
leading_coeff_C 1
@[simp] lemma monic_one : monic (1 : polynomial R) := leading_coeff_C _
lemma monic.ne_zero {R : Type*} [semiring R] [nontrivial R] {p : polynomial R} (hp : p.monic) :
p ≠ 0 :=
by { rintro rfl, simpa [monic] using hp }
lemma monic.ne_zero_of_ne (h : (0:R) ≠ 1) {p : polynomial R} (hp : p.monic) :
p ≠ 0 :=
by { nontriviality R, exact hp.ne_zero }
lemma monic.ne_zero_of_polynomial_ne {r} (hp : monic p) (hne : q ≠ r) : p ≠ 0 :=
by { haveI := nontrivial.of_polynomial_ne hne, exact hp.ne_zero }
lemma leading_coeff_add_of_degree_lt (h : degree p < degree q) :
leading_coeff (p + q) = leading_coeff q :=
have coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h,
by simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h),
this, coeff_add, zero_add]
lemma leading_coeff_add_of_degree_eq (h : degree p = degree q)
(hlc : leading_coeff p + leading_coeff q ≠ 0) :
leading_coeff (p + q) = leading_coeff p + leading_coeff q :=
have nat_degree (p + q) = nat_degree p,
by apply nat_degree_eq_of_degree_eq;
rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self],
by simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add]
@[simp] lemma coeff_mul_degree_add_degree (p q : polynomial R) :
coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q :=
calc coeff (p * q) (nat_degree p + nat_degree q) =
∑ x in nat.antidiagonal (nat_degree p + nat_degree q),
coeff p x.1 * coeff q x.2 : coeff_mul _ _ _
... = coeff p (nat_degree p) * coeff q (nat_degree q) :
begin
refine finset.sum_eq_single (nat_degree p, nat_degree q) _ _,
{ rintro ⟨i,j⟩ h₁ h₂, rw nat.mem_antidiagonal at h₁,
by_cases H : nat_degree p < i,
{ rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 H)), zero_mul] },
{ rw not_lt_iff_eq_or_lt at H, cases H,
{ subst H, rw add_left_cancel_iff at h₁, dsimp at h₁, subst h₁, exfalso, exact h₂ rfl },
{ suffices : nat_degree q < j,
{ rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 this)), mul_zero] },
{ by_contra H', rw not_lt at H',
exact ne_of_lt (nat.lt_of_lt_of_le
(nat.add_lt_add_right H j) (nat.add_le_add_left H' _)) h₁ } } } },
{ intro H, exfalso, apply H, rw nat.mem_antidiagonal }
end
lemma degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
degree (p * q) = degree p + degree q :=
have hp : p ≠ 0 := by refine mt _ h; exact λ hp, by rw [hp, leading_coeff_zero, zero_mul],
have hq : q ≠ 0 := by refine mt _ h; exact λ hq, by rw [hq, leading_coeff_zero, mul_zero],
le_antisymm (degree_mul_le _ _)
begin
rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq],
refine le_degree_of_ne_zero _,
rwa coeff_mul_degree_add_degree
end
lemma degree_mul_monic (hq : monic q) : degree (p * q) = degree p + degree q :=
if hp : p = 0 then by simp [hp]
else degree_mul' $ by rwa [hq.leading_coeff, mul_one, ne.def, leading_coeff_eq_zero]
lemma nat_degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
nat_degree (p * q) = nat_degree p + nat_degree q :=
have hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, zero_mul]),
have hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, mul_zero]),
nat_degree_eq_of_degree_eq_some $
by rw [degree_mul' h, with_bot.coe_add, degree_eq_nat_degree hp, degree_eq_nat_degree hq]
lemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
leading_coeff (p * q) = leading_coeff p * leading_coeff q :=
begin
unfold leading_coeff,
rw [nat_degree_mul' h, coeff_mul_degree_add_degree],
refl
end
lemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 →
leading_coeff (p ^ n) = leading_coeff p ^ n :=
nat.rec_on n (by simp) $
λ n ih h,
have h₁ : leading_coeff p ^ n ≠ 0 :=
λ h₁, h $ by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← ih h₁] at h,
by rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁]
lemma degree_pow' : ∀ {n : ℕ}, leading_coeff p ^ n ≠ 0 →
degree (p ^ n) = n • (degree p)
| 0 := λ h, by rw [pow_zero, ← C_1] at *;
rw [degree_C h, zero_nsmul]
| (n+1) := λ h,
have h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $
by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← leading_coeff_pow' h₁] at h,
by rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁]
lemma nat_degree_pow' {n : ℕ} (h : leading_coeff p ^ n ≠ 0) :
nat_degree (p ^ n) = n * nat_degree p :=
if hp0 : p = 0 then
if hn0 : n = 0 then by simp *
else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp
else
have hpn : p ^ n ≠ 0, from λ hpn0, have h1 : _ := h,
by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h;
exact h rfl,
option.some_inj.1 $ show (nat_degree (p ^ n) : with_bot ℕ) = (n * nat_degree p : ℕ),
by rw [← degree_eq_nat_degree hpn, degree_pow' h, degree_eq_nat_degree hp0,
← with_bot.coe_nsmul]; simp
theorem leading_coeff_mul_monic {p q : polynomial R} (hq : monic q) :
leading_coeff (p * q) = leading_coeff p :=
decidable.by_cases
(λ H : leading_coeff p = 0, by rw [H, leading_coeff_eq_zero.1 H, zero_mul, leading_coeff_zero])
(λ H : leading_coeff p ≠ 0,
by rw [leading_coeff_mul', hq.leading_coeff, mul_one];
rwa [hq.leading_coeff, mul_one])
@[simp] theorem leading_coeff_mul_X_pow {p : polynomial R} {n : ℕ} :
leading_coeff (p * X ^ n) = leading_coeff p :=
leading_coeff_mul_monic (monic_X_pow n)
@[simp] theorem leading_coeff_mul_X {p : polynomial R} :
leading_coeff (p * X) = leading_coeff p :=
leading_coeff_mul_monic monic_X
lemma nat_degree_mul_le {p q : polynomial R} : nat_degree (p * q) ≤ nat_degree p + nat_degree q :=
begin
apply nat_degree_le_of_degree_le,
apply le_trans (degree_mul_le p q),
rw with_bot.coe_add,
refine add_le_add _ _; apply degree_le_nat_degree,
end
lemma subsingleton_of_monic_zero (h : monic (0 : polynomial R)) :
(∀ p q : polynomial R, p = q) ∧ (∀ a b : R, a = b) :=
by rw [monic.def, leading_coeff_zero] at h;
exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero],
λ a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩
lemma zero_le_degree_iff {p : polynomial R} : 0 ≤ degree p ↔ p ≠ 0 :=
by rw [ne.def, ← degree_eq_bot];
cases degree p; exact dec_trivial
lemma degree_nonneg_iff_ne_zero : 0 ≤ degree p ↔ p ≠ 0 :=
⟨λ h0p hp0, absurd h0p (by rw [hp0, degree_zero]; exact dec_trivial),
λ hp0, le_of_not_gt (λ h, by simp [gt, degree_eq_bot, *] at *)⟩
lemma nat_degree_eq_zero_iff_degree_le_zero : p.nat_degree = 0 ↔ p.degree ≤ 0 :=
by rw [← nonpos_iff_eq_zero, nat_degree_le_iff_degree_le, with_bot.coe_zero]
theorem degree_le_iff_coeff_zero (f : polynomial R) (n : with_bot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 :=
⟨λ (H : finset.sup (f.support) some ≤ n) m (Hm : n < (m : with_bot ℕ)), decidable.of_not_not $ λ H4,
have H1 : m ∉ f.support,
from λ H2, not_lt_of_ge ((finset.sup_le_iff.1 H) m H2 : ((m : with_bot ℕ) ≤ n)) Hm,
H1 $ (finsupp.mem_support_to_fun f m).2 H4,
λ H, finset.sup_le $ λ b Hb, decidable.of_not_not $ λ Hn,
(finsupp.mem_support_to_fun f b).1 Hb $ H b $ lt_of_not_ge Hn⟩
theorem degree_lt_iff_coeff_zero (f : polynomial R) (n : ℕ) :
degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 :=
begin
refine ⟨λ hf m hm, coeff_eq_zero_of_degree_lt (lt_of_lt_of_le hf (with_bot.coe_le_coe.2 hm)), _⟩,
simp only [degree, finset.sup_lt_iff (with_bot.bot_lt_coe n), mem_support_iff,
with_bot.some_eq_coe, with_bot.coe_lt_coe, ← @not_le ℕ],
exact λ h m, mt (h m),
end
lemma degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree :=
by haveI := nontrivial.of_polynomial_ne hp; exact
have leading_coeff p * leading_coeff X ≠ 0, by simpa,
by erw [degree_mul' this, degree_eq_nat_degree hp,
degree_X, ← with_bot.coe_one, ← with_bot.coe_add, with_bot.coe_lt_coe];
exact nat.lt_succ_self _
lemma nat_degree_pos_iff_degree_pos :
0 < nat_degree p ↔ 0 < degree p :=
lt_iff_lt_of_le_iff_le nat_degree_le_iff_degree_le
lemma eq_C_of_nat_degree_le_zero (h : nat_degree p ≤ 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero $ degree_le_of_nat_degree_le h
lemma eq_C_of_nat_degree_eq_zero (h : nat_degree p = 0) : p = C (coeff p 0) :=
eq_C_of_nat_degree_le_zero h.le
lemma ne_zero_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : p ≠ 0 :=
by rw ← degree_nonneg_iff_ne_zero; exact trans (by exact_mod_cast n.zero_le) hdeg
lemma le_nat_degree_of_coe_le_degree (hdeg : ↑n ≤ p.degree) :
n ≤ p.nat_degree :=
with_bot.coe_le_coe.mp ((degree_eq_nat_degree $ ne_zero_of_coe_le_degree hdeg) ▸ hdeg)
end semiring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : polynomial R}
@[simp] lemma degree_X_pow (n : ℕ) : degree ((X : polynomial R) ^ n) = n :=
by rw [X_pow_eq_monomial, degree_monomial _ (@one_ne_zero R _ _)]
@[simp] lemma nat_degree_X_pow (n : ℕ) : nat_degree ((X : polynomial R) ^ n) = n :=
nat_degree_eq_of_degree_eq_some (degree_X_pow n)
theorem not_is_unit_X : ¬ is_unit (X : polynomial R) :=
λ ⟨⟨_, g, hfg, hgf⟩, rfl⟩, @zero_ne_one R _ _ $ by { rw [← coeff_one_zero, ← hgf], simp }
@[simp] lemma degree_mul_X : degree (p * X) = degree p + 1 := by simp [degree_mul_monic monic_X]
@[simp] lemma degree_mul_X_pow : degree (p * X ^ n) = degree p + n :=
by simp [degree_mul_monic (monic_X_pow n)]
end nonzero_semiring
section ring
variables [ring R] {p q : polynomial R}
lemma degree_sub_le (p q : polynomial R) : degree (p - q) ≤ max (degree p) (degree q) :=
by simpa only [sub_eq_add_neg, degree_neg q] using degree_add_le p (-q)
lemma degree_sub_lt (hd : degree p = degree q)
(hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) :
degree (p - q) < degree p :=
have hp : single (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p :=
finsupp.single_add_erase _ _,
have hq : single (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q :=
finsupp.single_add_erase _ _,
have hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd,
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0),
calc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) :
by conv {to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]}
... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q))
: degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _
... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
lemma nat_degree_X_sub_C_le {r : R} : (X - C r).nat_degree ≤ 1 :=
nat_degree_le_iff_degree_le.2 $ le_trans (degree_sub_le _ _) $ max_le degree_X_le $
le_trans degree_C_le $ with_bot.coe_le_coe.2 zero_le_one
lemma degree_sum_fin_lt {n : ℕ} (f : fin n → R) :
degree (∑ i : fin n, C (f i) * X ^ (i : ℕ)) < n :=
begin
haveI : is_commutative (with_bot ℕ) max := ⟨max_comm⟩,
haveI : is_associative (with_bot ℕ) max := ⟨max_assoc⟩,
calc (∑ i, C (f i) * X ^ (i : ℕ)).degree
≤ finset.univ.fold (⊔) ⊥ (λ i, (C (f i) * X ^ (i : ℕ)).degree) : degree_sum_le _ _
... = finset.univ.fold max ⊥ (λ i, (C (f i) * X ^ (i : ℕ)).degree) :
(@finset.fold_hom _ _ _ (⊔) _ _ _ ⊥ finset.univ _ _ _ id (with_bot.sup_eq_max)).symm
... < n : (finset.fold_max_lt (n : with_bot ℕ)).mpr ⟨with_bot.bot_lt_some _, _⟩,
rintros ⟨i, hi⟩ -,
calc (C (f ⟨i, hi⟩) * X ^ i).degree
≤ (C _).degree + (X ^ i).degree : degree_mul_le _ _
... ≤ 0 + i : add_le_add degree_C_le (degree_X_pow_le i)
... = i : zero_add _
... < n : with_bot.some_lt_some.mpr hi,
end
lemma degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p :=
by { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h] }
lemma degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q :=
by { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg] }
end ring
section nonzero_ring
variables [nontrivial R] [ring R]
@[simp] lemma degree_X_sub_C (a : R) : degree (X - C a) = 1 :=
have degree (C a) < degree (X : polynomial R),
from calc degree (C a) ≤ 0 : degree_C_le
... < 1 : with_bot.some_lt_some.mpr zero_lt_one
... = degree X : degree_X.symm,
by rw [degree_sub_eq_left_of_degree_lt this, degree_X]
@[simp] lemma degree_X_add_C (a : R) : degree (X + C a) = 1 :=
have degree (C a) < degree (X : polynomial R),
from calc degree (C a) ≤ 0 : degree_C_le
... < 1 : with_bot.some_lt_some.mpr zero_lt_one
... = degree X : degree_X.symm,
by rw [degree_add_eq_left_of_degree_lt this, degree_X]
@[simp] lemma nat_degree_X_sub_C (x : R) : (X - C x).nat_degree = 1 :=
nat_degree_eq_of_degree_eq_some $ degree_X_sub_C x
@[simp]
lemma next_coeff_X_sub_C (c : R) : next_coeff (X - C c) = - c :=
by simp [next_coeff_of_pos_nat_degree]
lemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
degree ((X : polynomial R) ^ n - C a) = n :=
have degree (C a) < degree ((X : polynomial R) ^ n),
from calc degree (C a) ≤ 0 : degree_C_le
... < degree ((X : polynomial R) ^ n) : by rwa [degree_X_pow];
exact with_bot.coe_lt_coe.2 hn,
by rw [degree_sub_eq_left_of_degree_lt this, degree_X_pow]
lemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) :
(X : polynomial R) ^ n - C a ≠ 0 :=
mt degree_eq_bot.2 (show degree ((X : polynomial R) ^ n - C a) ≠ ⊥,
by rw degree_X_pow_sub_C hn a; exact dec_trivial)
theorem X_sub_C_ne_zero (r : R) : X - C r ≠ 0 :=
pow_one (X : polynomial R) ▸ X_pow_sub_C_ne_zero zero_lt_one r
theorem zero_nmem_multiset_map_X_sub_C {α : Type*} (m : multiset α) (f : α → R) :
(0 : polynomial R) ∉ m.map (λ a, X - C (f a)) :=
λ mem, let ⟨a, _, ha⟩ := multiset.mem_map.mp mem in X_sub_C_ne_zero _ ha
lemma nat_degree_X_pow_sub_C {n : ℕ} {r : R} :
(X ^ n - C r).nat_degree = n :=
begin
by_cases hn : n = 0,
{ rw [hn, pow_zero, ←C_1, ←ring_hom.map_sub, nat_degree_C] },
{ exact nat_degree_eq_of_degree_eq_some (degree_X_pow_sub_C (pos_iff_ne_zero.mpr hn) r) },
end
@[simp] lemma leading_coeff_X_pow_sub_C {n : ℕ} (hn : 0 < n) {r : R} :
(X ^ n - C r).leading_coeff = 1 :=
by rw [leading_coeff, nat_degree_X_pow_sub_C, coeff_sub, coeff_X_pow_self,
coeff_C, if_neg (pos_iff_ne_zero.mp hn), sub_zero]
@[simp] lemma leading_coeff_X_pow_sub_one {n : ℕ} (hn : 0 < n) :
(X ^ n - 1 : polynomial R).leading_coeff = 1 :=
leading_coeff_X_pow_sub_C hn
end nonzero_ring
section no_zero_divisors
variables [semiring R] [no_zero_divisors R] {p q : polynomial R}
@[simp] lemma degree_mul : degree (p * q) = degree p + degree q :=
if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add]
else if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot]
else degree_mul' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)
(mt leading_coeff_eq_zero.1 hq0)
@[simp] lemma degree_pow [nontrivial R] (p : polynomial R) (n : ℕ) :
degree (p ^ n) = n • (degree p) :=
by induction n; [simp only [pow_zero, degree_one, zero_nsmul],
simp only [*, pow_succ, succ_nsmul, degree_mul]]
@[simp] lemma leading_coeff_mul (p q : polynomial R) : leading_coeff (p * q) =
leading_coeff p * leading_coeff q :=
begin
by_cases hp : p = 0,
{ simp only [hp, zero_mul, leading_coeff_zero] },
{ by_cases hq : q = 0,
{ simp only [hq, mul_zero, leading_coeff_zero] },
{ rw [leading_coeff_mul'],
exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } }
end
@[simp] lemma leading_coeff_X_add_C [nontrivial R] (a b : R) (ha : a ≠ 0):
leading_coeff (C a * X + C b) = a :=
begin
rw [add_comm, leading_coeff_add_of_degree_lt],
{ simp },
{ simpa [degree_C ha] using lt_of_le_of_lt degree_C_le (with_bot.coe_lt_coe.2 zero_lt_one)}
end
/-- `polynomial.leading_coeff` bundled as a `monoid_hom` when `R` has `no_zero_divisors`, and thus
`leading_coeff` is multiplicative -/
def leading_coeff_hom : polynomial R →* R :=
{ to_fun := leading_coeff,
map_one' := by simp,
map_mul' := leading_coeff_mul }
@[simp] lemma leading_coeff_hom_apply (p : polynomial R) :
leading_coeff_hom p = leading_coeff p := rfl
@[simp] lemma leading_coeff_pow (p : polynomial R) (n : ℕ) :
leading_coeff (p ^ n) = leading_coeff p ^ n :=
(leading_coeff_hom : polynomial R →* R).map_pow p n
end no_zero_divisors
end polynomial
|
cdd876984f06ce29aac94079e4b8c8ca4df66a66 | 32da3d0f92cab08875472ef6cacc1931c2b3eafa | /src/algebra/module/basic.lean | 29afb41e8975adf84cccabd13161a1915da4b761 | [
"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 | 20,109 | lean | /-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
-/
import algebra.big_operators.basic
import algebra.group.hom
import algebra.ring.basic
import data.rat.cast
import group_theory.group_action.group
import tactic.nth_rewrite
/-!
# Modules over a ring
In this file we define
* `semimodule R M` : an additive commutative monoid `M` is a `semimodule` over a
`semiring` `R` if for `r : R` and `x : M` their "scalar multiplication `r • x : M` is defined, and
the operation `•` satisfies some natural associativity and distributivity axioms similar to those
on a ring.
* `module R M` : same as `semimodule R M` but assumes that `R` is a `ring` and `M` is an
additive commutative group.
* `vector_space k M` : same as `semimodule k M` and `module k M` but assumes that `k` is a `field`
and `M` is an additive commutative group.
* `linear_map R M M₂`, `M →ₗ[R] M₂` : a linear map between two R-`semimodule`s.
## Implementation notes
* `vector_space` and `module` are abbreviations for `semimodule R M`.
## Tags
semimodule, module, vector space
-/
open function
open_locale big_operators
universes u u' v w x y z
variables {R : Type u} {k : Type u'} {S : Type v} {M : Type w} {M₂ : Type x} {M₃ : Type y}
{ι : Type z}
/-- A semimodule is a generalization of vector spaces to a scalar semiring.
It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`,
connected by a "scalar multiplication" operation `r • x : M`
(where `r : R` and `x : M`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
@[protect_proj] class semimodule (R : Type u) (M : Type v) [semiring R]
[add_comm_monoid M] extends distrib_mul_action R M :=
(add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
(zero_smul : ∀x : M, (0 : R) • x = 0)
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [semimodule R M] (r s : R) (x y : M)
theorem add_smul : (r + s) • x = r • x + s • x := semimodule.add_smul r s x
variables (R)
@[simp] theorem zero_smul : (0 : R) • x = 0 := semimodule.zero_smul x
theorem two_smul : (2 : R) • x = x + x := by rw [bit0, add_smul, one_smul]
theorem two_smul' : (2 : R) • x = bit0 x := two_smul R x
/-- Pullback a `semimodule` structure along an injective additive monoid homomorphism. -/
protected def function.injective.semimodule [add_comm_monoid M₂] [has_scalar R M₂] (f : M₂ →+ M)
(hf : injective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) :
semimodule R M₂ :=
{ smul := (•),
add_smul := λ c₁ c₂ x, hf $ by simp only [smul, f.map_add, add_smul],
zero_smul := λ x, hf $ by simp only [smul, zero_smul, f.map_zero],
.. hf.distrib_mul_action f smul }
/-- Pushforward a `semimodule` structure along a surjective additive monoid homomorphism. -/
protected def function.surjective.semimodule [add_comm_monoid M₂] [has_scalar R M₂] (f : M →+ M₂)
(hf : surjective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) :
semimodule R M₂ :=
{ smul := (•),
add_smul := λ c₁ c₂ x, by { rcases hf x with ⟨x, rfl⟩,
simp only [add_smul, ← smul, ← f.map_add] },
zero_smul := λ x, by { rcases hf x with ⟨x, rfl⟩, simp only [← f.map_zero, ← smul, zero_smul] },
.. hf.distrib_mul_action f smul }
variable (M)
/-- `(•)` as an `add_monoid_hom`. -/
def smul_add_hom : R →+ M →+ M :=
{ to_fun := const_smul_hom M,
map_zero' := add_monoid_hom.ext $ λ r, by simp,
map_add' := λ x y, add_monoid_hom.ext $ λ r, by simp [add_smul] }
variables {R M}
@[simp] lemma smul_add_hom_apply (r : R) (x : M) :
smul_add_hom R M r x = r • x := rfl
lemma semimodule.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 :=
by rw [←one_smul R x, ←zero_eq_one, zero_smul]
lemma list.sum_smul {l : list R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum :=
((smul_add_hom R M).flip x).map_list_sum l
lemma multiset.sum_smul {l : multiset R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum :=
((smul_add_hom R M).flip x).map_multiset_sum l
lemma finset.sum_smul {f : ι → R} {s : finset ι} {x : M} :
(∑ i in s, f i) • x = (∑ i in s, (f i) • x) :=
((smul_add_hom R M).flip x).map_sum f s
end add_comm_monoid
variables (R)
/-- An `add_comm_monoid` that is a `semimodule` over a `ring` carries a natural `add_comm_group` structure. -/
def semimodule.add_comm_monoid_to_add_comm_group [ring R] [add_comm_monoid M] [semimodule R M] :
add_comm_group M :=
{ neg := λ a, (-1 : R) • a,
add_left_neg := λ a, show (-1 : R) • a + a = 0, by {
nth_rewrite 1 ← one_smul _ a,
rw [← add_smul, add_left_neg, zero_smul] },
..(infer_instance : add_comm_monoid M), }
variables {R}
section add_comm_group
variables (R M) [semiring R] [add_comm_group M]
/-- A structure containing most informations as in a semimodule, except the fields `zero_smul`
and `smul_zero`. As these fields can be deduced from the other ones when `M` is an `add_comm_group`,
this provides a way to construct a semimodule structure by checking less properties, in
`semimodule.of_core`. -/
@[nolint has_inhabited_instance]
structure semimodule.core extends has_scalar R M :=
(smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y)
(add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
(mul_smul : ∀(r s : R) (x : M), (r * s) • x = r • s • x)
(one_smul : ∀x : M, (1 : R) • x = x)
variables {R M}
/-- Define `semimodule` without proving `zero_smul` and `smul_zero` by using an auxiliary
structure `semimodule.core`, when the underlying space is an `add_comm_group`. -/
def semimodule.of_core (H : semimodule.core R M) : semimodule R M :=
by letI := H.to_has_scalar; exact
{ zero_smul := λ x, (add_monoid_hom.mk' (λ r : R, r • x) (λ r s, H.add_smul r s x)).map_zero,
smul_zero := λ r, (add_monoid_hom.mk' ((•) r) (H.smul_add r)).map_zero,
..H }
end add_comm_group
/--
Modules are defined as an `abbreviation` for semimodules,
if the base semiring is a ring.
(A previous definition made `module` a structure
defined to be `semimodule`.)
This has as advantage that modules are completely transparent
for type class inference, which means that all instances for semimodules
are immediately picked up for modules as well.
A cosmetic disadvantage is that one can not extend modules as such,
in definitions such as `normed_space`.
The solution is to extend `semimodule` instead.
-/
library_note "module definition"
/-- A module is the same as a semimodule, except the scalar semiring is actually
a ring.
This is the traditional generalization of spaces like `ℤ^n`, which have a natural
addition operation and a way to multiply them by elements of a ring, but no multiplication
operation between vectors. -/
abbreviation module (R : Type u) (M : Type v) [ring R] [add_comm_group M] :=
semimodule R M
/--
To prove two semimodule structures on a fixed `add_comm_monoid` agree,
it suffices to check the scalar multiplications agree.
-/
-- We'll later use this to show `semimodule ℕ M` and `module ℤ M` are subsingletons.
@[ext]
lemma semimodule_ext {R : Type*} [semiring R] {M : Type*} [add_comm_monoid M] (P Q : semimodule R M)
(w : ∀ (r : R) (m : M), by { haveI := P, exact r • m } = by { haveI := Q, exact r • m }) :
P = Q :=
begin
unfreezingI { rcases P with ⟨⟨⟨⟨P⟩⟩⟩⟩, rcases Q with ⟨⟨⟨⟨Q⟩⟩⟩⟩ },
congr,
funext r m,
exact w r m,
all_goals { apply proof_irrel_heq },
end
section module
variables [ring R] [add_comm_group M] [module R M] (r s : R) (x y : M)
@[simp] theorem neg_smul : -r • x = - (r • x) :=
eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul])
variables (R)
theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp
variables {R}
theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y :=
by simp [add_smul, sub_eq_add_neg]
theorem smul_eq_zero {R E : Type*} [division_ring R] [add_comm_group E] [module R E]
{c : R} {x : E} :
c • x = 0 ↔ c = 0 ∨ x = 0 :=
⟨λ h, or_iff_not_imp_left.2 $ λ hc, (units.mk0 c hc).smul_eq_zero.1 h,
λ h, h.elim (λ hc, hc.symm ▸ zero_smul R x) (λ hx, hx.symm ▸ smul_zero c)⟩
end module
/-- A semimodule over a `subsingleton` semiring is a `subsingleton`. We cannot register this
as an instance because Lean has no way to guess `R`. -/
theorem semimodule.subsingleton (R M : Type*) [semiring R] [subsingleton R] [add_comm_monoid M]
[semimodule R M] :
subsingleton M :=
⟨λ x y, by rw [← one_smul R x, ← one_smul R y, subsingleton.elim (1:R) 0, zero_smul, zero_smul]⟩
@[priority 910] -- see Note [lower instance priority]
instance semiring.to_semimodule [semiring R] : semimodule R R :=
{ smul := (*),
smul_add := mul_add,
add_smul := add_mul,
mul_smul := mul_assoc,
one_smul := one_mul,
zero_smul := zero_mul,
smul_zero := mul_zero }
@[simp] lemma smul_eq_mul [semiring R] {a a' : R} : a • a' = a * a' := rfl
/-- A ring homomorphism `f : R →+* M` defines a module structure by `r • x = f r * x`. -/
def ring_hom.to_semimodule [semiring R] [semiring S] (f : R →+* S) : semimodule R S :=
{ smul := λ r x, f r * x,
smul_add := λ r x y, by unfold has_scalar.smul; rw [mul_add],
add_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_add, add_mul],
mul_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_mul, mul_assoc],
one_smul := λ x, show f 1 * x = _, by rw [f.map_one, one_mul],
zero_smul := λ x, show f 0 * x = 0, by rw [f.map_zero, zero_mul],
smul_zero := λ r, mul_zero (f r) }
/--
Vector spaces are defined as an `abbreviation` for semimodules,
if the base ring is a field.
(A previous definition made `vector_space` a structure
defined to be `module`.)
This has as advantage that vector spaces are completely transparent
for type class inference, which means that all instances for semimodules
are immediately picked up for vector spaces as well.
A cosmetic disadvantage is that one can not extend vector spaces as such,
in definitions such as `normed_space`.
The solution is to extend `semimodule` instead.
-/
library_note "vector space definition"
/-- A vector space is the same as a module, except the scalar ring is actually
a field. (This adds commutativity of the multiplication and existence of inverses.)
This is the traditional generalization of spaces like `ℝ^n`, which have a natural
addition operation and a way to multiply them by real numbers, but no multiplication
operation between vectors. -/
abbreviation vector_space (R : Type u) (M : Type v) [field R] [add_comm_group M] :=
semimodule R M
namespace add_comm_monoid
open add_monoid
variables [add_comm_monoid M]
/-- The natural ℕ-semimodule structure on any `add_comm_monoid`. -/
-- We don't make this a global instance, as it results in too many instances,
-- and confusing ambiguity in the notation `n • x` when `n : ℕ`.
def nat_semimodule : semimodule ℕ M :=
{ smul := nsmul,
smul_add := λ _ _ _, nsmul_add _ _ _,
add_smul := λ _ _ _, add_nsmul _ _ _,
mul_smul := λ _ _ _, mul_nsmul _ _ _,
one_smul := one_nsmul,
zero_smul := zero_nsmul,
smul_zero := nsmul_zero }
instance : subsingleton (semimodule ℕ M) :=
begin
split,
intros P Q,
ext n,
-- isn't that lovely: `r • m = r • m`
have one_smul : by { haveI := P, exact (1 : ℕ) • m } = by { haveI := Q, exact (1 : ℕ) • m },
begin
rw [@one_smul ℕ _ _ (by { haveI := P, apply_instance, }) m],
rw [@one_smul ℕ _ _ (by { haveI := Q, apply_instance, }) m],
end,
induction n with n ih,
{ erw [zero_smul, zero_smul], },
{ rw [nat.succ_eq_add_one, add_smul, add_smul],
erw ih,
rw [one_smul], }
end
/-- Note this does not depend on the `nat_semimodule` definition above, to avoid issues when
diamonds occur in finding `semimodule ℕ M` instances. -/
instance nat_is_scalar_tower [semiring S] [semimodule S M] [semimodule ℕ S] [semimodule ℕ M] :
is_scalar_tower ℕ S M :=
{ smul_assoc := λ n x y, nat.rec_on n
(by simp only [zero_smul])
(λ n ih, by simp only [nat.succ_eq_add_one, add_smul, one_smul, ih]) }
end add_comm_monoid
namespace add_comm_group
variables [add_comm_group M]
/-- The natural ℤ-module structure on any `add_comm_group`. -/
-- We don't immediately make this a global instance, as it results in too many instances,
-- and confusing ambiguity in the notation `n • x` when `n : ℤ`.
-- We do turn it into a global instance, but only at the end of this file,
-- and I remain dubious whether this is a good idea.
def int_module : module ℤ M :=
{ smul := gsmul,
smul_add := λ _ _ _, gsmul_add _ _ _,
add_smul := λ _ _ _, add_gsmul _ _ _,
mul_smul := λ _ _ _, gsmul_mul _ _ _,
one_smul := one_gsmul,
zero_smul := zero_gsmul,
smul_zero := gsmul_zero }
instance : subsingleton (module ℤ M) :=
begin
split,
intros P Q,
ext,
-- isn't that lovely: `r • m = r • m`
have one_smul : by { haveI := P, exact (1 : ℤ) • m } = by { haveI := Q, exact (1 : ℤ) • m },
begin
rw [@one_smul ℤ _ _ (by { haveI := P, apply_instance, }) m],
rw [@one_smul ℤ _ _ (by { haveI := Q, apply_instance, }) m],
end,
have nat_smul : ∀ n : ℕ, by { haveI := P, exact (n : ℤ) • m } = by { haveI := Q, exact (n : ℤ) • m },
begin
intro n,
induction n with n ih,
{ erw [zero_smul, zero_smul], },
{ rw [int.coe_nat_succ, add_smul, add_smul],
erw ih,
rw [one_smul], }
end,
cases r,
{ rw [int.of_nat_eq_coe, nat_smul], },
{ rw [int.neg_succ_of_nat_coe, neg_smul, neg_smul, nat_smul], }
end
instance int_is_scalar_tower [ring S] [module S M] [semimodule ℤ S] [semimodule ℤ M] :
is_scalar_tower ℤ S M :=
{ smul_assoc := λ n x y, int.induction_on n
(by simp only [zero_smul])
(λ n ih, by simp only [one_smul, add_smul, ih])
(λ n ih, by simp only [one_smul, sub_smul, ih]) }
end add_comm_group
section
local attribute [instance] add_comm_monoid.nat_semimodule
lemma semimodule.smul_eq_smul (R : Type*) [semiring R]
{M : Type*} [add_comm_monoid M] [semimodule R M]
(n : ℕ) (b : M) : n • b = (n : R) • b :=
begin
induction n with n ih,
{ rw [nat.cast_zero, zero_smul, zero_smul] },
{ change (n + 1) • b = (n + 1 : R) • b,
rw [add_smul, add_smul, one_smul, ih, one_smul] }
end
lemma semimodule.nsmul_eq_smul (R : Type*) [semiring R]
{M : Type*} [add_comm_monoid M] [semimodule R M] (n : ℕ) (b : M) :
n •ℕ b = (n : R) • b :=
semimodule.smul_eq_smul R n b
lemma nat.smul_def {M : Type*} [add_comm_monoid M] (n : ℕ) (x : M) :
n • x = n •ℕ x :=
rfl
end
namespace nat
variables [semiring R] [add_comm_monoid M] [semimodule R M] [semimodule ℕ M]
instance smul_comm_class : smul_comm_class ℕ R M :=
{ smul_comm := λ n r m, nat.rec_on n
(by simp only [zero_smul, smul_zero])
(λ n ih, by simp only [succ_eq_add_one, add_smul, one_smul, ←ih, smul_add]) }
-- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
instance smul_comm_class' : smul_comm_class R ℕ M := smul_comm_class.symm _ _ _
end nat
section
local attribute [instance] add_comm_group.int_module
lemma gsmul_eq_smul {M : Type*} [add_comm_group M] (n : ℤ) (x : M) : gsmul n x = n • x := rfl
lemma module.gsmul_eq_smul_cast (R : Type*) [ring R] {M : Type*} [add_comm_group M] [module R M]
(n : ℤ) (b : M) : gsmul n b = (n : R) • b :=
begin
cases n,
{ apply semimodule.nsmul_eq_smul, },
{ dsimp,
rw semimodule.nsmul_eq_smul R,
push_cast,
rw neg_smul, }
end
end
lemma module.gsmul_eq_smul {M : Type*} [add_comm_group M] [module ℤ M]
(n : ℤ) (b : M) : gsmul n b = n • b :=
by rw [module.gsmul_eq_smul_cast ℤ, int.cast_id]
namespace int
variables [semiring R] [add_comm_group M] [semimodule R M] [semimodule ℤ M]
instance smul_comm_class : smul_comm_class ℤ R M :=
{ smul_comm := λ n x y, int.induction_on n
(by simp only [zero_smul, smul_zero])
(λ n ih, by simp only [one_smul, add_smul, smul_add, ih])
(λ n ih, by simp only [one_smul, sub_smul, smul_sub, ih]) }
-- `smul_comm_class.symm` is not registered as an instance, as it would cause a loop
instance smul_comm_class' : smul_comm_class R ℤ M := smul_comm_class.symm _ _ _
end int
namespace add_monoid_hom
-- We prove this without using the `add_comm_group.int_module` instance, so the `•`s here
-- come from whatever the local `module ℤ` structure actually is.
lemma map_int_module_smul
[add_comm_group M] [add_comm_group M₂]
[module ℤ M] [module ℤ M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a :=
by simp only [← module.gsmul_eq_smul, f.map_gsmul]
lemma map_int_cast_smul
[ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]
(f : M →+ M₂) (x : ℤ) (a : M) : f ((x : R) • a) = (x : R) • f a :=
by simp only [← module.gsmul_eq_smul_cast, f.map_gsmul]
lemma map_nat_cast_smul
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
[semimodule R M] [semimodule R M₂] (f : M →+ M₂) (x : ℕ) (a : M) :
f ((x : R) • a) = (x : R) • f a :=
by simp only [← semimodule.nsmul_eq_smul, f.map_nsmul]
lemma map_rat_cast_smul {R : Type*} [division_ring R] [char_zero R]
{E : Type*} [add_comm_group E] [module R E] {F : Type*} [add_comm_group F] [module R F]
(f : E →+ F) (c : ℚ) (x : E) :
f ((c : R) • x) = (c : R) • f x :=
begin
have : ∀ (x : E) (n : ℕ), 0 < n → f (((n⁻¹ : ℚ) : R) • x) = ((n⁻¹ : ℚ) : R) • f x,
{ intros x n hn,
replace hn : (n : R) ≠ 0 := nat.cast_ne_zero.2 (ne_of_gt hn),
conv_rhs { congr, skip, rw [← one_smul R x, ← mul_inv_cancel hn, mul_smul] },
rw [f.map_nat_cast_smul, smul_smul, rat.cast_inv, rat.cast_coe_nat,
inv_mul_cancel hn, one_smul] },
refine c.num_denom_cases_on (λ m n hn hmn, _),
rw [rat.mk_eq_div, div_eq_mul_inv, rat.cast_mul, int.cast_coe_nat, mul_smul, mul_smul,
rat.cast_coe_int, f.map_int_cast_smul, this _ n hn]
end
lemma map_rat_module_smul {E : Type*} [add_comm_group E] [vector_space ℚ E]
{F : Type*} [add_comm_group F] [module ℚ F] (f : E →+ F) (c : ℚ) (x : E) :
f (c • x) = c • f x :=
rat.cast_id c ▸ f.map_rat_cast_smul c x
@[simp] lemma nat_smul_apply [add_monoid M] [add_comm_monoid M₂]
[semimodule ℕ (M →+ M₂)] [semimodule ℕ M₂]
(n : ℕ) (f : M →+ M₂) (a : M) :
(n • f) a = n • (f a) :=
begin
induction n with n IH,
{ simp only [zero_smul, zero_apply] },
{ simp only [nat.succ_eq_add_one, add_smul, IH, one_smul, add_apply] }
end
@[simp] lemma int_smul_apply [add_monoid M] [add_comm_group M₂]
[module ℤ (M →+ M₂)] [module ℤ M₂]
(n : ℤ) (f : M →+ M₂) (a : M) :
(n • f) a = n • (f a) :=
begin
apply int.induction_on' n 0,
{ simp only [zero_smul, zero_apply] },
all_goals
{ intros k hk IH,
simp only [add_smul, sub_smul, IH, one_smul, add_apply, sub_apply] }
end
end add_monoid_hom
-- We finally turn on these instances globally:
attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module
section module_division_ring
/-! Some tests for the vanishing of elements in modules over division rings. -/
variables (R) [division_ring R] [add_comm_group M] [module R M]
lemma smul_nat_eq_zero [char_zero R] {v : M} {n : ℕ} :
n • v = 0 ↔ n = 0 ∨ v = 0 :=
by { rw [semimodule.smul_eq_smul R, smul_eq_zero], simp }
lemma eq_zero_of_smul_two_eq_zero [char_zero R] {v : M} (hv : 2 • v = 0) : v = 0 :=
((smul_nat_eq_zero R).mp hv).resolve_left (by norm_num)
lemma eq_zero_of_eq_neg [char_zero R] {v : M} (hv : v = - v) : v = 0 :=
begin
refine eq_zero_of_smul_two_eq_zero R _,
convert add_eq_zero_iff_eq_neg.mpr hv,
abel
end
lemma ne_neg_of_ne_zero [char_zero R] {v : R} (hv : v ≠ 0) : v ≠ -v :=
λ h, hv (eq_zero_of_eq_neg R h)
end module_division_ring
|
540bf5fc4b57f8cd86ad15d8d54aa0c183b1ca88 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/category_theory/monad/adjunction.lean | 947d6320f66b653a57e92c613bfac8797c3d0390 | [
"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 | 6,112 | 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.monad.algebra
import category_theory.adjunction.fully_faithful
namespace category_theory
open category
universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
variables (R : D ⥤ C)
namespace adjunction
instance monad (R : D ⥤ C) [is_right_adjoint R] : monad ((left_adjoint R) ⋙ R) :=
let L := left_adjoint R in
let h : L ⊣ R := is_right_adjoint.adj in
{ η := h.unit,
μ := whisker_right (whisker_left L h.counit) R,
assoc' := λ X, by { dsimp, erw [←R.map_comp, h.counit.naturality, R.map_comp], refl },
right_unit' := λ X, by { dsimp, rw [←R.map_comp], simp }, }
@[simp] lemma monad_η_app [is_right_adjoint R] (X) :
(η_ ((left_adjoint R) ⋙ R)).app X = is_right_adjoint.adj.unit.app X := rfl
@[simp] lemma monad_μ_app [is_right_adjoint R] (X) :
(μ_ ((left_adjoint R) ⋙ R)).app X = R.map (is_right_adjoint.adj.counit.app ((left_adjoint R).obj X)) := rfl
end adjunction
namespace monad
/--
Gven any adjunction `L ⊣ R`, there is a comparison functor `category_theory.monad.comparison R`
sending objects `Y : D` to Eilenberg-Moore algebras for `L ⋙ R` with underlying object `R.obj X`.
We later show that this is full when `R` is full, faithful when `R` is faithful,
and essentially surjective when `R` is reflective.
-/
-- We can't use `@[simps]` here because it can't cope with `let` statements.
def comparison [is_right_adjoint R] : D ⥤ algebra ((left_adjoint R) ⋙ R) :=
let h : _ ⊣ R := is_right_adjoint.adj in
{ obj := λ X,
{ A := R.obj X,
a := R.map (h.counit.app X),
assoc' := by { dsimp, conv { to_rhs, erw [←R.map_comp, h.counit.naturality, R.map_comp], }, refl } },
map := λ X Y f,
{ f := R.map f,
h' := begin dsimp, erw [←R.map_comp, h.counit.naturality, R.map_comp, functor.id_map], refl, end } }.
@[simp] lemma comparison_map_f [is_right_adjoint R] {X Y} (f : X ⟶ Y) :
((comparison R).map f).f = R.map f := rfl
@[simp] lemma comparison_obj_a [is_right_adjoint R] (X) :
((comparison R).obj X).a = R.map (is_right_adjoint.adj.counit.app X) := rfl
/--
The underlying object of `(monad.comparison R).obj X` is just `R.obj X`.
-/
def comparison_forget [is_right_adjoint R] : comparison R ⋙ forget ((left_adjoint R) ⋙ R) ≅ R :=
{ hom := { app := λ X, 𝟙 _, },
inv := { app := λ X, 𝟙 _, } }
end monad
/-- A functor is *reflective*, or *a reflective inclusion*, if it is fully faithful and right adjoint. -/
class reflective (R : D ⥤ C) extends is_right_adjoint R, full R, faithful R.
/-- A right adjoint functor `R : D ⥤ C` is *monadic* if the comparison function `monad.comparison R` from `D` to the
category of Eilenberg-Moore algebras for the adjunction is an equivalence. -/
class monadic_right_adjoint (R : D ⥤ C) extends is_right_adjoint R :=
(eqv : is_equivalence (monad.comparison R))
instance μ_iso_of_reflective [reflective R] : is_iso (μ_ ((left_adjoint R) ⋙ R)) :=
by { dsimp [adjunction.monad], apply_instance }
attribute [instance] monadic_right_adjoint.eqv
-- PROJECT prove Beck's monadicity theorem, e.g. from Section 5.5 of [Riehl][riehl2017]
namespace reflective
lemma comparison_ess_surj_aux [reflective R] (X : monad.algebra ((left_adjoint R) ⋙ R)) :
((is_right_adjoint.adj).unit).app (R.obj ((left_adjoint R).obj (X.A)))
= R.map ((left_adjoint R).map ((is_right_adjoint.adj).unit.app X.A)) :=
begin
-- both are left inverses to μ_X.
apply (cancel_mono ((μ_ ((left_adjoint R) ⋙ R)).app _)).1,
{ dsimp, erw [adjunction.right_triangle_components, ←R.map_comp], simp, },
{ apply is_iso.mono_of_iso _,
apply nat_iso.is_iso_app_of_is_iso }
end
instance [reflective R] (X : monad.algebra ((left_adjoint R) ⋙ R)) :
is_iso ((is_right_adjoint.adj : _ ⊣ R).unit.app X.A) :=
let L := left_adjoint R in
let h : L ⊣ R := (is_right_adjoint.adj) in
{ inv := X.a,
hom_inv_id' := X.unit,
inv_hom_id' :=
begin
dsimp,
erw [h.unit.naturality, comparison_ess_surj_aux,
←R.map_comp, ←L.map_comp, X.unit, L.map_id, R.map_id],
refl
end }
instance comparison_ess_surj [reflective R] : ess_surj (monad.comparison R) :=
let L := left_adjoint R in
let h : L ⊣ R := is_right_adjoint.adj in
{ obj_preimage := λ X, L.obj X.A,
iso' := λ X,
{ hom :=
{ f := (as_iso (h.unit.app X.A)).inv,
h' :=
begin
dsimp,
apply (cancel_epi (R.map (L.map ((h.unit).app (X.A))))).1,
rw [is_iso.hom_inv_id_assoc, ←category.assoc, ←R.map_comp,adjunction.left_triangle_components],
erw [functor.map_id, category.id_comp],
apply (cancel_epi ((h.unit).app (X.A))).1,
rw is_iso.hom_inv_id,
exact X.unit,
end },
inv :=
{ f := (as_iso (h.unit.app X.A)).hom,
h' :=
begin
dsimp,
erw [←R.map_comp, adjunction.left_triangle_components, R.map_id],
apply (cancel_epi ((h.unit).app (X.A))).1,
conv { to_rhs, erw [←category.assoc, X.unit] },
erw [comp_id, id_comp],
end },
hom_inv_id' := by { ext, exact (as_iso (h.unit.app X.A)).inv_hom_id, },
inv_hom_id' := by { ext, exact (as_iso (h.unit.app X.A)).hom_inv_id, }, } }
instance comparison_full [full R] [is_right_adjoint R] : full (monad.comparison R) :=
{ preimage := λ X Y f, R.preimage f.f }
instance comparison_faithful [faithful R] [is_right_adjoint R] : faithful (monad.comparison R) :=
{ map_injective' := λ X Y f g w, by { have w' := (congr_arg monad.algebra.hom.f w), exact R.map_injective w' } }
end reflective
/-- Any reflective inclusion has a monadic right adjoint.
cf Prop 5.3.3 of [Riehl][riehl2017] -/
@[priority 100] -- see Note [lower instance priority]
instance monadic_of_reflective [reflective R] : monadic_right_adjoint R :=
{ eqv := equivalence.equivalence_of_fully_faithfully_ess_surj _ }
end category_theory
|
0a6b93768960ded7db86d91f019d739977d46e8b | 1dd482be3f611941db7801003235dc84147ec60a | /src/measure_theory/decomposition.lean | c6225ec79922cd82ce4fe1038302c2d9994d2c73 | [
"Apache-2.0"
] | permissive | sanderdahmen/mathlib | 479039302bd66434bb5672c2a4cecf8d69981458 | 8f0eae75cd2d8b7a083cf935666fcce4565df076 | refs/heads/master | 1,587,491,322,775 | 1,549,672,060,000 | 1,549,672,060,000 | 169,748,224 | 0 | 0 | Apache-2.0 | 1,549,636,694,000 | 1,549,636,694,000 | null | UTF-8 | Lean | false | false | 8,552 | 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
Hahn decomposition theorem
TODO:
* introduce finite measures (into nnreal)
* show general for signed measures (into ℝ)
-/
import measure_theory.measure_space
local attribute [instance, priority 0] classical.prop_decidable
namespace measure_theory
open set lattice filter
variables {α : Type*} [measurable_space α] {μ ν : measure α}
lemma hahn_decomposition (hμ : μ univ < ⊤) (hν : ν univ < ⊤) :
∃s, is_measurable s ∧
(∀t, is_measurable t → t ⊆ s → ν t ≤ μ t) ∧
(∀t, is_measurable t → t ⊆ - s → μ t ≤ ν t) :=
begin
let d : set α → ℝ := λs, ((μ s).to_nnreal : ℝ) - (ν s).to_nnreal,
let c : set ℝ := d '' {s | is_measurable s },
let γ : ℝ := Sup c,
have hμ : ∀s, μ s < ⊤ := assume s, lt_of_le_of_lt (measure_mono $ subset_univ _) hμ,
have hν : ∀s, ν s < ⊤ := assume s, lt_of_le_of_lt (measure_mono $ subset_univ _) hν,
have to_nnreal_μ : ∀s, ((μ s).to_nnreal : ennreal) = μ s :=
(assume s, ennreal.coe_to_nnreal $ ne_top_of_lt $ hμ _),
have to_nnreal_ν : ∀s, ((ν s).to_nnreal : ennreal) = ν s :=
(assume s, ennreal.coe_to_nnreal $ ne_top_of_lt $ hν _),
have d_empty : d ∅ = 0, { simp [d], rw [measure_empty, measure_empty], simp },
have d_split : ∀s t, is_measurable s → is_measurable t →
d s = d (s \ t) + d (s ∩ t),
{ assume s t hs ht,
simp only [d],
rw [measure_eq_inter_diff hs ht, measure_eq_inter_diff hs ht,
ennreal.to_nnreal_add (hμ _) (hμ _), ennreal.to_nnreal_add (hν _) (hν _),
nnreal.coe_add, nnreal.coe_add],
simp only [sub_eq_add_neg, neg_add],
ac_refl },
have d_Union : ∀(s : ℕ → set α), (∀n, is_measurable (s n)) → monotone s →
tendsto (λn, d (s n)) at_top (nhds (d (⋃n, s n))),
{ assume s hs hm,
refine tendsto_sub _ _;
refine (nnreal.tendsto_coe.2 $
(tendsto_measure_Union hs hm).comp $ ennreal.tendsto_to_nnreal $ @ne_top_of_lt _ _ _ ⊤ _),
exact hμ _,
exact hν _ },
have d_Inter : ∀(s : ℕ → set α), (∀n, is_measurable (s n)) → (∀n m, n ≤ m → s m ⊆ s n) →
tendsto (λn, d (s n)) at_top (nhds (d (⋂n, s n))),
{ assume s hs hm,
refine tendsto_sub _ _;
refine (nnreal.tendsto_coe.2 $
(tendsto_measure_Inter hs hm _).comp $ ennreal.tendsto_to_nnreal $ @ne_top_of_lt _ _ _ ⊤ _),
exact ⟨0, hμ _⟩,
exact hμ _,
exact ⟨0, hν _⟩,
exact hν _ },
have bdd_c : bdd_above c,
{ use (μ univ).to_nnreal,
rintros r ⟨s, hs, rfl⟩,
refine le_trans (sub_le_self _ $ nnreal.coe_nonneg _) _,
rw [← nnreal.coe_le, ← ennreal.coe_le_coe, to_nnreal_μ, to_nnreal_μ],
exact measure_mono (subset_univ _) },
have c_nonempty : c ≠ ∅ := ne_empty_of_mem (mem_image_of_mem _ is_measurable.empty),
have d_le_γ : ∀s, is_measurable s → d s ≤ γ := assume s hs, le_cSup bdd_c ⟨s, hs, rfl⟩,
have : ∀n:ℕ, ∃s : set α, is_measurable s ∧ γ - (1/2)^n < d s,
{ assume n,
have : γ - (1/2)^n < γ := sub_lt_self γ (pow_pos (half_pos zero_lt_one) n),
rcases exists_lt_of_lt_cSup c_nonempty this with ⟨r, ⟨s, hs, rfl⟩, hlt⟩,
exact ⟨s, hs, hlt⟩ },
rcases classical.axiom_of_choice this with ⟨e, he⟩,
change ℕ → set α at e,
have he₁ : ∀n, is_measurable (e n) := assume n, (he n).1,
have he₂ : ∀n, γ - (1/2)^n < d (e n) := assume n, (he n).2,
let f : ℕ → ℕ → set α := λn m, (finset.Ico n (m + 1)).inf e,
have hf : ∀n m, is_measurable (f n m),
{ assume n m,
simp only [f, finset.inf_eq_infi],
exact is_measurable.bInter (countable_encodable _) (assume i _, he₁ _) },
have f_subset_f : ∀{a b c d}, a ≤ b → c ≤ d → f a d ⊆ f b c,
{ assume a b c d hab hcd,
dsimp only [f],
rw [finset.inf_eq_infi, finset.inf_eq_infi],
refine bInter_subset_bInter_left _,
simp,
rintros j ⟨hbj, hjc⟩,
exact ⟨le_trans hab hbj, lt_of_lt_of_le hjc $ add_le_add_right hcd 1⟩ },
have f_succ : ∀n m, n ≤ m → f n (m + 1) = f n m ∩ e (m + 1),
{ assume n m hnm,
have : n ≤ m + 1 := le_of_lt (nat.succ_le_succ hnm),
simp only [f],
rw [finset.Ico.succ_top this, finset.inf_insert, set.inter_comm],
refl },
have le_d_f : ∀n m, m ≤ n → γ - 2 * ((1 / 2) ^ m) + (1 / 2) ^ n ≤ d (f m n),
{ assume n m h,
refine nat.le_induction _ _ n h,
{ have := he₂ m,
simp only [f],
rw [finset.Ico.succ_singleton, finset.inf_singleton],
linarith },
{ assume n (hmn : m ≤ n) ih,
have : γ + (γ - 2 * (1 / 2)^m + (1 / 2) ^ (n + 1)) ≤ γ + d (f m (n + 1)),
{ calc γ + (γ - 2 * (1 / 2)^m + (1 / 2) ^ (n+1)) ≤
γ + (γ - 2 * (1 / 2)^m + ((1 / 2) ^ n - (1/2)^(n+1))) :
begin
refine add_le_add_left (add_le_add_left _ _) γ,
simp only [pow_add, pow_one, le_sub_iff_add_le],
linarith
end
... = (γ - (1 / 2)^(n+1)) + (γ - 2 * (1 / 2)^m + (1 / 2)^n) :
by simp only [sub_eq_add_neg]; ac_refl
... ≤ d (e (n + 1)) + d (f m n) : add_le_add (le_of_lt $ he₂ _) ih
... ≤ d (e (n + 1)) + d (f m n \ e (n + 1)) + d (f m (n + 1)) :
by rw [f_succ _ _ hmn, d_split (f m n) (e (n + 1)) (hf _ _) (he₁ _), add_assoc]
... = d (e (n + 1) ∪ f m n) + d (f m (n + 1)) :
begin
rw [d_split (e (n + 1) ∪ f m n) (e (n + 1)),
union_diff_left, union_inter_cancel_left],
ac_refl,
exact (he₁ _).union (hf _ _),
exact (he₁ _)
end
... ≤ γ + d (f m (n + 1)) :
add_le_add_right (d_le_γ _ $ (he₁ _).union (hf _ _)) _ },
exact (add_le_add_iff_left γ).1 this } },
let s := ⋃ m, ⋂n, f m n,
have γ_le_d_s : γ ≤ d s,
{ have hγ : tendsto (λm:ℕ, γ - 2 * (1/2)^m) at_top (nhds γ),
{ suffices : tendsto (λm:ℕ, γ - 2 * (1/2)^m) at_top (nhds (γ - 2 * 0)), { simpa },
exact (tendsto_sub tendsto_const_nhds $ tendsto_mul tendsto_const_nhds $
tendsto_pow_at_top_nhds_0_of_lt_1
(le_of_lt $ half_pos $ zero_lt_one) (half_lt_self zero_lt_one)) },
have hd : tendsto (λm, d (⋂n, f m n)) at_top (nhds (d (⋃ m, ⋂ n, f m n))),
{ refine d_Union _ _ _,
{ assume n, exact is_measurable.Inter (assume m, hf _ _) },
{ exact assume n m hnm, subset_Inter
(assume i, subset.trans (Inter_subset (f n) i) $ f_subset_f hnm $ le_refl _) } },
refine le_of_tendsto_of_tendsto (@at_top_ne_bot ℕ _ _) hγ hd (univ_mem_sets' $ assume m, _),
change γ - 2 * (1 / 2) ^ m ≤ d (⋂ (n : ℕ), f m n),
have : tendsto (λn, d (f m n)) at_top (nhds (d (⋂ n, f m n))),
{ refine d_Inter _ _ _,
{ assume n, exact hf _ _ },
{ assume n m hnm, exact f_subset_f (le_refl _) hnm } },
refine ge_of_tendsto (@at_top_ne_bot ℕ _ _) this (mem_at_top_sets.2 ⟨m, assume n hmn, _⟩),
change γ - 2 * (1 / 2) ^ m ≤ d (f m n),
refine le_trans _ (le_d_f _ _ hmn),
exact le_add_of_le_of_nonneg (le_refl _) (pow_nonneg (le_of_lt $ half_pos $ zero_lt_one) _) },
have hs : is_measurable s :=
is_measurable.Union (assume n, is_measurable.Inter (assume m, hf _ _)),
refine ⟨s, hs, _, _⟩,
{ assume t ht hts,
have : 0 ≤ d t := ((add_le_add_iff_left γ).1 $
calc γ + 0 ≤ d s : by rw [add_zero]; exact γ_le_d_s
... = d (s \ t) + d t : by rw [d_split _ _ hs ht, inter_eq_self_of_subset_right hts]
... ≤ γ + d t : add_le_add (d_le_γ _ (hs.diff ht)) (le_refl _)),
rw [← to_nnreal_μ, ← to_nnreal_ν, ennreal.coe_le_coe, nnreal.coe_le],
simpa only [d, le_sub_iff_add_le, zero_add] using this },
{ assume t ht hts,
have : d t ≤ 0,
exact ((add_le_add_iff_left γ).1 $
calc γ + d t ≤ d s + d t : add_le_add γ_le_d_s (le_refl _)
... = d (s ∪ t) :
begin
rw [d_split _ _ (hs.union ht) ht, union_diff_right, union_inter_cancel_right,
diff_eq_self.2],
exact assume a ⟨hat, has⟩, hts hat has
end
... ≤ γ + 0 : by rw [add_zero]; exact d_le_γ _ (hs.union ht)),
rw [← to_nnreal_μ, ← to_nnreal_ν, ennreal.coe_le_coe, nnreal.coe_le],
simpa only [d, sub_le_iff_le_add, zero_add] using this }
end
end measure_theory
|
7f2126e969e478b7394a849a9eefdd222f6aefc8 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /test/set.lean | bbeebd5240130ade8af07daf14c91c93780c66cf | [
"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,344 | lean | import data.matrix.notation
example (x : ℕ) (h : x = 3) : x + x + x = 9 :=
begin
set y := x with ←h_xy,
guard_hyp y : ℕ := x,
guard_hyp h_xy : x = y,
guard_hyp h : y = 3,
guard_target y + y + y = 9,
set! z : ℕ := y,
guard_target y + y + y = 9,
simp [h]
end
example : true :=
let X1 := (![![1, 0], ![0, 0]] : matrix (fin 2) (fin 2) ℕ), -- X1 : fin 1.succ → fin 2 → ℕ
X2 : matrix (fin 2) (fin 2) ℕ := ![![1, 0], ![0, 0]] in -- X2 : matrix (fin 2) (fin 2) ℕ
begin
set Y1 := (![![1, 0], ![0, 0]] : matrix (fin 2) (fin 2) ℕ),
set Y2 : matrix (fin 2) (fin 2) ℕ := ![![1, 0], ![0, 0]],
let Z1 := (![![1, 0], ![0, 0]] : matrix (fin 2) (fin 2) ℕ),
let Z2 : matrix (fin 2) (fin 2) ℕ := ![![1, 0], ![0, 0]],
guard_hyp Y2 : matrix (fin 2) (fin 2) ℕ := (![![1, 0], ![0, 0]] : matrix (fin 2) (fin 2) ℕ),
trivial
end
def T {α : Type} := ℕ
def v : @T ℕ := nat.zero
def S := @T ℕ
def u : S := nat.zero
def p : true :=
begin
set a : T := v,
set b : T := u, -- the type `T` can't be fully elaborated without the body but this is fine
trivial
end
section lean_555 -- https://github.com/leanprover-community/mathlib/pull/14488
inductive foo | bar
instance : has_coe_to_sort foo _ :=
⟨λ _, unit⟩
example : true :=
begin
set x : foo.bar := (),
trivial,
end
end lean_555
|
1a178f69fb65f99fdf6bcad631508e866689eb36 | e39f04f6ff425fe3b3f5e26a8998b817d1dba80f | /analysis/measure_theory/outer_measure.lean | 58858557c09454a779c01132ca2215777c81ed26 | [
"Apache-2.0"
] | permissive | kristychoi/mathlib | c504b5e8f84e272ea1d8966693c42de7523bf0ec | 257fd84fe98927ff4a5ffe044f68c4e9d235cc75 | refs/heads/master | 1,586,520,722,896 | 1,544,030,145,000 | 1,544,031,933,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,153 | 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
Outer measures -- overapproximations of measures
-/
import order.galois_connection algebra.big_operators algebra.module
analysis.ennreal analysis.limits
analysis.measure_theory.measurable_space
noncomputable theory
open set lattice finset function filter encodable
local attribute [instance] classical.prop_decidable
namespace measure_theory
structure outer_measure (α : Type*) :=
(measure_of : set α → ennreal)
(empty : measure_of ∅ = 0)
(mono : ∀{s₁ s₂}, s₁ ⊆ s₂ → measure_of s₁ ≤ measure_of s₂)
(Union_nat : ∀(s:ℕ → set α), measure_of (⋃i, s i) ≤ (∑i, measure_of (s i)))
namespace outer_measure
instance {α} : has_coe_to_fun (outer_measure α) := ⟨_, λ m, m.measure_of⟩
section basic
variables {α : Type*} {ms : set (outer_measure α)} {m : outer_measure α}
@[simp] theorem empty' (m : outer_measure α) : m ∅ = 0 := m.empty
theorem mono' (m : outer_measure α) {s₁ s₂}
(h : s₁ ⊆ s₂) : m s₁ ≤ m s₂ := m.mono h
theorem Union_aux (m : set α → ennreal) (m0 : m ∅ = 0)
{β} [encodable β] (s : β → set α) :
(∑ b, m (s b)) = ∑ i, m (⋃ b ∈ decode2 β i, s b) :=
begin
have H : ∀ n, m (⋃ b ∈ decode2 β n, s b) ≠ 0 → (decode2 β n).is_some,
{ intros n h,
cases decode2 β n with b,
{ exact (h (by simp [m0])).elim },
{ exact rfl } },
refine tsum_eq_tsum_of_ne_zero_bij (λ n h, option.get (H n h)) _ _ _,
{ intros m n hm hn e,
have := mem_decode2.1 (option.get_mem (H n hn)),
rwa [← e, mem_decode2.1 (option.get_mem (H m hm))] at this },
{ intros b h,
refine ⟨encode b, _, _⟩,
{ convert h, simp [ext_iff, encodek2] },
{ exact option.get_of_mem _ (encodek2 _) } },
{ intros n h,
transitivity, swap,
rw [show decode2 β n = _, from option.get_mem (H n h)],
congr, simp [ext_iff] }
end
protected theorem Union (m : outer_measure α)
{β} [encodable β] (s : β → set α) :
m (⋃i, s i) ≤ (∑i, m (s i)) :=
by rw [Union_decode2, Union_aux _ m.empty' s]; exact m.Union_nat _
lemma Union_null (m : outer_measure α)
{β} [encodable β] {s : β → set α} (h : ∀ i, m (s i) = 0) : m (⋃i, s i) = 0 :=
by simpa [h] using m.Union s
protected lemma union (m : outer_measure α) (s₁ s₂ : set α) :
m (s₁ ∪ s₂) ≤ m s₁ + m s₂ :=
begin
convert m.Union (λ b, cond b s₁ s₂),
{ simp [union_eq_Union] },
{ rw tsum_fintype, change _ = _ + _, simp }
end
lemma union_null (m : outer_measure α) {s₁ s₂ : set α}
(h₁ : m s₁ = 0) (h₂ : m s₂ = 0) : m (s₁ ∪ s₂) = 0 :=
by simpa [h₁, h₂] using m.union s₁ s₂
@[extensionality] lemma ext : ∀{μ₁ μ₂ : outer_measure α},
(∀s, μ₁ s = μ₂ s) → μ₁ = μ₂
| ⟨m₁, e₁, _, u₁⟩ ⟨m₂, e₂, _, u₂⟩ h := by congr; exact funext h
instance : has_zero (outer_measure α) :=
⟨{ measure_of := λ_, 0,
empty := rfl,
mono := assume _ _ _, le_refl 0,
Union_nat := assume s, zero_le _ }⟩
@[simp] theorem zero_apply (s : set α) : (0 : outer_measure α) s = 0 := rfl
instance : inhabited (outer_measure α) := ⟨0⟩
instance : has_add (outer_measure α) :=
⟨λm₁ m₂,
{ measure_of := λs, m₁ s + m₂ s,
empty := show m₁ ∅ + m₂ ∅ = 0, by simp [outer_measure.empty],
mono := assume s₁ s₂ h, add_le_add' (m₁.mono h) (m₂.mono h),
Union_nat := assume s,
calc m₁ (⋃i, s i) + m₂ (⋃i, s i) ≤
(∑i, m₁ (s i)) + (∑i, m₂ (s i)) :
add_le_add' (m₁.Union_nat s) (m₂.Union_nat s)
... = _ : ennreal.tsum_add.symm}⟩
@[simp] theorem add_apply (m₁ m₂ : outer_measure α) (s : set α) :
(m₁ + m₂) s = m₁ s + m₂ s := rfl
instance : add_comm_monoid (outer_measure α) :=
{ zero := 0,
add := (+),
add_comm := assume a b, ext $ assume s, add_comm _ _,
add_assoc := assume a b c, ext $ assume s, add_assoc _ _ _,
add_zero := assume a, ext $ assume s, add_zero _,
zero_add := assume a, ext $ assume s, zero_add _ }
instance : has_bot (outer_measure α) := ⟨0⟩
instance outer_measure.order_bot : order_bot (outer_measure α) :=
{ le := λm₁ m₂, ∀s, m₁ s ≤ m₂ s,
bot := 0,
le_refl := assume a s, le_refl _,
le_trans := assume a b c hab hbc s, le_trans (hab s) (hbc s),
le_antisymm := assume a b hab hba, ext $ assume s, le_antisymm (hab s) (hba s),
bot_le := assume a s, zero_le _ }
section supremum
instance : has_Sup (outer_measure α) :=
⟨λms, {
measure_of := λs, ⨆m:ms, m.val s,
empty := le_zero_iff_eq.1 $ supr_le $ λ ⟨m, h⟩, le_of_eq m.empty,
mono := assume s₁ s₂ hs, supr_le_supr $ assume ⟨m, hm⟩, m.mono hs,
Union_nat := assume f, supr_le $ assume m,
calc m.val (⋃i, f i) ≤ (∑ (i : ℕ), m.val (f i)) : m.val.Union_nat _
... ≤ (∑i, ⨆m:ms, m.val (f i)) :
ennreal.tsum_le_tsum $ assume i, le_supr (λm:ms, m.val (f i)) m }⟩
private lemma le_Sup (hm : m ∈ ms) : m ≤ Sup ms :=
λ s, le_supr (λm:ms, m.val s) ⟨m, hm⟩
private lemma Sup_le (hm : ∀m' ∈ ms, m' ≤ m) : Sup ms ≤ m :=
λ s, (supr_le $ assume ⟨m', h'⟩, (hm m' h') s)
instance : has_Inf (outer_measure α) := ⟨λs, Sup {m | ∀m'∈s, m ≤ m'}⟩
private lemma Inf_le (hm : m ∈ ms) : Inf ms ≤ m := Sup_le $ assume m' h', h' _ hm
private lemma le_Inf (hm : ∀m' ∈ ms, m ≤ m') : m ≤ Inf ms := le_Sup hm
instance : complete_lattice (outer_measure α) :=
{ top := Sup univ,
le_top := assume a, le_Sup (mem_univ a),
Sup := Sup,
Sup_le := assume s m, Sup_le,
le_Sup := assume s m, le_Sup,
Inf := Inf,
Inf_le := assume s m, Inf_le,
le_Inf := assume s m, le_Inf,
sup := λa b, Sup {a, b},
le_sup_left := assume a b, le_Sup $ by simp,
le_sup_right := assume a b, le_Sup $ by simp,
sup_le := assume a b c ha hb, Sup_le $ by simp [or_imp_distrib, ha, hb] {contextual:=tt},
inf := λa b, Inf {a, b},
inf_le_left := assume a b, Inf_le $ by simp,
inf_le_right := assume a b, Inf_le $ by simp,
le_inf := assume a b c ha hb, le_Inf $ by simp [or_imp_distrib, ha, hb] {contextual:=tt},
.. outer_measure.order_bot }
@[simp] theorem Sup_apply (ms : set (outer_measure α)) (s : set α) :
(Sup ms) s = ⨆ m : ms, m s := rfl
@[simp] theorem supr_apply {ι} (f : ι → outer_measure α) (s : set α) :
(⨆ i : ι, f i) s = ⨆ i, f i s :=
le_antisymm
(supr_le $ λ ⟨_, i, rfl⟩, le_supr _ i)
(supr_le $ λ i, le_supr
(λ (m : {a : outer_measure α // ∃ i, f i = a}), m.1 s)
⟨f i, i, rfl⟩)
@[simp] theorem sup_apply (m₁ m₂ : outer_measure α) (s : set α) :
(m₁ ⊔ m₂) s = m₁ s ⊔ m₂ s :=
by have := supr_apply (λ b, cond b m₁ m₂) s;
rwa [supr_bool_eq, supr_bool_eq] at this
end supremum
def map {β} (f : α → β) (m : outer_measure α) : outer_measure β :=
{ measure_of := λs, m (f ⁻¹' s),
empty := m.empty,
mono := λ s t h, m.mono (preimage_mono h),
Union_nat := λ s, by rw [preimage_Union]; exact
m.Union_nat (λ i, f ⁻¹' s i) }
@[simp] theorem map_apply {β} (f : α → β)
(m : outer_measure α) (s : set β) : map f m s = m (f ⁻¹' s) := rfl
@[simp] theorem map_id (m : outer_measure α) : map id m = m :=
ext $ λ s, rfl
@[simp] theorem map_map {β γ} (f : α → β) (g : β → γ)
(m : outer_measure α) : map g (map f m) = map (g ∘ f) m :=
ext $ λ s, rfl
instance : functor outer_measure := {map := λ α β, map}
instance : is_lawful_functor outer_measure :=
{ id_map := λ α, map_id,
comp_map := λ α β γ f g m, (map_map f g m).symm }
/-- The dirac outer measure. -/
def dirac (a : α) : outer_measure α :=
{ measure_of := λs, ⨆ h : a ∈ s, 1,
empty := by simp,
mono := λ s t h, supr_le_supr2 (λ h', ⟨h h', le_refl _⟩),
Union_nat := λ s, supr_le $ λ h,
let ⟨i, h⟩ := mem_Union.1 h in
le_trans (by exact le_supr _ h) (ennreal.le_tsum i) }
@[simp] theorem dirac_apply (a : α) (s : set α) :
dirac a s = ⨆ h : a ∈ s, 1 := rfl
def sum {ι} (f : ι → outer_measure α) : outer_measure α :=
{ measure_of := λs, ∑ i, f i s,
empty := by simp,
mono := λ s t h, ennreal.tsum_le_tsum (λ i, (f i).mono' h),
Union_nat := λ s, by rw ennreal.tsum_comm; exact
ennreal.tsum_le_tsum (λ i, (f i).Union_nat _) }
@[simp] theorem sum_apply {ι} (f : ι → outer_measure α) (s : set α) :
sum f s = ∑ i, f i s := rfl
instance : has_scalar ennreal (outer_measure α) :=
⟨λ a m, {
measure_of := λs, a * m s,
empty := by simp,
mono := λ s t h, canonically_ordered_semiring.mul_le_mul (le_refl _) (m.mono' h),
Union_nat := λ s, by rw ennreal.mul_tsum; exact
canonically_ordered_semiring.mul_le_mul (le_refl _) (m.Union_nat _) }⟩
@[simp] theorem smul_apply (a : ennreal) (m : outer_measure α) (s : set α) :
(a • m) s = a * m s := rfl
instance : semimodule ennreal (outer_measure α) :=
{ smul_add := λ a m₁ m₂, ext $ λ s, mul_add _ _ _,
add_smul := λ a b m, ext $ λ s, add_mul _ _ _,
mul_smul := λ a b m, ext $ λ s, mul_assoc _ _ _,
one_smul := λ m, ext $ λ s, one_mul _,
zero_smul := λ m, ext $ λ s, zero_mul _,
smul_zero := λ a, ext $ λ s, mul_zero _,
..outer_measure.has_scalar }
theorem smul_dirac_apply (a : ennreal) (b : α) (s : set α) :
(a • dirac b) s = ⨆ h : b ∈ s, a :=
by by_cases b ∈ s; simp [h]
theorem top_apply {s : set α} (h : s ≠ ∅) : (⊤ : outer_measure α) s = ⊤ :=
let ⟨a, as⟩ := set.exists_mem_of_ne_empty h in
top_unique $ le_supr_of_le ⟨⊤ • dirac a, trivial⟩ $
by simp [smul_dirac_apply, as]
end basic
section of_function
set_option eqn_compiler.zeta true
/-- Given any function `m` assigning measures to sets satisying `m ∅ = 0`, there is
a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : set α`. -/
protected def of_function {α : Type*} (m : set α → ennreal) (m_empty : m ∅ = 0) :
outer_measure α :=
let μ := λs, ⨅{f : ℕ → set α} (h : s ⊆ ⋃i, f i), ∑i, m (f i) in
{ measure_of := μ,
empty := le_antisymm
(infi_le_of_le (λ_, ∅) $ infi_le_of_le (empty_subset _) $ by simp [m_empty])
(zero_le _),
mono := assume s₁ s₂ hs, infi_le_infi $ assume f,
infi_le_infi2 $ assume hb, ⟨subset.trans hs hb, le_refl _⟩,
Union_nat := assume s, ennreal.le_of_forall_epsilon_le $ begin
assume ε hε (hb : (∑i, μ (s i)) < ⊤),
rcases ennreal.exists_pos_sum_of_encodable (ennreal.coe_lt_coe.2 hε) ℕ with ⟨ε', hε', hl⟩,
refine le_trans _ (add_le_add_left' (le_of_lt hl)),
rw ← ennreal.tsum_add,
choose f hf using show
∀i, ∃f:ℕ → set α, s i ⊆ (⋃i, f i) ∧ (∑i, m (f i)) < μ (s i) + ε' i,
{ intro,
have : μ (s i) < μ (s i) + ε' i :=
ennreal.lt_add_right
(lt_of_le_of_lt (by apply ennreal.le_tsum) hb)
(by simpa using hε' i),
simpa [μ, infi_lt_iff] },
refine le_trans _ (ennreal.tsum_le_tsum $ λ i, le_of_lt (hf i).2),
rw [← ennreal.tsum_prod, ← tsum_equiv equiv.nat_prod_nat_equiv_nat.symm],
swap, {apply_instance},
refine infi_le_of_le _ (infi_le _ _),
exact Union_subset (λ i, subset.trans (hf i).1 $
Union_subset $ λ j, subset.trans (by simp) $
subset_Union _ $ equiv.nat_prod_nat_equiv_nat (i, j)),
end }
theorem of_function_le {α : Type*} (m : set α → ennreal) (m_empty s) :
outer_measure.of_function m m_empty s ≤ m s :=
let f : ℕ → set α := λi, nat.rec_on i s (λn s, ∅) in
infi_le_of_le f $ infi_le_of_le (subset_Union f 0) $ le_of_eq $
calc (∑i, m (f i)) = ({0} : finset ℕ).sum (λi, m (f i)) :
tsum_eq_sum $ by intro i; cases i; simp [m_empty]
... = m s : by simp; refl
theorem le_of_function {α : Type*} {m m_empty} {μ : outer_measure α} :
μ ≤ outer_measure.of_function m m_empty ↔ ∀ s, μ s ≤ m s :=
⟨λ H s, le_trans (H _) (of_function_le _ _ _),
λ H s, le_infi $ λ f, le_infi $ λ hs,
le_trans (μ.mono hs) $ le_trans (μ.Union f) $
ennreal.tsum_le_tsum $ λ i, H _⟩
end of_function
section caratheodory_measurable
universe u
parameters {α : Type u} (m : outer_measure α)
include m
local attribute [simp] set.inter_comm set.inter_left_comm set.inter_assoc
variables {s s₁ s₂ : set α}
private def C (s : set α) := ∀t, m t = m (t ∩ s) + m (t \ s)
private lemma C_iff_le {s : set α} : C s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t :=
forall_congr $ λ t, le_antisymm_iff.trans $ and_iff_right $
by convert m.union _ _; rw inter_union_diff t s
@[simp] private lemma C_empty : C ∅ := by simp [C, m.empty, diff_empty]
private lemma C_compl : C s₁ → C (- s₁) := by simp [C, diff_eq]
@[simp] private lemma C_compl_iff : C (- s) ↔ C s :=
⟨λ h, by simpa using C_compl m h, C_compl⟩
private lemma C_union (h₁ : C s₁) (h₂ : C s₂) : C (s₁ ∪ s₂) :=
λ t, begin
rw [h₁ t, h₂ (t ∩ s₁), h₂ (t \ s₁), h₁ (t ∩ (s₁ ∪ s₂)),
inter_diff_assoc _ _ s₁, set.inter_assoc _ _ s₁,
inter_eq_self_of_subset_right (set.subset_union_left _ _),
union_diff_left, h₂ (t ∩ s₁)],
simp [diff_eq]
end
private lemma measure_inter_union (h : s₁ ∩ s₂ ⊆ ∅) (h₁ : C s₁) {t : set α} :
m (t ∩ (s₁ ∪ s₂)) = m (t ∩ s₁) + m (t ∩ s₂) :=
by rw [h₁, set.inter_assoc, union_inter_cancel_left h,
inter_diff_assoc, union_diff_cancel_left h]
private lemma C_Union_lt {s : ℕ → set α} : ∀{n:ℕ}, (∀i<n, C (s i)) → C (⋃i<n, s i)
| 0 h := by simp [nat.not_lt_zero]
| (n + 1) h := by rw Union_lt_succ; exact C_union m
(h n (le_refl (n + 1)))
(C_Union_lt $ assume i hi, h i $ lt_of_lt_of_le hi $ nat.le_succ _)
private lemma C_inter (h₁ : C s₁) (h₂ : C s₂) : C (s₁ ∩ s₂) :=
by rw [← C_compl_iff, compl_inter]; from C_union _ (C_compl _ h₁) (C_compl _ h₂)
private lemma C_sum {s : ℕ → set α} (h : ∀i, C (s i)) (hd : pairwise (disjoint on s)) {t : set α} :
∀ {n}, (finset.range n).sum (λi, m (t ∩ s i)) = m (t ∩ ⋃i<n, s i)
| 0 := by simp [nat.not_lt_zero, m.empty]
| (nat.succ n) := begin
simp [Union_lt_succ, range_succ],
rw [measure_inter_union m _ (h n), C_sum],
intro a, simpa [range_succ] using λ h₁ i hi h₂, hd _ _ (ne_of_gt hi) ⟨h₁, h₂⟩
end
private lemma C_Union_nat {s : ℕ → set α} (h : ∀i, C (s i))
(hd : pairwise (disjoint on s)) : C (⋃i, s i) :=
C_iff_le.2 $ λ t, begin
have hp : m (t ∩ ⋃i, s i) ≤ (⨆n, m (t ∩ ⋃i<n, s i)),
{ convert m.Union (λ i, t ∩ s i),
{ rw inter_Union_left },
{ simp [ennreal.tsum_eq_supr_nat, C_sum m h hd] } },
refine le_trans (add_le_add_right' hp) _,
rw ennreal.supr_add,
refine supr_le (λ n, le_trans (add_le_add_left' _)
(ge_of_eq (C_Union_lt m (λ i _, h i) _))),
refine m.mono (diff_subset_diff_right _),
exact bUnion_subset (λ i _, subset_Union _ i),
end
private lemma f_Union {s : ℕ → set α} (h : ∀i, C (s i))
(hd : pairwise (disjoint on s)) : m (⋃i, s i) = ∑i, m (s i) :=
begin
refine le_antisymm (m.Union_nat s) _,
rw ennreal.tsum_eq_supr_nat,
refine supr_le (λ n, _),
have := @C_sum _ m _ h hd univ n,
simp at this, simp [this],
exact m.mono (bUnion_subset (λ i _, subset_Union _ i)),
end
private def caratheodory_dynkin : measurable_space.dynkin_system α :=
{ has := C,
has_empty := C_empty,
has_compl := assume s, C_compl,
has_Union_nat := assume f hf hn, C_Union_nat hn hf }
/-- Given an outer measure `μ`, the Caratheodory measurable space is
defined such that `s` is measurable if `∀t, μ t = μ (t ∩ s) + μ (t \ s)`. -/
protected def caratheodory : measurable_space α :=
caratheodory_dynkin.to_measurable_space $ assume s₁ s₂, C_inter
lemma is_caratheodory {s : set α} :
caratheodory.is_measurable s ↔ ∀t, m t = m (t ∩ s) + m (t \ s) :=
iff.rfl
lemma is_caratheodory_le {s : set α} :
caratheodory.is_measurable s ↔ ∀t, m (t ∩ s) + m (t \ s) ≤ m t :=
C_iff_le
protected lemma Union_eq_of_caratheodory {s : ℕ → set α}
(h : ∀i, caratheodory.is_measurable (s i)) (hd : pairwise (disjoint on s)) :
m (⋃i, s i) = ∑i, m (s i) :=
f_Union h hd
end caratheodory_measurable
variables {α : Type*}
lemma caratheodory_is_measurable {m : set α → ennreal} {s : set α}
{h₀ : m ∅ = 0} (hs : ∀t, m (t ∩ s) + m (t \ s) ≤ m t) :
(outer_measure.of_function m h₀).caratheodory.is_measurable s :=
let o := (outer_measure.of_function m h₀) in
(is_caratheodory_le o).2 $ λ t,
le_infi $ λ f, le_infi $ λ hf, begin
refine le_trans (add_le_add'
(infi_le_of_le (λi, f i ∩ s) $ infi_le _ _)
(infi_le_of_le (λi, f i \ s) $ infi_le _ _)) _,
{ rw ← inter_Union_right,
exact inter_subset_inter_left _ hf },
{ rw ← diff_Union_right,
exact diff_subset_diff_left hf },
{ rw ← ennreal.tsum_add,
exact ennreal.tsum_le_tsum (λ i, hs _) }
end
@[simp] theorem zero_caratheodory : (0 : outer_measure α).caratheodory = ⊤ :=
top_unique $ λ s _ t, (add_zero _).symm
theorem le_add_caratheodory (m₁ m₂ : outer_measure α) :
m₁.caratheodory ⊓ m₂.caratheodory ≤ (m₁ + m₂ : outer_measure α).caratheodory :=
λ s ⟨hs₁, hs₂⟩ t, by simp [hs₁ t, hs₂ t]
theorem le_sum_caratheodory {ι} (m : ι → outer_measure α) :
(⨅ i, (m i).caratheodory) ≤ (sum m).caratheodory :=
λ s h t, by simp [λ i,
measurable_space.is_measurable_infi.1 h i t, ennreal.tsum_add]
theorem le_smul_caratheodory (a : ennreal) (m : outer_measure α) :
m.caratheodory ≤ (a • m).caratheodory :=
λ s h t, by simp [h t, mul_add]
@[simp] theorem dirac_caratheodory (a : α) : (dirac a).caratheodory = ⊤ :=
top_unique $ λ s _ t, begin
by_cases a ∈ t; simp [h],
by_cases a ∈ s; simp [h]
end
end outer_measure
end measure_theory
|
09e8cda76271d8a484724b4dcf0cd51e419f7b24 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/order/complete_lattice.lean | 0dd7476e66d5988be78769b3bbb57a00d6b497c6 | [] | 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 | 52,378 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.order.bounds
import Mathlib.PostPort
universes u_6 l u_1 u_2 u_4 u_5 u_3
namespace Mathlib
/-!
# Theory of complete lattices
## Main definitions
* `Sup` and `Inf` are the supremum and the infimum of a set;
* `supr (f : ι → α)` and `infi (f : ι → α)` are indexed supremum and infimum of a function,
defined as `Sup` and `Inf` of the range of this function;
* `class complete_lattice`: a bounded lattice such that `Sup s` is always the least upper boundary
of `s` and `Inf s` is always the greatest lower boundary of `s`;
* `class complete_linear_order`: a linear ordered complete lattice.
## Naming conventions
We use `Sup`/`Inf`/`supr`/`infi` for the corresponding functions in the statement. Sometimes we
also use `bsupr`/`binfi` for "bounded` supremum or infimum, i.e. one of `⨆ i ∈ s, f i`,
`⨆ i (hi : p i), f i`, or more generally `⨆ i (hi : p i), f i hi`.
## Notation
* `⨆ i, f i` : `supr f`, the supremum of the range of `f`;
* `⨅ i, f i` : `infi f`, the infimum of the range of `f`.
-/
/-- class for the `Sup` operator -/
/-- class for the `Inf` operator -/
class has_Sup (α : Type u_6)
where
Sup : set α → α
class has_Inf (α : Type u_6)
where
Inf : set α → α
/-- Supremum of a set -/
/-- Infimum of a set -/
/-- Indexed supremum -/
/-- Indexed infimum -/
def supr {α : Type u_1} [has_Sup α] {ι : Sort u_2} (s : ι → α) : α :=
Sup (set.range s)
def infi {α : Type u_1} [has_Inf α] {ι : Sort u_2} (s : ι → α) : α :=
Inf (set.range s)
protected instance has_Inf_to_nonempty (α : Type u_1) [has_Inf α] : Nonempty α :=
Nonempty.intro (Inf ∅)
protected instance has_Sup_to_nonempty (α : Type u_1) [has_Sup α] : Nonempty α :=
Nonempty.intro (Sup ∅)
protected instance order_dual.has_Sup (α : Type u_1) [has_Inf α] : has_Sup (order_dual α) :=
has_Sup.mk Inf
protected instance order_dual.has_Inf (α : Type u_1) [has_Sup α] : has_Inf (order_dual α) :=
has_Inf.mk Sup
/-- A complete lattice is a bounded lattice which
has suprema and infima for every subset. -/
class complete_lattice (α : Type u_6)
extends bounded_lattice α, has_Sup α, has_Inf α
where
le_Sup : ∀ (s : set α) (a : α), a ∈ s → a ≤ Sup s
Sup_le : ∀ (s : set α) (a : α), (∀ (b : α), b ∈ s → b ≤ a) → Sup s ≤ a
Inf_le : ∀ (s : set α) (a : α), a ∈ s → Inf s ≤ a
le_Inf : ∀ (s : set α) (a : α), (∀ (b : α), b ∈ s → a ≤ b) → a ≤ Inf s
/-- Create a `complete_lattice` from a `partial_order` and `Inf` function
that returns the greatest lower bound of a set. Usually this constructor provides
poor definitional equalities. If other fields are known explicitly, they should be
provided; for example, if `inf` is known explicitly, construct the `complete_lattice`
instance as
```
instance : complete_lattice my_T :=
{ inf := better_inf,
le_inf := ...,
inf_le_right := ...,
inf_le_left := ...
-- don't care to fix sup, Sup, bot, top
..complete_lattice_of_Inf my_T _ }
```
-/
def complete_lattice_of_Inf (α : Type u_1) [H1 : partial_order α] [H2 : has_Inf α] (is_glb_Inf : ∀ (s : set α), is_glb s (Inf s)) : complete_lattice α :=
complete_lattice.mk (fun (a b : α) => Inf (set_of fun (x : α) => a ≤ x ∧ b ≤ x)) partial_order.le partial_order.lt
partial_order.le_refl partial_order.le_trans partial_order.le_antisymm sorry sorry sorry
(fun (a b : α) => Inf (insert a (singleton b))) sorry sorry sorry (Inf ∅) sorry (Inf set.univ) sorry
(fun (s : set α) => Inf (upper_bounds s)) Inf sorry sorry sorry sorry
/-- Create a `complete_lattice` from a `partial_order` and `Sup` function
that returns the least upper bound of a set. Usually this constructor provides
poor definitional equalities. If other fields are known explicitly, they should be
provided; for example, if `inf` is known explicitly, construct the `complete_lattice`
instance as
```
instance : complete_lattice my_T :=
{ inf := better_inf,
le_inf := ...,
inf_le_right := ...,
inf_le_left := ...
-- don't care to fix sup, Inf, bot, top
..complete_lattice_of_Sup my_T _ }
```
-/
def complete_lattice_of_Sup (α : Type u_1) [H1 : partial_order α] [H2 : has_Sup α] (is_lub_Sup : ∀ (s : set α), is_lub s (Sup s)) : complete_lattice α :=
complete_lattice.mk (fun (a b : α) => Sup (insert a (singleton b))) partial_order.le partial_order.lt
partial_order.le_refl partial_order.le_trans partial_order.le_antisymm sorry sorry sorry
(fun (a b : α) => Sup (set_of fun (x : α) => x ≤ a ∧ x ≤ b)) sorry sorry sorry (Sup set.univ) sorry (Sup ∅) sorry Sup
(fun (s : set α) => Sup (lower_bounds s)) sorry sorry sorry sorry
/-- A complete linear order is a linear order whose lattice structure is complete. -/
class complete_linear_order (α : Type u_6)
extends linear_order α, complete_lattice α
where
namespace order_dual
protected instance complete_lattice (α : Type u_1) [complete_lattice α] : complete_lattice (order_dual α) :=
complete_lattice.mk bounded_lattice.sup bounded_lattice.le bounded_lattice.lt sorry sorry sorry sorry sorry sorry
bounded_lattice.inf sorry sorry sorry bounded_lattice.top sorry bounded_lattice.bot sorry Sup Inf
complete_lattice.Inf_le complete_lattice.le_Inf complete_lattice.le_Sup complete_lattice.Sup_le
protected instance complete_linear_order (α : Type u_1) [complete_linear_order α] : complete_linear_order (order_dual α) :=
complete_linear_order.mk complete_lattice.sup complete_lattice.le complete_lattice.lt sorry sorry sorry sorry sorry
sorry complete_lattice.inf sorry sorry sorry complete_lattice.top sorry complete_lattice.bot sorry
complete_lattice.Sup complete_lattice.Inf sorry sorry sorry sorry sorry linear_order.decidable_le
linear_order.decidable_eq linear_order.decidable_lt
end order_dual
theorem le_Sup {α : Type u_1} [complete_lattice α] {s : set α} {a : α} : a ∈ s → a ≤ Sup s :=
complete_lattice.le_Sup s a
theorem Sup_le {α : Type u_1} [complete_lattice α] {s : set α} {a : α} : (∀ (b : α), b ∈ s → b ≤ a) → Sup s ≤ a :=
complete_lattice.Sup_le s a
theorem Inf_le {α : Type u_1} [complete_lattice α] {s : set α} {a : α} : a ∈ s → Inf s ≤ a :=
complete_lattice.Inf_le s a
theorem le_Inf {α : Type u_1} [complete_lattice α] {s : set α} {a : α} : (∀ (b : α), b ∈ s → a ≤ b) → a ≤ Inf s :=
complete_lattice.le_Inf s a
theorem is_lub_Sup {α : Type u_1} [complete_lattice α] (s : set α) : is_lub s (Sup s) :=
{ left := fun (x : α) => le_Sup, right := fun (x : α) => Sup_le }
theorem is_lub.Sup_eq {α : Type u_1} [complete_lattice α] {s : set α} {a : α} (h : is_lub s a) : Sup s = a :=
is_lub.unique (is_lub_Sup s) h
theorem is_glb_Inf {α : Type u_1} [complete_lattice α] (s : set α) : is_glb s (Inf s) :=
{ left := fun (a : α) => Inf_le, right := fun (a : α) => le_Inf }
theorem is_glb.Inf_eq {α : Type u_1} [complete_lattice α] {s : set α} {a : α} (h : is_glb s a) : Inf s = a :=
is_glb.unique (is_glb_Inf s) h
theorem le_Sup_of_le {α : Type u_1} [complete_lattice α] {s : set α} {a : α} {b : α} (hb : b ∈ s) (h : a ≤ b) : a ≤ Sup s :=
le_trans h (le_Sup hb)
theorem Inf_le_of_le {α : Type u_1} [complete_lattice α] {s : set α} {a : α} {b : α} (hb : b ∈ s) (h : b ≤ a) : Inf s ≤ a :=
le_trans (Inf_le hb) h
theorem Sup_le_Sup {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} (h : s ⊆ t) : Sup s ≤ Sup t :=
is_lub.mono (is_lub_Sup s) (is_lub_Sup t) h
theorem Inf_le_Inf {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} (h : s ⊆ t) : Inf t ≤ Inf s :=
is_glb.mono (is_glb_Inf s) (is_glb_Inf t) h
@[simp] theorem Sup_le_iff {α : Type u_1} [complete_lattice α] {s : set α} {a : α} : Sup s ≤ a ↔ ∀ (b : α), b ∈ s → b ≤ a :=
is_lub_le_iff (is_lub_Sup s)
@[simp] theorem le_Inf_iff {α : Type u_1} [complete_lattice α] {s : set α} {a : α} : a ≤ Inf s ↔ ∀ (b : α), b ∈ s → a ≤ b :=
le_is_glb_iff (is_glb_Inf s)
theorem Sup_le_Sup_of_forall_exists_le {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} (h : ∀ (x : α) (H : x ∈ s), ∃ (y : α), ∃ (H : y ∈ t), x ≤ y) : Sup s ≤ Sup t := sorry
theorem Inf_le_Inf_of_forall_exists_le {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} (h : ∀ (x : α) (H : x ∈ s), ∃ (y : α), ∃ (H : y ∈ t), y ≤ x) : Inf t ≤ Inf s := sorry
theorem Inf_le_Sup {α : Type u_1} [complete_lattice α] {s : set α} (hs : set.nonempty s) : Inf s ≤ Sup s :=
is_glb_le_is_lub (is_glb_Inf s) (is_lub_Sup s) hs
-- TODO: it is weird that we have to add union_def
theorem Sup_union {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} : Sup (s ∪ t) = Sup s ⊔ Sup t :=
is_lub.Sup_eq (is_lub.union (is_lub_Sup s) (is_lub_Sup t))
theorem Sup_inter_le {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} : Sup (s ∩ t) ≤ Sup s ⊓ Sup t := sorry
/-
Sup_le (assume a ⟨a_s, a_t⟩, le_inf (le_Sup a_s) (le_Sup a_t))
-/
theorem Inf_union {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} : Inf (s ∪ t) = Inf s ⊓ Inf t :=
is_glb.Inf_eq (is_glb.union (is_glb_Inf s) (is_glb_Inf t))
theorem le_Inf_inter {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} : Inf s ⊔ Inf t ≤ Inf (s ∩ t) :=
Sup_inter_le
@[simp] theorem Sup_empty {α : Type u_1} [complete_lattice α] : Sup ∅ = ⊥ :=
is_lub.Sup_eq is_lub_empty
@[simp] theorem Inf_empty {α : Type u_1} [complete_lattice α] : Inf ∅ = ⊤ :=
is_glb.Inf_eq is_glb_empty
@[simp] theorem Sup_univ {α : Type u_1} [complete_lattice α] : Sup set.univ = ⊤ :=
is_lub.Sup_eq is_lub_univ
@[simp] theorem Inf_univ {α : Type u_1} [complete_lattice α] : Inf set.univ = ⊥ :=
is_glb.Inf_eq is_glb_univ
-- TODO(Jeremy): get this automatically
@[simp] theorem Sup_insert {α : Type u_1} [complete_lattice α] {a : α} {s : set α} : Sup (insert a s) = a ⊔ Sup s :=
is_lub.Sup_eq (is_lub.insert a (is_lub_Sup s))
@[simp] theorem Inf_insert {α : Type u_1} [complete_lattice α] {a : α} {s : set α} : Inf (insert a s) = a ⊓ Inf s :=
is_glb.Inf_eq (is_glb.insert a (is_glb_Inf s))
theorem Sup_le_Sup_of_subset_instert_bot {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} (h : s ⊆ insert ⊥ t) : Sup s ≤ Sup t :=
le_trans (Sup_le_Sup h) (le_of_eq (trans Sup_insert bot_sup_eq))
theorem Inf_le_Inf_of_subset_insert_top {α : Type u_1} [complete_lattice α] {s : set α} {t : set α} (h : s ⊆ insert ⊤ t) : Inf t ≤ Inf s :=
le_trans (le_of_eq (trans (Eq.symm top_inf_eq) (Eq.symm Inf_insert))) (Inf_le_Inf h)
-- We will generalize this to conditionally complete lattices in `cSup_singleton`.
theorem Sup_singleton {α : Type u_1} [complete_lattice α] {a : α} : Sup (singleton a) = a :=
is_lub.Sup_eq is_lub_singleton
-- We will generalize this to conditionally complete lattices in `cInf_singleton`.
theorem Inf_singleton {α : Type u_1} [complete_lattice α] {a : α} : Inf (singleton a) = a :=
is_glb.Inf_eq is_glb_singleton
theorem Sup_pair {α : Type u_1} [complete_lattice α] {a : α} {b : α} : Sup (insert a (singleton b)) = a ⊔ b :=
is_lub.Sup_eq is_lub_pair
theorem Inf_pair {α : Type u_1} [complete_lattice α] {a : α} {b : α} : Inf (insert a (singleton b)) = a ⊓ b :=
is_glb.Inf_eq is_glb_pair
@[simp] theorem Inf_eq_top {α : Type u_1} [complete_lattice α] {s : set α} : Inf s = ⊤ ↔ ∀ (a : α), a ∈ s → a = ⊤ :=
{ mp := fun (h : Inf s = ⊤) (a : α) (ha : a ∈ s) => top_unique (h ▸ Inf_le ha),
mpr :=
fun (h : ∀ (a : α), a ∈ s → a = ⊤) => top_unique (le_Inf fun (a : α) (ha : a ∈ s) => iff.mpr top_le_iff (h a ha)) }
theorem eq_singleton_top_of_Inf_eq_top_of_nonempty {α : Type u_1} [complete_lattice α] {s : set α} (h_inf : Inf s = ⊤) (hne : set.nonempty s) : s = singleton ⊤ :=
eq.mpr (id (Eq._oldrec (Eq.refl (s = singleton ⊤)) (propext set.eq_singleton_iff_nonempty_unique_mem)))
{ left := hne, right := eq.mp (Eq._oldrec (Eq.refl (Inf s = ⊤)) (propext Inf_eq_top)) h_inf }
@[simp] theorem Sup_eq_bot {α : Type u_1} [complete_lattice α] {s : set α} : Sup s = ⊥ ↔ ∀ (a : α), a ∈ s → a = ⊥ :=
Inf_eq_top
theorem eq_singleton_bot_of_Sup_eq_bot_of_nonempty {α : Type u_1} [complete_lattice α] {s : set α} (h_sup : Sup s = ⊥) (hne : set.nonempty s) : s = singleton ⊥ :=
eq.mpr (id (Eq._oldrec (Eq.refl (s = singleton ⊥)) (propext set.eq_singleton_iff_nonempty_unique_mem)))
{ left := hne, right := eq.mp (Eq._oldrec (Eq.refl (Sup s = ⊥)) (propext Sup_eq_bot)) h_sup }
theorem Inf_lt_iff {α : Type u_1} [complete_linear_order α] {s : set α} {b : α} : Inf s < b ↔ ∃ (a : α), ∃ (H : a ∈ s), a < b :=
is_glb_lt_iff (is_glb_Inf s)
theorem lt_Sup_iff {α : Type u_1} [complete_linear_order α] {s : set α} {b : α} : b < Sup s ↔ ∃ (a : α), ∃ (H : a ∈ s), b < a :=
lt_is_lub_iff (is_lub_Sup s)
theorem Sup_eq_top {α : Type u_1} [complete_linear_order α] {s : set α} : Sup s = ⊤ ↔ ∀ (b : α) (H : b < ⊤), ∃ (a : α), ∃ (H : a ∈ s), b < a := sorry
theorem Inf_eq_bot {α : Type u_1} [complete_linear_order α] {s : set α} : Inf s = ⊥ ↔ ∀ (b : α) (H : b > ⊥), ∃ (a : α), ∃ (H : a ∈ s), a < b :=
Sup_eq_top
theorem lt_supr_iff {α : Type u_1} {ι : Sort u_4} [complete_linear_order α] {a : α} {f : ι → α} : a < supr f ↔ ∃ (i : ι), a < f i :=
iff.trans lt_Sup_iff set.exists_range_iff
theorem infi_lt_iff {α : Type u_1} {ι : Sort u_4} [complete_linear_order α] {a : α} {f : ι → α} : infi f < a ↔ ∃ (i : ι), f i < a :=
iff.trans Inf_lt_iff set.exists_range_iff
/-
### supr & infi
-/
-- TODO: this declaration gives error when starting smt state
--@[ematch]
theorem le_supr {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (s : ι → α) (i : ι) : s i ≤ supr s :=
le_Sup (Exists.intro i rfl)
theorem le_supr' {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (s : ι → α) (i : ι) : s i ≤ supr s :=
le_Sup (Exists.intro i rfl)
/- TODO: this version would be more powerful, but, alas, the pattern matcher
doesn't accept it.
@[ematch] theorem le_supr' (s : ι → α) (i : ι) : (: s i :) ≤ (: supr s :) :=
le_Sup ⟨i, rfl⟩
-/
theorem is_lub_supr {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} : is_lub (set.range s) (supr fun (j : ι) => s j) :=
is_lub_Sup (set.range s)
theorem is_lub.supr_eq {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} (h : is_lub (set.range s) a) : (supr fun (j : ι) => s j) = a :=
is_lub.Sup_eq h
theorem is_glb_infi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} : is_glb (set.range s) (infi fun (j : ι) => s j) :=
is_glb_Inf (set.range s)
theorem is_glb.infi_eq {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} (h : is_glb (set.range s) a) : (infi fun (j : ι) => s j) = a :=
is_glb.Inf_eq h
theorem le_supr_of_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} (i : ι) (h : a ≤ s i) : a ≤ supr s :=
le_trans h (le_supr s i)
theorem le_bsupr {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} (i : ι) (hi : p i) : f i hi ≤ supr fun (i : ι) => supr fun (hi : p i) => f i hi :=
le_supr_of_le i (le_supr (f i) hi)
theorem le_bsupr_of_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {a : α} {p : ι → Prop} {f : (i : ι) → p i → α} (i : ι) (hi : p i) (h : a ≤ f i hi) : a ≤ supr fun (i : ι) => supr fun (hi : p i) => f i hi :=
le_trans h (le_bsupr i hi)
theorem supr_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} (h : ∀ (i : ι), s i ≤ a) : supr s ≤ a := sorry
theorem bsupr_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {a : α} {p : ι → Prop} {f : (i : ι) → p i → α} (h : ∀ (i : ι) (hi : p i), f i hi ≤ a) : (supr fun (i : ι) => supr fun (hi : p i) => f i hi) ≤ a :=
supr_le fun (i : ι) => supr_le (h i)
theorem bsupr_le_supr {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (p : ι → Prop) (f : ι → α) : (supr fun (i : ι) => supr fun (H : p i) => f i) ≤ supr fun (i : ι) => f i :=
bsupr_le fun (i : ι) (hi : p i) => le_supr f i
theorem supr_le_supr {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {t : ι → α} (h : ∀ (i : ι), s i ≤ t i) : supr s ≤ supr t :=
supr_le fun (i : ι) => le_supr_of_le i (h i)
theorem supr_le_supr2 {α : Type u_1} {ι : Sort u_4} {ι₂ : Sort u_5} [complete_lattice α] {s : ι → α} {t : ι₂ → α} (h : ∀ (i : ι), ∃ (j : ι₂), s i ≤ t j) : supr s ≤ supr t :=
supr_le fun (j : ι) => exists.elim (h j) le_supr_of_le
theorem bsupr_le_bsupr {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} {g : (i : ι) → p i → α} (h : ∀ (i : ι) (hi : p i), f i hi ≤ g i hi) : (supr fun (i : ι) => supr fun (hi : p i) => f i hi) ≤ supr fun (i : ι) => supr fun (hi : p i) => g i hi :=
bsupr_le fun (i : ι) (hi : p i) => le_trans (h i hi) (le_bsupr i hi)
theorem supr_le_supr_const {α : Type u_1} {ι : Sort u_4} {ι₂ : Sort u_5} [complete_lattice α] {a : α} (h : ι → ι₂) : (supr fun (i : ι) => a) ≤ supr fun (j : ι₂) => a :=
supr_le ((le_supr fun (j : ι₂) => a) ∘ h)
@[simp] theorem supr_le_iff {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} : supr s ≤ a ↔ ∀ (i : ι), s i ≤ a :=
iff.trans (is_lub_le_iff is_lub_supr) set.forall_range_iff
theorem supr_lt_iff {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} : supr s < a ↔ ∃ (b : α), ∃ (H : b < a), ∀ (i : ι), s i ≤ b := sorry
theorem Sup_eq_supr {α : Type u_1} [complete_lattice α] {s : set α} : Sup s = supr fun (a : α) => supr fun (H : a ∈ s) => a :=
le_antisymm (Sup_le fun (b : α) (h : b ∈ s) => le_supr_of_le b (le_supr (fun (h : b ∈ s) => b) h))
(supr_le fun (b : α) => supr_le fun (h : b ∈ s) => le_Sup h)
theorem le_supr_iff {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} : a ≤ supr s ↔ ∀ (b : α), (∀ (i : ι), s i ≤ b) → a ≤ b :=
{ mp := fun (h : a ≤ supr s) (b : α) (hb : ∀ (i : ι), s i ≤ b) => le_trans h (supr_le hb),
mpr := fun (h : ∀ (b : α), (∀ (i : ι), s i ≤ b) → a ≤ b) => h (supr s) fun (i : ι) => le_supr s i }
theorem monotone.le_map_supr {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] {s : ι → α} [complete_lattice β] {f : α → β} (hf : monotone f) : (supr fun (i : ι) => f (s i)) ≤ f (supr s) :=
supr_le fun (i : ι) => hf (le_supr s i)
theorem monotone.le_map_supr2 {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] [complete_lattice β] {f : α → β} (hf : monotone f) {ι' : ι → Sort u_3} (s : (i : ι) → ι' i → α) : (supr fun (i : ι) => supr fun (h : ι' i) => f (s i h)) ≤ f (supr fun (i : ι) => supr fun (h : ι' i) => s i h) :=
le_trans (supr_le_supr fun (i : ι) => monotone.le_map_supr hf) (monotone.le_map_supr hf)
theorem monotone.le_map_Sup {α : Type u_1} {β : Type u_2} [complete_lattice α] [complete_lattice β] {s : set α} {f : α → β} (hf : monotone f) : (supr fun (a : α) => supr fun (H : a ∈ s) => f a) ≤ f (Sup s) :=
eq.mpr (id (Eq._oldrec (Eq.refl ((supr fun (a : α) => supr fun (H : a ∈ s) => f a) ≤ f (Sup s))) Sup_eq_supr))
(monotone.le_map_supr2 hf fun (a : α) (H : a ∈ s) => a)
theorem supr_comp_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {ι' : Sort u_2} (f : ι' → α) (g : ι → ι') : (supr fun (x : ι) => f (g x)) ≤ supr fun (y : ι') => f y :=
supr_le_supr2 fun (x : ι) => Exists.intro (g x) (le_refl (f (g x)))
theorem monotone.supr_comp_eq {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] [preorder β] {f : β → α} (hf : monotone f) {s : ι → β} (hs : ∀ (x : β), ∃ (i : ι), x ≤ s i) : (supr fun (x : ι) => f (s x)) = supr fun (y : β) => f y :=
le_antisymm (supr_comp_le f fun (x : ι) => s x)
(supr_le_supr2 fun (x : β) => Exists.imp (fun (i : ι) (hi : x ≤ s i) => hf hi) (hs x))
theorem function.surjective.supr_comp {ι : Sort u_4} {ι₂ : Sort u_5} {α : Type u_1} [has_Sup α] {f : ι → ι₂} (hf : function.surjective f) (g : ι₂ → α) : (supr fun (x : ι) => g (f x)) = supr fun (y : ι₂) => g y := sorry
theorem supr_congr {ι : Sort u_4} {ι₂ : Sort u_5} {α : Type u_1} [has_Sup α] {f : ι → α} {g : ι₂ → α} (h : ι → ι₂) (h1 : function.surjective h) (h2 : ∀ (x : ι), g (h x) = f x) : (supr fun (x : ι) => f x) = supr fun (y : ι₂) => g y := sorry
-- TODO: finish doesn't do well here.
theorem supr_congr_Prop {α : Type u_1} [has_Sup α] {p : Prop} {q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ (x : q), f₁ (iff.mpr pq x) = f₂ x) : supr f₁ = supr f₂ :=
eq.mpr (id (Eq._oldrec (Eq.refl (supr f₁ = supr f₂)) (Eq.symm (funext f))))
(Eq.symm
(function.surjective.supr_comp (fun (h : p) => Exists.intro (iff.mp pq h) (Eq.refl (iff.mpr pq (iff.mp pq h)))) f₁))
theorem infi_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (s : ι → α) (i : ι) : infi s ≤ s i :=
Inf_le (Exists.intro i rfl)
theorem infi_le' {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (s : ι → α) (i : ι) : infi s ≤ s i :=
Inf_le (Exists.intro i rfl)
theorem infi_le_of_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} (i : ι) (h : s i ≤ a) : infi s ≤ a :=
le_trans (infi_le s i) h
theorem binfi_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} (i : ι) (hi : p i) : (infi fun (i : ι) => infi fun (hi : p i) => f i hi) ≤ f i hi :=
infi_le_of_le i (infi_le (f i) hi)
theorem binfi_le_of_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {a : α} {p : ι → Prop} {f : (i : ι) → p i → α} (i : ι) (hi : p i) (h : f i hi ≤ a) : (infi fun (i : ι) => infi fun (hi : p i) => f i hi) ≤ a :=
le_trans (binfi_le i hi) h
theorem le_infi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} (h : ∀ (i : ι), a ≤ s i) : a ≤ infi s := sorry
theorem le_binfi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {a : α} {p : ι → Prop} {f : (i : ι) → p i → α} (h : ∀ (i : ι) (hi : p i), a ≤ f i hi) : a ≤ infi fun (i : ι) => infi fun (hi : p i) => f i hi :=
le_infi fun (i : ι) => le_infi (h i)
theorem infi_le_binfi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (p : ι → Prop) (f : ι → α) : (infi fun (i : ι) => f i) ≤ infi fun (i : ι) => infi fun (H : p i) => f i :=
le_binfi fun (i : ι) (hi : p i) => infi_le f i
theorem infi_le_infi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {t : ι → α} (h : ∀ (i : ι), s i ≤ t i) : infi s ≤ infi t :=
le_infi fun (i : ι) => infi_le_of_le i (h i)
theorem infi_le_infi2 {α : Type u_1} {ι : Sort u_4} {ι₂ : Sort u_5} [complete_lattice α] {s : ι → α} {t : ι₂ → α} (h : ∀ (j : ι₂), ∃ (i : ι), s i ≤ t j) : infi s ≤ infi t :=
le_infi fun (j : ι₂) => exists.elim (h j) infi_le_of_le
theorem binfi_le_binfi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} {g : (i : ι) → p i → α} (h : ∀ (i : ι) (hi : p i), f i hi ≤ g i hi) : (infi fun (i : ι) => infi fun (hi : p i) => f i hi) ≤ infi fun (i : ι) => infi fun (hi : p i) => g i hi :=
le_binfi fun (i : ι) (hi : p i) => le_trans (binfi_le i hi) (h i hi)
theorem infi_le_infi_const {α : Type u_1} {ι : Sort u_4} {ι₂ : Sort u_5} [complete_lattice α] {a : α} (h : ι₂ → ι) : (infi fun (i : ι) => a) ≤ infi fun (j : ι₂) => a :=
le_infi ((infi_le fun (i : ι) => a) ∘ h)
@[simp] theorem le_infi_iff {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} {a : α} : a ≤ infi s ↔ ∀ (i : ι), a ≤ s i :=
{ mp := fun (this : a ≤ infi s) (i : ι) => le_trans this (infi_le s i), mpr := le_infi }
theorem Inf_eq_infi {α : Type u_1} [complete_lattice α] {s : set α} : Inf s = infi fun (a : α) => infi fun (H : a ∈ s) => a :=
Sup_eq_supr
theorem monotone.map_infi_le {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] {s : ι → α} [complete_lattice β] {f : α → β} (hf : monotone f) : f (infi s) ≤ infi fun (i : ι) => f (s i) :=
le_infi fun (i : ι) => hf (infi_le s i)
theorem monotone.map_infi2_le {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] [complete_lattice β] {f : α → β} (hf : monotone f) {ι' : ι → Sort u_3} (s : (i : ι) → ι' i → α) : f (infi fun (i : ι) => infi fun (h : ι' i) => s i h) ≤ infi fun (i : ι) => infi fun (h : ι' i) => f (s i h) :=
monotone.le_map_supr2 (monotone.order_dual hf) fun (i : ι) (h : ι' i) => s i h
theorem monotone.map_Inf_le {α : Type u_1} {β : Type u_2} [complete_lattice α] [complete_lattice β] {s : set α} {f : α → β} (hf : monotone f) : f (Inf s) ≤ infi fun (a : α) => infi fun (H : a ∈ s) => f a :=
eq.mpr (id (Eq._oldrec (Eq.refl (f (Inf s) ≤ infi fun (a : α) => infi fun (H : a ∈ s) => f a)) Inf_eq_infi))
(monotone.map_infi2_le hf fun (a : α) (H : a ∈ s) => a)
theorem le_infi_comp {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {ι' : Sort u_2} (f : ι' → α) (g : ι → ι') : (infi fun (y : ι') => f y) ≤ infi fun (x : ι) => f (g x) :=
infi_le_infi2 fun (x : ι) => Exists.intro (g x) (le_refl (f (g x)))
theorem monotone.infi_comp_eq {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] [preorder β] {f : β → α} (hf : monotone f) {s : ι → β} (hs : ∀ (x : β), ∃ (i : ι), s i ≤ x) : (infi fun (x : ι) => f (s x)) = infi fun (y : β) => f y :=
le_antisymm (infi_le_infi2 fun (x : β) => Exists.imp (fun (i : ι) (hi : s i ≤ x) => hf hi) (hs x))
(le_infi_comp (fun (y : β) => f y) fun (x : ι) => s x)
theorem function.surjective.infi_comp {ι : Sort u_4} {ι₂ : Sort u_5} {α : Type u_1} [has_Inf α] {f : ι → ι₂} (hf : function.surjective f) (g : ι₂ → α) : (infi fun (x : ι) => g (f x)) = infi fun (y : ι₂) => g y :=
function.surjective.supr_comp hf g
theorem infi_congr {ι : Sort u_4} {ι₂ : Sort u_5} {α : Type u_1} [has_Inf α] {f : ι → α} {g : ι₂ → α} (h : ι → ι₂) (h1 : function.surjective h) (h2 : ∀ (x : ι), g (h x) = f x) : (infi fun (x : ι) => f x) = infi fun (y : ι₂) => g y :=
supr_congr h h1 h2
theorem infi_congr_Prop {α : Type u_1} [has_Inf α] {p : Prop} {q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ (x : q), f₁ (iff.mpr pq x) = f₂ x) : infi f₁ = infi f₂ :=
supr_congr_Prop pq f
theorem supr_const_le {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {x : α} : (supr fun (h : ι) => x) ≤ x :=
supr_le fun (_x : ι) => le_rfl
theorem le_infi_const {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {x : α} : x ≤ infi fun (h : ι) => x :=
le_infi fun (_x : ι) => le_rfl
-- We will generalize this to conditionally complete lattices in `cinfi_const`.
theorem infi_const {α : Type u_1} {ι : Sort u_4} [complete_lattice α] [Nonempty ι] {a : α} : (infi fun (b : ι) => a) = a :=
eq.mpr (id (Eq._oldrec (Eq.refl ((infi fun (b : ι) => a) = a)) (infi.equations._eqn_1 fun (b : ι) => a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (Inf (set.range fun (b : ι) => a) = a)) set.range_const))
(eq.mpr (id (Eq._oldrec (Eq.refl (Inf (singleton a) = a)) Inf_singleton)) (Eq.refl a)))
-- We will generalize this to conditionally complete lattices in `csupr_const`.
theorem supr_const {α : Type u_1} {ι : Sort u_4} [complete_lattice α] [Nonempty ι] {a : α} : (supr fun (b : ι) => a) = a :=
infi_const
@[simp] theorem infi_top {α : Type u_1} {ι : Sort u_4} [complete_lattice α] : (infi fun (i : ι) => ⊤) = ⊤ :=
top_unique (le_infi fun (i : ι) => le_refl ⊤)
@[simp] theorem supr_bot {α : Type u_1} {ι : Sort u_4} [complete_lattice α] : (supr fun (i : ι) => ⊥) = ⊥ :=
infi_top
@[simp] theorem infi_eq_top {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} : infi s = ⊤ ↔ ∀ (i : ι), s i = ⊤ :=
iff.trans Inf_eq_top set.forall_range_iff
@[simp] theorem supr_eq_bot {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {s : ι → α} : supr s = ⊥ ↔ ∀ (i : ι), s i = ⊥ :=
iff.trans Sup_eq_bot set.forall_range_iff
@[simp] theorem infi_pos {α : Type u_1} [complete_lattice α] {p : Prop} {f : p → α} (hp : p) : (infi fun (h : p) => f h) = f hp :=
le_antisymm (infi_le (fun (h : p) => f h) hp) (le_infi fun (h : p) => le_refl (f hp))
@[simp] theorem infi_neg {α : Type u_1} [complete_lattice α] {p : Prop} {f : p → α} (hp : ¬p) : (infi fun (h : p) => f h) = ⊤ :=
le_antisymm le_top (le_infi fun (h : p) => false.elim (hp h))
@[simp] theorem supr_pos {α : Type u_1} [complete_lattice α] {p : Prop} {f : p → α} (hp : p) : (supr fun (h : p) => f h) = f hp :=
le_antisymm (supr_le fun (h : p) => le_refl (f h)) (le_supr f hp)
@[simp] theorem supr_neg {α : Type u_1} [complete_lattice α] {p : Prop} {f : p → α} (hp : ¬p) : (supr fun (h : p) => f h) = ⊥ :=
le_antisymm (supr_le fun (h : p) => false.elim (hp h)) bot_le
theorem supr_eq_dif {α : Type u_1} [complete_lattice α] {p : Prop} [Decidable p] (a : p → α) : (supr fun (h : p) => a h) = dite p (fun (h : p) => a h) fun (h : ¬p) => ⊥ := sorry
theorem supr_eq_if {α : Type u_1} [complete_lattice α] {p : Prop} [Decidable p] (a : α) : (supr fun (h : p) => a) = ite p a ⊥ :=
supr_eq_dif fun (_x : p) => a
theorem infi_eq_dif {α : Type u_1} [complete_lattice α] {p : Prop} [Decidable p] (a : p → α) : (infi fun (h : p) => a h) = dite p (fun (h : p) => a h) fun (h : ¬p) => ⊤ :=
supr_eq_dif fun (h : p) => a h
theorem infi_eq_if {α : Type u_1} [complete_lattice α] {p : Prop} [Decidable p] (a : α) : (infi fun (h : p) => a) = ite p a ⊤ :=
infi_eq_dif fun (_x : p) => a
-- TODO: should this be @[simp]?
theorem infi_comm {α : Type u_1} {ι : Sort u_4} {ι₂ : Sort u_5} [complete_lattice α] {f : ι → ι₂ → α} : (infi fun (i : ι) => infi fun (j : ι₂) => f i j) = infi fun (j : ι₂) => infi fun (i : ι) => f i j :=
le_antisymm (le_infi fun (i : ι₂) => le_infi fun (j : ι) => infi_le_of_le j (infi_le (fun (j_1 : ι₂) => f j j_1) i))
(le_infi fun (j : ι) => le_infi fun (i : ι₂) => infi_le_of_le i (infi_le (fun (i_1 : ι) => f i_1 i) j))
/- TODO: this is strange. In the proof below, we get exactly the desired
among the equalities, but close does not get it.
begin
apply @le_antisymm,
simp, intros,
begin [smt]
ematch, ematch, ematch, trace_state, have := le_refl (f i_1 i),
trace_state, close
end
end
-/
-- TODO: should this be @[simp]?
theorem supr_comm {α : Type u_1} {ι : Sort u_4} {ι₂ : Sort u_5} [complete_lattice α] {f : ι → ι₂ → α} : (supr fun (i : ι) => supr fun (j : ι₂) => f i j) = supr fun (j : ι₂) => supr fun (i : ι) => f i j :=
infi_comm
@[simp] theorem infi_infi_eq_left {α : Type u_1} {β : Type u_2} [complete_lattice α] {b : β} {f : (x : β) → x = b → α} : (infi fun (x : β) => infi fun (h : x = b) => f x h) = f b rfl := sorry
@[simp] theorem infi_infi_eq_right {α : Type u_1} {β : Type u_2} [complete_lattice α] {b : β} {f : (x : β) → b = x → α} : (infi fun (x : β) => infi fun (h : b = x) => f x h) = f b rfl := sorry
@[simp] theorem supr_supr_eq_left {α : Type u_1} {β : Type u_2} [complete_lattice α] {b : β} {f : (x : β) → x = b → α} : (supr fun (x : β) => supr fun (h : x = b) => f x h) = f b rfl :=
infi_infi_eq_left
@[simp] theorem supr_supr_eq_right {α : Type u_1} {β : Type u_2} [complete_lattice α] {b : β} {f : (x : β) → b = x → α} : (supr fun (x : β) => supr fun (h : b = x) => f x h) = f b rfl :=
infi_infi_eq_right
theorem infi_subtype {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : Subtype p → α} : (infi fun (x : Subtype p) => f x) = infi fun (i : ι) => infi fun (h : p i) => f { val := i, property := h } := sorry
theorem infi_subtype' {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} : (infi fun (i : ι) => infi fun (h : p i) => f i h) = infi fun (x : Subtype p) => f (↑x) (subtype.property x) :=
Eq.symm infi_subtype
theorem infi_subtype'' {α : Type u_1} [complete_lattice α] {ι : Type u_2} (s : set ι) (f : ι → α) : (infi fun (i : ↥s) => f ↑i) = infi fun (t : ι) => infi fun (H : t ∈ s) => f t :=
infi_subtype
theorem infi_inf_eq {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {f : ι → α} {g : ι → α} : (infi fun (x : ι) => f x ⊓ g x) = (infi fun (x : ι) => f x) ⊓ infi fun (x : ι) => g x := sorry
/- TODO: here is another example where more flexible pattern matching
might help.
begin
apply @le_antisymm,
safe, pose h := f a ⊓ g a, begin [smt] ematch, ematch end
end
-/
theorem infi_inf {α : Type u_1} {ι : Sort u_4} [complete_lattice α] [h : Nonempty ι] {f : ι → α} {a : α} : (infi fun (x : ι) => f x) ⊓ a = infi fun (x : ι) => f x ⊓ a := sorry
theorem inf_infi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] [Nonempty ι] {f : ι → α} {a : α} : (a ⊓ infi fun (x : ι) => f x) = infi fun (x : ι) => a ⊓ f x := sorry
theorem binfi_inf {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} {a : α} (h : ∃ (i : ι), p i) : (infi fun (i : ι) => infi fun (h : p i) => f i h) ⊓ a = infi fun (i : ι) => infi fun (h : p i) => f i h ⊓ a := sorry
theorem inf_binfi {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} {a : α} (h : ∃ (i : ι), p i) : (a ⊓ infi fun (i : ι) => infi fun (h : p i) => f i h) = infi fun (i : ι) => infi fun (h : p i) => a ⊓ f i h := sorry
theorem supr_sup_eq {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {g : β → α} : (supr fun (x : β) => f x ⊔ g x) = (supr fun (x : β) => f x) ⊔ supr fun (x : β) => g x :=
infi_inf_eq
theorem supr_sup {α : Type u_1} {ι : Sort u_4} [complete_lattice α] [h : Nonempty ι] {f : ι → α} {a : α} : (supr fun (x : ι) => f x) ⊔ a = supr fun (x : ι) => f x ⊔ a :=
infi_inf
theorem sup_supr {α : Type u_1} {ι : Sort u_4} [complete_lattice α] [Nonempty ι] {f : ι → α} {a : α} : (a ⊔ supr fun (x : ι) => f x) = supr fun (x : ι) => a ⊔ f x :=
inf_infi
/- supr and infi under Prop -/
@[simp] theorem infi_false {α : Type u_1} [complete_lattice α] {s : False → α} : infi s = ⊤ :=
le_antisymm le_top (le_infi fun (i : False) => false.elim i)
@[simp] theorem supr_false {α : Type u_1} [complete_lattice α] {s : False → α} : supr s = ⊥ :=
le_antisymm (supr_le fun (i : False) => false.elim i) bot_le
@[simp] theorem infi_true {α : Type u_1} [complete_lattice α] {s : True → α} : infi s = s trivial :=
le_antisymm (infi_le s trivial)
(le_infi
fun (_x : True) => (fun (_a : True) => true.dcases_on _a (idRhs (s trivial ≤ s trivial) (le_refl (s trivial)))) _x)
@[simp] theorem supr_true {α : Type u_1} [complete_lattice α] {s : True → α} : supr s = s trivial := sorry
@[simp] theorem infi_exists {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : Exists p → α} : (infi fun (x : Exists p) => f x) = infi fun (i : ι) => infi fun (h : p i) => f (Exists.intro i h) := sorry
@[simp] theorem supr_exists {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : Exists p → α} : (supr fun (x : Exists p) => f x) = supr fun (i : ι) => supr fun (h : p i) => f (Exists.intro i h) :=
infi_exists
theorem infi_and {α : Type u_1} [complete_lattice α] {p : Prop} {q : Prop} {s : p ∧ q → α} : infi s = infi fun (h₁ : p) => infi fun (h₂ : q) => s { left := h₁, right := h₂ } := sorry
/-- The symmetric case of `infi_and`, useful for rewriting into a infimum over a conjunction -/
theorem infi_and' {α : Type u_1} [complete_lattice α] {p : Prop} {q : Prop} {s : p → q → α} : (infi fun (h₁ : p) => infi fun (h₂ : q) => s h₁ h₂) = infi fun (h : p ∧ q) => s (and.left h) (and.right h) :=
Eq.symm infi_and
theorem supr_and {α : Type u_1} [complete_lattice α] {p : Prop} {q : Prop} {s : p ∧ q → α} : supr s = supr fun (h₁ : p) => supr fun (h₂ : q) => s { left := h₁, right := h₂ } :=
infi_and
/-- The symmetric case of `supr_and`, useful for rewriting into a supremum over a conjunction -/
theorem supr_and' {α : Type u_1} [complete_lattice α] {p : Prop} {q : Prop} {s : p → q → α} : (supr fun (h₁ : p) => supr fun (h₂ : q) => s h₁ h₂) = supr fun (h : p ∧ q) => s (and.left h) (and.right h) :=
Eq.symm supr_and
theorem infi_or {α : Type u_1} [complete_lattice α] {p : Prop} {q : Prop} {s : p ∨ q → α} : infi s = (infi fun (h : p) => s (Or.inl h)) ⊓ infi fun (h : q) => s (Or.inr h) := sorry
theorem supr_or {α : Type u_1} [complete_lattice α] {p : Prop} {q : Prop} {s : p ∨ q → α} : (supr fun (x : p ∨ q) => s x) = (supr fun (i : p) => s (Or.inl i)) ⊔ supr fun (j : q) => s (Or.inr j) :=
infi_or
theorem Sup_range {ι : Sort u_4} {α : Type u_1} [has_Sup α] {f : ι → α} : Sup (set.range f) = supr f :=
rfl
theorem Inf_range {ι : Sort u_4} {α : Type u_1} [has_Inf α] {f : ι → α} : Inf (set.range f) = infi f :=
rfl
theorem supr_range {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] {g : β → α} {f : ι → β} : (supr fun (b : β) => supr fun (H : b ∈ set.range f) => g b) = supr fun (i : ι) => g (f i) := sorry
theorem infi_range {α : Type u_1} {β : Type u_2} {ι : Sort u_4} [complete_lattice α] {g : β → α} {f : ι → β} : (infi fun (b : β) => infi fun (H : b ∈ set.range f) => g b) = infi fun (i : ι) => g (f i) :=
supr_range
theorem Inf_image {α : Type u_1} {β : Type u_2} [complete_lattice α] {s : set β} {f : β → α} : Inf (f '' s) = infi fun (a : β) => infi fun (H : a ∈ s) => f a := sorry
theorem Sup_image {α : Type u_1} {β : Type u_2} [complete_lattice α] {s : set β} {f : β → α} : Sup (f '' s) = supr fun (a : β) => supr fun (H : a ∈ s) => f a :=
Inf_image
/-
### supr and infi under set constructions
-/
theorem infi_emptyset {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} : (infi fun (x : β) => infi fun (H : x ∈ ∅) => f x) = ⊤ := sorry
theorem supr_emptyset {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} : (supr fun (x : β) => supr fun (H : x ∈ ∅) => f x) = ⊥ := sorry
theorem infi_univ {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} : (infi fun (x : β) => infi fun (H : x ∈ set.univ) => f x) = infi fun (x : β) => f x := sorry
theorem supr_univ {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} : (supr fun (x : β) => supr fun (H : x ∈ set.univ) => f x) = supr fun (x : β) => f x := sorry
theorem infi_union {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {s : set β} {t : set β} : (infi fun (x : β) => infi fun (H : x ∈ s ∪ t) => f x) =
(infi fun (x : β) => infi fun (H : x ∈ s) => f x) ⊓ infi fun (x : β) => infi fun (H : x ∈ t) => f x := sorry
theorem infi_split {α : Type u_1} {β : Type u_2} [complete_lattice α] (f : β → α) (p : β → Prop) : (infi fun (i : β) => f i) =
(infi fun (i : β) => infi fun (h : p i) => f i) ⊓ infi fun (i : β) => infi fun (h : ¬p i) => f i := sorry
theorem infi_split_single {α : Type u_1} {β : Type u_2} [complete_lattice α] (f : β → α) (i₀ : β) : (infi fun (i : β) => f i) = f i₀ ⊓ infi fun (i : β) => infi fun (h : i ≠ i₀) => f i := sorry
theorem infi_le_infi_of_subset {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {s : set β} {t : set β} (h : s ⊆ t) : (infi fun (x : β) => infi fun (H : x ∈ t) => f x) ≤ infi fun (x : β) => infi fun (H : x ∈ s) => f x := sorry
theorem supr_union {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {s : set β} {t : set β} : (supr fun (x : β) => supr fun (H : x ∈ s ∪ t) => f x) =
(supr fun (x : β) => supr fun (H : x ∈ s) => f x) ⊔ supr fun (x : β) => supr fun (H : x ∈ t) => f x :=
infi_union
theorem supr_split {α : Type u_1} {β : Type u_2} [complete_lattice α] (f : β → α) (p : β → Prop) : (supr fun (i : β) => f i) =
(supr fun (i : β) => supr fun (h : p i) => f i) ⊔ supr fun (i : β) => supr fun (h : ¬p i) => f i :=
infi_split (fun (i : β) => f i) fun (i : β) => p i
theorem supr_split_single {α : Type u_1} {β : Type u_2} [complete_lattice α] (f : β → α) (i₀ : β) : (supr fun (i : β) => f i) = f i₀ ⊔ supr fun (i : β) => supr fun (h : i ≠ i₀) => f i :=
infi_split_single (fun (i : β) => f i) i₀
theorem supr_le_supr_of_subset {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {s : set β} {t : set β} (h : s ⊆ t) : (supr fun (x : β) => supr fun (H : x ∈ s) => f x) ≤ supr fun (x : β) => supr fun (H : x ∈ t) => f x :=
infi_le_infi_of_subset h
theorem infi_insert {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {s : set β} {b : β} : (infi fun (x : β) => infi fun (H : x ∈ insert b s) => f x) = f b ⊓ infi fun (x : β) => infi fun (H : x ∈ s) => f x :=
Eq.trans infi_union (congr_arg (fun (x : α) => x ⊓ infi fun (x : β) => infi fun (H : x ∈ s) => f x) infi_infi_eq_left)
theorem supr_insert {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {s : set β} {b : β} : (supr fun (x : β) => supr fun (H : x ∈ insert b s) => f x) = f b ⊔ supr fun (x : β) => supr fun (H : x ∈ s) => f x :=
Eq.trans supr_union (congr_arg (fun (x : α) => x ⊔ supr fun (x : β) => supr fun (H : x ∈ s) => f x) supr_supr_eq_left)
theorem infi_singleton {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {b : β} : (infi fun (x : β) => infi fun (H : x ∈ singleton b) => f x) = f b := sorry
theorem infi_pair {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {a : β} {b : β} : (infi fun (x : β) => infi fun (H : x ∈ insert a (singleton b)) => f x) = f a ⊓ f b := sorry
theorem supr_singleton {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {b : β} : (supr fun (x : β) => supr fun (H : x ∈ singleton b) => f x) = f b :=
infi_singleton
theorem supr_pair {α : Type u_1} {β : Type u_2} [complete_lattice α] {f : β → α} {a : β} {b : β} : (supr fun (x : β) => supr fun (H : x ∈ insert a (singleton b)) => f x) = f a ⊔ f b := sorry
theorem infi_image {α : Type u_1} {β : Type u_2} [complete_lattice α] {γ : Type u_3} {f : β → γ} {g : γ → α} {t : set β} : (infi fun (c : γ) => infi fun (H : c ∈ f '' t) => g c) = infi fun (b : β) => infi fun (H : b ∈ t) => g (f b) := sorry
theorem supr_image {α : Type u_1} {β : Type u_2} [complete_lattice α] {γ : Type u_3} {f : β → γ} {g : γ → α} {t : set β} : (supr fun (c : γ) => supr fun (H : c ∈ f '' t) => g c) = supr fun (b : β) => supr fun (H : b ∈ t) => g (f b) :=
infi_image
/-!
### `supr` and `infi` under `Type`
-/
theorem infi_of_empty' {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (h : ι → False) {s : ι → α} : infi s = ⊤ :=
top_unique (le_infi fun (i : ι) => false.elim (h i))
theorem supr_of_empty' {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (h : ι → False) {s : ι → α} : supr s = ⊥ :=
bot_unique (supr_le fun (i : ι) => false.elim (h i))
theorem infi_of_empty {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (h : ¬Nonempty ι) {s : ι → α} : infi s = ⊤ :=
infi_of_empty' fun (i : ι) => h (Nonempty.intro i)
theorem supr_of_empty {α : Type u_1} {ι : Sort u_4} [complete_lattice α] (h : ¬Nonempty ι) {s : ι → α} : supr s = ⊥ :=
supr_of_empty' fun (i : ι) => h (Nonempty.intro i)
@[simp] theorem infi_empty {α : Type u_1} [complete_lattice α] {s : empty → α} : infi s = ⊤ :=
infi_of_empty nonempty_empty
@[simp] theorem supr_empty {α : Type u_1} [complete_lattice α] {s : empty → α} : supr s = ⊥ :=
supr_of_empty nonempty_empty
theorem supr_bool_eq {α : Type u_1} [complete_lattice α] {f : Bool → α} : (supr fun (b : Bool) => f b) = f tt ⊔ f false := sorry
theorem infi_bool_eq {α : Type u_1} [complete_lattice α] {f : Bool → α} : (infi fun (b : Bool) => f b) = f tt ⊓ f false :=
supr_bool_eq
theorem is_glb_binfi {α : Type u_1} {β : Type u_2} [complete_lattice α] {s : set β} {f : β → α} : is_glb (f '' s) (infi fun (x : β) => infi fun (H : x ∈ s) => f x) := sorry
theorem supr_subtype {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : Subtype p → α} : (supr fun (x : Subtype p) => f x) = supr fun (i : ι) => supr fun (h : p i) => f { val := i, property := h } :=
infi_subtype
theorem supr_subtype' {α : Type u_1} {ι : Sort u_4} [complete_lattice α] {p : ι → Prop} {f : (i : ι) → p i → α} : (supr fun (i : ι) => supr fun (h : p i) => f i h) = supr fun (x : Subtype p) => f (↑x) (subtype.property x) :=
Eq.symm supr_subtype
theorem Sup_eq_supr' {α : Type u_1} [complete_lattice α] {s : set α} : Sup s = supr fun (x : ↥s) => ↑x := sorry
theorem is_lub_bsupr {α : Type u_1} {β : Type u_2} [complete_lattice α] {s : set β} {f : β → α} : is_lub (f '' s) (supr fun (x : β) => supr fun (H : x ∈ s) => f x) := sorry
theorem infi_sigma {α : Type u_1} {β : Type u_2} [complete_lattice α] {p : β → Type u_3} {f : sigma p → α} : (infi fun (x : sigma p) => f x) = infi fun (i : β) => infi fun (h : p i) => f (sigma.mk i h) := sorry
theorem supr_sigma {α : Type u_1} {β : Type u_2} [complete_lattice α] {p : β → Type u_3} {f : sigma p → α} : (supr fun (x : sigma p) => f x) = supr fun (i : β) => supr fun (h : p i) => f (sigma.mk i h) :=
infi_sigma
theorem infi_prod {α : Type u_1} {β : Type u_2} [complete_lattice α] {γ : Type u_3} {f : β × γ → α} : (infi fun (x : β × γ) => f x) = infi fun (i : β) => infi fun (j : γ) => f (i, j) := sorry
theorem supr_prod {α : Type u_1} {β : Type u_2} [complete_lattice α] {γ : Type u_3} {f : β × γ → α} : (supr fun (x : β × γ) => f x) = supr fun (i : β) => supr fun (j : γ) => f (i, j) :=
infi_prod
theorem infi_sum {α : Type u_1} {β : Type u_2} [complete_lattice α] {γ : Type u_3} {f : β ⊕ γ → α} : (infi fun (x : β ⊕ γ) => f x) = (infi fun (i : β) => f (sum.inl i)) ⊓ infi fun (j : γ) => f (sum.inr j) := sorry
theorem supr_sum {α : Type u_1} {β : Type u_2} [complete_lattice α] {γ : Type u_3} {f : β ⊕ γ → α} : (supr fun (x : β ⊕ γ) => f x) = (supr fun (i : β) => f (sum.inl i)) ⊔ supr fun (j : γ) => f (sum.inr j) :=
infi_sum
/-!
### `supr` and `infi` under `ℕ`
-/
theorem supr_ge_eq_supr_nat_add {α : Type u_1} [complete_lattice α] {u : ℕ → α} (n : ℕ) : (supr fun (i : ℕ) => supr fun (H : i ≥ n) => u i) = supr fun (i : ℕ) => u (i + n) := sorry
theorem infi_ge_eq_infi_nat_add {α : Type u_1} [complete_lattice α] {u : ℕ → α} (n : ℕ) : (infi fun (i : ℕ) => infi fun (H : i ≥ n) => u i) = infi fun (i : ℕ) => u (i + n) :=
supr_ge_eq_supr_nat_add n
theorem supr_eq_top {α : Type u_1} {ι : Sort u_4} [complete_linear_order α] (f : ι → α) : supr f = ⊤ ↔ ∀ (b : α), b < ⊤ → ∃ (i : ι), b < f i := sorry
theorem infi_eq_bot {α : Type u_1} {ι : Sort u_4} [complete_linear_order α] (f : ι → α) : infi f = ⊥ ↔ ∀ (b : α), b > ⊥ → ∃ (i : ι), f i < b := sorry
/-!
### Instances
-/
protected instance complete_lattice_Prop : complete_lattice Prop :=
complete_lattice.mk bounded_distrib_lattice.sup bounded_distrib_lattice.le bounded_distrib_lattice.lt sorry sorry sorry
sorry sorry sorry bounded_distrib_lattice.inf sorry sorry sorry bounded_distrib_lattice.top sorry
bounded_distrib_lattice.bot sorry (fun (s : set Prop) => ∃ (a : Prop), ∃ (H : a ∈ s), a)
(fun (s : set Prop) => ∀ (a : Prop), a ∈ s → a) sorry sorry sorry sorry
theorem Inf_Prop_eq {s : set Prop} : Inf s = ∀ (p : Prop), p ∈ s → p :=
rfl
theorem Sup_Prop_eq {s : set Prop} : Sup s = ∃ (p : Prop), ∃ (H : p ∈ s), p :=
rfl
theorem infi_Prop_eq {ι : Sort u_1} {p : ι → Prop} : (infi fun (i : ι) => p i) = ∀ (i : ι), p i := sorry
theorem supr_Prop_eq {ι : Sort u_1} {p : ι → Prop} : (supr fun (i : ι) => p i) = ∃ (i : ι), p i := sorry
protected instance pi.has_Sup {α : Type u_1} {β : α → Type u_2} [(i : α) → has_Sup (β i)] : has_Sup ((i : α) → β i) :=
has_Sup.mk fun (s : set ((i : α) → β i)) (i : α) => supr fun (f : ↥s) => coe f i
protected instance pi.has_Inf {α : Type u_1} {β : α → Type u_2} [(i : α) → has_Inf (β i)] : has_Inf ((i : α) → β i) :=
has_Inf.mk fun (s : set ((i : α) → β i)) (i : α) => infi fun (f : ↥s) => coe f i
protected instance pi.complete_lattice {α : Type u_1} {β : α → Type u_2} [(i : α) → complete_lattice (β i)] : complete_lattice ((i : α) → β i) :=
complete_lattice.mk bounded_lattice.sup bounded_lattice.le bounded_lattice.lt sorry sorry sorry sorry sorry sorry
bounded_lattice.inf sorry sorry sorry bounded_lattice.top sorry bounded_lattice.bot sorry Sup Inf sorry sorry sorry
sorry
theorem Inf_apply {α : Type u_1} {β : α → Type u_2} [(i : α) → has_Inf (β i)] {s : set ((a : α) → β a)} {a : α} : Inf s a = infi fun (f : ↥s) => coe f a :=
rfl
theorem infi_apply {α : Type u_1} {β : α → Type u_2} {ι : Sort u_3} [(i : α) → has_Inf (β i)] {f : ι → (a : α) → β a} {a : α} : infi (fun (i : ι) => f i) a = infi fun (i : ι) => f i a := sorry
theorem Sup_apply {α : Type u_1} {β : α → Type u_2} [(i : α) → has_Sup (β i)] {s : set ((a : α) → β a)} {a : α} : Sup s a = supr fun (f : ↥s) => coe f a :=
rfl
theorem supr_apply {α : Type u_1} {β : α → Type u_2} {ι : Sort u_3} [(i : α) → has_Sup (β i)] {f : ι → (a : α) → β a} {a : α} : supr (fun (i : ι) => f i) a = supr fun (i : ι) => f i a :=
infi_apply
theorem monotone_Sup_of_monotone {α : Type u_1} {β : Type u_2} [preorder α] [complete_lattice β] {s : set (α → β)} (m_s : ∀ (f : α → β), f ∈ s → monotone f) : monotone (Sup s) :=
fun (x y : α) (h : x ≤ y) => supr_le fun (f : ↥s) => le_supr_of_le f (m_s (↑f) (subtype.property f) h)
theorem monotone_Inf_of_monotone {α : Type u_1} {β : Type u_2} [preorder α] [complete_lattice β] {s : set (α → β)} (m_s : ∀ (f : α → β), f ∈ s → monotone f) : monotone (Inf s) :=
fun (x y : α) (h : x ≤ y) => le_infi fun (f : ↥s) => infi_le_of_le f (m_s (↑f) (subtype.property f) h)
namespace prod
protected instance has_Inf (α : Type u_1) (β : Type u_2) [has_Inf α] [has_Inf β] : has_Inf (α × β) :=
has_Inf.mk fun (s : set (α × β)) => (Inf (fst '' s), Inf (snd '' s))
protected instance has_Sup (α : Type u_1) (β : Type u_2) [has_Sup α] [has_Sup β] : has_Sup (α × β) :=
has_Sup.mk fun (s : set (α × β)) => (Sup (fst '' s), Sup (snd '' s))
protected instance complete_lattice (α : Type u_1) (β : Type u_2) [complete_lattice α] [complete_lattice β] : complete_lattice (α × β) :=
complete_lattice.mk bounded_lattice.sup bounded_lattice.le bounded_lattice.lt sorry sorry sorry sorry sorry sorry
bounded_lattice.inf sorry sorry sorry bounded_lattice.top sorry bounded_lattice.bot sorry Sup Inf sorry sorry sorry
sorry
|
771b323bd64eb64aa977adbdf32df4309f7549a2 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/control/lawful_fix.lean | 64df81a2c9ad0e1975001b40f9115d8952dc65f3 | [
"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 | 7,647 | lean | /-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import data.stream.init
import tactic.apply
import control.fix
import order.omega_complete_partial_order
/-!
# Lawful fixed point operators
This module defines the laws required of a `has_fix` instance, using the theory of
omega complete partial orders (ωCPO). Proofs of the lawfulness of all `has_fix` instances in
`control.fix` are provided.
## Main definition
* class `lawful_fix`
-/
universes u v
open_locale classical
variables {α : Type*} {β : α → Type*}
open omega_complete_partial_order
/-- Intuitively, a fixed point operator `fix` is lawful if it satisfies `fix f = f (fix f)` for all
`f`, but this is inconsistent / uninteresting in most cases due to the existence of "exotic"
functions `f`, such as the function that is defined iff its argument is not, familiar from the
halting problem. Instead, this requirement is limited to only functions that are `continuous` in the
sense of `ω`-complete partial orders, which excludes the example because it is not monotone
(making the input argument less defined can make `f` more defined). -/
class lawful_fix (α : Type*) [omega_complete_partial_order α] extends has_fix α :=
(fix_eq : ∀ {f : α →o α}, continuous f → has_fix.fix f = f (has_fix.fix f))
lemma lawful_fix.fix_eq' {α} [omega_complete_partial_order α] [lawful_fix α]
{f : α → α} (hf : continuous' f) :
has_fix.fix f = f (has_fix.fix f) :=
lawful_fix.fix_eq (hf.to_bundled _)
namespace part
open part nat nat.upto
namespace fix
variables (f : (Π a, part $ β a) →o (Π a, part $ β a))
lemma approx_mono' {i : ℕ} : fix.approx f i ≤ fix.approx f (succ i) :=
begin
induction i, dsimp [approx], apply @bot_le _ _ _ (f ⊥),
intro, apply f.monotone, apply i_ih
end
lemma approx_mono ⦃i j : ℕ⦄ (hij : i ≤ j) : approx f i ≤ approx f j :=
begin
induction j with j ih, { cases hij, exact le_rfl },
cases hij, { exact le_rfl },
exact le_trans (ih ‹_›) (approx_mono' f)
end
lemma mem_iff (a : α) (b : β a) : b ∈ part.fix f a ↔ ∃ i, b ∈ approx f i a :=
begin
by_cases h₀ : ∃ (i : ℕ), (approx f i a).dom,
{ simp only [part.fix_def f h₀],
split; intro hh, exact ⟨_,hh⟩,
have h₁ := nat.find_spec h₀,
rw [dom_iff_mem] at h₁,
cases h₁ with y h₁,
replace h₁ := approx_mono' f _ _ h₁,
suffices : y = b, subst this, exact h₁,
cases hh with i hh,
revert h₁, generalize : (succ (nat.find h₀)) = j, intro,
wlog : i ≤ j := le_total i j using [i j b y,j i y b],
replace hh := approx_mono f case _ _ hh,
apply part.mem_unique h₁ hh },
{ simp only [fix_def' ⇑f h₀, not_exists, false_iff, not_mem_none],
simp only [dom_iff_mem, not_exists] at h₀,
intro, apply h₀ }
end
lemma approx_le_fix (i : ℕ) : approx f i ≤ part.fix f :=
assume a b hh,
by { rw [mem_iff f], exact ⟨_,hh⟩ }
lemma exists_fix_le_approx (x : α) : ∃ i, part.fix f x ≤ approx f i x :=
begin
by_cases hh : ∃ i b, b ∈ approx f i x,
{ rcases hh with ⟨i,b,hb⟩, existsi i,
intros b' h',
have hb' := approx_le_fix f i _ _ hb,
obtain rfl := part.mem_unique h' hb',
exact hb },
{ simp only [not_exists] at hh, existsi 0,
intros b' h',
simp only [mem_iff f] at h',
cases h' with i h',
cases hh _ _ h' }
end
include f
/-- The series of approximations of `fix f` (see `approx`) as a `chain` -/
def approx_chain : chain (Π a, part $ β a) := ⟨approx f, approx_mono f⟩
lemma le_f_of_mem_approx {x} : x ∈ approx_chain f → x ≤ f x :=
begin
simp only [(∈), forall_exists_index],
rintro i rfl,
apply approx_mono'
end
lemma approx_mem_approx_chain {i} : approx f i ∈ approx_chain f :=
stream.mem_of_nth_eq rfl
end fix
open fix
variables {α}
variables (f : (Π a, part $ β a) →o (Π a, part $ β a))
open omega_complete_partial_order
open part (hiding ωSup) nat
open nat.upto omega_complete_partial_order
lemma fix_eq_ωSup : part.fix f = ωSup (approx_chain f) :=
begin
apply le_antisymm,
{ intro x, cases exists_fix_le_approx f x with i hx,
transitivity' approx f i.succ x,
{ transitivity', apply hx, apply approx_mono' f },
apply' le_ωSup_of_le i.succ,
dsimp [approx], refl', },
{ apply ωSup_le _ _ _,
simp only [fix.approx_chain, order_hom.coe_fun_mk],
intros y x, apply approx_le_fix f },
end
lemma fix_le {X : Π a, part $ β a} (hX : f X ≤ X) : part.fix f ≤ X :=
begin
rw fix_eq_ωSup f,
apply ωSup_le _ _ _,
simp only [fix.approx_chain, order_hom.coe_fun_mk],
intros i,
induction i, dsimp [fix.approx], apply' bot_le,
transitivity' f X, apply f.monotone i_ih,
apply hX
end
variables {f} (hc : continuous f)
include hc
lemma fix_eq : part.fix f = f (part.fix f) :=
begin
rw [fix_eq_ωSup f,hc],
apply le_antisymm,
{ apply ωSup_le_ωSup_of_le _,
intros i, existsi [i], intro x, -- intros x y hx,
apply le_f_of_mem_approx _ ⟨i, rfl⟩, },
{ apply ωSup_le_ωSup_of_le _,
intros i, existsi i.succ, refl', }
end
end part
namespace part
/-- `to_unit` as a monotone function -/
@[simps]
def to_unit_mono (f : part α →o part α) : (unit → part α) →o (unit → part α) :=
{ to_fun := λ x u, f (x u),
monotone' := λ x y (h : x ≤ y) u, f.monotone $ h u }
lemma to_unit_cont (f : part α →o part α) (hc : continuous f) : continuous (to_unit_mono f)
| c := begin
ext ⟨⟩ : 1,
dsimp [omega_complete_partial_order.ωSup],
erw [hc, chain.map_comp], refl
end
instance : lawful_fix (part α) :=
⟨λ f hc, show part.fix (to_unit_mono f) () = _, by rw part.fix_eq (to_unit_cont f hc); refl⟩
end part
open sigma
namespace pi
instance {β} : lawful_fix (α → part β) := ⟨λ f, part.fix_eq⟩
variables {γ : Π a : α, β a → Type*}
section monotone
variables (α β γ)
/-- `sigma.curry` as a monotone function. -/
@[simps]
def monotone_curry [∀ x y, preorder $ γ x y] :
(Π x : Σ a, β a, γ x.1 x.2) →o (Π a (b : β a), γ a b) :=
{ to_fun := curry,
monotone' := λ x y h a b, h ⟨a,b⟩ }
/-- `sigma.uncurry` as a monotone function. -/
@[simps]
def monotone_uncurry [∀ x y, preorder $ γ x y] :
(Π a (b : β a), γ a b) →o (Π x : Σ a, β a, γ x.1 x.2) :=
{ to_fun := uncurry,
monotone' := λ x y h a, h a.1 a.2 }
variables [∀ x y, omega_complete_partial_order $ γ x y]
open omega_complete_partial_order.chain
lemma continuous_curry : continuous $ monotone_curry α β γ :=
λ c, by { ext x y, dsimp [curry,ωSup], rw [map_comp,map_comp], refl }
lemma continuous_uncurry : continuous $ monotone_uncurry α β γ :=
λ c, by { ext x y, dsimp [uncurry,ωSup], rw [map_comp,map_comp], refl }
end monotone
open has_fix
instance [has_fix $ Π x : sigma β, γ x.1 x.2] : has_fix (Π x (y : β x), γ x y) :=
⟨ λ f, curry (fix $ uncurry ∘ f ∘ curry) ⟩
variables [∀ x y, omega_complete_partial_order $ γ x y]
section curry
variables {f : (Π x (y : β x), γ x y) →o (Π x (y : β x), γ x y)}
variables (hc : continuous f)
lemma uncurry_curry_continuous :
continuous $ (monotone_uncurry α β γ).comp $ f.comp $ monotone_curry α β γ :=
continuous_comp _ _
(continuous_comp _ _ (continuous_curry _ _ _) hc)
(continuous_uncurry _ _ _)
end curry
instance pi.lawful_fix' [lawful_fix $ Π x : sigma β, γ x.1 x.2] : lawful_fix (Π x y, γ x y) :=
{ fix_eq := λ f hc,
begin
dsimp [fix],
conv { to_lhs, erw [lawful_fix.fix_eq (uncurry_curry_continuous hc)] },
refl,
end, }
end pi
|
88fb5d70209851cfdf272e005706a03655ae3091 | bdb33f8b7ea65f7705fc342a178508e2722eb851 | /data/nat/basic.lean | 977621feae3c7a4fb47f2572a040e130cbe020aa | [
"Apache-2.0"
] | permissive | rwbarton/mathlib | 939ae09bf8d6eb1331fc2f7e067d39567e10e33d | c13c5ea701bb1eec057e0a242d9f480a079105e9 | refs/heads/master | 1,584,015,335,862 | 1,524,142,167,000 | 1,524,142,167,000 | 130,614,171 | 0 | 0 | Apache-2.0 | 1,548,902,667,000 | 1,524,437,371,000 | Lean | UTF-8 | Lean | false | false | 19,057 | lean | /-
Copyright (c) 2014 Floris van Doorn. 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
Basic operations on the natural numbers.
-/
import logic.basic algebra.order data.option
universe u
namespace nat
variables {m n k : ℕ}
theorem pred_sub (n m : ℕ) : pred n - m = pred (n - m) :=
by rw [← sub_one, nat.sub_sub, one_add]; refl
theorem pos_iff_ne_zero : n > 0 ↔ n ≠ 0 :=
⟨ne_of_gt, nat.pos_of_ne_zero⟩
theorem pos_iff_ne_zero' : 0 < n ↔ n ≠ 0 := pos_iff_ne_zero
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 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 : n ≥ m) : m + (n - m) = n :=
by rw [add_comm, nat.sub_add_cancel h]
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_min (n m : ℕ) : n - min n m = n - m :=
nat.sub_eq_of_eq_add $ by rw [add_comm, sub_add_min]
protected theorem lt_of_sub_pos (h : n - m > 0) : m < n :=
lt_of_not_ge
(assume : m ≥ n,
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 :=
le_imp_le_iff_lt_imp_lt.1 (λ h, nat.sub_le_sub_right h _)
protected theorem lt_of_sub_lt_sub_left : m - n < m - k → k < n :=
le_imp_le_iff_lt_imp_lt.1 (nat.sub_le_sub_left _)
protected theorem sub_lt_self (h₁ : m > 0) (h₂ : n > 0) : 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_iff_lt_imp_lt.2 nat.lt_sub_right_of_add_lt
protected theorem le_add_of_sub_le_left : n - k ≤ m → n ≤ k + m :=
le_imp_le_iff_lt_imp_lt.2 nat.lt_sub_left_of_add_lt
protected theorem lt_add_of_sub_lt_right : n - k < m → n < m + k :=
le_imp_le_iff_lt_imp_lt.1 nat.le_sub_right_of_add_le
protected theorem lt_add_of_sub_lt_left : n - k < m → n < k + m :=
le_imp_le_iff_lt_imp_lt.1 nat.le_sub_left_of_add_le
protected theorem sub_le_left_of_le_add : n ≤ k + m → n - k ≤ m :=
le_imp_le_iff_lt_imp_lt.2 nat.add_lt_of_lt_sub_left
protected theorem sub_le_right_of_le_add : n ≤ m + k → n - k ≤ m :=
le_imp_le_iff_lt_imp_lt.2 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 (H : m ≤ k) : n < k - m ↔ m + n < k :=
⟨λ h, by have := nat.add_le_add_left h m;
rwa [nat.add_sub_cancel' H] at this,
nat.lt_sub_left_of_add_lt⟩
protected theorem lt_sub_right_iff_add_lt (H : n ≤ k) : m < k - n ↔ m + n < k :=
by rw [nat.lt_sub_left_iff_add_lt H, add_comm]
theorem sub_le_left_iff_le_add (H : n ≤ m) : m - n ≤ k ↔ m ≤ n + k :=
le_iff_le_iff_lt_iff_lt.2 (nat.lt_sub_left_iff_add_lt H)
theorem sub_le_right_iff_le_add (H : k ≤ m) : m - k ≤ n ↔ m ≤ n + k :=
by rw [nat.sub_le_left_iff_le_add H, 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 :=
le_iff_le_iff_lt_iff_lt.1 (nat.sub_le_sub_right_iff _ _ _ H)
protected theorem sub_lt_sub_left_iff (H : n ≤ m) : m - n < m - k ↔ k < n :=
le_iff_le_iff_lt_iff_lt.1 (nat.sub_le_sub_left_iff H)
protected theorem sub_le_iff (h₁ : n ≤ m) (h₂ : k ≤ m) : m - n ≤ k ↔ m - k ≤ n :=
(nat.sub_le_left_iff_le_add h₁).trans (nat.sub_le_right_iff_le_add h₂).symm
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 lt_pred_of_succ_lt {n m : ℕ} : succ n < m → n < pred m :=
@nat.lt_sub_right_of_add_lt n m 1
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
attribute [simp] nat.div_self
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,
(nat.le_div_iff_mul_le _ _ hk).2 $ le_trans (nat.div_mul_le_self _ _) 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 : b > 0) (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 : b > 0) (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_right_inj {a b c : ℕ} (ha : a > 0) : b * a = c * a ↔ b = c :=
⟨nat.eq_of_mul_eq_mul_right ha, λ e, e ▸ rfl⟩
protected theorem mul_left_inj {a b c : ℕ} (ha : a > 0) : a * b = a * c ↔ b = c :=
⟨nat.eq_of_mul_eq_mul_left ha, λ e, e ▸ rfl⟩
@[simp] protected theorem dvd_one {n : ℕ} : n ∣ 1 ↔ n = 1 :=
⟨eq_one_of_dvd_one, λ e, e.symm ▸ dvd_refl _⟩
protected theorem mul_dvd_mul_iff_left {a b c : ℕ} (ha : a > 0) : a * b ∣ a * c ↔ b ∣ c :=
exists_congr $ λ d, by rw [mul_assoc, nat.mul_left_inj ha]
protected theorem mul_dvd_mul_iff_right {a b c : ℕ} (hc : c > 0) : a * c ∣ b * c ↔ a ∣ b :=
exists_congr $ λ d, by rw [mul_right_comm, nat.mul_right_inj hc]
theorem add_pos_left {m : ℕ} (h : m > 0) (n : ℕ) : m + n > 0 :=
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 : n > 0) : m + n > 0 :=
begin rw add_comm, exact add_pos_left h m end
theorem add_pos_iff_pos_or_pos (m n : ℕ) : m + n > 0 ↔ m > 0 ∨ n > 0 :=
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
theorem succ_le_succ_iff {m n : ℕ} : succ m ≤ succ n ↔ m ≤ n :=
⟨le_of_succ_le_succ, succ_le_succ⟩
theorem lt_succ_iff {m n : ℕ} : m < succ n ↔ m ≤ n :=
succ_le_succ_iff
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 le_zero_iff {i : ℕ} : i ≤ 0 ↔ i = 0 :=
⟨nat.eq_zero_of_le_zero, assume h, h ▸ le_refl i⟩
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⟩
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
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
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 _))
/- partial subtraction -/
/-- Partial predecessor operation. Returns `ppred n = some m`
if `n = m + 1`, otherwise `none`. -/
@[simp] def ppred : ℕ → option ℕ
| 0 := none
| (n+1) := some n
/-- Partial subtraction operation. Returns `psub m n = some k`
if `m = n + k`, otherwise `none`. -/
@[simp] def psub (m : ℕ) : ℕ → option ℕ
| 0 := some m
| (n+1) := psub n >>= ppred
theorem pred_eq_ppred (n : ℕ) : pred n = (ppred n).get_or_else 0 :=
by cases n; refl
theorem sub_eq_psub (m : ℕ) : ∀ n, m - n = (psub m n).get_or_else 0
| 0 := rfl
| (n+1) := (pred_eq_ppred (m-n)).trans $
by rw [sub_eq_psub, psub]; cases psub m n; refl
@[simp] theorem ppred_eq_some {m : ℕ} : ∀ {n}, ppred n = some m ↔ succ m = n
| 0 := by split; intro h; contradiction
| (n+1) := by dsimp; split; intro h; injection h; subst n
@[simp] theorem ppred_eq_none : ∀ {n : ℕ}, ppred n = none ↔ n = 0
| 0 := by simp
| (n+1) := by dsimp; split; contradiction
theorem psub_eq_some {m : ℕ} : ∀ {n k}, psub m n = some k ↔ k + n = m
| 0 k := by simp [eq_comm]
| (n+1) k := by dsimp; apply option.bind_eq_some.trans; simp [psub_eq_some]
theorem psub_eq_none (m n : ℕ) : psub m n = none ↔ m < n :=
begin
cases s : psub m n; simp [eq_comm],
{ show m < n, refine lt_of_not_ge (λ h, _),
cases le.dest h with k e,
injection s.symm.trans (psub_eq_some.2 $ (add_comm _ _).trans e) },
{ show n ≤ m, rw ← psub_eq_some.1 s, apply le_add_left }
end
theorem ppred_eq_pred {n} (h : 0 < n) : ppred n = some (pred n) :=
ppred_eq_some.2 $ succ_pred_eq_of_pos h
theorem psub_eq_sub {m n} (h : n ≤ m) : psub m n = some (m - n) :=
psub_eq_some.2 $ nat.sub_add_cancel h
theorem psub_add (m n k) : psub m (n + k) = do x ← psub m n, psub x k :=
by induction k; simp [*, add_succ, bind_assoc]
/- pow -/
theorem pow_add (a m n : ℕ) : a^(m + n) = a^m * a^n :=
by induction n; simp [*, pow_succ, mul_assoc]
theorem pow_dvd_pow (a : ℕ) {m n : ℕ} (h : m ≤ n) : a^m ∣ a^n :=
by rw [← nat.add_sub_cancel' h, pow_add]; apply dvd_mul_right
@[simp] theorem bodd_div2_eq (n : ℕ) : bodd_div2 n = (bodd n, div2 n) :=
by unfold bodd div2; cases bodd_div2 n; refl
/- foldl & foldr -/
/-- `foldl op n a` is the `n`-times iterate of `op` on `a`. -/
@[simp] def foldl {α : Sort*} (op : α → α) : ℕ → α → α
| 0 a := a
| (succ k) a := foldl k (op a)
/-- `foldr op n a` is the `n`-times iterate of `op` on `a`.
It is provably the same as `foldl` but has different
definitional equalities. -/
@[simp] def foldr {α : Sort*} (op : α → α) (a : α) : ℕ → α
| 0 := a
| (succ k) := op (foldr k)
/- size and shift -/
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 _
@[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, refl
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 le_imp_le_iff_lt_imp_lt.1 (λ 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 _)
/- factorial -/
/-- `fact n` is the factorial of `n`. -/
@[simp] def fact : nat → nat
| 0 := 1
| (succ n) := succ n * fact n
@[simp] theorem fact_zero : fact 0 = 1 := rfl
@[simp] theorem fact_one : fact 1 = 1 := rfl
@[simp] theorem fact_succ (n) : fact (succ n) = succ n * fact n := rfl
theorem fact_pos : ∀ n, fact n > 0
| 0 := zero_lt_one
| (succ n) := mul_pos (succ_pos _) (fact_pos n)
theorem fact_ne_zero (n : ℕ) : fact n ≠ 0 := ne_of_gt (fact_pos _)
theorem fact_dvd_fact {m n} (h : m ≤ n) : fact m ∣ fact n :=
begin
induction n with n IH; simp,
{ have := eq_zero_of_le_zero h, subst m, simp },
{ cases eq_or_lt_of_le h with he hl,
{ subst m, simp },
{ apply dvd_mul_of_dvd_right (IH (le_of_lt_succ hl)) } }
end
theorem dvd_fact : ∀ {m n}, m > 0 → m ≤ n → m ∣ fact n
| (succ m) n _ h := dvd_of_mul_right_dvd (fact_dvd_fact h)
theorem fact_le {m n} (h : m ≤ n) : fact m ≤ fact n :=
le_of_dvd (fact_pos _) (fact_dvd_fact h)
end nat
|
3b1e12252ac7bf5590eae8d2d95497667d0b9831 | 6e8de6b43162bef473b4a0bd93b71db886df98ce | /src/pregeom/basis.lean | 0cd9218d023cd42d5b7a85e0a4a23ad63f5beea2 | [
"Unlicense"
] | permissive | adamtopaz/comb_geom | 38ec6fde8d2543f56227ec50cdfb86cac6ac33c1 | e16b629d6de3fbdea54a528755e7305dfb51e902 | refs/heads/master | 1,668,613,552,530 | 1,593,199,940,000 | 1,593,199,940,000 | 269,824,442 | 6 | 0 | Unlicense | 1,593,119,545,000 | 1,591,404,975,000 | Lean | UTF-8 | Lean | false | false | 7,321 | lean | import order.zorn
import tactic
import .basic
import ..helpers
import data.set
open_locale classical
variables {T : Type*} [pregeom T]
namespace pregeom
namespace basis
open has_cl
/--
A set `S` is independent if for all `x ∈ S`, the element `x` is not contained in
`cl (S - {x})`
-/
def is_indep (S : set T) := ∀ {x : T}, x ∈ S → x ∉ cl (S - {x})
/--
A set `S` is spanning if `∀ t : T, t ∈ cl S`.
-/
def is_spanning (S : set T) := ∀ t : T, t ∈ cl S
/-- A basis is a spanning independent set. -/
def is_basis (S : set T) := is_indep S ∧ is_spanning S
/-- If `A` spans, and `A ≤ B`, then `B` spans. -/
@[simp]
lemma super_spans {A B : set T} {spans : is_spanning A} (le : A ≤ B): is_spanning B :=
begin
unfold is_spanning at *,
have mono: cl A ≤ cl B, by exact pregeom.monotone le,
intro t,
replace spans := spans t,
exact mono spans,
end
/-- If `S` is independent and `t ∉ cl S` then `insert t S` is independent. -/
lemma insert_indep {t : T} {S : set T} : is_indep S → t ∉ cl S → is_indep (insert t S) :=
begin
intros h ht,
by_contradiction,
unfold is_indep at a,
rw not_forall at a,
cases a with z hz,
simp only [set.mem_insert_iff, set.not_not_mem, set.sub_eq_diff, classical.not_imp] at hz,
cases hz with h1 h2,
cases h1,
{ rw h1 at *,
suffices : insert t S - {t} ≤ S,
{ replace h2 := monotone this h2,
contradiction, },
tidy, },
{ have : insert t S \ {z} = insert t (S \ {z}), by tidy; finish,
rw this at h2, clear this,
have : z ∉ cl (S \ {z}), by {apply h, tidy, },
have bad := exchange h2 this,
have : insert z (S \ {z}) = S, by tidy; finish,
rw this at bad,
contradiction, }
end
/-- A basis is a maximal independent set. -/
theorem basis_iff_maximal_indep {S : set T} :
is_basis S ↔
is_indep S ∧ (∀ S' : set T, S ≤ S' → is_indep S' → S = S') :=
begin
split,
{ intro h,
refine ⟨h.1,_⟩,
intros S' hle hindep,
suffices : S' ≤ S, by exact le_antisymm hle this,
intros t ht,
cases h with h1 h2,
replace h2 := h2 t,
by_contradiction contra,
have claim1 : S ≤ S' - {t},
{ intros s hs,
refine ⟨hle hs,_⟩,
change s ≠ t,
intro c,
rw c at hs,
contradiction, },
have claim2 : t ∈ cl (S' - {t}), by exact monotone claim1 h2,
replace hindep := hindep ht,
contradiction, },
{ rintros ⟨h1,h2⟩,
refine ⟨by assumption,_⟩,
by_contradiction contra,
have : ∃ t : T, t ∉ cl S,
{ unfold is_spanning at contra,
rw not_forall at contra,
assumption, },
cases this with t ht,
replace h2 := h2 (insert t S),
have : S ≤ insert t S, by finish,
replace h2 := h2 this, clear this,
have : is_indep (insert t S), by apply insert_indep; assumption,
replace h2 := h2 @this,
rw h2 at ht,
have : t ∈ cl (insert t S),
{ apply inclusive,
simp, },
contradiction, }
end
/-- If `S` spans and `t ∈ cl (S - {t})` then `S - {t}` spans as well. -/
lemma subtract_spanning {t : T} {S : set T} : is_spanning S → t ∈ cl (S - {t}) → is_spanning (S - {t}) :=
begin
intros spanning ht,
unfold is_spanning,
intro u,
have sets : {t} ⊆ cl (S - {t}), by simpa,
have pull_in := cl_union_eq sets,
rw ← pull_in,
simp,
have hu : u ∈ cl S, by exact spanning u,
have le : S ≤ insert t S, by
{ intros s hs,
exact set.mem_insert_of_mem t hs, },
apply pregeom.monotone le,
assumption,
end
/-- A basis is a minimal spanning set. -/
theorem basis_iff_minimal_spanning {S : set T} :
is_basis S ↔
is_spanning S ∧ (∀ S' : set T, S' ≤ S → is_spanning S' → S = S') :=
begin
split,
{ intro basis,
refine ⟨ basis.2, _ ⟩,
intros S' le spanning,
tidy,
by_contradiction contra,
have remove : S' ≤ S - {x}, by exact helpers.smaller le contra,
have smaller_spans: is_spanning (S - {x}),
{ apply super_spans remove,
exact spanning, },
have x_seperate: x ∉ cl (S - {x}), by
{ unfold is_indep at basis_left,
replace basis_left := basis_left a,
exact basis_left, },
have x_included: x ∈ cl (S - {x}), by
{ unfold is_spanning at smaller_spans,
replace smaller_spans := smaller_spans x,
exact smaller_spans, },
contradiction, },
{ intro h,
cases h with spans inf,
unfold is_basis,
refine ⟨ _, spans⟩,
unfold is_indep,
intros x hx,
intro contra,
have lt : S - {x} ≤ S, by
{ intros t ht,
finish, },
replace inf := inf (S - {x}) lt,
suffices : is_spanning (S - {x}), by
{ replace inf := inf this,
have problem: ¬ S = S - {x}, by exact helpers.missing_elem S hx,
contradiction, },
exact subtract_spanning spans contra, }
end
-- Ignore these definitions: they are only here to help in some of the proofs.
variable (T)
private def indep_sets := { S : set T // is_indep S }
variable {T}
private def indep_sets_rel : indep_sets T → indep_sets T → Prop := λ A B, A.1 ≤ B.1
private def indep_sets_union (S : set (indep_sets T)) : set T := Sup (subtype.val '' S)
-- This proof takes a while to check! Can it be simplified?
private lemma union_chain_indep {S : set (indep_sets T)} :
zorn.chain indep_sets_rel S → is_indep (indep_sets_union S) :=
begin
intros zorn t ht contra,
rcases finchar contra with ⟨A,hA1,hA2⟩,
suffices claim : ∀ A : finset T, ↑A ≤ indep_sets_union S - {t} →
∃ B : indep_sets T, B ∈ S ∧ t ∈ B.val ∧ ↑A ≤ B.val,
{ replace claim := claim A hA1,
rcases claim with ⟨⟨B,hB⟩,hB1,hB2,hB3⟩,
dsimp at hB2 hB3,
have : ↑A ≤ B - {t},
{ intros a ha,
refine ⟨hB3 ha,_⟩,
dsimp,
change a ≠ t,
replace ha := hA1 ha,
finish, },
replace hA2 := monotone this hA2,
unfold is_indep at hB,
replace hB := hB hB2,
contradiction, },
refine finset.induction _ _,
{ intro,
rcases ht with ⟨B,⟨C,hC1,hC2⟩,h1⟩,
use C,
tidy, },
{ rintros a B ha ind useful,
have : ↑B ≤ indep_sets_union S - {t},
{ intros b hb,
apply useful,
finish, },
replace ind := ind this,
rcases ind with ⟨C,hC1,hC2,hC3⟩,
have : a ∈ indep_sets_union S - {t},
{ apply useful,
simp, },
rcases this with ⟨⟨D,⟨⟨E,hE1,rfl⟩,hE3⟩⟩, h3⟩,
by_cases eq : C = E,
{ rw eq at *,
use E,
refine ⟨hC1,hC2,_⟩,
tidy, },
{ cases @zorn _ hC1 _ hE1 eq,
{ use E, tidy, },
{ use C, tidy, } } }
end
/-- Any pregeometry has a basis. -/
theorem exists_basis : ∃ S : set T, is_basis S :=
begin
have zorn := @zorn.exists_maximal_of_chains_bounded
(indep_sets T)
(λ A B, A.1 ≤ B.1) _ _,
{ rcases zorn with ⟨⟨B,hB1⟩,hB2⟩,
use B,
rw basis_iff_maximal_indep,
refine ⟨@hB1,_⟩,
intros S' h1 h2,
replace hB2 := hB2 ⟨S',@h2⟩ h1,
rw le_antisymm_iff,
exact ⟨h1,hB2⟩, },
{ intro C,
intro hZ,
refine ⟨⟨Sup (subtype.val '' C),_⟩,_⟩,
{ apply union_chain_indep,
assumption, },
{ intros,
dsimp,
cases a with a ha,
dsimp at *,
change a ≤ _,
refine le_Sup _,
tidy, } },
{ tidy, }
end
end basis
end pregeom |
2e27e20964247289ba78a8f39be541bc4ecb8a3d | 48f4f349e1bb919d14ab7e5921d0cfe825f4c423 | /fabstract/Bauer_A_InjBaireNat/toposes.lean | 8979d5e03a42d4677d59b124b932278099f922ff | [] | no_license | thalesant/formalabstracts-2017 | fdf4ff90d30ab1dcb6d4cf16a068a997ea5ecc80 | c47181342c9e41954aa8d41f5049965b5f332bca | refs/heads/master | 1,584,610,453,925 | 1,528,277,508,000 | 1,528,277,508,000 | 136,299,625 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 841 | lean | -- an incomplete definition of toposes
import meta_data
.categories
run_cmd tactic.skip -- temporary fix
unfinished nno_structure : category → Type :=
{ description := "natural numbers object in a category",
sources := [cite.Website "https://ncatlab.org/nlab/show/natural+numbers+object"] }
structure natural_numbers (C : category) :=
(underlying_object : C.obj)
(nno_structure : nno_structure C)
unfinished missing_topos_structure : Type :=
{ description := "the rest of the structure of an elementary topos",
sources := [cite.Website "https://ncatlab.org/nlab/show/topos"] }
structure topos :=
(underlying_category : category)
(nno : natural_numbers underlying_category)
(exponent : Π (A B : underlying_category.obj), exponential A B)
(topos_structure : missing_topos_structure)
|
1cda5e2c7278f7c73c3c5bc4669308ca17d9bd4d | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/data/rat/default.lean | 33d5888eec2c4f0da80ba4c39ebc9c7d2656bff1 | [
"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 | 326 | lean | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import data.rat.basic
import data.rat.order
import data.rat.cast
import data.rat.floor
import data.rat.meta_defs
/-!
# Default Imports to Work With Rational Numbers
-/
|
bb952dd0c8f53c6df7a74d2ba130f15ce177625e | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/geometry/manifold/charted_space.lean | 8e18a77915d6e0b9fe004dab29c9177487332f85 | [
"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 | 43,241 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import topology.local_homeomorph
/-!
# Charted spaces
A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean
half-space for manifolds with boundaries, or an infinite dimensional vector space for more general
notions of manifolds), i.e., the manifold is covered by open subsets on which there are local
homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth
maps.
In this file, we introduce a general framework describing these notions, where the model space is an
arbitrary topological space. We avoid the word *manifold*, which should be reserved for the
situation where the model space is a (subset of a) vector space, and use the terminology
*charted space* instead.
If the changes of charts satisfy some additional property (for instance if they are smooth), then
`M` inherits additional structure (it makes sense to talk about smooth manifolds). There are
therefore two different ingredients in a charted space:
* the set of charts, which is data
* the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop.
We separate these two parts in the definition: the charted space structure is just the set of
charts, and then the different smoothness requirements (smooth manifold, orientable manifold,
contact manifold, and so on) are additional properties of these charts. These properties are
formalized through the notion of structure groupoid, i.e., a set of local homeomorphisms stable
under composition and inverse, to which the change of coordinates should belong.
## Main definitions
* `structure_groupoid H` : a subset of local homeomorphisms of `H` stable under composition,
inverse and restriction (ex: local diffeos).
* `continuous_groupoid H` : the groupoid of all local homeomorphisms of `H`
* `charted_space H M` : charted space structure on `M` modelled on `H`, given by an atlas of
local homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class.
* `has_groupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space
modelled on `H`, require that all coordinate changes belong to `G`. This is a type class.
* `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted
space structure, i.e., the set of charts.
* `G.maximal_atlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a
structure groupoid, one can consider all the local homeomorphisms from `M` to `H` such that
changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the
maximal atlas (for the groupoid `G`).
* `structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for
the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category.
As a basic example, we give the instance
`instance charted_space_model_space (H : Type*) [topological_space H] : charted_space H H`
saying that a topological space is a charted space over itself, with the identity as unique chart.
This charted space structure is compatible with any groupoid.
Additional useful definitions:
* `pregroupoid H` : a subset of local mas of `H` stable under composition and
restriction, but not inverse (ex: smooth maps)
* `groupoid_of_pregroupoid` : construct a groupoid from a pregroupoid, by requiring that a map and
its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps)
* `chart_at H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on
`H`.
* `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition
of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid.
* `G.compatible_of_mem_maximal_atlas he he'` states that, for any two charts `e` and `e'` in the
maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the
`G` if `M` admits `G` as a structure groupoid.
* `charted_space_core.to_charted_space`: consider a space without a topology, but endowed with a set
of charts (which are local equivs) for which the change of coordinates are local homeos. Then
one can construct a topology on the space for which the charts become local homeos, defining
a genuine charted space structure.
## Implementation notes
The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends
on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current
formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas
defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms
between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the
definition is only that, read in charts, the structomorphism locally belongs to the groupoid under
consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas).
A consequence is that the invariance under structomorphisms of properties defined in terms of the
atlas is not obvious in general, and could require some work in theory (amounting to the fact
that these properties only depend on the maximal atlas, for instance). In practice, this does not
create any real difficulty.
We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the
model space is a half space.
Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and
sometimes as spaces with an atlas from which a topology is deduced. We use the former approach:
otherwise, there would be an instance from manifolds to topological spaces, which means that any
instance search for topological spaces would try to find manifold structures involving a yet
unknown model space, leading to problems. However, we also introduce the latter approach,
through a structure `charted_space_core` making it possible to construct a topology out of a set of
local equivs with compatibility conditions (but we do not register it as an instance).
In the definition of a charted space, the model space is written as an explicit parameter as there
can be several model spaces for a given topological space. For instance, a complex manifold
(modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`.
## Notations
In the locale `manifold`, we denote the composition of local homeomorphisms with `≫ₕ`, and the
composition of local equivs with `≫`.
-/
noncomputable theory
open_locale classical
universes u
variables {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*}
/- Notational shortcut for the composition of local homeomorphisms and local equivs, i.e.,
`local_homeomorph.trans` and `local_equiv.trans`.
Note that, as is usual for equivs, the composition is from left to right, hence the direction of
the arrow. -/
localized "infixr ` ≫ₕ `:100 := local_homeomorph.trans" in manifold
localized "infixr ` ≫ `:100 := local_equiv.trans" in manifold
open set local_homeomorph
/-! ### Structure groupoids-/
section groupoid
/-! One could add to the definition of a structure groupoid the fact that the restriction of an
element of the groupoid to any open set still belongs to the groupoid.
(This is in Kobayashi-Nomizu.)
I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is
made of functions respecting the fibers and linear in the fibers (so that a charted space over this
groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always
defined on sets of the form `s × E`. There is a typeclass `closed_under_restriction` for groupoids
which have the restriction property.
The only nontrivial requirement is locality: if a local homeomorphism belongs to the groupoid
around each point in its domain of definition, then it belongs to the groupoid. Without this
requirement, the composition of structomorphisms does not have to be a structomorphism. Note that
this implies that a local homeomorphism with empty source belongs to any structure groupoid, as
it trivially satisfies this condition.
There is also a technical point, related to the fact that a local homeomorphism is by definition a
global map which is a homeomorphism when restricted to its source subset (and its values outside
of the source are not relevant). Therefore, we also require that being a member of the groupoid only
depends on the values on the source.
We use primes in the structure names as we will reformulate them below (without primes) using a
`has_mem` instance, writing `e ∈ G` instead of `e ∈ G.members`.
-/
/-- A structure groupoid is a set of local homeomorphisms of a topological space stable under
composition and inverse. They appear in the definition of the smoothness class of a manifold. -/
structure structure_groupoid (H : Type u) [topological_space H] :=
(members : set (local_homeomorph H H))
(trans' : ∀e e' : local_homeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members)
(symm' : ∀e : local_homeomorph H H, e ∈ members → e.symm ∈ members)
(id_mem' : local_homeomorph.refl H ∈ members)
(locality' : ∀e : local_homeomorph H H, (∀x ∈ e.source, ∃s, is_open s ∧
x ∈ s ∧ e.restr s ∈ members) → e ∈ members)
(eq_on_source' : ∀ e e' : local_homeomorph H H, e ∈ members → e' ≈ e → e' ∈ members)
variable [topological_space H]
instance : has_mem (local_homeomorph H H) (structure_groupoid H) :=
⟨λ(e : local_homeomorph H H) (G : structure_groupoid H), e ∈ G.members⟩
lemma structure_groupoid.trans (G : structure_groupoid H) {e e' : local_homeomorph H H}
(he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G :=
G.trans' e e' he he'
lemma structure_groupoid.symm (G : structure_groupoid H) {e : local_homeomorph H H} (he : e ∈ G) :
e.symm ∈ G :=
G.symm' e he
lemma structure_groupoid.id_mem (G : structure_groupoid H) :
local_homeomorph.refl H ∈ G :=
G.id_mem'
lemma structure_groupoid.locality (G : structure_groupoid H) {e : local_homeomorph H H}
(h : ∀x ∈ e.source, ∃s, is_open s ∧ x ∈ s ∧ e.restr s ∈ G) :
e ∈ G :=
G.locality' e h
lemma structure_groupoid.eq_on_source (G : structure_groupoid H) {e e' : local_homeomorph H H}
(he : e ∈ G) (h : e' ≈ e) : e' ∈ G :=
G.eq_on_source' e e' he h
/-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid -/
instance structure_groupoid.partial_order : partial_order (structure_groupoid H) :=
partial_order.lift structure_groupoid.members
(λa b h, by { cases a, cases b, dsimp at h, induction h, refl })
lemma structure_groupoid.le_iff {G₁ G₂ : structure_groupoid H} :
G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ :=
iff.rfl
/-- The trivial groupoid, containing only the identity (and maps with empty source, as this is
necessary from the definition) -/
def id_groupoid (H : Type u) [topological_space H] : structure_groupoid H :=
{ members := {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅},
trans' := λe e' he he', begin
cases he; simp at he he',
{ simpa only [he, refl_trans]},
{ have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _,
rw he at this,
have : (e ≫ₕ e') ∈ {e : local_homeomorph H H | e.source = ∅} := disjoint_iff.1 this,
exact (mem_union _ _ _).2 (or.inr this) },
end,
symm' := λe he, begin
cases (mem_union _ _ _).1 he with E E,
{ finish },
{ right,
simpa only [e.to_local_equiv.image_source_eq_target.symm] with mfld_simps using E},
end,
id_mem' := mem_union_left _ rfl,
locality' := λe he, begin
cases e.source.eq_empty_or_nonempty with h h,
{ right, exact h },
{ left,
rcases h with ⟨x, hx⟩,
rcases he x hx with ⟨s, open_s, xs, hs⟩,
have x's : x ∈ (e.restr s).source,
{ rw [restr_source, open_s.interior_eq],
exact ⟨hx, xs⟩ },
cases hs,
{ replace hs : local_homeomorph.restr e s = local_homeomorph.refl H,
by simpa only using hs,
have : (e.restr s).source = univ, by { rw hs, simp },
change (e.to_local_equiv).source ∩ interior s = univ at this,
have : univ ⊆ interior s, by { rw ← this, exact inter_subset_right _ _ },
have : s = univ, by rwa [open_s.interior_eq, univ_subset_iff] at this,
simpa only [this, restr_univ] using hs },
{ exfalso,
rw mem_set_of_eq at hs,
rwa hs at x's } },
end,
eq_on_source' := λe e' he he'e, begin
cases he,
{ left,
have : e = e',
{ refine eq_of_eq_on_source_univ (setoid.symm he'e) _ _;
rw set.mem_singleton_iff.1 he ; refl },
rwa ← this },
{ right,
change (e.to_local_equiv).source = ∅ at he,
rwa [set.mem_set_of_eq, he'e.source_eq] }
end }
/-- Every structure groupoid contains the identity groupoid -/
instance : order_bot (structure_groupoid H) :=
{ bot := id_groupoid H,
bot_le := begin
assume u f hf,
change f ∈ {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅} at hf,
simp only [singleton_union, mem_set_of_eq, mem_insert_iff] at hf,
cases hf,
{ rw hf,
apply u.id_mem },
{ apply u.locality,
assume x hx,
rw [hf, mem_empty_eq] at hx,
exact hx.elim }
end,
..structure_groupoid.partial_order }
instance (H : Type u) [topological_space H] : inhabited (structure_groupoid H) :=
⟨id_groupoid H⟩
/-- To construct a groupoid, one may consider classes of local homeos such that both the function
and its inverse have some property. If this property is stable under composition,
one gets a groupoid. `pregroupoid` bundles the properties needed for this construction, with the
groupoid of smooth functions with smooth inverses as an application. -/
structure pregroupoid (H : Type*) [topological_space H] :=
(property : (H → H) → (set H) → Prop)
(comp : ∀{f g u v}, property f u → property g v → is_open u → is_open v → is_open (u ∩ f ⁻¹' v)
→ property (g ∘ f) (u ∩ f ⁻¹' v))
(id_mem : property id univ)
(locality : ∀{f u}, is_open u → (∀x∈u, ∃v, is_open v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u)
(congr : ∀{f g : H → H} {u}, is_open u → (∀x∈u, g x = f x) → property f u → property g u)
/-- Construct a groupoid of local homeos for which the map and its inverse have some property,
from a pregroupoid asserting that this property is stable under composition. -/
def pregroupoid.groupoid (PG : pregroupoid H) : structure_groupoid H :=
{ members := {e : local_homeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target},
trans' := λe e' he he', begin
split,
{ apply PG.comp he.1 he'.1 e.open_source e'.open_source,
apply e.continuous_to_fun.preimage_open_of_open e.open_source e'.open_source },
{ apply PG.comp he'.2 he.2 e'.open_target e.open_target,
apply e'.continuous_inv_fun.preimage_open_of_open e'.open_target e.open_target }
end,
symm' := λe he, ⟨he.2, he.1⟩,
id_mem' := ⟨PG.id_mem, PG.id_mem⟩,
locality' := λe he, begin
split,
{ apply PG.locality e.open_source (λx xu, _),
rcases he x xu with ⟨s, s_open, xs, hs⟩,
refine ⟨s, s_open, xs, _⟩,
convert hs.1,
exact s_open.interior_eq.symm },
{ apply PG.locality e.open_target (λx xu, _),
rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩,
refine ⟨e.target ∩ e.symm ⁻¹' s, _, ⟨xu, xs⟩, _⟩,
{ exact continuous_on.preimage_open_of_open e.continuous_inv_fun e.open_target s_open },
{ rw [← inter_assoc, inter_self],
convert hs.2,
exact s_open.interior_eq.symm } },
end,
eq_on_source' := λe e' he ee', begin
split,
{ apply PG.congr e'.open_source ee'.2,
simp only [ee'.1, he.1] },
{ have A := ee'.symm',
apply PG.congr e'.symm.open_source A.2,
convert he.2,
rw A.1,
refl }
end }
lemma mem_groupoid_of_pregroupoid {PG : pregroupoid H} {e : local_homeomorph H H} :
e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target :=
iff.rfl
lemma groupoid_of_pregroupoid_le (PG₁ PG₂ : pregroupoid H)
(h : ∀f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid :=
begin
refine structure_groupoid.le_iff.2 (λ e he, _),
rw mem_groupoid_of_pregroupoid at he ⊢,
exact ⟨h _ _ he.1, h _ _ he.2⟩
end
lemma mem_pregroupoid_of_eq_on_source (PG : pregroupoid H) {e e' : local_homeomorph H H}
(he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source :=
begin
rw ← he'.1,
exact PG.congr e.open_source he'.eq_on.symm he,
end
/-- The pregroupoid of all local maps on a topological space `H` -/
@[reducible] def continuous_pregroupoid (H : Type*) [topological_space H] : pregroupoid H :=
{ property := λf s, true,
comp := λf g u v hf hg hu hv huv, trivial,
id_mem := trivial,
locality := λf u u_open h, trivial,
congr := λf g u u_open hcongr hf, trivial }
instance (H : Type*) [topological_space H] : inhabited (pregroupoid H) :=
⟨continuous_pregroupoid H⟩
/-- The groupoid of all local homeomorphisms on a topological space `H` -/
def continuous_groupoid (H : Type*) [topological_space H] : structure_groupoid H :=
pregroupoid.groupoid (continuous_pregroupoid H)
/-- Every structure groupoid is contained in the groupoid of all local homeomorphisms -/
instance : order_top (structure_groupoid H) :=
{ top := continuous_groupoid H,
le_top := λ u f hf, by { split; exact dec_trivial },
..structure_groupoid.partial_order }
/-- A groupoid is closed under restriction if it contains all restrictions of its element local
homeomorphisms to open subsets of the source. -/
class closed_under_restriction (G : structure_groupoid H) : Prop :=
(closed_under_restriction : ∀ {e : local_homeomorph H H}, e ∈ G → ∀ (s : set H), is_open s →
e.restr s ∈ G)
lemma closed_under_restriction' {G : structure_groupoid H} [closed_under_restriction G]
{e : local_homeomorph H H} (he : e ∈ G) {s : set H} (hs : is_open s) :
e.restr s ∈ G :=
closed_under_restriction.closed_under_restriction he s hs
/-- The trivial restriction-closed groupoid, containing only local homeomorphisms equivalent to the
restriction of the identity to the various open subsets. -/
def id_restr_groupoid : structure_groupoid H :=
{ members := {e | ∃ {s : set H} (h : is_open s), e ≈ local_homeomorph.of_set s h},
trans' := begin
rintros e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩,
refine ⟨s ∩ s', is_open_inter hs hs', _⟩,
have := local_homeomorph.eq_on_source.trans' hse hse',
rwa local_homeomorph.of_set_trans_of_set at this,
end,
symm' := begin
rintros e ⟨s, hs, hse⟩,
refine ⟨s, hs, _⟩,
rw [← of_set_symm],
exact local_homeomorph.eq_on_source.symm' hse,
end,
id_mem' := ⟨univ, is_open_univ, by simp only with mfld_simps⟩,
locality' := begin
intros e h,
refine ⟨e.source, e.open_source, by simp only with mfld_simps, _⟩,
intros x hx,
rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩,
have hes : x ∈ (e.restr s).source,
{ rw e.restr_source, refine ⟨hx, _⟩,
rw hs.interior_eq, exact hxs },
simpa only with mfld_simps using local_homeomorph.eq_on_source.eq_on hes' hes,
end,
eq_on_source' := begin
rintros e e' ⟨s, hs, hse⟩ hee',
exact ⟨s, hs, setoid.trans hee' hse⟩,
end
}
lemma id_restr_groupoid_mem {s : set H} (hs : is_open s) :
of_set s hs ∈ @id_restr_groupoid H _ := ⟨s, hs, by refl⟩
/-- The trivial restriction-closed groupoid is indeed `closed_under_restriction`. -/
instance closed_under_restriction_id_restr_groupoid :
closed_under_restriction (@id_restr_groupoid H _) :=
⟨ begin
rintros e ⟨s', hs', he⟩ s hs,
use [s' ∩ s, is_open_inter hs' hs],
refine setoid.trans (local_homeomorph.eq_on_source.restr he s) _,
exact ⟨by simp only [hs.interior_eq] with mfld_simps, by simp only with mfld_simps⟩,
end ⟩
/-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed
groupoid. -/
lemma closed_under_restriction_iff_id_le (G : structure_groupoid H) :
closed_under_restriction G ↔ id_restr_groupoid ≤ G :=
begin
split,
{ introsI _i,
apply structure_groupoid.le_iff.mpr,
rintros e ⟨s, hs, hes⟩,
refine G.eq_on_source _ hes,
convert closed_under_restriction' G.id_mem hs,
rw hs.interior_eq,
simp only with mfld_simps },
{ intros h,
split,
intros e he s hs,
rw ← of_set_trans (e : local_homeomorph H H) hs,
refine G.trans _ he,
apply structure_groupoid.le_iff.mp h,
exact id_restr_groupoid_mem hs },
end
/-- The groupoid of all local homeomorphisms on a topological space `H` is closed under restriction.
-/
instance : closed_under_restriction (continuous_groupoid H) :=
(closed_under_restriction_iff_id_le _).mpr (by convert le_top)
end groupoid
/-! ### Charted spaces -/
/-- A charted space is a topological space endowed with an atlas, i.e., a set of local
homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts
cover the whole space. We express the covering property by chosing for each `x` a member
`chart_at H x` of the atlas containing `x` in its source: in the smooth case, this is convenient to
construct the tangent bundle in an efficient way.
The model space is written as an explicit parameter as there can be several model spaces for a
given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen
sometimes as a real manifold over `ℝ^(2n)`.
-/
class charted_space (H : Type*) [topological_space H] (M : Type*) [topological_space M] :=
(atlas [] : set (local_homeomorph M H))
(chart_at [] : M → local_homeomorph M H)
(mem_chart_source [] : ∀x, x ∈ (chart_at x).source)
(chart_mem_atlas [] : ∀x, chart_at x ∈ atlas)
export charted_space
attribute [simp, mfld_simps] mem_chart_source chart_mem_atlas
section charted_space
/-- Any space is a charted_space modelled over itself, by just using the identity chart -/
instance charted_space_self (H : Type*) [topological_space H] : charted_space H H :=
{ atlas := {local_homeomorph.refl H},
chart_at := λx, local_homeomorph.refl H,
mem_chart_source := λx, mem_univ x,
chart_mem_atlas := λx, mem_singleton _ }
/-- In the trivial charted_space structure of a space modelled over itself through the identity, the
atlas members are just the identity -/
@[simp, mfld_simps] lemma charted_space_self_atlas
{H : Type*} [topological_space H] {e : local_homeomorph H H} :
e ∈ atlas H H ↔ e = local_homeomorph.refl H :=
by simp [atlas, charted_space.atlas]
/-- In the model space, chart_at is always the identity -/
@[simp, mfld_simps] lemma chart_at_self_eq {H : Type*} [topological_space H] {x : H} :
chart_at H x = local_homeomorph.refl H :=
by simpa using chart_mem_atlas H x
/-- Same thing as `H × H'`. We introduce it for technical reasons: a charted space `M` with model `H`
is a set of local charts from `M` to `H` covering the space. Every space is registered as a charted
space over itself, using the only chart `id`, in `manifold_model_space`. You can also define a product
of charted space `M` and `M'` (with model space `H × H'`) by taking the products of the charts. Now,
on `H × H'`, there are two charted space structures with model space `H × H'` itself, the one coming
from `manifold_model_space`, and the one coming from the product of the two `manifold_model_space` on
each component. They are equal, but not defeq (because the product of `id` and `id` is not defeq to
`id`), which is bad as we know. This expedient of renaming `H × H'` solves this problem. -/
def model_prod (H : Type*) (H' : Type*) := H × H'
section
local attribute [reducible] model_prod
instance model_prod_inhabited {α β : Type*} [inhabited α] [inhabited β] :
inhabited (model_prod α β) :=
⟨(default α, default β)⟩
instance (H : Type*) [topological_space H] (H' : Type*) [topological_space H'] :
topological_space (model_prod H H') :=
by apply_instance
/- Next lemma shows up often when dealing with derivatives, register it as simp. -/
@[simp, mfld_simps] lemma model_prod_range_prod_id
{H : Type*} {H' : Type*} {α : Type*} (f : H → α) :
range (λ (p : model_prod H H'), (f p.1, p.2)) = set.prod (range f) univ :=
by rw prod_range_univ_eq
end
/-- The product of two charted spaces is naturally a charted space, with the canonical
construction of the atlas of product maps. -/
instance prod_charted_space (H : Type*) [topological_space H]
(M : Type*) [topological_space M] [charted_space H M]
(H' : Type*) [topological_space H']
(M' : Type*) [topological_space M'] [charted_space H' M'] :
charted_space (model_prod H H') (M × M') :=
{ atlas :=
{f : (local_homeomorph (M×M') (model_prod H H')) |
∃ g ∈ charted_space.atlas H M, ∃ h ∈ (charted_space.atlas H' M'),
f = local_homeomorph.prod g h},
chart_at := λ x: (M × M'),
(charted_space.chart_at H x.1).prod (charted_space.chart_at H' x.2),
mem_chart_source :=
begin
intro x,
simp only with mfld_simps,
end,
chart_mem_atlas :=
begin
intro x,
use (charted_space.chart_at H x.1),
split,
{ apply chart_mem_atlas _, },
{ use (charted_space.chart_at H' x.2), simp only [chart_mem_atlas, eq_self_iff_true, and_self], }
end }
section prod_charted_space
variables [topological_space H] [topological_space M] [charted_space H M]
[topological_space H'] [topological_space M'] [charted_space H' M'] {x : M×M'}
@[simp, mfld_simps] lemma prod_charted_space_chart_at :
(chart_at (model_prod H H') x) = (chart_at H x.fst).prod (chart_at H' x.snd) := rfl
end prod_charted_space
end charted_space
/-! ### Constructing a topology from an atlas -/
/-- Sometimes, one may want to construct a charted space structure on a space which does not yet
have a topological structure, where the topology would come from the charts. For this, one needs
charts that are only local equivs, and continuity properties for their composition.
This is formalised in `charted_space_core`. -/
@[nolint has_inhabited_instance]
structure charted_space_core (H : Type*) [topological_space H] (M : Type*) :=
(atlas : set (local_equiv M H))
(chart_at : M → local_equiv M H)
(mem_chart_source : ∀x, x ∈ (chart_at x).source)
(chart_mem_atlas : ∀x, chart_at x ∈ atlas)
(open_source : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas → is_open (e.symm.trans e').source)
(continuous_to_fun : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas →
continuous_on (e.symm.trans e') (e.symm.trans e').source)
namespace charted_space_core
variables [topological_space H] (c : charted_space_core H M) {e : local_equiv M H}
/-- Topology generated by a set of charts on a Type. -/
protected def to_topological_space : topological_space M :=
topological_space.generate_from $ ⋃ (e : local_equiv M H) (he : e ∈ c.atlas)
(s : set H) (s_open : is_open s), {e ⁻¹' s ∩ e.source}
lemma open_source' (he : e ∈ c.atlas) : @is_open M c.to_topological_space e.source :=
begin
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
refine ⟨e, he, univ, is_open_univ, _⟩,
simp only [set.univ_inter, set.preimage_univ]
end
lemma open_target (he : e ∈ c.atlas) : is_open e.target :=
begin
have E : e.target ∩ e.symm ⁻¹' e.source = e.target :=
subset.antisymm (inter_subset_left _ _) (λx hx, ⟨hx,
local_equiv.target_subset_preimage_source _ hx⟩),
simpa [local_equiv.trans_source, E] using c.open_source e e he he
end
/-- An element of the atlas in a charted space without topology becomes a local homeomorphism
for the topology constructed from this atlas. The `local_homeomorph` version is given in this
definition. -/
def local_homeomorph (e : local_equiv M H) (he : e ∈ c.atlas) :
@local_homeomorph M H c.to_topological_space _ :=
{ open_source := by convert c.open_source' he,
open_target := by convert c.open_target he,
continuous_to_fun := begin
letI : topological_space M := c.to_topological_space,
rw continuous_on_open_iff (c.open_source' he),
assume s s_open,
rw inter_comm,
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
exact ⟨e, he, ⟨s, s_open, rfl⟩⟩
end,
continuous_inv_fun := begin
letI : topological_space M := c.to_topological_space,
apply continuous_on_open_of_generate_from (c.open_target he),
assume t ht,
simp only [exists_prop, mem_Union, mem_singleton_iff] at ht,
rcases ht with ⟨e', e'_atlas, s, s_open, ts⟩,
rw ts,
let f := e.symm.trans e',
have : is_open (f ⁻¹' s ∩ f.source),
by simpa [inter_comm] using (continuous_on_open_iff (c.open_source e e' he e'_atlas)).1
(c.continuous_to_fun e e' he e'_atlas) s s_open,
have A : e' ∘ e.symm ⁻¹' s ∩ (e.target ∩ e.symm ⁻¹' e'.source) =
e.target ∩ (e' ∘ e.symm ⁻¹' s ∩ e.symm ⁻¹' e'.source),
by { rw [← inter_assoc, ← inter_assoc], congr' 1, exact inter_comm _ _ },
simpa [local_equiv.trans_source, preimage_inter, preimage_comp.symm, A] using this
end,
..e }
/-- Given a charted space without topology, endow it with a genuine charted space structure with
respect to the topology constructed from the atlas. -/
def to_charted_space : @charted_space H _ M c.to_topological_space :=
{ atlas := ⋃ (e : local_equiv M H) (he : e ∈ c.atlas), {c.local_homeomorph e he},
chart_at := λx, c.local_homeomorph (c.chart_at x) (c.chart_mem_atlas x),
mem_chart_source := λx, c.mem_chart_source x,
chart_mem_atlas := λx, begin
simp only [mem_Union, mem_singleton_iff],
exact ⟨c.chart_at x, c.chart_mem_atlas x, rfl⟩,
end }
end charted_space_core
/-! ### Charted space with a given structure groupoid -/
section has_groupoid
variables [topological_space H] [topological_space M] [charted_space H M]
section
set_option old_structure_cmd true
/-- A charted space has an atlas in a groupoid `G` if the change of coordinates belong to the
groupoid -/
class has_groupoid {H : Type*} [topological_space H] (M : Type*) [topological_space M]
[charted_space H M] (G : structure_groupoid H) : Prop :=
(compatible [] : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M → e.symm ≫ₕ e' ∈ G)
end
/-- Reformulate in the `structure_groupoid` namespace the compatibility condition of charts in a
charted space admitting a structure groupoid, to make it more easily accessible with dot
notation. -/
lemma structure_groupoid.compatible {H : Type*} [topological_space H] (G : structure_groupoid H)
{M : Type*} [topological_space M] [charted_space H M] [has_groupoid M G]
{e e' : local_homeomorph M H} (he : e ∈ atlas H M) (he' : e' ∈ atlas H M) :
e.symm ≫ₕ e' ∈ G :=
has_groupoid.compatible G he he'
lemma has_groupoid_of_le {G₁ G₂ : structure_groupoid H} (h : has_groupoid M G₁) (hle : G₁ ≤ G₂) :
has_groupoid M G₂ :=
⟨ λ e e' he he', hle ((h.compatible : _) he he') ⟩
lemma has_groupoid_of_pregroupoid (PG : pregroupoid H)
(h : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M
→ PG.property (e.symm ≫ₕ e') (e.symm ≫ₕ e').source) :
has_groupoid M (PG.groupoid) :=
⟨assume e e' he he', mem_groupoid_of_pregroupoid.mpr ⟨h he he', h he' he⟩⟩
/-- The trivial charted space structure on the model space is compatible with any groupoid -/
instance has_groupoid_model_space (H : Type*) [topological_space H] (G : structure_groupoid H) :
has_groupoid H G :=
{ compatible := λe e' he he', begin
replace he : e ∈ atlas H H := he,
replace he' : e' ∈ atlas H H := he',
rw charted_space_self_atlas at he he',
simp [he, he', structure_groupoid.id_mem]
end }
/-- Any charted space structure is compatible with the groupoid of all local homeomorphisms -/
instance has_groupoid_continuous_groupoid : has_groupoid M (continuous_groupoid H) :=
⟨begin
assume e e' he he',
rw [continuous_groupoid, mem_groupoid_of_pregroupoid],
simp only [and_self]
end⟩
section maximal_atlas
variables (M) (G : structure_groupoid H)
/-- Given a charted space admitting a structure groupoid, the maximal atlas associated to this
structure groupoid is the set of all local charts that are compatible with the atlas, i.e., such
that changing coordinates with an atlas member gives an element of the groupoid. -/
def structure_groupoid.maximal_atlas : set (local_homeomorph M H) :=
{e | ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G}
variable {M}
/-- The elements of the atlas belong to the maximal atlas for any structure groupoid -/
lemma structure_groupoid.mem_maximal_atlas_of_mem_atlas [has_groupoid M G]
{e : local_homeomorph M H} (he : e ∈ atlas H M) : e ∈ G.maximal_atlas M :=
λ e' he', ⟨G.compatible he he', G.compatible he' he⟩
lemma structure_groupoid.chart_mem_maximal_atlas [has_groupoid M G]
(x : M) : chart_at H x ∈ G.maximal_atlas M :=
G.mem_maximal_atlas_of_mem_atlas (chart_mem_atlas H x)
variable {G}
lemma mem_maximal_atlas_iff {e : local_homeomorph M H} :
e ∈ G.maximal_atlas M ↔ ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G :=
iff.rfl
/-- Changing coordinates between two elements of the maximal atlas gives rise to an element
of the structure groupoid. -/
lemma structure_groupoid.compatible_of_mem_maximal_atlas {e e' : local_homeomorph M H}
(he : e ∈ G.maximal_atlas M) (he' : e' ∈ G.maximal_atlas M) : e.symm ≫ₕ e' ∈ G :=
begin
apply G.locality (λ x hx, _),
set f := chart_at H (e.symm x) with hf,
let s := e.target ∩ (e.symm ⁻¹' f.source),
have hs : is_open s,
{ apply e.symm.continuous_to_fun.preimage_open_of_open; apply open_source },
have xs : x ∈ s, by { dsimp at hx, simp [s, hx] },
refine ⟨s, hs, xs, _⟩,
have A : e.symm ≫ₕ f ∈ G := (mem_maximal_atlas_iff.1 he f (chart_mem_atlas _ _)).1,
have B : f.symm ≫ₕ e' ∈ G := (mem_maximal_atlas_iff.1 he' f (chart_mem_atlas _ _)).2,
have C : (e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') ∈ G := G.trans A B,
have D : (e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') ≈ (e.symm ≫ₕ e').restr s := calc
(e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') = e.symm ≫ₕ (f ≫ₕ f.symm) ≫ₕ e' : by simp [trans_assoc]
... ≈ e.symm ≫ₕ (of_set f.source f.open_source) ≫ₕ e' :
by simp [eq_on_source.trans', trans_self_symm]
... ≈ (e.symm ≫ₕ (of_set f.source f.open_source)) ≫ₕ e' : by simp [trans_assoc]
... ≈ (e.symm.restr s) ≫ₕ e' : by simp [s, trans_of_set']
... ≈ (e.symm ≫ₕ e').restr s : by simp [restr_trans],
exact G.eq_on_source C (setoid.symm D),
end
variable (G)
/-- In the model space, the identity is in any maximal atlas. -/
lemma structure_groupoid.id_mem_maximal_atlas : local_homeomorph.refl H ∈ G.maximal_atlas H :=
G.mem_maximal_atlas_of_mem_atlas (by simp)
end maximal_atlas
section singleton
variables {α : Type*} [topological_space α]
variables (e : local_homeomorph α H)
/-- If a single local homeomorphism `e` from a space `α` into `H` has source covering the whole
space `α`, then that local homeomorphism induces an `H`-charted space structure on `α`.
(This condition is equivalent to `e` being an open embedding of `α` into `H`; see
`local_homeomorph.to_open_embedding` and `open_embedding.to_local_homeomorph`.) -/
def singleton_charted_space (h : e.source = set.univ) : charted_space H α :=
{ atlas := {e},
chart_at := λ _, e,
mem_chart_source := λ _, by simp only [h] with mfld_simps,
chart_mem_atlas := λ _, by tauto }
lemma singleton_charted_space_one_chart (h : e.source = set.univ) (e' : local_homeomorph α H)
(h' : e' ∈ (singleton_charted_space e h).atlas) : e' = e := h'
/-- Given a local homeomorphism `e` from a space `α` into `H`, if its source covers the whole
space `α`, then the induced charted space structure on `α` is `has_groupoid G` for any structure
groupoid `G` which is closed under restrictions. -/
lemma singleton_has_groupoid (h : e.source = set.univ) (G : structure_groupoid H)
[closed_under_restriction G] : @has_groupoid _ _ _ _ (singleton_charted_space e h) G :=
{ compatible := begin
intros e' e'' he' he'',
rw singleton_charted_space_one_chart e h e' he',
rw singleton_charted_space_one_chart e h e'' he'',
refine G.eq_on_source _ e.trans_symm_self,
have hle : id_restr_groupoid ≤ G := (closed_under_restriction_iff_id_le G).mp (by assumption),
exact structure_groupoid.le_iff.mp hle _ (id_restr_groupoid_mem _),
end }
end singleton
namespace topological_space.opens
open topological_space
variables (G : structure_groupoid H) [has_groupoid M G]
variables (s : opens M)
/-- An open subset of a charted space is naturally a charted space. -/
instance : charted_space H s :=
{ atlas := ⋃ (x : s), {@local_homeomorph.subtype_restr _ _ _ _ (chart_at H x.1) s ⟨x⟩},
chart_at := λ x, @local_homeomorph.subtype_restr _ _ _ _ (chart_at H x.1) s ⟨x⟩,
mem_chart_source := λ x, by { simp only with mfld_simps, exact (mem_chart_source H x.1) },
chart_mem_atlas := λ x, by { simp only [mem_Union, mem_singleton_iff], use x } }
/-- If a groupoid `G` is `closed_under_restriction`, then an open subset of a space which is
`has_groupoid G` is naturally `has_groupoid G`. -/
instance [closed_under_restriction G] : has_groupoid s G :=
{ compatible := begin
rintros e e' ⟨_, ⟨x, hc⟩, he⟩ ⟨_, ⟨x', hc'⟩, he'⟩,
haveI : nonempty s := ⟨x⟩,
simp only [hc.symm, mem_singleton_iff, subtype.val_eq_coe] at he,
simp only [hc'.symm, mem_singleton_iff, subtype.val_eq_coe] at he',
rw [he, he'],
convert G.eq_on_source _ (subtype_restr_symm_trans_subtype_restr s (chart_at H x) (chart_at H x')),
apply closed_under_restriction',
{ exact G.compatible (chart_mem_atlas H x) (chart_mem_atlas H x') },
{ exact preimage_open_of_open_symm (chart_at H x) s.2 },
end }
end topological_space.opens
/-! ### Structomorphisms -/
/-- A `G`-diffeomorphism between two charted spaces is a homeomorphism which, when read in the
charts, belongs to `G`. We avoid the word diffeomorph as it is too related to the smooth category,
and use structomorph instead. -/
@[nolint has_inhabited_instance]
structure structomorph (G : structure_groupoid H) (M : Type*) (M' : Type*)
[topological_space M] [topological_space M'] [charted_space H M] [charted_space H M']
extends homeomorph M M' :=
(mem_groupoid : ∀c : local_homeomorph M H, ∀c' : local_homeomorph M' H,
c ∈ atlas H M → c' ∈ atlas H M' → c.symm ≫ₕ to_homeomorph.to_local_homeomorph ≫ₕ c' ∈ G)
variables [topological_space M'] [topological_space M'']
{G : structure_groupoid H} [charted_space H M'] [charted_space H M'']
/-- The identity is a diffeomorphism of any charted space, for any groupoid. -/
def structomorph.refl (M : Type*) [topological_space M] [charted_space H M]
[has_groupoid M G] : structomorph G M M :=
{ mem_groupoid := λc c' hc hc', begin
change (local_homeomorph.symm c) ≫ₕ (local_homeomorph.refl M) ≫ₕ c' ∈ G,
rw local_homeomorph.refl_trans,
exact has_groupoid.compatible G hc hc'
end,
..homeomorph.refl M }
/-- The inverse of a structomorphism is a structomorphism -/
def structomorph.symm (e : structomorph G M M') : structomorph G M' M :=
{ mem_groupoid := begin
assume c c' hc hc',
have : (c'.symm ≫ₕ e.to_homeomorph.to_local_homeomorph ≫ₕ c).symm ∈ G :=
G.symm (e.mem_groupoid c' c hc' hc),
rwa [trans_symm_eq_symm_trans_symm, trans_symm_eq_symm_trans_symm, symm_symm, trans_assoc]
at this,
end,
..e.to_homeomorph.symm}
/-- The composition of structomorphisms is a structomorphism -/
def structomorph.trans (e : structomorph G M M') (e' : structomorph G M' M'') : structomorph G M M'' :=
{ mem_groupoid := begin
/- Let c and c' be two charts in M and M''. We want to show that e' ∘ e is smooth in these
charts, around any point x. For this, let y = e (c⁻¹ x), and consider a chart g around y.
Then g ∘ e ∘ c⁻¹ and c' ∘ e' ∘ g⁻¹ are both smooth as e and e' are structomorphisms, so
their composition is smooth, and it coincides with c' ∘ e' ∘ e ∘ c⁻¹ around x. -/
assume c c' hc hc',
refine G.locality (λx hx, _),
let f₁ := e.to_homeomorph.to_local_homeomorph,
let f₂ := e'.to_homeomorph.to_local_homeomorph,
let f := (e.to_homeomorph.trans e'.to_homeomorph).to_local_homeomorph,
have feq : f = f₁ ≫ₕ f₂ := homeomorph.trans_to_local_homeomorph _ _,
-- define the atlas g around y
let y := (c.symm ≫ₕ f₁) x,
let g := chart_at H y,
have hg₁ := chart_mem_atlas H y,
have hg₂ := mem_chart_source H y,
let s := (c.symm ≫ₕ f₁).source ∩ (c.symm ≫ₕ f₁) ⁻¹' g.source,
have open_s : is_open s,
by apply (c.symm ≫ₕ f₁).continuous_to_fun.preimage_open_of_open; apply open_source,
have : x ∈ s,
{ split,
{ simp only [trans_source, preimage_univ, inter_univ, homeomorph.to_local_homeomorph_source],
rw trans_source at hx,
exact hx.1 },
{ exact hg₂ } },
refine ⟨s, open_s, this, _⟩,
let F₁ := (c.symm ≫ₕ f₁ ≫ₕ g) ≫ₕ (g.symm ≫ₕ f₂ ≫ₕ c'),
have A : F₁ ∈ G := G.trans (e.mem_groupoid c g hc hg₁) (e'.mem_groupoid g c' hg₁ hc'),
let F₂ := (c.symm ≫ₕ f ≫ₕ c').restr s,
have : F₁ ≈ F₂ := calc
F₁ ≈ c.symm ≫ₕ f₁ ≫ₕ (g ≫ₕ g.symm) ≫ₕ f₂ ≫ₕ c' : by simp [F₁, trans_assoc]
... ≈ c.symm ≫ₕ f₁ ≫ₕ (of_set g.source g.open_source) ≫ₕ f₂ ≫ₕ c' :
by simp [eq_on_source.trans', trans_self_symm g]
... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (of_set g.source g.open_source)) ≫ₕ (f₂ ≫ₕ c') :
by simp [trans_assoc]
... ≈ ((c.symm ≫ₕ f₁).restr s) ≫ₕ (f₂ ≫ₕ c') : by simp [s, trans_of_set']
... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (f₂ ≫ₕ c')).restr s : by simp [restr_trans]
... ≈ (c.symm ≫ₕ (f₁ ≫ₕ f₂) ≫ₕ c').restr s : by simp [eq_on_source.restr, trans_assoc]
... ≈ F₂ : by simp [F₂, feq],
have : F₂ ∈ G := G.eq_on_source A (setoid.symm this),
exact this
end,
..homeomorph.trans e.to_homeomorph e'.to_homeomorph }
end has_groupoid
|
428200340ddffa7b54d1a2fb1ba44d0bcef48f51 | 01ae0d022f2e2fefdaaa898938c1ac1fbce3b3ab | /categories/adjunctions/examples/functor_categories.lean | 619d5238da8b746cb8519e24a0760a364e663a89 | [] | 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 | 854 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import ...adjunctions
open categories
open categories.functor
open categories.natural_transformation
open categories.products
open categories.isomorphism
open categories.types
open categories.functor_categories
namespace categories.adjunctions
-- EXERCISE an adjunction F ⊢ G gives an adjunction F^* ⊢ G^*
-- cf Leinster 2.2.14
-- definition pullback_adjunction { C D : Category } { L : Functor C D } { R : Functor D C } ( A : Adjunction L R ) ( E : Category )
-- : Adjunction (whisker_on_left_functor E L) (whisker_on_left_functor E R) := {
-- unit := sorry,
-- counit := sorry,
-- triangle_1 := sorry,
-- triangle_2 := sorry
-- }
end categories.adjunctions |
700c87ea17d17787b3ed25d9d833249e808b6eca | dcf093fda1f51c094394c50e182cfb9dec39635a | /wlog.lean | 06a06370a68a118c7e20c6660843e355d1f5bb5b | [] | no_license | dselsam/cs103 | 7ac496d0293befca95d3045add91c5270a5d291f | 31ab9784a6f65f226efb702a0da52f907c616a71 | refs/heads/master | 1,611,092,644,140 | 1,492,571,015,000 | 1,492,571,015,000 | 88,693,969 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,695 | lean | import data.nat data.set
open nat set
variable {T : Type}
/-
Lemma 2: A Δ B ⊆ (A ∪ B) – (A ∩ B)
Proof of Lemma 2: We will show that for any x ∈ A Δ B, x ∈ (A ∪ B) – (A ∩ B). Consider any
x ∈ A Δ B. Then either x ∈ A and x ∉ B, or x ∈ B and x ∉ A. Assume without loss of generality that
x ∈ A and x ∉ B. Since x ∈ A, x ∈ A ∪ B. Since x ∉ B, x ∉ A ∩ B, so x ∈ (A ∪ B) – (A ∩ B). Since our
choice of x was arbitrary, we have that A Δ B ⊆ (A ∪ B) – (A ∩ B). ■
-/
definition set_minus [reducible] (A B : set T) :=
λ x, x ∈ A ∧ ¬ x ∈ B
notation a - b := set_minus a b
example : ∀ (A B : set T) (x : T), (x ∈ A ∧ x ∉ B) ∨ (x ∈ B ∧ x ∉ A) → x ∈ A ∪ B - A ∩ B := sorry
/-
Theorem: If m and n have opposite parity, m + n is odd
Proof: Without loss of generality, assume that m is odd and n is even. Since m is odd, there exists an
integer r such that m = 2r + 1. Since n is even, there exists an integer s such that n = 2s. Then
m + n = 2r + 1 + 2s = 2(r + s) + 1. Consequently, m + n is odd. ■
-/
definition even (x : nat) := ∃ k, x = 2 * k.
definition odd (x : nat) := ∃ k, x = 2 * k + 1.
example : ∀ (m n : nat), (odd m ∧ even n) ∨ (odd n ∧ even n) → odd (m + n) := sorry
/-
Theorem: Let G be an undirected graph and let C1 and C2 be connected components of G. If C1 ≠ C2,
then C1 ∩ C2 = Ø.
Proof: By contradiction. Suppose that C1 and C2 are connected components of some undirected
graph G, that C1 ≠ C2, but that C1 ∩ C2 ≠ Ø. Since C1 ∩ C2 ≠ Ø, there must be some node v such that
v ∈ C1 and v ∈ C2. Furthermore, since C1 ≠ C2, there must be some node u that either u ∈ C1 or
u ∈ C2, but not both. Without loss of generality, assume that u ∈ C1 and u ∉ C2.
By the definition of a connected component, since u ∈ C1 and v ∈ C1, we know u ↔ v. Similarly, by
the definition of a connected component, since v ∈ C2 and u ∉ C2, we know that u ↮ v, contradicting
our previous assertion. We have reached a contradiction, so our assumption must have been wrong.
Thus C1 ∩ C2 = Ø, as required. ■
-/
-- similar to the first one
example : ∀ (C1 C2 : set T) (u : T), (u ∈ C1 ∧ u ∉ C2) ∨ (u ∈ C2 ∧ u ∉ C1) → true := sorry
/-
Theorem: Let G = (V, E) be any graph containing a simple cycle C. Let u, v ∈ V be nodes in G. If
u ↔ v, then after deleting any single edge in C from graph G, it is still the case that u ↔ v.
Proof: Consider any graph G = (V, E) with a simple cycle C = (x1, x2, …, xn, x1). Consider any u, v ∈
V such that u ↔ v. This means that there must be some simple path (u, y1, y2, …, ym, v) from u to v.
*
Now, suppose that we remove the edge {xi, xi+1} from G.
†
We need to show that u ↔ v in this modified
graph. We consider two cases. First, it might be the case that the edge {xi, xi+1} does not appear
on the path (u, y1, …, ym, v). In that case, the path (u, y1, …, ym, v) is a valid path from u to v in the
new graph, so u ↔ v still holds.
Second, it might be the case that the edge {xi, xi+1} appears somewhere in our original path (u, y1, …,
ym, v). Since the graph is undirected, the edge might appear as {xi, xi+1} or as {xi+1, xi} when it occurs
in the path. Assume without loss of generality that it appears as {xi, xi+1} (otherwise, we can just reverse
the ordering of the nodes in the original cycle so as to relabel the edges). This means that we
can split the original path into three smaller paths – a path from u to xi, then the edge {xi, xi+1}, and finally
a path from xi+1 to v. Thus u ↔ xi and xi+1 ↔ v. Now, since the edge {xi, xi+1} lies on the cycle
C, after deleting the edge from the cycle, there is still a path from xi to xi+1. Specifically, we can follow
the edges of the cycle in reverse from xi until we reach xi+1. In other words, in this new graph, we
must have that xi ↔ xi+1.
Since in this new graph u ↔ xi, xi ↔ xi+1, and xi+1 ↔ v, we thus have that u ↔ v in the new graph, as
required. ■
* We have not formally proven that u ↔ v iff there is a simple path from u to v. It's a good exercise to try to prove this result. As a hint, try using
the well-ordering principle by considering the shortest path from u to v and proving that it must be a simple path.
† It might be the case that this edge is the last edge on the cycle, which goes from xn to x1. In proofs such as this one, it is typical to allow for a
slight abuse of notation by letting xi+1 mean “the next node on the cycle,” which might not necessarily have the next index.
-/
-- Not sure why he needs a directionality of the edge at all...weird
/-
Theorem: Let G be a tree with at least one edge. If any edge is removed from G, the resulting graph
consists of two connected components that are each trees over their respective nodes.
Proof: Let G = (V, E) be a tree with at least one edge, and let {u, v} ∈ E be an arbitrary edge of G.
By our lemma, if we remove {u, v} from G, we are left with two connected components; call them Cu
and Cv, with u ∈ Cu and v ∈ Cv. Since Cu and Cv are connected components, they are connected. Consequently,
if we can show that Cu and Cv are acyclic, then we can conclude that Cu and Cv are trees.
To show that Cu and Cv are acyclic, assume for the sake of contradiction that at least one of them is
not; without loss of generality, let it be Cu. This means that there is a simple cycle contained purely
within Cu. But since all of the edges in Cu are also present in G, this means that there is a simple cycle
in G, contradicting the fact that G is a tree. We have reached a contradiction, so our assumption
must have been wrong. Thus Cu and Cv must be acyclic, and therefore are trees. ■
-/
-- example acyclic Cu ∨ acyclic Cv → false
/-
Theorem: Let T = (V, E) be a tree. If |V| = 1, then V has exactly one leaf node. Otherwise, V has at
least two leaf nodes.
Proof: By induction. Let P(n) be “any tree with n nodes has exactly one leaf if n = 1 and at least two
leaves if n ≥ 2.” We prove P(n) is true for all n ∈ ℕ⁺ by induction on n.
Assume that for some n ∈ ℕ⁺, that for all n' ∈ ℕ⁺ with n' < n, that P(n') holds and any tree with n'
nodes either has one node and exactly one leaf, or has at least two nodes and at least two leaves. We
will prove that P(n) holds in this case.
First, if n = 1, then the only tree with n nodes is one with a single isolated node. This node has no
edges connected to it, so it is a leaf. Thus P(n) holds.
Otherwise, assume that n ≥ 2 and consider any tree T with n nodes. Choose any edge of T and remove
it; this splits T into two subtrees T1 and T2. We now consider three cases about the relative
sizes of T1 and T2.
Case 1: T1 and T2 each have one node. This means that the tree T has exactly two nodes, so it has exactly
one edge. Thus each of the nodes in T are leaves, since they are incident to just one edge each,
and so T has at least two leaves.
Case 2: Both T1 and T2 have at least two nodes. By the inductive hypothesis, this means that T1 and
T2 each have two leaf nodes, meaning that there are at least four nodes in the graph that have at most
one edge touching them. When we add back to T the initial edge that we deleted, this new edge can
be incident to at most two of these nodes. Consequently, the other two nodes must still have at most
one edge incident to them, and so they are still leaves in the overall graph T. Thus T has at least two
leaves.
Case 3: One of T1 and T2 has exactly one node, and the other has at least two. Without loss of generality,
assume that T1 has one node u, and that T2 has at least two. By the inductive hypothesis, T2 has
at least two leaves. Also by the inductive hypothesis, T1's sole node u must be a leaf, and moreover it
must have no edges incident to it, because any one-node graph must have no edges. When we add
back to T the initial edge that we deleted, this edge will be incident to u and incident to at most one
of the at least two leaves from T2. This means that there are now at least two leaves in T: first, the
node u, which now has exactly one edge incident to it, and second, one of the leaves from T2 that is
not incident to the new edge. Thus T has at least two leaves.
Thus in all three cases T has at least two leaves, so P(n) holds, completing the induction. ■
-/
-- Another simple binary disjunction, binary commutative relation one.
/-
Lemma: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. Then for any two sets [x]R,
[y]R ∈ X, if [x]R ≠ [y]R, then [x]R ∩ [y]R = Ø.
Proof: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. We proceed by contrapositive
and show that for any [x]R, [y]R ∈ X, that if [x]R ∩ [y]R ≠ Ø, then [x]R = [y]R.
Consider any [x]R, [y]R ∈ X such that [x]R ∩ [y]R ≠ Ø. Then there must be some element w such that
w ∈ [x]R and w ∈ [y]R. By definition, this means w ∈ { z ∈ A | xRz } and w ∈ { z ∈ A | yRz }. Consequently,
xRw and yRw. Since R is symmetric, this means that xRw and wRy. Since R is transitive,
this means that xRy. By symmetry, we also have that yRx.
We will now use this fact to show that [x]R ⊆ [y]R. Without loss of generality, we can use this same
argument to show that [y]R ⊆ [x]R, from which we can conclude that [x]R = [y]R, as required.
To show that [x]R ⊆ [y]R, consider any z ∈ [x]R. This means that xRz. Since yRx and xRz, by transitivity
we have that yRz. Consequently, z ∈ [y]R. Since our choice of z was arbitrary, we have that any
z ∈ [x]R satisfies z ∈ [y]R. Thus [x]R ⊆ [y]R, as required. ■
-/
-- This one is a bit more subtle.
--Goal: (R x y → P x y) ∧ (R y x → P y x)
--no special knowledge of x and y
--wlog assume R x y
-- this is a weird one
/-
Theorem: | is a partial order over ℕ.
Proof: We will show that | is reflexive, antisymmetric, and transitive. To see that | is reflexive, we will
prove that for any n ∈ ℕ, that n | n (that there exists some q ∈ ℕ such that n = nq). So let n be any
natural number, and take q = 1. Then nq = n · 1 = n, so n | n.
To see that | is antisymmetric, we will prove that for any m, n ∈ ℕ, that if m | n and n | m, that m = n.
Consider any m, n ∈ ℕ where m | n and n | m. This means that there exists q, r ∈ ℕ such that n = mq
and m = nr. Consequently:
m = nr = (mq)r = mqr
n = mq = (nr)q = nqr
We now consider two cases. First, if m = n = 0, then we are done, since m = n. Otherwise, at least
one of m or n is nonzero; without loss of generality, assume m ≠ 0. Then since m = mqr, we know
that 1 = qr. Since q, r ∈ ℕ, this is only possible if q = r = 1. Consequently, m = nr = n · 1 = n, so
m = n, as required.
To see that | is transitive, we will prove that for any m, n, p ∈ ℕ, that if m | n and n | p, then m | p.
Consider any m, n, p ∈ ℕ where m | n and n | p; then there must exist q, r ∈ ℕ such that n = qm and
p = rn. Consequently, p = rn = r(qm) = qrm = (qr)m. Since qr ∈ ℕ, this means that there is some
k ∈ ℕ (namely, qr) such that p = km. Thus m | p, as required.
Since | is reflexive, antisymmetric, and transitive over ℕ, | is a partial order over ℕ.
-/
--standard case:
--m = n vs n = m
------------------------------------
--Either:
--have an OR (wlog, assume _)
--or want to show an AND (wlog, we'll show that _) -- this one is sketchier, I am okay ignoring it for now
example : ∀ (A B : set T) (x : T), (x ∈ A ∧ x ∉ B) ∨ (x ∈ B ∧ x ∉ A) → x ∈ A ∪ B - A ∩ B :=
assume A B x x_or_and,
wlog x_or_and
(assume x_in_A_nin_B : x ∈ A ∧ x ∉ B,
show x ∈ A ∪ B - A ∩ B, from sorry)
open prod.ops
example : ∀ (A B : set T) (x : T),
let R := λ UV, x ∈ UV.1 ∧ x ∉ UV.2 in
let Goal := λ
let Pi := _ in -- permutations on pairs
have can_assume_generic : R (A,B) ∨ R (B,A) ↔ ∀ (pi : Pi), R (pi (A,B)),
have suffices : ∀ pi, Goal (pi (A,B)) → Goal (A,B),
-- replace assumption,
assume pi RpiAB,
show Goal (pi (A,B)),
show Goal (A,B)
-- Binary wlog
check @or.elim
check @bool.rec
-- or.elim : ∀ {a b c : Prop}, a ∨ b → (a → c) → (b → c) → c
-- bool.rec : Π {C : bool → Type}, C bool.ff → C bool.tt → (Π (n : bool), C n)
-- or.rec : ∀ {a b C : Prop}, (a → C) → (b → C) → a ∨ b → C
-- wlog : Π (disj : ?A ∨ ?B) (?A → ?G) : ?G
-- wlog : Π (disj : ?A ∨ ?B) (a_to_G : @?F ?T ?A) {Aok : ?F ?A = G} {Bok : ?F ?B → G} :=
or.elim disj (eq.rec a_to_G Aok)
(Bok ?)
-- hmm...this is confusing
-- I provide a proof of (A → C), which we can "generalize" to a proof of (∀ {?T}, ?T → ?G)
-- and then `Aok` and `Bok` can handle the conversions.
(assume x_in_A_nin_B : x ∈ A ∧ x ∉ B,
show x ∈ A ∪ B - A ∩ B, from sorry)
wlog := or.elim disj (F
definition wlog : ∀ {A B C : Prop} { MysteryType1 MysteryType2 : Type } { F : Π {M1 : MysteryType1} (M2 : M1), M2 → C }
(disj : A ∨ B) (pf1 : F A) : C :=
or.rec pf1 (λ b,
@or.elim a b c disj (@
C a → c :=
----------------
lemma opposite_parity_sum_odd : ∀ (m n : nat), opposite_parity m n → odd (m + n) :=
assume m n : nat,
-- Without loss of generality, assume that m is odd and n is even.
suffices_to_show (∀ (m n : nat), odd m ∧ even n → odd (m + n))
(assume (lem : ∀ (m n : nat), odd m ∧ even n → odd (m + n))
(m n : nat) (opp_mn : opposite_parity m n),
or.elim opp_mn (assume H : odd m ∧ even n, lem m n H) (assume H : odd n ∧ even m, (add_comm n m) ▸ (lem n m H)))
(take (m n : nat),
|
72ea96fbb4eef777a2fe7628e0aba560c90b78f2 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/ring_theory/power_series/basic.lean | 64057659cb4e8739eb85b1c2ee0262d1b1d89700 | [
"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 | 75,248 | 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 algebra.big_operators.nat_antidiagonal
import data.finsupp.interval
import data.mv_polynomial.basic
import data.polynomial.algebra_map
import data.polynomial.coeff
import linear_algebra.std_basis
import ring_theory.ideal.local_ring
import ring_theory.multiplicity
import tactic.linarith
/-!
# 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`, `le_order_add`).
## Implementation notes
In this file we define multivariate formal power series with
variables indexed by `σ` and coefficients in `R` as
`mv_power_series σ R := (σ →₀ ℕ) → R`.
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 R := mv_power_series unit R`.
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 big_operators polynomial
/-- Multivariate formal power series, where `σ` is the index set of the variables
and `R` is the coefficient ring.-/
def mv_power_series (σ : Type*) (R : Type*) := (σ →₀ ℕ) → R
namespace mv_power_series
open finsupp
variables {σ R : Type*}
instance [inhabited R] : inhabited (mv_power_series σ R) := ⟨λ _, default⟩
instance [has_zero R] : has_zero (mv_power_series σ R) := pi.has_zero
instance [add_monoid R] : add_monoid (mv_power_series σ R) := pi.add_monoid
instance [add_group R] : add_group (mv_power_series σ R) := pi.add_group
instance [add_comm_monoid R] : add_comm_monoid (mv_power_series σ R) := pi.add_comm_monoid
instance [add_comm_group R] : add_comm_group (mv_power_series σ R) := pi.add_comm_group
instance [nontrivial R] : nontrivial (mv_power_series σ R) := function.nontrivial
instance {A} [semiring R] [add_comm_monoid A] [module R A] :
module R (mv_power_series σ A) := pi.module _ _ _
instance {A S} [semiring R] [semiring S] [add_comm_monoid A] [module R A] [module S A]
[has_scalar R S] [is_scalar_tower R S A] :
is_scalar_tower R S (mv_power_series σ A) :=
pi.is_scalar_tower
section semiring
variables (R) [semiring R]
/-- The `n`th monomial with coefficient `a` as multivariate formal power series.-/
def monomial (n : σ →₀ ℕ) : R →ₗ[R] mv_power_series σ R :=
linear_map.std_basis R _ n
/-- The `n`th coefficient of a multivariate formal power series.-/
def coeff (n : σ →₀ ℕ) : (mv_power_series σ R) →ₗ[R] R := linear_map.proj n
variables {R}
/-- Two multivariate formal power series are equal if all their coefficients are equal.-/
@[ext] lemma ext {φ ψ} (h : ∀ (n : σ →₀ ℕ), coeff R n φ = coeff R 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 σ R} :
φ = ψ ↔ (∀ (n : σ →₀ ℕ), coeff R n φ = coeff R n ψ) :=
function.funext_iff
lemma monomial_def [decidable_eq σ] (n : σ →₀ ℕ) :
monomial R n = linear_map.std_basis R _ n :=
by convert rfl -- unify the `decidable` arguments
lemma coeff_monomial [decidable_eq σ] (m n : σ →₀ ℕ) (a : R) :
coeff R m (monomial R n a) = if m = n then a else 0 :=
by rw [coeff, monomial_def, linear_map.proj_apply, linear_map.std_basis_apply,
function.update_apply, pi.zero_apply]
@[simp] lemma coeff_monomial_same (n : σ →₀ ℕ) (a : R) :
coeff R n (monomial R n a) = a :=
linear_map.std_basis_same R _ n a
lemma coeff_monomial_ne {m n : σ →₀ ℕ} (h : m ≠ n) (a : R) :
coeff R m (monomial R n a) = 0 :=
linear_map.std_basis_ne R _ _ _ h a
lemma eq_of_coeff_monomial_ne_zero {m n : σ →₀ ℕ} {a : R} (h : coeff R m (monomial R n a) ≠ 0) :
m = n :=
by_contra $ λ h', h $ coeff_monomial_ne h' a
@[simp] lemma coeff_comp_monomial (n : σ →₀ ℕ) :
(coeff R n).comp (monomial R n) = linear_map.id :=
linear_map.ext $ coeff_monomial_same n
@[simp] lemma coeff_zero (n : σ →₀ ℕ) : coeff R n (0 : mv_power_series σ R) = 0 := rfl
variables (m n : σ →₀ ℕ) (φ ψ : mv_power_series σ R)
instance : has_one (mv_power_series σ R) := ⟨monomial R (0 : σ →₀ ℕ) 1⟩
lemma coeff_one [decidable_eq σ] :
coeff R n (1 : mv_power_series σ R) = if n = 0 then 1 else 0 :=
coeff_monomial _ _ _
lemma coeff_zero_one : coeff R (0 : σ →₀ ℕ) 1 = 1 :=
coeff_monomial_same 0 1
lemma monomial_zero_one : monomial R (0 : σ →₀ ℕ) 1 = 1 := rfl
instance : has_mul (mv_power_series σ R) :=
⟨λ φ ψ n, ∑ p in finsupp.antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ⟩
lemma coeff_mul : coeff R n (φ * ψ) =
∑ p in finsupp.antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := rfl
protected lemma zero_mul : (0 : mv_power_series σ R) * φ = 0 :=
ext $ λ n, by simp [coeff_mul]
protected lemma mul_zero : φ * 0 = 0 :=
ext $ λ n, by simp [coeff_mul]
lemma coeff_monomial_mul (a : R) :
coeff R m (monomial R n a * φ) = if n ≤ m then a * coeff R (m - n) φ else 0 :=
begin
have : ∀ p ∈ antidiagonal m,
coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 (monomial R n a) * coeff R p.2 φ ≠ 0 → p.1 = n :=
λ p _ hp, eq_of_coeff_monomial_ne_zero (left_ne_zero_of_mul hp),
rw [coeff_mul, ← finset.sum_filter_of_ne this, antidiagonal_filter_fst_eq,
finset.sum_ite_index],
simp only [finset.sum_singleton, coeff_monomial_same, finset.sum_empty]
end
lemma coeff_mul_monomial (a : R) :
coeff R m (φ * monomial R n a) = if n ≤ m then coeff R (m - n) φ * a else 0 :=
begin
have : ∀ p ∈ antidiagonal m,
coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 φ * coeff R p.2 (monomial R n a) ≠ 0 → p.2 = n :=
λ p _ hp, eq_of_coeff_monomial_ne_zero (right_ne_zero_of_mul hp),
rw [coeff_mul, ← finset.sum_filter_of_ne this, antidiagonal_filter_snd_eq,
finset.sum_ite_index],
simp only [finset.sum_singleton, coeff_monomial_same, finset.sum_empty]
end
lemma coeff_add_monomial_mul (a : R) :
coeff R (m + n) (monomial R m a * φ) = a * coeff R n φ :=
begin
rw [coeff_monomial_mul, if_pos, add_tsub_cancel_left],
exact le_add_right le_rfl
end
lemma coeff_add_mul_monomial (a : R) :
coeff R (m + n) (φ * monomial R n a) = coeff R m φ * a :=
begin
rw [coeff_mul_monomial, if_pos, add_tsub_cancel_right],
exact le_add_left le_rfl
end
protected lemma one_mul : (1 : mv_power_series σ R) * φ = φ :=
ext $ λ n, by simpa using coeff_add_monomial_mul 0 n φ 1
protected lemma mul_one : φ * 1 = φ :=
ext $ λ n, by simpa using coeff_add_mul_monomial n 0 φ 1
protected lemma mul_add (φ₁ φ₂ φ₃ : mv_power_series σ R) :
φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, mul_add, finset.sum_add_distrib, linear_map.map_add]
protected lemma add_mul (φ₁ φ₂ φ₃ : mv_power_series σ R) :
(φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ :=
ext $ λ n, by simp only [coeff_mul, add_mul, finset.sum_add_distrib, linear_map.map_add]
protected lemma mul_assoc (φ₁ φ₂ φ₃ : mv_power_series σ R) :
(φ₁ * φ₂) * φ₃ = φ₁ * (φ₂ * φ₃) :=
begin
ext1 n,
simp only [coeff_mul, finset.sum_mul, finset.mul_sum, finset.sum_sigma'],
refine finset.sum_bij (λ p _, ⟨(p.2.1, p.2.2 + p.1.2), (p.2.2, p.1.2)⟩) _ _ _ _;
simp only [mem_antidiagonal, finset.mem_sigma, heq_iff_eq, prod.mk.inj_iff, and_imp,
exists_prop],
{ rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩, dsimp only, rintro rfl rfl,
simp [add_assoc] },
{ rintros ⟨⟨a, b⟩, ⟨c, d⟩⟩, dsimp only, rintro rfl rfl,
apply mul_assoc },
{ rintros ⟨⟨a, b⟩, ⟨c, d⟩⟩ ⟨⟨i, j⟩, ⟨k, l⟩⟩, dsimp only, rintro rfl rfl - rfl rfl - rfl rfl,
refl },
{ rintro ⟨⟨i, j⟩, ⟨k, l⟩⟩, dsimp only, rintro rfl rfl,
refine ⟨⟨(i + k, l), (i, k)⟩, _, _⟩; simp [add_assoc] }
end
instance : semiring (mv_power_series σ R) :=
{ 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 R] : comm_semiring (mv_power_series σ R) :=
{ mul_comm := λ φ ψ, ext $ λ n, by simpa only [coeff_mul, mul_comm]
using sum_antidiagonal_swap n (λ a b, coeff R a φ * coeff R b ψ),
.. mv_power_series.semiring }
instance [ring R] : ring (mv_power_series σ R) :=
{ .. mv_power_series.semiring,
.. mv_power_series.add_comm_group }
instance [comm_ring R] : comm_ring (mv_power_series σ R) :=
{ .. mv_power_series.comm_semiring,
.. mv_power_series.add_comm_group }
section semiring
variables [semiring R]
lemma monomial_mul_monomial (m n : σ →₀ ℕ) (a b : R) :
monomial R m a * monomial R n b = monomial R (m + n) (a * b) :=
begin
ext k,
simp only [coeff_mul_monomial, coeff_monomial],
split_ifs with h₁ h₂ h₃ h₃ h₂; try { refl },
{ rw [← h₂, tsub_add_cancel_of_le h₁] at h₃, exact (h₃ rfl).elim },
{ rw [h₃, add_tsub_cancel_right] at h₂, exact (h₂ rfl).elim },
{ exact zero_mul b },
{ rw h₂ at h₁, exact (h₁ $ le_add_left le_rfl).elim }
end
variables (σ) (R)
/-- The constant multivariate formal power series.-/
def C : R →+* mv_power_series σ R :=
{ map_one' := rfl,
map_mul' := λ a b, (monomial_mul_monomial 0 0 a b).symm,
map_zero' := (monomial R (0 : _)).map_zero,
.. monomial R (0 : σ →₀ ℕ) }
variables {σ} {R}
@[simp] lemma monomial_zero_eq_C : ⇑(monomial R (0 : σ →₀ ℕ)) = C σ R := rfl
lemma monomial_zero_eq_C_apply (a : R) : monomial R (0 : σ →₀ ℕ) a = C σ R a := rfl
lemma coeff_C [decidable_eq σ] (n : σ →₀ ℕ) (a : R) :
coeff R n (C σ R a) = if n = 0 then a else 0 :=
coeff_monomial _ _ _
lemma coeff_zero_C (a : R) : coeff R (0 : σ →₀ℕ) (C σ R a) = a :=
coeff_monomial_same 0 a
/-- The variables of the multivariate formal power series ring.-/
def X (s : σ) : mv_power_series σ R := monomial R (single s 1) 1
lemma coeff_X [decidable_eq σ] (n : σ →₀ ℕ) (s : σ) :
coeff R n (X s : mv_power_series σ R) = if n = (single s 1) then 1 else 0 :=
coeff_monomial _ _ _
lemma coeff_index_single_X [decidable_eq σ] (s t : σ) :
coeff R (single t 1) (X s : mv_power_series σ R) = if t = s then 1 else 0 :=
by simp only [coeff_X, single_left_inj one_ne_zero]
@[simp] lemma coeff_index_single_self_X (s : σ) :
coeff R (single s 1) (X s : mv_power_series σ R) = 1 :=
coeff_monomial_same _ _
lemma coeff_zero_X (s : σ) : coeff R (0 : σ →₀ ℕ) (X s : mv_power_series σ R) = 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 R (single s 1) 1 := rfl
lemma X_pow_eq (s : σ) (n : ℕ) :
(X s : mv_power_series σ R)^n = monomial R (single s n) 1 :=
begin
induction n with n ih,
{ rw [pow_zero, finsupp.single_zero, monomial_zero_one] },
{ rw [pow_succ', ih, nat.succ_eq_add_one, finsupp.single_add, X, monomial_mul_monomial, one_mul] }
end
lemma coeff_X_pow [decidable_eq σ] (m : σ →₀ ℕ) (s : σ) (n : ℕ) :
coeff R m ((X s : mv_power_series σ R)^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 σ R) (a : R) :
coeff R n (φ * C σ R a) = coeff R n φ * a :=
by simpa using coeff_add_mul_monomial n 0 φ a
@[simp] lemma coeff_C_mul (n : σ →₀ ℕ) (φ : mv_power_series σ R) (a : R) :
coeff R n (C σ R a * φ) = a * coeff R n φ :=
by simpa using coeff_add_monomial_mul 0 n φ a
lemma coeff_zero_mul_X (φ : mv_power_series σ R) (s : σ) :
coeff R (0 : σ →₀ ℕ) (φ * X s) = 0 :=
begin
have : ¬single s 1 ≤ 0, from λ h, by simpa using h s,
simp only [X, coeff_mul_monomial, if_neg this]
end
lemma coeff_zero_X_mul (φ : mv_power_series σ R) (s : σ) :
coeff R (0 : σ →₀ ℕ) (X s * φ) = 0 :=
begin
have : ¬single s 1 ≤ 0, from λ h, by simpa using h s,
simp only [X, coeff_monomial_mul, if_neg this]
end
variables (σ) (R)
/-- The constant coefficient of a formal power series.-/
def constant_coeff : (mv_power_series σ R) →+* R :=
{ to_fun := coeff R (0 : σ →₀ ℕ),
map_one' := coeff_zero_one,
map_mul' := λ φ ψ, by simp [coeff_mul, support_single_ne_zero],
map_zero' := linear_map.map_zero _,
.. coeff R (0 : σ →₀ ℕ) }
variables {σ} {R}
@[simp] lemma coeff_zero_eq_constant_coeff :
⇑(coeff R (0 : σ →₀ ℕ)) = constant_coeff σ R := rfl
lemma coeff_zero_eq_constant_coeff_apply (φ : mv_power_series σ R) :
coeff R (0 : σ →₀ ℕ) φ = constant_coeff σ R φ := rfl
@[simp] lemma constant_coeff_C (a : R) : constant_coeff σ R (C σ R a) = a := rfl
@[simp] lemma constant_coeff_comp_C :
(constant_coeff σ R).comp (C σ R) = ring_hom.id R := rfl
@[simp] lemma constant_coeff_zero : constant_coeff σ R 0 = 0 := rfl
@[simp] lemma constant_coeff_one : constant_coeff σ R 1 = 1 := rfl
@[simp] lemma constant_coeff_X (s : σ) : constant_coeff σ R (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 σ R) (h : is_unit φ) :
is_unit (constant_coeff σ R φ) :=
h.map _
@[simp]
lemma coeff_smul (f : mv_power_series σ R) (n) (a : R) :
coeff _ n (a • f) = a * coeff _ n f :=
rfl
lemma smul_eq_C_mul (f : mv_power_series σ R) (a : R) :
a • f = C σ R a * f :=
by { ext, simp }
lemma X_inj [nontrivial R] {s t : σ} : (X s : mv_power_series σ R) = X t ↔ s = t :=
⟨begin
intro h, replace h := congr_arg (coeff R (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 semiring
section map
variables {S T : Type*} [semiring R] [semiring S] [semiring T]
variables (f : R →+* S) (g : S →+* T)
variable (σ)
/-- The map between multivariate formal power series induced by a map on the coefficients.-/
def map : mv_power_series σ R →+* mv_power_series σ S :=
{ to_fun := λ φ n, f $ coeff R n φ,
map_zero' := ext $ λ n, f.map_zero,
map_one' := ext $ λ n, show f ((coeff R n) 1) = (coeff S n) 1,
by { rw [coeff_one, coeff_one], split_ifs; simp [f.map_one, f.map_zero] },
map_add' := λ φ ψ, ext $ λ n,
show f ((coeff R n) (φ + ψ)) = f ((coeff R n) φ) + f ((coeff R n) ψ), by simp,
map_mul' := λ φ ψ, ext $ λ n, show f _ = _,
begin
rw [coeff_mul, f.map_sum, 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 R) = 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 σ R) :
coeff S n (map σ f φ) = f (coeff R n φ) := rfl
@[simp] lemma constant_coeff_map (φ : mv_power_series σ R) :
constant_coeff σ S (map σ f φ) = f (constant_coeff σ R φ) := rfl
@[simp] lemma map_monomial (n : σ →₀ ℕ) (a : R) :
map σ f (monomial R n a) = monomial S n (f a) :=
by { ext m, simp [coeff_monomial, apply_ite f] }
@[simp] lemma map_C (a : R) : map σ f (C σ R a) = C σ S (f a) :=
map_monomial _ _ _
@[simp] lemma map_X (s : σ) : map σ f (X s) = X s := by simp [mv_power_series.X]
end map
section algebra
variables {A : Type*} [comm_semiring R] [semiring A] [algebra R A]
instance : algebra R (mv_power_series σ A) :=
{ commutes' := λ a φ, by { ext n, simp [algebra.commutes] },
smul_def' := λ a σ, by { ext n, simp [(coeff A n).map_smul_of_tower a, algebra.smul_def] },
to_ring_hom := (mv_power_series.map σ (algebra_map R A)).comp (C σ R),
.. mv_power_series.module }
theorem C_eq_algebra_map : C σ R = (algebra_map R (mv_power_series σ R)) := rfl
theorem algebra_map_apply {r : R} :
algebra_map R (mv_power_series σ A) r = C σ A (algebra_map R A r) :=
begin
change (mv_power_series.map σ (algebra_map R A)).comp (C σ R) r = _,
simp,
end
instance [nonempty σ] [nontrivial R] : nontrivial (subalgebra R (mv_power_series σ R)) :=
⟨⟨⊥, ⊤, begin
rw [ne.def, set_like.ext_iff, not_forall],
inhabit σ,
refine ⟨X default, _⟩,
simp only [algebra.mem_bot, not_exists, set.mem_range, iff_true, algebra.mem_top],
intros x,
rw [ext_iff, not_forall],
refine ⟨finsupp.single default 1, _⟩,
simp [algebra_map_apply, coeff_C],
end⟩⟩
end algebra
section trunc
variables [comm_semiring R] (n : σ →₀ ℕ)
/-- Auxiliary definition for the truncation function. -/
def trunc_fun (φ : mv_power_series σ R) : mv_polynomial σ R :=
∑ m in finset.Iio n, mv_polynomial.monomial m (coeff R m φ)
lemma coeff_trunc_fun (m : σ →₀ ℕ) (φ : mv_power_series σ R) :
(trunc_fun n φ).coeff m = if m < n then coeff R m φ else 0 :=
by simp [trunc_fun, mv_polynomial.coeff_sum]
variable (R)
/-- The `n`th truncation of a multivariate formal power series to a multivariate polynomial -/
def trunc : mv_power_series σ R →+ mv_polynomial σ R :=
{ to_fun := trunc_fun n,
map_zero' := by { ext, simp [coeff_trunc_fun] },
map_add' := by { intros, ext, simp [coeff_trunc_fun, ite_add], split_ifs; refl } }
variable {R}
lemma coeff_trunc (m : σ →₀ ℕ) (φ : mv_power_series σ R) :
(trunc R n φ).coeff m = if m < n then coeff R m φ else 0 :=
by simp [trunc, coeff_trunc_fun]
@[simp] lemma trunc_one (hnn : n ≠ 0) : trunc R n 1 = 1 :=
mv_polynomial.ext _ _ $ λ m,
begin
rw [coeff_trunc, coeff_one],
split_ifs with H H' H',
{ subst m, simp },
{ symmetry, rw mv_polynomial.coeff_one, exact if_neg (ne.symm H'), },
{ symmetry, rw mv_polynomial.coeff_one, refine if_neg _,
rintro rfl, apply H, exact ne.bot_lt hnn, }
end
@[simp] lemma trunc_C (hnn : n ≠ 0) (a : R) : trunc R n (C σ R 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, exact ne.bot_lt hnn,
end
end trunc
section comm_semiring
variable [comm_semiring R]
lemma X_pow_dvd_iff {s : σ} {n : ℕ} {φ : mv_power_series σ R} :
(X s : mv_power_series σ R)^n ∣ φ ↔ ∀ m : σ →₀ ℕ, m s < n → coeff R 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 at hij,
rw [← hij, finsupp.add_apply, finsupp.single_eq_same], exact nat.le_add_right n _ },
{ intro h, refine ⟨λ m, coeff R (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 R m φ) H.symm },
{ rintros ⟨i,j⟩ hij hne, rw finsupp.mem_antidiagonal 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 [add_tsub_cancel_left, finsupp.add_apply, finsupp.tsub_apply] },
{ exact zero_mul _ } },
{ intro hni, exfalso, apply hni, rwa [finsupp.mem_antidiagonal, add_comm] } },
{ rw [h, coeff_mul, finset.sum_eq_zero],
{ rintros ⟨i,j⟩ hij, rw finsupp.mem_antidiagonal at hij,
rw coeff_X_pow, split_ifs with hi,
{ exfalso, apply H, rw [← hij, hi], ext,
rw [coe_add, coe_add, pi.add_apply, pi.add_apply, add_tsub_cancel_left, add_comm], },
{ exact zero_mul _ } },
{ classical, contrapose! H, ext t,
by_cases hst : s = t,
{ subst t, simpa using tsub_add_cancel_of_le H },
{ simp [finsupp.single_apply, hst] } } } }
end
lemma X_dvd_iff {s : σ} {φ : mv_power_series σ R} :
(X s : mv_power_series σ R) ∣ φ ↔ ∀ m : σ →₀ ℕ, m s = 0 → coeff R m φ = 0 :=
begin
rw [← pow_one (X s : mv_power_series σ R), 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 R]
/-
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 : R) (φ : mv_power_series σ R) : mv_power_series σ R
| n := if n = 0 then a else
- a * ∑ x in n.antidiagonal,
if h : x.2 < n then coeff R 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 [decidable_eq σ] (n : σ →₀ ℕ) (a : R) (φ : mv_power_series σ R) :
coeff R n (inv.aux a φ) = if n = 0 then a else
- a * ∑ x in n.antidiagonal,
if x.2 < n then coeff R x.1 φ * coeff R x.2 (inv.aux a φ) else 0 :=
show inv.aux a φ n = _,
begin
rw inv.aux,
convert rfl -- unify `decidable` instances
end
/-- A multivariate formal power series is invertible if the constant coefficient is invertible.-/
def inv_of_unit (φ : mv_power_series σ R) (u : Rˣ) : mv_power_series σ R :=
inv.aux (↑u⁻¹) φ
lemma coeff_inv_of_unit [decidable_eq σ] (n : σ →₀ ℕ) (φ : mv_power_series σ R) (u : Rˣ) :
coeff R n (inv_of_unit φ u) = if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * ∑ x in n.antidiagonal,
if x.2 < n then coeff R x.1 φ * coeff R x.2 (inv_of_unit φ u) else 0 :=
coeff_inv_aux n (↑u⁻¹) φ
@[simp] lemma constant_coeff_inv_of_unit (φ : mv_power_series σ R) (u : Rˣ) :
constant_coeff σ R (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 σ R) (u : Rˣ) (h : constant_coeff σ R φ = 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,
{ rw [finsupp.mem_antidiagonal, 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, mul_neg, 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_rfl), 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] 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 R]
/-- Multivariate formal power series over a local ring form a local ring. -/
instance [local_ring R] : local_ring (mv_power_series σ R) :=
local_ring.of_is_unit_or_is_unit_one_sub_self $ by
{ intro φ,
rcases local_ring.is_unit_or_is_unit_one_sub_self (constant_coeff σ R φ) with ⟨u,h⟩|⟨u,h⟩;
[left, right];
{ refine is_unit_of_mul_eq_one _ _ (mul_inv_of_unit _ u _),
simpa using h.symm } }
-- TODO(jmc): once adic topology lands, show that this is complete
end comm_ring
section local_ring
variables {S : Type*} [comm_ring R] [comm_ring S] (f : R →+* S)
[is_local_ring_hom f]
-- Thanks to the linter for informing us that this instance does
-- not actually need R and S to be local rings!
/-- The map `A[[X]] → B[[X]]` induced by a local ring hom `A → B` is local -/
instance map.is_local_ring_hom : is_local_ring_hom (map σ f) :=
⟨begin
rintros φ ⟨ψ, h⟩,
replace h := congr_arg (constant_coeff σ S) h,
rw constant_coeff_map at h,
have : is_unit (constant_coeff σ S ↑ψ) := @is_unit_constant_coeff σ S _ (↑ψ) ψ.is_unit,
rw h at this,
rcases is_unit_of_map_unit f _ this with ⟨c, hc⟩,
exact is_unit_of_mul_eq_one φ (inv_of_unit φ c) (mul_inv_of_unit φ c hc.symm)
end⟩
end local_ring
section field
variables {k : Type*} [field k]
/-- The inverse `1/f` of a multivariable power series `f` over a field -/
protected def inv (φ : mv_power_series σ k) : mv_power_series σ k :=
inv.aux (constant_coeff σ k φ)⁻¹ φ
instance : has_inv (mv_power_series σ k) := ⟨mv_power_series.inv⟩
lemma coeff_inv [decidable_eq σ] (n : σ →₀ ℕ) (φ : mv_power_series σ k) :
coeff k n (φ⁻¹) = if n = 0 then (constant_coeff σ k φ)⁻¹ else
- (constant_coeff σ k φ)⁻¹ * ∑ x in n.antidiagonal,
if x.2 < n then coeff k x.1 φ * coeff k x.2 (φ⁻¹) else 0 :=
coeff_inv_aux n _ φ
@[simp] lemma constant_coeff_inv (φ : mv_power_series σ k) :
constant_coeff σ k (φ⁻¹) = (constant_coeff σ k φ)⁻¹ :=
by rw [← coeff_zero_eq_constant_coeff_apply, coeff_inv, if_pos rfl]
lemma inv_eq_zero {φ : mv_power_series σ k} :
φ⁻¹ = 0 ↔ constant_coeff σ k φ = 0 :=
⟨λ h, by simpa using congr_arg (constant_coeff σ k) 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] lemma zero_inv : (0 : mv_power_series σ k)⁻¹ = 0 :=
by rw [inv_eq_zero, constant_coeff_zero]
@[simp, priority 1100]
lemma inv_of_unit_eq (φ : mv_power_series σ k) (h : constant_coeff σ k φ ≠ 0) :
inv_of_unit φ (units.mk0 _ h) = φ⁻¹ := rfl
@[simp]
lemma inv_of_unit_eq' (φ : mv_power_series σ k) (u : units k) (h : constant_coeff σ k φ = 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_cancel (φ : mv_power_series σ k) (h : constant_coeff σ k φ ≠ 0) :
φ * φ⁻¹ = 1 :=
by rw [← inv_of_unit_eq φ h, mul_inv_of_unit φ (units.mk0 _ h) rfl]
@[simp] protected lemma inv_mul_cancel (φ : mv_power_series σ k) (h : constant_coeff σ k φ ≠ 0) :
φ⁻¹ * φ = 1 :=
by rw [mul_comm, φ.mul_inv_cancel h]
protected lemma eq_mul_inv_iff_mul_eq {φ₁ φ₂ φ₃ : mv_power_series σ k}
(h : constant_coeff σ k φ₃ ≠ 0) :
φ₁ = φ₂ * φ₃⁻¹ ↔ φ₁ * φ₃ = φ₂ :=
⟨λ k, by simp [k, mul_assoc, mv_power_series.inv_mul_cancel _ h],
λ k, by simp [← k, mul_assoc, mv_power_series.mul_inv_cancel _ h]⟩
protected lemma eq_inv_iff_mul_eq_one {φ ψ : mv_power_series σ k} (h : constant_coeff σ k ψ ≠ 0) :
φ = ψ⁻¹ ↔ φ * ψ = 1 :=
by rw [← mv_power_series.eq_mul_inv_iff_mul_eq h, one_mul]
protected lemma inv_eq_iff_mul_eq_one {φ ψ : mv_power_series σ k} (h : constant_coeff σ k ψ ≠ 0) :
ψ⁻¹ = φ ↔ φ * ψ = 1 :=
by rw [eq_comm, mv_power_series.eq_inv_iff_mul_eq_one h]
@[simp] protected lemma mul_inv_rev (φ ψ : mv_power_series σ k) :
(φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ :=
begin
by_cases h : constant_coeff σ k (φ * ψ) = 0,
{ rw inv_eq_zero.mpr h,
simp only [map_mul, mul_eq_zero] at h,
-- we don't have `no_zero_divisors (mw_power_series σ k)` yet,
cases h;
simp [inv_eq_zero.mpr h] },
{ rw [mv_power_series.inv_eq_iff_mul_eq_one h],
simp only [not_or_distrib, map_mul, mul_eq_zero] at h,
rw [←mul_assoc, mul_assoc _⁻¹, mv_power_series.inv_mul_cancel _ h.left, mul_one,
mv_power_series.inv_mul_cancel _ h.right] }
end
@[simp] lemma inv_one : (1 : mv_power_series σ k)⁻¹ = 1 :=
by { rw [mv_power_series.inv_eq_iff_mul_eq_one, mul_one], simp }
@[simp] lemma C_inv (r : k) : (C σ k r)⁻¹ = C σ k r⁻¹ :=
begin
rcases eq_or_ne r 0 with rfl|hr,
{ simp },
rw [mv_power_series.inv_eq_iff_mul_eq_one, ←map_mul, inv_mul_cancel hr, map_one],
simpa using hr
end
@[simp] lemma X_inv (s : σ) : (X s : mv_power_series σ k)⁻¹ = 0 :=
by rw [inv_eq_zero, constant_coeff_X]
@[simp] lemma smul_inv (r : k) (φ : mv_power_series σ k) :
(r • φ)⁻¹ = r⁻¹ • φ⁻¹ :=
by simp [smul_eq_C_mul, mul_comm]
end field
end mv_power_series
namespace mv_polynomial
open finsupp
variables {σ : Type*} {R : Type*} [comm_semiring R] (φ ψ : mv_polynomial σ R)
/-- The natural inclusion from multivariate polynomials into multivariate formal power series.-/
instance coe_to_mv_power_series : has_coe (mv_polynomial σ R) (mv_power_series σ R) :=
⟨λ φ n, coeff n φ⟩
lemma coe_def : (φ : mv_power_series σ R) = λ n, coeff n φ := rfl
@[simp, norm_cast] lemma coeff_coe (n : σ →₀ ℕ) :
mv_power_series.coeff R n ↑φ = coeff n φ := rfl
@[simp, norm_cast] lemma coe_monomial (n : σ →₀ ℕ) (a : R) :
(monomial n a : mv_power_series σ R) = mv_power_series.monomial R 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, norm_cast] lemma coe_zero : ((0 : mv_polynomial σ R) : mv_power_series σ R) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : mv_polynomial σ R) : mv_power_series σ R) = 1 :=
coe_monomial _ _
@[simp, norm_cast] lemma coe_add :
((φ + ψ : mv_polynomial σ R) : mv_power_series σ R) = φ + ψ := rfl
@[simp, norm_cast] lemma coe_mul :
((φ * ψ : mv_polynomial σ R) : mv_power_series σ R) = φ * ψ :=
mv_power_series.ext $ λ n,
by simp only [coeff_coe, mv_power_series.coeff_mul, coeff_mul]
@[simp, norm_cast] lemma coe_C (a : R) :
((C a : mv_polynomial σ R) : mv_power_series σ R) = mv_power_series.C σ R a :=
coe_monomial _ _
@[simp, norm_cast] lemma coe_bit0 :
((bit0 φ : mv_polynomial σ R) : mv_power_series σ R) = bit0 (φ : mv_power_series σ R) :=
coe_add _ _
@[simp, norm_cast] lemma coe_bit1 :
((bit1 φ : mv_polynomial σ R) : mv_power_series σ R) = bit1 (φ : mv_power_series σ R) :=
by rw [bit1, bit1, coe_add, coe_one, coe_bit0]
@[simp, norm_cast] lemma coe_X (s : σ) :
((X s : mv_polynomial σ R) : mv_power_series σ R) = mv_power_series.X s :=
coe_monomial _ _
variables (σ R)
lemma coe_injective : function.injective (coe : mv_polynomial σ R → mv_power_series σ R) :=
λ x y h, by { ext, simp_rw [←coeff_coe, h] }
variables {σ R φ ψ}
@[simp, norm_cast] lemma coe_inj : (φ : mv_power_series σ R) = ψ ↔ φ = ψ :=
(coe_injective σ R).eq_iff
@[simp] lemma coe_eq_zero_iff : (φ : mv_power_series σ R) = 0 ↔ φ = 0 :=
by rw [←coe_zero, coe_inj]
@[simp] lemma coe_eq_one_iff : (φ : mv_power_series σ R) = 1 ↔ φ = 1 :=
by rw [←coe_one, coe_inj]
/--
The coercion from multivariable polynomials to multivariable power series
as a ring homomorphism.
-/
def coe_to_mv_power_series.ring_hom : mv_polynomial σ R →+* mv_power_series σ R :=
{ to_fun := (coe : mv_polynomial σ R → mv_power_series σ R),
map_zero' := coe_zero,
map_one' := coe_one,
map_add' := coe_add,
map_mul' := coe_mul }
@[simp, norm_cast] lemma coe_pow (n : ℕ) :
((φ ^ n : mv_polynomial σ R) : mv_power_series σ R) = (φ : mv_power_series σ R) ^ n :=
coe_to_mv_power_series.ring_hom.map_pow _ _
variables (φ ψ)
@[simp] lemma coe_to_mv_power_series.ring_hom_apply : coe_to_mv_power_series.ring_hom φ = φ := rfl
section algebra
variables (A : Type*) [comm_semiring A] [algebra R A]
lemma algebra_map_apply (r : R) : algebra_map R (mv_polynomial σ A) r = C (algebra_map R A r) := rfl
/--
The coercion from multivariable polynomials to multivariable power series
as an algebra homomorphism.
-/
def coe_to_mv_power_series.alg_hom : mv_polynomial σ R →ₐ[R] mv_power_series σ A :=
{ commutes' := λ r, by simp [algebra_map_apply, mv_power_series.algebra_map_apply],
..(mv_power_series.map σ (algebra_map R A)).comp coe_to_mv_power_series.ring_hom}
@[simp] lemma coe_to_mv_power_series.alg_hom_apply : (coe_to_mv_power_series.alg_hom A φ) =
mv_power_series.map σ (algebra_map R A) ↑φ := rfl
end algebra
end mv_polynomial
namespace mv_power_series
variables {σ R A : Type*} [comm_semiring R] [comm_semiring A] [algebra R A]
(f : mv_power_series σ R)
instance algebra_mv_polynomial : algebra (mv_polynomial σ R) (mv_power_series σ A) :=
ring_hom.to_algebra (mv_polynomial.coe_to_mv_power_series.alg_hom A).to_ring_hom
instance algebra_mv_power_series : algebra (mv_power_series σ R) (mv_power_series σ A) :=
(map σ (algebra_map R A)).to_algebra
variables (A)
lemma algebra_map_apply' (p : mv_polynomial σ R):
algebra_map (mv_polynomial σ R) (mv_power_series σ A) p = map σ (algebra_map R A) p := rfl
lemma algebra_map_apply'' :
algebra_map (mv_power_series σ R) (mv_power_series σ A) f = map σ (algebra_map R A) f := rfl
end mv_power_series
/-- Formal power series over the coefficient ring `R`.-/
def power_series (R : Type*) := mv_power_series unit R
namespace power_series
open finsupp (single)
variable {R : Type*}
section
local attribute [reducible] power_series
instance [inhabited R] : inhabited (power_series R) := by apply_instance
instance [add_monoid R] : add_monoid (power_series R) := by apply_instance
instance [add_group R] : add_group (power_series R) := by apply_instance
instance [add_comm_monoid R] : add_comm_monoid (power_series R) := by apply_instance
instance [add_comm_group R] : add_comm_group (power_series R) := by apply_instance
instance [semiring R] : semiring (power_series R) := by apply_instance
instance [comm_semiring R] : comm_semiring (power_series R) := by apply_instance
instance [ring R] : ring (power_series R) := by apply_instance
instance [comm_ring R] : comm_ring (power_series R) := by apply_instance
instance [nontrivial R] : nontrivial (power_series R) := by apply_instance
instance {A} [semiring R] [add_comm_monoid A] [module R A] :
module R (power_series A) := by apply_instance
instance {A S} [semiring R] [semiring S] [add_comm_monoid A] [module R A] [module S A]
[has_scalar R S] [is_scalar_tower R S A] :
is_scalar_tower R S (power_series A) :=
pi.is_scalar_tower
instance {A} [semiring A] [comm_semiring R] [algebra R A] :
algebra R (power_series A) := by apply_instance
end
section semiring
variables (R) [semiring R]
/-- The `n`th coefficient of a formal power series.-/
def coeff (n : ℕ) : power_series R →ₗ[R] R := mv_power_series.coeff R (single () n)
/-- The `n`th monomial with coefficient `a` as formal power series.-/
def monomial (n : ℕ) : R →ₗ[R] power_series R := mv_power_series.monomial R (single () n)
variables {R}
lemma coeff_def {s : unit →₀ ℕ} {n : ℕ} (h : s () = n) :
coeff R n = mv_power_series.coeff R 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 R} (h : ∀ n, coeff R n φ = coeff R 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 R} : φ = ψ ↔ (∀ n, coeff R n φ = coeff R n ψ) :=
⟨λ h n, congr_arg (coeff R n) h, ext⟩
/-- Constructor for formal power series.-/
def mk {R} (f : ℕ → R) : power_series R := λ s, f (s ())
@[simp] lemma coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n :=
congr_arg f finsupp.single_eq_same
lemma coeff_monomial (m n : ℕ) (a : R) :
coeff R m (monomial R n a) = if m = n then a else 0 :=
calc coeff R m (monomial R n a) = _ : mv_power_series.coeff_monomial _ _ _
... = if m = n then a else 0 :
by simp only [finsupp.unique_single_eq_iff]
lemma monomial_eq_mk (n : ℕ) (a : R) :
monomial R n a = mk (λ m, if m = n then a else 0) :=
ext $ λ m, by { rw [coeff_monomial, coeff_mk] }
@[simp] lemma coeff_monomial_same (n : ℕ) (a : R) :
coeff R n (monomial R n a) = a :=
mv_power_series.coeff_monomial_same _ _
@[simp] lemma coeff_comp_monomial (n : ℕ) :
(coeff R n).comp (monomial R n) = linear_map.id :=
linear_map.ext $ coeff_monomial_same n
variable (R)
/--The constant coefficient of a formal power series. -/
def constant_coeff : power_series R →+* R := mv_power_series.constant_coeff unit R
/-- The constant formal power series.-/
def C : R →+* power_series R := mv_power_series.C unit R
variable {R}
/-- The variable of the formal power series ring.-/
def X : power_series R := mv_power_series.X ()
@[simp] lemma coeff_zero_eq_constant_coeff :
⇑(coeff R 0) = constant_coeff R :=
by { rw [coeff, finsupp.single_zero], refl }
lemma coeff_zero_eq_constant_coeff_apply (φ : power_series R) :
coeff R 0 φ = constant_coeff R φ :=
by rw [coeff_zero_eq_constant_coeff]; refl
@[simp] lemma monomial_zero_eq_C : ⇑(monomial R 0) = C R :=
by rw [monomial, finsupp.single_zero, mv_power_series.monomial_zero_eq_C, C]
lemma monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a :=
by simp
lemma coeff_C (n : ℕ) (a : R) :
coeff R n (C R a : power_series R) = if n = 0 then a else 0 :=
by rw [← monomial_zero_eq_C_apply, coeff_monomial]
@[simp] lemma coeff_zero_C (a : R) : coeff R 0 (C R a) = a :=
by rw [← monomial_zero_eq_C_apply, coeff_monomial_same 0 a]
lemma X_eq : (X : power_series R) = monomial R 1 1 := rfl
lemma coeff_X (n : ℕ) :
coeff R n (X : power_series R) = if n = 1 then 1 else 0 :=
by rw [X_eq, coeff_monomial]
@[simp] lemma coeff_zero_X : coeff R 0 (X : power_series R) = 0 :=
by rw [coeff, finsupp.single_zero, X, mv_power_series.coeff_zero_X]
@[simp] lemma coeff_one_X : coeff R 1 (X : power_series R) = 1 :=
by rw [coeff_X, if_pos rfl]
@[simp] lemma X_ne_zero [nontrivial R] : (X : power_series R) ≠ 0 :=
λ H, by simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff R 1) H
lemma X_pow_eq (n : ℕ) : (X : power_series R)^n = monomial R n 1 :=
mv_power_series.X_pow_eq _ n
lemma coeff_X_pow (m n : ℕ) :
coeff R m ((X : power_series R)^n) = if m = n then 1 else 0 :=
by rw [X_pow_eq, coeff_monomial]
@[simp] lemma coeff_X_pow_self (n : ℕ) :
coeff R n ((X : power_series R)^n) = 1 :=
by rw [coeff_X_pow, if_pos rfl]
@[simp] lemma coeff_one (n : ℕ) :
coeff R n (1 : power_series R) = if n = 0 then 1 else 0 :=
coeff_C n 1
lemma coeff_zero_one : coeff R 0 (1 : power_series R) = 1 :=
coeff_zero_C 1
lemma coeff_mul (n : ℕ) (φ ψ : power_series R) :
coeff R n (φ * ψ) = ∑ p in finset.nat.antidiagonal n, coeff R p.1 φ * coeff R 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, ← 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 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 R) (a : R) :
coeff R n (φ * C R a) = coeff R n φ * a :=
mv_power_series.coeff_mul_C _ φ a
@[simp] lemma coeff_C_mul (n : ℕ) (φ : power_series R) (a : R) :
coeff R n (C R a * φ) = a * coeff R n φ :=
mv_power_series.coeff_C_mul _ φ a
@[simp] lemma coeff_smul {S : Type*} [semiring S] [module R S]
(n : ℕ) (φ : power_series S) (a : R) : coeff S n (a • φ) = a • coeff S n φ :=
rfl
lemma smul_eq_C_mul (f : power_series R) (a : R) :
a • f = C R a * f :=
by { ext, simp }
@[simp] lemma coeff_succ_mul_X (n : ℕ) (φ : power_series R) :
coeff R (n+1) (φ * X) = coeff R n φ :=
begin
simp only [coeff, finsupp.single_add],
convert φ.coeff_add_mul_monomial (single () n) (single () 1) _,
rw mul_one
end
@[simp] lemma coeff_succ_X_mul (n : ℕ) (φ : power_series R) :
coeff R (n + 1) (X * φ) = coeff R n φ :=
begin
simp only [coeff, finsupp.single_add, add_comm n 1],
convert φ.coeff_add_monomial_mul (single () 1) (single () n) _,
rw one_mul,
end
@[simp] lemma constant_coeff_C (a : R) : constant_coeff R (C R a) = a := rfl
@[simp] lemma constant_coeff_comp_C :
(constant_coeff R).comp (C R) = ring_hom.id R := rfl
@[simp] lemma constant_coeff_zero : constant_coeff R 0 = 0 := rfl
@[simp] lemma constant_coeff_one : constant_coeff R 1 = 1 := rfl
@[simp] lemma constant_coeff_X : constant_coeff R X = 0 := mv_power_series.coeff_zero_X _
lemma coeff_zero_mul_X (φ : power_series R) : coeff R 0 (φ * X) = 0 := by simp
lemma coeff_zero_X_mul (φ : power_series R) : coeff R 0 (X * φ) = 0 := by simp
-- The following section duplicates the api of `data.polynomial.coeff` and should attempt to keep
-- up to date with that
section
lemma coeff_C_mul_X_pow (x : R) (k n : ℕ) :
coeff R n (C R x * X ^ k : power_series R) = if n = k then x else 0 :=
by simp [X_pow_eq, coeff_monomial]
@[simp]
theorem coeff_mul_X_pow (p : power_series R) (n d : ℕ) :
coeff R (d + n) (p * X ^ n) = coeff R d p :=
begin
rw [coeff_mul, finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one],
{ rintros ⟨i,j⟩ h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,
rw [finset.nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },
{ exact λ h1, (h1 (finset.nat.mem_antidiagonal.2 rfl)).elim }
end
@[simp]
theorem coeff_X_pow_mul (p : power_series R) (n d : ℕ) :
coeff R (d + n) (X ^ n * p) = coeff R d p :=
begin
rw [coeff_mul, finset.sum_eq_single (n,d), coeff_X_pow, if_pos rfl, one_mul],
{ rintros ⟨i,j⟩ h1 h2, rw [coeff_X_pow, if_neg, zero_mul], rintro rfl, apply h2,
rw [finset.nat.mem_antidiagonal, add_comm, add_right_cancel_iff] at h1, subst h1 },
{ rw add_comm,
exact λ h1, (h1 (finset.nat.mem_antidiagonal.2 rfl)).elim }
end
lemma coeff_mul_X_pow' (p : power_series R) (n d : ℕ) :
coeff R d (p * X ^ n) = ite (n ≤ d) (coeff R (d - n) p) 0 :=
begin
split_ifs,
{ rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] },
{ refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (λ x hx, _)),
rw [coeff_X_pow, if_neg, mul_zero],
exact ne_of_lt (lt_of_le_of_lt (nat.le_of_add_le_right
(le_of_eq (finset.nat.mem_antidiagonal.mp hx))) (not_le.mp h)) },
end
lemma coeff_X_pow_mul' (p : power_series R) (n d : ℕ) :
coeff R d (X ^ n * p) = ite (n ≤ d) (coeff R (d - n) p) 0 :=
begin
split_ifs,
{ rw [← tsub_add_cancel_of_le h, coeff_X_pow_mul], simp, },
{ refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (λ x hx, _)),
rw [coeff_X_pow, if_neg, zero_mul],
have := finset.nat.mem_antidiagonal.mp hx,
rw add_comm at this,
exact ne_of_lt (lt_of_le_of_lt (nat.le_of_add_le_right
(le_of_eq this)) (not_le.mp h)) },
end
end
/-- If a formal power series is invertible, then so is its constant coefficient.-/
lemma is_unit_constant_coeff (φ : power_series R) (h : is_unit φ) :
is_unit (constant_coeff R φ) :=
mv_power_series.is_unit_constant_coeff φ h
/-- Split off the constant coefficient. -/
lemma eq_shift_mul_X_add_const (φ : power_series R) :
φ = mk (λ p, coeff R (p + 1) φ) * X + C R (constant_coeff R φ) :=
begin
ext (_ | n),
{ simp only [ring_hom.map_add, constant_coeff_C, constant_coeff_X, coeff_zero_eq_constant_coeff,
zero_add, mul_zero, ring_hom.map_mul], },
{ simp only [coeff_succ_mul_X, coeff_mk, linear_map.map_add, coeff_C, n.succ_ne_zero, sub_zero,
if_false, add_zero], }
end
/-- Split off the constant coefficient. -/
lemma eq_X_mul_shift_add_const (φ : power_series R) :
φ = X * mk (λ p, coeff R (p + 1) φ) + C R (constant_coeff R φ) :=
begin
ext (_ | n),
{ simp only [ring_hom.map_add, constant_coeff_C, constant_coeff_X, coeff_zero_eq_constant_coeff,
zero_add, zero_mul, ring_hom.map_mul], },
{ simp only [coeff_succ_X_mul, coeff_mk, linear_map.map_add, coeff_C, n.succ_ne_zero, sub_zero,
if_false, add_zero], }
end
section map
variables {S : Type*} {T : Type*} [semiring S] [semiring T]
variables (f : R →+* S) (g : S →+* T)
/-- The map between formal power series induced by a map on the coefficients.-/
def map : power_series R →+* power_series S :=
mv_power_series.map _ f
@[simp] lemma map_id : (map (ring_hom.id R) :
power_series R → power_series R) = id := rfl
lemma map_comp : map (g.comp f) = (map g).comp (map f) := rfl
@[simp] lemma coeff_map (n : ℕ) (φ : power_series R) :
coeff S n (map f φ) = f (coeff R n φ) := rfl
@[simp] lemma map_C (r : R) : map f (C _ r) = C _ (f r) :=
by { ext, simp [coeff_C, apply_ite f] }
@[simp] lemma map_X : map f X = X :=
by { ext, simp [coeff_X, apply_ite f] }
end map
end semiring
section comm_semiring
variables [comm_semiring R]
lemma X_pow_dvd_iff {n : ℕ} {φ : power_series R} :
(X : power_series R)^n ∣ φ ↔ ∀ m, m < n → coeff R m φ = 0 :=
begin
convert @mv_power_series.X_pow_dvd_iff unit R _ () 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 R} :
(X : power_series R) ∣ φ ↔ constant_coeff R φ = 0 :=
begin
rw [← pow_one (X : power_series R), 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
open finset nat
/-- The ring homomorphism taking a power series `f(X)` to `f(aX)`. -/
noncomputable def rescale (a : R) : power_series R →+* power_series R :=
{ to_fun := λ f, power_series.mk $ λ n, a^n * (power_series.coeff R n f),
map_zero' := by { ext, simp only [linear_map.map_zero, power_series.coeff_mk, mul_zero], },
map_one' := by { ext1, simp only [mul_boole, power_series.coeff_mk, power_series.coeff_one],
split_ifs, { rw [h, pow_zero], }, refl, },
map_add' := by { intros, ext, exact mul_add _ _ _, },
map_mul' := λ f g, by
{ ext,
rw [power_series.coeff_mul, power_series.coeff_mk, power_series.coeff_mul, finset.mul_sum],
apply sum_congr rfl,
simp only [coeff_mk, prod.forall, nat.mem_antidiagonal],
intros b c H,
rw [←H, pow_add, mul_mul_mul_comm] }, }
@[simp] lemma coeff_rescale (f : power_series R) (a : R) (n : ℕ) :
coeff R n (rescale a f) = a^n * coeff R n f := coeff_mk n _
@[simp] lemma rescale_zero : rescale 0 = (C R).comp (constant_coeff R) :=
begin
ext,
simp only [function.comp_app, ring_hom.coe_comp, rescale, ring_hom.coe_mk,
power_series.coeff_mk _ _, coeff_C],
split_ifs,
{ simp only [h, one_mul, coeff_zero_eq_constant_coeff, pow_zero], },
{ rw [zero_pow' n h, zero_mul], },
end
lemma rescale_zero_apply : rescale 0 X = C R (constant_coeff R X) :=
by simp
@[simp] lemma rescale_one : rescale 1 = ring_hom.id (power_series R) :=
by { ext, simp only [ring_hom.id_apply, rescale, one_pow, coeff_mk, one_mul,
ring_hom.coe_mk], }
section trunc
/-- The `n`th truncation of a formal power series to a polynomial -/
def trunc (n : ℕ) (φ : power_series R) : R[X] :=
∑ m in Ico 0 n, polynomial.monomial m (coeff R m φ)
lemma coeff_trunc (m) (n) (φ : power_series R) :
(trunc n φ).coeff m = if m < n then coeff R m φ else 0 :=
by simp [trunc, polynomial.coeff_sum, polynomial.coeff_monomial, nat.lt_succ_iff]
@[simp] lemma trunc_zero (n) : trunc n (0 : power_series R) = 0 :=
polynomial.ext $ λ m,
begin
rw [coeff_trunc, linear_map.map_zero, polynomial.coeff_zero],
split_ifs; refl
end
@[simp] lemma trunc_one (n) : trunc (n + 1) (1 : power_series R) = 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 _,
rintro rfl, apply H, exact nat.zero_lt_succ _ }
end
@[simp] lemma trunc_C (n) (a : R) : trunc (n + 1) (C R 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 R) :
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 R]
/-- Auxiliary function used for computing inverse of a power series -/
protected def inv.aux : R → power_series R → power_series R :=
mv_power_series.inv.aux
lemma coeff_inv_aux (n : ℕ) (a : R) (φ : power_series R) :
coeff R n (inv.aux a φ) = if n = 0 then a else
- a * ∑ x in finset.nat.antidiagonal n,
if x.2 < n then coeff R x.1 φ * coeff R 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, ← 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 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 R) (u : Rˣ) : power_series R :=
mv_power_series.inv_of_unit φ u
lemma coeff_inv_of_unit (n : ℕ) (φ : power_series R) (u : Rˣ) :
coeff R n (inv_of_unit φ u) = if n = 0 then ↑u⁻¹ else
- ↑u⁻¹ * ∑ x in finset.nat.antidiagonal n,
if x.2 < n then coeff R x.1 φ * coeff R x.2 (inv_of_unit φ u) else 0 :=
coeff_inv_aux n ↑u⁻¹ φ
@[simp] lemma constant_coeff_inv_of_unit (φ : power_series R) (u : Rˣ) :
constant_coeff R (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 R) (u : Rˣ) (h : constant_coeff R φ = u) :
φ * inv_of_unit φ u = 1 :=
mv_power_series.mul_inv_of_unit φ u $ h
/-- Two ways of removing the constant coefficient of a power series are the same. -/
lemma sub_const_eq_shift_mul_X (φ : power_series R) :
φ - C R (constant_coeff R φ) = power_series.mk (λ p, coeff R (p + 1) φ) * X :=
sub_eq_iff_eq_add.mpr (eq_shift_mul_X_add_const φ)
lemma sub_const_eq_X_mul_shift (φ : power_series R) :
φ - C R (constant_coeff R φ) = X * power_series.mk (λ p, coeff R (p + 1) φ) :=
sub_eq_iff_eq_add.mpr (eq_X_mul_shift_add_const φ)
end ring
section comm_ring
variables {A : Type*} [comm_ring A]
@[simp] lemma rescale_neg_one_X : rescale (-1 : A) X = -X :=
begin
ext, simp only [linear_map.map_neg, coeff_rescale, coeff_X],
split_ifs with h; simp [h]
end
/-- The ring homomorphism taking a power series `f(X)` to `f(-X)`. -/
noncomputable def eval_neg_hom : power_series A →+* power_series A :=
rescale (-1 : A)
@[simp] lemma eval_neg_hom_X : eval_neg_hom (X : power_series A) = -X :=
rescale_neg_one_X
end comm_ring
section domain
variables [ring R] [is_domain R]
lemma eq_zero_or_eq_zero_of_mul_eq_zero (φ ψ : power_series R) (h : φ * ψ = 0) :
φ = 0 ∨ ψ = 0 :=
begin
rw or_iff_not_imp_left, intro H,
have ex : ∃ m, coeff R m φ ≠ 0, { contrapose! H, exact ext H },
let m := nat.find ex,
have hm₁ : coeff R m φ ≠ 0 := nat.find_spec ex,
have hm₂ : ∀ k < m, ¬coeff R k φ ≠ 0 := λ k, nat.find_min ex,
ext n, rw (coeff R n).map_zero, apply nat.strong_induction_on n,
clear n, intros n ih,
replace h := congr_arg (coeff R (m + n)) h,
rw [linear_map.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,
obtain rfl := le_antisymm hi hne,
simpa [ne.def, prod.mk.inj_iff] using (add_right_inj m).mp hij },
{ contrapose!, intro h, rw finset.nat.mem_antidiagonal }
end
instance : is_domain (power_series R) :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := eq_zero_or_eq_zero_of_mul_eq_zero,
.. power_series.nontrivial, }
end domain
section is_domain
variables [comm_ring R] [is_domain R]
/-- 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 R))).is_prime :=
begin
suffices : ideal.span ({X} : set (power_series R)) = (constant_coeff R).ker,
{ rw this, exact ring_hom.ker_is_prime _ },
apply ideal.ext, intro φ,
rw [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 R) :=
begin
rw ← ideal.span_singleton_prime,
{ exact span_X_is_prime },
{ intro h, simpa using congr_arg (coeff R 1) h }
end
lemma rescale_injective {a : R} (ha : a ≠ 0) : function.injective (rescale a) :=
begin
intros p q h,
rw power_series.ext_iff at *,
intros n,
specialize h n,
rw [coeff_rescale, coeff_rescale, mul_eq_mul_left_iff] at h,
apply h.resolve_right,
intro h',
exact ha (pow_eq_zero h'),
end
end is_domain
section local_ring
variables {S : Type*} [comm_ring R] [comm_ring S]
(f : R →+* S) [is_local_ring_hom f]
instance map.is_local_ring_hom : is_local_ring_hom (map f) :=
mv_power_series.map.is_local_ring_hom f
variables [local_ring R] [local_ring S]
instance : local_ring (power_series R) :=
mv_power_series.local_ring
end local_ring
section algebra
variables {A : Type*} [comm_semiring R] [semiring A] [algebra R A]
theorem C_eq_algebra_map {r : R} : C R r = (algebra_map R (power_series R)) r := rfl
theorem algebra_map_apply {r : R} :
algebra_map R (power_series A) r = C A (algebra_map R A r) :=
mv_power_series.algebra_map_apply
instance [nontrivial R] : nontrivial (subalgebra R (power_series R)) :=
mv_power_series.subalgebra.nontrivial
end algebra
section field
variables {k : Type*} [field k]
/-- The inverse 1/f of a power series f defined over a field -/
protected def inv : power_series k → power_series k :=
mv_power_series.inv
instance : has_inv (power_series k) := ⟨power_series.inv⟩
lemma inv_eq_inv_aux (φ : power_series k) :
φ⁻¹ = inv.aux (constant_coeff k φ)⁻¹ φ := rfl
lemma coeff_inv (n) (φ : power_series k) :
coeff k n (φ⁻¹) = if n = 0 then (constant_coeff k φ)⁻¹ else
- (constant_coeff k φ)⁻¹ * ∑ x in finset.nat.antidiagonal n,
if x.2 < n then coeff k x.1 φ * coeff k x.2 (φ⁻¹) else 0 :=
by rw [inv_eq_inv_aux, coeff_inv_aux n (constant_coeff k φ)⁻¹ φ]
@[simp] lemma constant_coeff_inv (φ : power_series k) :
constant_coeff k (φ⁻¹) = (constant_coeff k φ)⁻¹ :=
mv_power_series.constant_coeff_inv φ
lemma inv_eq_zero {φ : power_series k} :
φ⁻¹ = 0 ↔ constant_coeff k φ = 0 :=
mv_power_series.inv_eq_zero
@[simp] lemma zero_inv : (0 : power_series k)⁻¹ = 0 := mv_power_series.zero_inv
@[simp, priority 1100] lemma inv_of_unit_eq (φ : power_series k) (h : constant_coeff k φ ≠ 0) :
inv_of_unit φ (units.mk0 _ h) = φ⁻¹ :=
mv_power_series.inv_of_unit_eq _ _
@[simp] lemma inv_of_unit_eq' (φ : power_series k) (u : units k) (h : constant_coeff k φ = u) :
inv_of_unit φ u = φ⁻¹ :=
mv_power_series.inv_of_unit_eq' φ _ h
@[simp] protected lemma mul_inv_cancel (φ : power_series k) (h : constant_coeff k φ ≠ 0) :
φ * φ⁻¹ = 1 :=
mv_power_series.mul_inv_cancel φ h
@[simp] protected lemma inv_mul_cancel (φ : power_series k) (h : constant_coeff k φ ≠ 0) :
φ⁻¹ * φ = 1 :=
mv_power_series.inv_mul_cancel φ h
lemma eq_mul_inv_iff_mul_eq {φ₁ φ₂ φ₃ : power_series k} (h : constant_coeff k φ₃ ≠ 0) :
φ₁ = φ₂ * φ₃⁻¹ ↔ φ₁ * φ₃ = φ₂ :=
mv_power_series.eq_mul_inv_iff_mul_eq h
lemma eq_inv_iff_mul_eq_one {φ ψ : power_series k} (h : constant_coeff k ψ ≠ 0) :
φ = ψ⁻¹ ↔ φ * ψ = 1 :=
mv_power_series.eq_inv_iff_mul_eq_one h
lemma inv_eq_iff_mul_eq_one {φ ψ : power_series k} (h : constant_coeff k ψ ≠ 0) :
ψ⁻¹ = φ ↔ φ * ψ = 1 :=
mv_power_series.inv_eq_iff_mul_eq_one h
@[simp] protected lemma mul_inv_rev (φ ψ : power_series k) :
(φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ :=
mv_power_series.mul_inv_rev _ _
@[simp] lemma inv_one : (1 : power_series k)⁻¹ = 1 :=
mv_power_series.inv_one
@[simp] lemma C_inv (r : k) : (C k r)⁻¹ = C k r⁻¹ :=
mv_power_series.C_inv _
@[simp] lemma X_inv : (X : power_series k)⁻¹ = 0 :=
mv_power_series.X_inv _
@[simp] lemma smul_inv (r : k) (φ : power_series k) :
(r • φ)⁻¹ = r⁻¹ • φ⁻¹ :=
mv_power_series.smul_inv _ _
end field
end power_series
namespace power_series
variable {R : Type*}
local attribute [instance, priority 1] classical.prop_decidable
noncomputable theory
section order_basic
open multiplicity
variables [semiring R] {φ : power_series R}
lemma exists_coeff_ne_zero_iff_ne_zero : (∃ (n : ℕ), coeff R n φ ≠ 0) ↔ φ ≠ 0 :=
begin
refine not_iff_not.mp _,
push_neg,
simp [power_series.ext_iff]
end
/-- The order of a formal power series `φ` is the greatest `n : enat`
such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/
def order (φ : power_series R) : enat :=
if h : φ = 0 then ⊤ else nat.find (exists_coeff_ne_zero_iff_ne_zero.mpr h)
/-- The order of the `0` power series is infinite.-/
@[simp] lemma order_zero : order (0 : power_series R) = ⊤ := dif_pos rfl
lemma order_finite_iff_ne_zero : (order φ).dom ↔ φ ≠ 0 :=
begin
simp only [order],
split,
{ split_ifs with h h; intro H,
{ contrapose! H,
simpa [←part.eq_none_iff'] },
{ exact h } },
{ intro h,
simp [h] }
end
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero.-/
lemma coeff_order (h : (order φ).dom) :
coeff R (φ.order.get h) φ ≠ 0 :=
begin
simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, enat.get_coe'],
generalize_proofs h,
exact nat.find_spec h
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 (n : ℕ) (h : coeff R n φ ≠ 0) :
order φ ≤ n :=
begin
have := exists.intro n h,
rw [order, dif_neg],
{ simp only [enat.coe_le_coe, nat.find_le_iff],
exact ⟨n, le_rfl, h⟩ },
{ exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, 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 (n : ℕ) (h: ↑n < order φ) :
coeff R n φ = 0 :=
by { contrapose! h, exact order_le _ h }
/-- The `0` power series is the unique power series with infinite order.-/
@[simp] lemma order_eq_top {φ : power_series R} :
φ.order = ⊤ ↔ φ = 0 :=
begin
split,
{ intro h, ext n, rw [(coeff R n).map_zero, coeff_of_lt_order], simp [h] },
{ rintros rfl, exact order_zero }
end
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`.-/
lemma nat_le_order (φ : power_series R) (n : ℕ) (h : ∀ i < n, coeff R i φ = 0) :
↑n ≤ order φ :=
begin
by_contra H, rw not_le at H,
have : (order φ).dom := enat.dom_of_le_coe H.le,
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 le_order (φ : power_series R) (n : enat) (h : ∀ i : ℕ, ↑i < n → coeff R i φ = 0) :
n ≤ order φ :=
begin
induction n using enat.cases_on,
{ show _ ≤ _, rw [top_le_iff, order_eq_top],
ext i, exact h _ (enat.coe_lt_top i) },
{ apply nat_le_order, 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 R} {n : ℕ} :
order φ = n ↔ (coeff R n φ ≠ 0) ∧ (∀ i, i < n → coeff R i φ = 0) :=
begin
rcases eq_or_ne φ 0 with rfl|hφ,
{ simpa using (enat.coe_ne_top _).symm },
simp [order, dif_neg hφ, nat.find_eq_iff]
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 R} {n : enat} :
order φ = n ↔ (∀ i:ℕ, ↑i = n → coeff R i φ ≠ 0) ∧ (∀ i:ℕ, ↑i < n → coeff R 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 le_order_add (φ ψ : power_series R) :
min (order φ) (order ψ) ≤ order (φ + ψ) :=
begin
refine le_order _ _ _,
simp [coeff_of_lt_order] {contextual := tt}
end
private lemma order_add_of_order_eq.aux (φ ψ : power_series R)
(h : order φ ≠ order ψ) (H : order φ < order ψ) :
order (φ + ψ) ≤ order φ ⊓ order ψ :=
begin
suffices : order (φ + ψ) = order φ,
{ rw [le_inf_iff, this], exact ⟨le_rfl, le_of_lt H⟩ },
{ rw order_eq, split,
{ intros i hi, rw ←hi at H, rw [(coeff _ _).map_add, coeff_of_lt_order i 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 R) (h : order φ ≠ order ψ) :
order (φ + ψ) = order φ ⊓ order ψ :=
begin
refine le_antisymm _ (le_order_add _ _),
by_cases H₁ : order φ < order ψ,
{ apply order_add_of_order_eq.aux _ _ h H₁ },
by_cases H₂ : order ψ < order φ,
{ simpa only [add_comm, 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 R) :
order φ + order ψ ≤ order (φ * ψ) :=
begin
apply le_order,
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 [← nat.cast_add, hij]
end
/-- The order of the monomial `a*X^n` is infinite if `a = 0` and `n` otherwise.-/
lemma order_monomial (n : ℕ) (a : R) [decidable (a = 0)] :
order (monomial R n a) = if a = 0 then ⊤ else n :=
begin
split_ifs with h,
{ rw [h, order_eq_top, linear_map.map_zero] },
{ rw [order_eq], split; intros i hi,
{ rw [enat.coe_inj] at hi, rwa [hi, coeff_monomial_same] },
{ 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 : R) (h : a ≠ 0) :
order (monomial R n a) = n :=
by rw [order_monomial, if_neg h]
/-- If `n` is strictly smaller than the order of `ψ`, then the `n`th coefficient of its product
with any other power series is `0`. -/
lemma coeff_mul_of_lt_order {φ ψ : power_series R} {n : ℕ} (h : ↑n < ψ.order) :
coeff R n (φ * ψ) = 0 :=
begin
suffices : coeff R n (φ * ψ) = ∑ p in finset.nat.antidiagonal n, 0,
rw [this, finset.sum_const_zero],
rw [coeff_mul],
apply finset.sum_congr rfl (λ x hx, _),
refine mul_eq_zero_of_right (coeff R x.fst φ) (coeff_of_lt_order x.snd (lt_of_le_of_lt _ h)),
rw finset.nat.mem_antidiagonal at hx,
norm_cast,
linarith,
end
lemma coeff_mul_one_sub_of_lt_order {R : Type*} [comm_ring R] {φ ψ : power_series R}
(n : ℕ) (h : ↑n < ψ.order) :
coeff R n (φ * (1 - ψ)) = coeff R n φ :=
by simp [coeff_mul_of_lt_order h, mul_sub]
lemma coeff_mul_prod_one_sub_of_lt_order {R ι : Type*} [comm_ring R] (k : ℕ) (s : finset ι)
(φ : power_series R) (f : ι → power_series R) :
(∀ i ∈ s, ↑k < (f i).order) → coeff R k (φ * ∏ i in s, (1 - f i)) = coeff R k φ :=
begin
apply finset.induction_on s,
{ simp },
{ intros a s ha ih t,
simp only [finset.mem_insert, forall_eq_or_imp] at t,
rw [finset.prod_insert ha, ← mul_assoc, mul_right_comm, coeff_mul_one_sub_of_lt_order _ t.1],
exact ih t.2 },
end
-- TODO: link with `X_pow_dvd_iff`
lemma X_pow_order_dvd (h : (order φ).dom) : X ^ ((order φ).get h) ∣ φ :=
begin
refine ⟨power_series.mk (λ n, coeff R (n + (order φ).get h) φ), _⟩,
ext n,
simp only [coeff_mul, coeff_X_pow, coeff_mk, boole_mul, finset.sum_ite,
finset.nat.filter_fst_eq_antidiagonal, finset.sum_const_zero, add_zero],
split_ifs with hn hn,
{ simp [tsub_add_cancel_of_le hn] },
{ simp only [finset.sum_empty],
refine coeff_of_lt_order _ _,
simpa [enat.coe_lt_iff] using λ _, hn }
end
lemma order_eq_multiplicity_X {R : Type*} [comm_semiring R] (φ : power_series R) :
order φ = multiplicity X φ :=
begin
rcases eq_or_ne φ 0 with rfl|hφ,
{ simp },
induction ho : order φ using enat.cases_on with n,
{ simpa [hφ] using ho },
have hn : φ.order.get (order_finite_iff_ne_zero.mpr hφ) = n,
{ simp [ho] },
rw ←hn,
refine le_antisymm (le_multiplicity_of_pow_dvd $ X_pow_order_dvd
(order_finite_iff_ne_zero.mpr hφ)) (enat.find_le _ _ _),
rintro ⟨ψ, H⟩,
have := congr_arg (coeff R n) H,
rw [mul_comm, coeff_mul_of_lt_order, ←hn] at this,
{ exact coeff_order _ this },
{ rw [X_pow_eq, order_monomial],
split_ifs,
{ exact enat.coe_lt_top _ },
{ rw [←hn, enat.coe_lt_coe],
exact nat.lt_succ_self _ } }
end
end order_basic
section order_zero_ne_one
variables [semiring R] [nontrivial R]
/-- The order of the formal power series `1` is `0`.-/
@[simp] lemma order_one : order (1 : power_series R) = 0 :=
by simpa using order_monomial_of_ne_zero 0 (1:R) one_ne_zero
/-- The order of the formal power series `X` is `1`.-/
@[simp] lemma order_X : order (X : power_series R) = 1 :=
by simpa only [nat.cast_one] using order_monomial_of_ne_zero 1 (1:R) one_ne_zero
/-- The order of the formal power series `X^n` is `n`.-/
@[simp] lemma order_X_pow (n : ℕ) : order ((X : power_series R)^n) = n :=
by { rw [X_pow_eq, order_monomial_of_ne_zero], exact one_ne_zero }
end order_zero_ne_one
section order_is_domain
-- TODO: generalize to `[semiring R] [no_zero_divisors R]`
variables [comm_ring R] [is_domain R]
/-- 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 R) :
order (φ * ψ) = order φ + order ψ :=
begin
simp_rw [order_eq_multiplicity_X],
exact multiplicity.mul X_prime
end
end order_is_domain
end power_series
namespace polynomial
open finsupp
variables {σ : Type*} {R : Type*} [comm_semiring R] (φ ψ : R[X])
/-- The natural inclusion from polynomials into formal power series.-/
instance coe_to_power_series : has_coe R[X] (power_series R) :=
⟨λ φ, power_series.mk $ λ n, coeff φ n⟩
lemma coe_def : (φ : power_series R) = power_series.mk (coeff φ) := rfl
@[simp, norm_cast] lemma coeff_coe (n) :
power_series.coeff R n φ = coeff φ n :=
congr_arg (coeff φ) (finsupp.single_eq_same)
@[simp, norm_cast] lemma coe_monomial (n : ℕ) (a : R) :
(monomial n a : power_series R) = power_series.monomial R n a :=
by { ext, simp [coeff_coe, power_series.coeff_monomial, polynomial.coeff_monomial, eq_comm] }
@[simp, norm_cast] lemma coe_zero : ((0 : R[X]) : power_series R) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : R[X]) : power_series R) = 1 :=
begin
have := coe_monomial 0 (1:R),
rwa power_series.monomial_zero_eq_C_apply at this,
end
@[simp, norm_cast] lemma coe_add :
((φ + ψ : R[X]) : power_series R) = φ + ψ :=
by { ext, simp }
@[simp, norm_cast] lemma coe_mul :
((φ * ψ : R[X]) : power_series R) = φ * ψ :=
power_series.ext $ λ n,
by simp only [coeff_coe, power_series.coeff_mul, coeff_mul]
@[simp, norm_cast] lemma coe_C (a : R) :
((C a : R[X]) : power_series R) = power_series.C R a :=
begin
have := coe_monomial 0 a,
rwa power_series.monomial_zero_eq_C_apply at this,
end
@[simp, norm_cast] lemma coe_bit0 :
((bit0 φ : R[X]) : power_series R) = bit0 (φ : power_series R) :=
coe_add φ φ
@[simp, norm_cast] lemma coe_bit1 :
((bit1 φ : R[X]) : power_series R) = bit1 (φ : power_series R) :=
by rw [bit1, bit1, coe_add, coe_one, coe_bit0]
@[simp, norm_cast] lemma coe_X :
((X : R[X]) : power_series R) = power_series.X :=
coe_monomial _ _
@[simp] lemma constant_coeff_coe : power_series.constant_coeff R φ = φ.coeff 0 := rfl
variables (R)
lemma coe_injective : function.injective (coe : R[X] → power_series R) :=
λ x y h, by { ext, simp_rw [←coeff_coe, h] }
variables {R φ ψ}
@[simp, norm_cast] lemma coe_inj : (φ : power_series R) = ψ ↔ φ = ψ :=
(coe_injective R).eq_iff
@[simp] lemma coe_eq_zero_iff : (φ : power_series R) = 0 ↔ φ = 0 :=
by rw [←coe_zero, coe_inj]
@[simp] lemma coe_eq_one_iff : (φ : power_series R) = 1 ↔ φ = 1 :=
by rw [←coe_one, coe_inj]
variables (φ ψ)
/--
The coercion from polynomials to power series
as a ring homomorphism.
-/
def coe_to_power_series.ring_hom : R[X] →+* power_series R :=
{ to_fun := (coe : R[X] → power_series R),
map_zero' := coe_zero,
map_one' := coe_one,
map_add' := coe_add,
map_mul' := coe_mul }
@[simp] lemma coe_to_power_series.ring_hom_apply : coe_to_power_series.ring_hom φ = φ := rfl
@[simp, norm_cast] lemma coe_pow (n : ℕ):
((φ ^ n : R[X]) : power_series R) = (φ : power_series R) ^ n :=
coe_to_power_series.ring_hom.map_pow _ _
variables (A : Type*) [semiring A] [algebra R A]
/--
The coercion from polynomials to power series
as an algebra homomorphism.
-/
def coe_to_power_series.alg_hom : R[X] →ₐ[R] power_series A :=
{ commutes' := λ r, by simp [algebra_map_apply, power_series.algebra_map_apply],
..(power_series.map (algebra_map R A)).comp coe_to_power_series.ring_hom }
@[simp] lemma coe_to_power_series.alg_hom_apply : (coe_to_power_series.alg_hom A φ) =
power_series.map (algebra_map R A) ↑φ := rfl
end polynomial
namespace power_series
variables {R A : Type*} [comm_semiring R] [comm_semiring A] [algebra R A] (f : power_series R)
instance algebra_polynomial : algebra R[X] (power_series A) :=
ring_hom.to_algebra (polynomial.coe_to_power_series.alg_hom A).to_ring_hom
instance algebra_power_series : algebra (power_series R) (power_series A) :=
(map (algebra_map R A)).to_algebra
@[priority 100] -- see Note [lower instance priority]
instance algebra_polynomial' {A : Type*} [comm_semiring A] [algebra R (polynomial A)] :
algebra R (power_series A) :=
ring_hom.to_algebra $ polynomial.coe_to_power_series.ring_hom.comp (algebra_map R (polynomial A))
variables (A)
lemma algebra_map_apply' (p : R[X]) :
algebra_map R[X] (power_series A) p = map (algebra_map R A) p := rfl
lemma algebra_map_apply'' :
algebra_map (power_series R) (power_series A) f = map (algebra_map R A) f := rfl
end power_series
|
c2671dfc79e53d9b505fa331e53013f2a1d96f68 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/lie/basic.lean | bb4a258425fd7c3390e59644b43321fa9e2e9f4e | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 28,872 | lean | /-
Copyright (c) 2019 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import tactic.noncomm_ring
import data.equiv.module
import data.bracket
/-!
# Lie algebras
This file defines Lie rings and Lie algebras over a commutative ring together with their
modules, morphisms and equivalences, as well as various lemmas to make these definitions usable.
## Main definitions
* `lie_ring`
* `lie_algebra`
* `lie_ring_module`
* `lie_module`
* `lie_hom`
* `lie_equiv`
* `lie_module_hom`
* `lie_module_equiv`
## Notation
Working over a fixed commutative ring `R`, we introduce the notations:
* `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras,
* `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras,
* `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`,
* `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`.
## Implementation notes
Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules,
are partially unbundled.
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975)
## Tags
lie bracket, jacobi identity, lie ring, lie algebra, lie module
-/
universes u v w w₁ w₂
open function
/-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the
Jacobi identity. -/
@[protect_proj] class lie_ring (L : Type v) extends add_comm_group L, has_bracket L L :=
(add_lie : ∀ (x y z : L), ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆)
(lie_add : ∀ (x y z : L), ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆)
(lie_self : ∀ (x : L), ⁅x, x⁆ = 0)
(leibniz_lie : ∀ (x y z : L), ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆)
/-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi
identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/
@[protect_proj] class lie_algebra (R : Type u) (L : Type v) [comm_ring R] [lie_ring L]
extends module R L :=
(lie_smul : ∀ (t : R) (x y : L), ⁅x, t • y⁆ = t • ⁅x, y⁆)
/-- A Lie ring module is an additive group, together with an additive action of a
Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms.
(For representations of Lie *algebras* see `lie_module`.) -/
@[protect_proj] class lie_ring_module (L : Type v) (M : Type w)
[lie_ring L] [add_comm_group M] extends has_bracket L M :=
(add_lie : ∀ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆)
(lie_add : ∀ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆)
(leibniz_lie : ∀ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆)
/-- A Lie module is a module over a commutative ring, together with a linear action of a Lie
algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/
@[protect_proj] class lie_module (R : Type u) (L : Type v) (M : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [add_comm_group M] [module R M]
[lie_ring_module L M] :=
(smul_lie : ∀ (t : R) (x : L) (m : M), ⁅t • x, m⁆ = t • ⁅x, m⁆)
(lie_smul : ∀ (t : R) (x : L) (m : M), ⁅x, t • m⁆ = t • ⁅x, m⁆)
section basic_properties
variables {R : Type u} {L : Type v} {M : Type w} {N : Type w₁}
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
variables [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
variables [add_comm_group N] [module R N] [lie_ring_module L N] [lie_module R L N]
variables (t : R) (x y z : L) (m n : M)
@[simp] lemma add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := lie_ring_module.add_lie x y m
@[simp] lemma lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := lie_ring_module.lie_add x m n
@[simp] lemma smul_lie : ⁅t • x, m⁆ = t • ⁅x, m⁆ := lie_module.smul_lie t x m
@[simp] lemma lie_smul : ⁅x, t • m⁆ = t • ⁅x, m⁆ := lie_module.lie_smul t x m
lemma leibniz_lie : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := lie_ring_module.leibniz_lie x y m
@[simp] lemma lie_zero : ⁅x, 0⁆ = (0 : M) := (add_monoid_hom.mk' _ (lie_add x)).map_zero
@[simp] lemma zero_lie : ⁅(0 : L), m⁆ = 0 :=
(add_monoid_hom.mk' (λ (x : L), ⁅x, m⁆) (λ x y, add_lie x y m)).map_zero
@[simp] lemma lie_self : ⁅x, x⁆ = 0 := lie_ring.lie_self x
instance lie_ring_self_module : lie_ring_module L L := { ..(infer_instance : lie_ring L) }
@[simp] lemma lie_skew : -⁅y, x⁆ = ⁅x, y⁆ :=
have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0, { rw ← lie_add, apply lie_self, },
by simpa [neg_eq_iff_add_eq_zero] using h
/-- Every Lie algebra is a module over itself. -/
instance lie_algebra_self_module : lie_module R L L :=
{ smul_lie := λ t x m, by rw [←lie_skew, ←lie_skew x m, lie_algebra.lie_smul, smul_neg],
lie_smul := by apply lie_algebra.lie_smul, }
@[simp] lemma neg_lie : ⁅-x, m⁆ = -⁅x, m⁆ :=
by { rw [←sub_eq_zero, sub_neg_eq_add, ←add_lie], simp, }
@[simp] lemma lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ :=
by { rw [←sub_eq_zero, sub_neg_eq_add, ←lie_add], simp, }
@[simp] lemma sub_lie : ⁅x - y, m⁆ = ⁅x, m⁆ - ⁅y, m⁆ :=
by simp [sub_eq_add_neg]
@[simp] lemma lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ :=
by simp [sub_eq_add_neg]
@[simp] lemma nsmul_lie (n : ℕ) : ⁅n • x, m⁆ = n • ⁅x, m⁆ :=
add_monoid_hom.map_nsmul ⟨λ (x : L), ⁅x, m⁆, zero_lie m, λ _ _, add_lie _ _ _⟩ _ _
@[simp] lemma lie_nsmul (n : ℕ) : ⁅x, n • m⁆ = n • ⁅x, m⁆ :=
add_monoid_hom.map_nsmul ⟨λ (m : M), ⁅x, m⁆, lie_zero x, λ _ _, lie_add _ _ _⟩ _ _
@[simp] lemma zsmul_lie (a : ℤ) : ⁅a • x, m⁆ = a • ⁅x, m⁆ :=
add_monoid_hom.map_zsmul ⟨λ (x : L), ⁅x, m⁆, zero_lie m, λ _ _, add_lie _ _ _⟩ _ _
@[simp] lemma lie_zsmul (a : ℤ) : ⁅x, a • m⁆ = a • ⁅x, m⁆ :=
add_monoid_hom.map_zsmul ⟨λ (m : M), ⁅x, m⁆, lie_zero x, λ _ _, lie_add _ _ _⟩ _ _
@[simp] lemma lie_lie : ⁅⁅x, y⁆, m⁆ = ⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆ :=
by rw [leibniz_lie, add_sub_cancel]
lemma lie_jacobi : ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 :=
by { rw [← neg_neg ⁅x, y⁆, lie_neg z, lie_skew y x, ← lie_skew, lie_lie], abel, }
instance lie_ring.int_lie_algebra : lie_algebra ℤ L :=
{ lie_smul := λ n x y, lie_zsmul x y n, }
instance : lie_ring_module L (M →ₗ[R] N) :=
{ bracket := λ x f,
{ to_fun := λ m, ⁅x, f m⁆ - f ⁅x, m⁆,
map_add' := λ m n, by { simp only [lie_add, linear_map.map_add], abel, },
map_smul' := λ t m, by simp only [smul_sub, linear_map.map_smul, lie_smul, ring_hom.id_apply] },
add_lie := λ x y f, by
{ ext n, simp only [add_lie, linear_map.coe_mk, linear_map.add_apply, linear_map.map_add],
abel, },
lie_add := λ x f g, by
{ ext n, simp only [linear_map.coe_mk, lie_add, linear_map.add_apply], abel, },
leibniz_lie := λ x y f, by
{ ext n,
simp only [lie_lie, linear_map.coe_mk, linear_map.map_sub, linear_map.add_apply, lie_sub],
abel, }, }
@[simp] lemma lie_hom.lie_apply (f : M →ₗ[R] N) (x : L) (m : M) :
⁅x, f⁆ m = ⁅x, f m⁆ - f ⁅x, m⁆ :=
rfl
instance : lie_module R L (M →ₗ[R] N) :=
{ smul_lie := λ t x f, by
{ ext n,
simp only [smul_sub, smul_lie, linear_map.smul_apply, lie_hom.lie_apply,
linear_map.map_smul], },
lie_smul := λ t x f, by
{ ext n, simp only [smul_sub, linear_map.smul_apply, lie_hom.lie_apply, lie_smul], }, }
end basic_properties
/-- A morphism of Lie algebras is a linear map respecting the bracket operations. -/
structure lie_hom (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends L →ₗ[R] L' :=
(map_lie' : ∀ {x y : L}, to_fun ⁅x, y⁆ = ⁅to_fun x, to_fun y⁆)
attribute [nolint doc_blame] lie_hom.to_linear_map
notation L ` →ₗ⁅`:25 R:25 `⁆ `:0 L':0 := lie_hom R L L'
namespace lie_hom
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R]
variables [lie_ring L₁] [lie_algebra R L₁]
variables [lie_ring L₂] [lie_algebra R L₂]
variables [lie_ring L₃] [lie_algebra R L₃]
instance : has_coe (L₁ →ₗ⁅R⁆ L₂) (L₁ →ₗ[R] L₂) := ⟨lie_hom.to_linear_map⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ →ₗ⁅R⁆ L₂) (λ _, L₁ → L₂) := ⟨λ f, f.to_linear_map.to_fun⟩
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂ := h
initialize_simps_projections lie_hom (to_linear_map_to_fun → apply)
@[simp, norm_cast] lemma coe_to_linear_map (f : L₁ →ₗ⁅R⁆ L₂) : ((f : L₁ →ₗ[R] L₂) : L₁ → L₂) = f :=
rfl
@[simp] lemma to_fun_eq_coe (f : L₁ →ₗ⁅R⁆ L₂) : f.to_fun = ⇑f := rfl
@[simp] lemma map_smul (f : L₁ →ₗ⁅R⁆ L₂) (c : R) (x : L₁) : f (c • x) = c • f x :=
linear_map.map_smul (f : L₁ →ₗ[R] L₂) c x
@[simp] lemma map_add (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x + y) = (f x) + (f y) :=
linear_map.map_add (f : L₁ →ₗ[R] L₂) x y
@[simp] lemma map_sub (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f (x - y) = (f x) - (f y) :=
linear_map.map_sub (f : L₁ →ₗ[R] L₂) x y
@[simp] lemma map_neg (f : L₁ →ₗ⁅R⁆ L₂) (x : L₁) : f (-x) = -(f x) :=
linear_map.map_neg (f : L₁ →ₗ[R] L₂) x
@[simp] lemma map_lie (f : L₁ →ₗ⁅R⁆ L₂) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := lie_hom.map_lie' f
@[simp] lemma map_zero (f : L₁ →ₗ⁅R⁆ L₂) : f 0 = 0 := (f : L₁ →ₗ[R] L₂).map_zero
/-- The identity map is a morphism of Lie algebras. -/
def id : L₁ →ₗ⁅R⁆ L₁ :=
{ map_lie' := λ x y, rfl,
.. (linear_map.id : L₁ →ₗ[R] L₁) }
@[simp] lemma coe_id : ((id : L₁ →ₗ⁅R⁆ L₁) : L₁ → L₁) = _root_.id := rfl
lemma id_apply (x : L₁) : (id : L₁ →ₗ⁅R⁆ L₁) x = x := rfl
/-- The constant 0 map is a Lie algebra morphism. -/
instance : has_zero (L₁ →ₗ⁅R⁆ L₂) := ⟨{ map_lie' := by simp, ..(0 : L₁ →ₗ[R] L₂)}⟩
@[norm_cast, simp] lemma coe_zero : ((0 : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = 0 := rfl
lemma zero_apply (x : L₁) : (0 : L₁ →ₗ⁅R⁆ L₂) x = 0 := rfl
/-- The identity map is a Lie algebra morphism. -/
instance : has_one (L₁ →ₗ⁅R⁆ L₁) := ⟨id⟩
@[simp] lemma coe_one : ((1 : (L₁ →ₗ⁅R⁆ L₁)) : L₁ → L₁) = _root_.id := rfl
lemma one_apply (x : L₁) : (1 : (L₁ →ₗ⁅R⁆ L₁)) x = x := rfl
instance : inhabited (L₁ →ₗ⁅R⁆ L₂) := ⟨0⟩
lemma coe_injective : @function.injective (L₁ →ₗ⁅R⁆ L₂) (L₁ → L₂) coe_fn :=
by rintro ⟨⟨f, _⟩⟩ ⟨⟨g, _⟩⟩ ⟨h⟩; congr
@[ext] lemma ext {f g : L₁ →ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g :=
coe_injective $ funext h
lemma ext_iff {f g : L₁ →ₗ⁅R⁆ L₂} : f = g ↔ ∀ x, f x = g x :=
⟨by { rintro rfl x, refl }, ext⟩
lemma congr_fun {f g : L₁ →ₗ⁅R⁆ L₂} (h : f = g) (x : L₁) : f x = g x := h ▸ rfl
@[simp] lemma mk_coe (f : L₁ →ₗ⁅R⁆ L₂) (h₁ h₂ h₃) :
(⟨⟨f, h₁, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) = f :=
by { ext, refl, }
@[simp] lemma coe_mk (f : L₁ → L₂) (h₁ h₂ h₃) :
((⟨⟨f, h₁, h₂⟩, h₃⟩ : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = f := rfl
/-- The composition of morphisms is a morphism. -/
def comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) : L₁ →ₗ⁅R⁆ L₃ :=
{ map_lie' := λ x y, by { change f (g ⁅x, y⁆) = ⁅f (g x), f (g y)⁆, rw [map_lie, map_lie], },
..linear_map.comp f.to_linear_map g.to_linear_map }
lemma comp_apply (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) (x : L₁) :
f.comp g x = f (g x) := rfl
@[norm_cast, simp]
lemma coe_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) :
(f.comp g : L₁ → L₃) = f ∘ g :=
rfl
@[norm_cast, simp]
lemma coe_linear_map_comp (f : L₂ →ₗ⁅R⁆ L₃) (g : L₁ →ₗ⁅R⁆ L₂) :
(f.comp g : L₁ →ₗ[R] L₃) = (f : L₂ →ₗ[R] L₃).comp (g : L₁ →ₗ[R] L₂) :=
rfl
@[simp] lemma comp_id (f : L₁ →ₗ⁅R⁆ L₂) : f.comp (id : L₁ →ₗ⁅R⁆ L₁) = f :=
by { ext, refl, }
@[simp] lemma id_comp (f : L₁ →ₗ⁅R⁆ L₂) : (id : L₂ →ₗ⁅R⁆ L₂).comp f = f :=
by { ext, refl, }
/-- The inverse of a bijective morphism is a morphism. -/
def inverse (f : L₁ →ₗ⁅R⁆ L₂) (g : L₂ → L₁)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : L₂ →ₗ⁅R⁆ L₁ :=
{ map_lie' := λ x y,
calc g ⁅x, y⁆ = g ⁅f (g x), f (g y)⁆ : by { conv_lhs { rw [←h₂ x, ←h₂ y], }, }
... = g (f ⁅g x, g y⁆) : by rw map_lie
... = ⁅g x, g y⁆ : (h₁ _),
..linear_map.inverse f.to_linear_map g h₁ h₂ }
end lie_hom
/-- An equivalence of Lie algebras is a morphism which is also a linear equivalence. We could
instead define an equivalence to be a morphism which is also a (plain) equivalence. However it is
more convenient to define via linear equivalence to get `.to_linear_equiv` for free. -/
structure lie_equiv (R : Type u) (L : Type v) (L' : Type w)
[comm_ring R] [lie_ring L] [lie_algebra R L] [lie_ring L'] [lie_algebra R L']
extends L →ₗ⁅R⁆ L' :=
(inv_fun : L' → L)
(left_inv : function.left_inverse inv_fun to_lie_hom.to_fun)
(right_inv : function.right_inverse inv_fun to_lie_hom.to_fun)
attribute [nolint doc_blame] lie_equiv.to_lie_hom
notation L ` ≃ₗ⁅`:50 R `⁆ ` L' := lie_equiv R L L'
namespace lie_equiv
variables {R : Type u} {L₁ : Type v} {L₂ : Type w} {L₃ : Type w₁}
variables [comm_ring R] [lie_ring L₁] [lie_ring L₂] [lie_ring L₃]
variables [lie_algebra R L₁] [lie_algebra R L₂] [lie_algebra R L₃]
/-- Consider an equivalence of Lie algebras as a linear equivalence. -/
def to_linear_equiv (f : L₁ ≃ₗ⁅R⁆ L₂) : L₁ ≃ₗ[R] L₂ := { ..f.to_lie_hom, ..f }
instance has_coe_to_lie_hom : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ →ₗ⁅R⁆ L₂) := ⟨to_lie_hom⟩
instance has_coe_to_linear_equiv : has_coe (L₁ ≃ₗ⁅R⁆ L₂) (L₁ ≃ₗ[R] L₂) := ⟨to_linear_equiv⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (L₁ ≃ₗ⁅R⁆ L₂) (λ _, L₁ → L₂) := ⟨λ e, e.to_lie_hom.to_fun⟩
@[simp, norm_cast] lemma coe_to_lie_hom (e : L₁ ≃ₗ⁅R⁆ L₂) : ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) = e :=
rfl
@[simp, norm_cast] lemma coe_to_linear_equiv (e : L₁ ≃ₗ⁅R⁆ L₂) :
((e : L₁ ≃ₗ[R] L₂) : L₁ → L₂) = e := rfl
@[simp] lemma to_linear_equiv_mk (f : L₁ →ₗ⁅R⁆ L₂) (g h₁ h₂) :
(mk f g h₁ h₂ : L₁ ≃ₗ[R] L₂) = { inv_fun := g, left_inv := h₁, right_inv := h₂, .. f } := rfl
lemma coe_linear_equiv_injective : injective (coe : (L₁ ≃ₗ⁅R⁆ L₂) → (L₁ ≃ₗ[R] L₂)) :=
begin
intros f₁ f₂ h, cases f₁, cases f₂, dsimp at h, simp only at h,
congr, exacts [lie_hom.coe_injective h.1, h.2]
end
lemma coe_injective : @injective (L₁ ≃ₗ⁅R⁆ L₂) (L₁ → L₂) coe_fn :=
linear_equiv.coe_injective.comp coe_linear_equiv_injective
@[ext] lemma ext {f g : L₁ ≃ₗ⁅R⁆ L₂} (h : ∀ x, f x = g x) : f = g := coe_injective $ funext h
instance : has_one (L₁ ≃ₗ⁅R⁆ L₁) :=
⟨{ map_lie' := λ x y, rfl,
..(1 : L₁ ≃ₗ[R] L₁)}⟩
@[simp] lemma one_apply (x : L₁) : (1 : (L₁ ≃ₗ⁅R⁆ L₁)) x = x := rfl
instance : inhabited (L₁ ≃ₗ⁅R⁆ L₁) := ⟨1⟩
/-- Lie algebra equivalences are reflexive. -/
@[refl]
def refl : L₁ ≃ₗ⁅R⁆ L₁ := 1
@[simp] lemma refl_apply (x : L₁) : (refl : L₁ ≃ₗ⁅R⁆ L₁) x = x := rfl
/-- Lie algebra equivalences are symmetric. -/
@[symm]
def symm (e : L₁ ≃ₗ⁅R⁆ L₂) : L₂ ≃ₗ⁅R⁆ L₁ :=
{ ..lie_hom.inverse e.to_lie_hom e.inv_fun e.left_inv e.right_inv,
..e.to_linear_equiv.symm }
@[simp] lemma symm_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.symm = e :=
by { ext, refl }
@[simp] lemma apply_symm_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e (e.symm x) = x :=
e.to_linear_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : L₁ ≃ₗ⁅R⁆ L₂) : ∀ x, e.symm (e x) = x :=
e.to_linear_equiv.symm_apply_apply
/-- Lie algebra equivalences are transitive. -/
@[trans]
def trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) : L₁ ≃ₗ⁅R⁆ L₃ :=
{ ..lie_hom.comp e₂.to_lie_hom e₁.to_lie_hom,
..linear_equiv.trans e₁.to_linear_equiv e₂.to_linear_equiv }
@[simp] lemma self_trans_symm (e : L₁ ≃ₗ⁅R⁆ L₂) : e.trans e.symm = refl :=
ext e.symm_apply_apply
@[simp] lemma symm_trans_self (e : L₁ ≃ₗ⁅R⁆ L₂) : e.symm.trans e = refl :=
e.symm.self_trans_symm
@[simp] lemma trans_apply (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) (x : L₁) :
(e₁.trans e₂) x = e₂ (e₁ x) := rfl
@[simp] lemma symm_trans (e₁ : L₁ ≃ₗ⁅R⁆ L₂) (e₂ : L₂ ≃ₗ⁅R⁆ L₃) :
(e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl
protected lemma bijective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.bijective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.to_linear_equiv.bijective
protected lemma injective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.injective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.to_linear_equiv.injective
protected lemma surjective (e : L₁ ≃ₗ⁅R⁆ L₂) : function.surjective ((e : L₁ →ₗ⁅R⁆ L₂) : L₁ → L₂) :=
e.to_linear_equiv.surjective
end lie_equiv
section lie_module_morphisms
variables (R : Type u) (L : Type v) (M : Type w) (N : Type w₁) (P : Type w₂)
variables [comm_ring R] [lie_ring L] [lie_algebra R L]
variables [add_comm_group M] [add_comm_group N] [add_comm_group P]
variables [module R M] [module R N] [module R P]
variables [lie_ring_module L M] [lie_ring_module L N] [lie_ring_module L P]
variables [lie_module R L M] [lie_module R L N] [lie_module R L P]
/-- A morphism of Lie algebra modules is a linear map which commutes with the action of the Lie
algebra. -/
structure lie_module_hom extends M →ₗ[R] N :=
(map_lie' : ∀ {x : L} {m : M}, to_fun ⁅x, m⁆ = ⁅x, to_fun m⁆)
attribute [nolint doc_blame] lie_module_hom.to_linear_map
notation M ` →ₗ⁅`:25 R,L:25 `⁆ `:0 N:0 := lie_module_hom R L M N
namespace lie_module_hom
variables {R L M N P}
instance : has_coe (M →ₗ⁅R,L⁆ N) (M →ₗ[R] N) := ⟨lie_module_hom.to_linear_map⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (M →ₗ⁅R,L⁆ N) (λ _, M → N) := ⟨λ f, f.to_linear_map.to_fun⟩
@[simp, norm_cast] lemma coe_to_linear_map (f : M →ₗ⁅R,L⁆ N) : ((f : M →ₗ[R] N) : M → N) = f :=
rfl
@[simp] lemma map_smul (f : M →ₗ⁅R,L⁆ N) (c : R) (x : M) : f (c • x) = c • f x :=
linear_map.map_smul (f : M →ₗ[R] N) c x
@[simp] lemma map_add (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x + y) = (f x) + (f y) :=
linear_map.map_add (f : M →ₗ[R] N) x y
@[simp] lemma map_sub (f : M →ₗ⁅R,L⁆ N) (x y : M) : f (x - y) = (f x) - (f y) :=
linear_map.map_sub (f : M →ₗ[R] N) x y
@[simp] lemma map_neg (f : M →ₗ⁅R,L⁆ N) (x : M) : f (-x) = -(f x) :=
linear_map.map_neg (f : M →ₗ[R] N) x
@[simp] lemma map_lie (f : M →ₗ⁅R,L⁆ N) (x : L) (m : M) : f ⁅x, m⁆ = ⁅x, f m⁆ :=
lie_module_hom.map_lie' f
lemma map_lie₂ (f : M →ₗ⁅R,L⁆ N →ₗ[R] P) (x : L) (m : M) (n : N) :
⁅x, f m n⁆ = f ⁅x, m⁆ n + f m ⁅x, n⁆ :=
by simp only [sub_add_cancel, map_lie, lie_hom.lie_apply]
@[simp] lemma map_zero (f : M →ₗ⁅R,L⁆ N) : f 0 = 0 :=
linear_map.map_zero (f : M →ₗ[R] N)
/-- The identity map is a morphism of Lie modules. -/
def id : M →ₗ⁅R,L⁆ M :=
{ map_lie' := λ x m, rfl,
.. (linear_map.id : M →ₗ[R] M) }
@[simp] lemma coe_id : ((id : M →ₗ⁅R,L⁆ M) : M → M) = _root_.id := rfl
lemma id_apply (x : M) : (id : M →ₗ⁅R,L⁆ M) x = x := rfl
/-- The constant 0 map is a Lie module morphism. -/
instance : has_zero (M →ₗ⁅R,L⁆ N) := ⟨{ map_lie' := by simp, ..(0 : M →ₗ[R] N) }⟩
@[norm_cast, simp] lemma coe_zero : ((0 : M →ₗ⁅R,L⁆ N) : M → N) = 0 := rfl
lemma zero_apply (m : M) : (0 : M →ₗ⁅R,L⁆ N) m = 0 := rfl
/-- The identity map is a Lie module morphism. -/
instance : has_one (M →ₗ⁅R,L⁆ M) := ⟨id⟩
instance : inhabited (M →ₗ⁅R,L⁆ N) := ⟨0⟩
lemma coe_injective : @function.injective (M →ₗ⁅R,L⁆ N) (M → N) coe_fn :=
by { rintros ⟨⟨f, _⟩⟩ ⟨⟨g, _⟩⟩ ⟨h⟩, congr, }
@[ext] lemma ext {f g : M →ₗ⁅R,L⁆ N} (h : ∀ m, f m = g m) : f = g :=
coe_injective $ funext h
lemma ext_iff {f g : M →ₗ⁅R,L⁆ N} : f = g ↔ ∀ m, f m = g m :=
⟨by { rintro rfl m, refl, }, ext⟩
lemma congr_fun {f g : M →ₗ⁅R,L⁆ N} (h : f = g) (x : M) : f x = g x := h ▸ rfl
@[simp] lemma mk_coe (f : M →ₗ⁅R,L⁆ N) (h) :
(⟨f, h⟩ : M →ₗ⁅R,L⁆ N) = f :=
by { ext, refl, }
@[simp] lemma coe_mk (f : M →ₗ[R] N) (h) :
((⟨f, h⟩ : M →ₗ⁅R,L⁆ N) : M → N) = f :=
by { ext, refl, }
@[norm_cast, simp] lemma coe_linear_mk (f : M →ₗ[R] N) (h) :
((⟨f, h⟩ : M →ₗ⁅R,L⁆ N) : M →ₗ[R] N) = f :=
by { ext, refl, }
/-- The composition of Lie module morphisms is a morphism. -/
def comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) : M →ₗ⁅R,L⁆ P :=
{ map_lie' := λ x m, by { change f (g ⁅x, m⁆) = ⁅x, f (g m)⁆, rw [map_lie, map_lie], },
..linear_map.comp f.to_linear_map g.to_linear_map }
lemma comp_apply (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) (m : M) :
f.comp g m = f (g m) := rfl
@[norm_cast, simp] lemma coe_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) :
(f.comp g : M → P) = f ∘ g :=
rfl
@[norm_cast, simp] lemma coe_linear_map_comp (f : N →ₗ⁅R,L⁆ P) (g : M →ₗ⁅R,L⁆ N) :
(f.comp g : M →ₗ[R] P) = (f : N →ₗ[R] P).comp (g : M →ₗ[R] N) :=
rfl
/-- The inverse of a bijective morphism of Lie modules is a morphism of Lie modules. -/
def inverse (f : M →ₗ⁅R,L⁆ N) (g : N → M)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : N →ₗ⁅R,L⁆ M :=
{ map_lie' := λ x n,
calc g ⁅x, n⁆ = g ⁅x, f (g n)⁆ : by rw h₂
... = g (f ⁅x, g n⁆) : by rw map_lie
... = ⁅x, g n⁆ : (h₁ _),
..linear_map.inverse f.to_linear_map g h₁ h₂ }
instance : has_add (M →ₗ⁅R,L⁆ N) :=
{ add := λ f g, { map_lie' := by simp, ..((f : M →ₗ[R] N) + (g : M →ₗ[R] N)) }, }
instance : has_sub (M →ₗ⁅R,L⁆ N) :=
{ sub := λ f g, { map_lie' := by simp, ..((f : M →ₗ[R] N) - (g : M →ₗ[R] N)) }, }
instance : has_neg (M →ₗ⁅R,L⁆ N) :=
{ neg := λ f, { map_lie' := by simp, ..(-(f : (M →ₗ[R] N))) }, }
@[norm_cast, simp] lemma coe_add (f g : M →ₗ⁅R,L⁆ N) : ⇑(f + g) = f + g := rfl
lemma add_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f + g) m = f m + g m := rfl
@[norm_cast, simp] lemma coe_sub (f g : M →ₗ⁅R,L⁆ N) : ⇑(f - g) = f - g := rfl
lemma sub_apply (f g : M →ₗ⁅R,L⁆ N) (m : M) : (f - g) m = f m - g m := rfl
@[norm_cast, simp] lemma coe_neg (f : M →ₗ⁅R,L⁆ N) : ⇑(-f) = -f := rfl
lemma neg_apply (f : M →ₗ⁅R,L⁆ N) (m : M) : (-f) m = -(f m) := rfl
instance : add_comm_group (M →ₗ⁅R,L⁆ N) :=
{ zero := 0,
add := (+),
neg := has_neg.neg,
sub := has_sub.sub,
nsmul := λ n f, { map_lie' := λ x m, by simp, ..(n • (f : M →ₗ[R] N)) },
nsmul_zero' := λ f, by { ext, simp, },
nsmul_succ' := λ n f, by { ext, simp [nat.succ_eq_one_add, add_nsmul], },
..(coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub :
add_comm_group (M →ₗ⁅R,L⁆ N)) }
instance : has_scalar R (M →ₗ⁅R,L⁆ N) :=
{ smul := λ t f, { map_lie' := by simp, ..(t • (f : M →ₗ[R] N)) }, }
@[norm_cast, simp] lemma coe_smul (t : R) (f : M →ₗ⁅R,L⁆ N) : ⇑(t • f) = t • f := rfl
lemma smul_apply (t : R) (f : M →ₗ⁅R,L⁆ N) (m : M) : (t • f) m = t • (f m) := rfl
instance : module R (M →ₗ⁅R,L⁆ N) :=
function.injective.module R ⟨λ f, f.to_linear_map.to_fun, rfl, coe_add⟩ coe_injective coe_smul
end lie_module_hom
/-- An equivalence of Lie algebra modules is a linear equivalence which is also a morphism of
Lie algebra modules. -/
structure lie_module_equiv extends M →ₗ⁅R,L⁆ N :=
(inv_fun : N → M)
(left_inv : function.left_inverse inv_fun to_fun)
(right_inv : function.right_inverse inv_fun to_fun)
attribute [nolint doc_blame] lie_module_equiv.to_lie_module_hom
notation M ` ≃ₗ⁅`:25 R,L:25 `⁆ `:0 N:0 := lie_module_equiv R L M N
namespace lie_module_equiv
variables {R L M N P}
/-- View an equivalence of Lie modules as a linear equivalence. -/
@[ancestor]
def to_linear_equiv (e : M ≃ₗ⁅R,L⁆ N) : M ≃ₗ[R] N := { ..e }
/-- View an equivalence of Lie modules as a type level equivalence. -/
@[ancestor]
def to_equiv (e : M ≃ₗ⁅R,L⁆ N) : M ≃ N := { ..e }
instance has_coe_to_equiv : has_coe (M ≃ₗ⁅R,L⁆ N) (M ≃ N) := ⟨to_equiv⟩
instance has_coe_to_lie_module_hom : has_coe (M ≃ₗ⁅R,L⁆ N) (M →ₗ⁅R,L⁆ N) := ⟨to_lie_module_hom⟩
instance has_coe_to_linear_equiv : has_coe (M ≃ₗ⁅R,L⁆ N) (M ≃ₗ[R] N) := ⟨to_linear_equiv⟩
/-- see Note [function coercion] -/
instance : has_coe_to_fun (M ≃ₗ⁅R,L⁆ N) (λ _, M → N) := ⟨λ e, e.to_lie_module_hom.to_fun⟩
lemma injective (e : M ≃ₗ⁅R,L⁆ N) : function.injective e := e.to_equiv.injective
@[simp] lemma coe_mk (f : M →ₗ⁅R,L⁆ N) (inv_fun h₁ h₂) :
((⟨f, inv_fun, h₁, h₂⟩ : M ≃ₗ⁅R,L⁆ N) : M → N) = f := rfl
@[simp, norm_cast] lemma coe_to_lie_module_hom (e : M ≃ₗ⁅R,L⁆ N) :
((e : M →ₗ⁅R,L⁆ N) : M → N) = e := rfl
@[simp, norm_cast] lemma coe_to_linear_equiv (e : M ≃ₗ⁅R,L⁆ N) : ((e : M ≃ₗ[R] N) : M → N) = e :=
rfl
lemma to_equiv_injective : function.injective (to_equiv : (M ≃ₗ⁅R,L⁆ N) → M ≃ N) :=
λ e₁ e₂ h, begin
rcases e₁ with ⟨⟨⟩⟩, rcases e₂ with ⟨⟨⟩⟩,
have inj := equiv.mk.inj h,
dsimp at inj,
apply lie_module_equiv.mk.inj_eq.mpr,
split,
{ congr,
ext,
rw inj.1 },
{ exact inj.2 },
end
@[ext] lemma ext (e₁ e₂ : M ≃ₗ⁅R,L⁆ N) (h : ∀ m, e₁ m = e₂ m) : e₁ = e₂ :=
to_equiv_injective (equiv.ext h)
instance : has_one (M ≃ₗ⁅R,L⁆ M) := ⟨{ map_lie' := λ x m, rfl, ..(1 : M ≃ₗ[R] M) }⟩
@[simp] lemma one_apply (m : M) : (1 : (M ≃ₗ⁅R,L⁆ M)) m = m := rfl
instance : inhabited (M ≃ₗ⁅R,L⁆ M) := ⟨1⟩
/-- Lie module equivalences are reflexive. -/
@[refl] def refl : M ≃ₗ⁅R,L⁆ M := 1
@[simp] lemma refl_apply (m : M) : (refl : M ≃ₗ⁅R,L⁆ M) m = m := rfl
/-- Lie module equivalences are syemmtric. -/
@[symm] def symm (e : M ≃ₗ⁅R,L⁆ N) : N ≃ₗ⁅R,L⁆ M :=
{ ..lie_module_hom.inverse e.to_lie_module_hom e.inv_fun e.left_inv e.right_inv,
..(e : M ≃ₗ[R] N).symm }
@[simp] lemma apply_symm_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e (e.symm x) = x :=
e.to_linear_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : M ≃ₗ⁅R,L⁆ N) : ∀ x, e.symm (e x) = x :=
e.to_linear_equiv.symm_apply_apply
@[simp] lemma symm_symm (e : M ≃ₗ⁅R,L⁆ N) : e.symm.symm = e :=
by { ext, apply_fun e.symm using e.symm.injective, simp, }
/-- Lie module equivalences are transitive. -/
@[trans] def trans (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) : M ≃ₗ⁅R,L⁆ P :=
{ ..lie_module_hom.comp e₂.to_lie_module_hom e₁.to_lie_module_hom,
..linear_equiv.trans e₁.to_linear_equiv e₂.to_linear_equiv }
@[simp] lemma trans_apply (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) (m : M) :
(e₁.trans e₂) m = e₂ (e₁ m) := rfl
@[simp] lemma symm_trans (e₁ : M ≃ₗ⁅R,L⁆ N) (e₂ : N ≃ₗ⁅R,L⁆ P) :
(e₁.trans e₂).symm = e₂.symm.trans e₁.symm := rfl
@[simp] lemma self_trans_symm (e : M ≃ₗ⁅R,L⁆ N) : e.trans e.symm = refl :=
ext _ _ e.symm_apply_apply
@[simp] lemma symm_trans_self (e : M ≃ₗ⁅R,L⁆ N) : e.symm.trans e = refl :=
ext _ _ e.apply_symm_apply
end lie_module_equiv
end lie_module_morphisms
|
910f2774c76df8b9e574d83045c22df8365b9c10 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/instances/sign.lean | 2ddc6e4e4d487045be87970e3584ed50d5ceaed8 | [
"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,656 | lean | /-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import data.sign
import topology.order.basic
/-!
# Topology on `sign_type`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file gives `sign_type` the discrete topology, and proves continuity results for `sign` in
an `order_topology`.
-/
instance : topological_space sign_type := ⊥
instance : discrete_topology sign_type := ⟨rfl⟩
variables {α : Type*} [has_zero α] [topological_space α]
section partial_order
variables [partial_order α] [decidable_rel ((<) : α → α → Prop)] [order_topology α]
lemma continuous_at_sign_of_pos {a : α} (h : 0 < a) : continuous_at sign a :=
begin
refine (continuous_at_const : continuous_at (λ x, (1 : sign_type)) a).congr _,
rw [filter.eventually_eq, eventually_nhds_iff],
exact ⟨{x | 0 < x}, λ x hx, (sign_pos hx).symm, is_open_lt' 0, h⟩
end
lemma continuous_at_sign_of_neg {a : α} (h : a < 0) : continuous_at sign a :=
begin
refine (continuous_at_const : continuous_at (λ x, (-1 : sign_type)) a).congr _,
rw [filter.eventually_eq, eventually_nhds_iff],
exact ⟨{x | x < 0}, λ x hx, (sign_neg hx).symm, is_open_gt' 0, h⟩
end
end partial_order
section linear_order
variables [linear_order α] [order_topology α]
lemma continuous_at_sign_of_ne_zero {a : α} (h : a ≠ 0) : continuous_at sign a :=
begin
rcases h.lt_or_lt with h_neg|h_pos,
{ exact continuous_at_sign_of_neg h_neg },
{ exact continuous_at_sign_of_pos h_pos }
end
end linear_order
|
fca76bd92c527b6cbbb20d6b4b95ef895420da48 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/category/Quiv.lean | 2bcf0b8f1830809671fb25d3ea525c95f4aaade9 | [
"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 | 3,173 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.adjunction.basic
import category_theory.category.Cat
import category_theory.path_category
/-!
# The category of quivers
The category of (bundled) quivers, and the free/forgetful adjunction between `Cat` and `Quiv`.
-/
universes v u
namespace category_theory
/-- Category of quivers. -/
@[nolint check_univs] -- intended to be used with explicit universe parameters
def Quiv := bundled quiver.{(v+1) u}
namespace Quiv
instance : has_coe_to_sort Quiv (Type u) :=
{ coe := bundled.α }
instance str (C : Quiv.{v u}) : quiver.{(v+1) u} C := C.str
/-- Construct a bundled `Quiv` from the underlying type and the typeclass. -/
def of (C : Type u) [quiver.{v+1} C] : Quiv.{v u} := bundled.of C
instance : inhabited Quiv := ⟨Quiv.of (quiver.empty pempty)⟩
/-- Category structure on `Quiv` -/
instance category : large_category.{max v u} Quiv.{v u} :=
{ hom := λ C D, prefunctor C D,
id := λ C, prefunctor.id C,
comp := λ C D E F G, prefunctor.comp F G,
id_comp' := λ C D F, by cases F; refl,
comp_id' := λ C D F, by cases F; refl,
assoc' := by intros; refl }
/-- The forgetful functor from categories to quivers. -/
@[simps]
def forget : Cat.{v u} ⥤ Quiv.{v u} :=
{ obj := λ C, Quiv.of C,
map := λ C D F, F.to_prefunctor, }
end Quiv
namespace Cat
/-- The functor sending each quiver to its path category. -/
@[simps]
def free : Quiv.{v u} ⥤ Cat.{(max u v) u} :=
{ obj := λ V, Cat.of (paths V),
map := λ V W F,
{ obj := λ X, F.obj X,
map := λ X Y f, F.map_path f,
map_comp' := λ X Y Z f g, F.map_path_comp f g, },
map_id' := λ V, by { change (show paths V ⥤ _, from _) = _, ext, apply eq_conj_eq_to_hom, refl },
map_comp' := λ U V W F G,
by { change (show paths U ⥤ _, from _) = _, ext, apply eq_conj_eq_to_hom, refl } }
end Cat
namespace Quiv
/-- Any prefunctor into a category lifts to a functor from the path category. -/
@[simps]
def lift {V : Type u} [quiver.{v+1} V] {C : Type*} [category C]
(F : prefunctor V C) : paths V ⥤ C :=
{ obj := λ X, F.obj X,
map := λ X Y f, compose_path (F.map_path f), }
-- We might construct `of_lift_iso_self : paths.of ⋙ lift F ≅ F`
-- (and then show that `lift F` is initial amongst such functors)
-- but it would require lifting quite a bit of machinery to quivers!
/--
The adjunction between forming the free category on a quiver, and forgetting a category to a quiver.
-/
def adj : Cat.free ⊣ Quiv.forget :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ V C,
{ to_fun := λ F, paths.of.comp F.to_prefunctor,
inv_fun := λ F, lift F,
left_inv := λ F, by { ext, { erw (eq_conj_eq_to_hom _).symm, apply category.id_comp }, refl },
right_inv := begin
rintro ⟨obj,map⟩,
dsimp only [prefunctor.comp],
congr,
ext X Y f,
exact category.id_comp _,
end, },
hom_equiv_naturality_left_symm' := λ V W C f g,
by { change (show paths V ⥤ _, from _) = _, ext, apply eq_conj_eq_to_hom, refl } }
end Quiv
end category_theory
|
30280abd9a98d9e7537a71adb1bb35dac705b467 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/algebra/ring_bigops.lean | 0b5d468d8cb58f30a2df200271a9b8fee1977c2f | [
"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 | 6,088 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Properties of finite sums and products in various structures, including ordered rings and fields.
There are two versions of every theorem: one for finsets, and one for finite sets.
-/
import .group_bigops .ordered_field
variables {A B : Type}
variable [deceqA : decidable_eq A]
/-
-- finset versions
-/
namespace finset
section comm_semiring
variable [csB : comm_semiring B]
include deceqA csB
proposition mul_Sum (f : A → B) {s : finset A} (b : B) :
b * (∑ x ∈ s, f x) = ∑ x ∈ s, b * f x :=
begin
induction s with a s ans ih,
{rewrite [+Sum_empty, mul_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem (λ x, b * f x) ans],
rewrite [-ih, left_distrib]
end
proposition Sum_mul (f : A → B) {s : finset A} (b : B) :
(∑ x ∈ s, f x) * b = ∑ x ∈ s, f x * b :=
by rewrite [mul.comm _ b, mul_Sum]; apply Sum_ext; intros; apply mul.comm
proposition Prod_eq_zero (f : A → B) {s : finset A} {a : A} (H : a ∈ s) (fa0 : f a = 0) :
(∏ x ∈ s, f x) = 0 :=
begin
induction s with b s bns ih,
{exact absurd H !not_mem_empty},
rewrite [Prod_insert_of_not_mem f bns],
have a = b ∨ a ∈ s, from eq_or_mem_of_mem_insert H,
cases this with aeqb ains,
{rewrite [-aeqb, fa0, zero_mul]},
rewrite [ih ains, mul_zero]
end
end comm_semiring
section ordered_comm_group
variable [ocgB : ordered_comm_group B]
include deceqA ocgB
proposition Sum_le_Sum (f g : A → B) {s : finset A} (H: ∀ x, x ∈ s → f x ≤ g x) :
(∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x) :=
begin
induction s with a s ans ih,
{exact le.refl _},
have H1 : f a ≤ g a, from H _ !mem_insert,
have H2 : (∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x), from ih (forall_of_forall_insert H),
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem g ans],
apply add_le_add H1 H2
end
proposition Sum_nonneg (f : A → B) {s : finset A} (H : ∀x, x ∈ s → f x ≥ 0) :
(∑ x ∈ s, f x) ≥ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≤ (∑ x ∈ s, f x) : Sum_le_Sum (λ x, 0) f H
proposition Sum_nonpos (f : A → B) {s : finset A} (H : ∀x, x ∈ s → f x ≤ 0) :
(∑ x ∈ s, f x) ≤ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≥ (∑ x ∈ s, f x) : Sum_le_Sum f (λ x, 0) H
end ordered_comm_group
section decidable_linear_ordered_comm_group
variable [dloocgB : decidable_linear_ordered_comm_group B]
include deceqA dloocgB
proposition abs_Sum_le (f : A → B) (s : finset A) : abs (∑ x ∈ s, f x) ≤ (∑ x ∈ s, abs (f x)) :=
begin
induction s with a s ans ih,
{rewrite [+Sum_empty, abs_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem _ ans],
apply le.trans,
apply abs_add_le_abs_add_abs,
apply add_le_add_left ih
end
end decidable_linear_ordered_comm_group
end finset
/-
-- set versions
-/
namespace set
local attribute classical.prop_decidable [instance]
section comm_semiring
variable [csB : comm_semiring B]
include csB
proposition mul_Sum (f : A → B) {s : set A} (b : B) :
b * (∑ x ∈ s, f x) = ∑ x ∈ s, b * f x :=
begin
cases (em (finite s)) with fins nfins,
rotate 1,
{rewrite [+Sum_of_not_finite nfins, mul_zero]},
induction fins with a s fins ans ih,
{rewrite [+Sum_empty, mul_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem (λ x, b * f x) ans],
rewrite [-ih, left_distrib]
end
proposition Sum_mul (f : A → B) {s : set A} (b : B) :
(∑ x ∈ s, f x) * b = ∑ x ∈ s, f x * b :=
by rewrite [mul.comm _ b, mul_Sum]; apply Sum_ext; intros; apply mul.comm
proposition Prod_eq_zero (f : A → B) {s : set A} [fins : finite s] {a : A} (H : a ∈ s) (fa0 : f a = 0) :
(∏ x ∈ s, f x) = 0 :=
begin
induction fins with b s fins bns ih,
{exact absurd H !not_mem_empty},
rewrite [Prod_insert_of_not_mem f bns],
have a = b ∨ a ∈ s, from eq_or_mem_of_mem_insert H,
cases this with aeqb ains,
{rewrite [-aeqb, fa0, zero_mul]},
rewrite [ih ains, mul_zero]
end
end comm_semiring
section ordered_comm_group
variable [ocgB : ordered_comm_group B]
include ocgB
proposition Sum_le_Sum (f g : A → B) {s : set A} (H: ∀₀ x ∈ s, f x ≤ g x) :
(∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x) :=
begin
cases (em (finite s)) with fins nfins,
{induction fins with a s fins ans ih,
{rewrite +Sum_empty},
{rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem g ans],
have H1 : f a ≤ g a, from H !mem_insert,
have H2 : (∑ x ∈ s, f x) ≤ (∑ x ∈ s, g x), from ih (forall_of_forall_insert H),
apply add_le_add H1 H2}},
rewrite [+Sum_of_not_finite nfins]
end
proposition Sum_nonneg (f : A → B) {s : set A} (H : ∀₀ x ∈ s, f x ≥ 0) :
(∑ x ∈ s, f x) ≥ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≤ (∑ x ∈ s, f x) : Sum_le_Sum (λ x, 0) f H
proposition Sum_nonpos (f : A → B) {s : set A} (H : ∀₀ x ∈ s, f x ≤ 0) :
(∑ x ∈ s, f x) ≤ 0 :=
calc
0 = (∑ x ∈ s, 0) : Sum_zero
... ≥ (∑ x ∈ s, f x) : Sum_le_Sum f (λ x, 0) H
end ordered_comm_group
section decidable_linear_ordered_comm_group
variable [dloocgB : decidable_linear_ordered_comm_group B]
include deceqA dloocgB
proposition abs_Sum_le (f : A → B) (s : set A) : abs (∑ x ∈ s, f x) ≤ (∑ x ∈ s, abs (f x)) :=
begin
cases (em (finite s)) with fins nfins,
rotate 1,
{rewrite [+Sum_of_not_finite nfins, abs_zero]},
induction fins with a s fins ans ih,
{rewrite [+Sum_empty, abs_zero]},
rewrite [Sum_insert_of_not_mem f ans, Sum_insert_of_not_mem _ ans],
apply le.trans,
apply abs_add_le_abs_add_abs,
apply add_le_add_left ih
end
end decidable_linear_ordered_comm_group
end set
|
ed17a759b0de8f3abf261247f699590e92603e40 | abd85493667895c57a7507870867b28124b3998f | /src/group_theory/quotient_group.lean | 816f600248cedd2a82fbc1aa0c6157a0e6de9082 | [
"Apache-2.0"
] | permissive | pechersky/mathlib | d56eef16bddb0bfc8bc552b05b7270aff5944393 | f1df14c2214ee114c9738e733efd5de174deb95d | refs/heads/master | 1,666,714,392,571 | 1,591,747,567,000 | 1,591,747,567,000 | 270,557,274 | 0 | 0 | Apache-2.0 | 1,591,597,975,000 | 1,591,597,974,000 | null | UTF-8 | Lean | false | false | 7,199 | lean | /-
Copyright (c) 2018 Kevin Buzzard and Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Patrick Massot.
This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl.
-/
import group_theory.coset
universes u v
namespace quotient_group
variables {G : Type u} [group G] (N : set G) [normal_subgroup N] {H : Type v} [group H]
@[to_additive quotient_add_group.add_group]
instance : group (quotient N) :=
{ one := (1 : G),
mul := quotient.map₂' (*)
(λ a₁ b₁ hab₁ a₂ b₂ hab₂,
((is_subgroup.mul_mem_cancel_right N (is_subgroup.inv_mem hab₂)).1
(by rw [mul_inv_rev, mul_inv_rev, ← mul_assoc (a₂⁻¹ * a₁⁻¹),
mul_assoc _ b₂, ← mul_assoc b₂, mul_inv_self, one_mul, mul_assoc (a₂⁻¹)];
exact normal_subgroup.normal _ hab₁ _))),
mul_assoc := λ a b c, quotient.induction_on₃' a b c
(λ a b c, congr_arg mk (mul_assoc a b c)),
one_mul := λ a, quotient.induction_on' a
(λ a, congr_arg mk (one_mul a)),
mul_one := λ a, quotient.induction_on' a
(λ a, congr_arg mk (mul_one a)),
inv := λ a, quotient.lift_on' a (λ a, ((a⁻¹ : G) : quotient N))
(λ a b hab, quotient.sound' begin
show a⁻¹⁻¹ * b⁻¹ ∈ N,
rw ← mul_inv_rev,
exact is_subgroup.inv_mem (is_subgroup.mem_norm_comm hab)
end),
mul_left_inv := λ a, quotient.induction_on' a
(λ a, congr_arg mk (mul_left_inv a)) }
@[to_additive quotient_add_group.is_add_group_hom]
instance : is_group_hom (mk : G → quotient N) := { map_mul := λ _ _, rfl }
@[simp, to_additive quotient_add_group.ker_mk]
lemma ker_mk :
is_group_hom.ker (quotient_group.mk : G → quotient_group.quotient N) = N :=
begin
ext g,
rw [is_group_hom.mem_ker, eq_comm],
show (((1 : G) : quotient_group.quotient N)) = g ↔ _,
rw [quotient_group.eq, one_inv, one_mul],
end
@[to_additive quotient_add_group.add_comm_group]
instance {G : Type*} [comm_group G] (s : set G) [is_subgroup s] : comm_group (quotient s) :=
{ mul_comm := λ a b, quotient.induction_on₂' a b
(λ a b, congr_arg mk (mul_comm a b)),
..@quotient_group.group _ _ s (normal_subgroup_of_comm_group s) }
@[simp, to_additive quotient_add_group.coe_zero]
lemma coe_one : ((1 : G) : quotient N) = 1 := rfl
@[simp, to_additive quotient_add_group.coe_add]
lemma coe_mul (a b : G) : ((a * b : G) : quotient N) = a * b := rfl
@[simp, to_additive quotient_add_group.coe_neg]
lemma coe_inv (a : G) : ((a⁻¹ : G) : quotient N) = a⁻¹ := rfl
@[simp] lemma coe_pow (a : G) (n : ℕ) : ((a ^ n : G) : quotient N) = a ^ n :=
(monoid_hom.of mk).map_pow a n
@[simp] lemma coe_gpow (a : G) (n : ℤ) : ((a ^ n : G) : quotient N) = a ^ n :=
(monoid_hom.of mk).map_gpow a n
local notation ` Q ` := quotient N
@[to_additive quotient_add_group.lift]
def lift (φ : G → H) [is_group_hom φ] (HN : ∀x∈N, φ x = 1) (q : Q) : H :=
q.lift_on' φ $ assume a b (hab : a⁻¹ * b ∈ N),
(calc φ a = φ a * 1 : (mul_one _).symm
... = φ a * φ (a⁻¹ * b) : HN (a⁻¹ * b) hab ▸ rfl
... = φ (a * (a⁻¹ * b)) : (is_mul_hom.map_mul φ a (a⁻¹ * b)).symm
... = φ b : by rw mul_inv_cancel_left)
@[simp, to_additive quotient_add_group.lift_mk]
lemma lift_mk {φ : G → H} [is_group_hom φ] (HN : ∀x∈N, φ x = 1) (g : G) :
lift N φ HN (g : Q) = φ g := rfl
@[simp, to_additive quotient_add_group.lift_mk']
lemma lift_mk' {φ : G → H} [is_group_hom φ] (HN : ∀x∈N, φ x = 1) (g : G) :
lift N φ HN (mk g : Q) = φ g := rfl
@[to_additive quotient_add_group.map]
def map (M : set H) [normal_subgroup M] (f : G → H) [is_group_hom f] (h : N ⊆ f ⁻¹' M) :
quotient N → quotient M :=
begin
haveI : is_group_hom ((mk : H → quotient M) ∘ f) := is_group_hom.comp _ _,
refine quotient_group.lift N (mk ∘ f) _,
assume x hx,
refine quotient_group.eq.2 _,
rw [mul_one, is_subgroup.inv_mem_iff],
exact h hx,
end
variables (φ : G → H) [is_group_hom φ] (HN : ∀x∈N, φ x = 1)
@[to_additive quotient_add_group.is_add_group_hom_quotient_lift]
instance is_group_hom_quotient_lift :
is_group_hom (lift N φ HN) :=
{ map_mul := λ q r, quotient.induction_on₂' q r $ is_mul_hom.map_mul φ }
@[to_additive quotient_add_group.map_is_add_group_hom]
instance map_is_group_hom (M : set H) [normal_subgroup M]
(f : G → H) [is_group_hom f] (h : N ⊆ f ⁻¹' M) : is_group_hom (map N M f h) :=
@quotient_group.is_group_hom_quotient_lift _ _ _ _ _ _ _ (is_group_hom.comp _ _) _
open function is_group_hom
/-- The induced map from the quotient by the kernel to the codomain. -/
@[to_additive quotient_add_group.ker_lift]
def ker_lift : quotient (ker φ) → H :=
lift _ φ $ λ g, (mem_ker φ).mp
@[simp, to_additive quotient_add_group.ker_lift_mk]
lemma ker_lift_mk (g : G) : (ker_lift φ) g = φ g :=
lift_mk _ _ _
@[simp, to_additive quotient_add_group.ker_lift_mk']
lemma ker_lift_mk' (g : G) : (ker_lift φ) (mk g) = φ g :=
lift_mk' _ _ _
@[to_additive quotient_add_group.ker_lift_is_add_group_hom]
instance ker_lift_is_group_hom : is_group_hom (ker_lift φ) :=
quotient_group.is_group_hom_quotient_lift _ _ _
@[to_additive quotient_add_group.injective_ker_lift]
lemma injective_ker_lift : injective (ker_lift φ) :=
assume a b, quotient.induction_on₂' a b $ assume a b (h : φ a = φ b), quotient.sound' $
show a⁻¹ * b ∈ ker φ, by rw [mem_ker φ,
is_mul_hom.map_mul φ, ← h, is_group_hom.map_inv φ, inv_mul_self]
--@[to_additive quotient_add_group.quotient_ker_equiv_range]
noncomputable def quotient_ker_equiv_range : (quotient (ker φ)) ≃ set.range φ :=
@equiv.of_bijective _ (set.range φ) (λ x, ⟨lift (ker φ) φ
(by simp [mem_ker]) x, by exact quotient.induction_on' x (λ x, ⟨x, rfl⟩)⟩)
⟨λ a b h, injective_ker_lift _ (subtype.mk.inj h),
λ ⟨x, y, hy⟩, ⟨mk y, subtype.eq hy⟩⟩
noncomputable def quotient_ker_equiv_of_surjective (hφ : function.surjective φ) :
(quotient (ker φ)) ≃ H :=
calc (quotient_group.quotient (is_group_hom.ker φ)) ≃ set.range φ : quotient_ker_equiv_range _
... ≃ H : ⟨λ a, a.1, λ b, ⟨b, hφ b⟩, λ ⟨_, _⟩, rfl, λ _, rfl⟩
end quotient_group
namespace quotient_add_group
open is_add_group_hom
variables {G : Type u} [_root_.add_group G] (N : set G) [normal_add_subgroup N] {H : Type v} [_root_.add_group H]
variables (φ : G → H) [_root_.is_add_group_hom φ]
noncomputable def quotient_ker_equiv_range : (quotient (ker φ)) ≃ set.range φ :=
@quotient_group.quotient_ker_equiv_range (multiplicative G) _ (multiplicative H) _ φ
(multiplicative.is_group_hom _)
noncomputable def quotient_ker_equiv_of_surjective (hφ : function.surjective φ) :
(quotient (ker φ)) ≃ H :=
@quotient_group.quotient_ker_equiv_of_surjective (multiplicative G) _ (multiplicative H) _ φ
(multiplicative.is_group_hom _) hφ
attribute [to_additive quotient_add_group.quotient_ker_equiv_range] quotient_group.quotient_ker_equiv_range
attribute [to_additive quotient_add_group.quotient_ker_equiv_of_surjective] quotient_group.quotient_ker_equiv_of_surjective
end quotient_add_group
|
15b0ea16c3cc473f8101c7b727a450411f94f6dd | a89b8d3c600409f2f752bc9ab5c96ac20787cfef | /library/init/meta/interactive.lean | 7c75f841f32b5873bfc7e72a8a44999da230a85a | [
"Apache-2.0"
] | permissive | Armael/lean | 0211a95f4db2a69189073497500e170660b5284e | 49bc0ef0fd04242242f81ebdb0912ce6daed5a65 | refs/heads/master | 1,611,565,828,709 | 1,496,958,664,000 | 1,497,031,159,000 | 93,794,727 | 0 | 0 | null | 1,496,958,642,000 | 1,496,958,642,000 | null | UTF-8 | Lean | false | false | 31,213 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.tactic init.meta.rewrite_tactic init.meta.simp_tactic
import init.meta.smt.congruence_closure init.category.combinators
import init.meta.interactive_base
open lean
open lean.parser
local postfix `?`:9001 := optional
local postfix *:9001 := many
namespace tactic
/- allows metavars and report errors -/
meta def i_to_expr (q : pexpr) : tactic expr :=
to_expr q tt
/- doesn't allows metavars and report errors -/
meta def i_to_expr_strict (q : pexpr) : tactic expr :=
to_expr q ff
namespace interactive
open interactive interactive.types expr
/-
itactic: parse a nested "interactive" tactic. That is, parse
`{` tactic `}`
-/
meta def itactic : Type :=
tactic unit
/--
This tactic applies to a goal that is either a Pi/forall or starts with a let binder.
If the current goal is a Pi/forall `∀ x:T, U` (resp `let x:=t in U`) then intro puts `x:T` (resp `x:=t`) in the local context. The new subgoal target is `U`.
If the goal is an arrow `T → U`, then it puts in the local context either `h:T`, and the new goal target is `U`.
If the goal is neither a Pi/forall nor starting with a let definition,
the tactic `intro` applies the tactic `whnf` until the tactic `intro` can be applied or the goal is not `head-reducible`.
-/
meta def intro : parse ident_? → tactic unit
| none := intro1 >> skip
| (some h) := tactic.intro h >> skip
/--
Similar to `intro` tactic. The tactic `intros` will keep introducing new hypotheses until the goal target is not a Pi/forall or let binder.
The variant `intros h_1 ... h_n` introduces `n` new hypotheses using the given identifiers to name them.
-/
meta def intros : parse ident_* → tactic unit
| [] := tactic.intros >> skip
| hs := intro_lst hs >> skip
/--
The tactic introv allows to automatically introduce the variables of a theorem and explicitly name the hypotheses involved.
The given names are used to name non-dependent hypotheses.
Examples:
```
example : ∀ a b : nat, a = b → b = a :=
begin
introv h,
exact h.symm
end
```
The state after `introv h` is
```
a b : ℕ,
h : a = b
⊢ b = a
```
```
example : ∀ a b : nat, a = b → ∀ c, b = c → a = c :=
begin
introv h₁ h₂,
exact h₁.trans h₂
end
```
The state after `introv h₁ h₂` is
```
a b : ℕ,
h₁ : a = b,
c : ℕ,
h₂ : b = c
⊢ a = c
```
-/
meta def introv (ns : parse ident_*) : tactic unit :=
tactic.introv ns >> return ()
/--
The tactic `rename h₁ h₂` renames hypothesis `h₁` into `h₂` in the current local context.
-/
meta def rename : parse ident → parse ident → tactic unit :=
tactic.rename
/--
This tactic applies to any goal.
The argument term is a term well-formed in the local context of the main goal.
The tactic apply tries to match the current goal against the conclusion of the type of term.
If it succeeds, then the tactic returns as many subgoals as the number of non-dependent premises
that have not been fixed by type inference or type class resolution.
The tactic `apply` uses higher-order pattern matching, type class resolution, and
first-order unification with dependent types.
-/
meta def apply (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.apply
/--
Similar to the `apply` tactic, but it also creates subgoals for dependent premises
that have not been fixed by type inference or type class resolution.
-/
meta def fapply (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.fapply
/--
This tactic tries to close the main goal `... |- U` using type class resolution.
It succeeds if it generates a term of type `U` using type class resolution.
-/
meta def apply_instance : tactic unit :=
tactic.apply_instance
/--
This tactic applies to any goal. It behaves like `exact` with a big difference:
the user can leave some holes `_` in the term.
`refine` will generate as many subgoals as there are holes in the term.
Note that some holes may be implicit.
The type of holes must be either synthesized by the system or declared by
an explicit type ascription like (e.g., `(_ : nat → Prop)`).
-/
meta def refine (q : parse texpr) : tactic unit :=
tactic.refine q
/--
This tactic looks in the local context for an hypothesis which type is equal to the goal target.
If it is the case, the subgoal is proved. Otherwise, it fails.
-/
meta def assumption : tactic unit :=
tactic.assumption
private meta def change_core (e : expr) : option expr → tactic unit
| none := tactic.change e
| (some h) :=
do num_reverted : ℕ ← revert h,
expr.pi n bi d b ← target,
tactic.change $ expr.pi n bi e b,
intron num_reverted
/--
This tactic applies to any goal. `change U` replaces the main goal target `T` with `U`
providing that `U` is well-formed with respect to the main goal local context,
and `T` and `U` are definitionally equal. `change U at h` will change a local hypothesis
with `U`. `change A with B at h1 h2 ...` will replace `A` with `B` in all the supplied
hypotheses (or `*`), or in the goal if no `at` clause is specified, provided that
`A` and `B` are definitionally equal.
-/
meta def change (q : parse texpr) : parse (tk "with" *> texpr)? → parse location → tactic unit
| none (loc.ns []) := do e ← i_to_expr q, change_core e none
| none (loc.ns [h]) := do eq ← i_to_expr q, eh ← get_local h, change_core eq (some eh)
| none _ := fail "change-at does not support multiple locations"
| (some w) l :=
do hs ← l.get_locals,
eq ← i_to_expr_strict q,
ew ← i_to_expr_strict w,
let repl := λe : expr, e.replace (λ a n, if a = eq then some ew else none),
hs.mmap' (λh, do e ← infer_type h, change_core (repl e) (some h)),
if l.include_goal then do g ← target, change_core (repl g) none else skip
/--
This tactic applies to any goal. It gives directly the exact proof
term of the goal. Let `T` be our goal, let `p` be a term of type `U` then
`exact p` succeeds iff `T` and `U` are definitionally equal.
-/
meta def exact (q : parse texpr) : tactic unit :=
do tgt : expr ← target,
i_to_expr_strict ``(%%q : %%tgt) >>= tactic.exact
/--
Like `exact`, but takes a list of terms and checks that all goals
are discharged after the tactic.
-/
meta def exacts : parse qexpr_list_or_texpr → tactic unit
| [] := done
| (t :: ts) := exact t >> exacts ts
/--
`revert h₁ ... hₙ` applies to any goal with hypotheses `h₁` ... `hₙ`.
It moves the hypotheses and its dependencies to the goal target.
This tactic is the inverse of `intro`.
-/
meta def revert (ids : parse ident*) : tactic unit :=
do hs ← mmap tactic.get_local ids, revert_lst hs, skip
private meta def resolve_name' (n : name) : tactic expr :=
do {
p ← resolve_name n,
match p with
| expr.const n _ := mk_const n -- create metavars for universe levels
| _ := i_to_expr p
end
}
/- Version of to_expr that tries to bypass the elaborator if `p` is just a constant or local constant.
This is not an optimization, by skipping the elaborator we make sure that no unwanted resolution is used.
Example: the elaborator will force any unassigned ?A that must have be an instance of (has_one ?A) to nat.
Remark: another benefit is that auxiliary temporary metavariables do not appear in error messages. -/
private meta def to_expr' (p : pexpr) : tactic expr :=
match p with
| (const c []) := do new_e ← resolve_name' c, save_type_info new_e p, return new_e
| (local_const c _ _ _) := do new_e ← resolve_name' c, save_type_info new_e p, return new_e
| _ := i_to_expr p
end
meta structure rw_rule :=
(pos : pos)
(symm : bool)
(rule : pexpr)
meta instance rw_rule.reflect : has_reflect rw_rule :=
λ ⟨p, s, r⟩, `(_)
private meta def rw_goal (m : transparency) (rs : list rw_rule) : tactic unit :=
rs.mfor' $ λ r, save_info r.pos >> to_expr' r.rule >>= rewrite_core m tt tt occurrences.all r.symm
private meta def rw_hyp (m : transparency) (rs : list rw_rule) (hname : name) : tactic unit :=
rs.mfor' $ λ r,
do h ← get_local hname,
save_info r.pos,
e ← to_expr' r.rule,
rewrite_at_core m tt tt occurrences.all r.symm e h
private meta def rw_hyps (m : transparency) (rs : list rw_rule) (hs : list name) : tactic unit :=
hs.mfor' (rw_hyp m rs)
meta def rw_rule_p (ep : parser pexpr) : parser rw_rule :=
rw_rule.mk <$> cur_pos <*> (option.is_some <$> (tk "-")?) <*> ep
meta structure rw_rules_t :=
(rules : list rw_rule)
(end_pos : option pos)
meta instance rw_rules_t.reflect : has_reflect rw_rules_t :=
λ ⟨rs, p⟩, `(_)
-- accepts the same content as `qexpr_list_or_texpr`, but with correct goal info pos annotations
meta def rw_rules : parser rw_rules_t :=
(tk "[" *>
rw_rules_t.mk <$> sep_by (skip_info (tk ",")) (set_goal_info_pos $ rw_rule_p (qexpr 0))
<*> (some <$> cur_pos <* set_goal_info_pos (tk "]")))
<|> rw_rules_t.mk <$> (list.ret <$> rw_rule_p texpr) <*> return none
private meta def rw_core (m : transparency) (rs : parse rw_rules) (loca : parse location) : tactic unit :=
match loca with
| loc.wildcard := fail "wildcard not allowed with rewrite"
| loc.ns [] := rw_goal m rs.rules
| loc.ns hs := rw_hyps m rs.rules hs
end >> try (reflexivity reducible)
>> (returnopt rs.end_pos >>= save_info <|> skip)
meta def rewrite : parse rw_rules → parse location → tactic unit :=
rw_core reducible
meta def rw : parse rw_rules → parse location → tactic unit :=
rewrite
/- rewrite followed by assumption -/
meta def rwa (q : parse rw_rules) (l : parse location) : tactic unit :=
rewrite q l >> try assumption
meta def erewrite : parse rw_rules → parse location → tactic unit :=
rw_core semireducible
meta def erw : parse rw_rules → parse location → tactic unit :=
erewrite
private meta def get_type_name (e : expr) : tactic name :=
do e_type ← infer_type e >>= whnf,
(const I ls) ← return $ get_app_fn e_type,
return I
precedence `generalizing` : 0
meta def induction (p : parse texpr) (rec_name : parse using_ident) (ids : parse with_ident_list)
(revert : parse $ (tk "generalizing" *> ident*)?) : tactic unit :=
do e ← i_to_expr p,
locals ← mmap tactic.get_local $ revert.get_or_else [],
n ← revert_lst locals,
tactic.induction e ids rec_name,
all_goals (intron n)
meta def cases (p : parse texpr) (ids : parse with_ident_list) : tactic unit :=
do e ← i_to_expr p,
tactic.cases e ids
private meta def find_case (goals : list expr) (ty : name) (idx : nat) (num_indices : nat) : option expr → expr → option (expr × expr)
| case e := if e.has_meta_var then match e with
| (mvar _ _) :=
do case ← case,
guard $ e ∈ goals,
pure (case, e)
| (app _ _) :=
let idx :=
match e.get_app_fn with
| const (name.mk_string rec ty') _ :=
guard (ty' = ty) >>
match mk_simple_name rec with
| `drec := some idx | `rec := some idx
-- indices + major premise
| `dcases_on := some (idx + num_indices + 1) | `cases_on := some (idx + num_indices + 1)
| _ := none
end
| _ := none
end in
match idx with
| none := list.foldl (<|>) (find_case case e.get_app_fn) $ e.get_app_args.map (find_case case)
| some idx :=
let args := e.get_app_args in
do arg ← args.nth idx,
args.enum.foldl
(λ acc ⟨i, arg⟩, match acc with
| some _ := acc
| _ := if i ≠ idx then find_case none arg else none
end)
-- start recursion with likely case
(find_case (some arg) arg)
end
| (lam _ _ _ e) := find_case case e
| (macro n args) := list.foldl (<|>) none $ args.map (find_case case)
| _ := none
end else none
private meta def rename_lams : expr → list name → tactic unit
| (lam n _ _ e) (n'::ns) := (rename n n' >> rename_lams e ns) <|> rename_lams e (n'::ns)
| _ _ := skip
/-- Focuses on the `induction`/`cases` subgoal corresponding to the given introduction rule,
optionally renaming introduced locals. -/
meta def case (ctor : parse ident) (ids : parse ident_*) (tac : itactic) : tactic unit :=
do r ← result,
env ← get_env,
ctor ← resolve_constant ctor
<|> fail ("'" ++ to_string ctor ++ "' is not a constructor"),
ty ← (env.inductive_type_of ctor).to_monad
<|> fail ("'" ++ to_string ctor ++ "' is not a constructor"),
let ctors := env.constructors_of ty,
let idx := env.inductive_num_params ty + /- motive -/ 1 +
list.index_of ctor ctors,
gs ← get_goals,
(case, g) ← (find_case gs ty idx (env.inductive_num_indices ty) none r ).to_monad
<|> fail "could not find open goal of given case",
set_goals $ g :: gs.filter (≠ g),
rename_lams case ids,
solve1 tac
meta def destruct (p : parse texpr) : tactic unit :=
i_to_expr p >>= tactic.destruct
meta def generalize (p : parse qexpr) (x : parse ident) : tactic unit :=
do e ← i_to_expr p,
tactic.generalize e x
meta def generalize2 (p : parse qexpr) (x : parse ident) (h : parse ident) : tactic unit :=
do tgt ← target,
e ← to_expr p,
let e' := tgt.replace $ λa n, if a = e then some (var n.succ) else none,
to_expr ``(Π x, %%e = x → %%e') >>= assert h,
swap,
t ← get_local h,
exact ``(%%t %%p rfl),
intro x,
intro h
meta def ginduction (p : parse texpr) (rec_name : parse using_ident) (ids : parse with_ident_list) : tactic unit :=
do x ← mk_fresh_name,
let (h, hs) := (match ids with
| [] := (`_h, [])
| (h :: hs) := (h, hs)
end : name × list name),
generalize2 p x h,
t ← get_local x,
induction (to_pexpr t) rec_name hs ([] : list name)
meta def trivial : tactic unit :=
tactic.triv <|> tactic.reflexivity <|> tactic.contradiction <|> fail "trivial tactic failed"
/-- Closes the main goal using sorry. -/
meta def admit : tactic unit := tactic.admit
/--
This tactic applies to any goal. The contradiction tactic attempts to find in the current local context an hypothesis that is equivalent to
an empty inductive type (e.g. `false`), a hypothesis of the form `c_1 ... = c_2 ...` where `c_1` and `c_2` are distinct constructors,
or two contradictory hypotheses.
-/
meta def contradiction : tactic unit :=
tactic.contradiction
meta def repeat : itactic → tactic unit :=
tactic.repeat
meta def try : itactic → tactic unit :=
tactic.try
meta def skip : tactic unit :=
tactic.skip
meta def solve1 : itactic → tactic unit :=
tactic.solve1
meta def abstract (id : parse ident? ) (tac : itactic) : tactic unit :=
tactic.abstract tac id
meta def all_goals : itactic → tactic unit :=
tactic.all_goals
meta def any_goals : itactic → tactic unit :=
tactic.any_goals
meta def focus (tac : itactic) : tactic unit :=
tactic.focus [tac]
/--
This tactic applies to any goal. `assert h : T` adds a new hypothesis of name `h` and type `T` to the current goal and opens a new subgoal with target `T`.
The new subgoal becomes the main goal.
-/
meta def assert (h : parse ident) (q : parse $ tk ":" *> texpr) : tactic unit :=
do e ← i_to_expr_strict q,
tactic.assert h e,
return ()
meta def define (h : parse ident) (q : parse $ tk ":" *> texpr) : tactic unit :=
do e ← i_to_expr_strict q,
tactic.define h e,
return ()
/--
This tactic applies to any goal. `note h : T := p` adds a new hypothesis of name `h` and type `T` to the current goal if `p` a term of type `T`.
-/
meta def note (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?) (q₂ : parse $ tk ":=" *> texpr) : tactic unit :=
match q₁ with
| some e := do
t ← i_to_expr_strict e,
v ← i_to_expr_strict ``(%%q₂ : %%t),
tactic.assertv (h.get_or_else `this) t v,
return ()
| none := do
p ← i_to_expr_strict q₂,
tactic.note (h.get_or_else `this) none p,
return ()
end
meta def pose (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?) (q₂ : parse $ tk ":=" *> texpr) : tactic unit :=
match q₁ with
| some e := do
t ← i_to_expr_strict e,
v ← i_to_expr_strict ``(%%q₂ : %%t),
tactic.definev (h.get_or_else `this) t v,
return ()
| none := do
p ← i_to_expr_strict q₂,
tactic.pose (h.get_or_else `this) none p,
return ()
end
/--
This tactic displays the current state in the tracing buffer.
-/
meta def trace_state : tactic unit :=
tactic.trace_state
/--
`trace a` displays `a` in the tracing buffer.
-/
meta def trace {α : Type} [has_to_tactic_format α] (a : α) : tactic unit :=
tactic.trace a
meta def existsi : parse qexpr_list_or_texpr → tactic unit
| [] := return ()
| (p::ps) := i_to_expr p >>= tactic.existsi >> existsi ps
/--
This tactic applies to a goal such that its conclusion is an inductive type (say `I`).
It tries to apply each constructor of `I` until it succeeds.
-/
meta def constructor : tactic unit :=
tactic.constructor
meta def left : tactic unit :=
tactic.left
meta def right : tactic unit :=
tactic.right
meta def split : tactic unit :=
tactic.split
meta def exfalso : tactic unit :=
tactic.exfalso
/--
The injection tactic is based on the fact that constructors of inductive datatypes are injections.
That means that if `c` is a constructor of an inductive datatype,
and if `(c t₁)` and `(c t₂)` are two terms that are equal then `t₁` and `t₂` are equal too.
If `q` is a proof of a statement of conclusion `t₁ = t₂`,
then injection applies injectivity to derive the equality of all arguments of `t₁` and `t₂` placed in the same positions.
For example, from `(a::b) = (c::d)` we derive `a=c` and `b=d`.
To use this tactic `t₁` and `t₂` should be constructor applications of the same constructor.
Given `h : a::b = c::d`, the tactic `injection h` adds to new hypothesis with types `a = c` and `b = d`
to the main goal. The tactic `injection h with h₁ h₂` uses the names `h₁` an `h₂` to name the new
hypotheses.
-/
meta def injection (q : parse texpr) (hs : parse with_ident_list) : tactic unit :=
do e ← i_to_expr q, tactic.injection_with e hs, try assumption
meta def injections (hs : parse with_ident_list) : tactic unit :=
do tactic.injections_with hs, try assumption
end interactive
section mk_simp_set
open expr
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
private meta def report_invalid_simp_lemma {α : Type} (n : name): tactic α :=
fail ("invalid simplification lemma '" ++ to_string n ++ "' (use command 'set_option trace.simp_lemmas true' for more details)")
private meta def simp_lemmas.resolve_and_add (s : simp_lemmas) (n : name) (ref : pexpr) : tactic simp_lemmas :=
do
p ← resolve_name n,
-- unpack local refs
let e := p.erase_annotations.get_app_fn.erase_annotations,
match e with
| const n _ :=
(do b ← is_valid_simp_lemma_cnst reducible n, guard b, save_const_type_info n ref, s.add_simp n)
<|>
(do eqns ← get_eqn_lemmas_for tt n, guard (eqns.length > 0), save_const_type_info n ref, add_simps s eqns)
<|>
report_invalid_simp_lemma n
| _ :=
(do e ← i_to_expr p, b ← is_valid_simp_lemma reducible e, guard b, try (save_type_info e ref), s.add e)
<|>
report_invalid_simp_lemma n
end
private meta def simp_lemmas.add_pexpr (s : simp_lemmas) (p : pexpr) : tactic simp_lemmas :=
match p with
| (const c []) := simp_lemmas.resolve_and_add s c p
| (local_const c _ _ _) := simp_lemmas.resolve_and_add s c p
| _ := do new_e ← i_to_expr p, s.add new_e
end
private meta def simp_lemmas.append_pexprs : simp_lemmas → list pexpr → tactic simp_lemmas
| s [] := return s
| s (l::ls) := do new_s ← simp_lemmas.add_pexpr s l, simp_lemmas.append_pexprs new_s ls
meta def mk_simp_set (no_dflt : bool) (attr_names : list name) (hs : list pexpr) (ex : list name) : tactic simp_lemmas :=
do s₀ ← join_user_simp_lemmas no_dflt attr_names,
s₁ ← simp_lemmas.append_pexprs s₀ hs,
-- add equational lemmas, if any
ex ← ex.mfor (λ n, list.cons n <$> get_eqn_lemmas_for tt n),
return $ simp_lemmas.erase s₁ $ ex.join
end mk_simp_set
namespace interactive
open interactive interactive.types expr
private meta def simp_goal (cfg : simp_config) : simp_lemmas → tactic unit
| s := do
(new_target, pr) ← target >>= simplify_core cfg s `eq,
replace_target new_target pr
private meta def simp_hyp (cfg : simp_config) (s : simp_lemmas) (h_name : name) : tactic unit :=
do h ← get_local h_name,
h_type ← infer_type h,
(h_new_type, pr) ← simplify_core cfg s `eq h_type,
replace_hyp h h_new_type pr,
return ()
private meta def simp_hyps (cfg : simp_config) : simp_lemmas → list name → tactic unit
| s [] := skip
| s (h::hs) := simp_hyp cfg s h >> simp_hyps s hs
private meta def simp_core (cfg : simp_config) (no_dflt : bool) (ctx : list expr) (hs : list pexpr) (attr_names : list name) (ids : list name) (locat : loc) : tactic unit :=
do s ← mk_simp_set no_dflt attr_names hs ids,
s ← s.append ctx,
match locat : _ → tactic unit with
| loc.wildcard :=
do ls ← local_context,
let loc_names := ls.map expr.local_pp_name,
revert_lst ls,
simp_intro_aux cfg ff s ff loc_names,
return ()
| (loc.ns []) := simp_goal cfg s
| (loc.ns hs) := simp_hyps cfg s hs
end,
try tactic.triv, try (tactic.reflexivity reducible)
/--
This tactic uses lemmas and hypotheses to simplify the main goal target or non-dependent hypotheses.
It has many variants.
- `simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`.
- `simp [h_1, ..., h_n]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and the given `h_i`s.
The `h_i`'s are terms. If a `h_i` is a definition `f`, then the equational lemmas associated with `f` are used.
This is a convenient way to "unfold" `f`.
- `simp only [h_1, ..., h_n]` is like `simp [h_1, ..., h_n]` but does not use `[simp]` lemmas
- `simp without id_1 ... id_n` simplifies the main goal target using the lemmas tagged with the attribute `[simp]`,
but removes the ones named `id_i`s.
- `simp at h_1 ... h_n` simplifies the non dependent hypotheses `h_1 : T_1` ... `h_n : T : n`. The tactic fails if the target or another hypothesis depends on one of them.
- `simp at *` simplifies all the hypotheses and the goal.
- `simp with attr_1 ... attr_n` simplifies the main goal target using the lemmas tagged with any of the attributes `[attr_1]`, ..., `[attr_n]` or `[simp]`.
-/
meta def simp (no_dflt : parse only_flag) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) (locat : parse location)
(cfg : simp_config := {}) : tactic unit :=
simp_core cfg no_dflt [] hs attr_names ids locat
/--
Similar to the `simp` tactic, but adds all applicable hypotheses as simplification rules.
-/
meta def simp_using_hs (no_dflt : parse only_flag) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list)
(cfg : simp_config := {}) : tactic unit :=
do ctx ← collect_ctx_simps,
simp_core cfg no_dflt ctx hs attr_names ids (loc.ns [])
meta def simph (no_dflt : parse only_flag) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list)
(cfg : simp_config := {}) : tactic unit :=
simp_using_hs no_dflt hs attr_names ids cfg
meta def simp_intros (ids : parse ident_*) (no_dflt : parse only_flag) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list)
(wo_ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit :=
do s ← mk_simp_set no_dflt attr_names hs wo_ids,
match ids with
| [] := simp_intros_using s cfg
| ns := simp_intro_lst_using ns s cfg
end,
try triv >> try (reflexivity reducible)
meta def simph_intros (ids : parse ident_*) (no_dflt : parse only_flag) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list)
(wo_ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit :=
do s ← mk_simp_set no_dflt attr_names hs wo_ids,
match ids with
| [] := simph_intros_using s cfg
| ns := simph_intro_lst_using ns s cfg
end,
try triv >> try (reflexivity reducible)
private meta def dsimp_hyps (s : simp_lemmas) (hs : list name) : tactic unit :=
hs.mfor' (λ h, get_local h >>= dsimp_at_core s)
meta def dsimp (no_dflt : parse only_flag) (es : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) : parse location → tactic unit
| (loc.ns []) := do s ← mk_simp_set no_dflt attr_names es ids, tactic.dsimp_core s
| (loc.ns hs) := do s ← mk_simp_set no_dflt attr_names es ids, dsimp_hyps s hs
| (loc.wildcard) := do ls ← local_context,
n ← revert_lst ls,
s ← mk_simp_set no_dflt attr_names es ids,
tactic.dsimp_core s,
intron n
/--
This tactic applies to a goal that has the form `t ~ u` where `~` is a reflexive relation.
That is, a relation which has a reflexivity lemma tagged with the attribute `[refl]`.
The tactic checks whether `t` and `u` are definitionally equal and then solves the goal.
-/
meta def reflexivity : tactic unit :=
tactic.reflexivity
/--
Shorter name for the tactic `reflexivity`.
-/
meta def refl : tactic unit :=
tactic.reflexivity
meta def symmetry : tactic unit :=
tactic.symmetry
meta def transitivity (q : parse texpr?) : tactic unit :=
tactic.transitivity >> match q with
| none := skip
| some q :=
do (r, lhs, rhs) ← target_lhs_rhs,
i_to_expr q >>= unify rhs
end
meta def ac_reflexivity : tactic unit :=
tactic.ac_refl
meta def ac_refl : tactic unit :=
tactic.ac_refl
meta def cc : tactic unit :=
tactic.cc
meta def subst (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.subst >> try (tactic.reflexivity reducible)
meta def clear : parse ident* → tactic unit :=
tactic.clear_lst
private meta def to_qualified_name_core : name → list name → tactic name
| n [] := fail $ "unknown declaration '" ++ to_string n ++ "'"
| n (ns::nss) := do
curr ← return $ ns ++ n,
env ← get_env,
if env.contains curr then return curr
else to_qualified_name_core n nss
private meta def to_qualified_name (n : name) : tactic name :=
do env ← get_env,
if env.contains n then return n
else do
ns ← open_namespaces,
to_qualified_name_core n ns
private meta def to_qualified_names : list name → tactic (list name)
| [] := return []
| (c::cs) := do new_c ← to_qualified_name c, new_cs ← to_qualified_names cs, return (new_c::new_cs)
private meta def dunfold_hyps : list name → list name → tactic unit
| cs [] := skip
| cs (h::hs) := get_local h >>= dunfold_at cs >> dunfold_hyps cs hs
meta def dunfold : parse ident* → parse location → tactic unit
| cs (loc.ns []) := do new_cs ← to_qualified_names cs, tactic.dunfold new_cs
| cs (loc.ns hs) := do new_cs ← to_qualified_names cs, dunfold_hyps new_cs hs
| cs (loc.wildcard) := do ls ← tactic.local_context,
n ← revert_lst ls,
new_cs ← to_qualified_names cs,
tactic.dunfold new_cs,
intron n
/- TODO(Leo): add support for non-refl lemmas -/
meta def unfold : parse ident* → parse location → tactic unit :=
dunfold
private meta def dunfold_hyps_occs : name → occurrences → list name → tactic unit
| c occs [] := skip
| c occs (h::hs) := get_local h >>= dunfold_core_at occs [c] >> dunfold_hyps_occs c occs hs
meta def dunfold_occs : parse ident → parse location → list nat → tactic unit
| c (loc.ns []) ps := do new_c ← to_qualified_name c, tactic.dunfold_occs_of ps new_c
| c (loc.ns hs) ps := do new_c ← to_qualified_name c, dunfold_hyps_occs new_c (occurrences.pos ps) hs
| c (loc.wildcard) ps := fail "wildcard not allowed when unfolding occurences"
/- TODO(Leo): add support for non-refl lemmas -/
meta def unfold_occs : parse ident → parse location → list nat → tactic unit :=
dunfold_occs
private meta def delta_hyps : list name → list name → tactic unit
| cs [] := skip
| cs (h::hs) := get_local h >>= delta_at cs >> dunfold_hyps cs hs
meta def delta : parse ident* → parse location → tactic unit
| cs (loc.ns []) := do new_cs ← to_qualified_names cs, tactic.delta new_cs
| cs (loc.ns hs) := do new_cs ← to_qualified_names cs, delta_hyps new_cs hs
| cs (loc.wildcard) := do ls ← tactic.local_context,
n ← revert_lst ls,
new_cs ← to_qualified_names cs,
tactic.delta new_cs,
intron n
meta def apply_opt_param : tactic unit :=
tactic.apply_opt_param
meta def apply_auto_param : tactic unit :=
tactic.apply_auto_param
meta def fail_if_success (tac : itactic) : tactic unit :=
tactic.fail_if_success tac
meta def success_if_fail (tac : itactic) : tactic unit :=
tactic.success_if_fail tac
meta def guard_expr_eq (t : expr) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do e ← to_expr p, guard (alpha_eqv t e)
meta def guard_target (p : parse texpr) : tactic unit :=
do t ← target, guard_expr_eq t p
meta def by_cases (q : parse texpr) (n : parse (tk "with" *> ident)?): tactic unit :=
do p ← tactic.to_expr_strict q,
tactic.by_cases p (n.get_or_else `h)
meta def by_contradiction : tactic unit :=
tactic.by_contradiction >> return ()
meta def by_contra : tactic unit :=
tactic.by_contradiction >> return ()
/-- Fail if there are unsolved goals. -/
meta def done : tactic unit :=
tactic.done
private meta def show_goal_aux (p : pexpr) : list expr → list expr → tactic unit
| [] r := fail "show_goal tactic failed"
| (g::gs) r := do
do {set_goals [g], g_ty ← target, ty ← i_to_expr p, unify g_ty ty, set_goals (g :: r.reverse ++ gs), tactic.change ty}
<|>
show_goal_aux gs (g::r)
meta def show_goal (q : parse texpr) : tactic unit :=
do gs ← get_goals,
show_goal_aux q gs []
end interactive
end tactic
section add_interactive
open tactic
/- See add_interactive -/
private meta def add_interactive_aux (new_namespace : name) : list name → command
| [] := return ()
| (n::ns) := do
env ← get_env,
d_name ← resolve_constant n,
(declaration.defn _ ls ty val hints trusted) ← env.get d_name,
(name.mk_string h _) ← return d_name,
let new_name := `tactic.interactive <.> h,
add_decl (declaration.defn new_name ls ty (expr.const d_name (ls.map level.param)) hints trusted),
add_interactive_aux ns
/--
Copy a list of meta definitions in the current namespace to
tactic.interactive.
This command is useful when we want to update tactic.interactive
without closing the current namespace.
-/
meta def add_interactive (ns : list name) (p : name := `tactic.interactive) : command :=
add_interactive_aux p ns
end add_interactive
|
4e84c31ada19c656b68df29e8f08aca7701c1660 | f3849be5d845a1cb97680f0bbbe03b85518312f0 | /library/init/data/list/basic.lean | 36b44d167aaa38311237092e65b31bdb28b85017 | [
"Apache-2.0"
] | permissive | bjoeris/lean | 0ed95125d762b17bfcb54dad1f9721f953f92eeb | 4e496b78d5e73545fa4f9a807155113d8e6b0561 | refs/heads/master | 1,611,251,218,281 | 1,495,337,658,000 | 1,495,337,658,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,865 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.logic init.data.nat.basic
open decidable list
universes u v w
instance (α : Type u) : inhabited (list α) :=
⟨list.nil⟩
variables {α : Type u} {β : Type v} {γ : Type w}
namespace list
protected def append : list α → list α → list α
| [] l := l
| (h :: s) t := h :: (append s t)
instance : has_append (list α) :=
⟨list.append⟩
protected def mem : α → list α → Prop
| a [] := false
| a (b :: l) := a = b ∨ mem a l
instance : has_mem α (list α) :=
⟨list.mem⟩
instance decidable_mem [decidable_eq α] (a : α) : ∀ (l : list α), decidable (a ∈ l)
| [] := is_false not_false
| (b::l) :=
if h₁ : a = b then is_true (or.inl h₁)
else match decidable_mem l with
| is_true h₂ := is_true (or.inr h₂)
| is_false h₂ := is_false (not_or h₁ h₂)
end
def concat : list α → α → list α
| [] a := [a]
| (b::l) a := b :: concat l a
instance : has_emptyc (list α) :=
⟨list.nil⟩
protected def insert [decidable_eq α] (a : α) (l : list α) : list α :=
if a ∈ l then l else concat l a
instance [decidable_eq α] : has_insert α (list α) :=
⟨list.insert⟩
protected def union [decidable_eq α] : list α → list α → list α
| l₁ [] := l₁
| l₁ (a::l₂) := union (insert a l₁) l₂
instance [decidable_eq α] : has_union (list α) :=
⟨list.union⟩
protected def inter [decidable_eq α] : list α → list α → list α
| [] l₂ := []
| (a::l₁) l₂ := if a ∈ l₂ then a :: inter l₁ l₂ else inter l₁ l₂
instance [decidable_eq α] : has_inter (list α) :=
⟨list.inter⟩
def length : list α → nat
| [] := 0
| (a :: l) := length l + 1
def empty : list α → bool
| [] := tt
| (_ :: _) := ff
open option nat
def nth : list α → nat → option α
| [] n := none
| (a :: l) 0 := some a
| (a :: l) (n+1) := nth l n
def update_nth : list α → ℕ → α → list α
| (x::xs) 0 a := a :: xs
| (x::xs) (i+1) a := x :: update_nth xs i a
| [] _ _ := []
def remove_nth : list α → ℕ → list α
| [] _ := []
| (x::xs) 0 := xs
| (x::xs) (i+1) := x :: remove_nth xs i
def remove_all [decidable_eq α] : list α → list α → list α
| (x :: xs) ys := (if x ∈ ys then remove_all xs ys else x :: remove_all xs ys)
| [] ys := []
def nth_le : Π (l : list α) (n), n < l.length → α
| [] n h := absurd h (not_lt_zero n)
| (a :: l) 0 h := a
| (a :: l) (n+1) h := nth_le l n (le_of_succ_le_succ h)
def head [inhabited α] : list α → α
| [] := default α
| (a :: l) := a
def tail : list α → list α
| [] := []
| (a :: l) := l
def reverse_core : list α → list α → list α
| [] r := r
| (a::l) r := reverse_core l (a::r)
def reverse : list α → list α :=
λ l, reverse_core l []
def map (f : α → β) : list α → list β
| [] := []
| (a :: l) := f a :: map l
def for : list α → (α → β) → list β :=
flip map
def map₂ (f : α → β → γ) : list α → list β → list γ
| [] _ := []
| _ [] := []
| (x::xs) (y::ys) := f x y :: map₂ xs ys
def join : list (list α) → list α
| [] := []
| (l :: ls) := l ++ (join ls)
def filter (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (a::l) := if p a then a :: filter l else filter l
def partition (p : α → Prop) [decidable_pred p] : list α → list α × list α
| [] := ([], [])
| (a::l) := let (l₁, l₂) := partition l in if p a then (a :: l₁, l₂) else (l₁, a :: l₂)
def take_while (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (a::l) := if p a then a :: take_while l else []
def drop_while (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (a::l) := if p a then drop_while l else a::l
def span (p : α → Prop) [decidable_pred p] : list α → list α × list α
| [] := ([], [])
| (a::xs) := if p a then let (l, r) := span xs in (a :: l, r) else ([], a::xs)
def find (p : α → Prop) [decidable_pred p] : list α → option α
| [] := none
| (a::l) := if p a then some a else find l
def find_index (p : α → Prop) [decidable_pred p] : list α → nat
| [] := 0
| (a::l) := if p a then 0 else succ (find_index l)
def find_indexes_aux (p : α → Prop) [decidable_pred p] : list α → nat → list nat
| [] n := []
| (a::l) n := let t := find_indexes_aux l (succ n) in if p a then n :: t else t
def find_indexes (p : α → Prop) [decidable_pred p] (l : list α) : list nat :=
find_indexes_aux p l 0
def index_of [decidable_eq α] (a : α) : list α → nat := find_index (eq a)
def indexes_of [decidable_eq α] (a : α) : list α → list nat := find_indexes (eq a)
def dropn : ℕ → list α → list α
| 0 a := a
| (succ n) [] := []
| (succ n) (x::r) := dropn n r
def taken : ℕ → list α → list α
| 0 a := []
| (succ n) [] := []
| (succ n) (x :: r) := x :: taken n r
def split_at : ℕ → list α → list α × list α
| 0 a := ([], a)
| (succ n) [] := ([], [])
| (succ n) (x :: xs) := let (l, r) := split_at n xs in (x :: l, r)
def foldl (f : α → β → α) : α → list β → α
| a [] := a
| a (b :: l) := foldl (f a b) l
def foldr (f : α → β → β) (b : β) : list α → β
| [] := b
| (a :: l) := f a (foldr l)
def any (l : list α) (p : α → bool) : bool :=
foldr (λ a r, p a || r) ff l
def all (l : list α) (p : α → bool) : bool :=
foldr (λ a r, p a && r) tt l
def bor (l : list bool) : bool := any l id
def band (l : list bool) : bool := all l id
def zip_with (f : α → β → γ) : list α → list β → list γ
| (x::xs) (y::ys) := f x y :: zip_with xs ys
| _ _ := []
def zip : list α → list β → list (prod α β) :=
zip_with prod.mk
def unzip : list (α × β) → list α × list β
| [] := ([], [])
| ((a, b) :: t) := match unzip t with (al, bl) := (a::al, b::bl) end
def repeat (a : α) : ℕ → list α
| 0 := []
| (succ n) := a :: repeat n
def range_core : ℕ → list ℕ → list ℕ
| 0 l := l
| (succ n) l := range_core n (n :: l)
def range (n : ℕ) : list ℕ :=
range_core n []
def iota : ℕ → list ℕ
| 0 := []
| (succ n) := succ n :: iota n
def enum_from : ℕ → list α → list (ℕ × α)
| n [] := nil
| n (x :: xs) := (n, x) :: enum_from (n + 1) xs
def enum : list α → list (ℕ × α) := enum_from 0
def sum [has_add α] [has_zero α] : list α → α :=
foldl (+) 0
def last : Π l : list α, l ≠ [] → α
| [] h := absurd rfl h
| [a] h := a
| (a::b::l) h := last (b::l) (λ h, list.no_confusion h)
def ilast [inhabited α] : list α → α
| [] := arbitrary α
| [a] := a
| [a, b] := b
| (a::b::l) := ilast l
def intersperse (sep : α) : list α → list α
| [] := []
| [x] := [x]
| (x::xs) := x::sep::intersperse xs
def intercalate (sep : list α) (xs : list (list α)) : list α :=
join (intersperse sep xs)
@[inline] def bind {α : Type u} {β : Type v} (a : list α) (b : α → list β) : list β :=
join (map b a)
@[inline] def ret {α : Type u} (a : α) : list α :=
[a]
def transpose_aux : list α → list (list α) → list (list α)
| [] ls := ls
| (a::i) [] := [a] :: transpose_aux i []
| (a::i) (l::ls) := (a::l) :: transpose_aux i ls
def transpose : list (list α) → list (list α)
| [] := []
| (l::ls) := transpose_aux l (transpose ls)
def sublists_aux : list α → (list α → list β → list β) → list β
| [] f := []
| (a::l) f := f [a] (sublists_aux l (λys r, f ys (f (a :: ys) r)))
def sublists (l : list α) : list (list α) :=
[] :: sublists_aux l cons
def scanl (f : α → β → α) : α → list β → list α
| a [] := [a]
| a (b::l) := a :: scanl (f a b) l
def scanr_aux (f : α → β → β) (b : β) : list α → β × list β
| [] := (b, [])
| (a::l) := let (b', l') := scanr_aux l in (f a b', b' :: l')
def scanr (f : α → β → β) (b : β) (l : list α) : list β :=
let (b', l') := scanr_aux f b l in b' :: l'
def inits : list α → list (list α)
| [] := [[]]
| (a::l) := [] :: map (λt, a::t) (inits l)
def tails : list α → list (list α)
| [] := [[]]
| (a::l) := (a::l) :: tails l
def is_prefix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, l₁ ++ t = l₂
def is_suffix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, t ++ l₁ = l₂
def is_infix (l₁ : list α) (l₂ : list α) : Prop := ∃ s t, s ++ l₁ ++ t = l₂
infix ` <+: `:50 := is_prefix
infix ` <:+ `:50 := is_suffix
infix ` <:+: `:50 := is_infix
end list
|
3977c6990a006882c93b803e8f1c16ef005b399e | 5749d8999a76f3a8fddceca1f6941981e33aaa96 | /src/measure_theory/simple_func_dense.lean | e6040bf12920b7e8edc49d1fb60dfc360866f52c | [
"Apache-2.0"
] | permissive | jdsalchow/mathlib | 13ab43ef0d0515a17e550b16d09bd14b76125276 | 497e692b946d93906900bb33a51fd243e7649406 | refs/heads/master | 1,585,819,143,348 | 1,580,072,892,000 | 1,580,072,892,000 | 154,287,128 | 0 | 0 | Apache-2.0 | 1,540,281,610,000 | 1,540,281,609,000 | null | UTF-8 | Lean | false | false | 15,104 | lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
Show that each Borel measurable function can be approximated,
both pointwise and in L¹ norm, by a sequence of simple functions.
-/
import measure_theory.l1_space
noncomputable theory
open lattice set filter topological_space
open_locale classical topological_space
universes u v
variables {α : Type u} {β : Type v} {ι : Type*}
namespace measure_theory
open ennreal nat metric
open_locale measure_theory
variables [measure_space α] [normed_group β] [second_countable_topology β]
local infixr ` →ₛ `:25 := simple_func
lemma simple_func_sequence_tendsto {f : α → β} (hf : measurable f) :
∃ (F : ℕ → (α →ₛ β)), ∀ x : α, tendsto (λ n, F n x) at_top (𝓝 (f x)) ∧
∀ n, ∥F n x∥ ≤ ∥f x∥ + ∥f x∥ :=
-- enumerate a countable dense subset {e k} of β
let ⟨D, ⟨D_countable, D_dense⟩⟩ := separable_space.exists_countable_closure_eq_univ β in
let e := enumerate_countable D_countable 0 in
let E := range e in
have E_dense : closure E = univ :=
dense_of_subset_dense (subset_range_enumerate D_countable 0) D_dense,
let A' (N k : ℕ) : set α :=
f ⁻¹' (metric.ball (e k) (1 / (N+1 : ℝ)) \ metric.ball 0 (1 / (N+1 : ℝ))) in
let A N := disjointed (A' N) in
have is_measurable_A' : ∀ {N k}, is_measurable (A' N k) :=
λ N k, hf.preimage $ is_measurable.inter is_measurable_ball $ is_measurable.compl is_measurable_ball,
have is_measurable_A : ∀ {N k}, is_measurable (A N k) :=
λ N, is_measurable.disjointed $ λ k, is_measurable_A',
have A_subset_A' : ∀ {N k x}, x ∈ A N k → x ∈ A' N k := λ N k, inter_subset_left _ _,
have dist_ek_fx' : ∀ {x N k}, x ∈ A' N k → (dist (e k) (f x) < 1 / (N+1 : ℝ)) :=
λ x N k, by { rw [dist_comm], simpa using (λ a b, a) },
have dist_ek_fx : ∀ {x N k}, x ∈ A N k → (dist (e k) (f x) < 1 / (N+1 : ℝ)) :=
λ x N k h, dist_ek_fx' (A_subset_A' h),
have norm_fx' : ∀ {x N k}, x ∈ A' N k → (1 / (N+1 : ℝ)) ≤ ∥f x∥ := λ x N k, by simp [ball_0_eq],
have norm_fx : ∀ {x N k}, x ∈ A N k → (1 / (N+1 : ℝ)) ≤ ∥f x∥ := λ x N k h, norm_fx' (A_subset_A' h),
-- construct the desired sequence of simple functions
let M N x := nat.find_greatest (λ M, x ∈ ⋃ k ≤ N, (A M k)) N in
let k N x := nat.find_greatest (λ k, x ∈ A (M N x) k) N in
let F N x := if x ∈ ⋃ M ≤ N, ⋃ k ≤ N, A M k then e (k N x) else 0 in
-- prove properties of the construction above
have k_unique : ∀ {M k k' x}, x ∈ A M k ∧ x ∈ A M k' → k = k' := λ M k k' x h,
begin
by_contradiction k_ne_k',
have : A M k ∩ A M k' ≠ ∅, rw ne_empty_iff_exists_mem, use x, exact h,
have : A M k ∩ A M k' = ∅ := disjoint_disjointed' k k' k_ne_k',
contradiction
end,
have x_mem_Union_k : ∀ {N x}, (x ∈ ⋃ M ≤ N, ⋃ k ≤ N, A M k) → x ∈ ⋃ k ≤ N, A (M N x) k :=
λ N x h,
@nat.find_greatest_spec (λ M, x ∈ ⋃ k ≤ N, (A M k)) _ N (
let ⟨M, hM⟩ := mem_Union.1 (h) in
let ⟨hM₁, hM₂⟩ := mem_Union.1 hM in
⟨M, ⟨hM₁, hM₂⟩⟩),
have x_mem_A : ∀ {N x}, (x ∈ ⋃ M ≤ N, ⋃ k ≤ N, A M k) → x ∈ A (M N x) (k N x) :=
λ N x h,
@nat.find_greatest_spec (λ k, x ∈ A (M N x) k) _ N (
let ⟨k, hk⟩ := mem_Union.1 (x_mem_Union_k h) in
let ⟨hk₁, hk₂⟩ := mem_Union.1 hk in
⟨k, ⟨hk₁, hk₂⟩⟩),
have x_mem_A' : ∀ {N x}, (x ∈ ⋃ M ≤ N, ⋃ k ≤ N, A M k) → x ∈ A' (M N x) (k N x) :=
λ N x h, mem_of_subset_of_mem (inter_subset_left _ _) (x_mem_A h),
-- prove that for all N, (F N) has finite range
have F_finite : ∀ {N}, finite (range (F N)) :=
begin
assume N, apply finite_range_ite,
{ rw range_comp, apply finite_image, exact finite_range_find_greatest },
{ exact finite_range_const }
end,
-- prove that for all N, (F N) is a measurable function
have F_measurable : ∀ {N}, measurable (F N) :=
begin
assume N, refine measurable.if _ _ measurable_const,
-- show `is_measurable {a : α | a ∈ ⋃ (M : ℕ) (H : M ≤ N) (k : ℕ) (H : k ≤ N), A M k}`
{ rw set_of_mem_eq, simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable_A] },
-- show `measurable (λ (x : α), e (k N x))`
apply measurable.comp measurable_from_nat, apply measurable_find_greatest,
assume k' k'_le_N, by_cases k'_eq_0 : k' = 0,
-- if k' = 0
have : {x | k N x = 0} = (-⋃ (M : ℕ) (H : M ≤ N) (k : ℕ) (H : k ≤ N), A M k) ∪
(⋃ (m ≤ N), A m 0 - ⋃ m' (hmm' : m < m') (hm'N : m' ≤ N) (k ≤ N), A m' k),
{ ext, split,
{ rw [mem_set_of_eq, mem_union_eq, or_iff_not_imp_left, mem_compl_eq, not_not_mem],
assume k_eq_0 x_mem,
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff],
refine ⟨M N x, ⟨nat.find_greatest_le, ⟨by { rw ← k_eq_0, exact x_mem_A x_mem} , _⟩⟩⟩,
assume m hMm hmN k k_le_N,
have := nat.find_greatest_is_greatest _ m ⟨hMm, hmN⟩,
{ simp only [not_exists, exists_prop, mem_Union, not_and] at this, exact this k k_le_N },
{ exact ⟨M N x, ⟨nat.find_greatest_le, x_mem_Union_k x_mem⟩⟩ } },
{ simp only [mem_set_of_eq, mem_union_eq, mem_compl_eq],
by_cases x_mem : (x ∉ ⋃ (M : ℕ) (H : M ≤ N) (k : ℕ) (H : k ≤ N), A M k),
{ intro, apply find_greatest_eq_zero, assume k k_le_N hx,
have : x ∈ ⋃ (M : ℕ) (H : M ≤ N) (k : ℕ) (H : k ≤ N), A M k,
{ rw [mem_Union], use M N x,
rw mem_Union, use nat.find_greatest_le,
rw mem_Union, use k, rw mem_Union, use k_le_N, assumption },
contradiction },
{ rw not_not_mem at x_mem, assume h, cases h, contradiction,
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff] at h,
rcases h with ⟨m, ⟨m_le_N, ⟨hx, hm⟩⟩⟩,
by_cases m_lt_M : m < M N x,
{ have := hm (M N x) m_lt_M nat.find_greatest_le (k N x) nat.find_greatest_le,
have := x_mem_A x_mem,
contradiction },
rw not_lt at m_lt_M, by_cases m_gt_M : m > M N x,
{ have := nat.find_greatest_is_greatest _ m ⟨m_gt_M, m_le_N⟩,
{ have : x ∈ ⋃ k ≤ N, A m k,
{ rw mem_Union, use 0, rw mem_Union, use nat.zero_le N, exact hx },
contradiction },
{ use m, split, exact m_le_N, rw mem_Union, use 0, rw mem_Union,
use nat.zero_le _, exact hx } },
rw not_lt at m_gt_M, have M_eq_m := le_antisymm m_lt_M m_gt_M,
rw ← k'_eq_0, exact k_unique ⟨x_mem_A x_mem, by { rw [k'_eq_0, M_eq_m], exact hx }⟩ } } },
-- end of `have`
rw [k'_eq_0, this], apply is_measurable.union,
{ apply is_measurable.compl,
simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable_A] },
{ simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable.diff, is_measurable_A] },
-- if k' ≠ 0
have : {x | k N x = k'} = ⋃(m ≤ N), A m k' - ⋃m' (hmm' : m < m') (hm'N : m' ≤ N) (k ≤ N), A m' k,
{ ext, split,
{ rw [mem_set_of_eq],
assume k_eq_k',
have x_mem : x ∈ ⋃ (M : ℕ) (H : M ≤ N) (k : ℕ) (H : k ≤ N), A M k,
{ have := find_greatest_of_ne_zero k_eq_k' k'_eq_0,
simp only [mem_Union], use M N x, use nat.find_greatest_le, use k', use k'_le_N,
assumption },
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff],
refine ⟨M N x, ⟨nat.find_greatest_le, ⟨by { rw ← k_eq_k', exact x_mem_A x_mem} , _⟩⟩⟩,
assume m hMm hmN k k_le_N,
have := nat.find_greatest_is_greatest _ m ⟨hMm, hmN⟩,
{ simp only [not_exists, exists_prop, mem_Union, not_and] at this, exact this k k_le_N },
exact ⟨M N x, ⟨nat.find_greatest_le, x_mem_Union_k x_mem⟩⟩ },
{ simp only [mem_set_of_eq, mem_union_eq, mem_compl_eq], assume h,
have x_mem : x ∈ ⋃ (M : ℕ) (H : M ≤ N) (k : ℕ) (H : k ≤ N), A M k,
{ simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff] at h,
rcases h with ⟨m, ⟨hm, ⟨hx, _⟩⟩⟩,
simp only [mem_Union], use m, use hm, use k', use k'_le_N, assumption },
simp only [not_exists, exists_prop, mem_Union, not_and, sub_eq_diff, mem_diff] at h,
rcases h with ⟨m, ⟨m_le_N, ⟨hx, hm⟩⟩⟩,
by_cases m_lt_M : m < M N x,
{ have := hm (M N x) m_lt_M nat.find_greatest_le (k N x) nat.find_greatest_le,
have := x_mem_A x_mem,
contradiction },
rw not_lt at m_lt_M, by_cases m_gt_M : m > M N x,
{ have := nat.find_greatest_is_greatest _ m ⟨m_gt_M, m_le_N⟩,
have : x ∈ ⋃ k ≤ N, A m k :=
by { rw mem_Union, use k', rw mem_Union, use k'_le_N, exact hx },
contradiction,
{ use m, split, exact m_le_N, rw mem_Union, use k', rw mem_Union, use k'_le_N, exact hx }},
rw not_lt at m_gt_M, have M_eq_m := le_antisymm m_lt_M m_gt_M,
exact k_unique ⟨x_mem_A x_mem, by { rw M_eq_m, exact hx }⟩ } },
-- end of `have`
rw this, simp [is_measurable.Union, is_measurable.Union_Prop, is_measurable.diff, is_measurable_A]
end,
-- start of proof
⟨λ N, ⟨F N, λ x, measurable.preimage F_measurable is_measurable_singleton, F_finite⟩,
-- The pointwise convergence part of the theorem
λ x, ⟨metric.tendsto_at_top.2 $ λ ε hε, classical.by_cases
--first case : f x = 0
( assume fx_eq_0 : f x = 0,
have x_not_mem_A' : ∀ {M k}, x ∉ A' M k := λ M k,
begin
simp only [mem_preimage, fx_eq_0, metric.mem_ball, one_div_eq_inv, norm_zero,
not_and, not_lt, add_comm, not_le, dist_zero_right, mem_diff],
assume h, rw add_comm, exact inv_pos_of_nat
end,
have x_not_mem_A : ∀ {M k}, x ∉ A M k :=
by { assume M k h, have := disjointed_subset h, exact absurd this x_not_mem_A' },
have F_eq_0 : ∀ {N}, F N x = 0 := λ N, by simp [F, if_neg, mem_Union, x_not_mem_A],
-- end of `have`
⟨0, λ n hn, show dist (F n x) (f x) < ε, by {rw [fx_eq_0, F_eq_0, dist_self], exact hε}⟩ )
--second case : f x ≠ 0
( assume fx_ne_0 : f x ≠ 0,
let ⟨N₀, hN⟩ := exists_nat_one_div_lt (lt_min ((norm_pos_iff _).2 fx_ne_0) hε) in
have norm_fx_gt : _ := (lt_min_iff.1 hN).1,
have ε_gt : _ := (lt_min_iff.1 hN).2,
have x_mem_Union_k_N₀ : x ∈ ⋃ k, A N₀ k :=
let ⟨k, hk⟩ := mem_closure_range_iff_nat.1 (by { rw E_dense, exact mem_univ (f x) }) N₀ in
begin
rw [Union_disjointed, mem_Union], use k,
rw [mem_preimage], simp, rw [← one_div_eq_inv, add_comm],
exact ⟨hk , le_of_lt norm_fx_gt⟩
end,
let ⟨k₀, x_mem_A⟩ := mem_Union.1 x_mem_Union_k_N₀ in
let n := max N₀ k₀ in
have x_mem_Union_Union : ∀ {N} (hN : n ≤ N), x ∈ ⋃ M ≤ N, ⋃ k ≤ N, A M k := assume N hN,
mem_Union.2
⟨N₀, mem_Union.2
⟨le_trans (le_max_left _ _) hN, mem_Union.2
⟨k₀, mem_Union.2 ⟨le_trans (le_max_right _ _) hN, x_mem_A⟩⟩⟩⟩,
have FN_eq : ∀ {N} (hN : n ≤ N), F N x = e (k N x) := assume N hN, if_pos $ x_mem_Union_Union hN,
-- start of proof
⟨n, assume N hN,
have N₀_le_N : N₀ ≤ N := le_trans (le_max_left _ _) hN,
have k₀_le_N : k₀ ≤ N := le_trans (le_max_right _ _) hN,
show dist (F N x) (f x) < ε, from
calc
dist (F N x) (f x) = dist (e (k N x)) (f x) : by rw FN_eq hN
... < 1 / ((M N x : ℝ) + 1) :
begin
have := x_mem_A' (x_mem_Union_Union hN),
rw [mem_preimage, mem_diff, metric.mem_ball, dist_comm] at this, exact this.1
end
... ≤ 1 / ((N₀ : ℝ) + 1) :
@one_div_le_one_div_of_le _ _ ((N₀ : ℝ) + 1) ((M N x : ℝ) + 1) (nat.cast_add_one_pos N₀)
(add_le_add_right (nat.cast_le.2 (nat.le_find_greatest N₀_le_N
begin rw mem_Union, use k₀, rw mem_Union, use k₀_le_N, exact x_mem_A end)) 1)
... < ε : ε_gt ⟩ ),
-- second part of the theorem
assume N, show ∥F N x∥ ≤ ∥f x∥ + ∥f x∥, from
classical.by_cases
( assume h : x ∈ ⋃ M ≤ N, ⋃ k ≤ N, A M k,
calc
∥F N x∥ = dist (F N x) 0 : by simp
... = dist (e (k N x)) 0 : begin simp only [F], rw if_pos h end
... ≤ dist (e (k N x)) (f x) + dist (f x) 0 : dist_triangle _ _ _
... = dist (e (k N x)) (f x) + ∥f x∥ : by simp
... ≤ 1 / ((M N x : ℝ) + 1) + ∥f x∥ :
le_of_lt $ add_lt_add_right (dist_ek_fx (x_mem_A h)) _
... ≤ ∥f x∥ + ∥f x∥ : add_le_add_right (norm_fx (x_mem_A h) ) _)
( assume h : x ∉ ⋃ M ≤ N, ⋃ k ≤ N, A M k,
have F_eq_0 : F N x = 0 := if_neg h,
by { simp only [F_eq_0, norm_zero], exact add_nonneg (norm_nonneg _) (norm_nonneg _) } )⟩⟩
lemma simple_func_sequence_tendsto' {f : α → β} (hfm : measurable f)
(hfi : integrable f) : ∃ (F : ℕ → (α →ₛ β)), (∀n, integrable (F n)) ∧
tendsto (λ n, ∫⁻ x, nndist (F n x) (f x)) at_top (𝓝 0) :=
let ⟨F, hF⟩ := simple_func_sequence_tendsto hfm in
let G : ℕ → α → ennreal := λn x, nndist (F n x) (f x) in
let g : α → ennreal := λx, nnnorm (f x) + nnnorm (f x) + nnnorm (f x) in
have hF_meas : ∀ n, measurable (G n) := λ n, measurable.comp measurable_coe $
(F n).measurable.nndist hfm,
have hg_meas : measurable g := measurable.comp measurable_coe $ measurable.add
(measurable.add hfm.nnnorm hfm.nnnorm) hfm.nnnorm,
have h_bound : ∀ n, ∀ₘ x, G n x ≤ g x := λ n, all_ae_of_all $ λ x, coe_le_coe.2 $
calc
nndist (F n x) (f x) ≤ nndist (F n x) 0 + nndist 0 (f x) : nndist_triangle _ _ _
... = nnnorm (F n x) + nnnorm (f x) : by simp [nndist_eq_nnnorm]
... ≤ nnnorm (f x) + nnnorm (f x) + nnnorm (f x) : by { simp [nnreal.coe_le.symm, (hF x).2] },
have h_finite : lintegral g < ⊤ :=
calc
(∫⁻ x, nnnorm (f x) + nnnorm (f x) + nnnorm (f x)) =
(∫⁻ x, nnnorm (f x)) + (∫⁻ x, nnnorm (f x)) + (∫⁻ x, nnnorm (f x)) :
by rw [lintegral_add, lintegral_add]; simp only [measurable.coe_nnnorm hfm, measurable.add]
... < ⊤ : by { simp only [and_self, add_lt_top], exact hfi},
have h_lim : ∀ₘ x, tendsto (λ n, G n x) at_top (𝓝 0) := all_ae_of_all $ λ x,
begin
apply (@tendsto_coe ℕ at_top (λ n, nndist (F n x) (f x)) 0).2,
apply (@nnreal.tendsto_coe ℕ at_top (λ n, nndist (F n x) (f x)) 0).1,
apply tendsto_iff_dist_tendsto_zero.1 (hF x).1
end,
begin
use F, split,
{ assume n, exact
calc
(∫⁻ a, nnnorm (F n a)) ≤ ∫⁻ a, nnnorm (f a) + nnnorm (f a) :
lintegral_le_lintegral _ _
(by { assume a, simp only [coe_add.symm, coe_le_coe], exact (hF a).2 n })
... = (∫⁻ a, nnnorm (f a)) + (∫⁻ a, nnnorm (f a)) :
lintegral_add (measurable.coe_nnnorm hfm) (measurable.coe_nnnorm hfm)
... < ⊤ : by simp only [add_lt_top, and_self]; exact hfi },
convert @tendsto_lintegral_of_dominated_convergence _ _ G (λ a, 0) g
hF_meas h_bound h_finite h_lim,
simp only [lintegral_zero]
end
end measure_theory
|
8ee6fac8f537ce73ac3f441ae223e55bddd35d02 | bb31430994044506fa42fd667e2d556327e18dfe | /src/number_theory/cyclotomic/basic.lean | 652614ab0c3fc422d59792e8d615ae8e5257747c | [
"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 | 31,523 | lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import ring_theory.polynomial.cyclotomic.basic
import number_theory.number_field.basic
import algebra.char_p.algebra
import field_theory.galois
/-!
# Cyclotomic extensions
Let `A` and `B` be commutative rings with `algebra A B`. For `S : set ℕ+`, we define a class
`is_cyclotomic_extension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th
primitive roots of unity, for all `n ∈ S`.
## Main definitions
* `is_cyclotomic_extension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive
roots of unity, for all `n ∈ S`.
* `cyclotomic_field`: given `n : ℕ+` and a field `K`, we define `cyclotomic n K` as the splitting
field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance
`is_cyclotomic_extension {n} K (cyclotomic_field n K)`.
* `cyclotomic_ring` : if `A` is a domain with fraction field `K` and `n : ℕ+`, we define
`cyclotomic_ring n A K` as the `A`-subalgebra of `cyclotomic_field n K` generated by the roots of
`X ^ n - 1`. If `n` is nonzero in `A`, it has the instance
`is_cyclotomic_extension {n} A (cyclotomic_ring n A K)`.
## Main results
* `is_cyclotomic_extension.trans` : if `is_cyclotomic_extension S A B` and
`is_cyclotomic_extension T B C`, then `is_cyclotomic_extension (S ∪ T) A C` if
`function.injective (algebra_map B C)`.
* `is_cyclotomic_extension.union_right` : given `is_cyclotomic_extension (S ∪ T) A B`, then
`is_cyclotomic_extension T (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) B`.
* `is_cyclotomic_extension.union_right` : given `is_cyclotomic_extension T A B` and `S ⊆ T`, then
`is_cyclotomic_extension S A (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 })`.
* `is_cyclotomic_extension.finite` : if `S` is finite and `is_cyclotomic_extension S A B`, then
`B` is a finite `A`-algebra.
* `is_cyclotomic_extension.number_field` : a finite cyclotomic extension of a number field is a
number field.
* `is_cyclotomic_extension.splitting_field_X_pow_sub_one` : if `is_cyclotomic_extension {n} K L`,
then `L` is the splitting field of `X ^ n - 1`.
* `is_cyclotomic_extension.splitting_field_cyclotomic` : if `is_cyclotomic_extension {n} K L`,
then `L` is the splitting field of `cyclotomic n K`.
## Implementation details
Our definition of `is_cyclotomic_extension` is very general, to allow rings of any characteristic
and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains.
All results are in the `is_cyclotomic_extension` namespace.
Note that some results, for example `is_cyclotomic_extension.trans`,
`is_cyclotomic_extension.finite`, `is_cyclotomic_extension.number_field`,
`is_cyclotomic_extension.finite_dimensional`, `is_cyclotomic_extension.is_galois` and
`cyclotomic_field.algebra_base` are lemmas, but they can be made local instances. Some of them are
included in the `cyclotomic` locale.
-/
open polynomial algebra finite_dimensional set
open_locale big_operators
universes u v w z
variables (n : ℕ+) (S T : set ℕ+) (A : Type u) (B : Type v) (K : Type w) (L : Type z)
variables [comm_ring A] [comm_ring B] [algebra A B]
variables [field K] [field L] [algebra K L]
noncomputable theory
/-- Given an `A`-algebra `B` and `S : set ℕ+`, we define `is_cyclotomic_extension S A B` requiring
that there is a `n`-th primitive root of unity in `B` for all `n ∈ S` and that `B` is generated
over `A` by the roots of `X ^ n - 1`. -/
@[mk_iff] class is_cyclotomic_extension : Prop :=
(exists_prim_root {n : ℕ+} (ha : n ∈ S) : ∃ r : B, is_primitive_root r n)
(adjoin_roots : ∀ (x : B), x ∈ adjoin A { b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1 })
namespace is_cyclotomic_extension
section basic
/-- A reformulation of `is_cyclotomic_extension` that uses `⊤`. -/
lemma iff_adjoin_eq_top : is_cyclotomic_extension S A B ↔
(∀ (n : ℕ+), n ∈ S → ∃ r : B, is_primitive_root r n) ∧
(adjoin A { b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1 } = ⊤) :=
⟨λ h, ⟨λ _, h.exists_prim_root, algebra.eq_top_iff.2 h.adjoin_roots⟩,
λ h, ⟨h.1, algebra.eq_top_iff.1 h.2⟩⟩
/-- A reformulation of `is_cyclotomic_extension` in the case `S` is a singleton. -/
lemma iff_singleton : is_cyclotomic_extension {n} A B ↔
(∃ r : B, is_primitive_root r n) ∧
(∀ x, x ∈ adjoin A { b : B | b ^ (n : ℕ) = 1 }) :=
by simp [is_cyclotomic_extension_iff]
/-- If `is_cyclotomic_extension ∅ A B`, then the image of `A` in `B` equals `B`. -/
lemma empty [h : is_cyclotomic_extension ∅ A B] : (⊥ : subalgebra A B) = ⊤ :=
by simpa [algebra.eq_top_iff, is_cyclotomic_extension_iff] using h
/-- If `is_cyclotomic_extension {1} A B`, then the image of `A` in `B` equals `B`. -/
lemma singleton_one [h : is_cyclotomic_extension {1} A B] : (⊥ : subalgebra A B) = ⊤ :=
algebra.eq_top_iff.2 (λ x, by simpa [adjoin_singleton_one]
using ((is_cyclotomic_extension_iff _ _ _).1 h).2 x)
variables {A B}
/-- If `(⊥ : subalgebra A B) = ⊤`, then `is_cyclotomic_extension ∅ A B`. -/
lemma singleton_zero_of_bot_eq_top (h : (⊥ : subalgebra A B) = ⊤) :
is_cyclotomic_extension ∅ A B :=
begin
refine (iff_adjoin_eq_top _ _ _).2 ⟨λ s hs, by simpa using hs, _root_.eq_top_iff.2 (λ x hx, _)⟩,
rw [← h] at hx,
simpa using hx,
end
variables (A B)
/-- Transitivity of cyclotomic extensions. -/
lemma trans (C : Type w) [comm_ring C] [algebra A C] [algebra B C]
[is_scalar_tower A B C] [hS : is_cyclotomic_extension S A B]
[hT : is_cyclotomic_extension T B C] (h : function.injective (algebra_map B C)) :
is_cyclotomic_extension (S ∪ T) A C :=
begin
refine ⟨λ n hn, _, λ x, _⟩,
{ cases hn,
{ obtain ⟨b, hb⟩ := ((is_cyclotomic_extension_iff _ _ _).1 hS).1 hn,
refine ⟨algebra_map B C b, _⟩,
exact hb.map_of_injective h },
{ exact ((is_cyclotomic_extension_iff _ _ _).1 hT).1 hn } },
{ refine adjoin_induction (((is_cyclotomic_extension_iff _ _ _).1 hT).2 x) (λ c ⟨n, hn⟩,
subset_adjoin ⟨n, or.inr hn.1, hn.2⟩) (λ b, _) (λ x y hx hy, subalgebra.add_mem _ hx hy)
(λ x y hx hy, subalgebra.mul_mem _ hx hy),
{ let f := is_scalar_tower.to_alg_hom A B C,
have hb : f b ∈ (adjoin A { b : B | ∃ (a : ℕ+), a ∈ S ∧ b ^ (a : ℕ) = 1 }).map f :=
⟨b, ((is_cyclotomic_extension_iff _ _ _).1 hS).2 b, rfl⟩,
rw [is_scalar_tower.to_alg_hom_apply, ← adjoin_image] at hb,
refine adjoin_mono (λ y hy, _) hb,
obtain ⟨b₁, ⟨⟨n, hn⟩, h₁⟩⟩ := hy,
exact ⟨n, ⟨mem_union_left T hn.1, by rw [← h₁, ← alg_hom.map_pow, hn.2, alg_hom.map_one]⟩⟩ } }
end
@[nontriviality] lemma subsingleton_iff [subsingleton B] :
is_cyclotomic_extension S A B ↔ S = {} ∨ S = {1} :=
begin
split,
{ rintro ⟨hprim, -⟩,
rw ←subset_singleton_iff_eq,
intros t ht,
obtain ⟨ζ, hζ⟩ := hprim ht,
rw [mem_singleton_iff, ←pnat.coe_eq_one_iff],
exact_mod_cast hζ.unique (is_primitive_root.of_subsingleton ζ) },
{ rintro (rfl|rfl),
{ refine ⟨λ _ h, h.elim, λ x, by convert (mem_top : x ∈ ⊤)⟩ },
{ rw iff_singleton,
refine ⟨⟨0, is_primitive_root.of_subsingleton 0⟩, λ x, by convert (mem_top : x ∈ ⊤)⟩ } }
end
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `S ∪ T`, then `B`
is a cyclotomic extension of `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 } ` given by
roots of unity of order in `T`. -/
lemma union_right [h : is_cyclotomic_extension (S ∪ T) A B] :
is_cyclotomic_extension T (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) B :=
begin
have : { b : B | ∃ (n : ℕ+), n ∈ S ∪ T ∧ b ^ (n : ℕ) = 1 } =
{ b : B | ∃ (n : ℕ+), n ∈ S ∧ b ^ (n : ℕ) = 1 } ∪
{ b : B | ∃ (n : ℕ+), n ∈ T ∧ b ^ (n : ℕ) = 1 },
{ refine le_antisymm (λ x hx, _) (λ x hx, _),
{ rcases hx with ⟨n, hn₁ | hn₂, hnpow⟩,
{ left, exact ⟨n, hn₁, hnpow⟩ },
{ right, exact ⟨n, hn₂, hnpow⟩ } },
{ rcases hx with ⟨n, hn⟩ | ⟨n, hn⟩,
{ exact ⟨n, or.inl hn.1, hn.2⟩ },
{ exact ⟨n, or.inr hn.1, hn.2⟩ } } },
refine ⟨λ n hn, ((is_cyclotomic_extension_iff _ _ _).1 h).1 (mem_union_right S hn), λ b, _⟩,
replace h := ((is_cyclotomic_extension_iff _ _ _).1 h).2 b,
rwa [this, adjoin_union_eq_adjoin_adjoin, subalgebra.mem_restrict_scalars] at h
end
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `T` and `S ⊆ T`,
then `adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }` is a cyclotomic extension of `B`
given by roots of unity of order in `S`. -/
lemma union_left [h : is_cyclotomic_extension T A B] (hS : S ⊆ T) :
is_cyclotomic_extension S A (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) :=
begin
refine ⟨λ n hn, _, λ b, _⟩,
{ obtain ⟨b, hb⟩ := ((is_cyclotomic_extension_iff _ _ _).1 h).1 (hS hn),
refine ⟨⟨b, subset_adjoin ⟨n, hn, hb.pow_eq_one⟩⟩, _⟩,
rwa [← is_primitive_root.coe_submonoid_class_iff, subtype.coe_mk] },
{ convert mem_top,
rw [← adjoin_adjoin_coe_preimage, preimage_set_of_eq],
norm_cast }
end
variables {n S}
/-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `is_cyclotomic_extension S A B` implies
`is_cyclotomic_extension (S ∪ {n}) A B`. -/
lemma of_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.nonempty) [H : is_cyclotomic_extension S A B] :
is_cyclotomic_extension (S ∪ {n}) A B :=
begin
refine (iff_adjoin_eq_top _ _ _).2 ⟨λ s hs, _, _⟩,
{ rw [mem_union, mem_singleton_iff] at hs,
obtain hs|rfl := hs,
{ exact H.exists_prim_root hs },
{ obtain ⟨m, hm⟩ := hS,
obtain ⟨x, rfl⟩ := h m hm,
obtain ⟨ζ, hζ⟩ := H.exists_prim_root hm,
refine ⟨ζ ^ (x : ℕ), _⟩,
convert hζ.pow_of_dvd x.ne_zero (dvd_mul_left (x : ℕ) s),
simp only [pnat.mul_coe, nat.mul_div_left, pnat.pos] } },
{ refine _root_.eq_top_iff.2 _,
rw [← ((iff_adjoin_eq_top S A B).1 H).2],
refine adjoin_mono (λ x hx, _),
simp only [union_singleton, mem_insert_iff, mem_set_of_eq] at ⊢ hx,
obtain ⟨m, hm⟩ := hx,
exact ⟨m, ⟨or.inr hm.1, hm.2⟩⟩ }
end
/-- If `∀ s ∈ S, n ∣ s` and `S` is not empty, then `is_cyclotomic_extension S A B` if and only if
`is_cyclotomic_extension (S ∪ {n}) A B`. -/
lemma iff_union_of_dvd (h : ∀ s ∈ S, n ∣ s) (hS : S.nonempty) :
is_cyclotomic_extension S A B ↔ is_cyclotomic_extension (S ∪ {n}) A B :=
begin
refine ⟨λ H, by exactI of_union_of_dvd A B h hS, λ H, (iff_adjoin_eq_top _ _ _).2 ⟨λ s hs, _, _⟩⟩,
{ exact H.exists_prim_root (subset_union_left _ _ hs) },
{ rw [_root_.eq_top_iff, ← ((iff_adjoin_eq_top _ A B).1 H).2],
refine adjoin_mono (λ x hx, _),
simp only [union_singleton, mem_insert_iff, mem_set_of_eq] at ⊢ hx,
obtain ⟨m, rfl|hm, hxpow⟩ := hx,
{ obtain ⟨y, hy⟩ := hS,
refine ⟨y, ⟨hy, _⟩⟩,
obtain ⟨z, rfl⟩ := h y hy,
simp only [pnat.mul_coe, pow_mul, hxpow, one_pow] },
{ exact ⟨m, ⟨hm, hxpow⟩⟩ } }
end
variables (n S)
/-- `is_cyclotomic_extension S A B` is equivalent to `is_cyclotomic_extension (S ∪ {1}) A B`. -/
lemma iff_union_singleton_one :
is_cyclotomic_extension S A B ↔ is_cyclotomic_extension (S ∪ {1}) A B :=
begin
obtain hS|rfl := S.eq_empty_or_nonempty.symm,
{ exact iff_union_of_dvd _ _ (λ s hs, one_dvd _) hS },
rw [empty_union],
refine ⟨λ H, _, λ H, _⟩,
{ refine (iff_adjoin_eq_top _ _ _).2 ⟨λ s hs, ⟨1, by simp [mem_singleton_iff.1 hs]⟩, _⟩,
simp [adjoin_singleton_one, @empty _ _ _ _ _ H] },
{ refine (iff_adjoin_eq_top _ _ _).2 ⟨λ s hs, (not_mem_empty s hs).elim, _⟩,
simp [@singleton_one A B _ _ _ H] }
end
variables {A B}
/-- If `(⊥ : subalgebra A B) = ⊤`, then `is_cyclotomic_extension {1} A B`. -/
lemma singleton_one_of_bot_eq_top (h : (⊥ : subalgebra A B) = ⊤) :
is_cyclotomic_extension {1} A B :=
begin
convert (iff_union_singleton_one _ _ _).1 (singleton_zero_of_bot_eq_top h),
simp
end
/-- If `function.surjective (algebra_map A B)`, then `is_cyclotomic_extension {1} A B`. -/
lemma singleton_one_of_algebra_map_bijective (h : function.surjective (algebra_map A B)) :
is_cyclotomic_extension {1} A B :=
singleton_one_of_bot_eq_top (surjective_algebra_map_iff.1 h).symm
variables (A B)
/-- Given `(f : B ≃ₐ[A] C)`, if `is_cyclotomic_extension S A B` then
`is_cyclotomic_extension S A C`. -/
@[protected] lemma equiv {C : Type*} [comm_ring C] [algebra A C] [h : is_cyclotomic_extension S A B]
(f : B ≃ₐ[A] C) : is_cyclotomic_extension S A C :=
begin
letI : algebra B C := f.to_alg_hom.to_ring_hom.to_algebra,
haveI : is_cyclotomic_extension {1} B C := singleton_one_of_algebra_map_bijective f.surjective,
haveI : is_scalar_tower A B C := is_scalar_tower.of_ring_hom f.to_alg_hom,
exact (iff_union_singleton_one _ _ _).2 (trans S {1} A B C f.injective)
end
@[protected]
lemma ne_zero [h : is_cyclotomic_extension {n} A B] [is_domain B] : ne_zero ((n : ℕ) : B) :=
begin
obtain ⟨⟨r, hr⟩, -⟩ := (iff_singleton n A B).1 h,
exact hr.ne_zero'
end
@[protected]
lemma ne_zero' [is_cyclotomic_extension {n} A B] [is_domain B] : ne_zero ((n : ℕ) : A) :=
begin
apply ne_zero.nat_of_ne_zero (algebra_map A B),
exact ne_zero n A B,
end
end basic
section fintype
lemma finite_of_singleton [is_domain B] [h : is_cyclotomic_extension {n} A B] : module.finite A B :=
begin
classical,
rw [module.finite_def, ← top_to_submodule, ← ((iff_adjoin_eq_top _ _ _).1 h).2],
refine fg_adjoin_of_finite _ (λ b hb, _),
{ simp only [mem_singleton_iff, exists_eq_left],
have : {b : B | b ^ (n : ℕ) = 1} = (nth_roots n (1 : B)).to_finset :=
set.ext (λ x, ⟨λ h, by simpa using h, λ h, by simpa using h⟩),
rw [this],
exact (nth_roots ↑n 1).to_finset.finite_to_set },
{ simp only [mem_singleton_iff, exists_eq_left, mem_set_of_eq] at hb,
refine ⟨X ^ (n : ℕ) - 1, ⟨monic_X_pow_sub_C _ n.pos.ne.symm, by simp [hb]⟩⟩ }
end
/-- If `S` is finite and `is_cyclotomic_extension S A B`, then `B` is a finite `A`-algebra. -/
@[protected]
lemma finite [is_domain B] [h₁ : finite S] [h₂ : is_cyclotomic_extension S A B] :
module.finite A B :=
begin
casesI nonempty_fintype S with h,
unfreezingI {revert h₂ A B},
refine set.finite.induction_on (set.finite.intro h) (λ A B, _) (λ n S hn hS H A B, _),
{ introsI _ _ _ _ _,
refine module.finite_def.2 ⟨({1} : finset B), _⟩,
simp [← top_to_submodule, ← empty, to_submodule_bot] },
{ introsI _ _ _ _ h,
haveI : is_cyclotomic_extension S A (adjoin A { b : B | ∃ (n : ℕ+),
n ∈ S ∧ b ^ (n : ℕ) = 1 }) := union_left _ (insert n S) _ _ (subset_insert n S),
haveI := H A (adjoin A { b : B | ∃ (n : ℕ+), n ∈ S ∧ b ^ (n : ℕ) = 1 }),
haveI : module.finite (adjoin A { b : B | ∃ (n : ℕ+), n ∈ S ∧ b ^ (n : ℕ) = 1 }) B,
{ rw [← union_singleton] at h,
letI := @union_right S {n} A B _ _ _ h,
exact finite_of_singleton n _ _ },
exact module.finite.trans (adjoin A { b : B | ∃ (n : ℕ+), n ∈ S ∧ b ^ (n : ℕ) = 1 }) _ }
end
/-- A cyclotomic finite extension of a number field is a number field. -/
lemma number_field [h : number_field K] [_root_.finite S] [is_cyclotomic_extension S K L] :
number_field L :=
{ to_char_zero := char_zero_of_injective_algebra_map (algebra_map K L).injective,
to_finite_dimensional := @module.finite.trans _ K L _ _ _ _
(@algebra_rat L _ (char_zero_of_injective_algebra_map (algebra_map K L).injective)) _ _
h.to_finite_dimensional (finite S K L) }
localized "attribute [instance] is_cyclotomic_extension.number_field" in cyclotomic
/-- A finite cyclotomic extension of an integral noetherian domain is integral -/
lemma integral [is_domain B] [is_noetherian_ring A] [_root_.finite S]
[is_cyclotomic_extension S A B] : algebra.is_integral A B :=
is_integral_of_noetherian $ is_noetherian_of_fg_of_noetherian' $ (finite S A B).out
/-- If `S` is finite and `is_cyclotomic_extension S K A`, then `finite_dimensional K A`. -/
lemma finite_dimensional (C : Type z) [_root_.finite S] [comm_ring C] [algebra K C] [is_domain C]
[is_cyclotomic_extension S K C] : finite_dimensional K C :=
is_cyclotomic_extension.finite S K C
localized "attribute [instance] is_cyclotomic_extension.finite_dimensional" in cyclotomic
end fintype
section
variables {A B}
lemma adjoin_roots_cyclotomic_eq_adjoin_nth_roots [decidable_eq B] [is_domain B] {ζ : B}
{n : ℕ+} (hζ : is_primitive_root ζ n) :
adjoin A ↑((map (algebra_map A B) (cyclotomic n A)).roots.to_finset) =
adjoin A {b : B | ∃ (a : ℕ+), a ∈ ({n} : set ℕ+) ∧ b ^ (a : ℕ) = 1} :=
begin
simp only [mem_singleton_iff, exists_eq_left, map_cyclotomic],
refine le_antisymm (adjoin_mono (λ x hx, _)) (adjoin_le (λ x hx, _)),
{ simp only [multiset.mem_to_finset, finset.mem_coe,
map_cyclotomic, mem_roots (cyclotomic_ne_zero n B)] at hx,
simp only [mem_singleton_iff, exists_eq_left, mem_set_of_eq],
rw is_root_of_unity_iff n.pos,
exact ⟨n, nat.mem_divisors_self n n.ne_zero, hx⟩ },
{ simp only [mem_singleton_iff, exists_eq_left, mem_set_of_eq] at hx,
obtain ⟨i, hin, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos,
refine set_like.mem_coe.2 (subalgebra.pow_mem _ (subset_adjoin _) _),
rwa [finset.mem_coe, multiset.mem_to_finset, mem_roots $ cyclotomic_ne_zero n B],
exact hζ.is_root_cyclotomic n.pos }
end
lemma adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic {n : ℕ+} [decidable_eq B] [is_domain B]
{ζ : B} (hζ : is_primitive_root ζ n) :
adjoin A (((map (algebra_map A B) (cyclotomic n A)).roots.to_finset) : set B) = adjoin A ({ζ}) :=
begin
refine le_antisymm (adjoin_le (λ x hx, _)) (adjoin_mono (λ x hx, _)),
{ suffices hx : x ^ ↑n = 1,
obtain ⟨i, hin, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx n.pos,
exact set_like.mem_coe.2 (subalgebra.pow_mem _ (subset_adjoin $ mem_singleton ζ) _),
rw is_root_of_unity_iff n.pos,
refine ⟨n, nat.mem_divisors_self n n.ne_zero, _⟩,
rwa [finset.mem_coe, multiset.mem_to_finset,
map_cyclotomic, mem_roots $ cyclotomic_ne_zero n B] at hx },
{ simp only [mem_singleton_iff, exists_eq_left, mem_set_of_eq] at hx,
simpa only [hx, multiset.mem_to_finset, finset.mem_coe, map_cyclotomic,
mem_roots (cyclotomic_ne_zero n B)] using hζ.is_root_cyclotomic n.pos }
end
lemma adjoin_primitive_root_eq_top {n : ℕ+} [is_domain B] [h : is_cyclotomic_extension {n} A B]
{ζ : B} (hζ : is_primitive_root ζ n) : adjoin A ({ζ} : set B) = ⊤ :=
begin
classical,
rw ←adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic hζ,
rw adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ,
exact ((iff_adjoin_eq_top {n} A B).mp h).2,
end
variable (A)
lemma _root_.is_primitive_root.adjoin_is_cyclotomic_extension {ζ : B} {n : ℕ+}
(h : is_primitive_root ζ n) : is_cyclotomic_extension {n} A (adjoin A ({ζ} : set B)) :=
{ exists_prim_root := λ i hi,
begin
rw [set.mem_singleton_iff] at hi,
refine ⟨⟨ζ, subset_adjoin $ set.mem_singleton ζ⟩, _⟩,
rwa [← is_primitive_root.coe_submonoid_class_iff, subtype.coe_mk, hi],
end,
adjoin_roots := λ x,
begin
refine adjoin_induction' (λ b hb, _) (λ a, _) (λ b₁ b₂ hb₁ hb₂, _) (λ b₁ b₂ hb₁ hb₂, _) x,
{ rw [set.mem_singleton_iff] at hb,
refine subset_adjoin _,
simp only [mem_singleton_iff, exists_eq_left, mem_set_of_eq, hb],
rw [← subalgebra.coe_eq_one, subalgebra.coe_pow, set_like.coe_mk],
exact ((is_primitive_root.iff_def ζ n).1 h).1 },
{ exact subalgebra.algebra_map_mem _ _ },
{ exact subalgebra.add_mem _ hb₁ hb₂ },
{ exact subalgebra.mul_mem _ hb₁ hb₂ }
end }
end
section field
variables {n S}
/-- A cyclotomic extension splits `X ^ n - 1` if `n ∈ S`.-/
lemma splits_X_pow_sub_one [H : is_cyclotomic_extension S K L] (hS : n ∈ S) :
splits (algebra_map K L) (X ^ (n : ℕ) - 1) :=
begin
rw [← splits_id_iff_splits, polynomial.map_sub, polynomial.map_one,
polynomial.map_pow, polynomial.map_X],
obtain ⟨z, hz⟩ := ((is_cyclotomic_extension_iff _ _ _).1 H).1 hS,
exact X_pow_sub_one_splits hz,
end
/-- A cyclotomic extension splits `cyclotomic n K` if `n ∈ S` and `ne_zero (n : K)`.-/
lemma splits_cyclotomic [is_cyclotomic_extension S K L] (hS : n ∈ S) :
splits (algebra_map K L) (cyclotomic n K) :=
begin
refine splits_of_splits_of_dvd _ (X_pow_sub_C_ne_zero n.pos _)
(splits_X_pow_sub_one K L hS) _,
use (∏ (i : ℕ) in (n : ℕ).proper_divisors, polynomial.cyclotomic i K),
rw [(eq_cyclotomic_iff n.pos _).1 rfl, ring_hom.map_one],
end
variables (n S)
section singleton
variables [is_cyclotomic_extension {n} K L]
/-- If `is_cyclotomic_extension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. -/
lemma splitting_field_X_pow_sub_one : is_splitting_field K L (X ^ (n : ℕ) - 1) :=
{ splits := splits_X_pow_sub_one K L (mem_singleton n),
adjoin_roots :=
begin
rw [← ((iff_adjoin_eq_top {n} K L).1 infer_instance).2],
congr,
refine set.ext (λ x, _),
simp only [polynomial.map_pow, mem_singleton_iff, multiset.mem_to_finset, exists_eq_left,
mem_set_of_eq, polynomial.map_X, polynomial.map_one, finset.mem_coe, polynomial.map_sub],
rwa [← ring_hom.map_one C, mem_roots (@X_pow_sub_C_ne_zero L _ _ _ n.pos _), is_root.def,
eval_sub, eval_pow, eval_C, eval_X, sub_eq_zero]
end }
/-- Any two `n`-th cyclotomic extensions are isomorphic. -/
def alg_equiv (L' : Type*) [field L'] [algebra K L'] [is_cyclotomic_extension {n} K L'] :
L ≃ₐ[K] L' :=
let _ := splitting_field_X_pow_sub_one n K L in let _ := splitting_field_X_pow_sub_one n K L' in
by exactI (is_splitting_field.alg_equiv L (X ^ (n : ℕ) - 1)).trans
(is_splitting_field.alg_equiv L' (X ^ (n : ℕ) - 1)).symm
localized "attribute [instance] is_cyclotomic_extension.splitting_field_X_pow_sub_one" in cyclotomic
include n
lemma is_galois : is_galois K L :=
begin
letI := splitting_field_X_pow_sub_one n K L,
exact is_galois.of_separable_splitting_field (X_pow_sub_one_separable_iff.2 ((ne_zero' n K L).1))
end
localized "attribute [instance] is_cyclotomic_extension.is_galois" in cyclotomic
/-- If `is_cyclotomic_extension {n} K L`, then `L` is the splitting field of `cyclotomic n K`. -/
lemma splitting_field_cyclotomic : is_splitting_field K L (cyclotomic n K) :=
{ splits := splits_cyclotomic K L (mem_singleton n),
adjoin_roots :=
begin
rw [← ((iff_adjoin_eq_top {n} K L).1 infer_instance).2],
letI := classical.dec_eq L,
obtain ⟨ζ, hζ⟩ := @is_cyclotomic_extension.exists_prim_root {n} K L _ _ _ _ _ (mem_singleton n),
exact adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ
end }
localized "attribute [instance] is_cyclotomic_extension.splitting_field_cyclotomic" in cyclotomic
end singleton
end field
end is_cyclotomic_extension
section cyclotomic_field
/-- Given `n : ℕ+` and a field `K`, we define `cyclotomic_field n K` as the
splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has
the instance `is_cyclotomic_extension {n} K (cyclotomic_field n K)`. -/
@[derive [field, algebra K, inhabited]]
def cyclotomic_field : Type w := (cyclotomic n K).splitting_field
namespace cyclotomic_field
instance [char_zero K] : char_zero (cyclotomic_field n K) :=
char_zero_of_injective_algebra_map ((algebra_map K _).injective)
instance is_cyclotomic_extension [ne_zero ((n : ℕ) : K)] :
is_cyclotomic_extension {n} K (cyclotomic_field n K) :=
begin
haveI : ne_zero ((n : ℕ) : (cyclotomic_field n K)) :=
ne_zero.nat_of_injective (algebra_map K _).injective,
letI := classical.dec_eq (cyclotomic_field n K),
obtain ⟨ζ, hζ⟩ := exists_root_of_splits (algebra_map K (cyclotomic_field n K))
(splitting_field.splits _) (degree_cyclotomic_pos n K n.pos).ne',
rw [← eval_map, ← is_root.def, map_cyclotomic, is_root_cyclotomic_iff] at hζ,
refine ⟨forall_eq.2 ⟨ζ, hζ⟩, _⟩,
rw [←algebra.eq_top_iff, ←splitting_field.adjoin_roots, eq_comm],
exact is_cyclotomic_extension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ,
end
end cyclotomic_field
end cyclotomic_field
section is_domain
variables [is_domain A] [algebra A K] [is_fraction_ring A K]
section cyclotomic_ring
/-- If `K` is the fraction field of `A`, the `A`-algebra structure on `cyclotomic_field n K`.
This is not an instance since it causes diamonds when `A = ℤ`. -/
@[nolint unused_arguments]
def cyclotomic_field.algebra_base : algebra A (cyclotomic_field n K) :=
((algebra_map K (cyclotomic_field n K)).comp (algebra_map A K)).to_algebra
local attribute [instance] cyclotomic_field.algebra_base
instance cyclotomic_field.no_zero_smul_divisors : no_zero_smul_divisors A (cyclotomic_field n K) :=
no_zero_smul_divisors.of_algebra_map_injective $ function.injective.comp
(no_zero_smul_divisors.algebra_map_injective _ _) $ is_fraction_ring.injective A K
/-- If `A` is a domain with fraction field `K` and `n : ℕ+`, we define `cyclotomic_ring n A K` as
the `A`-subalgebra of `cyclotomic_field n K` generated by the roots of `X ^ n - 1`. If `n`
is nonzero in `A`, it has the instance `is_cyclotomic_extension {n} A (cyclotomic_ring n A K)`. -/
@[derive [comm_ring, is_domain, inhabited]]
def cyclotomic_ring : Type w := adjoin A { b : (cyclotomic_field n K) | b ^ (n : ℕ) = 1 }
namespace cyclotomic_ring
/-- The `A`-algebra structure on `cyclotomic_ring n A K`.
This is not an instance since it causes diamonds when `A = ℤ`. -/
def algebra_base : algebra A (cyclotomic_ring n A K) := (adjoin A _).algebra
local attribute [instance] cyclotomic_ring.algebra_base
instance : no_zero_smul_divisors A (cyclotomic_ring n A K) := (adjoin A _).no_zero_smul_divisors_bot
lemma algebra_base_injective : function.injective $ algebra_map A (cyclotomic_ring n A K) :=
no_zero_smul_divisors.algebra_map_injective _ _
instance : algebra (cyclotomic_ring n A K) (cyclotomic_field n K) :=
(adjoin A _).to_algebra
lemma adjoin_algebra_injective :
function.injective $ algebra_map (cyclotomic_ring n A K) (cyclotomic_field n K) :=
subtype.val_injective
instance : no_zero_smul_divisors (cyclotomic_ring n A K) (cyclotomic_field n K) :=
no_zero_smul_divisors.of_algebra_map_injective (adjoin_algebra_injective n A K)
instance : is_scalar_tower A (cyclotomic_ring n A K) (cyclotomic_field n K) :=
is_scalar_tower.subalgebra' _ _ _ _
instance is_cyclotomic_extension [ne_zero ((n : ℕ) : A)] :
is_cyclotomic_extension {n} A (cyclotomic_ring n A K) :=
{ exists_prim_root := λ a han,
begin
rw mem_singleton_iff at han,
subst a,
haveI := ne_zero.of_no_zero_smul_divisors A K n,
haveI := ne_zero.of_no_zero_smul_divisors A (cyclotomic_field n K) n,
obtain ⟨μ, hμ⟩ :=
(cyclotomic_field.is_cyclotomic_extension n K).exists_prim_root (mem_singleton n),
refine ⟨⟨μ, subset_adjoin _⟩, _⟩,
{ apply (is_root_of_unity_iff n.pos (cyclotomic_field n K)).mpr,
refine ⟨n, nat.mem_divisors_self _ n.ne_zero, _⟩,
rwa [← is_root_cyclotomic_iff] at hμ },
{ rwa [← is_primitive_root.coe_submonoid_class_iff, subtype.coe_mk] }
end,
adjoin_roots := λ x,
begin
refine adjoin_induction' (λ y hy, _) (λ a, _) (λ y z hy hz, _) (λ y z hy hz, _) x,
{ refine subset_adjoin _,
simp only [mem_singleton_iff, exists_eq_left, mem_set_of_eq],
rwa [← subalgebra.coe_eq_one, subalgebra.coe_pow, subtype.coe_mk] },
{ exact subalgebra.algebra_map_mem _ a },
{ exact subalgebra.add_mem _ hy hz },
{ exact subalgebra.mul_mem _ hy hz },
end }
instance [ne_zero ((n : ℕ) : A)] :
is_fraction_ring (cyclotomic_ring n A K) (cyclotomic_field n K) :=
{ map_units := λ ⟨x, hx⟩, begin
rw is_unit_iff_ne_zero,
apply map_ne_zero_of_mem_non_zero_divisors,
apply adjoin_algebra_injective,
exact hx
end,
surj := λ x,
begin
letI : ne_zero ((n : ℕ) : K) := ne_zero.nat_of_injective (is_fraction_ring.injective A K),
refine algebra.adjoin_induction (((is_cyclotomic_extension.iff_singleton n K _).1
(cyclotomic_field.is_cyclotomic_extension n K)).2 x) (λ y hy, _) (λ k, _) _ _,
{ exact ⟨⟨⟨y, subset_adjoin hy⟩, 1⟩, by simpa⟩ },
{ have : is_localization (non_zero_divisors A) K := infer_instance,
replace := this.surj,
obtain ⟨⟨z, w⟩, hw⟩ := this k,
refine ⟨⟨algebra_map A _ z, algebra_map A _ w, map_mem_non_zero_divisors _
(algebra_base_injective n A K) w.2⟩, _⟩,
letI : is_scalar_tower A K (cyclotomic_field n K) :=
is_scalar_tower.of_algebra_map_eq (congr_fun rfl),
rw [set_like.coe_mk, ← is_scalar_tower.algebra_map_apply,
← is_scalar_tower.algebra_map_apply, @is_scalar_tower.algebra_map_apply A K _ _ _ _ _
(_root_.cyclotomic_field.algebra n K) _ _ w, ← ring_hom.map_mul, hw,
← is_scalar_tower.algebra_map_apply] },
{ rintro y z ⟨a, ha⟩ ⟨b, hb⟩,
refine ⟨⟨a.1 * b.2 + b.1 * a.2, a.2 * b.2, mul_mem_non_zero_divisors.2 ⟨a.2.2, b.2.2⟩⟩, _⟩,
rw [set_like.coe_mk, ring_hom.map_mul, add_mul, ← mul_assoc, ha,
mul_comm ((algebra_map _ _) ↑a.2), ← mul_assoc, hb],
simp only [map_add, map_mul] },
{ rintro y z ⟨a, ha⟩ ⟨b, hb⟩,
refine ⟨⟨a.1 * b.1, a.2 * b.2, mul_mem_non_zero_divisors.2 ⟨a.2.2, b.2.2⟩⟩, _⟩,
rw [set_like.coe_mk, ring_hom.map_mul, mul_comm ((algebra_map _ _) ↑a.2), mul_assoc,
← mul_assoc z, hb, ← mul_comm ((algebra_map _ _) ↑a.2), ← mul_assoc, ha],
simp only [map_mul] }
end,
eq_iff_exists := λ x y, ⟨λ h, ⟨1, by rw adjoin_algebra_injective n A K h⟩,
λ ⟨c, hc⟩, by rw mul_right_cancel₀ (non_zero_divisors.ne_zero c.prop) hc⟩ }
lemma eq_adjoin_primitive_root {μ : (cyclotomic_field n K)} (h : is_primitive_root μ n) :
cyclotomic_ring n A K = adjoin A ({μ} : set ((cyclotomic_field n K))) :=
begin
letI := classical.prop_decidable,
rw [←is_cyclotomic_extension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic h,
is_cyclotomic_extension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots h],
simp [cyclotomic_ring]
end
end cyclotomic_ring
end cyclotomic_ring
end is_domain
section is_alg_closed
variables [is_alg_closed K]
/-- Algebraically closed fields are `S`-cyclotomic extensions over themselves if
`ne_zero ((a : ℕ) : K))` for all `a ∈ S`. -/
lemma is_alg_closed.is_cyclotomic_extension (h : ∀ a ∈ S, ne_zero ((a : ℕ) : K)) :
is_cyclotomic_extension S K K :=
begin
refine ⟨λ a ha, _, algebra.eq_top_iff.mp $ subsingleton.elim _ _ ⟩,
obtain ⟨r, hr⟩ := is_alg_closed.exists_aeval_eq_zero K _ (degree_cyclotomic_pos a K a.pos).ne',
refine ⟨r, _⟩,
haveI := h a ha,
rwa [coe_aeval_eq_eval, ← is_root.def, is_root_cyclotomic_iff] at hr,
end
instance is_alg_closed_of_char_zero.is_cyclotomic_extension [char_zero K] :
∀ S, is_cyclotomic_extension S K K :=
λ S, is_alg_closed.is_cyclotomic_extension S K (λ a ha, infer_instance)
end is_alg_closed
|
b0f55d0a2534e793585e262d608a922f0cd0bf16 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/tactic/simp_rw.lean | cb9325926f71b38e89f057442a37bf11ef1138d7 | [] | 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,912 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
The `simp_rw` tactic, a mix of `simp` and `rewrite`.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.core
import Mathlib.PostPort
namespace Mathlib
/-!
# The `simp_rw` tactic
This module defines a tactic `simp_rw` which functions as a mix of `simp` and
`rw`. Like `rw`, it applies each rewrite rule in the given order, but like
`simp` it repeatedly applies these rules and also under binders like `∀ x, ...`,
`∃ x, ...` and `λ x, ...`.
## Implementation notes
The tactic works by taking each rewrite rule in turn and applying `simp only` to
it. Arguments to `simp_rw` are of the format used by `rw` and are translated to
their equivalents for `simp`.
-/
namespace tactic.interactive
/--
`simp_rw` functions as a mix of `simp` and `rw`. Like `rw`, it applies each
rewrite rule in the given order, but like `simp` it repeatedly applies these
rules and also under binders like `∀ x, ...`, `∃ x, ...` and `λ x, ...`.
Usage:
- `simp_rw [lemma_1, ..., lemma_n]` will rewrite the goal by applying the
lemmas in that order. A lemma preceded by `←` is applied in the reverse direction.
- `simp_rw [lemma_1, ..., lemma_n] at h₁ ... hₙ` will rewrite the given hypotheses.
- `simp_rw [...] at ⊢ h₁ ... hₙ` rewrites the goal as well as the given hypotheses.
- `simp_rw [...] at *` rewrites in the whole context: all hypotheses and the goal.
Lemmas passed to `simp_rw` must be expressions that are valid arguments to `simp`.
For example, neither `simp` nor `rw` can solve the following, but `simp_rw` can:
```lean
example {α β : Type} {f : α → β} {t : set β} : (∀ s, f '' s ⊆ t) = ∀ s : set α, ∀ x ∈ s, x ∈ f ⁻¹' t :=
by simp_rw [set.image_subset_iff, set.subset_def]
```
-/
|
d18246e3277bbbfc4b2b455afe06a3fd060963ec | c777c32c8e484e195053731103c5e52af26a25d1 | /src/data/polynomial/laurent.lean | bcdfada8689be5fe32b97500803ee293db33e896 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 20,023 | lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import data.polynomial.algebra_map
import ring_theory.localization.basic
/-! # Laurent polynomials
We introduce Laurent polynomials over a semiring `R`. Mathematically, they are expressions of the
form
$$
\sum_{i \in \mathbb{Z}} a_i T ^ i
$$
where the sum extends over a finite subset of `ℤ`. Thus, negative exponents are allowed. The
coefficients come from the semiring `R` and the variable `T` commutes with everything.
Since we are going to convert back and forth between polynomials and Laurent polynomials, we
decided to maintain some distinction by using the symbol `T`, rather than `X`, as the variable for
Laurent polynomials
## Notation
The symbol `R[T;T⁻¹]` stands for `laurent_polynomial R`. We also define
* `C : R →+* R[T;T⁻¹]` the inclusion of constant polynomials, analogous to the one for `R[X]`;
* `T : ℤ → R[T;T⁻¹]` the sequence of powers of the variable `T`.
## Implementation notes
We define Laurent polynomials as `add_monoid_algebra R ℤ`.
Thus, they are essentially `finsupp`s `ℤ →₀ R`.
This choice differs from the current irreducible design of `polynomial`, that instead shields away
the implementation via `finsupp`s. It is closer to the original definition of polynomials.
As a consequence, `laurent_polynomial` plays well with polynomials, but there is a little roughness
in establishing the API, since the `finsupp` implementation of `R[X]` is well-shielded.
Unlike the case of polynomials, I felt that the exponent notation was not too easy to use, as only
natural exponents would be allowed. Moreover, in the end, it seems likely that we should aim to
perform computations on exponents in `ℤ` anyway and separating this via the symbol `T` seems
convenient.
I made a *heavy* use of `simp` lemmas, aiming to bring Laurent polynomials to the form `C a * T n`.
Any comments or suggestions for improvements is greatly appreciated!
## Future work
Lots is missing!
-- (Riccardo) add inclusion into Laurent series.
-- (Riccardo) giving a morphism (as `R`-alg, so in the commutative case)
from `R[T,T⁻¹]` to `S` is the same as choosing a unit of `S`.
-- A "better" definition of `trunc` would be as an `R`-linear map. This works:
-- ```
-- def trunc : R[T;T⁻¹] →[R] R[X] :=
-- begin
-- refine (_ : add_monoid_algebra R ℕ →[R] R[X]).comp _,
-- { exact ⟨(to_finsupp_iso R).symm, by simp⟩ },
-- { refine ⟨λ r, comap_domain _ r (set.inj_on_of_injective (λ a b ab, int.of_nat.inj ab) _), _⟩,
-- exact λ r f, comap_domain_smul _ _ _ }
-- end
-- ```
-- but it would make sense to bundle the maps better, for a smoother user experience.
-- I (DT) did not have the strength to embark on this (possibly short!) journey, after getting to
-- this stage of the Laurent process!
-- This would likely involve adding a `comap_domain` analogue of
-- `add_monoid_algebra.map_domain_alg_hom` and an `R`-linear version of
-- `polynomial.to_finsupp_iso`.
-- Add `degree, int_degree, int_trailing_degree, leading_coeff, trailing_coeff,...`.
-/
open_locale polynomial big_operators
open polynomial add_monoid_algebra finsupp
noncomputable theory
variables {R : Type*}
/-- The semiring of Laurent polynomials with coefficients in the semiring `R`.
We denote it by `R[T;T⁻¹]`.
The ring homomorphism `C : R →+* R[T;T⁻¹]` includes `R` as the constant polynomials. -/
abbreviation laurent_polynomial (R : Type*) [semiring R] := add_monoid_algebra R ℤ
local notation R`[T;T⁻¹]`:9000 := laurent_polynomial R
/-- The ring homomorphism, taking a polynomial with coefficients in `R` to a Laurent polynomial
with coefficients in `R`. -/
def polynomial.to_laurent [semiring R] : R[X] →+* R[T;T⁻¹] :=
(map_domain_ring_hom R int.of_nat_hom).comp (to_finsupp_iso R)
/-- This is not a simp lemma, as it is usually preferable to use the lemmas about `C` and `X`
instead. -/
lemma polynomial.to_laurent_apply [semiring R] (p : R[X]) :
p.to_laurent = p.to_finsupp.map_domain coe := rfl
/-- The `R`-algebra map, taking a polynomial with coefficients in `R` to a Laurent polynomial
with coefficients in `R`. -/
def polynomial.to_laurent_alg [comm_semiring R] :
R[X] →ₐ[R] R[T;T⁻¹] :=
begin
refine alg_hom.comp _ (to_finsupp_iso_alg R).to_alg_hom,
exact (map_domain_alg_hom R R int.of_nat_hom),
end
@[simp]
lemma polynomial.to_laurent_alg_apply [comm_semiring R] (f : R[X]) :
f.to_laurent_alg = f.to_laurent := rfl
namespace laurent_polynomial
section semiring
variables [semiring R]
lemma single_zero_one_eq_one : (single 0 1 : R[T;T⁻¹]) = (1 : R[T;T⁻¹]) := rfl
/-! ### The functions `C` and `T`. -/
/-- The ring homomorphism `C`, including `R` into the ring of Laurent polynomials over `R` as
the constant Laurent polynomials. -/
def C : R →+* R[T;T⁻¹] :=
single_zero_ring_hom
lemma algebra_map_apply {R A : Type*} [comm_semiring R] [semiring A] [algebra R A] (r : R) :
algebra_map R (laurent_polynomial A) r = C (algebra_map R A r) :=
rfl
/--
When we have `[comm_semiring R]`, the function `C` is the same as `algebra_map R R[T;T⁻¹]`.
(But note that `C` is defined when `R` is not necessarily commutative, in which case
`algebra_map` is not available.)
-/
lemma C_eq_algebra_map {R : Type*} [comm_semiring R] (r : R) :
C r = algebra_map R R[T;T⁻¹] r :=
rfl
lemma single_eq_C (r : R) : single 0 r = C r := rfl
/-- The function `n ↦ T ^ n`, implemented as a sequence `ℤ → R[T;T⁻¹]`.
Using directly `T ^ n` does not work, since we want the exponents to be of Type `ℤ` and there
is no `ℤ`-power defined on `R[T;T⁻¹]`. Using that `T` is a unit introduces extra coercions.
For these reasons, the definition of `T` is as a sequence. -/
def T (n : ℤ) : R[T;T⁻¹] := single n 1
@[simp]
lemma T_zero : (T 0 : R[T;T⁻¹]) = 1 := rfl
lemma T_add (m n : ℤ) : (T (m + n) : R[T;T⁻¹]) = T m * T n :=
by { convert single_mul_single.symm, simp [T] }
lemma T_sub (m n : ℤ) : (T (m - n) : R[T;T⁻¹]) = T m * T (-n) :=
by rw [← T_add, sub_eq_add_neg]
@[simp]
lemma T_pow (m : ℤ) (n : ℕ) : (T m ^ n : R[T;T⁻¹]) = T (n * m) :=
by rw [T, T, single_pow n, one_pow, nsmul_eq_mul]
/-- The `simp` version of `mul_assoc`, in the presence of `T`'s. -/
@[simp]
lemma mul_T_assoc (f : R[T;T⁻¹]) (m n : ℤ) : f * T m * T n = f * T (m + n) :=
by simp [← T_add, mul_assoc]
@[simp]
lemma single_eq_C_mul_T (r : R) (n : ℤ) :
(single n r : R[T;T⁻¹]) = (C r * T n : R[T;T⁻¹]) :=
by convert single_mul_single.symm; simp
-- This lemma locks in the right changes and is what Lean proved directly.
-- The actual `simp`-normal form of a Laurent monomial is `C a * T n`, whenever it can be reached.
@[simp]
lemma _root_.polynomial.to_laurent_C_mul_T (n : ℕ) (r : R) :
((polynomial.monomial n r).to_laurent : R[T;T⁻¹]) = C r * T n :=
show map_domain coe (monomial n r).to_finsupp = (C r * T n : R[T;T⁻¹]),
by rw [to_finsupp_monomial, map_domain_single, single_eq_C_mul_T]
@[simp]
lemma _root_.polynomial.to_laurent_C (r : R) : (polynomial.C r).to_laurent = C r :=
begin
convert polynomial.to_laurent_C_mul_T 0 r,
simp only [int.coe_nat_zero, T_zero, mul_one],
end
@[simp]
lemma _root_.polynomial.to_laurent_X : (polynomial.X.to_laurent : R[T;T⁻¹]) = T 1 :=
begin
have : (polynomial.X : R[X]) = monomial 1 1,
{ simp [← C_mul_X_pow_eq_monomial] },
simp [this, polynomial.to_laurent_C_mul_T],
end
@[simp] lemma _root_.polynomial.to_laurent_one : (polynomial.to_laurent : R[X] → R[T;T⁻¹]) 1 = 1 :=
map_one polynomial.to_laurent
@[simp]
lemma _root_.polynomial.to_laurent_C_mul_eq (r : R) (f : R[X]) :
(polynomial.C r * f).to_laurent = C r * f.to_laurent :=
by simp only [_root_.map_mul, polynomial.to_laurent_C]
@[simp]
lemma _root_.polynomial.to_laurent_X_pow (n : ℕ) : (X ^ n : R[X]).to_laurent = T n :=
by simp only [map_pow, polynomial.to_laurent_X, T_pow, mul_one]
@[simp]
lemma _root_.polynomial.to_laurent_C_mul_X_pow (n : ℕ) (r : R) :
(polynomial.C r * X ^ n).to_laurent = C r * T n :=
by simp only [_root_.map_mul, polynomial.to_laurent_C, polynomial.to_laurent_X_pow]
instance invertible_T (n : ℤ) : invertible (T n : R[T;T⁻¹]) :=
{ inv_of := T (- n),
inv_of_mul_self := by rw [← T_add, add_left_neg, T_zero],
mul_inv_of_self := by rw [← T_add, add_right_neg, T_zero] }
@[simp]
lemma inv_of_T (n : ℤ) : ⅟ (T n : R[T;T⁻¹]) = T (- n) := rfl
lemma is_unit_T (n : ℤ) : is_unit (T n : R[T;T⁻¹]) :=
is_unit_of_invertible _
@[elab_as_eliminator] protected lemma induction_on {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹])
(h_C : ∀ a, M (C a))
(h_add : ∀ {p q}, M p → M q → M (p + q))
(h_C_mul_T : ∀ (n : ℕ) (a : R), M (C a * T n) → M (C a * T (n + 1)))
(h_C_mul_T_Z : ∀ (n : ℕ) (a : R), M (C a * T (- n)) → M (C a * T (- n - 1))) :
M p :=
begin
have A : ∀ {n : ℤ} {a : R}, M (C a * T n),
{ assume n a,
apply n.induction_on,
{ simpa only [T_zero, mul_one] using h_C a },
{ exact λ m, h_C_mul_T m a },
{ exact λ m, h_C_mul_T_Z m a } },
have B : ∀ (s : finset ℤ), M (s.sum (λ (n : ℤ), C (p.to_fun n) * T n)),
{ apply finset.induction,
{ convert h_C 0, simp only [finset.sum_empty, _root_.map_zero] },
{ assume n s ns ih, rw finset.sum_insert ns, exact h_add A ih } },
convert B p.support,
ext a,
simp_rw [← single_eq_C_mul_T, finset.sum_apply', single_apply, finset.sum_ite_eq'],
split_ifs with h h,
{ refl },
{ exact finsupp.not_mem_support_iff.mp h }
end
/-- To prove something about Laurent polynomials, it suffices to show that
* the condition is closed under taking sums, and
* it holds for monomials.
-/
@[elab_as_eliminator] protected lemma induction_on' {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹])
(h_add : ∀p q, M p → M q → M (p + q))
(h_C_mul_T : ∀(n : ℤ) (a : R), M (C a * T n)) :
M p :=
begin
refine p.induction_on (λ a, _) h_add _ _;
try { exact λ n f _, h_C_mul_T _ f },
convert h_C_mul_T 0 a,
exact (mul_one _).symm,
end
lemma commute_T (n : ℤ) (f : R[T;T⁻¹]) : commute (T n) f :=
f.induction_on' (λ p q Tp Tq, commute.add_right Tp Tq) $ λ m a,
show T n * _ = _, by
{ rw [T, T, ← single_eq_C, single_mul_single, single_mul_single, single_mul_single],
simp [add_comm] }
@[simp]
lemma T_mul (n : ℤ) (f : R[T;T⁻¹]) : T n * f = f * T n :=
(commute_T n f).eq
/-- `trunc : R[T;T⁻¹] →+ R[X]` maps a Laurent polynomial `f` to the polynomial whose terms of
nonnegative degree coincide with the ones of `f`. The terms of negative degree of `f` "vanish".
`trunc` is a left-inverse to `polynomial.to_laurent`. -/
def trunc : R[T;T⁻¹] →+ R[X] :=
((to_finsupp_iso R).symm.to_add_monoid_hom).comp $
comap_domain.add_monoid_hom $ λ a b, int.of_nat.inj
@[simp]
lemma trunc_C_mul_T (n : ℤ) (r : R) : trunc (C r * T n) = ite (0 ≤ n) (monomial n.to_nat r) 0 :=
begin
apply (to_finsupp_iso R).injective,
rw [← single_eq_C_mul_T, trunc, add_monoid_hom.coe_comp, function.comp_app,
comap_domain.add_monoid_hom_apply, to_finsupp_iso_apply],
by_cases n0 : 0 ≤ n,
{ lift n to ℕ using n0,
erw [comap_domain_single, to_finsupp_iso_symm_apply],
simp only [int.coe_nat_nonneg, int.to_nat_coe_nat, if_true, to_finsupp_iso_apply,
to_finsupp_monomial] },
{ lift (- n) to ℕ using (neg_pos.mpr (not_le.mp n0)).le with m,
rw [to_finsupp_iso_apply, to_finsupp_inj, if_neg n0],
erw to_finsupp_iso_symm_apply,
ext a,
have := ((not_le.mp n0).trans_le (int.coe_zero_le a)).ne',
simp only [coeff, comap_domain_apply, int.of_nat_eq_coe, coeff_zero, single_apply_eq_zero, this,
is_empty.forall_iff] }
end
@[simp] lemma left_inverse_trunc_to_laurent :
function.left_inverse (trunc : R[T;T⁻¹] → R[X]) polynomial.to_laurent :=
begin
refine λ f, f.induction_on' _ _,
{ exact λ f g hf hg, by simp only [hf, hg, _root_.map_add] },
{ exact λ n r, by simp only [polynomial.to_laurent_C_mul_T, trunc_C_mul_T, int.coe_nat_nonneg,
int.to_nat_coe_nat, if_true] }
end
@[simp] lemma _root_.polynomial.trunc_to_laurent (f : R[X]) : trunc f.to_laurent = f :=
left_inverse_trunc_to_laurent _
lemma _root_.polynomial.to_laurent_injective :
function.injective (polynomial.to_laurent : R[X] → R[T;T⁻¹]) :=
left_inverse_trunc_to_laurent.injective
@[simp] lemma _root_.polynomial.to_laurent_inj (f g : R[X]) :
f.to_laurent = g.to_laurent ↔ f = g :=
⟨λ h, polynomial.to_laurent_injective h, congr_arg _⟩
lemma _root_.polynomial.to_laurent_ne_zero {f : R[X]} :
f ≠ 0 ↔ f.to_laurent ≠ 0 :=
(map_ne_zero_iff _ (by exact polynomial.to_laurent_injective)).symm
lemma exists_T_pow (f : R[T;T⁻¹]) :
∃ (n : ℕ) (f' : R[X]), f'.to_laurent = f * T n :=
begin
apply f.induction_on' _ (λ n a, _); clear f,
{ rintros f g ⟨m, fn, hf⟩ ⟨n, gn, hg⟩,
refine ⟨m + n, fn * X ^ n + gn * X ^ m, _⟩,
simp only [hf, hg, add_mul, add_comm (n : ℤ), map_add, map_mul, polynomial.to_laurent_X_pow,
mul_T_assoc, int.coe_nat_add] },
{ cases n with n n,
{ exact ⟨0, polynomial.C a * X ^ n, by simp⟩ },
{ refine ⟨n + 1, polynomial.C a, _⟩,
simp only [int.neg_succ_of_nat_eq, polynomial.to_laurent_C, int.coe_nat_succ, mul_T_assoc,
add_left_neg, T_zero, mul_one] } }
end
/-- This is a version of `exists_T_pow` stated as an induction principle. -/
@[elab_as_eliminator] lemma induction_on_mul_T {Q : R[T;T⁻¹] → Prop} (f : R[T;T⁻¹])
(Qf : ∀ {f : R[X]} {n : ℕ}, Q (f.to_laurent * T (- n))) :
Q f :=
begin
rcases f.exists_T_pow with ⟨n, f', hf⟩,
rw [← mul_one f, ← T_zero, ← nat.cast_zero, ← nat.sub_self n, nat.cast_sub rfl.le, T_sub,
← mul_assoc, ← hf],
exact Qf,
end
/-- Suppose that `Q` is a statement about Laurent polynomials such that
* `Q` is true on *ordinary* polynomials;
* `Q (f * T)` implies `Q f`;
it follow that `Q` is true on all Laurent polynomials. -/
lemma reduce_to_polynomial_of_mul_T (f : R[T;T⁻¹]) {Q : R[T;T⁻¹] → Prop}
(Qf : ∀ (f : R[X]), Q f.to_laurent)
(QT : ∀ f, Q (f * T 1) → Q f) :
Q f :=
begin
induction f using laurent_polynomial.induction_on_mul_T with f n,
induction n with n hn,
{ simpa only [int.coe_nat_zero, neg_zero, T_zero, mul_one] using Qf _ },
{ convert QT _ _,
simpa using hn }
end
section support
lemma support_C_mul_T (a : R) (n : ℤ) : (C a * T n).support ⊆ {n} :=
by simpa only [← single_eq_C_mul_T] using support_single_subset
lemma support_C_mul_T_of_ne_zero {a : R} (a0 : a ≠ 0) (n : ℤ) : (C a * T n).support = {n} :=
begin
rw ← single_eq_C_mul_T,
exact support_single_ne_zero _ a0,
end
/-- The support of a polynomial `f` is a finset in `ℕ`. The lemma `to_laurent_support f`
shows that the support of `f.to_laurent` is the same finset, but viewed in `ℤ` under the natural
inclusion `ℕ ↪ ℤ`. -/
lemma to_laurent_support (f : R[X]) :
f.to_laurent.support = f.support.map nat.cast_embedding :=
begin
generalize' hd : f.support = s,
revert f,
refine finset.induction_on s _ _; clear s,
{ simp only [polynomial.support_eq_empty, map_zero, finsupp.support_zero, eq_self_iff_true,
implies_true_iff, finset.map_empty] {contextual := tt} },
{ intros a s as hf f fs,
have : (erase a f).to_laurent.support = s.map nat.cast_embedding := hf (f.erase a) (by simp only
[fs, finset.erase_eq_of_not_mem as, polynomial.support_erase, finset.erase_insert_eq_erase]),
rw [← monomial_add_erase f a, finset.map_insert, ← this, map_add,
polynomial.to_laurent_C_mul_T, support_add_eq, finset.insert_eq],
{ congr,
exact support_C_mul_T_of_ne_zero (polynomial.mem_support_iff.mp (by simp [fs])) _ },
{ rw this,
exact disjoint.mono_left (support_C_mul_T _ _) (by simpa) } }
end
end support
section degrees
/-- The degree of a Laurent polynomial takes values in `with_bot ℤ`.
If `f : R[T;T⁻¹]` is a Laurent polynomial, then `f.degree` is the maximum of its support of `f`,
or `⊥`, if `f = 0`. -/
def degree (f : R[T;T⁻¹]) : with_bot ℤ := f.support.max
@[simp] lemma degree_zero : degree (0 : R[T;T⁻¹]) = ⊥ := rfl
@[simp] lemma degree_eq_bot_iff {f : R[T;T⁻¹]} : f.degree = ⊥ ↔ f = 0 :=
begin
refine ⟨λ h, _, λ h, by rw [h, degree_zero]⟩,
rw [degree, finset.max_eq_sup_with_bot] at h,
ext n,
refine not_not.mp (λ f0, _),
simp_rw [finset.sup_eq_bot_iff, finsupp.mem_support_iff, ne.def, with_bot.coe_ne_bot] at h,
exact h n f0,
end
section exact_degrees
open_locale classical
@[simp] lemma degree_C_mul_T (n : ℤ) (a : R) (a0 : a ≠ 0) : (C a * T n).degree = n :=
begin
rw degree,
convert finset.max_singleton,
refine support_eq_singleton.mpr _,
simp only [← single_eq_C_mul_T, single_eq_same, a0, ne.def, not_false_iff, eq_self_iff_true,
and_self],
end
lemma degree_C_mul_T_ite (n : ℤ) (a : R) : (C a * T n).degree = ite (a = 0) ⊥ n :=
by split_ifs with h h;
simp only [h, map_zero, zero_mul, degree_zero, degree_C_mul_T, ne.def, not_false_iff]
@[simp] lemma degree_T [nontrivial R] (n : ℤ) : (T n : R[T;T⁻¹]).degree = n :=
begin
rw [← one_mul (T n), ← map_one C],
exact degree_C_mul_T n 1 (one_ne_zero : (1 : R) ≠ 0),
end
lemma degree_C {a : R} (a0 : a ≠ 0) : (C a).degree = 0 :=
begin
rw [← mul_one (C a), ← T_zero],
exact degree_C_mul_T 0 a a0
end
lemma degree_C_ite (a : R) : (C a).degree = ite (a = 0) ⊥ 0 :=
by split_ifs with h h;
simp only [h, map_zero, degree_zero, degree_C, ne.def, not_false_iff]
end exact_degrees
section degree_bounds
lemma degree_C_mul_T_le (n : ℤ) (a : R) : (C a * T n).degree ≤ n :=
begin
by_cases a0 : a = 0,
{ simp only [a0, map_zero, zero_mul, degree_zero, bot_le] },
{ exact (degree_C_mul_T n a a0).le }
end
lemma degree_T_le (n : ℤ) : (T n : R[T;T⁻¹]).degree ≤ n :=
(le_of_eq (by rw [map_one, one_mul])).trans (degree_C_mul_T_le n (1 : R))
lemma degree_C_le (a : R) : (C a).degree ≤ 0 :=
(le_of_eq (by rw [T_zero, mul_one])).trans (degree_C_mul_T_le 0 a)
end degree_bounds
end degrees
instance : module R[X] R[T;T⁻¹] :=
module.comp_hom _ polynomial.to_laurent
instance (R : Type*) [semiring R] : is_scalar_tower R[X] R[X] R[T;T⁻¹] :=
{ smul_assoc := λ x y z, by simp only [has_smul.smul, has_smul.comp.smul, map_mul, mul_assoc] }
end semiring
section comm_semiring
variable [comm_semiring R]
instance algebra_polynomial (R : Type*) [comm_semiring R] : algebra R[X] R[T;T⁻¹] :=
{ commutes' := λ f l, by simp [mul_comm],
smul_def' := λ f l, rfl,
.. polynomial.to_laurent }
lemma algebra_map_X_pow (n : ℕ) : algebra_map R[X] R[T;T⁻¹] (X ^ n) = T n :=
polynomial.to_laurent_X_pow n
@[simp]
lemma algebra_map_eq_to_laurent (f : R[X]) : algebra_map R[X] R[T;T⁻¹] f = f.to_laurent :=
rfl
lemma is_localization : is_localization (submonoid.closure ({X} : set R[X])) R[T;T⁻¹] :=
{ map_units := λ t, begin
cases t with t ht,
rcases submonoid.mem_closure_singleton.mp ht with ⟨n, rfl⟩,
simp only [is_unit_T n, set_like.coe_mk, algebra_map_eq_to_laurent, polynomial.to_laurent_X_pow]
end,
surj := λ f, begin
induction f using laurent_polynomial.induction_on_mul_T with f n,
have := (submonoid.closure ({X} : set R[X])).pow_mem submonoid.mem_closure_singleton_self n,
refine ⟨(f, ⟨_, this⟩), _⟩,
simp only [set_like.coe_mk, algebra_map_eq_to_laurent, polynomial.to_laurent_X_pow, mul_T_assoc,
add_left_neg, T_zero, mul_one],
end,
eq_iff_exists := λ f g, begin
rw [algebra_map_eq_to_laurent, algebra_map_eq_to_laurent, polynomial.to_laurent_inj],
refine ⟨_, _⟩,
{ rintro rfl,
exact ⟨1, rfl⟩ },
{ rintro ⟨⟨h, hX⟩, h⟩,
rcases submonoid.mem_closure_singleton.mp hX with ⟨n, rfl⟩,
exact mul_X_pow_injective n h }
end }
end comm_semiring
end laurent_polynomial
|
bf3e4addf9bede13b09a88860930a64a22e6b98f | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/apply_tac1.lean | 5dd4d6a963280ee08563614248636adc33ca63d5 | [
"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 | 558 | lean | import tactic.
import Int.
variable f : Int -> Int -> Bool
variable P : Int -> Int -> Bool
axiom Ax1 (x y : Int) (H : P x y) : (f x y)
theorem T1 (a : Int) : (P a a) → (f a a).
apply Ax1.
exact.
done.
variable b : Int
axiom Ax2 (x : Int) : (f x b)
(*
simple_tac = Repeat(OrElse(assumption_tac(), apply_tac("Ax2"), apply_tac("Ax1")))
*)
theorem T2 (a : Int) : (P a a) → (f a a).
simple_tac.
done.
theorem T3 (a : Int) : (P a a) → (f a a).
Repeat (OrElse exact (apply Ax2) (apply Ax1)).
done.
print environment 2. |
eec3ef731847137947b154f572ae51b50ddeb141 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/data/finset/prod.lean | 885a9af98772b701e68fc665998cf4d6412fa7fa | [
"Apache-2.0"
] | permissive | ramonfmir/mathlib | c5dc8b33155473fab97c38bd3aa6723dc289beaa | 14c52e990c17f5a00c0cc9e09847af16fabbed25 | refs/heads/master | 1,661,979,343,526 | 1,660,830,384,000 | 1,660,830,384,000 | 182,072,989 | 0 | 0 | null | 1,555,585,876,000 | 1,555,585,876,000 | null | UTF-8 | Lean | false | false | 10,235 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Oliver Nash
-/
import data.finset.card
/-!
# Finsets in product types
This file defines finset constructions on the product type `α × β`. Beware not to confuse with the
`finset.prod` operation which computes the multiplicative product.
## Main declarations
* `finset.product`: Turns `s : finset α`, `t : finset β` into their product in `finset (α × β)`.
* `finset.diag`: For `s : finset α`, `s.diag` is the `finset (α × α)` of pairs `(a, a)` with
`a ∈ s`.
* `finset.off_diag`: For `s : finset α`, `s.off_diag` is the `finset (α × α)` of pairs `(a, b)` with
`a, b ∈ s` and `a ≠ b`.
-/
open multiset
variables {α β γ : Type*}
namespace finset
/-! ### prod -/
section prod
variables {s s' : finset α} {t t' : finset β} {a : α} {b : β}
/-- `product s t` is the set of pairs `(a, b)` such that `a ∈ s` and `b ∈ t`. -/
protected def product (s : finset α) (t : finset β) : finset (α × β) := ⟨_, s.nodup.product t.nodup⟩
/- This notation binds more strongly than (pre)images, unions and intersections. -/
infixr ` ×ˢ `:82 := finset.product
@[simp] lemma product_val : (s ×ˢ t).1 = s.1 ×ˢ t.1 := rfl
@[simp] lemma mem_product {p : α × β} : p ∈ s ×ˢ t ↔ p.1 ∈ s ∧ p.2 ∈ t := mem_product
lemma mk_mem_product (ha : a ∈ s) (hb : b ∈ t) : (a, b) ∈ s ×ˢ t := mem_product.2 ⟨ha, hb⟩
@[simp, norm_cast] lemma coe_product (s : finset α) (t : finset β) :
(↑(s ×ˢ t) : set (α × β)) = s ×ˢ t :=
set.ext $ λ x, finset.mem_product
lemma subset_product [decidable_eq α] [decidable_eq β] {s : finset (α × β)} :
s ⊆ s.image prod.fst ×ˢ s.image prod.snd :=
λ p hp, mem_product.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩
lemma product_subset_product (hs : s ⊆ s') (ht : t ⊆ t') : s ×ˢ t ⊆ s' ×ˢ t' :=
λ ⟨x,y⟩ h, mem_product.2 ⟨hs (mem_product.1 h).1, ht (mem_product.1 h).2⟩
lemma product_subset_product_left (hs : s ⊆ s') : s ×ˢ t ⊆ s' ×ˢ t :=
product_subset_product hs (subset.refl _)
lemma product_subset_product_right (ht : t ⊆ t') : s ×ˢ t ⊆ s ×ˢ t' :=
product_subset_product (subset.refl _) ht
lemma product_eq_bUnion [decidable_eq α] [decidable_eq β] (s : finset α) (t : finset β) :
s ×ˢ t = s.bUnion (λa, t.image $ λb, (a, b)) :=
ext $ λ ⟨x, y⟩, by simp only [mem_product, mem_bUnion, mem_image, exists_prop, prod.mk.inj_iff,
and.left_comm, exists_and_distrib_left, exists_eq_right, exists_eq_left]
lemma product_eq_bUnion_right [decidable_eq α] [decidable_eq β] (s : finset α) (t : finset β) :
s ×ˢ t = t.bUnion (λ b, s.image $ λ a, (a, b)) :=
ext $ λ ⟨x, y⟩, by simp only [mem_product, mem_bUnion, mem_image, exists_prop, prod.mk.inj_iff,
and.left_comm, exists_and_distrib_left, exists_eq_right, exists_eq_left]
/-- See also `finset.sup_product_left`. -/
@[simp] lemma product_bUnion [decidable_eq γ] (s : finset α) (t : finset β) (f : α × β → finset γ) :
(s ×ˢ t).bUnion f = s.bUnion (λ a, t.bUnion (λ b, f (a, b))) :=
by { classical, simp_rw [product_eq_bUnion, bUnion_bUnion, image_bUnion] }
@[simp] lemma card_product (s : finset α) (t : finset β) : card (s ×ˢ t) = card s * card t :=
multiset.card_product _ _
lemma filter_product (p : α → Prop) (q : β → Prop) [decidable_pred p] [decidable_pred q] :
(s ×ˢ t).filter (λ (x : α × β), p x.1 ∧ q x.2) = s.filter p ×ˢ t.filter q :=
by { ext ⟨a, b⟩, simp only [mem_filter, mem_product],
exact and_and_and_comm (a ∈ s) (b ∈ t) (p a) (q b) }
lemma filter_product_card (s : finset α) (t : finset β)
(p : α → Prop) (q : β → Prop) [decidable_pred p] [decidable_pred q] :
((s ×ˢ t).filter (λ (x : α × β), p x.1 ↔ q x.2)).card =
(s.filter p).card * (t.filter q).card + (s.filter (not ∘ p)).card * (t.filter (not ∘ q)).card :=
begin
classical,
rw [← card_product, ← card_product, ← filter_product, ← filter_product, ← card_union_eq],
{ apply congr_arg, ext ⟨a, b⟩, simp only [filter_union_right, mem_filter, mem_product],
split; intros h; use h.1,
simp only [function.comp_app, and_self, h.2, em (q b)],
cases h.2; { try { simp at h_1 }, simp [h_1] } },
{ rw disjoint_iff, change _ ∩ _ = ∅, ext ⟨a, b⟩, rw mem_inter,
simp only [and_imp, mem_filter, not_and, not_not, function.comp_app, iff_false, mem_product,
not_mem_empty], intros, assumption }
end
lemma empty_product (t : finset β) : (∅ : finset α) ×ˢ t = ∅ := rfl
lemma product_empty (s : finset α) : s ×ˢ (∅ : finset β) = ∅ :=
eq_empty_of_forall_not_mem (λ x h, (finset.mem_product.1 h).2)
lemma nonempty.product (hs : s.nonempty) (ht : t.nonempty) : (s ×ˢ t).nonempty :=
let ⟨x, hx⟩ := hs, ⟨y, hy⟩ := ht in ⟨(x, y), mem_product.2 ⟨hx, hy⟩⟩
lemma nonempty.fst (h : (s ×ˢ t).nonempty) : s.nonempty :=
let ⟨xy, hxy⟩ := h in ⟨xy.1, (mem_product.1 hxy).1⟩
lemma nonempty.snd (h : (s ×ˢ t).nonempty) : t.nonempty :=
let ⟨xy, hxy⟩ := h in ⟨xy.2, (mem_product.1 hxy).2⟩
@[simp] lemma nonempty_product : (s ×ˢ t).nonempty ↔ s.nonempty ∧ t.nonempty :=
⟨λ h, ⟨h.fst, h.snd⟩, λ h, h.1.product h.2⟩
@[simp] lemma product_eq_empty {s : finset α} {t : finset β} : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
by rw [←not_nonempty_iff_eq_empty, nonempty_product, not_and_distrib, not_nonempty_iff_eq_empty,
not_nonempty_iff_eq_empty]
@[simp] lemma singleton_product {a : α} :
({a} : finset α) ×ˢ t = t.map ⟨prod.mk a, prod.mk.inj_left _⟩ :=
by { ext ⟨x, y⟩, simp [and.left_comm, eq_comm] }
@[simp] lemma product_singleton {b : β} :
s ×ˢ {b} = s.map ⟨λ i, (i, b), prod.mk.inj_right _⟩ :=
by { ext ⟨x, y⟩, simp [and.left_comm, eq_comm] }
lemma singleton_product_singleton {a : α} {b : β} :
({a} : finset α) ×ˢ ({b} : finset β) = {(a, b)} :=
by simp only [product_singleton, function.embedding.coe_fn_mk, map_singleton]
@[simp] lemma union_product [decidable_eq α] [decidable_eq β] :
(s ∪ s') ×ˢ t = s ×ˢ t ∪ s' ×ˢ t :=
by { ext ⟨x, y⟩, simp only [or_and_distrib_right, mem_union, mem_product] }
@[simp] lemma product_union [decidable_eq α] [decidable_eq β] :
s ×ˢ (t ∪ t') = s ×ˢ t ∪ s ×ˢ t' :=
by { ext ⟨x, y⟩, simp only [and_or_distrib_left, mem_union, mem_product] }
end prod
section diag
variables (s t : finset α) [decidable_eq α]
/-- Given a finite set `s`, the diagonal, `s.diag` is the set of pairs of the form `(a, a)` for
`a ∈ s`. -/
def diag := (s ×ˢ s).filter (λ a : α × α, a.fst = a.snd)
/-- Given a finite set `s`, the off-diagonal, `s.off_diag` is the set of pairs `(a, b)` with `a ≠ b`
for `a, b ∈ s`. -/
def off_diag := (s ×ˢ s).filter (λ (a : α × α), a.fst ≠ a.snd)
@[simp] lemma mem_diag (x : α × α) : x ∈ s.diag ↔ x.1 ∈ s ∧ x.1 = x.2 :=
by { simp only [diag, mem_filter, mem_product], split; intros h;
simp only [h, and_true, eq_self_iff_true, and_self], rw ←h.2, exact h.1 }
@[simp] lemma mem_off_diag (x : α × α) : x ∈ s.off_diag ↔ x.1 ∈ s ∧ x.2 ∈ s ∧ x.1 ≠ x.2 :=
by { simp only [off_diag, mem_filter, mem_product], split; intros h;
simp only [h, ne.def, not_false_iff, and_self] }
@[simp] lemma diag_card : (diag s).card = s.card :=
begin
suffices : diag s = s.image (λ a, (a, a)),
{ rw this, apply card_image_of_inj_on, exact λ x1 h1 x2 h2 h3, (prod.mk.inj h3).1 },
ext ⟨a₁, a₂⟩, rw mem_diag, split; intros h; rw finset.mem_image at *,
{ use [a₁, h.1, prod.mk.inj_iff.mpr ⟨rfl, h.2⟩] },
{ rcases h with ⟨a, h1, h2⟩, have h := prod.mk.inj h2, rw [←h.1, ←h.2], use h1 },
end
@[simp] lemma off_diag_card : (off_diag s).card = s.card * s.card - s.card :=
begin
suffices : (diag s).card + (off_diag s).card = s.card * s.card,
{ nth_rewrite 2 ← s.diag_card, simp only [diag_card] at *, rw tsub_eq_of_eq_add_rev, rw this },
rw ← card_product,
apply filter_card_add_filter_neg_card_eq_card,
end
@[simp] lemma diag_empty : (∅ : finset α).diag = ∅ := rfl
@[simp] lemma off_diag_empty : (∅ : finset α).off_diag = ∅ := rfl
@[simp] lemma diag_union_off_diag : s.diag ∪ s.off_diag = s ×ˢ s :=
filter_union_filter_neg_eq _ _
@[simp] lemma disjoint_diag_off_diag : disjoint s.diag s.off_diag := disjoint_filter_filter_neg _ _
lemma product_sdiff_diag : s ×ˢ s \ s.diag = s.off_diag :=
by rw [←diag_union_off_diag, union_comm, union_sdiff_self,
sdiff_eq_self_of_disjoint (disjoint_diag_off_diag _).symm]
lemma product_sdiff_off_diag : s ×ˢ s \ s.off_diag = s.diag :=
by rw [←diag_union_off_diag, union_sdiff_self, sdiff_eq_self_of_disjoint (disjoint_diag_off_diag _)]
lemma diag_union : (s ∪ t).diag = s.diag ∪ t.diag :=
by { ext ⟨i, j⟩, simp only [mem_diag, mem_union, or_and_distrib_right] }
variables {s t}
lemma off_diag_union (h : disjoint s t) :
(s ∪ t).off_diag = s.off_diag ∪ t.off_diag ∪ s ×ˢ t ∪ t ×ˢ s :=
begin
rw [off_diag, union_product, product_union, product_union, union_comm _ (t ×ˢ t),
union_assoc, union_left_comm (s ×ˢ t), ←union_assoc, filter_union, filter_union, ←off_diag,
←off_diag, filter_true_of_mem, ←union_assoc],
simp only [mem_union, mem_product, ne.def, prod.forall],
rintro i j (⟨hi, hj⟩ | ⟨hi, hj⟩),
{ exact h.forall_ne_finset hi hj },
{ exact h.symm.forall_ne_finset hi hj },
end
variables (a : α)
@[simp] lemma off_diag_singleton : ({a} : finset α).off_diag = ∅ :=
by simp [←finset.card_eq_zero]
lemma diag_singleton : ({a} : finset α).diag = {(a, a)} :=
by rw [←product_sdiff_off_diag, off_diag_singleton, sdiff_empty, singleton_product_singleton]
lemma diag_insert : (insert a s).diag = insert (a, a) s.diag :=
by rw [insert_eq, insert_eq, diag_union, diag_singleton]
lemma off_diag_insert (has : a ∉ s) :
(insert a s).off_diag = s.off_diag ∪ {a} ×ˢ s ∪ s ×ˢ {a} :=
by rw [insert_eq, union_comm, off_diag_union (disjoint_singleton_right.2 has), off_diag_singleton,
union_empty, union_right_comm]
end diag
end finset
|
a1d190d38ea34cb07495f58b7e8fada6e2379009 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/category_theory/sites/sieves.lean | 39430023d16d300f4f782c6c187370199487eb26 | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 23,489 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, E. W. Ayers
-/
import category_theory.over
import category_theory.limits.shapes.finite_limits
import category_theory.yoneda
import order.complete_lattice
import data.set.lattice
/-!
# Theory of sieves
- For an object `X` of a category `C`, a `sieve X` is a set of morphisms to `X`
which is closed under left-composition.
- The complete lattice structure on sieves is given, as well as the Galois insertion
given by downward-closing.
- A `sieve X` (functorially) induces a presheaf on `C` together with a monomorphism to
the yoneda embedding of `X`.
## Tags
sieve, pullback
-/
universes v₁ v₂ v₃ u₁ u₂ u₃
namespace category_theory
open category limits
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D] (F : C ⥤ D)
variables {X Y Z : C} (f : Y ⟶ X)
/-- A set of arrows all with codomain `X`. -/
@[derive complete_lattice]
def presieve (X : C) := Π ⦃Y⦄, set (Y ⟶ X)
namespace presieve
instance : inhabited (presieve X) := ⟨⊤⟩
/--
Given a set of arrows `S` all with codomain `X`, and a set of arrows with codomain `Y` for each
`f : Y ⟶ X` in `S`, produce a set of arrows with codomain `X`:
`{ g ≫ f | (f : Y ⟶ X) ∈ S, (g : Z ⟶ Y) ∈ R f }`.
-/
def bind (S : presieve X) (R : Π ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → presieve Y) :
presieve X :=
λ Z h, ∃ (Y : C) (g : Z ⟶ Y) (f : Y ⟶ X) (H : S f), R H g ∧ g ≫ f = h
@[simp]
lemma bind_comp {S : presieve X}
{R : Π ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → presieve Y} {g : Z ⟶ Y} (h₁ : S f) (h₂ : R h₁ g) :
bind S R (g ≫ f) :=
⟨_, _, _, h₁, h₂, rfl⟩
/-- The singleton presieve. -/
-- Note we can't make this into `has_singleton` because of the out-param.
inductive singleton : presieve X
| mk : singleton f
@[simp] lemma singleton_eq_iff_domain (f g : Y ⟶ X) : singleton f g ↔ f = g :=
begin
split,
{ rintro ⟨a, rfl⟩,
refl },
{ rintro rfl,
apply singleton.mk, }
end
lemma singleton_self : singleton f f := singleton.mk
/--
Pullback a set of arrows with given codomain along a fixed map, by taking the pullback in the
category.
This is not the same as the arrow set of `sieve.pullback`, but there is a relation between them
in `pullback_arrows_comm`.
-/
inductive pullback_arrows [has_pullbacks C] (R : presieve X) :
presieve Y
| mk (Z : C) (h : Z ⟶ X) : R h → pullback_arrows (pullback.snd : pullback h f ⟶ Y)
lemma pullback_singleton [has_pullbacks C] (g : Z ⟶ X) :
pullback_arrows f (singleton g) = singleton (pullback.snd : pullback g f ⟶ _) :=
begin
ext W h,
split,
{ rintro ⟨W, _, _, _⟩,
exact singleton.mk },
{ rintro ⟨_⟩,
exact pullback_arrows.mk Z g singleton.mk }
end
/-- Construct the presieve given by the family of arrows indexed by `ι`. -/
inductive of_arrows {ι : Type*} (Y : ι → C) (f : Π i, Y i ⟶ X) : presieve X
| mk (i : ι) : of_arrows (f i)
lemma of_arrows_punit :
of_arrows _ (λ _ : punit, f) = singleton f :=
begin
ext Y g,
split,
{ rintro ⟨_⟩,
apply singleton.mk },
{ rintro ⟨_⟩,
exact of_arrows.mk punit.star },
end
lemma of_arrows_pullback [has_pullbacks C] {ι : Type*}
(Z : ι → C) (g : Π (i : ι), Z i ⟶ X) :
of_arrows (λ i, pullback (g i) f) (λ i, pullback.snd) =
pullback_arrows f (of_arrows Z g) :=
begin
ext T h,
split,
{ rintro ⟨hk⟩,
exact pullback_arrows.mk _ _ (of_arrows.mk hk) },
{ rintro ⟨W, k, hk₁⟩,
cases hk₁ with i hi,
apply of_arrows.mk },
end
lemma of_arrows_bind {ι : Type*} (Z : ι → C) (g : Π (i : ι), Z i ⟶ X)
(j : Π ⦃Y⦄ (f : Y ⟶ X), of_arrows Z g f → Type*)
(W : Π ⦃Y⦄ (f : Y ⟶ X) H, j f H → C)
(k : Π ⦃Y⦄ (f : Y ⟶ X) H i, W f H i ⟶ Y) :
(of_arrows Z g).bind (λ Y f H, of_arrows (W f H) (k f H)) =
of_arrows (λ (i : Σ i, j _ (of_arrows.mk i)), W (g i.1) _ i.2)
(λ ij, k (g ij.1) _ ij.2 ≫ g ij.1) :=
begin
ext Y f,
split,
{ rintro ⟨_, _, _, ⟨i⟩, ⟨i'⟩, rfl⟩,
exact of_arrows.mk (sigma.mk _ _) },
{ rintro ⟨i⟩,
exact bind_comp _ (of_arrows.mk _) (of_arrows.mk _) }
end
/-- Given a presieve on `F(X)`, we can define a presieve on `X` by taking the preimage via `F`. -/
def functor_pullback (R : presieve (F.obj X)) : presieve X := λ _ f, R (F.map f)
@[simp] lemma functor_pullback_mem (R : presieve (F.obj X)) {Y} (f : Y ⟶ X) :
R.functor_pullback F f ↔ R (F.map f) := iff.rfl
@[simp] lemma functor_pullback_id (R : presieve X) : R.functor_pullback (𝟭 _) = R := rfl
section functor_pushforward
variables {E : Type u₃} [category.{v₃} E] (G : D ⥤ E)
/--
Given a presieve on `X`, we can define a presieve on `F(X)` (which is actually a sieve)
by taking the sieve generated by the image via `F`.
-/
def functor_pushforward (S : presieve X) : presieve (F.obj X) :=
λ Y f, ∃ (Z : C) (g : Z ⟶ X) (h : Y ⟶ F.obj Z), S g ∧ f = h ≫ F.map g
lemma functor_pushforward_comp (R : presieve X) :
R.functor_pushforward (F ⋙ G) = (R.functor_pushforward F).functor_pushforward G :=
begin
ext x f,
split,
{ rintro ⟨X, f₁, g₁, h₁, rfl⟩, exact ⟨F.obj X, F.map f₁, g₁, ⟨X, f₁, 𝟙 _, h₁, by simp⟩, rfl⟩ },
{ rintro ⟨X, f₁, g₁, ⟨X', f₂, g₂, h₁, rfl⟩, rfl⟩, use ⟨X', f₂, g₁ ≫ G.map g₂, h₁, by simp⟩ }
end
lemma image_mem_functor_pushforward (R : presieve X) {f : Y ⟶ X} (h : R f) :
R.functor_pushforward F (F.map f) := ⟨Y, f, 𝟙 _, h, by simp⟩
end functor_pushforward
end presieve
/--
For an object `X` of a category `C`, a `sieve X` is a set of morphisms to `X` which is closed under
left-composition.
-/
structure sieve {C : Type u₁} [category.{v₁} C] (X : C) :=
(arrows : presieve X)
(downward_closed' : ∀ {Y Z f} (hf : arrows f) (g : Z ⟶ Y), arrows (g ≫ f))
namespace sieve
instance : has_coe_to_fun (sieve X) := ⟨_, sieve.arrows⟩
initialize_simps_projections sieve (arrows → apply)
variables {S R : sieve X}
@[simp, priority 100] lemma downward_closed (S : sieve X) {f : Y ⟶ X} (hf : S f)
(g : Z ⟶ Y) : S (g ≫ f) :=
S.downward_closed' hf g
lemma arrows_ext : Π {R S : sieve X}, R.arrows = S.arrows → R = S
| ⟨Ra, _⟩ ⟨Sa, _⟩ rfl := rfl
@[ext]
protected lemma ext {R S : sieve X}
(h : ∀ ⦃Y⦄ (f : Y ⟶ X), R f ↔ S f) :
R = S :=
arrows_ext $ funext $ λ x, funext $ λ f, propext $ h f
protected lemma ext_iff {R S : sieve X} :
R = S ↔ (∀ ⦃Y⦄ (f : Y ⟶ X), R f ↔ S f) :=
⟨λ h Y f, h ▸ iff.rfl, sieve.ext⟩
open lattice
/-- The supremum of a collection of sieves: the union of them all. -/
protected def Sup (𝒮 : set (sieve X)) : (sieve X) :=
{ arrows := λ Y, {f | ∃ S ∈ 𝒮, sieve.arrows S f},
downward_closed' := λ Y Z f, by { rintro ⟨S, hS, hf⟩ g, exact ⟨S, hS, S.downward_closed hf _⟩ } }
/-- The infimum of a collection of sieves: the intersection of them all. -/
protected def Inf (𝒮 : set (sieve X)) : (sieve X) :=
{ arrows := λ Y, {f | ∀ S ∈ 𝒮, sieve.arrows S f},
downward_closed' := λ Y Z f hf g S H, S.downward_closed (hf S H) g }
/-- The union of two sieves is a sieve. -/
protected def union (S R : sieve X) : sieve X :=
{ arrows := λ Y f, S f ∨ R f,
downward_closed' := by { rintros Y Z f (h | h) g; simp [h] } }
/-- The intersection of two sieves is a sieve. -/
protected def inter (S R : sieve X) : sieve X :=
{ arrows := λ Y f, S f ∧ R f,
downward_closed' := by { rintros Y Z f ⟨h₁, h₂⟩ g, simp [h₁, h₂] } }
/--
Sieves on an object `X` form a complete lattice.
We generate this directly rather than using the galois insertion for nicer definitional properties.
-/
instance : complete_lattice (sieve X) :=
{ le := λ S R, ∀ ⦃Y⦄ (f : Y ⟶ X), S f → R f,
le_refl := λ S f q, id,
le_trans := λ S₁ S₂ S₃ S₁₂ S₂₃ Y f h, S₂₃ _ (S₁₂ _ h),
le_antisymm := λ S R p q, sieve.ext (λ Y f, ⟨p _, q _⟩),
top := { arrows := λ _, set.univ, downward_closed' := λ Y Z f g h, ⟨⟩ },
bot := { arrows := λ _, ∅, downward_closed' := λ _ _ _ p _, false.elim p },
sup := sieve.union,
inf := sieve.inter,
Sup := sieve.Sup,
Inf := sieve.Inf,
le_Sup := λ 𝒮 S hS Y f hf, ⟨S, hS, hf⟩,
Sup_le := λ ℰ S hS Y f, by { rintro ⟨R, hR, hf⟩, apply hS R hR _ hf },
Inf_le := λ _ _ hS _ _ h, h _ hS,
le_Inf := λ _ _ hS _ _ hf _ hR, hS _ hR _ hf,
le_sup_left := λ _ _ _ _, or.inl,
le_sup_right := λ _ _ _ _, or.inr,
sup_le := λ _ _ _ a b _ _ hf, hf.elim (a _) (b _),
inf_le_left := λ _ _ _ _, and.left,
inf_le_right := λ _ _ _ _, and.right,
le_inf := λ _ _ _ p q _ _ z, ⟨p _ z, q _ z⟩,
le_top := λ _ _ _ _, trivial,
bot_le := λ _ _ _, false.elim }
/-- The maximal sieve always exists. -/
instance sieve_inhabited : inhabited (sieve X) := ⟨⊤⟩
@[simp]
lemma Inf_apply {Ss : set (sieve X)} {Y} (f : Y ⟶ X) :
Inf Ss f ↔ ∀ (S : sieve X) (H : S ∈ Ss), S f :=
iff.rfl
@[simp]
lemma Sup_apply {Ss : set (sieve X)} {Y} (f : Y ⟶ X) :
Sup Ss f ↔ ∃ (S : sieve X) (H : S ∈ Ss), S f :=
iff.rfl
@[simp]
lemma inter_apply {R S : sieve X} {Y} (f : Y ⟶ X) :
(R ⊓ S) f ↔ R f ∧ S f :=
iff.rfl
@[simp]
lemma union_apply {R S : sieve X} {Y} (f : Y ⟶ X) :
(R ⊔ S) f ↔ R f ∨ S f :=
iff.rfl
@[simp]
lemma top_apply (f : Y ⟶ X) : (⊤ : sieve X) f := trivial
/-- Generate the smallest sieve containing the given set of arrows. -/
@[simps]
def generate (R : presieve X) : sieve X :=
{ arrows := λ Z f, ∃ Y (h : Z ⟶ Y) (g : Y ⟶ X), R g ∧ h ≫ g = f,
downward_closed' :=
begin
rintro Y Z _ ⟨W, g, f, hf, rfl⟩ h,
exact ⟨_, h ≫ g, _, hf, by simp⟩,
end }
/--
Given a presieve on `X`, and a sieve on each domain of an arrow in the presieve, we can bind to
produce a sieve on `X`.
-/
@[simps]
def bind (S : presieve X) (R : Π ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → sieve Y) : sieve X :=
{ arrows := S.bind (λ Y f h, R h),
downward_closed' :=
begin
rintro Y Z f ⟨W, f, h, hh, hf, rfl⟩ g,
exact ⟨_, g ≫ f, _, hh, by simp [hf]⟩,
end }
open order lattice
lemma sets_iff_generate (R : presieve X) (S : sieve X) :
generate R ≤ S ↔ R ≤ S :=
⟨λ H Y g hg, H _ ⟨_, 𝟙 _, _, hg, category.id_comp _⟩,
λ ss Y f,
begin
rintro ⟨Z, f, g, hg, rfl⟩,
exact S.downward_closed (ss Z hg) f,
end⟩
/-- Show that there is a galois insertion (generate, set_over). -/
def gi_generate : galois_insertion (generate : presieve X → sieve X) arrows :=
{ gc := sets_iff_generate,
choice := λ 𝒢 _, generate 𝒢,
choice_eq := λ _ _, rfl,
le_l_u := λ S Y f hf, ⟨_, 𝟙 _, _, hf, category.id_comp _⟩ }
lemma le_generate (R : presieve X) : R ≤ generate R :=
gi_generate.gc.le_u_l R
@[simp] lemma generate_sieve (S : sieve X) : generate S = S :=
gi_generate.l_u_eq S
/-- If the identity arrow is in a sieve, the sieve is maximal. -/
lemma id_mem_iff_eq_top : S (𝟙 X) ↔ S = ⊤ :=
⟨λ h, top_unique $ λ Y f _, by simpa using downward_closed _ h f,
λ h, h.symm ▸ trivial⟩
/-- If an arrow set contains a split epi, it generates the maximal sieve. -/
lemma generate_of_contains_split_epi {R : presieve X} (f : Y ⟶ X) [split_epi f]
(hf : R f) : generate R = ⊤ :=
begin
rw ← id_mem_iff_eq_top,
exact ⟨_, section_ f, f, hf, by simp⟩,
end
@[simp]
lemma generate_of_singleton_split_epi (f : Y ⟶ X) [split_epi f] :
generate (presieve.singleton f) = ⊤ :=
generate_of_contains_split_epi f (presieve.singleton_self _)
@[simp]
lemma generate_top : generate (⊤ : presieve X) = ⊤ :=
generate_of_contains_split_epi (𝟙 _) ⟨⟩
/-- Given a morphism `h : Y ⟶ X`, send a sieve S on X to a sieve on Y
as the inverse image of S with `_ ≫ h`.
That is, `sieve.pullback S h := (≫ h) '⁻¹ S`. -/
@[simps]
def pullback (h : Y ⟶ X) (S : sieve X) : sieve Y :=
{ arrows := λ Y sl, S (sl ≫ h),
downward_closed' := λ Z W f g h, by simp [g] }
@[simp]
lemma pullback_id : S.pullback (𝟙 _) = S :=
by simp [sieve.ext_iff]
@[simp]
lemma pullback_top {f : Y ⟶ X} : (⊤ : sieve X).pullback f = ⊤ :=
top_unique (λ _ g, id)
lemma pullback_comp {f : Y ⟶ X} {g : Z ⟶ Y} (S : sieve X) :
S.pullback (g ≫ f) = (S.pullback f).pullback g :=
by simp [sieve.ext_iff]
@[simp]
lemma pullback_inter {f : Y ⟶ X} (S R : sieve X) :
(S ⊓ R).pullback f = S.pullback f ⊓ R.pullback f :=
by simp [sieve.ext_iff]
lemma pullback_eq_top_iff_mem (f : Y ⟶ X) : S f ↔ S.pullback f = ⊤ :=
by rw [← id_mem_iff_eq_top, pullback_apply, category.id_comp]
lemma pullback_eq_top_of_mem (S : sieve X) {f : Y ⟶ X} : S f → S.pullback f = ⊤ :=
(pullback_eq_top_iff_mem f).1
/--
Push a sieve `R` on `Y` forward along an arrow `f : Y ⟶ X`: `gf : Z ⟶ X` is in the sieve if `gf`
factors through some `g : Z ⟶ Y` which is in `R`.
-/
@[simps]
def pushforward (f : Y ⟶ X) (R : sieve Y) : sieve X :=
{ arrows := λ Z gf, ∃ g, g ≫ f = gf ∧ R g,
downward_closed' := λ Z₁ Z₂ g ⟨j, k, z⟩ h, ⟨h ≫ j, by simp [k], by simp [z]⟩ }
lemma pushforward_apply_comp {R : sieve Y} {Z : C} {g : Z ⟶ Y} (hg : R g) (f : Y ⟶ X) :
R.pushforward f (g ≫ f) :=
⟨g, rfl, hg⟩
lemma pushforward_comp {f : Y ⟶ X} {g : Z ⟶ Y} (R : sieve Z) :
R.pushforward (g ≫ f) = (R.pushforward g).pushforward f :=
sieve.ext (λ W h, ⟨λ ⟨f₁, hq, hf₁⟩, ⟨f₁ ≫ g, by simpa, f₁, rfl, hf₁⟩,
λ ⟨y, hy, z, hR, hz⟩, ⟨z, by rwa reassoc_of hR, hz⟩⟩)
lemma galois_connection (f : Y ⟶ X) : galois_connection (sieve.pushforward f) (sieve.pullback f) :=
λ S R, ⟨λ hR Z g hg, hR _ ⟨g, rfl, hg⟩, λ hS Z g ⟨h, hg, hh⟩, hg ▸ hS h hh⟩
lemma pullback_monotone (f : Y ⟶ X) : monotone (sieve.pullback f) :=
(galois_connection f).monotone_u
lemma pushforward_monotone (f : Y ⟶ X) : monotone (sieve.pushforward f) :=
(galois_connection f).monotone_l
lemma le_pushforward_pullback (f : Y ⟶ X) (R : sieve Y) :
R ≤ (R.pushforward f).pullback f :=
(galois_connection f).le_u_l _
lemma pullback_pushforward_le (f : Y ⟶ X) (R : sieve X) :
(R.pullback f).pushforward f ≤ R :=
(galois_connection f).l_u_le _
lemma pushforward_union {f : Y ⟶ X} (S R : sieve Y) :
(S ⊔ R).pushforward f = S.pushforward f ⊔ R.pushforward f :=
(galois_connection f).l_sup
lemma pushforward_le_bind_of_mem (S : presieve X)
(R : Π ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → sieve Y) (f : Y ⟶ X) (h : S f) :
(R h).pushforward f ≤ bind S R :=
begin
rintro Z _ ⟨g, rfl, hg⟩,
exact ⟨_, g, f, h, hg, rfl⟩,
end
lemma le_pullback_bind (S : presieve X) (R : Π ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → sieve Y)
(f : Y ⟶ X) (h : S f) :
R h ≤ (bind S R).pullback f :=
begin
rw ← galois_connection f,
apply pushforward_le_bind_of_mem,
end
/-- If `f` is a monomorphism, the pushforward-pullback adjunction on sieves is coreflective. -/
def galois_coinsertion_of_mono (f : Y ⟶ X) [mono f] :
galois_coinsertion (sieve.pushforward f) (sieve.pullback f) :=
begin
apply (galois_connection f).to_galois_coinsertion,
rintros S Z g ⟨g₁, hf, hg₁⟩,
rw cancel_mono f at hf,
rwa ← hf,
end
/-- If `f` is a split epi, the pushforward-pullback adjunction on sieves is reflective. -/
def galois_insertion_of_split_epi (f : Y ⟶ X) [split_epi f] :
galois_insertion (sieve.pushforward f) (sieve.pullback f) :=
begin
apply (galois_connection f).to_galois_insertion,
intros S Z g hg,
refine ⟨g ≫ section_ f, by simpa⟩,
end
lemma pullback_arrows_comm [has_pullbacks C] {X Y : C} (f : Y ⟶ X)
(R : presieve X) :
sieve.generate (R.pullback_arrows f) = (sieve.generate R).pullback f :=
begin
ext Z g,
split,
{ rintro ⟨_, h, k, hk, rfl⟩,
cases hk with W g hg,
change (sieve.generate R).pullback f (h ≫ pullback.snd),
rw [sieve.pullback_apply, assoc, ← pullback.condition, ← assoc],
exact sieve.downward_closed _ (sieve.le_generate R W hg) (h ≫ pullback.fst)},
{ rintro ⟨W, h, k, hk, comm⟩,
exact ⟨_, _, _, presieve.pullback_arrows.mk _ _ hk, pullback.lift_snd _ _ comm⟩ },
end
section functor
variables {E : Type u₃} [category.{v₃} E] (G : D ⥤ E)
/--
If `R` is a sieve, then the `category_theory.presieve.functor_pullback` of `R` is actually a sieve.
-/
@[simps] def functor_pullback (R : sieve (F.obj X)) : sieve X :=
{ arrows := presieve.functor_pullback F R,
downward_closed' := λ _ _ f hf g,
begin
unfold presieve.functor_pullback,
rw F.map_comp,
exact R.downward_closed hf (F.map g),
end }
@[simp] lemma functor_pullback_arrows (R : sieve (F.obj X)) :
(R.functor_pullback F).arrows = R.arrows.functor_pullback F := rfl
@[simp] lemma functor_pullback_id (R : sieve X) : R.functor_pullback (𝟭 _) = R :=
by { ext, refl }
lemma functor_pullback_comp (R : sieve ((F ⋙ G).obj X)) :
R.functor_pullback (F ⋙ G) = (R.functor_pullback G).functor_pullback F := by { ext, refl }
lemma functor_pushforward_extend_eq {R : presieve X} :
(generate R).arrows.functor_pushforward F = R.functor_pushforward F :=
begin
ext Y f, split,
{ rintro ⟨X', g, f', ⟨X'', g', f'', h₁, rfl⟩, rfl⟩,
exact ⟨X'', f'', f' ≫ F.map g', h₁, by simp⟩ },
{ rintro ⟨X', g, f', h₁, h₂⟩, exact ⟨X', g, f', le_generate R _ h₁, h₂⟩ }
end
/-- The sieve generated by the image of `R` under `F`. -/
@[simps] def functor_pushforward (R : sieve X) : sieve (F.obj X) :=
{ arrows := R.arrows.functor_pushforward F,
downward_closed' := λ Y Z f h g, by
{ obtain ⟨X, α, β, hα, rfl⟩ := h,
exact ⟨X, α, g ≫ β, hα, by simp⟩ } }
@[simp] lemma functor_pushforward_id (R : sieve X) :
R.functor_pushforward (𝟭 _) = R :=
begin
ext X f,
split,
{ intro hf,
obtain ⟨X, g, h, hg, rfl⟩ := hf,
exact R.downward_closed hg h, },
{ intro hf,
exact ⟨X, f, 𝟙 _, hf, by simp⟩ }
end
lemma functor_pushforward_comp (R : sieve X) :
R.functor_pushforward (F ⋙ G) = (R.functor_pushforward F).functor_pushforward G :=
by { ext, simpa [R.arrows.functor_pushforward_comp F G] }
lemma functor_galois_connection (X : C) :
_root_.galois_connection
(sieve.functor_pushforward F : sieve X → sieve (F.obj X))
(sieve.functor_pullback F) :=
begin
intros R S,
split,
{ intros hle X f hf,
apply hle,
refine ⟨X, f, 𝟙 _, hf, _⟩,
rw category.id_comp, },
{ rintros hle Y f ⟨X, g, h, hg, rfl⟩,
apply sieve.downward_closed S,
exact hle g hg, }
end
lemma functor_pullback_monotone (X : C) :
monotone (sieve.functor_pullback F : sieve (F.obj X) → sieve X) :=
(functor_galois_connection F X).monotone_u
lemma functor_pushforward_monotone (X : C) :
monotone (sieve.functor_pushforward F : sieve X → sieve (F.obj X)) :=
(functor_galois_connection F X).monotone_l
lemma le_functor_pushforward_pullback (R : sieve X) :
R ≤ (R.functor_pushforward F).functor_pullback F :=
(functor_galois_connection F X).le_u_l _
lemma functor_pullback_pushforward_le (R : sieve (F.obj X)) :
(R.functor_pullback F).functor_pushforward F ≤ R :=
(functor_galois_connection F X).l_u_le _
lemma functor_pushforward_union (S R : sieve X) :
(S ⊔ R).functor_pushforward F = S.functor_pushforward F ⊔ R.functor_pushforward F :=
(functor_galois_connection F X).l_sup
lemma functor_pullback_union (S R : sieve (F.obj X)) :
(S ⊔ R).functor_pullback F = S.functor_pullback F ⊔ R.functor_pullback F := rfl
lemma functor_pullback_inter (S R : sieve (F.obj X)) :
(S ⊓ R).functor_pullback F = S.functor_pullback F ⊓ R.functor_pullback F := rfl
lemma functor_pushforward_bot (F : C ⥤ D) (X : C) :
(⊥ : sieve X).functor_pushforward F = ⊥ := (functor_galois_connection F X).l_bot
@[simp] lemma functor_pullback_bot (F : C ⥤ D) (X : C) :
(⊥ : sieve (F.obj X)).functor_pullback F = ⊥ := rfl
@[simp] lemma functor_pullback_top (F : C ⥤ D) (X : C) :
(⊤ : sieve (F.obj X)).functor_pullback F = ⊤ := rfl
lemma image_mem_functor_pushforward (R : sieve X) {V} {f : V ⟶ X} (h : R f) :
R.functor_pushforward F (F.map f) := ⟨V, f, 𝟙 _, h, by simp⟩
/-- When `F` is essentially surjective and full, the galois connection is a galois insertion. -/
def ess_surj_full_functor_galois_insertion [ess_surj F] [full F] (X : C) :
galois_insertion
(sieve.functor_pushforward F : sieve X → sieve (F.obj X))
(sieve.functor_pullback F) :=
begin
apply (functor_galois_connection F X).to_galois_insertion,
intros S Y f hf,
refine ⟨_, F.preimage ((F.obj_obj_preimage_iso Y).hom ≫ f), (F.obj_obj_preimage_iso Y).inv, _⟩,
simpa using S.downward_closed hf _,
end
/-- When `F` is fully faithful, the galois connection is a galois coinsertion. -/
def fully_faithful_functor_galois_coinsertion [full F] [faithful F] (X : C) :
galois_coinsertion
(sieve.functor_pushforward F : sieve X → sieve (F.obj X))
(sieve.functor_pullback F) :=
begin
apply (functor_galois_connection F X).to_galois_coinsertion,
rintros S Y f ⟨Z, g, h, h₁, h₂⟩,
rw [←F.image_preimage h, ←F.map_comp] at h₂,
rw F.map_injective h₂,
exact S.downward_closed h₁ _,
end
end functor
/-- A sieve induces a presheaf. -/
@[simps]
def functor (S : sieve X) : Cᵒᵖ ⥤ Type v₁ :=
{ obj := λ Y, {g : Y.unop ⟶ X // S g},
map := λ Y Z f g, ⟨f.unop ≫ g.1, downward_closed _ g.2 _⟩ }
/--
If a sieve S is contained in a sieve T, then we have a morphism of presheaves on their induced
presheaves.
-/
@[simps]
def nat_trans_of_le {S T : sieve X} (h : S ≤ T) : S.functor ⟶ T.functor :=
{ app := λ Y f, ⟨f.1, h _ f.2⟩ }.
/-- The natural inclusion from the functor induced by a sieve to the yoneda embedding. -/
@[simps]
def functor_inclusion (S : sieve X) : S.functor ⟶ yoneda.obj X :=
{ app := λ Y f, f.1 }.
lemma nat_trans_of_le_comm {S T : sieve X} (h : S ≤ T) :
nat_trans_of_le h ≫ functor_inclusion _ = functor_inclusion _ :=
rfl
/-- The presheaf induced by a sieve is a subobject of the yoneda embedding. -/
instance functor_inclusion_is_mono : mono S.functor_inclusion :=
⟨λ Z f g h, by { ext Y y, apply congr_fun (nat_trans.congr_app h Y) y }⟩
/--
A natural transformation to a representable functor induces a sieve. This is the left inverse of
`functor_inclusion`, shown in `sieve_of_functor_inclusion`.
-/
-- TODO: Show that when `f` is mono, this is right inverse to `functor_inclusion` up to isomorphism.
@[simps]
def sieve_of_subfunctor {R} (f : R ⟶ yoneda.obj X) : sieve X :=
{ arrows := λ Y g, ∃ t, f.app (opposite.op Y) t = g,
downward_closed' := λ Y Z _,
begin
rintro ⟨t, rfl⟩ g,
refine ⟨R.map g.op t, _⟩,
rw functor_to_types.naturality _ _ f,
simp,
end }
lemma sieve_of_subfunctor_functor_inclusion : sieve_of_subfunctor S.functor_inclusion = S :=
begin
ext,
simp only [functor_inclusion_app, sieve_of_subfunctor_apply, subtype.val_eq_coe],
split,
{ rintro ⟨⟨f, hf⟩, rfl⟩,
exact hf },
{ intro hf,
exact ⟨⟨_, hf⟩, rfl⟩ }
end
instance functor_inclusion_top_is_iso : is_iso ((⊤ : sieve X).functor_inclusion) :=
⟨⟨{ app := λ Y a, ⟨a, ⟨⟩⟩ }, by tidy⟩⟩
end sieve
end category_theory
|
790ade46de75f82d92b5e346021c8e10ba426f30 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/1367.lean | a71567c5c12f2048eb1e6b01e511abc951e36a1f | [
"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 | 160 | lean | def two := 2
notation "𝟚" => two
/- 𝟚 : Nat -/
#check 𝟚
def three (_ : Nat) := 3
notation "𝟛" => three
/- three 10 : Nat -/
#check 𝟛 10
|
17150df5c32d5bb7a47b5840c1822e3b7bdf0a28 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/linear_algebra/basic.lean | 0ba16eac1dd6750df3bbefbaf5162ee9e2f419d4 | [
"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 | 83,668 | 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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import algebra.big_operators.pi
import algebra.module.hom
import algebra.module.prod
import algebra.module.submodule.lattice
import data.dfinsupp.basic
import data.finsupp.basic
import order.compactly_generated
/-!
# Linear algebra
This file defines the basics of linear algebra. It sets up the "categorical/lattice structure" of
modules over a ring, submodules, and linear maps.
Many of the relevant definitions, including `module`, `submodule`, and `linear_map`, are found in
`src/algebra/module`.
## Main definitions
* Many constructors for (semi)linear maps
* The kernel `ker` and range `range` of a linear map are submodules of the domain and codomain
respectively.
* The general linear group is defined to be the group of invertible linear maps from `M` to itself.
See `linear_algebra.span` for the span of a set (as a submodule),
and `linear_algebra.quotient` for quotients by submodules.
## Main theorems
See `linear_algebra.isomorphisms` for Noether's three isomorphism theorems for modules.
## Notations
* We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear
(resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`).
## Implementation notes
We note that, when constructing linear maps, it is convenient to use operations defined on bundled
maps (`linear_map.prod`, `linear_map.coprod`, arithmetic operations like `+`) instead of defining a
function and proving it is linear.
## TODO
* Parts of this file have not yet been generalized to semilinear maps
## Tags
linear algebra, vector space, module
-/
open function
open_locale big_operators pointwise
variables {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} {R₄ : Type*}
variables {S : Type*}
variables {K : Type*} {K₂ : Type*}
variables {M : Type*} {M' : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} {M₄ : Type*}
variables {N : Type*} {N₂ : Type*}
variables {ι : Type*}
variables {V : Type*} {V₂ : Type*}
namespace finsupp
lemma smul_sum {α : Type*} {β : Type*} {R : Type*} {M : Type*}
[has_zero β] [monoid R] [add_comm_monoid M] [distrib_mul_action R M]
{v : α →₀ β} {c : R} {h : α → β → M} :
c • (v.sum h) = v.sum (λa b, c • h a b) :=
finset.smul_sum
@[simp]
lemma sum_smul_index_linear_map' {α : Type*} {R : Type*} {M : Type*} {M₂ : Type*}
[semiring R] [add_comm_monoid M] [module R M] [add_comm_monoid M₂] [module R M₂]
{v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} :
(c • v).sum (λ a, h a) = c • (v.sum (λ a, h a)) :=
begin
rw [finsupp.sum_smul_index', finsupp.smul_sum],
{ simp only [map_smul], },
{ intro i, exact (h i).map_zero },
end
variables (α : Type*) [fintype α]
variables (R M) [add_comm_monoid M] [semiring R] [module R M]
/-- Given `fintype α`, `linear_equiv_fun_on_fintype R` is the natural `R`-linear equivalence between
`α →₀ β` and `α → β`. -/
@[simps apply] noncomputable def linear_equiv_fun_on_fintype :
(α →₀ M) ≃ₗ[R] (α → M) :=
{ to_fun := coe_fn,
map_add' := λ f g, by { ext, refl },
map_smul' := λ c f, by { ext, refl },
.. equiv_fun_on_fintype }
@[simp] lemma linear_equiv_fun_on_fintype_single [decidable_eq α] (x : α) (m : M) :
(linear_equiv_fun_on_fintype R M α) (single x m) = pi.single x m :=
begin
ext a,
change (equiv_fun_on_fintype (single x m)) a = _,
convert _root_.congr_fun (equiv_fun_on_fintype_single x m) a,
end
@[simp] lemma linear_equiv_fun_on_fintype_symm_single [decidable_eq α]
(x : α) (m : M) : (linear_equiv_fun_on_fintype R M α).symm (pi.single x m) = single x m :=
begin
ext a,
change (equiv_fun_on_fintype.symm (pi.single x m)) a = _,
convert congr_fun (equiv_fun_on_fintype_symm_single x m) a,
end
@[simp] lemma linear_equiv_fun_on_fintype_symm_coe (f : α →₀ M) :
(linear_equiv_fun_on_fintype R M α).symm f = f :=
by { ext, simp [linear_equiv_fun_on_fintype], }
end finsupp
/-- decomposing `x : ι → R` as a sum along the canonical basis -/
lemma pi_eq_sum_univ {ι : Type*} [fintype ι] [decidable_eq ι] {R : Type*} [semiring R] (x : ι → R) :
x = ∑ i, x i • (λj, if i = j then 1 else 0) :=
by { ext, simp }
/-! ### Properties of linear maps -/
namespace linear_map
section add_comm_monoid
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid M₂]
variables [add_comm_monoid M₃] [add_comm_monoid M₄]
variables [module R M] [module R M₁] [module R₂ M₂] [module R₃ M₃] [module R₄ M₄]
variables {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₃₄ : R₃ →+* R₄}
variables {σ₁₃ : R →+* R₃} {σ₂₄ : R₂ →+* R₄} {σ₁₄ : R →+* R₄}
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [ring_hom_comp_triple σ₂₃ σ₃₄ σ₂₄]
variables [ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄] [ring_hom_comp_triple σ₁₂ σ₂₄ σ₁₄]
variables (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃)
include R R₂
theorem comp_assoc (h : M₃ →ₛₗ[σ₃₄] M₄) :
((h.comp g : M₂ →ₛₗ[σ₂₄] M₄).comp f : M →ₛₗ[σ₁₄] M₄)
= h.comp (g.comp f : M →ₛₗ[σ₁₃] M₃) := rfl
omit R R₂
/-- The restriction of a linear map `f : M → M₂` to a submodule `p ⊆ M` gives a linear map
`p → M₂`. -/
def dom_restrict (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) : p →ₛₗ[σ₁₂] M₂ := f.comp p.subtype
@[simp] lemma dom_restrict_apply (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) (x : p) :
f.dom_restrict p x = f x := rfl
/-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a
linear map M₂ → p. -/
def cod_restrict (p : submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) (h : ∀c, f c ∈ p) : M →ₛₗ[σ₁₂] p :=
by refine {to_fun := λc, ⟨f c, h c⟩, ..}; intros; apply set_coe.ext; simp
@[simp] theorem cod_restrict_apply (p : submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) {h} (x : M) :
(cod_restrict p f h x : M₂) = f x := rfl
@[simp] lemma comp_cod_restrict (p : submodule R₃ M₃) (h : ∀b, g b ∈ p) :
((cod_restrict p g h).comp f : M →ₛₗ[σ₁₃] p) = cod_restrict p (g.comp f) (assume b, h _) :=
ext $ assume b, rfl
@[simp] lemma subtype_comp_cod_restrict (p : submodule R₂ M₂) (h : ∀b, f b ∈ p) :
p.subtype.comp (cod_restrict p f h) = f :=
ext $ assume b, rfl
/-- Restrict domain and codomain of an endomorphism. -/
def restrict (f : M →ₗ[R] M) {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) : p →ₗ[R] p :=
(f.dom_restrict p).cod_restrict p $ set_like.forall.2 hf
lemma restrict_apply
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) (x : p) :
f.restrict hf x = ⟨f x, hf x.1 x.2⟩ := rfl
lemma subtype_comp_restrict {f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) :
p.subtype.comp (f.restrict hf) = f.dom_restrict p := rfl
lemma restrict_eq_cod_restrict_dom_restrict
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) :
f.restrict hf = (f.dom_restrict p).cod_restrict p (λ x, hf x.1 x.2) := rfl
lemma restrict_eq_dom_restrict_cod_restrict
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x, f x ∈ p) :
f.restrict (λ x _, hf x) = (f.cod_restrict p hf).dom_restrict p := rfl
instance unique_of_left [subsingleton M] : unique (M →ₛₗ[σ₁₂] M₂) :=
{ uniq := λ f, ext $ λ x, by rw [subsingleton.elim x 0, map_zero, map_zero],
.. linear_map.inhabited }
instance unique_of_right [subsingleton M₂] : unique (M →ₛₗ[σ₁₂] M₂) :=
coe_injective.unique
/-- Evaluation of a `σ₁₂`-linear map at a fixed `a`, as an `add_monoid_hom`. -/
def eval_add_monoid_hom (a : M) : (M →ₛₗ[σ₁₂] M₂) →+ M₂ :=
{ to_fun := λ f, f a,
map_add' := λ f g, linear_map.add_apply f g a,
map_zero' := rfl }
/-- `linear_map.to_add_monoid_hom` promoted to an `add_monoid_hom` -/
def to_add_monoid_hom' : (M →ₛₗ[σ₁₂] M₂) →+ (M →+ M₂) :=
{ to_fun := to_add_monoid_hom,
map_zero' := by ext; refl,
map_add' := by intros; ext; refl }
lemma sum_apply (t : finset ι) (f : ι → M →ₛₗ[σ₁₂] M₂) (b : M) :
(∑ d in t, f d) b = ∑ d in t, f d b :=
add_monoid_hom.map_sum ((add_monoid_hom.eval b).comp to_add_monoid_hom') f _
section smul_right
variables [semiring S] [module R S] [module S M] [is_scalar_tower R S M]
/-- When `f` is an `R`-linear map taking values in `S`, then `λb, f b • x` is an `R`-linear map. -/
def smul_right (f : M₁ →ₗ[R] S) (x : M) : M₁ →ₗ[R] M :=
{ to_fun := λb, f b • x,
map_add' := λ x y, by rw [f.map_add, add_smul],
map_smul' := λ b y, by dsimp; rw [map_smul, smul_assoc] }
@[simp] theorem coe_smul_right (f : M₁ →ₗ[R] S) (x : M) :
(smul_right f x : M₁ → M) = λ c, f c • x := rfl
theorem smul_right_apply (f : M₁ →ₗ[R] S) (x : M) (c : M₁) :
smul_right f x c = f c • x := rfl
end smul_right
instance [nontrivial M] : nontrivial (module.End R M) :=
begin
obtain ⟨m, ne⟩ := (nontrivial_iff_exists_ne (0 : M)).mp infer_instance,
exact nontrivial_of_ne 1 0 (λ p, ne (linear_map.congr_fun p m)),
end
@[simp, norm_cast] lemma coe_fn_sum {ι : Type*} (t : finset ι) (f : ι → M →ₛₗ[σ₁₂] M₂) :
⇑(∑ i in t, f i) = ∑ i in t, (f i : M → M₂) :=
add_monoid_hom.map_sum ⟨@to_fun R R₂ _ _ σ₁₂ M M₂ _ _ _ _, rfl, λ x y, rfl⟩ _ _
@[simp] lemma pow_apply (f : M →ₗ[R] M) (n : ℕ) (m : M) :
(f^n) m = (f^[n] m) :=
begin
induction n with n ih,
{ refl, },
{ simp only [function.comp_app, function.iterate_succ, linear_map.mul_apply, pow_succ, ih],
exact (function.commute.iterate_self _ _ m).symm, },
end
lemma pow_map_zero_of_le
{f : module.End R M} {m : M} {k l : ℕ} (hk : k ≤ l) (hm : (f^k) m = 0) : (f^l) m = 0 :=
by rw [← tsub_add_cancel_of_le hk, pow_add, mul_apply, hm, map_zero]
lemma commute_pow_left_of_commute
{f : M →ₛₗ[σ₁₂] M₂} {g : module.End R M} {g₂ : module.End R₂ M₂}
(h : g₂.comp f = f.comp g) (k : ℕ) : (g₂^k).comp f = f.comp (g^k) :=
begin
induction k with k ih,
{ simpa only [pow_zero], },
{ rw [pow_succ, pow_succ, linear_map.mul_eq_comp, linear_map.comp_assoc, ih,
← linear_map.comp_assoc, h, linear_map.comp_assoc, linear_map.mul_eq_comp], },
end
lemma submodule_pow_eq_zero_of_pow_eq_zero {N : submodule R M}
{g : module.End R N} {G : module.End R M} (h : G.comp N.subtype = N.subtype.comp g)
{k : ℕ} (hG : G^k = 0) : g^k = 0 :=
begin
ext m,
have hg : N.subtype.comp (g^k) m = 0,
{ rw [← commute_pow_left_of_commute h, hG, zero_comp, zero_apply], },
simp only [submodule.subtype_apply, comp_app, submodule.coe_eq_zero, coe_comp] at hg,
rw [hg, linear_map.zero_apply],
end
lemma coe_pow (f : M →ₗ[R] M) (n : ℕ) : ⇑(f^n) = (f^[n]) :=
by { ext m, apply pow_apply, }
@[simp] lemma id_pow (n : ℕ) : (id : M →ₗ[R] M)^n = id := one_pow n
section
variables {f' : M →ₗ[R] M}
lemma iterate_succ (n : ℕ) : (f' ^ (n + 1)) = comp (f' ^ n) f' :=
by rw [pow_succ', mul_eq_comp]
lemma iterate_surjective (h : surjective f') : ∀ n : ℕ, surjective ⇑(f' ^ n)
| 0 := surjective_id
| (n + 1) := by { rw [iterate_succ], exact surjective.comp (iterate_surjective n) h, }
lemma iterate_injective (h : injective f') : ∀ n : ℕ, injective ⇑(f' ^ n)
| 0 := injective_id
| (n + 1) := by { rw [iterate_succ], exact injective.comp (iterate_injective n) h, }
lemma iterate_bijective (h : bijective f') : ∀ n : ℕ, bijective ⇑(f' ^ n)
| 0 := bijective_id
| (n + 1) := by { rw [iterate_succ], exact bijective.comp (iterate_bijective n) h, }
lemma injective_of_iterate_injective {n : ℕ} (hn : n ≠ 0) (h : injective ⇑(f' ^ n)) :
injective f' :=
begin
rw [← nat.succ_pred_eq_of_pos (pos_iff_ne_zero.mpr hn), iterate_succ, coe_comp] at h,
exact injective.of_comp h,
end
lemma surjective_of_iterate_surjective {n : ℕ} (hn : n ≠ 0) (h : surjective ⇑(f' ^ n)) :
surjective f' :=
begin
rw [← nat.succ_pred_eq_of_pos (pos_iff_ne_zero.mpr hn),
nat.succ_eq_add_one, add_comm, pow_add] at h,
exact surjective.of_comp h,
end
lemma pow_apply_mem_of_forall_mem {p : submodule R M}
(n : ℕ) (h : ∀ x ∈ p, f' x ∈ p) (x : M) (hx : x ∈ p) :
(f'^n) x ∈ p :=
begin
induction n with n ih generalizing x, { simpa, },
simpa only [iterate_succ, coe_comp, function.comp_app, restrict_apply] using ih _ (h _ hx),
end
lemma pow_restrict {p : submodule R M} (n : ℕ)
(h : ∀ x ∈ p, f' x ∈ p) (h' := pow_apply_mem_of_forall_mem n h) :
(f'.restrict h)^n = (f'^n).restrict h' :=
begin
induction n with n ih;
ext,
{ simp [restrict_apply], },
{ simp [restrict_apply, linear_map.iterate_succ, -linear_map.pow_apply, ih], },
end
end
/-- A linear map `f` applied to `x : ι → R` can be computed using the image under `f` of elements
of the canonical basis. -/
lemma pi_apply_eq_sum_univ [fintype ι] [decidable_eq ι] (f : (ι → R) →ₗ[R] M) (x : ι → R) :
f x = ∑ i, x i • (f (λj, if i = j then 1 else 0)) :=
begin
conv_lhs { rw [pi_eq_sum_univ x, f.map_sum] },
apply finset.sum_congr rfl (λl hl, _),
rw map_smul
end
end add_comm_monoid
section module
variables [semiring R] [semiring S]
[add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
[module R M] [module R M₂] [module R M₃]
[module S M₂] [module S M₃] [smul_comm_class R S M₂] [smul_comm_class R S M₃]
(f : M →ₗ[R] M₂)
variable (S)
/-- Applying a linear map at `v : M`, seen as `S`-linear map from `M →ₗ[R] M₂` to `M₂`.
See `linear_map.applyₗ` for a version where `S = R`. -/
@[simps]
def applyₗ' : M →+ (M →ₗ[R] M₂) →ₗ[S] M₂ :=
{ to_fun := λ v,
{ to_fun := λ f, f v,
map_add' := λ f g, f.add_apply g v,
map_smul' := λ x f, f.smul_apply x v },
map_zero' := linear_map.ext $ λ f, f.map_zero,
map_add' := λ x y, linear_map.ext $ λ f, f.map_add _ _ }
section
variables (R M)
/--
The equivalence between R-linear maps from `R` to `M`, and points of `M` itself.
This says that the forgetful functor from `R`-modules to types is representable, by `R`.
This as an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`.
When `R` is commutative, we can take this to be the usual action with `S = R`.
Otherwise, `S = ℕ` shows that the equivalence is additive.
See note [bundled maps over different rings].
-/
@[simps]
def ring_lmap_equiv_self [module S M] [smul_comm_class R S M] : (R →ₗ[R] M) ≃ₗ[S] M :=
{ to_fun := λ f, f 1,
inv_fun := smul_right (1 : R →ₗ[R] R),
left_inv := λ f, by { ext, simp },
right_inv := λ x, by simp,
.. applyₗ' S (1 : R) }
end
end module
section comm_semiring
variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [module R M] [module R M₂] [module R M₃]
variables (f g : M →ₗ[R] M₂)
include R
/-- Composition by `f : M₂ → M₃` is a linear map from the space of linear maps `M → M₂`
to the space of linear maps `M₂ → M₃`. -/
def comp_right (f : M₂ →ₗ[R] M₃) : (M →ₗ[R] M₂) →ₗ[R] (M →ₗ[R] M₃) :=
{ to_fun := f.comp,
map_add' := λ _ _, linear_map.ext $ λ _, map_add f _ _,
map_smul' := λ _ _, linear_map.ext $ λ _, map_smul f _ _ }
@[simp]
lemma comp_right_apply (f : M₂ →ₗ[R] M₃) (g : M →ₗ[R] M₂) :
comp_right f g = f.comp g := rfl
/-- Applying a linear map at `v : M`, seen as a linear map from `M →ₗ[R] M₂` to `M₂`.
See also `linear_map.applyₗ'` for a version that works with two different semirings.
This is the `linear_map` version of `add_monoid_hom.eval`. -/
@[simps]
def applyₗ : M →ₗ[R] (M →ₗ[R] M₂) →ₗ[R] M₂ :=
{ to_fun := λ v, { to_fun := λ f, f v, ..applyₗ' R v },
map_smul' := λ x y, linear_map.ext $ λ f, map_smul f _ _,
..applyₗ' R }
/-- Alternative version of `dom_restrict` as a linear map. -/
def dom_restrict'
(p : submodule R M) : (M →ₗ[R] M₂) →ₗ[R] (p →ₗ[R] M₂) :=
{ to_fun := λ φ, φ.dom_restrict p,
map_add' := by simp [linear_map.ext_iff],
map_smul' := by simp [linear_map.ext_iff] }
@[simp] lemma dom_restrict'_apply (f : M →ₗ[R] M₂) (p : submodule R M) (x : p) :
dom_restrict' p f x = f x := rfl
/--
The family of linear maps `M₂ → M` parameterised by `f ∈ M₂ → R`, `x ∈ M`, is linear in `f`, `x`.
-/
def smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M :=
{ to_fun := λ f,
{ to_fun := linear_map.smul_right f,
map_add' := λ m m', by { ext, apply smul_add, },
map_smul' := λ c m, by { ext, apply smul_comm, } },
map_add' := λ f f', by { ext, apply add_smul, },
map_smul' := λ c f, by { ext, apply mul_smul, } }
@[simp] lemma smul_rightₗ_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) :
(smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M) f x c = (f c) • x := rfl
end comm_semiring
end linear_map
/--
The `R`-linear equivalence between additive morphisms `A →+ B` and `ℕ`-linear morphisms `A →ₗ[ℕ] B`.
-/
@[simps]
def add_monoid_hom_lequiv_nat {A B : Type*} (R : Type*)
[semiring R] [add_comm_monoid A] [add_comm_monoid B] [module R B] :
(A →+ B) ≃ₗ[R] (A →ₗ[ℕ] B) :=
{ to_fun := add_monoid_hom.to_nat_linear_map,
inv_fun := linear_map.to_add_monoid_hom,
map_add' := by { intros, ext, refl },
map_smul' := by { intros, ext, refl },
left_inv := by { intros f, ext, refl },
right_inv := by { intros f, ext, refl } }
/--
The `R`-linear equivalence between additive morphisms `A →+ B` and `ℤ`-linear morphisms `A →ₗ[ℤ] B`.
-/
@[simps]
def add_monoid_hom_lequiv_int {A B : Type*} (R : Type*)
[semiring R] [add_comm_group A] [add_comm_group B] [module R B] :
(A →+ B) ≃ₗ[R] (A →ₗ[ℤ] B) :=
{ to_fun := add_monoid_hom.to_int_linear_map,
inv_fun := linear_map.to_add_monoid_hom,
map_add' := by { intros, ext, refl },
map_smul' := by { intros, ext, refl },
left_inv := by { intros f, ext, refl },
right_inv := by { intros f, ext, refl } }
/-! ### Properties of submodules -/
namespace submodule
section add_comm_monoid
variables [semiring R] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M']
variables [module R M] [module R M'] [module R₂ M₂] [module R₃ M₃]
variables {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variables {σ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables (p p' : submodule R M) (q q' : submodule R₂ M₂)
variables (q₁ q₁' : submodule R M')
variables {r : R} {x y : M}
open set
variables {p p'}
/-- If two submodules `p` and `p'` satisfy `p ⊆ p'`, then `of_le p p'` is the linear map version of
this inclusion. -/
def of_le (h : p ≤ p') : p →ₗ[R] p' :=
p.subtype.cod_restrict p' $ λ ⟨x, hx⟩, h hx
@[simp] theorem coe_of_le (h : p ≤ p') (x : p) :
(of_le h x : M) = x := rfl
theorem of_le_apply (h : p ≤ p') (x : p) : of_le h x = ⟨x, h x.2⟩ := rfl
theorem of_le_injective (h : p ≤ p') : function.injective (of_le h) :=
λ x y h, subtype.val_injective (subtype.mk.inj h)
variables (p p')
lemma subtype_comp_of_le (p q : submodule R M) (h : p ≤ q) :
q.subtype.comp (of_le h) = p.subtype :=
by { ext ⟨b, hb⟩, refl }
variables (R)
@[simp] lemma subsingleton_iff : subsingleton (submodule R M) ↔ subsingleton M :=
have h : subsingleton (submodule R M) ↔ subsingleton (add_submonoid M),
{ rw [←subsingleton_iff_bot_eq_top, ←subsingleton_iff_bot_eq_top],
convert to_add_submonoid_eq.symm; refl, },
h.trans add_submonoid.subsingleton_iff
@[simp] lemma nontrivial_iff : nontrivial (submodule R M) ↔ nontrivial M :=
not_iff_not.mp (
(not_nontrivial_iff_subsingleton.trans $ subsingleton_iff R).trans
not_nontrivial_iff_subsingleton.symm)
variables {R}
instance [subsingleton M] : unique (submodule R M) :=
⟨⟨⊥⟩, λ a, @subsingleton.elim _ ((subsingleton_iff R).mpr ‹_›) a _⟩
instance unique' [subsingleton R] : unique (submodule R M) :=
by haveI := module.subsingleton R M; apply_instance
instance [nontrivial M] : nontrivial (submodule R M) := (nontrivial_iff R).mpr ‹_›
theorem mem_right_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p} :
(x:M) ∈ p' ↔ x = 0 :=
⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x x.2 hx, λ h, h.symm ▸ p'.zero_mem⟩
theorem mem_left_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p'} :
(x:M) ∈ p ↔ x = 0 :=
⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x hx x.2, λ h, h.symm ▸ p.zero_mem⟩
section
variables [ring_hom_surjective σ₁₂]
/-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/
def map (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) : submodule R₂ M₂ :=
{ carrier := f '' p,
smul_mem' :=
begin
rintro c x ⟨y, hy, rfl⟩,
obtain ⟨a, rfl⟩ := σ₁₂.is_surjective c,
exact ⟨_, p.smul_mem a hy, map_smulₛₗ f _ _⟩,
end,
.. p.to_add_submonoid.map f.to_add_monoid_hom }
@[simp] lemma map_coe (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
(map f p : set M₂) = f '' p := rfl
lemma map_to_add_submonoid (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
(p.map f).to_add_submonoid = p.to_add_submonoid.map (f : M →+ M₂) :=
set_like.coe_injective rfl
lemma map_to_add_submonoid' (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
(p.map f).to_add_submonoid = p.to_add_submonoid.map f :=
set_like.coe_injective rfl
@[simp] lemma mem_map {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R M} {x : M₂} :
x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x := iff.rfl
theorem mem_map_of_mem {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R M} {r} (h : r ∈ p) :
f r ∈ map f p := set.mem_image_of_mem _ h
lemma apply_coe_mem_map (f : M →ₛₗ[σ₁₂] M₂) {p : submodule R M} (r : p) :
f r ∈ map f p := mem_map_of_mem r.prop
@[simp] lemma map_id : map (linear_map.id : M →ₗ[R] M) p = p :=
submodule.ext $ λ a, by simp
lemma map_comp [ring_hom_surjective σ₂₃] [ring_hom_surjective σ₁₃]
(f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃)
(p : submodule R M) : map (g.comp f : M →ₛₗ[σ₁₃] M₃) p = map g (map f p) :=
set_like.coe_injective $ by simp [map_coe]; rw ← image_comp
lemma map_mono {f : M →ₛₗ[σ₁₂] M₂} {p p' : submodule R M} :
p ≤ p' → map f p ≤ map f p' := image_subset _
@[simp] lemma map_zero : map (0 : M →ₛₗ[σ₁₂] M₂) p = ⊥ :=
have ∃ (x : M), x ∈ p := ⟨0, p.zero_mem⟩,
ext $ by simp [this, eq_comm]
lemma map_add_le (f g : M →ₛₗ[σ₁₂] M₂) : map (f + g) p ≤ map f p ⊔ map g p :=
begin
rintros x ⟨m, hm, rfl⟩,
exact add_mem_sup (mem_map_of_mem hm) (mem_map_of_mem hm),
end
lemma range_map_nonempty (N : submodule R M) :
(set.range (λ ϕ, submodule.map ϕ N : (M →ₛₗ[σ₁₂] M₂) → submodule R₂ M₂)).nonempty :=
⟨_, set.mem_range.mpr ⟨0, rfl⟩⟩
end
include σ₂₁
/-- The pushforward of a submodule by an injective linear map is
linearly equivalent to the original submodule. See also `linear_equiv.submodule_map` for a
computable version when `f` has an explicit inverse. -/
noncomputable def equiv_map_of_injective (f : M →ₛₗ[σ₁₂] M₂) (i : injective f)
(p : submodule R M) : p ≃ₛₗ[σ₁₂] p.map f :=
{ map_add' := by { intros, simp, refl },
map_smul' := by { intros, simp, refl },
..(equiv.set.image f p i) }
@[simp] lemma coe_equiv_map_of_injective_apply (f : M →ₛₗ[σ₁₂] M₂) (i : injective f)
(p : submodule R M) (x : p) :
(equiv_map_of_injective f i p x : M₂) = f x := rfl
omit σ₂₁
/-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/
def comap (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R₂ M₂) : submodule R M :=
{ carrier := f ⁻¹' p,
smul_mem' := λ a x h, by simp [p.smul_mem _ h],
.. p.to_add_submonoid.comap f.to_add_monoid_hom }
@[simp] lemma comap_coe (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R₂ M₂) :
(comap f p : set M) = f ⁻¹' p := rfl
@[simp] lemma mem_comap {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R₂ M₂} :
x ∈ comap f p ↔ f x ∈ p := iff.rfl
@[simp] lemma comap_id : comap linear_map.id p = p :=
set_like.coe_injective rfl
lemma comap_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃)
(p : submodule R₃ M₃) : comap (g.comp f : M →ₛₗ[σ₁₃] M₃) p = comap f (comap g p) :=
rfl
lemma comap_mono {f : M →ₛₗ[σ₁₂] M₂} {q q' : submodule R₂ M₂} :
q ≤ q' → comap f q ≤ comap f q' := preimage_mono
lemma le_comap_pow_of_le_comap (p : submodule R M) {f : M →ₗ[R] M} (h : p ≤ p.comap f) (k : ℕ) :
p ≤ p.comap (f^k) :=
begin
induction k with k ih,
{ simp [linear_map.one_eq_id], },
{ simp [linear_map.iterate_succ, comap_comp, h.trans (comap_mono ih)], },
end
section
variables [ring_hom_surjective σ₁₂]
lemma map_le_iff_le_comap {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R M} {q : submodule R₂ M₂} :
map f p ≤ q ↔ p ≤ comap f q := image_subset_iff
lemma gc_map_comap (f : M →ₛₗ[σ₁₂] M₂) : galois_connection (map f) (comap f)
| p q := map_le_iff_le_comap
@[simp] lemma map_bot (f : M →ₛₗ[σ₁₂] M₂) : map f ⊥ = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma map_sup (f : M →ₛₗ[σ₁₂] M₂) : map f (p ⊔ p') = map f p ⊔ map f p' :=
(gc_map_comap f).l_sup
@[simp] lemma map_supr {ι : Sort*} (f : M →ₛₗ[σ₁₂] M₂) (p : ι → submodule R M) :
map f (⨆i, p i) = (⨆i, map f (p i)) :=
(gc_map_comap f).l_supr
end
@[simp] lemma comap_top (f : M →ₛₗ[σ₁₂] M₂) : comap f ⊤ = ⊤ := rfl
@[simp] lemma comap_inf (f : M →ₛₗ[σ₁₂] M₂) : comap f (q ⊓ q') = comap f q ⊓ comap f q' := rfl
@[simp] lemma comap_infi [ring_hom_surjective σ₁₂] {ι : Sort*} (f : M →ₛₗ[σ₁₂] M₂)
(p : ι → submodule R₂ M₂) :
comap f (⨅i, p i) = (⨅i, comap f (p i)) :=
(gc_map_comap f).u_infi
@[simp] lemma comap_zero : comap (0 : M →ₛₗ[σ₁₂] M₂) q = ⊤ :=
ext $ by simp
lemma map_comap_le [ring_hom_surjective σ₁₂] (f : M →ₛₗ[σ₁₂] M₂) (q : submodule R₂ M₂) :
map f (comap f q) ≤ q :=
(gc_map_comap f).l_u_le _
lemma le_comap_map [ring_hom_surjective σ₁₂] (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
p ≤ comap f (map f p) :=
(gc_map_comap f).le_u_l _
section galois_insertion
variables {f : M →ₛₗ[σ₁₂] M₂} (hf : surjective f)
variables [ring_hom_surjective σ₁₂]
include hf
/-- `map f` and `comap f` form a `galois_insertion` when `f` is surjective. -/
def gi_map_comap : galois_insertion (map f) (comap f) :=
(gc_map_comap f).to_galois_insertion
(λ S x hx, begin
rcases hf x with ⟨y, rfl⟩,
simp only [mem_map, mem_comap],
exact ⟨y, hx, rfl⟩
end)
lemma map_comap_eq_of_surjective (p : submodule R₂ M₂) : (p.comap f).map f = p :=
(gi_map_comap hf).l_u_eq _
lemma map_surjective_of_surjective : function.surjective (map f) :=
(gi_map_comap hf).l_surjective
lemma comap_injective_of_surjective : function.injective (comap f) :=
(gi_map_comap hf).u_injective
lemma map_sup_comap_of_surjective (p q : submodule R₂ M₂) :
(p.comap f ⊔ q.comap f).map f = p ⊔ q :=
(gi_map_comap hf).l_sup_u _ _
lemma map_supr_comap_of_sujective {ι : Sort*} (S : ι → submodule R₂ M₂) :
(⨆ i, (S i).comap f).map f = supr S :=
(gi_map_comap hf).l_supr_u _
lemma map_inf_comap_of_surjective (p q : submodule R₂ M₂) :
(p.comap f ⊓ q.comap f).map f = p ⊓ q :=
(gi_map_comap hf).l_inf_u _ _
lemma map_infi_comap_of_surjective {ι : Sort*} (S : ι → submodule R₂ M₂) :
(⨅ i, (S i).comap f).map f = infi S :=
(gi_map_comap hf).l_infi_u _
lemma comap_le_comap_iff_of_surjective (p q : submodule R₂ M₂) :
p.comap f ≤ q.comap f ↔ p ≤ q :=
(gi_map_comap hf).u_le_u_iff
lemma comap_strict_mono_of_surjective : strict_mono (comap f) :=
(gi_map_comap hf).strict_mono_u
end galois_insertion
section galois_coinsertion
variables [ring_hom_surjective σ₁₂] {f : M →ₛₗ[σ₁₂] M₂} (hf : injective f)
include hf
/-- `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. -/
def gci_map_comap : galois_coinsertion (map f) (comap f) :=
(gc_map_comap f).to_galois_coinsertion
(λ S x, by simp [mem_comap, mem_map, hf.eq_iff])
lemma comap_map_eq_of_injective (p : submodule R M) : (p.map f).comap f = p :=
(gci_map_comap hf).u_l_eq _
lemma comap_surjective_of_injective : function.surjective (comap f) :=
(gci_map_comap hf).u_surjective
lemma map_injective_of_injective : function.injective (map f) :=
(gci_map_comap hf).l_injective
lemma comap_inf_map_of_injective (p q : submodule R M) : (p.map f ⊓ q.map f).comap f = p ⊓ q :=
(gci_map_comap hf).u_inf_l _ _
lemma comap_infi_map_of_injective {ι : Sort*} (S : ι → submodule R M) :
(⨅ i, (S i).map f).comap f = infi S :=
(gci_map_comap hf).u_infi_l _
lemma comap_sup_map_of_injective (p q : submodule R M) : (p.map f ⊔ q.map f).comap f = p ⊔ q :=
(gci_map_comap hf).u_sup_l _ _
lemma comap_supr_map_of_injective {ι : Sort*} (S : ι → submodule R M) :
(⨆ i, (S i).map f).comap f = supr S :=
(gci_map_comap hf).u_supr_l _
lemma map_le_map_iff_of_injective (p q : submodule R M) : p.map f ≤ q.map f ↔ p ≤ q :=
(gci_map_comap hf).l_le_l_iff
lemma map_strict_mono_of_injective : strict_mono (map f) :=
(gci_map_comap hf).strict_mono_l
end galois_coinsertion
--TODO(Mario): is there a way to prove this from order properties?
lemma map_inf_eq_map_inf_comap [ring_hom_surjective σ₁₂] {f : M →ₛₗ[σ₁₂] M₂}
{p : submodule R M} {p' : submodule R₂ M₂} :
map f p ⊓ p' = map f (p ⊓ comap f p') :=
le_antisymm
(by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩)
(le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right))
lemma map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' :=
ext $ λ x, ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨⟨_, h₁⟩, h₂, rfl⟩⟩
lemma eq_zero_of_bot_submodule : ∀(b : (⊥ : submodule R M)), b = 0
| ⟨b', hb⟩ := subtype.eq $ show b' = 0, from (mem_bot R).1 hb
/-- The infimum of a family of invariant submodule of an endomorphism is also an invariant
submodule. -/
lemma _root_.linear_map.infi_invariant {σ : R →+* R} [ring_hom_surjective σ] {ι : Sort*}
(f : M →ₛₗ[σ] M) {p : ι → submodule R M} (hf : ∀ i, ∀ v ∈ (p i), f v ∈ p i) :
∀ v ∈ infi p, f v ∈ infi p :=
begin
have : ∀ i, (p i).map f ≤ p i,
{ rintros i - ⟨v, hv, rfl⟩,
exact hf i v hv },
suffices : (infi p).map f ≤ infi p,
{ exact λ v hv, this ⟨v, hv, rfl⟩, },
exact le_infi (λ i, (submodule.map_mono (infi_le p i)).trans (this i)),
end
end add_comm_monoid
section add_comm_group
variables [ring R] [add_comm_group M] [module R M] (p : submodule R M)
variables [add_comm_group M₂] [module R M₂]
@[simp] lemma neg_coe : -(p : set M) = p := set.ext $ λ x, p.neg_mem_iff
@[simp] protected lemma map_neg (f : M →ₗ[R] M₂) : map (-f) p = map f p :=
ext $ λ y, ⟨λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, show -x ∈ p, from neg_mem hx, map_neg f x⟩,
λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, show -x ∈ p, from neg_mem hx, (map_neg (-f) _).trans (neg_neg (f x))⟩⟩
end add_comm_group
end submodule
namespace submodule
variables [field K]
variables [add_comm_group V] [module K V]
variables [add_comm_group V₂] [module K V₂]
lemma comap_smul (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) (h : a ≠ 0) :
p.comap (a • f) = p.comap f :=
by ext b; simp only [submodule.mem_comap, p.smul_mem_iff h, linear_map.smul_apply]
lemma map_smul (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) (h : a ≠ 0) :
p.map (a • f) = p.map f :=
le_antisymm
begin rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap], exact le_rfl end
begin rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap], exact le_rfl end
lemma comap_smul' (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) :
p.comap (a • f) = (⨅ h : a ≠ 0, p.comap f) :=
by classical; by_cases a = 0; simp [h, comap_smul]
lemma map_smul' (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) :
p.map (a • f) = (⨆ h : a ≠ 0, p.map f) :=
by classical; by_cases a = 0; simp [h, map_smul]
end submodule
/-! ### Properties of linear maps -/
namespace linear_map
section add_comm_monoid
variables [semiring R] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables [module R M] [module R₂ M₂] [module R₃ M₃]
include R
open submodule
section finsupp
variables {γ : Type*} [has_zero γ]
@[simp] lemma map_finsupp_sum (f : M →ₛₗ[σ₁₂] M₂) {t : ι →₀ γ} {g : ι → γ → M} :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum
lemma coe_finsupp_sum (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) :
⇑(t.sum g) = t.sum (λ i d, g i d) := coe_fn_sum _ _
@[simp] lemma finsupp_sum_apply (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) (b : M) :
(t.sum g) b = t.sum (λ i d, g i d b) := sum_apply _ _ _
end finsupp
section dfinsupp
open dfinsupp
variables {γ : ι → Type*} [decidable_eq ι]
section sum
variables [Π i, has_zero (γ i)] [Π i (x : γ i), decidable (x ≠ 0)]
@[simp] lemma map_dfinsupp_sum (f : M →ₛₗ[σ₁₂] M₂) {t : Π₀ i, γ i} {g : Π i, γ i → M} :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum
lemma coe_dfinsupp_sum (t : Π₀ i, γ i) (g : Π i, γ i → M →ₛₗ[σ₁₂] M₂) :
⇑(t.sum g) = t.sum (λ i d, g i d) := coe_fn_sum _ _
@[simp] lemma dfinsupp_sum_apply (t : Π₀ i, γ i) (g : Π i, γ i → M →ₛₗ[σ₁₂] M₂) (b : M) :
(t.sum g) b = t.sum (λ i d, g i d b) := sum_apply _ _ _
end sum
section sum_add_hom
variables [Π i, add_zero_class (γ i)]
@[simp] lemma map_dfinsupp_sum_add_hom (f : M →ₛₗ[σ₁₂] M₂) {t : Π₀ i, γ i} {g : Π i, γ i →+ M} :
f (sum_add_hom g t) = sum_add_hom (λ i, f.to_add_monoid_hom.comp (g i)) t :=
f.to_add_monoid_hom.map_dfinsupp_sum_add_hom _ _
end sum_add_hom
end dfinsupp
variables {σ₂₁ : R₂ →+* R} {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple τ₁₂ τ₂₃ τ₁₃]
theorem map_cod_restrict [ring_hom_surjective σ₂₁] (p : submodule R M) (f : M₂ →ₛₗ[σ₂₁] M) (h p') :
submodule.map (cod_restrict p f h) p' = comap p.subtype (p'.map f) :=
submodule.ext $ λ ⟨x, hx⟩, by simp [subtype.ext_iff_val]
theorem comap_cod_restrict (p : submodule R M) (f : M₂ →ₛₗ[σ₂₁] M) (hf p') :
submodule.comap (cod_restrict p f hf) p' = submodule.comap f (map p.subtype p') :=
submodule.ext $ λ x, ⟨λ h, ⟨⟨_, hf x⟩, h, rfl⟩, by rintro ⟨⟨_, _⟩, h, ⟨⟩⟩; exact h⟩
section
/-- The range of a linear map `f : M → M₂` is a submodule of `M₂`.
See Note [range copy pattern]. -/
def range [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : submodule R₂ M₂ :=
(map f ⊤).copy (set.range f) set.image_univ.symm
theorem range_coe [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
(range f : set M₂) = set.range f := rfl
lemma range_to_add_submonoid [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
f.range.to_add_submonoid = f.to_add_monoid_hom.mrange := rfl
@[simp] theorem mem_range [ring_hom_surjective τ₁₂]
{f : M →ₛₗ[τ₁₂] M₂} {x} : x ∈ range f ↔ ∃ y, f y = x :=
iff.rfl
lemma range_eq_map [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) : f.range = map f ⊤ :=
by { ext, simp }
theorem mem_range_self [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) (x : M) : f x ∈ f.range := ⟨x, rfl⟩
@[simp] theorem range_id : range (linear_map.id : M →ₗ[R] M) = ⊤ :=
set_like.coe_injective set.range_id
theorem range_comp [ring_hom_surjective τ₁₂] [ring_hom_surjective τ₂₃] [ring_hom_surjective τ₁₃]
(f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) :=
set_like.coe_injective (set.range_comp g f)
theorem range_comp_le_range [ring_hom_surjective τ₂₃] [ring_hom_surjective τ₁₃]
(f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g :=
set_like.coe_mono (set.range_comp_subset_range f g)
theorem range_eq_top [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} :
range f = ⊤ ↔ surjective f :=
by rw [set_like.ext'_iff, range_coe, top_coe, set.range_iff_surjective]
lemma range_le_iff_comap [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R₂ M₂} :
range f ≤ p ↔ comap f p = ⊤ :=
by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff]
lemma map_le_range [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R M} :
map f p ≤ range f :=
set_like.coe_mono (set.image_subset_range f p)
@[simp] lemma range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*}
[semiring R] [ring R₂] [add_comm_monoid M] [add_comm_group M₂] [module R M] [module R₂ M₂]
{τ₁₂ : R →+* R₂} [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
(-f).range = f.range :=
begin
change ((-linear_map.id : M₂ →ₗ[R₂] M₂).comp f).range = _,
rw [range_comp, submodule.map_neg, submodule.map_id],
end
end
/--
The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map.
-/
@[simps]
def iterate_range (f : M →ₗ[R] M) : ℕ →o (submodule R M)ᵒᵈ :=
⟨λ n, (f ^ n).range, λ n m w x h, begin
obtain ⟨c, rfl⟩ := le_iff_exists_add.mp w,
rw linear_map.mem_range at h,
obtain ⟨m, rfl⟩ := h,
rw linear_map.mem_range,
use (f ^ c) m,
rw [pow_add, linear_map.mul_apply],
end⟩
/-- Restrict the codomain of a linear map `f` to `f.range`.
This is the bundled version of `set.range_factorization`. -/
@[reducible] def range_restrict [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
M →ₛₗ[τ₁₂] f.range := f.cod_restrict f.range f.mem_range_self
/-- The range of a linear map is finite if the domain is finite.
Note: this instance can form a diamond with `subtype.fintype` in the
presence of `fintype M₂`. -/
instance fintype_range [fintype M] [decidable_eq M₂] [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) : fintype (range f) :=
set.fintype_range f
/-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the
set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/
def ker (f : M →ₛₗ[τ₁₂] M₂) : submodule R M := comap f ⊥
@[simp] theorem mem_ker {f : M →ₛₗ[τ₁₂] M₂} {y} : y ∈ ker f ↔ f y = 0 := mem_bot R₂
@[simp] theorem ker_id : ker (linear_map.id : M →ₗ[R] M) = ⊥ := rfl
@[simp] theorem map_coe_ker (f : M →ₛₗ[τ₁₂] M₂) (x : ker f) : f x = 0 := mem_ker.1 x.2
lemma ker_to_add_submonoid (f : M →ₛₗ[τ₁₂] M₂) :
f.ker.to_add_submonoid = f.to_add_monoid_hom.mker := rfl
lemma comp_ker_subtype (f : M →ₛₗ[τ₁₂] M₂) : f.comp f.ker.subtype = 0 :=
linear_map.ext $ λ x, suffices f x = 0, by simp [this], mem_ker.1 x.2
theorem ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = comap f (ker g) := rfl
theorem ker_le_ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
ker f ≤ ker (g.comp f : M →ₛₗ[τ₁₃] M₃) :=
by rw ker_comp; exact comap_mono bot_le
theorem disjoint_ker {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 :=
by simp [disjoint_def]
theorem ker_eq_bot' {f : M →ₛₗ[τ₁₂] M₂} :
ker f = ⊥ ↔ (∀ m, f m = 0 → m = 0) :=
by simpa [disjoint] using @disjoint_ker _ _ _ _ _ _ _ _ _ _ _ f ⊤
theorem ker_eq_bot_of_inverse {τ₂₁ : R₂ →+* R} [ring_hom_inv_pair τ₁₂ τ₂₁]
{f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₁] M} (h : (g.comp f : M →ₗ[R] M) = id) :
ker f = ⊥ :=
ker_eq_bot'.2 $ λ m hm, by rw [← id_apply m, ← h, comp_apply, hm, g.map_zero]
lemma le_ker_iff_map [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R M} :
p ≤ ker f ↔ map f p = ⊥ :=
by rw [ker, eq_bot_iff, map_le_iff_le_comap]
lemma ker_cod_restrict {τ₂₁ : R₂ →+* R} (p : submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) :
ker (cod_restrict p f hf) = ker f :=
by rw [ker, comap_cod_restrict, map_bot]; refl
lemma range_cod_restrict {τ₂₁ : R₂ →+* R} [ring_hom_surjective τ₂₁] (p : submodule R M)
(f : M₂ →ₛₗ[τ₂₁] M) (hf) :
range (cod_restrict p f hf) = comap p.subtype f.range :=
by simpa only [range_eq_map] using map_cod_restrict _ _ _ _
lemma ker_restrict {p : submodule R M} {f : M →ₗ[R] M} (hf : ∀ x : M, x ∈ p → f x ∈ p) :
ker (f.restrict hf) = (f.dom_restrict p).ker :=
by rw [restrict_eq_cod_restrict_dom_restrict, ker_cod_restrict]
lemma _root_.submodule.map_comap_eq [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) (q : submodule R₂ M₂) : map f (comap f q) = range f ⊓ q :=
le_antisymm (le_inf map_le_range (map_comap_le _ _)) $
by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩
lemma _root_.submodule.map_comap_eq_self [ring_hom_surjective τ₁₂]
{f : M →ₛₗ[τ₁₂] M₂} {q : submodule R₂ M₂} (h : q ≤ range f) : map f (comap f q) = q :=
by rwa [submodule.map_comap_eq, inf_eq_right]
@[simp] theorem ker_zero : ker (0 : M →ₛₗ[τ₁₂] M₂) = ⊤ :=
eq_top_iff'.2 $ λ x, by simp
@[simp] theorem range_zero [ring_hom_surjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ :=
by simpa only [range_eq_map] using submodule.map_zero _
theorem ker_eq_top {f : M →ₛₗ[τ₁₂] M₂} : ker f = ⊤ ↔ f = 0 :=
⟨λ h, ext $ λ x, mem_ker.1 $ h.symm ▸ trivial, λ h, h.symm ▸ ker_zero⟩
section
variables [ring_hom_surjective τ₁₂]
lemma range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 :=
by rw [range_le_iff_comap]; exact ker_eq_top
theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 :=
by rw [← range_le_bot_iff, le_bot_iff]
lemma range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} :
range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 :=
⟨λ h, ker_eq_top.1 $ eq_top_iff'.2 $ λ x, h $ ⟨_, rfl⟩,
λ h x hx, mem_ker.2 $ exists.elim hx $ λ y hy, by rw [←hy, ←comp_apply, h, zero_apply]⟩
theorem comap_le_comap_iff {f : M →ₛₗ[τ₁₂] M₂} (hf : range f = ⊤) {p p'} :
comap f p ≤ comap f p' ↔ p ≤ p' :=
⟨λ H x hx, by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩
theorem comap_injective {f : M →ₛₗ[τ₁₂] M₂} (hf : range f = ⊤) : injective (comap f) :=
λ p p' h, le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h))
((comap_le_comap_iff hf).1 (ge_of_eq h))
end
theorem ker_eq_bot_of_injective {f : M →ₛₗ[τ₁₂] M₂} (hf : injective f) : ker f = ⊥ :=
begin
have : disjoint ⊤ f.ker, by { rw [disjoint_ker, ← map_zero f], exact λ x hx H, hf H },
simpa [disjoint]
end
/--
The increasing sequence of submodules consisting of the kernels of the iterates of a linear map.
-/
@[simps]
def iterate_ker (f : M →ₗ[R] M) : ℕ →o submodule R M :=
⟨λ n, (f ^ n).ker, λ n m w x h, begin
obtain ⟨c, rfl⟩ := le_iff_exists_add.mp w,
rw linear_map.mem_ker at h,
rw [linear_map.mem_ker, add_comm, pow_add, linear_map.mul_apply, h, linear_map.map_zero],
end⟩
end add_comm_monoid
section ring
variables [ring R] [ring R₂] [ring R₃]
variables [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R₂ M₂] [module R₃ M₃]
variables {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple τ₁₂ τ₂₃ τ₁₃]
variables {f : M →ₛₗ[τ₁₂] M₂}
include R
open submodule
lemma range_to_add_subgroup [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
f.range.to_add_subgroup = f.to_add_monoid_hom.range := rfl
lemma ker_to_add_subgroup (f : M →ₛₗ[τ₁₂] M₂) :
f.ker.to_add_subgroup = f.to_add_monoid_hom.ker := rfl
theorem sub_mem_ker_iff {x y} : x - y ∈ f.ker ↔ f x = f y :=
by rw [mem_ker, map_sub, sub_eq_zero]
theorem disjoint_ker' {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x y ∈ p, f x = f y → x = y :=
disjoint_ker.trans
⟨λ H x hx y hy h, eq_of_sub_eq_zero $ H _ (sub_mem hx hy) (by simp [h]),
λ H x h₁ h₂, H x h₁ 0 (zero_mem _) (by simpa using h₂)⟩
theorem inj_of_disjoint_ker {p : submodule R M}
{s : set M} (h : s ⊆ p) (hd : disjoint p (ker f)) :
∀ x y ∈ s, f x = f y → x = y :=
λ x hx y hy, disjoint_ker'.1 hd _ (h hx) _ (h hy)
theorem ker_eq_bot : ker f = ⊥ ↔ injective f :=
by simpa [disjoint] using @disjoint_ker' _ _ _ _ _ _ _ _ _ _ _ f ⊤
lemma ker_le_iff [ring_hom_surjective τ₁₂] {p : submodule R M} :
ker f ≤ p ↔ ∃ (y ∈ range f), f ⁻¹' {y} ⊆ p :=
begin
split,
{ intros h, use 0, rw [← set_like.mem_coe, f.range_coe], exact ⟨⟨0, map_zero f⟩, h⟩, },
{ rintros ⟨y, h₁, h₂⟩,
rw set_like.le_def, intros z hz, simp only [mem_ker, set_like.mem_coe] at hz,
rw [← set_like.mem_coe, f.range_coe, set.mem_range] at h₁, obtain ⟨x, hx⟩ := h₁,
have hx' : x ∈ p, { exact h₂ hx, },
have hxz : z + x ∈ p, { apply h₂, simp [hx, hz], },
suffices : z + x - x ∈ p, { simpa only [this, add_sub_cancel], },
exact p.sub_mem hxz hx', },
end
end ring
section field
variables [field K] [field K₂]
variables [add_comm_group V] [module K V]
variables [add_comm_group V₂] [module K V₂]
lemma ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f :=
submodule.comap_smul f _ a h
lemma ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅(h : a ≠ 0), ker f :=
submodule.comap_smul' f _ a
lemma range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f :=
by simpa only [range_eq_map] using submodule.map_smul f _ a h
lemma range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆(h : a ≠ 0), range f :=
by simpa only [range_eq_map] using submodule.map_smul' f _ a
end field
end linear_map
namespace is_linear_map
lemma is_linear_map_add [semiring R] [add_comm_monoid M] [module R M] :
is_linear_map R (λ (x : M × M), x.1 + x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp, cc },
{ intros x y,
simp [smul_add] }
end
lemma is_linear_map_sub {R M : Type*} [semiring R] [add_comm_group M] [module R M]:
is_linear_map R (λ (x : M × M), x.1 - x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp [add_comm, add_left_comm, sub_eq_add_neg] },
{ intros x y,
simp [smul_sub] }
end
end is_linear_map
namespace submodule
section add_comm_monoid
variables [semiring R] [semiring R₂] [add_comm_monoid M] [add_comm_monoid M₂]
variables [module R M] [module R₂ M₂]
variables (p p' : submodule R M) (q : submodule R₂ M₂)
variables {τ₁₂ : R →+* R₂}
open linear_map
@[simp] theorem map_top [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : map f ⊤ = range f :=
f.range_eq_map.symm
@[simp] theorem comap_bot (f : M →ₛₗ[τ₁₂] M₂) : comap f ⊥ = ker f := rfl
@[simp] theorem ker_subtype : p.subtype.ker = ⊥ :=
ker_eq_bot_of_injective $ λ x y, subtype.ext_val
@[simp] theorem range_subtype : p.subtype.range = p :=
by simpa using map_comap_subtype p ⊤
lemma map_subtype_le (p' : submodule R p) : map p.subtype p' ≤ p :=
by simpa using (map_le_range : map p.subtype p' ≤ p.subtype.range)
/-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the
maximal submodule of `p` is just `p `. -/
@[simp] lemma map_subtype_top : map p.subtype (⊤ : submodule R p) = p :=
by simp
@[simp] lemma comap_subtype_eq_top {p p' : submodule R M} :
comap p.subtype p' = ⊤ ↔ p ≤ p' :=
eq_top_iff.trans $ map_le_iff_le_comap.symm.trans $ by rw [map_subtype_top]
@[simp] lemma comap_subtype_self : comap p.subtype p = ⊤ :=
comap_subtype_eq_top.2 le_rfl
@[simp] theorem ker_of_le (p p' : submodule R M) (h : p ≤ p') : (of_le h).ker = ⊥ :=
by rw [of_le, ker_cod_restrict, ker_subtype]
lemma range_of_le (p q : submodule R M) (h : p ≤ q) : (of_le h).range = comap q.subtype p :=
by rw [← map_top, of_le, linear_map.map_cod_restrict, map_top, range_subtype]
@[simp] lemma map_subtype_range_of_le {p p' : submodule R M} (h : p ≤ p') :
map p'.subtype (of_le h).range = p :=
by simp [range_of_le, map_comap_eq, h]
lemma disjoint_iff_comap_eq_bot {p q : submodule R M} :
disjoint p q ↔ comap p.subtype q = ⊥ :=
by rw [←(map_injective_of_injective (show injective p.subtype, from subtype.coe_injective)).eq_iff,
map_comap_subtype, map_bot, disjoint_iff]
/-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N` -/
def map_subtype.rel_iso : submodule R p ≃o {p' : submodule R M // p' ≤ p} :=
{ to_fun := λ p', ⟨map p.subtype p', map_subtype_le p _⟩,
inv_fun := λ q, comap p.subtype q,
left_inv := λ p', comap_map_eq_of_injective subtype.coe_injective p',
right_inv := λ ⟨q, hq⟩, subtype.ext_val $ by simp [map_comap_subtype p, inf_of_le_right hq],
map_rel_iff' := λ p₁ p₂, subtype.coe_le_coe.symm.trans begin
dsimp,
rw [map_le_iff_le_comap,
comap_map_eq_of_injective (show injective p.subtype, from subtype.coe_injective) p₂],
end }
/-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of
submodules of `M`. -/
def map_subtype.order_embedding : submodule R p ↪o submodule R M :=
(rel_iso.to_rel_embedding $ map_subtype.rel_iso p).trans (subtype.rel_embedding _ _)
@[simp] lemma map_subtype_embedding_eq (p' : submodule R p) :
map_subtype.order_embedding p p' = map p.subtype p' := rfl
end add_comm_monoid
end submodule
namespace linear_map
section semiring
variables [semiring R] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [module R M] [module R₂ M₂] [module R₃ M₃]
variables {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple τ₁₂ τ₂₃ τ₁₃]
/-- A monomorphism is injective. -/
lemma ker_eq_bot_of_cancel {f : M →ₛₗ[τ₁₂] M₂}
(h : ∀ (u v : f.ker →ₗ[R] M), f.comp u = f.comp v → u = v) : f.ker = ⊥ :=
begin
have h₁ : f.comp (0 : f.ker →ₗ[R] M) = 0 := comp_zero _,
rw [←submodule.range_subtype f.ker, ←h 0 f.ker.subtype (eq.trans h₁ (comp_ker_subtype f).symm)],
exact range_zero
end
lemma range_comp_of_range_eq_top [ring_hom_surjective τ₁₂] [ring_hom_surjective τ₂₃]
[ring_hom_surjective τ₁₃]
{f : M →ₛₗ[τ₁₂] M₂} (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : range f = ⊤) :
range (g.comp f : M →ₛₗ[τ₁₃] M₃) = range g :=
by rw [range_comp, hf, submodule.map_top]
lemma ker_comp_of_ker_eq_bot (f : M →ₛₗ[τ₁₂] M₂) {g : M₂ →ₛₗ[τ₂₃] M₃}
(hg : ker g = ⊥) : ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = ker f :=
by rw [ker_comp, hg, submodule.comap_bot]
section image
/-- If `O` is a submodule of `M`, and `Φ : O →ₗ M'` is a linear map,
then `(ϕ : O →ₗ M').submodule_image N` is `ϕ(N)` as a submodule of `M'` -/
def submodule_image {M' : Type*} [add_comm_monoid M'] [module R M']
{O : submodule R M} (ϕ : O →ₗ[R] M') (N : submodule R M) : submodule R M' :=
(N.comap O.subtype).map ϕ
@[simp] lemma mem_submodule_image {M' : Type*} [add_comm_monoid M'] [module R M']
{O : submodule R M} {ϕ : O →ₗ[R] M'} {N : submodule R M} {x : M'} :
x ∈ ϕ.submodule_image N ↔ ∃ y (yO : y ∈ O) (yN : y ∈ N), ϕ ⟨y, yO⟩ = x :=
begin
refine submodule.mem_map.trans ⟨_, _⟩; simp_rw submodule.mem_comap,
{ rintro ⟨⟨y, yO⟩, (yN : y ∈ N), h⟩,
exact ⟨y, yO, yN, h⟩ },
{ rintro ⟨y, yO, yN, h⟩,
exact ⟨⟨y, yO⟩, yN, h⟩ }
end
lemma mem_submodule_image_of_le {M' : Type*} [add_comm_monoid M'] [module R M']
{O : submodule R M} {ϕ : O →ₗ[R] M'} {N : submodule R M} (hNO : N ≤ O) {x : M'} :
x ∈ ϕ.submodule_image N ↔ ∃ y (yN : y ∈ N), ϕ ⟨y, hNO yN⟩ = x :=
begin
refine mem_submodule_image.trans ⟨_, _⟩,
{ rintro ⟨y, yO, yN, h⟩,
exact ⟨y, yN, h⟩ },
{ rintro ⟨y, yN, h⟩,
exact ⟨y, hNO yN, yN, h⟩ }
end
lemma submodule_image_apply_of_le {M' : Type*} [add_comm_group M'] [module R M']
{O : submodule R M} (ϕ : O →ₗ[R] M') (N : submodule R M) (hNO : N ≤ O) :
ϕ.submodule_image N = (ϕ.comp (submodule.of_le hNO)).range :=
by rw [submodule_image, range_comp, submodule.range_of_le]
end image
end semiring
end linear_map
@[simp] lemma linear_map.range_range_restrict [semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
[module R M] [module R M₂] (f : M →ₗ[R] M₂) :
f.range_restrict.range = ⊤ :=
by simp [f.range_cod_restrict _]
/-! ### Linear equivalences -/
namespace linear_equiv
section add_comm_monoid
section subsingleton
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables [module R M] [module R₂ M₂]
variables [subsingleton M] [subsingleton M₂]
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
include σ₂₁
/-- Between two zero modules, the zero map is an equivalence. -/
instance : has_zero (M ≃ₛₗ[σ₁₂] M₂) :=
⟨{ to_fun := 0,
inv_fun := 0,
right_inv := λ x, subsingleton.elim _ _,
left_inv := λ x, subsingleton.elim _ _,
..(0 : M →ₛₗ[σ₁₂] M₂)}⟩
omit σ₂₁
-- Even though these are implied by `subsingleton.elim` via the `unique` instance below, they're
-- nice to have as `rfl`-lemmas for `dsimp`.
include σ₂₁
@[simp] lemma zero_symm : (0 : M ≃ₛₗ[σ₁₂] M₂).symm = 0 := rfl
@[simp] lemma coe_zero : ⇑(0 : M ≃ₛₗ[σ₁₂] M₂) = 0 := rfl
lemma zero_apply (x : M) : (0 : M ≃ₛₗ[σ₁₂] M₂) x = 0 := rfl
/-- Between two zero modules, the zero map is the only equivalence. -/
instance : unique (M ≃ₛₗ[σ₁₂] M₂) :=
{ uniq := λ f, to_linear_map_injective (subsingleton.elim _ _),
default := 0 }
omit σ₂₁
end subsingleton
section
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables {module_M : module R M} {module_M₂ : module R₂ M₂}
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variables {re₁₂ : ring_hom_inv_pair σ₁₂ σ₂₁} {re₂₁ : ring_hom_inv_pair σ₂₁ σ₁₂}
variables (e e' : M ≃ₛₗ[σ₁₂] M₂)
lemma map_eq_comap {p : submodule R M} :
(p.map (e : M →ₛₗ[σ₁₂] M₂) : submodule R₂ M₂) = p.comap (e.symm : M₂ →ₛₗ[σ₂₁] M) :=
set_like.coe_injective $ by simp [e.image_eq_preimage]
/-- A linear equivalence of two modules restricts to a linear equivalence from any submodule
`p` of the domain onto the image of that submodule.
This is the linear version of `add_equiv.submonoid_map` and `add_equiv.subgroup_map`.
This is `linear_equiv.of_submodule'` but with `map` on the right instead of `comap` on the left. -/
def submodule_map (p : submodule R M) :
p ≃ₛₗ[σ₁₂] ↥(p.map (e : M →ₛₗ[σ₁₂] M₂) : submodule R₂ M₂) :=
{ inv_fun := λ y, ⟨(e.symm : M₂ →ₛₗ[σ₂₁] M) y, by
{ rcases y with ⟨y', hy⟩, rw submodule.mem_map at hy, rcases hy with ⟨x, hx, hxy⟩, subst hxy,
simp only [symm_apply_apply, submodule.coe_mk, coe_coe, hx], }⟩,
left_inv := λ x, by simp only [linear_map.dom_restrict_apply, linear_map.cod_restrict_apply,
linear_map.to_fun_eq_coe, linear_equiv.coe_coe, linear_equiv.symm_apply_apply, set_like.eta],
right_inv := λ y, by { apply set_coe.ext, simp only [linear_map.dom_restrict_apply,
linear_map.cod_restrict_apply, linear_map.to_fun_eq_coe, linear_equiv.coe_coe, set_like.coe_mk,
linear_equiv.apply_symm_apply] },
..((e : M →ₛₗ[σ₁₂] M₂).dom_restrict p).cod_restrict (p.map (e : M →ₛₗ[σ₁₂] M₂))
(λ x, ⟨x, by simp only [linear_map.dom_restrict_apply, eq_self_iff_true, and_true,
set_like.coe_mem, set_like.mem_coe]⟩) }
include σ₂₁
@[simp] lemma submodule_map_apply (p : submodule R M) (x : p) :
↑(e.submodule_map p x) = e x := rfl
@[simp] lemma submodule_map_symm_apply (p : submodule R M)
(x : (p.map (e : M →ₛₗ[σ₁₂] M₂) : submodule R₂ M₂)) :
↑((e.submodule_map p).symm x) = e.symm x :=
rfl
omit σ₂₁
end
section finsupp
variables {γ : Type*}
variables [semiring R] [semiring R₂]
variables [add_comm_monoid M] [add_comm_monoid M₂]
variables [module R M] [module R₂ M₂] [has_zero γ]
variables {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair τ₁₂ τ₂₁] [ring_hom_inv_pair τ₂₁ τ₁₂]
include τ₂₁
@[simp] lemma map_finsupp_sum (f : M ≃ₛₗ[τ₁₂] M₂) {t : ι →₀ γ} {g : ι → γ → M} :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum _
omit τ₂₁
end finsupp
section dfinsupp
open dfinsupp
variables [semiring R] [semiring R₂]
variables [add_comm_monoid M] [add_comm_monoid M₂]
variables [module R M] [module R₂ M₂]
variables {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair τ₁₂ τ₂₁] [ring_hom_inv_pair τ₂₁ τ₁₂]
variables {γ : ι → Type*} [decidable_eq ι]
include τ₂₁
@[simp] lemma map_dfinsupp_sum [Π i, has_zero (γ i)] [Π i (x : γ i), decidable (x ≠ 0)]
(f : M ≃ₛₗ[τ₁₂] M₂) (t : Π₀ i, γ i) (g : Π i, γ i → M) :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum _
@[simp] lemma map_dfinsupp_sum_add_hom [Π i, add_zero_class (γ i)] (f : M ≃ₛₗ[τ₁₂] M₂)
(t : Π₀ i, γ i) (g : Π i, γ i →+ M) :
f (sum_add_hom g t) = sum_add_hom (λ i, f.to_add_equiv.to_add_monoid_hom.comp (g i)) t :=
f.to_add_equiv.map_dfinsupp_sum_add_hom _ _
end dfinsupp
section uncurry
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables (V V₂ R)
/-- Linear equivalence between a curried and uncurried function.
Differs from `tensor_product.curry`. -/
protected def curry :
(V × V₂ → R) ≃ₗ[R] (V → V₂ → R) :=
{ map_add' := λ _ _, by { ext, refl },
map_smul' := λ _ _, by { ext, refl },
.. equiv.curry _ _ _ }
@[simp] lemma coe_curry : ⇑(linear_equiv.curry R V V₂) = curry := rfl
@[simp] lemma coe_curry_symm : ⇑(linear_equiv.curry R V V₂).symm = uncurry := rfl
end uncurry
section
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables {module_M : module R M} {module_M₂ : module R₂ M₂} {module_M₃ : module R₃ M₃}
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variables {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables {σ₃₂ : R₃ →+* R₂}
variables {re₁₂ : ring_hom_inv_pair σ₁₂ σ₂₁} {re₂₁ : ring_hom_inv_pair σ₂₁ σ₁₂}
variables {re₂₃ : ring_hom_inv_pair σ₂₃ σ₃₂} {re₃₂ : ring_hom_inv_pair σ₃₂ σ₂₃}
variables (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₁] M) (e : M ≃ₛₗ[σ₁₂] M₂) (h : M₂ →ₛₗ[σ₂₃] M₃)
variables (e'' : M₂ ≃ₛₗ[σ₂₃] M₃)
variables (p q : submodule R M)
/-- Linear equivalence between two equal submodules. -/
def of_eq (h : p = q) : p ≃ₗ[R] q :=
{ map_smul' := λ _ _, rfl, map_add' := λ _ _, rfl, .. equiv.set.of_eq (congr_arg _ h) }
variables {p q}
@[simp] lemma coe_of_eq_apply (h : p = q) (x : p) : (of_eq p q h x : M) = x := rfl
@[simp] lemma of_eq_symm (h : p = q) : (of_eq p q h).symm = of_eq q p h.symm := rfl
include σ₂₁
/-- A linear equivalence which maps a submodule of one module onto another, restricts to a linear
equivalence of the two submodules. -/
def of_submodules (p : submodule R M) (q : submodule R₂ M₂) (h : p.map (e : M →ₛₗ[σ₁₂] M₂) = q) :
p ≃ₛₗ[σ₁₂] q := (e.submodule_map p).trans (linear_equiv.of_eq _ _ h)
@[simp] lemma of_submodules_apply {p : submodule R M} {q : submodule R₂ M₂}
(h : p.map ↑e = q) (x : p) : ↑(e.of_submodules p q h x) = e x := rfl
@[simp] lemma of_submodules_symm_apply {p : submodule R M} {q : submodule R₂ M₂}
(h : p.map ↑e = q) (x : q) : ↑((e.of_submodules p q h).symm x) = e.symm x := rfl
include re₁₂ re₂₁
/-- A linear equivalence of two modules restricts to a linear equivalence from the preimage of any
submodule to that submodule.
This is `linear_equiv.of_submodule` but with `comap` on the left instead of `map` on the right. -/
def of_submodule' [module R M] [module R₂ M₂] (f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) :
U.comap (f : M →ₛₗ[σ₁₂] M₂) ≃ₛₗ[σ₁₂] U :=
(f.symm.of_submodules _ _ f.symm.map_eq_comap).symm
lemma of_submodule'_to_linear_map [module R M] [module R₂ M₂]
(f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) :
(f.of_submodule' U).to_linear_map =
(f.to_linear_map.dom_restrict _).cod_restrict _ subtype.prop :=
by { ext, refl }
@[simp]
lemma of_submodule'_apply [module R M] [module R₂ M₂]
(f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) (x : U.comap (f : M →ₛₗ[σ₁₂] M₂)) :
(f.of_submodule' U x : M₂) = f (x : M) := rfl
@[simp]
lemma of_submodule'_symm_apply [module R M] [module R₂ M₂]
(f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) (x : U) :
((f.of_submodule' U).symm x : M) = f.symm (x : M₂) := rfl
variable (p)
omit σ₂₁ re₁₂ re₂₁
/-- The top submodule of `M` is linearly equivalent to `M`. -/
def of_top (h : p = ⊤) : p ≃ₗ[R] M :=
{ inv_fun := λ x, ⟨x, h.symm ▸ trivial⟩,
left_inv := λ ⟨x, h⟩, rfl,
right_inv := λ x, rfl,
.. p.subtype }
@[simp] theorem of_top_apply {h} (x : p) : of_top p h x = x := rfl
@[simp] theorem coe_of_top_symm_apply {h} (x : M) : ((of_top p h).symm x : M) = x := rfl
theorem of_top_symm_apply {h} (x : M) : (of_top p h).symm x = ⟨x, h.symm ▸ trivial⟩ := rfl
include σ₂₁ re₁₂ re₂₁
/-- If a linear map has an inverse, it is a linear equivalence. -/
def of_linear (h₁ : f.comp g = linear_map.id) (h₂ : g.comp f = linear_map.id) :
M ≃ₛₗ[σ₁₂] M₂ :=
{ inv_fun := g,
left_inv := linear_map.ext_iff.1 h₂,
right_inv := linear_map.ext_iff.1 h₁,
..f }
omit σ₂₁ re₁₂ re₂₁
include σ₂₁ re₁₂ re₂₁
@[simp] theorem of_linear_apply {h₁ h₂} (x : M) : of_linear f g h₁ h₂ x = f x := rfl
omit σ₂₁ re₁₂ re₂₁
include σ₂₁ re₁₂ re₂₁
@[simp] theorem of_linear_symm_apply {h₁ h₂} (x : M₂) : (of_linear f g h₁ h₂).symm x = g x :=
rfl
omit σ₂₁ re₁₂ re₂₁
@[simp] protected theorem range : (e : M →ₛₗ[σ₁₂] M₂).range = ⊤ :=
linear_map.range_eq_top.2 e.to_equiv.surjective
include σ₂₁ re₁₂ re₂₁
lemma eq_bot_of_equiv [module R₂ M₂] (e : p ≃ₛₗ[σ₁₂] (⊥ : submodule R₂ M₂)) : p = ⊥ :=
begin
refine bot_unique (set_like.le_def.2 $ assume b hb, (submodule.mem_bot R).2 _),
rw [← p.mk_eq_zero hb, ← e.map_eq_zero_iff],
apply submodule.eq_zero_of_bot_submodule
end
omit σ₂₁ re₁₂ re₂₁
@[simp] protected theorem ker : (e : M →ₛₗ[σ₁₂] M₂).ker = ⊥ :=
linear_map.ker_eq_bot_of_injective e.to_equiv.injective
@[simp] theorem range_comp [ring_hom_surjective σ₁₂] [ring_hom_surjective σ₂₃]
[ring_hom_surjective σ₁₃] :
(h.comp (e : M →ₛₗ[σ₁₂] M₂) : M →ₛₗ[σ₁₃] M₃).range = h.range :=
linear_map.range_comp_of_range_eq_top _ e.range
include module_M
@[simp] theorem ker_comp (l : M →ₛₗ[σ₁₂] M₂) :
(((e'' : M₂ →ₛₗ[σ₂₃] M₃).comp l : M →ₛₗ[σ₁₃] M₃) : M →ₛₗ[σ₁₃] M₃).ker = l.ker :=
linear_map.ker_comp_of_ker_eq_bot _ e''.ker
omit module_M
variables {f g}
include σ₂₁
/-- An linear map `f : M →ₗ[R] M₂` with a left-inverse `g : M₂ →ₗ[R] M` defines a linear
equivalence between `M` and `f.range`.
This is a computable alternative to `linear_equiv.of_injective`, and a bidirectional version of
`linear_map.range_restrict`. -/
def of_left_inverse [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{g : M₂ → M} (h : function.left_inverse g f) : M ≃ₛₗ[σ₁₂] f.range :=
{ to_fun := f.range_restrict,
inv_fun := g ∘ f.range.subtype,
left_inv := h,
right_inv := λ x, subtype.ext $
let ⟨x', hx'⟩ := linear_map.mem_range.mp x.prop in
show f (g x) = x, by rw [←hx', h x'],
.. f.range_restrict }
omit σ₂₁
@[simp] lemma of_left_inverse_apply [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
(h : function.left_inverse g f) (x : M) :
↑(of_left_inverse h x) = f x := rfl
include σ₂₁
@[simp] lemma of_left_inverse_symm_apply [ring_hom_inv_pair σ₁₂ σ₂₁]
[ring_hom_inv_pair σ₂₁ σ₁₂] (h : function.left_inverse g f) (x : f.range) :
(of_left_inverse h).symm x = g x := rfl
omit σ₂₁
variables (f)
/-- An `injective` linear map `f : M →ₗ[R] M₂` defines a linear equivalence
between `M` and `f.range`. See also `linear_map.of_left_inverse`. -/
noncomputable def of_injective [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
(h : injective f) : M ≃ₛₗ[σ₁₂] f.range :=
of_left_inverse $ classical.some_spec h.has_left_inverse
@[simp] theorem of_injective_apply [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{h : injective f} (x : M) : ↑(of_injective f h x) = f x := rfl
/-- A bijective linear map is a linear equivalence. -/
noncomputable def of_bijective [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
(hf₁ : injective f) (hf₂ : surjective f) : M ≃ₛₗ[σ₁₂] M₂ :=
(of_injective f hf₁).trans (of_top _ $ linear_map.range_eq_top.2 hf₂)
@[simp] theorem of_bijective_apply [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{hf₁ hf₂} (x : M) : of_bijective f hf₁ hf₂ x = f x := rfl
end
end add_comm_monoid
section add_comm_group
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄]
variables {module_M : module R M} {module_M₂ : module R₂ M₂}
variables {module_M₃ : module R₃ M₃} {module_M₄ : module R₄ M₄}
variables {σ₁₂ : R →+* R₂} {σ₃₄ : R₃ →+* R₄}
variables {σ₂₁ : R₂ →+* R} {σ₄₃ : R₄ →+* R₃}
variables {re₁₂ : ring_hom_inv_pair σ₁₂ σ₂₁} {re₂₁ : ring_hom_inv_pair σ₂₁ σ₁₂}
variables {re₃₄ : ring_hom_inv_pair σ₃₄ σ₄₃} {re₄₃ : ring_hom_inv_pair σ₄₃ σ₃₄}
variables (e e₁ : M ≃ₛₗ[σ₁₂] M₂) (e₂ : M₃ ≃ₛₗ[σ₃₄] M₄)
@[simp] theorem map_neg (a : M) : e (-a) = -e a := e.to_linear_map.map_neg a
@[simp] theorem map_sub (a b : M) : e (a - b) = e a - e b :=
e.to_linear_map.map_sub a b
end add_comm_group
section neg
variables (R) [semiring R] [add_comm_group M] [module R M]
/-- `x ↦ -x` as a `linear_equiv` -/
def neg : M ≃ₗ[R] M := { .. equiv.neg M, .. (-linear_map.id : M →ₗ[R] M) }
variable {R}
@[simp] lemma coe_neg : ⇑(neg R : M ≃ₗ[R] M) = -id := rfl
lemma neg_apply (x : M) : neg R x = -x := by simp
@[simp] lemma symm_neg : (neg R : M ≃ₗ[R] M).symm = neg R := rfl
end neg
section comm_semiring
variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [module R M] [module R M₂] [module R M₃]
open _root_.linear_map
/-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/
def smul_of_unit (a : Rˣ) : M ≃ₗ[R] M :=
distrib_mul_action.to_linear_equiv R M a
/-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a
linear isomorphism between the two function spaces. -/
def arrow_congr {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_semiring R]
[add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₂₁] [add_comm_monoid M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) :
(M₁ →ₗ[R] M₂₁) ≃ₗ[R] (M₂ →ₗ[R] M₂₂) :=
{ to_fun := λ f : M₁ →ₗ[R] M₂₁, (e₂ : M₂₁ →ₗ[R] M₂₂).comp $ f.comp (e₁.symm : M₂ →ₗ[R] M₁),
inv_fun := λ f, (e₂.symm : M₂₂ →ₗ[R] M₂₁).comp $ f.comp (e₁ : M₁ →ₗ[R] M₂),
left_inv := λ f, by { ext x, simp only [symm_apply_apply, comp_app, coe_comp, coe_coe]},
right_inv := λ f, by { ext x, simp only [comp_app, apply_symm_apply, coe_comp, coe_coe]},
map_add' := λ f g, by { ext x, simp only [map_add, add_apply, comp_app, coe_comp, coe_coe]},
map_smul' := λ c f, by { ext x, simp only [smul_apply, comp_app, coe_comp, map_smulₛₗ e₂,
coe_coe]} }
@[simp] lemma arrow_congr_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_semiring R]
[add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₂₁] [add_comm_monoid M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₁ →ₗ[R] M₂₁) (x : M₂) :
arrow_congr e₁ e₂ f x = e₂ (f (e₁.symm x)) :=
rfl
@[simp] lemma arrow_congr_symm_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_semiring R]
[add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₂₁] [add_comm_monoid M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₂ →ₗ[R] M₂₂) (x : M₁) :
(arrow_congr e₁ e₂).symm f x = e₂.symm (f (e₁ x)) :=
rfl
lemma arrow_congr_comp {N N₂ N₃ : Sort*}
[add_comm_monoid N] [add_comm_monoid N₂] [add_comm_monoid N₃]
[module R N] [module R N₂] [module R N₃]
(e₁ : M ≃ₗ[R] N) (e₂ : M₂ ≃ₗ[R] N₂) (e₃ : M₃ ≃ₗ[R] N₃) (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) :
arrow_congr e₁ e₃ (g.comp f) = (arrow_congr e₂ e₃ g).comp (arrow_congr e₁ e₂ f) :=
by { ext, simp only [symm_apply_apply, arrow_congr_apply, linear_map.comp_apply], }
lemma arrow_congr_trans {M₁ M₂ M₃ N₁ N₂ N₃ : Sort*}
[add_comm_monoid M₁] [module R M₁] [add_comm_monoid M₂] [module R M₂]
[add_comm_monoid M₃] [module R M₃] [add_comm_monoid N₁] [module R N₁]
[add_comm_monoid N₂] [module R N₂] [add_comm_monoid N₃] [module R N₃]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : N₁ ≃ₗ[R] N₂) (e₃ : M₂ ≃ₗ[R] M₃) (e₄ : N₂ ≃ₗ[R] N₃) :
(arrow_congr e₁ e₂).trans (arrow_congr e₃ e₄) = arrow_congr (e₁.trans e₃) (e₂.trans e₄) :=
rfl
/-- If `M₂` and `M₃` are linearly isomorphic then the two spaces of linear maps from `M` into `M₂`
and `M` into `M₃` are linearly isomorphic. -/
def congr_right (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ[R] (M →ₗ[R] M₃) :=
arrow_congr (linear_equiv.refl R M) f
/-- If `M` and `M₂` are linearly isomorphic then the two spaces of linear maps from `M` and `M₂` to
themselves are linearly isomorphic. -/
def conj (e : M ≃ₗ[R] M₂) : (module.End R M) ≃ₗ[R] (module.End R M₂) := arrow_congr e e
lemma conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M) :
e.conj f = ((↑e : M →ₗ[R] M₂).comp f).comp (e.symm : M₂ →ₗ[R] M) := rfl
lemma symm_conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M₂) :
e.symm.conj f = ((↑e.symm : M₂ →ₗ[R] M).comp f).comp (e : M →ₗ[R] M₂) := rfl
lemma conj_comp (e : M ≃ₗ[R] M₂) (f g : module.End R M) :
e.conj (g.comp f) = (e.conj g).comp (e.conj f) :=
arrow_congr_comp e e e f g
lemma conj_trans (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃) :
e₁.conj.trans e₂.conj = (e₁.trans e₂).conj :=
by { ext f x, refl, }
@[simp] lemma conj_id (e : M ≃ₗ[R] M₂) : e.conj linear_map.id = linear_map.id :=
by { ext, simp [conj_apply], }
end comm_semiring
section field
variables [field K] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module K M] [module K M₂] [module K M₃]
variables (K) (M)
open _root_.linear_map
/-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/
@[simps] def smul_of_ne_zero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M :=
smul_of_unit $ units.mk0 a ha
end field
end linear_equiv
namespace submodule
section module
variables [semiring R] [add_comm_monoid M] [module R M]
/-- Given `p` a submodule of the module `M` and `q` a submodule of `p`, `p.equiv_subtype_map q`
is the natural `linear_equiv` between `q` and `q.map p.subtype`. -/
def equiv_subtype_map (p : submodule R M) (q : submodule R p) :
q ≃ₗ[R] q.map p.subtype :=
{ inv_fun :=
begin
rintro ⟨x, hx⟩,
refine ⟨⟨x, _⟩, _⟩;
rcases hx with ⟨⟨_, h⟩, _, rfl⟩;
assumption
end,
left_inv := λ ⟨⟨_, _⟩, _⟩, rfl,
right_inv := λ ⟨x, ⟨_, h⟩, _, rfl⟩, rfl,
.. (p.subtype.dom_restrict q).cod_restrict _
begin
rintro ⟨x, hx⟩,
refine ⟨x, hx, rfl⟩,
end }
@[simp]
lemma equiv_subtype_map_apply {p : submodule R M} {q : submodule R p} (x : q) :
(p.equiv_subtype_map q x : M) = p.subtype.dom_restrict q x :=
rfl
@[simp]
lemma equiv_subtype_map_symm_apply {p : submodule R M} {q : submodule R p} (x : q.map p.subtype) :
((p.equiv_subtype_map q).symm x : M) = x :=
by { cases x, refl }
/-- If `s ≤ t`, then we can view `s` as a submodule of `t` by taking the comap
of `t.subtype`. -/
@[simps]
def comap_subtype_equiv_of_le {p q : submodule R M} (hpq : p ≤ q) :
comap q.subtype p ≃ₗ[R] p :=
{ to_fun := λ x, ⟨x, x.2⟩,
inv_fun := λ x, ⟨⟨x, hpq x.2⟩, x.2⟩,
left_inv := λ x, by simp only [coe_mk, set_like.eta, coe_coe],
right_inv := λ x, by simp only [subtype.coe_mk, set_like.eta, coe_coe],
map_add' := λ x y, rfl,
map_smul' := λ c x, rfl }
end module
end submodule
namespace submodule
variables [comm_semiring R] [comm_semiring R₂]
variables [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module R₂ M₂]
variables [add_comm_monoid N] [add_comm_monoid N₂] [module R N] [module R N₂]
variables {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair τ₁₂ τ₂₁] [ring_hom_inv_pair τ₂₁ τ₁₂]
variables (p : submodule R M) (q : submodule R₂ M₂)
variables (pₗ : submodule R N) (qₗ : submodule R N₂)
include τ₂₁
@[simp] lemma mem_map_equiv {e : M ≃ₛₗ[τ₁₂] M₂} {x : M₂} : x ∈ p.map (e : M →ₛₗ[τ₁₂] M₂) ↔
e.symm x ∈ p :=
begin
rw submodule.mem_map, split,
{ rintros ⟨y, hy, hx⟩, simp [←hx, hy], },
{ intros hx, refine ⟨e.symm x, hx, by simp⟩, },
end
omit τ₂₁
lemma map_equiv_eq_comap_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : submodule R M) :
K.map (e : M →ₛₗ[τ₁₂] M₂) = K.comap (e.symm : M₂ →ₛₗ[τ₂₁] M) :=
submodule.ext (λ _, by rw [mem_map_equiv, mem_comap, linear_equiv.coe_coe])
lemma comap_equiv_eq_map_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : submodule R₂ M₂) :
K.comap (e : M →ₛₗ[τ₁₂] M₂) = K.map (e.symm : M₂ →ₛₗ[τ₂₁] M) :=
(map_equiv_eq_comap_symm e.symm K).symm
lemma comap_le_comap_smul (fₗ : N →ₗ[R] N₂) (c : R) :
comap fₗ qₗ ≤ comap (c • fₗ) qₗ :=
begin
rw set_like.le_def,
intros m h,
change c • (fₗ m) ∈ qₗ,
change fₗ m ∈ qₗ at h,
apply qₗ.smul_mem _ h,
end
lemma inf_comap_le_comap_add (f₁ f₂ : M →ₛₗ[τ₁₂] M₂) :
comap f₁ q ⊓ comap f₂ q ≤ comap (f₁ + f₂) q :=
begin
rw set_like.le_def,
intros m h,
change f₁ m + f₂ m ∈ q,
change f₁ m ∈ q ∧ f₂ m ∈ q at h,
apply q.add_mem h.1 h.2,
end
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatible_maps : submodule R (N →ₗ[R] N₂) :=
{ carrier := {fₗ | pₗ ≤ comap fₗ qₗ},
zero_mem' := by { change pₗ ≤ comap 0 qₗ, rw comap_zero, refine le_top, },
add_mem' := λ f₁ f₂ h₁ h₂, by { apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂),
rw le_inf_iff, exact ⟨h₁, h₂⟩, },
smul_mem' := λ c fₗ h, le_trans h (comap_le_comap_smul qₗ fₗ c), }
end submodule
namespace equiv
variables [semiring R] [add_comm_monoid M] [module R M] [add_comm_monoid M₂] [module R M₂]
/-- An equivalence whose underlying function is linear is a linear equivalence. -/
def to_linear_equiv (e : M ≃ M₂) (h : is_linear_map R (e : M → M₂)) : M ≃ₗ[R] M₂ :=
{ .. e, .. h.mk' e}
end equiv
section fun_left
variables (R M) [semiring R] [add_comm_monoid M] [module R M]
variables {m n p : Type*}
namespace linear_map
/-- Given an `R`-module `M` and a function `m → n` between arbitrary types,
construct a linear map `(n → M) →ₗ[R] (m → M)` -/
def fun_left (f : m → n) : (n → M) →ₗ[R] (m → M) :=
{ to_fun := (∘ f), map_add' := λ _ _, rfl, map_smul' := λ _ _, rfl }
@[simp] theorem fun_left_apply (f : m → n) (g : n → M) (i : m) : fun_left R M f g i = g (f i) :=
rfl
@[simp] theorem fun_left_id (g : n → M) : fun_left R M _root_.id g = g :=
rfl
theorem fun_left_comp (f₁ : n → p) (f₂ : m → n) :
fun_left R M (f₁ ∘ f₂) = (fun_left R M f₂).comp (fun_left R M f₁) :=
rfl
theorem fun_left_surjective_of_injective (f : m → n) (hf : injective f) :
surjective (fun_left R M f) :=
begin
classical,
intro g,
refine ⟨λ x, if h : ∃ y, f y = x then g h.some else 0, _⟩,
{ ext,
dsimp only [fun_left_apply],
split_ifs with w,
{ congr,
exact hf w.some_spec, },
{ simpa only [not_true, exists_apply_eq_apply] using w } },
end
theorem fun_left_injective_of_surjective (f : m → n) (hf : surjective f) :
injective (fun_left R M f) :=
begin
obtain ⟨g, hg⟩ := hf.has_right_inverse,
suffices : left_inverse (fun_left R M g) (fun_left R M f),
{ exact this.injective },
intro x,
rw [←linear_map.comp_apply, ← fun_left_comp, hg.id, fun_left_id],
end
end linear_map
namespace linear_equiv
open _root_.linear_map
/-- Given an `R`-module `M` and an equivalence `m ≃ n` between arbitrary types,
construct a linear equivalence `(n → M) ≃ₗ[R] (m → M)` -/
def fun_congr_left (e : m ≃ n) : (n → M) ≃ₗ[R] (m → M) :=
linear_equiv.of_linear (fun_left R M e) (fun_left R M e.symm)
(linear_map.ext $ λ x, funext $ λ i,
by rw [id_apply, ← fun_left_comp, equiv.symm_comp_self, fun_left_id])
(linear_map.ext $ λ x, funext $ λ i,
by rw [id_apply, ← fun_left_comp, equiv.self_comp_symm, fun_left_id])
@[simp] theorem fun_congr_left_apply (e : m ≃ n) (x : n → M) :
fun_congr_left R M e x = fun_left R M e x :=
rfl
@[simp] theorem fun_congr_left_id :
fun_congr_left R M (equiv.refl n) = linear_equiv.refl R (n → M) :=
rfl
@[simp] theorem fun_congr_left_comp (e₁ : m ≃ n) (e₂ : n ≃ p) :
fun_congr_left R M (equiv.trans e₁ e₂) =
linear_equiv.trans (fun_congr_left R M e₂) (fun_congr_left R M e₁) :=
rfl
@[simp] lemma fun_congr_left_symm (e : m ≃ n) :
(fun_congr_left R M e).symm = fun_congr_left R M e.symm :=
rfl
end linear_equiv
end fun_left
namespace linear_map
variables [semiring R] [add_comm_monoid M] [module R M]
variables (R M)
/-- The group of invertible linear maps from `M` to itself -/
@[reducible] def general_linear_group := (M →ₗ[R] M)ˣ
namespace general_linear_group
variables {R M}
instance : has_coe_to_fun (general_linear_group R M) (λ _, M → M) := by apply_instance
/-- An invertible linear map `f` determines an equivalence from `M` to itself. -/
def to_linear_equiv (f : general_linear_group R M) : (M ≃ₗ[R] M) :=
{ inv_fun := f.inv.to_fun,
left_inv := λ m, show (f.inv * f.val) m = m,
by erw f.inv_val; simp,
right_inv := λ m, show (f.val * f.inv) m = m,
by erw f.val_inv; simp,
..f.val }
/-- An equivalence from `M` to itself determines an invertible linear map. -/
def of_linear_equiv (f : (M ≃ₗ[R] M)) : general_linear_group R M :=
{ val := f,
inv := (f.symm : M →ₗ[R] M),
val_inv := linear_map.ext $ λ _, f.apply_symm_apply _,
inv_val := linear_map.ext $ λ _, f.symm_apply_apply _ }
variables (R M)
/-- The general linear group on `R` and `M` is multiplicatively equivalent to the type of linear
equivalences between `M` and itself. -/
def general_linear_equiv : general_linear_group R M ≃* (M ≃ₗ[R] M) :=
{ to_fun := to_linear_equiv,
inv_fun := of_linear_equiv,
left_inv := λ f, by { ext, refl },
right_inv := λ f, by { ext, refl },
map_mul' := λ x y, by {ext, refl} }
@[simp] lemma general_linear_equiv_to_linear_map (f : general_linear_group R M) :
(general_linear_equiv R M f : M →ₗ[R] M) = f :=
by {ext, refl}
@[simp] lemma coe_fn_general_linear_equiv (f : general_linear_group R M) :
⇑(general_linear_equiv R M f) = (f : M → M) :=
rfl
end general_linear_group
end linear_map
|
5ff730660f4904a1efe3cbc63ff74cc50986a472 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch4/ex0302.lean | 868a0805b21b7d8e083842d916739e7c94436ad7 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 316 | lean | variables (a b c d e : ℕ)
variable h1 : a = b
variable h2 : b = c + 1
variable h3 : c = d
variable h4 : e = 1 + d
include h1 h2 h3 h4
theorem T : a = e :=
calc
a = b : by rw h1
... = c + 1 : by rw h2
... = d + 1 : by rw h3
... = 1 + d : by rw add_comm
... = e : by rw h4
|
2fec5eae11f482ae2a012790937e5bc7c1632f8b | f4bff2062c030df03d65e8b69c88f79b63a359d8 | /src/game/order/level04.lean | d76304f781d3166270bf0f39c0b3c0d0c1a4f8c5 | [
"Apache-2.0"
] | permissive | adastra7470/real-number-game | 776606961f52db0eb824555ed2f8e16f92216ea3 | f9dcb7d9255a79b57e62038228a23346c2dc301b | refs/heads/master | 1,669,221,575,893 | 1,594,669,800,000 | 1,594,669,800,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 825 | lean | import game.order.level03
namespace xena -- hide
/-
# Chapter 2 : Order
## Level 4
This level invites you to work out a property of the absolute value.
In Lean the absolute value of $x$ is denoted by `abs x`.
For ease of use, a notation can be used around that definition as below.
Feel free to use the triangle inequality on the real numbers,
`abs_add : ∀ (a b : ?M_1), |a + b| ≤ |a| + |b|`
together with the `linarith` and `norm_num` tactics.
-/
notation `|` x `|` := abs x
/- Lemma
For any two real numbers $a$ and $b$, we have that
$$| a - b| ≤ |a| + |b|$$.
-/
theorem abs_sub_le_sum_abs (a b : ℝ) : |a - b| ≤ |a| + |b| :=
begin
have H : a - b = a + (-b), linarith,
rw H,
have G := abs_add a (-b),
have F : abs (-b) = abs b, norm_num,
rw F at G, exact G, done
end
end xena --hide
|
3fedbb9338068f6de61d4d3b5ad3a88ee623156e | 618003631150032a5676f229d13a079ac875ff77 | /src/data/list/tfae.lean | e32f1ab4ad1dd55e7d1d1ec6d3bb702fffb8a817 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 1,842 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Simon Hudon
-/
import data.list.basic
namespace list
/- tfae: The Following (propositions) Are Equivalent -/
def tfae (l : list Prop) : Prop := ∀ x ∈ l, ∀ y ∈ l, x ↔ y
theorem tfae_nil : tfae [] := forall_mem_nil _
theorem tfae_singleton (p) : tfae [p] := by simp [tfae, -eq_iff_iff]
theorem tfae_cons_of_mem {a b} {l : list Prop} (h : b ∈ l) :
tfae (a::l) ↔ (a ↔ b) ∧ tfae l :=
⟨λ H, ⟨H a (by simp) b (or.inr h), λ p hp q hq, H _ (or.inr hp) _ (or.inr hq)⟩,
begin
rintro ⟨ab, H⟩ p (rfl | hp) q (rfl | hq),
{ refl },
{ exact ab.trans (H _ h _ hq) },
{ exact (ab.trans (H _ h _ hp)).symm },
{ exact H _ hp _ hq }
end⟩
theorem tfae_cons_cons {a b} {l : list Prop} : tfae (a::b::l) ↔ (a ↔ b) ∧ tfae (b::l) :=
tfae_cons_of_mem (or.inl rfl)
theorem tfae_of_forall (b : Prop) (l : list Prop) (h : ∀ a ∈ l, a ↔ b) : tfae l :=
λ a₁ h₁ a₂ h₂, (h _ h₁).trans (h _ h₂).symm
theorem tfae_of_cycle {a b} {l : list Prop} :
list.chain (→) a (b::l) → (ilast' b l → a) → tfae (a::b::l) :=
begin
induction l with c l IH generalizing a b;
simp only [tfae_cons_cons, tfae_singleton, and_true, chain_cons, chain.nil] at *,
{ intros a b, exact iff.intro a b },
rintros ⟨ab,⟨bc,ch⟩⟩ la,
have := IH ⟨bc,ch⟩ (ab ∘ la),
exact ⟨⟨ab, la ∘ (this.2 c (or.inl rfl) _ (ilast'_mem _ _)).1 ∘ bc⟩, this⟩
end
theorem tfae.out {l} (h : tfae l) (n₁ n₂)
(h₁ : n₁ < list.length l . tactic.exact_dec_trivial)
(h₂ : n₂ < list.length l . tactic.exact_dec_trivial) :
list.nth_le l n₁ h₁ ↔ list.nth_le l n₂ h₂ :=
h _ (list.nth_le_mem _ _ _) _ (list.nth_le_mem _ _ _)
end list
|
3b9fe655d6b31879b4155f26c8f2b262ee628005 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/goal.lean | f9ed94d74b7215b79cd4c8e1e6979bf3f75e92f1 | [
"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 | 113 | lean | import logic
open tactic
theorem T {a b c d : Prop} (H : a) (H : b) (H : c) (H : d) : a
:= by state; assumption
|
c63cfeec72b3082457a971a8093c1038e9ab9b1a | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/algebra/order.lean | 399aa491d641356d640f08acd4138393d6fd293c | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 18,094 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Weak orders "≤", strict orders "<", and structures that include both.
-/
import logic.eq logic.connectives algebra.binary algebra.priority
open eq function
variables {A : Type}
/- weak orders -/
structure weak_order [class] (A : Type) extends has_le A :=
(le_refl : ∀a, le a a)
(le_trans : ∀a b c, le a b → le b c → le a c)
(le_antisymm : ∀a b, le a b → le b a → a = b)
section
variables [weak_order A]
attribute [refl]
theorem le.refl (a : A) : a ≤ a := weak_order.le_refl a
theorem le_of_eq {a b : A} (H : a = b) : a ≤ b := H ▸ le.refl a
attribute [trans]
theorem le.trans {a b c : A} : a ≤ b → b ≤ c → a ≤ c := weak_order.le_trans a b c
attribute [trans]
theorem ge.trans {a b c : A} (H1 : a ≥ b) (H2: b ≥ c) : a ≥ c := le.trans H2 H1
theorem le.antisymm {a b : A} : a ≤ b → b ≤ a → a = b := weak_order.le_antisymm a b
-- Alternate syntax. (Abbreviations do not migrate well.)
theorem eq_of_le_of_ge {a b : A} : a ≤ b → b ≤ a → a = b := le.antisymm
end
structure linear_weak_order [class] (A : Type) extends weak_order A :=
(le_total : ∀a b, le a b ∨ le b a)
section
variables [linear_weak_order A]
theorem le.total (a b : A) : a ≤ b ∨ b ≤ a := linear_weak_order.le_total a b
theorem le_of_not_ge {a b : A} (H : ¬ a ≥ b) : a ≤ b := or.resolve_left (le.total b a) H
end
/- strict orders -/
structure strict_order [class] (A : Type) extends has_lt A :=
(lt_irrefl : ∀a, ¬ lt a a)
(lt_trans : ∀a b c, lt a b → lt b c → lt a c)
section
variable [strict_order A]
theorem lt.irrefl (a : A) : ¬ a < a := strict_order.lt_irrefl a
theorem not_lt_self (a : A) : ¬ a < a := lt.irrefl a -- alternate syntax
theorem lt_self_iff_false (a : A) : a < a ↔ false :=
iff_false_intro (lt.irrefl a)
attribute [trans]
theorem lt.trans {a b c : A} : a < b → b < c → a < c := strict_order.lt_trans a b c
attribute [trans]
theorem gt.trans {a b c : A} (H1 : a > b) (H2: b > c) : a > c := lt.trans H2 H1
theorem ne_of_lt {a b : A} (lt_ab : a < b) : a ≠ b :=
assume eq_ab : a = b,
show false, from lt.irrefl b (eq_ab ▸ lt_ab)
theorem ne_of_gt {a b : A} (gt_ab : a > b) : a ≠ b :=
ne.symm (ne_of_lt gt_ab)
theorem lt.asymm {a b : A} (H : a < b) : ¬ b < a :=
assume H1 : b < a, lt.irrefl _ (lt.trans H H1)
theorem not_lt_of_gt {a b : A} (H : a > b) : ¬ a < b := lt.asymm H -- alternate syntax
end
/- well-founded orders -/
structure wf_strict_order [class] (A : Type) extends strict_order A :=
(wf_rec : ∀P : A → Type, (∀x, (∀y, lt y x → P y) → P x) → ∀x, P x)
definition wf.rec_on {A : Type} [s : wf_strict_order A] {P : A → Type}
(x : A) (H : ∀x, (∀y, wf_strict_order.lt y x → P y) → P x) : P x :=
wf_strict_order.wf_rec P H x
theorem wf.ind_on.{u v} {A : Type.{u}} [s : wf_strict_order.{u 0} A] {P : A → Prop}
(x : A) (H : ∀x, (∀y, wf_strict_order.lt y x → P y) → P x) : P x :=
wf.rec_on x H
/- structures with a weak and a strict order -/
structure order_pair [class] (A : Type) extends weak_order A, has_lt A :=
(le_of_lt : ∀ a b, lt a b → le a b)
(lt_of_lt_of_le : ∀ a b c, lt a b → le b c → lt a c)
(lt_of_le_of_lt : ∀ a b c, le a b → lt b c → lt a c)
(lt_irrefl : ∀ a, ¬ lt a a)
section
variable [s : order_pair A]
variables {a b c : A}
include s
theorem le_of_lt : a < b → a ≤ b := order_pair.le_of_lt a b
attribute [trans]
theorem lt_of_lt_of_le : a < b → b ≤ c → a < c := order_pair.lt_of_lt_of_le a b c
attribute [trans]
theorem lt_of_le_of_lt : a ≤ b → b < c → a < c := order_pair.lt_of_le_of_lt a b c
private theorem lt_irrefl (s' : order_pair A) (a : A) : ¬ a < a := order_pair.lt_irrefl a
private theorem lt_trans (s' : order_pair A) (a b c: A) (lt_ab : a < b) (lt_bc : b < c) : a < c :=
lt_of_lt_of_le lt_ab (le_of_lt lt_bc)
attribute [instance]
definition order_pair.to_strict_order : strict_order A :=
⦃ strict_order, s, lt_irrefl := lt_irrefl s, lt_trans := lt_trans s ⦄
attribute [trans]
theorem gt_of_gt_of_ge (H1 : a > b) (H2 : b ≥ c) : a > c := lt_of_le_of_lt H2 H1
attribute [trans]
theorem gt_of_ge_of_gt (H1 : a ≥ b) (H2 : b > c) : a > c := lt_of_lt_of_le H2 H1
theorem not_le_of_gt (H : a > b) : ¬ a ≤ b :=
assume H1 : a ≤ b,
lt.irrefl _ (lt_of_lt_of_le H H1)
theorem not_lt_of_ge (H : a ≥ b) : ¬ a < b :=
assume H1 : a < b,
lt.irrefl _ (lt_of_le_of_lt H H1)
end
structure strong_order_pair [class] (A : Type) extends weak_order A, has_lt A :=
(le_iff_lt_or_eq : ∀a b, le a b ↔ lt a b ∨ a = b)
(lt_irrefl : ∀ a, ¬ lt a a)
section strong_order_pair
variable [strong_order_pair A]
theorem le_iff_lt_or_eq {a b : A} : a ≤ b ↔ a < b ∨ a = b :=
strong_order_pair.le_iff_lt_or_eq a b
theorem lt_or_eq_of_le {a b : A} (le_ab : a ≤ b) : a < b ∨ a = b :=
iff.mp le_iff_lt_or_eq le_ab
theorem le_of_lt_or_eq {a b : A} (lt_or_eq : a < b ∨ a = b) : a ≤ b :=
iff.mpr le_iff_lt_or_eq lt_or_eq
private theorem lt_irrefl' (a : A) : ¬ a < a :=
strong_order_pair.lt_irrefl a
private theorem le_of_lt' (a b : A) : a < b → a ≤ b :=
take Hlt, le_of_lt_or_eq (or.inl Hlt)
private theorem lt_iff_le_and_ne {a b : A} : a < b ↔ (a ≤ b ∧ a ≠ b) :=
iff.intro
(take Hlt, and.intro (le_of_lt_or_eq (or.inl Hlt)) (take Hab, absurd (Hab ▸ Hlt) (lt_irrefl' b)))
(take Hand,
have Hor : a < b ∨ a = b, from lt_or_eq_of_le (and.left Hand),
or_resolve_left Hor (and.right Hand))
theorem lt_of_le_of_ne {a b : A} : a ≤ b → a ≠ b → a < b :=
take H1 H2, iff.mpr lt_iff_le_and_ne (and.intro H1 H2)
private theorem ne_of_lt' {a b : A} (H : a < b) : a ≠ b :=
and.right ((iff.mp lt_iff_le_and_ne) H)
private theorem lt_of_lt_of_le' (a b c : A) : a < b → b ≤ c → a < c :=
assume lt_ab : a < b,
assume le_bc : b ≤ c,
have le_ac : a ≤ c, from le.trans (le_of_lt' _ _ lt_ab) le_bc,
have ne_ac : a ≠ c, from
assume eq_ac : a = c,
have le_ba : b ≤ a, from symm eq_ac ▸ le_bc,
have eq_ab : a = b, from le.antisymm (le_of_lt' _ _ lt_ab) le_ba,
show false, from ne_of_lt' lt_ab eq_ab,
show a < c, from iff.mpr (lt_iff_le_and_ne) (and.intro le_ac ne_ac)
theorem lt_of_le_of_lt' (a b c : A) : a ≤ b → b < c → a < c :=
assume le_ab : a ≤ b,
assume lt_bc : b < c,
have le_ac : a ≤ c, from le.trans le_ab (le_of_lt' _ _ lt_bc),
have ne_ac : a ≠ c, from
assume eq_ac : a = c,
have le_cb : c ≤ b, from eq_ac ▸ le_ab,
have eq_bc : b = c, from le.antisymm (le_of_lt' _ _ lt_bc) le_cb,
show false, from ne_of_lt' lt_bc eq_bc,
show a < c, from iff.mpr (lt_iff_le_and_ne) (and.intro le_ac ne_ac)
end strong_order_pair
attribute [instance]
definition strong_order_pair.to_order_pair
[s : strong_order_pair A] : order_pair A :=
⦃ order_pair, s,
lt_irrefl := lt_irrefl',
le_of_lt := le_of_lt',
lt_of_le_of_lt := lt_of_le_of_lt',
lt_of_lt_of_le := lt_of_lt_of_le' ⦄
/- linear orders -/
structure linear_order_pair [class] (A : Type) extends order_pair A, linear_weak_order A
structure linear_strong_order_pair [class] (A : Type) extends strong_order_pair A,
linear_weak_order A
attribute [instance]
definition linear_strong_order_pair.to_linear_order_pair
[s : linear_strong_order_pair A] : linear_order_pair A :=
⦃ linear_order_pair, s, strong_order_pair.to_order_pair ⦄
section
variable [linear_strong_order_pair A]
variables (a b c : A)
theorem lt.trichotomy : a < b ∨ a = b ∨ b < a :=
or.elim (le.total a b)
(assume H : a ≤ b,
or.elim (iff.mp le_iff_lt_or_eq H) (assume H1, or.inl H1) (assume H1, or.inr (or.inl H1)))
(assume H : b ≤ a,
or.elim (iff.mp le_iff_lt_or_eq H)
(assume H1, or.inr (or.inr H1))
(assume H1, or.inr (or.inl (symm H1))))
theorem lt.by_cases {a b : A} {P : Prop}
(H1 : a < b → P) (H2 : a = b → P) (H3 : b < a → P) : P :=
or.elim (lt.trichotomy a b)
(assume H, H1 H)
(assume H, or.elim H (assume H', H2 H') (assume H', H3 H'))
definition lt_ge_by_cases {a b : A} {P : Prop} (H1 : a < b → P) (H2 : a ≥ b → P) : P :=
lt.by_cases H1 (λH, H2 (H ▸ le.refl a)) (λH, H2 (le_of_lt H))
theorem le_of_not_gt {a b : A} (H : ¬ a > b) : a ≤ b :=
lt.by_cases (assume H', absurd H' H) (assume H', H' ▸ (le.refl b)) (assume H', le_of_lt H')
theorem lt_of_not_ge {a b : A} (H : ¬ a ≥ b) : a < b :=
lt.by_cases
(assume H', absurd (le_of_lt H') H)
(assume H', absurd (H' ▸ le.refl b) H)
(assume H', H')
theorem lt_or_ge : a < b ∨ a ≥ b :=
lt.by_cases
(assume H1 : a < b, or.inl H1)
(assume H1 : a = b, or.inr (H1 ▸ le.refl a))
(assume H1 : a > b, or.inr (le_of_lt H1))
theorem le_or_gt : a ≤ b ∨ a > b :=
or.swap (lt_or_ge b a)
theorem lt_or_gt_of_ne {a b : A} (H : a ≠ b) : a < b ∨ a > b :=
lt.by_cases (assume H1, or.inl H1) (assume H1, absurd H1 H) (assume H1, or.inr H1)
end
open decidable
structure decidable_linear_order [class] (A : Type) extends linear_strong_order_pair A :=
(decidable_lt : decidable_rel lt)
section
variable [s : decidable_linear_order A]
variables {a b c d : A}
include s
open decidable
attribute [instance]
definition decidable_lt : decidable (a < b) :=
@decidable_linear_order.decidable_lt _ _ _ _
attribute [instance]
definition decidable_le : decidable (a ≤ b) :=
by_cases
(assume H : a < b, tt (le_of_lt H))
(assume H : ¬ a < b,
have H1 : b ≤ a, from le_of_not_gt H,
by_cases
(assume H2 : b < a, ff (not_le_of_gt H2))
(assume H2 : ¬ b < a, tt (le_of_not_gt H2)))
attribute [instance]
definition has_decidable_eq : decidable (a = b) :=
by_cases
(assume H : a ≤ b,
by_cases
(assume H1 : b ≤ a, tt (le.antisymm H H1))
(assume H1 : ¬ b ≤ a, ff (assume H2 : a = b, H1 (H2 ▸ le.refl a))))
(assume H : ¬ a ≤ b,
(ff (assume H1 : a = b, H (H1 ▸ le.refl a))))
theorem eq_or_lt_of_not_lt {a b : A} (H : ¬ a < b) : a = b ∨ b < a :=
if Heq : a = b then or.inl Heq else or.inr (lt_of_not_ge (λ Hge, H (lt_of_le_of_ne Hge Heq)))
theorem eq_or_lt_of_le {a b : A} (H : a ≤ b) : a = b ∨ a < b :=
sorry
/-
begin
cases eq_or_lt_of_not_lt (not_lt_of_ge H),
exact or.inl a_1⁻¹,
exact or.inr a_1
end
-/
-- testing equality first may result in more definitional equalities
definition lt.cases {B : Type} (a b : A) (t_lt t_eq t_gt : B) : B :=
if a = b then t_eq else (if a < b then t_lt else t_gt)
theorem lt.cases_of_eq {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a = b) :
lt.cases a b t_lt t_eq t_gt = t_eq := if_pos H
theorem lt.cases_of_lt {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a < b) :
lt.cases a b t_lt t_eq t_gt = t_lt :=
trans (if_neg (ne_of_lt H)) (if_pos H)
theorem lt.cases_of_gt {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a > b) :
lt.cases a b t_lt t_eq t_gt = t_gt :=
trans (if_neg (ne.symm (ne_of_lt H))) (if_neg (lt.asymm H))
definition min (a b : A) : A := if a ≤ b then a else b
definition max (a b : A) : A := if a ≤ b then b else a
/- these show min and max form a lattice -/
theorem min_le_left (a b : A) : min a b ≤ a :=
sorry
/-
by_cases
(assume H : a ≤ b, by rewrite [↑min, if_pos H])
(assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply le_of_lt (lt_of_not_ge H))
-/
theorem min_le_right (a b : A) : min a b ≤ b :=
sorry
/-
by_cases
(assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply H)
(assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H])
-/
theorem le_min {a b c : A} (H₁ : c ≤ a) (H₂ : c ≤ b) : c ≤ min a b :=
sorry
/-
by_cases
(assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply H₁)
(assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply H₂)
-/
theorem le_max_left (a b : A) : a ≤ max a b :=
sorry
/-
by_cases
(assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply H)
(assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H])
-/
theorem le_max_right (a b : A) : b ≤ max a b :=
sorry
/-
by_cases
(assume H : a ≤ b, by rewrite [↑max, if_pos H])
(assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply le_of_lt (lt_of_not_ge H))
-/
theorem max_le {a b c : A} (H₁ : a ≤ c) (H₂ : b ≤ c) : max a b ≤ c :=
sorry
/-
by_cases
(assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply H₂)
(assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply H₁)
-/
theorem le_max_left_iff_true (a b : A) : a ≤ max a b ↔ true :=
iff_true_intro (le_max_left a b)
theorem le_max_right_iff_true (a b : A) : b ≤ max a b ↔ true :=
iff_true_intro (le_max_right a b)
/- these are also proved for lattices, but with inf and sup in place of min and max -/
theorem eq_min {a b c : A} (H₁ : c ≤ a) (H₂ : c ≤ b) (H₃ : ∀{d}, d ≤ a → d ≤ b → d ≤ c) :
c = min a b :=
le.antisymm (le_min H₁ H₂) (H₃ (min_le_left a b) (min_le_right a b))
theorem min.comm (a b : A) : min a b = min b a :=
eq_min (min_le_right a b) (min_le_left a b) (λ c H₁ H₂, le_min H₂ H₁)
theorem min.assoc (a b c : A) : min (min a b) c = min a (min b c) :=
sorry
/-
begin
apply eq_min,
{ apply le.trans, apply min_le_left, apply min_le_left },
{ apply le_min, apply le.trans, apply min_le_left, apply min_le_right, apply min_le_right },
{ intros [d, H₁, H₂], apply le_min, apply le_min H₁, apply le.trans H₂, apply min_le_left,
apply le.trans H₂, apply min_le_right }
end
-/
theorem min.left_comm (a b c : A) : min a (min b c) = min b (min a c) :=
binary.left_comm (@min.comm A s) (@min.assoc A s) a b c
theorem min.right_comm (a b c : A) : min (min a b) c = min (min a c) b :=
binary.right_comm (@min.comm A s) (@min.assoc A s) a b c
theorem min_self (a : A) : min a a = a :=
sorry -- by apply eq.symm; apply eq_min (le.refl a) !le.refl; intros; assumption
theorem min_eq_left {a b : A} (H : a ≤ b) : min a b = a :=
sorry -- by apply eq.symm; apply eq_min !le.refl H; intros; assumption
theorem min_eq_right {a b : A} (H : b ≤ a) : min a b = b :=
eq.subst (min.comm b a) (min_eq_left H)
theorem eq_max {a b c : A} (H₁ : a ≤ c) (H₂ : b ≤ c) (H₃ : ∀{d}, a ≤ d → b ≤ d → c ≤ d) :
c = max a b :=
le.antisymm (H₃ (le_max_left a b) (le_max_right a b)) (max_le H₁ H₂)
theorem max.comm (a b : A) : max a b = max b a :=
eq_max (le_max_right a b) (le_max_left a b) (λ c H₁ H₂, max_le H₂ H₁)
theorem max.assoc (a b c : A) : max (max a b) c = max a (max b c) :=
sorry
/-
begin
apply eq_max,
{ apply le.trans, apply le_max_left a b, apply le_max_left },
{ apply max_le, apply le.trans, apply le_max_right a b, apply le_max_left, apply le_max_right },
{ intros [d, H₁, H₂], apply max_le, apply max_le H₁, apply le.trans !le_max_left H₂,
apply le.trans !le_max_right H₂}
end
-/
theorem max.left_comm (a b c : A) : max a (max b c) = max b (max a c) :=
binary.left_comm (@max.comm A s) (@max.assoc A s) a b c
theorem max.right_comm (a b c : A) : max (max a b) c = max (max a c) b :=
binary.right_comm (@max.comm A s) (@max.assoc A s) a b c
theorem max_self (a : A) : max a a = a :=
sorry -- by apply eq.symm; apply eq_max (le.refl a) !le.refl; intros; assumption
theorem max_eq_left {a b : A} (H : b ≤ a) : max a b = a :=
sorry -- by apply eq.symm; apply eq_max !le.refl H; intros; assumption
theorem max_eq_right {a b : A} (H : a ≤ b) : max a b = b :=
eq.subst (max.comm b a) (max_eq_left H)
/- these rely on lt_of_lt -/
theorem min_eq_left_of_lt {a b : A} (H : a < b) : min a b = a :=
min_eq_left (le_of_lt H)
theorem min_eq_right_of_lt {a b : A} (H : b < a) : min a b = b :=
min_eq_right (le_of_lt H)
theorem max_eq_left_of_lt {a b : A} (H : b < a) : max a b = a :=
max_eq_left (le_of_lt H)
theorem max_eq_right_of_lt {a b : A} (H : a < b) : max a b = b :=
max_eq_right (le_of_lt H)
/- these use the fact that it is a linear ordering -/
theorem lt_min {a b c : A} (H₁ : a < b) (H₂ : a < c) : a < min b c :=
sorry
/-
or.elim !le_or_gt
(assume H : b ≤ c, by rewrite (min_eq_left H); apply H₁)
(assume H : b > c, by rewrite (min_eq_right_of_lt H); apply H₂)
-/
theorem max_lt {a b c : A} (H₁ : a < c) (H₂ : b < c) : max a b < c :=
sorry
/-
or.elim !le_or_gt
(assume H : a ≤ b, by rewrite (max_eq_right H); apply H₂)
(assume H : a > b, by rewrite (max_eq_left_of_lt H); apply H₁)
-/
end
/- order instances -/
attribute [instance]
definition weak_order_Prop : weak_order Prop :=
⦃ weak_order,
le := λx y, x → y,
le_refl := λx, id,
le_trans := λa b c H1 H2 x, H2 (H1 x),
le_antisymm := λf g H1 H2, propext (and.intro H1 H2)
⦄
attribute [instance]
definition weak_order_fun (A B : Type) [weak_order B] : weak_order (A → B) :=
⦃ weak_order,
le := λx y, ∀b, x b ≤ y b,
le_refl := λf b, le.refl (f b),
le_trans := λf g h H1 H2 b, le.trans (H1 b) (H2 b),
le_antisymm := λf g H1 H2, funext (λb, le.antisymm (H1 b) (H2 b))
⦄
definition weak_order_dual {A : Type} (wo : weak_order A) : weak_order A :=
⦃ weak_order,
le := λx y, y ≤ x,
le_refl := le.refl,
le_trans := sorry, -- take a b c `b ≤ a` `c ≤ b`, le.trans `c ≤ b` `b ≤ a`,
le_antisymm := sorry ⦄ -- take a b `b ≤ a` `a ≤ b`, le.antisymm `a ≤ b` `b ≤ a` ⦄
lemma le_dual_eq_le {A : Type} (wo : weak_order A) (a b : A) :
@le _ (@weak_order.to_has_le _ (weak_order_dual wo)) a b =
@le _ (@weak_order.to_has_le _ wo) b a :=
rfl
-- what to do with the strict variants?
|
36e902bddb5e8f6fbb0e44dda96e5b97b46c7a8f | 6214e13b31733dc9aeb4833db6a6466005763162 | /src/qiaux.lean | 08b8960c1fad2991cc877c70abfe76b5530c9227 | [] | no_license | joshua0pang/esverify-theory | 272a250445f3aeea49a7e72d1ab58c2da6618bbe | 8565b123c87b0113f83553d7732cd6696c9b5807 | refs/heads/master | 1,585,873,849,081 | 1,527,304,393,000 | 1,527,304,393,000 | 154,901,199 | 1 | 0 | null | 1,540,593,067,000 | 1,540,593,067,000 | null | UTF-8 | Lean | false | false | 12,338 | lean | -- auxilliary definitions and lemmas used for termination of QI
import .definitions1
def prop.num_quantifiers: prop → ℕ
| (prop.term t) := 0
| (prop.not P) := P.num_quantifiers
| (prop.and P₁ P₂) := P₁.num_quantifiers + P₂.num_quantifiers
| (prop.or P₁ P₂) := P₁.num_quantifiers + P₂.num_quantifiers
| (prop.pre t₁ t₂) := 0
| (prop.pre₁ op t) := 0
| (prop.pre₂ op t₁ t₂) := 0
| (prop.post t₁ t₂) := 0
| (prop.call t) := 0
| (prop.forallc x P) := 1 + P.num_quantifiers
| (prop.exis x P) := 1 + P.num_quantifiers
lemma same_num_quantifiers_after_substt {P: prop} {x y: var}:
P.num_quantifiers = (P.substt x y).num_quantifiers :=
begin
induction P,
case prop.term t {
unfold prop.substt,
change (
prop.num_quantifiers (prop.term t) =
prop.num_quantifiers (prop.term (term.substt x y t))
),
unfold prop.num_quantifiers
},
case prop.not P₁ ih {
unfold prop.substt,
unfold prop.num_quantifiers,
from ih
},
case prop.and P₁ P₂ P₁_ih P₂_ih {
unfold prop.substt,
change (
prop.num_quantifiers (prop.and P₁ P₂) =
prop.num_quantifiers (prop.and (prop.substt x y P₁) (prop.substt x y P₂))
),
unfold prop.num_quantifiers,
rw[P₁_ih],
rw[P₂_ih]
},
case prop.or P₁ P₂ P₁_ih P₂_ih {
unfold prop.substt,
change (
prop.num_quantifiers (prop.or P₁ P₂) =
prop.num_quantifiers (prop.or (prop.substt x y P₁) (prop.substt x y P₂))
),
unfold prop.num_quantifiers,
rw[P₁_ih],
rw[P₂_ih]
},
case prop.pre t₁ t₂ {
unfold prop.substt,
unfold prop.num_quantifiers
},
case prop.pre₁ op t {
unfold prop.substt,
unfold prop.num_quantifiers
},
case prop.pre₂ op t₁ t₂ {
unfold prop.substt,
unfold prop.num_quantifiers
},
case prop.call t {
unfold prop.substt,
unfold prop.num_quantifiers
},
case prop.post t₁ t₂ {
unfold prop.substt,
unfold prop.num_quantifiers
},
case prop.forallc y P₁ P₁_ih {
unfold prop.substt,
by_cases (x = y) with h,
simp[h],
simp[h],
unfold prop.num_quantifiers,
apply eq_add_left_of_eq,
from P₁_ih
},
case prop.exis y P' P'_ih {
unfold prop.substt,
by_cases (x = y) with h,
simp[h],
simp[h],
unfold prop.num_quantifiers,
apply eq_add_left_of_eq,
from P'_ih
}
end
lemma lifted_prop_smaller {P: prop} {x: var}:
∀P', ((P.lift_p x = some P') → (P'.num_quantifiers < P.num_quantifiers)) ∧
((P.lift_n x = some P') → (P'.num_quantifiers < P.num_quantifiers)) :=
begin
induction P,
case prop.term t {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
contradiction,
assume h1,
unfold prop.lift_n at h1,
contradiction
},
case prop.not P₁ ih {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
cases h2: prop.lift_n P₁ x,
simp[h2] at h1,
cases h1,
have h3, from (ih a).right h2,
simp[h2] at h1,
cases h1,
unfold prop.num_quantifiers,
from h3,
assume h1,
unfold prop.lift_n at h1,
cases h2: prop.lift_p P₁ x,
simp[h2] at h1,
cases h1,
have h3, from (ih a).left h2,
simp[h2] at h1,
cases h1,
unfold prop.num_quantifiers,
from h3
},
case prop.and P₁ P₂ P₁_ih P₂_ih {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
cases h2: prop.lift_p P₁ x,
simp[h2] at h1,
cases h3: prop.lift_p P₂ x,
simp[h3] at h1,
cases h1,
simp[h3] at h1,
cases h1,
have h3, from (P₂_ih a).left h3,
unfold prop.num_quantifiers,
apply nat.add_lt_add_left,
from h3,
simp[h2] at h1,
cases h1,
unfold prop.num_quantifiers,
apply nat.add_lt_add_right,
from (P₁_ih a).left h2,
assume h1,
unfold prop.lift_n at h1,
cases h2: prop.lift_n P₁ x,
simp[h2] at h1,
cases h3: prop.lift_n P₂ x,
simp[h3] at h1,
cases h1,
simp[h3] at h1,
cases h1,
have h3, from (P₂_ih a).right h3,
unfold prop.num_quantifiers,
apply nat.add_lt_add_left,
from h3,
simp[h2] at h1,
cases h1,
unfold prop.num_quantifiers,
apply nat.add_lt_add_right,
from (P₁_ih a).right h2
},
case prop.or P₁ P₂ P₁_ih P₂_ih {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
cases h2: prop.lift_p P₁ x,
simp[h2] at h1,
cases h3: prop.lift_p P₂ x,
simp[h3] at h1,
cases h1,
simp[h3] at h1,
cases h1,
have h3, from (P₂_ih a).left h3,
unfold prop.num_quantifiers,
apply nat.add_lt_add_left,
from h3,
simp[h2] at h1,
cases h1,
unfold prop.num_quantifiers,
apply nat.add_lt_add_right,
from (P₁_ih a).left h2,
assume h1,
unfold prop.lift_n at h1,
cases h2: prop.lift_n P₁ x,
simp[h2] at h1,
cases h3: prop.lift_n P₂ x,
simp[h3] at h1,
cases h1,
simp[h3] at h1,
cases h1,
have h3, from (P₂_ih a).right h3,
unfold prop.num_quantifiers,
apply nat.add_lt_add_left,
from h3,
simp[h2] at h1,
cases h1,
unfold prop.num_quantifiers,
apply nat.add_lt_add_right,
from (P₁_ih a).right h2
},
case prop.pre t₁ t₂ {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
contradiction,
assume h1,
unfold prop.lift_n at h1,
contradiction
},
case prop.pre₁ op t {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
contradiction,
assume h1,
unfold prop.lift_n at h1,
contradiction
},
case prop.pre₂ op t₁ t₂ {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
contradiction,
assume h1,
unfold prop.lift_n at h1,
contradiction
},
case prop.call t {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
contradiction,
assume h1,
unfold prop.lift_n at h1,
contradiction
},
case prop.post t₁ t₂ {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
contradiction,
assume h1,
unfold prop.lift_n at h1,
contradiction
},
case prop.forallc y P₁ P₁_ih {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
have h2, from option.some.inj h1,
simp[h2.symm],
unfold prop.num_quantifiers,
have h3: (prop.num_quantifiers P₁ = prop.num_quantifiers (prop.substt y x P₁)),
from same_num_quantifiers_after_substt,
rw[←h3],
simp,
from lt_of_add_one,
assume h1,
unfold prop.lift_n at h1,
contradiction
},
case prop.exis y P₁ P₁_ih {
assume P',
split,
assume h1,
unfold prop.lift_p at h1,
contradiction,
assume h1,
unfold prop.lift_n at h1,
contradiction
}
end
def erased_measure : has_well_founded
(psum prop prop)
:= ⟨_, measure_wf $ λ s,
match s with
| psum.inl a := a.sizeof
| psum.inr a := a.sizeof
end⟩
def instantiate_with_measure : has_well_founded
(psum (Σ' (p : prop), calltrigger)
(Σ' (p : prop), calltrigger))
:= ⟨_, measure_wf $ λ s,
match s with
| psum.inl a := a.1.sizeof
| psum.inr a := a.1.sizeof
end⟩
def find_calls_measure : has_well_founded
(psum prop prop)
:= ⟨_, measure_wf $ λ s,
match s with
| psum.inl a := a.sizeof
| psum.inr a := a.sizeof
end⟩
def prop.simplesize: prop → ℕ
| (prop.term t) := 0
| (prop.not P) := 1 + P.simplesize
| (prop.and P₁ P₂) := 1 + P₁.simplesize + P₂.simplesize
| (prop.or P₁ P₂) := 1 + P₁.simplesize + P₂.simplesize
| (prop.pre t₁ t₂) := 0
| (prop.pre₁ op t) := 0
| (prop.pre₂ op t₁ t₂) := 0
| (prop.call t) := 0
| (prop.post t₁ t₂) := 0
| (prop.forallc x P) := 1 + P.simplesize
| (prop.exis x P) := 1 + P.simplesize
lemma same_simplesize_after_subst {P: prop} {x: var} {v: value}:
P.simplesize = (prop.subst x v P).simplesize :=
begin
induction P,
case prop.term t {
unfold prop.subst,
unfold prop.simplesize,
change (0 = prop.simplesize (prop.term (term.subst x v t))),
unfold prop.simplesize
},
case prop.not P₁ ih {
unfold prop.subst,
unfold prop.simplesize,
rw[ih]
},
case prop.and P₁ P₂ P₁_ih P₂_ih {
unfold prop.subst,
unfold prop.simplesize,
change (prop.simplesize (prop.and P₁ P₂) = prop.simplesize (prop.and (prop.subst x v P₁) (prop.subst x v P₂))),
unfold prop.simplesize,
rw[P₁_ih],
rw[P₂_ih]
},
case prop.or P₁ P₂ P₁_ih P₂_ih {
unfold prop.subst,
unfold prop.simplesize,
change (prop.simplesize (prop.or P₁ P₂) = prop.simplesize (prop.or (prop.subst x v P₁) (prop.subst x v P₂))),
unfold prop.simplesize,
rw[P₁_ih],
rw[P₂_ih]
},
case prop.pre t₁ t₂ {
unfold prop.subst,
unfold prop.simplesize
},
case prop.pre₁ op t {
unfold prop.subst,
unfold prop.simplesize
},
case prop.pre₂ op t₁ t₂ {
unfold prop.subst,
unfold prop.simplesize
},
case prop.call t {
unfold prop.subst,
unfold prop.simplesize
},
case prop.post t₁ t₂ {
unfold prop.subst,
unfold prop.simplesize
},
case prop.forallc z P' P'_ih {
unfold prop.subst,
unfold prop.simplesize,
apply eq_add_left_of_eq,
by_cases (x = z) with h1,
simp[h1],
simp[h1],
from P'_ih
},
case prop.exis z P' P'_ih {
unfold prop.subst,
unfold prop.simplesize,
apply eq_add_left_of_eq,
by_cases (x = z) with h1,
simp[h1],
simp[h1],
from P'_ih
}
end
lemma simplesize_prop_not {P: prop}:
P.simplesize < P.not.simplesize :=
begin
unfold prop.simplesize,
rw[add_comm],
apply lt_add_of_pos_right,
from zero_lt_one
end
lemma simplesize_prop_and₁ {P S: prop}:
P.simplesize < (prop.and P S).simplesize :=
begin
unfold prop.simplesize,
rw[add_assoc],
rw[add_comm],
rw[add_assoc],
apply lt_add_of_pos_right,
change 0 < prop.simplesize S + 1,
apply lt_add_of_le_of_pos nonneg_of_nat,
from zero_lt_one
end
lemma simplesize_prop_and₂ {P S: prop}:
S.simplesize < (prop.and P S).simplesize :=
begin
unfold prop.simplesize,
rw[add_comm],
apply lt_add_of_pos_right,
change 0 < 1 + prop.simplesize P,
rw[add_comm],
apply lt_add_of_le_of_pos nonneg_of_nat,
from zero_lt_one
end
lemma simplesize_prop_or₁ {P S: prop}:
P.simplesize < (prop.or P S).simplesize :=
begin
unfold prop.simplesize,
rw[add_assoc],
rw[add_comm],
rw[add_assoc],
apply lt_add_of_pos_right,
change 0 < prop.simplesize S + 1,
apply lt_add_of_le_of_pos nonneg_of_nat,
from zero_lt_one
end
lemma simplesize_prop_or₂ {P S: prop}:
S.simplesize < (prop.or P S).simplesize :=
begin
unfold prop.simplesize,
rw[add_comm],
apply lt_add_of_pos_right,
change 0 < 1 + prop.simplesize P,
rw[add_comm],
apply lt_add_of_le_of_pos nonneg_of_nat,
from zero_lt_one
end
lemma simplesize_prop_exis {P: prop} {x: var}:
P.simplesize < (prop.exis x P).simplesize :=
begin
unfold prop.simplesize,
rw[add_comm],
apply lt_add_of_pos_right,
from zero_lt_one
end
lemma simplesize_prop_forall {P: prop} {x: var}:
P.simplesize < (prop.forallc x P).simplesize :=
begin
unfold prop.simplesize,
rw[add_comm],
apply lt_add_of_pos_right,
from zero_lt_one
end
|
510c7ab1f3bc70c9463aae9a88c63997310df1df | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/closed/zero.lean | 720938c6f74b6ed55cbdda25d08b84e66453f253 | [
"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,102 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.closed.cartesian
import category_theory.punit
import category_theory.conj
import category_theory.limits.shapes.zero_objects
/-!
# A cartesian closed category with zero object is trivial
A cartesian closed category with zero object is trivial: it is equivalent to the category with one
object and one morphism.
## References
* https://mathoverflow.net/a/136480
-/
universes v u
noncomputable theory
namespace category_theory
open category limits
variables {C : Type u} [category.{v} C]
variables [has_finite_products C] [cartesian_closed C]
/--
If a cartesian closed category has an initial object which is isomorphic to the terminal object,
then each homset has exactly one element.
-/
def unique_homset_of_initial_iso_terminal [has_initial C] (i : ⊥_ C ≅ ⊤_ C) (X Y : C) :
unique (X ⟶ Y) :=
equiv.unique $
calc (X ⟶ Y) ≃ (X ⨯ ⊤_ C ⟶ Y) : iso.hom_congr (prod.right_unitor _).symm (iso.refl _)
... ≃ (X ⨯ ⊥_ C ⟶ Y) : iso.hom_congr (prod.map_iso (iso.refl _) i.symm) (iso.refl _)
... ≃ (⊥_ C ⟶ Y ^^ X) : (exp.adjunction _).hom_equiv _ _
open_locale zero_object
/-- If a cartesian closed category has a zero object, each homset has exactly one element. -/
def unique_homset_of_zero [has_zero_object C] (X Y : C) :
unique (X ⟶ Y) :=
begin
haveI : has_initial C := has_zero_object.has_initial,
apply unique_homset_of_initial_iso_terminal _ X Y,
refine ⟨default, (default : ⊤_ C ⟶ 0) ≫ default, _, _⟩; simp
end
local attribute [instance] unique_homset_of_zero
/--
A cartesian closed category with a zero object is equivalent to the category with one object and
one morphism.
-/
def equiv_punit [has_zero_object C] : C ≌ discrete punit :=
equivalence.mk
(functor.star C)
(functor.from_punit 0)
(nat_iso.of_components
(λ X, { hom := default, inv := default })
(λ X Y f, dec_trivial))
(functor.punit_ext _ _)
end category_theory
|
da364b5b2f781bea74deec9dcbb2c13ed0b32614 | 9d00e4b237465921fb33aa10eed92a2495ca2e46 | /testProofs.lean | 357c21733ba996670c4dc1257052f493f346b697 | [] | no_license | Bpalkmim/LeanNatD | 7756abf1ed7b0e7a3e3b9d16ad756018f5c70c7c | 2e73bb44e44b955839e7a0874cd7013fbfb9c4e3 | refs/heads/master | 1,610,999,141,530 | 1,475,515,895,000 | 1,475,515,895,000 | 69,893,600 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,397 | lean | namespace testProofs
-- Requer os namespaces
open implRules
open andRules
open orRules
open negBotRules
print " "
print "Provas AVANÇADAS - início"
print " "
constants A B C D : Prop
--- Termos úteis
variable a : Proof A
variable b : Proof B
variable NEGb : Proof (neg B)
variable c : Proof C
variable NEGc : Proof (neg C)
variable d : Proof D
variable NEGd : Proof (neg D)
variable NEGdIMPNEGb : Proof (implies (neg D) (neg B))
variable aORb : Proof (or A B)
variable bDEPb : Π x : Proof B, Proof B
variable aIMPc : Proof (implies A C)
variable aDEPb : Π x : Proof A, Proof B
variable concl : Π x : Proof (and (or A B) (and (implies A C) (implies (neg D) (neg B)))), Proof (or C D)
--- Testes parciais
-- Parte direita
check impl_elim NEGdIMPNEGb NEGd
-- Parte esquerda
check impl_elim aIMPc a
check
-- Junção
check neg_elim
b
(impl_elim NEGdIMPNEGb NEGd)
check bot_intui
(neg_elim
(or_elim aORb aDEPb bDEPb b b)
(impl_elim NEGdIMPNEGb NEGd)
)
d
--- Teste final ((A ∨ B) ∧ (A → C) ∧ (¬D → ¬B)) → (C ∨ D) INTUICIONISTA
--- USAR OUTRA SENTENÇA!!!
check impl_intro
concl
(or_intro_right
c
(bot_intui
(neg_elim
(or_elim
aORb
aDEPb --- CONSERTARRRRR!!! TODO
bDEPb
)
(impl_elim
NEGdIMPNEGb
NEGd
)
)
d
)
)
print " "
print "Provas AVANÇADAS - fim"
print " "
end testProofs |
d394718d02289a99ecf68853fbb3147270442760 | 8c95816d6379a6864848d68ce735a5700c1cbbc3 | /src/smt2/syntax.lean | e1ba8309636648df49e5afa0502ff4e4cb90a014 | [
"Apache-2.0"
] | permissive | aqjune/smt2_interface | f00ed0a4317d7c9112deb0806c8e89e6512a901e | 598848a7a6fa47520fadcfe1b16891053a296084 | refs/heads/master | 1,631,518,664,718 | 1,524,489,340,000 | 1,524,489,340,000 | 115,204,811 | 0 | 0 | null | 1,514,043,428,000 | 1,514,043,427,000 | null | UTF-8 | Lean | false | false | 5,443 | lean | namespace smt2
@[reducible] def symbol : Type := string
@[reducible] def identifier : Type := string
inductive special_constant : Type
| number : int → special_constant
| bitvec : nat → int → special_constant
| string : string → special_constant
| bool : bool → special_constant
def hexdigit (n:nat) : char :=
char.of_nat $
if n < 10 then '0'.to_nat + n
else 'A'.to_nat + n - 10
def to_hex : nat → string
| 0 := "" -- leave it as "".
| n'@(n+1) :=
have n' / 16 < n', begin apply nat.div_lt_self, apply nat.zero_lt_succ, comp_val end,
to_hex (n' / 16) ++ to_string (hexdigit (n' % 16))
def special_constant.to_string : special_constant → string
| (special_constant.number i) := to_string i
| (special_constant.string str) := str
| (special_constant.bitvec bitsz num) :=
let unum := if num < 0 then 2^bitsz - num.nat_abs + 1 else num.to_nat in
if bitsz % 4 = 0 then -- use #xNNNN format
let l := to_hex unum in
"#x" ++ list.as_string (list.repeat '0' (bitsz / 4 - l.length)) ++ l
else -- use #bBBBB format
let b := ((nat.bits unum).map (λ b, cond b 1 0)).reverse in
let zeros := list.repeat 0 (bitsz - list.length b) in
let bits := zeros ++ b in -- Add leading zeros
"#b" ++ bits.foldl (λ fmt bit, fmt ++ to_string bit) ""
| (special_constant.bool b) :=
if b then "true" else "false"
meta def special_constant.to_format : special_constant → format :=
to_fmt ∘ special_constant.to_string
instance int_to_special_constant : has_coe int special_constant :=
⟨ special_constant.number ⟩
inductive sort : Type
| id : identifier → sort
| apply : identifier → list sort → sort
instance : has_coe string sort :=
⟨ sort.id ⟩
meta def sort.to_format : sort → format
| (sort.id i) := to_fmt i
| (sort.apply name sorts) := -- (name sort1 sort2 ..)
format.paren $
to_fmt name ++
(format.join $ sorts.map (λ s, to_fmt " " ++ sort.to_format s))
meta instance sort_has_to_fmt : has_to_format sort :=
⟨ sort.to_format ⟩
inductive attr : Type
inductive qualified_name : Type
| id : identifier → qualified_name
| qual_id : identifier → sort → qualified_name
meta def qualified_name.to_format : qualified_name → format
| (qualified_name.id i) := i
| (qualified_name.qual_id _ _) := "NYI"
instance string_to_qual_name : has_coe string qualified_name :=
⟨ fun str, qualified_name.id str ⟩
inductive term : Type
| qual_id : qualified_name → term
| const : special_constant → term
| apply : qualified_name → list term → term
| apply2 : term → list term → term
| letb : list (name × term) → term → term
| forallq : list (symbol × sort) → term → term
| existsq : list (symbol × sort) → term → term
| annotate : term → list attr → term
instance qual_name_to_term : has_coe qualified_name term :=
⟨ term.qual_id ⟩
instance special_const_to_term : has_coe special_constant term :=
⟨ term.const ⟩
meta def term.to_format : term → format
| (term.qual_id id) := id.to_format
| (term.const spec_const) := spec_const.to_format
| (term.apply qual_id ts) :=
let formatted_ts := format.join $ list.intersperse " " $ ts.map term.to_format in
format.bracket "(" ")" (
qual_id.to_format ++ format.space ++ formatted_ts)
| (term.apply2 f ts) :=
let formatted_ts := format.join $ list.intersperse " " $ ts.map term.to_format in
format.bracket "(" ")" (
f.to_format ++ format.space ++ formatted_ts)
| (term.letb ps ret) := "NYI"
| (term.forallq bs body) :=
"(forall (" ++
format.join (bs.map (fun ⟨sym, sort⟩, format.bracket "(" ")" $ to_fmt sym ++ " " ++ to_fmt sort)) ++ ") " ++
term.to_format body ++ ")"
| (term.existsq ps ret) := "NYI existsq"
| (term.annotate _ _) := "NYI annotate"
inductive fun_def : Type
inductive info_flag : Type
inductive keyword : Type
inductive option : Type
inductive cmd : Type
| assert_cmd : term → cmd
| check_sat : cmd
| check_sat_assuming : term → cmd -- not complete
| declare_const : symbol → sort → cmd
| declare_fun : symbol → list sort → sort → cmd
| declare_sort : symbol → nat → cmd
| define_fun : fun_def → cmd
| define_fun_rec : fun_def → cmd
| define_funs_rec : cmd -- not complete
| define_sort : symbol → list symbol → sort → cmd
| echo : string → cmd
| exit_cmd : cmd
| get_assertions : cmd
| get_assignment : cmd
| get_info : info_flag → cmd
| get_model : cmd
| get_option : keyword → cmd
| get_proof : cmd
| get_unsat_assumtpions : cmd
| get_unsat_core : cmd
| get_value : cmd -- not complete
| pop : nat → cmd
| push : nat → cmd
| reset : cmd
| reset_assertions : cmd
| set_info : attr → cmd
| set_logic : symbol → cmd
| set_opt : option → cmd
open cmd
meta def string_lit (s : string) : format :=
format.bracket "\"" "\"" (to_fmt s)
meta def cmd.to_format : cmd → format
| (echo msg) := "(echo " ++ string_lit msg ++ ")\n"
| (declare_const sym srt) := "(declare-const " ++ sym ++ " " ++ to_fmt srt ++ ")"
| (assert_cmd t) := "(assert " ++ t.to_format ++ ")"
| (check_sat) := "(check-sat)"
| (declare_fun sym ps rs) := "(declare-fun " ++ sym ++
format.bracket " (" ")" (format.join $ list.intersperse " " $ list.map to_fmt ps) ++ " " ++ to_fmt rs ++ ")"
| (declare_sort sym arity) := "(declare-sort " ++ sym ++ " " ++ to_string arity ++ ")"
| (reset) := "(reset)"
| _ := "NYI"
meta instance : has_to_format cmd :=
⟨ cmd.to_format ⟩
end smt2
|
b3155c9c3966eabcbec609d0f25a0e084db8456f | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/geometry/manifold/instances/real.lean | 0ee93ba3e67e1dbcf95fe971b9397a85bcc8a980 | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,573 | 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 geometry.manifold.algebra.smooth_functions
import linear_algebra.finite_dimensional
import analysis.normed_space.pi_Lp
/-!
# Constructing examples of manifolds over ℝ
We introduce the necessary bits to be able to define manifolds modelled over `ℝ^n`, boundaryless
or with boundary or with corners. As a concrete example, we construct explicitly the manifold with
boundary structure on the real interval `[x, y]`.
More specifically, we introduce
* `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n)` for the model space
used to define `n`-dimensional real manifolds with boundary
* `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
## Notations
In the locale `manifold`, we introduce the notations
* `𝓡 n` for the identity model with corners on `euclidean_space ℝ (fin n)`
* `𝓡∂ n` for `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n)`.
For instance, if a manifold `M` is boundaryless, smooth and modelled on `euclidean_space ℝ (fin m)`,
and `N` is smooth with boundary modelled on `euclidean_half_space n`, and `f : M → N` is a smooth
map, then the derivative of `f` can be written simply as `mfderiv (𝓡 m) (𝓡∂ n) f` (as to why the
model with corners can not be implicit, see the discussion in `smooth_manifold_with_corners.lean`).
## Implementation notes
The manifold structure on the interval `[x, y] = Icc x y` requires the assumption `x < y` as a
typeclass. We provide it as `[fact (x < y)]`.
-/
noncomputable theory
open set function
open_locale manifold
/--
The half-space in `ℝ^n`, used to model manifolds with boundary. We only define it when
`1 ≤ n`, as the definition only makes sense in this case.
-/
def euclidean_half_space (n : ℕ) [has_zero (fin n)] : Type :=
{x : euclidean_space ℝ (fin n) // 0 ≤ x 0}
/--
The quadrant in `ℝ^n`, used to model manifolds with corners, made of all vectors with nonnegative
coordinates.
-/
def euclidean_quadrant (n : ℕ) : Type := {x : euclidean_space ℝ (fin n) // ∀i:fin n, 0 ≤ x i}
section
/- Register class instances for euclidean half-space and quadrant, that can not be noticed
without the following reducibility attribute (which is only set in this section). -/
local attribute [reducible] euclidean_half_space euclidean_quadrant
variable {n : ℕ}
instance [has_zero (fin n)] : topological_space (euclidean_half_space n) := by apply_instance
instance : topological_space (euclidean_quadrant n) := by apply_instance
instance [has_zero (fin n)] : inhabited (euclidean_half_space n) := ⟨⟨0, le_refl _⟩⟩
instance : inhabited (euclidean_quadrant n) := ⟨⟨0, λ i, le_refl _⟩⟩
lemma range_half_space (n : ℕ) [has_zero (fin n)] :
range (λx : euclidean_half_space n, x.val) = {y | 0 ≤ y 0} :=
by simp
lemma range_quadrant (n : ℕ) :
range (λx : euclidean_quadrant n, x.val) = {y | ∀i:fin n, 0 ≤ y i} :=
by simp
end
/--
Definition of the model with corners `(euclidean_space ℝ (fin n), euclidean_half_space n)`, used as
a model for manifolds with boundary. In the locale `manifold`, use the shortcut `𝓡∂ n`.
-/
def model_with_corners_euclidean_half_space (n : ℕ) [has_zero (fin n)] :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n) :=
{ to_fun := subtype.val,
inv_fun := λx, ⟨update x 0 (max (x 0) 0), by simp [le_refl]⟩,
source := univ,
target := {x | 0 ≤ x 0},
map_source' := λx hx, x.property,
map_target' := λx hx, mem_univ _,
left_inv' := λ ⟨xval, xprop⟩ hx, begin
rw [subtype.mk_eq_mk, update_eq_iff],
exact ⟨max_eq_left xprop, λ i _, rfl⟩
end,
right_inv' := λx hx, update_eq_iff.2 ⟨max_eq_left hx, λ i _, rfl⟩,
source_eq := rfl,
unique_diff' :=
have this : unique_diff_on ℝ _ :=
unique_diff_on.pi (fin n) (λ _, ℝ) _ _ (λ i ∈ ({0} : set (fin n)), unique_diff_on_Ici 0),
by simpa only [singleton_pi] using this,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ $ continuous_id.update 0 $
(continuous_apply 0).max continuous_const }
/--
Definition of the model with corners `(euclidean_space ℝ (fin n), euclidean_quadrant n)`, used as a
model for manifolds with corners -/
def model_with_corners_euclidean_quadrant (n : ℕ) :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_quadrant n) :=
{ to_fun := subtype.val,
inv_fun := λx, ⟨λi, max (x i) 0, λi, by simp only [le_refl, or_true, le_max_iff]⟩,
source := univ,
target := {x | ∀ i, 0 ≤ x i},
map_source' := λx hx, by simpa only [subtype.range_val] using x.property,
map_target' := λx hx, mem_univ _,
left_inv' := λ ⟨xval, xprop⟩ hx, by { ext i, simp only [subtype.coe_mk, xprop i, max_eq_left] },
right_inv' := λ x hx, by { ext1 i, simp only [hx i, max_eq_left] },
source_eq := rfl,
unique_diff' :=
have this : unique_diff_on ℝ _ :=
unique_diff_on.univ_pi (fin n) (λ _, ℝ) _ (λ i, unique_diff_on_Ici 0),
by simpa only [pi_univ_Ici] using this,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ $ continuous_pi $ λ i,
(continuous_id.max continuous_const).comp (continuous_apply i) }
localized "notation `𝓡 `n := model_with_corners_self ℝ (euclidean_space ℝ (fin n))" in manifold
localized "notation `𝓡∂ `n := model_with_corners_euclidean_half_space n" in manifold
/--
The left chart for the topological space `[x, y]`, defined on `[x,y)` and sending `x` to `0` in
`euclidean_half_space 1`.
-/
def Icc_left_chart (x y : ℝ) [fact (x < y)] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | z.val < y},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, z.val - x, sub_nonneg.mpr z.property.1⟩,
inv_fun := λz, ⟨min (z.val 0 + x) y, by simp [le_refl, z.prop, le_of_lt (fact.out (x < y))]⟩,
map_source' := by simp only [imp_self, sub_lt_sub_iff_right, mem_set_of_eq, forall_true_iff],
map_target' :=
by { simp only [min_lt_iff, mem_set_of_eq], assume z hz, left,
dsimp [-subtype.val_eq_coe] at hz, linarith },
left_inv' := begin
rintros ⟨z, hz⟩ h'z,
simp only [mem_set_of_eq, mem_Icc] at hz h'z,
simp only [hz, min_eq_left, sub_add_cancel]
end,
right_inv' := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
dsimp at hz h'z,
have A : x + z 0 ≤ y, by linarith,
rw subsingleton.elim i 0,
simp only [A, add_comm, add_sub_cancel', min_eq_left],
end,
open_source := begin
have : is_open {z : ℝ | z < y} := is_open_Iio,
exact this.preimage continuous_subtype_val
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : euclidean_space ℝ (fin 1) | z 0 < y - x} :=
this.preimage (@continuous_apply (fin 1) (λ _, ℝ) _ 0),
exact this.preimage continuous_subtype_val
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), z - x) :=
continuous.sub (continuous_pi $ λi, continuous_id) continuous_const,
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, min (z + x) y) :=
(continuous_id.add continuous_const).min continuous_const,
have B : continuous (λz : euclidean_space ℝ (fin 1), z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
The right chart for the topological space `[x, y]`, defined on `(x,y]` and sending `y` to `0` in
`euclidean_half_space 1`.
-/
def Icc_right_chart (x y : ℝ) [fact (x < y)] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | x < z.val},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, y - z.val, sub_nonneg.mpr z.property.2⟩,
inv_fun := λz,
⟨max (y - z.val 0) x, by simp [le_refl, z.prop, le_of_lt (fact.out (x < y)), sub_eq_add_neg]⟩,
map_source' := by simp only [imp_self, mem_set_of_eq, sub_lt_sub_iff_left, forall_true_iff],
map_target' :=
by { simp only [lt_max_iff, mem_set_of_eq], assume z hz, left,
dsimp [-subtype.val_eq_coe] at hz, linarith },
left_inv' := begin
rintros ⟨z, hz⟩ h'z,
simp only [mem_set_of_eq, mem_Icc] at hz h'z,
simp only [hz, sub_eq_add_neg, max_eq_left, add_add_neg_cancel'_right, neg_add_rev, neg_neg]
end,
right_inv' := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
dsimp at hz h'z,
have A : x ≤ y - z 0, by linarith,
rw subsingleton.elim i 0,
simp only [A, sub_sub_cancel, max_eq_left],
end,
open_source := begin
have : is_open {z : ℝ | x < z} := is_open_Ioi,
exact this.preimage continuous_subtype_val
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : euclidean_space ℝ (fin 1) | z 0 < y - x} :=
this.preimage (@continuous_apply (fin 1) (λ _, ℝ) _ 0),
exact this.preimage continuous_subtype_val
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), y - z) :=
continuous_const.sub (continuous_pi (λi, continuous_id)),
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, max (y - z) x) :=
(continuous_const.sub continuous_id).max continuous_const,
have B : continuous (λz : euclidean_space ℝ (fin 1), z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
Charted space structure on `[x, y]`, using only two charts taking values in
`euclidean_half_space 1`.
-/
instance Icc_manifold (x y : ℝ) [fact (x < y)] : charted_space (euclidean_half_space 1) (Icc x y) :=
{ atlas := {Icc_left_chart x y, Icc_right_chart x y},
chart_at := λz, if z.val < y then Icc_left_chart x y else Icc_right_chart x y,
mem_chart_source := λz, begin
by_cases h' : z.val < y,
{ simp only [h', if_true],
exact h' },
{ simp only [h', if_false],
apply lt_of_lt_of_le (fact.out (x < y)),
simpa only [not_lt] using h'}
end,
chart_mem_atlas := λz, by { by_cases h' : z.val < y; simp [h'] } }
/--
The manifold structure on `[x, y]` is smooth.
-/
instance Icc_smooth_manifold (x y : ℝ) [fact (x < y)] :
smooth_manifold_with_corners (𝓡∂ 1) (Icc x y) :=
begin
have M : times_cont_diff_on ℝ ∞ (λz : euclidean_space ℝ (fin 1), - z + (λi, y - x)) univ,
{ rw times_cont_diff_on_univ,
exact times_cont_diff_id.neg.add times_cont_diff_const },
apply smooth_manifold_with_corners_of_times_cont_diff_on,
assume e e' he he',
simp only [atlas, mem_singleton_iff, mem_insert_iff] at he he',
/- We need to check that any composition of two charts gives a `C^∞` function. Each chart can be
either the left chart or the right chart, leaving 4 possibilities that we handle successively.
-/
rcases he with rfl | rfl; rcases he' with rfl | rfl,
{ -- `e = left chart`, `e' = left chart`
exact (mem_groupoid_of_pregroupoid.mpr (symm_trans_mem_times_cont_diff_groupoid _ _ _)).1 },
{ -- `e = left chart`, `e' = right chart`
apply M.congr_mono _ (subset_univ _),
rintro _ ⟨⟨hz₁, hz₂⟩, ⟨⟨z, hz₀⟩, rfl⟩⟩,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart,
update_same, max_eq_left, hz₀, lt_sub_iff_add_lt] with mfld_simps at hz₁ hz₂,
rw [min_eq_left hz₁.le, lt_add_iff_pos_left] at hz₂,
ext i,
rw subsingleton.elim i 0,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, *,
pi_Lp.add_apply, pi_Lp.neg_apply, max_eq_left, min_eq_left hz₁.le, update_same]
with mfld_simps,
abel },
{ -- `e = right chart`, `e' = left chart`
apply M.congr_mono _ (subset_univ _),
rintro _ ⟨⟨hz₁, hz₂⟩, ⟨z, hz₀⟩, rfl⟩,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, max_lt_iff,
update_same, max_eq_left hz₀] with mfld_simps at hz₁ hz₂,
rw lt_sub at hz₁,
ext i,
rw subsingleton.elim i 0,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart,
pi_Lp.add_apply, pi_Lp.neg_apply, update_same, max_eq_left, hz₀, hz₁.le] with mfld_simps,
abel },
{ -- `e = right chart`, `e' = right chart`
exact (mem_groupoid_of_pregroupoid.mpr (symm_trans_mem_times_cont_diff_groupoid _ _ _)).1 }
end
/-! Register the manifold structure on `Icc 0 1`, and also its zero and one. -/
section
lemma fact_zero_lt_one : fact ((0 : ℝ) < 1) := ⟨zero_lt_one⟩
local attribute [instance] fact_zero_lt_one
instance : charted_space (euclidean_half_space 1) (Icc (0 : ℝ) 1) := by apply_instance
instance : smooth_manifold_with_corners (𝓡∂ 1) (Icc (0 : ℝ) 1) := by apply_instance
end
|
f537b222dcb27bb38a9cf7130896712c60ae92a6 | 968e2f50b755d3048175f176376eff7139e9df70 | /examples/prop_logic_theory/unnamed_287.lean | 8d76a4cf08814b609200f11a6c6731d5f3aeeb8d | [] | no_license | gihanmarasingha/mth1001_sphinx | 190a003269ba5e54717b448302a27ca26e31d491 | 05126586cbf5786e521be1ea2ef5b4ba3c44e74a | refs/heads/master | 1,672,913,933,677 | 1,604,516,583,000 | 1,604,516,583,000 | 309,245,750 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 367 | lean | variables p q : Prop
-- BEGIN
example (h : p ∧ q) : q ∧ p :=
begin
have h₂ : p, from h.left,
have h₃ : q, from h.right,
exact and.intro h₃ h₂,
end
-- END
Alternatively, one can use the 'anonymous constructor' notation ``⟨h₃, h₂⟩`` in place of
``and.intro h₃ h₂``. Here, ``⟨`` and ``⟩`` are written as ``\<`` and ``\>`` respectively. |
cc5bfbb21a51084f37bfd1ea2e98602c8da7f743 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/nasty_sizeof.lean | c7a73d1719dbca5088942341243658e43c3f7329 | [
"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 | 100 | lean | def nasty_sizeof : list nat → nat
| [] := 100000000
| (a::as) := nasty_sizeof as + 100000000
|
8ccdb664159dd6976cbe03e34bf9c4535a7ea206 | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /src/tactic/finish.lean | 288eee9ac7a43991770eced808e119f7b1bc866c | [
"Apache-2.0"
] | permissive | anrddh/mathlib | 6a374da53c7e3a35cb0298b0cd67824efef362b4 | a4266a01d2dcb10de19369307c986d038c7bb6a6 | refs/heads/master | 1,656,710,827,909 | 1,589,560,456,000 | 1,589,560,456,000 | 264,271,800 | 0 | 0 | Apache-2.0 | 1,589,568,062,000 | 1,589,568,061,000 | null | UTF-8 | Lean | false | false | 23,095 | lean | /-
Copyright (c) 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Jesse Michael Han
-/
import tactic.hint
/-!
# The `finish` family of tactics
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.
## Main definitions
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 accept an optional list of simplifier rules, typically definitions that should be expanded.
(The equations and identities should not refer to the local context.)
## Implementation notes
The variants `ifinish`, `iclarify`, and `isafe` try to restrict to intuitionistic logic. But the
`done` tactic leaks classical logic:
```lean
example {P : Prop} : ¬¬P → P :=
by using_smt (do smt_tactic.intros, smt_tactic.close)
```
They also do not work well with the current heuristic instantiation method used by `ematch`.
So they are left here mainly for reference.
-/
declare_trace auto.done
declare_trace auto.finish
namespace tactic
namespace interactive
meta def revert_all := tactic.revert_all
end interactive
end tactic
open tactic expr
namespace auto
/-! ### Utilities -/
meta def whnf_reducible (e : expr) : tactic expr := whnf e reducible
-- stolen from interactive.lean
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.
* `(use_simp := tt)`: call the simplifier
* `(classical := tt)`: use classical logic
* `(max_ematch_rounds := 20)`: for the "done" tactic
-/
@[derive decidable_eq, derive inhabited]
structure auto_config : Type :=
(use_simp := tt)
(classical := tt)
(max_ematch_rounds := 20)
/-!
### 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`.
For efficiency, we push negations inwards from the top down. (For example, consider
simplifying `¬ ¬ (p ∨ q)`.)
-/
section
universe u
variable {α : Type u}
variables (p q : Prop)
variable (s : α → Prop)
local attribute [instance, priority 10] classical.prop_decidable
theorem not_not_eq : (¬ ¬ p) = p := propext not_not
theorem not_and_eq : (¬ (p ∧ q)) = (¬ p ∨ ¬ q) := propext not_and_distrib
theorem not_or_eq : (¬ (p ∨ q)) = (¬ p ∧ ¬ q) := propext not_or_distrib
theorem not_forall_eq : (¬ ∀ x, s x) = (∃ x, ¬ s x) := propext not_forall
theorem not_exists_eq : (¬ ∃ x, s x) = (∀ x, ¬ s x) := propext not_exists
theorem not_implies_eq : (¬ (p → q)) = (p ∧ ¬ q) := propext not_imp
theorem classical.implies_iff_not_or : (p → q) ↔ (¬ p ∨ q) := imp_iff_not_or
end
def common_normalize_lemma_names : list name :=
[``bex_def, ``forall_and_distrib, ``exists_imp_distrib, ``or.assoc, ``or.comm, ``or.left_comm,
``and.assoc, ``and.comm, ``and.left_comm]
def classical_normalize_lemma_names : list name :=
common_normalize_lemma_names ++ [``classical.implies_iff_not_or]
/-- optionally returns an equivalent expression and proof of equivalence -/
private meta def transform_negation_step (cfg : auto_config) (e : expr) :
tactic (option (expr × expr)) :=
do e ← whnf_reducible e,
match e with
| `(¬ %%ne) :=
(do ne ← whnf_reducible ne,
match ne with
| `(¬ %%a) := if ¬ cfg.classical then return none
else do pr ← mk_app ``not_not_eq [a],
return (some (a, pr))
| `(%%a ∧ %%b) := do pr ← mk_app ``not_and_eq [a, b],
return (some (`(¬ %%a ∨ ¬ %%b), pr))
| `(%%a ∨ %%b) := do pr ← mk_app ``not_or_eq [a, b],
return (some (`(¬ %%a ∧ ¬ %%b), pr))
| `(Exists %%p) := do pr ← mk_app ``not_exists_eq [p],
`(%%_ = %%e') ← infer_type pr,
return (some (e', pr))
| (pi n bi d p) := if ¬ cfg.classical then return none
else if p.has_var then do
pr ← mk_app ``not_forall_eq [lam n bi d (expr.abstract_local p n)],
`(%%_ = %%e') ← infer_type pr,
return (some (e', pr))
else do
pr ← mk_app ``not_implies_eq [d, p],
`(%%_ = %%e') ← infer_type pr,
return (some (e', pr))
| _ := return none
end)
| _ := return none
end
/-- given an expr `e`, returns a new expression and a proof of equality -/
private meta def transform_negation (cfg : auto_config) : expr → tactic (option (expr × expr)) :=
λ e, do
opr ← transform_negation_step cfg e,
match opr with
| (some (e', pr)) := do
opr' ← transform_negation e',
match opr' with
| none := return (some (e', pr))
| (some (e'', pr')) := do pr'' ← mk_eq_trans pr pr',
return (some (e'', pr''))
end
| none := return none
end
meta def normalize_negations (cfg : auto_config) (h : expr) : tactic unit :=
do t ← infer_type h,
(_, e, pr) ← simplify_top_down ()
(λ _, λ e, do
oepr ← transform_negation cfg e,
match oepr with
| (some (e', pr)) := return ((), e', pr)
| none := do pr ← mk_eq_refl e, return ((), e, pr)
end)
t,
replace_hyp h e pr,
skip
meta def normalize_hyp (cfg : auto_config) (simps : simp_lemmas) (h : expr) : tactic unit :=
(do h ← simp_hyp simps [] h, try (normalize_negations cfg h)) <|>
try (normalize_negations cfg 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 cfg simps)
/-!
### Eliminate existential quantifiers
-/
/-- eliminate an existential quantifier if there is one -/
meta def eelim : tactic unit :=
do ctx ← local_context,
first $ ctx.map $ λ h,
do t ← infer_type h >>= whnf_reducible,
guard (is_app_of t ``Exists),
tgt ← target,
to_expr ``(@exists.elim _ _ %%tgt %%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.map $ λ 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 (note_anon 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 := local_context >>= split_hyps_aux >>= guardb
/-!
### Eagerly apply all the preprocessing rules
-/
/-- 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-/)
/-!
### Terminal tactic
-/
/--
The terminal tactic, used to try to finish off goals:
- 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?
-/
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
private meta def report_invalid_em_lemma {α : Type} (n : name) : smt_tactic α :=
fail format!"invalid ematch lemma '{n}'"
private meta def add_hinst_lemma_from_name (md : transparency) (lhs_lemma : bool) (n : name)
(hs : hinst_lemmas) (ref : pexpr) : smt_tactic hinst_lemmas :=
do p ← resolve_name n,
match p with
| expr.const n _ := (do h ← hinst_lemma.mk_from_decl_core md n lhs_lemma,
tactic.save_const_type_info n ref, return $ hs.add h) <|>
(do hs₁ ← smt_tactic.mk_ematch_eqn_lemmas_for_core md n,
tactic.save_const_type_info n ref, return $ hs.merge hs₁) <|>
report_invalid_em_lemma n
| _ := (do e ← to_expr p, h ← hinst_lemma.mk_core md e lhs_lemma,
try (tactic.save_type_info e ref), return $ hs.add h) <|>
report_invalid_em_lemma n
end
private meta def add_hinst_lemma_from_pexpr (md : transparency) (lhs_lemma : bool) (hs : hinst_lemmas)
: pexpr → smt_tactic hinst_lemmas
| p@(expr.const c []) := add_hinst_lemma_from_name md lhs_lemma c hs p
| p@(expr.local_const c _ _ _) := add_hinst_lemma_from_name md lhs_lemma c hs p
| p := do new_e ← to_expr p, h ← hinst_lemma.mk_core md new_e lhs_lemma,
return $ hs.add h
private meta def add_hinst_lemmas_from_pexprs (md : transparency) (lhs_lemma : bool)
(ps : list pexpr) (hs : hinst_lemmas) : smt_tactic hinst_lemmas :=
list.mfoldl (add_hinst_lemma_from_pexpr md lhs_lemma) hs ps
/--
`done` first attempts to close the goal using `contradiction`. If this fails, it creates an
SMT state and will repeatedly use `ematch` (using `ematch` lemmas in the environment,
universally quantified assumptions, and the supplied lemmas `ps`) and congruence closure.
-/
meta def done (ps : list pexpr) (cfg : auto_config := {}) : tactic unit :=
do trace_state_if_enabled `auto.done "entering done",
contradiction <|>
(solve1 $
(do revert_all,
using_smt
(do smt_tactic.intros,
ctx ← local_context,
hs ← mk_hinst_lemmas ctx,
hs' ← add_hinst_lemmas_from_pexprs reducible ff ps hs,
smt_tactic.iterate_at_most cfg.max_ematch_rounds
(smt_tactic.ematch_using hs' >> smt_tactic.try smt_tactic.close))))
/-!
### Tactics that perform case splits
-/
@[derive decidable_eq, derive inhabited]
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
-/
/--
`safe_core s ps cfg opt` negates the goal, normalizes hypotheses
(by splitting conjunctions, eliminating existentials, pushing negations inwards,
and calling `simp` with the supplied lemmas `s`), and then tries `contradiction`.
If this fails, it will create an SMT state and repeatedly use `ematch`
(using `ematch` lemmas in the environment, universally quantified assumptions,
and the supplied lemmas `ps`) and congruence closure.
`safe_core` is complete for propositional logic. Depending on the form of `opt`
it will:
- (if `opt` is `case_option.force`) fail if it does not close the goal,
- (if `opt` is `case_option.at_most_one`) fail if it produces more than one goal, and
- (if `opt` is `case_option.accept`) ignore the number of goals it produces.
-/
meta def safe_core (s : simp_lemmas × list name) (ps : list pexpr) (cfg : auto_config) : case_option → tactic unit :=
λ co, focus1 $
do trace_state_if_enabled `auto.finish "entering safe_core",
if cfg.use_simp then do
trace_if_enabled `auto.finish "simplifying hypotheses",
simp_all s.1 s.2 { fail_if_unchanged := ff },
trace_state_if_enabled `auto.finish "result:"
else skip,
tactic.done <|>
do trace_if_enabled `auto.finish "preprocessing hypotheses",
preprocess_hyps cfg,
trace_state_if_enabled `auto.finish "result:",
done ps cfg <|>
(mcond (case_some_hyp co safe_core)
skip
(match co with
| case_option.force := done ps cfg
| case_option.at_most_one := try (done ps cfg)
| case_option.accept := try (done ps cfg)
end))
/--
`clarify` is `safe_core`, but with the `(opt : case_option)`
parameter fixed at `case_option.at_most_one`.
-/
meta def clarify (s : simp_lemmas × list name) (ps : list pexpr)
(cfg : auto_config := {}) : tactic unit := safe_core s ps cfg case_option.at_most_one
/--
`safe` is `safe_core`, but with the `(opt : case_option)`
parameter fixed at `case_option.accept`.
-/
meta def safe (s : simp_lemmas × list name) (ps : list pexpr)
(cfg : auto_config := {}) : tactic unit := safe_core s ps cfg case_option.accept
/--
`finish` is `safe_core`, but with the `(opt : case_option)`
parameter fixed at `case_option.force`.
-/
meta def finish (s : simp_lemmas × list name) (ps : list pexpr)
(cfg : auto_config := {}) : tactic unit := safe_core s ps cfg case_option.force
/--
`iclarify` is like `clarify`, but in some places restricts to intuitionistic logic.
Classical logic still leaks, so this tactic is deprecated.
-/
meta def iclarify (s : simp_lemmas × list name) (ps : list pexpr)
(cfg : auto_config := {}) : tactic unit := clarify s ps {classical := ff, ..cfg}
/--
`isafe` is like `safe`, but in some places restricts to intuitionistic logic.
Classical logic still leaks, so this tactic is deprecated.
-/
meta def isafe (s : simp_lemmas × list name) (ps : list pexpr)
(cfg : auto_config := {}) : tactic unit := safe s ps {classical := ff, ..cfg}
/--
`ifinish` is like `finish`, but in some places restricts to intuitionistic logic.
Classical logic still leaks, so this tactic is deprecated.
-/
meta def ifinish (s : simp_lemmas × list name) (ps : list pexpr) (cfg : auto_config := {}) : tactic unit :=
finish s ps {classical := ff, ..cfg}
end auto
/-! ### interactive versions -/
open auto
namespace tactic
namespace interactive
open lean lean.parser interactive interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many
/--
`clarify [h1,...,hn] using [e1,...,en]` negates the goal, normalizes hypotheses
(by splitting conjunctions, eliminating existentials, pushing negations inwards,
and calling `simp` with the supplied lemmas `h1,...,hn`), and then tries `contradiction`.
If this fails, it will create an SMT state and repeatedly use `ematch`
(using `ematch` lemmas in the environment, universally quantified assumptions,
and the supplied lemmas `e1,...,en`) and congruence closure.
`clarify` is complete for propositional logic.
Either of the supplied simp lemmas or the supplied ematch lemmas are optional.
`clarify` will fail if it produces more than one goal.
-/
meta def clarify (hs : parse simp_arg_list) (ps : parse (tk "using" *> pexpr_list_or_texpr)?)
(cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs,
auto.clarify s (ps.get_or_else []) cfg
/--
`safe [h1,...,hn] using [e1,...,en]` negates the goal, normalizes hypotheses
(by splitting conjunctions, eliminating existentials, pushing negations inwards,
and calling `simp` with the supplied lemmas `h1,...,hn`), and then tries `contradiction`.
If this fails, it will create an SMT state and repeatedly use `ematch`
(using `ematch` lemmas in the environment, universally quantified assumptions,
and the supplied lemmas `e1,...,en`) and congruence closure.
`safe` is complete for propositional logic.
Either of the supplied simp lemmas or the supplied ematch lemmas are optional.
`safe` ignores the number of goals it produces, and should never fail.
-/
meta def safe (hs : parse simp_arg_list) (ps : parse (tk "using" *> pexpr_list_or_texpr)?)
(cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs,
auto.safe s (ps.get_or_else []) cfg
/--
`finish [h1,...,hn] using [e1,...,en]` negates the goal, normalizes hypotheses
(by splitting conjunctions, eliminating existentials, pushing negations inwards,
and calling `simp` with the supplied lemmas `h1,...,hn`), and then tries `contradiction`.
If this fails, it will create an SMT state and repeatedly use `ematch`
(using `ematch` lemmas in the environment, universally quantified assumptions,
and the supplied lemmas `e1,...,en`) and congruence closure.
`finish` is complete for propositional logic.
Either of the supplied simp lemmas or the supplied ematch lemmas are optional.
`finish` will fail if it does not close the goal.
-/
meta def finish (hs : parse simp_arg_list) (ps : parse (tk "using" *> pexpr_list_or_texpr)?)
(cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs,
auto.finish s (ps.get_or_else []) cfg
add_hint_tactic "finish"
/--
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.
* `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 accept an optional list of simplifier rules, typically definitions that should be expanded.
(The equations and identities should not refer to the local context.) All also accept an optional
list of `ematch` lemmas, which must be preceded by `using`.
-/
add_tactic_doc
{ name := "finish / clarify / safe",
category := doc_category.tactic,
decl_names := [`tactic.interactive.finish, `tactic.interactive.clarify,
`tactic.interactive.safe],
tags := ["logic", "finishing"] }
/--
`iclarify` is like `clarify`, but only uses intuitionistic logic.
-/
meta def iclarify (hs : parse simp_arg_list) (ps : parse (tk "using" *> pexpr_list_or_texpr)?)
(cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs,
auto.iclarify s (ps.get_or_else []) cfg
/--
`isafe` is like `safe`, but only uses intuitionistic logic.
-/
meta def isafe (hs : parse simp_arg_list) (ps : parse (tk "using" *> pexpr_list_or_texpr)?)
(cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs,
auto.isafe s (ps.get_or_else []) cfg
/--
`ifinish` is like `finish`, but only uses intuitionistic logic.
-/
meta def ifinish (hs : parse simp_arg_list) (ps : parse (tk "using" *> pexpr_list_or_texpr)?)
(cfg : auto_config := {}) : tactic unit :=
do s ← mk_simp_set ff [] hs,
auto.ifinish s (ps.get_or_else []) cfg
end interactive
end tactic
|
7b709dfe85aac511821becb5ea3d4535077d1d68 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Util/Profile.lean | d247970b1f355cfeb09aeb7d79520535346014cd | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,785 | lean | /-
Copyright (c) 2019 Sebastian Ullrich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich
-/
import Lean.Data.Options
namespace Lean
register_builtin_option profiler : Bool := {
defValue := false
group := "profiler"
descr := "show execution times of various Lean components"
}
register_builtin_option profiler.threshold : Nat := {
defValue := 100
group := "profiler"
descr := "threshold in milliseconds, profiling times under threshold will not be reported individually"
}
@[export lean_get_profiler]
private def get_profiler (o : Options) : Bool :=
profiler.get o
@[export lean_get_profiler_threshold]
def profiler.threshold.getSecs (o : Options) : Float :=
(profiler.threshold.get o).toFloat / 1000
/-- Print and accumulate run time of `act` when option `profiler` is set to `true`. -/
@[extern "lean_profileit"]
def profileit {α : Type} (category : @& String) (opts : @& Options) (fn : Unit → α) (decl := Name.anonymous) : α := fn ()
unsafe def profileitIOUnsafe {ε α : Type} (category : String) (opts : Options) (act : EIO ε α) (decl := Name.anonymous) : EIO ε α :=
match profileit (decl := decl) category opts fun _ => unsafeEIO act with
| Except.ok a => pure a
| Except.error e => throw e
@[implemented_by profileitIOUnsafe]
def profileitIO {ε α : Type} (category : String) (opts : Options) (act : EIO ε α) (decl := Name.anonymous) : EIO ε α := act
-- impossible to infer `ε`
def profileitM {m : Type → Type} (ε : Type) [MonadFunctorT (EIO ε) m] {α : Type} (category : String) (opts : Options) (act : m α) (decl := Name.anonymous) : m α :=
monadMap (fun {β} => profileitIO (ε := ε) (α := β) (decl := decl) category opts) act
end Lean
|
4e582cdc9dc30ccb797bec22cb0eb75cdb47e38b | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/run/even_perf.lean | 5914dea3f3cb96abdc93f140802245ec062206c8 | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 194 | lean | open nat
def even : nat → bool
| 0 := tt
| (succ 0) := ff
| (succ (succ n)) := even n
vm_eval even 0
vm_eval even 1
vm_eval even 2
vm_eval even 10000
vm_eval even 10001
|
f7c053aa8da2f9f3523fe9a0778988ec32fb75c1 | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /tests/lean/run/match_tac3.lean | 38844920dbb09f5abd4a39cc1025facd4d0f178e | [
"Apache-2.0"
] | permissive | chubbymaggie/lean | 0d06ae25f9dd396306fb02190e89422ea94afd7b | d2c7b5c31928c98f545b16420d37842c43b4ae9a | refs/heads/master | 1,611,313,622,901 | 1,430,266,839,000 | 1,430,267,083,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 219 | lean | import data.nat
open nat
theorem tst (a b : nat) (H : a = 0) : a + b = b :=
begin
revert H,
match a with
| zero := λ H, by rewrite zero_add
| (n+1) := λ H, nat.no_confusion H
end
end
print definition tst
|
2be5898f74cb01df82e1c48559f4f953cba22c1d | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/analysis/special_functions/exp_log.lean | f4fbe4629d175b633ac9d600a30f9f802afdc516 | [
"Apache-2.0"
] | permissive | hamdysalah1/mathlib | b915f86b2503feeae268de369f1b16932321f097 | 95454452f6b3569bf967d35aab8d852b1ddf8017 | refs/heads/master | 1,677,154,116,545 | 1,611,797,994,000 | 1,611,797,994,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 31,468 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import data.complex.exponential
import analysis.complex.basic
import analysis.calculus.mean_value
import measure_theory.borel_space
/-!
# Complex and real exponential, real logarithm
## Main statements
This file establishes the basic analytical properties of the complex and real exponential functions
(continuity, differentiability, computation of the derivative).
It also contains the definition of the real logarithm function (as the inverse of the
exponential on `(0, +∞)`, extended to `ℝ` by setting `log (-x) = log x`) and its basic
properties (continuity, differentiability, formula for the derivative).
The complex logarithm is *not* defined in this file as it relies on trigonometric functions. See
instead `trigonometric.lean`.
## Tags
exp, log
-/
noncomputable theory
open finset filter metric asymptotics set function
open_locale classical topological_space
namespace complex
/-- The complex exponential is everywhere differentiable, with the derivative `exp x`. -/
lemma has_deriv_at_exp (x : ℂ) : has_deriv_at exp (exp x) x :=
begin
rw has_deriv_at_iff_is_o_nhds_zero,
have : (1 : ℕ) < 2 := by norm_num,
refine (is_O.of_bound (∥exp x∥) _).trans_is_o (is_o_pow_id this),
filter_upwards [metric.ball_mem_nhds (0 : ℂ) zero_lt_one],
simp only [metric.mem_ball, dist_zero_right, normed_field.norm_pow],
intros z hz,
calc ∥exp (x + z) - exp x - z * exp x∥
= ∥exp x * (exp z - 1 - z)∥ : by { congr, rw [exp_add], ring }
... = ∥exp x∥ * ∥exp z - 1 - z∥ : normed_field.norm_mul _ _
... ≤ ∥exp x∥ * ∥z∥^2 :
mul_le_mul_of_nonneg_left (abs_exp_sub_one_sub_id_le (le_of_lt hz)) (norm_nonneg _)
end
lemma differentiable_exp : differentiable ℂ exp :=
λx, (has_deriv_at_exp x).differentiable_at
lemma differentiable_at_exp {x : ℂ} : differentiable_at ℂ exp x :=
differentiable_exp x
@[simp] lemma deriv_exp : deriv exp = exp :=
funext $ λ x, (has_deriv_at_exp x).deriv
@[simp] lemma iter_deriv_exp : ∀ n : ℕ, (deriv^[n] exp) = exp
| 0 := rfl
| (n+1) := by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]
lemma continuous_exp : continuous exp :=
differentiable_exp.continuous
lemma times_cont_diff_exp : ∀ {n}, times_cont_diff ℂ n exp :=
begin
refine times_cont_diff_all_iff_nat.2 (λ n, _),
induction n with n ihn,
{ exact times_cont_diff_zero.2 continuous_exp },
{ rw times_cont_diff_succ_iff_deriv,
use differentiable_exp,
rwa deriv_exp }
end
lemma measurable_exp : measurable exp := continuous_exp.measurable
end complex
section
variables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
lemma has_deriv_at.cexp (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, complex.exp (f x)) (complex.exp (f x) * f') x :=
(complex.has_deriv_at_exp (f x)).comp x hf
lemma has_deriv_within_at.cexp (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, complex.exp (f x)) (complex.exp (f x) * f') s x :=
(complex.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_cexp (hf : differentiable_within_at ℂ f s x)
(hxs : unique_diff_within_at ℂ s x) :
deriv_within (λx, complex.exp (f x)) s x = complex.exp (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.cexp.deriv_within hxs
@[simp] lemma deriv_cexp (hc : differentiable_at ℂ f x) :
deriv (λx, complex.exp (f x)) x = complex.exp (f x) * (deriv f x) :=
hc.has_deriv_at.cexp.deriv
end
section
variables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ}
{x : E} {s : set E}
lemma measurable.cexp {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f) :
measurable (λ x, complex.exp (f x)) :=
complex.measurable_exp.comp hf
lemma has_fderiv_within_at.cexp (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, complex.exp (f x)) (complex.exp (f x) • f') s x :=
(complex.has_deriv_at_exp (f x)).comp_has_fderiv_within_at x hf
lemma has_fderiv_at.cexp (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, complex.exp (f x)) (complex.exp (f x) • f') x :=
has_fderiv_within_at_univ.1 $ hf.has_fderiv_within_at.cexp
lemma differentiable_within_at.cexp (hf : differentiable_within_at ℂ f s x) :
differentiable_within_at ℂ (λ x, complex.exp (f x)) s x :=
hf.has_fderiv_within_at.cexp.differentiable_within_at
@[simp] lemma differentiable_at.cexp (hc : differentiable_at ℂ f x) :
differentiable_at ℂ (λx, complex.exp (f x)) x :=
hc.has_fderiv_at.cexp.differentiable_at
lemma differentiable_on.cexp (hc : differentiable_on ℂ f s) :
differentiable_on ℂ (λx, complex.exp (f x)) s :=
λx h, (hc x h).cexp
@[simp] lemma differentiable.cexp (hc : differentiable ℂ f) :
differentiable ℂ (λx, complex.exp (f x)) :=
λx, (hc x).cexp
lemma times_cont_diff.cexp {n} (h : times_cont_diff ℂ n f) :
times_cont_diff ℂ n (λ x, complex.exp (f x)) :=
complex.times_cont_diff_exp.comp h
lemma times_cont_diff_at.cexp {n} (hf : times_cont_diff_at ℂ n f x) :
times_cont_diff_at ℂ n (λ x, complex.exp (f x)) x :=
complex.times_cont_diff_exp.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.cexp {n} (hf : times_cont_diff_on ℂ n f s) :
times_cont_diff_on ℂ n (λ x, complex.exp (f x)) s :=
complex.times_cont_diff_exp.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.cexp {n} (hf : times_cont_diff_within_at ℂ n f s x) :
times_cont_diff_within_at ℂ n (λ x, complex.exp (f x)) s x :=
complex.times_cont_diff_exp.times_cont_diff_at.comp_times_cont_diff_within_at x hf
end
namespace real
variables {x y z : ℝ}
lemma has_deriv_at_exp (x : ℝ) : has_deriv_at exp (exp x) x :=
(complex.has_deriv_at_exp x).real_of_complex
lemma times_cont_diff_exp {n} : times_cont_diff ℝ n exp :=
complex.times_cont_diff_exp.real_of_complex
lemma differentiable_exp : differentiable ℝ exp :=
λx, (has_deriv_at_exp x).differentiable_at
lemma differentiable_at_exp : differentiable_at ℝ exp x :=
differentiable_exp x
@[simp] lemma deriv_exp : deriv exp = exp :=
funext $ λ x, (has_deriv_at_exp x).deriv
@[simp] lemma iter_deriv_exp : ∀ n : ℕ, (deriv^[n] exp) = exp
| 0 := rfl
| (n+1) := by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]
lemma continuous_exp : continuous exp :=
differentiable_exp.continuous
lemma measurable_exp : measurable exp := continuous_exp.measurable
end real
section
/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
variables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}
lemma has_deriv_at.exp (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, real.exp (f x)) (real.exp (f x) * f') x :=
(real.has_deriv_at_exp (f x)).comp x hf
lemma has_deriv_within_at.exp (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, real.exp (f x)) (real.exp (f x) * f') s x :=
(real.has_deriv_at_exp (f x)).comp_has_deriv_within_at x hf
lemma deriv_within_exp (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, real.exp (f x)) s x = real.exp (f x) * (deriv_within f s x) :=
hf.has_deriv_within_at.exp.deriv_within hxs
@[simp] lemma deriv_exp (hc : differentiable_at ℝ f x) :
deriv (λx, real.exp (f x)) x = real.exp (f x) * (deriv f x) :=
hc.has_deriv_at.exp.deriv
end
section
/-! Register lemmas for the derivatives of the composition of `real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ}
{x : E} {s : set E}
lemma measurable.exp {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, real.exp (f x)) :=
real.measurable_exp.comp hf
lemma times_cont_diff.exp {n} (hf : times_cont_diff ℝ n f) :
times_cont_diff ℝ n (λ x, real.exp (f x)) :=
real.times_cont_diff_exp.comp hf
lemma times_cont_diff_at.exp {n} (hf : times_cont_diff_at ℝ n f x) :
times_cont_diff_at ℝ n (λ x, real.exp (f x)) x :=
real.times_cont_diff_exp.times_cont_diff_at.comp x hf
lemma times_cont_diff_on.exp {n} (hf : times_cont_diff_on ℝ n f s) :
times_cont_diff_on ℝ n (λ x, real.exp (f x)) s :=
real.times_cont_diff_exp.comp_times_cont_diff_on hf
lemma times_cont_diff_within_at.exp {n} (hf : times_cont_diff_within_at ℝ n f s x) :
times_cont_diff_within_at ℝ n (λ x, real.exp (f x)) s x :=
real.times_cont_diff_exp.times_cont_diff_at.comp_times_cont_diff_within_at x hf
lemma has_fderiv_within_at.exp (hf : has_fderiv_within_at f f' s x) :
has_fderiv_within_at (λ x, real.exp (f x)) (real.exp (f x) • f') s x :=
begin
convert (has_deriv_at_iff_has_fderiv_at.1 $
real.has_deriv_at_exp (f x)).comp_has_fderiv_within_at x hf,
ext y, simp [mul_comm]
end
lemma has_fderiv_at.exp (hf : has_fderiv_at f f' x) :
has_fderiv_at (λ x, real.exp (f x)) (real.exp (f x) • f') x :=
has_fderiv_within_at_univ.1 $ hf.has_fderiv_within_at.exp
lemma differentiable_within_at.exp (hf : differentiable_within_at ℝ f s x) :
differentiable_within_at ℝ (λ x, real.exp (f x)) s x :=
hf.has_fderiv_within_at.exp.differentiable_within_at
@[simp] lemma differentiable_at.exp (hc : differentiable_at ℝ f x) :
differentiable_at ℝ (λx, real.exp (f x)) x :=
hc.has_fderiv_at.exp.differentiable_at
lemma differentiable_on.exp (hc : differentiable_on ℝ f s) :
differentiable_on ℝ (λx, real.exp (f x)) s :=
λx h, (hc x h).exp
@[simp] lemma differentiable.exp (hc : differentiable ℝ f) :
differentiable ℝ (λx, real.exp (f x)) :=
λx, (hc x).exp
lemma fderiv_within_exp (hf : differentiable_within_at ℝ f s x)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, real.exp (f x)) s x = real.exp (f x) • (fderiv_within ℝ f s x) :=
hf.has_fderiv_within_at.exp.fderiv_within hxs
@[simp] lemma fderiv_exp (hc : differentiable_at ℝ f x) :
fderiv ℝ (λx, real.exp (f x)) x = real.exp (f x) • (fderiv ℝ f x) :=
hc.has_fderiv_at.exp.fderiv
end
namespace real
variables {x y z : ℝ}
/-- The real exponential function tends to `+∞` at `+∞`. -/
lemma tendsto_exp_at_top : tendsto exp at_top at_top :=
begin
have A : tendsto (λx:ℝ, x + 1) at_top at_top :=
tendsto_at_top_add_const_right at_top 1 tendsto_id,
have B : ∀ᶠ x in at_top, x + 1 ≤ exp x :=
eventually_at_top.2 ⟨0, λx hx, add_one_le_exp_of_nonneg hx⟩,
exact tendsto_at_top_mono' at_top B A
end
/-- The real exponential function tends to `0` at `-∞` or, equivalently, `exp(-x)` tends to `0`
at `+∞` -/
lemma tendsto_exp_neg_at_top_nhds_0 : tendsto (λx, exp (-x)) at_top (𝓝 0) :=
(tendsto_inv_at_top_zero.comp tendsto_exp_at_top).congr (λx, (exp_neg x).symm)
/-- The real exponential function tends to `1` at `0`. -/
lemma tendsto_exp_nhds_0_nhds_1 : tendsto exp (𝓝 0) (𝓝 1) :=
by { convert continuous_exp.tendsto 0, simp }
lemma tendsto_exp_at_bot : tendsto exp at_bot (𝓝 0) :=
(tendsto_exp_neg_at_top_nhds_0.comp tendsto_neg_at_bot_at_top).congr $
λ x, congr_arg exp $ neg_neg x
lemma tendsto_exp_at_bot_nhds_within : tendsto exp at_bot (𝓝[Ioi 0] 0) :=
tendsto_inf.2 ⟨tendsto_exp_at_bot, tendsto_principal.2 $ eventually_of_forall exp_pos⟩
/-- `real.exp` as an order isomorphism between `ℝ` and `(0, +∞)`. -/
def exp_order_iso : ℝ ≃o Ioi (0 : ℝ) :=
strict_mono.order_iso_of_surjective _ (exp_strict_mono.cod_restrict exp_pos) $
(continuous_subtype_mk _ continuous_exp).surjective
(by simp only [tendsto_Ioi_at_top, subtype.coe_mk, tendsto_exp_at_top])
(by simp [tendsto_exp_at_bot_nhds_within])
@[simp] lemma coe_exp_order_iso_apply (x : ℝ) : (exp_order_iso x : ℝ) = exp x := rfl
@[simp] lemma coe_comp_exp_order_iso : coe ∘ exp_order_iso = exp := rfl
@[simp] lemma range_exp : range exp = Ioi 0 :=
by rw [← coe_comp_exp_order_iso, range_comp, exp_order_iso.range_eq, image_univ, subtype.range_coe]
@[simp] lemma map_exp_at_top : map exp at_top = at_top :=
by rw [← coe_comp_exp_order_iso, ← filter.map_map, order_iso.map_at_top, map_coe_Ioi_at_top]
@[simp] lemma comap_exp_at_top : comap exp at_top = at_top :=
by rw [← map_exp_at_top, comap_map exp_injective, map_exp_at_top]
@[simp] lemma tendsto_exp_comp_at_top {α : Type*} {l : filter α} {f : α → ℝ} :
tendsto (λ x, exp (f x)) l at_top ↔ tendsto f l at_top :=
by rw [← tendsto_comap_iff, comap_exp_at_top]
lemma tendsto_comp_exp_at_top {α : Type*} {l : filter α} {f : ℝ → α} :
tendsto (λ x, f (exp x)) at_top l ↔ tendsto f at_top l :=
by rw [← tendsto_map'_iff, map_exp_at_top]
@[simp] lemma map_exp_at_bot : map exp at_bot = 𝓝[Ioi 0] 0 :=
by rw [← coe_comp_exp_order_iso, ← filter.map_map, exp_order_iso.map_at_bot, ← map_coe_Ioi_at_bot]
lemma comap_exp_nhds_within_Ioi_zero : comap exp (𝓝[Ioi 0] 0) = at_bot :=
by rw [← map_exp_at_bot, comap_map exp_injective]
lemma tendsto_comp_exp_at_bot {α : Type*} {l : filter α} {f : ℝ → α} :
tendsto (λ x, f (exp x)) at_bot l ↔ tendsto f (𝓝[Ioi 0] 0) l :=
by rw [← map_exp_at_bot, tendsto_map'_iff]
/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,
to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to
`(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and
the derivative of `log` is `1/x` away from `0`. -/
@[pp_nodot] noncomputable def log (x : ℝ) : ℝ :=
if hx : x = 0 then 0 else exp_order_iso.symm ⟨abs x, abs_pos.2 hx⟩
lemma log_of_ne_zero (hx : x ≠ 0) : log x = exp_order_iso.symm ⟨abs x, abs_pos.2 hx⟩ := dif_neg hx
lemma log_of_pos (hx : 0 < x) : log x = exp_order_iso.symm ⟨x, hx⟩ :=
by { rw [log_of_ne_zero hx.ne'], congr, exact abs_of_pos hx }
lemma exp_log_eq_abs (hx : x ≠ 0) : exp (log x) = abs x :=
by rw [log_of_ne_zero hx, ← coe_exp_order_iso_apply, order_iso.apply_symm_apply, subtype.coe_mk]
lemma exp_log (hx : 0 < x) : exp (log x) = x :=
by { rw exp_log_eq_abs hx.ne', exact abs_of_pos hx }
lemma exp_log_of_neg (hx : x < 0) : exp (log x) = -x :=
by { rw exp_log_eq_abs (ne_of_lt hx), exact abs_of_neg hx }
@[simp] lemma log_exp (x : ℝ) : log (exp x) = x :=
exp_injective $ exp_log (exp_pos x)
lemma surj_on_log : surj_on log (Ioi 0) univ :=
λ x _, ⟨exp x, exp_pos x, log_exp x⟩
lemma log_surjective : surjective log :=
λ x, ⟨exp x, log_exp x⟩
@[simp] lemma range_log : range log = univ :=
log_surjective.range_eq
@[simp] lemma log_zero : log 0 = 0 := dif_pos rfl
@[simp] lemma log_one : log 1 = 0 :=
exp_injective $ by rw [exp_log zero_lt_one, exp_zero]
@[simp] lemma log_abs (x : ℝ) : log (abs x) = log x :=
begin
by_cases h : x = 0,
{ simp [h] },
{ rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] }
end
@[simp] lemma log_neg_eq_log (x : ℝ) : log (-x) = log x :=
by rw [← log_abs x, ← log_abs (-x), abs_neg]
lemma surj_on_log' : surj_on log (Iio 0) univ :=
λ x _, ⟨-exp x, neg_lt_zero.2 $ exp_pos x, by rw [log_neg_eq_log, log_exp]⟩
lemma log_mul (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y :=
exp_injective $
by rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]
@[simp] lemma log_inv (x : ℝ) : log (x⁻¹) = -log x :=
begin
by_cases hx : x = 0, { simp [hx] },
rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]
end
lemma log_le_log (h : 0 < x) (h₁ : 0 < y) : real.log x ≤ real.log y ↔ x ≤ y :=
by rw [← exp_le_exp, exp_log h, exp_log h₁]
lemma log_lt_log (hx : 0 < x) : x < y → log x < log y :=
by { intro h, rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] }
lemma log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y :=
by { rw [← exp_lt_exp, exp_log hx, exp_log hy] }
lemma log_pos_iff (hx : 0 < x) : 0 < log x ↔ 1 < x :=
by { rw ← log_one, exact log_lt_log_iff zero_lt_one hx }
lemma log_pos (hx : 1 < x) : 0 < log x :=
(log_pos_iff (lt_trans zero_lt_one hx)).2 hx
lemma log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 :=
by { rw ← log_one, exact log_lt_log_iff h zero_lt_one }
lemma log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1
lemma log_nonneg_iff (hx : 0 < x) : 0 ≤ log x ↔ 1 ≤ x :=
by rw [← not_lt, log_neg_iff hx, not_lt]
lemma log_nonneg (hx : 1 ≤ x) : 0 ≤ log x :=
(log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx
lemma log_nonpos_iff (hx : 0 < x) : log x ≤ 0 ↔ x ≤ 1 :=
by rw [← not_lt, log_pos_iff hx, not_lt]
lemma log_nonpos_iff' (hx : 0 ≤ x) : log x ≤ 0 ↔ x ≤ 1 :=
begin
rcases hx.eq_or_lt with (rfl|hx),
{ simp [le_refl, zero_le_one] },
exact log_nonpos_iff hx
end
lemma log_nonpos (hx : 0 ≤ x) (h'x : x ≤ 1) : log x ≤ 0 :=
(log_nonpos_iff' hx).2 h'x
lemma strict_mono_incr_on_log : strict_mono_incr_on log (set.Ioi 0) :=
λ x hx y hy hxy, log_lt_log hx hxy
lemma strict_mono_decr_on_log : strict_mono_decr_on log (set.Iio 0) :=
begin
rintros x (hx : x < 0) y (hy : y < 0) hxy,
rw [← log_abs y, ← log_abs x],
refine log_lt_log (abs_pos.2 hy.ne) _,
rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]
end
/-- The real logarithm function tends to `+∞` at `+∞`. -/
lemma tendsto_log_at_top : tendsto log at_top at_top :=
tendsto_comp_exp_at_top.1 $ by simpa only [log_exp] using tendsto_id
lemma tendsto_log_nhds_within_zero : tendsto log (𝓝[{0}ᶜ] 0) at_bot :=
begin
rw [← (show _ = log, from funext log_abs)],
refine tendsto.comp _ tendsto_abs_nhds_within_zero,
simpa [← tendsto_comp_exp_at_bot] using tendsto_id
end
lemma continuous_on_log : continuous_on log {0}ᶜ :=
begin
rw [continuous_on_iff_continuous_restrict, restrict],
conv in (log _) { rw [log_of_ne_zero (show (x : ℝ) ≠ 0, from x.2)] },
exact exp_order_iso.symm.continuous.comp (continuous_subtype_mk _ continuous_subtype_coe.norm)
end
lemma continuous_log' : continuous (λ x : {x : ℝ // 0 < x}, log x) :=
continuous_on_iff_continuous_restrict.1 $ continuous_on_log.mono $ λ x hx, ne_of_gt hx
lemma continuous_at_log (hx : x ≠ 0) : continuous_at log x :=
(continuous_on_log x hx).continuous_at $ mem_nhds_sets is_open_compl_singleton hx
@[simp] lemma continuous_at_log_iff : continuous_at log x ↔ x ≠ 0 :=
begin
refine ⟨_, continuous_at_log⟩,
rintros h rfl,
exact not_tendsto_nhds_of_tendsto_at_bot tendsto_log_nhds_within_zero _
(h.tendsto.mono_left inf_le_left)
end
lemma has_deriv_at_log_of_pos (hx : 0 < x) : has_deriv_at log x⁻¹ x :=
have has_deriv_at log (exp $ log x)⁻¹ x,
from (has_deriv_at_exp $ log x).of_local_left_inverse (continuous_at_log hx.ne')
(ne_of_gt $ exp_pos _) $ eventually.mono (lt_mem_nhds hx) @exp_log,
by rwa [exp_log hx] at this
lemma has_deriv_at_log (hx : x ≠ 0) : has_deriv_at log x⁻¹ x :=
begin
cases hx.lt_or_lt with hx hx,
{ convert (has_deriv_at_log_of_pos (neg_pos.mpr hx)).comp x (has_deriv_at_neg x),
{ ext y, exact (log_neg_eq_log y).symm },
{ field_simp [hx.ne] } },
{ exact has_deriv_at_log_of_pos hx }
end
lemma differentiable_at_log (hx : x ≠ 0) : differentiable_at ℝ log x :=
(has_deriv_at_log hx).differentiable_at
lemma differentiable_on_log : differentiable_on ℝ log {0}ᶜ :=
λ x hx, (differentiable_at_log hx).differentiable_within_at
@[simp] lemma differentiable_at_log_iff : differentiable_at ℝ log x ↔ x ≠ 0 :=
⟨λ h, continuous_at_log_iff.1 h.continuous_at, differentiable_at_log⟩
lemma deriv_log (x : ℝ) : deriv log x = x⁻¹ :=
if hx : x = 0 then
by rw [deriv_zero_of_not_differentiable_at (mt differentiable_at_log_iff.1 (not_not.2 hx)), hx,
inv_zero]
else (has_deriv_at_log hx).deriv
@[simp] lemma deriv_log' : deriv log = has_inv.inv := funext deriv_log
lemma measurable_log : measurable log :=
measurable_of_measurable_on_compl_singleton 0 $ continuous.measurable $
continuous_on_iff_continuous_restrict.1 continuous_on_log
lemma times_cont_diff_on_log {n : with_top ℕ} : times_cont_diff_on ℝ n log {0}ᶜ :=
begin
suffices : times_cont_diff_on ℝ ⊤ log {0}ᶜ, from this.of_le le_top,
refine (times_cont_diff_on_top_iff_deriv_of_open is_open_compl_singleton).2 _,
simp [differentiable_on_log, times_cont_diff_on_inv]
end
lemma times_cont_diff_at_log (hx : x ≠ 0) {n : with_top ℕ} : times_cont_diff_at ℝ n log x :=
(times_cont_diff_on_log x hx).times_cont_diff_at $ mem_nhds_sets is_open_compl_singleton hx
end real
section log_differentiable
open real
section continuity
variables {α : Type*}
lemma filter.tendsto.log {f : α → ℝ} {l : filter α} {x : ℝ} (h : tendsto f l (𝓝 x)) (hx : x ≠ 0) :
tendsto (λ x, log (f x)) l (𝓝 (log x)) :=
(continuous_at_log hx).tendsto.comp h
variables [topological_space α] {f : α → ℝ} {s : set α} {a : α}
lemma continuous.log (hf : continuous f) (h₀ : ∀ x, f x ≠ 0) : continuous (λ x, log (f x)) :=
continuous_on_log.comp_continuous hf h₀
lemma continuous_at.log (hf : continuous_at f a) (h₀ : f a ≠ 0) :
continuous_at (λ x, log (f x)) a :=
hf.log h₀
lemma continuous_within_at.log (hf : continuous_within_at f s a) (h₀ : f a ≠ 0) :
continuous_within_at (λ x, log (f x)) s a :=
hf.log h₀
lemma continuous_on.log (hf : continuous_on f s) (h₀ : ∀ x ∈ s, f x ≠ 0) :
continuous_on (λ x, log (f x)) s :=
λ x hx, (hf x hx).log (h₀ x hx)
end continuity
section deriv
variables {f : ℝ → ℝ} {x f' : ℝ} {s : set ℝ}
lemma measurable.log {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, log (f x)) :=
measurable_log.comp hf
lemma has_deriv_within_at.log (hf : has_deriv_within_at f f' s x) (hx : f x ≠ 0) :
has_deriv_within_at (λ y, log (f y)) (f' / (f x)) s x :=
begin
rw div_eq_inv_mul,
exact (has_deriv_at_log hx).comp_has_deriv_within_at x hf
end
lemma has_deriv_at.log (hf : has_deriv_at f f' x) (hx : f x ≠ 0) :
has_deriv_at (λ y, log (f y)) (f' / f x) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hf.log hx
end
lemma deriv_within.log (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, log (f x)) s x = (deriv_within f s x) / (f x) :=
(hf.has_deriv_within_at.log hx).deriv_within hxs
@[simp] lemma deriv.log (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
deriv (λx, log (f x)) x = (deriv f x) / (f x) :=
(hf.has_deriv_at.log hx).deriv
end deriv
section fderiv
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {x : E} {f' : E →L[ℝ] ℝ}
{s : set E}
lemma has_fderiv_within_at.log (hf : has_fderiv_within_at f f' s x) (hx : f x ≠ 0) :
has_fderiv_within_at (λ x, log (f x)) ((f x)⁻¹ • f') s x :=
(has_deriv_at_log hx).comp_has_fderiv_within_at x hf
lemma has_fderiv_at.log (hf : has_fderiv_at f f' x) (hx : f x ≠ 0) :
has_fderiv_at (λ x, log (f x)) ((f x)⁻¹ • f') x :=
(has_deriv_at_log hx).comp_has_fderiv_at x hf
lemma differentiable_within_at.log (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0) :
differentiable_within_at ℝ (λx, log (f x)) s x :=
(hf.has_fderiv_within_at.log hx).differentiable_within_at
@[simp] lemma differentiable_at.log (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
differentiable_at ℝ (λx, log (f x)) x :=
(hf.has_fderiv_at.log hx).differentiable_at
lemma differentiable_on.log (hf : differentiable_on ℝ f s) (hx : ∀ x ∈ s, f x ≠ 0) :
differentiable_on ℝ (λx, log (f x)) s :=
λx h, (hf x h).log (hx x h)
@[simp] lemma differentiable.log (hf : differentiable ℝ f) (hx : ∀ x, f x ≠ 0) :
differentiable ℝ (λx, log (f x)) :=
λx, (hf x).log (hx x)
lemma fderiv_within.log (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, log (f x)) s x = (f x)⁻¹ • fderiv_within ℝ f s x :=
(hf.has_fderiv_within_at.log hx).fderiv_within hxs
@[simp] lemma fderiv.log (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
fderiv ℝ (λx, log (f x)) x = (f x)⁻¹ • fderiv ℝ f x :=
(hf.has_fderiv_at.log hx).fderiv
end fderiv
end log_differentiable
namespace real
/-- The function `exp(x)/x^n` tends to `+∞` at `+∞`, for any natural number `n` -/
lemma tendsto_exp_div_pow_at_top (n : ℕ) : tendsto (λx, exp x / x^n) at_top at_top :=
begin
refine (at_top_basis_Ioi.tendsto_iff (at_top_basis' 1)).2 (λ C hC₁, _),
have hC₀ : 0 < C, from zero_lt_one.trans_le hC₁,
have : 0 < (exp 1 * C)⁻¹ := inv_pos.2 (mul_pos (exp_pos _) hC₀),
obtain ⟨N, hN⟩ : ∃ N, ∀ k ≥ N, (↑k ^ n : ℝ) / exp 1 ^ k < (exp 1 * C)⁻¹ :=
eventually_at_top.1 ((tendsto_pow_const_div_const_pow_of_one_lt n
(one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)),
simp only [← exp_nat_mul, mul_one, div_lt_iff, exp_pos, ← div_eq_inv_mul] at hN,
refine ⟨N, trivial, λ x hx, _⟩, rw mem_Ioi at hx,
have hx₀ : 0 < x, from N.cast_nonneg.trans_lt hx,
rw [mem_Ici, le_div_iff (pow_pos hx₀ _), ← le_div_iff' hC₀],
calc x ^ n ≤ (nat_ceil x) ^ n : pow_le_pow_of_le_left hx₀.le (le_nat_ceil _) _
... ≤ exp (nat_ceil x) / (exp 1 * C) : (hN _ (lt_nat_ceil.2 hx).le).le
... ≤ exp (x + 1) / (exp 1 * C) : div_le_div_of_le (mul_pos (exp_pos _) hC₀).le
(exp_le_exp.2 $ (nat_ceil_lt_add_one hx₀.le).le)
... = exp x / C : by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne']
end
/-- The function `x^n * exp(-x)` tends to `0` at `+∞`, for any natural number `n`. -/
lemma tendsto_pow_mul_exp_neg_at_top_nhds_0 (n : ℕ) : tendsto (λx, x^n * exp (-x)) at_top (𝓝 0) :=
(tendsto_inv_at_top_zero.comp (tendsto_exp_div_pow_at_top n)).congr $ λx,
by rw [comp_app, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg]
/-- The function `(b * exp x + c) / (x ^ n)` tends to `+∞` at `+∞`, for any positive natural number
`n` and any real numbers `b` and `c` such that `b` is positive. -/
lemma tendsto_mul_exp_add_div_pow_at_top (b c : ℝ) (n : ℕ) (hb : 0 < b) (hn : 1 ≤ n) :
tendsto (λ x, (b * (exp x) + c) / (x^n)) at_top at_top :=
begin
refine tendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top 0) _)
(((tendsto_exp_div_pow_at_top n).const_mul_at_top hb).at_top_add
((tendsto_pow_neg_at_top hn).mul (@tendsto_const_nhds _ _ _ c _))),
intros x hx,
simp only [fpow_neg x n],
ring,
end
/-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+∞`, for any positive natural number
`n` and any real numbers `b` and `c` such that `b` is nonzero. -/
lemma tendsto_div_pow_mul_exp_add_at_top (b c : ℝ) (n : ℕ) (hb : 0 ≠ b) (hn : 1 ≤ n) :
tendsto (λ x, x^n / (b * (exp x) + c)) at_top (𝓝 0) :=
begin
have H : ∀ d e, 0 < d → tendsto (λ (x:ℝ), x^n / (d * (exp x) + e)) at_top (𝓝 0),
{ intros b' c' h,
convert tendsto.inv_tendsto_at_top (tendsto_mul_exp_add_div_pow_at_top b' c' n h hn),
ext x,
simpa only [pi.inv_apply] using inv_div.symm },
cases lt_or_gt_of_ne hb,
{ exact H b c h },
{ convert (H (-b) (-c) (neg_pos.mpr h)).neg,
{ ext x,
field_simp,
rw [← neg_add (b * exp x) c, neg_div_neg_eq] },
{ exact neg_zero.symm } },
end
open_locale big_operators
/-- A crude lemma estimating the difference between `log (1-x)` and its Taylor series at `0`,
where the main point of the bound is that it tends to `0`. The goal is to deduce the series
expansion of the logarithm, in `has_sum_pow_div_log_of_abs_lt_1`.
-/
lemma abs_log_sub_add_sum_range_le {x : ℝ} (h : abs x < 1) (n : ℕ) :
abs ((∑ i in range n, x^(i+1)/(i+1)) + log (1-x)) ≤ (abs x)^(n+1) / (1 - abs x) :=
begin
/- For the proof, we show that the derivative of the function to be estimated is small,
and then apply the mean value inequality. -/
let F : ℝ → ℝ := λ x, ∑ i in range n, x^(i+1)/(i+1) + log (1-x),
-- First step: compute the derivative of `F`
have A : ∀ y ∈ Ioo (-1 : ℝ) 1, deriv F y = - (y^n) / (1 - y),
{ assume y hy,
have : (∑ i in range n, (↑i + 1) * y ^ i / (↑i + 1)) = (∑ i in range n, y ^ i),
{ congr' with i,
have : (i : ℝ) + 1 ≠ 0 := ne_of_gt (nat.cast_add_one_pos i),
field_simp [this, mul_comm] },
field_simp [F, this, ← geom_series_def, geom_sum (ne_of_lt hy.2),
sub_ne_zero_of_ne (ne_of_gt hy.2), sub_ne_zero_of_ne (ne_of_lt hy.2)],
ring },
-- second step: show that the derivative of `F` is small
have B : ∀ y ∈ Icc (-abs x) (abs x), abs (deriv F y) ≤ (abs x)^n / (1 - abs x),
{ assume y hy,
have : y ∈ Ioo (-(1 : ℝ)) 1 := ⟨lt_of_lt_of_le (neg_lt_neg h) hy.1, lt_of_le_of_lt hy.2 h⟩,
calc abs (deriv F y) = abs (-(y^n) / (1 - y)) : by rw [A y this]
... ≤ (abs x)^n / (1 - abs x) :
begin
have : abs y ≤ abs x := abs_le.2 hy,
have : 0 < 1 - abs x, by linarith,
have : 1 - abs x ≤ abs (1 - y) := le_trans (by linarith [hy.2]) (le_abs_self _),
simp only [← pow_abs, abs_div, abs_neg],
apply_rules [div_le_div, pow_nonneg, abs_nonneg, pow_le_pow_of_le_left]
end },
-- third step: apply the mean value inequality
have C : ∥F x - F 0∥ ≤ ((abs x)^n / (1 - abs x)) * ∥x - 0∥,
{ have : ∀ y ∈ Icc (- abs x) (abs x), differentiable_at ℝ F y,
{ assume y hy,
have : 1 - y ≠ 0 := sub_ne_zero_of_ne (ne_of_gt (lt_of_le_of_lt hy.2 h)),
simp [F, this] },
apply convex.norm_image_sub_le_of_norm_deriv_le this B (convex_Icc _ _) _ _,
{ simpa using abs_nonneg x },
{ simp [le_abs_self x, neg_le.mp (neg_le_abs_self x)] } },
-- fourth step: conclude by massaging the inequality of the third step
simpa [F, norm_eq_abs, div_mul_eq_mul_div, pow_succ'] using C
end
/-- Power series expansion of the logarithm around `1`. -/
theorem has_sum_pow_div_log_of_abs_lt_1 {x : ℝ} (h : abs x < 1) :
has_sum (λ (n : ℕ), x ^ (n + 1) / (n + 1)) (-log (1 - x)) :=
begin
rw summable.has_sum_iff_tendsto_nat,
show tendsto (λ (n : ℕ), ∑ (i : ℕ) in range n, x ^ (i + 1) / (i + 1)) at_top (𝓝 (-log (1 - x))),
{ rw [tendsto_iff_norm_tendsto_zero],
simp only [norm_eq_abs, sub_neg_eq_add],
refine squeeze_zero (λ n, abs_nonneg _) (abs_log_sub_add_sum_range_le h) _,
suffices : tendsto (λ (t : ℕ), abs x ^ (t + 1) / (1 - abs x)) at_top
(𝓝 (abs x * 0 / (1 - abs x))), by simpa,
simp only [pow_succ],
refine (tendsto_const_nhds.mul _).div_const,
exact tendsto_pow_at_top_nhds_0_of_lt_1 (abs_nonneg _) h },
show summable (λ (n : ℕ), x ^ (n + 1) / (n + 1)),
{ refine summable_of_norm_bounded _ (summable_geometric_of_lt_1 (abs_nonneg _) h) (λ i, _),
calc ∥x ^ (i + 1) / (i + 1)∥
= abs x ^ (i+1) / (i+1) :
begin
have : (0 : ℝ) ≤ i + 1 := le_of_lt (nat.cast_add_one_pos i),
rw [norm_eq_abs, abs_div, ← pow_abs, abs_of_nonneg this],
end
... ≤ abs x ^ (i+1) / (0 + 1) :
begin
apply_rules [div_le_div_of_le_left, pow_nonneg, abs_nonneg, add_le_add_right,
i.cast_nonneg],
norm_num,
end
... ≤ abs x ^ i :
by simpa [pow_succ'] using mul_le_of_le_one_right (pow_nonneg (abs_nonneg x) i) (le_of_lt h) }
end
end real
|
d712bc8007de3d2f0246f7a99063f72d5ce2fa70 | 9bf90df35bb15a2f76571e35c48192142a328c40 | /src/ch7.lean | edda5cd3b966e210822513e0540defa079f3d9da | [] | no_license | ehaskell1/set_theory | ed0726520e84990d5f3180bafa0a3674ed31fb5e | e6c829c4dd953d98c9cba08f9f79784cd91794fb | refs/heads/master | 1,693,282,405,362 | 1,636,928,916,000 | 1,636,928,916,000 | 428,055,746 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 100,092 | lean | import ch6
universe u
namespace Set
local attribute [irreducible] mem
structure part_order (R : Set) : Prop :=
(rel : R.is_rel)
(trans : R.transitive)
(irrefl : ∀ ⦃x : Set⦄, x.pair x ∉ R)
def part_le (R x y : Set) : Prop := x.pair y ∈ R ∨ x = y
-- Theorem 7A part a
theorem not_lt_and_gt_part {R : Set} (hR : R.part_order) {x y : Set} : ¬ (x.pair y ∈ R ∧ y.pair x ∈ R) :=
(assume h, hR.irrefl (hR.trans h.left h.right))
-- Theorem 7A part b
theorem eq_of_le_of_ge {R : Set} (hR : R.part_order) {x y : Set} (hxy : R.part_le x y) (hyx : R.part_le y x) : x = y :=
begin
cases hxy,
cases hyx,
exfalso, exact not_lt_and_gt_part hR ⟨hxy, hyx⟩,
exact hyx.symm,
exact hxy,
end
lemma part_order_of_lin_order {A R : Set} (hR : A.lin_order R) : R.part_order :=
⟨λ z, assume hz, is_pair_of_mem_prod (hR.rel hz), hR.trans, hR.irrefl⟩
structure struct : Type (u+1) :=
(fld rel : Set.{u})
(is_rel : rel ⊆ fld.prod fld)
@[ext]
lemma struct.ext (S R : struct) (fe : R.fld = S.fld) (re : R.rel = S.rel) : R = S :=
begin
cases R, cases S, dsimp at fe re, simp only [re, fe], exact ⟨rfl, rfl⟩,
end
def is_least (D R m : Set) : Prop := ¬ ∃ x : Set, x ∈ D ∧ x.pair m ∈ R
theorem least_unique {A R : Set} (lin : A.lin_order R) {D : Set} (DA : D ⊆ A) {m n : Set} (mD : m ∈ D) (nD : n ∈ D)
(ml : D.is_least R m) (nl : D.is_least R n) : m = n :=
begin
apply classical.by_contradiction, intro mn,
cases lin.conn (DA mD) (DA nD) mn with mln nlm,
exact nl ⟨_, mD, mln⟩,
exact ml ⟨_, nD, nlm⟩,
end
structure well_order (A R : Set) : Prop :=
(lin : A.lin_order R)
(well : ∀ ⦃X : Set⦄, X ≠ ∅ → X ⊆ A → ∃ m : Set, m ∈ X ∧ X.is_least R m)
-- Theorem 7B
theorem well_order_iff_not_exists_desc_chain {A R : Set} (hlin : A.lin_order R) :
A.well_order R ↔ ¬ ∃ f : Set, f.into_fun ω A ∧ ∀ ⦃n : Set⦄, n ∈ ω → (f.fun_value n.succ).pair (f.fun_value n) ∈ R :=
begin
split,
rintros hwell ⟨f, finto, hf⟩,
have hran : f.ran ≠ ∅, apply ne_empty_of_inhabited, use f.fun_value ∅,
apply fun_value_def'' finto.left, rw finto.right.left, exact zero_nat,
obtain ⟨m, hm, hl⟩ := hwell.well hran finto.right.right,
obtain ⟨x, hx, he⟩ := eq_fun_value_of_mem_ran finto.left hm, subst he,
apply hl, use f.fun_value x.succ, split,
apply fun_value_def'' finto.left, rw finto.right.left at *, exact nat_induct.succ_closed hx,
rw finto.right.left at hx, exact hf hx,
intro ne, apply classical.by_contradiction, intro nw, apply ne,
have h : ¬ ∀ ⦃X : Set⦄, X ≠ ∅ → X ⊆ A → ∃ m : Set, m ∈ X ∧ X.is_least R m,
intro h, apply nw, exact ⟨hlin, h⟩,
dsimp [is_least] at h, push_neg at h, rcases h with ⟨X, ne, hX, h⟩,
have Rrel : R.is_rel := λ z hz, is_pair_of_mem_prod (hlin.rel hz),
obtain ⟨f, finto, hf⟩ := exists_desc_chain_of_no_least ne Rrel h,
exact ⟨f, into_of_into_ran_sub hX finto, hf⟩,
end
def seg (R t : Set) : Set := {x ∈ R.dom | x.pair t ∈ R}
@[simp]
lemma mem_seg {R t x : Set} : x ∈ R.seg t ↔ x.pair t ∈ R :=
begin
simp only [seg, mem_sep, mem_dom, and_iff_right_iff_imp], intro hxt, exact ⟨_, hxt⟩,
end
-- example
lemma seg_nat {n : Set} (hn : n ∈ ω) : (pair_sep (λ m n, m ∈ n) ω ω).seg n = n :=
begin
apply ext, intro m, simp only [mem_seg, pair_mem_pair_sep], split,
rintro ⟨-, -, hmn⟩, exact hmn,
intro hmn, exact ⟨mem_nat_of_mem_nat_of_mem hn hmn, hn, hmn⟩,
end
def ind (A R B : Set) : Prop := ∀ ⦃t : Set⦄, t ∈ A → R.seg t ⊆ B → t ∈ B
theorem transfinite_ind {A R : Set} (hwell : A.well_order R) {B : Set} (hBA : B ⊆ A) (h : A.ind R B) : B = A :=
begin
apply classical.by_contradiction, intro hne,
have dne := diff_ne_empty_of_ne hBA hne,
obtain ⟨m, hmB, hl⟩ := hwell.well dne subset_diff,
rw mem_diff at hmB, apply hmB.right, apply h hmB.left,
intros y hy, rw mem_seg at hy, apply classical.by_contradiction, intro hyB,
apply hl, refine ⟨_, _, hy⟩, rw mem_diff, refine ⟨_, hyB⟩,
have hz : y.pair m ∈ A.prod A := hwell.lin.rel hy,
rw pair_mem_prod at hz, exact hz.left,
end
-- Theorem 7C
theorem transfinite_ind_conv {A R : Set} (hlin : A.lin_order R) (h : ∀ ⦃B : Set⦄, B ⊆ A → A.ind R B → B = A) : A.well_order R :=
begin
refine ⟨hlin, _⟩, intros C hC hCA,
let B : Set := {t ∈ A | ∀ {x}, x ∈ C → t.pair x ∈ R},
have hBC : B ∩ C = ∅, rw eq_empty, intros t ht, rw [mem_inter, mem_sep] at ht,
exact hlin.irrefl (ht.left.right ht.right),
have hBA : B ⊆ A := sep_subset,
by_cases hcase : A.ind R B,
rw h hBA hcase at hBC, exfalso, apply hC, rw eq_empty, intros x hx, apply mem_empty x, rw [←hBC, mem_inter],
exact ⟨hCA hx, hx⟩,
dsimp [ind] at hcase, push_neg at hcase, rcases hcase with ⟨t, htA, hseg, htB⟩, use t, split,
rw [mem_sep] at htB, push_neg at htB,
obtain ⟨x, hxC, htx⟩ := htB htA,
have hxt : x = t, apply classical.by_contradiction, intro hxt,
cases hlin.conn (hCA hxC) htA hxt with hxt' hxt',
apply mem_empty x, rw [←hBC, mem_inter], split,
apply hseg, rw mem_seg, exact hxt',
exact hxC,
exact htx hxt',
subst hxt, exact hxC,
rintro ⟨x, hxC, hxt⟩, apply mem_empty x, rw [←hBC, mem_inter], split,
apply hseg, rw mem_seg, exact hxt,
exact hxC,
end
def lin_le (R x y : Set) : Prop := x.pair y ∈ R ∨ x = y
lemma le_iff_not_lt {A R : Set} (hlin : A.lin_order R) {x : Set} (hx : x ∈ A) {y : Set} (hy : y ∈ A) :
R.lin_le x y ↔ ¬ y.pair x ∈ R :=
begin
split,
rintro (hxy|hxy); intro hyx,
exact hlin.irrefl (hlin.trans hxy hyx),
subst hxy, exact hlin.irrefl hyx,
intro hyx, by_cases hc : x = y,
exact or.inr hc,
cases hlin.conn hx hy hc,
exact or.inl h,
exfalso, exact hyx h,
end
lemma lt_iff_not_le {A R : Set} (hlin : A.lin_order R) {x : Set} (hx : x ∈ A) {y : Set} (hy : y ∈ A) :
x.pair y ∈ R ↔ ¬ R.lin_le y x :=
begin
rw le_iff_not_lt hlin hy hx, simp only [not_not],
end
lemma mem_fld_of_lt {A R : Set} (hlin : A.lin_order R) {x y : Set} (hxy : x.pair y ∈ R) : x ∈ A :=
begin
have hxy' : x.pair y ∈ A.prod A := hlin.rel hxy,
rw pair_mem_prod at hxy', exact hxy'.left,
end
lemma mem_fld_of_le {A R : Set} (hlin : A.lin_order R) {y : Set} (hy : y ∈ A) {x : Set} (hxy : R.lin_le x y) : x ∈ A :=
begin
cases hxy,
exact mem_fld_of_lt hlin hxy,
subst hxy, exact hy,
end
lemma lt_or_le {A R : Set} (hlin : A.lin_order R) {x : Set} (hx : x ∈ A) {y : Set} (hy : y ∈ A) :
x.pair y ∈ R ∨ R.lin_le y x :=
begin
by_cases hxy : x.pair y ∈ R,
exact or.inl hxy,
rw ←le_iff_not_lt hlin hy hx at hxy, exact or.inr hxy,
end
lemma le_or_le {A R : Set} (hlin : A.lin_order R) {x : Set} (hx : x ∈ A) {y : Set} (hy : y ∈ A) :
R.lin_le x y ∨ R.lin_le y x :=
begin
cases lt_or_le hlin hx hy,
left, left, exact h,
right, exact h,
end
lemma lt_of_le_of_lt {A R : Set} (hlin : A.lin_order R) {x y : Set} (hxy : R.lin_le x y) {z : Set} (hyz : y.pair z ∈ R) :
x.pair z ∈ R :=
begin
cases hxy,
exact hlin.trans hxy hyz,
subst hxy, exact hyz,
end
lemma lt_of_lt_of_le {A R : Set} (hlin : A.lin_order R) {x y : Set} (hxy : x.pair y ∈ R) {z : Set} (hyz : R.lin_le y z) :
x.pair z ∈ R :=
begin
cases hyz,
exact hlin.trans hxy hyz,
subst hyz, exact hxy,
end
lemma le_of_le_of_le {A R : Set} (hlin : A.lin_order R) {x y : Set} (hxy : R.lin_le x y) {z : Set} (hyz : R.lin_le y z) :
R.lin_le x z :=
begin
cases hxy,
left, exact lt_of_lt_of_le hlin hxy hyz,
subst hxy, exact hyz,
end
lemma seg_subset_seg {A R : Set} (hlin : A.lin_order R) {x t : Set} (hxt : x.pair t ∈ R) : R.seg x ⊆ R.seg t :=
begin
intros z hz, rw mem_seg at *, exact hlin.trans hz hxt,
end
lemma seg_subset_seg_of_le {A R : Set} (hlin : A.lin_order R) {x y : Set} (hxy : R.lin_le x y)
: R.seg x ⊆ R.seg y :=
begin
cases hxy,
exact seg_subset_seg hlin hxy,
subst hxy, exact subset_self,
end
lemma seg_inter_of_lt {A R : Set} (hlin : A.lin_order R) {x t : Set} (hxt : x.pair t ∈ R) : {t} ∩ R.seg x = ∅ :=
begin
rw eq_empty, intros z hz, rw [mem_inter, mem_seg, mem_singleton] at hz, rcases hz with ⟨he, hzx⟩, subst he,
exact hlin.irrefl (hlin.trans hzx hxt),
end
lemma seg_inter {A R : Set} (hlin : A.lin_order R) {x : Set} : {x} ∩ R.seg x = ∅ :=
begin
rw eq_empty, intros z hz, rw [mem_inter, mem_singleton, mem_seg] at hz, cases hz with he hzx,
subst he, exact hlin.irrefl hzx,
end
lemma mem_fld_of_pair_mem_struct {R : struct} {x y : Set} (hxy : x.pair y ∈ R.rel) : x ∈ R.fld ∧ y ∈ R.fld :=
begin
replace hxy := R.is_rel hxy, rw pair_mem_prod at hxy, exact hxy,
end
lemma seg_sub_fld {R : struct} {t : Set} (tA : t ∈ R.fld) : R.rel.seg t ⊆ R.fld :=
begin
intros x xt, rw mem_seg at xt, exact (mem_fld_of_pair_mem_struct xt).left,
end
lemma seg_sub {A R : Set} (Rsub : R ⊆ A.prod A) {t : Set} (tA : t ∈ A) : R.seg t ⊆ A :=
begin
let S : struct := ⟨A, R, Rsub⟩,
have tA' : t ∈ S.fld := tA,
exact seg_sub_fld tA',
end
local attribute [instance] classical.prop_decidable
local attribute [instance] classical.all_definable
theorem replacement {p : Set.{u} → Set.{u} → Prop} {A : Set.{u}}
(h : ∀ ⦃x : Set⦄, x ∈ A → ∃! y : Set, p x y) :
∃ B : Set.{u}, ∀ {y : Set.{u}}, y ∈ B ↔ ∃ x : Set, x ∈ A ∧ p x y :=
begin
have hch : ∀ x : {x : Set // x ∈ A}, ∃ y : Set, p x.val y := λ ⟨x, hx⟩, exists_of_exists_unique (h hx),
obtain ⟨g, hg⟩ := classical.axiom_of_choice hch,
use A.image (λ x, if hx : x ∈ A then g ⟨x, hx⟩ else ∅), intro y,
simp only [mem_image, exists_prop], split,
rintro ⟨x, hx, he⟩, simp only [hx, dif_pos] at he, rw ←he, exact ⟨x, hx, hg ⟨x, hx⟩⟩,
rintro ⟨x, hx, pxy⟩, refine ⟨x, hx, _⟩, simp only [hx, dif_pos],
exact unique_of_exists_unique (h hx) (hg ⟨x, hx⟩) pxy,
end
theorem replacement' {p : Set.{u} → Set.{u} → Prop} {A : Set.{u}}
(h : ∀ ⦃x : Set⦄, x ∈ A → ∀ {y₁ : Set}, p x y₁ → ∀ {y₂ : Set}, p x y₂ → y₁ = y₂) :
∃ B : Set.{u}, ∀ {y : Set.{u}}, y ∈ B ↔ ∃ x : Set, x ∈ A ∧ p x y :=
begin
let q : Set → Set → Prop := λ x y, p x y ∨ (¬ ∃ y, p x y) ∧ y = ∅,
have h : ∀ x : Set, x ∈ A → ∃! y : Set, q x y, intros x hx, by_cases hc : ∃ y, p x y,
rcases hc with ⟨y, pxy⟩, refine ⟨_, or.inl pxy, _⟩, rintros y' (pxy'|hc),
exact h hx pxy' pxy,
exfalso, exact hc.left ⟨_, pxy⟩,
refine ⟨_, or.inr ⟨hc, rfl⟩, _⟩, rintros y' (pxy'|hc),
exfalso, exact hc ⟨_, pxy'⟩,
exact hc.right,
obtain ⟨B, hB⟩ := replacement h,
use {y ∈ B | ∃ x, x ∈ A ∧ p x y}, intro y, rw [mem_sep, hB],
simp only [and_imp, and_iff_right_iff_imp, exists_imp_distrib],
intros x hx pxy, exact ⟨_, hx, or.inl pxy⟩,
end
theorem replacement'' (f : Set.{u} → Set.{u}) {A : Set.{u}} :
∃ B : Set.{u}, ∀ {y : Set.{u}}, y ∈ B ↔ ∃ x : Set, x ∈ A ∧ y = f x :=
begin
apply replacement, intros x xA, exact exists_unique_eq f _,
end
noncomputable def repl_img (f : Set → Set) (A : Set) : Set := classical.some (@replacement'' f A)
lemma mem_repl_img {f : Set → Set} {A y : Set} : y ∈ repl_img f A ↔ ∃ x : Set, x ∈ A ∧ y = f x :=
classical.some_spec (@replacement'' f A)
lemma repl_img_sub_of_closed {f : Set → Set} {X : Set}
(h₁ : ∀ {x : Set}, x ∈ X → f x ∈ X) : repl_img f X ⊆ X :=
begin
intro y, rw mem_repl_img, rintro ⟨x, xX, yfx⟩, subst yfx, exact h₁ xX,
end
lemma of_repl_img {f : Set → Set} {X : Set} {p : Set → Prop} (h : ∀ {x : Set}, x ∈ X → p (f x)) :
∀ ⦃y : Set⦄, y ∈ repl_img f X → p y :=
begin
intro y, rw mem_repl_img, rintro ⟨x, xX, yfx⟩, subst yfx, exact h xX,
end
lemma repl_img_ext {X : Set} {f g : Set → Set} (h : ∀ ⦃x : Set⦄, x ∈ X → f x = g x)
: repl_img f X = repl_img g X :=
begin
apply ext, intro z, simp only [mem_repl_img], apply exists_congr, finish,
end
lemma repl_img_comp {X : Set} {f g : Set → Set} : repl_img f (repl_img g X) = repl_img (f ∘ g) X :=
begin
apply ext, simp only [mem_repl_img, function.comp_app], intro z, split,
finish,
tauto,
end
lemma repl_img_equin_self {X : Set}
{f : Set → Set} (foto : ∀ {x₁ : Set}, x₁ ∈ X → ∀ {x₂ : Set}, x₂ ∈ X → f x₁ = f x₂ → x₁ = x₂) :
X ≈ (repl_img f X) :=
begin
let F := pair_sep_eq X (repl_img f X) f,
refine ⟨F, ⟨pair_sep_eq_is_fun, pair_sep_eq_dom_eq _, pair_sep_eq_ran_eq _⟩, pair_sep_eq_oto @foto⟩,
{ intros x xX, rw mem_repl_img, exact ⟨_, xX, rfl⟩, },
{ intro y, simp only [mem_repl_img, and_imp, exists_imp_distrib], intros x xX yx, subst yx, exact ⟨_, xX, rfl⟩, },
end
lemma repl_img_inf_of_inf {X : Set} (Xfin : ¬ X.is_finite)
{f : Set → Set} (foto : ∀ {x₁ : Set}, x₁ ∈ X → ∀ {x₂ : Set}, x₂ ∈ X → f x₁ = f x₂ → x₁ = x₂) :
¬ (repl_img f X).is_finite :=
begin
intro fin, apply Xfin, apply finite_of_equin_finite fin,
exact equin_symm (repl_img_equin_self @foto),
end
theorem transfinite_rec {p : Set.{u} → Set.{u} → Prop} {A R : Set.{u}} (hwell : A.well_order R)
(h : ∀ f : Set, ∃! y, p f y)
: ∃! F : Set, F.is_function ∧ F.dom = A ∧ ∀ ⦃t : Set⦄, t ∈ A → p (F.restrict (R.seg t)) (F.fun_value t) :=
begin
let pcon : Set.{u} → Set.{u} → Prop := (λ t v, (∀ ⦃x : Set.{u}⦄, x ∈ v.dom ↔ R.lin_le x t)
∧ ∀ ⦃x : Set⦄, x ∈ v.dom → p (v.restrict (R.seg x)) (v.fun_value x)),
let φ := (λ t v : Set.{u}, v.is_function ∧ pcon t v),
have prerepl : ∀ {t₁ t₂ : Set}, R.lin_le t₁ t₂ → ∀ {v₁ : Set}, φ t₁ v₁ → ∀ {v₂ : Set}, φ t₂ v₂
→ ∀ {x : Set}, x ∈ A → R.lin_le x t₁ → v₁.fun_value x = v₂.fun_value x,
intros t₁ t₂ htt v₁ φ₁ v₂ φ₂, refine classical.by_contradiction _, intros hex,
push_neg at hex,
let X := {x ∈ A | R.lin_le x t₁ ∧ v₁.fun_value x ≠ v₂.fun_value x},
replace hex : ∃ x : Set, x ∈ X,
rcases hex with ⟨x, hx, hne⟩, use x, rw mem_sep, exact ⟨hx, hne⟩,
obtain ⟨x, hx, hle⟩ := hwell.well (ne_empty_of_inhabited X hex) (sep_subset),
have he : v₁.restrict (R.seg x) = v₂.restrict (R.seg x),
have hsub₁ : R.seg x ⊆ v₁.dom, intros z hz, rw φ₁.right.left, rw mem_seg at hz, left,
rw mem_sep at hx, exact lt_of_lt_of_le hwell.lin hz hx.right.left,
have hsub₂ : R.seg x ⊆ v₂.dom, intros z hz, rw φ₂.right.left, rw mem_seg at hz, left,
rw mem_sep at hx, exact lt_of_lt_of_le hwell.lin (lt_of_lt_of_le hwell.lin hz hx.right.left) htt,
apply fun_ext (restrict_is_function φ₁.left) (restrict_is_function φ₂.left),
rw [restrict_dom hsub₁, restrict_dom hsub₂],
intros z hz, rw restrict_dom hsub₁ at hz,
rw [restrict_fun_value φ₁.left hsub₁ hz, restrict_fun_value φ₂.left hsub₂ hz],
apply classical.by_contradiction, intro hne, apply hle, rw mem_seg at hz,
have hzX : z ∈ X, rw mem_sep, rw mem_sep at hx,
exact ⟨mem_fld_of_lt hwell.lin hz, or.inl (lt_of_lt_of_le hwell.lin hz hx.right.left), hne⟩,
exact ⟨_, hzX, hz⟩,
rw mem_sep at hx, apply hx.right.right,
have hx₁ : x ∈ v₁.dom, rw φ₁.right.left, exact hx.right.left,
have hx₂ : x ∈ v₂.dom, rw φ₂.right.left, exact le_of_le_of_le hwell.lin hx.right.left htt,
apply unique_of_exists_unique (h (v₁.restrict (R.seg x))) (φ₁.right.right hx₁),
rw he, exact φ₂.right.right hx₂,
have hrepl : ∀ ⦃t : Set⦄, t ∈ A → ∀ {v₁ : Set}, φ t v₁ → ∀ {v₂ : Set}, φ t v₂ → v₁ = v₂,
intros t ht v₁ hv₁ v₂ hv₂, apply fun_ext hv₁.left hv₂.left,
apply ext, simp only [hv₁.right.left, hv₂.right.left, forall_const, iff_self],
intros x hx, rw hv₁.right.left at hx,
have hxA : x ∈ A := mem_fld_of_le hwell.lin ht hx,
exact prerepl (or.inr rfl) hv₁ hv₂ hxA hx,
obtain ⟨H, hH⟩ := replacement' hrepl,
let F := H.Union,
have hstar : ∀ {x y : Set}, x.pair y ∈ F ↔ ∃ v : Set, v ∈ H ∧ x.pair y ∈ v,
simp only [mem_Union, exists_prop, forall_const, iff_self],
have hfun : F.is_function, rw is_function_iff, split,
apply Union_is_rel, intros v vH, simp only [hH, φ] at vH,
rcases vH with ⟨-, -, vfun, -⟩, exact vfun.left,
simp only [hstar, hH, φ], rintros x y₁ y₂ ⟨v₁, ⟨t₁, ht₁, vfun₁, pcon₁⟩, hxy₁⟩ ⟨v₂, ⟨t₂, ht₂, vfun₂, pcon₂⟩, hxy₂⟩,
rw [fun_value_def vfun₁ hxy₁, fun_value_def vfun₂ hxy₂],
have hx₁ : R.lin_le x t₁, rw [←pcon₁.left, mem_dom], exact ⟨_, hxy₁⟩,
have hx₂ : R.lin_le x t₂, rw [←pcon₂.left, mem_dom], exact ⟨_, hxy₂⟩,
have hx : x ∈ A := mem_fld_of_le hwell.lin ht₁ hx₁,
cases le_or_le hwell.lin ht₁ ht₂ with htt htt,
exact prerepl htt ⟨vfun₁, pcon₁⟩ ⟨vfun₂, pcon₂⟩ hx hx₁,
symmetry, exact prerepl htt ⟨vfun₂, pcon₂⟩ ⟨vfun₁, pcon₁⟩ hx hx₂,
have hpcon : ∀ ⦃x : Set⦄, x ∈ F.dom → p (F.restrict (R.seg x)) (F.fun_value x), intros x hx,
simp only [mem_dom, hstar] at hx, rcases hx with ⟨y, v, vH, hxy⟩,
have vH' := vH, simp only [hH, φ, pcon, mem_dom] at vH',
rcases vH' with ⟨t, ht, vfun, vdom, hp⟩, specialize hp ⟨_, hxy⟩,
have he : v.restrict (R.seg x) = F.restrict (R.seg x),
have hsub : R.seg x ⊆ v.dom, intros z hz, rw [mem_dom, vdom], left, rw mem_seg at hz,
have hxt := (@vdom _).mp ⟨_, hxy⟩,
exact lt_of_lt_of_le hwell.lin hz hxt,
have hsub' : R.seg x ⊆ F.dom, intros z hz, simp only [mem_dom, hstar],
have hz' : z ∈ v.dom, rw [mem_dom, vdom], left, rw mem_seg at hz,
have hxt := (@vdom _).mp ⟨_, hxy⟩,
exact lt_of_lt_of_le hwell.lin hz hxt,
rw mem_dom at hz', rcases hz' with ⟨y', hzy⟩, exact ⟨_, _, vH, hzy⟩,
apply fun_ext (restrict_is_function vfun) (restrict_is_function hfun),
rw [restrict_dom hsub, restrict_dom hsub'],
intros z hz, rw restrict_dom hsub at hz,
rw [restrict_fun_value vfun hsub hz, restrict_fun_value hfun hsub' hz],
apply fun_value_def hfun, rw hstar, refine ⟨_, vH, _⟩, apply fun_value_def' vfun,
rw [mem_dom, vdom], left, rw mem_seg at hz,
have hxt := (@vdom _).mp ⟨_, hxy⟩,
exact lt_of_lt_of_le hwell.lin hz hxt,
have he' : v.fun_value x = F.fun_value x,
apply fun_value_def hfun, rw hstar, refine ⟨_, vH, _⟩, apply fun_value_def' vfun,
rw mem_dom, exact ⟨_, hxy⟩,
rw [he, he'] at hp, exact hp,
have hdom : F.dom = A, rw eq_iff_subset_and_subset, split,
intros x hx, rw [mem_dom] at hx, simp only [hstar, hH, φ, pcon] at hx,
rcases hx with ⟨y, v, ⟨t, ht, vfun, hv, hv'⟩, hxy⟩,
have hx' : x ∈ v.dom, rw mem_dom, exact ⟨_, hxy⟩,
rw hv at hx', exact mem_fld_of_le hwell.lin ht hx',
apply @classical.by_contradiction (A ⊆ F.dom), intros hin, rw subset_def at hin, push_neg at hin,
replace hin : (A \ F.dom) ≠ ∅, apply ne_empty_of_inhabited, simp only [inhab, mem_diff], exact hin,
obtain ⟨t, ht, hle⟩ := hwell.well hin subset_diff,
rw mem_diff at ht,
have hdom : R.seg t = F.dom, rw eq_iff_subset_and_subset, split,
intros x hx, rw mem_seg at hx, apply classical.by_contradiction, intro hxF, apply hle,
use x, rw mem_diff, exact ⟨⟨mem_fld_of_lt hwell.lin hx, hxF⟩, hx⟩,
intros x hx, simp only [mem_dom, hstar] at hx, rcases hx with ⟨y, v, vH, hxy⟩,
have vH' := vH, simp only [hH, φ, pcon, mem_dom] at vH',
rcases vH' with ⟨t', ht', -, hv, -⟩,
cases lt_or_le hwell.lin ht' ht.left with htt htt,
rw mem_seg, replace hxy := (@hv _).mp ⟨_, hxy⟩, exact lt_of_le_of_lt hwell.lin hxy htt,
rw ←hv at htt, cases htt with y' hty, exfalso, apply ht.right,
simp only [mem_dom, hstar], exact ⟨_, _, vH, hty⟩,
rcases exists_of_exists_unique (h F) with ⟨y, hy⟩, apply ht.right,
simp only [mem_dom, hstar, hH, φ, pcon], use y, use F ∪ {t.pair y}, rw and_comm, split,
rw [mem_union, mem_singleton], right, refl,
use t, split,
exact ht.left,
split, exact union_singleton_is_fun hfun ht.right, split, simp only [←mem_dom],
simp only [union_dom, mem_union, mem_singleton, ←hdom, dom_singleton, lin_le, mem_seg, forall_const, iff_self],
simp only [←mem_dom], simp only [union_dom, ←hdom, dom_singleton, mem_union, mem_singleton, mem_seg],
rintros x (hxt|hxt),
have hsub : R.seg x ⊆ F.dom, rw ←hdom, exact seg_subset_seg hwell.lin hxt,
have hsub' : R.seg x ⊆ (F ∪ {t.pair y}).dom, rw [union_dom, dom_singleton], exact subset_union_of_subset_left hsub,
have he : (F ∪ {t.pair y}).restrict (R.seg x) = F.restrict (R.seg x),
apply fun_ext (restrict_is_function (union_singleton_is_fun hfun ht.right)) (restrict_is_function hfun),
simp only [restrict_dom_inter, union_dom, dom_singleton, ←hdom, union_inter, seg_inter_of_lt hwell.lin hxt, union_empty],
simp only [restrict_dom_inter, union_dom, dom_singleton, ←hdom, union_inter],
simp only [seg_inter_of_lt hwell.lin hxt, union_empty, inter_eq_of_subset (seg_subset_seg hwell.lin hxt)],
intros z hz,
rw restrict_fun_value (union_singleton_is_fun hfun ht.right) hsub' hz,
rw restrict_fun_value hfun hsub hz, symmetry, apply fun_value_def (union_singleton_is_fun hfun ht.right),
rw mem_union, left, apply fun_value_def' hfun, rw ←hdom, exact (seg_subset_seg hwell.lin hxt) hz,
have he' : (F ∪ {t.pair y}).fun_value x = F.fun_value x, symmetry,
apply fun_value_def (union_singleton_is_fun hfun ht.right), rw mem_union, left,
apply fun_value_def' hfun, rw [←hdom, mem_seg], exact hxt,
rw [he, he'],
have hx : x ∈ F.dom, rw [←hdom, mem_seg], exact hxt,
exact hpcon hx,
subst hxt,
have he : (F ∪ {x.pair y}).restrict (R.seg x) = F,
apply fun_ext (restrict_is_function (union_singleton_is_fun hfun ht.right)) hfun,
rw [restrict_dom_inter, union_dom, dom_singleton, union_inter, seg_inter hwell.lin, union_empty, hdom],
rw inter_eq_of_subset subset_self,
intros z hz,
rw [restrict_dom_inter, union_dom, dom_singleton, union_inter, seg_inter hwell.lin, union_empty, hdom, inter_eq_of_subset subset_self] at hz,
have hsub : R.seg x ⊆ (F ∪ {x.pair y}).dom, rw [union_dom, dom_singleton, hdom], exact subset_union_left,
rw ←hdom at hz, rw restrict_fun_value (union_singleton_is_fun hfun ht.right) hsub hz, symmetry,
apply fun_value_def (union_singleton_is_fun hfun ht.right), rw mem_union, left,
apply fun_value_def' hfun, rw ←hdom, exact hz,
have he' : (F ∪ {x.pair y}).fun_value x = y, symmetry,
apply fun_value_def (union_singleton_is_fun hfun ht.right), rw [mem_union, mem_singleton], right, refl,
rw [he, he'], exact hy,
rw hdom at hpcon,
refine exists_unique_of_exists_of_unique ⟨_, hfun, hdom, hpcon⟩ _,
rintros F F' ⟨Ffun, Fdom, hF⟩ ⟨Ffun', Fdom', hF'⟩,
let B : Set := {t ∈ A | F.fun_value t = F'.fun_value t},
suffices hBA : B = A, apply fun_ext Ffun Ffun',
rw [Fdom, Fdom'],
intros x hx, rw [Fdom, ←hBA, mem_sep] at hx, exact hx.right,
apply transfinite_ind hwell sep_subset, intros t htA ht, rw mem_sep, refine ⟨htA, _⟩,
have he : F.restrict (R.seg t) = F'.restrict (R.seg t),
apply fun_ext (restrict_is_function Ffun) (restrict_is_function Ffun'),
simp only [restrict_dom_inter, Fdom, Fdom'],
intros x hx, rw [restrict_dom_inter, mem_inter] at hx,
rw restrict_fun_value' Ffun hx.left hx.right,
rw [Fdom, ←Fdom'] at hx,
rw restrict_fun_value' Ffun' hx.left hx.right,
specialize ht hx.right, rw mem_sep at ht, exact ht.right,
specialize hF htA, specialize hF' htA, rw he at hF,
exact unique_of_exists_unique (h _) hF hF',
end
-- I think that was the longest proof yet...
theorem transfinite_rec' {A R : Set.{u}} (hwell : A.well_order R) (f : Set.{u} → Set.{u})
: ∃! F : Set, F.is_function ∧ F.dom = A ∧ ∀ ⦃t : Set⦄, t ∈ A → (F.fun_value t) = f (F.restrict (R.seg t)) :=
transfinite_rec hwell (exists_unique_eq f)
noncomputable def trans_rec (A R : Set) (f : Set → Set) : Set :=
if well : A.well_order R then
classical.some (exists_of_exists_unique (transfinite_rec' well f))
else
∅
lemma trans_rec_fun {A R : Set} (well : A.well_order R) {f : Set → Set} : (A.trans_rec R f).is_function :=
begin
simp only [trans_rec, dif_pos well],
exact (classical.some_spec (exists_of_exists_unique (transfinite_rec' well f))).left,
end
lemma trans_rec_dom {A R : Set} (well : A.well_order R) {f : Set → Set} : (A.trans_rec R f).dom = A :=
begin
simp only [trans_rec, dif_pos well],
exact (classical.some_spec (exists_of_exists_unique (transfinite_rec' well f))).right.left,
end
lemma trans_rec_spec {A R : Set} (well : A.well_order R) {f : Set → Set} :
∀ ⦃t : Set⦄, t ∈ A → (A.trans_rec R f).fun_value t = f ((A.trans_rec R f).restrict (R.seg t)) :=
begin
simp only [trans_rec, dif_pos well],
exact (classical.some_spec (exists_of_exists_unique (transfinite_rec' well f))).right.right,
end
noncomputable def eps_img_fun (R : struct) : Set :=
if case : R.fld.well_order R.rel then
classical.some (exists_of_exists_unique (@transfinite_rec (λ f y, y = f.ran) _ _ case (exists_unique_eq ran)))
else
∅
lemma eps_img_fun_spec {R : struct} (well : R.fld.well_order R.rel) :
(eps_img_fun R).is_function ∧ (eps_img_fun R).dom = R.fld
∧ ∀ ⦃t : Set⦄, t ∈ R.fld → (eps_img_fun R).fun_value t = ((eps_img_fun R).restrict (R.rel.seg t)).ran :=
begin
simp only [eps_img_fun, well, dif_pos],
exact classical.some_spec (exists_of_exists_unique (@transfinite_rec (λ f y, y = f.ran) _ _ well (exists_unique_eq ran))),
end
lemma eps_img_fun_value_img {R : struct} (well : R.fld.well_order R.rel) {t : Set} (ht : t ∈ R.fld) :
(eps_img_fun R).fun_value t = (eps_img_fun R).img (R.rel.seg t) :=
begin
obtain ⟨-, -, h⟩ := eps_img_fun_spec well,
rw [img, h ht],
end
lemma mem_eps_img_fun {R : struct} (well : R.fld.well_order R.rel) {t : Set} (ht : t ∈ R.fld) {y : Set} :
y ∈ (eps_img_fun R).fun_value t ↔ ∃ x : Set, x.pair t ∈ R.rel ∧ y = (eps_img_fun R).fun_value x :=
begin
obtain ⟨f, dom, -⟩ := eps_img_fun_spec well,
have sub : R.rel.seg t ⊆ (eps_img_fun R).dom, intros x hx, rw mem_seg at hx,
replace hx := (mem_fld_of_pair_mem_struct hx).left, rw dom, exact hx,
simp only [eps_img_fun_value_img well ht, mem_img' f sub, mem_seg],
end
lemma fun_value_mem_eps_img_fun {R : struct} (well : R.fld.well_order R.rel) {t : Set} (ht : t ∈ R.fld) {x : Set} (hx : x.pair t ∈ R.rel) :
(eps_img_fun R).fun_value x ∈ (eps_img_fun R).fun_value t :=
begin
rw mem_eps_img_fun well ht, exact ⟨_, hx, rfl⟩,
end
noncomputable def eps_img (R : struct) : Set := (eps_img_fun R).ran
@[simp]
lemma mem_eps_img {R : struct} (well : R.fld.well_order R.rel) {y : Set} :
y ∈ eps_img R ↔ ∃ x : Set, x ∈ R.fld ∧ y = (eps_img_fun R).fun_value x :=
begin
obtain ⟨f, dom, -⟩ := eps_img_fun_spec well,
rw [eps_img, mem_ran_iff f, dom],
end
lemma fun_value_mem_eps_img {R : struct} (well : R.fld.well_order R.rel) {x : Set} (hx : x ∈ R.fld) :
(eps_img_fun R).fun_value x ∈ eps_img R :=
begin
rw mem_eps_img well, exact ⟨_, hx, rfl⟩,
end
-- Theorem 7D part a
theorem eps_img_fun_irrefl {R : struct} (well : R.fld.well_order R.rel) {t : Set} (tA : t ∈ R.fld) :
(eps_img_fun R).fun_value t ∉ (eps_img_fun R).fun_value t :=
begin
let S := {x ∈ R.fld | (eps_img_fun R).fun_value x ∈ (eps_img_fun R).fun_value x},
intro ftt,
have SE : S ≠ ∅, apply ne_empty_of_inhabited, use t, rw mem_sep, exact ⟨tA, ftt⟩,
obtain ⟨m, mS, le⟩ := well.well SE sep_subset,
rw [mem_sep] at mS, obtain ⟨mA, fmm⟩ := mS,
have fmm' := fmm, rw mem_eps_img_fun well mA at fmm', obtain ⟨x, xm, fmx⟩ := fmm',
have xA := (mem_fld_of_pair_mem_struct xm).left,
apply le, use x, rw mem_sep, rw ←fmx, exact ⟨⟨xA, fmm⟩, xm⟩,
end
-- Theorem 7D part b part 1
theorem eps_img_fun_onto {R : struct} (well : R.fld.well_order R.rel) : (eps_img_fun R).onto_fun R.fld (eps_img R) :=
begin
obtain ⟨f, dom, -⟩ := eps_img_fun_spec well,
rw [eps_img, ←dom], exact ⟨f, rfl, rfl⟩,
end
-- Theorem 7D part b part 2
theorem eps_img_fun_oto {R : struct} (well : R.fld.well_order R.rel) : (eps_img_fun R).one_to_one :=
begin
obtain ⟨f, dom, -⟩ := eps_img_fun_spec well,
apply one_to_one_of f, rw dom, intros s sA t tA st fst,
cases well.lin.conn sA tA st with slt tls,
have fslt := fun_value_mem_eps_img_fun well tA slt,
rw fst at fslt, exact eps_img_fun_irrefl well tA fslt,
have ftls := fun_value_mem_eps_img_fun well sA tls,
rw fst at ftls, exact eps_img_fun_irrefl well tA ftls,
end
-- Theorem 7D part c
theorem fun_value_mem_eps_img_fun_iff {R : struct} (well : R.fld.well_order R.rel) {s : Set} (sA : s ∈ R.fld) {t : Set} (tA : t ∈ R.fld) :
(eps_img_fun R).fun_value s ∈ (eps_img_fun R).fun_value t ↔ s.pair t ∈ R.rel :=
begin
obtain ⟨f, dom, _⟩ := eps_img_fun_spec well,
split,
intro fst, rw mem_eps_img_fun well tA at fst,
obtain ⟨x, xt, fsx⟩ := fst,
have xA := (mem_fld_of_pair_mem_struct xt).left,
rw ←dom at sA xA,
rw from_one_to_one f (eps_img_fun_oto well) xA sA fsx.symm at xt,
exact xt,
intro st, exact fun_value_mem_eps_img_fun well tA st,
end
-- Theorem 7D part d
theorem eps_img_transitive {R : struct} (well : R.fld.well_order R.rel) :
(eps_img R).transitive_set :=
begin
intros y yf, rw mem_Union at yf, obtain ⟨Y, Yf, yY⟩ := yf,
rw mem_eps_img well at Yf, obtain ⟨t, tf, Yt⟩ := Yf, subst Yt,
obtain ⟨f, dom, spec⟩ := eps_img_fun_spec well, rw [spec tf, mem_ran_iff (restrict_is_function f)] at yY,
obtain ⟨x, xt, yx⟩ := yY, subst yx,
have doms : R.rel.seg t ⊆ (eps_img_fun R).dom, rw dom, exact seg_sub_fld tf,
rw restrict_dom doms at xt, rw restrict_fun_value f doms xt, rw dom at doms,
have xA : x ∈ R.fld := doms xt,
exact fun_value_mem_eps_img well xA,
end
structure isomorphism (R S : struct) (f : Set) : Prop :=
(corr : R.fld.correspondence S.fld f)
(iso : ∀ ⦃x y : Set⦄, x ∈ R.fld → y ∈ R.fld → (x.pair y ∈ R.rel ↔ (f.fun_value x).pair (f.fun_value y) ∈ S.rel))
lemma iso_iso {R S : struct} {f : Set} (iso : f.isomorphism R S) :
∀ ⦃x y : Set⦄, x.pair y ∈ R.rel ↔ x ∈ R.fld ∧ y ∈ R.fld ∧ (f.fun_value x).pair (f.fun_value y) ∈ S.rel :=
begin
intros x y, split,
rintro xy, have xy' := R.is_rel xy, rw pair_mem_prod at xy', rw ←iso.iso xy'.left xy'.right,
exact ⟨xy'.left, xy'.right, xy⟩,
rintro ⟨xR, yR, fxy⟩, rw iso.iso xR yR, exact fxy,
end
def isomorphic (R S : struct) : Prop := ∃ f : Set, f.isomorphism R S
lemma iso_of_corr {R S : struct} {f : Set} (RS : R.fld.correspondence S.fld f)
(h : ∀ ⦃x y : Set⦄, x ∈ R.fld → y ∈ R.fld → (x.pair y ∈ R.rel ↔ (f.fun_value x).pair (f.fun_value y) ∈ S.rel)) :
isomorphic R S :=
⟨_, RS, h⟩
lemma iso_of_corr' {R S : struct} {f : Set} (RS : R.fld.correspondence S.fld f)
(h : ∀ ⦃x y : Set⦄, x.pair y ∈ R.rel ↔ x ∈ R.fld ∧ y ∈ R.fld ∧ (f.fun_value x).pair (f.fun_value y) ∈ S.rel) :
f.isomorphism R S :=
begin
refine ⟨RS, _⟩, intros x y xR yR, rw h, finish,
end
lemma equin_of_iso {R S : struct} (RS : isomorphic R S) : R.fld ≈ S.fld :=
begin
rcases RS with ⟨f, corr, -⟩, exact ⟨_, corr⟩,
end
-- Theorem 7E part 1
theorem iso_refl {R : struct} : isomorphic R R :=
begin
use R.fld.id, split,
exact ⟨id_onto, id_oto⟩,
intros x y hx hy,
rw [id_value hx, id_value hy],
end
-- Theorem 7E part 2
theorem iso_symm {R S : struct} (h : isomorphic R S) : isomorphic S R :=
begin
rcases h with ⟨f, corr, iso⟩,
have hif : f.inv.is_function, rw T3F_a, exact corr.oto,
have hio : f.inv.one_to_one, rw ←T3F_b corr.onto.left.left, exact corr.onto.left,
use f.inv, split,
exact corr_symm corr,
intros X Y hX hY,
rw ←corr.onto.right.right at hX hY,
have hfX : f.inv.fun_value X ∈ R.fld, rw [←corr.onto.right.left, ←T3E_b],
apply fun_value_def'' hif, rw T3E_a, exact hX,
have hfY: f.inv.fun_value Y ∈ R.fld, rw [←corr.onto.right.left, ←T3E_b],
apply fun_value_def'' hif, rw T3E_a, exact hY,
rw [iso hfX hfY, T3G_b corr.onto.left corr.oto _ hX, T3G_b corr.onto.left corr.oto _ hY],
end
-- Theorem 7E part 3
theorem iso_trans {R S : struct} (hRS : isomorphic R S) {T : struct} (hST : isomorphic S T) : isomorphic R T :=
begin
rcases hRS with ⟨f, fcorr, fiso⟩,
rcases hST with ⟨g, gcorr, giso⟩,
use g.comp f, split,
exact corr_trans fcorr gcorr,
intros x y hx hy,
have hfx : f.fun_value x ∈ S.fld, rw ←fcorr.onto.right.right,
apply fun_value_def'' fcorr.onto.left, rw fcorr.onto.right.left, exact hx,
have hfy : f.fun_value y ∈ S.fld, rw ←fcorr.onto.right.right,
apply fun_value_def'' fcorr.onto.left, rw fcorr.onto.right.left, exact hy,
have gfd : (g.comp f).dom = f.dom, apply dom_comp,
rw [fcorr.onto.right.right, gcorr.onto.right.left], exact subset_self,
have hx' : x ∈ (g.comp f).dom, rw gfd, rw fcorr.onto.right.left, exact hx,
have hy' : y ∈ (g.comp f).dom, rw gfd, rw fcorr.onto.right.left, exact hy,
rw [T3H_c gcorr.onto.left fcorr.onto.left hx', T3H_c gcorr.onto.left fcorr.onto.left hy'],
rw ←giso hfx hfy, rw ←fiso hx hy,
end
lemma iso_of_eq {R S : struct} (RS : R = S) : isomorphic R S :=
by rw RS; exact iso_refl
def fun_order (A R f : Set) : Set := pair_sep (λ x y, (f.fun_value x).pair (f.fun_value y) ∈ R) A A
-- Lemma 7F part a
lemma part_order_from_fun {A B f : Set} (into : f.into_fun A B) (oto : f.one_to_one)
{R : Set} (rel : R ⊆ B.prod B) (part : R.part_order) :
A.fun_order R f ⊆ A.prod A ∧ (A.fun_order R f).part_order :=
begin
refine ⟨pair_sep_sub_prod, pair_sep_is_rel, _, _⟩,
intros x y z xy yz, rw [fun_order, pair_mem_pair_sep] at *,
rcases xy with ⟨xA, -, fxy⟩, rcases yz with ⟨-, zA, fyz⟩,
exact ⟨xA, zA, part.trans fxy fyz⟩,
intros x xx, rw [fun_order, pair_mem_pair_sep] at xx, exact part.irrefl xx.right.right,
end
-- Lemma 7F part b
lemma lin_order_from_fun {A B f : Set} (into : f.into_fun A B) (oto : f.one_to_one)
{R : Set} (lin : B.lin_order R) : A.lin_order (A.fun_order R f) :=
begin
have Bpart := part_order_of_lin_order lin,
obtain ⟨rel, Apart⟩ := part_order_from_fun into oto lin.rel Bpart,
refine ⟨rel, Apart.trans, Apart.irrefl, _⟩,
intros x y xA yA xy, simp only [fun_order, pair_mem_pair_sep],
have xd : x ∈ f.dom, rw into.right.left, exact xA,
have yd : y ∈ f.dom, rw into.right.left, exact yA,
have fx : f.fun_value x ∈ B, apply into.right.right,
apply fun_value_def'' into.left, exact xd,
have fy : f.fun_value y ∈ B, apply into.right.right,
apply fun_value_def'' into.left, exact yd,
have fxy : f.fun_value x ≠ f.fun_value y, intro fxy,
exact xy (from_one_to_one into.left oto xd yd fxy),
cases lin.conn fx fy fxy,
left, exact ⟨xA, yA, h⟩,
right, exact ⟨yA, xA, h⟩,
end
-- Lemma 7F part c
lemma well_order_from_fun {A B f : Set} (into : f.into_fun A B) (oto : f.one_to_one)
{R : Set} (well : B.well_order R) : A.well_order (A.fun_order R f) :=
begin
refine ⟨lin_order_from_fun into oto well.lin, _⟩,
intros S SE SA,
rw ←into.right.left at SA,
have fSE : f.img S ≠ ∅, apply ne_empty_of_inhabited,
replace SE := inhabited_of_ne_empty SE,
cases SE with x xS, use f.fun_value x,
apply fun_value_mem_img into.left SA xS,
have fSB : f.img S ⊆ B := subset_trans img_subset_ran into.right.right,
obtain ⟨M, MfS, le⟩ := well.well fSE fSB,
rw mem_img' into.left SA at MfS, rcases MfS with ⟨m, mS, mM⟩, subst mM,
refine ⟨m, mS, _⟩, rintro ⟨x, xS, xm⟩, apply le, rw [fun_order, pair_mem_pair_sep] at xm,
refine ⟨f.fun_value x, fun_value_mem_img into.left SA xS, xm.right.right⟩,
end
lemma fun_order_eq {R S : struct} {f : Set} (fiso : f.isomorphism S R) : S.fld.fun_order R.rel f = S.rel :=
begin
apply rel_ext (pair_sep_is_rel) (sub_rel_is_rel prod_is_rel S.is_rel),
intros x y, rw pair_mem_pair_sep, split,
rintro ⟨hx, hy, fxy⟩, rw fiso.iso hx hy, exact fxy,
intro xy,
obtain ⟨hx, hy⟩ := mem_fld_of_pair_mem_struct xy,
rw ←fiso.iso hx hy, exact ⟨hx, hy, xy⟩,
end
-- Theorem 7G part a
theorem part_order_iso {R S : struct} (RS : isomorphic R S) (part : R.rel.part_order) : S.rel.part_order :=
begin
replace RS := iso_symm RS,
cases RS with f fiso,
have he := fun_order_eq fiso, rw ←he,
exact (part_order_from_fun (into_of_onto fiso.corr.onto) fiso.corr.oto R.is_rel part).right,
end
-- Theorem 7G part b
theorem lin_order_iso {R S : struct} (RS : isomorphic R S) (lin : R.fld.lin_order R.rel) : S.fld.lin_order S.rel :=
begin
replace RS := iso_symm RS,
cases RS with f fiso,
have he := fun_order_eq fiso, rw ←he,
exact (lin_order_from_fun (into_of_onto fiso.corr.onto) fiso.corr.oto lin),
end
-- Theorem 7G part c
theorem well_order_iso {R S : struct} (RS : isomorphic R S) (well : R.fld.well_order R.rel) : S.fld.well_order S.rel :=
begin
replace RS := iso_symm RS,
cases RS with f fiso,
have he := fun_order_eq fiso, rw ←he,
exact (well_order_from_fun (into_of_onto fiso.corr.onto) fiso.corr.oto well),
end
def eps_order (A : Set) : Set := pair_sep (λ x y, x ∈ y) A A
def eps_order_struct (A : Set) : struct := ⟨A, A.eps_order, pair_sep_sub_prod⟩
theorem nat_well_order' : well_order ω nat_order :=
⟨nat_order_lin, begin
intros X Xne Xsub,
obtain ⟨m, mX, le⟩ := nat_well_order Xsub Xne,
refine ⟨_, mX, _⟩, rw is_least, push_neg,
intros x xX, specialize le xX, rw nat_order,
rw pair_mem_pair_sep' (Xsub xX) (Xsub mX),
exact not_lt_of_le (Xsub mX) (Xsub xX) le,
end⟩
lemma nat_order_eq : nat_order = eps_order ω :=
begin
apply rel_ext (pair_sep_is_rel) (pair_sep_is_rel), intros m n, simp only [pair_mem_pair_sep],
end
lemma nat_order_seg {n : Set} (nω : n ∈ ω) : nat_order.seg n = n :=
begin
rw nat_order_eq, exact seg_nat nω,
end
@[simp]
lemma eps_order_struct_fld {A : Set} : A.eps_order_struct.fld = A := rfl
@[simp]
lemma eps_order_struct_rel {A : Set} : A.eps_order_struct.rel = A.eps_order := rfl
lemma pair_mem_eps_order {A x y : Set} (xA : x ∈ A) (yA : y ∈ A) : x.pair y ∈ A.eps_order_struct.rel ↔ x ∈ y :=
begin
simp only [eps_order_struct_rel, eps_order, xA, yA, true_and, pair_mem_pair_sep],
end
lemma pair_mem_eps_order' {A x y : Set} (xA : x ∈ A) (yA : y ∈ A) : x.pair y ∈ A.eps_order ↔ x ∈ y :=
pair_mem_eps_order xA yA
lemma eps_img_iso {R : struct} (well : R.fld.well_order R.rel) : (eps_img_fun R).isomorphism R (eps_img R).eps_order_struct :=
begin
refine ⟨⟨eps_img_fun_onto well, eps_img_fun_oto well⟩, _⟩,
intros x y xA yA,
have fx : (eps_img_fun R).fun_value x ∈ eps_img R := fun_value_mem_eps_img well xA,
have fy : (eps_img_fun R).fun_value y ∈ eps_img R := fun_value_mem_eps_img well yA,
rw [pair_mem_eps_order fx fy, fun_value_mem_eps_img_fun_iff well xA yA],
end
lemma eps_img_isomorphic {R : struct} (well : R.fld.well_order R.rel) : isomorphic R (eps_img R).eps_order_struct :=
⟨_, eps_img_iso well⟩
-- Corollary 7H
lemma eps_img_well_order {R : struct} (well : R.fld.well_order R.rel) : (eps_img R).well_order (eps_img R).eps_order :=
well_order_iso (eps_img_isomorphic well) well
-- Exercise 13
theorem iso_unique {R S : struct} (Rwell : R.fld.well_order R.rel) (Swell : S.fld.well_order S.rel) (iso : isomorphic R S) :
∃! f : Set, f.isomorphism R S :=
begin
apply exists_unique_of_exists_of_unique iso, intros f g fiso giso,
apply fun_ext fiso.corr.onto.left giso.corr.onto.left,
rw [fiso.corr.onto.right.left, giso.corr.onto.right.left],
intros y yA, rw fiso.corr.onto.right.left at yA, apply classical.by_contradiction, intro fg,
let X := {x ∈ R.fld | f.fun_value x ≠ g.fun_value x},
have XA : X ⊆ R.fld := sep_subset,
have XE : X ≠ ∅, apply ne_empty_of_inhabited, use y, rw mem_sep, exact ⟨yA, fg⟩,
obtain ⟨m, mA, le⟩ := Rwell.well XE XA, apply le,
rw mem_sep at mA,
have fm : f.fun_value m ∈ S.fld, rw ←fiso.corr.onto.right.right,
apply fun_value_def'' fiso.corr.onto.left, rw fiso.corr.onto.right.left, exact mA.left,
have gm : g.fun_value m ∈ S.fld, rw ←giso.corr.onto.right.right,
apply fun_value_def'' giso.corr.onto.left, rw giso.corr.onto.right.left, exact mA.left,
cases Swell.lin.conn fm gm mA.right with fgm gfm,
rw [←giso.corr.onto.right.right, mem_ran_iff giso.corr.onto.left] at fm,
rcases fm with ⟨x, xA, mx⟩, rw mx at fgm, rw giso.corr.onto.right.left at xA,
rw ←giso.iso xA mA.left at fgm, refine ⟨x, _, fgm⟩, rw mem_sep, refine ⟨xA, _⟩,
rw ←mx, intro fxm,
rw ←fiso.corr.onto.right.left at xA mA,
have xem : x = m := from_one_to_one fiso.corr.onto.left fiso.corr.oto xA mA.left fxm, subst xem,
exact Rwell.lin.irrefl fgm,
rw [←fiso.corr.onto.right.right, mem_ran_iff fiso.corr.onto.left] at gm,
rcases gm with ⟨x, xA, mx⟩, rw mx at gfm, rw fiso.corr.onto.right.left at xA,
rw ←fiso.iso xA mA.left at gfm, refine ⟨x, _, gfm⟩, rw mem_sep, refine ⟨xA, _⟩,
rw ←mx, intro gmx,
rw ←giso.corr.onto.right.left at xA mA,
have mex : m = x := from_one_to_one giso.corr.onto.left giso.corr.oto mA.left xA gmx, subst mex,
exact Rwell.lin.irrefl gfm,
end
-- Theorem 7I
theorem iso_iff_eps_img_eq {R S : struct} (Rwell : R.fld.well_order R.rel) (Swell : S.fld.well_order S.rel) :
isomorphic R S ↔ eps_img R = eps_img S :=
begin
split,
rintro ⟨f, ⟨fonto, foto⟩, fiso⟩,
obtain ⟨⟨Ronto, Roto⟩, Riso⟩ := eps_img_iso Rwell,
obtain ⟨⟨Sonto, Soto⟩, Siso⟩ := eps_img_iso Swell,
let E₁ := eps_img_fun R, let E₂ := eps_img_fun S,
let B := {s ∈ R.fld | E₁.fun_value s = E₂.fun_value (f.fun_value s)},
suffices hBA : B = R.fld, apply ext, intro x, rw [mem_eps_img Rwell, mem_eps_img Swell], split,
rintro ⟨s, sA, xfs⟩, rw [←hBA, mem_sep] at sA, rw sA.right at xfs, refine ⟨_, _, xfs⟩,
rw ←fonto.right.right, apply fun_value_def'' fonto.left, rw fonto.right.left, exact sA.left,
rintro ⟨t, tA, xft⟩, subst xft,
rw [←fonto.right.right, mem_ran_iff fonto.left] at tA,
obtain ⟨s, sA, tfs⟩ := tA, subst tfs, rw [fonto.right.left, ←hBA, mem_sep] at sA,
rw ←sA.right, exact ⟨_, sA.left, rfl⟩,
apply transfinite_ind Rwell sep_subset, intros s sA sub, rw mem_sep, refine ⟨sA, _⟩,
apply ext, intro z,
have fs : f.fun_value s ∈ S.fld, rw ←fonto.right.right, apply fun_value_def'' fonto.left, rw fonto.right.left, exact sA,
rw [mem_eps_img_fun Rwell sA, mem_eps_img_fun Swell fs], split,
rintro ⟨x, xs, zfx⟩, subst zfx, use f.fun_value x, split,
rw ←fiso (mem_fld_of_pair_mem_struct xs).left sA, exact xs,
rw ←mem_seg at xs, replace xs := sub xs, rw mem_sep at xs, exact xs.right,
rintro ⟨y, yfs, zfy⟩, subst zfy,
have yr : y ∈ f.ran, rw fonto.right.right, exact (mem_fld_of_pair_mem_struct yfs).left,
rw mem_ran_iff fonto.left at yr, obtain ⟨x, xA, yfs⟩ := yr, subst yfs, use x,
rw fonto.right.left at xA, rw ←fiso xA sA at yfs, split,
exact yfs,
symmetry, rw ←mem_seg at yfs, replace yfs := sub yfs, rw mem_sep at yfs, exact yfs.right,
intro he, apply iso_trans (eps_img_isomorphic Rwell), rw he, exact iso_symm (eps_img_isomorphic Swell),
end
def is_ordinal (S : Set) : Prop := ∃ R : struct, R.fld.well_order R.rel ∧ S = eps_img R
lemma eps_img_ord {R : struct} (Rwell : R.fld.well_order R.rel) : (eps_img R).is_ordinal :=
⟨_, Rwell, rfl⟩
lemma exists_iso_ord {R : struct} (Rwell : R.fld.well_order R.rel) : ∃ α : Set, α.is_ordinal ∧ isomorphic α.eps_order_struct R :=
⟨_, ⟨_, Rwell, rfl⟩, iso_symm (eps_img_isomorphic Rwell)⟩
def struct_restrict (R : struct) (S : Set) : struct := ⟨S, R.rel ∩ (S.prod S), inter_subset_right⟩
@[simp]
lemma struct_restrict_fld {R : struct} {S : Set} : (S.struct_restrict R).fld = S := rfl
@[simp]
lemma struct_restrict_rel {R : struct} {S : Set} : (S.struct_restrict R).rel = R.rel ∩ (S.prod S) := rfl
def part_order_on (A R : Set) : Prop := R.part_order ∧ R ⊆ A.prod A
lemma part_from_lin {A R : Set} (lin : A.lin_order R) : A.part_order_on R := ⟨part_order_of_lin_order lin, lin.rel⟩
lemma part_to_lin {A R : Set} (part : A.part_order_on R) (conn : ∀ ⦃x y : Set⦄, x ∈ A → y ∈ A → x ≠ y → x.pair y ∈ R ∨ y.pair x ∈ R) :
A.lin_order R := ⟨part.right, part.left.trans, part.left.irrefl, conn⟩
-- Theorem 7J part a
theorem part_order_struct_restrict {R : struct} (Rpart : R.fld.part_order_on R.rel) {S : Set} (SR : S ⊆ R.fld) :
(S.struct_restrict R).fld.part_order_on (S.struct_restrict R).rel :=
begin
simp, refine ⟨⟨inter_rel_is_rel Rpart.left.rel, _, _⟩, inter_subset_right⟩,
{ intros x y z xy yz, rw [mem_inter, pair_mem_prod] at *,
exact ⟨Rpart.left.trans xy.left yz.left, xy.right.left, yz.right.right⟩, },
{ intros x xx, rw mem_inter at xx, exact Rpart.left.irrefl xx.left, },
end
-- Theorem 7J part b
theorem lin_order_struct_restrict {R : struct} (Rlin : R.fld.lin_order R.rel) {S : Set} (SR : S ⊆ R.fld) :
(S.struct_restrict R).fld.lin_order (S.struct_restrict R).rel :=
begin
apply part_to_lin (part_order_struct_restrict (part_from_lin Rlin) SR), simp,
intros x y xS yS xy, cases Rlin.conn (SR xS) (SR yS) xy with xly ylx,
exact or.inl ⟨xly, xS, yS⟩,
exact or.inr ⟨ylx, yS, xS⟩,
end
-- Theorem 7J part c
theorem well_order_struct_restrict {R : struct} (Rwell : R.fld.well_order R.rel) {S : Set} (SR : S ⊆ R.fld) :
(S.struct_restrict R).fld.well_order (S.struct_restrict R).rel :=
begin
refine ⟨lin_order_struct_restrict Rwell.lin SR, _⟩, simp,
intros X XE XS,
obtain ⟨m, mX, le⟩ := Rwell.well XE (subset_trans XS SR),
refine ⟨_, mX, _⟩, rintro ⟨x, xX, xm⟩, rw mem_inter at xm, exact le ⟨_, xX, xm.left⟩,
end
-- Theorem 7K
theorem T7K {R : struct.{u}} (Rwell : R.fld.well_order R.rel) {S : struct.{u}} (Swell : S.fld.well_order S.rel) :
isomorphic R S
∨ (∃ b : Set, b ∈ S.fld ∧ isomorphic R ((S.rel.seg b).struct_restrict S))
∨ (∃ a : Set, a ∈ R.fld ∧ isomorphic ((R.rel.seg a).struct_restrict R) S) :=
begin
let e : Set := classical.some (univ_not_set' (R.fld ∪ S.fld)),
have eRS : e ∉ R.fld ∪ S.fld := classical.some_spec (univ_not_set' (R.fld ∪ S.fld)),
rw mem_union at eRS, push_neg at eRS,
let g : Set → Set := λ f, if case : ∃ m, m ∈ (S.fld \ f.ran) ∧ (S.fld \ f.ran).is_least S.rel m
then classical.some case else e,
have gt : ∀ {f : Set}, (∃ m, m ∈ (S.fld \ f.ran) ∧ (S.fld \ f.ran).is_least S.rel m)
→ (g f) ∈ (S.fld \ f.ran) ∧ (S.fld \ f.ran).is_least S.rel (g f),
intros f case, dsimp only [g], rw [dif_pos case], exact classical.some_spec case,
have gf : ∀ {f : Set}, ¬ (∃ m, m ∈ (S.fld \ f.ran) ∧ (S.fld \ f.ran).is_least S.rel m) → g f = e,
intros f case, dsimp only [g], rw [dif_neg case],
have ge : ∀ {f : Set}, g f = e → S.fld \ f.ran = ∅, intros f gf,
apply classical.by_contradiction, intro ne,
obtain ⟨m, hm, mle⟩ := Swell.well ne subset_diff,
obtain ⟨hgf, gfle⟩ := gt ⟨_, hm, mle⟩,
rw least_unique Swell.lin subset_diff hgf hm gfle mle at gf,
apply eRS.right, rw mem_diff at hm, rw ←gf, exact hm.left,
obtain ⟨F, Ffun, Fdom, Fval⟩ := exists_of_exists_unique (transfinite_rec' Rwell g),
have Fxle : ∀ {x : Set}, x ∈ R.fld → F.fun_value x ≠ e → (S.fld \ F.img (R.rel.seg x)).is_least S.rel (F.fun_value x),
intros x xA Fxne,
have ex : ∃ m, m ∈ (S.fld \ F.img (R.rel.seg x)) ∧ (S.fld \ F.img (R.rel.seg x)).is_least S.rel m,
apply classical.by_contradiction, intro nem, rw Fval xA at Fxne, exact Fxne (gf nem),
rw Fval xA, exact (gt ex).right,
have Fran : F.ran ⊆ S.fld ∪ {e}, intros y yF, rw mem_ran_iff Ffun at yF, obtain ⟨x, xA, yFx⟩ := yF,
rw Fdom at xA, rw Fval xA at yFx, rw [mem_union, mem_singleton], subst yFx,
by_cases case : ∃ m, m ∈ (S.fld \ (F.restrict (R.rel.seg x)).ran) ∧ (S.fld \ (F.restrict (R.rel.seg x)).ran).is_least S.rel m,
have h := (gt case).left, rw mem_diff at h, left, exact h.left,
right, exact gf case,
have seg_sub_dom : ∀ {y : Set}, y ∈ R.fld → R.rel.seg y ⊆ F.dom, intros y yA, rw Fdom, exact seg_sub_fld yA,
have seg_sub_dom' : ∀ {x y : Set}, x.pair y ∈ R.rel → R.rel.seg y ⊆ F.dom, intros x y xy,
exact seg_sub_dom (mem_fld_of_pair_mem_struct xy).right,
have sub_of_le : ∀ {x y : Set}, R.rel.lin_le x y → S.fld \ F.img (R.rel.seg y) ⊆ S.fld \ F.img (R.rel.seg x),
intros x y xy, cases xy,
obtain ⟨xA, yA⟩ := mem_fld_of_pair_mem_struct xy,
apply diff_sub_diff_of_sub, intros Z hZ,
rw mem_img' Ffun (seg_sub_dom xA) at hZ, obtain ⟨z, zx, hZ⟩ := hZ, subst hZ,
apply fun_value_mem_img Ffun (seg_sub_dom yA), exact (seg_subset_seg Rwell.lin xy) zx,
subst xy, exact subset_self,
have Fle_of_le : ∀ {x y : Set}, R.rel.lin_le x y → F.fun_value x ≠ e → F.fun_value y ≠ e → S.rel.lin_le (F.fun_value x) (F.fun_value y),
intros x y xy Fxne Fyne, cases xy with xly xey,
obtain ⟨xA, yA⟩ := mem_fld_of_pair_mem_struct xly,
have sub := sub_of_le (or.inl xly),
have ex : ∃ m, m ∈ (S.fld \ F.img (R.rel.seg x)) ∧ (S.fld \ F.img (R.rel.seg x)).is_least S.rel m,
apply classical.by_contradiction, intro nem, rw Fval xA at Fxne, exact Fxne (gf nem),
have ey : ∃ m, m ∈ (S.fld \ F.img (R.rel.seg y)) ∧ (S.fld \ F.img (R.rel.seg y)).is_least S.rel m,
apply classical.by_contradiction, intro nem, rw Fval yA at Fyne, exact Fyne (gf nem),
have Fxle := (gt ex).right, have Fym := (gt ey).left,
rw ←Fval xA at Fxle, rw ←Fval yA at Fym,
have FxB : F.fun_value x ∈ S.fld ∪ {e}, apply Fran, apply fun_value_def'' Ffun, rw Fdom, exact xA,
have FyB : F.fun_value y ∈ S.fld ∪ {e}, apply Fran, apply fun_value_def'' Ffun, rw Fdom, exact yA,
rw [mem_union, mem_singleton] at FxB FyB,
cases FxB with FxB Fxe,
cases FyB with FyB Fye,
rw le_iff_not_lt Swell.lin FxB FyB, intro Fyx, apply Fxle, exact ⟨_, sub Fym, Fyx⟩,
exfalso, exact Fyne Fye,
exfalso, exact Fxne Fxe,
subst xey, right, refl,
have Fx_in_Fy : ∀ {x y : Set}, x.pair y ∈ R.rel → F.fun_value x ∈ F.img (R.rel.seg y), intros x y xy,
apply fun_value_mem_img Ffun (seg_sub_dom' xy), rw mem_seg, exact xy,
have Fx_nin_Fx : ∀ {x : Set}, x ∈ R.fld → F.fun_value x ≠ e → F.fun_value x ∉ F.img (R.rel.seg x),
intros x xA Fxe,
have em : ∃ m, m ∈ (S.fld \ F.img (R.rel.seg x)) ∧ (S.fld \ F.img (R.rel.seg x)).is_least S.rel m,
apply classical.by_contradiction, intro nem, rw Fval xA at Fxe, exact Fxe (gf nem),
have h := (gt em).left, rw [mem_diff, ←Fval xA] at h, exact h.right,
have Fne_of_ne : ∀ {x y : Set}, x ∈ R.fld → y ∈ R.fld → x ≠ y → F.fun_value x ≠ e → F.fun_value y ≠ e → F.fun_value x ≠ F.fun_value y,
intros x y xA yA xy Fxe Fye Fxy, cases Rwell.lin.conn xA yA xy with xly ylx,
specialize Fx_in_Fy xly, rw Fxy at Fx_in_Fy, exact Fx_nin_Fx yA Fye Fx_in_Fy,
specialize Fx_in_Fy ylx, rw ←Fxy at Fx_in_Fy, exact Fx_nin_Fx xA Fxe Fx_in_Fy,
have Flt_of_lt : ∀ {x y : Set}, x.pair y ∈ R.rel → F.fun_value x ≠ e → F.fun_value y ≠ e → (F.fun_value x).pair (F.fun_value y) ∈ S.rel,
intros x y xy Fxe Fye,
have xny : x ≠ y, intro xey, subst xey, exact Rwell.lin.irrefl xy,
cases Fle_of_le (or.inl xy) Fxe Fye with lt eq,
exact lt,
have xA := (mem_fld_of_pair_mem_struct xy).left, have yA := (mem_fld_of_pair_mem_struct xy).right,
exfalso, exact Fne_of_ne xA yA xny Fxe Fye eq,
have lt_of_Flt : ∀ {x y : Set}, x ∈ R.fld → y ∈ R.fld → (F.fun_value x).pair (F.fun_value y) ∈ S.rel
→ F.fun_value x ≠ e → F.fun_value y ≠ e → x.pair y ∈ R.rel,
intros x y xA yA Fxy Fxne Fyne,
have FxB : F.fun_value x ∈ S.fld,
have h : F.fun_value x ∈ S.fld ∪ {e}, apply Fran, rw ←Fdom at xA, exact fun_value_def'' Ffun xA,
rw [mem_union, mem_singleton] at h, cases h with FxB Fxe,
exact FxB,
exfalso, exact Fxne Fxe,
have FyB : F.fun_value y ∈ S.fld,
have h : F.fun_value y ∈ S.fld ∪ {e}, apply Fran, rw ←Fdom at yA, exact fun_value_def'' Ffun yA,
rw [mem_union, mem_singleton] at h, cases h with FyB Fye,
exact FyB,
exfalso, exact Fyne Fye,
rw lt_iff_not_le Swell.lin FxB FyB at Fxy, rw lt_iff_not_le Rwell.lin xA yA,
intro ylex, exact Fxy (Fle_of_le ylex Fyne Fxne),
by_cases case₁ : e ∈ F.ran,
let C := {x ∈ R.fld | F.fun_value x = e},
have CE : C ≠ ∅, apply ne_empty_of_inhabited, rw mem_ran_iff Ffun at case₁,
obtain ⟨x, xA, ee⟩ := case₁, use x, rw mem_sep, rw Fdom at xA, exact ⟨xA, ee.symm⟩,
obtain ⟨a, aA, le⟩ := Rwell.well CE sep_subset, rw [mem_sep] at aA, obtain ⟨aA, Fa⟩ := aA,
rw Fval aA at Fa,
let F' := F.restrict (R.rel.seg a),
have Fran : F'.ran = S.fld, rw eq_iff_subset_and_subset, split,
intros y yF, simp only [restrict_ran, mem_img' Ffun (seg_sub_dom aA), mem_seg] at yF,
obtain ⟨x, xa, yFx⟩ := yF, subst yFx,
have xA : x ∈ R.fld := (mem_fld_of_pair_mem_struct xa).left,
have gF : (F.restrict (R.rel.seg a)).fun_value x ∈ S.fld ∪ {e}, apply Fran,
rw ←mem_seg at xa, rw restrict_fun_value Ffun (seg_sub_dom aA) xa,
rw ←Fdom at xA, exact fun_value_def'' Ffun xA,
have xsa : x ∈ R.rel.seg a, rw mem_seg, exact xa,
rw [restrict_fun_value Ffun (seg_sub_dom aA) xsa, mem_union, mem_singleton] at gF, cases gF,
exact gF,
exfalso, apply le, refine ⟨x, _, xa⟩, rw mem_sep, exact ⟨xA, gF⟩,
intros y yB, apply classical.by_contradiction, intro yF, apply mem_empty y,
rw ←ge Fa, rw mem_diff, exact ⟨yB, yF⟩,
have fne : ∀ {x : Set}, x.pair a ∈ R.rel → F.fun_value x ≠ e, intros x xa Fxe,
apply le, refine ⟨_, _, xa⟩, rw mem_sep, exact ⟨(mem_fld_of_pair_mem_struct xa).left, Fxe⟩,
have Foto : F'.one_to_one, apply one_to_one_of (restrict_is_function Ffun), intros x xa y ya xy,
rw restrict_dom (seg_sub_dom aA) at xa ya,
rw [restrict_fun_value Ffun (seg_sub_dom aA) xa, restrict_fun_value Ffun (seg_sub_dom aA) ya],
rw mem_seg at xa ya,
have xA := (mem_fld_of_pair_mem_struct xa).left, have yA := (mem_fld_of_pair_mem_struct ya).left,
exact Fne_of_ne xA yA xy (fne xa) (fne ya),
right, right, refine ⟨_, aA, F', ⟨⟨⟨restrict_is_function Ffun, restrict_dom (seg_sub_dom aA), Fran⟩, Foto⟩, _⟩⟩,
intros x y xa ya, rw struct_restrict_fld at xa ya,
simp only [struct_restrict_rel, mem_inter, pair_mem_prod],
rw [restrict_fun_value Ffun (seg_sub_dom aA) xa, restrict_fun_value Ffun (seg_sub_dom aA) ya],
rw mem_seg at xa ya,
have xA : x ∈ R.fld := (mem_fld_of_pair_mem_struct xa).left,
have yA : y ∈ R.fld := (mem_fld_of_pair_mem_struct ya).left,
split,
rintro ⟨xy, -, -⟩, exact Flt_of_lt xy (fne xa) (fne ya),
intro Fxy, simp only [mem_seg], exact ⟨lt_of_Flt xA yA Fxy (fne xa) (fne ya), xa, ya⟩,
have fne : ∀ {x : Set}, x ∈ R.fld → F.fun_value x ≠ e, intros x xA Fxe,
apply case₁, rw ←Fxe, apply fun_value_def'' Ffun, rw Fdom, exact xA,
have Foto : F.one_to_one, apply one_to_one_of Ffun, intros x xA y yA xy,
rw Fdom at xA yA, exact Fne_of_ne xA yA xy (fne xA) (fne yA),
have Fran' : F.ran ⊆ S.fld, intros y yF,
have h : y ∈ S.fld ∪ {e} := Fran yF,
rw [mem_union, mem_singleton] at h, cases h with yB ye,
exact yB,
exfalso, rw ye at yF, exact case₁ yF,
by_cases case₂ : F.ran = S.fld,
left, refine ⟨_, ⟨⟨Ffun, Fdom, case₂⟩, Foto⟩, _⟩, intros x y xA yA, split,
intro xy, exact Flt_of_lt xy (fne xA) (fne yA),
intro Fxy, exact lt_of_Flt xA yA Fxy (fne xA) (fne yA),
have ne : S.fld \ F.ran ≠ ∅,
have nsub : ¬ S.fld ⊆ F.ran, intro h, apply case₂, rw eq_iff_subset_and_subset, exact ⟨Fran', h⟩,
intro eqz, rw eq_empty at eqz, apply nsub, intros y yB, apply classical.by_contradiction, intro ynF,
apply eqz y, rw mem_diff, exact ⟨yB, ynF⟩,
obtain ⟨b, bBF, le⟩ := Swell.well ne subset_diff, rw mem_diff at bBF,
have Fran : F.ran = S.rel.seg b, rw eq_iff_subset_and_subset, split,
intros y yF, rw mem_ran_iff Ffun at yF, obtain ⟨x, xA, yFx⟩ := yF, rw Fdom at xA, subst yFx,
have FxB : F.fun_value x ∈ S.fld,
have Fxran : F.fun_value x ∈ S.fld ∪ {e}, apply Fran, apply fun_value_def'' Ffun, rw Fdom, exact xA,
rw [mem_union, mem_singleton] at Fxran, cases Fxran with FxB Fxe,
exact FxB,
exfalso, exact (fne xA) Fxe,
rw [mem_seg, lt_iff_not_le Swell.lin FxB bBF.left], rintro (bFx|eq),
apply Fxle xA (fne xA), refine ⟨_, _, bFx⟩, rw mem_diff, refine ⟨bBF.left, _⟩,
intro mem_img, exact bBF.right (img_subset_ran mem_img),
subst eq, apply bBF.right, rw ←Fdom at xA, exact fun_value_def'' Ffun xA,
intros x xb, rw mem_seg at xb, apply classical.by_contradiction, intro xF, apply le, refine ⟨_, _, xb⟩,
rw mem_diff, exact ⟨(mem_fld_of_pair_mem_struct xb).left, xF⟩,
right, left, refine ⟨_, bBF.left, F, ⟨⟨⟨Ffun, Fdom, Fran⟩, Foto⟩, _⟩⟩,
intros x y xA yA, simp only [←Fran, struct_restrict_rel, mem_inter, pair_mem_prod], split,
intro xy, refine ⟨Flt_of_lt xy (fne xA) (fne yA), fun_value_def'' Ffun _, fun_value_def'' Ffun _⟩,
rw Fdom, exact xA,
rw Fdom, exact yA,
rintro ⟨Fxy, -, -⟩, exact lt_of_Flt xA yA Fxy (fne xA) (fne yA),
end
def eps_ordered (A : Set) : Prop := A.well_order A.eps_order
lemma seg_eq_of_trans {A : Set} (trans : A.transitive_set) {t : Set} (tA : t ∈ A) : A.eps_order.seg t = t :=
begin
apply ext, intro x, rw [mem_seg, eps_order, pair_mem_pair_sep], split,
rintro ⟨-, -, xt⟩, exact xt,
intro xt, refine ⟨_, tA, xt⟩, apply trans, rw mem_Union, exact ⟨_, tA, xt⟩,
end
-- Theorem 7L
theorem eps_img_trans_well_eq_self {α : Set} (trans : α.transitive_set) (well : α.well_order α.eps_order) : eps_img α.eps_order_struct = α :=
begin
have well' : α.eps_order_struct.fld.well_order α.eps_order_struct.rel,
simp only [eps_order_struct_rel, eps_order_struct_fld], exact well,
obtain ⟨efun, edom, eran⟩ := eps_img_fun_onto well',
let B := {x ∈ α | (eps_img_fun α.eps_order_struct).fun_value x = x},
have Be : B = α, apply transfinite_ind well sep_subset, intros t tA ind,
have tA' : t ∈ α.eps_order_struct.fld, exact tA,
rw [mem_sep, eps_img_fun_value_img well' tA', eps_order_struct_rel],
refine ⟨tA, _⟩, apply ext, intro y,
have seg_sub : α.eps_order.seg t ⊆ α.eps_order_struct.fld, rw [eps_order_struct_fld], exact subset_trans ind sep_subset,
rw ←edom at seg_sub, rw [mem_img' efun seg_sub], split,
rintro ⟨x, xt, yx⟩, subst yx, specialize ind xt, rw mem_sep at ind, rw ind.right,
rw [mem_seg, eps_order, pair_mem_pair_sep] at xt, exact xt.right.right,
intro yt,
have yt' : y ∈ α.eps_order.seg t, rw [mem_seg, eps_order, pair_mem_pair_sep], refine ⟨_, tA, yt⟩,
apply trans, rw mem_Union, exact ⟨_, tA, yt⟩,
specialize ind yt', rw mem_sep at ind, refine ⟨_, yt', ind.right.symm⟩,
have ef : eps_img_fun α.eps_order_struct = α.id, apply fun_ext efun id_is_function,
simp only [edom, id_into.right.left, eps_order_struct_fld],
intros t tA, rw [edom, eps_order_struct_fld, ←Be, mem_sep] at tA,
rw [id_value tA.left, tA.right],
rw [←eran, ef], nth_rewrite 1 [←(@id_onto α).right.right],
end
theorem eps_img_trans_well_is_ordinal {α : Set} (trans : α.transitive_set) (well : α.well_order α.eps_order) : α.is_ordinal :=
⟨α.eps_order_struct, well, (eps_img_trans_well_eq_self trans well).symm⟩
lemma ordinal_well_ordered {α : Set} (ordinal : α.is_ordinal) : α.well_order α.eps_order :=
begin
rcases ordinal with ⟨R, well, Re⟩, rw Re, exact eps_img_well_order well,
end
lemma ordinal_well_ordered' {α : Set} (ordinal : α.is_ordinal) : α.eps_order_struct.fld.well_order α.eps_order_struct.rel :=
ordinal_well_ordered ordinal
lemma ordinal_trans {α : Set} (ordinal : α.is_ordinal) : α.transitive_set :=
begin
rcases ordinal with ⟨R, well, Re⟩, rw Re, exact eps_img_transitive well,
end
lemma seg_ord {α : Set} (αord : α.is_ordinal) {β : Set} (βα : β ∈ α) : α.eps_order.seg β = β :=
seg_eq_of_trans (ordinal_trans αord) βα
theorem eps_img_ord_eq_self {α : Set} (αord : α.is_ordinal) : eps_img α.eps_order_struct = α :=
eps_img_trans_well_eq_self (ordinal_trans αord) (ordinal_well_ordered αord)
lemma eps_img_eq_of_iso_ord {α : Set} (αord : α.is_ordinal) {W : struct} (Wiso : isomorphic W α.eps_order_struct) :
eps_img W = α :=
begin
rw [←eps_img_ord_eq_self αord,
←iso_iff_eps_img_eq (well_order_iso (iso_symm Wiso) (ordinal_well_ordered' αord)) (ordinal_well_ordered' αord)],
exact Wiso,
end
lemma restrict_seg_sub {R : struct} {t : Set} (tA : t ∈ R.fld) : (struct_restrict R (R.rel.seg t)).rel.seg t ⊆ R.rel.seg t :=
begin
intro x, simp only [mem_seg, struct_restrict_rel, mem_inter],rintro ⟨xt, -⟩, exact xt,
end
lemma eps_img_fun_restrict {R : struct} (well : R.fld.well_order R.rel) {T : Set} (TA : T ∈ R.fld) :
∀ {x : Set}, x ∈ R.rel.seg T → (eps_img_fun (struct_restrict R (R.rel.seg T))).fun_value x = (eps_img_fun R).fun_value x :=
begin
have sub := seg_sub_fld TA,
have well' := well_order_struct_restrict well sub,
obtain ⟨efun, edom, -⟩ := eps_img_fun_onto well,
obtain ⟨efun', edom', -⟩ := eps_img_fun_onto well',
let B := {x ∈ R.rel.seg T | (eps_img_fun (struct_restrict R (R.rel.seg T))).fun_value x = (eps_img_fun R).fun_value x},
have BA : B = R.rel.seg T, apply transfinite_ind well' sep_subset,
intros t ht ind, rw mem_sep, refine ⟨ht, _⟩,
rw [eps_img_fun_value_img well' ht, eps_img_fun_value_img well (sub ht)], apply ext, intro x,
have dsub : R.rel.seg t ⊆ (eps_img_fun R).dom, rw edom, exact seg_sub_fld (sub ht),
have dsub' : (struct_restrict R (R.rel.seg T)).rel.seg t ⊆ (eps_img_fun (struct_restrict R (R.rel.seg T))).dom,
rw [edom', struct_restrict_rel, struct_restrict_fld], intro z,
simp only [mem_seg, mem_inter, pair_mem_prod], rintro ⟨-, zT, -⟩, exact zT,
rw [mem_img' efun dsub, mem_img' efun' dsub'], split,
rintro ⟨z, zt, xz⟩, subst xz, specialize ind zt, rw mem_sep at ind,
rw [struct_restrict_rel, mem_seg, mem_inter, ←mem_seg] at zt, exact ⟨_, zt.left, ind.right⟩,
rintro ⟨z, zt, xz⟩, subst xz, use z,
have zt' : z ∈ (struct_restrict R (R.rel.seg T)).rel.seg t,
simp only [mem_seg, struct_restrict_rel, mem_inter, mem_prod, exists_prop],
rw [struct_restrict_fld] at ht, rw mem_seg at zt ht,
exact ⟨zt, _, well.lin.trans zt ht, _, ht, rfl⟩,
specialize ind zt', rw mem_sep at ind, exact ⟨zt', ind.right.symm⟩,
intros t tT, rw [←BA, mem_sep] at tT, exact tT.right,
end
lemma eps_img_img_eps_fun {R : struct} (well : R.fld.well_order R.rel) {t : Set} (tA : t ∈ R.fld) :
eps_img ((R.rel.seg t).struct_restrict R) = (eps_img_fun R).img (R.rel.seg t) :=
begin
have well' : (struct_restrict R (R.rel.seg t)).fld.well_order (struct_restrict R (R.rel.seg t)).rel
:= well_order_struct_restrict well (seg_sub_fld tA),
obtain ⟨efun, edom, -⟩ := eps_img_fun_onto well,
have sub : R.rel.seg t ⊆ (eps_img_fun R).dom, rw edom, exact seg_sub_fld tA,
apply ext, simp only [mem_eps_img well', mem_img' efun sub, struct_restrict_fld], intro y, split,
rintro ⟨x, xt, yx⟩, subst yx, refine ⟨x, xt, eps_img_fun_restrict well tA xt⟩,
rintro ⟨x, xt, yx⟩, subst yx, refine ⟨x, xt, (eps_img_fun_restrict well tA xt).symm⟩,
end
-- Theorem 7M part a
theorem ord_of_mem_ord {α : Set} (ord : α.is_ordinal) ⦃x : Set⦄ (xα : x ∈ α) : x.is_ordinal :=
begin
rcases ord with ⟨R, well, αe⟩, rw [αe, mem_eps_img well] at xα,
obtain ⟨t, tA, xt⟩ := xα, subst xt,
refine ⟨(R.rel.seg t).struct_restrict R, well_order_struct_restrict well (seg_sub_fld tA), _⟩,
rw [eps_img_fun_value_img well tA], exact (eps_img_img_eps_fun well tA).symm,
end
lemma ord_of_succ_ord {α : Set} (αord : α.succ.is_ordinal) : α.is_ordinal :=
ord_of_mem_ord αord self_mem_succ
-- Theorem 7M part b
theorem ord_mem_trans {α β γ : Set} (γord : γ.is_ordinal)
(αβ : α ∈ β) (βγ : β ∈ γ) : α ∈ γ :=
transitive_set_iff.mp (ordinal_trans γord) βγ αβ
-- Theorem 7M part c
theorem ord_mem_irrefl {α : Set} (ordinal : α.is_ordinal) : α ∉ α :=
begin
rcases ordinal with ⟨R, well, αe⟩, subst αe, intro ee,
obtain ⟨t, tA, ee'⟩ := (mem_eps_img well).mp ee, rw ee' at ee,
exact eps_img_fun_irrefl well tA ee,
end
lemma restrict_eps_order_eq {β : Set} (βtrans : β.transitive_set) {δ : Set} (δβ : δ ∈ β) : struct_restrict β.eps_order_struct δ = δ.eps_order_struct :=
begin
simp only [eps_order_struct, struct_restrict, eps_order], refine ⟨rfl, _⟩,
apply rel_ext (inter_rel_is_rel pair_sep_is_rel) pair_sep_is_rel, intros x y,
simp only [mem_inter, pair_mem_pair_sep, pair_mem_prod], split,
rintro ⟨⟨-, -, xy⟩, xδ, yδ⟩, exact ⟨xδ, yδ, xy⟩,
rw transitive_set_iff at βtrans,
rintro ⟨xδ, yδ, xy⟩, exact ⟨⟨βtrans δβ xδ, βtrans δβ yδ, xy⟩, xδ, yδ⟩,
end
lemma mem_of_iso_seg {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) {δ : Set} (δβ : δ ∈ β)
(iso : isomorphic α.eps_order_struct (struct_restrict β.eps_order_struct (β.eps_order_struct.rel.seg δ))) : α ∈ β :=
begin
have αwell : α.eps_order_struct.fld.well_order α.eps_order_struct.rel := ordinal_well_ordered αord,
have βwell : β.eps_order_struct.fld.well_order β.eps_order_struct.rel := ordinal_well_ordered βord,
have αtrans := ordinal_trans αord, have βtrans := ordinal_trans βord,
rw [eps_order_struct_rel, seg_eq_of_trans βtrans δβ, restrict_eps_order_eq βtrans δβ] at iso,
have δord := ord_of_mem_ord βord δβ,
have δwell : δ.eps_order_struct.fld.well_order δ.eps_order_struct.rel := ordinal_well_ordered δord,
have δtrans := ordinal_trans δord,
rw [iso_iff_eps_img_eq αwell δwell] at iso,
rw [eps_img_trans_well_eq_self αtrans αwell, eps_img_trans_well_eq_self δtrans δwell] at iso,
subst iso, exact δβ,
end
-- Theorem 7M part d
theorem ord_conn {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) (αβ : α ≠ β) : α ∈ β ∨ β ∈ α :=
begin
have αwell : α.eps_order_struct.fld.well_order α.eps_order_struct.rel := ordinal_well_ordered αord,
have βwell : β.eps_order_struct.fld.well_order β.eps_order_struct.rel := ordinal_well_ordered βord,
have αtrans := ordinal_trans αord, have βtrans := ordinal_trans βord,
rcases T7K αwell βwell with (RS|⟨δ, δβ, iso⟩|⟨δ, δα, iso⟩),
{ exfalso, apply αβ, rw [iso_iff_eps_img_eq αwell βwell] at RS,
rw [eps_img_trans_well_eq_self αtrans αwell, eps_img_trans_well_eq_self βtrans βwell] at RS,
exact RS, },
{ rw eps_order_struct_fld at δβ,
left, exact mem_of_iso_seg αord βord δβ iso, },
{ rw eps_order_struct_fld at δα,
right, exact mem_of_iso_seg βord αord δα (iso_symm iso), },
end
lemma ord_eq_of_not_lt {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) (αβ : ¬ α ∈ β) (βα : ¬ β ∈ α) : α = β :=
begin
apply classical.by_contradiction, intro αneβ,
cases ord_conn αord βord αneβ,
exact αβ h,
exact βα h,
end
theorem ord_conn' {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) : α ≤ β ∨ β ≤ α :=
begin
by_cases eq : α = β,
left, right, exact eq,
cases ord_conn αord βord eq,
left, left, exact h,
right, left, exact h,
end
-- Theorem 7M part e
theorem exists_least_ord_of_nonempty {S : Set} (Sord : ∀ {x : Set}, x ∈ S → x.is_ordinal) (SE : S ≠ ∅) :
∃ μ : Set, μ ∈ S ∧ S.is_least S.eps_order μ :=
begin
obtain ⟨β, βS⟩ := inhabited_of_ne_empty SE,
by_cases βiS : β ∩ S = ∅,
{ refine ⟨_, βS, _⟩, rintro ⟨α, αS, αβ⟩, rw [eps_order, pair_mem_pair_sep] at αβ,
apply mem_empty α, rw [←βiS, mem_inter], exact ⟨αβ.right.right, αS⟩, },
{ obtain ⟨μ, μβ, le⟩ := (ordinal_well_ordered (Sord βS)).well βiS inter_subset_left,
rw mem_inter at μβ,
refine ⟨_, μβ.right, _⟩, rintro ⟨α, αS, αμ⟩, rw [eps_order, pair_mem_pair_sep] at αμ,
by_cases αβ : α ∈ β,
apply le, use α, rw [eps_order, pair_mem_pair_sep, mem_inter],
exact ⟨⟨αβ, αS⟩, αβ, μβ.left, αμ.right.right⟩,
apply αβ,
apply ord_mem_trans (Sord βS) αμ.right.right μβ.left, },
end
lemma is_ordinal_iff {α : Set} : α.is_ordinal ↔ α.transitive_set ∧ α.well_order α.eps_order :=
⟨assume ord, ⟨ordinal_trans ord, ordinal_well_ordered ord⟩, assume ⟨trans, well⟩, eps_img_trans_well_is_ordinal trans well⟩
lemma nat_is_ord {n : Set} (nω : n ∈ ω) : n.is_ordinal :=
begin
rw is_ordinal_iff, refine ⟨nat_transitive nω, ⟨pair_sep_sub_prod, _, _, _⟩, _⟩,
{ intros x y z, simp only [eps_order, pair_mem_pair_sep],
rintros ⟨xn, yn, xy⟩ ⟨-, zn, yz⟩,
have xω := mem_nat_of_mem_nat_of_mem nω xn,
have yω := mem_nat_of_mem_nat_of_mem nω yn,
have zω := mem_nat_of_mem_nat_of_mem nω zn,
exact ⟨xn, zn, lt_trans xω yω zω xy yz⟩, },
{ intro m, rw [eps_order, pair_mem_pair_sep],
rintro ⟨mn, -, mm⟩,
have mω := mem_nat_of_mem_nat_of_mem nω mn,
exact nat_not_mem_self mω mm, },
{ intros m k mn kn mnek, simp only [eps_order, pair_mem_pair_sep],
have mω := mem_nat_of_mem_nat_of_mem nω mn,
have kω := mem_nat_of_mem_nat_of_mem nω kn,
cases nat_order_conn mω kω mnek with mk km,
left, exact ⟨mn, kn, mk⟩,
right, exact ⟨kn, mn, km⟩, },
{ intros X XE Xn,
have Xω : X ⊆ ω, intros m mX, exact mem_nat_of_mem_nat_of_mem nω (Xn mX),
obtain ⟨m, mX, le⟩ := nat_well_order Xω XE,
refine ⟨_, mX, _⟩, rw is_least, push_neg,
intros k kX, rw [eps_order, pair_mem_pair_sep],
rintro ⟨kn, mn, km⟩, specialize le kX,
have kω := mem_nat_of_mem_nat_of_mem nω kn,
have mω := mem_nat_of_mem_nat_of_mem nω mn,
cases le with mk mk,
exact not_lt_and_gt kω mω ⟨km, mk⟩,
subst mk, exact nat_not_mem_self mω km, },
end
theorem one_is_ord : is_ordinal one := nat_is_ord one_nat
lemma eps_order_ordinals_lin {A : Set} (Aord : ∀ {x : Set}, x ∈ A → x.is_ordinal) : A.lin_order A.eps_order :=
begin
refine ⟨pair_sep_sub_prod, _, _, _⟩,
{ intros x y z xy yz, rw [eps_order, pair_mem_pair_sep] at *,
rcases xy with ⟨xA, yA, xy⟩, rcases yz with ⟨-, zA, yz⟩,
exact ⟨xA, zA, ord_mem_trans (Aord zA) xy yz⟩, },
{ intros x xx, rw [eps_order, pair_mem_pair_sep] at xx,
rcases xx with ⟨xA, -, xx⟩, exact ord_mem_irrefl (Aord xA) xx, },
{ intros x y xA yA xney, simp only [eps_order, pair_mem_pair_sep],
cases ord_conn (Aord xA) (Aord yA) xney with xy yx,
left, exact ⟨xA, yA, xy⟩,
right, exact ⟨yA, xA, yx⟩, },
end
-- Corollary 7N part a
theorem trans_ords_is_ord {S : Set} (Sord : ∀ {x : Set}, x ∈ S → x.is_ordinal) (trans : S.transitive_set) : S.is_ordinal :=
begin
rw is_ordinal_iff, refine ⟨trans, eps_order_ordinals_lin @Sord, _⟩,
intros X XE XS,
obtain ⟨μ, μX, le⟩ := exists_least_ord_of_nonempty (λ x xX, Sord (XS xX)) XE,
refine ⟨_, μX, _⟩, rintro ⟨x, xX, xμ⟩, refine le ⟨_, xX, _⟩,
rw [eps_order, pair_mem_pair_sep] at *,
rcases xμ with ⟨-, -, xμ⟩, exact ⟨xX, μX, xμ⟩,
end
theorem omega_is_ord : is_ordinal ω :=
trans_ords_is_ord @nat_is_ord nat_transitive_set
-- Corollary 7N part b
theorem zero_is_ord : is_ordinal ∅ :=
begin
apply trans_ords_is_ord vacuous, rw transitive_set_iff, exact vacuous,
end
-- Corollary 7N part c
theorem succ_ord_of_ord {α : Set} (αord : α.is_ordinal) : α.succ.is_ordinal :=
begin
apply trans_ords_is_ord,
intros x xα, rw mem_succ at xα, cases xα,
subst xα, exact αord,
exact ord_of_mem_ord αord xα,
rw [transitive_set, T4E (ordinal_trans αord)], exact self_sub_succ,
end
-- Corollary 7N part d
theorem Union_ords_is_ord {A : Set} (Aord : ∀ {x : Set}, x ∈ A → x.is_ordinal) : A.Union.is_ordinal :=
begin
apply trans_ords_is_ord,
intros x xA, rw mem_Union at xA, rcases xA with ⟨X, XA, xX⟩, exact ord_of_mem_ord (Aord XA) xX,
rw [transitive_set_iff'], intros δ δA, rw mem_Union at δA,
rcases δA with ⟨α, αA, δα⟩,
have αtrans := ordinal_trans (Aord αA), rw transitive_set_iff' at αtrans,
intros x xδ, rw mem_Union, exact ⟨_, αA, αtrans δα xδ⟩,
end
lemma ord_mem_iff_ssub {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) : α ∈ β ↔ α ⊂ β :=
begin
split,
intro αβ,
have βtrans := ordinal_trans βord,
rw transitive_set_iff' at βtrans,
refine ⟨βtrans αβ, assume αeβ, _⟩,
subst αeβ, exact ord_mem_irrefl αord αβ,
rintro ⟨sub, eq⟩, cases ord_conn αord βord eq with αβ βα,
exact αβ,
exfalso, apply eq, rw eq_iff_subset_and_subset, refine ⟨sub, _⟩,
have αtrans := ordinal_trans αord,
rw transitive_set_iff' at αtrans,
exact αtrans βα,
end
lemma ord_le_iff_sub {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) : α ≤ β ↔ α ⊆ β :=
begin
split,
rintro (αβ|αβ),
rw ord_mem_iff_ssub αord βord at αβ, exact αβ.left,
subst αβ, exact subset_self,
intro αβ, by_cases αeβ : α = β,
subst αeβ, right, refl,
left, rw ord_mem_iff_ssub αord βord, exact ⟨αβ, αeβ⟩,
end
lemma eps_order_sub {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) (αβ : α ≤ β) :
α.eps_order ⊆ β.eps_order :=
begin
have sub : α ⊆ β, rw ←ord_le_iff_sub αord βord, exact αβ,
apply rel_sub pair_sep_is_rel, intros x y xy, rw pair_mem_pair_sep at xy, rcases xy with ⟨xα, yα, xy⟩,
rw pair_mem_eps_order' (sub xα) (sub yα), exact xy,
end
lemma Union_least_upper_bound {α β : Set} (βord : β.is_ordinal) (αβ : α ∈ β) :
α.Union ≤ β :=
begin
have αord := ord_of_mem_ord βord αβ,
have hα : ∀ x : Set, x ∈ α → x.is_ordinal := λ x, assume xα, ord_of_mem_ord αord xα,
rw ord_le_iff_sub (Union_ords_is_ord hα) βord, rw ord_mem_iff_ssub αord βord at αβ,
intros y hy, rw mem_Union at hy, rcases hy with ⟨X, Xα, yX⟩,
have βtrans := ordinal_trans βord, rw transitive_set_iff at βtrans,
exact βtrans (αβ.left Xα) yX,
end
lemma succ_least_upper_bound {α β : Set} (βord : β.is_ordinal) (αβ : α ∈ β) :
α.succ ≤ β :=
begin
rw ord_le_iff_sub (succ_ord_of_ord (ord_of_mem_ord βord αβ)) βord,
apply union_subset_of_subset_of_subset,
intros x hx, rw mem_singleton at hx, subst hx, exact αβ,
rw ←ord_le_iff_sub (ord_of_mem_ord βord αβ) βord, left, exact αβ,
end
lemma Union_le_succ {α : Set} (αord : α.is_ordinal) : α.Union ≤ α.succ :=
Union_least_upper_bound (succ_ord_of_ord αord) self_mem_succ
lemma ord_eq {α : Set} (αord : α.is_ordinal) : α = {x ∈ α | x.is_ordinal} :=
begin
rw eq_iff_subset_and_subset, refine ⟨λ x, assume xα, _, sep_subset⟩,
rw mem_sep, exact ⟨xα, ord_of_mem_ord αord xα⟩,
end
lemma seg_ord_eq_self {α : Set} (αord : α.is_ordinal) {β : Set} (βα : β ∈ α) : α.eps_order.seg β = β :=
begin
apply ext, intro γ, rw [mem_seg, eps_order, pair_mem_pair_sep], split,
rintro ⟨-, -, γβ⟩, exact γβ,
intro γβ, exact ⟨ord_mem_trans αord γβ βα, βα, γβ⟩,
end
-- Burali-Forti Theorem
theorem not_exists_ord_set : ¬ ∃ Ω : Set, ∀ {x : Set}, x ∈ Ω ↔ x.is_ordinal :=
begin
rintro ⟨Ω, hΩ⟩,
have Ωord : Ω.is_ordinal, apply trans_ords_is_ord,
intros x xΩ, rw ←hΩ, exact xΩ,
rw transitive_set_iff, intros X XΩ x xX, rw hΩ, rw hΩ at XΩ, exact ord_of_mem_ord XΩ xX,
apply ord_mem_irrefl Ωord, rw hΩ, exact Ωord,
end
lemma ord_not_le_iff_lt {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) : ¬ (α ≤ β) ↔ β ∈ α :=
begin
split,
intro αβ, by_cases αeβ : α = β,
exfalso, exact αβ (or.inr αeβ),
cases ord_conn αord βord αeβ,
exfalso, exact αβ (or.inl h),
exact h,
rintros βα (αβ|αβ),
exact ord_mem_irrefl αord (ord_mem_trans αord αβ βα),
subst αβ, exfalso, exact ord_mem_irrefl αord βα,
end
lemma ord_not_lt_iff_le {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) : ¬ (α ∈ β) ↔ (β ≤ α) :=
begin
rw [←not_iff_not, not_not, iff.comm], exact ord_not_le_iff_lt βord αord,
end
lemma ord_eq_iff_le_and_le {α : Set} (αord : α.is_ordinal) {β : Set} (βord : β.is_ordinal) : α = β ↔ α ≤ β ∧ β ≤ α :=
begin
split,
intro αβ, subst αβ, exact ⟨le_self, le_self⟩,
rintro ⟨(αβ|αβ), (βα|βα)⟩,
exfalso, exact ord_mem_irrefl αord (ord_mem_trans αord αβ βα),
exact βα.symm,
exact αβ,
exact βα.symm,
end
lemma ord_lt_of_le_of_lt {α β δ : Set} (δord : δ.is_ordinal) (αβ : α ≤ β) (βδ : β ∈ δ) : α ∈ δ :=
begin
cases αβ,
exact ord_mem_trans δord αβ βδ,
subst αβ, exact βδ,
end
lemma ord_lt_of_lt_of_le {α β δ : Set} (δord : δ.is_ordinal) (αβ : α ∈ β) (βδ : β ≤ δ) : α ∈ δ :=
begin
cases βδ,
exact ord_mem_trans δord αβ βδ,
subst βδ, exact αβ,
end
lemma ord_le_trans {α β δ : Set} (δord : δ.is_ordinal) (αβ : α ≤ β) (βδ : β ≤ δ) : α ≤ δ :=
begin
cases αβ,
exact or.inl (ord_lt_of_lt_of_le δord αβ βδ),
subst αβ, exact βδ,
end
-- exercise 18
lemma Union_max_of_exists_max {S : Set} (Sord : ∀ {x : Set}, x ∈ S → x.is_ordinal) :
S.Union ∉ S ∧ ¬ (∃ β : Set, β ∈ S ∧ ∀ {α : Set}, α ∈ S → α ≤ β) ∧ ¬ (∃ α : Set, S.Union = α.succ)
∨ S.Union ∈ S ∧ ∀ {α : Set}, α ∈ S → α ≤ S.Union :=
begin
by_cases case : S.Union ∈ S,
refine or.inr ⟨case, λ α, assume αS, _⟩, rw ord_le_iff_sub (Sord αS) (Union_ords_is_ord @Sord),
intros β βα, rw mem_Union, exact ⟨_, αS, βα⟩,
have nmax : ¬∃ (β : Set), β ∈ S ∧ ∀ {α : Set}, α ∈ S → α ≤ β,
rintro ⟨β, βS, ge⟩,
have βe : β = S.Union, apply ext, intro γ, split,
intro γβ, rw mem_Union, exact ⟨_, βS, γβ⟩,
rw mem_Union, rintro ⟨α, αS, γα⟩, cases ge αS with αβ αβ,
apply ord_mem_trans (Sord βS) γα αβ,
subst αβ, exact γα,
subst βe, exact case βS,
refine or.inl ⟨case, nmax, _⟩, rintro ⟨α, αe⟩, push_neg at nmax,
have nmax' : ¬∃ (β : Set), β ∈ S.Union ∧ ∀ {γ : Set}, γ ∈ S.Union → γ ≤ β,
push_neg, intros β, rw mem_Union, rintro ⟨γ, γS, βγ⟩,
rcases nmax _ γS with ⟨δ, δS, δγ⟩, rw ord_not_le_iff_lt (Sord δS) (Sord γS) at δγ,
use γ, rw [mem_Union, ord_not_le_iff_lt (Sord γS) (ord_of_mem_ord (Sord γS) βγ)],
exact ⟨⟨_, δS, δγ⟩, βγ⟩,
rw αe at nmax', apply nmax', refine ⟨_, self_mem_succ, λ β, assume βα, _⟩,
rw ←mem_succ_iff_le, exact βα,
end
lemma case_exists_bound {S : Set} (Sord : ∀ {x : Set}, x ∈ S → x.is_ordinal)
(ex : ∃ β : Set, β ∈ S ∧ ∀ {α : Set}, α ∈ S → α ≤ β) : S.Union ∈ S ∧ ∀ {α : Set}, α ∈ S → α ≤ S.Union :=
begin
obtain (⟨-, ex₂, -⟩|h) := Union_max_of_exists_max @Sord,
exfalso, exact ex₂ ex,
exact h,
end
lemma case_not_exists_bound {S : Set} (Sord : ∀ {x : Set}, x ∈ S → x.is_ordinal)
(nex : ¬ ∃ β : Set, β ∈ S ∧ ∀ {α : Set}, α ∈ S → α ≤ β) : S.Union ∉ S ∧ ¬ ∃ α : Set, S.Union = α.succ :=
begin
rcases Union_max_of_exists_max @Sord with (⟨SUS, -, nE⟩|⟨SU, h⟩),
exact ⟨SUS, nE⟩,
rw ←not_or_distrib, rintro (-|-);
apply nex; exact ⟨_, SU, @h⟩,
end
lemma Union_succ_ord_eq_self {α : Set} (αord : α.is_ordinal) : α.succ.Union = α :=
begin
apply ext, simp only [mem_Union, exists_prop, mem_succ_iff_le], intro β, split,
rintro ⟨γ, γα, βγ⟩, exact ord_lt_of_lt_of_le αord βγ γα,
intro βα, exact ⟨_, or.inr rfl, βα⟩,
end
noncomputable def rec_fun' (f : Set → Set) (base : Set) : Set :=
trans_rec ω nat_order (λ g, if g = ∅ then base else f (g.fun_value g.dom.Union))
lemma rec_fun_fun' {f : Set → Set} {base : Set} : (rec_fun' f base).is_function :=
trans_rec_fun nat_well_order'
lemma rec_fun_dom' {f : Set → Set} {base : Set} : (rec_fun' f base).dom = ω :=
trans_rec_dom nat_well_order'
lemma rec_fun_base' {f : Set → Set} {base : Set} : (rec_fun' f base).fun_value ∅ = base :=
by rw [rec_fun', trans_rec_spec nat_well_order' zero_nat, nat_order_seg zero_nat, restrict_empty, if_pos rfl]
lemma rec_fun_ind' {f : Set → Set} {base n : Set} (nω : n ∈ ω) :
(rec_fun' f base).fun_value n.succ = f ((rec_fun' f base).fun_value n) :=
begin
have nω' := nat_induct.succ_closed nω,
have nω'' := subset_nat_of_mem_nat nω',
rw [rec_fun', trans_rec_spec nat_well_order' nω', nat_order_seg nω'],
have hdom : ((rec_fun' f base).restrict n.succ).dom = n.succ,
apply restrict_dom, rw rec_fun_dom', exact nω'',
have ne : (rec_fun' f base).restrict n.succ ≠ ∅, apply ne_empty_of_inhabited,
use n.pair ((rec_fun' f base).fun_value n), rw pair_mem_restrict,
refine ⟨fun_value_def''' rec_fun_fun' _ rfl, self_mem_succ⟩,
rw rec_fun_dom', exact nω,
rw rec_fun' at ne hdom, rw [if_neg ne, hdom],
have h : n.succ.Union ∈ n.succ,
rw Union_succ_ord_eq_self (nat_is_ord nω), exact self_mem_succ,
rw [←@rec_fun_dom' f base, rec_fun'] at nω'',
rw [←rec_fun', restrict_fun_value rec_fun_fun' nω'' h, Union_succ_ord_eq_self (nat_is_ord nω)],
end
-- Hartogs' Theorem
theorem exists_large_ord {A : Set} : ∃ α : Set, α.is_ordinal ∧ ¬ α ≼ A :=
begin
let W := {x ∈ A.powerset.prod (A.prod A).powerset | ∃ B R : Set, x = B.pair R ∧ B ⊆ A ∧ B.well_order R},
have memW : ∀ {x : Set}, x ∈ W ↔ ∃ B R : Set, x = B.pair R ∧ B ⊆ A ∧ B.well_order R,
simp only [mem_powerset, and_imp, exists_prop, mem_sep, and_iff_right_iff_imp, mem_prod, exists_imp_distrib],
intros X B R XBR BA Rwell, subst XBR, refine ⟨_, BA, R, _, rfl⟩,
apply subset_trans Rwell.lin.rel, intros x xBB, rw mem_prod at xBB,
rcases xBB with ⟨a, aB, b, bB, xab⟩, subst xab, rw pair_mem_prod, exact ⟨BA aB, BA bB⟩,
let f : Set → Set := (λ S, if is_rel : S.snd ⊆ S.fst.prod S.fst then eps_img ⟨S.fst, S.snd, is_rel⟩ else ∅),
obtain ⟨𝓔, mem𝓔⟩ := @replacement'' f W,
let α : Set := {β ∈ 𝓔 | β.is_ordinal ∧ β ≼ A},
have memα : ∀ {β : Set}, β ∈ α ↔ β.is_ordinal ∧ β ≼ A,
simp only [and_imp, mem_sep, and_iff_right_iff_imp, dominated_iff],
rintros β βord ⟨B, BA, f, fonto, foto⟩, rw mem𝓔,
let S := fun_order B β.eps_order f.inv,
have βwell := ordinal_well_ordered βord,
have Swell : B.well_order S, refine well_order_from_fun (into_of_onto (inv_onto_of_onto fonto foto)) _ βwell,
rw ←T3F_b fonto.left.left, exact fonto.left,
have iso : f.isomorphism β.eps_order_struct ⟨B, S, pair_sep_sub_prod⟩,
refine ⟨⟨fonto, foto⟩, _⟩, intros x y xβ yβ, dsimp, dsimp at xβ yβ,
have fxB : f.fun_value x ∈ B, rw ←fonto.right.right, apply fun_value_def'' fonto.left, rw fonto.right.left, exact xβ,
have fyB : f.fun_value y ∈ B, rw ←fonto.right.right, apply fun_value_def'' fonto.left, rw fonto.right.left, exact yβ,
have xd : x ∈ f.dom, rw fonto.right.left, exact xβ,
have yd : y ∈ f.dom, rw fonto.right.left, exact yβ,
simp only [S, fun_order, pair_mem_pair_sep' fxB fyB, T3G_a fonto.left foto _ xd, T3G_a fonto.left foto _ yd],
let P := B.pair S,
have cond : P.snd ⊆ P.fst.prod P.fst,
simp only [fst_congr, snd_congr], exact Swell.lin.rel,
use P, split,
rw memW, exact ⟨_, _, rfl, BA, Swell⟩,
change β = if is_rel : P.snd ⊆ P.fst.prod P.fst then eps_img ⟨P.fst, P.snd, is_rel⟩ else ∅,
simp only [dif_pos cond, fst_congr, snd_congr],
let P' : struct := ⟨B, S, Swell.lin.rel⟩,
let β' : struct := β.eps_order_struct,
have Swell' : P'.fld.well_order P'.rel := Swell,
have βwell' : β'.fld.well_order β'.rel := βwell,
rw ←(iso_iff_eps_img_eq βwell' Swell').mp ⟨f, iso⟩,
symmetry, exact eps_img_trans_well_eq_self (ordinal_trans βord) βwell,
apply classical.by_contradiction, intro all, push_neg at all,
apply not_exists_ord_set, use α, intro β,
simp only [memα, and_iff_left_iff_imp], exact all _,
end
def WO : Prop := ∀ A : Set, ∃ R : Set, A.well_order R
theorem choice_equiv_3_WO : Axiom_of_choice_III.{u} → WO.{u} :=
begin
intros ax3 A,
obtain ⟨α, αord, ndom⟩ := @exists_large_ord A,
obtain ⟨G, Gfun, Gdom, Gspec⟩ := @ax3 A,
obtain ⟨e, eA⟩ := univ_not_set' A,
let rec := λ f : Set, if A \ f.ran = ∅ then e else G.fun_value (A \ f.ran),
obtain ⟨F, ⟨Ffun, Fdom, Fspec⟩, -⟩ := transfinite_rec' (ordinal_well_ordered αord) rec,
have Fval : ∀ {γ : Set}, γ ∈ α → A \ F.img γ ≠ ∅ → F.fun_value γ = G.fun_value (A \ F.img γ),
intros γ γα case, rw ←restrict_ran at case,
simp only [Fspec γα, seg_ord_eq_self αord γα, rec],
simp only [case, if_false], rw restrict_ran,
have Fval' : ∀ {γ : Set}, γ ∈ α → A \ F.img γ = ∅ → F.fun_value γ = e,
intros γ γα case, rw ←restrict_ran at case,
simp only [Fspec γα, seg_ord_eq_self αord γα, rec],
simp only [case, if_true, eq_self_iff_true],
have Fran : F.ran ⊆ A ∪ {e}, intros x xF, rw mem_ran_iff Ffun at xF,
rcases xF with ⟨δ, δα, xFδ⟩, subst xFδ, rw Fdom at δα, rw [mem_union, mem_singleton],
by_cases case : A \ (F.img δ) = ∅,
right, exact Fval' δα case,
left, rw Fval δα case,
have sub : A \ F.img δ ∈ G.dom, rw [Gdom, mem_sep, mem_powerset], exact ⟨subset_diff, case⟩,
exact subset_diff (Gspec _ sub),
have Foto'' : ∀ {β : Set}, β ∈ α → F.fun_value β ≠ e → ∀ {γ : Set}, γ ∈ β → F.fun_value γ ≠ e → F.fun_value β ≠ F.fun_value γ,
intros β βα Fβe γ γβ Fγe Fβγ,
have Fβ : F.fun_value β ∉ F.img β,
have h : A \ F.img β ≠ ∅, intro h, exact Fβe (Fval' βα h),
specialize Fval βα h, rw Fval,
have h' : A \ F.img β ∈ G.dom, rw [Gdom, mem_sep, mem_powerset], exact ⟨subset_diff, h⟩,
specialize Gspec _ h', rw mem_diff at Gspec, exact Gspec.right,
apply Fβ, rw Fβγ, refine fun_value_mem_img Ffun _ γβ,
rw Fdom, rw ←ord_le_iff_sub (ord_of_mem_ord αord βα) αord, left, exact βα,
have Foto' : ∀ {β : Set}, β ∈ α → F.fun_value β ≠ e → ∀ {γ : Set}, γ ∈ α → F.fun_value γ ≠ e → β ≠ γ → F.fun_value β ≠ F.fun_value γ,
intros β βα Fβe γ γα Fγe βneγ,
cases ord_conn (ord_of_mem_ord αord βα) (ord_of_mem_ord αord γα) βneγ with βγ γβ,
exact (Foto'' γα Fγe βγ Fβe).symm,
exact Foto'' βα Fβe γβ Fγe,
have eran : e ∈ F.ran,
apply classical.by_contradiction, intro eran, apply ndom, use F, split,
refine ⟨Ffun, Fdom, _⟩, intros y yran,
specialize Fran yran, rw [mem_union, mem_singleton] at Fran, cases Fran,
exact Fran,
exfalso, rw Fran at yran, exact eran yran,
have h : ∀ {β : Set}, β ∈ α → F.fun_value β ≠ e, intros β βα Fβe,
apply eran, rw mem_ran_iff Ffun, rw Fdom, exact ⟨_, βα, Fβe.symm⟩,
apply one_to_one_of Ffun, intros β βα γ γα βγ, rw Fdom at βα γα,
exact Foto' βα (h βα) γα (h γα) βγ,
rw mem_ran_iff Ffun at eran,
let X := {δ ∈ α | F.fun_value δ = e},
have XE : X ≠ ∅, apply ne_empty_of_inhabited, rcases eran with ⟨δ, δα, eFδ⟩, use δ, rw mem_sep,
rw Fdom at δα, exact ⟨δα, eFδ.symm⟩,
obtain ⟨δ, δX, le⟩ := (ordinal_well_ordered αord).well XE sep_subset,
rw mem_sep at δX,
have ne : ∀ {β : Set}, β ∈ δ → F.fun_value β ≠ e,
intros β βδ Fβe, apply le, use β,
have βα : β ∈ α := ord_mem_trans αord βδ δX.left,
rw [mem_sep' βα, eps_order, pair_mem_pair_sep' βα δX.left],
exact ⟨Fβe, βδ⟩,
use A.fun_order α.eps_order (F.restrict δ).inv, refine well_order_from_fun _ _ (ordinal_well_ordered αord),
have δsub : δ ⊆ F.dom, rw Fdom, rw ←ord_le_iff_sub (ord_of_mem_ord αord δX.left) αord, left, exact δX.left,
rw [into_fun, T3F_a, T3E_a, T3E_b, restrict_dom δsub, ←Fdom, restrict_ran], refine ⟨_, _, δsub⟩,
apply one_to_one_ext (restrict_is_function Ffun), simp only [restrict_dom δsub],
intros β γ βδ γδ Fβγ,
rw [restrict_fun_value Ffun δsub βδ, restrict_fun_value Ffun δsub γδ] at Fβγ,
apply classical.by_contradiction, intro βγ,
exact Foto' (ord_mem_trans αord βδ δX.left) (ne βδ) (ord_mem_trans αord γδ δX.left) (ne γδ) βγ Fβγ,
have sub : F.img δ ⊆ A, intro x, rw [mem_img' Ffun δsub],
rintro ⟨β, βδ, xFβ⟩, subst xFβ,
have h : F.fun_value β ∈ A ∪ {e}, apply Fran, apply fun_value_def'' Ffun, rw Fdom,
exact ord_mem_trans αord βδ δX.left,
rw [mem_union, mem_singleton] at h, cases h,
exact h,
exfalso, exact ne βδ h,
apply classical.by_contradiction, intro FδA,
have diffne : A \ F.img δ ≠ ∅ := diff_ne_empty_of_ne sub FδA,
rcases δX with ⟨δα, Fδe⟩,
rw Fval δα (diff_ne_empty_of_ne sub FδA) at Fδe, apply eA, rw ←Fδe,
have h : A \ F.img δ ∈ G.dom, rw [Gdom, mem_sep, mem_powerset],
exact ⟨subset_diff, diffne⟩,
exact subset_diff (Gspec _ h),
rw ←T3F_b (restrict_is_rel), exact restrict_is_function Ffun,
end
-- Well-Ordering Theorem
theorem exists_well_order : WO := choice_equiv_3_WO @ax_ch_3
-- Numeration Theorem
theorem exists_equin_ordinal {A : Set} : ∃ α : Set, α.is_ordinal ∧ A ≈ α :=
begin
obtain ⟨R, Rwell⟩ := exists_well_order A,
let R' : struct := ⟨A, R, Rwell.lin.rel⟩,
have Rwell' : R'.fld.well_order R'.rel := Rwell,
refine ⟨eps_img R', ⟨_, Rwell', rfl⟩, _⟩,
obtain ⟨corr, -⟩ := eps_img_iso Rwell',
exact ⟨_, corr⟩,
end
theorem exists_least_equin_ordinal {A : Set} :
∃ α : Set, α.is_ordinal ∧ A ≈ α ∧ ∀ {β : Set}, β.is_ordinal → A ≈ β → α ≤ β :=
begin
obtain ⟨α, αord, equin⟩ := @exists_equin_ordinal A,
let X := {β ∈ α.succ | A ≈ β},
have Xord : ∀ β : Set, β ∈ X → β.is_ordinal,
intros β βX, rw mem_sep at βX,
exact ord_of_mem_ord (succ_ord_of_ord αord) βX.left,
have XE : X ≠ ∅, apply ne_empty_of_inhabited, use α, rw mem_sep,
exact ⟨self_mem_succ, equin⟩,
obtain ⟨μ, μX, le⟩ := exists_least_ord_of_nonempty Xord XE,
refine ⟨_, Xord _ μX, _, _⟩,
rw mem_sep at μX, exact μX.right,
intros β βord equin',
by_cases βα : β ∈ α.succ,
have βX : β ∈ X, rw mem_sep, exact ⟨βα, equin'⟩,
rw [is_least, eps_order] at le, push_neg at le,
specialize le _ βX, rw pair_mem_pair_sep' βX μX at le,
rw ←ord_not_le_iff_lt (Xord _ μX) βord at le, push_neg at le, exact le,
apply classical.by_contradiction, intro μβ,
rw ord_not_le_iff_lt (Xord _ μX) βord at μβ,
rw mem_sep at μX, apply βα,
exact ord_mem_trans (succ_ord_of_ord αord) μβ μX.left,
end
noncomputable def card (A : Set) : Set := classical.some (@exists_least_equin_ordinal A)
lemma card_is_ordinal {A : Set} : A.card.is_ordinal :=
(classical.some_spec (@exists_least_equin_ordinal A)).left
lemma equin_card_of_self {A : Set} : A ≈ A.card :=
(classical.some_spec (@exists_least_equin_ordinal A)).right.left
lemma card_least {A : Set} : ∀ {β : Set}, β.is_ordinal → A ≈ β → A.card ≤ β :=
(classical.some_spec (@exists_least_equin_ordinal A)).right.right
-- Theorem 7P part a
theorem card_equiv {A B : Set} : A.card = B.card ↔ A ≈ B :=
begin
split,
intro cardAB, apply equin_trans equin_card_of_self, rw cardAB,
apply equin_symm, exact equin_card_of_self,
intro AB,
have equin : A ≈ B.card := equin_trans AB equin_card_of_self,
have equin' : B ≈ A.card := equin_trans (equin_symm AB) equin_card_of_self,
have cardAB : A.card ≤ B.card := card_least card_is_ordinal equin,
have cardBA : B.card ≤ A.card := card_least card_is_ordinal equin',
rw ord_eq_iff_le_and_le card_is_ordinal card_is_ordinal,
exact ⟨cardAB, cardBA⟩,
end
-- Theorem 7P part b
theorem card_finite : ∀ {A : Set}, A.is_finite → A.card ∈ ω ∧ A ≈ A.card :=
begin
intros A Afin, rcases Afin with ⟨n, nnat, An⟩,
refine ⟨_, equin_card_of_self⟩,
cases card_least (nat_is_ord nnat) An,
exact mem_nat_of_mem_nat_of_mem nnat h,
rw h, exact nnat,
end
def is_cardinal (N : Set) : Prop := ∃ A : Set, A.card = N
theorem card_of_cardinal_eq_self {κ : Set} (h : κ.is_cardinal) : κ.card = κ :=
begin
rcases h with ⟨K, Kcard⟩, nth_rewrite 1 ←Kcard, rw card_equiv,
rw ←Kcard, exact equin_symm equin_card_of_self,
end
lemma eq_card {A α : Set} (αord : α.is_ordinal) (equin : A ≈ α) (least : ∀ {β : Set}, β.is_ordinal → A ≈ β → α ≤ β) : α = A.card :=
begin
rw ord_eq_iff_le_and_le αord card_is_ordinal,
exact ⟨least card_is_ordinal equin_card_of_self, card_least αord equin⟩,
end
lemma is_card_of {A α : Set} (αord : α.is_ordinal) (equin : A ≈ α) (least : ∀ {β : Set}, β.is_ordinal → A ≈ β → α ≤ β) : α.is_cardinal :=
⟨_, (eq_card αord equin @least).symm⟩
-- parts 5-6 of theorem 6M
def is_chain (B : Set) : Prop := ∀ ⦃C : Set⦄, C ∈ B → ∀ ⦃D : Set⦄, D ∈ B → C ⊆ D ∨ D ⊆ C
-- Cardinal comparabilityd
def Axiom_of_choice_V : Prop := ∀ C D : Set, C ≼ D ∨ D ≼ C
-- Zorn's lemma
def Axiom_of_choice_VI : Prop := ∀ 𝓐 : Set, (∀ 𝓑 : Set, 𝓑.is_chain → 𝓑 ⊆ 𝓐 → 𝓑.Union ∈ 𝓐) → ∃ M, M ∈ 𝓐 ∧ ∀ N ∈ 𝓐, N ≠ M → ¬(M ⊆ N)
theorem choice_equiv_5_WO : Axiom_of_choice_V.{u} → WO.{u} :=
begin
intros ax_ch_5 A,
obtain ⟨α, αord, nd⟩ := @exists_large_ord A,
cases ax_ch_5 α A with αA Aα,
exfalso, exact nd αA,
rcases Aα with ⟨f, finto, foto⟩, use A.fun_order α.eps_order f,
exact well_order_from_fun finto foto (ordinal_well_ordered αord),
end
theorem choice_equiv_WO_6 : WO.{u} → Axiom_of_choice_VI.{u} :=
begin
intros wo 𝓐 closed,
obtain ⟨R, Rwell⟩ := wo 𝓐,
have diffseg : ∀ {A : Set}, A ∈ 𝓐 → 𝓐 \ R.seg A ≠ ∅,
intros A A𝓐,
apply diff_ne_empty_of_ne (seg_sub Rwell.lin.rel A𝓐),
intro segA𝓐, rw [←segA𝓐, mem_seg] at A𝓐,
exact Rwell.lin.irrefl A𝓐,
let next : Set → Set := λ X, if case : 𝓐 \ X = ∅ then ∅ else classical.some (Rwell.well case subset_diff),
have next_val : ∀ {A : Set}, A ∈ 𝓐 → next (R.seg A) = A,
intros A A𝓐, simp only [next, dif_neg (diffseg A𝓐)],
obtain ⟨mem, le⟩ := classical.some_spec (Rwell.well (diffseg A𝓐) subset_diff),
rw mem_diff at mem,
apply classical.by_contradiction, intro neq, cases Rwell.lin.conn mem.left A𝓐 neq,
apply mem.right, rw mem_seg, exact h,
apply le, use A, rw [mem_diff, mem_seg], refine ⟨⟨A𝓐, _⟩, h⟩, apply Rwell.lin.irrefl,
let f : Set → Set := λ g, if ∀ B : Set, B ∈ g.dom → g.fun_value B = one → B ⊆ next g.dom then one else ∅,
obtain ⟨F, ⟨Ffun, Fdom, Fspec⟩, -⟩ := transfinite_rec' Rwell f,
have segsub : ∀ {A : Set}, A ∈ 𝓐 → R.seg A ⊆ F.dom, rw Fdom,
intros A A𝓐, exact seg_sub Rwell.lin.rel A𝓐,
have Fval : ∀ {A : Set}, A ∈ 𝓐 → (∀ B : Set, B.pair A ∈ R → F.fun_value B = one → B ⊆ A) → F.fun_value A = one,
intros A A𝓐 case,
have case' : ∀ B : Set, B ∈ (F.restrict (R.seg A)).dom → (F.restrict (R.seg A)).fun_value B = one → B ⊆ next (F.restrict (R.seg A)).dom,
rw [restrict_dom (segsub A𝓐), next_val A𝓐], intros B BAR,
rw restrict_fun_value Ffun (segsub A𝓐) BAR, rw mem_seg at BAR,
intro FB, exact case _ BAR FB,
simp only [Fspec A𝓐, f], rw if_pos case',
have Fval' : ∀ {A : Set}, A ∈ 𝓐 → ¬ (∀ B : Set, B.pair A ∈ R → F.fun_value B = one → B ⊆ A) → F.fun_value A = ∅,
intros A A𝓐 case,
have case' : ¬ ∀ B : Set, B ∈ (F.restrict (R.seg A)).dom → (F.restrict (R.seg A)).fun_value B = one → B ⊆ next (F.restrict (R.seg A)).dom,
rw [restrict_dom (segsub A𝓐), next_val A𝓐], intro case', apply case,
intros B BA FB, rw ←mem_seg at BA, apply case' _ BA,
rw restrict_fun_value Ffun (segsub A𝓐) BA, exact FB,
simp only [Fspec A𝓐, f], rw if_neg case',
have Fran : F.ran ⊆ two, apply ran_sub Ffun, intros A A𝓐, rw Fdom at A𝓐, rw mem_two,
by_cases case : ∀ B : Set, B.pair A ∈ R → F.fun_value B = one → B ⊆ A,
right, exact Fval A𝓐 case,
left, exact Fval' A𝓐 case,
let 𝓒 := {A ∈ 𝓐 | F.fun_value A = one},
have mem𝓒 : ∀ {A : Set}, A ∈ 𝓐 → (A ∈ 𝓒 ↔ ∀ B : Set, B.pair A ∈ R → B ∈ 𝓒 → B ⊆ A),
intros A A𝓐, simp only [mem_sep], split,
rintros ⟨-, FA⟩ B BAR ⟨B𝓐, FB⟩, apply @classical.by_contradiction (B ⊆ A), intro BA,
apply zero_ne_one, symmetry, rw ←FA, apply Fval' A𝓐, push_neg,
exact ⟨_, BAR, FB, BA⟩,
intro h, refine ⟨A𝓐, Fval A𝓐 _⟩, intros B BAR FB, refine h _ BAR ⟨_, FB⟩,
replace BAR := Rwell.lin.rel BAR, rw pair_mem_prod at BAR, exact BAR.left,
use 𝓒.Union, split,
refine closed _ _ sep_subset, intros A A𝓒 B B𝓒,
have A𝓐 : A ∈ 𝓐, rw mem_sep at A𝓒, exact A𝓒.left,
have B𝓐 : B ∈ 𝓐, rw mem_sep at B𝓒, exact B𝓒.left,
by_cases case : A = B,
left, subst case, exact subset_self,
cases Rwell.lin.conn A𝓐 B𝓐 case with AB BA,
rw mem𝓒 B𝓐 at B𝓒, left, exact B𝓒 _ AB A𝓒,
rw mem𝓒 A𝓐 at A𝓒, right, exact A𝓒 _ BA B𝓒,
intros D D𝓐 Dne𝓒 𝓒D, apply Dne𝓒, rw eq_iff_subset_and_subset, refine ⟨_, 𝓒D⟩,
suffices D𝓒 : D ∈ 𝓒, exact subset_Union D𝓒,
rw mem𝓒 D𝓐, intros B BD B𝓒, exact subset_trans (subset_Union B𝓒) 𝓒D,
end
end Set |
572998da86ea5e9d66ab324522f94b2f44c3482b | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /src/Lean/Compiler/ConstFolding.lean | 376d01825f9860c5e02b7988be87f4268b8affe5 | [
"Apache-2.0"
] | permissive | williamdemeo/lean4 | 72161c58fe65c3ad955d6a3050bb7d37c04c0d54 | 6d00fcf1d6d873e195f9220c668ef9c58e9c4a35 | refs/heads/master | 1,678,305,356,877 | 1,614,708,995,000 | 1,614,708,995,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,086 | 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.Expr
import Lean.Compiler.Util
/- Constant folding for primitives that have special runtime support. -/
namespace Lean.Compiler
abbrev BinFoldFn := Bool → Expr → Expr → Option Expr
abbrev UnFoldFn := Bool → Expr → Option Expr
def mkUIntTypeName (nbytes : Nat) : Name :=
Name.mkSimple ("UInt" ++ toString nbytes)
structure NumScalarTypeInfo where
nbits : Nat
id : Name := mkUIntTypeName nbits
ofNatFn : Name := Name.mkStr id "ofNat"
toNatFn : Name := Name.mkStr id "toNat"
size : Nat := 2^nbits
def numScalarTypes : List NumScalarTypeInfo :=
[{nbits := 8}, {nbits := 16}, {nbits := 32}, {nbits := 64},
{id := `USize, nbits := System.Platform.numBits}]
def isOfNat (fn : Name) : Bool :=
numScalarTypes.any (fun info => info.ofNatFn == fn)
def isToNat (fn : Name) : Bool :=
numScalarTypes.any (fun info => info.toNatFn == fn)
def getInfoFromFn (fn : Name) : List NumScalarTypeInfo → Option NumScalarTypeInfo
| [] => none
| info::infos =>
if info.ofNatFn == fn then some info
else getInfoFromFn fn infos
def getInfoFromVal : Expr → Option NumScalarTypeInfo
| Expr.app (Expr.const fn _ _) _ _ => getInfoFromFn fn numScalarTypes
| _ => none
@[export lean_get_num_lit]
def getNumLit : Expr → Option Nat
| Expr.lit (Literal.natVal n) _ => some n
| Expr.app (Expr.const fn _ _) a _ => if isOfNat fn then getNumLit a else none
| _ => none
def mkUIntLit (info : NumScalarTypeInfo) (n : Nat) : Expr :=
mkApp (mkConst info.ofNatFn) (mkNatLit (n%info.size))
def mkUInt32Lit (n : Nat) : Expr :=
mkUIntLit {nbits := 32} n
def foldBinUInt (fn : NumScalarTypeInfo → Bool → Nat → Nat → Nat) (beforeErasure : Bool) (a₁ a₂ : Expr) : Option Expr := do
let n₁ ← getNumLit a₁
let n₂ ← getNumLit a₂
let info ← getInfoFromVal a₁
pure $ mkUIntLit info (fn info beforeErasure n₁ n₂)
def foldUIntAdd := foldBinUInt $ fun _ _ => Add.add
def foldUIntMul := foldBinUInt $ fun _ _ => Mul.mul
def foldUIntDiv := foldBinUInt $ fun _ _ => Div.div
def foldUIntMod := foldBinUInt $ fun _ _ => Mod.mod
def foldUIntSub := foldBinUInt $ fun info _ a b => (a + (info.size - b))
def preUIntBinFoldFns : List (Name × BinFoldFn) :=
[(`add, foldUIntAdd), (`mul, foldUIntMul), (`div, foldUIntDiv),
(`mod, foldUIntMod), (`sub, foldUIntSub)]
def uintBinFoldFns : List (Name × BinFoldFn) :=
numScalarTypes.foldl (fun r info => r ++ (preUIntBinFoldFns.map (fun ⟨suffix, fn⟩ => (info.id ++ suffix, fn)))) []
def foldNatBinOp (fn : Nat → Nat → Nat) (a₁ a₂ : Expr) : Option Expr := do
let n₁ ← getNumLit a₁
let n₂ ← getNumLit a₂
pure $ mkNatLit (fn n₁ n₂)
def foldNatAdd (_ : Bool) := foldNatBinOp Add.add
def foldNatMul (_ : Bool) := foldNatBinOp Mul.mul
def foldNatDiv (_ : Bool) := foldNatBinOp Div.div
def foldNatMod (_ : Bool) := foldNatBinOp Mod.mod
-- TODO: add option for controlling the limit
def natPowThreshold := 256
def foldNatPow (_ : Bool) (a₁ a₂ : Expr) : Option Expr := do
let n₁ ← getNumLit a₁
let n₂ ← getNumLit a₂
if n₂ < natPowThreshold then pure $ mkNatLit (n₁ ^ n₂) else none
def mkNatEq (a b : Expr) : Expr :=
mkAppN (mkConst `Eq [levelOne]) #[(mkConst `Nat), a, b]
def mkNatLt (a b : Expr) : Expr :=
mkAppN (mkConst `HasLess.Less [levelZero]) #[mkConst `Nat, mkConst `Nat.less, a, b]
def mkNatLe (a b : Expr) : Expr :=
mkAppN (mkConst `HasLessEq.LessEq [levelZero]) #[mkConst `Nat, mkConst `Nat.lessEq, a, b]
def toDecidableExpr (beforeErasure : Bool) (pred : Expr) (r : Bool) : Expr :=
match beforeErasure, r with
| false, true => mkDecIsTrue neutralExpr neutralExpr
| false, false => mkDecIsFalse neutralExpr neutralExpr
| true, true => mkDecIsTrue pred (mkLcProof pred)
| true, false => mkDecIsFalse pred (mkLcProof pred)
def foldNatBinPred (mkPred : Expr → Expr → Expr) (fn : Nat → Nat → Bool)
(beforeErasure : Bool) (a₁ a₂ : Expr) : Option Expr := do
let n₁ ← getNumLit a₁
let n₂ ← getNumLit a₂
pure $ toDecidableExpr beforeErasure (mkPred a₁ a₂) (fn n₁ n₂)
def foldNatDecEq := foldNatBinPred mkNatEq (fun a b => a = b)
def foldNatDecLt := foldNatBinPred mkNatLt (fun a b => a < b)
def foldNatDecLe := foldNatBinPred mkNatLe (fun a b => a ≤ b)
def natFoldFns : List (Name × BinFoldFn) :=
[(`Nat.add, foldNatAdd),
(`Nat.mul, foldNatMul),
(`Nat.div, foldNatDiv),
(`Nat.mod, foldNatMod),
(`Nat.pow, foldNatPow),
(`Nat.pow._main, foldNatPow),
(`Nat.decEq, foldNatDecEq),
(`Nat.decLt, foldNatDecLt),
(`Nat.decLe, foldNatDecLe)]
def getBoolLit : Expr → Option Bool
| Expr.const `Bool.true _ _ => some true
| Expr.const `Bool.false _ _ => some false
| _ => none
def foldStrictAnd (_ : Bool) (a₁ a₂ : Expr) : Option Expr :=
let v₁ := getBoolLit a₁
let v₂ := getBoolLit a₂
match v₁, v₂ with
| some true, _ => a₂
| some false, _ => a₁
| _, some true => a₁
| _, some false => a₂
| _, _ => none
def foldStrictOr (_ : Bool) (a₁ a₂ : Expr) : Option Expr :=
let v₁ := getBoolLit a₁
let v₂ := getBoolLit a₂
match v₁, v₂ with
| some true, _ => a₁
| some false, _ => a₂
| _, some true => a₂
| _, some false => a₁
| _, _ => none
def boolFoldFns : List (Name × BinFoldFn) :=
[(`strictOr, foldStrictOr), (`strictAnd, foldStrictAnd)]
def binFoldFns : List (Name × BinFoldFn) :=
boolFoldFns ++ uintBinFoldFns ++ natFoldFns
def foldNatSucc (_ : Bool) (a : Expr) : Option Expr := do
let n ← getNumLit a
pure $ mkNatLit (n+1)
def foldCharOfNat (beforeErasure : Bool) (a : Expr) : Option Expr := do
guard (!beforeErasure)
let n ← getNumLit a
pure $
if isValidChar n.toUInt32 then mkUInt32Lit n
else mkUInt32Lit 0
def foldToNat (_ : Bool) (a : Expr) : Option Expr := do
let n ← getNumLit a
pure $ mkNatLit n
def uintFoldToNatFns : List (Name × UnFoldFn) :=
numScalarTypes.foldl (fun r info => (info.toNatFn, foldToNat) :: r) []
def unFoldFns : List (Name × UnFoldFn) :=
[(`Nat.succ, foldNatSucc),
(`Char.ofNat, foldCharOfNat)]
++ uintFoldToNatFns
def findBinFoldFn (fn : Name) : Option BinFoldFn :=
binFoldFns.lookup fn
def findUnFoldFn (fn : Name) : Option UnFoldFn :=
unFoldFns.lookup fn
@[export lean_fold_bin_op]
def foldBinOp (beforeErasure : Bool) (f : Expr) (a : Expr) (b : Expr) : Option Expr := do
match f with
| Expr.const fn _ _ =>
let foldFn ← findBinFoldFn fn
foldFn beforeErasure a b
| _ => none
@[export lean_fold_un_op]
def foldUnOp (beforeErasure : Bool) (f : Expr) (a : Expr) : Option Expr := do
match f with
| Expr.const fn _ _ =>
let foldFn ← findUnFoldFn fn
foldFn beforeErasure a
| _ => none
end Lean.Compiler
|
ca5dfe0725a1cf1e93691ce0240fb933a790d029 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/measure_theory/integration_auto.lean | 46cd72987b90efae551cc222c002a11bd4540fed | [] | 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 | 72,675 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.measure_theory.measure_space
import Mathlib.measure_theory.borel_space
import Mathlib.data.indicator_function
import Mathlib.data.support
import Mathlib.PostPort
universes u v l u_1 u_2 u_3 u_4 u_5
namespace Mathlib
/-!
# Lebesgue integral for `ennreal`-valued functions
We define simple functions and show that each Borel measurable function on `ennreal` can be
approximated by a sequence of simple functions.
To prove something for an arbitrary measurable function into `ennreal`, the theorem
`measurable.ennreal_induction` shows that is it sufficient to show that the property holds for
(multiples of) characteristic functions and is closed under addition and supremum of increasing
sequences of functions.
## Notation
We introduce the following notation for the lower Lebesgue integral of a function `f : α → ennreal`.
* `∫⁻ x, f x ∂μ`: integral of a function `f : α → ennreal` with respect to a measure `μ`;
* `∫⁻ x, f x`: integral of a function `f : α → ennreal` with respect to the canonical measure
`volume` on `α`;
* `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ennreal` over a set `s` with respect
to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`;
* `∫⁻ x in s, f x`: integral of a function `f : α → ennreal` over a set `s` with respect
to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`.
-/
namespace measure_theory
/-- A function `f` from a measurable space to any type is called *simple*,
if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. This structure bundles
a function with these properties. -/
structure simple_func (α : Type u) [measurable_space α] (β : Type v) where
to_fun : α → β
is_measurable_fiber' : ∀ (x : β), is_measurable (to_fun ⁻¹' singleton x)
finite_range' : set.finite (set.range to_fun)
namespace simple_func
protected instance has_coe_to_fun {α : Type u_1} {β : Type u_2} [measurable_space α] :
has_coe_to_fun (simple_func α β) :=
has_coe_to_fun.mk (fun (x : simple_func α β) => α → β) to_fun
theorem coe_injective {α : Type u_1} {β : Type u_2} [measurable_space α] {f : simple_func α β}
{g : simple_func α β} (H : ⇑f = ⇑g) : f = g :=
sorry
theorem ext {α : Type u_1} {β : Type u_2} [measurable_space α] {f : simple_func α β}
{g : simple_func α β} (H : ∀ (a : α), coe_fn f a = coe_fn g a) : f = g :=
coe_injective (funext H)
theorem finite_range {α : Type u_1} {β : Type u_2} [measurable_space α] (f : simple_func α β) :
set.finite (set.range ⇑f) :=
finite_range' f
theorem is_measurable_fiber {α : Type u_1} {β : Type u_2} [measurable_space α] (f : simple_func α β)
(x : β) : is_measurable (⇑f ⁻¹' singleton x) :=
is_measurable_fiber' f x
/-- Range of a simple function `α →ₛ β` as a `finset β`. -/
protected def range {α : Type u_1} {β : Type u_2} [measurable_space α] (f : simple_func α β) :
finset β :=
set.finite.to_finset (finite_range f)
@[simp] theorem mem_range {α : Type u_1} {β : Type u_2} [measurable_space α] {f : simple_func α β}
{b : β} : b ∈ simple_func.range f ↔ b ∈ set.range ⇑f :=
set.finite.mem_to_finset
theorem mem_range_self {α : Type u_1} {β : Type u_2} [measurable_space α] (f : simple_func α β)
(x : α) : coe_fn f x ∈ simple_func.range f :=
iff.mpr mem_range (Exists.intro x rfl)
@[simp] theorem coe_range {α : Type u_1} {β : Type u_2} [measurable_space α] (f : simple_func α β) :
↑(simple_func.range f) = set.range ⇑f :=
set.finite.coe_to_finset (finite_range f)
theorem mem_range_of_measure_ne_zero {α : Type u_1} {β : Type u_2} [measurable_space α]
{f : simple_func α β} {x : β} {μ : measure α} (H : coe_fn μ (⇑f ⁻¹' singleton x) ≠ 0) :
x ∈ simple_func.range f :=
sorry
theorem forall_range_iff {α : Type u_1} {β : Type u_2} [measurable_space α] {f : simple_func α β}
{p : β → Prop} : (∀ (y : β), y ∈ simple_func.range f → p y) ↔ ∀ (x : α), p (coe_fn f x) :=
sorry
theorem exists_range_iff {α : Type u_1} {β : Type u_2} [measurable_space α] {f : simple_func α β}
{p : β → Prop} :
(∃ (y : β), ∃ (H : y ∈ simple_func.range f), p y) ↔ ∃ (x : α), p (coe_fn f x) :=
sorry
theorem preimage_eq_empty_iff {α : Type u_1} {β : Type u_2} [measurable_space α]
(f : simple_func α β) (b : β) : ⇑f ⁻¹' singleton b = ∅ ↔ ¬b ∈ simple_func.range f :=
iff.trans set.preimage_singleton_eq_empty (not_congr (iff.symm mem_range))
theorem exists_forall_le {α : Type u_1} {β : Type u_2} [measurable_space α] [Nonempty β]
[directed_order β] (f : simple_func α β) : ∃ (C : β), ∀ (x : α), coe_fn f x ≤ C :=
Exists.imp (fun (C : β) => iff.mp forall_range_iff) (finset.exists_le (simple_func.range f))
/-- Constant function as a `simple_func`. -/
def const (α : Type u_1) {β : Type u_2} [measurable_space α] (b : β) : simple_func α β :=
mk (fun (a : α) => b) sorry set.finite_range_const
protected instance inhabited {α : Type u_1} {β : Type u_2} [measurable_space α] [Inhabited β] :
Inhabited (simple_func α β) :=
{ default := const α Inhabited.default }
theorem const_apply {α : Type u_1} {β : Type u_2} [measurable_space α] (a : α) (b : β) :
coe_fn (const α b) a = b :=
rfl
@[simp] theorem coe_const {α : Type u_1} {β : Type u_2} [measurable_space α] (b : β) :
⇑(const α b) = function.const α b :=
rfl
@[simp] theorem range_const {β : Type u_2} (α : Type u_1) [measurable_space α] [Nonempty α]
(b : β) : simple_func.range (const α b) = singleton b :=
sorry
theorem is_measurable_cut {α : Type u_1} {β : Type u_2} [measurable_space α] (r : α → β → Prop)
(f : simple_func α β) (h : ∀ (b : β), is_measurable (set_of fun (a : α) => r a b)) :
is_measurable (set_of fun (a : α) => r a (coe_fn f a)) :=
sorry
theorem is_measurable_preimage {α : Type u_1} {β : Type u_2} [measurable_space α]
(f : simple_func α β) (s : set β) : is_measurable (⇑f ⁻¹' s) :=
is_measurable_cut (fun (_x : α) (b : β) => b ∈ s) f fun (b : β) => is_measurable.const (b ∈ s)
/-- A simple function is measurable -/
protected theorem measurable {α : Type u_1} {β : Type u_2} [measurable_space α] [measurable_space β]
(f : simple_func α β) : measurable ⇑f :=
fun (s : set β) (_x : is_measurable s) => is_measurable_preimage f s
protected theorem ae_measurable {α : Type u_1} {β : Type u_2} [measurable_space α]
[measurable_space β] {μ : measure α} (f : simple_func α β) : ae_measurable ⇑f :=
measurable.ae_measurable (simple_func.measurable f)
protected theorem sum_measure_preimage_singleton {α : Type u_1} {β : Type u_2} [measurable_space α]
(f : simple_func α β) {μ : measure α} (s : finset β) :
(finset.sum s fun (y : β) => coe_fn μ (⇑f ⁻¹' singleton y)) = coe_fn μ (⇑f ⁻¹' ↑s) :=
sum_measure_preimage_singleton s fun (_x : β) (_x_1 : _x ∈ s) => is_measurable_fiber f _x
theorem sum_range_measure_preimage_singleton {α : Type u_1} {β : Type u_2} [measurable_space α]
(f : simple_func α β) (μ : measure α) :
(finset.sum (simple_func.range f) fun (y : β) => coe_fn μ (⇑f ⁻¹' singleton y)) =
coe_fn μ set.univ :=
sorry
/-- If-then-else as a `simple_func`. -/
def piecewise {α : Type u_1} {β : Type u_2} [measurable_space α] (s : set α) (hs : is_measurable s)
(f : simple_func α β) (g : simple_func α β) : simple_func α β :=
mk (set.piecewise s ⇑f ⇑g) sorry sorry
@[simp] theorem coe_piecewise {α : Type u_1} {β : Type u_2} [measurable_space α] {s : set α}
(hs : is_measurable s) (f : simple_func α β) (g : simple_func α β) :
⇑(piecewise s hs f g) = set.piecewise s ⇑f ⇑g :=
rfl
theorem piecewise_apply {α : Type u_1} {β : Type u_2} [measurable_space α] {s : set α}
(hs : is_measurable s) (f : simple_func α β) (g : simple_func α β) (a : α) :
coe_fn (piecewise s hs f g) a = ite (a ∈ s) (coe_fn f a) (coe_fn g a) :=
rfl
@[simp] theorem piecewise_compl {α : Type u_1} {β : Type u_2} [measurable_space α] {s : set α}
(hs : is_measurable (sᶜ)) (f : simple_func α β) (g : simple_func α β) :
piecewise (sᶜ) hs f g = piecewise s (is_measurable.of_compl hs) g f :=
sorry
@[simp] theorem piecewise_univ {α : Type u_1} {β : Type u_2} [measurable_space α]
(f : simple_func α β) (g : simple_func α β) : piecewise set.univ is_measurable.univ f g = f :=
sorry
@[simp] theorem piecewise_empty {α : Type u_1} {β : Type u_2} [measurable_space α]
(f : simple_func α β) (g : simple_func α β) : piecewise ∅ is_measurable.empty f g = g :=
sorry
theorem measurable_bind {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
[measurable_space γ] (f : simple_func α β) (g : β → α → γ) (hg : ∀ (b : β), measurable (g b)) :
measurable fun (a : α) => g (coe_fn f a) a :=
fun (s : set γ) (hs : is_measurable s) =>
is_measurable_cut (fun (a : α) (b : β) => g b a ∈ s) f fun (b : β) => hg b hs
/-- If `f : α →ₛ β` is a simple function and `g : β → α →ₛ γ` is a family of simple functions,
then `f.bind g` binds the first argument of `g` to `f`. In other words, `f.bind g a = g (f a) a`. -/
def bind {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] (f : simple_func α β)
(g : β → simple_func α γ) : simple_func α γ :=
mk (fun (a : α) => coe_fn (g (coe_fn f a)) a) sorry sorry
@[simp] theorem bind_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α β) (g : β → simple_func α γ) (a : α) :
coe_fn (bind f g) a = coe_fn (g (coe_fn f a)) a :=
rfl
/-- Given a function `g : β → γ` and a simple function `f : α →ₛ β`, `f.map g` return the simple
function `g ∘ f : α →ₛ γ` -/
def map {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] (g : β → γ)
(f : simple_func α β) : simple_func α γ :=
bind f (const α ∘ g)
theorem map_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] (g : β → γ)
(f : simple_func α β) (a : α) : coe_fn (map g f) a = g (coe_fn f a) :=
rfl
theorem map_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} [measurable_space α]
(g : β → γ) (h : γ → δ) (f : simple_func α β) : map h (map g f) = map (h ∘ g) f :=
rfl
@[simp] theorem coe_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(g : β → γ) (f : simple_func α β) : ⇑(map g f) = g ∘ ⇑f :=
rfl
@[simp] theorem range_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
[DecidableEq γ] (g : β → γ) (f : simple_func α β) :
simple_func.range (map g f) = finset.image g (simple_func.range f) :=
sorry
@[simp] theorem map_const {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(g : β → γ) (b : β) : map g (const α b) = const α (g b) :=
rfl
theorem map_preimage {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α β) (g : β → γ) (s : set γ) :
⇑(map g f) ⁻¹' s = ⇑f ⁻¹' ↑(finset.filter (fun (b : β) => g b ∈ s) (simple_func.range f)) :=
sorry
theorem map_preimage_singleton {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α β) (g : β → γ) (c : γ) :
⇑(map g f) ⁻¹' singleton c =
⇑f ⁻¹' ↑(finset.filter (fun (b : β) => g b = c) (simple_func.range f)) :=
map_preimage f g (singleton c)
/-- Composition of a `simple_fun` and a measurable function is a `simple_func`. -/
def comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] [measurable_space β]
(f : simple_func β γ) (g : α → β) (hgm : measurable g) : simple_func α γ :=
mk (⇑f ∘ g) sorry sorry
@[simp] theorem coe_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
[measurable_space β] (f : simple_func β γ) {g : α → β} (hgm : measurable g) :
⇑(comp f g hgm) = ⇑f ∘ g :=
rfl
theorem range_comp_subset_range {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
[measurable_space β] (f : simple_func β γ) {g : α → β} (hgm : measurable g) :
simple_func.range (comp f g hgm) ⊆ simple_func.range f :=
sorry
/-- If `f` is a simple function taking values in `β → γ` and `g` is another simple function
with the same domain and codomain `β`, then `f.seq g = f a (g a)`. -/
def seq {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α (β → γ)) (g : simple_func α β) : simple_func α γ :=
bind f fun (f : β → γ) => map f g
@[simp] theorem seq_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α (β → γ)) (g : simple_func α β) (a : α) :
coe_fn (seq f g) a = coe_fn f a (coe_fn g a) :=
rfl
/-- Combine two simple functions `f : α →ₛ β` and `g : α →ₛ β`
into `λ a, (f a, g a)`. -/
def pair {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] (f : simple_func α β)
(g : simple_func α γ) : simple_func α (β × γ) :=
seq (map Prod.mk f) g
@[simp] theorem pair_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α β) (g : simple_func α γ) (a : α) :
coe_fn (pair f g) a = (coe_fn f a, coe_fn g a) :=
rfl
theorem pair_preimage {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α β) (g : simple_func α γ) (s : set β) (t : set γ) :
⇑(pair f g) ⁻¹' set.prod s t = ⇑f ⁻¹' s ∩ ⇑g ⁻¹' t :=
rfl
/- A special form of `pair_preimage` -/
theorem pair_preimage_singleton {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
(f : simple_func α β) (g : simple_func α γ) (b : β) (c : γ) :
⇑(pair f g) ⁻¹' singleton (b, c) = ⇑f ⁻¹' singleton b ∩ ⇑g ⁻¹' singleton c :=
sorry
theorem bind_const {α : Type u_1} {β : Type u_2} [measurable_space α] (f : simple_func α β) :
bind f (const α) = f :=
sorry
protected instance has_zero {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β] :
HasZero (simple_func α β) :=
{ zero := const α 0 }
protected instance has_add {α : Type u_1} {β : Type u_2} [measurable_space α] [Add β] :
Add (simple_func α β) :=
{ add := fun (f g : simple_func α β) => seq (map Add.add f) g }
protected instance has_mul {α : Type u_1} {β : Type u_2} [measurable_space α] [Mul β] :
Mul (simple_func α β) :=
{ mul := fun (f g : simple_func α β) => seq (map Mul.mul f) g }
protected instance has_sup {α : Type u_1} {β : Type u_2} [measurable_space α] [has_sup β] :
has_sup (simple_func α β) :=
has_sup.mk fun (f g : simple_func α β) => seq (map has_sup.sup f) g
protected instance has_inf {α : Type u_1} {β : Type u_2} [measurable_space α] [has_inf β] :
has_inf (simple_func α β) :=
has_inf.mk fun (f g : simple_func α β) => seq (map has_inf.inf f) g
protected instance has_le {α : Type u_1} {β : Type u_2} [measurable_space α] [HasLessEq β] :
HasLessEq (simple_func α β) :=
{ LessEq := fun (f g : simple_func α β) => ∀ (a : α), coe_fn f a ≤ coe_fn g a }
@[simp] theorem coe_zero {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β] : ⇑0 = 0 :=
rfl
@[simp] theorem const_zero {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β] :
const α 0 = 0 :=
rfl
@[simp] theorem coe_add {α : Type u_1} {β : Type u_2} [measurable_space α] [Add β]
(f : simple_func α β) (g : simple_func α β) : ⇑(f + g) = ⇑f + ⇑g :=
rfl
@[simp] theorem coe_mul {α : Type u_1} {β : Type u_2} [measurable_space α] [Mul β]
(f : simple_func α β) (g : simple_func α β) : ⇑(f * g) = ⇑f * ⇑g :=
rfl
@[simp] theorem coe_le {α : Type u_1} {β : Type u_2} [measurable_space α] [preorder β]
{f : simple_func α β} {g : simple_func α β} : ⇑f ≤ ⇑g ↔ f ≤ g :=
iff.rfl
@[simp] theorem range_zero {α : Type u_1} {β : Type u_2} [measurable_space α] [Nonempty α]
[HasZero β] : simple_func.range 0 = singleton 0 :=
sorry
theorem eq_zero_of_mem_range_zero {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
{y : β} : y ∈ simple_func.range 0 → y = 0 :=
iff.mpr forall_range_iff fun (x : α) => rfl
theorem sup_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [has_sup β]
(f : simple_func α β) (g : simple_func α β) (a : α) :
coe_fn (f ⊔ g) a = coe_fn f a ⊔ coe_fn g a :=
rfl
theorem mul_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [Mul β] (f : simple_func α β)
(g : simple_func α β) (a : α) : coe_fn (f * g) a = coe_fn f a * coe_fn g a :=
rfl
theorem add_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [Add β] (f : simple_func α β)
(g : simple_func α β) (a : α) : coe_fn (f + g) a = coe_fn f a + coe_fn g a :=
rfl
theorem add_eq_map₂ {α : Type u_1} {β : Type u_2} [measurable_space α] [Add β] (f : simple_func α β)
(g : simple_func α β) : f + g = map (fun (p : β × β) => prod.fst p + prod.snd p) (pair f g) :=
rfl
theorem mul_eq_map₂ {α : Type u_1} {β : Type u_2} [measurable_space α] [Mul β] (f : simple_func α β)
(g : simple_func α β) : f * g = map (fun (p : β × β) => prod.fst p * prod.snd p) (pair f g) :=
rfl
theorem sup_eq_map₂ {α : Type u_1} {β : Type u_2} [measurable_space α] [has_sup β]
(f : simple_func α β) (g : simple_func α β) :
f ⊔ g = map (fun (p : β × β) => prod.fst p ⊔ prod.snd p) (pair f g) :=
rfl
theorem const_mul_eq_map {α : Type u_1} {β : Type u_2} [measurable_space α] [Mul β]
(f : simple_func α β) (b : β) : const α b * f = map (fun (a : β) => b * a) f :=
rfl
theorem map_add {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] [Add β] [Add γ]
{g : β → γ} (hg : ∀ (x y : β), g (x + y) = g x + g y) (f₁ : simple_func α β)
(f₂ : simple_func α β) : map g (f₁ + f₂) = map g f₁ + map g f₂ :=
ext fun (x : α) => hg (coe_fn f₁ x) (coe_fn f₂ x)
protected instance add_monoid {α : Type u_1} {β : Type u_2} [measurable_space α] [add_monoid β] :
add_monoid (simple_func α β) :=
function.injective.add_monoid (fun (f : simple_func α β) => (fun (this : α → β) => this) ⇑f)
coe_injective sorry sorry
protected instance add_comm_monoid {α : Type u_1} {β : Type u_2} [measurable_space α]
[add_comm_monoid β] : add_comm_monoid (simple_func α β) :=
function.injective.add_comm_monoid (fun (f : simple_func α β) => (fun (this : α → β) => this) ⇑f)
coe_injective sorry sorry
protected instance has_neg {α : Type u_1} {β : Type u_2} [measurable_space α] [Neg β] :
Neg (simple_func α β) :=
{ neg := fun (f : simple_func α β) => map Neg.neg f }
@[simp] theorem coe_neg {α : Type u_1} {β : Type u_2} [measurable_space α] [Neg β]
(f : simple_func α β) : ⇑(-f) = -⇑f :=
rfl
protected instance has_sub {α : Type u_1} {β : Type u_2} [measurable_space α] [Sub β] :
Sub (simple_func α β) :=
{ sub := fun (f g : simple_func α β) => seq (map Sub.sub f) g }
@[simp] theorem coe_sub {α : Type u_1} {β : Type u_2} [measurable_space α] [Sub β]
(f : simple_func α β) (g : simple_func α β) : ⇑(f - g) = ⇑f - ⇑g :=
rfl
theorem sub_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [Sub β] (f : simple_func α β)
(g : simple_func α β) (x : α) : coe_fn (f - g) x = coe_fn f x - coe_fn g x :=
rfl
protected instance add_group {α : Type u_1} {β : Type u_2} [measurable_space α] [add_group β] :
add_group (simple_func α β) :=
function.injective.add_group_sub (fun (f : simple_func α β) => (fun (this : α → β) => this) ⇑f)
coe_injective sorry sorry sorry sorry
protected instance add_comm_group {α : Type u_1} {β : Type u_2} [measurable_space α]
[add_comm_group β] : add_comm_group (simple_func α β) :=
function.injective.add_comm_group_sub
(fun (f : simple_func α β) => (fun (this : α → β) => this) ⇑f) coe_injective sorry sorry sorry
sorry
protected instance has_scalar {α : Type u_1} {β : Type u_2} [measurable_space α] {K : Type u_5}
[has_scalar K β] : has_scalar K (simple_func α β) :=
has_scalar.mk fun (k : K) (f : simple_func α β) => map (has_scalar.smul k) f
@[simp] theorem coe_smul {α : Type u_1} {β : Type u_2} [measurable_space α] {K : Type u_5}
[has_scalar K β] (c : K) (f : simple_func α β) : ⇑(c • f) = c • ⇑f :=
rfl
theorem smul_apply {α : Type u_1} {β : Type u_2} [measurable_space α] {K : Type u_5}
[has_scalar K β] (k : K) (f : simple_func α β) (a : α) : coe_fn (k • f) a = k • coe_fn f a :=
rfl
protected instance semimodule {α : Type u_1} {β : Type u_2} [measurable_space α] {K : Type u_5}
[semiring K] [add_comm_monoid β] [semimodule K β] : semimodule K (simple_func α β) :=
function.injective.semimodule K
(add_monoid_hom.mk (fun (f : simple_func α β) => (fun (this : α → β) => this) ⇑f) sorry sorry)
coe_injective sorry
theorem smul_eq_map {α : Type u_1} {β : Type u_2} [measurable_space α] {K : Type u_5}
[has_scalar K β] (k : K) (f : simple_func α β) : k • f = map (has_scalar.smul k) f :=
rfl
protected instance preorder {α : Type u_1} {β : Type u_2} [measurable_space α] [preorder β] :
preorder (simple_func α β) :=
preorder.mk LessEq (fun (a b : simple_func α β) => a ≤ b ∧ ¬b ≤ a) sorry sorry
protected instance partial_order {α : Type u_1} {β : Type u_2} [measurable_space α]
[partial_order β] : partial_order (simple_func α β) :=
partial_order.mk preorder.le preorder.lt sorry sorry sorry
protected instance order_bot {α : Type u_1} {β : Type u_2} [measurable_space α] [order_bot β] :
order_bot (simple_func α β) :=
order_bot.mk (const α ⊥) partial_order.le partial_order.lt sorry sorry sorry sorry
protected instance order_top {α : Type u_1} {β : Type u_2} [measurable_space α] [order_top β] :
order_top (simple_func α β) :=
order_top.mk (const α ⊤) partial_order.le partial_order.lt sorry sorry sorry sorry
protected instance semilattice_inf {α : Type u_1} {β : Type u_2} [measurable_space α]
[semilattice_inf β] : semilattice_inf (simple_func α β) :=
semilattice_inf.mk has_inf.inf partial_order.le partial_order.lt sorry sorry sorry sorry sorry
sorry
protected instance semilattice_sup {α : Type u_1} {β : Type u_2} [measurable_space α]
[semilattice_sup β] : semilattice_sup (simple_func α β) :=
semilattice_sup.mk has_sup.sup partial_order.le partial_order.lt sorry sorry sorry sorry sorry
sorry
protected instance semilattice_sup_bot {α : Type u_1} {β : Type u_2} [measurable_space α]
[semilattice_sup_bot β] : semilattice_sup_bot (simple_func α β) :=
semilattice_sup_bot.mk order_bot.bot semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
protected instance lattice {α : Type u_1} {β : Type u_2} [measurable_space α] [lattice β] :
lattice (simple_func α β) :=
lattice.mk semilattice_sup.sup semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry sorry
sorry semilattice_inf.inf sorry sorry sorry
protected instance bounded_lattice {α : Type u_1} {β : Type u_2} [measurable_space α]
[bounded_lattice β] : bounded_lattice (simple_func α β) :=
bounded_lattice.mk lattice.sup lattice.le lattice.lt sorry sorry sorry sorry sorry sorry
lattice.inf sorry sorry sorry order_top.top sorry order_bot.bot sorry
theorem finset_sup_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
[semilattice_sup_bot β] {f : γ → simple_func α β} (s : finset γ) (a : α) :
coe_fn (finset.sup s f) a = finset.sup s fun (c : γ) => coe_fn (f c) a :=
sorry
/-- Restrict a simple function `f : α →ₛ β` to a set `s`. If `s` is measurable,
then `f.restrict s a = if a ∈ s then f a else 0`, otherwise `f.restrict s = const α 0`. -/
def restrict {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β] (f : simple_func α β)
(s : set α) : simple_func α β :=
dite (is_measurable s) (fun (hs : is_measurable s) => piecewise s hs f 0)
fun (hs : ¬is_measurable s) => 0
theorem restrict_of_not_measurable {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
{f : simple_func α β} {s : set α} (hs : ¬is_measurable s) : restrict f s = 0 :=
dif_neg hs
@[simp] theorem coe_restrict {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) {s : set α} (hs : is_measurable s) :
⇑(restrict f s) = set.indicator s ⇑f :=
sorry
@[simp] theorem restrict_univ {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) : restrict f set.univ = f :=
sorry
@[simp] theorem restrict_empty {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) : restrict f ∅ = 0 :=
sorry
theorem map_restrict_of_zero {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
[HasZero β] [HasZero γ] {g : β → γ} (hg : g 0 = 0) (f : simple_func α β) (s : set α) :
map g (restrict f s) = restrict (map g f) s :=
sorry
theorem map_coe_ennreal_restrict {α : Type u_1} [measurable_space α] (f : simple_func α nnreal)
(s : set α) : map coe (restrict f s) = restrict (map coe f) s :=
map_restrict_of_zero ennreal.coe_zero f s
theorem map_coe_nnreal_restrict {α : Type u_1} [measurable_space α] (f : simple_func α nnreal)
(s : set α) : map coe (restrict f s) = restrict (map coe f) s :=
map_restrict_of_zero nnreal.coe_zero f s
theorem restrict_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) {s : set α} (hs : is_measurable s) (a : α) :
coe_fn (restrict f s) a = ite (a ∈ s) (coe_fn f a) 0 :=
sorry
theorem restrict_preimage {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) {s : set α} (hs : is_measurable s) {t : set β} (ht : ¬0 ∈ t) :
⇑(restrict f s) ⁻¹' t = s ∩ ⇑f ⁻¹' t :=
sorry
theorem restrict_preimage_singleton {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) {s : set α} (hs : is_measurable s) {r : β} (hr : r ≠ 0) :
⇑(restrict f s) ⁻¹' singleton r = s ∩ ⇑f ⁻¹' singleton r :=
restrict_preimage f hs (ne.symm hr)
theorem mem_restrict_range {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β] {r : β}
{s : set α} {f : simple_func α β} (hs : is_measurable s) :
r ∈ simple_func.range (restrict f s) ↔ r = 0 ∧ s ≠ set.univ ∨ r ∈ ⇑f '' s :=
sorry
theorem mem_image_of_mem_range_restrict {α : Type u_1} {β : Type u_2} [measurable_space α]
[HasZero β] {r : β} {s : set α} {f : simple_func α β}
(hr : r ∈ simple_func.range (restrict f s)) (h0 : r ≠ 0) : r ∈ ⇑f '' s :=
sorry
theorem restrict_mono {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β] [preorder β]
(s : set α) {f : simple_func α β} {g : simple_func α β} (H : f ≤ g) :
restrict f s ≤ restrict g s :=
sorry
/-- Fix a sequence `i : ℕ → β`. Given a function `α → β`, its `n`-th approximation
by simple functions is defined so that in case `β = ennreal` it sends each `a` to the supremum
of the set `{i k | k ≤ n ∧ i k ≤ f a}`, see `approx_apply` and `supr_approx_apply` for details. -/
def approx {α : Type u_1} {β : Type u_2} [measurable_space α] [semilattice_sup_bot β] [HasZero β]
(i : ℕ → β) (f : α → β) (n : ℕ) : simple_func α β :=
finset.sup (finset.range n)
fun (k : ℕ) => restrict (const α (i k)) (set_of fun (a : α) => i k ≤ f a)
theorem approx_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [semilattice_sup_bot β]
[HasZero β] [topological_space β] [order_closed_topology β] [measurable_space β]
[opens_measurable_space β] {i : ℕ → β} {f : α → β} {n : ℕ} (a : α) (hf : measurable f) :
coe_fn (approx i f n) a = finset.sup (finset.range n) fun (k : ℕ) => ite (i k ≤ f a) (i k) 0 :=
sorry
theorem monotone_approx {α : Type u_1} {β : Type u_2} [measurable_space α] [semilattice_sup_bot β]
[HasZero β] (i : ℕ → β) (f : α → β) : monotone (approx i f) :=
fun (n m : ℕ) (h : n ≤ m) => finset.sup_mono (iff.mpr finset.range_subset h)
theorem approx_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
[semilattice_sup_bot β] [HasZero β] [topological_space β] [order_closed_topology β]
[measurable_space β] [opens_measurable_space β] [measurable_space γ] {i : ℕ → β} {f : γ → β}
{g : α → γ} {n : ℕ} (a : α) (hf : measurable f) (hg : measurable g) :
coe_fn (approx i (f ∘ g) n) a = coe_fn (approx i f n) (g a) :=
sorry
theorem supr_approx_apply {α : Type u_1} {β : Type u_2} [measurable_space α] [topological_space β]
[complete_lattice β] [order_closed_topology β] [HasZero β] [measurable_space β]
[opens_measurable_space β] (i : ℕ → β) (f : α → β) (a : α) (hf : measurable f)
(h_zero : 0 = ⊥) :
(supr fun (n : ℕ) => coe_fn (approx i f n) a) =
supr fun (k : ℕ) => supr fun (h : i k ≤ f a) => i k :=
sorry
/-- A sequence of `ennreal`s such that its range is the set of non-negative rational numbers. -/
def ennreal_rat_embed (n : ℕ) : ennreal :=
ennreal.of_real ↑(option.get_or_else (encodable.decode ℚ n) 0)
theorem ennreal_rat_embed_encode (q : ℚ) :
ennreal_rat_embed (encodable.encode q) = ↑(nnreal.of_real ↑q) :=
sorry
/-- Approximate a function `α → ennreal` by a sequence of simple functions. -/
def eapprox {α : Type u_1} [measurable_space α] : (α → ennreal) → ℕ → simple_func α ennreal :=
approx ennreal_rat_embed
theorem monotone_eapprox {α : Type u_1} [measurable_space α] (f : α → ennreal) :
monotone (eapprox f) :=
monotone_approx ennreal_rat_embed f
theorem supr_eapprox_apply {α : Type u_1} [measurable_space α] (f : α → ennreal) (hf : measurable f)
(a : α) : (supr fun (n : ℕ) => coe_fn (eapprox f n) a) = f a :=
sorry
theorem eapprox_comp {α : Type u_1} {γ : Type u_3} [measurable_space α] [measurable_space γ]
{f : γ → ennreal} {g : α → γ} {n : ℕ} (hf : measurable f) (hg : measurable g) :
⇑(eapprox (f ∘ g) n) = ⇑(eapprox f n) ∘ g :=
funext fun (a : α) => approx_comp a hf hg
/-- Integral of a simple function whose codomain is `ennreal`. -/
def lintegral {α : Type u_1} [measurable_space α] (f : simple_func α ennreal) (μ : measure α) :
ennreal :=
finset.sum (simple_func.range f) fun (x : ennreal) => x * coe_fn μ (⇑f ⁻¹' singleton x)
theorem lintegral_eq_of_subset {α : Type u_1} [measurable_space α] {μ : measure α}
(f : simple_func α ennreal) {s : finset ennreal}
(hs :
∀ (x : α), coe_fn f x ≠ 0 → coe_fn μ (⇑f ⁻¹' singleton (coe_fn f x)) ≠ 0 → coe_fn f x ∈ s) :
lintegral f μ = finset.sum s fun (x : ennreal) => x * coe_fn μ (⇑f ⁻¹' singleton x) :=
sorry
/-- Calculate the integral of `(g ∘ f)`, where `g : β → ennreal` and `f : α →ₛ β`. -/
theorem map_lintegral {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
(g : β → ennreal) (f : simple_func α β) :
lintegral (map g f) μ =
finset.sum (simple_func.range f) fun (x : β) => g x * coe_fn μ (⇑f ⁻¹' singleton x) :=
sorry
theorem add_lintegral {α : Type u_1} [measurable_space α] {μ : measure α}
(f : simple_func α ennreal) (g : simple_func α ennreal) :
lintegral (f + g) μ = lintegral f μ + lintegral g μ :=
sorry
theorem const_mul_lintegral {α : Type u_1} [measurable_space α] {μ : measure α}
(f : simple_func α ennreal) (x : ennreal) : lintegral (const α x * f) μ = x * lintegral f μ :=
sorry
/-- Integral of a simple function `α →ₛ ennreal` as a bilinear map. -/
def lintegralₗ {α : Type u_1} [measurable_space α] :
linear_map ennreal (simple_func α ennreal) (linear_map ennreal (measure α) ennreal) :=
linear_map.mk (fun (f : simple_func α ennreal) => linear_map.mk (lintegral f) sorry sorry) sorry
sorry
@[simp] theorem zero_lintegral {α : Type u_1} [measurable_space α] {μ : measure α} :
lintegral 0 μ = 0 :=
iff.mp linear_map.ext_iff (linear_map.map_zero lintegralₗ) μ
theorem lintegral_add {α : Type u_1} [measurable_space α] {μ : measure α} {ν : measure α}
(f : simple_func α ennreal) : lintegral f (μ + ν) = lintegral f μ + lintegral f ν :=
linear_map.map_add (coe_fn lintegralₗ f) μ ν
theorem lintegral_smul {α : Type u_1} [measurable_space α] {μ : measure α}
(f : simple_func α ennreal) (c : ennreal) : lintegral f (c • μ) = c • lintegral f μ :=
linear_map.map_smul (coe_fn lintegralₗ f) c μ
@[simp] theorem lintegral_zero {α : Type u_1} [measurable_space α] (f : simple_func α ennreal) :
lintegral f 0 = 0 :=
linear_map.map_zero (coe_fn lintegralₗ f)
theorem lintegral_sum {α : Type u_1} [measurable_space α] {ι : Type u_2} (f : simple_func α ennreal)
(μ : ι → measure α) : lintegral f (measure.sum μ) = tsum fun (i : ι) => lintegral f (μ i) :=
sorry
theorem restrict_lintegral {α : Type u_1} [measurable_space α] {μ : measure α}
(f : simple_func α ennreal) {s : set α} (hs : is_measurable s) :
lintegral (restrict f s) μ =
finset.sum (simple_func.range f)
fun (r : ennreal) => r * coe_fn μ (⇑f ⁻¹' singleton r ∩ s) :=
sorry
theorem lintegral_restrict {α : Type u_1} [measurable_space α] (f : simple_func α ennreal)
(s : set α) (μ : measure α) :
lintegral f (measure.restrict μ s) =
finset.sum (simple_func.range f)
fun (y : ennreal) => y * coe_fn μ (⇑f ⁻¹' singleton y ∩ s) :=
sorry
theorem restrict_lintegral_eq_lintegral_restrict {α : Type u_1} [measurable_space α] {μ : measure α}
(f : simple_func α ennreal) {s : set α} (hs : is_measurable s) :
lintegral (restrict f s) μ = lintegral f (measure.restrict μ s) :=
sorry
theorem const_lintegral {α : Type u_1} [measurable_space α] {μ : measure α} (c : ennreal) :
lintegral (const α c) μ = c * coe_fn μ set.univ :=
sorry
theorem const_lintegral_restrict {α : Type u_1} [measurable_space α] {μ : measure α} (c : ennreal)
(s : set α) : lintegral (const α c) (measure.restrict μ s) = c * coe_fn μ s :=
sorry
theorem restrict_const_lintegral {α : Type u_1} [measurable_space α] {μ : measure α} (c : ennreal)
{s : set α} (hs : is_measurable s) : lintegral (restrict (const α c) s) μ = c * coe_fn μ s :=
sorry
theorem le_sup_lintegral {α : Type u_1} [measurable_space α] {μ : measure α}
(f : simple_func α ennreal) (g : simple_func α ennreal) :
lintegral f μ ⊔ lintegral g μ ≤ lintegral (f ⊔ g) μ :=
sorry
/-- `simple_func.lintegral` is monotone both in function and in measure. -/
theorem lintegral_mono {α : Type u_1} [measurable_space α] {f : simple_func α ennreal}
{g : simple_func α ennreal} (hfg : f ≤ g) {μ : measure α} {ν : measure α} (hμν : μ ≤ ν) :
lintegral f μ ≤ lintegral g ν :=
sorry
/-- `simple_func.lintegral` depends only on the measures of `f ⁻¹' {y}`. -/
theorem lintegral_eq_of_measure_preimage {α : Type u_1} {β : Type u_2} [measurable_space α]
{μ : measure α} [measurable_space β] {f : simple_func α ennreal} {g : simple_func β ennreal}
{ν : measure β}
(H : ∀ (y : ennreal), coe_fn μ (⇑f ⁻¹' singleton y) = coe_fn ν (⇑g ⁻¹' singleton y)) :
lintegral f μ = lintegral g ν :=
sorry
/-- If two simple functions are equal a.e., then their `lintegral`s are equal. -/
theorem lintegral_congr {α : Type u_1} [measurable_space α] {μ : measure α}
{f : simple_func α ennreal} {g : simple_func α ennreal}
(h : filter.eventually_eq (measure.ae μ) ⇑f ⇑g) : lintegral f μ = lintegral g μ :=
sorry
theorem lintegral_map {α : Type u_1} [measurable_space α] {μ : measure α} {β : Type u_2}
[measurable_space β] {μ' : measure β} (f : simple_func α ennreal) (g : simple_func β ennreal)
(m : α → β) (eq : ∀ (a : α), coe_fn f a = coe_fn g (m a))
(h : ∀ (s : set β), is_measurable s → coe_fn μ' s = coe_fn μ (m ⁻¹' s)) :
lintegral f μ = lintegral g μ' :=
sorry
theorem support_eq {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) :
function.support ⇑f =
set.Union
fun (y : β) =>
set.Union
fun (H : y ∈ finset.filter (fun (y : β) => y ≠ 0) (simple_func.range f)) =>
⇑f ⁻¹' singleton y :=
sorry
/-- A `simple_func` has finite measure support if it is equal to `0` outside of a set of finite
measure. -/
protected def fin_meas_supp {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
(f : simple_func α β) (μ : measure α) :=
filter.eventually_eq (measure.cofinite μ) (⇑f) 0
theorem fin_meas_supp_iff_support {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
{f : simple_func α β} {μ : measure α} :
simple_func.fin_meas_supp f μ ↔ coe_fn μ (function.support ⇑f) < ⊤ :=
iff.rfl
theorem fin_meas_supp_iff {α : Type u_1} {β : Type u_2} [measurable_space α] [HasZero β]
{f : simple_func α β} {μ : measure α} :
simple_func.fin_meas_supp f μ ↔ ∀ (y : β), y ≠ 0 → coe_fn μ (⇑f ⁻¹' singleton y) < ⊤ :=
sorry
namespace fin_meas_supp
theorem meas_preimage_singleton_ne_zero {α : Type u_1} {β : Type u_2} [measurable_space α]
[HasZero β] {μ : measure α} {f : simple_func α β} (h : simple_func.fin_meas_supp f μ) {y : β}
(hy : y ≠ 0) : coe_fn μ (⇑f ⁻¹' singleton y) < ⊤ :=
iff.mp fin_meas_supp_iff h y hy
protected theorem map {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] [HasZero β]
[HasZero γ] {μ : measure α} {f : simple_func α β} {g : β → γ}
(hf : simple_func.fin_meas_supp f μ) (hg : g 0 = 0) : simple_func.fin_meas_supp (map g f) μ :=
flip lt_of_le_of_lt hf (measure_mono (function.support_comp_subset hg ⇑f))
theorem of_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] [HasZero β]
[HasZero γ] {μ : measure α} {f : simple_func α β} {g : β → γ}
(h : simple_func.fin_meas_supp (map g f) μ) (hg : ∀ (b : β), g b = 0 → b = 0) :
simple_func.fin_meas_supp f μ :=
flip lt_of_le_of_lt h (measure_mono (function.support_subset_comp hg fun (x : α) => coe_fn f x))
theorem map_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] [HasZero β]
[HasZero γ] {μ : measure α} {f : simple_func α β} {g : β → γ}
(hg : ∀ {b : β}, g b = 0 ↔ b = 0) :
simple_func.fin_meas_supp (map g f) μ ↔ simple_func.fin_meas_supp f μ :=
{ mp := fun (h : simple_func.fin_meas_supp (map g f) μ) => of_map h fun (b : β) => iff.mp hg,
mpr := fun (h : simple_func.fin_meas_supp f μ) => fin_meas_supp.map h (iff.mpr hg rfl) }
protected theorem pair {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α] [HasZero β]
[HasZero γ] {μ : measure α} {f : simple_func α β} {g : simple_func α γ}
(hf : simple_func.fin_meas_supp f μ) (hg : simple_func.fin_meas_supp g μ) :
simple_func.fin_meas_supp (pair f g) μ :=
sorry
protected theorem map₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4}
[measurable_space α] [HasZero β] [HasZero γ] [HasZero δ] {μ : measure α} {f : simple_func α β}
(hf : simple_func.fin_meas_supp f μ) {g : simple_func α γ} (hg : simple_func.fin_meas_supp g μ)
{op : β → γ → δ} (H : op 0 0 = 0) :
simple_func.fin_meas_supp (map (function.uncurry op) (pair f g)) μ :=
fin_meas_supp.map (fin_meas_supp.pair hf hg) H
protected theorem add {α : Type u_1} [measurable_space α] {μ : measure α} {β : Type u_2}
[add_monoid β] {f : simple_func α β} {g : simple_func α β} (hf : simple_func.fin_meas_supp f μ)
(hg : simple_func.fin_meas_supp g μ) : simple_func.fin_meas_supp (f + g) μ :=
eq.mpr (id (Eq._oldrec (Eq.refl (simple_func.fin_meas_supp (f + g) μ)) (add_eq_map₂ f g)))
(fin_meas_supp.map₂ hf hg (zero_add 0))
protected theorem mul {α : Type u_1} [measurable_space α] {μ : measure α} {β : Type u_2}
[monoid_with_zero β] {f : simple_func α β} {g : simple_func α β}
(hf : simple_func.fin_meas_supp f μ) (hg : simple_func.fin_meas_supp g μ) :
simple_func.fin_meas_supp (f * g) μ :=
eq.mpr (id (Eq._oldrec (Eq.refl (simple_func.fin_meas_supp (f * g) μ)) (mul_eq_map₂ f g)))
(fin_meas_supp.map₂ hf hg (zero_mul 0))
theorem lintegral_lt_top {α : Type u_1} [measurable_space α] {μ : measure α}
{f : simple_func α ennreal} (hm : simple_func.fin_meas_supp f μ)
(hf : filter.eventually (fun (a : α) => coe_fn f a < ⊤) (measure.ae μ)) : lintegral f μ < ⊤ :=
sorry
theorem of_lintegral_lt_top {α : Type u_1} [measurable_space α] {μ : measure α}
{f : simple_func α ennreal} (h : lintegral f μ < ⊤) : simple_func.fin_meas_supp f μ :=
sorry
theorem iff_lintegral_lt_top {α : Type u_1} [measurable_space α] {μ : measure α}
{f : simple_func α ennreal}
(hf : filter.eventually (fun (a : α) => coe_fn f a < ⊤) (measure.ae μ)) :
simple_func.fin_meas_supp f μ ↔ lintegral f μ < ⊤ :=
{ mp := fun (h : simple_func.fin_meas_supp f μ) => lintegral_lt_top h hf,
mpr := fun (h : lintegral f μ < ⊤) => of_lintegral_lt_top h }
end fin_meas_supp
/-- To prove something for an arbitrary simple function, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under
addition (of functions with disjoint support).
It is possible to make the hypotheses in `h_sum` a bit stronger, and such conditions can be added
once we need them (for example it is only necessary to consider the case where `g` is a multiple
of a characteristic function, and that this multiple doesn't appear in the image of `f`) -/
protected theorem induction {α : Type u_1} {γ : Type u_2} [measurable_space α] [add_monoid γ]
{P : simple_func α γ → Prop}
(h_ind :
∀ (c : γ) {s : set α} (hs : is_measurable s), P (piecewise s hs (const α c) (const α 0)))
(h_sum :
∀ {f g : simple_func α γ},
set.univ ⊆ ⇑f ⁻¹' singleton 0 ∪ ⇑g ⁻¹' singleton 0 → P f → P g → P (f + g))
(f : simple_func α γ) : P f :=
sorry
end simple_func
/-- The lower Lebesgue integral of a function `f` with respect to a measure `μ`. -/
def lintegral {α : Type u_1} [measurable_space α] (μ : measure α) (f : α → ennreal) : ennreal :=
supr fun (g : simple_func α ennreal) => supr fun (hf : ⇑g ≤ f) => simple_func.lintegral g μ
/-! In the notation for integrals, an expression like `∫⁻ x, g ∥x∥ ∂μ` will not be parsed correctly,
and needs parentheses. We do not set the binding power of `r` to `0`, because then
`∫⁻ x, f x = 0` will be parsed incorrectly. -/
theorem simple_func.lintegral_eq_lintegral {α : Type u_1} [measurable_space α]
(f : simple_func α ennreal) (μ : measure α) :
(lintegral μ fun (a : α) => coe_fn f a) = simple_func.lintegral f μ :=
sorry
theorem lintegral_mono' {α : Type u_1} [measurable_space α] {μ : measure α} {ν : measure α}
(hμν : μ ≤ ν) {f : α → ennreal} {g : α → ennreal} (hfg : f ≤ g) :
(lintegral μ fun (a : α) => f a) ≤ lintegral ν fun (a : α) => g a :=
sorry
theorem lintegral_mono {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{g : α → ennreal} (hfg : f ≤ g) :
(lintegral μ fun (a : α) => f a) ≤ lintegral μ fun (a : α) => g a :=
lintegral_mono' (le_refl μ) hfg
theorem lintegral_mono_nnreal {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → nnreal}
{g : α → nnreal} (h : f ≤ g) :
(lintegral μ fun (a : α) => ↑(f a)) ≤ lintegral μ fun (a : α) => ↑(g a) :=
sorry
theorem monotone_lintegral {α : Type u_1} [measurable_space α] (μ : measure α) :
monotone (lintegral μ) :=
lintegral_mono
@[simp] theorem lintegral_const {α : Type u_1} [measurable_space α] {μ : measure α} (c : ennreal) :
(lintegral μ fun (a : α) => c) = c * coe_fn μ set.univ :=
sorry
@[simp] theorem lintegral_one {α : Type u_1} [measurable_space α] {μ : measure α} :
(lintegral μ fun (a : α) => 1) = coe_fn μ set.univ :=
eq.mpr
(id
(Eq._oldrec (Eq.refl ((lintegral μ fun (a : α) => 1) = coe_fn μ set.univ))
(lintegral_const 1)))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (1 * coe_fn μ set.univ = coe_fn μ set.univ))
(one_mul (coe_fn μ set.univ))))
(Eq.refl (coe_fn μ set.univ)))
theorem set_lintegral_const {α : Type u_1} [measurable_space α] {μ : measure α} (s : set α)
(c : ennreal) : (lintegral (measure.restrict μ s) fun (a : α) => c) = c * coe_fn μ s :=
sorry
theorem set_lintegral_one {α : Type u_1} [measurable_space α] {μ : measure α} (s : set α) :
(lintegral (measure.restrict μ s) fun (a : α) => 1) = coe_fn μ s :=
sorry
/-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions
`φ : α →ₛ ennreal` such that `φ ≤ f`. This lemma says that it suffices to take
functions `φ : α →ₛ ℝ≥0`. -/
theorem lintegral_eq_nnreal {α : Type u_1} [measurable_space α] (f : α → ennreal) (μ : measure α) :
(lintegral μ fun (a : α) => f a) =
supr
fun (φ : simple_func α nnreal) =>
supr
fun (hf : ∀ (x : α), ↑(coe_fn φ x) ≤ f x) =>
simple_func.lintegral (simple_func.map coe φ) μ :=
sorry
theorem exists_simple_func_forall_lintegral_sub_lt_of_pos {α : Type u_1} [measurable_space α]
{μ : measure α} {f : α → ennreal} (h : (lintegral μ fun (x : α) => f x) < ⊤) {ε : ennreal}
(hε : 0 < ε) :
∃ (φ : simple_func α nnreal),
(∀ (x : α), ↑(coe_fn φ x) ≤ f x) ∧
∀ (ψ : simple_func α nnreal),
(∀ (x : α), ↑(coe_fn ψ x) ≤ f x) →
simple_func.lintegral (simple_func.map coe (ψ - φ)) μ < ε :=
sorry
theorem supr_lintegral_le {α : Type u_1} [measurable_space α] {μ : measure α} {ι : Sort u_2}
(f : ι → α → ennreal) :
(supr fun (i : ι) => lintegral μ fun (a : α) => f i a) ≤
lintegral μ fun (a : α) => supr fun (i : ι) => f i a :=
sorry
theorem supr2_lintegral_le {α : Type u_1} [measurable_space α] {μ : measure α} {ι : Sort u_2}
{ι' : ι → Sort u_3} (f : (i : ι) → ι' i → α → ennreal) :
(supr fun (i : ι) => supr fun (h : ι' i) => lintegral μ fun (a : α) => f i h a) ≤
lintegral μ fun (a : α) => supr fun (i : ι) => supr fun (h : ι' i) => f i h a :=
sorry
theorem le_infi_lintegral {α : Type u_1} [measurable_space α] {μ : measure α} {ι : Sort u_2}
(f : ι → α → ennreal) :
(lintegral μ fun (a : α) => infi fun (i : ι) => f i a) ≤
infi fun (i : ι) => lintegral μ fun (a : α) => f i a :=
sorry
theorem le_infi2_lintegral {α : Type u_1} [measurable_space α] {μ : measure α} {ι : Sort u_2}
{ι' : ι → Sort u_3} (f : (i : ι) → ι' i → α → ennreal) :
(lintegral μ fun (a : α) => infi fun (i : ι) => infi fun (h : ι' i) => f i h a) ≤
infi fun (i : ι) => infi fun (h : ι' i) => lintegral μ fun (a : α) => f i h a :=
sorry
theorem lintegral_mono_ae {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{g : α → ennreal} (h : filter.eventually (fun (a : α) => f a ≤ g a) (measure.ae μ)) :
(lintegral μ fun (a : α) => f a) ≤ lintegral μ fun (a : α) => g a :=
sorry
theorem lintegral_congr_ae {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{g : α → ennreal} (h : filter.eventually_eq (measure.ae μ) f g) :
(lintegral μ fun (a : α) => f a) = lintegral μ fun (a : α) => g a :=
le_antisymm (lintegral_mono_ae (filter.eventually_eq.le h))
(lintegral_mono_ae (filter.eventually_eq.le (filter.eventually_eq.symm h)))
theorem lintegral_congr {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{g : α → ennreal} (h : ∀ (a : α), f a = g a) :
(lintegral μ fun (a : α) => f a) = lintegral μ fun (a : α) => g a :=
sorry
theorem set_lintegral_congr {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{s : set α} {t : set α} (h : filter.eventually_eq (measure.ae μ) s t) :
(lintegral (measure.restrict μ s) fun (x : α) => f x) =
lintegral (measure.restrict μ t) fun (x : α) => f x :=
sorry
/-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence.
See `lintegral_supr_directed` for a more general form. -/
theorem lintegral_supr {α : Type u_1} [measurable_space α] {μ : measure α} {f : ℕ → α → ennreal}
(hf : ∀ (n : ℕ), measurable (f n)) (h_mono : monotone f) :
(lintegral μ fun (a : α) => supr fun (n : ℕ) => f n a) =
supr fun (n : ℕ) => lintegral μ fun (a : α) => f n a :=
sorry
/-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence. Version with
ae_measurable functions. -/
theorem lintegral_supr' {α : Type u_1} [measurable_space α] {μ : measure α} {f : ℕ → α → ennreal}
(hf : ∀ (n : ℕ), ae_measurable (f n))
(h_mono : filter.eventually (fun (x : α) => monotone fun (n : ℕ) => f n x) (measure.ae μ)) :
(lintegral μ fun (a : α) => supr fun (n : ℕ) => f n a) =
supr fun (n : ℕ) => lintegral μ fun (a : α) => f n a :=
sorry
theorem lintegral_eq_supr_eapprox_lintegral {α : Type u_1} [measurable_space α] {μ : measure α}
{f : α → ennreal} (hf : measurable f) :
(lintegral μ fun (a : α) => f a) =
supr fun (n : ℕ) => simple_func.lintegral (simple_func.eapprox f n) μ :=
sorry
/-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. This lemma states states this fact in terms of `ε` and `δ`. -/
theorem exists_pos_set_lintegral_lt_of_measure_lt {α : Type u_1} [measurable_space α]
{μ : measure α} {f : α → ennreal} (h : (lintegral μ fun (x : α) => f x) < ⊤) {ε : ennreal}
(hε : 0 < ε) :
∃ (δ : ennreal),
∃ (H : δ > 0),
∀ (s : set α),
coe_fn μ s < δ → (lintegral (measure.restrict μ s) fun (x : α) => f x) < ε :=
sorry
/-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
theorem tendsto_set_lintegral_zero {α : Type u_1} [measurable_space α] {μ : measure α}
{ι : Type u_2} {f : α → ennreal} (h : (lintegral μ fun (x : α) => f x) < ⊤) {l : filter ι}
{s : ι → set α} (hl : filter.tendsto (⇑μ ∘ s) l (nhds 0)) :
filter.tendsto (fun (i : ι) => lintegral (measure.restrict μ (s i)) fun (x : α) => f x) l
(nhds 0) :=
sorry
@[simp] theorem lintegral_add {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{g : α → ennreal} (hf : measurable f) (hg : measurable g) :
(lintegral μ fun (a : α) => f a + g a) =
(lintegral μ fun (a : α) => f a) + lintegral μ fun (a : α) => g a :=
sorry
theorem lintegral_add' {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{g : α → ennreal} (hf : ae_measurable f) (hg : ae_measurable g) :
(lintegral μ fun (a : α) => f a + g a) =
(lintegral μ fun (a : α) => f a) + lintegral μ fun (a : α) => g a :=
sorry
theorem lintegral_zero {α : Type u_1} [measurable_space α] {μ : measure α} :
(lintegral μ fun (a : α) => 0) = 0 :=
sorry
theorem lintegral_zero_fun {α : Type u_1} [measurable_space α] {μ : measure α} :
(lintegral μ fun (a : α) => HasZero.zero a) = 0 :=
sorry
@[simp] theorem lintegral_smul_measure {α : Type u_1} [measurable_space α] {μ : measure α}
(c : ennreal) (f : α → ennreal) :
(lintegral (c • μ) fun (a : α) => f a) = c * lintegral μ fun (a : α) => f a :=
sorry
@[simp] theorem lintegral_sum_measure {α : Type u_1} [measurable_space α] {ι : Type u_2}
(f : α → ennreal) (μ : ι → measure α) :
(lintegral (measure.sum μ) fun (a : α) => f a) =
tsum fun (i : ι) => lintegral (μ i) fun (a : α) => f a :=
sorry
@[simp] theorem lintegral_add_measure {α : Type u_1} [measurable_space α] (f : α → ennreal)
(μ : measure α) (ν : measure α) :
(lintegral (μ + ν) fun (a : α) => f a) =
(lintegral μ fun (a : α) => f a) + lintegral ν fun (a : α) => f a :=
sorry
@[simp] theorem lintegral_zero_measure {α : Type u_1} [measurable_space α] (f : α → ennreal) :
(lintegral 0 fun (a : α) => f a) = 0 :=
sorry
theorem lintegral_finset_sum {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
(s : finset β) {f : β → α → ennreal} (hf : ∀ (b : β), measurable (f b)) :
(lintegral μ fun (a : α) => finset.sum s fun (b : β) => f b a) =
finset.sum s fun (b : β) => lintegral μ fun (a : α) => f b a :=
sorry
@[simp] theorem lintegral_const_mul {α : Type u_1} [measurable_space α] {μ : measure α}
(r : ennreal) {f : α → ennreal} (hf : measurable f) :
(lintegral μ fun (a : α) => r * f a) = r * lintegral μ fun (a : α) => f a :=
sorry
theorem lintegral_const_mul'' {α : Type u_1} [measurable_space α] {μ : measure α} (r : ennreal)
{f : α → ennreal} (hf : ae_measurable f) :
(lintegral μ fun (a : α) => r * f a) = r * lintegral μ fun (a : α) => f a :=
sorry
theorem lintegral_const_mul_le {α : Type u_1} [measurable_space α] {μ : measure α} (r : ennreal)
(f : α → ennreal) : (r * lintegral μ fun (a : α) => f a) ≤ lintegral μ fun (a : α) => r * f a :=
sorry
theorem lintegral_const_mul' {α : Type u_1} [measurable_space α] {μ : measure α} (r : ennreal)
(f : α → ennreal) (hr : r ≠ ⊤) :
(lintegral μ fun (a : α) => r * f a) = r * lintegral μ fun (a : α) => f a :=
sorry
theorem lintegral_mul_const {α : Type u_1} [measurable_space α] {μ : measure α} (r : ennreal)
{f : α → ennreal} (hf : measurable f) :
(lintegral μ fun (a : α) => f a * r) = (lintegral μ fun (a : α) => f a) * r :=
sorry
theorem lintegral_mul_const'' {α : Type u_1} [measurable_space α] {μ : measure α} (r : ennreal)
{f : α → ennreal} (hf : ae_measurable f) :
(lintegral μ fun (a : α) => f a * r) = (lintegral μ fun (a : α) => f a) * r :=
sorry
theorem lintegral_mul_const_le {α : Type u_1} [measurable_space α] {μ : measure α} (r : ennreal)
(f : α → ennreal) : (lintegral μ fun (a : α) => f a) * r ≤ lintegral μ fun (a : α) => f a * r :=
sorry
theorem lintegral_mul_const' {α : Type u_1} [measurable_space α] {μ : measure α} (r : ennreal)
(f : α → ennreal) (hr : r ≠ ⊤) :
(lintegral μ fun (a : α) => f a * r) = (lintegral μ fun (a : α) => f a) * r :=
sorry
/- A double integral of a product where each factor contains only one variable
is a product of integrals -/
theorem lintegral_lintegral_mul {α : Type u_1} [measurable_space α] {μ : measure α} {β : Type u_2}
[measurable_space β] {ν : measure β} {f : α → ennreal} {g : β → ennreal} (hf : measurable f)
(hg : measurable g) :
(lintegral μ fun (x : α) => lintegral ν fun (y : β) => f x * g y) =
(lintegral μ fun (x : α) => f x) * lintegral ν fun (y : β) => g y :=
sorry
-- TODO: Need a better way of rewriting inside of a integral
theorem lintegral_rw₁ {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α} {f : α → β}
{f' : α → β} (h : filter.eventually_eq (measure.ae μ) f f') (g : β → ennreal) :
(lintegral μ fun (a : α) => g (f a)) = lintegral μ fun (a : α) => g (f' a) :=
lintegral_congr_ae
(filter.eventually.mono h
fun (a : α) (h : f a = f' a) =>
eq.mpr (id (Eq._oldrec (Eq.refl (g (f a) = g (f' a))) h)) (Eq.refl (g (f' a))))
-- TODO: Need a better way of rewriting inside of a integral
theorem lintegral_rw₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} [measurable_space α]
{μ : measure α} {f₁ : α → β} {f₁' : α → β} {f₂ : α → γ} {f₂' : α → γ}
(h₁ : filter.eventually_eq (measure.ae μ) f₁ f₁')
(h₂ : filter.eventually_eq (measure.ae μ) f₂ f₂') (g : β → γ → ennreal) :
(lintegral μ fun (a : α) => g (f₁ a) (f₂ a)) = lintegral μ fun (a : α) => g (f₁' a) (f₂' a) :=
sorry
@[simp] theorem lintegral_indicator {α : Type u_1} [measurable_space α] {μ : measure α}
(f : α → ennreal) {s : set α} (hs : is_measurable s) :
(lintegral μ fun (a : α) => set.indicator s f a) =
lintegral (measure.restrict μ s) fun (a : α) => f a :=
sorry
/-- Chebyshev's inequality -/
theorem mul_meas_ge_le_lintegral {α : Type u_1} [measurable_space α] {μ : measure α}
{f : α → ennreal} (hf : measurable f) (ε : ennreal) :
ε * coe_fn μ (set_of fun (x : α) => ε ≤ f x) ≤ lintegral μ fun (a : α) => f a :=
sorry
theorem meas_ge_le_lintegral_div {α : Type u_1} [measurable_space α] {μ : measure α}
{f : α → ennreal} (hf : measurable f) {ε : ennreal} (hε : ε ≠ 0) (hε' : ε ≠ ⊤) :
coe_fn μ (set_of fun (x : α) => ε ≤ f x) ≤ (lintegral μ fun (a : α) => f a) / ε :=
sorry
@[simp] theorem lintegral_eq_zero_iff {α : Type u_1} [measurable_space α] {μ : measure α}
{f : α → ennreal} (hf : measurable f) :
(lintegral μ fun (a : α) => f a) = 0 ↔ filter.eventually_eq (measure.ae μ) f 0 :=
sorry
@[simp] theorem lintegral_eq_zero_iff' {α : Type u_1} [measurable_space α] {μ : measure α}
{f : α → ennreal} (hf : ae_measurable f) :
(lintegral μ fun (a : α) => f a) = 0 ↔ filter.eventually_eq (measure.ae μ) f 0 :=
sorry
theorem lintegral_pos_iff_support {α : Type u_1} [measurable_space α] {μ : measure α}
{f : α → ennreal} (hf : measurable f) :
(0 < lintegral μ fun (a : α) => f a) ↔ 0 < coe_fn μ (function.support f) :=
sorry
/-- Weaker version of the monotone convergence theorem-/
theorem lintegral_supr_ae {α : Type u_1} [measurable_space α] {μ : measure α} {f : ℕ → α → ennreal}
(hf : ∀ (n : ℕ), measurable (f n))
(h_mono :
∀ (n : ℕ), filter.eventually (fun (a : α) => f n a ≤ f (Nat.succ n) a) (measure.ae μ)) :
(lintegral μ fun (a : α) => supr fun (n : ℕ) => f n a) =
supr fun (n : ℕ) => lintegral μ fun (a : α) => f n a :=
sorry
theorem lintegral_sub {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
{g : α → ennreal} (hf : measurable f) (hg : measurable g)
(hg_fin : (lintegral μ fun (a : α) => g a) < ⊤)
(h_le : filter.eventually_le (measure.ae μ) g f) :
(lintegral μ fun (a : α) => f a - g a) =
(lintegral μ fun (a : α) => f a) - lintegral μ fun (a : α) => g a :=
sorry
/-- Monotone convergence theorem for nonincreasing sequences of functions -/
theorem lintegral_infi_ae {α : Type u_1} [measurable_space α] {μ : measure α} {f : ℕ → α → ennreal}
(h_meas : ∀ (n : ℕ), measurable (f n))
(h_mono : ∀ (n : ℕ), filter.eventually_le (measure.ae μ) (f (Nat.succ n)) (f n))
(h_fin : (lintegral μ fun (a : α) => f 0 a) < ⊤) :
(lintegral μ fun (a : α) => infi fun (n : ℕ) => f n a) =
infi fun (n : ℕ) => lintegral μ fun (a : α) => f n a :=
sorry
/-- Monotone convergence theorem for nonincreasing sequences of functions -/
theorem lintegral_infi {α : Type u_1} [measurable_space α] {μ : measure α} {f : ℕ → α → ennreal}
(h_meas : ∀ (n : ℕ), measurable (f n)) (h_mono : ∀ {m n : ℕ}, m ≤ n → f n ≤ f m)
(h_fin : (lintegral μ fun (a : α) => f 0 a) < ⊤) :
(lintegral μ fun (a : α) => infi fun (n : ℕ) => f n a) =
infi fun (n : ℕ) => lintegral μ fun (a : α) => f n a :=
lintegral_infi_ae h_meas (fun (n : ℕ) => ae_of_all μ (h_mono (le_of_lt (nat.lt_succ_self n))))
h_fin
/-- Known as Fatou's lemma, version with `ae_measurable` functions -/
theorem lintegral_liminf_le' {α : Type u_1} [measurable_space α] {μ : measure α}
{f : ℕ → α → ennreal} (h_meas : ∀ (n : ℕ), ae_measurable (f n)) :
(lintegral μ fun (a : α) => filter.liminf filter.at_top fun (n : ℕ) => f n a) ≤
filter.liminf filter.at_top fun (n : ℕ) => lintegral μ fun (a : α) => f n a :=
sorry
/-- Known as Fatou's lemma -/
theorem lintegral_liminf_le {α : Type u_1} [measurable_space α] {μ : measure α}
{f : ℕ → α → ennreal} (h_meas : ∀ (n : ℕ), measurable (f n)) :
(lintegral μ fun (a : α) => filter.liminf filter.at_top fun (n : ℕ) => f n a) ≤
filter.liminf filter.at_top fun (n : ℕ) => lintegral μ fun (a : α) => f n a :=
lintegral_liminf_le' fun (n : ℕ) => measurable.ae_measurable (h_meas n)
theorem limsup_lintegral_le {α : Type u_1} [measurable_space α] {μ : measure α}
{f : ℕ → α → ennreal} {g : α → ennreal} (hf_meas : ∀ (n : ℕ), measurable (f n))
(h_bound : ∀ (n : ℕ), filter.eventually_le (measure.ae μ) (f n) g)
(h_fin : (lintegral μ fun (a : α) => g a) < ⊤) :
(filter.limsup filter.at_top fun (n : ℕ) => lintegral μ fun (a : α) => f n a) ≤
lintegral μ fun (a : α) => filter.limsup filter.at_top fun (n : ℕ) => f n a :=
sorry
/-- Dominated convergence theorem for nonnegative functions -/
theorem tendsto_lintegral_of_dominated_convergence {α : Type u_1} [measurable_space α]
{μ : measure α} {F : ℕ → α → ennreal} {f : α → ennreal} (bound : α → ennreal)
(hF_meas : ∀ (n : ℕ), measurable (F n))
(h_bound : ∀ (n : ℕ), filter.eventually_le (measure.ae μ) (F n) bound)
(h_fin : (lintegral μ fun (a : α) => bound a) < ⊤)
(h_lim :
filter.eventually
(fun (a : α) => filter.tendsto (fun (n : ℕ) => F n a) filter.at_top (nhds (f a)))
(measure.ae μ)) :
filter.tendsto (fun (n : ℕ) => lintegral μ fun (a : α) => F n a) filter.at_top
(nhds (lintegral μ fun (a : α) => f a)) :=
sorry
/-- Dominated convergence theorem for nonnegative functions which are just almost everywhere
measurable. -/
theorem tendsto_lintegral_of_dominated_convergence' {α : Type u_1} [measurable_space α]
{μ : measure α} {F : ℕ → α → ennreal} {f : α → ennreal} (bound : α → ennreal)
(hF_meas : ∀ (n : ℕ), ae_measurable (F n))
(h_bound : ∀ (n : ℕ), filter.eventually_le (measure.ae μ) (F n) bound)
(h_fin : (lintegral μ fun (a : α) => bound a) < ⊤)
(h_lim :
filter.eventually
(fun (a : α) => filter.tendsto (fun (n : ℕ) => F n a) filter.at_top (nhds (f a)))
(measure.ae μ)) :
filter.tendsto (fun (n : ℕ) => lintegral μ fun (a : α) => F n a) filter.at_top
(nhds (lintegral μ fun (a : α) => f a)) :=
sorry
/-- Dominated convergence theorem for filters with a countable basis -/
theorem tendsto_lintegral_filter_of_dominated_convergence {α : Type u_1} [measurable_space α]
{μ : measure α} {ι : Type u_2} {l : filter ι} {F : ι → α → ennreal} {f : α → ennreal}
(bound : α → ennreal) (hl_cb : filter.is_countably_generated l)
(hF_meas : filter.eventually (fun (n : ι) => measurable (F n)) l)
(h_bound :
filter.eventually
(fun (n : ι) => filter.eventually (fun (a : α) => F n a ≤ bound a) (measure.ae μ)) l)
(h_fin : (lintegral μ fun (a : α) => bound a) < ⊤)
(h_lim :
filter.eventually (fun (a : α) => filter.tendsto (fun (n : ι) => F n a) l (nhds (f a)))
(measure.ae μ)) :
filter.tendsto (fun (n : ι) => lintegral μ fun (a : α) => F n a) l
(nhds (lintegral μ fun (a : α) => f a)) :=
sorry
/-- Monotone convergence for a suprema over a directed family and indexed by an encodable type -/
theorem lintegral_supr_directed {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[encodable β] {f : β → α → ennreal} (hf : ∀ (b : β), measurable (f b))
(h_directed : directed LessEq f) :
(lintegral μ fun (a : α) => supr fun (b : β) => f b a) =
supr fun (b : β) => lintegral μ fun (a : α) => f b a :=
sorry
theorem lintegral_tsum {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[encodable β] {f : β → α → ennreal} (hf : ∀ (i : β), measurable (f i)) :
(lintegral μ fun (a : α) => tsum fun (i : β) => f i a) =
tsum fun (i : β) => lintegral μ fun (a : α) => f i a :=
sorry
theorem lintegral_Union {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[encodable β] {s : β → set α} (hm : ∀ (i : β), is_measurable (s i))
(hd : pairwise (disjoint on s)) (f : α → ennreal) :
(lintegral (measure.restrict μ (set.Union fun (i : β) => s i)) fun (a : α) => f a) =
tsum fun (i : β) => lintegral (measure.restrict μ (s i)) fun (a : α) => f a :=
sorry
theorem lintegral_Union_le {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[encodable β] (s : β → set α) (f : α → ennreal) :
(lintegral (measure.restrict μ (set.Union fun (i : β) => s i)) fun (a : α) => f a) ≤
tsum fun (i : β) => lintegral (measure.restrict μ (s i)) fun (a : α) => f a :=
sorry
theorem lintegral_map {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[measurable_space β] {f : β → ennreal} {g : α → β} (hf : measurable f) (hg : measurable g) :
(lintegral (coe_fn (measure.map g) μ) fun (a : β) => f a) =
lintegral μ fun (a : α) => f (g a) :=
sorry
theorem lintegral_map' {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[measurable_space β] {f : β → ennreal} {g : α → β} (hf : ae_measurable f) (hg : measurable g) :
(lintegral (coe_fn (measure.map g) μ) fun (a : β) => f a) =
lintegral μ fun (a : α) => f (g a) :=
Eq.trans
(Eq.trans (lintegral_congr_ae (ae_measurable.ae_eq_mk hf))
(lintegral_map (ae_measurable.measurable_mk hf) hg))
(lintegral_congr_ae (ae_eq_comp hg (filter.eventually_eq.symm (ae_measurable.ae_eq_mk hf))))
theorem lintegral_comp {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[measurable_space β] {f : β → ennreal} {g : α → β} (hf : measurable f) (hg : measurable g) :
lintegral μ (f ∘ g) = lintegral (coe_fn (measure.map g) μ) fun (a : β) => f a :=
Eq.symm (lintegral_map hf hg)
theorem set_lintegral_map {α : Type u_1} {β : Type u_2} [measurable_space α] {μ : measure α}
[measurable_space β] {f : β → ennreal} {g : α → β} {s : set β} (hs : is_measurable s)
(hf : measurable f) (hg : measurable g) :
(lintegral (measure.restrict (coe_fn (measure.map g) μ) s) fun (y : β) => f y) =
lintegral (measure.restrict μ (g ⁻¹' s)) fun (x : α) => f (g x) :=
sorry
theorem lintegral_dirac' {α : Type u_1} [measurable_space α] (a : α) {f : α → ennreal}
(hf : measurable f) : (lintegral (measure.dirac a) fun (a : α) => f a) = f a :=
sorry
theorem lintegral_dirac {α : Type u_1} [measurable_space α] [measurable_singleton_class α] (a : α)
(f : α → ennreal) : (lintegral (measure.dirac a) fun (a : α) => f a) = f a :=
sorry
theorem lintegral_count' {α : Type u_1} [measurable_space α] {f : α → ennreal} (hf : measurable f) :
(lintegral measure.count fun (a : α) => f a) = tsum fun (a : α) => f a :=
sorry
theorem lintegral_count {α : Type u_1} [measurable_space α] [measurable_singleton_class α]
(f : α → ennreal) : (lintegral measure.count fun (a : α) => f a) = tsum fun (a : α) => f a :=
sorry
theorem ae_lt_top {α : Type u_1} [measurable_space α] {μ : measure α} {f : α → ennreal}
(hf : measurable f) (h2f : (lintegral μ fun (x : α) => f x) < ⊤) :
filter.eventually (fun (x : α) => f x < ⊤) (measure.ae μ) :=
sorry
/-- Given a measure `μ : measure α` and a function `f : α → ennreal`, `μ.with_density f` is the
measure such that for a measurable set `s` we have `μ.with_density f s = ∫⁻ a in s, f a ∂μ`. -/
def measure.with_density {α : Type u_1} [measurable_space α] (μ : measure α) (f : α → ennreal) :
measure α :=
measure.of_measurable
(fun (s : set α) (hs : is_measurable s) => lintegral (measure.restrict μ s) fun (a : α) => f a)
sorry sorry
@[simp] theorem with_density_apply {α : Type u_1} [measurable_space α] {μ : measure α}
(f : α → ennreal) {s : set α} (hs : is_measurable s) :
coe_fn (measure.with_density μ f) s = lintegral (measure.restrict μ s) fun (a : α) => f a :=
measure.of_measurable_apply s hs
end measure_theory
/-- To prove something for an arbitrary measurable function into `ennreal`, it suffices to show
that the property holds for (multiples of) characteristic functions and is closed under addition
and supremum of increasing sequences of functions.
It is possible to make the hypotheses in the induction steps a bit stronger, and such conditions
can be added once we need them (for example in `h_sum` it is only necessary to consider the sum of
a simple function with a multiple of a characteristic function and that the intersection
of their images is a subset of `{0}`. -/
theorem measurable.ennreal_induction {α : Type u_1} [measurable_space α] {P : (α → ennreal) → Prop}
(h_ind : ∀ (c : ennreal) {s : set α}, is_measurable s → P (set.indicator s fun (_x : α) => c))
(h_sum :
∀ {f g : α → ennreal},
set.univ ⊆ f ⁻¹' singleton 0 ∪ g ⁻¹' singleton 0 →
measurable f → measurable g → P f → P g → P (f + g))
(h_supr :
∀ {f : ℕ → α → ennreal},
(∀ (n : ℕ), measurable (f n)) →
monotone f → (∀ (n : ℕ), P (f n)) → P fun (x : α) => supr fun (n : ℕ) => f n x)
{f : α → ennreal} (hf : measurable f) : P f :=
sorry
namespace measure_theory
/-- This is Exercise 1.2.1 from [tao2010]. It allows you to express integration of a measurable
function with respect to `(μ.with_density f)` as an integral with respect to `μ`, called the base
measure. `μ` is often the Lebesgue measure, and in this circumstance `f` is the probability density
function, and `(μ.with_density f)` represents any continuous random variable as a
probability measure, such as the uniform distribution between 0 and 1, the Gaussian distribution,
the exponential distribution, the Beta distribution, or the Cauchy distribution (see Section 2.4
of [wasserman2004]). Thus, this method shows how to one can calculate expectations, variances,
and other moments as a function of the probability density function.
-/
theorem lintegral_with_density_eq_lintegral_mul {α : Type u_1} [measurable_space α] (μ : measure α)
{f : α → ennreal} (h_mf : measurable f) {g : α → ennreal} :
measurable g →
(lintegral (measure.with_density μ f) fun (a : α) => g a) =
lintegral μ fun (a : α) => Mul.mul f g a :=
sorry
end Mathlib |
e86ced63f2b05cf0f6f0f0dbff8eec92f17c44d6 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/analysis/convex/slope.lean | abe5e37c12a7aa10f381cc88a28b19db023175e6 | [
"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 | 10,423 | lean | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo Jaffré
-/
import analysis.convex.function
import tactic.field_simp
/-!
# Slopes of convex functions
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variables {𝕜 : Type*} [linear_ordered_field 𝕜] {s : set 𝕜} {f : 𝕜 → 𝕜}
/-- If `f : 𝕜 → 𝕜` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
lemma convex_on.slope_mono_adjacent (hf : convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) ≤ (f z - f y) / (z - y) :=
begin
have hxz := hxy.trans hyz,
rw ←sub_pos at hxy hxz hyz,
suffices : f y / (y - x) + f y / (z - y) ≤ f x / (y - x) + f z / (z - y),
{ ring_nf at this ⊢, linarith },
set a := (z - y) / (z - x),
set b := (y - x) / (z - x),
have hy : a • x + b • z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },
have key, from
hf.2 hx hz
(show 0 ≤ a, by apply div_nonneg; linarith)
(show 0 ≤ b, by apply div_nonneg; linarith)
(show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith] }),
rw hy at key,
replace key := mul_le_mul_of_nonneg_left key hxz.le,
field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key ⊢,
rw div_le_div_right,
{ linarith },
{ nlinarith }
end
/-- If `f : 𝕜 → 𝕜` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
lemma concave_on.slope_anti_adjacent (hf : concave_on 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s)
(hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f z - f y) / (z - y) ≤ (f y - f x) / (y - x) :=
begin
rw [←neg_le_neg_iff, ←neg_sub_neg (f x), ←neg_sub_neg (f y)],
simp_rw [←pi.neg_apply, ←neg_div, neg_sub],
exact convex_on.slope_mono_adjacent hf.neg hx hz hxy hyz,
end
/-- If `f : 𝕜 → 𝕜` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_convex_on.slope_strict_mono_adjacent (hf : strict_convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) :=
begin
have hxz := hxy.trans hyz,
have hxz' := hxz.ne,
rw ←sub_pos at hxy hxz hyz,
suffices : f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y),
{ ring_nf at this ⊢, linarith },
set a := (z - y) / (z - x),
set b := (y - x) / (z - x),
have hy : a • x + b • z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },
have key, from
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith] }),
rw hy at key,
replace key := mul_lt_mul_of_pos_left key hxz,
field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key ⊢,
rw div_lt_div_right,
{ linarith },
{ nlinarith }
end
/-- If `f : 𝕜 → 𝕜` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_concave_on.slope_anti_adjacent (hf : strict_concave_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f z - f y) / (z - y) < (f y - f x) / (y - x) :=
begin
rw [←neg_lt_neg_iff, ←neg_sub_neg (f x), ←neg_sub_neg (f y)],
simp_rw [←pi.neg_apply, ←neg_div, neg_sub],
exact strict_convex_on.slope_strict_mono_adjacent hf.neg hx hz hxy hyz,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
lemma convex_on_of_slope_mono_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) ≤ (f z - f y) / (z - y)) :
convex_on 𝕜 s f :=
linear_order.convex_on_of_lt hs $ λ x hx z hz hxz a b ha hb hab,
begin
let y := a * x + b * z,
have hxy : x < y,
{ rw [← one_mul x, ← hab, add_mul],
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },
have hyz : y < z,
{ rw [← one_mul z, ← hab, add_mul],
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },
have : (f y - f x) * (z - y) ≤ (f z - f y) * (y - x),
from (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),
have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),
have ha : (z - y) / (z - x) = a,
{ rw [eq_comm, ← sub_eq_iff_eq_add'] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
have hb : (y - x) / (z - x) = b,
{ rw [eq_comm, ← sub_eq_iff_eq_add] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add,
sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
lemma concave_on_of_slope_anti_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) ≤ (f y - f x) / (y - x)) : concave_on 𝕜 s f :=
begin
rw ←neg_convex_on_iff,
refine convex_on_of_slope_mono_adjacent hs (λ x y z hx hz hxy hyz, _),
rw ←neg_le_neg_iff,
simp_rw [←neg_div, neg_sub, pi.neg_apply, neg_sub_neg],
exact hf hx hz hxy hyz,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
lemma strict_convex_on_of_slope_strict_mono_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) < (f z - f y) / (z - y)) :
strict_convex_on 𝕜 s f :=
linear_order.strict_convex_on_of_lt hs $ λ x hx z hz hxz a b ha hb hab,
begin
let y := a * x + b * z,
have hxy : x < y,
{ rw [← one_mul x, ← hab, add_mul],
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },
have hyz : y < z,
{ rw [← one_mul z, ← hab, add_mul],
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },
have : (f y - f x) * (z - y) < (f z - f y) * (y - x),
from (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),
have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),
have ha : (z - y) / (z - x) = a,
{ rw [eq_comm, ← sub_eq_iff_eq_add'] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
have hb : (y - x) / (z - x) = b,
{ rw [eq_comm, ← sub_eq_iff_eq_add] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add,
sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
lemma strict_concave_on_of_slope_strict_anti_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) < (f y - f x) / (y - x)) : strict_concave_on 𝕜 s f :=
begin
rw ←neg_strict_convex_on_iff,
refine strict_convex_on_of_slope_strict_mono_adjacent hs (λ x y z hx hz hxy hyz, _),
rw ←neg_lt_neg_iff,
simp_rw [←neg_div, neg_sub, pi.neg_apply, neg_sub_neg],
exact hf hx hz hxy hyz,
end
/-- A function `f : 𝕜 → 𝕜` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
lemma convex_on_iff_slope_mono_adjacent :
convex_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) ≤ (f z - f y) / (z - y) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_mono_adjacent⟩, λ h, convex_on_of_slope_mono_adjacent h.1 h.2⟩
/-- A function `f : 𝕜 → 𝕜` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
lemma concave_on_iff_slope_anti_adjacent :
concave_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) ≤ (f y - f x) / (y - x) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_anti_adjacent⟩, λ h, concave_on_of_slope_anti_adjacent h.1 h.2⟩
/-- A function `f : 𝕜 → 𝕜` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_convex_on_iff_slope_strict_mono_adjacent :
strict_convex_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) < (f z - f y) / (z - y) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_strict_mono_adjacent⟩,
λ h, strict_convex_on_of_slope_strict_mono_adjacent h.1 h.2⟩
/-- A function `f : 𝕜 → 𝕜` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_concave_on_iff_slope_strict_anti_adjacent :
strict_concave_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) < (f y - f x) / (y - x) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_anti_adjacent⟩,
λ h, strict_concave_on_of_slope_strict_anti_adjacent h.1 h.2⟩
|
f5420ed373ab784fb4606e50cc55d1a684199e07 | f3a5af2927397cf346ec0e24312bfff077f00425 | /src/game/world8/level13.lean | 1970ee6d9fd3ee3e88b1f8568316c998f87d7ea9 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/natural_number_game | 05c39e1586408cfb563d1a12e1085a90726ab655 | f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd | refs/heads/master | 1,688,570,964,990 | 1,636,908,242,000 | 1,636,908,242,000 | 195,403,790 | 277 | 84 | Apache-2.0 | 1,694,547,955,000 | 1,562,328,792,000 | Lean | UTF-8 | Lean | false | false | 688 | lean | import game.world8.level12 -- hide
namespace mynat -- hide
/-
# Advanced Addition World
## Level 13: `ne_succ_self`
The last level in Advanced Addition World is the statement
that $n\not=\operatorname{succ}(n)$. When you've done this
you've completed Advanced Addition World and can move on
to Advanced Multiplication World (after first doing
Multiplication World, if you didn't do it already).
-/
/- Lemma
For any natural number $n$, we have
$$ n \neq \operatorname{succ}(n). $$
-/
lemma ne_succ_self (n : mynat) : n ≠ succ n :=
begin [nat_num_game]
induction n with d hd,
apply zero_ne_succ,
intro hs,
apply hd,
apply succ_inj,
assumption
end
end mynat -- hide
|
8674085142adeeb757cdfd94801179ae8d10a323 | 3618c6e11aa822fd542440674dfb9a7b9921dba0 | /src/no_letters.lean | 02f464641a42cea398b03f8c807274a08c9c9f60 | [] | no_license | ChrisHughes24/single_relation | 99ceedcc02d236ce46d6c65d72caa669857533c5 | 057e157a59de6d0e43b50fcb537d66792ec20450 | refs/heads/master | 1,683,652,062,698 | 1,683,360,089,000 | 1,683,360,089,000 | 279,346,432 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,736 | lean | import P
import initial
/-!
# No letters
This file handles the case that all letters in `r` are in `T`
## Implementation Notes
Every function in this file uses an ad-hoc implementation of the
binary coproduct of `P (free_group T)` and `free_group Tᶜ`. It is implemented as
a `list (P (free_group ι) × free_group ι)`.
The representation is in reverse, i.e. the list `[(p, a), (q, b)]` represents
the word `b * q * a * p` in the coproduct. The word returned will be reduced in the
sense that the only occurence of `1` will be either `prod.fst` of the first
element of the list, or `prod.snd` of the final element.
-/
variables {ι : Type} [decidable_eq ι] (T : set ι) [decidable_pred T]
(r : free_group ι) (hs : solver r ∅)
open semidirect_product free_group
/-- `no_letters_reduce_mul (p, w) l`, returns `p * w * l` if `l`is thought
of as an element of the binary coproduct of `P (free_group ι)` and `free_group ι`. -/
def no_letters_reduce_mul : P (free_group ι) × free_group ι →
list (P (free_group ι) × free_group ι) →
list (P (free_group ι) × free_group ι)
| p [] := [p]
| (p, w₁) ((q, w₂)::l) :=
if w₁ = 1
then (q * p, w₂) :: l
else (p, w₁) :: (q, w₂) :: l
/-- Auxiliary definition used to define `no_letters`. `no_letters_core r T l₁ l₂` effectively
returns a normalization `l₁ * l₂` when `l₁` is regarded as an element of `free_group ι`
and `l₂` as the coproduct of `P (free_group T)` and `free_group Tᶜ`. Normalized means that
every letter in `P (free_group T)` that is equal to `1` in the quotient by `r` is rewritten
to be `1`, and that if the `right` of any element of `P (free_group T)` is `1`, then this is
the first element in the list. -/
meta def no_letters_core : Π (l : list (Σ i : ι, C∞))
(l₂ : list (P (free_group ι) × free_group ι)),
list (P (free_group ι) × free_group ι)
| [] l₂ := l₂
| (i::l) [] :=
if i.1 ∈ T
then no_letters_core l [(inr (of_list [i]), 1)]
else no_letters_core l [(1, of_list [i])]
| (i::l₁) ((p, w) :: l₂) :=
if i.1 ∈ T
then no_letters_core l₁ ((p * inr (of_list [i]), w) :: l₂)
else match hs p.right with
| none := no_letters_core l₁ ((1, of_list [i]) :: (p, w) :: l₂)
| (some q) := no_letters_core l₁
(no_letters_reduce_mul
(⟨mul_free (of_list [⟨i.1, i.2⁻¹⟩]) (p.1 * q.1), 1⟩, w * of_list [i]) l₂)
end
/-- `no_letters` solves the word problem when every letter in `r` is in `T`. -/
meta def no_letters : solver r T :=
λ w, let p : P (free_group ι) :=
(no_letters_core T r hs w.to_list []).foldl
(λ x y, inr y.2 * y.1 * x) 1 in
guard (mem_closure_var T p.right) >> return p
|
1c314640fb48720f1813c2f70aef4f2c8d64e22e | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/tactic/omega/find_scalars.lean | bd4cfc962396a28d6a62425b6d08471575e2017c | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 1,890 | lean | /-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
A tactic which performs Fourier–Motzkin elimination to find
a contradictory linear combination of input constraints.
-/
import tactic.omega.term data.list.min_max
open list.func
namespace omega
meta def trisect (m : nat) :
list (list nat × term) → (list (list nat × term) ×
list (list nat × term) × list (list nat × term))
| [] := ([],[],[])
| ((p,t)::pts) :=
let (neg,zero,pos) := trisect pts in
if get m t.snd < 0
then ((p,t)::neg,zero,pos)
else if get m t.snd = 0
then (neg,(p,t)::zero,pos)
else (neg,zero,(p,t)::pos)
meta def elim_var_aux (m : nat) :
((list nat × term) × (list nat × term)) → tactic (list nat × term)
| ((p1,t1), (p2,t2)) :=
let n := int.nat_abs (get m t1.snd) in
let o := int.nat_abs (get m t2.snd) in
let lcm := (nat.lcm n o) in
let n' := lcm / n in
let o' := lcm / o in
return (add (p1.map ((*) n')) (p2.map ((*) o')),
term.add (t1.mul n') (t2.mul o'))
meta def elim_var (m : nat) (neg pos : list (list nat × term)) :
tactic (list (list nat × term)) :=
let pairs := list.product neg pos in
monad.mapm (elim_var_aux m) pairs
meta def find_neg_const : list (list nat × term) → tactic (list nat)
| [] := tactic.failed
| ((π,⟨c,_⟩)::l) := if c < 0 then return π else find_neg_const l
meta def find_scalars_core : nat → list (list nat × term) → tactic (list nat)
| 0 pts := find_neg_const pts
| (m+1) pts :=
let (neg,zero,pos) := trisect m pts in
do new ← elim_var m neg pos,
find_scalars_core m (new ++ zero)
meta def find_scalars (ts : list term) : tactic (list nat) :=
find_scalars_core
(ts.map (λ t : term, t.snd.length)).maximum.iget
(ts.map_with_index (λ m t, (list.func.set 1 [] m, t)))
end omega
|
e478fdfd25642379d6bf6c6782bbe308dc1d43cb | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/locally_convex/with_seminorms.lean | a578827117d1d36f00ab916a7989c3b5f86f5a69 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 30,886 | lean | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll, Anatole Dedecker
-/
import analysis.seminorm
import analysis.locally_convex.bounded
import topology.algebra.filter_basis
import topology.algebra.module.locally_convex
/-!
# Topology induced by a family of seminorms
## Main definitions
* `seminorm_family.basis_sets`: The set of open seminorm balls for a family of seminorms.
* `seminorm_family.module_filter_basis`: A module filter basis formed by the open balls.
* `seminorm.is_bounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be
bounded by a finite number of seminorms in `E`.
## Main statements
* `with_seminorms.to_locally_convex_space`: A space equipped with a family of seminorms is locally
convex.
* `with_seminorms.first_countable`: A space is first countable if it's topology is induced by a
countable family of seminorms.
## Continuity of semilinear maps
If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then
we have a direct method to prove that a linear map is continuous:
* `seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous.
If the topology of a space `E` is induced by a family of seminorms, then we can characterize von
Neumann boundedness in terms of that seminorm family. Together with
`linear_map.continuous_of_locally_bounded` this gives general criterion for continuity.
* `with_seminorms.is_vonN_bounded_iff_finset_seminorm_bounded`
* `with_seminorms.is_vonN_bounded_iff_seminorm_bounded`
* `with_seminorms.image_is_vonN_bounded_iff_finset_seminorm_bounded`
* `with_seminorms.image_is_vonN_bounded_iff_seminorm_bounded`
## Tags
seminorm, locally convex
-/
open normed_field set seminorm topological_space
open_locale big_operators nnreal pointwise topology
variables {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*}
section filter_basis
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E]
variables (𝕜 E ι)
/-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/
abbreviation seminorm_family := ι → seminorm 𝕜 E
variables {𝕜 E ι}
namespace seminorm_family
/-- The sets of a filter basis for the neighborhood filter of 0. -/
def basis_sets (p : seminorm_family 𝕜 E ι) : set (set E) :=
⋃ (s : finset ι) r (hr : 0 < r), singleton $ ball (s.sup p) (0 : E) r
variables (p : seminorm_family 𝕜 E ι)
lemma basis_sets_iff {U : set E} :
U ∈ p.basis_sets ↔ ∃ (i : finset ι) r (hr : 0 < r), U = ball (i.sup p) 0 r :=
by simp only [basis_sets, mem_Union, mem_singleton_iff]
lemma basis_sets_mem (i : finset ι) {r : ℝ} (hr : 0 < r) :
(i.sup p).ball 0 r ∈ p.basis_sets :=
(basis_sets_iff _).mpr ⟨i,_,hr,rfl⟩
lemma basis_sets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) :
(p i).ball 0 r ∈ p.basis_sets :=
(basis_sets_iff _).mpr ⟨{i},_,hr, by rw finset.sup_singleton⟩
lemma basis_sets_nonempty [nonempty ι] : p.basis_sets.nonempty :=
begin
let i := classical.arbitrary ι,
refine set.nonempty_def.mpr ⟨(p i).ball 0 1, _⟩,
exact p.basis_sets_singleton_mem i zero_lt_one,
end
lemma basis_sets_intersect
(U V : set E) (hU : U ∈ p.basis_sets) (hV : V ∈ p.basis_sets) :
∃ (z : set E) (H : z ∈ p.basis_sets), z ⊆ U ∩ V :=
begin
classical,
rcases p.basis_sets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩,
rcases p.basis_sets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩,
use ((s ∪ t).sup p).ball 0 (min r₁ r₂),
refine ⟨p.basis_sets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), _⟩,
rw [hU, hV, ball_finset_sup_eq_Inter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩),
ball_finset_sup_eq_Inter _ _ _ hr₁, ball_finset_sup_eq_Inter _ _ _ hr₂],
exact set.subset_inter
(set.Inter₂_mono' $ λ i hi, ⟨i, finset.subset_union_left _ _ hi, ball_mono $ min_le_left _ _⟩)
(set.Inter₂_mono' $ λ i hi, ⟨i, finset.subset_union_right _ _ hi, ball_mono $
min_le_right _ _⟩),
end
lemma basis_sets_zero (U) (hU : U ∈ p.basis_sets) :
(0 : E) ∈ U :=
begin
rcases p.basis_sets_iff.mp hU with ⟨ι', r, hr, hU⟩,
rw [hU, mem_ball_zero, map_zero],
exact hr,
end
lemma basis_sets_add (U) (hU : U ∈ p.basis_sets) :
∃ (V : set E) (H : V ∈ p.basis_sets), V + V ⊆ U :=
begin
rcases p.basis_sets_iff.mp hU with ⟨s, r, hr, hU⟩,
use (s.sup p).ball 0 (r/2),
refine ⟨p.basis_sets_mem s (div_pos hr zero_lt_two), _⟩,
refine set.subset.trans (ball_add_ball_subset (s.sup p) (r/2) (r/2) 0 0) _,
rw [hU, add_zero, add_halves'],
end
lemma basis_sets_neg (U) (hU' : U ∈ p.basis_sets) :
∃ (V : set E) (H : V ∈ p.basis_sets), V ⊆ (λ (x : E), -x) ⁻¹' U :=
begin
rcases p.basis_sets_iff.mp hU' with ⟨s, r, hr, hU⟩,
rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero],
exact ⟨U, hU', eq.subset hU⟩,
end
/-- The `add_group_filter_basis` induced by the filter basis `seminorm_basis_zero`. -/
protected def add_group_filter_basis [nonempty ι] : add_group_filter_basis E :=
add_group_filter_basis_of_comm p.basis_sets p.basis_sets_nonempty
p.basis_sets_intersect p.basis_sets_zero p.basis_sets_add p.basis_sets_neg
lemma basis_sets_smul_right (v : E) (U : set E)
(hU : U ∈ p.basis_sets) : ∀ᶠ (x : 𝕜) in 𝓝 0, x • v ∈ U :=
begin
rcases p.basis_sets_iff.mp hU with ⟨s, r, hr, hU⟩,
rw [hU, filter.eventually_iff],
simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul],
by_cases h : 0 < (s.sup p) v,
{ simp_rw (lt_div_iff h).symm,
rw ←_root_.ball_zero_eq,
exact metric.ball_mem_nhds 0 (div_pos hr h) },
simp_rw [le_antisymm (not_lt.mp h) (map_nonneg _ v), mul_zero, hr],
exact is_open.mem_nhds is_open_univ (mem_univ 0),
end
variables [nonempty ι]
lemma basis_sets_smul (U) (hU : U ∈ p.basis_sets) :
∃ (V : set 𝕜) (H : V ∈ 𝓝 (0 : 𝕜)) (W : set E)
(H : W ∈ p.add_group_filter_basis.sets), V • W ⊆ U :=
begin
rcases p.basis_sets_iff.mp hU with ⟨s, r, hr, hU⟩,
refine ⟨metric.ball 0 r.sqrt, metric.ball_mem_nhds 0 (real.sqrt_pos.mpr hr), _⟩,
refine ⟨(s.sup p).ball 0 r.sqrt, p.basis_sets_mem s (real.sqrt_pos.mpr hr), _⟩,
refine set.subset.trans (ball_smul_ball (s.sup p) r.sqrt r.sqrt) _,
rw [hU, real.mul_self_sqrt (le_of_lt hr)],
end
lemma basis_sets_smul_left (x : 𝕜) (U : set E)
(hU : U ∈ p.basis_sets) : ∃ (V : set E)
(H : V ∈ p.add_group_filter_basis.sets), V ⊆ (λ (y : E), x • y) ⁻¹' U :=
begin
rcases p.basis_sets_iff.mp hU with ⟨s, r, hr, hU⟩,
rw hU,
by_cases h : x ≠ 0,
{ rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero],
use (s.sup p).ball 0 (r / ‖x‖),
exact ⟨p.basis_sets_mem s (div_pos hr (norm_pos_iff.mpr h)), subset.rfl⟩ },
refine ⟨(s.sup p).ball 0 r, p.basis_sets_mem s hr, _⟩,
simp only [not_ne_iff.mp h, subset_def, mem_ball_zero, hr, mem_univ, map_zero,
implies_true_iff, preimage_const_of_mem, zero_smul],
end
/-- The `module_filter_basis` induced by the filter basis `seminorm_basis_zero`. -/
protected def module_filter_basis : module_filter_basis 𝕜 E :=
{ to_add_group_filter_basis := p.add_group_filter_basis,
smul' := p.basis_sets_smul,
smul_left' := p.basis_sets_smul_left,
smul_right' := p.basis_sets_smul_right }
lemma filter_eq_infi (p : seminorm_family 𝕜 E ι) :
p.module_filter_basis.to_filter_basis.filter = ⨅ i, (𝓝 0).comap (p i) :=
begin
refine le_antisymm (le_infi $ λ i, _) _,
{ rw p.module_filter_basis.to_filter_basis.has_basis.le_basis_iff
(metric.nhds_basis_ball.comap _),
intros ε hε,
refine ⟨(p i).ball 0 ε, _, _⟩,
{ rw ← (finset.sup_singleton : _ = p i),
exact p.basis_sets_mem {i} hε, },
{ rw [id, (p i).ball_zero_eq_preimage_ball] } },
{ rw p.module_filter_basis.to_filter_basis.has_basis.ge_iff,
rintros U (hU : U ∈ p.basis_sets),
rcases p.basis_sets_iff.mp hU with ⟨s, r, hr, rfl⟩,
rw [id, seminorm.ball_finset_sup_eq_Inter _ _ _ hr, s.Inter_mem_sets],
exact λ i hi, filter.mem_infi_of_mem i ⟨metric.ball 0 r, metric.ball_mem_nhds 0 hr,
eq.subset ((p i).ball_zero_eq_preimage_ball).symm⟩, },
end
end seminorm_family
end filter_basis
section bounded
namespace seminorm
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E]
variables [normed_field 𝕜₂] [add_comm_group F] [module 𝕜₂ F]
variables {σ₁₂ : 𝕜 →+* 𝕜₂} [ring_hom_isometric σ₁₂]
-- Todo: This should be phrased entirely in terms of the von Neumann bornology.
/-- The proposition that a linear map is bounded between spaces with families of seminorms. -/
def is_bounded (p : ι → seminorm 𝕜 E) (q : ι' → seminorm 𝕜₂ F) (f : E →ₛₗ[σ₁₂] F) : Prop :=
∀ i, ∃ s : finset ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • s.sup p
lemma is_bounded_const (ι' : Type*) [nonempty ι']
{p : ι → seminorm 𝕜 E} {q : seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) :
is_bounded p (λ _ : ι', q) f ↔ ∃ (s : finset ι) C : ℝ≥0, q.comp f ≤ C • s.sup p :=
by simp only [is_bounded, forall_const]
lemma const_is_bounded (ι : Type*) [nonempty ι]
{p : seminorm 𝕜 E} {q : ι' → seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) :
is_bounded (λ _ : ι, p) q f ↔ ∀ i, ∃ C : ℝ≥0, (q i).comp f ≤ C • p :=
begin
split; intros h i,
{ rcases h i with ⟨s, C, h⟩,
exact ⟨C, le_trans h (smul_le_smul (finset.sup_le (λ _ _, le_rfl)) le_rfl)⟩ },
use [{classical.arbitrary ι}],
simp only [h, finset.sup_singleton],
end
lemma is_bounded_sup {p : ι → seminorm 𝕜 E} {q : ι' → seminorm 𝕜₂ F}
{f : E →ₛₗ[σ₁₂] F} (hf : is_bounded p q f) (s' : finset ι') :
∃ (C : ℝ≥0) (s : finset ι), (s'.sup q).comp f ≤ C • (s.sup p) :=
begin
classical,
obtain rfl | hs' := s'.eq_empty_or_nonempty,
{ exact ⟨1, ∅, by simp [seminorm.bot_eq_zero]⟩ },
choose fₛ fC hf using hf,
use [s'.card • s'.sup fC, finset.bUnion s' fₛ],
have hs : ∀ i : ι', i ∈ s' → (q i).comp f ≤ s'.sup fC • ((finset.bUnion s' fₛ).sup p) :=
begin
intros i hi,
refine (hf i).trans (smul_le_smul _ (finset.le_sup hi)),
exact finset.sup_mono (finset.subset_bUnion_of_mem fₛ hi),
end,
refine (comp_mono f (finset_sup_le_sum q s')).trans _,
simp_rw [←pullback_apply, add_monoid_hom.map_sum, pullback_apply],
refine (finset.sum_le_sum hs).trans _,
rw [finset.sum_const, smul_assoc],
exact le_rfl,
end
end seminorm
end bounded
section topology
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E] [nonempty ι]
/-- The proposition that the topology of `E` is induced by a family of seminorms `p`. -/
structure with_seminorms (p : seminorm_family 𝕜 E ι) [t : topological_space E] : Prop :=
(topology_eq_with_seminorms : t = p.module_filter_basis.topology)
lemma with_seminorms.with_seminorms_eq {p : seminorm_family 𝕜 E ι} [t : topological_space E]
(hp : with_seminorms p) : t = p.module_filter_basis.topology := hp.1
variables [topological_space E]
variables {p : seminorm_family 𝕜 E ι}
lemma with_seminorms.topological_add_group (hp : with_seminorms p) : topological_add_group E :=
begin
rw hp.with_seminorms_eq,
exact add_group_filter_basis.is_topological_add_group _
end
lemma with_seminorms.has_basis (hp : with_seminorms p) : (𝓝 (0 : E)).has_basis
(λ (s : set E), s ∈ p.basis_sets) id :=
begin
rw (congr_fun (congr_arg (@nhds E) hp.1) 0),
exact add_group_filter_basis.nhds_zero_has_basis _,
end
lemma with_seminorms.has_basis_zero_ball (hp : with_seminorms p) : (𝓝 (0 : E)).has_basis
(λ sr : finset ι × ℝ, 0 < sr.2) (λ sr, (sr.1.sup p).ball 0 sr.2) :=
begin
refine ⟨λ V, _⟩,
simp only [hp.has_basis.mem_iff, seminorm_family.basis_sets_iff, prod.exists],
split,
{ rintros ⟨-, ⟨s, r, hr, rfl⟩, hV⟩,
exact ⟨s, r, hr, hV⟩ },
{ rintros ⟨s, r, hr, hV⟩,
exact ⟨_, ⟨s, r, hr, rfl⟩, hV⟩ }
end
lemma with_seminorms.has_basis_ball (hp : with_seminorms p) {x : E} : (𝓝 (x : E)).has_basis
(λ sr : finset ι × ℝ, 0 < sr.2) (λ sr, (sr.1.sup p).ball x sr.2) :=
begin
haveI : topological_add_group E := hp.topological_add_group,
rw [← map_add_left_nhds_zero],
convert (hp.has_basis_zero_ball.map ((+) x)),
ext sr : 1,
have : (sr.fst.sup p).ball (x +ᵥ 0) sr.snd = x +ᵥ (sr.fst.sup p).ball 0 sr.snd
:= eq.symm (seminorm.vadd_ball (sr.fst.sup p)),
rwa [vadd_eq_add, add_zero] at this,
end
/-- The `x`-neighbourhoods of a space whose topology is induced by a family of seminorms
are exactly the sets which contain seminorm balls around `x`.-/
lemma with_seminorms.mem_nhds_iff (hp : with_seminorms p) (x : E) (U : set E) :
U ∈ nhds x ↔ ∃ (s : finset ι) (r > 0), (s.sup p).ball x r ⊆ U :=
by rw [hp.has_basis_ball.mem_iff, prod.exists]
/-- The open sets of a space whose topology is induced by a family of seminorms
are exactly the sets which contain seminorm balls around all of their points.-/
lemma with_seminorms.is_open_iff_mem_balls (hp : with_seminorms p) (U : set E) :
is_open U ↔ ∀ x ∈ U, ∃ (s : finset ι) (r > 0), (s.sup p).ball x r ⊆ U :=
by simp_rw [←with_seminorms.mem_nhds_iff hp _ U, is_open_iff_mem_nhds]
/- Note that through the following lemmas, one also immediately has that separating families
of seminorms induce T₂ and T₃ topologies by `topological_add_group.t2_space`
and `topological_add_group.t3_space` -/
/-- A separating family of seminorms induces a T₁ topology. -/
lemma with_seminorms.t1_of_separating (hp : with_seminorms p) (h : ∀ x ≠ 0, ∃ i, p i x ≠ 0) :
t1_space E :=
begin
haveI := hp.topological_add_group,
refine topological_add_group.t1_space _ _,
rw [← is_open_compl_iff, hp.is_open_iff_mem_balls],
rintros x (hx : x ≠ 0),
cases h x hx with i pi_nonzero,
refine ⟨{i}, p i x, by positivity, subset_compl_singleton_iff.mpr _⟩,
rw [finset.sup_singleton, mem_ball, zero_sub, map_neg_eq_map, not_lt]
end
/-- A family of seminorms inducing a T₁ topology is separating. -/
lemma with_seminorms.separating_of_t1 [t1_space E] (hp : with_seminorms p) (x : E) (hx : x ≠ 0) :
∃ i, p i x ≠ 0 :=
begin
have := ((t1_space_tfae E).out 0 9).mp infer_instance,
by_contra' h,
refine hx (this _),
rw hp.has_basis_zero_ball.specializes_iff,
rintros ⟨s, r⟩ (hr : 0 < r),
simp only [ball_finset_sup_eq_Inter _ _ _ hr, mem_Inter₂, mem_ball_zero, h, hr, forall_true_iff],
end
/-- A family of seminorms is separating iff it induces a T₁ topology. -/
lemma with_seminorms.separating_iff_t1 (hp : with_seminorms p) :
(∀ x ≠ 0, ∃ i, p i x ≠ 0) ↔ t1_space E :=
begin
refine ⟨with_seminorms.t1_of_separating hp, _⟩,
introI,
exact with_seminorms.separating_of_t1 hp,
end
end topology
section tendsto
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E] [nonempty ι] [topological_space E]
variables {p : seminorm_family 𝕜 E ι}
/-- Convergence along filters for `with_seminorms`.
Variant with `finset.sup`. -/
lemma with_seminorms.tendsto_nhds' (hp : with_seminorms p) (u : F → E) {f : filter F} (y₀ : E) :
filter.tendsto u f (𝓝 y₀) ↔ ∀ (s : finset ι) ε, 0 < ε → ∀ᶠ x in f, s.sup p (u x - y₀) < ε :=
by simp [hp.has_basis_ball.tendsto_right_iff]
/-- Convergence along filters for `with_seminorms`. -/
lemma with_seminorms.tendsto_nhds (hp : with_seminorms p) (u : F → E) {f : filter F} (y₀ : E) :
filter.tendsto u f (𝓝 y₀) ↔ ∀ i ε, 0 < ε → ∀ᶠ x in f, p i (u x - y₀) < ε :=
begin
rw hp.tendsto_nhds' u y₀,
exact ⟨λ h i, by simpa only [finset.sup_singleton] using h {i},
λ h s ε hε, (s.eventually_all.2 $ λ i _, h i ε hε).mono (λ _, finset_sup_apply_lt hε)⟩,
end
variables [semilattice_sup F] [nonempty F]
/-- Limit `→ ∞` for `with_seminorms`. -/
lemma with_seminorms.tendsto_nhds_at_top (hp : with_seminorms p) (u : F → E) (y₀ : E) :
filter.tendsto u filter.at_top (𝓝 y₀) ↔ ∀ i ε, 0 < ε → ∃ x₀, ∀ x, x₀ ≤ x → p i (u x - y₀) < ε :=
begin
rw hp.tendsto_nhds u y₀,
exact forall₃_congr (λ _ _ _, filter.eventually_at_top),
end
end tendsto
section topological_add_group
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E]
variables [t : topological_space E] [topological_add_group E]
variables [nonempty ι]
include t
lemma seminorm_family.with_seminorms_of_nhds (p : seminorm_family 𝕜 E ι)
(h : 𝓝 (0 : E) = p.module_filter_basis.to_filter_basis.filter) :
with_seminorms p :=
begin
refine ⟨topological_add_group.ext infer_instance
(p.add_group_filter_basis.is_topological_add_group) _⟩,
rw add_group_filter_basis.nhds_zero_eq,
exact h,
end
lemma seminorm_family.with_seminorms_of_has_basis (p : seminorm_family 𝕜 E ι)
(h : (𝓝 (0 : E)).has_basis (λ (s : set E), s ∈ p.basis_sets) id) :
with_seminorms p :=
p.with_seminorms_of_nhds $ filter.has_basis.eq_of_same_basis h
p.add_group_filter_basis.to_filter_basis.has_basis
lemma seminorm_family.with_seminorms_iff_nhds_eq_infi (p : seminorm_family 𝕜 E ι) :
with_seminorms p ↔ (𝓝 0 : filter E) = ⨅ i, (𝓝 0).comap (p i) :=
begin
rw ← p.filter_eq_infi,
refine ⟨λ h, _, p.with_seminorms_of_nhds⟩,
rw h.topology_eq_with_seminorms,
exact add_group_filter_basis.nhds_zero_eq _,
end
lemma with_seminorms.continuous_seminorm [nontrivially_normed_field 𝕝]
[module 𝕝 E] [has_continuous_const_smul 𝕝 E] {p : seminorm_family 𝕝 E ι} (hp : with_seminorms p)
(i : ι) : continuous (p i) :=
begin
refine seminorm.continuous one_pos _,
rw [p.with_seminorms_iff_nhds_eq_infi.mp hp, ball_zero_eq_preimage_ball],
exact filter.mem_infi_of_mem i (filter.preimage_mem_comap $ metric.ball_mem_nhds _ one_pos)
end
/-- The topology induced by a family of seminorms is exactly the infimum of the ones induced by
each seminorm individually. We express this as a characterization of `with_seminorms p`. -/
lemma seminorm_family.with_seminorms_iff_topological_space_eq_infi (p : seminorm_family 𝕜 E ι) :
with_seminorms p ↔ t = ⨅ i, (p i).to_add_group_seminorm.to_seminormed_add_comm_group
.to_uniform_space.to_topological_space :=
begin
rw [p.with_seminorms_iff_nhds_eq_infi, topological_add_group.ext_iff infer_instance
(topological_add_group_infi $ λ i, infer_instance), nhds_infi],
congrm (_ = ⨅ i, _),
exact @comap_norm_nhds_zero _ (p i).to_add_group_seminorm.to_seminormed_add_group,
all_goals {apply_instance}
end
omit t
/-- The uniform structure induced by a family of seminorms is exactly the infimum of the ones
induced by each seminorm individually. We express this as a characterization of
`with_seminorms p`. -/
lemma seminorm_family.with_seminorms_iff_uniform_space_eq_infi [u : uniform_space E]
[uniform_add_group E] (p : seminorm_family 𝕜 E ι) :
with_seminorms p ↔ u = ⨅ i, (p i).to_add_group_seminorm.to_seminormed_add_comm_group
.to_uniform_space :=
begin
rw [p.with_seminorms_iff_nhds_eq_infi, uniform_add_group.ext_iff infer_instance
(uniform_add_group_infi $ λ i, infer_instance), to_topological_space_infi, nhds_infi],
congrm (_ = ⨅ i, _),
exact @comap_norm_nhds_zero _ (p i).to_add_group_seminorm.to_seminormed_add_group,
all_goals {apply_instance}
end
end topological_add_group
section normed_space
/-- The topology of a `normed_space 𝕜 E` is induced by the seminorm `norm_seminorm 𝕜 E`. -/
lemma norm_with_seminorms (𝕜 E) [normed_field 𝕜] [seminormed_add_comm_group E] [normed_space 𝕜 E] :
with_seminorms (λ (_ : fin 1), norm_seminorm 𝕜 E) :=
begin
let p : seminorm_family 𝕜 E (fin 1) := λ _, norm_seminorm 𝕜 E,
refine ⟨seminormed_add_comm_group.to_topological_add_group.ext
p.add_group_filter_basis.is_topological_add_group _⟩,
refine filter.has_basis.eq_of_same_basis metric.nhds_basis_ball _,
rw ←ball_norm_seminorm 𝕜 E,
refine filter.has_basis.to_has_basis p.add_group_filter_basis.nhds_zero_has_basis _
(λ r hr, ⟨(norm_seminorm 𝕜 E).ball 0 r, p.basis_sets_singleton_mem 0 hr, rfl.subset⟩),
rintros U (hU : U ∈ p.basis_sets),
rcases p.basis_sets_iff.mp hU with ⟨s, r, hr, hU⟩,
use [r, hr],
rw [hU, id.def],
by_cases h : s.nonempty,
{ rw finset.sup_const h },
rw [finset.not_nonempty_iff_eq_empty.mp h, finset.sup_empty, ball_bot _ hr],
exact set.subset_univ _,
end
end normed_space
section nontrivially_normed_field
variables [nontrivially_normed_field 𝕜] [add_comm_group E] [module 𝕜 E] [nonempty ι]
variables {p : seminorm_family 𝕜 E ι}
variables [topological_space E]
lemma with_seminorms.is_vonN_bounded_iff_finset_seminorm_bounded {s : set E}
(hp : with_seminorms p) :
bornology.is_vonN_bounded 𝕜 s ↔ ∀ I : finset ι, ∃ r (hr : 0 < r), ∀ (x ∈ s), I.sup p x < r :=
begin
rw (hp.has_basis).is_vonN_bounded_basis_iff,
split,
{ intros h I,
simp only [id.def] at h,
specialize h ((I.sup p).ball 0 1) (p.basis_sets_mem I zero_lt_one),
rcases h with ⟨r, hr, h⟩,
cases normed_field.exists_lt_norm 𝕜 r with a ha,
specialize h a (le_of_lt ha),
rw [seminorm.smul_ball_zero (norm_pos_iff.1 $ hr.trans ha), mul_one] at h,
refine ⟨‖a‖, lt_trans hr ha, _⟩,
intros x hx,
specialize h hx,
exact (finset.sup I p).mem_ball_zero.mp h },
intros h s' hs',
rcases p.basis_sets_iff.mp hs' with ⟨I, r, hr, hs'⟩,
rw [id.def, hs'],
rcases h I with ⟨r', hr', h'⟩,
simp_rw ←(I.sup p).mem_ball_zero at h',
refine absorbs.mono_right _ h',
exact (finset.sup I p).ball_zero_absorbs_ball_zero hr,
end
lemma with_seminorms.image_is_vonN_bounded_iff_finset_seminorm_bounded (f : G → E) {s : set G}
(hp : with_seminorms p) : bornology.is_vonN_bounded 𝕜 (f '' s) ↔
∀ I : finset ι, ∃ r (hr : 0 < r), ∀ (x ∈ s), I.sup p (f x) < r :=
by simp_rw [hp.is_vonN_bounded_iff_finset_seminorm_bounded, set.ball_image_iff]
lemma with_seminorms.is_vonN_bounded_iff_seminorm_bounded {s : set E} (hp : with_seminorms p) :
bornology.is_vonN_bounded 𝕜 s ↔ ∀ i : ι, ∃ r (hr : 0 < r), ∀ (x ∈ s), p i x < r :=
begin
rw hp.is_vonN_bounded_iff_finset_seminorm_bounded,
split,
{ intros hI i,
convert hI {i},
rw [finset.sup_singleton] },
intros hi I,
by_cases hI : I.nonempty,
{ choose r hr h using hi,
have h' : 0 < I.sup' hI r :=
by { rcases hI.bex with ⟨i, hi⟩, exact lt_of_lt_of_le (hr i) (finset.le_sup' r hi) },
refine ⟨I.sup' hI r, h', λ x hx, finset_sup_apply_lt h' (λ i hi, _)⟩,
refine lt_of_lt_of_le (h i x hx) _,
simp only [finset.le_sup'_iff, exists_prop],
exact ⟨i, hi, (eq.refl _).le⟩ },
simp only [finset.not_nonempty_iff_eq_empty.mp hI, finset.sup_empty, coe_bot, pi.zero_apply,
exists_prop],
exact ⟨1, zero_lt_one, λ _ _, zero_lt_one⟩,
end
lemma with_seminorms.image_is_vonN_bounded_iff_seminorm_bounded (f : G → E) {s : set G}
(hp : with_seminorms p) :
bornology.is_vonN_bounded 𝕜 (f '' s) ↔ ∀ i : ι, ∃ r (hr : 0 < r), ∀ (x ∈ s), p i (f x) < r :=
by simp_rw [hp.is_vonN_bounded_iff_seminorm_bounded, set.ball_image_iff]
end nontrivially_normed_field
section continuous_bounded
namespace seminorm
variables [nontrivially_normed_field 𝕜] [add_comm_group E] [module 𝕜 E]
variables [normed_field 𝕝] [module 𝕝 E]
variables [nontrivially_normed_field 𝕜₂] [add_comm_group F] [module 𝕜₂ F]
variables [normed_field 𝕝₂] [module 𝕝₂ F]
variables {σ₁₂ : 𝕜 →+* 𝕜₂} [ring_hom_isometric σ₁₂]
variables {τ₁₂ : 𝕝 →+* 𝕝₂} [ring_hom_isometric τ₁₂]
variables [nonempty ι] [nonempty ι']
lemma continuous_of_continuous_comp {q : seminorm_family 𝕝₂ F ι'}
[topological_space E] [topological_add_group E]
[topological_space F] [topological_add_group F] (hq : with_seminorms q)
(f : E →ₛₗ[τ₁₂] F) (hf : ∀ i, continuous ((q i).comp f)) : continuous f :=
begin
refine continuous_of_continuous_at_zero f _,
simp_rw [continuous_at, f.map_zero, q.with_seminorms_iff_nhds_eq_infi.mp hq, filter.tendsto_infi,
filter.tendsto_comap_iff],
intros i,
convert (hf i).continuous_at,
exact (map_zero _).symm
end
lemma continuous_iff_continuous_comp
{q : seminorm_family 𝕜₂ F ι'} [topological_space E] [topological_add_group E]
[topological_space F] [topological_add_group F] [has_continuous_const_smul 𝕜₂ F]
(hq : with_seminorms q) (f : E →ₛₗ[σ₁₂] F) :
continuous f ↔ ∀ i, continuous ((q i).comp f) :=
⟨λ h i, continuous.comp (hq.continuous_seminorm i) h, continuous_of_continuous_comp hq f⟩
lemma continuous_from_bounded {p : seminorm_family 𝕝 E ι} {q : seminorm_family 𝕝₂ F ι'}
[topological_space E] [topological_add_group E] (hp : with_seminorms p)
[topological_space F] [topological_add_group F] (hq : with_seminorms q)
(f : E →ₛₗ[τ₁₂] F) (hf : seminorm.is_bounded p q f) : continuous f :=
begin
refine continuous_of_continuous_comp hq _ (λ i, seminorm.continuous_of_continuous_at_zero _),
rw [metric.continuous_at_iff', map_zero],
intros r hr,
rcases hf i with ⟨s₁, C, hf⟩,
have hC' : 0 < C + 1 := by positivity,
rw hp.has_basis.eventually_iff,
refine ⟨(s₁.sup p).ball 0 (r/(C + 1)), p.basis_sets_mem _ (by positivity), _⟩,
simp_rw [ ←metric.mem_ball, ←mem_preimage, ←ball_zero_eq_preimage_ball],
refine subset.trans _ (ball_antitone hf),
norm_cast,
rw ← ball_smul (s₁.sup p) hC',
refine ball_antitone (smul_le_smul le_rfl _),
simp only [le_add_iff_nonneg_right, zero_le'],
end
lemma cont_with_seminorms_normed_space (F) [seminormed_add_comm_group F] [normed_space 𝕝₂ F]
[uniform_space E] [uniform_add_group E]
{p : ι → seminorm 𝕝 E} (hp : with_seminorms p) (f : E →ₛₗ[τ₁₂] F)
(hf : ∃ (s : finset ι) C : ℝ≥0, (norm_seminorm 𝕝₂ F).comp f ≤ C • s.sup p) :
continuous f :=
begin
rw ←seminorm.is_bounded_const (fin 1) at hf,
exact continuous_from_bounded hp (norm_with_seminorms 𝕝₂ F) f hf,
end
lemma cont_normed_space_to_with_seminorms (E) [seminormed_add_comm_group E] [normed_space 𝕝 E]
[uniform_space F] [uniform_add_group F]
{q : ι → seminorm 𝕝₂ F} (hq : with_seminorms q) (f : E →ₛₗ[τ₁₂] F)
(hf : ∀ i : ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • (norm_seminorm 𝕝 E)) : continuous f :=
begin
rw ←seminorm.const_is_bounded (fin 1) at hf,
exact continuous_from_bounded (norm_with_seminorms 𝕝 E) hq f hf,
end
end seminorm
end continuous_bounded
section locally_convex_space
open locally_convex_space
variables [nonempty ι] [normed_field 𝕜] [normed_space ℝ 𝕜]
[add_comm_group E] [module 𝕜 E] [module ℝ E] [is_scalar_tower ℝ 𝕜 E] [topological_space E]
[topological_add_group E]
lemma with_seminorms.to_locally_convex_space {p : seminorm_family 𝕜 E ι} (hp : with_seminorms p) :
locally_convex_space ℝ E :=
begin
apply of_basis_zero ℝ E id (λ s, s ∈ p.basis_sets),
{ rw [hp.1, add_group_filter_basis.nhds_eq _, add_group_filter_basis.N_zero],
exact filter_basis.has_basis _ },
{ intros s hs,
change s ∈ set.Union _ at hs,
simp_rw [set.mem_Union, set.mem_singleton_iff] at hs,
rcases hs with ⟨I, r, hr, rfl⟩,
exact convex_ball _ _ _ }
end
end locally_convex_space
section normed_space
variables (𝕜) [normed_field 𝕜] [normed_space ℝ 𝕜] [seminormed_add_comm_group E]
/-- Not an instance since `𝕜` can't be inferred. See `normed_space.to_locally_convex_space` for a
slightly weaker instance version. -/
lemma normed_space.to_locally_convex_space' [normed_space 𝕜 E] [module ℝ E]
[is_scalar_tower ℝ 𝕜 E] : locally_convex_space ℝ E :=
(norm_with_seminorms 𝕜 E).to_locally_convex_space
/-- See `normed_space.to_locally_convex_space'` for a slightly stronger version which is not an
instance. -/
instance normed_space.to_locally_convex_space [normed_space ℝ E] :
locally_convex_space ℝ E :=
normed_space.to_locally_convex_space' ℝ
end normed_space
section topological_constructions
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E]
variables [normed_field 𝕜₂] [add_comm_group F] [module 𝕜₂ F]
variables {σ₁₂ : 𝕜 →+* 𝕜₂} [ring_hom_isometric σ₁₂]
/-- The family of seminorms obtained by composing each seminorm by a linear map. -/
def seminorm_family.comp (q : seminorm_family 𝕜₂ F ι) (f : E →ₛₗ[σ₁₂] F) :
seminorm_family 𝕜 E ι :=
λ i, (q i).comp f
lemma seminorm_family.comp_apply (q : seminorm_family 𝕜₂ F ι) (i : ι) (f : E →ₛₗ[σ₁₂] F) :
q.comp f i = (q i).comp f :=
rfl
lemma seminorm_family.finset_sup_comp (q : seminorm_family 𝕜₂ F ι) (s : finset ι)
(f : E →ₛₗ[σ₁₂] F) : (s.sup q).comp f = s.sup (q.comp f) :=
begin
ext x,
rw [seminorm.comp_apply, seminorm.finset_sup_apply, seminorm.finset_sup_apply],
refl
end
variables [topological_space F] [topological_add_group F]
lemma linear_map.with_seminorms_induced [hι : nonempty ι] {q : seminorm_family 𝕜₂ F ι}
(hq : with_seminorms q) (f : E →ₛₗ[σ₁₂] F) :
@with_seminorms 𝕜 E ι _ _ _ _ (q.comp f) (induced f infer_instance) :=
begin
letI : topological_space E := induced f infer_instance,
letI : topological_add_group E := topological_add_group_induced f,
rw [(q.comp f).with_seminorms_iff_nhds_eq_infi, nhds_induced, map_zero,
q.with_seminorms_iff_nhds_eq_infi.mp hq, filter.comap_infi],
refine infi_congr (λ i, _),
exact filter.comap_comap
end
lemma inducing.with_seminorms [hι : nonempty ι] {q : seminorm_family 𝕜₂ F ι}
(hq : with_seminorms q) [topological_space E] {f : E →ₛₗ[σ₁₂] F} (hf : inducing f) :
with_seminorms (q.comp f) :=
begin
rw hf.induced,
exact f.with_seminorms_induced hq
end
end topological_constructions
section topological_properties
variables [nontrivially_normed_field 𝕜] [add_comm_group E] [module 𝕜 E] [nonempty ι] [countable ι]
variables {p : seminorm_family 𝕜 E ι}
variables [uniform_space E] [uniform_add_group E]
/-- If the topology of a space is induced by a countable family of seminorms, then the topology
is first countable. -/
lemma with_seminorms.first_countable (hp : with_seminorms p) :
topological_space.first_countable_topology E :=
begin
haveI : (𝓝 (0 : E)).is_countably_generated,
{ rw p.with_seminorms_iff_nhds_eq_infi.mp hp,
exact filter.infi.is_countably_generated _ },
haveI : (uniformity E).is_countably_generated := uniform_add_group.uniformity_countably_generated,
exact uniform_space.first_countable_topology E,
end
end topological_properties
|
46de19fc29e24716bef054ab2237cadab5a0ea5b | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/ring_theory/ideal/local_ring.lean | 8928de69e17230380167aef2cf4873d7077d14a9 | [
"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 | 15,282 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Mario Carneiro
-/
import algebra.algebra.basic
import ring_theory.ideal.operations
import ring_theory.jacobson_ideal
/-!
# Local rings
Define local rings as commutative rings having a unique maximal ideal.
## Main definitions
* `local_ring`: A predicate on commutative semirings, stating that for any pair of elements that
adds up to `1`, one of them is a unit. This is shown to be equivalent to the condition that there
exists a unique maximal ideal.
* `local_ring.maximal_ideal`: The unique maximal ideal for a local rings. Its carrier set is the
set of non units.
* `is_local_ring_hom`: A predicate on semiring homomorphisms, requiring that it maps nonunits
to nonunits. For local rings, this means that the image of the unique maximal ideal is again
contained in the unique maximal ideal.
* `local_ring.residue_field`: The quotient of a local ring by its maximal ideal.
-/
universes u v w u'
variables {R : Type u} {S : Type v} {T : Type w} {K : Type u'}
/-- A semiring is local if it is nontrivial and `a` or `b` is a unit whenever `a + b = 1`.
Note that `local_ring` is a predicate. -/
class local_ring (R : Type u) [semiring R] extends nontrivial R : Prop :=
of_is_unit_or_is_unit_of_add_one ::
(is_unit_or_is_unit_of_add_one {a b : R} (h : a + b = 1) : is_unit a ∨ is_unit b)
section comm_semiring
variables [comm_semiring R]
namespace local_ring
lemma of_is_unit_or_is_unit_of_is_unit_add [nontrivial R]
(h : ∀ a b : R, is_unit (a + b) → is_unit a ∨ is_unit b) :
local_ring R :=
⟨λ a b hab, h a b $ hab.symm ▸ is_unit_one⟩
/-- A semiring is local if it is nontrivial and the set of nonunits is closed under the addition. -/
lemma of_nonunits_add [nontrivial R]
(h : ∀ a b : R, a ∈ nonunits R → b ∈ nonunits R → a + b ∈ nonunits R) :
local_ring R :=
⟨λ a b hab, or_iff_not_and_not.2 $ λ H, h a b H.1 H.2 $ hab.symm ▸ is_unit_one⟩
/-- A semiring is local if it has a unique maximal ideal. -/
lemma of_unique_max_ideal (h : ∃! I : ideal R, I.is_maximal) :
local_ring R :=
@of_nonunits_add _ _ (nontrivial_of_ne (0 : R) 1 $
let ⟨I, Imax, _⟩ := h in (λ (H : 0 = 1), Imax.1.1 $ I.eq_top_iff_one.2 $ H ▸ I.zero_mem)) $
λ x y hx hy H,
let ⟨I, Imax, Iuniq⟩ := h in
let ⟨Ix, Ixmax, Hx⟩ := exists_max_ideal_of_mem_nonunits hx in
let ⟨Iy, Iymax, Hy⟩ := exists_max_ideal_of_mem_nonunits hy in
have xmemI : x ∈ I, from Iuniq Ix Ixmax ▸ Hx,
have ymemI : y ∈ I, from Iuniq Iy Iymax ▸ Hy,
Imax.1.1 $ I.eq_top_of_is_unit_mem (I.add_mem xmemI ymemI) H
lemma of_unique_nonzero_prime (h : ∃! P : ideal R, P ≠ ⊥ ∧ ideal.is_prime P) :
local_ring R :=
of_unique_max_ideal begin
rcases h with ⟨P, ⟨hPnonzero, hPnot_top, _⟩, hPunique⟩,
refine ⟨P, ⟨⟨hPnot_top, _⟩⟩, λ M hM, hPunique _ ⟨_, ideal.is_maximal.is_prime hM⟩⟩,
{ refine ideal.maximal_of_no_maximal (λ M hPM hM, ne_of_lt hPM _),
exact (hPunique _ ⟨ne_bot_of_gt hPM, ideal.is_maximal.is_prime hM⟩).symm },
{ rintro rfl,
exact hPnot_top (hM.1.2 P (bot_lt_iff_ne_bot.2 hPnonzero)) },
end
variables [local_ring R]
lemma is_unit_or_is_unit_of_is_unit_add {a b : R} (h : is_unit (a + b)) :
is_unit a ∨ is_unit b :=
begin
rcases h with ⟨u, hu⟩,
rw [←units.inv_mul_eq_one, mul_add] at hu,
apply or.imp _ _ (is_unit_or_is_unit_of_add_one hu);
exact is_unit_of_mul_is_unit_right,
end
lemma nonunits_add {a b : R} (ha : a ∈ nonunits R) (hb : b ∈ nonunits R) : a + b ∈ nonunits R:=
λ H, not_or ha hb (is_unit_or_is_unit_of_is_unit_add H)
variables (R)
/-- The ideal of elements that are not units. -/
def maximal_ideal : ideal R :=
{ carrier := nonunits R,
zero_mem' := zero_mem_nonunits.2 $ zero_ne_one,
add_mem' := λ x y hx hy, nonunits_add hx hy,
smul_mem' := λ a x, mul_mem_nonunits_right }
instance maximal_ideal.is_maximal : (maximal_ideal R).is_maximal :=
begin
rw ideal.is_maximal_iff,
split,
{ intro h, apply h, exact is_unit_one },
{ intros I x hI hx H,
erw not_not at hx,
rcases hx with ⟨u,rfl⟩,
simpa using I.mul_mem_left ↑u⁻¹ H }
end
lemma maximal_ideal_unique : ∃! I : ideal R, I.is_maximal :=
⟨maximal_ideal R, maximal_ideal.is_maximal R,
λ I hI, hI.eq_of_le (maximal_ideal.is_maximal R).1.1 $
λ x hx, hI.1.1 ∘ I.eq_top_of_is_unit_mem hx⟩
variable {R}
lemma eq_maximal_ideal {I : ideal R} (hI : I.is_maximal) : I = maximal_ideal R :=
unique_of_exists_unique (maximal_ideal_unique R) hI $ maximal_ideal.is_maximal R
lemma le_maximal_ideal {J : ideal R} (hJ : J ≠ ⊤) : J ≤ maximal_ideal R :=
begin
rcases ideal.exists_le_maximal J hJ with ⟨M, hM1, hM2⟩,
rwa ←eq_maximal_ideal hM1
end
@[simp] lemma mem_maximal_ideal (x) : x ∈ maximal_ideal R ↔ x ∈ nonunits R := iff.rfl
end local_ring
end comm_semiring
section comm_ring
variables [comm_ring R]
namespace local_ring
lemma of_is_unit_or_is_unit_one_sub_self [nontrivial R]
(h : ∀ a : R, is_unit a ∨ is_unit (1 - a)) : local_ring R :=
⟨λ a b hab, add_sub_cancel' a b ▸ hab.symm ▸ h a⟩
variables [local_ring R]
lemma is_unit_or_is_unit_one_sub_self (a : R) : is_unit a ∨ is_unit (1 - a) :=
is_unit_or_is_unit_of_is_unit_add $ (add_sub_cancel'_right a 1).symm ▸ is_unit_one
lemma is_unit_of_mem_nonunits_one_sub_self (a : R) (h : 1 - a ∈ nonunits R) :
is_unit a :=
or_iff_not_imp_right.1 (is_unit_or_is_unit_one_sub_self a) h
lemma is_unit_one_sub_self_of_mem_nonunits (a : R) (h : a ∈ nonunits R) :
is_unit (1 - a) :=
or_iff_not_imp_left.1 (is_unit_or_is_unit_one_sub_self a) h
lemma of_surjective' [comm_ring S] [nontrivial S] (f : R →+* S) (hf : function.surjective f) :
local_ring S :=
of_is_unit_or_is_unit_one_sub_self
begin
intros b,
obtain ⟨a, rfl⟩ := hf b,
apply (is_unit_or_is_unit_one_sub_self a).imp f.is_unit_map _,
rw [← f.map_one, ← f.map_sub],
apply f.is_unit_map,
end
lemma jacobson_eq_maximal_ideal (I : ideal R) (h : I ≠ ⊤) :
I.jacobson = local_ring.maximal_ideal R :=
begin
apply le_antisymm,
{ exact Inf_le ⟨local_ring.le_maximal_ideal h, local_ring.maximal_ideal.is_maximal R⟩ },
{ exact le_Inf (λ J (hJ : I ≤ J ∧ J.is_maximal),
le_of_eq (local_ring.eq_maximal_ideal hJ.2).symm) }
end
end local_ring
end comm_ring
/-- A local ring homomorphism is a homomorphism `f` between local rings such that `a` in the domain
is a unit if `f a` is a unit for any `a`. See `local_ring.local_hom_tfae` for other equivalent
definitions. -/
class is_local_ring_hom [semiring R] [semiring S] (f : R →+* S) : Prop :=
(map_nonunit : ∀ a, is_unit (f a) → is_unit a)
section
variables [semiring R] [semiring S] [semiring T]
instance is_local_ring_hom_id (R : Type*) [semiring R] : is_local_ring_hom (ring_hom.id R) :=
{ map_nonunit := λ a, id }
@[simp] lemma is_unit_map_iff (f : R →+* S) [is_local_ring_hom f] (a) :
is_unit (f a) ↔ is_unit a :=
⟨is_local_ring_hom.map_nonunit a, f.is_unit_map⟩
@[simp] lemma map_mem_nonunits_iff (f : R →+* S) [is_local_ring_hom f] (a) :
f a ∈ nonunits S ↔ a ∈ nonunits R :=
⟨λ h ha, h $ (is_unit_map_iff f a).mpr ha, λ h ha, h $ (is_unit_map_iff f a).mp ha⟩
instance is_local_ring_hom_comp
(g : S →+* T) (f : R →+* S) [is_local_ring_hom g] [is_local_ring_hom f] :
is_local_ring_hom (g.comp f) :=
{ map_nonunit := λ a, is_local_ring_hom.map_nonunit a ∘ is_local_ring_hom.map_nonunit (f a) }
instance is_local_ring_hom_equiv (f : R ≃+* S) :
is_local_ring_hom (f : R →+* S) :=
{ map_nonunit := λ a ha,
begin
convert (f.symm : S →+* R).is_unit_map ha,
exact (ring_equiv.symm_apply_apply f a).symm,
end }
@[simp] lemma is_unit_of_map_unit (f : R →+* S) [is_local_ring_hom f]
(a) (h : is_unit (f a)) : is_unit a :=
is_local_ring_hom.map_nonunit a h
theorem of_irreducible_map (f : R →+* S) [h : is_local_ring_hom f] {x}
(hfx : irreducible (f x)) : irreducible x :=
⟨λ h, hfx.not_unit $ is_unit.map f h, λ p q hx, let ⟨H⟩ := h in
or.imp (H p) (H q) $ hfx.is_unit_or_is_unit $ f.map_mul p q ▸ congr_arg f hx⟩
lemma is_local_ring_hom_of_comp (f : R →+* S) (g : S →+* T) [is_local_ring_hom (g.comp f)] :
is_local_ring_hom f :=
⟨λ a ha, (is_unit_map_iff (g.comp f) _).mp (g.is_unit_map ha)⟩
/-- If `f : R →+* S` is a local ring hom, then `R` is a local ring if `S` is. -/
lemma _root_.ring_hom.domain_local_ring {R S : Type*} [comm_semiring R] [comm_semiring S]
[H : _root_.local_ring S] (f : R →+* S)
[is_local_ring_hom f] : _root_.local_ring R :=
begin
haveI : nontrivial R := pullback_nonzero f f.map_zero f.map_one,
apply local_ring.of_nonunits_add,
intros a b,
simp_rw [←map_mem_nonunits_iff f, f.map_add],
exact local_ring.nonunits_add
end
end
section
open local_ring
variables [comm_semiring R] [local_ring R] [comm_semiring S] [local_ring S]
/--
The image of the maximal ideal of the source is contained within the maximal ideal of the target.
-/
lemma map_nonunit (f : R →+* S) [is_local_ring_hom f] (a : R) (h : a ∈ maximal_ideal R) :
f a ∈ maximal_ideal S :=
λ H, h $ is_unit_of_map_unit f a H
end
namespace local_ring
section
variables [comm_semiring R] [local_ring R] [comm_semiring S] [local_ring S]
/--
A ring homomorphism between local rings is a local ring hom iff it reflects units,
i.e. any preimage of a unit is still a unit. https://stacks.math.columbia.edu/tag/07BJ
-/
theorem local_hom_tfae (f : R →+* S) :
tfae [is_local_ring_hom f,
f '' (maximal_ideal R).1 ⊆ maximal_ideal S,
(maximal_ideal R).map f ≤ maximal_ideal S,
maximal_ideal R ≤ (maximal_ideal S).comap f,
(maximal_ideal S).comap f = maximal_ideal R] :=
begin
tfae_have : 1 → 2, rintros _ _ ⟨a,ha,rfl⟩,
resetI, exact map_nonunit f a ha,
tfae_have : 2 → 4, exact set.image_subset_iff.1,
tfae_have : 3 ↔ 4, exact ideal.map_le_iff_le_comap,
tfae_have : 4 → 1, intro h, fsplit, exact λ x, not_imp_not.1 (@h x),
tfae_have : 1 → 5, intro, resetI, ext,
exact not_iff_not.2 (is_unit_map_iff f x),
tfae_have : 5 → 4, exact λ h, le_of_eq h.symm,
tfae_finish,
end
end
lemma of_surjective [comm_semiring R] [local_ring R] [comm_semiring S] [nontrivial S]
(f : R →+* S) [is_local_ring_hom f] (hf : function.surjective f) :
local_ring S :=
of_is_unit_or_is_unit_of_is_unit_add
begin
intros a b hab,
obtain ⟨a, rfl⟩ := hf a,
obtain ⟨b, rfl⟩ := hf b,
rw ←map_add at hab,
exact (is_unit_or_is_unit_of_is_unit_add $ is_local_ring_hom.map_nonunit _ hab).imp
f.is_unit_map f.is_unit_map
end
/-- If `f : R →+* S` is a surjective local ring hom, then the induced units map is surjective. -/
lemma surjective_units_map_of_local_ring_hom [comm_ring R] [comm_ring S]
(f : R →+* S) (hf : function.surjective f) (h : is_local_ring_hom f) :
function.surjective (units.map $ f.to_monoid_hom) :=
begin
intro a,
obtain ⟨b,hb⟩ := hf (a : S),
use (is_unit_of_map_unit f _ (by { rw hb, exact units.is_unit _})).unit, ext, exact hb,
end
section
variables (R) [comm_ring R] [local_ring R] [comm_ring S] [local_ring S] [comm_ring T] [local_ring T]
/-- The residue field of a local ring is the quotient of the ring by its maximal ideal. -/
@[derive [ring, comm_ring, inhabited]]
def residue_field := R ⧸ maximal_ideal R
noncomputable instance residue_field.field : field (residue_field R) :=
ideal.quotient.field (maximal_ideal R)
/-- The quotient map from a local ring to its residue field. -/
def residue : R →+* (residue_field R) :=
ideal.quotient.mk _
instance residue_field.algebra : algebra R (residue_field R) :=
ideal.quotient.algebra _
lemma residue_field.algebra_map_eq : algebra_map R (residue_field R) = residue R := rfl
variables {R}
namespace residue_field
/-- The map on residue fields induced by a local homomorphism between local rings -/
def map (f : R →+* S) [is_local_ring_hom f] : residue_field R →+* residue_field S :=
ideal.quotient.lift (maximal_ideal R) ((ideal.quotient.mk _).comp f) $
λ a ha,
begin
erw ideal.quotient.eq_zero_iff_mem,
exact map_nonunit f a ha
end
/-- Applying `residue_field.map` to the identity ring homomorphism gives the identity
ring homomorphism. -/
@[simp] lemma map_id :
local_ring.residue_field.map (ring_hom.id R) = ring_hom.id (local_ring.residue_field R) :=
ideal.quotient.ring_hom_ext $ ring_hom.ext $ λx, rfl
/-- The composite of two `residue_field.map`s is the `residue_field.map` of the composite. -/
lemma map_comp (f : T →+* R) (g : R →+* S) [is_local_ring_hom f] [is_local_ring_hom g] :
local_ring.residue_field.map (g.comp f) =
(local_ring.residue_field.map g).comp (local_ring.residue_field.map f) :=
ideal.quotient.ring_hom_ext $ ring_hom.ext $ λx, rfl
lemma map_id_apply (x : residue_field R) : map (ring_hom.id R) x = x :=
fun_like.congr_fun map_id x
@[simp] lemma map_map (f : R →+* S) (g : S →+* T) (x : residue_field R)
[is_local_ring_hom f] [is_local_ring_hom g] :
map g (map f x) = map (g.comp f) x :=
fun_like.congr_fun (map_comp f g).symm x
/-- A ring isomorphism defines an isomorphism of residue fields. -/
@[simps apply]
def map_equiv (f : R ≃+* S) : local_ring.residue_field R ≃+* local_ring.residue_field S :=
{ to_fun := map (f : R →+* S),
inv_fun := map (f.symm : S →+* R),
left_inv := λ x, by simp only [map_map, ring_equiv.symm_comp, map_id, ring_hom.id_apply],
right_inv := λ x, by simp only [map_map, ring_equiv.comp_symm, map_id, ring_hom.id_apply],
map_mul' := ring_hom.map_mul _,
map_add' := ring_hom.map_add _ }
@[simp] lemma map_equiv.symm (f : R ≃+* S) : (map_equiv f).symm = map_equiv f.symm := rfl
@[simp] lemma map_equiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* T) :
map_equiv (e₁.trans e₂) = (map_equiv e₁).trans (map_equiv e₂) :=
ring_equiv.to_ring_hom_injective $ map_comp (e₁ : R →+* S) (e₂ : S →+* T)
@[simp] lemma map_equiv_refl : map_equiv (ring_equiv.refl R) = ring_equiv.refl _ :=
ring_equiv.to_ring_hom_injective map_id
/-- The group homomorphism from `ring_aut R` to `ring_aut k` where `k`
is the residue field of `R`. -/
@[simps] def map_aut : ring_aut R →* ring_aut (local_ring.residue_field R) :=
{ to_fun := map_equiv,
map_mul' := λ e₁ e₂, map_equiv_trans e₂ e₁,
map_one' := map_equiv_refl }
end residue_field
lemma ker_eq_maximal_ideal [field K] (φ : R →+* K) (hφ : function.surjective φ) :
φ.ker = maximal_ideal R :=
local_ring.eq_maximal_ideal $ (ring_hom.ker_is_maximal_of_surjective φ) hφ
lemma is_local_ring_hom_residue :
is_local_ring_hom (local_ring.residue R) :=
begin
constructor,
intros a ha,
by_contra,
erw ideal.quotient.eq_zero_iff_mem.mpr ((local_ring.mem_maximal_ideal _).mpr h) at ha,
exact ha.ne_zero rfl,
end
end
end local_ring
namespace field
variables (K) [field K]
open_locale classical
@[priority 100] -- see Note [lower instance priority]
instance : local_ring K :=
local_ring.of_is_unit_or_is_unit_one_sub_self $ λ a,
if h : a = 0
then or.inr (by rw [h, sub_zero]; exact is_unit_one)
else or.inl $ is_unit.mk0 a h
end field
|
52ddb17070154a0dbf711ba6eaebfa097a3b93fd | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/lake/examples/deps/bar/lakefile.lean | a180b75b235e85d5e3a9d932e067c9de48cac534 | [
"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 | 143 | lean | import Lake
open System Lake DSL
package bar
require foo from ".."/"foo"
lean_lib Bar
@[default_target]
lean_exe bar where
root := `Main
|
95cdc953362c6d5b514edfb601055bf0459e1a08 | 9db059bff49b1090a86ec0050ac6c577eb16ac67 | /src/exercises/algebraic_hierarchy.lean | 1ea6088eaff66bad1fec097efff2089b29807407 | [] | no_license | fpvandoorn/Harvard-tutoring | d64cd75c4c529009ee562c30e9cb245fe237e760 | a8846c08e32cdc7b91a7e28adfa5d9b2810088b0 | refs/heads/master | 1,680,870,428,641 | 1,617,022,194,000 | 1,617,022,194,000 | 330,297,467 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 14,722 | lean | /-
This is a file covering the material on Wednesday afternoon
at LFTCM2020. It's how to build some algebraic structures in Lean
This file has the excercise solutions replaced by `sorry`.
-/
import data.rat.basic -- we'll need the rationals at the end of this file
/-
As a mathematician I essentially always start my Lean files with the following line:
-/
import tactic
/- That gives me access to all Lean's tactics
(see https://leanprover-community.github.io/mathlib_docs/tactics.html)
-/
/-
## The point of this file
The idea of this file is to show how to build in Lean what the computer scientists call
"an algebraic heirarchy", and what mathematicians call "groups, rings, fields, modules etc".
Firstly, we will define groups, and develop a basic interface for groups.
Then we will define rings, fields, modules, vector spaces, and just demonstrate
that they are usable, rather than making a complete interface for all of them.
Let's start with the theory of groups. Unfortunately Lean has groups already,
so we will have to do everything in a namespace
-/
namespace lftcm
/-
... which means that now when we define `group`, it will actually be called `lftcm.group`.
## Notation typeclasses
To make a term of type `has_mul G`, you need to give a map G^2 → G (or
more precisely, a map `has_mul.mul : G → G → G`. Lean's notation `g * h`
is notation for `has_mul.mul g h`. Furthermore, `has_mul` is a class.
In short, this means that if you write `[has_mul G]` then `G` will
magically have a multiplication called `*` (satisfying no axioms).
Similarly `[has_one G]` gives you `has_one.one : G` with notation `1 : G`,
and `[has_inv G]` gives you `has_inv.inv : G → G` with notation `g⁻¹ : G`
## Definition of a group
If `G` is a type, equipped with `* : G^2 → G`, `1 : G` and `⁻¹ : G → G`
then it's a group if it satisfies the group axioms.
-/
-- `group G` is the type of group structures on a type `G`.
-- first we ask for the structure
class group (G : Type) extends has_mul G, has_one G, has_inv G :=
-- and then we ask for the axioms
(mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c))
(one_mul : ∀ (a : G), 1 * a = a)
(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)
/-
Advantages of this approach: axioms look lovely.
Disadvantage: what if I want the group law to be `+`?? I have embedded `has_mul`
in the definition.
Lean's solution: develop a `to_additive` metaprogram which translates all theorems about
`group`s (with group law `*`) to theorems about `add_group`s (with group law `+`). We will
not go into details here.
-/
namespace group
-- let G be a group
variables {G : Type} [group G]
/-
Lemmas about groups are proved in this namespace. We already have some!
All the group axioms are theorems in this namespace. Indeed we have just defined
`group.mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c)`
`group.one_mul : ∀ (a : G), 1 * a = a`
`group.mul_left_inv : ∀ (a : G), a⁻¹ * a = 1`
Because we are in the `group` namespace, we don't need to write `group.`
everywhere.
Let's put some more theorems into the `group` namespace.
We definitely need `mul_one` and `mul_right_inv`, and it's a fun exercise to
get them. Here is a route:
`mul_left_cancel : ∀ (a b c : G), a * b = a * c → b = c`
`mul_eq_of_eq_inv_mul {a x y : G} : x = a⁻¹ * y → a * x = y`
`mul_one (a : G) : a * 1 = a`
`mul_right_inv (a : G) : a * a⁻¹ = 1`
-/
lemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c :=
calc b = 1 * b : by rw one_mul
... = (a⁻¹ * a) * b : by rw mul_left_inv
... = a⁻¹ * (a * b) : by sorry
... = a⁻¹ * (a * c) : by sorry
... = (a⁻¹ * a) * c : by sorry
... = 1 * c : by sorry
... = c : by sorry
lemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=
begin
apply mul_left_cancel a⁻¹,
-- ⊢ a⁻¹ * (a * x) = a⁻¹ * y
sorry
end
-- The same proof
lemma mul_eq_of_eq_inv_mul' {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=
mul_left_cancel a⁻¹ _ _ $ by rwa [←mul_assoc, mul_left_inv, one_mul]
/-
So now we can finally prove `mul_one` and `mul_right_inv`.
But before we start, let's learn a little bit about the simplifier.
## The `simp` tactic -- Lean's simplifier
We have the theorems (axioms) `one_mul g : 1 * g = g` and
`mul_left_inv g : g⁻¹ * g = 1`. Both of these theorems are of
the form `A = B`, with `A` more complicated than `B`. This means
that they are *perfect* theorems for the simplifier. Let's teach
those theorems to the simplifier, by adding the `@[simp]` attribute to them.
An "attribute" is just a tag which we attach to a theorem (or definition).
-/
attribute [simp] one_mul mul_left_inv
/-
Now let's prove `mul_one` using the simplifier. This also a perfect
`simp` lemma, so let's also add the `simp` tag to it.
-/
@[simp] theorem mul_one (a : G) : a * 1 = a :=
begin
apply mul_eq_of_eq_inv_mul,
-- ⊢ 1 = a⁻¹ * a
simp,
end
/-
The simplifier solved `1 = a⁻¹ * a` because it knew `mul_left_inv`.
Feel free to comment out the `attribute [simp] one_mul mul_left_inv` line
above, and observe that the proof breaks.
-/
-- see if you can get the simplifier to do this one too
@[simp] theorem mul_right_inv (a : G) : a * a⁻¹ = 1 :=
begin
sorry
end
-- Now here's a question. Can we train the simplifier to solve the following problem:
--example (a b c d : G) :
-- ((a * b)⁻¹ * a * 1⁻¹⁻¹⁻¹ * b⁻¹ * b * b * 1 * 1⁻¹)⁻¹ = (c⁻¹⁻¹ * d * d⁻¹ * 1⁻¹⁻¹ * c⁻¹⁻¹⁻¹)⁻¹⁻¹ :=
--by simp
-- Remove the --'s and see that it fails. Let's see if we can get it to work.
-- We start with two very natural `simp` lemmas.
@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=
begin
sorry
end
@[simp] lemma inv_inv (a : G) : a⁻¹⁻¹ = a :=
begin
sorry
end
-- Here is a riskier looking `[simp]` lemma.
attribute [simp] mul_assoc -- recall this says (a * b) * c = a * (b * c)
-- The simplifier will now push all brackets to the right, which means
-- that it's worth proving the following two lemmas and tagging
-- them `[simp]`, so that we can still cancel a with a⁻¹ in these situations.
@[simp] lemma inv_mul_cancel_left (a b : G) : a⁻¹ * (a * b) = b :=
begin
sorry
end
@[simp] lemma mul_inv_cancel_left (a b : G) : a * (a⁻¹ * b) = b :=
begin
sorry
end
-- Finally, let's make a `simp` lemma which enables us to
-- reduce all inverses to inverses of variables
@[simp] lemma mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=
begin
sorry
end
/-
If you solved them all -- congratulations!
You have just turned Lean's simplifier into a normalising confluent
rewriting system for groups, following Knuth-Bendix.
https://en.wikipedia.org/wiki/Confluence_(abstract_rewriting)#Motivating_examples
In other words, the simplifier will now put any element of a free group
into a canonical normal form, and can hence solve the word problem
for free groups.
-/
example (a b c d : G) :
((a * b)⁻¹ * a * 1⁻¹⁻¹⁻¹ * b⁻¹ * b * b * 1 * 1⁻¹)⁻¹ = (c⁻¹⁻¹ * d * d⁻¹ * 1⁻¹⁻¹ * c⁻¹⁻¹⁻¹)⁻¹⁻¹ :=
by simp
-- Abstract example of the power of classes: we can define products of groups with instances
instance (G : Type) [group G] (H : Type) [group H] : group (G × H) :=
{ mul := λ k l, (k.1*l.1, k.2*l.2),
one := (1,1),
inv := λ k, (k.1⁻¹, k.2⁻¹),
mul_assoc := begin
intros a b c,
cases a, cases b, cases c,
ext;
simp,
end,
one_mul := begin
sorry
end,
mul_left_inv := begin
sorry
end }
-- the type class inference system now knows that products of groups are groups
example (G H K : Type) [group G] [group H] [group K] : group (G × H × K) :=
by apply_instance
end group
-- let's make a group of order two.
-- First the elements {+1, -1}
inductive mu2
| p1 : mu2
| m1 : mu2
namespace mu2
-- Now let's do some CS stuff:
-- 1) prove it has decidable equality
attribute [derive decidable_eq] mu2
-- 2) prove it is finite
instance : fintype mu2 := ⟨⟨[mu2.p1, mu2.m1], by simp⟩, λ x, by cases x; simp⟩
-- now back to the maths.
-- Define multiplication by doing all cases
def mul : mu2 → mu2 → mu2
| p1 p1 := p1
| p1 m1 := m1
| m1 p1 := m1
| m1 m1 := p1
instance : has_mul mu2 := ⟨mul⟩
-- identity
def one : mu2 := p1
-- notation
instance : has_one mu2 := ⟨one⟩
-- inverse
def inv : mu2 → mu2 := id
-- notation
instance : has_inv mu2 := ⟨inv⟩
-- currently we have notation but no axioms
example : p1 * m1 * m1 = p1⁻¹ * p1 := rfl -- all true by definition
-- now let's make it a group
instance : group mu2 :=
begin
-- first define the structure
refine_struct { mul := mul, one := one, inv := inv },
-- now we have three goals (the axioms)
all_goals {exact dec_trivial}
end
end mu2
-- Now let's build rings and modules and stuff (via monoids and add_comm_groups)
-- a monoid is a group without inverses
class monoid (M : Type) extends has_mul M, has_one M :=
(mul_assoc : ∀ (a b c : M), a * b * c = a * (b * c))
(one_mul : ∀ (a : M), 1 * a = a)
(mul_one : ∀ (a : M), a * 1 = a)
-- additive commutative groups from first principles
class add_comm_group (A : Type) extends has_add A, has_zero A, has_neg A :=
(add_assoc : ∀ (a b c : A), a + b + c = a + (b + c))
(zero_add : ∀ (a : A), 0 + a = a)
(add_left_neg : ∀ (a : A), -a + a = 0)
(add_comm : ∀ a b : A, a + b = b + a)
-- Notation for subtraction is handy to have; define a - b to be a + (-b)
instance (A : Type) [add_comm_group A] : has_sub A := ⟨λ a b, a + -b⟩
-- rings are additive abelian groups and multiplicative monoids,
-- with distributivity
class ring (R : Type) extends monoid R, add_comm_group R :=
(mul_add : ∀ (a b c : R), a * (b + c) = a * b + a * c)
(add_mul : ∀ (a b c : R), (a + b) * c = a * c + b * c)
-- for commutative rings, add commutativity of multiplication
class comm_ring (R : Type) extends ring R :=
(mul_comm : ∀ a b : R, a * b = b * a)
/-- Typeclass for types with a scalar multiplication operation, denoted `•` (`\bu`) -/
class has_scalar (R : Type) (M : Type) := (smul : R → M → M)
infixr ` • `:73 := has_scalar.smul
-- modules for a ring
class module (R : Type) [ring R] (M : Type) [add_comm_group M]
extends has_scalar R M :=
(smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y)
(add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
(mul_smul : ∀ (r s : R) (x : M), (r * s) • x = r • s • x)
(one_smul : ∀ x : M, (1 : R) • x = x)
-- for fields we let ⁻¹ be defined on the entire field, and demand 0⁻¹ = 0
-- and that a⁻¹ * a = 1 for non-zero a. This is merely for convenience;
-- one can easily check that it's mathematically equivalent to the usual
-- definition of a field.
class field (K : Type) extends comm_ring K, has_inv K :=
(zero_ne_one : (0 : K) ≠ 1)
(mul_inv_cancel : ∀ {a : K}, a ≠ 0 → a * a⁻¹ = 1)
(inv_zero : (0 : K)⁻¹ = 0)
-- the type of vector spaces
def vector_space (K : Type) [field K] (V : Type) [add_comm_group V] := module K V
/-
Exercise for the reader: define manifolds, schemes, perfectoid spaces in Lean.
All have been done! As you can see, it is clearly *feasible*, although it does
sometimes take time to get it right. It is all very much work in progress.
The extraordinary thing is that although these computer theorem
provers have been around for about 50 years, there has never been a serious
effort to make the standard definitions used all over modern mathematics in
one of them, and this is why these systems are rarely used in mathematics departments.
Changing this is one of the goals of the Leanprover community.
-/
/-
Let's check that we can make the rational numbers into a field. Of course
they are already a field in Lean, but remember that when we say `field`
below, we mean our just-defined structure `lftcm.field`.
-/
-- the rationals are a field (easy because all the work is done in the import)
instance : field ℚ :=
{ mul := (*),
one := 1,
mul_assoc := rat.mul_assoc,
one_mul := rat.one_mul,
mul_one := rat.mul_one,
add := (+),
zero := 0,
neg := has_neg.neg, -- no () trickery for unary operators
add_assoc := rat.add_assoc,
zero_add := rat.zero_add,
add_left_neg := rat.add_left_neg,
add_comm := rat.add_comm,
mul_add := rat.mul_add,
add_mul := rat.add_mul,
mul_comm := rat.mul_comm,
inv := has_inv.inv, -- see neg
zero_ne_one := rat.zero_ne_one,
mul_inv_cancel := rat.mul_inv_cancel,
inv_zero := inv_zero -- I don't know why rat.inv_zero was never explicitly defined
}
/-
Below is evidence that we can prove basic theorems about these structures.
Note however that it is a *complete pain* because we are *re-implementing*
everything; `add_comm` defaults to Lean's version for Lean's `add_comm_group`s, so we
have to explicitly write `add_comm_group.add_comm` to use our own version.
The mathlib versions of these proofs are less ugly.
-/
variables {A : Type} [add_comm_group A]
lemma add_comm_group.add_left_cancel (a b c : A) (Habac : a + b = a + c) : b = c :=
begin
rw ←add_comm_group.zero_add b,
rw ←add_comm_group.add_left_neg a,
rw add_comm_group.add_assoc,
rw Habac,
rw ←add_comm_group.add_assoc,
rw add_comm_group.add_left_neg,
rw add_comm_group.zero_add,
end
lemma add_comm_group.add_right_neg (a : A) : a + -a = 0 :=
begin
rw add_comm_group.add_comm,
rw add_comm_group.add_left_neg,
end
lemma add_comm_group.sub_eq_add_neg (a b : A) :
a - b = a + -b :=
begin
-- this is just our definition of subtraction
refl
end
lemma add_comm_group.sub_self (a : A) : a - a = 0 :=
begin
rw add_comm_group.sub_eq_add_neg,
rw add_comm_group.add_comm,
rw add_comm_group.add_left_neg,
end
lemma add_comm_group.neg_eq_of_add_eq_zero (a b : A) (h : a + b = 0) : -a = b :=
begin
apply add_comm_group.add_left_cancel a,
rw h,
rw add_comm_group.add_right_neg,
end
lemma add_comm_group.add_zero (a : A) : a + 0 = a :=
begin
rw add_comm_group.add_comm,
rw add_comm_group.zero_add,
end
variables {R : Type} [ring R]
lemma ring.mul_zero (r : R) : r * 0 = 0 :=
begin
apply add_comm_group.add_left_cancel (r * 0),
rw ←ring.mul_add,
rw add_comm_group.add_zero,
rw add_comm_group.add_zero,
end
lemma ring.mul_neg (a b : R) : a * -b = -(a * b) :=
begin
sorry
end
lemma ring.mul_sub (R : Type) [comm_ring R] (r a b : R) : r * (a - b) = r * a - r * b :=
begin
sorry
end
lemma comm_ring.sub_mul (R : Type) [comm_ring R] (r a b : R) : (a - b) * r = a * r - b * r :=
begin
sorry
end
-- etc etc, for thousands of lines of mathlib, which develop the interface
-- abelian groups, rings, commutative rings, modules, fields, vector spaces etc.
end lftcm
|
36e3ebe163a93921a2a565696ac5aaf5c37911bd | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /counterexamples/char_p_zero_ne_char_zero.lean | a567d155f59ec4b4fb80e0b3b3911d2b4374f906 | [
"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,171 | lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Eric Wieser
-/
import algebra.char_p.basic
/-! # `char_p R 0` and `char_zero R` need not coincide for semirings
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
For rings, the two notions coincide.
In fact, `char_p.of_char_zero` shows that `char_zero R` implies `char_p R 0` for any `char_zero`
`add_monoid R` with `1`.
The reverse implication holds for any `add_left_cancel_monoid R` with `1`, by `char_p_to_char_zero`.
This file shows that there are semiring `R` for which `char_p R 0` holds and `char_zero R` does not.
The example is `{0, 1}` with saturating addition.
-/
namespace counterexample
@[simp] lemma add_one_eq_one (x : with_zero unit) : x + 1 = 1 :=
with_zero.cases_on x (by refl) (λ h, by refl)
lemma with_zero_unit_char_p_zero : char_p (with_zero unit) 0 :=
⟨λ x, by cases x; simp⟩
lemma with_zero_unit_not_char_zero : ¬ char_zero (with_zero unit) :=
λ ⟨h⟩, h.ne (by simp : 1 + 1 ≠ 0 + 1) (by simp)
end counterexample
|
972d6f5fe1829c1823084fce4dd4ce8b9a207a1a | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /stage0/src/Init/Control/StateRef.lean | 38fd9d21159f085ded41b295aafccbde96f05a7a | [
"Apache-2.0"
] | permissive | banksonian/lean4 | 3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc | 78da6b3aa2840693eea354a41e89fc5b212a5011 | refs/heads/master | 1,673,703,624,165 | 1,605,123,551,000 | 1,605,123,551,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,521 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
The State monad transformer using IO references.
-/
prelude
import Init.System.IO
import Init.Control.State
def StateRefT' (ω : Type) (σ : Type) (m : Type → Type) (α : Type) : Type := ReaderT (ST.Ref ω σ) m α
/- Recall that `StateRefT` is a macro that infers `ω` from the `m`. -/
@[inline] def StateRefT'.run {ω σ : Type} {m : Type → Type} [Monad m] [MonadLiftT (ST ω) m] {α : Type} (x : StateRefT' ω σ m α) (s : σ) : m (α × σ) := do
let ref ← ST.mkRef s
let a ← x ref
let s ← ref.get
pure (a, s)
@[inline] def StateRefT'.run' {ω σ : Type} {m : Type → Type} [Monad m] [MonadLiftT (ST ω) m] {α : Type} (x : StateRefT' ω σ m α) (s : σ) : m α := do
let (a, _) ← x.run s
pure a
namespace StateRefT'
variables {ω σ : Type} {m : Type → Type} {α : Type}
@[inline] protected def lift (x : m α) : StateRefT' ω σ m α :=
fun _ => x
instance [Monad m] : Monad (StateRefT' ω σ m) := inferInstanceAs (Monad (ReaderT _ _))
instance : MonadLift m (StateRefT' ω σ m) := ⟨StateRefT'.lift⟩
instance [Monad m] [MonadIO m] : MonadIO (StateRefT' ω σ m) := inferInstanceAs (MonadIO (ReaderT _ _))
instance (σ m) [Monad m] : MonadFunctor m (StateRefT' ω σ m) := inferInstanceAs (MonadFunctor m (ReaderT _ _))
@[inline] protected def get [Monad m] [MonadLiftT (ST ω) m] : StateRefT' ω σ m σ :=
fun ref => ref.get
@[inline] protected def set [Monad m] [MonadLiftT (ST ω) m] (s : σ) : StateRefT' ω σ m PUnit :=
fun ref => ref.set s
@[inline] protected def modifyGet [Monad m] [MonadLiftT (ST ω) m] (f : σ → α × σ) : StateRefT' ω σ m α :=
fun ref => ref.modifyGet f
instance [MonadLiftT (ST ω) m] [Monad m] : MonadStateOf σ (StateRefT' ω σ m) := {
get := StateRefT'.get,
set := StateRefT'.set,
modifyGet := StateRefT'.modifyGet
}
instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (StateRefT' ω σ m) := {
throw := StateRefT'.lift ∘ throwThe ε,
tryCatch := fun x c s => tryCatchThe ε (x s) (fun e => c e s)
}
end StateRefT'
instance (ω σ : Type) (m : Type → Type) : MonadControl m (StateRefT' ω σ m) :=
inferInstanceAs (MonadControl m (ReaderT _ _))
instance {m : Type → Type} {ω σ : Type} [MonadFinally m] [Monad m] : MonadFinally (StateRefT' ω σ m) :=
inferInstanceAs (MonadFinally (ReaderT _ _))
|
8a87f67569dedd2ee53b2555e0f5bdf98a088fbc | d29d82a0af640c937e499f6be79fc552eae0aa13 | /src/data/nat/totient.lean | 0e306e851b514da4226eae69f1c8fb285ec29962 | [
"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 | 5,650 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import algebra.big_operators.basic
import data.zmod.basic
/-!
# Euler's totient function
This file defines [Euler's totient function][https://en.wikipedia.org/wiki/Euler's_totient_function]
`nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`.
We prove the divisor sum formula, namely that `n` equals `φ` summed over the divisors of `n`. See
`sum_totient`.
-/
open finset
open_locale big_operators
namespace nat
/-- Euler's totient function. This counts the number of naturals strictly less than `n` which are
coprime with `n`. -/
def totient (n : ℕ) : ℕ := ((range n).filter (nat.coprime n)).card
localized "notation `φ` := nat.totient" in nat
@[simp] theorem totient_zero : φ 0 = 0 := rfl
lemma totient_le (n : ℕ) : φ n ≤ n :=
calc totient n ≤ (range n).card : card_filter_le _ _
... = n : card_range _
lemma totient_pos : ∀ {n : ℕ}, 0 < n → 0 < φ n
| 0 := dec_trivial
| 1 := by simp [totient]
| (n+2) := λ h, card_pos.2 ⟨1, mem_filter.2 ⟨mem_range.2 dec_trivial, coprime_one_right _⟩⟩
open zmod
@[simp] lemma _root_.zmod.card_units_eq_totient (n : ℕ) [fact (0 < n)] :
fintype.card (units (zmod n)) = φ n :=
calc fintype.card (units (zmod n)) = fintype.card {x : zmod n // x.val.coprime n} :
fintype.card_congr zmod.units_equiv_coprime
... = φ n :
begin
apply finset.card_congr (λ (a : {x : zmod n // x.val.coprime n}) _, a.1.val),
{ intro a, simp [(a : zmod n).val_lt, a.prop.symm] {contextual := tt} },
{ intros _ _ _ _ h, rw subtype.ext_iff_val, apply val_injective, exact h, },
{ intros b hb,
rw [finset.mem_filter, finset.mem_range] at hb,
refine ⟨⟨b, _⟩, finset.mem_univ _, _⟩,
{ let u := unit_of_coprime b hb.2.symm,
exact val_coe_unit_coprime u },
{ show zmod.val (b : zmod n) = b,
rw [val_nat_cast, nat.mod_eq_of_lt hb.1], } }
end
lemma totient_mul {m n : ℕ} (h : m.coprime n) : φ (m * n) = φ m * φ n :=
if hmn0 : m * n = 0
then by cases nat.mul_eq_zero.1 hmn0 with h h;
simp only [totient_zero, mul_zero, zero_mul, h]
else
begin
haveI : fact (0 < (m * n)) := ⟨nat.pos_of_ne_zero hmn0⟩,
haveI : fact (0 < m) := ⟨nat.pos_of_ne_zero $ left_ne_zero_of_mul hmn0⟩,
haveI : fact (0 < n) := ⟨nat.pos_of_ne_zero $ right_ne_zero_of_mul hmn0⟩,
rw [← zmod.card_units_eq_totient, ← zmod.card_units_eq_totient,
← zmod.card_units_eq_totient,
fintype.card_congr (units.map_equiv (chinese_remainder h).to_mul_equiv).to_equiv,
fintype.card_congr (@mul_equiv.prod_units (zmod m) (zmod n) _ _).to_equiv,
fintype.card_prod]
end
lemma sum_totient (n : ℕ) : ∑ m in (range n.succ).filter (∣ n), φ m = n :=
if hn0 : n = 0 then by simp [hn0]
else
calc ∑ m in (range n.succ).filter (∣ n), φ m
= ∑ d in (range n.succ).filter (∣ n), ((range (n / d)).filter (λ m, gcd (n / d) m = 1)).card :
eq.symm $ sum_bij (λ d _, n / d)
(λ d hd, mem_filter.2 ⟨mem_range.2 $ lt_succ_of_le $ nat.div_le_self _ _,
by conv {to_rhs, rw ← nat.mul_div_cancel' (mem_filter.1 hd).2}; simp⟩)
(λ _ _, rfl)
(λ a b ha hb h,
have ha : a * (n / a) = n, from nat.mul_div_cancel' (mem_filter.1 ha).2,
have 0 < (n / a), from nat.pos_of_ne_zero (λ h, by simp [*, lt_irrefl] at *),
by rw [← nat.mul_left_inj this, ha, h, nat.mul_div_cancel' (mem_filter.1 hb).2])
(λ b hb,
have hb : b < n.succ ∧ b ∣ n, by simpa [-range_succ] using hb,
have hbn : (n / b) ∣ n, from ⟨b, by rw nat.div_mul_cancel hb.2⟩,
have hnb0 : (n / b) ≠ 0, from λ h, by simpa [h, ne.symm hn0] using nat.div_mul_cancel hbn,
⟨n / b, mem_filter.2 ⟨mem_range.2 $ lt_succ_of_le $ nat.div_le_self _ _, hbn⟩,
by rw [← nat.mul_left_inj (nat.pos_of_ne_zero hnb0),
nat.mul_div_cancel' hb.2, nat.div_mul_cancel hbn]⟩)
... = ∑ d in (range n.succ).filter (∣ n), ((range n).filter (λ m, gcd n m = d)).card :
sum_congr rfl (λ d hd,
have hd : d ∣ n, from (mem_filter.1 hd).2,
have hd0 : 0 < d, from nat.pos_of_ne_zero (λ h, hn0 (eq_zero_of_zero_dvd $ h ▸ hd)),
card_congr (λ m hm, d * m)
(λ m hm, have hm : m < n / d ∧ gcd (n / d) m = 1, by simpa using hm,
mem_filter.2 ⟨mem_range.2 $ nat.mul_div_cancel' hd ▸
(mul_lt_mul_left hd0).2 hm.1,
by rw [← nat.mul_div_cancel' hd, gcd_mul_left, hm.2, mul_one]⟩)
(λ a b ha hb h, (nat.mul_right_inj hd0).1 h)
(λ b hb, have hb : b < n ∧ gcd n b = d, by simpa using hb,
⟨b / d, mem_filter.2 ⟨mem_range.2
((mul_lt_mul_left (show 0 < d, from hb.2 ▸ hb.2.symm ▸ hd0)).1
(by rw [← hb.2, nat.mul_div_cancel' (gcd_dvd_left _ _),
nat.mul_div_cancel' (gcd_dvd_right _ _)]; exact hb.1)),
hb.2 ▸ coprime_div_gcd_div_gcd (hb.2.symm ▸ hd0)⟩,
hb.2 ▸ nat.mul_div_cancel' (gcd_dvd_right _ _)⟩))
... = ((filter (∣ n) (range n.succ)).bUnion (λ d, (range n).filter (λ m, gcd n m = d))).card :
(card_bUnion (by intros; apply disjoint_filter.2; cc)).symm
... = (range n).card :
congr_arg card (finset.ext (λ m, ⟨by finish,
λ hm, have h : m < n, from mem_range.1 hm,
mem_bUnion.2 ⟨gcd n m, mem_filter.2
⟨mem_range.2 (lt_succ_of_le (le_of_dvd (lt_of_le_of_lt (zero_le _) h)
(gcd_dvd_left _ _))), gcd_dvd_left _ _⟩, mem_filter.2 ⟨hm, rfl⟩⟩⟩))
... = n : card_range _
end nat
|
e760b5f7d6a4fe6bf2153abd2ecd06449d302d6a | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/coe11.lean | 734f7c3c7d3b106eb7dc63172bb9a2de7fcf1a4b | [
"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 | 970 | lean | import algebra.category.basic
open category
inductive my_functor {obC obD : Type} (C : category obC) (D : category obD) : Type :=
mk : Π (obF : obC → obD) (homF : Π{A B : obC}, hom A B → hom (obF A) (obF B)),
(Π {A : obC}, homF (ID A) = ID (obF A)) →
(Π {A B C : obC} {f : hom A B} {g : hom B C}, homF (g ∘ f) = homF g ∘ homF f) →
my_functor C D
definition my_object [coercion] {obC obD : Type} {C : category obC} {D : category obD} (F : my_functor C D) : obC → obD :=
my_functor.rec (λ obF homF Hid Hcomp, obF) F
definition my_homphism [coercion] {obC obD : Type} {C : category obC} {D : category obD} (F : my_functor C D) :
Π{A B : obC}, hom A B → hom (my_object F A) (my_object F B) :=
my_functor.rec (λ obF homF Hid Hcomp, homF) F
constants obC obD : Type
constants a b : obC
constant C : category obC
attribute C [instance]
constant D : category obD
constant F : my_functor C D
constant m : hom a b
check F a
check F m
|
92fdcc062e821175f211c9e6d899c9c1664f0e8d | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /tests/lean/ppSyntax.lean | 76c4d66c4649e50b5101a5fd178bea9d893eccb1 | [
"Apache-2.0"
] | permissive | banksonian/lean4 | 3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc | 78da6b3aa2840693eea354a41e89fc5b212a5011 | refs/heads/master | 1,673,703,624,165 | 1,605,123,551,000 | 1,605,123,551,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 175 | lean | import Lean
open Lean
def test (stx : Unhygienic Syntax) : MetaM Unit :=
PrettyPrinter.ppTerm stx.run >>= IO.println
-- test imported `ParserDescr`
#eval test `(s!"hi!")
|
0183a5e0c755bf1163fd6192baa61c36fc741a12 | 1a2aed113dcb5f1c07ae98040953fba5e6563624 | /lean_root/src/tao_ch5.lean | 1895044d510ce2f6d765d14b22e399ce39a8a536 | [
"Apache-2.0"
] | permissive | kevindoran/lean | 61d9fb90363b04587624036136482b29e3c16ebd | 77e755095a31e3a214010eb48a61e48d65dfdec9 | refs/heads/master | 1,670,372,072,769 | 1,598,920,365,000 | 1,598,920,365,000 | 264,824,992 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 554 | lean |
import order.bounds
import data.real.basic
-- Consider reworking to be congruent with mathlib's bounds or ereals.
-- https://leanprover-community.github.io/mathlib_docs/order/bounds.html#lower_bounds
def has_infinite_sup (X : set ℝ) : Prop :=
X.nonempty ∧ ¬ (upper_bounds X).nonempty
def has_infinite_inf (X : set ℝ) : Prop :=
X.nonempty ∧ ¬ (lower_bounds X).nonempty
def has_finite_sup (X : set ℝ) : Prop :=
X.nonempty ∧ (upper_bounds X).nonempty
def has_finite_inf (X : set ℝ) : Prop :=
X.nonempty ∧ (lower_bounds X).nonempty
|
e63b3c9a7ec3bafc5aafdf3a9b5a18faf12b75c7 | ad31a621913db8baff8c0518c10b76ef58a178c0 | /src/3_nat_equiv_nat_sq.lean | b60428ef9e9513ed9bc076c644383ff81e39dde3 | [] | no_license | shingtaklam1324/lean_blog | 0a881d38273bf8f45a8c837ebc131a2c529884fb | 730670bb1066d081a4c6a1494badb5f4be27cdbc | refs/heads/master | 1,668,249,864,724 | 1,592,876,934,000 | 1,592,876,934,000 | 274,282,996 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,458 | lean | import data.equiv.basic
data.nat.prime
data.nat.multiplicity
tactic
set_theory.schroeder_bernstein
open function nat
def to_fun : ℕ → ℕ × ℕ := λ x, (x,0)
def inv_fun' : ℕ × ℕ → ℕ := λ ⟨x,y⟩, 2^x * 3^y
lemma injective_to_fun : injective to_fun :=
begin
intros a b h,
unfold to_fun at h,
rw prod.eq_iff_fst_eq_snd_eq at h,
exact h.1
end
lemma injective_inv_fun_aux (p q x y : ℕ) (hp : nat.prime p) (hpq : ¬ p ∣ q) :
multiplicity p (p^x * q^y) = x :=
calc
multiplicity p (p^x * q^y)
= multiplicity p (p^x) + multiplicity p (q^y) : by rw prime.multiplicity_mul hp
... = (x : enat) + multiplicity p (q^y) : by rw prime.multiplicity_pow_self hp
... = (x : enat) + y •ℕ multiplicity p q : by rw prime.multiplicity_pow hp
... = (x : enat) + y •ℕ 0 : by rw multiplicity.multiplicity_eq_zero_of_not_dvd hpq
... = (x : enat) + 0 : by rw nsmul_zero
... = (x : enat) : by rw add_zero
lemma injective_inv_fun : injective inv_fun' :=
begin
rintros ⟨x1,y1⟩ ⟨x2,y2⟩ h,
unfold inv_fun' at h,
have hx : x1 = x2,
{ have h1 : multiplicity 2 (2^x1 * 3^y1) = x1,
{ exact injective_inv_fun_aux 2 3 x1 y1 prime_two (by norm_num) },
have h2 : multiplicity 2 (2^x1 * 3^y1) = x2,
{ rw h,
exact injective_inv_fun_aux 2 3 x2 y2 prime_two (by norm_num) },
rwa [h1, enat.coe_inj] at h2, },
have hy : y1 = y2,
{ have h1 : multiplicity 3 (2^x1 * 3^y1) = y1,
{ rw mul_comm,
exact injective_inv_fun_aux 3 2 y1 x1 prime_three (by norm_num) },
have h2 : multiplicity 3 (2^x1 * 3^y1) = y2,
{ rw [h, mul_comm],
exact injective_inv_fun_aux 3 2 y2 x2 prime_three (by norm_num) },
rwa [h1, enat.coe_inj] at h2 },
rw [hx, hy],
end
def sbf := embedding.schroeder_bernstein injective_to_fun injective_inv_fun
#check sbf -- sbf : ∃ (h : ℕ → ℕ × ℕ), bijective h
noncomputable def f := classical.some sbf
def hf := classical.some_spec sbf
def inv_x := bijective_iff_has_inverse.1 hf
noncomputable def invf := classical.some inv_x
def h_invf := classical.some_spec inv_x
noncomputable def nat_equiv_nat_sq :
ℕ ≃ (ℕ × ℕ) :=
{ to_fun := f,
inv_fun := invf,
left_inv := begin
rw [f, invf],
exact h_invf.1,
end,
right_inv := begin
rw [f, invf],
exact h_invf.2,
end }
|
93f7753de83a5f4fce328dcbf5f180013a38452f | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /08_Building_Theories_and_Proofs.org.10.lean | f9f1dec4e0a904b2967ae2901ff56da0c97259c8 | [] | 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 | 523 | lean | import standard
import data.examples.vector
open vector nat
-- BEGIN
variables (P : Π (n m : ℕ) (v : vector bool n) (w : vector bool m), Type)
(p : Π (n m : ℕ) (v : vector bool n) (w : vector bool m), P n m v w)
(n m : ℕ) (v : vector bool n) (w : vector bool m)
set_option pp.metavar_args false
eval (!p : P n m v w) -- p n m v w
eval (!p : P n n v v) -- p n n v v
check !p -- p ?n ?m ?v ?w : P ?n ?m ?v ?w
eval (!P v w : Type) -- P n m v w
eval (!p : !P w v) -- p m n w v
-- END
|
2e3530188b722b8716e8eea90b89776ea26fa9d8 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /stage0/src/Lean/Util/ReplaceLevel.lean | 0b892e18f57a772cc402771e96f9a4f3c51f63a4 | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,421 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Expr
namespace Lean
namespace Level
partial def replace (f? : Level → Option Level) (u : Level) : Level :=
match f? u with
| some v => v
| none => match u with
| max v₁ v₂ _ => mkLevelMax' (replace f? v₁) (replace f? v₂)
| imax v₁ v₂ _ => mkLevelIMax' (replace f? v₁) (replace f? v₂)
| succ v _ => mkLevelSucc (replace f? v)
| _ => u
end Level
namespace Expr
namespace ReplaceLevelImpl
abbrev cacheSize : USize := 8192
structure State :=
(keys : Array Expr) -- Remark: our "unsafe" implementation relies on the fact that `()` is not a valid Expr
(results : Array Expr)
abbrev ReplaceM := StateM State
@[inline] unsafe def cache (i : USize) (key : Expr) (result : Expr) : ReplaceM Expr := do
modify fun s => { keys := s.keys.uset i key lcProof, results := s.results.uset i result lcProof };
pure result
@[specialize] unsafe def replaceUnsafeM (f? : Level → Option Level) (size : USize) (e : Expr) : ReplaceM Expr := do
let rec visit (e : Expr) := do
let c ← get
let h := ptrAddrUnsafe e
let i := h % size
if ptrAddrUnsafe (c.keys.uget i lcProof) == h then
pure <| c.results.uget i lcProof
else match e with
| Expr.forallE _ d b _ => cache i e <| e.updateForallE! (← visit d) (← visit b)
| Expr.lam _ d b _ => cache i e <| e.updateLambdaE! (← visit d) (← visit b)
| Expr.mdata _ b _ => cache i e <| e.updateMData! (← visit b)
| Expr.letE _ t v b _ => cache i e <| e.updateLet! (← visit t) (← visit v) (← visit b)
| Expr.app f a _ => cache i e <| e.updateApp! (← visit f) (← visit a)
| Expr.proj _ _ b _ => cache i e <| e.updateProj! (← visit b)
| Expr.sort u _ => cache i e <| e.updateSort! (u.replace f?)
| Expr.const n us _ => cache i e <| e.updateConst! (us.map (Level.replace f?))
| e => pure e
visit e
unsafe def initCache : State :=
{ keys := mkArray cacheSize.toNat (cast lcProof ()), -- `()` is not a valid `Expr`
results := mkArray cacheSize.toNat arbitrary }
@[inline] unsafe def replaceUnsafe (f? : Level → Option Level) (e : Expr) : Expr :=
(replaceUnsafeM f? cacheSize e).run' initCache
end ReplaceLevelImpl
@[implementedBy ReplaceLevelImpl.replaceUnsafe]
partial def replaceLevel (f? : Level → Option Level) : Expr → Expr
| e@(Expr.forallE _ d b _) => let d := replaceLevel f? d; let b := replaceLevel f? b; e.updateForallE! d b
| e@(Expr.lam _ d b _) => let d := replaceLevel f? d; let b := replaceLevel f? b; e.updateLambdaE! d b
| e@(Expr.mdata _ b _) => let b := replaceLevel f? b; e.updateMData! b
| e@(Expr.letE _ t v b _) => let t := replaceLevel f? t; let v := replaceLevel f? v; let b := replaceLevel f? b; e.updateLet! t v b
| e@(Expr.app f a _) => let f := replaceLevel f? f; let a := replaceLevel f? a; e.updateApp! f a
| e@(Expr.proj _ _ b _) => let b := replaceLevel f? b; e.updateProj! b
| e@(Expr.sort u _) => e.updateSort! (u.replace f?)
| e@(Expr.const n us _) => e.updateConst! (us.map (Level.replace f?))
| e => e
end Expr
end Lean
|
cf7ee9db4926f87fae87f006a5c01d69e2f389e2 | 66a6486e19b71391cc438afee5f081a4257564ec | /algebra/graded.hlean | d4f3f8536ed55e2b0ab30f2bca60e824d6e2d065 | [
"Apache-2.0"
] | permissive | spiceghello/Spectral | c8ccd1e32d4b6a9132ccee20fcba44b477cd0331 | 20023aa3de27c22ab9f9b4a177f5a1efdec2b19f | refs/heads/master | 1,611,263,374,078 | 1,523,349,717,000 | 1,523,349,717,000 | 92,312,239 | 0 | 0 | null | 1,495,642,470,000 | 1,495,642,470,000 | null | UTF-8 | Lean | false | false | 28,448 | hlean | /- Graded (left-) R-modules for a ring R. -/
-- Author: Floris van Doorn
import .left_module .direct_sum .submodule --..heq
open is_trunc algebra eq left_module pointed function equiv is_equiv prod group sigma sigma.ops nat
trunc_index property
namespace left_module
definition graded [reducible] (str : Type) (I : Type) : Type := I → str
definition graded_module [reducible] (R : Ring) : Type → Type := graded (LeftModule R)
-- TODO: We can (probably) make I a type everywhere
variables {R : Ring} {I : Set} {M M₁ M₂ M₃ : graded_module R I}
/-
morphisms between graded modules.
The definition is unconventional in two ways:
(1) The degree is determined by an endofunction instead of a element of I (and in this case we
don't need to assume that I is a group). The "standard" degree i corresponds to the endofunction
which is addition with i on the right. However, this is more flexible. For example, the
composition of two graded module homomorphisms φ₂ and φ₁ with degrees i₂ and i₁ has type
M₁ i → M₂ ((i + i₁) + i₂).
However, a homomorphism with degree i₁ + i₂ must have type
M₁ i → M₂ (i + (i₁ + i₂)),
which means that we need to insert a transport. With endofunctions this is not a problem:
λi, (i + i₁) + i₂
is a perfectly fine degree of a map
(2) Since we cannot eliminate all possible transports, we don't define a homomorphism as function
M₁ i →lm M₂ (i + deg f) or M₁ i →lm M₂ (deg f i)
but as a function taking a path as argument. Specifically, for every path
deg f i = j
we get a function M₁ i → M₂ j.
(3) Note: we do assume that I is a set. This is not strictly necessary, but it simplifies things
-/
definition graded_hom_of_deg (d : I ≃ I) (M₁ M₂ : graded_module R I) : Type :=
Π⦃i j : I⦄ (p : d i = j), M₁ i →lm M₂ j
definition gmd_constant [constructor] (d : I ≃ I) (M₁ M₂ : graded_module R I) : graded_hom_of_deg d M₁ M₂ :=
λi j p, lm_constant (M₁ i) (M₂ j)
definition gmd0 [constructor] {d : I ≃ I} {M₁ M₂ : graded_module R I} : graded_hom_of_deg d M₁ M₂ :=
gmd_constant d M₁ M₂
structure graded_hom (M₁ M₂ : graded_module R I) : Type :=
mk' :: (d : I ≃ I)
(fn' : graded_hom_of_deg d M₁ M₂)
notation M₁ ` →gm ` M₂ := graded_hom M₁ M₂
abbreviation deg [unfold 5] := @graded_hom.d
postfix ` ↘`:max := graded_hom.fn' -- there is probably a better character for this? Maybe ↷?
definition graded_hom_fn [reducible] [unfold 5] [coercion] (f : M₁ →gm M₂) (i : I) : M₁ i →lm M₂ (deg f i) :=
f ↘ idp
definition graded_hom_fn_out [reducible] [unfold 5] (f : M₁ →gm M₂) (i : I) : M₁ ((deg f)⁻¹ i) →lm M₂ i :=
f ↘ (to_right_inv (deg f) i)
infix ` ← `:max := graded_hom_fn_out -- todo: change notation
-- definition graded_hom_fn_out_rec (f : M₁ →gm M₂)
-- (P : Π{i j} (p : deg f i = j) (m : M₁ i) (n : M₂ j), Type)
-- (H : Πi m, P (right_inv (deg f) i) m (f ← i m)) {i j : I}
-- (p : deg f i = j) (m : M₁ i) (n : M₂ j) : P p m (f ↘ p m) :=
-- begin
-- revert i j p m n, refine equiv_rect (deg f)⁻¹ᵉ _ _, intro i,
-- refine eq.rec_to (right_inv (deg f) i) _,
-- intro m n, exact H i m
-- end
-- definition graded_hom_fn_rec (f : M₁ →gm M₂)
-- {P : Π{i j} (p : deg f i = j) (m : M₁ i) (n : M₂ j), Type}
-- (H : Πi m, P idp m (f i m)) ⦃i j : I⦄
-- (p : deg f i = j) (m : M₁ i) : P p m (f ↘ p m) :=
-- begin
-- induction p, apply H
-- end
-- definition graded_hom_fn_out_rec (f : M₁ →gm M₂)
-- {P : Π{i j} (p : deg f i = j) (m : M₁ i) (n : M₂ j), Type}
-- (H : Πi m, P idp m (f i m)) ⦃i : I⦄ (m : M₁ ((deg f)⁻¹ᵉ i)) :
-- P (right_inv (deg f) i) m (f ← i m) :=
-- graded_hom_fn_rec f H (right_inv (deg f) i) m
-- definition graded_hom_fn_out_rec_simple (f : M₁ →gm M₂)
-- {P : Π{j} (n : M₂ j), Type}
-- (H : Πi m, P (f i m)) ⦃i : I⦄ (m : M₁ ((deg f)⁻¹ᵉ i)) :
-- P (f ← i m) :=
-- graded_hom_fn_out_rec f H m
definition graded_hom.mk [constructor] (d : I ≃ I)
(fn : Πi, M₁ i →lm M₂ (d i)) : M₁ →gm M₂ :=
graded_hom.mk' d (λi j p, homomorphism_of_eq (ap M₂ p) ∘lm fn i)
definition graded_hom.mk_out [constructor] (d : I ≃ I)
(fn : Πi, M₁ (d⁻¹ i) →lm M₂ i) : M₁ →gm M₂ :=
graded_hom.mk' d (λi j p, fn j ∘lm homomorphism_of_eq (ap M₁ (eq_inv_of_eq p)))
definition graded_hom.mk_out' [constructor] (d : I ≃ I)
(fn : Πi, M₁ (d i) →lm M₂ i) : M₁ →gm M₂ :=
graded_hom.mk' d⁻¹ᵉ (λi j p, fn j ∘lm homomorphism_of_eq (ap M₁ (eq_inv_of_eq p)))
definition graded_hom.mk_out_in [constructor] (d₁ : I ≃ I) (d₂ : I ≃ I)
(fn : Πi, M₁ (d₁ i) →lm M₂ (d₂ i)) : M₁ →gm M₂ :=
graded_hom.mk' (d₁⁻¹ᵉ ⬝e d₂) (λi j p, homomorphism_of_eq (ap M₂ p) ∘lm fn (d₁⁻¹ᵉ i) ∘lm
homomorphism_of_eq (ap M₁ (to_right_inv d₁ i)⁻¹))
definition graded_hom_eq_transport (f : M₁ →gm M₂) {i j : I} (p : deg f i = j) (m : M₁ i) :
f ↘ p m = transport M₂ p (f i m) :=
by induction p; reflexivity
definition graded_hom_mk_refl (d : I ≃ I)
(fn : Πi, M₁ i →lm M₂ (d i)) {i : I} (m : M₁ i) : graded_hom.mk d fn i m = fn i m :=
by reflexivity
lemma graded_hom_mk_out'_destruct (d : I ≃ I)
(fn : Πi, M₁ (d i) →lm M₂ i) {i : I} (m : M₁ (d i)) :
graded_hom.mk_out' d fn ↘ (left_inv d i) m = fn i m :=
begin
unfold [graded_hom.mk_out'],
apply ap (λx, fn i (cast x m)),
refine !ap_compose⁻¹ ⬝ ap02 _ _,
apply is_set.elim --TODO: we can also prove this if I is not a set
end
lemma graded_hom_mk_out_destruct (d : I ≃ I)
(fn : Πi, M₁ (d⁻¹ i) →lm M₂ i) {i : I} (m : M₁ (d⁻¹ i)) :
graded_hom.mk_out d fn ↘ (right_inv d i) m = fn i m :=
begin
rexact graded_hom_mk_out'_destruct d⁻¹ᵉ fn m
end
lemma graded_hom_mk_out_in_destruct (d₁ : I ≃ I) (d₂ : I ≃ I)
(fn : Πi, M₁ (d₁ i) →lm M₂ (d₂ i)) {i : I} (m : M₁ (d₁ i)) :
graded_hom.mk_out_in d₁ d₂ fn ↘ (ap d₂ (left_inv d₁ i)) m = fn i m :=
begin
unfold [graded_hom.mk_out_in],
rewrite [adj d₁, -ap_inv, - +ap_compose, ],
refine cast_fn_cast_square fn _ _ !con.left_inv m
end
definition graded_hom_eq_zero {f : M₁ →gm M₂} {i j k : I} {q : deg f i = j} {p : deg f i = k}
(m : M₁ i) (r : f ↘ q m = 0) : f ↘ p m = 0 :=
have f ↘ p m = transport M₂ (q⁻¹ ⬝ p) (f ↘ q m), begin induction p, induction q, reflexivity end,
this ⬝ ap (transport M₂ (q⁻¹ ⬝ p)) r ⬝ tr_eq_of_pathover (apd (λi, 0) (q⁻¹ ⬝ p))
definition graded_hom_change_image {f : M₁ →gm M₂} {i j k : I} {m : M₂ k} (p : deg f i = k)
(q : deg f j = k) (h : image (f ↘ p) m) : image (f ↘ q) m :=
begin
have Σ(r : i = j), ap (deg f) r = p ⬝ q⁻¹,
from ⟨eq_of_fn_eq_fn (deg f) (p ⬝ q⁻¹), !ap_eq_of_fn_eq_fn'⟩,
induction this with r s, induction r, induction q, esimp at s, induction s, exact h
end
definition graded_hom_codom_rec {f : M₁ →gm M₂} {j : I} {P : Π⦃i⦄, deg f i = j → Type}
{i i' : I} (p : deg f i = j) (h : P p) (q : deg f i' = j) : P q :=
begin
have Σ(r : i = i'), ap (deg f) r = p ⬝ q⁻¹,
from ⟨eq_of_fn_eq_fn (deg f) (p ⬝ q⁻¹), !ap_eq_of_fn_eq_fn'⟩,
induction this with r s, induction r, induction q, esimp at s, induction s, exact h
end
variables {f' : M₂ →gm M₃} {f g h : M₁ →gm M₂}
definition graded_hom_compose [constructor] (f' : M₂ →gm M₃) (f : M₁ →gm M₂) : M₁ →gm M₃ :=
graded_hom.mk' (deg f ⬝e deg f') (λi j p, f' ↘ p ∘lm f i)
infixr ` ∘gm `:75 := graded_hom_compose
definition graded_hom_compose_fn (f' : M₂ →gm M₃) (f : M₁ →gm M₂) (i : I) (m : M₁ i) :
(f' ∘gm f) i m = f' (deg f i) (f i m) :=
by reflexivity
definition graded_hom_compose_fn_ext (f' : M₂ →gm M₃) (f : M₁ →gm M₂) ⦃i j k : I⦄
(p : deg f i = j) (q : deg f' j = k) (r : (deg f ⬝e deg f') i = k) (s : ap (deg f') p ⬝ q = r)
(m : M₁ i) : ((f' ∘gm f) ↘ r) m = (f' ↘ q) (f ↘ p m) :=
by induction s; induction q; induction p; reflexivity
definition graded_hom_compose_fn_out (f' : M₂ →gm M₃) (f : M₁ →gm M₂) (i : I)
(m : M₁ ((deg f ⬝e deg f')⁻¹ᵉ i)) : (f' ∘gm f) ← i m = f' ← i (f ← ((deg f')⁻¹ᵉ i) m) :=
graded_hom_compose_fn_ext f' f _ _ _ idp m
-- the following composition might be useful if you want tight control over the paths to which f and f' are applied
definition graded_hom_compose_ext [constructor] (f' : M₂ →gm M₃) (f : M₁ →gm M₂)
(d : Π⦃i j⦄ (p : (deg f ⬝e deg f') i = j), I)
(pf : Π⦃i j⦄ (p : (deg f ⬝e deg f') i = j), deg f i = d p)
(pf' : Π⦃i j⦄ (p : (deg f ⬝e deg f') i = j), deg f' (d p) = j) : M₁ →gm M₃ :=
graded_hom.mk' (deg f ⬝e deg f') (λi j p, (f' ↘ (pf' p)) ∘lm (f ↘ (pf p)))
variable (M)
definition graded_hom_id [constructor] [refl] : M →gm M :=
graded_hom.mk erfl (λi, lmid)
variable {M}
abbreviation gmid [constructor] := graded_hom_id M
definition graded_hom_reindex [constructor] {J : Set} (e : J ≃ I) (f : M₁ →gm M₂) :
(λy, M₁ (e y)) →gm (λy, M₂ (e y)) :=
graded_hom.mk' (e ⬝e deg f ⬝e e⁻¹ᵉ) (λy₁ y₂ p, f ↘ (eq_of_inv_eq p))
definition gm_constant [constructor] (M₁ M₂ : graded_module R I) (d : I ≃ I) : M₁ →gm M₂ :=
graded_hom.mk' d (gmd_constant d M₁ M₂)
definition is_surjective_graded_hom_compose ⦃x z⦄
(f' : M₂ →gm M₃) (f : M₁ →gm M₂) (p : deg f' (deg f x) = z)
(H' : Π⦃y⦄ (q : deg f' y = z), is_surjective (f' ↘ q))
(H : Π⦃y⦄ (q : deg f x = y), is_surjective (f ↘ q)) : is_surjective ((f' ∘gm f) ↘ p) :=
begin
induction p,
apply is_surjective_compose (f' (deg f x)) (f x),
apply H', apply H
end
structure graded_iso (M₁ M₂ : graded_module R I) : Type :=
mk' :: (to_hom : M₁ →gm M₂)
(is_equiv_to_hom : Π⦃i j⦄ (p : deg to_hom i = j), is_equiv (to_hom ↘ p))
infix ` ≃gm `:25 := graded_iso
attribute graded_iso.to_hom [coercion]
attribute graded_iso._trans_of_to_hom [unfold 5]
definition is_equiv_graded_iso [instance] [priority 1010] (φ : M₁ ≃gm M₂) (i : I) :
is_equiv (φ i) :=
graded_iso.is_equiv_to_hom φ idp
definition isomorphism_of_graded_iso' [constructor] (φ : M₁ ≃gm M₂) {i j : I} (p : deg φ i = j) :
M₁ i ≃lm M₂ j :=
isomorphism.mk (φ ↘ p) !graded_iso.is_equiv_to_hom
definition isomorphism_of_graded_iso [constructor] (φ : M₁ ≃gm M₂) (i : I) :
M₁ i ≃lm M₂ (deg φ i) :=
isomorphism.mk (φ i) _
definition isomorphism_of_graded_iso_out [constructor] (φ : M₁ ≃gm M₂) (i : I) :
M₁ ((deg φ)⁻¹ i) ≃lm M₂ i :=
isomorphism_of_graded_iso' φ !to_right_inv
protected definition graded_iso.mk [constructor] (d : I ≃ I) (φ : Πi, M₁ i ≃lm M₂ (d i)) :
M₁ ≃gm M₂ :=
begin
apply graded_iso.mk' (graded_hom.mk d φ),
intro i j p, induction p,
exact to_is_equiv (equiv_of_isomorphism (φ i)),
end
protected definition graded_iso.mk_out [constructor] (d : I ≃ I) (φ : Πi, M₁ (d⁻¹ i) ≃lm M₂ i) :
M₁ ≃gm M₂ :=
begin
apply graded_iso.mk' (graded_hom.mk_out d φ),
intro i j p, esimp,
exact @is_equiv_compose _ _ _ _ _ !is_equiv_cast _,
end
definition graded_iso_of_eq [constructor] {M₁ M₂ : graded_module R I} (p : M₁ ~ M₂)
: M₁ ≃gm M₂ :=
graded_iso.mk erfl (λi, isomorphism_of_eq (p i))
-- definition to_gminv [constructor] (φ : M₁ ≃gm M₂) : M₂ →gm M₁ :=
-- graded_hom.mk_out (deg φ)⁻¹ᵉ
-- abstract begin
-- intro i, apply isomorphism.to_hom, symmetry,
-- apply isomorphism_of_graded_iso φ
-- end end
variable (M)
definition graded_iso.refl [refl] [constructor] : M ≃gm M :=
graded_iso.mk equiv.rfl (λi, isomorphism.rfl)
variable {M}
definition graded_iso.rfl [refl] [constructor] : M ≃gm M := graded_iso.refl M
definition graded_iso.symm [symm] [constructor] (φ : M₁ ≃gm M₂) : M₂ ≃gm M₁ :=
graded_iso.mk_out (deg φ)⁻¹ᵉ (λi, (isomorphism_of_graded_iso φ i)⁻¹ˡᵐ)
definition graded_iso.trans [trans] [constructor] (φ : M₁ ≃gm M₂) (ψ : M₂ ≃gm M₃) : M₁ ≃gm M₃ :=
graded_iso.mk (deg φ ⬝e deg ψ)
(λi, isomorphism_of_graded_iso φ i ⬝lm isomorphism_of_graded_iso ψ (deg φ i))
definition graded_iso.eq_trans [trans] [constructor]
{M₁ M₂ M₃ : graded_module R I} (φ : M₁ ~ M₂) (ψ : M₂ ≃gm M₃) : M₁ ≃gm M₃ :=
proof graded_iso.trans (graded_iso_of_eq φ) ψ qed
definition graded_iso.trans_eq [trans] [constructor]
{M₁ M₂ M₃ : graded_module R I} (φ : M₁ ≃gm M₂) (ψ : M₂ ~ M₃) : M₁ ≃gm M₃ :=
graded_iso.trans φ (graded_iso_of_eq ψ)
postfix `⁻¹ᵉᵍᵐ`:(max + 1) := graded_iso.symm
infixl ` ⬝egm `:75 := graded_iso.trans
infixl ` ⬝egmp `:75 := graded_iso.trans_eq
infixl ` ⬝epgm `:75 := graded_iso.eq_trans
definition graded_hom_of_eq [constructor] {M₁ M₂ : graded_module R I} (p : M₁ ~ M₂) : M₁ →gm M₂ :=
proof graded_iso_of_eq p qed
definition fooff {I : Set} (P : I → Type) {i j : I} (M : P i) (N : P j) := unit
notation M ` ==[`:50 P:0 `] `:0 N:50 := fooff P M N
definition graded_homotopy (f g : M₁ →gm M₂) : Type :=
Π⦃i j k⦄ (p : deg f i = j) (q : deg g i = k) (m : M₁ i), f ↘ p m ==[λi, M₂ i] g ↘ q m
-- mk' :: (hd : deg f ~ deg g)
-- (hfn : Π⦃i j : I⦄ (pf : deg f i = j) (pg : deg g i = j), f ↘ pf ~ g ↘ pg)
infix ` ~gm `:50 := graded_homotopy
-- definition graded_homotopy.mk2 (hd : deg f ~ deg g) (hfn : Πi m, f i m =[hd i] g i m) : f ~gm g :=
-- graded_homotopy.mk' hd
-- begin
-- intro i j pf pg m, induction (is_set.elim (hd i ⬝ pg) pf), induction pg, esimp,
-- exact graded_hom_eq_transport f (hd i) m ⬝ tr_eq_of_pathover (hfn i m),
-- end
definition graded_homotopy.mk (h : Πi m, f i m ==[λi, M₂ i] g i m) : f ~gm g :=
begin
intros i j k p q m, induction q, induction p, constructor --exact h i m
end
-- definition graded_hom_compose_out {d₁ d₂ : I ≃ I} (f₂ : Πi, M₂ i →lm M₃ (d₂ i))
-- (f₁ : Πi, M₁ (d₁⁻¹ i) →lm M₂ i) : graded_hom.mk d₂ f₂ ∘gm graded_hom.mk_out d₁ f₁ ~gm
-- graded_hom.mk_out_in d₁⁻¹ᵉ d₂ _ :=
-- _
-- definition graded_hom_out_in_compose_out {d₁ d₂ d₃ : I ≃ I} (f₂ : Πi, M₂ (d₂ i) →lm M₃ (d₃ i))
-- (f₁ : Πi, M₁ (d₁⁻¹ i) →lm M₂ i) : graded_hom.mk_out_in d₂ d₃ f₂ ∘gm graded_hom.mk_out d₁ f₁ ~gm
-- graded_hom.mk_out_in (d₂ ⬝e d₁⁻¹ᵉ) d₃ (λi, f₂ i ∘lm (f₁ (d₂ i))) :=
-- begin
-- apply graded_homotopy.mk, intro i m, exact sorry
-- end
-- definition graded_hom_out_in_rfl {d₁ d₂ : I ≃ I} (f : Πi, M₁ i →lm M₂ (d₂ i))
-- (p : Πi, d₁ i = i) :
-- graded_hom.mk_out_in d₁ d₂ (λi, sorry) ~gm graded_hom.mk d₂ f :=
-- begin
-- apply graded_homotopy.mk, intro i m, exact sorry
-- end
-- definition graded_homotopy.trans (h₁ : f ~gm g) (h₂ : g ~gm h) : f ~gm h :=
-- begin
-- exact sorry
-- end
-- postfix `⁻¹ᵍᵐ`:(max + 1) := graded_iso.symm
--infixl ` ⬝gm `:75 := graded_homotopy.trans
-- infixl ` ⬝gmp `:75 := graded_iso.trans_eq
-- infixl ` ⬝pgm `:75 := graded_iso.eq_trans
-- definition graded_homotopy_of_deg (d : I ≃ I) (f g : graded_hom_of_deg d M₁ M₂) : Type :=
-- Π⦃i j : I⦄ (p : d i = j), f p ~ g p
-- notation f ` ~[`:50 d:0 `] `:0 g:50 := graded_homotopy_of_deg d f g
-- variables {d : I ≃ I} {f₁ f₂ : graded_hom_of_deg d M₁ M₂}
-- definition graded_homotopy_of_deg.mk [constructor] (h : Πi, f₁ (idpath (d i)) ~ f₂ (idpath (d i))) :
-- f₁ ~[d] f₂ :=
-- begin
-- intro i j p, induction p, exact h i
-- end
-- definition graded_homotopy.mk_out [constructor] {M₁ M₂ : graded_module R I} (d : I ≃ I)
-- (fn : Πi, M₁ (d⁻¹ i) →lm M₂ i) : M₁ →gm M₂ :=
-- graded_hom.mk' d (λi j p, fn j ∘lm homomorphism_of_eq (ap M₁ (eq_inv_of_eq p)))
-- definition is_gconstant (f : M₁ →gm M₂) : Type :=
-- f↘ ~[deg f] gmd0
definition compose_constant (f' : M₂ →gm M₃) (f : M₁ →gm M₂) : Type :=
Π⦃i j k : I⦄ (p : deg f i = j) (q : deg f' j = k) (m : M₁ i), f' ↘ q (f ↘ p m) = 0
definition compose_constant.mk (h : Πi m, f' (deg f i) (f i m) = 0) : compose_constant f' f :=
by intros; induction p; induction q; exact h i m
definition compose_constant.elim (h : compose_constant f' f) (i : I) (m : M₁ i) : f' (deg f i) (f i m) = 0 :=
h idp idp m
definition is_gconstant (f : M₁ →gm M₂) : Type :=
Π⦃i j : I⦄ (p : deg f i = j) (m : M₁ i), f ↘ p m = 0
definition is_gconstant.mk (h : Πi m, f i m = 0) : is_gconstant f :=
by intros; induction p; exact h i m
definition is_gconstant.elim (h : is_gconstant f) (i : I) (m : M₁ i) : f i m = 0 :=
h idp m
/- direct sum of graded R-modules -/
variables {J : Set} (N : graded_module R J)
definition dirsum' : AddAbGroup :=
group.dirsum (λj, AddAbGroup_of_LeftModule (N j))
variable {N}
definition dirsum_smul [constructor] (r : R) : dirsum' N →a dirsum' N :=
dirsum_functor (λi, smul_homomorphism (N i) r)
definition dirsum_smul_right_distrib (r s : R) (n : dirsum' N) :
dirsum_smul (r + s) n = dirsum_smul r n + dirsum_smul s n :=
begin
refine dirsum_functor_homotopy _ _ _ n ⬝ !dirsum_functor_mul⁻¹,
intro i ni, exact to_smul_right_distrib r s ni
end
definition dirsum_mul_smul' (r s : R) (n : dirsum' N) :
dirsum_smul (r * s) n = (dirsum_smul r ∘a dirsum_smul s) n :=
begin
refine dirsum_functor_homotopy _ _ _ n ⬝ (dirsum_functor_compose _ _ n)⁻¹ᵖ,
intro i ni, exact to_mul_smul r s ni
end
definition dirsum_mul_smul (r s : R) (n : dirsum' N) :
dirsum_smul (r * s) n = dirsum_smul r (dirsum_smul s n) :=
proof dirsum_mul_smul' r s n qed
definition dirsum_one_smul (n : dirsum' N) : dirsum_smul 1 n = n :=
begin
refine dirsum_functor_homotopy _ _ _ n ⬝ !dirsum_functor_gid,
intro i ni, exact to_one_smul ni
end
definition dirsum : LeftModule R :=
LeftModule_of_AddAbGroup (dirsum' N) (λr n, dirsum_smul r n)
proof (λr, homomorphism.addstruct (dirsum_smul r)) qed
proof dirsum_smul_right_distrib qed
proof dirsum_mul_smul qed
proof dirsum_one_smul qed
/- graded variants of left-module constructions -/
definition graded_submodule [constructor] (S : Πi, property (M i)) [Π i, is_submodule (M i) (S i)] :
graded_module R I :=
λi, submodule (S i)
definition graded_submodule_incl [constructor] (S : Πi, property (M i)) [H : Π i, is_submodule (M i) (S i)] :
graded_submodule S →gm M :=
have Π i, is_submodule (M (to_fun erfl i)) (S i), from H,
graded_hom.mk erfl (λi, submodule_incl (S i))
definition graded_hom_lift [constructor] (S : Πi, property (M₂ i)) [Π i, is_submodule (M₂ i) (S i)]
(φ : M₁ →gm M₂)
(h : Π(i : I) (m : M₁ i), φ i m ∈ S (deg φ i)) : M₁ →gm graded_submodule S :=
graded_hom.mk (deg φ) (λi, hom_lift (φ i) (h i))
definition graded_submodule_functor [constructor]
{S : Πi, property (M₁ i)} [Π i, is_submodule (M₁ i) (S i)]
{T : Πi, property (M₂ i)} [Π i, is_submodule (M₂ i) (T i)]
(φ : M₁ →gm M₂)
(h : Π(i : I) (m : M₁ i), S i m → T (deg φ i) (φ i m)) :
graded_submodule S →gm graded_submodule T :=
graded_hom.mk (deg φ) (λi, submodule_functor (φ i) (h i))
definition graded_image (f : M₁ →gm M₂) : graded_module R I :=
λi, image_module (f ← i)
lemma graded_image_lift_lemma (f : M₁ →gm M₂) {i j: I} (p : deg f i = j) (m : M₁ i) :
image (f ← j) (f ↘ p m) :=
graded_hom_change_image p (right_inv (deg f) j) (image.mk m idp)
definition graded_image_lift [constructor] (f : M₁ →gm M₂) : M₁ →gm graded_image f :=
graded_hom.mk' (deg f) (λi j p, hom_lift (f ↘ p) (graded_image_lift_lemma f p))
definition graded_image_lift_destruct (f : M₁ →gm M₂) {i : I}
(m : M₁ ((deg f)⁻¹ᵉ i)) : graded_image_lift f ← i m = image_lift (f ← i) m :=
subtype_eq idp
definition graded_image.rec {f : M₁ →gm M₂} {i : I} {P : graded_image f (deg f i) → Type}
[h : Πx, is_prop (P x)] (H : Πm, P (graded_image_lift f i m)) : Πm, P m :=
begin
assert H₂ : Πi' (p : deg f i' = deg f i) (m : M₁ i'),
P ⟨f ↘ p m, graded_hom_change_image p _ (image.mk m idp)⟩,
{ refine eq.rec_equiv_symm (deg f) _, intro m,
refine transport P _ (H m), apply subtype_eq, reflexivity },
refine @total_image.rec _ _ _ _ h _, intro m,
refine transport P _ (H₂ _ (right_inv (deg f) (deg f i)) m),
apply subtype_eq, reflexivity
end
definition image_graded_image_lift {f : M₁ →gm M₂} {i j : I} (p : deg f i = j)
(m : graded_image f j)
(h : image (f ↘ p) m.1) : image (graded_image_lift f ↘ p) m :=
begin
induction p,
revert m h, refine total_image.rec _, intro m h,
induction h with n q, refine image.mk n (subtype_eq q)
end
lemma is_surjective_graded_image_lift ⦃x y⦄ (f : M₁ →gm M₂)
(p : deg f x = y) : is_surjective (graded_image_lift f ↘ p) :=
begin
intro m, apply image_graded_image_lift, exact graded_hom_change_image (right_inv (deg f) y) _ m.2
end
definition graded_image_elim [constructor] {f : M₁ →gm M₂} (g : M₁ →gm M₃)
(h : Π⦃i m⦄, f i m = 0 → g i m = 0) :
graded_image f →gm M₃ :=
begin
apply graded_hom.mk_out_in (deg f) (deg g),
intro i,
apply image_elim (g ↘ (ap (deg g) (to_left_inv (deg f) i))),
exact abstract begin
intro m p,
refine graded_hom_eq_zero m (h _),
exact graded_hom_eq_zero m p end end
end
lemma graded_image_elim_destruct {f : M₁ →gm M₂} {g : M₁ →gm M₃}
(h : Π⦃i m⦄, f i m = 0 → g i m = 0) {i j k : I}
(p' : deg f i = j) (p : deg g ((deg f)⁻¹ᵉ j) = k)
(q : deg g i = k) (r : ap (deg g) (to_left_inv (deg f) i) ⬝ q = ap ((deg f)⁻¹ᵉ ⬝e deg g) p' ⬝ p)
(m : M₁ i) : graded_image_elim g h ↘ p (graded_image_lift f ↘ p' m) =
g ↘ q m :=
begin
revert i j p' k p q r m,
refine equiv_rect (deg f ⬝e (deg f)⁻¹ᵉ) _ _,
intro i, refine eq.rec_grading _ (deg f) (right_inv (deg f) (deg f i)) _,
intro k p q r m,
assert r' : q = p,
{ refine cancel_left _ (r ⬝ whisker_right _ _), refine !ap_compose ⬝ ap02 (deg g) _,
exact !adj_inv⁻¹ },
induction r', clear r,
revert k q m, refine eq.rec_to (ap (deg g) (to_left_inv (deg f) i)) _, intro m,
refine graded_hom_mk_out_in_destruct (deg f) (deg g) _ (graded_image_lift f ← (deg f i) m) ⬝ _,
refine ap (image_elim _ _) !graded_image_lift_destruct ⬝ _, reflexivity
end
/- alternative (easier) definition of graded_image with "wrong" grading -/
-- definition graded_image' (f : M₁ →gm M₂) : graded_module R I :=
-- λi, image_module (f i)
-- definition graded_image'_lift [constructor] (f : M₁ →gm M₂) : M₁ →gm graded_image' f :=
-- graded_hom.mk erfl (λi, image_lift (f i))
-- definition graded_image'_elim [constructor] {f : M₁ →gm M₂} (g : M₁ →gm M₃)
-- (h : Π⦃i m⦄, f i m = 0 → g i m = 0) :
-- graded_image' f →gm M₃ :=
-- begin
-- apply graded_hom.mk (deg g),
-- intro i,
-- apply image_elim (g i),
-- intro m p, exact h p
-- end
-- theorem graded_image'_elim_compute {f : M₁ →gm M₂} {g : M₁ →gm M₃}
-- (h : Π⦃i m⦄, f i m = 0 → g i m = 0) :
-- graded_image'_elim g h ∘gm graded_image'_lift f ~gm g :=
-- begin
-- apply graded_homotopy.mk,
-- intro i m, exact sorry --reflexivity
-- end
-- theorem graded_image_elim_compute {f : M₁ →gm M₂} {g : M₁ →gm M₃}
-- (h : Π⦃i m⦄, f i m = 0 → g i m = 0) :
-- graded_image_elim g h ∘gm graded_image_lift f ~gm g :=
-- begin
-- refine _ ⬝gm graded_image'_elim_compute h,
-- esimp, exact sorry
-- -- refine graded_hom_out_in_compose_out _ _ ⬝gm _, exact sorry
-- -- -- apply graded_homotopy.mk,
-- -- -- intro i m,
-- end
-- variables {α β : I ≃ I}
-- definition gen_image (f : M₁ →gm M₂) (p : Πi, deg f (α i) = β i) : graded_module R I :=
-- λi, image_module (f ↘ (p i))
-- definition gen_image_lift [constructor] (f : M₁ →gm M₂) (p : Πi, deg f (α i) = β i) : M₁ →gm gen_image f p :=
-- graded_hom.mk_out α⁻¹ᵉ (λi, image_lift (f ↘ (p i)))
-- definition gen_image_elim [constructor] {f : M₁ →gm M₂} (p : Πi, deg f (α i) = β i) (g : M₁ →gm M₃)
-- (h : Π⦃i m⦄, f i m = 0 → g i m = 0) :
-- gen_image f p →gm M₃ :=
-- begin
-- apply graded_hom.mk_out_in α⁻¹ᵉ (deg g),
-- intro i,
-- apply image_elim (g ↘ (ap (deg g) (to_right_inv α i))),
-- intro m p,
-- refine graded_hom_eq_zero m (h _),
-- exact graded_hom_eq_zero m p
-- end
-- theorem gen_image_elim_compute {f : M₁ →gm M₂} {p : deg f ∘ α ~ β} {g : M₁ →gm M₃}
-- (h : Π⦃i m⦄, f i m = 0 → g i m = 0) :
-- gen_image_elim p g h ∘gm gen_image_lift f p ~gm g :=
-- begin
-- -- induction β with β βe, esimp at *, induction p using homotopy.rec_on_idp,
-- assert q : β ⬝e (deg f)⁻¹ᵉ = α,
-- { apply equiv_eq, intro i, apply inv_eq_of_eq, exact (p i)⁻¹ },
-- induction q,
-- -- unfold [gen_image_elim, gen_image_lift],
-- -- induction (is_prop.elim (λi, to_right_inv (deg f) (β i)) p),
-- -- apply graded_homotopy.mk,
-- -- intro i m, reflexivity
-- exact sorry
-- end
definition graded_kernel (f : M₁ →gm M₂) : graded_module R I :=
λi, kernel_module (f i)
definition graded_quotient (S : Πi, property (M i)) [Π i, is_submodule (M i) (S i)] : graded_module R I :=
λi, quotient_module (S i)
definition graded_quotient_map [constructor] (S : Πi, property (M i)) [Π i, is_submodule (M i) (S i)] :
M →gm graded_quotient S :=
graded_hom.mk erfl (λi, quotient_map (S i))
definition graded_quotient_elim [constructor]
(S : Πi, property (M i)) [Π i, is_submodule (M i) (S i)]
(φ : M →gm M₂)
(H : Πi ⦃m⦄, S i m → φ i m = 0) : graded_quotient S →gm M₂ :=
graded_hom.mk (deg φ) (λi, quotient_elim (φ i) (H i))
definition graded_homology (g : M₂ →gm M₃) (f : M₁ →gm M₂) : graded_module R I :=
graded_quotient (λ i, homology_quotient_property (g i) (f ← i))
-- the two reasonable definitions of graded_homology are definitionally equal
example (g : M₂ →gm M₃) (f : M₁ →gm M₂) :
(λi, homology (g i) (f ← i)) = graded_homology g f := idp
definition graded_homology.mk (g : M₂ →gm M₃) (f : M₁ →gm M₂) {i : I} (m : M₂ i) (h : g i m = 0) :
graded_homology g f i :=
homology.mk _ m h
definition graded_homology_intro [constructor] (g : M₂ →gm M₃) (f : M₁ →gm M₂) :
graded_kernel g →gm graded_homology g f :=
@graded_quotient_map _ _ _ (λ i, homology_quotient_property (g i) (f ← i)) _
definition graded_homology_elim {g : M₂ →gm M₃} {f : M₁ →gm M₂} (h : M₂ →gm M)
(H : compose_constant h f) : graded_homology g f →gm M :=
graded_hom.mk (deg h) (λi, homology_elim (h i) (H _ _))
definition image_of_graded_homology_intro_eq_zero {g : M₂ →gm M₃} {f : M₁ →gm M₂}
⦃i j : I⦄ (p : deg f i = j) (m : graded_kernel g j) (H : graded_homology_intro g f j m = 0) :
image (f ↘ p) m.1 :=
begin
induction p, exact graded_hom_change_image _ _
(@rel_of_quotient_map_eq_zero _ _ _ _ m H)
end
definition is_exact_gmod (f : M₁ →gm M₂) (f' : M₂ →gm M₃) : Type :=
Π⦃i j k⦄ (p : deg f i = j) (q : deg f' j = k), is_exact_mod (f ↘ p) (f' ↘ q)
definition is_exact_gmod.mk {f : M₁ →gm M₂} {f' : M₂ →gm M₃}
(h₁ : Π⦃i⦄ (m : M₁ i), f' (deg f i) (f i m) = 0)
(h₂ : Π⦃i⦄ (m : M₂ (deg f i)), f' (deg f i) m = 0 → image (f i) m) : is_exact_gmod f f' :=
begin intro i j k p q; induction p; induction q; split, apply h₁, apply h₂ end
definition gmod_im_in_ker (h : is_exact_gmod f f') : compose_constant f' f :=
λi j k p q, is_exact.im_in_ker (h p q)
definition gmod_ker_in_im (h : is_exact_gmod f f') ⦃i : I⦄ (m : M₂ i) (p : f' i m = 0) :
image (f ← i) m :=
is_exact.ker_in_im (h (right_inv (deg f) i) idp) m p
definition is_exact_gmod_reindex [constructor] {J : Set} (e : J ≃ I) (h : is_exact_gmod f f') :
is_exact_gmod (graded_hom_reindex e f) (graded_hom_reindex e f') :=
λi j k p q, h (eq_of_inv_eq p) (eq_of_inv_eq q)
end left_module
|
7bfe4b8756c465b83975e855388a71366adee700 | 9b9a16fa2cb737daee6b2785474678b6fa91d6d4 | /src/category_theory/functor_category.lean | 4c5807678b42d985c1ff65c8b380560e6b3749da | [
"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 | 2,683 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Tim Baumann, Stephen Morgan, Scott Morrison
import category_theory.natural_transformation
namespace category_theory
universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
open nat_trans
variables (C : Type u₁) [𝒞 : category.{v₁} C] (D : Type u₂) [𝒟 : category.{v₂} D]
include 𝒞 𝒟
/--
`functor.category C D` gives the category structure on functors and natural transformations
between categories `C` and `D`.
Notice that if `C` and `D` are both small categories at the same universe level,
this is another small category at that level.
However if `C` and `D` are both large categories at the same universe level,
this is a small category at the next higher level.
-/
instance functor.category : category.{(max u₁ v₂)} (C ⥤ D) :=
{ hom := λ F G, F ⟹ G,
id := λ F, nat_trans.id F,
comp := λ _ _ _ α β, α ⊟ β }
variables {C D} {E : Type u₃} [ℰ : category.{v₃} E]
namespace functor.category
section
@[simp] lemma id_app (F : C ⥤ D) (X : C) : (𝟙 F : F ⟹ F).app X = 𝟙 (F.obj X) := rfl
@[simp] lemma comp_app {F G H : C ⥤ D} (α : F ⟶ G) (β : G ⟶ H) (X : C) :
(α ≫ β).app X = α.app X ≫ β.app X := rfl
end
namespace nat_trans
-- This section gives two lemmas about natural transformations
-- between functors into functor categories,
-- spelling them out in components.
include ℰ
lemma app_naturality {F G : C ⥤ (D ⥤ E)} (T : F ⟹ G) (X : C) {Y Z : D} (f : Y ⟶ Z) :
((F.obj X).map f) ≫ ((T.app X).app Z) = ((T.app X).app Y) ≫ ((G.obj X).map f) :=
(T.app X).naturality f
lemma naturality_app {F G : C ⥤ (D ⥤ E)} (T : F ⟹ G) (Z : D) {X Y : C} (f : X ⟶ Y) :
((F.map f).app Z) ≫ ((T.app Y).app Z) = ((T.app X).app Z) ≫ ((G.map f).app Z) :=
congr_fun (congr_arg app (T.naturality f)) Z
end nat_trans
end functor.category
namespace functor
include ℰ
protected def flip (F : C ⥤ (D ⥤ E)) : D ⥤ (C ⥤ E) :=
{ obj := λ k,
{ obj := λ j, (F.obj j).obj k,
map := λ j j' f, (F.map f).app k,
map_id' := λ X, begin rw category_theory.functor.map_id, refl end,
map_comp' := λ X Y Z f g, by rw [functor.map_comp, ←functor.category.comp_app] },
map := λ c c' f,
{ app := λ j, (F.obj j).map f,
naturality' := λ X Y g, by dsimp; rw ←nat_trans.naturality } }.
@[simp] lemma flip_obj_map (F : C ⥤ (D ⥤ E)) {c c' : C} (f : c ⟶ c') (d : D) :
((F.flip).obj d).map f = (F.map f).app d := rfl
end functor
end category_theory
|
bf315045c531a8caac4931d89a08c6d562984ff2 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/run/e8.lean | 73f1e2382d5a4600602e3604bf21a129640bbf73 | [
"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 | 835 | lean | precedence `+`:65
namespace nat
constant nat : Type.{1}
constant add : nat → nat → nat
infixl + := add
end nat
namespace int
open nat (nat)
constant int : Type.{1}
constant add : int → int → int
infixl + := add
constant of_nat : nat → int
coercion of_nat
end int
-- Open "only" the notation and declarations from the namespaces nat and int
open [notation] nat
open [notation] int
open [decls] nat
open [decls] int
constants n m : nat
constants i j : int
check n + m
check i + j
-- The following check does not work, since we are not open the coercions
-- check n + i
-- Here is a possible trick for this kind of configuration
definition add_ni (a : nat) (b : int) := (of_nat a) + b
definition add_in (a : int) (b : nat) := a + (of_nat b)
infixl + := add_ni
infixl + := add_in
check i + n
check n + i
|
454997875d2784bb6b3867e16668380518ac2f86 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebraic_geometry/Spec.lean | 03a242b6849ba970706b6dd5d5de4daa26b28db9 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 8,643 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Justus Springer
-/
import algebraic_geometry.locally_ringed_space
import algebraic_geometry.structure_sheaf
import data.equiv.transfer_instance
/-!
# $Spec$ as a functor to locally ringed spaces.
We define the functor $Spec$ from commutative rings to locally ringed spaces.
## Implementation notes
We define $Spec$ in three consecutive steps, each with more structure than the last:
1. `Spec.to_Top`, valued in the category of topological spaces,
2. `Spec.to_SheafedSpace`, valued in the category of sheafed spaces and
3. `Spec.to_LocallyRingedSpace`, valued in the category of locally ringed spaces.
Additionally, we provide `Spec.to_PresheafedSpace` as a composition of `Spec.to_SheafedSpace` with
a forgetful functor.
## Future work
Adjunction between `Γ` and `Spec`
-/
noncomputable theory
namespace algebraic_geometry
open opposite
open category_theory
open structure_sheaf
/--
The spectrum of a commutative ring, as a topological space.
-/
def Spec.Top_obj (R : CommRing) : Top := Top.of (prime_spectrum R)
/--
The induced map of a ring homomorphism on the ring spectra, as a morphism of topological spaces.
-/
@[simps] def Spec.Top_map {R S : CommRing} (f : R ⟶ S) :
Spec.Top_obj S ⟶ Spec.Top_obj R :=
{ to_fun := prime_spectrum.comap f,
continuous_to_fun := prime_spectrum.comap_continuous f }
@[simp] lemma Spec.Top_map_id (R : CommRing) :
Spec.Top_map (𝟙 R) = 𝟙 (Spec.Top_obj R) :=
continuous_map.ext $ λ x,
by erw [Spec.Top_map_to_fun, prime_spectrum.comap_id, id.def, Top.id_app]
lemma Spec.Top_map_comp {R S T : CommRing} (f : R ⟶ S) (g : S ⟶ T) :
Spec.Top_map (f ≫ g) = Spec.Top_map g ≫ Spec.Top_map f :=
continuous_map.ext $ λ x,
begin
dsimp only [Spec.Top_map_to_fun, Top.comp_app],
erw prime_spectrum.comap_comp,
end
/--
The spectrum, as a contravariant functor from commutative rings to topological spaces.
-/
@[simps] def Spec.to_Top : CommRingᵒᵖ ⥤ Top :=
{ obj := λ R, Spec.Top_obj (unop R),
map := λ R S f, Spec.Top_map f.unop,
map_id' := λ R, by rw [unop_id, Spec.Top_map_id],
map_comp' := λ R S T f g, by rw [unop_comp, Spec.Top_map_comp] }
/--
The spectrum of a commutative ring, as a `SheafedSpace`.
-/
@[simps] def Spec.SheafedSpace_obj (R : CommRing) : SheafedSpace CommRing :=
{ carrier := Spec.Top_obj R, ..structure_sheaf R }
/--
The induced map of a ring homomorphism on the ring spectra, as a morphism of sheafed spaces.
-/
@[simps] def Spec.SheafedSpace_map {R S : CommRing} (f : R ⟶ S) :
Spec.SheafedSpace_obj S ⟶ Spec.SheafedSpace_obj R :=
{ base := Spec.Top_map f,
c :=
{ app := λ U, comap f (unop U) ((topological_space.opens.map (Spec.Top_map f)).obj (unop U))
(λ p, id),
naturality' := λ U V i, ring_hom.ext $ λ s, subtype.eq $ funext $ λ p, rfl } }
@[simp] lemma Spec.SheafedSpace_map_id {R : CommRing} :
Spec.SheafedSpace_map (𝟙 R) = 𝟙 (Spec.SheafedSpace_obj R) :=
PresheafedSpace.ext _ _ (Spec.Top_map_id R) $ nat_trans.ext _ _ $ funext $ λ U,
begin
dsimp,
erw [PresheafedSpace.id_c_app, comap_id], swap,
{ rw [Spec.Top_map_id, topological_space.opens.map_id_obj_unop] },
rw [eq_to_hom_op, eq_to_hom_map, eq_to_hom_trans],
refl,
end
lemma Spec.SheafedSpace_map_comp {R S T : CommRing} (f : R ⟶ S) (g : S ⟶ T) :
Spec.SheafedSpace_map (f ≫ g) = Spec.SheafedSpace_map g ≫ Spec.SheafedSpace_map f :=
PresheafedSpace.ext _ _ (Spec.Top_map_comp f g) $ nat_trans.ext _ _ $ funext $ λ U,
begin
dsimp,
erw [Top.presheaf.pushforward.comp_inv_app, ← category.assoc, category.comp_id,
(structure_sheaf T).presheaf.map_id, category.comp_id, comap_comp],
refl,
end
/--
Spec, as a contravariant functor from commutative rings to sheafed spaces.
-/
@[simps] def Spec.to_SheafedSpace : CommRingᵒᵖ ⥤ SheafedSpace CommRing :=
{ obj := λ R, Spec.SheafedSpace_obj (unop R),
map := λ R S f, Spec.SheafedSpace_map f.unop,
map_id' := λ R, by rw [unop_id, Spec.SheafedSpace_map_id],
map_comp' := λ R S T f g, by rw [unop_comp, Spec.SheafedSpace_map_comp] }
/--
Spec, as a contravariant functor from commutative rings to presheafed spaces.
-/
def Spec.to_PresheafedSpace : CommRingᵒᵖ ⥤ PresheafedSpace CommRing :=
Spec.to_SheafedSpace ⋙ SheafedSpace.forget_to_PresheafedSpace
@[simp] lemma Spec.to_PresheafedSpace_obj (R : CommRingᵒᵖ) :
Spec.to_PresheafedSpace.obj R = (Spec.SheafedSpace_obj (unop R)).to_PresheafedSpace := rfl
lemma Spec.to_PresheafedSpace_obj_op (R : CommRing) :
Spec.to_PresheafedSpace.obj (op R) = (Spec.SheafedSpace_obj R).to_PresheafedSpace := rfl
@[simp] lemma Spec.to_PresheafedSpace_map (R S : CommRingᵒᵖ) (f : R ⟶ S) :
Spec.to_PresheafedSpace.map f = Spec.SheafedSpace_map f.unop := rfl
lemma Spec.to_PresheafedSpace_map_op (R S : CommRing) (f : R ⟶ S) :
Spec.to_PresheafedSpace.map f.op = Spec.SheafedSpace_map f := rfl
/--
The spectrum of a commutative ring, as a `LocallyRingedSpace`.
-/
@[simps] def Spec.LocallyRingedSpace_obj (R : CommRing) : LocallyRingedSpace :=
{ local_ring := λ x, @@ring_equiv.local_ring _
(show local_ring (localization.at_prime _), by apply_instance) _
(iso.CommRing_iso_to_ring_equiv $ stalk_iso R x).symm,
.. Spec.SheafedSpace_obj R }
@[elementwise]
lemma stalk_map_to_stalk {R S : CommRing} (f : R ⟶ S) (p : prime_spectrum S) :
to_stalk R (prime_spectrum.comap f p) ≫
PresheafedSpace.stalk_map (Spec.SheafedSpace_map f) p =
f ≫ to_stalk S p :=
begin
erw [← to_open_germ S ⊤ ⟨p, trivial⟩, ← to_open_germ R ⊤ ⟨prime_spectrum.comap f p, trivial⟩,
category.assoc, PresheafedSpace.stalk_map_germ (Spec.SheafedSpace_map f) ⊤ ⟨p, trivial⟩,
Spec.SheafedSpace_map_c_app, to_open_comp_comap_assoc],
refl
end
/--
Under the isomorphisms `stalk_iso`, the map `stalk_map (Spec.SheafedSpace_map f) p` corresponds
to the induced local ring homomorphism `localization.local_ring_hom`.
-/
@[elementwise]
lemma local_ring_hom_comp_stalk_iso {R S : CommRing} (f : R ⟶ S) (p : prime_spectrum S) :
(stalk_iso R (prime_spectrum.comap f p)).hom ≫
@category_struct.comp _ _
(CommRing.of (localization.at_prime (prime_spectrum.comap f p).as_ideal))
(CommRing.of (localization.at_prime p.as_ideal)) _
(localization.local_ring_hom (prime_spectrum.comap f p).as_ideal p.as_ideal f rfl)
(stalk_iso S p).inv =
PresheafedSpace.stalk_map (Spec.SheafedSpace_map f) p :=
(stalk_iso R (prime_spectrum.comap f p)).eq_inv_comp.mp $ (stalk_iso S p).comp_inv_eq.mpr $
localization.local_ring_hom_unique _ _ _ _ $ λ x, by
rw [stalk_iso_hom, stalk_iso_inv, comp_apply, comp_apply, localization_to_stalk_of,
stalk_map_to_stalk_apply, stalk_to_fiber_ring_hom_to_stalk]
/--
The induced map of a ring homomorphism on the prime spectra, as a morphism of locally ringed spaces.
-/
@[simps] def Spec.LocallyRingedSpace_map {R S : CommRing} (f : R ⟶ S) :
Spec.LocallyRingedSpace_obj S ⟶ Spec.LocallyRingedSpace_obj R :=
subtype.mk (Spec.SheafedSpace_map f) $ λ p, is_local_ring_hom.mk $ λ a ha,
begin
-- Here, we are showing that the map on prime spectra induced by `f` is really a morphism of
-- *locally* ringed spaces, i.e. that the induced map on the stalks is a local ring homomorphism.
rw ← local_ring_hom_comp_stalk_iso_apply at ha,
replace ha := (stalk_iso S p).hom.is_unit_map ha,
rw coe_inv_hom_id at ha,
replace ha := is_local_ring_hom.map_nonunit _ ha,
convert ring_hom.is_unit_map (stalk_iso R (prime_spectrum.comap f p)).inv ha,
rw coe_hom_inv_id,
end
@[simp] lemma Spec.LocallyRingedSpace_map_id (R : CommRing) :
Spec.LocallyRingedSpace_map (𝟙 R) = 𝟙 (Spec.LocallyRingedSpace_obj R) :=
subtype.ext $ by { rw [Spec.LocallyRingedSpace_map_coe, Spec.SheafedSpace_map_id], refl }
lemma Spec.LocallyRingedSpace_map_comp {R S T : CommRing} (f : R ⟶ S) (g : S ⟶ T) :
Spec.LocallyRingedSpace_map (f ≫ g) =
Spec.LocallyRingedSpace_map g ≫ Spec.LocallyRingedSpace_map f :=
subtype.ext $ by { rw [Spec.LocallyRingedSpace_map_coe, Spec.SheafedSpace_map_comp], refl }
/--
Spec, as a contravariant functor from commutative rings to locally ringed spaces.
-/
@[simps] def Spec.to_LocallyRingedSpace : CommRingᵒᵖ ⥤ LocallyRingedSpace :=
{ obj := λ R, Spec.LocallyRingedSpace_obj (unop R),
map := λ R S f, Spec.LocallyRingedSpace_map f.unop,
map_id' := λ R, by rw [unop_id, Spec.LocallyRingedSpace_map_id],
map_comp' := λ R S T f g, by rw [unop_comp, Spec.LocallyRingedSpace_map_comp] }
end algebraic_geometry
|
047811f855a6f9fa43391eccc3977247913f4fee | df561f413cfe0a88b1056655515399c546ff32a5 | /3-function-world/l2.lean | 7354d9484feaa04f5c83acbae3bf86c30ebdec29 | [] | 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 | 60 | lean | example : mynat → mynat :=
begin
intro n, exact 3*n+2,
end |
639e56ca4b9b858f54eb42513022c23a332f6302 | 19cc34575500ee2e3d4586c15544632aa07a8e66 | /src/data/complex/is_R_or_C.lean | 806129c557990c25f1891faa3a427cb52fdced0e | [
"Apache-2.0"
] | permissive | LibertasSpZ/mathlib | b9fcd46625eb940611adb5e719a4b554138dade6 | 33f7870a49d7cc06d2f3036e22543e6ec5046e68 | refs/heads/master | 1,672,066,539,347 | 1,602,429,158,000 | 1,602,429,158,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,802 | lean | /-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import analysis.normed_space.basic
import analysis.complex.basic
/-!
# `is_R_or_C`: a typeclass for ℝ or ℂ
This file defines the typeclass `is_R_or_C` intended to have only two instances:
ℝ and ℂ. It is meant for definitions and theorems which hold for both the real and the complex case,
and in particular when the real case follows directly from the complex case by setting `re` to `id`,
`im` to zero and so on. Its API follows closely that of ℂ.
Possible applications include defining inner products and Hilbert spaces for both the real and
complex case. One would produce the definitions and proof for an arbitrary field of this
typeclass, which basically amounts to doing the complex case, and the two cases then fall out
immediately from the two instances of the class.
-/
/--
This typeclass captures properties shared by ℝ and ℂ, with an API that closely matches that of ℂ.
-/
class is_R_or_C (K : Type*) extends nondiscrete_normed_field K, normed_algebra ℝ K, complete_space K :=
(re : K →+ ℝ)
(im : K →+ ℝ)
(conj : K →+* K)
(I : K) -- Meant to be set to 0 for K=ℝ
(of_real : ℝ → K) -- Meant to be id for K=ℝ and the coercion from ℝ for K=ℂ
(I_re_ax : re I = 0)
(I_mul_I_ax : I = 0 ∨ I * I = -1)
(re_add_im_ax : ∀ (z : K), of_real (re z) + of_real (im z) * I = z)
(smul_coe_mul_ax : ∀ (z : K) (r : ℝ), r • z = of_real r * z)
(of_real_re_ax : ∀ r : ℝ, re (of_real r) = r)
(of_real_im_ax : ∀ r : ℝ, im (of_real r) = 0)
(mul_re_ax : ∀ z w : K, re (z * w) = re z * re w - im z * im w)
(mul_im_ax : ∀ z w : K, im (z * w) = re z * im w + im z * re w)
(conj_re_ax : ∀ z : K, re (conj z) = re z)
(conj_im_ax : ∀ z : K, im (conj z) = -(im z))
(conj_I_ax : conj I = -I)
(norm_sq_eq_def_ax : ∀ (z : K), ∥z∥^2 = (re z) * (re z) + (im z) * (im z))
(mul_im_I_ax : ∀ (z : K), (im z) * im I = im z)
(inv_def_ax : ∀ (z : K), z⁻¹ = conj z * of_real ((∥z∥^2)⁻¹))
(div_I_ax : ∀ (z : K), z / I = -(z * I))
namespace is_R_or_C
variables {K : Type*} [is_R_or_C K]
local notation `𝓚` := @is_R_or_C.of_real K _
local postfix `†`:100 := @is_R_or_C.conj K _
lemma of_real_alg : ∀ x : ℝ, 𝓚 x = x • (1 : K) :=
λ x, by rw [←mul_one (𝓚 x), smul_coe_mul_ax]
@[simp] lemma re_add_im (z : K) : 𝓚 (re z) + 𝓚 (im z) * I = z := is_R_or_C.re_add_im_ax z
@[simp] lemma of_real_re : ∀ r : ℝ, re (𝓚 r) = r := is_R_or_C.of_real_re_ax
@[simp] lemma of_real_im : ∀ r : ℝ, im (𝓚 r) = 0 := is_R_or_C.of_real_im_ax
@[simp] lemma mul_re : ∀ z w : K, re (z * w) = re z * re w - im z * im w :=
is_R_or_C.mul_re_ax
@[simp] lemma mul_im : ∀ z w : K, im (z * w) = re z * im w + im z * re w :=
is_R_or_C.mul_im_ax
lemma inv_def {z : K} : z⁻¹ = conj z * of_real ((∥z∥^2)⁻¹) := is_R_or_C.inv_def_ax z
theorem ext_iff : ∀ {z w : K}, z = w ↔ re z = re w ∧ im z = im w :=
λ z w, { mp := by { rintro rfl, cc },
mpr := by { rintro ⟨h₁,h₂⟩, rw [←re_add_im z, ←re_add_im w, h₁, h₂] } }
theorem ext : ∀ {z w : K}, re z = re w → im z = im w → z = w :=
by { simp_rw ext_iff, cc }
@[simp] lemma zero_re : re (𝓚 0) = (0 : ℝ) := by simp only [of_real_re]
@[simp] lemma zero_im : im (𝓚 0) = 0 := by rw [of_real_im]
lemma of_real_zero : 𝓚 0 = 0 := by rw [of_real_alg, zero_smul]
@[simp] lemma zero_re' : re (0 : K) = (0 : ℝ) :=
by simp only [add_monoid_hom.map_zero]
@[simp] lemma of_real_one : 𝓚 1 = 1 := by rw [of_real_alg, one_smul]
@[simp] lemma one_re : re (1 : K) = 1 := by rw [←of_real_one, of_real_re]
@[simp] lemma one_im : im (1 : K) = 0 := by rw [←of_real_one, of_real_im]
@[simp] theorem of_real_inj {z w : ℝ} : 𝓚 z = 𝓚 w ↔ z = w :=
{ mp := λ h, by { convert congr_arg re h; simp only [of_real_re] },
mpr := λ h, by rw h }
@[simp] lemma bit0_re (z : K) : re (bit0 z) = bit0 (re z) := by simp [bit0]
@[simp] lemma bit1_re (z : K) : re (bit1 z) = bit1 (re z) :=
by simp only [bit1, add_monoid_hom.map_add, bit0_re, add_right_inj, one_re]
@[simp] lemma bit0_im (z : K) : im (bit0 z) = bit0 (im z) := by simp [bit0]
@[simp] lemma bit1_im (z : K) : im (bit1 z) = bit0 (im z) :=
by simp only [bit1, add_right_eq_self, add_monoid_hom.map_add, bit0_im, one_im]
@[simp] theorem of_real_eq_zero {z : ℝ} : 𝓚 z = 0 ↔ z = 0 :=
by rw [←of_real_zero]; exact of_real_inj
@[simp] lemma of_real_add ⦃r s : ℝ⦄ : 𝓚 (r + s) = 𝓚 r + 𝓚 s :=
by apply (@is_R_or_C.ext_iff K _ (𝓚 (r + s)) (𝓚 r + 𝓚 s)).mpr; simp
@[simp] lemma of_real_bit0 (r : ℝ) : 𝓚 (bit0 r : ℝ) = bit0 (𝓚 r) :=
ext_iff.2 $ by simp [bit0]
@[simp] lemma of_real_bit1 (r : ℝ) : 𝓚 (bit1 r : ℝ) = bit1 (𝓚 r) :=
ext_iff.2 $ by simp [bit1]
/- Note: This can be proven by `norm_num` once K is proven to be of characteristic zero below. -/
lemma two_ne_zero : (2 : K) ≠ 0 :=
begin
intro h, rw [(show (2 : K) = 𝓚 2, by norm_num), ←of_real_zero, of_real_inj] at h,
linarith,
end
@[simp] lemma of_real_neg (r : ℝ) : 𝓚 (-r) = -(𝓚 r) := ext_iff.2 $ by simp
@[simp] lemma of_real_mul (r s : ℝ) : 𝓚 (r * s) = (𝓚 r) * (𝓚 s) := ext_iff.2 $ by simp
lemma of_real_mul_re (r : ℝ) (z : K) : re ((𝓚 r) * z) = r * re z :=
by simp only [mul_re, of_real_im, zero_mul, of_real_re, sub_zero]
lemma smul_re (r : ℝ) (z : K) : re ((𝓚 r) * z) = r * (re z) :=
by simp only [of_real_im, zero_mul, of_real_re, sub_zero, mul_re]
lemma smul_im (r : ℝ) (z : K) : im ((𝓚 r) * z) = r * (im z) :=
by simp only [add_zero, of_real_im, zero_mul, of_real_re, mul_im]
lemma smul_re' : ∀ (r : ℝ) (z : K), re (r • z) = r * (re z) :=
λ r z, by { rw [smul_coe_mul_ax], apply smul_re }
lemma smul_im' : ∀ (r : ℝ) (z : K), im (r • z) = r * (im z) :=
λ r z, by { rw [smul_coe_mul_ax], apply smul_im }
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
@[simp] lemma I_re : re (I : K) = 0 := I_re_ax
@[simp] lemma I_im (z : K) : im z * im (I : K) = im z := mul_im_I_ax z
@[simp] lemma I_im' (z : K) : im (I : K) * im z = im z :=
by rw [mul_comm, I_im _]
lemma I_mul_I : (I : K) = 0 ∨ (I : K) * I = -1 := I_mul_I_ax
@[simp] lemma conj_re (z : K) : re (conj z) = re z := is_R_or_C.conj_re_ax z
@[simp] lemma conj_im (z : K) : im (conj z) = -(im z) := is_R_or_C.conj_im_ax z
@[simp] lemma conj_of_real (r : ℝ) : conj (𝓚 r) = (𝓚 r) :=
by { rw ext_iff, simp only [of_real_im, conj_im, eq_self_iff_true, conj_re, and_self, neg_zero] }
@[simp] lemma conj_bit0 (z : K) : conj (bit0 z) = bit0 (conj z) := by simp [bit0, ext_iff]
@[simp] lemma conj_bit1 (z : K) : conj (bit1 z) = bit1 (conj z) := by simp [bit0, ext_iff]
@[simp] lemma conj_neg_I : conj (-I) = (I : K) := by simp [ext_iff]
@[simp] lemma conj_conj (z : K) : conj (conj z) = z := by simp [ext_iff]
lemma conj_involutive : @function.involutive K is_R_or_C.conj := conj_conj
lemma conj_bijective : @function.bijective K K is_R_or_C.conj := conj_involutive.bijective
lemma conj_inj (z w : K) : conj z = conj w ↔ z = w := conj_bijective.1.eq_iff
@[simp] lemma conj_eq_zero {z : K} : conj z = 0 ↔ z = 0 :=
by simpa using @conj_inj K _ z 0
lemma eq_conj_iff_real {z : K} : conj z = z ↔ ∃ r : ℝ, z = (𝓚 r) :=
begin
split,
{ intro h,
suffices : im z = 0,
{ use (re z),
rw ← add_zero (of_real _),
convert (re_add_im z).symm, simp [this] },
contrapose! h,
rw ← re_add_im z,
simp only [conj_of_real, ring_hom.map_add, ring_hom.map_mul, conj_I_ax],
rw [add_left_cancel_iff, ext_iff],
simpa [neg_eq_iff_add_eq_zero, add_self_eq_zero] },
{ rintros ⟨r, rfl⟩, apply conj_of_real }
end
/-- Conjugation as a ring equivalence. This is used to convert the inner product into a
sesquilinear product. -/
def conj_to_ring_equiv : K ≃+* Kᵒᵖ :=
{ to_fun := opposite.op ∘ conj,
inv_fun := conj ∘ opposite.unop,
left_inv := λ x, by simp only [conj_conj, function.comp_app, opposite.unop_op],
right_inv := λ x, by simp only [conj_conj, opposite.op_unop, function.comp_app],
map_mul' := λ x y, by simp [mul_comm],
map_add' := λ x y, by simp }
lemma eq_conj_iff_re {z : K} : conj z = z ↔ 𝓚 (re z) = z :=
eq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩
/-- The norm squared function. -/
def norm_sq (z : K) : ℝ := re z * re z + im z * im z
lemma norm_sq_eq_def {z : K} : ∥z∥^2 = (re z) * (re z) + (im z) * (im z) := norm_sq_eq_def_ax z
lemma norm_sq_eq_def' (z : K) : norm_sq z = ∥z∥^2 := by rw [norm_sq_eq_def, norm_sq]
@[simp] lemma norm_sq_of_real (r : ℝ) : ∥𝓚 r∥^2 = r * r :=
by simp [norm_sq_eq_def]
@[simp] lemma norm_sq_zero : norm_sq (0 : K) = 0 := by simp [norm_sq, pow_two]
@[simp] lemma norm_sq_one : norm_sq (1 : K) = 1 := by simp [norm_sq]
lemma norm_sq_nonneg (z : K) : 0 ≤ norm_sq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
@[simp] lemma norm_sq_eq_zero {z : K} : norm_sq z = 0 ↔ z = 0 :=
by { rw [norm_sq, ←norm_sq_eq_def], simp [pow_two] }
@[simp] lemma norm_sq_pos {z : K} : 0 < norm_sq z ↔ z ≠ 0 :=
by rw [lt_iff_le_and_ne, ne, eq_comm]; simp [norm_sq_nonneg]
@[simp] lemma norm_sq_neg (z : K) : norm_sq (-z) = norm_sq z :=
by simp [norm_sq]
@[simp] lemma norm_sq_conj (z : K) : norm_sq (conj z) = norm_sq z := by simp [norm_sq]
@[simp] lemma norm_sq_mul (z w : K) : norm_sq (z * w) = norm_sq z * norm_sq w :=
by simp [norm_sq, pow_two]; ring
lemma norm_sq_add (z w : K) :
norm_sq (z + w) = norm_sq z + norm_sq w + 2 * (re (z * conj w)) :=
by simp [norm_sq, pow_two]; ring
lemma re_sq_le_norm_sq (z : K) : re z * re z ≤ norm_sq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
lemma im_sq_le_norm_sq (z : K) : im z * im z ≤ norm_sq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : K) : z * conj z = 𝓚 (norm_sq z) :=
by simp [ext_iff, norm_sq, mul_comm, sub_eq_neg_add, add_comm]
theorem add_conj (z : K) : z + conj z = 𝓚 (2 * re z) :=
by simp [ext_iff, two_mul]
/-- The pseudo-coercion `of_real` as a `ring_hom`. -/
def of_real_hom : ℝ →+* K := ⟨of_real, of_real_one, of_real_mul, of_real_zero, of_real_add⟩
@[simp] lemma of_real_sub (r s : ℝ) : 𝓚 (r - s : ℝ) = 𝓚 r - 𝓚 s := ext_iff.2 $ by simp
@[simp] lemma of_real_pow (r : ℝ) (n : ℕ) : 𝓚 (r ^ n : ℝ) = (𝓚 r) ^ n :=
by induction n; simp [*, of_real_mul, pow_succ]
theorem sub_conj (z : K) : z - conj z = 𝓚 (2 * im z) * I :=
by simp [ext_iff, two_mul, sub_eq_add_neg, add_mul, mul_im_I_ax]
lemma norm_sq_sub (z w : K) : norm_sq (z - w) =
norm_sq z + norm_sq w - 2 * re (z * conj w) :=
by simp [-mul_re, norm_sq_add, add_comm, add_left_comm, sub_eq_add_neg]
lemma sqrt_norm_sq_eq_norm {z : K} : real.sqrt (norm_sq z) = ∥z∥ :=
begin
have h₁ : (norm_sq z) = ∥z∥^2 := by rw [norm_sq_eq_def, norm_sq],
have h₂ : ∥z∥ = real.sqrt (∥z∥^2) := eq_comm.mp (real.sqrt_sqr (norm_nonneg z)),
rw [h₂],
exact congr_arg real.sqrt h₁
end
/-! ### Inversion -/
@[simp] lemma inv_re (z : K) : re (z⁻¹) = re z / norm_sq z :=
by simp [inv_def, norm_sq_eq_def, norm_sq, division_def]
@[simp] lemma inv_im (z : K) : im (z⁻¹) = im (-z) / norm_sq z :=
by simp [inv_def, norm_sq_eq_def, norm_sq, division_def]
@[simp] lemma of_real_inv (r : ℝ) : 𝓚 (r⁻¹) = (𝓚 r)⁻¹ :=
begin
rw ext_iff, by_cases r = 0, { simp [h] },
{ simp; field_simp [h, norm_sq] },
end
protected lemma inv_zero : (0⁻¹ : K) = 0 :=
by rw [← of_real_zero, ← of_real_inv, inv_zero]
protected theorem mul_inv_cancel {z : K} (h : z ≠ 0) : z * z⁻¹ = 1 :=
by rw [inv_def, ←mul_assoc, mul_conj, ←of_real_mul, ←norm_sq_eq_def',
mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]
lemma div_re (z w : K) : re (z / w) = re z * re w / norm_sq w + im z * im w / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]
lemma div_im (z w : K) : im (z / w) = im z * re w / norm_sq w - re z * im w / norm_sq w :=
by simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]
@[simp] lemma of_real_div (r s : ℝ) : 𝓚 (r / s : ℝ) = 𝓚 r / 𝓚 s :=
(@is_R_or_C.of_real_hom K _).map_div r s
lemma div_re_of_real {z : K} {r : ℝ} : re (z / (𝓚 r)) = re z / r :=
begin
by_cases h : r = 0,
{ simp [h, of_real_zero] },
{ change r ≠ 0 at h,
rw [div_eq_mul_inv, ←of_real_inv, div_eq_mul_inv],
simp [norm_sq, norm_sq_of_real, div_mul_eq_div_mul_one_div, div_self h] }
end
@[simp] lemma of_real_fpow (r : ℝ) (n : ℤ) : 𝓚 (r ^ n) = (𝓚 r) ^ n :=
(@is_R_or_C.of_real_hom K _).map_fpow r n
lemma I_mul_I_of_nonzero : (I : K) ≠ 0 → (I : K) * I = -1 :=
by { have := I_mul_I_ax, tauto }
@[simp] lemma div_I (z : K) : z / I = -(z * I) :=
begin
by_cases h : (I : K) = 0,
{ simp [h] },
{ field_simp [h], simp [mul_assoc, I_mul_I_of_nonzero h] }
end
@[simp] lemma inv_I : (I : K)⁻¹ = -I :=
by { by_cases h : (I : K) = 0; field_simp [h] }
@[simp] lemma norm_sq_inv (z : K) : norm_sq z⁻¹ = (norm_sq z)⁻¹ :=
begin
by_cases z = 0,
{ simp [h] },
{ refine mul_right_cancel' (mt norm_sq_eq_zero.1 h) _,
simp [h, ←norm_sq_mul], }
end
@[simp] lemma norm_sq_div (z w : K) : norm_sq (z / w) = norm_sq z / norm_sq w :=
by { rw [division_def, norm_sq_mul, norm_sq_inv], refl }
lemma norm_conj {z : K} : ∥conj z∥ = ∥z∥ :=
by simp only [←sqrt_norm_sq_eq_norm, norm_sq_conj]
lemma conj_inv {z : K} : conj (z⁻¹) = (conj z)⁻¹ :=
by simp only [inv_def, norm_conj, ring_hom.map_mul, conj_of_real]
lemma conj_div {z w : K} : conj (z / w) = (conj z) / (conj w) :=
by rw [div_eq_inv_mul, div_eq_inv_mul, ring_hom.map_mul]; simp only [conj_inv]
/-! ### Cast lemmas -/
@[simp] theorem of_real_nat_cast (n : ℕ) : 𝓚 (n : ℝ) = n :=
of_real_hom.map_nat_cast n
@[simp] lemma nat_cast_re (n : ℕ) : re (n : K) = n :=
by rw [← of_real_nat_cast, of_real_re]
@[simp] lemma nat_cast_im (n : ℕ) : im (n : K) = 0 :=
by rw [← of_real_nat_cast, of_real_im]
@[simp] theorem of_real_int_cast (n : ℤ) : 𝓚 (n : ℝ) = n :=
of_real_hom.map_int_cast n
@[simp] lemma int_cast_re (n : ℤ) : re (n : K) = n :=
by rw [← of_real_int_cast, of_real_re]
@[simp] lemma int_cast_im (n : ℤ) : im (n : K) = 0 :=
by rw [← of_real_int_cast, of_real_im]
@[simp] theorem of_real_rat_cast (n : ℚ) : 𝓚 (n : ℝ) = n :=
(@is_R_or_C.of_real_hom K _).map_rat_cast n
@[simp] lemma rat_cast_re (q : ℚ) : re (q : K) = q :=
by rw [← of_real_rat_cast, of_real_re]
@[simp] lemma rat_cast_im (q : ℚ) : im (q : K) = 0 :=
by rw [← of_real_rat_cast, of_real_im]
/-! ### Characteristic zero -/
/--
ℝ and ℂ are both of characteristic zero.
Note: This is not registered as an instance to avoid having multiple instances on ℝ and ℂ.
-/
lemma char_zero_R_or_C : char_zero K :=
char_zero_of_inj_zero $ λ n h,
by rwa [← of_real_nat_cast, of_real_eq_zero, nat.cast_eq_zero] at h
theorem re_eq_add_conj (z : K) : 𝓚 (re z) = (z + conj z) / 2 :=
by rw [add_conj]; simp; rw [mul_div_cancel_left (𝓚 (re z)) two_ne_zero]
/-! ### Absolute value -/
/-- The complex absolute value function, defined as the square root of the norm squared. -/
@[pp_nodot] noncomputable def abs (z : K) : ℝ := (norm_sq z).sqrt
local notation `abs'` := _root_.abs
local notation `absK` := @abs K _
@[simp] lemma abs_of_real (r : ℝ) : absK (𝓚 r) = abs' r :=
by simp [abs, norm_sq, norm_sq_of_real, real.sqrt_mul_self_eq_abs]
lemma abs_of_nonneg {r : ℝ} (h : 0 ≤ r) : absK (𝓚 r) = r :=
(abs_of_real _).trans (abs_of_nonneg h)
lemma abs_of_nat (n : ℕ) : absK n = n :=
by { rw [← of_real_nat_cast], exact abs_of_nonneg (nat.cast_nonneg n) }
lemma mul_self_abs (z : K) : abs z * abs z = norm_sq z :=
real.mul_self_sqrt (norm_sq_nonneg _)
@[simp] lemma abs_zero : absK 0 = 0 := by simp [abs]
@[simp] lemma abs_one : absK 1 = 1 := by simp [abs]
@[simp] lemma abs_two : absK 2 = 2 :=
calc absK 2 = absK (𝓚 2) : by rw [of_real_bit0, of_real_one]
... = (2 : ℝ) : abs_of_nonneg (by norm_num)
lemma abs_nonneg (z : K) : 0 ≤ absK z :=
real.sqrt_nonneg _
@[simp] lemma abs_eq_zero {z : K} : absK z = 0 ↔ z = 0 :=
(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero
lemma abs_ne_zero {z : K} : abs z ≠ 0 ↔ z ≠ 0 :=
not_congr abs_eq_zero
@[simp] lemma abs_conj (z : K) : abs (conj z) = abs z :=
by simp [abs]
@[simp] lemma abs_mul (z w : K) : abs (z * w) = abs z * abs w :=
by rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl
lemma abs_re_le_abs (z : K) : abs' (re z) ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg (re z)) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply re_sq_le_norm_sq
lemma abs_im_le_abs (z : K) : abs' (im z) ≤ abs z :=
by rw [mul_self_le_mul_self_iff (_root_.abs_nonneg (im z)) (abs_nonneg _),
abs_mul_abs_self, mul_self_abs];
apply im_sq_le_norm_sq
lemma re_le_abs (z : K) : re z ≤ abs z :=
(abs_le.1 (abs_re_le_abs _)).2
lemma im_le_abs (z : K) : im z ≤ abs z :=
(abs_le.1 (abs_im_le_abs _)).2
lemma abs_add (z w : K) : abs (z + w) ≤ abs z + abs w :=
(mul_self_le_mul_self_iff (abs_nonneg _)
(add_nonneg (abs_nonneg _) (abs_nonneg _))).2 $
begin
rw [mul_self_abs, add_mul_self_eq, mul_self_abs, mul_self_abs,
add_right_comm, norm_sq_add, add_le_add_iff_left,
mul_assoc, mul_le_mul_left (@zero_lt_two ℝ _)],
simpa [-mul_re] using re_le_abs (z * conj w)
end
instance : is_absolute_value absK :=
{ abv_nonneg := abs_nonneg,
abv_eq_zero := λ _, abs_eq_zero,
abv_add := abs_add,
abv_mul := abs_mul }
open is_absolute_value
@[simp] lemma abs_abs (z : K) : abs' (abs z) = abs z :=
_root_.abs_of_nonneg (abs_nonneg _)
@[simp] lemma abs_pos {z : K} : 0 < abs z ↔ z ≠ 0 := abv_pos abs
@[simp] lemma abs_neg : ∀ z : K, abs (-z) = abs z := abv_neg abs
lemma abs_sub : ∀ z w : K, abs (z - w) = abs (w - z) := abv_sub abs
lemma abs_sub_le : ∀ a b c : K, abs (a - c) ≤ abs (a - b) + abs (b - c) := abv_sub_le abs
@[simp] theorem abs_inv : ∀ z : K, abs z⁻¹ = (abs z)⁻¹ := abv_inv abs
@[simp] theorem abs_div : ∀ z w : K, abs (z / w) = abs z / abs w := abv_div abs
lemma abs_abs_sub_le_abs_sub : ∀ z w : K, abs' (abs z - abs w) ≤ abs (z - w) :=
abs_abv_sub_le_abv_sub abs
lemma abs_re_div_abs_le_one (z : K) : abs' (re z / abs z) ≤ 1 :=
begin
by_cases hz : z = 0,
{ simp [hz, zero_le_one] },
{ simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_re_le_abs] }
end
lemma abs_im_div_abs_le_one (z : K) : abs' (im z / abs z) ≤ 1 :=
begin
by_cases hz : z = 0,
{ simp [hz, zero_le_one] },
{ simp_rw [_root_.abs_div, abs_abs, div_le_iff (abs_pos.2 hz), one_mul, abs_im_le_abs] }
end
@[simp] lemma abs_cast_nat (n : ℕ) : abs (n : K) = n :=
by rw [← of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]
lemma norm_sq_eq_abs (x : K) : norm_sq x = abs x ^ 2 :=
by rw [abs, pow_two, real.mul_self_sqrt (norm_sq_nonneg _)]
lemma re_eq_abs_of_mul_conj (x : K) : re (x * (conj x)) = abs (x * (conj x)) :=
by rw [mul_conj, of_real_re, abs_of_real, norm_sq_eq_abs, pow_two, _root_.abs_mul, abs_abs]
lemma abs_sqr_re_add_conj (x : K) : (abs (x + x†))^2 = (re (x + x†))^2 :=
by simp [pow_two, ←norm_sq_eq_abs, norm_sq]
lemma abs_sqr_re_add_conj' (x : K) : (abs (x† + x))^2 = (re (x† + x))^2 :=
by simp [pow_two, ←norm_sq_eq_abs, norm_sq]
lemma conj_mul_eq_norm_sq_left (x : K) : x† * x = 𝓚 (norm_sq x) :=
begin
rw ext_iff,
refine ⟨by simp [of_real_re, mul_re, conj_re, conj_im, norm_sq],_⟩,
simp [of_real_im, mul_im, conj_im, conj_re, mul_comm],
end
/-! ### Cauchy sequences -/
theorem is_cau_seq_re (f : cau_seq K abs) : is_cau_seq abs' (λ n, re (f n)) :=
λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij,
lt_of_le_of_lt (by simpa using abs_re_le_abs (f j - f i)) (H _ ij)
theorem is_cau_seq_im (f : cau_seq K abs) : is_cau_seq abs' (λ n, im (f n)) :=
λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij,
lt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)
/-- The real part of a K Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_re (f : cau_seq K abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_re f⟩
/-- The imaginary part of a K Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cau_seq_im (f : cau_seq K abs) : cau_seq ℝ abs' :=
⟨_, is_cau_seq_im f⟩
lemma is_cau_seq_abs {f : ℕ → K} (hf : is_cau_seq abs f) :
is_cau_seq abs' (abs ∘ f) :=
λ ε ε0, let ⟨i, hi⟩ := hf ε ε0 in
⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩
end is_R_or_C
section instances
noncomputable instance real.is_R_or_C : is_R_or_C ℝ :=
{ re := add_monoid_hom.id ℝ,
im := 0,
conj := ring_hom.id ℝ,
I := 0,
of_real := id,
I_re_ax := by simp only [add_monoid_hom.map_zero],
I_mul_I_ax := or.intro_left _ rfl,
re_add_im_ax := λ z, by unfold_coes; simp [add_zero, id.def, mul_zero],
smul_coe_mul_ax := λ z r, by simp only [algebra.id.smul_eq_mul, id.def],
of_real_re_ax := λ r, by simp only [id.def, add_monoid_hom.id_apply],
of_real_im_ax := λ r, by simp only [add_monoid_hom.zero_apply],
mul_re_ax := λ z w, by simp only [sub_zero, mul_zero, add_monoid_hom.zero_apply, add_monoid_hom.id_apply],
mul_im_ax := λ z w, by simp only [add_zero, zero_mul, mul_zero, add_monoid_hom.zero_apply],
conj_re_ax := λ z, by simp only [ring_hom.id_apply],
conj_im_ax := λ z, by simp only [neg_zero, add_monoid_hom.zero_apply],
conj_I_ax := by simp only [ring_hom.map_zero, neg_zero],
norm_sq_eq_def_ax := λ z, by simp only [pow_two, norm, ←abs_mul, abs_mul_self z, add_zero, mul_zero, add_monoid_hom.zero_apply, add_monoid_hom.id_apply],
mul_im_I_ax := λ z, by simp only [mul_zero, add_monoid_hom.zero_apply],
inv_def_ax :=
begin
intro z,
unfold_coes,
have H : z ≠ 0 → 1 / z = z / (z * z) := λ h,
calc
1 / z = 1 * (1 / z) : (one_mul (1 / z)).symm
... = (z / z) * (1 / z) : congr_arg (λ x, x * (1 / z)) (div_self h).symm
... = z / (z * z) : by field_simp,
rcases lt_trichotomy z 0 with hlt|heq|hgt,
{ field_simp [norm, abs, max_eq_right_of_lt (show z < -z, by linarith), pow_two, mul_inv', ←H (ne_of_lt hlt)] },
{ simp [heq] },
{ field_simp [norm, abs, max_eq_left_of_lt (show -z < z, by linarith), pow_two, mul_inv', ←H (ne_of_gt hgt)] },
end,
div_I_ax := λ z, by simp only [div_zero, mul_zero, neg_zero]}
noncomputable instance complex.is_R_or_C : is_R_or_C ℂ :=
{ re := ⟨complex.re, complex.zero_re, complex.add_re⟩,
im := ⟨complex.im, complex.zero_im, complex.add_im⟩,
conj := complex.conj,
I := complex.I,
of_real := coe,
I_re_ax := by simp only [add_monoid_hom.coe_mk, complex.I_re],
I_mul_I_ax := by simp only [complex.I_mul_I, eq_self_iff_true, or_true],
re_add_im_ax := by simp only [forall_const, add_monoid_hom.coe_mk, complex.re_add_im, eq_self_iff_true],
smul_coe_mul_ax := λ z r, rfl,
of_real_re_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_re],
of_real_im_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_im],
mul_re_ax := λ z w, by simp only [complex.mul_re, add_monoid_hom.coe_mk],
mul_im_ax := λ z w, by simp only [add_monoid_hom.coe_mk, complex.mul_im],
conj_re_ax := λ z, by simp only [ring_hom.coe_mk, add_monoid_hom.coe_mk, complex.conj_re],
conj_im_ax := λ z, by simp only [ring_hom.coe_mk, complex.conj_im, add_monoid_hom.coe_mk],
conj_I_ax := by simp only [complex.conj_I, ring_hom.coe_mk],
norm_sq_eq_def_ax := λ z, by simp only [←complex.norm_sq_eq_abs, ←complex.norm_sq, add_monoid_hom.coe_mk, complex.norm_eq_abs],
mul_im_I_ax := λ z, by simp only [mul_one, add_monoid_hom.coe_mk, complex.I_im],
inv_def_ax := λ z, by convert complex.inv_def z; exact (complex.norm_sq_eq_abs z).symm,
div_I_ax := complex.div_I }
end instances
namespace is_R_or_C
section cleanup_lemmas
local notation `reR` := @is_R_or_C.re ℝ _
local notation `imR` := @is_R_or_C.im ℝ _
local notation `conjR` := @is_R_or_C.conj ℝ _
local notation `IR` := @is_R_or_C.I ℝ _
local notation `of_realR` := @is_R_or_C.of_real ℝ _
local notation `absR` := @is_R_or_C.abs ℝ _
local notation `norm_sqR` := @is_R_or_C.norm_sq ℝ _
local notation `reC` := @is_R_or_C.re ℂ _
local notation `imC` := @is_R_or_C.im ℂ _
local notation `conjC` := @is_R_or_C.conj ℂ _
local notation `IC` := @is_R_or_C.I ℂ _
local notation `of_realC` := @is_R_or_C.of_real ℂ _
local notation `absC` := @is_R_or_C.abs ℂ _
local notation `norm_sqC` := @is_R_or_C.norm_sq ℂ _
@[simp] lemma re_to_real {x : ℝ} : reR x = x := rfl
@[simp] lemma im_to_real {x : ℝ} : imR x = 0 := rfl
@[simp] lemma conj_to_real {x : ℝ} : conjR x = x := rfl
@[simp] lemma I_to_real : IR = 0 := rfl
@[simp] lemma of_real_to_real {x : ℝ} : of_realR x = x := rfl
@[simp] lemma norm_sq_to_real {x : ℝ} : norm_sqR x = x*x := by simp [is_R_or_C.norm_sq]
@[simp] lemma abs_to_real {x : ℝ} : absR x = _root_.abs x :=
by simp [is_R_or_C.abs, abs, real.sqrt_mul_self_eq_abs]
@[simp] lemma re_to_complex {x : ℂ} : reC x = x.re := rfl
@[simp] lemma im_to_complex {x : ℂ} : imC x = x.im := rfl
@[simp] lemma conj_to_complex {x : ℂ} : conjC x = x.conj := rfl
@[simp] lemma I_to_complex : IC = complex.I := rfl
@[simp] lemma of_real_to_complex {x : ℝ} : of_realC x = x := rfl
@[simp] lemma norm_sq_to_complex {x : ℂ} : norm_sqC x = complex.norm_sq x :=
by simp [is_R_or_C.norm_sq, complex.norm_sq]
@[simp] lemma abs_to_complex {x : ℂ} : absC x = complex.abs x :=
by simp [is_R_or_C.abs, complex.abs]
end cleanup_lemmas
end is_R_or_C
|
bd3beffd2719d46c04b4522db7288ac0769ed4bd | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/analysis/calculus/fderiv_symmetric.lean | b5cd69507ceb803980a05f34619f918527fa64de | [
"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 | 19,573 | lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.calculus.deriv
import analysis.calculus.mean_value
import analysis.convex.topology
/-!
# Symmetry of the second derivative
We show that, over the reals, the second derivative is symmetric.
The most precise result is `convex.second_derivative_within_at_symmetric`. It asserts that,
if a function is differentiable inside a convex set `s` with nonempty interior, and has a second
derivative within `s` at a point `x`, then this second derivative at `x` is symmetric. Note that
this result does not require continuity of the first derivative.
The following particular cases of this statement are especially relevant:
`second_derivative_symmetric_of_eventually` asserts that, if a function is differentiable on a
neighborhood of `x`, and has a second derivative at `x`, then this second derivative is symmetric.
`second_derivative_symmetric` asserts that, if a function is differentiable, and has a second
derivative at `x`, then this second derivative is symmetric.
## Implementation note
For the proof, we obtain an asymptotic expansion to order two of `f (x + v + w) - f (x + v)`, by
using the mean value inequality applied to a suitable function along the
segment `[x + v, x + v + w]`. This expansion involves `f'' ⬝ w` as we move along a segment directed
by `w` (see `convex.taylor_approx_two_segment`).
Consider the alternate sum `f (x + v + w) + f x - f (x + v) - f (x + w)`, corresponding to the
values of `f` along a rectangle based at `x` with sides `v` and `w`. One can write it using the two
sides directed by `w`, as `(f (x + v + w) - f (x + v)) - (f (x + w) - f x)`. Together with the
previous asymptotic expansion, one deduces that it equals `f'' v w + o(1)` when `v, w` tends to `0`.
Exchanging the roles of `v` and `w`, one instead gets an asymptotic expansion `f'' w v`, from which
the equality `f'' v w = f'' w v` follows.
In our most general statement, we only assume that `f` is differentiable inside a convex set `s`, so
a few modifications have to be made. Since we don't assume continuity of `f` at `x`, we consider
instead the rectangle based at `x + v + w` with sides `v` and `w`,
in `convex.is_o_alternate_sum_square`, but the argument is essentially the same. It only works
when `v` and `w` both point towards the interior of `s`, to make sure that all the sides of the
rectangle are contained in `s` by convexity. The general case follows by linearity, though.
-/
open asymptotics set
open_locale topological_space
variables {E F : Type*} [normed_group E] [normed_space ℝ E]
[normed_group F] [normed_space ℝ F]
{s : set E} (s_conv : convex s)
{f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)}
(hf : ∀ x ∈ interior s, has_fderiv_at f (f' x) x)
{x : E} (xs : x ∈ s) (hx : has_fderiv_within_at f' f'' (interior s) x)
include s_conv xs hx hf
/-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is
differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one can
Taylor-expand to order two the function `f` on the segment `[x + h v, x + h (v + w)]`, giving a
bilinear estimate for `f (x + hv + hw) - f (x + hv)` in terms of `f' w` and of `f'' ⬝ w`, up to
`o(h^2)`.
This is a technical statement used to show that the second derivative is symmetric.
-/
lemma convex.taylor_approx_two_segment
{v w : E} (hv : x + v ∈ interior s) (hw : x + v + w ∈ interior s) :
is_o (λ (h : ℝ), f (x + h • v + h • w) - f (x + h • v) - h • f' x w
- h^2 • f'' v w - (h^2/2) • f'' w w) (λ h, h^2) (𝓝[Ioi (0 : ℝ)] 0) :=
begin
-- it suffices to check that the expression is bounded by `ε * ((∥v∥ + ∥w∥) * ∥w∥) * h^2` for
-- small enough `h`, for any positive `ε`.
apply is_o.trans_is_O (is_o_iff.2 (λ ε εpos, _)) (is_O_const_mul_self ((∥v∥ + ∥w∥) * ∥w∥) _ _),
-- consider a ball of radius `δ` around `x` in which the Taylor approximation for `f''` is
-- good up to `δ`.
rw [has_fderiv_within_at, has_fderiv_at_filter, is_o_iff] at hx,
rcases metric.mem_nhds_within_iff.1 (hx εpos) with ⟨δ, δpos, sδ⟩,
have E1 : ∀ᶠ h in 𝓝[Ioi (0:ℝ)] 0, h * (∥v∥ + ∥w∥) < δ,
{ have : filter.tendsto (λ h, h * (∥v∥ + ∥w∥)) (𝓝[Ioi (0:ℝ)] 0) (𝓝 (0 * (∥v∥ + ∥w∥))) :=
(continuous_id.mul continuous_const).continuous_within_at,
apply (tendsto_order.1 this).2 δ,
simpa only [zero_mul] using δpos },
have E2 : ∀ᶠ h in 𝓝[Ioi (0:ℝ)] 0, (h : ℝ) < 1 :=
mem_nhds_within_Ioi_iff_exists_Ioo_subset.2
⟨(1 : ℝ), by simp only [mem_Ioi, zero_lt_one], λ x hx, hx.2⟩,
filter_upwards [E1, E2, self_mem_nhds_within],
-- we consider `h` small enough that all points under consideration belong to this ball,
-- and also with `0 < h < 1`.
assume h hδ h_lt_1 hpos,
replace hpos : 0 < h := hpos,
have xt_mem : ∀ t ∈ Icc (0 : ℝ) 1, x + h • v + (t * h) • w ∈ interior s,
{ assume t ht,
have : x + h • v ∈ interior s :=
s_conv.add_smul_mem_interior xs hv ⟨hpos, h_lt_1.le⟩,
rw [← smul_smul],
apply s_conv.interior.add_smul_mem this _ ht,
rw add_assoc at hw,
convert s_conv.add_smul_mem_interior xs hw ⟨hpos, h_lt_1.le⟩ using 1,
simp only [add_assoc, smul_add] },
-- define a function `g` on `[0,1]` (identified with `[v, v + w]`) such that `g 1 - g 0` is the
-- quantity to be estimated. We will check that its derivative is given by an explicit
-- expression `g'`, that we can bound. Then the desired bound for `g 1 - g 0` follows from the
-- mean value inequality.
let g := λ t, f (x + h • v + (t * h) • w) - (t * h) • f' x w - (t * h^2) • f'' v w
- ((t * h)^2/2) • f'' w w,
set g' := λ t, f' (x + h • v + (t * h) • w) (h • w) - h • f' x w
- h^2 • f'' v w - (t * h^2) • f'' w w with hg',
-- check that `g'` is the derivative of `g`, by a straightforward computation
have g_deriv : ∀ t ∈ Icc (0 : ℝ) 1, has_deriv_within_at g (g' t) (Icc 0 1) t,
{ assume t ht,
apply_rules [has_deriv_within_at.sub, has_deriv_within_at.add],
{ refine (hf _ _).comp_has_deriv_within_at _ _,
{ exact xt_mem t ht },
apply has_deriv_at.has_deriv_within_at,
suffices : has_deriv_at (λ u, x + h • v + (u * h) • w) (0 + 0 + (1 * h) • w) t,
by simpa only [one_mul, zero_add],
apply_rules [has_deriv_at.add, has_deriv_at_const, has_deriv_at.smul_const,
has_deriv_at_id'] },
{ suffices : has_deriv_within_at (λ u, (u * h) • f' x w) ((1 * h) • f' x w) (Icc 0 1) t,
by simpa only [one_mul],
apply_rules [has_deriv_at.has_deriv_within_at, has_deriv_at.smul_const, has_deriv_at_id'] },
{ suffices : has_deriv_within_at (λ u, (u * h ^ 2) • f'' v w) ((1 * h^2) • f'' v w) (Icc 0 1) t,
by simpa only [one_mul],
apply_rules [has_deriv_at.has_deriv_within_at, has_deriv_at.smul_const, has_deriv_at_id'] },
{ suffices H : has_deriv_within_at (λ u, ((u * h) ^ 2 / 2) • f'' w w)
(((((2 : ℕ) : ℝ) * (t * h) ^ (2 - 1) * (1 * h))/2) • f'' w w) (Icc 0 1) t,
{ convert H using 2,
simp only [one_mul, nat.cast_bit0, pow_one, nat.cast_one],
ring },
apply_rules [has_deriv_at.has_deriv_within_at, has_deriv_at.smul_const, has_deriv_at_id',
has_deriv_at.pow] } },
-- check that `g'` is uniformly bounded, with a suitable bound `ε * ((∥v∥ + ∥w∥) * ∥w∥) * h^2`.
have g'_bound : ∀ t ∈ Ico (0 : ℝ) 1, ∥g' t∥ ≤ ε * ((∥v∥ + ∥w∥) * ∥w∥) * h^2,
{ assume t ht,
have I : ∥h • v + (t * h) • w∥ ≤ h * (∥v∥ + ∥w∥) := calc
∥h • v + (t * h) • w∥ ≤ ∥h • v∥ + ∥(t * h) • w∥ : norm_add_le _ _
... = h * ∥v∥ + t * (h * ∥w∥) :
by simp only [norm_smul, real.norm_eq_abs, hpos.le, abs_of_nonneg, abs_mul, ht.left,
mul_assoc]
... ≤ h * ∥v∥ + 1 * (h * ∥w∥) :
add_le_add (le_refl _) (mul_le_mul_of_nonneg_right ht.2.le
(mul_nonneg hpos.le (norm_nonneg _)))
... = h * (∥v∥ + ∥w∥) : by ring,
calc ∥g' t∥ = ∥(f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)) (h • w)∥ :
begin
rw hg',
have : h * (t * h) = t * (h * h), by ring,
simp only [continuous_linear_map.coe_sub', continuous_linear_map.map_add, pow_two,
continuous_linear_map.add_apply, pi.smul_apply, smul_sub, smul_add, smul_smul, ← sub_sub,
continuous_linear_map.coe_smul', pi.sub_apply, continuous_linear_map.map_smul, this]
end
... ≤ ∥f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)∥ * ∥h • w∥ :
continuous_linear_map.le_op_norm _ _
... ≤ (ε * ∥h • v + (t * h) • w∥) * (∥h • w∥) :
begin
apply mul_le_mul_of_nonneg_right _ (norm_nonneg _),
have H : x + h • v + (t * h) • w ∈ metric.ball x δ ∩ interior s,
{ refine ⟨_, xt_mem t ⟨ht.1, ht.2.le⟩⟩,
rw [add_assoc, add_mem_ball_iff_norm],
exact I.trans_lt hδ },
have := sδ H,
simp only [mem_set_of_eq] at this,
convert this;
abel
end
... ≤ (ε * (∥h • v∥ + ∥h • w∥)) * (∥h • w∥) :
begin
apply mul_le_mul_of_nonneg_right _ (norm_nonneg _),
apply mul_le_mul_of_nonneg_left _ (εpos.le),
apply (norm_add_le _ _).trans,
refine add_le_add (le_refl _) _,
simp only [norm_smul, real.norm_eq_abs, abs_mul, abs_of_nonneg, ht.1, hpos.le, mul_assoc],
exact mul_le_of_le_one_left (mul_nonneg hpos.le (norm_nonneg _)) ht.2.le,
end
... = ε * ((∥v∥ + ∥w∥) * ∥w∥) * h^2 :
by { simp only [norm_smul, real.norm_eq_abs, abs_mul, abs_of_nonneg, hpos.le], ring } },
-- conclude using the mean value inequality
have I : ∥g 1 - g 0∥ ≤ ε * ((∥v∥ + ∥w∥) * ∥w∥) * h^2, by simpa only [mul_one, sub_zero] using
norm_image_sub_le_of_norm_deriv_le_segment' g_deriv g'_bound 1 (right_mem_Icc.2 zero_le_one),
convert I using 1,
{ congr' 1,
dsimp only [g],
simp only [nat.one_ne_zero, add_zero, one_mul, zero_div, zero_mul, sub_zero, zero_smul,
ne.def, not_false_iff, bit0_eq_zero, zero_pow'],
abel },
{ simp only [real.norm_eq_abs, abs_mul, add_nonneg (norm_nonneg v) (norm_nonneg w),
abs_of_nonneg, mul_assoc, pow_bit0_abs, norm_nonneg, abs_pow] }
end
/-- One can get `f'' v w` as the limit of `h ^ (-2)` times the alternate sum of the values of `f`
along the vertices of a quadrilateral with sides `h v` and `h w` based at `x`.
In a setting where `f` is not guaranteed to be continuous at `f`, we can still
get this if we use a quadrilateral based at `h v + h w`. -/
lemma convex.is_o_alternate_sum_square
{v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) :
is_o (λ (h : ℝ), f (x + h • (2 • v + 2 • w)) + f (x + h • (v + w))
- f (x + h • (2 • v + w)) - f (x + h • (v + 2 • w)) - h^2 • f'' v w)
(λ h, h^2) (𝓝[Ioi (0 : ℝ)] 0) :=
begin
have A : (1 : ℝ)/2 ∈ Ioc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩,
have B : (1 : ℝ)/2 ∈ Icc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩,
have C : ∀ (w : E), (2 : ℝ) • w = 2 • w := λ w, by simp only [two_smul],
have h2v2w : x + (2 : ℝ) • v + (2 : ℝ) • w ∈ interior s,
{ convert s_conv.interior.add_smul_sub_mem h4v h4w B using 1,
simp only [smul_sub, smul_smul, one_div, add_sub_add_left_eq_sub, mul_add, add_smul],
norm_num,
simp only [show (4 : ℝ) = (2 : ℝ) + (2 : ℝ), by norm_num, add_smul],
abel },
have h2vww : x + (2 • v + w) + w ∈ interior s,
{ convert h2v2w using 1,
simp only [two_smul],
abel },
have h2v : x + (2 : ℝ) • v ∈ interior s,
{ convert s_conv.add_smul_sub_mem_interior xs h4v A using 1,
simp only [smul_smul, one_div, add_sub_cancel', add_right_inj],
norm_num },
have h2w : x + (2 : ℝ) • w ∈ interior s,
{ convert s_conv.add_smul_sub_mem_interior xs h4w A using 1,
simp only [smul_smul, one_div, add_sub_cancel', add_right_inj],
norm_num },
have hvw : x + (v + w) ∈ interior s,
{ convert s_conv.add_smul_sub_mem_interior xs h2v2w A using 1,
simp only [smul_smul, one_div, add_sub_cancel', add_right_inj, smul_add, smul_sub],
norm_num,
abel },
have h2vw : x + (2 • v + w) ∈ interior s,
{ convert s_conv.interior.add_smul_sub_mem h2v h2v2w B using 1,
simp only [smul_add, smul_sub, smul_smul, ← C],
norm_num,
abel },
have hvww : x + (v + w) + w ∈ interior s,
{ convert s_conv.interior.add_smul_sub_mem h2w h2v2w B using 1,
simp only [one_div, add_sub_cancel', inv_smul_smul', add_sub_add_right_eq_sub, ne.def,
not_false_iff, bit0_eq_zero, one_ne_zero],
rw two_smul,
abel },
have TA1 := s_conv.taylor_approx_two_segment hf xs hx h2vw h2vww,
have TA2 := s_conv.taylor_approx_two_segment hf xs hx hvw hvww,
convert TA1.sub TA2,
ext h,
simp only [two_smul, smul_add, ← add_assoc, continuous_linear_map.map_add,
continuous_linear_map.add_apply, pi.smul_apply,
continuous_linear_map.coe_smul', continuous_linear_map.map_smul],
abel,
end
/-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is
differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one
has `f'' v w = f'' w v`. Superseded by `convex.second_derivative_within_at_symmetric`, which
removes the assumption that `v` and `w` point inside `s`.
-/
lemma convex.second_derivative_within_at_symmetric_of_mem_interior
{v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) :
f'' w v = f'' v w :=
begin
have A : is_o (λ (h : ℝ), h^2 • (f'' w v- f'' v w)) (λ h, h^2) (𝓝[Ioi (0 : ℝ)] 0),
{ convert (s_conv.is_o_alternate_sum_square hf xs hx h4v h4w).sub
(s_conv.is_o_alternate_sum_square hf xs hx h4w h4v),
ext h,
simp only [add_comm, smul_add, smul_sub],
abel },
have B : is_o (λ (h : ℝ), f'' w v - f'' v w) (λ h, (1 : ℝ)) (𝓝[Ioi (0 : ℝ)] 0),
{ have : is_O (λ (h : ℝ), 1/h^2) (λ h, 1/h^2) (𝓝[Ioi (0 : ℝ)] 0) := is_O_refl _ _,
have C := this.smul_is_o A,
apply C.congr' _ _,
{ filter_upwards [self_mem_nhds_within],
assume h hpos,
rw [← one_smul ℝ (f'' w v - f'' v w), smul_smul, smul_smul],
congr' 1,
field_simp [has_lt.lt.ne' hpos] },
{ filter_upwards [self_mem_nhds_within],
assume h hpos,
field_simp [has_lt.lt.ne' hpos, has_scalar.smul] } },
simpa only [sub_eq_zero] using (is_o_const_const_iff (@one_ne_zero ℝ _ _)).1 B,
end
omit s_conv xs hx hf
/-- If a function is differentiable inside a convex set with nonempty interior, and has a second
derivative at a point of this convex set, then this second derivative is symmetric. -/
theorem convex.second_derivative_within_at_symmetric
{s : set E} (s_conv : convex s) (hne : (interior s).nonempty)
{f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)}
(hf : ∀ x ∈ interior s, has_fderiv_at f (f' x) x)
{x : E} (xs : x ∈ s) (hx : has_fderiv_within_at f' f'' (interior s) x) (v w : E) :
f'' v w = f'' w v :=
begin
/- we work around a point `x + 4 z` in the interior of `s`. For any vector `m`,
then `x + 4 (z + t m)` also belongs to the interior of `s` for small enough `t`. This means that
we will be able to apply `second_derivative_within_at_symmetric_of_mem_interior` to show
that `f''` is symmetric, after cancelling all the contributions due to `z`. -/
rcases hne with ⟨y, hy⟩,
obtain ⟨z, hz⟩ : ∃ z, z = ((1:ℝ) / 4) • (y - x) := ⟨((1:ℝ) / 4) • (y - x), rfl⟩,
have A : ∀ (m : E), filter.tendsto (λ (t : ℝ), x + (4 : ℝ) • (z + t • m)) (𝓝 0) (𝓝 y),
{ assume m,
have : x + (4 : ℝ) • (z + (0 : ℝ) • m) = y, by simp [hz],
rw ← this,
refine tendsto_const_nhds.add _,
refine tendsto_const_nhds.smul _,
refine tendsto_const_nhds.add _,
exact continuous_at_id.smul continuous_at_const },
have B : ∀ (m : E), ∀ᶠ t in 𝓝[Ioi (0 : ℝ)] (0 : ℝ), x + (4 : ℝ) • (z + t • m) ∈ interior s,
{ assume m,
apply nhds_within_le_nhds,
apply A m,
rw [mem_interior_iff_mem_nhds] at hy,
exact interior_mem_nhds.2 hy },
-- we choose `t m > 0` such that `x + 4 (z + (t m) m)` belongs to the interior of `s`, for any
-- vector `m`.
choose t ts tpos using λ m, ((B m).and self_mem_nhds_within).exists,
-- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z`
-- and `z + (t m) m`, we deduce that `f'' m z = f'' z m` for all `m`.
have C : ∀ (m : E), f'' m z = f'' z m,
{ assume m,
have : f'' (z + t m • m) (z + t 0 • 0) = f'' (z + t 0 • 0) (z + t m • m) :=
s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts 0) (ts m),
simp only [continuous_linear_map.map_add, continuous_linear_map.map_smul, add_right_inj,
continuous_linear_map.add_apply, pi.smul_apply, continuous_linear_map.coe_smul', add_zero,
continuous_linear_map.zero_apply, smul_zero, continuous_linear_map.map_zero] at this,
exact smul_right_injective F (tpos m).ne' this },
-- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z + (t v) v`
-- and `z + (t w) w`, we deduce that `f'' v w = f'' w v`. Cross terms involving `z` can be
-- eliminated thanks to the fact proved above that `f'' m z = f'' z m`.
have : f'' (z + t v • v) (z + t w • w) = f'' (z + t w • w) (z + t v • v) :=
s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts w) (ts v),
simp only [continuous_linear_map.map_add, continuous_linear_map.map_smul, smul_add, smul_smul,
continuous_linear_map.add_apply, pi.smul_apply, continuous_linear_map.coe_smul', C] at this,
rw ← sub_eq_zero at this,
abel at this,
simp only [one_gsmul, neg_smul, sub_eq_zero, mul_comm, ← sub_eq_add_neg] at this,
apply smul_right_injective F _ this,
simp [(tpos v).ne', (tpos w).ne']
end
/-- If a function is differentiable around `x`, and has two derivatives at `x`, then the second
derivative is symmetric. -/
theorem second_derivative_symmetric_of_eventually
{f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)}
(hf : ∀ᶠ y in 𝓝 x, has_fderiv_at f (f' y) y)
(hx : has_fderiv_at f' f'' x) (v w : E) :
f'' v w = f'' w v :=
begin
rcases metric.mem_nhds_iff.1 hf with ⟨ε, εpos, hε⟩,
have A : (interior (metric.ball x ε)).nonempty,
by { rw metric.is_open_ball.interior_eq, exact metric.nonempty_ball εpos },
exact convex.second_derivative_within_at_symmetric (convex_ball x ε) A
(λ y hy, hε (interior_subset hy)) (metric.mem_ball_self εpos) hx.has_fderiv_within_at v w,
end
/-- If a function is differentiable, and has two derivatives at `x`, then the second
derivative is symmetric. -/
theorem second_derivative_symmetric
{f : E → F} {f' : E → (E →L[ℝ] F)} {f'' : E →L[ℝ] (E →L[ℝ] F)}
(hf : ∀ y, has_fderiv_at f (f' y) y)
(hx : has_fderiv_at f' f'' x) (v w : E) :
f'' v w = f'' w v :=
second_derivative_symmetric_of_eventually (filter.eventually_of_forall hf) hx v w
|
4e8fd4e4553dc74aaa102f0ddbd7eaf1704f1a28 | c61b91f85121053c627318ad8fcde30dfb8637d2 | /Chapter3/3-2.lean | 0d58ede3bbc6fa6b5f716f42150332dbad1efcfb | [] | no_license | robkorn/theorem-proving-in-lean-exercises | 9e2256360eaf6f8df6cdd8fd656e63dfb04c8cdb | 9c51da587105ee047a9db55d52709d881a39be7a | refs/heads/master | 1,585,403,341,988 | 1,540,142,619,000 | 1,540,142,619,000 | 148,431,678 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,666 | lean |
namespace hidden
constants p q : Prop
theorem t1 : p → q → p := λ hp : p, λ hq : q, hp
#print t1
theorem tt1 : p -> q -> p :=
assume hp : p,
assume hq : q,
show p, from hp
lemma ttt1 : p -> q -> q :=
λ hp : p,
assume hq : q,
show q, from hq
lemma tl (hp : p) (hq : q) : p :=
show p, from hp
#check tl
axiom hp : p
theorem t2 : q -> p := t1 hp
theorem t1more (p q : Prop) (hp : p) (hq : q) : p := hp
#check t1more
theorem t1m1 : ∀ (p q : Prop), p -> q -> p :=
assume (p q : Prop),
λ hp : p,
λ hq : q,
show p, from hp
#check t1m1
lemma t1m2 : Π (p q : Prop), p -> q -> p :=
λ (p q : Prop) (hp : p) (hq : q),
show p, from hp
#check t1m2
variables p q : Prop
theorem t1m3 : p -> q -> p :=
λ hp : p,
λ hq : q,
show p, from hp
#check t1m3
variable {hp : p}
theorem t1m4 : q -> p :=
λ hq : q,
hp
end hidden
namespace pairs
variables p q r s : Prop
theorem t1 : p -> q -> p :=
λ hp : p,
assume hq : q,
hp
#check t1 p q
#check t1 r s
#check t1 (r → s) (s → r)
variable h : r → s
#check t1 (r → s) (s → r) h
end pairs
namespace composition
variables p q r s : Prop
theorem t2 (h₁ : q → r) (h₂ : p → q) : p → r :=
assume h₃ : p,
show r, from h₁ $ h₂ h₃
theorem myt2 : (q → r) → (p → q) → (p → r) :=
λ h₁ : q → r,
λ h₂ : p → q,
λ h₃ : p,
show r, from h₁ $ h₂ h₃
end composition
|
f4ee1dc403450533bcbe6334f9e75822ece25d63 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/complex/basic.lean | 13ccea2e8b15c45be631a06e071a8ceef9845be7 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 15,055 | lean | /-
Copyright (c) Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import data.complex.determinant
import data.complex.is_R_or_C
/-!
# Normed space structure on `ℂ`.
This file gathers basic facts on complex numbers of an analytic nature.
## Main results
This file registers `ℂ` as a normed field, expresses basic properties of the norm, and gives
tools on the real vector space structure of `ℂ`. Notably, in the namespace `complex`,
it defines functions:
* `re_clm`
* `im_clm`
* `of_real_clm`
* `conj_cle`
They are bundled versions of the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and
the complex conjugate as continuous `ℝ`-linear maps. The last two are also bundled as linear
isometries in `of_real_li` and `conj_lie`.
We also register the fact that `ℂ` is an `is_R_or_C` field.
-/
noncomputable theory
namespace complex
open_locale complex_conjugate topological_space
instance : has_norm ℂ := ⟨abs⟩
@[simp] lemma norm_eq_abs (z : ℂ) : ∥z∥ = abs z := rfl
instance : normed_add_comm_group ℂ :=
normed_add_comm_group.of_core ℂ
{ norm_eq_zero_iff := λ z, abs_eq_zero,
triangle := abs_add,
norm_neg := abs_neg }
instance : normed_field ℂ :=
{ norm := abs,
dist_eq := λ _ _, rfl,
norm_mul' := abs_mul,
.. complex.field, .. complex.normed_add_comm_group }
instance : densely_normed_field ℂ :=
{ lt_norm_lt := λ r₁ r₂ h₀ hr, let ⟨x, h⟩ := normed_field.exists_lt_norm_lt ℝ h₀ hr in
have this : ∥(∥x∥ : ℂ)∥ = ∥(∥x∥)∥, by simp only [norm_eq_abs, abs_of_real, real.norm_eq_abs],
⟨∥x∥, by rwa [this, norm_norm]⟩ }
instance {R : Type*} [normed_field R] [normed_algebra R ℝ] : normed_algebra R ℂ :=
{ norm_smul_le := λ r x, begin
rw [norm_eq_abs, norm_eq_abs, ←algebra_map_smul ℝ r x, algebra.smul_def, abs_mul,
←norm_algebra_map' ℝ r, coe_algebra_map, abs_of_real],
refl,
end,
to_algebra := complex.algebra }
variables {E : Type*} [normed_add_comm_group E] [normed_space ℂ E]
/-- The module structure from `module.complex_to_real` is a normed space. -/
@[priority 900] -- see Note [lower instance priority]
instance _root_.normed_space.complex_to_real : normed_space ℝ E :=
normed_space.restrict_scalars ℝ ℂ E
lemma dist_eq (z w : ℂ) : dist z w = abs (z - w) := rfl
lemma dist_eq_re_im (z w : ℂ) : dist z w = real.sqrt ((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) :=
by { rw [sq, sq], refl }
@[simp] lemma dist_mk (x₁ y₁ x₂ y₂ : ℝ) :
dist (mk x₁ y₁) (mk x₂ y₂) = real.sqrt ((x₁ - x₂) ^ 2 + (y₁ - y₂) ^ 2) :=
dist_eq_re_im _ _
lemma dist_of_re_eq {z w : ℂ} (h : z.re = w.re) : dist z w = dist z.im w.im :=
by rw [dist_eq_re_im, h, sub_self, zero_pow two_pos, zero_add, real.sqrt_sq_eq_abs, real.dist_eq]
lemma nndist_of_re_eq {z w : ℂ} (h : z.re = w.re) : nndist z w = nndist z.im w.im :=
nnreal.eq $ dist_of_re_eq h
lemma edist_of_re_eq {z w : ℂ} (h : z.re = w.re) : edist z w = edist z.im w.im :=
by rw [edist_nndist, edist_nndist, nndist_of_re_eq h]
lemma dist_of_im_eq {z w : ℂ} (h : z.im = w.im) : dist z w = dist z.re w.re :=
by rw [dist_eq_re_im, h, sub_self, zero_pow two_pos, add_zero, real.sqrt_sq_eq_abs, real.dist_eq]
lemma nndist_of_im_eq {z w : ℂ} (h : z.im = w.im) : nndist z w = nndist z.re w.re :=
nnreal.eq $ dist_of_im_eq h
lemma edist_of_im_eq {z w : ℂ} (h : z.im = w.im) : edist z w = edist z.re w.re :=
by rw [edist_nndist, edist_nndist, nndist_of_im_eq h]
lemma dist_conj_self (z : ℂ) : dist (conj z) z = 2 * |z.im| :=
by rw [dist_of_re_eq (conj_re z), conj_im, dist_comm, real.dist_eq, sub_neg_eq_add, ← two_mul,
_root_.abs_mul, abs_of_pos (@two_pos ℝ _ _)]
lemma nndist_conj_self (z : ℂ) : nndist (conj z) z = 2 * real.nnabs z.im :=
nnreal.eq $ by rw [← dist_nndist, nnreal.coe_mul, nnreal.coe_two, real.coe_nnabs, dist_conj_self]
lemma dist_self_conj (z : ℂ) : dist z (conj z) = 2 * |z.im| :=
by rw [dist_comm, dist_conj_self]
lemma nndist_self_conj (z : ℂ) : nndist z (conj z) = 2 * real.nnabs z.im :=
by rw [nndist_comm, nndist_conj_self]
@[simp] lemma comap_abs_nhds_zero : filter.comap abs (𝓝 0) = 𝓝 0 := comap_norm_nhds_zero
@[simp] lemma norm_real (r : ℝ) : ∥(r : ℂ)∥ = ∥r∥ := abs_of_real _
@[simp] lemma norm_rat (r : ℚ) : ∥(r : ℂ)∥ = |(r : ℝ)| :=
by { rw ← of_real_rat_cast, exact norm_real _ }
@[simp] lemma norm_nat (n : ℕ) : ∥(n : ℂ)∥ = n := abs_of_nat _
@[simp] lemma norm_int {n : ℤ} : ∥(n : ℂ)∥ = |n| :=
by simp [← rat.cast_coe_int] {single_pass := tt}
lemma norm_int_of_nonneg {n : ℤ} (hn : 0 ≤ n) : ∥(n : ℂ)∥ = n :=
by simp [hn]
@[continuity] lemma continuous_abs : continuous abs := continuous_norm
@[continuity] lemma continuous_norm_sq : continuous norm_sq :=
by simpa [← norm_sq_eq_abs] using continuous_abs.pow 2
@[simp, norm_cast] lemma nnnorm_real (r : ℝ) : ∥(r : ℂ)∥₊ = ∥r∥₊ :=
subtype.ext $ norm_real r
@[simp, norm_cast] lemma nnnorm_nat (n : ℕ) : ∥(n : ℂ)∥₊ = n :=
subtype.ext $ by simp
@[simp, norm_cast] lemma nnnorm_int (n : ℤ) : ∥(n : ℂ)∥₊ = ∥n∥₊ :=
subtype.ext $ by simp only [coe_nnnorm, norm_int, int.norm_eq_abs]
lemma nnnorm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) :
∥ζ∥₊ = 1 :=
begin
refine (@pow_left_inj nnreal _ _ _ _ zero_le' zero_le' hn.bot_lt).mp _,
rw [←nnnorm_pow, h, nnnorm_one, one_pow],
end
lemma norm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) :
∥ζ∥ = 1 :=
congr_arg coe (nnnorm_eq_one_of_pow_eq_one h hn)
/-- The `abs` function on `ℂ` is proper. -/
lemma tendsto_abs_cocompact_at_top : filter.tendsto abs (filter.cocompact ℂ) filter.at_top :=
tendsto_norm_cocompact_at_top
/-- The `norm_sq` function on `ℂ` is proper. -/
lemma tendsto_norm_sq_cocompact_at_top :
filter.tendsto norm_sq (filter.cocompact ℂ) filter.at_top :=
by simpa [mul_self_abs] using
tendsto_abs_cocompact_at_top.at_top_mul_at_top tendsto_abs_cocompact_at_top
open continuous_linear_map
/-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/
def re_clm : ℂ →L[ℝ] ℝ := re_lm.mk_continuous 1 (λ x, by simp [abs_re_le_abs])
@[continuity] lemma continuous_re : continuous re := re_clm.continuous
@[simp] lemma re_clm_coe : (coe (re_clm) : ℂ →ₗ[ℝ] ℝ) = re_lm := rfl
@[simp] lemma re_clm_apply (z : ℂ) : (re_clm : ℂ → ℝ) z = z.re := rfl
@[simp] lemma re_clm_norm : ∥re_clm∥ = 1 :=
le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _) $
calc 1 = ∥re_clm 1∥ : by simp
... ≤ ∥re_clm∥ : unit_le_op_norm _ _ (by simp)
@[simp] lemma re_clm_nnnorm : ∥re_clm∥₊ = 1 := subtype.ext re_clm_norm
/-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/
def im_clm : ℂ →L[ℝ] ℝ := im_lm.mk_continuous 1 (λ x, by simp [abs_im_le_abs])
@[continuity] lemma continuous_im : continuous im := im_clm.continuous
@[simp] lemma im_clm_coe : (coe (im_clm) : ℂ →ₗ[ℝ] ℝ) = im_lm := rfl
@[simp] lemma im_clm_apply (z : ℂ) : (im_clm : ℂ → ℝ) z = z.im := rfl
@[simp] lemma im_clm_norm : ∥im_clm∥ = 1 :=
le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _) $
calc 1 = ∥im_clm I∥ : by simp
... ≤ ∥im_clm∥ : unit_le_op_norm _ _ (by simp)
@[simp] lemma im_clm_nnnorm : ∥im_clm∥₊ = 1 := subtype.ext im_clm_norm
lemma restrict_scalars_one_smul_right' (x : E) :
continuous_linear_map.restrict_scalars ℝ ((1 : ℂ →L[ℂ] ℂ).smul_right x : ℂ →L[ℂ] E) =
re_clm.smul_right x + I • im_clm.smul_right x :=
by { ext ⟨a, b⟩, simp [mk_eq_add_mul_I, add_smul, mul_smul, smul_comm I] }
lemma restrict_scalars_one_smul_right (x : ℂ) :
continuous_linear_map.restrict_scalars ℝ ((1 : ℂ →L[ℂ] ℂ).smul_right x : ℂ →L[ℂ] ℂ) = x • 1 :=
by { ext1 z, dsimp, apply mul_comm }
/-- The complex-conjugation function from `ℂ` to itself is an isometric linear equivalence. -/
def conj_lie : ℂ ≃ₗᵢ[ℝ] ℂ := ⟨conj_ae.to_linear_equiv, abs_conj⟩
@[simp] lemma conj_lie_apply (z : ℂ) : conj_lie z = conj z := rfl
@[simp] lemma conj_lie_symm : conj_lie.symm = conj_lie := rfl
lemma isometry_conj : isometry (conj : ℂ → ℂ) := conj_lie.isometry
@[simp] lemma dist_conj_conj (z w : ℂ) : dist (conj z) (conj w) = dist z w :=
isometry_conj.dist_eq z w
@[simp] lemma nndist_conj_conj (z w : ℂ) : nndist (conj z) (conj w) = nndist z w :=
isometry_conj.nndist_eq z w
lemma dist_conj_comm (z w : ℂ) : dist (conj z) w = dist z (conj w) :=
by rw [← dist_conj_conj, conj_conj]
lemma nndist_conj_comm (z w : ℂ) : nndist (conj z) w = nndist z (conj w) :=
subtype.ext $ dist_conj_comm _ _
/-- The determinant of `conj_lie`, as a linear map. -/
@[simp] lemma det_conj_lie : (conj_lie.to_linear_equiv : ℂ →ₗ[ℝ] ℂ).det = -1 :=
det_conj_ae
/-- The determinant of `conj_lie`, as a linear equiv. -/
@[simp] lemma linear_equiv_det_conj_lie : conj_lie.to_linear_equiv.det = -1 :=
linear_equiv_det_conj_ae
instance : has_continuous_star ℂ := ⟨conj_lie.continuous⟩
@[continuity] lemma continuous_conj : continuous (conj : ℂ → ℂ) := continuous_star
/-- The only continuous ring homomorphisms from `ℂ` to `ℂ` are the identity and the complex
conjugation. -/
lemma ring_hom_eq_id_or_conj_of_continuous {f : ℂ →+* ℂ} (hf : continuous f) :
f = ring_hom.id ℂ ∨ f = conj :=
begin
refine (real_alg_hom_eq_id_or_conj $ alg_hom.mk' f $ λ x z, congr_fun _ x).imp (λ h, _) (λ h, _),
{ refine rat.dense_embedding_coe_real.dense.equalizer (by continuity) (by continuity) _,
ext1, simp only [real_smul, function.comp_app, map_rat_cast, of_real_rat_cast, map_mul], },
all_goals { convert congr_arg alg_hom.to_ring_hom h, ext1, refl, },
end
/-- Continuous linear equiv version of the conj function, from `ℂ` to `ℂ`. -/
def conj_cle : ℂ ≃L[ℝ] ℂ := conj_lie
@[simp] lemma conj_cle_coe : conj_cle.to_linear_equiv = conj_ae.to_linear_equiv := rfl
@[simp] lemma conj_cle_apply (z : ℂ) : conj_cle z = conj z := rfl
@[simp] lemma conj_cle_norm : ∥(conj_cle : ℂ →L[ℝ] ℂ)∥ = 1 :=
conj_lie.to_linear_isometry.norm_to_continuous_linear_map
@[simp] lemma conj_cle_nnorm : ∥(conj_cle : ℂ →L[ℝ] ℂ)∥₊ = 1 := subtype.ext conj_cle_norm
/-- Linear isometry version of the canonical embedding of `ℝ` in `ℂ`. -/
def of_real_li : ℝ →ₗᵢ[ℝ] ℂ := ⟨of_real_am.to_linear_map, norm_real⟩
lemma isometry_of_real : isometry (coe : ℝ → ℂ) := of_real_li.isometry
@[continuity] lemma continuous_of_real : continuous (coe : ℝ → ℂ) := of_real_li.continuous
/-- Continuous linear map version of the canonical embedding of `ℝ` in `ℂ`. -/
def of_real_clm : ℝ →L[ℝ] ℂ := of_real_li.to_continuous_linear_map
@[simp] lemma of_real_clm_coe : (of_real_clm : ℝ →ₗ[ℝ] ℂ) = of_real_am.to_linear_map := rfl
@[simp] lemma of_real_clm_apply (x : ℝ) : of_real_clm x = x := rfl
@[simp] lemma of_real_clm_norm : ∥of_real_clm∥ = 1 := of_real_li.norm_to_continuous_linear_map
@[simp] lemma of_real_clm_nnnorm : ∥of_real_clm∥₊ = 1 := subtype.ext $ of_real_clm_norm
noncomputable instance : is_R_or_C ℂ :=
{ re := ⟨complex.re, complex.zero_re, complex.add_re⟩,
im := ⟨complex.im, complex.zero_im, complex.add_im⟩,
I := complex.I,
I_re_ax := by simp only [add_monoid_hom.coe_mk, complex.I_re],
I_mul_I_ax := by simp only [complex.I_mul_I, eq_self_iff_true, or_true],
re_add_im_ax := λ z, by simp only [add_monoid_hom.coe_mk, complex.re_add_im,
complex.coe_algebra_map, complex.of_real_eq_coe],
of_real_re_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_re,
complex.coe_algebra_map, complex.of_real_eq_coe],
of_real_im_ax := λ r, by simp only [add_monoid_hom.coe_mk, complex.of_real_im,
complex.coe_algebra_map, complex.of_real_eq_coe],
mul_re_ax := λ z w, by simp only [complex.mul_re, add_monoid_hom.coe_mk],
mul_im_ax := λ z w, by simp only [add_monoid_hom.coe_mk, complex.mul_im],
conj_re_ax := λ z, rfl,
conj_im_ax := λ z, rfl,
conj_I_ax := by simp only [complex.conj_I, ring_hom.coe_mk],
norm_sq_eq_def_ax := λ z, by simp only [←complex.norm_sq_eq_abs, ←complex.norm_sq_apply,
add_monoid_hom.coe_mk, complex.norm_eq_abs],
mul_im_I_ax := λ z, by simp only [mul_one, add_monoid_hom.coe_mk, complex.I_im],
inv_def_ax := λ z, by simp only [complex.inv_def, complex.norm_sq_eq_abs, complex.coe_algebra_map,
complex.of_real_eq_coe, complex.norm_eq_abs],
div_I_ax := complex.div_I }
lemma _root_.is_R_or_C.re_eq_complex_re : ⇑(is_R_or_C.re : ℂ →+ ℝ) = complex.re := rfl
lemma _root_.is_R_or_C.im_eq_complex_im : ⇑(is_R_or_C.im : ℂ →+ ℝ) = complex.im := rfl
section
variables {α β γ : Type*}
[add_comm_monoid α] [topological_space α] [add_comm_monoid γ] [topological_space γ]
/-- The natural `add_equiv` from `ℂ` to `ℝ × ℝ`. -/
@[simps apply symm_apply_re symm_apply_im { simp_rhs := tt }]
def equiv_real_prod_add_hom : ℂ ≃+ ℝ × ℝ :=
{ map_add' := by simp, .. equiv_real_prod }
/-- The natural `linear_equiv` from `ℂ` to `ℝ × ℝ`. -/
@[simps apply symm_apply_re symm_apply_im { simp_rhs := tt }]
def equiv_real_prod_add_hom_lm : ℂ ≃ₗ[ℝ] ℝ × ℝ :=
{ map_smul' := by simp [equiv_real_prod_add_hom], .. equiv_real_prod_add_hom }
/-- The natural `continuous_linear_equiv` from `ℂ` to `ℝ × ℝ`. -/
@[simps apply symm_apply_re symm_apply_im { simp_rhs := tt }]
def equiv_real_prodₗ : ℂ ≃L[ℝ] ℝ × ℝ :=
equiv_real_prod_add_hom_lm.to_continuous_linear_equiv
end
lemma has_sum_iff {α} (f : α → ℂ) (c : ℂ) :
has_sum f c ↔ has_sum (λ x, (f x).re) c.re ∧ has_sum (λ x, (f x).im) c.im :=
begin
-- For some reason, `continuous_linear_map.has_sum` is orders of magnitude faster than
-- `has_sum.mapL` here:
refine ⟨λ h, ⟨re_clm.has_sum h, im_clm.has_sum h⟩, _⟩,
rintro ⟨h₁, h₂⟩,
convert (h₁.prod_mk h₂).mapL equiv_real_prodₗ.symm.to_continuous_linear_map,
{ ext x; refl },
{ cases c, refl }
end
end complex
namespace is_R_or_C
local notation `reC` := @is_R_or_C.re ℂ _
local notation `imC` := @is_R_or_C.im ℂ _
local notation `IC` := @is_R_or_C.I ℂ _
local notation `absC` := @is_R_or_C.abs ℂ _
local notation `norm_sqC` := @is_R_or_C.norm_sq ℂ _
@[simp] lemma re_to_complex {x : ℂ} : reC x = x.re := rfl
@[simp] lemma im_to_complex {x : ℂ} : imC x = x.im := rfl
@[simp] lemma I_to_complex : IC = complex.I := rfl
@[simp] lemma norm_sq_to_complex {x : ℂ} : norm_sqC x = complex.norm_sq x :=
by simp [is_R_or_C.norm_sq, complex.norm_sq]
@[simp] lemma abs_to_complex {x : ℂ} : absC x = complex.abs x :=
by simp [is_R_or_C.abs, complex.abs]
end is_R_or_C
|
fd860142c32124faba28e83d393a3233f774938d | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/varBinderUpdate.lean | 2710b16bdbead5b69a8e9cb2af4b58f3707fdcc0 | [
"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 | 805 | lean | namespace Ex1
variable {α : Type}
variable [Add α]
variable (α)
def f (a : α) := a + a
#check f Nat 5
variable {α}
def g (b : α) := b
#check g 5
#check f
#check g
end Ex1
namespace Ex2
variable {α β : Type}
variable (α)
def f (a : α) := a
def g (b : β) := b
#check f Nat 5
#check g 5
#check f
#check g
variable (α)
end Ex2
namespace Ex3
variable {α : Type}
variable (f : α → α)
variable (α)
def g (a : α) := f a
#check g
variable {f}
def h (a : α) := f a
#check h
end Ex3
namespace Ex4
variable {α β : Type}
variable (α γ)
def g (a : α) (b : β) (c : γ) := (a, b, c)
#check g Nat Bool 10 "hello" true
end Ex4
namespace Ex5
variable [i : Add α]
variable (i) -- Error
end Ex5
namespace Ex6
variable (a : Nat)
variable (h : a = a := rfl)
variable {h} -- Error
end Ex6
|
d4a486ee867fcb1bee28158cc9fc112208b2bf3f | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/analysis/asymptotics/specific_asymptotics.lean | 3d5227187c385a30e045cb188571f4debb164ca1 | [
"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,659 | lean | /-
Copyright (c) 2021 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import analysis.normed_space.ordered
import analysis.asymptotics.asymptotics
/-!
# A collection of specific asymptotic results
This file contains specific lemmas about asymptotics which don't have their place in the general
theory developped in `analysis.asymptotics.asymptotics`.
-/
open filter asymptotics
open_locale topological_space
section linear_ordered_field
variables {𝕜 : Type*} [linear_ordered_field 𝕜]
lemma pow_div_pow_eventually_eq_at_top {p q : ℕ} :
(λ x : 𝕜, x^p / x^q) =ᶠ[at_top] (λ x, x^((p : ℤ) -q)) :=
begin
apply ((eventually_gt_at_top (0 : 𝕜)).mono (λ x hx, _)),
simp [fpow_sub hx.ne'],
end
lemma pow_div_pow_eventually_eq_at_bot {p q : ℕ} :
(λ x : 𝕜, x^p / x^q) =ᶠ[at_bot] (λ x, x^((p : ℤ) -q)) :=
begin
apply ((eventually_lt_at_bot (0 : 𝕜)).mono (λ x hx, _)),
simp [fpow_sub hx.ne'.symm],
end
lemma tendsto_fpow_at_top_at_top {n : ℤ}
(hn : 0 < n) : tendsto (λ x : 𝕜, x^n) at_top at_top :=
begin
lift n to ℕ using hn.le,
simp only [gpow_coe_nat],
exact tendsto_pow_at_top (nat.succ_le_iff.mpr $int.coe_nat_pos.mp hn)
end
lemma tendsto_pow_div_pow_at_top_at_top {p q : ℕ}
(hpq : q < p) : tendsto (λ x : 𝕜, x^p / x^q) at_top at_top :=
begin
rw tendsto_congr' pow_div_pow_eventually_eq_at_top,
apply tendsto_fpow_at_top_at_top,
linarith
end
lemma tendsto_pow_div_pow_at_top_zero [topological_space 𝕜] [order_topology 𝕜] {p q : ℕ}
(hpq : p < q) : tendsto (λ x : 𝕜, x^p / x^q) at_top (𝓝 0) :=
begin
rw tendsto_congr' pow_div_pow_eventually_eq_at_top,
apply tendsto_fpow_at_top_zero,
linarith
end
end linear_ordered_field
section normed_linear_ordered_field
variables {𝕜 : Type*} [normed_linear_ordered_field 𝕜]
lemma asymptotics.is_o_pow_pow_at_top_of_lt
[order_topology 𝕜] {p q : ℕ} (hpq : p < q) :
is_o (λ x : 𝕜, x^p) (λ x, x^q) at_top :=
begin
refine (is_o_iff_tendsto' _).mpr (tendsto_pow_div_pow_at_top_zero hpq),
exact (eventually_gt_at_top 0).mono (λ x hx hxq, (pow_ne_zero q hx.ne' hxq).elim),
end
lemma asymptotics.is_O.trans_tendsto_norm_at_top {α : Type*} {u v : α → 𝕜} {l : filter α}
(huv : is_O u v l) (hu : tendsto (λ x, ∥u x∥) l at_top) : tendsto (λ x, ∥v x∥) l at_top :=
begin
rcases huv.exists_pos with ⟨c, hc, hcuv⟩,
rw is_O_with at hcuv,
convert tendsto.at_top_div_const hc (tendsto_at_top_mono' l hcuv hu),
ext x,
rw mul_div_cancel_left _ hc.ne.symm,
end
end normed_linear_ordered_field
|
39236753bf13ae60ee83c0824570ec0ff49b0bd4 | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /stage0/src/Lean/Meta/Basic.lean | e13bc96cc6c43d47589f38a802fcc5b500f43127 | [
"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 | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 73,212 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Data.LOption
import Lean.Environment
import Lean.Class
import Lean.ReducibilityAttrs
import Lean.Util.ReplaceExpr
import Lean.Util.MonadBacktrack
import Lean.Compiler.InlineAttrs
import Lean.Meta.TransparencyMode
/-!
This module provides four (mutually dependent) goodies that are needed for building the elaborator and tactic frameworks.
1- Weak head normal form computation with support for metavariables and transparency modes.
2- Definitionally equality checking with support for metavariables (aka unification modulo definitional equality).
3- Type inference.
4- Type class resolution.
They are packed into the MetaM monad.
-/
namespace Lean.Meta
builtin_initialize isDefEqStuckExceptionId : InternalExceptionId ← registerInternalExceptionId `isDefEqStuck
/--
Configuration flags for the `MetaM` monad.
Many of them are used to control the `isDefEq` function that checks whether two terms are definitionally equal or not.
Recall that when `isDefEq` is trying to check whether
`?m@C a₁ ... aₙ` and `t` are definitionally equal (`?m@C a₁ ... aₙ =?= t`), where
`?m@C` as a shorthand for `C |- ?m : t` where `t` is the type of `?m`.
We solve it using the assignment `?m := fun a₁ ... aₙ => t` if
1) `a₁ ... aₙ` are pairwise distinct free variables that are *not* let-variables.
2) `a₁ ... aₙ` are not in `C`
3) `t` only contains free variables in `C` and/or `{a₁, ..., aₙ}`
4) For every metavariable `?m'@C'` occurring in `t`, `C'` is a subprefix of `C`
5) `?m` does not occur in `t`
-/
structure Config where
/--
If `foApprox` is set to true, and some `aᵢ` is not a free variable,
then we use first-order unification
```
?m a_1 ... a_i a_{i+1} ... a_{i+k} =?= f b_1 ... b_k
```
reduces to
```
?m a_1 ... a_i =?= f
a_{i+1} =?= b_1
...
a_{i+k} =?= b_k
```
-/
foApprox : Bool := false
/--
When `ctxApprox` is set to true, we relax condition 4, by creating an
auxiliary metavariable `?n'` with a smaller context than `?m'`.
-/
ctxApprox : Bool := false
/--
When `quasiPatternApprox` is set to true, we ignore condition 2.
-/
quasiPatternApprox : Bool := false
/-- When `constApprox` is set to true,
we solve `?m t =?= c` using
`?m := fun _ => c`
when `?m t` is not a higher-order pattern and `c` is not an application as -/
constApprox : Bool := false
/--
When the following flag is set,
`isDefEq` throws the exeption `Exeption.isDefEqStuck`
whenever it encounters a constraint `?m ... =?= t` where
`?m` is read only.
This feature is useful for type class resolution where
we may want to notify the caller that the TC problem may be solveable
later after it assigns `?m`. -/
isDefEqStuckEx : Bool := false
/--
Controls which definitions and theorems can be unfolded by `isDefEq` and `whnf`.
-/
transparency : TransparencyMode := TransparencyMode.default
/-- If zetaNonDep == false, then non dependent let-decls are not zeta expanded. -/
zetaNonDep : Bool := true
/-- When `trackZeta == true`, we store zetaFVarIds all free variables that have been zeta-expanded. -/
trackZeta : Bool := false
/-- Enable/disable the unification hints feature. -/
unificationHints : Bool := true
/-- Enables proof irrelevance at `isDefEq` -/
proofIrrelevance : Bool := true
/-- By default synthetic opaque metavariables are not assigned by `isDefEq`. Motivation: we want to make
sure typing constraints resolved during elaboration should not "fill" holes that are supposed to be filled using tactics.
However, this restriction is too restrictive for tactics such as `exact t`. When elaborating `t`, we dot not fill
named holes when solving typing constraints or TC resolution. But, we ignore the restriction when we try to unify
the type of `t` with the goal target type. We claim this is not a hack and is defensible behavior because
this last unification step is not really part of the term elaboration. -/
assignSyntheticOpaque : Bool := false
/-- When `ignoreLevelDepth` is `false`, only universe level metavariables with depth == metavariable context depth
can be assigned.
We used to have `ignoreLevelDepth == false` always, but this setting produced counterintuitive behavior in a few
cases. Recall that universe levels are often ignored by users, they may not even be aware they exist.
We still use this restriction for regular metavariables. See discussion at the beginning of `MetavarContext.lean`.
We claim it is reasonable to ignore this restriction for universe metavariables because their values are often
contrained by the terms is instances and simp theorems.
TODO: we should delete this configuration option and the method `isReadOnlyLevelMVar` after we have more tests.
-/
ignoreLevelMVarDepth : Bool := true
/-- Enable/Disable support for offset constraints such as `?x + 1 =?= e` -/
offsetCnstrs : Bool := true
/-- Eta for structures configuration mode. -/
etaStruct : EtaStructMode := .all
/--
Function parameter information cache.
-/
structure ParamInfo where
/-- The binder annotation for the parameter. -/
binderInfo : BinderInfo := BinderInfo.default
/-- `hasFwdDeps` is true if there is another parameter whose type depends on this one. -/
hasFwdDeps : Bool := false
/-- `backDeps` contains the backwards dependencies. That is, the (0-indexed) position of previous parameters that this one depends on. -/
backDeps : Array Nat := #[]
/-- `isProp` is true if the parameter is always a proposition. -/
isProp : Bool := false
/--
`isDecInst` is true if the parameter's type is of the form `Decidable ...`.
This information affects the generation of congruence theorems.
-/
isDecInst : Bool := false
/--
`higherOrderOutParam` is true if this parameter is a higher-order output parameter
of local instance.
Example:
```
getElem :
{cont : Type u_1} → {idx : Type u_2} → {elem : Type u_3} →
{dom : cont → idx → Prop} → [self : GetElem cont idx elem dom] →
(xs : cont) → (i : idx) → dom xs i → elem
```
This flag is true for the parameter `dom` because it is output parameter of
`[self : GetElem cont idx elem dom]`
-/
higherOrderOutParam : Bool := false
/--
`dependsOnHigherOrderOutParam` is true if the type of this parameter depends on
the higher-order output parameter of a previous local instance.
Example:
```
getElem :
{cont : Type u_1} → {idx : Type u_2} → {elem : Type u_3} →
{dom : cont → idx → Prop} → [self : GetElem cont idx elem dom] →
(xs : cont) → (i : idx) → dom xs i → elem
```
This flag is true for the parameter with type `dom xs i` since `dom` is an output parameter
of the instance `[self : GetElem cont idx elem dom]`
-/
dependsOnHigherOrderOutParam : Bool := false
deriving Inhabited
def ParamInfo.isImplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.implicit
def ParamInfo.isInstImplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.instImplicit
def ParamInfo.isStrictImplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.strictImplicit
def ParamInfo.isExplicit (p : ParamInfo) : Bool :=
p.binderInfo == BinderInfo.default || p.binderInfo == BinderInfo.auxDecl
/--
Function information cache. See `ParamInfo`.
-/
structure FunInfo where
/-- Parameter information cache. -/
paramInfo : Array ParamInfo := #[]
/--
`resultDeps` contains the function result type backwards dependencies.
That is, the (0-indexed) position of parameters that the result type depends on.
-/
resultDeps : Array Nat := #[]
/--
Key for the function information cache.
-/
structure InfoCacheKey where
/-- The transparency mode used to compute the `FunInfo`. -/
transparency : TransparencyMode
/-- The function being cached information about. It is quite often an `Expr.const`. -/
expr : Expr
/--
`nargs? = some n` if the cached information was computed assuming the function has arity `n`.
If `nargs? = none`, then the cache information consumed the arrow type as much as possible
unsing the current transparency setting.
X-/
nargs? : Option Nat
deriving Inhabited, BEq
namespace InfoCacheKey
instance : Hashable InfoCacheKey :=
⟨fun ⟨transparency, expr, nargs⟩ => mixHash (hash transparency) <| mixHash (hash expr) (hash nargs)⟩
end InfoCacheKey
abbrev SynthInstanceCache := PersistentHashMap Expr (Option Expr)
abbrev InferTypeCache := PersistentExprStructMap Expr
abbrev FunInfoCache := PersistentHashMap InfoCacheKey FunInfo
abbrev WhnfCache := PersistentExprStructMap Expr
/--
A mapping `(s, t) ↦ isDefEq s t`.
TODO: consider more efficient representations (e.g., a proper set) and caching policies (e.g., imperfect cache).
We should also investigate the impact on memory consumption. -/
abbrev DefEqCache := PersistentHashMap (Expr × Expr) Bool
/--
Cache datastructures for type inference, type class resolution, whnf, and definitional equality.
-/
structure Cache where
inferType : InferTypeCache := {}
funInfo : FunInfoCache := {}
synthInstance : SynthInstanceCache := {}
whnfDefault : WhnfCache := {} -- cache for closed terms and `TransparencyMode.default`
whnfAll : WhnfCache := {} -- cache for closed terms and `TransparencyMode.all`
defEq : DefEqCache := {}
deriving Inhabited
/--
"Context" for a postponed universe constraint.
`lhs` and `rhs` are the surrounding `isDefEq` call when the postponed constraint was created.
-/
structure DefEqContext where
lhs : Expr
rhs : Expr
lctx : LocalContext
localInstances : LocalInstances
/--
Auxiliary structure for representing postponed universe constraints.
Remark: the fields `ref` and `rootDefEq?` are used for error message generation only.
Remark: we may consider improving the error message generation in the future.
-/
structure PostponedEntry where
/-- We save the `ref` at entry creation time. This is used for reporting errors back to the user. -/
ref : Syntax
lhs : Level
rhs : Level
/-- Context for the surrounding `isDefEq` call when entry was created. -/
ctx? : Option DefEqContext
deriving Inhabited
/--
`MetaM` monad state.
-/
structure State where
mctx : MetavarContext := {}
cache : Cache := {}
/-- When `trackZeta == true`, then any let-decl free variable that is zeta expansion performed by `MetaM` is stored in `zetaFVarIds`. -/
zetaFVarIds : FVarIdSet := {}
/-- Array of postponed universe level constraints -/
postponed : PersistentArray PostponedEntry := {}
deriving Inhabited
/--
Backtrackable state for the `MetaM` monad.
-/
structure SavedState where
core : Core.State
meta : State
deriving Inhabited
/--
Contextual information for the `MetaM` monad.
-/
structure Context where
config : Config := {}
/-- Local context -/
lctx : LocalContext := {}
/-- Local instances in `lctx`. -/
localInstances : LocalInstances := #[]
/-- Not `none` when inside of an `isDefEq` test. See `PostponedEntry`. -/
defEqCtx? : Option DefEqContext := none
/--
Track the number of nested `synthPending` invocations. Nested invocations can happen
when the type class resolution invokes `synthPending`.
Remark: in the current implementation, `synthPending` fails if `synthPendingDepth > 0`.
We will add a configuration option if necessary. -/
synthPendingDepth : Nat := 0
/--
A predicate to control whether a constant can be unfolded or not at `whnf`.
Note that we do not cache results at `whnf` when `canUnfold?` is not `none`. -/
canUnfold? : Option (Config → ConstantInfo → CoreM Bool) := none
abbrev MetaM := ReaderT Context $ StateRefT State CoreM
-- Make the compiler generate specialized `pure`/`bind` so we do not have to optimize through the
-- whole monad stack at every use site. May eventually be covered by `deriving`.
instance : Monad MetaM := let i := inferInstanceAs (Monad MetaM); { pure := i.pure, bind := i.bind }
instance : Inhabited (MetaM α) where
default := fun _ _ => default
instance : MonadLCtx MetaM where
getLCtx := return (← read).lctx
instance : MonadMCtx MetaM where
getMCtx := return (← get).mctx
modifyMCtx f := modify fun s => { s with mctx := f s.mctx }
instance : MonadEnv MetaM where
getEnv := return (← getThe Core.State).env
modifyEnv f := do modifyThe Core.State fun s => { s with env := f s.env, cache := {} }; modify fun s => { s with cache := {} }
instance : AddMessageContext MetaM where
addMessageContext := addMessageContextFull
protected def saveState : MetaM SavedState :=
return { core := (← getThe Core.State), meta := (← get) }
/-- Restore backtrackable parts of the state. -/
def SavedState.restore (b : SavedState) : MetaM Unit := do
Core.restore b.core
modify fun s => { s with mctx := b.meta.mctx, zetaFVarIds := b.meta.zetaFVarIds, postponed := b.meta.postponed }
instance : MonadBacktrack SavedState MetaM where
saveState := Meta.saveState
restoreState s := s.restore
@[inline] def MetaM.run (x : MetaM α) (ctx : Context := {}) (s : State := {}) : CoreM (α × State) :=
x ctx |>.run s
@[inline] def MetaM.run' (x : MetaM α) (ctx : Context := {}) (s : State := {}) : CoreM α :=
Prod.fst <$> x.run ctx s
@[inline] def MetaM.toIO (x : MetaM α) (ctxCore : Core.Context) (sCore : Core.State) (ctx : Context := {}) (s : State := {}) : IO (α × Core.State × State) := do
let ((a, s), sCore) ← (x.run ctx s).toIO ctxCore sCore
pure (a, sCore, s)
instance [MetaEval α] : MetaEval (MetaM α) :=
⟨fun env opts x _ => MetaEval.eval env opts x.run' true⟩
protected def throwIsDefEqStuck : MetaM α :=
throw <| Exception.internal isDefEqStuckExceptionId
builtin_initialize
registerTraceClass `Meta
registerTraceClass `Meta.debug
export Core (instantiateTypeLevelParams instantiateValueLevelParams)
@[inline] def liftMetaM [MonadLiftT MetaM m] (x : MetaM α) : m α :=
liftM x
@[inline] def mapMetaM [MonadControlT MetaM m] [Monad m] (f : forall {α}, MetaM α → MetaM α) {α} (x : m α) : m α :=
controlAt MetaM fun runInBase => f <| runInBase x
@[inline] def map1MetaM [MonadControlT MetaM m] [Monad m] (f : forall {α}, (β → MetaM α) → MetaM α) {α} (k : β → m α) : m α :=
controlAt MetaM fun runInBase => f fun b => runInBase <| k b
@[inline] def map2MetaM [MonadControlT MetaM m] [Monad m] (f : forall {α}, (β → γ → MetaM α) → MetaM α) {α} (k : β → γ → m α) : m α :=
controlAt MetaM fun runInBase => f fun b c => runInBase <| k b c
section Methods
variable [MonadControlT MetaM n] [Monad n]
@[inline] def modifyCache (f : Cache → Cache) : MetaM Unit :=
modify fun ⟨mctx, cache, zetaFVarIds, postponed⟩ => ⟨mctx, f cache, zetaFVarIds, postponed⟩
@[inline] def modifyInferTypeCache (f : InferTypeCache → InferTypeCache) : MetaM Unit :=
modifyCache fun ⟨ic, c1, c2, c3, c4, c5⟩ => ⟨f ic, c1, c2, c3, c4, c5⟩
@[inline] def modifyDefEqCache (f : DefEqCache → DefEqCache) : MetaM Unit :=
modifyCache fun ⟨c1, c2, c3, c4, c5, defeq⟩ => ⟨c1, c2, c3, c4, c5, f defeq⟩
def getLocalInstances : MetaM LocalInstances :=
return (← read).localInstances
def getConfig : MetaM Config :=
return (← read).config
def resetZetaFVarIds : MetaM Unit :=
modify fun s => { s with zetaFVarIds := {} }
def getZetaFVarIds : MetaM FVarIdSet :=
return (← get).zetaFVarIds
/-- Return the array of postponed universe level constraints. -/
def getPostponed : MetaM (PersistentArray PostponedEntry) :=
return (← get).postponed
/-- Set the array of postponed universe level constraints. -/
def setPostponed (postponed : PersistentArray PostponedEntry) : MetaM Unit :=
modify fun s => { s with postponed := postponed }
/-- Modify the array of postponed universe level constraints. -/
@[inline] def modifyPostponed (f : PersistentArray PostponedEntry → PersistentArray PostponedEntry) : MetaM Unit :=
modify fun s => { s with postponed := f s.postponed }
/--
`useEtaStruct inductName` return `true` if we eta for structures is enabled for
for the inductive datatype `inductName`.
Recall we have three different settings: `.none` (never use it), `.all` (always use it), `.notClasses`
(enabled only for structure-like inductive types that are not classes).
The parameter `inductName` affects the result only if the current setting is `.notClasses`.
-/
def useEtaStruct (inductName : Name) : MetaM Bool := do
match (← getConfig).etaStruct with
| .none => return false
| .all => return true
| .notClasses => return !isClass (← getEnv) inductName
/-! WARNING: The following 4 constants are a hack for simulating forward declarations.
They are defined later using the `export` attribute. This is hackish because we
have to hard-code the true arity of these definitions here, and make sure the C names match.
We have used another hack based on `IO.Ref`s in the past, it was safer but less efficient. -/
/-- Reduces an expression to its Weak Head Normal Form.
This is when the topmost expression has been fully reduced,
but may contain subexpressions which have not been reduced. -/
@[extern 6 "lean_whnf"] opaque whnf : Expr → MetaM Expr
/-- Returns the inferred type of the given expression, or fails if it is not type-correct. -/
@[extern 6 "lean_infer_type"] opaque inferType : Expr → MetaM Expr
@[extern 7 "lean_is_expr_def_eq"] opaque isExprDefEqAux : Expr → Expr → MetaM Bool
@[extern 7 "lean_is_level_def_eq"] opaque isLevelDefEqAux : Level → Level → MetaM Bool
@[extern 6 "lean_synth_pending"] protected opaque synthPending : MVarId → MetaM Bool
def whnfForall (e : Expr) : MetaM Expr := do
let e' ← whnf e
if e'.isForall then pure e' else pure e
-- withIncRecDepth for a monad `n` such that `[MonadControlT MetaM n]`
protected def withIncRecDepth (x : n α) : n α :=
mapMetaM (withIncRecDepth (m := MetaM)) x
private def mkFreshExprMVarAtCore
(mvarId : MVarId) (lctx : LocalContext) (localInsts : LocalInstances) (type : Expr) (kind : MetavarKind) (userName : Name) (numScopeArgs : Nat) : MetaM Expr := do
modifyMCtx fun mctx => mctx.addExprMVarDecl mvarId userName lctx localInsts type kind numScopeArgs;
return mkMVar mvarId
def mkFreshExprMVarAt
(lctx : LocalContext) (localInsts : LocalInstances) (type : Expr)
(kind : MetavarKind := MetavarKind.natural) (userName : Name := Name.anonymous) (numScopeArgs : Nat := 0)
: MetaM Expr := do
mkFreshExprMVarAtCore (← mkFreshMVarId) lctx localInsts type kind userName numScopeArgs
def mkFreshLevelMVar : MetaM Level := do
let mvarId ← mkFreshLMVarId
modifyMCtx fun mctx => mctx.addLevelMVarDecl mvarId;
return mkLevelMVar mvarId
private def mkFreshExprMVarCore (type : Expr) (kind : MetavarKind) (userName : Name) : MetaM Expr := do
mkFreshExprMVarAt (← getLCtx) (← getLocalInstances) type kind userName
private def mkFreshExprMVarImpl (type? : Option Expr) (kind : MetavarKind) (userName : Name) : MetaM Expr :=
match type? with
| some type => mkFreshExprMVarCore type kind userName
| none => do
let u ← mkFreshLevelMVar
let type ← mkFreshExprMVarCore (mkSort u) MetavarKind.natural Name.anonymous
mkFreshExprMVarCore type kind userName
def mkFreshExprMVar (type? : Option Expr) (kind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Expr :=
mkFreshExprMVarImpl type? kind userName
def mkFreshTypeMVar (kind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Expr := do
let u ← mkFreshLevelMVar
mkFreshExprMVar (mkSort u) kind userName
/-- Low-level version of `MkFreshExprMVar` which allows users to create/reserve a `mvarId` using `mkFreshId`, and then later create
the metavar using this method. -/
private def mkFreshExprMVarWithIdCore (mvarId : MVarId) (type : Expr)
(kind : MetavarKind := MetavarKind.natural) (userName : Name := Name.anonymous) (numScopeArgs : Nat := 0)
: MetaM Expr := do
mkFreshExprMVarAtCore mvarId (← getLCtx) (← getLocalInstances) type kind userName numScopeArgs
def mkFreshExprMVarWithId (mvarId : MVarId) (type? : Option Expr := none) (kind : MetavarKind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Expr :=
match type? with
| some type => mkFreshExprMVarWithIdCore mvarId type kind userName
| none => do
let u ← mkFreshLevelMVar
let type ← mkFreshExprMVar (mkSort u)
mkFreshExprMVarWithIdCore mvarId type kind userName
def mkFreshLevelMVars (num : Nat) : MetaM (List Level) :=
num.foldM (init := []) fun _ us =>
return (← mkFreshLevelMVar)::us
def mkFreshLevelMVarsFor (info : ConstantInfo) : MetaM (List Level) :=
mkFreshLevelMVars info.numLevelParams
/--
Create a constant with the given name and new universe metavariables.
Example: ``mkConstWithFreshMVarLevels `Monad`` returns `@Monad.{?u, ?v}`
-/
def mkConstWithFreshMVarLevels (declName : Name) : MetaM Expr := do
let info ← getConstInfo declName
return mkConst declName (← mkFreshLevelMVarsFor info)
/-- Return current transparency setting/mode. -/
def getTransparency : MetaM TransparencyMode :=
return (← getConfig).transparency
def shouldReduceAll : MetaM Bool :=
return (← getTransparency) == TransparencyMode.all
def shouldReduceReducibleOnly : MetaM Bool :=
return (← getTransparency) == TransparencyMode.reducible
/--
Return `some mvarDecl` where `mvarDecl` is `mvarId` declaration in the current metavariable context.
Return `none` if `mvarId` has no declaration in the current metavariable context.
-/
def _root_.Lean.MVarId.findDecl? (mvarId : MVarId) : MetaM (Option MetavarDecl) :=
return (← getMCtx).findDecl? mvarId
@[deprecated MVarId.findDecl?]
def findMVarDecl? (mvarId : MVarId) : MetaM (Option MetavarDecl) :=
mvarId.findDecl?
/--
Return `mvarId` declaration in the current metavariable context.
Throw an exception if `mvarId` is not declarated in the current metavariable context.
-/
def _root_.Lean.MVarId.getDecl (mvarId : MVarId) : MetaM MetavarDecl := do
match (← mvarId.findDecl?) with
| some d => pure d
| none => throwError "unknown metavariable '?{mvarId.name}'"
@[deprecated MVarId.getDecl]
def getMVarDecl (mvarId : MVarId) : MetaM MetavarDecl := do
mvarId.getDecl
/--
Return `mvarId` kind. Throw an exception if `mvarId` is not declarated in the current metavariable context.
-/
def _root_.Lean.MVarId.getKind (mvarId : MVarId) : MetaM MetavarKind :=
return (← mvarId.getDecl).kind
@[deprecated MVarId.getKind]
def getMVarDeclKind (mvarId : MVarId) : MetaM MetavarKind :=
mvarId.getKind
/-- Reture `true` if `e` is a synthetic (or synthetic opaque) metavariable -/
def isSyntheticMVar (e : Expr) : MetaM Bool := do
if e.isMVar then
return (← e.mvarId!.getKind) matches .synthetic | .syntheticOpaque
else
return false
/--
Set `mvarId` kind in the current metavariable context.
-/
def _root_.Lean.MVarId.setKind (mvarId : MVarId) (kind : MetavarKind) : MetaM Unit :=
modifyMCtx fun mctx => mctx.setMVarKind mvarId kind
@[deprecated MVarId.setKind]
def setMVarKind (mvarId : MVarId) (kind : MetavarKind) : MetaM Unit :=
mvarId.setKind kind
/-- Update the type of the given metavariable. This function assumes the new type is
definitionally equal to the current one -/
def _root_.Lean.MVarId.setType (mvarId : MVarId) (type : Expr) : MetaM Unit := do
modifyMCtx fun mctx => mctx.setMVarType mvarId type
@[deprecated MVarId.setType]
def setMVarType (mvarId : MVarId) (type : Expr) : MetaM Unit := do
mvarId.setType type
/--
Return true if the given metavariable is "read-only".
That is, its `depth` is different from the current metavariable context depth.
-/
def _root_.Lean.MVarId.isReadOnly (mvarId : MVarId) : MetaM Bool := do
return (← mvarId.getDecl).depth != (← getMCtx).depth
@[deprecated MVarId.isReadOnly]
def isReadOnlyExprMVar (mvarId : MVarId) : MetaM Bool := do
mvarId.isReadOnly
/--
Return true if `mvarId.isReadOnly` return true or if `mvarId` is a synthetic opaque metavariable.
Recall `isDefEq` will not assign a value to `mvarId` if `mvarId.isReadOnlyOrSyntheticOpaque`.
-/
def _root_.Lean.MVarId.isReadOnlyOrSyntheticOpaque (mvarId : MVarId) : MetaM Bool := do
let mvarDecl ← mvarId.getDecl
match mvarDecl.kind with
| MetavarKind.syntheticOpaque => return !(← getConfig).assignSyntheticOpaque
| _ => return mvarDecl.depth != (← getMCtx).depth
@[deprecated MVarId.isReadOnlyOrSyntheticOpaque]
def isReadOnlyOrSyntheticOpaqueExprMVar (mvarId : MVarId) : MetaM Bool := do
mvarId.isReadOnlyOrSyntheticOpaque
/--
Return the level of the given universe level metavariable.
-/
def _root_.Lean.LMVarId.getLevel (mvarId : LMVarId) : MetaM Nat := do
match (← getMCtx).findLevelDepth? mvarId with
| some depth => return depth
| _ => throwError "unknown universe metavariable '?{mvarId.name}'"
@[deprecated LMVarId.getLevel]
def getLevelMVarDepth (mvarId : LMVarId) : MetaM Nat :=
mvarId.getLevel
/--
Return true if the given universe metavariable is "read-only".
That is, its `depth` is different from the current metavariable context depth.
-/
def _root_.Lean.LMVarId.isReadOnly (mvarId : LMVarId) : MetaM Bool := do
if (← getConfig).ignoreLevelMVarDepth then
return false
else
return (← mvarId.getLevel) != (← getMCtx).depth
@[deprecated LMVarId.isReadOnly]
def isReadOnlyLevelMVar (mvarId : LMVarId) : MetaM Bool := do
mvarId.isReadOnly
/--
Set the user-facing name for the given metavariable.
-/
def _root_.Lean.MVarId.setUserName (mvarId : MVarId) (newUserName : Name) : MetaM Unit :=
modifyMCtx fun mctx => mctx.setMVarUserName mvarId newUserName
@[deprecated MVarId.setUserName]
def setMVarUserName (mvarId : MVarId) (userNameNew : Name) : MetaM Unit :=
mvarId.setUserName userNameNew
/--
Throw an exception saying `fvarId` is not declared in the current local context.
-/
def _root_.Lean.FVarId.throwUnknown (fvarId : FVarId) : CoreM α :=
throwError "unknown free variable '{mkFVar fvarId}'"
@[deprecated FVarId.throwUnknown]
def throwUnknownFVar (fvarId : FVarId) : MetaM α :=
fvarId.throwUnknown
/--
Return `some decl` if `fvarId` is declared in the current local context.
-/
def _root_.Lean.FVarId.findDecl? (fvarId : FVarId) : MetaM (Option LocalDecl) :=
return (← getLCtx).find? fvarId
@[deprecated FVarId.findDecl?]
def findLocalDecl? (fvarId : FVarId) : MetaM (Option LocalDecl) :=
fvarId.findDecl?
/--
Return the local declaration for the given free variable.
Throw an exception if local declaration is not in the current local context.
-/
def _root_.Lean.FVarId.getDecl (fvarId : FVarId) : MetaM LocalDecl := do
match (← getLCtx).find? fvarId with
| some d => return d
| none => fvarId.throwUnknown
@[deprecated FVarId.getDecl]
def getLocalDecl (fvarId : FVarId) : MetaM LocalDecl := do
fvarId.getDecl
/-- Return the type of the given free variable. -/
def _root_.Lean.FVarId.getType (fvarId : FVarId) : MetaM Expr :=
return (← fvarId.getDecl).type
/-- Return the binder information for the given free variable. -/
def _root_.Lean.FVarId.getBinderInfo (fvarId : FVarId) : MetaM BinderInfo :=
return (← fvarId.getDecl).binderInfo
/-- Return `some value` if the given free variable is a let-declaration, and `none` otherwise. -/
def _root_.Lean.FVarId.getValue? (fvarId : FVarId) : MetaM (Option Expr) :=
return (← fvarId.getDecl).value?
/-- Return the user-facing name for the given free variable. -/
def _root_.Lean.FVarId.getUserName (fvarId : FVarId) : MetaM Name :=
return (← fvarId.getDecl).userName
/-- Return `true` is the free variable is a let-variable. -/
def _root_.Lean.FVarId.isLetVar (fvarId : FVarId) : MetaM Bool :=
return (← fvarId.getDecl).isLet
/-- Get the local declaration associated to the given `Expr` in the current local
context. Fails if the given expression is not a fvar or if no such declaration exists. -/
def getFVarLocalDecl (fvar : Expr) : MetaM LocalDecl :=
fvar.fvarId!.getDecl
/--
Given a user-facing name for a free variable, return its declaration in the current local context.
Throw an exception if free variable is not declared.
-/
def getLocalDeclFromUserName (userName : Name) : MetaM LocalDecl := do
match (← getLCtx).findFromUserName? userName with
| some d => pure d
| none => throwError "unknown local declaration '{userName}'"
/-- Given a user-facing name for a free variable, return the free variable or throw if not declared. -/
def getFVarFromUserName (userName : Name) : MetaM Expr := do
let d ← getLocalDeclFromUserName userName
return Expr.fvar d.fvarId
/--
Lift a `MkBindingM` monadic action `x` to `MetaM`.
-/
@[inline] def liftMkBindingM (x : MetavarContext.MkBindingM α) : MetaM α := do
match x { lctx := (← getLCtx), mainModule := (← getEnv).mainModule } { mctx := (← getMCtx), ngen := (← getNGen), nextMacroScope := (← getThe Core.State).nextMacroScope } with
| .ok e sNew => do
setMCtx sNew.mctx
modifyThe Core.State fun s => { s with ngen := sNew.ngen, nextMacroScope := sNew.nextMacroScope }
pure e
| .error (.revertFailure ..) sNew => do
setMCtx sNew.mctx
modifyThe Core.State fun s => { s with ngen := sNew.ngen, nextMacroScope := sNew.nextMacroScope }
throwError "failed to create binder due to failure when reverting variable dependencies"
/--
Similar to `abstracM` but consider only the first `min n xs.size` entries in `xs`
It is also similar to `Expr.abstractRange`, but handles metavariables correctly.
It uses `elimMVarDeps` to ensure `e` and the type of the free variables `xs` do not
contain a metavariable `?m` s.t. local context of `?m` contains a free variable in `xs`.
-/
def _root_.Lean.Expr.abstractRangeM (e : Expr) (n : Nat) (xs : Array Expr) : MetaM Expr :=
liftMkBindingM <| MetavarContext.abstractRange e n xs
@[deprecated Expr.abstractRangeM]
def abstractRange (e : Expr) (n : Nat) (xs : Array Expr) : MetaM Expr :=
e.abstractRangeM n xs
/--
Replace free (or meta) variables `xs` with loose bound variables.
Similar to `Expr.abstract`, but handles metavariables correctly.
-/
def _root_.Lean.Expr.abstractM (e : Expr) (xs : Array Expr) : MetaM Expr :=
e.abstractRangeM xs.size xs
@[deprecated Expr.abstractM]
def abstract (e : Expr) (xs : Array Expr) : MetaM Expr :=
e.abstractM xs
/--
Collect forward dependencies for the free variables in `toRevert`.
Recall that when reverting free variables `xs`, we must also revert their forward dependencies.
-/
def collectForwardDeps (toRevert : Array Expr) (preserveOrder : Bool) : MetaM (Array Expr) := do
liftMkBindingM <| MetavarContext.collectForwardDeps toRevert preserveOrder
/-- Takes an array `xs` of free variables or metavariables and a term `e` that may contain those variables, and abstracts and binds them as universal quantifiers.
- if `usedOnly = true` then only variables that the expression body depends on will appear.
- if `usedLetOnly = true` same as `usedOnly` except for let-bound variables. (That is, local constants which have been assigned a value.)
-/
def mkForallFVars (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) (usedLetOnly : Bool := true) (binderInfoForMVars := BinderInfo.implicit) : MetaM Expr :=
if xs.isEmpty then return e else liftMkBindingM <| MetavarContext.mkForall xs e usedOnly usedLetOnly binderInfoForMVars
/-- Takes an array `xs` of free variables and metavariables and a
body term `e` and creates `fun ..xs => e`, suitably
abstracting `e` and the types in `xs`. -/
def mkLambdaFVars (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) (usedLetOnly : Bool := true) (binderInfoForMVars := BinderInfo.implicit) : MetaM Expr :=
if xs.isEmpty then return e else liftMkBindingM <| MetavarContext.mkLambda xs e usedOnly usedLetOnly binderInfoForMVars
def mkLetFVars (xs : Array Expr) (e : Expr) (usedLetOnly := true) (binderInfoForMVars := BinderInfo.implicit) : MetaM Expr :=
mkLambdaFVars xs e (usedLetOnly := usedLetOnly) (binderInfoForMVars := binderInfoForMVars)
/-- `fun _ : Unit => a` -/
def mkFunUnit (a : Expr) : MetaM Expr :=
return Lean.mkLambda (← mkFreshUserName `x) BinderInfo.default (mkConst ``Unit) a
def elimMVarDeps (xs : Array Expr) (e : Expr) (preserveOrder : Bool := false) : MetaM Expr :=
if xs.isEmpty then pure e else liftMkBindingM <| MetavarContext.elimMVarDeps xs e preserveOrder
/-- `withConfig f x` executes `x` using the updated configuration object obtained by applying `f`. -/
@[inline] def withConfig (f : Config → Config) : n α → n α :=
mapMetaM <| withReader (fun ctx => { ctx with config := f ctx.config })
@[inline] def withTrackingZeta (x : n α) : n α :=
withConfig (fun cfg => { cfg with trackZeta := true }) x
@[inline] def withoutProofIrrelevance (x : n α) : n α :=
withConfig (fun cfg => { cfg with proofIrrelevance := false }) x
@[inline] def withTransparency (mode : TransparencyMode) : n α → n α :=
mapMetaM <| withConfig (fun config => { config with transparency := mode })
/-- `withDefault x` excutes `x` using the default transparency setting. -/
@[inline] def withDefault (x : n α) : n α :=
withTransparency TransparencyMode.default x
/-- `withReducible x` excutes `x` using the reducible transparency setting. In this setting only definitions tagged as `[reducible]` are unfolded. -/
@[inline] def withReducible (x : n α) : n α :=
withTransparency TransparencyMode.reducible x
/--
`withReducibleAndInstances x` excutes `x` using the `.instances` transparency setting. In this setting only definitions tagged as `[reducible]`
or type class instances are unfolded.
-/
@[inline] def withReducibleAndInstances (x : n α) : n α :=
withTransparency TransparencyMode.instances x
/--
Execute `x` ensuring the transparency setting is at least `mode`.
Recall that `.all > .default > .instances > .reducible`.
-/
@[inline] def withAtLeastTransparency (mode : TransparencyMode) (x : n α) : n α :=
withConfig
(fun config =>
let oldMode := config.transparency
let mode := if oldMode.lt mode then mode else oldMode
{ config with transparency := mode })
x
/-- Execute `x` allowing `isDefEq` to assign synthetic opaque metavariables. -/
@[inline] def withAssignableSyntheticOpaque (x : n α) : n α :=
withConfig (fun config => { config with assignSyntheticOpaque := true }) x
/-- Save cache, execute `x`, restore cache -/
@[inline] private def savingCacheImpl (x : MetaM α) : MetaM α := do
let savedCache := (← get).cache
try x finally modify fun s => { s with cache := savedCache }
@[inline] def savingCache : n α → n α :=
mapMetaM savingCacheImpl
def getTheoremInfo (info : ConstantInfo) : MetaM (Option ConstantInfo) := do
if (← shouldReduceAll) then
return some info
else
return none
private def getDefInfoTemp (info : ConstantInfo) : MetaM (Option ConstantInfo) := do
match (← getTransparency) with
| TransparencyMode.all => return some info
| TransparencyMode.default => return some info
| _ =>
if (← isReducible info.name) then
return some info
else
return none
/-- Remark: we later define `getConst?` at `GetConst.lean` after we define `Instances.lean`.
This method is only used to implement `isClassQuickConst?`.
It is very similar to `getConst?`, but it returns none when `TransparencyMode.instances` and
`constName` is an instance. This difference should be irrelevant for `isClassQuickConst?`. -/
private def getConstTemp? (constName : Name) : MetaM (Option ConstantInfo) := do
match (← getEnv).find? constName with
| some (info@(ConstantInfo.thmInfo _)) => getTheoremInfo info
| some (info@(ConstantInfo.defnInfo _)) => getDefInfoTemp info
| some info => pure (some info)
| none => throwUnknownConstant constName
private def isClassQuickConst? (constName : Name) : MetaM (LOption Name) := do
if isClass (← getEnv) constName then
return .some constName
else
match (← getConstTemp? constName) with
| some (.defnInfo ..) => return .undef -- We may be able to unfold the definition
| _ => return .none
private partial def isClassQuick? : Expr → MetaM (LOption Name)
| .bvar .. => return .none
| .lit .. => return .none
| .fvar .. => return .none
| .sort .. => return .none
| .lam .. => return .none
| .letE .. => return .undef
| .proj .. => return .undef
| .forallE _ _ b _ => isClassQuick? b
| .mdata _ e => isClassQuick? e
| .const n _ => isClassQuickConst? n
| .mvar mvarId => do
match (← getExprMVarAssignment? mvarId) with
| some val => isClassQuick? val
| none => return .none
| .app f _ =>
match f.getAppFn with
| .const n .. => isClassQuickConst? n
| .lam .. => return .undef
| _ => return .none
def saveAndResetSynthInstanceCache : MetaM SynthInstanceCache := do
let savedSythInstance := (← get).cache.synthInstance
modifyCache fun c => { c with synthInstance := {} }
return savedSythInstance
def restoreSynthInstanceCache (cache : SynthInstanceCache) : MetaM Unit :=
modifyCache fun c => { c with synthInstance := cache }
@[inline] private def resettingSynthInstanceCacheImpl (x : MetaM α) : MetaM α := do
let savedSythInstance ← saveAndResetSynthInstanceCache
try x finally restoreSynthInstanceCache savedSythInstance
/-- Reset `synthInstance` cache, execute `x`, and restore cache -/
@[inline] def resettingSynthInstanceCache : n α → n α :=
mapMetaM resettingSynthInstanceCacheImpl
@[inline] def resettingSynthInstanceCacheWhen (b : Bool) (x : n α) : n α :=
if b then resettingSynthInstanceCache x else x
private def withNewLocalInstanceImp (className : Name) (fvar : Expr) (k : MetaM α) : MetaM α := do
let localDecl ← getFVarLocalDecl fvar
/- Recall that we use `auxDecl` binderInfo when compiling recursive declarations. -/
match localDecl.binderInfo with
| .auxDecl => k
| _ =>
resettingSynthInstanceCache <|
withReader
(fun ctx => { ctx with localInstances := ctx.localInstances.push { className := className, fvar := fvar } })
k
/-- Add entry `{ className := className, fvar := fvar }` to localInstances,
and then execute continuation `k`.
It resets the type class cache using `resettingSynthInstanceCache`. -/
def withNewLocalInstance (className : Name) (fvar : Expr) : n α → n α :=
mapMetaM <| withNewLocalInstanceImp className fvar
private def fvarsSizeLtMaxFVars (fvars : Array Expr) (maxFVars? : Option Nat) : Bool :=
match maxFVars? with
| some maxFVars => fvars.size < maxFVars
| none => true
mutual
/--
`withNewLocalInstances isClassExpensive fvars j k` updates the vector or local instances
using free variables `fvars[j] ... fvars.back`, and execute `k`.
- `isClassExpensive` is defined later.
- The type class chache is reset whenever a new local instance is found.
- `isClassExpensive` uses `whnf` which depends (indirectly) on the set of local instances.
Thus, each new local instance requires a new `resettingSynthInstanceCache`. -/
private partial def withNewLocalInstancesImp
(fvars : Array Expr) (i : Nat) (k : MetaM α) : MetaM α := do
if h : i < fvars.size then
let fvar := fvars.get ⟨i, h⟩
let decl ← getFVarLocalDecl fvar
match (← isClassQuick? decl.type) with
| .none => withNewLocalInstancesImp fvars (i+1) k
| .undef =>
match (← isClassExpensive? decl.type) with
| none => withNewLocalInstancesImp fvars (i+1) k
| some c => withNewLocalInstance c fvar <| withNewLocalInstancesImp fvars (i+1) k
| .some c => withNewLocalInstance c fvar <| withNewLocalInstancesImp fvars (i+1) k
else
k
/--
`forallTelescopeAuxAux lctx fvars j type`
Remarks:
- `lctx` is the `MetaM` local context extended with declarations for `fvars`.
- `type` is the type we are computing the telescope for. It contains only
dangling bound variables in the range `[j, fvars.size)`
- if `reducing? == true` and `type` is not `forallE`, we use `whnf`.
- when `type` is not a `forallE` nor it can't be reduced to one, we
excute the continuation `k`.
Here is an example that demonstrates the `reducing?`.
Suppose we have
```
abbrev StateM s a := s -> Prod a s
```
Now, assume we are trying to build the telescope for
```
forall (x : Nat), StateM Int Bool
```
if `reducing == true`, the function executes `k #[(x : Nat) (s : Int)] Bool`.
if `reducing == false`, the function executes `k #[(x : Nat)] (StateM Int Bool)`
if `maxFVars?` is `some max`, then we interrupt the telescope construction
when `fvars.size == max`
-/
private partial def forallTelescopeReducingAuxAux
(reducing : Bool) (maxFVars? : Option Nat)
(type : Expr)
(k : Array Expr → Expr → MetaM α) : MetaM α := do
let rec process (lctx : LocalContext) (fvars : Array Expr) (j : Nat) (type : Expr) : MetaM α := do
match type with
| .forallE n d b bi =>
if fvarsSizeLtMaxFVars fvars maxFVars? then
let d := d.instantiateRevRange j fvars.size fvars
let fvarId ← mkFreshFVarId
let lctx := lctx.mkLocalDecl fvarId n d bi
let fvar := mkFVar fvarId
let fvars := fvars.push fvar
process lctx fvars j b
else
let type := type.instantiateRevRange j fvars.size fvars;
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
k fvars type
| _ =>
let type := type.instantiateRevRange j fvars.size fvars;
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
if reducing && fvarsSizeLtMaxFVars fvars maxFVars? then
let newType ← whnf type
if newType.isForall then
process lctx fvars fvars.size newType
else
k fvars type
else
k fvars type
process (← getLCtx) #[] 0 type
private partial def forallTelescopeReducingAux (type : Expr) (maxFVars? : Option Nat) (k : Array Expr → Expr → MetaM α) : MetaM α := do
match maxFVars? with
| some 0 => k #[] type
| _ => do
let newType ← whnf type
if newType.isForall then
forallTelescopeReducingAuxAux true maxFVars? newType k
else
k #[] type
private partial def isClassExpensive? (type : Expr) : MetaM (Option Name) :=
withReducible do -- when testing whether a type is a type class, we only unfold reducible constants.
forallTelescopeReducingAux type none fun _ type => do
let env ← getEnv
match type.getAppFn with
| .const c _ => do
if isClass env c then
return some c
else
-- make sure abbreviations are unfolded
match (← whnf type).getAppFn with
| .const c _ => return if isClass env c then some c else none
| _ => return none
| _ => return none
private partial def isClassImp? (type : Expr) : MetaM (Option Name) := do
match (← isClassQuick? type) with
| .none => return none
| .some c => return (some c)
| .undef => isClassExpensive? type
end
/--
`isClass? type` return `some ClsName` if `type` is an instance of the class `ClsName`.
Example:
```
#eval do
let x ← mkAppM ``Inhabited #[mkConst ``Nat]
IO.println (← isClass? x)
-- (some Inhabited)
```
-/
def isClass? (type : Expr) : MetaM (Option Name) :=
try isClassImp? type catch _ => return none
private def withNewLocalInstancesImpAux (fvars : Array Expr) (j : Nat) : n α → n α :=
mapMetaM <| withNewLocalInstancesImp fvars j
partial def withNewLocalInstances (fvars : Array Expr) (j : Nat) : n α → n α :=
mapMetaM <| withNewLocalInstancesImpAux fvars j
@[inline] private def forallTelescopeImp (type : Expr) (k : Array Expr → Expr → MetaM α) : MetaM α := do
forallTelescopeReducingAuxAux (reducing := false) (maxFVars? := none) type k
/--
Given `type` of the form `forall xs, A`, execute `k xs A`.
This combinator will declare local declarations, create free variables for them,
execute `k` with updated local context, and make sure the cache is restored after executing `k`. -/
def forallTelescope (type : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => forallTelescopeImp type k) k
private def forallTelescopeReducingImp (type : Expr) (k : Array Expr → Expr → MetaM α) : MetaM α :=
forallTelescopeReducingAux type (maxFVars? := none) k
/--
Similar to `forallTelescope`, but given `type` of the form `forall xs, A`,
it reduces `A` and continues bulding the telescope if it is a `forall`. -/
def forallTelescopeReducing (type : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => forallTelescopeReducingImp type k) k
private def forallBoundedTelescopeImp (type : Expr) (maxFVars? : Option Nat) (k : Array Expr → Expr → MetaM α) : MetaM α :=
forallTelescopeReducingAux type maxFVars? k
/--
Similar to `forallTelescopeReducing`, stops constructing the telescope when
it reaches size `maxFVars`. -/
def forallBoundedTelescope (type : Expr) (maxFVars? : Option Nat) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => forallBoundedTelescopeImp type maxFVars? k) k
private partial def lambdaTelescopeImp (e : Expr) (consumeLet : Bool) (k : Array Expr → Expr → MetaM α) : MetaM α := do
process consumeLet (← getLCtx) #[] 0 e
where
process (consumeLet : Bool) (lctx : LocalContext) (fvars : Array Expr) (j : Nat) (e : Expr) : MetaM α := do
match consumeLet, e with
| _, .lam n d b bi =>
let d := d.instantiateRevRange j fvars.size fvars
let fvarId ← mkFreshFVarId
let lctx := lctx.mkLocalDecl fvarId n d bi
let fvar := mkFVar fvarId
process consumeLet lctx (fvars.push fvar) j b
| true, .letE n t v b _ => do
let t := t.instantiateRevRange j fvars.size fvars
let v := v.instantiateRevRange j fvars.size fvars
let fvarId ← mkFreshFVarId
let lctx := lctx.mkLetDecl fvarId n t v
let fvar := mkFVar fvarId
process true lctx (fvars.push fvar) j b
| _, e =>
let e := e.instantiateRevRange j fvars.size fvars
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstancesImp fvars j do
k fvars e
/-- Similar to `lambdaTelescope` but for lambda and let expressions. -/
def lambdaLetTelescope (e : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => lambdaTelescopeImp e true k) k
/--
Given `e` of the form `fun ..xs => A`, execute `k xs A`.
This combinator will declare local declarations, create free variables for them,
execute `k` with updated local context, and make sure the cache is restored after executing `k`. -/
def lambdaTelescope (e : Expr) (k : Array Expr → Expr → n α) : n α :=
map2MetaM (fun k => lambdaTelescopeImp e false k) k
/-- Return the parameter names for the given global declaration. -/
def getParamNames (declName : Name) : MetaM (Array Name) := do
forallTelescopeReducing (← getConstInfo declName).type fun xs _ => do
xs.mapM fun x => do
let localDecl ← x.fvarId!.getDecl
return localDecl.userName
-- `kind` specifies the metavariable kind for metavariables not corresponding to instance implicit `[ ... ]` arguments.
private partial def forallMetaTelescopeReducingAux
(e : Expr) (reducing : Bool) (maxMVars? : Option Nat) (kind : MetavarKind) : MetaM (Array Expr × Array BinderInfo × Expr) :=
process #[] #[] 0 e
where
process (mvars : Array Expr) (bis : Array BinderInfo) (j : Nat) (type : Expr) : MetaM (Array Expr × Array BinderInfo × Expr) := do
if maxMVars?.isEqSome mvars.size then
let type := type.instantiateRevRange j mvars.size mvars;
return (mvars, bis, type)
else
match type with
| .forallE n d b bi =>
let d := d.instantiateRevRange j mvars.size mvars
let k := if bi.isInstImplicit then MetavarKind.synthetic else kind
let mvar ← mkFreshExprMVar d k n
let mvars := mvars.push mvar
let bis := bis.push bi
process mvars bis j b
| _ =>
let type := type.instantiateRevRange j mvars.size mvars;
if reducing then do
let newType ← whnf type;
if newType.isForall then
process mvars bis mvars.size newType
else
return (mvars, bis, type)
else
return (mvars, bis, type)
/-- Given `e` of the form `forall ..xs, A`, this combinator will create a new
metavariable for each `x` in `xs` and instantiate `A` with these.
Returns a product containing
- the new metavariables
- the binder info for the `xs`
- the instantiated `A`
-/
def forallMetaTelescope (e : Expr) (kind := MetavarKind.natural) : MetaM (Array Expr × Array BinderInfo × Expr) :=
forallMetaTelescopeReducingAux e (reducing := false) (maxMVars? := none) kind
/-- Similar to `forallMetaTelescope`, but if `e = forall ..xs, A`
it will reduce `A` to construct further mvars. -/
def forallMetaTelescopeReducing (e : Expr) (maxMVars? : Option Nat := none) (kind := MetavarKind.natural) : MetaM (Array Expr × Array BinderInfo × Expr) :=
forallMetaTelescopeReducingAux e (reducing := true) maxMVars? kind
/-- Similar to `forallMetaTelescopeReducing`, stops
constructing the telescope when it reaches size `maxMVars`. -/
def forallMetaBoundedTelescope (e : Expr) (maxMVars : Nat) (kind : MetavarKind := MetavarKind.natural) : MetaM (Array Expr × Array BinderInfo × Expr) :=
forallMetaTelescopeReducingAux e (reducing := true) (maxMVars? := some maxMVars) (kind := kind)
/-- Similar to `forallMetaTelescopeReducingAux` but for lambda expressions. -/
partial def lambdaMetaTelescope (e : Expr) (maxMVars? : Option Nat := none) : MetaM (Array Expr × Array BinderInfo × Expr) :=
process #[] #[] 0 e
where
process (mvars : Array Expr) (bis : Array BinderInfo) (j : Nat) (type : Expr) : MetaM (Array Expr × Array BinderInfo × Expr) := do
let finalize : Unit → MetaM (Array Expr × Array BinderInfo × Expr) := fun _ => do
let type := type.instantiateRevRange j mvars.size mvars
return (mvars, bis, type)
if maxMVars?.isEqSome mvars.size then
finalize ()
else
match type with
| .lam _ d b bi =>
let d := d.instantiateRevRange j mvars.size mvars
let mvar ← mkFreshExprMVar d
let mvars := mvars.push mvar
let bis := bis.push bi
process mvars bis j b
| _ => finalize ()
private def withNewFVar (fvar fvarType : Expr) (k : Expr → MetaM α) : MetaM α := do
match (← isClass? fvarType) with
| none => k fvar
| some c => withNewLocalInstance c fvar <| k fvar
private def withLocalDeclImp (n : Name) (bi : BinderInfo) (type : Expr) (k : Expr → MetaM α) : MetaM α := do
let fvarId ← mkFreshFVarId
let ctx ← read
let lctx := ctx.lctx.mkLocalDecl fvarId n type bi
let fvar := mkFVar fvarId
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewFVar fvar type k
/-- Create a free variable `x` with name, binderInfo and type, add it to the context and run in `k`.
Then revert the context. -/
def withLocalDecl (name : Name) (bi : BinderInfo) (type : Expr) (k : Expr → n α) : n α :=
map1MetaM (fun k => withLocalDeclImp name bi type k) k
def withLocalDeclD (name : Name) (type : Expr) (k : Expr → n α) : n α :=
withLocalDecl name BinderInfo.default type k
/-- Append an array of free variables `xs` to the local context and execute `k xs`.
declInfos takes the form of an array consisting of:
- the name of the variable
- the binder info of the variable
- a type constructor for the variable, where the array consists of all of the free variables
defined prior to this one. This is needed because the type of the variable may depend on prior variables.
-/
partial def withLocalDecls
[Inhabited α]
(declInfos : Array (Name × BinderInfo × (Array Expr → n Expr)))
(k : (xs : Array Expr) → n α)
: n α :=
loop #[]
where
loop [Inhabited α] (acc : Array Expr) : n α := do
if acc.size < declInfos.size then
let (name, bi, typeCtor) := declInfos[acc.size]!
withLocalDecl name bi (←typeCtor acc) fun x => loop (acc.push x)
else
k acc
def withLocalDeclsD [Inhabited α] (declInfos : Array (Name × (Array Expr → n Expr))) (k : (xs : Array Expr) → n α) : n α :=
withLocalDecls
(declInfos.map (fun (name, typeCtor) => (name, BinderInfo.default, typeCtor))) k
private def withNewBinderInfosImp (bs : Array (FVarId × BinderInfo)) (k : MetaM α) : MetaM α := do
let lctx := bs.foldl (init := (← getLCtx)) fun lctx (fvarId, bi) =>
lctx.setBinderInfo fvarId bi
withReader (fun ctx => { ctx with lctx := lctx }) k
def withNewBinderInfos (bs : Array (FVarId × BinderInfo)) (k : n α) : n α :=
mapMetaM (fun k => withNewBinderInfosImp bs k) k
/--
Execute `k` using a local context where any `x` in `xs` that is tagged as
instance implicit is treated as a regular implicit. -/
def withInstImplicitAsImplict (xs : Array Expr) (k : MetaM α) : MetaM α := do
let newBinderInfos ← xs.filterMapM fun x => do
let bi ← x.fvarId!.getBinderInfo
if bi == .instImplicit then
return some (x.fvarId!, .implicit)
else
return none
withNewBinderInfos newBinderInfos k
private def withLetDeclImp (n : Name) (type : Expr) (val : Expr) (k : Expr → MetaM α) : MetaM α := do
let fvarId ← mkFreshFVarId
let ctx ← read
let lctx := ctx.lctx.mkLetDecl fvarId n type val
let fvar := mkFVar fvarId
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewFVar fvar type k
/--
Add the local declaration `<name> : <type> := <val>` to the local context and execute `k x`, where `x` is a new
free variable corresponding to the `let`-declaration. After executing `k x`, the local context is restored.
-/
def withLetDecl (name : Name) (type : Expr) (val : Expr) (k : Expr → n α) : n α :=
map1MetaM (fun k => withLetDeclImp name type val k) k
def withLocalInstancesImp (decls : List LocalDecl) (k : MetaM α) : MetaM α := do
let localInsts := (← read).localInstances
let size := localInsts.size
let localInstsNew ← decls.foldlM (init := localInsts) fun localInstsNew decl => do
match (← isClass? decl.type) with
| none => return localInstsNew
| some className => return localInstsNew.push { className, fvar := decl.toExpr }
if localInstsNew.size == size then
k
else
resettingSynthInstanceCache <| withReader (fun ctx => { ctx with localInstances := localInstsNew }) k
/-- Register any local instance in `decls` -/
def withLocalInstances (decls : List LocalDecl) : n α → n α :=
mapMetaM <| withLocalInstancesImp decls
private def withExistingLocalDeclsImp (decls : List LocalDecl) (k : MetaM α) : MetaM α := do
let ctx ← read
let lctx := decls.foldl (fun (lctx : LocalContext) decl => lctx.addDecl decl) ctx.lctx
withReader (fun ctx => { ctx with lctx := lctx }) do
withLocalInstancesImp decls k
/--
`withExistingLocalDecls decls k`, adds the given local declarations to the local context,
and then executes `k`. This method assumes declarations in `decls` have valid `FVarId`s.
After executing `k`, the local context is restored.
Remark: this method is used, for example, to implement the `match`-compiler.
Each `match`-alternative commes with a local declarations (corresponding to pattern variables),
and we use `withExistingLocalDecls` to add them to the local context before we process
them.
-/
def withExistingLocalDecls (decls : List LocalDecl) : n α → n α :=
mapMetaM <| withExistingLocalDeclsImp decls
private def withNewMCtxDepthImp (x : MetaM α) : MetaM α := do
let saved ← get
modify fun s => { s with mctx := s.mctx.incDepth, postponed := {} }
try
x
finally
modify fun s => { s with mctx := saved.mctx, postponed := saved.postponed }
/--
Save cache and `MetavarContext`, bump the `MetavarContext` depth, execute `x`,
and restore saved data.
Metavariable context depths are used to control which metavariables may be assigned in `isDefEq`.
See the docstring of `isDefEq` for more information.
-/
def withNewMCtxDepth : n α → n α :=
mapMetaM withNewMCtxDepthImp
private def withLocalContextImp (lctx : LocalContext) (localInsts : LocalInstances) (x : MetaM α) : MetaM α := do
let localInstsCurr ← getLocalInstances
withReader (fun ctx => { ctx with lctx := lctx, localInstances := localInsts }) do
if localInsts == localInstsCurr then
x
else
resettingSynthInstanceCache x
/--
`withLCtx lctx localInsts k` replaces the local context and local instances, and then executes `k`.
The local context and instances are restored after executing `k`.
This method assumes that the local instances in `localInsts` are in the local context `lctx`.
-/
def withLCtx (lctx : LocalContext) (localInsts : LocalInstances) : n α → n α :=
mapMetaM <| withLocalContextImp lctx localInsts
private def withMVarContextImp (mvarId : MVarId) (x : MetaM α) : MetaM α := do
let mvarDecl ← mvarId.getDecl
withLocalContextImp mvarDecl.lctx mvarDecl.localInstances x
/--
Execute `x` using the given metavariable `LocalContext` and `LocalInstances`.
The type class resolution cache is flushed when executing `x` if its `LocalInstances` are
different from the current ones. -/
def _root_.Lean.MVarId.withContext (mvarId : MVarId) : n α → n α :=
mapMetaM <| withMVarContextImp mvarId
@[deprecated MVarId.withContext]
def withMVarContext (mvarId : MVarId) : n α → n α :=
mvarId.withContext
private def withMCtxImp (mctx : MetavarContext) (x : MetaM α) : MetaM α := do
let mctx' ← getMCtx
setMCtx mctx
try x finally setMCtx mctx'
/--
`withMCtx mctx k` replaces the metavariable context and then executes `k`.
The metavariable context is restored after executing `k`.
This method is used to implement the type class resolution procedure. -/
def withMCtx (mctx : MetavarContext) : n α → n α :=
mapMetaM <| withMCtxImp mctx
@[inline] private def approxDefEqImp (x : MetaM α) : MetaM α :=
withConfig (fun config => { config with foApprox := true, ctxApprox := true, quasiPatternApprox := true}) x
/-- Execute `x` using approximate unification: `foApprox`, `ctxApprox` and `quasiPatternApprox`. -/
@[inline] def approxDefEq : n α → n α :=
mapMetaM approxDefEqImp
@[inline] private def fullApproxDefEqImp (x : MetaM α) : MetaM α :=
withConfig (fun config => { config with foApprox := true, ctxApprox := true, quasiPatternApprox := true, constApprox := true }) x
/--
Similar to `approxDefEq`, but uses all available approximations.
We don't use `constApprox` by default at `approxDefEq` because it often produces undesirable solution for monadic code.
For example, suppose we have `pure (x > 0)` which has type `?m Prop`. We also have the goal `[Pure ?m]`.
Now, assume the expected type is `IO Bool`. Then, the unification constraint `?m Prop =?= IO Bool` could be solved
as `?m := fun _ => IO Bool` using `constApprox`, but this spurious solution would generate a failure when we try to
solve `[Pure (fun _ => IO Bool)]` -/
@[inline] def fullApproxDefEq : n α → n α :=
mapMetaM fullApproxDefEqImp
/-- Instantiate assigned universe metavariables in `u`, and then normalize it. -/
def normalizeLevel (u : Level) : MetaM Level := do
let u ← instantiateLevelMVars u
pure u.normalize
/-- `whnf` with reducible transparency.-/
def whnfR (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.reducible <| whnf e
/-- `whnf` with default transparency.-/
def whnfD (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.default <| whnf e
/-- `whnf` with instances transparency.-/
def whnfI (e : Expr) : MetaM Expr :=
withTransparency TransparencyMode.instances <| whnf e
/--
Mark declaration `declName` with the attribute `[inline]`.
This method does not check whether the given declaration is a definition.
Recall that this attribute can only be set in the same module where `declName` has been declared.
-/
def setInlineAttribute (declName : Name) (kind := Compiler.InlineAttributeKind.inline): MetaM Unit := do
let env ← getEnv
match Compiler.setInlineAttribute env declName kind with
| .ok env => setEnv env
| .error msg => throwError msg
private partial def instantiateForallAux (ps : Array Expr) (i : Nat) (e : Expr) : MetaM Expr := do
if h : i < ps.size then
let p := ps.get ⟨i, h⟩
match (← whnf e) with
| .forallE _ _ b _ => instantiateForallAux ps (i+1) (b.instantiate1 p)
| _ => throwError "invalid instantiateForall, too many parameters"
else
return e
/-- Given `e` of the form `forall (a_1 : A_1) ... (a_n : A_n), B[a_1, ..., a_n]` and `p_1 : A_1, ... p_n : A_n`, return `B[p_1, ..., p_n]`. -/
def instantiateForall (e : Expr) (ps : Array Expr) : MetaM Expr :=
instantiateForallAux ps 0 e
private partial def instantiateLambdaAux (ps : Array Expr) (i : Nat) (e : Expr) : MetaM Expr := do
if h : i < ps.size then
let p := ps.get ⟨i, h⟩
match (← whnf e) with
| .lam _ _ b _ => instantiateLambdaAux ps (i+1) (b.instantiate1 p)
| _ => throwError "invalid instantiateLambda, too many parameters"
else
return e
/-- Given `e` of the form `fun (a_1 : A_1) ... (a_n : A_n) => t[a_1, ..., a_n]` and `p_1 : A_1, ... p_n : A_n`, return `t[p_1, ..., p_n]`.
It uses `whnf` to reduce `e` if it is not a lambda -/
def instantiateLambda (e : Expr) (ps : Array Expr) : MetaM Expr :=
instantiateLambdaAux ps 0 e
/-- Pretty-print the given expression. -/
def ppExpr (e : Expr) : MetaM Format := do
let ctxCore ← readThe Core.Context
Lean.ppExpr { env := (← getEnv), mctx := (← getMCtx), lctx := (← getLCtx), opts := (← getOptions), currNamespace := ctxCore.currNamespace, openDecls := ctxCore.openDecls } e
@[inline] protected def orElse (x : MetaM α) (y : Unit → MetaM α) : MetaM α := do
let s ← saveState
try x catch _ => s.restore; y ()
instance : OrElse (MetaM α) := ⟨Meta.orElse⟩
instance : Alternative MetaM where
failure := fun {_} => throwError "failed"
orElse := Meta.orElse
@[inline] private def orelseMergeErrorsImp (x y : MetaM α)
(mergeRef : Syntax → Syntax → Syntax := fun r₁ _ => r₁)
(mergeMsg : MessageData → MessageData → MessageData := fun m₁ m₂ => m₁ ++ Format.line ++ m₂) : MetaM α := do
let env ← getEnv
let mctx ← getMCtx
try
x
catch ex =>
setEnv env
setMCtx mctx
match ex with
| Exception.error ref₁ m₁ =>
try
y
catch
| Exception.error ref₂ m₂ => throw <| Exception.error (mergeRef ref₁ ref₂) (mergeMsg m₁ m₂)
| ex => throw ex
| ex => throw ex
/--
Similar to `orelse`, but merge errors. Note that internal errors are not caught.
The default `mergeRef` uses the `ref` (position information) for the first message.
The default `mergeMsg` combines error messages using `Format.line ++ Format.line` as a separator. -/
@[inline] def orelseMergeErrors [MonadControlT MetaM m] [Monad m] (x y : m α)
(mergeRef : Syntax → Syntax → Syntax := fun r₁ _ => r₁)
(mergeMsg : MessageData → MessageData → MessageData := fun m₁ m₂ => m₁ ++ Format.line ++ Format.line ++ m₂) : m α := do
controlAt MetaM fun runInBase => orelseMergeErrorsImp (runInBase x) (runInBase y) mergeRef mergeMsg
/-- Execute `x`, and apply `f` to the produced error message -/
def mapErrorImp (x : MetaM α) (f : MessageData → MessageData) : MetaM α := do
try
x
catch
| Exception.error ref msg => throw <| Exception.error ref <| f msg
| ex => throw ex
@[inline] def mapError [MonadControlT MetaM m] [Monad m] (x : m α) (f : MessageData → MessageData) : m α :=
controlAt MetaM fun runInBase => mapErrorImp (runInBase x) f
/--
Sort free variables using an order `x < y` iff `x` was defined before `y`.
If a free variable is not in the local context, we use their id. -/
def sortFVarIds (fvarIds : Array FVarId) : MetaM (Array FVarId) := do
let lctx ← getLCtx
return fvarIds.qsort fun fvarId₁ fvarId₂ =>
match lctx.find? fvarId₁, lctx.find? fvarId₂ with
| some d₁, some d₂ => d₁.index < d₂.index
| some _, none => false
| none, some _ => true
| none, none => Name.quickLt fvarId₁.name fvarId₂.name
end Methods
/-- Return `true` if `declName` is an inductive predicate. That is, `inductive` type in `Prop`. -/
def isInductivePredicate (declName : Name) : MetaM Bool := do
match (← getEnv).find? declName with
| some (.inductInfo { type := type, ..}) =>
forallTelescopeReducing type fun _ type => do
match (← whnfD type) with
| .sort u .. => return u == levelZero
| _ => return false
| _ => return false
def isListLevelDefEqAux : List Level → List Level → MetaM Bool
| [], [] => return true
| u::us, v::vs => isLevelDefEqAux u v <&&> isListLevelDefEqAux us vs
| _, _ => return false
def getNumPostponed : MetaM Nat := do
return (← getPostponed).size
def getResetPostponed : MetaM (PersistentArray PostponedEntry) := do
let ps ← getPostponed
setPostponed {}
return ps
/-- Annotate any constant and sort in `e` that satisfies `p` with `pp.universes true` -/
private def exposeRelevantUniverses (e : Expr) (p : Level → Bool) : Expr :=
e.replace fun
| .const _ us => if us.any p then some (e.setPPUniverses true) else none
| .sort u => if p u then some (e.setPPUniverses true) else none
| _ => none
private def mkLeveErrorMessageCore (header : String) (entry : PostponedEntry) : MetaM MessageData := do
match entry.ctx? with
| none =>
return m!"{header}{indentD m!"{entry.lhs} =?= {entry.rhs}"}"
| some ctx =>
withLCtx ctx.lctx ctx.localInstances do
let s := entry.lhs.collectMVars entry.rhs.collectMVars
/- `p u` is true if it contains a universe metavariable in `s` -/
let p (u : Level) := u.any fun | .mvar m => s.contains m | _ => false
let lhs := exposeRelevantUniverses (← instantiateMVars ctx.lhs) p
let rhs := exposeRelevantUniverses (← instantiateMVars ctx.rhs) p
try
addMessageContext m!"{header}{indentD m!"{entry.lhs} =?= {entry.rhs}"}\nwhile trying to unify{indentD m!"{lhs} : {← inferType lhs}"}\nwith{indentD m!"{rhs} : {← inferType rhs}"}"
catch _ =>
addMessageContext m!"{header}{indentD m!"{entry.lhs} =?= {entry.rhs}"}\nwhile trying to unify{indentD lhs}\nwith{indentD rhs}"
def mkLevelStuckErrorMessage (entry : PostponedEntry) : MetaM MessageData := do
mkLeveErrorMessageCore "stuck at solving universe constraint" entry
def mkLevelErrorMessage (entry : PostponedEntry) : MetaM MessageData := do
mkLeveErrorMessageCore "failed to solve universe constraint" entry
private def processPostponedStep (exceptionOnFailure : Bool) : MetaM Bool := do
let ps ← getResetPostponed
for p in ps do
unless (← withReader (fun ctx => { ctx with defEqCtx? := p.ctx? }) <| isLevelDefEqAux p.lhs p.rhs) do
if exceptionOnFailure then
withRef p.ref do
throwError (← mkLevelErrorMessage p)
else
return false
return true
partial def processPostponed (mayPostpone : Bool := true) (exceptionOnFailure := false) : MetaM Bool := do
if (← getNumPostponed) == 0 then
return true
else
let numPostponedBegin ← getNumPostponed
withTraceNode `Meta.isLevelDefEq.postponed
(fun _ => return m!"processing #{numPostponedBegin} postponed is-def-eq level constraints") do
let rec loop : MetaM Bool := do
let numPostponed ← getNumPostponed
if numPostponed == 0 then
return true
else
if !(← processPostponedStep exceptionOnFailure) then
return false
else
let numPostponed' ← getNumPostponed
if numPostponed' == 0 then
return true
else if numPostponed' < numPostponed then
loop
else
trace[Meta.isLevelDefEq.postponed] "no progress solving pending is-def-eq level constraints"
return mayPostpone
loop
/--
`checkpointDefEq x` executes `x` and process all postponed universe level constraints produced by `x`.
We keep the modifications only if `processPostponed` return true and `x` returned `true`.
If `mayPostpone == false`, all new postponed universe level constraints must be solved before returning.
We currently try to postpone universe constraints as much as possible, even when by postponing them we
are not sure whether `x` really succeeded or not.
-/
@[specialize] def checkpointDefEq (x : MetaM Bool) (mayPostpone : Bool := true) : MetaM Bool := do
let s ← saveState
/-
It is not safe to use the `isDefEq` cache between different `isDefEq` calls.
Reason: different configuration settings, and result depends on the state of the `MetavarContext`
We have tried in the past to track when the result was independent of the `MetavarContext` state
but it was not effective. It is more important to cache aggressively inside of a single `isDefEq`
call because some of the heuristics create many similar subproblems.
See issue #1102 for an example that triggers an exponential blowup if we don't use this more
aggresive form of caching.
-/
modifyDefEqCache fun _ => {}
let postponed ← getResetPostponed
try
if (← x) then
if (← processPostponed mayPostpone) then
let newPostponed ← getPostponed
setPostponed (postponed ++ newPostponed)
return true
else
s.restore
return false
else
s.restore
return false
catch ex =>
s.restore
throw ex
/--
Determines whether two universe level expressions are definitionally equal to each other.
-/
def isLevelDefEq (u v : Level) : MetaM Bool :=
checkpointDefEq (mayPostpone := true) <| Meta.isLevelDefEqAux u v
/-- See `isDefEq`. -/
def isExprDefEq (t s : Expr) : MetaM Bool :=
withReader (fun ctx => { ctx with defEqCtx? := some { lhs := t, rhs := s, lctx := ctx.lctx, localInstances := ctx.localInstances } }) do
checkpointDefEq (mayPostpone := true) <| Meta.isExprDefEqAux t s
/--
Determines whether two expressions are definitionally equal to each other.
To control how metavariables are assigned and unified, metavariables and their context have a "depth".
Given a metavariable `?m` and a `MetavarContext` `mctx`, `?m` is not assigned if `?m.depth != mctx.depth`.
The combinator `withNewMCtxDepth x` will bump the depth while executing `x`.
So, `withNewMCtxDepth (isDefEq a b)` is `isDefEq` without any mvar assignment happening
whereas `isDefEq a b` will assign any metavariables of the current depth in `a` and `b` to unify them.
For matching (where only mvars in `b` should be assigned), we create the term inside the `withNewMCtxDepth`.
For an example, see [Lean.Meta.Simp.tryTheoremWithExtraArgs?](https://github.com/leanprover/lean4/blob/master/src/Lean/Meta/Tactic/Simp/Rewrite.lean#L100-L106)
-/
abbrev isDefEq (t s : Expr) : MetaM Bool :=
isExprDefEq t s
def isExprDefEqGuarded (a b : Expr) : MetaM Bool := do
try isExprDefEq a b catch _ => return false
/-- Similar to `isDefEq`, but returns `false` if an exception has been thrown. -/
abbrev isDefEqGuarded (t s : Expr) : MetaM Bool :=
isExprDefEqGuarded t s
def isDefEqNoConstantApprox (t s : Expr) : MetaM Bool :=
approxDefEq <| isDefEq t s
/--
Eta expand the given expression.
Example:
```
etaExpand (mkConst ``Nat.add)
```
produces `fun x y => Nat.add x y`
-/
def etaExpand (e : Expr) : MetaM Expr :=
withDefault do forallTelescopeReducing (← inferType e) fun xs _ => mkLambdaFVars xs (mkAppN e xs)
end Meta
builtin_initialize
registerTraceClass `Meta.isLevelDefEq.postponed
export Meta (MetaM)
end Lean
|
a6f80a966f800e1091f924c420ef2f6a863951bb | 4727251e0cd73359b15b664c3170e5d754078599 | /src/topology/uniform_space/basic.lean | dab3dfc966d1edafcfcb7bae4c5aaa6ede61a4c2 | [
"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 | 74,190 | 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 order.filter.lift
import topology.subset_properties
/-!
# Uniform spaces
Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly
generalize to uniform spaces, e.g.
* uniform continuity (in this file)
* completeness (in `cauchy.lean`)
* extension of uniform continuous functions to complete spaces (in `uniform_embedding.lean`)
* totally bounded sets (in `cauchy.lean`)
* totally bounded complete sets are compact (in `cauchy.lean`)
A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions
which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means
"for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages
of `X`. The two main examples are:
* If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V`
* If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V`
Those examples are generalizations in two different directions of the elementary example where
`X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological
group structure on `ℝ` and its metric space structure.
Each uniform structure on `X` induces a topology on `X` characterized by
> `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (prod.mk x) (𝓤 X)`
where `prod.mk x : X → X × X := (λ y, (x, y))` is the partial evaluation of the product
constructor.
The dictionary with metric spaces includes:
* an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X`
* a ball `ball x r` roughly corresponds to `uniform_space.ball x V := {y | (x, y) ∈ V}`
for some `V ∈ 𝓤 X`, but the later is more general (it includes in
particular both open and closed balls for suitable `V`).
In particular we have:
`is_open_iff_ball_subset {s : set X} : is_open s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s`
The triangle inequality is abstracted to a statement involving the composition of relations in `X`.
First note that the triangle inequality in a metric space is equivalent to
`∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`.
Then, for any `V` and `W` with type `set (X × X)`, the composition `V ○ W : set (X × X)` is
defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`.
In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }`
then the triangle inequality, as reformulated above, says `V ○ W` is contained in
`{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`.
In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`.
Note that this discussion does not depend on any axiom imposed on the uniformity filter,
it is simply captured by the definition of composition.
The uniform space axioms ask the filter `𝓤 X` to satisfy the following:
* every `V ∈ 𝓤 X` contains the diagonal `id_rel = { p | p.1 = p.2 }`. This abstracts the fact
that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that
`x - x` belongs to every neighborhood of zero in the topological group case.
* `V ∈ 𝓤 X → prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x`
in a metric space, and to continuity of negation in the topological group case.
* `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds
to cutting the radius of a ball in half and applying the triangle inequality.
In the topological group case, it comes from continuity of addition at `(0, 0)`.
These three axioms are stated more abstractly in the definition below, in terms of
operations on filters, without directly manipulating entourages.
## Main definitions
* `uniform_space X` is a uniform space structure on a type `X`
* `uniform_continuous f` is a predicate saying a function `f : α → β` between uniform spaces
is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r`
In this file we also define a complete lattice structure on the type `uniform_space X`
of uniform structures on `X`, as well as the pullback (`uniform_space.comap`) of uniform structures
coming from the pullback of filters.
Like distance functions, uniform structures cannot be pushed forward in general.
## Notations
Localized in `uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`,
and `○` for composition of relations, seen as terms with type `set (X × X)`.
## Implementation notes
There is already a theory of relations in `data/rel.lean` where the main definition is
`def rel (α β : Type*) := α → β → Prop`.
The relations used in the current file involve only one type, but this is not the reason why
we don't reuse `data/rel.lean`. We use `set (α × α)`
instead of `rel α α` because we really need sets to use the filter library, and elements
of filters on `α × α` have type `set (α × α)`.
The structure `uniform_space X` bundles a uniform structure on `X`, a topology on `X` and
an assumption saying those are compatible. This may not seem mathematically reasonable at first,
but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance]
below.
## References
The formalization uses the books:
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
But it makes a more systematic use of the filter library.
-/
open set filter classical
open_locale classical topological_space filter
set_option eqn_compiler.zeta true
universes u
/-!
### Relations, seen as `set (α × α)`
-/
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Sort*}
/-- The identity relation, or the graph of the identity function -/
def id_rel {α : Type*} := {p : α × α | p.1 = p.2}
@[simp] theorem mem_id_rel {a b : α} : (a, b) ∈ @id_rel α ↔ a = b := iff.rfl
@[simp] theorem id_rel_subset {s : set (α × α)} : id_rel ⊆ s ↔ ∀ a, (a, a) ∈ s :=
by simp [subset_def]; exact forall_congr (λ a, by simp)
/-- The composition of relations -/
def comp_rel {α : Type u} (r₁ r₂ : set (α×α)) := {p : α × α | ∃z:α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂}
localized "infix ` ○ `:55 := comp_rel" in uniformity
@[simp] theorem mem_comp_rel {r₁ r₂ : set (α×α)}
{x y : α} : (x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := iff.rfl
@[simp] theorem swap_id_rel : prod.swap '' id_rel = @id_rel α :=
set.ext $ assume ⟨a, b⟩, by simp [image_swap_eq_preimage_swap]; exact eq_comm
theorem monotone_comp_rel [preorder β] {f g : β → set (α×α)}
(hf : monotone f) (hg : monotone g) : monotone (λx, (f x) ○ (g x)) :=
assume a b h p ⟨z, h₁, h₂⟩, ⟨z, hf h h₁, hg h h₂⟩
@[mono]
lemma comp_rel_mono {f g h k: set (α×α)} (h₁ : f ⊆ h) (h₂ : g ⊆ k) : f ○ g ⊆ h ○ k :=
λ ⟨x, y⟩ ⟨z, h, h'⟩, ⟨z, h₁ h, h₂ h'⟩
lemma prod_mk_mem_comp_rel {a b c : α} {s t : set (α×α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) :
(a, b) ∈ s ○ t :=
⟨c, h₁, h₂⟩
@[simp] lemma id_comp_rel {r : set (α×α)} : id_rel ○ r = r :=
set.ext $ assume ⟨a, b⟩, by simp
lemma comp_rel_assoc {r s t : set (α×α)} :
(r ○ s) ○ t = r ○ (s ○ t) :=
by ext p; cases p; simp only [mem_comp_rel]; tauto
lemma subset_comp_self {α : Type*} {s : set (α × α)} (h : id_rel ⊆ s) : s ⊆ s ○ s :=
λ ⟨x, y⟩ xy_in, ⟨x, h (by rw mem_id_rel), xy_in⟩
/-- The relation is invariant under swapping factors. -/
def symmetric_rel (V : set (α × α)) : Prop := prod.swap ⁻¹' V = V
/-- The maximal symmetric relation contained in a given relation. -/
def symmetrize_rel (V : set (α × α)) : set (α × α) := V ∩ prod.swap ⁻¹' V
lemma symmetric_symmetrize_rel (V : set (α × α)) : symmetric_rel (symmetrize_rel V) :=
by simp [symmetric_rel, symmetrize_rel, preimage_inter, inter_comm, ← preimage_comp]
lemma symmetrize_rel_subset_self (V : set (α × α)) : symmetrize_rel V ⊆ V :=
sep_subset _ _
@[mono]
lemma symmetrize_mono {V W: set (α × α)} (h : V ⊆ W) : symmetrize_rel V ⊆ symmetrize_rel W :=
inter_subset_inter h $ preimage_mono h
lemma symmetric_rel_inter {U V : set (α × α)} (hU : symmetric_rel U) (hV : symmetric_rel V) :
symmetric_rel (U ∩ V) :=
begin
unfold symmetric_rel at *,
rw [preimage_inter, hU, hV],
end
/-- This core description of a uniform space is outside of the type class hierarchy. It is useful
for constructions of uniform spaces, when the topology is derived from the uniform space. -/
structure uniform_space.core (α : Type u) :=
(uniformity : filter (α × α))
(refl : 𝓟 id_rel ≤ uniformity)
(symm : tendsto prod.swap uniformity uniformity)
(comp : uniformity.lift' (λs, s ○ s) ≤ uniformity)
/-- An alternative constructor for `uniform_space.core`. This version unfolds various
`filter`-related definitions. -/
def uniform_space.core.mk' {α : Type u} (U : filter (α × α))
(refl : ∀ (r ∈ U) x, (x, x) ∈ r)
(symm : ∀ r ∈ U, prod.swap ⁻¹' r ∈ U)
(comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) : uniform_space.core α :=
⟨U, λ r ru, id_rel_subset.2 (refl _ ru), symm,
begin
intros r ru,
rw [mem_lift'_sets],
exact comp _ ru,
apply monotone_comp_rel; exact monotone_id,
end⟩
/-- Defining an `uniform_space.core` from a filter basis satisfying some uniformity-like axioms. -/
def uniform_space.core.mk_of_basis {α : Type u} (B : filter_basis (α × α))
(refl : ∀ (r ∈ B) x, (x, x) ∈ r)
(symm : ∀ r ∈ B, ∃ t ∈ B, t ⊆ prod.swap ⁻¹' r)
(comp : ∀ r ∈ B, ∃ t ∈ B, t ○ t ⊆ r) : uniform_space.core α :=
{ uniformity := B.filter,
refl := B.has_basis.ge_iff.mpr (λ r ru, id_rel_subset.2 $ refl _ ru),
symm := (B.has_basis.tendsto_iff B.has_basis).mpr symm,
comp := (has_basis.le_basis_iff (B.has_basis.lift' (monotone_comp_rel monotone_id monotone_id))
B.has_basis).mpr comp }
/-- A uniform space generates a topological space -/
def uniform_space.core.to_topological_space {α : Type u} (u : uniform_space.core α) :
topological_space α :=
{ is_open := λs, ∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ u.uniformity,
is_open_univ := by simp; intro; exact univ_mem,
is_open_inter :=
assume s t hs ht x ⟨xs, xt⟩, by filter_upwards [hs x xs, ht x xt]; simp {contextual := tt},
is_open_sUnion :=
assume s hs x ⟨t, ts, xt⟩, by filter_upwards [hs t ts x xt] with p ph h using ⟨t, ts, ph h⟩ }
lemma uniform_space.core_eq :
∀{u₁ u₂ : uniform_space.core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂
| ⟨u₁, _, _, _⟩ ⟨u₂, _, _, _⟩ h := by { congr, exact h }
-- the topological structure is embedded in the uniform structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- A uniform space is a generalization of the "uniform" topological aspects of a
metric space. It consists of a filter on `α × α` called the "uniformity", which
satisfies properties analogous to the reflexivity, symmetry, and triangle properties
of a metric.
A metric space has a natural uniformity, and a uniform space has a natural topology.
A topological group also has a natural uniformity, even when it is not metrizable. -/
class uniform_space (α : Type u) extends topological_space α, uniform_space.core α :=
(is_open_uniformity : ∀s, is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ uniformity))
/-- Alternative constructor for `uniform_space α` when a topology is already given. -/
@[pattern] def uniform_space.mk' {α} (t : topological_space α)
(c : uniform_space.core α)
(is_open_uniformity : ∀s:set α, t.is_open s ↔
(∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ c.uniformity)) :
uniform_space α := ⟨c, is_open_uniformity⟩
/-- Construct a `uniform_space` from a `uniform_space.core`. -/
def uniform_space.of_core {α : Type u} (u : uniform_space.core α) : uniform_space α :=
{ to_core := u,
to_topological_space := u.to_topological_space,
is_open_uniformity := assume a, iff.rfl }
/-- Construct a `uniform_space` from a `u : uniform_space.core` and a `topological_space` structure
that is equal to `u.to_topological_space`. -/
def uniform_space.of_core_eq {α : Type u} (u : uniform_space.core α) (t : topological_space α)
(h : t = u.to_topological_space) : uniform_space α :=
{ to_core := u,
to_topological_space := t,
is_open_uniformity := assume a, h.symm ▸ iff.rfl }
lemma uniform_space.to_core_to_topological_space (u : uniform_space α) :
u.to_core.to_topological_space = u.to_topological_space :=
topological_space_eq $ funext $ assume s,
by rw [uniform_space.core.to_topological_space, uniform_space.is_open_uniformity]
@[ext]
lemma uniform_space_eq : ∀{u₁ u₂ : uniform_space α}, u₁.uniformity = u₂.uniformity → u₁ = u₂
| (uniform_space.mk' t₁ u₁ o₁) (uniform_space.mk' t₂ u₂ o₂) h :=
have u₁ = u₂, from uniform_space.core_eq h,
have t₁ = t₂, from topological_space_eq $ funext $ assume s, by rw [o₁, o₂]; simp [this],
by simp [*]
lemma uniform_space.of_core_eq_to_core
(u : uniform_space α) (t : topological_space α) (h : t = u.to_core.to_topological_space) :
uniform_space.of_core_eq u.to_core t h = u :=
uniform_space_eq rfl
/-- Replace topology in a `uniform_space` instance with a propositionally (but possibly not
definitionally) equal one. -/
@[reducible] def uniform_space.replace_topology {α : Type*} [i : topological_space α]
(u : uniform_space α) (h : i = u.to_topological_space) : uniform_space α :=
uniform_space.of_core_eq u.to_core i $ h.trans u.to_core_to_topological_space.symm
lemma uniform_space.replace_topology_eq {α : Type*} [i : topological_space α] (u : uniform_space α)
(h : i = u.to_topological_space) : u.replace_topology h = u :=
u.of_core_eq_to_core _ _
section uniform_space
variables [uniform_space α]
/-- The uniformity is a filter on α × α (inferred from an ambient uniform space
structure on α). -/
def uniformity (α : Type u) [uniform_space α] : filter (α × α) :=
(@uniform_space.to_core α _).uniformity
localized "notation `𝓤` := uniformity" in uniformity
lemma is_open_uniformity {s : set α} :
is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α) :=
uniform_space.is_open_uniformity s
lemma refl_le_uniformity : 𝓟 id_rel ≤ 𝓤 α :=
(@uniform_space.to_core α _).refl
instance uniformity.ne_bot [nonempty α] : ne_bot (𝓤 α) :=
begin
inhabit α,
refine (principal_ne_bot_iff.2 _).mono refl_le_uniformity,
exact ⟨(default, default), rfl⟩
end
lemma refl_mem_uniformity {x : α} {s : set (α × α)} (h : s ∈ 𝓤 α) :
(x, x) ∈ s :=
refl_le_uniformity h rfl
lemma mem_uniformity_of_eq {x y : α} {s : set (α × α)} (h : s ∈ 𝓤 α) (hx : x = y) :
(x, y) ∈ s :=
hx ▸ refl_mem_uniformity h
lemma symm_le_uniformity : map (@prod.swap α α) (𝓤 _) ≤ (𝓤 _) :=
(@uniform_space.to_core α _).symm
lemma comp_le_uniformity : (𝓤 α).lift' (λs:set (α×α), s ○ s) ≤ 𝓤 α :=
(@uniform_space.to_core α _).comp
lemma tendsto_swap_uniformity : tendsto (@prod.swap α α) (𝓤 α) (𝓤 α) :=
symm_le_uniformity
lemma comp_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, t ○ t ⊆ s :=
have s ∈ (𝓤 α).lift' (λt:set (α×α), t ○ t),
from comp_le_uniformity hs,
(mem_lift'_sets $ monotone_comp_rel monotone_id monotone_id).mp this
/-- Relation `λ f g, tendsto (λ x, (f x, g x)) l (𝓤 α)` is transitive. -/
lemma filter.tendsto.uniformity_trans {l : filter β} {f₁ f₂ f₃ : β → α}
(h₁₂ : tendsto (λ x, (f₁ x, f₂ x)) l (𝓤 α)) (h₂₃ : tendsto (λ x, (f₂ x, f₃ x)) l (𝓤 α)) :
tendsto (λ x, (f₁ x, f₃ x)) l (𝓤 α) :=
begin
refine le_trans (le_lift' $ λ s hs, mem_map.2 _) comp_le_uniformity,
filter_upwards [h₁₂ hs, h₂₃ hs] with x hx₁₂ hx₂₃ using ⟨_, hx₁₂, hx₂₃⟩,
end
/-- Relation `λ f g, tendsto (λ x, (f x, g x)) l (𝓤 α)` is symmetric -/
lemma filter.tendsto.uniformity_symm {l : filter β} {f : β → α × α}
(h : tendsto f l (𝓤 α)) :
tendsto (λ x, ((f x).2, (f x).1)) l (𝓤 α) :=
tendsto_swap_uniformity.comp h
/-- Relation `λ f g, tendsto (λ x, (f x, g x)) l (𝓤 α)` is reflexive. -/
lemma tendsto_diag_uniformity (f : β → α) (l : filter β) :
tendsto (λ x, (f x, f x)) l (𝓤 α) :=
assume s hs, mem_map.2 $ univ_mem' $ λ x, refl_mem_uniformity hs
lemma tendsto_const_uniformity {a : α} {f : filter β} : tendsto (λ _, (a, a)) f (𝓤 α) :=
tendsto_diag_uniformity (λ _, a) f
lemma symm_of_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s :=
have preimage prod.swap s ∈ 𝓤 α, from symm_le_uniformity hs,
⟨s ∩ preimage prod.swap s, inter_mem hs this, λ a b ⟨h₁, h₂⟩, ⟨h₂, h₁⟩, inter_subset_left _ _⟩
lemma comp_symm_of_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀{a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s :=
let ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs in
let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ in
⟨t', ht', ht'₁, subset.trans (monotone_comp_rel monotone_id monotone_id ht'₂) ht₂⟩
lemma uniformity_le_symm : 𝓤 α ≤ (@prod.swap α α) <$> 𝓤 α :=
by rw [map_swap_eq_comap_swap];
from map_le_iff_le_comap.1 tendsto_swap_uniformity
lemma uniformity_eq_symm : 𝓤 α = (@prod.swap α α) <$> 𝓤 α :=
le_antisymm uniformity_le_symm symm_le_uniformity
@[simp] lemma comap_swap_uniformity : comap (@prod.swap α α) (𝓤 α) = 𝓤 α :=
(congr_arg _ uniformity_eq_symm).trans $ comap_map prod.swap_injective
lemma symmetrize_mem_uniformity {V : set (α × α)} (h : V ∈ 𝓤 α) : symmetrize_rel V ∈ 𝓤 α :=
begin
apply (𝓤 α).inter_sets h,
rw [← image_swap_eq_preimage_swap, uniformity_eq_symm],
exact image_mem_map h,
end
theorem uniformity_lift_le_swap {g : set (α×α) → filter β} {f : filter β} (hg : monotone g)
(h : (𝓤 α).lift (λs, g (preimage prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f :=
calc (𝓤 α).lift g ≤ (filter.map (@prod.swap α α) $ 𝓤 α).lift g :
lift_mono uniformity_le_symm le_rfl
... ≤ _ :
by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h
lemma uniformity_lift_le_comp {f : set (α×α) → filter β} (h : monotone f) :
(𝓤 α).lift (λs, f (s ○ s)) ≤ (𝓤 α).lift f :=
calc (𝓤 α).lift (λs, f (s ○ s)) =
((𝓤 α).lift' (λs:set (α×α), s ○ s)).lift f :
begin
rw [lift_lift'_assoc],
exact monotone_comp_rel monotone_id monotone_id,
exact h
end
... ≤ (𝓤 α).lift f : lift_mono comp_le_uniformity le_rfl
lemma comp_le_uniformity3 :
(𝓤 α).lift' (λs:set (α×α), s ○ (s ○ s)) ≤ (𝓤 α) :=
calc (𝓤 α).lift' (λd, d ○ (d ○ d)) =
(𝓤 α).lift (λs, (𝓤 α).lift' (λt:set(α×α), s ○ (t ○ t))) :
begin
rw [lift_lift'_same_eq_lift'],
exact (assume x, monotone_comp_rel monotone_const $ monotone_comp_rel monotone_id monotone_id),
exact (assume x, monotone_comp_rel monotone_id monotone_const),
end
... ≤ (𝓤 α).lift (λs, (𝓤 α).lift' (λt:set(α×α), s ○ t)) :
lift_mono' $ assume s hs, @uniformity_lift_le_comp α _ _ (𝓟 ∘ (○) s) $
monotone_principal.comp (monotone_comp_rel monotone_const monotone_id)
... = (𝓤 α).lift' (λs:set(α×α), s ○ s) :
lift_lift'_same_eq_lift'
(assume s, monotone_comp_rel monotone_const monotone_id)
(assume s, monotone_comp_rel monotone_id monotone_const)
... ≤ (𝓤 α) : comp_le_uniformity
/-- See also `comp_open_symm_mem_uniformity_sets`. -/
lemma comp_symm_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, symmetric_rel t ∧ t ○ t ⊆ s :=
begin
obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs,
use [symmetrize_rel w, symmetrize_mem_uniformity w_in, symmetric_symmetrize_rel w],
have : symmetrize_rel w ⊆ w := symmetrize_rel_subset_self w,
calc symmetrize_rel w ○ symmetrize_rel w ⊆ w ○ w : by mono
... ⊆ s : w_sub,
end
lemma subset_comp_self_of_mem_uniformity {s : set (α × α)} (h : s ∈ 𝓤 α) : s ⊆ s ○ s :=
subset_comp_self (refl_le_uniformity h)
lemma comp_comp_symm_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, symmetric_rel t ∧ t ○ t ○ t ⊆ s :=
begin
rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, w_symm, w_sub⟩,
rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩,
use [t, t_in, t_symm],
have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in,
calc
t ○ t ○ t ⊆ w ○ t : by mono
... ⊆ w ○ (t ○ t) : by mono
... ⊆ w ○ w : by mono
... ⊆ s : w_sub,
end
/-!
### Balls in uniform spaces
-/
/-- The ball around `(x : β)` with respect to `(V : set (β × β))`. Intended to be
used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the
notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/
def uniform_space.ball (x : β) (V : set (β × β)) : set β := (prod.mk x) ⁻¹' V
open uniform_space (ball)
lemma uniform_space.mem_ball_self (x : α) {V : set (α × α)} (hV : V ∈ 𝓤 α) :
x ∈ ball x V :=
refl_mem_uniformity hV
/-- The triangle inequality for `uniform_space.ball` -/
lemma mem_ball_comp {V W : set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) :
z ∈ ball x (V ○ W) :=
prod_mk_mem_comp_rel h h'
lemma ball_subset_of_comp_subset {V W : set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) :
ball x W ⊆ ball y V :=
λ z z_in, h' (mem_ball_comp h z_in)
lemma ball_mono {V W : set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W :=
by tauto
lemma ball_inter_left (x : β) (V W : set (β × β)) : ball x (V ∩ W) ⊆ ball x V :=
ball_mono (inter_subset_left V W) x
lemma ball_inter_right (x : β) (V W : set (β × β)) : ball x (V ∩ W) ⊆ ball x W :=
ball_mono (inter_subset_right V W) x
lemma mem_ball_symmetry {V : set (β × β)} (hV : symmetric_rel V) {x y} :
x ∈ ball y V ↔ y ∈ ball x V :=
show (x, y) ∈ prod.swap ⁻¹' V ↔ (x, y) ∈ V, by { unfold symmetric_rel at hV, rw hV }
lemma ball_eq_of_symmetry {V : set (β × β)} (hV : symmetric_rel V) {x} :
ball x V = {y | (y, x) ∈ V} :=
by { ext y, rw mem_ball_symmetry hV, exact iff.rfl }
lemma mem_comp_of_mem_ball {V W : set (β × β)} {x y z : β} (hV : symmetric_rel V)
(hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W :=
begin
rw mem_ball_symmetry hV at hx,
exact ⟨z, hx, hy⟩
end
lemma uniform_space.is_open_ball (x : α) {V : set (α × α)} (hV : is_open V) :
is_open (ball x V) :=
hV.preimage $ continuous_const.prod_mk continuous_id
lemma mem_comp_comp {V W M : set (β × β)} (hW' : symmetric_rel W) {p : β × β} :
p ∈ V ○ M ○ W ↔ ((ball p.1 V ×ˢ ball p.2 W) ∩ M).nonempty :=
begin
cases p with x y,
split,
{ rintros ⟨z, ⟨w, hpw, hwz⟩, hzy⟩,
exact ⟨(w, z), ⟨hpw, by rwa mem_ball_symmetry hW'⟩, hwz⟩, },
{ rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩,
rwa mem_ball_symmetry hW' at z_in,
use [z, w] ; tauto },
end
/-!
### Neighborhoods in uniform spaces
-/
lemma mem_nhds_uniformity_iff_right {x : α} {s : set α} :
s ∈ 𝓝 x ↔ {p : α × α | p.1 = x → p.2 ∈ s} ∈ 𝓤 α :=
begin
refine ⟨_, λ hs, _⟩,
{ simp only [mem_nhds_iff, is_open_uniformity, and_imp, exists_imp_distrib],
intros t ts ht xt,
filter_upwards [ht x xt] using λ y h eq, ts (h eq) },
{ refine mem_nhds_iff.mpr ⟨{x | {p : α × α | p.1 = x → p.2 ∈ s} ∈ 𝓤 α}, _, _, hs⟩,
{ exact λ y hy, refl_mem_uniformity hy rfl },
{ refine is_open_uniformity.mpr (λ y hy, _),
rcases comp_mem_uniformity_sets hy with ⟨t, ht, tr⟩,
filter_upwards [ht], rintro ⟨a, b⟩ hp' rfl,
filter_upwards [ht], rintro ⟨a', b'⟩ hp'' rfl,
exact @tr (a, b') ⟨a', hp', hp''⟩ rfl } }
end
lemma mem_nhds_uniformity_iff_left {x : α} {s : set α} :
s ∈ 𝓝 x ↔ {p : α × α | p.2 = x → p.1 ∈ s} ∈ 𝓤 α :=
by { rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right], refl }
lemma nhds_eq_comap_uniformity_aux {α : Type u} {x : α} {s : set α} {F : filter (α × α)} :
{p : α × α | p.fst = x → p.snd ∈ s} ∈ F ↔ s ∈ comap (prod.mk x) F :=
by rw mem_comap ; from iff.intro
(assume hs, ⟨_, hs, assume x hx, hx rfl⟩)
(assume ⟨t, h, ht⟩, F.sets_of_superset h $
assume ⟨p₁, p₂⟩ hp (h : p₁ = x), ht $ by simp [h.symm, hp])
lemma nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (prod.mk x) :=
by { ext s, rw [mem_nhds_uniformity_iff_right], exact nhds_eq_comap_uniformity_aux }
/-- See also `is_open_iff_open_ball_subset`. -/
lemma is_open_iff_ball_subset {s : set α} : is_open s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, ball x V ⊆ s :=
begin
simp_rw [is_open_iff_mem_nhds, nhds_eq_comap_uniformity],
exact iff.rfl,
end
lemma nhds_basis_uniformity' {p : ι → Prop} {s : ι → set (α × α)} (h : (𝓤 α).has_basis p s)
{x : α} :
(𝓝 x).has_basis p (λ i, ball x (s i)) :=
by { rw [nhds_eq_comap_uniformity], exact h.comap (prod.mk x) }
lemma nhds_basis_uniformity {p : ι → Prop} {s : ι → set (α × α)} (h : (𝓤 α).has_basis p s) {x : α} :
(𝓝 x).has_basis p (λ i, {y | (y, x) ∈ s i}) :=
begin
replace h := h.comap prod.swap,
rw [← map_swap_eq_comap_swap, ← uniformity_eq_symm] at h,
exact nhds_basis_uniformity' h
end
lemma uniform_space.mem_nhds_iff {x : α} {s : set α} : s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, ball x V ⊆ s :=
begin
rw [nhds_eq_comap_uniformity, mem_comap],
exact iff.rfl,
end
lemma uniform_space.ball_mem_nhds (x : α) ⦃V : set (α × α)⦄ (V_in : V ∈ 𝓤 α) : ball x V ∈ 𝓝 x :=
begin
rw uniform_space.mem_nhds_iff,
exact ⟨V, V_in, subset.refl _⟩
end
lemma uniform_space.mem_nhds_iff_symm {x : α} {s : set α} :
s ∈ 𝓝 x ↔ ∃ V ∈ 𝓤 α, symmetric_rel V ∧ ball x V ⊆ s :=
begin
rw uniform_space.mem_nhds_iff,
split,
{ rintros ⟨V, V_in, V_sub⟩,
use [symmetrize_rel V, symmetrize_mem_uniformity V_in, symmetric_symmetrize_rel V],
exact subset.trans (ball_mono (symmetrize_rel_subset_self V) x) V_sub },
{ rintros ⟨V, V_in, V_symm, V_sub⟩,
exact ⟨V, V_in, V_sub⟩ }
end
lemma uniform_space.has_basis_nhds (x : α) :
has_basis (𝓝 x) (λ s : set (α × α), s ∈ 𝓤 α ∧ symmetric_rel s) (λ s, ball x s) :=
⟨λ t, by simp [uniform_space.mem_nhds_iff_symm, and_assoc]⟩
open uniform_space
lemma uniform_space.mem_closure_iff_symm_ball {s : set α} {x} :
x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → symmetric_rel V → (s ∩ ball x V).nonempty :=
by simp [mem_closure_iff_nhds_basis (has_basis_nhds x), set.nonempty]
lemma uniform_space.mem_closure_iff_ball {s : set α} {x} :
x ∈ closure s ↔ ∀ {V}, V ∈ 𝓤 α → (ball x V ∩ s).nonempty :=
by simp [mem_closure_iff_nhds_basis' (nhds_basis_uniformity' (𝓤 α).basis_sets)]
lemma uniform_space.has_basis_nhds_prod (x y : α) :
has_basis (𝓝 (x, y)) (λ s, s ∈ 𝓤 α ∧ symmetric_rel s) $ λ s, ball x s ×ˢ ball y s :=
begin
rw nhds_prod_eq,
apply (has_basis_nhds x).prod' (has_basis_nhds y),
rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩,
exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, symmetric_rel_inter U_symm V_symm⟩,
ball_inter_left x U V, ball_inter_right y U V⟩,
end
lemma nhds_eq_uniformity {x : α} : 𝓝 x = (𝓤 α).lift' (ball x) :=
(nhds_basis_uniformity' (𝓤 α).basis_sets).eq_binfi
lemma mem_nhds_left (x : α) {s : set (α×α)} (h : s ∈ 𝓤 α) :
{y : α | (x, y) ∈ s} ∈ 𝓝 x :=
ball_mem_nhds x h
lemma mem_nhds_right (y : α) {s : set (α×α)} (h : s ∈ 𝓤 α) :
{x : α | (x, y) ∈ s} ∈ 𝓝 y :=
mem_nhds_left _ (symm_le_uniformity h)
lemma tendsto_right_nhds_uniformity {a : α} : tendsto (λa', (a', a)) (𝓝 a) (𝓤 α) :=
assume s, mem_nhds_right a
lemma tendsto_left_nhds_uniformity {a : α} : tendsto (λa', (a, a')) (𝓝 a) (𝓤 α) :=
assume s, mem_nhds_left a
lemma lift_nhds_left {x : α} {g : set α → filter β} (hg : monotone g) :
(𝓝 x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ s}) :=
eq.trans
begin
rw [nhds_eq_uniformity],
exact (filter.lift_assoc $ monotone_principal.comp $ monotone_preimage.comp monotone_preimage )
end
(congr_arg _ $ funext $ assume s, filter.lift_principal hg)
lemma lift_nhds_right {x : α} {g : set α → filter β} (hg : monotone g) :
(𝓝 x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (y, x) ∈ s}) :=
calc (𝓝 x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ s}) : lift_nhds_left hg
... = ((@prod.swap α α) <$> (𝓤 α)).lift (λs:set (α×α), g {y | (x, y) ∈ s}) :
by rw [←uniformity_eq_symm]
... = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ image prod.swap s}) :
map_lift_eq2 $ hg.comp monotone_preimage
... = _ : by simp [image_swap_eq_preimage_swap]
lemma nhds_nhds_eq_uniformity_uniformity_prod {a b : α} :
𝓝 a ×ᶠ 𝓝 b =
(𝓤 α).lift (λs:set (α×α), (𝓤 α).lift' (λt:set (α×α),
{y : α | (y, a) ∈ s} ×ˢ {y : α | (b, y) ∈ t})) :=
begin
rw [prod_def],
show (𝓝 a).lift (λs:set α, (𝓝 b).lift (λt:set α, 𝓟 (s ×ˢ t))) = _,
rw [lift_nhds_right],
apply congr_arg, funext s,
rw [lift_nhds_left],
refl,
exact monotone_principal.comp (monotone_prod monotone_const monotone_id),
exact (monotone_lift' monotone_const $ monotone_lam $
assume x, monotone_prod monotone_id monotone_const)
end
lemma nhds_eq_uniformity_prod {a b : α} :
𝓝 (a, b) =
(𝓤 α).lift' (λs:set (α×α), {y : α | (y, a) ∈ s} ×ˢ {y : α | (b, y) ∈ s}) :=
begin
rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'],
{ intro s, exact monotone_prod monotone_const monotone_preimage },
{ intro t, exact monotone_prod monotone_preimage monotone_const }
end
lemma nhdset_of_mem_uniformity {d : set (α×α)} (s : set (α×α)) (hd : d ∈ 𝓤 α) :
∃(t : set (α×α)), is_open t ∧ s ⊆ t ∧ t ⊆ {p | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} :=
let cl_d := {p:α×α | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} in
have ∀p ∈ s, ∃t ⊆ cl_d, is_open t ∧ p ∈ t, from
assume ⟨x, y⟩ hp, _root_.mem_nhds_iff.mp $
show cl_d ∈ 𝓝 (x, y),
begin
rw [nhds_eq_uniformity_prod, mem_lift'_sets],
exact ⟨d, hd, assume ⟨a, b⟩ ⟨ha, hb⟩, ⟨x, y, ha, hp, hb⟩⟩,
exact monotone_prod monotone_preimage monotone_preimage
end,
have ∃t:(Π(p:α×α) (h:p ∈ s), set (α×α)),
∀p, ∀h:p ∈ s, t p h ⊆ cl_d ∧ is_open (t p h) ∧ p ∈ t p h,
by simp [classical.skolem] at this; simp; assumption,
match this with
| ⟨t, ht⟩ :=
⟨(⋃ p:α×α, ⋃ h : p ∈ s, t p h : set (α×α)),
is_open_Union $ assume (p:α×α), is_open_Union $ assume hp, (ht p hp).right.left,
assume ⟨a, b⟩ hp, begin simp; exact ⟨a, b, hp, (ht (a,b) hp).right.right⟩ end,
Union_subset $ assume p, Union_subset $ assume hp, (ht p hp).left⟩
end
/-- Entourages are neighborhoods of the diagonal. -/
lemma nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α :=
begin
intros V V_in,
rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩,
have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x),
{ rw nhds_prod_eq,
exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) },
apply mem_of_superset this,
rintros ⟨u, v⟩ ⟨u_in, v_in⟩,
exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in)
end
/-- Entourages are neighborhoods of the diagonal. -/
lemma supr_nhds_le_uniformity : (⨆ x : α, 𝓝 (x, x)) ≤ 𝓤 α :=
supr_le nhds_le_uniformity
/-!
### Closure and interior in uniform spaces
-/
lemma closure_eq_uniformity (s : set $ α × α) :
closure s = ⋂ V ∈ {V | V ∈ 𝓤 α ∧ symmetric_rel V}, V ○ s ○ V :=
begin
ext ⟨x, y⟩,
simp_rw [mem_closure_iff_nhds_basis (uniform_space.has_basis_nhds_prod x y),
mem_Inter, mem_set_of_eq],
refine forall₂_congr (λ V, _),
rintros ⟨V_in, V_symm⟩,
simp_rw [mem_comp_comp V_symm, inter_comm, exists_prop],
exact iff.rfl,
end
lemma uniformity_has_basis_closed : has_basis (𝓤 α) (λ V : set (α × α), V ∈ 𝓤 α ∧ is_closed V) id :=
begin
refine filter.has_basis_self.2 (λ t h, _),
rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩,
refine ⟨closure w, mem_of_superset w_in subset_closure, is_closed_closure, _⟩,
refine subset.trans _ r,
rw closure_eq_uniformity,
apply Inter_subset_of_subset,
apply Inter_subset,
exact ⟨w_in, w_symm⟩
end
/-- Closed entourages form a basis of the uniformity filter. -/
lemma uniformity_has_basis_closure : has_basis (𝓤 α) (λ V : set (α × α), V ∈ 𝓤 α) closure :=
⟨begin
intro t,
rw uniformity_has_basis_closed.mem_iff,
split,
{ rintros ⟨r, ⟨r_in, r_closed⟩, r_sub⟩,
use [r, r_in],
convert r_sub,
rw r_closed.closure_eq,
refl },
{ rintros ⟨r, r_in, r_sub⟩,
exact ⟨closure r, ⟨mem_of_superset r_in subset_closure, is_closed_closure⟩, r_sub⟩ }
end⟩
lemma closure_eq_inter_uniformity {t : set (α×α)} :
closure t = (⋂ d ∈ 𝓤 α, d ○ (t ○ d)) :=
set.ext $ assume ⟨a, b⟩,
calc (a, b) ∈ closure t ↔ (𝓝 (a, b) ⊓ 𝓟 t ≠ ⊥) : mem_closure_iff_nhds_ne_bot
... ↔ (((@prod.swap α α) <$> 𝓤 α).lift'
(λ (s : set (α × α)), {x : α | (x, a) ∈ s} ×ˢ {y : α | (b, y) ∈ s}) ⊓ 𝓟 t ≠ ⊥) :
by rw [←uniformity_eq_symm, nhds_eq_uniformity_prod]
... ↔ ((map (@prod.swap α α) (𝓤 α)).lift'
(λ (s : set (α × α)), {x : α | (x, a) ∈ s} ×ˢ {y : α | (b, y) ∈ s}) ⊓ 𝓟 t ≠ ⊥) :
by refl
... ↔ ((𝓤 α).lift'
(λ (s : set (α × α)), {y : α | (a, y) ∈ s} ×ˢ {x : α | (x, b) ∈ s}) ⊓ 𝓟 t ≠ ⊥) :
begin
rw [map_lift'_eq2],
simp [image_swap_eq_preimage_swap, function.comp],
exact monotone_prod monotone_preimage monotone_preimage
end
... ↔ (∀s ∈ 𝓤 α, ({y : α | (a, y) ∈ s} ×ˢ {x : α | (x, b) ∈ s} ∩ t).nonempty) :
begin
rw [lift'_inf_principal_eq, ← ne_bot_iff, lift'_ne_bot_iff],
exact (monotone_prod monotone_preimage monotone_preimage).inter monotone_const
end
... ↔ (∀ s ∈ 𝓤 α, (a, b) ∈ s ○ (t ○ s)) :
forall₂_congr $ λ s hs,
⟨assume ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩, ⟨x, hx, y, hxyt, hy⟩,
assume ⟨x, hx, y, hxyt, hy⟩, ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩⟩
... ↔ _ : by simp
lemma uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, by simp; filter_upwards [hs] using subset_closure)
(calc (𝓤 α).lift' closure ≤ (𝓤 α).lift' (λd, d ○ (d ○ d)) :
lift'_mono' (by intros s hs; rw [closure_eq_inter_uniformity]; exact bInter_subset_of_mem hs)
... ≤ (𝓤 α) : comp_le_uniformity3)
lemma uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior :=
le_antisymm
(le_infi $ assume d, le_infi $ assume hd,
let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $
monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp
(comp_le_uniformity3 hd) in
let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs in
have s ⊆ interior d, from
calc s ⊆ t : hst
... ⊆ interior d : (subset_interior_iff_subset_of_open ht).mpr $
λ x (hx : x ∈ t), let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx in hs_comp ⟨x, h₁, y, h₂, h₃⟩,
have interior d ∈ 𝓤 α, by filter_upwards [hs] using this,
by simp [this])
(assume s hs, ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset)
lemma interior_mem_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) :
interior s ∈ 𝓤 α :=
by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs
lemma mem_uniformity_is_closed {s : set (α×α)} (h : s ∈ 𝓤 α) :
∃t ∈ 𝓤 α, is_closed t ∧ t ⊆ s :=
let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_has_basis_closed.mem_iff.1 h in
⟨t, ht_mem, htc, hts⟩
lemma is_open_iff_open_ball_subset {s : set α} :
is_open s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, is_open V ∧ ball x V ⊆ s :=
begin
rw is_open_iff_ball_subset,
split; intros h x hx,
{ obtain ⟨V, hV, hV'⟩ := h x hx,
exact ⟨interior V, interior_mem_uniformity hV, is_open_interior,
(ball_mono interior_subset x).trans hV'⟩, },
{ obtain ⟨V, hV, -, hV'⟩ := h x hx,
exact ⟨V, hV, hV'⟩, },
end
/-- The uniform neighborhoods of all points of a dense set cover the whole space. -/
lemma dense.bUnion_uniformity_ball {s : set α} {U : set (α × α)} (hs : dense s) (hU : U ∈ 𝓤 α) :
(⋃ x ∈ s, ball x U) = univ :=
begin
refine Union₂_eq_univ_iff.2 (λ y, _),
rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩,
exact ⟨x, hxs, hxy⟩
end
/-!
### Uniformity bases
-/
/-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/
lemma uniformity_has_basis_open : has_basis (𝓤 α) (λ V : set (α × α), V ∈ 𝓤 α ∧ is_open V) id :=
has_basis_self.2 $ λ s hs,
⟨interior s, interior_mem_uniformity hs, is_open_interior, interior_subset⟩
lemma filter.has_basis.mem_uniformity_iff {p : β → Prop} {s : β → set (α×α)}
(h : (𝓤 α).has_basis p s) {t : set (α × α)} :
t ∈ 𝓤 α ↔ ∃ i (hi : p i), ∀ a b, (a, b) ∈ s i → (a, b) ∈ t :=
h.mem_iff.trans $ by simp only [prod.forall, subset_def]
/-- Symmetric entourages form a basis of `𝓤 α` -/
lemma uniform_space.has_basis_symmetric :
(𝓤 α).has_basis (λ s : set (α × α), s ∈ 𝓤 α ∧ symmetric_rel s) id :=
has_basis_self.2 $ λ t t_in, ⟨symmetrize_rel t, symmetrize_mem_uniformity t_in,
symmetric_symmetrize_rel t, symmetrize_rel_subset_self t⟩
/-- Open elements `s : set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis
of `𝓤 α`. -/
lemma uniformity_has_basis_open_symmetric :
has_basis (𝓤 α) (λ V : set (α × α), V ∈ 𝓤 α ∧ is_open V ∧ symmetric_rel V) id :=
begin
simp only [← and_assoc],
refine uniformity_has_basis_open.restrict (λ s hs, ⟨symmetrize_rel s, _⟩),
exact ⟨⟨symmetrize_mem_uniformity hs.1, is_open.inter hs.2 (hs.2.preimage continuous_swap)⟩,
symmetric_symmetrize_rel s, symmetrize_rel_subset_self s⟩
end
lemma comp_open_symm_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, is_open t ∧ symmetric_rel t ∧ t ○ t ⊆ s :=
begin
obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs,
obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_has_basis_open_symmetric.mem_iff.mp ht₁,
exact ⟨u, hu₁, hu₂, hu₃, (comp_rel_mono hu₄ hu₄).trans ht₂⟩,
end
section
variable (α)
lemma uniform_space.has_seq_basis [is_countably_generated $ 𝓤 α] :
∃ V : ℕ → set (α × α), has_antitone_basis (𝓤 α) V ∧ ∀ n, symmetric_rel (V n) :=
let ⟨U, hsym, hbasis⟩ := uniform_space.has_basis_symmetric.exists_antitone_subbasis
in ⟨U, hbasis, λ n, (hsym n).2⟩
end
lemma filter.has_basis.bInter_bUnion_ball {p : ι → Prop} {U : ι → set (α × α)}
(h : has_basis (𝓤 α) p U) (s : set α) :
(⋂ i (hi : p i), ⋃ x ∈ s, ball x (U i)) = closure s :=
begin
ext x,
simp [mem_closure_iff_nhds_basis (nhds_basis_uniformity h), ball]
end
/-! ### Uniform continuity -/
/-- A function `f : α → β` is *uniformly continuous* if `(f x, f y)` tends to the diagonal
as `(x, y)` tends to the diagonal. In other words, if `x` is sufficiently close to `y`, then
`f x` is close to `f y` no matter where `x` and `y` are located in `α`. -/
def uniform_continuous [uniform_space β] (f : α → β) :=
tendsto (λx:α×α, (f x.1, f x.2)) (𝓤 α) (𝓤 β)
/-- A function `f : α → β` is *uniformly continuous* on `s : set α` if `(f x, f y)` tends to
the diagonal as `(x, y)` tends to the diagonal while remaining in `s ×ˢ s`.
In other words, if `x` is sufficiently close to `y`, then `f x` is close to
`f y` no matter where `x` and `y` are located in `s`.-/
def uniform_continuous_on [uniform_space β] (f : α → β) (s : set α) : Prop :=
tendsto (λ x : α × α, (f x.1, f x.2)) (𝓤 α ⊓ principal (s ×ˢ s)) (𝓤 β)
theorem uniform_continuous_def [uniform_space β] {f : α → β} :
uniform_continuous f ↔ ∀ r ∈ 𝓤 β, { x : α × α | (f x.1, f x.2) ∈ r} ∈ 𝓤 α :=
iff.rfl
theorem uniform_continuous_iff_eventually [uniform_space β] {f : α → β} :
uniform_continuous f ↔ ∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r :=
iff.rfl
theorem uniform_continuous_on_univ [uniform_space β] {f : α → β} :
uniform_continuous_on f univ ↔ uniform_continuous f :=
by rw [uniform_continuous_on, uniform_continuous, univ_prod_univ, principal_univ, inf_top_eq]
lemma uniform_continuous_of_const [uniform_space β] {c : α → β} (h : ∀a b, c a = c b) :
uniform_continuous c :=
have (λ (x : α × α), (c (x.fst), c (x.snd))) ⁻¹' id_rel = univ, from
eq_univ_iff_forall.2 $ assume ⟨a, b⟩, h a b,
le_trans (map_le_iff_le_comap.2 $ by simp [comap_principal, this, univ_mem]) refl_le_uniformity
lemma uniform_continuous_id : uniform_continuous (@id α) :=
by simp [uniform_continuous]; exact tendsto_id
lemma uniform_continuous_const [uniform_space β] {b : β} : uniform_continuous (λa:α, b) :=
uniform_continuous_of_const $ λ _ _, rfl
lemma uniform_continuous.comp [uniform_space β] [uniform_space γ] {g : β → γ} {f : α → β}
(hg : uniform_continuous g) (hf : uniform_continuous f) : uniform_continuous (g ∘ f) :=
hg.comp hf
lemma filter.has_basis.uniform_continuous_iff [uniform_space β] {p : γ → Prop} {s : γ → set (α×α)}
(ha : (𝓤 α).has_basis p s) {q : δ → Prop} {t : δ → set (β×β)} (hb : (𝓤 β).has_basis q t)
{f : α → β} :
uniform_continuous f ↔ ∀ i (hi : q i), ∃ j (hj : p j), ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ t i :=
(ha.tendsto_iff hb).trans $ by simp only [prod.forall]
lemma filter.has_basis.uniform_continuous_on_iff [uniform_space β] {p : γ → Prop}
{s : γ → set (α×α)} (ha : (𝓤 α).has_basis p s) {q : δ → Prop} {t : δ → set (β×β)}
(hb : (𝓤 β).has_basis q t) {f : α → β} {S : set α} :
uniform_continuous_on f S ↔
∀ i (hi : q i), ∃ j (hj : p j), ∀ x y ∈ S, (x, y) ∈ s j → (f x, f y) ∈ t i :=
((ha.inf_principal (S ×ˢ S)).tendsto_iff hb).trans $
by simp [prod.forall, set.inter_comm (s _), ball_mem_comm]
end uniform_space
open_locale uniformity
section constructions
instance : partial_order (uniform_space α) :=
{ le := λt s, t.uniformity ≤ s.uniformity,
le_antisymm := assume t s h₁ h₂, uniform_space_eq $ le_antisymm h₁ h₂,
le_refl := assume t, le_rfl,
le_trans := assume a b c h₁ h₂, le_trans h₁ h₂ }
instance : has_Inf (uniform_space α) :=
⟨assume s, uniform_space.of_core
{ uniformity := (⨅u∈s, @uniformity α u),
refl := le_infi $ assume u, le_infi $ assume hu, u.refl,
symm := le_infi $ assume u, le_infi $ assume hu,
le_trans (map_mono $ infi_le_of_le _ $ infi_le _ hu) u.symm,
comp := le_infi $ assume u, le_infi $ assume hu,
le_trans (lift'_mono (infi_le_of_le _ $ infi_le _ hu) $ le_rfl) u.comp }⟩
private lemma Inf_le {tt : set (uniform_space α)} {t : uniform_space α} (h : t ∈ tt) :
Inf tt ≤ t :=
show (⨅u∈tt, @uniformity α u) ≤ t.uniformity,
from infi_le_of_le t $ infi_le _ h
private lemma le_Inf {tt : set (uniform_space α)} {t : uniform_space α} (h : ∀t'∈tt, t ≤ t') :
t ≤ Inf tt :=
show t.uniformity ≤ (⨅u∈tt, @uniformity α u),
from le_infi $ assume t', le_infi $ assume ht', h t' ht'
instance : has_top (uniform_space α) :=
⟨uniform_space.of_core { uniformity := ⊤, refl := le_top, symm := le_top, comp := le_top }⟩
instance : has_bot (uniform_space α) :=
⟨{ to_topological_space := ⊥,
uniformity := 𝓟 id_rel,
refl := le_rfl,
symm := by simp [tendsto]; apply subset.refl,
comp :=
begin
rw [lift'_principal], {simp},
exact monotone_comp_rel monotone_id monotone_id
end,
is_open_uniformity :=
assume s, by simp [is_open_fold, subset_def, id_rel] {contextual := tt } } ⟩
instance : complete_lattice (uniform_space α) :=
{ sup := λa b, Inf {x | a ≤ x ∧ b ≤ x},
le_sup_left := λ a b, le_Inf (λ _ ⟨h, _⟩, h),
le_sup_right := λ a b, le_Inf (λ _ ⟨_, h⟩, h),
sup_le := λ a b c h₁ h₂, Inf_le ⟨h₁, h₂⟩,
inf := λ a b, Inf {a, b},
le_inf := λ a b c h₁ h₂, le_Inf (λ u h,
by { cases h, exact h.symm ▸ h₁, exact (mem_singleton_iff.1 h).symm ▸ h₂ }),
inf_le_left := λ a b, Inf_le (by simp),
inf_le_right := λ a b, Inf_le (by simp),
top := ⊤,
le_top := λ a, show a.uniformity ≤ ⊤, from le_top,
bot := ⊥,
bot_le := λ u, u.refl,
Sup := λ tt, Inf {t | ∀ t' ∈ tt, t' ≤ t},
le_Sup := λ s u h, le_Inf (λ u' h', h' u h),
Sup_le := λ s u h, Inf_le h,
Inf := Inf,
le_Inf := λ s a hs, le_Inf hs,
Inf_le := λ s a ha, Inf_le ha,
..uniform_space.partial_order }
lemma infi_uniformity {ι : Sort*} {u : ι → uniform_space α} :
(infi u).uniformity = (⨅i, (u i).uniformity) :=
show (⨅a (h : ∃i:ι, u i = a), a.uniformity) = _, from
le_antisymm
(le_infi $ assume i, infi_le_of_le (u i) $ infi_le _ ⟨i, rfl⟩)
(le_infi $ assume a, le_infi $ assume ⟨i, (ha : u i = a)⟩, ha ▸ infi_le _ _)
lemma infi_uniformity' {ι : Sort*} {u : ι → uniform_space α} :
@uniformity α (infi u) = (⨅i, @uniformity α (u i)) :=
infi_uniformity
lemma inf_uniformity {u v : uniform_space α} :
(u ⊓ v).uniformity = u.uniformity ⊓ v.uniformity :=
have (u ⊓ v) = (⨅i (h : i = u ∨ i = v), i), by simp [infi_or, infi_inf_eq],
calc (u ⊓ v).uniformity = ((⨅i (h : i = u ∨ i = v), i) : uniform_space α).uniformity : by rw [this]
... = _ : by simp [infi_uniformity, infi_or, infi_inf_eq]
lemma inf_uniformity' {u v : uniform_space α} :
@uniformity α (u ⊓ v) = @uniformity α u ⊓ @uniformity α v :=
inf_uniformity
instance inhabited_uniform_space : inhabited (uniform_space α) := ⟨⊥⟩
instance inhabited_uniform_space_core : inhabited (uniform_space.core α) :=
⟨@uniform_space.to_core _ default⟩
/-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f`
is the inverse image in the filter sense of the induced function `α × α → β × β`. -/
def uniform_space.comap (f : α → β) (u : uniform_space β) : uniform_space α :=
{ uniformity := u.uniformity.comap (λp:α×α, (f p.1, f p.2)),
to_topological_space := u.to_topological_space.induced f,
refl := le_trans (by simp; exact assume ⟨a, b⟩ (h : a = b), h ▸ rfl) (comap_mono u.refl),
symm := by simp [tendsto_comap_iff, prod.swap, (∘)];
exact tendsto_swap_uniformity.comp tendsto_comap,
comp := le_trans
begin
rw [comap_lift'_eq, comap_lift'_eq2],
exact (lift'_mono' $ assume s hs ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩, ⟨f x, h₁, h₂⟩),
repeat { exact monotone_comp_rel monotone_id monotone_id }
end
(comap_mono u.comp),
is_open_uniformity := λ s, begin
change (@is_open α (u.to_topological_space.induced f) s ↔ _),
simp [is_open_iff_nhds, nhds_induced, mem_nhds_uniformity_iff_right, filter.comap, and_comm],
refine ball_congr (λ x hx, ⟨_, _⟩),
{ rintro ⟨t, hts, ht⟩, refine ⟨_, ht, _⟩,
rintro ⟨x₁, x₂⟩ h rfl, exact hts (h rfl) },
{ rintro ⟨t, ht, hts⟩,
exact ⟨{y | (f x, y) ∈ t}, λ y hy, @hts (x, y) hy rfl,
mem_nhds_uniformity_iff_right.1 $ mem_nhds_left _ ht⟩ }
end }
lemma uniformity_comap [uniform_space α] [uniform_space β] {f : α → β}
(h : ‹uniform_space α› = uniform_space.comap f ‹uniform_space β›) :
𝓤 α = comap (prod.map f f) (𝓤 β) :=
by { rw h, refl }
lemma uniform_space_comap_id {α : Type*} : uniform_space.comap (id : α → α) = id :=
by ext u ; dsimp [uniform_space.comap] ; rw [prod.id_prod, filter.comap_id]
lemma uniform_space.comap_comap {α β γ} [uγ : uniform_space γ] {f : α → β} {g : β → γ} :
uniform_space.comap (g ∘ f) uγ = uniform_space.comap f (uniform_space.comap g uγ) :=
by ext ; dsimp [uniform_space.comap] ; rw filter.comap_comap
lemma uniform_continuous_iff {α β} [uα : uniform_space α] [uβ : uniform_space β] {f : α → β} :
uniform_continuous f ↔ uα ≤ uβ.comap f :=
filter.map_le_iff_le_comap
lemma le_iff_uniform_continuous_id {u v : uniform_space α} :
u ≤ v ↔ @uniform_continuous _ _ u v id :=
by rw [uniform_continuous_iff, uniform_space_comap_id, id]
lemma uniform_continuous_comap {f : α → β} [u : uniform_space β] :
@uniform_continuous α β (uniform_space.comap f u) u f :=
tendsto_comap
theorem to_topological_space_comap {f : α → β} {u : uniform_space β} :
@uniform_space.to_topological_space _ (uniform_space.comap f u) =
topological_space.induced f (@uniform_space.to_topological_space β u) := rfl
lemma uniform_continuous_comap' {f : γ → β} {g : α → γ} [v : uniform_space β] [u : uniform_space α]
(h : uniform_continuous (f ∘ g)) : @uniform_continuous α γ u (uniform_space.comap f v) g :=
tendsto_comap_iff.2 h
lemma to_nhds_mono {u₁ u₂ : uniform_space α} (h : u₁ ≤ u₂) (a : α) :
@nhds _ (@uniform_space.to_topological_space _ u₁) a ≤
@nhds _ (@uniform_space.to_topological_space _ u₂) a :=
by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact (lift'_mono h le_rfl)
lemma to_topological_space_mono {u₁ u₂ : uniform_space α} (h : u₁ ≤ u₂) :
@uniform_space.to_topological_space _ u₁ ≤ @uniform_space.to_topological_space _ u₂ :=
le_of_nhds_le_nhds $ to_nhds_mono h
lemma uniform_continuous.continuous [uniform_space α] [uniform_space β] {f : α → β}
(hf : uniform_continuous f) : continuous f :=
continuous_iff_le_induced.mpr $ to_topological_space_mono $ uniform_continuous_iff.1 hf
lemma to_topological_space_bot : @uniform_space.to_topological_space α ⊥ = ⊥ := rfl
lemma to_topological_space_top : @uniform_space.to_topological_space α ⊤ = ⊤ :=
top_unique $ assume s hs, s.eq_empty_or_nonempty.elim
(assume : s = ∅, this.symm ▸ @is_open_empty _ ⊤)
(assume ⟨x, hx⟩,
have s = univ, from top_unique $ assume y hy, hs x hx (x, y) rfl,
this.symm ▸ @is_open_univ _ ⊤)
lemma to_topological_space_infi {ι : Sort*} {u : ι → uniform_space α} :
(infi u).to_topological_space = ⨅i, (u i).to_topological_space :=
begin
casesI is_empty_or_nonempty ι,
{ rw [infi_of_empty, infi_of_empty, to_topological_space_top] },
{ refine (eq_of_nhds_eq_nhds $ assume a, _),
rw [nhds_infi, nhds_eq_uniformity],
change (infi u).uniformity.lift' (preimage $ prod.mk a) = _,
rw [infi_uniformity, lift'_infi],
{ simp only [nhds_eq_uniformity], refl },
{ exact assume a b, rfl } },
end
lemma to_topological_space_Inf {s : set (uniform_space α)} :
(Inf s).to_topological_space = (⨅i∈s, @uniform_space.to_topological_space α i) :=
begin
rw [Inf_eq_infi],
simp only [← to_topological_space_infi],
end
lemma to_topological_space_inf {u v : uniform_space α} :
(u ⊓ v).to_topological_space = u.to_topological_space ⊓ v.to_topological_space :=
by rw [to_topological_space_Inf, infi_pair]
/-- A uniform space with the discrete uniformity has the discrete topology. -/
lemma discrete_topology_of_discrete_uniformity [hα : uniform_space α]
(h : uniformity α = 𝓟 id_rel) :
discrete_topology α :=
⟨(uniform_space_eq h.symm : ⊥ = hα) ▸ rfl⟩
instance : uniform_space empty := ⊥
instance : uniform_space punit := ⊥
instance : uniform_space bool := ⊥
instance : uniform_space ℕ := ⊥
instance : uniform_space ℤ := ⊥
instance {p : α → Prop} [t : uniform_space α] : uniform_space (subtype p) :=
uniform_space.comap subtype.val t
lemma uniformity_subtype {p : α → Prop} [t : uniform_space α] :
𝓤 (subtype p) = comap (λq:subtype p × subtype p, (q.1.1, q.2.1)) (𝓤 α) :=
rfl
lemma uniform_continuous_subtype_val {p : α → Prop} [uniform_space α] :
uniform_continuous (subtype.val : {a : α // p a} → α) :=
uniform_continuous_comap
lemma uniform_continuous_subtype_mk {p : α → Prop} [uniform_space α] [uniform_space β]
{f : β → α} (hf : uniform_continuous f) (h : ∀x, p (f x)) :
uniform_continuous (λx, ⟨f x, h x⟩ : β → subtype p) :=
uniform_continuous_comap' hf
lemma uniform_continuous_on_iff_restrict [uniform_space α] [uniform_space β] {f : α → β}
{s : set α} :
uniform_continuous_on f s ↔ uniform_continuous (s.restrict f) :=
begin
unfold uniform_continuous_on set.restrict uniform_continuous tendsto,
rw [show (λ x : s × s, (f x.1, f x.2)) = prod.map f f ∘ coe, by ext x; cases x; refl,
uniformity_comap rfl,
show prod.map subtype.val subtype.val = (coe : s × s → α × α), by ext x; cases x; refl],
conv in (map _ (comap _ _)) { rw ← filter.map_map },
rw subtype_coe_map_comap_prod, refl,
end
lemma tendsto_of_uniform_continuous_subtype
[uniform_space α] [uniform_space β] {f : α → β} {s : set α} {a : α}
(hf : uniform_continuous (λx:s, f x.val)) (ha : s ∈ 𝓝 a) :
tendsto f (𝓝 a) (𝓝 (f a)) :=
by rw [(@map_nhds_subtype_coe_eq α _ s a (mem_of_mem_nhds ha) ha).symm]; exact
tendsto_map' (continuous_iff_continuous_at.mp hf.continuous _)
lemma uniform_continuous_on.continuous_on [uniform_space α] [uniform_space β] {f : α → β}
{s : set α} (h : uniform_continuous_on f s) : continuous_on f s :=
begin
rw uniform_continuous_on_iff_restrict at h,
rw continuous_on_iff_continuous_restrict,
exact h.continuous
end
@[to_additive]
instance [uniform_space α] : uniform_space (αᵐᵒᵖ) :=
uniform_space.comap mul_opposite.unop ‹_›
@[to_additive]
lemma uniformity_mul_opposite [uniform_space α] :
𝓤 (αᵐᵒᵖ) = comap (λ q : αᵐᵒᵖ × αᵐᵒᵖ, (q.1.unop, q.2.unop)) (𝓤 α) :=
rfl
@[simp, to_additive] lemma comap_uniformity_mul_opposite [uniform_space α] :
comap (λ p : α × α, (mul_opposite.op p.1, mul_opposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α :=
by simpa [uniformity_mul_opposite, comap_comap, (∘)] using comap_id
namespace mul_opposite
@[to_additive]
lemma uniform_continuous_unop [uniform_space α] : uniform_continuous (unop : αᵐᵒᵖ → α) :=
uniform_continuous_comap
@[to_additive]
lemma uniform_continuous_op [uniform_space α] : uniform_continuous (op : α → αᵐᵒᵖ) :=
uniform_continuous_comap' uniform_continuous_id
end mul_opposite
section prod
/- a similar product space is possible on the function space (uniformity of pointwise convergence),
but we want to have the uniformity of uniform convergence on function spaces -/
instance [u₁ : uniform_space α] [u₂ : uniform_space β] : uniform_space (α × β) :=
uniform_space.of_core_eq
(u₁.comap prod.fst ⊓ u₂.comap prod.snd).to_core
prod.topological_space
(calc prod.topological_space = (u₁.comap prod.fst ⊓ u₂.comap prod.snd).to_topological_space :
by rw [to_topological_space_inf, to_topological_space_comap, to_topological_space_comap]; refl
... = _ : by rw [uniform_space.to_core_to_topological_space])
theorem uniformity_prod [uniform_space α] [uniform_space β] : 𝓤 (α × β) =
(𝓤 α).comap (λp:(α × β) × α × β, (p.1.1, p.2.1)) ⊓
(𝓤 β).comap (λp:(α × β) × α × β, (p.1.2, p.2.2)) :=
inf_uniformity
lemma uniformity_prod_eq_prod [uniform_space α] [uniform_space β] :
𝓤 (α×β) =
map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ᶠ 𝓤 β) :=
have map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) =
comap (λp:(α×β)×(α×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))),
from funext $ assume f, map_eq_comap_of_inverse
(funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl) (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl),
by rw [this, uniformity_prod, filter.prod, comap_inf, comap_comap, comap_comap]
lemma mem_map_iff_exists_image' {α : Type*} {β : Type*} {f : filter α} {m : α → β} {t : set β} :
t ∈ (map m f).sets ↔ (∃s∈f, m '' s ⊆ t) :=
mem_map_iff_exists_image
lemma mem_uniformity_of_uniform_continuous_invariant [uniform_space α] {s:set (α×α)} {f : α → α → α}
(hf : uniform_continuous (λp:α×α, f p.1 p.2)) (hs : s ∈ 𝓤 α) :
∃u∈𝓤 α, ∀a b c, (a, b) ∈ u → (f a c, f b c) ∈ s :=
begin
rw [uniform_continuous, uniformity_prod_eq_prod, tendsto_map'_iff, (∘)] at hf,
rcases mem_map_iff_exists_image'.1 (hf hs) with ⟨t, ht, hts⟩, clear hf,
rcases mem_prod_iff.1 ht with ⟨u, hu, v, hv, huvt⟩, clear ht,
refine ⟨u, hu, assume a b c hab, hts $ (mem_image _ _ _).2 ⟨⟨⟨a, b⟩, ⟨c, c⟩⟩, huvt ⟨_, _⟩, _⟩⟩,
exact hab,
exact refl_mem_uniformity hv,
refl
end
lemma mem_uniform_prod [t₁ : uniform_space α] [t₂ : uniform_space β] {a : set (α × α)}
{b : set (β × β)} (ha : a ∈ 𝓤 α) (hb : b ∈ 𝓤 β) :
{p:(α×β)×(α×β) | (p.1.1, p.2.1) ∈ a ∧ (p.1.2, p.2.2) ∈ b } ∈ (@uniformity (α × β) _) :=
by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap ha) (preimage_mem_comap hb)
lemma tendsto_prod_uniformity_fst [uniform_space α] [uniform_space β] :
tendsto (λp:(α×β)×(α×β), (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) :=
le_trans (map_mono (@inf_le_left (uniform_space (α×β)) _ _ _)) map_comap_le
lemma tendsto_prod_uniformity_snd [uniform_space α] [uniform_space β] :
tendsto (λp:(α×β)×(α×β), (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) :=
le_trans (map_mono (@inf_le_right (uniform_space (α×β)) _ _ _)) map_comap_le
lemma uniform_continuous_fst [uniform_space α] [uniform_space β] :
uniform_continuous (λp:α×β, p.1) :=
tendsto_prod_uniformity_fst
lemma uniform_continuous_snd [uniform_space α] [uniform_space β] :
uniform_continuous (λp:α×β, p.2) :=
tendsto_prod_uniformity_snd
variables [uniform_space α] [uniform_space β] [uniform_space γ]
lemma uniform_continuous.prod_mk
{f₁ : α → β} {f₂ : α → γ} (h₁ : uniform_continuous f₁) (h₂ : uniform_continuous f₂) :
uniform_continuous (λa, (f₁ a, f₂ a)) :=
by rw [uniform_continuous, uniformity_prod]; exact
tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
lemma uniform_continuous.prod_mk_left {f : α × β → γ} (h : uniform_continuous f) (b) :
uniform_continuous (λ a, f (a,b)) :=
h.comp (uniform_continuous_id.prod_mk uniform_continuous_const)
lemma uniform_continuous.prod_mk_right {f : α × β → γ} (h : uniform_continuous f) (a) :
uniform_continuous (λ b, f (a,b)) :=
h.comp (uniform_continuous_const.prod_mk uniform_continuous_id)
lemma uniform_continuous.prod_map [uniform_space δ] {f : α → γ} {g : β → δ}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (prod.map f g) :=
(hf.comp uniform_continuous_fst).prod_mk (hg.comp uniform_continuous_snd)
lemma to_topological_space_prod {α} {β} [u : uniform_space α] [v : uniform_space β] :
@uniform_space.to_topological_space (α × β) prod.uniform_space =
@prod.topological_space α β u.to_topological_space v.to_topological_space := rfl
end prod
section
open uniform_space function
variables {δ' : Type*} [uniform_space α] [uniform_space β] [uniform_space γ] [uniform_space δ]
[uniform_space δ']
local notation f `∘₂` g := function.bicompr f g
/-- Uniform continuity for functions of two variables. -/
def uniform_continuous₂ (f : α → β → γ) := uniform_continuous (uncurry f)
lemma uniform_continuous₂_def (f : α → β → γ) :
uniform_continuous₂ f ↔ uniform_continuous (uncurry f) := iff.rfl
lemma uniform_continuous₂.uniform_continuous {f : α → β → γ} (h : uniform_continuous₂ f) :
uniform_continuous (uncurry f) := h
lemma uniform_continuous₂_curry (f : α × β → γ) :
uniform_continuous₂ (function.curry f) ↔ uniform_continuous f :=
by rw [uniform_continuous₂, uncurry_curry]
lemma uniform_continuous₂.comp {f : α → β → γ} {g : γ → δ}
(hg : uniform_continuous g) (hf : uniform_continuous₂ f) :
uniform_continuous₂ (g ∘₂ f) :=
hg.comp hf
lemma uniform_continuous₂.bicompl {f : α → β → γ} {ga : δ → α} {gb : δ' → β}
(hf : uniform_continuous₂ f) (hga : uniform_continuous ga) (hgb : uniform_continuous gb) :
uniform_continuous₂ (bicompl f ga gb) :=
hf.uniform_continuous.comp (hga.prod_map hgb)
end
lemma to_topological_space_subtype [u : uniform_space α] {p : α → Prop} :
@uniform_space.to_topological_space (subtype p) subtype.uniform_space =
@subtype.topological_space α p u.to_topological_space := rfl
section sum
variables [uniform_space α] [uniform_space β]
open sum
/-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained
by taking independently an entourage of the diagonal in the first part, and an entourage of
the diagonal in the second part. -/
def uniform_space.core.sum : uniform_space.core (α ⊕ β) :=
uniform_space.core.mk'
(map (λ p : α × α, (inl p.1, inl p.2)) (𝓤 α) ⊔ map (λ p : β × β, (inr p.1, inr p.2)) (𝓤 β))
(λ r ⟨H₁, H₂⟩ x, by cases x; [apply refl_mem_uniformity H₁, apply refl_mem_uniformity H₂])
(λ r ⟨H₁, H₂⟩, ⟨symm_le_uniformity H₁, symm_le_uniformity H₂⟩)
(λ r ⟨Hrα, Hrβ⟩, begin
rcases comp_mem_uniformity_sets Hrα with ⟨tα, htα, Htα⟩,
rcases comp_mem_uniformity_sets Hrβ with ⟨tβ, htβ, Htβ⟩,
refine ⟨_,
⟨mem_map_iff_exists_image.2 ⟨tα, htα, subset_union_left _ _⟩,
mem_map_iff_exists_image.2 ⟨tβ, htβ, subset_union_right _ _⟩⟩, _⟩,
rintros ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩,
⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩,
{ have A : (a, c) ∈ tα ○ tα := ⟨b, hab, hbc⟩,
exact Htα A },
{ have A : (a, c) ∈ tβ ○ tβ := ⟨b, hab, hbc⟩,
exact Htβ A }
end)
/-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage
of the diagonal. -/
lemma union_mem_uniformity_sum
{a : set (α × α)} (ha : a ∈ 𝓤 α) {b : set (β × β)} (hb : b ∈ 𝓤 β) :
((λ p : (α × α), (inl p.1, inl p.2)) '' a ∪ (λ p : (β × β), (inr p.1, inr p.2)) '' b) ∈
(@uniform_space.core.sum α β _ _).uniformity :=
⟨mem_map_iff_exists_image.2 ⟨_, ha, subset_union_left _ _⟩,
mem_map_iff_exists_image.2 ⟨_, hb, subset_union_right _ _⟩⟩
/- To prove that the topology defined by the uniform structure on the disjoint union coincides with
the disjoint union topology, we need two lemmas saying that open sets can be characterized by
the uniform structure -/
lemma uniformity_sum_of_open_aux {s : set (α ⊕ β)} (hs : is_open s) {x : α ⊕ β} (xs : x ∈ s) :
{ p : ((α ⊕ β) × (α ⊕ β)) | p.1 = x → p.2 ∈ s } ∈ (@uniform_space.core.sum α β _ _).uniformity :=
begin
cases x,
{ refine mem_of_superset
(union_mem_uniformity_sum (mem_nhds_uniformity_iff_right.1 (is_open.mem_nhds hs.1 xs))
univ_mem)
(union_subset _ _);
rintro _ ⟨⟨_, b⟩, h, ⟨⟩⟩ ⟨⟩,
exact h rfl },
{ refine mem_of_superset
(union_mem_uniformity_sum univ_mem (mem_nhds_uniformity_iff_right.1
(is_open.mem_nhds hs.2 xs)))
(union_subset _ _);
rintro _ ⟨⟨a, _⟩, h, ⟨⟩⟩ ⟨⟩,
exact h rfl },
end
lemma open_of_uniformity_sum_aux {s : set (α ⊕ β)}
(hs : ∀x ∈ s, { p : ((α ⊕ β) × (α ⊕ β)) | p.1 = x → p.2 ∈ s } ∈
(@uniform_space.core.sum α β _ _).uniformity) :
is_open s :=
begin
split,
{ refine (@is_open_iff_mem_nhds α _ _).2 (λ a ha, mem_nhds_uniformity_iff_right.2 _),
rcases mem_map_iff_exists_image.1 (hs _ ha).1 with ⟨t, ht, st⟩,
refine mem_of_superset ht _,
rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl },
{ refine (@is_open_iff_mem_nhds β _ _).2 (λ b hb, mem_nhds_uniformity_iff_right.2 _),
rcases mem_map_iff_exists_image.1 (hs _ hb).2 with ⟨t, ht, st⟩,
refine mem_of_superset ht _,
rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl }
end
/- We can now define the uniform structure on the disjoint union -/
instance sum.uniform_space : uniform_space (α ⊕ β) :=
{ to_core := uniform_space.core.sum,
is_open_uniformity := λ s, ⟨uniformity_sum_of_open_aux, open_of_uniformity_sum_aux⟩ }
lemma sum.uniformity : 𝓤 (α ⊕ β) =
map (λ p : α × α, (inl p.1, inl p.2)) (𝓤 α) ⊔
map (λ p : β × β, (inr p.1, inr p.2)) (𝓤 β) := rfl
end sum
end constructions
-- For a version of the Lebesgue number lemma assuming only a sequentially compact space,
-- see topology/sequences.lean
/-- Let `c : ι → set α` be an open cover of a compact set `s`. Then there exists an entourage
`n` such that for each `x ∈ s` its `n`-neighborhood is contained in some `c i`. -/
lemma lebesgue_number_lemma {α : Type u} [uniform_space α] {s : set α} {ι} {c : ι → set α}
(hs : is_compact s) (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ n ∈ 𝓤 α, ∀ x ∈ s, ∃ i, {y | (x, y) ∈ n} ⊆ c i :=
begin
let u := λ n, {x | ∃ i (m ∈ 𝓤 α), {y | (x, y) ∈ m ○ n} ⊆ c i},
have hu₁ : ∀ n ∈ 𝓤 α, is_open (u n),
{ refine λ n hn, is_open_uniformity.2 _,
rintro x ⟨i, m, hm, h⟩,
rcases comp_mem_uniformity_sets hm with ⟨m', hm', mm'⟩,
apply (𝓤 α).sets_of_superset hm',
rintros ⟨x, y⟩ hp rfl,
refine ⟨i, m', hm', λ z hz, h (monotone_comp_rel monotone_id monotone_const mm' _)⟩,
dsimp at hz ⊢, rw comp_rel_assoc,
exact ⟨y, hp, hz⟩ },
have hu₂ : s ⊆ ⋃ n ∈ 𝓤 α, u n,
{ intros x hx,
rcases mem_Union.1 (hc₂ hx) with ⟨i, h⟩,
rcases comp_mem_uniformity_sets (is_open_uniformity.1 (hc₁ i) x h) with ⟨m', hm', mm'⟩,
exact mem_bUnion hm' ⟨i, _, hm', λ y hy, mm' hy rfl⟩ },
rcases hs.elim_finite_subcover_image hu₁ hu₂ with ⟨b, bu, b_fin, b_cover⟩,
refine ⟨_, (bInter_mem b_fin).2 bu, λ x hx, _⟩,
rcases mem_Union₂.1 (b_cover hx) with ⟨n, bn, i, m, hm, h⟩,
refine ⟨i, λ y hy, h _⟩,
exact prod_mk_mem_comp_rel (refl_mem_uniformity hm) (bInter_subset_of_mem bn hy)
end
/-- Let `c : set (set α)` be an open cover of a compact set `s`. Then there exists an entourage
`n` such that for each `x ∈ s` its `n`-neighborhood is contained in some `t ∈ c`. -/
lemma lebesgue_number_lemma_sUnion {α : Type u} [uniform_space α] {s : set α} {c : set (set α)}
(hs : is_compact s) (hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
∃ n ∈ 𝓤 α, ∀ x ∈ s, ∃ t ∈ c, ∀ y, (x, y) ∈ n → y ∈ t :=
by rw sUnion_eq_Union at hc₂;
simpa using lebesgue_number_lemma hs (by simpa) hc₂
/-- A useful consequence of the Lebesgue number lemma: given any compact set `K` contained in an
open set `U`, we can find an (open) entourage `V` such that the ball of size `V` about any point of
`K` is contained in `U`. -/
lemma lebesgue_number_of_compact_open [uniform_space α]
{K U : set α} (hK : is_compact K) (hU : is_open U) (hKU : K ⊆ U) :
∃ V ∈ 𝓤 α, is_open V ∧ ∀ x ∈ K, uniform_space.ball x V ⊆ U :=
begin
let W : K → set (α × α) := λ k, classical.some $ is_open_iff_open_ball_subset.mp hU k.1 $ hKU k.2,
have hW : ∀ k, W k ∈ 𝓤 α ∧ is_open (W k) ∧ uniform_space.ball k.1 (W k) ⊆ U,
{ intros k,
obtain ⟨h₁, h₂, h₃⟩ := classical.some_spec (is_open_iff_open_ball_subset.mp hU k.1 (hKU k.2)),
exact ⟨h₁, h₂, h₃⟩, },
let c : K → set α := λ k, uniform_space.ball k.1 (W k),
have hc₁ : ∀ k, is_open (c k), { exact λ k, uniform_space.is_open_ball k.1 (hW k).2.1, },
have hc₂ : K ⊆ ⋃ i, c i,
{ intros k hk,
simp only [mem_Union, set_coe.exists],
exact ⟨k, hk, uniform_space.mem_ball_self k (hW ⟨k, hk⟩).1⟩, },
have hc₃ : ∀ k, c k ⊆ U, { exact λ k, (hW k).2.2, },
obtain ⟨V, hV, hV'⟩ := lebesgue_number_lemma hK hc₁ hc₂,
refine ⟨interior V, interior_mem_uniformity hV, is_open_interior, _⟩,
intros k hk,
obtain ⟨k', hk'⟩ := hV' k hk,
exact ((ball_mono interior_subset k).trans hk').trans (hc₃ k'),
end
/-!
### Expressing continuity properties in uniform spaces
We reformulate the various continuity properties of functions taking values in a uniform space
in terms of the uniformity in the target. Since the same lemmas (essentially with the same names)
also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or
the edistance in the target), we put them in a namespace `uniform` here.
In the metric and emetric space setting, there are also similar lemmas where one assumes that
both the source and the target are metric spaces, reformulating things in terms of the distance
on both sides. These lemmas are generally written without primes, and the versions where only
the target is a metric space is primed. We follow the same convention here, thus giving lemmas
with primes.
-/
namespace uniform
variables [uniform_space α]
theorem tendsto_nhds_right {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ tendsto (λ x, (a, u x)) f (𝓤 α) :=
⟨λ H, tendsto_left_nhds_uniformity.comp H,
λ H s hs, by simpa [mem_of_mem_nhds hs] using H (mem_nhds_uniformity_iff_right.1 hs)⟩
theorem tendsto_nhds_left {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ tendsto (λ x, (u x, a)) f (𝓤 α) :=
⟨λ H, tendsto_right_nhds_uniformity.comp H,
λ H s hs, by simpa [mem_of_mem_nhds hs] using H (mem_nhds_uniformity_iff_left.1 hs)⟩
theorem continuous_at_iff'_right [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔ tendsto (λ x, (f b, f x)) (𝓝 b) (𝓤 α) :=
by rw [continuous_at, tendsto_nhds_right]
theorem continuous_at_iff'_left [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔ tendsto (λ x, (f x, f b)) (𝓝 b) (𝓤 α) :=
by rw [continuous_at, tendsto_nhds_left]
theorem continuous_at_iff_prod [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔ tendsto (λ x : β × β, (f x.1, f x.2)) (𝓝 (b, b)) (𝓤 α) :=
⟨λ H, le_trans (H.prod_map' H) (nhds_le_uniformity _),
λ H, continuous_at_iff'_left.2 $ H.comp $ tendsto_id.prod_mk_nhds tendsto_const_nhds⟩
theorem continuous_within_at_iff'_right [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔ tendsto (λ x, (f b, f x)) (𝓝[s] b) (𝓤 α) :=
by rw [continuous_within_at, tendsto_nhds_right]
theorem continuous_within_at_iff'_left [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔ tendsto (λ x, (f x, f b)) (𝓝[s] b) (𝓤 α) :=
by rw [continuous_within_at, tendsto_nhds_left]
theorem continuous_on_iff'_right [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔ ∀ b ∈ s, tendsto (λ x, (f b, f x)) (𝓝[s] b) (𝓤 α) :=
by simp [continuous_on, continuous_within_at_iff'_right]
theorem continuous_on_iff'_left [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔ ∀ b ∈ s, tendsto (λ x, (f x, f b)) (𝓝[s] b) (𝓤 α) :=
by simp [continuous_on, continuous_within_at_iff'_left]
theorem continuous_iff'_right [topological_space β] {f : β → α} :
continuous f ↔ ∀ b, tendsto (λ x, (f b, f x)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_right
theorem continuous_iff'_left [topological_space β] {f : β → α} :
continuous f ↔ ∀ b, tendsto (λ x, (f x, f b)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_left
end uniform
lemma filter.tendsto.congr_uniformity {α β} [uniform_space β] {f g : α → β} {l : filter α} {b : β}
(hf : tendsto f l (𝓝 b)) (hg : tendsto (λ x, (f x, g x)) l (𝓤 β)) :
tendsto g l (𝓝 b) :=
uniform.tendsto_nhds_right.2 $ (uniform.tendsto_nhds_right.1 hf).uniformity_trans hg
lemma uniform.tendsto_congr {α β} [uniform_space β] {f g : α → β} {l : filter α} {b : β}
(hfg : tendsto (λ x, (f x, g x)) l (𝓤 β)) :
tendsto f l (𝓝 b) ↔ tendsto g l (𝓝 b) :=
⟨λ h, h.congr_uniformity hfg, λ h, h.congr_uniformity hfg.uniformity_symm⟩
|
f4734f85856dc89468616a6df80fba2d830e47ca | 618003631150032a5676f229d13a079ac875ff77 | /src/algebra/continued_fractions/default.lean | 5d91f70b04f0e4cb9b4bc5bae649d8adaf0b924c | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 418 | lean | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import algebra.continued_fractions.continuants_recurrence
import algebra.continued_fractions.terminated_stable
import algebra.continued_fractions.convergents_equiv
import algebra.continued_fractions.computation
/-!
# Default Exports for Continued Fractions
-/
|
8375b6dd144448afdc3b3a3339b12d1ff4569bb4 | f618aea02cb4104ad34ecf3b9713065cc0d06103 | /src/data/real/nnreal.lean | a6b19fef03b78e0a647cb6134b388c612adfbaf6 | [
"Apache-2.0"
] | permissive | joehendrix/mathlib | 84b6603f6be88a7e4d62f5b1b0cbb523bb82b9a5 | c15eab34ad754f9ecd738525cb8b5a870e834ddc | refs/heads/master | 1,589,606,591,630 | 1,555,946,393,000 | 1,555,946,393,000 | 182,813,854 | 0 | 0 | null | 1,555,946,309,000 | 1,555,946,308,000 | null | UTF-8 | Lean | false | false | 15,608 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
Nonnegative real numbers.
-/
import data.real.basic order.lattice algebra.field
local attribute [instance, priority 0] nat.cast_coe
local attribute [instance, priority 0] rat.cast_coe
noncomputable theory
open lattice
local attribute [instance] classical.prop_decidable
def nnreal := {r : ℝ // 0 ≤ r}
local notation ` ℝ≥0 ` := nnreal
namespace nnreal
instance : has_coe ℝ≥0 ℝ := ⟨subtype.val⟩
protected lemma eq {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) → n = m := subtype.eq
protected lemma eq_iff {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) ↔ n = m :=
iff.intro nnreal.eq (congr_arg coe)
protected def of_real (r : ℝ) : ℝ≥0 := ⟨max r 0, le_max_right _ _⟩
lemma coe_of_real (r : ℝ) (hr : 0 ≤ r) : (nnreal.of_real r : ℝ) = r :=
max_eq_left hr
lemma coe_nonneg (r : nnreal) : (0 : ℝ) ≤ r := r.2
instance : has_zero ℝ≥0 := ⟨⟨0, le_refl 0⟩⟩
instance : has_one ℝ≥0 := ⟨⟨1, zero_le_one⟩⟩
instance : has_add ℝ≥0 := ⟨λa b, ⟨a + b, add_nonneg a.2 b.2⟩⟩
instance : has_sub ℝ≥0 := ⟨λa b, nnreal.of_real (a - b)⟩
instance : has_mul ℝ≥0 := ⟨λa b, ⟨a * b, mul_nonneg a.2 b.2⟩⟩
instance : has_inv ℝ≥0 := ⟨λa, ⟨(a.1)⁻¹, inv_nonneg.2 a.2⟩⟩
instance : has_div ℝ≥0 := ⟨λa b, ⟨a.1 / b.1, div_nonneg' a.2 b.2⟩⟩
instance : has_le ℝ≥0 := ⟨λ r s, (r:ℝ) ≤ s⟩
instance : has_bot ℝ≥0 := ⟨0⟩
instance : inhabited ℝ≥0 := ⟨0⟩
@[simp] protected lemma coe_zero : ((0 : ℝ≥0) : ℝ) = 0 := rfl
@[simp] protected lemma coe_one : ((1 : ℝ≥0) : ℝ) = 1 := rfl
@[simp] protected lemma coe_add (r₁ r₂ : ℝ≥0) : ((r₁ + r₂ : ℝ≥0) : ℝ) = r₁ + r₂ := rfl
@[simp] protected lemma coe_mul (r₁ r₂ : ℝ≥0) : ((r₁ * r₂ : ℝ≥0) : ℝ) = r₁ * r₂ := rfl
@[simp] protected lemma coe_div (r₁ r₂ : ℝ≥0) : ((r₁ / r₂ : ℝ≥0) : ℝ) = r₁ / r₂ := rfl
@[simp] protected lemma coe_inv (r : ℝ≥0) : ((r⁻¹ : ℝ≥0) : ℝ) = r⁻¹ := rfl
@[simp] protected lemma coe_sub (r₁ r₂ : ℝ≥0) (h : r₂ ≤ r₁) : ((r₁ - r₂ : ℝ≥0) : ℝ) = r₁ - r₂ :=
max_eq_left $ le_sub.2 $ by simp [show (r₂ : ℝ) ≤ r₁, from h]
-- TODO: setup semifield!
@[simp] protected lemma zero_div (r : ℝ≥0) : 0 / r = 0 := nnreal.eq (zero_div _)
@[simp] protected lemma coe_eq_zero (r : ℝ≥0) : ↑r = (0 : ℝ) ↔ r = 0 := @nnreal.eq_iff r 0
instance : comm_semiring ℝ≥0 :=
begin
refine { zero := 0, add := (+), one := 1, mul := (*), ..};
{ intros;
apply nnreal.eq;
simp [mul_comm, mul_assoc, add_comm_monoid.add, left_distrib, right_distrib,
add_comm_monoid.zero] }
end
instance : is_semiring_hom (coe : ℝ≥0 → ℝ) := by refine_struct {..}; intros; refl
lemma sum_coe {α} {s : finset α} {f : α → ℝ≥0} : ↑(s.sum f) = s.sum (λa, (f a : ℝ)) :=
eq.symm $ finset.sum_hom _
lemma prod_coe {α} {s : finset α} {f : α → ℝ≥0} : ↑(s.prod f) = s.prod (λa, (f a : ℝ)) :=
eq.symm $ finset.prod_hom _
lemma smul_coe (r : ℝ≥0) : ∀n, ↑(add_monoid.smul n r) = add_monoid.smul n (r:ℝ)
| 0 := rfl
| (n + 1) := by simp [add_monoid.add_smul, smul_coe n]
@[simp] protected lemma coe_nat_cast : ∀(n : ℕ), (↑(↑n : ℝ≥0) : ℝ) = n
| 0 := rfl
| (n + 1) := by simp [coe_nat_cast n]
instance : decidable_linear_order ℝ≥0 :=
decidable_linear_order.lift (coe : ℝ≥0 → ℝ) subtype.val_injective
protected lemma coe_le {r₁ r₂ : ℝ≥0} : r₁ ≤ r₂ ↔ (r₁ : ℝ) ≤ r₂ := iff.rfl
protected lemma coe_lt {r₁ r₂ : ℝ≥0} : r₁ < r₂ ↔ (r₁ : ℝ) < r₂ := iff.rfl
protected lemma coe_pos {r : ℝ≥0} : 0 < r ↔ (0 : ℝ) < r := iff.rfl
instance : order_bot ℝ≥0 :=
{ bot := ⊥, bot_le := assume ⟨a, h⟩, h, .. nnreal.decidable_linear_order }
instance : canonically_ordered_monoid ℝ≥0 :=
{ add_le_add_left := assume a b h c, @add_le_add_left ℝ _ a b h c,
lt_of_add_lt_add_left := assume a b c, @lt_of_add_lt_add_left ℝ _ a b c,
le_iff_exists_add := assume ⟨a, ha⟩ ⟨b, hb⟩,
iff.intro
(assume h : a ≤ b,
⟨⟨b - a, le_sub_iff_add_le.2 $ by simp [h]⟩,
nnreal.eq $ show b = a + (b - a), by rw [add_sub_cancel'_right]⟩)
(assume ⟨⟨c, hc⟩, eq⟩, eq.symm ▸ show a ≤ a + c, from (le_add_iff_nonneg_right a).2 hc),
..nnreal.comm_semiring,
..nnreal.lattice.order_bot,
..nnreal.decidable_linear_order }
instance : distrib_lattice ℝ≥0 := by apply_instance
instance : semilattice_inf_bot ℝ≥0 :=
{ .. nnreal.lattice.order_bot, .. nnreal.lattice.distrib_lattice }
instance : semilattice_sup_bot ℝ≥0 :=
{ .. nnreal.lattice.order_bot, .. nnreal.lattice.distrib_lattice }
instance : linear_ordered_semiring ℝ≥0 :=
{ add_left_cancel := assume a b c h, nnreal.eq $ @add_left_cancel ℝ _ a b c (nnreal.eq_iff.2 h),
add_right_cancel := assume a b c h, nnreal.eq $ @add_right_cancel ℝ _ a b c (nnreal.eq_iff.2 h),
le_of_add_le_add_left := assume a b c, @le_of_add_le_add_left ℝ _ a b c,
mul_le_mul_of_nonneg_left := assume a b c, @mul_le_mul_of_nonneg_left ℝ _ a b c,
mul_le_mul_of_nonneg_right := assume a b c, @mul_le_mul_of_nonneg_right ℝ _ a b c,
mul_lt_mul_of_pos_left := assume a b c, @mul_lt_mul_of_pos_left ℝ _ a b c,
mul_lt_mul_of_pos_right := assume a b c, @mul_lt_mul_of_pos_right ℝ _ a b c,
zero_lt_one := @zero_lt_one ℝ _,
.. nnreal.decidable_linear_order,
.. nnreal.canonically_ordered_monoid,
.. nnreal.comm_semiring }
instance : canonically_ordered_comm_semiring ℝ≥0 :=
{ zero_ne_one := assume h, @zero_ne_one ℝ _ $ congr_arg subtype.val $ h,
mul_eq_zero_iff := assume a b, nnreal.eq_iff.symm.trans $ mul_eq_zero.trans $ by simp,
.. nnreal.linear_ordered_semiring,
.. nnreal.canonically_ordered_monoid,
.. nnreal.comm_semiring }
instance : densely_ordered ℝ≥0 :=
⟨assume a b (h : (a : ℝ) < b), let ⟨c, hac, hcb⟩ := dense h in
⟨⟨c, le_trans a.property $ le_of_lt $ hac⟩, hac, hcb⟩⟩
instance : no_top_order ℝ≥0 :=
⟨assume a, let ⟨b, hb⟩ := no_top (a:ℝ) in ⟨⟨b, le_trans a.property $ le_of_lt $ hb⟩, hb⟩⟩
lemma bdd_above_coe {s : set ℝ≥0} : bdd_above ((coe : nnreal → ℝ) '' s) ↔ bdd_above s :=
iff.intro
(assume ⟨b, hb⟩, ⟨nnreal.of_real b, assume ⟨y, hy⟩ hys, show y ≤ max b 0, from
le_max_left_of_le $ hb _ $ set.mem_image_of_mem _ hys⟩)
(assume ⟨b, hb⟩, ⟨b, assume y ⟨x, hx, eq⟩, eq ▸ hb _ $ hx⟩)
lemma bdd_below_coe (s : set ℝ≥0) : bdd_below ((coe : nnreal → ℝ) '' s) :=
⟨0, assume r ⟨q, _, eq⟩, eq ▸ q.2⟩
instance : has_Sup ℝ≥0 :=
⟨λs, ⟨Sup ((coe : nnreal → ℝ) '' s),
begin
by_cases h : s = ∅,
{ simp [h, set.image_empty, real.Sup_empty] },
rcases set.ne_empty_iff_exists_mem.1 h with ⟨⟨b, hb⟩, hbs⟩,
by_cases h' : bdd_above s,
{ exact le_cSup_of_le (bdd_above_coe.2 h') (set.mem_image_of_mem _ hbs) hb },
{ rw [real.Sup_of_not_bdd_above], rwa [bdd_above_coe] }
end⟩⟩
instance : has_Inf ℝ≥0 :=
⟨λs, ⟨Inf ((coe : nnreal → ℝ) '' s),
begin
by_cases h : s = ∅,
{ simp [h, set.image_empty, real.Inf_empty] },
exact le_cInf (by simp [h]) (assume r ⟨q, _, eq⟩, eq ▸ q.2)
end⟩⟩
lemma coe_Sup (s : set nnreal) : (↑(Sup s) : ℝ) = Sup ((coe : nnreal → ℝ) '' s) := rfl
lemma coe_Inf (s : set nnreal) : (↑(Inf s) : ℝ) = Inf ((coe : nnreal → ℝ) '' s) := rfl
instance : conditionally_complete_linear_order_bot ℝ≥0 :=
{ Sup := Sup,
Inf := Inf,
le_cSup := assume s a hs ha, le_cSup (bdd_above_coe.2 hs) (set.mem_image_of_mem _ ha),
cSup_le := assume s a hs h,show Sup ((coe : nnreal → ℝ) '' s) ≤ a, from
cSup_le (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h _ hb,
cInf_le := assume s a _ has, cInf_le (bdd_below_coe s) (set.mem_image_of_mem _ has),
le_cInf := assume s a hs h, show (↑a : ℝ) ≤ Inf ((coe : nnreal → ℝ) '' s), from
le_cInf (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h _ hb,
cSup_empty := nnreal.eq $ by simp [coe_Sup, real.Sup_empty]; refl,
decidable_le := begin assume x y, apply classical.dec end,
.. nnreal.linear_ordered_semiring, .. lattice.lattice_of_decidable_linear_order,
.. nnreal.lattice.order_bot }
instance : archimedean nnreal :=
⟨ assume x y pos_y,
let ⟨n, hr⟩ := archimedean.arch (x:ℝ) (pos_y : (0 : ℝ) < y) in
⟨n, show (x:ℝ) ≤ (add_monoid.smul n y : nnreal), by simp [*, smul_coe]⟩ ⟩
lemma le_of_forall_epsilon_le {a b : nnreal} (h : ∀ε, ε > 0 → a ≤ b + ε) : a ≤ b :=
le_of_forall_le_of_dense $ assume x hxb,
begin
rcases le_iff_exists_add.1 (le_of_lt hxb) with ⟨ε, rfl⟩,
exact h _ ((lt_add_iff_pos_right b).1 hxb)
end
lemma lt_iff_exists_rat_btwn (a b : nnreal) :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ nnreal.of_real q < b) :=
iff.intro
(assume (h : (↑a:ℝ) < (↑b:ℝ)),
let ⟨q, haq, hqb⟩ := exists_rat_btwn h in
have 0 ≤ (q : ℝ), from le_trans a.2 $ le_of_lt haq,
⟨q, rat.cast_nonneg.1 this, by simp [coe_of_real _ this, nnreal.coe_lt, haq, hqb]⟩)
(assume ⟨q, _, haq, hqb⟩, lt_trans haq hqb)
lemma bot_eq_zero : (⊥ : nnreal) = 0 := rfl
lemma mul_sup (a b c : ℝ≥0) : a * (b ⊔ c) = (a * b) ⊔ (a * c) :=
begin
cases le_total b c with h h,
{ simp [sup_eq_max, max_eq_right h, max_eq_right (mul_le_mul_of_nonneg_left h (zero_le a))] },
{ simp [sup_eq_max, max_eq_left h, max_eq_left (mul_le_mul_of_nonneg_left h (zero_le a))] },
end
lemma mul_finset_sup {α} {f : α → ℝ≥0} {s : finset α} (r : ℝ≥0) :
r * s.sup f = s.sup (λa, r * f a) :=
begin
refine s.induction_on _ _,
{ simp [bot_eq_zero] },
{ assume a s has ih, simp [has, ih, mul_sup], }
end
section of_real
@[simp] lemma zero_le_coe {q : nnreal} : 0 ≤ (q : ℝ) := q.2
@[simp] lemma of_real_zero : nnreal.of_real 0 = 0 :=
by simp [nnreal.of_real]; refl
@[simp] lemma of_real_one : nnreal.of_real 1 = 1 :=
by simp [nnreal.of_real, max_eq_left (zero_le_one : (0 :ℝ) ≤ 1)]; refl
@[simp] lemma of_real_pos {r : ℝ} : 0 < nnreal.of_real r ↔ 0 < r :=
by simp [nnreal.of_real, nnreal.coe_lt, lt_irrefl]
@[simp] lemma of_real_eq_zero {r : ℝ} : nnreal.of_real r = 0 ↔ r ≤ 0 :=
by simpa [-of_real_pos] using (not_iff_not.2 (@of_real_pos r))
lemma of_real_of_nonpos {r : ℝ} : r ≤ 0 → nnreal.of_real r = 0 :=
of_real_eq_zero.2
@[simp] lemma of_real_coe {r : nnreal} : nnreal.of_real r = r :=
nnreal.eq $ by simp [nnreal.of_real]
@[simp] lemma of_real_le_of_real_iff {r p : ℝ} (hp : 0 ≤ p) :
nnreal.of_real r ≤ nnreal.of_real p ↔ r ≤ p :=
by simp [nnreal.coe_le, nnreal.of_real, hp]
@[simp] lemma of_real_lt_of_real_iff' {r p : ℝ} :
nnreal.of_real r < nnreal.of_real p ↔ r < p ∧ 0 < p :=
by simp [nnreal.coe_lt, nnreal.of_real, lt_irrefl]
lemma of_real_lt_of_real_iff {r p : ℝ} (h : 0 < p) :
nnreal.of_real r < nnreal.of_real p ↔ r < p :=
of_real_lt_of_real_iff'.trans (and_iff_left h)
@[simp] lemma of_real_add {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
nnreal.of_real (r + p) = nnreal.of_real r + nnreal.of_real p :=
nnreal.eq $ by simp [nnreal.of_real, hr, hp, add_nonneg]
lemma of_real_add_of_real {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
nnreal.of_real r + nnreal.of_real p = nnreal.of_real (r + p) :=
(of_real_add hr hp).symm
lemma of_real_le_of_real {r p : ℝ} (h : r ≤ p) : nnreal.of_real r ≤ nnreal.of_real p :=
nnreal.coe_le.2 $ max_le_max h $ le_refl _
lemma of_real_add_le {r p : ℝ} : nnreal.of_real (r + p) ≤ nnreal.of_real r + nnreal.of_real p :=
nnreal.coe_le.2 $ max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) nnreal.zero_le_coe
end of_real
section mul
lemma mul_eq_mul_left {a b c : nnreal} (h : a ≠ 0) : (a * b = a * c ↔ b = c) :=
begin
rw [← nnreal.eq_iff, ← nnreal.eq_iff, nnreal.coe_mul, nnreal.coe_mul], split,
{ exact eq_of_mul_eq_mul_left (mt (@nnreal.eq_iff a 0).1 h) },
{ assume h, rw [h] }
end
end mul
section sub
lemma sub_eq_zero {r p : nnreal} (h : r ≤ p) : r - p = 0 :=
nnreal.eq $ max_eq_right $ sub_le_iff_le_add.2 $ by simpa [nnreal.coe_le] using h
@[simp] lemma sub_le_iff_le_add {r p q : nnreal} : r - p ≤ q ↔ r ≤ q + p :=
match le_total p r with
| or.inl h :=
by rw [nnreal.coe_le, nnreal.coe_le, nnreal.coe_sub _ _ h, nnreal.coe_add, sub_le_iff_le_add]
| or.inr h :=
have r ≤ p + q, from le_add_right h,
by simpa [nnreal.coe_le, nnreal.coe_le, sub_eq_zero h]
end
lemma add_sub_cancel {r p : nnreal} : (p + r) - r = p :=
nnreal.eq $ by rw [nnreal.coe_sub, nnreal.coe_add, add_sub_cancel]; exact le_add_left (le_refl _)
lemma add_sub_cancel' {r p : nnreal} : (r + p) - r = p :=
by rw [add_comm, add_sub_cancel]
@[simp] lemma sub_add_cancel_of_le {a b : nnreal} (h : b ≤ a) : (a - b) + b = a :=
nnreal.eq $ by rw [nnreal.coe_add, nnreal.coe_sub _ _ h, sub_add_cancel]
end sub
section inv
lemma div_def {r p : nnreal} : r / p = r * p⁻¹ := rfl
@[simp] lemma inv_zero : (0 : nnreal)⁻¹ = 0 := nnreal.eq inv_zero
@[simp] lemma inv_eq_zero {r : nnreal} : (r : nnreal)⁻¹ = 0 ↔ r = 0 :=
by rw [← nnreal.eq_iff, nnreal.coe_inv, nnreal.coe_zero, inv_eq_zero, ← nnreal.coe_zero, nnreal.eq_iff]
@[simp] lemma inv_pos {r : nnreal} : 0 < r⁻¹ ↔ 0 < r :=
by simp [zero_lt_iff_ne_zero]
@[simp] lemma inv_mul_cancel {r : ℝ≥0} (h : r ≠ 0) : r⁻¹ * r = 1 :=
nnreal.eq $ inv_mul_cancel $ mt (@nnreal.eq_iff r 0).1 h
@[simp] lemma mul_inv_cancel {r : ℝ≥0} (h : r ≠ 0) : r * r⁻¹ = 1 :=
by rw [mul_comm, inv_mul_cancel h]
@[simp] lemma inv_inv {r : ℝ≥0} : r⁻¹⁻¹ = r := nnreal.eq inv_inv'
@[simp] lemma inv_le {r p : ℝ≥0} (h : r ≠ 0) : r⁻¹ ≤ p ↔ 1 ≤ r * p :=
by rw [← mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h]
lemma inv_le_of_le_mul {r p : ℝ≥0} (h : 1 ≤ r * p) : r⁻¹ ≤ p :=
by by_cases r = 0; simp [*, inv_le]
@[simp] lemma le_inv_iff_mul_le {r p : ℝ≥0} (h : p ≠ 0) : (r ≤ p⁻¹ ↔ r * p ≤ 1) :=
by rw [← mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
@[simp] lemma lt_inv_iff_mul_lt {r p : ℝ≥0} (h : p ≠ 0) : (r < p⁻¹ ↔ r * p < 1) :=
by rw [← mul_lt_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
lemma mul_le_if_le_inv {a b r : nnreal} (hr : r ≠ 0) : r * a ≤ b ↔ a ≤ r⁻¹ * b :=
have 0 < r, from lt_of_le_of_ne (zero_le r) hr.symm,
by rw [← @mul_le_mul_left _ _ a _ r this, ← mul_assoc, mul_inv_cancel hr, one_mul]
lemma le_of_forall_lt_one_mul_lt {x y : ℝ≥0} (h : ∀a<1, a * x ≤ y) : x ≤ y :=
le_of_forall_ge_of_dense $ assume a ha,
have hx : x ≠ 0 := zero_lt_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha),
have hx' : x⁻¹ ≠ 0, by rwa [(≠), inv_eq_zero],
have a * x⁻¹ < 1, by rwa [← lt_inv_iff_mul_lt hx', inv_inv],
have (a * x⁻¹) * x ≤ y, from h _ this,
by rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this
lemma div_add_div_same (a b c : ℝ≥0) : a / c + b / c = (a + b) / c :=
eq.symm $ right_distrib a b (c⁻¹)
lemma add_halves (a : ℝ≥0) : a / 2 + a / 2 = a := nnreal.eq (add_halves a)
lemma half_lt_self {a : ℝ≥0} (h : a ≠ 0) : a / 2 < a :=
by rw [nnreal.coe_lt, nnreal.coe_div]; exact
half_lt_self (bot_lt_iff_ne_bot.2 h)
end inv
end nnreal
|
94095b040c2a3996e17558474de63291944949f9 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Compiler/IR/EmitC.lean | db46c338bd66f7e7e8aaef1b1599acf3ba5a26b1 | [
"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 | 26,210 | 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.Runtime
import Lean.Compiler.NameMangling
import Lean.Compiler.ExportAttr
import Lean.Compiler.InitAttr
import Lean.Compiler.IR.CompilerM
import Lean.Compiler.IR.EmitUtil
import Lean.Compiler.IR.NormIds
import Lean.Compiler.IR.SimpCase
import Lean.Compiler.IR.Boxing
namespace Lean.IR.EmitC
open ExplicitBoxing (requiresBoxedVersion mkBoxedName isBoxedName)
def leanMainFn := "_lean_main"
structure Context where
env : Environment
modName : Name
jpMap : JPParamsMap := {}
mainFn : FunId := default
mainParams : Array Param := #[]
abbrev M := ReaderT Context (EStateM String String)
def getEnv : M Environment := Context.env <$> read
def getModName : M Name := Context.modName <$> read
def getDecl (n : Name) : M Decl := do
let env ← getEnv
match findEnvDecl env n with
| some d => pure d
| none => throw s!"unknown declaration '{n}'"
@[inline] def emit {α : Type} [ToString α] (a : α) : M Unit :=
modify fun out => out ++ toString a
@[inline] def emitLn {α : Type} [ToString α] (a : α) : M Unit := do
emit a; emit "\n"
def emitLns {α : Type} [ToString α] (as : List α) : M Unit :=
as.forM fun a => emitLn a
def argToCString (x : Arg) : String :=
match x with
| Arg.var x => toString x
| _ => "lean_box(0)"
def emitArg (x : Arg) : M Unit :=
emit (argToCString x)
def toCType : IRType → String
| IRType.float => "double"
| IRType.uint8 => "uint8_t"
| IRType.uint16 => "uint16_t"
| IRType.uint32 => "uint32_t"
| IRType.uint64 => "uint64_t"
| IRType.usize => "size_t"
| IRType.object => "lean_object*"
| IRType.tobject => "lean_object*"
| IRType.irrelevant => "lean_object*"
| IRType.struct _ _ => panic! "not implemented yet"
| IRType.union _ _ => panic! "not implemented yet"
def throwInvalidExportName {α : Type} (n : Name) : M α :=
throw s!"invalid export name '{n}'"
def toCName (n : Name) : M String := do
let env ← getEnv;
-- TODO: we should support simple export names only
match getExportNameFor? env n with
| some (.str .anonymous s) => pure s
| some _ => throwInvalidExportName n
| none => if n == `main then pure leanMainFn else pure n.mangle
def emitCName (n : Name) : M Unit :=
toCName n >>= emit
def toCInitName (n : Name) : M String := do
let env ← getEnv;
-- TODO: we should support simple export names only
match getExportNameFor? env n with
| some (.str .anonymous s) => return "_init_" ++ s
| some _ => throwInvalidExportName n
| none => pure ("_init_" ++ n.mangle)
def emitCInitName (n : Name) : M Unit :=
toCInitName n >>= emit
def emitFnDeclAux (decl : Decl) (cppBaseName : String) (isExternal : Bool) : M Unit := do
let ps := decl.params
let env ← getEnv
if ps.isEmpty then
if isClosedTermName env decl.name then emit "static "
else if isExternal then emit "extern "
else emit "LEAN_EXPORT "
else
if !isExternal then emit "LEAN_EXPORT "
emit (toCType decl.resultType ++ " " ++ cppBaseName)
unless ps.isEmpty do
emit "("
-- We omit irrelevant parameters for extern constants
let ps := if isExternC env decl.name then ps.filter (fun p => !p.ty.isIrrelevant) else ps
if ps.size > closureMaxArgs && isBoxedName decl.name then
emit "lean_object**"
else
ps.size.forM fun i => do
if i > 0 then emit ", "
emit (toCType ps[i]!.ty)
emit ")"
emitLn ";"
def emitFnDecl (decl : Decl) (isExternal : Bool) : M Unit := do
let cppBaseName ← toCName decl.name
emitFnDeclAux decl cppBaseName isExternal
def emitExternDeclAux (decl : Decl) (cNameStr : String) : M Unit := do
let env ← getEnv
let extC := isExternC env decl.name
emitFnDeclAux decl cNameStr extC
def emitFnDecls : M Unit := do
let env ← getEnv
let decls := getDecls env
let modDecls : NameSet := decls.foldl (fun s d => s.insert d.name) {}
let usedDecls : NameSet := decls.foldl (fun s d => collectUsedDecls env d (s.insert d.name)) {}
let usedDecls := usedDecls.toList
usedDecls.forM fun n => do
let decl ← getDecl n;
match getExternNameFor env `c decl.name with
| some cName => emitExternDeclAux decl cName
| none => emitFnDecl decl (!modDecls.contains n)
def emitMainFn : M Unit := do
let d ← getDecl `main
match d with
| .fdecl (xs := xs) .. => do
unless xs.size == 2 || xs.size == 1 do throw "invalid main function, incorrect arity when generating code"
let env ← getEnv
let usesLeanAPI := usesModuleFrom env `Lean
if usesLeanAPI then
emitLn "void lean_initialize();"
else
emitLn "void lean_initialize_runtime_module();";
emitLn "
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif
int main(int argc, char ** argv) {
#if defined(WIN32) || defined(_WIN32)
SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
lean_object* in; lean_object* res;";
if usesLeanAPI then
emitLn "lean_initialize();"
else
emitLn "lean_initialize_runtime_module();"
let modName ← getModName
/- We disable panic messages because they do not mesh well with extracted closed terms.
See issue #534. We can remove this workaround after we implement issue #467. -/
emitLn "lean_set_panic_messages(false);"
emitLn ("res = " ++ mkModuleInitializationFunctionName modName ++ "(1 /* builtin */, lean_io_mk_world());")
emitLn "lean_set_panic_messages(true);"
emitLns ["lean_io_mark_end_initialization();",
"if (lean_io_result_is_ok(res)) {",
"lean_dec_ref(res);",
"lean_init_task_manager();"];
if xs.size == 2 then
emitLns ["in = lean_box(0);",
"int i = argc;",
"while (i > 1) {",
" lean_object* n;",
" i--;",
" n = lean_alloc_ctor(1,2,0); lean_ctor_set(n, 0, lean_mk_string(argv[i])); lean_ctor_set(n, 1, in);",
" in = n;",
"}"]
emitLn ("res = " ++ leanMainFn ++ "(in, lean_io_mk_world());")
else
emitLn ("res = " ++ leanMainFn ++ "(lean_io_mk_world());")
emitLn "}"
-- `IO _`
let retTy := env.find? `main |>.get! |>.type |>.getForallBody
-- either `UInt32` or `(P)Unit`
let retTy := retTy.appArg!
-- finalize at least the task manager to avoid leak sanitizer false positives from tasks outliving the main thread
emitLns ["lean_finalize_task_manager();",
"if (lean_io_result_is_ok(res)) {",
" int ret = " ++ if retTy.constName? == some ``UInt32 then "lean_unbox_uint32(lean_io_result_get_value(res));" else "0;",
" lean_dec_ref(res);",
" return ret;",
"} else {",
" lean_io_result_show_error(res);",
" lean_dec_ref(res);",
" return 1;",
"}"]
emitLn "}"
| _ => throw "function declaration expected"
def hasMainFn : M Bool := do
let env ← getEnv
let decls := getDecls env
return decls.any (fun d => d.name == `main)
def emitMainFnIfNeeded : M Unit := do
if (← hasMainFn) then emitMainFn
def emitFileHeader : M Unit := do
let env ← getEnv
let modName ← getModName
emitLn "// Lean compiler output"
emitLn ("// Module: " ++ toString modName)
emit "// Imports:"
env.imports.forM fun m => emit (" " ++ toString m)
emitLn ""
emitLn "#include <lean/lean.h>"
emitLns [
"#if defined(__clang__)",
"#pragma clang diagnostic ignored \"-Wunused-parameter\"",
"#pragma clang diagnostic ignored \"-Wunused-label\"",
"#elif defined(__GNUC__) && !defined(__CLANG__)",
"#pragma GCC diagnostic ignored \"-Wunused-parameter\"",
"#pragma GCC diagnostic ignored \"-Wunused-label\"",
"#pragma GCC diagnostic ignored \"-Wunused-but-set-variable\"",
"#endif",
"#ifdef __cplusplus",
"extern \"C\" {",
"#endif"
]
def emitFileFooter : M Unit :=
emitLns [
"#ifdef __cplusplus",
"}",
"#endif"
]
def throwUnknownVar {α : Type} (x : VarId) : M α :=
throw s!"unknown variable '{x}'"
def getJPParams (j : JoinPointId) : M (Array Param) := do
let ctx ← read;
match ctx.jpMap.find? j with
| some ps => pure ps
| none => throw "unknown join point"
def declareVar (x : VarId) (t : IRType) : M Unit := do
emit (toCType t); emit " "; emit x; emit "; "
def declareParams (ps : Array Param) : M Unit :=
ps.forM fun p => declareVar p.x p.ty
partial def declareVars : FnBody → Bool → M Bool
| e@(FnBody.vdecl x t _ b), d => do
let ctx ← read
if isTailCallTo ctx.mainFn e then
pure d
else
declareVar x t; declareVars b true
| FnBody.jdecl _ xs _ b, d => do declareParams xs; declareVars b (d || xs.size > 0)
| e, d => if e.isTerminal then pure d else declareVars e.body d
def emitTag (x : VarId) (xType : IRType) : M Unit := do
if xType.isObj then do
emit "lean_obj_tag("; emit x; emit ")"
else
emit x
def isIf (alts : Array Alt) : Option (Nat × FnBody × FnBody) :=
if alts.size != 2 then none
else match alts[0]! with
| Alt.ctor c b => some (c.cidx, b, alts[1]!.body)
| _ => none
def emitInc (x : VarId) (n : Nat) (checkRef : Bool) : M Unit := do
emit $
if checkRef then (if n == 1 then "lean_inc" else "lean_inc_n")
else (if n == 1 then "lean_inc_ref" else "lean_inc_ref_n")
emit "("; emit x
if n != 1 then emit ", "; emit n
emitLn ");"
def emitDec (x : VarId) (n : Nat) (checkRef : Bool) : M Unit := do
emit (if checkRef then "lean_dec" else "lean_dec_ref");
emit "("; emit x;
if n != 1 then emit ", "; emit n
emitLn ");"
def emitDel (x : VarId) : M Unit := do
emit "lean_free_object("; emit x; emitLn ");"
def emitSetTag (x : VarId) (i : Nat) : M Unit := do
emit "lean_ctor_set_tag("; emit x; emit ", "; emit i; emitLn ");"
def emitSet (x : VarId) (i : Nat) (y : Arg) : M Unit := do
emit "lean_ctor_set("; emit x; emit ", "; emit i; emit ", "; emitArg y; emitLn ");"
def emitOffset (n : Nat) (offset : Nat) : M Unit := do
if n > 0 then
emit "sizeof(void*)*"; emit n;
if offset > 0 then emit " + "; emit offset
else
emit offset
def emitUSet (x : VarId) (n : Nat) (y : VarId) : M Unit := do
emit "lean_ctor_set_usize("; emit x; emit ", "; emit n; emit ", "; emit y; emitLn ");"
def emitSSet (x : VarId) (n : Nat) (offset : Nat) (y : VarId) (t : IRType) : M Unit := do
match t with
| IRType.float => emit "lean_ctor_set_float"
| IRType.uint8 => emit "lean_ctor_set_uint8"
| IRType.uint16 => emit "lean_ctor_set_uint16"
| IRType.uint32 => emit "lean_ctor_set_uint32"
| IRType.uint64 => emit "lean_ctor_set_uint64"
| _ => throw "invalid instruction";
emit "("; emit x; emit ", "; emitOffset n offset; emit ", "; emit y; emitLn ");"
def emitJmp (j : JoinPointId) (xs : Array Arg) : M Unit := do
let ps ← getJPParams j
unless xs.size == ps.size do throw "invalid goto"
xs.size.forM fun i => do
let p := ps[i]!
let x := xs[i]!
emit p.x; emit " = "; emitArg x; emitLn ";"
emit "goto "; emit j; emitLn ";"
def emitLhs (z : VarId) : M Unit := do
emit z; emit " = "
def emitArgs (ys : Array Arg) : M Unit :=
ys.size.forM fun i => do
if i > 0 then emit ", "
emitArg ys[i]!
def emitCtorScalarSize (usize : Nat) (ssize : Nat) : M Unit := do
if usize == 0 then emit ssize
else if ssize == 0 then emit "sizeof(size_t)*"; emit usize
else emit "sizeof(size_t)*"; emit usize; emit " + "; emit ssize
def emitAllocCtor (c : CtorInfo) : M Unit := do
emit "lean_alloc_ctor("; emit c.cidx; emit ", "; emit c.size; emit ", "
emitCtorScalarSize c.usize c.ssize; emitLn ");"
def emitCtorSetArgs (z : VarId) (ys : Array Arg) : M Unit :=
ys.size.forM fun i => do
emit "lean_ctor_set("; emit z; emit ", "; emit i; emit ", "; emitArg ys[i]!; emitLn ");"
def emitCtor (z : VarId) (c : CtorInfo) (ys : Array Arg) : M Unit := do
emitLhs z;
if c.size == 0 && c.usize == 0 && c.ssize == 0 then do
emit "lean_box("; emit c.cidx; emitLn ");"
else do
emitAllocCtor c; emitCtorSetArgs z ys
def emitReset (z : VarId) (n : Nat) (x : VarId) : M Unit := do
emit "if (lean_is_exclusive("; emit x; emitLn ")) {";
n.forM fun i => do
emit " lean_ctor_release("; emit x; emit ", "; emit i; emitLn ");"
emit " "; emitLhs z; emit x; emitLn ";";
emitLn "} else {";
emit " lean_dec_ref("; emit x; emitLn ");";
emit " "; emitLhs z; emitLn "lean_box(0);";
emitLn "}"
def emitReuse (z : VarId) (x : VarId) (c : CtorInfo) (updtHeader : Bool) (ys : Array Arg) : M Unit := do
emit "if (lean_is_scalar("; emit x; emitLn ")) {";
emit " "; emitLhs z; emitAllocCtor c;
emitLn "} else {";
emit " "; emitLhs z; emit x; emitLn ";";
if updtHeader then emit " lean_ctor_set_tag("; emit z; emit ", "; emit c.cidx; emitLn ");"
emitLn "}";
emitCtorSetArgs z ys
def emitProj (z : VarId) (i : Nat) (x : VarId) : M Unit := do
emitLhs z; emit "lean_ctor_get("; emit x; emit ", "; emit i; emitLn ");"
def emitUProj (z : VarId) (i : Nat) (x : VarId) : M Unit := do
emitLhs z; emit "lean_ctor_get_usize("; emit x; emit ", "; emit i; emitLn ");"
def emitSProj (z : VarId) (t : IRType) (n offset : Nat) (x : VarId) : M Unit := do
emitLhs z;
match t with
| IRType.float => emit "lean_ctor_get_float"
| IRType.uint8 => emit "lean_ctor_get_uint8"
| IRType.uint16 => emit "lean_ctor_get_uint16"
| IRType.uint32 => emit "lean_ctor_get_uint32"
| IRType.uint64 => emit "lean_ctor_get_uint64"
| _ => throw "invalid instruction"
emit "("; emit x; emit ", "; emitOffset n offset; emitLn ");"
def toStringArgs (ys : Array Arg) : List String :=
ys.toList.map argToCString
def emitSimpleExternalCall (f : String) (ps : Array Param) (ys : Array Arg) : M Unit := do
emit f; emit "("
-- We must remove irrelevant arguments to extern calls.
discard <| ys.size.foldM
(fun i (first : Bool) =>
if ps[i]!.ty.isIrrelevant then
pure first
else do
unless first do emit ", "
emitArg ys[i]!
pure false)
true
emitLn ");"
pure ()
def emitExternCall (f : FunId) (ps : Array Param) (extData : ExternAttrData) (ys : Array Arg) : M Unit :=
match getExternEntryFor extData `c with
| some (ExternEntry.standard _ extFn) => emitSimpleExternalCall extFn ps ys
| some (ExternEntry.inline _ pat) => do emit (expandExternPattern pat (toStringArgs ys)); emitLn ";"
| some (ExternEntry.foreign _ extFn) => emitSimpleExternalCall extFn ps ys
| _ => throw s!"failed to emit extern application '{f}'"
def emitFullApp (z : VarId) (f : FunId) (ys : Array Arg) : M Unit := do
emitLhs z
let decl ← getDecl f
match decl with
| Decl.extern _ ps _ extData => emitExternCall f ps extData ys
| _ =>
emitCName f
if ys.size > 0 then emit "("; emitArgs ys; emit ")"
emitLn ";"
def emitPartialApp (z : VarId) (f : FunId) (ys : Array Arg) : M Unit := do
let decl ← getDecl f
let arity := decl.params.size;
emitLhs z; emit "lean_alloc_closure((void*)("; emitCName f; emit "), "; emit arity; emit ", "; emit ys.size; emitLn ");";
ys.size.forM fun i => do
let y := ys[i]!
emit "lean_closure_set("; emit z; emit ", "; emit i; emit ", "; emitArg y; emitLn ");"
def emitApp (z : VarId) (f : VarId) (ys : Array Arg) : M Unit :=
if ys.size > closureMaxArgs then do
emit "{ lean_object* _aargs[] = {"; emitArgs ys; emitLn "};";
emitLhs z; emit "lean_apply_m("; emit f; emit ", "; emit ys.size; emitLn ", _aargs); }"
else do
emitLhs z; emit "lean_apply_"; emit ys.size; emit "("; emit f; emit ", "; emitArgs ys; emitLn ");"
def emitBoxFn (xType : IRType) : M Unit :=
match xType with
| IRType.usize => emit "lean_box_usize"
| IRType.uint32 => emit "lean_box_uint32"
| IRType.uint64 => emit "lean_box_uint64"
| IRType.float => emit "lean_box_float"
| _ => emit "lean_box"
def emitBox (z : VarId) (x : VarId) (xType : IRType) : M Unit := do
emitLhs z; emitBoxFn xType; emit "("; emit x; emitLn ");"
def emitUnbox (z : VarId) (t : IRType) (x : VarId) : M Unit := do
emitLhs z;
match t with
| IRType.usize => emit "lean_unbox_usize"
| IRType.uint32 => emit "lean_unbox_uint32"
| IRType.uint64 => emit "lean_unbox_uint64"
| IRType.float => emit "lean_unbox_float"
| _ => emit "lean_unbox";
emit "("; emit x; emitLn ");"
def emitIsShared (z : VarId) (x : VarId) : M Unit := do
emitLhs z; emit "!lean_is_exclusive("; emit x; emitLn ");"
def emitIsTaggedPtr (z : VarId) (x : VarId) : M Unit := do
emitLhs z; emit "!lean_is_scalar("; emit x; emitLn ");"
def toHexDigit (c : Nat) : String :=
String.singleton c.digitChar
def quoteString (s : String) : String :=
let q := "\"";
let q := s.foldl
(fun q c => q ++
if c == '\n' then "\\n"
else if c == '\r' then "\\r"
else if c == '\t' then "\\t"
else if c == '\\' then "\\\\"
else if c == '\"' then "\\\""
else if c.toNat <= 31 then
"\\x" ++ toHexDigit (c.toNat / 16) ++ toHexDigit (c.toNat % 16)
-- TODO(Leo): we should use `\unnnn` for escaping unicode characters.
else String.singleton c)
q;
q ++ "\""
def emitNumLit (t : IRType) (v : Nat) : M Unit := do
if t.isObj then
if v < UInt32.size then
emit "lean_unsigned_to_nat("; emit v; emit "u)"
else
emit "lean_cstr_to_nat(\""; emit v; emit "\")"
else
emit v
def emitLit (z : VarId) (t : IRType) (v : LitVal) : M Unit := do
emitLhs z;
match v with
| LitVal.num v => emitNumLit t v; emitLn ";"
| LitVal.str v => emit "lean_mk_string_from_bytes("; emit (quoteString v); emit ", "; emit v.utf8ByteSize; emitLn ");"
def emitVDecl (z : VarId) (t : IRType) (v : Expr) : M Unit :=
match v with
| Expr.ctor c ys => emitCtor z c ys
| Expr.reset n x => emitReset z n x
| Expr.reuse x c u ys => emitReuse z x c u ys
| Expr.proj i x => emitProj z i x
| Expr.uproj i x => emitUProj z i x
| Expr.sproj n o x => emitSProj z t n o x
| Expr.fap c ys => emitFullApp z c ys
| Expr.pap c ys => emitPartialApp z c ys
| Expr.ap x ys => emitApp z x ys
| Expr.box t x => emitBox z x t
| Expr.unbox x => emitUnbox z t x
| Expr.isShared x => emitIsShared z x
| Expr.isTaggedPtr x => emitIsTaggedPtr z x
| Expr.lit v => emitLit z t v
def isTailCall (x : VarId) (v : Expr) (b : FnBody) : M Bool := do
let ctx ← read;
match v, b with
| Expr.fap f _, FnBody.ret (Arg.var y) => return f == ctx.mainFn && x == y
| _, _ => pure false
def paramEqArg (p : Param) (x : Arg) : Bool :=
match x with
| Arg.var x => p.x == x
| _ => false
/--
Given `[p_0, ..., p_{n-1}]`, `[y_0, ..., y_{n-1}]`, representing the assignments
```
p_0 := y_0,
...
p_{n-1} := y_{n-1}
```
Return true iff we have `(i, j)` where `j > i`, and `y_j == p_i`.
That is, we have
```
p_i := y_i,
...
p_j := p_i, -- p_i was overwritten above
```
-/
def overwriteParam (ps : Array Param) (ys : Array Arg) : Bool :=
let n := ps.size;
n.any fun i =>
let p := ps[i]!
(i+1, n).anyI fun j => paramEqArg p ys[j]!
def emitTailCall (v : Expr) : M Unit :=
match v with
| Expr.fap _ ys => do
let ctx ← read
let ps := ctx.mainParams
unless ps.size == ys.size do throw "invalid tail call"
if overwriteParam ps ys then
emitLn "{"
ps.size.forM fun i => do
let p := ps[i]!
let y := ys[i]!
unless paramEqArg p y do
emit (toCType p.ty); emit " _tmp_"; emit i; emit " = "; emitArg y; emitLn ";"
ps.size.forM fun i => do
let p := ps[i]!
let y := ys[i]!
unless paramEqArg p y do emit p.x; emit " = _tmp_"; emit i; emitLn ";"
emitLn "}"
else
ys.size.forM fun i => do
let p := ps[i]!
let y := ys[i]!
unless paramEqArg p y do emit p.x; emit " = "; emitArg y; emitLn ";"
emitLn "goto _start;"
| _ => throw "bug at emitTailCall"
mutual
partial def emitIf (x : VarId) (xType : IRType) (tag : Nat) (t : FnBody) (e : FnBody) : M Unit := do
emit "if ("; emitTag x xType; emit " == "; emit tag; emitLn ")";
emitFnBody t;
emitLn "else";
emitFnBody e
partial def emitCase (x : VarId) (xType : IRType) (alts : Array Alt) : M Unit :=
match isIf alts with
| some (tag, t, e) => emitIf x xType tag t e
| _ => do
emit "switch ("; emitTag x xType; emitLn ") {";
let alts := ensureHasDefault alts;
alts.forM fun alt => do
match alt with
| Alt.ctor c b => emit "case "; emit c.cidx; emitLn ":"; emitFnBody b
| Alt.default b => emitLn "default: "; emitFnBody b
emitLn "}"
partial def emitBlock (b : FnBody) : M Unit := do
match b with
| FnBody.jdecl _ _ _ b => emitBlock b
| d@(FnBody.vdecl x t v b) =>
let ctx ← read
if isTailCallTo ctx.mainFn d then
emitTailCall v
else
emitVDecl x t v
emitBlock b
| FnBody.inc x n c p b =>
unless p do emitInc x n c
emitBlock b
| FnBody.dec x n c p b =>
unless p do emitDec x n c
emitBlock b
| FnBody.del x b => emitDel x; emitBlock b
| FnBody.setTag x i b => emitSetTag x i; emitBlock b
| FnBody.set x i y b => emitSet x i y; emitBlock b
| FnBody.uset x i y b => emitUSet x i y; emitBlock b
| FnBody.sset x i o y t b => emitSSet x i o y t; emitBlock b
| FnBody.mdata _ b => emitBlock b
| FnBody.ret x => emit "return "; emitArg x; emitLn ";"
| FnBody.case _ x xType alts => emitCase x xType alts
| FnBody.jmp j xs => emitJmp j xs
| FnBody.unreachable => emitLn "lean_internal_panic_unreachable();"
partial def emitJPs : FnBody → M Unit
| FnBody.jdecl j _ v b => do emit j; emitLn ":"; emitFnBody v; emitJPs b
| e => do unless e.isTerminal do emitJPs e.body
partial def emitFnBody (b : FnBody) : M Unit := do
emitLn "{"
let declared ← declareVars b false
if declared then emitLn ""
emitBlock b
emitJPs b
emitLn "}"
end
def emitDeclAux (d : Decl) : M Unit := do
let env ← getEnv
let (_, jpMap) := mkVarJPMaps d
withReader (fun ctx => { ctx with jpMap := jpMap }) do
unless hasInitAttr env d.name do
match d with
| .fdecl (f := f) (xs := xs) (type := t) (body := b) .. =>
let baseName ← toCName f;
if xs.size == 0 then
emit "static "
else
emit "LEAN_EXPORT " -- make symbol visible to the interpreter
emit (toCType t); emit " ";
if xs.size > 0 then
emit baseName;
emit "(";
if xs.size > closureMaxArgs && isBoxedName d.name then
emit "lean_object** _args"
else
xs.size.forM fun i => do
if i > 0 then emit ", "
let x := xs[i]!
emit (toCType x.ty); emit " "; emit x.x
emit ")"
else
emit ("_init_" ++ baseName ++ "()")
emitLn " {";
if xs.size > closureMaxArgs && isBoxedName d.name then
xs.size.forM fun i => do
let x := xs[i]!
emit "lean_object* "; emit x.x; emit " = _args["; emit i; emitLn "];"
emitLn "_start:";
withReader (fun ctx => { ctx with mainFn := f, mainParams := xs }) (emitFnBody b);
emitLn "}"
| _ => pure ()
def emitDecl (d : Decl) : M Unit := do
let d := d.normalizeIds; -- ensure we don't have gaps in the variable indices
try
emitDeclAux d
catch err =>
throw s!"{err}\ncompiling:\n{d}"
def emitFns : M Unit := do
let env ← getEnv;
let decls := getDecls env;
decls.reverse.forM emitDecl
def emitMarkPersistent (d : Decl) (n : Name) : M Unit := do
if d.resultType.isObj then
emit "lean_mark_persistent("
emitCName n
emitLn ");"
def emitDeclInit (d : Decl) : M Unit := do
let env ← getEnv
let n := d.name
if isIOUnitInitFn env n then
emit "res = "; emitCName n; emitLn "(lean_io_mk_world());"
emitLn "if (lean_io_result_is_error(res)) return res;"
emitLn "lean_dec_ref(res);"
else if d.params.size == 0 then
match getInitFnNameFor? env d.name with
| some initFn =>
if getBuiltinInitFnNameFor? env d.name |>.isSome then
emit "if (builtin) {"
emit "res = "; emitCName initFn; emitLn "(lean_io_mk_world());"
emitLn "if (lean_io_result_is_error(res)) return res;"
emitCName n; emitLn " = lean_io_result_get_value(res);"
emitMarkPersistent d n
emitLn "lean_dec_ref(res);"
if getBuiltinInitFnNameFor? env d.name |>.isSome then
emit "}"
| _ =>
emitCName n; emit " = "; emitCInitName n; emitLn "();"; emitMarkPersistent d n
def emitInitFn : M Unit := do
let env ← getEnv
let modName ← getModName
env.imports.forM fun imp => emitLn ("lean_object* " ++ mkModuleInitializationFunctionName imp.module ++ "(uint8_t builtin, lean_object*);")
emitLns [
"static bool _G_initialized = false;",
"LEAN_EXPORT lean_object* " ++ mkModuleInitializationFunctionName modName ++ "(uint8_t builtin, lean_object* w) {",
"lean_object * res;",
"if (_G_initialized) return lean_io_result_mk_ok(lean_box(0));",
"_G_initialized = true;"
]
env.imports.forM fun imp => emitLns [
"res = " ++ mkModuleInitializationFunctionName imp.module ++ "(builtin, lean_io_mk_world());",
"if (lean_io_result_is_error(res)) return res;",
"lean_dec_ref(res);"]
let decls := getDecls env
decls.reverse.forM emitDeclInit
emitLns ["return lean_io_result_mk_ok(lean_box(0));", "}"]
def main : M Unit := do
emitFileHeader
emitFnDecls
emitFns
emitInitFn
emitMainFnIfNeeded
emitFileFooter
end EmitC
@[export lean_ir_emit_c]
def emitC (env : Environment) (modName : Name) : Except String String :=
match (EmitC.main { env := env, modName := modName }).run "" with
| EStateM.Result.ok _ s => Except.ok s
| EStateM.Result.error err _ => Except.error err
end Lean.IR
|
97e0361d753c7b2c3ef2096890ea1bed6465b672 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/run/nested_rec.lean | ba9a6c6eb8bcc6e35d64cbe4a90d5a769fc04218 | [
"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 | 1,254 | lean | open nat prod sigma
-- We will define the following example by well-foudned recursion
-- g 0 := 0
-- g (succ x) := g (g x)
definition g.F (x : nat) : (Π y, y < x → Σ r : nat, r ≤ y) → Σ r : nat, r ≤ x :=
nat.cases_on x
(λ f, ⟨zero, le.refl zero⟩)
(λ x₁ (f : Π y, y < succ x₁ → Σ r : nat, r ≤ y),
let p₁ := f x₁ (lt.base x₁) in
let gx₁ := pr₁ p₁ in
let p₂ := f gx₁ (lt_of_le_of_lt (pr₂ p₁) (lt.base x₁)) in
let ggx₁ := pr₁ p₂ in
⟨ggx₁, le_succ_of_le (le.trans (pr₂ p₂) (pr₂ p₁))⟩)
definition g (x : nat) : nat :=
pr₁ (well_founded.fix g.F x)
example : g 3 = 0 :=
rfl
example : g 6 = 0 :=
rfl
theorem g_zero : g 0 = 0 :=
rfl
theorem g_succ (a : nat) : g (succ a) = g (g a) :=
have aux : well_founded.fix g.F (succ a) = sigma.mk (g (g a)) _, from
well_founded.fix_eq g.F (succ a),
calc g (succ a) = pr₁ (well_founded.fix g.F (succ a)) : rfl
... = g (g a) : {aux}
theorem g_all_zero (a : nat) : g a = zero :=
nat.induction_on a
g_zero
(λ a₁ (ih : g a₁ = zero), calc
g (succ a₁) = g (g a₁) : g_succ
... = g 0 : ih
... = 0 : g_zero)
|
157f10823b3e969b77dc89f00052a279f2f42f3d | d7189ea2ef694124821b033e533f18905b5e87ef | /galois/subset/subset.lean | 0aefa8214b6e9c30e40310a5d20f1f37d585bf33 | [
"Apache-2.0"
] | permissive | digama0/lean-protocol-support | eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59 | cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda | refs/heads/master | 1,625,421,450,627 | 1,506,035,462,000 | 1,506,035,462,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,886 | lean | import galois.tactic
galois.list.preds
universes u v w
/-- Defines a subset of a type -/
def subset (A : Sort u) := A → Prop
namespace subset
section
parameter {A : Type u}
/-- A subset that is the same for all members of the type -/
def const (P : Prop) : subset A := λ _, P
/-- The subset with all memebers -/
def tt : subset A := const true
/-- The empty subset -/
def ff : subset A := const false
/-- Subset P is included in subset Q if all members of P are also in Q -/
def included (P Q : subset A) := ∀ x : A, P x → Q x
/-- The intersection of two subsets contains all shared members -/
def bintersection (P Q : subset A) := λ x, P x ∧ Q x
/-- The union of two subsets contains all members of both-/
def bunion (P Q : subset A) := λ x, P x ∨ Q x
/-- Lifting of prop implication --/
def tImp {T : Type u} (P Q : subset T) : subset T :=
λ x, P x → Q x
infixr `=>` : 50 := tImp
instance subset_has_union : has_union (subset A)
:= ⟨ bunion ⟩
instance subset_has_inter : has_inter (subset A)
:= ⟨ bintersection ⟩
instance subset_has_le : has_le (subset A):= ⟨ included ⟩
/-- If two subsets include eachother they are the same -/
lemma included_eq {P Q : subset A}
(PQ : P ≤ Q) (QP : Q ≤ P) : P = Q
:= begin
apply funext, intros x, apply propext, split,
apply PQ, apply QP
end
/-- Every set includes itself -/
lemma included_refl (P : subset A)
: P ≤ P := λ _ H, H
/-- Transitivity of inclusion -/
lemma included_trans {P Q R : subset A}
(PQ : P ≤ Q) (QR : Q ≤ R)
: P ≤ R :=
begin
intros x HP, apply QR, apply PQ, assumption
end
/-- Intersection is monotonic, it grows as either of its arguments grows -/
lemma bintersection_mono {P P' Q Q' : subset A}
(HP : P ≤ P') (HQ : Q ≤ Q')
: P ∩ Q ≤ P' ∩ Q'
:= begin
intros x H, induction H with Hl Hr,
constructor, apply HP, assumption,
apply HQ, assumption
end
/-- Union is monotonic, it grows as either of its arguments grows -/
lemma bunion_mono {P P' Q Q' : subset A}
(HP : P ≤ P') (HQ : Q ≤ Q')
: P ∪ Q ≤ P' ∪ Q'
:= begin
intros x H, induction H with Hl Hr,
{ apply or.inl, apply HP, assumption },
{ apply or.inr, apply HQ, assumption }
end
/-- Intersection such that: The intersection of all subsets defined by F -/
def intersection_st (F : subset A → Prop)
: subset A
:= λ x, ∀ P, F P → P x
/-- Union such that: The union of all subsets defined by F -/
inductive union_st (F : subset A → Prop)
(x : A) : Prop
| mk : ∀ P, F P → P x → union_st
def union_st' (F : subset A → Prop) : subset A := union_st F
/-- union_st distributes over and -/
lemma union_st_bintersection {F G : subset A → Prop}
: union_st' (λ x, F x ∧ G x) ≤ union_st' F ∩ union_st' G
:= begin
intros x H,
induction H with P FGP Px,
induction FGP with FP GP,
constructor; constructor; assumption
end
/-- union st is monotone -/
lemma union_st_mono {F G : subset (subset A)}
(H : F ≤ G)
: union_st' F ≤ union_st' G
:= begin
intros x H,
induction H with P FP Px,
constructor, apply H, assumption, assumption
end
/-- Every set is contained in tt -/
lemma tt_top (P : subset A) : P ≤ tt :=
begin intros x H, constructor end
/-- false is contained in every set -/
lemma ff_bot (P : subset A) : ff ≤ P :=
begin intros x H, exfalso, apply H, end
definition from_list' (l : list A) : subset A :=
fun x :A, x ∈ l
/-- Create a subset of items contained in a list -/
inductive from_list : list A → subset A
| here : ∀ {x xs}, (from_list (x :: xs)) x
| there : ∀ {x y xs}, from_list xs y → from_list (x :: xs) y
/-- Union of an indexed set such that : If we have a set of indexes
defined by P, and a mapping from those indexes to subsets defined
by F, this function gives the union of the range of F over P -/
inductive union_ix_st {Ix : Type v} (P : Ix → Prop) (F : Ix → subset A) (x : A) : Prop
| mk : ∀ ix, P ix → F ix x → union_ix_st
/-- Intersection of an indexed set: If we have an indexed collection of
subsets, this is the intersection over the entire range of those subsets -/
def intersection_ix {Ix : Type v} (F : Ix → subset A) : subset A
:= λ x, ∀ ix : Ix, F ix x
/-- Intersection of an indexed set: If we have an indexed collection of
subsets, this is the union over the entire range of those subsets -/
def union_ix {Ix : Type v} (F : Ix → subset A) : subset A :=
union_ix_st (λ _, true) F
/-- If we increase the domain of the indexes, the union of the range increases as well -/
lemma union_ix_st_mono {Ix : Type v} {P Q : subset Ix} {F G : Ix → subset A}
(H1 : P ≤ Q)
(H : ∀ ix : Ix, F ix ≤ G ix)
: @has_le.le _ subset_has_le (union_ix_st P F) (union_ix_st Q G)
:= begin
intros x H,
induction H with P _ FP Px,
constructor, apply H1, assumption, apply H, assumption,
end
/-- If we increase the range of the indexed sets, union ix
of those index sets increases -/
lemma union_ix_mono {Ix : Type v} {F G : Ix → subset A}
(H : ∀ ix : Ix, F ix ≤ G ix)
: union_ix F ≤ union_ix G
:= begin
apply union_ix_st_mono, intros x H', apply H',
assumption
end
lemma intersection_ix_mono {Ix : Type v} {F G : Ix → subset A}
(H : ∀ ix : Ix, F ix ≤ G ix)
: intersection_ix F ≤ intersection_ix G
:= begin
intros x H' ix, apply H, apply H'
end
lemma imp_or (P Q : subset A)
: (P ≤ Q) = (P ∪ Q = Q)
:= begin
apply propext, split; intros H,
{ apply included_eq, intros x H',
induction H' with H' H', apply H, assumption, assumption,
intros x Qx, apply or.inr, assumption },
{ rw ← H, intros x Px, apply or.inl, assumption }
end
lemma imp_and (P Q : subset A)
: (P ≤ Q) = (P = P ∩ Q)
:= begin
apply propext, split; intros H,
{ apply included_eq, intros x Px,
constructor, assumption, apply H, assumption,
intros x PQx, induction PQx with H1 H2,
assumption },
{ rw H, intros x PQx, induction PQx with H1 H2,
assumption }
end
lemma and_distr_l (P Q R : subset A)
: (P ∩ Q) ∪ (P ∩ R) = P ∩ (Q ∪ R)
:= begin
apply included_eq; intros x Hx,
induction Hx with H H, induction H with H H',
constructor, assumption, apply or.inl, assumption,
induction H with H H', constructor, assumption,
apply or.inr, assumption,
induction Hx with H H', induction H' with H' H',
apply or.inl, constructor; assumption,
apply or.inr, constructor; assumption
end
lemma inter_comm (P Q : subset A) : P ∩ Q = Q ∩ P
:= begin
apply funext, intros x, simp [has_inter.inter],
unfold bintersection, rw and_comm,
end
end
lemma intersection_ix_precompose {A : Type u} {B : Type w}
{Ix : Type v} (F : Ix → subset B) (f : A → B)
: intersection_ix F ∘ f = intersection_ix (λ ix, F ix ∘ f)
:= begin
unfold intersection_ix
end
/-- Definition of monotone for unary functions over subsets -/
def monotone {A : Type u} {B : Type v} (F : subset A → subset B) :=
∀ P Q, P ≤ Q → F P ≤ F Q
end subset
|
d445fe1289201770be00bbfbe6dc3777730002ac | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/topology/metric_space/closeds.lean | a1c8c58c7900fee86b1066b1fd9e8c970a400b1e | [
"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 | 21,278 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import topology.metric_space.hausdorff_distance
import topology.compacts
import analysis.specific_limits
/-!
# Closed subsets
This file defines the metric and emetric space structure on the types of closed subsets and nonempty
compact subsets of a metric or emetric space.
The Hausdorff distance induces an emetric space structure on the type of closed subsets
of an emetric space, called `closeds`. Its completeness, resp. compactness, resp.
second-countability, follow from the corresponding properties of the original space.
In a metric space, the type of nonempty compact subsets (called `nonempty_compacts`) also
inherits a metric space structure from the Hausdorff distance, as the Hausdorff edistance is
always finite in this context.
-/
noncomputable theory
open_locale classical topological_space ennreal
universe u
open classical set function topological_space filter
namespace emetric
section
variables {α : Type u} [emetric_space α] {s : set α}
/-- In emetric spaces, the Hausdorff edistance defines an emetric space structure
on the type of closed subsets -/
instance closeds.emetric_space : emetric_space (closeds α) :=
{ edist := λs t, Hausdorff_edist s.val t.val,
edist_self := λs, Hausdorff_edist_self,
edist_comm := λs t, Hausdorff_edist_comm,
edist_triangle := λs t u, Hausdorff_edist_triangle,
eq_of_edist_eq_zero :=
λs t h, subtype.eq ((Hausdorff_edist_zero_iff_eq_of_closed s.property t.property).1 h) }
/-- The edistance to a closed set depends continuously on the point and the set -/
lemma continuous_inf_edist_Hausdorff_edist :
continuous (λp : α × (closeds α), inf_edist p.1 (p.2).val) :=
begin
refine continuous_of_le_add_edist 2 (by simp) _,
rintros ⟨x, s⟩ ⟨y, t⟩,
calc inf_edist x (s.val) ≤ inf_edist x (t.val) + Hausdorff_edist (t.val) (s.val) :
inf_edist_le_inf_edist_add_Hausdorff_edist
... ≤ (inf_edist y (t.val) + edist x y) + Hausdorff_edist (t.val) (s.val) :
add_le_add_right inf_edist_le_inf_edist_add_edist _
... = inf_edist y (t.val) + (edist x y + Hausdorff_edist (s.val) (t.val)) :
by simp [add_comm, add_left_comm, Hausdorff_edist_comm, -subtype.val_eq_coe]
... ≤ inf_edist y (t.val) + (edist (x, s) (y, t) + edist (x, s) (y, t)) :
add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _
... = inf_edist y (t.val) + 2 * edist (x, s) (y, t) :
by rw [← mul_two, mul_comm]
end
/-- Subsets of a given closed subset form a closed set -/
lemma is_closed_subsets_of_is_closed (hs : is_closed s) :
is_closed {t : closeds α | t.val ⊆ s} :=
begin
refine is_closed_of_closure_subset (λt ht x hx, _),
-- t : closeds α, ht : t ∈ closure {t : closeds α | t.val ⊆ s},
-- x : α, hx : x ∈ t.val
-- goal : x ∈ s
have : x ∈ closure s,
{ refine mem_closure_iff.2 (λε εpos, _),
rcases mem_closure_iff.1 ht ε εpos with ⟨u, hu, Dtu⟩,
-- u : closeds α, hu : u ∈ {t : closeds α | t.val ⊆ s}, hu' : edist t u < ε
rcases exists_edist_lt_of_Hausdorff_edist_lt hx Dtu with ⟨y, hy, Dxy⟩,
-- y : α, hy : y ∈ u.val, Dxy : edist x y < ε
exact ⟨y, hu hy, Dxy⟩ },
rwa hs.closure_eq at this,
end
/-- By definition, the edistance on `closeds α` is given by the Hausdorff edistance -/
lemma closeds.edist_eq {s t : closeds α} : edist s t = Hausdorff_edist s.val t.val := rfl
/-- In a complete space, the type of closed subsets is complete for the
Hausdorff edistance. -/
instance closeds.complete_space [complete_space α] : complete_space (closeds α) :=
begin
/- We will show that, if a sequence of sets `s n` satisfies
`edist (s n) (s (n+1)) < 2^{-n}`, then it converges. This is enough to guarantee
completeness, by a standard completeness criterion.
We use the shorthand `B n = 2^{-n}` in ennreal. -/
let B : ℕ → ℝ≥0∞ := λ n, (2⁻¹)^n,
have B_pos : ∀ n, (0:ℝ≥0∞) < B n,
by simp [B, ennreal.pow_pos],
have B_ne_top : ∀ n, B n ≠ ⊤,
by simp [B, ennreal.pow_ne_top],
/- Consider a sequence of closed sets `s n` with `edist (s n) (s (n+1)) < B n`.
We will show that it converges. The limit set is t0 = ⋂n, closure (⋃m≥n, s m).
We will have to show that a point in `s n` is close to a point in `t0`, and a point
in `t0` is close to a point in `s n`. The completeness then follows from a
standard criterion. -/
refine complete_of_convergent_controlled_sequences B B_pos (λs hs, _),
let t0 := ⋂n, closure (⋃m≥n, (s m).val),
let t : closeds α := ⟨t0, is_closed_Inter (λ_, is_closed_closure)⟩,
use t,
-- The inequality is written this way to agree with `edist_le_of_edist_le_geometric_of_tendsto₀`
have I1 : ∀n:ℕ, ∀x ∈ (s n).val, ∃y ∈ t0, edist x y ≤ 2 * B n,
{ /- This is the main difficulty of the proof. Starting from `x ∈ s n`, we want
to find a point in `t0` which is close to `x`. Define inductively a sequence of
points `z m` with `z n = x` and `z m ∈ s m` and `edist (z m) (z (m+1)) ≤ B m`. This is
possible since the Hausdorff distance between `s m` and `s (m+1)` is at most `B m`.
This sequence is a Cauchy sequence, therefore converging as the space is complete, to
a limit which satisfies the required properties. -/
assume n x hx,
obtain ⟨z, hz₀, hz⟩ : ∃ z : Π l, (s (n+l)).val, (z 0:α) = x ∧
∀ k, edist (z k:α) (z (k+1):α) ≤ B n / 2^k,
{ -- We prove existence of the sequence by induction.
have : ∀ (l : ℕ) (z : (s (n+l)).val), ∃ z' : (s (n+l+1)).val, edist (z:α) z' ≤ B n / 2^l,
{ assume l z,
obtain ⟨z', z'_mem, hz'⟩ : ∃ z' ∈ (s (n+l+1)).val, edist (z:α) z' < B n / 2^l,
{ apply exists_edist_lt_of_Hausdorff_edist_lt z.2,
simp only [B, ennreal.inv_pow, div_eq_mul_inv],
rw [← pow_add],
apply hs; simp },
exact ⟨⟨z', z'_mem⟩, le_of_lt hz'⟩ },
use [λ k, nat.rec_on k ⟨x, hx⟩ (λl z, some (this l z)), rfl],
exact λ k, some_spec (this k _) },
-- it follows from the previous bound that `z` is a Cauchy sequence
have : cauchy_seq (λ k, ((z k):α)),
from cauchy_seq_of_edist_le_geometric_two (B n) (B_ne_top n) hz,
-- therefore, it converges
rcases cauchy_seq_tendsto_of_complete this with ⟨y, y_lim⟩,
use y,
-- the limit point `y` will be the desired point, in `t0` and close to our initial point `x`.
-- First, we check it belongs to `t0`.
have : y ∈ t0 := mem_Inter.2 (λk, mem_closure_of_tendsto y_lim
begin
simp only [exists_prop, set.mem_Union, filter.eventually_at_top, set.mem_preimage,
set.preimage_Union],
exact ⟨k, λ m hm, ⟨n+m, zero_add k ▸ add_le_add (zero_le n) hm, (z m).2⟩⟩
end),
use this,
-- Then, we check that `y` is close to `x = z n`. This follows from the fact that `y`
-- is the limit of `z k`, and the distance between `z n` and `z k` has already been estimated.
rw [← hz₀],
exact edist_le_of_edist_le_geometric_two_of_tendsto₀ (B n) hz y_lim },
have I2 : ∀n:ℕ, ∀x ∈ t0, ∃y ∈ (s n).val, edist x y ≤ 2 * B n,
{ /- For the (much easier) reverse inequality, we start from a point `x ∈ t0` and we want
to find a point `y ∈ s n` which is close to `x`.
`x` belongs to `t0`, the intersection of the closures. In particular, it is well
approximated by a point `z` in `⋃m≥n, s m`, say in `s m`. Since `s m` and
`s n` are close, this point is itself well approximated by a point `y` in `s n`,
as required. -/
assume n x xt0,
have : x ∈ closure (⋃m≥n, (s m).val), by apply mem_Inter.1 xt0 n,
rcases mem_closure_iff.1 this (B n) (B_pos n) with ⟨z, hz, Dxz⟩,
-- z : α, Dxz : edist x z < B n,
simp only [exists_prop, set.mem_Union] at hz,
rcases hz with ⟨m, ⟨m_ge_n, hm⟩⟩,
-- m : ℕ, m_ge_n : m ≥ n, hm : z ∈ (s m).val
have : Hausdorff_edist (s m).val (s n).val < B n := hs n m n m_ge_n (le_refl n),
rcases exists_edist_lt_of_Hausdorff_edist_lt hm this with ⟨y, hy, Dzy⟩,
-- y : α, hy : y ∈ (s n).val, Dzy : edist z y < B n
exact ⟨y, hy, calc
edist x y ≤ edist x z + edist z y : edist_triangle _ _ _
... ≤ B n + B n : add_le_add (le_of_lt Dxz) (le_of_lt Dzy)
... = 2 * B n : (two_mul _).symm ⟩ },
-- Deduce from the above inequalities that the distance between `s n` and `t0` is at most `2 B n`.
have main : ∀n:ℕ, edist (s n) t ≤ 2 * B n := λn, Hausdorff_edist_le_of_mem_edist (I1 n) (I2 n),
-- from this, the convergence of `s n` to `t0` follows.
refine tendsto_at_top.2 (λε εpos, _),
have : tendsto (λn, 2 * B n) at_top (𝓝 (2 * 0)),
from ennreal.tendsto.const_mul
(ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 $ by simp [ennreal.one_lt_two])
(or.inr $ by simp),
rw mul_zero at this,
obtain ⟨N, hN⟩ : ∃ N, ∀ b ≥ N, ε > 2 * B b,
from ((tendsto_order.1 this).2 ε εpos).exists_forall_of_at_top,
exact ⟨N, λn hn, lt_of_le_of_lt (main n) (hN n hn)⟩
end
/-- In a compact space, the type of closed subsets is compact. -/
instance closeds.compact_space [compact_space α] : compact_space (closeds α) :=
⟨begin
/- by completeness, it suffices to show that it is totally bounded,
i.e., for all ε>0, there is a finite set which is ε-dense.
start from a set `s` which is ε-dense in α. Then the subsets of `s`
are finitely many, and ε-dense for the Hausdorff distance. -/
refine compact_of_totally_bounded_is_closed (emetric.totally_bounded_iff.2 (λε εpos, _))
is_closed_univ,
rcases exists_between εpos with ⟨δ, δpos, δlt⟩,
rcases emetric.totally_bounded_iff.1
(compact_iff_totally_bounded_complete.1 (@compact_univ α _ _)).1 δ δpos with ⟨s, fs, hs⟩,
-- s : set α, fs : finite s, hs : univ ⊆ ⋃ (y : α) (H : y ∈ s), eball y δ
-- we first show that any set is well approximated by a subset of `s`.
have main : ∀ u : set α, ∃v ⊆ s, Hausdorff_edist u v ≤ δ,
{ assume u,
let v := {x : α | x ∈ s ∧ ∃y∈u, edist x y < δ},
existsi [v, ((λx hx, hx.1) : v ⊆ s)],
refine Hausdorff_edist_le_of_mem_edist _ _,
{ assume x hx,
have : x ∈ ⋃y ∈ s, ball y δ := hs (by simp),
rcases mem_bUnion_iff.1 this with ⟨y, ys, dy⟩,
have : edist y x < δ := by simp at dy; rwa [edist_comm] at dy,
exact ⟨y, ⟨ys, ⟨x, hx, this⟩⟩, le_of_lt dy⟩ },
{ rintros x ⟨hx1, ⟨y, yu, hy⟩⟩,
exact ⟨y, yu, le_of_lt hy⟩ }},
-- introduce the set F of all subsets of `s` (seen as members of `closeds α`).
let F := {f : closeds α | f.val ⊆ s},
use F,
split,
-- `F` is finite
{ apply @finite_of_finite_image _ _ F (λf, f.val),
{ exact subtype.val_injective.inj_on F },
{ refine fs.finite_subsets.subset (λb, _),
simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib],
assume x hx hx',
rwa hx' at hx }},
-- `F` is ε-dense
{ assume u _,
rcases main u.val with ⟨t0, t0s, Dut0⟩,
have : is_closed t0 := (fs.subset t0s).is_compact.is_closed,
let t : closeds α := ⟨t0, this⟩,
have : t ∈ F := t0s,
have : edist u t < ε := lt_of_le_of_lt Dut0 δlt,
apply mem_bUnion_iff.2,
exact ⟨t, ‹t ∈ F›, this⟩ }
end⟩
/-- In an emetric space, the type of non-empty compact subsets is an emetric space,
where the edistance is the Hausdorff edistance -/
instance nonempty_compacts.emetric_space : emetric_space (nonempty_compacts α) :=
{ edist := λs t, Hausdorff_edist s.val t.val,
edist_self := λs, Hausdorff_edist_self,
edist_comm := λs t, Hausdorff_edist_comm,
edist_triangle := λs t u, Hausdorff_edist_triangle,
eq_of_edist_eq_zero := λs t h, subtype.eq $ begin
have : closure (s.val) = closure (t.val) := Hausdorff_edist_zero_iff_closure_eq_closure.1 h,
rwa [s.property.2.is_closed.closure_eq,
t.property.2.is_closed.closure_eq] at this,
end }
/-- `nonempty_compacts.to_closeds` is a uniform embedding (as it is an isometry) -/
lemma nonempty_compacts.to_closeds.uniform_embedding :
uniform_embedding (@nonempty_compacts.to_closeds α _ _) :=
isometry.uniform_embedding $ λx y, rfl
/-- The range of `nonempty_compacts.to_closeds` is closed in a complete space -/
lemma nonempty_compacts.is_closed_in_closeds [complete_space α] :
is_closed (range $ @nonempty_compacts.to_closeds α _ _) :=
begin
have : range nonempty_compacts.to_closeds = {s : closeds α | s.val.nonempty ∧ is_compact s.val},
from range_inclusion _,
rw this,
refine is_closed_of_closure_subset (λs hs, ⟨_, _⟩),
{ -- take a set set t which is nonempty and at a finite distance of s
rcases mem_closure_iff.1 hs ⊤ ennreal.coe_lt_top with ⟨t, ht, Dst⟩,
rw edist_comm at Dst,
-- since `t` is nonempty, so is `s`
exact nonempty_of_Hausdorff_edist_ne_top ht.1 (ne_of_lt Dst) },
{ refine compact_iff_totally_bounded_complete.2 ⟨_, s.property.is_complete⟩,
refine totally_bounded_iff.2 (λε εpos, _),
-- we have to show that s is covered by finitely many eballs of radius ε
-- pick a nonempty compact set t at distance at most ε/2 of s
rcases mem_closure_iff.1 hs (ε/2) (ennreal.half_pos εpos) with ⟨t, ht, Dst⟩,
-- cover this space with finitely many balls of radius ε/2
rcases totally_bounded_iff.1 (compact_iff_totally_bounded_complete.1 ht.2).1 (ε/2)
(ennreal.half_pos εpos) with ⟨u, fu, ut⟩,
refine ⟨u, ⟨fu, λx hx, _⟩⟩,
-- u : set α, fu : finite u, ut : t.val ⊆ ⋃ (y : α) (H : y ∈ u), eball y (ε / 2)
-- then s is covered by the union of the balls centered at u of radius ε
rcases exists_edist_lt_of_Hausdorff_edist_lt hx Dst with ⟨z, hz, Dxz⟩,
rcases mem_bUnion_iff.1 (ut hz) with ⟨y, hy, Dzy⟩,
have : edist x y < ε := calc
edist x y ≤ edist x z + edist z y : edist_triangle _ _ _
... < ε/2 + ε/2 : ennreal.add_lt_add Dxz Dzy
... = ε : ennreal.add_halves _,
exact mem_bUnion hy this },
end
/-- In a complete space, the type of nonempty compact subsets is complete. This follows
from the same statement for closed subsets -/
instance nonempty_compacts.complete_space [complete_space α] :
complete_space (nonempty_compacts α) :=
(complete_space_iff_is_complete_range nonempty_compacts.to_closeds.uniform_embedding).2 $
nonempty_compacts.is_closed_in_closeds.is_complete
/-- In a compact space, the type of nonempty compact subsets is compact. This follows from
the same statement for closed subsets -/
instance nonempty_compacts.compact_space [compact_space α] : compact_space (nonempty_compacts α) :=
⟨begin
rw embedding.compact_iff_compact_image nonempty_compacts.to_closeds.uniform_embedding.embedding,
rw [image_univ],
exact nonempty_compacts.is_closed_in_closeds.compact
end⟩
/-- In a second countable space, the type of nonempty compact subsets is second countable -/
instance nonempty_compacts.second_countable_topology [second_countable_topology α] :
second_countable_topology (nonempty_compacts α) :=
begin
haveI : separable_space (nonempty_compacts α) :=
begin
/- To obtain a countable dense subset of `nonempty_compacts α`, start from
a countable dense subset `s` of α, and then consider all its finite nonempty subsets.
This set is countable and made of nonempty compact sets. It turns out to be dense:
by total boundedness, any compact set `t` can be covered by finitely many small balls, and
approximations in `s` of the centers of these balls give the required finite approximation
of `t`. -/
rcases exists_countable_dense α with ⟨s, cs, s_dense⟩,
let v0 := {t : set α | finite t ∧ t ⊆ s},
let v : set (nonempty_compacts α) := {t : nonempty_compacts α | t.val ∈ v0},
refine ⟨⟨v, ⟨_, _⟩⟩⟩,
{ have : countable (subtype.val '' v),
{ refine (countable_set_of_finite_subset cs).mono (λx hx, _),
rcases (mem_image _ _ _).1 hx with ⟨y, ⟨hy, yx⟩⟩,
rw ← yx,
exact hy },
apply countable_of_injective_of_countable_image _ this,
apply subtype.val_injective.inj_on },
{ refine λt, mem_closure_iff.2 (λε εpos, _),
-- t is a compact nonempty set, that we have to approximate uniformly by a a set in `v`.
rcases exists_between εpos with ⟨δ, δpos, δlt⟩,
-- construct a map F associating to a point in α an approximating point in s, up to δ/2.
have Exy : ∀x, ∃y, y ∈ s ∧ edist x y < δ/2,
{ assume x,
rcases mem_closure_iff.1 (s_dense x) (δ/2) (ennreal.half_pos δpos) with ⟨y, ys, hy⟩,
exact ⟨y, ⟨ys, hy⟩⟩ },
let F := λx, some (Exy x),
have Fspec : ∀x, F x ∈ s ∧ edist x (F x) < δ/2 := λx, some_spec (Exy x),
-- cover `t` with finitely many balls. Their centers form a set `a`
have : totally_bounded t.val := (compact_iff_totally_bounded_complete.1 t.property.2).1,
rcases totally_bounded_iff.1 this (δ/2) (ennreal.half_pos δpos) with ⟨a, af, ta⟩,
-- a : set α, af : finite a, ta : t.val ⊆ ⋃ (y : α) (H : y ∈ a), eball y (δ / 2)
-- replace each center by a nearby approximation in `s`, giving a new set `b`
let b := F '' a,
have : finite b := af.image _,
have tb : ∀x ∈ t.val, ∃y ∈ b, edist x y < δ,
{ assume x hx,
rcases mem_bUnion_iff.1 (ta hx) with ⟨z, za, Dxz⟩,
existsi [F z, mem_image_of_mem _ za],
calc edist x (F z) ≤ edist x z + edist z (F z) : edist_triangle _ _ _
... < δ/2 + δ/2 : ennreal.add_lt_add Dxz (Fspec z).2
... = δ : ennreal.add_halves _ },
-- keep only the points in `b` that are close to point in `t`, yielding a new set `c`
let c := {y ∈ b | ∃x∈t.val, edist x y < δ},
have : finite c := ‹finite b›.subset (λx hx, hx.1),
-- points in `t` are well approximated by points in `c`
have tc : ∀x ∈ t.val, ∃y ∈ c, edist x y ≤ δ,
{ assume x hx,
rcases tb x hx with ⟨y, yv, Dxy⟩,
have : y ∈ c := by simp [c, -mem_image]; exact ⟨yv, ⟨x, hx, Dxy⟩⟩,
exact ⟨y, this, le_of_lt Dxy⟩ },
-- points in `c` are well approximated by points in `t`
have ct : ∀y ∈ c, ∃x ∈ t.val, edist y x ≤ δ,
{ rintros y ⟨hy1, ⟨x, xt, Dyx⟩⟩,
have : edist y x ≤ δ := calc
edist y x = edist x y : edist_comm _ _
... ≤ δ : le_of_lt Dyx,
exact ⟨x, xt, this⟩ },
-- it follows that their Hausdorff distance is small
have : Hausdorff_edist t.val c ≤ δ :=
Hausdorff_edist_le_of_mem_edist tc ct,
have Dtc : Hausdorff_edist t.val c < ε := lt_of_le_of_lt this δlt,
-- the set `c` is not empty, as it is well approximated by a nonempty set
have hc : c.nonempty,
from nonempty_of_Hausdorff_edist_ne_top t.property.1 (ne_top_of_lt Dtc),
-- let `d` be the version of `c` in the type `nonempty_compacts α`
let d : nonempty_compacts α := ⟨c, ⟨hc, ‹finite c›.is_compact⟩⟩,
have : c ⊆ s,
{ assume x hx,
rcases (mem_image _ _ _).1 hx.1 with ⟨y, ⟨ya, yx⟩⟩,
rw ← yx,
exact (Fspec y).1 },
have : d ∈ v := ⟨‹finite c›, this⟩,
-- we have proved that `d` is a good approximation of `t` as requested
exact ⟨d, ‹d ∈ v›, Dtc⟩ },
end,
apply second_countable_of_separable,
end
end --section
end emetric --namespace
namespace metric
section
variables {α : Type u} [metric_space α]
/-- `nonempty_compacts α` inherits a metric space structure, as the Hausdorff
edistance between two such sets is finite. -/
instance nonempty_compacts.metric_space : metric_space (nonempty_compacts α) :=
emetric_space.to_metric_space $ λx y, Hausdorff_edist_ne_top_of_nonempty_of_bounded x.2.1 y.2.1
(bounded_of_compact x.2.2) (bounded_of_compact y.2.2)
/-- The distance on `nonempty_compacts α` is the Hausdorff distance, by construction -/
lemma nonempty_compacts.dist_eq {x y : nonempty_compacts α} :
dist x y = Hausdorff_dist x.val y.val := rfl
lemma lipschitz_inf_dist_set (x : α) :
lipschitz_with 1 (λ s : nonempty_compacts α, inf_dist x s.val) :=
lipschitz_with.of_le_add $ assume s t,
by { rw dist_comm,
exact inf_dist_le_inf_dist_add_Hausdorff_dist (edist_ne_top t s) }
lemma lipschitz_inf_dist :
lipschitz_with 2 (λ p : α × (nonempty_compacts α), inf_dist p.1 p.2.val) :=
@lipschitz_with.uncurry _ _ _ _ _ _ (λ (x : α) (s : nonempty_compacts α), inf_dist x s.val) 1 1
(λ s, lipschitz_inf_dist_pt s.val) lipschitz_inf_dist_set
lemma uniform_continuous_inf_dist_Hausdorff_dist :
uniform_continuous (λp : α × (nonempty_compacts α), inf_dist p.1 (p.2).val) :=
lipschitz_inf_dist.uniform_continuous
end --section
end metric --namespace
|
d3dfa8e3798f974d5101b84d508565f93fdf5137 | f083c4ed5d443659f3ed9b43b1ca5bb037ddeb58 | /data/int/basic.lean | 3ebc5874cb4ffddb419c89675661047f8438246c | [
"Apache-2.0"
] | permissive | semorrison/mathlib | 1be6f11086e0d24180fec4b9696d3ec58b439d10 | 20b4143976dad48e664c4847b75a85237dca0a89 | refs/heads/master | 1,583,799,212,170 | 1,535,634,130,000 | 1,535,730,505,000 | 129,076,205 | 0 | 0 | Apache-2.0 | 1,551,697,998,000 | 1,523,442,265,000 | Lean | UTF-8 | Lean | false | false | 45,056 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The integers, with addition, multiplication, and subtraction.
-/
import data.nat.basic algebra.char_zero algebra.order_functions
open nat
namespace int
instance : inhabited ℤ := ⟨0⟩
meta instance : has_to_format ℤ := ⟨λ z, int.rec_on z (λ k, ↑k) (λ k, "-("++↑k++"+1)")⟩
attribute [simp] int.coe_nat_add int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_succ
@[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl
@[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl
@[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl
theorem coe_nat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := coe_nat_le_coe_nat_iff m n
theorem coe_nat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n := coe_nat_lt_coe_nat_iff m n
theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n := int.coe_nat_eq_coe_nat_iff m n
@[simp] theorem coe_nat_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n :=
by rw [← int.coe_nat_zero, coe_nat_lt]
@[simp] theorem coe_nat_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 :=
by rw [← int.coe_nat_zero, coe_nat_inj']
@[simp] theorem coe_nat_ne_zero {n : ℕ} : (n : ℤ) ≠ 0 ↔ n ≠ 0 :=
not_congr coe_nat_eq_zero
lemma coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := coe_nat_le.2 (zero_le _)
lemma coe_nat_ne_zero_iff_pos {n : ℕ} : (n : ℤ) ≠ 0 ↔ 0 < n :=
⟨λ h, nat.pos_of_ne_zero (coe_nat_ne_zero.1 h),
λ h, (ne_of_lt (coe_nat_lt.2 h)).symm⟩
/- succ and pred -/
/-- Immediate successor of an integer: `succ n = n + 1` -/
def succ (a : ℤ) := a + 1
/-- Immediate predecessor of an integer: `pred n = n - 1` -/
def pred (a : ℤ) := a - 1
theorem nat_succ_eq_int_succ (n : ℕ) : (nat.succ n : ℤ) = int.succ n := rfl
theorem pred_succ (a : ℤ) : pred (succ a) = a := add_sub_cancel _ _
theorem succ_pred (a : ℤ) : succ (pred a) = a := sub_add_cancel _ _
theorem neg_succ (a : ℤ) : -succ a = pred (-a) := neg_add _ _
theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a :=
by rw [neg_succ, succ_pred]
theorem neg_pred (a : ℤ) : -pred a = succ (-a) :=
by rw [eq_neg_of_eq_neg (neg_succ (-a)).symm, neg_neg]
theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a :=
by rw [neg_pred, pred_succ]
theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n
theorem neg_nat_succ (n : ℕ) : -(nat.succ n : ℤ) = pred (-n) := neg_succ n
theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := succ_neg_succ n
theorem lt_succ_self (a : ℤ) : a < succ a :=
lt_add_of_pos_right _ zero_lt_one
theorem pred_self_lt (a : ℤ) : pred a < a :=
sub_lt_self _ zero_lt_one
theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl
theorem lt_add_one_iff {a b : ℤ} : a < b + 1 ↔ a ≤ b :=
@add_le_add_iff_right _ _ a b 1
theorem sub_one_le_iff {a b : ℤ} : a - 1 < b ↔ a ≤ b :=
sub_lt_iff_lt_add.trans lt_add_one_iff
theorem le_sub_one_iff {a b : ℤ} : a ≤ b - 1 ↔ a < b :=
le_sub_iff_add_le
@[elab_as_eliminator] protected lemma induction_on {p : ℤ → Prop}
(i : ℤ) (hz : p 0) (hp : ∀i, p i → p (i + 1)) (hn : ∀i, p i → p (i - 1)) : p i :=
begin
induction i,
{ induction i,
{ exact hz },
{ exact hp _ i_ih } },
{ have : ∀n:ℕ, p (- n),
{ intro n, induction n,
{ simp [hz] },
{ have := hn _ n_ih, simpa } },
exact this (i + 1) }
end
/- nat abs -/
attribute [simp] nat_abs nat_abs_of_nat nat_abs_zero nat_abs_one
theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b :=
begin
have, {
refine (λ a b : ℕ, sub_nat_nat_elim a b.succ
(λ m n i, n = b.succ → nat_abs i ≤ (m + b).succ) _ _ rfl);
intros i n e,
{ subst e, rw [add_comm _ i, add_assoc],
exact nat.le_add_right i (b.succ + b).succ },
{ apply succ_le_succ,
rw [← succ_inj e, ← add_assoc, add_comm],
apply nat.le_add_right } },
cases a; cases b with b b; simp [nat_abs, nat.succ_add];
try {refl}; [skip, rw add_comm a b]; apply this
end
theorem nat_abs_neg_of_nat (n : ℕ) : nat_abs (neg_of_nat n) = n :=
by cases n; refl
theorem nat_abs_mul (a b : ℤ) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) :=
by cases a; cases b; simp [(*), int.mul, nat_abs_neg_of_nat]
theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 :=
by simp [neg_succ_of_nat_eq]
lemma nat_abs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.nat_abs ≠ 0 :=
λ h, hz $ int.eq_zero_of_nat_abs_eq_zero h
/- / -/
@[simp] theorem of_nat_div (m n : ℕ) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl
@[simp] theorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n := rfl
theorem neg_succ_of_nat_div (m : ℕ) {b : ℤ} (H : b > 0) :
-[1+m] / b = -(m / b + 1) :=
match b, eq_succ_of_zero_lt H with ._, ⟨n, rfl⟩ := rfl end
@[simp] protected theorem div_neg : ∀ (a b : ℤ), a / -b = -(a / b)
| (m : ℕ) 0 := show of_nat (m / 0) = -(m / 0 : ℕ), by rw nat.div_zero; refl
| (m : ℕ) (n+1:ℕ) := rfl
| 0 -[1+ n] := rfl
| (m+1:ℕ) -[1+ n] := (neg_neg _).symm
| -[1+ m] 0 := rfl
| -[1+ m] (n+1:ℕ) := rfl
| -[1+ m] -[1+ n] := rfl
theorem div_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : b > 0) : a / b = -((-a - 1) / b + 1) :=
match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ :=
by change (- -[1+ m] : ℤ) with (m+1 : ℤ); rw add_sub_cancel; refl
end
protected theorem div_nonneg {a b : ℤ} (Ha : a ≥ 0) (Hb : b ≥ 0) : a / b ≥ 0 :=
match a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := coe_zero_le _
end
protected theorem div_nonpos {a b : ℤ} (Ha : a ≥ 0) (Hb : b ≤ 0) : a / b ≤ 0 :=
nonpos_of_neg_nonneg $ by rw [← int.div_neg]; exact int.div_nonneg Ha (neg_nonneg_of_nonpos Hb)
theorem div_neg' {a b : ℤ} (Ha : a < 0) (Hb : b > 0) : a / b < 0 :=
match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := neg_succ_lt_zero _
end
@[simp] protected theorem zero_div : ∀ (b : ℤ), 0 / b = 0
| 0 := rfl
| (n+1:ℕ) := rfl
| -[1+ n] := rfl
@[simp] protected theorem div_zero : ∀ (a : ℤ), a / 0 = 0
| 0 := rfl
| (n+1:ℕ) := rfl
| -[1+ n] := rfl
@[simp] protected theorem div_one : ∀ (a : ℤ), a / 1 = a
| 0 := rfl
| (n+1:ℕ) := congr_arg of_nat (nat.div_one _)
| -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _)
theorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 :=
match a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2
end
theorem div_eq_zero_of_lt_abs {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < abs b) : a / b = 0 :=
match b, abs b, abs_eq_nat_abs b, H2 with
| (n : ℕ), ._, rfl, H2 := div_eq_zero_of_lt H1 H2
| -[1+ n], ._, rfl, H2 := neg_inj $ by rw [← int.div_neg]; exact div_eq_zero_of_lt H1 H2
end
protected theorem add_mul_div_right (a b : ℤ) {c : ℤ} (H : c ≠ 0) :
(a + b * c) / c = a / c + b :=
have ∀ {k n : ℕ} {a : ℤ}, (a + n * k.succ) / k.succ = a / k.succ + n, from
λ k n a, match a with
| (m : ℕ) := congr_arg of_nat $ nat.add_mul_div_right _ _ k.succ_pos
| -[1+ m] := show ((n * k.succ:ℕ) - m.succ : ℤ) / k.succ =
n - (m / k.succ + 1 : ℕ), begin
cases lt_or_ge m (n*k.succ) with h h,
{ rw [← int.coe_nat_sub h,
← int.coe_nat_sub ((nat.div_lt_iff_lt_mul _ _ k.succ_pos).2 h)],
apply congr_arg of_nat,
rw [mul_comm, nat.mul_sub_div], rwa mul_comm },
{ change (↑(n * nat.succ k) - (m + 1) : ℤ) / ↑(nat.succ k) =
↑n - ((m / nat.succ k : ℕ) + 1),
rw [← sub_sub, ← sub_sub, ← neg_sub (m:ℤ), ← neg_sub _ (n:ℤ),
← int.coe_nat_sub h,
← int.coe_nat_sub ((nat.le_div_iff_mul_le _ _ k.succ_pos).2 h),
← neg_succ_of_nat_coe', ← neg_succ_of_nat_coe'],
{ apply congr_arg neg_succ_of_nat,
rw [mul_comm, nat.sub_mul_div], rwa mul_comm } }
end
end,
have ∀ {a b c : ℤ}, c > 0 → (a + b * c) / c = a / c + b, from
λ a b c H, match c, eq_succ_of_zero_lt H, b with
| ._, ⟨k, rfl⟩, (n : ℕ) := this
| ._, ⟨k, rfl⟩, -[1+ n] :=
show (a - n.succ * k.succ) / k.succ = (a / k.succ) - n.succ, from
eq_sub_of_add_eq $ by rw [← this, sub_add_cancel]
end,
match lt_trichotomy c 0 with
| or.inl hlt := neg_inj $ by rw [← int.div_neg, neg_add, ← int.div_neg, ← neg_mul_neg];
apply this (neg_pos_of_neg hlt)
| or.inr (or.inl heq) := absurd heq H
| or.inr (or.inr hgt) := this hgt
end
protected theorem add_mul_div_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b ≠ 0) :
(a + b * c) / b = a / b + c :=
by rw [mul_comm, int.add_mul_div_right _ _ H]
@[simp] protected theorem mul_div_cancel (a : ℤ) {b : ℤ} (H : b ≠ 0) : a * b / b = a :=
by have := int.add_mul_div_right 0 a H;
rwa [zero_add, int.zero_div, zero_add] at this
@[simp] protected theorem mul_div_cancel_left {a : ℤ} (b : ℤ) (H : a ≠ 0) : a * b / a = b :=
by rw [mul_comm, int.mul_div_cancel _ H]
@[simp] protected theorem div_self {a : ℤ} (H : a ≠ 0) : a / a = 1 :=
by have := int.mul_div_cancel 1 H; rwa one_mul at this
/- mod -/
theorem of_nat_mod (m n : nat) : (m % n : ℤ) = of_nat (m % n) := rfl
@[simp] theorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n := rfl
theorem neg_succ_of_nat_mod (m : ℕ) {b : ℤ} (bpos : b > 0) :
-[1+m] % b = b - 1 - m % b :=
by rw [sub_sub, add_comm]; exact
match b, eq_succ_of_zero_lt bpos with ._, ⟨n, rfl⟩ := rfl end
@[simp] theorem mod_neg : ∀ (a b : ℤ), a % -b = a % b
| (m : ℕ) n := @congr_arg ℕ ℤ _ _ (λ i, ↑(m % i)) (nat_abs_neg _)
| -[1+ m] n := @congr_arg ℕ ℤ _ _ (λ i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _)
@[simp] theorem mod_abs (a b : ℤ) : a % (abs b) = a % b :=
abs_by_cases (λ i, a % i = a % b) rfl (mod_neg _ _)
@[simp] theorem zero_mod (b : ℤ) : 0 % b = 0 :=
congr_arg of_nat $ nat.zero_mod _
@[simp] theorem mod_zero : ∀ (a : ℤ), a % 0 = a
| (m : ℕ) := congr_arg of_nat $ nat.mod_zero _
| -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _
@[simp] theorem mod_one : ∀ (a : ℤ), a % 1 = 0
| (m : ℕ) := congr_arg of_nat $ nat.mod_one _
| -[1+ m] := show (1 - (m % 1).succ : ℤ) = 0, by rw nat.mod_one; refl
theorem mod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a :=
match a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2)
end
theorem mod_nonneg : ∀ (a : ℤ) {b : ℤ}, b ≠ 0 → a % b ≥ 0
| (m : ℕ) n H := coe_zero_le _
| -[1+ m] n H :=
sub_nonneg_of_le $ coe_nat_le_coe_nat_of_le $ nat.mod_lt _ (nat_abs_pos_of_ne_zero H)
theorem mod_lt_of_pos (a : ℤ) {b : ℤ} (H : b > 0) : a % b < b :=
match a, b, eq_succ_of_zero_lt H with
| (m : ℕ), ._, ⟨n, rfl⟩ := coe_nat_lt_coe_nat_of_lt (nat.mod_lt _ (nat.succ_pos _))
| -[1+ m], ._, ⟨n, rfl⟩ := sub_lt_self _ (coe_nat_lt_coe_nat_of_lt $ nat.succ_pos _)
end
theorem mod_lt (a : ℤ) {b : ℤ} (H : b ≠ 0) : a % b < abs b :=
by rw [← mod_abs]; exact mod_lt_of_pos _ (abs_pos_of_ne_zero H)
theorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[1+ m] :=
begin
rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n:ℤ)],
apply eq_neg_of_eq_neg,
rw [neg_sub, sub_sub_self, add_right_comm],
exact @congr_arg ℕ ℤ _ _ (λi, (i + 1 : ℤ)) (nat.mod_add_div _ _).symm
end
theorem mod_add_div : ∀ (a b : ℤ), a % b + b * (a / b) = a
| (m : ℕ) 0 := congr_arg of_nat (nat.mod_add_div _ _)
| (m : ℕ) (n+1:ℕ) := congr_arg of_nat (nat.mod_add_div _ _)
| 0 -[1+ n] := rfl
| (m+1:ℕ) -[1+ n] := show (_ + -(n+1) * -((m + 1) / (n + 1) : ℕ) : ℤ) = _,
by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _)
| -[1+ m] 0 := by rw [mod_zero, int.div_zero]; refl
| -[1+ m] (n+1:ℕ) := mod_add_div_aux m n.succ
| -[1+ m] -[1+ n] := mod_add_div_aux m n.succ
theorem mod_def (a b : ℤ) : a % b = a - b * (a / b) :=
eq_sub_of_add_eq (mod_add_div _ _)
@[simp] theorem add_mul_mod_self {a b c : ℤ} : (a + b * c) % c = a % c :=
if cz : c = 0 then by rw [cz, mul_zero, add_zero] else
by rw [mod_def, mod_def, int.add_mul_div_right _ _ cz,
mul_add, mul_comm, add_sub_add_right_eq_sub]
@[simp] theorem add_mul_mod_self_left (a b c : ℤ) : (a + b * c) % b = a % b :=
by rw [mul_comm, add_mul_mod_self]
@[simp] theorem add_mod_self {a b : ℤ} : (a + b) % b = a % b :=
by have := add_mul_mod_self_left a b 1; rwa mul_one at this
@[simp] theorem add_mod_self_left {a b : ℤ} : (a + b) % a = b % a :=
by rw [add_comm, add_mod_self]
@[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]
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]
theorem mod_add_cancel_right {m n k : ℤ} (i) : (m + i) % n = (k + i) % n ↔
m % n = k % n :=
⟨λ H, by have := add_mod_eq_add_mod_right (-i) H;
rwa [add_neg_cancel_right, add_neg_cancel_right] at this,
add_mod_eq_add_mod_right _⟩
theorem mod_add_cancel_left {m n k i : ℤ} :
(i + m) % n = (i + k) % n ↔ m % n = k % n :=
by rw [add_comm, add_comm i, mod_add_cancel_right]
theorem mod_sub_cancel_right {m n k : ℤ} (i) : (m - i) % n = (k - i) % n ↔
m % n = k % n :=
mod_add_cancel_right _
theorem mod_eq_mod_iff_mod_sub_eq_zero {m n k : ℤ} : m % n = k % n ↔ (m - k) % n = 0 :=
(mod_sub_cancel_right k).symm.trans $ by simp
@[simp] theorem mul_mod_left (a b : ℤ) : (a * b) % b = 0 :=
by rw [← zero_add (a * b), add_mul_mod_self, zero_mod]
@[simp] theorem mul_mod_right (a b : ℤ) : (a * b) % a = 0 :=
by rw [mul_comm, mul_mod_left]
@[simp] theorem mod_self {a : ℤ} : a % a = 0 :=
by have := mul_mod_left 1 a; rwa one_mul at this
@[simp] lemma mod_mod (a b : ℤ) : a % b % b = a % b :=
by conv {to_rhs, rw [← mod_add_div a b, add_mul_mod_self_left]}
/- properties of / and % -/
@[simp] theorem mul_div_mul_of_pos {a : ℤ} (b c : ℤ) (H : a > 0) : a * b / (a * c) = b / c :=
suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k, from
match a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with
| ._, ⟨m, rfl⟩, ._, ⟨k, or.inl rfl⟩ := this _ _ _
| ._, ⟨m, rfl⟩, ._, ⟨k, or.inr rfl⟩ :=
by rw [← neg_mul_eq_mul_neg, int.div_neg, int.div_neg];
apply congr_arg has_neg.neg; apply this
end,
λ m k b, match b, k with
| (n : ℕ), k := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos)
| -[1+ n], 0 := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero]
| -[1+ n], k+1 := congr_arg neg_succ_of_nat $
show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin
apply nat.div_eq_of_lt_le,
{ refine le_trans _ (nat.le_add_right _ _),
rw [← nat.mul_div_mul _ _ m.succ_pos],
apply nat.div_mul_le_self },
{ change m.succ * n.succ ≤ _,
rw [mul_left_comm],
apply nat.mul_le_mul_left,
apply (nat.div_lt_iff_lt_mul _ _ k.succ_pos).1,
apply nat.lt_succ_self }
end
end
@[simp] theorem mul_div_mul_of_pos_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b > 0) :
a * b / (c * b) = a / c :=
by rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H]
@[simp] theorem mul_mod_mul_of_pos {a : ℤ} (b c : ℤ) (H : a > 0) : a * b % (a * c) = a * (b % c) :=
by rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc]
theorem lt_div_add_one_mul_self (a : ℤ) {b : ℤ} (H : b > 0) : a < (a / b + 1) * b :=
by rw [add_mul, one_mul, mul_comm]; apply lt_add_of_sub_left_lt;
rw [← mod_def]; apply mod_lt_of_pos _ H
theorem abs_div_le_abs : ∀ (a b : ℤ), abs (a / b) ≤ abs a :=
suffices ∀ (a : ℤ) (n : ℕ), abs (a / n) ≤ abs a, from
λ a b, match b, eq_coe_or_neg b with
| ._, ⟨n, or.inl rfl⟩ := this _ _
| ._, ⟨n, or.inr rfl⟩ := by rw [int.div_neg, abs_neg]; apply this
end,
λ a n, by rw [abs_eq_nat_abs, abs_eq_nat_abs]; exact
coe_nat_le_coe_nat_of_le (match a, n with
| (m : ℕ), n := nat.div_le_self _ _
| -[1+ m], 0 := nat.zero_le _
| -[1+ m], n+1 := nat.succ_le_succ (nat.div_le_self _ _)
end)
theorem div_le_self {a : ℤ} (b : ℤ) (Ha : a ≥ 0) : a / b ≤ a :=
by have := le_trans (le_abs_self _) (abs_div_le_abs a b);
rwa [abs_of_nonneg Ha] at this
theorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a :=
by have := mod_add_div a b; rwa [H, zero_add] at this
theorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a :=
by rw [mul_comm, mul_div_cancel_of_mod_eq_zero H]
/- dvd -/
theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n :=
⟨λ ⟨a, ae⟩, m.eq_zero_or_pos.elim
(λm0, by simp [m0] at ae; simp [ae, m0])
(λm0l, by {
cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_left ℤ _ m a
(by simp [ae.symm]) (by simpa using m0l)) with k e,
subst a, exact ⟨k, int.coe_nat_inj ae⟩ }),
λ ⟨k, e⟩, dvd.intro k $ by rw [e, int.coe_nat_mul]⟩
theorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.nat_abs :=
by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
theorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.nat_abs ∣ n :=
by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
theorem dvd_antisymm {a b : ℤ} (H1 : a ≥ 0) (H2 : b ≥ 0) : a ∣ b → b ∣ a → a = b :=
begin
rw [← abs_of_nonneg H1, ← abs_of_nonneg H2, abs_eq_nat_abs, abs_eq_nat_abs],
rw [coe_nat_dvd, coe_nat_dvd, coe_nat_inj'],
apply nat.dvd_antisymm
end
theorem dvd_of_mod_eq_zero {a b : ℤ} (H : b % a = 0) : a ∣ b :=
⟨b / a, (mul_div_cancel_of_mod_eq_zero H).symm⟩
theorem mod_eq_zero_of_dvd : ∀ {a b : ℤ}, a ∣ b → b % a = 0
| a ._ ⟨c, rfl⟩ := mul_mod_right _ _
theorem dvd_iff_mod_eq_zero (a b : ℤ) : a ∣ b ↔ b % a = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
theorem nat_abs_dvd {a b : ℤ} : (a.nat_abs : ℤ) ∣ b ↔ a ∣ b :=
(nat_abs_eq a).elim (λ e, by rw ← e) (λ e, by rw [← neg_dvd_iff_dvd, ← e])
theorem dvd_nat_abs {a b : ℤ} : a ∣ b.nat_abs ↔ a ∣ b :=
(nat_abs_eq b).elim (λ e, by rw ← e) (λ e, by rw [← dvd_neg_iff_dvd, ← e])
instance decidable_dvd : @decidable_rel ℤ (∣) :=
assume a n, decidable_of_decidable_of_iff (by apply_instance) (dvd_iff_mod_eq_zero _ _).symm
protected theorem div_mul_cancel {a b : ℤ} (H : b ∣ a) : a / b * b = a :=
div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H)
protected theorem mul_div_cancel' {a b : ℤ} (H : a ∣ b) : a * (b / a) = b :=
by rw [mul_comm, int.div_mul_cancel H]
protected theorem mul_div_assoc (a : ℤ) : ∀ {b c : ℤ}, c ∣ b → (a * b) / c = a * (b / c)
| ._ c ⟨d, rfl⟩ := if cz : c = 0 then by simp [cz] else
by rw [mul_left_comm, int.mul_div_cancel_left _ cz, int.mul_div_cancel_left _ cz]
theorem div_dvd_div : ∀ {a b c : ℤ} (H1 : a ∣ b) (H2 : b ∣ c), b / a ∣ c / a
| a ._ ._ ⟨b, rfl⟩ ⟨c, rfl⟩ := if az : a = 0 then by simp [az] else
by rw [int.mul_div_cancel_left _ az, mul_assoc, int.mul_div_cancel_left _ az];
apply dvd_mul_right
protected theorem eq_mul_of_div_eq_right {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) :
a = b * c :=
by rw [← H2, int.mul_div_cancel' H1]
protected theorem div_eq_of_eq_mul_right {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = b * c) :
a / b = c :=
by rw [H2, int.mul_div_cancel_left _ H1]
protected theorem div_eq_iff_eq_mul_right {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
a / b = c ↔ a = b * c :=
⟨int.eq_mul_of_div_eq_right H', int.div_eq_of_eq_mul_right H⟩
protected theorem div_eq_iff_eq_mul_left {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
a / b = c ↔ a = c * b :=
by rw mul_comm; exact int.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, int.eq_mul_of_div_eq_right H1 H2]
protected theorem div_eq_of_eq_mul_left {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = c * b) :
a / b = c :=
int.div_eq_of_eq_mul_right H1 (by rw [mul_comm, H2])
theorem neg_div_of_dvd : ∀ {a b : ℤ} (H : b ∣ a), -a / b = -(a / b)
| ._ b ⟨c, rfl⟩ := if bz : b = 0 then by simp [bz] else
by rw [neg_mul_eq_mul_neg, int.mul_div_cancel_left _ bz, int.mul_div_cancel_left _ bz]
theorem div_sign : ∀ a b, a / sign b = a * sign b
| a (n+1:ℕ) := by unfold sign; simp
| a 0 := by simp [sign]
| a -[1+ n] := by simp [sign]
@[simp] theorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b
| a 0 := by simp
| 0 b := by simp
| (m+1:ℕ) (n+1:ℕ) := rfl
| (m+1:ℕ) -[1+ n] := rfl
| -[1+ m] (n+1:ℕ) := rfl
| -[1+ m] -[1+ n] := rfl
protected theorem sign_eq_div_abs (a : ℤ) : sign a = a / (abs a) :=
if az : a = 0 then by simp [az] else
(int.div_eq_of_eq_mul_left (mt eq_zero_of_abs_eq_zero az)
(sign_mul_abs _).symm).symm
theorem mul_sign : ∀ (i : ℤ), i * sign i = nat_abs i
| (n+1:ℕ) := mul_one _
| 0 := mul_zero _
| -[1+ n] := mul_neg_one _
theorem le_of_dvd {a b : ℤ} (bpos : b > 0) (H : a ∣ b) : a ≤ b :=
match a, b, eq_succ_of_zero_lt bpos, H with
| (m : ℕ), ._, ⟨n, rfl⟩, H := coe_nat_le_coe_nat_of_le $
nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H
| -[1+ m], ._, ⟨n, rfl⟩, _ :=
le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _)
end
theorem eq_one_of_dvd_one {a : ℤ} (H : a ≥ 0) (H' : a ∣ 1) : a = 1 :=
match a, eq_coe_of_zero_le H, H' with
| ._, ⟨n, rfl⟩, H' := congr_arg coe $
nat.eq_one_of_dvd_one $ coe_nat_dvd.1 H'
end
theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : a ≥ 0) (H' : a * b = 1) : a = 1 :=
eq_one_of_dvd_one H ⟨b, H'.symm⟩
theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : b ≥ 0) (H' : a * b = 1) : b = 1 :=
eq_one_of_mul_eq_one_right H (by rw [mul_comm, H'])
lemma of_nat_dvd_of_dvd_nat_abs {a : ℕ} : ∀ {z : ℤ} (haz : a ∣ z.nat_abs), ↑a ∣ z
| (int.of_nat _) haz := int.coe_nat_dvd.2 haz
| -[1+k] haz :=
begin
change ↑a ∣ -(k+1 : ℤ),
apply dvd_neg_of_dvd,
apply int.coe_nat_dvd.2,
exact haz
end
lemma dvd_nat_abs_of_of_nat_dvd {a : ℕ} : ∀ {z : ℤ} (haz : ↑a ∣ z), a ∣ z.nat_abs
| (int.of_nat _) haz := int.coe_nat_dvd.1 (int.dvd_nat_abs.2 haz)
| -[1+k] haz :=
have haz' : (↑a:ℤ) ∣ (↑(k+1):ℤ), from dvd_of_dvd_neg haz,
int.coe_nat_dvd.1 haz'
lemma pow_div_of_le_of_pow_div_int {p m n : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) :
↑(p ^ m) ∣ k :=
begin
induction k,
{ apply int.coe_nat_dvd.2,
apply pow_div_of_le_of_pow_div hmn,
apply int.coe_nat_dvd.1 hdiv },
{ change -[1+k] with -(↑(k+1) : ℤ),
apply dvd_neg_of_dvd,
apply int.coe_nat_dvd.2,
apply pow_div_of_le_of_pow_div hmn,
apply int.coe_nat_dvd.1,
apply dvd_of_dvd_neg,
exact hdiv }
end
/- / and ordering -/
protected theorem div_mul_le (a : ℤ) {b : ℤ} (H : b ≠ 0) : a / b * b ≤ a :=
le_of_sub_nonneg $ by rw [mul_comm, ← mod_def]; apply mod_nonneg _ H
protected theorem div_le_of_le_mul {a b c : ℤ} (H : c > 0) (H' : a ≤ b * c) : a / c ≤ b :=
le_of_mul_le_mul_right (le_trans (int.div_mul_le _ (ne_of_gt H)) H') H
protected theorem mul_lt_of_lt_div {a b c : ℤ} (H : c > 0) (H3 : a < b / c) : a * c < b :=
lt_of_not_ge $ mt (int.div_le_of_le_mul H) (not_le_of_gt H3)
protected theorem mul_le_of_le_div {a b c : ℤ} (H1 : c > 0) (H2 : a ≤ b / c) : a * c ≤ b :=
le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le _ (ne_of_gt H1))
protected theorem le_div_of_mul_le {a b c : ℤ} (H1 : c > 0) (H2 : a * c ≤ b) : a ≤ b / c :=
le_of_lt_add_one $ lt_of_mul_lt_mul_right
(lt_of_le_of_lt H2 (lt_div_add_one_mul_self _ H1)) (le_of_lt H1)
protected theorem le_div_iff_mul_le {a b c : ℤ} (H : c > 0) : a ≤ b / c ↔ a * c ≤ b :=
⟨int.mul_le_of_le_div H, int.le_div_of_mul_le H⟩
protected theorem div_le_div {a b c : ℤ} (H : c > 0) (H' : a ≤ b) : a / c ≤ b / c :=
int.le_div_of_mul_le H (le_trans (int.div_mul_le _ (ne_of_gt H)) H')
protected theorem div_lt_of_lt_mul {a b c : ℤ} (H : c > 0) (H' : a < b * c) : a / c < b :=
lt_of_not_ge $ mt (int.mul_le_of_le_div H) (not_le_of_gt H')
protected theorem lt_mul_of_div_lt {a b c : ℤ} (H1 : c > 0) (H2 : a / c < b) : a < b * c :=
lt_of_not_ge $ mt (int.le_div_of_mul_le H1) (not_le_of_gt H2)
protected theorem div_lt_iff_lt_mul {a b c : ℤ} (H : c > 0) : a / c < b ↔ a < b * c :=
⟨int.lt_mul_of_div_lt H, int.div_lt_of_lt_mul H⟩
protected theorem le_mul_of_div_le {a b c : ℤ} (H1 : b ≥ 0) (H2 : b ∣ a) (H3 : a / b ≤ c) :
a ≤ c * b :=
by rw [← int.div_mul_cancel H2]; exact mul_le_mul_of_nonneg_right H3 H1
protected theorem lt_div_of_mul_lt {a b c : ℤ} (H1 : b ≥ 0) (H2 : b ∣ c) (H3 : a * b < c) :
a < c / b :=
lt_of_not_ge $ mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3)
protected theorem lt_div_iff_mul_lt {a b : ℤ} (c : ℤ) (H : c > 0) (H' : c ∣ b) :
a < b / c ↔ a * c < b :=
⟨int.mul_lt_of_lt_div H, int.lt_div_of_mul_lt (le_of_lt H) H'⟩
theorem div_pos_of_pos_of_dvd {a b : ℤ} (H1 : a > 0) (H2 : b ≥ 0) (H3 : b ∣ a) : a / b > 0 :=
int.lt_div_of_mul_lt H2 H3 (by rwa zero_mul)
theorem div_eq_div_of_mul_eq_mul {a b c d : ℤ} (H1 : b ∣ a) (H2 : d ∣ c) (H3 : b ≠ 0)
(H4 : d ≠ 0) (H5 : a * d = b * c) :
a / b = c / d :=
int.div_eq_of_eq_mul_right H3 $
by rw [← int.mul_div_assoc _ H2]; exact
(int.div_eq_of_eq_mul_left H4 H5.symm).symm
theorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0) (hbc : b ∣ c)
(h : b * a = c * d) : a = c / b * d :=
begin
cases hbc with k hk,
subst hk,
rw int.mul_div_cancel_left, rw mul_assoc at h,
apply _root_.eq_of_mul_eq_mul_left _ h,
repeat {assumption}
end
theorem of_nat_add_neg_succ_of_nat_of_lt {m n : ℕ}
(h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] :=
begin
change sub_nat_nat _ _ = _,
have h' : n.succ - m = (n - m).succ,
apply succ_sub,
apply le_of_lt_succ h,
simp [*, sub_nat_nat]
end
theorem of_nat_add_neg_succ_of_nat_of_ge {m n : ℕ}
(h : m ≥ n.succ) : of_nat m + -[1+n] = of_nat (m - n.succ) :=
begin
change sub_nat_nat _ _ = _,
have h' : n.succ - m = 0,
apply sub_eq_zero_of_le h,
simp [*, sub_nat_nat]
end
@[simp] theorem neg_add_neg (m n : ℕ) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl
/- to_nat -/
theorem to_nat_eq_max : ∀ (a : ℤ), (to_nat a : ℤ) = max a 0
| (n : ℕ) := (max_eq_left (coe_zero_le n)).symm
| -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm
@[simp] theorem to_nat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (to_nat a : ℤ) = a :=
by rw [to_nat_eq_max, max_eq_left h]
@[simp] theorem to_nat_coe_nat (n : ℕ) : to_nat ↑n = n := rfl
theorem le_to_nat (a : ℤ) : a ≤ to_nat a :=
by rw [to_nat_eq_max]; apply le_max_left
@[simp] theorem to_nat_le (a : ℤ) (n : ℕ) : to_nat a ≤ n ↔ a ≤ n :=
by rw [(coe_nat_le_coe_nat_iff _ _).symm, to_nat_eq_max, max_le_iff];
exact and_iff_left (coe_zero_le _)
def to_nat' : ℤ → option ℕ
| (n : ℕ) := some n
| -[1+ n] := none
theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n
| (m : ℕ) n := option.some_inj.trans coe_nat_inj'.symm
| -[1+ m] n := by split; intro h; cases h
/- units -/
@[simp] theorem units_nat_abs (u : units ℤ) : nat_abs u = 1 :=
units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹,
by rw [← nat_abs_mul, units.mul_inv]; refl,
by rw [← nat_abs_mul, units.inv_mul]; refl⟩
theorem units_eq_one_or (u : units ℤ) : u = 1 ∨ u = -1 :=
by simpa [units.ext_iff, units_nat_abs] using nat_abs_eq u
/- bitwise ops -/
@[simp] lemma bodd_zero : bodd 0 = ff := rfl
@[simp] lemma bodd_one : bodd 1 = tt := rfl
@[simp] lemma bodd_two : bodd 2 = ff := rfl
@[simp] lemma bodd_sub_nat_nat (m n : ℕ) : bodd (sub_nat_nat m n) = bxor m.bodd n.bodd :=
by apply sub_nat_nat_elim m n (λ m n i, bodd i = bxor m.bodd n.bodd);
intros i m; simp [bodd]; cases i.bodd; cases m.bodd; refl
@[simp] lemma bodd_neg_of_nat (n : ℕ) : bodd (neg_of_nat n) = n.bodd :=
by cases n; simp; refl
@[simp] lemma bodd_neg (n : ℤ) : bodd (-n) = bodd n :=
by cases n; unfold has_neg.neg; simp [int.coe_nat_eq, int.neg, bodd]
@[simp] lemma bodd_add (m n : ℤ) : bodd (m + n) = bxor (bodd m) (bodd n) :=
by cases m with m m; cases n with n n; unfold has_add.add; simp [int.add, bodd];
cases m.bodd; cases n.bodd; refl
@[simp] lemma bodd_mul (m n : ℤ) : bodd (m * n) = bodd m && bodd n :=
by cases m with m m; cases n with n n; unfold has_mul.mul; simp [int.mul, bodd];
cases m.bodd; cases n.bodd; refl
theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
| (n : ℕ) :=
by rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ),
by cases bodd n; refl]; exact congr_arg of_nat n.bodd_add_div2
| -[1+ n] := begin
refine eq.trans _ (congr_arg neg_succ_of_nat n.bodd_add_div2),
dsimp [bodd], cases nat.bodd n; dsimp [cond, bnot, div2, int.mul],
{ change -[1+ 2 * nat.div2 n] = _, rw zero_add },
{ rw [zero_add, add_comm], refl }
end
theorem div2_val : ∀ n, div2 n = n / 2
| (n : ℕ) := congr_arg of_nat n.div2_val
| -[1+ n] := congr_arg neg_succ_of_nat n.div2_val
lemma bit0_val (n : ℤ) : bit0 n = 2 * n := (two_mul _).symm
lemma bit1_val (n : ℤ) : bit1 n = 2 * n + 1 := congr_arg (+(1:ℤ)) (bit0_val _)
lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 :=
by { cases b, apply (bit0_val n).trans (add_zero _).symm, apply bit1_val }
lemma bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans $ (add_comm _ _).trans $ bodd_add_div2 _
def {u} bit_cases_on {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n :=
by rw [← bit_decomp n]; apply h
@[simp] lemma bit_zero : bit ff 0 = 0 := rfl
@[simp] lemma bit_coe_nat (b) (n : ℕ) : bit b n = nat.bit b n :=
by rw [bit_val, nat.bit_val]; cases b; refl
@[simp] lemma bit_neg_succ (b) (n : ℕ) : bit b -[1+ n] = -[1+ nat.bit (bnot b) n] :=
by rw [bit_val, nat.bit_val]; cases b; refl
@[simp] lemma bodd_bit (b n) : bodd (bit b n) = b :=
by rw bit_val; simp; cases b; cases bodd n; refl
@[simp] lemma div2_bit (b n) : div2 (bit b n) = n :=
begin
rw [bit_val, div2_val, add_comm, int.add_mul_div_left, (_ : (_/2:ℤ) = 0), zero_add],
cases b, all_goals {exact dec_trivial}
end
@[simp] lemma test_bit_zero (b) : ∀ n, test_bit (bit b n) 0 = b
| (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_zero
| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_zero];
clear test_bit_zero; cases b; refl
@[simp] lemma test_bit_succ (m b) : ∀ n, test_bit (bit b n) (nat.succ m) = test_bit n m
| (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_succ
| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_succ]
private meta def bitwise_tac : tactic unit := `[
funext m,
funext n,
cases m with m m; cases n with n n; try {refl},
all_goals {
apply congr_arg of_nat <|> apply congr_arg neg_succ_of_nat,
try {dsimp [nat.land, nat.ldiff, nat.lor]},
try {rw [
show nat.bitwise (λ a b, a && bnot b) n m =
nat.bitwise (λ a b, b && bnot a) m n, from
congr_fun (congr_fun (@nat.bitwise_swap (λ a b, b && bnot a) rfl) n) m]},
apply congr_arg (λ f, nat.bitwise f m n),
funext a,
funext b,
cases a; cases b; refl
},
all_goals {unfold nat.land nat.ldiff nat.lor}
]
theorem bitwise_or : bitwise bor = lor := by bitwise_tac
theorem bitwise_and : bitwise band = land := by bitwise_tac
theorem bitwise_diff : bitwise (λ a b, a && bnot b) = ldiff := by bitwise_tac
theorem bitwise_xor : bitwise bxor = lxor := by bitwise_tac
@[simp] lemma bitwise_bit (f : bool → bool → bool) (a m b n) :
bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=
begin
cases m with m m; cases n with n n;
repeat { rw [← int.coe_nat_eq] <|> rw bit_coe_nat <|> rw bit_neg_succ };
unfold bitwise nat_bitwise bnot;
[ induction h : f ff ff,
induction h : f ff tt,
induction h : f tt ff,
induction h : f tt tt ],
all_goals {
unfold cond, rw nat.bitwise_bit,
repeat { rw bit_coe_nat <|> rw bit_neg_succ <|> rw bnot_bnot } },
all_goals { unfold bnot {fail_if_unchanged := ff}; rw h; refl }
end
@[simp] lemma lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) :=
by rw [← bitwise_or, bitwise_bit]
@[simp] lemma land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) :=
by rw [← bitwise_and, bitwise_bit]
@[simp] lemma ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) :=
by rw [← bitwise_diff, bitwise_bit]
@[simp] lemma lxor_bit (a m b n) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) :=
by rw [← bitwise_xor, bitwise_bit]
@[simp] lemma lnot_bit (b) : ∀ n, lnot (bit b n) = bit (bnot b) (lnot n)
| (n : ℕ) := by simp [lnot]
| -[1+ n] := by simp [lnot]
@[simp] lemma test_bit_bitwise (f : bool → bool → bool) (m n k) :
test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=
begin
induction k with k IH generalizing m n;
apply bit_cases_on m; intros a m';
apply bit_cases_on n; intros b n';
rw bitwise_bit,
{ simp [test_bit_zero] },
{ simp [test_bit_succ, IH] }
end
@[simp] lemma test_bit_lor (m n k) : test_bit (lor m n) k = test_bit m k || test_bit n k :=
by rw [← bitwise_or, test_bit_bitwise]
@[simp] lemma test_bit_land (m n k) : test_bit (land m n) k = test_bit m k && test_bit n k :=
by rw [← bitwise_and, test_bit_bitwise]
@[simp] lemma test_bit_ldiff (m n k) : test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) :=
by rw [← bitwise_diff, test_bit_bitwise]
@[simp] lemma test_bit_lxor (m n k) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) :=
by rw [← bitwise_xor, test_bit_bitwise]
@[simp] lemma test_bit_lnot : ∀ n k, test_bit (lnot n) k = bnot (test_bit n k)
| (n : ℕ) k := by simp [lnot, test_bit]
| -[1+ n] k := by simp [lnot, test_bit]
lemma shiftl_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), shiftl m (n + k) = shiftl (shiftl m n) k
| (m : ℕ) n (k:ℕ) := congr_arg of_nat (nat.shiftl_add _ _ _)
| -[1+ m] n (k:ℕ) := congr_arg neg_succ_of_nat (nat.shiftl'_add _ _ _ _)
| (m : ℕ) n -[1+k] := sub_nat_nat_elim n k.succ
(λ n k i, shiftl ↑m i = nat.shiftr (nat.shiftl m n) k)
(λ i n, congr_arg coe $
by rw [← nat.shiftl_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
(λ i n, congr_arg coe $
by rw [add_assoc, nat.shiftr_add, ← nat.shiftl_sub, nat.sub_self]; refl)
| -[1+ m] n -[1+k] := sub_nat_nat_elim n k.succ
(λ n k i, shiftl -[1+ m] i = -[1+ nat.shiftr (nat.shiftl' tt m n) k])
(λ i n, congr_arg neg_succ_of_nat $
by rw [← nat.shiftl'_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
(λ i n, congr_arg neg_succ_of_nat $
by rw [add_assoc, nat.shiftr_add, ← nat.shiftl'_sub, nat.sub_self]; refl)
lemma shiftl_sub (m : ℤ) (n : ℕ) (k : ℤ) : shiftl m (n - k) = shiftr (shiftl m n) k :=
shiftl_add _ _ _
@[simp] lemma shiftl_neg (m n : ℤ) : shiftl m (-n) = shiftr m n := rfl
@[simp] lemma shiftr_neg (m n : ℤ) : shiftr m (-n) = shiftl m n := by rw [← shiftl_neg, neg_neg]
@[simp] lemma shiftl_coe_nat (m n : ℕ) : shiftl m n = nat.shiftl m n := rfl
@[simp] lemma shiftr_coe_nat (m n : ℕ) : shiftr m n = nat.shiftr m n := by cases n; refl
@[simp] lemma shiftl_neg_succ (m n : ℕ) : shiftl -[1+ m] n = -[1+ nat.shiftl' tt m n] := rfl
@[simp] lemma shiftr_neg_succ (m n : ℕ) : shiftr -[1+ m] n = -[1+ nat.shiftr m n] := by cases n; refl
lemma shiftr_add : ∀ (m : ℤ) (n k : ℕ), shiftr m (n + k) = shiftr (shiftr m n) k
| (m : ℕ) n k := by rw [shiftr_coe_nat, shiftr_coe_nat,
← int.coe_nat_add, shiftr_coe_nat, nat.shiftr_add]
| -[1+ m] n k := by rw [shiftr_neg_succ, shiftr_neg_succ,
← int.coe_nat_add, shiftr_neg_succ, nat.shiftr_add]
lemma shiftl_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), shiftl m n = m * ↑(2 ^ n)
| (m : ℕ) n := congr_arg coe (nat.shiftl_eq_mul_pow _ _)
| -[1+ m] n := @congr_arg ℕ ℤ _ _ (λi, -i) (nat.shiftl'_tt_eq_mul_pow _ _)
lemma shiftr_eq_div_pow : ∀ (m : ℤ) (n : ℕ), shiftr m n = m / ↑(2 ^ n)
| (m : ℕ) n := by rw shiftr_coe_nat; exact congr_arg coe (nat.shiftr_eq_div_pow _ _)
| -[1+ m] n := begin
rw [shiftr_neg_succ, neg_succ_of_nat_div, nat.shiftr_eq_div_pow], refl,
exact coe_nat_lt_coe_nat_of_lt (nat.pos_pow_of_pos _ dec_trivial)
end
lemma one_shiftl (n : ℕ) : shiftl 1 n = (2 ^ n : ℕ) :=
congr_arg coe (nat.one_shiftl _)
@[simp] lemma zero_shiftl : ∀ n : ℤ, shiftl 0 n = 0
| (n : ℕ) := congr_arg coe (nat.zero_shiftl _)
| -[1+ n] := congr_arg coe (nat.zero_shiftr _)
@[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := zero_shiftl _
/- Least upper bound property for integers -/
theorem exists_least_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → b ≤ z)
(Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ (∀ z : ℤ, P z → lb ≤ z) :=
let ⟨b, Hb⟩ := Hbdd in
have EX : ∃ n : ℕ, P (b + n), from
let ⟨elt, Helt⟩ := Hinh in
match elt, le.dest (Hb _ Helt), Helt with
| ._, ⟨n, rfl⟩, Hn := ⟨n, Hn⟩
end,
⟨b + (nat.find EX : ℤ), nat.find_spec EX, λ z h,
match z, le.dest (Hb _ h), h with
| ._, ⟨n, rfl⟩, h := add_le_add_left
(int.coe_nat_le.2 $ nat.find_min' _ h) _
end⟩
theorem exists_greatest_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → z ≤ b)
(Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ (∀ z : ℤ, P z → z ≤ ub) :=
have Hbdd' : ∃ (b : ℤ), ∀ (z : ℤ), P (-z) → b ≤ z, from
let ⟨b, Hb⟩ := Hbdd in ⟨-b, λ z h, neg_le.1 (Hb _ h)⟩,
have Hinh' : ∃ z : ℤ, P (-z), from
let ⟨elt, Helt⟩ := Hinh in ⟨-elt, by rw [neg_neg]; exact Helt⟩,
let ⟨lb, Plb, al⟩ := exists_least_of_bdd Hbdd' Hinh' in
⟨-lb, Plb, λ z h, le_neg.1 $ al _ $ by rwa neg_neg⟩
/- cast (injection into groups with one) -/
@[simp] theorem nat_cast_eq_coe_nat : ∀ n,
@coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ nat.cast_coe)) n =
@coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ int.has_coe)) n
| 0 := rfl
| (n+1) := congr_arg (+(1:ℤ)) (nat_cast_eq_coe_nat n)
section cast
variables {α : Type*}
section
variables [has_zero α] [has_one α] [has_add α] [has_neg α]
/-- Canonical homomorphism from the integers to any ring(-like) structure `α` -/
protected def cast : ℤ → α
| (n : ℕ) := n
| -[1+ n] := -(n+1)
@[priority 0] instance cast_coe : has_coe ℤ α := ⟨int.cast⟩
@[simp] theorem cast_zero : ((0 : ℤ) : α) = 0 := rfl
@[simp] theorem cast_of_nat (n : ℕ) : (of_nat n : α) = n := rfl
@[simp] theorem cast_coe_nat (n : ℕ) : ((n : ℤ) : α) = n := rfl
@[simp] theorem cast_coe_nat' (n : ℕ) :
(@coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ nat.cast_coe)) n : α) = n :=
by simp
@[simp] theorem cast_neg_succ_of_nat (n : ℕ) : (-[1+ n] : α) = -(n + 1) := rfl
end
@[simp] theorem cast_one [add_monoid α] [has_one α] [has_neg α] : ((1 : ℤ) : α) = 1 := nat.cast_one
@[simp] theorem cast_sub_nat_nat [add_group α] [has_one α] (m n) : ((int.sub_nat_nat m n : ℤ) : α) = m - n :=
begin
unfold sub_nat_nat, cases e : n - m,
{ simp [sub_nat_nat, e, nat.le_of_sub_eq_zero e] },
{ rw [sub_nat_nat, cast_neg_succ_of_nat, ← nat.cast_succ, ← e,
nat.cast_sub $ _root_.le_of_lt $ nat.lt_of_sub_eq_succ e, neg_sub] },
end
@[simp] theorem cast_neg_of_nat [add_group α] [has_one α] : ∀ n, ((neg_of_nat n : ℤ) : α) = -n
| 0 := neg_zero.symm
| (n+1) := rfl
@[simp] theorem cast_add [add_group α] [has_one α] : ∀ m n, ((m + n : ℤ) : α) = m + n
| (m : ℕ) (n : ℕ) := nat.cast_add _ _
| (m : ℕ) -[1+ n] := cast_sub_nat_nat _ _
| -[1+ m] (n : ℕ) := (cast_sub_nat_nat _ _).trans $ sub_eq_of_eq_add $
show (n:α) = -(m+1) + n + (m+1),
by rw [add_assoc, ← cast_succ, ← nat.cast_add, add_comm,
nat.cast_add, cast_succ, neg_add_cancel_left]
| -[1+ m] -[1+ n] := show -((m + n + 1 + 1 : ℕ) : α) = -(m + 1) + -(n + 1),
by rw [← neg_add_rev, ← nat.cast_add_one, ← nat.cast_add_one, ← nat.cast_add];
apply congr_arg (λ x:ℕ, -(x:α)); simp
@[simp] theorem cast_neg [add_group α] [has_one α] : ∀ n, ((-n : ℤ) : α) = -n
| (n : ℕ) := cast_neg_of_nat _
| -[1+ n] := (neg_neg _).symm
theorem cast_sub [add_group α] [has_one α] (m n) : ((m - n : ℤ) : α) = m - n :=
by simp
@[simp] theorem cast_eq_zero [add_group α] [has_one α] [char_zero α] {n : ℤ} : (n : α) = 0 ↔ n = 0 :=
⟨λ h, begin cases n,
{ exact congr_arg coe (nat.cast_eq_zero.1 h) },
{ rw [cast_neg_succ_of_nat, neg_eq_zero, ← cast_succ, nat.cast_eq_zero] at h,
contradiction }
end, λ h, by rw [h, cast_zero]⟩
@[simp] theorem cast_inj [add_group α] [has_one α] [char_zero α] {m n : ℤ} : (m : α) = n ↔ m = n :=
by rw [← sub_eq_zero, ← cast_sub, cast_eq_zero, sub_eq_zero]
theorem cast_injective [add_group α] [has_one α] [char_zero α] : function.injective (coe : ℤ → α)
| m n := cast_inj.1
@[simp] theorem cast_ne_zero [add_group α] [has_one α] [char_zero α] {n : ℤ} : (n : α) ≠ 0 ↔ n ≠ 0 :=
not_congr cast_eq_zero
@[simp] theorem cast_mul [ring α] : ∀ m n, ((m * n : ℤ) : α) = m * n
| (m : ℕ) (n : ℕ) := nat.cast_mul _ _
| (m : ℕ) -[1+ n] := (cast_neg_of_nat _).trans $
show (-(m * (n + 1) : ℕ) : α) = m * -(n + 1),
by rw [nat.cast_mul, nat.cast_add_one, neg_mul_eq_mul_neg]
| -[1+ m] (n : ℕ) := (cast_neg_of_nat _).trans $
show (-((m + 1) * n : ℕ) : α) = -(m + 1) * n,
by rw [nat.cast_mul, nat.cast_add_one, neg_mul_eq_neg_mul]
| -[1+ m] -[1+ n] := show (((m + 1) * (n + 1) : ℕ) : α) = -(m + 1) * -(n + 1),
by rw [nat.cast_mul, nat.cast_add_one, nat.cast_add_one, neg_mul_neg]
theorem mul_cast_comm [ring α] (a : α) (n : ℤ) : a * n = n * a :=
by cases n; simp [nat.mul_cast_comm, left_distrib, right_distrib, *]
@[simp] theorem cast_bit0 [ring α] (n : ℤ) : ((bit0 n : ℤ) : α) = bit0 n := cast_add _ _
@[simp] theorem cast_bit1 [ring α] (n : ℤ) : ((bit1 n : ℤ) : α) = bit1 n :=
by rw [bit1, cast_add, cast_one, cast_bit0]; refl
theorem cast_nonneg [linear_ordered_ring α] : ∀ {n : ℤ}, (0 : α) ≤ n ↔ 0 ≤ n
| (n : ℕ) := by simp
| -[1+ n] := by simpa [not_le_of_gt (neg_succ_lt_zero n)] using
show -(n:α) < 1, from lt_of_le_of_lt (by simp) zero_lt_one
@[simp] theorem cast_le [linear_ordered_ring α] {m n : ℤ} : (m : α) ≤ n ↔ m ≤ n :=
by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg]
@[simp] theorem cast_lt [linear_ordered_ring α] {m n : ℤ} : (m : α) < n ↔ m < n :=
by simpa [-cast_le] using not_congr (@cast_le α _ n m)
@[simp] theorem cast_nonpos [linear_ordered_ring α] {n : ℤ} : (n : α) ≤ 0 ↔ n ≤ 0 :=
by rw [← cast_zero, cast_le]
@[simp] theorem cast_pos [linear_ordered_ring α] {n : ℤ} : (0 : α) < n ↔ 0 < n :=
by rw [← cast_zero, cast_lt]
@[simp] theorem cast_lt_zero [linear_ordered_ring α] {n : ℤ} : (n : α) < 0 ↔ n < 0 :=
by rw [← cast_zero, cast_lt]
theorem eq_cast [add_group α] [has_one α] (f : ℤ → α)
(H1 : f 1 = 1) (Hadd : ∀ x y, f (x + y) = f x + f y) (n : ℤ) : f n = n :=
begin
have H : ∀ (n : ℕ), f n = n :=
nat.eq_cast' (λ n, f n) H1 (λ x y, Hadd x y),
cases n, {apply H},
apply eq_neg_of_add_eq_zero,
rw [← nat.cast_zero, ← H 0, int.coe_nat_zero,
← show -[1+ n] + (↑n + 1) = 0, from neg_add_self (↑n+1),
Hadd, show f (n+1) = n+1, from H (n+1)]
end
@[simp] theorem cast_id (n : ℤ) : ↑n = n :=
(eq_cast id rfl (λ _ _, rfl) n).symm
@[simp] theorem cast_min [decidable_linear_ordered_comm_ring α] {a b : ℤ} : (↑(min a b) : α) = min a b :=
by by_cases a ≤ b; simp [h, min]
@[simp] theorem cast_max [decidable_linear_ordered_comm_ring α] {a b : ℤ} : (↑(max a b) : α) = max a b :=
by by_cases a ≤ b; simp [h, max]
@[simp] theorem cast_abs [decidable_linear_ordered_comm_ring α] {q : ℤ} : ((abs q : ℤ) : α) = abs q :=
by simp [abs]
end cast
end int
|
016b3c36c71d9daaf233ec2e32c79d9095caf17c | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/analysis/box_integral/integrability.lean | 763a6ca1b9fd9ee54932d5ceda094ed60b4a205c | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,646 | lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.box_integral.basic
/-!
# McShane integrability vs Bochner integrability
In this file we prove that any Bochner integrable function is McShane integrable (hence, it is
Henstock and `⊥` integrable) with the same integral. The proof is based on
[Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55].
## Tags
integral, McShane integral, Bochner integral
-/
open_locale classical nnreal ennreal topological_space big_operators
universes u v
variables {ι : Type u} {E : Type v} [fintype ι] [normed_group E] [normed_space ℝ E]
open measure_theory metric set finset filter box_integral
namespace box_integral
/-- The indicator function of a measurable set is McShane integrable with respect to any
locally-finite measure. -/
lemma has_integral_indicator_const (l : integration_params) (hl : l.bRiemann = ff)
{s : set (ι → ℝ)} (hs : measurable_set s) (I : box ι) (y : E)
(μ : measure (ι → ℝ)) [is_locally_finite_measure μ] :
has_integral.{u v v} I l (s.indicator (λ _, y)) μ.to_box_additive.to_smul
((μ (s ∩ I)).to_real • y) :=
begin
refine has_integral_of_mul (∥y∥) (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.le, rw nnreal.coe_pos at ε0,
/- First we choose a closed set `F ⊆ s ∩ I.Icc` and an open set `U ⊇ s` such that
both `(s ∩ I.Icc) \ F` and `U \ s` have measuer less than `ε`. -/
have A : μ (s ∩ I.Icc) ≠ ∞,
from ((measure_mono $ set.inter_subset_right _ _).trans_lt (I.measure_Icc_lt_top μ)).ne,
have B : μ (s ∩ I) ≠ ∞,
from ((measure_mono $ set.inter_subset_right _ _).trans_lt (I.measure_coe_lt_top μ)).ne,
obtain ⟨F, hFs, hFc, hμF⟩ : ∃ F ⊆ s ∩ I.Icc, is_closed F ∧ μ ((s ∩ I.Icc) \ F) < ε,
from (hs.inter I.measurable_set_Icc).exists_is_closed_diff_lt A (ennreal.coe_pos.2 ε0).ne',
obtain ⟨U, hsU, hUo, hUt, hμU⟩ : ∃ U ⊇ s ∩ I.Icc, is_open U ∧ μ U < ∞ ∧ μ (U \ (s ∩ I.Icc)) < ε,
from (hs.inter I.measurable_set_Icc).exists_is_open_diff_lt A (ennreal.coe_pos.2 ε0).ne',
/- Then we choose `r` so that `closed_ball x (r x) ⊆ U` whenever `x ∈ s ∩ I.Icc` and
`closed_ball x (r x)` is disjoint with `F` otherwise. -/
have : ∀ x ∈ s ∩ I.Icc, ∃ r : Ioi (0 : ℝ), closed_ball x r ⊆ U,
from λ x hx, subtype.exists'.1 (nhds_basis_closed_ball.mem_iff.1 (hUo.mem_nhds $ hsU hx)),
choose! rs hrsU,
have : ∀ x ∈ I.Icc \ s, ∃ r : Ioi (0 : ℝ), closed_ball x r ⊆ Fᶜ,
from λ x hx, subtype.exists'.1 (nhds_basis_closed_ball.mem_iff.1 (hFc.is_open_compl.mem_nhds $
λ hx', hx.2 (hFs hx').1)),
choose! rs' hrs'F,
set r : (ι → ℝ) → Ioi (0 : ℝ) := s.piecewise rs rs',
refine ⟨λ c, r, λ c, l.r_cond_of_bRiemann_eq_ff hl, λ c π hπ hπp, _⟩, rw mul_comm,
/- Then the union of boxes `J ∈ π` such that `π.tag ∈ s` includes `F` and is included by `U`,
hence its measure is `ε`-close to the measure of `s`. -/
dsimp [integral_sum],
simp only [mem_closed_ball, dist_eq_norm, ← indicator_smul_apply, sum_indicator_eq_sum_filter,
← sum_smul, ← sub_smul, norm_smul, real.norm_eq_abs, ← prepartition.filter_boxes,
← prepartition.measure_Union_to_real],
refine mul_le_mul_of_nonneg_right _ (norm_nonneg y),
set t := (π.to_prepartition.filter (λ J, π.tag J ∈ s)).Union,
change abs ((μ t).to_real - (μ (s ∩ I)).to_real) ≤ ε,
have htU : t ⊆ U ∩ I,
{ simp only [t, prepartition.Union_def, Union_subset_iff, prepartition.mem_filter, and_imp],
refine λ J hJ hJs x hx, ⟨hrsU _ ⟨hJs, π.tag_mem_Icc J⟩ _, π.le_of_mem' J hJ hx⟩,
simpa only [r, s.piecewise_eq_of_mem _ _ hJs] using hπ.1 J hJ (box.coe_subset_Icc hx) },
refine abs_sub_le_iff.2 ⟨_, _⟩,
{ refine (ennreal.le_to_real_sub B).trans (ennreal.to_real_le_coe_of_le_coe _),
refine (ennreal.sub_le_sub (measure_mono htU) le_rfl).trans (le_measure_diff.trans _),
refine (measure_mono $ λ x hx, _).trans hμU.le,
exact ⟨hx.1.1, λ hx', hx.2 ⟨hx'.1, hx.1.2⟩⟩ },
{ have hμt : μ t ≠ ∞ :=
((measure_mono (htU.trans (inter_subset_left _ _))).trans_lt hUt).ne,
refine (ennreal.le_to_real_sub hμt).trans (ennreal.to_real_le_coe_of_le_coe _),
refine le_measure_diff.trans ((measure_mono _).trans hμF.le),
rintro x ⟨⟨hxs, hxI⟩, hxt⟩,
refine ⟨⟨hxs, box.coe_subset_Icc hxI⟩, λ hxF, hxt _⟩,
simp only [t, prepartition.Union_def, prepartition.mem_filter, set.mem_Union, exists_prop],
rcases hπp x hxI with ⟨J, hJπ, hxJ⟩,
refine ⟨J, ⟨hJπ, _⟩, hxJ⟩,
contrapose hxF,
refine hrs'F _ ⟨π.tag_mem_Icc J, hxF⟩ _,
simpa only [r, s.piecewise_eq_of_not_mem _ _ hxF] using hπ.1 J hJπ (box.coe_subset_Icc hxJ) }
end
/-- If `f` is a.e. equal to zero on a rectangular box, then it has McShane integral zero on this
box. -/
lemma has_integral_zero_of_ae_eq_zero {l : integration_params} {I : box ι} {f : (ι → ℝ) → E}
{μ : measure (ι → ℝ)} [is_locally_finite_measure μ] (hf : f =ᵐ[μ.restrict I] 0)
(hl : l.bRiemann = ff) :
has_integral.{u v v} I l f μ.to_box_additive.to_smul 0 :=
begin
/- Each set `{x | n < ∥f x∥ ≤ n + 1}`, `n : ℕ`, has measure zero. We cover it by an open set of
measure less than `ε / 2 ^ n / (n + 1)`. Then the norm of the integral sum is less than `ε`. -/
refine has_integral_iff.2 (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.lt.le, rw [gt_iff_lt, nnreal.coe_pos] at ε0,
rcases nnreal.exists_pos_sum_of_encodable ε0.ne' ℕ with ⟨δ, δ0, c, hδc, hcε⟩,
haveI := fact.mk (I.measure_coe_lt_top μ),
change μ.restrict I {x | f x ≠ 0} = 0 at hf,
set N : (ι → ℝ) → ℕ := λ x, ⌈∥f x∥⌉₊,
have N0 : ∀ {x}, N x = 0 ↔ f x = 0, by { intro x, simp [N] },
have : ∀ n, ∃ U ⊇ N ⁻¹' {n}, is_open U ∧ μ.restrict I U < δ n / n,
{ refine λ n, (N ⁻¹' {n}).exists_is_open_lt_of_lt _ _,
cases n,
{ simpa [ennreal.div_zero (ennreal.coe_pos.2 (δ0 _)).ne']
using measure_lt_top (μ.restrict I) _ },
{ refine (measure_mono_null _ hf).le.trans_lt _,
{ exact λ x hxN hxf, n.succ_ne_zero ((eq.symm hxN).trans $ N0.2 hxf) },
{ simp [(δ0 _).ne'] } } },
choose U hNU hUo hμU,
have : ∀ x, ∃ r : Ioi (0 : ℝ), closed_ball x r ⊆ U (N x),
from λ x, subtype.exists'.1 (nhds_basis_closed_ball.mem_iff.1 ((hUo _).mem_nhds (hNU _ rfl))),
choose r hrU,
refine ⟨λ _, r, λ c, l.r_cond_of_bRiemann_eq_ff hl, λ c π hπ hπp, _⟩,
rw [dist_eq_norm, sub_zero, ← integral_sum_fiberwise (λ J, N (π.tag J))],
refine le_trans _ (nnreal.coe_lt_coe.2 hcε).le,
refine (norm_sum_le_of_le _ _).trans
(sum_le_has_sum _ (λ n _, (δ n).2) (nnreal.has_sum_coe.2 hδc)),
rintro n -,
dsimp [integral_sum],
have : ∀ J ∈ π.filter (λ J, N (π.tag J) = n),
∥(μ ↑J).to_real • f (π.tag J)∥ ≤ (μ J).to_real * n,
{ intros J hJ, rw tagged_prepartition.mem_filter at hJ,
rw [norm_smul, real.norm_eq_abs, abs_of_nonneg ennreal.to_real_nonneg],
exact mul_le_mul_of_nonneg_left (hJ.2 ▸ nat.le_ceil _) ennreal.to_real_nonneg },
refine (norm_sum_le_of_le _ this).trans _, clear this,
rw [← sum_mul, ← prepartition.measure_Union_to_real],
generalize hm : μ (π.filter (λ J, N (π.tag J) = n)).Union = m,
have : m < δ n / n,
{ simp only [measure.restrict_apply (hUo _).measurable_set] at hμU,
refine hm ▸ (measure_mono _).trans_lt (hμU _),
simp only [set.subset_def, tagged_prepartition.mem_Union, exists_prop,
tagged_prepartition.mem_filter],
rintro x ⟨J, ⟨hJ, rfl⟩, hx⟩,
exact ⟨hrU _ (hπ.1 _ hJ (box.coe_subset_Icc hx)), π.le_of_mem' J hJ hx⟩ },
lift m to ℝ≥0 using ne_top_of_lt this,
rw [ennreal.coe_to_real, ← nnreal.coe_nat_cast, ← nnreal.coe_mul, nnreal.coe_le_coe,
← ennreal.coe_le_coe, ennreal.coe_mul, ennreal.coe_nat, mul_comm],
exact (mul_le_mul_left' this.le _).trans ennreal.mul_div_le
end
/-- If `f` has integral `y` on a box `I` with respect to a locally finite measure `μ` and `g` is
a.e. equal to `f` on `I`, then `g` has the same integral on `I`. -/
lemma has_integral.congr_ae {l : integration_params} {I : box ι} {y : E} {f g : (ι → ℝ) → E}
{μ : measure (ι → ℝ)} [is_locally_finite_measure μ]
(hf : has_integral.{u v v} I l f μ.to_box_additive.to_smul y)
(hfg : f =ᵐ[μ.restrict I] g) (hl : l.bRiemann = ff) :
has_integral.{u v v} I l g μ.to_box_additive.to_smul y :=
begin
have : (g - f) =ᵐ[μ.restrict I] 0, from hfg.mono (λ x hx, sub_eq_zero.2 hx.symm),
simpa using hf.add (has_integral_zero_of_ae_eq_zero this hl)
end
end box_integral
namespace measure_theory
namespace simple_func
/-- A simple function is McShane integrable w.r.t. any locally finite measure. -/
lemma has_box_integral (f : simple_func (ι → ℝ) E) (μ : measure (ι → ℝ))
[is_locally_finite_measure μ] (I : box ι) (l : integration_params) (hl : l.bRiemann = ff) :
has_integral.{u v v} I l f μ.to_box_additive.to_smul (f.integral (μ.restrict I)) :=
begin
induction f using measure_theory.simple_func.induction with y s hs f g hd hfi hgi,
{ simpa [function.const, measure.restrict_apply hs]
using box_integral.has_integral_indicator_const l hl hs I y μ },
{ letI := borel E, haveI : borel_space E := ⟨rfl⟩, haveI := fact.mk (I.measure_coe_lt_top μ),
rw integral_add,
exacts [hfi.add hgi, integrable_iff.2 $ λ _ _, measure_lt_top _ _,
integrable_iff.2 $ λ _ _, measure_lt_top _ _] }
end
/-- For a simple function, its McShane (or Henstock, or `⊥`) box integral is equal to its
integral in the sense of `measure_theory.simple_func.integral`. -/
lemma box_integral_eq_integral (f : simple_func (ι → ℝ) E) (μ : measure (ι → ℝ))
[is_locally_finite_measure μ] (I : box ι) (l : integration_params) (hl : l.bRiemann = ff) :
box_integral.integral.{u v v} I l f μ.to_box_additive.to_smul = f.integral (μ.restrict I) :=
(f.has_box_integral μ I l hl).integral_eq
end simple_func
open topological_space
/-- If `f : ℝⁿ → E` is Bochner integrable w.r.t. a locally finite measure `μ` on a rectangular box
`I`, then it is McShane integrable on `I` with the same integral. -/
lemma integrable_on.has_box_integral [second_countable_topology E] [measurable_space E]
[borel_space E] [complete_space E] {f : (ι → ℝ) → E} {μ : measure (ι → ℝ)}
[is_locally_finite_measure μ] {I : box ι} (hf : integrable_on f I μ) (l : integration_params)
(hl : l.bRiemann = ff) :
has_integral.{u v v} I l f μ.to_box_additive.to_smul (∫ x in I, f x ∂ μ) :=
begin
/- First we replace an `ae_measurable` function by a measurable one. -/
rcases hf.ae_measurable with ⟨g, hg, hfg⟩,
rw integral_congr_ae hfg, have hgi : integrable_on g I μ := (integrable_congr hfg).1 hf,
refine box_integral.has_integral.congr_ae _ hfg.symm hl,
clear_dependent f,
/- Now consider the sequence of simple functions `simple_func.approx_on g hg univ 0 trivial`
approximating `g`. Recall some properties of this sequence. -/
set f : ℕ → simple_func (ι → ℝ) E := simple_func.approx_on g hg univ 0 trivial,
have hfi : ∀ n, integrable_on (f n) I μ, from simple_func.integrable_approx_on_univ hg hgi,
have hfi' := λ n, ((f n).has_box_integral μ I l hl).integrable,
have hfgi : tendsto (λ n, (f n).integral (μ.restrict I)) at_top (𝓝 $ ∫ x in I, g x ∂μ),
from tendsto_integral_approx_on_univ_of_measurable hg hgi,
have hfg_mono : ∀ x {m n}, m ≤ n → ∥f n x - g x∥ ≤ ∥f m x - g x∥,
{ intros x m n hmn,
rw [← dist_eq_norm, ← dist_eq_norm, dist_nndist, dist_nndist, nnreal.coe_le_coe,
← ennreal.coe_le_coe, ← edist_nndist, ← edist_nndist],
exact simple_func.edist_approx_on_mono hg _ x hmn },
/- Now consider `ε > 0`. We need to find `r` such that for any tagged partition subordinate
to `r`, the integral sum is `(μ I + 1 + 1) * ε`-close to the Bochner integral. -/
refine has_integral_of_mul ((μ I).to_real + 1 + 1) (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.le, rw nnreal.coe_pos at ε0, have ε0' := ennreal.coe_pos.2 ε0,
/- Choose `N` such that the integral of `∥f N x - g x∥` is less than or equal to `ε`. -/
obtain ⟨N₀, hN₀⟩ : ∃ N : ℕ, ∫ x in I, ∥f N x - g x∥ ∂μ ≤ ε,
{ have : tendsto (λ n, ∫⁻ x in I, ∥f n x - g x∥₊ ∂μ) at_top (𝓝 0),
from simple_func.tendsto_approx_on_univ_L1_nnnorm hg hgi,
refine (this.eventually (ge_mem_nhds ε0')).exists.imp (λ N hN, _),
exact integral_coe_le_of_lintegral_coe_le hN },
/- For each `x`, we choose `Nx x ≥ N₀` such that `dist (f Nx x) (g x) ≤ ε`. -/
have : ∀ x, ∃ N₁, N₀ ≤ N₁ ∧ dist (f N₁ x) (g x) ≤ ε,
{ intro x,
have : tendsto (λ n, f n x) at_top (𝓝 $ g x),
from simple_func.tendsto_approx_on hg _ (subset_closure trivial),
exact ((eventually_ge_at_top N₀).and $ this $ closed_ball_mem_nhds _ ε0).exists },
choose Nx hNx hNxε,
/- We also choose a convergent series with `∑' i : ℕ, δ i < ε`. -/
rcases nnreal.exists_pos_sum_of_encodable ε0.ne' ℕ with ⟨δ, δ0, c, hδc, hcε⟩,
/- Since each simple function `fᵢ` is integrable, there exists `rᵢ : ℝⁿ → (0, ∞)` such that
the integral sum of `f` over any tagged prepartition is `δᵢ`-close to the sum of integrals
of `fᵢ` over the boxes of this prepartition. For each `x`, we choose `r (Nx x)` as the radius
at `x`. -/
set r : ℝ≥0 → (ι → ℝ) → Ioi (0 : ℝ) := λ c x, (hfi' $ Nx x).convergence_r (δ $ Nx x) c x,
refine ⟨r, λ c, l.r_cond_of_bRiemann_eq_ff hl, λ c π hπ hπp, _⟩,
/- Now we prove the estimate in 3 "jumps": first we replace `g x` in the formula for the
integral sum by `f (Nx x)`; then we replace each `μ J • f (Nx (π.tag J)) (π.tag J)`
by the Bochner integral of `f (Nx (π.tag J)) x` over `J`, then we jump to the Bochner
integral of `g`. -/
refine (dist_triangle4 _ (∑ J in π.boxes, (μ J).to_real • f (Nx $ π.tag J) (π.tag J))
(∑ J in π.boxes, ∫ x in J, f (Nx $ π.tag J) x ∂μ) _).trans _,
rw [add_mul, add_mul, one_mul],
refine add_le_add_three _ _ _,
{ /- Since each `f (Nx $ π.tag J)` is `ε`-close to `g (π.tag J)`, replacing the latter with
the former in the formula for the integral sum changes the sum at most by `μ I * ε`. -/
rw [← hπp.Union_eq, π.to_prepartition.measure_Union_to_real, sum_mul, integral_sum],
refine dist_sum_sum_le_of_le _ (λ J hJ, _), dsimp,
rw [dist_eq_norm, ← smul_sub, norm_smul, real.norm_eq_abs,
abs_of_nonneg ennreal.to_real_nonneg],
refine mul_le_mul_of_nonneg_left _ ennreal.to_real_nonneg,
rw [← dist_eq_norm'], exact hNxε _ },
{ /- We group the terms of both sums by the values of `Nx (π.tag J)`.
For each `N`, the sum of Bochner integrals over the boxes is equal
to the sum of box integrals, and the sum of box integrals is `δᵢ`-close
to the corresponding integral sum due to the Henstock-Sacks inequality. -/
rw [← π.to_prepartition.sum_fiberwise (λ J, Nx (π.tag J)),
← π.to_prepartition.sum_fiberwise (λ J, Nx (π.tag J))],
refine le_trans _ (nnreal.coe_lt_coe.2 hcε).le,
refine (dist_sum_sum_le_of_le _ (λ n hn, _)).trans
(sum_le_has_sum _ (λ n _, (δ n).2) (nnreal.has_sum_coe.2 hδc)),
have hNxn : ∀ J ∈ π.filter (λ J, Nx (π.tag J) = n), Nx (π.tag J) = n,
from λ J hJ, (π.mem_filter.1 hJ).2,
have hrn : ∀ J ∈ π.filter (λ J, Nx (π.tag J) = n),
r c (π.tag J) = (hfi' n).convergence_r (δ n) c (π.tag J),
{ intros J hJ, have := hNxn J hJ, clear hJ, subst n },
have : l.mem_base_set I c ((hfi' n).convergence_r (δ n) c) (π.filter (λ J, Nx (π.tag J) = n)),
from (hπ.filter _).mono' _ le_rfl le_rfl (λ J hJ, (hrn J hJ).le),
convert (hfi' n).dist_integral_sum_sum_integral_le_of_mem_base_set (δ0 _) this using 2,
{ refine sum_congr rfl (λ J hJ, _),
simp [hNxn J hJ] },
{ refine sum_congr rfl (λ J hJ, _),
rw [← simple_func.integral_eq_integral, simple_func.box_integral_eq_integral _ _ _ _ hl,
hNxn J hJ],
exact (hfi _).mono_set (prepartition.le_of_mem _ hJ) } },
{ /- For the last jump, we use the fact that the distance between `f (Nx x) x` and `g x` is less
than or equal to the distance between `f N₀ x` and `g x` and the integral of `∥f N₀ x - g x∥`
is less than or equal to `ε`. -/
refine le_trans _ hN₀,
have hfi : ∀ n (J ∈ π), integrable_on (f n) ↑J μ,
from λ n J hJ, (hfi n).mono_set (π.le_of_mem' J hJ),
have hgi : ∀ J ∈ π, integrable_on g ↑J μ, from λ J hJ, hgi.mono_set (π.le_of_mem' J hJ),
have hfgi : ∀ n (J ∈ π), integrable_on (λ x, ∥f n x - g x∥) J μ,
from λ n J hJ, ((hfi n J hJ).sub (hgi J hJ)).norm,
rw [← hπp.Union_eq, prepartition.Union_def',
integral_finset_bUnion π.boxes (λ J hJ, J.measurable_set_coe) π.pairwise_disjoint hgi,
integral_finset_bUnion π.boxes (λ J hJ, J.measurable_set_coe) π.pairwise_disjoint (hfgi _)],
refine dist_sum_sum_le_of_le _ (λ J hJ, _),
rw [dist_eq_norm, ← integral_sub (hfi _ J hJ) (hgi J hJ)],
refine norm_integral_le_of_norm_le (hfgi _ J hJ) (eventually_of_forall $ λ x, _),
exact hfg_mono x (hNx (π.tag J)) }
end
end measure_theory
|
37f03c6d4fb7044f72e204909718abd0906f0c36 | 5df84495ec6c281df6d26411cc20aac5c941e745 | /src/formal_ml/lattice.lean | 5286969de64eed29f7d6e165a9d3056ee0d0bef4 | [
"Apache-2.0"
] | permissive | eric-wieser/formal-ml | e278df5a8df78aa3947bc8376650419e1b2b0a14 | 630011d19fdd9539c8d6493a69fe70af5d193590 | refs/heads/master | 1,681,491,589,256 | 1,612,642,743,000 | 1,612,642,743,000 | 360,114,136 | 0 | 0 | Apache-2.0 | 1,618,998,189,000 | 1,618,998,188,000 | null | UTF-8 | Lean | false | false | 2,183 | lean | import order.complete_lattice
lemma le_supr'' {α : Type*} {ι : Sort*} [_inst_1 : complete_lattice α] (s : ι → α) (i : ι) (x:α):
(x ≤ s i) → x ≤ supr s :=
begin
intro A1,
apply le_trans A1,
apply le_supr,
end
lemma infi_prop_def {α:Type*} [complete_lattice α]
{v:α} {P:Prop} (H:P):(⨅ (H2:P), v) = v :=
begin
apply le_antisymm,
{ apply infi_le, apply H },
{ apply @le_infi, intro A1, apply le_refl v },
end
lemma supr_prop_def {α:Type*} [complete_lattice α]
{v:α} {P:Prop} (H:P):(⨆ (H2:P), v) = v :=
begin
apply le_antisymm,
{
apply supr_le,
intro A1,
apply le_refl v,
},
{
apply @le_supr α P _ (λ H2:P, v),
apply H,
},
end
lemma supr_prop_false {α:Type*} [complete_lattice α]
{v:α} {P:Prop} (H:¬P):(⨆ (H2:P), v) = ⊥ :=
begin
apply le_antisymm,
{
apply supr_le,
intro A1,
exfalso,
apply H,
apply A1,
},
{
apply bot_le,
},
end
lemma infi_prop_false {α:Type*} [complete_lattice α]
{v:α} {P:Prop} (H:¬P):(⨅ (H2:P), v) = ⊤ :=
begin
apply le_antisymm,
{
apply le_top,
},
{
apply le_infi,
intro A1,
exfalso,
apply H,
apply A1,
},
end
lemma infi_le_trans {α β:Type*} [complete_lattice β] (a:α) (f:α → β)
(b:β):(f a ≤ b) → (⨅ (c:α), (f c)) ≤ b :=
begin
intros A1,
apply le_trans _ A1,
apply @infi_le _ _ _,
end
/-
I saw this pattern a bunch below. It could be more widely used.
-/
lemma infi_set_le_trans {α β:Type*} [complete_lattice β] (a:α) (P:α → Prop) (f:α → β)
(b:β):(P a) → (f a ≤ b) → (⨅ (c:α) (H:P c), f c) ≤ b :=
begin
intros A1 A2,
apply infi_le_trans a,
rw infi_prop_def A1,
apply A2,
end
lemma infi_set_image {α β γ:Type*} [complete_lattice γ] (S:set α) (f:α → β)
(g:β → γ):(⨅ (c∈ (f '' S)), g c) = ⨅ (a∈ S), (g ∘ f) a :=
begin
apply le_antisymm;simp,
{
intros a B1,
apply infi_le_trans (f a),
apply infi_le_trans a,
rw infi_prop_def,
apply and.intro B1,
refl,
},
{
intros b h_b,
apply infi_le_of_le b,
apply infi_le_of_le h_b,
apply le_refl,
},
end
|
73333b948b59233ecc7ab2013a18f7320b62c501 | 07c6143268cfb72beccd1cc35735d424ebcb187b | /src/topology/uniform_space/cauchy.lean | c8afcb37a398bb6b938b1ac8a29a3460582d36a4 | [
"Apache-2.0"
] | permissive | khoek/mathlib | bc49a842910af13a3c372748310e86467d1dc766 | aa55f8b50354b3e11ba64792dcb06cccb2d8ee28 | refs/heads/master | 1,588,232,063,837 | 1,587,304,803,000 | 1,587,304,803,000 | 176,688,517 | 0 | 0 | Apache-2.0 | 1,553,070,585,000 | 1,553,070,585,000 | null | UTF-8 | Lean | false | false | 25,043 | 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
Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets.
-/
import topology.uniform_space.basic topology.bases data.set.intervals
universes u v
open filter topological_space set classical
open_locale classical
variables {α : Type u} {β : Type v} [uniform_space α]
open_locale uniformity topological_space
/-- A filter `f` is Cauchy if for every entourage `r`, there exists an
`s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy
sequences, because if `a : ℕ → α` then the filter of sets containing
cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/
def cauchy (f : filter α) := f ≠ ⊥ ∧ filter.prod f f ≤ (𝓤 α)
/-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f`
has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/
def is_complete (s : set α) := ∀f, cauchy f → f ≤ principal s → ∃x∈s, f ≤ 𝓝 x
lemma filter.has_basis.cauchy_iff {p : β → Prop} {s : β → set (α × α)} (h : (𝓤 α).has_basis p s)
{f : filter α} :
cauchy f ↔ (f ≠ ⊥ ∧ (∀ i, p i → ∃ t ∈ f, ∀ x y ∈ t, (x, y) ∈ s i)) :=
and_congr iff.rfl $ (f.basis_sets.prod_self.le_basis_iff h).trans $
by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id]
lemma cauchy_iff' {f : filter α} :
cauchy f ↔ (f ≠ ⊥ ∧ (∀ s ∈ 𝓤 α, ∃t∈f, ∀ x y ∈ t, (x, y) ∈ s)) :=
(𝓤 α).basis_sets.cauchy_iff
lemma cauchy_iff {f : filter α} :
cauchy f ↔ (f ≠ ⊥ ∧ (∀ s ∈ 𝓤 α, ∃t∈f, (set.prod t t) ⊆ s)) :=
(𝓤 α).basis_sets.cauchy_iff.trans $
by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id]
lemma cauchy_map_iff {l : filter β} {f : β → α} :
cauchy (l.map f) ↔ (l ≠ ⊥ ∧ tendsto (λp:β×β, (f p.1, f p.2)) (l.prod l) (𝓤 α)) :=
by rw [cauchy, (≠), map_eq_bot_iff, prod_map_map_eq]; refl
lemma cauchy_downwards {f g : filter α} (h_c : cauchy f) (hg : g ≠ ⊥) (h_le : g ≤ f) : cauchy g :=
⟨hg, le_trans (filter.prod_mono h_le h_le) h_c.right⟩
lemma cauchy_nhds {a : α} : cauchy (𝓝 a) :=
⟨nhds_ne_bot,
calc filter.prod (𝓝 a) (𝓝 a) =
(𝓤 α).lift (λs:set (α×α), (𝓤 α).lift' (λt:set(α×α),
set.prod {y : α | (y, a) ∈ s} {y : α | (a, y) ∈ t})) : nhds_nhds_eq_uniformity_uniformity_prod
... ≤ (𝓤 α).lift' (λs:set (α×α), comp_rel s s) :
le_infi $ assume s, le_infi $ assume hs,
infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le s $ infi_le_of_le hs $
principal_mono.mpr $
assume ⟨x, y⟩ ⟨(hx : (x, a) ∈ s), (hy : (a, y) ∈ s)⟩, ⟨a, hx, hy⟩
... ≤ 𝓤 α : comp_le_uniformity⟩
lemma cauchy_pure {a : α} : cauchy (pure a) :=
cauchy_downwards cauchy_nhds pure_ne_bot (pure_le_nhds a)
/-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and
`sequentially_complete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s`
one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y`
with `(x, y) ∈ s`, then `f` converges to `x`. -/
lemma le_nhds_of_cauchy_adhp_aux {f : filter α} {x : α}
(adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, (set.prod t t ⊆ s) ∧ ∃ y, (y ∈ t) ∧ (x, y) ∈ s) :
f ≤ 𝓝 x :=
begin
-- Consider a neighborhood `s` of `x`
assume s hs,
-- Take an entourage twice smaller than `s`
rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩,
-- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U`
rcases adhs U U_mem with ⟨t, t_mem, ht, y, hy, hxy⟩,
apply mem_sets_of_superset t_mem,
-- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s`
exact (λ z hz, hU (prod_mk_mem_comp_rel hxy (ht $ mk_mem_prod hy hz)) rfl)
end
/-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point
for `f`. -/
lemma le_nhds_of_cauchy_adhp {f : filter α} {x : α} (hf : cauchy f)
(adhs : f ⊓ 𝓝 x ≠ ⊥) : f ≤ 𝓝 x :=
le_nhds_of_cauchy_adhp_aux
begin
assume s hs,
-- Take `t ∈ f` such that `t × t ⊆ s`.
rcases (cauchy_iff.1 hf).2 s hs with ⟨t, t_mem, ht⟩,
use [t, t_mem, ht],
exact (forall_sets_nonempty_iff_ne_bot.2 adhs _
(inter_mem_inf_sets t_mem (mem_nhds_left x hs)))
end
lemma le_nhds_iff_adhp_of_cauchy {f : filter α} {x : α} (hf : cauchy f) :
f ≤ 𝓝 x ↔ f ⊓ 𝓝 x ≠ ⊥ :=
⟨assume h, (inf_of_le_left h).symm ▸ hf.left,
le_nhds_of_cauchy_adhp hf⟩
lemma cauchy_map [uniform_space β] {f : filter α} {m : α → β}
(hm : uniform_continuous m) (hf : cauchy f) : cauchy (map m f) :=
⟨have f ≠ ⊥, from hf.left, by simp; assumption,
calc filter.prod (map m f) (map m f) =
map (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_map_map_eq
... ≤ map (λp:α×α, (m p.1, m p.2)) (𝓤 α) : map_mono hf.right
... ≤ 𝓤 β : hm⟩
lemma cauchy_comap [uniform_space β] {f : filter β} {m : α → β}
(hm : comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α)
(hf : cauchy f) (hb : comap m f ≠ ⊥) : cauchy (comap m f) :=
⟨hb,
calc filter.prod (comap m f) (comap m f) =
comap (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_comap_comap_eq
... ≤ comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) : comap_mono hf.right
... ≤ 𝓤 α : hm⟩
/-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function
defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that
is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/
def cauchy_seq [semilattice_sup β] (u : β → α) := cauchy (at_top.map u)
lemma cauchy_seq_of_tendsto_nhds [semilattice_sup β] [nonempty β] (f : β → α) {x}
(hx : tendsto f at_top (𝓝 x)) :
cauchy_seq f :=
cauchy_downwards cauchy_nhds (map_ne_bot at_top_ne_bot) hx
lemma cauchy_seq_iff_tendsto [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ tendsto (prod.map u u) at_top (𝓤 α) :=
cauchy_map_iff.trans $ (and_iff_right at_top_ne_bot).trans $
by simp only [prod_at_top_at_top_eq, prod.map_def]
/-- If a Cauchy sequence has a convergent subsequence, then it converges. -/
lemma tendsto_nhds_of_cauchy_seq_of_subseq
[semilattice_sup β] {u : β → α} (hu : cauchy_seq u)
{ι : Type*} {f : ι → β} {p : filter ι} (hp : p ≠ ⊥)
(hf : tendsto f p at_top) {a : α} (ha : tendsto (λ i, u (f i)) p (𝓝 a)) :
tendsto u at_top (𝓝 a) :=
begin
apply le_nhds_of_cauchy_adhp hu,
rw ← bot_lt_iff_ne_bot,
have : ⊥ < map (λ i, u (f i)) p ⊓ 𝓝 a,
by { rw [bot_lt_iff_ne_bot, inf_of_le_left ha], exact map_ne_bot hp },
exact lt_of_lt_of_le this (inf_le_inf (map_mono hf) (le_refl _))
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma filter.has_basis.cauchy_seq_iff {γ} [nonempty β] [semilattice_sup β] {u : β → α}
{p : γ → Prop} {s : γ → set (α × α)} (h : (𝓤 α).has_basis p s) :
cauchy_seq u ↔ ∀ i, p i → ∃N, ∀m n≥N, (u m, u n) ∈ s i :=
begin
rw [cauchy_seq_iff_tendsto, ← prod_at_top_at_top_eq],
refine (at_top_basis.prod_self.tendsto_iff h).trans _,
simp only [exists_prop, true_and, maps_to, preimage, subset_def, prod.forall,
mem_prod_eq, mem_set_of_eq, mem_Ici, and_imp, prod.map]
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma filter.has_basis.cauchy_seq_iff' {γ} [nonempty β] [semilattice_sup β] {u : β → α}
{p : γ → Prop} {s : γ → set (α × α)} (H : (𝓤 α).has_basis p s) :
cauchy_seq u ↔ ∀ i, p i → ∃N, ∀n≥N, (u n, u N) ∈ s i :=
begin
refine H.cauchy_seq_iff.trans ⟨λ h i hi, _, λ h i hi, _⟩,
{ exact (h i hi).imp (λ N hN n hn, hN n N hn (le_refl N)) },
{ rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩,
rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩,
refine (h j hj).imp (λ N hN m n hm hn, hts ⟨u N, hjt _, ht' $ hjt _⟩),
{ exact hN m hm },
{ exact hN n hn } }
end
lemma cauchy_seq_of_controlled [semilattice_sup β] [nonempty β]
(U : β → set (α × α)) (hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s)
{f : β → α} (hf : ∀ {N m n : β}, N ≤ m → N ≤ n → (f m, f n) ∈ U N) :
cauchy_seq f :=
cauchy_seq_iff_tendsto.2
begin
assume s hs,
rw [mem_map, mem_at_top_sets],
cases hU s hs with N hN,
refine ⟨(N, N), λ mn hmn, _⟩,
cases mn with m n,
exact hN (hf hmn.1 hmn.2)
end
/-- A complete space is defined here using uniformities. A uniform space
is complete if every Cauchy filter converges. -/
class complete_space (α : Type u) [uniform_space α] : Prop :=
(complete : ∀{f:filter α}, cauchy f → ∃x, f ≤ 𝓝 x)
lemma complete_univ {α : Type u} [uniform_space α] [complete_space α] :
is_complete (univ : set α) :=
begin
assume f hf _,
rcases complete_space.complete hf with ⟨x, hx⟩,
exact ⟨x, mem_univ x, hx⟩
end
lemma cauchy_prod [uniform_space β] {f : filter α} {g : filter β} :
cauchy f → cauchy g → cauchy (filter.prod f g)
| ⟨f_proper, hf⟩ ⟨g_proper, hg⟩ := ⟨filter.prod_ne_bot.2 ⟨f_proper, g_proper⟩,
let p_α := λp:(α×β)×(α×β), (p.1.1, p.2.1), p_β := λp:(α×β)×(α×β), (p.1.2, p.2.2) in
suffices (f.prod f).comap p_α ⊓ (g.prod g).comap p_β ≤ (𝓤 α).comap p_α ⊓ (𝓤 β).comap p_β,
by simpa [uniformity_prod, filter.prod, filter.comap_inf, filter.comap_comap_comp, (∘),
inf_assoc, inf_comm, inf_left_comm],
inf_le_inf (filter.comap_mono hf) (filter.comap_mono hg)⟩
instance complete_space.prod [uniform_space β] [complete_space α] [complete_space β] :
complete_space (α × β) :=
{ complete := λ f hf,
let ⟨x1, hx1⟩ := complete_space.complete $ cauchy_map uniform_continuous_fst hf in
let ⟨x2, hx2⟩ := complete_space.complete $ cauchy_map uniform_continuous_snd hf in
⟨(x1, x2), by rw [nhds_prod_eq, filter.prod_def];
from filter.le_lift (λ s hs, filter.le_lift' $ λ t ht,
have H1 : prod.fst ⁻¹' s ∈ f.sets := hx1 hs,
have H2 : prod.snd ⁻¹' t ∈ f.sets := hx2 ht,
filter.inter_mem_sets H1 H2)⟩ }
/--If `univ` is complete, the space is a complete space -/
lemma complete_space_of_is_complete_univ (h : is_complete (univ : set α)) : complete_space α :=
⟨λ f hf, let ⟨x, _, hx⟩ := h f hf ((@principal_univ α).symm ▸ le_top) in ⟨x, hx⟩⟩
lemma complete_space_iff_is_complete_univ :
complete_space α ↔ is_complete (univ : set α) :=
⟨@complete_univ α _, complete_space_of_is_complete_univ⟩
lemma cauchy_iff_exists_le_nhds [complete_space α] {l : filter α} (hl : l ≠ ⊥) :
cauchy l ↔ (∃x, l ≤ 𝓝 x) :=
⟨complete_space.complete, assume ⟨x, hx⟩, cauchy_downwards cauchy_nhds hl hx⟩
lemma cauchy_map_iff_exists_tendsto [complete_space α] {l : filter β} {f : β → α}
(hl : l ≠ ⊥) : cauchy (l.map f) ↔ (∃x, tendsto f l (𝓝 x)) :=
cauchy_iff_exists_le_nhds (map_ne_bot hl)
/-- A Cauchy sequence in a complete space converges -/
theorem cauchy_seq_tendsto_of_complete [semilattice_sup β] [complete_space α]
{u : β → α} (H : cauchy_seq u) : ∃x, tendsto u at_top (𝓝 x) :=
complete_space.complete H
/-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/
lemma cauchy_seq_tendsto_of_is_complete [semilattice_sup β] {K : set α} (h₁ : is_complete K)
{u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : cauchy_seq u) : ∃ v ∈ K, tendsto u at_top (𝓝 v) :=
h₁ _ h₃ $ le_principal_iff.2 $ mem_map_sets_iff.2 ⟨univ, univ_mem_sets,
by { simp only [image_univ], rintros _ ⟨n, rfl⟩, exact h₂ n }⟩
theorem le_nhds_lim_of_cauchy {α} [uniform_space α] [complete_space α]
[nonempty α] {f : filter α} (hf : cauchy f) : f ≤ 𝓝 (lim f) :=
lim_spec (complete_space.complete hf)
lemma is_complete_of_is_closed [complete_space α] {s : set α}
(h : is_closed s) : is_complete s :=
λ f cf fs, let ⟨x, hx⟩ := complete_space.complete cf in
⟨x, is_closed_iff_nhds.mp h x (ne_bot_of_le_ne_bot cf.left (le_inf hx fs)), hx⟩
/-- A set `s` is totally bounded if for every entourage `d` there is a finite
set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/
def totally_bounded (s : set α) : Prop :=
∀d ∈ 𝓤 α, ∃t : set α, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d})
theorem totally_bounded_iff_subset {s : set α} : totally_bounded s ↔
∀d ∈ 𝓤 α, ∃t ⊆ s, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}) :=
⟨λ H d hd, begin
rcases comp_symm_of_uniformity hd with ⟨r, hr, rs, rd⟩,
rcases H r hr with ⟨k, fk, ks⟩,
let u := {y ∈ k | ∃ x, x ∈ s ∧ (x, y) ∈ r},
let f : u → α := λ x, classical.some x.2.2,
have : ∀ x : u, f x ∈ s ∧ (f x, x.1) ∈ r := λ x, classical.some_spec x.2.2,
refine ⟨range f, _, _, _⟩,
{ exact range_subset_iff.2 (λ x, (this x).1) },
{ have : finite u := finite_subset fk (λ x h, h.1),
exact ⟨@set.fintype_range _ _ _ _ this.fintype⟩ },
{ intros x xs,
have := ks xs, simp at this,
rcases this with ⟨y, hy, xy⟩,
let z : coe_sort u := ⟨y, hy, x, xs, xy⟩,
exact mem_bUnion_iff.2 ⟨_, ⟨z, rfl⟩, rd $ mem_comp_rel.2 ⟨_, xy, rs (this z).2⟩⟩ }
end,
λ H d hd, let ⟨t, _, ht⟩ := H d hd in ⟨t, ht⟩⟩
lemma totally_bounded_subset {s₁ s₂ : set α} (hs : s₁ ⊆ s₂)
(h : totally_bounded s₂) : totally_bounded s₁ :=
assume d hd, let ⟨t, ht₁, ht₂⟩ := h d hd in ⟨t, ht₁, subset.trans hs ht₂⟩
lemma totally_bounded_empty : totally_bounded (∅ : set α) :=
λ d hd, ⟨∅, finite_empty, empty_subset _⟩
lemma totally_bounded_closure {s : set α} (h : totally_bounded s) :
totally_bounded (closure s) :=
assume t ht,
let ⟨t', ht', hct', htt'⟩ := mem_uniformity_is_closed ht, ⟨c, hcf, hc⟩ := h t' ht' in
⟨c, hcf,
calc closure s ⊆ closure (⋃ (y : α) (H : y ∈ c), {x : α | (x, y) ∈ t'}) : closure_mono hc
... = _ : closure_eq_of_is_closed $ is_closed_bUnion hcf $ assume i hi,
continuous_iff_is_closed.mp (continuous_id.prod_mk continuous_const) _ hct'
... ⊆ _ : bUnion_subset $ assume i hi, subset.trans (assume x, @htt' (x, i))
(subset_bUnion_of_mem hi)⟩
lemma totally_bounded_image [uniform_space β] {f : α → β} {s : set α}
(hf : uniform_continuous f) (hs : totally_bounded s) : totally_bounded (f '' s) :=
assume t ht,
have {p:α×α | (f p.1, f p.2) ∈ t} ∈ 𝓤 α,
from hf ht,
let ⟨c, hfc, hct⟩ := hs _ this in
⟨f '' c, finite_image f hfc,
begin
simp [image_subset_iff],
simp [subset_def] at hct,
intros x hx, simp,
exact hct x hx
end⟩
lemma cauchy_of_totally_bounded_of_ultrafilter {s : set α} {f : filter α}
(hs : totally_bounded s) (hf : is_ultrafilter f) (h : f ≤ principal s) : cauchy f :=
⟨hf.left, assume t ht,
let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht in
let ⟨i, hi, hs_union⟩ := hs t' ht'₁ in
have (⋃y∈i, {x | (x,y) ∈ t'}) ∈ f.sets,
from mem_sets_of_superset (le_principal_iff.mp h) hs_union,
have ∃y∈i, {x | (x,y) ∈ t'} ∈ f.sets,
from mem_of_finite_Union_ultrafilter hf hi this,
let ⟨y, hy, hif⟩ := this in
have set.prod {x | (x,y) ∈ t'} {x | (x,y) ∈ t'} ⊆ comp_rel t' t',
from assume ⟨x₁, x₂⟩ ⟨(h₁ : (x₁, y) ∈ t'), (h₂ : (x₂, y) ∈ t')⟩,
⟨y, h₁, ht'_symm h₂⟩,
(filter.prod f f).sets_of_superset (prod_mem_prod hif hif) (subset.trans this ht'_t)⟩
lemma totally_bounded_iff_filter {s : set α} :
totally_bounded s ↔ (∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c) :=
⟨assume : totally_bounded s, assume f hf hs,
⟨ultrafilter_of f, ultrafilter_of_le,
cauchy_of_totally_bounded_of_ultrafilter this
(ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hs)⟩,
assume h : ∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c, assume d hd,
classical.by_contradiction $ assume hs,
have hd_cover : ∀{t:set α}, finite t → ¬ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}),
by simpa using hs,
let
f := ⨅t:{t : set α // finite t}, principal (s \ (⋃y∈t.val, {x | (x,y) ∈ d})),
⟨a, ha⟩ := (@ne_empty_iff_nonempty α s).1
(assume h, hd_cover finite_empty $ h.symm ▸ empty_subset _)
in
have f ≠ ⊥,
from infi_ne_bot_of_directed ⟨a⟩
(assume ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩, ⟨⟨t₁ ∪ t₂, finite_union ht₁ ht₂⟩,
principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $
assume t, Union_subset_Union_const or.inl,
principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $
assume t, Union_subset_Union_const or.inr⟩)
(assume ⟨t, ht⟩, by simp [diff_eq_empty]; exact hd_cover ht),
have f ≤ principal s, from infi_le_of_le ⟨∅, finite_empty⟩ $ by simp; exact subset.refl s,
let
⟨c, (hc₁ : c ≤ f), (hc₂ : cauchy c)⟩ := h f ‹f ≠ ⊥› this,
⟨m, hm, (hmd : set.prod m m ⊆ d)⟩ := (@mem_prod_same_iff α c d).mp $ hc₂.right hd
in
have c ≤ principal s, from le_trans ‹c ≤ f› this,
have m ∩ s ∈ c.sets, from inter_mem_sets hm $ le_principal_iff.mp this,
let ⟨y, hym, hys⟩ := nonempty_of_mem_sets hc₂.left this in
let ys := (⋃y'∈({y}:set α), {x | (x, y') ∈ d}) in
have m ⊆ ys,
from assume y' hy',
show y' ∈ (⋃y'∈({y}:set α), {x | (x, y') ∈ d}),
by simp; exact @hmd (y', y) ⟨hy', hym⟩,
have c ≤ principal (s - ys),
from le_trans hc₁ $ infi_le_of_le ⟨{y}, finite_singleton _⟩ $ le_refl _,
have (s - ys) ∩ (m ∩ s) ∈ c.sets,
from inter_mem_sets (le_principal_iff.mp this) ‹m ∩ s ∈ c.sets›,
have ∅ ∈ c.sets,
from c.sets_of_superset this $ assume x ⟨⟨hxs, hxys⟩, hxm, _⟩, hxys $ ‹m ⊆ ys› hxm,
hc₂.left $ empty_in_sets_eq_bot.mp this⟩
lemma totally_bounded_iff_ultrafilter {s : set α} :
totally_bounded s ↔ (∀f, is_ultrafilter f → f ≤ principal s → cauchy f) :=
⟨assume hs f, cauchy_of_totally_bounded_of_ultrafilter hs,
assume h, totally_bounded_iff_filter.mpr $ assume f hf hfs,
have cauchy (ultrafilter_of f),
from h (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs),
⟨ultrafilter_of f, ultrafilter_of_le, this⟩⟩
lemma compact_iff_totally_bounded_complete {s : set α} :
compact s ↔ totally_bounded s ∧ is_complete s :=
⟨λ hs, ⟨totally_bounded_iff_ultrafilter.2 (λ f hf1 hf2,
let ⟨x, xs, fx⟩ := compact_iff_ultrafilter_le_nhds.1 hs f hf1 hf2 in
cauchy_downwards (cauchy_nhds) (hf1.1) fx),
λ f fc fs,
let ⟨a, as, fa⟩ := hs f fc.1 fs in
⟨a, as, le_nhds_of_cauchy_adhp fc fa⟩⟩,
λ ⟨ht, hc⟩, compact_iff_ultrafilter_le_nhds.2
(λf hf hfs, hc _ (totally_bounded_iff_ultrafilter.1 ht _ hf hfs) hfs)⟩
@[priority 100] -- see Note [lower instance priority]
instance complete_of_compact {α : Type u} [uniform_space α] [compact_space α] : complete_space α :=
⟨λf hf, by simpa [principal_univ] using (compact_iff_totally_bounded_complete.1 compact_univ).2 f hf⟩
lemma compact_of_totally_bounded_is_closed [complete_space α] {s : set α}
(ht : totally_bounded s) (hc : is_closed s) : compact s :=
(@compact_iff_totally_bounded_complete α _ s).2 ⟨ht, is_complete_of_is_closed hc⟩
/-! ### Sequentially complete space
In this section we prove that a uniform space is complete provided that it is sequentially complete
(i.e., any Cauchy sequence converges) and its uniformity filter admits a countable generating set.
In particular, this applies to (e)metric spaces, see the files `topology/metric_space/emetric_space` and
`topology/metric_space/basic`.
More precisely, we assume that there is a sequence of entourages `U_n` such that any other
entourage includes one of `U_n`. Then any Cauchy filter `f` generates a decreasing sequence of
sets `s_n ∈ f` such that `s_n × s_n ⊆ U_n`. Choose a sequence `x_n∈s_n`. It is easy to show
that this is a Cauchy sequence. If this sequence converges to some `a`, then `f ≤ 𝓝 a`. -/
namespace sequentially_complete
variables {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)}
(U_mem : ∀ n, U n ∈ 𝓤 α) (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s)
open set finset
noncomputable theory
/-- An auxiliary sequence of sets approximating a Cauchy filter. -/
def set_seq_aux (n : ℕ) : {s : set α // ∃ (_ : s ∈ f), s.prod s ⊆ U n } :=
indefinite_description _ $ (cauchy_iff.1 hf).2 (U n) (U_mem n)
/-- Given a Cauchy filter `f` and a sequence `U` of entourages, `set_seq` provides
a sequence of monotonically decreasing sets `s n ∈ f` such that `(s n).prod (s n) ⊆ U`. -/
def set_seq (n : ℕ) : set α := ⋂ m ∈ Iic n, (set_seq_aux hf U_mem m).val
lemma set_seq_mem (n : ℕ) : set_seq hf U_mem n ∈ f :=
Inter_mem_sets (finite_le_nat n) (λ m _, (set_seq_aux hf U_mem m).2.fst)
lemma set_seq_mono ⦃m n : ℕ⦄ (h : m ≤ n) : set_seq hf U_mem n ⊆ set_seq hf U_mem m :=
bInter_subset_bInter_left (λ k hk, le_trans hk h)
lemma set_seq_sub_aux (n : ℕ) : set_seq hf U_mem n ⊆ set_seq_aux hf U_mem n :=
bInter_subset_of_mem right_mem_Iic
lemma set_seq_prod_subset {N m n} (hm : N ≤ m) (hn : N ≤ n) :
(set_seq hf U_mem m).prod (set_seq hf U_mem n) ⊆ U N :=
begin
assume p hp,
refine (set_seq_aux hf U_mem N).2.snd ⟨_, _⟩;
apply set_seq_sub_aux,
exact set_seq_mono hf U_mem hm hp.1,
exact set_seq_mono hf U_mem hn hp.2
end
/-- A sequence of points such that `seq n ∈ set_seq n`. Here `set_seq` is a monotonically
decreasing sequence of sets `set_seq n ∈ f` with diameters controlled by a given sequence
of entourages. -/
def seq (n : ℕ) : α := some $ nonempty_of_mem_sets hf.1 (set_seq_mem hf U_mem n)
lemma seq_mem (n : ℕ) : seq hf U_mem n ∈ set_seq hf U_mem n :=
some_spec $ nonempty_of_mem_sets hf.1 (set_seq_mem hf U_mem n)
lemma seq_pair_mem ⦃N m n : ℕ⦄ (hm : N ≤ m) (hn : N ≤ n) :
(seq hf U_mem m, seq hf U_mem n) ∈ U N :=
set_seq_prod_subset hf U_mem hm hn ⟨seq_mem hf U_mem m, seq_mem hf U_mem n⟩
include U_le
theorem seq_is_cauchy_seq : cauchy_seq $ seq hf U_mem :=
cauchy_seq_of_controlled U U_le $ seq_pair_mem hf U_mem
/-- If the sequence `sequentially_complete.seq` converges to `a`, then `f ≤ 𝓝 a`. -/
theorem le_nhds_of_seq_tendsto_nhds ⦃a : α⦄ (ha : tendsto (seq hf U_mem) at_top (𝓝 a)) :
f ≤ 𝓝 a :=
le_nhds_of_cauchy_adhp_aux
begin
assume s hs,
rcases U_le s hs with ⟨m, hm⟩,
rcases (tendsto_at_top' _ _).1 ha _ (mem_nhds_left a (U_mem m)) with ⟨n, hn⟩,
refine ⟨set_seq hf U_mem (max m n), set_seq_mem hf U_mem _, _,
seq hf U_mem (max m n), seq_mem hf U_mem _, _⟩,
{ have := le_max_left m n,
exact set.subset.trans (set_seq_prod_subset hf U_mem this this) hm },
{ exact hm (hn _ $ le_max_right m n) }
end
end sequentially_complete
namespace uniform_space
open sequentially_complete
variables (H : is_countably_generated (𝓤 α))
include H
/-- A uniform space is complete provided that (a) its uniformity filter has a countable basis;
(b) any sequence satisfying a "controlled" version of the Cauchy condition converges. -/
theorem complete_of_convergent_controlled_sequences (U : ℕ → set (α × α)) (U_mem : ∀ n, U n ∈ 𝓤 α)
(HU : ∀ u : ℕ → α, (∀ N m n, N ≤ m → N ≤ n → (u m, u n) ∈ U N) → ∃ a, tendsto u at_top (𝓝 a)) :
complete_space α :=
begin
rcases H.exists_antimono_seq' with ⟨U', U'_mono, hU'⟩,
have Hmem : ∀ n, U n ∩ U' n ∈ 𝓤 α,
from λ n, inter_mem_sets (U_mem n) (hU'.2 ⟨n, subset.refl _⟩),
refine ⟨λ f hf, (HU (seq hf Hmem) (λ N m n hm hn, _)).imp $
le_nhds_of_seq_tendsto_nhds _ _ (λ s hs, _)⟩,
{ rcases (hU'.1 hs) with ⟨N, hN⟩,
exact ⟨N, subset.trans (inter_subset_right _ _) hN⟩ },
{ exact inter_subset_left _ _ (seq_pair_mem hf Hmem hm hn) }
end
/-- A sequentially complete uniform space with a countable basis of the uniformity filter is
complete. -/
theorem complete_of_cauchy_seq_tendsto
(H' : ∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) :
complete_space α :=
let ⟨U', U'_mono, hU'⟩ := H.exists_antimono_seq' in
complete_of_convergent_controlled_sequences H U' (λ n, hU'.2 ⟨n, subset.refl _⟩)
(λ u hu, H' u $ cauchy_seq_of_controlled U' (λ s hs, hU'.1 hs) hu)
protected lemma first_countable_topology : first_countable_topology α :=
⟨λ a, by { rw nhds_eq_comap_uniformity, exact H.comap (prod.mk a) }⟩
end uniform_space
|
7a9b145721e7aaef36fb89bffb4aa82582f4bb0d | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/char_zero.lean | a775dc0f6aa41a35fc7f1087b4926967ebec18a7 | [
"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 | 6,244 | lean | /-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.nat.cast
import data.fintype.basic
import tactic.wlog
/-!
# Characteristic zero
A ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered
as an element of `R`. Since this definition doesn't mention the multiplicative structure of `R`
except for the existence of `1` in this file characteristic zero is defined for additive monoids
with `1`.
## Main definition
`char_zero` is the typeclass of an additive monoid with one such that the natural homomorphism
from the natural numbers into it is injective.
## Main statements
* A linearly ordered semiring has characteristic zero.
* Characteristic zero implies that the additive monoid is infinite.
## TODO
* Once order of a group is defined for infinite additive monoids redefine or at least connect to
order of `1` in the additive monoid with one.
* Unify with `char_p` (possibly using an out-parameter)
-/
/-- Typeclass for monoids with characteristic zero.
(This is usually stated on fields but it makes sense for any additive monoid with 1.) -/
class char_zero (R : Type*) [add_monoid R] [has_one R] : Prop :=
(cast_injective : function.injective (coe : ℕ → R))
theorem char_zero_of_inj_zero {R : Type*} [add_left_cancel_monoid R] [has_one R]
(H : ∀ n:ℕ, (n:R) = 0 → n = 0) : char_zero R :=
⟨λ m n, begin
assume h,
wlog hle : m ≤ n,
rcases nat.le.dest hle with ⟨k, rfl⟩,
rw [nat.cast_add, eq_comm, add_right_eq_self] at h,
rw [H k h, add_zero]
end⟩
/-- Note this is not an instance as `char_zero` implies `nontrivial`,
and this would risk forming a loop. -/
lemma ordered_semiring.to_char_zero {R : Type*} [ordered_semiring R] [nontrivial R] :
char_zero R :=
⟨nat.strict_mono_cast.injective⟩
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_semiring.to_char_zero {R : Type*}
[linear_ordered_semiring R] : char_zero R :=
ordered_semiring.to_char_zero
namespace nat
variables {R : Type*} [add_monoid R] [has_one R] [char_zero R]
theorem cast_injective : function.injective (coe : ℕ → R) :=
char_zero.cast_injective
@[simp, norm_cast] theorem cast_inj {m n : ℕ} : (m : R) = n ↔ m = n :=
cast_injective.eq_iff
@[simp, norm_cast] theorem cast_eq_zero {n : ℕ} : (n : R) = 0 ↔ n = 0 :=
by rw [← cast_zero, cast_inj]
@[norm_cast] theorem cast_ne_zero {n : ℕ} : (n : R) ≠ 0 ↔ n ≠ 0 :=
not_congr cast_eq_zero
lemma cast_add_one_ne_zero (n : ℕ) : (n + 1 : R) ≠ 0 :=
by exact_mod_cast n.succ_ne_zero
@[simp, norm_cast]
theorem cast_dvd_char_zero {k : Type*} [field k] [char_zero k] {m n : ℕ}
(n_dvd : n ∣ m) : ((m / n : ℕ) : k) = m / n :=
begin
by_cases hn : n = 0,
{ subst hn,
simp },
{ exact cast_dvd n_dvd (cast_ne_zero.mpr hn), },
end
end nat
section
variables (M : Type*) [add_monoid M] [has_one M] [char_zero M]
@[priority 100] -- see Note [lower instance priority]
instance char_zero.infinite : infinite M :=
infinite.of_injective coe nat.cast_injective
variable {M}
@[field_simps] lemma two_ne_zero' : (2:M) ≠ 0 :=
have ((2:ℕ):M) ≠ 0, from nat.cast_ne_zero.2 dec_trivial,
by rwa [nat.cast_two] at this
end
section
variables {R : Type*} [semiring R] [no_zero_divisors R] [char_zero R]
@[simp]
lemma add_self_eq_zero {a : R} : a + a = 0 ↔ a = 0 :=
by simp only [(two_mul a).symm, mul_eq_zero, two_ne_zero', false_or]
@[simp]
lemma bit0_eq_zero {a : R} : bit0 a = 0 ↔ a = 0 := add_self_eq_zero
@[simp]
lemma zero_eq_bit0 {a : R} : 0 = bit0 a ↔ a = 0 :=
by { rw [eq_comm], exact bit0_eq_zero }
end
section
variables {R : Type*} [ring R] [no_zero_divisors R] [char_zero R]
lemma neg_eq_self_iff {a : R} : -a = a ↔ a = 0 :=
neg_eq_iff_add_eq_zero.trans add_self_eq_zero
lemma eq_neg_self_iff {a : R} : a = -a ↔ a = 0 :=
eq_neg_iff_add_eq_zero.trans add_self_eq_zero
lemma nat_mul_inj {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) : n = 0 ∨ a = b :=
begin
rw [←sub_eq_zero, ←mul_sub, mul_eq_zero, sub_eq_zero] at h,
exact_mod_cast h,
end
lemma nat_mul_inj' {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) (w : n ≠ 0) : a = b :=
by simpa [w] using nat_mul_inj h
lemma bit0_injective : function.injective (bit0 : R → R) :=
λ a b h, begin
dsimp [bit0] at h,
simp only [(two_mul a).symm, (two_mul b).symm] at h,
refine nat_mul_inj' _ two_ne_zero,
exact_mod_cast h,
end
lemma bit1_injective : function.injective (bit1 : R → R) :=
λ a b h, begin
simp only [bit1, add_left_inj] at h,
exact bit0_injective h,
end
@[simp] lemma bit0_eq_bit0 {a b : R} : bit0 a = bit0 b ↔ a = b :=
bit0_injective.eq_iff
@[simp] lemma bit1_eq_bit1 {a b : R} : bit1 a = bit1 b ↔ a = b :=
bit1_injective.eq_iff
@[simp]
lemma bit1_eq_one {a : R} : bit1 a = 1 ↔ a = 0 :=
by rw [show (1 : R) = bit1 0, by simp, bit1_eq_bit1]
@[simp]
lemma one_eq_bit1 {a : R} : 1 = bit1 a ↔ a = 0 :=
by { rw [eq_comm], exact bit1_eq_one }
end
section
variables {R : Type*} [division_ring R] [char_zero R]
@[simp] lemma half_add_self (a : R) : (a + a) / 2 = a :=
by rw [← mul_two, mul_div_cancel a two_ne_zero']
@[simp] lemma add_halves' (a : R) : a / 2 + a / 2 = a :=
by rw [← add_div, half_add_self]
lemma sub_half (a : R) : a - a / 2 = a / 2 :=
by rw [sub_eq_iff_eq_add, add_halves']
lemma half_sub (a : R) : a / 2 - a = - (a / 2) :=
by rw [← neg_sub, sub_half]
end
namespace with_top
instance {R : Type*} [add_monoid R] [has_one R] [char_zero R] : char_zero (with_top R) :=
{ cast_injective := λ m n h, by rwa [← coe_nat, ← coe_nat n, coe_eq_coe, nat.cast_inj] at h }
end with_top
section ring_hom
variables {R S : Type*} [semiring R] [semiring S]
lemma ring_hom.char_zero (ϕ : R →+* S) [hS : char_zero S] : char_zero R :=
⟨λ a b h, char_zero.cast_injective (by rw [←ϕ.map_nat_cast, ←ϕ.map_nat_cast, h])⟩
lemma ring_hom.char_zero_iff {ϕ : R →+* S} (hϕ : function.injective ϕ) :
char_zero R ↔ char_zero S :=
⟨λ hR, ⟨λ a b h, by rwa [←@nat.cast_inj R _ _ hR, ←hϕ.eq_iff, ϕ.map_nat_cast, ϕ.map_nat_cast]⟩,
λ hS, by exactI ϕ.char_zero⟩
end ring_hom
|
4ed25c569f3335ca6088814c4b3aaa7d6fc0ce1e | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/ring_theory/polynomial/chebyshev/default.lean | 05ad32d9f4d117e867963225deb72d2c01434a72 | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 46 | lean | import ring_theory.polynomial.chebyshev.basic
|
65aa2a07ece00f5c2b54bb3cdba0721c98d925ba | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/548.lean | 7b0b13e06c9b7f8869a388c8538477f29492b29a | [
"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 | 667 | lean | open nat
example (a b : nat) (P : nat → Prop) (H₁ : a = b) (H₂ : P a) : P b :=
begin
rewrite H₁ at *,
exact H₂
end
example (a b : nat) (P : nat → Prop) (H₀ : a = 0 → b = 1) (H₁ : a = 0) (H₂ : P b) : P 1 :=
begin
rewrite (H₀ H₁) at *,
exact H₂
end
example (a c : nat) (P : nat → Prop) (H₁ : P a) (b : nat) (H₂ : a = b) (H₃ : b = c) : P c :=
begin
rewrite H₂ at H₁,
exact (eq.rec_on H₃ H₁)
end
example (a c : nat) (f : nat → nat → nat) (P : nat → Prop) (H₁ : P a) (b : nat) (d : nat) (H₂ : a = f b d) (H₃ : f b d = c)
: P c :=
begin
rewrite H₂ at H₁,
exact (eq.rec_on H₃ H₁)
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.